Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mac] fix build failure with CONFIG_DISABLE_CSMA_CA_ON_LAST_ATTEMPT #2922

Merged
merged 1 commit into from Jul 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 57 additions & 50 deletions src/core/mac/mac.cpp
Expand Up @@ -1023,69 +1023,77 @@ void Mac::ProcessTransmitSecurity(Frame &aFrame, bool aProcessAesCcm)

void Mac::StartCsmaBackoff(void)
{
uint32_t backoffExponent = kMinBE + mTransmitRetries + mCsmaBackoffs;
uint32_t backoff;
bool shouldReceive;

if (RadioSupportsCsmaBackoff())
{
// If the radio supports CSMA back off logic, immediately schedule the send.
BeginTransmit();
ExitNow();
}
#if OPENTHREAD_CONFIG_DISABLE_CSMA_CA_ON_LAST_ATTEMPT
else if ((sendFrame.GetMaxFrameRetries() > 0) && (sendFrame.GetMaxFrameRetries() <= mTransmitRetries))
{
BeginTransmit();
}
#endif
else
else if (mTransmitRetries > 0)
{
uint32_t backoffExponent = kMinBE + mTransmitRetries + mCsmaBackoffs;
uint32_t backoff;
bool shouldReceive;
Frame &sendFrame(*GetOperationFrame());

if (backoffExponent > kMaxBE)
if ((sendFrame.GetMaxFrameRetries() > 0) && (sendFrame.GetMaxFrameRetries() <= mTransmitRetries))
{
backoffExponent = kMaxBE;
BeginTransmit();
ExitNow();
}
}
#endif

backoff = Random::GetUint32InRange(0, 1U << backoffExponent);
backoff *= (static_cast<uint32_t>(kUnitBackoffPeriod) * OT_RADIO_SYMBOL_TIME);
if (backoffExponent > kMaxBE)
{
backoffExponent = kMaxBE;
}

backoff = Random::GetUint32InRange(0, 1U << backoffExponent);
backoff *= (static_cast<uint32_t>(kUnitBackoffPeriod) * OT_RADIO_SYMBOL_TIME);

// Put the radio in either sleep or receive mode depending on
// `mRxOnWhenIdle` flag before starting the backoff timer.
// Put the radio in either sleep or receive mode depending on
// `mRxOnWhenIdle` flag before starting the backoff timer.

shouldReceive = (mRxOnWhenIdle || otPlatRadioGetPromiscuous(&GetInstance()));
shouldReceive = (mRxOnWhenIdle || otPlatRadioGetPromiscuous(&GetInstance()));

if (!shouldReceive)
if (!shouldReceive)
{
if (RadioSleep() == OT_ERROR_INVALID_STATE)
{
if (RadioSleep() == OT_ERROR_INVALID_STATE)
{
// If `RadioSleep()` returns `OT_ERROR_INVALID_STATE`
// indicating sleep is being delayed, the radio should
// be put in receive mode.
// If `RadioSleep()` returns `OT_ERROR_INVALID_STATE`
// indicating sleep is being delayed, the radio should
// be put in receive mode.

shouldReceive = true;
}
shouldReceive = true;
}
}

if (shouldReceive)
if (shouldReceive)
{
switch (mOperation)
{
switch (mOperation)
{
case kOperationActiveScan:
case kOperationEnergyScan:
RadioReceive(mScanChannel);
break;
case kOperationActiveScan:
case kOperationEnergyScan:
RadioReceive(mScanChannel);
break;

default:
RadioReceive(mRadioChannel);
break;
}
default:
RadioReceive(mRadioChannel);
break;
}
}

#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
mBackoffTimer.Start(backoff);
mBackoffTimer.Start(backoff);
#else // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
mBackoffTimer.Start(backoff / 1000UL);
mBackoffTimer.Start(backoff / 1000UL);
#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
}

exit:
return;
}

void Mac::HandleBackoffTimer(Timer &aTimer)
Expand Down Expand Up @@ -1144,17 +1152,6 @@ void Mac::BeginTransmit(void)

VerifyOrExit(mEnabled, error = OT_ERROR_ABORT);

#if OPENTHREAD_CONFIG_DISABLE_CSMA_CA_ON_LAST_ATTEMPT
else if ((sendFrame.GetMaxFrameRetries() > 0) && (sendFrame.GetMaxFrameRetries() <= mTransmitRetries))
{
sendFrame.SetCsmaCaEnabled(false);
}
else
#endif
{
sendFrame.SetCsmaCaEnabled(true);
}

if (mCsmaBackoffs == 0 && mTransmitRetries == 0 && mBroadcastTransmitCount == 0)
{
switch (mOperation)
Expand Down Expand Up @@ -1208,7 +1205,6 @@ void Mac::BeginTransmit(void)
sendFrame.SetTimeSyncSeq(GetNetif().GetTimeSync().GetTimeSyncSeq());
sendFrame.SetNetworkTimeOffset(GetNetif().GetTimeSync().GetNetworkTimeOffset());
}

#endif

if (applyTransmitSecurity)
Expand All @@ -1218,6 +1214,17 @@ void Mac::BeginTransmit(void)
}
}

#if OPENTHREAD_CONFIG_DISABLE_CSMA_CA_ON_LAST_ATTEMPT
if ((sendFrame.GetMaxFrameRetries() > 0) && (sendFrame.GetMaxFrameRetries() <= mTransmitRetries))
{
sendFrame.SetCsmaCaEnabled(false);
}
else
#endif
{
sendFrame.SetCsmaCaEnabled(true);
}

error = RadioReceive(sendFrame.GetChannel());
assert(error == OT_ERROR_NONE);

Expand Down