From dfcf34b09088c684aad1db397fddcc30fb25e7ab Mon Sep 17 00:00:00 2001 From: mikee47 Date: Sun, 4 Aug 2019 18:05:14 +0100 Subject: [PATCH] Host implementation * Add list of AP's for Host * Add check to host for WPS/SmartConfig (not supported) --- .../esp_hal/include/esp_systemapi.h | 1 - .../Host/Components/esp_wifi/component.mk | 13 +- .../Arch/Host/Components/esp_wifi/esp_wifi.c | 114 ------ .../esp_wifi/include/esp_smartconfig.h | 50 --- .../Components/esp_wifi/include/esp_wifi.h | 145 ------- .../esp_wifi/include/esp_wifi_types.h | 132 ------- Sming/Arch/Host/Components/hostlib/hostlib.h | 1 - .../Arch/Host/Components/hostlib/startup.cpp | 2 +- Sming/Arch/Host/Components/lwip/lwipopts.h | 2 +- Sming/Arch/Host/Platform/AccessPoint.cpp | 73 ---- Sming/Arch/Host/Platform/AccessPointImpl.cpp | 69 ++++ Sming/Arch/Host/Platform/AccessPointImpl.h | 30 ++ Sming/Arch/Host/Platform/Station.cpp | 251 ------------ Sming/Arch/Host/Platform/StationImpl.cpp | 368 ++++++++++++++++++ Sming/Arch/Host/Platform/StationImpl.h | 86 ++++ Sming/Arch/Host/Platform/WifiEvents.cpp | 88 ----- Sming/Arch/Host/Platform/WifiEventsImpl.cpp | 15 + Sming/Arch/Host/Platform/WifiEventsImpl.h | 41 ++ 18 files changed, 620 insertions(+), 861 deletions(-) delete mode 100644 Sming/Arch/Host/Components/esp_wifi/esp_wifi.c delete mode 100644 Sming/Arch/Host/Components/esp_wifi/include/esp_smartconfig.h delete mode 100644 Sming/Arch/Host/Components/esp_wifi/include/esp_wifi.h delete mode 100644 Sming/Arch/Host/Components/esp_wifi/include/esp_wifi_types.h delete mode 100644 Sming/Arch/Host/Platform/AccessPoint.cpp create mode 100644 Sming/Arch/Host/Platform/AccessPointImpl.cpp create mode 100644 Sming/Arch/Host/Platform/AccessPointImpl.h delete mode 100644 Sming/Arch/Host/Platform/Station.cpp create mode 100644 Sming/Arch/Host/Platform/StationImpl.cpp create mode 100644 Sming/Arch/Host/Platform/StationImpl.h delete mode 100644 Sming/Arch/Host/Platform/WifiEvents.cpp create mode 100644 Sming/Arch/Host/Platform/WifiEventsImpl.cpp create mode 100644 Sming/Arch/Host/Platform/WifiEventsImpl.h diff --git a/Sming/Arch/Host/Components/esp_hal/include/esp_systemapi.h b/Sming/Arch/Host/Components/esp_hal/include/esp_systemapi.h index 40df8090d1..5fbebd7d27 100644 --- a/Sming/Arch/Host/Components/esp_hal/include/esp_systemapi.h +++ b/Sming/Arch/Host/Components/esp_hal/include/esp_systemapi.h @@ -34,7 +34,6 @@ struct ip_addr { #include #include #include -#include #include "esp_sleep.h" #include diff --git a/Sming/Arch/Host/Components/esp_wifi/component.mk b/Sming/Arch/Host/Components/esp_wifi/component.mk index 88d5fb36a6..a4f3c34418 100644 --- a/Sming/Arch/Host/Components/esp_wifi/component.mk +++ b/Sming/Arch/Host/Components/esp_wifi/component.mk @@ -3,10 +3,15 @@ COMPONENT_DEPENDS := lwip # Options to add for configuring host network behaviour CACHE_VARS += HOST_NETWORK_OPTIONS HOST_NETWORK_OPTIONS ?= -CLI_TARGET_OPTIONS += $(HOST_NETWORK_OPTIONS) +CLI_TARGET_OPTIONS += $(HOST_NETWORK_OPTIONS) -COMPONENT_VARS := ENABLE_WPS +COMPONENT_TARGETS := esp-wifi-check + +.PHONY: esp-wifi-check +$(COMPONENT_RULE)esp-wifi-check: ifeq ($(ENABLE_WPS),1) - GLOBAL_CFLAGS += -DENABLE_WPS=1 - EXTRA_LIBS := wps + $(warning WPS not supported) +endif +ifeq ($(ENABLE_SMART_CONFIG),1) + $(warning 'Smart Config' not supported) endif diff --git a/Sming/Arch/Host/Components/esp_wifi/esp_wifi.c b/Sming/Arch/Host/Components/esp_wifi/esp_wifi.c deleted file mode 100644 index 1a9a9d8f3a..0000000000 --- a/Sming/Arch/Host/Components/esp_wifi/esp_wifi.c +++ /dev/null @@ -1,114 +0,0 @@ -/** - * esp_wifi.c - * - * Copyright 2019 mikee47 - * - * This file is part of the Sming Framework Project - * - * This library is free software: you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation, version 3 or later. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with SHEM. - * If not, see . - * - ****/ - -#include "include/esp_wifi.h" -#include -#include - -static wifi_event_handler_cb_t event_handler; - -void wifi_set_event_handler_cb(wifi_event_handler_cb_t cb) -{ - event_handler = cb; -} - -static void wifi_status_callback(struct netif* nif) -{ - if(event_handler == NULL || nif == NULL) { - return; - } - - static uint32_t prev_flags; - - uint32_t changed_flags = prev_flags ^ nif->flags; - prev_flags = nif->flags; - - if(changed_flags & NETIF_FLAG_UP) { - System_Event_t evt = {.event = - (nif->flags & NETIF_FLAG_UP) ? EVENT_STAMODE_CONNECTED : EVENT_STAMODE_DISCONNECTED}; - const char SSID[] = "Host WiFi"; - memcpy(evt.event_info.connected.ssid, SSID, sizeof(SSID)); - evt.event_info.connected.ssid_len = sizeof(SSID) - 1; - memcpy(evt.event_info.connected.bssid, nif->hwaddr, 6); - evt.event_info.connected.channel = 1; - event_handler(&evt); - } - - if(!ip4_addr_isany_val(nif->ip_addr)) { - System_Event_t evt = {.event = EVENT_STAMODE_GOT_IP, - .event_info = {.got_ip = { - .ip.addr = nif->ip_addr.addr, - .mask.addr = nif->netmask.addr, - .gw.addr = nif->gw.addr, - }}}; - event_handler(&evt); - } -} - -static void status_callback(struct netif* netif) -{ - host_queue_callback((host_task_callback_t)wifi_status_callback, (uint32_t)netif); -} - -// Called directly from startup code -void host_wifi_lwip_init_complete(void) -{ - struct netif* nif = netif_default; - - if(nif == NULL) { - return; - } - - netif_set_status_callback(nif, status_callback); - - netif_set_up(nif); -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&nif, 1); -#endif - - if(ip4_addr_isany_val(nif->ip_addr)) { - dhcp_start(nif); - } -} - -bool wifi_get_ip_info(uint8 if_index, struct ip_info* info) -{ - struct netif* nif = netif_default; - - if(if_index != STATION_IF || nif == NULL) { - return false; - } - - info->ip.addr = nif->ip_addr.addr; - info->gw.addr = nif->gw.addr; - info->netmask.addr = nif->netmask.addr; - return true; -} - -bool wifi_get_macaddr(uint8 if_index, uint8* macaddr) -{ - struct netif* nif = netif_default; - - if(if_index != STATION_IF || nif == NULL) { - return false; - } - - memcpy(macaddr, nif->hwaddr, 6); - return true; -} diff --git a/Sming/Arch/Host/Components/esp_wifi/include/esp_smartconfig.h b/Sming/Arch/Host/Components/esp_wifi/include/esp_smartconfig.h deleted file mode 100644 index a351cb4d27..0000000000 --- a/Sming/Arch/Host/Components/esp_wifi/include/esp_smartconfig.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ESPRESSIF MIT License - * - * Copyright (c) 2016 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __SMARTCONFIG_H__ -#define __SMARTCONFIG_H__ - -typedef enum { - SC_STATUS_WAIT = 0, - SC_STATUS_FIND_CHANNEL, - SC_STATUS_GETTING_SSID_PSWD, - SC_STATUS_LINK, - SC_STATUS_LINK_OVER, -} sc_status; - -typedef enum { - SC_TYPE_ESPTOUCH = 0, - SC_TYPE_AIRKISS, - SC_TYPE_ESPTOUCH_AIRKISS, -} sc_type; - -//typedef void (*sc_callback_t)(sc_status status, void *pdata); -// -//const char *smartconfig_get_version(void); -//bool smartconfig_start(sc_callback_t cb, ...); -//bool smartconfig_stop(void); -//bool esptouch_set_timeout(uint8 time_s); //15s~255s, offset:45s -//bool smartconfig_set_type(sc_type type); - -#endif diff --git a/Sming/Arch/Host/Components/esp_wifi/include/esp_wifi.h b/Sming/Arch/Host/Components/esp_wifi/include/esp_wifi.h deleted file mode 100644 index ce16e7ca17..0000000000 --- a/Sming/Arch/Host/Components/esp_wifi/include/esp_wifi.h +++ /dev/null @@ -1,145 +0,0 @@ -#pragma once - -#include "esp_wifi_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//#define NULL_MODE 0x00 -//#define STATION_MODE 0x01 -//#define SOFTAP_MODE 0x02 -//#define STATIONAP_MODE 0x03 - -//uint8 wifi_get_opmode(void); -//uint8 wifi_get_opmode_default(void); -//bool wifi_set_opmode(uint8 opmode); -//bool wifi_set_opmode_current(uint8 opmode); -//uint8 wifi_get_broadcast_if(void); -//bool wifi_set_broadcast_if(uint8 interface); - -//bool wifi_station_get_config(struct station_config *config); -//bool wifi_station_get_config_default(struct station_config *config); -//bool wifi_station_set_config(struct station_config *config); -//bool wifi_station_set_config_current(struct station_config *config); - -//bool wifi_station_connect(void); -//bool wifi_station_disconnect(void); - -//void wifi_enable_signaling_measurement(void); -//void wifi_disable_signaling_measurement(void); - -//sint8 wifi_station_get_rssi(void); - -//uint8 wifi_station_get_connect_status(void); - -//uint8 wifi_station_get_current_ap_id(void); -//bool wifi_station_ap_change(uint8 current_ap_id); -//bool wifi_station_ap_number_set(uint8 ap_number); -//uint8 wifi_station_get_ap_info(struct station_config config[]); - -//bool wifi_station_dhcpc_start(void); -//bool wifi_station_dhcpc_stop(void); -//enum dhcp_status wifi_station_dhcpc_status(void); -//bool wifi_station_dhcpc_set_maxtry(uint8 num); - -//char* wifi_station_get_hostname(void); -//bool wifi_station_set_hostname(char *name); - -//int wifi_station_set_cert_key(uint8 *client_cert, int client_cert_len, -// uint8 *private_key, int private_key_len, -// uint8 *private_key_passwd, int private_key_passwd_len); -//void wifi_station_clear_cert_key(void); -//int wifi_station_set_username(uint8 *username, int len); -//void wifi_station_clear_username(void); - -//bool wifi_softap_get_config(struct softap_config *config); -//bool wifi_softap_get_config_default(struct softap_config *config); -//bool wifi_softap_set_config(struct softap_config *config); -//bool wifi_softap_set_config_current(struct softap_config *config); - -//uint8 wifi_softap_get_station_num(void); -//struct station_info * wifi_softap_get_station_info(void); -//void wifi_softap_free_station_info(void); - -//bool wifi_softap_dhcps_start(void); -//bool wifi_softap_dhcps_stop(void); - -//bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please); -//bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); -//uint32 wifi_softap_get_dhcps_lease_time(void); -//bool wifi_softap_set_dhcps_lease_time(uint32 minute); -//bool wifi_softap_reset_dhcps_lease_time(void); - -//enum dhcp_status wifi_softap_dhcps_status(void); -//bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); - -bool wifi_get_ip_info(uint8 if_index, struct ip_info *info); -//bool wifi_set_ip_info(uint8 if_index, struct ip_info *info); -bool wifi_get_macaddr(uint8 if_index, uint8 *macaddr); -//bool wifi_set_macaddr(uint8 if_index, uint8 *macaddr); - -//uint8 wifi_get_channel(void); -//bool wifi_set_channel(uint8 channel); - -//void wifi_status_led_install(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func); -//void wifi_status_led_uninstall(); - -//void wifi_promiscuous_enable(uint8 promiscuous); - -//typedef void (* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len); - -//void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); - -//void wifi_promiscuous_set_mac(const uint8_t *address); - -//enum phy_mode wifi_get_phy_mode(void); -//bool wifi_set_phy_mode(enum phy_mode mode); - -typedef void (* wifi_event_handler_cb_t)(System_Event_t *event); - -void wifi_set_event_handler_cb(wifi_event_handler_cb_t cb); - -//bool wifi_wps_enable(WPS_TYPE_t wps_type); -//bool wifi_wps_disable(void); -//bool wifi_wps_start(void); - -//typedef void (*wps_st_cb_t)(int status); -//bool wifi_set_wps_cb(wps_st_cb_t cb); - -//typedef void (*freedom_outside_cb_t)(uint8 status); -//int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb); -//void wifi_unregister_send_pkt_freedom_cb(void); -//int wifi_send_pkt_freedom(uint8 *buf, int len, bool sys_seq); - -//int wifi_rfid_locp_recv_open(void); -//void wifi_rfid_locp_recv_close(void); - -//typedef void (*rfid_locp_cb_t)(uint8 *frm, int len, int rssi); -//int wifi_register_rfid_locp_recv_cb(rfid_locp_cb_t cb); -//void wifi_unregister_rfid_locp_recv_cb(void); - -//int wifi_set_user_fixed_rate(uint8 enable_mask, uint8 rate); -//int wifi_get_user_fixed_rate(uint8 *enable_mask, uint8 *rate); - -//int wifi_set_user_sup_rate(uint8 min, uint8 max); - -//bool wifi_set_user_rate_limit(uint8 mode, uint8 ifidx, uint8 max, uint8 min); -//uint8 wifi_get_user_limit_rate_mask(void); -//bool wifi_set_user_limit_rate_mask(uint8 enable_mask); - -//typedef void (*user_ie_manufacturer_recv_cb_t)(uint8 type, const uint8 sa[6], const uint8 m_oui[3], uint8 *ie, uint8 ie_len, int rssi); - -//bool wifi_set_user_ie(bool enable, uint8 *m_oui, uint8 type, uint8 *user_ie, uint8 len); -//int wifi_register_user_ie_manufacturer_recv_cb(user_ie_manufacturer_recv_cb_t cb); -//void wifi_unregister_user_ie_manufacturer_recv_cb(void); - -//bool wifi_set_country(wifi_country_t *country); -//bool wifi_get_country(wifi_country_t *country); - -void host_wifi_lwip_init_complete(void); - - -#ifdef __cplusplus -} -#endif diff --git a/Sming/Arch/Host/Components/esp_wifi/include/esp_wifi_types.h b/Sming/Arch/Host/Components/esp_wifi/include/esp_wifi_types.h deleted file mode 100644 index 7a72000c89..0000000000 --- a/Sming/Arch/Host/Components/esp_wifi/include/esp_wifi_types.h +++ /dev/null @@ -1,132 +0,0 @@ -#pragma once -#include "c_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define STATION_IF 0x00 -#define SOFTAP_IF 0x01 - -/* Platform/WifiEvents.h */ - -struct ip_info { - struct ip_addr ip; - struct ip_addr netmask; - struct ip_addr gw; -}; - -/* System events */ - -enum { - EVENT_STAMODE_CONNECTED = 0, - EVENT_STAMODE_DISCONNECTED, - EVENT_STAMODE_AUTHMODE_CHANGE, - EVENT_STAMODE_GOT_IP, - EVENT_STAMODE_DHCP_TIMEOUT, - EVENT_SOFTAPMODE_STACONNECTED, - EVENT_SOFTAPMODE_STADISCONNECTED, - EVENT_SOFTAPMODE_PROBEREQRECVED, - EVENT_OPMODE_CHANGED, - EVENT_SOFTAPMODE_DISTRIBUTE_STA_IP, - EVENT_MAX, -}; - -typedef struct { - uint8 ssid[32]; - uint8 ssid_len; - uint8 bssid[6]; - uint8 channel; -} Event_StaMode_Connected_t; - -typedef struct { - uint8 ssid[32]; - uint8 ssid_len; - uint8 bssid[6]; - uint8 reason; -} Event_StaMode_Disconnected_t; - -typedef struct { - uint8 old_mode; - uint8 new_mode; -} Event_StaMode_AuthMode_Change_t; - -typedef struct { - struct ip_addr ip; - struct ip_addr mask; - struct ip_addr gw; -} Event_StaMode_Got_IP_t; - -typedef struct { - uint8 mac[6]; - uint8 aid; -} Event_SoftAPMode_StaConnected_t; - -typedef struct { - uint8 mac[6]; - struct ip_addr ip; - uint8 aid; -} Event_SoftAPMode_Distribute_Sta_IP_t; - -typedef struct { - uint8 mac[6]; - uint8 aid; -} Event_SoftAPMode_StaDisconnected_t; - -typedef struct { - int rssi; - uint8 mac[6]; -} Event_SoftAPMode_ProbeReqRecved_t; - -typedef struct { - uint8 old_opmode; - uint8 new_opmode; -} Event_OpMode_Change_t; - -typedef union { - Event_StaMode_Connected_t connected; - Event_StaMode_Disconnected_t disconnected; - Event_StaMode_AuthMode_Change_t auth_change; - Event_StaMode_Got_IP_t got_ip; - Event_SoftAPMode_StaConnected_t sta_connected; - Event_SoftAPMode_Distribute_Sta_IP_t distribute_sta_ip; - Event_SoftAPMode_StaDisconnected_t sta_disconnected; - Event_SoftAPMode_ProbeReqRecved_t ap_probereqrecved; - Event_OpMode_Change_t opmode_changed; -} Event_Info_u; - -typedef struct _esp_event { - uint32 event; - Event_Info_u event_info; -} System_Event_t; - -/* Platform/Station.h */ - -enum STATUS { - OK, - FAIL, - PENDING, - BUSY, - CANCEL, -}; - -struct bss_info; - -enum AUTH_MODE { - AUTH_OPEN, - AUTH_WEP, - AUTH_WPA_PSK, - AUTH_WPA2_PSK, - AUTH_WPA_WPA2_PSK, - AUTH_MAX, -}; - -/* Platform/AccessPoint */ - -struct softap_config; - -#ifdef __cplusplus -} -#endif diff --git a/Sming/Arch/Host/Components/hostlib/hostlib.h b/Sming/Arch/Host/Components/hostlib/hostlib.h index 58ec6e94ef..94172cecb3 100644 --- a/Sming/Arch/Host/Components/hostlib/hostlib.h +++ b/Sming/Arch/Host/Components/hostlib/hostlib.h @@ -26,7 +26,6 @@ #ifdef __WIN32 // Prevent early inclusion of winsock.h #include -#undef EVENT_MAX // Conflicts with definitions in esp_wifi_types.h #endif #include diff --git a/Sming/Arch/Host/Components/hostlib/startup.cpp b/Sming/Arch/Host/Components/hostlib/startup.cpp index 76e53e5efb..c2731afdee 100644 --- a/Sming/Arch/Host/Components/hostlib/startup.cpp +++ b/Sming/Arch/Host/Components/hostlib/startup.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include @@ -40,6 +39,7 @@ static int exitCode = 0; static bool done = false; extern void init(); +extern void host_wifi_lwip_init_complete(); static void cleanup() { diff --git a/Sming/Arch/Host/Components/lwip/lwipopts.h b/Sming/Arch/Host/Components/lwip/lwipopts.h index ec02e8a16e..b6250d69de 100644 --- a/Sming/Arch/Host/Components/lwip/lwipopts.h +++ b/Sming/Arch/Host/Components/lwip/lwipopts.h @@ -310,7 +310,7 @@ /** * LWIP_IGMP==1: Turn on IGMP module. */ -#define LWIP_IGMP 0 +#define LWIP_IGMP 1 /* ---------------------------------- diff --git a/Sming/Arch/Host/Platform/AccessPoint.cpp b/Sming/Arch/Host/Platform/AccessPoint.cpp deleted file mode 100644 index 53df8a8e09..0000000000 --- a/Sming/Arch/Host/Platform/AccessPoint.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**** - * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. - * Created 2015 by Skurydin Alexey - * http://github.com/SmingHub/Sming - * All files of the Sming Core are provided under the LGPL v3 license. - * - * AccessPoint.cpp - * - ****/ - -#include "Platform/AccessPoint.h" -#include "Data/HexString.h" - -AccessPointClass WifiAccessPoint; - -void AccessPointClass::enable(bool enabled, bool save) -{ -} - -bool AccessPointClass::isEnabled() -{ - return false; -} - -bool AccessPointClass::config(const String& ssid, String password, AUTH_MODE mode, bool hidden, int channel, - int beaconInterval) -{ - return false; -} - -IPAddress AccessPointClass::getIP() -{ - return IPADDR_NONE; -} - -IPAddress AccessPointClass::getNetworkBroadcast() -{ - return IPADDR_NONE; -} - -IPAddress AccessPointClass::getNetworkMask() -{ - return IPADDR_NONE; -} - -IPAddress AccessPointClass::getNetworkGateway() -{ - return IPADDR_NONE; -} - -bool AccessPointClass::setIP(IPAddress address) -{ - return false; -} - -String AccessPointClass::getMAC(char sep) -{ - return nullptr; -} - -String AccessPointClass::getSSID() -{ - return nullptr; -} - -String AccessPointClass::getPassword() -{ - return nullptr; -} - -void AccessPointClass::onSystemReady() -{ -} diff --git a/Sming/Arch/Host/Platform/AccessPointImpl.cpp b/Sming/Arch/Host/Platform/AccessPointImpl.cpp new file mode 100644 index 0000000000..9518dccb27 --- /dev/null +++ b/Sming/Arch/Host/Platform/AccessPointImpl.cpp @@ -0,0 +1,69 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/SmingHub/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + * + * AccessPoint.cpp + * + ****/ + +#include "AccessPointImpl.h" + +static AccessPointImpl accessPoint; +AccessPointClass& WifiAccessPoint = accessPoint; + +void AccessPointImpl::enable(bool enabled, bool save) +{ +} + +bool AccessPointImpl::isEnabled() const +{ + return false; +} + +bool AccessPointImpl::config(const String& ssid, String password, WifiAuthMode mode, bool hidden, int channel, + int beaconInterval) +{ + return false; +} + +IPAddress AccessPointImpl::getIP() const +{ + return INADDR_NONE; +} + +IPAddress AccessPointImpl::getNetworkBroadcast() const +{ + return INADDR_NONE; +} + +IPAddress AccessPointImpl::getNetworkMask() const +{ + return INADDR_NONE; +} + +IPAddress AccessPointImpl::getNetworkGateway() const +{ + return INADDR_NONE; +} + +bool AccessPointImpl::setIP(IPAddress address) +{ + return false; +} + +MACAddress AccessPointImpl::getMacAddr() const +{ + return MACADDR_NONE; +} + +String AccessPointImpl::getSSID() const +{ + return nullptr; +} + +String AccessPointImpl::getPassword() const +{ + return nullptr; +} diff --git a/Sming/Arch/Host/Platform/AccessPointImpl.h b/Sming/Arch/Host/Platform/AccessPointImpl.h new file mode 100644 index 0000000000..76a6662275 --- /dev/null +++ b/Sming/Arch/Host/Platform/AccessPointImpl.h @@ -0,0 +1,30 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/SmingHub/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + * + * AccessPointImpl.h - Host WiFi Access Point + * + ****/ + +#pragma once + +#include "Platform/AccessPoint.h" + +class AccessPointImpl : public AccessPointClass +{ +public: + void enable(bool enabled, bool save) override; + bool isEnabled() const override; + bool config(const String& ssid, String password, WifiAuthMode mode, bool hidden, int channel, + int beaconInterval) override; + IPAddress getIP() const override; + bool setIP(IPAddress address) override; + MACAddress getMacAddr() const override; + IPAddress getNetworkMask() const override; + IPAddress getNetworkGateway() const override; + IPAddress getNetworkBroadcast() const override; + String getSSID() const override; + String getPassword() const override; +}; diff --git a/Sming/Arch/Host/Platform/Station.cpp b/Sming/Arch/Host/Platform/Station.cpp deleted file mode 100644 index 3b54e20129..0000000000 --- a/Sming/Arch/Host/Platform/Station.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/**** - * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. - * Created 2015 by Skurydin Alexey - * http://github.com/SmingHub/Sming - * All files of the Sming Core are provided under the LGPL v3 license. - * - * Station.cpp - * - ****/ - -#include "Platform/Station.h" -#include "Data/HexString.h" - -StationClass WifiStation; - -void StationClass::enable(bool enabled, bool save) -{ -} - -bool StationClass::isEnabled() -{ - return true; -} - -bool StationClass::config(const String& ssid, const String& password, bool autoConnectOnStartup, bool save) -{ - return true; -} - -bool StationClass::connect() -{ - return true; -} - -bool StationClass::disconnect() -{ - return true; -} - -bool StationClass::isConnected() -{ - return true; -} - -bool StationClass::isConnectionFailed() -{ - return false; -} - -bool StationClass::isEnabledDHCP() -{ - return true; -} - -void StationClass::enableDHCP(bool enable) -{ -} - -void StationClass::setHostname(const String& hostname) -{ -} - -String StationClass::getHostname() -{ - return nullptr; -} - -IPAddress StationClass::getIP() -{ - struct ip_info info = {0}; - wifi_get_ip_info(STATION_IF, &info); - return info.ip; -} - -String StationClass::getMAC(char sep) -{ - uint8 hwaddr[6]; - if(wifi_get_macaddr(STATION_IF, hwaddr)) { - return makeHexString(hwaddr, sizeof(hwaddr), sep); - } else { - return nullptr; - } -} - -IPAddress StationClass::getNetworkBroadcast() -{ - struct ip_info info = {0}; - wifi_get_ip_info(STATION_IF, &info); - return (info.ip.addr | ~info.netmask.addr); -} - -IPAddress StationClass::getNetworkMask() -{ - struct ip_info info = {0}; - wifi_get_ip_info(STATION_IF, &info); - return info.netmask; -} - -IPAddress StationClass::getNetworkGateway() -{ - struct ip_info info = {0}; - wifi_get_ip_info(STATION_IF, &info); - return info.gw; -} - -bool StationClass::setIP(IPAddress address) -{ - return false; -} - -bool StationClass::setIP(IPAddress address, IPAddress netmask, IPAddress gateway) -{ - return false; -} - -String StationClass::getSSID() -{ - return nullptr; -} - -int8_t StationClass::getRssi() -{ - return -120; -} - -uint8_t StationClass::getChannel() -{ - return 0; -} - -String StationClass::getPassword() -{ - return nullptr; -} - -EStationConnectionStatus StationClass::getConnectionStatus() -{ - return eSCS_GotIP; -} - -bool StationClass::startScan(ScanCompletedDelegate scanCompleted) -{ - scanCompletedCallback = scanCompleted; - if(!scanCompleted) { - return false; - } - - host_queue_callback( - [](uint32_t param) { - auto self = reinterpret_cast(param); - BssList list; - BssInfo info(nullptr); - info.ssid = "Dummy SSID"; - info.channel = 1; - info.rssi = -50; - info.hidden = false; - info.authorization = AUTH_OPEN; - wifi_get_macaddr(STATION_IF, info.bssid); - list.add(info); - self->scanCompletedCallback(true, list); - }, - uint32_t(this)); - - return true; -} - -void StationClass::onSystemReady() -{ -} - -const char* StationClass::getConnectionStatusName() -{ - switch(getConnectionStatus()) { - case eSCS_Idle: - return "Idle"; - case eSCS_Connecting: - return "Connecting"; - case eSCS_WrongPassword: - return "Wrong password"; - case eSCS_AccessPointNotFound: - return "Access point not found"; - case eSCS_ConnectionFailed: - return "Connection failed"; - case eSCS_GotIP: - return "Successful connected"; - default: - SYSTEM_ERROR("Unknown status: %d", getConnectionStatus()); - return ""; - }; -} - -void StationClass::smartConfigStart(SmartConfigType sctype, SmartConfigDelegate callback) -{ -} - -void StationClass::smartConfigStop() -{ -} - -#ifdef ENABLE_WPS -void StationClass::internalWpsConfig(wps_cb_status status) -{ -} - -bool StationClass::wpsConfigStart(WPSConfigDelegate callback) -{ - return false; -} - -bool StationClass::beginWPSConfig() -{ - debugf("StationClass::beginWPSConfig()\n"); - return (wpsConfigStart()); -} - -void StationClass::wpsConfigStop() -{ -} -#endif - -//////////// - -BssInfo::BssInfo(bss_info* info) -{ -} - -const char* BssInfo::getAuthorizationMethodName() -{ - switch(authorization) { - case AUTH_OPEN: - return "OPEN"; - case AUTH_WEP: - return "WEP"; - case AUTH_WPA_PSK: - return "WPA_PSK"; - case AUTH_WPA2_PSK: - return "WPA2_PSK"; - case AUTH_WPA_WPA2_PSK: - return "WPA_WPA2_PSK"; - default: - SYSTEM_ERROR("Unknown auth: %d", authorization); - return ""; - } -} - -uint32_t BssInfo::getHashId() -{ - uint32_t a = bssid[4] | (bssid[5] << 8); - uint32_t b = bssid[0] | (bssid[1] << 8) | (bssid[2] << 16) | (bssid[3] << 24); - return a ^ b; -} diff --git a/Sming/Arch/Host/Platform/StationImpl.cpp b/Sming/Arch/Host/Platform/StationImpl.cpp new file mode 100644 index 0000000000..d4348fa98f --- /dev/null +++ b/Sming/Arch/Host/Platform/StationImpl.cpp @@ -0,0 +1,368 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/SmingHub/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + * + * StationImpl.cpp + * + ****/ + +#include "StationImpl.h" +#include "WifiEventsImpl.h" +#include +#include + +StationImpl station; +StationClass& WifiStation = station; + +static StationImpl::ApInfo apInfoList[] = { + { + .ssid = "Host WiFi", + .bssid = {}, + .authMode = AUTH_OPEN, + .channel = 1, + .hidden = false, + }, + { + .ssid = "Private WiFi", + .bssid = {}, + .authMode = AUTH_WPA2_PSK, + .channel = 8, + .hidden = false, + .pwd = "pass", + }, + { + .ssid = "George's Cafe", + .bssid = {}, + .authMode = AUTH_OPEN, + .channel = 5, + .hidden = false, + }, + { + .ssid = "Dentist", + .bssid = {}, + .authMode = AUTH_WPA_WPA2_PSK, + .channel = 11, + .hidden = false, + .pwd = "fillings", + }, + { + .ssid = "Can you see me", + .bssid = {}, + .authMode = AUTH_WPA_PSK, + .channel = 6, + .hidden = true, + .pwd = "secret", + }, +}; + +// Called directly from startup code +void host_wifi_lwip_init_complete(void) +{ + station.initialise(netif_default); +} + +static int getRandomRssi() +{ + return int(os_random() % 50) - 90; +} + +class BssInfoImpl : public BssInfo +{ +public: + explicit BssInfoImpl(const StationImpl::ApInfo& info) + { + ssid = info.ssid; + authorization = info.authMode; + channel = info.channel; + rssi = getRandomRssi(); + hidden = info.hidden; + } +}; + +StationImpl::StationImpl() : currentAp(&apInfoList[0]), savedAp(&apInfoList[0]) +{ +} + +void StationImpl::initialise(netif* nif) +{ + if(nif == nullptr) { + connectionStatus = eSCS_AccessPointNotFound; + return; + } + + auto netif_callback = [](netif* nif) { + host_queue_callback([](uint32_t param) { station.statusCallback(reinterpret_cast(param)); }, + uint32_t(nif)); + }; + + netif_set_status_callback(nif, netif_callback); + + netif_set_up(nif); +#if LWIP_IPV6 + netif_create_ip6_linklocal_address(&nif, 1); +#endif + + if(ip4_addr_isany_val(nif->ip_addr)) { + connectionStatus = eSCS_Connecting; + dhcp_start(nif); + } +} + +void StationImpl::statusCallback(netif* nif) +{ + if(nif == nullptr) { + if(currentAp != nullptr) { + wifiEventsImpl.stationDisconnected(*currentAp, WIFI_DISCONNECT_REASON_CONNECTION_FAIL); + } + return; + } + + static uint32_t prev_flags; + + hostmsg("NETIF 0x%08x -> 0x%08x", prev_flags, nif->flags); + + uint32_t changed_flags = prev_flags ^ nif->flags; + prev_flags = nif->flags; + + if(changed_flags & NETIF_FLAG_UP) { + assert(currentAp != nullptr); + if(nif->flags & NETIF_FLAG_UP) { + wifiEventsImpl.stationConnected(*currentAp); + } else { + wifiEventsImpl.stationDisconnected(*currentAp, WIFI_DISCONNECT_REASON_CONNECTION_FAIL); + } + } + + if((nif->flags & NETIF_FLAG_UP) && !ip4_addr_isany_val(nif->ip_addr)) { + connectionStatus = eSCS_GotIP; + wifiEventsImpl.stationGotIp(nif->ip_addr, nif->netmask, nif->gw); + } else { + connectionStatus = eSCS_ConnectionFailed; + } +} + +void StationImpl::enable(bool enabled, bool save) +{ + if(save) { + savedConfig.enabled = enabled; + } else { + currentConfig.enabled = enabled; + } +} + +bool StationImpl::isEnabled() const +{ + return currentConfig.enabled; +} + +bool StationImpl::config(const String& ssid, const String& password, bool autoConnectOnStartup, bool save) +{ + for(auto& ap : apInfoList) { + if(ssid == ap.ssid) { + if(ap.authMode != AUTH_OPEN) { + if(password != ap.pwd) { + debug_w("Bad password for '%s'", ssid.c_str()); + return false; + } + } + + currentAp = ≈ + if(save) { + savedAp = ≈ + } + + debug_i("Connected to SSID '%s'", ssid.c_str()); + + autoConnect = autoConnectOnStartup; + return true; + } + } + + debug_w("SSID '%s' not found", ssid.c_str()); + return false; +} + +bool StationImpl::connect() +{ + netif* nif = netif_default; + + if(nif == nullptr) { + return false; + } + + netif_set_link_up(nif); + return true; +} + +bool StationImpl::disconnect() +{ + netif* nif = netif_default; + + if(nif == nullptr) { + return false; + } + + netif_set_link_down(nif); + return true; +} + +bool StationImpl::isEnabledDHCP() const +{ + return dhcpEnabled; +} + +void StationImpl::enableDHCP(bool enable) +{ + netif* nif = netif_default; + if(nif != nullptr) { + if(enable && !dhcpEnabled) { + dhcp_start(nif); + } else if(!enable && dhcpEnabled) { + dhcp_stop(nif); + } + } + dhcpEnabled = enable; +} + +void StationImpl::setHostname(const String& hostname) +{ + this->hostName = hostname; +} + +String StationImpl::getHostname() const +{ + return hostName; +} + +IPAddress StationImpl::getIP() const +{ + netif* nif = netif_default; + + return nif ? nif->ip_addr.addr : IPADDR_NONE; +} + +MACAddress StationImpl::getMacAddr() const +{ + netif* nif = netif_default; + + if(nif == nullptr) { + return MACADDR_NONE; + } else { + return nif->hwaddr; + } +} + +IPAddress StationImpl::getNetworkBroadcast() const +{ + netif* nif = netif_default; + + if(nif == nullptr) { + return INADDR_NONE; + } else { + return nif->ip_addr.addr | ~nif->netmask.addr; + } +} + +IPAddress StationImpl::getNetworkMask() const +{ + netif* nif = netif_default; + + return nif ? nif->netmask : INADDR_NONE; +} + +IPAddress StationImpl::getNetworkGateway() const +{ + netif* nif = netif_default; + + return nif ? nif->gw : INADDR_NONE; +} + +bool StationImpl::setIP(IPAddress address, IPAddress netmask, IPAddress gateway) +{ + netif* nif = netif_default; + + if(nif == nullptr) { + return false; + } + + netif_set_ipaddr(nif, address); + netif_set_netmask(nif, netmask); + netif_set_gw(nif, gateway); + return true; +} + +String StationImpl::getSSID() const +{ + return currentAp ? currentAp->ssid : nullptr; +} + +int8_t StationImpl::getRssi() const +{ + return getRandomRssi(); +} + +uint8_t StationImpl::getChannel() const +{ + return currentAp ? currentAp->channel : 0; +} + +String StationImpl::getPassword() const +{ + return currentAp ? currentAp->pwd : nullptr; +} + +StationConnectionStatus StationImpl::getConnectionStatus() const +{ + return connectionStatus; +} + +bool StationImpl::startScan(ScanCompletedDelegate scanCompleted) +{ + scanCompletedCallback = scanCompleted; + if(!scanCompleted) { + return false; + } + + host_queue_callback( + [](uint32_t param) { + auto self = reinterpret_cast(param); + BssList list; + for(const auto& info : apInfoList) { + list.addElement(new BssInfoImpl(info)); + } + self->scanCompletedCallback(true, list); + }, + uint32_t(this)); + + return true; +} + +#ifdef ENABLE_SMART_CONFIG + +bool StationImpl::smartConfigStart(SmartConfigType sctype, SmartConfigDelegate callback) +{ + debug_e("SmartConfig not supported"); + return false; +} + +void StationImpl::smartConfigStop() +{ +} + +#endif // ENABLE_SMART_CONFIG + +#ifdef ENABLE_WPS + +bool StationImpl::wpsConfigStart(WPSConfigDelegate callback) +{ + debug_e("WPS not supported"); + return false; +} + +void StationImpl::wpsConfigStop() +{ +} + +#endif // ENABLE_WPS diff --git a/Sming/Arch/Host/Platform/StationImpl.h b/Sming/Arch/Host/Platform/StationImpl.h new file mode 100644 index 0000000000..06d134d2b2 --- /dev/null +++ b/Sming/Arch/Host/Platform/StationImpl.h @@ -0,0 +1,86 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/SmingHub/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + * + * StationImpl.h - Host WiFi Station + * + ****/ + +#pragma once + +#include + +struct netif; + +class StationImpl : public StationClass +{ +public: + struct ApInfo { + const char* ssid; + MACAddress bssid; + WifiAuthMode authMode; + uint8_t channel; + bool hidden; + const char* pwd; + }; + + StationImpl(); + void initialise(netif* nif); + const ApInfo* getApInfo() + { + return currentAp; + } + + // StationClass + void enable(bool enabled, bool save) override; + bool isEnabled() const override; + bool config(const String& ssid, const String& password, bool autoConnectOnStartup, bool save) override; + bool connect() override; + bool disconnect() override; + StationConnectionStatus getConnectionStatus() const override; + bool isEnabledDHCP() const override; + void enableDHCP(bool enable) override; + void setHostname(const String& hostname) override; + String getHostname() const override; + IPAddress getIP() const override; + MACAddress getMacAddr() const override; + IPAddress getNetworkMask() const override; + IPAddress getNetworkGateway() const override; + IPAddress getNetworkBroadcast() const override; + bool setIP(IPAddress address, IPAddress netmask, IPAddress gateway) override; + String getSSID() const override; + String getPassword() const override; + int8_t getRssi() const override; + uint8_t getChannel() const override; + bool startScan(ScanCompletedDelegate scanCompleted) override; + +#ifdef ENABLE_SMART_CONFIG + bool smartConfigStart(SmartConfigType sctype, SmartConfigDelegate callback) override; + void smartConfigStop() override; +#endif + +#ifdef ENABLE_WPS + bool wpsConfigStart(WPSConfigDelegate callback) override; + void wpsConfigStop() override; +#endif + +private: + void statusCallback(netif* nif); + +private: + ApInfo* currentAp; + ApInfo* savedAp; + + struct StationConfig { + bool enabled = true; + }; + StationConfig currentConfig; + StationConfig savedConfig; + bool autoConnect = true; + bool connected = true; + String hostName; + StationConnectionStatus connectionStatus = eSCS_Idle; + bool dhcpEnabled = true; +}; diff --git a/Sming/Arch/Host/Platform/WifiEvents.cpp b/Sming/Arch/Host/Platform/WifiEvents.cpp deleted file mode 100644 index 3198f3baf5..0000000000 --- a/Sming/Arch/Host/Platform/WifiEvents.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**** - * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. - * Created 2015 by Skurydin Alexey - * http://github.com/SmingHub/Sming - * All files of the Sming Core are provided under the LGPL v3 license. - * - * WifiEvents.cpp - * - */ - -#include -#include "Platform/WifiEvents.h" -#include -#include - -WifiEventsClass WifiEvents; - -void WifiEventHandler(System_Event_t* evt); - -WifiEventsClass::WifiEventsClass() -{ - wifi_set_event_handler_cb([](System_Event_t* evt) { WifiEvents.WifiEventHandler(evt); }); -} - -#ifndef SMING_RELEASE -static String macToStr(const uint8_t mac[]) -{ - return makeHexString(mac, 6, ':'); -} -#endif - -void WifiEventsClass::WifiEventHandler(System_Event_t* evt) -{ - switch(evt->event) { - case EVENT_STAMODE_CONNECTED: - debugf("connect to ssid %s, channel %d", evt->event_info.connected.ssid, evt->event_info.connected.channel); - if(onSTAConnect) { - onSTAConnect((const char*)evt->event_info.connected.ssid, evt->event_info.connected.ssid_len, - evt->event_info.connected.bssid, evt->event_info.connected.channel); - } - break; - case EVENT_STAMODE_DISCONNECTED: - debugf("disconnect from ssid %s, reason %d", evt->event_info.disconnected.ssid, - evt->event_info.disconnected.reason); - if(onSTADisconnect) { - onSTADisconnect((const char*)evt->event_info.disconnected.ssid, evt->event_info.disconnected.ssid_len, - evt->event_info.disconnected.bssid, evt->event_info.disconnected.reason); - } - break; - case EVENT_STAMODE_AUTHMODE_CHANGE: - debugf("mode: %d -> %d", evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode); - if(onSTAAuthModeChange) { - onSTAAuthModeChange(evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode); - } - break; - case EVENT_STAMODE_GOT_IP: { - IPAddress ip(evt->event_info.got_ip.ip); - IPAddress mask(evt->event_info.got_ip.mask); - IPAddress gw(evt->event_info.got_ip.gw); - debugf("ip: %s, mask: %s, gw: %s", ip.toString().c_str(), mask.toString().c_str(), gw.toString().c_str()); - if(onSTAGotIP) { - onSTAGotIP(ip, mask, gw); - } - break; - } - case EVENT_SOFTAPMODE_STACONNECTED: - debugf("station: %s join, AID = %d", macToStr(evt->event_info.sta_connected.mac).c_str(), - evt->event_info.sta_connected.aid); - if(onSOFTAPConnect) { - onSOFTAPConnect(evt->event_info.sta_connected.mac, evt->event_info.sta_connected.aid); - } - break; - case EVENT_SOFTAPMODE_STADISCONNECTED: - debugf("station: %s leave, AID = %d", macToStr(evt->event_info.sta_disconnected.mac), - evt->event_info.sta_disconnected.aid); - if(onSOFTAPDisconnect) { - onSOFTAPDisconnect(evt->event_info.sta_disconnected.mac, evt->event_info.sta_disconnected.aid); - } - break; - case EVENT_SOFTAPMODE_PROBEREQRECVED: - if(onSOFTAPProbeReqRecved) { - onSOFTAPProbeReqRecved(evt->event_info.ap_probereqrecved.rssi, evt->event_info.ap_probereqrecved.mac); - } - break; - default: - break; - } -} diff --git a/Sming/Arch/Host/Platform/WifiEventsImpl.cpp b/Sming/Arch/Host/Platform/WifiEventsImpl.cpp new file mode 100644 index 0000000000..33af51aea0 --- /dev/null +++ b/Sming/Arch/Host/Platform/WifiEventsImpl.cpp @@ -0,0 +1,15 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/SmingHub/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + * + * WifiEventsImpl.cpp + * + */ + +#include "WifiEventsImpl.h" +#include "StationImpl.h" + +WifiEventsImpl wifiEventsImpl; +WifiEventsClass& WifiEvents = wifiEventsImpl; diff --git a/Sming/Arch/Host/Platform/WifiEventsImpl.h b/Sming/Arch/Host/Platform/WifiEventsImpl.h new file mode 100644 index 0000000000..54723ae9c5 --- /dev/null +++ b/Sming/Arch/Host/Platform/WifiEventsImpl.h @@ -0,0 +1,41 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/SmingHub/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + * + * WifiEventsImpl.h - Host WiFi events + * + ****/ + +#pragma once + +#include "Platform/WifiEvents.h" +#include "StationImpl.h" + +class WifiEventsImpl : public WifiEventsClass +{ +public: + void stationConnected(const StationImpl::ApInfo& ap) + { + if(onSTAConnect) { + onSTAConnect(ap.ssid, ap.bssid, ap.channel); + } + } + + void stationDisconnected(const StationImpl::ApInfo& ap, WifiDisconnectReason reason) + { + if(onSTADisconnect) { + onSTADisconnect(ap.ssid, ap.bssid, reason); + } + } + + void stationGotIp(ip_addr_t ip, ip_addr_t netmask, ip_addr_t gw) + { + if(onSTAGotIP) { + onSTAGotIP(ip, netmask, gw); + } + } +}; + +extern WifiEventsImpl wifiEventsImpl;