[wake-up] fix time wrap for wake-up frames (#11028)

This commit fixes the potential issue that mTxDelay becomes 0 around the
32-bit time wrapping.
This commit is contained in:
Yakun Xu
2025-01-06 09:34:08 -08:00
committed by GitHub
parent 336d70127d
commit 93f6d619ef
2 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -413,7 +413,7 @@ void SubMac::StartCsmaBackoff(void)
uint8_t backoffExponent = kCsmaMinBe + mCsmaBackoffs;
#if !OPENTHREAD_MTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
if (mTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)
if (mTransmitFrame.mInfo.mTxInfo.mTxDelay != 0 || mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime != 0)
{
SetState(kStateCslTransmit);
+6 -4
View File
@@ -80,15 +80,17 @@ Mac::TxFrame *WakeupTxScheduler::PrepareWakeupFrame(Mac::TxFrames &aTxFrames)
Mac::TxFrame *frame = nullptr;
Mac::Address target;
Mac::Address source;
uint32_t radioTxUs;
uint32_t radioTxDelay;
uint32_t rendezvousTimeUs;
TimeMicro nowUs = TimerMicro::GetNow();
Mac::ConnectionIe *connectionIe;
VerifyOrExit(mIsRunning);
target.SetExtended(mWedAddress);
source.SetExtended(Get<Mac::Mac>().GetExtAddress());
radioTxUs = static_cast<uint32_t>(Get<Radio>().GetNow()) + (mTxTimeUs - TimerMicro::GetNow());
VerifyOrExit(mTxTimeUs >= nowUs);
radioTxDelay = mTxTimeUs - nowUs;
#if OPENTHREAD_CONFIG_MULTI_RADIO
frame = &aTxFrames.GetTxFrame(Mac::kRadioTypeIeee802154);
@@ -97,8 +99,8 @@ Mac::TxFrame *WakeupTxScheduler::PrepareWakeupFrame(Mac::TxFrames &aTxFrames)
#endif
VerifyOrExit(frame->GenerateWakeupFrame(Get<Mac::Mac>().GetPanId(), target, source) == kErrorNone, frame = nullptr);
frame->SetTxDelayBaseTime(0);
frame->SetTxDelay(radioTxUs);
frame->SetTxDelayBaseTime(static_cast<uint32_t>(Get<Radio>().GetNow()));
frame->SetTxDelay(radioTxDelay);
frame->SetCsmaCaEnabled(false);
frame->SetMaxCsmaBackoffs(0);
frame->SetMaxFrameRetries(0);