From 4afa5d0d29c0a44f8f0bdf42f3a2bb82ce5f034e Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Tue, 29 May 2018 20:25:20 +0800 Subject: [PATCH] esp32/wpa_supplicant: fix some bugs introduced by wifi os adapter 1. Fix the WiFi/BT coexist bug 2. Fix WPA2 enterprise example crash bug 3. Add size and version check for crypto type struct 4. Add MD5 check for crypto type header file --- components/esp32/fast_crypto_ops.c | 8 ++++++++ components/esp32/include/esp_wifi_crypto_types.h | 10 ++++++++++ components/esp32/include/esp_wifi_internal.h | 11 +++++++++++ components/esp32/lib | 2 +- components/esp32/phy_init.c | 2 ++ components/esp32/test/component.mk | 5 +++++ ...test_os_adapter_md5.c => test_header_files_md5.c} | 12 +++++++++++- .../include/wpa2/eap_peer/eap_methods.h | 3 +++ 8 files changed, 51 insertions(+), 2 deletions(-) rename components/esp32/test/{test_os_adapter_md5.c => test_header_files_md5.c} (52%) diff --git a/components/esp32/fast_crypto_ops.c b/components/esp32/fast_crypto_ops.c index aa0054d707..7e05a7b8c9 100644 --- a/components/esp32/fast_crypto_ops.c +++ b/components/esp32/fast_crypto_ops.c @@ -36,6 +36,8 @@ * we recommend, so as the API in WPS default and WPA2 default. */ const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = { + .size = sizeof(wpa_crypto_funcs_t), + .version = ESP_WIFI_CRYPTO_VERSION, .aes_wrap = (esp_aes_wrap_t)fast_aes_wrap, .aes_unwrap = (esp_aes_unwrap_t)fast_aes_unwrap, .hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector, @@ -58,6 +60,8 @@ const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = { }; const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = { + .size = sizeof(wps_crypto_funcs_t), + .version = ESP_WIFI_CRYPTO_VERSION, .aes_128_encrypt = (esp_aes_128_encrypt_t)fast_aes_128_cbc_encrypt, .aes_128_decrypt = (esp_aes_128_decrypt_t)fast_aes_128_cbc_decrypt, .crypto_mod_exp = (esp_crypto_mod_exp_t)fast_crypto_mod_exp, @@ -85,6 +89,8 @@ const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = { * crypto_hash_finish, so do crypto_cipher. */ const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs = { + .size = sizeof(wpa2_crypto_funcs_t), + .version = ESP_WIFI_CRYPTO_VERSION, .crypto_hash_init = (esp_crypto_hash_init_t)fast_crypto_hash_init, .crypto_hash_update = (esp_crypto_hash_update_t)fast_crypto_hash_update, .crypto_hash_finish = (esp_crypto_hash_finish_t)fast_crypto_hash_finish, @@ -100,6 +106,8 @@ const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs = { .eap_peer_blob_deinit = (esp_eap_peer_blob_deinit_t)eap_peer_blob_deinit, .eap_peer_config_init = (esp_eap_peer_config_init_t)eap_peer_config_init, .eap_peer_config_deinit = (esp_eap_peer_config_deinit_t)eap_peer_config_deinit, + .eap_peer_register_methods = (esp_eap_peer_register_methods_t)eap_peer_register_methods, + .eap_peer_unregister_methods = (esp_eap_peer_unregister_methods_t)eap_peer_unregister_methods, .eap_deinit_prev_method = (esp_eap_deinit_prev_method_t)eap_deinit_prev_method, .eap_peer_get_eap_method = (esp_eap_peer_get_eap_method_t)eap_peer_get_eap_method, .eap_sm_abort = (esp_eap_sm_abort_t)eap_sm_abort, diff --git a/components/esp32/include/esp_wifi_crypto_types.h b/components/esp32/include/esp_wifi_crypto_types.h index 2e605d870c..0848f06ac9 100644 --- a/components/esp32/include/esp_wifi_crypto_types.h +++ b/components/esp32/include/esp_wifi_crypto_types.h @@ -27,6 +27,8 @@ extern "C" { #endif +#define ESP_WIFI_CRYPTO_VERSION 0x00000001 + /* * Enumeration for hash operations. * When WPA2 is connecting, this enum is used to @@ -697,6 +699,8 @@ typedef int (*esp_wps_is_selected_pbc_registrar_t)(const void *msg, unsigned cha * hardware. */ typedef struct { + uint32_t size; + uint32_t version; esp_aes_wrap_t aes_wrap; /**< station connect function used when send EAPOL frame */ esp_aes_unwrap_t aes_unwrap; /**< station connect function used when decrypt key data */ esp_hmac_sha256_vector_t hmac_sha256_vector; /**< station connect function used when check MIC */ @@ -724,6 +728,8 @@ typedef struct { * hardware. */ typedef struct{ + uint32_t size; + uint32_t version; esp_aes_128_encrypt_t aes_128_encrypt; /**< function used to process message when do WPS */ esp_aes_128_decrypt_t aes_128_decrypt; /**< function used to process message when do WPS */ esp_crypto_mod_exp_t crypto_mod_exp; /**< function used to calculate public key and private key */ @@ -750,6 +756,8 @@ typedef struct{ * hardware. */ typedef struct { + uint32_t size; + uint32_t version; esp_crypto_hash_init_t crypto_hash_init; /**< function used to initialize a crypto_hash structure when use TLSV1 */ esp_crypto_hash_update_t crypto_hash_update; /**< function used to calculate hash data when use TLSV1 */ esp_crypto_hash_finish_t crypto_hash_finish; /**< function used to finish the hash calculate when use TLSV1 */ @@ -765,6 +773,8 @@ typedef struct { esp_eap_peer_blob_deinit_t eap_peer_blob_deinit; esp_eap_peer_config_init_t eap_peer_config_init; esp_eap_peer_config_deinit_t eap_peer_config_deinit; + esp_eap_peer_register_methods_t eap_peer_register_methods; + esp_eap_peer_unregister_methods_t eap_peer_unregister_methods; esp_eap_deinit_prev_method_t eap_deinit_prev_method; esp_eap_peer_get_eap_method_t eap_peer_get_eap_method; esp_eap_sm_abort_t eap_sm_abort; diff --git a/components/esp32/include/esp_wifi_internal.h b/components/esp32/include/esp_wifi_internal.h index 875e5ac04a..7ddfd69446 100644 --- a/components/esp32/include/esp_wifi_internal.h +++ b/components/esp32/include/esp_wifi_internal.h @@ -138,6 +138,17 @@ esp_err_t esp_wifi_internal_set_sta_ip(void); */ esp_err_t esp_wifi_internal_osi_funcs_md5_check(const char *md5); +/** + * @brief Check the MD5 values of the crypto types header files in IDF and WiFi library + * + * @attention 1. It is used for internal CI version check + * + * @return + * - ESP_OK : succeed + * - ESP_WIFI_INVALID_ARG : MD5 check fail + */ +esp_err_t esp_wifi_internal_crypto_funcs_md5_check(const char *md5); + /** * @brief Allocate a chunk of memory for WiFi driver * diff --git a/components/esp32/lib b/components/esp32/lib index 13a07ae99e..37f7289daf 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 13a07ae99e83c2781c1bfd322e131226c688a4e9 +Subproject commit 37f7289daf5aacbd4c789f9e01f451f5e3f45f76 diff --git a/components/esp32/phy_init.c b/components/esp32/phy_init.c index 314f142683..d730e01c6b 100644 --- a/components/esp32/phy_init.c +++ b/components/esp32/phy_init.c @@ -133,6 +133,8 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibrat extern esp_err_t wifi_osi_funcs_register(wifi_osi_funcs_t *osi_funcs); status = wifi_osi_funcs_register(&g_wifi_osi_funcs); if(status != ESP_OK) { + ESP_LOGE(TAG, "failed to register wifi os adapter, ret(%d)", status); + _lock_release(&s_phy_rf_init_lock); return ESP_FAIL; } coex_bt_high_prio(); diff --git a/components/esp32/test/component.mk b/components/esp32/test/component.mk index 178dd4cf4d..592b9b9048 100644 --- a/components/esp32/test/component.mk +++ b/components/esp32/test/component.mk @@ -12,6 +12,11 @@ COMPONENT_SRCDIRS := . test_vectors WIFI_OS_ADAPTER_MD5_VAL=\"$(shell md5sum $(IDF_PATH)/components/esp32/include/esp_wifi_os_adapter.h | cut -c 1-7)\" CFLAGS+=-DWIFI_OS_ADAPTER_MD5=$(WIFI_OS_ADAPTER_MD5_VAL) +# Calculate MD5 value of header file esp_wifi_crypto_types.h +WIFI_CRYPTO_MD5_VAL=\"$(shell md5sum $(IDF_PATH)/components/esp32/include/esp_wifi_crypto_types.h | cut -c 1-7)\" +CFLAGS+=-DWIFI_CRYPTO_MD5=$(WIFI_CRYPTO_MD5_VAL) + + test_tjpgd.o: test_tjpgd_logo.h test_tjpgd_logo.h: $(COMPONENT_PATH)/logo.jpg diff --git a/components/esp32/test/test_os_adapter_md5.c b/components/esp32/test/test_header_files_md5.c similarity index 52% rename from components/esp32/test/test_os_adapter_md5.c rename to components/esp32/test/test_header_files_md5.c index 315a386081..009de0ea59 100644 --- a/components/esp32/test/test_os_adapter_md5.c +++ b/components/esp32/test/test_header_files_md5.c @@ -5,7 +5,7 @@ #include "esp_log.h" #include "esp_wifi_internal.h" -static const char* TAG = "test_os_adapter_md5"; +static const char* TAG = "test_header_files_md5"; TEST_CASE("wifi os adapter MD5","[wifi]") { @@ -16,3 +16,13 @@ TEST_CASE("wifi os adapter MD5","[wifi]") ESP_LOGI(TAG, "test passed..."); } + +TEST_CASE("wifi crypto types MD5","[wifi]") +{ + const char *test_wifi_crypto_funcs_md5 = WIFI_CRYPTO_MD5; + + ESP_LOGI(TAG, "test wifi crypto adapter MD5..."); + TEST_ESP_OK(esp_wifi_internal_crypto_funcs_md5_check(test_wifi_crypto_funcs_md5)); + + ESP_LOGI(TAG, "test passed..."); +} diff --git a/components/wpa_supplicant/include/wpa2/eap_peer/eap_methods.h b/components/wpa_supplicant/include/wpa2/eap_peer/eap_methods.h index 253b2d8a17..7d518dec2c 100644 --- a/components/wpa_supplicant/include/wpa2/eap_peer/eap_methods.h +++ b/components/wpa_supplicant/include/wpa2/eap_peer/eap_methods.h @@ -33,4 +33,7 @@ int eap_peer_peap_register(void); int eap_peer_ttls_register(void); int eap_peer_mschapv2_register(void); +void eap_peer_unregister_methods(void); +int eap_peer_register_methods(void); + #endif /* EAP_METHODS_H */ -- 2.40.0