Skip to content

Commit

Permalink
Integrate terms and conditions configurations into the all-clusters s…
Browse files Browse the repository at this point in the history
…ample 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.
  • Loading branch information
swan-amazon committed May 7, 2024
1 parent b2441ea commit e6865d7
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/include/platform/internal/GenericConfigurationManagerImpl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,26 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetFailSafeArmed(bool v
return WriteConfigValue(ConfigClass::kConfigKey_FailSafeArmed, val);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcceptedVersion(uint16_t &value) {
return ReadConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCMinRequiredVersion(uint16_t &value) {
return ReadConfigValue(ConfigClass::kConfigKey_TCMinRequiredVersion, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcknowledgements(uint16_t &value) {
return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgements, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcknowledgementsRequired(uint16_t &value) {
return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgementsRequired, value);
}

template <class ConfigClass>
CHIP_ERROR
GenericConfigurationManagerImpl<ConfigClass>::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo)
Expand Down
28 changes: 28 additions & 0 deletions src/platform/Linux/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 14 additions & 9 deletions src/platform/Linux/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Linux/PosixConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e6865d7

Please sign in to comment.