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 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: MPL-2.0
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
12
13#pragma once
14
15#ifdef __cplusplus
16extern "C" {
17#else // #ifdef __cplusplus
18#include <stdbool.h>
19#endif // #ifdef __cplusplus
20
23#define CC_MQTTSN_CLIENT_MAJOR_VERSION 2U
24
27#define CC_MQTTSN_CLIENT_MINOR_VERSION 0U
28
31#define CC_MQTTSN_CLIENT_PATCH_VERSION 12U
32
34#define CC_MQTTSN_CLIENT_MAKE_VERSION(major_, minor_, patch_) \
35 ((static_cast<unsigned>(major_) << 24) | \
36 (static_cast<unsigned>(minor_) << 8) | \
37 (static_cast<unsigned>(patch_)))
38
40#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)
41
51
72
85
99
108
120
130
139
142struct CC_MqttsnClient;
143
147typedef struct CC_MqttsnClient* CC_MqttsnClientHandle;
148
151struct CC_MqttsnSearch;
152
156typedef struct CC_MqttsnSearch* CC_MqttsnSearchHandle;
157
160struct CC_MqttsnConnect;
161
165typedef struct CC_MqttsnConnect* CC_MqttsnConnectHandle;
166
169struct CC_MqttsnDisconnect;
170
174typedef struct CC_MqttsnDisconnect* CC_MqttsnDisconnectHandle;
175
178struct CC_MqttsnSubscribe;
179
183typedef struct CC_MqttsnSubscribe* CC_MqttsnSubscribeHandle;
184
187struct CC_MqttsnUnsubscribe;
188
192typedef struct CC_MqttsnUnsubscribe* CC_MqttsnUnsubscribeHandle;
193
196struct CC_MqttsnPublish;
197
201typedef struct CC_MqttsnPublish* CC_MqttsnPublishHandle;
202
205struct CC_MqttsnWill;
206
210typedef struct CC_MqttsnWill* CC_MqttsnWillHandle;
211
214struct CC_MqttsnSleep;
215
219typedef struct CC_MqttsnSleep* CC_MqttsnSleepHandle;
220
223typedef unsigned short CC_MqttsnTopicId;
224
227typedef struct
228{
229 const char* m_topic;
230 const unsigned char* m_data;
231 unsigned m_dataLen;
236
239typedef struct
240{
241 unsigned char m_gwId;
242 const unsigned char* m_addr;
243 unsigned m_addrLen;
245
248typedef struct
249{
250 const char* m_clientId;
251 unsigned m_duration;
254
261
264typedef struct
265{
266 const char* m_topic;
267 const unsigned char* m_data;
268 unsigned m_dataLen;
270 bool m_retain;
272
281
289
297
300typedef struct
301{
302 const char* m_topic;
303 const unsigned char* m_data;
304 unsigned m_dataLen;
307 bool m_retain;
309
316
324
327typedef struct
328{
329 unsigned m_duration;
331
340typedef void (*CC_MqttsnNextTickProgramCb)(void* data, unsigned duration);
341
349typedef unsigned (*CC_MqttsnCancelNextTickWaitCb)(void* data);
350
364typedef void (*CC_MqttsnSendOutputDataCb)(void* data, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius);
365
374typedef void (*CC_MqttsnGwStatusReportCb)(void* data, CC_MqttsnGwStatus status, const CC_MqttsnGatewayInfo* info);
375
382
392typedef void (*CC_MqttsnMessageReportCb)(void* data, const CC_MqttsnMessageInfo* msgInfo);
393
399typedef void (*CC_MqttsnErrorLogCb)(void* data, const char* msg);
400
406typedef unsigned (*CC_MqttsnGwinfoDelayRequestCb)(void* data);
407
414typedef void (*CC_MqttsnSearchCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnGatewayInfo* info);
415
424typedef void (*CC_MqttsnConnectCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info);
425
432typedef void (*CC_MqttsnDisconnectCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status);
433
447
459
474
483typedef void (*CC_MqttsnWillCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnWillInfo* info);
484
491typedef void (*CC_MqttsnSleepCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status);
492
493#ifdef __cplusplus
494}
495#endif
void(* CC_MqttsnGwStatusReportCb)(void *data, CC_MqttsnGwStatus status, const CC_MqttsnGatewayInfo *info)
Callback used to report gateway status.
Definition common.h:374
void(* CC_MqttsnMessageReportCb)(void *data, const CC_MqttsnMessageInfo *msgInfo)
Callback used to report incoming messages.
Definition common.h:392
void(* CC_MqttsnGwDisconnectedReportCb)(void *data, CC_MqttsnGatewayDisconnectReason reason)
Callback used to report unsolicited disconnection of the gateway.
Definition common.h:381
void(* CC_MqttsnNextTickProgramCb)(void *data, unsigned duration)
Callback used to request time measurement.
Definition common.h:340
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:364
struct CC_MqttsnClient * CC_MqttsnClientHandle
Handler used to access client specific data structures.
Definition common.h:147
unsigned(* CC_MqttsnCancelNextTickWaitCb)(void *data)
Callback used to request termination of existing time measurement.
Definition common.h:349
void(* CC_MqttsnErrorLogCb)(void *data, const char *msg)
Callback used to report discovered errors.
Definition common.h:399
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:406
struct CC_MqttsnConnect * CC_MqttsnConnectHandle
Handle for "connect" operation.
Definition common.h:165
void(* CC_MqttsnConnectCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo *info)
Callback used to report completion of the connect operation.
Definition common.h:424
struct CC_MqttsnDisconnect * CC_MqttsnDisconnectHandle
Handle for "disconnect" operation.
Definition common.h:174
void(* CC_MqttsnDisconnectCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the disconnect operation.
Definition common.h:432
CC_MqttsnReturnCode
Return code as per MQTT-SN specification.
Definition common.h:112
CC_MqttsnConnectionStatus
Connection state.
Definition common.h:124
unsigned short CC_MqttsnTopicId
Type used to hold Topic ID value.
Definition common.h:223
CC_MqttsnGwStatus
Status of the gateway.
Definition common.h:76
CC_MqttsnGatewayDisconnectReason
Reason for reporting unsolicited gateway disconnection.
Definition common.h:103
CC_MqttsnAsyncOpStatus
Status of the asynchronous operation.
Definition common.h:89
CC_MqttsnErrorCode
Error code returned by various API functions.
Definition common.h:55
CC_MqttsnQoS
Quality of Service.
Definition common.h:45
CC_MqttsnDataOrigin
Data origin.
Definition common.h:134
@ CC_MqttsnReturnCode_Conjestion
Rejected due to conjesion.
Definition common.h:114
@ CC_MqttsnReturnCode_InvalidTopicId
Rejected due to invalid topic ID.
Definition common.h:115
@ CC_MqttsnReturnCode_NotSupported
Rejected as not supported.
Definition common.h:116
@ CC_MqttsnReturnCode_MaxTypeValue
Allow safe cast between 1 byte raw value and the enum.
Definition common.h:118
@ CC_MqttsnReturnCode_Accepted
Accepted.
Definition common.h:113
@ CC_MqttsnReturnCode_ValuesLimit
Limit for the values.
Definition common.h:117
@ CC_MqttsnConnectionStatus_Connected
Client connected to the gateway.
Definition common.h:126
@ CC_MqttsnConnectionStatus_Asleep
Client in the sleep mode.
Definition common.h:127
@ CC_MqttsnConnectionStatus_ValuesLimit
Limit for the values.
Definition common.h:128
@ CC_MqttsnConnectionStatus_Disconnected
Client disconnection from the gateway.
Definition common.h:125
@ CC_MqttsnGwStatus_UpdatedByClient
The gateway's address was updated by another client.
Definition common.h:79
@ CC_MqttsnGwStatus_AddedByGateway
Added by the ADVERTISE or GWINFO sent by the gateway messages.
Definition common.h:77
@ CC_MqttsnGwStatus_ValuesLimit
Limit for the values.
Definition common.h:83
@ CC_MqttsnGwStatus_Alive
The ADVERTISE or GWINFO message have been received from the gateway indicating it's alive.
Definition common.h:80
@ CC_MqttsnGwStatus_Removed
The gateway hasn't advertised its presence in time, assumed no longer available.
Definition common.h:82
@ CC_MqttsnGwStatus_AddedByClient
Added by the GWINFO message sent by another client.
Definition common.h:78
@ CC_MqttsnGwStatus_Tentative
The gateway hasn't advertised its presence in time, assumed packet loss.
Definition common.h:81
@ CC_MqttsnGatewayDisconnectReason_ValuesLimit
Limit for the values.
Definition common.h:106
@ CC_MqttsnGatewayDisconnectReason_NoGatewayResponse
No messages from the gateway and no response to PINGREQ.
Definition common.h:105
@ CC_MqttsnGatewayDisconnectReason_DisconnectMsg
Gateway sent DISCONNECT message.
Definition common.h:104
@ CC_MqttsnAsyncOpStatus_OutOfMemory
The client library wasn't able to allocate necessary memory.
Definition common.h:94
@ CC_MqttsnAsyncOpStatus_Timeout
The required response from broker hasn't been received in time.
Definition common.h:92
@ CC_MqttsnAsyncOpStatus_GatewayDisconnected
Gateway disconnection detected during the operation execution.
Definition common.h:96
@ CC_MqttsnAsyncOpStatus_Aborted
The operation has been aborted before completion due to client's side operation.
Definition common.h:93
@ CC_MqttsnAsyncOpStatus_Complete
The requested operation has been completed, refer to reported extra details for information.
Definition common.h:90
@ CC_MqttsnAsyncOpStatus_BadParam
Bad value has been returned from the relevant callback.
Definition common.h:95
@ CC_MqttsnAsyncOpStatus_InternalError
Internal library error, please submit bug report.
Definition common.h:91
@ CC_MqttsnAsyncOpStatus_ValuesLimit
Limit for the values.
Definition common.h:97
@ CC_MqttsnErrorCode_NotSleeping
The client is not in ASLEEP mode.
Definition common.h:68
@ CC_MqttsnErrorCode_NotIntitialized
The allocated client hasn't been initialized.
Definition common.h:58
@ CC_MqttsnErrorCode_OutOfMemory
Memory allocation failed.
Definition common.h:63
@ CC_MqttsnErrorCode_ValuesLimit
Upper limit of the values.
Definition common.h:70
@ CC_MqttsnErrorCode_InsufficientConfig
The required configuration hasn't been performed.
Definition common.h:62
@ CC_MqttsnErrorCode_Busy
The client library is in the middle of previous operation(s), cannot start a new one.
Definition common.h:59
@ CC_MqttsnErrorCode_Disconnecting
The client is in "disconnecting" state, (re)connect is required in the next iteration loop.
Definition common.h:67
@ CC_MqttsnErrorCode_PreparationLocked
Another operation is being prepared, cannot create a new one without performing "send" or "cancel".
Definition common.h:69
@ CC_MqttsnErrorCode_Success
The requested operation was successfully started.
Definition common.h:56
@ CC_MqttsnErrorCode_InternalError
Internal library error, please submit bug report.
Definition common.h:57
@ CC_MqttsnErrorCode_RetryLater
Retry in next event loop iteration.
Definition common.h:66
@ CC_MqttsnErrorCode_NotSupported
Feature is not supported.
Definition common.h:65
@ CC_MqttsnErrorCode_BadParam
Bad parameter is passed to the function.
Definition common.h:61
@ CC_MqttsnErrorCode_BufferOverflow
Output buffer is too short.
Definition common.h:64
@ CC_MqttsnErrorCode_NotConnected
The client library is not connected to the gateway. Returned by operations that require connection to...
Definition common.h:60
@ CC_MqttsnQoS_ValuesLimit
Limit for the values.
Definition common.h:49
@ CC_MqttsnQoS_AtMostOnceDelivery
QoS=0. At most once delivery.
Definition common.h:46
@ CC_MqttsnQoS_ExactlyOnceDelivery
QoS=2. Exactly once delivery.
Definition common.h:48
@ CC_MqttsnQoS_AtLeastOnceDelivery
QoS=1. At least once delivery.
Definition common.h:47
@ CC_MqttsnDataOrigin_ValuesLimit
Limit for the values.
Definition common.h:137
@ CC_MqttsnDataOrigin_ConnectedGw
Data comes from the connected gateway.
Definition common.h:136
@ CC_MqttsnDataOrigin_Any
Data comes from any node on the network.
Definition common.h:135
struct CC_MqttsnPublish * CC_MqttsnPublishHandle
Handle for "publish" operation.
Definition common.h:201
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:473
void(* CC_MqttsnSearchCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnGatewayInfo *info)
Callback used to report completion of the asynchronous operation.
Definition common.h:414
struct CC_MqttsnSearch * CC_MqttsnSearchHandle
Handle for "search" operation.
Definition common.h:156
struct CC_MqttsnSleep * CC_MqttsnSleepHandle
Handle for "sleep" operation.
Definition common.h:219
void(* CC_MqttsnSleepCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the sleep operation.
Definition common.h:491
struct CC_MqttsnUnsubscribe * CC_MqttsnUnsubscribeHandle
Handle for "unsubscribe" operation.
Definition common.h:192
struct CC_MqttsnSubscribe * CC_MqttsnSubscribeHandle
Handle for "subscribe" operation.
Definition common.h:183
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:446
void(* CC_MqttsnUnsubscribeCompleteCb)(void *data, CC_MqttsnUnsubscribeHandle handle, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the unsubscribe operation.
Definition common.h:458
struct CC_MqttsnWill * CC_MqttsnWillHandle
Handle for "will" operation.
Definition common.h:210
void(* CC_MqttsnWillCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnWillInfo *info)
Callback used to report completion of the publish operation.
Definition common.h:483
Configuration the "connect" operation.
Definition common.h:249
unsigned m_duration
Duration (Keep alive) configuration in seconds. Defaults to 60 when initialized.
Definition common.h:251
bool m_cleanSession
Clean session configuration.
Definition common.h:252
const char * m_clientId
Client ID.
Definition common.h:250
Information on the "connect" operation completion.
Definition common.h:258
CC_MqttsnReturnCode m_returnCode
Return code reported by the CONNACK message.
Definition common.h:259
Gateway information.
Definition common.h:240
unsigned m_addrLen
Length of the address.
Definition common.h:243
const unsigned char * m_addr
Address of the gateway if known, NULL if not.
Definition common.h:242
unsigned char m_gwId
Gateway ID.
Definition common.h:241
Incoming message information.
Definition common.h:228
CC_MqttsnQoS m_qos
QoS level the message was received with.
Definition common.h:233
bool m_retained
Retain flag of the message.
Definition common.h:234
const char * m_topic
Topic the message was published with. May be NULL if message is reported with predefined topic ID.
Definition common.h:229
unsigned m_dataLen
Number of bytes in reported message binary data.
Definition common.h:231
const unsigned char * m_data
Pointer to reported message binary data.
Definition common.h:230
CC_MqttsnTopicId m_topicId
Predefined topic ID. This data member is used only if topic field has value NULL.
Definition common.h:232
Configuration the will for "publish" operations.
Definition common.h:301
unsigned m_dataLen
Publish data (message) length.
Definition common.h:304
const char * m_topic
Publish topic.
Definition common.h:302
const unsigned char * m_data
Publish data (message).
Definition common.h:303
bool m_retain
Publish message retain configuration.
Definition common.h:307
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:305
CC_MqttsnQoS m_qos
Publish message QoS.
Definition common.h:306
Information on the "publish" operation completion.
Definition common.h:313
CC_MqttsnReturnCode m_returnCode
Return code reported by the PUBACK message.
Definition common.h:314
Configuration the "sleep" operation.
Definition common.h:328
unsigned m_duration
Duration configuration in seconds.
Definition common.h:329
Configuration the "subscribe" operation.
Definition common.h:276
const char * m_topic
Subscription topic, can be NULL when pre-defined topic ID is used.
Definition common.h:277
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:278
CC_MqttsnQoS m_qos
Max QoS value.
Definition common.h:279
Information on the "subscribe" operation completion.
Definition common.h:285
CC_MqttsnQoS m_qos
Granted max QoS value.
Definition common.h:287
CC_MqttsnReturnCode m_returnCode
Return code reported by the SUBACK message.
Definition common.h:286
Configuration the "unsubscribe" operation.
Definition common.h:293
const char * m_topic
Subscription topic, can be NULL when pre-defined topic ID is used.
Definition common.h:294
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:295
Configuration the will for "connect" and "will" operations.
Definition common.h:265
CC_MqttsnQoS m_qos
Will message QoS.
Definition common.h:269
const unsigned char * m_data
Will data (message).
Definition common.h:267
unsigned m_dataLen
Will data (message) length.
Definition common.h:268
bool m_retain
Will message retain configuration.
Definition common.h:270
const char * m_topic
Will topic.
Definition common.h:266
Information on the "will" operation completion.
Definition common.h:320
CC_MqttsnReturnCode m_msgUpdReturnCode
Return code reported by the WILLMSGRESP message.
Definition common.h:322
CC_MqttsnReturnCode m_topicUpdReturnCode
Return code reported by the WILLTOPICRESP message.
Definition common.h:321