diff --git a/include/platform/radio.h b/include/platform/radio.h index ec51e2079..3b00df5c4 100644 --- a/include/platform/radio.h +++ b/include/platform/radio.h @@ -91,7 +91,8 @@ typedef enum otRadioCaps kRadioCapsNone = 0, ///< None kRadioCapsAckTimeout = 1, ///< Radio supports AckTime event kRadioCapsEnergyScan = 2, ///< Radio supports Energy Scans - kRadioCapsTransmitRetries = 4, ///< Radio supports transmission retry logic with collision avoidance + kRadioCapsTransmitRetries = 4, ///< Radio supports transmission retry logic with collision avoidance (CSMA). + kRadioCapsCsmaBackOff = 8, ///< Radio supports CSMA backoff for frame transmission (but no retry). } otRadioCaps; /** diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 0bb58518e..e727f049a 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -81,10 +81,9 @@ static_assert(kMinBackoffSum > 0, "The min backoff value should be greater than void Mac::StartCsmaBackoff(void) { - if (RadioSupportsRetriesAndCsmaBackoff()) + if (RadioSupportsCsmaBackoff()) { - // If the radio supports the retry and back off logic, immediately schedule the send, - // and the radio will take care of everything. + // If the radio supports CSMA back off logic, immediately schedule the send. HandleBeginTransmit(); } else @@ -856,7 +855,7 @@ void Mac::TransmitDoneTask(RadioPacket *aPacket, bool aRxPending, ThreadError aE mCounters.mTxErrAbort++; } - if (!RadioSupportsRetriesAndCsmaBackoff() && + if (!RadioSupportsCsmaBackoff() && aError == kThreadError_ChannelAccessFailure && mCsmaAttempts < kMaxCSMABackoffs) { @@ -989,7 +988,7 @@ void Mac::SentFrame(ThreadError aError) case kThreadError_NoAck: otDumpDebgMac("NO ACK", sendFrame.GetHeader(), 16); - if (!RadioSupportsRetriesAndCsmaBackoff() && + if (!RadioSupportsRetries() && mTransmitAttempts < kMaxFrameAttempts) { mTransmitAttempts++; @@ -1540,7 +1539,16 @@ void Mac::SetPromiscuous(bool aPromiscuous) } } -bool Mac::RadioSupportsRetriesAndCsmaBackoff(void) +bool Mac::RadioSupportsCsmaBackoff(void) +{ + /* Check either of the following conditions: + * 1) Radio provides the CSMA backoff capability (i.e., `kRadioCapsCsmaBackOff` bit is set) or; + * 2) It provides `kRadioCapsTransmitRetries` which indicates support for MAC retries along with CSMA backoff. + */ + return (otPlatRadioGetCaps(mNetif.GetInstance()) & (kRadioCapsTransmitRetries | kRadioCapsCsmaBackOff)) != 0; +} + +bool Mac::RadioSupportsRetries(void) { return (otPlatRadioGetCaps(mNetif.GetInstance()) & kRadioCapsTransmitRetries) != 0; } diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 42d2e8df7..e210f0dd5 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -560,13 +560,22 @@ public: void ClearSrcMatchEntries(void); /** - * This method indicates whether or not transmit retries and CSMA backoff logic is supported by the radio layer. + * This method indicates whether or not CSMA backoff is supported by the radio layer. * - * @retval true Retries and CSMA are supported by the radio. - * @retval false Retries and CSMA are not supported by the radio. + * @retval true CSMA backoff is supported by the radio. + * @retval false CSMA backoff is not supported by the radio. * */ - bool RadioSupportsRetriesAndCsmaBackoff(void); + bool RadioSupportsCsmaBackoff(void); + + /** + * This method indicates whether or not transmit retries is supported by the radio layer. + * + * @retval true Retries (and CSMA) are supported by the radio. + * @retval false Retries (and CSMA) are not supported by the radio. + * + */ + bool RadioSupportsRetries(void); private: enum ScanType