Files
Yakun Xu 71e2f4b47f [diag] add radio address and promiscuous mode commands (#13720)
This commit introduces diagnostic commands to configure and query
lower-layer radio address filtering and promiscuous mode directly:
- `diag radio promiscuous [enable|disable]`
- `diag radio panid [panid]`
- `diag radio shortaddr [shortaddr]`
- `diag radio extaddr [extaddr]`

Difference from `diag radio receive filter`:
`diag radio receive filter` is a higher-layer software filter within
the diagnostics module that drops frames after they have already been
received by the radio driver and passed up the stack. In contrast, the
new commands (`diag radio panid|shortaddr|extaddr` and
`diag radio promiscuous`) directly configure the lower-layer radio
driver / RCP hardware registers. When promiscuous mode is disabled via
`diag radio promiscuous disable`, address filtering and ACK generation
are performed directly by the lower-layer radio hardware/RCP.

When entering diagnostics mode (`diag start`), the current PAN ID,
short address, and extended address are initialized from the MAC layer.
When exiting diagnostics mode (`diag stop`), the original address
settings and promiscuous mode (disabled) are automatically restored.
2026-10-22 11:13:20 -07:00

386 lines
8.7 KiB
Plaintext
Executable File

#!/usr/bin/expect -f
#
# Copyright (c) 2022, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
source "tests/scripts/expect/_common.exp"
source "tests/scripts/expect/_multinode.exp"
spawn_node 1
spawn_node 2
switch_node 1
send "diag start\n"
expect_line "Done"
send "diag channel 11\n"
expect_line "Done"
send "diag stats clear\n"
expect_line "Done"
switch_node 2
send "diag start\n"
expect_line "Done"
send "diag channel 11\n"
expect_line "Done"
send "diag stats clear\n"
expect_line "Done"
send "diag send 10 100\n"
expect_line "Done"
send "diag stats\n"
expect "received packets: 0"
expect "sent success packets: 10"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
expect "sent error invalid state packets: 0"
expect "sent error others packets: 0"
expect "first received packet: rssi=0, lqi=0"
expect "last received packet: rssi=0, lqi=0"
expect_line "Done"
send "diag send async 10 100\n"
expect_line "Done"
sleep 2
send "diag stats\n"
expect "received packets: 0"
expect "sent success packets: 20"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
expect "sent error others packets: 0"
expect "first received packet: rssi=0, lqi=0"
expect "last received packet: rssi=0, lqi=0"
expect_line "Done"
switch_node 1
send "diag stats\n"
expect "received packets: 20"
expect "sent success packets: 0"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
expect "sent error invalid state packets: 0"
expect "sent error others packets: 0"
expect "first received packet: rssi=-20, lqi=0"
expect "last received packet: rssi=-20, lqi=0"
expect_line "Done"
send "diag stats clear\n"
expect_line "Done"
switch_node 2
send "diag repeat 20 100\n"
expect_line "Done"
sleep 1
send "diag repeat stop\n"
expect_line "Done"
switch_node 1
send "diag stats\n"
expect -r {received packets: \d+}
expect "sent success packets: 0"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
expect "sent error invalid state packets: 0"
expect "sent error others packets: 0"
expect "first received packet: rssi=-20, lqi=0"
expect "last received packet: rssi=-20, lqi=0"
expect_line "Done"
send "diag stats clear\n"
expect_line "Done"
dispose_all
spawn_node 1
send "diag start\n"
expect_line "Done"
send_user "input too short test\n"
send "diag frame 11\n"
expect "Error"
send_user "input too long test\n"
send "diag frame 11223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900\n"
expect "Error"
send_user "input odd length test\n"
send "diag frame 123\n"
expect "Error"
send "diag radio sleep\n"
expect_line "Done"
send "diag radio disable\n"
expect_line "Done"
send "diag send 10 10\n"
expect "Error 13: InvalidState"
send "diag radio enable\n"
expect_line "Done"
send "diag radio receive\n"
expect_line "Done"
send "diag repeat 100 100\n"
expect "Done"
send "diag send 1 10\n"
expect "Error 13: InvalidState"
send "diag repeat stop\n"
expect "Done"
send "diag send 1 10\n"
expect "Done"
send_user "shortest frame test\n"
send "diag frame 112233\n"
expect "Done"
send "diag send 1\n"
expect "Done"
send_user "longest frame test\n"
send "diag frame 11223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677\n"
expect "Done"
send "diag repeat 1\n"
expect "Done"
sleep 3
send "diag repeat stop\n"
expect "Done"
send "diag repeat stop\n"
expect "Done"
send_user "send frame with security processed\n"
send "diag frame -s 112233\n"
expect "Done"
send "diag send 1\n"
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 "Done"
send_user "send frame with tx power\n"
send "diag frame -p 11 112233\n"
expect "Done"
send "diag send 1\n"
expect "Done"
send "diag channel 11\n"
expect_line "Done"
send "diag power 10\n"
expect_line "Done"
send "diag radio sleep\n"
expect_line "Done"
send "diag radio state\n"
expect "sleep"
expect_line "Done"
send "diag radio receive\n"
expect_line "Done"
send "diag radio state\n"
expect "receive"
expect_line "Done"
send "diag gpio set 0 1\n"
expect_line "Done"
send "diag gpio get 0\n"
expect "1"
expect_line "Done"
send "diag gpio mode 0 in\n"
expect_line "Done"
send "diag gpio mode 0\n"
expect "in"
expect_line "Done"
send "diag gpio mode 0 out\n"
expect_line "Done"
send "diag gpio mode 0\n"
expect "out"
expect_line "Done"
send "diag cw start\n"
expect_line "Done"
send "diag cw stop\n"
expect_line "Done"
send "diag stream start\n"
expect_line "Done"
send "diag stream stop\n"
expect_line "Done"
send "diag rawpowersetting 112233\n"
expect_line "Done"
send "diag rawpowersetting\n"
expect "112233"
expect_line "Done"
send "diag rawpowersetting enable\n"
expect_line "Done"
send "diag rawpowersetting disable\n"
expect_line "Done"
send_user "radio promiscuous test\n"
send "diag radio promiscuous\n"
expect_line "enabled"
expect_line "Done"
send "diag radio promiscuous disable\n"
expect_line "Done"
send "diag radio promiscuous\n"
expect_line "disabled"
expect_line "Done"
send "diag radio promiscuous enable\n"
expect_line "Done"
send "diag radio promiscuous\n"
expect_line "enabled"
expect_line "Done"
send "diag radio promiscuous invalid\n"
expect "Error 7: InvalidArgs"
send "diag radio promiscuous enable foo\n"
expect "Error 7: InvalidArgs"
send_user "radio panid test\n"
send "diag radio panid 0x1234\n"
expect_line "Done"
send "diag radio panid\n"
expect_line "0x1234"
expect_line "Done"
send "diag radio panid 0x12345\n"
expect "Error 7: InvalidArgs"
send "diag radio panid 0x1234 foo\n"
expect "Error 7: InvalidArgs"
send_user "radio shortaddr test\n"
send "diag radio shortaddr 0xaaaa\n"
expect_line "Done"
send "diag radio shortaddr\n"
expect_line "0xaaaa"
expect_line "Done"
send "diag radio shortaddr invalid\n"
expect "Error 7: InvalidArgs"
send "diag radio shortaddr 0xaaaa foo\n"
expect "Error 7: InvalidArgs"
send_user "radio extaddr test\n"
send "diag radio extaddr 8070605040302010\n"
expect_line "Done"
send "diag radio extaddr\n"
expect_line "8070605040302010"
expect_line "Done"
send "diag radio extaddr 80706050403020\n"
expect "Error 7: InvalidArgs"
send "diag radio extaddr 807060504030201000\n"
expect "Error 7: InvalidArgs"
send "diag radio extaddr 8070605040302010 foo\n"
expect "Error 7: InvalidArgs"
send "diag invalid_commad\n"
expect "Error 35: InvalidCommand"
send "diag stop\n"
expect_line "Done"
send "diag channel\n"
expect "Error 13: InvalidState"
send_user "radio address reset test\n"
send "panid\n"
set panid [expect_line {0x[0-9a-f]{4}}]
expect_line "Done"
send "extaddr\n"
set extaddr [expect_line {[0-9a-f]{16}}]
expect_line "Done"
send "diag start\n"
expect_line "Done"
send "diag radio promiscuous\n"
expect_line "enabled"
expect_line "Done"
send "diag radio panid\n"
expect_line $panid
expect_line "Done"
send "diag radio shortaddr\n"
expect_line "0xfffe"
expect_line "Done"
send "diag radio extaddr\n"
expect_line $extaddr
expect_line "Done"
send "diag stop\n"
expect_line "Done"
dispose_all