AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
aws_iot_mqtt_client_common_internal.c File Reference

MQTT client internal API definitions. More...

Macros

#define MAX_NO_OF_REMAINING_LENGTH_BYTES   4
 

Functions

size_t aws_iot_mqtt_internal_write_len_to_buffer (unsigned char *buf, uint32_t length)
 Encodes the message length according to the MQTT algorithm. More...
 
IoT_Error_t aws_iot_mqtt_internal_decode_remaining_length_from_buffer (unsigned char *buf, uint32_t *decodedLen, uint32_t *readBytesLen)
 Decodes the message length according to the MQTT algorithm. More...
 
uint32_t aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length (uint32_t rem_len)
 Calculates the length of the "remaining length" encoding. More...
 
uint16_t aws_iot_mqtt_internal_read_uint16_t (unsigned char **pptr)
 Calculates uint16 packet id from two bytes read from the input buffer. More...
 
void aws_iot_mqtt_internal_write_uint_16 (unsigned char **pptr, uint16_t anInt)
 Writes an integer as 2 bytes to an output buffer. More...
 
unsigned char aws_iot_mqtt_internal_read_char (unsigned char **pptr)
 Reads one character from the input buffer. More...
 
void aws_iot_mqtt_internal_write_char (unsigned char **pptr, unsigned char c)
 Writes one character to an output buffer. More...
 
void aws_iot_mqtt_internal_write_utf8_string (unsigned char **pptr, const char *string, uint16_t stringLen)
 Writes a UTF-8 string into an MQTT packet. More...
 
IoT_Error_t aws_iot_mqtt_internal_init_header (MQTTHeader *pHeader, MessageTypes message_type, QoS qos, uint8_t dup, uint8_t retained)
 Initialize the MQTTHeader structure. More...
 
IoT_Error_t aws_iot_mqtt_internal_send_packet (AWS_IoT_Client *pClient, size_t length, Timer *pTimer)
 Send an MQTT packet on the network. More...
 
IoT_Error_t aws_iot_mqtt_internal_cycle_read (AWS_IoT_Client *pClient, Timer *pTimer, uint8_t *pPacketType)
 Read an MQTT packet from the network. More...
 
IoT_Error_t aws_iot_mqtt_internal_flushBuffers (AWS_IoT_Client *pClient)
 Flush incoming data from the MQTT client. More...
 
IoT_Error_t aws_iot_mqtt_internal_wait_for_read (AWS_IoT_Client *pClient, uint8_t packetType, Timer *pTimer)
 Wait until a packet is read from the network. More...
 
IoT_Error_t aws_iot_mqtt_internal_serialize_zero (unsigned char *pTxBuf, size_t txBufLen, MessageTypes packetType, size_t *pSerializedLength)
 

Detailed Description

MQTT client internal API definitions.

Macro Definition Documentation

◆ MAX_NO_OF_REMAINING_LENGTH_BYTES

#define MAX_NO_OF_REMAINING_LENGTH_BYTES   4

Max length of packet header

Function Documentation

◆ aws_iot_mqtt_internal_write_len_to_buffer()

size_t aws_iot_mqtt_internal_write_len_to_buffer ( unsigned char *  buf,
uint32_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

◆ aws_iot_mqtt_internal_decode_remaining_length_from_buffer()

IoT_Error_t aws_iot_mqtt_internal_decode_remaining_length_from_buffer ( unsigned char *  buf,
uint32_t *  decodedLen,
uint32_t *  readBytesLen 
)

Decodes the message length according to the MQTT algorithm.

Parameters
bufthe buffer containing the message
decodedLenvalue the decoded length returned
readBytesLenoutput parameter for the number of bytes read from the socket
Returns
IoT_Error_t indicating decode status

◆ aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length()

uint32_t aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length ( uint32_t  rem_len)

Calculates the length of the "remaining length" encoding.

Parameters
rem_len"remaining length" to encode
Returns
length of the remaining length encoding

◆ aws_iot_mqtt_internal_read_uint16_t()

uint16_t aws_iot_mqtt_internal_read_uint16_t ( unsigned char **  pptr)

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

Checks Endianness at runtime

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

◆ aws_iot_mqtt_internal_write_uint_16()

void aws_iot_mqtt_internal_write_uint_16 ( 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

◆ aws_iot_mqtt_internal_read_char()

unsigned char aws_iot_mqtt_internal_read_char ( 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

◆ aws_iot_mqtt_internal_write_char()

void aws_iot_mqtt_internal_write_char ( 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

◆ aws_iot_mqtt_internal_write_utf8_string()

void aws_iot_mqtt_internal_write_utf8_string ( unsigned char **  pptr,
const char *  string,
uint16_t  stringLen 
)

Writes a UTF-8 string into an MQTT packet.

Parameters
pptrWhere the string should be written
stringThe string to write
stringLenLength to write

◆ aws_iot_mqtt_internal_init_header()

IoT_Error_t aws_iot_mqtt_internal_init_header ( MQTTHeader pHeader,
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.

Parameters
pHeaderHeader to initialize
message_typeMQTT packet type
qosQuality of service for packet
dupDUP flag of a publish
retainedRETAIN flag of a publish
Returns
Returns SUCCESS unless an invalid packet type is given.

◆ aws_iot_mqtt_internal_send_packet()

IoT_Error_t aws_iot_mqtt_internal_send_packet ( AWS_IoT_Client *  pClient,
size_t  length,
Timer *  pTimer 
)

Send an MQTT packet on the network.

Parameters
pClientMQTT client which holds packet
lengthLength of packet to send
pTimerAmount of time allowed to send packet
Returns
IoT_Error_t of send status

◆ aws_iot_mqtt_internal_cycle_read()

IoT_Error_t aws_iot_mqtt_internal_cycle_read ( AWS_IoT_Client *  pClient,
Timer *  pTimer,
uint8_t *  pPacketType 
)

Read an MQTT packet from the network.

Parameters
pClientMQTT client
pTimerAmount of time allowed to read packet
pPacketTypeOutput parameter for packet read from network
Returns
IoT_Error_t of read status

◆ aws_iot_mqtt_internal_flushBuffers()

IoT_Error_t aws_iot_mqtt_internal_flushBuffers ( AWS_IoT_Client *  pClient)

Flush incoming data from the MQTT client.

Parameters
pClientClient with data to flush
Returns
Always returns SUCCESS

◆ aws_iot_mqtt_internal_wait_for_read()

IoT_Error_t aws_iot_mqtt_internal_wait_for_read ( AWS_IoT_Client *  pClient,
uint8_t  packetType,
Timer *  pTimer 
)

Wait until a packet is read from the network.

Only used in single-threaded mode where one command at a time is in process

Parameters
pClientMQTT client
packetTypeMQTT packet to read
pTimerAmount of time allowed to read packet
Returns
IoT_Error_t of read status

◆ aws_iot_mqtt_internal_serialize_zero()

IoT_Error_t aws_iot_mqtt_internal_serialize_zero ( unsigned char *  pTxBuf,
size_t  txBufLen,
MessageTypes  packetType,
size_t *  pSerializedLength 
)

Serializes a 0-length packet into the supplied buffer, ready for writing to a socket

Parameters
pTxBufthe buffer into which the packet will be serialized
txBufLenthe length in bytes of the supplied buffer, to avoid overruns
packetTypethe message type
pSerializedLengthlength
Returns
IoT_Error_t indicating function execution status