From c87a81d346930e5cf55bdf59a37c1143adb2410f Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Thu, 14 Jun 2018 05:34:43 +0800 Subject: [PATCH] [mac-frame] unify mac frame access using Get()/Set() methods (#2787) --- include/openthread/platform/radio.h | 2 +- src/core/mac/mac.cpp | 12 ++++++------ src/core/mac/mac_frame.hpp | 16 ++++++++++++++++ src/ncp/ncp_base.cpp | 2 +- src/ncp/ncp_base_radio.cpp | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index d0a2bb7d7..da6de35e8 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -103,7 +103,7 @@ typedef struct otRadioFrame int8_t mRssi; ///< Received signal strength indicator in dBm for received frames. uint8_t mLqi; ///< Link Quality Indicator for received frames. uint8_t mMaxTxAttempts; ///< Max number of transmit attempts for an outbound frame. - bool mDidTX : 1; ///< Set to true if this frame sent from the radio. Ignored by radio driver. + bool mDidTx : 1; ///< Set to true if this frame sent from the radio. Ignored by radio driver. bool mIsARetx : 1; ///< Set to true if this frame is a retransmission. Should be ignored by radio driver. bool mIsCcaEnabled : 1; ///< Set to true if CCA must be enabled for this packet. False otherwise. diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 2a774d898..f936460de 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -1084,12 +1084,12 @@ void Mac::BeginTransmit(void) // Disable CCA for the last attempt if (mTransmitAttempts == (sendFrame.GetMaxTxAttempts() - 1)) { - sendFrame.mIsCcaEnabled = false; + sendFrame.SetIsCcaEnabled(false); } else #endif { - sendFrame.mIsCcaEnabled = true; + sendFrame.SetIsCcaEnabled(true); } if (mCsmaAttempts == 0 && mTransmitAttempts == 0) @@ -1147,7 +1147,7 @@ void Mac::BeginTransmit(void) if (mPcapCallback) { - sendFrame.mDidTX = true; + sendFrame.SetDidTx(true); mPcapCallback(&sendFrame, mPcapCallbackContext); } @@ -1768,7 +1768,7 @@ void Mac::HandleReceivedFrame(Frame *aFrame, otError aError) if (mPcapCallback) { - aFrame->mDidTX = false; + aFrame->SetDidTx(false); mPcapCallback(aFrame, mPcapCallbackContext); } @@ -1841,7 +1841,7 @@ void Mac::HandleReceivedFrame(Frame *aFrame, otError aError) // override with the rssi in setting if (rssi != OT_MAC_FILTER_FIXED_RSS_DISABLED) { - aFrame->mRssi = rssi; + aFrame->SetRssi(rssi); } #endif // OPENTHREAD_ENABLE_MAC_FILTER @@ -1906,7 +1906,7 @@ void Mac::HandleReceivedFrame(Frame *aFrame, otError aError) #endif // OPENTHREAD_ENABLE_MAC_FILTER - neighbor->GetLinkInfo().AddRss(GetNoiseFloor(), aFrame->mRssi); + neighbor->GetLinkInfo().AddRss(GetNoiseFloor(), aFrame->GetRssi()); if (aFrame->GetSecurityEnabled() == true) { diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index c128e0c79..270c7f107 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -918,6 +918,22 @@ public: */ void SetIsARetransmission(bool aIsARetx) { mIsARetx = aIsARetx; } + /** + * This method sets the did Tx attribute. + * + * @param[in] aDidTx TRUE if frame is sent from the radio, FALSE otherwise. + * + */ + void SetDidTx(bool aDidTx) { mDidTx = aDidTx; } + + /** + * This method sets the CCA enabled attribute. + * + * @param[in] aIsCcaEnabled TRUE if CCA must be enabled for this packet, FALSE otherwise. + * + */ + void SetIsCcaEnabled(bool aIsCcaEnabled) { mIsCcaEnabled = aIsCcaEnabled; } + /** * This method returns the IEEE 802.15.4 PSDU length. * diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 181809e66..4b10adb20 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -992,7 +992,7 @@ void NcpBase::HandleRawFrame(const otRadioFrame *aFrame) goto exit; } - if (aFrame->mDidTX) + if (aFrame->mDidTx) { flags |= SPINEL_MD_FLAG_TX; } diff --git a/src/ncp/ncp_base_radio.cpp b/src/ncp/ncp_base_radio.cpp index 92ba00f39..a0f071002 100644 --- a/src/ncp/ncp_base_radio.cpp +++ b/src/ncp/ncp_base_radio.cpp @@ -62,7 +62,7 @@ void NcpBase::LinkRawReceiveDone(otRadioFrame *aFrame, otError aError) uint16_t flags = 0; uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; - if (aFrame->mDidTX) + if (aFrame->mDidTx) { flags |= SPINEL_MD_FLAG_TX; }