From 8b1d0a9d5acb3a50a89eb9e2a8bb33425faae58a Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 25 Jan 2023 21:32:31 -0800 Subject: [PATCH] [net-diags] include link quality in child table entry (#8398) This commit updates the `ChildTableEntry` which is included in Network Diagnostic "Child Table TLV" to also provide the Link Quality In info for the child (using the unused two-bit field in the existing entry format). --- include/openthread/instance.h | 2 +- include/openthread/netdiag.h | 8 ++++++ src/cli/cli.cpp | 1 + src/core/thread/network_diagnostic.cpp | 6 +++-- src/core/thread/network_diagnostic_tlvs.hpp | 27 ++++++++++++++++++++- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 39062bb52..f96eed552 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (279) +#define OPENTHREAD_API_VERSION (280) /** * @addtogroup api-instance diff --git a/include/openthread/netdiag.h b/include/openthread/netdiag.h index 40cd074ea..eb3e7b697 100644 --- a/include/openthread/netdiag.h +++ b/include/openthread/netdiag.h @@ -202,6 +202,14 @@ typedef struct otNetworkDiagChildEntry */ uint16_t mTimeout : 5; + /** + * Link Quality In value in [0,3]. + * + * Value 0 indicates that sender does not support the feature to provide link quality info. + * + */ + uint8_t mLinkQuality : 2; + /** * Child ID from which an RLOC can be generated. */ diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 1623e6b46..4d0c43fa8 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -7202,6 +7202,7 @@ void Interpreter::OutputChildTableEntry(uint8_t aIndentSize, const otNetworkDiag OutputLine("ChildId: 0x%04x", aChildEntry.mChildId); OutputLine(aIndentSize, "Timeout: %u", aChildEntry.mTimeout); + OutputLine(aIndentSize, "Link Quality: %u", aChildEntry.mLinkQuality); OutputLine(aIndentSize, "Mode:"); OutputMode(aIndentSize + kIndentSize, aChildEntry.mMode); } diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 7f8837fb8..04399bdcc 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -256,6 +256,7 @@ Error NetworkDiagnostic::AppendChildTable(Message &aMessage) entry.Clear(); entry.SetTimeout(timeout + 4); + entry.SetLinkQuality(child.GetLinkQualityIn()); entry.SetChildId(Mle::ChildIdFromRloc16(child.GetRloc16())); entry.SetMode(child.GetDeviceMode()); @@ -780,8 +781,9 @@ Error NetworkDiagnostic::GetNextDiagTlv(const Coap::Message &aMessage, Iterator SuccessOrExit(error = aMessage.Read(valueOffset, entry)); - childInfo->mTimeout = entry.GetTimeout(); - childInfo->mChildId = entry.GetChildId(); + childInfo->mTimeout = entry.GetTimeout(); + childInfo->mLinkQuality = entry.GetLinkQuality(); + childInfo->mChildId = entry.GetChildId(); entry.GetMode().Get(childInfo->mMode); childCount++; diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index ed8abe948..1c24f52a8 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -45,6 +45,7 @@ #include "common/tlvs.hpp" #include "net/ip6_address.hpp" #include "radio/radio.hpp" +#include "thread/link_quality.hpp" #include "thread/mle_tlvs.hpp" #include "thread/mle_types.hpp" @@ -467,6 +468,28 @@ public: SetTimeoutChildId((GetTimeoutChildId() & ~kTimeoutMask) | ((aTimeout << kTimeoutOffset) & kTimeoutMask)); } + /** + * This method the Link Quality value. + * + * @returns The Link Quality value. + * + */ + LinkQuality GetLinkQuality(void) const + { + return static_cast((GetTimeoutChildId() & kLqiMask) >> kLqiOffset); + } + + /** + * This method set the Link Quality value. + * + * @param[in] aLinkQuality The Link Quality value. + * + */ + void SetLinkQuality(LinkQuality aLinkQuality) + { + SetTimeoutChildId((GetTimeoutChildId() & ~kLqiMask) | ((aLinkQuality << kLqiOffset) & kLqiMask)); + } + /** * This method returns the Child ID value. * @@ -506,12 +529,14 @@ private: // 1 0 // 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Timeout |RSV| Child ID | + // | Timeout |LQI| Child ID | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ static constexpr uint8_t kTimeoutOffset = 11; + static constexpr uint8_t kLqiOffset = 9; static constexpr uint8_t kChildIdOffset = 0; static constexpr uint16_t kTimeoutMask = 0x1f << kTimeoutOffset; + static constexpr uint16_t kLqiMask = 0x3 << kLqiOffset; static constexpr uint16_t kChildIdMask = 0x1ff << kChildIdOffset; uint16_t GetTimeoutChildId(void) const { return HostSwap16(mTimeoutChildId); }