@@ -56,12 +56,12 @@ void DeviceManager::Init()
56
56
NodeId DeviceManager::GetNextAvailableNodeId ()
57
57
{
58
58
mLastUsedNodeId ++;
59
- VerifyOrDieWithMsg (mLastUsedNodeId < std::numeric_limits<chip:: NodeId>::max (), NotSpecified, " No more available NodeIds." );
59
+ VerifyOrDieWithMsg (mLastUsedNodeId < std::numeric_limits<NodeId>::max (), NotSpecified, " No more available NodeIds." );
60
60
61
61
return mLastUsedNodeId ;
62
62
}
63
63
64
- void DeviceManager::UpdateLastUsedNodeId (chip:: NodeId nodeId)
64
+ void DeviceManager::UpdateLastUsedNodeId (NodeId nodeId)
65
65
{
66
66
if (nodeId > mLastUsedNodeId )
67
67
{
@@ -159,7 +159,7 @@ void DeviceManager::PairRemoteFabricBridge(NodeId nodeId, const char * deviceRem
159
159
PushCommand (commandBuilder.c_str ());
160
160
}
161
161
162
- void DeviceManager::PairRemoteDevice (chip:: NodeId nodeId, const char * payload)
162
+ void DeviceManager::PairRemoteDevice (NodeId nodeId, const char * payload)
163
163
{
164
164
StringBuilder<kMaxCommandSize > commandBuilder;
165
165
@@ -238,7 +238,7 @@ void DeviceManager::ReadSupportedDeviceCategories()
238
238
PushCommand (commandBuilder.c_str ());
239
239
}
240
240
241
- void DeviceManager::StartReverseCommissioning ()
241
+ void DeviceManager::RequestCommissioningApproval ()
242
242
{
243
243
ChipLogProgress (NotSpecified, " Starting reverse commissioning for bridge device: NodeId: " ChipLogFormatX64,
244
244
ChipLogValueX64 (mRemoteBridgeNodeId ));
@@ -255,7 +255,36 @@ void DeviceManager::StartReverseCommissioning()
255
255
PushCommand (commandBuilder.c_str ());
256
256
}
257
257
258
- void DeviceManager::CommissionApprovedRequest (uint64_t requestId, uint16_t responseTimeoutSeconds)
258
+ void DeviceManager::HandleCommissioningRequestResult (TLV::TLVReader * data)
259
+ {
260
+ ChipLogProgress (NotSpecified, " CommissioningRequestResult event received." );
261
+
262
+ CommissionerControl::Events::CommissioningRequestResult::DecodableType value;
263
+ CHIP_ERROR error = app::DataModel::Decode (*data, value);
264
+ if (error != CHIP_NO_ERROR)
265
+ {
266
+ ChipLogError (NotSpecified, " Failed to decode event value. Error: %" CHIP_ERROR_FORMAT, error.Format ());
267
+ return ;
268
+ }
269
+
270
+ if (value.requestId != mRequestId )
271
+ {
272
+ ChipLogError (NotSpecified, " The RequestId does not match the RequestId provided to RequestCommissioningApproval" );
273
+ return ;
274
+ }
275
+
276
+ if (value.statusCode != static_cast <uint8_t >(Protocols::InteractionModel::Status::Success))
277
+ {
278
+ ChipLogError (NotSpecified, " The server is not ready to begin commissioning the requested device" );
279
+ return ;
280
+ }
281
+
282
+ // The server is ready to begin commissioning the requested device, request the Commissioner Control Server to begin
283
+ // commissioning a previously approved request.
284
+ SendCommissionNodeRequest (value.requestId , kResponseTimeoutSeconds );
285
+ }
286
+
287
+ void DeviceManager::SendCommissionNodeRequest (uint64_t requestId, uint16_t responseTimeoutSeconds)
259
288
{
260
289
ChipLogProgress (NotSpecified, " Request the Commissioner Control Server to begin commissioning a previously approved request." );
261
290
@@ -266,6 +295,35 @@ void DeviceManager::CommissionApprovedRequest(uint64_t requestId, uint16_t respo
266
295
PushCommand (commandBuilder.c_str ());
267
296
}
268
297
298
+ void DeviceManager::HandleReverseOpenCommissioningWindow (TLV::TLVReader * data)
299
+ {
300
+ CommissionerControl::Commands::ReverseOpenCommissioningWindow::DecodableType value;
301
+ CHIP_ERROR error = app::DataModel::Decode (*data, value);
302
+ if (error != CHIP_NO_ERROR)
303
+ {
304
+ ChipLogError (NotSpecified, " Failed to decode command response value. Error: %" CHIP_ERROR_FORMAT, error.Format ());
305
+ return ;
306
+ }
307
+
308
+ // Log all fields
309
+ ChipLogProgress (NotSpecified, " DecodableType fields:" );
310
+ ChipLogProgress (NotSpecified, " commissioningTimeout: %u" , value.commissioningTimeout );
311
+ ChipLogProgress (NotSpecified, " discriminator: %u" , value.discriminator );
312
+ ChipLogProgress (NotSpecified, " iterations: %u" , value.iterations );
313
+
314
+ char verifierHex[Crypto::kSpake2p_VerifierSerialized_Length * 2 + 1 ];
315
+ Encoding::BytesToHex (value.PAKEPasscodeVerifier .data (), value.PAKEPasscodeVerifier .size (), verifierHex, sizeof (verifierHex),
316
+ Encoding::HexFlags::kNullTerminate );
317
+ ChipLogProgress (NotSpecified, " PAKEPasscodeVerifier: %s" , verifierHex);
318
+
319
+ char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1 ];
320
+ Encoding::BytesToHex (value.salt .data (), value.salt .size (), saltHex, sizeof (saltHex), Encoding::HexFlags::kNullTerminate );
321
+ ChipLogProgress (NotSpecified, " salt: %s" , saltHex);
322
+
323
+ OpenDeviceCommissioningWindow (mLocalBridgeNodeId , value.commissioningTimeout , value.iterations , value.discriminator , saltHex,
324
+ verifierHex);
325
+ }
326
+
269
327
void DeviceManager::HandleAttributeData (const app::ConcreteDataAttributePath & path, TLV::TLVReader * data)
270
328
{
271
329
if (path.mClusterId == CommissionerControl::Id &&
@@ -284,7 +342,7 @@ void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & p
284
342
if (value.Has (CommissionerControl::SupportedDeviceCategoryBitmap::kFabricSynchronization ))
285
343
{
286
344
ChipLogProgress (NotSpecified, " Remote Fabric-Bridge supports Fabric Synchronization, start reverse commissioning." );
287
- StartReverseCommissioning ();
345
+ RequestCommissioningApproval ();
288
346
}
289
347
290
348
return ;
@@ -399,39 +457,24 @@ void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & p
399
457
}
400
458
}
401
459
402
- void DeviceManager::HandleEventData (const chip:: app::EventHeader & header, chip:: TLV::TLVReader * data)
460
+ void DeviceManager::HandleEventData (const app::EventHeader & header, TLV::TLVReader * data)
403
461
{
404
- if (header.mPath .mClusterId != CommissionerControl::Id ||
405
- header.mPath .mEventId != CommissionerControl::Events::CommissioningRequestResult::Id)
406
- {
407
- return ;
408
- }
409
-
410
- ChipLogProgress (NotSpecified, " CommissioningRequestResult event received." );
411
-
412
- CommissionerControl::Events::CommissioningRequestResult::DecodableType value;
413
- CHIP_ERROR error = app::DataModel::Decode (*data, value);
414
- if (error != CHIP_NO_ERROR)
462
+ if (header.mPath .mClusterId == CommissionerControl::Id &&
463
+ header.mPath .mEventId == CommissionerControl::Events::CommissioningRequestResult::Id)
415
464
{
416
- ChipLogError (NotSpecified, " Failed to decode event value. Error: %" CHIP_ERROR_FORMAT, error.Format ());
417
- return ;
465
+ HandleCommissioningRequestResult (data);
418
466
}
467
+ }
419
468
420
- if (value.requestId != mRequestId )
421
- {
422
- ChipLogError (NotSpecified, " The RequestId does not match the RequestId provided to RequestCommissioningApproval" );
423
- return ;
424
- }
469
+ void DeviceManager::HandleCommandResponse (const app::ConcreteCommandPath & path, TLV::TLVReader * data)
470
+ {
471
+ ChipLogProgress (NotSpecified, " Command Response received." );
425
472
426
- if (value.statusCode != static_cast <uint8_t >(Protocols::InteractionModel::Status::Success))
473
+ if (path.mClusterId == CommissionerControl::Id &&
474
+ path.mCommandId == CommissionerControl::Commands::ReverseOpenCommissioningWindow::Id)
427
475
{
428
- ChipLogError (NotSpecified, " The server is not ready to begin commissioning the requested device" );
429
- return ;
476
+ HandleReverseOpenCommissioningWindow (data);
430
477
}
431
-
432
- // The server is ready to begin commissioning the requested device, request the Commissioner Control Server to begin
433
- // commissioning a previously approved request.
434
- CommissionApprovedRequest (value.requestId , kResponseTimeoutSeconds );
435
478
}
436
479
437
480
void DeviceManager::OnDeviceRemoved (NodeId deviceId, CHIP_ERROR err)
0 commit comments