FreeRTOS: BLE
BLE
Return to main page ↑
iot_ble_mqtt_serialize.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS BLE V2.2.0
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
26 
33 #ifndef IOT_BLE_MQTT_SERIALIZE_H
34 #define IOT_BLE_MQTT_SERIALIZE_H
35 
36 /* bool is defined in only C99+. */
37 #if defined( __cplusplus ) || ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) )
38  #include <stdbool.h>
39 #elif !defined( bool ) && !defined( false ) && !defined( true )
40  #define bool int8_t
41  #define false ( int8_t ) 0
42  #define true ( int8_t ) 1
43 #endif
44 
50 #define IOT_BLE_MQTT_MSG_TYPE "w"
51 #define IOT_BLE_MQTT_CLIENT_ID "d"
52 #define IOT_BLE_MQTT_BROKER_EP "a"
53 #define IOT_BLE_MQTT_CLEAN_SESSION "c"
54 #define IOT_BLE_MQTT_TOPIC "u"
55 #define IOT_BLE_MQTT_TOPIC_LIST "v"
56 #define IOT_BLE_MQTT_QOS "n"
57 #define IOT_BLE_MQTT_QOS_LIST "o"
58 #define IOT_BLE_MQTT_MESSAGE_ID "i"
59 #define IOT_BLE_MQTT_PAYLOAD "k"
60 #define IOT_BLE_MQTT_STATUS "s"
61 
68 #define IOT_BLE_MQTT_MSG_TYPE_CONNECT ( 1 )
69 #define IOT_BLE_MQTT_MSG_TYPE_CONNACK ( 2 )
70 #define IOT_BLE_MQTT_MSG_TYPE_PUBLISH ( 3 )
71 #define IOT_BLE_MQTT_MSG_TYPE_PUBACK ( 4 )
72 #define IOT_BLE_MQTT_MSG_TYPE_PUBREC ( 5 )
73 #define IOT_BLE_MQTT_MSG_TYPE_PUBREL ( 6 )
74 #define IOT_BLE_MQTT_MSG_TYPE_PUBCOMP ( 7 )
75 #define IOT_BLE_MQTT_MSG_TYPE_SUBSCRIBE ( 8 )
76 #define IOT_BLE_MQTT_MSG_TYPE_SUBACK ( 9 )
77 #define IOT_BLE_MQTT_MSG_TYPE_UNSUBSCRIBE ( 10 )
78 #define IOT_BLE_MQTT_MSG_TYPE_UNSUBACK ( 11 )
79 #define IOT_BLE_MQTT_MSG_TYPE_PINGREQ ( 12 )
80 #define IOT_BLE_MQTT_MSG_TYPE_PINGRESP ( 13 )
81 #define IOT_BLE_MQTT_MSG_TYPE_DISCONNECT ( 14 )
82 #define IOT_BLE_MQTT_MSG_TYPE_INVALID ( 0xFF )
83 
90 typedef enum
91 {
108 typedef enum MQTTBLEQoS
109 {
112 } MQTTBLEQoS_t;
121 typedef struct MQTTBLESubscribeInfo
122 {
127 
131  const char * pTopicFilter;
132 
146 typedef struct MQTTBLEConnectInfo
147 {
152 
157 
161  const char * pClientIdentifier;
162 
167 
171  const char * pUserName;
172 
176  uint16_t userNameLength;
177 
181  const char * pPassword;
182 
186  uint16_t passwordLength;
195 typedef struct MQTTBLEPublishInfo
196 {
201 
205  bool retain;
206 
210  bool dup;
211 
215  const char * pTopicName;
216 
220  uint16_t topicNameLength;
221 
225  const void * pPayload;
226 
231 
235  bool pending;
236 
249 typedef enum MQTTBLEStatus
250 {
257 
258 
272  uint8_t ** const pConnectPacket,
273  size_t * const pPacketSize );
274 
286 MQTTBLEStatus_t IotBleMqtt_DeserializeConnack( const uint8_t * pBuffer,
287  size_t length );
288 
303  uint8_t ** const pPublishPacket,
304  size_t * const pPacketSize,
305  uint16_t packetIdentifier );
306 
315 void IotBleMqtt_PublishSetDup( uint8_t * const pPublishPacket,
316  uint8_t * pPacketIdentifierHigh,
317  uint16_t * const pNewPacketIdentifier );
318 
333  size_t length,
334  MQTTBLEPublishInfo_t * publishInfo,
335  uint16_t * packetIdentifier );
336 
349 MQTTBLEStatus_t IotBleMqtt_SerializePuback( uint16_t packetIdentifier,
350  uint8_t ** const pPubackPacket,
351  size_t * const pPacketSize );
352 
366  size_t length,
367  uint16_t * packetIdentifier );
368 
384  size_t subscriptionCount,
385  uint8_t ** const pSubscribePacket,
386  size_t * const pPacketSize,
387  uint16_t * const pPacketIdentifier );
388 
402 MQTTBLEStatus_t IotBleMqtt_DeserializeSuback( const uint8_t * pBuffer,
403  size_t length,
404  uint16_t * packetIdentifier,
405  uint8_t * pStatusCode );
406 
422  size_t subscriptionCount,
423  uint8_t ** const pUnsubscribePacket,
424  size_t * const pPacketSize,
425  uint16_t * const pPacketIdentifier );
426 
440  size_t length,
441  uint16_t * packetIdentifier );
442 
454 MQTTBLEStatus_t IotBleMqtt_SerializeDisconnect( uint8_t ** const pDisconnectPacket,
455  size_t * const pPacketSize );
456 
467 MQTTBLEStatus_t IotBleMqtt_SerializePingreq( uint8_t ** const pPingreqPacket,
468  size_t * const pPacketSize );
469 
480 MQTTBLEStatus_t IotBleMqtt_DeserializePingresp( const uint8_t * pBuffer,
481  size_t length );
482 
492 uint8_t IotBleMqtt_GetPacketType( const uint8_t * pBuffer,
493  size_t length );
494 
495 
501 void IotBleMqtt_FreePacket( uint8_t * pPacket );
502 
503 #endif /* IOT_MQTT_SERIALIZE_BLE_H */
bool retain
Whether this is a retained message.
Definition: iot_ble_mqtt_serialize.h:205
Definition: iot_ble_mqtt_serialize.h:121
Definition: iot_ble_mqtt_serialize.h:98
MQTTBLEQoS_t qos
Quality of Service for subscription.
Definition: iot_ble_mqtt_serialize.h:126
MQTTBLEStatus_t IotBleMqtt_DeserializeSuback(const uint8_t *pBuffer, size_t length, uint16_t *packetIdentifier, uint8_t *pStatusCode)
Deserialize MQTT SUBACK message received over BLE connection.
Definition: iot_ble_mqtt_serialize.h:111
bool cleanSession
Whether to establish a new, clean session or resume a previous session.
Definition: iot_ble_mqtt_serialize.h:151
MQTTBLEQoS_t
Definition: iot_ble_mqtt_serialize.h:108
Definition: iot_ble_mqtt_serialize.h:252
uint8_t IotBleMqtt_GetPacketType(const uint8_t *pBuffer, size_t length)
Gets the packet type for the MQTT message.
Definition: iot_ble_mqtt_serialize.h:251
bool pending
Pending flag for continuation of publish packet.
Definition: iot_ble_mqtt_serialize.h:235
Definition: iot_ble_mqtt_serialize.h:254
Definition: iot_ble_mqtt_serialize.h:146
uint16_t passwordLength
Length of MQTT password. Set to 0 if not used.
Definition: iot_ble_mqtt_serialize.h:186
Definition: iot_ble_mqtt_serialize.h:96
Definition: iot_ble_mqtt_serialize.h:93
uint16_t topicNameLength
Length of topic name.
Definition: iot_ble_mqtt_serialize.h:220
MQTTBLEConnectStatus_t
Definition: iot_ble_mqtt_serialize.h:90
uint16_t keepAliveSeconds
MQTT keep alive period.
Definition: iot_ble_mqtt_serialize.h:156
uint16_t clientIdentifierLength
Length of the client identifier.
Definition: iot_ble_mqtt_serialize.h:166
Definition: iot_ble_mqtt_serialize.h:92
MQTTBLEStatus_t IotBleMqtt_SerializePublish(const MQTTBLEPublishInfo_t *const pPublishInfo, uint8_t **const pPublishPacket, size_t *const pPacketSize, uint16_t packetIdentifier)
Serialize MQTT PUBLISH message sent over BLE connection.
MQTTBLEStatus_t IotBleMqtt_SerializeSubscribe(const MQTTBLESubscribeInfo_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.
Definition: iot_ble_mqtt_serialize.h:253
MQTTBLEStatus_t IotBleMqtt_DeserializePuback(uint8_t *pBuffer, size_t length, uint16_t *packetIdentifier)
Deserialize MQTT PUBACK message received from a BLE connection.
MQTTBLEStatus_t IotBleMqtt_SerializeDisconnect(uint8_t **const pDisconnectPacket, size_t *const pPacketSize)
Serialize MQTT DISCONNECT message sent over BLE connection.
size_t payloadLength
Message payload length.
Definition: iot_ble_mqtt_serialize.h:230
MQTTBLEStatus_t IotBleMqtt_SerializeConnect(const MQTTBLEConnectInfo_t *const pConnectInfo, uint8_t **const pConnectPacket, size_t *const pPacketSize)
Serialize the MQTT CONNECT message sent over BLE connection.
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.
const void * pPayload
Message payload.
Definition: iot_ble_mqtt_serialize.h:225
Definition: iot_ble_mqtt_serialize.h:97
Definition: iot_ble_mqtt_serialize.h:94
const char * pUserName
MQTT user name. Set to NULL if not used.
Definition: iot_ble_mqtt_serialize.h:171
Definition: iot_ble_mqtt_serialize.h:110
MQTTBLEStatus_t
Definition: iot_ble_mqtt_serialize.h:249
uint16_t packetIdentifier
Packet Identifier for QoS1, QoS2 publish packet.
Definition: iot_ble_mqtt_serialize.h:240
MQTTBLEStatus_t IotBleMqtt_DeserializeUnsuback(uint8_t *pBuffer, size_t length, uint16_t *packetIdentifier)
Deserialize MQTT UNSUBACK message received over BLE connection.
MQTTBLEStatus_t IotBleMqtt_SerializeUnsubscribe(const MQTTBLESubscribeInfo_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.
MQTTBLEStatus_t IotBleMqtt_DeserializePublish(uint8_t *pBuffer, size_t length, MQTTBLEPublishInfo_t *publishInfo, uint16_t *packetIdentifier)
Deserialize MQTT PUBLISH message received over BLE connection.
MQTTBLEStatus_t IotBleMqtt_SerializePuback(uint16_t packetIdentifier, uint8_t **const pPubackPacket, size_t *const pPacketSize)
Serialize MQTT PUBACK message sent over BLE connection.
const char * pClientIdentifier
MQTT client identifier. Must be unique per client.
Definition: iot_ble_mqtt_serialize.h:161
uint16_t userNameLength
Length of MQTT user name. Set to 0 if not used.
Definition: iot_ble_mqtt_serialize.h:176
MQTTBLEQoS_t qos
Quality of Service for message.
Definition: iot_ble_mqtt_serialize.h:200
MQTTBLEStatus_t IotBleMqtt_SerializePingreq(uint8_t **const pPingreqPacket, size_t *const pPacketSize)
Serializes MQTT PING request message sent over BLE connection.
Definition: iot_ble_mqtt_serialize.h:95
const char * pTopicFilter
Topic filter to subscribe to.
Definition: iot_ble_mqtt_serialize.h:131
const char * pTopicName
Topic name on which the message is published.
Definition: iot_ble_mqtt_serialize.h:215
MQTTBLEStatus_t IotBleMqtt_DeserializeConnack(const uint8_t *pBuffer, size_t length)
Deserialize MQTT CONNACK message received over BLE connection.
Definition: iot_ble_mqtt_serialize.h:255
void IotBleMqtt_FreePacket(uint8_t *pPacket)
Frees an MQTT message.
bool dup
Whether this is a duplicate publish message.
Definition: iot_ble_mqtt_serialize.h:210
MQTTBLEStatus_t IotBleMqtt_DeserializePingresp(const uint8_t *pBuffer, size_t length)
Deserializes MQTT PINGRESP received over BLE connection.
uint16_t topicFilterLength
Length of subscription topic filter.
Definition: iot_ble_mqtt_serialize.h:136
const char * pPassword
MQTT password. Set to NULL if not used.
Definition: iot_ble_mqtt_serialize.h:181
Definition: iot_ble_mqtt_serialize.h:195