From 188a97dc21c5d33488f56eb29b599aa81ac82e0a Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 31 Aug 2016 12:33:08 -0700 Subject: [PATCH] Ncp: Add support for child table property (#499) This commit adds support to `NcpBase` for getting the list of children (and the info about each child) by adding the get handler for spinel property `THREAD_CHILD_TABLE`. --- src/ncp/ncp_base.cpp | 63 ++++++++++++++++++++++++++++++++++++++++---- src/ncp/ncp_base.hpp | 2 ++ src/ncp/spinel.h | 3 ++- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 188e03ff5..6d683398b 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -113,6 +113,8 @@ const NcpBase::GetPropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = { SPINEL_PROP_NET_PARTITION_ID, &NcpBase::GetPropertyHandler_NET_PARTITION_ID }, { SPINEL_PROP_THREAD_LEADER_ADDR, &NcpBase::GetPropertyHandler_THREAD_LEADER_ADDR }, + { SPINEL_PROP_THREAD_PARENT, &NcpBase::GetPropertyHandler_THREAD_PARENT }, + { SPINEL_PROP_THREAD_CHILD_TABLE, &NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE }, { SPINEL_PROP_THREAD_LEADER_RID, &NcpBase::GetPropertyHandler_THREAD_LEADER_RID }, { SPINEL_PROP_THREAD_LEADER_WEIGHT, &NcpBase::GetPropertyHandler_THREAD_LEADER_WEIGHT }, { SPINEL_PROP_THREAD_LOCAL_LEADER_WEIGHT, &NcpBase::GetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT }, @@ -689,11 +691,10 @@ void NcpBase::UpdateChangedProps(void) } else if ((mChangedFlags & (OT_THREAD_CHILD_ADDED | OT_THREAD_CHILD_REMOVED)) != 0) { - // TODO: Uncomment this once we add support for this property. - //SuccessOrExit(HandleCommandPropertyGet( - // SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, - // SPINEL_PROP_THREAD_CHILD_TABLE - //)); + SuccessOrExit(HandleCommandPropertyGet( + SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, + SPINEL_PROP_THREAD_CHILD_TABLE + )); mChangedFlags &= ~static_cast(OT_THREAD_CHILD_ADDED | OT_THREAD_CHILD_REMOVED); } else if ((mChangedFlags & OT_THREAD_NETDATA_UPDATED) != 0) @@ -1769,6 +1770,58 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_ADDR(uint8_t header, spine return errorCode; } +ThreadError NcpBase::GetPropertyHandler_THREAD_PARENT(uint8_t header, spinel_prop_key_t key) +{ + ThreadError errorCode = kThreadError_None; + (void)key; + + errorCode = SendLastStatus(header, SPINEL_STATUS_UNIMPLEMENTED); + + return errorCode; +} + +ThreadError NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE(uint8_t header, spinel_prop_key_t key) +{ + ThreadError errorCode = kThreadError_None; + otChildInfo childInfo; + uint8_t index; + + SuccessOrExit(errorCode = OutboundFrameBegin()); + SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key)); + + index = 0; + + while (otGetChildInfoByIndex(index, &childInfo) == kThreadError_None) + { + if (childInfo.mTimeout > 0) + { + SuccessOrExit( + errorCode = OutboundFrameFeedPacked( + "T(ESSLLCCcbbbb)", + childInfo.mExtAddress, + childInfo.mChildId, + childInfo.mRloc16, + childInfo.mTimeout, + childInfo.mAge, + childInfo.mNetworkDataVersion, + childInfo.mLinkQualityIn, + childInfo.mAverageRssi, + childInfo.mRxOnWhenIdle, + childInfo.mSecureDataRequest, + childInfo.mFullFunction, + childInfo.mFullNetworkData + )); + } + + index++; + } + + SuccessOrExit(errorCode = OutboundFrameSend()); + +exit: + return errorCode; +} + ThreadError NcpBase::GetPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spinel_prop_key_t key) { ThreadError errorCode = kThreadError_None; diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 906819419..4185c429d 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -293,6 +293,8 @@ private: ThreadError GetPropertyHandler_MAC_SCAN_MASK(uint8_t header, spinel_prop_key_t key); ThreadError GetPropertyHandler_MAC_SCAN_PERIOD(uint8_t header, spinel_prop_key_t key); ThreadError GetPropertyHandler_THREAD_LEADER_ADDR(uint8_t header, spinel_prop_key_t key); + ThreadError GetPropertyHandler_THREAD_PARENT(uint8_t header, spinel_prop_key_t key); + ThreadError GetPropertyHandler_THREAD_CHILD_TABLE(uint8_t header, spinel_prop_key_t key); ThreadError GetPropertyHandler_THREAD_LEADER_RID(uint8_t header, spinel_prop_key_t key); ThreadError GetPropertyHandler_THREAD_LEADER_WEIGHT(uint8_t header, spinel_prop_key_t key); ThreadError GetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT(uint8_t header, spinel_prop_key_t key); diff --git a/src/ncp/spinel.h b/src/ncp/spinel.h index 0fa524a7d..c7a97028d 100644 --- a/src/ncp/spinel.h +++ b/src/ncp/spinel.h @@ -368,7 +368,8 @@ typedef enum SPINEL_PROP_THREAD__BEGIN = 0x50, SPINEL_PROP_THREAD_LEADER_ADDR = SPINEL_PROP_THREAD__BEGIN + 0, ///< [6] SPINEL_PROP_THREAD_PARENT = SPINEL_PROP_THREAD__BEGIN + 1, ///< LADDR, SADDR [ES] - SPINEL_PROP_THREAD_CHILD_TABLE = SPINEL_PROP_THREAD__BEGIN + 2, ///< [A(T(ES))] + SPINEL_PROP_THREAD_CHILD_TABLE = SPINEL_PROP_THREAD__BEGIN + 2, ///< [A(T(ESSLLCCcbbbb))] + /// array(EUI64,chId,rloc16,timeout,age,netDataVer,inLqi,aveRSS,rxOnInIdle,secureDataReq,fullFunc,fullNetData) SPINEL_PROP_THREAD_LEADER_RID = SPINEL_PROP_THREAD__BEGIN + 3, ///< [C] SPINEL_PROP_THREAD_LEADER_WEIGHT = SPINEL_PROP_THREAD__BEGIN + 4, ///< [C] SPINEL_PROP_THREAD_LOCAL_LEADER_WEIGHT