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 18, 2024
1 parent acedec1 commit e1cb7fa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,22 @@ 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.enableUseStorageFabric && params.useStorageFabricIndex != kUndefinedFabricIndex)
{
VerifyOrReturnError(params.systemState->Fabrics()->FabricCount() >= kMinValidFabricIndex, CHIP_ERROR_INVALID_ARGUMENT);
const FabricInfo * fabricInfo = nullptr;
fabricInfo = params.systemState->Fabrics()->FindFabricWithIndex(params.useStorageFabricIndex);
if (fabricInfo != nullptr)
{
// ensure the fabric is existed
mFabricIndex = fabricInfo->GetFabricIndex();
}
}

mSystemState = params.systemState->Retain();
mState = State::Initialized;
Expand Down Expand Up @@ -408,6 +416,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
23 changes: 23 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ struct ControllerInitParams
*/
bool removeFromFabricTableOnShutdown = true;

/**
* Controls whether use the storage fabric table. If operational key pair
* or NOC chain are not passed, the fabric index are not available even if
* there is a fabric in storage. This provides a way to SetupController when
* the device has NOC installed and reboots, by providing a storage fabric
* index instead of operational key pair and NOC chain.
*/
bool enableUseStorageFabric = false;

/**
* Use a storage fabric index to find the fabric table.
*/
FabricIndex useStorageFabricIndex = kUndefinedFabricIndex;

chip::VendorId controllerVendorId;
};

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

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

protected:
enum class State
{
Expand Down
14 changes: 14 additions & 0 deletions src/controller/CHIPDeviceControllerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ struct SetupParams
*/
bool removeFromFabricTableOnShutdown = true;

/**
* Controls whether use the storage fabric table. If operational key pair
* or NOC chain are not passed, the fabric index are not available even if
* there is a fabric in storage. This provides a way to SetupController when
* the device has NOC installed and reboots, by providing a storage fabric
* index instead of operational key pair and NOC chain.
*/
bool enableUseStorageFabric = false;

/**
* Use a storage fabric index to find the fabric table.
*/
FabricIndex useStorageFabricIndex = kUndefinedFabricIndex;

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

0 comments on commit e1cb7fa

Please sign in to comment.