diff --git a/examples/all-clusters-app/esp32/main/include/ShellCommands.h b/examples/all-clusters-app/esp32/main/include/ShellCommands.h index aea17cca138523..3e4e8536cee962 100644 --- a/examples/all-clusters-app/esp32/main/include/ShellCommands.h +++ b/examples/all-clusters-app/esp32/main/include/ShellCommands.h @@ -125,10 +125,10 @@ class CASECommands // Register the CASESession commands void Register(); - void SetFabricInfo(FabricInfo * fabricInfo) { mFabricInfo = fabricInfo; } + void SetFabricInfo(const FabricInfo * fabricInfo) { mFabricInfo = fabricInfo; } void SetNodeId(NodeId nodeId) { mNodeId = nodeId; } void SetOnConnecting(bool onConnecting) { mOnConnecting = onConnecting; } - FabricInfo * GetFabricInfo(void) { return mFabricInfo; } + const FabricInfo * GetFabricInfo(void) { return mFabricInfo; } NodeId GetNodeId(void) { return mNodeId; } bool GetOnConnecting(void) { return mOnConnecting; } @@ -167,7 +167,7 @@ class CASECommands return CHIP_ERROR_INCORRECT_STATE; } const FabricIndex fabricIndex = static_cast(strtoul(argv[0], nullptr, 10)); - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); if (fabricInfo == nullptr) { @@ -201,9 +201,9 @@ class CASECommands static Callback::Callback sOnConnectedCallback; static Callback::Callback sOnConnectionFailureCallback; static Shell::Engine sSubShell; - FabricInfo * mFabricInfo = nullptr; - NodeId mNodeId = 0; - bool mOnConnecting = false; + const FabricInfo * mFabricInfo = nullptr; + NodeId mNodeId = 0; + bool mOnConnecting = false; }; } // namespace Shell diff --git a/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h b/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h index aea17cca138523..3e4e8536cee962 100644 --- a/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h +++ b/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h @@ -125,10 +125,10 @@ class CASECommands // Register the CASESession commands void Register(); - void SetFabricInfo(FabricInfo * fabricInfo) { mFabricInfo = fabricInfo; } + void SetFabricInfo(const FabricInfo * fabricInfo) { mFabricInfo = fabricInfo; } void SetNodeId(NodeId nodeId) { mNodeId = nodeId; } void SetOnConnecting(bool onConnecting) { mOnConnecting = onConnecting; } - FabricInfo * GetFabricInfo(void) { return mFabricInfo; } + const FabricInfo * GetFabricInfo(void) { return mFabricInfo; } NodeId GetNodeId(void) { return mNodeId; } bool GetOnConnecting(void) { return mOnConnecting; } @@ -167,7 +167,7 @@ class CASECommands return CHIP_ERROR_INCORRECT_STATE; } const FabricIndex fabricIndex = static_cast(strtoul(argv[0], nullptr, 10)); - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); if (fabricInfo == nullptr) { @@ -201,9 +201,9 @@ class CASECommands static Callback::Callback sOnConnectedCallback; static Callback::Callback sOnConnectionFailureCallback; static Shell::Engine sSubShell; - FabricInfo * mFabricInfo = nullptr; - NodeId mNodeId = 0; - bool mOnConnecting = false; + const FabricInfo * mFabricInfo = nullptr; + NodeId mNodeId = 0; + bool mOnConnecting = false; }; } // namespace Shell diff --git a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp index 28658b9578c28b..41b5008fa5412c 100644 --- a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp +++ b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp @@ -247,9 +247,9 @@ void OTAProviderExample::SendQueryImageResponse(app::CommandHandler * commandObj // TODO: This uses the current node as the provider to supply the OTA image. This can be configurable such that the // provider supplying the response is not the provider supplying the OTA image. - FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex(); - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); - NodeId nodeId = fabricInfo->GetPeerId().GetNodeId(); + FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex(); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); + NodeId nodeId = fabricInfo->GetPeerId().GetNodeId(); // Generate the ImageURI if one is not already preset if (strlen(mImageUri) == 0) diff --git a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp index bacbcfe98d6464..2953c4ba2a91f1 100644 --- a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp +++ b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp @@ -48,7 +48,7 @@ CHIP_ERROR ModelCommand::RunCommand() } Server * server = &(chip::Server::GetInstance()); - chip::FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex); + const FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex); if (fabric == nullptr) { ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex); diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp index 4d49a6461799e2..9a08e65a13fabe 100644 --- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp @@ -33,7 +33,7 @@ CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIn } Server * server = &(chip::Server::GetInstance()); - chip::FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex); + const FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex); if (fabric == nullptr) { ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex); diff --git a/src/app/clusters/administrator-commissioning-server/administrator-commissioning-server.cpp b/src/app/clusters/administrator-commissioning-server/administrator-commissioning-server.cpp index 215c99218ea2fb..5ca4685427cec6 100644 --- a/src/app/clusters/administrator-commissioning-server/administrator-commissioning-server.cpp +++ b/src/app/clusters/administrator-commissioning-server/administrator-commissioning-server.cpp @@ -105,10 +105,10 @@ bool emberAfAdministratorCommissioningClusterOpenCommissioningWindowCallback( ChipLogProgress(Zcl, "Received command to open commissioning window"); - FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex(); - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); - auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); - auto & commissionMgr = Server::GetInstance().GetCommissioningWindowManager(); + FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex(); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); + auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); + auto & commissionMgr = Server::GetInstance().GetCommissioningWindowManager(); VerifyOrExit(fabricInfo != nullptr, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR)); VerifyOrExit(!failSafeContext.IsFailSafeArmed(), status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_BUSY)); @@ -167,10 +167,10 @@ bool emberAfAdministratorCommissioningClusterOpenBasicCommissioningWindowCallbac InteractionModel::Status globalStatus = InteractionModel::Status::Success; ChipLogProgress(Zcl, "Received command to open basic commissioning window"); - FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex(); - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); - auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); - auto & commissionMgr = Server::GetInstance().GetCommissioningWindowManager(); + FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex(); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); + auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); + auto & commissionMgr = Server::GetInstance().GetCommissioningWindowManager(); VerifyOrExit(fabricInfo != nullptr, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR)); diff --git a/src/app/clusters/bindings/BindingManager.cpp b/src/app/clusters/bindings/BindingManager.cpp index 022fe145a208a5..5e8415b08f4668 100644 --- a/src/app/clusters/bindings/BindingManager.cpp +++ b/src/app/clusters/bindings/BindingManager.cpp @@ -52,7 +52,7 @@ namespace { chip::PeerId PeerIdForNode(chip::FabricTable * fabricTable, chip::FabricIndex fabric, chip::NodeId node) { - chip::FabricInfo * fabricInfo = fabricTable->FindFabricWithIndex(fabric); + const chip::FabricInfo * fabricInfo = fabricTable->FindFabricWithIndex(fabric); if (fabricInfo == nullptr) { return chip::PeerId(); @@ -202,7 +202,7 @@ CHIP_ERROR BindingManager::NotifyBoundClusterChanged(EndpointId endpoint, Cluste { if (iter->type == EMBER_UNICAST_BINDING) { - FabricInfo * fabricInfo = mInitParams.mFabricTable->FindFabricWithIndex(iter->fabricIndex); + const FabricInfo * fabricInfo = mInitParams.mFabricTable->FindFabricWithIndex(iter->fabricIndex); VerifyOrReturnError(fabricInfo != nullptr, CHIP_ERROR_NOT_FOUND); PeerId peer = fabricInfo->GetPeerIdForNode(iter->nodeId); OperationalDeviceProxy * peerDevice = mInitParams.mCASESessionManager->FindExistingSession(peer); diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index d02a994e9b3498..71e4f83c0d2d90 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -247,7 +247,7 @@ CHIP_ERROR OperationalCredentialsAttrAccess::Read(const ConcreteReadAttributePat return CHIP_NO_ERROR; } -FabricInfo * RetrieveCurrentFabric(CommandHandler * aCommandHandler) +const FabricInfo * RetrieveCurrentFabric(CommandHandler * aCommandHandler) { FabricIndex index = aCommandHandler->GetAccessingFabricIndex(); ChipLogDetail(Zcl, "OpCreds: Finding fabric with fabricIndex 0x%x", static_cast(index)); @@ -285,7 +285,7 @@ void FailSafeCleanup(const chip::DeviceLayer::ChipDeviceEvent * event) CASESessionManager * caseSessionManager = Server::GetInstance().GetCASESessionManager(); if (caseSessionManager) { - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex); VerifyOrReturn(fabricInfo != nullptr); caseSessionManager->ReleaseSessionsForFabric(fabricInfo->GetFabricIndex()); @@ -492,7 +492,7 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(app::CommandH CHIP_ERROR err = CHIP_ERROR_INTERNAL; // Fetch current fabric - FabricInfo * fabric = RetrieveCurrentFabric(commandObj); + const FabricInfo * fabric = RetrieveCurrentFabric(commandObj); if (fabric == nullptr) { SendNOCResponse(commandObj, commandPath, OperationalCertStatus::kInsufficientPrivilege, ourFabricIndex, @@ -610,8 +610,8 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co CHIP_ERROR err = CHIP_NO_ERROR; FabricIndex newFabricIndex = kUndefinedFabricIndex; Credentials::GroupDataProvider::KeySet keyset; - FabricInfo * newFabricInfo = nullptr; - auto & fabricTable = Server::GetInstance().GetFabricTable(); + const FabricInfo * newFabricInfo = nullptr; + auto & fabricTable = Server::GetInstance().GetFabricTable(); auto * secureSession = commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession(); auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); @@ -784,9 +784,9 @@ bool emberAfOperationalCredentialsClusterUpdateNOCCallback(app::CommandHandler * ChipLogProgress(Zcl, "OpCreds: Received an UpdateNOC command"); - auto & fabricTable = Server::GetInstance().GetFabricTable(); - auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); - FabricInfo * fabricInfo = RetrieveCurrentFabric(commandObj); + auto & fabricTable = Server::GetInstance().GetFabricTable(); + auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); + const FabricInfo * fabricInfo = RetrieveCurrentFabric(commandObj); bool csrWasForUpdateNoc = false; //< Output param of HasPendingOperationalKey bool hasPendingKey = fabricTable.HasPendingOperationalKey(csrWasForUpdateNoc); @@ -1014,7 +1014,7 @@ bool emberAfOperationalCredentialsClusterCSRRequestCallback(app::CommandHandler commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession()->GetCryptoContext().GetAttestationChallenge(); failSafeContext.SetCsrRequestForUpdateNoc(isForUpdateNoc); - FabricInfo * fabricInfo = RetrieveCurrentFabric(commandObj); + const FabricInfo * fabricInfo = RetrieveCurrentFabric(commandObj); VerifyOrExit(CSRNonce.size() == Credentials::kExpectedAttestationNonceSize, finalStatus = Status::InvalidCommand); diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index b34d08c646e05f..27958a8d4ed88c 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -363,7 +363,7 @@ void DefaultOTARequestor::ConnectToProvider(OnConnectedAction onConnectedAction) return; } - FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex); + const FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex); if (fabricInfo == nullptr) { @@ -393,7 +393,7 @@ void DefaultOTARequestor::DisconnectFromProvider() return; } - FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex); + const FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex); if (fabricInfo == nullptr) { ChipLogError(SoftwareUpdate, "Cannot find fabric"); @@ -726,7 +726,7 @@ CHIP_ERROR DefaultOTARequestor::GenerateUpdateToken() VerifyOrReturnError(mServer != nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mProviderLocation.HasValue(), CHIP_ERROR_INCORRECT_STATE); - FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex); + const FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex); VerifyOrReturnError(fabricInfo != nullptr, CHIP_ERROR_INCORRECT_STATE); static_assert(sizeof(NodeId) == sizeof(uint64_t), "Unexpected NodeId size"); diff --git a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp index 5dff75ad84f79c..447096d34bf687 100644 --- a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp @@ -77,7 +77,7 @@ CHIP_ERROR ExtendedOTARequestorDriver::GetUserConsentSubject(chip::ota::UserCons return CHIP_ERROR_INTERNAL; } - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(subject.fabricIndex); + const FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(subject.fabricIndex); if (fabricInfo == nullptr) { ChipLogError(SoftwareUpdate, "Cannot find fabric"); diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 13eac3aedd8a56..7045dcad598381 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -370,7 +370,7 @@ class Server void OnGroupAdded(chip::FabricIndex fabric_index, const Credentials::GroupDataProvider::GroupInfo & new_group) override { - FabricInfo * fabric = mServer->GetFabricTable().FindFabricWithIndex(fabric_index); + const FabricInfo * fabric = mServer->GetFabricTable().FindFabricWithIndex(fabric_index); if (fabric == nullptr) { ChipLogError(AppServer, "Group added to nonexistent fabric?"); @@ -386,7 +386,7 @@ class Server void OnGroupRemoved(chip::FabricIndex fabric_index, const Credentials::GroupDataProvider::GroupInfo & old_group) override { - FabricInfo * fabric = mServer->GetFabricTable().FindFabricWithIndex(fabric_index); + const FabricInfo * fabric = mServer->GetFabricTable().FindFabricWithIndex(fabric_index); if (fabric == nullptr) { ChipLogError(AppServer, "Group added to nonexistent fabric?"); diff --git a/src/app/tests/TestOperationalDeviceProxy.cpp b/src/app/tests/TestOperationalDeviceProxy.cpp index ffdc2285c69a54..5d6f928fdc4d7d 100644 --- a/src/app/tests/TestOperationalDeviceProxy.cpp +++ b/src/app/tests/TestOperationalDeviceProxy.cpp @@ -51,8 +51,8 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite, System::LayerImpl systemLayer; // Heap-allocate the fairly large FabricTable so we don't end up with a huge // stack. - FabricTable * fabrics = Platform::New(); - FabricInfo * fabric = fabrics->FindFabricWithIndex(1); + FabricTable * fabrics = Platform::New(); + const FabricInfo * fabric = fabrics->FindFabricWithIndex(1); VerifyOrDie(fabric != nullptr); secure_channel::MessageCounterManager messageCounterManager; chip::TestPersistentStorageDelegate deviceStorage; diff --git a/src/credentials/FabricTable.cpp b/src/credentials/FabricTable.cpp index a91feb68bdcbfb..aba07b08e0a503 100644 --- a/src/credentials/FabricTable.cpp +++ b/src/credentials/FabricTable.cpp @@ -467,7 +467,7 @@ const FabricInfo * FabricTable::FindFabric(const Crypto::P256PublicKey & rootPub return nullptr; } -FabricInfo * FabricTable::FindFabricWithIndex(FabricIndex fabricIndex) +FabricInfo * FabricTable::GetMutableFabricByIndex(FabricIndex fabricIndex) { // Try to match pending fabric first if available if (HasPendingFabricUpdate() && (mPendingFabric.GetFabricIndex() == fabricIndex)) @@ -870,13 +870,13 @@ CHIP_ERROR FabricTable::Delete(FabricIndex fabricIndex) VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_ARGUMENT); - FabricInfo * fabricInfo = FindFabricWithIndex(fabricIndex); + FabricInfo * fabricInfo = GetMutableFabricByIndex(fabricIndex); if (fabricInfo == &mPendingFabric) { // Asked to Delete while pending an update: reset the pending state and // get back to the underlying fabric data for existing fabric. RevertPendingFabricData(); - fabricInfo = FindFabricWithIndex(fabricIndex); + fabricInfo = GetMutableFabricByIndex(fabricIndex); } bool fabricIsInitialized = fabricInfo != nullptr && fabricInfo->IsInitialized(); @@ -1053,7 +1053,7 @@ void FabricTable::Forget(FabricIndex fabricIndex) { ChipLogProgress(FabricProvisioning, "Forgetting fabric 0x%x", static_cast(fabricIndex)); - auto * fabricInfo = FindFabricWithIndex(fabricIndex); + auto * fabricInfo = GetMutableFabricByIndex(fabricIndex); VerifyOrReturn(fabricInfo != nullptr); RevertPendingFabricData(); @@ -1719,7 +1719,7 @@ CHIP_ERROR FabricTable::CommitPendingFabricData() } // Make sure we actually have a pending fabric - FabricInfo * pendingFabricEntry = FindFabricWithIndex(fabricIndexBeingCommitted); + FabricInfo * pendingFabricEntry = GetMutableFabricByIndex(fabricIndexBeingCommitted); if (isUpdating && hasPending && !hasInvalidInternalState) { @@ -1806,7 +1806,7 @@ CHIP_ERROR FabricTable::CommitPendingFabricData() if (isUpdating) { // This will get the non-pending fabric - FabricInfo * existingFabricToUpdate = FindFabricWithIndex(fabricIndexBeingCommitted); + FabricInfo * existingFabricToUpdate = GetMutableFabricByIndex(fabricIndexBeingCommitted); // Multiple interlocks validated the below, so it's fatal if we are somehow incoherent here VerifyOrDie((existingFabricToUpdate != nullptr) && (existingFabricToUpdate != &mPendingFabric)); @@ -1817,7 +1817,7 @@ CHIP_ERROR FabricTable::CommitPendingFabricData() } // Store pending metadata first - FabricInfo * liveFabricEntry = FindFabricWithIndex(fabricIndexBeingCommitted); + FabricInfo * liveFabricEntry = GetMutableFabricByIndex(fabricIndexBeingCommitted); VerifyOrDie(liveFabricEntry != nullptr); CHIP_ERROR metadataErr = StoreFabricMetadata(liveFabricEntry); @@ -1978,7 +1978,7 @@ CHIP_ERROR FabricTable::SetFabricLabel(FabricIndex fabricIndex, const CharSpan & ReturnErrorCodeIf(fabricLabel.size() > kFabricLabelMaxLengthInBytes, CHIP_ERROR_INVALID_ARGUMENT); - FabricInfo * fabricInfo = FindFabricWithIndex(fabricIndex); + FabricInfo * fabricInfo = GetMutableFabricByIndex(fabricIndex); bool fabricIsInitialized = (fabricInfo != nullptr) && fabricInfo->IsInitialized(); VerifyOrReturnError(fabricIsInitialized, CHIP_ERROR_INCORRECT_STATE); diff --git a/src/credentials/FabricTable.h b/src/credentials/FabricTable.h index b7cffb12dcf114..1fdca772cd5fad 100644 --- a/src/credentials/FabricTable.h +++ b/src/credentials/FabricTable.h @@ -400,22 +400,6 @@ class DLL_EXPORT FabricTable #endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST const FabricInfo * FindFabric(const Crypto::P256PublicKey & rootPubKey, FabricId fabricId) const; - - /** - * @brief Get a mutable FabricInfo entry from the table by FabricIndex. - * - * NOTE: This is private for use within the FabricTable itself. All mutations have to go through the - * FabricTable public methods that take a FabricIndex so that there are no mutations about which - * the FabricTable is unaware, since this would break expectations regarding shadow/pending - * entries used during fail-safe. - * - * TODO(#19929): Need to make this const and private, but can't just yet. - * - * @param fabricIndex - fabric index for which to get the FabricInfo entry/ - * @return the FabricInfo entry for the fabricIndex if found, or nullptr if not found - */ - FabricInfo * FindFabricWithIndex(FabricIndex fabricIndex); - const FabricInfo * FindFabricWithIndex(FabricIndex fabricIndex) const; const FabricInfo * FindFabricWithCompressedId(CompressedFabricId compressedFabricId) const; @@ -505,6 +489,19 @@ class DLL_EXPORT FabricTable ConstFabricIterator begin() const { return cbegin(); } ConstFabricIterator end() const { return cend(); } + /** + * @brief Get a mutable FabricInfo entry from the table by FabricIndex. + * + * NOTE: This is private for use within the FabricTable itself. All mutations have to go through the + * FabricTable public methods that take a FabricIndex so that there are no mutations about which + * the FabricTable is unaware, since this would break expectations regarding shadow/pending + * entries used during fail-safe. + * + * @param fabricIndex - fabric index for which to get a mutable FabricInfo entry + * @return the FabricInfo entry for the fabricIndex if found, or nullptr if not found + */ + FabricInfo * GetMutableFabricByIndex(FabricIndex fabricIndex); + /** * @brief Get the RCAC (operational root certificate) associated with a fabric. * diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.mm b/src/darwin/Framework/CHIP/CHIPDeviceController.mm index 3329baa644a6cc..ba2e4309fb35ce 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.mm +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.mm @@ -719,7 +719,7 @@ - (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable return CHIP_NO_ERROR; } - chip::FabricInfo * otherFabric = fabricTable->FindFabricWithIndex(fabricIndex); + const chip::FabricInfo * otherFabric = fabricTable->FindFabricWithIndex(fabricIndex); if (!otherFabric) { // Should not happen... return CHIP_ERROR_INCORRECT_STATE; diff --git a/src/darwin/Framework/CHIP/CHIPDeviceControllerStartupParams.mm b/src/darwin/Framework/CHIP/CHIPDeviceControllerStartupParams.mm index 76e5943e0aff68..8f3fbdbec3549a 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceControllerStartupParams.mm +++ b/src/darwin/Framework/CHIP/CHIPDeviceControllerStartupParams.mm @@ -204,7 +204,7 @@ - (instancetype)initForExistingFabric:(FabricTable *)fabricTable return nil; } - FabricInfo * fabric = fabricTable->FindFabricWithIndex(fabricIndex); + const FabricInfo * fabric = fabricTable->FindFabricWithIndex(fabricIndex); if (self.vendorId == nil) { self.vendorId = @(fabric->GetVendorId()); diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index 029d24307a8d2a..f886501d48c631 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -213,7 +213,7 @@ CHIP_ERROR InitCredentialSets() gCommissionerFabrics.AddNewFabricForTest(rcacSpan, icacSpan, nocSpan, opKeySpan, &gCommissionerFabricIndex)); } - FabricInfo * newFabric = gCommissionerFabrics.FindFabricWithIndex(gCommissionerFabricIndex); + const FabricInfo * newFabric = gCommissionerFabrics.FindFabricWithIndex(gCommissionerFabricIndex); VerifyOrReturnError(newFabric != nullptr, CHIP_ERROR_INTERNAL); ReturnErrorOnFailure(InitTestIpk(gCommissionerGroupDataProvider, *newFabric, /* numIpks= */ 1)); diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index a7933d64952113..8842c728b4c08e 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -152,7 +152,7 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P auto * groups = Credentials::GetGroupDataProvider(); VerifyOrReturnError(nullptr != groups, CHIP_ERROR_INTERNAL); - FabricInfo * fabric = mFabricTable->FindFabricWithIndex(groupSession->GetFabricIndex()); + const FabricInfo * fabric = mFabricTable->FindFabricWithIndex(groupSession->GetFabricIndex()); VerifyOrReturnError(fabric != nullptr, CHIP_ERROR_INVALID_ARGUMENT); packetHeader.SetDestinationGroupId(groupSession->GetGroupId()); @@ -277,7 +277,7 @@ CHIP_ERROR SessionManager::SendPreparedMessage(const SessionHandle & sessionHand case Transport::Session::SessionType::kGroupOutgoing: { auto groupSession = sessionHandle->AsOutgoingGroupSession(); - FabricInfo * fabric = mFabricTable->FindFabricWithIndex(groupSession->GetFabricIndex()); + const FabricInfo * fabric = mFabricTable->FindFabricWithIndex(groupSession->GetFabricIndex()); VerifyOrReturnError(fabric != nullptr, CHIP_ERROR_INVALID_ARGUMENT); multicastAddress = Transport::PeerAddress::Multicast(fabric->GetFabricId(), groupSession->GetGroupId());