[mle] simplify CslClockAccuracyTlv (#12905)

This commit updates `CslClockAccuracyTlv` to use the `SimpleTlvInfo`
and a separate `CslClockAccuracyTlvValue` class. This change
simplifies how the TLV is appended to and read from messages
by leveraging the `Tlv::Append<TlvType>` and `Tlv::Find<TlvType>`
helper methods (avoiding the use of `FindTlv()`).
This commit is contained in:
Abtin Keshavarzian
2026-04-16 10:27:08 -05:00
committed by GitHub
parent e43df01933
commit e536562296
3 changed files with 44 additions and 51 deletions
+6 -13
View File
@@ -3852,13 +3852,8 @@ Error Mle::TxMessage::AppendCslTimeoutTlv(void)
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Error Mle::TxMessage::AppendCslClockAccuracyTlv(void)
{
CslClockAccuracyTlv cslClockAccuracyTlv;
cslClockAccuracyTlv.Init();
cslClockAccuracyTlv.SetCslClockAccuracy(Get<Radio>().GetCslAccuracy());
cslClockAccuracyTlv.SetCslUncertainty(Get<Radio>().GetCslUncertainty());
return Append(cslClockAccuracyTlv);
return Tlv::Append<CslClockAccuracyTlv>(
*this, CslClockAccuracyTlvValue(Get<Radio>().GetCslAccuracy(), Get<Radio>().GetCslUncertainty()));
}
#endif
@@ -4237,13 +4232,11 @@ exit:
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
Error Mle::RxMessage::ReadCslClockAccuracyTlv(Mac::CslAccuracy &aCslAccuracy) const
{
Error error;
CslClockAccuracyTlv clockAccuracyTlv;
Error error;
CslClockAccuracyTlvValue tlvValue;
SuccessOrExit(error = Tlv::FindTlv(*this, clockAccuracyTlv));
VerifyOrExit(clockAccuracyTlv.IsValid(), error = kErrorParse);
aCslAccuracy.SetClockAccuracy(clockAccuracyTlv.GetCslClockAccuracy());
aCslAccuracy.SetUncertainty(clockAccuracyTlv.GetCslUncertainty());
SuccessOrExit(error = Tlv::Find<CslClockAccuracyTlv>(*this, tlvValue));
tlvValue.Get(aCslAccuracy);
exit:
return error;
+19
View File
@@ -196,5 +196,24 @@ void LeaderDataTlvValue::Get(LeaderData &aLeaderData) const
aLeaderData.SetLeaderRouterId(mLeaderRouterId);
}
//---------------------------------------------------------------------------------------------------------------------
// CslClockAccuracyTlvValue
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
CslClockAccuracyTlvValue::CslClockAccuracyTlvValue(uint8_t aClockAccuracy, uint8_t aUncertainty)
: mClockAccuracy(aClockAccuracy)
, mUncertainty(aUncertainty)
{
}
void CslClockAccuracyTlvValue::Get(Mac::CslAccuracy &aAccuracy) const
{
aAccuracy.SetClockAccuracy(mClockAccuracy);
aAccuracy.SetUncertainty(mUncertainty);
}
#endif
} // namespace Mle
} // namespace ot
+19 -38
View File
@@ -926,63 +926,44 @@ private:
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
/**
* Implements CSL Clock Accuracy TLV generation and parsing.
* Represents CSL Clock Accuracy TLV value.
*/
OT_TOOL_PACKED_BEGIN
class CslClockAccuracyTlv : public Tlv, public TlvInfo<Tlv::kCslClockAccuracy>
class CslClockAccuracyTlvValue
{
public:
/**
* Initializes the TLV.
* Default constructor.
*/
void Init(void)
{
SetType(kCslClockAccuracy);
SetLength(sizeof(*this) - sizeof(Tlv));
}
CslClockAccuracyTlvValue(void) = default;
/**
* Indicates whether or not the TLV appears to be well-formed.
* Initializes the TLV value with given clock accuracy and uncertainty.
*
* @retval TRUE If the TLV appears to be well-formed.
* @retval FALSE If the TLV does not appear to be well-formed.
* @param[in] aClockAccuracy The clock accuracy in ppm.
* @param[in] aUncertainty The clock uncertainty in units of 10 us.
*/
bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); }
CslClockAccuracyTlvValue(uint8_t aClockAccuracy, uint8_t aUncertainty);
/**
* Returns the CSL Clock Accuracy value.
* Gets the CSL clock accuracy and uncertainty values.
*
* @returns The CSL Clock Accuracy value.
* @param[out] aAccuracy A reference to a `Mac::CslAccuracy` to return the values.
*/
uint8_t GetCslClockAccuracy(void) const { return mCslClockAccuracy; }
/**
* Sets the CSL Clock Accuracy value.
*
* @param[in] aCslClockAccuracy The CSL Clock Accuracy value.
*/
void SetCslClockAccuracy(uint8_t aCslClockAccuracy) { mCslClockAccuracy = aCslClockAccuracy; }
/**
* Returns the Clock Uncertainty value.
*
* @returns The Clock Uncertainty value.
*/
uint8_t GetCslUncertainty(void) const { return mCslUncertainty; }
/**
* Sets the CSL Uncertainty value.
*
* @param[in] aCslUncertainty The CSL Uncertainty value.
*/
void SetCslUncertainty(uint8_t aCslUncertainty) { mCslUncertainty = aCslUncertainty; }
void Get(Mac::CslAccuracy &aAccuracy) const;
private:
uint8_t mCslClockAccuracy;
uint8_t mCslUncertainty;
uint8_t mClockAccuracy;
uint8_t mUncertainty;
} OT_TOOL_PACKED_END;
/**
* Defines CSL Clock Accuracy TLV constants and types.
*/
typedef SimpleTlvInfo<Tlv::kCslClockAccuracy, CslClockAccuracyTlvValue> CslClockAccuracyTlv;
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
/**
* @}