diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index 0f8edcf5760eab..9b70101f512640 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -24,28 +24,35 @@ #include #include #include +#include +#include using namespace chip; bool emberAfGeneralCommissioningClusterArmFailSafeCallback(chip::app::Command * commandObj, uint16_t expiryLengthSeconds, uint64_t breadcrumb, uint32_t timeoutMs) { - EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE; - emberAfSendImmediateDefaultResponse(status); + CHIP_ERROR err = DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().ArmFailSafe(expiryLengthSeconds); + emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE); + return true; } bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(chip::app::Command * commandObj) { - EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE; - emberAfSendImmediateDefaultResponse(status); + CHIP_ERROR err = DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().CommissioningComplete(); + emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE); + return true; } bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(chip::app::Command * commandObj, uint8_t location, uint8_t * countryCode, uint64_t breadcrumb, uint32_t timeoutMs) { - EmberAfStatus status = EMBER_ZCL_STATUS_FAILURE; - emberAfSendImmediateDefaultResponse(status); + CHIP_ERROR err = DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().SetRegulatoryConfig( + location, reinterpret_cast(countryCode), breadcrumb); + + emberAfSendImmediateDefaultResponse(err == CHIP_NO_ERROR ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE); + return true; } diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index b72529e605ffd6..3aceb5c8f2d3b0 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -93,6 +93,9 @@ class ConfigurationManager // Lifetime counter is monotonic counter that is incremented only in the case of a factory reset CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter); #endif + CHIP_ERROR GetRegulatoryLocation(uint32_t & location); + CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen); + CHIP_ERROR GetBreadcrumb(uint64_t & breadcrumb); CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen); CHIP_ERROR StorePrimaryWiFiMACAddress(const uint8_t * buf); CHIP_ERROR StorePrimary802154MACAddress(const uint8_t * buf); @@ -116,6 +119,9 @@ class ConfigurationManager CHIP_ERROR ClearServiceProvisioningData(); CHIP_ERROR StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen); CHIP_ERROR StorePairedAccountId(const char * accountId, size_t accountIdLen); + CHIP_ERROR StoreRegulatoryLocation(uint32_t location); + CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen); + CHIP_ERROR StoreBreadcrumb(uint64_t breadcrumb); CHIP_ERROR GetQRCodeString(char * buf, size_t bufSize); @@ -371,6 +377,21 @@ inline CHIP_ERROR ConfigurationManager::GetLifetimeCounter(uint16_t & lifetimeCo } #endif +inline CHIP_ERROR ConfigurationManager::GetRegulatoryLocation(uint32_t & location) +{ + return static_cast(this)->_GetRegulatoryLocation(location); +} + +inline CHIP_ERROR ConfigurationManager::GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) +{ + return static_cast(this)->_GetCountryCode(buf, bufSize, codeLen); +} + +inline CHIP_ERROR ConfigurationManager::GetBreadcrumb(uint64_t & breadcrumb) +{ + return static_cast(this)->_GetBreadcrumb(breadcrumb); +} + inline CHIP_ERROR ConfigurationManager::StoreSerialNumber(const char * serialNum, size_t serialNumLen) { return static_cast(this)->_StoreSerialNumber(serialNum, serialNumLen); @@ -463,6 +484,21 @@ inline CHIP_ERROR ConfigurationManager::StoreServiceProvisioningData(uint64_t se accountIdLen); } +inline CHIP_ERROR ConfigurationManager::StoreRegulatoryLocation(uint32_t location) +{ + return static_cast(this)->_StoreRegulatoryLocation(location); +} + +inline CHIP_ERROR ConfigurationManager::StoreCountryCode(const char * code, size_t codeLen) +{ + return static_cast(this)->_StoreCountryCode(code, codeLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreBreadcrumb(uint64_t breadcrumb) +{ + return static_cast(this)->_StoreBreadcrumb(breadcrumb); +} + inline CHIP_ERROR ConfigurationManager::ClearServiceProvisioningData() { return static_cast(this)->_ClearServiceProvisioningData(); diff --git a/src/include/platform/internal/DeviceControlServer.h b/src/include/platform/internal/DeviceControlServer.h new file mode 100644 index 00000000000000..6e62eb345275eb --- /dev/null +++ b/src/include/platform/internal/DeviceControlServer.h @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the Device Layer DeviceControlServer object. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +class DeviceControlServer final +{ +public: + // ===== Members for internal use by other Device Layer components. + + CHIP_ERROR ArmFailSafe(uint16_t expiryLengthSeconds); + CHIP_ERROR DisarmFailSafe(); + CHIP_ERROR CommissioningComplete(); + CHIP_ERROR SetRegulatoryConfig(uint8_t location, const char * countryCode, uint64_t breadcrumb); + + static DeviceControlServer & DeviceControlSvr(); + +private: + // ===== Members for internal use by the following friends. + static DeviceControlServer sInstance; + + // ===== Private members reserved for use by this class only. + + DeviceControlServer() = default; + ~DeviceControlServer() = default; + + // No copy, move or assignment. + DeviceControlServer(const DeviceControlServer &) = delete; + DeviceControlServer(const DeviceControlServer &&) = delete; + DeviceControlServer & operator=(const DeviceControlServer &) = delete; +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/include/platform/internal/DeviceDescriptionServer.h b/src/include/platform/internal/DeviceDescriptionServer.h deleted file mode 100644 index aa2ea8b023940d..00000000000000 --- a/src/include/platform/internal/DeviceDescriptionServer.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Defines the Device Layer DeviceDescriptionServer object. - */ - -#pragma once - -#include -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -/** - * Implements the chip Device Description profile for a chip device. - */ -class DeviceDescriptionServer final : public ::chip::Profiles::DeviceDescription::DeviceDescriptionServer -{ - typedef ::chip::Profiles::DeviceDescription::DeviceDescriptionServer ServerBaseClass; - -public: - // ===== Members for internal use by other Device Layer components. - - CHIP_ERROR Init(); - - bool IsUserSelectedModeActive(void); - void SetUserSelectedMode(bool val); - uint16_t GetUserSelectedModeTimeout(void); - void SetUserSelectedModeTimeout(uint16_t val); - - void OnPlatformEvent(const ChipDeviceEvent * event); - -private: - // ===== Members for internal use by the following friends. - - friend DeviceDescriptionServer & DeviceDescriptionSvr(void); - - static DeviceDescriptionServer sInstance; - - // ===== Private members reserved for use by this class only. - - enum - { - kUserSelectedModeTimeShift = 10 - }; - - uint32_t mUserSelectedModeEndTime; // Monotonic system time scaled to units of 1024ms. - uint16_t mUserSelectedModeTimeoutSec; - - static void HandleIdentifyRequest(void * appState, uint64_t nodeId, const IPAddress & nodeAddr, - const ::chip::Profiles::DeviceDescription::IdentifyRequestMessage & reqMsg, bool & sendResp, - ::chip::Profiles::DeviceDescription::IdentifyResponseMessage & respMsg); - -protected: - // Construction/destruction limited to subclasses. - DeviceDescriptionServer() = default; - ~DeviceDescriptionServer() = default; - - // No copy, move or assignment. - DeviceDescriptionServer(const DeviceDescriptionServer &) = delete; - DeviceDescriptionServer(const DeviceDescriptionServer &&) = delete; - DeviceDescriptionServer & operator=(const DeviceDescriptionServer &) = delete; -}; - -/** - * Returns a reference to the DeviceDescriptionServer singleton object. - */ -inline DeviceDescriptionServer & DeviceDescriptionSvr(void) -{ - return DeviceDescriptionServer::sInstance; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp index 9da803cf92fdf5..7d862abe76f800 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp @@ -657,6 +657,42 @@ CHIP_ERROR GenericConfigurationManagerImpl::_StoreFabricId(uint64_t f return err; } +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetRegulatoryLocation(uint32_t & location) +{ + return Impl()->ReadConfigValue(ImplClass::kConfigKey_RegulatoryLocation, location); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::_StoreRegulatoryLocation(uint32_t location) +{ + return Impl()->WriteConfigValue(ImplClass::kConfigKey_RegulatoryLocation, location); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) +{ + return Impl()->ReadConfigValueStr(ImplClass::kConfigKey_CountryCode, buf, bufSize, codeLen); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::_StoreCountryCode(const char * code, size_t codeLen) +{ + return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_CountryCode, code, codeLen); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::_GetBreadcrumb(uint64_t & breadcrumb) +{ + return Impl()->ReadConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::_StoreBreadcrumb(uint64_t breadcrumb) +{ + return Impl()->WriteConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb); +} + template CHIP_ERROR GenericConfigurationManagerImpl::_GetServiceId(uint64_t & serviceId) { diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index d2345e0ee052b4..a2a5c99228e4f4 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -116,6 +116,12 @@ class GenericConfigurationManagerImpl CHIP_ERROR _GetQRCodeString(char * buf, size_t bufSize); CHIP_ERROR _GetWiFiAPSSID(char * buf, size_t bufSize); CHIP_ERROR _GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo); + CHIP_ERROR _GetRegulatoryLocation(uint32_t & location); + CHIP_ERROR _StoreRegulatoryLocation(uint32_t location); + CHIP_ERROR _GetCountryCode(char * buf, size_t bufSize, size_t & codeLen); + CHIP_ERROR _StoreCountryCode(const char * code, size_t codeLen); + CHIP_ERROR _GetBreadcrumb(uint64_t & breadcrumb); + CHIP_ERROR _StoreBreadcrumb(uint64_t breadcrumb); CHIP_ERROR _ConfigureChipStack(); #if !defined(NDEBUG) CHIP_ERROR _RunUnitTests(void); diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 26c5adfac43584..e7dbc96a442072 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -204,7 +204,7 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { "../include/platform/TimeSyncManager.h", "../include/platform/internal/BLEManager.h", "../include/platform/internal/CHIPDeviceLayerInternal.h", - "../include/platform/internal/DeviceDescriptionServer.h", + "../include/platform/internal/DeviceControlServer.h", "../include/platform/internal/DeviceNetworkInfo.h", "../include/platform/internal/DeviceNetworkProvisioning.h", "../include/platform/internal/EventLogging.h", @@ -222,6 +222,7 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { "../include/platform/internal/GenericSoftwareUpdateManagerImpl.h", "../include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h", "../include/platform/internal/testing/ConfigUnitTest.h", + "DeviceControlServer.cpp", "GeneralUtils.cpp", "Globals.cpp", "PersistedStorage.cpp", diff --git a/src/platform/Darwin/PosixConfig.cpp b/src/platform/Darwin/PosixConfig.cpp index 4c08ba95323b90..e5becd390a0453 100644 --- a/src/platform/Darwin/PosixConfig.cpp +++ b/src/platform/Darwin/PosixConfig.cpp @@ -67,6 +67,9 @@ const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceId = { k const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceCert = { kConfigNamespace_ChipConfig, "op-device-cert" }; const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_ChipConfig, "op-device-ca-certs" }; const PosixConfig::Key PosixConfig::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" }; +const PosixConfig::Key PosixConfig::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "regulatory-location" }; +const PosixConfig::Key PosixConfig::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" }; +const PosixConfig::Key PosixConfig::kConfigKey_Breadcrumb = { kConfigNamespace_ChipConfig, "breadcrumb" }; // Prefix used for NVS keys that contain Chip group encryption keys. const char PosixConfig::kGroupKeyNamePrefix[] = "gk-"; diff --git a/src/platform/Darwin/PosixConfig.h b/src/platform/Darwin/PosixConfig.h index e1af67c2222abe..6a77b69351adf5 100644 --- a/src/platform/Darwin/PosixConfig.h +++ b/src/platform/Darwin/PosixConfig.h @@ -74,6 +74,9 @@ class PosixConfig static const Key kConfigKey_OperationalDeviceICACerts; static const Key kConfigKey_OperationalDevicePrivateKey; static const Key kConfigKey_SetupDiscriminator; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_Breadcrumb; static const char kGroupKeyNamePrefix[]; diff --git a/src/platform/DeviceControlServer.cpp b/src/platform/DeviceControlServer.cpp new file mode 100644 index 00000000000000..8a26d9d754e47c --- /dev/null +++ b/src/platform/DeviceControlServer.cpp @@ -0,0 +1,80 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Provides the implementation of the DeviceControlServer object. + */ + +#include + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +DeviceControlServer DeviceControlServer::sInstance; + +DeviceControlServer & DeviceControlServer::DeviceControlSvr() +{ + return sInstance; +} + +CHIP_ERROR DeviceControlServer::ArmFailSafe(uint16_t expiryLengthSeconds) +{ + // TODO + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR DeviceControlServer::DisarmFailSafe() +{ + // TODO + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR DeviceControlServer::CommissioningComplete() +{ + // TODO + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR DeviceControlServer::SetRegulatoryConfig(uint8_t location, const char * countryCode, uint64_t breadcrumb) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = ConfigurationMgr().StoreRegulatoryLocation(location); + SuccessOrExit(err); + + err = ConfigurationMgr().StoreCountryCode(countryCode, strlen(countryCode)); + SuccessOrExit(err); + + err = ConfigurationMgr().StoreBreadcrumb(breadcrumb); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "SetRegulatoryConfig failed with error: %s", ErrorStr(err)); + } + + return err; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/EFR32/EFR32Config.h b/src/platform/EFR32/EFR32Config.h index 1fb39300edde0a..d813e8a2d1ec8f 100644 --- a/src/platform/EFR32/EFR32Config.h +++ b/src/platform/EFR32/EFR32Config.h @@ -95,15 +95,18 @@ class EFR32Config static constexpr Key kConfigKey_OperationalDeviceCert = EFR32ConfigKey(kChipConfig_KeyBase, 0x0A); static constexpr Key kConfigKey_OperationalDeviceICACerts = EFR32ConfigKey(kChipConfig_KeyBase, 0x0B); static constexpr Key kConfigKey_OperationalDevicePrivateKey = EFR32ConfigKey(kChipConfig_KeyBase, 0x0C); + static constexpr Key kConfigKey_RegulatoryLocation = EFR32ConfigKey(kChipConfig_KeyBase, 0x0D); + static constexpr Key kConfigKey_CountryCode = EFR32ConfigKey(kChipConfig_KeyBase, 0x0E); + static constexpr Key kConfigKey_Breadcrumb = EFR32ConfigKey(kChipConfig_KeyBase, 0x0F); - static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kChipConfig_KeyBase, 0x0D); - static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); // Allows 16 Group Keys to be created. + static constexpr Key kConfigKey_GroupKeyBase = EFR32ConfigKey(kChipConfig_KeyBase, 0x10); + static constexpr Key kConfigKey_GroupKeyMax = EFR32ConfigKey(kChipConfig_KeyBase, 0x1F); // Allows 16 Group Keys to be created. // Set key id limits for each group. static constexpr Key kMinConfigKey_ChipFactory = EFR32ConfigKey(kChipFactory_KeyBase, 0x00); static constexpr Key kMaxConfigKey_ChipFactory = EFR32ConfigKey(kChipFactory_KeyBase, 0x07); static constexpr Key kMinConfigKey_ChipConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x00); - static constexpr Key kMaxConfigKey_ChipConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x1C); + static constexpr Key kMaxConfigKey_ChipConfig = EFR32ConfigKey(kChipConfig_KeyBase, 0x1F); static constexpr Key kMinConfigKey_ChipCounter = EFR32ConfigKey(kChipCounter_KeyBase, 0x00); static constexpr Key kMaxConfigKey_ChipCounter = EFR32ConfigKey(kChipCounter_KeyBase, 0x1F); // Allows 32 Counters to be created. diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index 1063d56fd9edce..20019b6d2b2c66 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -72,6 +72,9 @@ const ESP32Config::Key ESP32Config::kConfigKey_OperationalDeviceId = { k const ESP32Config::Key ESP32Config::kConfigKey_OperationalDeviceCert = { kConfigNamespace_ChipConfig, "op-device-cert" }; const ESP32Config::Key ESP32Config::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_ChipConfig, "op-device-ca-certs" }; const ESP32Config::Key ESP32Config::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" }; +const ESP32Config::Key ESP32Config::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "regulatory-location" }; +const ESP32Config::Key ESP32Config::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" }; +const ESP32Config::Key ESP32Config::kConfigKey_Breadcrumb = { kConfigNamespace_ChipConfig, "breadcrumb" }; // Prefix used for NVS keys that contain Chip group encryption keys. const char ESP32Config::kGroupKeyNamePrefix[] = "gk-"; diff --git a/src/platform/ESP32/ESP32Config.h b/src/platform/ESP32/ESP32Config.h index 46fdb877376a4a..39bd6b97534983 100644 --- a/src/platform/ESP32/ESP32Config.h +++ b/src/platform/ESP32/ESP32Config.h @@ -75,6 +75,9 @@ class ESP32Config static const Key kConfigKey_OperationalDeviceICACerts; static const Key kConfigKey_OperationalDevicePrivateKey; static const Key kConfigKey_SetupDiscriminator; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_Breadcrumb; static const char kGroupKeyNamePrefix[]; diff --git a/src/platform/K32W/K32WConfig.h b/src/platform/K32W/K32WConfig.h index b93f987c2ade64..72338d9db3076d 100644 --- a/src/platform/K32W/K32WConfig.h +++ b/src/platform/K32W/K32WConfig.h @@ -88,33 +88,37 @@ class K32WConfig static constexpr Key kConfigKey_OperationalDeviceICACerts = K32WConfigKey(kPDMId_ChipConfig, 0x09); static constexpr Key kConfigKey_OperationalDevicePrivateKey = K32WConfigKey(kPDMId_ChipConfig, 0x0A); - static constexpr Key kConfigKey_GroupKey = K32WConfigKey(kPDMId_ChipConfig, 0x0B); - static constexpr Key kConfigKey_GroupKey0 = K32WConfigKey(kPDMId_ChipConfig, 0x0C); - static constexpr Key kConfigKey_GroupKey1 = K32WConfigKey(kPDMId_ChipConfig, 0x0D); - static constexpr Key kConfigKey_GroupKey2 = K32WConfigKey(kPDMId_ChipConfig, 0x0E); - static constexpr Key kConfigKey_GroupKey3 = K32WConfigKey(kPDMId_ChipConfig, 0x0F); - static constexpr Key kConfigKey_GroupKey4 = K32WConfigKey(kPDMId_ChipConfig, 0x10); - static constexpr Key kConfigKey_GroupKey5 = K32WConfigKey(kPDMId_ChipConfig, 0x11); - static constexpr Key kConfigKey_GroupKey6 = K32WConfigKey(kPDMId_ChipConfig, 0x12); - static constexpr Key kConfigKey_GroupKey7 = K32WConfigKey(kPDMId_ChipConfig, 0x13); - static constexpr Key kConfigKey_GroupKey8 = K32WConfigKey(kPDMId_ChipConfig, 0x14); - static constexpr Key kConfigKey_GroupKey9 = K32WConfigKey(kPDMId_ChipConfig, 0x15); - static constexpr Key kConfigKey_GroupKey10 = K32WConfigKey(kPDMId_ChipConfig, 0x16); - static constexpr Key kConfigKey_GroupKey11 = K32WConfigKey(kPDMId_ChipConfig, 0x17); - static constexpr Key kConfigKey_GroupKey12 = K32WConfigKey(kPDMId_ChipConfig, 0x18); - static constexpr Key kConfigKey_GroupKey13 = K32WConfigKey(kPDMId_ChipConfig, 0x19); - static constexpr Key kConfigKey_GroupKey14 = K32WConfigKey(kPDMId_ChipConfig, 0x1A); - static constexpr Key kConfigKey_GroupKey15 = K32WConfigKey(kPDMId_ChipConfig, 0x1B); + static constexpr Key kConfigKey_RegulatoryLocation = K32WConfigKey(kPDMId_ChipConfig, 0x0B); + static constexpr Key kConfigKey_CountryCode = K32WConfigKey(kPDMId_ChipConfig, 0x0C); + static constexpr Key kConfigKey_Breadcrumb = K32WConfigKey(kPDMId_ChipConfig, 0x0D); + + static constexpr Key kConfigKey_GroupKey = K32WConfigKey(kPDMId_ChipConfig, 0x0E); + static constexpr Key kConfigKey_GroupKey0 = K32WConfigKey(kPDMId_ChipConfig, 0x0F); + static constexpr Key kConfigKey_GroupKey1 = K32WConfigKey(kPDMId_ChipConfig, 0x10); + static constexpr Key kConfigKey_GroupKey2 = K32WConfigKey(kPDMId_ChipConfig, 0x11); + static constexpr Key kConfigKey_GroupKey3 = K32WConfigKey(kPDMId_ChipConfig, 0x12); + static constexpr Key kConfigKey_GroupKey4 = K32WConfigKey(kPDMId_ChipConfig, 0x13); + static constexpr Key kConfigKey_GroupKey5 = K32WConfigKey(kPDMId_ChipConfig, 0x14); + static constexpr Key kConfigKey_GroupKey6 = K32WConfigKey(kPDMId_ChipConfig, 0x15); + static constexpr Key kConfigKey_GroupKey7 = K32WConfigKey(kPDMId_ChipConfig, 0x16); + static constexpr Key kConfigKey_GroupKey8 = K32WConfigKey(kPDMId_ChipConfig, 0x17); + static constexpr Key kConfigKey_GroupKey9 = K32WConfigKey(kPDMId_ChipConfig, 0x18); + static constexpr Key kConfigKey_GroupKey10 = K32WConfigKey(kPDMId_ChipConfig, 0x19); + static constexpr Key kConfigKey_GroupKey11 = K32WConfigKey(kPDMId_ChipConfig, 0x1A); + static constexpr Key kConfigKey_GroupKey12 = K32WConfigKey(kPDMId_ChipConfig, 0x1B); + static constexpr Key kConfigKey_GroupKey13 = K32WConfigKey(kPDMId_ChipConfig, 0x1C); + static constexpr Key kConfigKey_GroupKey14 = K32WConfigKey(kPDMId_ChipConfig, 0x1D); + static constexpr Key kConfigKey_GroupKey15 = K32WConfigKey(kPDMId_ChipConfig, 0x1E); static constexpr Key kConfigKey_GroupKeyBase = kConfigKey_GroupKey0; - static constexpr Key kConfigKey_GroupKeyMax = K32WConfigKey(kPDMId_ChipConfig, 0x1B); + static constexpr Key kConfigKey_GroupKeyMax = K32WConfigKey(kPDMId_ChipConfig, 0x1E); ; // Allows 16 Group Keys to be created. // Set key id limits for each group. static constexpr Key kMinConfigKey_ChipFactory = K32WConfigKey(kPDMId_ChipFactory, 0x00); static constexpr Key kMaxConfigKey_ChipFactory = K32WConfigKey(kPDMId_ChipFactory, 0x08); static constexpr Key kMinConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x00); - static constexpr Key kMaxConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x1A); + static constexpr Key kMaxConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x1E); static constexpr Key kMinConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x00); static constexpr Key kMaxConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x1F); // Allows 32 Counters to be created. diff --git a/src/platform/Linux/PosixConfig.cpp b/src/platform/Linux/PosixConfig.cpp index ebe9eb1eabd907..e5771074d39ca8 100644 --- a/src/platform/Linux/PosixConfig.cpp +++ b/src/platform/Linux/PosixConfig.cpp @@ -72,6 +72,9 @@ const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceId = { k const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceCert = { kConfigNamespace_ChipConfig, "op-device-cert" }; const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceICACerts = { kConfigNamespace_ChipConfig, "op-device-ca-certs" }; const PosixConfig::Key PosixConfig::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" }; +const PosixConfig::Key PosixConfig::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "regulatory-location" }; +const PosixConfig::Key PosixConfig::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" }; +const PosixConfig::Key PosixConfig::kConfigKey_Breadcrumb = { kConfigNamespace_ChipConfig, "breadcrumb" }; // Prefix used for NVS keys that contain Chip group encryption keys. const char PosixConfig::kGroupKeyNamePrefix[] = "gk-"; diff --git a/src/platform/Linux/PosixConfig.h b/src/platform/Linux/PosixConfig.h index bac6963d790f73..ce597ba346e0af 100644 --- a/src/platform/Linux/PosixConfig.h +++ b/src/platform/Linux/PosixConfig.h @@ -76,6 +76,9 @@ class PosixConfig static const Key kConfigKey_OperationalDeviceICACerts; static const Key kConfigKey_OperationalDevicePrivateKey; static const Key kConfigKey_SetupDiscriminator; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_Breadcrumb; static const char kGroupKeyNamePrefix[]; diff --git a/src/platform/Zephyr/ZephyrConfig.cpp b/src/platform/Zephyr/ZephyrConfig.cpp index 6ac82ba05176c3..2f8781a4357b60 100644 --- a/src/platform/Zephyr/ZephyrConfig.cpp +++ b/src/platform/Zephyr/ZephyrConfig.cpp @@ -72,7 +72,9 @@ const ZephyrConfig::Key ZephyrConfig::kConfigKey_OperationalDeviceId = C const ZephyrConfig::Key ZephyrConfig::kConfigKey_OperationalDeviceCert = CONFIG_KEY(NAMESPACE_CONFIG "op-device-cert"); const ZephyrConfig::Key ZephyrConfig::kConfigKey_OperationalDeviceICACerts = CONFIG_KEY(NAMESPACE_CONFIG "op-device-ca-certs"); const ZephyrConfig::Key ZephyrConfig::kConfigKey_OperationalDevicePrivateKey = CONFIG_KEY(NAMESPACE_CONFIG "op-device-key"); - +const ZephyrConfig::Key ZephyrConfig::kConfigKey_RegulatoryLocation = CONFIG_KEY(NAMESPACE_CONFIG "regulatory-location"); +const ZephyrConfig::Key ZephyrConfig::kConfigKey_CountryCode = CONFIG_KEY(NAMESPACE_CONFIG "country-code"); +const ZephyrConfig::Key ZephyrConfig::kConfigKey_Breadcrumb = CONFIG_KEY(NAMESPACE_CONFIG "breadcrumb"); namespace { constexpr const char * sAllResettableConfigKeys[] = { ZephyrConfig::kConfigKey_FabricId, @@ -86,7 +88,10 @@ constexpr const char * sAllResettableConfigKeys[] = { ZephyrConfig::kConfigKey_F ZephyrConfig::kConfigKey_OperationalDeviceId, ZephyrConfig::kConfigKey_OperationalDeviceCert, ZephyrConfig::kConfigKey_OperationalDeviceICACerts, - ZephyrConfig::kConfigKey_OperationalDevicePrivateKey }; + ZephyrConfig::kConfigKey_OperationalDevicePrivateKey, + ZephyrConfig::kConfigKey_RegulatoryLocation, + ZephyrConfig::kConfigKey_CountryCode, + ZephyrConfig::kConfigKey_Breadcrumb }; // Data structure to be passed as a parameter of Zephyr's settings_load_subtree_direct() function struct ReadRequest diff --git a/src/platform/Zephyr/ZephyrConfig.h b/src/platform/Zephyr/ZephyrConfig.h index f50cf394b052a1..e804af050f7ca5 100644 --- a/src/platform/Zephyr/ZephyrConfig.h +++ b/src/platform/Zephyr/ZephyrConfig.h @@ -64,6 +64,9 @@ class ZephyrConfig static const Key kConfigKey_OperationalDeviceCert; static const Key kConfigKey_OperationalDeviceICACerts; static const Key kConfigKey_OperationalDevicePrivateKey; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_Breadcrumb; static CHIP_ERROR Init(void); diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp index f228677bef87a0..644a89b0251612 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp @@ -68,6 +68,10 @@ const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceICAC const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDevicePrivateKey = { { kCC13X2_26X2ChipFactory_Sysid, 0x001d } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { { kCC13X2_26X2ChipFactory_Sysid, 0x001e } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { { kCC13X2_26X2ChipFactory_Sysid, 0x001f } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Breadcrumb = { { kCC13X2_26X2ChipFactory_Sysid, 0x0020 } }; + /* Static local variables */ static NVINTF_nvFuncts_t sNvoctpFps = { 0 }; diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h b/src/platform/cc13x2_26x2/CC13X2_26X2Config.h index 78387921221c07..12ef94c62fe431 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.h @@ -67,6 +67,9 @@ class CC13X2_26X2Config static const Key kConfigKey_OperationalDeviceCert; static const Key kConfigKey_OperationalDeviceICACerts; static const Key kConfigKey_OperationalDevicePrivateKey; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_Breadcrumb; static CHIP_ERROR Init(void); diff --git a/src/platform/qpg6100/qpg6100Config.h b/src/platform/qpg6100/qpg6100Config.h index bcc5b051a7bfd8..328378c547d78e 100644 --- a/src/platform/qpg6100/qpg6100Config.h +++ b/src/platform/qpg6100/qpg6100Config.h @@ -86,9 +86,12 @@ class QPG6100Config static constexpr Key kConfigKey_OperationalDeviceCert = QorvoConfigKey(kFileId_ChipConfig, 0x0A); static constexpr Key kConfigKey_OperationalDeviceICACerts = QorvoConfigKey(kFileId_ChipConfig, 0x0B); static constexpr Key kConfigKey_OperationalDevicePrivateKey = QorvoConfigKey(kFileId_ChipConfig, 0x0C); + static constexpr Key kConfigKey_RegulatoryLocation = QorvoConfigKey(kFileId_ChipConfig, 0x0D); + static constexpr Key kConfigKey_CountryCode = QorvoConfigKey(kFileId_ChipConfig, 0x0E); + static constexpr Key kConfigKey_Breadcrumb = QorvoConfigKey(kFileId_ChipConfig, 0x0F); - static constexpr Key kConfigKey_GroupKeyBase = QorvoConfigKey(kFileId_ChipConfig, 0x0D); - static constexpr Key kConfigKey_GroupKeyMax = QorvoConfigKey(kFileId_ChipConfig, 0x1C); // Allows 16 Group Keys to be created. + static constexpr Key kConfigKey_GroupKeyBase = QorvoConfigKey(kFileId_ChipConfig, 0x10); + static constexpr Key kConfigKey_GroupKeyMax = QorvoConfigKey(kFileId_ChipConfig, 0x1F); // Allows 16 Group Keys to be created. static constexpr Key kConfigKey_CounterKeyBase = QorvoConfigKey(kFileId_ChipCounter, 0x00); static constexpr Key kConfigKey_CounterKeyMax = diff --git a/src/platform/tests/TestConfigurationMgr.cpp b/src/platform/tests/TestConfigurationMgr.cpp index 2a5734f7ad9f05..c8fa8273fb13ab 100644 --- a/src/platform/tests/TestConfigurationMgr.cpp +++ b/src/platform/tests/TestConfigurationMgr.cpp @@ -395,6 +395,52 @@ static void TestConfigurationMgr_ServiceProvisioningData(nlTestSuite * inSuite, NL_TEST_ASSERT(inSuite, memcmp(buf, serviceConfig, serviceConfigLen) == 0); } +static void TestConfigurationMgr_RegulatoryLocation(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + uint32_t location = 0; + + err = ConfigurationMgr().StoreRegulatoryLocation(12345); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = ConfigurationMgr().GetRegulatoryLocation(location); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + NL_TEST_ASSERT(inSuite, location == 12345); +} + +static void TestConfigurationMgr_CountryCode(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + char buf[8]; + size_t countryCodeLen = 0; + const char * countryCode = "US"; + + err = ConfigurationMgr().StoreCountryCode(countryCode, strlen(countryCode)); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = ConfigurationMgr().GetCountryCode(buf, 8, countryCodeLen); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + NL_TEST_ASSERT(inSuite, countryCodeLen == strlen(countryCode)); + NL_TEST_ASSERT(inSuite, strcmp(buf, countryCode) == 0); +} + +static void TestConfigurationMgr_Breadcrumb(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + uint64_t breadcrumb = 0; + + err = ConfigurationMgr().StoreBreadcrumb(12345); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = ConfigurationMgr().GetBreadcrumb(breadcrumb); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + NL_TEST_ASSERT(inSuite, breadcrumb == 12345); +} + /** * Test Suite. It lists all the test functions. */ @@ -418,6 +464,9 @@ static const nlTest sTests[] = { NL_TEST_DEF("Test ConfigurationMgr::ServiceConfig", TestConfigurationMgr_ServiceConfig), NL_TEST_DEF("Test ConfigurationMgr::PairedAccountId", TestConfigurationMgr_PairedAccountId), NL_TEST_DEF("Test ConfigurationMgr::ServiceProvisioningData", TestConfigurationMgr_ServiceProvisioningData), + NL_TEST_DEF("Test ConfigurationMgr::RegulatoryLocation", TestConfigurationMgr_RegulatoryLocation), + NL_TEST_DEF("Test ConfigurationMgr::CountryCode", TestConfigurationMgr_CountryCode), + NL_TEST_DEF("Test ConfigurationMgr::Breadcrumb", TestConfigurationMgr_Breadcrumb), NL_TEST_SENTINEL() };