diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 2862a3fa432425..b7f02c8b831ce9 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -28,6 +28,9 @@ #include #include +#include "../dcl/DCLClient.h" +#include "../dcl/DisplayTermsAndConditions.h" + #include using namespace ::chip; @@ -235,6 +238,7 @@ CHIP_ERROR PairingCommand::PairWithCode(NodeId remoteId) discoveryType = DiscoveryType::kDiscoveryNetworkOnlyWithoutPASEAutoRetry; } + ReturnErrorOnFailure(MaybeDisplayTermsAndConditions(commissioningParams)); return CurrentCommissioner().PairDevice(remoteId, mOnboardingPayload, commissioningParams, discoveryType); } @@ -588,3 +592,27 @@ void PairingCommand::OnDeviceAttestationCompleted(Controller::DeviceCommissioner SetCommandExitStatus(err); } } + +CHIP_ERROR PairingCommand::MaybeDisplayTermsAndConditions(CommissioningParameters & params) +{ + VerifyOrReturnError(mUseDCL.ValueOr(false), CHIP_NO_ERROR); + + Json::Value tc; + auto client = tool::dcl::DCLClient(mDCLHostName, mDCLPort); + ReturnErrorOnFailure(client.TermsAndConditions(mOnboardingPayload, tc)); + if (tc != Json::nullValue) + { + uint16_t version = 0; + uint16_t userResponse = 0; + ReturnErrorOnFailure(tool::dcl::DisplayTermsAndConditions(tc, version, userResponse, mCountryCode)); + + TermsAndConditionsAcknowledgement termsAndConditionsAcknowledgement = { + .acceptedTermsAndConditions = userResponse, + .acceptedTermsAndConditionsVersion = version, + }; + params.SetTermsAndConditionsAcknowledgement(termsAndConditionsAcknowledgement); + params.SetRequireTermsAndConditionsAcknowledgement(true); + } + + return CHIP_NO_ERROR; +} diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index b6903e34d53529..285a3f1440ca9b 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -106,6 +106,10 @@ class PairingCommand : public CHIPCommand, break; case PairingMode::Code: AddArgument("skip-commissioning-complete", 0, 1, &mSkipCommissioningComplete); + AddArgument("dcl-hostname", &mDCLHostName, + "Hostname of the DCL server to fetch information from. Defaults to 'on.dcl.csa-iot.org'."); + AddArgument("dcl-port", 0, UINT16_MAX, &mDCLPort, "Port number for connecting to the DCL server. Defaults to '443'."); + AddArgument("use-dcl", 0, 1, &mUseDCL, "Use DCL to fetch onboarding information"); FALLTHROUGH; case PairingMode::CodePaseOnly: AddArgument("payload", &mOnboardingPayload); @@ -252,6 +256,7 @@ class PairingCommand : public CHIPCommand, CHIP_ERROR PairWithMdnsOrBleByIndexWithCode(NodeId remoteId, uint16_t index); CHIP_ERROR Unpair(NodeId remoteId); chip::Controller::CommissioningParameters GetCommissioningParameters(); + CHIP_ERROR MaybeDisplayTermsAndConditions(chip::Controller::CommissioningParameters & params); const PairingMode mPairingMode; const PairingNetworkType mNetworkType; @@ -275,6 +280,9 @@ class PairingCommand : public CHIPCommand, chip::Optional mRequireTCAcknowledgements; chip::Optional mTCAcknowledgements; chip::Optional mTCAcknowledgementVersion; + chip::Optional mDCLHostName; + chip::Optional mDCLPort; + chip::Optional mUseDCL; chip::app::DataModel::List mTimeZoneList; TypedComplexArgument> mComplex_TimeZones;