AWS IoT Embedded C Device SDK
Data Structures | Typedefs | Enumerations | Functions
aws_iot_mqtt_client_common_internal.h File Reference

Internal MQTT functions not exposed to application. More...

#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "aws_iot_log.h"
#include "aws_iot_mqtt_client_interface.h"

Go to the source code of this file.

Data Structures

union  MQTTHeader
 

Typedefs

typedef enum msgTypes MessageTypes
 

Enumerations

enum  msgTypes {
  UNKNOWN = -1, CONNECT = 1, CONNACK = 2, PUBLISH = 3,
  PUBACK = 4, PUBREC = 5, PUBREL = 6, PUBCOMP = 7,
  SUBSCRIBE = 8, SUBACK = 9, UNSUBSCRIBE = 10, UNSUBACK = 11,
  PINGREQ = 12, PINGRESP = 13, DISCONNECT = 14
}
 

Functions

IoT_Error_t aws_iot_mqtt_internal_init_header (MQTTHeader *pHeader, MessageTypes message_type, QoS qos, uint8_t dup, uint8_t retained)
 
IoT_Error_t aws_iot_mqtt_internal_serialize_ack (unsigned char *pTxBuf, size_t txBufLen, MessageTypes msgType, uint8_t dup, uint16_t packetId, uint32_t *pSerializedLen)
 
IoT_Error_t aws_iot_mqtt_internal_deserialize_ack (unsigned char *, unsigned char *, uint16_t *, unsigned char *, size_t)
 
uint32_t aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length (uint32_t rem_len)
 
size_t aws_iot_mqtt_internal_write_len_to_buffer (unsigned char *buf, uint32_t length)
 
IoT_Error_t aws_iot_mqtt_internal_decode_remaining_length_from_buffer (unsigned char *buf, uint32_t *decodedLen, uint32_t *readBytesLen)
 
uint16_t aws_iot_mqtt_internal_read_uint16_t (unsigned char **pptr)
 
void aws_iot_mqtt_internal_write_uint_16 (unsigned char **pptr, uint16_t anInt)
 
unsigned char aws_iot_mqtt_internal_read_char (unsigned char **pptr)
 
void aws_iot_mqtt_internal_write_char (unsigned char **pptr, unsigned char c)
 
void aws_iot_mqtt_internal_write_utf8_string (unsigned char **pptr, const char *string, uint16_t stringLen)
 
IoT_Error_t aws_iot_mqtt_internal_send_packet (AWS_IoT_Client *pClient, size_t length, Timer *pTimer)
 
IoT_Error_t aws_iot_mqtt_internal_cycle_read (AWS_IoT_Client *pClient, Timer *pTimer, uint8_t *pPacketType)
 
IoT_Error_t aws_iot_mqtt_internal_wait_for_read (AWS_IoT_Client *pClient, uint8_t packetType, Timer *pTimer)
 
IoT_Error_t aws_iot_mqtt_internal_serialize_zero (unsigned char *pTxBuf, size_t txBufLen, MessageTypes packetType, size_t *pSerializedLength)
 
IoT_Error_t aws_iot_mqtt_internal_deserialize_publish (uint8_t *dup, QoS *qos, uint8_t *retained, uint16_t *pPacketId, char **pTopicName, uint16_t *topicNameLen, unsigned char **payload, size_t *payloadLen, unsigned char *pRxBuf, size_t rxBufLen)
 
IoT_Error_t aws_iot_mqtt_set_client_state (AWS_IoT_Client *pClient, ClientState expectedCurrentState, ClientState newState)
 

Function Documentation

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
thebuffer containing the message
valuethe decoded length returned
Returns
the number of bytes read from the socket
IoT_Error_t aws_iot_mqtt_internal_deserialize_ack ( unsigned char *  pPacketType,
unsigned char *  dup,
uint16_t *  pPacketId,
unsigned char *  pRxBuf,
size_t  rxBuflen 
)

Deserializes the supplied (wire) buffer into an ack

Parameters
pPacketTypereturned integer - the MQTT packet type
dupreturned integer - the MQTT dup flag
pPacketIdreturned integer - the MQTT packet identifier
pRxBufthe raw buffer data, of the correct length determined by the remaining length field
rxBuflenthe length in bytes of the data in the supplied buffer
Returns
An IoT Error Type defining successful/failed call
IoT_Error_t aws_iot_mqtt_internal_deserialize_publish ( uint8_t *  dup,
QoS qos,
uint8_t *  retained,
uint16_t *  pPacketId,
char **  pTopicName,
uint16_t *  topicNameLen,
unsigned char **  payload,
size_t *  payloadLen,
unsigned char *  pRxBuf,
size_t  rxBufLen 
)

Deserializes the supplied (wire) buffer into publish data

Parameters
dupreturned uint8_t - the MQTT dup flag
qosreturned QoS type - the MQTT QoS value
retainedreturned uint8_t - the MQTT retained flag
pPacketIdreturned uint16_t - the MQTT packet identifier
pTopicNamereturned String - the MQTT topic in the publish
topicNameLenreturned uint16_t - the length of the MQTT topic in the publish
payloadreturned byte buffer - the MQTT publish payload
payloadlenreturned size_t - the length of the MQTT payload
pRxBufthe raw buffer data, of the correct length determined by the remaining length field
rxBufLenthe length in bytes of the data in the supplied buffer
Returns
An IoT Error Type defining successful/failed call
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

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
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
IoT_Error_t aws_iot_mqtt_internal_serialize_ack ( unsigned char *  pTxBuf,
size_t  txBufLen,
MessageTypes  msgType,
uint8_t  dup,
uint16_t  packetId,
uint32_t *  pSerializedLen 
)

Serializes the ack packet into the supplied buffer.

Parameters
pTxBufthe buffer into which the packet will be serialized
txBufLenthe length in bytes of the supplied buffer
msgTypethe MQTT packet type
dupthe MQTT dup flag
packetIdthe MQTT packet identifier
pSerializedLenuint32_t - pointer to the variable that stores serialized len
Returns
An IoT Error Type defining successful/failed call
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
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer, to avoid overruns
packettypethe message type
serializedlength
Returns
IoT_Error_t indicating function execution status
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
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
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