Skip to content

Commit

Permalink
[radio] use new implementation of time sync
Browse files Browse the repository at this point in the history
  • Loading branch information
bukepo committed Sep 3, 2024
1 parent 943b91b commit 388aa6f
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions src/src/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ static otRadioFrame sTransmitFrame;
static uint8_t sTransmitPsdu[OT_RADIO_FRAME_MAX_SIZE + 1];

#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
static otExtAddress sExtAddress;
static otRadioIeInfo sTransmitIeInfo;
static otInstance *sInstance = NULL;
static otExtAddress sExtAddress;
static otInstance *sInstance = NULL;
#endif

static otRadioFrame sAckFrame;
Expand Down Expand Up @@ -172,9 +171,6 @@ static void dataInit(void)

sDefaultTxPower = OT_RADIO_POWER_INVALID;
sTransmitFrame.mPsdu = sTransmitPsdu + 1;
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
sTransmitFrame.mInfo.mTxInfo.mIeInfo = &sTransmitIeInfo;
#endif

sReceiveError = OT_ERROR_NONE;

Expand Down Expand Up @@ -534,10 +530,11 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
otMacFrameSetFrameCounter(aFrame, sMacFrameCounter++);
}

if (aFrame->mInfo.mTxInfo.mTxDelay != 0)
if (aFrame->mInfo.mTxInfo.mTimeInfo.mDelayInfo.mTxDelay != 0)
{
if (!nrf_802154_transmit_raw_at(&aFrame->mPsdu[-1], true, aFrame->mInfo.mTxInfo.mTxDelayBaseTime,
aFrame->mInfo.mTxInfo.mTxDelay, aFrame->mChannel))
if (!nrf_802154_transmit_raw_at(&aFrame->mPsdu[-1], true,
aFrame->mInfo.mTxInfo.mTimeInfo.mDelayInfo.mTxDelayBaseTime,
aFrame->mInfo.mTxInfo.mTimeInfo.mDelayInfo.mTxDelay, aFrame->mChannel))
{
error = OT_ERROR_INVALID_STATE;
}
Expand Down Expand Up @@ -1220,7 +1217,7 @@ int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
void nrf_802154_tx_started(const uint8_t *aFrame)
{
bool processSecurity = false;
uint64_t now = otPlatTimeGet();

assert(aFrame == sTransmitPsdu);
OT_UNUSED_VARIABLE(aFrame);
Expand All @@ -1234,34 +1231,17 @@ void nrf_802154_tx_started(const uint8_t *aFrame)

// Update IE and secure transmit frame
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
if (sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset != 0)
{
uint8_t *timeIe = sTransmitFrame.mPsdu + sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset;
uint64_t time = otPlatTimeGet() + sTransmitFrame.mInfo.mTxInfo.mIeInfo->mNetworkTimeOffset;

*timeIe = sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeSyncSeq;

*(++timeIe) = (uint8_t)(time & 0xff);
for (uint8_t i = 1; i < sizeof(uint64_t); i++)
{
time = time >> 8;
*(++timeIe) = (uint8_t)(time & 0xff);
}

processSecurity = true;
}
otMacFrameUpdateTimeIe(&sTransmitFrame, now);
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE

#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
otEXPECT(otMacFrameIsSecurityEnabled(&sTransmitFrame) && otMacFrameIsKeyIdMode1(&sTransmitFrame) &&
!sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed);

sTransmitFrame.mInfo.mTxInfo.mAesKey = &sCurrKey;

processSecurity = true;
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2

otEXPECT(processSecurity);
otEXPECT(!sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed);
otMacFrameProcessTransmitAesCcm(&sTransmitFrame, &sExtAddress);

exit:
Expand Down

0 comments on commit 388aa6f

Please sign in to comment.