Skip to content

Commit

Permalink
Merge branch 'bugfix/backport_supplicant_fixes_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
fix(wifi): Backport some fixes(v5.2)

See merge request espressif/esp-idf!33976
  • Loading branch information
Jiang Jiang Jian committed Oct 14, 2024
2 parents d4d2448 + 6699f1a commit 90b9629
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 47 deletions.
4 changes: 4 additions & 0 deletions components/wpa_supplicant/esp_supplicant/src/esp_hostap.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "esp_wifi_types.h"
#include "esp_wpa3_i.h"
#include "esp_wps.h"
#include "esp_wps_i.h"

#define WIFI_PASSWORD_LEN_MAX 65

Expand Down Expand Up @@ -238,6 +239,9 @@ bool hostap_deinit(void *data)
esp_wifi_unset_appie_internal(WIFI_APPIE_WPA);
esp_wifi_unset_appie_internal(WIFI_APPIE_ASSOC_RESP);

#ifdef CONFIG_WPS_REGISTRAR
wifi_ap_wps_disable_internal();
#endif
#ifdef CONFIG_SAE
wpa3_hostap_auth_deinit();
/* Wait till lock is released by wpa3 task */
Expand Down
4 changes: 4 additions & 0 deletions components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,27 @@ int wpa3_hostap_post_evt(uint32_t evt_id, uint32_t data)
if (g_wpa3_hostap_evt_queue == NULL) {
WPA3_HOSTAP_AUTH_API_UNLOCK();
os_free(evt);
wpa_printf(MSG_DEBUG, "hostap evt queue NULL");
return ESP_FAIL;
}
} else {
os_free(evt);
wpa_printf(MSG_DEBUG, "g_wpa3_hostap_auth_api_lock not found");
return ESP_FAIL;
}
if (evt->id == SIG_WPA3_RX_CONFIRM || evt->id == SIG_TASK_DEL) {
/* prioritising confirm for completing handshake for committed sta */
if (os_queue_send_to_front(g_wpa3_hostap_evt_queue, &evt, 0) != pdPASS) {
WPA3_HOSTAP_AUTH_API_UNLOCK();
wpa_printf(MSG_DEBUG, "failed to add msg to queue front");
os_free(evt);
return ESP_FAIL;
}
} else {
if (os_queue_send(g_wpa3_hostap_evt_queue, &evt, 0) != pdPASS) {
WPA3_HOSTAP_AUTH_API_UNLOCK();
os_free(evt);
wpa_printf(MSG_DEBUG, "failed to send msg to queue");
return ESP_FAIL;
}
}
Expand Down
69 changes: 38 additions & 31 deletions components/wpa_supplicant/esp_supplicant/src/esp_wps.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void wifi_station_wps_msg_timeout(void *data, void *user_ctx);
void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx);
void wifi_station_wps_success(void *data, void *user_ctx);
void wifi_station_wps_timeout(void *data, void *user_ctx);
int wps_delete_timer(void);

struct wps_sm *gWpsSm = NULL;
static wps_factory_information_t *s_factory_info = NULL;
Expand Down Expand Up @@ -418,11 +419,11 @@ wps_parse_scan_result(struct wps_scan_ie *scan)
wpabuf_free(buf);
if (scan->ssid[1] > SSID_MAX_LEN) {
return false;
}
}
esp_wifi_enable_sta_privacy_internal();
os_memset(sm->ssid[0], 0, SSID_MAX_LEN);
os_memcpy(sm->ssid[0], (char *)&scan->ssid[2], (int)scan->ssid[1]);
sm->ssid_len[0] = scan->ssid[1];
os_memset(sm->creds[0].ssid, 0, SSID_MAX_LEN);
os_memcpy(sm->creds[0].ssid, (char *)&scan->ssid[2], (int)scan->ssid[1]);
sm->creds[0].ssid_len = scan->ssid[1];
if (scan->bssid && memcmp(sm->bssid, scan->bssid, ETH_ALEN) != 0) {
wpa_printf(MSG_INFO, "sm BSSid: "MACSTR " scan BSSID " MACSTR,
MAC2STR(sm->bssid), MAC2STR(scan->bssid));
Expand All @@ -436,7 +437,7 @@ wps_parse_scan_result(struct wps_scan_ie *scan)
wps_build_ic_appie_wps_ar();
}
}
wpa_printf(MSG_DEBUG, "wps discover [%s]", (char *)sm->ssid);
wpa_printf(MSG_DEBUG, "wps discover [%s]", (char *)sm->creds[0].ssid);
sm->channel = scan->chan;

