le_secStore_interface.h

Go to the documentation of this file.
1 
2 
3 /*
4  * ====================== WARNING ======================
5  *
6  * THE CONTENTS OF THIS FILE HAVE BEEN AUTO-GENERATED.
7  * DO NOT MODIFY IN ANY WAY.
8  *
9  * ====================== WARNING ======================
10  */
11 
12 /**
13  * @page c_secStore Secure Storage
14  *
15  * @ref le_secStore_interface.h "API Reference" <br>
16  * @ref c_secStoreAdmin API <br>
17  * @ref platformConstraintsSecStorage Constraints
18  *
19  * <HR>
20  *
21  * This API for accessing secure storage.
22  *
23  * Secure storage can be used to store sensitive information like passwords, keys, certificates,
24  * etc. All data in the secure storage is in an encrypted format. Each app using this API only has
25  * access to its own secure storage data.
26  *
27  * App's items in secure storage have a name and a value. The item name is used to access the item's
28  * value and can be maximum 255 characters. The item name can contain path separators, '/', to
29  * help organize an app's data. Item names cannot contain a trailing separator.
30  *
31  * To create or update an item, use le_secStore_Write() to specify the item's name and value. If the
32  * item doesn't exist, it'll be created. Each item can be a maximum of 8192 bytes. If it's larger,
33  * le_secStore_Write() will fail.
34  *
35  * Additionally, an app's total secure storage usage is limited by the maxSecureStorageBytes setting
36  * that may be specified in the xdef files. The maxSecureStorageBytes default is 8192 bytes.
37  *
38  * Writing to secure storage may also fail if the system-wide secure storage is out of memory. The
39  * system-wide secure storage memory amount is platform dependent
40  * (see @ref platformConstraintsSecStorage).
41  *
42  * To read an item, use le_secStore_Read(), and specify the item's name. To delete an item, use
43  * le_secStore_Delete().
44  *
45  * For deleting all the contents of an app, special item name "*" is supported. Example,
46  * le_secStore_Delete("*") will erase all the securage storage contents of a given app. Note that
47  * the special item name is not supported for reading and writing from secure storage.
48  *
49  * All the functions in this API are provided by the @b secStore service.
50  *
51  * Here's a code sample binding to this service:
52  * @verbatim
53  bindings:
54  {
55  clientExe.clientComponent.le_secStore -> secStore.le_secStore
56  }
57  @endverbatim
58  *
59  * Whenever the secure storage is modified, a timer of 300 seconds is started. When the timer
60  * expires, a backup is performed to capture all changes since the previous backup. If the secure
61  * storage is not modified, then the backup is not performed.
62  * If corruption in the secure storage is detected, a restore is performed and the target device is
63  * rebooted.
64  *
65  * @section c_secStoreGlobal Global Secure Storage
66  *
67  * This same API also provides access to a global area that can be shared across the system.
68  * This interface is called @c secStoreGlobal.
69  *
70  * Here's a code sample binding to this service:
71  * @verbatim
72  bindings:
73  {
74  clientExe.clientComponent.secStoreGlobal -> secStore.secStoreGlobal
75  }
76  @endverbatim
77  *
78  * And the following code should be used to use the API from your .cdef file:
79  * @verbatim
80  requires:
81  {
82  api:
83 
84  {
85  secStoreGlobal = le_secStore.api
86  }
87  }
88  @endverbatim
89  *
90  * <HR>
91  *
92  * Copyright (C) Sierra Wireless Inc.
93  */
94 /**
95  * @file le_secStore_interface.h
96  *
97  * Legato @ref c_secStore API
98  *
99  * Copyright (C) Sierra Wireless Inc.
100  */
101 
102 #ifndef LE_SECSTORE_INTERFACE_H_INCLUDE_GUARD
103 #define LE_SECSTORE_INTERFACE_H_INCLUDE_GUARD
104 
105 
106 #include "legato.h"
107 
108 // Internal includes for this interface
109 #include "le_secStore_common.h"
110 /** @addtogroup le_secStore le_secStore API Reference
111  * @{
112  * @file le_secStore_common.h
113  * @file le_secStore_interface.h **/
114 //--------------------------------------------------------------------------------------------------
115 /**
116  * Type for handler called when a server disconnects.
117  */
118 //--------------------------------------------------------------------------------------------------
119 typedef void (*le_secStore_DisconnectHandler_t)(void *);
120 
121 //--------------------------------------------------------------------------------------------------
122 /**
123  *
124  * Connect the current client thread to the service providing this API. Block until the service is
125  * available.
126  *
127  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
128  * called before any other functions in this API. Normally, ConnectService is automatically called
129  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
130  *
131  * This function is created automatically.
132  */
133 //--------------------------------------------------------------------------------------------------
135 (
136  void
137 );
138 
139 //--------------------------------------------------------------------------------------------------
140 /**
141  *
142  * Try to connect the current client thread to the service providing this API. Return with an error
143  * if the service is not available.
144  *
145  * For each thread that wants to use this API, either ConnectService or TryConnectService must be
146  * called before any other functions in this API. Normally, ConnectService is automatically called
147  * for the main thread, but not for any other thread. For details, see @ref apiFilesC_client.
148  *
149  * This function is created automatically.
150  *
151  * @return
152  * - LE_OK if the client connected successfully to the service.
153  * - LE_UNAVAILABLE if the server is not currently offering the service to which the client is
154  * bound.
155  * - LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
156  * - LE_COMM_ERROR if the Service Directory cannot be reached.
157  */
158 //--------------------------------------------------------------------------------------------------
160 (
161  void
162 );
163 
164 //--------------------------------------------------------------------------------------------------
165 /**
166  * Set handler called when server disconnection is detected.
167  *
168  * When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants
169  * to continue without exiting, it should call longjmp() from inside the handler.
170  */
171 //--------------------------------------------------------------------------------------------------
173 (
174  le_secStore_DisconnectHandler_t disconnectHandler,
175  void *contextPtr
176 );
177 
178 //--------------------------------------------------------------------------------------------------
179 /**
180  *
181  * Disconnect the current client thread from the service providing this API.
182  *
183  * Normally, this function doesn't need to be called. After this function is called, there's no
184  * longer a connection to the service, and the functions in this API can't be used. For details, see
185  * @ref apiFilesC_client.
186  *
187  * This function is created automatically.
188  */
189 //--------------------------------------------------------------------------------------------------
191 (
192  void
193 );
194 
195 
196 //--------------------------------------------------------------------------------------------------
197 /**
198  * Version of the SecStore data storage
199  */
200 //--------------------------------------------------------------------------------------------------
201 
202 
203 //--------------------------------------------------------------------------------------------------
204 /**
205  * Writes an item to secure storage. If the item already exists, it'll be overwritten with
206  * the new value. If the item doesn't already exist, it'll be created.
207  * If the item name is not valid or the buffer is NULL, this function will kill the calling client.
208  *
209  * @return
210  * LE_OK if successful.
211  * LE_NO_MEMORY if there isn't enough memory to store the item.
212  * LE_UNAVAILABLE if the secure storage is currently unavailable.
213  * LE_FAULT if there was some other error.
214  */
215 //--------------------------------------------------------------------------------------------------
217 (
218  const char* LE_NONNULL name,
219  ///< [IN] Name of the secure storage item.
220  const uint8_t* bufPtr,
221  ///< [IN] Buffer containing the data to store.
222  size_t bufSize
223  ///< [IN]
224 );
225 
226 //--------------------------------------------------------------------------------------------------
227 /**
228  * Reads an item from secure storage.
229  * If the item name is not valid or the buffer is NULL, this function will kill the calling client.
230  *
231  * @return
232  * LE_OK if successful.
233  * LE_OVERFLOW if the buffer is too small to hold the entire item. No data will be written to
234  * the buffer in this case.
235  * LE_NOT_FOUND if the item doesn't exist.
236  * LE_UNAVAILABLE if the secure storage is currently unavailable.
237  * LE_FAULT if there was some other error.
238  */
239 //--------------------------------------------------------------------------------------------------
241 (
242  const char* LE_NONNULL name,
243  ///< [IN] Name of the secure storage item.
244  uint8_t* bufPtr,
245  ///< [OUT] Buffer to store the data in.
246  size_t* bufSizePtr
247  ///< [INOUT]
248 );
249 
250 //--------------------------------------------------------------------------------------------------
251 /**
252  * Deletes an item from secure storage.
253  * If the item name is not valid, this function will kill the calling client.
254  *
255  * @return
256  * LE_OK if successful.
257  * LE_NOT_FOUND if the item doesn't exist.
258  * LE_UNAVAILABLE if the secure storage is currently unavailable.
259  * LE_FAULT if there was some other error.
260  */
261 //--------------------------------------------------------------------------------------------------
263 (
264  const char* LE_NONNULL name
265  ///< [IN] Name of the secure storage item.
266 );
267 
268 //--------------------------------------------------------------------------------------------------
269 /**
270  * Gets the size of the buffer required to read an item from the secure storage.
271  * It can be actual size of the data, or some slightly greater number.
272  *
273  * @return
274  * LE_OK if successful.
275  * LE_NOT_FOUND if the path doesn't exist.
276  * LE_UNAVAILABLE if the secure storage is currently unavailable.
277  * LE_FAULT if there was some other error.
278  */
279 //--------------------------------------------------------------------------------------------------
281 (
282  const char* LE_NONNULL path,
283  ///< [IN] Path of the secure storage item.
284  uint32_t* sizePtr
285  ///< [OUT] Number that is equal to or greater than
286  ///< the size of the item, in bytes.
287 );
288 
289 //--------------------------------------------------------------------------------------------------
290 /**
291  * Start the "batch write" that aggregates multiple write/delete operation into a single batch
292  * with the purpose of improving the performance.
293  *
294  * The performance is optimized by postponing the data serialization (triggered by write/delete
295  * API calls by this particular client) until the function EndBatchWrite is called.
296  *
297  * @return
298  * LE_OK if successful.
299  * LE_FAULT if there was error.
300  */
301 //--------------------------------------------------------------------------------------------------
303 (
304  void
305 );
306 
307 //--------------------------------------------------------------------------------------------------
308 /**
309  * Ends the "batch write" operation and serializes the data to the persistent storage.
310  *
311  * @note - Failure to finish the (previously started) batch write may result in data loss.
312  * - This is not a transactional mechanism, i.e. the possibility to roll back the changes
313  * is not provided.
314  *
315  * @return
316  * LE_OK if successful.
317  * LE_FAULT if there was error.
318  */
319 //--------------------------------------------------------------------------------------------------
321 (
322  void
323 );
324 
325 /** @} **/
326 
327 #endif // LE_SECSTORE_INTERFACE_H_INCLUDE_GUARD
le_result_t le_secStore_EndBatchWrite(void)
le_result_t
Definition: le_basics.h:46
le_result_t le_secStore_Delete(const char *LE_NONNULL name)
le_result_t le_secStore_StartBatchWrite(void)
void le_secStore_DisconnectService(void)
le_result_t le_secStore_GetMinimumBufferSize(const char *LE_NONNULL path, uint32_t *sizePtr)
le_result_t le_secStore_Write(const char *LE_NONNULL name, const uint8_t *bufPtr, size_t bufSize)
void(* le_secStore_DisconnectHandler_t)(void *)
Definition: le_secStore_interface.h:119
#define LE_FULL_API
Definition: le_apiFeatures.h:40
void le_secStore_ConnectService(void)
LE_FULL_API void le_secStore_SetServerDisconnectHandler(le_secStore_DisconnectHandler_t disconnectHandler, void *contextPtr)
le_result_t le_secStore_Read(const char *LE_NONNULL name, uint8_t *bufPtr, size_t *bufSizePtr)
le_result_t le_secStore_TryConnectService(void)