Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: openthread: support WC and WED #80132

Merged
merged 5 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions drivers/ieee802154/Kconfig.nrf5
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ config IEEE802154_NRF5_MULTIPLE_CCA
When this option is enabled the OpenThread capability
IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA is supported by the ieee802154_nrf5.

config IEEE802154_NRF5_CST_ENDPOINT
bool "Support for OpenThread CST Endpoint extension in the ieee802154_nrf5."
default y if OPENTHREAD_WAKEUP_COORDINATOR
help
Enable support for OpenThread CST (Coordinated Sampled Transmitter) Endpoint
with CST IE injection as an extension to ieee802154_nrf5 driver.
When this option is enabled, the ieee802154_nrf5 driver supports the
IEEE802154_OPENTHREAD_HW_CST capability.

endif
14 changes: 14 additions & 0 deletions drivers/ieee802154/ieee802154_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,15 @@
((caps & NRF_802154_CAPABILITY_DELAYED_RX) ? IEEE802154_HW_RXTIME : 0UL) |
IEEE802154_HW_SLEEP_TO_TX |
IEEE802154_RX_ON_WHEN_IDLE |
((caps & NRF_802154_CAPABILITY_SECURITY) ? IEEE802154_HW_TX_SEC : 0UL)

Check notice on line 255 in drivers/ieee802154/ieee802154_nrf5.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/ieee802154/ieee802154_nrf5.c:255 - IEEE802154_HW_FCS | - IEEE802154_HW_PROMISC | - IEEE802154_HW_FILTER | + IEEE802154_HW_FCS | IEEE802154_HW_PROMISC | IEEE802154_HW_FILTER | ((caps & NRF_802154_CAPABILITY_CSMA) ? IEEE802154_HW_CSMA : 0UL) | - IEEE802154_HW_TX_RX_ACK | - IEEE802154_HW_RX_TX_ACK | - IEEE802154_HW_ENERGY_SCAN | + IEEE802154_HW_TX_RX_ACK | IEEE802154_HW_RX_TX_ACK | IEEE802154_HW_ENERGY_SCAN | ((caps & NRF_802154_CAPABILITY_DELAYED_TX) ? IEEE802154_HW_TXTIME : 0UL) | ((caps & NRF_802154_CAPABILITY_DELAYED_RX) ? IEEE802154_HW_RXTIME : 0UL) | - IEEE802154_HW_SLEEP_TO_TX | - IEEE802154_RX_ON_WHEN_IDLE | + IEEE802154_HW_SLEEP_TO_TX | IEEE802154_RX_ON_WHEN_IDLE |
#if defined(CONFIG_IEEE802154_NRF5_MULTIPLE_CCA)
| IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA
#endif
#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
| IEEE802154_HW_SELECTIVE_TXCHANNEL
#endif
#if defined(CONFIG_IEEE802154_NRF5_CST_ENDPOINT)
| IEEE802154_OPENTHREAD_HW_CST
#endif
;
}
Expand Down Expand Up @@ -1028,6 +1031,17 @@
}
break;

#if defined(CONFIG_IEEE802154_NRF5_CST_ENDPOINT)
case IEEE802154_OPENTHREAD_CONFIG_CST_PERIOD:
nrf_802154_cst_writer_period_set(config->cst_period);
break;

case IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME:
nrf_802154_cst_writer_anchor_time_set(nrf_802154_timestamp_phr_to_mhr_convert(
config->expected_tx_time / NSEC_PER_USEC));
break;
#endif /* CONFIG_IEEE802154_NRF5_CST_ENDPOINT */

default:
return -EINVAL;
}
Expand Down
64 changes: 62 additions & 2 deletions include/zephyr/net/ieee802154_radio_openthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include <zephyr/net/ieee802154_radio.h>

/** Bit number starting the OpenThread specific capabilities of ieee802154 driver. */
#define IEEE802154_OPENTHREAD_HW_CAPS_BITS_START IEEE802154_HW_CAPS_BITS_PRIV_START

/**
* OpenThread specific capabilities of ieee802154 driver.
* This type extends @ref ieee802154_hw_caps.
Expand All @@ -22,7 +25,26 @@
/** Capability to transmit with @ref IEEE802154_OPENTHREAD_TX_MODE_TXTIME_MULTIPLE_CCA
* mode.
*/
IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA = BIT(IEEE802154_HW_CAPS_BITS_PRIV_START),
IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA = BIT(IEEE802154_OPENTHREAD_HW_CAPS_BITS_START),

