From 8ce12aaa046cf89e534ab32d07eca1e19ed1b9ad Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Mon, 21 Oct 2024 12:01:56 +0200 Subject: [PATCH] net: openthread: add wake-up coordinator support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Kconfig option `OPENTHREAD_WAKEUP_COORDINATOR` to enable the Wake-up Coordinator role. Implement API to set Coordinated Sampled Transmitting sample time and period for a driver that supports `IEE802154_OPENTHREAD_HW_CST` capability. The feature is be enabled on with ieee802154_nrf5 driver with option by setting default value of CONFIG_IEEE802154_NRF5_CST_ENDPOINT. Signed-off-by: Damian Krolik Co-authored-by: Andrzej KuroĊ› --- drivers/ieee802154/Kconfig.nrf5 | 1 + modules/openthread/CMakeLists.txt | 1 + modules/openthread/Kconfig.features | 4 ++ modules/openthread/platform/radio.c | 59 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/drivers/ieee802154/Kconfig.nrf5 b/drivers/ieee802154/Kconfig.nrf5 index 1705ccd4203..bf4bcd1be8c 100644 --- a/drivers/ieee802154/Kconfig.nrf5 +++ b/drivers/ieee802154/Kconfig.nrf5 @@ -96,6 +96,7 @@ config IEEE802154_NRF5_MULTIPLE_CCA 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. diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 977b7e5921f..b0dfd8baf18 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -128,6 +128,7 @@ 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") 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) diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index f4cbfb3551a..44cd3cc7ada 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -128,6 +128,10 @@ 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_DHCP6_CLIENT bool "DHCPv6 client support" diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 70b17e7708e..34725f70dba 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -1396,6 +1396,65 @@ void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTi } #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; + + 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); + (void)result; +} +#endif /* CONFIG_OPENTHREAD_WAKEUP_COORDINATOR */ + uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance) { ARG_UNUSED(aInstance);