Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[link-metrics] define StatusSubTlv to simplify appending/parsing it #8051

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions src/core/thread/link_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -373,35 +373,36 @@ Error LinkMetrics::HandleManagementRequest(const Message &aMessage, Neighbor &aN
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;

default:
break;
}

index += static_cast<uint16_t>(tlv.GetSize());
offset += sizeof(Tlv) + tlv.GetLength();
}

VerifyOrExit(hasStatus, error = kErrorParse);
Expand Down Expand Up @@ -813,20 +814,6 @@ Error LinkMetrics::AppendReportSubTlvToMessage(Message &aMessage, const MetricsV
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

Expand Down
1 change: 0 additions & 1 deletion src/core/thread/link_metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ class LinkMetrics : public InstanceLocator, private NonCopyable
uint16_t aEndPos,
Metrics & aMetrics);
static Error AppendReportSubTlvToMessage(Message &aMessage, const MetricsValues &aValues);
static Error AppendStatusSubTlvToMessage(Message &aMessage, Status aStatus);

ReportCallback mReportCallback;
void * mReportCallbackContext;
Expand Down
6 changes: 6 additions & 0 deletions src/core/thread/link_metrics_tlvs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class SubTlv
*/
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.
*
Expand Down