mqtt_sn_message.h File Reference

MQTT-SN message formatting and parsing. More...

#include "core/net.h"
#include "mqtt_sn/mqtt_sn_common.h"

Go to the source code of this file.

Data Structures

struct  MqttSnMessage
 MQTT-SN message. More...
 

Macros

#define MQTT_SN_MAX_MSG_SIZE   1024
 

Functions

error_t mqttSnFormatHeader (MqttSnMessage *message, MqttSnMsgType type, size_t length)
 Format MQTT-SN message header. More...
 
error_t mqttSnFormatSearchGw (MqttSnMessage *message, uint8_t radius)
 Format SEARCHGW message. More...
 
error_t mqttSnFormatConnect (MqttSnMessage *message, MqttSnFlags flags, uint16_t duration, const char_t *clientId)
 Format CONNECT message. More...
 
error_t mqttSnFormatWillTopic (MqttSnMessage *message, MqttSnFlags flags, const char_t *topicName)
 Format WILLTOPIC message. More...
 
error_t mqttSnFormatWillMsg (MqttSnMessage *message, const void *data, size_t dataLen)
 Format WILLMSG message. More...
 
error_t mqttSnFormatRegister (MqttSnMessage *message, uint16_t msgId, uint16_t topicId, const char_t *topicName)
 Format REGISTER message. More...
 
error_t mqttSnFormatRegAck (MqttSnMessage *message, uint16_t msgId, uint16_t topicId, MqttSnReturnCode returnCode)
 Format REGACK message. More...
 
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. More...
 
error_t mqttSnFormatPubAck (MqttSnMessage *message, uint16_t msgId, uint16_t topicId, MqttSnReturnCode returnCode)
 Format PUBACK message. More...
 
error_t mqttSnFormatPubRec (MqttSnMessage *message, uint16_t msgId)
 Format PUBREC message. More...
 
error_t mqttSnFormatPubRel (MqttSnMessage *message, uint16_t msgId)
 Format PUBREL message. More...
 
error_t mqttSnFormatPubComp (MqttSnMessage *message, uint16_t msgId)
 Format PUBCOMP message. More...
 
error_t mqttSnFormatSubscribe (MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName)
 Format SUBSCRIBE message. More...
 
error_t mqttSnFormatUnsubscribe (MqttSnMessage *message, MqttSnFlags flags, uint16_t msgId, uint16_t topicId, const char_t *topicName)
 Format UNSUBSCRIBE message. More...
 
error_t mqttSnFormatPingReq (MqttSnMessage *message, const char_t *clientId)
 Format PINGREQ message. More...
 
error_t mqttSnFormatPingResp (MqttSnMessage *message)
 Format PINGRESP message. More...
 
error_t mqttSnFormatDisconnect (MqttSnMessage *message, uint16_t duration)
 Format DISCONNECT message. More...
 
error_t mqttSnFormatWillTopicUpd (MqttSnMessage *message, MqttSnFlags flags, const char_t *topicName)
 Format WILLTOPICUPD message. More...
 
error_t mqttSnFormatWillMsgUpd (MqttSnMessage *message, const void *data, size_t dataLen)
 Format WILLMSGUPD message. More...
 
error_t mqttSnParseHeader (MqttSnMessage *message, MqttSnMsgType *type)
 Format MQTT-SN message header. More...
 
error_t mqttSnParseGwInfo (const MqttSnMessage *message, uint8_t *gwId, const uint8_t **gwAdd, size_t *gwAddLen)
 Parse GWINFO message. More...
 
error_t mqttSnParseConnAck (const MqttSnMessage *message, MqttSnReturnCode *returnCode)
 Parse CONNACK message. More...
 
error_t mqttSnParseWillTopicReq (const MqttSnMessage *message)
 Parse WILLTOPICREQ message. More...
 
error_t mqttSnParseWillMsgReq (const MqttSnMessage *message)
 Parse WILLMSGREQ message. More...
 
