Skip to content

Commit

Permalink
[diag] add flag to enable CSMA/CA (openthread#10723)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukepo authored Sep 18, 2024
1 parent fa3509e commit c6a4657
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 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,11 +80,12 @@ Done

### diag frame

Usage: `diag frame [-s] <frame>`
Usage: `diag frame [-c] [-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.
- 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.

```bash
> diag frame 11223344
Expand Down
17 changes: 14 additions & 3 deletions src/core/diags/factory_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,25 @@ Error Diags::ProcessFrame(uint8_t aArgsLength, char *aArgs[])
Error error = kErrorNone;
uint16_t size = OT_RADIO_FRAME_MAX_SIZE;
bool securityProcessed = false;
bool csmaCaEnabled = false;

if (aArgsLength >= 1)
while (aArgsLength > 1)
{
if (StringMatch(aArgs[0], "-s"))
{
securityProcessed = true;
aArgs++;
aArgsLength--;
}
else if (StringMatch(aArgs[0], "-c"))
{
csmaCaEnabled = true;
}
else
{
ExitNow(error = kErrorInvalidArgs);
}

aArgs++;
aArgsLength--;
}

VerifyOrExit(aArgsLength == 1, error = kErrorInvalidArgs);
Expand All @@ -254,6 +264,7 @@ Error Diags::ProcessFrame(uint8_t aArgsLength, char *aArgs[])
VerifyOrExit(size >= OT_RADIO_FRAME_MIN_SIZE, error = kErrorInvalidArgs);

ResetTxPacket();
mTxPacket->mInfo.mTxInfo.mCsmaCaEnabled = csmaCaEnabled;
mTxPacket->mInfo.mTxInfo.mIsSecurityProcessed = securityProcessed;
mTxPacket->mLength = size;
mIsTxPacketSet = true;
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 @@ -159,6 +159,13 @@ send "diag send 1\n"
expect "length 0x3"
expect "Done"

send_user "send frame with CSMA/CA enabled\n"
send "diag frame -c 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 c6a4657

Please sign in to comment.