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.
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>
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.
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.
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.
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.
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.
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.
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.
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`.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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
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`.