From 9fefeedb0d6d594c12cacd86ca9b33cf791981e2 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Fri, 13 Dec 2024 07:32:41 +0800 Subject: [PATCH] [mac-frame] process the security of the wakeup frame (#11003) If the radio driver supports the `OT_RADIO_CAPS_TRANSMIT_SEC`, the radio driver should process the security of the send frame. But the current method `otMacFrameProcessTransmitSecurity()` doesn't process the security of the wakeup frame. Which causes sent wakeup frame is not encrypted. This commit enables the method `otMacFrameProcessTransmitSecurity()` to process the security of the wakeup frame. --- examples/platforms/utils/mac_frame.cpp | 20 ++++++++++++++++++-- examples/platforms/utils/mac_frame.h | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/platforms/utils/mac_frame.cpp b/examples/platforms/utils/mac_frame.cpp index 1356c7e4b5f..6f23f6df7f4 100644 --- a/examples/platforms/utils/mac_frame.cpp +++ b/examples/platforms/utils/mac_frame.cpp @@ -224,6 +224,16 @@ bool otMacFrameIsKeyIdMode1(otRadioFrame *aFrame) return (error == OT_ERROR_NONE) ? (keyIdMode == Mac::Frame::kKeyIdMode1) : false; } +bool otMacFrameIsKeyIdMode2(otRadioFrame *aFrame) +{ + uint8_t keyIdMode; + otError error; + + error = static_cast(aFrame)->GetKeyIdMode(keyIdMode); + + return (error == OT_ERROR_NONE) ? (keyIdMode == Mac::Frame::kKeyIdMode2) : false; +} + uint8_t otMacFrameGetKeyId(otRadioFrame *aFrame) { uint8_t keyId = 0; @@ -306,9 +316,15 @@ otError otMacFrameProcessTransmitSecurity(otRadioFrame *aFrame, otRadioContext * otMacKeyMaterial *key = nullptr; uint8_t keyId; uint32_t frameCounter; + bool processKeyId; + + processKeyId = +#if OPENTHREAD_CONFIG_WAKEUP_END_DEVICE_ENABLE + otMacFrameIsKeyIdMode2(aFrame) || +#endif + otMacFrameIsKeyIdMode1(aFrame); - VerifyOrExit(otMacFrameIsSecurityEnabled(aFrame) && otMacFrameIsKeyIdMode1(aFrame) && - !aFrame->mInfo.mTxInfo.mIsSecurityProcessed); + VerifyOrExit(otMacFrameIsSecurityEnabled(aFrame) && processKeyId && !aFrame->mInfo.mTxInfo.mIsSecurityProcessed); if (otMacFrameIsAck(aFrame)) { diff --git a/examples/platforms/utils/mac_frame.h b/examples/platforms/utils/mac_frame.h index 5501f0acd53..8817db6bd16 100644 --- a/examples/platforms/utils/mac_frame.h +++ b/examples/platforms/utils/mac_frame.h @@ -259,6 +259,16 @@ bool otMacFrameIsSecurityEnabled(otRadioFrame *aFrame); */ bool otMacFrameIsKeyIdMode1(otRadioFrame *aFrame); +/** + * Tell if the key ID mode of @p aFrame is 2. + * + * @param[in] aFrame A pointer to the frame. + * + * @retval true The frame key ID mode is 2. + * @retval false The frame security is not enabled or key ID mode is not 2. + */ +bool otMacFrameIsKeyIdMode2(otRadioFrame *aFrame); + /** * Get the key ID of @p aFrame. *