From 97e42349aa8905c15babfe56ecb793779829e9cf Mon Sep 17 00:00:00 2001 From: yinqingzhao Date: Fri, 13 Sep 2024 20:19:29 +0800 Subject: [PATCH] feat(wifi):wifi add channel bit definition --- .../esp32c5/ld/esp32c5.rom.net80211.ld | 22 ++--- components/esp_wifi/Kconfig | 8 +- components/esp_wifi/include/esp_wifi.h | 10 +-- .../esp_wifi/include/esp_wifi_types_generic.h | 84 +++++++++++++++++-- components/esp_wifi/lib | 2 +- .../esp32c5/include/soc/Kconfig.soc_caps.in | 2 +- components/soc/esp32c5/include/soc/soc_caps.h | 2 +- .../wifi/fast_scan/main/Kconfig.projbuild | 2 +- examples/wifi/fast_scan/main/fast_scan.c | 2 +- examples/wifi/iperf/main/idf_component.yml | 2 +- 10 files changed, 105 insertions(+), 31 deletions(-) diff --git a/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld b/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld index ff8dbbcdac..bd55f3bb3c 100644 --- a/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld +++ b/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld @@ -35,18 +35,18 @@ ic_ebuf_alloc = 0x40000b4c; ic_reset_extra_softap_rx_ba = 0x40000b50; ieee80211_align_eb = 0x40000b54; ieee80211_ampdu_reorder = 0x40000b58; -ieee80211_ampdu_start_age_timer = 0x40000b5c; -ieee80211_encap_esfbuf = 0x40000b60; +/*ieee80211_ampdu_start_age_timer = 0x40000b5c;*/ +/*ieee80211_encap_esfbuf = 0x40000b60;*/ ieee80211_is_tx_allowed = 0x40000b64; -ieee80211_output_pending_eb = 0x40000b68; -ieee80211_output_process = 0x40000b6c; +/*ieee80211_output_pending_eb = 0x40000b68;*/ +/*ieee80211_output_process = 0x40000b6c;*/ /*ieee80211_set_tx_desc = 0x40000b70;*/ ieee80211_classify = 0x40000b74; ieee80211_copy_eb_header = 0x40000b78; ieee80211_recycle_cache_eb = 0x40000b7c; ieee80211_search_node = 0x40000b80; -ieee80211_crypto_encap = 0x40000b84; -ieee80211_crypto_decap = 0x40000b88; +/*ieee80211_crypto_encap = 0x40000b84;*/ +/*ieee80211_crypto_decap = 0x40000b88;*/ ieee80211_decap = 0x40000b8c; ieee80211_set_tx_pti = 0x40000b90; ieee80211_gettid = 0x40000b94; @@ -61,12 +61,12 @@ ieee80211_find_ie = 0x40000bb4; ieee80211_find_ext_ie = 0x40000bb8; ieee80211_merge_mbssid_profile = 0x40000bbc; ieee80211_encap_esfbuf_htc = 0x40000bc0; -wifi_get_macaddr = 0x40000bc4; -wifi_rf_phy_disable = 0x40000bc8; -wifi_rf_phy_enable = 0x40000bcc; -wifi_is_started = 0x40000bd0; +/*wifi_get_macaddr = 0x40000bc4;*/ +/*wifi_rf_phy_disable = 0x40000bc8;*/ +/*wifi_rf_phy_enable = 0x40000bcc;*/ +/*wifi_is_started = 0x40000bd0;*/ /*sta_input = 0x40000bd4;*/ -sta_rx_eapol = 0x40000bd8; +/*sta_rx_eapol = 0x40000bd8;*/ sta_reset_beacon_timeout = 0x40000bdc; sta_get_beacon_timeout = 0x40000be0; ampdu_process_multicast_address_qos_frame = 0x40000be4; diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 4536eed694..eb69f2056c 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -657,28 +657,28 @@ menu "Wi-Fi" config ESP_WIFI_ENABLE_DUMP_HESIGB bool "Enable Wi-Fi dump HE-SIGB which is contained in DL HE MU PPDUs" - depends on SOC_WIFI_HE_SUPPORT_5G + depends on SOC_WIFI_SUPPORT_5G default "n" help Enable Wi-Fi dump HE-SIGB which is contained in DL HE MU PPDUs. config ESP_WIFI_ENABLE_DUMP_MU_CFO bool "Enable Wi-Fi dump MU CFO" - depends on SOC_WIFI_HE_SUPPORT_5G + depends on SOC_WIFI_SUPPORT_5G default "n" help Enable Wi-Fi dump MU CFO. config ESP_WIFI_ENABLE_DUMP_CTRL_NDPA bool "Enable Wi-Fi dump NDPA frames" - depends on SOC_WIFI_HE_SUPPORT_5G + depends on SOC_WIFI_SUPPORT_5G default "n" help Enable Wi-Fi dump NDPA frames. config ESP_WIFI_ENABLE_DUMP_CTRL_BFRP bool "Enable Wi-Fi dump BFRP frames" - depends on SOC_WIFI_HE_SUPPORT_5G + depends on SOC_WIFI_SUPPORT_5G default "n" help Enable Wi-Fi dump BFRP frames. diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index c8f615bd86..ce08ecb748 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -677,7 +677,7 @@ esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type); * @brief Set protocol type of specified interface * The default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N). * if CONFIG_SOC_WIFI_HE_SUPPORT and band mode is 2.4G, the default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_11AX). - * if CONFIG_SOC_WIFI_HE_SUPPORT_5G and band mode is 5G, the default protocol is (WIFI_PROTOCOL_11A|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_11AC|WIFI_PROTOCOL_11AX). + * if CONFIG_SOC_WIFI_SUPPORT_5G and band mode is 5G, the default protocol is (WIFI_PROTOCOL_11A|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_11AC|WIFI_PROTOCOL_11AX). * * @attention 1. When WiFi band mode is 2.4G only, support 802.11b or 802.11bg or 802.11bgn or 802.11bgnax or LR mode * @attention 2. When WiFi band mode is 5G only, support 802.11a or 802.11an or 802.11anac or 802.11anacax @@ -1653,8 +1653,8 @@ esp_err_t esp_wifi_get_band(wifi_band_t* band); * @attention 1. When the WiFi band mode is set to 2.4G only, it operates exclusively on the 2.4GHz channels. * @attention 2. When the WiFi band mode is set to 5G only, it operates exclusively on the 5GHz channels. * @attention 3. When the WiFi band mode is set to 2.4G + 5G (WIFI_BAND_MODE_AUTO), it can operate on both the 2.4GHz and 5GHz channels. - * @attention 4. WiFi band mode can be set to 5G only or 2.4G + 5G (WIFI_BAND_MODE_AUTO) if CONFIG_SOC_WIFI_HE_SUPPORT_5G is supported. - * @attention 5. If CONFIG_SOC_WIFI_HE_SUPPORT_5G is not supported, the API will return ESP_ERR_INVALID_ARG when the band mode is set to either 5G only or 2.4G + 5G (WIFI_BAND_MODE_AUTO). + * @attention 4. WiFi band mode can be set to 5G only or 2.4G + 5G (WIFI_BAND_MODE_AUTO) if CONFIG_SOC_WIFI_SUPPORT_5G is supported. + * @attention 5. If CONFIG_SOC_WIFI_SUPPORT_5G is not supported, the API will return ESP_ERR_INVALID_ARG when the band mode is set to either 5G only or 2.4G + 5G (WIFI_BAND_MODE_AUTO). * @attention 6. When a WiFi band mode change triggers a band change, if no channel is set for the current band, a default channel will be assigned: channel 1 for 2.4G band and channel 36 for 5G band. * * @param[in] band_mode store the band mode of WiFi @@ -1717,7 +1717,7 @@ esp_err_t esp_wifi_set_protocols(wifi_interface_t ifx, wifi_protocols_t *protoco /** * @brief Get the current protocol of the specified interface and specified band * - * @attention 1. The 5G protocol can only be read when CONFIG_SOC_WIFI_HE_SUPPORT_5G is enabled. + * @attention 1. The 5G protocol can only be read when CONFIG_SOC_WIFI_SUPPORT_5G is enabled. * @attention 2. When the WiFi band mode is set to 2.4G only, it will not get 5G protocol * @attention 3. When the WiFi band mode is set to 5G only, it will not get 2.4G protocol * @@ -1756,7 +1756,7 @@ esp_err_t esp_wifi_set_bandwidths(wifi_interface_t ifx, wifi_bandwidths_t* bw); /** * @brief Get the bandwidth of specified interface and specified band * - * @attention 1. The 5G bandwidth can only be read when CONFIG_SOC_WIFI_HE_SUPPORT_5G is enabled. + * @attention 1. The 5G bandwidth can only be read when CONFIG_SOC_WIFI_SUPPORT_5G is enabled. * @attention 2. When the WiFi band mode is set to 2.4G only, it will not get 5G bandwidth * @attention 3. When the WiFi band mode is set to 5G only, it will not get 2.4G bandwidth * diff --git a/components/esp_wifi/include/esp_wifi_types_generic.h b/components/esp_wifi/include/esp_wifi_types_generic.h index ec99df53bb..536b0a3c52 100644 --- a/components/esp_wifi/include/esp_wifi_types_generic.h +++ b/components/esp_wifi/include/esp_wifi_types_generic.h @@ -49,10 +49,16 @@ typedef enum { /** @brief Structure describing WiFi country-based regional restrictions. */ typedef struct { char cc[3]; /**< country code string */ - uint8_t schan; /**< start channel */ - uint8_t nchan; /**< total channel number */ + uint8_t schan; /**< start channel of the allowed 2.4GHz WiFi channels */ + uint8_t nchan; /**< total channel number of the allowed 2.4GHz WiFi channels */ int8_t max_tx_power; /**< This field is used for getting WiFi maximum transmitting power, call esp_wifi_set_max_tx_power to set the maximum transmitting power. */ wifi_country_policy_t policy; /**< country policy */ +#if SOC_WIFI_SUPPORT_5G + uint32_t wifi_5g_channel_mask; /**< A bitmask representing the allowed 5GHz WiFi channels. + Each bit in the mask corresponds to a specific channel as wifi_5g_channel_bit_t shown. + Bitmask set to 0 indicates 5GHz channels are allowed according to local regulatory rules. + Please note that configured bitmask takes effect only when policy is manual. */ +#endif } wifi_country_t; /* Strength of authmodes */ @@ -178,8 +184,8 @@ typedef struct { } wifi_scan_time_t; typedef struct { - uint16_t ghz_2_channels; /**< Represents 2.4 GHz channels */ - uint32_t ghz_5_channels; /**< Represents 5 GHz channels */ + uint16_t ghz_2_channels; /**< Represents 2.4 GHz channels, that bits can be set as wifi_2g_channel_bit_t shown. */ + uint32_t ghz_5_channels; /**< Represents 5 GHz channels, that bits can be set as wifi_5g_channel_bit_t shown. */ } wifi_scan_channel_bitmap_t; /** @brief Parameters for an SSID scan. */ @@ -191,7 +197,9 @@ typedef struct { wifi_scan_type_t scan_type; /**< scan type, active or passive */ wifi_scan_time_t scan_time; /**< scan time per channel */ uint8_t home_chan_dwell_time; /**< time spent at home channel between scanning consecutive channels. */ - wifi_scan_channel_bitmap_t channel_bitmap; /**< Channel bitmap for setting specific channels to be scanned. For 2.4ghz channels set ghz_2_channels from BIT(1) to BIT(14) from LSB to MSB order to indicate channels to be scanned. Currently scanning in 5ghz channels is not supported. Please note that the 'channel' parameter above needs to be set to 0 to allow scanning by bitmap. */ + wifi_scan_channel_bitmap_t channel_bitmap; /**< Channel bitmap for setting specific channels to be scanned. + Please note that the 'channel' parameter above needs to be set to 0 to allow scanning by bitmap. + Also, note that only allowed channels configured by wifi_country_t can be scaned. */ } wifi_scan_config_t; /** @brief Parameters default scan configurations. */ @@ -305,6 +313,72 @@ typedef enum { WIFI_BAND_MODE_AUTO = 3, /* WiFi band mode is 2.4G + 5G */ } wifi_band_mode_t; +#ifndef BIT +#define BIT(nr) (1 << (nr)) +#endif + +#define CHANNEL_TO_BIT_NUMBER(channel) ((channel >= 1 && channel <= 14) ? (channel) : \ + ((channel >= 36 && channel <= 64 && (channel - 36) % 4 == 0) ? ((channel - 36) / 4 + 1) : \ + ((channel >= 100 && channel <= 144 && (channel - 100) % 4 == 0) ? ((channel - 100) / 4 + 9) : \ + ((channel >= 149 && channel <= 177 && (channel - 149) % 4 == 0) ? ((channel - 149) / 4 + 21) : 0)))) + +#define BIT_NUMBER_TO_CHANNEL(bit_number, band) ((band == WIFI_BAND_2G) ? (bit_number) : \ + ((bit_number >= 1 && bit_number <= 8) ? ((bit_number - 1) * 4 + 36) : \ + ((bit_number >= 9 && bit_number <= 20) ? ((bit_number - 9) * 4 + 100) : \ + ((bit_number >= 21 && bit_number <= 28) ? ((bit_number - 21) * 4 + 149) : 0)))) + +#define CHANNEL_TO_BIT(channel) (BIT(CHANNEL_TO_BIT_NUMBER(channel))) + +/** Argument structure for 2.4G channels */ +typedef enum { + WIFI_CHANNEL_1 = BIT(1), /**< wifi channel 1 */ + WIFI_CHANNEL_2 = BIT(2), /**< wifi channel 2 */ + WIFI_CHANNEL_3 = BIT(3), /**< wifi channel 3 */ + WIFI_CHANNEL_4 = BIT(4), /**< wifi channel 4 */ + WIFI_CHANNEL_5 = BIT(5), /**< wifi channel 5 */ + WIFI_CHANNEL_6 = BIT(6), /**< wifi channel 6 */ + WIFI_CHANNEL_7 = BIT(7), /**< wifi channel 7 */ + WIFI_CHANNEL_8 = BIT(8), /**< wifi channel 8 */ + WIFI_CHANNEL_9 = BIT(9), /**< wifi channel 9 */ + WIFI_CHANNEL_10 = BIT(10), /**< wifi channel 10 */ + WIFI_CHANNEL_11 = BIT(11), /**< wifi channel 11 */ + WIFI_CHANNEL_12 = BIT(12), /**< wifi channel 12 */ + WIFI_CHANNEL_13 = BIT(13), /**< wifi channel 13 */ + WIFI_CHANNEL_14 = BIT(14), /**< wifi channel 14 */ +} wifi_2g_channel_bit_t; + +/** Argument structure for 5G channels */ +typedef enum { + WIFI_CHANNEL_36 = BIT(1), /**< wifi channel 36 */ + WIFI_CHANNEL_40 = BIT(2), /**< wifi channel 40 */ + WIFI_CHANNEL_44 = BIT(3), /**< wifi channel 44 */ + WIFI_CHANNEL_48 = BIT(4), /**< wifi channel 48 */ + WIFI_CHANNEL_52 = BIT(5), /**< wifi channel 52 */ + WIFI_CHANNEL_56 = BIT(6), /**< wifi channel 56 */ + WIFI_CHANNEL_60 = BIT(7), /**< wifi channel 60 */ + WIFI_CHANNEL_64 = BIT(8), /**< wifi channel 64 */ + WIFI_CHANNEL_100 = BIT(9), /**< wifi channel 100 */ + WIFI_CHANNEL_104 = BIT(10), /**< wifi channel 104 */ + WIFI_CHANNEL_108 = BIT(11), /**< wifi channel 108 */ + WIFI_CHANNEL_112 = BIT(12), /**< wifi channel 112 */ + WIFI_CHANNEL_116 = BIT(13), /**< wifi channel 116 */ + WIFI_CHANNEL_120 = BIT(14), /**< wifi channel 120 */ + WIFI_CHANNEL_124 = BIT(15), /**< wifi channel 124 */ + WIFI_CHANNEL_128 = BIT(16), /**< wifi channel 128 */ + WIFI_CHANNEL_132 = BIT(17), /**< wifi channel 132 */ + WIFI_CHANNEL_136 = BIT(18), /**< wifi channel 136 */ + WIFI_CHANNEL_140 = BIT(19), /**< wifi channel 140 */ + WIFI_CHANNEL_144 = BIT(20), /**< wifi channel 144 */ + WIFI_CHANNEL_149 = BIT(21), /**< wifi channel 149 */ + WIFI_CHANNEL_153 = BIT(22), /**< wifi channel 153 */ + WIFI_CHANNEL_157 = BIT(23), /**< wifi channel 157 */ + WIFI_CHANNEL_161 = BIT(24), /**< wifi channel 161 */ + WIFI_CHANNEL_165 = BIT(25), /**< wifi channel 165 */ + WIFI_CHANNEL_169 = BIT(26), /**< wifi channel 169 */ + WIFI_CHANNEL_173 = BIT(27), /**< wifi channel 173 */ + WIFI_CHANNEL_177 = BIT(28), /**< wifi channel 177 */ +} wifi_5g_channel_bit_t; + #define WIFI_PROTOCOL_11B 0x1 #define WIFI_PROTOCOL_11G 0x2 #define WIFI_PROTOCOL_11N 0x4 diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index efa80057b0..6b249f7335 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit efa80057b04ade8b1412a0dedcb5572d6ccd1fcc +Subproject commit 6b249f7335ed8e341c111a51b4d368d1825ac3c6 diff --git a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in index b6deae6d49..b2236ecd95 100644 --- a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in @@ -1387,7 +1387,7 @@ config SOC_WIFI_HE_SUPPORT bool default y -config SOC_WIFI_HE_SUPPORT_5G +config SOC_WIFI_SUPPORT_5G bool default y diff --git a/components/soc/esp32c5/include/soc/soc_caps.h b/components/soc/esp32c5/include/soc/soc_caps.h index 6f2418d8c7..fcd5bacef4 100644 --- a/components/soc/esp32c5/include/soc/soc_caps.h +++ b/components/soc/esp32c5/include/soc/soc_caps.h @@ -594,7 +594,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_HE_SUPPORT_5G (1) /*!< Support Wi-Fi 6 in 5G */ +#define SOC_WIFI_SUPPORT_5G (1) /*!< Support 5G */ #define SOC_WIFI_MAC_VERSION_NUM (3) /*!< Wi-Fi MAC version num is 3 */ /*---------------------------------- Bluetooth CAPS ----------------------------------*/ diff --git a/examples/wifi/fast_scan/main/Kconfig.projbuild b/examples/wifi/fast_scan/main/Kconfig.projbuild index bf87095172..142265241b 100644 --- a/examples/wifi/fast_scan/main/Kconfig.projbuild +++ b/examples/wifi/fast_scan/main/Kconfig.projbuild @@ -67,7 +67,7 @@ menu "Example Configuration" config EXAMPLE_FAST_SCAN_RSSI_5G_ADJUSTMENT int "fast scan rssi 5g adjustment" - depends on EXAMPLE_FAST_SCAN_THRESHOLD && SOC_WIFI_HE_SUPPORT_5G + depends on EXAMPLE_FAST_SCAN_THRESHOLD && SOC_WIFI_SUPPORT_5G range 0 128 default 10 help diff --git a/examples/wifi/fast_scan/main/fast_scan.c b/examples/wifi/fast_scan/main/fast_scan.c index 0b06d7aeea..1c7f33606d 100644 --- a/examples/wifi/fast_scan/main/fast_scan.c +++ b/examples/wifi/fast_scan/main/fast_scan.c @@ -61,7 +61,7 @@ #else #define DEFAULT_AUTHMODE WIFI_AUTH_OPEN #endif -#if CONFIG_SOC_WIFI_HE_SUPPORT_5G +#if CONFIG_SOC_WIFI_SUPPORT_5G #define DEFAULT_RSSI_5G_ADJUSTMENT CONFIG_EXAMPLE_FAST_SCAN_RSSI_5G_ADJUSTMENT #else #define DEFAULT_RSSI_5G_ADJUSTMENT 0 diff --git a/examples/wifi/iperf/main/idf_component.yml b/examples/wifi/iperf/main/idf_component.yml index fdb795321d..661b37a3b9 100644 --- a/examples/wifi/iperf/main/idf_component.yml +++ b/examples/wifi/iperf/main/idf_component.yml @@ -4,7 +4,7 @@ dependencies: espressif/iperf-cmd: version: "~0.1.1" esp-qa/wifi-cmd: - version: "~0.1.0" + version: "~0.1.8" esp-qa/ping-cmd: version: "~0.0.1" espressif/esp-extconn: