From ffb227ebd2750436b0b5fac85d090bc46f2ac4e1 Mon Sep 17 00:00:00 2001 From: xuxiao Date: Mon, 2 Sep 2024 20:14:43 +0800 Subject: [PATCH] feat(wifi): add support for ap choose --- components/esp_wifi/include/esp_wifi_he_types.h | 4 ++-- components/esp_wifi/include/esp_wifi_types_generic.h | 5 +++-- components/esp_wifi/lib | 2 +- components/soc/esp32c5/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32c5/include/soc/soc_caps.h | 1 + components/soc/esp32c6/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32c6/include/soc/soc_caps.h | 1 + components/soc/esp32c61/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32c61/include/soc/soc_caps.h | 1 + examples/wifi/fast_scan/main/Kconfig.projbuild | 9 +++++++++ examples/wifi/fast_scan/main/fast_scan.c | 7 +++++++ 11 files changed, 37 insertions(+), 5 deletions(-) diff --git a/components/esp_wifi/include/esp_wifi_he_types.h b/components/esp_wifi/include/esp_wifi_he_types.h index 49131091a7..e9dc2e17a4 100644 --- a/components/esp_wifi/include/esp_wifi_he_types.h +++ b/components/esp_wifi/include/esp_wifi_he_types.h @@ -41,7 +41,7 @@ enum { /** * @brief Channel state information(CSI) configuration type */ -#if CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61 +#if CONFIG_SOC_WIFI_MAC_VERSION_NUM == 3 typedef struct { uint32_t enable : 1; /**< enable to acquire CSI */ uint32_t acquire_csi_legacy : 1; /**< enable to acquire L-LTF */ @@ -172,7 +172,7 @@ typedef enum { /** * @brief RxControl Info */ -#if CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61 +#if CONFIG_SOC_WIFI_MAC_VERSION_NUM == 3 typedef struct { signed rssi: 8; /**< the RSSI of the reception frame */ unsigned rate: 5; /**< if cur_bb_format is RX_BB_FORMAT_11B, it's the transmission rate. otherwise it's Rate field of L-SIG */ diff --git a/components/esp_wifi/include/esp_wifi_types_generic.h b/components/esp_wifi/include/esp_wifi_types_generic.h index 5e2f38b439..ec99df53bb 100644 --- a/components/esp_wifi/include/esp_wifi_types_generic.h +++ b/components/esp_wifi/include/esp_wifi_types_generic.h @@ -280,9 +280,10 @@ typedef enum { /** @brief Structure describing parameters for a WiFi fast scan */ typedef struct { - int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */ - wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode + int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */ + wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode Note: In case this value is not set and password is set as per WPA2 standards(password len >= 8), it will be defaulted to WPA2 and device won't connect to deprecated WEP/WPA networks. Please set authmode threshold as WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK to connect to WEP/WPA networks */ + uint8_t rssi_5g_adjustment; /**< The RSSI value of the 5G AP is within the rssi_5g_adjustment range compared to the 2G AP, the 5G AP will be given priority for connection. */ } wifi_scan_threshold_t; typedef enum { diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index f78422a3cb..d44e167813 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit f78422a3cb497b8f73a3d35956cf31d677a4e08b +Subproject commit d44e16781303546cce729625004c88c1fef983d3 diff --git a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in index 6ddccc8adf..8740fab913 100644 --- a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in @@ -1387,6 +1387,10 @@ config SOC_WIFI_HE_SUPPORT_5G bool default y +config SOC_WIFI_MAC_VERSION_NUM + int + default 3 + config SOC_BLE_SUPPORTED bool default y diff --git a/components/soc/esp32c5/include/soc/soc_caps.h b/components/soc/esp32c5/include/soc/soc_caps.h index 920055d750..c4fd2d2547 100644 --- a/components/soc/esp32c5/include/soc/soc_caps.h +++ b/components/soc/esp32c5/include/soc/soc_caps.h @@ -592,6 +592,7 @@ #define SOC_WIFI_MESH_SUPPORT (1) /*!< Support WIFI MESH */ #define SOC_WIFI_HE_SUPPORT (1) /*!< Support Wi-Fi 6 */ #define SOC_WIFI_HE_SUPPORT_5G (1) /*!< Support Wi-Fi 6 in 5G */ +#define SOC_WIFI_MAC_VERSION_NUM (3) /*!< Wi-Fi MAC version num is 3 */ /*---------------------------------- Bluetooth CAPS ----------------------------------*/ #define SOC_BLE_SUPPORTED (1) /*!< Support Bluetooth Low Energy hardware */ diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 0a1aa7da1f..47dc43d9d5 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1483,6 +1483,10 @@ config SOC_WIFI_HE_SUPPORT bool default y +config SOC_WIFI_MAC_VERSION_NUM + int + default 2 + config SOC_BLE_SUPPORTED bool default y diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index e55ed60b86..b997a19b90 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -584,6 +584,7 @@ #define SOC_WIFI_CSI_SUPPORT (1) /*!< Support CSI */ #define SOC_WIFI_MESH_SUPPORT (1) /*!< Support WIFI MESH */ #define SOC_WIFI_HE_SUPPORT (1) /*!< Support Wi-Fi 6 */ +#define SOC_WIFI_MAC_VERSION_NUM (2) /*!< Wi-Fi MAC version num is 2 */ /*---------------------------------- Bluetooth CAPS ----------------------------------*/ #define SOC_BLE_SUPPORTED (1) /*!< Support Bluetooth Low Energy hardware */ diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index 23d9f90543..e825165289 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -847,6 +847,10 @@ config SOC_WIFI_HE_SUPPORT bool default y +config SOC_WIFI_MAC_VERSION_NUM + int + default 3 + config SOC_PHY_COMBO_MODULE bool default y diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index 6ab137ee9e..c56d34abbb 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -455,6 +455,7 @@ #define SOC_WIFI_CSI_SUPPORT (1) /*!< Support CSI */ #define SOC_WIFI_MESH_SUPPORT (1) /*!< Support WIFI MESH */ #define SOC_WIFI_HE_SUPPORT (1) /*!< Support Wi-Fi 6 */ +#define SOC_WIFI_MAC_VERSION_NUM (3) /*!< Wi-Fi MAC version num is 3 */ /*---------------------------------- Bluetooth CAPS ----------------------------------*/ // \#define SOC_BLE_SUPPORTED (1) /*!< Support Bluetooth Low Energy hardware */ diff --git a/examples/wifi/fast_scan/main/Kconfig.projbuild b/examples/wifi/fast_scan/main/Kconfig.projbuild index 95f738919c..bf87095172 100644 --- a/examples/wifi/fast_scan/main/Kconfig.projbuild +++ b/examples/wifi/fast_scan/main/Kconfig.projbuild @@ -65,4 +65,13 @@ menu "Example Configuration" bool "wpa2" endchoice + config EXAMPLE_FAST_SCAN_RSSI_5G_ADJUSTMENT + int "fast scan rssi 5g adjustment" + depends on EXAMPLE_FAST_SCAN_THRESHOLD && SOC_WIFI_HE_SUPPORT_5G + range 0 128 + default 10 + help + It is used to compensate for the signal difference between 2G and 5G, allowing + the STA to prioritize connecting to the 5G AP + endmenu diff --git a/examples/wifi/fast_scan/main/fast_scan.c b/examples/wifi/fast_scan/main/fast_scan.c index 90b943851c..0b06d7aeea 100644 --- a/examples/wifi/fast_scan/main/fast_scan.c +++ b/examples/wifi/fast_scan/main/fast_scan.c @@ -61,9 +61,15 @@ #else #define DEFAULT_AUTHMODE WIFI_AUTH_OPEN #endif +#if CONFIG_SOC_WIFI_HE_SUPPORT_5G +#define DEFAULT_RSSI_5G_ADJUSTMENT CONFIG_EXAMPLE_FAST_SCAN_RSSI_5G_ADJUSTMENT +#else +#define DEFAULT_RSSI_5G_ADJUSTMENT 0 +#endif #else #define DEFAULT_RSSI -127 #define DEFAULT_AUTHMODE WIFI_AUTH_OPEN +#define DEFAULT_RSSI_5G_ADJUSTMENT 0 #endif /*CONFIG_EXAMPLE_FAST_SCAN_THRESHOLD*/ static const char *TAG = "scan"; @@ -107,6 +113,7 @@ static void fast_scan(void) .sort_method = DEFAULT_SORT_METHOD, .threshold.rssi = DEFAULT_RSSI, .threshold.authmode = DEFAULT_AUTHMODE, + .threshold.rssi_5g_adjustment = DEFAULT_RSSI_5G_ADJUSTMENT, }, }; ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));