From cc6196ff6a348b26af4acaf64789eb30a4379b53 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Mon, 29 Aug 2022 15:16:16 +0530 Subject: [PATCH] esp_wifi: Remove unnecessary function pointer from wpa_sm_init --- .../esp_supplicant/src/esp_wpa_main.c | 3 +- .../esp_supplicant/src/esp_wpas_glue.c | 3 +- components/wpa_supplicant/src/rsn_supp/wpa.c | 28 +++++------------ .../wpa_supplicant/src/rsn_supp/wpa_i.h | 30 +++++-------------- 4 files changed, 18 insertions(+), 46 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c index 8c3e4e9efd..a1daecf01c 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c @@ -124,8 +124,7 @@ void wpa_neg_complete(void) bool wpa_attach(void) { bool ret = true; - ret = wpa_sm_init(NULL, wpa_sendto_wrapper, - wpa_config_assoc_ie, wpa_install_key, wpa_get_key, wpa_deauthenticate, wpa_neg_complete); + ret = wpa_sm_init(); if(ret) { ret = (esp_wifi_register_tx_cb_internal(eapol_txcb, WIFI_TXCB_EAPOL_ID) == ESP_OK); } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c index a250db8672..8ade599116 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpas_glue.c @@ -107,11 +107,10 @@ void wpa_sm_free_eapol(u8 *buffer) void wpa_sm_deauthenticate(struct wpa_sm *sm, u8 reason_code) { - /*only need send deauth frame when associated*/ if (WPA_SM_STATE(sm) >= WPA_ASSOCIATED) { pmksa_cache_clear_current(sm); - sm->wpa_deauthenticate(reason_code); + wpa_deauthenticate(reason_code); } } diff --git a/components/wpa_supplicant/src/rsn_supp/wpa.c b/components/wpa_supplicant/src/rsn_supp/wpa.c index ffbb8c33df..731c3e3e30 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa.c +++ b/components/wpa_supplicant/src/rsn_supp/wpa.c @@ -818,7 +818,7 @@ void wpa_supplicant_key_neg_complete(struct wpa_sm *sm, wpa_sm_cancel_auth_timeout(sm); wpa_sm_set_state(WPA_COMPLETED); - sm->wpa_neg_complete(); + wpa_neg_complete(); if (secure) { wpa_sm_mlme_setprotection( @@ -2192,26 +2192,14 @@ void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm) } - - -#ifdef ESP_SUPPLICANT -bool wpa_sm_init(char * payload, WPA_SEND_FUNC snd_func, - WPA_SET_ASSOC_IE set_assoc_ie_func, WPA_INSTALL_KEY ppinstallkey, WPA_GET_KEY ppgetkey, WPA_DEAUTH_FUNC wpa_deauth, - WPA_NEG_COMPLETE wpa_neg_complete) +bool wpa_sm_init(void) { struct wpa_sm *sm = &gWpaSm; u16 spp_attrubute = 0; + os_memset(sm, 0, sizeof(struct wpa_sm)); + sm->eapol_version = DEFAULT_EAPOL_VERSION; /* DEFAULT_EAPOL_VERSION */ - sm->sendto = snd_func; - sm->config_assoc_ie = set_assoc_ie_func; - sm->install_ppkey = ppinstallkey; - sm->get_ppkey = ppgetkey; - sm->wpa_deauthenticate = wpa_deauth; - sm->wpa_neg_complete = wpa_neg_complete; - sm->key_install = false; - sm->ap_rsnxe = NULL; - sm->assoc_rsnxe = NULL; spp_attrubute = esp_wifi_get_spp_attrubute_internal(WIFI_IF_STA); sm->spp_sup.capable = ((spp_attrubute & WPA_CAPABILITY_SPP_CAPABLE) ? SPP_AMSDU_CAP_ENABLE : SPP_AMSDU_CAP_DISABLE); @@ -2242,6 +2230,7 @@ void wpa_sm_deinit(void) } +#ifdef ESP_SUPPLICANT void wpa_set_profile(u32 wpa_proto, u8 auth_mode) { struct wpa_sm *sm = &gWpaSm; @@ -2468,7 +2457,7 @@ set_assoc_ie(u8 * assoc_buf) else sm->assoc_wpa_ie_len = ASSOC_IE_LEN - 2; - sm->config_assoc_ie(sm->proto, assoc_buf, sm->assoc_wpa_ie_len); + wpa_config_assoc_ie(sm->proto, assoc_buf, sm->assoc_wpa_ie_len); } int wpa_sm_set_key(struct install_key *key_sm, enum wpa_alg alg, @@ -2492,15 +2481,14 @@ int wpa_sm_set_key(struct install_key *key_sm, enum wpa_alg alg, key_sm->set_tx = set_tx; memcpy(key_sm->key, key, key_len); - sm->install_ppkey(alg, addr, key_idx, set_tx, seq, seq_len, key, key_len, key_flag); + wpa_install_key(alg, addr, key_idx, set_tx, seq, seq_len, key, key_len, key_flag); return 0; } static int wpa_sm_get_key(uint8_t *ifx, int *alg, u8 *addr, int *key_idx, u8 *key, size_t key_len, enum key_flag key_flag) { - struct wpa_sm *sm = &gWpaSm; - return sm->get_ppkey(ifx, alg, addr, key_idx, key, key_len, key_flag); + return wpa_get_key(ifx, alg, addr, key_idx, key, key_len, key_flag); } void wpa_supplicant_clr_countermeasures(u16 *pisunicast) diff --git a/components/wpa_supplicant/src/rsn_supp/wpa_i.h b/components/wpa_supplicant/src/rsn_supp/wpa_i.h index b19924c52c..b513ebc4e9 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa_i.h +++ b/components/wpa_supplicant/src/rsn_supp/wpa_i.h @@ -76,14 +76,6 @@ struct wpa_sm { struct install_key install_gtk; int mic_errors_seen; /* Michael MIC errors with the current PTK */ - void (* sendto) (void *buffer, uint16_t len); - void (*config_assoc_ie) (u8 proto, u8 *assoc_buf, u32 assoc_wpa_ie_len); - void (*install_ppkey) (enum wpa_alg alg, u8 *addr, int key_idx, int set_tx, - u8 *seq, unsigned int seq_len, u8 *key, unsigned int key_len, enum key_flag key_flag); - int (*get_ppkey) (uint8_t *ifx, int *alg, uint8_t *addr, int *key_idx, - uint8_t *key, size_t key_len, enum key_flag key_flag); - void (*wpa_deauthenticate)(u8 reason_code); - void (*wpa_neg_complete)(void); struct wpa_gtk_data gd; //used for calllback save param u16 key_info; //used for txcallback param u16 txcb_flags; @@ -165,8 +157,6 @@ struct wpa_sm { */ -typedef void (* WPA_SEND_FUNC)(void *buffer, u16 len); - int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md, const u8 *ies, size_t ies_len, bool auth_ie); @@ -183,24 +173,20 @@ static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm, return 0; } -typedef void (* WPA_SET_ASSOC_IE)(u8 proto, u8 *assoc_buf, u32 assoc_wpa_ie_len); +void wpa_config_assoc_ie(u8 proto, u8 *assoc_buf, u32 assoc_wpa_ie_len); -typedef 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); +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); -typedef int (*WPA_GET_KEY) (u8 *ifx, int *alg, u8 *addt, int *keyidx, u8 *key, size_t key_len, enum key_flag key_flag); +int wpa_get_key(uint8_t *ifx, int *alg, u8 *addr, int *key_idx, + u8 *key, size_t key_len, enum key_flag key_flag); -typedef void (*WPA_DEAUTH_FUNC)(u8 reason_code); +void wpa_deauthenticate(u8 reason_code); -typedef void (*WPA_NEG_COMPLETE)(void); +void wpa_neg_complete(void); -bool wpa_sm_init(char * payload, WPA_SEND_FUNC snd_func, \ - WPA_SET_ASSOC_IE set_assoc_ie_func, \ - WPA_INSTALL_KEY ppinstallkey, \ - WPA_GET_KEY ppgetkey, \ - WPA_DEAUTH_FUNC wpa_deauth, \ - WPA_NEG_COMPLETE wpa_neg_complete); +bool wpa_sm_init(void); void wpa_sm_deinit(void);