mirror of
https://github.com/espressif/openthread.git
synced 2026-07-26 13:59:05 +00:00
[dataset] simplify AppendMleDatasetTlv() (#10043)
- Inlines `AppendMleDatasetTlv()` in `DatasetManager` (removing from `Dataset` class) - Updates the locally read 'dataset' directly by removing the timestamp before appending it to the message as an MLE TLV value. - Leverages `Read()` which already updates the `DelayTimerTlv` with the remaining delay, eliminating the need to re-calculate and update the delay. - Uses `Tlv::AppendTlv()` to append the MLE TLV with `dataset` bytes as value.
This commit is contained in:
@@ -525,6 +525,22 @@ public:
|
||||
return FindStringTlv(aMessage, StringTlvType::kType, StringTlvType::kMaxStringLength, aValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a TLV with a given type and value to a message.
|
||||
*
|
||||
* On success this method grows the message by the size of the TLV.
|
||||
*
|
||||
* @param[in] aMessage The message to append to.
|
||||
* @param[in] aType The TLV type to append.
|
||||
* @param[in] aValue A buffer containing the TLV value.
|
||||
* @param[in] aLength The value length (in bytes).
|
||||
*
|
||||
* @retval kErrorNone Successfully appended the TLV to the message.
|
||||
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
|
||||
*
|
||||
*/
|
||||
static Error AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength);
|
||||
|
||||
/**
|
||||
* Appends a TLV with a given type and value to a message.
|
||||
*
|
||||
@@ -687,7 +703,6 @@ private:
|
||||
};
|
||||
|
||||
static Error FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint16_t aLength);
|
||||
static Error AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength);
|
||||
static Error ReadStringTlv(const Message &aMessage, uint16_t aOffset, uint8_t aMaxStringLength, char *aValue);
|
||||
static Error FindStringTlv(const Message &aMessage, uint8_t aType, uint8_t aMaxStringLength, char *aValue);
|
||||
static Error AppendStringTlv(Message &aMessage, uint8_t aType, uint8_t aMaxStringLength, const char *aValue);
|
||||
|
||||
@@ -450,43 +450,6 @@ exit:
|
||||
|
||||
void Dataset::RemoveTlv(Tlv::Type aType) { RemoveTlv(FindTlv(aType)); }
|
||||
|
||||
Error Dataset::AppendMleDatasetTlv(Type aType, Message &aMessage) const
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Mle::Tlv tlv;
|
||||
Mle::Tlv::Type type;
|
||||
|
||||
VerifyOrExit(mLength > 0);
|
||||
|
||||
type = (aType == kActive ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset);
|
||||
|
||||
tlv.SetType(type);
|
||||
tlv.SetLength(static_cast<uint8_t>(mLength) - sizeof(Tlv) - sizeof(Timestamp));
|
||||
SuccessOrExit(error = aMessage.Append(tlv));
|
||||
|
||||
for (const Tlv *cur = GetTlvsStart(); cur < GetTlvsEnd(); cur = cur->GetNext())
|
||||
{
|
||||
if (((aType == kActive) && (cur->GetType() == Tlv::kActiveTimestamp)) ||
|
||||
((aType == kPending) && (cur->GetType() == Tlv::kPendingTimestamp)))
|
||||
{
|
||||
; // skip Active or Pending Timestamp TLV
|
||||
}
|
||||
else if (cur->GetType() == Tlv::kDelayTimer)
|
||||
{
|
||||
uint32_t remainingDelay = DelayTimerTlv::CalculateRemainingDelay(*cur, mUpdateTime);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<DelayTimerTlv>(aMessage, remainingDelay));
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = cur->AppendTo(aMessage));
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Dataset::RemoveTlv(Tlv *aTlv)
|
||||
{
|
||||
if (aTlv != nullptr)
|
||||
|
||||
@@ -494,18 +494,6 @@ public:
|
||||
*/
|
||||
void SetFrom(const Tlvs &aTlvs);
|
||||
|
||||
/**
|
||||
* Appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
|
||||
*
|
||||
* @param[in] aType The type of the dataset, active or pending.
|
||||
* @param[in] aMessage A message to append to.
|
||||
*
|
||||
* @retval kErrorNone Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
|
||||
* @retval kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV.
|
||||
*
|
||||
*/
|
||||
Error AppendMleDatasetTlv(Type aType, Message &aMessage) const;
|
||||
|
||||
/**
|
||||
* Applies the Active or Pending Dataset to the Thread interface.
|
||||
*
|
||||
|
||||
@@ -64,11 +64,18 @@ RegisterLogModule("DatasetManager");
|
||||
|
||||
Error DatasetManager::AppendMleDatasetTlv(Message &aMessage) const
|
||||
{
|
||||
Dataset dataset;
|
||||
Mle::Tlv::Type mleTlvType = IsActiveDataset() ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset;
|
||||
Dataset dataset;
|
||||
|
||||
IgnoreError(Read(dataset));
|
||||
|
||||
return dataset.AppendMleDatasetTlv(GetType(), aMessage);
|
||||
// Remove the Active or Pending Timestamp TLV from Dataset before
|
||||
// appending to the message. The timestamp is appended as its own
|
||||
// MLE TLV to the message.
|
||||
|
||||
dataset.RemoveTlv(IsActiveDataset() ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp);
|
||||
|
||||
return Tlv::AppendTlv(aMessage, mleTlvType, dataset.GetBytes(), static_cast<uint8_t>(dataset.GetSize()));
|
||||
}
|
||||
|
||||
Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
|
||||
Reference in New Issue
Block a user