Merge branch 'bugfix/softap_beacon_process_v4.3' into 'release/v4.3'

esp_wifi: validate softAP interface when sending beacon and add sta_connected callback (Backport v4.3)

See merge request espressif/esp-idf!23264
This commit is contained in:
Jiang Jiang Jian
2023-04-23 10:31:05 +08:00
5 changed files with 50 additions and 55 deletions

View File

@ -161,8 +161,10 @@ static void clear_bssid_flag(struct wpa_supplicant *wpa_s)
}
esp_wifi_get_config(WIFI_IF_STA, config);
config->sta.bssid_set = 0;
esp_wifi_set_config(WIFI_IF_STA, config);
if (config->sta.bssid_set) {
config->sta.bssid_set = 0;
esp_wifi_set_config(WIFI_IF_STA, config);
}
os_free(config);
wpa_printf(MSG_DEBUG, "cleared bssid flag");
}
@ -185,49 +187,6 @@ static void register_action_frame(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 action frames */
register_action_frame(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;
wifi_event_sta_disconnected_t *disconn = event_data;
wpas_rrm_reset(wpa_s);
if (wpa_s->current_bss) {
wpa_s->current_bss = NULL;
}
if (disconn->reason != WIFI_REASON_ROAMING) {
clear_bssid_flag(wpa_s);
}
}
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
static int ieee80211_handle_rx_frm(u8 type, u8 *frame, size_t len, u8 *sender,
u32 rssi, u8 channel, u64 current_tsf)
@ -289,11 +248,6 @@ int esp_supplicant_common_init(struct wpa_funcs *wpa_cb)
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(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) */
wpa_s->type = 0;
wpa_s->subtype = 0;
@ -317,10 +271,6 @@ void esp_supplicant_common_deinit(void)
esp_scan_deinit(wpa_s);
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(wpa_s);
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) */
if (wpa_s->type) {
wpa_s->type = 0;
@ -341,6 +291,41 @@ void esp_supplicant_common_deinit(void)
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
}
void supplicant_sta_conn_handler(uint8_t *bssid)
{
#if defined(CONFIG_WPA_11KV_SUPPORT)
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_action_frame(wpa_s);
/* clear set bssid flag */
clear_bssid_flag(wpa_s);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT)*/
}
void supplicant_sta_disconn_handler(void)
{
#if defined(CONFIG_WPA_11KV_SUPPORT)
struct wpa_supplicant *wpa_s = &g_wpa_supp;
wpas_rrm_reset(wpa_s);
if (wpa_s->current_bss) {
wpa_s->current_bss = NULL;
}
clear_bssid_flag(wpa_s);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
}
#if defined(CONFIG_WPA_11KV_SUPPORT)
bool esp_rrm_is_rrm_supported_connection(void)
{

View File

@ -50,4 +50,6 @@ static inline void esp_set_rm_enabled_ie(void) {}
int esp_supplicant_common_init(struct wpa_funcs *wpa_cb);
void esp_supplicant_common_deinit(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

@ -120,6 +120,7 @@ struct wpa_funcs {
bool (*wpa_sta_init)(void);
bool (*wpa_sta_deinit)(void);
void (*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);

View File

@ -200,6 +200,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) {
@ -220,6 +225,7 @@ static void wpa_sta_disconnected_cb(uint8_t reason_code)
default:
break;
}
supplicant_sta_disconn_handler();
}
int esp_supplicant_init(void)
@ -235,6 +241,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;