AWS IoT Device SDK C:
MQTT
MQTT 3.1.1 client library
|
Return to main page ↑ |
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 |
Macros | |
#define | MQTT_HEADER_FIELD_TYPE(_byte) ((_byte >> 4) & 0x0F) |
#define | MQTT_HEADER_FIELD_DUP(_byte) ((_byte & (1 << 3)) >> 3) |
#define | MQTT_HEADER_FIELD_QOS(_byte) ((_byte & (3 << 1)) >> 1) |
#define | MQTT_HEADER_FIELD_RETAIN(_byte) ((_byte & (1 << 0)) >> 0) |
Enumerations | |
enum | MessageTypes { 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) |
Initialize the MQTTHeader structure. More... | |
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) |
Calculates the length of the "remaining length" encoding. More... | |
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... | |
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_flushBuffers (AWS_IoT_Client *pClient) |
Flush incoming data from the MQTT client. 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_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) |
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) |
Change the state in an MQTT client. More... | |
IoT_Error_t | aws_iot_mqtt_client_lock_mutex (AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex) |
Lock a mutex in the MQTT client. More... | |
IoT_Error_t | aws_iot_mqtt_client_unlock_mutex (AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex) |
Unlock a mutex in the MQTT client. More... | |
Internal MQTT functions not exposed to application.
#define MQTT_HEADER_FIELD_TYPE | ( | _byte | ) | ((_byte >> 4) & 0x0F) |
Message type
#define MQTT_HEADER_FIELD_DUP | ( | _byte | ) | ((_byte & (1 << 3)) >> 3) |
DUP flag
#define MQTT_HEADER_FIELD_QOS | ( | _byte | ) | ((_byte & (3 << 1)) >> 1) |
QoS
#define MQTT_HEADER_FIELD_RETAIN | ( | _byte | ) | ((_byte & (1 << 0)) >> 0) |
Retain flag
enum MessageTypes |
Types of MQTT messages
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.
pHeader | Header to initialize |
message_type | MQTT packet type |
qos | Quality of service for packet |
dup | DUP flag of a publish |
retained | RETAIN flag of a publish |
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.
pTxBuf | the buffer into which the packet will be serialized |
txBufLen | the length in bytes of the supplied buffer |
msgType | the MQTT packet type |
dup | the MQTT dup flag |
packetId | the MQTT packet identifier |
pSerializedLen | uint32_t - pointer to the variable that stores serialized len |
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
pPacketType | returned integer - the MQTT packet type |
dup | returned integer - the MQTT dup flag |
pPacketId | returned integer - the MQTT packet identifier |
pRxBuf | the raw buffer data, of the correct length determined by the remaining length field |
rxBuflen | the length in bytes of the data in the supplied buffer |
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.
rem_len | "remaining length" to encode |
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.
buf | the buffer into which the encoded data is written |
length | the length to be encoded |
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.
buf | the buffer containing the message |
decodedLen | value the decoded length returned |
readBytesLen | output parameter for the number of bytes read from the socket |
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
pptr | pointer to the input buffer - incremented by the number of bytes used & returned |
void aws_iot_mqtt_internal_write_uint_16 | ( | unsigned char ** | pptr, |
uint16_t | anInt | ||
) |
Writes an integer as 2 bytes to an output buffer.
pptr | pointer to the output buffer - incremented by the number of bytes used & returned |
anInt | the integer to write |
unsigned char aws_iot_mqtt_internal_read_char | ( | unsigned char ** | pptr | ) |
Reads one character from the input buffer.
pptr | pointer to the input buffer - incremented by the number of bytes used & returned |
void aws_iot_mqtt_internal_write_char | ( | unsigned char ** | pptr, |
unsigned char | c | ||
) |
Writes one character to an output buffer.
pptr | pointer to the output buffer - incremented by the number of bytes used & returned |
c | the character to write |
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.
pptr | Where the string should be written |
string | The string to write |
stringLen | Length to write |
IoT_Error_t aws_iot_mqtt_internal_flushBuffers | ( | AWS_IoT_Client * | pClient | ) |
Flush incoming data from the MQTT client.
pClient | Client with data to flush |
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.
pClient | MQTT client which holds packet |
length | Length of packet to send |
pTimer | Amount of time allowed to send packet |
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.
pClient | MQTT client |
pTimer | Amount of time allowed to read packet |
pPacketType | Output parameter for packet read from network |
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
pClient | MQTT client |
packetType | MQTT packet to read |
pTimer | Amount of time allowed to read packet |
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
pTxBuf | the buffer into which the packet will be serialized |
txBufLen | the length in bytes of the supplied buffer, to avoid overruns |
packetType | the message type |
pSerializedLength | length |
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
dup | returned uint8_t - the MQTT dup flag |
qos | returned QoS type - the MQTT QoS value |
retained | returned uint8_t - the MQTT retained flag |
pPacketId | returned uint16_t - the MQTT packet identifier |
pTopicName | returned String - the MQTT topic in the publish |
topicNameLen | returned uint16_t - the length of the MQTT topic in the publish |
payload | returned byte buffer - the MQTT publish payload |
payloadLen | returned size_t - the length of the MQTT payload |
pRxBuf | the raw buffer data, of the correct length determined by the remaining length field |
rxBufLen | the length in bytes of the data in the supplied buffer |
IoT_Error_t aws_iot_mqtt_set_client_state | ( | AWS_IoT_Client * | pClient, |
ClientState | expectedCurrentState, | ||
ClientState | newState | ||
) |
Change the state in an MQTT client.
pClient | MQTT client |
expectedCurrentState | What the current state of the client should be |
newState | What the new state of the client should be |
IoT_Error_t aws_iot_mqtt_client_lock_mutex | ( | AWS_IoT_Client * | pClient, |
IoT_Mutex_t * | pMutex | ||
) |
Lock a mutex in the MQTT client.
pClient | MQTT client |
pMutex | Mutex to lock |
IoT_Error_t aws_iot_mqtt_client_unlock_mutex | ( | AWS_IoT_Client * | pClient, |
IoT_Mutex_t * | pMutex | ||
) |
Unlock a mutex in the MQTT client.
pClient | MQTT client |
pMutex | Mutex to unlock |