Skip to content

Commit

Permalink
Merge branch 'bugfix/eapol_txdone_cb_issue_v4.4' into 'release/v4.4'
Browse files Browse the repository at this point in the history
Fix EAPOL Key TxDone callback implementation (Backport v4.4)

See merge request espressif/esp-idf!25382
  • Loading branch information
jack0c committed Aug 17, 2023
2 parents 8c1e87e + debcbac commit e6bd433
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ esf_buf_alloc_dynamic = 0x400015c0;
esf_buf_recycle = 0x400015c4;
/*lmacTxDone = 0x4000162c;*/
ppMapTxQueue = 0x400016d8;
rcGetSched = 0x40001764;
/*rcGetSched = 0x40001764;*/
wDevCheckBlockError = 0x400017b4;
ppProcTxDone = 0x40001804;
/*sta_input = rom_sta_input;*/
Expand Down
2 changes: 1 addition & 1 deletion components/esp_rom/esp32s3/ld/esp32s3.rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ rcampduuprate = 0x4000573c;
rcClearCurAMPDUSched = 0x40005748;
rcClearCurSched = 0x40005754;
rcClearCurStat = 0x40005760;
rcGetSched = 0x4000576c;
/*rcGetSched = 0x4000576c;*/
rcLowerSched = 0x40005778;
rcSetTxAmpduLimit = 0x40005784;
/* rcTxUpdatePer = 0x40005790;*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -167,8 +167,8 @@ typedef enum wps_status {
WPS_STATUS_MAX,
} WPS_STATUS_t;

#define WIFI_TXCB_EAPOL_ID 3
typedef void(*wifi_tx_cb_t)(void *);
typedef void(* eapol_txcb_t)(uint8_t *, size_t, bool);
typedef int (*wifi_ipc_fn_t)(void *);
typedef struct {
wifi_ipc_fn_t fn;
Expand Down Expand Up @@ -229,6 +229,7 @@ bool esp_wifi_wpa_ptk_init_done_internal(uint8_t *mac);
uint8_t esp_wifi_sta_set_reset_param_internal(uint8_t reset_flag);
uint8_t esp_wifi_get_sta_gtk_index_internal(void);
int esp_wifi_register_tx_cb_internal(wifi_tx_cb_t fn, u8 id);
int esp_wifi_register_eapol_txdonecb_internal(eapol_txcb_t fn);
int esp_wifi_register_wpa_cb_internal(struct wpa_funcs *cb);
int esp_wifi_unregister_wpa_cb_internal(void);
int esp_wifi_get_assoc_bssid_internal(uint8_t *bssid);
Expand Down
3 changes: 2 additions & 1 deletion components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool wpa_attach(void)
ret = wpa_sm_init(NULL, wpa_sendto_wrapper,
wpa_config_assoc_ie, wpa_install_key, wpa_get_key, wpa_deauthenticate, wpa_neg_complete);
if(ret) {
ret = (esp_wifi_register_tx_cb_internal(eapol_txcb, WIFI_TXCB_EAPOL_ID) == ESP_OK);
ret = (esp_wifi_register_eapol_txdonecb_internal(eapol_txcb) == ESP_OK);
}
esp_set_scan_ie();
return ret;
Expand Down Expand Up @@ -161,6 +161,7 @@ void wpa_ap_get_peer_spp_msg(void *sm_data, bool *spp_cap, bool *spp_req)
bool wpa_deattach(void)
{
esp_wifi_sta_wpa2_ent_disable();
esp_wifi_register_eapol_txdonecb_internal(NULL);
wpa_sm_deinit();
return true;
}
Expand Down
36 changes: 23 additions & 13 deletions components/wpa_supplicant/src/rsn_supp/wpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2646,30 +2646,40 @@ int wpa_michael_mic_failure(u16 isunicast)
eapol tx callback function to make sure new key
install after 4-way handoff
*/
void eapol_txcb(void *eb)
void eapol_txcb(uint8_t *eapol_payload, size_t len, bool tx_failure)
{
struct ieee802_1x_hdr *hdr;
struct wpa_eapol_key *key;
struct wpa_sm *sm = &gWpaSm;
u8 isdeauth = 0; //no_zero value is the reason for deauth

if (false == esp_wifi_sta_is_running_internal()){
if (len < (sizeof(struct ieee802_1x_hdr) + sizeof(struct wpa_eapol_key))) {
wpa_printf(MSG_ERROR, "EAPOL TxDone with invalid payload len! (len - %d)", len);
return;
}
hdr = (struct ieee802_1x_hdr *) eapol_payload;
key = (struct wpa_eapol_key *) (hdr + 1);

switch(WPA_SM_STATE(sm)) {
case WPA_FIRST_HALF_4WAY_HANDSHAKE:
break;
case WPA_LAST_HALF_4WAY_HANDSHAKE:

if (esp_wifi_eb_tx_status_success_internal(eb) != true) {
wpa_printf(MSG_ERROR, "Eapol message 4/4 tx failure, not installing keys");
return;
}

if (sm->txcb_flags & WPA_4_4_HANDSHAKE_BIT) {
sm->txcb_flags &= ~WPA_4_4_HANDSHAKE_BIT;
isdeauth = wpa_supplicant_send_4_of_4_txcallback(sm);
if (WPA_GET_BE16(key->key_data_length) == 0 ||
(WPA_GET_BE16(key->key_info) & WPA_KEY_INFO_SECURE)) {
/* msg 4/4 Tx Done */
if (tx_failure) {
wpa_printf(MSG_ERROR, "Eapol message 4/4 tx failure, not installing keys");
return;
}

if (sm->txcb_flags & WPA_4_4_HANDSHAKE_BIT) {
sm->txcb_flags &= ~WPA_4_4_HANDSHAKE_BIT;
isdeauth = wpa_supplicant_send_4_of_4_txcallback(sm);
} else {
wpa_printf(MSG_DEBUG, "4/4 txcb, flags=%d", sm->txcb_flags);
}
} else {
wpa_printf(MSG_DEBUG, "4/4 txcb, flags=%d\n", sm->txcb_flags);
/* msg 2/4 Tx Done */
wpa_printf(MSG_DEBUG, "2/4 txcb, flags=%d, txfail %d", sm->txcb_flags, tx_failure);
}
break;
case WPA_GROUP_HANDSHAKE:
Expand Down
2 changes: 1 addition & 1 deletion components/wpa_supplicant/src/rsn_supp/wpa_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bool wpa_sm_init(char * payload, WPA_SEND_FUNC snd_func, \

void wpa_sm_deinit(void);

void eapol_txcb(void *eb);
void eapol_txcb(uint8_t *eapol_payload, size_t len, bool tx_failure);

void wpa_set_profile(u32 wpa_proto, u8 auth_mode);

Expand Down

0 comments on commit e6bd433

Please sign in to comment.