SSL Example.
Copyright (c) 2016-2018 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... | |
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 |
Referenced by main().
|
static |
Configure UART console.
References usart_config::baudrate, cdc_uart_module, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), and usart_get_config_defaults().
int main | ( | void | ) |
Main application function.
Application entry point.
References configure_console(), gbConnectedWifi, gbHostIpByName, 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, printf, registerSocketCallback(), resolve_cb(), ret, SOCK_ERR_NO_ERROR, socket_cb(), SocketInit, socketInit(), SocketWaiting, sslConnect(), STRING_HEADER, system_init(), tcp_client_socket, and wifi_cb().
|
static |
Callback function of IP address.
[in] | hostName | Domain name. |
[in] | hostIp | Server IP. |
References gbHostIpByName, gu32HostIp, IPV4_BYTE, and printf.
Referenced by main().
|
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 gu8SocketStatus, printf, tstrSocketConnectMsg::s8Error, 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_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 |
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, gethostbyname(), M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, m2m_wifi_request_dhcp_client(), M2M_WIFI_RESP_CON_STATE_CHANGED, MAIN_HOST_NAME, MAIN_WLAN_AUTH, MAIN_WLAN_PSK, MAIN_WLAN_SSID, printf, and tstrM2mWifiStateChanged::u8CurrState.
Referenced by main().
|
static |
UART module for debug.
Get host IP status variable.
Referenced by main(), resolve_cb(), and wifi_cb().
uint32_t gu32HostIp = 0 |
IP address of host.
Referenced by iot_tls_connect(), main(), resolve_cb(), smtpConnect(), and sslConnect().
uint8_t gu8SocketStatus = SocketInit |
Referenced by main(), retry_smtp_server(), and socket_cb().
|
static |
TCP client socket handler.
Referenced by main(), socket_cb(), and sslConnect().