From c9c203bbed6afed97325afc356432ddb4ef4ea72 Mon Sep 17 00:00:00 2001 From: Kamil Burzynski Date: Mon, 27 Nov 2017 23:20:55 +0100 Subject: [PATCH] [network-data] added support for iterating over services from leader data (#2368) --- include/openthread/server.h | 15 +++++++++++++++ include/openthread/types.h | 5 +++++ src/core/api/server_api.cpp | 14 ++++++++++++++ src/core/thread/network_data.cpp | 1 + 4 files changed, 35 insertions(+) diff --git a/include/openthread/server.h b/include/openthread/server.h index 1d3a9a6d3..af3ed7649 100644 --- a/include/openthread/server.h +++ b/include/openthread/server.h @@ -110,6 +110,21 @@ OTAPI otError OTCALL otServerRemoveService(otInstance *aInstance, uint32_t aEnte OTAPI otError OTCALL otServerGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig); +/** + * This function gets the next service in the leader 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 service entry + it should be set to OT_NETWORK_DATA_ITERATOR_INIT. + * @param[out] aConfig A pointer to where the service information will be placed. + * + * @retval OT_ERROR_NONE Successfully found the next service. + * @retval OT_ERROR_NOT_FOUND No subsequent service exists in the leader Network Data. + * + */ +OTAPI otError OTCALL otServerGetNextLeaderService(otInstance *aInstance, otNetworkDataIterator *aIterator, + otServiceConfig *aConfig); + /** * Immediately register the local network data with the Leader. * diff --git a/include/openthread/types.h b/include/openthread/types.h index 0102664ba..1d9b2a09c 100644 --- a/include/openthread/types.h +++ b/include/openthread/types.h @@ -856,6 +856,11 @@ typedef struct otServerConfig */ typedef struct otServiceConfig { + /** + * Service ID. This field is used to return service ID when iterating over network data from leader. + */ + uint8_t mServiceID; + /** * IANA Enterprise Number. */ diff --git a/src/core/api/server_api.cpp b/src/core/api/server_api.cpp index 166d4c6f5..71549107b 100644 --- a/src/core/api/server_api.cpp +++ b/src/core/api/server_api.cpp @@ -87,6 +87,20 @@ exit: return error; } +otError otServerGetNextLeaderService(otInstance *aInstance, otNetworkDataIterator *aIterator, + otServiceConfig *aConfig) +{ + otError error = OT_ERROR_NONE; + Instance &instance = *static_cast(aInstance); + + VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); + + error = instance.GetThreadNetif().GetNetworkDataLeader().GetNextService(aIterator, aConfig); + +exit: + return error; +} + otError otServerRegister(otInstance *aInstance) { Instance &instance = *static_cast(aInstance); diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index 3d2f367dc..84fa1e083 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -285,6 +285,7 @@ otError NetworkData::GetNextService(otNetworkDataIterator *aIterator, uint16_t a { memset(aConfig, 0, sizeof(*aConfig)); + aConfig->mServiceID = service->GetServiceID(); aConfig->mEnterpriseNumber = service->GetEnterpriseNumber(); aConfig->mServiceDataLength = service->GetServiceDataLength();