summaryrefslogtreecommitdiffstats
path: root/nv_hal/hal_api/nv_hal.h
blob: 2014754167c96f28c2b857b88844731cda3fb9dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 * @copyright Copyright(c) 2018-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef HAL_API_NV_HAL_H_
#define HAL_API_NV_HAL_H_

#include <stdint.h>
#include <native_service/frameworkunified_types.h>

/**
 * @file nv_hal.h
 * @brief This file provides API for accessing storage device.
 */

/** @addtogroup backup_manager
 *  @{
 */
/** @addtogroup nv_hal
 *  @ingroup backup_manager
 *  @{
 */

/**
 * \~english NvHalMedia
 */
enum NvHalMedia {
  /**
   * \~english CacheDram
   */
  NVHALMEDIA_CACHEDRAM = 0,
  /**
   * \~english BackupDram
   */
  NVHALMEDIA_BACKUPDRAM,
  /**
   * \~english nand
   */
  NVHALMEDIA_NAND,
  /**
   * \~english Max
   */
  NVHALMEDIA_MAX
};

/**\ingroup InitNv
 * \~english @par Brief
 *      Initialize Nv hal library.
 * \~english @retval eFrameworkunifiedStatusOK   : succsess initialize.
 * \~english @retval eFrameworkunifiedStatusFail : fail initialize
 * \~english @par Preconditions
 *      - There is no preconditions for this API.
 * \~english @par Change of internal state
 *      - Change of internal state according to the API does not occur.
 * \~english @par Conditions of processing failure
 *      - Initialization processing failure.[eFrameworkunifiedStatusFail]
 * \~english @par Detail
 *      - Perform Nv_hal library initialization.
 *      - This process also performs deletion of temporary files accompanying system reset\n
 *        during write processing.
 *      - The API can only be used by 1 process.
 * \~english @par Classification
 *      Public
 * \~english @par Type
 *      Sync
 * \~english @see
 *      - None
 */
EFrameworkunifiedStatus InitNv(void);

/**\ingroup GetSizeNv
 * \~english @par Brief
 *      This API get data size which is stored in storage device.
 * \~english @param [in] media
 *      enum NvHalMedia           - Media type
 * \~english @param [in] filename
 *      const char*               - file name(Concatenated[category name/item name])
 * \~english @param [out] size
 *      uint32_t                  - Data size
 * \~english @par
 *      - Get decrypted data size as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
 *       - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
 *       - Encryption data     : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
 * \~english @retval eFrameworkunifiedStatusOK OK
 * \~english @retval eFrameworkunifiedStatusFileLoadError File not exists
 * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
 * \~english @par Preconditions
 *      - There is no preconditions for this API.
 * \~english @par Change of internal state
 *      - Change of internal state according to the API does not occur.
 * \~english @par Conditions of processing failure
 *      - If the parameter media is less than NVHALMEDIA_CACHEDRAM or greater than\n
 *      NVHALMEDIA_NAND. [eFrameworkunifiedStatusInvldParam]
 *      - Parameter id is NULL. [eFrameworkunifiedStatusInvldParam]
 *      - Value of parameter size is 0. [eFrameworkunifiedStatusInvldParam]
 *      - Internal IO error(lstat).[eFrameworkunifiedStatusFileLoadError]
 * \~english @par Detail
 *      - This API get the data size according to specified media and ID.
 *      - The API can only be used by 1 process.
 * \~english @par Classification
 *      Public
 * \~english @par Type
 *      Sync
 * \~english @see WriteNv ReadNv
 */
EFrameworkunifiedStatus GetSizeNv(enum NvHalMedia media, const char *filename, uint32_t* size);



/**\ingroup ReadNv
 * \~english @par Brief
 *      Read data from storage device.
 * \~english @param [in] media
 *      enum NvHalMedia           - Media type
 * \~english @param [in] filename
 *      const char*               - file name(Concatenated[category name/item name])
 * \~english @param [out] buffer
 *      uint8_t*                  - Buffer for storing read data
 * \~english @param [in] size
 *      uint32_t                  - Data size
 * \~english @par
 *      - Decrypt and read data as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
 *       - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
 *       - Encryption data     : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
 * \~english @retval eFrameworkunifiedStatusOK OK
 * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
 * \~english @retval eFrameworkunifiedStatusFail Read data failed
 * \~english @par Preconditions
 *      - There is no preconditions for this API.
 * \~english @par Change of internal state
 *      - Change of internal state according to the API does not occur.
 * \~english @par Conditions of processing failure
 *      - If the parameter media is less than NVHALMEDIA_CACHEDRAM or greater than\n
 *      NVHALMEDIA_NAND. [eFrameworkunifiedStatusInvldParam]
 *      - Parameter id is NULL. [eFrameworkunifiedStatusInvldParam]
 *      - Parameter buffer is NULL. [eFrameworkunifiedStatusInvldParam]
 *      - Value of parameter size is 0. [eFrameworkunifiedStatusInvldParam]
 *      - Internal IO error(open, pread, lstat, close).[eFrameworkunifiedStatusFail]
 *      - The value of parameter size is not equal to the file size specified by id.
 *      [eFrameworkunifiedStatusFail]
 * \~english @par Detail
 *      - This API reads data according to specified media and ID.
 *      - ID is managed by backup_manager.For details, refer to "Details about XML file" in external specification of backup_manager.
 *      - The API can only be used by 1 process.
 * \~english @par Classification
 *      Public
 * \~english @par Type
 *      Sync
 * \~english @see CheckNv WriteNv
 */
