1 /*
2  *  Copyright (c) 2020, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * @brief
32  *   This file includes the OpenThread API for Dataset Updater module.
33  */
34 
35 #ifndef OPENTHREAD_DATASET_UPDATER_H_
36 #define OPENTHREAD_DATASET_UPDATER_H_
37 
38 #include <openthread/dataset.h>
39 #include <openthread/instance.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @addtogroup api-operational-dataset
47  *
48  * @{
49  *
50  * For FTD builds only, Dataset Updater includes functions to manage dataset updates.
51  */
52 
53 /**
54  * This callback function pointer is called when a Dataset update request finishes, reporting success or failure status
55  * of the Dataset update request.
56  *
57  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
58  *
59  * @param[in] aError   The error status.
60  *                     OT_ERROR_NONE            indicates successful Dataset update.
61  *                     OT_ERROR_INVALID_STATE   indicates failure due invalid state (MLE being disabled).
62  *                     OT_ERROR_ALREADY         indicates failure due to another device within network requesting
63  *                                              a conflicting Dataset update.
64  *
65  * @param[in] aContext A pointer to the arbitrary context (provided by user in `otDatasetUpdaterRequestUpdate()`).
66  */
67 typedef void (*otDatasetUpdaterCallback)(otError aError, void *aContext);
68 
69 /**
70  * Requests an update to Operational Dataset.
71  *
72  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
73  *
74  * @p aDataset should contain the fields to be updated and their new value. It must not contain Active or Pending
75  * Timestamp fields. The Delay field is optional, if not provided a default value (1000 ms) would be used.
76  *
77  * @param[in]  aInstance               A pointer to an OpenThread instance.
78  * @param[in]  aDataset                A pointer to the Dataset containing the fields to change.
79  * @param[in]  aCallback               A callback to indicate when Dataset update request finishes.
80  * @param[in]  aContext                An arbitrary context passed to callback.
81  *
82  * @retval OT_ERROR_NONE           Dataset update started successfully (@p aCallback will be invoked on completion).
83  * @retval OT_ERROR_INVALID_STATE  Device is disabled or not fully configured (missing or incomplete Active Dataset).
84  * @retval OT_ERROR_ALREADY        The @p aDataset fields already match the existing Active Dataset.
85  * @retval OT_ERROR_INVALID_ARGS   The @p aDataset is not valid (contains Active or Pending Timestamp).
86  * @retval OT_ERROR_BUSY           Cannot start update, a previous one is ongoing.
87  * @retval OT_ERROR_NO_BUFS        Could not allocated buffer to save Dataset.
88  */
89 otError otDatasetUpdaterRequestUpdate(otInstance                 *aInstance,
90                                       const otOperationalDataset *aDataset,
91                                       otDatasetUpdaterCallback    aCallback,
92                                       void                       *aContext);
93 
94 /**
95  * Cancels an ongoing (if any) Operational Dataset update request.
96  *
97  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
98  *
99  * @param[in]  aInstance         A pointer to an OpenThread instance.
100  */
101 void otDatasetUpdaterCancelUpdate(otInstance *aInstance);
102 
103 /**
104  * Indicates whether there is an ongoing Operation Dataset update request.
105  *
106  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
107  *
108  * @param[in]  aInstance         A pointer to an OpenThread instance.
109  *
110  * @retval TRUE    There is an ongoing update.
111  * @retval FALSE   There is no ongoing update.
112  */
113 bool otDatasetUpdaterIsUpdateOngoing(otInstance *aInstance);
114 
115 /**
116  * @}
117  */
118 
119 #ifdef __cplusplus
120 } // extern "C"
121 #endif
122 
123 #endif // OPENTHREAD_DATASET_UPDATER_H_
124