Commit Graph

76 Commits

Author SHA1 Message Date
Li Cao 8dadae2ea1 [format] upgrade clang-format to 19 (#11783)
We just updated the version from 14 to 16. But very unfortunately
clang-format-16 was just deprecated recently. So this time we update
the version to the latest available one. There are newer releases than
19 (like 20) but as I tested, sudo apt-get install -y clang-format-19
can work while 20 doesn't work.

misc-include-cleaner in clang-tidy-19 exerts a very strict check which
requires to directly include all headers for every symbols in the
source file. However in our current code we intentionally use some
indirect include. So this commit disables misc-include-cleaner.
2025-08-06 10:49:52 -07:00
Marius Preda c25120edc0 [cli] update default bind interface (#11187)
This commit updates the default CLI bind interface to be consistent with
the description. The default behavior should apply to all Thread nodes,
not just devices that define UDP platform layer. For Thread nodes that
only use the Open Thread Stack, netif type OT_NETIF_THREAD_HOST has no
meaning.

Support for OT_NETIF_THREAD_HOST has been kept using the -h option.

Updated the CLI bind command readme to make it clear when the netif
options are valid and what is the default behavior.

Signed-off-by: Marius Preda <marius.preda@nxp.com>
2025-01-27 20:02:57 -08:00
Abtin Keshavarzian 473af53155 [udp] add kNetifThreadInternal which disallows platform UDP use (#10965)
This commit introduces `kNetifThreadInternal` as a network interface
option for UDP sockets. Unlike other options, this disallows the use
of platform UDP for the socket, indicating that the socket should use
the OpenThread internal Thread network interface only.

This model replaces the previous approach where `ShouldUsePlatformUdp()`
would check the socket port against a set of port numbers used by
different modules (such as MLE, TMF, Joiner Router, etc) to determine
whether platform UDP APIs should be used. With the new model, each
module decides whether to associate its socket with the
`kNetifThreadInternal`.

This is a more flexible and extensible model, ensuring that sockets
that should not use the platform do not waste resources (they will
not be created or opened/closed on the platform). This also help
avoid edge cases where platform UDP operations may unintentionally
fail when the platform socket is not actually needed.
2024-11-28 08:58:19 -08:00
Esko Dijk a46786b0e8 [cli] udp bind doc update to clarify that multicast address cannot be used as argument (#10370) 2024-06-18 09:17:11 -07:00
Dávid Fehér 1fceb225b3 [cli] add UDP socket openness check before sending with udp send (#10206)
Problem: Executing the `udp send` command in CLI without previously
opening the example udp socket results in an unhandled null-pointer
exception.

Solution: Before anything is processed in the
`UdpExample::Process<Cmd("send")>(Arg aArgs[])` method, the UDP socket
is checked whether it's open or not. If not, the method returns with
OT_ERROR_INVALID_STATE error avoiding the null-pointer exception.
2024-05-09 07:41:54 -07:00
Li Cao 3bf281d32d [cli] move a few static util methods to Cli::Utils class (#10138)
This commit moves a few static util methods from the `Interpreter`
class to the `Cli::Utils` class. Since the `Interpreter` class and
other classes for cli components inherit the `Cli::Utils`, they can
still access these methods. Putting these methods in utils class is
more intuitive. This change also makes other cli classes less
dependent on the `Interpreter` class.
2024-05-01 10:56:18 -07:00
Li Cao da72435f3a [cli] fix namespace usage (#10088)
The method `ParseEnableOrDisable` has been moved to the `Utils` class
and these components inherit the `Utils` class so there is no need to
add namespace.
2024-04-29 14:15:50 -07:00
Li Cao 7d6580ee3c [cli] move Process{Get/Set/Enable/Disable} methods to Utils class (#9951)
This commit moves the `Process{Get/Set/Enable/Disable}` methods to the
Output class and rename the `Output` class to `Utils`.  The purpose is
to reduce code size in the Interpreter class to make the class focus
more on the command handling and easier for further refactoring.

The commit also removes the alias typedef of `Arg` in each cli module
because they are unnecessary. Having one definition in the parent
class is enough.
2024-03-22 10:35:46 -07:00
Abtin Keshavarzian a0d805c8f0 [cli] style fixes & remove core defined error constants (#9868)
This commit contains small changes in the CLI modules:

- Replace use of core-internal `kError` with `OT_ERROR` constants.
- Remove `#endif` comments when the corresponding `#if` is less
  than 20 lines away adhering to OT style guide.
- Adhere to single `return` policy (use `ExitNow()`).
- Avoid calling `static` method `ParseToIp6Address()` with an object.
- Smaller style fixes: New lines after variable declaration, use
  shorter local variable names, etc.
2024-02-22 11:29:38 -08:00
jrhodie 6cfe14c941 [cli] add references to CoAP concepts guide from CLI (#9856) 2024-02-20 12:50:22 -08:00
Abtin Keshavarzian 686eb30e9a [common] add ClearAllBytes() template function (#9818)
This commit introduces the `ClearAllBytes<ObjectType>()` template
function to zero out all bytes within an object. This replaces
`memset(0)` calls in OT core modules, simplifying code and improving
safety by automatically using the correct object size.
2024-02-01 11:58:47 -08:00
Abtin Keshavarzian 7761b81d23 [cli] use static constexpr for constants instead of of enum (#9789) 2024-01-22 23:08:29 -08:00
jrhodie d26f4e59a2 [docs] added xrefs from UDP CLI to UDP Concepts Guide (#9558) 2023-10-24 01:01:38 -07:00
jrhodie be317ecb73 [docs] UDP commands - added Doxygen tags (#9504) 2023-10-11 13:27:37 -07:00
Jonathan Hui 3d39d24a21 [style] fix spelling errors (#8939) 2023-04-11 22:39:35 -07:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian f5acfb2dac [cli] update CLI Output class (#8343)
This commit updates the `Cli::Output` class and the related types. A
new type `OutputImplementer` is added which provides the basic output
functionality, i.e., method `OutputV()`. `Output` class requires a
reference to an `OutputImplementer` which it then uses to provide all
the different `Output{}()` method flavors. The new model allows all
CLI sub-modules to directly inherit `Output` class while reusing a
single and common underlying `OutputImplementer` provided by the
`Cli::Interpreter`.
2022-11-01 13:28:37 -07:00
Abtin Keshavarzian 61d9e72c18 [cli] update sub-modules to use Process<Cmd("cmd")> method (#8224)
This commit updates CLI `SrpServer`, `CoapSecure`, `UdpExample`, and
`TcpExample` to use the template `Process<Cmd("cmd")>` model. This
helps make them similar to other CLI modules.
2022-10-03 09:32:02 -07:00
Song GUO 6973a1b067 [nat64] implement functions for NAT64 on the client side (#8126)
This commit adds the ability for accepting an IPv4 address for {ping,
tcp, udp} CLI commands.
2022-09-15 08:43:36 -07:00
Abtin Keshavarzian a4cba16c39 [common] add BinarySearch module and Stringfy (#7294)
This commit adds set of generic binary search related functions in
OpenThread core under `BinarySearch` module. The binary search module
replaces and enhances the existing `Lookup` table module (which was
limited to search based on strings and mainly used by CLI to map from
command string to a handler function).

This commit also adds a new class `Stringfy` in `string.hpp` to help
convert from a set of `uint16_t` values (e.g., a non-sequential
`enum`) to strings using binary search in a table. The new methods are
used for converting `Coap::Code` and `IpProto` enumerations to
corresponding strings.
2022-01-10 13:19:34 -08:00
Abtin Keshavarzian 6153855ae0 [cli] simplify generating output (adding Output & OutputWrapper) (#7012)
This commit adds a new class `Cli::Output` which now includes all the
simple `Output{Item}()` methods that are used by CLI and its
sub-modules. It also adds new `Output` method flavors that output an
item (e.g., an IPv6 address) with an appended newline at the end.
These patterns are often used by CLI modules so having such new
methods help simplify the code.

The commit also adds `OutputWrapper` which is a wrapper over an
`Output` instance providing similar methods. This class is used as
the base class of different CLI sub-modules (e.g., `Cli::Dataset` or
`Cli::Joiner`, etc.) which helps simplify their implementation
(allow them to use the same set of `Output` helper methods as the
ones used by the `Cli::Interpreter` class).
2021-09-21 13:28:19 -07:00
Simon Lin 15584dcda3 [cli] allow binding CLI udp socket to unspecified interface (#6761) 2021-08-09 19:49:18 -07:00
Abtin Keshavarzian 0a6a0b6604 [cli] simplify argument processing (#6767)
This commit changes `ParseCmd()` such that as `aArgs` array entries
are populated with parsed arguments from a command line string, the
remaining unused `aArgs` entries in the array are marked as "empty".
We also ensure that the `aArgs[]` array always end with an "empty"
`Arg` which  indicates end of the list (this is similar to how C
string ends with a null '\0' character). This commit also changes
different methods of `Arg` class (`Arg::ParseAs{Type}()` or overload
of operator `==`, etc) to check and handle when `Arg` is marked
as "empty".

These changes help simplify how the arguments are processed in CLI
modules. In `Cli::Process{Command}()` methods we can just pass the
`aArgs[]` array and do not need to pass a separate args length
parameter. In many cases the args length checks can be removed since
it will be checked from `ParseAs{Type}()` call.
2021-06-29 13:56:41 -07:00
Simon Lin e9e875de24 [udp] forbid udp duplicate open (#6626) 2021-06-23 17:01:47 -07:00
Abtin Keshavarzian e66b9a3958 [cmd-parser] simplify ParseAsHexString() & Cli::UdpExample::ProcessSend() (#6726)
This commit enhances `CmdLineParser` methods that parse a hex string
adding a new version which allows a (longer) hex string to be parsed
in short segments sequentially. The unit test `test_cmd_line_parser`
is also updated to verify the behavior of the newly added method.

This commit also updates CLI `UdpExample` implementation to use the
new method for parsing message payload data from input hex string and
simplifies how `ProcessSend()` parses different arguments indicating
message payload options.
2021-06-17 10:23:25 -07:00
Abtin Keshavarzian fb7ce6232e [cli] simplify arg checking/parsing with new Arg class (#6524)
This commit adds a new `Arg` class in `parse_cmdline` which represents
a single argument (wrapper over a C string). The `Arg` class is then
used in CLI modules. This helps simplify the CLI code mainly using
simpler syntax, e.g., using an overload of `==` operator to compare an
argument with a C string, or calling `ParseAs{Type}()` methods
directly on an `Arg` instance.
2021-04-29 15:36:23 -07:00
Abtin Keshavarzian 850468a68a [cli] adding helper method ParseEnableOrDisable() (#6426)
This commit adds a helper method `Cli::ParseEnableOrDisable()` which
checks a given string against two common commands "enable" or
"disable". This method is then used in CLI modules.
2021-04-12 07:27:26 -07:00
Abtin Keshavarzian db117e27b2 [cli] add helper method to output "Enabled/Disabled" status (#6158) 2021-02-09 22:14:48 -08:00
Jonathan Hui 8941a367a6 [clang-tidy] misc-unused-using-decls (#5732) 2020-10-29 08:36:27 -07:00
Abtin Keshavarzian 4b3b37c312 [cmd-parser] adding helper 'ParseAs{Type}' function (#5607)
This commit adds new helper functions under `Utils::CmdLineParser` to
parse a given ASCII string as different simple types, namely signed or
unsigned integers of different bit lengths (`uint8/16/32/64`, and
`int8/16/32`). The new functions validate that the parsed value fits
within the supported range of the expected int type. This commit also
adds different flavors of `ParseAsHexString()` to parse a hex string
into sequence of bytes (with fixed/known size or unknown size allowing
or disallowing truncation). It also moves the parse related methods
(like `ParseAsIp6Prefix`) from CLI modules in `CmdLineParser`.

The CLI modules are then updated to use the new `ParseAs{Type}`
functions simplifying the code and adding extra checks when parsing
the CLI input.

Finally, this commit adds a unit test `test_cmd_line_parser` verifying
the behavior of new `ParseAs{Type}()` functions.
2020-10-08 10:28:38 -07:00
Abtin Keshavarzian 4db030c6c9 [utils] adding 'LookupTable' class and use it in CLI (#5602)
This commit adds `LookupTable` module which provides helper methods to
perform binary search in a generic sorted lookup table for specific
entry matching a given name string. It also provides `constexpr`
methods to check (at build-time) whether a lookup table array is
sorted. This commit also updates CLI modules to use the `LookupTable`
methods for command lookup. It also adds a unit test for the lookup
table.
2020-10-02 17:35:35 -07:00
Jonathan Hui 13d2de89d2 [cli] do not pass user-controlled input as format string (#5599) 2020-09-29 21:12:21 -07:00
Abtin Keshavarzian 6b6a3b8f74 [cli] style fixes and smaller enhancements (#5581)
This commit contains a group of style fixes and smaller enhancements
in CLI modules:
- Remove unnecessary `struct` when declaring variable.
- Remove use of single `"%s"` in `Output` methods.
- Fix order of `#include` headers.
- Remove unnecessary use of `OT_UNUSED_VARIABLE`.
- Remove unnecessary temp variables and casts.
- Add comments to `#endif` directives than are more than  than 20
  lines away from the corresponding `#if` they are associated with.
2020-09-28 17:28:06 -07:00
Abtin Keshavarzian b735193857 [cli] misc enhancements (#5528)
This commit contains a group of smaller enhancements in Cli modules:
- Add and use OutputLine() helper method which outputs a formatted
  string line (appends newline \r\n).
- Use binary search when finding the command in sCommands array (also
  adds static_assert check to ensure sCommands array is sorted).
- Define Command struct as a private nested type.
- Use enum constants (replacing #define).
- Rename method to OutputResult() (from AppendResult) to harmonize
  with rest of a Output{Something}() methods.
- Remove comments at #endif when within 20 lines of #if
2020-09-15 06:58:14 -07:00
Yakun Xu 8370395c47 [cli] remove multiple servers support (#5387) 2020-08-14 22:15:32 -07:00
Zhanglong Xia 9af8fe8cc5 [cli] add cli commands to set unsecure port and link security (#5349) 2020-08-11 09:28:55 -07:00
Simon Lin 5e9b2818eb [style] convert to C++11 for loops (#5263) 2020-07-21 09:41:40 -07:00
Abtin Keshavarzian dc1d47d2c0 [udp6] update UDP socket definitions (#5231)
This commit updates the  public OT `otUdp{}` (like `otUdpConnect`, or
`otUpdSend()`) functions to requires a pointer the OpenThread instance
to be passed as their first parameter (this harmonizes the definitions
with other public APIs and removes the need for `otUdpSocket` to track
the instance).

The core implementation in `udp6` module is updated to define
`SocketHandle` as an internal mirror of `otUdpSocket` structure. The
socket related methods `Open`(), `Bind()`, `Connect()`, etc., are
moved to `Udp` class itself (with a `SocketHandle` passed as a
parameter). For core internal use `Socket` class is defined as a
sub-class of `SocketHandle` and `InstanceLocator` providing same
helper methods. The separation between `SocketHandle` and `Socket`
type addresses the problem that can be caused by the treating/casting
publicly provided `otUdpSockt` objects as `InstanceLocator`.
2020-07-14 10:03:03 -07:00
Jonathan Hui 1326d64a64 [style] replace NULL with nullptr (#5109) 2020-06-17 22:44:54 -07:00
kangping 49f36f8c24 [error] force error checking (#4784) 2020-05-06 11:17:58 -07:00
Rongli Sun c8efee95f3 [nits] unify size_t type for local variable when OT_ARRAY_LENGTH is used (#4894) 2020-04-28 16:31:25 -07:00
Jonathan Hui 8eeb1e83eb [cli] change aArgsLength type from int to uint8_t (#4718) 2020-03-23 00:12:09 -07:00
Jonathan Hui a6a93d688d [cli] change 'argc' -> 'aArgsLength', 'argv' -> 'aArgs' (#4718) 2020-03-23 00:12:09 -07:00
kangping 133ec09b80 [cli] return OT_ERROR_INVALID_ARGS for invalid arguments (#4639)
- Remove argument parsing failure from semantic of OT_ERROR_PARSE.

- Add OT_ERROR_INVALID_COMMAND to indicate invalid CLI command error.

- return OT_ERROR_INVALID_ARGS for invalid CLI arguments.
2020-03-19 10:51:42 -07:00
Rongli Sun eac27c0f45 [cli] add hex string payload for udp send (#4241) 2019-10-24 10:33:08 -07:00
Jonathan Hui 87ef3b1d51 [cli] avoid NULL dereference with udp send -s 0 command (#4164) 2019-09-16 18:08:47 -07:00
Jonathan Hui a154692422 [cli] add error check to udp send command (#4148) 2019-09-08 21:40:15 -07:00
Christian Stauffer 864e3458f5 [ip6] add IPv6 fragmentation and reassembly support (#3948) 2019-08-28 10:31:55 -07:00
Jonathan Hui 1631d23a13 [netif] remove interface id specification from interfaces (#3925) 2019-06-20 09:30:56 -07:00
Łukasz Duda eb46303ff8 [cli] clean up IPv6 address printing (#3855) 2019-05-22 10:59:04 -07:00