Microchip® Advanced Software Framework

winc3400/ssl_connect_example/main21.c File Reference

SSL Example.

Copyright (c) 2017-2019 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "main.h"
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"

Macros

#define STRING_EOL   "\r\n"
 
#define STRING_HEADER
 

Functions

static void configure_console (void)
 Configure UART console. More...
 
int main (void)
 Main application function. 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 int8_t sslConnect (void)
 Creates and connects to an unsecure socket to be used for SSL. More...
 
static void wifi_cb (uint8_t u8MsgType, void *pvMsg)
 Callback to get the Wi-Fi status update. More...
 

Variables

static struct usart_module cdc_uart_module
 UART module for debug. More...
 
static bool gbConnectedWifi = false
 Wi-Fi status variable. More...
 
static bool gbHostIpByName = false
 Get host IP status variable. More...
 
static bool gbSocketConnectInit = false
 Secure socket connection start variable. More...
 
uint32_t gu32HostIp = 0
 IP address of host. More...
 
uint8_t gu8SocketStatus = SocketInit
 
static SOCKET tcp_client_socket = -1
 TCP client socket handler. More...
 

#define STRING_EOL   "\r\n"
#define STRING_HEADER
Value:
"-- SSL example --"STRING_EOL \
"-- "BOARD_NAME " --"STRING_EOL \
"-- Compiled: "__DATE__ " "__TIME__ " --"STRING_EOL
#define BOARD_NAME
Definition: app_init.h:140
#define STRING_EOL
Definition: winc3400/ssl_connect_example/main21.c:96

Referenced by main().

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 gbHostIpByName, gu32HostIp, IPV4_BYTE, and printf.

Referenced by main().

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 gu8SocketStatus, printf, tstrSocketConnectMsg::s8Error, SOCK_ERR_NO_ERROR, SOCKET_MSG_CONNECT, SocketError, and tcp_client_socket.

Referenced by main().

static int8_t sslConnect ( void  )
static

Creates and connects to an unsecure socket to be used for SSL.

Parameters
[in]None.
Returns
SOCK_ERR_NO_ERROR if success, -1 if socket create error, SOCK_ERR_INVALID if socket connect error.

References _htons, AF_INET, close(), connect(), gu32HostIp, MAIN_HOST_PORT, printf, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_ERR_INVALID, SOCK_ERR_NO_ERROR, SOCK_STREAM, socket(), SOCKET_FLAGS_SSL, and tcp_client_socket.

Referenced by main().

static void wifi_cb ( uint8_t  u8MsgType,
void *  pvMsg 
)
static

Callback to get the Wi-Fi status update.

Parameters
[in]u8MsgTypetype of Wi-Fi notification. Possible types are:
[in]pvMsgA pointer to a buffer containing the notification parameters (if any). It should be casted to the correct data type corresponding to the notification type.

References gbConnectedWifi, gbHostIpByName, gbSocketConnectInit, gethostbyname(), M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, M2M_WIFI_RESP_CON_STATE_CHANGED, M2M_WIFI_RESP_GET_SYS_TIME, MAIN_HOST_NAME, MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, printf, and tstrM2mWifiStateChanged::u8CurrState.

Referenced by main().

struct usart_module cdc_uart_module
static

UART module for debug.

bool gbConnectedWifi = false
static

Wi-Fi status variable.

Referenced by main(), and wifi_cb().

bool gbHostIpByName = false
static

Get host IP status variable.

Referenced by main(), resolve_cb(), and wifi_cb().

bool gbSocketConnectInit = false
static

Secure socket connection start variable.

Referenced by main(), and wifi_cb().

uint32_t gu32HostIp = 0

IP address of host.

uint8_t gu8SocketStatus = SocketInit
SOCKET tcp_client_socket = -1
static

TCP client socket handler.

Referenced by main(), socket_cb(), and sslConnect().