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  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
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
42 extern "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 
51 /**
52  * @brief MQTT-SN transport protocols
53  **/
54 
55 typedef enum {
56  MQTT_SN_TRANSPORT_PROTOCOL_UDP = 1, ///<UDP protocol
57  MQTT_SN_TRANSPORT_PROTOCOL_DTLS = 2 ///<DTLS protocol
59 
60 
61 /**
62  * @brief Quality of service level
63  **/
64 
65 typedef enum
66 {
67  MQTT_SN_QOS_LEVEL_0 = 0, ///<At most once delivery
68  MQTT_SN_QOS_LEVEL_1 = 1, ///<At least once delivery
69  MQTT_SN_QOS_LEVEL_2 = 2, ///<Exactly once delivery
70  MQTT_SN_QOS_LEVEL_MINUS_1 = 3 ///<No connection setup
72 
73 
74 /**
75  * @brief Topic ID types
76  **/
77 
78 typedef enum
79 {
80  MQTT_SN_NORMAL_TOPIC_ID = 0, ///<Normal topic ID
81  MQTT_SN_PREDEFINED_TOPIC_ID = 1, ///<Predefined topic ID
82  MQTT_SN_NORMAL_TOPIC_NAME = 0, ///<Normal topic name
83  MQTT_SN_SHORT_TOPIC_NAME = 2 ///<Short topic name
85 
86 
87 /**
88  * @brief MQTT-SN message types
89  **/
90 
91 typedef enum
92 {
121 } MqttSnMsgType;
122 
123 
124 /**
125  * @brief MQTT-SN return codes
126  **/
127 
128 typedef enum
129 {
135 
136 
137 //CodeWarrior or Win32 compiler?
138 #if defined(__CWCC__) || defined(_WIN32)
139  #pragma pack(push, 1)
140 #endif
141 
142 
143 /**
144  * @brief MQTT-SN flags
145  **/
146 
147 typedef __start_packed struct
148 {
149  __start_packed union
150  {
151  uint8_t all;
152  __start_packed struct
153  {
154 #ifdef _CPU_BIG_ENDIAN
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  };
172 
173 
174 /**
175  * @brief Message header
176  **/
177 
178 typedef __start_packed struct
179 {
180  uint8_t length;
181  uint8_t msgType;
182  uint8_t data[];
184 
185 
186 /**
187  * @brief Extended message header
188  **/
189 
190 typedef __start_packed struct
191 {
192  uint8_t prefix;
193  uint16_t length;
194  uint8_t msgType;
195  uint8_t data[];
197 
198 
199 /**
200  * @brief ADVERTISE message
201  **/
202 
203 typedef __start_packed struct
204 {
205  uint8_t gwId;
206  uint16_t duration;
208 
209 
210 /**
211  * @brief SEARCHGW message
212  **/
213 
214 typedef __start_packed struct
215 {
216  uint8_t radius;
218 
219 
220 /**
221  * @brief GWINFO message
222  **/
223 
224 typedef __start_packed struct
225 {
226  uint8_t gwId;
227  uint8_t gwAdd[];
229 
230 
231 /**
232  * @brief CONNECT message
233  **/
234 
235 typedef __start_packed struct
236 {
238  uint8_t protocolId;
239  uint16_t duration;
242 
243 
244 /**
245  * @brief CONNACK message
246  **/
247 
248 typedef __start_packed struct
249 {
250  uint8_t returnCode;
252 
253 
254 /**
255  * @brief WILLTOPICREQ message
256  **/
257 
258 typedef void MqttSnWillTopicReq;
259 
260 
261 /**
262  * @brief WILLTOPIC message
263  **/
264 
265 typedef __start_packed struct
266 {
270 
271 
272 /**
273  * @brief WILLMSGREQ message
274  **/
275 
276 typedef void MqttSnWillMsgReq;
277 
278 
279 /**
280  * @brief WILLMSG message
281  **/
282 
283 typedef void MqttSnWillMsg;
284 
285 
286 /**
287  * @brief REGISTER message
288  **/
289 
290 typedef __start_packed struct
291 {
292  uint16_t topicId;
293  uint16_t msgId;
296 
297 
298 /**
299  * @brief REGACK message
300  **/
301 
302 typedef __start_packed struct
303 {
304  uint16_t topicId;
305  uint16_t msgId;
306  uint8_t returnCode;
308 
309 
310 /**
311  * @brief PUBLISH message
312  **/
313 
314 typedef __start_packed struct
315 {
317  uint16_t topicId;
318  uint16_t msgId;
319  uint8_t data[];
321 
322 
323 /**
324  * @brief PUBACK message
325  **/
326 
327 typedef __start_packed struct
328 {
329  uint16_t topicId;
330  uint16_t msgId;
331  uint8_t returnCode;
333 
334 
335 /**
336  * @brief PUBREC message
337  **/
338 
339 typedef __start_packed struct
340 {
341  uint16_t msgId;
343 
344 
345 /**
346  * @brief PUBREL message
347  **/
348 
349 typedef __start_packed struct
350 {
351  uint16_t msgId;
353 
354 
355 /**
356  * @brief PUBCOMP message
357  **/
358 
359 typedef __start_packed struct
360 {
361  uint16_t msgId;
363 
364 
365 /**
366  * @brief SUBSCRIBE message
367  **/
368 
369 typedef __start_packed struct
370 {
372  uint16_t msgId;
373  char_t topicName[];
375 
376 
377 /**
378  * @brief SUBACK message
379  **/
380 
381 typedef __start_packed struct
382 {
384  uint16_t topicId;
385  uint16_t msgId;
386  uint8_t returnCode;
388 
389 
390 /**
391  * @brief UNSUBSCRIBE message
392  **/
393 
394 typedef __start_packed struct
395 {
397  uint16_t msgId;
398  char_t topicName[];
400 
401 
402 /**
403  * @brief UNSUBACK message
404  **/
405 
406 typedef __start_packed struct
407 {
408  uint16_t msgId;
410 
411 
412 /**
413  * @brief PINGREQ message
414  **/
415 
416 typedef void MqttSnPingReq;
417 
418 
419 /**
420  * @brief PINGRESP message
421  **/
422 
423 typedef void MqttSnPingResp;
424 
425 
426 /**
427  * @brief DISCONNECT message
428  **/
429 
430 typedef __start_packed struct
431 {
432  uint16_t duration;
434 
435 
436 /**
437  * @brief WILLTOPICUPD message
438  **/
439 
440 typedef __start_packed struct
441 {
443  char_t willTopic[];
445 
446 
447 /**
448  * @brief WILLTOPICRESP message
449  **/
450 
451 typedef __start_packed struct
452 {
453  uint8_t returnCode;
455 
456 
457 /**
458  * @brief WILLMSGUPD message
459  **/
460 
461 typedef void MqttSnWillMsgUpd;
462 
463 
464 /**
465  * @brief WILLMSGRESP message
466  **/
467 
468 typedef __start_packed struct
469 {
470  uint8_t returnCode;
472 
473 
474 //CodeWarrior or Win32 compiler?
475 #if defined(__CWCC__) || defined(_WIN32)
476  #pragma pack(pop)
477 #endif
478 
479 
480 /**
481  * @brief Predefined topic
482  **/
483 
484 typedef struct
485 {
486  const char_t *topicName; ///<Topic name
487  uint16_t topicId; ///<Topic identifier
489 
490 
491 //C++ guard
492 #ifdef __cplusplus
493 }
494 #endif
495 
496 #endif
__start_packed struct @242 MqttSnRegAck
REGACK message.
__start_packed struct @252 MqttSnDisconnect
DISCONNECT message.
__start_packed struct @247 MqttSnPubComp
PUBCOMP message.
__start_packed struct @234 MqttSnExtHeader
Extended message header.
@ MQTT_SN_MSG_TYPE_PINGRESP
__start_packed struct @238 MqttSnConnect
CONNECT message.
@ MQTT_SN_MSG_TYPE_WILLMSG
@ MQTT_SN_MSG_TYPE_ADVERTISE
@ MQTT_SN_MSG_TYPE_REGISTER
Predefined topic.
@ MQTT_SN_SHORT_TOPIC_NAME
Short topic name.
@ MQTT_SN_MSG_TYPE_PINGREQ
@ MQTT_SN_TRANSPORT_PROTOCOL_DTLS
DTLS protocol.
__start_packed struct @239 MqttSnConnAck
CONNACK message.
void MqttSnWillMsgReq
WILLMSGREQ message.
@ MQTT_SN_MSG_TYPE_CONNECT
__start_packed struct @251 MqttSnUnsubAck
UNSUBACK message.
@ MQTT_SN_QOS_LEVEL_1
At least once delivery.
MqttSnReturnCode
MQTT-SN return codes.
@ MQTT_SN_PREDEFINED_TOPIC_ID
Predefined topic ID.
MqttSnQosLevel
Quality of service level.
@ MQTT_SN_NORMAL_TOPIC_NAME
Normal topic name.
@ MQTT_SN_RETURN_CODE_REJECTED_NOT_SUPPORTED
@ MQTT_SN_MSG_TYPE_GWINFO
uint16_t msgId
@ MQTT_SN_RETURN_CODE_REJECTED_CONGESTION
@ MQTT_SN_MSG_TYPE_WILLTOPICRESP
uint16_t topicId
char_t willTopic[]
@ MQTT_SN_MSG_TYPE_PUBREL
__start_packed struct @233 MqttSnHeader
Message header.
uint8_t length
uint8_t returnCode
uint8_t prefix
uint8_t gwAdd[]
__start_packed struct @232 MqttSnFlags
MQTT-SN flags.
__start_packed struct @236 MqttSnSearchGw
SEARCHGW message.
@ MQTT_SN_MSG_TYPE_WILLTOPICREQ
@ MQTT_SN_MSG_TYPE_WILLMSGREQ
@ MQTT_SN_NORMAL_TOPIC_ID
Normal topic ID.
void MqttSnPingResp
PINGRESP message.
__start_packed struct @253 MqttSnWillTopicUpd
WILLTOPICUPD message.
__start_packed struct @240 MqttSnWillTopic
WILLTOPIC message.
__start_packed struct @235 MqttSnAdvertise
ADVERTISE message.
@ MQTT_SN_MSG_TYPE_PUBREC
@ MQTT_SN_TRANSPORT_PROTOCOL_UDP
UDP protocol.
uint8_t radius
@ MQTT_SN_MSG_TYPE_WILLTOPICUPD
@ MQTT_SN_MSG_TYPE_SUBSCRIBE
@ MQTT_SN_MSG_TYPE_PUBLISH
@ MQTT_SN_MSG_TYPE_WILLMSGRESP
@ MQTT_SN_MSG_TYPE_PUBCOMP
@ MQTT_SN_MSG_TYPE_DISCONNECT
uint8_t qos
MqttSnTopicIdType
Topic ID types.
uint8_t will
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @246 MqttSnPubRel
PUBREL message.
char_t topicName[]
__start_packed struct @249 MqttSnSubAck
SUBACK message.
__start_packed struct @241 MqttSnRegister
REGISTER message.
@ MQTT_SN_MSG_TYPE_REGACK
__start_packed struct @245 MqttSnPubRec
PUBREC message.
MqttSnFlags flags
__start_packed struct @237 MqttSnGwInfo
GWINFO message.
__start_packed struct @244 MqttSnPubAck
PUBACK message.
uint8_t gwId
uint16_t duration
char char_t
Definition: compiler_port.h:43
MqttSnMsgType
MQTT-SN message types.
void MqttSnWillTopicReq
WILLTOPICREQ message.
const char_t * topicName
Topic name.
uint8_t msgType
@ MQTT_SN_MSG_TYPE_WILLMSGUPD
@ MQTT_SN_MSG_TYPE_SEARCHGW
__start_packed struct @255 MqttSnWillMsgResp
WILLMSGRESP message.
@ MQTT_SN_RETURN_CODE_REJECTED_INVALID_TOPIC_ID
void MqttSnWillMsg
WILLMSG message.
@ MQTT_SN_RETURN_CODE_ACCEPTED
uint8_t protocolId
__start_packed struct @254 MqttSnWillTopicResp
WILLTOPICRESP message.
uint8_t cleanSession
uint8_t all
void MqttSnPingReq
PINGREQ message.
void MqttSnWillMsgUpd
WILLMSGUPD message.
@ MQTT_SN_MSG_TYPE_UNSUBACK
__start_packed struct @243 MqttSnPublish
PUBLISH message.
uint8_t topicIdType
uint16_t topicId
Topic identifier.
MqttSnTransportProtocol
MQTT-SN transport protocols.
char_t clientId[]
uint8_t data[]
TCP/IP stack core.
@ MQTT_SN_MSG_TYPE_UNSUBSCRIBE
@ MQTT_SN_MSG_TYPE_ENCAPSULATED
@ MQTT_SN_QOS_LEVEL_MINUS_1
No connection setup.
@ MQTT_SN_MSG_TYPE_WILLTOPIC
__start_packed struct @250 MqttSnUnsubscribe
UNSUBSCRIBE message.
uint8_t retain
@ MQTT_SN_MSG_TYPE_CONNACK
__start_packed struct @248 MqttSnSubscribe
SUBSCRIBE message.
@ MQTT_SN_QOS_LEVEL_2
Exactly once delivery.
@ MQTT_SN_QOS_LEVEL_0
At most once delivery.
@ MQTT_SN_MSG_TYPE_PUBACK
uint8_t dup
@ MQTT_SN_MSG_TYPE_SUBACK