CommsChampion Ecosystem MQTT-SN Client
MQTT-SN client library.
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1//
2// Copyright 2016 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
10
11#pragma once
12
13#ifdef __cplusplus
14extern "C" {
15#else // #ifdef __cplusplus
16#include <stdbool.h>
17#endif // #ifdef __cplusplus
18
21#define CC_MQTTSN_CLIENT_MAJOR_VERSION 2U
22
25#define CC_MQTTSN_CLIENT_MINOR_VERSION 0U
26
29#define CC_MQTTSN_CLIENT_PATCH_VERSION 5U
30
32#define CC_MQTTSN_CLIENT_MAKE_VERSION(major_, minor_, patch_) \
33 ((static_cast<unsigned>(major_) << 24) | \
34 (static_cast<unsigned>(minor_) << 8) | \
35 (static_cast<unsigned>(patch_)))
36
38#define CC_MQTTSN_CLIENT_VERSION CC_MQTTSN_CLIENT_MAKE_VERSION(CC_MQTTSN_CLIENT_MAJOR_VERSION, CC_MQTTSN_CLIENT_MINOR_VERSION, CC_MQTTSN_CLIENT_PATCH_VERSION)
39
49
70
83
97
106
117
127
136
139struct CC_MqttsnClient;
140
144typedef struct CC_MqttsnClient* CC_MqttsnClientHandle;
145
148struct CC_MqttsnSearch;
149
153typedef struct CC_MqttsnSearch* CC_MqttsnSearchHandle;
154
157struct CC_MqttsnConnect;
158
162typedef struct CC_MqttsnConnect* CC_MqttsnConnectHandle;
163
166struct CC_MqttsnDisconnect;
167
171typedef struct CC_MqttsnDisconnect* CC_MqttsnDisconnectHandle;
172
175struct CC_MqttsnSubscribe;
176
180typedef struct CC_MqttsnSubscribe* CC_MqttsnSubscribeHandle;
181
184struct CC_MqttsnUnsubscribe;
185
189typedef struct CC_MqttsnUnsubscribe* CC_MqttsnUnsubscribeHandle;
190
193struct CC_MqttsnPublish;
194
198typedef struct CC_MqttsnPublish* CC_MqttsnPublishHandle;
199
202struct CC_MqttsnWill;
203
207typedef struct CC_MqttsnWill* CC_MqttsnWillHandle;
208
211struct CC_MqttsnSleep;
212
216typedef struct CC_MqttsnSleep* CC_MqttsnSleepHandle;
217
220typedef unsigned short CC_MqttsnTopicId;
221
224typedef struct
225{
226 const char* m_topic;
227 const unsigned char* m_data;
228 unsigned m_dataLen;
233
236typedef struct
237{
238 unsigned char m_gwId;
239 const unsigned char* m_addr;
240 unsigned m_addrLen;
242
245typedef struct
246{
247 const char* m_clientId;
248 unsigned m_duration;
251
258
261typedef struct
262{
263 const char* m_topic;
264 const unsigned char* m_data;
265 unsigned m_dataLen;
267 bool m_retain;
269
278
286
294
297typedef struct
298{
299 const char* m_topic;
300 const unsigned char* m_data;
301 unsigned m_dataLen;
304 bool m_retain;
306
313
321
324typedef struct
325{
326 unsigned m_duration;
328
337typedef void (*CC_MqttsnNextTickProgramCb)(void* data, unsigned duration);
338
346typedef unsigned (*CC_MqttsnCancelNextTickWaitCb)(void* data);
347
361typedef void (*CC_MqttsnSendOutputDataCb)(void* data, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius);
362
371typedef void (*CC_MqttsnGwStatusReportCb)(void* data, CC_MqttsnGwStatus status, const CC_MqttsnGatewayInfo* info);
372
379
389typedef void (*CC_MqttsnMessageReportCb)(void* data, const CC_MqttsnMessageInfo* msgInfo);
390
396typedef void (*CC_MqttsnErrorLogCb)(void* data, const char* msg);
397
403typedef unsigned (*CC_MqttsnGwinfoDelayRequestCb)(void* data);
404
411typedef void (*CC_MqttsnSearchCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnGatewayInfo* info);
412
421typedef void (*CC_MqttsnConnectCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info);
422
429typedef void (*CC_MqttsnDisconnectCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status);
430
444
456
471
480typedef void (*CC_MqttsnWillCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnWillInfo* info);
481
488typedef void (*CC_MqttsnSleepCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status);
489
490
491#ifdef __cplusplus
492}
493#endif
void(* CC_MqttsnGwStatusReportCb)(void *data, CC_MqttsnGwStatus status, const CC_MqttsnGatewayInfo *info)
Callback used to report gateway status.
Definition common.h:371
void(* CC_MqttsnMessageReportCb)(void *data, const CC_MqttsnMessageInfo *msgInfo)
Callback used to report incoming messages.
Definition common.h:389
void(* CC_MqttsnGwDisconnectedReportCb)(void *data, CC_MqttsnGatewayDisconnectReason reason)
Callback used to report unsolicited disconnection of the gateway.
Definition common.h:378
void(* CC_MqttsnNextTickProgramCb)(void *data, unsigned duration)
Callback used to request time measurement.
Definition common.h:337
void(* CC_MqttsnSendOutputDataCb)(void *data, const unsigned char *buf, unsigned bufLen, unsigned broadcastRadius)
Callback used to request to send data to the gateway.
Definition common.h:361
struct CC_MqttsnClient * CC_MqttsnClientHandle
Handler used to access client specific data structures.
Definition common.h:144
unsigned(* CC_MqttsnCancelNextTickWaitCb)(void *data)
Callback used to request termination of existing time measurement.
Definition common.h:346
void(* CC_MqttsnErrorLogCb)(void *data, const char *msg)
Callback used to report discovered errors.
Definition common.h:396
unsigned(* CC_MqttsnGwinfoDelayRequestCb)(void *data)
Callback used to request delay (in ms) to wait before responding with GWINFO message on behalf of a g...
Definition common.h:403
struct CC_MqttsnConnect * CC_MqttsnConnectHandle
Handle for "connect" operation.
Definition common.h:162
void(* CC_MqttsnConnectCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo *info)
Callback used to report completion of the connect operation.
Definition common.h:421
struct CC_MqttsnDisconnect * CC_MqttsnDisconnectHandle
Handle for "disconnect" operation.
Definition common.h:171
void(* CC_MqttsnDisconnectCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the disconnect operation.
Definition common.h:429
CC_MqttsnReturnCode
Return code as per MQTT-SN specification.
Definition common.h:110
CC_MqttsnConnectionStatus
Connection state.
Definition common.h:121
unsigned short CC_MqttsnTopicId
Type used to hold Topic ID value.
Definition common.h:220
CC_MqttsnGwStatus
Status of the gateway.
Definition common.h:74
CC_MqttsnGatewayDisconnectReason
Reason for reporting unsolicited gateway disconnection.
Definition common.h:101
CC_MqttsnAsyncOpStatus
Status of the asynchronous operation.
Definition common.h:87
CC_MqttsnErrorCode
Error code returned by various API functions.
Definition common.h:53
CC_MqttsnQoS
Quality of Service.
Definition common.h:43
CC_MqttsnDataOrigin
Data origin.
Definition common.h:131
@ CC_MqttsnReturnCode_Conjestion
Rejected due to conjesion.
Definition common.h:112
@ CC_MqttsnReturnCode_InvalidTopicId
Rejected due to invalid topic ID.
Definition common.h:113
@ CC_MqttsnReturnCode_NotSupported
Rejected as not supported.
Definition common.h:114
@ CC_MqttsnReturnCode_Accepted
Accepted.
Definition common.h:111
@ CC_MqttsnReturnCode_ValuesLimit
Limit for the values.
Definition common.h:115
@ CC_MqttsnConnectionStatus_Connected
Client connected to the gateway.
Definition common.h:123
@ CC_MqttsnConnectionStatus_Asleep
Client in the sleep mode.
Definition common.h:124
@ CC_MqttsnConnectionStatus_ValuesLimit
Limit for the values.
Definition common.h:125
@ CC_MqttsnConnectionStatus_Disconnected
Client disconnection from the gateway.
Definition common.h:122
@ CC_MqttsnGwStatus_UpdatedByClient
The gateway's address was updated by another client.
Definition common.h:77
@ CC_MqttsnGwStatus_AddedByGateway
Added by the ADVERTISE or GWINFO sent by the gateway messages.
Definition common.h:75
@ CC_MqttsnGwStatus_ValuesLimit
Limit for the values.
Definition common.h:81
@ CC_MqttsnGwStatus_Alive
The ADVERTISE or GWINFO message have been received from the gateway indicating it's alive.
Definition common.h:78
@ CC_MqttsnGwStatus_Removed
The gateway hasn't advertised its presence in time, assumed no longer available.
Definition common.h:80
@ CC_MqttsnGwStatus_AddedByClient
Added by the GWINFO message sent by another client.
Definition common.h:76
@ CC_MqttsnGwStatus_Tentative
The gateway hasn't advertised its presence in time, assumed packet loss.
Definition common.h:79
@ CC_MqttsnGatewayDisconnectReason_ValuesLimit
Limit for the values.
Definition common.h:104
@ CC_MqttsnGatewayDisconnectReason_NoGatewayResponse
No messages from the gateway and no response to PINGREQ.
Definition common.h:103
@ CC_MqttsnGatewayDisconnectReason_DisconnectMsg
Gateway sent DISCONNECT message.
Definition common.h:102
@ CC_MqttsnAsyncOpStatus_OutOfMemory
The client library wasn't able to allocate necessary memory.
Definition common.h:92
@ CC_MqttsnAsyncOpStatus_Timeout
The required response from broker hasn't been received in time.
Definition common.h:90
@ CC_MqttsnAsyncOpStatus_GatewayDisconnected
Gateway disconnection detected during the operation execution.
Definition common.h:94
@ CC_MqttsnAsyncOpStatus_Aborted
The operation has been aborted before completion due to client's side operation.
Definition common.h:91
@ CC_MqttsnAsyncOpStatus_Complete
The requested operation has been completed, refer to reported extra details for information.
Definition common.h:88
@ CC_MqttsnAsyncOpStatus_BadParam
Bad value has been returned from the relevant callback.
Definition common.h:93
@ CC_MqttsnAsyncOpStatus_InternalError
Internal library error, please submit bug report
Definition common.h:89
@ CC_MqttsnAsyncOpStatus_ValuesLimit
Limit for the values.
Definition common.h:95
@ CC_MqttsnErrorCode_NotSleeping
The client is not in ASLEEP mode.
Definition common.h:66
@ CC_MqttsnErrorCode_NotIntitialized
The allocated client hasn't been initialized.
Definition common.h:56
@ CC_MqttsnErrorCode_OutOfMemory
Memory allocation failed.
Definition common.h:61
@ CC_MqttsnErrorCode_ValuesLimit
Upper limit of the values.
Definition common.h:68
@ CC_MqttsnErrorCode_InsufficientConfig
The required configuration hasn't been performed.
Definition common.h:60
@ CC_MqttsnErrorCode_Busy
The client library is in the middle of previous operation(s), cannot start a new one.
Definition common.h:57
@ CC_MqttsnErrorCode_Disconnecting
The client is in "disconnecting" state, (re)connect is required in the next iteration loop.
Definition common.h:65
@ CC_MqttsnErrorCode_PreparationLocked
Another operation is being prepared, cannot create a new one without performing "send" or "cancel".
Definition common.h:67
@ CC_MqttsnErrorCode_Success
The requested operation was successfully started.
Definition common.h:54
@ CC_MqttsnErrorCode_InternalError
Internal library error, please submit bug report
Definition common.h:55
@ CC_MqttsnErrorCode_RetryLater
Retry in next event loop iteration.
Definition common.h:64
@ CC_MqttsnErrorCode_NotSupported
Feature is not supported.
Definition common.h:63
@ CC_MqttsnErrorCode_BadParam
Bad parameter is passed to the function.
Definition common.h:59
@ CC_MqttsnErrorCode_BufferOverflow
Output buffer is too short.
Definition common.h:62
@ CC_MqttsnErrorCode_NotConnected
The client library is not connected to the gateway. Returned by operations that require connection to...
Definition common.h:58
@ CC_MqttsnQoS_ValuesLimit
Limit for the values.
Definition common.h:47
@ CC_MqttsnQoS_AtMostOnceDelivery
QoS=0. At most once delivery.
Definition common.h:44
@ CC_MqttsnQoS_ExactlyOnceDelivery
QoS=2. Exactly once delivery.
Definition common.h:46
@ CC_MqttsnQoS_AtLeastOnceDelivery
QoS=1. At least once delivery.
Definition common.h:45
@ CC_MqttsnDataOrigin_ValuesLimit
Limit for the values.
Definition common.h:134
@ CC_MqttsnDataOrigin_ConnectedGw
Data comes from the connected gateway.
Definition common.h:133
@ CC_MqttsnDataOrigin_Any
Data comes from any node on the network.
Definition common.h:132
struct CC_MqttsnPublish * CC_MqttsnPublishHandle
Handle for "publish" operation.
Definition common.h:198
void(* CC_MqttsnPublishCompleteCb)(void *data, CC_MqttsnPublishHandle handle, CC_MqttsnAsyncOpStatus status, const CC_MqttsnPublishInfo *info)
Callback used to report completion of the publish operation.
Definition common.h:470
void(* CC_MqttsnSearchCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnGatewayInfo *info)
Callback used to report completion of the asynchronous operation.
Definition common.h:411
struct CC_MqttsnSearch * CC_MqttsnSearchHandle
Handle for "search" operation.
Definition common.h:153
struct CC_MqttsnSleep * CC_MqttsnSleepHandle
Handle for "sleep" operation.
Definition common.h:216
void(* CC_MqttsnSleepCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the sleep operation.
Definition common.h:488
struct CC_MqttsnUnsubscribe * CC_MqttsnUnsubscribeHandle
Handle for "unsubscribe" operation.
Definition common.h:189
struct CC_MqttsnSubscribe * CC_MqttsnSubscribeHandle
Handle for "subscribe" operation.
Definition common.h:180
void(* CC_MqttsnSubscribeCompleteCb)(void *data, CC_MqttsnSubscribeHandle handle, CC_MqttsnAsyncOpStatus status, const CC_MqttsnSubscribeInfo *info)
Callback used to report completion of the subscribe operation.
Definition common.h:443
void(* CC_MqttsnUnsubscribeCompleteCb)(void *data, CC_MqttsnUnsubscribeHandle handle, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the unsubscribe operation.
Definition common.h:455
struct CC_MqttsnWill * CC_MqttsnWillHandle
Handle for "will" operation.
Definition common.h:207
void(* CC_MqttsnWillCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnWillInfo *info)
Callback used to report completion of the publish operation.
Definition common.h:480
Configuration the "connect" operation.
Definition common.h:246
unsigned m_duration
Duration (Keep alive) configuration in seconds. Defaults to 60 when initialized.
Definition common.h:248
bool m_cleanSession
Clean session configuration.
Definition common.h:249
const char * m_clientId
Client ID.
Definition common.h:247
Information on the "connect" operation completion.
Definition common.h:255
CC_MqttsnReturnCode m_returnCode
Return code reported by the CONNACK message.
Definition common.h:256
Gateway information.
Definition common.h:237
unsigned m_addrLen
Length of the address.
Definition common.h:240
const unsigned char * m_addr
Address of the gateway if known, NULL if not.
Definition common.h:239
unsigned char m_gwId
Gateway ID.
Definition common.h:238
Incoming message information.
Definition common.h:225
CC_MqttsnQoS m_qos
QoS level the message was received with.
Definition common.h:230
bool m_retained
Retain flag of the message.
Definition common.h:231
const char * m_topic
Topic the message was published with. May be NULL if message is reported with predefined topic ID.
Definition common.h:226
unsigned m_dataLen
Number of bytes in reported message binary data.
Definition common.h:228
const unsigned char * m_data
Pointer to reported message binary data.
Definition common.h:227
CC_MqttsnTopicId m_topicId
Predefined topic ID. This data member is used only if topic field has value NULL.
Definition common.h:229
Configuration the will for "publish" operations.
Definition common.h:298
unsigned m_dataLen
Publish data (message) length.
Definition common.h:301
const char * m_topic
Publish topic.
Definition common.h:299
const unsigned char * m_data
Publish data (message).
Definition common.h:300
bool m_retain
Publish message retain configuration.
Definition common.h:304
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:302
CC_MqttsnQoS m_qos
Publish message QoS.
Definition common.h:303
Information on the "publish" operation completion.
Definition common.h:310
CC_MqttsnReturnCode m_returnCode
Return code reported by the PUBACK message.
Definition common.h:311
Configuration the "sleep" operation.
Definition common.h:325
unsigned m_duration
Duration configuration in seconds.
Definition common.h:326
Configuration the "subscribe" operation.
Definition common.h:273
const char * m_topic
Subscription topic, can be NULL when pre-defined topic ID is used.
Definition common.h:274
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:275
CC_MqttsnQoS m_qos
Max QoS value.
Definition common.h:276
Information on the "subscribe" operation completion.
Definition common.h:282
CC_MqttsnQoS m_qos
Granted max QoS value.
Definition common.h:284
CC_MqttsnReturnCode m_returnCode
Return code reported by the SUBACK message.
Definition common.h:283
Configuration the "unsubscribe" operation.
Definition common.h:290
const char * m_topic
Subscription topic, can be NULL when pre-defined topic ID is used.
Definition common.h:291
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:292
Configuration the will for "connect" and "will" operations.
Definition common.h:262
CC_MqttsnQoS m_qos
Will message QoS.
Definition common.h:266
const unsigned char * m_data
Will data (message).
Definition common.h:264
unsigned m_dataLen
Will data (message) length.
Definition common.h:265
bool m_retain
Will message retain configuration.
Definition common.h:267
const char * m_topic
Will topic.
Definition common.h:263
Information on the "will" operation completion.
Definition common.h:317
CC_MqttsnReturnCode m_msgUpdReturnCode
Return code reported by the WILLMSGRESP message.
Definition common.h:319
CC_MqttsnReturnCode m_topicUpdReturnCode
Return code reported by the WILLTOPICRESP message.
Definition common.h:318