diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.eco4.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.eco4.ld index 7848cf885a..46bddfd4c0 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.eco4.ld @@ -19,7 +19,7 @@ lmacDiscardMSDU = 0x40001b18; lmacEndFrameExchangeSequence = 0x40001b1c; lmacMSDUAged = 0x40001b28; //lmacSetTxFrame = 0x40001b4c; -pm_check_state = 0x40001b6c; +/* pm_check_state = 0x40001b6c; */ pm_dream = 0x40001b78; pm_on_beacon_rx = 0x40001ba0; //pm_parse_beacon = 0x40001bac; @@ -57,7 +57,7 @@ ppTxFragmentProc = 0x40001e08; esf_buf_setup = 0x40001e0c; hal_crypto_set_key_entry = 0x40001e18; /*pm_start = 0x40001e34;*/ -pm_stop = 0x40001e38; +/*pm_stop = 0x40001e38;*/ hal_set_sta_tbtt = 0x40001e4c; //pm_update_next_tbtt = 0x40001e50; pm_set_sleep_type = 0x40001e54; diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index 0df4950951..6f7a77265e 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -493,7 +493,7 @@ hal_mac_tx_get_blockack = 0x40001af4; /*hal_mac_tx_set_ppdu = 0x40001af8;*/ ic_get_trc = 0x40001afc; /* ic_mac_deinit = 0x40001b00; */ -ic_mac_init = 0x40001b04; +/* ic_mac_init = 0x40001b04; */ ic_interface_enabled = 0x40001b08; is_lmac_idle = 0x40001b0c; /*lmacAdjustTimestamp = 0x40001b10;*/ diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld index 5dec621359..d10b0524de 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld @@ -14,7 +14,7 @@ lmacTxDone = 0x4000162c; /*lmacTxFrame = 0x40001630;*/ mac_tx_set_htsig = 0x40001638; mac_tx_set_plcp1 = 0x40001640; -pm_check_state = 0x40001648; +/* pm_check_state = 0x40001648; */ /*pm_on_beacon_rx = 0x4000167c;*/ /*pm_parse_beacon = 0x40001688;*/ /*pm_process_tim = 0x4000168c;*/ diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index 1220dcdc33..b7fc458124 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -683,7 +683,7 @@ hal_mac_tx_get_blockack = 0x400015d0; /* hal_mac_tx_set_ppdu = 0x400015d4;*/ ic_get_trc = 0x400015d8; /* ic_mac_deinit = 0x400015dc; */ -ic_mac_init = 0x400015e0; +/* ic_mac_init = 0x400015e0; */ ic_interface_enabled = 0x400015e4; is_lmac_idle = 0x400015e8; /*lmacAdjustTimestamp = 0x400015ec;*/ diff --git a/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld b/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld index 1a862d0990..11741fde65 100644 --- a/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld +++ b/components/esp_rom/esp32c5/ld/esp32c5.rom.net80211.ld @@ -36,7 +36,7 @@ ic_reset_extra_softap_rx_ba = 0x40000b50; ieee80211_align_eb = 0x40000b54; ieee80211_ampdu_reorder = 0x40000b58; ieee80211_ampdu_start_age_timer = 0x40000b5c; -ieee80211_encap_esfbuf = 0x40000b60; +/*ieee80211_encap_esfbuf = 0x40000b60;*/ ieee80211_is_tx_allowed = 0x40000b64; ieee80211_output_pending_eb = 0x40000b68; ieee80211_output_process = 0x40000b6c; diff --git a/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld b/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld index 875ea947df..0f66f607be 100644 --- a/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld +++ b/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld @@ -53,7 +53,7 @@ hal_get_tsf_time = 0x40000c64; hal_get_sta_tsf = 0x40000c68; ic_get_trc = 0x40000c74; ic_mac_deinit = 0x40000c78; -ic_mac_init = 0x40000c7c; +/* ic_mac_init = 0x40000c7c; */ ic_interface_enabled = 0x40000c80; is_lmac_idle = 0x40000c84; ic_get_he_rts_threshold_bytes = 0x40000c88; @@ -104,7 +104,7 @@ mac_tx_set_tb = 0x40000d38; mac_tx_set_mplen = 0x40000d3c; mac_tx_set_txop_q = 0x40000d40; mac_tx_set_pti = 0x40000d44; -pm_check_state = 0x40000d48; +/*pm_check_state = 0x40000d48;*/ pm_disable_dream_timer = 0x40000d4c; pm_disable_sleep_delay_timer = 0x40000d50; pm_dream = 0x40000d54; diff --git a/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld b/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld index 0465d92762..105d01a0f1 100644 --- a/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld +++ b/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld @@ -31,7 +31,7 @@ hal_mac_tx_get_blockack = 0x40000bfc; //hal_mac_tx_set_ppdu = 0x40000c00; ic_get_trc = 0x40000c04; //ic_mac_deinit = 0x40000c08; -ic_mac_init = 0x40000c0c; +/* ic_mac_init = 0x40000c0c; */ ic_interface_enabled = 0x40000c10; is_lmac_idle = 0x40000c14; /*lmacAdjustTimestamp = 0x40000c18;*/ diff --git a/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld b/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld index 2fb70a00f3..aa52ae4d88 100644 --- a/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld +++ b/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld @@ -60,7 +60,7 @@ dbg_hal_check_clr_mplen_bitmap = 0x40000bdc; dbg_hal_check_set_mplen_bitmap = 0x40000be0; ic_get_trc = 0x40000be4; ic_mac_deinit = 0x40000be8; -ic_mac_init = 0x40000bec; +/* ic_mac_init = 0x40000bec; */ ic_interface_enabled = 0x40000bf0; is_lmac_idle = 0x40000bf4; ic_get_he_rts_threshold_bytes = 0x40000bf8; @@ -110,7 +110,7 @@ mac_tx_set_tb = 0x40000ca4; mac_tx_set_mplen = 0x40000ca8; mac_tx_set_txop_q = 0x40000cac; mac_tx_set_pti = 0x40000cb0; -pm_check_state = 0x40000cb4; +/* pm_check_state = 0x40000cb4; */ pm_disable_dream_timer = 0x40000cb8; pm_disable_sleep_delay_timer = 0x40000cbc; pm_dream = 0x40000cc0; diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index bf4c37ddc8..9cf3e823c8 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -936,7 +936,7 @@ hal_mac_tx_get_blockack = 0x400052b0; /* hal_mac_tx_set_ppdu = 0x400052bc;*/ ic_get_trc = 0x400052c8; /* ic_mac_deinit = 0x400052d4; */ -ic_mac_init = 0x400052e0; +/* ic_mac_init = 0x400052e0; */ ic_interface_enabled = 0x400052ec; is_lmac_idle = 0x400052f8; /*lmacAdjustTimestamp = 0x40005304;*/ diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 603e5b6573..e45c091363 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -999,6 +999,7 @@ esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter * - ESP_ERR_WIFI_MODE: invalid mode * - ESP_ERR_WIFI_PASSWORD: invalid password * - ESP_ERR_WIFI_NVS: WiFi internal NVS error + * - ESP_ERR_WIFI_STATE: WiFi still connecting when invoke esp_wifi_set_config * - others: refer to the error code in esp_err.h */ esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf); diff --git a/components/esp_wifi/include/esp_wifi_types_generic.h b/components/esp_wifi/include/esp_wifi_types_generic.h index cabb434a39..2cc2fa008a 100644 --- a/components/esp_wifi/include/esp_wifi_types_generic.h +++ b/components/esp_wifi/include/esp_wifi_types_generic.h @@ -246,6 +246,7 @@ typedef struct { wifi_scan_channel_bitmap_t channel_bitmap; /**< Channel bitmap for setting specific channels to be scanned. Please note that the 'channel' parameter above needs to be set to 0 to allow scanning by bitmap. Also, note that only allowed channels configured by wifi_country_t can be scanned. */ + bool coex_background_scan; /**< Enable it to scan return home channel under coexist */ } wifi_scan_config_t; /** @@ -1116,6 +1117,9 @@ typedef enum { WIFI_EVENT_AP_WRONG_PASSWORD, /**< a station tried to connect with wrong password */ WIFI_EVENT_STA_BEACON_OFFSET_UNSTABLE, /**< Station sampled beacon offset unstable */ + WIFI_EVENT_DPP_URI_READY, /**< DPP URI is ready through Bootstrapping */ + WIFI_EVENT_DPP_CFG_RECVD, /**< Config received via DPP Authentication */ + WIFI_EVENT_DPP_FAILED, /**< DPP failed */ WIFI_EVENT_MAX, /**< Invalid Wi-Fi event ID */ } wifi_event_t; @@ -1520,6 +1524,22 @@ typedef struct { float beacon_success_rate; /**< Received beacon success rate */ } wifi_event_sta_beacon_offset_unstable_t; +/** Argument structure for WIFI_EVENT_DPP_URI_READY event */ +typedef struct { + uint32_t uri_data_len; /**< URI data length including null termination */ + char uri[]; /**< URI data */ +} wifi_event_dpp_uri_ready_t; + +/** Argument structure for WIFI_EVENT_DPP_CFG_RECVD event */ +typedef struct { + wifi_config_t wifi_cfg; /**< Received WIFI config in DPP */ +} wifi_event_dpp_config_received_t; + +/** Argument structure for WIFI_EVENT_DPP_FAIL event */ +typedef struct { + int failure_reason; /**< Failure reason */ +} wifi_event_dpp_failed_t; + #ifdef __cplusplus } #endif diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index c163646647..583c685668 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit c1636466476b3ebbbbfbdb9122285008d5a7daf4 +Subproject commit 583c685668cc420e60f5f22148ddf10c32e94cc3 diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h b/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h index 5330c5dbe8..0346ee71f5 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -55,7 +55,10 @@ typedef void (*esp_supp_dpp_event_cb_t)(esp_supp_dpp_event_t evt, void *data); * * Starts DPP Supplicant and initializes related Data Structures. * - * @param evt_cb Callback function to receive DPP related events + * @note The `evt_cb` parameter is deprecated and will be ignored in future IDF versions. + * Directly register for WiFi events to get DPP events. + * + * @param evt_cb (Deprecated) Callback function to receive DPP related events * * return * - ESP_OK: Success diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c index d984a49a07..17ce5408ea 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp.c @@ -19,6 +19,7 @@ #include "esp_wps_i.h" #include "rsn_supp/wpa.h" #include "rsn_supp/pmksa_cache.h" +#include #ifdef CONFIG_DPP @@ -31,8 +32,11 @@ struct action_rx_param { }; static void *s_dpp_api_lock = NULL; +static void *s_dpp_event_group = NULL; -static bool s_dpp_listen_in_progress; +#define DPP_ROC_EVENT_HANDLED BIT0 + +static atomic_bool roc_in_progress; static struct esp_dpp_context_t s_dpp_ctx; static int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel); static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action; @@ -41,6 +45,7 @@ static void tx_status_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); static void roc_status_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); +static void dpp_listen_next_channel(void *data, void *user_ctx); static esp_err_t dpp_api_lock(void) { if (!s_dpp_api_lock) { @@ -65,7 +70,30 @@ static esp_err_t dpp_api_unlock(void) return ESP_OK; } -static uint8_t esp_dpp_deinit_auth(void) +static void dpp_event_handler(void *arg, esp_event_base_t event_base, + int32_t event_id, void *event_data) +{ + if (!s_dpp_ctx.dpp_event_cb) { + return; + } + switch (event_id) { + case WIFI_EVENT_DPP_URI_READY: + wifi_event_dpp_uri_ready_t *event = (wifi_event_dpp_uri_ready_t *) event_data; + s_dpp_ctx.dpp_event_cb(ESP_SUPP_DPP_URI_READY, (void *)(event->uri)); + break; + case WIFI_EVENT_DPP_CFG_RECVD: + s_dpp_ctx.dpp_event_cb(ESP_SUPP_DPP_CFG_RECVD, (wifi_config_t *)event_data); + break; + case WIFI_EVENT_DPP_FAILED: + s_dpp_ctx.dpp_event_cb(ESP_SUPP_DPP_FAIL, (void *)event_data); + break; + default: + break; + } + return; +} + +static uint8_t dpp_deinit_auth(void) { if (s_dpp_ctx.dpp_auth) { dpp_auth_deinit(s_dpp_ctx.dpp_auth); @@ -75,24 +103,38 @@ static uint8_t esp_dpp_deinit_auth(void) return ESP_OK; } -static void listen_stop_handler(void *data, void *user_ctx) +static int listen_stop_handler(void *data, void *user_ctx) { wifi_roc_req_t req = {0}; - s_dpp_listen_in_progress = false; + wpa_printf(MSG_DEBUG, "DPP: Stoping ROC"); req.ifx = WIFI_IF_STA; req.type = WIFI_ROC_CANCEL; + eloop_cancel_timeout(dpp_listen_next_channel, NULL, NULL); + s_dpp_ctx.dpp_listen_ongoing = false; esp_wifi_remain_on_channel(&req); + + return 0; } -static void esp_dpp_call_cb(esp_supp_dpp_event_t evt, void *data) +static void dpp_stop(void) { if (s_dpp_ctx.dpp_auth) { - esp_dpp_deinit_auth(); + dpp_deinit_auth(); listen_stop_handler(NULL, NULL); } - s_dpp_ctx.dpp_event_cb(evt, data); +} + +static void dpp_abort_with_failure(uint32_t failure_reason) +{ + /* Stop DPP*/ + dpp_stop(); + + /* Send event to APP */ + wifi_event_dpp_failed_t event = {0}; + event.failure_reason = failure_reason; + esp_event_post(WIFI_EVENT, WIFI_EVENT_DPP_FAILED, &event, sizeof(event), OS_BLOCK); } static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx) @@ -103,7 +145,7 @@ static void esp_dpp_auth_conf_wait_timeout(void *eloop_ctx, void *timeout_ctx) wpa_printf(MSG_INFO, "DPP: Terminate authentication exchange due to Auth Confirm timeout"); - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_AUTH_TIMEOUT); + dpp_abort_with_failure(ESP_ERR_DPP_AUTH_TIMEOUT); } esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len, @@ -129,7 +171,7 @@ esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint3 if (ESP_OK != esp_wifi_action_tx_req(req)) { wpa_printf(MSG_ERROR, "DPP: Failed to perform offchannel operation"); - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE); + dpp_abort_with_failure(ESP_ERR_DPP_TX_FAILURE); os_free(req); return ESP_FAIL; } @@ -231,7 +273,7 @@ static void gas_query_timeout(void *eloop_data, void *user_ctx) wpabuf_free(auth->conf_req); auth->conf_req = NULL; } - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_CONF_TIMEOUT); + dpp_abort_with_failure(ESP_ERR_DPP_CONF_TIMEOUT); } static int gas_query_req_tx(struct dpp_authentication *auth) @@ -244,7 +286,7 @@ static int gas_query_req_tx(struct dpp_authentication *auth) supp_op_classes); if (!buf) { wpa_printf(MSG_ERROR, "DPP: No configuration request data available"); - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_FAILURE); + dpp_abort_with_failure(ESP_ERR_DPP_FAILURE); return ESP_FAIL; } @@ -292,10 +334,15 @@ static int esp_dpp_handle_config_obj(struct dpp_authentication *auth, wpa_printf(MSG_INFO, DPP_EVENT_CONNECTOR "%s", conf->connector); } - if (s_dpp_listen_in_progress) { + if (atomic_load(&roc_in_progress)) { listen_stop_handler(NULL, NULL); } - esp_dpp_call_cb(ESP_SUPP_DPP_CFG_RECVD, wifi_cfg); + /* deinit AUTH since authentication is done */ + dpp_deinit_auth(); + + wifi_event_dpp_config_received_t event = {0}; + event.wifi_cfg = s_dpp_ctx.wifi_cfg; + esp_event_post(WIFI_EVENT, WIFI_EVENT_DPP_CFG_RECVD, &event, sizeof(event), OS_BLOCK); return 0; } @@ -548,7 +595,7 @@ static void esp_dpp_rx_action(void *data, void *user_ctx) (size_t)(public_action->v.pa_vendor_spec.vendor_data - (u8 *)rx_param->action_frm); - if (s_dpp_listen_in_progress) { + if (atomic_load(&roc_in_progress)) { listen_stop_handler(NULL, NULL); } @@ -570,11 +617,11 @@ static void esp_dpp_rx_action(void *data, void *user_ctx) os_free(rx_param); if (ret != ESP_OK) { - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_FAILURE); + dpp_abort_with_failure(ESP_ERR_DPP_FAILURE); } } -void esp_dpp_listen_next_channel(void *data, void *user_ctx) +static void dpp_listen_next_channel(void *data, void *user_ctx) { struct dpp_bootstrap_params_t *p = &s_dpp_ctx.bootstrap_params; static int counter; @@ -582,10 +629,14 @@ void esp_dpp_listen_next_channel(void *data, void *user_ctx) esp_err_t ret = 0; wifi_roc_req_t req = {0}; + if (!s_dpp_ctx.dpp_listen_ongoing) { + return; + } if (p->num_chan <= 0) { wpa_printf(MSG_ERROR, "Listen channel not set"); return; } + channel = p->chan_list[counter++ % p->num_chan]; wpa_printf(MSG_DEBUG, "DPP: Starting ROC on channel %d", channel); @@ -600,12 +651,14 @@ void esp_dpp_listen_next_channel(void *data, void *user_ctx) wpa_printf(MSG_ERROR, "Failed ROC. error : 0x%x", ret); return; } + os_event_group_clear_bits(s_dpp_event_group, DPP_ROC_EVENT_HANDLED); } static void esp_dpp_bootstrap_gen(void *data, void *user_ctx) { char *command = data; const char *uri; + uint32_t len; s_dpp_ctx.id = dpp_bootstrap_gen(s_dpp_ctx.dpp_global, command); @@ -618,7 +671,17 @@ static void esp_dpp_bootstrap_gen(void *data, void *user_ctx) } uri = dpp_bootstrap_get_uri(s_dpp_ctx.dpp_global, s_dpp_ctx.id); - esp_dpp_call_cb(ESP_SUPP_DPP_URI_READY, (void *)uri); + wifi_event_dpp_uri_ready_t *event; + len = sizeof(*event) + os_strlen(uri) + 1; + event = os_malloc(len); + if (!event) { + return; + } + event->uri_data_len = os_strlen(uri); + os_memcpy(event->uri, uri, event->uri_data_len); + event->uri[event->uri_data_len++] = '\0'; + esp_event_post(WIFI_EVENT, WIFI_EVENT_DPP_URI_READY, event, len, OS_BLOCK); + os_free(event); os_free(command); dpp_api_lock(); s_dpp_ctx.bootstrap_done = true; @@ -638,6 +701,14 @@ static int esp_dpp_deinit(void *data, void *user_ctx) esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE, &roc_status_handler); + if (s_dpp_ctx.dpp_event_cb) { + esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_DPP_URI_READY, + &dpp_event_handler); + esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_DPP_CFG_RECVD, + &dpp_event_handler); + esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_DPP_FAILED, + &dpp_event_handler); + } if (params->info) { os_free(params->info); params->info = NULL; @@ -653,6 +724,11 @@ static int esp_dpp_deinit(void *data, void *user_ctx) } s_dpp_ctx.dpp_init_done = false; s_dpp_ctx.bootstrap_done = false; + s_dpp_ctx.dpp_event_cb = NULL; + if (s_dpp_event_group) { + os_event_group_delete(s_dpp_event_group); + s_dpp_event_group = NULL; + } return 0; } @@ -698,7 +774,7 @@ static void esp_dpp_auth_resp_retry(void *eloop_ctx, void *timeout_ctx) auth->auth_resp_tries++; if (auth->auth_resp_tries >= max_tries) { wpa_printf(MSG_INFO, "DPP: No confirm received from initiator - stopping exchange"); - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE); + dpp_abort_with_failure(ESP_ERR_DPP_TX_FAILURE); return; } @@ -724,29 +800,30 @@ static void tx_status_handler(void *arg, esp_event_base_t event_base, return; } if (!auth) { - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_FAILURE); + wpa_printf(MSG_DEBUG, "Auth already deinitialized, return"); return; } if (auth->waiting_auth_conf) { eloop_cancel_timeout(esp_dpp_auth_resp_retry_timeout, NULL, NULL); - if (evt->status) { + if (evt->status == WIFI_ACTION_TX_FAILED) { /* failed to send auth response frame */ eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL); eloop_register_timeout(1, 0, esp_dpp_auth_resp_retry, NULL, NULL); - } else { + } else if (evt->status == WIFI_ACTION_TX_DONE) { eloop_cancel_timeout(esp_dpp_auth_conf_wait_timeout, NULL, NULL); eloop_register_timeout(ESP_DPP_AUTH_TIMEOUT_SECS, 0, esp_dpp_auth_conf_wait_timeout, NULL, NULL); } } else if (auth->auth_success) { - if (evt->status) { + if (evt->status == WIFI_ACTION_TX_FAILED) { /* failed to send gas query frame, retry logic needed? */ wpa_printf(MSG_WARNING, "DPP: failed to send GAS query frame"); - esp_dpp_call_cb(ESP_SUPP_DPP_FAIL, (void *)ESP_ERR_DPP_TX_FAILURE); - } else { + dpp_abort_with_failure(ESP_ERR_DPP_TX_FAILURE); + } else if (evt->status == WIFI_ACTION_TX_DONE) { eloop_cancel_timeout(gas_query_timeout, NULL, auth); eloop_register_timeout(ESP_GAS_TIMEOUT_SECS, 0, gas_query_timeout, NULL, auth); } } + atomic_store(&roc_in_progress, true); } static void roc_status_handler(void *arg, esp_event_base_t event_base, @@ -754,9 +831,13 @@ static void roc_status_handler(void *arg, esp_event_base_t event_base, { wifi_event_roc_done_t *evt = (wifi_event_roc_done_t *)event_data; - if (s_dpp_listen_in_progress && evt->context == (uint32_t)s_action_rx_cb) { - eloop_register_timeout(0, 0, esp_dpp_listen_next_channel, NULL, NULL); + if (evt->context == (uint32_t)s_action_rx_cb) { + eloop_cancel_timeout(dpp_listen_next_channel, NULL, NULL); + eloop_register_timeout(0, 0, dpp_listen_next_channel, NULL, NULL); } + + atomic_store(&roc_in_progress, false); + os_event_group_set_bits(s_dpp_event_group, DPP_ROC_EVENT_HANDLED); } static char *esp_dpp_parse_chan_list(const char *chan_list) @@ -916,6 +997,12 @@ fail: return ret; } +static void dpp_listen_start(void *ctx, void *data) +{ + s_dpp_ctx.dpp_listen_ongoing = true; + dpp_listen_next_channel(NULL, NULL); +} + esp_err_t esp_supp_dpp_start_listen(void) { int ret = dpp_api_lock(); @@ -933,18 +1020,24 @@ esp_err_t esp_supp_dpp_start_listen(void) wpa_printf(MSG_ERROR, "DPP: ROC not possible before wifi is started"); return ESP_ERR_INVALID_STATE; } - wpa_printf(MSG_DEBUG, "DPP: Starting ROC"); /* cancel previous ROC if ongoing */ esp_supp_dpp_stop_listen(); - s_dpp_listen_in_progress = true; - eloop_register_timeout(0, 0, esp_dpp_listen_next_channel, NULL, NULL); + + /* Give ample time to set the bit, timeout is necessary when ROC is not running previously */ + os_event_group_wait_bits(s_dpp_event_group, DPP_ROC_EVENT_HANDLED, 0, 0, os_task_ms_to_tick(100)); + wpa_printf(MSG_DEBUG, "DPP: Starting ROC"); + eloop_register_timeout(0, 0, dpp_listen_start, NULL, NULL); return 0; } esp_err_t esp_supp_dpp_stop_listen(void) { - eloop_register_timeout(0, 0, listen_stop_handler, NULL, NULL); + int ret = eloop_register_timeout_blocking(listen_stop_handler, NULL, NULL); + + if (ret) { + return ESP_FAIL; + } return ESP_OK; } @@ -980,14 +1073,22 @@ static int esp_dpp_init(void *eloop_data, void *user_ctx) goto init_fail; } - s_dpp_listen_in_progress = false; s_dpp_ctx.dpp_event_cb = cb; + if (cb) { + esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_DPP_URI_READY, + &dpp_event_handler, NULL); + esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_DPP_CFG_RECVD, + &dpp_event_handler, NULL); + esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_DPP_FAILED, + &dpp_event_handler, NULL); + } esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ACTION_TX_STATUS, &tx_status_handler, NULL); esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ROC_DONE, &roc_status_handler, NULL); + s_dpp_event_group = os_event_group_create(); wpa_printf(MSG_INFO, "DPP: dpp init done"); s_dpp_ctx.dpp_init_done = true; diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h b/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h index 651dfdbcc3..a0c6c9a475 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h @@ -40,6 +40,7 @@ struct esp_dpp_context_t { int id; bool dpp_init_done; bool bootstrap_done; + bool dpp_listen_ongoing; }; #ifdef CONFIG_TESTING_OPTIONS diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c b/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c index ab488f2155..45b7e90768 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c @@ -22,6 +22,7 @@ #include "esp_wps.h" #include "esp_wps_i.h" +#include "rsn_supp/wpa.h" #include "ap/sta_info.h" #include "common/sae.h" #include "ap/ieee802_11.h" @@ -172,7 +173,7 @@ void *hostap_init(void) } #endif /* CONFIG_IEEE80211W */ - + esp_wifi_ap_set_group_mgmt_cipher_internal(cipher_type_map_supp_to_public(auth_conf->group_mgmt_cipher)); spp_attrubute = esp_wifi_get_spp_attrubute_internal(WIFI_IF_AP); auth_conf->spp_sup.capable = ((spp_attrubute & WPA_CAPABILITY_SPP_CAPABLE) ? SPP_AMSDU_CAP_ENABLE : SPP_AMSDU_CAP_DISABLE); auth_conf->spp_sup.require = ((spp_attrubute & WPA_CAPABILITY_SPP_REQUIRED) ? SPP_AMSDU_REQ_ENABLE : SPP_AMSDU_REQ_DISABLE); @@ -208,9 +209,6 @@ void *hostap_init(void) auth_conf->sae_require_mfp = 1; #endif /* CONFIG_SAE */ - //TODO change it when AP support GCMP-PSK - auth_conf->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC; - hapd->conf->ap_max_inactivity = 5 * 60; hostapd_setup_wpa_psk(hapd->conf); diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h b/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h index 0419b884bd..e4ca4879ed 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h @@ -305,5 +305,6 @@ void esp_wifi_enable_sae_pk_only_mode_internal(void); uint8_t esp_wifi_ap_get_transition_disable_internal(void); int esp_wifi_softap_set_obss_overlap(bool overlap); void esp_wifi_set_sigma_internal(bool flag); +void esp_wifi_ap_set_group_mgmt_cipher_internal(wifi_cipher_type_t cipher); #endif /* _ESP_WIFI_DRIVER_H_ */ diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c index e4f52c4321..948f271397 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/wpa_supplicant/port/include/os.h b/components/wpa_supplicant/port/include/os.h index af4677cae6..a2de76d46d 100644 --- a/components/wpa_supplicant/port/include/os.h +++ b/components/wpa_supplicant/port/include/os.h @@ -376,7 +376,7 @@ extern const wifi_osi_funcs_t *wifi_funcs; #define os_timer_get_time(void) wifi_funcs->_esp_timer_get_time(void) #define os_event_group_create(void) wifi_funcs->_event_group_create(void) -#define os_event_group_delete(void) wifi_funcs->_event_group_delete(void) +#define os_event_group_delete(a) wifi_funcs->_event_group_delete((a)) #define os_event_group_wait_bits(a, b, c, d, e) wifi_funcs->_event_group_wait_bits((a), (b), (c), (d), (e)) #define os_event_group_clear_bits(a, b) wifi_funcs->_event_group_clear_bits((a), (b)) #define os_event_group_set_bits(a, b) wifi_funcs->_event_group_set_bits((a), (b)) diff --git a/components/wpa_supplicant/src/ap/wpa_auth.c b/components/wpa_supplicant/src/ap/wpa_auth.c index dc4e4b28a4..6f1e6ae7f2 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth.c +++ b/components/wpa_supplicant/src/ap/wpa_auth.c @@ -165,9 +165,8 @@ static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth, if (key) { wpa_printf (MSG_DEBUG, "%s : igtk idx %d", __func__, idx); wifi_wpa_igtk_t *igtk = os_malloc(sizeof(wifi_wpa_igtk_t)); - if (igtk != NULL) { - memcpy(&igtk->igtk[0], key, WPA_IGTK_LEN); + memcpy(&igtk->igtk[0], key, key_len); memset((uint8_t*)&igtk->pn[0],0,6); igtk->keyid[0] = idx; igtk->keyid[1] = 0; @@ -2484,6 +2483,8 @@ static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth, struct wpa_group *group) { int ret = 0; + size_t len; + len = wpa_cipher_key_len(wpa_auth->conf.group_mgmt_cipher); if (wpa_auth_set_key(wpa_auth, group->vlan_id, wpa_cipher_to_alg(wpa_auth->conf.wpa_group), (uint8_t *)broadcast_ether_addr, group->GN, @@ -2495,7 +2496,7 @@ static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth, wpa_auth_set_key(wpa_auth, group->vlan_id, WIFI_WPA_ALG_IGTK, broadcast_ether_addr, group->GN_igtk, group->IGTK[group->GN_igtk - 4], - WPA_IGTK_LEN) < 0) + len) < 0) ret = -1; #endif /* CONFIG_IEEE80211W */ diff --git a/components/wpa_supplicant/src/rsn_supp/wpa.c b/components/wpa_supplicant/src/rsn_supp/wpa.c index c65cd77851..62e2455c0d 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa.c +++ b/components/wpa_supplicant/src/rsn_supp/wpa.c @@ -110,6 +110,12 @@ wifi_cipher_type_t cipher_type_map_supp_to_public(unsigned wpa_cipher) case WPA_CIPHER_AES_128_CMAC: return WIFI_CIPHER_TYPE_AES_CMAC128; + case WPA_CIPHER_BIP_GMAC_128: + return WIFI_CIPHER_TYPE_AES_GMAC128; + + case WPA_CIPHER_BIP_GMAC_256: + return WIFI_CIPHER_TYPE_AES_GMAC256; + case WPA_CIPHER_SMS4: return WIFI_CIPHER_TYPE_SMS4; diff --git a/examples/protocols/https_server/wss_server/sdkconfig.defaults b/examples/protocols/https_server/wss_server/sdkconfig.defaults index 0a73bafe0c..3f94b869b5 100644 --- a/examples/protocols/https_server/wss_server/sdkconfig.defaults +++ b/examples/protocols/https_server/wss_server/sdkconfig.defaults @@ -1,2 +1,3 @@ CONFIG_ESP_HTTPS_SERVER_ENABLE=y CONFIG_HTTPD_WS_SUPPORT=y +CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y diff --git a/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c b/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c index a5af57587a..b2bac9e24c 100644 --- a/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c +++ b/examples/wifi/wifi_easy_connect/dpp-enrollee/main/dpp_enrollee_main.c @@ -54,21 +54,56 @@ static EventGroupHandle_t s_dpp_event_group; static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { - if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { - ESP_ERROR_CHECK(esp_supp_dpp_start_listen()); - ESP_LOGI(TAG, "Started listening for DPP Authentication"); - } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { - if (s_retry_num < WIFI_MAX_RETRY_NUM) { - esp_wifi_connect(); - s_retry_num++; - ESP_LOGI(TAG, "retry to connect to the AP"); - } else { - xEventGroupSetBits(s_dpp_event_group, DPP_CONNECT_FAIL_BIT); - } - ESP_LOGI(TAG, "connect to the AP fail"); - } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) { + if (event_base == WIFI_EVENT) { + switch (event_id) { + case WIFI_EVENT_STA_START: + ESP_ERROR_CHECK(esp_supp_dpp_start_listen()); + ESP_LOGI(TAG, "Started listening for DPP Authentication"); + break; + case WIFI_EVENT_STA_DISCONNECTED: + if (s_retry_num < WIFI_MAX_RETRY_NUM) { + esp_wifi_connect(); + s_retry_num++; + ESP_LOGI(TAG, "Disconnect event, retry to connect to the AP"); + } else { + xEventGroupSetBits(s_dpp_event_group, DPP_CONNECT_FAIL_BIT); + } + break; + case WIFI_EVENT_STA_CONNECTED: ESP_LOGI(TAG, "Successfully connected to the AP ssid : %s ", s_dpp_wifi_config.sta.ssid); - } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { + break; + case WIFI_EVENT_DPP_URI_READY: + wifi_event_dpp_uri_ready_t *uri_data = event_data; + if (uri_data != NULL) { + esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); + + ESP_LOGI(TAG, "Scan below QR Code to configure the enrollee:"); + esp_qrcode_generate(&cfg, (const char *)uri_data->uri); + } + break; + case WIFI_EVENT_DPP_CFG_RECVD: + wifi_event_dpp_config_received_t *config = event_data; + memcpy(&s_dpp_wifi_config, &config->wifi_cfg, sizeof(s_dpp_wifi_config)); + s_retry_num = 0; + esp_wifi_set_config(ESP_IF_WIFI_STA, &s_dpp_wifi_config); + esp_wifi_connect(); + break; + case WIFI_EVENT_DPP_FAILED: + wifi_event_dpp_failed_t *dpp_failure = event_data; + if (s_retry_num < 5) { + ESP_LOGI(TAG, "DPP Auth failed (Reason: %s), retry...", esp_err_to_name((int)dpp_failure->failure_reason)); + ESP_ERROR_CHECK(esp_supp_dpp_start_listen()); + s_retry_num++; + } else { + xEventGroupSetBits(s_dpp_event_group, DPP_AUTH_FAIL_BIT); + } + + break; + default: + break; + } + } + if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data; ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); s_retry_num = 0; @@ -76,37 +111,6 @@ static void event_handler(void *arg, esp_event_base_t event_base, } } -void dpp_enrollee_event_cb(esp_supp_dpp_event_t event, void *data) -{ - switch (event) { - case ESP_SUPP_DPP_URI_READY: - if (data != NULL) { - esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); - - ESP_LOGI(TAG, "Scan below QR Code to configure the enrollee:"); - esp_qrcode_generate(&cfg, (const char *)data); - } - break; - case ESP_SUPP_DPP_CFG_RECVD: - memcpy(&s_dpp_wifi_config, data, sizeof(s_dpp_wifi_config)); - s_retry_num = 0; - esp_wifi_set_config(ESP_IF_WIFI_STA, &s_dpp_wifi_config); - esp_wifi_connect(); - break; - case ESP_SUPP_DPP_FAIL: - if (s_retry_num < 5) { - ESP_LOGI(TAG, "DPP Auth failed (Reason: %s), retry...", esp_err_to_name((int)data)); - ESP_ERROR_CHECK(esp_supp_dpp_start_listen()); - s_retry_num++; - } else { - xEventGroupSetBits(s_dpp_event_group, DPP_AUTH_FAIL_BIT); - } - break; - default: - break; - } -} - esp_err_t dpp_enrollee_bootstrap(void) { esp_err_t ret; @@ -157,7 +161,7 @@ void dpp_enrollee_init(void) ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); - ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb)); + ESP_ERROR_CHECK(esp_supp_dpp_init(NULL)); ESP_ERROR_CHECK(dpp_enrollee_bootstrap()); ESP_ERROR_CHECK(esp_wifi_start()); @@ -172,8 +176,6 @@ void dpp_enrollee_init(void) /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually * happened. */ if (bits & DPP_CONNECTED_BIT) { - ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", - s_dpp_wifi_config.sta.ssid, s_dpp_wifi_config.sta.password); } else if (bits & DPP_CONNECT_FAIL_BIT) { ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", s_dpp_wifi_config.sta.ssid, s_dpp_wifi_config.sta.password);