fix(wifi) : Resetting current bssid for every roaming connection intiated

- Bssid reset after btm or legacy roam
     - Making few changes in CMake for wpa_supplicant and esp_wifi
This commit is contained in:
tarun.kumar
2025-09-16 21:38:38 +05:30
committed by BOT
parent 0f3034586b
commit fdda62267e
5 changed files with 27 additions and 8 deletions

View File

@@ -63,7 +63,7 @@ idf_component_register(SRCS "${srcs}"
PRIV_REQUIRES esp_pm esp_timer nvs_flash PRIV_REQUIRES esp_pm esp_timer nvs_flash
wpa_supplicant hal lwip esp_coex wpa_supplicant hal lwip esp_coex
PRIV_INCLUDE_DIRS ../wpa_supplicant/src/ ../wpa_supplicant/esp_supplicant/src/ PRIV_INCLUDE_DIRS ../wpa_supplicant/src/ ../wpa_supplicant/esp_supplicant/src/
wifi_apps/roaming_app/include wifi_apps/roaming_app/include wifi_apps/roaming_app/src
LDFRAGMENTS "${ldfragments}") LDFRAGMENTS "${ldfragments}")
if(CONFIG_ESP_WIFI_ENABLED OR CONFIG_ESP_HOST_WIFI_ENABLED) if(CONFIG_ESP_WIFI_ENABLED OR CONFIG_ESP_HOST_WIFI_ENABLED)

View File

