diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h b/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h index 1ffcf18047..fa40e0cd62 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h @@ -1,17 +1,7 @@ -/** - * Copyright 2020 Espressif Systems (Shanghai) PTE LTD +/* + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ #ifndef _ESP_RRM_H @@ -41,11 +31,22 @@ typedef void (*neighbor_rep_request_cb)(void *ctx, const uint8_t *report, size_t * @param cb_ctx: callback context * * @return - * - 0: success else failure + * - 0: success + * - -1: AP does not support RRM + * - -2: station not connected to AP */ int esp_rrm_send_neighbor_rep_request(neighbor_rep_request_cb cb, void *cb_ctx); +/** + * @brief Check RRM capability of connected AP + * + * @return + * - true: AP supports RRM + * - false: AP does not support RRM or station not connected to AP + */ +bool esp_rrm_is_rrm_supported_connection(void); + #ifdef __cplusplus } #endif diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h b/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h index 4301385d2c..2ee95bedd7 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h @@ -36,12 +36,23 @@ enum btm_query_reason { * @param cand_list: whether candidate list to be included from scan results available in supplicant's cache. * * @return - * - 0: success else failure + * - 0: success + * - -1: AP does not support BTM + * - -2: station not connected to AP */ int esp_wnm_send_bss_transition_mgmt_query(enum btm_query_reason query_reason, const char *btm_candidates, int cand_list); +/** + * @brief Check bss trasition capability of connected AP + * + * @return + * - true: AP supports BTM + * - false: AP does not support BTM or station not connected to AP + */ +bool esp_wnm_is_btm_supported_connection(void); + #ifdef __cplusplus } #endif diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common.c b/components/wpa_supplicant/esp_supplicant/src/esp_common.c index 105ca37aa8..93d5e0ae73 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common.c @@ -429,23 +429,82 @@ void esp_supplicant_common_deinit(void) } #ifdef CONFIG_WPA_11KV_SUPPORT +bool esp_rrm_is_rrm_supported_connection(void) +{ + struct wpa_supplicant *wpa_s = &g_wpa_supp; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_DEBUG, "STA not associated, return"); + return false; + } + + if (!(wpa_s->rrm_ie[0] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) { + wpa_printf(MSG_DEBUG, + "RRM: No network support for Neighbor Report."); + return false; + } + + return true; +} int esp_rrm_send_neighbor_rep_request(neighbor_rep_request_cb cb, void *cb_ctx) { + struct wpa_supplicant *wpa_s = &g_wpa_supp; struct wpa_ssid_value wpa_ssid = {0}; - struct wifi_ssid *ssid = esp_wifi_sta_get_prof_ssid_internal(); + struct wifi_ssid *ssid; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_ERROR, "STA not associated, return"); + return -2; + } + + if (!(wpa_s->rrm_ie[0] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) { + wpa_printf(MSG_ERROR, + "RRM: No network support for Neighbor Report."); + return -1; + } + + ssid = esp_wifi_sta_get_prof_ssid_internal(); os_memcpy(wpa_ssid.ssid, ssid->ssid, ssid->len); wpa_ssid.ssid_len = ssid->len; - return wpas_rrm_send_neighbor_rep_request(&g_wpa_supp, &wpa_ssid, 0, 0, cb, cb_ctx); + return wpas_rrm_send_neighbor_rep_request(wpa_s, &wpa_ssid, 0, 0, cb, cb_ctx); +} + +bool esp_wnm_is_btm_supported_connection(void) +{ + struct wpa_supplicant *wpa_s = &g_wpa_supp; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_DEBUG, "STA not associated, return"); + return false; + } + + if (!wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION)) { + wpa_printf(MSG_DEBUG, "AP doesn't support BTM, return"); + return false; + } + + return true; } int esp_wnm_send_bss_transition_mgmt_query(enum btm_query_reason query_reason, const char *btm_candidates, int cand_list) { - return wnm_send_bss_transition_mgmt_query(&g_wpa_supp, query_reason, btm_candidates, cand_list); + struct wpa_supplicant *wpa_s = &g_wpa_supp; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_ERROR, "STA not associated, return"); + return -2; + } + + if (!wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION)) { + wpa_printf(MSG_ERROR, "AP doesn't support BTM, return"); + return -1; + } + return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, btm_candidates, cand_list); } int esp_mbo_update_non_pref_chan(struct non_pref_chan_s *non_pref_chan) @@ -572,9 +631,9 @@ static uint8_t get_extended_caps_ie(uint8_t *ie, size_t len) *pos++ = ext_caps_ie_len; *pos++ = 0; *pos++ = 0; -#define WLAN_EXT_CAPAB_BSS_TRANSITION BIT(3) - *pos |= WLAN_EXT_CAPAB_BSS_TRANSITION; -#undef WLAN_EXT_CAPAB_BSS_TRANSITION +#define CAPAB_BSS_TRANSITION BIT(3) + *pos |= CAPAB_BSS_TRANSITION; +#undef CAPAB_BSS_TRANSITION os_memcpy(ie, ext_caps_ie, sizeof(ext_caps_ie)); return ext_caps_ie_len + 2; 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 0ad024d057..8d8856cebf 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c @@ -260,8 +260,8 @@ int esp_supplicant_init(void) wpa_cb->wpa_config_done = wpa_config_done; esp_wifi_register_wpa3_cb(wpa_cb); - ret = esp_supplicant_common_init(wpa_cb); eloop_init(); + ret = esp_supplicant_common_init(wpa_cb); if (ret != 0) { return ret; diff --git a/components/wpa_supplicant/src/common/ieee802_11_defs.h b/components/wpa_supplicant/src/common/ieee802_11_defs.h index 4087166767..a378d91e3b 100644 --- a/components/wpa_supplicant/src/common/ieee802_11_defs.h +++ b/components/wpa_supplicant/src/common/ieee802_11_defs.h @@ -250,6 +250,8 @@ #define WLAN_EID_EXT_HE_CAPABILITIES 35 #define WLAN_EID_EXT_HE_OPERATION 36 +#define WLAN_EXT_CAPAB_BSS_TRANSITION 19 + /* Action frame categories (IEEE Std 802.11-2016, 9.4.1.11, Table 9-76) */ #define WLAN_ACTION_SPECTRUM_MGMT 0 #define WLAN_ACTION_QOS 1 diff --git a/examples/wifi/roaming/main/roaming_example.c b/examples/wifi/roaming/main/roaming_example.c index 88f6672a27..9f17e4229c 100644 --- a/examples/wifi/roaming/main/roaming_example.c +++ b/examples/wifi/roaming/main/roaming_example.c @@ -54,6 +54,17 @@ static void event_handler(void* arg, esp_event_base_t event_base, esp_wifi_set_rssi_threshold(EXAMPLE_WIFI_RSSI_THRESHOLD); } #endif + if (esp_rrm_is_rrm_supported_connection()) { + ESP_LOGI(TAG,"RRM supported"); + } else { + ESP_LOGI(TAG,"RRM not supported"); + } + if (esp_wnm_is_btm_supported_connection()) { + ESP_LOGI(TAG,"BTM supported"); + } else { + ESP_LOGI(TAG,"BTM not supported"); + } + } } diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 7cc6f8d07b..b15f884cd1 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1651,7 +1651,6 @@ components/wifi_provisioning/src/scheme_console.c components/wifi_provisioning/src/wifi_config.c components/wifi_provisioning/src/wifi_provisioning_priv.h components/wifi_provisioning/src/wifi_scan.c -components/wpa_supplicant/esp_supplicant/include/esp_rrm.h components/wpa_supplicant/esp_supplicant/src/esp_scan_i.h components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c components/wpa_supplicant/esp_supplicant/src/esp_wpa3_i.h