Merge branch 'bugfix/roaming_app_issues_v5.4' into 'release/v5.4'

fix(wifi): Fix some issues observed in roaming app (v5.4)

See merge request espressif/esp-idf!37414
This commit is contained in:
Kapil Gupta
2025-04-11 19:34:05 +08:00
9 changed files with 433 additions and 215 deletions

View File

@@ -15,6 +15,9 @@
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE #ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#include "apps_private/wifi_apps_private.h" #include "apps_private/wifi_apps_private.h"
#endif #endif
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
#include "esp_roaming.h"
#endif
// //
// Purpose of this module is to provide basic wifi initialization setup for // Purpose of this module is to provide basic wifi initialization setup for
@@ -26,6 +29,9 @@ static esp_netif_t *s_wifi_netifs[MAX_WIFI_IFS] = { NULL };
static bool wifi_default_handlers_set = false; static bool wifi_default_handlers_set = false;
static esp_err_t disconnect_and_destroy(esp_netif_t* esp_netif); static esp_err_t disconnect_and_destroy(esp_netif_t* esp_netif);
#ifdef CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_IP_RENEW_SKIP
static bool roaming_ongoing = false;
#endif
// //
// Default event handlers // Default event handlers
@@ -77,6 +83,12 @@ static void wifi_default_action_sta_start(void *arg, esp_event_base_t base, int3
static void wifi_default_action_sta_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data) static void wifi_default_action_sta_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{ {
#ifdef CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
roam_disable_reconnect();
#ifdef CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_IP_RENEW_SKIP
roaming_ongoing = false;
#endif
#endif /* CONFIG_ESP_WIFI_ENABLE_ROAMING_APP */
if (s_wifi_netifs[WIFI_IF_STA] != NULL) { if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
esp_netif_action_stop(s_wifi_netifs[WIFI_IF_STA], base, event_id, data); esp_netif_action_stop(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
} }
@@ -84,6 +96,16 @@ static void wifi_default_action_sta_stop(void *arg, esp_event_base_t base, int32
static void wifi_default_action_sta_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data) static void wifi_default_action_sta_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{ {
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
roam_sta_connected();
#ifdef CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_IP_RENEW_SKIP
if (roaming_ongoing) {
/* IP stack is already in ready state */
roaming_ongoing = false;
return;
}
#endif
#endif
if (s_wifi_netifs[WIFI_IF_STA] != NULL) { if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
esp_err_t ret; esp_err_t ret;
esp_netif_t *esp_netif = s_wifi_netifs[WIFI_IF_STA]; esp_netif_t *esp_netif = s_wifi_netifs[WIFI_IF_STA];
@@ -103,6 +125,18 @@ static void wifi_default_action_sta_connected(void *arg, esp_event_base_t base,
static void wifi_default_action_sta_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data) static void wifi_default_action_sta_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{ {
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
roam_sta_disconnected(data);
#ifdef CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_IP_RENEW_SKIP
wifi_event_sta_disconnected_t *disconn = data;
if (disconn->reason == WIFI_REASON_ROAMING) {
roaming_ongoing = true;
/* do nothing else */
return;
}
roaming_ongoing = false;
#endif
#endif
if (s_wifi_netifs[WIFI_IF_STA] != NULL) { if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
esp_netif_action_disconnected(s_wifi_netifs[WIFI_IF_STA], base, event_id, data); esp_netif_action_disconnected(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
} }

View File

@@ -182,7 +182,7 @@ static esp_err_t wifi_deinit_internal(void)
esp_supplicant_deinit(); esp_supplicant_deinit();
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP #if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
deinit_roaming_app(); roam_deinit_app();
#endif #endif
err = esp_wifi_deinit_internal(); err = esp_wifi_deinit_internal();
@@ -447,7 +447,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
} }
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP #if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
init_roaming_app(); roam_init_app();
#endif #endif
} else { } else {
@@ -485,7 +485,7 @@ esp_err_t esp_wifi_connect(void)
ret = esp_wifi_connect_internal(); ret = esp_wifi_connect_internal();
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP #if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
roaming_app_enable_reconnect(); roam_enable_reconnect();
#endif #endif
return ret; return ret;
} }
@@ -493,11 +493,11 @@ esp_err_t esp_wifi_connect(void)
esp_err_t esp_wifi_disconnect(void) esp_err_t esp_wifi_disconnect(void)
{ {
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
roam_disable_reconnect();
#endif
ret = esp_wifi_disconnect_internal(); ret = esp_wifi_disconnect_internal();
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
roaming_app_disable_reconnect();
#endif
return ret; return ret;
} }

View File

@@ -1,135 +1,42 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#pragma once #pragma once
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_err.h"
#include "esp_wifi_types.h"
#include "utils/common.h"
#include <sys/time.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define SUPPLICANT_CANDIDATE_LIST_EXPIRY 10 struct roam_config {
uint8_t backoff_time;
/* Global Roaming Configuration */ bool low_rssi_roam_trigger;
#define ROAMING_BACKOFF_TIME CONFIG_ESP_WIFI_ROAMING_BACKOFF_TIME int8_t low_rssi_threshold;
uint8_t rssi_threshold_reduction_offset;
/* Low RSSI based roaming configuration */ bool scan_monitor;
#define LOW_RSSI_ROAMING_ENABLED CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_ROAMING uint8_t scan_interval;
#if LOW_RSSI_ROAMING_ENABLED int8_t scan_rssi_threshold;
#define ROAMING_LOW_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_THRESHOLD uint8_t scan_rssi_diff;
#define RSSI_THRESHOLD_REDUCTION_OFFSET CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_OFFSET bool legacy_roam_enabled;
#endif /*LOW_RSSI_ROAMING_ENABLED*/ uint8_t btm_retry_cnt;
bool btm_roaming_enabled;
/* Periodic Scan based Roaming configuration */ bool rrm_monitor;
#define PERIODIC_SCAN_MONITORING CONFIG_ESP_WIFI_ROAMING_PERIODIC_SCAN_MONITOR uint8_t rrm_monitor_time;
#if PERIODIC_SCAN_MONITORING int8_t rrm_monitor_rssi_threshold;
#define SCAN_MONITOR_INTERVAL CONFIG_ESP_WIFI_ROAMING_SCAN_MONITOR_INTERVAL wifi_scan_config_t scan_config;
#define SCAN_MONITOR_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_PERIODIC_SCAN_THRESHOLD
#define SCAN_ROAM_RSSI_DIFF CONFIG_ESP_WIFI_ROAMING_SCAN_ROAM_RSSI_DIFF
#endif /* PERIODIC_SCAN_MONITORING */
/* Scan configuration */
#define SCAN_TIME_MIN_DURATION CONFIG_ESP_WIFI_ROAMING_SCAN_MIN_SCAN_TIME
#define SCAN_TIME_MAX_DURATION CONFIG_ESP_WIFI_ROAMING_SCAN_MAX_SCAN_TIME
#define HOME_CHANNEL_DWELL_TIME CONFIG_ESP_WIFI_ROAMING_HOME_CHANNEL_DWELL_TIME
#define SCAN_PREFERRED_CHAN_LIST CONFIG_ESP_WIFI_ROAMING_SCAN_CHAN_LIST
#define DEFAULT_PREFERRED_SCAN_CHAN_LIST "None"
#define SCAN_RESULTS_USABILITY_WINDOW CONFIG_ESP_WIFI_ROAMING_SCAN_EXPIRY_WINDOW
#define MAX_CANDIDATE_COUNT CONFIG_ESP_WIFI_ROAMING_MAX_CANDIDATES
/* Legacy roaming configuration */
#define LEGACY_ROAM_ENABLED CONFIG_ESP_WIFI_ROAMING_LEGACY_ROAMING
#define BSS_TM_RETRY_COUNT CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_RETRY_COUNT
/* Network Assisted Roaming */
#define NETWORK_ASSISTED_ROAMING_ENABLED CONFIG_ESP_WIFI_ROAMING_NETWORK_ASSISTED_ROAM
/* Periodic RRM configuration */
#define PERIODIC_RRM_MONITORING CONFIG_ESP_WIFI_ROAMING_PERIODIC_RRM_MONITORING
#if PERIODIC_RRM_MONITORING
#define RRM_MONITOR_TIME CONFIG_ESP_WIFI_ROAMING_RRM_MONITOR_TIME
#define RRM_MONITOR_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_RRM_MONITOR_THRESHOLD
#endif /*PERIODIC_RRM_MONITORING*/
#define MAX_SCAN_CHAN_LIST_COUNT 14
#define MAX_NEIGHBOR_LEN 512
#define IS_PSK(authmode) \
(((authmode == WIFI_AUTH_WPA_PSK) || (authmode == WIFI_AUTH_WPA2_PSK) || \
(authmode == WIFI_AUTH_WPA_WPA2_PSK) || (authmode == WIFI_AUTH_WPA3_PSK) || \
(authmode == WIFI_AUTH_WPA2_WPA3_PSK) || (authmode == WIFI_AUTH_WAPI_PSK) ? 1 : 0))
#define OWE_COMPATIBLE(curr_auth, cand_auth) \
((((curr_auth == WIFI_AUTH_OPEN) || (curr_auth == WIFI_AUTH_OWE)) && ((cand_auth == WIFI_AUTH_OPEN) || (cand_auth == WIFI_AUTH_OWE)))? 1 : 0)
#define PSK_COMPATIBLE(curr_auth, cand_auth) \
((IS_PSK(curr_auth) && IS_PSK(cand_auth)) ? 1 : 0)
struct scanned_ap_info {
uint16_t current_count;
struct timeval time;
wifi_ap_record_t ap_records[MAX_CANDIDATE_COUNT];
};
struct cand_bss {
uint8_t channel;
uint8_t bssid[ETH_ALEN];
}; };
struct roaming_app { void roam_init_app(void);
wifi_scan_config_t scan_params; void roam_deinit_app(void);
bool scan_ongoing; void roam_disable_reconnect(void);
int8_t current_rssi_threshold; void roam_enable_reconnect(void);
char *btm_neighbor_list; void roam_sta_connected(void);
struct timeval last_roamed_time; void roam_sta_disconnected(void *disconn);
wifi_ap_record_t ap_info; esp_err_t roam_get_config_params(struct roam_config *config);
struct scanned_ap_info scanned_aps; esp_err_t roam_set_config_params(struct roam_config *config);
bool btm_support;
bool rrm_support;
#if LOW_RSSI_ROAMING_ENABLED
int8_t current_low_rssi_threshold;
#endif
#if LEGACY_ROAM_ENABLED && NETWORK_ASSISTED_ROAMING_ENABLED
uint8_t btm_attempt;
#endif
#if LEGACY_ROAM_ENABLED
bool force_roam_ongoing;
#endif
#if PERIODIC_RRM_MONITORING
bool periodic_rrm_active;
bool rrm_request_active;
#endif
#if PERIODIC_SCAN_MONITORING
bool periodic_scan_active;
#endif
bool allow_reconnect;
};
void init_roaming_app(void);
void deinit_roaming_app(void);
#if PERIODIC_RRM_MONITORING
void roaming_app_periodic_rrm_internal_handler(void *data, void *ctx);
#endif /*PERIODIC_RRM_MONITORING*/
#if PERIODIC_SCAN_MONITORING
void roaming_app_periodic_scan_internal_handler(void *data, void *ctx);
#endif /*PERIODIC_SCAN_ROAM_MONITORING*/
void roaming_app_trigger_roam_internal_handler(void *data, void *ctx);
void roaming_app_disable_reconnect(void);
void roaming_app_enable_reconnect(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -90,13 +90,21 @@ menu "Roaming Methods"
Retry threshold after which the station should stop using Network Assisted Retry threshold after which the station should stop using Network Assisted
roaming methods and start using legacy roaming instead. roaming methods and start using legacy roaming instead.
config ESP_WIFI_NETWORK_ASSISTED_ROAMING_IP_RENEW_SKIP
bool "Skip IP renew during BTM based roaming"
depends on ESP_WIFI_ROAMING_NETWORK_ASSISTED_ROAM
default y
help
Station will not ask for IP renew after a BTM based roaming. Before enabling please
make sure your network supports this.
endmenu #"Roaming Methods" endmenu #"Roaming Methods"
menu "Scan Configuration" menu "Scan Configuration"
config ESP_WIFI_ROAMING_SCAN_MIN_SCAN_TIME config ESP_WIFI_ROAMING_SCAN_MIN_SCAN_TIME
int "Minimum duration (in milliseconds) of station's per channel active scan" int "Minimum duration (in milliseconds) of station's per channel active scan"
default 10 default 30
range 0 120 range 0 120
help help
Minimum duration of active scanning per channel in milliseconds. Minimum duration of active scanning per channel in milliseconds.

View File

@@ -0,0 +1,143 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_err.h"
#include "esp_wifi_types.h"
#include "utils/common.h"
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SUPPLICANT_CANDIDATE_LIST_EXPIRY 10
/* Global Roaming Configuration */
#define ROAMING_BACKOFF_TIME CONFIG_ESP_WIFI_ROAMING_BACKOFF_TIME
/* Low RSSI based roaming configuration */
#define LOW_RSSI_ROAMING_ENABLED CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_ROAMING
#if LOW_RSSI_ROAMING_ENABLED
#define ROAMING_LOW_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_THRESHOLD
#define RSSI_THRESHOLD_REDUCTION_OFFSET CONFIG_ESP_WIFI_ROAMING_LOW_RSSI_OFFSET
#endif /*LOW_RSSI_ROAMING_ENABLED*/
/* Periodic Scan based Roaming configuration */
#define PERIODIC_SCAN_MONITORING CONFIG_ESP_WIFI_ROAMING_PERIODIC_SCAN_MONITOR
#if PERIODIC_SCAN_MONITORING
#define SCAN_MONITOR_INTERVAL CONFIG_ESP_WIFI_ROAMING_SCAN_MONITOR_INTERVAL
#define SCAN_MONITOR_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_PERIODIC_SCAN_THRESHOLD
#define SCAN_ROAM_RSSI_DIFF CONFIG_ESP_WIFI_ROAMING_SCAN_ROAM_RSSI_DIFF
#endif /* PERIODIC_SCAN_MONITORING */
/* Scan configuration */
#define SCAN_TIME_MIN_DURATION CONFIG_ESP_WIFI_ROAMING_SCAN_MIN_SCAN_TIME
#define SCAN_TIME_MAX_DURATION CONFIG_ESP_WIFI_ROAMING_SCAN_MAX_SCAN_TIME
#define HOME_CHANNEL_DWELL_TIME CONFIG_ESP_WIFI_ROAMING_HOME_CHANNEL_DWELL_TIME
#define SCAN_PREFERRED_CHAN_LIST CONFIG_ESP_WIFI_ROAMING_SCAN_CHAN_LIST
#define DEFAULT_PREFERRED_SCAN_CHAN_LIST "None"
#define SCAN_RESULTS_USABILITY_WINDOW CONFIG_ESP_WIFI_ROAMING_SCAN_EXPIRY_WINDOW
#define MAX_CANDIDATE_COUNT CONFIG_ESP_WIFI_ROAMING_MAX_CANDIDATES
/* Legacy roaming configuration */
#ifdef CONFIG_ESP_WIFI_ROAMING_LEGACY_ROAMING
#define LEGACY_ROAM_ENABLED CONFIG_ESP_WIFI_ROAMING_LEGACY_ROAMING
#else
#define LEGACY_ROAM_ENABLED 0
#endif
#ifdef CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_RETRY_COUNT
#define BSS_TM_RETRY_COUNT CONFIG_ESP_WIFI_NETWORK_ASSISTED_ROAMING_RETRY_COUNT
#else
#define BSS_TM_RETRY_COUNT 0
#endif
/* Network Assisted Roaming */
#ifdef CONFIG_ESP_WIFI_ROAMING_NETWORK_ASSISTED_ROAM
#define NETWORK_ASSISTED_ROAMING_ENABLED CONFIG_ESP_WIFI_ROAMING_NETWORK_ASSISTED_ROAM
#else
#define NETWORK_ASSISTED_ROAMING_ENABLED 0
#endif
/* Periodic RRM configuration */
#ifdef CONFIG_ESP_WIFI_ROAMING_PERIODIC_RRM_MONITORING
#define PERIODIC_RRM_MONITORING CONFIG_ESP_WIFI_ROAMING_PERIODIC_RRM_MONITORING
#else
#define PERIODIC_RRM_MONITORING 0
#endif
#if PERIODIC_RRM_MONITORING
#define RRM_MONITOR_TIME CONFIG_ESP_WIFI_ROAMING_RRM_MONITOR_TIME
#define RRM_MONITOR_RSSI_THRESHOLD CONFIG_ESP_WIFI_ROAMING_RRM_MONITOR_THRESHOLD
#else
#define RRM_MONITOR_TIME 232
#define RRM_MONITOR_RSSI_THRESHOLD -100
#endif /*PERIODIC_RRM_MONITORING*/
#define MAX_SCAN_CHAN_LIST_COUNT 14
#define MAX_NEIGHBOR_LEN 512
#define IS_PSK(authmode) \
(((authmode == WIFI_AUTH_WPA_PSK) || (authmode == WIFI_AUTH_WPA2_PSK) || \
(authmode == WIFI_AUTH_WPA_WPA2_PSK) || (authmode == WIFI_AUTH_WPA3_PSK) || \
(authmode == WIFI_AUTH_WPA2_WPA3_PSK) || (authmode == WIFI_AUTH_WAPI_PSK) ? 1 : 0))
#define OWE_COMPATIBLE(curr_auth, cand_auth) \
((((curr_auth == WIFI_AUTH_OPEN) || (curr_auth == WIFI_AUTH_OWE)) && ((cand_auth == WIFI_AUTH_OPEN) || (cand_auth == WIFI_AUTH_OWE)))? 1 : 0)
#define PSK_COMPATIBLE(curr_auth, cand_auth) \
((IS_PSK(curr_auth) && IS_PSK(cand_auth)) ? 1 : 0)
struct scanned_ap_info {
uint16_t current_count;
struct timeval time;
wifi_ap_record_t ap_records[MAX_CANDIDATE_COUNT];
};
struct cand_bss {
uint8_t channel;
uint8_t bssid[ETH_ALEN];
};
struct roam_bss_info {
wifi_ap_record_t ap;
bool btm_support;
bool rrm_support;
};
struct roaming_app {
struct roam_config config;
bool scan_ongoing;
int8_t current_rssi_threshold;
char *btm_neighbor_list;
struct timeval last_roamed_time;
struct scanned_ap_info scanned_aps;
struct roam_bss_info current_bss;
#if LOW_RSSI_ROAMING_ENABLED
int8_t current_low_rssi_threshold;
#endif
#if LEGACY_ROAM_ENABLED && NETWORK_ASSISTED_ROAMING_ENABLED
uint8_t btm_attempt;
#endif
#if LEGACY_ROAM_ENABLED
bool force_roam_ongoing;
#endif
#if PERIODIC_RRM_MONITORING
bool periodic_rrm_active;
bool rrm_request_active;
#endif
#if PERIODIC_SCAN_MONITORING
bool periodic_scan_active;
#endif
bool allow_reconnect;
};
#ifdef __cplusplus
}
#endif

View File

@@ -22,6 +22,7 @@
#include "regex.h" #include "regex.h"
#include <stdio.h> #include <stdio.h>
#include "esp_roaming.h" #include "esp_roaming.h"
#include "esp_roaming_i.h"
#include "utils/common.h" #include "utils/common.h"
#include "esp_wifi_driver.h" #include "esp_wifi_driver.h"
#include "utils/eloop.h" #include "utils/eloop.h"
@@ -43,6 +44,12 @@ static void *neighbor_list_lock = NULL;
static int wifi_post_roam_event(struct cand_bss *bss); static int wifi_post_roam_event(struct cand_bss *bss);
static void determine_best_ap(int8_t rssi_threshold); static void determine_best_ap(int8_t rssi_threshold);
#if PERIODIC_RRM_MONITORING
static void roaming_app_periodic_rrm_internal_handler(void *data, void *ctx);
#endif
#if PERIODIC_SCAN_MONITORING
static void roaming_app_periodic_scan_internal_handler(void *data, void *ctx);
#endif
static const char *ROAMING_TAG = "ROAM"; static const char *ROAMING_TAG = "ROAM";
@@ -51,18 +58,28 @@ 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);
} }
void roaming_app_disable_reconnect(void) static void disable_reconnect(void *ctx, void *data)
{ {
ESP_LOGD(ROAMING_TAG, "Switching off reconnect due to application trigerred disconnect"); ESP_LOGD(ROAMING_TAG, "Disable roaming app reconnect");
g_roaming_app.allow_reconnect = false; g_roaming_app.allow_reconnect = false;
} }
void roaming_app_enable_reconnect(void) static void enable_reconnect(void *ctx, void *data)
{ {
ESP_LOGD(ROAMING_TAG, "Switching on reconnect due to application trigerred reconnect"); ESP_LOGD(ROAMING_TAG, "Enable roaming app reconnect");
g_roaming_app.allow_reconnect = true; g_roaming_app.allow_reconnect = true;
} }
void roam_disable_reconnect(void)
{
eloop_register_timeout(0, 0, disable_reconnect, NULL, NULL);
}
void roam_enable_reconnect(void)
{
eloop_register_timeout(0, 0, enable_reconnect, NULL, NULL);
}
static void roaming_app_get_ap_info(wifi_ap_record_t *ap_info) static void roaming_app_get_ap_info(wifi_ap_record_t *ap_info)
{ {
esp_wifi_sta_get_ap_info(ap_info); esp_wifi_sta_get_ap_info(ap_info);
@@ -71,10 +88,10 @@ static void roaming_app_get_ap_info(wifi_ap_record_t *ap_info)
* If the current rssi is below the configured rssi threshold for * If the current rssi is below the configured rssi threshold for
* low rssi based roaming and the current rssi threshold is below that, * low rssi based roaming and the current rssi threshold is below that,
* we should reset the rssi threshold back to the configured rssi threshold */ * we should reset the rssi threshold back to the configured rssi threshold */
if ((ap_info->rssi > ROAMING_LOW_RSSI_THRESHOLD) && (g_roaming_app.current_low_rssi_threshold < ROAMING_LOW_RSSI_THRESHOLD)) { if ((ap_info->rssi > g_roaming_app.config.low_rssi_threshold) && (g_roaming_app.current_low_rssi_threshold < g_roaming_app.config.low_rssi_threshold)) {
g_roaming_app.current_low_rssi_threshold = ROAMING_LOW_RSSI_THRESHOLD; g_roaming_app.current_low_rssi_threshold = g_roaming_app.config.low_rssi_threshold;
esp_wifi_set_rssi_threshold(ROAMING_LOW_RSSI_THRESHOLD); esp_wifi_set_rssi_threshold(g_roaming_app.config.low_rssi_threshold);
ESP_LOGD(ROAMING_TAG, "Reset the low rssi threshold back to %d", ROAMING_LOW_RSSI_THRESHOLD); ESP_LOGD(ROAMING_TAG, "Reset the low rssi threshold back to %d", g_roaming_app.config.low_rssi_threshold);
} }
#endif /*LOW_RSSI_ROAMING_ENABLED*/ #endif /*LOW_RSSI_ROAMING_ENABLED*/
} }
@@ -118,6 +135,10 @@ static int8_t initialize_roaming_event(void)
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
static void init_periodic_rrm_event(void) static void init_periodic_rrm_event(void)
{ {
if (!g_roaming_app.config.rrm_monitor) {
ESP_LOGI(ROAMING_TAG, "RRM monitor is disabled in config");
return;
}
if (!neighbor_list_lock) { if (!neighbor_list_lock) {
neighbor_list_lock = os_recursive_mutex_create(); neighbor_list_lock = os_recursive_mutex_create();
if (!neighbor_list_lock) { if (!neighbor_list_lock) {
@@ -126,7 +147,7 @@ static void init_periodic_rrm_event(void)
} }
ESP_LOGV(ROAMING_TAG, "Initialised Periodic RRM Monitoring event!"); ESP_LOGV(ROAMING_TAG, "Initialised Periodic RRM Monitoring event!");
g_roaming_app.periodic_rrm_active = true; g_roaming_app.periodic_rrm_active = true;
if (eloop_register_timeout(RRM_MONITOR_TIME, 0, roaming_app_periodic_rrm_internal_handler, NULL, NULL)) { if (eloop_register_timeout(g_roaming_app.config.rrm_monitor_time, 0, roaming_app_periodic_rrm_internal_handler, NULL, NULL)) {
ESP_LOGE(ROAMING_TAG, "Could not register periodic neighbor report event."); ESP_LOGE(ROAMING_TAG, "Could not register periodic neighbor report event.");
} }
} }
@@ -135,18 +156,20 @@ static void init_periodic_rrm_event(void)
#if PERIODIC_SCAN_MONITORING #if PERIODIC_SCAN_MONITORING
static void init_periodic_scan_roam_event(void) static void init_periodic_scan_roam_event(void)
{ {
if (!g_roaming_app.config.scan_monitor) {
ESP_LOGI(ROAMING_TAG, "%s: Scan monitor is disabled in config", __func__);
return;
}
ESP_LOGV(ROAMING_TAG, "Initialised Periodic Scan Roam event!"); ESP_LOGV(ROAMING_TAG, "Initialised Periodic Scan Roam event!");
g_roaming_app.periodic_scan_active = true; g_roaming_app.periodic_scan_active = true;
if (eloop_register_timeout(SCAN_MONITOR_INTERVAL, 0, roaming_app_periodic_scan_internal_handler, NULL, NULL)) { if (eloop_register_timeout(g_roaming_app.config.scan_interval, 0, roaming_app_periodic_scan_internal_handler, NULL, NULL)) {
ESP_LOGE(ROAMING_TAG, "Could not register periodic scan monitoring event"); ESP_LOGE(ROAMING_TAG, "Could not register periodic scan monitoring event");
} }
} }
#endif /*PERIODIC_SCAN_ROAM_MONITORING*/ #endif /*PERIODIC_SCAN_ROAM_MONITORING*/
static void roaming_app_disconnected_event_handler(void* arg, esp_event_base_t event_base, static void roaming_app_disconnected_event_handler(void *ctx, void *data)
int32_t event_id, void* event_data)
{ {
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
g_roaming_app.periodic_rrm_active = false; g_roaming_app.periodic_rrm_active = false;
#endif /*PERIODIC_RRM_MONITORING*/ #endif /*PERIODIC_RRM_MONITORING*/
@@ -155,7 +178,7 @@ static void roaming_app_disconnected_event_handler(void* arg, esp_event_base_t e
g_roaming_app.periodic_scan_active = false; g_roaming_app.periodic_scan_active = false;
#endif /*PERIODIC_SCAN_MONITORING*/ #endif /*PERIODIC_SCAN_MONITORING*/
wifi_event_sta_disconnected_t *disconn = event_data; wifi_event_sta_disconnected_t *disconn = data;
ESP_LOGD(ROAMING_TAG, "station got disconnected reason=%d", disconn->reason); ESP_LOGD(ROAMING_TAG, "station got disconnected reason=%d", disconn->reason);
if (disconn->reason == WIFI_REASON_ROAMING) { if (disconn->reason == WIFI_REASON_ROAMING) {
ESP_LOGD(ROAMING_TAG, "station roaming, do nothing"); ESP_LOGD(ROAMING_TAG, "station roaming, do nothing");
@@ -174,39 +197,33 @@ static void roaming_app_disconnected_event_handler(void* arg, esp_event_base_t e
#endif /*LEGACY_ROAM_ENABLED*/ #endif /*LEGACY_ROAM_ENABLED*/
esp_wifi_connect(); esp_wifi_connect();
} }
os_free(disconn);
} }
static void roaming_app_sta_stop_event_handler(void* arg, esp_event_base_t event_base, static void roaming_app_connected_event_handler(void *ctx, void *data)
int32_t event_id, void* event_data)
{
g_roaming_app.allow_reconnect = false;
}
static void roaming_app_connected_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{ {
roaming_app_get_ap_info(&g_roaming_app.current_bss.ap);
g_roaming_app.config.scan_config.ssid = g_roaming_app.current_bss.ap.ssid;
#if LOW_RSSI_ROAMING_ENABLED #if LOW_RSSI_ROAMING_ENABLED
roaming_app_get_ap_info(&g_roaming_app.ap_info); if (g_roaming_app.current_bss.ap.rssi < g_roaming_app.config.low_rssi_threshold) {
g_roaming_app.scan_params.ssid = g_roaming_app.ap_info.ssid;
if (g_roaming_app.ap_info.rssi < ROAMING_LOW_RSSI_THRESHOLD) {
/* To ensure that the threshold is set to one offset below the current AP RSSI /* To ensure that the threshold is set to one offset below the current AP RSSI
* in case, the AP is already below the RSSI threshold */ * in case, the AP is already below the RSSI threshold */
g_roaming_app.current_low_rssi_threshold = g_roaming_app.ap_info.rssi - RSSI_THRESHOLD_REDUCTION_OFFSET; g_roaming_app.current_low_rssi_threshold = g_roaming_app.current_bss.ap.rssi - g_roaming_app.config.rssi_threshold_reduction_offset;
} else { } else {
g_roaming_app.current_low_rssi_threshold = ROAMING_LOW_RSSI_THRESHOLD; g_roaming_app.current_low_rssi_threshold = g_roaming_app.config.low_rssi_threshold;
} }
ESP_LOGD(ROAMING_TAG, "setting rssi threshold as %d", g_roaming_app.current_low_rssi_threshold); ESP_LOGD(ROAMING_TAG, "setting rssi threshold as %d", g_roaming_app.current_low_rssi_threshold);
esp_wifi_set_rssi_threshold(g_roaming_app.current_low_rssi_threshold); esp_wifi_set_rssi_threshold(g_roaming_app.current_low_rssi_threshold);
#endif /*LOW_RSSI_ROAMING_ENABLED*/ #endif /*LOW_RSSI_ROAMING_ENABLED*/
g_roaming_app.rrm_support = esp_rrm_is_rrm_supported_connection(); g_roaming_app.current_bss.rrm_support = esp_rrm_is_rrm_supported_connection();
g_roaming_app.btm_support = esp_wnm_is_btm_supported_connection(); g_roaming_app.current_bss.btm_support = esp_wnm_is_btm_supported_connection();
ESP_LOGD(ROAMING_TAG, "Station connected, RRM %ssupported, BTM %ssupported", ESP_LOGD(ROAMING_TAG, "Station connected, RRM %ssupported, BTM %ssupported",
g_roaming_app.rrm_support ? " " : "not ", g_roaming_app.current_bss.rrm_support ? " " : "not ",
g_roaming_app.btm_support ? " " : "not "); g_roaming_app.current_bss.btm_support ? " " : "not ");
gettimeofday(&g_roaming_app.last_roamed_time, NULL); gettimeofday(&g_roaming_app.last_roamed_time, NULL);
if (!initialize_roaming_event()) { if (!initialize_roaming_event()) {
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
if (g_roaming_app.rrm_support) { if (g_roaming_app.current_bss.rrm_support) {
init_periodic_rrm_event(); init_periodic_rrm_event();
} }
#endif /*PERIODIC_RRM_MONITORING*/ #endif /*PERIODIC_RRM_MONITORING*/
@@ -218,10 +235,29 @@ static void roaming_app_connected_event_handler(void* arg, esp_event_base_t even
ESP_LOGE(ROAMING_TAG, "Failed to Initialise roaming events"); ESP_LOGE(ROAMING_TAG, "Failed to Initialise roaming events");
} }
#if LEGACY_ROAM_ENABLED #if LEGACY_ROAM_ENABLED
g_roaming_app.force_roam_ongoing = true; g_roaming_app.force_roam_ongoing = false;
#endif /*LEGACY_ROAM_ENABLED*/ #endif /*LEGACY_ROAM_ENABLED*/
g_roaming_app.allow_reconnect = true; g_roaming_app.allow_reconnect = true;
} }
void roam_sta_connected(void)
{
eloop_register_timeout(0, 0, roaming_app_connected_event_handler, NULL, NULL);
}
void roam_sta_disconnected(void *data)
{
wifi_event_sta_disconnected_t *disconn = os_malloc(sizeof(*disconn));
if (!disconn) {
return;
}
os_memcpy(disconn, data, sizeof(*disconn));
if (eloop_register_timeout(0, 0, roaming_app_disconnected_event_handler, NULL, disconn) != 0) {
os_free(disconn);
}
}
#define MAX_NEIGHBOR_LEN 512 #define MAX_NEIGHBOR_LEN 512
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
static char * get_btm_neighbor_list(uint8_t *report, size_t report_len) static char * get_btm_neighbor_list(uint8_t *report, size_t report_len)
@@ -359,15 +395,16 @@ static void roaming_app_neighbor_report_recv_handler(void* arg, esp_event_base_t
} }
#endif /*PERIODIC_RRM_MONITORING*/ #endif /*PERIODIC_RRM_MONITORING*/
#if LOW_RSSI_ROAMING_ENABLED #if LOW_RSSI_ROAMING_ENABLED
static void roaming_app_rssi_low_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) static void roaming_app_rssi_low_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{ {
wifi_event_bss_rssi_low_t *event = event_data; wifi_event_bss_rssi_low_t *event = event_data;
ESP_LOGI(ROAMING_TAG, "%s:bss rssi is=%ld", __func__, event->rssi); ESP_LOGI(ROAMING_TAG, "%s:bss rssi is=%ld", __func__, event->rssi);
roaming_app_get_ap_info(&g_roaming_app.ap_info); roaming_app_get_ap_info(&g_roaming_app.current_bss.ap);
determine_best_ap(0); determine_best_ap(0);
g_roaming_app.current_low_rssi_threshold -= RSSI_THRESHOLD_REDUCTION_OFFSET; g_roaming_app.current_low_rssi_threshold -= g_roaming_app.config.rssi_threshold_reduction_offset;
ESP_LOGD(ROAMING_TAG, "Resetting RSSI Threshold to %d", g_roaming_app.current_low_rssi_threshold); ESP_LOGD(ROAMING_TAG, "Resetting RSSI Threshold to %d", g_roaming_app.current_low_rssi_threshold);
esp_wifi_set_rssi_threshold(g_roaming_app.current_low_rssi_threshold); esp_wifi_set_rssi_threshold(g_roaming_app.current_low_rssi_threshold);
@@ -388,8 +425,9 @@ static void trigger_network_assisted_roam(void)
#endif /*PERIODIC_RRM_MONITORING*/ #endif /*PERIODIC_RRM_MONITORING*/
ESP_LOGD(ROAMING_TAG, "Sent BTM Query"); ESP_LOGD(ROAMING_TAG, "Sent BTM Query");
gettimeofday(&g_roaming_app.last_roamed_time, NULL); gettimeofday(&g_roaming_app.last_roamed_time, NULL);
#if LEGACY_ROAM_ENABLED
g_roaming_app.btm_attempt++; g_roaming_app.btm_attempt++;
#endif
} }
#endif /*NETWORK_ASSISTED_ROAMING*/ #endif /*NETWORK_ASSISTED_ROAMING*/
@@ -415,14 +453,14 @@ void roaming_app_trigger_roam(struct cand_bss *bss)
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
ESP_LOGD(ROAMING_TAG,"Processing trigger roaming request."); ESP_LOGD(ROAMING_TAG,"Processing trigger roaming request.");
if (time_diff_sec(&now, &g_roaming_app.last_roamed_time) < ROAMING_BACKOFF_TIME ) { if (time_diff_sec(&now, &g_roaming_app.last_roamed_time) < g_roaming_app.config.backoff_time ) {
ESP_LOGD(ROAMING_TAG,"Ignoring request as time difference to last request is %ld",time_diff_sec(&now, &g_roaming_app.last_roamed_time)); ESP_LOGD(ROAMING_TAG,"Ignoring request as time difference to last request is %ld",time_diff_sec(&now, &g_roaming_app.last_roamed_time));
goto free_bss; goto free_bss;
} }
#if NETWORK_ASSISTED_ROAMING_ENABLED #if NETWORK_ASSISTED_ROAMING_ENABLED
if (g_roaming_app.btm_support) { if (g_roaming_app.config.btm_roaming_enabled && g_roaming_app.current_bss.btm_support) {
#if LEGACY_ROAM_ENABLED && NETWORK_ASSISTED_ROAMING_ENABLED #if LEGACY_ROAM_ENABLED && NETWORK_ASSISTED_ROAMING_ENABLED
if (g_roaming_app.btm_attempt <= BSS_TM_RETRY_COUNT) { if (g_roaming_app.btm_attempt <= g_roaming_app.config.btm_retry_cnt) {
#endif #endif
trigger_network_assisted_roam(); trigger_network_assisted_roam();
goto free_bss; goto free_bss;
@@ -435,7 +473,9 @@ void roaming_app_trigger_roam(struct cand_bss *bss)
} }
#endif /*NETWORK_ASSISTED_ROAMING_ENABLED*/ #endif /*NETWORK_ASSISTED_ROAMING_ENABLED*/
#if LEGACY_ROAM_ENABLED #if LEGACY_ROAM_ENABLED
trigger_legacy_roam(bss); if (g_roaming_app.config.legacy_roam_enabled) {
trigger_legacy_roam(bss);
}
#endif /*LEGACY_ROAM_ENABLED*/ #endif /*LEGACY_ROAM_ENABLED*/
free_bss : free_bss :
os_free(bss); os_free(bss);
@@ -489,8 +529,8 @@ void print_ap_records(struct scanned_ap_info *ap_info)
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
static void periodic_rrm_request(struct timeval *now) static void periodic_rrm_request(struct timeval *now)
{ {
roaming_app_get_ap_info(&g_roaming_app.ap_info); roaming_app_get_ap_info(&g_roaming_app.current_bss.ap);
if (esp_rrm_is_rrm_supported_connection() && (g_roaming_app.ap_info.rssi < RRM_MONITOR_RSSI_THRESHOLD)) { if (esp_rrm_is_rrm_supported_connection() && (g_roaming_app.current_bss.ap.rssi < g_roaming_app.config.rrm_monitor_rssi_threshold)) {
if (esp_rrm_send_neighbor_report_request() < 0) { if (esp_rrm_send_neighbor_report_request() < 0) {
ESP_LOGE(ROAMING_TAG, "failed to send neighbor report request"); ESP_LOGE(ROAMING_TAG, "failed to send neighbor report request");
return; return;
@@ -502,7 +542,7 @@ static void periodic_rrm_request(struct timeval *now)
static bool candidate_security_match(wifi_ap_record_t candidate) static bool candidate_security_match(wifi_ap_record_t candidate)
{ {
wifi_auth_mode_t curr_auth = g_roaming_app.ap_info.authmode; wifi_auth_mode_t curr_auth = g_roaming_app.current_bss.ap.authmode;
wifi_auth_mode_t cand_auth = candidate.authmode; wifi_auth_mode_t cand_auth = candidate.authmode;
ESP_LOGV(ROAMING_TAG, "Cand authmode : %d, Current Authmode : %d", cand_auth, curr_auth); ESP_LOGV(ROAMING_TAG, "Cand authmode : %d, Current Authmode : %d", cand_auth, curr_auth);
if (cand_auth == curr_auth) { if (cand_auth == curr_auth) {
@@ -606,7 +646,7 @@ static void conduct_scan(void)
gettimeofday(&g_roaming_app.scanned_aps.time, NULL); gettimeofday(&g_roaming_app.scanned_aps.time, NULL);
/* Issue scan */ /* Issue scan */
os_memset(&g_roaming_app.scanned_aps, 0, sizeof(struct scanned_ap_info)); os_memset(&g_roaming_app.scanned_aps, 0, sizeof(struct scanned_ap_info));
if (esp_wifi_promiscuous_scan_start(&g_roaming_app.scan_params, scan_done_event_handler) < 0) { if (esp_wifi_promiscuous_scan_start(&g_roaming_app.config.scan_config, scan_done_event_handler) < 0) {
ESP_LOGE(ROAMING_TAG, "failed to issue scan"); ESP_LOGE(ROAMING_TAG, "failed to issue scan");
return; return;
} }
@@ -643,32 +683,39 @@ static void periodic_scan_roam(struct timeval *now)
* as the results produced by a scan at this time would not be used by * as the results produced by a scan at this time would not be used by
* supplicant to build candidate lists. * supplicant to build candidate lists.
* */ * */
if (time_diff_sec(now, &g_roaming_app.last_roamed_time) < ROAMING_BACKOFF_TIME - SUPPLICANT_CANDIDATE_LIST_EXPIRY) { if (time_diff_sec(now, &g_roaming_app.last_roamed_time) < g_roaming_app.config.backoff_time - SUPPLICANT_CANDIDATE_LIST_EXPIRY) {
return; return;
} }
#endif /*NETWORK_ASSISTED_ROAMING_ENABLED && !LEGACY_ROAM_ENABLED*/ #endif /*NETWORK_ASSISTED_ROAMING_ENABLED && !LEGACY_ROAM_ENABLED*/
/* If the current RSSI is not worse than the configured threshold /* If the current RSSI is not worse than the configured threshold
* for station initiated roam, then do not trigger roam */ * for station initiated roam, then do not trigger roam */
roaming_app_get_ap_info(&g_roaming_app.ap_info); roaming_app_get_ap_info(&g_roaming_app.current_bss.ap);
if (g_roaming_app.ap_info.rssi > SCAN_MONITOR_RSSI_THRESHOLD) { ESP_LOGD(ROAMING_TAG, "Connected AP's RSSI=%d", g_roaming_app.current_bss.ap.rssi);
if (g_roaming_app.current_bss.ap.rssi > g_roaming_app.config.scan_rssi_threshold) {
return; return;
} }
determine_best_ap(SCAN_ROAM_RSSI_DIFF - 1); determine_best_ap(g_roaming_app.config.scan_rssi_diff - 1);
} }
#endif /*PERIODIC_SCAN_MONITORING*/ #endif /*PERIODIC_SCAN_MONITORING*/
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
void roaming_app_periodic_rrm_internal_handler(void *data, void *ctx) static void roaming_app_periodic_rrm_internal_handler(void *data, void *ctx)
{ {
struct timeval now; struct timeval now;
if (!g_roaming_app.config.rrm_monitor) {
ESP_LOGI(ROAMING_TAG, "%s:RRM monitor is disabled in config", __func__);
return;
}
if (g_roaming_app.periodic_rrm_active) { if (g_roaming_app.periodic_rrm_active) {
ESP_LOGD(ROAMING_TAG,"Triggered periodic rrm event!"); ESP_LOGD(ROAMING_TAG,"Triggered periodic rrm event!");
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
/* This will be done every RRM_MONITOR_TIME */ /* This will be done every g_roaming_app.config.rrm_monitor_time */
periodic_rrm_request(&now); periodic_rrm_request(&now);
if (eloop_register_timeout(RRM_MONITOR_TIME, 0, roaming_app_periodic_rrm_internal_handler, NULL, NULL)) { if (eloop_register_timeout(g_roaming_app.config.rrm_monitor_time, 0, roaming_app_periodic_rrm_internal_handler, NULL, NULL)) {
ESP_LOGE(ROAMING_TAG,"Could not register periodic neighbor report request event."); ESP_LOGE(ROAMING_TAG,"Could not register periodic neighbor report request event.");
} }
} }
@@ -676,17 +723,23 @@ void roaming_app_periodic_rrm_internal_handler(void *data, void *ctx)
#endif /*PERIODIC_RRM_MONITORING*/ #endif /*PERIODIC_RRM_MONITORING*/
#if PERIODIC_SCAN_MONITORING #if PERIODIC_SCAN_MONITORING
void roaming_app_periodic_scan_internal_handler(void *data, void *ctx) static void roaming_app_periodic_scan_internal_handler(void *data, void *ctx)
{ {
struct timeval now; struct timeval now;
if (!g_roaming_app.config.scan_monitor) {
ESP_LOGI(ROAMING_TAG, "%s: Scan monitor is disabled in config", __func__);
return;
}
if (g_roaming_app.periodic_scan_active) { if (g_roaming_app.periodic_scan_active) {
ESP_LOGD(ROAMING_TAG,"Started the periodic scan roam event!"); ESP_LOGD(ROAMING_TAG,"Started the periodic scan roam event!");
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
/* This will be done every SCAN_MONITOR_INTERVAL */ /* This will be done every g_roaming_app.config.scan_interval */
periodic_scan_roam(&now); periodic_scan_roam(&now);
if (eloop_register_timeout(SCAN_MONITOR_INTERVAL, 0, roaming_app_periodic_scan_internal_handler, NULL, NULL)) { if (eloop_register_timeout(g_roaming_app.config.scan_interval, 0, roaming_app_periodic_scan_internal_handler, NULL, NULL)) {
ESP_LOGE(ROAMING_TAG,"Could not register periodic scan event."); ESP_LOGE(ROAMING_TAG,"Could not register periodic scan event.");
} }
} }
@@ -736,14 +789,14 @@ static int8_t parse_scan_chan_list(void)
char* token; char* token;
token = strsep(&scan_chan_string, ","); token = strsep(&scan_chan_string, ",");
g_roaming_app.scan_params.channel_bitmap.ghz_2_channels = 0; g_roaming_app.config.scan_config.channel_bitmap.ghz_2_channels = 0;
while (token != NULL) { while (token != NULL) {
uint8_t channel = atoi(token); uint8_t channel = atoi(token);
/* Check if the number is within the required range */ /* Check if the number is within the required range */
if (channel >= 1 && channel <= 14) { if (channel >= 1 && channel <= 14) {
/* Check if the number is already present in the array */ /* Check if the number is already present in the array */
g_roaming_app.scan_params.channel_bitmap.ghz_2_channels |= (1 << channel); g_roaming_app.config.scan_config.channel_bitmap.ghz_2_channels |= (1 << channel);
} else { } else {
ESP_LOGE(ROAMING_TAG, "Channel out of range: %d", channel); ESP_LOGE(ROAMING_TAG, "Channel out of range: %d", channel);
ret = -1; ret = -1;
@@ -759,7 +812,51 @@ cleanup:
return ret; return ret;
} }
esp_err_t init_scan_params(void)
static esp_err_t init_config_params(void)
{
g_roaming_app.config.backoff_time = ROAMING_BACKOFF_TIME;
g_roaming_app.config.low_rssi_roam_trigger = LOW_RSSI_ROAMING_ENABLED;
g_roaming_app.config.low_rssi_threshold = ROAMING_LOW_RSSI_THRESHOLD;
g_roaming_app.config.rssi_threshold_reduction_offset = RSSI_THRESHOLD_REDUCTION_OFFSET;
g_roaming_app.config.scan_monitor = PERIODIC_SCAN_MONITORING;
g_roaming_app.config.scan_interval = SCAN_MONITOR_INTERVAL;
g_roaming_app.config.scan_rssi_threshold = SCAN_MONITOR_RSSI_THRESHOLD;
g_roaming_app.config.scan_rssi_diff = SCAN_ROAM_RSSI_DIFF;
g_roaming_app.config.legacy_roam_enabled = LEGACY_ROAM_ENABLED;
g_roaming_app.config.btm_retry_cnt = BSS_TM_RETRY_COUNT;
g_roaming_app.config.btm_roaming_enabled = NETWORK_ASSISTED_ROAMING_ENABLED;
g_roaming_app.config.rrm_monitor = PERIODIC_RRM_MONITORING;
g_roaming_app.config.rrm_monitor_time = RRM_MONITOR_TIME;
g_roaming_app.config.rrm_monitor_rssi_threshold = RRM_MONITOR_RSSI_THRESHOLD;
ESP_LOGD(ROAMING_TAG, "Roaming app config :");
ESP_LOGD(ROAMING_TAG, "backoff time=%d low_rssi_roam_trigger=%d low_rssi_threshold=%d rssi_threshold_reduction_offset=%d",
g_roaming_app.config.backoff_time, g_roaming_app.config.low_rssi_roam_trigger,
g_roaming_app.config.low_rssi_threshold, g_roaming_app.config.rssi_threshold_reduction_offset);
ESP_LOGD(ROAMING_TAG, "scan_monitor=%d scan_interval=%d scan_rssi_threshold=%d scan_rssi_diff=%d",
g_roaming_app.config.scan_monitor, g_roaming_app.config.scan_interval,
g_roaming_app.config.scan_rssi_threshold, g_roaming_app.config.scan_rssi_diff);
ESP_LOGD(ROAMING_TAG, "legacy_roam_enabled=%d, btm_retry_cnt=%d btm_roaming_enabled=%d",
g_roaming_app.config.legacy_roam_enabled,
g_roaming_app.config.btm_retry_cnt, g_roaming_app.config.btm_roaming_enabled);
ESP_LOGD(ROAMING_TAG, "rrm_monitor=%d, rrm_monitor_time=%d rrm_monitor_rssi_threshold=%d",
g_roaming_app.config.rrm_monitor,
g_roaming_app.config.rrm_monitor_time,
g_roaming_app.config.rrm_monitor_rssi_threshold);
return ESP_OK;
}
static esp_err_t init_scan_config(void)
{ {
if (!scan_results_lock) { if (!scan_results_lock) {
scan_results_lock = os_recursive_mutex_create(); scan_results_lock = os_recursive_mutex_create();
@@ -773,15 +870,15 @@ esp_err_t init_scan_params(void)
ESP_ERROR_CHECK(parse_scan_chan_list()); ESP_ERROR_CHECK(parse_scan_chan_list());
} }
g_roaming_app.scan_params.scan_type = 0; g_roaming_app.config.scan_config.scan_type = 0;
g_roaming_app.scan_params.scan_time.active.min = SCAN_TIME_MIN_DURATION; g_roaming_app.config.scan_config.scan_time.active.min = SCAN_TIME_MIN_DURATION;
g_roaming_app.scan_params.scan_time.active.max = SCAN_TIME_MAX_DURATION; g_roaming_app.config.scan_config.scan_time.active.max = SCAN_TIME_MAX_DURATION;
g_roaming_app.scan_params.home_chan_dwell_time = HOME_CHANNEL_DWELL_TIME; g_roaming_app.config.scan_config.home_chan_dwell_time = HOME_CHANNEL_DWELL_TIME;
gettimeofday(&g_roaming_app.scanned_aps.time, NULL); gettimeofday(&g_roaming_app.scanned_aps.time, NULL);
return ESP_OK; return ESP_OK;
} }
void init_roaming_app(void) void roam_init_app(void)
{ {
#if !LOW_RSSI_ROAMING_ENABLED && !PERIODIC_SCAN_MONITORING #if !LOW_RSSI_ROAMING_ENABLED && !PERIODIC_SCAN_MONITORING
ESP_LOGE(ROAMING_TAG, "No roaming trigger enabled. Roaming app cannot be initialized"); ESP_LOGE(ROAMING_TAG, "No roaming trigger enabled. Roaming app cannot be initialized");
@@ -792,14 +889,12 @@ void init_roaming_app(void)
ESP_LOGE(ROAMING_TAG, "No roaming method enabled. Roaming app cannot be initialized"); ESP_LOGE(ROAMING_TAG, "No roaming method enabled. Roaming app cannot be initialized");
return; return;
#endif #endif
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED, roaming_app_connected_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, roaming_app_disconnected_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_STOP, roaming_app_sta_stop_event_handler, NULL));
#if LOW_RSSI_ROAMING_ENABLED #if LOW_RSSI_ROAMING_ENABLED
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_BSS_RSSI_LOW, ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_BSS_RSSI_LOW,
&roaming_app_rssi_low_handler, NULL)); &roaming_app_rssi_low_handler, NULL));
#endif /*ROAMING_LOW_RSSI_THRESHOLD*/ #endif /*LOW_RSSI_ROAMING_ENABLED*/
ESP_ERROR_CHECK(init_scan_params()); ESP_ERROR_CHECK(init_scan_config());
ESP_ERROR_CHECK(init_config_params());
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_NEIGHBOR_REP, ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_NEIGHBOR_REP,
&roaming_app_neighbor_report_recv_handler, NULL)); &roaming_app_neighbor_report_recv_handler, NULL));
@@ -807,7 +902,7 @@ void init_roaming_app(void)
ESP_LOGI(ROAMING_TAG, "Roaming app initialization done"); ESP_LOGI(ROAMING_TAG, "Roaming app initialization done");
} }
void deinit_roaming_app(void) void roam_deinit_app(void)
{ {
#if !LOW_RSSI_ROAMING_ENABLED && !PERIODIC_SCAN_MONITORING #if !LOW_RSSI_ROAMING_ENABLED && !PERIODIC_SCAN_MONITORING
ESP_LOGE(ROAMING_TAG, "No roaming trigger enabled. Roaming app cannot be de-initialized"); ESP_LOGE(ROAMING_TAG, "No roaming trigger enabled. Roaming app cannot be de-initialized");
@@ -818,30 +913,19 @@ void deinit_roaming_app(void)
ESP_LOGE(ROAMING_TAG, "No roaming trigger enabled. Roaming app cannot be de-initialized"); ESP_LOGE(ROAMING_TAG, "No roaming trigger enabled. Roaming app cannot be de-initialized");
return; return;
#endif #endif
/* Unregister Event handlers */
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED, roaming_app_connected_event_handler));
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, roaming_app_disconnected_event_handler));
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_STOP, roaming_app_sta_stop_event_handler));
#if LOW_RSSI_ROAMING_ENABLED #if LOW_RSSI_ROAMING_ENABLED
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_BSS_RSSI_LOW, ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_BSS_RSSI_LOW,
&roaming_app_rssi_low_handler)); &roaming_app_rssi_low_handler));
#endif /*ROAMING_LOW_RSSI_THRESHOLD*/ #endif /*LOW_RSSI_ROAMING_ENABLED*/
#if PERIODIC_RRM_MONITORING
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_NEIGHBOR_REP,
&roaming_app_neighbor_report_recv_handler));
#endif /*PERIODIC_RRM_MONITORING*/
/* Disabling the periodic scan and RRM events */
#if PERIODIC_RRM_MONITORING
g_roaming_app.periodic_rrm_active = false;
#endif /*PERIODIC_RRM_MONITORING*/
#if PERIODIC_SCAN_MONITORING #if PERIODIC_SCAN_MONITORING
g_roaming_app.periodic_scan_active = false; g_roaming_app.periodic_scan_active = false;
#endif /*PERIODIC_SCAN_MONITORING*/ #endif /*PERIODIC_SCAN_MONITORING*/
#if PERIODIC_RRM_MONITORING #if PERIODIC_RRM_MONITORING
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_NEIGHBOR_REP,
&roaming_app_neighbor_report_recv_handler));
/* Disabling the periodic scan and RRM events */
g_roaming_app.periodic_rrm_active = false;
if (neighbor_list_lock) { if (neighbor_list_lock) {
os_mutex_delete(neighbor_list_lock); os_mutex_delete(neighbor_list_lock);
neighbor_list_lock = NULL; neighbor_list_lock = NULL;
@@ -852,3 +936,50 @@ void deinit_roaming_app(void)
scan_results_lock = NULL; scan_results_lock = NULL;
} }
} }
/* No need for this to be done in pptask ctx */
esp_err_t roam_get_config_params(struct roam_config *config)
{
memcpy(config, &g_roaming_app.config, sizeof(*config));
return ESP_OK;
}
static int update_config_params(void *data)
{
struct roam_config *config = data;
g_roaming_app.config = *config;
ESP_LOGI(ROAMING_TAG, "Updated Roaming app config :");
ESP_LOGI(ROAMING_TAG, "backoff time=%d low_rssi_roam_trigger=%d low_rssi_threshold=%d rssi_threshold_reduction_offset=%d",
g_roaming_app.config.backoff_time, g_roaming_app.config.low_rssi_roam_trigger,
g_roaming_app.config.low_rssi_threshold, g_roaming_app.config.rssi_threshold_reduction_offset);
ESP_LOGI(ROAMING_TAG, "scan_monitor=%d scan_interval=%d scan_rssi_threshold=%d scan_rssi_diff=%d",
g_roaming_app.config.scan_monitor, g_roaming_app.config.scan_interval,
g_roaming_app.config.scan_rssi_threshold, g_roaming_app.config.scan_rssi_diff);
ESP_LOGI(ROAMING_TAG, "legacy_roam_enabled=%d, btm_retry_cnt=%d btm_roaming_enabled=%d",
g_roaming_app.config.legacy_roam_enabled,
g_roaming_app.config.btm_retry_cnt, g_roaming_app.config.btm_roaming_enabled);
ESP_LOGI(ROAMING_TAG, "rrm_monitor=%d, rrm_monitor_time=%d rrm_monitor_rssi_threshold=%d",
g_roaming_app.config.rrm_monitor,
g_roaming_app.config.rrm_monitor_time,
g_roaming_app.config.rrm_monitor_rssi_threshold);
return ESP_OK;
}
esp_err_t roam_set_config_params(struct roam_config *config)
{
wifi_ipc_config_t cfg;
cfg.fn = update_config_params;
cfg.arg = config;
cfg.arg_size = sizeof(*config);
esp_wifi_ipc_internal(&cfg, false);
return ESP_OK;
}

View File

@@ -23,9 +23,6 @@
#include "rsn_supp/wpa_i.h" #include "rsn_supp/wpa_i.h"
#include "rsn_supp/wpa.h" #include "rsn_supp/wpa.h"
#include "esp_private/wifi.h" #include "esp_private/wifi.h"
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
#include "esp_roaming.h"
#endif
/* 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])

View File

@@ -40,9 +40,6 @@
#include "ap/sta_info.h" #include "ap/sta_info.h"
#include "wps/wps_defs.h" #include "wps/wps_defs.h"
#include "wps/wps.h" #include "wps/wps.h"
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
#include "esp_roaming.h"
#endif
#include "rsn_supp/pmksa_cache.h" #include "rsn_supp/pmksa_cache.h"
#ifdef CONFIG_DPP #ifdef CONFIG_DPP

View File

@@ -17,6 +17,7 @@
#include "list.h" #include "list.h"
#include "eloop.h" #include "eloop.h"
#include "esp_wifi_driver.h" #include "esp_wifi_driver.h"
#include "rom/ets_sys.h"
struct eloop_timeout { struct eloop_timeout {
struct dl_list list; struct dl_list list;