blob: 1140170e6abd1abc78034431b06176a197ae3e2d [file] [log] [blame]
Pascal Brandc639ac82015-07-02 08:53:34 +02001/*
2 * Copyright (c) 2014, STMicroelectronics International N.V.
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 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "storage.h"
29
30#include <tee_api.h>
Pascal Brand90f23352016-05-19 15:15:47 +020031#include <trace.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020032
33#define ASSERT_PARAM_TYPE(pt) \
34do { \
35 if ((pt) != param_types) \
36 return TEE_ERROR_BAD_PARAMETERS; \
37} while (0)
38
Jens Wiklanderc5231592015-11-11 09:27:27 +010039#define VAL2HANDLE(v) (void *)(uintptr_t)(v)
40
Pascal Brandc639ac82015-07-02 08:53:34 +020041TEE_Result ta_storage_cmd_open(uint32_t param_types, TEE_Param params[4])
42{
Jens Wiklanderc5231592015-11-11 09:27:27 +010043 TEE_Result res;
44 TEE_ObjectHandle o;
45
Pascal Brandc639ac82015-07-02 08:53:34 +020046 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
47 (TEE_PARAM_TYPE_MEMREF_INPUT,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020048 TEE_PARAM_TYPE_VALUE_INOUT,
49 TEE_PARAM_TYPE_VALUE_INPUT,
Pascal Brandc639ac82015-07-02 08:53:34 +020050 TEE_PARAM_TYPE_NONE));
51
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020052 res = TEE_OpenPersistentObject(params[2].value.a,
Pascal Brandc639ac82015-07-02 08:53:34 +020053 params[0].memref.buffer,
54 params[0].memref.size,
Jens Wiklanderc5231592015-11-11 09:27:27 +010055 params[1].value.a, &o);
56
57 params[1].value.b = (uintptr_t)o;
58 return res;
Pascal Brandc639ac82015-07-02 08:53:34 +020059}
60
61TEE_Result ta_storage_cmd_create(uint32_t param_types, TEE_Param params[4])
62{
Jens Wiklanderc5231592015-11-11 09:27:27 +010063 TEE_Result res;
64 TEE_ObjectHandle o;
65
Pascal Brandc639ac82015-07-02 08:53:34 +020066 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
67 (TEE_PARAM_TYPE_MEMREF_INPUT,
68 TEE_PARAM_TYPE_VALUE_INOUT,
69 TEE_PARAM_TYPE_VALUE_INPUT,
70 TEE_PARAM_TYPE_MEMREF_INPUT));
71
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020072 res = TEE_CreatePersistentObject(params[2].value.b,
Jens Wiklanderc5231592015-11-11 09:27:27 +010073 params[0].memref.buffer, params[0].memref.size,
74 params[1].value.a,
75 (TEE_ObjectHandle)(uintptr_t)params[2].value.a,
76 params[3].memref.buffer, params[3].memref.size, &o);
77 params[1].value.b = (uintptr_t)o;
78 return res;
Pascal Brandc639ac82015-07-02 08:53:34 +020079}
80
Pascal Brandeb84c442016-04-19 17:49:49 +020081TEE_Result ta_storage_cmd_create_overwrite(uint32_t param_types,
82 TEE_Param params[4])
83{
84 TEE_Result res;
85
86 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
87 (TEE_PARAM_TYPE_MEMREF_INPUT,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020088 TEE_PARAM_TYPE_VALUE_INPUT,
Pascal Brandeb84c442016-04-19 17:49:49 +020089 TEE_PARAM_TYPE_NONE,
90 TEE_PARAM_TYPE_NONE));
91
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020092 res = TEE_CreatePersistentObject(params[1].value.a,
Pascal Brandeb84c442016-04-19 17:49:49 +020093 params[0].memref.buffer, params[0].memref.size,
94 TEE_DATA_FLAG_OVERWRITE,
95 NULL, NULL, 0, NULL);
96 return res;
97}
98
Pascal Brandc639ac82015-07-02 08:53:34 +020099TEE_Result ta_storage_cmd_close(uint32_t param_types, TEE_Param params[4])
100{
101 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
102 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
103 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
104
Jens Wiklanderc5231592015-11-11 09:27:27 +0100105 TEE_CloseObject((TEE_ObjectHandle)(uintptr_t)params[0].value.a);
Pascal Brandc639ac82015-07-02 08:53:34 +0200106
107 return TEE_SUCCESS;
108}
109
110TEE_Result ta_storage_cmd_read(uint32_t param_types, TEE_Param params[4])
111{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100112 TEE_ObjectHandle o = VAL2HANDLE(params[1].value.a);
113
Pascal Brandc639ac82015-07-02 08:53:34 +0200114 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
115 (TEE_PARAM_TYPE_MEMREF_OUTPUT,
116 TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE,
117 TEE_PARAM_TYPE_NONE));
118
Jens Wiklanderc5231592015-11-11 09:27:27 +0100119 return TEE_ReadObjectData(o, params[0].memref.buffer,
Pascal Brandc639ac82015-07-02 08:53:34 +0200120 params[0].memref.size, &params[1].value.b);
121}
122
123TEE_Result ta_storage_cmd_write(uint32_t param_types, TEE_Param params[4])
124{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100125 TEE_ObjectHandle o = VAL2HANDLE(params[1].value.a);
126
Pascal Brandc639ac82015-07-02 08:53:34 +0200127 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
128 (TEE_PARAM_TYPE_MEMREF_INPUT,
129 TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
130 TEE_PARAM_TYPE_NONE));
131
Jens Wiklanderc5231592015-11-11 09:27:27 +0100132 return TEE_WriteObjectData(o, params[0].memref.buffer,
Pascal Brandc639ac82015-07-02 08:53:34 +0200133 params[0].memref.size);
134}
135
136TEE_Result ta_storage_cmd_seek(uint32_t param_types, TEE_Param params[4])
137{
138 TEE_Result res;
139 TEE_ObjectInfo info;
Jens Wiklanderc5231592015-11-11 09:27:27 +0100140 TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a);
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +0200141 int32_t offs;
Pascal Brandc639ac82015-07-02 08:53:34 +0200142
143 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
144 (TEE_PARAM_TYPE_VALUE_INPUT,
145 TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE,
146 TEE_PARAM_TYPE_NONE));
147
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +0200148 offs = *(int32_t *)&params[0].value.b;
149 res = TEE_SeekObjectData(o, offs, params[1].value.a);
Jens Wiklanderc5231592015-11-11 09:27:27 +0100150 if (res != TEE_SUCCESS)
151 return res;
152 res = TEE_GetObjectInfo1(o, &info);
Pascal Brandc639ac82015-07-02 08:53:34 +0200153
154 params[1].value.b = info.dataPosition;
155
156 return res;
157}
158
159TEE_Result ta_storage_cmd_unlink(uint32_t param_types, TEE_Param params[4])
160{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100161 TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a);
162
Pascal Brandc639ac82015-07-02 08:53:34 +0200163 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
164 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
165 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
166
Jens Wiklanderc5231592015-11-11 09:27:27 +0100167 TEE_CloseAndDeletePersistentObject1(o);
Pascal Brandc639ac82015-07-02 08:53:34 +0200168
169 return TEE_SUCCESS;
170}
171
172TEE_Result ta_storage_cmd_rename(uint32_t param_types, TEE_Param params[4])
173{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100174 TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a);
175
Pascal Brandc639ac82015-07-02 08:53:34 +0200176 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
177 (TEE_PARAM_TYPE_VALUE_INPUT,
178 TEE_PARAM_TYPE_MEMREF_INPUT, TEE_PARAM_TYPE_NONE,
179 TEE_PARAM_TYPE_NONE));
180
Jens Wiklanderc5231592015-11-11 09:27:27 +0100181 return TEE_RenamePersistentObject(o, params[1].memref.buffer,
Pascal Brandc639ac82015-07-02 08:53:34 +0200182 params[1].memref.size);
183}
184
185TEE_Result ta_storage_cmd_trunc(uint32_t param_types, TEE_Param params[4])
186{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100187 TEE_ObjectHandle o = VAL2HANDLE(params[0].value.a);
188
Pascal Brandc639ac82015-07-02 08:53:34 +0200189 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
190 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
191 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
192
Jens Wiklanderc5231592015-11-11 09:27:27 +0100193 return TEE_TruncateObjectData(o, params[0].value.b);
Pascal Brandc639ac82015-07-02 08:53:34 +0200194}
195
196TEE_Result ta_storage_cmd_alloc_enum(uint32_t param_types, TEE_Param params[4])
197{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100198 TEE_Result res;
199 TEE_ObjectEnumHandle oe;
200
Pascal Brandc639ac82015-07-02 08:53:34 +0200201 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
202 (TEE_PARAM_TYPE_VALUE_OUTPUT, TEE_PARAM_TYPE_NONE,
203 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
204
Jens Wiklanderc5231592015-11-11 09:27:27 +0100205 res = TEE_AllocatePersistentObjectEnumerator(&oe);
206 params[0].value.a = (uintptr_t)oe;
207 return res;
Pascal Brandc639ac82015-07-02 08:53:34 +0200208}
209
210TEE_Result ta_storage_cmd_free_enum(uint32_t param_types, TEE_Param params[4])
211{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100212 TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a);
213
Pascal Brandc639ac82015-07-02 08:53:34 +0200214 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
215 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
216 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
217
Jens Wiklanderc5231592015-11-11 09:27:27 +0100218 TEE_FreePersistentObjectEnumerator(oe);
Pascal Brandc639ac82015-07-02 08:53:34 +0200219 return TEE_SUCCESS;
220}
221
222TEE_Result ta_storage_cmd_reset_enum(uint32_t param_types, TEE_Param params[4])
223{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100224 TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a);
225
Pascal Brandc639ac82015-07-02 08:53:34 +0200226 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
227 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
228 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
229
Jens Wiklanderc5231592015-11-11 09:27:27 +0100230 TEE_ResetPersistentObjectEnumerator(oe);
Pascal Brandc639ac82015-07-02 08:53:34 +0200231 return TEE_SUCCESS;
232}
233
234TEE_Result ta_storage_cmd_start_enum(uint32_t param_types, TEE_Param params[4])
235{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100236 TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a);
237
Pascal Brandc639ac82015-07-02 08:53:34 +0200238 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
239 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
240 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
241
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200242 return TEE_StartPersistentObjectEnumerator(oe, params[0].value.b);
Pascal Brandc639ac82015-07-02 08:53:34 +0200243}
244
245TEE_Result ta_storage_cmd_next_enum(uint32_t param_types, TEE_Param params[4])
246{
Jens Wiklanderc5231592015-11-11 09:27:27 +0100247 TEE_ObjectEnumHandle oe = VAL2HANDLE(params[0].value.a);
Pascal Brandc603e0d2016-04-25 12:37:18 +0200248 TEE_ObjectInfo *obj;
Jens Wiklanderc5231592015-11-11 09:27:27 +0100249
Pascal Brandc603e0d2016-04-25 12:37:18 +0200250 if (TEE_PARAM_TYPE_GET(param_types, 0) != TEE_PARAM_TYPE_VALUE_INPUT)
251 return TEE_ERROR_BAD_PARAMETERS;
252 if (TEE_PARAM_TYPE_GET(param_types, 2) != TEE_PARAM_TYPE_MEMREF_OUTPUT)
253 return TEE_ERROR_BAD_PARAMETERS;
254 if (TEE_PARAM_TYPE_GET(param_types, 3) != TEE_PARAM_TYPE_NONE)
255 return TEE_ERROR_BAD_PARAMETERS;
Pascal Brandc639ac82015-07-02 08:53:34 +0200256
Pascal Brandc603e0d2016-04-25 12:37:18 +0200257 if (TEE_PARAM_TYPE_GET(param_types, 1) == TEE_PARAM_TYPE_NONE)
258 obj = NULL;
259 else if (TEE_PARAM_TYPE_GET(param_types, 1) ==
260 TEE_PARAM_TYPE_MEMREF_OUTPUT) {
261 if (params[1].memref.size < sizeof(TEE_ObjectInfo)) {
262 params[1].memref.size = sizeof(TEE_ObjectInfo);
263 return TEE_ERROR_SHORT_BUFFER;
264 }
265 params[1].memref.size = sizeof(TEE_ObjectInfo);
266 obj = (TEE_ObjectInfo *)params[1].memref.buffer;
267 } else
268 return TEE_ERROR_BAD_PARAMETERS;
Pascal Brandc639ac82015-07-02 08:53:34 +0200269
270 if (params[2].memref.size < TEE_OBJECT_ID_MAX_LEN)
271 return TEE_ERROR_SHORT_BUFFER;
272
Pascal Brandc603e0d2016-04-25 12:37:18 +0200273 return TEE_GetNextPersistentObject(oe, obj,
274 params[2].memref.buffer,
275 &params[2].memref.size);
Pascal Brandc639ac82015-07-02 08:53:34 +0200276}
Pascal Brand90f23352016-05-19 15:15:47 +0200277
278static TEE_Result check_obj(TEE_ObjectInfo *o1, TEE_ObjectInfo *o2)
279{
280 if ((o1->objectType != o2->objectType) ||
281 (o1->keySize != o2->keySize) ||
282 (o1->maxKeySize != o2->maxKeySize) ||
283 (o1->objectUsage != o2->objectUsage))
284 return TEE_ERROR_GENERIC;
285 return TEE_SUCCESS;
286}
287
288TEE_Result ta_storage_cmd_key_in_persistent(uint32_t param_types,
289 TEE_Param params[4])
290{
291 TEE_Result result = TEE_SUCCESS;
292 TEE_ObjectHandle transient_key = (TEE_ObjectHandle)NULL;
293 TEE_ObjectHandle persistent_key = (TEE_ObjectHandle)NULL;
294 TEE_ObjectHandle key = (TEE_ObjectHandle)NULL;
295 TEE_OperationHandle encrypt_op = (TEE_OperationHandle)NULL;
296 TEE_ObjectInfo keyInfo;
297 TEE_ObjectInfo keyInfo2;
298 TEE_ObjectInfo keyInfo3;
299 uint32_t alg = TEE_ALG_AES_CBC_NOPAD;
300 void *IV = NULL;
301 size_t IVlen = 16;
302 size_t key_size = 256;
303 uint32_t objectID = 1;
304 uint32_t flags = TEE_DATA_FLAG_ACCESS_READ |
305 TEE_DATA_FLAG_ACCESS_WRITE |
306 TEE_DATA_FLAG_ACCESS_WRITE_META |
307 TEE_DATA_FLAG_SHARE_READ |
308 TEE_DATA_FLAG_SHARE_WRITE;
309
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200310 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
311 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
312 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
Pascal Brand90f23352016-05-19 15:15:47 +0200313
314 result = TEE_AllocateTransientObject(TEE_TYPE_AES, key_size,
315 &transient_key);
316 if (result != TEE_SUCCESS) {
317 EMSG("Failed to Allocate transient object handle : 0x%x",
318 result);
319 goto cleanup1;
320 }
321
322 result = TEE_GenerateKey(transient_key, key_size, NULL, 0);
323 if (result != TEE_SUCCESS) {
324 EMSG("Failed to generate a transient key: 0x%x", result);
325 goto cleanup2;
326 }
327
328 TEE_GetObjectInfo1(transient_key, &keyInfo);
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200329 result = TEE_CreatePersistentObject(params[0].value.a,
Pascal Brand90f23352016-05-19 15:15:47 +0200330 &objectID, sizeof(objectID),
331 flags, transient_key, NULL, 0,
332 &persistent_key);
333 if (result != TEE_SUCCESS) {
334 EMSG("Failed to create a persistent key: 0x%x", result);
335 goto cleanup2;
336 }
337
338 TEE_GetObjectInfo1(persistent_key, &keyInfo2);
339 result = check_obj(&keyInfo, &keyInfo2);
340 if (result != TEE_SUCCESS) {
341 EMSG("keyInfo and keyInfo2 are different");
342 goto cleanup2;
343 }
344
345 TEE_CloseObject(persistent_key);
346
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200347 result = TEE_OpenPersistentObject(params[0].value.a,
Pascal Brand90f23352016-05-19 15:15:47 +0200348 &objectID, sizeof(objectID),
349 flags, &key);
350 if (result != TEE_SUCCESS) {
351 EMSG("Failed to open persistent key: 0x%x", result);
352 goto cleanup2;
353 }
354
355 TEE_GetObjectInfo(key, &keyInfo3);
356 result = check_obj(&keyInfo3, &keyInfo2);
357 if (result != TEE_SUCCESS) {
358 EMSG("keyInfo2 and keyInfo3 are different");
359 goto cleanup2;
360 }
361
362 result = TEE_AllocateOperation(&encrypt_op, alg, TEE_MODE_ENCRYPT,
363 keyInfo3.maxObjectSize);
364 if (result != TEE_SUCCESS) {
365 EMSG("Failed to allocate an operation: 0x%x", result);
366 goto cleanup3;
367 }
368
369 result = TEE_SetOperationKey(encrypt_op, key);
370 if (result != TEE_SUCCESS) {
371 EMSG("Failed to set operation key: 0x%x", result);
372 goto cleanup4;
373 }
374
375 IV = TEE_Malloc(IVlen, 0);
376 if (!IV) {
377 EMSG("Out of memory for IV.");
378 result = TEE_ERROR_OUT_OF_MEMORY;
379 goto cleanup4;
380 }
381
382 TEE_CipherInit(encrypt_op, IV, IVlen);
383 TEE_Free(IV);
384
385cleanup4:
386 TEE_FreeOperation(encrypt_op);
387cleanup3:
388 TEE_CloseAndDeletePersistentObject1(key);
389cleanup2:
390 TEE_FreeTransientObject(transient_key);
391cleanup1:
392 return result;
393}
394
Pascal Brand29ee18f2016-05-23 14:13:56 +0200395TEE_Result ta_storage_cmd_loop(uint32_t param_types, TEE_Param params[4])
396{
397 TEE_ObjectHandle object = TEE_HANDLE_NULL;
398 TEE_Result res;
399 int object_id = 0;
400 uint32_t flags = TEE_DATA_FLAG_OVERWRITE |
401 TEE_DATA_FLAG_ACCESS_WRITE_META;
402 int i = 0;
403
Pascal Brand29ee18f2016-05-23 14:13:56 +0200404 (void)params;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200405 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
406 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
407 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
Pascal Brand29ee18f2016-05-23 14:13:56 +0200408
409 for (i = 0; i < 20; i++) {
410 DMSG("\n\nLOOP : %d", i);
411 object = TEE_HANDLE_NULL;
412 object_id = i;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200413 res = TEE_CreatePersistentObject(params[0].value.a,
Pascal Brand29ee18f2016-05-23 14:13:56 +0200414 &object_id, sizeof(int), flags,
415 TEE_HANDLE_NULL, NULL, 0,
416 &object);
417
418 if (res != TEE_SUCCESS) {
419 EMSG("FAIL");
420 return res;
421 }
422
423 res = TEE_CloseAndDeletePersistentObject1(object);
424 if (res != TEE_SUCCESS) {
425 EMSG("FAIL");
426 return res;
427 }
428 }
429
430 return TEE_SUCCESS;
431}
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +0200432
433TEE_Result ta_storage_cmd_restrict_usage(uint32_t param_types,
434 TEE_Param params[4])
435{
436 TEE_ObjectHandle o;
437
438 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
439 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
440 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
441
442 o = (TEE_ObjectHandle)(uintptr_t)params[0].value.a;
443 TEE_RestrictObjectUsage1(o, params[0].value.b);
444 return TEE_SUCCESS;
445}
446
447TEE_Result ta_storage_cmd_alloc_obj(uint32_t param_types, TEE_Param params[4])
448{
449 TEE_Result res;
450 TEE_ObjectHandle o;
451
452 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
453 (TEE_PARAM_TYPE_VALUE_INPUT,
454 TEE_PARAM_TYPE_VALUE_OUTPUT,
455 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
456
457 res = TEE_AllocateTransientObject(params[0].value.a, params[0].value.b,
458 &o);
459 params[1].value.a = (uint32_t)(uintptr_t)o;
460 return res;
461}
462
463TEE_Result ta_storage_cmd_free_obj(uint32_t param_types, TEE_Param params[4])
464{
465 TEE_ObjectHandle o;
466
467 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
468 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
469 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
470
471 o = (TEE_ObjectHandle)(uintptr_t)params[0].value.a;
472 TEE_FreeTransientObject(o);
473 return TEE_SUCCESS;
474}
475
476TEE_Result ta_storage_cmd_reset_obj(uint32_t param_types, TEE_Param params[4])
477{
478 TEE_ObjectHandle o;
479
480 ASSERT_PARAM_TYPE(TEE_PARAM_TYPES
481 (TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE,
482 TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE));
483
484 o = (TEE_ObjectHandle)(uintptr_t)params[0].value.a;
485 TEE_ResetTransientObject(o);
486 return TEE_SUCCESS;
487}