From 4647629eb1e0c161acbec49349477a31cb9b8737 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Tue, 7 May 2024 18:45:34 +0000 Subject: [PATCH] Add support for terms and conditions check and enhanced setup flow This commit adds support for terms and conditions (TC) check and enhances the setup flow as part of the Connected Home over IP (CHIP) Specification 1.4. Changes include: - Extended support for terms and conditions check and enhanced setup flow feature as part of the connectedhomeip spec 1.4. - Added functionality to retrieve and store Terms and Conditions (TC) information, including accepted version, minimum required version, acknowledgements, and required acknowledgements. - Implemented methods in `TermsAndConditionsManager` to handle TC versioning and acknowledgements. - Updated `GeneralCommissioningAttrAccess` to include support for reading TC-related attributes. - Added callback functions in `emberAfGeneralCommissioningCluster` to handle TC acknowledgements during commissioning. - Integrated `TermsAndConditionsManager` into the server context for managing TC-related information. - Enhanced error handling and logging for TC-related operations. - Adjusted build configuration to include default values for TC versioning and acknowledgements. - Expanded configuration management in `ConfigurationManagerImpl` to handle TC-related configuration keys. - Updated `PosixConfig` to include configuration keys for TC-related information. - Implemented default values for TC versioning and acknowledgements in `ConfigurationManagerImpl`. --- .../general-commissioning-server.cpp | 120 +++++++++++++----- src/app/server/BUILD.gn | 4 +- src/app/server/Server.h | 4 + src/app/server/TermsAndConditionsManager.cpp | 78 ++++++++++++ src/app/server/TermsAndConditionsManager.h | 20 +++ src/include/platform/CHIPDeviceConfig.h | 18 +++ src/include/platform/ConfigurationManager.h | 6 + .../GenericConfigurationManagerImpl.h | 8 ++ .../GenericConfigurationManagerImpl.ipp | 42 ++++++ src/lib/core/BUILD.gn | 4 + .../Linux/ConfigurationManagerImpl.cpp | 29 +++++ src/platform/Linux/PosixConfig.cpp | 23 ++-- src/platform/Linux/PosixConfig.h | 4 + src/platform/device.gni | 7 + 14 files changed, 326 insertions(+), 41 deletions(-) create mode 100644 src/app/server/TermsAndConditionsManager.cpp create mode 100644 src/app/server/TermsAndConditionsManager.h 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 536ac205454862..e5d94e9e8f137b 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2024 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. @@ -66,7 +66,8 @@ class GeneralCommissioningAttrAccess : public AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; private: - CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(uint8_t &), AttributeValueEncoder & aEncoder); + template + CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &), AttributeValueEncoder & aEncoder); CHIP_ERROR ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder); CHIP_ERROR ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder); }; @@ -95,17 +96,29 @@ CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath case SupportsConcurrentConnection::Id: { return ReadSupportsConcurrentConnection(aEncoder); } - default: { - break; + case TCAcceptedVersion::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCAcceptedVersion, aEncoder); + } + case TCMinRequiredVersion::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCMinRequiredVersion, aEncoder); + } + case TCAcknowledgements::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgements, aEncoder); } + case TCAcknowledgementsRequired::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgementsRequired, aEncoder); + } + default: + break; } return CHIP_NO_ERROR; } -CHIP_ERROR GeneralCommissioningAttrAccess::ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(uint8_t &), +template +CHIP_ERROR GeneralCommissioningAttrAccess::ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &), AttributeValueEncoder & aEncoder) { - uint8_t data; + T data; CHIP_ERROR err = (DeviceLayer::ConfigurationMgr().*getter)(data); if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) { @@ -208,15 +221,20 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler * return true; } +#ifndef CHIP_CONFIG_TNC_ACCEPTED_ACKNOWLEDGEMENTS +#error "Failed to set CHIP_CONFIG_TNC_ACCEPTED_ACKNOWLEDGEMENTS" +#endif + bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::CommissioningComplete::DecodableType & commandData) { MATTER_TRACE_SCOPE("CommissioningComplete", "GeneralCommissioning"); - DeviceControlServer * devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr(); - auto & failSafe = Server::GetInstance().GetFailSafeContext(); - auto & fabricTable = Server::GetInstance().GetFabricTable(); + DeviceControlServer * devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr(); + auto & failSafe = Server::GetInstance().GetFailSafeContext(); + auto & fabricTable = Server::GetInstance().GetFabricTable(); + auto & termsAndConditionsManager = Server::GetInstance().GetTermsAndConditionsManager(); ChipLogProgress(FailSafe, "GeneralCommissioning: Received CommissioningComplete"); @@ -239,34 +257,58 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( } else { - if (failSafe.NocCommandHasBeenInvoked()) + CHIP_ERROR err; + + // Fetch the terms and conditions acknowledgements for verification + uint16_t tcAcceptedVersion = 0U, tcMinRequiredVersion = 0U, tcAcknowledgements = 0U, tcAcknowledgementsRequired = 0U; + + err = termsAndConditionsManager.GetTCAcceptedVersion(tcAcceptedVersion); + CheckSuccess(err, Failure); + + err = termsAndConditionsManager.GetTCMinRequiredVersion(tcMinRequiredVersion); + CheckSuccess(err, Failure); + + err = termsAndConditionsManager.GetTCAcknowledgements(tcAcknowledgements); + CheckSuccess(err, Failure); + + err = termsAndConditionsManager.GetTCAcknowledgementsRequired(tcAcknowledgementsRequired); + CheckSuccess(err, Failure); + + if (tcAcknowledgementsRequired != (tcAcknowledgementsRequired & tcAcknowledgements)) { - CHIP_ERROR err = fabricTable.CommitPendingFabricData(); - if (err != CHIP_NO_ERROR) - { - // No need to revert on error: CommitPendingFabricData always reverts if not fully successful. - ChipLogError(FailSafe, "GeneralCommissioning: Failed to commit pending fabric data: %" CHIP_ERROR_FORMAT, - err.Format()); - } - else + ChipLogError(AppServer, "Required terms and conditions have not been accepted"); + Breadcrumb::Set(commandPath.mEndpointId, 0); + response.errorCode = CommissioningErrorEnum::kRequiredTCNotAccepted; + } + + else if (tcAcceptedVersion < tcMinRequiredVersion) + { + ChipLogError(AppServer, "Minimium terms and conditions version has not been accepted"); + Breadcrumb::Set(commandPath.mEndpointId, 0); + response.errorCode = CommissioningErrorEnum::kTCMinVersionNotMet; + } + + else + { + if (failSafe.NocCommandHasBeenInvoked()) { + err = fabricTable.CommitPendingFabricData(); + CheckSuccess(err, Failure); ChipLogProgress(FailSafe, "GeneralCommissioning: Successfully commited pending fabric data"); } - CheckSuccess(err, Failure); - } - /* - * Pass fabric of commissioner to DeviceControlSvr. - * This allows device to send messages back to commissioner. - * Once bindings are implemented, this may no longer be needed. - */ - failSafe.DisarmFailSafe(); - CheckSuccess( - devCtrl->PostCommissioningCompleteEvent(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()), - Failure); + /* + * Pass fabric of commissioner to DeviceControlSvr. + * This allows device to send messages back to commissioner. + * Once bindings are implemented, this may no longer be needed. + */ + failSafe.DisarmFailSafe(); + err = devCtrl->PostCommissioningCompleteEvent(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()); + CheckSuccess(err, Failure); - Breadcrumb::Set(commandPath.mEndpointId, 0); - response.errorCode = CommissioningErrorEnum::kOk; + Breadcrumb::Set(commandPath.mEndpointId, 0); + response.errorCode = CommissioningErrorEnum::kOk; + } } } @@ -328,6 +370,22 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH return true; } +bool emberAfGeneralCommissioningClusterSetTCAcknowledgementsCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgements::DecodableType & commandData) +{ + MATTER_TRACE_SCOPE("SetTCAcknowledgements", "GeneralCommissioning"); + auto & termsAndConditionsManager = Server::GetInstance().GetTermsAndConditionsManager(); + + Commands::SetTCAcknowledgementsResponse::Type response; + + CheckSuccess(termsAndConditionsManager.SetTCAcknowledgements(commandData.TCVersion, commandData.TCUserResponse), Failure); + response.errorCode = CommissioningErrorEnum::kOk; + + commandObj->AddResponse(commandPath, response); + return true; +} + namespace { void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg) { diff --git a/src/app/server/BUILD.gn b/src/app/server/BUILD.gn index 7c661464bbaea3..268201b12b1725 100644 --- a/src/app/server/BUILD.gn +++ b/src/app/server/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Project CHIP Authors +# Copyright (c) 2020-2024 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. @@ -44,6 +44,8 @@ static_library("server") { "OnboardingCodesUtil.h", "Server.cpp", "Server.h", + "TermsAndConditionsManager.cpp", + "TermsAndConditionsManager.h", ] public_configs = [ ":server_config" ] diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 302471b8bebb89..f672a85f74e8e8 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -357,6 +358,8 @@ class Server app::FailSafeContext & GetFailSafeContext() { return mFailSafeContext; } + app::TermsAndConditionsManager & GetTermsAndConditionsManager() { return mTermsAndConditionsManager; } + TestEventTriggerDelegate * GetTestEventTriggerDelegate() { return mTestEventTriggerDelegate; } Crypto::OperationalKeystore * GetOperationalKeystore() { return mOperationalKeystore; } @@ -636,6 +639,7 @@ class Server Crypto::OperationalKeystore * mOperationalKeystore; Credentials::OperationalCertificateStore * mOpCertStore; app::FailSafeContext mFailSafeContext; + app::TermsAndConditionsManager mTermsAndConditionsManager; bool mIsDnssdReady = false; uint16_t mOperationalServicePort; diff --git a/src/app/server/TermsAndConditionsManager.cpp b/src/app/server/TermsAndConditionsManager.cpp new file mode 100644 index 00000000000000..c303dfc92e3cb9 --- /dev/null +++ b/src/app/server/TermsAndConditionsManager.cpp @@ -0,0 +1,78 @@ +#include "TermsAndConditionsManager.h" + +#include + +CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCAcceptedVersion(uint16_t & value) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = DeviceLayer::ConfigurationMgr().GetTCAcceptedVersion(value); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "GetTCAcceptedVersion failed with error: %s", ErrorStr(err)); + } + return err; +} + +CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCMinRequiredVersion(uint16_t & value) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = DeviceLayer::ConfigurationMgr().GetTCMinRequiredVersion(value); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "GetTCMinRequiredVersion failed with error: %s", ErrorStr(err)); + } + return err; +} + +CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCAcknowledgements(uint16_t & value) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = DeviceLayer::ConfigurationMgr().GetTCAcknowledgements(value); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "GetTCAcknowledgements failed with error: %s", ErrorStr(err)); + } + return err; +} + +CHIP_ERROR chip::app::TermsAndConditionsManager::GetTCAcknowledgementsRequired(uint16_t & value) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = DeviceLayer::ConfigurationMgr().GetTCAcknowledgementsRequired(value); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "GetTCAcknowledgementsRequired failed with error: %s", ErrorStr(err)); + } + return err; +} + +CHIP_ERROR chip::app::TermsAndConditionsManager::SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = DeviceLayer::ConfigurationMgr().StoreTCAcknowledgements(tcVersion, tcUserResponse); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "SetTCAcknowledgements failed with error: %s", ErrorStr(err)); + } + return err; +} diff --git a/src/app/server/TermsAndConditionsManager.h b/src/app/server/TermsAndConditionsManager.h new file mode 100644 index 00000000000000..c2459272dae5a8 --- /dev/null +++ b/src/app/server/TermsAndConditionsManager.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include + +namespace chip { +namespace app { + +class TermsAndConditionsManager { +public: + CHIP_ERROR GetTCAcceptedVersion(uint16_t &value); + CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value); + CHIP_ERROR GetTCAcknowledgements(uint16_t &value); + CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value); + CHIP_ERROR SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse); +}; + +}; // namespace app +}; // namespace chip diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 785b47656dd5a3..a0f4e83f09a194 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -1507,6 +1507,24 @@ static_assert(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN <= CHIP_DEVICE // -------------------- Miscellaneous -------------------- +// ----------------------- Terms and Conditions ----------------------- + +#ifndef CHIP_CONFIG_TNC_ACCEPTED_ACKNOWLEDGEMENTS +#define CHIP_CONFIG_TNC_ACCEPTED_ACKNOWLEDGEMENTS 0 +#endif + +#ifndef CHIP_CONFIG_TNC_ACCEPTED_VERSION +#define CHIP_CONFIG_TNC_ACCEPTED_VERSION 0 +#endif + +#ifndef CHIP_CONFIG_TNC_REQUIRED_ACKNOWLEDGEMENTS +#define CHIP_CONFIG_TNC_REQUIRED_ACKNOWLEDGEMENTS 0 +#endif + +#ifndef CHIP_CONFIG_TNC_REQUIRED_VERSION +#define CHIP_CONFIG_TNC_REQUIRED_VERSION 0 +#endif + /** * CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES * diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index c7158d22c58d5e..1b34b95c696b6b 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -132,6 +132,12 @@ 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 StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) = 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..6ba54a370f0481 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -81,6 +81,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager #endif CHIP_ERROR GetFailSafeArmed(bool & val) override; CHIP_ERROR SetFailSafeArmed(bool val) override; + CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) override; bool IsCommissionableDeviceTypeEnabled() override; CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override; @@ -94,6 +95,11 @@ class GenericConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR StoreRegulatoryLocation(uint8_t location) override; CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) override; CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) 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 StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) override; CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) 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..cdc0b22c921b9c 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -582,6 +582,48 @@ 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::StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) +{ + CHIP_ERROR err; + + err = WriteConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, 0U); + SuccessOrExit(err); + + err = WriteConfigValue(ConfigClass::kConfigKey_TCAcknowledgements, tcUserResponse); + SuccessOrExit(err); + + err = WriteConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, tcVersion); + SuccessOrExit(err); + +exit: + return err; +} + template CHIP_ERROR GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) diff --git a/src/lib/core/BUILD.gn b/src/lib/core/BUILD.gn index eaecf859ac1993..d944be14ee510a 100644 --- a/src/lib/core/BUILD.gn +++ b/src/lib/core/BUILD.gn @@ -69,6 +69,10 @@ buildconfig_header("chip_buildconfig") { "CHIP_CONFIG_TLV_VALIDATE_CHAR_STRING_ON_WRITE=${chip_tlv_validate_char_string_on_write}", "CHIP_CONFIG_TLV_VALIDATE_CHAR_STRING_ON_READ=${chip_tlv_validate_char_string_on_read}", "CHIP_CONFIG_COMMAND_SENDER_BUILTIN_SUPPORT_FOR_BATCHED_COMMANDS=${chip_enable_sending_batch_commands}", + "CHIP_CONFIG_TNC_ACCEPTED_ACKNOWLEDGEMENTS=${chip_tnc_accepted_acknowledgements}", + "CHIP_CONFIG_TNC_ACCEPTED_VERSION=${chip_tnc_accepted_version}", + "CHIP_CONFIG_TNC_REQUIRED_ACKNOWLEDGEMENTS=${chip_tnc_required_acknowledgements}", + "CHIP_CONFIG_TNC_REQUIRED_VERSION=${chip_tnc_required_version}", ] visibility = [ ":chip_config_header" ] diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index 92e2c1e290b7bc..2a4822a2f87058 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -24,6 +24,7 @@ */ #include +#include #include #include #include @@ -118,6 +119,34 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(err); } + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCAcceptedVersion)) + { + uint16_t tcAcceptedVersion = CHIP_CONFIG_TNC_ACCEPTED_VERSION; + err = WriteConfigValue(PosixConfig::kConfigKey_TCAcceptedVersion, tcAcceptedVersion); + SuccessOrExit(err); + } + + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCMinRequiredVersion)) + { + uint16_t tcMinRequiredVersion = CHIP_CONFIG_TNC_REQUIRED_VERSION; + err = WriteConfigValue(PosixConfig::kConfigKey_TCMinRequiredVersion, tcMinRequiredVersion); + SuccessOrExit(err); + } + + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCAcknowledgements)) + { + uint16_t tcAcknowledgements = CHIP_CONFIG_TNC_ACCEPTED_ACKNOWLEDGEMENTS; + err = WriteConfigValue(PosixConfig::kConfigKey_TCAcknowledgements, tcAcknowledgements); + SuccessOrExit(err); + } + + if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_TCAcknowledgementsRequired)) + { + uint16_t tcAcknowledgementsRequired = CHIP_CONFIG_TNC_REQUIRED_ACKNOWLEDGEMENTS; + 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; diff --git a/src/platform/device.gni b/src/platform/device.gni index 01358d4880f876..6181a33114c613 100644 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -225,6 +225,13 @@ declare_args() { build_tv_casting_common_a = false } +declare_args() { + chip_tnc_accepted_acknowledgements = 0 + chip_tnc_accepted_version = 0 + chip_tnc_required_acknowledgements = 0 + chip_tnc_required_version = 0 +} + assert(!chip_disable_platform_kvs || chip_device_platform == "darwin", "Can only disable KVS on some platforms")