From 379ac5e394a9fa92f38651f2718bd5b752c24d3b Mon Sep 17 00:00:00 2001 From: Dave Lacerte Date: Tue, 26 Mar 2024 14:49:19 -0400 Subject: [PATCH] modules: openthread: platform: radio: Time Sync OT Feature support Add missing otRadioIeInfo structure and add plaform time to transmit frame Signed-off-by: Dave Lacerte --- modules/openthread/Kconfig.features | 3 ++- modules/openthread/platform/radio.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index cc29a53c65..7fd9ed5080 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -341,7 +341,8 @@ config OPENTHREAD_SRP_SERVER select OPENTHREAD_ECDSA config OPENTHREAD_TIME_SYNC - bool "The time synchronization service feature" + bool "The time synchronization service feature [EXPERIMENTAL]" + select EXPERIMENTAL config OPENTHREAD_TREL bool "TREL radio link for Thread over Infrastructure feature" diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 64effaef33..b320d0f476 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -85,6 +85,10 @@ static otRadioFrame sTransmitFrame; static otRadioFrame ack_frame; static uint8_t ack_psdu[ACK_PKT_LENGTH]; +#if defined(CONFIG_OPENTHREAD_TIME_SYNC) +static otRadioIeInfo tx_ie_info; +#endif + static struct net_pkt *tx_pkt; static struct net_buf *tx_payload; @@ -334,6 +338,10 @@ static void dataInit(void) for (size_t i = 0; i < CHANNEL_COUNT; i++) { max_tx_power_table[i] = OT_RADIO_POWER_INVALID; } + +#if defined(CONFIG_OPENTHREAD_TIME_SYNC) + sTransmitFrame.mInfo.mTxInfo.mIeInfo = &tx_ie_info; +#endif } void platformRadioInit(void) @@ -385,6 +393,18 @@ void transmit_message(struct k_work *tx_job) radio_api->set_channel(radio_dev, channel); radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(channel)); +#if defined(CONFIG_OPENTHREAD_TIME_SYNC) + if (sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset != 0) { + uint8_t *time_ie = + sTransmitFrame.mPsdu + sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset; + uint64_t offset_plat_time = + otPlatTimeGet() + sTransmitFrame.mInfo.mTxInfo.mIeInfo->mNetworkTimeOffset; + + *(time_ie++) = sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeSyncSeq; + sys_put_le64(offset_plat_time, time_ie); + } +#endif + net_pkt_set_ieee802154_frame_secured(tx_pkt, sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed); net_pkt_set_ieee802154_mac_hdr_rdy(tx_pkt, sTransmitFrame.mInfo.mTxInfo.mIsHeaderUpdated);