FreeRTOS: BLE
BLE
Return to main page ↑
iot_ble_mqtt_serialize.h File Reference

File contains serializer and deserializer APIS for sending and receiving MQTT messages over BLE using a companion device SDK. More...

#include "types/iot_mqtt_types.h"
#include "aws_clientcredential.h"

Go to the source code of this file.

Macros

#define IOT_BLE_MQTT_MSG_TYPE   "w"
 
#define IOT_BLE_MQTT_CLIENT_ID   "d"
 
#define IOT_BLE_MQTT_BROKER_EP   "a"
 
#define IOT_BLE_MQTT_CLEAN_SESSION   "c"
 
#define IOT_BLE_MQTT_TOPIC   "u"
 
#define IOT_BLE_MQTT_TOPIC_LIST   "v"
 
#define IOT_BLE_MQTT_QOS   "n"
 
#define IOT_BLE_MQTT_QOS_LIST   "o"
 
#define IOT_BLE_MQTT_MESSAGE_ID   "i"
 
#define IOT_BLE_MQTT_PAYLOAD   "k"
 
#define IOT_BLE_MQTT_STATUS   "s"
 
#define IOT_BLE_MQTT_MSG_TYPE_CONNECT   ( 1 )
 
#define IOT_BLE_MQTT_MSG_TYPE_CONNACK   ( 2 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBLISH   ( 3 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBACK   ( 4 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBREC   ( 5 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBREL   ( 6 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBCOMP   ( 7 )
 
#define IOT_BLE_MQTT_MSG_TYPE_SUBSCRIBE   ( 8 )
 
#define IOT_BLE_MQTT_MSG_TYPE_SUBACK   ( 9 )
 
#define IOT_BLE_MQTT_MSG_TYPE_UNSUBSCRIBE   ( 10 )
 
#define IOT_BLE_MQTT_MSG_TYPE_UNSUBACK   ( 11 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PINGREQ   ( 12 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PINGRESP   ( 13 )
 
#define IOT_BLE_MQTT_MSG_TYPE_DISCONNECT   ( 14 )
 

Enumerations

enum  MQTTBLEConnectStatus_t {
  IOT_BLE_MQTT_STATUS_UNKNOWN = 0, IOT_BLE_MQTT_STATUS_CONNECTING, IOT_BLE_MQTT_STATUS_CONNECTED, IOT_BLE_MQTT_STATUS_DISCONNECTED,
  IOT_BLE_MQTT_STATUS_CONNECTION_REFUSED, IOT_BLE_MQTT_STATUS_CONNECTION_ERROR, IOT_BLE_MQTT_STATUS_PROTOCOL_ERROR
}
 

Functions

bool IotBleMqtt_InitSerialize (void)
 Initializes the serializer for MQTT messages over BLE. More...
 
void IotBleMqtt_CleanupSerialize (void)
 Cleanup the serializerfor Mqtt messages over BLE.
 
IotMqttError_t IotBleMqtt_SerializeConnect (const IotMqttConnectInfo_t *const pConnectInfo, uint8_t **const pConnectPacket, size_t *const pPacketSize)
 Serialize the MQTT CONNECT message sent over BLE connection. More...
 
IotMqttError_t IotBleMqtt_DeserializeConnack (struct _mqttPacket *pConnack)
 Deserialize MQTT CONNACK message received over BLE connection. More...
 
IotMqttError_t IotBleMqtt_SerializePublish (const IotMqttPublishInfo_t *const pPublishInfo, uint8_t **const pPublishPacket, size_t *const pPacketSize, uint16_t *const pPacketIdentifier, uint8_t **pPacketIdentifierHigh)
 Serialize MQTT PUBLISH message sent over BLE connection. More...
 
void IotBleMqtt_PublishSetDup (uint8_t *const pPublishPacket, uint8_t *pPacketIdentifierHigh, uint16_t *const pNewPacketIdentifier)
 Set the DUP flag to indicate its a duplicate QoS1/QoS2 message. More...
 
IotMqttError_t IotBleMqtt_DeserializePublish (struct _mqttPacket *pConnack)
 Deserialize MQTT PUBLISH message received over BLE connection. More...
 
IotMqttError_t IotBleMqtt_SerializePuback (uint16_t packetIdentifier, uint8_t **const pPubackPacket, size_t *const pPacketSize)
 Serialize MQTT PUBACK message sent over BLE connection. More...
 
IotMqttError_t IotBleMqtt_DeserializePuback (struct _mqttPacket *pConnack)
 Deserialize MQTT PUBACK message received from a BLE connection. More...
 
