Merge branch 'bugfix/fix_some_wifi_bugs_230612_v5.0' into 'release/v5.0'

Fixed some wifi bugs 230612 v5.0 (Backport v5.0)

See merge request espressif/esp-idf!24172
This commit is contained in:
Jiang Jiang Jian 2023-06-14 01:10:29 +08:00
commit 2798527b0b
14 changed files with 114 additions and 67 deletions

View File

@ -1146,6 +1146,7 @@ esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec);
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_WIFI_ARG: invalid argument
*/
esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec);
@ -1319,6 +1320,29 @@ esp_err_t esp_wifi_config_80211_tx_rate(wifi_interface_t ifx, wifi_phy_rate_t ra
*/
esp_err_t esp_wifi_disable_pmf_config(wifi_interface_t ifx);
/**
* @brief Get the Association id assigned to STA by AP
*
* @param[out] aid store the aid
*
* @attention aid = 0 if station is not connected to AP.
*
* @return
* - ESP_OK: succeed
*/
esp_err_t esp_wifi_sta_get_aid(uint16_t *aid);
/**
* @brief Get the negotiated phymode after connection.
*
* @param[out] phymode store the negotiated phymode.
*
* @attention Operation phy mode, BIT[5]: indicate whether LR enabled, BIT[0-4]: wifi_phy_mode_t
*
* @return
* - ESP_OK: succeed
*/
esp_err_t esp_wifi_sta_get_negotiated_phymode(wifi_phy_mode_t *phymode);
#ifdef __cplusplus
}
#endif

View File

