Skip to content

Commit

Permalink
Capture failSafeContext in CommissioningFailedTimerComplete event
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Mar 17, 2022
1 parent 267c0e4 commit 4d32ccc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ struct ChipDeviceEvent final
CHIP_ERROR Status;
uint64_t PeerNodeId;
FabricIndex PeerFabricIndex;
bool AddNocCommandHasBeenInvoked;
bool UpdateNocCommandHasBeenInvoked;
} CommissioningComplete;

struct
Expand Down
13 changes: 6 additions & 7 deletions src/platform/FailSafeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4d32ccc

Please sign in to comment.