From f5a114a42f38674416210a46a15a5652a7ed89ae Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 2 Jan 2025 11:10:41 +0530 Subject: [PATCH] fix(esp_wifi): Add review comments and some cleanup --- .../esp_supplicant/src/esp_common.c | 29 +++++++++-------- .../esp_supplicant/src/esp_hostap.c | 4 +-- .../esp_supplicant/src/esp_wpa3.c | 32 +++++++++++-------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common.c b/components/wpa_supplicant/esp_supplicant/src/esp_common.c index e3990293a1..36b147b09c 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common.c @@ -782,15 +782,16 @@ int wpa_drv_send_action(struct wpa_supplicant *wpa_s, const u8 *data, size_t data_len, int no_cck) { - int ret = 0; - wifi_mgmt_frm_req_t *req = os_zalloc(sizeof(*req) + data_len);; - if (!req) - return -1; + int ret = -1; + wifi_mgmt_frm_req_t *req; if (!wpa_s->current_bss) { - wpa_printf(MSG_ERROR, "STA not associated, return"); - ret = -1; - goto cleanup; + return ret; + } + + req = os_zalloc(sizeof(*req) + data_len); + if (!req) { + return ret; } req->ifx = WIFI_IF_STA; @@ -798,14 +799,14 @@ int wpa_drv_send_action(struct wpa_supplicant *wpa_s, req->data_len = data_len; os_memcpy(req->data, data, req->data_len); - if (esp_wifi_send_mgmt_frm_internal(req) != 0) { - wpa_printf(MSG_ERROR, "action frame sending failed"); - ret = -1; - goto cleanup; - } - wpa_printf(MSG_INFO, "action frame sent"); + ret = esp_wifi_send_mgmt_frm_internal(req); + + if (ret != 0) { + wpa_printf(MSG_ERROR, "action frame sending failed"); + } else { + wpa_printf(MSG_INFO, "action frame sent"); + } -cleanup: os_free(req); return ret; } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c b/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c index 82ff55ee40..5bc9f7fa31 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_hostap.c @@ -308,8 +308,7 @@ u16 esp_send_assoc_resp(struct hostapd_data *hapd, const u8 *addr, reply = os_zalloc(sizeof(wifi_mgmt_frm_req_t) + sizeof(uint16_t)); if (!reply) { wpa_printf(MSG_ERROR, "failed to allocate memory for assoc response"); - res = WLAN_STATUS_UNSPECIFIED_FAILURE; - goto done; + return WLAN_STATUS_UNSPECIFIED_FAILURE; } reply->ifx = WIFI_IF_AP; reply->subtype = subtype; @@ -322,7 +321,6 @@ u16 esp_send_assoc_resp(struct hostapd_data *hapd, const u8 *addr, wpa_printf(MSG_INFO, "esp_send_assoc_resp_failed: send failed"); } #undef ASSOC_RESP_LENGTH -done: os_free(reply); return res; } diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c index 828fc970b5..f19b6719c9 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa3.c @@ -667,35 +667,39 @@ int esp_send_sae_auth_reply(struct hostapd_data *hapd, u16 auth_alg, u16 auth_transaction, u16 resp, const u8 *ies, size_t ies_len) { - int reply_res = ESP_FAIL; - ies_len += 3 * sizeof(uint16_t); + int status = ESP_FAIL; + /* Calculate total frame data length (auth_alg + transaction + resp + IEs) */ + size_t data_len = ies_len + 3 * sizeof(uint16_t); - wifi_mgmt_frm_req_t *req = os_zalloc(sizeof(*req) + ies_len); + wifi_mgmt_frm_req_t *req = os_zalloc(sizeof(*req) + data_len); if (!req) { - wpa_printf(MSG_ERROR, "failed to send sae auth reply"); - return reply_res; + wpa_printf(MSG_ERROR, "Failed to allocate SAE authentication reply"); + return status; } - ((uint16_t *)req->data)[0] = htole16(auth_alg); - ((uint16_t *)req->data)[1] = htole16(auth_transaction); - ((uint16_t *)req->data)[2] = htole16(resp); - if (ies_len) { - os_memcpy(&((uint16_t *)req->data)[3], ies, ies_len - 3 * sizeof(uint16_t)); + /* Populate the frame data */ + ((uint16_t *)req->data)[0] = htole16(auth_alg); /* Authentication algorithm */ + ((uint16_t *)req->data)[1] = htole16(auth_transaction); /* Transaction number */ + ((uint16_t *)req->data)[2] = htole16(resp); /* Response code */ + + if (ies && ies_len) { + os_memcpy(&((uint16_t *)req->data)[3], ies, ies_len); } req->ifx = WIFI_IF_AP; req->subtype = (WLAN_FC_STYPE_AUTH << 4); - req->data_len = ies_len; + req->data_len = data_len; os_memcpy(req->da, bssid, ETH_ALEN); if (esp_wifi_send_mgmt_frm_internal(req) != 0) { - wpa_printf(MSG_INFO, "%s: send failed", __func__); + wpa_printf(MSG_INFO, "%s: SAE authentication reply send failed", __func__); } else { - reply_res = ESP_OK; + status = ESP_OK; } os_free(req); - return reply_res; + + return status; } void esp_wifi_register_wpa3_ap_cb(struct wpa_funcs *wpa_cb)