From 864897099458ba7da27b4af828cffe7871eeac4b Mon Sep 17 00:00:00 2001 From: chenwen Date: Tue, 25 May 2021 20:17:57 +0800 Subject: [PATCH] esp32&esp32c3/wifi: Fix the issues of Wi-Fi configuration being overwritten --- arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c | 5 ++++- arch/xtensa/src/esp32/esp32_wifi_adapter.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c index d15a271371..9c44b81df3 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c @@ -5202,6 +5202,7 @@ int esp_wifi_sta_password(struct iwreq *iwr, bool set) return -EINVAL; } + memset(wifi_cfg.sta.password, 0x0, PWD_MAX_LEN); memcpy(wifi_cfg.sta.password, pdata, len); wifi_cfg.sta.pmf_cfg.capable = true; @@ -5328,6 +5329,7 @@ int esp_wifi_sta_essid(struct iwreq *iwr, bool set) if (set) { + memset(wifi_cfg.sta.ssid, 0x0, SSID_MAX_LEN); memcpy(wifi_cfg.sta.ssid, pdata, len); ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg); @@ -6284,8 +6286,8 @@ int esp_wifi_softap_password(struct iwreq *iwr, bool set) if (set) { wifi_cfg.ap.max_connection = ESP_MAX_STA_CONN; + memset(wifi_cfg.ap.password, 0x0, PWD_MAX_LEN); memcpy(wifi_cfg.ap.password, pdata, len); - wifi_cfg.ap.password[len] = '\0'; if (len) { wifi_cfg.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK; @@ -6369,6 +6371,7 @@ int esp_wifi_softap_essid(struct iwreq *iwr, bool set) if (set) { + memset(wifi_cfg.ap.ssid, 0x0, SSID_MAX_LEN); memcpy(wifi_cfg.ap.ssid, pdata, len); ret = esp_wifi_set_config(WIFI_IF_AP, &wifi_cfg); diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index 3e50fc711a..fe79707996 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -5231,6 +5231,7 @@ int esp_wifi_sta_password(struct iwreq *iwr, bool set) if (set) { + memset(wifi_cfg.sta.password, 0x0, PWD_MAX_LEN); memcpy(wifi_cfg.sta.password, pdata, len); wifi_cfg.sta.pmf_cfg.capable = true; @@ -5355,6 +5356,7 @@ int esp_wifi_sta_essid(struct iwreq *iwr, bool set) if (set) { + memset(wifi_cfg.sta.ssid, 0x0, SSID_MAX_LEN); memcpy(wifi_cfg.sta.ssid, pdata, len); ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg); @@ -6302,6 +6304,7 @@ int esp_wifi_softap_password(struct iwreq *iwr, bool set) if (set) { + memset(wifi_cfg.ap.password, 0x0, PWD_MAX_LEN); memcpy(wifi_cfg.ap.password, pdata, len); ret = esp_wifi_set_config(WIFI_IF_AP, &wifi_cfg); @@ -6381,6 +6384,7 @@ int esp_wifi_softap_essid(struct iwreq *iwr, bool set) if (set) { + memset(wifi_cfg.ap.ssid, 0x0, SSID_MAX_LEN); memcpy(wifi_cfg.ap.ssid, pdata, len); ret = esp_wifi_set_config(WIFI_IF_AP, &wifi_cfg);