EFrameworkunifiedStatus ReadNv(enum NvHalMedia media, const char *filename, uint8_t *buffer, uint32_t size);

/**\ingroup WriteNv
 * \~english @par Brief
 *      Write data to storage device.
 * \~english @param [in] media
 *      enum NvHalMedia           - Media type
 * \~english @param [in] filename
 *      const char*               - filename(Concatenated[category name/item name])
 * \~english @param [in] buffer
 *      uint8_t*                  - Buffer for storing written data
 * \~english @param [in] size
 *      uint32_t                  - Data size
 * \~english @par
 *      - Encrypt and write data as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
 *       - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
 *       - Encryption data     : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
 * \~english @retval eFrameworkunifiedStatusOK OK
 * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
 * \~english @retval eFrameworkunifiedStatusFail Write data failed
 * \~english @par Preconditions
 *      - There is no preconditions for this API.
 * \~english @par Change of internal state
 *      - Change of internal state according to the API does not occur.
 * \~english @par Conditions of processing failure
 *      - If the parameter media is less than NVHALMEDIA_CACHEDRAM or greater than\n
 *      NVHALMEDIA_NAND. [eFrameworkunifiedStatusInvldParam]
 *      - Parameter id is NULL. [eFrameworkunifiedStatusInvldParam]
 *      - Parameter buffer is NULL. [eFrameworkunifiedStatusInvldParam]
 *      - Value of parameter size is 0. [eFrameworkunifiedStatusInvldParam]
 *      - Internal IO error(open, pwrite, close, mkdir).[eFrameworkunifiedStatusFail]
 * \~english @par Detail
 *      - This API writes data according to specified media and ID.
 *      - filename is managed by backup_manager.For details, refer to "Details about XML file" in external specification of backup_manager.
 *      - The API can only be used by 1 process.
 * \~english @par Classification
 *      Public
 * \~english @par Type
 *      Sync
 * \~english @see CheckNv ReadNv
 */
EFrameworkunifiedStatus WriteNv(enum NvHalMedia media, const char *filename, uint8_t *buffer, uint32_t size);

/**\ingroup DeleteNv
 * \~english @par Brief
 *      Delete data which is stored in storage device.
 * \~english @param [in] media
 *      enum \ref NvHalMedia           - Media type
 * \~english @param [in] filename
 *      const char*               - filename(Concatenated[category name/item name])
 * \~english @par
 *      - Delete data as encryption data when item name in the argument of filename (file name) is added Prefix "ENC_".
 *       - Non encryption data : D_BK_CA_GID_D/D_BK_ID_GID_D
 *       - Encryption data     : D_BK_CA_GID_D/ENC_D_BK_ID_GID_D
 * \~english @retval eFrameworkunifiedStatusOK OK
 * \~english @retval eFrameworkunifiedStatusInvldParam Parameter error
 * \~english @retval eFrameworkunifiedStatusFail Delete data failed
 * \~english @par Preconditions
 *      - There is no preconditions for this API.
 * \~english @par Change of internal state
 *      - Change of internal state according to the API does not occur.
 * \~english @par Conditions of processing failure
 *      - If the parameter media is less than \ref NVHALMEDIA_CACHEDRAM or greater than\n
 *        \ref NVHALMEDIA_NAND . [eFrameworkunifiedStatusInvldParam]
 *      - Parameter filename (filename) is NULL. [eFrameworkunifiedStatusInvldParam]
 *      - Internal IO error.[eFrameworkunifiedStatusFail]
 * \~english @par Detail
 *      - This API delete data according to specified media and filename.
 *      - This API delete encryption key if data is encrypted.
 *      - filename is managed by backup_manager.For details, refer to "Details about XML file" in external specification of backup_manager.
 *      - The API can only be used by 1 process.
 * \~english @par Classification
 *      Public
 * \~english @par Type
 *      Sync
 * \~english @see GetSizeNv ReadNv WriteNv
 */
EFrameworkunifiedStatus DeleteNv(enum NvHalMedia media, const char *filename);

/** @}*/  // end of nv_hal
/** @}*/  // end of backup_manager

#endif  // HAL_API_NV_HAL_H_