Skip to content

Commit 7578745

Browse files
committed
[nrf toup] Check Fail-Safe marker during boot.
Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
1 parent ed33404 commit 7578745

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/app/FailSafeContext.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@ CHIP_ERROR FailSafeContext::Init(const InitParams & initParams)
5959
return CHIP_NO_ERROR;
6060
}
6161

62+
void FailSafeContext::CheckMarker()
63+
{
64+
Marker marker;
65+
66+
CHIP_ERROR err = GetMarker(marker);
67+
68+
if (err == CHIP_NO_ERROR)
69+
{
70+
// Found a marker! We need to trigger a cleanup.
71+
ChipLogError(FabricProvisioning, "Found a Fail-Safe marker for index 0x%x, preparing cleanup!",
72+
static_cast<unsigned>(marker.fabricIndex));
73+
74+
// Fake arm Fail-Safe and trigger timer expiry.
75+
// We handle only the case when new fabric is added. FabricTable CommitMarker
76+
// is responsible for guarding the case of updating the existing fabric.
77+
SetFailSafeArmed(true);
78+
mFabricIndex = marker.fabricIndex;
79+
mAddNocCommandHasBeenInvoked = true;
80+
ForceFailSafeTimerExpiry();
81+
}
82+
else if (err != CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
83+
{
84+
// Got an error, but somehow value is not missing altogether: inconsistent state but touch nothing.
85+
ChipLogError(FabricProvisioning, "Error loading Fail-Safe marker: %" CHIP_ERROR_FORMAT ", hope for the best!",
86+
err.Format());
87+
}
88+
}
89+
6290
void FailSafeContext::HandleArmFailSafeTimer(System::Layer * layer, void * aAppState)
6391
{
6492
FailSafeContext * failSafeContext = reinterpret_cast<FailSafeContext *>(aAppState);

src/app/FailSafeContext.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class FailSafeContext
4242

4343
CHIP_ERROR Init(const InitParams & initParams);
4444

45+
void CheckMarker();
46+
4547
// ===== Members for internal use by other Device Layer components.
4648

4749
/**

src/app/server/Server.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
445445
}
446446
}
447447

448+
// Run fail-safe check for marker. If marker is present, then device was reset while fail-safe was armed
449+
// and we need to trigger a cleanup.
450+
GetFailSafeContext().CheckMarker();
451+
448452
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT // support UDC port for commissioner declaration msgs
449453
mUdcTransportMgr = chip::Platform::New<UdcTransportMgr>();
450454
ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(DeviceLayer::UDPEndPointManager())

0 commit comments

Comments
 (0)