esp_wifi: Update wifi lib
1. Add STA checks during STA PMF operations 2. Fix WPA2-Ent issue with Open AP 3. Skip WPA-TKIP profile if PMF is required 4. Skip & clear Supplicant PMK Cache with mismatching AP config 5. Use flag ESP32_WIFI_ENABLE_WPA3_SAE to control WPA3 code, disabling it code footprint reduces by 7.7kB in libwpa_supplicant.a 6. Fix handling of multiple AP credentials in WPS, apps need update to handle the new event for the fix to work Closes https://github.com/espressif/esp-idf/issues/5971
This commit is contained in:
committed by
zhangyanjiao
parent
b8991833ca
commit
ffc87ab7d9
@@ -27,6 +27,7 @@
|
||||
#include "esp_wps.h"
|
||||
#include "esp_event.h"
|
||||
#include "nvs_flash.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*set wps mode via project configuration */
|
||||
@@ -38,6 +39,7 @@
|
||||
#define WPS_MODE WPS_TYPE_DISABLE
|
||||
#endif /*CONFIG_EXAMPLE_WPS_TYPE_PBC*/
|
||||
|
||||
#define MAX_RETRY_ATTEMPTS 2
|
||||
|
||||
#ifndef PIN2STR
|
||||
#define PIN2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7]
|
||||
@@ -46,23 +48,67 @@
|
||||
|
||||
static const char *TAG = "example_wps";
|
||||
static esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_MODE);
|
||||
static wifi_config_t wps_ap_creds[MAX_WPS_AP_CRED];
|
||||
static int s_ap_creds_num = 0;
|
||||
static int s_retry_num = 0;
|
||||
|
||||
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
static int ap_idx = 1;
|
||||
|
||||
switch (event_id) {
|
||||
case WIFI_EVENT_STA_START:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
|
||||
break;
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
if (s_retry_num < MAX_RETRY_ATTEMPTS) {
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
s_retry_num++;
|
||||
} else if (ap_idx < s_ap_creds_num) {
|
||||
/* Try the next AP credential if first one fails */
|
||||
|
||||
if (ap_idx < s_ap_creds_num) {
|
||||
ESP_LOGI(TAG, "Connecting to SSID: %s, Passphrase: %s",
|
||||
wps_ap_creds[ap_idx].sta.ssid, wps_ap_creds[ap_idx].sta.password);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wps_ap_creds[ap_idx++]) );
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
}
|
||||
s_retry_num = 0;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Failed to connect!");
|
||||
}
|
||||
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_SUCCESS");
|
||||
/* esp_wifi_wps_start() only gets ssid & password, so call esp_wifi_connect() here. */
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
{
|
||||
wifi_event_sta_wps_er_success_t *evt =
|
||||
(wifi_event_sta_wps_er_success_t *)event_data;
|
||||
int i;
|
||||
|
||||
if (evt) {
|
||||
s_ap_creds_num = evt->ap_cred_cnt;
|
||||
for (i = 0; i < s_ap_creds_num; i++) {
|
||||
memcpy(wps_ap_creds[i].sta.ssid, evt->ap_cred[i].ssid,
|
||||
sizeof(evt->ap_cred[i].ssid));
|
||||
memcpy(wps_ap_creds[i].sta.password, evt->ap_cred[i].passphrase,
|
||||
sizeof(evt->ap_cred[i].passphrase));
|
||||
}
|
||||
/* If multiple AP credentials are received from WPS, connect with first one */
|
||||
ESP_LOGI(TAG, "Connecting to SSID: %s, Passphrase: %s",
|
||||
wps_ap_creds[0].sta.ssid, wps_ap_creds[0].sta.password);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wps_ap_creds[0]) );
|
||||
}
|
||||
/*
|
||||
* If only one AP credential is received from WPS, there will be no event data and
|
||||
* esp_wifi_set_config() is already called by WPS modules for backward compatibility
|
||||
* with legacy apps. So directly attempt connection here.
|
||||
*/
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
}
|
||||
break;
|
||||
case WIFI_EVENT_STA_WPS_ER_FAILED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_FAILED");
|
||||
|
||||
Reference in New Issue
Block a user