diff --git a/Makefile.am b/Makefile.am index 8c6145985..81861e62b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-dhcp6-server \ --enable-dns-client \ --enable-application-coap \ + --enable-border-router \ $(NULL) SUBDIRS = \ diff --git a/configure.ac b/configure.ac index dec2f9d7d..b58785674 100644 --- a/configure.ac +++ b/configure.ac @@ -1047,6 +1047,36 @@ AC_SUBST(OPENTHREAD_ENABLE_RAW_LINK_API) AM_CONDITIONAL([OPENTHREAD_ENABLE_RAW_LINK_API], [test "${enable_raw_link_api}" = "yes"]) AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_RAW_LINK_API],[${OPENTHREAD_ENABLE_RAW_LINK_API}],[Define to 1 if you want to enable raw link-layer API]) +# +# Border Router +# + +AC_ARG_ENABLE(border_router, + [AS_HELP_STRING([--enable-border-router],[Enable Border Router support @<:@default=no@:>@.])], + [ + case "${enableval}" in + + no|yes) + enable_border_router=${enableval} + ;; + + *) + AC_MSG_ERROR([Invalid value ${enable_border_router} for --enable-border-router]) + ;; + esac + ], + [enable_border_router=no]) + +if test "$enable_border_router" = "yes"; then + OPENTHREAD_ENABLE_BORDER_ROUTER=1 +else + OPENTHREAD_ENABLE_BORDER_ROUTER=0 +fi + +AC_SUBST(OPENTHREAD_ENABLE_BORDER_ROUTER) +AM_CONDITIONAL([OPENTHREAD_ENABLE_BORDER_ROUTER], [test "${enable_border_router}" = "yes"]) +AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_BORDER_ROUTER],[${OPENTHREAD_ENABLE_BORDER_ROUTER}],[Define to 1 if you want to enable Border Router]) + # # Examples # @@ -1400,6 +1430,7 @@ AC_MSG_NOTICE([ OpenThread DNS Client support : ${enable_dns_client} OpenThread Application CoAP support : ${enable_application_coap} OpenThread Raw Link-Layer support : ${enable_raw_link_api} + OpenThread Border Router support : ${enable_border_router} OpenThread examples : ${OPENTHREAD_EXAMPLES} OpenThread platform information : ${PLATFORM_INFO} diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj index 384ab96a6..3a6549071 100644 --- a/etc/visual-studio/libopenthread.vcxproj +++ b/etc/visual-studio/libopenthread.vcxproj @@ -58,6 +58,7 @@ + diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters index 5ca9de7a8..f6b99f71c 100644 --- a/etc/visual-studio/libopenthread.vcxproj.filters +++ b/etc/visual-studio/libopenthread.vcxproj.filters @@ -72,6 +72,9 @@ Source Files\api + + Source Files\api + Source Files\api diff --git a/etc/visual-studio/libopenthread_k.vcxproj b/etc/visual-studio/libopenthread_k.vcxproj index d92ffc00d..ca6772c58 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj +++ b/etc/visual-studio/libopenthread_k.vcxproj @@ -68,6 +68,7 @@ + @@ -154,6 +155,7 @@ + diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters index 2ca92d6af..28fb65f8e 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj.filters +++ b/etc/visual-studio/libopenthread_k.vcxproj.filters @@ -75,6 +75,9 @@ Source Files\api + + Source Files\api + Source Files\api @@ -581,6 +584,9 @@ Header Files\openthread + + Header Files\openthread + Header Files\openthread diff --git a/examples/Makefile-posix b/examples/Makefile-posix index 1e356e84c..333a3413f 100644 --- a/examples/Makefile-posix +++ b/examples/Makefile-posix @@ -102,6 +102,7 @@ configure_OPTIONS = \ --enable-legacy \ --enable-mac-whitelist \ --enable-mtd-network-diagnostic \ + --enable-border-router \ $(NULL) ifndef BuildJobs diff --git a/examples/apps/windows/otAdapter.h b/examples/apps/windows/otAdapter.h index 3d7880f86..b23ec1d69 100644 --- a/examples/apps/windows/otAdapter.h +++ b/examples/apps/windows/otAdapter.h @@ -30,6 +30,7 @@ #define OTDLL 1 #include +#include #include #include #include diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 4b125f028..13a1873e8 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -30,6 +30,10 @@ ifeq ($(BA_PROXY),1) configure_OPTIONS += --enable-border-agent-proxy endif +ifeq ($(BORDER_ROUTER),1) +configure_OPTIONS += --enable-border-router +endif + ifeq ($(CERT_LOG),1) configure_OPTIONS += --enable-cert-log endif diff --git a/examples/drivers/windows/otApi/otApi.cpp b/examples/drivers/windows/otApi/otApi.cpp index f54928cd3..65e3dab07 100644 --- a/examples/drivers/windows/otApi/otApi.cpp +++ b/examples/drivers/windows/otApi/otApi.cpp @@ -1806,16 +1806,51 @@ otThreadSetNetworkName( OTAPI otError OTCALL -otNetDataGetNextPrefixInfo( +otNetDataGetNextOnMeshPrefix( _In_ otInstance *aInstance, - bool _aLocal, _Inout_ otNetworkDataIterator *aIterator, _Out_ otBorderRouterConfig *aConfig ) { if (aInstance == nullptr || aConfig == nullptr) return OT_ERROR_INVALID_ARGS; - BOOLEAN aLocal = _aLocal ? TRUE : FALSE; + BOOLEAN aLocal = FALSE; + PackedBuffer3 InBuffer(aInstance->InterfaceGuid, aLocal, *aIterator); + BYTE OutBuffer[sizeof(uint8_t) + sizeof(otBorderRouterConfig)]; + + otError aError = + DwordToThreadError( + SendIOCTL( + aInstance->ApiHandle, + IOCTL_OTLWF_OT_NEXT_ON_MESH_PREFIX, + &InBuffer, sizeof(InBuffer), + OutBuffer, sizeof(OutBuffer))); + + if (aError == OT_ERROR_NONE) + { + memcpy(aIterator, OutBuffer, sizeof(uint8_t)); + memcpy(aConfig, OutBuffer + sizeof(uint8_t), sizeof(otBorderRouterConfig)); + } + else + { + ZeroMemory(aConfig, sizeof(otBorderRouterConfig)); + } + + return aError; +} + +OTAPI +otError +OTCALL +otBorderRouterGetNextOnMeshPrefix( + _In_ otInstance *aInstance, + _Inout_ otNetworkDataIterator *aIterator, + _Out_ otBorderRouterConfig *aConfig + ) +{ + if (aInstance == nullptr || aConfig == nullptr) return OT_ERROR_INVALID_ARGS; + + BOOLEAN aLocal = TRUE; PackedBuffer3 InBuffer(aInstance->InterfaceGuid, aLocal, *aIterator); BYTE OutBuffer[sizeof(uint8_t) + sizeof(otBorderRouterConfig)]; @@ -2467,7 +2502,7 @@ otThreadSetJoinerUdpPort( OTAPI otError OTCALL -otNetDataAddPrefixInfo( +otBorderRouterAddOnMeshPrefix( _In_ otInstance *aInstance, const otBorderRouterConfig *aConfig ) @@ -2479,7 +2514,7 @@ otNetDataAddPrefixInfo( OTAPI otError OTCALL -otNetDataRemovePrefixInfo( +otBorderRouterRemoveOnMeshPrefix( _In_ otInstance *aInstance, const otIp6Prefix *aPrefix ) @@ -2491,7 +2526,7 @@ otNetDataRemovePrefixInfo( OTAPI otError OTCALL -otNetDataAddRoute( +otBorderRouterAddRoute( _In_ otInstance *aInstance, const otExternalRouteConfig *aConfig ) @@ -2503,7 +2538,7 @@ otNetDataAddRoute( OTAPI otError OTCALL -otNetDataRemoveRoute( +otBorderRouterRemoveRoute( _In_ otInstance *aInstance, const otIp6Prefix *aPrefix ) @@ -2515,7 +2550,7 @@ otNetDataRemoveRoute( OTAPI otError OTCALL -otNetDataRegister( +otBorderRouterRegister( _In_ otInstance *aInstance ) { diff --git a/examples/drivers/windows/otApi/precomp.h b/examples/drivers/windows/otApi/precomp.h index cf29dceab..0308eb491 100644 --- a/examples/drivers/windows/otApi/precomp.h +++ b/examples/drivers/windows/otApi/precomp.h @@ -22,6 +22,7 @@ #define OTAPI EXTERN_C __declspec(dllexport) #include +#include #include #include #include diff --git a/examples/drivers/windows/otLwf/iocontrol.c b/examples/drivers/windows/otLwf/iocontrol.c index 72104f43f..a13603345 100644 --- a/examples/drivers/windows/otLwf/iocontrol.c +++ b/examples/drivers/windows/otLwf/iocontrol.c @@ -2586,7 +2586,7 @@ otLwfIoCtl_otAddBorderRouter( if (InBufferLength >= sizeof(otBorderRouterConfig)) { - status = ThreadErrorToNtstatus(otNetDataAddPrefixInfo(pFilter->otCtx, (otBorderRouterConfig*)InBuffer)); + status = ThreadErrorToNtstatus(otBorderRouterAddOnMeshPrefix(pFilter->otCtx, (otBorderRouterConfig*)InBuffer)); } return status; @@ -2667,7 +2667,7 @@ otLwfIoCtl_otRemoveBorderRouter( if (InBufferLength >= sizeof(otIp6Prefix)) { - status = ThreadErrorToNtstatus(otNetDataRemovePrefixInfo(pFilter->otCtx, (otIp6Prefix*)InBuffer)); + status = ThreadErrorToNtstatus(otBorderRouterRemoveOnMeshPrefix(pFilter->otCtx, (otIp6Prefix*)InBuffer)); } return status; @@ -2730,7 +2730,7 @@ otLwfIoCtl_otAddExternalRoute( if (InBufferLength >= sizeof(otExternalRouteConfig)) { - status = ThreadErrorToNtstatus(otNetDataAddRoute(pFilter->otCtx, (otExternalRouteConfig*)InBuffer)); + status = ThreadErrorToNtstatus(otBorderRouterAddRoute(pFilter->otCtx, (otExternalRouteConfig*)InBuffer)); } return status; @@ -2802,7 +2802,7 @@ otLwfIoCtl_otRemoveExternalRoute( if (InBufferLength >= sizeof(otIp6Prefix)) { - status = ThreadErrorToNtstatus(otNetDataRemoveRoute(pFilter->otCtx, (otIp6Prefix*)InBuffer)); + status = ThreadErrorToNtstatus(otBorderRouterRemoveRoute(pFilter->otCtx, (otIp6Prefix*)InBuffer)); } return status; @@ -2865,7 +2865,7 @@ otLwfIoCtl_otSendServerData( UNREFERENCED_PARAMETER(OutBuffer); *OutBufferLength = 0; - status = ThreadErrorToNtstatus(otNetDataRegister(pFilter->otCtx)); + status = ThreadErrorToNtstatus(otBorderRouterRegister(pFilter->otCtx)); return status; } @@ -4804,13 +4804,24 @@ otLwfIoCtl_otNextOnMeshPrefix( BOOLEAN aLocal = *(BOOLEAN*)InBuffer; uint8_t aIterator = *(uint8_t*)(InBuffer + sizeof(BOOLEAN)); otBorderRouterConfig* aConfig = (otBorderRouterConfig*)((PUCHAR)OutBuffer + sizeof(uint8_t)); - status = ThreadErrorToNtstatus( - otNetDataGetNextPrefixInfo( - pFilter->otCtx, - aLocal, - &aIterator, - aConfig) - ); + if (aLocal) + { + status = ThreadErrorToNtstatus( + otBorderRouterGetNextOnMeshPrefix( + pFilter->otCtx, + &aIterator, + aConfig) + ); + } + else + { + status = ThreadErrorToNtstatus( + otNetDataGetNextOnMeshPrefix( + pFilter->otCtx, + &aIterator, + aConfig) + ); + } *OutBufferLength = sizeof(uint8_t) + sizeof(otBorderRouterConfig); if (status == STATUS_SUCCESS) { diff --git a/examples/drivers/windows/otLwf/precomp.h b/examples/drivers/windows/otLwf/precomp.h index 5fd2e9b6f..31ef93032 100644 --- a/examples/drivers/windows/otLwf/precomp.h +++ b/examples/drivers/windows/otLwf/precomp.h @@ -62,6 +62,7 @@ RtlCopyBufferToMdl( #include #include #include +#include #include #include #include diff --git a/examples/drivers/windows/otNodeApi/otNodeApi.cpp b/examples/drivers/windows/otNodeApi/otNodeApi.cpp index 82fea3be2..4dfa64ad5 100644 --- a/examples/drivers/windows/otNodeApi/otNodeApi.cpp +++ b/examples/drivers/windows/otNodeApi/otNodeApi.cpp @@ -1610,7 +1610,7 @@ OTNODEAPI int32_t OTCALL otNodeAddPrefix(otNode* aNode, const char *aPrefix, con return OT_ERROR_INVALID_ARGS; } - auto result = otNetDataAddPrefixInfo(aNode->mInstance, &config); + auto result = otBorderRouterAddOnMeshPrefix(aNode->mInstance, &config); otLogFuncExit(); return result; } @@ -1623,7 +1623,7 @@ OTNODEAPI int32_t OTCALL otNodeRemovePrefix(otNode* aNode, const char *aPrefix) auto error = otNodeParsePrefix(aPrefix, &prefix); if (error != OT_ERROR_NONE) return error; - auto result = otNetDataRemovePrefixInfo(aNode->mInstance, &prefix); + auto result = otBorderRouterRemoveOnMeshPrefix(aNode->mInstance, &prefix); otLogFuncExit(); return result; } @@ -1653,7 +1653,7 @@ OTNODEAPI int32_t OTCALL otNodeAddRoute(otNode* aNode, const char *aPrefix, cons return OT_ERROR_INVALID_ARGS; } - auto result = otNetDataAddRoute(aNode->mInstance, &config); + auto result = otBorderRouterAddRoute(aNode->mInstance, &config); otLogFuncExit(); return result; } @@ -1666,7 +1666,7 @@ OTNODEAPI int32_t OTCALL otNodeRemoveRoute(otNode* aNode, const char *aPrefix) auto error = otNodeParsePrefix(aPrefix, &prefix); if (error != OT_ERROR_NONE) return error; - auto result = otNetDataRemoveRoute(aNode->mInstance, &prefix); + auto result = otBorderRouterRemoveRoute(aNode->mInstance, &prefix); otLogFuncExit(); return result; } @@ -1675,7 +1675,7 @@ OTNODEAPI int32_t OTCALL otNodeRegisterNetdata(otNode* aNode) { otLogFuncEntryMsg("[%d]", aNode->mId); printf("%d: registernetdata\r\n", aNode->mId); - auto result = otNetDataRegister(aNode->mInstance); + auto result = otBorderRouterRegister(aNode->mInstance); otLogFuncExit(); return result; } diff --git a/examples/drivers/windows/otNodeApi/precomp.h b/examples/drivers/windows/otNodeApi/precomp.h index 5ab5e10f2..671d5d94b 100644 --- a/examples/drivers/windows/otNodeApi/precomp.h +++ b/examples/drivers/windows/otNodeApi/precomp.h @@ -50,6 +50,7 @@ using namespace std; #define OTNODEAPI EXTERN_C __declspec(dllexport) #include +#include #include #include #include diff --git a/include/openthread-windows-config.h b/include/openthread-windows-config.h index 322567776..83db31bfc 100644 --- a/include/openthread-windows-config.h +++ b/include/openthread-windows-config.h @@ -72,6 +72,9 @@ #define OPENTHREAD_ENABLE_RAW_LINK_API 1 #endif +/* Define to 1 to enable Border Router feature. */ +#define OPENTHREAD_ENABLE_BORDER_ROUTER 1 + /* Name of package */ #define PACKAGE "openthread" diff --git a/include/openthread/Makefile.am b/include/openthread/Makefile.am index d8d45fb31..e07751055 100644 --- a/include/openthread/Makefile.am +++ b/include/openthread/Makefile.am @@ -53,6 +53,7 @@ openthread_headers = \ coap.h \ commissioner.h \ crypto.h \ + border_router.h \ dataset.h \ dataset_ftd.h \ diag.h \ diff --git a/include/openthread/border_router.h b/include/openthread/border_router.h new file mode 100644 index 000000000..27a90c72b --- /dev/null +++ b/include/openthread/border_router.h @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2016-2017, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * @brief + * This file defines the OpenThread Border Router API. + */ + +#ifndef OPENTHREAD_BORDER_ROUTER_H_ +#define OPENTHREAD_BORDER_ROUTER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup api-thread-general + * + * @{ + * + */ + +/** + * This method provides a full or stable copy of the local Thread Network Data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aStable TRUE when copying the stable version, FALSE when copying the full version. + * @param[out] aData A pointer to the data buffer. + * @param[inout] aDataLength On entry, size of the data buffer pointed to by @p aData. + * On exit, number of copied bytes. + */ +OTAPI otError OTCALL otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, + uint8_t *aDataLength); + +/** + * Add a border router configuration to the local network data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aConfig A pointer to the border router configuration. + * + * @retval OT_ERROR_NONE Successfully added the configuration to the local network data. + * @retval OT_ERROR_INVALID_ARGS One or more configuration parameters were invalid. + * @retval OT_ERROR_NO_BUFS Not enough room is available to add the configuration to the local network data. + * + * @sa otBorderRouterRemoveOnMeshPrefix + * @sa otBorderRouterRegister + */ +OTAPI otError OTCALL otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig); + +/** + * Remove a border router configuration from the local network data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aPrefix A pointer to an IPv6 prefix. + * + * @retval OT_ERROR_NONE Successfully removed the configuration from the local network data. + * + * @sa otBorderRouterAddOnMeshPrefix + * @sa otBorderRouterRegister + */ +OTAPI otError OTCALL otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix); + +/** + * This function gets the next On Mesh Prefix in the local Network Data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[inout] aIterator A pointer to the Network Data iterator context. To get the first on-mesh entry + it should be set to OT_NETWORK_DATA_ITERATOR_INIT. + * @param[out] aConfig A pointer to where the On Mesh Prefix information will be placed. + * + * @retval OT_ERROR_NONE Successfully found the next On Mesh prefix. + * @retval OT_ERROR_NOT_FOUND No subsequent On Mesh prefix exists in the Thread Network Data. + * + */ +OTAPI otError OTCALL otBorderRouterGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator, + otBorderRouterConfig *aConfig); + +/** + * Add an external route configuration to the local network data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aConfig A pointer to the external route configuration. + * + * @retval OT_ERROR_NONE Successfully added the configuration to the local network data. + * @retval OT_ERROR_INVALID_ARGS One or more configuration parameters were invalid. + * @retval OT_ERROR_NO_BUFS Not enough room is available to add the configuration to the local network data. + * + * @sa otBorderRouterRemoveRoute + * @sa otBorderRouterRegister + */ +OTAPI otError OTCALL otBorderRouterAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig); + +/** + * Remove an external route configuration from the local network data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aPrefix A pointer to an IPv6 prefix. + * + * @retval OT_ERROR_NONE Successfully removed the configuration from the local network data. + * + * @sa otBorderRouterAddRoute + * @sa otBorderRouterRegister + */ +OTAPI otError OTCALL otBorderRouterRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPrefix); + +/** + * This function gets the next external route in the local Network Data. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[inout] aIterator A pointer to the Network Data iterator context. To get the first external route entry + it should be set to OT_NETWORK_DATA_ITERATOR_INIT. + * @param[out] aConfig A pointer to where the External Route information will be placed. + * + * @retval OT_ERROR_NONE Successfully found the next External Route. + * @retval OT_ERROR_NOT_FOUND No subsequent external route entry exists in the Thread Network Data. + * + */ +otError otBorderRouterGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, + otExternalRouteConfig *aConfig); + +/** + * Immediately register the local network data with the Leader. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * retval OT_ERROR_NONE Successfully queued a Server Data Request message for delivery. + * + * @sa otBorderRouterAddOnMeshPrefix + * @sa otBorderRouterRemoveOnMeshPrefix + * @sa otBorderRouterAddRoute + * @sa otBorderRouterRemoveRoute + */ +OTAPI otError OTCALL otBorderRouterRegister(otInstance *aInstance); + +/** + * @} + * + */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENTHREAD_BORDER_ROUTER_H_ diff --git a/include/openthread/netdata.h b/include/openthread/netdata.h index 15ea0621b..630d49edc 100644 --- a/include/openthread/netdata.h +++ b/include/openthread/netdata.h @@ -57,26 +57,13 @@ extern "C" { * @param[inout] aDataLength On entry, size of the data buffer pointed to by @p aData. * On exit, number of copied bytes. */ -OTAPI otError OTCALL otNetDataGetLeader(otInstance *aInstance, bool aStable, uint8_t *aData, - uint8_t *aDataLength); +OTAPI otError OTCALL otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, + uint8_t *aDataLength); /** - * This method provides a full or stable copy of the local Thread Network Data. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aStable TRUE when copying the stable version, FALSE when copying the full version. - * @param[out] aData A pointer to the data buffer. - * @param[inout] aDataLength On entry, size of the data buffer pointed to by @p aData. - * On exit, number of copied bytes. - */ -OTAPI otError OTCALL otNetDataGetLocal(otInstance *aInstance, bool aStable, uint8_t *aData, - uint8_t *aDataLength); - -/** - * This function gets the next On Mesh Prefix in the Network Data. + * This function gets the next On Mesh Prefix in the partition's Network Data. * * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aLocal TRUE to retrieve from the local Network Data, FALSE for partition's Network Data * @param[inout] aIterator A pointer to the Network Data iterator context. To get the first on-mesh entry it should be set to OT_NETWORK_DATA_ITERATOR_INIT. * @param[out] aConfig A pointer to where the On Mesh Prefix information will be placed. @@ -85,70 +72,13 @@ OTAPI otError OTCALL otNetDataGetLocal(otInstance *aInstance, bool aStable, uint * @retval OT_ERROR_NOT_FOUND No subsequent On Mesh prefix exists in the Thread Network Data. * */ -OTAPI otError OTCALL otNetDataGetNextPrefixInfo(otInstance *aInstance, bool aLocal, - otNetworkDataIterator *aIterator, otBorderRouterConfig *aConfig); +OTAPI otError OTCALL otNetDataGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator, + otBorderRouterConfig *aConfig); /** - * Add a border router configuration to the local network data. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aConfig A pointer to the border router configuration. - * - * @retval OT_ERROR_NONE Successfully added the configuration to the local network data. - * @retval OT_ERROR_INVALID_ARGS One or more configuration parameters were invalid. - * @retval OT_ERROR_NO_BUFS Not enough room is available to add the configuration to the local network data. - * - * @sa otRemoveBorderRouter - * @sa otSendServerData - */ -OTAPI otError OTCALL otNetDataAddPrefixInfo(otInstance *aInstance, const otBorderRouterConfig *aConfig); - -/** - * Remove a border router configuration from the local network data. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aPrefix A pointer to an IPv6 prefix. - * - * @retval OT_ERROR_NONE Successfully removed the configuration from the local network data. - * - * @sa otAddBorderRouter - * @sa otSendServerData - */ -OTAPI otError OTCALL otNetDataRemovePrefixInfo(otInstance *aInstance, const otIp6Prefix *aPrefix); - -/** - * Add an external route configuration to the local network data. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aConfig A pointer to the external route configuration. - * - * @retval OT_ERROR_NONE Successfully added the configuration to the local network data. - * @retval OT_ERROR_INVALID_ARGS One or more configuration parameters were invalid. - * @retval OT_ERROR_NO_BUFS Not enough room is available to add the configuration to the local network data. - * - * @sa otRemoveExternalRoute - * @sa otSendServerData - */ -OTAPI otError OTCALL otNetDataAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig); - -/** - * Remove an external route configuration from the local network data. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aPrefix A pointer to an IPv6 prefix. - * - * @retval OT_ERROR_NONE Successfully removed the configuration from the local network data. - * - * @sa otAddExternalRoute - * @sa otSendServerData - */ -OTAPI otError OTCALL otNetDataRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPrefix); - -/** - * This function gets the next external route in the Network Data. + * This function gets the next external route in the partition's Network Data. * * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aLocal TRUE to retrieve from the local Network Data, FALSE for partition's Network Data * @param[inout] aIterator A pointer to the Network Data iterator context. To get the first external route entry it should be set to OT_NETWORK_DATA_ITERATOR_INIT. * @param[out] aConfig A pointer to where the External Route information will be placed. @@ -157,23 +87,9 @@ OTAPI otError OTCALL otNetDataRemoveRoute(otInstance *aInstance, const otIp6Pref * @retval OT_ERROR_NOT_FOUND No subsequent external route entry exists in the Thread Network Data. * */ -otError otNetDataGetNextRoute(otInstance *aInstance, bool aLocal, otNetworkDataIterator *aIterator, +otError otNetDataGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig); -/** - * Immediately register the local network data with the Leader. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * retval OT_ERROR_NONE Successfully queued a Server Data Request message for delivery. - * - * @sa otAddBorderRouter - * @sa otRemoveBorderRouter - * @sa otAddExternalRoute - * @sa otRemoveExternalRoute - */ -OTAPI otError OTCALL otNetDataRegister(otInstance *aInstance); - /** * Get the Network Data Version. * diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 03ad2dfe2..869361a49 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -57,6 +57,10 @@ #include #endif +#if OPENTHREAD_ENABLE_BORDER_ROUTER +#include +#endif + #ifndef OTDLL #include #include @@ -153,7 +157,9 @@ const struct Command Interpreter::sCommands[] = { "linkquality", &Interpreter::ProcessLinkQuality }, { "masterkey", &Interpreter::ProcessMasterKey }, { "mode", &Interpreter::ProcessMode }, +#if OPENTHREAD_ENABLE_BORDER_ROUTER { "netdataregister", &Interpreter::ProcessNetworkDataRegister }, +#endif #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC { "networkdiagnostic", &Interpreter::ProcessNetworkDiagnostic }, #endif // OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC @@ -170,14 +176,18 @@ const struct Command Interpreter::sCommands[] = #ifndef OTDLL { "promiscuous", &Interpreter::ProcessPromiscuous }, #endif +#if OPENTHREAD_ENABLE_BORDER_ROUTER { "prefix", &Interpreter::ProcessPrefix }, +#endif #if OPENTHREAD_FTD { "pskc", &Interpreter::ProcessPSKc }, { "releaserouterid", &Interpreter::ProcessReleaseRouterId }, #endif { "reset", &Interpreter::ProcessReset }, { "rloc16", &Interpreter::ProcessRloc16 }, +#if OPENTHREAD_ENABLE_BORDER_ROUTER { "route", &Interpreter::ProcessRoute }, +#endif #if OPENTHREAD_FTD { "router", &Interpreter::ProcessRouter }, { "routerdowngradethreshold", &Interpreter::ProcessRouterDowngradeThreshold }, @@ -1449,16 +1459,18 @@ exit: AppendResult(error); } +#if OPENTHREAD_ENABLE_BORDER_ROUTER void Interpreter::ProcessNetworkDataRegister(int argc, char *argv[]) { otError error = OT_ERROR_NONE; - SuccessOrExit(error = otNetDataRegister(mInstance)); + SuccessOrExit(error = otBorderRouterRegister(mInstance)); exit: (void)argc; (void)argv; AppendResult(error); } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER #if OPENTHREAD_FTD void Interpreter::ProcessNetworkIdTimeout(int argc, char *argv[]) @@ -1794,6 +1806,7 @@ void Interpreter::HandleLinkPcapReceive(const otRadioFrame *aFrame) } #endif +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError Interpreter::ProcessPrefixAdd(int argc, char *argv[]) { otError error = OT_ERROR_NONE; @@ -1878,7 +1891,7 @@ otError Interpreter::ProcessPrefixAdd(int argc, char *argv[]) } } - error = otNetDataAddPrefixInfo(mInstance, &config); + error = otBorderRouterAddOnMeshPrefix(mInstance, &config); exit: return error; @@ -1911,7 +1924,7 @@ otError Interpreter::ProcessPrefixRemove(int argc, char *argv[]) ExitNow(error = OT_ERROR_PARSE); } - error = otNetDataRemovePrefixInfo(mInstance, &prefix); + error = otBorderRouterRemoveOnMeshPrefix(mInstance, &prefix); exit: (void)argc; @@ -1923,7 +1936,7 @@ otError Interpreter::ProcessPrefixList(void) otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT; otBorderRouterConfig config; - while (otNetDataGetNextPrefixInfo(mInstance, true, &iterator, &config) == OT_ERROR_NONE) + while (otBorderRouterGetNextOnMeshPrefix(mInstance, &iterator, &config) == OT_ERROR_NONE) { mServer->OutputFormat("%x:%x:%x:%x::/%d ", HostSwap16(config.mPrefix.mPrefix.mFields.m16[0]), @@ -2010,6 +2023,7 @@ void Interpreter::ProcessPrefix(int argc, char *argv[]) exit: AppendResult(error); } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER #if OPENTHREAD_FTD void Interpreter::ProcessReleaseRouterId(int argc, char *argv[]) @@ -2042,6 +2056,7 @@ void Interpreter::ProcessRloc16(int argc, char *argv[]) (void)argv; } +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError Interpreter::ProcessRouteAdd(int argc, char *argv[]) { otError error = OT_ERROR_NONE; @@ -2097,7 +2112,7 @@ otError Interpreter::ProcessRouteAdd(int argc, char *argv[]) } } - error = otNetDataAddRoute(mInstance, &config); + error = otBorderRouterAddRoute(mInstance, &config); exit: return error; @@ -2131,7 +2146,7 @@ otError Interpreter::ProcessRouteRemove(int argc, char *argv[]) ExitNow(error = OT_ERROR_PARSE); } - error = otNetDataRemoveRoute(mInstance, &prefix); + error = otBorderRouterRemoveRoute(mInstance, &prefix); exit: return error; @@ -2159,6 +2174,7 @@ void Interpreter::ProcessRoute(int argc, char *argv[]) exit: AppendResult(error); } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER #if OPENTHREAD_FTD void Interpreter::ProcessRouter(int argc, char *argv[]) diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 706d078f3..e0a03ff2c 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -229,7 +229,9 @@ private: void ProcessLinkQuality(int argc, char *argv[]); void ProcessMasterKey(int argc, char *argv[]); void ProcessMode(int argc, char *argv[]); +#if OPENTHREAD_ENABLE_BORDER_ROUTER void ProcessNetworkDataRegister(int argc, char *argv[]); +#endif #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC void ProcessNetworkDiagnostic(int argc, char *argv[]); #endif // OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC @@ -241,19 +243,23 @@ private: void ProcessParent(int argc, char *argv[]); void ProcessPing(int argc, char *argv[]); void ProcessPollPeriod(int argc, char *argv[]); +#if OPENTHREAD_ENABLE_BORDER_ROUTER void ProcessPrefix(int argc, char *argv[]); otError ProcessPrefixAdd(int argc, char *argv[]); otError ProcessPrefixRemove(int argc, char *argv[]); otError ProcessPrefixList(void); +#endif void ProcessPromiscuous(int argc, char *argv[]); #if OPENTHREAD_FTD void ProcessPSKc(int argc, char *argv[]); void ProcessReleaseRouterId(int argc, char *argv[]); #endif void ProcessReset(int argc, char *argv[]); +#if OPENTHREAD_ENABLE_BORDER_ROUTER void ProcessRoute(int argc, char *argv[]); otError ProcessRouteAdd(int argc, char *argv[]); otError ProcessRouteRemove(int argc, char *argv[]); +#endif #if OPENTHREAD_FTD void ProcessRouter(int argc, char *argv[]); void ProcessRouterDowngradeThreshold(int argc, char *argv[]); diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 92a56a8b7..5769addc4 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -95,6 +95,7 @@ SOURCES_COMMON = \ api/commissioner_api.cpp \ api/child_supervision_api.cpp \ api/crypto_api.cpp \ + api/border_router_api.cpp \ api/dataset_api.cpp \ api/dataset_ftd_api.cpp \ api/dhcp6_api.cpp \ @@ -279,8 +280,6 @@ HEADERS_COMMON = \ thread/network_data_leader_ftd.hpp \ thread/network_data_leader_mtd.hpp \ thread/network_data_local.hpp \ - thread/network_data_local_ftd.hpp \ - thread/network_data_local_mtd.hpp \ thread/network_data_tlvs.hpp \ thread/panid_query_server.hpp \ thread/network_diagnostic.hpp \ diff --git a/src/core/api/border_router_api.cpp b/src/core/api/border_router_api.cpp new file mode 100644 index 000000000..6b5e52808 --- /dev/null +++ b/src/core/api/border_router_api.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2016-2017, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements the OpenThread Border Router API. + */ + +#ifdef OPENTHREAD_CONFIG_FILE +#include OPENTHREAD_CONFIG_FILE +#else +#include +#endif + +#if OPENTHREAD_ENABLE_BORDER_ROUTER + +#include + +#include "openthread-instance.h" + +using namespace ot; + +otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) +{ + otError error = OT_ERROR_NONE; + + VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); + + aInstance->mThreadNetif.GetNetworkDataLocal().GetNetworkData(aStable, aData, *aDataLength); + +exit: + return error; +} + +otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig) +{ + uint8_t flags = 0; + + if (aConfig->mPreferred) + { + flags |= NetworkData::BorderRouterEntry::kPreferredFlag; + } + + if (aConfig->mSlaac) + { + flags |= NetworkData::BorderRouterEntry::kSlaacFlag; + } + + if (aConfig->mDhcp) + { + flags |= NetworkData::BorderRouterEntry::kDhcpFlag; + } + + if (aConfig->mConfigure) + { + flags |= NetworkData::BorderRouterEntry::kConfigureFlag; + } + + if (aConfig->mDefaultRoute) + { + flags |= NetworkData::BorderRouterEntry::kDefaultRouteFlag; + } + + if (aConfig->mOnMesh) + { + flags |= NetworkData::BorderRouterEntry::kOnMeshFlag; + } + + return aInstance->mThreadNetif.GetNetworkDataLocal().AddOnMeshPrefix(aConfig->mPrefix.mPrefix.mFields.m8, + aConfig->mPrefix.mLength, + aConfig->mPreference, flags, aConfig->mStable); +} + +otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix) +{ + return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveOnMeshPrefix(aPrefix->mPrefix.mFields.m8, aPrefix->mLength); +} + +otError otBorderRouterGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator, + otBorderRouterConfig *aConfig) +{ + otError error = OT_ERROR_NONE; + + VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); + + error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextOnMeshPrefix(aIterator, aConfig); + +exit: + return error; +} + +otError otBorderRouterAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig) +{ + return aInstance->mThreadNetif.GetNetworkDataLocal().AddHasRoutePrefix(aConfig->mPrefix.mPrefix.mFields.m8, + aConfig->mPrefix.mLength, + aConfig->mPreference, aConfig->mStable); +} + +otError otBorderRouterRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPrefix) +{ + return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveHasRoutePrefix(aPrefix->mPrefix.mFields.m8, + aPrefix->mLength); +} + +otError otBorderRouterGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, + otExternalRouteConfig *aConfig) +{ + otError error = OT_ERROR_NONE; + + VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); + + error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextExternalRoute(aIterator, aConfig); + +exit: + return error; +} + +otError otBorderRouterRegister(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetNetworkDataLocal().SendServerDataNotification(); +} + +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER diff --git a/src/core/api/netdata_api.cpp b/src/core/api/netdata_api.cpp index c9d8d909c..69d7d1770 100644 --- a/src/core/api/netdata_api.cpp +++ b/src/core/api/netdata_api.cpp @@ -37,7 +37,7 @@ using namespace ot; -otError otNetDataGetLeader(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) +otError otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) { otError error = OT_ERROR_NONE; @@ -49,120 +49,32 @@ exit: return error; } -otError otNetDataGetLocal(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) -{ - otError error = OT_ERROR_NONE; - - VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); - - aInstance->mThreadNetif.GetNetworkDataLocal().GetNetworkData(aStable, aData, *aDataLength); - -exit: - return error; -} - -otError otNetDataAddPrefixInfo(otInstance *aInstance, const otBorderRouterConfig *aConfig) -{ - uint8_t flags = 0; - - if (aConfig->mPreferred) - { - flags |= NetworkData::BorderRouterEntry::kPreferredFlag; - } - - if (aConfig->mSlaac) - { - flags |= NetworkData::BorderRouterEntry::kSlaacFlag; - } - - if (aConfig->mDhcp) - { - flags |= NetworkData::BorderRouterEntry::kDhcpFlag; - } - - if (aConfig->mConfigure) - { - flags |= NetworkData::BorderRouterEntry::kConfigureFlag; - } - - if (aConfig->mDefaultRoute) - { - flags |= NetworkData::BorderRouterEntry::kDefaultRouteFlag; - } - - if (aConfig->mOnMesh) - { - flags |= NetworkData::BorderRouterEntry::kOnMeshFlag; - } - - return aInstance->mThreadNetif.GetNetworkDataLocal().AddOnMeshPrefix(aConfig->mPrefix.mPrefix.mFields.m8, - aConfig->mPrefix.mLength, - aConfig->mPreference, flags, aConfig->mStable); -} - -otError otNetDataRemovePrefixInfo(otInstance *aInstance, const otIp6Prefix *aPrefix) -{ - return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveOnMeshPrefix(aPrefix->mPrefix.mFields.m8, aPrefix->mLength); -} - -otError otNetDataGetNextPrefixInfo(otInstance *aInstance, bool aLocal, otNetworkDataIterator *aIterator, - otBorderRouterConfig *aConfig) +otError otNetDataGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator, + otBorderRouterConfig *aConfig) { otError error = OT_ERROR_NONE; VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); - if (aLocal) - { - error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextOnMeshPrefix(aIterator, aConfig); - } - else - { - error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNextOnMeshPrefix(aIterator, aConfig); - } + error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNextOnMeshPrefix(aIterator, aConfig); exit: return error; } -otError otNetDataAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig) -{ - return aInstance->mThreadNetif.GetNetworkDataLocal().AddHasRoutePrefix(aConfig->mPrefix.mPrefix.mFields.m8, - aConfig->mPrefix.mLength, - aConfig->mPreference, aConfig->mStable); -} - -otError otNetDataRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPrefix) -{ - return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveHasRoutePrefix(aPrefix->mPrefix.mFields.m8, - aPrefix->mLength); -} - -otError otNetDataGetNextRoute(otInstance *aInstance, bool aLocal, otNetworkDataIterator *aIterator, +otError otNetDataGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig) { otError error = OT_ERROR_NONE; VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); - if (aLocal) - { - error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextExternalRoute(aIterator, aConfig); - } - else - { - error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNextExternalRoute(aIterator, aConfig); - } + error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNextExternalRoute(aIterator, aConfig); exit: return error; } -otError otNetDataRegister(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetNetworkDataLocal().SendServerDataNotification(); -} - uint8_t otNetDataGetVersion(otInstance *aInstance) { return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetDataVersion(); diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index 07143d5f3..996553a8f 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -108,7 +108,7 @@ void Dhcp6Client::UpdateAddresses(otInstance *aInstance, otDhcpAddress *aAddress found = false; iterator = OT_NETWORK_DATA_ITERATOR_INIT; - while ((otNetDataGetNextPrefixInfo(aInstance, false, &iterator, &config)) == OT_ERROR_NONE) + while ((otNetDataGetNextOnMeshPrefix(aInstance, &iterator, &config)) == OT_ERROR_NONE) { if (!config.mDhcp) { @@ -135,7 +135,7 @@ void Dhcp6Client::UpdateAddresses(otInstance *aInstance, otDhcpAddress *aAddress // add IdentityAssociation for new configured prefix iterator = OT_NETWORK_DATA_ITERATOR_INIT; - while (otNetDataGetNextPrefixInfo(aInstance, false, &iterator, &config) == OT_ERROR_NONE) + while (otNetDataGetNextOnMeshPrefix(aInstance, &iterator, &config) == OT_ERROR_NONE) { if (!config.mDhcp) { diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 30f98f253..eec27fc96 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -259,7 +259,9 @@ otError Mle::Stop(bool aClearNetworkDatasets) mNetif.GetKeyManager().Stop(); SetStateDetached(); mNetif.RemoveUnicastAddress(mMeshLocal16); +#if OPENTHREAD_ENABLE_BORDER_ROUTER mNetif.GetNetworkDataLocal().Clear(); +#endif mNetif.GetNetworkDataLeader().Clear(); memset(&mLeaderData, 0, sizeof(mLeaderData)); @@ -601,7 +603,9 @@ otError Mle::SetStateChild(uint16_t aRloc16) mNetif.GetMle().HandleChildStart(mParentRequestMode); } +#if OPENTHREAD_ENABLE_BORDER_ROUTER mNetif.GetNetworkDataLocal().ClearResubmitDelayTimer(); +#endif mNetif.GetIp6().SetForwardingEnabled(false); mNetif.GetIp6().mMpl.SetTimerExpirations(kMplChildDataMessageTimerExpirations); @@ -1264,7 +1268,9 @@ void Mle::HandleNetifStateChanged(uint32_t aFlags) mSendChildUpdateRequest.Post(); } +#if OPENTHREAD_ENABLE_BORDER_ROUTER mNetif.GetNetworkDataLocal().SendServerDataNotification(); +#endif } if (aFlags & (OT_NET_ROLE | OT_NET_KEY_SEQUENCE_COUNTER)) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index dd0723886..e2143fbd3 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -1503,7 +1503,9 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa UpdateRoutes(route, routerId); +#if OPENTHREAD_ENABLE_BORDER_ROUTER mNetif.GetNetworkDataLocal().SendServerDataNotification(); +#endif exit: return error; diff --git a/src/core/thread/network_data_local.cpp b/src/core/thread/network_data_local.cpp index b607a8c04..4bbabafe7 100644 --- a/src/core/thread/network_data_local.cpp +++ b/src/core/thread/network_data_local.cpp @@ -31,8 +31,6 @@ * This file implements the local Thread Network Data. */ -#if OPENTHREAD_FTD - #ifdef OPENTHREAD_CONFIG_FILE #include OPENTHREAD_CONFIG_FILE #else @@ -47,6 +45,8 @@ #include "mac/mac_frame.hpp" #include "thread/thread_netif.hpp" +#if OPENTHREAD_ENABLE_BORDER_ROUTER + namespace ot { namespace NetworkData { @@ -234,6 +234,9 @@ otError Local::SendServerDataNotification(void) otError error = OT_ERROR_NONE; uint16_t rloc = mNetif.GetMle().GetRloc16(); +#if OPENTHREAD_FTD + + // Don't send this Server Data Notification if the device is going to upgrade to Router if ((mNetif.GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD) != 0 && (mNetif.GetMle().IsRouterRoleEnabled()) && (mNetif.GetMle().GetRole() < OT_DEVICE_ROLE_ROUTER) && @@ -242,6 +245,8 @@ otError Local::SendServerDataNotification(void) ExitNow(error = OT_ERROR_INVALID_STATE); } +#endif + UpdateRloc(); VerifyOrExit(!IsOnMeshPrefixConsistent() || !IsExternalRouteConsistent(), ClearResubmitDelayTimer()); @@ -261,4 +266,4 @@ exit: } // namespace NetworkData } // namespace ot -#endif // OPENTHREAD_FTD +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER diff --git a/src/core/thread/network_data_local.hpp b/src/core/thread/network_data_local.hpp index 2363ec5d4..9dbb4e631 100644 --- a/src/core/thread/network_data_local.hpp +++ b/src/core/thread/network_data_local.hpp @@ -26,11 +26,128 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if OPENTHREAD_MTD -#include "network_data_local_mtd.hpp" -#elif OPENTHREAD_FTD -#include "network_data_local_ftd.hpp" -#else -#error "Please define OPENTHREAD_MTD=1 or OPENTHREAD_FTD=1" -#endif +/** + * @file + * This file includes definitions for manipulating local Thread Network Data. + */ +#ifndef NETWORK_DATA_LOCAL_HPP_ +#define NETWORK_DATA_LOCAL_HPP_ + +#include "thread/network_data.hpp" + +namespace ot { + +class ThreadNetif; + +/** + * @addtogroup core-netdata-local + * + * @brief + * This module includes definitions for manipulating local Thread Network Data. + * + * @{ + */ + +namespace NetworkData { + +/** + * This class implements the Thread Network Data contributed by the local device. + * + */ +class Local: public NetworkData +{ +public: + /** + * This constructor initializes the local Network Data. + * + * @param[in] aNetif A reference to the Thread network interface. + * + */ + explicit Local(ThreadNetif &aNetif); + + /** + * This method adds a Border Router entry to the Thread Network Data. + * + * @param[in] aPrefix A pointer to the prefix. + * @param[in] aPrefixLength The length of @p aPrefix in bytes. + * @param[in] aPrf The preference value. + * @param[in] aFlags The Border Router Flags value. + * @param[in] aStable The Stable value. + * + * @retval OT_ERROR_NONE Successfully added the Border Router entry. + * @retval OT_ERROR_NO_BUFS Insufficient space to add the Border Router entry. + * @retval OT_ERROR_INVALID_ARGS The prefix is mesh local prefix. + * + */ + otError AddOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, uint8_t aFlags, + bool aStable); + + /** + * This method removes a Border Router entry from the Thread Network Data. + * + * @param[in] aPrefix A pointer to the prefix. + * @param[in] aPrefixLength The length of @p aPrefix in bytes. + * + * @retval OT_ERROR_NONE Successfully removed the Border Router entry. + * @retval OT_ERROR_NOT_FOUND Could not find the Border Router entry. + * + */ + otError RemoveOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength); + + /** + * This method adds a Has Route entry to the Thread Network data. + * + * @param[in] aPrefix A pointer to the prefix. + * @param[in] aPrefixLength The length of @p aPrefix in bytes. + * @param[in] aPrf The preference value. + * @param[in] aStable The Stable value. + * + * @retval OT_ERROR_NONE Successfully added the Has Route entry. + * @retval OT_ERROR_NO_BUFS Insufficient space to add the Has Route entry. + * + */ + otError AddHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, bool aStable); + + /** + * This method removes a Border Router entry from the Thread Network Data. + * + * @param[in] aPrefix A pointer to the prefix. + * @param[in] aPrefixLength The length of @p aPrefix in bytes. + * + * @retval OT_ERROR_NONE Successfully removed the Border Router entry. + * @retval OT_ERROR_NOT_FOUND Could not find the Border Router entry. + * + */ + otError RemoveHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength); + + /** + * This method sends a Server Data Notification message to the Leader. + * + * @retval OT_ERROR_NONE Successfully enqueued the notification message. + * @retval OT_ERROR_NO_BUFS Insufficient message buffers to generate the notification message. + * + */ + otError SendServerDataNotification(void); + +private: + otError UpdateRloc(void); + otError UpdateRloc(PrefixTlv &aPrefix); + otError UpdateRloc(HasRouteTlv &aHasRoute); + otError UpdateRloc(BorderRouterTlv &aBorderRouter); + + bool IsOnMeshPrefixConsistent(void); + bool IsExternalRouteConsistent(void); + + uint16_t mOldRloc; +}; + +} // namespace NetworkData + +/** + * @} + */ + +} // namespace ot + +#endif // NETWORK_DATA_LOCAL_HPP_ diff --git a/src/core/thread/network_data_local_ftd.hpp b/src/core/thread/network_data_local_ftd.hpp deleted file mode 100644 index 9dbb4e631..000000000 --- a/src/core/thread/network_data_local_ftd.hpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file includes definitions for manipulating local Thread Network Data. - */ - -#ifndef NETWORK_DATA_LOCAL_HPP_ -#define NETWORK_DATA_LOCAL_HPP_ - -#include "thread/network_data.hpp" - -namespace ot { - -class ThreadNetif; - -/** - * @addtogroup core-netdata-local - * - * @brief - * This module includes definitions for manipulating local Thread Network Data. - * - * @{ - */ - -namespace NetworkData { - -/** - * This class implements the Thread Network Data contributed by the local device. - * - */ -class Local: public NetworkData -{ -public: - /** - * This constructor initializes the local Network Data. - * - * @param[in] aNetif A reference to the Thread network interface. - * - */ - explicit Local(ThreadNetif &aNetif); - - /** - * This method adds a Border Router entry to the Thread Network Data. - * - * @param[in] aPrefix A pointer to the prefix. - * @param[in] aPrefixLength The length of @p aPrefix in bytes. - * @param[in] aPrf The preference value. - * @param[in] aFlags The Border Router Flags value. - * @param[in] aStable The Stable value. - * - * @retval OT_ERROR_NONE Successfully added the Border Router entry. - * @retval OT_ERROR_NO_BUFS Insufficient space to add the Border Router entry. - * @retval OT_ERROR_INVALID_ARGS The prefix is mesh local prefix. - * - */ - otError AddOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, uint8_t aFlags, - bool aStable); - - /** - * This method removes a Border Router entry from the Thread Network Data. - * - * @param[in] aPrefix A pointer to the prefix. - * @param[in] aPrefixLength The length of @p aPrefix in bytes. - * - * @retval OT_ERROR_NONE Successfully removed the Border Router entry. - * @retval OT_ERROR_NOT_FOUND Could not find the Border Router entry. - * - */ - otError RemoveOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength); - - /** - * This method adds a Has Route entry to the Thread Network data. - * - * @param[in] aPrefix A pointer to the prefix. - * @param[in] aPrefixLength The length of @p aPrefix in bytes. - * @param[in] aPrf The preference value. - * @param[in] aStable The Stable value. - * - * @retval OT_ERROR_NONE Successfully added the Has Route entry. - * @retval OT_ERROR_NO_BUFS Insufficient space to add the Has Route entry. - * - */ - otError AddHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, bool aStable); - - /** - * This method removes a Border Router entry from the Thread Network Data. - * - * @param[in] aPrefix A pointer to the prefix. - * @param[in] aPrefixLength The length of @p aPrefix in bytes. - * - * @retval OT_ERROR_NONE Successfully removed the Border Router entry. - * @retval OT_ERROR_NOT_FOUND Could not find the Border Router entry. - * - */ - otError RemoveHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength); - - /** - * This method sends a Server Data Notification message to the Leader. - * - * @retval OT_ERROR_NONE Successfully enqueued the notification message. - * @retval OT_ERROR_NO_BUFS Insufficient message buffers to generate the notification message. - * - */ - otError SendServerDataNotification(void); - -private: - otError UpdateRloc(void); - otError UpdateRloc(PrefixTlv &aPrefix); - otError UpdateRloc(HasRouteTlv &aHasRoute); - otError UpdateRloc(BorderRouterTlv &aBorderRouter); - - bool IsOnMeshPrefixConsistent(void); - bool IsExternalRouteConsistent(void); - - uint16_t mOldRloc; -}; - -} // namespace NetworkData - -/** - * @} - */ - -} // namespace ot - -#endif // NETWORK_DATA_LOCAL_HPP_ diff --git a/src/core/thread/network_data_local_mtd.hpp b/src/core/thread/network_data_local_mtd.hpp deleted file mode 100644 index 382d956dd..000000000 --- a/src/core/thread/network_data_local_mtd.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file includes definitions for manipulating local Thread Network Data. - */ - -#ifndef NETWORK_DATA_LOCAL_HPP_ -#define NETWORK_DATA_LOCAL_HPP_ - -#include "thread/network_data.hpp" - -namespace ot { - -class ThreadNetif; - -namespace NetworkData { - -class Local -{ -public: - explicit Local(ThreadNetif &) { } - - void Clear(void) { } - - otError AddOnMeshPrefix(const uint8_t *, uint8_t, int8_t, uint8_t, bool) { return OT_ERROR_NOT_IMPLEMENTED; } - otError RemoveOnMeshPrefix(const uint8_t *, uint8_t) { return OT_ERROR_NOT_IMPLEMENTED; } - - otError AddHasRoutePrefix(const uint8_t *, uint8_t, int8_t, bool) { return OT_ERROR_NOT_IMPLEMENTED; } - otError RemoveHasRoutePrefix(const uint8_t *, uint8_t) { return OT_ERROR_NOT_IMPLEMENTED; } - - otError SendServerDataNotification(void) { return OT_ERROR_NOT_IMPLEMENTED; } - - void GetNetworkData(bool, uint8_t *, uint8_t &aDataLength) { aDataLength = 0; } - otError GetNextOnMeshPrefix(otNetworkDataIterator *, otBorderRouterConfig *) { return OT_ERROR_NOT_FOUND; } - otError GetNextExternalRoute(otNetworkDataIterator *, otExternalRouteConfig *) { return OT_ERROR_NOT_FOUND; } - void ClearResubmitDelayTimer(void) { } - -}; - -} // namespace NetworkData -} // namespace ot - -#endif // NETWORK_DATA_LOCAL_HPP_ diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index e698d2d44..fc5640846 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -82,7 +82,9 @@ ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6): mMac(*this), mMeshForwarder(*this), mMleRouter(*this), +#if OPENTHREAD_ENABLE_BORDER_ROUTER mNetworkDataLocal(*this), +#endif mNetworkDataLeader(*this), #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC mNetworkDiagnostic(*this), diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index b29e4d8fb..ecbedc1ac 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -258,6 +258,7 @@ public: */ MeshForwarder &GetMeshForwarder(void) { return mMeshForwarder; } +#if OPENTHREAD_ENABLE_BORDER_ROUTER /** * This method returns a reference to the network data local object. * @@ -265,6 +266,7 @@ public: * */ NetworkData::Local &GetNetworkDataLocal(void) { return mNetworkDataLocal; } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER /** * This method returns a reference to the network data leader object. @@ -427,7 +429,9 @@ private: Mac::Mac mMac; MeshForwarder mMeshForwarder; Mle::MleRouter mMleRouter; +#if OPENTHREAD_ENABLE_BORDER_ROUTER NetworkData::Local mNetworkDataLocal; +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER NetworkData::Leader mNetworkDataLeader; #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC NetworkDiagnostic::NetworkDiagnostic mNetworkDiagnostic; diff --git a/src/core/utils/slaac_address.cpp b/src/core/utils/slaac_address.cpp index 012c0c0b4..d896aaf12 100644 --- a/src/core/utils/slaac_address.cpp +++ b/src/core/utils/slaac_address.cpp @@ -71,7 +71,7 @@ void Slaac::UpdateAddresses(otInstance *aInstance, otNetifAddress *aAddresses, u iterator = OT_NETWORK_DATA_ITERATOR_INIT; - while (otNetDataGetNextPrefixInfo(aInstance, false, &iterator, &config) == OT_ERROR_NONE) + while (otNetDataGetNextOnMeshPrefix(aInstance, &iterator, &config) == OT_ERROR_NONE) { if (config.mSlaac == false) { @@ -96,7 +96,7 @@ void Slaac::UpdateAddresses(otInstance *aInstance, otNetifAddress *aAddresses, u // add addresses iterator = OT_NETWORK_DATA_ITERATOR_INIT; - while (otNetDataGetNextPrefixInfo(aInstance, false, &iterator, &config) == OT_ERROR_NONE) + while (otNetDataGetNextOnMeshPrefix(aInstance, &iterator, &config) == OT_ERROR_NONE) { bool found = false; diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 66cb1919b..6d5cd2f63 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -45,6 +45,10 @@ #include #endif +#if OPENTHREAD_ENABLE_BORDER_ROUTER +#include +#endif + #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #include #endif @@ -154,9 +158,11 @@ const NcpBase::GetPropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] = { SPINEL_PROP_THREAD_NEIGHBOR_TABLE, &NcpBase::GetPropertyHandler_THREAD_NEIGHBOR_TABLE }, { SPINEL_PROP_THREAD_LEADER_RID, &NcpBase::GetPropertyHandler_THREAD_LEADER_RID }, { SPINEL_PROP_THREAD_LEADER_WEIGHT, &NcpBase::GetPropertyHandler_THREAD_LEADER_WEIGHT }, +#if OPENTHREAD_ENABLE_BORDER_ROUTER { SPINEL_PROP_THREAD_NETWORK_DATA, &NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA }, - { SPINEL_PROP_THREAD_NETWORK_DATA_VERSION, &NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA_VERSION }, { SPINEL_PROP_THREAD_STABLE_NETWORK_DATA, &NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA }, +#endif + { SPINEL_PROP_THREAD_NETWORK_DATA_VERSION, &NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA_VERSION }, { SPINEL_PROP_THREAD_STABLE_NETWORK_DATA_VERSION, &NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA_VERSION }, { SPINEL_PROP_THREAD_LEADER_NETWORK_DATA, &NcpBase::GetPropertyHandler_THREAD_LEADER_NETWORK_DATA }, { SPINEL_PROP_THREAD_STABLE_LEADER_NETWORK_DATA, &NcpBase::GetPropertyHandler_THREAD_STABLE_LEADER_NETWORK_DATA }, @@ -326,13 +332,14 @@ const NcpBase::SetPropertyHandlerEntry NcpBase::mSetPropertyHandlerTable[] = { SPINEL_PROP_THREAD_DISCOVERY_SCAN_ENABLE_FILTERING, &NcpBase::SetPropertyHandler_THREAD_DISCOVERY_SCAN_ENABLE_FILTERING }, { SPINEL_PROP_THREAD_DISCOVERY_SCAN_PANID, &NcpBase::SetPropertyHandler_THREAD_DISCOVERY_SCAN_PANID }, - +#if OPENTHREAD_ENABLE_BORDER_ROUTER + { SPINEL_PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE, &NcpBase::SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE }, +#endif #if OPENTHREAD_FTD { SPINEL_PROP_NET_PSKC, &NcpBase::SetPropertyHandler_NET_PSKC }, { SPINEL_PROP_THREAD_CHILD_TIMEOUT, &NcpBase::SetPropertyHandler_THREAD_CHILD_TIMEOUT }, { SPINEL_PROP_THREAD_NETWORK_ID_TIMEOUT, &NcpBase::SetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT }, { SPINEL_PROP_THREAD_LOCAL_LEADER_WEIGHT, &NcpBase::SetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT }, - { SPINEL_PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE, &NcpBase::SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE }, { SPINEL_PROP_THREAD_ROUTER_ROLE_ENABLED, &NcpBase::SetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED }, { SPINEL_PROP_THREAD_CHILD_COUNT_MAX, &NcpBase::SetPropertyHandler_THREAD_CHILD_COUNT_MAX }, { SPINEL_PROP_THREAD_ROUTER_UPGRADE_THRESHOLD, &NcpBase::SetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD }, @@ -377,8 +384,10 @@ const NcpBase::InsertPropertyHandlerEntry NcpBase::mInsertPropertyHandlerTable[] { SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, &NcpBase::InsertPropertyHandler_MAC_SRC_MATCH_EXTENDED_ADDRESSES }, #endif { SPINEL_PROP_IPV6_ADDRESS_TABLE, &NcpBase::InsertPropertyHandler_IPV6_ADDRESS_TABLE }, +#if OPENTHREAD_ENABLE_BORDER_ROUTER { SPINEL_PROP_THREAD_OFF_MESH_ROUTES, &NcpBase::InsertPropertyHandler_THREAD_OFF_MESH_ROUTES }, { SPINEL_PROP_THREAD_ON_MESH_NETS, &NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS }, +#endif { SPINEL_PROP_THREAD_ASSISTING_PORTS, &NcpBase::InsertPropertyHandler_THREAD_ASSISTING_PORTS }, #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD { SPINEL_PROP_THREAD_JOINERS, &NcpBase::NcpBase::InsertPropertyHandler_THREAD_JOINERS }, @@ -397,8 +406,10 @@ const NcpBase::RemovePropertyHandlerEntry NcpBase::mRemovePropertyHandlerTable[] { SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, &NcpBase::RemovePropertyHandler_MAC_SRC_MATCH_EXTENDED_ADDRESSES }, #endif { SPINEL_PROP_IPV6_ADDRESS_TABLE, &NcpBase::RemovePropertyHandler_IPV6_ADDRESS_TABLE }, +#if OPENTHREAD_ENABLE_BORDER_ROUTER { SPINEL_PROP_THREAD_OFF_MESH_ROUTES, &NcpBase::RemovePropertyHandler_THREAD_OFF_MESH_ROUTES }, { SPINEL_PROP_THREAD_ON_MESH_NETS, &NcpBase::RemovePropertyHandler_THREAD_ON_MESH_NETS }, +#endif { SPINEL_PROP_THREAD_ASSISTING_PORTS, &NcpBase::RemovePropertyHandler_THREAD_ASSISTING_PORTS }, #if OPENTHREAD_ENABLE_MAC_WHITELIST { SPINEL_PROP_MAC_WHITELIST, &NcpBase::RemovePropertyHandler_MAC_WHITELIST }, @@ -2547,13 +2558,14 @@ otError NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA_VERSION(uint8_t h ); } +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA(uint8_t header, spinel_prop_key_t key) { otError errorCode = OT_ERROR_NONE; uint8_t network_data[255]; uint8_t network_data_len = 255; - otNetDataGetLocal( + otBorderRouterGetNetData( mInstance, false, // Stable? network_data, @@ -2581,7 +2593,7 @@ otError NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA(uint8_t header, s uint8_t network_data[255]; uint8_t network_data_len = 255; - otNetDataGetLocal( + otBorderRouterGetNetData( mInstance, true, // Stable? network_data, @@ -2602,6 +2614,7 @@ otError NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA(uint8_t header, s exit: return errorCode; } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::GetPropertyHandler_THREAD_LEADER_NETWORK_DATA(uint8_t header, spinel_prop_key_t key) { @@ -2609,7 +2622,7 @@ otError NcpBase::GetPropertyHandler_THREAD_LEADER_NETWORK_DATA(uint8_t header, s uint8_t network_data[255]; uint8_t network_data_len = 255; - otNetDataGetLeader( + otNetDataGet( mInstance, false, // Stable? network_data, @@ -2637,7 +2650,7 @@ otError NcpBase::GetPropertyHandler_THREAD_STABLE_LEADER_NETWORK_DATA(uint8_t he uint8_t network_data[255]; uint8_t network_data_len = 255; - otNetDataGetLeader( + otNetDataGet( mInstance, true, // Stable? network_data, @@ -2969,7 +2982,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spinel_p // Fill from non-local network data first for (otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT ;;) { - errorCode = otNetDataGetNextPrefixInfo(mInstance, false, &iter, &border_router_config); + errorCode = otNetDataGetNextOnMeshPrefix(mInstance, &iter, &border_router_config); if (errorCode != OT_ERROR_NONE) { @@ -2994,10 +3007,11 @@ otError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spinel_p )); } +#if OPENTHREAD_ENABLE_BORDER_ROUTER // Fill from local network data last for (otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT ;;) { - errorCode = otNetDataGetNextPrefixInfo(mInstance, true, &iter, &border_router_config); + errorCode = otBorderRouterGetNextOnMeshPrefix(mInstance, &iter, &border_router_config); if (errorCode != OT_ERROR_NONE) { @@ -3021,6 +3035,7 @@ otError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spinel_p true )); } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER SuccessOrExit(errorCode = OutboundFrameSend()); @@ -3246,7 +3261,7 @@ otError NcpBase::GetPropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spine key )); - while (otNetDataGetNextRoute(mInstance, false, &iter, &external_route_config) == OT_ERROR_NONE) + while (otNetDataGetNextRoute(mInstance, &iter, &external_route_config) == OT_ERROR_NONE) { flags = static_cast(external_route_config.mPreference); flags <<= SPINEL_NET_FLAG_PREFERENCE_OFFSET; @@ -3268,7 +3283,8 @@ otError NcpBase::GetPropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spine )); } - while (otNetDataGetNextRoute(mInstance, true, &iter, &external_route_config) == OT_ERROR_NONE) +#if OPENTHREAD_ENABLE_BORDER_ROUTER + while (otBorderRouterGetNextRoute(mInstance, &iter, &external_route_config) == OT_ERROR_NONE) { flags = static_cast(external_route_config.mPreference); flags <<= SPINEL_NET_FLAG_PREFERENCE_OFFSET; @@ -3289,6 +3305,7 @@ otError NcpBase::GetPropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spine true )); } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER SuccessOrExit(errorCode = OutboundFrameSend()); @@ -5549,7 +5566,7 @@ otError NcpBase::SetPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spine return errorCode; } -#if OPENTHREAD_FTD +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len) { @@ -5588,12 +5605,14 @@ otError NcpBase::SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(uint8_t h if (should_register_with_leader) { - otNetDataRegister(mInstance); + otBorderRouterRegister(mInstance); } return errorCode; } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER +#if OPENTHREAD_FTD otError NcpBase::SetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len) { @@ -6848,6 +6867,7 @@ exit: return errorCode; } +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::InsertPropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len) { @@ -6886,7 +6906,7 @@ otError NcpBase::InsertPropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, sp ext_route_config.mPrefix.mPrefix = *addr_ptr; ext_route_config.mStable = stable; ext_route_config.mPreference = ((flags & SPINEL_NET_FLAG_PREFERENCE_MASK) >> SPINEL_NET_FLAG_PREFERENCE_OFFSET); - errorCode = otNetDataAddRoute(mInstance, &ext_route_config); + errorCode = otBorderRouterAddRoute(mInstance, &ext_route_config); if (errorCode == OT_ERROR_NONE) { @@ -6958,7 +6978,7 @@ otError NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spine border_router_config.mDefaultRoute = ((flags & SPINEL_NET_FLAG_DEFAULT_ROUTE) != 0); border_router_config.mOnMesh = ((flags & SPINEL_NET_FLAG_ON_MESH) != 0); - errorCode = otNetDataAddPrefixInfo(mInstance, &border_router_config); + errorCode = otBorderRouterAddOnMeshPrefix(mInstance, &border_router_config); if (errorCode == OT_ERROR_NONE) { @@ -6983,6 +7003,7 @@ otError NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spine exit: return errorCode; } +#endif // OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::InsertPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len) @@ -7296,6 +7317,7 @@ otError NcpBase::RemovePropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, spinel return errorCode; } +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError NcpBase::RemovePropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len) { @@ -7325,7 +7347,7 @@ otError NcpBase::RemovePropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, sp if (parsedLength > 0) { ip6_prefix.mPrefix = *addr_ptr; - errorCode = otNetDataRemoveRoute(mInstance, &ip6_prefix); + errorCode = otBorderRouterRemoveRoute(mInstance, &ip6_prefix); if (errorCode == OT_ERROR_NONE) { @@ -7380,7 +7402,7 @@ otError NcpBase::RemovePropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spine if (parsedLength > 0) { ip6_prefix.mPrefix = *addr_ptr; - errorCode = otNetDataRemovePrefixInfo(mInstance, &ip6_prefix); + errorCode = otBorderRouterRemoveOnMeshPrefix(mInstance, &ip6_prefix); if (errorCode == OT_ERROR_NONE) { @@ -7405,6 +7427,7 @@ otError NcpBase::RemovePropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spine exit: return errorCode; } +#endif otError NcpBase::RemovePropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len) diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 1ffb93467..4fec5b90a 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -392,9 +392,11 @@ private: otError GetPropertyHandler_THREAD_NEIGHBOR_TABLE(uint8_t header, spinel_prop_key_t key); otError GetPropertyHandler_THREAD_LEADER_RID(uint8_t header, spinel_prop_key_t key); otError GetPropertyHandler_THREAD_LEADER_WEIGHT(uint8_t header, spinel_prop_key_t key); +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError GetPropertyHandler_THREAD_NETWORK_DATA(uint8_t header, spinel_prop_key_t key); - otError GetPropertyHandler_THREAD_NETWORK_DATA_VERSION(uint8_t header, spinel_prop_key_t key); otError GetPropertyHandler_THREAD_STABLE_NETWORK_DATA(uint8_t header, spinel_prop_key_t key); +#endif + otError GetPropertyHandler_THREAD_NETWORK_DATA_VERSION(uint8_t header, spinel_prop_key_t key); otError GetPropertyHandler_THREAD_STABLE_NETWORK_DATA_VERSION(uint8_t header, spinel_prop_key_t key); otError GetPropertyHandler_THREAD_LEADER_NETWORK_DATA(uint8_t header, spinel_prop_key_t key); otError GetPropertyHandler_THREAD_STABLE_LEADER_NETWORK_DATA(uint8_t header, spinel_prop_key_t key); @@ -537,6 +539,11 @@ private: otError SetPropertyHandler_THREAD_MODE(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); +#if OPENTHREAD_ENABLE_BORDER_ROUTER + otError SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(uint8_t header, spinel_prop_key_t key, + const uint8_t *value_ptr, uint16_t value_len); +#endif + #if OPENTHREAD_FTD otError SetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); @@ -556,8 +563,6 @@ private: const uint8_t *value_ptr, uint16_t value_len); otError SetPropertyHandler_THREAD_PREFERRED_ROUTER_ID(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); - otError SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(uint8_t header, spinel_prop_key_t key, - const uint8_t *value_ptr, uint16_t value_len); otError SetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); #if OPENTHREAD_CONFIG_ENABLE_STEERING_DATA_SET_OOB @@ -617,10 +622,12 @@ private: #endif otError InsertPropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError InsertPropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); otError InsertPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); +#endif otError InsertPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); #if OPENTHREAD_ENABLE_MAC_WHITELIST @@ -640,10 +647,12 @@ private: #endif otError RemovePropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); +#if OPENTHREAD_ENABLE_BORDER_ROUTER otError RemovePropertyHandler_THREAD_OFF_MESH_ROUTES(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); otError RemovePropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); +#endif otError RemovePropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len); #if OPENTHREAD_ENABLE_MAC_WHITELIST