[spinel] use 64bit timestamp for rx frames (#4037)

This commit changes the default timestamp of rx frames to be 64bit,
which is aimed to ensure the timestamp never wraps. This commit
changes the protocol of spinel.

NOTE: Changing spinel protocol is not allowed normally. However, since
the timestamp is only used by sniffer, an exception is made due to the
improved efficiency. Pyspinel is also updated accordingly.
This commit is contained in:
Yakun Xu
2019-07-31 08:56:37 -07:00
committed by Jonathan Hui
parent 0546a2f972
commit a5ed9ce573
2 changed files with 20 additions and 31 deletions
+5 -11
View File
@@ -90,10 +90,7 @@ void NcpBase::LinkRawReceiveDone(otRadioFrame *aFrame, otError aError)
SuccessOrExit(mEncoder.WriteUint8(aFrame->mChannel)); // 802.15.4 channel (Receive channel)
SuccessOrExit(mEncoder.WriteUint8(aFrame->mInfo.mRxInfo.mLqi)); // 802.15.4 LQI
SuccessOrExit(mEncoder.WriteUint32(
static_cast<uint32_t>(aFrame->mInfo.mRxInfo.mTimestamp / 1000))); // The timestamp milliseconds
SuccessOrExit(
mEncoder.WriteUint16(aFrame->mInfo.mRxInfo.mTimestamp % 1000)); // The timestamp microseconds, offset to mMsec
SuccessOrExit(mEncoder.WriteUint64(aFrame->mInfo.mRxInfo.mTimestamp)); // The timestamp in microseconds
SuccessOrExit(mEncoder.CloseStruct());
@@ -137,13 +134,10 @@ void NcpBase::LinkRawTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame,
SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused)
SuccessOrExit(mEncoder.WriteUint16(0)); // Flags
SuccessOrExit(mEncoder.OpenStruct()); // PHY-data
SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mChannel)); // Receive channel
SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mInfo.mRxInfo.mLqi)); // Link Quality Indicator
SuccessOrExit(mEncoder.WriteUint32(
static_cast<uint32_t>(aAckFrame->mInfo.mRxInfo.mTimestamp / 1000))); // The timestamp milliseconds
SuccessOrExit(mEncoder.WriteUint16(aAckFrame->mInfo.mRxInfo.mTimestamp %
1000)); // The timestamp microseconds, offset to mMsec
SuccessOrExit(mEncoder.OpenStruct()); // PHY-data
SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mChannel)); // Receive channel
SuccessOrExit(mEncoder.WriteUint8(aAckFrame->mInfo.mRxInfo.mLqi)); // Link Quality Indicator
SuccessOrExit(mEncoder.WriteUint64(aAckFrame->mInfo.mRxInfo.mTimestamp)); // The timestamp in microseconds
SuccessOrExit(mEncoder.CloseStruct());
+15 -20
View File
@@ -612,29 +612,25 @@ otError RadioSpinel::ParseRadioFrame(otRadioFrame &aFrame, const uint8_t *aBuffe
otError error = OT_ERROR_NONE;
uint16_t flags = 0;
int8_t noiseFloor = -128;
uint32_t msec = 0;
uint16_t usec = 0;
spinel_size_t size = OT_RADIO_FRAME_MAX_SIZE;
unsigned int receiveError = 0;
spinel_ssize_t unpacked;
// Timestamp is ms + us.
unpacked =
spinel_datatype_unpack_in_place(aBuffer, aLength,
SPINEL_DATATYPE_DATA_WLEN_S // Frame
SPINEL_DATATYPE_INT8_S // RSSI
SPINEL_DATATYPE_INT8_S // Noise Floor
SPINEL_DATATYPE_UINT16_S // Flags
SPINEL_DATATYPE_STRUCT_S( // PHY-data
SPINEL_DATATYPE_UINT8_S // 802.15.4 channel
SPINEL_DATATYPE_UINT8_S // 802.15.4 LQI
SPINEL_DATATYPE_UINT32_S // Timestamp (ms).
SPINEL_DATATYPE_UINT16_S // Timestamp (us).
) SPINEL_DATATYPE_STRUCT_S( // Vendor-data
SPINEL_DATATYPE_UINT_PACKED_S // Receive error
),
aFrame.mPsdu, &size, &aFrame.mInfo.mRxInfo.mRssi, &noiseFloor, &flags,
&aFrame.mChannel, &aFrame.mInfo.mRxInfo.mLqi, &msec, &usec, &receiveError);
unpacked = spinel_datatype_unpack_in_place(aBuffer, aLength,
SPINEL_DATATYPE_DATA_WLEN_S // Frame
SPINEL_DATATYPE_INT8_S // RSSI
SPINEL_DATATYPE_INT8_S // Noise Floor
SPINEL_DATATYPE_UINT16_S // Flags
SPINEL_DATATYPE_STRUCT_S( // PHY-data
SPINEL_DATATYPE_UINT8_S // 802.15.4 channel
SPINEL_DATATYPE_UINT8_S // 802.15.4 LQI
SPINEL_DATATYPE_UINT64_S // Timestamp (us).
) SPINEL_DATATYPE_STRUCT_S( // Vendor-data
SPINEL_DATATYPE_UINT_PACKED_S // Receive error
),
aFrame.mPsdu, &size, &aFrame.mInfo.mRxInfo.mRssi, &noiseFloor, &flags,
&aFrame.mChannel, &aFrame.mInfo.mRxInfo.mLqi,
&aFrame.mInfo.mRxInfo.mTimestamp, &receiveError);
VerifyOrExit(unpacked > 0, error = OT_ERROR_PARSE);
@@ -642,7 +638,6 @@ otError RadioSpinel::ParseRadioFrame(otRadioFrame &aFrame, const uint8_t *aBuffe
{
aFrame.mLength = static_cast<uint8_t>(size);
aFrame.mInfo.mRxInfo.mTimestamp = msec * 1000 + usec;
aFrame.mInfo.mRxInfo.mAckedWithFramePending = ((flags & SPINEL_MD_FLAG_ACKED_FP) != 0);
}
else if (receiveError < OT_NUM_ERRORS)