77#include "ot_shell.h"
88#include <net/ot_rpc.h>
99
10- #include <zephyr/shell/shell.h>
1110#include <zephyr/net/net_ip.h>
11+ #include <zephyr/shell/shell.h>
1212
1313#include <openthread/cli.h>
1414#include <openthread/coap.h>
15+ #include <openthread/dns_client.h>
16+ #include <openthread/instance.h>
1517#include <openthread/ip6.h>
16- #include <openthread/link.h>
1718#include <openthread/link_raw.h>
18- #include <openthread/thread.h>
19- #include <openthread/udp.h>
19+ #include <openthread/link.h>
20+ #include <openthread/mesh_diag.h>
21+ #include <openthread/message.h>
2022#include <openthread/netdata.h>
2123#include <openthread/netdiag.h>
22- #include <openthread/message.h>
23- #include <openthread/mesh_diag.h>
2424#include <openthread/srp_client.h>
25- #include <openthread/dns_client.h>
25+ #include <openthread/thread.h>
26+ #include <openthread/udp.h>
2627
2728#include <string.h>
2829
@@ -142,7 +143,7 @@ static int ot_cli_command_send(const struct shell *sh, size_t argc, char *argv[]
142143
143144 ot_cli_lazy_init (sh );
144145
145- for (size_t i = 1 ; i < argc ; i ++ ) {
146+ for (size_t i = 0 ; i < argc ; i ++ ) {
146147 int arg_len = snprintk (ptr , end - ptr , "%s" , argv [i ]);
147148
148149 if (arg_len < 0 ) {
@@ -152,7 +153,7 @@ static int ot_cli_command_send(const struct shell *sh, size_t argc, char *argv[]
152153 ptr += arg_len ;
153154
154155 if (ptr >= end ) {
155- shell_fprintf (sh , SHELL_WARNING , "OT shell buffer full\n " );
156+ shell_warn (sh , "OT shell buffer full" );
156157 return - ENOEXEC ;
157158 }
158159
@@ -238,7 +239,7 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
238239 return ot_cli_command_exec (ot_cli_command_discover , sh , argc , argv );
239240}
240241
241- static otError ot_cli_command_radio (const struct shell * sh , size_t argc , char * argv [])
242+ static otError cmd_radio_impl (const struct shell * sh , size_t argc , char * argv [])
242243{
243244 if (argc != 2 || strcmp (argv [1 ], "time" ) != 0 ) {
244245 return OT_ERROR_INVALID_COMMAND ;
@@ -252,10 +253,10 @@ static otError ot_cli_command_radio(const struct shell *sh, size_t argc, char *a
252253static int cmd_radio (const struct shell * sh , size_t argc , char * argv [])
253254{
254255 if (argc == 2 && strcmp (argv [1 ], "time" ) == 0 ) {
255- return ot_cli_command_exec (ot_cli_command_radio , sh , argc , argv );
256+ return ot_cli_command_exec (cmd_radio_impl , sh , argc , argv );
256257 }
257258
258- return ot_cli_command_send (sh , argc + 1 , argv - 1 );
259+ return ot_cli_command_send (sh , argc , argv );
259260}
260261
261262static otError ot_cli_command_ifconfig (const struct shell * sh , size_t argc , char * argv [])
@@ -441,7 +442,7 @@ static int cmd_state(const struct shell *sh, size_t argc, char *argv[])
441442 * Serialization of OT APIs for enforcing the role is to be done,
442443 * so send the command to be processed by the RPC server.
443444 */
444- return ot_cli_command_send (sh , argc + 1 , argv - 1 );
445+ return ot_cli_command_send (sh , argc , argv );
445446 }
446447
447448 return ot_cli_command_exec (ot_cli_command_state , sh , argc , argv );
@@ -731,7 +732,7 @@ static int cmd_test_coap_stop(const struct shell *sh, size_t argc, char *argv[])
731732
732733static int cmd_ot (const struct shell * sh , size_t argc , char * argv [])
733734{
734- return ot_cli_command_send (sh , argc , argv );
735+ return ot_cli_command_send (sh , argc - 1 , argv + 1 );
735736}
736737
737738static int cmd_test_srp_client_autostart (const struct shell * sh , size_t argc , char * argv [])
@@ -2089,19 +2090,212 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
20892090 SHELL_CMD_ARG (send , NULL , "Send message [addr port] <message>" , cmd_udp_send , 2 , 2 ),
20902091 SHELL_CMD_ARG (close , NULL , "Close socket" , cmd_udp_close , 1 , 0 ), SHELL_SUBCMD_SET_END );
20912092
2093+ static otError cmd_channel_impl (const struct shell * sh , size_t argc , char * argv [])
2094+ {
2095+ shell_print (sh , "%u" , otLinkGetChannel (NULL ));
2096+ return OT_ERROR_NONE ;
2097+ }
2098+
2099+ static int cmd_channel (const struct shell * sh , size_t argc , char * argv [])
2100+ {
2101+ if (argc == 1 ) {
2102+ return ot_cli_command_exec (cmd_channel_impl , sh , argc , argv );
2103+ }
2104+
2105+ return ot_cli_command_send (sh , argc , argv );
2106+ }
2107+
2108+ static otError cmd_counters_mac_impl (const struct shell * sh , size_t argc , char * argv [])
2109+ {
2110+ const otMacCounters * counters = otLinkGetCounters (NULL );
2111+
2112+ shell_print (sh , "TxTotal: %u" , counters -> mTxTotal );
2113+
2114+ shell_print (sh , " TxUnicast: %u" , counters -> mTxUnicast );
2115+ shell_print (sh , " TxBroadcast: %u" , counters -> mTxBroadcast );
2116+ shell_print (sh , " TxAckRequested: %u" , counters -> mTxAckRequested );
2117+ shell_print (sh , " TxAcked: %u" , counters -> mTxAcked );
2118+ shell_print (sh , " TxNoAckRequested: %u" , counters -> mTxNoAckRequested );
2119+ shell_print (sh , " TxData: %u" , counters -> mTxData );
2120+ shell_print (sh , " TxDataPoll: %u" , counters -> mTxDataPoll );
2121+ shell_print (sh , " TxBeacon: %u" , counters -> mTxBeacon );
2122+ shell_print (sh , " TxBeaconRequest: %u" , counters -> mTxBeaconRequest );
2123+ shell_print (sh , " TxOther: %u" , counters -> mTxOther );
2124+ shell_print (sh , " TxRetry: %u" , counters -> mTxRetry );
2125+ shell_print (sh , " TxErrCca: %u" , counters -> mTxErrCca );
2126+ shell_print (sh , " TxErrBusyChannel: %u" , counters -> mTxErrBusyChannel );
2127+ shell_print (sh , " TxErrAbort: %u" , counters -> mTxErrAbort );
2128+ shell_print (sh , " TxDirectMaxRetryExpiry: %u" , counters -> mTxDirectMaxRetryExpiry );
2129+ shell_print (sh , " TxIndirectMaxRetryExpiry: %u" , counters -> mTxIndirectMaxRetryExpiry );
2130+
2131+ shell_print (sh , "RxTotal: %u" , counters -> mRxTotal );
2132+
2133+ shell_print (sh , " RxUnicast: %u" , counters -> mRxUnicast );
2134+ shell_print (sh , " RxBroadcast: %u" , counters -> mRxBroadcast );
2135+ shell_print (sh , " RxData: %u" , counters -> mRxData );
2136+ shell_print (sh , " RxDataPoll: %u" , counters -> mRxDataPoll );
2137+ shell_print (sh , " RxBeacon: %u" , counters -> mRxBeacon );
2138+ shell_print (sh , " RxBeaconRequest: %u" , counters -> mRxBeaconRequest );
2139+ shell_print (sh , " RxOther: %u" , counters -> mRxOther );
2140+ shell_print (sh , " RxAddressFiltered: %u" , counters -> mRxAddressFiltered );
2141+ shell_print (sh , " RxDestAddrFiltered: %u" , counters -> mRxDestAddrFiltered );
2142+ shell_print (sh , " RxDuplicated: %u" , counters -> mRxDuplicated );
2143+ shell_print (sh , " RxErrNoFrame: %u" , counters -> mRxErrNoFrame );
2144+ shell_print (sh , " RxErrNoUnknownNeighbor: %u" , counters -> mRxErrUnknownNeighbor );
2145+ shell_print (sh , " RxErrInvalidSrcAddr: %u" , counters -> mRxErrInvalidSrcAddr );
2146+ shell_print (sh , " RxErrSec: %u" , counters -> mRxErrSec );
2147+ shell_print (sh , " RxErrFcs: %u" , counters -> mRxErrFcs );
2148+ shell_print (sh , " RxErrOther: %u" , counters -> mRxErrOther );
2149+
2150+ return OT_ERROR_NONE ;
2151+ }
2152+
2153+ static int cmd_counters_mac (const struct shell * sh , size_t argc , char * argv [])
2154+ {
2155+ if (argc == 1 ) {
2156+ return ot_cli_command_exec (cmd_counters_mac_impl , sh , argc , argv );
2157+ }
2158+
2159+ return ot_cli_command_send (sh , argc + 1 , argv - 1 );
2160+ }
2161+
2162+ static otError cmd_counters_mle_impl (const struct shell * sh , size_t argc , char * argv [])
2163+ {
2164+ const otMleCounters * counters = otThreadGetMleCounters (NULL );
2165+
2166+ shell_print (sh , "Role Disabled: %u" , counters -> mDisabledRole );
2167+ shell_print (sh , "Role Detached: %u" , counters -> mDetachedRole );
2168+ shell_print (sh , "Role Child: %u" , counters -> mChildRole );
2169+ shell_print (sh , "Role Router: %u" , counters -> mRouterRole );
2170+ shell_print (sh , "Role Leader: %u" , counters -> mLeaderRole );
2171+ shell_print (sh , "Attach Attempts: %u" , counters -> mAttachAttempts );
2172+ shell_print (sh , "Partition Id Changes: %u" , counters -> mPartitionIdChanges );
2173+ shell_print (sh , "Better Partition Attach Attempts: %u" ,
2174+ counters -> mBetterPartitionAttachAttempts );
2175+ shell_print (sh , "Parent Changes: %u" , counters -> mParentChanges );
2176+ shell_print (sh , "Time Disabled Milli: %llu" , counters -> mDisabledTime );
2177+ shell_print (sh , "Time Detached Milli: %llu" , counters -> mDetachedTime );
2178+ shell_print (sh , "Time Child Milli: %llu" , counters -> mChildTime );
2179+ shell_print (sh , "Time Router Milli: %llu" , counters -> mRouterTime );
2180+ shell_print (sh , "Time Leader Milli: %llu" , counters -> mLeaderTime );
2181+ shell_print (sh , "Time Tracked Milli: %llu" , counters -> mTrackedTime );
2182+
2183+ return OT_ERROR_NONE ;
2184+ }
2185+
2186+ static int cmd_counters_mle (const struct shell * sh , size_t argc , char * argv [])
2187+ {
2188+ if (argc == 1 ) {
2189+ return ot_cli_command_exec (cmd_counters_mle_impl , sh , argc , argv );
2190+ }
2191+
2192+ return ot_cli_command_send (sh , argc + 1 , argv - 1 );
2193+ }
2194+
2195+ SHELL_STATIC_SUBCMD_SET_CREATE (counters_cmds ,
2196+ SHELL_CMD_ARG (mac , NULL , "MAC counters" , cmd_counters_mac , 1 , 1 ),
2197+ SHELL_CMD_ARG (mle , NULL , "MLE counters" , cmd_counters_mle , 1 , 1 ),
2198+ SHELL_SUBCMD_SET_END );
2199+
2200+ static otError cmd_extaddr_impl (const struct shell * sh , size_t argc , char * argv [])
2201+ {
2202+ const otExtAddress * ext_addr = otLinkGetExtendedAddress (NULL );
2203+
2204+ shell_print (sh , "%016llx" , sys_get_be64 (ext_addr -> m8 ));
2205+
2206+ return OT_ERROR_NONE ;
2207+ }
2208+
2209+ static int cmd_extaddr (const struct shell * sh , size_t argc , char * argv [])
2210+ {
2211+ if (argc == 1 ) {
2212+ return ot_cli_command_exec (cmd_extaddr_impl , sh , argc , argv );
2213+ }
2214+
2215+ return ot_cli_command_send (sh , argc , argv );
2216+ }
2217+
2218+ static otError cmd_networkname_impl (const struct shell * sh , size_t argc , char * argv [])
2219+ {
2220+ shell_print (sh , "%s" , otThreadGetNetworkName (NULL ));
2221+ return OT_ERROR_NONE ;
2222+ }
2223+
2224+ static int cmd_networkname (const struct shell * sh , size_t argc , char * argv [])
2225+ {
2226+ if (argc == 1 ) {
2227+ return ot_cli_command_exec (cmd_networkname_impl , sh , argc , argv );
2228+ }
2229+
2230+ return ot_cli_command_send (sh , argc , argv );
2231+ }
2232+
2233+ static otError cmd_panid_impl (const struct shell * sh , size_t argc , char * argv [])
2234+ {
2235+ shell_print (sh , "0x%04x" , otLinkGetPanId (NULL ));
2236+ return OT_ERROR_NONE ;
2237+ }
2238+
2239+ static int cmd_panid (const struct shell * sh , size_t argc , char * argv [])
2240+ {
2241+ if (argc == 1 ) {
2242+ return ot_cli_command_exec (cmd_panid_impl , sh , argc , argv );
2243+ }
2244+
2245+ return ot_cli_command_send (sh , argc , argv );
2246+ }
2247+
2248+ static otError cmd_partitionid_impl (const struct shell * sh , size_t argc , char * argv [])
2249+ {
2250+ shell_print (sh , "%u" , otThreadGetPartitionId (NULL ));
2251+ return OT_ERROR_NONE ;
2252+ }
2253+
2254+ static int cmd_partitionid (const struct shell * sh , size_t argc , char * argv [])
2255+ {
2256+ if (argc == 1 ) {
2257+ return ot_cli_command_exec (cmd_partitionid_impl , sh , argc , argv );
2258+ }
2259+
2260+ return ot_cli_command_send (sh , argc , argv );
2261+ }
2262+
2263+ static otError cmd_version_impl (const struct shell * sh , size_t argc , char * argv [])
2264+ {
2265+ shell_print (sh , "%s" , otGetVersionString ());
2266+ return OT_ERROR_NONE ;
2267+ }
2268+
2269+ static int cmd_version (const struct shell * sh , size_t argc , char * argv [])
2270+ {
2271+ if (argc == 1 ) {
2272+ return ot_cli_command_exec (cmd_version_impl , sh , argc , argv );
2273+ }
2274+
2275+ return ot_cli_command_send (sh , argc , argv );
2276+ }
2277+
20922278SHELL_STATIC_SUBCMD_SET_CREATE (
2093- ot_cmds , SHELL_CMD_ARG (ifconfig , NULL , "Interface management" , cmd_ifconfig , 1 , 1 ),
2279+ ot_cmds , SHELL_CMD_ARG (channel , NULL , "Channel configuration" , cmd_channel , 1 , 255 ),
2280+ SHELL_CMD_ARG (cli , NULL , "Send command as text" , cmd_ot , 1 , 255 ),
2281+ SHELL_CMD_ARG (counters , & counters_cmds , "Counters subcommands" , NULL , 1 , 0 ),
2282+ SHELL_CMD_ARG (discover , NULL , "Thread discovery scan" , cmd_discover , 1 , 4 ),
2283+ SHELL_CMD_ARG (eui64 , NULL , "EUI64 configuration" , cmd_eui64 , 1 , 1 ),
2284+ SHELL_CMD_ARG (extaddr , NULL , "Ext address configuration" , cmd_extaddr , 1 , 1 ),
2285+ SHELL_CMD_ARG (factoryreset , NULL , "Factory reset" , cmd_factoryreset , 1 , 0 ),
2286+ SHELL_CMD_ARG (ifconfig , NULL , "Interface management" , cmd_ifconfig , 1 , 1 ),
20942287 SHELL_CMD_ARG (ipmaddr , NULL , "IPv6 multicast configuration" , cmd_ipmaddr , 1 , 2 ),
20952288 SHELL_CMD_ARG (mode , NULL , "Mode configuration" , cmd_mode , 1 , 1 ),
2289+ SHELL_CMD_ARG (networkname , NULL , "Network name configuration" , cmd_networkname , 1 , 1 ),
2290+ SHELL_CMD_ARG (panid , NULL , "PAN ID configuration" , cmd_panid , 1 , 1 ),
2291+ SHELL_CMD_ARG (partitionid , NULL , "Partition configuration" , cmd_partitionid , 1 , 2 ),
20962292 SHELL_CMD_ARG (pollperiod , NULL , "Polling configuration" , cmd_pollperiod , 1 , 1 ),
2097- SHELL_CMD_ARG (state , NULL , "Current role" , cmd_state , 1 , 1 ),
2098- SHELL_CMD_ARG (thread , NULL , "Role management" , cmd_thread , 2 , 0 ),
2099- SHELL_CMD_ARG (discover , NULL , "Thread discovery scan" , cmd_discover , 1 , 4 ),
21002293 SHELL_CMD_ARG (radio , NULL , "Radio configuration" , cmd_radio , 1 , 1 ),
2101- SHELL_CMD_ARG (eui64 , NULL , "EUI64 configuration" , cmd_eui64 , 1 , 1 ),
21022294 SHELL_CMD_ARG (rloc16 , NULL , "Get RLOC16" , cmd_rloc16 , 1 , 0 ),
2295+ SHELL_CMD_ARG (state , NULL , "Current role" , cmd_state , 1 , 1 ),
2296+ SHELL_CMD_ARG (thread , NULL , "Role management" , cmd_thread , 2 , 0 ),
21032297 SHELL_CMD_ARG (udp , & udp_cmds , "UDP subcommands" , NULL , 1 , 0 ),
2104- SHELL_CMD_ARG (factoryreset , NULL , "Factory reset " , cmd_factoryreset , 1 , 0 ),
2298+ SHELL_CMD_ARG (version , NULL , "Get version " , cmd_version , 1 , 1 ),
21052299 SHELL_CMD_ARG (test_message , NULL , "Test message API" , cmd_test_message , 1 , 0 ),
21062300 SHELL_CMD_ARG (test_net_data , NULL , "Test netdata API" , cmd_test_net_data , 1 , 0 ),
21072301 SHELL_CMD_ARG (test_net_data_mesh_prefix , NULL , "Test netdata msh prefix API" ,
0 commit comments