mirror of
https://github.com/espressif/openthread.git
synced 2026-08-15 07:07:46 +00:00
[dataset] move ApplyConfiguration() to DatasetManager (#10280)
This commit moves the implementation of `ApplyConfiguration()` from the `Dataset` class to `DatasetManager`. This aligns better with the responsibility of the `DatasetManager` class (managing the active and pending dataset and being an `InstanceLocator`), keeping the `Dataset` class focused on providing helper functions related to TLVs in the Dataset: finding TLVs, reading TLV values, writing/updating TLVs, etc.
This commit is contained in:
@@ -585,72 +585,6 @@ void Dataset::RemoveTlv(Tlv *aTlv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Dataset::ApplyConfiguration(Instance &aInstance) const
|
|
||||||
{
|
|
||||||
Mac::Mac &mac = aInstance.Get<Mac::Mac>();
|
|
||||||
KeyManager &keyManager = aInstance.Get<KeyManager>();
|
|
||||||
Error error = kErrorNone;
|
|
||||||
|
|
||||||
SuccessOrExit(error = ValidateTlvs());
|
|
||||||
|
|
||||||
for (const Tlv *cur = GetTlvsStart(); cur < GetTlvsEnd(); cur = cur->GetNext())
|
|
||||||
{
|
|
||||||
switch (cur->GetType())
|
|
||||||
{
|
|
||||||
case Tlv::kChannel:
|
|
||||||
{
|
|
||||||
uint8_t channel = static_cast<uint8_t>(cur->ReadValueAs<ChannelTlv>().GetChannel());
|
|
||||||
|
|
||||||
error = mac.SetPanChannel(channel);
|
|
||||||
|
|
||||||
if (error != kErrorNone)
|
|
||||||
{
|
|
||||||
LogWarn("ApplyConfiguration() Failed to set channel to %d (%s)", channel, ErrorToString(error));
|
|
||||||
ExitNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Tlv::kPanId:
|
|
||||||
mac.SetPanId(cur->ReadValueAs<PanIdTlv>());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Tlv::kExtendedPanId:
|
|
||||||
aInstance.Get<ExtendedPanIdManager>().SetExtPanId(cur->ReadValueAs<ExtendedPanIdTlv>());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Tlv::kNetworkName:
|
|
||||||
IgnoreError(aInstance.Get<NetworkNameManager>().SetNetworkName(As<NetworkNameTlv>(cur)->GetNetworkName()));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Tlv::kNetworkKey:
|
|
||||||
keyManager.SetNetworkKey(cur->ReadValueAs<NetworkKeyTlv>());
|
|
||||||
break;
|
|
||||||
|
|
||||||
#if OPENTHREAD_FTD
|
|
||||||
case Tlv::kPskc:
|
|
||||||
keyManager.SetPskc(cur->ReadValueAs<PskcTlv>());
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case Tlv::kMeshLocalPrefix:
|
|
||||||
aInstance.Get<Mle::MleRouter>().SetMeshLocalPrefix(cur->ReadValueAs<MeshLocalPrefixTlv>());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Tlv::kSecurityPolicy:
|
|
||||||
keyManager.SetSecurityPolicy(As<SecurityPolicyTlv>(cur)->GetSecurityPolicy());
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *Dataset::TypeToString(Type aType) { return (aType == kActive) ? "Active" : "Pending"; }
|
const char *Dataset::TypeToString(Type aType) { return (aType == kActive) ? "Active" : "Pending"; }
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||||
|
|||||||
@@ -636,17 +636,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
Error SetFrom(const Message &aMessage, uint16_t aOffset, uint16_t aLength);
|
Error SetFrom(const Message &aMessage, uint16_t aOffset, uint16_t aLength);
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies the Active or Pending Dataset to the Thread interface.
|
|
||||||
*
|
|
||||||
* @param[in] aInstance A reference to the OpenThread instance.
|
|
||||||
*
|
|
||||||
* @retval kErrorNone Successfully applied configuration.
|
|
||||||
* @retval kErrorParse The dataset has at least one TLV with invalid format.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
Error ApplyConfiguration(Instance &aInstance) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the start of Dataset TLVs sequence.
|
* Returns a pointer to the start of Dataset TLVs sequence.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ Error DatasetManager::Restore(void)
|
|||||||
|
|
||||||
if (IsActiveDataset())
|
if (IsActiveDataset())
|
||||||
{
|
{
|
||||||
IgnoreError(dataset.ApplyConfiguration(GetInstance()));
|
IgnoreError(ApplyConfiguration(dataset));
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalDatasetChange();
|
SignalDatasetChange();
|
||||||
@@ -172,7 +172,71 @@ Error DatasetManager::ApplyConfiguration(void) const
|
|||||||
Dataset dataset;
|
Dataset dataset;
|
||||||
|
|
||||||
SuccessOrExit(error = Read(dataset));
|
SuccessOrExit(error = Read(dataset));
|
||||||
SuccessOrExit(error = dataset.ApplyConfiguration(GetInstance()));
|
error = ApplyConfiguration(dataset);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error DatasetManager::ApplyConfiguration(const Dataset &aDataset) const
|
||||||
|
{
|
||||||
|
Error error = kErrorNone;
|
||||||
|
|
||||||
|
SuccessOrExit(error = aDataset.ValidateTlvs());
|
||||||
|
|
||||||
|
for (const Tlv *cur = aDataset.GetTlvsStart(); cur < aDataset.GetTlvsEnd(); cur = cur->GetNext())
|
||||||
|
{
|
||||||
|
switch (cur->GetType())
|
||||||
|
{
|
||||||
|
case Tlv::kChannel:
|
||||||
|
{
|
||||||
|
uint8_t channel = static_cast<uint8_t>(cur->ReadValueAs<ChannelTlv>().GetChannel());
|
||||||
|
|
||||||
|
error = Get<Mac::Mac>().SetPanChannel(channel);
|
||||||
|
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("ApplyConfiguration() Failed to set channel to %d (%s)", channel, ErrorToString(error));
|
||||||
|
ExitNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Tlv::kPanId:
|
||||||
|
Get<Mac::Mac>().SetPanId(cur->ReadValueAs<PanIdTlv>());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tlv::kExtendedPanId:
|
||||||
|
Get<ExtendedPanIdManager>().SetExtPanId(cur->ReadValueAs<ExtendedPanIdTlv>());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tlv::kNetworkName:
|
||||||
|
IgnoreError(Get<NetworkNameManager>().SetNetworkName(As<NetworkNameTlv>(cur)->GetNetworkName()));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tlv::kNetworkKey:
|
||||||
|
Get<KeyManager>().SetNetworkKey(cur->ReadValueAs<NetworkKeyTlv>());
|
||||||
|
break;
|
||||||
|
|
||||||
|
#if OPENTHREAD_FTD
|
||||||
|
case Tlv::kPskc:
|
||||||
|
Get<KeyManager>().SetPskc(cur->ReadValueAs<PskcTlv>());
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case Tlv::kMeshLocalPrefix:
|
||||||
|
Get<Mle::MleRouter>().SetMeshLocalPrefix(cur->ReadValueAs<MeshLocalPrefixTlv>());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Tlv::kSecurityPolicy:
|
||||||
|
Get<KeyManager>().SetSecurityPolicy(As<SecurityPolicyTlv>(cur)->GetSecurityPolicy());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -237,7 +301,7 @@ Error DatasetManager::Save(const Dataset &aDataset, bool aAllowOlderTimestamp)
|
|||||||
|
|
||||||
if (IsActiveDataset())
|
if (IsActiveDataset())
|
||||||
{
|
{
|
||||||
SuccessOrExit(error = aDataset.ApplyConfiguration(GetInstance()));
|
SuccessOrExit(error = ApplyConfiguration(aDataset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ private:
|
|||||||
bool IsActiveDataset(void) const { return (mType == Dataset::kActive); }
|
bool IsActiveDataset(void) const { return (mType == Dataset::kActive); }
|
||||||
bool IsPendingDataset(void) const { return (mType == Dataset::kPending); }
|
bool IsPendingDataset(void) const { return (mType == Dataset::kPending); }
|
||||||
void Clear(void);
|
void Clear(void);
|
||||||
|
Error ApplyConfiguration(const Dataset &aDataset) const;
|
||||||
void HandleGet(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) const;
|
void HandleGet(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) const;
|
||||||
void HandleTimer(void);
|
void HandleTimer(void);
|
||||||
Error Save(const Dataset &aDataset, bool aAllowOlderTimestamp);
|
Error Save(const Dataset &aDataset, bool aAllowOlderTimestamp);
|
||||||
|
|||||||
Reference in New Issue
Block a user