diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 57c75cd0d813ae..2c5c99d87f22cf 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -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; @@ -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; diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index a7e6f6dac4bcb9..5a66535bdfa34a 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -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 storageFabricIndex; + chip::VendorId controllerVendorId; }; @@ -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 { diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index ebc728ca206875..d278b891f721ab 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -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) diff --git a/src/controller/CHIPDeviceControllerFactory.h b/src/controller/CHIPDeviceControllerFactory.h index 6b4aa77fdc00c8..7669375fd64a30 100644 --- a/src/controller/CHIPDeviceControllerFactory.h +++ b/src/controller/CHIPDeviceControllerFactory.h @@ -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 storageFabricIndex; + Credentials::DeviceAttestationVerifier * deviceAttestationVerifier = nullptr; CommissioningDelegate * defaultCommissioner = nullptr; };