Skip to content

Commit

Permalink
[ESP32] Set the country code in esp_phy layer (#27365)
Browse files Browse the repository at this point in the history
* [ESP32] Set the country code in esp_phy layer

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 18, 2023
1 parent 0f86c37 commit 3263715
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#include "esp_ota_ops.h"
#include "esp_phy_init.h"
#include "esp_wifi.h"
#include "nvs.h"
#include "nvs_flash.h"
Expand Down Expand Up @@ -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<ESP32Config>::StoreCountryCode(code, codeLen);
}

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
Expand Down
4 changes: 4 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 3263715

Please sign in to comment.