mqtt_sn_common.h
Go to the documentation of this file.
1 /**
2  * @file mqtt_sn_common.h
3  * @brief Definitions common to MQTT-SN client and gateway
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _MQTT_SN_COMMON_H
30 #define _MQTT_SN_COMMON_H
31 
32 //Dependencies
33 #include "core/net.h"
34 
35 //MQTT-SN port number
36 #define MQTT_SN_PORT 1883
37 
38 //C++ guard
39 #ifdef __cplusplus
40  extern "C" {
41 #endif
42 
43 //MQTT-SN protocol identifier
44 #define MQTT_SN_PROTOCOL_ID 0x01
45 //Reserved topic identifier
46 #define MQTT_SN_INVALID_TOPIC_ID 0x0000
47 
48 
49 /**
50  * @brief MQTT-SN transport protocols
51  **/
52 
53 typedef enum {
54  MQTT_SN_TRANSPORT_PROTOCOL_UDP = 1, ///<UDP protocol
55  MQTT_SN_TRANSPORT_PROTOCOL_DTLS = 2 ///<DTLS protocol
57 
58 
59 /**
60  * @brief Quality of service level
61  **/
62 
63 typedef enum
64 {
65  MQTT_SN_QOS_LEVEL_0 = 0, ///<At most once delivery
66  MQTT_SN_QOS_LEVEL_1 = 1, ///<At least once delivery
67  MQTT_SN_QOS_LEVEL_2 = 2, ///<Exactly once delivery
68  MQTT_SN_QOS_LEVEL_MINUS_1 = 3 ///<No connection setup
70 
71 
72 /**
73  * @brief Topic ID types
74  **/
75 
76 typedef enum
77 {
78  MQTT_SN_NORMAL_TOPIC_ID = 0, ///<Normal topic ID
79  MQTT_SN_PREDEFINED_TOPIC_ID = 1, ///<Predefined topic ID
80  MQTT_SN_NORMAL_TOPIC_NAME = 0, ///<Normal topic name
81  MQTT_SN_SHORT_TOPIC_NAME = 2 ///<Short topic name
83 
84 
85 /**
86  * @brief MQTT-SN message types
87  **/
88 
89 typedef enum
90 {
119 } MqttSnMsgType;
120 
121 
122 /**
123  * @brief MQTT-SN return codes
124  **/
125 
126 typedef enum
127 {
133 
134 
135 //CodeWarrior or Win32 compiler?
136 #if defined(__CWCC__) || defined(_WIN32)
137  #pragma pack(push, 1)
138 #endif
139 
140 
141 /**
142  * @brief MQTT-SN flags
143  **/
144 
145 typedef __start_packed struct
146 {
147  __start_packed union
148  {
149  uint8_t all;
150  __start_packed struct
151  {
152 #ifdef _CPU_BIG_ENDIAN
153  uint8_t dup : 1;
154  uint8_t qos : 2;
155  uint8_t retain : 1;
156  uint8_t will : 1;
157  uint8_t cleanSession : 1;
158  uint8_t topicIdType : 2;
159 #else
160  uint8_t topicIdType : 2;
161  uint8_t cleanSession : 1;
162  uint8_t will : 1;
163  uint8_t retain : 1;
164  uint8_t qos : 2;
165  uint8_t dup : 1;
166 #endif
167  };
168  };
170 
171 
172 /**
173  * @brief Message header
174  **/
175 
176 typedef __start_packed struct
177 {
178  uint8_t length;
179  uint8_t msgType;
180  uint8_t data[];
182 
183 
184 /**
185  * @brief Extended message header
186  **/
187 
188 typedef __start_packed struct
189 {
190  uint8_t prefix;
191  uint16_t length;
192  uint8_t msgType;
193  uint8_t data[];
195 
196 
197 /**
198  * @brief ADVERTISE message
199  **/
200 
201 typedef __start_packed struct
202 {
203  uint8_t gwId;
204  uint16_t duration;
206 
207 
208 /**
209  * @brief SEARCHGW message
210  **/
211 
212 typedef __start_packed struct
213 {
214  uint8_t radius;
216 
217 
218 /**
219  * @brief GWINFO message
220  **/
221 
222 typedef __start_packed struct
223 {
224  uint8_t gwId;
225  uint8_t gwAdd[];
227 
228 
229 /**
230  * @brief CONNECT message
231  **/
232 
233 typedef __start_packed struct
234 {
236  uint8_t protocolId;
237  uint16_t duration;
240 
241 
242 /**
243  * @brief CONNACK message
244  **/
245 
246 typedef __start_packed struct
247 {
248  uint8_t returnCode;
250 
251 
252 /**
253  * @brief WILLTOPICREQ message
254  **/
255 
256 typedef void MqttSnWillTopicReq;
257 
258 
259 /**
260  * @brief WILLTOPIC message
261  **/
262 
263 typedef __start_packed struct
264 {
268 
269 
270 /**
271  * @brief WILLMSGREQ message
272  **/
273 
274 typedef void MqttSnWillMsgReq;
275 
276 
277 /**
278  * @brief WILLMSG message
279  **/
280 
281 typedef void MqttSnWillMsg;
282 
283 
284 /**
285  * @brief REGISTER message
286  **/
287 
288 typedef __start_packed struct
289 {
290  uint16_t topicId;
291  uint16_t msgId;
294 
295 
296 /**
297  * @brief REGACK message
298  **/
299 
300 typedef __start_packed struct
301 {
302  uint16_t topicId;
303  uint16_t msgId;
304  uint8_t returnCode;
306 
307 
308 /**
309  * @brief PUBLISH message
310  **/
311 
312 typedef __start_packed struct
313 {
315  uint16_t topicId;
316  uint16_t msgId;
317  uint8_t data[];
319 
320 
321 /**
322  * @brief PUBACK message
323  **/
324 
325 typedef __start_packed struct
326 {
327  uint16_t topicId;
328  uint16_t msgId;
329  uint8_t returnCode;
331 
332 
333 /**
334  * @brief PUBREC message
335  **/
336 
337 typedef __start_packed struct
338 {
339  uint16_t msgId;
341 
342 
343 /**
344  * @brief PUBREL message
345  **/
346 
347 typedef __start_packed struct
348 {
349  uint16_t msgId;
351 
352 
353 /**
354  * @brief PUBCOMP message
355  **/
356 
357 typedef __start_packed struct
358 {
359  uint16_t msgId;
361 
362 
363 /**
364  * @brief SUBSCRIBE message
365  **/
366 
367 typedef __start_packed struct
368 {
370  uint16_t msgId;
371  char_t topicName[];
373 
374 
375 /**
376  * @brief SUBACK message
377  **/
378 
379 typedef __start_packed struct
380 {
382  uint16_t topicId;
383  uint16_t msgId;
384  uint8_t returnCode;
386 
387 
388 /**
389  * @brief UNSUBSCRIBE message
390  **/
391 
392 typedef __start_packed struct
393 {
395  uint16_t msgId;
396  char_t topicName[];
398 
399 
400 /**
401  * @brief UNSUBACK message
402  **/
403 
404 typedef __start_packed struct
405 {
406  uint16_t msgId;
408 
409 
410 /**
411  * @brief PINGREQ message
412  **/
413 
414 typedef void MqttSnPingReq;
415 
416 
417 /**
418  * @brief PINGRESP message
419  **/
420 
421 typedef void MqttSnPingResp;
422 
423 
424 /**
425  * @brief DISCONNECT message
426  **/
427 
428 typedef __start_packed struct
429 {
430  uint16_t duration;
432 
433 
434 /**
435  * @brief WILLTOPICUPD message
436  **/
437 
438 typedef __start_packed struct
439 {
441  char_t willTopic[];
443 
444 
445 /**
446  * @brief WILLTOPICRESP message
447  **/
448 
449 typedef __start_packed struct
450 {
451  uint8_t returnCode;
453 
454 
455 /**
456  * @brief WILLMSGUPD message
457  **/
458 
459 typedef void MqttSnWillMsgUpd;
460 
461 
462 /**
463  * @brief WILLMSGRESP message
464  **/
465 
466 typedef __start_packed struct
467 {
468  uint8_t returnCode;
470 
471 
472 //CodeWarrior or Win32 compiler?
473 #if defined(__CWCC__) || defined(_WIN32)
474  #pragma pack(pop)
475 #endif
476 
477 
478 /**
479  * @brief Predefined topic
480  **/
481 
482 typedef struct
483 {
484  const char_t *topicName; ///<Topic name
485  uint16_t topicId; ///<Topic identifier
487 
488 
489 //C++ guard
490 #ifdef __cplusplus
491  }
492 #endif
493 
494 #endif
uint8_t returnCode
uint8_t prefix
__start_packed struct @257 MqttSnWillTopicResp
WILLTOPICRESP message.
__start_packed struct @246 MqttSnPublish
PUBLISH message.
At most once delivery.
__start_packed struct @249 MqttSnPubRel
PUBREL message.
uint8_t topicIdType
char char_t
Definition: compiler_port.h:41
__start_packed struct @247 MqttSnPubAck
PUBACK message.
Exactly once delivery.
At least once delivery.
__start_packed struct @254 MqttSnUnsubAck
UNSUBACK message.
TCP/IP stack core.
uint8_t radius
Short topic name.
Predefined topic ID.
__start_packed struct @253 MqttSnUnsubscribe
UNSUBSCRIBE message.
uint8_t gwId
void MqttSnWillMsgUpd
WILLMSGUPD message.
Normal topic name.
MqttSnQosLevel
Quality of service level.
uint8_t all
__start_packed struct @248 MqttSnPubRec
PUBREC message.
uint8_t retain
uint16_t msgId
MqttSnTopicIdType
Topic ID types.
MqttSnMsgType
MQTT-SN message types.
uint16_t duration
uint8_t dup
uint8_t will
__start_packed struct @243 MqttSnWillTopic
WILLTOPIC message.
Normal topic ID.
MqttSnFlags flags
uint8_t msgType
__start_packed struct @240 MqttSnGwInfo
GWINFO message.
char_t willTopic[]
uint8_t cleanSession
uint8_t qos
char_t clientId[]
__start_packed struct @250 MqttSnPubComp
PUBCOMP message.
uint8_t data[]
uint16_t topicId
Topic identifier.
Predefined topic.
__start_packed struct @239 MqttSnSearchGw
SEARCHGW message.
uint8_t protocolId
char_t topicName[]
MqttSnTransportProtocol
MQTT-SN transport protocols.
__start_packed struct @242 MqttSnConnAck
CONNACK message.
uint16_t topicId
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @245 MqttSnRegAck
REGACK message.
__start_packed struct @256 MqttSnWillTopicUpd
WILLTOPICUPD message.
void MqttSnPingResp
PINGRESP message.
__start_packed struct @244 MqttSnRegister
REGISTER message.
__start_packed struct @235 MqttSnFlags
MQTT-SN flags.
void MqttSnWillMsg
WILLMSG message.
void MqttSnPingReq
PINGREQ message.
__start_packed struct @238 MqttSnAdvertise
ADVERTISE message.
MqttSnReturnCode
MQTT-SN return codes.
uint8_t length
const char_t * topicName
Topic name.
__start_packed struct @251 MqttSnSubscribe
SUBSCRIBE message.
No connection setup.
__start_packed struct @252 MqttSnSubAck
SUBACK message.
void MqttSnWillMsgReq
WILLMSGREQ message.
__start_packed struct @236 MqttSnHeader
Message header.
__start_packed struct @237 MqttSnExtHeader
Extended message header.
__start_packed struct @258 MqttSnWillMsgResp
WILLMSGRESP message.
void MqttSnWillTopicReq
WILLTOPICREQ message.
__start_packed struct @241 MqttSnConnect
CONNECT message.
uint8_t gwAdd[]
__start_packed struct @255 MqttSnDisconnect
DISCONNECT message.