From 5756b9db6626bdc8f7cc94dae3f305ac361ec20e Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 19 Feb 2021 09:36:26 -0800 Subject: [PATCH] [cli] add CLI commands for multi-radio feature (#6178) This commit adds new CLI command `multiradio` to get the list of supported radio types by device and `multiradio neighbor` sub-command to get the radio info (supported radios and the their preference) for specific neighbor or for all neighbors. --- src/cli/README.md | 38 ++++++++++++++++++++ src/cli/cli.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++ src/cli/cli.hpp | 5 +++ 3 files changed, 131 insertions(+) diff --git a/src/cli/README.md b/src/cli/README.md index cf432adf4..7d5356060 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -67,6 +67,7 @@ Done - [masterkey](#masterkey) - [mlr](#mlr-reg-ipaddr--timeout) - [mode](#mode) +- [multiradio](#multiradio) - [neighbor](#neighbor-list) - [netdata](README_NETDATA.md) - [netstat](#netstat) @@ -1404,6 +1405,43 @@ Done Done ``` +### multiradio + +Get the list of supported radio links by the device. + +This command is always available, even when only a single radio is supported by the device. + +```bash +> multiradio +[15.4, TREL] +Done +``` + +### multiradio neighbor list + +Get the list of neighbors and their supported radios and their preference. + +This command is only available when device supports more than one radio link. + +```bash +> multiradio neighbor list +ExtAddr:3a65bc38dbe4a5be, RLOC16:0xcc00, Radios:[15.4(255), TREL(255)] +ExtAddr:17df23452ee4a4be, RLOC16:0x1300, Radios:[15.4(255)] +Done +``` + +### multiradio neighbor \ + +Get the radio info for specific neighbor with a given extended address. + +This command is only available when device supports more than one radio link. + +```bash +> multiradio neighbor 3a65bc38dbe4a5be +[15.4(255), TREL(255)] +Done +``` + ### neighbor list List RLOC16 of neighbors. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 66580256b..2d8c70341 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2639,6 +2639,94 @@ exit: return error; } +otError Interpreter::ProcessMultiRadio(uint8_t aArgsLength, char *aArgs[]) +{ + otError error = OT_ERROR_NONE; + + OT_UNUSED_VARIABLE(aArgs); + + if (aArgsLength == 0) + { + bool isFirst = true; + + OutputFormat("["); +#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE + OutputFormat("15.4"); + isFirst = false; +#endif +#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE + OutputFormat("%sTREL", isFirst ? "" : ", "); +#endif + OutputLine("]"); + + OT_UNUSED_VARIABLE(isFirst); + } +#if OPENTHREAD_CONFIG_MULTI_RADIO + else if (strcmp(aArgs[0], "neighbor") == 0) + { + otMultiRadioNeighborInfo multiRadioInfo; + + VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS); + + if (strcmp(aArgs[1], "list") == 0) + { + otNeighborInfoIterator iterator = OT_NEIGHBOR_INFO_ITERATOR_INIT; + otNeighborInfo neighInfo; + + while (otThreadGetNextNeighborInfo(mInstance, &iterator, &neighInfo) == OT_ERROR_NONE) + { + if (otMultiRadioGetNeighborInfo(mInstance, &neighInfo.mExtAddress, &multiRadioInfo) != OT_ERROR_NONE) + { + continue; + } + + OutputFormat("ExtAddr:"); + OutputExtAddress(neighInfo.mExtAddress); + OutputFormat(", RLOC16:0x%04x, Radios:", neighInfo.mRloc16); + OutputMultiRadioInfo(multiRadioInfo); + } + } + else + { + otExtAddress extAddress; + + SuccessOrExit(error = ParseAsHexString(aArgs[1], extAddress.m8)); + SuccessOrExit(error = otMultiRadioGetNeighborInfo(mInstance, &extAddress, &multiRadioInfo)); + OutputMultiRadioInfo(multiRadioInfo); + } + } +#endif // OPENTHREAD_CONFIG_MULTI_RADIO + else + { + ExitNow(error = OT_ERROR_INVALID_COMMAND); + } + +exit: + return error; +} + +#if OPENTHREAD_CONFIG_MULTI_RADIO +void Interpreter::OutputMultiRadioInfo(const otMultiRadioNeighborInfo &aMultiRadioInfo) +{ + bool isFirst = true; + + OutputFormat("["); + + if (aMultiRadioInfo.mSupportsIeee802154) + { + OutputFormat("15.4(%d)", aMultiRadioInfo.mIeee802154Info.mPreference); + isFirst = false; + } + + if (aMultiRadioInfo.mSupportsTrelUdp6) + { + OutputFormat("%sTREL(%d)", isFirst ? "" : ", ", aMultiRadioInfo.mTrelUdp6Info.mPreference); + } + + OutputLine("]"); +} +#endif // OPENTHREAD_CONFIG_MULTI_RADIO + #if OPENTHREAD_FTD otError Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]) { diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index cf0a9e5ef..0462c80a3 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -424,6 +424,10 @@ private: uint8_t aFailedAddressNum); #endif otError ProcessMode(uint8_t aArgsLength, char *aArgs[]); + otError ProcessMultiRadio(uint8_t aArgsLength, char *aArgsp[]); +#if OPENTHREAD_CONFIG_MULTI_RADIO + void OutputMultiRadioInfo(const otMultiRadioNeighborInfo &aMultiRadioInfo); +#endif #if OPENTHREAD_FTD otError ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]); #endif @@ -711,6 +715,7 @@ private: {"mlr", &Interpreter::ProcessMlr}, #endif {"mode", &Interpreter::ProcessMode}, + {"multiradio", &Interpreter::ProcessMultiRadio}, #if OPENTHREAD_FTD {"neighbor", &Interpreter::ProcessNeighbor}, #endif