@ -259,12 +259,12 @@ typedef struct {
uint8_t ssid[32]; /**< SSID of ESP32 soft-AP. If ssid_len field is 0, this must be a Null terminated string. Otherwise, length is set according to ssid_len. */
uint8_t password[64]; /**< Password of ESP32 soft-AP. */
uint8_t ssid_len; /**< Optional length of SSID field. */
uint8_t channel; /**< Channel of ESP32 soft-AP */
wifi_auth_mode_t authmode; /**< Auth mode of ESP32 soft-AP. Do not support AUTH_WEP in soft-AP mode */
uint8_t channel; /**< Channel of soft-AP */
wifi_auth_mode_t authmode; /**< Auth mode of soft-AP. Do not support AUTH_WEP, AUTH_WAPI_PSK and AUTH_OWE in soft-AP mode. When the auth mode is set to WPA2_PSK, WPA2_WPA3_PSK or WPA3_PSK, the pairwise cipher will be overwritten with WIFI_CIPHER_TYPE_CCMP. */
uint8_t ssid_hidden; /**< Broadcast SSID or not, default 0, broadcast the SSID */
uint8_t max_connection; /**< Max number of stations allowed to connect in */
uint16_t beacon_interval; /**< Beacon interval which should be multiples of 100. Unit: TU(time unit, 1 TU = 1024 us). Range: 100 ~ 60000. Default value: 100 */
wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of SoftAP, group cipher will be derived using this. cipher values are valid starting from WIFI_CIPHER_TYPE_TKIP, enum values before that will be considered as invalid and default cipher suites(TKIP+CCMP) will be used. Valid cipher suites in softAP mode are WIFI_CIPHER_TYPE_TKIP, WIFI_CIPHER_TYPE_CCMP and WIFI_CIPHER_TYPE_TKIP_CCMP. */
wifi_cipher_type_t pairwise_cipher; /**< Pairwise cipher of SoftAP, group cipher will be derived using this. Cipher values are valid starting from WIFI_CIPHER_TYPE_TKIP, enum values before that will be considered as invalid and default cipher suites(TKIP+CCMP) will be used. Valid cipher suites in softAP mode are WIFI_CIPHER_TYPE_TKIP, WIFI_CIPHER_TYPE_CCMP and WIFI_CIPHER_TYPE_TKIP_CCMP. */
bool ftm_responder; /**< Enable FTM Responder mode */
wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame */
} wifi_ap_config_t;
@ -359,6 +359,19 @@ typedef enum {
#define WIFI_VENDOR_IE_ELEMENT_ID 0xDD
/**
* @brief Operation Phymode
*/
typedef enum
{
WIFI_PHY_MODE_LR, /**< PHY mode for Low Rate */
WIFI_PHY_MODE_11B, /**< PHY mode for 11b */
WIFI_PHY_MODE_11G, /**< PHY mode for 11g */
WIFI_PHY_MODE_HT20, /**< PHY mode for Bandwidth HT20 */
WIFI_PHY_MODE_HT40, /**< PHY mode for Bandwidth HT40 */
WIFI_PHY_MODE_HE20, /**< PHY mode for Bandwidth HE20 */
} wifi_phy_mode_t;
/**
* @brief Vendor Information Element header
*

@ -1 +1 @@
Subproject commit 3f0144cd0f58073751f76c45f923b382440c58d0
Subproject commit 1aa30ac2b972d84956f30d03197e93f87d9c8950

View File

@ -206,47 +206,6 @@ static void register_mgmt_frames(struct wpa_supplicant *wpa_s)
esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype);
}
static void supplicant_sta_conn_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
u8 bssid[ETH_ALEN];
u8 *ie;
struct wpa_supplicant *wpa_s = &g_wpa_supp;
int ret = esp_wifi_get_assoc_bssid_internal(bssid);
if (ret < 0) {
wpa_printf(MSG_ERROR, "Not able to get connected bssid");
return;
}
struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
if (!bss) {
wpa_printf(MSG_INFO, "connected bss entry not present in scan cache");
return;
}
wpa_s->current_bss = bss;
ie = (u8 *)bss;
ie += sizeof(struct wpa_bss);
ieee802_11_parse_elems(wpa_s, ie, bss->ie_len);
wpa_bss_flush(wpa_s);
/* Register for mgmt frames */
register_mgmt_frames(wpa_s);
/* clear set bssid flag */
clear_bssid_flag(wpa_s);
}
static void supplicant_sta_disconn_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
#ifdef CONFIG_WPA_11KV_SUPPORT
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(wpa_s);
#endif /* CONFIG_WPA_11KV_SUPPORT */
if (wpa_s->current_bss) {
wpa_s->current_bss = NULL;
}
}
#ifdef CONFIG_IEEE80211R
static int handle_auth_frame(u8 *frame, size_t len,
u8 *sender, u32 rssi, u8 channel)
@ -383,11 +342,6 @@ int esp_supplicant_common_init(struct wpa_funcs *wpa_cb)
#endif /* CONFIG_WPA_11KV_SUPPORT */
esp_scan_init(wpa_s);
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED,
&supplicant_sta_conn_handler, NULL);
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED,
&supplicant_sta_disconn_handler, NULL);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R) */
wpa_s->type = 0;
wpa_s->subtype = 0;
@ -419,10 +373,6 @@ void esp_supplicant_common_deinit(void)
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(wpa_s);
#endif /* CONFIG_WPA_11KV_SUPPORT */
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED,
&supplicant_sta_conn_handler);
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED,
&supplicant_sta_disconn_handler);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R) */
if (wpa_s->type) {
wpa_s->type = 0;
@ -444,6 +394,44 @@ void esp_supplicant_common_deinit(void)
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R) */
}
void supplicant_sta_conn_handler(uint8_t *bssid)
{
#if defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R)
u8 *ie;
struct wpa_supplicant *wpa_s = &g_wpa_supp;
struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
if (!bss) {
wpa_printf(MSG_INFO, "connected bss entry not present in scan cache");
return;
}
wpa_s->current_bss = bss;
ie = (u8 *)bss;
ie += sizeof(struct wpa_bss);
ieee802_11_parse_elems(wpa_s, ie, bss->ie_len);
wpa_bss_flush(wpa_s);
/* Register for mgmt frames */
register_mgmt_frames(wpa_s);
/* clear set bssid flag */
clear_bssid_flag(wpa_s);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R) */
}
void supplicant_sta_disconn_handler(void)
{
#if defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R)
struct wpa_supplicant *wpa_s = &g_wpa_supp;
#ifdef CONFIG_WPA_11KV_SUPPORT
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(wpa_s);
#endif /* CONFIG_WPA_11KV_SUPPORT */
if (wpa_s->current_bss) {
wpa_s->current_bss = NULL;
}
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R) */
}
#if defined(CONFIG_WPA_11KV_SUPPORT) || defined(CONFIG_IEEE80211R)
#ifdef CONFIG_WPA_11KV_SUPPORT
bool esp_rrm_is_rrm_supported_connection(void)

View File

@ -44,4 +44,6 @@ int esp_supplicant_common_init(struct wpa_funcs *wpa_cb);
void esp_supplicant_common_deinit(void);
void esp_set_scan_ie(void);
void esp_set_assoc_ie(uint8_t *bssid, const u8 *ies, size_t ies_len, bool add_mdie);
void supplicant_sta_conn_handler(uint8_t* bssid);
void supplicant_sta_disconn_handler(void);
#endif

View File