IotMqttError_t IotBleMqtt_SerializeSubscribe (const IotMqttSubscription_t *const pSubscriptionList, size_t subscriptionCount, uint8_t **const pSubscribePacket, size_t *const pPacketSize, uint16_t *const pPacketIdentifier)
 Serialize MQTT SUBSCRIBE message sent over BLE connection. More...
 
IotMqttError_t IotBleMqtt_DeserializeSuback (struct _mqttPacket *pConnack)
 Deserialize MQTT SUBACK message received over BLE connection. More...
 
IotMqttError_t IotBleMqtt_SerializeUnsubscribe (const IotMqttSubscription_t *const pSubscriptionList, size_t subscriptionCount, uint8_t **const pUnsubscribePacket, size_t *const pPacketSize, uint16_t *const pPacketIdentifier)
 Serialize MQTT UNSUBSCRIBE message sent over BLE connection. More...
 
IotMqttError_t IotBleMqtt_DeserializeUnsuback (struct _mqttPacket *pConnack)
 Deserialize MQTT UNSUBACK message received over BLE connection. More...
 
IotMqttError_t IotBleMqtt_SerializeDisconnect (uint8_t **const pDisconnectPacket, size_t *const pPacketSize)
 Serialize MQTT DISCONNECT message sent over BLE connection. More...
 
IotMqttError_t IotBleMqtt_SerializePingreq (uint8_t **const pPingreqPacket, size_t *const pPacketSize)
 Serializes MQTT PING request message sent over BLE connection. More...
 
IotMqttError_t IotBleMqtt_DeserializePingresp (struct _mqttPacket *pConnack)
 Deserializes MQTT PINGRESP received over BLE connection. More...
 
uint8_t IotBleMqtt_GetPacketType (void *pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface)
 Gets the packet type for the MQTT message. More...
 
size_t IotBleMqtt_GetRemainingLength (void *pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface)
 Gets the payload length for the MQTT message. More...
 
void IotBleMqtt_FreePacket (uint8_t *pPacket)
 Frees an MQTT message. More...
 

Detailed Description

File contains serializer and deserializer APIS for sending and receiving MQTT messages over BLE using a companion device SDK.

Enumeration Type Documentation

◆ MQTTBLEConnectStatus_t

Enumerator
IOT_BLE_MQTT_STATUS_UNKNOWN 

IOT_BLE_MQTT_STATUS_UNKNOWN Connection status unknown by the SDK.

IOT_BLE_MQTT_STATUS_CONNECTING 

IOT_BLE_MQTT_STATUS_CONNECTING SDK has sent CONNECT request to server and waiting for the response.

IOT_BLE_MQTT_STATUS_CONNECTED 

IOT_BLE_MQTT_STATUS_CONNECTED SDK is connected to the MQTT server.

IOT_BLE_MQTT_STATUS_DISCONNECTED 

IOT_BLE_MQTT_STATUS_DISCONNECTED SDK is disconnected with the MQTT server.

IOT_BLE_MQTT_STATUS_CONNECTION_REFUSED 

IOT_BLE_MQTT_STATUS_CONNECTION_REFUSED Server refused connection with the SDK.

IOT_BLE_MQTT_STATUS_CONNECTION_ERROR 

IOT_BLE_MQTT_STATUS_CONNECTION_ERROR Internal error while connecting to the server.

IOT_BLE_MQTT_STATUS_PROTOCOL_ERROR 

IOT_BLE_MQTT_STATUS_PROTOCOL_ERROR CONNECT message from the device was malformed.

Function Documentation

◆ IotBleMqtt_InitSerialize()

bool IotBleMqtt_InitSerialize ( void  )

Initializes the serializer for MQTT messages over BLE.

Returns
true or false

◆ IotBleMqtt_SerializeConnect()

IotMqttError_t IotBleMqtt_SerializeConnect ( const IotMqttConnectInfo_t *const  pConnectInfo,
uint8_t **const  pConnectPacket,
size_t *const  pPacketSize 
)

Serialize the MQTT CONNECT message sent over BLE connection.

Serialize the CONNECT message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pConnectInfoMQTT CONNECT parameters.
[in]pWillInfoWill Message parameters.
[out]pConnectPacketThe buffer containing the serialized data.
[in]pPacketSizeThe Size of the serialized data.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY.

◆ IotBleMqtt_DeserializeConnack()

IotMqttError_t IotBleMqtt_DeserializeConnack ( struct _mqttPacket *  pConnack)

