Skip to content

Commit

Permalink
[spinel] do not update the sent frame when the diag is enabled
Browse files Browse the repository at this point in the history
When running command `diag frame -s fd874f68f1ca00efbe00adde5d4f4913e953845a154d4cbab10000000001820e390005009bb8ea011c58a065c39fbd` and `diag send 20` to send diag frames,
we found that the frame is modified by the RadioSpinel module. Which causes the diag sent frames are not the same.

This commit disables the RadioSpinel module from changing the sent frame when the diag mode is enabled.
  • Loading branch information
zhanglongxia committed Dec 4, 2024
1 parent 65dd8bf commit b9c86a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/core/diags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ Done

### diag frame

Usage: `diag frame [-c] [-p TX_POWER] [-s] <frame>`
Usage: `diag frame [-c] [-p TX_POWER] [-s] [-u] <frame>`

Set the frame (hex encoded) to be used by `diag send` and `diag repeat`. The frame may be overwritten by `diag send` and `diag repeat`.

- Specify `-s` to indicate that tx security is already processed so that it should be skipped in the radio layer.
- Specify `-c` to enable CSMA/CA for this frame in the radio layer.
- Specify `-p` to specify the tx power in dBm for this frame.
- Specify `-s` to indicate that tx security is already processed so that it should be skipped in the radio layer.
- Specify `-u` to specify the `mInfo.mTxInfo.mIsHeaderUpdated` filed for this frame.

```bash
> diag frame 11223344
Expand Down
16 changes: 15 additions & 1 deletion src/core/diags/factory_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Diags::Diags(Instance &aInstance)

void Diags::ResetTxPacket(void)
{
mIsHeaderUpdated = false;
mTxPacket->mInfo.mTxInfo.mTxDelayBaseTime = 0;
mTxPacket->mInfo.mTxInfo.mTxDelay = 0;
mTxPacket->mInfo.mTxInfo.mMaxCsmaBackoffs = 0;
Expand All @@ -232,13 +233,15 @@ Error Diags::ProcessFrame(uint8_t aArgsLength, char *aArgs[])
uint16_t size = OT_RADIO_FRAME_MAX_SIZE;
bool securityProcessed = false;
bool csmaCaEnabled = false;
bool isHeaderUpdated = false;
int8_t txPower = OT_RADIO_POWER_INVALID;

while (aArgsLength > 1)
{
if (StringMatch(aArgs[0], "-s"))
{
securityProcessed = true;
isHeaderUpdated = true;
}
else if (StringMatch(aArgs[0], "-p"))
{
Expand All @@ -255,6 +258,10 @@ Error Diags::ProcessFrame(uint8_t aArgsLength, char *aArgs[])
{
csmaCaEnabled = true;
}
else if (StringMatch(aArgs[0], "-u"))
{
isHeaderUpdated = true;
}
else
{
ExitNow(error = kErrorInvalidArgs);
Expand All @@ -276,6 +283,7 @@ Error Diags::ProcessFrame(uint8_t aArgsLength, char *aArgs[])
mTxPacket->mInfo.mTxInfo.mTxPower = txPower;
mTxPacket->mLength = size;
mIsTxPacketSet = true;
mIsHeaderUpdated = isHeaderUpdated;

exit:
AppendErrorResult(error);
Expand Down Expand Up @@ -514,7 +522,13 @@ void Diags::TransmitPacket(void)
{
mTxPacket->mChannel = mChannel;

if (!mIsTxPacketSet)
if (mIsTxPacketSet)
{
// The `mInfo.mTxInfo.mIsHeaderUpdated` field may be updated by the radio driver after the frame is sent,
// set the `mInfo.mTxInfo.mIsHeaderUpdated` field before transmitting the frame.
mTxPacket->mInfo.mTxInfo.mIsHeaderUpdated = mIsHeaderUpdated;
}
else
{
ResetTxPacket();
mTxPacket->mLength = mTxLen;
Expand Down
7 changes: 4 additions & 3 deletions src/core/diags/factory_diags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ class Diags : public InstanceLocator, private NonCopyable
uint8_t mChannel;
int8_t mTxPower;
uint8_t mTxLen;
bool mIsTxPacketSet;
bool mRepeatActive;
bool mDiagSendOn;
bool mIsHeaderUpdated : 1;
bool mIsTxPacketSet : 1;
bool mRepeatActive : 1;
bool mDiagSendOn : 1;
#endif

otDiagOutputCallback mOutputCallback;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/spinel/radio_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,10 +1582,8 @@ void RadioSpinel::HandleTransmitDone(uint32_t aCommand,
error = SpinelStatusToOtError(status);
}

static_cast<Mac::TxFrame *>(mTransmitFrame)->SetIsHeaderUpdated(headerUpdated);

if ((sRadioCaps & OT_RADIO_CAPS_TRANSMIT_SEC) && headerUpdated &&
static_cast<Mac::TxFrame *>(mTransmitFrame)->GetSecurityEnabled())
if ((sRadioCaps & OT_RADIO_CAPS_TRANSMIT_SEC) && (!mTransmitFrame->mInfo.mTxInfo.mIsHeaderUpdated) &&
headerUpdated && static_cast<Mac::TxFrame *>(mTransmitFrame)->GetSecurityEnabled())
{
uint8_t keyId;
uint32_t frameCounter;
Expand All @@ -1602,6 +1600,8 @@ void RadioSpinel::HandleTransmitDone(uint32_t aCommand,
#endif
}

static_cast<Mac::TxFrame *>(mTransmitFrame)->SetIsHeaderUpdated(headerUpdated);

exit:
// A parse error indicates an RCP misbehavior, so recover the RCP immediately.
mState = kStateTransmitDone;
Expand Down

0 comments on commit b9c86a5

Please sign in to comment.