[dataset] fix issue in applying pending dataset when delaytimer expires (#2988)

This commit is contained in:
rongli
2018-08-28 11:52:02 -07:00
committed by Jonathan Hui
parent 2e89aa0ad3
commit 54bf9ef0e0
3 changed files with 19 additions and 5 deletions
+13 -1
View File
@@ -518,7 +518,7 @@ void Dataset::Remove(uint8_t *aStart, uint8_t aLength)
mLength -= aLength;
}
otError Dataset::ApplyConfiguration(Instance &aInstance) const
otError Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated) const
{
ThreadNetif &netif = aInstance.GetThreadNetif();
Mac::Mac & mac = netif.GetMac();
@@ -528,6 +528,11 @@ otError Dataset::ApplyConfiguration(Instance &aInstance) const
VerifyOrExit(IsValid(), error = OT_ERROR_PARSE);
if (aIsMasterKeyUpdated)
{
*aIsMasterKeyUpdated = false;
}
while (cur < end)
{
switch (cur->GetType())
@@ -578,6 +583,13 @@ otError Dataset::ApplyConfiguration(Instance &aInstance) const
case Tlv::kNetworkMasterKey:
{
const NetworkMasterKeyTlv *key = static_cast<const NetworkMasterKeyTlv *>(cur);
if (aIsMasterKeyUpdated &&
memcmp(&key->GetNetworkMasterKey(), &netif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE))
{
*aIsMasterKeyUpdated = true;
}
netif.GetKeyManager().SetMasterKey(key->GetNetworkMasterKey());
break;
}
+3 -2
View File
@@ -224,13 +224,14 @@ public:
/**
* This method applies the Active or Pending Dataset to the Thread interface.
*
* @param[in] aInstance A reference to the OpenThread instance.
* @param[in] aInstance A reference to the OpenThread instance.
* @param[out] aIsMasterKeyUpdated A pointer to where to place whether master key was updated.
*
* @retval OT_ERROR_NONE Successfully applied configuration.
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
*
*/
otError ApplyConfiguration(Instance &aInstance) const;
otError ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated = NULL) const;
/**
* This method converts a Pending Dataset to an Active Dataset.
+3 -2
View File
@@ -149,6 +149,7 @@ otError DatasetManager::Set(const Dataset &aDataset)
otError error = OT_ERROR_NONE;
const Timestamp *timestamp;
int compare;
bool isMasterkeyUpdated = false;
timestamp = aDataset.GetTimestamp();
@@ -159,13 +160,13 @@ otError DatasetManager::Set(const Dataset &aDataset)
if (mLocal.GetType() == Tlv::kActiveTimestamp)
{
SuccessOrExit(error = aDataset.ApplyConfiguration(GetInstance()));
SuccessOrExit(error = aDataset.ApplyConfiguration(GetInstance(), &isMasterkeyUpdated));
}
}
compare = mLocal.Compare(timestamp);
if (compare > 0)
if (isMasterkeyUpdated || compare > 0)
{
ThreadNetif &netif = GetNetif();