MQTT API Reference
MQTT 3.1.1 client library
iot_mqtt_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of
5  * this software and associated documentation files (the "Software"), to deal in
6  * the Software without restriction, including without limitation the rights to
7  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8  * the Software, and to permit persons to whom the Software is furnished to do so,
9  * subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21 
28 #ifndef IOT_MQTT_INTERNAL_H_
29 #define IOT_MQTT_INTERNAL_H_
30 
31 /* The config header is always included first. */
32 #include "iot_config.h"
33 
34 /* Linear containers (lists and queues) include. */
35 #include "iot_linear_containers.h"
36 
37 /* MQTT include. */
38 #include "iot_mqtt.h"
39 
40 /* Task pool include. */
41 #include "iot_taskpool.h"
42 
52 #if IOT_MQTT_ENABLE_ASSERTS == 1
53  #ifndef IotMqtt_Assert
54  #ifdef Iot_DefaultAssert
55  #define IotMqtt_Assert( expression ) Iot_DefaultAssert( expression )
56  #else
57  #error "Asserts are enabled for MQTT, but IotMqtt_Assert is not defined"
58  #endif
59  #endif
60 #else
61  #define IotMqtt_Assert( expression )
62 #endif
63 
64 /* Configure logs for MQTT functions. */
65 #ifdef IOT_LOG_LEVEL_MQTT
66  #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_MQTT
67 #else
68  #ifdef IOT_LOG_LEVEL_GLOBAL
69  #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_GLOBAL
70  #else
71  #define LIBRARY_LOG_LEVEL IOT_LOG_NONE
72  #endif
73 #endif
74 
75 #define LIBRARY_LOG_NAME ( "MQTT" )
76 #include "iot_logging_setup.h"
77 
78 /*
79  * Provide default values for undefined memory allocation functions based on
80  * the usage of dynamic memory allocation.
81  */
82 #if IOT_STATIC_MEMORY_ONLY == 1
84 
90  void * IotMqtt_MallocConnection( size_t size );
91 
97  void IotMqtt_FreeConnection( void * ptr );
98 
104  #define IotMqtt_MallocMessage Iot_MallocMessageBuffer
105 
111  #define IotMqtt_FreeMessage Iot_FreeMessageBuffer
112 
118  void * IotMqtt_MallocOperation( size_t size );
119 
125  void IotMqtt_FreeOperation( void * ptr );
126 
132  void * IotMqtt_MallocSubscription( size_t size );
133 
139  void IotMqtt_FreeSubscription( void * ptr );
140 #else /* if IOT_STATIC_MEMORY_ONLY == 1 */
141  #ifndef IotMqtt_MallocConnection
142  #ifdef Iot_DefaultMalloc
143  #define IotMqtt_MallocConnection Iot_DefaultMalloc
144  #else
145  #error "No malloc function defined for IotMqtt_MallocConnection"
146  #endif
147  #endif
148 
149  #ifndef IotMqtt_FreeConnection
150  #ifdef Iot_DefaultFree
151  #define IotMqtt_FreeConnection Iot_DefaultFree
152  #else
153  #error "No free function defined for IotMqtt_FreeConnection"
154  #endif
155  #endif
156 
157  #ifndef IotMqtt_MallocMessage
158  #ifdef Iot_DefaultMalloc
159  #define IotMqtt_MallocMessage Iot_DefaultMalloc
160  #else
161  #error "No malloc function defined for IotMqtt_MallocMessage"
162  #endif
163  #endif
164 
165  #ifndef IotMqtt_FreeMessage
166  #ifdef Iot_DefaultFree
167  #define IotMqtt_FreeMessage Iot_DefaultFree
168  #else
169  #error "No free function defined for IotMqtt_FreeMessage"
170  #endif
171  #endif
172 
173  #ifndef IotMqtt_MallocOperation
174  #ifdef Iot_DefaultMalloc
175  #define IotMqtt_MallocOperation Iot_DefaultMalloc
176  #else
177  #error "No malloc function defined for IotMqtt_MallocOperation"
178  #endif
179  #endif
180 
181  #ifndef IotMqtt_FreeOperation
182  #ifdef Iot_DefaultFree
183  #define IotMqtt_FreeOperation Iot_DefaultFree
184  #else
185  #error "No free function defined for IotMqtt_FreeOperation"
186  #endif
187  #endif
188 
189  #ifndef IotMqtt_MallocSubscription
190  #ifdef Iot_DefaultMalloc
191  #define IotMqtt_MallocSubscription Iot_DefaultMalloc
192  #else
193  #error "No malloc function defined for IotMqtt_MallocSubscription"
194  #endif
195  #endif
196 
197  #ifndef IotMqtt_FreeSubscription
198  #ifdef Iot_DefaultFree
199  #define IotMqtt_FreeSubscription Iot_DefaultFree
200  #else
201  #error "No free function defined for IotMqtt_FreeSubscription"
202  #endif
203  #endif
204 #endif /* if IOT_STATIC_MEMORY_ONLY == 1 */
205 
212 #ifndef AWS_IOT_MQTT_ENABLE_METRICS
213  #define AWS_IOT_MQTT_ENABLE_METRICS ( 1 )
214 #endif
215 #ifndef IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES
216  #define IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES ( 0 )
217 #endif
218 #ifndef IOT_MQTT_RESPONSE_WAIT_MS
219  #define IOT_MQTT_RESPONSE_WAIT_MS ( 1000 )
220 #endif
221 #ifndef IOT_MQTT_RETRY_MS_CEILING
222  #define IOT_MQTT_RETRY_MS_CEILING ( 60000 )
223 #endif
224 
233 #ifndef EMPTY_ELSE_MARKER
234  #define EMPTY_ELSE_MARKER
235 #endif
236 
237 /*
238  * Constants related to limits defined in AWS Service Limits.
239  *
240  * For details, see
241  * https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html
242  *
243  * Used to validate parameters if when connecting to an AWS IoT MQTT server.
244  */
245 #define AWS_IOT_MQTT_SERVER_MAX_CLIENTID ( 128 )
246 #define AWS_IOT_MQTT_SERVER_MAX_TOPIC_LENGTH ( 256 )
247 #define AWS_IOT_MQTT_SERVER_MAX_TOPIC_FILTERS_PER_SUBSCRIBE ( 8 )
249 /*
250  * MQTT control packet type and flags. Always the first byte of an MQTT
251  * packet.
252  *
253  * For details, see
254  * http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/csprd02/mqtt-v3.1.1-csprd02.html#_Toc385349757
255  */
256 #define MQTT_PACKET_TYPE_CONNECT ( ( uint8_t ) 0x10U )
257 #define MQTT_PACKET_TYPE_CONNACK ( ( uint8_t ) 0x20U )
258 #define MQTT_PACKET_TYPE_PUBLISH ( ( uint8_t ) 0x30U )
259 #define MQTT_PACKET_TYPE_PUBACK ( ( uint8_t ) 0x40U )
260 #define MQTT_PACKET_TYPE_SUBSCRIBE ( ( uint8_t ) 0x82U )
261 #define MQTT_PACKET_TYPE_SUBACK ( ( uint8_t ) 0x90U )
262 #define MQTT_PACKET_TYPE_UNSUBSCRIBE ( ( uint8_t ) 0xa2U )
263 #define MQTT_PACKET_TYPE_UNSUBACK ( ( uint8_t ) 0xb0U )
264 #define MQTT_PACKET_TYPE_PINGREQ ( ( uint8_t ) 0xc0U )
265 #define MQTT_PACKET_TYPE_PINGRESP ( ( uint8_t ) 0xd0U )
266 #define MQTT_PACKET_TYPE_DISCONNECT ( ( uint8_t ) 0xe0U )
273 #define MQTT_REMAINING_LENGTH_INVALID ( ( size_t ) 268435456 )
274 
283 #define MQTT_INTERNAL_FLAG_BLOCK_ON_SEND ( 0x80000000 )
284 
285 /*---------------------- MQTT internal data structures ----------------------*/
286 
293 struct _mqttConnection;
302 typedef struct _mqttOperation
303 {
304  /* Pointers to neighboring queue elements. */
308  struct _mqttConnection * pMqttConnection;
313  union
314  {
315  /* If incomingPublish is false, this struct is valid. */
316  struct
317  {
318  /* Basic operation information. */
319  int32_t jobReference;
321  uint32_t flags;
322  uint16_t packetIdentifier;
324  /* Serialized packet and size. */
325  uint8_t * pMqttPacket;
327  size_t packetSize;
329  /* How to notify of an operation's completion. */
330  union
331  {
334  } notify;
337  union
338  {
339  struct
340  {
341  uint32_t count;
342  uint32_t limit;
343  uint32_t nextPeriodMs;
344  } retry;
346  struct
347  {
348  uint32_t failure;
349  uint32_t keepAliveMs;
350  uint32_t nextPeriodMs;
351  } ping;
352  } periodic;
353  } operation;
354 
355  /* If incomingPublish is true, this struct is valid. */
356  struct
357  {
359  const void * pReceivedData;
360  } publish;
361  } u;
363 
367 typedef struct _mqttConnection
368 {
375  #if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES == 1
377  #endif
378 
381  int32_t references;
390 
394 typedef struct _mqttSubscription
395 {
398  int32_t references;
409 
410  struct
411  {
412  uint16_t identifier;
413  size_t order;
414  } packetInfo;
418  uint16_t topicFilterLength;
419  char pTopicFilter[];
421 
428 typedef struct _mqttPacket
429 {
430  union
431  {
437 
443  } u;
445  uint8_t * pRemainingData;
447  uint16_t packetIdentifier;
448  uint8_t type;
449 } _mqttPacket_t;
450 
451 /*-------------------- MQTT struct validation functions ---------------------*/
452 
460 bool _IotMqtt_ValidateConnect( const IotMqttConnectInfo_t * pConnectInfo );
461 
471 bool _IotMqtt_ValidatePublish( bool awsIotMqttMode,
472  const IotMqttPublishInfo_t * pPublishInfo );
473 
482 
496  bool awsIotMqttMode,
497  const IotMqttSubscription_t * pListStart,
498  size_t listSize );
499 
500 /*-------------------- MQTT packet serializer functions ---------------------*/
501 
514 uint8_t _IotMqtt_GetPacketType( void * pNetworkConnection,
515  const IotNetworkInterface_t * pNetworkInterface );
516 
526 size_t _IotMqtt_GetRemainingLength( void * pNetworkConnection,
527  const IotNetworkInterface_t * pNetworkInterface );
528 
539  uint8_t ** pConnectPacket,
540  size_t * pPacketSize );
541 
555 
569  uint8_t ** pPublishPacket,
570  size_t * pPacketSize,
571  uint16_t * pPacketIdentifier,
572  uint8_t ** pPacketIdentifierHigh );
573 
586 void _IotMqtt_PublishSetDup( uint8_t * pPublishPacket,
587  uint8_t * pPacketIdentifierHigh,
588  uint16_t * pNewPacketIdentifier );
589 
603 
613 IotMqttError_t _IotMqtt_SerializePuback( uint16_t packetIdentifier,
614  uint8_t ** pPubackPacket,
615  size_t * pPacketSize );
616 
629 
642  size_t subscriptionCount,
643  uint8_t ** pSubscribePacket,
644  size_t * pPacketSize,
645  uint16_t * pPacketIdentifier );
646 
659 
672  size_t subscriptionCount,
673  uint8_t ** pUnsubscribePacket,
674  size_t * pPacketSize,
675  uint16_t * pPacketIdentifier );
676 
689 
698 IotMqttError_t _IotMqtt_SerializePingreq( uint8_t ** pPingreqPacket,
699  size_t * pPacketSize );
700 
713 
722 IotMqttError_t _IotMqtt_SerializeDisconnect( uint8_t ** pDisconnectPacket,
723  size_t * pPacketSize );
724 
730 void _IotMqtt_FreePacket( uint8_t * pPacket );
731 
732 /*-------------------- MQTT operation record functions ----------------------*/
733 
745  uint32_t flags,
746  const IotMqttCallbackInfo_t * pCallbackInfo,
747  _mqttOperation_t ** pNewOperation );
748 
761  bool cancelJob );
762 
769 void _IotMqtt_DestroyOperation( _mqttOperation_t * pOperation );
770 
779  IotTaskPoolJob_t pKeepAliveJob,
780  void * pContext );
781 
791  IotTaskPoolJob_t pPublishJob,
792  void * pContext );
793 
802 void _IotMqtt_ProcessSend( IotTaskPool_t pTaskPool,
803  IotTaskPoolJob_t pSendJob,
804  void * pContext );
805 
815  IotTaskPoolJob_t pOperationJob,
816  void * pContext );
817 
831  IotTaskPoolRoutine_t jobRoutine,
832  uint32_t delay );
833 
846  const uint16_t * pPacketIdentifier );
847 
857 void _IotMqtt_Notify( _mqttOperation_t * pOperation );
858 
859 /*----------------- MQTT subscription management functions ------------------*/
860 
873  uint16_t subscribePacketIdentifier,
874  const IotMqttSubscription_t * pSubscriptionList,
875  size_t subscriptionCount );
876 
886  IotMqttCallbackParam_t * pCallbackParam );
887 
899  uint16_t packetIdentifier,
900  int32_t order );
901 
911  const IotMqttSubscription_t * pSubscriptionList,
912  size_t subscriptionCount );
913 
914 /*------------------ MQTT connection management functions -------------------*/
915 
925 
934 
946 bool _IotMqtt_GetNextByte( void * pNetworkConnection,
947  const IotNetworkInterface_t * pNetworkInterface,
948  uint8_t * pIncomingByte );
949 
962  _mqttConnection_t * pMqttConnection );
963 
964 #endif /* ifndef IOT_MQTT_INTERNAL_H_ */
_IotMqtt_ProcessKeepAlive
void _IotMqtt_ProcessKeepAlive(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pKeepAliveJob, void *pContext)
Task pool routine for processing an MQTT connection's keep-alive.
Definition: iot_mqtt_operation.c:672
_IotMqtt_DeserializePublish
IotMqttError_t _IotMqtt_DeserializePublish(_mqttPacket_t *pPublish)
Deserialize a PUBLISH packet received from the server.
Definition: iot_mqtt_serialize.c:1191
_mqttSubscription_t::order
size_t order
Order in the packet's list of subscriptions.
Definition: iot_mqtt_internal.h:413
_IotMqtt_DecrementConnectionReferences
void _IotMqtt_DecrementConnectionReferences(_mqttConnection_t *pMqttConnection)
Decrement the reference count of an MQTT connection.
Definition: iot_mqtt_api.c:864
IotTaskPoolRoutine_t
void(* IotTaskPoolRoutine_t)(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext)
_mqttOperation_t::jobReference
int32_t jobReference
Tracks if a job is using this operation. Must always be 0, 1, or 2.
Definition: iot_mqtt_internal.h:319
IotSemaphore_t
_IotSystemSemaphore_t IotSemaphore_t
_mqttOperation_t::keepAliveMs
uint32_t keepAliveMs
Keep-alive interval in milliseconds. Its max value (per spec) is 65,535,000.
Definition: iot_mqtt_internal.h:349
IotMqtt_FreeOperation
void IotMqtt_FreeOperation(void *ptr)
Free an _mqttOperation_t. This function should have the same signature as free.
_IotMqtt_DeserializePingresp
IotMqttError_t _IotMqtt_DeserializePingresp(_mqttPacket_t *pPingresp)
Deserialize a PINGRESP packet.
Definition: iot_mqtt_serialize.c:1851
_IotMqtt_RemoveSubscriptionByPacket
void _IotMqtt_RemoveSubscriptionByPacket(_mqttConnection_t *pMqttConnection, uint16_t packetIdentifier, int32_t order)
Remove a single subscription from the subscription manager by packetIdentifier and order.
Definition: iot_mqtt_subscription.c:503
_mqttOperation_t::pPacketIdentifierHigh
uint8_t * pPacketIdentifierHigh
The location of the high byte of the packet identifier in the MQTT packet.
Definition: iot_mqtt_internal.h:326
_IotMqtt_ValidatePublish
bool _IotMqtt_ValidatePublish(bool awsIotMqttMode, const IotMqttPublishInfo_t *pPublishInfo)
Check that an IotMqttPublishInfo_t is valid.
Definition: iot_mqtt_validate.c:153
_mqttConnection_t::disconnectCallback
IotMqttCallbackInfo_t disconnectCallback
A function to invoke when this connection is disconnected.
Definition: iot_mqtt_internal.h:373
_mqttOperation_t::incomingPublish
bool incomingPublish
Set to true if this operation an incoming PUBLISH.
Definition: iot_mqtt_internal.h:307
_IotMqtt_CloseNetworkConnection
void _IotMqtt_CloseNetworkConnection(IotMqttDisconnectReason_t disconnectReason, _mqttConnection_t *pMqttConnection)
Closes the network connection associated with an MQTT connection.
Definition: iot_mqtt_network.c:800
_mqttConnection_t::pingreq
_mqttOperation_t pingreq
Operation used for MQTT keep-alive.
Definition: iot_mqtt_internal.h:388
_mqttOperation_t::pMqttPacket
uint8_t * pMqttPacket
The MQTT packet to send over the network.
Definition: iot_mqtt_internal.h:325
_IotMqtt_SerializePuback
IotMqttError_t _IotMqtt_SerializePuback(uint16_t packetIdentifier, uint8_t **pPubackPacket, size_t *pPacketSize)
Generate a PUBACK packet for the given packet identifier.
Definition: iot_mqtt_serialize.c:1392
IotMutex_t
_IotSystemMutex_t IotMutex_t
_mqttOperation_t::link
IotLink_t link
List link member.
Definition: iot_mqtt_internal.h:305
_mqttConnection_t::subscriptionList
IotListDouble_t subscriptionList
Holds subscriptions associated with this connection.
Definition: iot_mqtt_internal.h:385
_mqttPacket_t::pIncomingPublish
_mqttOperation_t * pIncomingPublish
(Output) Operation representing an incoming PUBLISH. Only used when deserializing PUBLISHes.
Definition: iot_mqtt_internal.h:442
_mqttOperation_t::job
IotTaskPoolJob_t job
Task pool job associated with this operation.
Definition: iot_mqtt_internal.h:311
_mqttSubscription_t
Represents a subscription stored in an MQTT connection.
Definition: iot_mqtt_internal.h:394
IotMqttError_t
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
_IotMqtt_SerializeConnect
IotMqttError_t _IotMqtt_SerializeConnect(const IotMqttConnectInfo_t *pConnectInfo, uint8_t **pConnectPacket, size_t *pPacketSize)
Generate a CONNECT packet from the given parameters.
Definition: iot_mqtt_serialize.c:668
IotMqttCallbackInfo_t
Information on a user-provided MQTT callback function.
Definition: iot_mqtt_types.h:516
_IotMqtt_FindOperation
_mqttOperation_t * _IotMqtt_FindOperation(_mqttConnection_t *pMqttConnection, IotMqttOperationType_t type, const uint16_t *pPacketIdentifier)
Search a list of MQTT operations pending responses using an operation name and packet identifier....
Definition: iot_mqtt_operation.c:1132
_mqttSubscription_t::identifier
uint16_t identifier
Packet identifier.
Definition: iot_mqtt_internal.h:412
_IotMqtt_DeserializePuback
IotMqttError_t _IotMqtt_DeserializePuback(_mqttPacket_t *pPuback)
Deserialize a PUBACK packet.
Definition: iot_mqtt_serialize.c:1428
_mqttSubscription_t::topicFilterLength
uint16_t topicFilterLength
Length of _mqttSubscription_t.pTopicFilter.
Definition: iot_mqtt_internal.h:418
_IotMqtt_ValidateSubscriptionList
bool _IotMqtt_ValidateSubscriptionList(IotMqttOperationType_t operation, bool awsIotMqttMode, const IotMqttSubscription_t *pListStart, size_t listSize)
Check that a list of IotMqttSubscription_t is valid.
Definition: iot_mqtt_validate.c:319
IotTaskPool_t
struct _taskPool * IotTaskPool_t
_IotMqtt_InvokeSubscriptionCallback
void _IotMqtt_InvokeSubscriptionCallback(_mqttConnection_t *pMqttConnection, IotMqttCallbackParam_t *pCallbackParam)
Process a received PUBLISH from the server, invoking any subscription callbacks that have a matching ...
Definition: iot_mqtt_subscription.c:396
_mqttOperation_t::waitSemaphore
IotSemaphore_t waitSemaphore
Semaphore to be used with IotMqtt_Wait.
Definition: iot_mqtt_internal.h:332
_mqttOperation_t::callback
IotMqttCallbackInfo_t callback
User-provided callback function and parameter.
Definition: iot_mqtt_internal.h:333
IotMqttOperation_t
struct _mqttOperation * IotMqttOperation_t
Opaque handle that references an in-progress MQTT operation.
Definition: iot_mqtt_types.h:88
_IotMqtt_ScheduleOperation
IotMqttError_t _IotMqtt_ScheduleOperation(_mqttOperation_t *pOperation, IotTaskPoolRoutine_t jobRoutine, uint32_t delay)
Schedule an operation for immediate processing.
Definition: iot_mqtt_operation.c:1084
_IotMqtt_GetPacketType
uint8_t _IotMqtt_GetPacketType(void *pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface)
Get the MQTT packet type from a stream of bytes off the network.
Definition: iot_mqtt_serialize.c:596
_mqttOperation_t
Internal structure representing a single MQTT operation, such as CONNECT, SUBSCRIBE,...
Definition: iot_mqtt_internal.h:302
_IotMqtt_GetRemainingLength
size_t _IotMqtt_GetRemainingLength(void *pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface)
Get the remaining length from a stream of bytes off the network.
Definition: iot_mqtt_serialize.c:611
_mqttOperation_t::type
IotMqttOperationType_t type
What operation this structure represents.
Definition: iot_mqtt_internal.h:320
IotMqttDisconnectReason_t
IotMqttDisconnectReason_t
The reason that an MQTT connection (and its associated network connection) was disconnected.
Definition: iot_mqtt_types.h:320
_IotMqtt_ProcessSend
void _IotMqtt_ProcessSend(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pSendJob, void *pContext)
Task pool routine for processing an MQTT operation to send.
Definition: iot_mqtt_operation.c:863
_mqttPacket_t::packetIdentifier
uint16_t packetIdentifier
(Output) MQTT packet identifier.
Definition: iot_mqtt_internal.h:447
_mqttConnection_t::pendingResponse
IotListDouble_t pendingResponse
List of processed operations awaiting a server response.
Definition: iot_mqtt_internal.h:383
iot_mqtt.h
User-facing functions of the MQTT 3.1.1 library.
_IotMqtt_DeserializeSuback
IotMqttError_t _IotMqtt_DeserializeSuback(_mqttPacket_t *pSuback)
Deserialize a SUBACK packet.
Definition: iot_mqtt_serialize.c:1579
IotMqtt_FreeSubscription
void IotMqtt_FreeSubscription(void *ptr)
Free an _mqttSubscription_t. This function should have the same signature as free.
_mqttConnection_t
Represents an MQTT connection.
Definition: iot_mqtt_internal.h:367
_mqttConnection_t::pSerializer
const IotMqttSerializer_t * pSerializer
MQTT packet serializer overrides.
Definition: iot_mqtt_internal.h:376
_mqttPacket_t::pRemainingData
uint8_t * pRemainingData
(Input) The remaining data in MQTT packet.
Definition: iot_mqtt_internal.h:445
_mqttOperation_t::pMqttConnection
struct _mqttConnection * pMqttConnection
MQTT connection associated with this operation.
Definition: iot_mqtt_internal.h:308
_mqttOperation_t::pReceivedData
const void * pReceivedData
Any buffer associated with this PUBLISH that should be freed.
Definition: iot_mqtt_internal.h:359
IotMqttSerializer_t
Function pointers for MQTT packet serializer overrides.
Definition: iot_mqtt_types.h:715
_mqttOperation_t::failure
uint32_t failure
Flag tracking keep-alive status.
Definition: iot_mqtt_internal.h:348
_mqttConnection_t::ownNetworkConnection
bool ownNetworkConnection
Whether this MQTT connection owns its network connection.
Definition: iot_mqtt_internal.h:370
_IotMqtt_ProcessIncomingPublish
void _IotMqtt_ProcessIncomingPublish(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pPublishJob, void *pContext)
Task pool routine for processing an incoming PUBLISH message.
Definition: iot_mqtt_operation.c:817
_IotMqtt_SerializeSubscribe
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.
Definition: iot_mqtt_serialize.c:1485
_mqttOperation_t::nextPeriodMs
uint32_t nextPeriodMs
Next retry period.
Definition: iot_mqtt_internal.h:343
_IotMqtt_DecrementOperationReferences
bool _IotMqtt_DecrementOperationReferences(_mqttOperation_t *pOperation, bool cancelJob)
Decrement the job reference count of an MQTT operation and optionally cancel its job.
Definition: iot_mqtt_operation.c:495
_IotMqtt_DeserializeConnack
IotMqttError_t _IotMqtt_DeserializeConnack(_mqttPacket_t *pConnack)
Deserialize a CONNACK packet.
Definition: iot_mqtt_serialize.c:887
_mqttPacket_t::type
uint8_t type
(Input) A value identifying the packet type.
Definition: iot_mqtt_internal.h:448
_IotMqtt_PublishSetDup
void _IotMqtt_PublishSetDup(uint8_t *pPublishPacket, uint8_t *pPacketIdentifierHigh, uint16_t *pNewPacketIdentifier)
Set the DUP bit in a QoS 1 PUBLISH packet.
Definition: iot_mqtt_serialize.c:1156
_IotMqtt_DeserializeUnsuback
IotMqttError_t _IotMqtt_DeserializeUnsuback(_mqttPacket_t *pUnsuback)
Deserialize a UNSUBACK packet.
Definition: iot_mqtt_serialize.c:1772
_IotMqtt_ValidateConnect
bool _IotMqtt_ValidateConnect(const IotMqttConnectInfo_t *pConnectInfo)
Check that an IotMqttConnectInfo_t is valid.
Definition: iot_mqtt_validate.c:38
_mqttConnection_t::disconnected
bool disconnected
Tracks if this connection has been disconnected.
Definition: iot_mqtt_internal.h:379
_mqttSubscription_t::unsubscribed
bool unsubscribed
Tracks whether an unsubscribe function has been called for this subscription.
Definition: iot_mqtt_internal.h:408
_mqttConnection_t::references
int32_t references
Counts callbacks and operations using this connection.
Definition: iot_mqtt_internal.h:381
_mqttPacket_t::pMqttConnection
_mqttConnection_t * pMqttConnection
(Input) MQTT connection associated with this packet. Only used when deserializing SUBACKs.
Definition: iot_mqtt_internal.h:436
_mqttPacket_t
Represents an MQTT packet received from the network.
Definition: iot_mqtt_internal.h:428
IotMqttOperationType_t
IotMqttOperationType_t
Types of MQTT operations.
Definition: iot_mqtt_types.h:277
_IotMqtt_FreePacket
void _IotMqtt_FreePacket(uint8_t *pPacket)
Free a packet generated by the serializer.
Definition: iot_mqtt_serialize.c:1912
_mqttConnection_t::pendingProcessing
IotListDouble_t pendingProcessing
List of operations waiting to be processed by a task pool routine.
Definition: iot_mqtt_internal.h:382
IotMqtt_MallocOperation
void * IotMqtt_MallocOperation(size_t size)
Allocate an _mqttOperation_t. This function should have the same signature as malloc.
_mqttOperation_t::status
IotMqttError_t status
Result of this operation. This is reported once a response is received.
Definition: iot_mqtt_internal.h:335
IotMqttSubscription_t
Information on an MQTT subscription.
Definition: iot_mqtt_types.h:550
IotMqtt_MallocConnection
void * IotMqtt_MallocConnection(size_t size)
Allocate an _mqttConnection_t. This function should have the same signature as malloc.
IotTaskPoolJobStorage_t
_mqttSubscription_t::references
int32_t references
How many subscription callbacks are using this subscription.
Definition: iot_mqtt_internal.h:398
_IotMqtt_DestroyOperation
void _IotMqtt_DestroyOperation(_mqttOperation_t *pOperation)
Free resources used to record an MQTT operation. This is called when the operation completes.
Definition: iot_mqtt_operation.c:566
_mqttOperation_t::publishInfo
IotMqttPublishInfo_t publishInfo
Deserialized PUBLISH.
Definition: iot_mqtt_internal.h:358
IotNetworkInterface_t
_IotMqtt_ValidateOperation
bool _IotMqtt_ValidateOperation(IotMqttOperation_t operation)
Check that an IotMqttOperation_t is valid and waitable.
Definition: iot_mqtt_validate.c:286
_mqttOperation_t::flags
uint32_t flags
Flags passed to the function that created this operation.
Definition: iot_mqtt_internal.h:321
iot_taskpool.h
iot_static_memory.h
_mqttConnection_t::awsIotMqttMode
bool awsIotMqttMode
Specifies if this connection is to an AWS IoT MQTT server.
Definition: iot_mqtt_internal.h:369
_mqttConnection_t::subscriptionMutex
IotMutex_t subscriptionMutex
Grants exclusive access to the subscription list.
Definition: iot_mqtt_internal.h:386
_mqttOperation_t::jobStorage
IotTaskPoolJobStorage_t jobStorage
Task pool job storage associated with this operation.
Definition: iot_mqtt_internal.h:310
_mqttSubscription_t::callback
IotMqttCallbackInfo_t callback
Callback information for this subscription.
Definition: iot_mqtt_internal.h:416
_mqttConnection_t::pNetworkInterface
const IotNetworkInterface_t * pNetworkInterface
Network interface provided to IotMqtt_Connect.
Definition: iot_mqtt_internal.h:372
_IotMqtt_RemoveSubscriptionByTopicFilter
void _IotMqtt_RemoveSubscriptionByTopicFilter(_mqttConnection_t *pMqttConnection, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount)
Remove an array of subscriptions from the subscription manager by topic filter.
Definition: iot_mqtt_subscription.c:524
_IotMqtt_SerializeUnsubscribe
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.
Definition: iot_mqtt_serialize.c:1682
IotMqttPublishInfo_t
Information on a PUBLISH message.
Definition: iot_mqtt_types.h:397
_IotMqtt_SerializeDisconnect
IotMqttError_t _IotMqtt_SerializeDisconnect(uint8_t **pDisconnectPacket, size_t *pPacketSize)
Generate a DISCONNECT packet.
Definition: iot_mqtt_serialize.c:1890
_mqttOperation_t::packetIdentifier
uint16_t packetIdentifier
The packet identifier used with this operation.
Definition: iot_mqtt_internal.h:322
IotMqttCallbackParam_t
Parameter to an MQTT callback function.
Definition: iot_mqtt_types.h:443
_IotMqtt_ProcessCompletedOperation
void _IotMqtt_ProcessCompletedOperation(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pOperationJob, void *pContext)
Task pool routine for processing a completed MQTT operation.
Definition: iot_mqtt_operation.c:1045
iot_linear_containers.h
_mqttOperation_t::limit
uint32_t limit
Maximum number of retries allowed.
Definition: iot_mqtt_internal.h:342
_IotMqtt_CreateOperation
IotMqttError_t _IotMqtt_CreateOperation(_mqttConnection_t *pMqttConnection, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, _mqttOperation_t **pNewOperation)
Create a record for a new in-progress MQTT operation.
Definition: iot_mqtt_operation.c:348
_mqttConnection_t::referencesMutex
IotMutex_t referencesMutex
Recursive mutex. Grants access to connection state and operation lists.
Definition: iot_mqtt_internal.h:380
_IotMqtt_SerializePublish
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.
Definition: iot_mqtt_serialize.c:1018
_mqttSubscription_t::link
IotLink_t link
List link member.
Definition: iot_mqtt_internal.h:396
_IotMqtt_SerializePingreq
IotMqttError_t _IotMqtt_SerializePingreq(uint8_t **pPingreqPacket, size_t *pPacketSize)
Generate a PINGREQ packet.
Definition: iot_mqtt_serialize.c:1829
_mqttConnection_t::pNetworkConnection
void * pNetworkConnection
References the transport-layer network connection.
Definition: iot_mqtt_internal.h:371
IotMqtt_MallocSubscription
void * IotMqtt_MallocSubscription(size_t size)
Allocate an _mqttSubscription_t. This function should have the same signature as malloc.
_mqttPacket_t::remainingLength
size_t remainingLength
(Input) Length of the remaining data in the MQTT packet.
Definition: iot_mqtt_internal.h:446
_IotMqtt_GetNextByte
bool _IotMqtt_GetNextByte(void *pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface, uint8_t *pIncomingByte)
Read the next available byte on a network connection.
Definition: iot_mqtt_network.c:770
iot_logging_setup.h
_IotMqtt_IncrementConnectionReferences
bool _IotMqtt_IncrementConnectionReferences(_mqttConnection_t *pMqttConnection)
Attempt to increment the reference count of an MQTT connection.
Definition: iot_mqtt_api.c:830
IotTaskPoolJob_t
struct _taskPoolJob * IotTaskPoolJob_t
_mqttOperation_t::packetSize
size_t packetSize
Size of pMqttPacket.
Definition: iot_mqtt_internal.h:327
_IotMqtt_AddSubscriptions
IotMqttError_t _IotMqtt_AddSubscriptions(_mqttConnection_t *pMqttConnection, uint16_t subscribePacketIdentifier, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount)
Add an array of subscriptions to the subscription manager.
Definition: iot_mqtt_subscription.c:309
_mqttOperation_t::count
uint32_t count
Current number of retries.
Definition: iot_mqtt_internal.h:341
_IotMqtt_Notify
void _IotMqtt_Notify(_mqttOperation_t *pOperation)
Notify of a completed MQTT operation.
Definition: iot_mqtt_operation.c:1245
IotMqttConnectInfo_t
Information on a new MQTT connection.
Definition: iot_mqtt_types.h:585
IotMqtt_FreeConnection
void IotMqtt_FreeConnection(void *ptr)
Free an _mqttConnection_t. This function should have the same signature as free.