[mle] add Mle::RxMessage::ReadAndSave{Active/Pending}Dataset() (#10348)

This commit adds `ReadAndSave{Active/Pending}Dataset()` helper methods
to `Mle::RxMessage` to read the Active or Pending Dataset from a
received MLE message and save it in the corresponding
`DatasetManager`.

This commit also refactors the code for parsing the MLE TLVs, moving
it from `DatasetManager` to the `Mle` class for better alignment of
responsibilities.
This commit is contained in:
Abtin Keshavarzian
2024-06-07 14:04:32 -07:00
committed by GitHub
parent 22ee728ac7
commit dd1e5f426d
4 changed files with 53 additions and 54 deletions
-16
View File
@@ -267,22 +267,6 @@ void DatasetManager::Clear(void)
SignalDatasetChange();
}
Error DatasetManager::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint16_t aLength)
{
Error error = kErrorNone;
Dataset dataset;
SuccessOrExit(error = dataset.SetFrom(aMessage, aOffset, aLength));
SuccessOrExit(error = dataset.ValidateTlvs());
SuccessOrExit(error = dataset.WriteTimestamp(mType, aTimestamp));
error = Save(dataset);
exit:
return error;
}
Error DatasetManager::Save(const Dataset &aDataset, bool aAllowOlderTimestamp)
{
Error error = kErrorNone;
-17
View File
@@ -162,23 +162,6 @@ public:
*/
Error Save(const Dataset &aDataset) { return Save(aDataset, /* aAllowOlderTimestamp */ false); }
/**
* Sets the Operational Dataset for the partition read from a given message.
*
* Also updates the non-volatile local version if the partition's Operational Dataset is newer. If Active
* Operational Dataset is changed, applies the configuration to to Thread interface.
*
* @param[in] aTimestamp The timestamp for the Operational Dataset.
* @param[in] aMessage The message to read from.
* @param[in] aOffset The offset where the Operational Dataset begins.
* @param[in] aLength The length of the Operational Dataset.
*
* @retval kErrorNone Successfully parsed the Dataset from the @p aMessage and saved it.
* @retval kErrorParse Could not parse the Dataset from @p aMessage.
*
*/
Error Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint16_t aLength);
/**
* Retrieves the channel mask from local dataset.
*
+49 -20
View File
@@ -2999,19 +2999,16 @@ Error Mle::HandleLeaderData(RxInfo &aRxInfo)
{
// We previously confirmed the message contains an
// Active or a Pending Dataset TLV before setting the
// corresponding `saveDataset` flag, so we can safely
// `IgnoreError()` on `FindTlvValueOffset()`.
// corresponding `saveDataset` flag.
if (saveActiveDataset)
{
IgnoreError(Tlv::FindTlvValueOffset(aRxInfo.mMessage, Tlv::kActiveDataset, offset, length));
IgnoreError(Get<MeshCoP::ActiveDatasetManager>().Save(activeTimestamp, aRxInfo.mMessage, offset, length));
IgnoreError(aRxInfo.mMessage.ReadAndSaveActiveDataset(activeTimestamp));
}
if (savePendingDataset)
{
IgnoreError(Tlv::FindTlvValueOffset(aRxInfo.mMessage, Tlv::kPendingDataset, offset, length));
IgnoreError(Get<MeshCoP::PendingDatasetManager>().Save(pendingTimestamp, aRxInfo.mMessage, offset, length));
IgnoreError(aRxInfo.mMessage.ReadAndSavePendingDataset(pendingTimestamp));
}
}
@@ -3313,8 +3310,6 @@ void Mle::HandleChildIdResponse(RxInfo &aRxInfo)
MeshCoP::Timestamp timestamp;
uint16_t networkDataOffset;
uint16_t networkDataLength;
uint16_t offset;
uint16_t length;
SuccessOrExit(error = Tlv::Find<SourceAddressTlv>(aRxInfo.mMessage, sourceAddress));
@@ -3335,11 +3330,9 @@ void Mle::HandleChildIdResponse(RxInfo &aRxInfo)
switch (Tlv::Find<ActiveTimestampTlv>(aRxInfo.mMessage, timestamp))
{
case kErrorNone:
if (Tlv::FindTlvValueOffset(aRxInfo.mMessage, Tlv::kActiveDataset, offset, length) == kErrorNone)
{
SuccessOrExit(error =
Get<MeshCoP::ActiveDatasetManager>().Save(timestamp, aRxInfo.mMessage, offset, length));
}
error = aRxInfo.mMessage.ReadAndSaveActiveDataset(timestamp);
error = (error == kErrorNotFound) ? kErrorNone : error;
SuccessOrExit(error);
break;
case kErrorNotFound:
@@ -3358,10 +3351,7 @@ void Mle::HandleChildIdResponse(RxInfo &aRxInfo)
switch (Tlv::Find<PendingTimestampTlv>(aRxInfo.mMessage, timestamp))
{
case kErrorNone:
if (Tlv::FindTlvValueOffset(aRxInfo.mMessage, Tlv::kPendingDataset, offset, length) == kErrorNone)
{
IgnoreError(Get<MeshCoP::PendingDatasetManager>().Save(timestamp, aRxInfo.mMessage, offset, length));
}
IgnoreError(aRxInfo.mMessage.ReadAndSavePendingDataset(timestamp));
break;
case kErrorNotFound:
@@ -4907,13 +4897,13 @@ Error Mle::TxMessage::AppendActiveDatasetTlv(void) { return AppendDatasetTlv(Mes
Error Mle::TxMessage::AppendPendingDatasetTlv(void) { return AppendDatasetTlv(MeshCoP::Dataset::kPending); }
Error Mle::TxMessage::AppendDatasetTlv(MeshCoP::Dataset::Type mDatasetType)
Error Mle::TxMessage::AppendDatasetTlv(MeshCoP::Dataset::Type aDatasetType)
{
Error error = kErrorNotFound;
Tlv::Type tlvType;
MeshCoP::Dataset dataset;
switch (mDatasetType)
switch (aDatasetType)
{
case MeshCoP::Dataset::kActive:
error = Get<MeshCoP::ActiveDatasetManager>().Read(dataset);
@@ -4938,7 +4928,7 @@ Error Mle::TxMessage::AppendDatasetTlv(MeshCoP::Dataset::Type mDatasetType)
// message. The Timestamp is appended as its own MLE TLV to the
// message.
dataset.RemoveTimestamp(mDatasetType);
dataset.RemoveTimestamp(aDatasetType);
error = Tlv::AppendTlv(*this, tlvType, dataset.GetBytes(), dataset.GetLength());
@@ -5074,6 +5064,45 @@ exit:
return error;
}
Error Mle::RxMessage::ReadAndSaveActiveDataset(const MeshCoP::Timestamp &aActiveTimestamp) const
{
return ReadAndSaveDataset(MeshCoP::Dataset::kActive, aActiveTimestamp);
}
Error Mle::RxMessage::ReadAndSavePendingDataset(const MeshCoP::Timestamp &aPendingTimestamp) const
{
return ReadAndSaveDataset(MeshCoP::Dataset::kPending, aPendingTimestamp);
}
Error Mle::RxMessage::ReadAndSaveDataset(MeshCoP::Dataset::Type aDatasetType,
const MeshCoP::Timestamp &aTimestamp) const
{
Error error = kErrorNone;
Tlv::Type tlvType = (aDatasetType == MeshCoP::Dataset::kActive) ? Tlv::kActiveDataset : Tlv::kPendingDataset;
MeshCoP::Dataset dataset;
uint16_t offset;
uint16_t length;
SuccessOrExit(error = Tlv::FindTlvValueOffset(*this, tlvType, offset, length));
SuccessOrExit(error = dataset.SetFrom(*this, offset, length));
SuccessOrExit(error = dataset.ValidateTlvs());
SuccessOrExit(error = dataset.WriteTimestamp(aDatasetType, aTimestamp));
switch (aDatasetType)
{
case MeshCoP::Dataset::kActive:
error = Get<MeshCoP::ActiveDatasetManager>().Save(dataset);
break;
case MeshCoP::Dataset::kPending:
error = Get<MeshCoP::PendingDatasetManager>().Save(dataset);
break;
}
exit:
return error;
}
Error Mle::RxMessage::ReadTlvRequestTlv(TlvList &aTlvList) const
{
Error error;
+4 -1
View File
@@ -1055,7 +1055,7 @@ private:
private:
Error AppendCompressedAddressEntry(uint8_t aContextId, const Ip6::Address &aAddress);
Error AppendAddressEntry(const Ip6::Address &aAddress);
Error AppendDatasetTlv(MeshCoP::Dataset::Type mDatasetType);
Error AppendDatasetTlv(MeshCoP::Dataset::Type aDatasetType);
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -1072,6 +1072,8 @@ private:
Error ReadFrameCounterTlvs(uint32_t &aLinkFrameCounter, uint32_t &aMleFrameCounter) const;
Error ReadTlvRequestTlv(TlvList &aTlvList) const;
Error ReadLeaderDataTlv(LeaderData &aLeaderData) const;
Error ReadAndSaveActiveDataset(const MeshCoP::Timestamp &aActiveTimestamp) const;
Error ReadAndSavePendingDataset(const MeshCoP::Timestamp &aPendingTimestamp) const;
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
Error ReadCslClockAccuracyTlv(Mac::CslAccuracy &aCslAccuracy) const;
#endif
@@ -1081,6 +1083,7 @@ private:
private:
Error ReadChallengeOrResponse(uint8_t aTlvType, RxChallenge &aRxChallenge) const;
Error ReadAndSaveDataset(MeshCoP::Dataset::Type aDatasetType, const MeshCoP::Timestamp &aTimestamp) const;
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -