Skip to content

Commit

Permalink
Clear things out from the CASESessionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Mar 18, 2022
1 parent 3f19e61 commit fa86a57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,31 @@ void FailSafeCleanup(const chip::DeviceLayer::ChipDeviceEvent * event)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Call to FailSafeCleanup");

FabricIndex fabricIndex = event->CommissioningComplete.PeerFabricIndex;

// 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 (event->CommissioningComplete.AddNocCommandHasBeenInvoked || event->CommissioningComplete.UpdateNocCommandHasBeenInvoked)
{
Server::GetInstance().GetSecureSessionManager().ExpireAllPairingsForFabric(event->CommissioningComplete.PeerFabricIndex);
CASESessionManager * caseSessionManager = Server::GetInstance().GetCASESessionManager();
if (caseSessionManager)
{
FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex);
VerifyOrReturn(fabricInfo != nullptr);

caseSessionManager->ReleaseSessionsForFabric(fabricInfo->GetCompressedId());
}

Server::GetInstance().GetSecureSessionManager().ExpireAllPairingsForFabric(fabricIndex);
}

// 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 (event->CommissioningComplete.AddNocCommandHasBeenInvoked)
{
Server::GetInstance().GetFabricTable().Delete(event->CommissioningComplete.PeerFabricIndex);
Server::GetInstance().GetFabricTable().Delete(fabricIndex);
}

// If an UpdateNOC command had been successfully invoked, revert the state of operational key pair, NOC and ICAC for that
Expand Down
13 changes: 9 additions & 4 deletions src/platform/DeviceControlServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ DeviceControlServer & DeviceControlServer::DeviceControlSvr()
CHIP_ERROR DeviceControlServer::CommissioningComplete(NodeId peerNodeId, FabricIndex accessingFabricIndex)
{
VerifyOrReturnError(CHIP_NO_ERROR == mFailSafeContext.DisarmFailSafe(), CHIP_ERROR_INTERNAL);

ChipDeviceEvent event;
event.Type = DeviceEventType::kCommissioningComplete;
event.CommissioningComplete.PeerNodeId = peerNodeId;
event.CommissioningComplete.PeerFabricIndex = accessingFabricIndex;
event.CommissioningComplete.Status = CHIP_NO_ERROR;

event.Type = DeviceEventType::kCommissioningComplete;
event.CommissioningComplete.PeerNodeId = peerNodeId;
event.CommissioningComplete.PeerFabricIndex = accessingFabricIndex;
event.CommissioningComplete.AddNocCommandHasBeenInvoked = mFailSafeContext.AddNocCommandHasBeenInvoked();
event.CommissioningComplete.UpdateNocCommandHasBeenInvoked = mFailSafeContext.UpdateNocCommandHasBeenInvoked();
event.CommissioningComplete.Status = CHIP_NO_ERROR;

return PlatformMgr().PostEvent(&event);
}

Expand Down

0 comments on commit fa86a57

Please sign in to comment.