mqtt_sn_message.c File Reference

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

#include "core/net.h"
#include "mqtt_sn/mqtt_sn_client.h"
#include "mqtt_sn/mqtt_sn_message.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   MQTT_SN_TRACE_LEVEL
 

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

Copyright (C) 2010-2018 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
1.9.0

Definition in file mqtt_sn_message.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   MQTT_SN_TRACE_LEVEL

Definition at line 30 of file mqtt_sn_message.c.

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 143 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 703 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 50 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 659 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 684 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 382 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 463 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 308 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 411 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 437 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 274 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 241 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 114 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 492 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 577 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 216 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 782 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 176 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 742 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 904 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 1302 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 869 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 805 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 1266 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 1288 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 1077 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 1169 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 1036 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 1111 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 1140 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 998 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 962 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 1201 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 1237 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 946 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 1371 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 933 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 1341 of file mqtt_sn_message.c.