Commit Graph

106 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
Tony Zhou 5050bec030 [cli] add "dataset active|pending -ns" support (#11518)
This CLI command argument "-ns" prints out the dataset fields and
redact the sensitive values, including the network key and PSKc
fields.
2025-06-03 08:20:49 -07:00
Eduardo Montoya 596c5aa6a2 [dataset] add support for wake-up channel (#10736)
- Add Wake-up Channel TLV to the dataset.
- Add CLI support to handle the wake-up channel.
- Add MAC support for wake-up channel (to be used for sending
  and receiving wake-up frames).
2024-09-26 14:01:46 -07:00
Abtin Keshavarzian 91e5a798f8 [cli] simplify parsing dataset TLVs (#10476)
This commit adds the `ParseTlvs()` helper method in the `Cli::Dataset`
class, which parses TLVs (as hex strings) from an input argument.
This is used in multiple methods to simplify the code.

The `Process<Cmd("set")>()` method is updated to avoid extra
conversion and use of core-internal types.
2024-07-08 15:05:58 -07:00
Abtin Keshavarzian 485cb18ea4 [dataset] add ValidateTlvs(), helper methods, and unit test (#10111)
This commit enhances dataset handling:

- Adds `ValidateTlvs()` which parses and validates all known TLVs
  within the `Dataset` and checks for any duplicates.
- Introduces a set of `SetFrom()` methods for constructing a `Dataset`
  from various types of inputs, e.g., other `Dataset`, TLV sequences,
  `DatasetInfo` structures, bytes read from `Message`. Now they
  consistently clear the `Dataset` before setting it.
- Adds `WriteTlvsFrom()` to update a `Dataset` replacing/appending a
  set of TLVs.
- Adds `AppendTlvsFrom()` to append an already encoded sequence of
  TLVs without validating/checking the format.
- Renames `Get/SetSize()` to `Get/SetLength()` for consistency.
- Adds `test_dataset.cpp` unit test for basic `Dataset` validation.
2024-05-02 14:40:11 -07:00
Abtin Keshavarzian 2b4b2cfe63 [docs] add documentation for CLI dataset updater command (#9905) 2024-03-11 11:29:21 -07: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 c10f650468 [cli] simplify dataset commands (#9366)
This commit simplifies the `Cli::Dataset` implementation by defining
an array of `ComponentMapper` structures. Each `ComponentMapper`
structure corresponds to a Dataset component, and provides the
following information:
- The component's CLI name
- A method pointer to output that component
- A method pointer to parse that component
- A pointer to the component's mIsPresent boolean flag

A new `LookupMapper()` method allows us to find (using binary search)
the entry corresponding to a given component name. This model allows
us to reuse code patterns for the main dataset sub-commands,
`mgmtsetcommand`, and `mgmtgetcommand` commands when outputting or
parsing dataset components.
2023-08-23 14:30:30 -07:00
Zhangwx 29b87786cd [docs] fix some typos (#9324) 2023-07-31 10:02:01 -07:00
Abtin Keshavarzian ef8deb506f [mle] delay router role downgrade on security policy change (#9187)
This commit adds a mechanism to delay the downgrade of routers or
leader when the security policy TLV changes in the Active Operational
Dataset such that the device is no longer eligible to act as a
router.

If the decision to become a child is made due to a security policy
change, the device first delays a random period up to the "router
selection jitter" before downgrading. If the device is the leader, an
additional fixed delay of 10 seconds is added to the random period.

If the security policy changes again while the device is waiting to
downgrade such that it becomes router-eligible again, the downgrade
is cancelled and the device remains in its current role.

This commit adds a `test_router_downgrade_on_sec_policy_change` to
validate the behavior of newly added mechanism.

This commit also updates the CLI `dataset` sub-commands to allow
getting and setting the "version threshold for routing" (VR) field in
security policy.
2023-06-30 15:09:50 -07:00
Jonathan Hui 2542cabc20 [cli] update dataset to operate directly on TLVs (#8871) 2023-03-16 09:36:41 -07:00
Abtin Keshavarzian a0b5198c02 [dataset] add otDatasetConvertToTlvs() API (#8720)
This commit adds `otDatasetConvertToTlvs()` to covert a given
Operational Dataset `otOperationalDataset` to TLVs. It also adds a
related CLI command `dataset tlvs`.
2023-03-10 14:10:50 -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 727002e9fe [cli] add OutputUint64() for 64-bit integer value in decimal format (#8354)
This commit also adds a helper `Uint64ToString()` method to convert a
`uint64_t` to decimal format string. The new methods allow us to
output `uint64_t` values without needing to cast to `unsigned long
long` and/or use of `%llu` (which may not be provided by certain
embedded libraries).
2022-11-07 09:35:27 +01:00
Sarah cd83fc1477 [docs] CLI Dataset (#7944) 2022-08-25 11:15:37 -07:00
Kangping 5daca7c684 [dataset] use full Timestamp TLV value in otOperationalDataset (#7739)
The `otOperationalDataset#mActiveTimestamp` should represent the full
Active Timestamp TLV value but not only the seconds. The same for
`otOperationalDataset#mPendingTimestamp`.
2022-06-03 10:59:16 -07:00
Eduardo Montoya 47fd27be3e [mac] remove beacons payload (#7472)
Thread Specification v1.2.1 removes support for Thread Beacons payload.
2022-04-06 12:18:22 -07:00
Abtin Keshavarzian 92ddd38777 [cli] use template Process<Cmd("command")> to simplify handlers (#7412)
This commit updates how the CLI command handlers are defined. A
template `Process<CommandId>()` method is now used to process a CLI
command where the `CommandId` is a `uint64` hash ID derived from
the command string itself.

This model helps simplify the CLI modules. With this change, there is
no need to declare different process methods for every CLI command in
the header files. It also makes the association between a CLI command
and its command string explicit and simple (e.g., `"state"` command
with `Process<Cmd("state")>` method).
2022-02-23 19:58:59 -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 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
hemanth-silabs cf452fbf7c [crypto] adding ARM PSA (Platform Security Architecture) support (#6862)
- New format for MAC keys, as a union between literal key and keyrefs.
- Modified key_manager to handle both literal keys or keyrefs.
- Modified MAC and sub_mac modules to handle both Literal Keys or keyrefs.
- Updated Crypto Modules to use abstracted APIs.
- New CLIs to handle networkkey and pskc references.
2021-09-08 14:47:46 -07:00
jinran-google 292fe60fcb [dataset] add API otDatasetParseTlvs (#6877)
Adds an API to parse a dataset from TLVs.
2021-08-11 22:09:15 -07:00
jinran-google 71bc37bbc3 [dataset] add callback to receive MGMT_SET responses (#6887) 2021-08-10 20:12:16 -07:00
Yakun Xu 2cc89cbfcb [dataset] remove mType from Dataset (#6831) 2021-07-19 22:44:12 -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
Jonathan Hui aaabf25ff2 [network-key] change name from master to network (#6721) 2021-06-16 23:07:23 -07:00
Abtin Keshavarzian f3671d5a75 [mac] new public API to validate and set otNetworkName (#6703)
This commit adds a new public API `otNetworkNameFromString()` to set
an `otNetworkName` instance from a given null terminated C string. The
new API will also validate that the given name string follows UTF-8
encoding and its length is not longer than max network name size.

This commit also simplifies the UTF-8 validation of `NetworkName` by
moving the check from `Mac::SetNetworkName()` to a newly added method
in `Mac::NetworkName` to set it from a C string.

It also defines `DomainName` as a `typedef` of `NetworkName` which
helps simplify its use and remove repeated code.

Finally, it updates the `Cli::Dataset` to use the new public API for
validating `otNetworkName`.
2021-06-03 22:13:51 -07:00
Abtin Keshavarzian 5ae8cf527c [cli] use OutputPrefix() in Cli::Dataset (#6699) 2021-06-01 22:46:19 -07:00
Jonathan Hui 66802336de [cli] fix args length checking in dataset securitypolicy (#6548) 2021-05-01 10:25:23 -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
kangping 423575fceb [meshcop] support Thread 1.2 Security Policy flags (#6320) 2021-04-14 08:16:08 -07:00
Jonathan Hui c8ef4b6a7c [cli] implement dataset updater CLI commands (#6227) 2021-03-08 08:48:04 -08:00
Moandor c7192ba798 [string] add UTF-8 validation (#5810) 2020-11-30 08:33:05 -08:00
Jonathan Hui 8941a367a6 [clang-tidy] misc-unused-using-decls (#5732) 2020-10-29 08:36:27 -07:00
Abtin Keshavarzian c9c0cf404d [code-utils] enhance 'VerifyOrExit' to make action optional (#5659)
This commit uses the newly added macros from `arg_macros.hpp` to
enhance `VerifyOfExit()` enabling `aAction` argument to be optional.
2020-10-16 08:07:16 -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
Abtin Keshavarzian 1f834a56c5 [cli] add 'OutputExtAddress()' helper method (#5591)
This commit also adds a template version of `OutputBytes()` which
accepts a reference array of a specific length. This helps simplify
the calls to this helper method where the array length can be
inferred. It also changes the code to use `OutputBytes()` for
outputting master key, pskc, xpanid, etc.
2020-09-29 06:51:44 -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
Jonathan Hui 42d76a0a4e [cli] change 'binary' arg to '-x' for consistency (#5543) (#5549) 2020-09-19 08:53:34 -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
Jonathan Hui 376f35a49e [cli] add length check on dataset 'set' command (#5361) 2020-08-10 10:02:11 -07:00
Jonathan Hui e810357adb [cli] support reading individual operational dataset values (#5344) 2020-08-06 11:52:35 -07:00
Jonathan Hui f8a6d52695 [cli] add '::' to end of mesh local prefix output (#5344) 2020-08-06 11:52:35 -07:00
Jonathan Hui 73afdadaa8 [cli] print channel mask with leading '0x' (#5344)
To be conssitent with intput format.
2020-08-06 11:52:35 -07:00
Simon Lin 5e9b2818eb [style] convert to C++11 for loops (#5263) 2020-07-21 09:41:40 -07:00
Jonathan Hui 1326d64a64 [style] replace NULL with nullptr (#5109) 2020-06-17 22:44:54 -07:00
Jonathan Hui f36ad41c62 [meshcop] support get/set operational dataset via raw TLVs (#5055)
- Add CLI commands to get/set operational dataset using TLVs.
2020-06-09 11:53:13 -07:00
Moandor a142b4234c [test] add expect tests for extaddr, ping, promiscuous (#4954) 2020-05-20 19:37:50 -07:00