AWS IoT Device SDK C:
MQTT
MQTT 3.1.1 client library
|
Return to main page ↑ |
Implements most user-facing functions of the MQTT library. More...
#include "iot_config.h"
#include <string.h>
#include <limits.h>
#include "types/iot_mqtt_types.h"
#include "private/iot_mqtt_helper.h"
#include "iot_mqtt_lightweight.h"
#include "iot_logging_setup.h"
Macros | |
#define | IotMqtt_Assert(expression) |
Assertion macro for the MQTT library. More... | |
Functions | |
static size_t | _getRemainingLength (IotNetworkConnection_t pNetworkConnection, IotMqttGetNextByte_t getNextByte) |
Get the remaining length from a stream of bytes off the network. More... | |
static IotMqttError_t | _deserializeConnack (IotMqttPacketInfo_t *pConnack) |
Deserialize a CONNACK packet. More... | |
static IotMqttError_t | _deserializeSuback (IotMqttPacketInfo_t *pSuback) |
Deserialize a SUBACK packet. More... | |
static IotMqttError_t | _deserializePuback (IotMqttPacketInfo_t *pPuback) |
Deserialize a PUBACK packet. More... | |
static IotMqttError_t | _deserializePingresp (IotMqttPacketInfo_t *pPingresp) |
Deserialize a PINGRESP packet. More... | |
static IotMqttError_t | _deserializeUnsuback (IotMqttPacketInfo_t *pUnsuback) |
Deserialize a UNSUBACK packet. More... | |
static IotMqttError_t | _deserializePublish (IotMqttPacketInfo_t *pPublish) |
Deserialize a PUBLISH packet received from the server. More... | |
static IotMqttError_t | _readSubackStatus (size_t statusCount, const uint8_t *pStatusStart) |
Decode the status bytes of a SUBACK packet. More... | |
static IotMqttError_t | _checkPublishRemainingLength (const IotMqttPacketInfo_t *pPublish, IotMqttQos_t qos, size_t qos0Minimum) |
Check the remaining length of incoming Publish against some value for QoS 0 or QoS 1/2. More... | |
IotMqttError_t | IotMqtt_GetConnectPacketSize (const IotMqttConnectInfo_t *pConnectInfo, size_t *pRemainingLength, size_t *pPacketSize) |
Calculate the size and "Remaining length" of a CONNECT packet generated from the given parameters. More... | |
IotMqttError_t | IotMqtt_SerializeConnect (const IotMqttConnectInfo_t *pConnectInfo, size_t remainingLength, uint8_t *pBuffer, size_t bufferSize) |
Generate a CONNECT packet from the given parameters. More... | |
IotMqttError_t | IotMqtt_GetSubscriptionPacketSize (IotMqttOperationType_t type, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, size_t *pRemainingLength, size_t *pPacketSize) |
Calculate the size and "Remaining length" of a SUBSCRIBE or UNSUBSCRIBE packet generated from the given parameters. More... | |
IotMqttError_t | IotMqtt_SerializeSubscribe (const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, size_t remainingLength, uint16_t *pPacketIdentifier, uint8_t *pBuffer, size_t bufferSize) |
Generate a SUBSCRIBE packet from the given parameters. More... | |
IotMqttError_t | IotMqtt_GetIncomingMQTTPacketTypeAndLength (IotMqttPacketInfo_t *pIncomingPacket, IotMqttGetNextByte_t getNextByte, IotNetworkConnection_t pNetworkConnection) |
Extract MQTT packet type and length from incoming packet. More... | |
IotMqttError_t | IotMqtt_GetPublishPacketSize (const IotMqttPublishInfo_t *pPublishInfo, size_t *pRemainingLength, size_t *pPacketSize) |
Calculate the size and "Remaining length" of a PUBLISH packet generated from the given parameters. More... | |
IotMqttError_t | IotMqtt_SerializePublish (const IotMqttPublishInfo_t *pPublishInfo, size_t remainingLength, uint16_t *pPacketIdentifier, uint8_t **pPacketIdentifierHigh, uint8_t *pBuffer, size_t bufferSize) |
Generate a PUBLISH packet from the given parameters. More... | |
IotMqttError_t | IotMqtt_SerializeUnsubscribe (const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, size_t remainingLength, uint16_t *pPacketIdentifier, uint8_t *pBuffer, size_t bufferSize) |
Generate a UNSUBSCRIBE packet from the given parameters. More... | |
IotMqttError_t | IotMqtt_SerializeDisconnect (uint8_t *pBuffer, size_t bufferSize) |
Generate a DISCONNECT packet. More... | |
IotMqttError_t | IotMqtt_SerializePingreq (uint8_t *pBuffer, size_t bufferSize) |
Generate a PINGREQ packet. More... | |
IotMqttError_t | IotMqtt_DeserializePublish (IotMqttPacketInfo_t *pMqttPacket) |
Deserialize incoming publish packet. More... | |
IotMqttError_t | IotMqtt_DeserializeResponse (IotMqttPacketInfo_t *pMqttPacket) |
Deserialize incoming ack packets. More... | |
Implements most user-facing functions of the MQTT library.
#define IotMqtt_Assert | ( | expression | ) |
Assertion macro for the MQTT library.
Set IOT_MQTT_ENABLE_ASSERTS to 1
to enable assertions in the MQTT library.
[in] | expression | Expression to be evaluated. |
|
static |
Get the remaining length from a stream of bytes off the network.
[in] | pNetworkConnection | Reference to the network connection. |
[in] | getNextByte | Function pointer used to interact with the network to get next byte. |
|
static |
Deserialize a CONNACK packet.
Converts the packet from a stream of bytes to an IotMqttError_t. Also prints out debug log messages about the packet.
[in,out] | pConnack | Pointer to an MQTT packet struct representing a CONNACK. |
|
static |
Deserialize a SUBACK packet.
Converts the packet from a stream of bytes to an IotMqttError_t and extracts the packet identifier. Also prints out debug log messages about the packet.
[in,out] | pSuback | Pointer to an MQTT packet struct representing a SUBACK. |
|
static |
Deserialize a PUBACK packet.
Converts the packet from a stream of bytes to an IotMqttError_t and extracts the packet identifier. Also prints out debug log messages about the packet.
[in,out] | pPuback | Pointer to an MQTT packet struct representing a PUBACK. |
|
static |
Deserialize a PINGRESP packet.
Converts the packet from a stream of bytes to an IotMqttError_t. Also prints out debug log messages about the packet.
[in,out] | pPingresp | Pointer to an MQTT packet struct representing a PINGRESP. |
|
static |
Deserialize a UNSUBACK packet.
Converts the packet from a stream of bytes to an IotMqttError_t and extracts the packet identifier. Also prints out debug log messages about the packet.
[in,out] | pUnsuback | Pointer to an MQTT packet struct representing an UNSUBACK. |
|
static |
Deserialize a PUBLISH packet received from the server.
Converts the packet from a stream of bytes to an IotMqttPublishInfo_t and extracts the packet identifier. Also prints out debug log messages about the packet.
[in,out] | pPublish | Pointer to an MQTT packet struct representing a PUBLISH. |
|
static |
Decode the status bytes of a SUBACK packet.
[in] | statusCount | Number of status bytes in the SUBACK. |
[in] | pStatusStart | The first status byte in the SUBACK. |
|
static |
Check the remaining length of incoming Publish against some value for QoS 0 or QoS 1/2.
The remaining length for a QoS 1/2 will always be two greater than for a QoS 0.
[in] | pPublish | Pointer to an MQTT packet struct representing a PUBLISH. |
[in] | qos | The QoS of the PUBLISH. |
[in] | qos0Minimum | Minimum possible remaining length for a QoS 0 PUBLISH. |
IotMqttError_t IotMqtt_GetConnectPacketSize | ( | const IotMqttConnectInfo_t * | pConnectInfo, |
size_t * | pRemainingLength, | ||
size_t * | pPacketSize | ||
) |
Calculate the size and "Remaining length" of a CONNECT packet generated from the given parameters.
[in] | pConnectInfo | User-provided CONNECT information struct. |
[out] | pRemainingLength | Output for calculated "Remaining length" field. |
[out] | pPacketSize | Output for calculated total packet size. |
IOT_MQTT_BAD_PARAMETER
, the output parameters should be ignored.Example
IotMqttError_t IotMqtt_SerializeConnect | ( | const IotMqttConnectInfo_t * | pConnectInfo, |
size_t | remainingLength, | ||
uint8_t * | pBuffer, | ||
size_t | bufferSize | ||
) |
Generate a CONNECT packet from the given parameters.
[in] | pConnectInfo | User-provided CONNECT information. |
[in] | remainingLength | remaining length of the packet to be serialized. |
[in,out] | pBuffer | User provided buffer where the CONNECT packet is written. |
[in] | bufferSize | Size of the buffer pointed to by pBuffer. |
Example
IotMqttError_t IotMqtt_GetSubscriptionPacketSize | ( | IotMqttOperationType_t | type, |
const IotMqttSubscription_t * | pSubscriptionList, | ||
size_t | subscriptionCount, | ||
size_t * | pRemainingLength, | ||
size_t * | pPacketSize | ||
) |
Calculate the size and "Remaining length" of a SUBSCRIBE or UNSUBSCRIBE packet generated from the given parameters.
[in] | type | Either IOT_MQTT_SUBSCRIBE or IOT_MQTT_UNSUBSCRIBE. |
[in] | pSubscriptionList | User-provided array of subscriptions. |
[in] | subscriptionCount | Size of pSubscriptionList . |
[out] | pRemainingLength | Output for calculated "Remaining length" field. |
[out] | pPacketSize | Output for calculated total packet size. |
Example
IotMqttError_t IotMqtt_SerializeSubscribe | ( | const IotMqttSubscription_t * | pSubscriptionList, |
size_t | subscriptionCount, | ||
size_t | remainingLength, | ||
uint16_t * | pPacketIdentifier, | ||
uint8_t * | pBuffer, | ||
size_t | bufferSize | ||
) |
Generate a SUBSCRIBE packet from the given parameters.
[in] | pSubscriptionList | User-provided array of subscriptions. |
[in] | subscriptionCount | Size of pSubscriptionList . |
[in] | remainingLength | remaining length of the packet to be serialized. |
[out] | pPacketIdentifier | The packet identifier generated for this SUBSCRIBE. |
[in,out] | pBuffer | User provide buffer where the SUBSCRIBE packet is written. |
[in] | bufferSize | Size of the buffer pointed to by pBuffer. |
IotMqttError_t IotMqtt_GetIncomingMQTTPacketTypeAndLength | ( | IotMqttPacketInfo_t * | pIncomingPacket, |
IotMqttGetNextByte_t | getNextByte, | ||
IotNetworkConnection_t | pNetworkConnection | ||
) |
Extract MQTT packet type and length from incoming packet.
[in,out] | pIncomingPacket | Pointer to IotMqttPacketInfo_t structure where type, remaining length and packet identifier are stored. |
[in] | getNextByte | Pointer to platform specific function which is used to extract type and length from incoming received stream (see example ). |
[in] | pNetworkConnection | Pointer to platform specific network connection which is used by getNextByte to receive network data |
Example
IotMqttError_t IotMqtt_GetPublishPacketSize | ( | const IotMqttPublishInfo_t * | pPublishInfo, |
size_t * | pRemainingLength, | ||
size_t * | pPacketSize | ||
) |
Calculate the size and "Remaining length" of a PUBLISH packet generated from the given parameters.
[in] | pPublishInfo | User-provided PUBLISH information struct. |
[out] | pRemainingLength | Output for calculated "Remaining length" field. |
[out] | pPacketSize | Output for calculated total packet size. |
Example
IotMqttError_t IotMqtt_SerializePublish | ( | const IotMqttPublishInfo_t * | pPublishInfo, |
size_t | remainingLength, | ||
uint16_t * | pPacketIdentifier, | ||
uint8_t ** | pPacketIdentifierHigh, | ||
uint8_t * | pBuffer, | ||
size_t | bufferSize | ||
) |
Generate a PUBLISH packet from the given parameters.
[in] | pPublishInfo | User-provided PUBLISH information. |
[in] | remainingLength | remaining length of the packet to be serialized. |
[out] | pPacketIdentifier | The packet identifier generated for this PUBLISH. |
[out] | pPacketIdentifierHigh | Where the high byte of the packet identifier is written. |
[in,out] | pBuffer | User provide buffer where the PUBLISH packet is written. |
[in] | bufferSize | Size of the buffer pointed to by pBuffer. |
Example
IotMqttError_t IotMqtt_SerializeUnsubscribe | ( | const IotMqttSubscription_t * | pSubscriptionList, |
size_t | subscriptionCount, | ||
size_t | remainingLength, | ||
uint16_t * | pPacketIdentifier, | ||
uint8_t * | pBuffer, | ||
size_t | bufferSize | ||
) |
Generate a UNSUBSCRIBE packet from the given parameters.
[in] | pSubscriptionList | User-provided array of subscriptions to remove. |
[in] | subscriptionCount | Size of pSubscriptionList . |
[in] | remainingLength | remaining length of the packet to be serialized. |
[out] | pPacketIdentifier | The packet identifier generated for this UNSUBSCRIBE. |
[in,out] | pBuffer | User provide buffer where the UNSUBSCRIBE packet is written. |
[in] | bufferSize | Size of the buffer pointed to by pBuffer. |
Example
IotMqttError_t IotMqtt_SerializeDisconnect | ( | uint8_t * | pBuffer, |
size_t | bufferSize | ||
) |
Generate a DISCONNECT packet.
[in,out] | pBuffer | User provide buffer where the DISCONNECT packet is written. |
[in] | bufferSize | Size of the buffer pointed to by pBuffer. |
Example
IotMqttError_t IotMqtt_SerializePingreq | ( | uint8_t * | pBuffer, |
size_t | bufferSize | ||
) |
Generate a PINGREQ packet.
[in,out] | pBuffer | User provide buffer where the PINGREQ packet is written. |
[in] | bufferSize | Size of the buffer pointed to by pBuffer. |
Example
IotMqttError_t IotMqtt_DeserializePublish | ( | IotMqttPacketInfo_t * | pMqttPacket | ) |
Deserialize incoming publish packet.
[in,out] | pMqttPacket | The caller of this API sets type, remainingLength and pRemainingData. On success, packetIdentifier and pubInfo will be set by the function. |
Example
IotMqttError_t IotMqtt_DeserializeResponse | ( | IotMqttPacketInfo_t * | pMqttPacket | ) |
Deserialize incoming ack packets.
[in,out] | pMqttPacket | The caller of this API sets type, remainingLength and pRemainingData. On success, packetIdentifier will be set. |
Example