Microchip® Advanced Software Framework

network_interface.h File Reference

Network interface definition for MQTT client.

Defines an interface to the TLS layer to be used by the MQTT client. Starting point for porting the SDK to the networking layer of a new platform.

Data Structures

struct  Network
 Network Structure. More...
 
struct  TLSConnectParams
 TLS Connection Parameters. More...
 

Typedefs

typedef struct Network Network
 Network Type. More...
 

Functions

int iot_tls_connect (Network *pNetwork, TLSConnectParams TLSParams)
 Create a TLS socket and open the connection. More...
 
int iot_tls_destroy (Network *pNetwork)
 Perform any tear-down or cleanup of TLS layer. More...
 
void iot_tls_disconnect (Network *pNetwork)
 Disconnect from network socket. More...
 
int iot_tls_init (Network *pNetwork)
 Initialize the TLS implementation. More...
 
int iot_tls_is_connected (Network *pNetwork)
 Check if TLS layer is still connected. More...
 
int iot_tls_read (Network *, unsigned char *, int, int)
 Read bytes from the network socket. More...
 
int iot_tls_write (Network *, unsigned char *, int, int)
 Write bytes to the network socket. More...
 

typedef struct Network Network

Network Type.

Defines a type for the network struct. See structure definition below.

int iot_tls_connect ( Network pNetwork,
TLSConnectParams  params 
)

Create a TLS socket and open the connection.

Creates an open socket connection including TLS handshake.

Parameters
pNetwork- Pointer to a Network struct defining the network interface.
TLSParams- TLSConnectParams defines the properties of the TLS connection.
Returns
integer - successful connection or TLS error

Create a TLS socket and open the connection.

Parameters
[in]pNetworkNetwork interface.
[in]paramsconnection parameters for TLS.
Returns
Status.

References _htons, AF_INET, close(), connect(), TLSConnectParams::DestinationPort, DNS_REQUEST, err, gethostbyname(), gu32HostIp, Network::my_socket, NONE_ERROR, TLSConnectParams::pDestinationURL, printf, ret, in_addr::s_addr, set_alpn_list(), sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_STREAM, socket(), SOCKET_FLAGS_SSL, SOCKET_MSG_CONNECT, SSL_CONNECT_ERROR, TCP_CONNECT_ERROR, and wait_for_event().

Referenced by iot_tls_init().

int iot_tls_destroy ( Network pNetwork)

Perform any tear-down or cleanup of TLS layer.

Called to cleanup any resources required for the TLS layer.

Parameters
Network- Pointer to a Network struct defining the network interface.
Returns
integer - successful cleanup or TLS error

Perform any tear-down or cleanup of TLS layer.

Parameters
[in]pNetworkNetwork interface.
Returns
Status.

References Network::disconnect, Network::mqttread, Network::mqttwrite, Network::my_socket, NONE_ERROR, NULL, and NULL_VALUE_ERROR.

Referenced by iot_tls_init().

void iot_tls_disconnect ( Network pNetwork)

Disconnect from network socket.

Parameters
Network- Pointer to a Network struct defining the network interface.

Disconnect from network socket.

Parameters
[in]pNetworkNetwork interface.
Returns
None.

References close(), Network::my_socket, and NULL.

Referenced by iot_tls_init().

int iot_tls_init ( Network pNetwork)

Initialize the TLS implementation.

Perform any initialization required by the TLS layer. Connects the interface to implementation by setting up the network layer function pointers to platform implementations.

Parameters
pNetwork- Pointer to a Network struct defining the network interface.
Returns
integer defining successful initialization or TLS error

Initialize the TLS implementation.

Parameters
[in]pNetworkNetwork interface.
Returns
Error status.

References Network::connect, Network::destroy, Network::disconnect, iot_tls_connect(), iot_tls_destroy(), iot_tls_disconnect(), iot_tls_is_connected(), iot_tls_read(), iot_tls_write(), Network::isConnected, Network::mqttread, Network::mqttwrite, Network::my_socket, NONE_ERROR, NULL, NULL_VALUE_ERROR, registerSocketCallback(), resolve_cb(), socket_cb(), and socketInit().

Referenced by aws_iot_mqtt_connect().

int iot_tls_is_connected ( Network pNetwork)

Check if TLS layer is still connected.

Called to check if the TLS layer is still connected or not.

Parameters
Network- Pointer to a Network struct defining the network interface.
Returns
int - integer indicating status of network physical layer connection

Check if TLS layer is still connected.

Parameters
[in]pNetworkNetwork interface.
Returns
Status.

Referenced by iot_tls_init().

int iot_tls_read ( Network ,
unsigned char *  ,
int  ,
int   
)

Read bytes from the network socket.

Parameters
Network- Pointer to a Network struct defining the network interface.
unsignedchar pointer - pointer to buffer where read bytes should be copied
integer- number of bytes to read
integer- read timeout value in milliseconds
Returns
integer - number of bytes read or TLS error

References buf_ptr, err, gau8SocketTestBuffer, i, len, Network::my_socket, NULL, NULL_VALUE_ERROR, printf, received_bytes, recv(), ret, SOCKET_MSG_RECV, SSL_READ_ERROR, and wait_for_event().

Referenced by iot_tls_init().

int iot_tls_write ( Network pNetwork,
unsigned char *  pMsg,
int  len,
int  timeout_ms 
)

Write bytes to the network socket.

Parameters
Network- Pointer to a Network struct defining the network interface.
unsignedchar pointer - buffer to write to socket
integer- number of bytes to write
integer- write timeout value in milliseconds
Returns
integer - number of bytes written or TLS error

Write bytes to the network socket.

Parameters
[in]pNetworkNetwork interface.
[in]pMsgdata to write
[in]lenlength of data.
[in]timeout_mstimeout for write function.
Returns
Status.

References err, i, len, Network::my_socket, NULL, NULL_VALUE_ERROR, printf, ret, send(), sent_bytes, SOCKET_MSG_SEND, SSL_WRITE_ERROR, and wait_for_event().

Referenced by iot_tls_init().