Skip to content

Commit 643f7aa

Browse files
SEDs should stay in active mode while a fail-safe is armed. (project-chip#27204)
Fixes project-chip#24047 Implements spec fix CHIP-Specifications/connectedhomeip-spec#5683
1 parent 00b522f commit 643f7aa

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/app/FailSafeContext.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222

2323
#include <lib/support/SafeInt.h>
24+
#include <platform/CHIPDeviceConfig.h>
25+
#include <platform/ConnectivityManager.h>
2426
#include <platform/internal/CHIPDeviceLayerInternal.h>
2527

2628
#include "FailSafeContext.h"
@@ -48,6 +50,19 @@ void FailSafeContext::HandleDisarmFailSafe(intptr_t arg)
4850
failSafeContext->DisarmFailSafe();
4951
}
5052

53+
void FailSafeContext::SetFailSafeArmed(bool armed)
54+
{
55+
#if CHIP_DEVICE_CONFIG_ENABLE_SED
56+
if (IsFailSafeArmed() != armed)
57+
{
58+
// Per spec, we should be staying in active mode while a fail-safe is
59+
// armed.
60+
DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(armed);
61+
}
62+
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
63+
mFailSafeArmed = armed;
64+
}
65+
5166
void FailSafeContext::FailSafeTimerExpired()
5267
{
5368
if (!IsFailSafeArmed())
@@ -66,8 +81,9 @@ void FailSafeContext::ScheduleFailSafeCleanup(FabricIndex fabricIndex, bool addN
6681
// Not armed, but busy so cannot rearm (via General Commissioning cluster) until the flushing
6782
// via `HandleDisarmFailSafe` path is complete.
6883
// TODO: This is hacky and we need to remove all this event pushing business, to keep all fail-safe logic-only.
69-
mFailSafeBusy = true;
70-
mFailSafeArmed = false;
84+
mFailSafeBusy = true;
85+
86+
SetFailSafeArmed(false);
7187

7288
ChipDeviceEvent event;
7389
event.Type = DeviceEventType::kFailSafeTimerExpired;
@@ -90,7 +106,7 @@ CHIP_ERROR FailSafeContext::ArmFailSafe(FabricIndex accessingFabricIndex, System
90106

91107
CHIP_ERROR err = CHIP_NO_ERROR;
92108
bool cancelTimersIfError = false;
93-
if (!mFailSafeArmed)
109+
if (!IsFailSafeArmed())
94110
{
95111
System::Clock::Timeout maxCumulativeTimeout = System::Clock::Seconds32(CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC);
96112
SuccessOrExit(err = DeviceLayer::SystemLayer().StartTimer(maxCumulativeTimeout, HandleMaxCumulativeFailSafeTimer, this));
@@ -100,8 +116,8 @@ CHIP_ERROR FailSafeContext::ArmFailSafe(FabricIndex accessingFabricIndex, System
100116
SuccessOrExit(
101117
err = DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(expiryLengthSeconds), HandleArmFailSafeTimer, this));
102118

103-
mFailSafeArmed = true;
104-
mFabricIndex = accessingFabricIndex;
119+
SetFailSafeArmed(true);
120+
mFabricIndex = accessingFabricIndex;
105121

106122
exit:
107123

src/app/FailSafeContext.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class FailSafeContext
6666

6767
bool IsFailSafeArmed(FabricIndex accessingFabricIndex) const
6868
{
69-
return mFailSafeArmed && MatchesFabricIndex(accessingFabricIndex);
69+
return IsFailSafeArmed() && MatchesFabricIndex(accessingFabricIndex);
7070
}
7171

7272
// Returns true if the fail-safe is in a state where commands that require an armed
@@ -82,7 +82,7 @@ class FailSafeContext
8282

8383
bool MatchesFabricIndex(FabricIndex accessingFabricIndex) const
8484
{
85-
VerifyOrDie(mFailSafeArmed);
85+
VerifyOrDie(IsFailSafeArmed());
8686
return (accessingFabricIndex == mFabricIndex);
8787
}
8888

@@ -94,7 +94,7 @@ class FailSafeContext
9494

9595
FabricIndex GetFabricIndex() const
9696
{
97-
VerifyOrDie(mFailSafeArmed);
97+
VerifyOrDie(IsFailSafeArmed());
9898
return mFabricIndex;
9999
}
100100

@@ -131,12 +131,15 @@ class FailSafeContext
131131
*/
132132
static void HandleDisarmFailSafe(intptr_t arg);
133133

134+
void SetFailSafeArmed(bool armed);
135+
134136
/**
135137
* @brief Reset to unarmed basic state
136138
*/
137139
void ResetState()
138140
{
139-
mFailSafeArmed = false;
141+
SetFailSafeArmed(false);
142+
140143
mAddNocCommandHasBeenInvoked = false;
141144
mUpdateNocCommandHasBeenInvoked = false;
142145
mAddTrustedRootCertHasBeenInvoked = false;

0 commit comments

Comments
 (0)