diff --git a/.vscode/launch.json b/.vscode/launch.json index afe60953d9f1bd..37c5909e32b5fb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,7 +17,7 @@ "breakpointMode": "path", "sourceLanguages": ["cpp"], "reverseDebugging": true, - "preRunCommands": ["platform shell rm /tmp/kvs.bin"], + "preRunCommands": [], "program": "${workspaceFolder}/out/linux-x64-all-clusters-no-ble-no-wifi/chip-all-clusters-app", "args": ["--KVS=/tmp/kvs.bin", "--trace_decode=1"], "cwd": "${workspaceFolder}/out/linux-x64-all-clusters-no-ble-no-wifi", @@ -36,8 +36,8 @@ "PATH": "${workspaceFolder}/third_party/pigweed/repo/out/host/host_tools:${workspaceFolder}/.environment/pigweed-venv/bin:${workspaceFolder}/.environment/cipd/packages/arm/bin:${workspaceFolder}/.environment/cipd/packages/arm:${workspaceFolder}/.environment/cipd/packages/zap:${workspaceFolder}/.environment/cipd/packages/pigweed/bin:${workspaceFolder}/.environment/cipd/packages/pigweed:${workspaceFolder}/.environment/cip:${containerEnv:PATH}" }, "stdio": [null, null, null], - "terminal": "integrated", - "stopOnEntry": true + "terminal": "console", + "stopOnEntry": false }, { "name": "LLDB Debugger: Chip-Tool (chip-tool)", diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index aec4d4601390e4..167aeaf983037b 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -2171,6 +2171,22 @@ "source": "server", "isIncoming": 0, "isEnabled": 1 + }, + { + "name": "SetTCAcknowledgements", + "code": 6, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + }, + { + "name": "SetTCAcknowledgementsResponse", + "code": 7, + "mfgCode": null, + "source": "server", + "isIncoming": 0, + "isEnabled": 1 } ], "attributes": [ @@ -2254,6 +2270,70 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "TCAcceptedVersion", + "code": 5, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "TCMinRequiredVersion", + "code": 6, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "TCAcknowledgements", + "code": 7, + "mfgCode": null, + "side": "server", + "type": "bitmap16", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0x0000", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "TCAcknowledgementsRequired", + "code": 8, + "mfgCode": null, + "side": "server", + "type": "boolean", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "true", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "GeneratedCommandList", "code": 65528, @@ -2328,7 +2408,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0", + "defaultValue": "1", "reportable": 1, "minInterval": 1, "maxInterval": 65534, diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index ed80bc007df796..0f30a12c8dc2c5 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -118,6 +118,12 @@ CommissioningParameters PairingCommand::GetCommissioningParameters() params.SetCountryCode(CharSpan::fromCharString(mCountryCode.Value())); } + if (mTCAcknowledgements.HasValue() && mTCAcknowledgementVersion.HasValue()) + { + params.SetTCAcknowledgements(mTCAcknowledgements.Value()); + params.SetTCAcknowledgementVersion(mTCAcknowledgementVersion.Value()); + } + // mTimeZoneList is an optional argument managed by TypedComplexArgument mComplex_TimeZones. // Since optional Complex arguments are not currently supported via the class, // we will use mTimeZoneList.data() value to determine if the argument was provided. diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index 0baf70128531b8..b75ae6157b7f0e 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,8 +55,7 @@ class PairingCommand : public CHIPCommand, PairingCommand(const char * commandName, PairingMode mode, PairingNetworkType networkType, CredentialIssuerCommands * credIssuerCmds, chip::Dnssd::DiscoveryFilterType filterType = chip::Dnssd::DiscoveryFilterType::kNone) : - CHIPCommand(commandName, credIssuerCmds), - mPairingMode(mode), mNetworkType(networkType), mFilterType(filterType), + CHIPCommand(commandName, credIssuerCmds), mPairingMode(mode), mNetworkType(networkType), mFilterType(filterType), mRemoteAddr{ IPAddress::Any, chip::Inet::InterfaceId::Null() }, mComplex_TimeZones(&mTimeZoneList), mComplex_DSTOffsets(&mDSTOffsetList), mCurrentFabricRemoveCallback(OnCurrentFabricRemove, this) { @@ -182,6 +181,14 @@ class PairingCommand : public CHIPCommand, AddArgument("dst-offset", &mComplex_DSTOffsets, "DSTOffset list to use when setting Time Synchronization cluster's DSTOffset attribute", Argument::kOptional); + + AddArgument("tc-acknowledgements", 0, UINT16_MAX, &mTCAcknowledgements, + "Terms and Conditions acknowledgements to use to set the General Commissioning cluster's TC " + "Acknowledgements bit-field"); + + AddArgument("tc-acknowledgement-version", 0, UINT16_MAX, &mTCAcknowledgementVersion, + "Terms and Conditions acknowledgement version to use to set the General Commissioning cluster's TC " + "Acknowledgement version"); } AddArgument("timeout", 0, UINT16_MAX, &mTimeout); @@ -233,6 +240,8 @@ class PairingCommand : public CHIPCommand, chip::Optional mBypassAttestationVerifier; chip::Optional> mCASEAuthTags; chip::Optional mCountryCode; + chip::Optional mTCAcknowledgements; + chip::Optional mTCAcknowledgementVersion; chip::Optional mSkipICDRegistration; chip::Optional mICDCheckInNodeId; chip::Optional mICDSymmetricKey; 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..9dec1a5da1bb96 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. @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -95,9 +96,28 @@ CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath case SupportsConcurrentConnection::Id: { return ReadSupportsConcurrentConnection(aEncoder); } - default: { - break; + case TCAcceptedVersion::Id: { + uint16_t tcAcceptedVersion; + CHIP_ERROR err = EnhancedSetupFlowProvider::GetInstance().GetTCAcceptedVersion(tcAcceptedVersion); + return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcAcceptedVersion); + } + case TCMinRequiredVersion::Id: { + uint16_t tcMinRequiredVersion; + CHIP_ERROR err = EnhancedSetupFlowProvider::GetInstance().GetTCMinRequiredVersion(tcMinRequiredVersion); + return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcMinRequiredVersion); + } + case TCAcknowledgements::Id: { + uint16_t tcAcknowledgements; + CHIP_ERROR err = EnhancedSetupFlowProvider::GetInstance().GetTCAcknowledgements(tcAcknowledgements); + return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcAcknowledgements); } + case TCAcknowledgementsRequired::Id: { + uint16_t tcAcknowledgementsRequired; + CHIP_ERROR err = EnhancedSetupFlowProvider::GetInstance().GetTCAcknowledgementsRequired(tcAcknowledgementsRequired); + return (CHIP_NO_ERROR != err) ? err : aEncoder.Encode(tcAcknowledgementsRequired); + } + default: + break; } return CHIP_NO_ERROR; } @@ -239,34 +259,43 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( } else { - if (failSafe.NocCommandHasBeenInvoked()) + CHIP_ERROR err; + + if (!EnhancedSetupFlowProvider::GetInstance().HasRequiredTermsAndConditionsBeenAcknowledged()) { - 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 (!EnhancedSetupFlowProvider::GetInstance().HasRequiredTermsAndConditionsMinVersionBeenAcknowledged()) + { + 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,13 +357,38 @@ 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"); + + Commands::SetTCAcknowledgementsResponse::Type response; + + CheckSuccess(EnhancedSetupFlowProvider::GetInstance().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) { - if (event->Type == DeviceLayer::DeviceEventType::kFailSafeTimerExpired) - { - // Spec says to reset Breadcrumb attribute to 0. - Breadcrumb::Set(0, 0); + switch (event->Type) { + case DeviceLayer::DeviceEventType::kFailSafeTimerExpired: { + // Spec says to reset Breadcrumb attribute to 0. + Breadcrumb::Set(0, 0); + break; + } + case DeviceLayer::DeviceEventType::kServerReady: { + EnhancedSetupFlowProvider::GetInstance().Init(); + break; + } + default: { + break; + } } } diff --git a/src/app/server/BUILD.gn b/src/app/server/BUILD.gn index 7c661464bbaea3..a07c61b398f054 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. @@ -40,10 +40,13 @@ static_library("server") { "Dnssd.h", "EchoHandler.cpp", "EchoHandler.h", + "EnhancedSetupFlowProvider.cpp", + "EnhancedSetupFlowProvider.h", "OnboardingCodesUtil.cpp", "OnboardingCodesUtil.h", "Server.cpp", "Server.h", + "TermsAndConditionsProvider.h", ] public_configs = [ ":server_config" ] diff --git a/src/app/server/EnhancedSetupFlowProvider.cpp b/src/app/server/EnhancedSetupFlowProvider.cpp new file mode 100644 index 00000000000000..9810629ec4a18f --- /dev/null +++ b/src/app/server/EnhancedSetupFlowProvider.cpp @@ -0,0 +1,97 @@ +/* + * + * 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 "EnhancedSetupFlowProvider.h" + +#include +#include + +chip::app::EnhancedSetupFlowProvider chip::app::EnhancedSetupFlowProvider::sEnhancedSetupFlowProviderInstance(kRootEndpointId); + +namespace { +constexpr char kTCUserAcceptedVersionKeyName[] = "tc-useracceptedversion"; +constexpr char kTCUserAcceptedAcknowledgementsKeyName[] = "tc-useracceptedacknowledgements"; +} // namespace + +CHIP_ERROR chip::app::EnhancedSetupFlowProvider::Init() +{ + uint16_t tcAcknowledgements = 0; + uint16_t tcAcceptedVersion = 0; + + chip::DeviceLayer::PersistedStorage::KeyValueStoreManager & kvsManager = + chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr(); + + kvsManager.Get(kTCUserAcceptedVersionKeyName, &tcAcceptedVersion, sizeof(tcAcceptedVersion)); + kvsManager.Get(kTCUserAcceptedAcknowledgementsKeyName, &tcAcknowledgements, sizeof(tcAcknowledgements)); + + mTCRequiredVersion = CHIP_CONFIG_TC_REQUIRED_VERSION; + mTCRequiredAcknowledgements = CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS; + mTCUserAcceptedVersion = tcAcceptedVersion; + mTCUserAcceptedAcknowledgements = tcAcknowledgements; + + return CHIP_NO_ERROR; +} + +bool chip::app::EnhancedSetupFlowProvider::HasRequiredTermsAndConditionsBeenAcknowledged() +{ + return (mTCUserAcceptedAcknowledgements & mTCRequiredAcknowledgements) == mTCRequiredAcknowledgements; +} + +bool chip::app::EnhancedSetupFlowProvider::HasRequiredTermsAndConditionsMinVersionBeenAcknowledged() +{ + return (mTCUserAcceptedVersion >= mTCRequiredVersion); +} + +CHIP_ERROR chip::app::EnhancedSetupFlowProvider::GetTCAcceptedVersion(uint16_t & value) +{ + value = mTCUserAcceptedVersion; + return CHIP_NO_ERROR; +} + +CHIP_ERROR chip::app::EnhancedSetupFlowProvider::GetTCMinRequiredVersion(uint16_t & value) +{ + value = mTCRequiredVersion; + return CHIP_NO_ERROR; +} + +CHIP_ERROR chip::app::EnhancedSetupFlowProvider::GetTCAcknowledgements(uint16_t & value) +{ + value = mTCUserAcceptedAcknowledgements; + return CHIP_NO_ERROR; +} + +CHIP_ERROR chip::app::EnhancedSetupFlowProvider::GetTCAcknowledgementsRequired(uint16_t & value) +{ + value = mTCUserAcceptedAcknowledgements; + return CHIP_NO_ERROR; +} + +CHIP_ERROR chip::app::EnhancedSetupFlowProvider::SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) +{ + chip::DeviceLayer::PersistedStorage::KeyValueStoreManager & kvsManager = + chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr(); + + mTCUserAcceptedVersion = tcVersion; + mTCUserAcceptedAcknowledgements = tcUserResponse; + + kvsManager.Put(kTCUserAcceptedVersionKeyName, &mTCUserAcceptedVersion, sizeof(mTCUserAcceptedVersion)); + kvsManager.Put(kTCUserAcceptedAcknowledgementsKeyName, &mTCUserAcceptedAcknowledgements, + sizeof(mTCUserAcceptedAcknowledgements)); + + return CHIP_NO_ERROR; +} diff --git a/src/app/server/EnhancedSetupFlowProvider.h b/src/app/server/EnhancedSetupFlowProvider.h new file mode 100644 index 00000000000000..eb70ed1db502b1 --- /dev/null +++ b/src/app/server/EnhancedSetupFlowProvider.h @@ -0,0 +1,58 @@ +/* + * + * 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 +#include + +namespace chip { +namespace app { + +class EnhancedSetupFlowProvider +{ +public: + static EnhancedSetupFlowProvider & GetInstance() { return sEnhancedSetupFlowProviderInstance; } + + EnhancedSetupFlowProvider(const chip::EndpointId & endpointId = kRootEndpointId) : mEndpointId(endpointId){}; + CHIP_ERROR Init(); + + bool HasRequiredTermsAndConditionsBeenAcknowledged(); + bool HasRequiredTermsAndConditionsMinVersionBeenAcknowledged(); + + 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); + +private: + static EnhancedSetupFlowProvider sEnhancedSetupFlowProviderInstance; + + const chip::EndpointId mEndpointId; + uint16_t mTCRequiredVersion; + uint16_t mTCRequiredAcknowledgements; + uint16_t mTCUserAcceptedVersion; + uint16_t mTCUserAcceptedAcknowledgements; +}; + +}; // namespace app +}; // namespace chip diff --git a/src/app/server/TermsAndConditionsProvider.h b/src/app/server/TermsAndConditionsProvider.h new file mode 100644 index 00000000000000..ca7cb4eefb13d5 --- /dev/null +++ b/src/app/server/TermsAndConditionsProvider.h @@ -0,0 +1,37 @@ +/* + * + * 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 TermsAndConditionsProvider +{ +public: + virtual ~TermsAndConditionsProvider() = default; + virtual CHIP_ERROR GetTCMinRequiredVersion(uint16_t & value); + virtual CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t & value); +}; + +}; // namespace app +}; // namespace chip diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index 42b39a10c7ab48..9fa5df21484f5b 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -343,13 +343,25 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStageInternal(Commissio case CommissioningStage::kArmFailsafe: return CommissioningStage::kConfigRegulatory; case CommissioningStage::kConfigRegulatory: + if (mParams.GetTCAcknowledgements().HasValue() && mParams.GetTCAcknowledgementVersion().HasValue()) + { + return CommissioningStage::kConfigureTCAcknowledgments; + } + else if (mDeviceCommissioningInfo.requiresUTC) + { + return CommissioningStage::kConfigureUTCTime; + } + else + { + return CommissioningStage::kSendPAICertificateRequest; + } + case CommissioningStage::kConfigureTCAcknowledgments: if (mDeviceCommissioningInfo.requiresUTC) { return CommissioningStage::kConfigureUTCTime; } else { - // Time cluster is not supported, move right to DA return CommissioningStage::kSendPAICertificateRequest; } case CommissioningStage::kConfigureUTCTime: diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index af0a66ea834da3..4c058cdc25b13a 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2013-2017 Nest Labs, Inc. * All rights reserved. * @@ -2426,6 +2426,22 @@ void DeviceCommissioner::OnSetRegulatoryConfigResponse( commissioner->CommissioningStageComplete(err, report); } +void DeviceCommissioner::OnSetTCAcknowledgementsResponse( + void * context, const GeneralCommissioning::Commands::SetTCAcknowledgementsResponse::DecodableType & data) +{ + CommissioningDelegate::CommissioningReport report; + CHIP_ERROR err = CHIP_NO_ERROR; + + ChipLogProgress(Controller, "Received SetTCAcknowledgements response errorCode=%u", to_underlying(data.errorCode)); + if (data.errorCode != GeneralCommissioning::CommissioningErrorEnum::kOk) + { + err = CHIP_ERROR_INTERNAL; + report.Set(data.errorCode); + } + DeviceCommissioner * commissioner = static_cast(context); + commissioner->CommissioningStageComplete(err, report); +} + void DeviceCommissioner::OnSetTimeZoneResponse(void * context, const TimeSynchronization::Commands::SetTimeZoneResponse::DecodableType & data) { @@ -2874,6 +2890,23 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio } } break; + case CommissioningStage::kConfigureTCAcknowledgments: { + ChipLogProgress(Controller, "Setting Terms and Conditions"); + + GeneralCommissioning::Commands::SetTCAcknowledgements::Type request; + request.TCUserResponse = params.GetTCAcknowledgements().Value(); + request.TCVersion = params.GetTCAcknowledgementVersion().Value(); + CHIP_ERROR err = + SendCommissioningCommand(proxy, request, OnSetTCAcknowledgementsResponse, OnBasicFailure, endpoint, timeout); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "Failed to send SetTCAcknowledgements command: %" CHIP_ERROR_FORMAT, err.Format()); + CommissioningStageComplete(err); + return; + } + + break; + } case CommissioningStage::kSendPAICertificateRequest: { ChipLogProgress(Controller, "Sending request for PAI certificate"); CHIP_ERROR err = SendCertificateChainRequestCommand(proxy, CertificateType::kPAI, timeout); diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index dd7b5bc31eec46..d6effac7ad4434 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2020-2024 Project CHIP Authors * Copyright (c) 2013-2017 Nest Labs, Inc. * All rights reserved. * @@ -893,6 +893,9 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, static void OnSetRegulatoryConfigResponse( void * context, const chip::app::Clusters::GeneralCommissioning::Commands::SetRegulatoryConfigResponse::DecodableType & data); + static void OnSetTCAcknowledgementsResponse( + void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgementsResponse::DecodableType & data); static void OnSetUTCError(void * context, CHIP_ERROR error); static void OnSetTimeZoneResponse(void * context, diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index 4b1040fcd79690..656aeb80ddad38 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2024 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace chip { @@ -38,6 +39,7 @@ enum CommissioningStage : uint8_t kReadCommissioningInfo2, ///< Query SupportsConcurrentConnection, ICD state, check for matching fabric kArmFailsafe, ///< Send ArmFailSafe (0x30:0) command to the device kConfigRegulatory, ///< Send SetRegulatoryConfig (0x30:2) command to the device + kConfigureTCAcknowledgments, ///< Send SetTCAcknowledgements (0x30:6) command to the device kConfigureUTCTime, ///< SetUTCTime if the DUT has a time cluster kConfigureTimeZone, ///< Configure a time zone if one is required and available kConfigureDSTOffset, ///< Configure DST offset if one is required and available @@ -158,6 +160,10 @@ class CommissioningParameters // The country code to be used for the node, if set. Optional GetCountryCode() const { return mCountryCode; } + Optional GetTCAcknowledgements() const { return mTCAcknowledgements; } + + Optional GetTCAcknowledgementVersion() const { return mTCAcknowledgementVersion; } + // Time zone to set for the node // If required, this will be truncated to fit the max size allowable on the node Optional> GetTimeZone() const @@ -330,6 +336,18 @@ class CommissioningParameters return *this; } + CommissioningParameters & SetTCAcknowledgements(uint16_t tcAcknowledgements) + { + mTCAcknowledgements.SetValue(tcAcknowledgements); + return *this; + } + + CommissioningParameters & SetTCAcknowledgementVersion(uint16_t tcAcknowledgementVersion) + { + mTCAcknowledgementVersion.SetValue(tcAcknowledgementVersion); + return *this; + } + // The lifetime of the list buffer needs to exceed the lifetime of the CommissioningParameters object. CommissioningParameters & SetTimeZone(app::DataModel::List timeZone) @@ -594,6 +612,8 @@ class CommissioningParameters Optional mAttestationNonce; Optional mWiFiCreds; Optional mCountryCode; + Optional mTCAcknowledgements; + Optional mTCAcknowledgementVersion; Optional mThreadOperationalDataset; Optional mNOCChainGenerationParameters; Optional mRootCert; diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 785b47656dd5a3..5797de71c03a6d 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,16 @@ static_assert(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN <= CHIP_DEVICE // -------------------- Miscellaneous -------------------- +// ----------------------- Terms and Conditions ----------------------- + +#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS +#define CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS 0 +#endif + +#ifndef CHIP_CONFIG_TC_REQUIRED_VERSION +#define CHIP_CONFIG_TC_REQUIRED_VERSION 0 +#endif + /** * CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES * diff --git a/src/lib/core/BUILD.gn b/src/lib/core/BUILD.gn index eaecf859ac1993..df4735e7a4ec2e 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,8 @@ 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_TC_REQUIRED_ACKNOWLEDGEMENTS=${chip_tc_required_acknowledgements}", + "CHIP_CONFIG_TC_REQUIRED_VERSION=${chip_tc_required_version}", ] visibility = [ ":chip_config_header" ] diff --git a/src/platform/device.gni b/src/platform/device.gni index 01358d4880f876..ece6774887f3c0 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,14 @@ declare_args() { build_tv_casting_common_a = false } +declare_args() { + # If non-zero, is the terms and conditions required acknowledgements bitfield + chip_tc_required_acknowledgements = 0 + + # If non-zero, is the terms and conditions required version + chip_tc_required_version = 0 +} + assert(!chip_disable_platform_kvs || chip_device_platform == "darwin", "Can only disable KVS on some platforms")