Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
898 changes: 745 additions & 153 deletions source/core_mqtt.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/core_mqtt_prop_deserializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ MQTTStatus_t MQTT_GetNextPropertyType( MQTTPropBuilder_t * pPropertyBuilder,

if( status != MQTTSuccess )
{
LogError( ( "Property type is invalid." ) );
/* Do nothing. checkPropBuilderParams will log the warning/error. */
}
else if( property == NULL )
{
Expand Down
1 change: 0 additions & 1 deletion source/core_mqtt_prop_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <inttypes.h>

#include "core_mqtt_serializer.h"
#include "transport_interface.h"

#include "private/core_mqtt_serializer_private.h"

Expand Down
843 changes: 759 additions & 84 deletions source/core_mqtt_serializer.c

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions source/core_mqtt_serializer_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,28 @@ MQTTStatus_t decodeVariableLength( const uint8_t * pBuffer,
}

/*-----------------------------------------------------------*/

uint8_t * serializeAckFixed( uint8_t * pIndex,
uint8_t packetType,
uint16_t packetId,
size_t remainingLength,
MQTTSuccessFailReasonCode_t reasonCode )
{
uint8_t * pIndexLocal = pIndex;

/* The first byte in the publish ack packet is the control packet type. */
*pIndexLocal = packetType;
pIndexLocal++;
/*After the packet type fixed header has remaining length.*/
pIndexLocal = encodeVariableLength( pIndexLocal, remainingLength );
/*Encode the packet id.*/
pIndexLocal[ 0 ] = UINT16_HIGH_BYTE( packetId );
pIndexLocal[ 1 ] = UINT16_LOW_BYTE( packetId );
pIndexLocal = &pIndexLocal[ 2 ];
/*We are now sending the ack.*/
*pIndexLocal = ( uint8_t ) reasonCode;
pIndexLocal++;
return pIndexLocal;
}

/*-----------------------------------------------------------*/
63 changes: 54 additions & 9 deletions source/include/core_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,16 +925,28 @@ MQTTStatus_t MQTT_Subscribe( MQTTContext_t * pContext,
* @param[in] pContext Initialized MQTT context.
* @param[in] pPublishInfo MQTT PUBLISH packet parameters.
* @param[in] packetId packet ID generated by #MQTT_GetPacketId.
* @param[in] pPropertyBuilder Properties to be sent in the outgoing packet.
*
* @return #MQTTNoMemory if pBuffer is too small to hold the MQTT packet;
* #MQTTBadParameter if invalid parameters are passed;
* #MQTTSendFailed if transport write failed;
* #MQTTStatusNotConnected if the connection is not established yet
* @return
* #MQTTBadParameter if invalid parameters are passed;<br>
* #MQTTBadResponse if there is an error in property parsing;<br>
* #MQTTSendFailed if transport write failed;<br>
* #MQTTStatusNotConnected if the connection is not established yet<br>
* #MQTTStatusDisconnectPending if the user is expected to call MQTT_Disconnect
* before calling any other API
* before calling any other API<br>
* #MQTTPublishStoreFailed if the user provided callback to copy and store the
* outgoing publish packet fails
* #MQTTSuccess otherwise.
* outgoing publish packet fails<br>
* #MQTTSuccess otherwise.<br>
*
* Functions to add optional properties to the PUBLISH packet are:
*
* - #MQTTPropAdd_PubPayloadFormat
* - #MQTTPropAdd_PubMessageExpiry
* - #MQTTPropAdd_PubTopicAlias
* - #MQTTPropAdd_PubResponseTopic
* - #MQTTPropAdd_PubCorrelationData
* - #MQTTPropAdd_PubContentType
* - #MQTTPropAdd_UserProp
*
* <b>Example</b>
* @code{c}
Expand All @@ -952,11 +964,19 @@ MQTTStatus_t MQTT_Subscribe( MQTTContext_t * pContext,
* publishInfo.topicNameLength = strlen( publishInfo.pTopicName );
* publishInfo.pPayload = "Hello World!";
* publishInfo.payloadLength = strlen( "Hello World!" );
* // Optional properties to be sent in the PUBLISH packet.
* MQTTPropBuilder_t propertyBuilder;
* uint8_t propertyBuffer[ 100 ];
* size_t propertyBufferLength = sizeof( propertyBuffer );
* status = MQTTPropertyBuilder_Init( &propertyBuilder, propertyBuffer, propertyBufferLength );
*
* // Set a property in the propertyBuilder
* status = MQTTPropAdd_PubPayloadFormat( &propertyBuilder, 1);
*
* // Packet ID is needed for QoS > 0.
* packetId = MQTT_GetPacketId( pContext );
*
* status = MQTT_Publish( pContext, &publishInfo, packetId );
* status = MQTT_Publish( pContext, &publishInfo, packetId, &propertyBuilder );
*
* if( status == MQTTSuccess )
* {
Expand All @@ -968,7 +988,8 @@ MQTTStatus_t MQTT_Subscribe( MQTTContext_t * pContext,
/* @[declare_mqtt_publish] */
MQTTStatus_t MQTT_Publish( MQTTContext_t * pContext,
const MQTTPublishInfo_t * pPublishInfo,
uint16_t packetId );
uint16_t packetId,
const MQTTPropBuilder_t * pPropertyBuilder );
/* @[declare_mqtt_publish] */

/**
Expand Down Expand Up @@ -1392,6 +1413,30 @@ void MQTT_SerializeMQTTVec( uint8_t * pAllocatedMem,
const MQTTVec_t * pVec );
/* @[declare_mqtt_serializemqttvec] */

/**
* @brief Get a human-readable string representation of an MQTT packet type.
*
* This function converts an MQTT packet type byte into a corresponding
* string representation for debugging and logging purposes.
*
* @param[in] packetType The MQTT packet type byte to convert.
*
* @return A pointer to a constant string containing the packet type name.
* Returns "UNKNOWN" if the packet type is not recognized.
*
* @note The returned string is statically allocated and should not be freed.
* @note For PUBLISH packets, the function masks the lower 4 bits (flags) and
* returns "PUBLISH" regardless of the QoS, DUP, or RETAIN flag values.
*
* <b>Example</b>
* @code{c}
* uint8_t packetType = MQTT_PACKET_TYPE_PUBLISH;
* const char * packetName = MQTT_GetPacketTypeString( packetType );
* printf( "Received packet: %s\n", packetName ); // Prints "Received packet: PUBLISH"
* @endcode
*/
const char * MQTT_GetPacketTypeString( uint8_t packetType );

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
20 changes: 20 additions & 0 deletions source/include/core_mqtt_config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@
#define LogDebug( message )
#endif

/**
* @brief Macro that is called in the MQTT library for logging "Trace" level
* messages.
*
* To enable trace level logging from MQTT library, this macro should be mapped to the
* application-specific logging implementation that supports trace logging.
*
* @note This logging macro is called in the MQTT library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Trace logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogTrace
#define LogTrace( message )
#endif

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
Loading