mqtt_sn_message.h
Go to the documentation of this file.
1 /**
2  * @file mqtt_sn_message.h
3  * @brief MQTT-SN message formatting and parsing
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_MESSAGE_H
30 #define _MQTT_SN_MESSAGE_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "mqtt_sn/mqtt_sn_common.h"
35 
36 //Maximum size of MQTT-SN messages
37 #ifndef MQTT_SN_MAX_MSG_SIZE
38  #define MQTT_SN_MAX_MSG_SIZE 1024
39 #elif (MQTT_SN_MAX_MSG_SIZE < 16)
40  #error MQTT_SN_MAX_MSG_SIZE parameter is not valid
41 #endif
42 
43 //C++ guard
44 #ifdef __cplusplus
45  extern "C" {
46 #endif
47 
48 
49 /**
50  * @brief MQTT-SN message
51  **/
52 
53 typedef struct
54 {
55  uint8_t buffer[MQTT_SN_MAX_MSG_SIZE + 1];
56  size_t length;
57  size_t pos;
59 
60 
61 //MQTT-SN related functions
63  size_t length);
64 
66  uint8_t radius);
67 
69  uint16_t duration, const char_t *clientId);
70 
72  const char_t *topicName);
73 
75  size_t dataLen);
76 
78  uint16_t msgId, uint16_t topicId, const char_t *topicName);
79 
82 
84  uint16_t msgId, uint16_t topicId, const char_t *topicName,
85  const uint8_t *data, size_t dataLen);
86 
89 
93 
95  uint16_t msgId, uint16_t topicId, const char_t *topicName);
96 
98  uint16_t msgId, uint16_t topicId, const char_t *topicName);
99 
102 
104  uint16_t duration);
105 
107  const char_t *topicName);
108 
110  size_t dataLen);
111 
113 
115  const uint8_t **gwAdd, size_t *gwAddLen);
116 
119 
122 
124  uint16_t *topicId, const char_t **topicName);
125 
127  uint16_t *topicId, MqttSnReturnCode *returnCode);
128 
130  uint16_t *msgId, uint16_t *topicId, const uint8_t **data, size_t *dataLen);
131 
133  uint16_t *topicId, MqttSnReturnCode *returnCode);
134 
138 
140  uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode);
141 
143 
145  const char_t **clientId);
146 
148 
150  uint16_t *duration);
151 
154 
157 
158 //C++ guard
159 #ifdef __cplusplus
160  }
161 #endif
162 
163 #endif
uint8_t returnCode
error_t mqttSnFormatPubRel(MqttSnMessage *message, uint16_t msgId)
Format PUBREL message.
char char_t
Definition: compiler_port.h:41
uint8_t flags
Definition: tcp.h:312
error_t mqttSnFormatWillMsg(MqttSnMessage *message, const void *data, size_t dataLen)
Format WILLMSG message.
error_t mqttSnFormatRegAck(MqttSnMessage *message, uint16_t msgId, uint16_t topicId, MqttSnReturnCode returnCode)
Format REGACK message.
TCP/IP stack core.
uint8_t radius
error_t mqttSnFormatPubRec(MqttSnMessage *message, uint16_t msgId)
Format PUBREC message.
error_t mqttSnParseConnAck(const MqttSnMessage *message, MqttSnReturnCode *returnCode)
Parse CONNACK message.
uint8_t message[]
Definition: chap.h:150
error_t mqttSnFormatUnsubscribe(MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName)
Format UNSUBSCRIBE message.
uint8_t gwId
error_t mqttSnParsePingReq(const MqttSnMessage *message, const char_t **clientId)
Parse PINGREQ message.
error_t mqttSnFormatPingResp(MqttSnMessage *message)
Format PINGRESP message.
MQTT-SN message.
error_t mqttSnFormatSearchGw(MqttSnMessage *message, uint8_t radius)
Format SEARCHGW message.
char_t type
error_t mqttSnParsePubRel(const MqttSnMessage *message, uint16_t *msgId)
Parse PUBREL message.
error_t mqttSnFormatWillTopicUpd(MqttSnMessage *message, MqttSnFlags flags, const char_t *topicName)
Format WILLTOPICUPD message.
uint16_t msgId
MqttSnMsgType
MQTT-SN message types.
uint16_t duration
error_t mqttSnFormatRegister(MqttSnMessage *message, uint16_t msgId, uint16_t topicId, const char_t *topicName)
Format REGISTER message.
error_t mqttSnParseUnsubAck(const MqttSnMessage *message, uint16_t *msgId)
Parse UNSUBACK message.
error_t mqttSnParseRegAck(const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
Parse REGACK message.
error_t mqttSnParseWillTopicReq(const MqttSnMessage *message)
Parse WILLTOPICREQ message.
error_t mqttSnParsePubAck(const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
Parse PUBACK message.
char_t clientId[]
#define MQTT_SN_MAX_MSG_SIZE
Definitions common to MQTT-SN client and gateway.
char_t topicName[]
uint16_t topicId
error_t mqttSnParseRegister(const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, const char_t **topicName)
Parse REGISTER message.
__start_packed struct @235 MqttSnFlags
MQTT-SN flags.
error_t
Error codes.
Definition: error.h:40
error_t mqttSnParsePubComp(const MqttSnMessage *message, uint16_t *msgId)
Parse PUBCOMP message.
error_t mqttSnParseWillMsgResp(const MqttSnMessage *message, MqttSnReturnCode *returnCode)
Parse WILLMSGRESP message.
error_t mqttSnFormatWillMsgUpd(MqttSnMessage *message, const void *data, size_t dataLen)
Format WILLMSGUPD message.
error_t mqttSnParseHeader(MqttSnMessage *message, MqttSnMsgType *type)
Format MQTT-SN message header.
error_t mqttSnParseWillMsgReq(const MqttSnMessage *message)
Parse WILLMSGREQ message.
error_t mqttSnFormatWillTopic(MqttSnMessage *message, MqttSnFlags flags, const char_t *topicName)
Format WILLTOPIC message.
uint8_t data[]
Definition: dtls_misc.h:167
error_t mqttSnFormatPubAck(MqttSnMessage *message, uint16_t msgId, uint16_t topicId, MqttSnReturnCode returnCode)
Format PUBACK message.
error_t mqttSnFormatHeader(MqttSnMessage *message, MqttSnMsgType type, size_t length)
Format MQTT-SN message header.
error_t mqttSnFormatPingReq(MqttSnMessage *message, const char_t *clientId)
Format PINGREQ message.
MqttSnReturnCode
MQTT-SN return codes.
error_t mqttSnParsePublish(const MqttSnMessage *message, MqttSnFlags *flags, uint16_t *msgId, uint16_t *topicId, const uint8_t **data, size_t *dataLen)
Parse PUBLISH message.
error_t mqttSnParseWillTopicResp(const MqttSnMessage *message, MqttSnReturnCode *returnCode)
Parse WILLTOPICRESP message.
error_t mqttSnParseGwInfo(const MqttSnMessage *message, uint8_t *gwId, const uint8_t **gwAdd, size_t *gwAddLen)
Parse GWINFO message.
error_t mqttSnParseDisconnect(const MqttSnMessage *message, uint16_t *duration)
Parse DISCONNECT message.
error_t mqttSnParseSubAck(const MqttSnMessage *message, MqttSnFlags *flags, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
Parse SUBACK message.
uint8_t length
Definition: dtls_misc.h:140
error_t mqttSnFormatSubscribe(MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName)
Format SUBSCRIBE message.
error_t mqttSnParsePingResp(const MqttSnMessage *message)
Parse PINGRESP message.
error_t mqttSnParsePubRec(const MqttSnMessage *message, uint16_t *msgId)
Parse PUBREC message.
error_t mqttSnFormatPubComp(MqttSnMessage *message, uint16_t msgId)
Format PUBCOMP message.
uint8_t gwAdd[]
error_t mqttSnFormatPublish(MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName, const uint8_t *data, size_t dataLen)
Format PUBLISH message.
error_t mqttSnFormatDisconnect(MqttSnMessage *message, uint16_t duration)
Format DISCONNECT message.
error_t mqttSnFormatConnect(MqttSnMessage *message, MqttSnFlags flags, uint16_t duration, const char_t *clientId)
Format CONNECT message.