From 1a6b1b1953b20a0ddd8b5f76d6dc366399ea1aee Mon Sep 17 00:00:00 2001 From: BennyE Date: Thu, 24 Dec 2020 00:37:37 +0100 Subject: [PATCH] implementing suggested changes --- ports/esp32s2/common-hal/wifi/Network.c | 5 +++-- ports/esp32s2/common-hal/wifi/Radio.c | 17 +++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index d134db057e..be4935dba5 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -51,7 +51,8 @@ mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self) { mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { const char* cstr = (const char*) self->record.country.cc; - // We know that we only want the CC thus limiting to two chars + // To address esp_wifi_get_country() returned/set wifi_country_t structure + // doesn't follow the documented behaviour (IDFGH-4486) #6315 + // 2 instead of strlen(cstr) which would be 6 and contain full element return mp_obj_new_str(cstr, 2); } - diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index d4db5d08d3..c498501c7f 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -42,10 +42,6 @@ #define MAC_ADDRESS_LENGTH 6 -#include "components/log/include/esp_log.h" - -static const char* TAG = "wifi"; - static void start_station(wifi_radio_obj_t *self) { if (self->sta_mode) { return; @@ -198,18 +194,15 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) { if (esp_wifi_sta_get_ap_info(&self->ap_info.record) != ESP_OK){ return mp_const_none; } else { - // The struct member appears to be (not NULL!), I don't know how to properly test for it. - // When the ESP-IDF starts working fine (when their bugfix is available), this "if" wouldn't trigger. - // Note: It is possible that Wi-Fi APs don't have a CC set, then even after this workaround - // the element would remain empty. if (strlen(self->ap_info.record.country.cc) == 0) { // Workaround to fill country related information in ap_info until ESP-IDF carries a fix // esp_wifi_sta_get_ap_info does not appear to fill wifi_country_t (e.g. country.cc) details // (IDFGH-4437) #6267 - if (esp_wifi_get_country(&self->ap_info.record.country) == ESP_OK) { - ESP_EARLY_LOGW(TAG, "Country Code: %s", self->ap_info.record.country.cc); - } else { - ESP_EARLY_LOGW(TAG, "Country Code - Workaround failed!"); + // Note: It is possible that Wi-Fi APs don't have a CC set, then even after this workaround + // the element would remain empty. + memset(&self->ap_info.record.country, 0, sizeof(wifi_country_t)); + if (esp_wifi_get_country(&self->ap_info.record.country) != ESP_OK) { + return mp_const_none; } } memcpy(&ap_info->record, &self->ap_info.record, sizeof(wifi_ap_record_t));