error_t mqttSnParseRegister (const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, const char_t **topicName)
 Parse REGISTER message. More...
 
error_t mqttSnParseRegAck (const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
 Parse REGACK message. More...
 
error_t mqttSnParsePublish (const MqttSnMessage *message, MqttSnFlags *flags, uint16_t *msgId, uint16_t *topicId, const uint8_t **data, size_t *dataLen)
 Parse PUBLISH message. More...
 
error_t mqttSnParsePubAck (const MqttSnMessage *message, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
 Parse PUBACK message. More...
 
error_t mqttSnParsePubRec (const MqttSnMessage *message, uint16_t *msgId)
 Parse PUBREC message. More...
 
error_t mqttSnParsePubRel (const MqttSnMessage *message, uint16_t *msgId)
 Parse PUBREL message. More...
 
error_t mqttSnParsePubComp (const MqttSnMessage *message, uint16_t *msgId)
 Parse PUBCOMP message. More...
 
error_t mqttSnParseSubAck (const MqttSnMessage *message, MqttSnFlags *flags, uint16_t *msgId, uint16_t *topicId, MqttSnReturnCode *returnCode)
 Parse SUBACK message. More...
 
error_t mqttSnParseUnsubAck (const MqttSnMessage *message, uint16_t *msgId)
 Parse UNSUBACK message. More...
 
error_t mqttSnParsePingReq (const MqttSnMessage *message, const char_t **clientId)
 Parse PINGREQ message. More...
 
error_t mqttSnParsePingResp (const MqttSnMessage *message)
 Parse PINGRESP message. More...
 
error_t mqttSnParseDisconnect (const MqttSnMessage *message, uint16_t *duration)
 Parse DISCONNECT message. More...
 
error_t mqttSnParseWillTopicResp (const MqttSnMessage *message, MqttSnReturnCode *returnCode)
 Parse WILLTOPICRESP message. More...
 
error_t mqttSnParseWillMsgResp (const MqttSnMessage *message, MqttSnReturnCode *returnCode)
 Parse WILLMSGRESP message. More...
 

Detailed Description

MQTT-SN message formatting and parsing.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file mqtt_sn_message.h.

Macro Definition Documentation

◆ MQTT_SN_MAX_MSG_SIZE

#define MQTT_SN_MAX_MSG_SIZE   1024

Definition at line 40 of file mqtt_sn_message.h.

Function Documentation

◆ mqttSnFormatConnect()

error_t mqttSnFormatConnect ( MqttSnMessage message,
MqttSnFlags  flags,
uint16_t  duration,
const char_t clientId 
)

Format CONNECT message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]flagsFlags
[in]durationValue of the keep-alive timer
[in]clientIdClient identifier
Returns
Error code

Definition at line 145 of file mqtt_sn_message.c.

◆ mqttSnFormatDisconnect()

error_t mqttSnFormatDisconnect ( MqttSnMessage message,
uint16_t  duration 
)

Format DISCONNECT message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]durationValue of the sleep timer
Returns
Error code

Definition at line 705 of file mqtt_sn_message.c.

◆ mqttSnFormatHeader()

error_t mqttSnFormatHeader ( MqttSnMessage message,
MqttSnMsgType  type,
size_t  length 
)

Format MQTT-SN message header.

Parameters
[in]messagePointer to the MQTT-SN message
[in]typeMessage type
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 52 of file mqtt_sn_message.c.

◆ mqttSnFormatPingReq()

error_t mqttSnFormatPingReq ( MqttSnMessage message,
const char_t clientId 
)

Format PINGREQ message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]clientIdClient identifier
Returns
Error code

Definition at line 661 of file mqtt_sn_message.c.

◆ mqttSnFormatPingResp()

error_t mqttSnFormatPingResp ( MqttSnMessage message)

Format PINGRESP message.

Parameters
[in]messagePointer to the MQTT-SN message
Returns
Error code

