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 | ||
) |
TLS connection functionality.
Create a TLS socket and open the connection.
[in] | pNetwork | Network interface. |
[in] | params | connection parameters for TLS. |
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().
int iot_tls_destroy | ( | Network * | pNetwork | ) |
TLS interface de-init function.
Perform any tear-down or cleanup of TLS layer.
[in] | pNetwork | Network interface. |
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.
[in] | pNetwork | Network interface. |
References close(), Network::my_socket, and NULL.
int iot_tls_init | ( | Network * | pNetwork | ) |
Intialization of network interface for TLS function.
Initialize the TLS implementation.
[in] | pNetwork | Network interface. |
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().
int iot_tls_is_connected | ( | Network * | pNetwork | ) |
TLS connection status call.
Check if TLS layer is still connected.
[in] | pNetwork | Network interface. |
int iot_tls_read | ( | Network * | , |
unsigned char * | , | ||
int | , | ||
int | |||
) |
Read bytes from the network socket.
Network | - Pointer to a Network struct defining the network interface. |
unsigned | char pointer - pointer to buffer where read bytes should be copied |
integer | - number of bytes to read |
integer | - read timeout value in milliseconds |
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.
[in] | pNetwork | Network interface. |
[in] | pMsg | data to write |
[in] | len | length of data. |
[in] | timeout_ms | timeout for write function. |
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 |
Callback function of IP address.
[in] | hostName | Domain name. |
[in] | hostIp | Server IP. |
References DNS_REQUEST, gbHostIpByName, gu32HostIp, IPV4_BYTE, printf, and state.
Referenced by iot_tls_init().
|
static |
Callback function of TCP client socket.
[in] | sock | socket handler. |
[in] | u8Msg | Type of Socket notification |
[in] | pvMsg | A structure contains notification informations. |
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 |
Event handling function for WIFI.
[in] | pvMsg | A structure contains notification informations. |
References m2m_wifi_handle_events(), NULL, and state.
Referenced by iot_tls_connect(), iot_tls_read(), and iot_tls_write().
|
static |
Referenced by iot_tls_read().
|
static |
Referenced by iot_tls_connect(), iot_tls_read(), iot_tls_write(), and socket_cb().
|
static |
Referenced by iot_tls_read().
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.
[in] | pNetwork | Network interface. |
[in] | pMsg | store the data read |
[in] | len | length of data. |
[in] | timeout_ms | timeout for write function. |
TLS read functionality.
SysTick counter for non busy wait delay.
uint32_t received_bytes = 0 |
uint32_t sent_bytes = 0 |
|
static |