Deserialize MQTT CONNACK message received over BLE connection.

Deserialize CONNACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pConnackStartPointer to start of the CONNACK message within a buffer.
[in]dataLengthLength of buffer containing the CONNACK message.
[out]pBytesProcessedLength of the CONNACK message parsed.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_BAD_RESPONSE.

◆ IotBleMqtt_SerializePublish()

IotMqttError_t IotBleMqtt_SerializePublish ( const IotMqttPublishInfo_t *const  pPublishInfo,
uint8_t **const  pPublishPacket,
size_t *const  pPacketSize,
uint16_t *const  pPacketIdentifier,
uint8_t **  pPacketIdentifierHigh 
)

Serialize MQTT PUBLISH message sent over BLE connection.

Serialize PUBLISH message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pPublishInfoPointer to the structure containing PUBLISH message parameters.
[out]pPublishPacketPointer to the serialized PUBLISH message.
[out]pPacketSizeLength of the serialized PUBLISH message.
[out]pPacketIdentifierUnique Identifier for the PUBLISH message.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY.

◆ IotBleMqtt_PublishSetDup()

void IotBleMqtt_PublishSetDup ( uint8_t *const  pPublishPacket,
uint8_t *  pPacketIdentifierHigh,
uint16_t *const  pNewPacketIdentifier 
)

Set the DUP flag to indicate its a duplicate QoS1/QoS2 message.

Sets the DUP flag in the serialized message to indicate its a duplicate QoS1/QoS2 message.

Parameters
[in]pPublishOperationThe operation containing the PUBLISH message.

◆ IotBleMqtt_DeserializePublish()

IotMqttError_t IotBleMqtt_DeserializePublish ( struct _mqttPacket *  pConnack)

Deserialize MQTT PUBLISH message received over BLE connection.

Deserializes the PUBLISH parameters from a CBOR map received over BLE connection.

Parameters
[in]pPublishStartPointer to start of the PUBLISH message within a buffer.
[in]dataLengthLength of buffer containing the PUBLISH message.
[out]pOutputParameters parsed from PUBLISH message.
[out]pPacketIdentifierUnique identifier for the PUBLISH message.
[out]pBytesProcessedLength of the PUBLISH message parsed.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_BAD_RESPONSE.

◆ IotBleMqtt_SerializePuback()

IotMqttError_t IotBleMqtt_SerializePuback ( uint16_t  packetIdentifier,
uint8_t **const  pPubackPacket,
size_t *const  pPacketSize 
)

Serialize MQTT PUBACK message sent over BLE connection.

Serializes the PUBACK parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]packetIdentifierIdentifier to be included in the PUBACK message.
[out]pPubackPacketPointer to the start of the PUBACK message.
[out]pPacketSizeLength of the PUBACK message.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY.

◆ IotBleMqtt_DeserializePuback()

IotMqttError_t IotBleMqtt_DeserializePuback ( struct _mqttPacket *  pConnack)

Deserialize MQTT PUBACK message received from a BLE connection.

Deserializes the PUBACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pPubackStartPointer to start of the PUBACK message within a buffer.
[in]dataLengthLength of buffer containing the PUBACK message.
[out]pPacketIdentifierUnique identifier for the PUBACK message.
[out]pBytesProcessedLength of the PUBACK message parsed.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_BAD_RESPONSE.

◆ IotBleMqtt_SerializeSubscribe()

IotMqttError_t IotBleMqtt_SerializeSubscribe ( const IotMqttSubscription_t *const  pSubscriptionList,
size_t  subscriptionCount,
uint8_t **const  pSubscribePacket,
size_t *const  pPacketSize,
uint16_t *const  pPacketIdentifier 
)

Serialize MQTT SUBSCRIBE message sent over BLE connection.

Serialize the SUBSCRIBE message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pSubscriptionListPointer to a array of subscriptions.
[out]subscriptionCountNumber of subscriptions.
[out]pSubscribePacketPointer to the SUBSCRIBE message.
[out]pPacketSizeLength of the SUBSCRIBE message.
[out]pPacketIdentifierUnique identifier for the SUBSCRIBE message.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY.

◆ IotBleMqtt_DeserializeSuback()

IotMqttError_t IotBleMqtt_DeserializeSuback ( struct _mqttPacket *  pConnack)

Deserialize MQTT SUBACK message received over BLE connection.

Deserializes MQTT SUBACK parameters from a CBOR map received over BLE connection. Removes the subscription callback from the connection, if it received an error response for a subscription

