From 32637156f734021d7406ceba0484709c35a72d3d Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Wed, 21 Jun 2023 19:56:17 +0530 Subject: [PATCH] [ESP32] Set the country code in esp_phy layer (#27365) * [ESP32] Set the country code in esp_phy layer * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/platform/ESP32/ConfigurationManagerImpl.cpp | 12 ++++++++++++ src/platform/ESP32/ConfigurationManagerImpl.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 889ccb8abdb776..8b4cb05e55e735 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -32,6 +32,7 @@ #include #include "esp_ota_ops.h" +#include "esp_phy_init.h" #include "esp_wifi.h" #include "nvs.h" #include "nvs_flash.h" @@ -236,6 +237,17 @@ CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location) #endif } +CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t codeLen) +{ + // As per spec, codeLen has to be 2 + VerifyOrReturnError((code != nullptr) && (codeLen == 2), CHIP_ERROR_INVALID_ARGUMENT); + // Write CountryCode to esp_phy layer + ReturnErrorOnFailure(MapConfigError(esp_phy_update_country_info(code))); + // As we do not have API to read country code from esp_phy layer, we are writing to NVS and when client reads the + // CountryCode then we read from NVS + return GenericConfigurationManagerImpl::StoreCountryCode(code, codeLen); +} + CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 7d86ebc8e51ca4..fce74d9307b823 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -58,6 +58,10 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR GetLocationCapability(uint8_t & location) override; static ConfigurationManagerImpl & GetDefaultInstance(); + // Set the country code to esp_phy layer and also store it to NVS + // GenericConfigurationManagerImpl::GetCountryCode() API already reads from the NVS so its not implemented here + CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) override; + private: // ===== Members that implement the ConfigurationManager public interface.