Microchip® Advanced Software Framework

AWS_SDK/AWS_SDK/aws_mqtt_embedded_client_lib/MQTTPacket/src/MQTTPacket.c File Reference
#include "StackTrace.h"
#include "MQTTPacket.h"
#include <string.h>

Macros

#define MAX_NO_OF_REMAINING_LENGTH_BYTES   4
 

Functions

uint32_t bufchar (unsigned char *c, uint32_t count)
 
MQTTReturnCode MQTTPacket_decode (uint32_t(*getcharfn)(unsigned char *, uint32_t), uint32_t *value, uint32_t *readBytesLen)
 Decodes the message length according to the MQTT algorithm. More...
 
MQTTReturnCode MQTTPacket_decodeBuf (unsigned char *buf, uint32_t *value, uint32_t *readBytesLen)
 
uint32_t MQTTPacket_encode (unsigned char *buf, size_t length)
 Encodes the message length according to the MQTT algorithm. More...
 
uint8_t MQTTPacket_equals (MQTTString *a, char *bptr)
 Compares an MQTTString to a C string. More...
 
MQTTReturnCode MQTTPacket_InitHeader (MQTTHeader *header, MessageTypes message_type, QoS qos, uint8_t dup, uint8_t retained)
 Initialize the MQTTHeader structure. More...
 
size_t MQTTPacket_len (size_t rem_len)
 
size_t MQTTstrlen (MQTTString mqttstring)
 Return the length of the MQTTstring - C string if there is one, otherwise the length delimited string. More...
 
unsigned char readChar (unsigned char **pptr)
 Reads one character from the input buffer. More...
 
int32_t readInt (unsigned char **pptr)
 Calculates an integer from two bytes read from the input buffer. More...
 
MQTTReturnCode readMQTTLenString (MQTTString *mqttstring, unsigned char **pptr, unsigned char *enddata)
 
uint16_t readPacketId (unsigned char **pptr)
 Calculates uint16 packet id from two bytes read from the input buffer. More...
 
size_t readSizeT (unsigned char **pptr)
 Calculates an integer from two bytes read from the input buffer. More...
 
void writeChar (unsigned char **pptr, unsigned char c)
 Writes one character to an output buffer. More...
 
void writeCString (unsigned char **pptr, const char *string)
 Writes a "UTF" string to an output buffer. More...
 
void writeInt (unsigned char **pptr, int32_t anInt)
 Writes an integer as 2 bytes to an output buffer. More...
 
void writeMQTTString (unsigned char **pptr, MQTTString mqttstring)
 
void writePacketId (unsigned char **pptr, uint16_t anInt)
 Writes an integer as 2 bytes to an output buffer. More...
 
void writeSizeT (unsigned char **pptr, size_t size)
 Writes size as 2 bytes to an output buffer. More...
 

Variables

static unsigned char * bufptr
 

#define MAX_NO_OF_REMAINING_LENGTH_BYTES   4

Referenced by MQTTPacket_decode().

uint32_t bufchar ( unsigned char *  c,
uint32_t  count 
)

References count, and i.

MQTTReturnCode MQTTPacket_decode ( uint32_t(*)(unsigned char *, uint32_t)  getcharfn,
uint32_t *  value,
uint32_t *  readBytesLen 
)

Decodes the message length according to the MQTT algorithm.

Parameters
getcharfnpointer to function to read the next character from the data source
valuethe decoded length returned
Returns
the number of bytes read from the socket

References c, FAILURE, FUNC_ENTRY, FUNC_EXIT_RC, len, MAX_NO_OF_REMAINING_LENGTH_BYTES, MQTTPACKET_READ_ERROR, and SUCCESS.

MQTTReturnCode MQTTPacket_decodeBuf ( unsigned char *  buf,
uint32_t *  value,
uint32_t *  readBytesLen 
)

References buf, bufchar(), and MQTTPacket_decode().

uint32_t MQTTPacket_encode ( unsigned char *  buf,
size_t  length 
)

Encodes the message length according to the MQTT algorithm.

Parameters
bufthe buffer into which the encoded data is written
lengththe length to be encoded
Returns
the number of bytes written to buffer

References FUNC_ENTRY, and FUNC_EXIT_RC.

uint8_t MQTTPacket_equals ( MQTTString a,
char *  bptr 
)

Compares an MQTTString to a C string.

Parameters
athe MQTTString to compare
bptrthe C string to compare
Returns
boolean - equal or not

