22
22
#include " ../common/CertificateIssuer.h"
23
23
#include " DeviceControllerDelegateBridge.h"
24
24
#include " PairingCommandBridge.h"
25
+ #include < commands/dcl/DCLClient.h>
26
+ #include < commands/dcl/DisplayTermsAndConditions.h>
25
27
#include < lib/support/logging/CHIPLogging.h>
26
28
27
29
#import " MTRError_Utils.h"
@@ -47,7 +49,7 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
47
49
48
50
@end
49
51
50
- void PairingCommandBridge::SetUpDeviceControllerDelegate ()
52
+ void PairingCommandBridge::SetUpDeviceControllerDelegate (NSError * __autoreleasing * error )
51
53
{
52
54
CHIPToolDeviceControllerDelegate * deviceControllerDelegate = [[CHIPToolDeviceControllerDelegate alloc ] init ];
53
55
[deviceControllerDelegate setCommandBridge: this ];
@@ -85,6 +87,8 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
85
87
params.countryCode = [NSString stringWithUTF8String: mCountryCode .Value ()];
86
88
}
87
89
90
+ MaybeDisplayTermsAndConditions (params, error);
91
+ VerifyOrReturn (*error == nil );
88
92
[deviceControllerDelegate setParams: params];
89
93
}
90
94
@@ -94,6 +98,39 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
94
98
[commissioner setDeviceControllerDelegate: deviceControllerDelegate queue: callbackQueue];
95
99
}
96
100
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
+
97
134
CHIP_ERROR PairingCommandBridge::RunCommand ()
98
135
{
99
136
NSError * error;
@@ -120,17 +157,20 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
120
157
121
158
void PairingCommandBridge::PairWithCode (NSError * __autoreleasing * error)
122
159
{
123
- SetUpDeviceControllerDelegate ();
160
+ SetUpDeviceControllerDelegate (error);
161
+ VerifyOrReturn (*error == nil );
162
+
124
163
auto * payload = [[MTRSetupPayload alloc ] initWithSetupPasscode: @(mSetupPINCode ) discriminator: @(mDiscriminator )];
125
164
MTRDeviceController * commissioner = CurrentCommissioner ();
126
165
[commissioner setupCommissioningSessionWithPayload: payload newNodeID: @(mNodeId ) error: error];
127
166
}
128
167
129
168
void PairingCommandBridge::PairWithIndex (NSError * __autoreleasing * error)
130
169
{
131
- SetUpDeviceControllerDelegate ();
132
- MTRDeviceController * commissioner = CurrentCommissioner ( );
170
+ SetUpDeviceControllerDelegate (error );
171
+ VerifyOrReturn (*error == nil );
133
172
173
+ MTRDeviceController * commissioner = CurrentCommissioner ();
134
174
if (mIndex >= [gDiscoveredDevices count ]) {
135
175
auto errorString = [NSString stringWithFormat: @" Error retrieving discovered device at index %@ " , @(mIndex )];
136
176
*error = [[NSError alloc ] initWithDomain: @" PairingDomain"
@@ -152,7 +192,9 @@ - (void)deviceAttestationCompletedForController:(MTRDeviceController *)controlle
152
192
void PairingCommandBridge::PairWithPayload (NSError * __autoreleasing * error)
153
193
{
154
194
NSString * onboardingPayload = [NSString stringWithUTF8String: mOnboardingPayload ];
155
- SetUpDeviceControllerDelegate ();
195
+ SetUpDeviceControllerDelegate (error);
196
+ VerifyOrReturn (*error == nil );
197
+
156
198
auto * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload: onboardingPayload error: error];
157
199
if (payload == nil ) {
158
200
return ;
0 commit comments