return true;
Expand Down Expand Up @@ -591,15 +592,15 @@ int wps_process_wps_mX_req(u8 *ubuf, int len, enum wps_process_res *res)
if (sm->state == WAIT_START) {
if (expd->opcode != WSC_Start) {
wpa_printf(MSG_DEBUG, "EAP-WSC: Unexpected Op-Code %d "
"in WAIT_START state", expd->opcode);
return ESP_FAIL;
"in WAIT_START state", expd->opcode);
return ESP_ERR_INVALID_STATE;
}
wpa_printf(MSG_DEBUG, "EAP-WSC: Received start");
sm->state = WPA_MESG;
} else if (expd->opcode == WSC_Start){
} else if (expd->opcode == WSC_Start) {
wpa_printf(MSG_DEBUG, "EAP-WSC: Unexpected Op-Code %d",
expd->opcode);
return ESP_FAIL;
expd->opcode);
return ESP_ERR_INVALID_STATE;
}

flag = *(u8 *)(ubuf + sizeof(struct eap_expand));
Expand Down Expand Up @@ -764,8 +765,7 @@ static int wps_sm_init(struct wps_sm *sm)
sm->scan_cnt = 0;
sm->discover_ssid_cnt = 0;
os_bzero(sm->bssid, ETH_ALEN);
os_bzero(sm->ssid, sizeof(sm->ssid));
os_bzero(sm->ssid_len, sizeof(sm->ssid_len));
os_bzero(sm->creds, sizeof(sm->creds));
sm->ap_cred_cnt = 0;

