From dff32e89027b3967857bfdd18967272dc14c2237 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Wed, 28 Jul 2021 19:09:19 +1000 Subject: [PATCH] WiFi module updates. - Added support for WPA3 - Evicted left-over broken WiFi auto-reconnect - Updated docs --- components/modules/wifi.c | 4 ++++ components/modules/wifi_sta.c | 20 ++++++++++++++++---- docs/modules/wifi.md | 18 ++++++++++++------ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/components/modules/wifi.c b/components/modules/wifi.c index 0a6f45a0..343b1884 100644 --- a/components/modules/wifi.c +++ b/components/modules/wifi.c @@ -132,6 +132,10 @@ LROT_BEGIN(wifi) LROT_NUMENTRY ( AUTH_WPA_PSK, WIFI_AUTH_WPA_PSK ) LROT_NUMENTRY ( AUTH_WPA2_PSK, WIFI_AUTH_WPA2_PSK ) LROT_NUMENTRY ( AUTH_WPA_WPA2_PSK, WIFI_AUTH_WPA_WPA2_PSK ) + LROT_NUMENTRY ( AUTH_WPA2_ENTERPRISE, WIFI_AUTH_WPA2_ENTERPRISE ) + LROT_NUMENTRY ( AUTH_WPA3_PSK, WIFI_AUTH_WPA3_PSK ) + LROT_NUMENTRY ( AUTH_WPA2_WPA3_PSK, WIFI_AUTH_WPA2_WPA3_PSK ) + LROT_NUMENTRY ( AUTH_WAPI_PSK, WIFI_AUTH_WAPI_PSK ) LROT_NUMENTRY ( STR_WIFI_SECOND_CHAN_NONE, WIFI_SECOND_CHAN_NONE ) LROT_NUMENTRY ( STR_WIFI_SECOND_CHAN_ABOVE, WIFI_SECOND_CHAN_ABOVE ) diff --git a/components/modules/wifi_sta.c b/components/modules/wifi_sta.c index f0dd972d..1fcaabc4 100644 --- a/components/modules/wifi_sta.c +++ b/components/modules/wifi_sta.c @@ -280,6 +280,18 @@ static int wifi_sta_config (lua_State *L) return luaL_error (L, "invalid BSSID: %s", bssid); } + lua_getfield(L, 1, "pmf"); + if (lua_isnumber(L, -1)) + { + int pmf_mode = lua_tointeger(L, -1); + if (pmf_mode) + cfg.sta.pmf_cfg.capable = true; + if (pmf_mode == 2) + cfg.sta.pmf_cfg.required = true; + } + else + cfg.sta.pmf_cfg.capable = true; + SET_SAVE_MODE(save); esp_err_t err = esp_wifi_set_config (WIFI_IF_STA, &cfg); if (err != ESP_OK) @@ -446,10 +458,10 @@ LROT_PUBLIC_BEGIN(wifi_sta) LROT_FUNCENTRY( getmac, wifi_sta_getmac ) LROT_FUNCENTRY( on, wifi_sta_on ) LROT_FUNCENTRY( scan, wifi_sta_scan ) + + LROT_NUMENTRY( PMF_OFF, 0 ) + LROT_NUMENTRY( PMF_AVAILABLE, 1 ) + LROT_NUMENTRY( PMF_REQUIRED, 2 ) LROT_END(wifi_sta, NULL, 0) - -// Currently no auto-connect, so do that in response to events -NODEMCU_ESP_EVENT(WIFI_EVENT, WIFI_EVENT_STA_START, do_connect); -NODEMCU_ESP_EVENT(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, do_connect); NODEMCU_ESP_EVENT(WIFI_EVENT, WIFI_EVENT_SCAN_DONE, on_scan_done); diff --git a/docs/modules/wifi.md b/docs/modules/wifi.md index 8eb1e9be..70860feb 100644 --- a/docs/modules/wifi.md +++ b/docs/modules/wifi.md @@ -147,6 +147,13 @@ being removed in the SDK/IDF. After start-up it is necessary to call - "AC-1D-1C-B1-0B-22" - "DE AD BE EF 7A C0" - "AcDc0123c0DE" + - `pmf` an optional setting to control whether Protected Management Frames + are supported and/or required. One of: + - `wifi.sta.PMF_OFF` + - `wifi.sta.PMF_AVAILABLE` + - `wifi.sta.PMF_REQUIRED`. + Defaults to `wifi.sta.PMF_AVAILABLE`. PMF is required when joining to + WPA3-Personal access points. - `save` Save station configuration to flash. - `true` configuration **will** be retained through power cycle. @@ -186,10 +193,8 @@ wifi.sta.config(station_cfg) ## wifi.sta.connect() Connects to the configured AP in station mode. You will want to call this -on start-up after [`wifi.start()`](#wifistart). The system will attempt -to connect until it succeeds or [`wifi.sta.disconnect()`](#wifistadisconnect) -is called. Each failed connect attempt will fire the `disconnected` -event. +on start-up after [`wifi.start()`](#wifistart), and quite possibly also +in response to `disconnected` events. #### Syntax `wifi.sta.connect()` @@ -203,6 +208,7 @@ event. #### See also - [`wifi.sta.disconnect()`](#wifistadisconnect) - [`wifi.sta.config()`](#wifistaconfig) +- [`wifi.sta.on()`](#wifistaon) ## wifi.sta.disconnect() @@ -255,7 +261,7 @@ Event information provided for each event is as follows: - `ssid`: the SSID of the network - `bssid`: the BSSID of the AP - `channel`: the primary channel of the network - - `auth` authentication method, one of `wifi.OPEN`, `wifi.WPA_PSK`, `wifi.WPA2_PSK` (default), `wifi.WPA_WPA2_PSK` + - `auth` authentication method, one of `wifi.AUTH_OPEN`, `wifi.AUTH_WPA_PSK`, `wifi.AUTH_WPA2_PSK`, `wifi.WPA_WPA2_PSK`, `wifi.AUTH_WPA3_PSK`, `wifi.AUTH_WAPI_PSK` - `disconnected`: information about the network/AP that was disconnected from: - `ssid`: the SSID of the network - `bssid`: the BSSID of the AP @@ -347,7 +353,7 @@ The following fields are provided for each scanned AP: - `bssid`: the BSSID of the AP - `channel`: primary WiFi channel of the AP - `rssi`: Received Signal Strength Indicator value -- `auth` authentication method, one of `wifi.OPEN`, `wifi.WPA_PSK`, `wifi.WPA2_PSK` (default), `wifi.WPA_WPA2_PSK` +- `auth` authentication method, one of `wifi.AUTH_OPEN`, `wifi.AUTH_WPA_PSK`, `wifi.AUTH_WPA2_PSK`, `wifi.AUTH_WPA_WPA2_PSK`, `wifi.AUTH_WPA2_ENTERPRISE`, `wifi.AUTH_WPA2_WPA3_PSK`, `wifi.AUTH_WPA3_PSK`, `wifi.AUTH_WAPI_PSK` - `bandwidth`: one of the following constants: - `wifi.HT20` - `wifi.HT40_ABOVE`