1 /* 2 * Copyright (c) 2021, 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 platform abstraction for secure non-volatile storage of settings. 33 */ 34 35 #ifndef OPENTHREAD_POSIX_SECURE_SETTINGS_H_ 36 #define OPENTHREAD_POSIX_SECURE_SETTINGS_H_ 37 38 #include <openthread/instance.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /** 45 * @addtogroup plat-settings 46 * 47 * @brief 48 * This module includes the platform abstraction for secure non-volatile storage of settings. 49 * 50 * @{ 51 */ 52 53 /** 54 * Performs any initialization for the secure settings subsystem, if necessary. 55 * 56 * @param[in] aInstance The OpenThread instance structure. 57 */ 58 void otPosixSecureSettingsInit(otInstance *aInstance); 59 60 /** 61 * Performs any de-initialization for the secure settings subsystem, if necessary. 62 * 63 * @param[in] aInstance The OpenThread instance structure. 64 */ 65 void otPosixSecureSettingsDeinit(otInstance *aInstance); 66 67 /** 68 * Fetches the value of the setting identified by aKey and write it to the memory pointed to by aValue. 69 * It then writes the length to the integer pointed to by aValueLength. The initial value of aValueLength is the 70 * maximum number of bytes to be written to aValue. 71 * 72 * Can be used to check for the existence of a key without fetching the value by setting aValue and 73 * aValueLength to NULL. You can also check the length of the setting without fetching it by setting only aValue 74 * to NULL. 75 * 76 * Note that the underlying storage implementation is not required to maintain the order of settings with multiple 77 * values. The order of such values MAY change after ANY write operation to the store. 78 * 79 * @param[in] aInstance The OpenThread instance structure. 80 * @param[in] aKey The key associated with the requested setting. 81 * @param[in] aIndex The index of the specific item to get. 82 * @param[out] aValue A pointer to where the value of the setting should be written. May be set to NULL if 83 * just testing for the presence or length of a setting. 84 * @param[in,out] aValueLength A pointer to the length of the value. When called, this pointer should point to an 85 * integer containing the maximum value size that can be written to aValue. At return, 86 * the actual length of the setting is written. This may be set to NULL if performing 87 * a presence check. 88 * 89 * @retval OT_ERROR_NONE The given setting was found and fetched successfully. 90 * @retval OT_ERROR_NOT_FOUND The given setting was not found in the setting store. 91 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented on this platform. 92 */ 93 otError otPosixSecureSettingsGet(otInstance *aInstance, 94 uint16_t aKey, 95 int aIndex, 96 uint8_t *aValue, 97 uint16_t *aValueLength); 98 99 /** 100 * Sets or replaces the value of a setting identified by aKey. If there was more than one value 101 * previously associated with aKey, then they are all deleted and replaced with this single entry. 102 * 103 * Calling this function successfully may cause unrelated settings with multiple values to be reordered. 104 * 105 * @param[in] aInstance The OpenThread instance structure. 106 * @param[in] aKey The key associated with the setting to change. 107 * @param[in] aValue A pointer to where the new value of the setting should be read from. MUST NOT be NULL if 108 * aValueLength is non-zero. 109 * @param[in] aValueLength The length of the data pointed to by aValue. May be zero. 110 * 111 * @retval OT_ERROR_NONE The given setting was changed or staged. 112 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented on this platform. 113 * @retval OT_ERROR_NO_BUFS No space remaining to store the given setting. 114 */ 115 otError otPosixSecureSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength); 116 117 /** 118 * Adds the value to a setting identified by aKey, without replacing any existing values. 119 * 120 * Note that the underlying implementation is not required to maintain the order of the items associated with a 121 * specific key. The added value may be added to the end, the beginning, or even somewhere in the middle. The order 122 * of any pre-existing values may also change. 123 * 124 * Calling this function successfully may cause unrelated settings with multiple values to be reordered. 125 * 126 * @param[in] aInstance The OpenThread instance structure. 127 * @param[in] aKey The key associated with the setting to change. 128 * @param[in] aValue A pointer to where the new value of the setting should be read from. MUST NOT be NULL 129 * if aValueLength is non-zero. 130 * @param[in] aValueLength The length of the data pointed to by aValue. May be zero. 131 * 132 * @retval OT_ERROR_NONE The given setting was added or staged to be added. 133 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented on this platform. 134 * @retval OT_ERROR_NO_BUFS No space remaining to store the given setting. 135 */ 136 otError otPosixSecureSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength); 137 138 /** 139 * Deletes a specific value from the setting identified by aKey from the secure settings store. 140 * 141 * Note that the underlying implementation is not required to maintain the order of the items associated with a 142 * specific key. 143 * 144 * @param[in] aInstance The OpenThread instance structure. 145 * @param[in] aKey The key associated with the requested setting. 146 * @param[in] aIndex The index of the value to be removed. If set to -1, all values for this aKey will be removed. 147 * 148 * @retval OT_ERROR_NONE The given key and index was found and removed successfully. 149 * @retval OT_ERROR_NOT_FOUND The given key or index was not found in the setting store. 150 * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented on this platform. 151 */ 152 otError otPosixSecureSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex); 153 154 /** 155 * Deletes all settings from the secure settings store, resetting it to its initial factory state. 156 * 157 * @param[in] aInstance The OpenThread instance structure. 158 */ 159 void otPosixSecureSettingsWipe(otInstance *aInstance); 160 161 /** 162 * @} 163 */ 164 165 #ifdef __cplusplus 166 } // extern "C" 167 #endif 168 169 #endif // OPENTHREAD_POSIX_SECURE_SETTINGS_H_ 170