From b6e2c2c9707d953ee9330371d8ffb89f85c79f5e Mon Sep 17 00:00:00 2001 From: Jintao Lin Date: Wed, 25 Nov 2020 09:37:21 +0800 Subject: [PATCH] [low-power] frame pending bit handling for enh-ack in simulation (#5853) MAC command frame has its command ID encrypted in frame version 802.15.4-2015. Radio driver cannot decrypt this frame payload without extended address. So the frame pending bit is not correctly set in the ACK in response to data request command with version 2015. This commit adds a special handling for frame version 2015 and only checks the frame type when deciding if it needs to set the frame pending bit. --- examples/platforms/simulation/radio.c | 3 ++- examples/platforms/utils/mac_frame.cpp | 5 +++++ examples/platforms/utils/mac_frame.h | 14 +++++++++++++- src/core/mac/mac_frame.hpp | 4 +++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/platforms/simulation/radio.c b/examples/platforms/simulation/radio.c index a1baca64f..2e856dc15 100644 --- a/examples/platforms/simulation/radio.c +++ b/examples/platforms/simulation/radio.c @@ -830,7 +830,8 @@ void radioSendAck(void) if ( #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 // Determine if frame pending should be set - (otMacFrameIsData(&sReceiveFrame) || otMacFrameIsDataRequest(&sReceiveFrame)) + ((otMacFrameIsVersion2015(&sReceiveFrame) && otMacFrameIsCommand(&sReceiveFrame)) || + otMacFrameIsData(&sReceiveFrame) || otMacFrameIsDataRequest(&sReceiveFrame)) #else otMacFrameIsDataRequest(&sReceiveFrame) #endif diff --git a/examples/platforms/utils/mac_frame.cpp b/examples/platforms/utils/mac_frame.cpp index b9ef7e333..dcaa6d119 100644 --- a/examples/platforms/utils/mac_frame.cpp +++ b/examples/platforms/utils/mac_frame.cpp @@ -76,6 +76,11 @@ bool otMacFrameIsData(const otRadioFrame *aFrame) return static_cast(aFrame)->GetType() == Mac::Frame::kFcfFrameData; } +bool otMacFrameIsCommand(const otRadioFrame *aFrame) +{ + return static_cast(aFrame)->GetType() == Mac::Frame::kFcfFrameMacCmd; +} + bool otMacFrameIsDataRequest(const otRadioFrame *aFrame) { return static_cast(aFrame)->IsDataRequestCommand(); diff --git a/examples/platforms/utils/mac_frame.h b/examples/platforms/utils/mac_frame.h index f7fff115f..edac95fe0 100644 --- a/examples/platforms/utils/mac_frame.h +++ b/examples/platforms/utils/mac_frame.h @@ -91,10 +91,22 @@ bool otMacFrameIsAck(const otRadioFrame *aFrame); bool otMacFrameIsData(const otRadioFrame *aFrame); /** - * Check if @p aFrame is an Data Request Command. + * Check if @p aFrame is a Command frame. * * @param[in] aFrame A pointer to the frame. * + * @retval true It is a Command frame. + * @retval false It is not a Command frame. + * + */ +bool otMacFrameIsCommand(const otRadioFrame *aFrame); + +/** + * Check if @p aFrame is a Data Request Command. + * + * @param[in] aFrame A pointer to the frame. For 802.15.4-2015 and above frame, + * the frame should be already decrypted. + * * @retval true It is a Data Request Command frame. * @retval false It is not a Data Request Command frame. * diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index 1063be592..fea5c59e6 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -733,7 +733,9 @@ public: otError SetCommandId(uint8_t aCommandId); /** - * This method indicates whether the frame is a MAC Data Request command (data poll) + * This method indicates whether the frame is a MAC Data Request command (data poll). + * + * For 802.15.4-2015 and above frame, the frame should be already decrypted. * * @returns TRUE if frame is a MAC Data Request command, FALSE otherwise. *