31
31
#include " TraceHandlers.h"
32
32
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
33
33
34
- std::map<std::string , std::unique_ptr<chip::Controller::DeviceCommissioner>> CHIPCommand::mCommissioners ;
34
+ std::map<CHIPCommand::CommissionerIdentity , std::unique_ptr<chip::Controller::DeviceCommissioner>> CHIPCommand::mCommissioners ;
35
35
std::set<CHIPCommand *> CHIPCommand::sDeferredCleanups ;
36
36
37
37
using DeviceControllerFactory = chip::Controller::DeviceControllerFactory;
@@ -125,7 +125,8 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
125
125
126
126
ReturnErrorOnFailure (GetAttestationTrustStore (mPaaTrustStorePath .ValueOr (nullptr ), &sTrustStore ));
127
127
128
- ReturnLogErrorOnFailure (InitializeCommissioner (kIdentityNull , kIdentityNullFabricId ));
128
+ CommissionerIdentity nullIdentity{ kIdentityNull , chip::kUndefinedNodeId };
129
+ ReturnLogErrorOnFailure (InitializeCommissioner (nullIdentity, kIdentityNullFabricId ));
129
130
130
131
// After initializing first commissioner, add the additional CD certs once
131
132
{
@@ -176,7 +177,10 @@ void CHIPCommand::MaybeTearDownStack()
176
177
177
178
CHIP_ERROR CHIPCommand::EnsureCommissionerForIdentity (std::string identity)
178
179
{
179
- if (mCommissioners .find (identity) != mCommissioners .end ())
180
+ chip::NodeId nodeId;
181
+ ReturnErrorOnFailure (GetCommissionerNodeId (identity, &nodeId));
182
+ CommissionerIdentity lookupKey{ identity, nodeId };
183
+ if (mCommissioners .find (lookupKey) != mCommissioners .end ())
180
184
{
181
185
return CHIP_NO_ERROR;
182
186
}
@@ -205,7 +209,7 @@ CHIP_ERROR CHIPCommand::EnsureCommissionerForIdentity(std::string identity)
205
209
}
206
210
}
207
211
208
- return InitializeCommissioner (identity , fabricId);
212
+ return InitializeCommissioner (lookupKey , fabricId);
209
213
}
210
214
211
215
CHIP_ERROR CHIPCommand::Run ()
@@ -306,6 +310,27 @@ std::string CHIPCommand::GetIdentity()
306
310
return name;
307
311
}
308
312
313
+ CHIP_ERROR CHIPCommand::GetCommissionerNodeId (std::string identity, chip::NodeId * nodeId)
314
+ {
315
+ if (mCommissionerNodeId .HasValue ())
316
+ {
317
+ *nodeId = mCommissionerNodeId .Value ();
318
+ return CHIP_NO_ERROR;
319
+ }
320
+
321
+ if (identity == kIdentityNull )
322
+ {
323
+ *nodeId = chip::kUndefinedNodeId ;
324
+ return CHIP_NO_ERROR;
325
+ }
326
+
327
+ ReturnLogErrorOnFailure (mCommissionerStorage .Init (identity.c_str ()));
328
+
329
+ *nodeId = mCommissionerStorage .GetLocalNodeId ();
330
+
331
+ return CHIP_NO_ERROR;
332
+ }
333
+
309
334
chip::FabricId CHIPCommand::CurrentCommissionerId ()
310
335
{
311
336
chip::FabricId id;
@@ -348,17 +373,20 @@ chip::Controller::DeviceCommissioner & CHIPCommand::GetCommissioner(std::string
348
373
// identities.
349
374
VerifyOrDie (EnsureCommissionerForIdentity (identity) == CHIP_NO_ERROR);
350
375
351
- auto item = mCommissioners .find (identity);
376
+ chip::NodeId nodeId;
377
+ VerifyOrDie (GetCommissionerNodeId (identity, &nodeId) == CHIP_NO_ERROR);
378
+ CommissionerIdentity lookupKey{ identity, nodeId };
379
+ auto item = mCommissioners .find (lookupKey);
352
380
VerifyOrDie (item != mCommissioners .end ());
353
381
return *item->second ;
354
382
}
355
383
356
- void CHIPCommand::ShutdownCommissioner (std::string key)
384
+ void CHIPCommand::ShutdownCommissioner (const CommissionerIdentity & key)
357
385
{
358
386
mCommissioners [key].get ()->Shutdown ();
359
387
}
360
388
361
- CHIP_ERROR CHIPCommand::InitializeCommissioner (std::string key , chip::FabricId fabricId)
389
+ CHIP_ERROR CHIPCommand::InitializeCommissioner (const CommissionerIdentity & identity , chip::FabricId fabricId)
362
390
{
363
391
chip::Platform::ScopedMemoryBuffer<uint8_t > noc;
364
392
chip::Platform::ScopedMemoryBuffer<uint8_t > icac;
@@ -381,7 +409,7 @@ CHIP_ERROR CHIPCommand::InitializeCommissioner(std::string key, chip::FabricId f
381
409
// TODO - OpCreds should only be generated for pairing command
382
410
// store the credentials in persistent storage, and
383
411
// generate when not available in the storage.
384
- ReturnLogErrorOnFailure (mCommissionerStorage .Init (key .c_str ()));
412
+ ReturnLogErrorOnFailure (mCommissionerStorage .Init (identity. mName .c_str ()));
385
413
if (mUseMaxSizedCerts .HasValue ())
386
414
{
387
415
auto option = CredentialIssuerCommands::CredentialIssuerOptions::kMaximizeCertificateSizes ;
@@ -395,14 +423,15 @@ CHIP_ERROR CHIPCommand::InitializeCommissioner(std::string key, chip::FabricId f
395
423
chip::MutableByteSpan rcacSpan (rcac.Get (), chip::Controller::kMaxCHIPDERCertLength );
396
424
397
425
ReturnLogErrorOnFailure (ephemeralKey.Initialize ());
398
- chip::NodeId nodeId = mCommissionerNodeId .ValueOr (mCommissionerStorage .GetLocalNodeId ());
399
426
400
- ReturnLogErrorOnFailure (mCredIssuerCmds ->GenerateControllerNOCChain (
401
- nodeId, fabricId, mCommissionerStorage .GetCommissionerCATs (), ephemeralKey, rcacSpan, icacSpan, nocSpan));
402
- commissionerParams.operationalKeypair = &ephemeralKey;
403
- commissionerParams.controllerRCAC = rcacSpan;
404
- commissionerParams.controllerICAC = icacSpan;
405
- commissionerParams.controllerNOC = nocSpan;
427
+ ReturnLogErrorOnFailure (mCredIssuerCmds ->GenerateControllerNOCChain (identity.mLocalNodeId , fabricId,
428
+ mCommissionerStorage .GetCommissionerCATs (),
429
+ ephemeralKey, rcacSpan, icacSpan, nocSpan));
430
+ commissionerParams.operationalKeypair = &ephemeralKey;
431
+ commissionerParams.controllerRCAC = rcacSpan;
432
+ commissionerParams.controllerICAC = icacSpan;
433
+ commissionerParams.controllerNOC = nocSpan;
434
+ commissionerParams.permitMultiControllerFabrics = true ;
406
435
}
407
436
408
437
// TODO: Initialize IPK epoch key in ExampleOperationalCredentials issuer rather than relying on DefaultIpkValue
@@ -411,7 +440,7 @@ CHIP_ERROR CHIPCommand::InitializeCommissioner(std::string key, chip::FabricId f
411
440
412
441
ReturnLogErrorOnFailure (DeviceControllerFactory::GetInstance ().SetupCommissioner (commissionerParams, *(commissioner.get ())));
413
442
414
- if (key != kIdentityNull )
443
+ if (identity. mName != kIdentityNull )
415
444
{
416
445
// Initialize Group Data, including IPK
417
446
chip::FabricIndex fabricIndex = commissioner->GetFabricIndex ();
@@ -428,7 +457,7 @@ CHIP_ERROR CHIPCommand::InitializeCommissioner(std::string key, chip::FabricId f
428
457
chip::Credentials::SetSingleIpkEpochKey (&sGroupDataProvider , fabricIndex, defaultIpk, compressed_fabric_id_span));
429
458
}
430
459
431
- mCommissioners [key ] = std::move (commissioner);
460
+ mCommissioners [identity ] = std::move (commissioner);
432
461
433
462
return CHIP_NO_ERROR;
434
463
}
0 commit comments