Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 7a96f68

Browse files
committed
Set 1000ms timer before reset weave config to ensure the device has sent
the respone(StatusReport) before tunnel close.
1 parent 65169b4 commit 7a96f68

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/lib/core/WeaveConfig.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,16 @@
23942394
extern const char WEAVE_NON_PRODUCTION_MARKER[];
23952395
#endif
23962396

2397+
/**
2398+
* @def WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS
2399+
*
2400+
* @brief The amount of time that a device waits after receiving a signal to reset its
2401+
* Weave configuration before executing the reset action.
2402+
*/
2403+
#ifndef WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS
2404+
#define WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS 1000
2405+
#endif // WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS
2406+
23972407
// clang-format on
23982408

23992409
#endif /* WEAVE_CONFIG_H_ */

src/lib/profiles/device-control/DeviceControl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ DeviceControlServer::DeviceControlServer()
7777
mTunnelInactivityTimeout = 0;
7878
mRemotePassiveRendezvousKeyId = 0;
7979
mRemotePassiveRendezvousEncryptionType = 0;
80+
mResetConfigTimeout = 0;
8081
}
8182

8283
/**
@@ -131,6 +132,7 @@ WEAVE_ERROR DeviceControlServer::Shutdown()
131132
mFailSafeToken = 0;
132133
mFailSafeArmed = false;
133134
mResetFlags = 0x0000;
135+
mResetConfigTimeout = WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS;
134136

135137
// Kill any pending or completed Remote Passive Rendezvous.
136138
CloseRemotePassiveRendezvous();
@@ -686,7 +688,9 @@ WEAVE_ERROR DeviceControlServer::HandleResetConfig(uint8_t *p, WeaveConnection *
686688

687689
curCon->Shutdown();
688690
} else {
689-
err = mDelegate->OnResetConfig(resetFlags);
691+
mResetFlags = resetFlags;
692+
System::Layer* lSystemLayer = ExchangeMgr->MessageLayer->SystemLayer;
693+
err = lSystemLayer->StartTimer(mResetConfigTimeout, HandleResetConfigTimeout, this);
690694
SuccessOrExit(err);
691695

692696
err = SendSuccessResponse();
@@ -709,6 +713,14 @@ WEAVE_ERROR DeviceControlServer::HandleResetConfig(uint8_t *p, WeaveConnection *
709713
return err;
710714
}
711715

716+
void DeviceControlServer::HandleResetConfigTimeout(System::Layer * aSystemLayer, void * aAppState, System::Error aError)
717+
{
718+
DeviceControlServer* server = reinterpret_cast<DeviceControlServer *>(aAppState);
719+
uint16_t resetFlags = server->mResetFlags;
720+
server->mDelegate->OnResetConfig(resetFlags);
721+
server->mResetFlags = 0x0000;
722+
}
723+
712724
WEAVE_ERROR DeviceControlServer::HandleArmFailSafe(uint8_t *p)
713725
{
714726
WEAVE_ERROR err = WEAVE_NO_ERROR;

src/lib/profiles/device-control/DeviceControl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class NL_DLL_EXPORT DeviceControlServer : public WeaveServerBase
325325
uint8_t mRemotePassiveRendezvousEncryptionType;
326326
uint16_t mResetFlags;
327327
bool mFailSafeArmed;
328+
uint16_t mResetConfigTimeout;
328329

329330
private:
330331
void StartMonitorTimer(ExchangeContext *monitorOp);
@@ -383,7 +384,7 @@ class NL_DLL_EXPORT DeviceControlServer : public WeaveServerBase
383384
static void HandleRendezvousIdentifyConnectionClosed(ExchangeContext *ec, WeaveConnection *con,
384385
WEAVE_ERROR conErr);
385386
static void HandleMonitorConnectionClose(ExchangeContext *ec, WeaveConnection *con, WEAVE_ERROR conErr);
386-
387+
static void HandleResetConfigTimeout(System::Layer * aSystemLayer, void * aAppState, System::Error aError);
387388

388389
WEAVE_ERROR VerifyRendezvousedDeviceIdentity(WeaveConnection *con);
389390
void HandleIdentifyFailed(void);

0 commit comments

Comments
 (0)