Commit Graph

29 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
Esko Dijk a0243fa01a [cli] add '-x' flag to tcp client to send hexadecimal data (#11218)
This adds the `-x` flag to the `tcp send` command so send specific
data defined by a hexadecimal string.  The purpose is to use this in
testing, for example to emulate HTTP GET requests.
2025-02-07 10:50:15 -08:00
Suvesh Pratapa ae5b750d30 [cli] set mUseTls to false after de-initializing TCP session (#10977)
Avoid SSL context operations in TCP callbacks (for
eg. `HandleTcpDisconnected`) when the context could have already been
de-allocated after de-initialization.
2024-11-27 15:36:33 -08:00
Łukasz Duda 6db2d5882d [cli] fix memory leak on TCP init failure (#10300)
This commit fixes potential memory leak for CLI TCP module.

Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
2024-05-28 09:18:17 -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 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
jrhodie 12af023121 [cli] add aliases for TCP and SRP concepts guides (#9707)
* Adding aliases for TCP and SRP concepts guides

* TCP and SRP concept guides now referenced by Command Ref CLIs
2023-12-11 15:28:40 -08:00
jrhodie 0d74e43fa6 [docs] TCP Commands - add Doxygen tags (#9578) 2023-11-06 15:41:32 -08:00
Sam Kumar 519537dd9b [tcplp] add support for TCP Fast Open (without cookie management) (#9165)
This commit adds support for TCP Fast Open, without cookie management.

To add support for this, I looked at the FreeBSD codebase and brought
in some code from FreeBSD 12.0 that implements TCP Fast Open --- the
version of FreeBSD that TCPlp is based on did not fully support TCP
Fast Open.

Normally, a part of TFO is cookie management --- the server generates
a cookie and includes it in the initial handshake, and client is
expected to present this cookie on future handshakes. This part is not
yet implemented, and I changed the logic from FreeBSD to allow data to
be exchanged in the TFO handshake even if the client does not present
a cookie. If we implement this functionality for TFO later, it is
probably worth departing from FreeBSD's data structures and policies
for maintaining cookie state in favor of something that is simpler and
more memory-efficient.
2023-08-21 15:00:52 -07:00
Li Cao 55e3440ee2 [cli] add command to get tcp results (#9142)
This commit updates the cli command of TCP benchmark so that the
result of TCP benchmark could be queried any time. This enables test
scripts to automate TCP benchmark test. Currently the command `tcp
benchmark` is asynchronous and return immediately. If we use `ot-ctl
tcp benchmark` on posix, it's hard to fetch the test results. With the
newly added command, we can write a script to poll and get the result.
2023-06-14 13:31:09 -07:00
Eduardo Montoya 25506997f2 [cli-tcp] fix TLS configuration for different platforms (#8693)
This commit addresses two issues:
- Use agnostic crypto API regardless of `OPENTHREAD_CONFIG_CRYPTO_LIB`
  choice.
- Limits the configured ciphersuites in order to avoid client-server
  conflicts during handshake.
2023-01-26 10:02:16 -08:00
Sam Kumar 65a8d520b1 [cli-tcp] add TLS mode to TCP CLI tool and TLS callbacks to TCP API (#8257)
This commit adds support for TLS in the TCP CLI tool, along with a
test of TLS functionality.

The main purpose of this is to provide an example of how to use
mbedTLS with TCPlp to run TLS. I felt it is important to have an
example because I expect that many applications that use TCP,
particularly those in which a Thread device exchanges data with a
device outside the Thread mesh, will need to run TLS over TCP for
security reasons.

A secondary benefit is to add TCP functionality to the TCP CLI
tool. Additionally, by having the example code be part of a "real"
application (the CLI tool), there is less risk of the code going stale
as OpenThread evolves.

I added an "expects" test for the TLS functionality in the CLI tool. I
also ran the code on two Nordic NRF52840-DK boards to make sure it
works.

The performance impact of TLS appears to be small. When using TCP
without TLS, I am able to achieve ~80 kb/s goodput between two
NRF52840-DK boards. With TLS in the same setup, I am able to achieve
~70-75 kb/s goodput.
2023-01-23 10:56:16 -08:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian 6b03d55cc4 [cli] add compile-time printf style arg check in CLI (#8369)
This commit adds compile-time check of format string to all CLI
`Output` methods. It also updates CLI module to  make arg string
formats consistent. In particular we use `'%lu` for `uint32_t`
arguments and they are explicitly cast to `unsigned long` using
`ToUlong()`.
2022-11-07 22:05:55 +01: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
Sam Kumar d5333ca831 [cli-tcp] fix bug causing "accept" action for all incoming connections (#8291) 2022-10-17 09:10:47 -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
Sam Kumar 9d76424c3c [cli-tcp] use TCP Circular Send Buffer in TCP CLI tool and test (#7867) 2022-09-19 10:30:48 -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
Sam Kumar 3fdaaab07c [tcp] fix minor bugs (#7335)
This commit fixes minor bugs in TCP.

1. The first change fixes a bug where the TCP CLI prints out an
incorrect message when a connection is terminated. This appears to
have been introduced in #7279.

2. The second change fixes a null pointer dereference when accepting a
TCP connection. This issue is purely theoretical at the moment,
because in the case where the dereferenced pointer is NULL, the
dereferenced value is not used, and so the compiler optimizes out the
memory access (so it seems). As a result, TCP actually runs without
issues. But I've fixed it anyway, to avoid depending on that behavior.
2022-01-19 19:56:13 -08: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 8361426c67 [core] use const array lookup for converting enum to string (#7279)
This commit updates different modules in OT core and CLI to use
`const` array lookup to convert an enumeration value to string.
2022-01-06 13:27:16 -08:00
Abtin Keshavarzian 60aa8b4fb9 [cli] add OutputSockAddr() method (#7121) 2021-11-01 09:24:50 -07: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
Mason Tran a935fc51f7 [tcp] fix uninitialized variable warning in TcpExample::ProcessBenchmark() (#6957) 2021-08-27 18:00:07 -07:00
Sam Kumar 6c03a1e962 [cli] add support for TCP in the CLI tool (#6770) 2021-07-19 14:32:49 -07:00