From da9b2978ad9d47b468b6082ab1852563c4f592a5 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 17 Jan 2017 23:34:23 -0800 Subject: [PATCH] Operational Dataset API cleanup. --- etc/visual-studio/libopenthread.vcxproj | 1 + .../libopenthread.vcxproj.filters | 3 + etc/visual-studio/libopenthread_k.vcxproj | 1 + .../libopenthread_k.vcxproj.filters | 3 + examples/drivers/windows/otApi/otApi.cpp | 20 +- examples/drivers/windows/otLwf/iocontrol.c | 16 +- .../drivers/windows/otNodeApi/otNodeApi.cpp | 8 +- include/openthread.h | 143 +----------- include/openthread/Makefile.am | 1 + include/openthread/dataset.h | 205 ++++++++++++++++++ src/cli/cli.cpp | 4 +- src/cli/cli_dataset.cpp | 20 +- src/core/Makefile.am | 1 + src/core/api/dataset_api.cpp | 143 ++++++++++++ src/core/openthread.cpp | 97 --------- src/ncp/ncp_base.cpp | 2 +- 16 files changed, 394 insertions(+), 274 deletions(-) create mode 100644 include/openthread/dataset.h create mode 100644 src/core/api/dataset_api.cpp diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj index 00b6b74e1..ecc07ab63 100644 --- a/etc/visual-studio/libopenthread.vcxproj +++ b/etc/visual-studio/libopenthread.vcxproj @@ -56,6 +56,7 @@ + diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters index 6f866638f..d9059f6db 100644 --- a/etc/visual-studio/libopenthread.vcxproj.filters +++ b/etc/visual-studio/libopenthread.vcxproj.filters @@ -63,6 +63,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 22096b604..e2ecc321e 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj +++ b/etc/visual-studio/libopenthread_k.vcxproj @@ -65,6 +65,7 @@ + diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters index b1bffd702..39466d959 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj.filters +++ b/etc/visual-studio/libopenthread_k.vcxproj.filters @@ -63,6 +63,9 @@ Source Files\api + + Source Files\api + Source Files\api diff --git a/examples/drivers/windows/otApi/otApi.cpp b/examples/drivers/windows/otApi/otApi.cpp index ea61dfb9c..20e12924e 100644 --- a/examples/drivers/windows/otApi/otApi.cpp +++ b/examples/drivers/windows/otApi/otApi.cpp @@ -1412,7 +1412,7 @@ otLinkSetChannel( OTAPI ThreadError OTCALL -otSetDelayTimerMinimal( +otDatasetSetDelayTimerMinimal( _In_ otInstance *aInstance, uint32_t aDelayTimerMinimal ) @@ -1426,7 +1426,7 @@ otSetDelayTimerMinimal( OTAPI uint32_t OTCALL -otGetDelayTimerMinimal( +otDatasetGetDelayTimerMinimal( _In_ otInstance *aInstance ) { @@ -2180,7 +2180,7 @@ otRemoveStateChangeCallback( OTAPI ThreadError OTCALL -otGetActiveDataset( +otDatasetGetActive( _In_ otInstance *aInstance, _Out_ otOperationalDataset *aDataset ) @@ -2192,7 +2192,7 @@ otGetActiveDataset( OTAPI ThreadError OTCALL -otSetActiveDataset( +otDatasetSetActive( _In_ otInstance *aInstance, const otOperationalDataset *aDataset ) @@ -2204,7 +2204,7 @@ otSetActiveDataset( OTAPI ThreadError OTCALL -otGetPendingDataset( +otDatasetGetPending( _In_ otInstance *aInstance, _Out_ otOperationalDataset *aDataset ) @@ -2216,7 +2216,7 @@ otGetPendingDataset( OTAPI ThreadError OTCALL -otSetPendingDataset( +otDatasetSetPending( _In_ otInstance *aInstance, const otOperationalDataset *aDataset ) @@ -2228,7 +2228,7 @@ otSetPendingDataset( OTAPI ThreadError OTCALL -otSendActiveGet( +otDatasetSendMgmtActiveGet( _In_ otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, @@ -2260,7 +2260,7 @@ otSendActiveGet( OTAPI ThreadError OTCALL -otSendActiveSet( +otDatasetSendMgmtActiveSet( _In_ otInstance *aInstance, const otOperationalDataset *aDataset, const uint8_t *aTlvs, @@ -2290,7 +2290,7 @@ otSendActiveSet( OTAPI ThreadError OTCALL -otSendPendingGet( +otDatasetSendMgmtPendingGet( _In_ otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, @@ -2322,7 +2322,7 @@ otSendPendingGet( OTAPI ThreadError OTCALL -otSendPendingSet( +otDatasetSendMgmtPendingSet( _In_ otInstance *aInstance, const otOperationalDataset *aDataset, const uint8_t *aTlvs, diff --git a/examples/drivers/windows/otLwf/iocontrol.c b/examples/drivers/windows/otLwf/iocontrol.c index a4c75ec3c..e25f83835 100644 --- a/examples/drivers/windows/otLwf/iocontrol.c +++ b/examples/drivers/windows/otLwf/iocontrol.c @@ -2327,12 +2327,12 @@ otLwfIoCtl_otActiveDataset( if (InBufferLength >= sizeof(otOperationalDataset)) { - status = ThreadErrorToNtstatus(otSetActiveDataset(pFilter->otCtx, (otOperationalDataset*)InBuffer)); + status = ThreadErrorToNtstatus(otDatasetSetActive(pFilter->otCtx, (otOperationalDataset*)InBuffer)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otOperationalDataset)) { - status = ThreadErrorToNtstatus(otGetActiveDataset(pFilter->otCtx, (otOperationalDataset*)OutBuffer)); + status = ThreadErrorToNtstatus(otDatasetGetActive(pFilter->otCtx, (otOperationalDataset*)OutBuffer)); *OutBufferLength = sizeof(otOperationalDataset); } else @@ -2359,12 +2359,12 @@ otLwfIoCtl_otPendingDataset( if (InBufferLength >= sizeof(otOperationalDataset)) { - status = ThreadErrorToNtstatus(otSetPendingDataset(pFilter->otCtx, (otOperationalDataset*)InBuffer)); + status = ThreadErrorToNtstatus(otDatasetSetPending(pFilter->otCtx, (otOperationalDataset*)InBuffer)); *OutBufferLength = 0; } else if (*OutBufferLength >= sizeof(otOperationalDataset)) { - status = ThreadErrorToNtstatus(otGetPendingDataset(pFilter->otCtx, (otOperationalDataset*)OutBuffer)); + status = ThreadErrorToNtstatus(otDatasetGetPending(pFilter->otCtx, (otOperationalDataset*)OutBuffer)); *OutBufferLength = sizeof(otOperationalDataset); } else @@ -5753,7 +5753,7 @@ otLwfIoCtl_otSendActiveGet( aAddress = (otIp6Address*)(InBuffer + sizeof(uint8_t) + aLength); status = ThreadErrorToNtstatus( - otSendActiveGet( + otDatasetSendMgmtActiveGet( pFilter->otCtx, aTlvTypes, aLength, @@ -5791,7 +5791,7 @@ otLwfIoCtl_otSendActiveSet( if (InBufferLength >= sizeof(otOperationalDataset) + sizeof(uint8_t) + aLength) { status = ThreadErrorToNtstatus( - otSendActiveSet( + otDatasetSendMgmtActiveSet( pFilter->otCtx, aDataset, aTlvTypes, @@ -5832,7 +5832,7 @@ otLwfIoCtl_otSendPendingGet( aAddress = (otIp6Address*)(InBuffer + sizeof(uint8_t) + aLength); status = ThreadErrorToNtstatus( - otSendPendingGet( + otDatasetSendMgmtPendingGet( pFilter->otCtx, aTlvTypes, aLength, @@ -5870,7 +5870,7 @@ otLwfIoCtl_otSendPendingSet( if (InBufferLength >= sizeof(otOperationalDataset) + sizeof(uint8_t) + aLength) { status = ThreadErrorToNtstatus( - otSendPendingSet( + otDatasetSendMgmtPendingSet( pFilter->otCtx, aDataset, aTlvTypes, diff --git a/examples/drivers/windows/otNodeApi/otNodeApi.cpp b/examples/drivers/windows/otNodeApi/otNodeApi.cpp index a8ac4aa97..00f515827 100644 --- a/examples/drivers/windows/otNodeApi/otNodeApi.cpp +++ b/examples/drivers/windows/otNodeApi/otNodeApi.cpp @@ -1949,7 +1949,7 @@ OTNODEAPI int32_t OTCALL otNodeSetActiveDataset(otNode* aNode, uint64_t aTimesta aDataset.mIsMasterKeySet = true; } - auto result = otSetActiveDataset(aNode->mInstance, &aDataset); + auto result = otDatasetSetActive(aNode->mInstance, &aDataset); otLogFuncExit(); return result; } @@ -1985,7 +1985,7 @@ OTNODEAPI int32_t OTCALL otNodeSetPendingDataset(otNode* aNode, uint64_t aActive aDataset.mIsChannelSet = true; } - auto result = otSetPendingDataset(aNode->mInstance, &aDataset); + auto result = otDatasetSetPending(aNode->mInstance, &aDataset); otLogFuncExit(); return result; } @@ -2053,7 +2053,7 @@ OTNODEAPI int32_t OTCALL otNodeSendPendingSet(otNode* aNode, uint64_t aActiveTim aDataset.mIsNetworkNameSet = true; } - auto result = otSendPendingSet(aNode->mInstance, &aDataset, nullptr, 0); + auto result = otDatasetSendMgmtPendingSet(aNode->mInstance, &aDataset, nullptr, 0); otLogFuncExit(); return result; } @@ -2138,7 +2138,7 @@ OTNODEAPI int32_t OTCALL otNodeSendActiveSet(otNode* aNode, uint64_t aActiveTime tlvsLength = (uint8_t)length; } - auto result = otSendActiveSet(aNode->mInstance, &aDataset, tlvsLength == 0 ? nullptr : tlvs, tlvsLength); + auto result = otDatasetSendMgmtActiveSet(aNode->mInstance, &aDataset, tlvsLength == 0 ? nullptr : tlvs, tlvsLength); otLogFuncExit(); return result; } diff --git a/include/openthread.h b/include/openthread.h index f7e3dd5c8..5eb4a64e2 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -38,6 +38,7 @@ #include #include "openthread/crypto.h" +#include "openthread/dataset.h" #include "openthread/ip6.h" #include "openthread/link.h" #include "openthread/message.h" @@ -368,28 +369,6 @@ OTAPI bool OTCALL otIsDiscoverInProgress(otInstance *aInstance); * */ -/** - * Set minimal delay timer. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms). - * - * @retval kThreadError_None Successfully set minimal delay timer. - * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid. - * - */ -OTAPI ThreadError OTCALL otSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal); - -/** - * Get minimal delay timer. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @retval the value of minimal delay timer (in ms). - * - */ -OTAPI uint32_t OTCALL otGetDelayTimerMinimal(otInstance *aInstance); - /** * Get the maximum number of children currently allowed. * @@ -621,126 +600,6 @@ OTAPI ThreadError OTCALL otSetStateChangedCallback(otInstance *aInstance, otStat OTAPI void OTCALL otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aCallbackContext); -/** - * This function gets the Active Operational Dataset. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aDataset A pointer to where the Active Operational Dataset will be placed. - * - * @retval kThreadError_None Successfully retrieved the Active Operational Dataset. - * @retval kThreadError_InvalidArgs @p aDataset was NULL. - * - */ -OTAPI ThreadError OTCALL otGetActiveDataset(otInstance *aInstance, otOperationalDataset *aDataset); - -/** - * This function sets the Active Operational Dataset. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDataset A pointer to the Active Operational Dataset. - * - * @retval kThreadError_None Successfully set the Active Operational Dataset. - * @retval kThreadError_NoBufs Insufficient buffer space to set the Active Operational Datset. - * @retval kThreadError_InvalidArgs @p aDataset was NULL. - * - */ -OTAPI ThreadError OTCALL otSetActiveDataset(otInstance *aInstance, const otOperationalDataset *aDataset); - -/** - * This function indicates whether a valid network is present in the Active Operational Dataset or not. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns TRUE if a valid network is present in the Active Operational Dataset, FALSE otherwise. - * - */ -OTAPI bool OTCALL otIsNodeCommissioned(otInstance *aInstance); - -/** - * This function gets the Pending Operational Dataset. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[out] aDataset A pointer to where the Pending Operational Dataset will be placed. - * - * @retval kThreadError_None Successfully retrieved the Pending Operational Dataset. - * @retval kThreadError_InvalidArgs @p aDataset was NULL. - * - */ -OTAPI ThreadError OTCALL otGetPendingDataset(otInstance *aInstance, otOperationalDataset *aDataset); - -/** - * This function sets the Pending Operational Dataset. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDataset A pointer to the Pending Operational Dataset. - * - * @retval kThreadError_None Successfully set the Pending Operational Dataset. - * @retval kThreadError_NoBufs Insufficient buffer space to set the Pending Operational Dataset. - * @retval kThreadError_InvalidArgs @p aDataset was NULL. - * - */ -OTAPI ThreadError OTCALL otSetPendingDataset(otInstance *aInstance, const otOperationalDataset *aDataset); - -/** - * This function sends MGMT_ACTIVE_GET. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aTlvTypes A pointer to the TLV Types. - * @param[in] aLength The length of TLV Types. - * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default. - * - * @retval kThreadError_None Successfully send the meshcop dataset command. - * @retval kThreadError_NoBufs Insufficient buffer space to send. - * - */ -OTAPI ThreadError OTCALL otSendActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, - const otIp6Address *aAddress); - -/** - * This function sends MGMT_ACTIVE_SET. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDataset A pointer to operational dataset. - * @param[in] aTlvs A pointer to TLVs. - * @param[in] aLength The length of TLVs. - * - * @retval kThreadError_None Successfully send the meshcop dataset command. - * @retval kThreadError_NoBufs Insufficient buffer space to send. - * - */ -OTAPI ThreadError OTCALL otSendActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset, - const uint8_t *aTlvs, uint8_t aLength); - -/** - * This function sends MGMT_PENDING_GET. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aTlvTypes A pointer to the TLV Types. - * @param[in] aLength The length of TLV Types. - * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default. - * - * @retval kThreadError_None Successfully send the meshcop dataset command. - * @retval kThreadError_NoBufs Insufficient buffer space to send. - * - */ -OTAPI ThreadError OTCALL otSendPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, - const otIp6Address *aAddress); - -/** - * This function sends MGMT_PENDING_SET. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aDataset A pointer to operational dataset. - * @param[in] aTlvs A pointer to TLVs. - * @param[in] aLength The length of TLVs. - * - * @retval kThreadError_None Successfully send the meshcop dataset command. - * @retval kThreadError_NoBufs Insufficient buffer space to send. - * - */ -OTAPI ThreadError OTCALL otSendPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset, - const uint8_t *aTlvs, uint8_t aLength); - /** * Set the preferred Router Id. * diff --git a/include/openthread/Makefile.am b/include/openthread/Makefile.am index cbc310acd..7c908ee6d 100644 --- a/include/openthread/Makefile.am +++ b/include/openthread/Makefile.am @@ -32,6 +32,7 @@ openthread_headers = \ coap.h \ commissioner.h \ crypto.h \ + dataset.h \ dhcp6_client.h \ dhcp6_server.h \ ip6.h \ diff --git a/include/openthread/dataset.h b/include/openthread/dataset.h new file mode 100644 index 000000000..b27ce9cff --- /dev/null +++ b/include/openthread/dataset.h @@ -0,0 +1,205 @@ +/* + * 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 + * @brief + * This file defines the OpenThread Operational Dataset API. + */ + +#ifndef OPENTHREAD_DATASET_H_ +#define OPENTHREAD_DATASET_H_ + +#include "openthread-types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup dataset Operational Dataset + * + * @brief + * This module includes functions for Operational Dataset configuration. + * + * @{ + * + */ + +/** + * This function indicates whether a valid network is present in the Active Operational Dataset or not. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns TRUE if a valid network is present in the Active Operational Dataset, FALSE otherwise. + * + */ +OTAPI bool OTCALL otDatasetIsCommissioned(otInstance *aInstance); + +/** + * This function gets the Active Operational Dataset. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aDataset A pointer to where the Active Operational Dataset will be placed. + * + * @retval kThreadError_None Successfully retrieved the Active Operational Dataset. + * @retval kThreadError_InvalidArgs @p aDataset was NULL. + * + */ +OTAPI ThreadError OTCALL otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset); + +/** + * This function sets the Active Operational Dataset. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDataset A pointer to the Active Operational Dataset. + * + * @retval kThreadError_None Successfully set the Active Operational Dataset. + * @retval kThreadError_NoBufs Insufficient buffer space to set the Active Operational Datset. + * @retval kThreadError_InvalidArgs @p aDataset was NULL. + * + */ +OTAPI ThreadError OTCALL otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset); + +/** + * This function gets the Pending Operational Dataset. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aDataset A pointer to where the Pending Operational Dataset will be placed. + * + * @retval kThreadError_None Successfully retrieved the Pending Operational Dataset. + * @retval kThreadError_InvalidArgs @p aDataset was NULL. + * + */ +OTAPI ThreadError OTCALL otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset); + +/** + * This function sets the Pending Operational Dataset. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDataset A pointer to the Pending Operational Dataset. + * + * @retval kThreadError_None Successfully set the Pending Operational Dataset. + * @retval kThreadError_NoBufs Insufficient buffer space to set the Pending Operational Dataset. + * @retval kThreadError_InvalidArgs @p aDataset was NULL. + * + */ +OTAPI ThreadError OTCALL otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset); + +/** + * This function sends MGMT_ACTIVE_GET. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aTlvTypes A pointer to the TLV Types. + * @param[in] aLength The length of TLV Types. + * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default. + * + * @retval kThreadError_None Successfully send the meshcop dataset command. + * @retval kThreadError_NoBufs Insufficient buffer space to send. + * + */ +OTAPI ThreadError OTCALL otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, + const otIp6Address *aAddress); + +/** + * This function sends MGMT_ACTIVE_SET. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDataset A pointer to operational dataset. + * @param[in] aTlvs A pointer to TLVs. + * @param[in] aLength The length of TLVs. + * + * @retval kThreadError_None Successfully send the meshcop dataset command. + * @retval kThreadError_NoBufs Insufficient buffer space to send. + * + */ +OTAPI ThreadError OTCALL otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset, + const uint8_t *aTlvs, uint8_t aLength); + +/** + * This function sends MGMT_PENDING_GET. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aTlvTypes A pointer to the TLV Types. + * @param[in] aLength The length of TLV Types. + * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default. + * + * @retval kThreadError_None Successfully send the meshcop dataset command. + * @retval kThreadError_NoBufs Insufficient buffer space to send. + * + */ +OTAPI ThreadError OTCALL otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, + const otIp6Address *aAddress); + +/** + * This function sends MGMT_PENDING_SET. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDataset A pointer to operational dataset. + * @param[in] aTlvs A pointer to TLVs. + * @param[in] aLength The length of TLVs. + * + * @retval kThreadError_None Successfully send the meshcop dataset command. + * @retval kThreadError_NoBufs Insufficient buffer space to send. + * + */ +OTAPI ThreadError OTCALL otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset, + const uint8_t *aTlvs, uint8_t aLength); + +/** + * Get minimal delay timer. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval the value of minimal delay timer (in ms). + * + */ +OTAPI uint32_t OTCALL otDatasetGetDelayTimerMinimal(otInstance *aInstance); + +/** + * Set minimal delay timer. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms). + * + * @retval kThreadError_None Successfully set minimal delay timer. + * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid. + * + */ +OTAPI ThreadError OTCALL otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal); + +/** + * @} + * + */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OPENTHREAD_DATASET_H_ diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index eacdfaa81..9115885dd 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -668,13 +668,13 @@ void Interpreter::ProcessDelayTimerMin(int argc, char *argv[]) if (argc == 0) { - sServer->OutputFormat("%d\r\n", (otGetDelayTimerMinimal(mInstance) / 1000)); + sServer->OutputFormat("%d\r\n", (otDatasetGetDelayTimerMinimal(mInstance) / 1000)); } else if (argc == 1) { unsigned long value; SuccessOrExit(error = ParseUnsignedLong(argv[0], value)); - SuccessOrExit(error = otSetDelayTimerMinimal(mInstance, static_cast(value * 1000))); + SuccessOrExit(error = otDatasetSetDelayTimerMinimal(mInstance, static_cast(value * 1000))); } else { diff --git a/src/cli/cli_dataset.cpp b/src/cli/cli_dataset.cpp index 75c359551..1d9787296 100644 --- a/src/cli/cli_dataset.cpp +++ b/src/cli/cli_dataset.cpp @@ -227,7 +227,7 @@ ThreadError Dataset::ProcessHelp(otInstance *aInstance, int argc, char *argv[]) ThreadError Dataset::ProcessActive(otInstance *aInstance, int argc, char *argv[]) { otOperationalDataset dataset; - otGetActiveDataset(aInstance, &dataset); + otDatasetGetActive(aInstance, &dataset); (void)argc; (void)argv; @@ -298,11 +298,11 @@ ThreadError Dataset::ProcessCommit(otInstance *aInstance, int argc, char *argv[] if (strcmp(argv[0], "active") == 0) { - SuccessOrExit(error = otSetActiveDataset(aInstance, &sDataset)); + SuccessOrExit(error = otDatasetSetActive(aInstance, &sDataset)); } else if (strcmp(argv[0], "pending") == 0) { - SuccessOrExit(error = otSetPendingDataset(aInstance, &sDataset)); + SuccessOrExit(error = otDatasetSetPending(aInstance, &sDataset)); } else { @@ -421,7 +421,7 @@ exit: ThreadError Dataset::ProcessPending(otInstance *aInstance, int argc, char *argv[]) { otOperationalDataset dataset; - otGetPendingDataset(aInstance, &dataset); + otDatasetGetPending(aInstance, &dataset); (void)argc; (void)argv; @@ -549,11 +549,11 @@ ThreadError Dataset::ProcessMgmtSetCommand(otInstance *aInstance, int argc, char if (strcmp(argv[0], "active") == 0) { - SuccessOrExit(error = otSendActiveSet(aInstance, &dataset, tlvs, static_cast(length))); + SuccessOrExit(error = otDatasetSendMgmtActiveSet(aInstance, &dataset, tlvs, static_cast(length))); } else if (strcmp(argv[0], "pending") == 0) { - SuccessOrExit(error = otSendPendingSet(aInstance, &dataset, tlvs, static_cast(length))); + SuccessOrExit(error = otDatasetSendMgmtPendingSet(aInstance, &dataset, tlvs, static_cast(length))); } else { @@ -643,13 +643,13 @@ ThreadError Dataset::ProcessMgmtGetCommand(otInstance *aInstance, int argc, char if (strcmp(argv[0], "active") == 0) { - SuccessOrExit(error = otSendActiveGet(aInstance, tlvs, static_cast(length), - destAddrSpecified ? &address : NULL)); + SuccessOrExit(error = otDatasetSendMgmtActiveGet(aInstance, tlvs, static_cast(length), + destAddrSpecified ? &address : NULL)); } else if (strcmp(argv[0], "pending") == 0) { - SuccessOrExit(error = otSendPendingGet(aInstance, tlvs, static_cast(length), - destAddrSpecified ? &address : NULL)); + SuccessOrExit(error = otDatasetSendMgmtPendingGet(aInstance, tlvs, static_cast(length), + destAddrSpecified ? &address : NULL)); } else { diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 6177108cf..75bfa4a97 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -41,6 +41,7 @@ CPPFLAGS_COMMON = \ SOURCES_COMMON = \ openthread.cpp \ api/crypto_api.cpp \ + api/dataset_api.cpp \ api/ip6_api.cpp \ api/link_api.cpp \ api/message_api.cpp \ diff --git a/src/core/api/dataset_api.cpp b/src/core/api/dataset_api.cpp new file mode 100644 index 000000000..c9f239dea --- /dev/null +++ b/src/core/api/dataset_api.cpp @@ -0,0 +1,143 @@ +/* + * 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 implements the OpenThread Operational Dataset API. + */ + +#include "openthread/dataset.h" + +#include "openthread-instance.h" + +using namespace Thread; + +#ifdef __cplusplus +extern "C" { +#endif + +bool otDatasetIsCommissioned(otInstance *aInstance) +{ + otOperationalDataset dataset; + + otDatasetGetActive(aInstance, &dataset); + + if ((dataset.mIsMasterKeySet) && (dataset.mIsNetworkNameSet) && + (dataset.mIsExtendedPanIdSet) && (dataset.mIsPanIdSet) && (dataset.mIsChannelSet)) + { + return true; + } + + return false; +} + +ThreadError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset) +{ + ThreadError error = kThreadError_None; + + VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); + + aInstance->mThreadNetif.GetActiveDataset().GetLocal().Get(*aDataset); + +exit: + return error; +} + +ThreadError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset) +{ + ThreadError error; + + VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetActiveDataset().Set(*aDataset); + +exit: + return error; +} + +ThreadError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset) +{ + ThreadError error = kThreadError_None; + + VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); + + aInstance->mThreadNetif.GetPendingDataset().GetLocal().Get(*aDataset); + +exit: + return error; +} + +ThreadError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset) +{ + ThreadError error; + + VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); + + error = aInstance->mThreadNetif.GetPendingDataset().Set(*aDataset); + +exit: + return error; +} + +ThreadError otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, + const otIp6Address *aAddress) +{ + return aInstance->mThreadNetif.GetActiveDataset().SendGetRequest(aTlvTypes, aLength, aAddress); +} + +ThreadError otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset, + const uint8_t *aTlvs, uint8_t aLength) +{ + return aInstance->mThreadNetif.GetActiveDataset().SendSetRequest(*aDataset, aTlvs, aLength); +} + +ThreadError otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, + const otIp6Address *aAddress) +{ + return aInstance->mThreadNetif.GetPendingDataset().SendGetRequest(aTlvTypes, aLength, aAddress); +} + +ThreadError otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset, + const uint8_t *aTlvs, uint8_t aLength) +{ + return aInstance->mThreadNetif.GetPendingDataset().SendSetRequest(*aDataset, aTlvs, aLength); +} + +uint32_t otDatasetGetDelayTimerMinimal(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetLeader().GetDelayTimerMinimal(); +} + +ThreadError otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal) +{ + return aInstance->mThreadNetif.GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 5191d4b77..a35b0407c 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -88,16 +88,6 @@ otInstance::otInstance(void) : extern "C" { #endif -ThreadError otSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal) -{ - return aInstance->mThreadNetif.GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal); -} - -uint32_t otGetDelayTimerMinimal(otInstance *aInstance) -{ - return aInstance->mThreadNetif.GetLeader().GetDelayTimerMinimal(); -} - uint8_t otGetMaxAllowedChildren(otInstance *aInstance) { uint8_t aNumChildren; @@ -877,93 +867,6 @@ ThreadError otIcmp6SendEchoRequest(otInstance *aInstance, otMessage aMessage, aIdentifier); } -ThreadError otGetActiveDataset(otInstance *aInstance, otOperationalDataset *aDataset) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); - - aInstance->mThreadNetif.GetActiveDataset().GetLocal().Get(*aDataset); - -exit: - return error; -} - -ThreadError otSetActiveDataset(otInstance *aInstance, const otOperationalDataset *aDataset) -{ - ThreadError error; - - VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetActiveDataset().Set(*aDataset); - -exit: - return error; -} - -bool otIsNodeCommissioned(otInstance *aInstance) -{ - otOperationalDataset dataset; - - otGetActiveDataset(aInstance, &dataset); - - if ((dataset.mIsMasterKeySet) && (dataset.mIsNetworkNameSet) && - (dataset.mIsExtendedPanIdSet) && (dataset.mIsPanIdSet) && (dataset.mIsChannelSet)) - { - return true; - } - - return false; -} - -ThreadError otGetPendingDataset(otInstance *aInstance, otOperationalDataset *aDataset) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); - - aInstance->mThreadNetif.GetPendingDataset().GetLocal().Get(*aDataset); - -exit: - return error; -} - -ThreadError otSetPendingDataset(otInstance *aInstance, const otOperationalDataset *aDataset) -{ - ThreadError error; - - VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs); - - error = aInstance->mThreadNetif.GetPendingDataset().Set(*aDataset); - -exit: - return error; -} - -ThreadError otSendActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, - const otIp6Address *aAddress) -{ - return aInstance->mThreadNetif.GetActiveDataset().SendGetRequest(aTlvTypes, aLength, aAddress); -} - -ThreadError otSendActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset, const uint8_t *aTlvs, - uint8_t aLength) -{ - return aInstance->mThreadNetif.GetActiveDataset().SendSetRequest(*aDataset, aTlvs, aLength); -} - -ThreadError otSendPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, - const otIp6Address *aAddress) -{ - return aInstance->mThreadNetif.GetPendingDataset().SendGetRequest(aTlvTypes, aLength, aAddress); -} - -ThreadError otSendPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset, const uint8_t *aTlvs, - uint8_t aLength) -{ - return aInstance->mThreadNetif.GetPendingDataset().SendSetRequest(*aDataset, aTlvs, aLength); -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 378ab59c8..a5da509d0 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -2055,7 +2055,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_SAVED(uint8_t header, spinel_prop_ke SPINEL_CMD_PROP_VALUE_IS, key, SPINEL_DATATYPE_BOOL_S, - otIsNodeCommissioned(mInstance) + otDatasetIsCommissioned(mInstance) ); }