/** Capability to support CST-related features.
*
* The CST-related features are described by "Specification changes for Thread-in-Mobile"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth documenting somewhere that this indicates the point of time when the end of SFD/start of PHR for the next transmission will occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have a look on doc for IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME, it's mentioned there.

* Draft version 1, July 11, 2024. The CST allows to transmit a frame with CST Phase and
* CST Period IEs as described by chapter 4.6.6.1 of the Thread-in-Mobile specification
* change. The upper layer implementation (OpenThread) is responsible for preparing
* a frame to be transmitted that contains placeholders where the CST Phase and CST Period
* are to be placed. The implementation of a driver is responsible for injecting
* correct value for CST Phase IE and CST Period IE based on configuration parameters
* @ref IEEE802154_OPENTHREAD_CONFIG_CST_PERIOD and
* @ref IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME.
*
* @note The CST transmission in its design is very similar to CSL reception.
* In the CSL reception the receiver side informs its peer about the moment in time
* when it will be able to receive. In the CST transmission the transmitter side informs
* its peer about the moment in time when the next transmission will occur.
*/
IEEE802154_OPENTHREAD_HW_CST = BIT(IEEE802154_OPENTHREAD_HW_CAPS_BITS_START + 1),
};

/** @brief TX mode */
Expand Down Expand Up @@ -80,7 +102,33 @@
* @ref IEEE802154_OPENTHREAD_TX_MODE_TXTIME_MULTIPLE_CCA.
* Requires IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA capability.
*/
IEEE802154_OPENTHREAD_CONFIG_MAX_EXTRA_CCA_ATTEMPTS = IEEE802154_CONFIG_PRIV_START
IEEE802154_OPENTHREAD_CONFIG_MAX_EXTRA_CCA_ATTEMPTS = IEEE802154_CONFIG_PRIV_START,

Check notice on line 106 in include/zephyr/net/ieee802154_radio_openthread.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/net/ieee802154_radio_openthread.h:106 - IEEE802154_OPENTHREAD_CONFIG_MAX_EXTRA_CCA_ATTEMPTS = IEEE802154_CONFIG_PRIV_START, + IEEE802154_OPENTHREAD_CONFIG_MAX_EXTRA_CCA_ATTEMPTS = IEEE802154_CONFIG_PRIV_START,
/** Configures the CST period of a device.
*
* When a frame containing CST Period IE is about to be transmitted by a driver,
* the driver SHALL inject the CST Period value to the CST Period IE based on
* the value of this configuration parameter.
*
* Requires IEEE802154_OPENTHREAD_HW_CST capability.
*/
IEEE802154_OPENTHREAD_CONFIG_CST_PERIOD,

/** Configure a point in time at which a TX frame is expected to be transmitted.
*
* When a frame containing CST Phase IE is about to be transmitted by a driver,
* the driver SHALL inject the CST Phase IE value to the CST Phase IE based on
* the value of this configuration parameter parameter, the time of transmission
* and the CST Period value.
*
* This parameter configures the nanosecond resolution timepoint relative to
* the network subsystem's local clock at which a TX frame's end of SFD
* (i.e. equivalently its end of SHR, start of PHR) is expected to be transmitted
* at the local antenna.
*
* Requires IEEE802154_OPENTHREAD_HW_CST capability.
*/
IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME,
};

/**
Expand All @@ -106,6 +154,18 @@
* requested with mode @ref IEEE802154_OPENTHREAD_TX_MODE_TXTIME_MULTIPLE_CCA.
*/
uint8_t max_extra_cca_attempts;

/** ``IEEE802154_OPENTHREAD_CONFIG_CST_PERIOD``
*
* The CST period (in CPU byte order).
*/
uint32_t cst_period;

/** ``IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME``
*
* A point in time at which a TX frame is expected to be transmitted.
*/
net_time_t expected_tx_time;
};
};

