From 050682ddc3b33fd7fc654e2f66d889bd204816c8 Mon Sep 17 00:00:00 2001 From: huamenggg <52490135+huamenggg@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:09:55 +0800 Subject: [PATCH] [tmf] add method to read entry from ChildTableTlv (#4147) This commit add a method to read entry from ChildTableTlv. The GetEntry() cannot be used because the current read ChildTableTlv operation doesn't read child table entries. --- src/core/thread/network_diagnostic_tlvs.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index 9c559cfb9..1a5a8a9be 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -1348,6 +1348,26 @@ public: return *reinterpret_cast(GetValue() + (aIndex * sizeof(ChildTableEntry))); } + /** + * This method reads the Child Table entry at @p aIndex. + * + * @param[out] aEntry A reference to a ChildTableEntry. + * @param[in] aMessage A reference to the message. + * @param[in] aOffset The offset of the ChildTableTLV in aMessage. + * @param[in] aIndex The index into the Child Table list. + * + * @retval OT_ERROR_NOT_FOUND No such entry is found. + * @retval OT_ERROR_NONE Successfully read the entry. + */ + otError ReadEntry(ChildTableEntry &aEntry, Message &aMessage, uint16_t aOffset, uint8_t aIndex) const + { + return (aIndex < GetNumEntries() && + aMessage.Read(aOffset + sizeof(ChildTableTlv) + (aIndex * sizeof(ChildTableEntry)), + sizeof(ChildTableEntry), &aEntry) == sizeof(ChildTableEntry)) + ? OT_ERROR_NONE + : OT_ERROR_INVALID_ARGS; + } + } OT_TOOL_PACKED_END; /**