Skip to content

Commit 48fc426

Browse files
authored
[darwin-framework-tool] Add Enhanced Commissioning Support (T&C Flow via Local DCL) to darwin-framework-tool (project-chip#37379)
* [darwin-framework-tool] Add darwin-framework-tool dcl tc-display and tc-display-by-payload commands * [darwin-framework-tool] Add TermsAndConditions support to darwin-framework-tool pairing code * [darwin] Add TermsAndConditions support MTRCommissioningParameters
1 parent cf68487 commit 48fc426

File tree

8 files changed

+445
-6
lines changed

8 files changed

+445
-6
lines changed

examples/darwin-framework-tool/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ executable("darwin-framework-tool") {
189189
"${chip_root}/examples/chip-tool/commands/common/Commands.cpp",
190190
"${chip_root}/examples/chip-tool/commands/common/Commands.h",
191191
"${chip_root}/examples/chip-tool/commands/common/HexConversion.h",
192+
"${chip_root}/examples/chip-tool/commands/dcl/DCLClient.cpp",
193+
"${chip_root}/examples/chip-tool/commands/dcl/DisplayTermsAndConditions.cpp",
194+
"${chip_root}/examples/chip-tool/commands/dcl/JsonSchemaMacros.cpp",
192195
"${chip_root}/examples/common/websocket-server/WebSocketServer.cpp",
193196
"${chip_root}/examples/common/websocket-server/WebSocketServer.h",
194197
"${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp",
@@ -220,6 +223,7 @@ executable("darwin-framework-tool") {
220223
"commands/configuration/ResetMRPParametersCommand.mm",
221224
"commands/configuration/SetMRPParametersCommand.h",
222225
"commands/configuration/SetMRPParametersCommand.mm",
226+
"commands/dcl/HTTPSRequest.mm",
223227
"commands/delay/Commands.h",
224228
"commands/delay/SleepCommand.h",
225229
"commands/delay/SleepCommand.mm",

examples/darwin-framework-tool/commands/dcl/HTTPSRequest.mm

+325
Large diffs are not rendered by default.

examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class PairingCommandBridge : public CHIPCommandBridge
6363
break;
6464
case PairingMode::Code:
6565
AddArgument("payload", &mOnboardingPayload);
66+
AddArgument("dcl-hostname", &mDCLHostName,
67+
"Hostname of the DCL server to fetch information from. Defaults to 'on.dcl.csa-iot.org'.");
68+
AddArgument("dcl-port", 0, UINT16_MAX, &mDCLPort, "Port number for connecting to the DCL server. Defaults to '443'.");
69+
AddArgument("use-dcl", 0, 1, &mUseDCL, "Use DCL to fetch onboarding information");
6670
break;
6771
case PairingMode::Ble:
6872
AddArgument("setup-pin-code", 0, 134217727, &mSetupPINCode);
@@ -71,6 +75,10 @@ class PairingCommandBridge : public CHIPCommandBridge
7175
case PairingMode::AlreadyDiscoveredByIndex:
7276
AddArgument("payload", &mOnboardingPayload);
7377
AddArgument("index", 0, UINT16_MAX, &mIndex);
78+
AddArgument("dcl-hostname", &mDCLHostName,
79+
"Hostname of the DCL server to fetch information from. Defaults to 'on.dcl.csa-iot.org'.");
80+
AddArgument("dcl-port", 0, UINT16_MAX, &mDCLPort, "Port number for connecting to the DCL server. Defaults to '443'.");
81+
AddArgument("use-dcl", 0, 1, &mUseDCL, "Use DCL to fetch onboarding information");
7482
break;
7583
}
7684

@@ -95,7 +103,8 @@ class PairingCommandBridge : public CHIPCommandBridge
95103
void PairWithIndex(NSError * __autoreleasing * error);
96104
void PairWithPayload(NSError * __autoreleasing * error);
97105
void Unpair();
98-
void SetUpDeviceControllerDelegate();
106+
void SetUpDeviceControllerDelegate(NSError * __autoreleasing * error);
107+
void MaybeDisplayTermsAndConditions(MTRCommissioningParameters * params, NSError * __autoreleasing * error);
99108

100109
const PairingMode mPairingMode;
101110
const CommissioningType mCommissioningType;
@@ -110,4 +119,7 @@ class PairingCommandBridge : public CHIPCommandBridge
110119
chip::Optional<bool> mUseDeviceAttestationDelegate;
111120
chip::Optional<uint16_t> mDeviceAttestationFailsafeTime;
112121
chip::Optional<char *> mCountryCode;
122+
chip::Optional<char *> mDCLHostName;
123+
chip::Optional<uint16_t> mDCLPort;
124+
chip::Optional<bool> mUseDCL;
113125
};

examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm

+47-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "../common/CertificateIssuer.h"
2323
#include "DeviceControllerDelegateBridge.h"
2424
#include "PairingCommandBridge.h"
25+
#include <commands/dcl/DCLClient.h>
26+
#include <commands/dcl/DisplayTermsAndConditions.h>
2527
#include <lib/support/logging/CHIPLogging.h>
2628

2729
#import "MTRError_Utils.h"
@@ -47,7 +49,7 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
4749

4850
@end
4951

50-
void PairingCommandBridge::SetUpDeviceControllerDelegate()
52+
void PairingCommandBridge::SetUpDeviceControllerDelegate(NSError * __autoreleasing * error)
5153
{
5254
CHIPToolDeviceControllerDelegate * deviceControllerDelegate = [[CHIPToolDeviceControllerDelegate alloc] init];
5355
[deviceControllerDelegate setCommandBridge:this];
@@ -85,6 +87,8 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
8587
params.countryCode = [NSString stringWithUTF8String:mCountryCode.Value()];
8688
}
8789

90+
MaybeDisplayTermsAndConditions(params, error);
91+
VerifyOrReturn(*error == nil);
8892
[deviceControllerDelegate setParams:params];
8993
}
9094

