From c0f4fdfd4da1f94a8642f54dee49f648102cb66a 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. Closes https://github.com/espressif/esp-idf/issues/5971 --- components/esp_wifi/lib | 2 +- 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 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 34f1262375..4bd967c1dc 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 34f1262375795c34dca8520ffd042f0e104843b7 +Subproject commit 4bd967c1dc46ab98028e71c406031759ac66a7b9 diff --git a/components/wpa_supplicant/CMakeLists.txt b/components/wpa_supplicant/CMakeLists.txt index 1dfdaa78c9..377b8a8e5a 100644 --- a/components/wpa_supplicant/CMakeLists.txt +++ b/components/wpa_supplicant/CMakeLists.txt @@ -144,10 +144,13 @@ target_compile_definitions(${COMPONENT_LIB} PRIVATE ESP32_WORKAROUND CONFIG_ECC CONFIG_IEEE80211W - CONFIG_WPA3_SAE CONFIG_SHA256 CONFIG_DPP CONFIG_WNM ) +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 e6b473c465..c81e71993b 100644 --- a/components/wpa_supplicant/component.mk +++ b/components/wpa_supplicant/component.mk @@ -35,4 +35,8 @@ ifneq ($(CONFIG_WPA_11KV_SUPPORT), y) src/esp_supplicant/esp_scan.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 -DCONFIG_WNM -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 -DCONFIG_WNM -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 6ad624c8b9..39e0fd3581 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 7b949634ac..76ba0ebb93 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);