mikroSDK Reference Manual
mqtt_sn_common.h
Go to the documentation of this file.
1
31#ifndef _MQTT_SN_COMMON_H
32#define _MQTT_SN_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36
37//MQTT-SN port number
38#define MQTT_SN_PORT 1883
39
40//C++ guard
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45//MQTT-SN protocol identifier
46#define MQTT_SN_PROTOCOL_ID 0x01
47//Reserved topic identifier
48#define MQTT_SN_INVALID_TOPIC_ID 0x0000
49
50
59
60
72
73
85
86
91typedef enum
92{
93 MQTT_SN_MSG_TYPE_ADVERTISE = 0x00,
94 MQTT_SN_MSG_TYPE_SEARCHGW = 0x01,
95 MQTT_SN_MSG_TYPE_GWINFO = 0x02,
96 MQTT_SN_MSG_TYPE_CONNECT = 0x04,
97 MQTT_SN_MSG_TYPE_CONNACK = 0x05,
98 MQTT_SN_MSG_TYPE_WILLTOPICREQ = 0x06,
99 MQTT_SN_MSG_TYPE_WILLTOPIC = 0x07,
100 MQTT_SN_MSG_TYPE_WILLMSGREQ = 0x08,
101 MQTT_SN_MSG_TYPE_WILLMSG = 0x09,
102 MQTT_SN_MSG_TYPE_REGISTER = 0x0A,
103 MQTT_SN_MSG_TYPE_REGACK = 0x0B,
104 MQTT_SN_MSG_TYPE_PUBLISH = 0x0C,
105 MQTT_SN_MSG_TYPE_PUBACK = 0x0D,
106 MQTT_SN_MSG_TYPE_PUBCOMP = 0x0E,
107 MQTT_SN_MSG_TYPE_PUBREC = 0x0F,
108 MQTT_SN_MSG_TYPE_PUBREL = 0x10,
109 MQTT_SN_MSG_TYPE_SUBSCRIBE = 0x12,
110 MQTT_SN_MSG_TYPE_SUBACK = 0x13,
111 MQTT_SN_MSG_TYPE_UNSUBSCRIBE = 0x14,
112 MQTT_SN_MSG_TYPE_UNSUBACK = 0x15,
113 MQTT_SN_MSG_TYPE_PINGREQ = 0x16,
114 MQTT_SN_MSG_TYPE_PINGRESP = 0x17,
115 MQTT_SN_MSG_TYPE_DISCONNECT = 0x18,
116 MQTT_SN_MSG_TYPE_WILLTOPICUPD = 0x1A,
117 MQTT_SN_MSG_TYPE_WILLTOPICRESP = 0x1B,
118 MQTT_SN_MSG_TYPE_WILLMSGUPD = 0x1C,
119 MQTT_SN_MSG_TYPE_WILLMSGRESP = 0x1D,
120 MQTT_SN_MSG_TYPE_ENCAPSULATED = 0xFE
122
123
128typedef enum
129{
130 MQTT_SN_RETURN_CODE_ACCEPTED = 0,
131 MQTT_SN_RETURN_CODE_REJECTED_CONGESTION = 1,
132 MQTT_SN_RETURN_CODE_REJECTED_INVALID_TOPIC_ID = 2,
133 MQTT_SN_RETURN_CODE_REJECTED_NOT_SUPPORTED = 3
135
136
137//CodeWarrior or Win32 compiler?
138#if defined(__CWCC__) || defined(_WIN32)
139 #pragma pack(push, 1)
140#endif
141
142
148{
149 __packed_union
150 {
151 uint8_t all;
153 {
154#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
155 uint8_t dup : 1;
156 uint8_t qos : 2;
157 uint8_t retain : 1;
158 uint8_t will : 1;
159 uint8_t cleanSession : 1;
160 uint8_t topicIdType : 2;
161#else
162 uint8_t topicIdType : 2;
163 uint8_t cleanSession : 1;
164 uint8_t will : 1;
165 uint8_t retain : 1;
166 uint8_t qos : 2;
167 uint8_t dup : 1;
168#endif
169 };
170 };
171} MqttSnFlags;
172
173
178typedef __packed_struct
179{
180 uint8_t length;
181 uint8_t msgType;
182 uint8_t data[];
183} MqttSnHeader;
184
185
190typedef __packed_struct
191{
192 uint8_t prefix;
193 uint16_t length;
194 uint8_t msgType;
195 uint8_t data[];
196} MqttSnExtHeader;
197
198
203typedef __packed_struct
204{
205 uint8_t gwId;
206 uint16_t duration;
207} MqttSnAdvertise;
208
209
214typedef __packed_struct
215{
216 uint8_t radius;
217} MqttSnSearchGw;
218
219
224typedef __packed_struct
225{
226 uint8_t gwId;
227 uint8_t gwAdd[];
228} MqttSnGwInfo;
229
230
235typedef __packed_struct
236{
237 MqttSnFlags flags;
238 uint8_t protocolId;
239 uint16_t duration;
240 char_t clientId[];
241} MqttSnConnect;
242
243
248typedef __packed_struct
249{
250 uint8_t returnCode;
251} MqttSnConnAck;
252
253
259
260
265typedef __packed_struct
266{
267 MqttSnFlags flags;
268 char_t willTopic[];
269} MqttSnWillTopic;
270
271
276typedef void MqttSnWillMsgReq;
277
278
283typedef void MqttSnWillMsg;
284
285
290typedef __packed_struct
291{
292 uint16_t topicId;
293 uint16_t msgId;
294 char_t topicName[];
295} MqttSnRegister;
296
297
302typedef __packed_struct
303{
304 uint16_t topicId;
305 uint16_t msgId;
306 uint8_t returnCode;
307} MqttSnRegAck;
308
309
314typedef __packed_struct
315{
316 MqttSnFlags flags;
317 uint16_t topicId;
318 uint16_t msgId;
319 uint8_t data[];
320} MqttSnPublish;
321
322
327typedef __packed_struct
328{
329 uint16_t topicId;
330 uint16_t msgId;
331 uint8_t returnCode;
332} MqttSnPubAck;
333
334
339typedef __packed_struct
340{
341 uint16_t msgId;
342} MqttSnPubRec;
343
344
349typedef __packed_struct
350{
351 uint16_t msgId;
352} MqttSnPubRel;
353
354
359typedef __packed_struct
360{
361 uint16_t msgId;
362} MqttSnPubComp;
363
364
369typedef __packed_struct
370{
371 MqttSnFlags flags;
372 uint16_t msgId;
373 char_t topicName[];
374} MqttSnSubscribe;
375
376
381typedef __packed_struct
382{
383 MqttSnFlags flags;
384 uint16_t topicId;
385 uint16_t msgId;
386 uint8_t returnCode;
387} MqttSnSubAck;
388
389
394typedef __packed_struct
395{
396 MqttSnFlags flags;
397 uint16_t msgId;
398 char_t topicName[];
399} MqttSnUnsubscribe;
400
401
406typedef __packed_struct
407{
408 uint16_t msgId;
409} MqttSnUnsubAck;
410
411
416typedef void MqttSnPingReq;
417
418
423typedef void MqttSnPingResp;
424
425
430typedef __packed_struct
431{
432 uint16_t duration;
433} MqttSnDisconnect;
434
435
440typedef __packed_struct
441{
442 MqttSnFlags flags;
443 char_t willTopic[];
444} MqttSnWillTopicUpd;
445
446
451typedef __packed_struct
452{
453 uint8_t returnCode;
454} MqttSnWillTopicResp;
455
456
461typedef void MqttSnWillMsgUpd;
462
463
468typedef __packed_struct
469{
470 uint8_t returnCode;
471} MqttSnWillMsgResp;
472
473
474//CodeWarrior or Win32 compiler?
475#if defined(__CWCC__) || defined(_WIN32)
476 #pragma pack(pop)
477#endif
478
479
484typedef struct
485{
486 const char_t *topicName;
487 uint16_t topicId;
489
490
491//C++ guard
492#ifdef __cplusplus
493}
494#endif
495
496#endif
MqttSnMsgType
MQTT-SN message types.
Definition mqtt_sn_common.h:92
MqttSnTransportProtocol
MQTT-SN transport protocols.
Definition mqtt_sn_common.h:55
@ MQTT_SN_TRANSPORT_PROTOCOL_DTLS
DTLS protocol.
Definition mqtt_sn_common.h:57
@ MQTT_SN_TRANSPORT_PROTOCOL_UDP
UDP protocol.
Definition mqtt_sn_common.h:56
MqttSnQosLevel
Quality of service level.
Definition mqtt_sn_common.h:66
@ MQTT_SN_QOS_LEVEL_MINUS_1
No connection setup.
Definition mqtt_sn_common.h:70
@ MQTT_SN_QOS_LEVEL_1
At least once delivery.
Definition mqtt_sn_common.h:68
@ MQTT_SN_QOS_LEVEL_0
At most once delivery.
Definition mqtt_sn_common.h:67
@ MQTT_SN_QOS_LEVEL_2
Exactly once delivery.
Definition mqtt_sn_common.h:69
MqttSnTopicIdType
Topic ID types.
Definition mqtt_sn_common.h:79
@ MQTT_SN_NORMAL_TOPIC_ID
Normal topic ID.
Definition mqtt_sn_common.h:80
@ MQTT_SN_SHORT_TOPIC_NAME
Short topic name.
Definition mqtt_sn_common.h:83
@ MQTT_SN_PREDEFINED_TOPIC_ID
Predefined topic ID.
Definition mqtt_sn_common.h:81
@ MQTT_SN_NORMAL_TOPIC_NAME
Normal topic name.
Definition mqtt_sn_common.h:82
void MqttSnPingResp
PINGRESP message.
Definition mqtt_sn_common.h:423
void MqttSnWillMsgUpd
WILLMSGUPD message.
Definition mqtt_sn_common.h:461
void MqttSnWillTopicReq
WILLTOPICREQ message.
Definition mqtt_sn_common.h:258
void MqttSnWillMsg
WILLMSG message.
Definition mqtt_sn_common.h:283
void MqttSnWillMsgReq
WILLMSGREQ message.
Definition mqtt_sn_common.h:276
MqttSnReturnCode
MQTT-SN return codes.
Definition mqtt_sn_common.h:129
typedef __packed_struct
MQTT-SN flags.
Definition mqtt_sn_common.h:148
void MqttSnPingReq
PINGREQ message.
Definition mqtt_sn_common.h:416
TCP/IP stack core.
Predefined topic.
Definition mqtt_sn_common.h:485
uint16_t topicId
Topic identifier.
Definition mqtt_sn_common.h:487
const char_t * topicName
Topic name.
Definition mqtt_sn_common.h:486