[diag] support send security processed frames (#10640)

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.
This commit is contained in:
Yakun Xu
2024-08-27 18:35:04 -07:00
committed by GitHub
parent a30cbda8ae
commit 95a4c338e0
4 changed files with 49 additions and 5 deletions
+6 -1
View File
@@ -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)
@@ -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
+35 -4
View File
@@ -33,6 +33,7 @@
#include "factory_diags.hpp"
#include "common/error.hpp"
#include "openthread/platform/radio.h"
#if OPENTHREAD_CONFIG_DIAG_ENABLE
@@ -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);
@@ -468,6 +498,7 @@ void Diags::TransmitPacket(void)
if (!mIsTxPacketSet)
{
ResetTxPacket();
mTxPacket->mLength = mTxLen;
for (uint8_t i = 0; i < mTxLen; i++)
+1
View File
@@ -210,6 +210,7 @@ private:
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);
+7
View File
@@ -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"