mirror of
https://github.com/espressif/openthread.git
synced 2026-10-18 05:28:10 +00:00
[dataset] introduce WriteTlv() methods (#9664)
This commit adds different flavors of `WriteTlv()` including template version as `Write<SimpleTlvType>()`. These methods write or update a TLV in `Dataset`. The new methods replace the previous `SetTlv()` methods. This new approach introduces type safety checks during compilation, guaranteeing the use of the correct value type for each TLV. For instance, `Write<PanIdTlv>()` only accepts `uint16_t` value, while `Write<NetworkKeyTlv>()` only accepts `NetworkKey` value. This commit also renames the previous `GetTlv()` to `FindTlv()`.
This commit is contained in:
@@ -179,7 +179,7 @@ exit:
|
||||
return rval;
|
||||
}
|
||||
|
||||
const Tlv *Dataset::GetTlv(Tlv::Type aType) const { return As<Tlv>(Tlv::FindTlv(mTlvs, mLength, aType)); }
|
||||
const Tlv *Dataset::FindTlv(Tlv::Type aType) const { return As<Tlv>(Tlv::FindTlv(mTlvs, mLength, aType)); }
|
||||
|
||||
void Dataset::ConvertTo(Info &aDatasetInfo) const
|
||||
{
|
||||
@@ -286,7 +286,7 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
|
||||
Timestamp activeTimestamp;
|
||||
|
||||
aDatasetInfo.GetActiveTimestamp(activeTimestamp);
|
||||
IgnoreError(SetTlv(Tlv::kActiveTimestamp, activeTimestamp));
|
||||
IgnoreError(Write<ActiveTimestampTlv>(activeTimestamp));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsPendingTimestampPresent())
|
||||
@@ -294,12 +294,12 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
|
||||
Timestamp pendingTimestamp;
|
||||
|
||||
aDatasetInfo.GetPendingTimestamp(pendingTimestamp);
|
||||
IgnoreError(SetTlv(Tlv::kPendingTimestamp, pendingTimestamp));
|
||||
IgnoreError(Write<PendingTimestampTlv>(pendingTimestamp));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsDelayPresent())
|
||||
{
|
||||
IgnoreError(SetTlv(Tlv::kDelayTimer, aDatasetInfo.GetDelay()));
|
||||
IgnoreError(Write<DelayTimerTlv>(aDatasetInfo.GetDelay()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsChannelPresent())
|
||||
@@ -307,7 +307,7 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
|
||||
ChannelTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetChannel(aDatasetInfo.GetChannel());
|
||||
IgnoreError(SetTlv(tlv));
|
||||
IgnoreError(WriteTlv(tlv));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsChannelMaskPresent())
|
||||
@@ -315,39 +315,39 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
|
||||
ChannelMaskTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetChannelMask(aDatasetInfo.GetChannelMask());
|
||||
IgnoreError(SetTlv(tlv));
|
||||
IgnoreError(WriteTlv(tlv));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsExtendedPanIdPresent())
|
||||
{
|
||||
IgnoreError(SetTlv(Tlv::kExtendedPanId, aDatasetInfo.GetExtendedPanId()));
|
||||
IgnoreError(Write<ExtendedPanIdTlv>(aDatasetInfo.GetExtendedPanId()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsMeshLocalPrefixPresent())
|
||||
{
|
||||
IgnoreError(SetTlv(Tlv::kMeshLocalPrefix, aDatasetInfo.GetMeshLocalPrefix()));
|
||||
IgnoreError(Write<MeshLocalPrefixTlv>(aDatasetInfo.GetMeshLocalPrefix()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsNetworkKeyPresent())
|
||||
{
|
||||
IgnoreError(SetTlv(Tlv::kNetworkKey, aDatasetInfo.GetNetworkKey()));
|
||||
IgnoreError(Write<NetworkKeyTlv>(aDatasetInfo.GetNetworkKey()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsNetworkNamePresent())
|
||||
{
|
||||
NameData nameData = aDatasetInfo.GetNetworkName().GetAsData();
|
||||
|
||||
IgnoreError(SetTlv(Tlv::kNetworkName, nameData.GetBuffer(), nameData.GetLength()));
|
||||
IgnoreError(WriteTlv(Tlv::kNetworkName, nameData.GetBuffer(), nameData.GetLength()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsPanIdPresent())
|
||||
{
|
||||
IgnoreError(SetTlv(Tlv::kPanId, aDatasetInfo.GetPanId()));
|
||||
IgnoreError(Write<PanIdTlv>(aDatasetInfo.GetPanId()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsPskcPresent())
|
||||
{
|
||||
IgnoreError(SetTlv(Tlv::kPskc, aDatasetInfo.GetPskc()));
|
||||
IgnoreError(Write<PskcTlv>(aDatasetInfo.GetPskc()));
|
||||
}
|
||||
|
||||
if (aDatasetInfo.IsSecurityPolicyPresent())
|
||||
@@ -356,7 +356,7 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
|
||||
|
||||
tlv.Init();
|
||||
tlv.SetSecurityPolicy(aDatasetInfo.GetSecurityPolicy());
|
||||
IgnoreError(SetTlv(tlv));
|
||||
IgnoreError(WriteTlv(tlv));
|
||||
}
|
||||
|
||||
mUpdateTime = TimerMilli::GetNow();
|
||||
@@ -371,13 +371,13 @@ Error Dataset::GetTimestamp(Type aType, Timestamp &aTimestamp) const
|
||||
|
||||
if (aType == kActive)
|
||||
{
|
||||
tlv = GetTlv(Tlv::kActiveTimestamp);
|
||||
tlv = FindTlv(Tlv::kActiveTimestamp);
|
||||
VerifyOrExit(tlv != nullptr, error = kErrorNotFound);
|
||||
aTimestamp = tlv->ReadValueAs<ActiveTimestampTlv>();
|
||||
}
|
||||
else
|
||||
{
|
||||
tlv = GetTlv(Tlv::kPendingTimestamp);
|
||||
tlv = FindTlv(Tlv::kPendingTimestamp);
|
||||
VerifyOrExit(tlv != nullptr, error = kErrorNotFound);
|
||||
aTimestamp = tlv->ReadValueAs<PendingTimestampTlv>();
|
||||
}
|
||||
@@ -388,35 +388,38 @@ exit:
|
||||
|
||||
void Dataset::SetTimestamp(Type aType, const Timestamp &aTimestamp)
|
||||
{
|
||||
IgnoreError(SetTlv((aType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, aTimestamp));
|
||||
if (aType == kActive)
|
||||
{
|
||||
IgnoreError(Write<ActiveTimestampTlv>(aTimestamp));
|
||||
}
|
||||
else
|
||||
{
|
||||
IgnoreError(Write<PendingTimestampTlv>(aTimestamp));
|
||||
}
|
||||
}
|
||||
|
||||
Error Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
|
||||
Error Dataset::WriteTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t bytesAvailable = sizeof(mTlvs) - mLength;
|
||||
Tlv *old = GetTlv(aType);
|
||||
Tlv tlv;
|
||||
Tlv *oldTlv = FindTlv(aType);
|
||||
Tlv *newTlv;
|
||||
|
||||
if (old != nullptr)
|
||||
if (oldTlv != nullptr)
|
||||
{
|
||||
bytesAvailable += sizeof(Tlv) + old->GetLength();
|
||||
bytesAvailable += sizeof(Tlv) + oldTlv->GetLength();
|
||||
}
|
||||
|
||||
VerifyOrExit(sizeof(Tlv) + aLength <= bytesAvailable, error = kErrorNoBufs);
|
||||
|
||||
if (old != nullptr)
|
||||
{
|
||||
RemoveTlv(old);
|
||||
}
|
||||
RemoveTlv(oldTlv);
|
||||
|
||||
tlv.SetType(aType);
|
||||
tlv.SetLength(aLength);
|
||||
memcpy(mTlvs + mLength, &tlv, sizeof(Tlv));
|
||||
mLength += sizeof(Tlv);
|
||||
newTlv = GetTlvsEnd();
|
||||
mLength += sizeof(Tlv) + aLength;
|
||||
|
||||
memcpy(mTlvs + mLength, aValue, aLength);
|
||||
mLength += aLength;
|
||||
newTlv->SetType(aType);
|
||||
newTlv->SetLength(aLength);
|
||||
memcpy(newTlv->GetValue(), aValue, aLength);
|
||||
|
||||
mUpdateTime = TimerMilli::GetNow();
|
||||
|
||||
@@ -424,7 +427,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Dataset::SetTlv(const Tlv &aTlv) { return SetTlv(aTlv.GetType(), aTlv.GetValue(), aTlv.GetLength()); }
|
||||
Error Dataset::WriteTlv(const Tlv &aTlv) { return WriteTlv(aTlv.GetType(), aTlv.GetValue(), aTlv.GetLength()); }
|
||||
|
||||
Error Dataset::ReadFromMessage(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
|
||||
{
|
||||
@@ -444,16 +447,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Dataset::RemoveTlv(Tlv::Type aType)
|
||||
{
|
||||
Tlv *tlv;
|
||||
|
||||
VerifyOrExit((tlv = GetTlv(aType)) != nullptr);
|
||||
RemoveTlv(tlv);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
void Dataset::RemoveTlv(Tlv::Type aType) { RemoveTlv(FindTlv(aType)); }
|
||||
|
||||
Error Dataset::AppendMleDatasetTlv(Type aType, Message &aMessage) const
|
||||
{
|
||||
@@ -504,11 +498,14 @@ exit:
|
||||
|
||||
void Dataset::RemoveTlv(Tlv *aTlv)
|
||||
{
|
||||
uint8_t *start = reinterpret_cast<uint8_t *>(aTlv);
|
||||
uint16_t length = sizeof(Tlv) + aTlv->GetLength();
|
||||
if (aTlv != nullptr)
|
||||
{
|
||||
uint8_t *start = reinterpret_cast<uint8_t *>(aTlv);
|
||||
uint16_t length = sizeof(Tlv) + aTlv->GetLength();
|
||||
|
||||
memmove(start, start + length, mLength - (static_cast<uint8_t>(start - mTlvs) + length));
|
||||
mLength -= length;
|
||||
memmove(start, start + length, mLength - (static_cast<uint8_t>(start - mTlvs) + length));
|
||||
mLength -= length;
|
||||
}
|
||||
}
|
||||
|
||||
Error Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsNetworkKeyUpdated) const
|
||||
@@ -609,7 +606,7 @@ void Dataset::SaveTlvInSecureStorageAndClearValue(Tlv::Type aTlvType, Crypto::St
|
||||
{
|
||||
using namespace ot::Crypto::Storage;
|
||||
|
||||
Tlv *tlv = GetTlv(aTlvType);
|
||||
Tlv *tlv = FindTlv(aTlvType);
|
||||
|
||||
VerifyOrExit(tlv != nullptr);
|
||||
VerifyOrExit(tlv->GetLength() > 0);
|
||||
@@ -628,7 +625,7 @@ Error Dataset::ReadTlvFromSecureStorage(Tlv::Type aTlvType, Crypto::Storage::Key
|
||||
using namespace ot::Crypto::Storage;
|
||||
|
||||
Error error = kErrorNone;
|
||||
Tlv *tlv = GetTlv(aTlvType);
|
||||
Tlv *tlv = FindTlv(aTlvType);
|
||||
size_t readLength;
|
||||
|
||||
VerifyOrExit(tlv != nullptr);
|
||||
|
||||
+71
-108
@@ -631,7 +631,7 @@ public:
|
||||
* @retval FALSE TLV with @p aType is not present in the Dataset.
|
||||
*
|
||||
*/
|
||||
bool ContainsTlv(Tlv::Type aType) const { return (GetTlv(aType) != nullptr); }
|
||||
bool ContainsTlv(Tlv::Type aType) const { return (FindTlv(aType) != nullptr); }
|
||||
|
||||
/**
|
||||
* Indicates whether or not a given TLV type is present in the Dataset.
|
||||
@@ -648,47 +648,101 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the TLV with a given type.
|
||||
* Searches for a given TLV type in the Dataset.
|
||||
*
|
||||
* @param[in] aType A TLV type.
|
||||
* @param[in] aType The TLV type to find.
|
||||
*
|
||||
* @returns A pointer to the TLV or `nullptr` if none is found.
|
||||
* @returns A pointer to the TLV or `nullptr` if not found.
|
||||
*
|
||||
*/
|
||||
Tlv *GetTlv(Tlv::Type aType) { return AsNonConst(AsConst(this)->GetTlv(aType)); }
|
||||
Tlv *FindTlv(Tlv::Type aType) { return AsNonConst(AsConst(this)->FindTlv(aType)); }
|
||||
|
||||
/**
|
||||
* Returns a pointer to the TLV with a given type.
|
||||
* Searches for a given TLV type in the Dataset.
|
||||
*
|
||||
* @param[in] aType The TLV type.
|
||||
* @param[in] aType The TLV type to find.
|
||||
*
|
||||
* @returns A pointer to the TLV or `nullptr` if none is found.
|
||||
* @returns A pointer to the TLV or `nullptr` if not found.
|
||||
*
|
||||
*/
|
||||
const Tlv *GetTlv(Tlv::Type aType) const;
|
||||
const Tlv *FindTlv(Tlv::Type aType) const;
|
||||
|
||||
/**
|
||||
* Returns a pointer to the TLV with a given template type `TlvType`
|
||||
* Writes a TLV to the Dataset.
|
||||
*
|
||||
* @returns A pointer to the TLV or `nullptr` if none is found.
|
||||
* If the specified TLV type already exists, it will be replaced. Otherwise, the TLV will be appended.
|
||||
*
|
||||
* @param[in] aTlv A reference to the TLV.
|
||||
*
|
||||
* @retval kErrorNone Successfully updated the TLV.
|
||||
* @retval kErrorNoBufs Could not add the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
template <typename TlvType> TlvType *GetTlv(void)
|
||||
Error WriteTlv(const Tlv &aTlv);
|
||||
|
||||
/**
|
||||
* Writes a TLV in the Dataset.
|
||||
*
|
||||
* If the specified TLV type already exists, it will be replaced. Otherwise, the TLV will be appended.
|
||||
*
|
||||
* @param[in] aType The TLV type.
|
||||
* @param[in] aValue A pointer to a buffer containing the TLV value.
|
||||
* @param[in] aLength The TLV length.
|
||||
*
|
||||
* @retval kErrorNone Successfully updated the TLV.
|
||||
* @retval kErrorNoBufs Could not add the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
Error WriteTlv(Tlv::Type aType, const void *aValue, uint8_t aLength);
|
||||
|
||||
/**
|
||||
* Writes a simple TLV in the Dataset.
|
||||
*
|
||||
* If the specified TLV type already exists, it will be replaced. Otherwise, the TLV will be appended.
|
||||
*
|
||||
* @tparam SimpleTlvType The simple TLV type (must be a sub-class of `SimpleTlvInfo`).
|
||||
*
|
||||
* @param[in] aValue The TLV value.
|
||||
*
|
||||
* @retval kErrorNone Successfully updated the TLV.
|
||||
* @retval kErrorNoBufs Could not add the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
template <typename SimpleTlvType> Error Write(const typename SimpleTlvType::ValueType &aValue)
|
||||
{
|
||||
return As<TlvType>(GetTlv(static_cast<Tlv::Type>(TlvType::kType)));
|
||||
return WriteTlv(static_cast<Tlv::Type>(SimpleTlvType::kType), &aValue, sizeof(aValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the TLV with a given template type `TlvType`
|
||||
* Writes a `uint` TLV in the Dataset.
|
||||
*
|
||||
* @returns A pointer to the TLV or `nullptr` if none is found.
|
||||
* If the specified TLV type already exists, it will be replaced. Otherwise, the TLV will be appended.
|
||||
*
|
||||
* @tparam UintTlvType The integer simple TLV type (must be a sub-class of `UintTlvInfo`).
|
||||
*
|
||||
* @param[in] aValue The TLV value.
|
||||
*
|
||||
* @retval kErrorNone Successfully updated the TLV.
|
||||
* @retval kErrorNoBufs Could not add the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
template <typename TlvType> const TlvType *GetTlv(void) const
|
||||
template <typename UintTlvType> Error Write(typename UintTlvType::UintValueType aValue)
|
||||
{
|
||||
return As<TlvType>(GetTlv(static_cast<Tlv::Type>(TlvType::kType)));
|
||||
typename UintTlvType::UintValueType value = BigEndian::HostSwap(aValue);
|
||||
|
||||
return WriteTlv(static_cast<Tlv::Type>(UintTlvType::kType), &value, sizeof(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a TLV from the Dataset.
|
||||
*
|
||||
* If the Dataset does not contain the given TLV type, no action is performed.
|
||||
*
|
||||
* @param[in] aType The TLV type to remove.
|
||||
*
|
||||
*/
|
||||
void RemoveTlv(Tlv::Type aType);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the byte representation of the Dataset.
|
||||
*
|
||||
@@ -766,55 +820,6 @@ public:
|
||||
*/
|
||||
void SetTimestamp(Type aType, const Timestamp &aTimestamp);
|
||||
|
||||
/**
|
||||
* Sets a TLV in the Dataset.
|
||||
*
|
||||
* @param[in] aTlv A reference to the TLV.
|
||||
*
|
||||
* @retval kErrorNone Successfully set the TLV.
|
||||
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
Error SetTlv(const Tlv &aTlv);
|
||||
|
||||
/**
|
||||
* Sets a TLV with a given TLV Type and Value.
|
||||
*
|
||||
* @param[in] aType The TLV Type.
|
||||
* @param[in] aValue A pointer to TLV Value.
|
||||
* @param[in] aLength The TLV Length in bytes (length of @p aValue).
|
||||
*
|
||||
* @retval kErrorNone Successfully set the TLV.
|
||||
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
Error SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength);
|
||||
|
||||
/**
|
||||
* Sets a TLV with a given TLV Type and Value.
|
||||
*
|
||||
* @tparam ValueType The type of TLV's Value.
|
||||
*
|
||||
* Specializations of this template method are provided for `uint16_t` and `uint32_t` types which ensure big-endian
|
||||
* encoding is used.
|
||||
*
|
||||
* @param[in] aType The TLV Type.
|
||||
* @param[in] aValue The TLV Value (of type `ValueType`).
|
||||
*
|
||||
* @retval kErrorNone Successfully set the TLV.
|
||||
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
template <typename ValueType> Error SetTlv(Tlv::Type aType, const ValueType &aValue)
|
||||
{
|
||||
static_assert(!TypeTraits::IsPointer<ValueType>::kValue, "ValueType must not be a pointer");
|
||||
static_assert(!TypeTraits::IsSame<ValueType, uint16_t>::kValue, "Specialization must be used for uint16_t");
|
||||
static_assert(!TypeTraits::IsSame<ValueType, uint32_t>::kValue, "Specialization must be used for uint32_t");
|
||||
static_assert(!TypeTraits::IsSame<ValueType, uint64_t>::kValue, "Specialization must be used for uint64_t");
|
||||
|
||||
return SetTlv(aType, &aValue, sizeof(ValueType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the Dataset from a given message and checks that it is well-formed and valid.
|
||||
*
|
||||
@@ -859,14 +864,6 @@ public:
|
||||
*/
|
||||
void SetFrom(const otOperationalDatasetTlvs &aDataset);
|
||||
|
||||
/**
|
||||
* Removes a TLV from the Dataset.
|
||||
*
|
||||
* @param[in] aType The type of a specific TLV.
|
||||
*
|
||||
*/
|
||||
void RemoveTlv(Tlv::Type aType);
|
||||
|
||||
/**
|
||||
* Appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
|
||||
*
|
||||
@@ -980,40 +977,6 @@ private:
|
||||
uint16_t mLength; ///< The number of valid bytes in @var mTlvs
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a template specialization of `SetTlv<ValueType>` with a `uint16_t` value type.
|
||||
*
|
||||
* @param[in] aType The TLV Type.
|
||||
* @param[in] aValue The TLV value (as `uint16_t`).
|
||||
*
|
||||
* @retval kErrorNone Successfully set the TLV.
|
||||
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint16_t &aValue)
|
||||
{
|
||||
uint16_t value = BigEndian::HostSwap16(aValue);
|
||||
|
||||
return SetTlv(aType, &value, sizeof(uint16_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a template specialization of `SetTlv<ValueType>` with a `uint32_t` value type
|
||||
*
|
||||
* @param[in] aType The TLV Type.
|
||||
* @param[in] aValue The TLV value (as `uint32_t`).
|
||||
*
|
||||
* @retval kErrorNone Successfully set the TLV.
|
||||
* @retval kErrorNoBufs Could not set the TLV due to insufficient buffer space.
|
||||
*
|
||||
*/
|
||||
template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint32_t &aValue)
|
||||
{
|
||||
uint32_t value = BigEndian::HostSwap32(aValue);
|
||||
|
||||
return SetTlv(aType, &value, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
DefineCoreType(otOperationalDatasetComponents, MeshCoP::Dataset::Components);
|
||||
|
||||
@@ -108,7 +108,7 @@ Error DatasetLocal::Read(Dataset &aDataset) const
|
||||
{
|
||||
uint32_t elapsed;
|
||||
uint32_t delayTimer;
|
||||
Tlv *tlv = aDataset.GetTlv(Tlv::kDelayTimer);
|
||||
Tlv *tlv = aDataset.FindTlv(Tlv::kDelayTimer);
|
||||
|
||||
VerifyOrExit(tlv != nullptr);
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ Error DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
|
||||
|
||||
SuccessOrExit(error = Read(dataset));
|
||||
|
||||
channelMaskTlv = dataset.GetTlv<ChannelMaskTlv>();
|
||||
channelMaskTlv = As<ChannelMaskTlv>(dataset.FindTlv(Tlv::kChannelMask));
|
||||
VerifyOrExit(channelMaskTlv != nullptr, error = kErrorNotFound);
|
||||
VerifyOrExit((mask = channelMaskTlv->GetChannelMask()) != 0);
|
||||
|
||||
@@ -418,7 +418,7 @@ void DatasetManager::SendGetResponse(const Coap::Message &aRequest,
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tlv = dataset.GetTlv(static_cast<Tlv::Type>(aTlvs[index]))) != nullptr)
|
||||
if ((tlv = dataset.FindTlv(static_cast<Tlv::Type>(aTlvs[index]))) != nullptr)
|
||||
{
|
||||
SuccessOrExit(error = tlv->AppendTo(*message));
|
||||
}
|
||||
@@ -746,7 +746,7 @@ void PendingDatasetManager::StartDelayTimer(void)
|
||||
|
||||
mDelayTimer.Stop();
|
||||
|
||||
tlv = dataset.GetTlv(Tlv::kDelayTimer);
|
||||
tlv = dataset.FindTlv(Tlv::kDelayTimer);
|
||||
VerifyOrExit(tlv != nullptr);
|
||||
|
||||
delay = tlv->ReadValueAs<DelayTimerTlv>();
|
||||
@@ -770,7 +770,7 @@ void PendingDatasetManager::HandleDelayTimer(void)
|
||||
|
||||
// if the Delay Timer value is larger than what our Timer implementation can handle, we have to compute
|
||||
// the remainder and wait some more.
|
||||
if ((tlv = dataset.GetTlv(Tlv::kDelayTimer)) != nullptr)
|
||||
if ((tlv = dataset.FindTlv(Tlv::kDelayTimer)) != nullptr)
|
||||
{
|
||||
uint32_t elapsed = mDelayTimer.GetFireTime() - dataset.GetUpdateTime();
|
||||
uint32_t delay = tlv->ReadValueAs<DelayTimerTlv>();
|
||||
|
||||
@@ -220,7 +220,7 @@ Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo
|
||||
OT_FALL_THROUGH;
|
||||
|
||||
default:
|
||||
SuccessOrExit(dataset.SetTlv(datasetTlv));
|
||||
SuccessOrExit(dataset.WriteTlv(datasetTlv));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ Error ActiveDatasetManager::GenerateLocal(void)
|
||||
Timestamp timestamp;
|
||||
|
||||
timestamp.Clear();
|
||||
IgnoreError(dataset.SetTlv(Tlv::kActiveTimestamp, timestamp));
|
||||
IgnoreError(dataset.Write<ActiveTimestampTlv>(timestamp));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<ChannelTlv>())
|
||||
@@ -315,7 +315,7 @@ Error ActiveDatasetManager::GenerateLocal(void)
|
||||
ChannelTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetChannel(Get<Mac::Mac>().GetPanChannel());
|
||||
IgnoreError(dataset.SetTlv(tlv));
|
||||
IgnoreError(dataset.WriteTlv(tlv));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<ChannelMaskTlv>())
|
||||
@@ -323,17 +323,17 @@ Error ActiveDatasetManager::GenerateLocal(void)
|
||||
ChannelMaskTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetChannelMask(Get<Mac::Mac>().GetSupportedChannelMask().GetMask());
|
||||
IgnoreError(dataset.SetTlv(tlv));
|
||||
IgnoreError(dataset.WriteTlv(tlv));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<ExtendedPanIdTlv>())
|
||||
{
|
||||
IgnoreError(dataset.SetTlv(Tlv::kExtendedPanId, Get<ExtendedPanIdManager>().GetExtPanId()));
|
||||
IgnoreError(dataset.Write<ExtendedPanIdTlv>(Get<ExtendedPanIdManager>().GetExtPanId()));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<MeshLocalPrefixTlv>())
|
||||
{
|
||||
IgnoreError(dataset.SetTlv(Tlv::kMeshLocalPrefix, Get<Mle::MleRouter>().GetMeshLocalPrefix()));
|
||||
IgnoreError(dataset.Write<MeshLocalPrefixTlv>(Get<Mle::MleRouter>().GetMeshLocalPrefix()));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<NetworkKeyTlv>())
|
||||
@@ -341,19 +341,19 @@ Error ActiveDatasetManager::GenerateLocal(void)
|
||||
NetworkKey networkKey;
|
||||
|
||||
Get<KeyManager>().GetNetworkKey(networkKey);
|
||||
IgnoreError(dataset.SetTlv(Tlv::kNetworkKey, networkKey));
|
||||
IgnoreError(dataset.Write<NetworkKeyTlv>(networkKey));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<NetworkNameTlv>())
|
||||
{
|
||||
NameData nameData = Get<NetworkNameManager>().GetNetworkName().GetAsData();
|
||||
|
||||
IgnoreError(dataset.SetTlv(Tlv::kNetworkName, nameData.GetBuffer(), nameData.GetLength()));
|
||||
IgnoreError(dataset.WriteTlv(Tlv::kNetworkName, nameData.GetBuffer(), nameData.GetLength()));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<PanIdTlv>())
|
||||
{
|
||||
IgnoreError(dataset.SetTlv(Tlv::kPanId, Get<Mac::Mac>().GetPanId()));
|
||||
IgnoreError(dataset.Write<PanIdTlv>(Get<Mac::Mac>().GetPanId()));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<PskcTlv>())
|
||||
@@ -369,7 +369,7 @@ Error ActiveDatasetManager::GenerateLocal(void)
|
||||
SuccessOrExit(error = pskc.GenerateRandom());
|
||||
}
|
||||
|
||||
IgnoreError(dataset.SetTlv(Tlv::kPskc, pskc));
|
||||
IgnoreError(dataset.Write<PskcTlv>(pskc));
|
||||
}
|
||||
|
||||
if (!dataset.Contains<SecurityPolicyTlv>())
|
||||
@@ -378,7 +378,7 @@ Error ActiveDatasetManager::GenerateLocal(void)
|
||||
|
||||
tlv.Init();
|
||||
tlv.SetSecurityPolicy(Get<KeyManager>().GetSecurityPolicy());
|
||||
IgnoreError(dataset.SetTlv(tlv));
|
||||
IgnoreError(dataset.WriteTlv(tlv));
|
||||
}
|
||||
|
||||
SuccessOrExit(error = mLocal.Save(dataset));
|
||||
@@ -432,17 +432,14 @@ void PendingDatasetManager::ApplyActiveDataset(const Timestamp &aTimestamp, Coap
|
||||
|
||||
SuccessOrExit(datasetTlv.ReadFromMessage(aMessage, offset));
|
||||
offset += static_cast<uint16_t>(datasetTlv.GetSize());
|
||||
IgnoreError(dataset.SetTlv(datasetTlv));
|
||||
IgnoreError(dataset.WriteTlv(datasetTlv));
|
||||
}
|
||||
|
||||
// add delay timer tlv
|
||||
IgnoreError(dataset.SetTlv(Tlv::kDelayTimer, Get<Leader>().GetDelayTimerMinimal()));
|
||||
IgnoreError(dataset.Write<DelayTimerTlv>(Get<Leader>().GetDelayTimerMinimal()));
|
||||
|
||||
// add pending timestamp tlv
|
||||
dataset.SetTimestamp(Dataset::kPending, aTimestamp);
|
||||
IgnoreError(DatasetManager::Save(dataset));
|
||||
|
||||
// reset delay timer
|
||||
StartDelayTimer();
|
||||
|
||||
exit:
|
||||
|
||||
@@ -123,7 +123,7 @@ void DatasetUpdater::PreparePendingDataset(void)
|
||||
{
|
||||
uint32_t delay = kDefaultDelay;
|
||||
|
||||
SuccessOrExit(error = dataset.SetTlv(Tlv::kDelayTimer, delay));
|
||||
SuccessOrExit(error = dataset.Write<DelayTimerTlv>(delay));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -143,7 +143,7 @@ void DatasetUpdater::PreparePendingDataset(void)
|
||||
}
|
||||
|
||||
{
|
||||
Timestamp timestamp = dataset.GetTlv(Tlv::kActiveTimestamp)->ReadValueAs<ActiveTimestampTlv>();
|
||||
Timestamp timestamp = dataset.FindTlv(Tlv::kActiveTimestamp)->ReadValueAs<ActiveTimestampTlv>();
|
||||
|
||||
timestamp.AdvanceRandomTicks();
|
||||
dataset.SetTimestamp(Dataset::kActive, timestamp);
|
||||
|
||||
@@ -308,7 +308,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
|
||||
|
||||
for (Tlv::Type tlvType : kTlvTypes)
|
||||
{
|
||||
const Tlv *tlv = dataset.GetTlv(tlvType);
|
||||
const Tlv *tlv = dataset.FindTlv(tlvType);
|
||||
|
||||
VerifyOrExit(tlv != nullptr, error = kErrorInvalidState);
|
||||
SuccessOrExit(error = tlv->AppendTo(*message));
|
||||
|
||||
Reference in New Issue
Block a user