Definition at line 686 of file mqtt_sn_message.c.

◆ mqttSnFormatPubAck()

error_t mqttSnFormatPubAck ( MqttSnMessage message,
uint16_t  msgId,
uint16_t  topicId,
MqttSnReturnCode  returnCode 
)

Format PUBACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]msgIdMessage identifier of the corresponding PUBLISH message
[in]topicIdTopic identifier
[in]returnCodeReturn code
Returns
Error code

Definition at line 384 of file mqtt_sn_message.c.

◆ mqttSnFormatPubComp()

error_t mqttSnFormatPubComp ( MqttSnMessage message,
uint16_t  msgId 
)

Format PUBCOMP message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]msgIdMessage identifier of the corresponding PUBLISH message
Returns
Error code

Definition at line 465 of file mqtt_sn_message.c.

◆ mqttSnFormatPublish()

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.

Parameters
[in]messagePointer to the MQTT-SN message
[in]flagsFlags
[in]msgIdMessage identifier
[in]topicIdTopic identifier
[in]topicNameShort topic name
[in]dataMessage payload
[in]dataLenLength of the message payload
Returns
Error code

Definition at line 310 of file mqtt_sn_message.c.

◆ mqttSnFormatPubRec()

error_t mqttSnFormatPubRec ( MqttSnMessage message,
uint16_t  msgId 
)

Format PUBREC message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]msgIdMessage identifier of the corresponding PUBLISH message
Returns
Error code

Definition at line 413 of file mqtt_sn_message.c.

◆ mqttSnFormatPubRel()

error_t mqttSnFormatPubRel ( MqttSnMessage message,
uint16_t  msgId 
)

Format PUBREL message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]msgIdMessage identifier of the corresponding PUBLISH message
Returns
Error code

Definition at line 439 of file mqtt_sn_message.c.

◆ mqttSnFormatRegAck()

error_t mqttSnFormatRegAck ( MqttSnMessage message,
uint16_t  msgId,
uint16_t  topicId,
MqttSnReturnCode  returnCode 
)

Format REGACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]msgIdMessage identifier
[in]topicIdTopic identifier
[in]returnCodeReturn code
Returns
Error code

Definition at line 276 of file mqtt_sn_message.c.

◆ mqttSnFormatRegister()

error_t mqttSnFormatRegister ( MqttSnMessage message,
uint16_t  msgId,
uint16_t  topicId,
const char_t topicName 
)

Format REGISTER message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]msgIdMessage identifier
[in]topicIdTopic identifier
[in]topicNameTopic name
Returns
Error code

Definition at line 243 of file mqtt_sn_message.c.

◆ mqttSnFormatSearchGw()

error_t mqttSnFormatSearchGw ( MqttSnMessage message,
uint8_t  radius 
)

Format SEARCHGW message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]radiusBroadcast radius of SEARCHGW message
Returns
Error code

Definition at line 116 of file mqtt_sn_message.c.

◆ mqttSnFormatSubscribe()

error_t mqttSnFormatSubscribe ( MqttSnMessage message,
MqttSnFlags  flags,
uint16_t  msgId,
uint16_t  topicId,
const char_t topicName 
)

Format SUBSCRIBE message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]flagsFlags
[in]msgIdMessage identifier
[in]topicIdTopic identifier
[in]topicNameTopic name
Returns
Error code

Definition at line 494 of file mqtt_sn_message.c.

◆ mqttSnFormatUnsubscribe()

error_t mqttSnFormatUnsubscribe ( MqttSnMessage message,
MqttSnFlags  flags,
uint16_t  msgId,
uint16_t  topicId,
const char_t topicName 
)

Format UNSUBSCRIBE message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]flagsFlags
[in]msgIdMessage identifier
[in]topicIdTopic identifier
[in]topicNameTopic name
Returns
Error code

Definition at line 579 of file mqtt_sn_message.c.

◆ mqttSnFormatWillMsg()

