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

Implements functions involving transport layer connections. More...

#include "iot_config.h"
#include <string.h>
#include "private/iot_mqtt_internal.h"
#include "platform/iot_threads.h"
#include "iot_atomic.h"

Functions

static bool _incomingPacketValid (uint8_t packetType)
 Check if an incoming packet type is valid. More...
 
static IotMqttError_t _allocateAndReceivePacket (IotNetworkConnection_t pNetworkConnection, const _mqttConnection_t *pMqttConnection, _mqttPacket_t *pIncomingPacket)
 Allocate space for an incoming MQTT packet received from the network. More...
 
static IotMqttError_t _getIncomingPacket (IotNetworkConnection_t pNetworkConnection, const _mqttConnection_t *pMqttConnection, _mqttPacket_t *pIncomingPacket)
 Get an incoming MQTT packet from the network. More...
 
static IotMqttError_t _deserializeAck (_mqttConnection_t *pMqttConnection, _mqttPacket_t *pIncomingPacket, IotMqttDeserialize_t _deserializer, IotMqttOperationType_t opType, const uint16_t *pPacketIdentifier)
 Deserialize a CONNACK, PUBACK, SUBACK, or UNSUBACK packet. More...
 
static IotMqttError_t _deserializePublishPacket (_mqttConnection_t *pMqttConnection, _mqttPacket_t *pIncomingPacket)
 Deserialize a PUBLISH packet. More...
 
static IotMqttError_t _deserializePingResp (_mqttConnection_t *pMqttConnection, _mqttPacket_t *pIncomingPacket)
 Deserialize a PINGRESP packet. More...
 
static IotMqttError_t _deserializeIncomingPacket (_mqttConnection_t *pMqttConnection, _mqttPacket_t *pIncomingPacket)
 Deserialize a packet received from the network. More...
 
static void _sendPuback (_mqttConnection_t *pMqttConnection, uint16_t packetIdentifier)
 Send a PUBACK for a received QoS 1 PUBLISH packet. More...
 
static void _flushPacket (IotNetworkConnection_t pNetworkConnection, const _mqttConnection_t *pMqttConnection, size_t length)
 Flush a packet from the stream of incoming data. More...
 
bool _IotMqtt_GetNextByte (IotNetworkConnection_t pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface, uint8_t *pIncomingByte)
 Read the next available byte on a network connection. More...
 
void _IotMqtt_CloseNetworkConnection (IotMqttDisconnectReason_t disconnectReason, _mqttConnection_t *pMqttConnection)
 Closes the network connection associated with an MQTT connection. More...
 
void IotMqtt_ReceiveCallback (IotNetworkConnection_t pNetworkConnection, void *pReceiveContext)
 Network receive callback for the MQTT library. More...
 

Detailed Description

Implements functions involving transport layer connections.

Function Documentation

◆ _incomingPacketValid()

static bool _incomingPacketValid ( uint8_t  packetType)
static

Check if an incoming packet type is valid.

Parameters
[in]packetTypeThe packet type to check.
Returns
true if the packet type is valid; false otherwise.

◆ _allocateAndReceivePacket()

static IotMqttError_t _allocateAndReceivePacket ( IotNetworkConnection_t  pNetworkConnection,
const _mqttConnection_t pMqttConnection,
_mqttPacket_t pIncomingPacket 
)
static

Allocate space for an incoming MQTT packet received from the network.

Parameters
[in]pNetworkConnectionNetwork connection to be used for receive.
[in]pMqttConnectionThe associated MQTT connection.
[out]pIncomingPacketOutput parameter for the incoming packet.
Returns
IOT_MQTT_SUCCESS, IOT_MQTT_NO_MEMORY or IOT_MQTT_BAD_RESPONSE.

◆ _getIncomingPacket()

static IotMqttError_t _getIncomingPacket ( IotNetworkConnection_t  pNetworkConnection,
const _mqttConnection_t pMqttConnection,
_mqttPacket_t pIncomingPacket 
)
static

Get an incoming MQTT packet from the network.

Parameters
[in]pNetworkConnectionNetwork connection to use for receive, which may be different from the network connection associated with the MQTT connection.
[in]pMqttConnectionThe associated MQTT connection.
[out]pIncomingPacketOutput parameter for the incoming packet.
Returns
IOT_MQTT_SUCCESS, IOT_MQTT_NO_MEMORY or IOT_MQTT_BAD_RESPONSE.

◆ _deserializeAck()

static IotMqttError_t _deserializeAck ( _mqttConnection_t pMqttConnection,
_mqttPacket_t pIncomingPacket,
IotMqttDeserialize_t  _deserializer,
IotMqttOperationType_t  opType,
const uint16_t *  pPacketIdentifier 
)
static

