From 84d7ab5c0c8d4574503828dde6a26492638af7eb Mon Sep 17 00:00:00 2001 From: jgujarathi Date: Fri, 29 Sep 2023 11:32:55 +0530 Subject: [PATCH] fix(wpa_supplicant): Clear bssid flag and channel in supplicant disconnect handler - Clear the bssid set flag and channel in supplicant disconnect handler as this can cause the station to recursively connect to the wrong AP in case roaming through BTM mechanisms fails. - Fix issue with incorrect blocking time calculation when blocking scan issued for a single channel. --- .../esp_supplicant/src/esp_common.c | 15 +++++++++++---- .../esp_supplicant/src/esp_common_i.h | 2 +- .../esp_supplicant/src/esp_wpa_main.c | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common.c b/components/wpa_supplicant/esp_supplicant/src/esp_common.c index 85809805f1..e6dac19a54 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common.c @@ -162,7 +162,7 @@ static void btm_rrm_task(void *pvParameters) } #endif /* CONFIG_SUPPLICANT_TASK */ -static void clear_bssid_flag(struct wpa_supplicant *wpa_s) +static void clear_bssid_flag_and_channel(struct wpa_supplicant *wpa_s) { wifi_config_t *config; @@ -178,7 +178,8 @@ static void clear_bssid_flag(struct wpa_supplicant *wpa_s) } esp_wifi_get_config(WIFI_IF_STA, config); - if (config->sta.bssid_set) { + if (config->sta.bssid_set || config->sta.channel) { + config->sta.channel = 0; config->sta.bssid_set = 0; esp_wifi_set_config(WIFI_IF_STA, config); } @@ -439,11 +440,11 @@ void supplicant_sta_conn_handler(uint8_t *bssid) /* Register for mgmt frames */ register_mgmt_frames(wpa_s); /* clear set bssid flag */ - clear_bssid_flag(wpa_s); + clear_bssid_flag_and_channel(wpa_s); #endif /* defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) */ } -void supplicant_sta_disconn_handler(void) +void supplicant_sta_disconn_handler(uint8_t reason_code) { #if defined(CONFIG_IEEE80211KV) || defined(CONFIG_IEEE80211R) struct wpa_supplicant *wpa_s = &g_wpa_supp; @@ -451,6 +452,12 @@ void supplicant_sta_disconn_handler(void) #ifdef CONFIG_IEEE80211KV wpas_rrm_reset(wpa_s); wpas_clear_beacon_rep_data(wpa_s); + /* Not clearing in case of roaming disconnect as BTM induced connection + * itself sets a specific bssid and channel to connect to before disconnection. + * Subsequent connections or disconnections will clear this flag */ + if (reason_code != WIFI_REASON_ROAMING) { + clear_bssid_flag_and_channel(wpa_s); + } #endif /* CONFIG_IEEE80211KV */ if (wpa_s->current_bss) { wpa_s->current_bss = NULL; diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h b/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h index e6c1d23290..3f4a439bbb 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common_i.h @@ -46,5 +46,5 @@ void esp_supplicant_unset_all_appie(void); void esp_set_scan_ie(void); void esp_set_assoc_ie(uint8_t *bssid, const u8 *ies, size_t ies_len, bool add_mdie); void supplicant_sta_conn_handler(uint8_t* bssid); -void supplicant_sta_disconn_handler(void); +void supplicant_sta_disconn_handler(uint8_t reason_code); #endif diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c index c977119922..acde48189b 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c @@ -301,7 +301,7 @@ static void wpa_sta_disconnected_cb(uint8_t reason_code) owe_deinit(); #endif /* CONFIG_OWE_STA */ - supplicant_sta_disconn_handler(); + supplicant_sta_disconn_handler(reason_code); } #ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT