xref: /aosp_15_r20/external/openthread/src/posix/platform/settings.hpp (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1*cfb92d14SAndroid Build Coastguard Worker /*
2*cfb92d14SAndroid Build Coastguard Worker  *  Copyright (c) 2022, The OpenThread Authors.
3*cfb92d14SAndroid Build Coastguard Worker  *  All rights reserved.
4*cfb92d14SAndroid Build Coastguard Worker  *
5*cfb92d14SAndroid Build Coastguard Worker  *  Redistribution and use in source and binary forms, with or without
6*cfb92d14SAndroid Build Coastguard Worker  *  modification, are permitted provided that the following conditions are met:
7*cfb92d14SAndroid Build Coastguard Worker  *  1. Redistributions of source code must retain the above copyright
8*cfb92d14SAndroid Build Coastguard Worker  *     notice, this list of conditions and the following disclaimer.
9*cfb92d14SAndroid Build Coastguard Worker  *  2. Redistributions in binary form must reproduce the above copyright
10*cfb92d14SAndroid Build Coastguard Worker  *     notice, this list of conditions and the following disclaimer in the
11*cfb92d14SAndroid Build Coastguard Worker  *     documentation and/or other materials provided with the distribution.
12*cfb92d14SAndroid Build Coastguard Worker  *  3. Neither the name of the copyright holder nor the
13*cfb92d14SAndroid Build Coastguard Worker  *     names of its contributors may be used to endorse or promote products
14*cfb92d14SAndroid Build Coastguard Worker  *     derived from this software without specific prior written permission.
15*cfb92d14SAndroid Build Coastguard Worker  *
16*cfb92d14SAndroid Build Coastguard Worker  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*cfb92d14SAndroid Build Coastguard Worker  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cfb92d14SAndroid Build Coastguard Worker  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cfb92d14SAndroid Build Coastguard Worker  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20*cfb92d14SAndroid Build Coastguard Worker  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*cfb92d14SAndroid Build Coastguard Worker  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*cfb92d14SAndroid Build Coastguard Worker  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*cfb92d14SAndroid Build Coastguard Worker  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*cfb92d14SAndroid Build Coastguard Worker  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*cfb92d14SAndroid Build Coastguard Worker  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*cfb92d14SAndroid Build Coastguard Worker  *  POSSIBILITY OF SUCH DAMAGE.
27*cfb92d14SAndroid Build Coastguard Worker  */
28*cfb92d14SAndroid Build Coastguard Worker 
29*cfb92d14SAndroid Build Coastguard Worker #ifndef OT_POSIX_PLATFORM_SETTINGS_HPP_
30*cfb92d14SAndroid Build Coastguard Worker #define OT_POSIX_PLATFORM_SETTINGS_HPP_
31*cfb92d14SAndroid Build Coastguard Worker 
32*cfb92d14SAndroid Build Coastguard Worker namespace ot {
33*cfb92d14SAndroid Build Coastguard Worker namespace Posix {
34*cfb92d14SAndroid Build Coastguard Worker 
35*cfb92d14SAndroid Build Coastguard Worker /**
36*cfb92d14SAndroid Build Coastguard Worker  * Gets a setting from the persisted file.
37*cfb92d14SAndroid Build Coastguard Worker  *
38*cfb92d14SAndroid Build Coastguard Worker  * @param[in]      aInstance     The OpenThread instance structure.
39*cfb92d14SAndroid Build Coastguard Worker  * @param[in]      aKey          The key associated with the requested setting.
40*cfb92d14SAndroid Build Coastguard Worker  * @param[in]      aIndex        The index of the specific item to get.
41*cfb92d14SAndroid Build Coastguard Worker  * @param[out]     aValue        A pointer to where the value of the setting should be written.
42*cfb92d14SAndroid Build Coastguard Worker  * @param[in,out]  aValueLength  A pointer to the length of the value.
43*cfb92d14SAndroid Build Coastguard Worker  *
44*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_NONE        The given setting was found and fetched successfully.
45*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_NOT_FOUND   The given key or index was not found in the setting store.
46*cfb92d14SAndroid Build Coastguard Worker  *
47*cfb92d14SAndroid Build Coastguard Worker  */
48*cfb92d14SAndroid Build Coastguard Worker otError PlatformSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength);
49*cfb92d14SAndroid Build Coastguard Worker 
50*cfb92d14SAndroid Build Coastguard Worker /**
51*cfb92d14SAndroid Build Coastguard Worker  * Sets a setting in the persisted file.
52*cfb92d14SAndroid Build Coastguard Worker  *
53*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aInstance     The OpenThread instance structure.
54*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aKey          The key associated with the requested setting.
55*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aValue        A pointer to where the new value of the setting should be read from.
56*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aValueLength  The length of the data pointed to by aValue.
57*cfb92d14SAndroid Build Coastguard Worker  *
58*cfb92d14SAndroid Build Coastguard Worker  */
59*cfb92d14SAndroid Build Coastguard Worker void PlatformSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
60*cfb92d14SAndroid Build Coastguard Worker 
61*cfb92d14SAndroid Build Coastguard Worker /**
62*cfb92d14SAndroid Build Coastguard Worker  * Adds a setting to the persisted file.
63*cfb92d14SAndroid Build Coastguard Worker  *
64*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aInstance     The OpenThread instance structure.
65*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aKey          The key associated with the requested setting.
66*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aValue        A pointer to where the new value of the setting should be read from.
67*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aValueLength  The length of the data pointed to by aValue.
68*cfb92d14SAndroid Build Coastguard Worker  *
69*cfb92d14SAndroid Build Coastguard Worker  */
70*cfb92d14SAndroid Build Coastguard Worker void PlatformSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
71*cfb92d14SAndroid Build Coastguard Worker 
72*cfb92d14SAndroid Build Coastguard Worker /**
73*cfb92d14SAndroid Build Coastguard Worker  * Removes a setting either from swap file or persisted file.
74*cfb92d14SAndroid Build Coastguard Worker  *
75*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aInstance  The OpenThread instance structure.
76*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aKey       The key associated with the requested setting.
77*cfb92d14SAndroid Build Coastguard Worker  * @param[in]  aIndex     The index of the value to be removed. If set to -1, all values for this aKey will be removed.
78*cfb92d14SAndroid Build Coastguard Worker  * @param[out] aSwapFd    A optional pointer to receive file descriptor of the generated swap file descriptor.
79*cfb92d14SAndroid Build Coastguard Worker  *
80*cfb92d14SAndroid Build Coastguard Worker  * @note
81*cfb92d14SAndroid Build Coastguard Worker  *   If @p aSwapFd is null, operate deleting on the setting file.
82*cfb92d14SAndroid Build Coastguard Worker  *   If @p aSwapFd is not null, operate on the swap file, and aSwapFd will point to the swap file descriptor.
83*cfb92d14SAndroid Build Coastguard Worker  *
84*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_NONE        The given key and index was found and removed successfully.
85*cfb92d14SAndroid Build Coastguard Worker  * @retval OT_ERROR_NOT_FOUND   The given key or index was not found in the setting store.
86*cfb92d14SAndroid Build Coastguard Worker  *
87*cfb92d14SAndroid Build Coastguard Worker  */
88*cfb92d14SAndroid Build Coastguard Worker otError PlatformSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex, int *aSwapFd);
89*cfb92d14SAndroid Build Coastguard Worker 
90*cfb92d14SAndroid Build Coastguard Worker /**
91*cfb92d14SAndroid Build Coastguard Worker  * Gets the sensitive keys that should be stored in the secure area.
92*cfb92d14SAndroid Build Coastguard Worker  *
93*cfb92d14SAndroid Build Coastguard Worker  * @param[in]   aInstance    The OpenThread instance structure.
94*cfb92d14SAndroid Build Coastguard Worker  * @param[out]  aKeys        A pointer to where the pointer to the array containing sensitive keys should be written.
95*cfb92d14SAndroid Build Coastguard Worker  * @param[out]  aKeysLength  A pointer to where the count of sensitive keys should be written.
96*cfb92d14SAndroid Build Coastguard Worker  *
97*cfb92d14SAndroid Build Coastguard Worker  */
98*cfb92d14SAndroid Build Coastguard Worker void PlatformSettingsGetSensitiveKeys(otInstance *aInstance, const uint16_t **aKeys, uint16_t *aKeysLength);
99*cfb92d14SAndroid Build Coastguard Worker 
100*cfb92d14SAndroid Build Coastguard Worker } // namespace Posix
101*cfb92d14SAndroid Build Coastguard Worker } // namespace ot
102*cfb92d14SAndroid Build Coastguard Worker 
103*cfb92d14SAndroid Build Coastguard Worker #endif // OT_POSIX_PLATFORM_SETTINGS_HPP_
104