AWS IoT Device SDK C:
MQTT
MQTT 3.1.1 client library
|
Return to main page ↑ |
Implements functions that generate and decode MQTT network packets. More...
#include "iot_config.h"
#include <string.h>
#include <limits.h>
#include "private/iot_mqtt_internal.h"
#include "private/iot_mqtt_helper.h"
#include "platform/iot_threads.h"
#include "iot_atomic.h"
Functions | |
static IotMqttError_t | _decodeSubackStatus (size_t statusCount, const uint8_t *pStatusStart, const _mqttPacket_t *pSuback) |
Decode the status bytes of a SUBACK packet. More... | |
static IotMqttError_t | _checkRemainingLength (const _mqttPacket_t *pPublish, IotMqttQos_t qos, size_t qos0Minimum) |
Check the remaining length against some value for QoS 0 or QoS 1/2. More... | |
uint8_t | _IotMqtt_GetPacketType (IotNetworkConnection_t pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface) |
Get the MQTT packet type from a stream of bytes off the network. More... | |
size_t | _IotMqtt_GetRemainingLength (IotNetworkConnection_t pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface) |
Get the remaining length from a stream of bytes off the network. More... | |
IotMqttError_t | _IotMqtt_SerializeConnect (const IotMqttConnectInfo_t *pConnectInfo, uint8_t **pConnectPacket, size_t *pPacketSize) |
Generate a CONNECT packet from the given parameters. More... | |
IotMqttError_t | _IotMqtt_DeserializeConnack (_mqttPacket_t *pConnack) |
Deserialize a CONNACK packet. More... | |
IotMqttError_t | _IotMqtt_SerializePublish (const IotMqttPublishInfo_t *pPublishInfo, uint8_t **pPublishPacket, size_t *pPacketSize, uint16_t *pPacketIdentifier, uint8_t **pPacketIdentifierHigh) |
Generate a PUBLISH packet from the given parameters. More... | |
void | _IotMqtt_PublishSetDup (uint8_t *pPublishPacket, uint8_t *pPacketIdentifierHigh, uint16_t *pNewPacketIdentifier) |
Set the DUP bit in a QoS 1 PUBLISH packet. More... | |
IotMqttError_t | _IotMqtt_DeserializePublish (_mqttPacket_t *pPublish) |
Deserialize a PUBLISH packet received from the server. More... | |
IotMqttError_t | _IotMqtt_SerializePuback (uint16_t packetIdentifier, uint8_t **pPubackPacket, size_t *pPacketSize) |
Generate a PUBACK packet for the given packet identifier. More... | |
IotMqttError_t | _IotMqtt_DeserializePuback (_mqttPacket_t *pPuback) |
Deserialize a PUBACK packet. More... | |
IotMqttError_t | _IotMqtt_SerializeSubscribe (const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint8_t **pSubscribePacket, size_t *pPacketSize, uint16_t *pPacketIdentifier) |
Generate a SUBSCRIBE packet from the given parameters. More... | |
IotMqttError_t | _IotMqtt_DeserializeSuback (_mqttPacket_t *pSuback) |
Deserialize a SUBACK packet. More... | |
IotMqttError_t | _IotMqtt_SerializeUnsubscribe (const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint8_t **pUnsubscribePacket, size_t *pPacketSize, uint16_t *pPacketIdentifier) |
Generate an UNSUBSCRIBE packet from the given parameters. More... | |
IotMqttError_t | _IotMqtt_DeserializeUnsuback (_mqttPacket_t *pUnsuback) |
Deserialize a UNSUBACK packet. More... | |
IotMqttError_t | _IotMqtt_SerializePingreq (uint8_t **pPingreqPacket, size_t *pPacketSize) |
Generate a PINGREQ packet. More... | |
IotMqttError_t | _IotMqtt_DeserializePingresp (_mqttPacket_t *pPingresp) |
Deserialize a PINGRESP packet. More... | |
IotMqttError_t | _IotMqtt_SerializeDisconnect (uint8_t **pDisconnectPacket, size_t *pPacketSize) |
Generate a DISCONNECT packet. More... | |
void | _IotMqtt_FreePacket (uint8_t *pPacket) |
Free a packet generated by the serializer. More... | |
Implements functions that generate and decode MQTT network packets.
|
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. |
[in] | pSuback | The SUBACK packet received from the network. |
|
static |
Check the remaining length 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. |
uint8_t _IotMqtt_GetPacketType | ( | IotNetworkConnection_t | pNetworkConnection, |
const IotNetworkInterface_t * | pNetworkInterface | ||
) |
Get the MQTT packet type from a stream of bytes off the network.
[in] | pNetworkConnection | Reference to the network connection. |
[in] | pNetworkInterface | Function pointers used to interact with the network. |
size_t _IotMqtt_GetRemainingLength | ( | IotNetworkConnection_t | pNetworkConnection, |
const IotNetworkInterface_t * | pNetworkInterface | ||
) |
Get the remaining length from a stream of bytes off the network.
[in] | pNetworkConnection | Reference to the network connection. |
[in] | pNetworkInterface | Function pointers used to interact with the network. |
IotMqttError_t _IotMqtt_SerializeConnect | ( | const IotMqttConnectInfo_t * | pConnectInfo, |
uint8_t ** | pConnectPacket, | ||
size_t * | pPacketSize | ||
) |
Generate a CONNECT packet from the given parameters.
[in] | pConnectInfo | User-provided CONNECT information. |
[out] | pConnectPacket | Where the CONNECT packet is written. |
[out] | pPacketSize | Size of the packet written to pConnectPacket . |
IotMqttError_t _IotMqtt_DeserializeConnack | ( | _mqttPacket_t * | pConnack | ) |
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. |
IotMqttError_t _IotMqtt_SerializePublish | ( | const IotMqttPublishInfo_t * | pPublishInfo, |
uint8_t ** | pPublishPacket, | ||
size_t * | pPacketSize, | ||
uint16_t * | pPacketIdentifier, | ||
uint8_t ** | pPacketIdentifierHigh | ||
) |
Generate a PUBLISH packet from the given parameters.
[in] | pPublishInfo | User-provided PUBLISH information. |
[out] | pPublishPacket | Where the PUBLISH packet is written. |
[out] | pPacketSize | Size of the packet written to pPublishPacket . |
[out] | pPacketIdentifier | The packet identifier generated for this PUBLISH. |
[out] | pPacketIdentifierHigh | Where the high byte of the packet identifier is written. |
void _IotMqtt_PublishSetDup | ( | uint8_t * | pPublishPacket, |
uint8_t * | pPacketIdentifierHigh, | ||
uint16_t * | pNewPacketIdentifier | ||
) |
Set the DUP bit in a QoS 1 PUBLISH packet.
[in] | pPublishPacket | Pointer to the PUBLISH packet to modify. |
[in] | pPacketIdentifierHigh | The high byte of any packet identifier to modify. |
[out] | pNewPacketIdentifier | Since AWS IoT does not support the DUP flag, a new packet identifier is generated and should be written here. This parameter is only used when connected to an AWS IoT MQTT server. |
IotMqttError_t _IotMqtt_DeserializePublish | ( | _mqttPacket_t * | pPublish | ) |
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. |
IotMqttError_t _IotMqtt_SerializePuback | ( | uint16_t | packetIdentifier, |
uint8_t ** | pPubackPacket, | ||
size_t * | pPacketSize | ||
) |
Generate a PUBACK packet for the given packet identifier.
[in] | packetIdentifier | The packet identifier to place in PUBACK. |
[out] | pPubackPacket | Where the PUBACK packet is written. |
[out] | pPacketSize | Size of the packet written to pPubackPacket . |
IotMqttError_t _IotMqtt_DeserializePuback | ( | _mqttPacket_t * | pPuback | ) |
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. |
IotMqttError_t _IotMqtt_SerializeSubscribe | ( | const IotMqttSubscription_t * | pSubscriptionList, |
size_t | subscriptionCount, | ||
uint8_t ** | pSubscribePacket, | ||
size_t * | pPacketSize, | ||
uint16_t * | pPacketIdentifier | ||
) |
Generate a SUBSCRIBE packet from the given parameters.
[in] | pSubscriptionList | User-provided array of subscriptions. |
[in] | subscriptionCount | Size of pSubscriptionList . |
[out] | pSubscribePacket | Where the SUBSCRIBE packet is written. |
[out] | pPacketSize | Size of the packet written to pSubscribePacket . |
[out] | pPacketIdentifier | The packet identifier generated for this SUBSCRIBE. |
IotMqttError_t _IotMqtt_DeserializeSuback | ( | _mqttPacket_t * | pSuback | ) |
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. |
IotMqttError_t _IotMqtt_SerializeUnsubscribe | ( | const IotMqttSubscription_t * | pSubscriptionList, |
size_t | subscriptionCount, | ||
uint8_t ** | pUnsubscribePacket, | ||
size_t * | pPacketSize, | ||
uint16_t * | pPacketIdentifier | ||
) |
Generate an UNSUBSCRIBE packet from the given parameters.
[in] | pSubscriptionList | User-provided array of subscriptions to remove. |
[in] | subscriptionCount | Size of pSubscriptionList . |
[out] | pUnsubscribePacket | Where the UNSUBSCRIBE packet is written. |
[out] | pPacketSize | Size of the packet written to pUnsubscribePacket . |
[out] | pPacketIdentifier | The packet identifier generated for this UNSUBSCRIBE. |
IotMqttError_t _IotMqtt_DeserializeUnsuback | ( | _mqttPacket_t * | pUnsuback | ) |
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. |
IotMqttError_t _IotMqtt_SerializePingreq | ( | uint8_t ** | pPingreqPacket, |
size_t * | pPacketSize | ||
) |
Generate a PINGREQ packet.
[out] | pPingreqPacket | Where the PINGREQ packet is written. |
[out] | pPacketSize | Size of the packet written to pPingreqPacket . |
IotMqttError_t _IotMqtt_DeserializePingresp | ( | _mqttPacket_t * | pPingresp | ) |
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. |
IotMqttError_t _IotMqtt_SerializeDisconnect | ( | uint8_t ** | pDisconnectPacket, |
size_t * | pPacketSize | ||
) |
Generate a DISCONNECT packet.
[out] | pDisconnectPacket | Where the DISCONNECT packet is written. |
[out] | pPacketSize | Size of the packet written to pDisconnectPacket . |
void _IotMqtt_FreePacket | ( | uint8_t * | pPacket | ) |
Free a packet generated by the serializer.
[in] | pPacket | The packet to free. |