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..f287c990840637 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) { @@ -214,9 +227,10 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( { 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 +253,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 +366,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..adc37032509c5f 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -1,6 +1,6 @@ /* * - * 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. @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -329,46 +330,108 @@ class Server */ void RejoinExistingMulticastGroups(); - FabricTable & GetFabricTable() { return mFabrics; } + FabricTable & GetFabricTable() + { + return mFabrics; + } - CASESessionManager * GetCASESessionManager() { return &mCASESessionManager; } + CASESessionManager * GetCASESessionManager() + { + return &mCASESessionManager; + } - Messaging::ExchangeManager & GetExchangeManager() { return mExchangeMgr; } + Messaging::ExchangeManager & GetExchangeManager() + { + return mExchangeMgr; + } - SessionManager & GetSecureSessionManager() { return mSessions; } + SessionManager & GetSecureSessionManager() + { + return mSessions; + } - SessionResumptionStorage * GetSessionResumptionStorage() { return mSessionResumptionStorage; } + SessionResumptionStorage * GetSessionResumptionStorage() + { + return mSessionResumptionStorage; + } - app::SubscriptionResumptionStorage * GetSubscriptionResumptionStorage() { return mSubscriptionResumptionStorage; } + app::SubscriptionResumptionStorage * GetSubscriptionResumptionStorage() + { + return mSubscriptionResumptionStorage; + } - TransportMgrBase & GetTransportManager() { return mTransports; } + TransportMgrBase & GetTransportManager() + { + return mTransports; + } - Credentials::GroupDataProvider * GetGroupDataProvider() { return mGroupsProvider; } + Credentials::GroupDataProvider * GetGroupDataProvider() + { + return mGroupsProvider; + } - Crypto::SessionKeystore * GetSessionKeystore() const { return mSessionKeystore; } + Crypto::SessionKeystore * GetSessionKeystore() const + { + return mSessionKeystore; + } #if CONFIG_NETWORK_LAYER_BLE - Ble::BleLayer * GetBleLayerObject() { return mBleLayer; } + Ble::BleLayer * GetBleLayerObject() + { + return mBleLayer; + } #endif - CommissioningWindowManager & GetCommissioningWindowManager() { return mCommissioningWindowManager; } + CommissioningWindowManager & GetCommissioningWindowManager() + { + return mCommissioningWindowManager; + } - PersistentStorageDelegate & GetPersistentStorage() { return *mDeviceStorage; } + PersistentStorageDelegate & GetPersistentStorage() + { + return *mDeviceStorage; + } - app::FailSafeContext & GetFailSafeContext() { return mFailSafeContext; } + app::FailSafeContext & GetFailSafeContext() + { + return mFailSafeContext; + } - TestEventTriggerDelegate * GetTestEventTriggerDelegate() { return mTestEventTriggerDelegate; } + app::TermsAndConditionsManager & GetTermsAndConditionsManager() + { + return mTermsAndConditionsManager; + } - Crypto::OperationalKeystore * GetOperationalKeystore() { return mOperationalKeystore; } + TestEventTriggerDelegate * GetTestEventTriggerDelegate() + { + return mTestEventTriggerDelegate; + } - Credentials::OperationalCertificateStore * GetOpCertStore() { return mOpCertStore; } + Crypto::OperationalKeystore * GetOperationalKeystore() + { + return mOperationalKeystore; + } - app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister() { return mAttributePersister; } + Credentials::OperationalCertificateStore * GetOpCertStore() + { + return mOpCertStore; + } - app::reporting::ReportScheduler * GetReportScheduler() { return mReportScheduler; } + app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister() + { + return mAttributePersister; + } + + app::reporting::ReportScheduler * GetReportScheduler() + { + return mReportScheduler; + } #if CHIP_CONFIG_ENABLE_ICD_SERVER - app::ICDManager & GetICDManager() { return mICDManager; } + app::ICDManager & GetICDManager() + { + return mICDManager; + } #endif // CHIP_CONFIG_ENABLE_ICD_SERVER /** @@ -386,7 +449,10 @@ class Server return System::SystemClock().GetMonotonicMicroseconds64() - mInitTimestamp; } - static Server & GetInstance() { return sServer; } + static Server & GetInstance() + { + return sServer; + } private: Server() {} @@ -636,6 +702,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..30597fe64ad418 --- /dev/null +++ b/src/app/server/TermsAndConditionsManager.cpp @@ -0,0 +1,96 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#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..6cf09e5752a928 --- /dev/null +++ b/src/app/server/TermsAndConditionsManager.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#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..9ea6c8fc6141a1 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2019-2020 Google LLC. * Copyright (c) 2018 Nest Labs, Inc. * @@ -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..94fd5acf77794f 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2019-2020 Google LLC. * Copyright (c) 2018 Nest Labs, Inc. * @@ -104,7 +104,10 @@ class ConfigurationManager virtual CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) = 0; virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) = 0; virtual CHIP_ERROR GetFirmwareBuildChipEpochTime(System::Clock::Seconds32 & buildTime) = 0; - virtual CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime) { return CHIP_ERROR_NOT_IMPLEMENTED; } + virtual CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime) + { + return CHIP_ERROR_NOT_IMPLEMENTED; + } #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) // Lifetime counter is monotonic counter that is incremented upon each commencement of advertising virtual CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) = 0; @@ -132,6 +135,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..a8b82356884b5d 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2019-2020 Google LLC. * Copyright (c) 2018 Nest Labs, Inc. * @@ -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..0a720b5d57d542 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2019-2020 Google LLC. * Copyright (c) 2018 Nest Labs, Inc. * @@ -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..853eb1d98c0a08 100644 --- a/src/lib/core/BUILD.gn +++ b/src/lib/core/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022 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. @@ -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..5b584c6829c634 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2018 Nest Labs, Inc. * All rights reserved. * @@ -118,6 +118,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..cb74ec8ae72f99 100644 --- a/src/platform/Linux/PosixConfig.cpp +++ b/src/platform/Linux/PosixConfig.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2019-2020 Google LLC. * Copyright (c) 2018 Nest Labs, Inc. * All rights reserved. @@ -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..eebb5b5b7a1960 100644 --- a/src/platform/Linux/PosixConfig.h +++ b/src/platform/Linux/PosixConfig.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 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. @@ -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..5db51079177c5f 100644 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -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. @@ -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")