diff --git a/examples/platforms/posix/radio.c b/examples/platforms/posix/radio.c index 42e157f78..31e20a3ac 100644 --- a/examples/platforms/posix/radio.c +++ b/examples/platforms/posix/radio.c @@ -139,8 +139,8 @@ static bool sPromiscuous = false; static bool sTxWait = false; static int8_t sTxPower = 0; -static uint8_t sShortAddressMatchTableCount = 0; -static uint8_t sExtAddressMatchTableCount = 0; +static uint16_t sShortAddressMatchTableCount = 0; +static uint16_t sExtAddressMatchTableCount = 0; static uint16_t sShortAddressMatchTable[POSIX_MAX_SRC_MATCH_ENTRIES]; static otExtAddress sExtAddressMatchTable[POSIX_MAX_SRC_MATCH_ENTRIES]; static bool sSrcMatchEnabled = false; diff --git a/include/openthread/thread_ftd.h b/include/openthread/thread_ftd.h index 3a0d44bcc..5cdf4a02c 100644 --- a/include/openthread/thread_ftd.h +++ b/include/openthread/thread_ftd.h @@ -103,7 +103,7 @@ typedef struct otEidCacheEntry * @sa otThreadSetMaxAllowedChildren * */ -uint8_t otThreadGetMaxAllowedChildren(otInstance *aInstance); +uint16_t otThreadGetMaxAllowedChildren(otInstance *aInstance); /** * Set the maximum number of children currently allowed. @@ -120,7 +120,7 @@ uint8_t otThreadGetMaxAllowedChildren(otInstance *aInstance); * @sa otThreadGetMaxAllowedChildren * */ -otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren); +otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint16_t aMaxChildren); /** * This function indicates whether or not the Router Role is enabled. @@ -449,7 +449,7 @@ otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChi * @sa otGetMaxAllowedChildren * */ -otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo); +otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint16_t aChildIndex, otChildInfo *aChildInfo); /** * This function gets the next IPv6 address (using an iterator) for a given child. @@ -469,7 +469,7 @@ otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, * */ otError otThreadGetChildNextIp6Address(otInstance * aInstance, - uint8_t aChildIndex, + uint16_t aChildIndex, otChildIp6AddressIterator *aIterator, otIp6Address * aAddress); diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 6061209ec..7f71aefed 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -590,7 +590,7 @@ void Interpreter::ProcessChild(int argc, char *argv[]) if (isTable || strcmp(argv[0], "list") == 0) { - uint8_t maxChildren; + uint16_t maxChildren; if (isTable) { @@ -602,7 +602,7 @@ void Interpreter::ProcessChild(int argc, char *argv[]) maxChildren = otThreadGetMaxAllowedChildren(mInstance); - for (uint8_t i = 0; i < maxChildren; i++) + for (uint16_t i = 0; i < maxChildren; i++) { if ((otThreadGetChildInfoByIndex(mInstance, i, &childInfo) != OT_ERROR_NONE) || childInfo.mIsStateRestoring) { @@ -689,14 +689,14 @@ exit: void Interpreter::ProcessChildIp(int argc, char *argv[]) { - otError error = OT_ERROR_NONE; - uint8_t maxChildren; + otError error = OT_ERROR_NONE; + uint16_t maxChildren; VerifyOrExit(argc == 0, error = OT_ERROR_INVALID_ARGS); maxChildren = otThreadGetMaxAllowedChildren(mInstance); - for (uint8_t childIndex = 0; childIndex < maxChildren; childIndex++) + for (uint16_t childIndex = 0; childIndex < maxChildren; childIndex++) { otChildIp6AddressIterator iterator = OT_CHILD_IP6_ADDRESS_ITERATOR_INIT; otIp6Address ip6Address; @@ -735,7 +735,7 @@ void Interpreter::ProcessChildMax(int argc, char *argv[]) else { SuccessOrExit(error = ParseLong(argv[0], value)); - SuccessOrExit(error = otThreadSetMaxAllowedChildren(mInstance, static_cast(value))); + SuccessOrExit(error = otThreadSetMaxAllowedChildren(mInstance, static_cast(value))); } exit: diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index ea6cc4002..130e64ddb 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -44,14 +44,14 @@ using namespace ot; -uint8_t otThreadGetMaxAllowedChildren(otInstance *aInstance) +uint16_t otThreadGetMaxAllowedChildren(otInstance *aInstance) { Instance &instance = *static_cast(aInstance); return instance.Get().GetMaxChildrenAllowed(); } -otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren) +otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint16_t aMaxChildren) { Instance &instance = *static_cast(aInstance); @@ -250,7 +250,7 @@ exit: return error; } -otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo) +otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint16_t aChildIndex, otChildInfo *aChildInfo) { otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); @@ -264,7 +264,7 @@ exit: } otError otThreadGetChildNextIp6Address(otInstance * aInstance, - uint8_t aChildIndex, + uint16_t aChildIndex, otChildIp6AddressIterator *aIterator, otIp6Address * aAddress) { diff --git a/src/core/common/message.cpp b/src/core/common/message.cpp index af1123400..7ebfef6f8 100644 --- a/src/core/common/message.cpp +++ b/src/core/common/message.cpp @@ -665,19 +665,19 @@ exit: return messageCopy; } -bool Message::GetChildMask(uint8_t aChildIndex) const +bool Message::GetChildMask(uint16_t aChildIndex) const { assert(aChildIndex < sizeof(mBuffer.mHead.mInfo.mChildMask) * 8); return (mBuffer.mHead.mInfo.mChildMask[aChildIndex / 8] & (0x80 >> (aChildIndex % 8))) != 0; } -void Message::ClearChildMask(uint8_t aChildIndex) +void Message::ClearChildMask(uint16_t aChildIndex) { assert(aChildIndex < sizeof(mBuffer.mHead.mInfo.mChildMask) * 8); mBuffer.mHead.mInfo.mChildMask[aChildIndex / 8] &= ~(0x80 >> (aChildIndex % 8)); } -void Message::SetChildMask(uint8_t aChildIndex) +void Message::SetChildMask(uint16_t aChildIndex) { assert(aChildIndex < sizeof(mBuffer.mHead.mInfo.mChildMask) * 8); mBuffer.mHead.mInfo.mChildMask[aChildIndex / 8] |= 0x80 >> (aChildIndex % 8); diff --git a/src/core/common/message.hpp b/src/core/common/message.hpp index 613b8475d..c7752eb41 100644 --- a/src/core/common/message.hpp +++ b/src/core/common/message.hpp @@ -63,8 +63,9 @@ namespace ot { enum { - kNumBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS, - kBufferSize = OPENTHREAD_CONFIG_MESSAGE_BUFFER_SIZE, + kNumBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS, + kBufferSize = OPENTHREAD_CONFIG_MESSAGE_BUFFER_SIZE, + kChildMaskBytes = BitVectorBytes(OPENTHREAD_CONFIG_MLE_MAX_CHILDREN), }; class Message; @@ -93,8 +94,8 @@ struct MessageInfo uint16_t mDatagramTag; ///< The datagram tag used for 6LoWPAN fragmentation. RssAverager mRssAverager; ///< The averager maintaining the received signal strength (RSS) average. - uint8_t mChildMask[8]; ///< A bit-vector to indicate which sleepy children need to receive this. - uint8_t mTimeout; ///< Seconds remaining before dropping the message. + uint8_t mChildMask[kChildMaskBytes]; ///< A bit-vector to indicate which sleepy children need to receive this. + uint8_t mTimeout; ///< Seconds remaining before dropping the message. union { uint16_t mPanId; ///< Used for MLE Discover Request and Response messages. @@ -500,7 +501,7 @@ public: * @retval FALSE If the message is not scheduled to be forwarded to the child. * */ - bool GetChildMask(uint8_t aChildIndex) const; + bool GetChildMask(uint16_t aChildIndex) const; /** * This method unschedules forwarding of the message to the child. @@ -508,7 +509,7 @@ public: * @param[in] aChildIndex The index into the child table. * */ - void ClearChildMask(uint8_t aChildIndex); + void ClearChildMask(uint16_t aChildIndex); /** * This method schedules forwarding of the message to the child. @@ -516,7 +517,7 @@ public: * @param[in] aChildIndex The index into the child table. * */ - void SetChildMask(uint8_t aChildIndex); + void SetChildMask(uint16_t aChildIndex); /** * This method returns whether or not the message forwarding is scheduled for at least one child. diff --git a/src/core/thread/child_table.cpp b/src/core/thread/child_table.cpp index 49ee72b14..5f4639ba7 100644 --- a/src/core/thread/child_table.cpp +++ b/src/core/thread/child_table.cpp @@ -105,7 +105,7 @@ ChildTable::ChildTable(Instance &aInstance) memset(mChildren, 0, sizeof(mChildren)); } -Child *ChildTable::GetChildAtIndex(uint8_t aChildIndex) +Child *ChildTable::GetChildAtIndex(uint16_t aChildIndex) { Child *child = NULL; @@ -209,9 +209,9 @@ exit: return rval; } -uint8_t ChildTable::GetNumChildren(StateFilter aFilter) const +uint16_t ChildTable::GetNumChildren(StateFilter aFilter) const { - uint8_t numChildren = 0; + uint16_t numChildren = 0; const Child *child = mChildren; for (uint16_t num = mMaxChildrenAllowed; num != 0; num--, child++) @@ -225,7 +225,7 @@ uint8_t ChildTable::GetNumChildren(StateFilter aFilter) const return numChildren; } -otError ChildTable::SetMaxChildrenAllowed(uint8_t aMaxChildren) +otError ChildTable::SetMaxChildrenAllowed(uint16_t aMaxChildren) { otError error = OT_ERROR_NONE; diff --git a/src/core/thread/child_table.hpp b/src/core/thread/child_table.hpp index 0f0588846..eaf2714fc 100644 --- a/src/core/thread/child_table.hpp +++ b/src/core/thread/child_table.hpp @@ -180,7 +180,7 @@ public: * @returns The index corresponding to @p aChild. * */ - uint8_t GetChildIndex(const Child &aChild) const { return static_cast(&aChild - mChildren); } + uint16_t GetChildIndex(const Child &aChild) const { return static_cast(&aChild - mChildren); } /** * This method returns a pointer to a `Child` entry at a given index, or `NULL` if the index is out of bounds, @@ -191,7 +191,7 @@ public: * @returns A pointer to the `Child` corresponding to the given index, or `NULL` if the index is out of bounds. * */ - Child *GetChildAtIndex(uint8_t aChildIndex); + Child *GetChildAtIndex(uint16_t aChildIndex); /** * This method gets a new/unused `Child` entry from the child table. @@ -255,7 +255,7 @@ public: * @returns Number of children matching the given state filer. * */ - uint8_t GetNumChildren(StateFilter aFilter) const; + uint16_t GetNumChildren(StateFilter aFilter) const; /** * This method returns the maximum number of children that can be supported (build-time constant). @@ -266,7 +266,7 @@ public: * @returns The maximum number of children supported * */ - uint8_t GetMaxChildren(void) const { return kMaxChildren; } + uint16_t GetMaxChildren(void) const { return kMaxChildren; } /** * This method get the maximum number of children allowed. @@ -274,7 +274,7 @@ public: * @returns The maximum number of children allowed. * */ - uint8_t GetMaxChildrenAllowed(void) const { return mMaxChildrenAllowed; } + uint16_t GetMaxChildrenAllowed(void) const { return mMaxChildrenAllowed; } /** * This method sets the maximum number of children allowed. @@ -289,7 +289,7 @@ public: * @retval OT_ERROR_INVALID_STATE The child table is not empty. * */ - otError SetMaxChildrenAllowed(uint8_t aMaxChildren); + otError SetMaxChildrenAllowed(uint16_t aMaxChildren); private: enum @@ -299,8 +299,8 @@ private: static bool MatchesFilter(const Child &aChild, StateFilter aFilter); - uint8_t mMaxChildrenAllowed; - Child mChildren[kMaxChildren]; + uint16_t mMaxChildrenAllowed; + Child mChildren[kMaxChildren]; }; #endif // OPENTHREAD_FTD @@ -338,8 +338,8 @@ public: } void Clear(void) {} - uint8_t GetChildIndex(const Child &) const { return 0; } - Child * GetChildAtIndex(uint8_t) { return NULL; } + uint16_t GetChildIndex(const Child &) const { return 0; } + Child * GetChildAtIndex(uint16_t) { return NULL; } Child *GetNewChild(void) { return NULL; } @@ -347,11 +347,11 @@ public: Child *FindChild(const Mac::ExtAddress &, StateFilter) { return NULL; } Child *FindChild(const Mac::Address &, StateFilter) { return NULL; } - bool HasChildren(StateFilter) const { return false; } - uint8_t GetNumChildren(StateFilter) const { return 0; } - uint8_t GetMaxChildren(void) const { return 0; } - uint8_t GetMaxChildrenAllowed(void) const { return 0; } - otError SetMaxChildrenAllowed(uint8_t) { return OT_ERROR_INVALID_STATE; } + bool HasChildren(StateFilter) const { return false; } + uint16_t GetNumChildren(StateFilter) const { return 0; } + uint16_t GetMaxChildren(void) const { return 0; } + uint16_t GetMaxChildrenAllowed(void) const { return 0; } + otError SetMaxChildrenAllowed(uint16_t) { return OT_ERROR_INVALID_STATE; } }; #endif // OPENTHREAD_MTD diff --git a/src/core/thread/indirect_sender.cpp b/src/core/thread/indirect_sender.cpp index a6228fde3..5cdcd76ff 100644 --- a/src/core/thread/indirect_sender.cpp +++ b/src/core/thread/indirect_sender.cpp @@ -86,8 +86,8 @@ exit: otError IndirectSender::AddMessageForSleepyChild(Message &aMessage, Child &aChild) { - otError error = OT_ERROR_NONE; - uint8_t childIndex; + otError error = OT_ERROR_NONE; + uint16_t childIndex; VerifyOrExit(!aChild.IsRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE); @@ -105,8 +105,8 @@ exit: otError IndirectSender::RemoveMessageFromSleepyChild(Message &aMessage, Child &aChild) { - otError error = OT_ERROR_NONE; - uint8_t childIndex = Get().GetChildIndex(aChild); + otError error = OT_ERROR_NONE; + uint16_t childIndex = Get().GetChildIndex(aChild); VerifyOrExit(aMessage.GetChildMask(childIndex), error = OT_ERROR_NOT_FOUND); @@ -175,7 +175,7 @@ void IndirectSender::HandleChildModeChange(Child &aChild, Mle::DeviceMode aOldMo if (!aOldMode.IsRxOnWhenIdle() && aChild.IsRxOnWhenIdle() && (aChild.GetIndirectMessageCount() > 0)) { - uint8_t childIndex = Get().GetChildIndex(aChild); + uint16_t childIndex = Get().GetChildIndex(aChild); for (Message *message = Get().mSendQueue.GetHead(); message; message = message->GetNext()) { @@ -204,7 +204,7 @@ Message *IndirectSender::FindIndirectMessage(Child &aChild) { Message *message; Message *next; - uint8_t childIndex = Get().GetChildIndex(aChild); + uint16_t childIndex = Get().GetChildIndex(aChild); for (message = Get().mSendQueue.GetHead(); message; message = next) { @@ -482,7 +482,7 @@ void IndirectSender::HandleSentFrameToChild(const Mac::TxFrame &aFrame, // The indirect tx of this message to the child is done. otError txError = aError; - uint8_t childIndex = Get().GetChildIndex(aChild); + uint16_t childIndex = Get().GetChildIndex(aChild); Mac::Address macDest; aChild.SetIndirectMessage(NULL); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 8a76169c9..b90c664f5 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -2903,7 +2903,7 @@ otError MleRouter::SendChildUpdateRequest(Child &aChild) if (!aChild.IsRxOnWhenIdle()) { - uint8_t childIndex = Get().GetChildIndex(aChild); + uint16_t childIndex = Get().GetChildIndex(aChild); for (message = Get().GetSendQueue().GetHead(); message; message = message->GetNext()) { @@ -3466,7 +3466,7 @@ exit: return error; } -otError MleRouter::GetChildInfoByIndex(uint8_t aChildIndex, otChildInfo &aChildInfo) +otError MleRouter::GetChildInfoByIndex(uint16_t aChildIndex, otChildInfo &aChildInfo) { otError error = OT_ERROR_NONE; Child * child = NULL; @@ -3480,7 +3480,7 @@ exit: return error; } -otError MleRouter::GetChildNextIp6Address(uint8_t aChildIndex, +otError MleRouter::GetChildNextIp6Address(uint16_t aChildIndex, Child::Ip6AddressIterator &aIterator, Ip6::Address & aAddress) { @@ -3499,9 +3499,9 @@ exit: void MleRouter::RestoreChildren(void) { - otError error = OT_ERROR_NONE; - bool foundDuplicate = false; - uint8_t numChildren = 0; + otError error = OT_ERROR_NONE; + bool foundDuplicate = false; + uint16_t numChildren = 0; for (Settings::ChildInfoIterator iter(GetInstance()); !iter.IsDone(); iter++) { @@ -3660,7 +3660,7 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig { for (index = aIterator;; index++) { - Child *child = mChildTable.GetChildAtIndex(static_cast(index)); + Child *child = mChildTable.GetChildAtIndex(static_cast(index)); if (child == NULL) { @@ -4181,8 +4181,8 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv) } else { - uint8_t numChildren = mChildTable.GetNumChildren(ChildTable::kInStateValid); - uint8_t maxAllowed = mChildTable.GetMaxChildrenAllowed(); + uint16_t numChildren = mChildTable.GetNumChildren(ChildTable::kInStateValid); + uint16_t maxAllowed = mChildTable.GetMaxChildrenAllowed(); if ((maxAllowed - numChildren) < (maxAllowed / 3)) { @@ -4562,8 +4562,8 @@ void MleRouter::RemoveChildren(void) bool MleRouter::HasSmallNumberOfChildren(void) { - uint8_t numChildren = 0; - uint8_t routerCount = mRouterTable.GetActiveRouterCount(); + uint16_t numChildren = 0; + uint8_t routerCount = mRouterTable.GetActiveRouterCount(); VerifyOrExit(routerCount > mRouterDowngradeThreshold); diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index 0e7a52cbb..556e92944 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -419,7 +419,7 @@ public: * @param[out] aChildInfo The child information. * */ - otError GetChildInfoByIndex(uint8_t aChildIndex, otChildInfo &aChildInfo); + otError GetChildInfoByIndex(uint16_t aChildIndex, otChildInfo &aChildInfo); /** * This methods gets the next IPv6 address (using an iterator) for a given child. @@ -434,7 +434,7 @@ public: * @retval OT_ERROR_INVALID_ARGS Child at @p aChildIndex is not valid. * */ - otError GetChildNextIp6Address(uint8_t aChildIndex, Child::Ip6AddressIterator &aIterator, Ip6::Address &aAddress); + otError GetChildNextIp6Address(uint16_t aChildIndex, Child::Ip6AddressIterator &aIterator, Ip6::Address &aAddress); /** * This method indicates whether or not the RLOC16 is an MTD child of this device. diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 94d297091..6dc5114f4 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -224,7 +224,7 @@ exit: otError NetworkDiagnostic::AppendChildTable(Message &aMessage) { otError error = OT_ERROR_NONE; - uint8_t count = 0; + uint16_t count = 0; uint8_t timeout = 0; ChildTableTlv tlv; ChildTableEntry entry; @@ -232,7 +232,13 @@ otError NetworkDiagnostic::AppendChildTable(Message &aMessage) tlv.Init(); count = Get().GetNumChildren(ChildTable::kInStateValid); - tlv.SetLength(count * sizeof(ChildTableEntry)); + + if (count > (CHAR_BIT * sizeof(uint8_t) / sizeof(ChildTableEntry))) + { + count = CHAR_BIT * sizeof(uint8_t) / sizeof(ChildTableEntry); + } + + tlv.SetLength(static_cast(count * sizeof(ChildTableEntry))); SuccessOrExit(error = aMessage.Append(&tlv, sizeof(ChildTableTlv))); diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index c0ac7beb1..9c559cfb9 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -1343,7 +1343,7 @@ public: * * @returns A reference to the Child Table entry. */ - ChildTableEntry &GetEntry(uint8_t aIndex) + ChildTableEntry &GetEntry(uint16_t aIndex) { return *reinterpret_cast(GetValue() + (aIndex * sizeof(ChildTableEntry))); } diff --git a/src/core/utils/child_supervision.cpp b/src/core/utils/child_supervision.cpp index 8a7f40f53..e25e7f903 100644 --- a/src/core/utils/child_supervision.cpp +++ b/src/core/utils/child_supervision.cpp @@ -63,8 +63,8 @@ void ChildSupervisor::SetSupervisionInterval(uint16_t aInterval) Child *ChildSupervisor::GetDestination(const Message &aMessage) const { - Child * child = NULL; - uint8_t childIndex; + Child * child = NULL; + uint16_t childIndex; VerifyOrExit(aMessage.GetType() == Message::kTypeSupervision); @@ -78,7 +78,7 @@ exit: void ChildSupervisor::SendMessage(Child &aChild) { Message *message = NULL; - uint8_t childIndex; + uint16_t childIndex; VerifyOrExit(aChild.GetIndirectMessageCount() == 0); diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index 6f08d9ae3..152f763ed 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -201,11 +201,11 @@ template <> otError NcpBase::HandlePropertyGet(v { otError error = OT_ERROR_NONE; otChildInfo childInfo; - uint8_t maxChildren; + uint16_t maxChildren; maxChildren = otThreadGetMaxAllowedChildren(mInstance); - for (uint8_t index = 0; index < maxChildren; index++) + for (uint16_t index = 0; index < maxChildren; index++) { if ((otThreadGetChildInfoByIndex(mInstance, index, &childInfo) != OT_ERROR_NONE) || childInfo.mIsStateRestoring) { @@ -259,13 +259,13 @@ template <> otError NcpBase::HandlePropertyGet otError NcpBase::HandlePropertyGet(void) { - return mEncoder.WriteUint8(otThreadGetMaxAllowedChildren(mInstance)); + return mEncoder.WriteUint8(static_cast(otThreadGetMaxAllowedChildren(mInstance))); } template <> otError NcpBase::HandlePropertySet(void) diff --git a/tests/unit/test_child_table.cpp b/tests/unit/test_child_table.cpp index 9499c01e2..f33589eb2 100644 --- a/tests/unit/test_child_table.cpp +++ b/tests/unit/test_child_table.cpp @@ -105,17 +105,17 @@ static bool StateMatchesFilter(Child::State aState, ChildTable::StateFilter aFil } // Verifies that `ChildTable` contains a given list of `TestChild` entries. -void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const TestChild *aChildList) +void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, const TestChild *aChildList) { printf("Test ChildTable with %d entries", aChildListLength); - for (uint8_t k = 0; k < OT_ARRAY_LENGTH(kAllFilters); k++) + for (uint16_t k = 0; k < OT_ARRAY_LENGTH(kAllFilters); k++) { ChildTable::StateFilter filter = kAllFilters[k]; // Verify that we can find all children from given list by rloc or extended address. - for (uint8_t listIndex = 0; listIndex < aChildListLength; listIndex++) + for (uint16_t listIndex = 0; listIndex < aChildListLength; listIndex++) { Child * child; Mac::Address address; @@ -146,7 +146,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const // Verify `ChildTable::Iterator` behavior when starting from different child entries. - for (uint8_t listIndex = 0; listIndex <= aChildListLength; listIndex++) + for (uint16_t listIndex = 0; listIndex <= aChildListLength; listIndex++) { Child *startingChild = NULL; @@ -161,7 +161,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const { ChildTable::Iterator iter(*sInstance, filter, startingChild); bool childObserved[kMaxChildren]; - uint8_t numChildren = 0; + uint16_t numChildren = 0; memset(childObserved, 0, sizeof(childObserved)); @@ -183,9 +183,9 @@ void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const for (; !iter.IsDone(); iter++) { - Child * child = iter.GetChild(); - bool didFind = false; - uint8_t childIndex; + Child * child = iter.GetChild(); + bool didFind = false; + uint16_t childIndex; VerifyOrQuit(child != NULL, "iter.GetChild() failed"); @@ -193,7 +193,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const VerifyOrQuit(childIndex < aTable.GetMaxChildrenAllowed(), "Child Index is out of bound"); VerifyOrQuit(aTable.GetChildAtIndex(childIndex) == child, "GetChildAtIndex() failed"); - for (uint8_t index = 0; index < aChildListLength; index++) + for (uint16_t index = 0; index < aChildListLength; index++) { if (ChildMatches(*iter.GetChild(), aChildList[index])) { @@ -223,7 +223,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const // Verify that there is no missing or extra entry between the expected list // and what was observed/returned by the iterator. - for (uint8_t index = 0; index < aChildListLength; index++) + for (uint16_t index = 0; index < aChildListLength; index++) { if (StateMatchesFilter(aChildList[index].mState, filter)) { @@ -296,9 +296,9 @@ void TestChildTable(void) }, }; - const uint8_t testListLength = OT_ARRAY_LENGTH(testChildList); + const uint16_t testListLength = OT_ARRAY_LENGTH(testChildList); - uint8_t testNumAllowedChildren = 2; + uint16_t testNumAllowedChildren = 2; ChildTable *table; otError error; @@ -314,7 +314,7 @@ void TestChildTable(void) VerifyOrQuit(table->GetMaxChildrenAllowed() == table->GetMaxChildren(), "GetMaxChildrenAllowed() initial value is incorrect "); - for (uint8_t i = 0; i < OT_ARRAY_LENGTH(kAllFilters); i++) + for (uint16_t i = 0; i < OT_ARRAY_LENGTH(kAllFilters); i++) { ChildTable::StateFilter filter = kAllFilters[i]; @@ -332,7 +332,7 @@ void TestChildTable(void) "Default child table size is too small for the unit test"); // Add the child entries from test list one by one and verify the table content - for (uint8_t i = 0; i < testListLength; i++) + for (uint16_t i = 0; i < testListLength; i++) { Child *child; @@ -354,7 +354,7 @@ void TestChildTable(void) VerifyChildTableContent(*table, 0, testChildList); // Add the child entries from test list in reverse order and verify the table content - for (uint8_t i = testListLength; i > 0; i--) + for (uint16_t i = testListLength; i > 0; i--) { Child *child; @@ -385,7 +385,7 @@ void TestChildTable(void) VerifyOrQuit(error == OT_ERROR_NONE, "SetMaxChildrenAllowed() failed"); VerifyOrQuit(table->GetMaxChildrenAllowed() == testNumAllowedChildren, "GetMaxChildrenAllowed() failed"); - for (uint8_t num = 0; num < testNumAllowedChildren; num++) + for (uint16_t num = 0; num < testNumAllowedChildren; num++) { Child *child = table->GetNewChild();