[tcat] fix TCAT activation while in kStateConnected (#13240)

An issue was found that Activate(0,0) while in kStateConnected did not have any effect.
This PR fixes the issue by checking for connected state, and setting mNextState
explicitly in that case. Also, a guard is added to validate that aDurationMs == 0 and
aDelayMs == 0 in kStateConnected as required by the Activate() function API. The API
is also updated to make clear that both parameters must be 0, if called while connected.
This commit is contained in:
Esko Dijk
2026-07-16 10:39:15 -07:00
committed by Jonathan Hui
parent 48346e3924
commit df8c385387
2 changed files with 12 additions and 6 deletions
+10 -4
View File
@@ -150,18 +150,24 @@ Error TcatAgent::Activate(const uint32_t aDelayMs, const uint32_t aDurationMs)
Error error = kErrorNone;
VerifyOrExit(IsStarted(), error = kErrorInvalidState);
VerifyOrExit(mState != kStateActive);
// while connected, activation is limited to one case as defined by the API:
VerifyOrExit(mState != kStateConnected || (aDurationMs == 0 && aDelayMs == 0), error = kErrorInvalidState);
VerifyOrExit(mState != kStateActive); // exit if a permanent activation is already in place
mTcatActiveDurationMs = aDurationMs;
mTimerSetsToActive = true;
if (aDelayMs > 0)
mActiveOrStandbyTimer.Stop();
if (mState == kStateConnected)
{
mNextState = kStateActive; // applied later, after disconnection
}
else if (aDelayMs > 0)
{
mActiveOrStandbyTimer.Start(aDelayMs);
}
else
{
mActiveOrStandbyTimer.Stop();
HandleTimer();
HandleTimer(); // reuse existing activation logic
}
exit:
+2 -2
View File
@@ -339,8 +339,8 @@ public:
* The state transitions to kStateActive or kStateActiveTemporary. In these states, TCAT Advertisements
* are actively sent and TCAT Commissioners are able to connect. From here, TCAT can be set to standby
* again using Standby().
* If a connection is ongoing and aDurationMs==0, this call will ensure that kStateActive will
* be kept after this connection is finished.
* If a connection is ongoing and aDelayMs==0 and aDurationMs==0, this call will ensure that kStateActive will
* be kept after this connection is finished. Any non-zero parameters are not supported while in kStateConnected.
* This function will override any ongoing temporary activation of TCAT, or any
* previously scheduled activation for a future time.
*