References MQTTString::cstring, MQTTLenString::data, MQTTLenString::len, and MQTTString::lenstring.

MQTTReturnCode MQTTPacket_InitHeader ( MQTTHeader header,
MessageTypes  message_type,
QoS  qos,
uint8_t  dup,
uint8_t  retained 
)

Initialize the MQTTHeader structure.

Used to ensure that Header bits are always initialized using the proper mappings. No Endianness issues here since the individual fields are all less than a byte. Also generates no warnings since all fields are initialized using hex constants

References MQTTHeader::bits, MQTTHeader::byte, CONNACK, CONNECT, DISCONNECT, MQTTHeader::dup, MQTT_NULL_VALUE_ERROR, MQTT_UNKNOWN_ERROR, NULL, PINGREQ, PINGRESP, PUBACK, PUBCOMP, PUBLISH, PUBREC, PUBREL, MQTTHeader::qos, QOS0, QOS1, QOS2, MQTTHeader::retain, SUBACK, SUBSCRIBE, SUCCESS, MQTTHeader::type, UNKNOWN, UNSUBACK, and UNSUBSCRIBE.

Referenced by MQTTSerialize_ack(), MQTTSerialize_connect(), MQTTSerialize_publish(), MQTTSerialize_subscribe(), MQTTSerialize_unsubscribe(), and MQTTSerialize_zero().

size_t MQTTPacket_len ( size_t  rem_len)
size_t MQTTstrlen ( MQTTString  mqttstring)

Return the length of the MQTTstring - C string if there is one, otherwise the length delimited string.

Parameters
mqttstringthe string to return the length of
Returns
the length of the string

References MQTTString::cstring, MQTTLenString::len, len, and MQTTString::lenstring.

unsigned char readChar ( unsigned char **  pptr)

Reads one character from the input buffer.

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the character read

References c.

int32_t readInt ( unsigned char **  pptr)

Calculates an integer from two bytes read from the input buffer.

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the integer value calculated

References len, and ptr.

MQTTReturnCode readMQTTLenString ( MQTTString mqttstring,
unsigned char **  pptr,
unsigned char *  enddata 
)
Parameters
mqttstringthe MQTTString structure into which the data is to be read
pptrpointer to the output buffer - incremented by the number of bytes used & returned
enddatapointer to the end of the data: do not read beyond
Returns
SUCCESS if successful, FAILURE if not

References MQTTString::cstring, MQTTLenString::data, FAILURE, FUNC_ENTRY, FUNC_EXIT_RC, MQTTLenString::len, MQTTString::lenstring, NULL, readInt(), readSizeT(), and SUCCESS.

uint16_t readPacketId ( unsigned char **  pptr)

Calculates uint16 packet id from two bytes read from the input buffer.

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the value calculated

References len, and ptr.

Referenced by MQTTDeserialize_ack(), MQTTDeserialize_publish(), and MQTTDeserialize_suback().

size_t readSizeT ( unsigned char **  pptr)

Calculates an integer from two bytes read from the input buffer.

Parameters
pptrpointer to the input buffer - incremented by the number of bytes used & returned
Returns
the integer value calculated

References ptr.

Referenced by readMQTTLenString().

void writeChar ( unsigned char **  pptr,
unsigned char  c 
)

Writes one character to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
cthe character to write

References c.

void writeCString ( unsigned char **  pptr,
const char *  string 
)

Writes a "UTF" string to an output buffer.

Converts C string to length-delimited.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
stringthe C string to write

References len, writeInt(), and writeSizeT().

void writeInt ( unsigned char **  pptr,
int32_t  anInt 
)

Writes an integer as 2 bytes to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
anIntthe integer to write
void writeMQTTString ( unsigned char **  pptr,
MQTTString  mqttstring 
)
void writePacketId ( unsigned char **  pptr,
uint16_t  anInt 
)

Writes an integer as 2 bytes to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
anIntthe integer to write

Referenced by MQTTSerialize_ack(), MQTTSerialize_subscribe(), and MQTTSerialize_unsubscribe().

void writeSizeT ( unsigned char **  pptr,
size_t  size 
)

Writes size as 2 bytes to an output buffer.

Parameters
pptrpointer to the output buffer - incremented by the number of bytes used & returned
anIntthe integer to write

Referenced by writeCString(), and writeMQTTString().

unsigned char* bufptr
static