mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 06:37:46 +00:00
[mle] add ChannelTlvValue to use in ChannelTlv & CslChannelTlv (#9612)
This commit is contained in:
+5
-17
@@ -2208,7 +2208,6 @@ void Mle::SendAnnounce(uint8_t aChannel, AnnounceMode aMode)
|
||||
void Mle::SendAnnounce(uint8_t aChannel, const Ip6::Address &aDestination, AnnounceMode aMode)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ChannelTlv channelTlv;
|
||||
MeshCoP::Timestamp activeTimestamp;
|
||||
TxMessage *message = nullptr;
|
||||
|
||||
@@ -2217,10 +2216,7 @@ void Mle::SendAnnounce(uint8_t aChannel, const Ip6::Address &aDestination, Annou
|
||||
message->SetLinkSecurityEnabled(true);
|
||||
message->SetChannel(aChannel);
|
||||
|
||||
channelTlv.Init();
|
||||
channelTlv.SetChannelPage(0);
|
||||
channelTlv.SetChannel(Get<Mac::Mac>().GetPanChannel());
|
||||
SuccessOrExit(error = channelTlv.AppendTo(*message));
|
||||
SuccessOrExit(error = Tlv::Append<ChannelTlv>(*message, ChannelTlvValue(Get<Mac::Mac>().GetPanChannel())));
|
||||
|
||||
switch (aMode)
|
||||
{
|
||||
@@ -3718,7 +3714,7 @@ exit:
|
||||
void Mle::HandleAnnounce(RxInfo &aRxInfo)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ChannelTlv channelTlv;
|
||||
ChannelTlvValue channelTlvValue;
|
||||
MeshCoP::Timestamp timestamp;
|
||||
const MeshCoP::Timestamp *localTimestamp;
|
||||
uint8_t channel;
|
||||
@@ -3729,10 +3725,8 @@ void Mle::HandleAnnounce(RxInfo &aRxInfo)
|
||||
|
||||
Log(kMessageReceive, kTypeAnnounce, aRxInfo.mMessageInfo.GetPeerAddr());
|
||||
|
||||
SuccessOrExit(error = Tlv::FindTlv(aRxInfo.mMessage, channelTlv));
|
||||
VerifyOrExit(channelTlv.IsValid(), error = kErrorParse);
|
||||
|
||||
channel = static_cast<uint8_t>(channelTlv.GetChannel());
|
||||
SuccessOrExit(error = Tlv::Find<ChannelTlv>(aRxInfo.mMessage, channelTlvValue));
|
||||
channel = static_cast<uint8_t>(channelTlvValue.GetChannel());
|
||||
|
||||
SuccessOrExit(error = Tlv::Find<ActiveTimestampTlv>(aRxInfo.mMessage, timestamp));
|
||||
SuccessOrExit(error = Tlv::Find<PanIdTlv>(aRxInfo.mMessage, panId));
|
||||
@@ -4807,16 +4801,10 @@ exit:
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
||||
Error Mle::TxMessage::AppendCslChannelTlv(void)
|
||||
{
|
||||
CslChannelTlv cslChannel;
|
||||
|
||||
// CSL channel value of zero indicates that the CSL channel is not
|
||||
// specified. We can use this value in the TLV as well.
|
||||
|
||||
cslChannel.Init();
|
||||
cslChannel.SetChannelPage(0);
|
||||
cslChannel.SetChannel(Get<Mac::Mac>().GetCslChannel());
|
||||
|
||||
return Append(cslChannel);
|
||||
return Tlv::Append<CslChannelTlv>(*this, ChannelTlvValue(Get<Mac::Mac>().GetCslChannel()));
|
||||
}
|
||||
|
||||
Error Mle::TxMessage::AppendCslTimeoutTlv(void)
|
||||
|
||||
@@ -2314,8 +2314,8 @@ void MleRouter::HandleChildUpdateRequest(RxInfo &aRxInfo)
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
|
||||
if (child->IsCslSynchronized())
|
||||
{
|
||||
CslChannelTlv cslChannel;
|
||||
uint32_t cslTimeout;
|
||||
ChannelTlvValue cslChannelTlvValue;
|
||||
uint32_t cslTimeout;
|
||||
|
||||
switch (Tlv::Find<CslTimeoutTlv>(aRxInfo.mMessage, cslTimeout))
|
||||
{
|
||||
@@ -2330,13 +2330,11 @@ void MleRouter::HandleChildUpdateRequest(RxInfo &aRxInfo)
|
||||
ExitNow(error = kErrorNone);
|
||||
}
|
||||
|
||||
if (Tlv::FindTlv(aRxInfo.mMessage, cslChannel) == kErrorNone)
|
||||
if (Tlv::Find<CslChannelTlv>(aRxInfo.mMessage, cslChannelTlvValue) == kErrorNone)
|
||||
{
|
||||
VerifyOrExit(cslChannel.IsValid(), error = kErrorParse);
|
||||
|
||||
// Special value of zero is used to indicate that
|
||||
// CSL channel is not specified.
|
||||
child->SetCslChannel(static_cast<uint8_t>(cslChannel.GetChannel()));
|
||||
child->SetCslChannel(static_cast<uint8_t>(cslChannelTlvValue.GetChannel()));
|
||||
}
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
|
||||
|
||||
@@ -1028,31 +1028,44 @@ private:
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements Channel TLV generation and parsing.
|
||||
* Implements Channel TLV value format.
|
||||
*
|
||||
* This is used by both Channel TLV and CSL Channel TLV.
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class ChannelTlv : public Tlv, public TlvInfo<Tlv::kChannel>
|
||||
class ChannelTlvValue
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
* Default constructor.
|
||||
*
|
||||
*/
|
||||
void Init(void)
|
||||
ChannelTlvValue(void) = default;
|
||||
|
||||
/**
|
||||
* Initializes the `ChannelTlvValue` with a given channel page and channel values.
|
||||
*
|
||||
* @param[in] aChannelPage The channel page.
|
||||
* @param[in] aChannel The channel.
|
||||
*
|
||||
*/
|
||||
ChannelTlvValue(uint8_t aChannelPage, uint16_t aChannel)
|
||||
: mChannelPage(aChannelPage)
|
||||
, mChannel(HostSwap16(aChannel))
|
||||
{
|
||||
SetType(kChannel);
|
||||
SetLength(sizeof(*this) - sizeof(Tlv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the TLV appears to be well-formed.
|
||||
* Initializes the `ChannelTlvValue` with zero channel page and a given channel value.
|
||||
*
|
||||
* @retval TRUE If the TLV appears to be well-formed.
|
||||
* @retval FALSE If the TLV does not appear to be well-formed.
|
||||
* @param[in] aChannel The channel.
|
||||
*
|
||||
*/
|
||||
bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); }
|
||||
ChannelTlvValue(uint16_t aChannel)
|
||||
: ChannelTlvValue(0, aChannel)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Channel Page value.
|
||||
@@ -1091,6 +1104,18 @@ private:
|
||||
uint16_t mChannel;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Defines Channel TLV constants and types.
|
||||
*
|
||||
*/
|
||||
typedef SimpleTlvInfo<Tlv::kChannel, ChannelTlvValue> ChannelTlv;
|
||||
|
||||
/**
|
||||
* Defines CSL Channel TLV constants and types.
|
||||
*
|
||||
*/
|
||||
typedef SimpleTlvInfo<Tlv::kCslChannel, ChannelTlvValue> CslChannelTlv;
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
/**
|
||||
* Defines Time Request TLV constants and types.
|
||||
@@ -1164,73 +1189,6 @@ private:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE)
|
||||
/**
|
||||
* Implements CSL Channel TLV generation and parsing.
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class CslChannelTlv : public Tlv, public TlvInfo<Tlv::kCslChannel>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
*
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetType(kCslChannel);
|
||||
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 Channel Page value.
|
||||
*
|
||||
* @returns The Channel Page value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetChannelPage(void) const { return mChannelPage; }
|
||||
|
||||
/**
|
||||
* Sets the Channel Page value.
|
||||
*
|
||||
* @param[in] aChannelPage The Channel Page value.
|
||||
*
|
||||
*/
|
||||
void SetChannelPage(uint8_t aChannelPage) { mChannelPage = aChannelPage; }
|
||||
|
||||
/**
|
||||
* Returns the Channel value.
|
||||
*
|
||||
* @returns The Channel value.
|
||||
*
|
||||
*/
|
||||
uint16_t GetChannel(void) const { return HostSwap16(mChannel); }
|
||||
|
||||
/**
|
||||
* Sets the Channel value.
|
||||
*
|
||||
* @param[in] aChannel The Channel value.
|
||||
*
|
||||
*/
|
||||
void SetChannel(uint16_t aChannel) { mChannel = HostSwap16(aChannel); }
|
||||
|
||||
private:
|
||||
uint8_t mChannelPage;
|
||||
uint16_t mChannel;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE)
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
|
||||
/**
|
||||
* Implements CSL Clock Accuracy TLV generation and parsing.
|
||||
|
||||
Reference in New Issue
Block a user