Parameters
[in]mqttConnectionThe MQTT connection used.
[in]pSubackStartStart of the SUBACK message within a buffer.
[in]dataLengthLength of the buffer containing SUBACK message
[out]pPacketIdentifierUnique identifier for the SUBACK message.
[out]pBytesProcessedLength of the SUBACK message parsed.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_BAD_RESPONSE.

◆ IotBleMqtt_SerializeUnsubscribe()

IotMqttError_t IotBleMqtt_SerializeUnsubscribe ( const IotMqttSubscription_t *const  pSubscriptionList,
size_t  subscriptionCount,
uint8_t **const  pUnsubscribePacket,
size_t *const  pPacketSize,
uint16_t *const  pPacketIdentifier 
)

Serialize MQTT UNSUBSCRIBE message sent over BLE connection.

Serialize the UNSUBSCRIBE message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pSubscriptionListPointer to a array of subscriptions.
[out]subscriptionCountNumber of subscriptions.
[out]pUnsubscribePacketPointer to the UNSUBSCRIBE message.
[out]pPacketSizeLength of the UNSUBSCRIBE message.
[out]pPacketIdentifierUnique identifier for the UNSUBSCRIBE message.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY.

◆ IotBleMqtt_DeserializeUnsuback()

IotMqttError_t IotBleMqtt_DeserializeUnsuback ( struct _mqttPacket *  pConnack)

Deserialize MQTT UNSUBACK message received over BLE connection.

Deserializes the UNSUBACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pUnsubackStartStart of the UNSUBACK message within a buffer.
[in]dataLengthLength of the buffer containing UNSUBACK message
[out]pPacketIdentifierUnique identifier for the UNSUBACK message.
[out]pBytesProcessedLength of the SUBACK message parsed.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_BAD_RESPONSE.

◆ IotBleMqtt_SerializeDisconnect()

IotMqttError_t IotBleMqtt_SerializeDisconnect ( uint8_t **const  pDisconnectPacket,
size_t *const  pPacketSize 
)

Serialize MQTT DISCONNECT message sent over BLE connection.

Serialize the DISCONNECT message parameters into a CBOR map to be sent over BLE connection.

Parameters
[out]pDisconnectPacketPointer to the DISCONNECT message
[out]pPacketSizeLength of the DISCONNECT message.
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY.

◆ IotBleMqtt_SerializePingreq()

IotMqttError_t IotBleMqtt_SerializePingreq ( uint8_t **const  pPingreqPacket,
size_t *const  pPacketSize 
)

Serializes MQTT PING request message sent over BLE connection.

Serializes PING request message parameters into a cbor map to be sent over BLE connection.

Parameters
[out]pPingreqPacketPointer to the PING request packet
[out]pPacketSizeSize of the PING request packet
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_NO_MEMORY

◆ IotBleMqtt_DeserializePingresp()

IotMqttError_t IotBleMqtt_DeserializePingresp ( struct _mqttPacket *  pConnack)

Deserializes MQTT PINGRESP received over BLE connection.

Deserializes PINGRESP parameters from a CBOR map received over BLE connection.

Parameters
[in]pPingrespStartPointer to start of buffer containing PING response
[in]dataLengthLength of the buffer containing PING response
[out]pBytesProcessedNumber of bytes parsed
Returns
#IOT_MQTT_SUCCESS or #IOT_MQTT_BAD_RESPONSE

◆ IotBleMqtt_GetPacketType()

uint8_t IotBleMqtt_GetPacketType ( void *  pNetworkConnection,
const IotNetworkInterface_t pNetworkInterface 
)

Gets the packet type for the MQTT message.

Parses the CBOR message received and gets the packet type.

Parameters
[in]pPacketPointer to the start of the packet
[in]packetSizelength of the buffer containing the packet
Returns
Packet type for the packet

◆ IotBleMqtt_GetRemainingLength()

size_t IotBleMqtt_GetRemainingLength ( void *  pNetworkConnection,
const IotNetworkInterface_t pNetworkInterface 
)

Gets the payload length for the MQTT message.

Parses the CBOR message received and gets the remaining payload length.

Parameters
[in]pPacketPointer to the start of the packet
[in]packetSizelength of the buffer containing the packet
Returns
Packet type for the packet

◆ IotBleMqtt_FreePacket()

void IotBleMqtt_FreePacket ( uint8_t *  pPacket)

Frees an MQTT message.

Parameters
[in]Pointerto the message.