Microchip® Advanced Software Framework

main.c File Reference

ALPN Example.

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

#include "asf.h"
#include "main.h"
#include <string.h>
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"
#include "driver/include/m2m_ssl.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 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 char server_host_name [] = MAIN_HOST_NAME
 Server host name. More...
 
static SOCKET tcp_client_socket = -1
 TCP client socket handler. More...
 

#define STRING_EOL   "\r\n"
#define STRING_HEADER
Value:
"-- ALPN example --"STRING_EOL \
"-- "BOARD_NAME " --"STRING_EOL \
"-- Compiled: "__DATE__ " "__TIME__ " --"STRING_EOL
#define BOARD_NAME
Name of the board.
Definition: same70_xplained.h:75
#define STRING_EOL
Definition: main.c:107

Referenced by main().

static void configure_console ( void  )
static
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, and IPV4_BYTE.

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]pvMsgStructure that contains notification information.
Returns
None.

References close(), get_alpn_index(), get_error_detail(), gu8SocketStatus, tstrSocketConnectMsg::s8Error, tstrSocketConnectMsg::sock, 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_NAME, MAIN_HOST_PORT, in_addr::s_addr, set_alpn_list(), setsockopt(), sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SO_SSL_SNI, SOCK_ERR_INVALID, SOCK_ERR_NO_ERROR, SOCK_STREAM, socket(), SOCKET_FLAGS_SSL, SOL_SSL_SOCKET, 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_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, server_host_name, and tstrM2mWifiStateChanged::u8CurrState.

Referenced by main().

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.

Referenced by resolve_cb(), and sslConnect().

uint8_t gu8SocketStatus = SocketInit

Referenced by main(), and socket_cb().

char server_host_name[] = MAIN_HOST_NAME
static

Server host name.

Referenced by wifi_cb().

SOCKET tcp_client_socket = -1
static

TCP client socket handler.

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