27 Commits

Author SHA1 Message Date
Zhanglong Xia 789ad728fd [dataset] add API otDatasetIsValid support (#12757)
This commit adds an API otDatasetIsValid to check whether the given
Operational Dataset contains all the required TLVs (Active Timestamp,
Channel, Channel Mask, Extended PAN ID, Mesh-Local Prefix, Network
Key, Network Name, PAN ID, PSKc, and Security Policy). This API also
checks whether there are duplicated TLVs or the TLVs are not
well-formed.
2026-03-26 17:26:03 -05:00
Abtin Keshavarzian c923900de0 [platform] implement otPlatLogOutput platform API (#12762)
This commit provides the platform-level implementation for the
instance-aware logging API `otPlatLogOutput()`. This API is used when
`OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` is enabled, allowing
the platform to receive the `otInstance` pointer with each log line.

The new API is implemented across:
- The simulation platform logging.
- The POSIX platform using `syslog()`.
- The NCP base to route logs to the NCP host.
- The CLI logging module.
- Unit tests and mock platforms.

The `OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` configuration is
also enabled for Toranj simulations to support multi-instance log
testing.
2026-03-25 21:21:24 -05:00
Abtin Keshavarzian cf733a331e [infra-if] add missing otInstance parameter to otPlatInfraIf APIs (#12662)
This commit updates the following `otPlatInfraIf` platform APIs to
include an `otInstance *` as their first parameter:

- `otPlatInfraIfHasAddress()`
- `otPlatInfraIfSendIcmp6Nd()`
- `otPlatInfraIfDiscoverNat64Prefix()`

Other APIs under `otPlatInfraIf` already follow this pattern. Passing
the `otInstance` pointer is the required standard for all platform
and public APIs; however, it was missed during the initial design of
these specific APIs.

While missing this parameter is often not a blocker on platforms using
a single OpenThread instance, it has become a blocker for simulations,
especially when multiple Border Routers are emulated in the same
simulation setup.

This change introduces a compatibility break for existing platform
implementations, however, it is necessary to support new use cases
(simulation of BRs). It also helps ensure consistent API design
across the stack.
2026-03-12 10:10:08 -05:00
Yakun Xu 54b936367d [test] conditionally test RCP restoration (#12339)
This commit makes the
`shouldNotDuplicateSrcMatchEntriesOnRestoreProperties` test
conditional, because RCP restoration is not always enabled.
2026-02-02 17:31:34 -08:00
Esko Dijk 3061fa19de [otns] add default (weak) OTNS platform API implementation in core (#12308)
A default OTNS platform API function otPlatOtnsStatus() is now
provided that writes the status push to the log always (regardless of
configured log level). This is useful as a default handling for apps
built with -DOT_OTNS=ON, avoiding linker errors while not mandating
each platform to implement the API by itself.

Specifically it enables the Posix CLI app ot-cli to be built with OTNS
support, which is required to run Posix nodes in OTNS and receive the
status-push events via stdout logging.

The logging is emitted from the module named "Otns" so that a
simulator or other tool can easily detect the OTNS format status push
events in the log output.
2026-01-22 10:49:37 -08:00
puddly 5fd62a9acf [spinel] clear source match tables before recovery (#12222)
Radio recovery that does not fully reset the firmware leads to tables
filling up with duplicate entries. After a few resets, future resets no
longer work. Clearing the tables before inserting entries allows for
their state to be consistent during recovery.
2026-01-15 20:21:54 -08:00
Abtin Keshavarzian b5737b4f2b [script] add script to check, enforce, and update header guards (#12227)
This commit introduces a new script `update-header-guards.py` which
checks for the presence of header guards in `.h` and `.hpp` files and
automatically updates them, standardizing the header guard name format
across the codebase.

The new format for header guards is derived from the full path of the
file. For example, `src/core/common/notifier.hpp` will use
`OT_CORE_COMMON_NOTIFIER_HPP_`. The guard name includes additional
prefixes such as `OT_` or `OPENTHREAD_` to ensure uniqueness.

This new naming format handles cases where the same filename may be used
in different folders, such as the two `heap.hpp` files located in
`src/core/common` and `src/core/utils`.

It also ensures that public and platform OpenThread headers under
`include/openthread` have uniquely distinct header guard names to avoid
conflicts when these headers are included in other projects.

The new script helped identify issues with existing header files that
lacked header guards (e.g., `posix/system.hpp`) or had improper guards
(e.g., `openthread/link_metrics.h`).

This commit also introduces a new check script `check-header-guards` to
validate that all header guards are correctly formatted. This check is
added to the GitHub CI actions to ensure consistency moving forward.

All existing header files have been updated (using the new script)
to apply the new guard name format.
2025-12-22 13:43:41 -08:00
Li Cao ad3035b91d [tests] add dnssd api implementations in FakePlatform (#12070)
This commit adds fake implementations for OT dnssd platform APIs.

The background is that I'm trying to enable the OT Dnssd Server
functions (Discovery Proxy) in ot-br-posix by default. Once it's
enabled, `openthread-ftd` needs implemenation of dnssd platform
APIs. To make some unit tests (in ot-br-posix) build successfully,
these fake implementations are required.
2025-10-27 16:52:02 -07:00
Yakun Xu e1d8a05c29 [udp] allow binding to multicast address (#11901)
This commit allows binding to multicast address, which means the socket
would only accept frames targeting to a particular multicast address.
This prevents other datagrams destined to the same port being delivered
to this socket.

Note that binding to a multicast address doesn't automatically subscribe
to the multicast group.
2025-09-10 08:51:27 -07:00
arnulfrupp bb5585d412 [tcat] add tcat implementations and bug fixes (#11402)
Commit adds check if commissioning is possible and if the tcat device is already commissioned.
Adds advertisement update on disconnected and role change.
Fixes key handling for key references.
Fixes the authorization processing.
Implements recent changes of the application TLVs.
2025-07-30 12:27:10 -07:00
Abtin Keshavarzian a495a2284b [otns] make various enhancements to Otns (#11643)
This commit contains various enhancements to the `Otns` class:

- Makes `Otns` methods non-static. This aligns their use with the
  clang-tidy `readability-static-accessed-through-instance` check,
  which disallows accessing static methods through an instance.
- Updates the `make-pretty` script to enable OTNS and include it in
  `clang-tidy` checks.
- Adds a stub implementation of `otPlatOtnsStatus()` in the simulation
  and fake platforms. This allows the OTNS feature to be enabled in
  `make-pretty` builds and covered by GitHub Action CI checks.
- Simplifies the `EmitStatus` methods to use the `String` class for
  constructing the status string.
- Adds a new helper method to construct the CoAP status string,
  removing duplicated code.
2025-06-30 14:39:30 -07:00
Jonathan Hui f390da0c94 [tests] fix spelling errors (#11640) 2025-06-25 17:07:30 -07:00
Yakun Xu 8c23a588ca [script] install gtest and gmock (#11358) 2025-03-24 08:29:53 -07:00
Jason Zhang 0019f38839 [gtest] fix build error when building posix (#11289)
This commit fix build error when running "./script/cmake-build posix
-DOT_BUILD_GTEST=ON".
2025-02-25 22:28:58 -08:00
Yakun Xu 6fac4078b6 [test] cover src match handling (#11258)
This commit adds tests to cover the handling of Src Match entries,
including adding, removing and clearing of short addr entries and
extended addr entries.
2025-02-19 19:18:25 -08:00
Abtin Keshavarzian d1147d62b9 [trel] detect and handle socket addr discrepancy for TREL peers (#10869)
This commit introduces a new mechanism for the TREL link to detect and
handle discrepancies between the IPv6 address and port used by a TREL
peer in a received TREL packet, and the information previously
reported by the platform layer (through DNS-SD discovery) for the
same peer.

Ideally, the platform underlying DNS-SD should detect changes to
advertised ports and addresses by peers. However, there are
situations where this is not detected reliably.

As a received frame over the TREL radio link is processed by the MAC
or MLE layers, if the frame passes receive security checks at either
layer (indicating it is a secure and authenticated/fresh frame from a
valid neighbor), the TREL peer socket address is automatically
updated from the received TREL packet info. This ensures the TREL
peer table is updated correctly if there are changes to TREL peer
addresses of valid Thread neighbors upon rx from such neighbor,
increasing the robustness of the TREL link.

This commit also introduces a new `otPlatTrel` platform API,
`otPlatTrelNotifyPeerSocketAddressDifference()`. The TREL
implementation now notifies the platform layer whenever it detects a
discrepancy in a TREL peer's socket address, regardless of whether
the peer table is automatically updated. This allows the platform
layer to take any appropriate action, such as restarting or
confirming DNS-SD service resolution query for the peer service
instance and/or address resolution query for its associated host
name.

This commit also adds a new test that validates the newly added
behavior, including the auto-update of peer table information and
notification of the platform through the new API, triggered by either
MLE or MAC messages over the TREL radio link.
2024-12-18 20:35:58 -08:00
Yakun Xu d540fc7f43 [mac] skip backoff when MaxBackoffs is 0 (#11012)
This commit allows skip CSMA backoff but keep CCA enabled by respect the
Max Backoffs parameter in TxInfo.
2024-12-09 11:12:35 -08:00
Zhanglong Xia c44538e4df [simulation] enable the platform assert (#10952)
When the ot-rcp enters the assert state, the host crashes and exits.
But the ot-rcp still runs in the dead loop and becomes an orphan
process.

This commit enables the platform assert so that the ot-rcp can
automatically exit when entering the assert state.
2024-11-22 16:48:51 -08:00
Yakun Xu 9277bce08e [spinel] add SPINEL_PROP_MAC_RX_AT (#10921)
This commit adds receive at functionality for spinel for host to
schedule reception on RCP.
2024-11-18 08:53:55 -08:00
Yakun Xu 005c5cefc2 [mac] apply RxChannelAfterTxDone only if RxOnWhenIdle (#10826)
This commit updates the implementation to apply RxChannelAfterTxDone
only if RxOnWhenIdle.
2024-10-28 14:19:44 -07:00
Li Cao 8cb126ede8 [test] add implementation of otPlatRadioSetChannelTargetPower in FakePlatform (#10865) 2024-10-28 09:28:13 -07:00
Yakun Xu 788608335e [rcp] always support sleep-to-tx capability (#10856)
This commit declares sleep-to-tx capability on RCP side so that the host
doesn't need to issue Receive() before Transmit().
2024-10-24 11:44:42 +01:00
Li Cao a225ee9c08 [test] add missing platform APIs in FakePlatform (#10844)
This commit adds some missing platform API implementation for
FakePlatform.

These are added so that FakePlatform can be used to write unit tests
in ot-br-posix.

The commit also guards the microSecondTimer code in `FakePlatform`
with the marcro `OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE` because
`otPlatAlarmMicroFired` is only defined in OT timer.cpp when
`OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE` is true.

This commit also removes some parameter names in the fake
implementation to avoid unused warnings.
2024-10-16 11:47:27 -07:00
Yakun Xu b0790b8ff0 [mac] skip CSMA backoff when disabled (#10838)
This commit updates SubMac to skip CSMA backoff when TX frame disables
it.
2024-10-15 11:20:39 -07:00
Yakun Xu c4262af670 [test] verify behavior of RxChannelAfterTxDone (#10817)
This commit adds a test to verify RX channel is switched correctly after TX done.
2024-10-11 08:26:28 -07:00
Yakun Xu ab5950cb54 [spinel] support per-frame TX power in coprocessor (#10804)
This commit passes the TX power from host to coprocessor. This commit
also adds a new fake platform for coprocessor to cover the changes in
RadioSpinel and NCP.
2024-10-10 07:51:13 -07:00
Yakun Xu 8cb529be2a [test] add fake platform (#10594)
This commit adds a fake platform for unit/component tests. This platform
uses virtual time so it should be able to run fast.

Note that the fake platforms leverage C++ virtual methods to allow mocking.

This commit verifies setting active dataset triggers the active dataset
change event by the notifier.
2024-10-08 21:00:35 -07:00