diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c index ac621e435b..3e4e13d6f5 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c @@ -570,6 +570,20 @@ int wps_process_wps_mX_req(u8 *ubuf, int len, enum wps_process_res *res) expd = (struct eap_expand *) ubuf; wpa_printf(MSG_DEBUG, "wps process mX req: len %d, tlen %d", len, tlen); + if (sm->state == WAIT_START) { + if (expd->opcode != WSC_Start) { + wpa_printf(MSG_DEBUG, "EAP-WSC: Unexpected Op-Code %d " + "in WAIT_START state", expd->opcode); + return ESP_FAIL; + } + wpa_printf(MSG_DEBUG, "EAP-WSC: Received start"); + sm->state = WPA_MESG; + } else if (expd->opcode == WSC_Start){ + wpa_printf(MSG_DEBUG, "EAP-WSC: Unexpected Op-Code %d", + expd->opcode); + return ESP_FAIL; + } + flag = *(u8 *)(ubuf + sizeof(struct eap_expand)); if (flag & WPS_MSG_FLAG_LEN) { tbuf = ubuf + sizeof(struct eap_expand) + 1 + 2;//two bytes total length @@ -622,6 +636,10 @@ int wps_process_wps_mX_req(u8 *ubuf, int len, enum wps_process_res *res) wps_enrollee_process_msg(sm->wps, expd->opcode, wps_buf); } + if (res && *res == WPS_FAILURE) { + sm->state = WPA_FAIL; + } + if (wps_buf) { wpabuf_free(wps_buf); wps_buf = NULL; @@ -757,6 +775,7 @@ int wps_stop_process(wifi_event_sta_wps_fail_reason_t reason_code) wps_stop_connection_timers(sm); esp_wifi_disconnect(); + sm->state = WPA_FAIL; wpa_printf(MSG_DEBUG, "Write wps_fail_information"); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), OS_BLOCK); @@ -1577,15 +1596,16 @@ wifi_wps_scan_done(void *arg, STATUS status) wpa_printf(MSG_DEBUG, "WPS: neg start"); esp_wifi_connect(); - eloop_cancel_timeout(wifi_station_wps_msg_timeout, NULL, NULL); - eloop_register_timeout(2, 0, wifi_station_wps_msg_timeout, NULL, NULL); + sm->state = WAIT_START; + 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; } eloop_cancel_timeout(wifi_wps_scan, NULL, NULL); - eloop_register_timeout(0, 100*1000, wifi_wps_scan, NULL, NULL); + eloop_register_timeout(0, 100*1000, wifi_wps_scan, NULL, NULL); } else { return; } @@ -1624,7 +1644,7 @@ int wifi_station_wps_start(void) struct wps_sm *sm = wps_sm_get(); if (!sm) { - wpa_printf(MSG_ERROR, "WPS: wps not initial"); + wpa_printf(MSG_ERROR, "WPS: wps is not initialized"); return ESP_FAIL; } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h b/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h index 7ad0e293b6..f28215289b 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wps_i.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -28,6 +28,14 @@ enum wps_sig_type { }; #endif +#ifdef ESP_SUPPLICANT +enum wps_sm_state{ + WAIT_START, + WPA_MESG, + WPA_FAIL +}; +#endif /* ESP_SUPPLICANT */ + #define WPS_IGNORE_SEL_REG_MAX_CNT 4 #define WPS_MAX_DIS_AP_NUM 10 @@ -47,6 +55,7 @@ struct discard_ap_list_t{ #define WPS_OUTBUF_SIZE 500 struct wps_sm { + u8 state; struct wps_config *wps_cfg; struct wps_context *wps_ctx; struct wps_data *wps; diff --git a/components/wpa_supplicant/src/wps/wps_enrollee.c b/components/wpa_supplicant/src/wps/wps_enrollee.c index 77726a0971..2f8e1aacfd 100644 --- a/components/wpa_supplicant/src/wps/wps_enrollee.c +++ b/components/wpa_supplicant/src/wps/wps_enrollee.c @@ -1667,8 +1667,8 @@ enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps, } switch (op_code) { - case WSC_Start: - return wps_process_wsc_start(wps, msg); + case WSC_Start: + return wps_process_wsc_start(wps, msg); case WSC_MSG: case WSC_UPnP: return wps_process_wsc_msg(wps, msg);