From 5d6dccf35c038e7da43167c6789c79a728a3e3c7 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 27 Nov 2018 10:05:18 -0800 Subject: [PATCH] [radio-spinel] determine presence of Ack from spinel TxDone frame (#3313) This commit changes `RadioSpinel` to determine if Ack is present directly from the received spinel TxDone frame (i.e. check the remaining unparsed length of spinel frame to determine if ack frame is included by Radio Co-Processor (RCP)). This change helps simplify the code by removing the requirement for `RadioSpinel` as the layer between OpenThread core and RCP to parse the 15.4 frame. --- src/posix/platform/radio_spinel.cpp | 63 +++++------------------------ src/posix/platform/radio_spinel.hpp | 1 - 2 files changed, 9 insertions(+), 55 deletions(-) diff --git a/src/posix/platform/radio_spinel.cpp b/src/posix/platform/radio_spinel.cpp index 8cd57df8a..33f93f53a 100644 --- a/src/posix/platform/radio_spinel.cpp +++ b/src/posix/platform/radio_spinel.cpp @@ -54,55 +54,8 @@ #include #include -enum -{ - IEEE802154_MIN_LENGTH = 5, - IEEE802154_MAX_LENGTH = 127, - IEEE802154_ACK_LENGTH = 5, - - IEEE802154_BROADCAST = 0xffff, - - IEEE802154_FRAME_TYPE_ACK = 2 << 0, - IEEE802154_FRAME_TYPE_MACCMD = 3 << 0, - IEEE802154_FRAME_TYPE_MASK = 7 << 0, - - IEEE802154_SECURITY_ENABLED = 1 << 3, - IEEE802154_FRAME_PENDING = 1 << 4, - IEEE802154_ACK_REQUEST = 1 << 5, - IEEE802154_PANID_COMPRESSION = 1 << 6, - - IEEE802154_DST_ADDR_NONE = 0 << 2, - IEEE802154_DST_ADDR_SHORT = 2 << 2, - IEEE802154_DST_ADDR_EXT = 3 << 2, - IEEE802154_DST_ADDR_MASK = 3 << 2, - - IEEE802154_SRC_ADDR_NONE = 0 << 6, - IEEE802154_SRC_ADDR_SHORT = 2 << 6, - IEEE802154_SRC_ADDR_EXT = 3 << 6, - IEEE802154_SRC_ADDR_MASK = 3 << 6, - - IEEE802154_DSN_OFFSET = 2, - IEEE802154_DSTPAN_OFFSET = 3, - IEEE802154_DSTADDR_OFFSET = 5, - - IEEE802154_SEC_LEVEL_MASK = 7 << 0, - - IEEE802154_KEY_ID_MODE_0 = 0 << 3, - IEEE802154_KEY_ID_MODE_1 = 1 << 3, - IEEE802154_KEY_ID_MODE_2 = 2 << 3, - IEEE802154_KEY_ID_MODE_3 = 3 << 3, - IEEE802154_KEY_ID_MODE_MASK = 3 << 3, - - IEEE802154_MACCMD_DATA_REQ = 4, -}; - static ot::PosixApp::RadioSpinel sRadioSpinel; -static inline bool isAckRequested(const uint8_t *frame) -{ - return (frame[0] & IEEE802154_ACK_REQUEST) != 0; -} - namespace ot { namespace PosixApp { @@ -206,7 +159,6 @@ RadioSpinel::RadioSpinel(void) , mWaitingKey(SPINEL_PROP_LAST_STATUS) , mRxSensitivity(0) , mState(kStateDisabled) - , mIsAckRequested(false) , mIsPromiscuous(false) , mIsReady(false) , mSupportsLogStream(false) @@ -725,7 +677,8 @@ void RadioSpinel::Process(const fd_set &aReadFdSet, const fd_set &aWriteFdSet) else #endif { - otPlatRadioTxDone(mInstance, mTransmitFrame, (mIsAckRequested ? &mAckRadioFrame : NULL), mTxError); + otPlatRadioTxDone(mInstance, mTransmitFrame, (mAckRadioFrame.mLength != 0) ? &mAckRadioFrame : NULL, + mTxError); } } @@ -1043,8 +996,6 @@ void RadioSpinel::RadioTransmit(void) otPlatRadioTxStarted(mInstance, mTransmitFrame); assert(mState == kStateTransmitPending); - mIsAckRequested = isAckRequested(mTransmitFrame->mPsdu) && !mIsPromiscuous; - error = Request(true, SPINEL_CMD_PROP_VALUE_SET, SPINEL_PROP_STREAM_RAW, SPINEL_DATATYPE_DATA_WLEN_S SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT8_S, mTransmitFrame->mPsdu, mTransmitFrame->mLength, mTransmitFrame->mChannel, mTransmitFrame->mInfo.mRxInfo.mRssi); @@ -1189,11 +1140,14 @@ void RadioSpinel::HandleTransmitDone(uint32_t aCommand, aBuffer += unpacked; aLength -= static_cast(unpacked); - if (mIsAckRequested) + if (aLength > 0) { - VerifyOrExit(aLength > 0, error = OT_ERROR_FAILED); SuccessOrExit(error = ParseRadioFrame(mAckRadioFrame, aBuffer, aLength)); } + else + { + mAckRadioFrame.mLength = 0; + } } else { @@ -1567,7 +1521,8 @@ void ot::PosixApp::RadioSpinel::Process(const Event &aEvent) else #endif { - otPlatRadioTxDone(mInstance, mTransmitFrame, (mIsAckRequested ? &mAckRadioFrame : NULL), mTxError); + otPlatRadioTxDone(mInstance, mTransmitFrame, (mAckRadioFrame.mLength != 0) ? &mAckRadioFrame : NULL, + mTxError); } } diff --git a/src/posix/platform/radio_spinel.hpp b/src/posix/platform/radio_spinel.hpp index c7f7321ff..ce872ad5c 100644 --- a/src/posix/platform/radio_spinel.hpp +++ b/src/posix/platform/radio_spinel.hpp @@ -609,7 +609,6 @@ private: char mVersion[kVersionStringSize]; State mState; - bool mIsAckRequested : 1; ///< Ack requested. bool mIsPromiscuous : 1; ///< Promiscuous mode. bool mIsReady : 1; ///< NCP ready. bool mSupportsLogStream : 1; ///< RCP supports `LOG_STREAM` property with OpenThread log meta-data format.