return 0;
Expand Down Expand Up @@ -806,7 +806,8 @@ int wps_finish(void)
if (sm->wps->state == WPS_FINISHED) {
wpa_printf(MSG_DEBUG, "wps finished------>");
wps_set_status(WPS_STATUS_SUCCESS);
wps_stop_connection_timers(sm);
/* WPS finished, dequeue all timers */
wps_delete_timer();

if (sm->ap_cred_cnt == 1) {
wifi_config_t *config = os_zalloc(sizeof(wifi_config_t));
Expand All @@ -816,12 +817,21 @@ int wps_finish(void)
}

esp_wifi_get_config(WIFI_IF_STA, config);
os_memcpy(config->sta.ssid, sm->ssid[0], sm->ssid_len[0]);
os_memcpy(config->sta.password, sm->key[0], sm->key_len[0]);
esp_wifi_disconnect();
os_memcpy(config->sta.ssid, sm->creds[0].ssid, sm->creds[0].ssid_len);
os_memcpy(config->sta.password, sm->creds[0].key, sm->creds[0].key_len);
os_memcpy(config->sta.bssid, sm->bssid, ETH_ALEN);
#ifndef CONFIG_WPS_STRICT
/* Some APs support AES in WPA IE, enable connection with them */
if (sm->creds[0].auth_type == WPS_AUTH_WPAPSK &&
(sm->creds[0].encr_type & WPS_ENCR_AES)) {
config->sta.threshold.authmode = WIFI_AUTH_WPA_PSK;
}
#endif
config->sta.bssid_set = 0;
config->sta.sae_pwe_h2e = 0;
esp_wifi_set_config(WIFI_IF_STA, config);
esp_wifi_connect();

os_free(config);
}
Expand All @@ -834,8 +844,7 @@ int wps_finish(void)
if (sm->ignore_sel_reg) {
sm->discover_ssid_cnt = 0;
esp_wifi_disconnect();
os_bzero(sm->ssid, sizeof(sm->ssid));
os_bzero(sm->ssid_len, sizeof(sm->ssid_len));
os_bzero(sm->creds, sizeof(sm->creds));
wps_add_discard_ap(sm->bssid);
} else {
ret = wps_stop_process(WPS_FAIL_REASON_NORMAL);
Expand Down Expand Up @@ -1058,6 +1067,8 @@ int wps_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len)
wpa_printf(MSG_DEBUG, "sm->wps->state = %d", sm->wps->state);
wps_start_msg_timer();
}
} else if (ret == ESP_ERR_INVALID_STATE) {
ret = ESP_OK;
} else {
ret = ESP_FAIL;
}
Expand Down Expand Up @@ -1285,8 +1296,7 @@ wifi_station_wps_msg_timeout_internal(void)
if (sm->ignore_sel_reg) {
esp_wifi_disconnect();
wps_add_discard_ap(sm->bssid);
os_bzero(sm->ssid, sizeof(sm->ssid));
os_bzero(sm->ssid_len, sizeof(sm->ssid_len));
os_bzero(sm->creds, sizeof(sm->creds));
os_bzero(sm->bssid, ETH_ALEN);
sm->discover_ssid_cnt = 0;
wifi_wps_scan(NULL, NULL);
Expand Down Expand Up @@ -1316,8 +1326,8 @@ void wifi_station_wps_success_internal(void)
if (sm->ap_cred_cnt > 1) {
evt.ap_cred_cnt = sm->ap_cred_cnt;
for (i = 0; i < MAX_WPS_AP_CRED; i++) {
os_memcpy(evt.ap_cred[i].ssid, sm->ssid[i], sm->ssid_len[i]);
os_memcpy(evt.ap_cred[i].passphrase, sm->key[i], sm->key_len[i]);
os_memcpy(evt.ap_cred[i].ssid, sm->creds[i].ssid, sm->creds[i].ssid_len);
os_memcpy(evt.ap_cred[i].passphrase, sm->creds[i].key, sm->creds[i].key_len);
}
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, &evt,
sizeof(evt), OS_BLOCK);
Expand Down Expand Up @@ -1355,17 +1365,13 @@ void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx)

