From d0f76991101bd86ccd51b2b1cc9ce616248feda6 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Tue, 17 Sep 2024 01:13:25 +0800 Subject: [PATCH] [radio] add tx timestamp (#10688) This commit adds tx timestamp so that the pcap callback can get the time when a frame was transmitted. --- examples/platforms/utils/mac_frame.cpp | 1 + examples/platforms/utils/mac_frame.h | 1 + include/openthread/instance.h | 2 +- include/openthread/platform/radio.h | 9 +++++++++ src/ncp/ncp_base_mtd.cpp | 7 ++++++- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/platforms/utils/mac_frame.cpp b/examples/platforms/utils/mac_frame.cpp index 08d21996d..a258a735b 100644 --- a/examples/platforms/utils/mac_frame.cpp +++ b/examples/platforms/utils/mac_frame.cpp @@ -376,5 +376,6 @@ otError otMacFrameProcessTxSfd(otRadioFrame *aFrame, uint64_t aRadioTime, otRadi #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE otMacFrameUpdateTimeIe(aFrame, aRadioTime, aRadioContext); #endif + aFrame->mInfo.mTxInfo.mTimestamp = aRadioTime; return otMacFrameProcessTransmitSecurity(aFrame, aRadioContext); } diff --git a/examples/platforms/utils/mac_frame.h b/examples/platforms/utils/mac_frame.h index 6c8f74521..7925f4a6b 100644 --- a/examples/platforms/utils/mac_frame.h +++ b/examples/platforms/utils/mac_frame.h @@ -358,6 +358,7 @@ typedef struct otRadioContext * * - CSL IE will be populated (if present) * - Time IE will be populated (if present) + * - Tx timestamp will be populated * - Tx security will be performed (including assignment of security frame counter and key id if not assigned) * * @param[in,out] aFrame The target frame. MUST NOT be `NULL`. diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 1a68a8d4a..d54b63387 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (441) +#define OPENTHREAD_API_VERSION (442) /** * @addtogroup api-instance diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index 45fbe4594..95d35032f 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -361,6 +361,15 @@ typedef struct otRadioFrame bool mCsmaCaEnabled : 1; ///< Set to true to enable CSMA-CA for this packet, false otherwise. bool mCslPresent : 1; ///< Set to true if CSL header IE is present. bool mIsSecurityProcessed : 1; ///< True if SubMac should skip the AES processing of this frame. + + /** + * The time of the local radio clock in microseconds when the end of + * the SFD was present at the local antenna. + * + * The platform should update this field before otPlatRadioTxStarted() is fired for each transmit attempt. + * + */ + uint64_t mTimestamp; } mTxInfo; /** diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 4f7c80569..671b127ff 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -4605,7 +4605,12 @@ void NcpBase::HandlePcapFrame(const otRadioFrame *aFrame, bool aIsTx) SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise floor (Currently unused) SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags - SuccessOrExit(mEncoder.OpenStruct()); // PHY-data + SuccessOrExit(mEncoder.OpenStruct()); // PHY-data + SuccessOrExit(mEncoder.WriteUint8(aFrame->mChannel)); // Channel + SuccessOrExit( + mEncoder.WriteUint8(aIsTx ? static_cast(OT_RADIO_LQI_NONE) : aFrame->mInfo.mRxInfo.mLqi)); // LQI + SuccessOrExit( + mEncoder.WriteUint64(aIsTx ? aFrame->mInfo.mTxInfo.mTimestamp : aFrame->mInfo.mRxInfo.mTimestamp)); // Timestamp // Empty for now SuccessOrExit(mEncoder.CloseStruct());