diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_common.c b/components/wpa_supplicant/src/esp_supplicant/esp_common.c index a2e35d679f..828804bad7 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_common.c +++ b/components/wpa_supplicant/src/esp_supplicant/esp_common.c @@ -220,8 +220,8 @@ static void esp_supplicant_sta_conn_handler(void* arg, esp_event_base_t event_ba esp_clear_bssid_flag(wpa_s); } -static void esp_supplicant_sta_disconn_handler(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data) +static void supplicant_sta_disconn_handler(void* arg, esp_event_base_t event_base, + int32_t event_id, void* event_data) { struct wpa_supplicant *wpa_s = &g_wpa_supp; wpas_rrm_reset(wpa_s); @@ -250,7 +250,7 @@ void esp_supplicant_common_init(struct wpa_funcs *wpa_cb) esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED, &esp_supplicant_sta_conn_handler, NULL); esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, - &esp_supplicant_sta_disconn_handler, NULL); + &supplicant_sta_disconn_handler, NULL); wpa_s->type = 0; wpa_s->subtype = 0; @@ -261,16 +261,19 @@ void esp_supplicant_common_deinit(void) { struct wpa_supplicant *wpa_s = &g_wpa_supp; - if (esp_supplicant_post_evt(SIG_SUPPLICANT_DEL_TASK, 0) != 0) { - wpa_printf(MSG_ERROR, "failed to send task delete event"); - } esp_scan_deinit(wpa_s); wpas_rrm_reset(wpa_s); wpas_clear_beacon_rep_data(wpa_s); esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED, &esp_supplicant_sta_conn_handler); esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, - &esp_supplicant_sta_disconn_handler); + &supplicant_sta_disconn_handler); + wpa_s->type = 0; + wpa_s->subtype = 0; + esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype); + if (esp_supplicant_post_evt(SIG_SUPPLICANT_DEL_TASK, 0) != 0) { + wpa_printf(MSG_ERROR, "failed to send task delete event"); + } } int esp_rrm_send_neighbor_rep_request(neighbor_rep_request_cb cb, @@ -390,13 +393,20 @@ int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data) evt->id = evt_id; evt->data = data; - SUPPLICANT_API_LOCK(); + /* Make sure lock exists before taking it */ + if (s_supplicant_api_lock) { + SUPPLICANT_API_LOCK(); + } else { + return -1; + } if (xQueueSend(s_supplicant_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) { SUPPLICANT_API_UNLOCK(); os_free(evt); return -1; } - SUPPLICANT_API_UNLOCK(); + if (evt_id != SIG_SUPPLICANT_DEL_TASK) { + SUPPLICANT_API_UNLOCK(); + } return 0; } diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_dpp.c b/components/wpa_supplicant/src/esp_supplicant/esp_dpp.c index 22f986b521..1dcdf6688e 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_dpp.c +++ b/components/wpa_supplicant/src/esp_supplicant/esp_dpp.c @@ -42,22 +42,36 @@ struct action_rx_param { static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data) { - DPP_API_LOCK(); - dpp_event_t *evt = os_zalloc(sizeof(dpp_event_t)); + int ret = ESP_OK; + if (evt == NULL) { - DPP_API_UNLOCK(); - return ESP_ERR_NO_MEM; + ret = ESP_ERR_NO_MEM; + goto end; } evt->id = evt_id; evt->data = data; - if ( xQueueSend(s_dpp_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) { - DPP_API_UNLOCK(); - os_free(evt); - return ESP_ERR_DPP_FAILURE; + if (s_dpp_api_lock) { + DPP_API_LOCK(); + } else { + ret = ESP_ERR_DPP_FAILURE; + goto end; } - DPP_API_UNLOCK(); - return ESP_OK; + if (xQueueSend(s_dpp_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) { + DPP_API_UNLOCK(); + ret = ESP_ERR_DPP_FAILURE; + goto end; + } + if (evt_id != SIG_DPP_DEL_TASK) { + DPP_API_UNLOCK(); + } + + return ret; +end: + if (evt) { + os_free(evt); + } + return ret; } static void esp_dpp_call_cb(esp_supp_dpp_event_t evt, void *data) @@ -654,6 +668,10 @@ void esp_supp_dpp_deinit(void) params->key = NULL; } + esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ACTION_TX_STATUS, + &offchan_event_handler); + esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_ROC_DONE, + &offchan_event_handler); s_dpp_auth_retries = 0; dpp_global_deinit(s_dpp_ctx.dpp_global); esp_dpp_post_evt(SIG_DPP_DEL_TASK, 0);