1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __TFM_PROTECTED_STORAGE_H__
9 #define __TFM_PROTECTED_STORAGE_H__
10 
11 #include <stdint.h>
12 
13 #include "psa/protected_storage.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /**
20  * \brief Initializes the protected storage system.
21  *
22  * \return A status indicating the success/failure of the operation as specified
23  *         in \ref psa_status_t
24  *
25  * \retval PSA_SUCCESS                     The operation completed successfully
26  * \retval PSA_ERROR_STORAGE_FAILURE       The operation failed because the
27  *                                         storage system initialization has
28  *                                         failed (fatal error)
29  * \retval PSA_ERROR_GENERIC_ERROR         The operation failed because of an
30  *                                         unspecified internal failure
31  */
32 psa_status_t tfm_ps_init(void);
33 
34 /**
35  * \brief Creates a new or modifies an existing asset.
36  *
37  * \param[in] client_id     Identifier of the asset's owner (client)
38  * \param[in] uid           Unique identifier for the data
39  * \param[in] data_length   The size in bytes of the data in `p_data`
40  * \param[in] create_flags  The flags indicating the properties of the data
41  *
42  * \return A status indicating the success/failure of the operation as specified
43  *         in \ref psa_status_t
44  *
45  * \retval PSA_SUCCESS                      The operation completed successfully
46  * \retval PSA_ERROR_NOT_PERMITTED          The operation failed because the
47  *                                          provided uid value was already
48  *                                          created with
49  *                                          PSA_STORAGE_FLAG_WRITE_ONCE
50  * \retval PSA_ERROR_INVALID_ARGUMENT       The operation failed because one or
51  *                                          more of the given arguments were
52  *                                          invalid (null pointer, etc.)
53  * \retval PSA_ERROR_NOT_SUPPORTED          The operation failed because one or
54  *                                          more of the flags provided in
55  *                                          `create_flags` is not supported or
56  *                                          is not valid
57  * \retval PSA_ERROR_INSUFFICIENT_STORAGE   The operation failed because there
58  *                                          was insufficient space on the
59  *                                          storage medium
60  * \retval PSA_ERROR_STORAGE_FAILURE        The operation failed because the
61  *                                          physical storage has failed (fatal
62  *                                          error)
63  * \retval PSA_ERROR_GENERIC_ERROR          The operation failed because of an
64  *                                          unspecified internal failure.
65  */
66 psa_status_t tfm_ps_set(int32_t client_id,
67                         psa_storage_uid_t uid,
68                         uint32_t data_length,
69                         psa_storage_create_flags_t create_flags);
70 /**
71  * \brief Gets the asset data for the provided uid.
72  *
73  * \param[in]  client_id      Identifier of the asset's owner (client)
74  * \param[in]  uid            Unique identifier for the data
75  * \param[in]  data_offset    The offset within the data associated with the
76  *                            `uid` to start retrieving data
77  * \param[in]  data_size      The amount of data to read (and the minimum
78  *                            allocated size of the `p_data` buffer)
79  * \param[out] p_data_length  The pointer to the size of the data retrieved
80  *                            upon success.
81  *
82  * \return A status indicating the success/failure of the operation as specified
83  *         in \ref psa_status_t
84  *
85  * \retval PSA_SUCCESS                    The operation completed successfully
86  * \retval PSA_ERROR_INVALID_ARGUMENT     The operation failed because one or
87  *                                        more of the given arguments were
88  *                                        invalid (null pointer, etc.)
89  * \retval PSA_ERROR_DOES_NOT_EXIST       The operation failed because the
90  *                                        provided uid value was not found in
91  *                                        the storage
92  * \retval PSA_ERROR_STORAGE_FAILURE      The operation failed because the
93  *                                        physical storage has failed (fatal
94  *                                        error)
95  * \retval PSA_ERROR_GENERIC_ERROR        The operation failed because of an
96  *                                        unspecified internal failure
97  * \retval PSA_ERROR_DATA_CORRUPT         The operation failed because the data
98  *                                        associated with the UID was corrupt
99  * \retval PSA_ERROR_INVALID_SIGNATURE    The operation failed because the data
100  *                                        associated with the UID failed
101  *                                        authentication
102  */
103 psa_status_t tfm_ps_get(int32_t client_id,
104                         psa_storage_uid_t uid,
105                         uint32_t data_offset,
106                         uint32_t data_size,
107                         size_t *p_data_length);
108 /**
109  * \brief Gets the metadata for the provided uid.
110  *
111  * \param[in]  client_id  Identifier of the asset's owner (client)
112  * \param[in]  uid        Unique identifier for the data
113  * \param[out] p_info     A pointer to the `psa_storage_info_t` struct that will
114  *                        be populated with the metadata
115  *
116  * \return A status indicating the success/failure of the operation as specified
117  *         in \ref psa_status_t
118  *
119  * \retval PSA_SUCCESS                    The operation completed successfully
120  * \retval PSA_ERROR_INVALID_ARGUMENT     The operation failed because one or
121  *                                        more of the given arguments were
122  *                                        invalid (null pointer, etc.)
123  * \retval PSA_ERROR_DOES_NOT_EXIST       The operation failed because the
124  *                                        provided uid value was not found in
125  *                                        the storage
126  * \retval PSA_ERROR_STORAGE_FAILURE      The operation failed because the
127  *                                        physical storage has failed (fatal
128  *                                        error)
129  * \retval PSA_ERROR_GENERIC_ERROR        The operation failed because of an
130  *                                        unspecified internal failure
131  * \retval PSA_ERROR_DATA_CORRUPT         The operation failed because the data
132  *                                        associated with the UID was corrupt
133  * \retval PSA_ERROR_INVALID_SIGNATURE    The operation failed because the data
134  *                                        associated with the UID failed
135  *                                        authentication
136  */
137 psa_status_t tfm_ps_get_info(int32_t client_id, psa_storage_uid_t uid,
138                              struct psa_storage_info_t *p_info);
139 
140 /**
141  * \brief Removes the provided uid and its associated data from storage.
142  *
143  * \param[in] client_id  Identifier of the asset's owner (client)
144  * \param[in] uid        Unique identifier for the data to be removed
145  *
146  * \return A status indicating the success/failure of the operation as specified
147  *         in \ref psa_status_t
148  *
149  * \retval PSA_SUCCESS                    The operation completed successfully
150  * \retval PSA_ERROR_INVALID_ARGUMENT     The operation failed because one or
151  *                                        more of the given arguments were
152  *                                        invalid (null pointer, etc.)
153  * \retval PSA_ERROR_DOES_NOT_EXIST       The operation failed because the
154  *                                        provided uid value was not found in
155  *                                        the storage
156  * \retval PSA_ERROR_NOT_PERMITTED        The operation failed because the
157  *                                        provided uid value was created with
158  *                                        PSA_STORAGE_FLAG_WRITE_ONCE
159  * \retval PSA_ERROR_STORAGE_FAILURE      The operation failed because the
160  *                                        physical storage has failed (fatal
161  *                                        error)
162  * \retval PSA_ERROR_GENERIC_ERROR        The operation failed because of an
163  *                                        unspecified internal failure
164  */
165 psa_status_t tfm_ps_remove(int32_t client_id, psa_storage_uid_t uid);
166 
167 /**
168  * \brief Gets a bitmask with flags set for all of the optional features
169  *        supported by the implementation.
170  *
171  * \return Bitmask value which contains all the bits set for all the optional
172  *         features supported by the implementation
173  */
174 uint32_t tfm_ps_get_support(void);
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif /* __TFM_PROTECTED_STORAGE_H__ */
181