[mle] fix unexpected data request (#4326)

This commit compares data version properly according to the device
mode (whether or not requiring full network data), thus avoiding
unexpected data request when receiving MLE advertisement.
This commit is contained in:
Rongli Sun
2019-11-15 00:29:55 +01:00
committed by Jonathan Hui
parent 13d185bf01
commit b816319a28
2 changed files with 19 additions and 15 deletions
+18 -15
View File
@@ -2877,8 +2877,7 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo
break;
}
if (mRetrieveNewNetworkData ||
(static_cast<int8_t>(leaderData.GetDataVersion() - Get<NetworkData::Leader>().GetVersion()) > 0))
if (mRetrieveNewNetworkData || IsNetworkDataNewer(leaderData))
{
delay = Random::NonCrypto::GetUint16InRange(0, kMleMaxResponseDelay);
SendDataRequest(aMessageInfo.GetPeerAddr(), tlvs, sizeof(tlvs), delay);
@@ -2919,6 +2918,22 @@ exit:
return error;
}
bool Mle::IsNetworkDataNewer(const LeaderDataTlv &aLeaderData)
{
int8_t diff;
if (IsFullNetworkData())
{
diff = static_cast<int8_t>(aLeaderData.GetDataVersion() - Get<NetworkData::Leader>().GetVersion());
}
else
{
diff = static_cast<int8_t>(aLeaderData.GetStableDataVersion() - Get<NetworkData::Leader>().GetStableVersion());
}
return (diff > 0);
}
otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
@@ -2950,19 +2965,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
}
else if (!mRetrieveNewNetworkData)
{
int8_t diff;
if (IsFullNetworkData())
{
diff = static_cast<int8_t>(leaderData.GetDataVersion() - Get<NetworkData::Leader>().GetVersion());
}
else
{
diff =
static_cast<int8_t>(leaderData.GetStableDataVersion() - Get<NetworkData::Leader>().GetStableVersion());
}
VerifyOrExit(diff > 0);
VerifyOrExit(IsNetworkDataNewer(leaderData));
}
// Active Timestamp
+1
View File
@@ -1713,6 +1713,7 @@ private:
uint32_t Reattach(void);
bool IsBetterParent(uint16_t aRloc16, uint8_t aLinkQuality, uint8_t aLinkMargin, ConnectivityTlv &aConnectivityTlv);
bool IsNetworkDataNewer(const LeaderDataTlv &aLeaderData);
void ResetParentCandidate(void);
otError GetAlocAddress(Ip6::Address &aAddress, uint16_t aAloc16) const;