Skip to content

Commit

Permalink
Setup controller by storage fabric, without providing NOC chain
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Feb 21, 2024
1 parent acedec1 commit b992f51
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,24 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params)
mDNSResolver.SetCommissioningDelegate(this);
RegisterDeviceDiscoveryDelegate(params.deviceDiscoveryDelegate);

VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mOperationalCredentialsDelegate = params.operationalCredentialsDelegate;

mVendorId = params.controllerVendorId;
if (params.operationalKeypair != nullptr || !params.controllerNOC.empty() || !params.controllerRCAC.empty())
{
ReturnErrorOnFailure(InitControllerNOCChain(params));
}
else if (params.storageFabricIndex.HasValue())
{
VerifyOrReturnError(params.systemState->Fabrics()->FabricCount() > 0, CHIP_ERROR_INVALID_ARGUMENT);
if (params.systemState->Fabrics()->FindFabricWithIndex(params.storageFabricIndex.Value()) != nullptr)
{
mFabricIndex = params.storageFabricIndex.Value();
}
else
{
ChipLogError(Controller, "There is no fabric corresponding to the storageFabricIndex");
return CHIP_ERROR_INVALID_ARGUMENT;
}
}

mSystemState = params.systemState->Retain();
mState = State::Initialized;
Expand Down Expand Up @@ -408,6 +418,8 @@ DeviceCommissioner::DeviceCommissioner() :

CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params)
{
VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mOperationalCredentialsDelegate = params.operationalCredentialsDelegate;
ReturnErrorOnFailure(DeviceController::Init(params));

mPairingDelegate = params.pairingDelegate;
Expand Down
16 changes: 16 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ struct ControllerInitParams
*/
bool removeFromFabricTableOnShutdown = true;

/**
* Specifies whether to utilize a storage fabric for initializing the DeviceController.
* If enabled and neither the operational key pair nor the NOC chain are provided, then
* attempt to locate a storage fabric corresponding to the provided storageFabricIndex.
*/
chip::Optional<FabricIndex> storageFabricIndex;

chip::VendorId controllerVendorId;
};

Expand Down Expand Up @@ -356,6 +363,15 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
*/
CHIP_ERROR InitControllerNOCChain(const ControllerInitParams & params);

/**
* @brief Update the operational credentials after DeviceController Init.
*/
CHIP_ERROR UpdateControllerNOCChain(ControllerInitParams params)
{
params.systemState = mSystemState;
return InitControllerNOCChain(params);
}

protected:
enum class State
{
Expand Down
4 changes: 4 additions & 0 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ void DeviceControllerFactory::PopulateInitParams(ControllerInitParams & controll
controllerParams.controllerVendorId = params.controllerVendorId;

controllerParams.enableServerInteractions = params.enableServerInteractions;
if (params.storageFabricIndex.HasValue())
{
controllerParams.storageFabricIndex.SetValue(params.storageFabricIndex.Value());
}
}

void DeviceControllerFactory::ControllerInitialized(const DeviceController & controller)
Expand Down
7 changes: 7 additions & 0 deletions src/controller/CHIPDeviceControllerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ struct SetupParams
*/
bool removeFromFabricTableOnShutdown = true;

/**
* Specifies whether to utilize a storage fabric for initializing the DeviceController.
* If enabled and neither the operational key pair nor the NOC chain are provided, then
* attempt to locate a storage fabric corresponding to the provided storageFabricIndex.
*/
chip::Optional<FabricIndex> storageFabricIndex;

Credentials::DeviceAttestationVerifier * deviceAttestationVerifier = nullptr;
CommissioningDelegate * defaultCommissioner = nullptr;
};
Expand Down

0 comments on commit b992f51

Please sign in to comment.