@ -33,7 +33,7 @@ void *hostap_init(void)
struct wpa_auth_config *auth_conf;
u16 spp_attrubute = 0;
u8 pairwise_cipher;
wifi_pmf_config_t pmf_cfg;
wifi_pmf_config_t pmf_cfg = {0};
hapd = (struct hostapd_data *)os_zalloc(sizeof(struct hostapd_data));
@ -47,7 +47,7 @@ void *hostap_init(void)
os_free(hapd);
return NULL;
}
hapd->conf->max_num_sta = MAX_STA_COUNT;
hapd->conf->max_num_sta = esp_wifi_ap_get_max_sta_conn();
auth_conf = (struct wpa_auth_config *)os_zalloc(sizeof(struct wpa_auth_config));
@ -70,11 +70,12 @@ void *hostap_init(void)
pairwise_cipher = esp_wifi_ap_get_prof_pairwise_cipher_internal();
#ifdef CONFIG_IEEE80211W
esp_wifi_get_pmf_config_internal(&pmf_cfg, WIFI_IF_AP);
if (pmf_cfg.required) {
pairwise_cipher = WIFI_CIPHER_TYPE_CCMP;
if((auth_conf->wpa & WPA_PROTO_RSN) == WPA_PROTO_RSN)
{
esp_wifi_get_pmf_config_internal(&pmf_cfg, WIFI_IF_AP);
if (pmf_cfg.required) {
pairwise_cipher = WIFI_CIPHER_TYPE_CCMP;
}
}
#endif /* CONFIG_IEEE80211W */

View File

@ -118,6 +118,7 @@ struct wpa_funcs {
bool (*wpa_sta_init)(void);
bool (*wpa_sta_deinit)(void);
int (*wpa_sta_connect)(uint8_t *bssid);
void (*wpa_sta_connected_cb)(uint8_t *bssid);
void (*wpa_sta_disconnected_cb)(uint8_t reason_code);
int (*wpa_sta_rx_eapol)(u8 *src_addr, u8 *buf, u32 len);
bool (*wpa_sta_in_4way_handshake)(void);
@ -282,5 +283,7 @@ bool esp_wifi_is_ft_enabled_internal(uint8_t if_index);
uint8_t esp_wifi_sta_get_config_sae_pwe_h2e_internal(void);
uint8_t esp_wifi_sta_get_use_h2e_internal(void);
void esp_wifi_sta_disable_wpa2_authmode_internal(void);
uint8_t esp_wifi_ap_get_max_sta_conn(void);
bool esp_wifi_eb_tx_status_success_internal(void *eb);
#endif /* _ESP_WIFI_DRIVER_H_ */

View File

@ -235,6 +235,11 @@ int wpa_parse_wpa_ie_wrapper(const u8 *wpa_ie, size_t wpa_ie_len, wifi_wpa_ie_t
return ret;
}
static void wpa_sta_connected_cb(uint8_t *bssid)
{
supplicant_sta_conn_handler(bssid);
}
static void wpa_sta_disconnected_cb(uint8_t reason_code)
{
switch (reason_code) {
@ -257,6 +262,8 @@ static void wpa_sta_disconnected_cb(uint8_t reason_code)
#ifdef CONFIG_OWE_STA
owe_deinit();
#endif /* CONFIG_OWE_STA */
supplicant_sta_disconn_handler();
}
#ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
@ -333,6 +340,7 @@ int esp_supplicant_init(void)
wpa_cb->wpa_sta_deinit = wpa_deattach;
wpa_cb->wpa_sta_rx_eapol = wpa_sm_rx_eapol;
wpa_cb->wpa_sta_connect = wpa_sta_connect;
wpa_cb->wpa_sta_connected_cb = wpa_sta_connected_cb;
wpa_cb->wpa_sta_disconnected_cb = wpa_sta_disconnected_cb;
wpa_cb->wpa_sta_in_4way_handshake = wpa_sta_in_4way_handshake;

View File

@ -2750,6 +2750,12 @@ void eapol_txcb(void *eb)
case WPA_FIRST_HALF_4WAY_HANDSHAKE:
break;
case WPA_LAST_HALF_4WAY_HANDSHAKE:
if (esp_wifi_eb_tx_status_success_internal(eb) != true) {
wpa_printf(MSG_ERROR, "Eapol message 4/4 tx failure, not installing keys");
return;
}
if (sm->txcb_flags & WPA_4_4_HANDSHAKE_BIT) {
sm->txcb_flags &= ~WPA_4_4_HANDSHAKE_BIT;
isdeauth = wpa_supplicant_send_4_of_4_txcallback(sm);

View File

@ -1241,7 +1241,7 @@ API :cpp:func:`esp_wifi_set_config()` can be used to configure the station. And
* - bssid
- This is valid only when bssid_set is 1; see field “bssid_set”.
* - channel
- If the channel is 0, the station scans the channel 1 ~ N to search for the target AP; otherwise, the station starts by scanning the channel whose value is the same as that of the “channel” field, and then scans others to find the target AP. If you do not know which channel the target AP is running on, set it to 0.
- If the channel is 0, the station scans the channel 1 ~ N to search for the target AP; otherwise, the station starts by scanning the channel whose value is the same as that of the “channel” field, and then scans the channel 1 ~ N but skip the specific channel to find the target AP. For example, if the channel is 3, the scan order will be 3, 1, 2, 4,..., N. If you do not know which channel the target AP is running on, set it to 0.
* - sort_method
- This field is only for WIFI_ALL_CHANNEL_SCAN.
@ -1620,7 +1620,7 @@ Current implementation of 802.11k includes support for beacon measurement report
Refer ESP-IDF example :idf_file:`examples/wifi/roaming/README.md` to set up and use these APIs. Example code only demonstrates how these APIs can be used, and the application should define its own algorithm and cases as required.
.. only:: esp32s2 or esp32c3
.. only:: SOC_WIFI_FTM_SUPPORT
Wi-Fi Location
-------------------------------

View File

@ -21,7 +21,7 @@ ESP-NOW uses a vendor-specific action frame to transmit ESP-NOW data. The defaul
------------------------------------------------------------------------------------------------------------
| MAC Header | Category Code | Organization Identifier | Random Values | Vendor Specific Content | FCS |
------------------------------------------------------------------------------------------------------------
24 bytes 1 byte 3 bytes 4 bytes 7~255 bytes 4 bytes
24 bytes 1 byte 3 bytes 4 bytes 7~257 bytes 4 bytes
- Category Code: The Category Code field is set to the value(127) indicating the vendor-specific category.
- Organization Identifier: The Organization Identifier contains a unique identifier (0x18fe34), which is the first three bytes of MAC address applied by Espressif.

View File

@ -1242,7 +1242,7 @@ API :cpp:func:`esp_wifi_set_config()` 可用于配置 station。配置的参数
* - bssid
- 只有当 bssid_set 为 1 时有效。见字段 “bssid_set”。
* - channel
- 该字段为 0 时station 扫描信道 1 ~ N 寻找目标 AP否则station 首先扫描值与 “channel” 字段相同的信道,再扫描其他信道。如果您不知道目标 AP 在哪个信道,请将该字段设置为 0。
- 该字段为 0 时station 扫描信道 1 ~ N 寻找目标 AP否则station 首先扫描值与 “channel” 字段相同的信道,再扫描其他信道。比如,当该字段设置为 3 时,扫描顺序为 312...N 。如果您不知道目标 AP 在哪个信道,请将该字段设置为 0。
* - sort_method
- 该字段仅用于 WIFI_ALL_CHANNEL_SCAN 模式。
@ -1620,7 +1620,7 @@ WPA2-Enterprise 是企业无线网络的安全认证机制。在连接到接入
请参考 IDF 示例程序 :idf_file:`examples/wifi/roaming/README.md` 来设置和使用这些 API。示例代码只演示了如何使用这些 API应用程序应根据需要定义自己的算法和案例。
.. only:: esp32s2 or esp32c3
.. only:: SOC_WIFI_FTM_SUPPORT
Wi-Fi Location
-------------------------------

View File

@ -21,7 +21,7 @@ ESP-NOW 使用各个供应商的动作帧传输数据,默认比特率为 1 Mbp
-----------------------------------------------------------------------------------------
| MAC 报头 | 分类代码 | 组织标识符 | 随机值 | 供应商特定内容 | FCS |
-----------------------------------------------------------------------------------------
24 字节 1 字节 3 字节 4 字节 7~255 字节 4 字节
24 字节 1 字节 3 字节 4 字节 7~257 字节 4 字节
- 分类代码:分类代码字段可用于指示各个供应商的类别(比如 127
- 组织标识符:组织标识符包含一个唯一标识符 (比如 0x18fe34),为乐鑫指定的 MAC 地址的前三个字节。

View File

@ -66,8 +66,10 @@ static esp_err_t set_dhcps_dns(esp_netif_t *netif, uint32_t addr)
dns.ip.u_addr.ip4.addr = addr;
dns.ip.type = IPADDR_TYPE_V4;
dhcps_offer_t dhcps_dns_value = OFFER_DNS;
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_stop(netif));
ESP_ERROR_CHECK(esp_netif_dhcps_option(netif, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_dns_value, sizeof(dhcps_dns_value)));
ESP_ERROR_CHECK(esp_netif_set_dns_info(netif, ESP_NETIF_DNS_MAIN, &dns));
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_start(netif));
return ESP_OK;
}