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 2f7101c35bb26c..989c2431cbc145 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -262,39 +262,30 @@ FabricInfo * RetrieveCurrentFabric(CommandHandler * aCommandHandler) return Server::GetInstance().GetFabricTable().FindFabricWithIndex(index); } -void FailSafeCleanup(FailSafeContext & failSafeContext) +void FailSafeCleanup(const chip::DeviceLayer::ChipDeviceEvent * event) { - FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(failSafeContext.GetFabricIndex()); - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Call to FailSafeCleanup"); - VerifyOrReturn(fabricInfo != nullptr); - // If an AddNOC or UpdateNOC command has been successfully invoked, terminate all CASE sessions associated with the Fabric // whose Fabric Index is recorded in the Fail-Safe context (see ArmFailSafe Command) by clearing any associated Secure // Session Context at the Server. - if (failSafeContext.NocCommandHasBeenInvoked()) + if (event->CommissioningComplete.AddNocCommandHasBeenInvoked || event->CommissioningComplete.UpdateNocCommandHasBeenInvoked) { - CASESessionManager * caseSessionManager = Server::GetInstance().GetCASESessionManager(); - - if (caseSessionManager) - { - caseSessionManager->ReleaseSessionsForFabric(fabricInfo->GetCompressedId()); - } + Server::GetInstance().GetSecureSessionManager().ExpireAllPairingsForFabric(event->CommissioningComplete.PeerFabricIndex); } // If an AddNOC command had been successfully invoked, achieve the equivalent effect of invoking the RemoveFabric command // against the Fabric Index stored in the Fail-Safe Context for the Fabric Index that was the subject of the AddNOC // command. - if (failSafeContext.AddNocCommandHasBeenInvoked()) + if (event->CommissioningComplete.AddNocCommandHasBeenInvoked) { - Server::GetInstance().GetFabricTable().Delete(fabricInfo->GetFabricIndex()); + Server::GetInstance().GetFabricTable().Delete(event->CommissioningComplete.PeerFabricIndex); } // If an UpdateNOC command had been successfully invoked, revert the state of operational key pair, NOC and ICAC for that // Fabric to the state prior to the Fail-Safe timer being armed, for the Fabric Index that was the subject of the UpdateNOC // command. - if (failSafeContext.UpdateNocCommandHasBeenInvoked()) + if (event->CommissioningComplete.UpdateNocCommandHasBeenInvoked) { // TODO: Revert the state of operational key pair, NOC and ICAC } @@ -306,10 +297,7 @@ void OnPlatformEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, in { if (event->CommissioningComplete.Status != CHIP_NO_ERROR) { - FailSafeContext & failSafeContext = DeviceControlServer::DeviceControlSvr().GetFailSafeContext(); - - VerifyOrReturn(event->CommissioningComplete.PeerFabricIndex == failSafeContext.GetFabricIndex()); - FailSafeCleanup(failSafeContext); + FailSafeCleanup(event); } } } diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index b6431bc8b22e33..3a043d12ba61cc 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -444,6 +444,8 @@ struct ChipDeviceEvent final CHIP_ERROR Status; uint64_t PeerNodeId; FabricIndex PeerFabricIndex; + bool AddNocCommandHasBeenInvoked; + bool UpdateNocCommandHasBeenInvoked; } CommissioningComplete; struct diff --git a/src/platform/FailSafeContext.cpp b/src/platform/FailSafeContext.cpp index c13befbb6d39c6..14e0bb417db72f 100644 --- a/src/platform/FailSafeContext.cpp +++ b/src/platform/FailSafeContext.cpp @@ -35,14 +35,13 @@ void FailSafeContext::HandleArmFailSafe(System::Layer * layer, void * aAppState) void FailSafeContext::CommissioningFailedTimerComplete() { - // TODO: If the fail-safe timer expires before the CommissioningComplete command is - // successfully invoked, conduct clean-up steps. - ChipDeviceEvent event; - event.Type = DeviceEventType::kCommissioningComplete; - event.CommissioningComplete.PeerFabricIndex = mFabricIndex; - event.CommissioningComplete.Status = CHIP_ERROR_TIMEOUT; - CHIP_ERROR status = PlatformMgr().PostEvent(&event); + event.Type = DeviceEventType::kCommissioningComplete; + event.CommissioningComplete.PeerFabricIndex = mFabricIndex; + event.CommissioningComplete.AddNocCommandHasBeenInvoked = mAddNocCommandHasBeenInvoked; + event.CommissioningComplete.UpdateNocCommandHasBeenInvoked = mUpdateNocCommandHasBeenInvoked; + event.CommissioningComplete.Status = CHIP_ERROR_TIMEOUT; + CHIP_ERROR status = PlatformMgr().PostEvent(&event); mFailSafeArmed = false; mAddNocCommandHasBeenInvoked = false;