Microchip® Advanced Software Framework

network_winc1500tls_wrapper.c File Reference

winc1500 TLS wrapper.

#include <stdbool.h>
#include <string.h>
#include "AWS_SDK/aws_iot_src/utils/aws_iot_error.h"
#include "AWS_SDK/aws_iot_src/utils/aws_iot_log.h"
#include "AWS_SDK/aws_iot_src/protocol/mqtt/aws_iot_embedded_client_wrapper/network_interface.h"
#include "driver/include/m2m_wifi.h"
#include "driver/source/nmasic.h"
#include "socket/include/socket.h"

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 
)
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.

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.

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.
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().

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

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, printf, 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, printf, 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.

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.

SysTick counter for non busy wait delay.

uint32_t received_bytes = 0
uint32_t sent_bytes = 0
int8_t state = -1
static