From 3acd9861bf89ad24036a561f479693d83c5cedfc Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Fri, 20 Nov 2020 21:48:54 +0800 Subject: [PATCH] wpa_supplicant: Use WPA3 flag to reduce code size Flag ESP32_WIFI_ENABLE_WPA3_SAE from Menuconfig is used to control the stack size required by WPA3. Use the same flag to compile out the WPA3 code and control the code size. With this flag disabled code footprint reduces by about 7.7kB in libwpa_supplicant.a Update WiFi libs with added checks to cleanly handle disabling of WPA3 callbacks. --- components/wpa_supplicant/CMakeLists.txt | 5 ++++- components/wpa_supplicant/component.mk | 6 +++++- components/wpa_supplicant/src/common/wpa_common.c | 6 +++--- components/wpa_supplicant/src/esp_supplicant/esp_wpa3_i.h | 4 ++++ components/wpa_supplicant/src/rsn_supp/wpa_ie.c | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/components/wpa_supplicant/CMakeLists.txt b/components/wpa_supplicant/CMakeLists.txt index e02604b33c..4fc3638cda 100644 --- a/components/wpa_supplicant/CMakeLists.txt +++ b/components/wpa_supplicant/CMakeLists.txt @@ -129,9 +129,12 @@ target_compile_definitions(${COMPONENT_LIB} PRIVATE ESP32_WORKAROUND CONFIG_ECC CONFIG_IEEE80211W - CONFIG_WPA3_SAE CONFIG_SHA256 CONFIG_DPP ) +if(CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE) + target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WPA3_SAE) +endif() + set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 3) diff --git a/components/wpa_supplicant/component.mk b/components/wpa_supplicant/component.mk index 7a178d8791..7706f77a25 100644 --- a/components/wpa_supplicant/component.mk +++ b/components/wpa_supplicant/component.mk @@ -26,4 +26,8 @@ else COMPONENT_OBJEXCLUDE := src/crypto/tls_mbedtls.o endif -CFLAGS += -DCONFIG_DPP -DCONFIG_WPA3_SAE -DCONFIG_IEEE80211W -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DEAP_PEAP -DEAP_MSCHAPv2 -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DCONFIG_ECC -D__ets__ -Wno-strict-aliasing +CFLAGS += -DCONFIG_DPP -DCONFIG_IEEE80211W -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DEAP_PEAP -DEAP_MSCHAPv2 -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DCONFIG_ECC -D__ets__ -Wno-strict-aliasing + +ifdef CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE + CFLAGS += -DCONFIG_WPA3_SAE +endif diff --git a/components/wpa_supplicant/src/common/wpa_common.c b/components/wpa_supplicant/src/common/wpa_common.c index ba909fee26..a7532c47b9 100644 --- a/components/wpa_supplicant/src/common/wpa_common.c +++ b/components/wpa_supplicant/src/common/wpa_common.c @@ -58,11 +58,11 @@ static int rsn_key_mgmt_to_bitfield(const u8 *s) if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_FT_PSK) return WPA_KEY_MGMT_FT_PSK; #endif /* CONFIG_IEEE80211R */ +#ifdef CONFIG_IEEE80211W #ifdef CONFIG_WPA3_SAE if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_SAE) return WPA_KEY_MGMT_SAE; #endif /* CONFIG_WPA3_SAE */ -#ifdef CONFIG_IEEE80211W if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_802_1X_SHA256) return WPA_KEY_MGMT_IEEE8021X_SHA256; if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_PSK_SHA256) @@ -396,10 +396,10 @@ int wpa_eapol_key_mic(const u8 *key, int ver, const u8 *buf, size_t len, #ifdef CONFIG_IEEE80211W #ifdef CONFIG_WPA3_SAE case WPA_KEY_INFO_TYPE_AKM_DEFINED: -#endif +#endif /* CONFIG_WPA3_SAE */ case WPA_KEY_INFO_TYPE_AES_128_CMAC: return omac1_aes_128(key, buf, len, mic); -#endif +#endif /* CONFIG_IEEE80211W */ default: return -1; } diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_wpa3_i.h b/components/wpa_supplicant/src/esp_supplicant/esp_wpa3_i.h index 93223040e8..738df29181 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_wpa3_i.h +++ b/components/wpa_supplicant/src/esp_supplicant/esp_wpa3_i.h @@ -31,5 +31,9 @@ static inline void esp_wifi_register_wpa3_cb(struct wpa_funcs *wpa_cb) wpa_cb->wpa3_parse_sae_msg = NULL; } +static inline void esp_wpa3_free_sae_data(void) +{ +} + #endif /* CONFIG_WPA3_SAE */ #endif /* ESP_WPA3_H */ diff --git a/components/wpa_supplicant/src/rsn_supp/wpa_ie.c b/components/wpa_supplicant/src/rsn_supp/wpa_ie.c index d648a45429..497d50ec7b 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa_ie.c +++ b/components/wpa_supplicant/src/rsn_supp/wpa_ie.c @@ -203,11 +203,11 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len, RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SHA256); } else if (key_mgmt == WPA_KEY_MGMT_PSK_SHA256) { RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_SHA256); -#endif /* CONFIG_IEEE80211W */ #ifdef CONFIG_WPA3_SAE } else if (key_mgmt == WPA_KEY_MGMT_SAE) { RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_SAE); #endif /* CONFIG_WPA3_SAE */ +#endif /* CONFIG_IEEE80211W */ } else { wpa_printf(MSG_DEBUG, "Invalid key management type (%d).", key_mgmt);