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

Set 1000ms timer before reset weave config to ensure the device has sent #648

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/core/WeaveConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
14 changes: 13 additions & 1 deletion src/lib/profiles/device-control/DeviceControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ DeviceControlServer::DeviceControlServer()
mTunnelInactivityTimeout = 0;
mRemotePassiveRendezvousKeyId = 0;
mRemotePassiveRendezvousEncryptionType = 0;
mResetConfigTimeout = 0;
}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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<DeviceControlServer *>(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;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/profiles/device-control/DeviceControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down