57 Commits

Author SHA1 Message Date
Zhanglong Xia 4cced2e81e [mac] adds the wake-up identifier to the Connection IE (#11907)
The P2P peer can be woken up using the wake-up identifier. The wake-up identifier
is included in the Connection IE. This commit implements methods to the Connection IE
and Frame to process wake-up identifier.
2025-10-28 11:01:19 -07:00
Abtin Keshavarzian af2e10a7bf [mac-frame] add mCommandId to TxFrame::Info (#10697)
This commit updates `TxFrame::Info` to include `mCommandId`, used when
the frame type is `kTypeMacCmd`. This allows callers to specify the
Command ID when preparing a MAC Command `TxFrame`. With this change
`Frame::SetCommandId()` is no longer used or needed so it is
removed.
2024-10-11 10:32:16 -07:00
Abtin Keshavarzian 262b998c10 [mac-frame] remove unused Set{Src/Dst}{Addr/PanId}() methods (#10779)
Recent changes updated `Mac::Frame` to use `FrameBuilder` for
preparing frame headers. With the adoption of this model, the
previously defined `Set` methods for setting source/destination
address or PAN ID are no longer used or needed. This commit removes
them.
2024-10-03 15:57:44 -07:00
Abtin Keshavarzian f0cb5a3f22 [mac-frame] update GenerateWakeupFrame() to use FrameBuilder (#10774)
This commit updates `TxFrame::GenerateWakeupFrame()` to utilize the
`FrameBuilder` class for constructing frame header fields.

It also updates the `TestMacWakeupFrameGeneration()` unit test in
`test_mac_frame.cpp`:
- Uses source and destination address constants that are not reversible
  to validate that extended addresses are appended in the correct byte
  order.
- Includes minor style changes (renames constants and uses lowercase
  hexadecimal digits for consistency).
2024-10-03 06:46:04 -07:00
Abtin Keshavarzian 09698fae24 [mac-frame] add TxFrame::Info and simplify mac header preparation (#10689)
This commit simplifies the preparation of MAC and security frames. It
introduces a `TxFrame::Info` structure that provides information
about the frame, such as its type, version, source and destination
addresses, PAN IDs, security level, and key ID mode. A new method
`PrepareHeadersIn()` is added, which uses the `Info` structure to
construct the MAC address and security headers in a given `TxFrame`.

This approach replaces the earlier `Mac::Frame::InitMacHeader()` where
all the information was passed as a list of input arguments. The
`TxFrame::Info` approach simplifies the code and allows for future
extension to accommodate other parameters (e.g., Header IE entries).
2024-10-01 11:37:17 -07:00
Damian Królik bc50521cfa [mac] multipurpose wake-up frame support (#10728)
1. Add OT_WAKEUP_COORDINATOR and OT_WAKEUP_END_DEVICE build
   options.
2. Add support for parsing and constructing 802.15.4
   Multipurpose frames.
3. Add support for parsing and constructing wake-up
   frames.
2024-09-23 09:02:15 -07:00
Yakun Xu e219fe92f1 [mac] support frames without sequence number (#10544)
This commit adds the capability to support frames without sequence
number.
2024-08-02 09:50:45 -07:00
Abtin Keshavarzian 23c0fc4d4b [test] define all unit tests in ot namespace (#9617)
This commit updates unit test modules to be defined under the `ot`
namespace. This aligns all the unit tests to follow the same
model, eliminating the need to use `ot::` prefix in unit test
code.
2023-11-19 18:40:20 -08:00
Abtin Keshavarzian 3b291108a9 [mac-frame] update GenerateEnhAck() to use InitMacHeader() (#9338)
This commit updates the `GenerateEnhAck()` method to add checks to
validate the received frame before preparing the ACK. These checks
are added as a safeguard in case the caller (radio platform
implementation) does not validate the received frame before calling
this method to generate the ACK.

Specifically, the checks verify that the received frame is using the
2015 version, has the "Ack Request" flag, has a valid source address
(which is used as the destination in the generated ACK), and has a
valid destination address that is not broadcast. The checks also
verify that if the received frame is secured, it uses security level
`kSecurityEncMic32`.

The commit also simplifies the code by using `InitMacHeader()` to
prepare the header and addresses. Enhanced ACK frames always have a
destination address and no source address (to keep the frame
shorter). If the received frame has a source PAN ID, it is used in
the ACK frame. If it does not, the code checks if the received frame
has a destination PAN ID and uses that in the ACK frame.
2023-08-14 21:45:38 -07:00
Abtin Keshavarzian 4639dc6fd1 [mac-frame] update InitMacFrame() (#9337)
This commit updates the `InitMacFrame()` method to allow the caller to
specify whether the source or destination PAN IDs are present or not.
It also handles all cases related to PAN ID compression as defined by
IEEE 802.15.4-2015. While these cases are not used by the Thread
stack itself, adding them to `InitMacFrame()` makes it more capable
allowing future use-cases of this method such as generating enhanced
ACKs based on a received frame.

The `test_mac_frame` unit test has been updated to cover the newly
added cases.
2023-08-14 13:35:08 -07:00
Jonathan Hui 7d6740c9b5 [clang-tidy] fix bugprone-too-small-loop-variable warnings (#9321) 2023-08-01 16:52:34 -07:00
Abtin Keshavarzian fe1cf3a294 [mac-frame] update InitMacHeader() (#8660)
This commit updates how we prepare the MAC headers:
- New `enum`s are defined in `Mac::Frame` to specify the frame
 `Type`,  `Version`, `SecurityLevel`, etc.
- `InitMacHeader()` will itself determine the Frame Control Field
  from the given address info.
- It now uses `FrameBuilder` to prepare the headers.
- New helper `MeshForwarder::PrepareMacHeaders()` is added which
  takes care of adding MAC (address, security header) along with
  any IE headers.
- These changes ensure that PAN ID Compression bit is properly
  set on MAC frames when using 2015 version (ensure that PAN
  IDs are not omitted when both addresses use Extended format).
2023-01-17 20:01:26 -08:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Jonathan Hui 9b6ac4b5ac [meshcop] separate Network Name from Mac (#7609) (#7616)
With the removal of Thread payload from IEEE 802.15.4 Beacons, the MAC
layer no longer needs to maintain the Network Name.
2022-04-22 10:13:17 -07:00
Abtin Keshavarzian 8d268663ef [mac] update Mac::NameData to use Data (#7026)
This commit updates `Mac::NameData` to use `Data` as its base
class and then use its method in the `NameData` implementation.
2021-09-23 09:18:29 -07:00
Abtin Keshavarzian 3c14f7b30f [mac] fix the Mac::NetworkName length check (length >= 1) (#7018)
This commit fixes the `NetworkName` check (for its length to be larger
than zero) which was recently added in commit e2f0afab5d. This commit
moves the name length check to method `Set(const NameData &aNameData)`
and after the `newLen` is calculated.

This commit also updates `TestMacNetworkName()` in unit test to verify
that setting the network name to an empty string correctly fails with
`kErrorInvalidArgs`.
2021-09-22 11:05:27 -07:00
Abtin Keshavarzian 57d072d352 [test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.

This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
2021-06-28 11:38:10 -07:00
Abtin Keshavarzian 153fc8678d [channel-mask] update Mac::ChannelMask::ToString() (#6375)
This commit contains a small fix in `Mac::ChannelMask::ToString()`
string output (e.g, return `{ 11-26 }` instead of `{ 11-26}`). This
commit also updates the unit test to follow naming style and verify
the `ToString()` behavior.
2021-03-31 17:05:58 -07:00
Abtin Keshavarzian 7dca56e982 [error] add 'ot::Error' and 'kError{Name}' for use by core modules (#6237)
This commit adds a new core header files `common/error.hpp` which
defines `ot::Error` (mirroring `otError`) and `kError{Name}` constants
(mirroring the public `OT_ERROR_{NAME}` definitions). The new (C++
style) definitions are used by core modules. This commit also moves
`otThreadErrorToString()` (from `logging.hpp` to `error.hpp`) and
renames it to `ErrorToString()` which is used as the internal (to
core) function to covert an `Error` to a string.
2021-03-15 21:07:07 -07:00
Li Cao 75ac125771 [mac] refactor code to add frame version and header IE in TX frames (#6189)
This commit refactors the code to set frame version, IE present field
in frame control field and to append Header IE.

- Split UpdateFrameControlField into two methods: CalcIePresent and
  CalcFrameVersion. Currently UpdateFrameControlField` is not
  easy-to-read and hard to extend the method to handle more cases.

- Move this code from Mac to MeshForwarder. I think it should be
  MeshForwarder's responsibility (PrepareDataFrame) to prepare the
  frame (though Mac sometimes prepare data frames itself). Since when
  preparing the frame, most information comes from the Message which
  is only in MeshForwarder, we can put this code for preparing frame
  in MeshForwarder.

- Enhance the way to append Header IEs to the frame. Currently in
  Mac::AppendHeaderIe, it generates a list of HeaderIe first and then
  call Frame::AppendHeaderIe. There are two problems here: 1. it uses
  another copy (copy HeaderIe to the frame's buffer). 2. it has to
  initialize Vendor IE (e.g. TimeSync IE) after Vendor IE header has
  been copied to the buffer. Currently it directly finds the first
  Vendor IE in the buffer and initialize it as TimeSync IE, which is
  not extensible. This commit shifts the responsibility of 'how to
  append the IE' to Frame, by providing AppendHeaderIeAt method. And
  MeshForwarder can decide which IEs to append and directly call the
  method to append IEs to the frame.
2021-02-25 08:02:52 -08:00
Abtin Keshavarzian ffb3fdf9bd [radio-selector] adding multi radio link support (#4440)
This commit adds support for multi radio links in OpenThread core.

A set of `OPENTHREAD_CONFIG_RADIO_LINK_*` definitions (in header
`config/radio_link.h`) determines the supported radio link types.

This commit adds a new class `RadioSelector` which selects the radio
link for each message transmission. Per neighbor it tracks the
supported radio types and a preference value for each type.
`RadioSelector` updates the preference value based on the history of
rx/tx events with the neighbor, e.g., a successful tx on a radio link
increases the preference, whereas a failed tx attempt decreases it.

A new class `Mac::Links` is added defining a layer between `Mac` and
different radio links (e.g., `SubMac` for 802.15.4 radio type).
Broadcast frames are sent in parallel over all radio links. A unicast
transmission is sent over a single radio link at a time but on a tx
failure it may be retransmitted over other radio links.

This commit also adds the concept of deferred ack, allowing radio
links report status of ack at a later time through a different
callback.
2020-12-10 11:46:07 -08:00
Li Cao e9d578da51 [mac-frame] handle exception case for payload of mac cmd (#5499)
In current Mac::Frame implementation, when the frame is a Mac command,
the CommandId is always not included as its private payload, which
means we won't encrypt the CommandId.

In most cases the Private Payload(things we need to encrypt) shall be
set to the MAC Payload field(For Mac cmd, this field includes
CommandId, shown in Figure 7-17) and the Open Payload shall be
empty. The only 2 exception cases are listed in Table 9-1.

So for Mac command with version >= 2, its CommandId should be included
in Private Payload and should be encrypted when necessary. For Mac
command with version < 2, CommandId should be in included in Open
Payload and shouldn't be encrypted.

This commit fixes this problem and adds unit tests for this.
2020-09-08 18:24:17 -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
Li Cao 903ea67505 [mac-frame] fix problems to generate enh ack (#4990)
- Existing code assumes security is always enabled in enhanced ack,
  however that's not always the case. So add security part only when
  it's required.

- FindHeaderIeIndex would return kInvalidIndex when IE is not
  present. It's possible that no IE is in an enh ack, so use
  SkipSecurityHeaderIndex instead.
2020-05-20 22:43:59 -07:00
Li Cao cd9558ca91 [mac-frame] add util functions to generate ack (#4884)
This commit adds mac frame util functions to generate acks (both Imm
and Enh acks) from a received frame. These funtions are utils APIs for
platforms which don't provide ack generation.

This commit also introduces compile options for CSL to control the CSL
IE related part.
2020-05-12 22:20:03 -07:00
Abtin Keshavarzian 7e5dce0542 [tests] update Mac::Frame unit test to check footer and frame length (#4883) 2020-04-24 16:15:02 -07:00
Li Cao ab029ec0ac [mac-frame] enhance utility functions (#4826)
This commit enhances some utility functions in mac frame for frame
parsing and adds some basic testing.

- Currently the mac frame parsing only doesn't include the rule for
  version 2015. This commit adds the parsing of dstPanId for 2015
  frames.

- This commit adds some helper function dealing with Security Header
  so that later commit of CSL and setting security header in enhanced
  ACK would be easier.
2020-04-16 23:11:45 -07:00
Rongli Sun 854a2309bd [domain] add domain name (#4815) 2020-04-14 09:08:42 -07:00
Jonathan Hui 5b22b4d7c7 [utils] remove wrap_string.h (#4483) 2020-01-22 13:39:25 -08:00
Abtin Keshavarzian f10c6c36fd [unit-test] remove (unnecessary) ENABLE_TEST_MAIN definition (#4367) 2019-12-11 09:16:48 -08:00
Abtin Keshavarzian ab27fcd9e6 [unit-test] remove extra \n at end of error message (#4367)
This commit removes the extra `\n` at the end of error message strings
used in `VerifyOrQuit()` or `SuccessOrQuit()` macros in different unit
test modules. This help make the style (usage of macros) consistent
across all unit tests.
2019-12-11 09:16:48 -08:00
Abtin Keshavarzian 86b3cfef56 [mac-frame] set kMtu from config param and inline simple getters (#4215) 2019-10-01 08:36:20 -07:00
Abtin Keshavarzian 4916f1c0c5 [mac] add Mac::NetworkName class (#4169)
This commit adds `Mac::NetworkName` class as C++ wrapper over the
`otNetworkName`. It also adds `NetworkName::Data` to represent the
network name as a pointer to a char array buffer (not necessarily null
terminated) with a given length. This representation is used by
`Mac::BeaconPlayload` and `MeshCop::NetworkNameTlv`. This commit also
adds a unit test for `Mac::NetworkName` class.
2019-09-20 14:39:28 +08:00
Abtin Keshavarzian 472a03af88 [mac-frame] helper methods to copy ExtAddress in normal/reverse byte order (#4144)
This commit updates `Mac::ExtAddress` and `Mac::Address` to add
helper methods to copy address from/to a byte array in normal or
reverse bye order. This commit also adds a unit test for the two
Address classes.
2019-09-09 17:13:06 -07:00
Abtin Keshavarzian b1d92846c0 [radio] add radio folder to core (#4045)
This commit renames existing `phy` folder into `radio`. It also
renames some of the related files in this folder. It also moves
all default/weak `otPlatRadio` implementations to a common
`radio_platform_defaults.cpp` file.
2019-08-08 08:29:38 -07:00
Yakun Xu 6c6aad2a01 [mac] define TxFrame and RxFrame types (#4040)
This commit defines RxFrame for receiving frames and TxFrame for
transmitting frames. The motivation is to prevent invalid uses of
Mac::Frame methods, because some of them are only available for rx
frames and some only for tx frames.
2019-08-01 15:28:19 -07:00
Zhanglong Xia 96725a985e [phy] add support for OQPSK modulation in 915MHz band (#3378) 2019-03-08 08:09:55 -08:00
Jonathan Hui 9d585edc46 [types] move types into specific headers (#2946) 2018-08-08 11:19:41 -07:00
Shu Chen e69019f962 [time-sync] network-wide time synchronization service (#2618)
OpenThread network-wide time synchronization service is an experimental feature, not part of the standard Thread protocol.

Feature Overview:
 * All the nodes in the same Thread partition sync to the same Thread network-wide time;
 * Microsecond level time synchronization precision;
 * Flexible time accuracy and time sync period configuration;
 * APIs for application layer use case, support both CLI and NCP version.

The feature is wrapped by OPENTHREAD_CONFIG_ENABLE_TIME_SYNC, there's no change to current Thread 1.1
implementation if OPENTHREAD_CONFIG_ENABLE_TIME_SYNC is not enabled.

If OPENTHREAD_CONFIG_ENABLE_TIME_SYNC is enabled, the node could:
 * Attach to a time sync enabled network, otherwise
 * Attach to a standard Thread 1.1 network, otherwise
 * Form a new time sync enabled network

In addition, if OPENTHREAD_CONFIG_TIME_SYNC_REQUIRED is also enable, the node could only:
 * Attach to a time sync enabled network, otherwise
 * Form a new time sync enabled network

Note:
Currently, the feature is only supported on nRF52840 and posix platforms. And the network time
is only synced among Routers and REEDs, the SEDs will be supported later as an optional feature.
2018-06-26 13:46:32 -05:00
Abtin Keshavarzian 4b918f85f0 [string] adding ot::String<size> class (#2764)
This commit adds a new template class `ot::String<size>` which
implements a fixed-length character string. This class is then used as
return value of `ToString()` methods from different classes. This
simplifies the `ToString()` implementation and its use. This commit
also adds a unit test for `String`.
2018-06-11 09:10:52 -07:00
Abtin Keshavarzian 2abd7a2822 [code-utils] adding helper macro OT_ARRAY_LENGTH() (#2743)
This commit adds helper macro `OT_ARRAY_LENGTH()` to get the number
of elements in an array.
2018-05-29 15:53:53 -07:00
Abtin Keshavarzian 7f901cf9c7 [announce-sender] feature to enable periodic tx of MLE Announce (#2693)
This commit adds a new feature/class namely `AnnounceSender` which
enables periodic transmission of MLE Announce messages on all
channels. The feature can be enabled using the config option
`OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER` (disabled by default).

This commit also adds some new helper methods in `Mac::ChannelMask`
to get number of channels in a given mask, and operator overloads
to compare two masks.
2018-05-15 19:32:01 -07:00
Abtin Keshavarzian 3ee92c974b [mac] add method ToString() to Mac::ChannelMask (#2578) 2018-02-26 21:54:13 +00:00
Abtin Keshavarzian 4d339496e5 [mac] adding Mac::ChannelMask class (#2560)
This commit adds a `Mac::ChannelMask` class to define a channel (a
`uint32_t` bit-vector specifying a set of channels). The `ChannelMask`
class provides methods to add/remove channel to the mask, intersect
two masks, and iterate through the channels in the mask. A unit test
for the new class is also added.
2018-02-20 17:28:46 +00:00
Jonathan Hui 69d98d4a53 [code-style] apply clang-format 2018-02-09 21:43:42 +00:00
Abtin Keshavarzian bbab3074ed [instance] single OpenThread instance optimizations (#1926)
This commit new configuration option `enable-multiple-instances` and
its corresponding option `OPENTHREAD_ENABLE_MULTIPLE_INSTANCES`. When
enabled OpenThread supports handling of multiple instances. By default
this is disabled.

This commit also adds two optimizations for single instance case to
simplify the code and also help reduce memory/RAM usage:

(1) OpenThread objects/classes typically keep a reference to a higher
level object (e.g., many classes keep track of owning `ThreadNetif`)
to be able to access other objects/methods within OpenThread class
hierarchy. In single instance mode, the reference member variables are
removed and instead global functions are used to access the singleton
objects from one class to the other. To implement this, a group of
`<Object>Locator` classes are defined (e.g., `ThreadNetifLocator`,
etc.) which are then used as base class of other OpenThread classes.

(2) OpenThread objects which provide a callback/handler (e.g.,
`Timer`, `Tasklet`, etc.) have `void *mContext` member variable which
is used to keep track of the owner of the object. In single instance
mode the `mConext` member variables are removed since the owner is
expected to be a singleton and can be uniquely determined from the
callback function.

To implement this, two changes are made: First the handler methods are
modified to provide a reference to the object (e.g., `Timer` handler
will provide a `Timer &aTimer` as a parameter of its handler
callback). Second, a new base class `Context` is introduced which
hides the implementation providing an arbitrary context information. A
new static method `GetOwner(aContext)` is added to classes which own a
callback providing objects. This method help convert a `Context` to
the reference of the owner class object.
2017-06-30 11:48:26 -07:00
Jonathan Hui fbfd76a990 Apply #include code style. (#1723) 2017-05-05 11:28:29 -07:00
Jonathan Hui 1eabda6a08 Change top-level namespace from 'Thread' to 'ot'. (#1664) 2017-04-27 22:29:05 -07:00
DuaneEllis-TI d65418c12f Add support for wrap_string.h and others (#1642) 2017-04-27 10:17:09 -07:00