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  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 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.8
29  **/
30 
31 #ifndef _MQTT_SN_MESSAGE_H
32 #define _MQTT_SN_MESSAGE_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mqtt_sn/mqtt_sn_common.h"
37 
38 //Maximum size of MQTT-SN messages
39 #ifndef MQTT_SN_MAX_MSG_SIZE
40  #define MQTT_SN_MAX_MSG_SIZE 1024
41 #elif (MQTT_SN_MAX_MSG_SIZE < 16)
42  #error MQTT_SN_MAX_MSG_SIZE parameter is not valid
43 #endif
44 
45 //C++ guard
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 
51 /**
52  * @brief MQTT-SN message
53  **/
54 
55 typedef struct
56 {
57  uint8_t buffer[MQTT_SN_MAX_MSG_SIZE + 1];
58  size_t length;
59  size_t pos;
61 
62 
63 //MQTT-SN related functions
65  size_t length);
66 
68  uint8_t radius);
69 
71  uint16_t duration, const char_t *clientId);
72 
74  const char_t *topicName);
75 
77  size_t dataLen);
78 
80  uint16_t msgId, uint16_t topicId, const char_t *topicName);
81 
84 
86  uint16_t msgId, uint16_t topicId, const char_t *topicName,
87  const uint8_t *data, size_t dataLen);
88 
91 
95 
97  uint16_t msgId, uint16_t topicId, const char_t *topicName);
98 
100  uint16_t msgId, uint16_t topicId, const char_t *topicName);
101 
104 
106  uint16_t duration);
107 
109  const char_t *topicName);
110 
112  size_t dataLen);
113 
115 
117  const uint8_t **gwAdd, size_t *gwAddLen);
118 
121 
124 
126  uint16_t *topicId, const char_t **topicName);
127 
129  uint16_t *topicId, MqttSnReturnCode *returnCode);
130 
132  uint16_t *msgId, uint16_t *topicId, const uint8_t **data, size_t *dataLen);
133 
135  uint16_t *topicId, MqttSnReturnCode *returnCode);
136 
140 
142  uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode);
143 
145 
147  const char_t **clientId);
148 
150 
152  uint16_t *duration);
153 
156 
159 
160 //C++ guard
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif
error_t mqttSnParsePingReq(const MqttSnMessage *message, const char_t **clientId)
Parse PINGREQ message.
uint8_t length
Definition: coap_common.h:190
error_t mqttSnParseWillTopicResp(const MqttSnMessage *message, MqttSnReturnCode *returnCode)
Parse WILLTOPICRESP message.
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 mqttSnFormatWillTopicUpd(MqttSnMessage *message, MqttSnFlags flags, const char_t *topicName)
Format WILLTOPICUPD message.
error_t mqttSnFormatWillMsg(MqttSnMessage *message, const void *data, size_t dataLen)
Format WILLMSG message.
uint8_t data[]
Definition: ethernet.h:209
error_t mqttSnFormatPingReq(MqttSnMessage *message, const char_t *clientId)
Format PINGREQ message.
MqttSnReturnCode
MQTT-SN return codes.
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 mqttSnFormatPingResp(MqttSnMessage *message)
Format PINGRESP message.
error_t mqttSnFormatUnsubscribe(MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName)
Format UNSUBSCRIBE message.
uint16_t msgId
#define MQTT_SN_MAX_MSG_SIZE
__start_packed struct @130 MqttSnFlags
MQTT-SN flags.
uint16_t topicId
error_t mqttSnFormatSearchGw(MqttSnMessage *message, uint8_t radius)
Format SEARCHGW message.
uint8_t returnCode
uint8_t gwAdd[]
error_t mqttSnFormatWillTopic(MqttSnMessage *message, MqttSnFlags flags, const char_t *topicName)
Format WILLTOPIC message.
error_t mqttSnParseUnsubAck(const MqttSnMessage *message, uint16_t *msgId)
Parse UNSUBACK message.
error_t mqttSnFormatConnect(MqttSnMessage *message, MqttSnFlags flags, uint16_t duration, const char_t *clientId)
Format CONNECT message.
char_t type
error_t
Error codes.
Definition: error.h:42
error_t mqttSnParseRegAck(const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
Parse REGACK message.
error_t mqttSnFormatPubComp(MqttSnMessage *message, uint16_t msgId)
Format PUBCOMP message.
uint8_t radius
error_t mqttSnParseRegister(const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, const char_t **topicName)
Parse REGISTER message.
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 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 mqttSnParsePubRel(const MqttSnMessage *message, uint16_t *msgId)
Parse PUBREL message.
error_t mqttSnFormatPubRec(MqttSnMessage *message, uint16_t msgId)
Format PUBREC message.
char_t topicName[]
error_t mqttSnParseHeader(MqttSnMessage *message, MqttSnMsgType *type)
Format MQTT-SN message header.
error_t mqttSnParseConnAck(const MqttSnMessage *message, MqttSnReturnCode *returnCode)
Parse CONNACK message.
error_t mqttSnParsePingResp(const MqttSnMessage *message)
Parse PINGRESP message.
Definitions common to MQTT-SN client and gateway.
error_t mqttSnParseSubAck(const MqttSnMessage *message, MqttSnFlags *flags, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
Parse SUBACK message.
uint8_t gwId
uint16_t duration
uint8_t flags
Definition: tcp.h:314
char char_t
Definition: compiler_port.h:43
error_t mqttSnParseWillTopicReq(const MqttSnMessage *message)
Parse WILLTOPICREQ message.
MqttSnMsgType
MQTT-SN message types.
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 mqttSnParsePubRec(const MqttSnMessage *message, uint16_t *msgId)
Parse PUBREC message.
MQTT-SN message.
uint8_t message[]
Definition: chap.h:152
error_t mqttSnFormatPubRel(MqttSnMessage *message, uint16_t msgId)
Format PUBREL message.
char_t clientId[]
error_t mqttSnFormatRegAck(MqttSnMessage *message, uint16_t msgId, uint16_t topicId, MqttSnReturnCode returnCode)
Format REGACK message.
TCP/IP stack core.
error_t mqttSnFormatRegister(MqttSnMessage *message, uint16_t msgId, uint16_t topicId, const char_t *topicName)
Format REGISTER message.
error_t mqttSnFormatWillMsgUpd(MqttSnMessage *message, const void *data, size_t dataLen)
Format WILLMSGUPD message.
error_t mqttSnParsePubAck(const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
Parse PUBACK message.
error_t mqttSnParseWillMsgReq(const MqttSnMessage *message)
Parse WILLMSGREQ message.
error_t mqttSnFormatSubscribe(MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName)
Format SUBSCRIBE message.