wpa_supplicant: Add wrappers for FreeRTOS APIs

This commit is contained in:
Kapil Gupta
2022-05-26 15:23:21 +05:30
parent 37596b4dd8
commit 0cdad0a002
11 changed files with 154 additions and 118 deletions

View File

@@ -1,16 +1,8 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ESP_WIFI_PRIVATE_H #ifndef _ESP_WIFI_PRIVATE_H
#define _ESP_WIFI_PRIVATE_H #define _ESP_WIFI_PRIVATE_H
@@ -21,5 +13,14 @@
#include "esp_wifi_crypto_types.h" #include "esp_wifi_crypto_types.h"
#include "esp_private/wifi_os_adapter.h" #include "esp_private/wifi_os_adapter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WIFI_OSI_FUNCS_INITIALIZER() &g_wifi_osi_funcs
#ifdef __cplusplus
}
#endif
#endif /* _ESP_WIFI_PRIVATE_H */ #endif /* _ESP_WIFI_PRIVATE_H */

View File

@@ -27,9 +27,12 @@
struct wpa_supplicant g_wpa_supp; struct wpa_supplicant g_wpa_supp;
#ifdef CONFIG_SUPPLICANT_TASK #ifdef CONFIG_SUPPLICANT_TASK
static TaskHandle_t s_supplicant_task_hdl = NULL; static void *s_supplicant_task_hdl = NULL;
static void *s_supplicant_evt_queue = NULL; static void *s_supplicant_evt_queue = NULL;
static void *s_supplicant_api_lock = NULL; static void *s_supplicant_api_lock = NULL;
#define SUPPLICANT_API_LOCK() os_mutex_lock(s_supplicant_api_lock)
#define SUPPLICANT_API_UNLOCK() os_mutex_unlock(s_supplicant_api_lock)
#define SUPPLICANT_TASK_STACK_SIZE (6144 + TASK_STACK_SIZE_ADD)
static int handle_action_frm(u8 *frame, size_t len, static int handle_action_frm(u8 *frame, size_t len,
u8 *sender, u32 rssi, u8 channel) u8 *sender, u32 rssi, u8 channel)
@@ -105,7 +108,7 @@ static void btm_rrm_task(void *pvParameters)
bool task_del = false; bool task_del = false;
while(1) { while(1) {
if (xQueueReceive(s_supplicant_evt_queue, &evt, portMAX_DELAY) != pdTRUE) if (os_queue_recv(s_supplicant_evt_queue, &evt, OS_BLOCK) != TRUE)
continue; continue;
/* event validation failed */ /* event validation failed */
@@ -139,16 +142,16 @@ static void btm_rrm_task(void *pvParameters)
break; break;
} }
vQueueDelete(s_supplicant_evt_queue); os_queue_delete(s_supplicant_evt_queue);
s_supplicant_evt_queue = NULL; s_supplicant_evt_queue = NULL;
if (s_supplicant_api_lock) { if (s_supplicant_api_lock) {
vSemaphoreDelete(s_supplicant_api_lock); os_semphr_delete(s_supplicant_api_lock);
s_supplicant_api_lock = NULL; s_supplicant_api_lock = NULL;
} }
/* At this point, we completed */ /* At this point, we completed */
vTaskDelete(NULL); os_task_delete(NULL);
} }
#endif #endif
@@ -346,22 +349,22 @@ int esp_supplicant_common_init(struct wpa_funcs *wpa_cb)
int ret = 0; int ret = 0;
#ifdef CONFIG_SUPPLICANT_TASK #ifdef CONFIG_SUPPLICANT_TASK
s_supplicant_api_lock = xSemaphoreCreateRecursiveMutex(); s_supplicant_api_lock = os_recursive_mutex_create();
if (!s_supplicant_api_lock) { if (!s_supplicant_api_lock) {
wpa_printf(MSG_ERROR, "%s: failed to create Supplicant API lock", __func__); wpa_printf(MSG_ERROR, "%s: failed to create Supplicant API lock", __func__);
ret = -1; ret = -1;
goto err; goto err;
} }
s_supplicant_evt_queue = xQueueCreate(3, sizeof(supplicant_event_t)); s_supplicant_evt_queue = os_queue_create(3, sizeof(supplicant_event_t));
if (!s_supplicant_evt_queue) { if (!s_supplicant_evt_queue) {
wpa_printf(MSG_ERROR, "%s: failed to create Supplicant event queue", __func__); wpa_printf(MSG_ERROR, "%s: failed to create Supplicant event queue", __func__);
ret = -1; ret = -1;
goto err; goto err;
} }
ret = xTaskCreate(btm_rrm_task, "btm_rrm_t", SUPPLICANT_TASK_STACK_SIZE, NULL, 2, &s_supplicant_task_hdl); ret = os_task_create(btm_rrm_task, "btm_rrm_t", SUPPLICANT_TASK_STACK_SIZE, NULL, 2, &s_supplicant_task_hdl);
if (ret != pdPASS) { if (ret != TRUE) {
wpa_printf(MSG_ERROR, "btm: failed to create task"); wpa_printf(MSG_ERROR, "btm: failed to create task");
ret = -1; ret = -1;
goto err; goto err;
@@ -417,11 +420,11 @@ void esp_supplicant_common_deinit(void)
#ifdef CONFIG_SUPPLICANT_TASK #ifdef CONFIG_SUPPLICANT_TASK
if (!s_supplicant_task_hdl && esp_supplicant_post_evt(SIG_SUPPLICANT_DEL_TASK, 0) != 0) { if (!s_supplicant_task_hdl && esp_supplicant_post_evt(SIG_SUPPLICANT_DEL_TASK, 0) != 0) {
if (s_supplicant_evt_queue) { if (s_supplicant_evt_queue) {
vQueueDelete(s_supplicant_evt_queue); os_queue_delete(s_supplicant_evt_queue);
s_supplicant_evt_queue = NULL; s_supplicant_evt_queue = NULL;
} }
if (s_supplicant_api_lock) { if (s_supplicant_api_lock) {
vSemaphoreDelete(s_supplicant_api_lock); os_semphr_delete(s_supplicant_api_lock);
s_supplicant_api_lock = NULL; s_supplicant_api_lock = NULL;
} }
} }
@@ -833,7 +836,7 @@ int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data)
os_free(evt); os_free(evt);
return -1; return -1;
} }
if (xQueueSend(s_supplicant_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) { if (os_queue_send(s_supplicant_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != TRUE) {
SUPPLICANT_API_UNLOCK(); SUPPLICANT_API_UNLOCK();
os_free(evt); os_free(evt);
return -1; return -1;

View File

@@ -21,15 +21,13 @@ struct ieee_mgmt_frame {
u8 payload[0]; u8 payload[0];
}; };
int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data);
typedef struct { typedef struct {
uint32_t id; uint32_t id;
uint32_t data; uint32_t data;
} supplicant_event_t; } supplicant_event_t;
#define SUPPLICANT_API_LOCK() xSemaphoreTakeRecursive(s_supplicant_api_lock, portMAX_DELAY)
#define SUPPLICANT_API_UNLOCK() xSemaphoreGiveRecursive(s_supplicant_api_lock)
#define SUPPLICANT_TASK_STACK_SIZE (6144 + TASK_STACK_SIZE_ADD)
enum SIG_SUPPLICANT { enum SIG_SUPPLICANT {
SIG_SUPPLICANT_RX_ACTION, SIG_SUPPLICANT_RX_ACTION,
SIG_SUPPLICANT_SCAN_DONE, SIG_SUPPLICANT_SCAN_DONE,
@@ -37,7 +35,6 @@ enum SIG_SUPPLICANT {
SIG_SUPPLICANT_MAX, SIG_SUPPLICANT_MAX,
}; };
int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data);
void esp_get_tx_power(uint8_t *tx_power); void esp_get_tx_power(uint8_t *tx_power);
#ifdef CONFIG_MBO #ifdef CONFIG_MBO
bool mbo_bss_profile_match(u8 *bssid); bool mbo_bss_profile_match(u8 *bssid);

View File

@@ -4,11 +4,6 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "esp_dpp_i.h" #include "esp_dpp_i.h"
#include "esp_dpp.h" #include "esp_dpp.h"
#include "esp_wpa.h" #include "esp_wpa.h"
@@ -18,7 +13,7 @@
#include "common/ieee802_11_defs.h" #include "common/ieee802_11_defs.h"
#ifdef CONFIG_DPP #ifdef CONFIG_DPP
static TaskHandle_t s_dpp_task_hdl = NULL; static void *s_dpp_task_hdl = NULL;
static void *s_dpp_evt_queue = NULL; static void *s_dpp_evt_queue = NULL;
static void *s_dpp_api_lock = NULL; static void *s_dpp_api_lock = NULL;
@@ -27,8 +22,8 @@ static int s_dpp_auth_retries;
struct esp_dpp_context_t s_dpp_ctx; struct esp_dpp_context_t s_dpp_ctx;
static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action; static wifi_action_rx_cb_t s_action_rx_cb = esp_supp_rx_action;
#define DPP_API_LOCK() xSemaphoreTakeRecursive(s_dpp_api_lock, portMAX_DELAY) #define DPP_API_LOCK() os_mutex_lock(s_dpp_api_lock)
#define DPP_API_UNLOCK() xSemaphoreGiveRecursive(s_dpp_api_lock) #define DPP_API_UNLOCK() os_mutex_unlock(s_dpp_api_lock)
struct action_rx_param { struct action_rx_param {
u8 sa[ETH_ALEN]; u8 sa[ETH_ALEN];
@@ -55,7 +50,7 @@ static int esp_dpp_post_evt(uint32_t evt_id, uint32_t data)
ret = ESP_ERR_DPP_FAILURE; ret = ESP_ERR_DPP_FAILURE;
goto end; goto end;
} }
if (xQueueSend(s_dpp_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) { if (os_queue_send(s_dpp_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != TRUE) {
DPP_API_UNLOCK(); DPP_API_UNLOCK();
ret = ESP_ERR_DPP_FAILURE; ret = ESP_ERR_DPP_FAILURE;
goto end; goto end;
@@ -348,7 +343,7 @@ static void esp_dpp_task(void *pvParameters )
bool task_del = false; bool task_del = false;
for (;;) { for (;;) {
if (xQueueReceive(s_dpp_evt_queue, &evt, portMAX_DELAY) == pdTRUE) { if (os_queue_recv(s_dpp_evt_queue, &evt, OS_BLOCK) == TRUE) {
if (evt->id >= SIG_DPP_MAX) { if (evt->id >= SIG_DPP_MAX) {
os_free(evt); os_free(evt);
continue; continue;
@@ -399,16 +394,16 @@ static void esp_dpp_task(void *pvParameters )
} }
} }
vQueueDelete(s_dpp_evt_queue); os_queue_delete(s_dpp_evt_queue);
s_dpp_evt_queue = NULL; s_dpp_evt_queue = NULL;
if (s_dpp_api_lock) { if (s_dpp_api_lock) {
vSemaphoreDelete(s_dpp_api_lock); os_semphr_delete(s_dpp_api_lock);
s_dpp_api_lock = NULL; s_dpp_api_lock = NULL;
} }
/* At this point, we completed */ /* At this point, we completed */
vTaskDelete(NULL); os_task_delete(NULL);
} }
int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel) int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t channel)
@@ -610,14 +605,14 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
s_dpp_ctx.dpp_global = dpp_global_init(&cfg); s_dpp_ctx.dpp_global = dpp_global_init(&cfg);
s_dpp_stop_listening = false; s_dpp_stop_listening = false;
s_dpp_evt_queue = xQueueCreate(3, sizeof(dpp_event_t)); s_dpp_evt_queue = os_queue_create(3, sizeof(dpp_event_t));
ret = xTaskCreate(esp_dpp_task, "dppT", DPP_TASK_STACK_SIZE, NULL, 2, &s_dpp_task_hdl); ret = os_task_create(esp_dpp_task, "dppT", DPP_TASK_STACK_SIZE, NULL, 2, &s_dpp_task_hdl);
if (ret != pdPASS) { if (ret != TRUE) {
wpa_printf(MSG_ERROR, "DPP: failed to create task"); wpa_printf(MSG_ERROR, "DPP: failed to create task");
return ESP_FAIL; return ESP_FAIL;
} }
s_dpp_api_lock = xSemaphoreCreateRecursiveMutex(); s_dpp_api_lock = os_recursive_mutex_create();
if (!s_dpp_api_lock) { if (!s_dpp_api_lock) {
esp_supp_dpp_deinit(); esp_supp_dpp_deinit();
wpa_printf(MSG_ERROR, "DPP: dpp_init: failed to create DPP API lock"); wpa_printf(MSG_ERROR, "DPP: dpp_init: failed to create DPP API lock");

View File

@@ -6,11 +6,6 @@
#include <string.h> #include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "esp_err.h" #include "esp_err.h"
#include "utils/includes.h" #include "utils/includes.h"
@@ -44,8 +39,8 @@
#define WPA2_VERSION "v2.0" #define WPA2_VERSION "v2.0"
#define DATA_MUTEX_TAKE() xSemaphoreTakeRecursive(s_wpa2_data_lock,portMAX_DELAY) #define DATA_MUTEX_TAKE() os_mutex_lock(s_wpa2_data_lock)
#define DATA_MUTEX_GIVE() xSemaphoreGiveRecursive(s_wpa2_data_lock) #define DATA_MUTEX_GIVE() os_mutex_unlock(s_wpa2_data_lock)
//length of the string "fast_provisioning={0/1/2} " //length of the string "fast_provisioning={0/1/2} "
#define FAST_PROVISIONING_CONFIG_STR_LEN 20 #define FAST_PROVISIONING_CONFIG_STR_LEN 20
@@ -68,7 +63,7 @@ static int wpa2_start_eapol_internal(void);
int wpa2_post(uint32_t sig, uint32_t par); int wpa2_post(uint32_t sig, uint32_t par);
#ifdef USE_WPA2_TASK #ifdef USE_WPA2_TASK
static TaskHandle_t s_wpa2_task_hdl = NULL; static void *s_wpa2_task_hdl = NULL;
static void *s_wpa2_queue = NULL; static void *s_wpa2_queue = NULL;
static wpa2_state_t s_wpa2_state = WPA2_STATE_DISABLED; static wpa2_state_t s_wpa2_state = WPA2_STATE_DISABLED;
static void *s_wpa2_api_lock = NULL; static void *s_wpa2_api_lock = NULL;
@@ -78,20 +73,20 @@ static bool s_disable_time_check = true;
static void wpa2_api_lock(void) static void wpa2_api_lock(void)
{ {
if (s_wpa2_api_lock == NULL) { if (s_wpa2_api_lock == NULL) {
s_wpa2_api_lock = xSemaphoreCreateRecursiveMutex(); s_wpa2_api_lock = os_recursive_mutex_create();
if (!s_wpa2_api_lock) { if (!s_wpa2_api_lock) {
wpa_printf(MSG_ERROR, "WPA2: failed to create wpa2 api lock"); wpa_printf(MSG_ERROR, "WPA2: failed to create wpa2 api lock");
return; return;
} }
} }
xSemaphoreTakeRecursive(s_wpa2_api_lock, portMAX_DELAY); os_mutex_lock(s_wpa2_api_lock);
} }
static void wpa2_api_unlock(void) static void wpa2_api_unlock(void)
{ {
if (s_wpa2_api_lock) { if (s_wpa2_api_lock) {
xSemaphoreGiveRecursive(s_wpa2_api_lock); os_mutex_unlock(s_wpa2_api_lock);
} }
} }
@@ -122,7 +117,7 @@ static void wpa2_set_eap_state(wpa2_ent_eap_state_t state)
static inline void wpa2_task_delete(void *arg) static inline void wpa2_task_delete(void *arg)
{ {
void *my_task_hdl = xTaskGetCurrentTaskHandle(); void *my_task_hdl = os_task_get_current_task();
int ret = ESP_OK; int ret = ESP_OK;
if (my_task_hdl == s_wpa2_task_hdl) { if (my_task_hdl == s_wpa2_task_hdl) {
@@ -198,7 +193,7 @@ void wpa2_task(void *pvParameters )
} }
for (;;) { for (;;) {
if ( pdPASS == xQueueReceive(s_wpa2_queue, &e, portMAX_DELAY) ) { if ( TRUE == os_queue_recv(s_wpa2_queue, &e, OS_BLOCK) ) {
if (e->sig < SIG_WPA2_MAX) { if (e->sig < SIG_WPA2_MAX) {
DATA_MUTEX_TAKE(); DATA_MUTEX_TAKE();
if(sm->wpa2_sig_cnt[e->sig]) { if(sm->wpa2_sig_cnt[e->sig]) {
@@ -236,7 +231,7 @@ void wpa2_task(void *pvParameters )
} else { } else {
if (s_wifi_wpa2_sync_sem) { if (s_wifi_wpa2_sync_sem) {
wpa_printf(MSG_DEBUG, "WPA2: wifi->wpa2 api completed sig(%d)", e->sig); wpa_printf(MSG_DEBUG, "WPA2: wifi->wpa2 api completed sig(%d)", e->sig);
xSemaphoreGive(s_wifi_wpa2_sync_sem); os_semphr_give(s_wifi_wpa2_sync_sem);
} else { } else {
wpa_printf(MSG_ERROR, "WPA2: null wifi->wpa2 sync sem"); wpa_printf(MSG_ERROR, "WPA2: null wifi->wpa2 sync sem");
} }
@@ -244,18 +239,18 @@ void wpa2_task(void *pvParameters )
} }
wpa_printf(MSG_DEBUG, "WPA2: queue deleted"); wpa_printf(MSG_DEBUG, "WPA2: queue deleted");
vQueueDelete(s_wpa2_queue); os_queue_delete(s_wpa2_queue);
wpa_printf(MSG_DEBUG, "WPA2: task deleted"); wpa_printf(MSG_DEBUG, "WPA2: task deleted");
s_wpa2_queue = NULL; s_wpa2_queue = NULL;
if (s_wifi_wpa2_sync_sem) { if (s_wifi_wpa2_sync_sem) {
wpa_printf(MSG_DEBUG, "WPA2: wifi->wpa2 api completed sig(%d)", e->sig); wpa_printf(MSG_DEBUG, "WPA2: wifi->wpa2 api completed sig(%d)", e->sig);
xSemaphoreGive(s_wifi_wpa2_sync_sem); os_semphr_give(s_wifi_wpa2_sync_sem);
} else { } else {
wpa_printf(MSG_ERROR, "WPA2: null wifi->wpa2 sync sem"); wpa_printf(MSG_ERROR, "WPA2: null wifi->wpa2 sync sem");
} }
/* At this point, we completed */ /* At this point, we completed */
vTaskDelete(NULL); os_task_delete(NULL);
} }
int wpa2_post(uint32_t sig, uint32_t par) int wpa2_post(uint32_t sig, uint32_t par)
@@ -281,12 +276,12 @@ int wpa2_post(uint32_t sig, uint32_t par)
DATA_MUTEX_GIVE(); DATA_MUTEX_GIVE();
evt->sig = sig; evt->sig = sig;
evt->par = par; evt->par = par;
if ( xQueueSend(s_wpa2_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) { if (os_queue_send(s_wpa2_queue, &evt, 10 / portTICK_PERIOD_MS ) != TRUE) {
wpa_printf(MSG_ERROR, "WPA2: Q S E"); wpa_printf(MSG_ERROR, "WPA2: Q S E");
return ESP_FAIL; return ESP_FAIL;
} else { } else {
if (s_wifi_wpa2_sync_sem) { if (s_wifi_wpa2_sync_sem) {
xSemaphoreTake(s_wifi_wpa2_sync_sem, portMAX_DELAY); os_semphr_take(s_wifi_wpa2_sync_sem, OS_BLOCK);
wpa_printf(MSG_DEBUG, "WPA2: wpa2 api return, sm->state(%d)", sm->finish_state); wpa_printf(MSG_DEBUG, "WPA2: wpa2 api return, sm->state(%d)", sm->finish_state);
} else { } else {
wpa_printf(MSG_ERROR, "WPA2: null wifi->wpa2 sync sem"); wpa_printf(MSG_ERROR, "WPA2: null wifi->wpa2 sync sem");
@@ -693,7 +688,7 @@ static int eap_peer_sm_init(void)
} }
gEapSm = sm; gEapSm = sm;
s_wpa2_data_lock = xSemaphoreCreateRecursiveMutex(); s_wpa2_data_lock = os_recursive_mutex_create();
if (!s_wpa2_data_lock) { if (!s_wpa2_data_lock) {
wpa_printf(MSG_ERROR, "wpa2 eap_peer_sm_init: failed to alloc data lock"); wpa_printf(MSG_ERROR, "wpa2 eap_peer_sm_init: failed to alloc data lock");
ret = ESP_ERR_NO_MEM; ret = ESP_ERR_NO_MEM;
@@ -728,14 +723,14 @@ static int eap_peer_sm_init(void)
gEapSm = sm; gEapSm = sm;
#ifdef USE_WPA2_TASK #ifdef USE_WPA2_TASK
s_wpa2_queue = xQueueCreate(SIG_WPA2_MAX, sizeof(s_wpa2_queue)); s_wpa2_queue = os_queue_create(SIG_WPA2_MAX, sizeof(s_wpa2_queue));
ret = xTaskCreate(wpa2_task, "wpa2T", WPA2_TASK_STACK_SIZE, NULL, 2, &s_wpa2_task_hdl); ret = os_task_create(wpa2_task, "wpa2T", WPA2_TASK_STACK_SIZE, NULL, 2, &s_wpa2_task_hdl);
if (ret != pdPASS) { if (ret != TRUE) {
wpa_printf(MSG_ERROR, "wps enable: failed to create task"); wpa_printf(MSG_ERROR, "wps enable: failed to create task");
ret = ESP_FAIL; ret = ESP_FAIL;
goto _err; goto _err;
} }
s_wifi_wpa2_sync_sem = xSemaphoreCreateCounting(1, 0); s_wifi_wpa2_sync_sem = os_semphr_create(1, 0);
if (!s_wifi_wpa2_sync_sem) { if (!s_wifi_wpa2_sync_sem) {
wpa_printf(MSG_ERROR, "WPA2: failed create wifi wpa2 task sync sem"); wpa_printf(MSG_ERROR, "WPA2: failed create wifi wpa2 task sync sem");
ret = ESP_FAIL; ret = ESP_FAIL;
@@ -780,18 +775,18 @@ static void eap_peer_sm_deinit(void)
} }
if (s_wifi_wpa2_sync_sem) { if (s_wifi_wpa2_sync_sem) {
vSemaphoreDelete(s_wifi_wpa2_sync_sem); os_semphr_delete(s_wifi_wpa2_sync_sem);
s_wifi_wpa2_sync_sem = NULL; s_wifi_wpa2_sync_sem = NULL;
} }
if (s_wpa2_data_lock) { if (s_wpa2_data_lock) {
vSemaphoreDelete(s_wpa2_data_lock); os_semphr_delete(s_wpa2_data_lock);
s_wpa2_data_lock = NULL; s_wpa2_data_lock = NULL;
wpa_printf(MSG_DEBUG, "wpa2 eap_peer_sm_deinit: free data lock"); wpa_printf(MSG_DEBUG, "wpa2 eap_peer_sm_deinit: free data lock");
} }
if (s_wpa2_queue) { if (s_wpa2_queue) {
vQueueDelete(s_wpa2_queue); os_queue_delete(s_wpa2_queue);
s_wpa2_queue = NULL; s_wpa2_queue = NULL;
} }
os_free(sm); os_free(sm);
@@ -866,9 +861,6 @@ esp_err_t esp_wifi_sta_wpa2_ent_disable_fn(void *param)
eap_peer_sm_deinit(); eap_peer_sm_deinit();
} }
#ifdef USE_WPA2_TASK
#endif
#ifdef EAP_PEER_METHOD #ifdef EAP_PEER_METHOD
eap_peer_unregister_methods(); eap_peer_unregister_methods();
#endif #endif

View File

@@ -38,6 +38,8 @@
#include "ap/sta_info.h" #include "ap/sta_info.h"
#include "wps/wps_defs.h" #include "wps/wps_defs.h"
const wifi_osi_funcs_t *wifi_funcs;
void wpa_install_key(enum wpa_alg alg, u8 *addr, int key_idx, int set_tx, void wpa_install_key(enum wpa_alg alg, u8 *addr, int key_idx, int set_tx,
u8 *seq, size_t seq_len, u8 *key, size_t key_len, enum key_flag key_flag) u8 *seq, size_t seq_len, u8 *key, size_t key_len, enum key_flag key_flag)
{ {
@@ -301,6 +303,10 @@ int esp_supplicant_init(void)
int ret = ESP_OK; int ret = ESP_OK;
struct wpa_funcs *wpa_cb; struct wpa_funcs *wpa_cb;
wifi_funcs = WIFI_OSI_FUNCS_INITIALIZER();
if (!wifi_funcs) {
return ESP_ERR_NOT_FOUND;
}
wpa_cb = (struct wpa_funcs *)os_zalloc(sizeof(struct wpa_funcs)); wpa_cb = (struct wpa_funcs *)os_zalloc(sizeof(struct wpa_funcs));
if (!wpa_cb) { if (!wpa_cb) {
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;

View File

@@ -6,10 +6,6 @@
#include <string.h> #include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "utils/includes.h" #include "utils/includes.h"
#include "rsn_supp/wpa.h" #include "rsn_supp/wpa.h"
#include "utils/common.h" #include "utils/common.h"
@@ -48,7 +44,7 @@ typedef struct {
int ret; /* return value */ int ret; /* return value */
} wps_ioctl_param_t; } wps_ioctl_param_t;
static TaskHandle_t s_wps_task_hdl = NULL; static void *s_wps_task_hdl = NULL;
static void *s_wps_queue = NULL; static void *s_wps_queue = NULL;
static void *s_wps_data_lock = NULL; static void *s_wps_data_lock = NULL;
static void *s_wps_task_create_sem = NULL; static void *s_wps_task_create_sem = NULL;
@@ -119,11 +115,11 @@ void wps_task(void *pvParameters )
wps_ioctl_param_t *param; wps_ioctl_param_t *param;
bool del_task = false; bool del_task = false;
xSemaphoreGive(s_wps_task_create_sem); os_semphr_give(s_wps_task_create_sem);
wpa_printf(MSG_DEBUG, "wps_Task enter"); wpa_printf(MSG_DEBUG, "wps_Task enter");
for (;;) { for (;;) {
if ( pdPASS == xQueueReceive(s_wps_queue, &e, portMAX_DELAY) ) { if ( TRUE == os_queue_recv(s_wps_queue, &e, OS_BLOCK) ) {
if ( (e->sig >= SIG_WPS_ENABLE) && (e->sig < SIG_WPS_NUM) ) { if ( (e->sig >= SIG_WPS_ENABLE) && (e->sig < SIG_WPS_NUM) ) {
DATA_MUTEX_TAKE(); DATA_MUTEX_TAKE();
@@ -144,7 +140,7 @@ void wps_task(void *pvParameters )
param = (wps_ioctl_param_t *)e->par; param = (wps_ioctl_param_t *)e->par;
if (!param) { if (!param) {
wpa_printf(MSG_ERROR, "wpsT: invalid param sig=%d", e->sig); wpa_printf(MSG_ERROR, "wpsT: invalid param sig=%d", e->sig);
xSemaphoreGive(s_wps_api_sem); os_semphr_give(s_wps_api_sem);
break; break;
} }
@@ -158,7 +154,7 @@ void wps_task(void *pvParameters )
param->ret = wifi_station_wps_start(); param->ret = wifi_station_wps_start();
} }
xSemaphoreGive(s_wps_api_sem); os_semphr_give(s_wps_api_sem);
break; break;
case SIG_WPS_RX: { case SIG_WPS_RX: {
@@ -203,7 +199,7 @@ void wps_task(void *pvParameters )
} }
} }
} }
vTaskDelete(NULL); os_task_delete(NULL);
} }
/* wps_post() is thread-safe /* wps_post() is thread-safe
@@ -232,7 +228,7 @@ int wps_post(uint32_t sig, uint32_t par)
evt->par = par; evt->par = par;
DATA_MUTEX_GIVE(); DATA_MUTEX_GIVE();
if ( xQueueSend(s_wps_queue, &evt, 10 / portTICK_PERIOD_MS) != pdPASS) { if (os_queue_send(s_wps_queue, &evt, 10 / portTICK_PERIOD_MS) != TRUE) {
wpa_printf(MSG_ERROR, "WPS: Q S E"); wpa_printf(MSG_ERROR, "WPS: Q S E");
DATA_MUTEX_TAKE(); DATA_MUTEX_TAKE();
s_wps_sig_cnt[sig]--; s_wps_sig_cnt[sig]--;
@@ -735,7 +731,7 @@ int wps_stop_process(wifi_event_sta_wps_fail_reason_t reason_code)
wpa_printf(MSG_DEBUG, "Write wps_fail_information"); wpa_printf(MSG_DEBUG, "Write wps_fail_information");
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), OS_BLOCK);
return ESP_OK; return ESP_OK;
} }
@@ -1031,7 +1027,7 @@ out:
esp_wifi_disarm_sta_connection_timer_internal(); esp_wifi_disarm_sta_connection_timer_internal();
ets_timer_disarm(&sm->wps_timeout_timer); ets_timer_disarm(&sm->wps_timeout_timer);
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), OS_BLOCK);
return ret; return ret;
} }
@@ -1214,7 +1210,7 @@ wifi_station_wps_timeout_internal(void)
wps_set_status(WPS_STATUS_DISABLE); wps_set_status(WPS_STATUS_DISABLE);
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_TIMEOUT, 0, 0, portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_TIMEOUT, 0, 0, OS_BLOCK);
} }
void wifi_station_wps_timeout(void) void wifi_station_wps_timeout(void)
@@ -1283,10 +1279,10 @@ void wifi_station_wps_success_internal(void)
os_memcpy(evt.ap_cred[i].passphrase, sm->key[i], sm->key_len[i]); os_memcpy(evt.ap_cred[i].passphrase, sm->key[i], sm->key_len[i]);
} }
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, &evt, esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, &evt,
sizeof(evt), portMAX_DELAY); sizeof(evt), OS_BLOCK);
} else { } else {
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS,
0, 0, portMAX_DELAY); 0, 0, OS_BLOCK);
} }
} }
@@ -1408,7 +1404,7 @@ wifi_station_wps_init(void)
if (wps_get_type() == WPS_TYPE_PIN) { if (wps_get_type() == WPS_TYPE_PIN) {
wifi_event_sta_wps_er_pin_t evt; wifi_event_sta_wps_er_pin_t evt;
os_memcpy(evt.pin_code, sm->wps->dev_password, 8); os_memcpy(evt.pin_code, sm->wps->dev_password, 8);
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PIN, &evt, sizeof(evt), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PIN, &evt, sizeof(evt), OS_BLOCK);
} }
sm->wps->wps->cred_cb = save_credentials_cb; sm->wps->wps->cred_cb = save_credentials_cb;
@@ -1549,7 +1545,7 @@ wifi_wps_scan_done(void *arg, STATUS status)
} else { } else {
wpa_printf(MSG_INFO, "PBC session overlap!"); wpa_printf(MSG_INFO, "PBC session overlap!");
wps_set_status(WPS_STATUS_DISABLE); wps_set_status(WPS_STATUS_DISABLE);
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP, 0, 0, portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP, 0, 0, OS_BLOCK);
} }
wpa_printf(MSG_DEBUG, "wps scan_done discover_ssid_cnt = %d", sm->discover_ssid_cnt); wpa_printf(MSG_DEBUG, "wps scan_done discover_ssid_cnt = %d", sm->discover_ssid_cnt);
@@ -1653,19 +1649,19 @@ int wps_task_deinit(void)
wpa_printf(MSG_DEBUG, "wps task deinit"); wpa_printf(MSG_DEBUG, "wps task deinit");
if (s_wps_api_sem) { if (s_wps_api_sem) {
vSemaphoreDelete(s_wps_api_sem); os_semphr_delete(s_wps_api_sem);
s_wps_api_sem = NULL; s_wps_api_sem = NULL;
wpa_printf(MSG_DEBUG, "wps task deinit: free api sem"); wpa_printf(MSG_DEBUG, "wps task deinit: free api sem");
} }
if (s_wps_task_create_sem) { if (s_wps_task_create_sem) {
vSemaphoreDelete(s_wps_task_create_sem); os_semphr_delete(s_wps_task_create_sem);
s_wps_task_create_sem = NULL; s_wps_task_create_sem = NULL;
wpa_printf(MSG_DEBUG, "wps task deinit: free task create sem"); wpa_printf(MSG_DEBUG, "wps task deinit: free task create sem");
} }
if (s_wps_queue) { if (s_wps_queue) {
vQueueDelete(s_wps_queue); os_queue_delete(s_wps_queue);
s_wps_queue = NULL; s_wps_queue = NULL;
wpa_printf(MSG_DEBUG, "wps task deinit: free queue"); wpa_printf(MSG_DEBUG, "wps task deinit: free queue");
} }
@@ -1675,7 +1671,7 @@ int wps_task_deinit(void)
} }
if (s_wps_data_lock) { if (s_wps_data_lock) {
vSemaphoreDelete(s_wps_data_lock); os_semphr_delete(s_wps_data_lock);
s_wps_data_lock = NULL; s_wps_data_lock = NULL;
wpa_printf(MSG_DEBUG, "wps task deinit: free data lock"); wpa_printf(MSG_DEBUG, "wps task deinit: free data lock");
} }
@@ -1691,26 +1687,26 @@ int wps_task_init(void)
*/ */
wps_task_deinit(); wps_task_deinit();
s_wps_data_lock = xSemaphoreCreateRecursiveMutex(); s_wps_data_lock = os_recursive_mutex_create();
if (!s_wps_data_lock) { if (!s_wps_data_lock) {
wpa_printf(MSG_ERROR, "wps task init: failed to alloc data lock"); wpa_printf(MSG_ERROR, "wps task init: failed to alloc data lock");
goto _wps_no_mem; goto _wps_no_mem;
} }
s_wps_api_sem = xSemaphoreCreateCounting(1, 0); s_wps_api_sem = os_semphr_create(1, 0);
if (!s_wps_api_sem) { if (!s_wps_api_sem) {
wpa_printf(MSG_ERROR, "wps task init: failed to create api sem"); wpa_printf(MSG_ERROR, "wps task init: failed to create api sem");
goto _wps_no_mem; goto _wps_no_mem;
} }
s_wps_task_create_sem = xSemaphoreCreateCounting(1, 0); s_wps_task_create_sem = os_semphr_create(1, 0);
if (!s_wps_task_create_sem) { if (!s_wps_task_create_sem) {
wpa_printf(MSG_ERROR, "wps task init: failed to create task sem"); wpa_printf(MSG_ERROR, "wps task init: failed to create task sem");
goto _wps_no_mem; goto _wps_no_mem;
} }
os_bzero(s_wps_sig_cnt, SIG_WPS_NUM); os_bzero(s_wps_sig_cnt, SIG_WPS_NUM);
s_wps_queue = xQueueCreate(SIG_WPS_NUM, sizeof(s_wps_queue)); s_wps_queue = os_queue_create(SIG_WPS_NUM, sizeof(s_wps_queue));
if (!s_wps_queue) { if (!s_wps_queue) {
wpa_printf(MSG_ERROR, "wps task init: failed to alloc queue"); wpa_printf(MSG_ERROR, "wps task init: failed to alloc queue");
goto _wps_no_mem; goto _wps_no_mem;
@@ -1718,14 +1714,14 @@ int wps_task_init(void)
wps_rxq_init(); wps_rxq_init();
ret = xTaskCreate(wps_task, "wpsT", WPS_TASK_STACK_SIZE, NULL, 2, &s_wps_task_hdl); ret = os_task_create(wps_task, "wpsT", WPS_TASK_STACK_SIZE, NULL, 2, &s_wps_task_hdl);
if (pdPASS != ret) { if (TRUE != ret) {
wpa_printf(MSG_ERROR, "wps enable: failed to create task"); wpa_printf(MSG_ERROR, "wps enable: failed to create task");
goto _wps_no_mem; goto _wps_no_mem;
} }
xSemaphoreTake(s_wps_task_create_sem, portMAX_DELAY); os_semphr_take(s_wps_task_create_sem, OS_BLOCK);
vSemaphoreDelete(s_wps_task_create_sem); os_semphr_delete(s_wps_task_create_sem);
s_wps_task_create_sem = NULL; s_wps_task_create_sem = NULL;
wpa_printf(MSG_DEBUG, "wifi wps enable: task prio:%d, stack:%d", 2, WPS_TASK_STACK_SIZE); wpa_printf(MSG_DEBUG, "wifi wps enable: task prio:%d, stack:%d", 2, WPS_TASK_STACK_SIZE);
@@ -1747,7 +1743,7 @@ int wps_post_block(uint32_t sig, void *arg)
return ESP_FAIL; return ESP_FAIL;
} }
if (pdPASS == xSemaphoreTake(s_wps_api_sem, portMAX_DELAY)) { if (TRUE == os_semphr_take(s_wps_api_sem, OS_BLOCK)) {
return param.ret; return param.ret;
} else { } else {
return ESP_FAIL; return ESP_FAIL;

View File

@@ -81,18 +81,18 @@ struct wps_sm {
#define API_MUTEX_TAKE() do {\ #define API_MUTEX_TAKE() do {\
if (!s_wps_api_lock) {\ if (!s_wps_api_lock) {\
s_wps_api_lock = xSemaphoreCreateRecursiveMutex();\ s_wps_api_lock = os_recursive_mutex_create();\
if (!s_wps_api_lock) {\ if (!s_wps_api_lock) {\
wpa_printf(MSG_ERROR, "wps api lock create failed");\ wpa_printf(MSG_ERROR, "wps api lock create failed");\
return ESP_ERR_NO_MEM;\ return ESP_ERR_NO_MEM;\
}\ }\
}\ }\
xSemaphoreTakeRecursive(s_wps_api_lock, portMAX_DELAY);\ os_mutex_lock(s_wps_api_lock);\
} while(0) } while(0)
#define API_MUTEX_GIVE() xSemaphoreGiveRecursive(s_wps_api_lock) #define API_MUTEX_GIVE() os_mutex_unlock(s_wps_api_lock)
#define DATA_MUTEX_TAKE() xSemaphoreTakeRecursive(s_wps_data_lock, portMAX_DELAY) #define DATA_MUTEX_TAKE() os_mutex_lock(s_wps_data_lock)
#define DATA_MUTEX_GIVE() xSemaphoreGiveRecursive(s_wps_data_lock) #define DATA_MUTEX_GIVE() os_mutex_unlock(s_wps_data_lock)
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);

View File

@@ -32,8 +32,8 @@ struct eloop_data {
bool eloop_started; bool eloop_started;
}; };
#define ELOOP_LOCK() xSemaphoreTakeRecursive(eloop_data_lock, portMAX_DELAY) #define ELOOP_LOCK() os_mutex_lock(eloop_data_lock)
#define ELOOP_UNLOCK() xSemaphoreGiveRecursive(eloop_data_lock) #define ELOOP_UNLOCK() os_mutex_unlock(eloop_data_lock)
static void *eloop_data_lock = NULL; static void *eloop_data_lock = NULL;
@@ -46,7 +46,7 @@ int eloop_init(void)
ets_timer_disarm(&eloop.eloop_timer); ets_timer_disarm(&eloop.eloop_timer);
ets_timer_setfn(&eloop.eloop_timer, (ETSTimerFunc *)eloop_run, NULL); ets_timer_setfn(&eloop.eloop_timer, (ETSTimerFunc *)eloop_run, NULL);
eloop_data_lock = xSemaphoreCreateRecursiveMutex(); eloop_data_lock = os_recursive_mutex_create();
if (!eloop_data_lock) { if (!eloop_data_lock) {
wpa_printf(MSG_ERROR, "failed to create eloop data loop"); wpa_printf(MSG_ERROR, "failed to create eloop data loop");
@@ -321,7 +321,7 @@ void eloop_destroy(void)
eloop_remove_timeout(timeout); eloop_remove_timeout(timeout);
} }
if (eloop_data_lock) { if (eloop_data_lock) {
vSemaphoreDelete(eloop_data_lock); os_semphr_delete(eloop_data_lock);
eloop_data_lock = NULL; eloop_data_lock = NULL;
} }
ets_timer_disarm(&eloop.eloop_timer); ets_timer_disarm(&eloop.eloop_timer);

View File

@@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "esp_err.h" #include "esp_err.h"
#include "supplicant_opt.h" #include "supplicant_opt.h"
#include "esp_wifi.h"
typedef time_t os_time_t; typedef time_t os_time_t;
@@ -341,4 +342,50 @@ static inline void forced_memzero(void *ptr, size_t len)
} }
} }
#endif #endif
extern const wifi_osi_funcs_t *wifi_funcs;
#define OS_BLOCK OSI_FUNCS_TIME_BLOCKING
#define os_mutex_lock(a) wifi_funcs->_mutex_lock((a))
#define os_mutex_unlock(a) wifi_funcs->_mutex_unlock((a))
#define os_recursive_mutex_create() wifi_funcs->_recursive_mutex_create()
#define os_queue_create(a, b) wifi_funcs->_queue_create((a), (b))
#define os_queue_delete(a) wifi_funcs->_queue_delete(a)
#define os_queue_send(a, b, c) wifi_funcs->_queue_send((a), (b), (c))
#define os_queue_recv(a, b, c) wifi_funcs->_queue_recv((a), (b), (c))
#define os_task_create(a,b,c,d,e,f) wifi_funcs->_task_create((a), (b), (c), (d), (e), (f))
#define os_task_delete(a) wifi_funcs->_task_delete((a))
#define os_task_get_current_task() wifi_funcs->_task_get_current_task()
#define os_semphr_create(a, b) wifi_funcs->_semphr_create((a), (b))
#define os_semphr_delete(a) wifi_funcs->_semphr_delete((a))
#define os_semphr_give(a) wifi_funcs->_semphr_give((a))
#define os_semphr_take(a, b) wifi_funcs->_semphr_take((a), (b))
#define os_task_ms_to_tick(a) wifi_funcs->_task_ms_to_tick((a))
#define os_timer_get_time(void) wifi_funcs->_esp_timer_get_time(void)
static inline void os_timer_setfn(void *ptimer, void *pfunction, void *parg)
{
return wifi_funcs->_timer_setfn(ptimer, pfunction, parg);
}
static inline void os_timer_disarm(void *ptimer)
{
return wifi_funcs->_timer_disarm(ptimer);
}
static inline void os_timer_arm_us(void *ptimer,uint32_t u_seconds,bool repeat_flag)
{
return wifi_funcs->_timer_arm_us(ptimer, u_seconds, repeat_flag);
}
static inline void os_timer_arm(void *ptimer,uint32_t milliseconds,bool repeat_flag)
{
return wifi_funcs->_timer_arm(ptimer, milliseconds, repeat_flag);
}
static inline void os_timer_done(void *ptimer)
{
return wifi_funcs->_timer_done(ptimer);
}
#endif /* OS_H */ #endif /* OS_H */

View File

@@ -708,7 +708,6 @@ components/esp_timer/test/test_esp_timer_light_sleep.c
components/esp_timer/test/test_ets_timer.c components/esp_timer/test/test_ets_timer.c
components/esp_wifi/include/esp_coexist_adapter.h components/esp_wifi/include/esp_coexist_adapter.h
components/esp_wifi/include/esp_mesh_internal.h components/esp_wifi/include/esp_mesh_internal.h
components/esp_wifi/include/esp_private/esp_wifi_private.h
components/esp_wifi/include/esp_private/esp_wifi_types_private.h components/esp_wifi/include/esp_private/esp_wifi_types_private.h
components/esp_wifi/include/esp_private/wifi_types.h components/esp_wifi/include/esp_private/wifi_types.h
components/esp_wifi/include/esp_smartconfig.h components/esp_wifi/include/esp_smartconfig.h