From e6865d7653ca355d45eb1664f02385597d8d5fb4 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Tue, 7 May 2024 18:32:53 +0000 Subject: [PATCH] Integrate terms and conditions configurations into the all-clusters sample app This commit adds support for terms and conditions configurations to the all-clusters sample app. The following changes have been made: - Added methods in ConfigurationManager.h to retrieve and set terms and conditions configurations. - Implemented these methods in GenericConfigurationManagerImpl.h and GenericConfigurationManagerImpl.ipp. - Updated ConfigurationManagerImpl.cpp to initialize default values for terms and conditions configurations if they do not exist. - Added new configuration keys in PosixConfig.h to represent terms and conditions configurations. These changes enable the all-clusters sample app to handle terms and conditions configurations efficiently, enhancing its functionality. --- src/include/platform/ConfigurationManager.h | 5 ++++ .../GenericConfigurationManagerImpl.h | 8 ++++++ .../GenericConfigurationManagerImpl.ipp | 20 +++++++++++++ .../Linux/ConfigurationManagerImpl.cpp | 28 +++++++++++++++++++ src/platform/Linux/PosixConfig.cpp | 23 +++++++++------ src/platform/Linux/PosixConfig.h | 4 +++ 6 files changed, 79 insertions(+), 9 deletions(-) diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index c7158d22c58d5e..7e891fedc2149b 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -132,6 +132,11 @@ class ConfigurationManager virtual CHIP_ERROR GetFailSafeArmed(bool & val) = 0; virtual CHIP_ERROR SetFailSafeArmed(bool val) = 0; + virtual CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCAcknowledgements(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) = 0; + virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0; #if CHIP_CONFIG_TEST diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index fa7e19503f845e..e3cb2d4d38d025 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -81,6 +81,12 @@ class GenericConfigurationManagerImpl : public ConfigurationManager #endif CHIP_ERROR GetFailSafeArmed(bool & val) override; CHIP_ERROR SetFailSafeArmed(bool val) override; + + CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) override; + CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) override; + CHIP_ERROR GetTCAcknowledgements(uint16_t &value) override; + CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) override; + CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) override; bool IsCommissionableDeviceTypeEnabled() override; CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override; @@ -136,11 +142,13 @@ class GenericConfigurationManagerImpl : public ConfigurationManager // Methods to read and write configuration values, as well as run the configuration unit test. typedef typename ConfigClass::Key Key; virtual CHIP_ERROR ReadConfigValue(Key key, bool & val) = 0; + virtual CHIP_ERROR ReadConfigValue(Key key, uint16_t & val) = 0; virtual CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) = 0; virtual CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) = 0; virtual CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) = 0; virtual CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) = 0; virtual CHIP_ERROR WriteConfigValue(Key key, bool val) = 0; + virtual CHIP_ERROR WriteConfigValue(Key key, uint16_t val) = 0; virtual CHIP_ERROR WriteConfigValue(Key key, uint32_t val) = 0; virtual CHIP_ERROR WriteConfigValue(Key key, uint64_t val) = 0; virtual CHIP_ERROR WriteConfigValueStr(Key key, const char * str) = 0; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index 955b782a3238ed..200411399770eb 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -582,6 +582,26 @@ CHIP_ERROR GenericConfigurationManagerImpl::SetFailSafeArmed(bool v return WriteConfigValue(ConfigClass::kConfigKey_FailSafeArmed, val); } +template +CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcceptedVersion(uint16_t &value) { + return ReadConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, value); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::GetTCMinRequiredVersion(uint16_t &value) { + return ReadConfigValue(ConfigClass::kConfigKey_TCMinRequiredVersion, value); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcknowledgements(uint16_t &value) { + return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgements, value); +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcknowledgementsRequired(uint16_t &value) { + return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgementsRequired, value); +} + template CHIP_ERROR GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index 92e2c1e290b7bc..bae62e2024c179 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -118,6 +118,34 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(err); } + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCAcceptedVersion)) + { + uint16_t tcAcceptedVersion = 0U; + err = WriteConfigValue(PosixConfig::kConfigKey_TCAcceptedVersion, tcAcceptedVersion); + SuccessOrExit(err); + } + + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCMinRequiredVersion)) + { + uint16_t tcMinRequiredVersion = 0U; + err = WriteConfigValue(PosixConfig::kConfigKey_TCMinRequiredVersion, tcMinRequiredVersion); + SuccessOrExit(err); + } + + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCAcknowledgements)) + { + uint16_t tcAcknowledgements = 0U; + err = WriteConfigValue(PosixConfig::kConfigKey_TCAcknowledgements, tcAcknowledgements); + SuccessOrExit(err); + } + + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCAcknowledgementsRequired)) + { + uint16_t tcAcknowledgementsRequired = 0U; + err = WriteConfigValue(PosixConfig::kConfigKey_TCAcknowledgementsRequired, tcAcknowledgementsRequired); + SuccessOrExit(err); + } + err = CHIP_NO_ERROR; exit: diff --git a/src/platform/Linux/PosixConfig.cpp b/src/platform/Linux/PosixConfig.cpp index 61a1fbd4dda6ed..fb8de8870fc473 100644 --- a/src/platform/Linux/PosixConfig.cpp +++ b/src/platform/Linux/PosixConfig.cpp @@ -62,17 +62,22 @@ const PosixConfig::Key PosixConfig::kConfigKey_Spake2pSalt = { kConfig const PosixConfig::Key PosixConfig::kConfigKey_Spake2pVerifier = { kConfigNamespace_ChipFactory, "verifier" }; const PosixConfig::Key PosixConfig::kConfigKey_VendorId = { kConfigNamespace_ChipFactory, "vendor-id" }; const PosixConfig::Key PosixConfig::kConfigKey_ProductId = { kConfigNamespace_ChipFactory, "product-id" }; +const PosixConfig::Key PosixConfig::kConfigKey_UniqueId = { kConfigNamespace_ChipFactory, "unique-id" }; + // Keys stored in the Chip-config namespace -const PosixConfig::Key PosixConfig::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" }; -const PosixConfig::Key PosixConfig::kConfigKey_PairedAccountId = { kConfigNamespace_ChipConfig, "account-id" }; -const PosixConfig::Key PosixConfig::kConfigKey_ServiceId = { kConfigNamespace_ChipConfig, "service-id" }; -const PosixConfig::Key PosixConfig::kConfigKey_LastUsedEpochKeyId = { kConfigNamespace_ChipConfig, "last-ek-id" }; -const PosixConfig::Key PosixConfig::kConfigKey_FailSafeArmed = { kConfigNamespace_ChipConfig, "fail-safe-armed" }; -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_LocationCapability = { kConfigNamespace_ChipConfig, "location-capability" }; -const PosixConfig::Key PosixConfig::kConfigKey_UniqueId = { kConfigNamespace_ChipFactory, "unique-id" }; +const PosixConfig::Key PosixConfig::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" }; +const PosixConfig::Key PosixConfig::kConfigKey_PairedAccountId = { kConfigNamespace_ChipConfig, "account-id" }; +const PosixConfig::Key PosixConfig::kConfigKey_ServiceId = { kConfigNamespace_ChipConfig, "service-id" }; +const PosixConfig::Key PosixConfig::kConfigKey_LastUsedEpochKeyId = { kConfigNamespace_ChipConfig, "last-ek-id" }; +const PosixConfig::Key PosixConfig::kConfigKey_FailSafeArmed = { kConfigNamespace_ChipConfig, "fail-safe-armed" }; +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_LocationCapability = { kConfigNamespace_ChipConfig, "location-capability" }; +const PosixConfig::Key PosixConfig::kConfigKey_TCAcceptedVersion = { kConfigNamespace_ChipConfig, "tc-accepted-version" }; +const PosixConfig::Key PosixConfig::kConfigKey_TCMinRequiredVersion = { kConfigNamespace_ChipConfig, "tc-min-required-version" }; +const PosixConfig::Key PosixConfig::kConfigKey_TCAcknowledgements = { kConfigNamespace_ChipConfig, "tc-acknowledgements" }; +const PosixConfig::Key PosixConfig::kConfigKey_TCAcknowledgementsRequired = { kConfigNamespace_ChipConfig, "tc-acknowledgements-required" }; // Keys stored in the Chip-counters namespace const PosixConfig::Key PosixConfig::kCounterKey_RebootCount = { kConfigNamespace_ChipCounters, "reboot-count" }; diff --git a/src/platform/Linux/PosixConfig.h b/src/platform/Linux/PosixConfig.h index c04d4a9be1093f..3d6b100f3fe48a 100644 --- a/src/platform/Linux/PosixConfig.h +++ b/src/platform/Linux/PosixConfig.h @@ -77,6 +77,10 @@ class PosixConfig static const Key kConfigKey_Spake2pVerifier; static const Key kConfigKey_VendorId; static const Key kConfigKey_ProductId; + static const Key kConfigKey_TCAcceptedVersion; + static const Key kConfigKey_TCMinRequiredVersion; + static const Key kConfigKey_TCAcknowledgements; + static const Key kConfigKey_TCAcknowledgementsRequired; static const Key kCounterKey_RebootCount; static const Key kCounterKey_UpTime;