mirror of
https://github.com/espressif/openthread.git
synced 2026-09-16 06:00:13 +00:00
[link-metrics] define StatusSubTlv to simplify appending/parsing it (#8051)
Status sub-TLV has a single `uint8_t` status value so we can use declare it as `UintTlvInfo<SubTlv::kStatus, uint8_t>` and then use helper `Append<StatusSubTlv>` and `Read<StatusSubTlv>` to append and read it.
This commit is contained in:
@@ -270,11 +270,11 @@ Error LinkMetrics::AppendReport(Message &aMessage, const Message &aRequestMessag
|
||||
|
||||
if (seriesInfo == nullptr)
|
||||
{
|
||||
SuccessOrExit(error = AppendStatusSubTlvToMessage(aMessage, kStatusSeriesIdNotRecognized));
|
||||
SuccessOrExit(error = Tlv::Append<StatusSubTlv>(aMessage, kStatusSeriesIdNotRecognized));
|
||||
}
|
||||
else if (seriesInfo->GetPduCount() == 0)
|
||||
{
|
||||
SuccessOrExit(error = AppendStatusSubTlvToMessage(aMessage, kStatusNoMatchingFramesReceived));
|
||||
SuccessOrExit(error = Tlv::Append<StatusSubTlv>(aMessage, kStatusNoMatchingFramesReceived));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -373,27 +373,28 @@ exit:
|
||||
Error LinkMetrics::HandleManagementResponse(const Message &aMessage, const Ip6::Address &aAddress)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Tlv tlv;
|
||||
uint16_t offset;
|
||||
uint16_t endOffset;
|
||||
uint16_t length;
|
||||
uint16_t index = 0;
|
||||
Status status;
|
||||
uint8_t status;
|
||||
bool hasStatus = false;
|
||||
|
||||
VerifyOrExit(mMgmtResponseCallback != nullptr);
|
||||
|
||||
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Mle::Tlv::Type::kLinkMetricsManagement, offset, length));
|
||||
endOffset = offset + length;
|
||||
|
||||
while (index < length)
|
||||
while (offset < endOffset)
|
||||
{
|
||||
SuccessOrExit(aMessage.Read(offset + index, tlv));
|
||||
Tlv tlv;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(offset, tlv));
|
||||
|
||||
switch (tlv.GetType())
|
||||
{
|
||||
case SubTlv::kStatus:
|
||||
case StatusSubTlv::kType:
|
||||
VerifyOrExit(!hasStatus, error = kErrorParse);
|
||||
VerifyOrExit(tlv.GetLength() == sizeof(status), error = kErrorParse);
|
||||
SuccessOrExit(aMessage.Read(offset + index + sizeof(tlv), status));
|
||||
SuccessOrExit(error = Tlv::Read<StatusSubTlv>(aMessage, offset, status));
|
||||
hasStatus = true;
|
||||
break;
|
||||
|
||||
@@ -401,7 +402,7 @@ Error LinkMetrics::HandleManagementResponse(const Message &aMessage, const Ip6::
|
||||
break;
|
||||
}
|
||||
|
||||
index += static_cast<uint16_t>(tlv.GetSize());
|
||||
offset += sizeof(Tlv) + tlv.GetLength();
|
||||
}
|
||||
|
||||
VerifyOrExit(hasStatus, error = kErrorParse);
|
||||
@@ -813,20 +814,6 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error LinkMetrics::AppendStatusSubTlvToMessage(Message &aMessage, Status aStatus)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Tlv statusTlv;
|
||||
|
||||
statusTlv.SetType(SubTlv::kStatus);
|
||||
statusTlv.SetLength(sizeof(uint8_t));
|
||||
SuccessOrExit(error = aMessage.AppendBytes(&statusTlv, sizeof(statusTlv)));
|
||||
SuccessOrExit(error = aMessage.AppendBytes(&aStatus, sizeof(aStatus)));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace LinkMetrics
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -291,7 +291,6 @@ private:
|
||||
uint16_t aEndPos,
|
||||
Metrics & aMetrics);
|
||||
static Error AppendReportSubTlvToMessage(Message &aMessage, const MetricsValues &aValues);
|
||||
static Error AppendStatusSubTlvToMessage(Message &aMessage, Status aStatus);
|
||||
|
||||
ReportCallback mReportCallback;
|
||||
void * mReportCallbackContext;
|
||||
|
||||
@@ -80,6 +80,12 @@ public:
|
||||
*/
|
||||
typedef UintTlvInfo<SubTlv::kQueryId, uint8_t> QueryIdSubTlv;
|
||||
|
||||
/**
|
||||
* This type defines a Link Metrics Status Sub-Tlv.
|
||||
*
|
||||
*/
|
||||
typedef UintTlvInfo<SubTlv::kStatus, uint8_t> StatusSubTlv;
|
||||
|
||||
/**
|
||||
* This class implements Link Metrics Report Sub-TLV generation and parsing.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user