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 |
Referenced by main().
|
static |
Configure UART console.
References uart_rs232_options::baudrate, CONF_UART, CONF_UART_BAUDRATE, CONF_UART_CHAR_LENGTH, CONF_UART_PARITY, CONF_UART_STOP_BITS, CONSOLE_UART_ID, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
int main | ( | void | ) |
Main application function.
Application entry point.
References board_init(), configure_console(), gbConnectedWifi, gbHostIpByName, gbSocketConnectInit, gu8SocketStatus, M2M_SUCCESS, M2M_WIFI_CH_ALL, m2m_wifi_connect(), m2m_wifi_handle_events(), m2m_wifi_init(), MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, nm_bsp_init(), NULL, tstrWifiInitParam::pfAppWifiCb, registerSocketCallback(), resolve_cb(), SOCK_ERR_NO_ERROR, socket_cb(), SocketInit, socketInit(), SocketWaiting, sslConnect(), STRING_HEADER, sysclk_init(), tcp_client_socket, and wifi_cb().
|
static |
Callback function of IP address.
[in] | hostName | Domain name. |
[in] | hostIp | Server IP. |
References gbHostIpByName, gu32HostIp, and IPV4_BYTE.
Referenced by main().
|
static |
Callback function of TCP client socket.
[in] | sock | socket handler. |
[in] | u8Msg | Type of Socket notification |
[in] | pvMsg | Structure that contains notification information. |
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 |
Creates and connects to an unsecure socket to be used for SSL.
[in] | None. |
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 |
Callback to get the Wi-Fi status update.
[in] | u8MsgType | type of Wi-Fi notification. Possible types are: |
[in] | pvMsg | A 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().
Get host IP status variable.
Referenced by main(), resolve_cb(), 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().
|
static |
Server host name.
Referenced by wifi_cb().
|
static |
TCP client socket handler.
Referenced by main(), socket_cb(), and sslConnect().