error_t mqttSnFormatWillMsg ( MqttSnMessage message,
const void *  data,
size_t  dataLen 
)

Format WILLMSG message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]dataWill message
[in]dataLenLength of the Will message
Returns
Error code

Definition at line 218 of file mqtt_sn_message.c.

◆ mqttSnFormatWillMsgUpd()

error_t mqttSnFormatWillMsgUpd ( MqttSnMessage message,
const void *  data,
size_t  dataLen 
)

Format WILLMSGUPD message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]dataWill message
[in]dataLenLength of the Will message
Returns
Error code

Definition at line 784 of file mqtt_sn_message.c.

◆ mqttSnFormatWillTopic()

error_t mqttSnFormatWillTopic ( MqttSnMessage message,
MqttSnFlags  flags,
const char_t topicName 
)

Format WILLTOPIC message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]flagsFlags
[in]topicNameTopic name
Returns
Error code

Definition at line 178 of file mqtt_sn_message.c.

◆ mqttSnFormatWillTopicUpd()

error_t mqttSnFormatWillTopicUpd ( MqttSnMessage message,
MqttSnFlags  flags,
const char_t topicName 
)

Format WILLTOPICUPD message.

Parameters
[in]messagePointer to the MQTT-SN message
[in]flagsFlags
[in]topicNameTopic name
Returns
Error code

Definition at line 744 of file mqtt_sn_message.c.

◆ mqttSnParseConnAck()

error_t mqttSnParseConnAck ( const MqttSnMessage message,
MqttSnReturnCode returnCode 
)

Parse CONNACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]returnCodeReturn code
Returns
Error code

Definition at line 906 of file mqtt_sn_message.c.

◆ mqttSnParseDisconnect()

error_t mqttSnParseDisconnect ( const MqttSnMessage message,
uint16_t *  duration 
)

Parse DISCONNECT message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]durationValue of the sleep timer
Returns
Error code

Definition at line 1304 of file mqtt_sn_message.c.

◆ mqttSnParseGwInfo()

error_t mqttSnParseGwInfo ( const MqttSnMessage message,
uint8_t *  gwId,
const uint8_t **  gwAdd,
size_t *  gwAddLen 
)

Parse GWINFO message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]gwIdGateway identifier
[out]gwAddGateway address
[out]gwAddLenLength of the gateway address
Returns
Error code

Definition at line 871 of file mqtt_sn_message.c.

◆ mqttSnParseHeader()

error_t mqttSnParseHeader ( MqttSnMessage message,
MqttSnMsgType type 
)

Format MQTT-SN message header.

Parameters
[in]messagePointer to the MQTT-SN message
[out]typeMessage type
Returns
Error code

Definition at line 807 of file mqtt_sn_message.c.

◆ mqttSnParsePingReq()

error_t mqttSnParsePingReq ( const MqttSnMessage message,
const char_t **  clientId 
)

Parse PINGREQ message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]clientIdClient identifier
Returns
Error code

Definition at line 1268 of file mqtt_sn_message.c.

◆ mqttSnParsePingResp()

error_t mqttSnParsePingResp ( const MqttSnMessage message)

Parse PINGRESP message.

Parameters
[in]messagePointer to the MQTT-SN message
Returns
Error code

Definition at line 1290 of file mqtt_sn_message.c.

◆ mqttSnParsePubAck()

error_t mqttSnParsePubAck ( const MqttSnMessage message,
uint16_t *  msgId,
uint16_t *  topicId,
MqttSnReturnCode returnCode 
)

Parse PUBACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
[out]topicIdTopic identifier
[out]returnCodeReturn code
Returns
Error code

Definition at line 1079 of file mqtt_sn_message.c.

◆ mqttSnParsePubComp()

error_t mqttSnParsePubComp ( const MqttSnMessage message,
uint16_t *  msgId 
)

Parse PUBCOMP message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
Returns
Error code

