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 - 2025 (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 9U
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
118
128
137
140struct CC_MqttsnClient;
141
145typedef struct CC_MqttsnClient* CC_MqttsnClientHandle;
146
149struct CC_MqttsnSearch;
150
154typedef struct CC_MqttsnSearch* CC_MqttsnSearchHandle;
155
158struct CC_MqttsnConnect;
159
163typedef struct CC_MqttsnConnect* CC_MqttsnConnectHandle;
164
167struct CC_MqttsnDisconnect;
168
172typedef struct CC_MqttsnDisconnect* CC_MqttsnDisconnectHandle;
173
176struct CC_MqttsnSubscribe;
177
181typedef struct CC_MqttsnSubscribe* CC_MqttsnSubscribeHandle;
182
185struct CC_MqttsnUnsubscribe;
186
190typedef struct CC_MqttsnUnsubscribe* CC_MqttsnUnsubscribeHandle;
191
194struct CC_MqttsnPublish;
195
199typedef struct CC_MqttsnPublish* CC_MqttsnPublishHandle;
200
203struct CC_MqttsnWill;
204
208typedef struct CC_MqttsnWill* CC_MqttsnWillHandle;
209
212struct CC_MqttsnSleep;
213
217typedef struct CC_MqttsnSleep* CC_MqttsnSleepHandle;
218
221typedef unsigned short CC_MqttsnTopicId;
222
225typedef struct
226{
227 const char* m_topic;
228 const unsigned char* m_data;
229 unsigned m_dataLen;
234
237typedef struct
238{
239 unsigned char m_gwId;
240 const unsigned char* m_addr;
241 unsigned m_addrLen;
243
246typedef struct
247{
248 const char* m_clientId;
249 unsigned m_duration;
252
259
262typedef struct
263{
264 const char* m_topic;
265 const unsigned char* m_data;
266 unsigned m_dataLen;
268 bool m_retain;
270
279
287
295
298typedef struct
299{
300 const char* m_topic;
301 const unsigned char* m_data;
302 unsigned m_dataLen;
305 bool m_retain;
307
314
322
325typedef struct
326{
327 unsigned m_duration;
329
338typedef void (*CC_MqttsnNextTickProgramCb)(void* data, unsigned duration);
339
347typedef unsigned (*CC_MqttsnCancelNextTickWaitCb)(void* data);
348
362typedef void (*CC_MqttsnSendOutputDataCb)(void* data, const unsigned char* buf, unsigned bufLen, unsigned broadcastRadius);
363
372typedef void (*CC_MqttsnGwStatusReportCb)(void* data, CC_MqttsnGwStatus status, const CC_MqttsnGatewayInfo* info);
373
380
390typedef void (*CC_MqttsnMessageReportCb)(void* data, const CC_MqttsnMessageInfo* msgInfo);
391
397typedef void (*CC_MqttsnErrorLogCb)(void* data, const char* msg);
398
404typedef unsigned (*CC_MqttsnGwinfoDelayRequestCb)(void* data);
405
412typedef void (*CC_MqttsnSearchCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnGatewayInfo* info);
413
422typedef void (*CC_MqttsnConnectCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo* info);
423
430typedef void (*CC_MqttsnDisconnectCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status);
431
445
457
472
481typedef void (*CC_MqttsnWillCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnWillInfo* info);
482
489typedef void (*CC_MqttsnSleepCompleteCb)(void* data, CC_MqttsnAsyncOpStatus status);
490
491
492#ifdef __cplusplus
493}
494#endif
void(* CC_MqttsnGwStatusReportCb)(void *data, CC_MqttsnGwStatus status, const CC_MqttsnGatewayInfo *info)
Callback used to report gateway status.
Definition common.h:372
void(* CC_MqttsnMessageReportCb)(void *data, const CC_MqttsnMessageInfo *msgInfo)
Callback used to report incoming messages.
Definition common.h:390
void(* CC_MqttsnGwDisconnectedReportCb)(void *data, CC_MqttsnGatewayDisconnectReason reason)
Callback used to report unsolicited disconnection of the gateway.
Definition common.h:379
void(* CC_MqttsnNextTickProgramCb)(void *data, unsigned duration)
Callback used to request time measurement.
Definition common.h:338
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:362
struct CC_MqttsnClient * CC_MqttsnClientHandle
Handler used to access client specific data structures.
Definition common.h:145
unsigned(* CC_MqttsnCancelNextTickWaitCb)(void *data)
Callback used to request termination of existing time measurement.
Definition common.h:347
void(* CC_MqttsnErrorLogCb)(void *data, const char *msg)
Callback used to report discovered errors.
Definition common.h:397
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:404
struct CC_MqttsnConnect * CC_MqttsnConnectHandle
Handle for "connect" operation.
Definition common.h:163
void(* CC_MqttsnConnectCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnConnectInfo *info)
Callback used to report completion of the connect operation.
Definition common.h:422
struct CC_MqttsnDisconnect * CC_MqttsnDisconnectHandle
Handle for "disconnect" operation.
Definition common.h:172
void(* CC_MqttsnDisconnectCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the disconnect operation.
Definition common.h:430
CC_MqttsnReturnCode
Return code as per MQTT-SN specification.
Definition common.h:110
CC_MqttsnConnectionStatus
Connection state.
Definition common.h:122
unsigned short CC_MqttsnTopicId
Type used to hold Topic ID value.
Definition common.h:221
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:132
@ 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_MaxTypeValue
Allow safe cast between 1 byte raw value and the enum.
Definition common.h:116
@ 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:124
@ CC_MqttsnConnectionStatus_Asleep
Client in the sleep mode.
Definition common.h:125
@ CC_MqttsnConnectionStatus_ValuesLimit
Limit for the values.
Definition common.h:126
@ CC_MqttsnConnectionStatus_Disconnected
Client disconnection from the gateway.
Definition common.h:123
@ 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:135
@ CC_MqttsnDataOrigin_ConnectedGw
Data comes from the connected gateway.
Definition common.h:134
@ CC_MqttsnDataOrigin_Any
Data comes from any node on the network.
Definition common.h:133
struct CC_MqttsnPublish * CC_MqttsnPublishHandle
Handle for "publish" operation.
Definition common.h:199
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:471
void(* CC_MqttsnSearchCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnGatewayInfo *info)
Callback used to report completion of the asynchronous operation.
Definition common.h:412
struct CC_MqttsnSearch * CC_MqttsnSearchHandle
Handle for "search" operation.
Definition common.h:154
struct CC_MqttsnSleep * CC_MqttsnSleepHandle
Handle for "sleep" operation.
Definition common.h:217
void(* CC_MqttsnSleepCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the sleep operation.
Definition common.h:489
struct CC_MqttsnUnsubscribe * CC_MqttsnUnsubscribeHandle
Handle for "unsubscribe" operation.
Definition common.h:190
struct CC_MqttsnSubscribe * CC_MqttsnSubscribeHandle
Handle for "subscribe" operation.
Definition common.h:181
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:444
void(* CC_MqttsnUnsubscribeCompleteCb)(void *data, CC_MqttsnUnsubscribeHandle handle, CC_MqttsnAsyncOpStatus status)
Callback used to report completion of the unsubscribe operation.
Definition common.h:456
struct CC_MqttsnWill * CC_MqttsnWillHandle
Handle for "will" operation.
Definition common.h:208
void(* CC_MqttsnWillCompleteCb)(void *data, CC_MqttsnAsyncOpStatus status, const CC_MqttsnWillInfo *info)
Callback used to report completion of the publish operation.
Definition common.h:481
Configuration the "connect" operation.
Definition common.h:247
unsigned m_duration
Duration (Keep alive) configuration in seconds. Defaults to 60 when initialized.
Definition common.h:249
bool m_cleanSession
Clean session configuration.
Definition common.h:250
const char * m_clientId
Client ID.
Definition common.h:248
Information on the "connect" operation completion.
Definition common.h:256
CC_MqttsnReturnCode m_returnCode
Return code reported by the CONNACK message.
Definition common.h:257
Gateway information.
Definition common.h:238
unsigned m_addrLen
Length of the address.
Definition common.h:241
const unsigned char * m_addr
Address of the gateway if known, NULL if not.
Definition common.h:240
unsigned char m_gwId
Gateway ID.
Definition common.h:239
Incoming message information.
Definition common.h:226
CC_MqttsnQoS m_qos
QoS level the message was received with.
Definition common.h:231
bool m_retained
Retain flag of the message.
Definition common.h:232
const char * m_topic
Topic the message was published with. May be NULL if message is reported with predefined topic ID.
Definition common.h:227
unsigned m_dataLen
Number of bytes in reported message binary data.
Definition common.h:229
const unsigned char * m_data
Pointer to reported message binary data.
Definition common.h:228
CC_MqttsnTopicId m_topicId
Predefined topic ID. This data member is used only if topic field has value NULL.
Definition common.h:230
Configuration the will for "publish" operations.
Definition common.h:299
unsigned m_dataLen
Publish data (message) length.
Definition common.h:302
const char * m_topic
Publish topic.
Definition common.h:300
const unsigned char * m_data
Publish data (message).
Definition common.h:301
bool m_retain
Publish message retain configuration.
Definition common.h:305
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:303
CC_MqttsnQoS m_qos
Publish message QoS.
Definition common.h:304
Information on the "publish" operation completion.
Definition common.h:311
CC_MqttsnReturnCode m_returnCode
Return code reported by the PUBACK message.
Definition common.h:312
Configuration the "sleep" operation.
Definition common.h:326
unsigned m_duration
Duration configuration in seconds.
Definition common.h:327
Configuration the "subscribe" operation.
Definition common.h:274
const char * m_topic
Subscription topic, can be NULL when pre-defined topic ID is used.
Definition common.h:275
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:276
CC_MqttsnQoS m_qos
Max QoS value.
Definition common.h:277
Information on the "subscribe" operation completion.
Definition common.h:283
CC_MqttsnQoS m_qos
Granted max QoS value.
Definition common.h:285
CC_MqttsnReturnCode m_returnCode
Return code reported by the SUBACK message.
Definition common.h:284
Configuration the "unsubscribe" operation.
Definition common.h:291
const char * m_topic
Subscription topic, can be NULL when pre-defined topic ID is used.
Definition common.h:292
CC_MqttsnTopicId m_topicId
Pre-defined topic ID, should be 0 when topic is not NULL.
Definition common.h:293
Configuration the will for "connect" and "will" operations.
Definition common.h:263
CC_MqttsnQoS m_qos
Will message QoS.
Definition common.h:267
const unsigned char * m_data
Will data (message).
Definition common.h:265
unsigned m_dataLen
Will data (message) length.
Definition common.h:266
bool m_retain
Will message retain configuration.
Definition common.h:268
const char * m_topic
Will topic.
Definition common.h:264
Information on the "will" operation completion.
Definition common.h:318
CC_MqttsnReturnCode m_msgUpdReturnCode
Return code reported by the WILLMSGRESP message.
Definition common.h:320
CC_MqttsnReturnCode m_topicUpdReturnCode
Return code reported by the WILLTOPICRESP message.
Definition common.h:319