From c54238fdd612cce027bc7b095954f0229b031608 Mon Sep 17 00:00:00 2001 From: kangping Date: Tue, 10 Mar 2020 00:19:17 +0800 Subject: [PATCH] [network-diagnostic] fix sed capacity when skipped in Connectivity Tlv (#4654) --- src/core/thread/network_diagnostic_tlvs.hpp | 36 ++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index f91d1bb47..2bdaf2c6c 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -368,11 +368,19 @@ public: */ bool IsValid(void) const { - return ((GetLength() >= sizeof(*this) - sizeof(NetworkDiagnosticTlv)) || - (GetLength() == - sizeof(*this) - sizeof(NetworkDiagnosticTlv) - sizeof(mSedBufferSize) - sizeof(mSedDatagramCount))); + return IsSedBufferingIncluded() || (GetLength() == sizeof(*this) - sizeof(NetworkDiagnosticTlv) - + sizeof(mSedBufferSize) - sizeof(mSedDatagramCount)); } + /** + * This method indicates whether or not the sed buffer size and datagram count are included. + * + * @retval TRUE If the sed buffer size and datagram count are included. + * @retval FALSE If the sed buffer size and datagram count are not included. + * + */ + bool IsSedBufferingIncluded(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); } + /** * This method returns the Parent Priority value. * @@ -494,7 +502,16 @@ public: * @returns The SED Buffer Size value. * */ - uint16_t GetSedBufferSize(void) const { return HostSwap16(mSedBufferSize); } + uint16_t GetSedBufferSize(void) const + { + uint16_t buffersize = OPENTHREAD_CONFIG_DEFAULT_SED_BUFFER_SIZE; + + if (IsSedBufferingIncluded()) + { + buffersize = HostSwap16(mSedBufferSize); + } + return buffersize; + } /** * This method sets the SED Buffer Size value. @@ -510,7 +527,16 @@ public: * @returns The SED Datagram Count value. * */ - uint8_t GetSedDatagramCount(void) const { return mSedDatagramCount; } + uint8_t GetSedDatagramCount(void) const + { + uint8_t count = OPENTHREAD_CONFIG_DEFAULT_SED_DATAGRAM_COUNT; + + if (IsSedBufferingIncluded()) + { + count = mSedDatagramCount; + } + return count; + } /** * This method sets the SED Datagram Count value.