Skip to content

Commit

Permalink
[wake-up] fix time wrap for wake-up frames (openthread#11028)
Browse files Browse the repository at this point in the history
This commit fixes the potential issue that mTxDelay becomes 0 around the
32-bit time wrapping.
  • Loading branch information
bukepo authored Jan 6, 2025
1 parent 336d701 commit 93f6d61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/mac/sub_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions src/core/mac/wakeup_tx_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 93f6d61

Please sign in to comment.