1 /* 2 * Copyright (c) 2022, 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 #ifndef OT_POSIX_PLATFORM_SETTINGS_HPP_ 30 #define OT_POSIX_PLATFORM_SETTINGS_HPP_ 31 32 namespace ot { 33 namespace Posix { 34 35 /** 36 * Gets a setting from the persisted file. 37 * 38 * @param[in] aInstance The OpenThread instance structure. 39 * @param[in] aKey The key associated with the requested setting. 40 * @param[in] aIndex The index of the specific item to get. 41 * @param[out] aValue A pointer to where the value of the setting should be written. 42 * @param[in,out] aValueLength A pointer to the length of the value. 43 * 44 * @retval OT_ERROR_NONE The given setting was found and fetched successfully. 45 * @retval OT_ERROR_NOT_FOUND The given key or index was not found in the setting store. 46 * 47 */ 48 otError PlatformSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength); 49 50 /** 51 * Sets a setting in the persisted file. 52 * 53 * @param[in] aInstance The OpenThread instance structure. 54 * @param[in] aKey The key associated with the requested setting. 55 * @param[in] aValue A pointer to where the new value of the setting should be read from. 56 * @param[in] aValueLength The length of the data pointed to by aValue. 57 * 58 */ 59 void PlatformSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength); 60 61 /** 62 * Adds a setting to the persisted file. 63 * 64 * @param[in] aInstance The OpenThread instance structure. 65 * @param[in] aKey The key associated with the requested setting. 66 * @param[in] aValue A pointer to where the new value of the setting should be read from. 67 * @param[in] aValueLength The length of the data pointed to by aValue. 68 * 69 */ 70 void PlatformSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength); 71 72 /** 73 * Removes a setting either from swap file or persisted file. 74 * 75 * @param[in] aInstance The OpenThread instance structure. 76 * @param[in] aKey The key associated with the requested setting. 77 * @param[in] aIndex The index of the value to be removed. If set to -1, all values for this aKey will be removed. 78 * @param[out] aSwapFd A optional pointer to receive file descriptor of the generated swap file descriptor. 79 * 80 * @note 81 * If @p aSwapFd is null, operate deleting on the setting file. 82 * If @p aSwapFd is not null, operate on the swap file, and aSwapFd will point to the swap file descriptor. 83 * 84 * @retval OT_ERROR_NONE The given key and index was found and removed successfully. 85 * @retval OT_ERROR_NOT_FOUND The given key or index was not found in the setting store. 86 * 87 */ 88 otError PlatformSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex, int *aSwapFd); 89 90 /** 91 * Gets the sensitive keys that should be stored in the secure area. 92 * 93 * @param[in] aInstance The OpenThread instance structure. 94 * @param[out] aKeys A pointer to where the pointer to the array containing sensitive keys should be written. 95 * @param[out] aKeysLength A pointer to where the count of sensitive keys should be written. 96 * 97 */ 98 void PlatformSettingsGetSensitiveKeys(otInstance *aInstance, const uint16_t **aKeys, uint16_t *aKeysLength); 99 100 } // namespace Posix 101 } // namespace ot 102 103 #endif // OT_POSIX_PLATFORM_SETTINGS_HPP_ 104