mirror of
https://github.com/espressif/openthread.git
synced 2026-09-13 04:30:08 +00:00
[mle] simplify TimeParameterTlv (#12923)
This commit simplifies the `TimeParameterTlv` implementation by defining a `TimeParameterTlvValue` and using the `SimpleTlvInfo` template to define `TimeParameterTlv`.
This commit is contained in:
+17
-21
@@ -3788,13 +3788,12 @@ Error Mle::TxMessage::AppendTimeRequestTlv(void)
|
||||
|
||||
Error Mle::TxMessage::AppendTimeParameterTlv(void)
|
||||
{
|
||||
TimeParameterTlv tlv;
|
||||
TimeParameterTlvValue tlvValue;
|
||||
|
||||
tlv.Init();
|
||||
tlv.SetTimeSyncPeriod(Get<TimeSync>().GetTimeSyncPeriod());
|
||||
tlv.SetXtalThreshold(Get<TimeSync>().GetXtalThreshold());
|
||||
tlvValue.SetTimeSyncPeriod(Get<TimeSync>().GetTimeSyncPeriod());
|
||||
tlvValue.SetXtalThreshold(Get<TimeSync>().GetXtalThreshold());
|
||||
|
||||
return tlv.AppendTo(*this);
|
||||
return Tlv::Append<TimeParameterTlv>(*this, tlvValue);
|
||||
}
|
||||
|
||||
Error Mle::TxMessage::AppendXtalAccuracyTlv(void)
|
||||
@@ -5265,9 +5264,6 @@ void Mle::Attacher::HandleParentResponse(RxInfo &aRxInfo)
|
||||
uint32_t mleFrameCounter;
|
||||
Mac::ExtAddress extAddress;
|
||||
Mac::CslAccuracy cslAccuracy;
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
TimeParameterTlv timeParameterTlv;
|
||||
#endif
|
||||
|
||||
SuccessOrExit(error = Tlv::Find<SourceAddressTlv>(aRxInfo.mMessage, sourceAddress));
|
||||
|
||||
@@ -5394,23 +5390,23 @@ void Mle::Attacher::HandleParentResponse(RxInfo &aRxInfo)
|
||||
SuccessOrExit(error = aRxInfo.mMessage.ReadFrameCounterTlvs(linkFrameCounter, mleFrameCounter));
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
|
||||
if (Tlv::FindTlv(aRxInfo.mMessage, timeParameterTlv) == kErrorNone)
|
||||
{
|
||||
VerifyOrExit(timeParameterTlv.IsValid());
|
||||
|
||||
Get<TimeSync>().SetTimeSyncPeriod(timeParameterTlv.GetTimeSyncPeriod());
|
||||
Get<TimeSync>().SetXtalThreshold(timeParameterTlv.GetXtalThreshold());
|
||||
}
|
||||
TimeParameterTlvValue tlvValue;
|
||||
|
||||
if (Tlv::Find<TimeParameterTlv>(aRxInfo.mMessage, tlvValue) == kErrorNone)
|
||||
{
|
||||
Get<TimeSync>().SetTimeSyncPeriod(tlvValue.GetTimeSyncPeriod());
|
||||
Get<TimeSync>().SetXtalThreshold(tlvValue.GetXtalThreshold());
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_REQUIRED
|
||||
else
|
||||
{
|
||||
// If the time sync feature is required, don't choose the
|
||||
// parent which doesn't support it.
|
||||
ExitNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the time sync feature is required, don't choose the
|
||||
// parent which doesn't support it.
|
||||
ExitNow();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
|
||||
SuccessOrExit(error = aRxInfo.mMessage.ReadChallengeTlv(mParentCandidate.mRxChallenge));
|
||||
|
||||
@@ -867,29 +867,12 @@ typedef SimpleTlvInfo<Tlv::kCslChannel, ChannelTlvValue> CslChannelTlv;
|
||||
typedef TlvInfo<Tlv::kTimeRequest> TimeRequestTlv;
|
||||
|
||||
/**
|
||||
* Implements Time Parameter TLV generation and parsing.
|
||||
* Represents a Time Parameter TLV value.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class TimeParameterTlv : public Tlv, public TlvInfo<Tlv::kTimeParameter>
|
||||
class TimeParameterTlvValue
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetType(kTimeParameter);
|
||||
SetLength(sizeof(*this) - sizeof(Tlv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the TLV appears to be well-formed.
|
||||
*
|
||||
* @retval TRUE If the TLV appears to be well-formed.
|
||||
* @retval FALSE If the TLV does not appear to be well-formed.
|
||||
*/
|
||||
bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); }
|
||||
|
||||
/**
|
||||
* Returns the time sync period.
|
||||
*
|
||||
@@ -923,6 +906,11 @@ private:
|
||||
uint16_t mXtalThreshold;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Defines Time Parameter TLV constants and types.
|
||||
*/
|
||||
typedef SimpleTlvInfo<Tlv::kTimeParameter, TimeParameterTlvValue> TimeParameterTlv;
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
|
||||
|
||||
Reference in New Issue
Block a user