From e77a7a1dfbd917cf73c68ef501534ef40af0b740 Mon Sep 17 00:00:00 2001 From: Jerry-ESP <107675966+Jerry-ESP@users.noreply.github.com> Date: Mon, 21 Nov 2022 07:09:48 +0800 Subject: [PATCH] Update the RegulatoryLocation and LocationCapability get and set logic (#23579) * ESP32: add RegulatoryLocation and LocationCapability value init * Restyled by clang-format Co-authored-by: Restyled.io --- config/esp32/components/chip/Kconfig | 13 ++++++++++--- .../GenericConfigurationManagerImpl.ipp | 17 ++++++++++++++++- .../ESP32/ConfigurationManagerImpl.cpp | 19 +++++++++++++++++++ src/platform/ESP32/ConfigurationManagerImpl.h | 1 + src/platform/ESP32/ESP32Config.cpp | 1 + src/platform/ESP32/ESP32Config.h | 1 + 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 57ace57f55bf1f..4f406f762f83eb 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -253,7 +253,7 @@ menu "CHIP Device Layer" help The size (in bytes) of the service directory cache. This limits the maximum size of the directory that can be returned in response to a service directory query. - + config ENABLE_EXTENDED_DISCOVERY bool "Enable Extended discovery Support" default n @@ -500,7 +500,7 @@ menu "CHIP Device Layer" config USE_BLE_ONLY_FOR_COMMISSIONING bool "Use BLE only for commissioning" default y - help + help Disable this flag if BLE is used for any other purpose than commissioning. When enabled, it deinitialized the BLE on successful commissioning, and on bootup do not initialize the BLE if device is already provisioned with Wi-Fi/Thread credentials. @@ -695,6 +695,13 @@ menu "CHIP Device Layer" Details like Supported calendar types, supported locales, and fixed labels will be read from factory partition. + config ENABLE_ESP32_LOCATIONCAPABILITY + depends on ENABLE_ESP32_FACTORY_DATA_PROVIDER + bool "Enable ESP32 Device LocationCapability " + default n + help + Enable ESP32 Device LocationCapability + endmenu @@ -890,7 +897,7 @@ menu "CHIP Device Layer" default "nvs" help Label of the partition to store key-values in the "chip-counters" namespace. - + config CHIP_KVS_NAMESPACE_PARTITION_LABEL string "chip-kvs namespace partition label" default "nvs" diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index 72f41dca2ae170..f6c9e504281896 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -415,7 +415,22 @@ void GenericConfigurationManagerImpl::NotifyOfAdvertisementStart() template CHIP_ERROR GenericConfigurationManagerImpl::GetRegulatoryLocation(uint8_t & location) { - return GetLocationCapability(location); + uint32_t value; + if (CHIP_NO_ERROR != ReadConfigValue(ConfigClass::kConfigKey_RegulatoryLocation, value)) + { + ReturnErrorOnFailure(GetLocationCapability(location)); + + if (CHIP_NO_ERROR != StoreRegulatoryLocation(location)) + { + ChipLogError(DeviceLayer, "Failed to store RegulatoryLocation"); + } + } + else + { + location = static_cast(value); + } + + return CHIP_NO_ERROR; } template diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 4fd82a072d9a68..c306fc05dc4139 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -221,6 +221,25 @@ CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer) return CHIP_NO_ERROR; } +CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location) +{ +#if CONFIG_ENABLE_ESP32_LOCATIONCAPABILITY + uint32_t value = 0; + CHIP_ERROR err = ReadConfigValue(ESP32Config::kConfigKey_LocationCapability, value); + + if (err == CHIP_NO_ERROR) + { + VerifyOrReturnError(value <= UINT8_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); + location = static_cast(value); + } + + return err; +#else + location = static_cast(chip::app::Clusters::GeneralCommissioning::RegulatoryLocationType::kIndoor); + return CHIP_NO_ERROR; +#endif +} + 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 32f4951473349e..64438612fd0a3e 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -57,6 +57,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override; CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize); CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override; + CHIP_ERROR GetLocationCapability(uint8_t & location) override; static ConfigurationManagerImpl & GetDefaultInstance(); private: diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index 361cd7b9c370c2..6007cb9282e148 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -77,6 +77,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductURL = { kConfig const ESP32Config::Key ESP32Config::kConfigKey_SupportedCalTypes = { kConfigNamespace_ChipFactory, "cal-types" }; const ESP32Config::Key ESP32Config::kConfigKey_SupportedLocaleSize = { kConfigNamespace_ChipFactory, "locale-sz" }; const ESP32Config::Key ESP32Config::kConfigKey_RotatingDevIdUniqueId = { kConfigNamespace_ChipFactory, "rd-id-uid" }; +const ESP32Config::Key ESP32Config::kConfigKey_LocationCapability = { kConfigNamespace_ChipFactory, "loc-capability" }; // Keys stored in the chip-config namespace const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" }; diff --git a/src/platform/ESP32/ESP32Config.h b/src/platform/ESP32/ESP32Config.h index f884af85c3da46..6a008dbb795cf7 100644 --- a/src/platform/ESP32/ESP32Config.h +++ b/src/platform/ESP32/ESP32Config.h @@ -79,6 +79,7 @@ class ESP32Config static const Key kConfigKey_SupportedCalTypes; static const Key kConfigKey_SupportedLocaleSize; static const Key kConfigKey_RotatingDevIdUniqueId; + static const Key kConfigKey_LocationCapability; // CHIP Config keys static const Key kConfigKey_ServiceConfig;