From dac80a87a452b74ad81bb25e48a56c53a861d4c4 Mon Sep 17 00:00:00 2001 From: Sarvesh Bodakhe Date: Tue, 11 Feb 2025 10:14:28 +0530 Subject: [PATCH] fix(wifi): Add some wifi bugfixes and features 1. Fix issue of increased stack usage when failure_retry_cnt is set and wifi driver internally retries connection attempts 2. Add WIFI_EVENT_AP_WRONG_PASSWORD in SoftAP. This event is triggered when external station tries connecting to softAP with wrong password. Current supported softAP AUTH modes: WPA-PSK, WPA2-PSK and WPA3-PSK (SAE-auth) --- components/esp_wifi/include/esp_wifi_types_generic.h | 7 +++++++ components/esp_wifi/lib | 2 +- components/wpa_supplicant/src/ap/ieee802_11.c | 4 ++++ components/wpa_supplicant/src/ap/wpa_auth.c | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/esp_wifi/include/esp_wifi_types_generic.h b/components/esp_wifi/include/esp_wifi_types_generic.h index 8deae4b561..8c88cf1c1f 100644 --- a/components/esp_wifi/include/esp_wifi_types_generic.h +++ b/components/esp_wifi/include/esp_wifi_types_generic.h @@ -910,6 +910,8 @@ typedef enum { WIFI_EVENT_STA_NEIGHBOR_REP, /**< Received Neighbor Report response */ + WIFI_EVENT_AP_WRONG_PASSWORD, /**< a station tried to connect with wrong password */ + WIFI_EVENT_MAX, /**< Invalid Wi-Fi event ID */ } wifi_event_t; @@ -1211,6 +1213,11 @@ typedef enum { WIFI_BAND_2G_5G = 3, /* Band is 2,4G + 5G */ } wifi_band_t; +/** Argument structure for WIFI_EVENT_AP_WRONG_PASSWORD event */ +typedef struct { + uint8_t mac[6]; /**< MAC address of the station trying to connect to Soft-AP */ +} wifi_event_ap_wrong_password_t; + /** * @brief Argument structure for wifi_tx_rate_config */ diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index fe3a9b95e4..a990dfc15c 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit fe3a9b95e4236a62e9a09bf7407f242469479b7c +Subproject commit a990dfc15caac96a2f515ddfe8487566685313cc diff --git a/components/wpa_supplicant/src/ap/ieee802_11.c b/components/wpa_supplicant/src/ap/ieee802_11.c index f47a9b86cc..622d18fbea 100644 --- a/components/wpa_supplicant/src/ap/ieee802_11.c +++ b/components/wpa_supplicant/src/ap/ieee802_11.c @@ -625,6 +625,10 @@ int handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta, if (sae_check_confirm(sta->sae, buf, len) < 0) { resp = WLAN_STATUS_CHALLENGE_FAIL; + wifi_event_ap_wrong_password_t evt = {0}; + os_memcpy(evt.mac, bssid, ETH_ALEN); + esp_event_post(WIFI_EVENT, WIFI_EVENT_AP_WRONG_PASSWORD, &evt, + sizeof(evt), 0); goto reply; } sta->sae->rc = peer_send_confirm; diff --git a/components/wpa_supplicant/src/ap/wpa_auth.c b/components/wpa_supplicant/src/ap/wpa_auth.c index 58748a85ff..18a5069fb3 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth.c +++ b/components/wpa_supplicant/src/ap/wpa_auth.c @@ -1668,6 +1668,10 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING) if (!ok) { wpa_printf(MSG_INFO, "invalid MIC in msg 2/4 of 4-Way Handshake"); + wifi_event_ap_wrong_password_t evt = {0}; + os_memcpy(evt.mac, sm->addr, ETH_ALEN); + esp_event_post(WIFI_EVENT, WIFI_EVENT_AP_WRONG_PASSWORD, &evt, + sizeof(evt), 0); return; }