[mle] simplify parsing and appending of 'TimeRequestTlv' (#5849)

This commit is contained in:
Abtin Keshavarzian
2020-11-24 09:43:11 -08:00
committed by GitHub
parent 088d193cd0
commit 6918698345
3 changed files with 6 additions and 51 deletions
+2 -5
View File
@@ -1354,11 +1354,8 @@ exit:
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
otError Mle::AppendTimeRequest(Message &aMessage)
{
TimeRequestTlv tlv;
tlv.Init();
return tlv.AppendTo(aMessage);
// `TimeRequestTlv` has no value.
return Tlv::Append<TimeRequestTlv>(aMessage, nullptr, 0);
}
otError Mle::AppendTimeParameter(Message &aMessage)
+2 -22
View File
@@ -561,9 +561,6 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf
LeaderData leaderData;
uint16_t sourceAddress;
RequestedTlvs requestedTlvs;
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
TimeRequestTlv timeRequest;
#endif
Log(kMessageReceive, kTypeLinkRequest, aMessageInfo.GetPeerAddr());
@@ -647,14 +644,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
if (neighbor != nullptr)
{
if (Tlv::FindTlv(aMessage, timeRequest) == OT_ERROR_NONE)
{
neighbor->SetTimeSyncEnabled(true);
}
else
{
neighbor->SetTimeSyncEnabled(false);
}
neighbor->SetTimeSyncEnabled(Tlv::Find<TimeRequestTlv>(aMessage, nullptr, 0) == OT_ERROR_NONE);
}
#endif
@@ -1553,9 +1543,6 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI
Challenge challenge;
Router * leader;
Child * child;
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
TimeRequestTlv timeRequest;
#endif
Log(kMessageReceive, kTypeParentRequest, aMessageInfo.GetPeerAddr());
@@ -1630,14 +1617,7 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI
child->ResetLinkFailures();
child->SetState(Neighbor::kStateParentRequest);
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
if (Tlv::FindTlv(aMessage, timeRequest) == OT_ERROR_NONE)
{
child->SetTimeSyncEnabled(true);
}
else
{
child->SetTimeSyncEnabled(false);
}
child->SetTimeSyncEnabled(Tlv::Find<TimeRequestTlv>(aMessage, nullptr, 0) == OT_ERROR_NONE);
#endif
}
else if (TimerMilli::GetNow() - child->GetLastHeard() < kParentRequestRouterTimeout - kParentRequestDuplicateMargin)
+2 -24
View File
@@ -1142,32 +1142,10 @@ private:
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
/**
* This class implements Time Request TLV generation and parsing.
* This class defines Time Request TLV constants and types.
*
*/
OT_TOOL_PACKED_BEGIN
class TimeRequestTlv : public Tlv, public TlvInfo<Tlv::kTimeRequest>
{
public:
/**
* This method initializes the TLV.
*
*/
void Init(void)
{
SetType(kTimeRequest);
SetLength(sizeof(*this) - sizeof(Tlv));
}
/**
* This method 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); }
} OT_TOOL_PACKED_END;
typedef TlvInfo<Tlv::kTimeRequest> TimeRequestTlv;
/**
* This class implements Time Parameter TLV generation and parsing.