Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae03df5

Browse files
committedJan 14, 2025·
[chip-tool] Add TermsAndConditions support to chip-tool pairing code command
1 parent 8443bf9 commit ae03df5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎examples/chip-tool/commands/pairing/PairingCommand.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <setup_payload/ManualSetupPayloadParser.h>
2929
#include <setup_payload/QRCodeSetupPayloadParser.h>
3030

31+
#include "../dcl/DCLClient.h"
32+
#include "../dcl/DisplayTermsAndConditions.h"
33+
3134
#include <string>
3235

3336
using namespace ::chip;
@@ -235,6 +238,7 @@ CHIP_ERROR PairingCommand::PairWithCode(NodeId remoteId)
235238
discoveryType = DiscoveryType::kDiscoveryNetworkOnlyWithoutPASEAutoRetry;
236239
}
237240

241+
ReturnErrorOnFailure(MaybeDisplayTermsAndConditions(commissioningParams));
238242
return CurrentCommissioner().PairDevice(remoteId, mOnboardingPayload, commissioningParams, discoveryType);
239243
}
240244

@@ -588,3 +592,27 @@ void PairingCommand::OnDeviceAttestationCompleted(Controller::DeviceCommissioner
588592
SetCommandExitStatus(err);
589593
}
590594
}
595+
596+
CHIP_ERROR PairingCommand::MaybeDisplayTermsAndConditions(CommissioningParameters & params)
597+
{
598+
VerifyOrReturnError(mUseDCL.ValueOr(false), CHIP_NO_ERROR);
599+
600+
Json::Value tc;
601+
auto client = tool::dcl::DCLClient(mDCLHostName, mDCLPort);
602+
ReturnErrorOnFailure(client.TermsAndConditions(mOnboardingPayload, tc));
603+
if (tc != Json::nullValue)
604+
{
605+
uint16_t version = 0;
606+
uint16_t userResponse = 0;
607+
ReturnErrorOnFailure(tool::dcl::DisplayTermsAndConditions(tc, version, userResponse, mCountryCode));
608+
609+
TermsAndConditionsAcknowledgement termsAndConditionsAcknowledgement = {
610+
.acceptedTermsAndConditions = userResponse,
611+
.acceptedTermsAndConditionsVersion = version,
612+
};
613+
params.SetTermsAndConditionsAcknowledgement(termsAndConditionsAcknowledgement);
614+
params.SetRequireTermsAndConditionsAcknowledgement(true);
615+
}
616+
617+
return CHIP_NO_ERROR;
618+
}

‎examples/chip-tool/commands/pairing/PairingCommand.h

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class PairingCommand : public CHIPCommand,
106106
break;
107107
case PairingMode::Code:
108108
AddArgument("skip-commissioning-complete", 0, 1, &mSkipCommissioningComplete);
109+
AddArgument("dcl-hostname", &mDCLHostName,
110+
"Hostname of the DCL server to fetch information from. Defaults to 'on.dcl.csa-iot.org'.");
111+
AddArgument("dcl-port", 0, UINT16_MAX, &mDCLPort, "Port number for connecting to the DCL server. Defaults to '443'.");
112+
AddArgument("use-dcl", 0, 1, &mUseDCL, "Use DCL to fetch onboarding information");
109113
FALLTHROUGH;
110114
case PairingMode::CodePaseOnly:
111115
AddArgument("payload", &mOnboardingPayload);
@@ -252,6 +256,7 @@ class PairingCommand : public CHIPCommand,
252256
CHIP_ERROR PairWithMdnsOrBleByIndexWithCode(NodeId remoteId, uint16_t index);
253257
CHIP_ERROR Unpair(NodeId remoteId);
254258
chip::Controller::CommissioningParameters GetCommissioningParameters();
259+
CHIP_ERROR MaybeDisplayTermsAndConditions(chip::Controller::CommissioningParameters & params);
255260

256261
const PairingMode mPairingMode;
257262
const PairingNetworkType mNetworkType;
@@ -275,6 +280,9 @@ class PairingCommand : public CHIPCommand,
275280
chip::Optional<bool> mRequireTCAcknowledgements;
276281
chip::Optional<uint16_t> mTCAcknowledgements;
277282
chip::Optional<uint16_t> mTCAcknowledgementVersion;
283+
chip::Optional<char *> mDCLHostName;
284+
chip::Optional<uint16_t> mDCLPort;
285+
chip::Optional<bool> mUseDCL;
278286
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type> mTimeZoneList;
279287
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type>>
280288
mComplex_TimeZones;

0 commit comments

Comments
 (0)
Please sign in to comment.