Skip to content

Commit

Permalink
[diag] support send security processed frames (openthread#10640)
Browse files Browse the repository at this point in the history
This commit extends the `diag frame` command by adding an argument `-s`
to indicate whether the frame has been encrypted or not, so that the
diag commands can be used to test frames having security processed in
the host.
  • Loading branch information
bukepo authored Aug 28, 2024
1 parent a30cbda commit 95a4c33
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/core/diags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The diagnostics module supports common diagnostics features that are listed belo
- [diag start](#diag-start)
- [diag channel](#diag-channel)
- [diag cw](#diag-cw-start)
- [diag frame](#diag-frame)
- [diag stream](#diag-stream-start)
- [diag power](#diag-power)
- [diag powersettings](#diag-powersettings)
Expand Down Expand Up @@ -77,10 +78,14 @@ Stop transmitting continuous carrier wave.
Done
```

### diag frame \<frame\>
### diag frame

Usage: `diag frame [-s] <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 skip security processing in radio layer.

```bash
> diag frame 11223344
Done
Expand Down
39 changes: 35 additions & 4 deletions src/core/diags/factory_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "factory_diags.hpp"
#include "common/error.hpp"
#include "openthread/platform/radio.h"

#if OPENTHREAD_CONFIG_DIAG_ENABLE

Expand Down Expand Up @@ -216,18 +217,47 @@ Diags::Diags(Instance &aInstance)
mStats.Clear();
}

void Diags::ResetTxPacket(void)
{
mTxPacket->mInfo.mTxInfo.mTxDelayBaseTime = 0;
mTxPacket->mInfo.mTxInfo.mTxDelay = 0;
mTxPacket->mInfo.mTxInfo.mMaxCsmaBackoffs = 0;
mTxPacket->mInfo.mTxInfo.mMaxFrameRetries = 0;
mTxPacket->mInfo.mTxInfo.mRxChannelAfterTxDone = mChannel;
mTxPacket->mInfo.mTxInfo.mTxPower = OT_RADIO_POWER_INVALID;
mTxPacket->mInfo.mTxInfo.mIsHeaderUpdated = false;
mTxPacket->mInfo.mTxInfo.mIsARetx = false;
mTxPacket->mInfo.mTxInfo.mCsmaCaEnabled = false;
mTxPacket->mInfo.mTxInfo.mCslPresent = false;
mTxPacket->mInfo.mTxInfo.mIsSecurityProcessed = false;
}

Error Diags::ProcessFrame(uint8_t aArgsLength, char *aArgs[])
{
Error error = kErrorNone;
uint16_t size = OT_RADIO_FRAME_MAX_SIZE;
Error error = kErrorNone;
uint16_t size = OT_RADIO_FRAME_MAX_SIZE;
bool securityProcessed = false;

if (aArgsLength >= 1)
{
if (StringMatch(aArgs[0], "-s"))
{
securityProcessed = true;
aArgs++;
aArgsLength--;
}
}

VerifyOrExit(aArgsLength == 1, error = kErrorInvalidArgs);

SuccessOrExit(error = Utils::CmdLineParser::ParseAsHexString(aArgs[0], size, mTxPacket->mPsdu));
VerifyOrExit(size <= OT_RADIO_FRAME_MAX_SIZE, error = kErrorInvalidArgs);
VerifyOrExit(size >= OT_RADIO_FRAME_MIN_SIZE, error = kErrorInvalidArgs);
mTxPacket->mLength = size;
mIsTxPacketSet = true;

ResetTxPacket();
mTxPacket->mInfo.mTxInfo.mIsSecurityProcessed = securityProcessed;
mTxPacket->mLength = size;
mIsTxPacketSet = true;

exit:
AppendErrorResult(error);
Expand Down Expand Up @@ -468,6 +498,7 @@ void Diags::TransmitPacket(void)

if (!mIsTxPacketSet)
{
ResetTxPacket();
mTxPacket->mLength = mTxLen;

for (uint8_t i = 0; i < mTxLen; i++)
Expand Down
1 change: 1 addition & 0 deletions src/core/diags/factory_diags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Diags : public InstanceLocator, private NonCopyable
void TransmitPacket(void);
void Output(const char *aFormat, ...);
void AppendErrorResult(Error aError);
void ResetTxPacket(void);

static Error ParseLong(char *aString, long &aLong);
static Error ParseBool(char *aString, bool &aBool);
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/expect/cli-diags.exp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ send "diag repeat 1\n"
expect "length 0x7f"
expect "Done"

send_user "send frame with security processed\n"
send "diag frame -s 112233\n"
expect "Done"
send "diag send 1\n"
expect "length 0x3"
expect "Done"

send "diag repeat stop\n"
expect "Done"

Expand Down

0 comments on commit 95a4c33

Please sign in to comment.