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 /**
55  * This callback function pointer is called when a Dataset update request finishes, reporting success or failure status
56  * of the Dataset update request.
57  *
58  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
59  *
60  * @param[in] aError   The error status.
61  *                     OT_ERROR_NONE            indicates successful Dataset update.
62  *                     OT_ERROR_INVALID_STATE   indicates failure due invalid state (MLE being disabled).
63  *                     OT_ERROR_ALREADY         indicates failure due to another device within network requesting
64  *                                              a conflicting Dataset update.
65  *
66  * @param[in] aContext A pointer to the arbitrary context (provided by user in `otDatasetUpdaterRequestUpdate()`).
67  *
68  */
69 typedef void (*otDatasetUpdaterCallback)(otError aError, void *aContext);
70 
71 /**
72  * Requests an update to Operational Dataset.
73  *
74  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
75  *
76  * @p aDataset should contain the fields to be updated and their new value. It must not contain Active or Pending
77  * Timestamp fields. The Delay field is optional, if not provided a default value (1000 ms) would be used.
78  *
79  * @param[in]  aInstance               A pointer to an OpenThread instance.
80  * @param[in]  aDataset                A pointer to the Dataset containing the fields to change.
81  * @param[in]  aCallback               A callback to indicate when Dataset update request finishes.
82  * @param[in]  aContext                An arbitrary context passed to callback.
83  *
84  * @retval OT_ERROR_NONE           Dataset update started successfully (@p aCallback will be invoked on completion).
85  * @retval OT_ERROR_INVALID_STATE  Device is disabled (MLE is disabled).
86  * @retval OT_ERROR_INVALID_ARGS   The @p aDataset is not valid (contains Active or Pending Timestamp).
87  * @retval OT_ERROR_BUSY           Cannot start update, a previous one is ongoing.
88  * @retval OT_ERROR_NO_BUFS        Could not allocated buffer to save Dataset.
89  *
90  */
91 otError otDatasetUpdaterRequestUpdate(otInstance                 *aInstance,
92                                       const otOperationalDataset *aDataset,
93                                       otDatasetUpdaterCallback    aCallback,
94                                       void                       *aContext);
95 
96 /**
97  * Cancels an ongoing (if any) Operational Dataset update request.
98  *
99  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
100  *
101  * @param[in]  aInstance         A pointer to an OpenThread instance.
102  *
103  */
104 void otDatasetUpdaterCancelUpdate(otInstance *aInstance);
105 
106 /**
107  * Indicates whether there is an ongoing Operation Dataset update request.
108  *
109  * Available when `OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE` is enabled.
110  *
111  * @param[in]  aInstance         A pointer to an OpenThread instance.
112  *
113  * @retval TRUE    There is an ongoing update.
114  * @retval FALSE   There is no ongoing update.
115  *
116  */
117 bool otDatasetUpdaterIsUpdateOngoing(otInstance *aInstance);
118 
119 /**
120  * @}
121  *
122  */
123 
124 #ifdef __cplusplus
125 } // extern "C"
126 #endif
127 
128 #endif // OPENTHREAD_DATASET_UPDATER_H_
129