Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Mar 15, 2022
1 parent 1f0af5a commit 267c0e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,36 +268,35 @@ void FailSafeCleanup(FailSafeContext & failSafeContext)

emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Call to FailSafeCleanup");

if (fabricInfo)
{
// 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())
{
CASESessionManager * caseSessionManager = Server::GetInstance().GetCASESessionManager();
VerifyOrReturn(fabricInfo != nullptr);

if (caseSessionManager)
{
caseSessionManager->ReleaseSession(fabricInfo->GetPeerId());
}
}
// 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())
{
CASESessionManager * caseSessionManager = Server::GetInstance().GetCASESessionManager();

// 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 (caseSessionManager)
{
Server::GetInstance().GetFabricTable().Delete(fabricInfo->GetFabricIndex());
caseSessionManager->ReleaseSessionsForFabric(fabricInfo->GetCompressedId());
}
}

// 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())
{
// TODO: Revert the state of operational key pair, NOC and ICAC
}
// 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())
{
Server::GetInstance().GetFabricTable().Delete(fabricInfo->GetFabricIndex());
}

// 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())
{
// TODO: Revert the state of operational key pair, NOC and ICAC
}
}

Expand All @@ -307,7 +306,10 @@ void OnPlatformEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, in
{
if (event->CommissioningComplete.Status != CHIP_NO_ERROR)
{
FailSafeCleanup(DeviceControlServer::DeviceControlSvr().GetFailSafeContext());
FailSafeContext & failSafeContext = DeviceControlServer::DeviceControlSvr().GetFailSafeContext();

VerifyOrReturn(event->CommissioningComplete.PeerFabricIndex == failSafeContext.GetFabricIndex());
FailSafeCleanup(failSafeContext);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/platform/FailSafeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ void FailSafeContext::CommissioningFailedTimerComplete()
// successfully invoked, conduct clean-up steps.

ChipDeviceEvent event;
event.Type = DeviceEventType::kCommissioningComplete;
event.CommissioningComplete.Status = CHIP_ERROR_TIMEOUT;
CHIP_ERROR status = PlatformMgr().PostEvent(&event);
event.Type = DeviceEventType::kCommissioningComplete;
event.CommissioningComplete.PeerFabricIndex = mFabricIndex;
event.CommissioningComplete.Status = CHIP_ERROR_TIMEOUT;
CHIP_ERROR status = PlatformMgr().PostEvent(&event);

mFailSafeArmed = false;
mAddNocCommandHasBeenInvoked = false;
Expand Down

0 comments on commit 267c0e4

Please sign in to comment.