mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-02 18:10:57 +02:00
Merge branch 'refactor/wps_eap_cleanup' into 'master'
refactor(esp_wifi): Remove WPS task code Closes WIFIBUG-1254 and WIFIBUG-1095 See merge request espressif/esp-idf!38555
This commit is contained in:
@@ -814,6 +814,14 @@ menu "Wi-Fi"
|
|||||||
be shared to other devices, making it in readable format increases
|
be shared to other devices, making it in readable format increases
|
||||||
that risk, also passphrase requires pbkdf2 to convert in psk.
|
that risk, also passphrase requires pbkdf2 to convert in psk.
|
||||||
|
|
||||||
|
config ESP_WIFI_WPS_RECONNECT_ON_FAIL
|
||||||
|
bool "Reconnect to previous SSID if WPS failed"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Select this option to enable reconnection to previous SSID if WPS fails.
|
||||||
|
This option will only work if station was connected to a network
|
||||||
|
when WPS was started.
|
||||||
|
|
||||||
endmenu # "WPS Configuration Options"
|
endmenu # "WPS Configuration Options"
|
||||||
|
|
||||||
|
|
||||||
|
@@ -264,7 +264,6 @@ target_compile_definitions(${COMPONENT_LIB} PRIVATE
|
|||||||
EAP_PEAP
|
EAP_PEAP
|
||||||
USE_WPA2_TASK
|
USE_WPA2_TASK
|
||||||
CONFIG_WPS
|
CONFIG_WPS
|
||||||
USE_WPS_TASK
|
|
||||||
ESPRESSIF_USE
|
ESPRESSIF_USE
|
||||||
CONFIG_ECC
|
CONFIG_ECC
|
||||||
CONFIG_IEEE80211W
|
CONFIG_IEEE80211W
|
||||||
@@ -291,6 +290,9 @@ endif()
|
|||||||
if(CONFIG_ESP_WIFI_WPS_STRICT)
|
if(CONFIG_ESP_WIFI_WPS_STRICT)
|
||||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WPS_STRICT)
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WPS_STRICT)
|
||||||
endif()
|
endif()
|
||||||
|
if(CONFIG_ESP_WIFI_WPS_RECONNECT_ON_FAIL)
|
||||||
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WPS_RECONNECT_ON_FAIL)
|
||||||
|
endif()
|
||||||
if(CONFIG_ESP_WIFI_SUITE_B_192)
|
if(CONFIG_ESP_WIFI_SUITE_B_192)
|
||||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_SUITEB192)
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_SUITEB192)
|
||||||
endif()
|
endif()
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -15,21 +15,6 @@ enum wps_msg_flag {
|
|||||||
WPS_MSG_FLAG_LEN = 0x02
|
WPS_MSG_FLAG_LEN = 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USE_WPS_TASK
|
|
||||||
enum wps_sig_type {
|
|
||||||
SIG_WPS_ENABLE = 1, //1
|
|
||||||
SIG_WPS_DISABLE, //2
|
|
||||||
SIG_WPS_START, //3
|
|
||||||
SIG_WPS_RX, //4
|
|
||||||
SIG_WPS_TIMER_TIMEOUT, //5
|
|
||||||
SIG_WPS_TIMER_MSG_TIMEOUT, //6
|
|
||||||
SIG_WPS_TIMER_SUCCESS_CB, //7
|
|
||||||
SIG_WPS_TIMER_SCAN, //8
|
|
||||||
SIG_WPS_TIMER_EAPOL_START, //9
|
|
||||||
SIG_WPS_NUM, //10
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum wps_reg_sig_type {
|
enum wps_reg_sig_type {
|
||||||
SIG_WPS_REG_ENABLE = 1, //1
|
SIG_WPS_REG_ENABLE = 1, //1
|
||||||
SIG_WPS_REG_DISABLE, //2
|
SIG_WPS_REG_DISABLE, //2
|
||||||
@@ -50,10 +35,6 @@ enum wps_sm_state {
|
|||||||
};
|
};
|
||||||
#endif /* ESP_SUPPLICANT */
|
#endif /* ESP_SUPPLICANT */
|
||||||
|
|
||||||
#define WPS_IGNORE_SEL_REG_MAX_CNT 10
|
|
||||||
|
|
||||||
#define WPS_MAX_DIS_AP_NUM 10
|
|
||||||
|
|
||||||
/* Bssid of the discard AP which is discarded for not select reg or other reason */
|
/* Bssid of the discard AP which is discarded for not select reg or other reason */
|
||||||
struct discard_ap_list_t {
|
struct discard_ap_list_t {
|
||||||
u8 bssid[6];
|
u8 bssid[6];
|
||||||
@@ -76,16 +57,9 @@ struct wps_sm {
|
|||||||
u8 current_identifier;
|
u8 current_identifier;
|
||||||
bool is_wps_scan;
|
bool is_wps_scan;
|
||||||
u8 channel;
|
u8 channel;
|
||||||
u8 scan_cnt;
|
|
||||||
#ifdef USE_WPS_TASK
|
|
||||||
u8 wps_sig_cnt[SIG_WPS_NUM];
|
|
||||||
#endif
|
|
||||||
u8 discover_ssid_cnt;
|
u8 discover_ssid_cnt;
|
||||||
bool ignore_sel_reg;
|
|
||||||
bool wps_pbc_overlap;
|
bool wps_pbc_overlap;
|
||||||
struct discard_ap_list_t dis_ap_list[WPS_MAX_DIS_AP_NUM];
|
bool post_m8_recv;
|
||||||
u8 discard_ap_cnt;
|
|
||||||
bool intermediate_disconnect;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define API_MUTEX_TAKE() do {\
|
#define API_MUTEX_TAKE() do {\
|
||||||
@@ -105,8 +79,6 @@ struct wps_sm {
|
|||||||
|
|
||||||
struct wps_sm *wps_sm_get(void);
|
struct wps_sm *wps_sm_get(void);
|
||||||
int wps_station_wps_unregister_cb(void);
|
int wps_station_wps_unregister_cb(void);
|
||||||
int wps_start_pending(void);
|
|
||||||
int wps_sm_rx_eapol(u8 *src_addr, u8 *buf, u32 len);
|
|
||||||
|
|
||||||
int wps_dev_deinit(struct wps_device_data *dev);
|
int wps_dev_deinit(struct wps_device_data *dev);
|
||||||
int wps_dev_init(void);
|
int wps_dev_init(void);
|
||||||
|
@@ -7,27 +7,28 @@
|
|||||||
CONDITIONS OF ANY KIND, either express or implied.
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/**
|
||||||
This example demonstrates how to use WPS.
|
* @brief Demonstrates how to use WPS.
|
||||||
It supports two modes, which can be selected in menuconfig.
|
*
|
||||||
|
* This example supports two modes, which can be selected in menuconfig:
|
||||||
WPS_TYPE_PBC:
|
*
|
||||||
Start ESP32 and it will enter WPS PBC mode. Then push WPS button on the router.
|
* - WPS_TYPE_PBC:
|
||||||
ESP32 will receive SSID and password, and connect to the router.
|
* Start the ESP device and it will enter WPS PBC mode. Then push the WPS button on the router.
|
||||||
|
* The ESP device will receive the SSID and password and connect to the router.
|
||||||
WPS_TYPE_PIN:
|
*
|
||||||
Start ESP32, you'll see an eight-digit PIN number in log output.
|
* - WPS_TYPE_PIN:
|
||||||
Enter the PIN code on the router and then the ESP32 will get connected to router.
|
* Start the ESP device, and you'll see an eight-digit PIN number in the log output.
|
||||||
*/
|
* Enter this PIN code on the router, and the ESP device will connect.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "esp_wifi.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_wps.h"
|
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#include "esp_wps.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
/*set wps mode via project configuration */
|
/*set wps mode via project configuration */
|
||||||
@@ -48,9 +49,50 @@
|
|||||||
|
|
||||||
static const char *TAG = "example_wps";
|
static const char *TAG = "example_wps";
|
||||||
static esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_MODE);
|
static esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_MODE);
|
||||||
static wifi_config_t wps_ap_creds[MAX_WPS_AP_CRED];
|
static wifi_config_t s_wps_ap_creds[MAX_WPS_AP_CRED];
|
||||||
static int s_ap_creds_num = 0;
|
static int s_ap_creds_num = 0;
|
||||||
static int s_retry_num = 0;
|
static int s_retry_num = 0;
|
||||||
|
static bool s_wps_done = false;
|
||||||
|
|
||||||
|
static void wps_restart(void)
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_wps_success(void *event_data)
|
||||||
|
{
|
||||||
|
wifi_event_sta_wps_er_success_t *evt = (wifi_event_sta_wps_er_success_t *)event_data;
|
||||||
|
if (evt) {
|
||||||
|
s_ap_creds_num = evt->ap_cred_cnt;
|
||||||
|
for (int idx = 0; idx < s_ap_creds_num; idx++) {
|
||||||
|
memcpy(s_wps_ap_creds[idx].sta.ssid, evt->ap_cred[idx].ssid,
|
||||||
|
sizeof(evt->ap_cred[idx].ssid));
|
||||||
|
memcpy(s_wps_ap_creds[idx].sta.password, evt->ap_cred[idx].passphrase,
|
||||||
|
sizeof(evt->ap_cred[idx].passphrase));
|
||||||
|
}
|
||||||
|
/* If multiple AP credentials are received from WPS, connect with first one */
|
||||||
|
ESP_LOGI(TAG, "Connecting to SSID: %s, Passphrase: %s",
|
||||||
|
s_wps_ap_creds[0].sta.ssid, s_wps_ap_creds[0].sta.password);
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &s_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());
|
||||||
|
s_wps_done = true;
|
||||||
|
esp_wifi_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_wps_pin(void *event_data)
|
||||||
|
{
|
||||||
|
/* display the PIN code */
|
||||||
|
wifi_event_sta_wps_er_pin_t* event = (wifi_event_sta_wps_er_pin_t*) event_data;
|
||||||
|
ESP_LOGI(TAG, "WPS_PIN = " PINSTR, PIN2STR(event->pin_code));
|
||||||
|
}
|
||||||
|
|
||||||
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
@@ -58,78 +100,46 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
static int ap_idx = 1;
|
static int ap_idx = 1;
|
||||||
|
|
||||||
switch (event_id) {
|
switch (event_id) {
|
||||||
case WIFI_EVENT_STA_START:
|
case WIFI_EVENT_STA_START:
|
||||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
|
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
|
||||||
break;
|
break;
|
||||||
case WIFI_EVENT_STA_DISCONNECTED:
|
case WIFI_EVENT_STA_DISCONNECTED:
|
||||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
|
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
|
||||||
|
if (s_wps_done) {
|
||||||
if (s_retry_num < MAX_RETRY_ATTEMPTS) {
|
if (s_retry_num < MAX_RETRY_ATTEMPTS) {
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
s_retry_num++;
|
s_retry_num++;
|
||||||
|
ESP_LOGI(TAG, "retrying to connect to the AP");
|
||||||
} else if (ap_idx < s_ap_creds_num) {
|
} else if (ap_idx < s_ap_creds_num) {
|
||||||
/* Try the next AP credential if first one fails */
|
/* Try the next AP credential if first one fails */
|
||||||
|
ESP_LOGI(TAG, "Connecting to SSID: %s, Passphrase: %s",
|
||||||
if (ap_idx < s_ap_creds_num) {
|
s_wps_ap_creds[ap_idx].sta.ssid, s_wps_ap_creds[ap_idx].sta.password);
|
||||||
ESP_LOGI(TAG, "Connecting to SSID: %s, Passphrase: %s",
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &s_wps_ap_creds[ap_idx++]));
|
||||||
wps_ap_creds[ap_idx].sta.ssid, wps_ap_creds[ap_idx].sta.password);
|
esp_wifi_connect();
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wps_ap_creds[ap_idx++]) );
|
|
||||||
esp_wifi_connect();
|
|
||||||
}
|
|
||||||
s_retry_num = 0;
|
s_retry_num = 0;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Failed to connect!");
|
ESP_LOGI(TAG, "Failed to connect!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
|
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
|
||||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_SUCCESS");
|
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_SUCCESS");
|
||||||
{
|
handle_wps_success(event_data);
|
||||||
wifi_event_sta_wps_er_success_t *evt =
|
break;
|
||||||
(wifi_event_sta_wps_er_success_t *)event_data;
|
case WIFI_EVENT_STA_WPS_ER_FAILED:
|
||||||
int i;
|
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_FAILED");
|
||||||
|
wps_restart();
|
||||||
if (evt) {
|
break;
|
||||||
s_ap_creds_num = evt->ap_cred_cnt;
|
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
|
||||||
for (i = 0; i < s_ap_creds_num; i++) {
|
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_TIMEOUT");
|
||||||
memcpy(wps_ap_creds[i].sta.ssid, evt->ap_cred[i].ssid,
|
wps_restart();
|
||||||
sizeof(evt->ap_cred[i].ssid));
|
break;
|
||||||
memcpy(wps_ap_creds[i].sta.password, evt->ap_cred[i].passphrase,
|
case WIFI_EVENT_STA_WPS_ER_PIN:
|
||||||
sizeof(evt->ap_cred[i].passphrase));
|
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_PIN");
|
||||||
}
|
handle_wps_pin(event_data);
|
||||||
/* If multiple AP credentials are received from WPS, connect with first one */
|
break;
|
||||||
ESP_LOGI(TAG, "Connecting to SSID: %s, Passphrase: %s",
|
default:
|
||||||
wps_ap_creds[0].sta.ssid, wps_ap_creds[0].sta.password);
|
break;
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_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_wifi_connect();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WIFI_EVENT_STA_WPS_ER_FAILED:
|
|
||||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_FAILED");
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
|
||||||
break;
|
|
||||||
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
|
|
||||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_TIMEOUT");
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
|
||||||
break;
|
|
||||||
case WIFI_EVENT_STA_WPS_ER_PIN:
|
|
||||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_PIN");
|
|
||||||
/* display the PIN code */
|
|
||||||
wifi_event_sta_wps_er_pin_t* event = (wifi_event_sta_wps_er_pin_t*) event_data;
|
|
||||||
ESP_LOGI(TAG, "WPS_PIN = " PINSTR, PIN2STR(event->pin_code));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +150,9 @@ static void got_ip_event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
ESP_LOGI(TAG, "got ip: " IPSTR, IP2STR(&event->ip_info.ip));
|
ESP_LOGI(TAG, "got ip: " IPSTR, IP2STR(&event->ip_info.ip));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*init wifi as sta and start wps*/
|
/**
|
||||||
|
* @brief Start WPS registration
|
||||||
|
*/
|
||||||
static void start_wps(void)
|
static void start_wps(void)
|
||||||
{
|
{
|
||||||
ESP_ERROR_CHECK(esp_netif_init());
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
|
Reference in New Issue
Block a user