@@ -37,6 +37,10 @@ void roam_sta_disconnected(void *disconn);
esp_err_t roam_get_config_params(struct roam_config *config); esp_err_t roam_get_config_params(struct roam_config *config);
esp_err_t roam_set_config_params(struct roam_config *config); esp_err_t roam_set_config_params(struct roam_config *config);
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
void esp_wifi_roaming_set_current_bssid(const uint8_t *bssid);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -57,6 +57,13 @@ static void roaming_app_periodic_scan_internal_handler(void *data, void *ctx);
static const char *ROAMING_TAG = "ROAM"; static const char *ROAMING_TAG = "ROAM";
void esp_wifi_roaming_set_current_bssid(const uint8_t *bssid)
{
if (bssid) {
memcpy(g_roaming_app.current_bss.ap.bssid, bssid, ETH_ALEN);
}
}
static inline long time_diff_sec(struct timeval *a, struct timeval *b) static inline long time_diff_sec(struct timeval *a, struct timeval *b)
{ {
return (a->tv_sec - b->tv_sec); return (a->tv_sec - b->tv_sec);
@@ -183,7 +190,11 @@ static void roaming_app_disconnected_event_handler(void *ctx, void *data)
#endif /*PERIODIC_SCAN_MONITORING*/ #endif /*PERIODIC_SCAN_MONITORING*/
wifi_event_sta_disconnected_t *disconn = data; wifi_event_sta_disconnected_t *disconn = data;
ESP_LOGD(ROAMING_TAG, "station got disconnected reason=%d", disconn->reason); #define RSSI_INVALID -128
g_roaming_app.current_bss.ap.rssi = RSSI_INVALID;
#undef RSSI_INVALID
ESP_LOGD(ROAMING_TAG, "station got disconnected reason=%d, rssi =%d", disconn->reason, disconn->rssi);
#if CONFIG_ESP_WIFI_ROAMING_AUTO_BLACKLISTING #if CONFIG_ESP_WIFI_ROAMING_AUTO_BLACKLISTING
if (disconn->reason == WIFI_REASON_CONNECTION_FAIL || disconn->reason == WIFI_REASON_AUTH_FAIL) { if (disconn->reason == WIFI_REASON_CONNECTION_FAIL || disconn->reason == WIFI_REASON_AUTH_FAIL) {
bool found = false; bool found = false;
@@ -498,6 +509,7 @@ static void trigger_legacy_roam(struct cand_bss *bss)
wifi_cfg.sta.bssid_set = true; wifi_cfg.sta.bssid_set = true;
os_memcpy(wifi_cfg.sta.bssid, bss->bssid, ETH_ALEN); os_memcpy(wifi_cfg.sta.bssid, bss->bssid, ETH_ALEN);
esp_wifi_internal_issue_disconnect(WIFI_REASON_BSS_TRANSITION_DISASSOC); esp_wifi_internal_issue_disconnect(WIFI_REASON_BSS_TRANSITION_DISASSOC);
esp_wifi_roaming_set_current_bssid(bss->bssid);
esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg); esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg);
esp_wifi_connect(); esp_wifi_connect();
ESP_LOGI(ROAMING_TAG, "Disconnecting and connecting to "MACSTR" on account of better rssi",MAC2STR(bss->bssid)); ESP_LOGI(ROAMING_TAG, "Disconnecting and connecting to "MACSTR" on account of better rssi",MAC2STR(bss->bssid));
@@ -710,19 +722,17 @@ static void parse_scan_results_and_roam(void)
int8_t rssi_diff = 0; int8_t rssi_diff = 0;
uint8_t i; uint8_t i;
int8_t best_ap_index = -1; int8_t best_ap_index = -1;
wifi_ap_record_t ap_info;
roaming_app_get_ap_info(&ap_info);
for (i = 0; i < g_roaming_app.scanned_aps.current_count; i++) { for (i = 0; i < g_roaming_app.scanned_aps.current_count; i++) {
if (is_bssid_blacklisted(g_roaming_app.scanned_aps.ap_records[i].bssid)) { if (is_bssid_blacklisted(g_roaming_app.scanned_aps.ap_records[i].bssid)) {
ESP_LOGD(ROAMING_TAG, "BSSID " MACSTR " is blacklisted, skipping", MAC2STR(g_roaming_app.scanned_aps.ap_records[i].bssid)); ESP_LOGD(ROAMING_TAG, "BSSID " MACSTR " is blacklisted, skipping", MAC2STR(g_roaming_app.scanned_aps.ap_records[i].bssid));
continue; continue;
} }
rssi_diff = g_roaming_app.scanned_aps.ap_records[i].rssi - ap_info.rssi; rssi_diff = g_roaming_app.scanned_aps.ap_records[i].rssi - g_roaming_app.current_bss.ap.rssi;
ESP_LOGD(ROAMING_TAG, "The difference between ("MACSTR", "MACSTR") with rssi (%d,%d) is : %d while the threshold is %d and the best rssi diff yet is %d, thecand_auth is %d", ESP_LOGD(ROAMING_TAG, "The difference between ("MACSTR", "MACSTR") with rssi (%d,%d) is : %d while the threshold is %d and the best rssi diff yet is %d, thecand_auth is %d",
MAC2STR(g_roaming_app.scanned_aps.ap_records[i].bssid),MAC2STR(ap_info.bssid), MAC2STR(g_roaming_app.scanned_aps.ap_records[i].bssid),MAC2STR(g_roaming_app.current_bss.ap.bssid),
g_roaming_app.scanned_aps.ap_records[i].rssi, ap_info.rssi, g_roaming_app.scanned_aps.ap_records[i].rssi, g_roaming_app.current_bss.ap.rssi,
rssi_diff, rssi_threshold, best_rssi_diff, g_roaming_app.scanned_aps.ap_records[i].authmode); rssi_diff, rssi_threshold, best_rssi_diff, g_roaming_app.scanned_aps.ap_records[i].authmode);
if ((memcmp(g_roaming_app.scanned_aps.ap_records[i].bssid, ap_info.bssid, ETH_ALEN) != 0) && if ((memcmp(g_roaming_app.scanned_aps.ap_records[i].bssid, g_roaming_app.current_bss.ap.bssid, ETH_ALEN) != 0) &&
candidate_security_match(g_roaming_app.scanned_aps.ap_records[i]) && rssi_diff > best_rssi_diff ) { candidate_security_match(g_roaming_app.scanned_aps.ap_records[i]) && rssi_diff > best_rssi_diff ) {
best_rssi_diff = rssi_diff; best_rssi_diff = rssi_diff;
best_ap_index = i; best_ap_index = i;

View File

@@ -245,6 +245,7 @@ idf_component_register(SRCS "${srcs}" "${esp_srcs}" "${tls_src}" "${roaming_src}
INCLUDE_DIRS include port/include esp_supplicant/include INCLUDE_DIRS include port/include esp_supplicant/include
PRIV_INCLUDE_DIRS src src/utils esp_supplicant/src src/crypto PRIV_INCLUDE_DIRS src src/utils esp_supplicant/src src/crypto
../esp_wifi/wifi_apps/roaming_app/include ../esp_wifi/wifi_apps/roaming_app/include
../esp_wifi/wifi_apps/roaming_app/src
LDFRAGMENTS ${linker_fragments} LDFRAGMENTS ${linker_fragments}
PRIV_REQUIRES mbedtls esp_timer esp_wifi) PRIV_REQUIRES mbedtls esp_timer esp_wifi)

View File

@@ -24,6 +24,7 @@
#include "rsn_supp/wpa.h" #include "rsn_supp/wpa.h"
#include "esp_private/wifi.h" #include "esp_private/wifi.h"
#include "esp_wifi_types_generic.h" #include "esp_wifi_types_generic.h"
#include "esp_roaming.h"
/* Utility Functions */ /* Utility Functions */
esp_err_t esp_supplicant_str_to_mac(const char *str, uint8_t dest[6]) esp_err_t esp_supplicant_str_to_mac(const char *str, uint8_t dest[6])
@@ -633,6 +634,9 @@ void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
config->sta.channel = bss->channel; config->sta.channel = bss->channel;
/* supplicant connect will only be called in case of bss transition(roaming) */ /* supplicant connect will only be called in case of bss transition(roaming) */
esp_wifi_internal_issue_disconnect(WIFI_REASON_BSS_TRANSITION_DISASSOC); esp_wifi_internal_issue_disconnect(WIFI_REASON_BSS_TRANSITION_DISASSOC);
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
esp_wifi_roaming_set_current_bssid(bss->bssid);
#endif
esp_wifi_set_config(WIFI_IF_STA, config); esp_wifi_set_config(WIFI_IF_STA, config);
os_free(config); os_free(config);
esp_wifi_connect(); esp_wifi_connect();