mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 22:57:46 +00:00
Use Tlv::GetOffset() method to find MLE Discovery TLV (#1896)
This commit is contained in:
+2
-16
@@ -3066,23 +3066,9 @@ otError Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::Message
|
||||
|
||||
VerifyOrExit(mIsDiscoverInProgress, error = OT_ERROR_DROP);
|
||||
|
||||
offset = aMessage.GetOffset();
|
||||
end = aMessage.GetLength();
|
||||
|
||||
// find MLE Discovery TLV
|
||||
while (offset < end)
|
||||
{
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
|
||||
if (tlv.GetType() == Tlv::kDiscovery)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
offset += sizeof(tlv) + tlv.GetLength();
|
||||
}
|
||||
|
||||
VerifyOrExit(offset < end, error = OT_ERROR_PARSE);
|
||||
VerifyOrExit(Tlv::GetOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
|
||||
offset += sizeof(tlv);
|
||||
end = offset + tlv.GetLength();
|
||||
|
||||
@@ -2570,23 +2570,9 @@ otError MleRouter::HandleDiscoveryRequest(const Message &aMessage, const Ip6::Me
|
||||
// only Routers and REEDs respond
|
||||
VerifyOrExit((mDeviceMode & ModeTlv::kModeFFD) != 0, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
offset = aMessage.GetOffset();
|
||||
end = aMessage.GetLength();
|
||||
|
||||
// find MLE Discovery TLV
|
||||
while (offset < end)
|
||||
{
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
|
||||
if (tlv.GetType() == Tlv::kDiscovery)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
offset += sizeof(tlv) + tlv.GetLength();
|
||||
}
|
||||
|
||||
VerifyOrExit(offset < end, error = OT_ERROR_PARSE);
|
||||
VerifyOrExit(Tlv::GetOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
|
||||
offset += sizeof(tlv);
|
||||
end = offset + sizeof(tlv) + tlv.GetLength();
|
||||
|
||||
Reference in New Issue
Block a user