mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/wps_wpa_connection' into 'master'
fix(esp_wifi): Allow connection with WPA mode in WPS See merge request espressif/esp-idf!32360
This commit is contained in:
commit
1ac6043bce
@ -440,9 +440,9 @@ wps_parse_scan_result(struct wps_scan_ie *scan)
|
||||
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));
|
||||
@ -468,7 +468,7 @@ wps_parse_scan_result(struct wps_scan_ie *scan)
|
||||
}
|
||||
}
|
||||
wpabuf_free(buf);
|
||||
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;
|
||||
@ -793,8 +793,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;
|
||||
@ -845,9 +844,16 @@ 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]);
|
||||
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);
|
||||
@ -863,8 +869,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);
|
||||
@ -1313,8 +1318,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);
|
||||
@ -1344,8 +1348,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);
|
||||
@ -1383,17 +1387,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++;
|
||||
|
||||
@ -1646,11 +1646,11 @@ 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");
|
||||
|
@ -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 {
|
||||
@ -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;
|
||||
@ -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];
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user