Skip to content

Commit

Permalink
[chip-tool] Add TermsAndConditions support to chip-tool pairing code …
Browse files Browse the repository at this point in the history
…command
  • Loading branch information
vivien-apple committed Jan 13, 2025
1 parent 8f3995e commit 4e72f95
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <setup_payload/ManualSetupPayloadParser.h>
#include <setup_payload/QRCodeSetupPayloadParser.h>

#include "../dcl/DCLClient.h"
#include "../dcl/DisplayTermsAndConditions.h"

#include <string>

using namespace ::chip;
Expand Down Expand Up @@ -235,6 +238,7 @@ CHIP_ERROR PairingCommand::PairWithCode(NodeId remoteId)
discoveryType = DiscoveryType::kDiscoveryNetworkOnlyWithoutPASEAutoRetry;
}

ReturnErrorOnFailure(MaybeDisplayTermsAndConditions(commissioningParams));
return CurrentCommissioner().PairDevice(remoteId, mOnboardingPayload, commissioningParams, discoveryType);
}

Expand Down Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -275,6 +280,9 @@ class PairingCommand : public CHIPCommand,
chip::Optional<bool> mRequireTCAcknowledgements;
chip::Optional<uint16_t> mTCAcknowledgements;
chip::Optional<uint16_t> mTCAcknowledgementVersion;
chip::Optional<char *> mDCLHostName;
chip::Optional<uint16_t> mDCLPort;
chip::Optional<bool> mUseDCL;
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type> mTimeZoneList;
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type>>
mComplex_TimeZones;
Expand Down

0 comments on commit 4e72f95

Please sign in to comment.