static int save_credentials_cb(void *ctx, const struct wps_credential *cred)
{
if (!gWpsSm || !cred || gWpsSm->ap_cred_cnt > 2) {
struct wps_credential *creds;
if (!gWpsSm || !cred || gWpsSm->ap_cred_cnt >= MAX_CRED_COUNT) {
return ESP_FAIL;
}

os_memset(gWpsSm->ssid[gWpsSm->ap_cred_cnt], 0x00, sizeof(gWpsSm->ssid[gWpsSm->ap_cred_cnt]));
os_memset(gWpsSm->key[gWpsSm->ap_cred_cnt], 0x00, sizeof(gWpsSm->key[gWpsSm->ap_cred_cnt]));

os_memcpy(gWpsSm->ssid[gWpsSm->ap_cred_cnt], cred->ssid, cred->ssid_len);
gWpsSm->ssid_len[gWpsSm->ap_cred_cnt] = cred->ssid_len;
os_memcpy(gWpsSm->key[gWpsSm->ap_cred_cnt], cred->key, cred->key_len);
gWpsSm->key_len[gWpsSm->ap_cred_cnt] = cred->key_len;
creds = &gWpsSm->creds[gWpsSm->ap_cred_cnt];
memcpy(creds, cred, sizeof(*creds));

gWpsSm->ap_cred_cnt++;

Expand Down Expand Up @@ -1618,14 +1624,15 @@ wifi_wps_scan_done(void *arg, ETS_STATUS status)
esp_wifi_disconnect();

os_memcpy(wifi_config.sta.bssid, sm->bssid, ETH_ALEN);
os_memcpy(wifi_config.sta.ssid, (char *)sm->ssid[0], sm->ssid_len[0]);
os_memcpy(wifi_config.sta.ssid, (char *)sm->creds[0].ssid, sm->creds[0].ssid_len);
wifi_config.sta.bssid_set = 1;
wifi_config.sta.channel = sm->channel;
wpa_printf(MSG_INFO, "WPS: connecting to %s, bssid=" MACSTR,
(char *)sm->ssid[0], MAC2STR(wifi_config.sta.bssid));
(char *)sm->creds[0].ssid, MAC2STR(wifi_config.sta.bssid));
esp_wifi_set_config(0, &wifi_config);

wpa_printf(MSG_DEBUG, "WPS: neg start");
wifi_config.sta.failure_retry_cnt = 2;
esp_wifi_connect();
sm->state = WAIT_START;
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
Expand Down
17 changes: 4 additions & 13 deletions components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "esp_wifi_driver.h"
#include "esp_wps.h"
#include "wps/wps.h"
#include "wps/wps_attr_parse.h"

/* WPS message flag */
enum wps_msg_flag {
Expand Down Expand Up @@ -57,15 +59,6 @@ struct discard_ap_list_t{
u8 bssid[6];
};

#ifndef MAX_PASSPHRASE_LEN
#define MAX_PASSPHRASE_LEN 64
#endif

#ifndef MAX_CRED_COUNT
#define MAX_CRED_COUNT 10
#endif

#define WPS_OUTBUF_SIZE 500
struct wps_sm {
u8 state;
struct wps_config *wps_cfg;
Expand All @@ -75,10 +68,7 @@ struct wps_sm {
u8 identity_len;
u8 ownaddr[ETH_ALEN];
u8 bssid[ETH_ALEN];
u8 ssid[MAX_CRED_COUNT][SSID_MAX_LEN];
u8 ssid_len[MAX_CRED_COUNT];
char key[MAX_CRED_COUNT][MAX_PASSPHRASE_LEN];
u8 key_len[MAX_CRED_COUNT];
struct wps_credential creds[MAX_CRED_COUNT];
u8 ap_cred_cnt;
struct wps_device_data *dev;
u8 uuid[16];
Expand Down Expand Up @@ -147,3 +137,4 @@ static inline int wps_set_status(uint32_t status)
bool is_wps_enabled(void);
int wps_init_cfg_pin(struct wps_config *cfg);
void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx);
int wifi_ap_wps_disable_internal(void);
6 changes: 4 additions & 2 deletions components/wpa_supplicant/src/common/wnm_sta.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,10 @@ int wnm_scan_process(struct wpa_supplicant *wpa_s, int reply_on_fail)
enum mbo_transition_reject_reason reason =
MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;

if (!wpa_s->wnm_neighbor_report_elements)
if (!wpa_s->wnm_neighbor_report_elements) {
wpa_printf(MSG_INFO, "WNM: Neighbor report not available");
return 0;
}

wpa_dbg(wpa_s, MSG_DEBUG,
"WNM: Process scan results for BSS Transition Management");
Expand All @@ -706,7 +708,7 @@ int wnm_scan_process(struct wpa_supplicant *wpa_s, int reply_on_fail)
/* Compare the Neighbor Report and scan results */
bss = compare_scan_neighbor_results(wpa_s, 0, &reason);
if (!bss) {
wpa_printf(MSG_DEBUG, "WNM: No BSS transition candidate match found");
wpa_printf(MSG_INFO, "WNM: No BSS transition candidate match found");
status = WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES;
goto send_bss_resp_fail;
}
Expand Down
4 changes: 4 additions & 0 deletions components/wpa_supplicant/src/wps/wps_attr_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ struct wps_parse_attr {
u16 oob_dev_password_len;

/* attributes that can occur multiple times */
#ifdef ESP_SUPPLICANT
#define MAX_CRED_COUNT MAX_WPS_AP_CRED
#else
#define MAX_CRED_COUNT 10
#endif
#define MAX_REQ_DEV_TYPE_COUNT 10

unsigned int num_cred;
Expand Down
2 changes: 1 addition & 1 deletion examples/wifi/roaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This example demonstrate a roaming example using 11k and 11v APIs.
This example demonstrates a roaming example using 802.11k and 802.11v APIs. 802.11r(FT-PSK) is enabled by default in this example.

## How to use example

Expand Down

0 comments on commit 90b9629

Please sign in to comment.