mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-18 01:29:02 +00:00
wpa_supplicant: Move ETS/ESP timers to eloop
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "utils/includes.h"
|
||||
#include "common.h"
|
||||
#include "eloop.h"
|
||||
#include "rsn_supp/wpa.h"
|
||||
#include "utils/common.h"
|
||||
#include "common/eapol_common.h"
|
||||
@@ -53,7 +55,7 @@ static uint8_t s_wps_sig_cnt[SIG_WPS_NUM] = {0};
|
||||
#endif
|
||||
|
||||
void wifi_wps_scan_done(void *arg, STATUS status);
|
||||
void wifi_wps_scan(void);
|
||||
void wifi_wps_scan(void *data, void *user_ctx);
|
||||
int wifi_station_wps_start(void);
|
||||
int wps_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len);
|
||||
void wifi_wps_start_internal(void);
|
||||
@@ -66,6 +68,11 @@ void wifi_wps_scan_internal(void);
|
||||
void wifi_station_wps_eapol_start_handle_internal(void);
|
||||
void wps_add_discard_ap(u8 *bssid);
|
||||
|
||||
void wifi_station_wps_msg_timeout(void *data, void *user_ctx);
|
||||
void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx);
|
||||
void wifi_station_wps_success(void *data, void *user_ctx);
|
||||
void wifi_station_wps_timeout(void *data, void *user_ctx);
|
||||
|
||||
struct wps_sm *gWpsSm = NULL;
|
||||
static wps_factory_information_t *s_factory_info = NULL;
|
||||
|
||||
@@ -228,7 +235,7 @@ int wps_post(uint32_t sig, uint32_t par)
|
||||
evt->par = par;
|
||||
DATA_MUTEX_GIVE();
|
||||
|
||||
if (os_queue_send(s_wps_queue, &evt, 10 / portTICK_PERIOD_MS) != TRUE) {
|
||||
if (os_queue_send(s_wps_queue, &evt, os_task_ms_to_tick(10)) != TRUE) {
|
||||
wpa_printf(MSG_ERROR, "WPS: Q S E");
|
||||
DATA_MUTEX_TAKE();
|
||||
s_wps_sig_cnt[sig]--;
|
||||
@@ -586,7 +593,7 @@ int wps_process_wps_mX_req(u8 *ubuf, int len, enum wps_process_res *res)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
|
||||
if (res) {
|
||||
*res = wps_enrollee_process_msg(sm->wps, expd->opcode, wps_buf);
|
||||
@@ -675,7 +682,7 @@ int wps_tx_start(void)
|
||||
wps_sm_ether_send(sm, ETH_P_EAPOL, buf, len);
|
||||
wps_sm_free_eapol(buf);
|
||||
|
||||
ets_timer_arm(&sm->wps_eapol_start_timer, 3000, 0);
|
||||
eloop_register_timeout(3, 0, wifi_station_wps_eapol_start_handle, NULL, NULL);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -693,8 +700,8 @@ int wps_start_pending(void)
|
||||
static void wps_stop_connection_timers(struct wps_sm *sm)
|
||||
{
|
||||
esp_wifi_disarm_sta_connection_timer_internal();
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_disarm(&sm->wps_success_cb_timer);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_success, NULL, NULL);
|
||||
}
|
||||
|
||||
static int wps_sm_init(struct wps_sm *sm)
|
||||
@@ -765,8 +772,8 @@ int wps_finish(void)
|
||||
|
||||
os_free(config);
|
||||
}
|
||||
ets_timer_disarm(&sm->wps_success_cb_timer);
|
||||
ets_timer_arm(&sm->wps_success_cb_timer, 1000, 0);
|
||||
eloop_cancel_timeout(wifi_station_wps_success, NULL, NULL);
|
||||
eloop_register_timeout(1, 0, wifi_station_wps_success, NULL, NULL);
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
@@ -820,14 +827,14 @@ int wps_start_msg_timer(void)
|
||||
if (sm->wps->state == WPS_FINISHED) {
|
||||
msg_timeout = 100;
|
||||
wpa_printf(MSG_DEBUG, "start msg timer WPS_FINISHED %d ms", msg_timeout);
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_arm(&sm->wps_msg_timeout_timer, msg_timeout, 0);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
eloop_register_timeout(0, msg_timeout*1000, wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
ret = 0;
|
||||
} else if (sm->wps->state == RECV_M2) {
|
||||
msg_timeout = 5000;
|
||||
msg_timeout = 5;
|
||||
wpa_printf(MSG_DEBUG, "start msg timer RECV_M2 %d ms", msg_timeout);
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_arm(&sm->wps_msg_timeout_timer, msg_timeout, 0);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
eloop_register_timeout(msg_timeout, 0, wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
@@ -980,10 +987,10 @@ int wps_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len)
|
||||
case EAP_TYPE_IDENTITY:
|
||||
wpa_printf(MSG_DEBUG, "=========identity===========");
|
||||
sm->current_identifier = ehdr->identifier;
|
||||
ets_timer_disarm(&sm->wps_eapol_start_timer);
|
||||
eloop_cancel_timeout(wifi_station_wps_eapol_start_handle, NULL, NULL);
|
||||
wpa_printf(MSG_DEBUG, "WPS: Build EAP Identity.");
|
||||
ret = wps_send_eap_identity_rsp(ehdr->identifier);
|
||||
ets_timer_arm(&sm->wps_eapol_start_timer, 3000, 0);
|
||||
eloop_register_timeout(3, 0, wifi_station_wps_eapol_start_handle, NULL, NULL);
|
||||
break;
|
||||
case EAP_TYPE_EXPANDED:
|
||||
wpa_printf(MSG_DEBUG, "=========expanded plen[%d], %d===========", plen, sizeof(*ehdr));
|
||||
@@ -1019,13 +1026,13 @@ int wps_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len)
|
||||
}
|
||||
out:
|
||||
if (ret != 0 && sm->ignore_sel_reg) {
|
||||
wifi_wps_scan();
|
||||
wifi_wps_scan(NULL, NULL);
|
||||
} else if ((ret != 0 || res == WPS_FAILURE)) {
|
||||
wifi_event_sta_wps_fail_reason_t reason_code = WPS_FAIL_REASON_NORMAL;
|
||||
wpa_printf(MSG_DEBUG, "wpa rx eapol internal: fail ret=%d", ret);
|
||||
wps_set_status(WPS_STATUS_DISABLE);
|
||||
esp_wifi_disarm_sta_connection_timer_internal();
|
||||
ets_timer_disarm(&sm->wps_timeout_timer);
|
||||
eloop_cancel_timeout(wifi_station_wps_timeout, NULL, NULL);
|
||||
|
||||
esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), OS_BLOCK);
|
||||
|
||||
@@ -1213,7 +1220,7 @@ wifi_station_wps_timeout_internal(void)
|
||||
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 *data, void *user_ctx)
|
||||
{
|
||||
#ifdef USE_WPS_TASK
|
||||
wps_post(SIG_WPS_TIMER_TIMEOUT, 0);
|
||||
@@ -1248,11 +1255,11 @@ wifi_station_wps_msg_timeout_internal(void)
|
||||
os_bzero(sm->ssid_len, sizeof(sm->ssid_len));
|
||||
os_bzero(sm->bssid, ETH_ALEN);
|
||||
sm->discover_ssid_cnt = 0;
|
||||
wifi_wps_scan();
|
||||
wifi_wps_scan(NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_station_wps_msg_timeout(void)
|
||||
void wifi_station_wps_msg_timeout(void *data, void *user_ctx)
|
||||
{
|
||||
#ifdef USE_WPS_TASK
|
||||
wps_post(SIG_WPS_TIMER_MSG_TIMEOUT, 0);
|
||||
@@ -1286,7 +1293,7 @@ void wifi_station_wps_success_internal(void)
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_station_wps_success(void)
|
||||
void wifi_station_wps_success(void *data, void *user_ctx)
|
||||
{
|
||||
#ifdef USE_WPS_TASK
|
||||
wps_post(SIG_WPS_TIMER_SUCCESS_CB, 0);
|
||||
@@ -1302,7 +1309,7 @@ void wifi_station_wps_eapol_start_handle_internal(void)
|
||||
wps_tx_start();
|
||||
}
|
||||
|
||||
void wifi_station_wps_eapol_start_handle(void)
|
||||
void wifi_station_wps_eapol_start_handle(void *data, void *user_ctx)
|
||||
{
|
||||
#ifdef USE_WPS_TASK
|
||||
wps_post(SIG_WPS_TIMER_EAPOL_START, 0);
|
||||
@@ -1418,16 +1425,11 @@ wifi_station_wps_init(void)
|
||||
wps_build_ic_appie_wps_ar();
|
||||
}
|
||||
|
||||
ets_timer_disarm(&sm->wps_timeout_timer);
|
||||
ets_timer_setfn(&sm->wps_timeout_timer, (ETSTimerFunc *)wifi_station_wps_timeout, NULL);
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_setfn(&sm->wps_msg_timeout_timer, (ETSTimerFunc *)wifi_station_wps_msg_timeout, NULL);
|
||||
ets_timer_disarm(&sm->wps_success_cb_timer);
|
||||
ets_timer_setfn(&sm->wps_success_cb_timer, (ETSTimerFunc *)wifi_station_wps_success, NULL);
|
||||
ets_timer_disarm(&sm->wps_scan_timer);
|
||||
ets_timer_setfn(&sm->wps_scan_timer, (ETSTimerFunc *)wifi_wps_scan, NULL);
|
||||
ets_timer_disarm(&sm->wps_eapol_start_timer);
|
||||
ets_timer_setfn(&sm->wps_eapol_start_timer, (ETSTimerFunc *)wifi_station_wps_eapol_start_handle, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_timeout, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_success, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_wps_scan, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_eapol_start_handle, NULL, NULL);
|
||||
|
||||
wps_cb = os_malloc(sizeof(struct wps_funcs));
|
||||
if (wps_cb == NULL) {
|
||||
@@ -1472,16 +1474,11 @@ int wps_delete_timer(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
ets_timer_disarm(&sm->wps_success_cb_timer);
|
||||
ets_timer_disarm(&sm->wps_timeout_timer);
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_disarm(&sm->wps_scan_timer);
|
||||
ets_timer_disarm(&sm->wps_eapol_start_timer);
|
||||
ets_timer_done(&sm->wps_success_cb_timer);
|
||||
ets_timer_done(&sm->wps_timeout_timer);
|
||||
ets_timer_done(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_done(&sm->wps_scan_timer);
|
||||
ets_timer_done(&sm->wps_eapol_start_timer);
|
||||
eloop_cancel_timeout(wifi_station_wps_success, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_timeout, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_wps_scan, NULL, NULL);
|
||||
eloop_cancel_timeout(wifi_station_wps_eapol_start_handle, NULL, NULL);
|
||||
esp_wifi_disarm_sta_connection_timer_internal();
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -1564,14 +1561,15 @@ wifi_wps_scan_done(void *arg, STATUS status)
|
||||
|
||||
wpa_printf(MSG_DEBUG, "WPS: neg start");
|
||||
esp_wifi_connect();
|
||||
ets_timer_disarm(&sm->wps_msg_timeout_timer);
|
||||
ets_timer_arm(&sm->wps_msg_timeout_timer, 2000, 0);
|
||||
eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
eloop_register_timeout(2, 0, wifi_station_wps_msg_timeout, NULL, NULL);
|
||||
} else if (wps_get_status() == WPS_STATUS_SCANNING) {
|
||||
if (wps_get_type() == WPS_TYPE_PIN && sm->scan_cnt > WPS_IGNORE_SEL_REG_MAX_CNT) {
|
||||
wpa_printf(MSG_INFO, "WPS: ignore selected registrar after %d scans", sm->scan_cnt);
|
||||
sm->ignore_sel_reg = true;
|
||||
}
|
||||
ets_timer_arm(&sm->wps_scan_timer, 100, 0);
|
||||
eloop_cancel_timeout(wifi_wps_scan, NULL, NULL);
|
||||
eloop_register_timeout(0, 100*1000, wifi_wps_scan, NULL, NULL);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -1590,7 +1588,7 @@ wifi_wps_scan_internal(void)
|
||||
esp_wifi_promiscuous_scan_start(NULL, wifi_wps_scan_done);
|
||||
}
|
||||
|
||||
void wifi_wps_scan(void)
|
||||
void wifi_wps_scan(void *data, void *user_ctx)
|
||||
{
|
||||
#ifdef USE_WPS_TASK
|
||||
wps_post(SIG_WPS_TIMER_SCAN, 0);
|
||||
@@ -1614,7 +1612,7 @@ int wifi_station_wps_start(void)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ets_timer_arm(&sm->wps_timeout_timer, 120000, 0); /* 120s total */
|
||||
eloop_register_timeout(120, 0, wifi_station_wps_timeout, NULL, NULL);
|
||||
|
||||
switch (wps_get_status()) {
|
||||
case WPS_STATUS_DISABLE: {
|
||||
@@ -1627,13 +1625,13 @@ int wifi_station_wps_start(void)
|
||||
sm->wps->wps->rf_band_cb = wps_rf_band_cb;
|
||||
wpabuf_clear_free(sm->wps->dh_privkey);
|
||||
sm->wps->dh_privkey = NULL;
|
||||
wifi_wps_scan();
|
||||
wifi_wps_scan(NULL, NULL);
|
||||
break;
|
||||
}
|
||||
case WPS_STATUS_SCANNING:
|
||||
sm->scan_cnt = 0;
|
||||
ets_timer_disarm(&sm->wps_timeout_timer);
|
||||
ets_timer_arm(&sm->wps_timeout_timer, 120000, 0); /* 120s total */
|
||||
eloop_cancel_timeout(wifi_station_wps_timeout, NULL, NULL);
|
||||
eloop_register_timeout(120, 0, wifi_station_wps_timeout, NULL, NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
Reference in New Issue
Block a user