From fffd5bac8c64db296e6ece1c0208743d1f532695 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 15 Mar 2023 18:36:39 -0700 Subject: [PATCH] [dataset] add `otDatasetUpdateTlvs` API (#8871) --- include/openthread/dataset.h | 15 +++++++++++++++ include/openthread/instance.h | 2 +- src/core/api/dataset_api.cpp | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/openthread/dataset.h b/include/openthread/dataset.h index f5f42808b..ac034364b 100644 --- a/include/openthread/dataset.h +++ b/include/openthread/dataset.h @@ -606,6 +606,21 @@ otError otDatasetParseTlvs(const otOperationalDatasetTlvs *aDatasetTlvs, otOpera */ otError otDatasetConvertToTlvs(const otOperationalDataset *aDataset, otOperationalDatasetTlvs *aDatasetTlvs); +/** + * Updates a given Operational Dataset. + * + * @p aDataset contains the fields to be updated and their new value. + * + * @param[in] aDataset Specifies the set of types and values to update. + * @param[in,out] aDatasetTlvs A pointer to dataset TLVs to update. + * + * @retval OT_ERROR_NONE Successfully updated @p aDatasetTlvs. + * @retval OT_ERROR_INVALID_ARGS @p aDataset contains invalid values. + * @retval OT_ERROR_NO_BUFS Not enough space space in @p aDatasetTlvs to apply the update. + * + */ +otError otDatasetUpdateTlvs(const otOperationalDataset *aDataset, otOperationalDatasetTlvs *aDatasetTlvs); + /** * @} * diff --git a/include/openthread/instance.h b/include/openthread/instance.h index d17c4a3dc..87ce6f735 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (299) +#define OPENTHREAD_API_VERSION (300) /** * @addtogroup api-instance diff --git a/src/core/api/dataset_api.cpp b/src/core/api/dataset_api.cpp index 612ed5c6a..7e4c0d42d 100644 --- a/src/core/api/dataset_api.cpp +++ b/src/core/api/dataset_api.cpp @@ -182,3 +182,18 @@ otError otDatasetConvertToTlvs(const otOperationalDataset *aDataset, otOperation exit: return error; } + +otError otDatasetUpdateTlvs(const otOperationalDataset *aDataset, otOperationalDatasetTlvs *aDatasetTlvs) +{ + Error error = kErrorNone; + MeshCoP::Dataset dataset; + + AssertPointerIsNotNull(aDatasetTlvs); + + dataset.SetFrom(*aDatasetTlvs); + SuccessOrExit(error = dataset.SetFrom(AsCoreType(aDataset))); + dataset.ConvertTo(*aDatasetTlvs); + +exit: + return error; +}