Expand Down
2 changes: 2 additions & 0 deletions modules/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ kconfig_to_ot_option(CONFIG_OPENTHREAD_TX_QUEUE_STATISTICS OT_TX_QUEUE_STATS "En
kconfig_to_ot_option(CONFIG_OPENTHREAD_UDP_FORWARD OT_UDP_FORWARD "Enable UDP forward feature")
kconfig_to_ot_option(CONFIG_OPENTHREAD_UPTIME OT_UPTIME "Enable support for tracking OpenThread instance's uptime")
kconfig_to_ot_option(CONFIG_OPENTHREAD_VERHOEFF_CHECKSUM OT_VERHOEFF_CHECKSUM "Verhoeff checksum")
kconfig_to_ot_option(CONFIG_OPENTHREAD_WAKEUP_COORDINATOR OT_WAKEUP_COORDINATOR "Enable Wake-up Coordinator role")
kconfig_to_ot_option(CONFIG_OPENTHREAD_WAKEUP_END_DEVICE OT_WAKEUP_END_DEVICE "Enable Wake-up End Device role")

if(CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE)
set(OT_NCP_VENDOR_HOOK_SOURCE ${CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE} CACHE STRING "NCP vendor hook source file name" FORCE)
Expand Down
8 changes: 8 additions & 0 deletions modules/openthread/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ config OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT
config OPENTHREAD_DATASET_UPDATER
bool "Dataset updater"

config OPENTHREAD_WAKEUP_COORDINATOR
bool "Wake-up Coordinator support"
select OPENTHREAD_CSL_RECEIVER

config OPENTHREAD_WAKEUP_END_DEVICE
bool "Wake-up End Device support"
imply OPENTHREAD_CSL_RECEIVER
rlubos marked this conversation as resolved.
Show resolved Hide resolved

config OPENTHREAD_DHCP6_CLIENT
bool "DHCPv6 client support"

Expand Down
5 changes: 3 additions & 2 deletions modules/openthread/platform/openthread-core-zephyr-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE \
(CONFIG_OPENTHREAD_CSL_RECEIVER && \
(OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2))
((CONFIG_OPENTHREAD_CSL_RECEIVER && \
(OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)) || \
CONFIG_OPENTHREAD_WAKEUP_END_DEVICE)

/* Zephyr does not use OpenThread's heap. mbedTLS will use heap memory allocated
* by Zephyr. Here, we use some dummy values to prevent OpenThread warnings.
Expand Down
61 changes: 60 additions & 1 deletion modules/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@
return OT_ERROR_NONE;
}

#if defined(CONFIG_OPENTHREAD_CSL_RECEIVER)
#if defined(CONFIG_OPENTHREAD_CSL_RECEIVER) || defined(CONFIG_OPENTHREAD_WAKEUP_END_DEVICE)
otError otPlatRadioReceiveAt(otInstance *aInstance, uint8_t aChannel,
uint32_t aStart, uint32_t aDuration)
{
Expand Down Expand Up @@ -1396,6 +1396,65 @@
}
#endif /* CONFIG_OPENTHREAD_CSL_RECEIVER */

#if defined(CONFIG_OPENTHREAD_WAKEUP_COORDINATOR)
otError otPlatRadioEnableCst(otInstance *aInstance, uint32_t aCstPeriod, otShortAddress aShortAddr,
const otExtAddress *aExtAddr)
{
struct ieee802154_config config;
int result;
uint8_t header_ie[OT_IE_HEADER_SIZE + OT_THREAD_IE_SIZE + OT_CST_IE_SIZE] = { 0 };
size_t index = 0;

Check notice on line 1406 in modules/openthread/platform/radio.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/openthread/platform/radio.c:1406 - uint8_t header_ie[OT_IE_HEADER_SIZE + OT_THREAD_IE_SIZE + OT_CST_IE_SIZE] = { 0 }; + uint8_t header_ie[OT_IE_HEADER_SIZE + OT_THREAD_IE_SIZE + OT_CST_IE_SIZE] = {0};

ARG_UNUSED(aInstance);

/* Configure the CST period first to give drivers a chance to validate
* the IE for consistency if they wish to.
*/
config.cst_period = aCstPeriod;
result = radio_api->configure(radio_dev, IEEE802154_OPENTHREAD_CONFIG_CST_PERIOD, &config);
if (result) {
return OT_ERROR_FAILED;
}

/* Configure the CST IE. */
header_ie[index++] = OT_THREAD_IE_SIZE + OT_CST_IE_SIZE;
header_ie[index++] = 0;
sys_put_le24(THREAD_IE_VENDOR_OUI, &header_ie[index]);
index += 3;
header_ie[index++] = THREAD_IE_SUBTYPE_CST;
/* Leave CST Phase empty intentionally */
index += 2;
sys_put_le16(aCstPeriod, &header_ie[index]);
index += 2;

config.ack_ie.header_ie = aCstPeriod > 0 ? (struct ieee802154_header_ie *)header_ie : NULL;
config.ack_ie.short_addr = aShortAddr;
config.ack_ie.ext_addr = aExtAddr != NULL ? aExtAddr->m8 : NULL;
config.ack_ie.purge_ie = false;

result = radio_api->configure(radio_dev, IEEE802154_CONFIG_ENH_ACK_HEADER_IE, &config);

return result ? OT_ERROR_FAILED : OT_ERROR_NONE;
}

void otPlatRadioUpdateCstSampleTime(otInstance *aInstance, uint32_t aCstSampleTime)
{
int result;

ARG_UNUSED(aInstance);

struct ieee802154_config config = {
.expected_tx_time = convert_32bit_us_wrapped_to_64bit_ns(
aCstSampleTime - PHR_DURATION_US),
};

result = radio_api->configure(radio_dev, IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME,
&config);
__ASSERT_NO_MSG(result == 0);

Check notice on line 1453 in modules/openthread/platform/radio.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/openthread/platform/radio.c:1453 - .expected_tx_time = convert_32bit_us_wrapped_to_64bit_ns( - aCstSampleTime - PHR_DURATION_US), + .expected_tx_time = + convert_32bit_us_wrapped_to_64bit_ns(aCstSampleTime - PHR_DURATION_US), }; result = radio_api->configure(radio_dev, IEEE802154_OPENTHREAD_CONFIG_EXPECTED_TX_TIME, - &config); + &config);
(void)result;
}
#endif /* CONFIG_OPENTHREAD_WAKEUP_COORDINATOR */

uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance)
{
ARG_UNUSED(aInstance);
Expand Down
Loading