Definition at line 1171 of file mqtt_sn_message.c.

◆ mqttSnParsePublish()

error_t mqttSnParsePublish ( const MqttSnMessage message,
MqttSnFlags flags,
uint16_t *  msgId,
uint16_t *  topicId,
const uint8_t **  data,
size_t *  dataLen 
)

Parse PUBLISH message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]flagsFlags
[out]msgIdMessage identifier
[out]topicIdTopic identifier
[out]dataPointer to the published data
[out]dataLenLength of the published data
Returns
Error code

Definition at line 1038 of file mqtt_sn_message.c.

◆ mqttSnParsePubRec()

error_t mqttSnParsePubRec ( const MqttSnMessage message,
uint16_t *  msgId 
)

Parse PUBREC message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
Returns
Error code

Definition at line 1113 of file mqtt_sn_message.c.

◆ mqttSnParsePubRel()

error_t mqttSnParsePubRel ( const MqttSnMessage message,
uint16_t *  msgId 
)

Parse PUBREL message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
Returns
Error code

Definition at line 1142 of file mqtt_sn_message.c.

◆ mqttSnParseRegAck()

error_t mqttSnParseRegAck ( const MqttSnMessage message,
uint16_t *  msgId,
uint16_t *  topicId,
MqttSnReturnCode returnCode 
)

Parse REGACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
[out]topicIdTopic identifier
[out]returnCodeReturn code
Returns
Error code

Definition at line 1000 of file mqtt_sn_message.c.

◆ mqttSnParseRegister()

error_t mqttSnParseRegister ( const MqttSnMessage message,
uint16_t *  msgId,
uint16_t *  topicId,
const char_t **  topicName 
)

Parse REGISTER message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
[out]topicIdTopic identifier
[out]topicNameTopic name
Returns
Error code

Definition at line 964 of file mqtt_sn_message.c.

◆ mqttSnParseSubAck()

error_t mqttSnParseSubAck ( const MqttSnMessage message,
MqttSnFlags flags,
uint16_t *  msgId,
uint16_t *  topicId,
MqttSnReturnCode returnCode 
)

Parse SUBACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]flagsFlags
[out]msgIdMessage identifier
[out]topicIdTopic identifier
[out]returnCodeReturn code
Returns
Error code

Definition at line 1203 of file mqtt_sn_message.c.

◆ mqttSnParseUnsubAck()

error_t mqttSnParseUnsubAck ( const MqttSnMessage message,
uint16_t *  msgId 
)

Parse UNSUBACK message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]msgIdMessage identifier
Returns
Error code

Definition at line 1239 of file mqtt_sn_message.c.

◆ mqttSnParseWillMsgReq()

error_t mqttSnParseWillMsgReq ( const MqttSnMessage message)

Parse WILLMSGREQ message.

Parameters
[in]messagePointer to the MQTT-SN message
Returns
Error code

Definition at line 948 of file mqtt_sn_message.c.

◆ mqttSnParseWillMsgResp()

error_t mqttSnParseWillMsgResp ( const MqttSnMessage message,
MqttSnReturnCode returnCode 
)

Parse WILLMSGRESP message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]returnCodeReturn code
Returns
Error code

Definition at line 1373 of file mqtt_sn_message.c.

◆ mqttSnParseWillTopicReq()

error_t mqttSnParseWillTopicReq ( const MqttSnMessage message)

Parse WILLTOPICREQ message.

Parameters
[in]messagePointer to the MQTT-SN message
Returns
Error code

Definition at line 935 of file mqtt_sn_message.c.

◆ mqttSnParseWillTopicResp()

error_t mqttSnParseWillTopicResp ( const MqttSnMessage message,
MqttSnReturnCode returnCode 
)

Parse WILLTOPICRESP message.

Parameters
[in]messagePointer to the MQTT-SN message
[out]returnCodeReturn code
Returns
Error code

Definition at line 1343 of file mqtt_sn_message.c.