Microchip® Advanced Software Framework

network_winc1500tls_wrapper.c File Reference

winc1500 TLS wrapper.

Macros

#define DNS_REQUEST   25
 
#define IPV4_BYTE(val, index)   ((val >> (index * 8)) & 0xFF)
 Using IP address. More...
 

Functions

int iot_tls_connect (Network *pNetwork, TLSConnectParams params)
 TLS connection functionality. More...
 
int iot_tls_destroy (Network *pNetwork)
 TLS interface de-init function. More...
 
void iot_tls_disconnect (Network *pNetwork)
 TLS disconnect function. More...
 
int iot_tls_init (Network *pNetwork)
 Intialization of network interface for TLS function. More...
 
int iot_tls_is_connected (Network *pNetwork)
 TLS connection status call. More...
 
int iot_tls_read (Network *pNetwork, unsigned char *pMsg, int len, int timeout_ms)
 Read bytes from the network socket. More...
 
int iot_tls_write (Network *pNetwork, unsigned char *pMsg, int len, int timeout_ms)
 TLS write functionality. More...
 
static void resolve_cb (uint8_t *hostName, uint32_t hostIp)
 Callback function of IP address. More...
 
static void socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg)
 Callback function of TCP client socket. More...
 
static void wait_for_event (uint8_t msg)
 Event handling function for WIFI. More...
 

Variables

static uint8_t * buf_ptr = &gau8SocketTestBuffer
 
static int8_t err = 0
 
static uint8_t gau8SocketTestBuffer [1460]
 
static bool gbHostIpByName = false
 Get host IP status variable. More...
 
uint32_t gu32HostIp = 0
 IP address of host. More...
 
volatile uint32_t ms_ticks
 TLS read functionality. More...
 
uint32_t received_bytes = 0
 
uint32_t sent_bytes = 0
 
static int8_t state = -1
 

#define DNS_REQUEST   25

Referenced by iot_tls_connect(), and resolve_cb().

#define IPV4_BYTE (   val,
  index 
)    ((val >> (index * 8)) & 0xFF)

Using IP address.

Referenced by resolve_cb().

int iot_tls_connect ( Network pNetwork,
TLSConnectParams  params 
)

TLS connection functionality.

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, in_addr::s_addr, 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)

TLS interface de-init function.

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)

TLS disconnect function.

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)
int iot_tls_is_connected ( Network pNetwork)

TLS connection status call.

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, Network::my_socket, NULL, NULL_VALUE_ERROR, received_bytes, recv(), 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 
)

TLS write functionality.

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, Network::my_socket, NULL, NULL_VALUE_ERROR, send(), sent_bytes, SOCKET_MSG_SEND, SSL_WRITE_ERROR, and wait_for_event().

Referenced by iot_tls_init().

static void resolve_cb ( uint8_t *  hostName,
uint32_t  hostIp 
)
static

Callback function of IP address.

Parameters
[in]hostNameDomain name.
[in]hostIpServer IP.
Returns
None.

References DNS_REQUEST, gbHostIpByName, gu32HostIp, IPV4_BYTE, and state.

Referenced by iot_tls_init().

static void socket_cb ( SOCKET  sock,
uint8_t  u8Msg,
void *  pvMsg 
)
static

Callback function of TCP client socket.

Parameters
[in]socksocket handler.
[in]u8MsgType of Socket notification
[in]pvMsgA structure contains notification informations.
Returns
None.

References err, received_bytes, tstrSocketRecvMsg::s16BufferSize, tstrSocketConnectMsg::s8Error, sent_bytes, SOCK_ERR_NO_ERROR, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, SOCKET_MSG_SEND, and state.

Referenced by iot_tls_init().

static void wait_for_event ( uint8_t  msg)
static

Event handling function for WIFI.

Parameters
[in]pvMsgA structure contains notification informations.
Returns
None.

References m2m_wifi_handle_events(), NULL, and state.

Referenced by iot_tls_connect(), iot_tls_read(), and iot_tls_write().

uint8_t* buf_ptr = &gau8SocketTestBuffer
static

Referenced by iot_tls_read().

int8_t err = 0
static
uint8_t gau8SocketTestBuffer[1460]
static

Referenced by iot_tls_read().

bool gbHostIpByName = false
static

Get host IP status variable.

Referenced by resolve_cb().

uint32_t gu32HostIp = 0

IP address of host.

Referenced by iot_tls_connect(), and resolve_cb().

volatile uint32_t ms_ticks

TLS read functionality.

Parameters
[in]pNetworkNetwork interface.
[in]pMsgstore the data read
[in]lenlength of data.
[in]timeout_mstimeout for write function.
Returns
Status.

TLS read functionality.

uint32_t received_bytes = 0

Referenced by iot_tls_read(), and socket_cb().

uint32_t sent_bytes = 0

Referenced by iot_tls_write(), and socket_cb().

int8_t state = -1
static