31#ifndef _MQTT_SN_CLIENT_H
32#define _MQTT_SN_CLIENT_H
40#ifndef MQTT_SN_CLIENT_SUPPORT
41 #define MQTT_SN_CLIENT_SUPPORT ENABLED
42#elif (MQTT_SN_CLIENT_SUPPORT != ENABLED && MQTT_SN_CLIENT_SUPPORT != DISABLED)
43 #error MQTT_SN_CLIENT_SUPPORT parameter is not valid
47#ifndef MQTT_SN_CLIENT_DTLS_SUPPORT
48 #define MQTT_SN_CLIENT_DTLS_SUPPORT DISABLED
49#elif (MQTT_SN_CLIENT_DTLS_SUPPORT != ENABLED && MQTT_SN_CLIENT_DTLS_SUPPORT != DISABLED)
50 #error MQTT_SN_CLIENT_DTLS_SUPPORT parameter is not valid
54#ifndef MQTT_SN_CLIENT_TOPIC_TABLE_SIZE
55 #define MQTT_SN_CLIENT_TOPIC_TABLE_SIZE 10
56#elif (MQTT_SN_CLIENT_TOPIC_TABLE_SIZE < 0)
57 #error MQTT_SN_CLIENT_TOPIC_TABLE_SIZE parameter is not valid
61#ifndef MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE
62 #define MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE 10
63#elif (MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE < 0)
64 #error MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE parameter is not valid
68#ifndef MQTT_SN_CLIENT_MAX_ID_LEN
69 #define MQTT_SN_CLIENT_MAX_ID_LEN 23
70#elif (MQTT_SN_CLIENT_MAX_ID_LEN < 0)
71 #error MQTT_SN_CLIENT_MAX_ID_LEN parameter is not valid
75#ifndef MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN
76 #define MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN 32
77#elif (MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN < 0)
78 #error MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN parameter is not valid
82#ifndef MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN
83 #define MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN 32
84#elif (MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN < 0)
85 #error MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN parameter is not valid
89#ifndef MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN
90 #define MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN 32
91#elif (MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN < 0)
92 #error MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN parameter is not valid
96#ifndef MQTT_SN_CLIENT_TICK_INTERVAL
97 #define MQTT_SN_CLIENT_TICK_INTERVAL 100
98#elif (MQTT_SN_CLIENT_TICK_INTERVAL < 10)
99 #error MQTT_SN_CLIENT_TICK_INTERVAL parameter is not valid
103#ifndef MQTT_SN_CLIENT_DEFAULT_TIMEOUT
104 #define MQTT_SN_CLIENT_DEFAULT_TIMEOUT 30000
105#elif (MQTT_SN_CLIENT_DEFAULT_TIMEOUT < 0)
106 #error MQTT_SN_CLIENT_DEFAULT_TIMEOUT parameter is not valid
110#ifndef MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE
111 #define MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE 0
112#elif (MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE < 0)
113 #error MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE parameter is not valid
117#ifndef MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES
118 #define MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES 5
119#elif (MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES < 0)
120 #error MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES parameter is not valid
124#ifndef MQTT_SN_CLIENT_SEARCH_DELAY
125 #define MQTT_SN_CLIENT_SEARCH_DELAY 0
126#elif (MQTT_SN_CLIENT_SEARCH_DELAY < 0)
127 #error MQTT_SN_CLIENT_SEARCH_DELAY parameter is not valid
131#ifndef MQTT_SN_CLIENT_RETRY_TIMEOUT
132 #define MQTT_SN_CLIENT_RETRY_TIMEOUT 5000
133#elif (MQTT_SN_CLIENT_RETRY_TIMEOUT < 1000)
134 #error MQTT_SN_CLIENT_RETRY_TIMEOUT parameter is not valid
138#ifndef MQTT_SN_CLIENT_PRIVATE_CONTEXT
139 #define MQTT_SN_CLIENT_PRIVATE_CONTEXT
143#if (MQTT_SN_CLIENT_DTLS_SUPPORT == ENABLED)
144 #include "core/crypto.h"
150#define MqttSnClientContext struct _MqttSnClientContext
164 MQTT_SN_CLIENT_STATE_DISCONNECTED = 0,
165 MQTT_SN_CLIENT_STATE_SEARCHING = 1,
166 MQTT_SN_CLIENT_STATE_CONNECTING = 2,
167 MQTT_SN_CLIENT_STATE_ACTIVE = 3,
168 MQTT_SN_CLIENT_STATE_SENDING_REQ = 4,
169 MQTT_SN_CLIENT_STATE_RESP_RECEIVED = 5,
170 MQTT_SN_CLIENT_STATE_LOST = 6,
171 MQTT_SN_CLIENT_STATE_ASLEEP = 7,
172 MQTT_SN_CLIENT_STATE_AWAKE = 8,
173 MQTT_SN_CLIENT_STATE_DISCONNECTING = 9
178#if (MQTT_SN_CLIENT_DTLS_SUPPORT == ENABLED)
195 const char_t *topic,
const uint8_t *
message,
size_t length,
205 char_t topic[MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN + 1];
206 uint8_t payload[MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN];
218 char_t topicName[MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN + 1];
250#if (MQTT_SN_CLIENT_DTLS_SUPPORT == ENABLED)
270 MQTT_SN_CLIENT_PRIVATE_CONTEXT
275error_t mqttSnClientInit(MqttSnClientContext *context);
277error_t mqttSnClientSetTransportProtocol(MqttSnClientContext *context,
280#if (MQTT_SN_CLIENT_DTLS_SUPPORT == ENABLED)
282error_t mqttSnClientRegisterDtlsInitCallback(MqttSnClientContext *context,
287error_t mqttSnClientRegisterPublishCallback(MqttSnClientContext *context,
290error_t mqttSnClientSetPredefinedTopics(MqttSnClientContext *context,
293error_t mqttSnClientSetTimeout(MqttSnClientContext *context,
296error_t mqttSnClientSetKeepAlive(MqttSnClientContext *context,
299error_t mqttSnClientSetIdentifier(MqttSnClientContext *context,
300 const char_t *clientId);
302error_t mqttSnClientSetWillMessage(MqttSnClientContext *context,
303 const char_t *topic,
const void *message,
size_t length,
306error_t mqttSnClientBindToInterface(MqttSnClientContext *context,
307 NetInterface *interface);
309error_t mqttSnClientSetGateway(MqttSnClientContext *context,
310 const IpAddr *gwIpAddr, uint16_t gwPort);
312error_t mqttSnClientSearchGateway(MqttSnClientContext *context,
313 const IpAddr *destIpAddr, uint16_t destPort);
315error_t mqttSnClientConnect(MqttSnClientContext *context, bool_t cleanSession);
317error_t mqttSnClientPublish(MqttSnClientContext *context,
318 const char_t *topicName,
const void *message,
size_t length,
321error_t mqttSnClientSubscribe(MqttSnClientContext *context,
324error_t mqttSnClientUnsubscribe(MqttSnClientContext *context,
325 const char_t *topicName);
327error_t mqttSnClientPing(MqttSnClientContext *context);
329error_t mqttSnClientUpdateWillMessage(MqttSnClientContext *context,
330 const char_t *topic,
const void *message,
size_t length,
333error_t mqttSnClientGetReturnCode(MqttSnClientContext *context,
338error_t mqttSnClientDisconnect(MqttSnClientContext *context,
341void mqttSnClientDeinit(MqttSnClientContext *context);
error_t
Error codes.
Definition error.h:43
error_t(* MqttSnClientDtlsInitCallback)(MqttSnClientContext *context, TlsContext *dtlsContext)
DTLS initialization callback.
Definition mqtt_sn_client.h:184
void(* MqttSnClientPublishCallback)(MqttSnClientContext *context, const char_t *topic, const uint8_t *message, size_t length, MqttSnQosLevel qos, bool_t retain)
PUBLISH message received callback.
Definition mqtt_sn_client.h:194
MqttSnClientState
MQTT-SN client states.
Definition mqtt_sn_client.h:163
Definitions common to MQTT-SN client and gateway.
MqttSnMsgType
MQTT-SN message types.
Definition mqtt_sn_common.h:92
MqttSnTransportProtocol
MQTT-SN transport protocols.
Definition mqtt_sn_common.h:55
MqttSnQosLevel
Quality of service level.
Definition mqtt_sn_common.h:66
MqttSnReturnCode
MQTT-SN return codes.
Definition mqtt_sn_common.h:129
MQTT-SN message formatting and parsing.
uint32_t systime_t
System time.
Definition os_port_none.h:90
IP network address.
Definition ip.h:72
QoS 2 message state.
Definition mqtt_sn_client.h:228
uint16_t msgId
Message identifier.
Definition mqtt_sn_client.h:230
bool_t ownership
Ownership of message accepted by the client.
Definition mqtt_sn_client.h:229
Mapping between a topic name and a topic ID.
Definition mqtt_sn_client.h:217
uint16_t topicId
Topic identifier.
Definition mqtt_sn_client.h:219
Will message.
Definition mqtt_sn_client.h:204
size_t length
Length of the Will message payload.
Definition mqtt_sn_client.h:207
MqttSnFlags flags
Flags.
Definition mqtt_sn_client.h:208
MQTT-SN message.
Definition mqtt_sn_message.h:56
Predefined topic.
Definition mqtt_sn_common.h:485
MQTT-SN client context.
Definition mqtt_sn_client.h:239
const MqttSnPredefinedTopic * predefinedTopicTable
List of predefined topics.
Definition mqtt_sn_client.h:242
IpAddr gwIpAddr
Gateway IP address.
Definition mqtt_sn_client.h:256
uint16_t msgId
Message identifier.
Definition mqtt_sn_client.h:265
MqttSnReturnCode returnCode
Status code returned by the gateway.
Definition mqtt_sn_client.h:267
uint16_t gwPort
Gateway port number.
Definition mqtt_sn_client.h:257
TlsSessionState dtlsSession
DTLS session state.
Definition mqtt_sn_client.h:252
uint_t keepAliveCounter
PINGREQ retransmission counter.
Definition mqtt_sn_client.h:262
systime_t timeout
Timeout value.
Definition mqtt_sn_client.h:244
MqttSnClientState state
MQTT-SN client state.
Definition mqtt_sn_client.h:240
char_t clientId[MQTT_SN_CLIENT_MAX_ID_LEN+1]
Client identifier.
Definition mqtt_sn_client.h:246
systime_t startTime
Start time.
Definition mqtt_sn_client.h:258
systime_t keepAliveTimestamp
Timestamp used to manage keep-alive.
Definition mqtt_sn_client.h:261
MqttSnClientPublishCallback publishCallback
PUBLISH message received callback.
Definition mqtt_sn_client.h:255
MqttSnClientWillMessage willMessage
Will message.
Definition mqtt_sn_client.h:247
MqttSnTransportProtocol transportProtocol
Transport protocol (UDP or DTLS)
Definition mqtt_sn_client.h:241
NetInterface * interface
Underlying network interface.
Definition mqtt_sn_client.h:248
systime_t retransmitStartTime
Time at which the last message was sent.
Definition mqtt_sn_client.h:259
MqttSnClientDtlsInitCallback dtlsInitCallback
DTLS initialization callback.
Definition mqtt_sn_client.h:253
TlsContext * dtlsContext
DTLS context.
Definition mqtt_sn_client.h:251
MqttSnMsgType msgType
Message type.
Definition mqtt_sn_client.h:264
systime_t keepAlive
Keep-alive interval.
Definition mqtt_sn_client.h:245
MqttSnMessage message
MQTT-SN message.
Definition mqtt_sn_client.h:263
Socket * socket
Underlying TCP socket.
Definition mqtt_sn_client.h:249
uint16_t topicId
Topic identifier returned by the gateway (REGACK/SUBACK)
Definition mqtt_sn_client.h:266
systime_t retransmitTimeout
Retransmission timeout.
Definition mqtt_sn_client.h:260
uint_t predefinedTopicTableSize
Number of predefined topics.
Definition mqtt_sn_client.h:243