Skip to content

Commit

Permalink
[mac_frame] process the security of the wakeup frame
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zhanglongxia committed Dec 11, 2024
1 parent 4f2eec9 commit f5b4218
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
20 changes: 18 additions & 2 deletions examples/platforms/utils/mac_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const Mac::Frame *>(aFrame)->GetKeyIdMode(keyIdMode);

return (error == OT_ERROR_NONE) ? (keyIdMode == Mac::Frame::kKeyIdMode2) : false;
}

uint8_t otMacFrameGetKeyId(otRadioFrame *aFrame)
{
uint8_t keyId = 0;
Expand Down Expand Up @@ -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))
{
Expand Down
10 changes: 10 additions & 0 deletions examples/platforms/utils/mac_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit f5b4218

Please sign in to comment.