@@ -94,6 +98,39 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
9498
[commissioner setDeviceControllerDelegate:deviceControllerDelegate queue:callbackQueue];
9599
}
96100

101+
void PairingCommandBridge::MaybeDisplayTermsAndConditions(MTRCommissioningParameters * params, NSError * __autoreleasing * error)
102+
{
103+
VerifyOrReturn(mUseDCL.ValueOr(false));
104+
105+
Json::Value tc;
106+
auto client = tool::dcl::DCLClient(mDCLHostName, mDCLPort);
107+
CHIP_ERROR err = client.TermsAndConditions(mOnboardingPayload, tc);
108+
109+
if (CHIP_NO_ERROR != err) {
110+
auto errorString = [NSString stringWithFormat:@"Error retrieving terms and conditions."];
111+
*error = [[NSError alloc] initWithDomain:@"PairingDomain"
112+
code:MTRErrorCodeGeneralError
113+
userInfo:@ { NSLocalizedDescriptionKey : NSLocalizedString(errorString, nil) }];
114+
return;
115+
}
116+
117+
if (tc != Json::nullValue) {
118+
uint16_t version = 0;
119+
uint16_t userResponse = 0;
120+
err = tool::dcl::DisplayTermsAndConditions(tc, version, userResponse, mCountryCode);
121+
if (CHIP_NO_ERROR != err) {
122+
auto errorString = [NSString stringWithFormat:@"Error displaying terms and conditions."];
123+
*error = [[NSError alloc] initWithDomain:@"PairingDomain"
124+
code:MTRErrorCodeGeneralError
125+
userInfo:@ { NSLocalizedDescriptionKey : NSLocalizedString(errorString, nil) }];
126+
return;
127+
}
128+
129+
params.acceptedTermsAndConditions = @(userResponse);
130+
params.acceptedTermsAndConditionsVersion = @(version);
131+
}
132+
}
133+
97134
CHIP_ERROR PairingCommandBridge::RunCommand()
98135
{
99136
NSError * error;
@@ -120,17 +157,20 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
120157

121158
void PairingCommandBridge::PairWithCode(NSError * __autoreleasing * error)
122159
{
123-
SetUpDeviceControllerDelegate();
160+
SetUpDeviceControllerDelegate(error);
161+
VerifyOrReturn(*error == nil);
162+
124163
auto * payload = [[MTRSetupPayload alloc] initWithSetupPasscode:@(mSetupPINCode) discriminator:@(mDiscriminator)];
125164
MTRDeviceController * commissioner = CurrentCommissioner();
126165
[commissioner setupCommissioningSessionWithPayload:payload newNodeID:@(mNodeId) error:error];
127166
}
128167

129168
void PairingCommandBridge::PairWithIndex(NSError * __autoreleasing * error)
130169
{
131-
SetUpDeviceControllerDelegate();
132-
MTRDeviceController * commissioner = CurrentCommissioner();
170+
SetUpDeviceControllerDelegate(error);
171+
VerifyOrReturn(*error == nil);
133172

173+
MTRDeviceController * commissioner = CurrentCommissioner();
134174
if (mIndex >= [gDiscoveredDevices count]) {
135175
auto errorString = [NSString stringWithFormat:@"Error retrieving discovered device at index %@", @(mIndex)];
136176
*error = [[NSError alloc] initWithDomain:@"PairingDomain"
@@ -152,7 +192,9 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
152192
void PairingCommandBridge::PairWithPayload(NSError * __autoreleasing * error)
153193
{
154194
NSString * onboardingPayload = [NSString stringWithUTF8String:mOnboardingPayload];
155-
SetUpDeviceControllerDelegate();
195+
SetUpDeviceControllerDelegate(error);
196+
VerifyOrReturn(*error == nil);
197+
156198
auto * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:onboardingPayload error:error];
157199
if (payload == nil) {
158200
return;

examples/darwin-framework-tool/main.mm

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "commands/bdx/Commands.h"
2525
#include "commands/common/Commands.h"
2626
#include "commands/configuration/Commands.h"
27+
#include "commands/dcl/Commands.h"
2728
#include "commands/delay/Commands.h"
2829
#include "commands/discover/Commands.h"
2930
#include "commands/interactive/Commands.h"
@@ -44,6 +45,7 @@ int main(int argc, const char * argv[])
4445
Commands commands;
4546
registerCommandsBdx(commands);
4647
registerCommandsPairing(commands);
48+
registerCommandsDCL(commands);
4749
registerCommandsDelay(commands);
4850
registerCommandsDiscover(commands);
4951
registerCommandsInteractive(commands);

src/darwin/Framework/CHIP/MTRCommissioningParameters.h

+11
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
102102
*/
103103
@property (nonatomic, assign) BOOL readEndpointInformation MTR_AVAILABLE(ios(18.4), macos(15.4), watchos(11.4), tvos(18.4));
104104

105+
/**
106+
* A bitmask of the user’s responses to the presented terms and conditions.
107+
* Each bit corresponds to a term’s acceptance (1) or non-acceptance (0) at the matching index.
108+
*/
109+
@property (nonatomic, copy, nullable) NSNumber * acceptedTermsAndConditions MTR_PROVISIONALLY_AVAILABLE;
110+
111+
/**
112+
* The version of the terms and conditions that the user has accepted.
113+
*/
114+
@property (nonatomic, copy, nullable) NSNumber * acceptedTermsAndConditionsVersion MTR_PROVISIONALLY_AVAILABLE;
115+
105116
@end
106117

107118
@interface MTRCommissioningParameters (Deprecated)

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm

+19
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,25 @@ - (BOOL)commissionNodeWithID:(NSNumber *)nodeID
973973
if (commissioningParams.threadOperationalDataset) {
974974
params.SetThreadOperationalDataset(AsByteSpan(commissioningParams.threadOperationalDataset));
975975
}
976+
if (commissioningParams.acceptedTermsAndConditions && commissioningParams.acceptedTermsAndConditionsVersion) {
977+
if (!chip::CanCastTo<uint16_t>([commissioningParams.acceptedTermsAndConditions unsignedIntValue])) {
978+
MTR_LOG_ERROR("%@ Error: acceptedTermsAndConditions value should be between 0 and 65535", self);
979+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_INTEGER_VALUE];
980+
return NO;
981+
}
982+
983+
if (!chip::CanCastTo<uint16_t>([commissioningParams.acceptedTermsAndConditionsVersion unsignedIntValue])) {
984+
MTR_LOG_ERROR("%@ Error: acceptedTermsAndConditionsVersion value should be between 0 and 65535", self);
985+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_INTEGER_VALUE];
986+
return NO;
987+
}
988+
989+
chip::Controller::TermsAndConditionsAcknowledgement termsAndConditionsAcknowledgement = {
990+
.acceptedTermsAndConditions = static_cast<uint16_t>([commissioningParams.acceptedTermsAndConditions unsignedIntValue]),
991+
.acceptedTermsAndConditionsVersion = static_cast<uint16_t>([commissioningParams.acceptedTermsAndConditionsVersion unsignedIntValue])
992+
};
993+
params.SetTermsAndConditionsAcknowledgement(termsAndConditionsAcknowledgement);
994+
}
976995
params.SetSkipCommissioningComplete(commissioningParams.skipCommissioningComplete);
977996
if (commissioningParams.wifiSSID) {
978997
chip::ByteSpan ssid = AsByteSpan(commissioningParams.wifiSSID);

src/darwin/Framework/Matter.xcodeproj/project.pbxproj

+24
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@
455455
CF3B63D12CA31E71003C1C87 /* MTROTAImageTransferHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = CF3B63CD2CA31E71003C1C87 /* MTROTAImageTransferHandler.mm */; };
456456
CF3B63D22CA31E71003C1C87 /* MTROTAUnsolicitedBDXMessageHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = CF3B63CE2CA31E71003C1C87 /* MTROTAUnsolicitedBDXMessageHandler.mm */; };
457457
D4288E872C8A273F002FEC53 /* MTRDevice_XPC_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = D4288E862C8A273F002FEC53 /* MTRDevice_XPC_Internal.h */; };
458+
B4D67A922D527F4A00C49965 /* DCLClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B4D67A8E2D527F4A00C49965 /* DCLClient.cpp */; };
459+
B4D67A932D527F4A00C49965 /* DisplayTermsAndConditions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B4D67A8F2D527F4A00C49965 /* DisplayTermsAndConditions.cpp */; };
460+
B4D67A952D527F4A00C49965 /* JsonSchemaMacros.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B4D67A912D527F4A00C49965 /* JsonSchemaMacros.cpp */; };
461+
B4D67A9B2D538E9700C49965 /* HTTPSRequest.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4D67A992D538E9700C49965 /* HTTPSRequest.mm */; };
458462
D444F9A72C6E8F9D007761E5 /* MTRXPCServerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D444F9A62C6E8F9D007761E5 /* MTRXPCServerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
459463
D444F9AA2C6E9A08007761E5 /* MTRXPCClientProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D444F9A82C6E99CA007761E5 /* MTRXPCClientProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
460464
D4772A46285AE98400383630 /* MTRClusterConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = D4772A45285AE98300383630 /* MTRClusterConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -963,6 +967,10 @@
963967
CF3B63CD2CA31E71003C1C87 /* MTROTAImageTransferHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTROTAImageTransferHandler.mm; sourceTree = "<group>"; };
964968
CF3B63CE2CA31E71003C1C87 /* MTROTAUnsolicitedBDXMessageHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTROTAUnsolicitedBDXMessageHandler.mm; sourceTree = "<group>"; };
965969
D4288E862C8A273F002FEC53 /* MTRDevice_XPC_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTRDevice_XPC_Internal.h; sourceTree = "<group>"; };
970+
B4D67A8E2D527F4A00C49965 /* DCLClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DCLClient.cpp; path = commands/dcl/DCLClient.cpp; sourceTree = "<group>"; };
971+
B4D67A8F2D527F4A00C49965 /* DisplayTermsAndConditions.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayTermsAndConditions.cpp; path = commands/dcl/DisplayTermsAndConditions.cpp; sourceTree = "<group>"; };
972+
B4D67A912D527F4A00C49965 /* JsonSchemaMacros.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JsonSchemaMacros.cpp; path = commands/dcl/JsonSchemaMacros.cpp; sourceTree = "<group>"; };
973+
B4D67A992D538E9700C49965 /* HTTPSRequest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = HTTPSRequest.mm; sourceTree = "<group>"; };
966974
D437613E285BDC0D0051FEA2 /* MTRErrorTestUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRErrorTestUtils.h; sourceTree = "<group>"; };
967975
D437613F285BDC0D0051FEA2 /* MTRTestKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRTestKeys.h; sourceTree = "<group>"; };
968976
D4376140285BDC0D0051FEA2 /* MTRTestStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRTestStorage.h; sourceTree = "<group>"; };
@@ -1031,6 +1039,7 @@
10311039
037C3D7B2991BD4F00B7EEE2 /* commands */ = {
10321040
isa = PBXGroup;
10331041
children = (
1042+
B4D67A9A2D538E9700C49965 /* dcl */,
10341043
B43B39E92CB859A5006AA284 /* memory */,
10351044
5124311D2BA0C09A000BC136 /* configuration */,
10361045
B4FCD56C2B603A6300832859 /* bdx */,
@@ -1157,6 +1166,9 @@
11571166
039546872991C400006D42A8 /* chip-tool */ = {
11581167
isa = PBXGroup;
11591168
children = (
1169+
B4D67A8E2D527F4A00C49965 /* DCLClient.cpp */,
1170+
B4D67A8F2D527F4A00C49965 /* DisplayTermsAndConditions.cpp */,
1171+
B4D67A912D527F4A00C49965 /* JsonSchemaMacros.cpp */,
11601172
0382FA2F2992F40C00247BBB /* ComplexArgumentParser.cpp */,
11611173
0382FA2B2992F06C00247BBB /* Commands.cpp */,
11621174
0382FA292992F05E00247BBB /* Command.cpp */,
@@ -1760,6 +1772,14 @@
17601772
path = "../common/websocket-server";
17611773
sourceTree = "<group>";
17621774
};
1775+
B4D67A9A2D538E9700C49965 /* dcl */ = {
1776+
isa = PBXGroup;
1777+
children = (
1778+
B4D67A992D538E9700C49965 /* HTTPSRequest.mm */,
1779+
);
1780+
path = dcl;
1781+
sourceTree = "<group>";
1782+
};
17631783
B4E262182AA0CFFE00DBA5BC /* delay */ = {
17641784
isa = PBXGroup;
17651785
children = (
@@ -2198,9 +2218,13 @@
21982218
B45373D22A9FEB0C00807602 /* buflist.c in Sources */,
21992219
7592BCFB2CBEE98C00EB74A0 /* CodegenDataModelProvider_Read.cpp in Sources */,
22002220
7592BCFC2CBEE98C00EB74A0 /* Instance.cpp in Sources */,
2221+
B4D67A9B2D538E9700C49965 /* HTTPSRequest.mm in Sources */,
22012222
7592BCFD2CBEE98C00EB74A0 /* EmberMetadata.cpp in Sources */,
22022223
7592BCFE2CBEE98C00EB74A0 /* CodegenDataModelProvider.cpp in Sources */,
22032224
7592BCFF2CBEE98C00EB74A0 /* CodegenDataModelProvider_Write.cpp in Sources */,
2225+
B4D67A922D527F4A00C49965 /* DCLClient.cpp in Sources */,
2226+
B4D67A932D527F4A00C49965 /* DisplayTermsAndConditions.cpp in Sources */,
2227+
B4D67A952D527F4A00C49965 /* JsonSchemaMacros.cpp in Sources */,
22042228
B45373C12A9FEA9100807602 /* close.c in Sources */,
22052229
B45373D42A9FEB0C00807602 /* context.c in Sources */,
22062230
B45373E52A9FEBA400807602 /* date.c in Sources */,

0 commit comments

Comments
 (0)