From 7a96f682f3fa45cab32e21951bd48a7a4637d91c Mon Sep 17 00:00:00 2001 From: haomingw Date: Thu, 4 Feb 2021 11:11:42 -0800 Subject: [PATCH] Set 1000ms timer before reset weave config to ensure the device has sent the respone(StatusReport) before tunnel close. --- src/lib/core/WeaveConfig.h | 10 ++++++++++ src/lib/profiles/device-control/DeviceControl.cpp | 14 +++++++++++++- src/lib/profiles/device-control/DeviceControl.h | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/lib/core/WeaveConfig.h b/src/lib/core/WeaveConfig.h index bb510b69d2..ff979dcac8 100644 --- a/src/lib/core/WeaveConfig.h +++ b/src/lib/core/WeaveConfig.h @@ -2394,6 +2394,16 @@ extern const char WEAVE_NON_PRODUCTION_MARKER[]; #endif +/** + * @def WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS + * + * @brief The amount of time that a device waits after receiving a signal to reset its + * Weave configuration before executing the reset action. + */ +#ifndef WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS +#define WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS 1000 +#endif // WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS + // clang-format on #endif /* WEAVE_CONFIG_H_ */ diff --git a/src/lib/profiles/device-control/DeviceControl.cpp b/src/lib/profiles/device-control/DeviceControl.cpp index 6c41f7d07c..874c60db5e 100644 --- a/src/lib/profiles/device-control/DeviceControl.cpp +++ b/src/lib/profiles/device-control/DeviceControl.cpp @@ -77,6 +77,7 @@ DeviceControlServer::DeviceControlServer() mTunnelInactivityTimeout = 0; mRemotePassiveRendezvousKeyId = 0; mRemotePassiveRendezvousEncryptionType = 0; + mResetConfigTimeout = 0; } /** @@ -131,6 +132,7 @@ WEAVE_ERROR DeviceControlServer::Shutdown() mFailSafeToken = 0; mFailSafeArmed = false; mResetFlags = 0x0000; + mResetConfigTimeout = WEAVE_CONFIG_RESET_WEAVE_CONFIG_TIMEOUT_MSECS; // Kill any pending or completed Remote Passive Rendezvous. CloseRemotePassiveRendezvous(); @@ -686,7 +688,9 @@ WEAVE_ERROR DeviceControlServer::HandleResetConfig(uint8_t *p, WeaveConnection * curCon->Shutdown(); } else { - err = mDelegate->OnResetConfig(resetFlags); + mResetFlags = resetFlags; + System::Layer* lSystemLayer = ExchangeMgr->MessageLayer->SystemLayer; + err = lSystemLayer->StartTimer(mResetConfigTimeout, HandleResetConfigTimeout, this); SuccessOrExit(err); err = SendSuccessResponse(); @@ -709,6 +713,14 @@ WEAVE_ERROR DeviceControlServer::HandleResetConfig(uint8_t *p, WeaveConnection * return err; } +void DeviceControlServer::HandleResetConfigTimeout(System::Layer * aSystemLayer, void * aAppState, System::Error aError) +{ + DeviceControlServer* server = reinterpret_cast(aAppState); + uint16_t resetFlags = server->mResetFlags; + server->mDelegate->OnResetConfig(resetFlags); + server->mResetFlags = 0x0000; +} + WEAVE_ERROR DeviceControlServer::HandleArmFailSafe(uint8_t *p) { WEAVE_ERROR err = WEAVE_NO_ERROR; diff --git a/src/lib/profiles/device-control/DeviceControl.h b/src/lib/profiles/device-control/DeviceControl.h index e155bd5672..3a4b1c2d6b 100644 --- a/src/lib/profiles/device-control/DeviceControl.h +++ b/src/lib/profiles/device-control/DeviceControl.h @@ -325,6 +325,7 @@ class NL_DLL_EXPORT DeviceControlServer : public WeaveServerBase uint8_t mRemotePassiveRendezvousEncryptionType; uint16_t mResetFlags; bool mFailSafeArmed; + uint16_t mResetConfigTimeout; private: void StartMonitorTimer(ExchangeContext *monitorOp); @@ -383,7 +384,7 @@ class NL_DLL_EXPORT DeviceControlServer : public WeaveServerBase static void HandleRendezvousIdentifyConnectionClosed(ExchangeContext *ec, WeaveConnection *con, WEAVE_ERROR conErr); static void HandleMonitorConnectionClose(ExchangeContext *ec, WeaveConnection *con, WEAVE_ERROR conErr); - + static void HandleResetConfigTimeout(System::Layer * aSystemLayer, void * aAppState, System::Error aError); WEAVE_ERROR VerifyRendezvousedDeviceIdentity(WeaveConnection *con); void HandleIdentifyFailed(void);