mirror of
https://github.com/espressif/openthread.git
synced 2026-08-26 12:11:17 +00:00
[settings] update Dataset related methods to use Dataset::Type (#7602)
This commit is contained in:
@@ -210,9 +210,14 @@ void Settings::Wipe(void)
|
||||
LogInfo("Wiped all info");
|
||||
}
|
||||
|
||||
Error Settings::SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset)
|
||||
Settings::Key Settings::KeyForDatasetType(MeshCoP::Dataset::Type aType)
|
||||
{
|
||||
Key key = (aIsActive ? kKeyActiveDataset : kKeyPendingDataset);
|
||||
return (aType == MeshCoP::Dataset::kActive) ? kKeyActiveDataset : kKeyPendingDataset;
|
||||
}
|
||||
|
||||
Error Settings::SaveOperationalDataset(MeshCoP::Dataset::Type aType, const MeshCoP::Dataset &aDataset)
|
||||
{
|
||||
Key key = KeyForDatasetType(aType);
|
||||
Error error = Get<SettingsDriver>().Set(key, aDataset.GetBytes(), aDataset.GetSize());
|
||||
|
||||
Log(kActionSave, error, key);
|
||||
@@ -220,13 +225,12 @@ Error Settings::SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &a
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Settings::ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const
|
||||
Error Settings::ReadOperationalDataset(MeshCoP::Dataset::Type aType, MeshCoP::Dataset &aDataset) const
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t length = MeshCoP::Dataset::kMaxSize;
|
||||
|
||||
SuccessOrExit(error = Get<SettingsDriver>().Get(aIsActive ? kKeyActiveDataset : kKeyPendingDataset,
|
||||
aDataset.GetBytes(), &length));
|
||||
SuccessOrExit(error = Get<SettingsDriver>().Get(KeyForDatasetType(aType), aDataset.GetBytes(), &length));
|
||||
VerifyOrExit(length <= MeshCoP::Dataset::kMaxSize, error = kErrorNotFound);
|
||||
|
||||
aDataset.SetSize(length);
|
||||
@@ -235,9 +239,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Settings::DeleteOperationalDataset(bool aIsActive)
|
||||
Error Settings::DeleteOperationalDataset(MeshCoP::Dataset::Type aType)
|
||||
{
|
||||
Key key = (aIsActive ? kKeyActiveDataset : kKeyPendingDataset);
|
||||
Key key = KeyForDatasetType(aType);
|
||||
Error error = Get<SettingsDriver>().Delete(key);
|
||||
|
||||
Log(kActionDelete, error, key);
|
||||
|
||||
@@ -47,16 +47,13 @@
|
||||
#include "common/settings_driver.hpp"
|
||||
#include "crypto/ecdsa.hpp"
|
||||
#include "mac/mac_types.hpp"
|
||||
#include "meshcop/dataset.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
#include "utils/flash.hpp"
|
||||
#include "utils/slaac_address.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
namespace MeshCoP {
|
||||
class Dataset;
|
||||
}
|
||||
|
||||
class Settings;
|
||||
|
||||
/**
|
||||
@@ -799,38 +796,38 @@ public:
|
||||
/**
|
||||
* This method saves the Operational Dataset (active or pending).
|
||||
*
|
||||
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
||||
* @param[in] aType The Dataset type (active or pending) to save.
|
||||
* @param[in] aDataset A reference to a `Dataset` object to be saved.
|
||||
*
|
||||
* @retval kErrorNone Successfully saved the Dataset.
|
||||
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||
*
|
||||
*/
|
||||
Error SaveOperationalDataset(bool aIsActive, const MeshCoP::Dataset &aDataset);
|
||||
Error SaveOperationalDataset(MeshCoP::Dataset::Type aType, const MeshCoP::Dataset &aDataset);
|
||||
|
||||
/**
|
||||
* This method reads the Operational Dataset (active or pending).
|
||||
*
|
||||
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
||||
* @param[out] aDataset A reference to a `Dataset` object to output the read content.
|
||||
* @param[in] aType The Dataset type (active or pending) to read.
|
||||
* @param[out] aDataset A reference to a `Dataset` object to output the read content.
|
||||
*
|
||||
* @retval kErrorNone Successfully read the Dataset.
|
||||
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||
*
|
||||
*/
|
||||
Error ReadOperationalDataset(bool aIsActive, MeshCoP::Dataset &aDataset) const;
|
||||
Error ReadOperationalDataset(MeshCoP::Dataset::Type aType, MeshCoP::Dataset &aDataset) const;
|
||||
|
||||
/**
|
||||
* This method deletes the Operational Dataset (active/pending) from settings.
|
||||
*
|
||||
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
||||
* @param[in] aType The Dataset type (active or pending) to delete.
|
||||
*
|
||||
* @retval kErrorNone Successfully deleted the Dataset.
|
||||
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||
*
|
||||
*/
|
||||
Error DeleteOperationalDataset(bool aIsActive);
|
||||
Error DeleteOperationalDataset(MeshCoP::Dataset::Type aType);
|
||||
|
||||
/**
|
||||
* This template method reads a specified settings entry.
|
||||
@@ -1114,6 +1111,8 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
static Key KeyForDatasetType(MeshCoP::Dataset::Type aType);
|
||||
|
||||
Error ReadEntry(Key aKey, void *aValue, uint16_t aMaxLength) const;
|
||||
Error SaveEntry(Key aKey, const void *aValue, void *aPrev, uint16_t aLength);
|
||||
Error DeleteEntry(Key aKey);
|
||||
|
||||
@@ -66,7 +66,7 @@ void DatasetLocal::Clear(void)
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
DestroySecurelyStoredKeys();
|
||||
#endif
|
||||
IgnoreError(Get<Settings>().DeleteOperationalDataset(IsActive()));
|
||||
IgnoreError(Get<Settings>().DeleteOperationalDataset(mType));
|
||||
mTimestamp.Clear();
|
||||
mTimestampPresent = false;
|
||||
mSaved = false;
|
||||
@@ -94,7 +94,7 @@ Error DatasetLocal::Read(Dataset &aDataset) const
|
||||
uint32_t elapsed;
|
||||
Error error;
|
||||
|
||||
error = Get<Settings>().ReadOperationalDataset(IsActive(), aDataset);
|
||||
error = Get<Settings>().ReadOperationalDataset(mType, aDataset);
|
||||
VerifyOrExit(error == kErrorNone, aDataset.mLength = 0);
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
@@ -189,7 +189,7 @@ Error DatasetLocal::Save(const Dataset &aDataset)
|
||||
if (aDataset.GetSize() == 0)
|
||||
{
|
||||
// do not propagate error back
|
||||
IgnoreError(Get<Settings>().DeleteOperationalDataset(IsActive()));
|
||||
IgnoreError(Get<Settings>().DeleteOperationalDataset(mType));
|
||||
mSaved = false;
|
||||
LogInfo("%s dataset deleted", Dataset::TypeToString(mType));
|
||||
}
|
||||
@@ -201,9 +201,9 @@ Error DatasetLocal::Save(const Dataset &aDataset)
|
||||
|
||||
dataset.Set(GetType(), aDataset);
|
||||
MoveKeysToSecureStorage(dataset);
|
||||
SuccessOrExit(error = Get<Settings>().SaveOperationalDataset(IsActive(), dataset));
|
||||
SuccessOrExit(error = Get<Settings>().SaveOperationalDataset(mType, dataset));
|
||||
#else
|
||||
SuccessOrExit(error = Get<Settings>().SaveOperationalDataset(IsActive(), aDataset));
|
||||
SuccessOrExit(error = Get<Settings>().SaveOperationalDataset(mType, aDataset));
|
||||
#endif
|
||||
|
||||
mSaved = true;
|
||||
@@ -320,7 +320,7 @@ void DatasetLocal::EmplaceSecurelyStoredKeys(Dataset &aDataset) const
|
||||
|
||||
dataset.Set(GetType(), aDataset);
|
||||
MoveKeysToSecureStorage(dataset);
|
||||
SuccessOrAssert(error = Get<Settings>().SaveOperationalDataset(IsActive(), dataset));
|
||||
SuccessOrAssert(error = Get<Settings>().SaveOperationalDataset(mType, dataset));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user