Deserialize a CONNACK, PUBACK, SUBACK, or UNSUBACK packet.

Parameters
[in]pMqttConnectionThe associated MQTT connection.
[in]pIncomingPacketThe packet received from the network.
[in]_deserializerThe deserialization function for the packet.
[in]opTypeThe type of operation corresponding to the packet.
[in]pPacketIdentifierAddress of incoming packet's packet identifier; NULL for a CONNACK.
Returns
IOT_MQTT_SUCCESS, IOT_MQTT_BAD_RESPONSE, or IOT_MQTT_SERVER_REFUSED.

◆ _deserializePublishPacket()

static IotMqttError_t _deserializePublishPacket ( _mqttConnection_t pMqttConnection,
_mqttPacket_t pIncomingPacket 
)
static

Deserialize a PUBLISH packet.

Parameters
[in]pMqttConnectionThe associated MQTT connection.
[in]pIncomingPacketThe packet received from the network.
Returns
IOT_MQTT_SUCCESS, IOT_MQTT_NO_MEMORY, IOT_MQTT_NETWORK_ERROR, or IOT_MQTT_SCHEDULING_ERROR.

◆ _deserializePingResp()

static IotMqttError_t _deserializePingResp ( _mqttConnection_t pMqttConnection,
_mqttPacket_t pIncomingPacket 
)
static

Deserialize a PINGRESP packet.

Parameters
[in]pMqttConnectionThe associated MQTT connection.
[in]pIncomingPacketThe packet received from the network.
Returns
IOT_MQTT_SUCCESS or IOT_MQTT_BAD_RESPONSE.

◆ _deserializeIncomingPacket()

static IotMqttError_t _deserializeIncomingPacket ( _mqttConnection_t pMqttConnection,
_mqttPacket_t pIncomingPacket 
)
static

Deserialize a packet received from the network.

Parameters
[in]pMqttConnectionThe associated MQTT connection.
[in]pIncomingPacketThe packet received from the network.
Returns
IOT_MQTT_SUCCESS, IOT_MQTT_NO_MEMORY, IOT_MQTT_NETWORK_ERROR, IOT_MQTT_SCHEDULING_ERROR, IOT_MQTT_BAD_RESPONSE, or IOT_MQTT_SERVER_REFUSED.

◆ _sendPuback()

static void _sendPuback ( _mqttConnection_t pMqttConnection,
uint16_t  packetIdentifier 
)
static

Send a PUBACK for a received QoS 1 PUBLISH packet.

Parameters
[in]pMqttConnectionWhich connection the PUBACK should be sent over.
[in]packetIdentifierWhich packet identifier to include in PUBACK.

◆ _flushPacket()

static void _flushPacket ( IotNetworkConnection_t  pNetworkConnection,
const _mqttConnection_t pMqttConnection,
size_t  length 
)
static

Flush a packet from the stream of incoming data.

This function is called when memory for a packet cannot be allocated. The packet is flushed from the stream of incoming data so that the next packet may be read.

Parameters
[in]pNetworkConnectionNetwork connection to use for receive, which may be different from the network connection associated with the MQTT connection.
[in]pMqttConnectionThe associated MQTT connection.
[in]lengthThe length of the packet to flush.

◆ _IotMqtt_GetNextByte()

bool _IotMqtt_GetNextByte ( IotNetworkConnection_t  pNetworkConnection,
const IotNetworkInterface_t pNetworkInterface,
uint8_t *  pIncomingByte 
)

Read the next available byte on a network connection.

Parameters
[in]pNetworkConnectionReference to the network connection.
[in]pNetworkInterfaceFunction pointers used to interact with the network.
[out]pIncomingByteThe byte read from the network.
Returns
true if a byte was successfully received from the network; false otherwise.

◆ _IotMqtt_CloseNetworkConnection()

void _IotMqtt_CloseNetworkConnection ( IotMqttDisconnectReason_t  disconnectReason,
_mqttConnection_t pMqttConnection 
)

Closes the network connection associated with an MQTT connection.

A network disconnect function must be set in the network interface for the network connection to be closed.

Parameters
[in]disconnectReasonA reason to pass to the connection's disconnect callback.
[in]pMqttConnectionThe MQTT connection with the network connection to close.

◆ IotMqtt_ReceiveCallback()

void IotMqtt_ReceiveCallback ( IotNetworkConnection_t  pNetworkConnection,
void *  pReceiveContext 
)

Network receive callback for the MQTT library.

This function should be called by the system whenever data is available for the MQTT library.

Parameters
[in]pNetworkConnectionThe network connection associated with the MQTT connection, passed by the network stack.
[in]pReceiveContextA pointer to the MQTT connection handle for which the packet was received.