blob: dacadff83db75f71f37e9649a40ad281642de286 [file] [log] [blame]
Pascal Brandc639ac82015-07-02 08:53:34 +02001/*
2 * Copyright (c) 2014, STMicroelectronics International N.V.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <string.h>
15#include <stdio.h>
16
17#include <adbg.h>
18#include <xtest_test.h>
19#include <xtest_helpers.h>
20
21#include <tee_client_api.h>
22#include <ta_storage.h>
23#include <tee_api_defines.h>
24#include <tee_api_types.h>
Jerome Forissiere3688342015-09-24 10:45:17 -070025#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +020026#include <TTA_DS_protocol.h>
27#endif
Pascal Brandc639ac82015-07-02 08:53:34 +020028
29static uint8_t file_00[] = {
30 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
31 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
32 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
33 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
34};
35
36static uint8_t file_01[] = {
37 0x01, 0x00
38};
39
40static uint8_t file_02[] = {
41 0x02, 0x11, 0x02
42};
43
44static uint8_t file_03[] = {
45 0x03, 0x13, 0x03
46};
47
Pascal Brandeb84c442016-04-19 17:49:49 +020048static uint8_t file_04[] = {
49 0x00, 0x01, 0x02
50};
51
Pascal Brandc639ac82015-07-02 08:53:34 +020052static uint8_t data_00[] = {
53 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
54 0x00, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
55 0x00, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
56 0x00, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x00
57};
58
59static uint8_t data_01[] = {
60 0x01, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
61 0x01, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
62 0x01, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
63 0x01, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x01
64};
65
66static TEEC_Result fs_open(TEEC_Session *sess, void *id, uint32_t id_size,
67 uint32_t flags, uint32_t *obj)
68{
Aijun Sun473d9072015-08-06 15:24:49 +080069 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020070 TEEC_Result res;
71 uint32_t org;
72
73 op.params[0].tmpref.buffer = id;
74 op.params[0].tmpref.size = id_size;
75 op.params[1].value.a = flags;
76 op.params[1].value.b = 0;
77
78 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
79 TEEC_VALUE_INOUT, TEEC_NONE,
80 TEEC_NONE);
81
82 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_OPEN, &op, &org);
83
84 if (res == TEEC_SUCCESS)
85 *obj = op.params[1].value.b;
86
87 return res;
88}
89
90static TEEC_Result fs_create(TEEC_Session *sess, void *id, uint32_t id_size,
91 uint32_t flags, uint32_t attr, void *data,
92 uint32_t data_size, uint32_t *obj)
93{
Aijun Sun473d9072015-08-06 15:24:49 +080094 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020095 TEEC_Result res;
96 uint32_t org;
97
98 op.params[0].tmpref.buffer = id;
99 op.params[0].tmpref.size = id_size;
100 op.params[1].value.a = flags;
101 op.params[1].value.b = 0;
102 op.params[2].value.a = attr;
103 op.params[2].value.b = 0;
104 op.params[3].tmpref.buffer = data;
105 op.params[3].tmpref.size = data_size;
106
107 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
108 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
109 TEEC_MEMREF_TEMP_INPUT);
110
111 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE, &op, &org);
112
113 if (res == TEEC_SUCCESS)
114 *obj = op.params[1].value.b;
115
116 return res;
117}
118
Pascal Brandeb84c442016-04-19 17:49:49 +0200119static TEEC_Result fs_create_overwrite(TEEC_Session *sess, void *id,
120 uint32_t id_size)
121{
122 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
123 TEEC_Result res;
124 uint32_t org;
125
126 op.params[0].tmpref.buffer = id;
127 op.params[0].tmpref.size = id_size;
128
129 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
130 TEEC_NONE, TEEC_NONE,
131 TEEC_NONE);
132
133 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE_OVERWRITE, &op, &org);
134
135 return res;
136}
137
Pascal Brandc639ac82015-07-02 08:53:34 +0200138static TEEC_Result fs_close(TEEC_Session *sess, uint32_t obj)
139{
Aijun Sun473d9072015-08-06 15:24:49 +0800140 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200141 uint32_t org;
142
143 op.params[0].value.a = obj;
144
145 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
146 TEEC_NONE, TEEC_NONE);
147
148 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CLOSE, &op, &org);
149}
150
151static TEEC_Result fs_read(TEEC_Session *sess, uint32_t obj, void *data,
152 uint32_t data_size, uint32_t *count)
153{
154 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800155 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200156 uint32_t org;
157
158 op.params[0].tmpref.buffer = data;
159 op.params[0].tmpref.size = data_size;
160 op.params[1].value.a = obj;
161 op.params[1].value.b = 0;
162
163 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
164 TEEC_VALUE_INOUT, TEEC_NONE,
165 TEEC_NONE);
166
167 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_READ, &op, &org);
168
169 if (res == TEEC_SUCCESS)
170 *count = op.params[1].value.b;
171
172 return res;
173}
174
175static TEEC_Result fs_write(TEEC_Session *sess, uint32_t obj, void *data,
176 uint32_t data_size)
177{
Aijun Sun473d9072015-08-06 15:24:49 +0800178 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200179 uint32_t org;
180
181 op.params[0].tmpref.buffer = data;
182 op.params[0].tmpref.size = data_size;
183 op.params[1].value.a = obj;
184 op.params[1].value.b = 0;
185
186 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
187 TEEC_VALUE_INPUT, TEEC_NONE,
188 TEEC_NONE);
189
190 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_WRITE, &op, &org);
191}
192
193static TEEC_Result fs_seek(TEEC_Session *sess, uint32_t obj, int32_t offset,
194 int32_t whence)
195{
Aijun Sun473d9072015-08-06 15:24:49 +0800196 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200197 uint32_t org;
198
199 op.params[0].value.a = obj;
200 op.params[0].value.b = offset;
201 op.params[1].value.a = whence;
202
203 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INOUT,
204 TEEC_NONE, TEEC_NONE);
205
206 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_SEEK, &op, &org);
207}
208
209static TEEC_Result fs_unlink(TEEC_Session *sess, uint32_t obj)
210{
Aijun Sun473d9072015-08-06 15:24:49 +0800211 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200212 uint32_t org;
213
214 op.params[0].value.a = obj;
215
216 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
217 TEEC_NONE, TEEC_NONE);
218
219 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_UNLINK, &op, &org);
220}
221
222static TEEC_Result fs_trunc(TEEC_Session *sess, uint32_t obj, uint32_t len)
223{
Aijun Sun473d9072015-08-06 15:24:49 +0800224 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200225 uint32_t org;
226
227 op.params[0].value.a = obj;
228 op.params[0].value.b = len;
229
230 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
231 TEEC_NONE, TEEC_NONE);
232
233 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_TRUNC, &op, &org);
234}
235
236static TEEC_Result fs_rename(TEEC_Session *sess, uint32_t obj, void *id,
237 uint32_t id_size)
238{
Aijun Sun473d9072015-08-06 15:24:49 +0800239 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200240 uint32_t org;
241
242 op.params[0].value.a = obj;
243 op.params[1].tmpref.buffer = id;
244 op.params[1].tmpref.size = id_size;
245
246 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
247 TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
248 TEEC_NONE);
249
250 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RENAME, &op, &org);
251}
252
253static TEEC_Result fs_alloc_enum(TEEC_Session *sess, uint32_t *e)
254{
255 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800256 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200257 uint32_t org;
258
259 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
260 TEEC_NONE, TEEC_NONE);
261
262 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_ENUM, &op, &org);
263
264 if (res == TEEC_SUCCESS)
265 *e = op.params[0].value.a;
266
267 return res;
268}
269
270static TEEC_Result fs_free_enum(TEEC_Session *sess, uint32_t e)
271{
Aijun Sun473d9072015-08-06 15:24:49 +0800272 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200273 uint32_t org;
274
275 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
276 TEEC_NONE);
277
278 op.params[0].value.a = e;
279
280 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_ENUM, &op, &org);
281}
282
283static TEEC_Result fs_start_enum(TEEC_Session *sess, uint32_t e)
284{
Aijun Sun473d9072015-08-06 15:24:49 +0800285 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200286 uint32_t org;
287
288 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
289 TEEC_NONE, TEEC_NONE);
290
291 op.params[0].value.a = e;
292
293 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_START_ENUM, &op, &org);
294}
295
296static TEEC_Result fs_next_enum(TEEC_Session *sess, uint32_t e, void *obj_info,
297 size_t info_size, void *id, uint32_t id_size)
298{
Aijun Sun473d9072015-08-06 15:24:49 +0800299 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200300 uint32_t org;
301
Pascal Brandc603e0d2016-04-25 12:37:18 +0200302 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brandc639ac82015-07-02 08:53:34 +0200303 TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE);
Pascal Brandc603e0d2016-04-25 12:37:18 +0200304 if (obj_info && info_size)
305 op.paramTypes |= (TEEC_MEMREF_TEMP_OUTPUT << 4);
Pascal Brandc639ac82015-07-02 08:53:34 +0200306
307 op.params[0].value.a = e;
308 op.params[1].tmpref.buffer = obj_info;
309 op.params[1].tmpref.size = info_size;
310 op.params[2].tmpref.buffer = id;
311 op.params[2].tmpref.size = id_size;
312
313 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_NEXT_ENUM, &op, &org);
314}
315
James Kung98c0ba12015-09-09 15:51:59 +0800316/* trunc */
317static void test_truncate_file_length(ADBG_Case_t *c)
318{
319 TEEC_Session sess;
320 uint32_t obj;
321 uint8_t out[10] = { 0 };
322 uint32_t count;
323 uint32_t orig;
324
325 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
326 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
327 return;
328
329 /* create */
330 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
331 fs_create(&sess, file_01, sizeof(file_01),
332 TEE_DATA_FLAG_ACCESS_WRITE |
333 TEE_DATA_FLAG_ACCESS_READ |
334 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
335 sizeof(data_00), &obj)))
336 goto exit;
337
338 /* trunc */
339 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 10)))
340 goto exit;
341
342 /* seek */
343 if (!ADBG_EXPECT_TEEC_SUCCESS(
344 c, fs_seek(&sess, obj, 5, TEE_DATA_SEEK_SET)))
345 goto exit;
346
347 /* verify */
348 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
349 goto exit;
350
351 /* check buffer */
352 (void)ADBG_EXPECT_BUFFER(c, &data_00[5], 5, out, count);
353
354 /* clean */
355 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
356 goto exit;
357
358exit:
359 TEEC_CloseSession(&sess);
360}
361
362/* extend */
363static void test_extend_file_length(ADBG_Case_t *c)
364{
365 TEEC_Session sess;
366 uint32_t obj;
367 uint8_t out[10] = { 0 };
368 uint8_t expect[10] = { 0 };
369 uint32_t count;
370 uint32_t orig;
371
372 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
373 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
374 return;
375
376 /* create */
377 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
378 fs_create(&sess, file_01, sizeof(file_01),
379 TEE_DATA_FLAG_ACCESS_WRITE |
380 TEE_DATA_FLAG_ACCESS_READ |
381 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
382 sizeof(data_00), &obj)))
383 goto exit;
384
385 /* extend */
386 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 40)))
387 goto exit;
388
389 /* seek */
390 if (!ADBG_EXPECT_TEEC_SUCCESS(
391 c, fs_seek(&sess, obj, 30, TEE_DATA_SEEK_SET)))
392 goto exit;
393
394 /* verify */
395 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
396 goto exit;
397
398 /* check buffer */
399 expect[0] = data_00[30];
400 expect[1] = data_00[31];
401 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
402
403 /* clean */
404 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
405 goto exit;
406
407exit:
408 TEEC_CloseSession(&sess);
409}
410
411/* file hole */
412static void test_file_hole(ADBG_Case_t *c)
413{
414 TEEC_Session sess;
415 uint32_t obj;
416 uint8_t out[10] = { 0 };
417 uint8_t expect[10] = { 0 };
418 uint32_t count;
419 uint32_t orig;
420
421 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
422 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
423 return;
424
425 /* create */
426 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
427 fs_create(&sess, file_01, sizeof(file_01),
428 TEE_DATA_FLAG_ACCESS_WRITE |
429 TEE_DATA_FLAG_ACCESS_READ |
430 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
431 sizeof(data_00), &obj)))
432 goto exit;
433
434 /* seek */
435 if (!ADBG_EXPECT_TEEC_SUCCESS(
436 c, fs_seek(&sess, obj, 80, TEE_DATA_SEEK_SET)))
437 goto exit;
438
439 /* write */
440 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_write(&sess, obj, data_00,
441 sizeof(data_00))))
442 goto exit;
443
444 /* seek */
445 if (!ADBG_EXPECT_TEEC_SUCCESS(
446 c, fs_seek(&sess, obj, 74, TEE_DATA_SEEK_SET)))
447 goto exit;
448
449 /* verify */
450 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
451 goto exit;
452
453 /* check buffer */
454 expect[6] = data_00[0];
455 expect[7] = data_00[1];
456 expect[8] = data_00[2];
457 expect[9] = data_00[3];
458 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
459
460 /* clean */
461 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
462 goto exit;
463
464exit:
465 TEEC_CloseSession(&sess);
466}
467
Jerome Forissiere3688342015-09-24 10:45:17 -0700468#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +0200469static TEEC_Result ds_open_access_conf(TEEC_Session *sess)
470{
471 TEEC_Operation op;
472 uint32_t org;
473
474 op.paramTypes = TEEC_PARAM_TYPES(
475 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
476
477 return TEEC_InvokeCommand(
478 sess, CMD_CreatePersistentObject_AccessConflict, &op, &org);
479}
480
481static TEEC_Result ds_res_obj_panic(TEEC_Session *sess)
482{
483 TEEC_Operation op;
484 uint32_t org;
485
486 op.paramTypes = TEEC_PARAM_TYPES(
487 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
488
489 return TEEC_InvokeCommand(
490 sess, CMD_RestrictObjectUsagePanic, &op, &org);
491}
492
493static TEEC_Result ds_seek_obj_inv_handle(TEEC_Session *sess)
494{
495 TEEC_Operation op;
496 uint32_t org;
497
498 op.paramTypes = TEEC_PARAM_TYPES(
499 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
500
501 op.params[0].value.a = CASE_DATA_OBJECT_NOT_PERSISTENT;
502
503 return TEEC_InvokeCommand(
504 sess, CMD_SeekObjectData_panic, &op, &org);
505}
506
507static TEEC_Result ds_seek_obj_bad_handle(TEEC_Session *sess)
508{
509 TEEC_Operation op;
510 uint32_t org;
511
512 op.paramTypes = TEEC_PARAM_TYPES(
513 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
514
515 op.params[0].value.a = CASE_DATA_BAD_HANDLE;
516
517 return TEEC_InvokeCommand(
518 sess, CMD_SeekObjectData_panic, &op, &org);
519}
520
521static TEEC_Result ds_seek_gp(
522 TEEC_Session *sess, TEE_Whence wh, uint32_t wh_off, uint32_t set_off,
523 void *in, size_t in_size, void *out, size_t out_size)
524{
525 TEEC_Operation op;
526 uint32_t org;
527
528 op.paramTypes = TEEC_PARAM_TYPES(
529 TEEC_VALUE_INPUT, TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
530 TEEC_MEMREF_TEMP_OUTPUT);
531
532 op.params[0].value.a = wh;
533 op.params[0].value.b = wh_off;
534 op.params[1].value.a = set_off;
535 op.params[2].tmpref.buffer = in;
536 op.params[2].tmpref.size = in_size;
537 op.params[3].tmpref.buffer = out;
538 op.params[3].tmpref.size = out_size;
539
540 return TEEC_InvokeCommand(sess, CMD_SeekWriteReadObjectData, &op, &org);
541}
542
543static TEEC_Result ds_init_object_and_attributes(TEEC_Session *sess,
544 uint32_t obj_type, uint32_t obj_size, const void *attr_meta,
545 size_t attr_meta_len, const void *attr_data, size_t attr_data_len,
546 uint32_t option)
547{
548 TEEC_Operation op;
549 uint32_t org;
550
551 op.paramTypes = TEEC_PARAM_TYPES(
552 TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
553 TEEC_MEMREF_TEMP_INPUT, TEEC_VALUE_INPUT);
554
555 op.params[0].value.a = obj_type;
556 op.params[0].value.b = obj_size;
557 op.params[1].tmpref.buffer = (void *)attr_meta;
558 op.params[1].tmpref.size = attr_meta_len;
559 op.params[2].tmpref.buffer = (void *)attr_data;
560 op.params[2].tmpref.size = attr_data_len;
561 op.params[3].value.a = option;
562
563 return TEEC_InvokeCommand(sess, CMD_InitObjectAndAttributes, &op, &org);
564}
565
566static TEEC_Result ds_rename_access_conflict(TEEC_Session *sess)
567{
568 TEEC_Operation op;
569 uint32_t org;
570
571 op.paramTypes = TEEC_PARAM_TYPES(
572 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
573
574 return TEEC_InvokeCommand(
575 sess, CMD_RenamePersistentObject_AccessConflict, &op, &org);
576}
577
578static TEEC_Result ds_start_enum_no_item(TEEC_Session *sess)
579{
580 TEEC_Operation op;
581 uint32_t org;
582 TEEC_Result res;
583
584 op.paramTypes = TEEC_PARAM_TYPES(
585 TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
586
587 res = TEEC_InvokeCommand(
588 sess, CMD_StartNGetPersistentObjectEnumerator_itemNotFound, &op, &org);
589
590 if (res != TEEC_SUCCESS)
591 return res;
592
593 if (op.params[0].value.a != 0 || op.params[0].value.b != 0)
594 return TEEC_ERROR_GENERIC;
595
596 return res;
597}
598
599static TEEC_Result ds_rename_success(TEEC_Session *sess)
600{
601 TEEC_Operation op;
602 uint32_t org;
603
604 op.paramTypes = TEEC_PARAM_TYPES(
605 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
606
607 return TEEC_InvokeCommand(
608 sess, CMD_RenamePersistentObject_Success, &op, &org);
609}
610
611static TEEC_Result ds_null_close_free_reset(TEEC_Session *sess)
612{
613 TEEC_Operation op;
614 uint32_t org;
615
616 op.paramTypes = TEEC_PARAM_TYPES(
617 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
618
619 return TEEC_InvokeCommand(
620 sess, CMD_CloseFreeAndResetObjectSuccessHandleNull, &op, &org);
621}
622#endif
623
Pascal Brandc639ac82015-07-02 08:53:34 +0200624/* create */
625static void xtest_tee_test_6001(ADBG_Case_t *c)
626{
627 TEEC_Session sess;
628 uint32_t obj;
629 uint32_t orig;
630
631 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
632 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
633 return;
634
635 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
636 fs_create(&sess, file_00, sizeof(file_00),
637 TEE_DATA_FLAG_ACCESS_WRITE |
638 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
639 sizeof(data_00), &obj)))
640 goto exit;
641
642 /* clean */
643 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
644 goto exit;
645
646exit:
647 TEEC_CloseSession(&sess);
648}
649
650/* open */
651static void xtest_tee_test_6002(ADBG_Case_t *c)
652{
653 TEEC_Session sess;
654 uint32_t obj;
655 uint32_t orig;
656
657 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
658 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
659 return;
660
661 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
662 fs_create(&sess, file_01, sizeof(file_01),
663 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_00,
664 sizeof(data_00), &obj)))
665 goto exit;
666
667 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
668 goto exit;
669
670 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
671 fs_open(&sess, file_01, sizeof(file_01),
672 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
673 goto exit;
674
675 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
676 goto exit;
677
678 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
679 fs_open(&sess, file_01, sizeof(file_01),
680 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
681 goto exit;
682
683 /* clean */
684 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
685 goto exit;
686
687exit:
688 TEEC_CloseSession(&sess);
689}
690
691/* read */
692static void xtest_tee_test_6003(ADBG_Case_t *c)
693{
694 TEEC_Session sess;
695 uint32_t obj;
696 uint8_t out[10] = { 0 };
697 uint32_t count;
698 uint32_t orig;
699
700 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
701 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
702 return;
703
704 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
705 fs_create(&sess, file_02, sizeof(file_02),
706 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
707 sizeof(data_01), &obj)))
708 goto exit;
709
710 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
711 goto exit;
712
713 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
714 fs_open(&sess, file_02, sizeof(file_02),
715 TEE_DATA_FLAG_ACCESS_READ |
716 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
717 goto exit;
718
719 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
720 goto exit;
721
722 (void)ADBG_EXPECT_BUFFER(c, data_01, 10, out, count);
723
724 /* clean */
725 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
726 goto exit;
727
728exit:
729 TEEC_CloseSession(&sess);
730}
731
732/* write */
733static void xtest_tee_test_6004(ADBG_Case_t *c)
734{
735 TEEC_Session sess;
736 uint32_t obj;
737 uint8_t out[10] = { 0 };
738 uint32_t count;
739 uint32_t orig;
740
741 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
742 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
743 return;
744
745 /* create */
746 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
747 fs_create(&sess, file_02, sizeof(file_02),
748 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
749 sizeof(data_01), &obj)))
750 goto exit;
751
752 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
753 goto exit;
754
755 /* write new data */
756 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
757 fs_open(&sess, file_02, sizeof(file_02),
758 TEE_DATA_FLAG_ACCESS_WRITE, &obj)))
759 goto exit;
760
761 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
762 fs_write(&sess, obj, data_00, sizeof(data_00))))
763 goto exit;
764
765 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
766 goto exit;
767
768 /* verify */
769 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
770 fs_open(&sess, file_02, sizeof(file_02),
771 TEE_DATA_FLAG_ACCESS_READ |
772 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
773 goto exit;
774
775 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
776 goto exit;
777
778 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
779
780 /* clean */
781 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
782 goto exit;
783
784exit:
785 TEEC_CloseSession(&sess);
786}
787
788/* seek */
789static void xtest_tee_test_6005(ADBG_Case_t *c)
790{
791 TEEC_Session sess;
792 uint32_t obj;
793 uint8_t out[10] = { 0 };
794 uint32_t count;
795 uint32_t orig;
796
797 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
798 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
799 return;
800
801 /* create */
802 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
803 fs_create(&sess, file_01, sizeof(file_01),
804 TEE_DATA_FLAG_ACCESS_WRITE |
805 TEE_DATA_FLAG_ACCESS_READ |
806 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
807 sizeof(data_00), &obj)))
808 goto exit;
809
810 /* seek */
811 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
812 fs_seek(&sess, obj, 10, TEE_DATA_SEEK_SET)))
813 goto exit;
814
815 /* verify */
816 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
817 goto exit;
818
819 (void)ADBG_EXPECT_BUFFER(c, &data_00[10], 10, out, count);
820
821 /* clean */
822 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
823 goto exit;
824
825exit:
826 TEEC_CloseSession(&sess);
827}
828
829/* unlink */
830static void xtest_tee_test_6006(ADBG_Case_t *c)
831{
832 TEEC_Session sess;
833 uint32_t obj;
834 uint32_t orig;
835
836 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
837 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
838 return;
839
840 /* create */
841 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
842 fs_create(&sess, file_01, sizeof(file_01),
843 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
844 sizeof(data_00), &obj)))
845 goto exit;
846
847 /* del & close */
848 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
849 goto exit;
850
851 /* check result */
852 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
853 fs_open(&sess, file_01, sizeof(file_01),
854 TEE_DATA_FLAG_ACCESS_READ, &obj)))
855 goto exit;
856
857exit:
858 TEEC_CloseSession(&sess);
859}
860
Pascal Brandc639ac82015-07-02 08:53:34 +0200861static void xtest_tee_test_6007(ADBG_Case_t *c)
862{
James Kung98c0ba12015-09-09 15:51:59 +0800863 Do_ADBG_BeginSubCase(c, "Test truncate file length");
864 test_truncate_file_length(c);
865 Do_ADBG_EndSubCase(c, "Test truncate file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200866
James Kung98c0ba12015-09-09 15:51:59 +0800867 Do_ADBG_BeginSubCase(c, "Test extend file length");
868 test_extend_file_length(c);
869 Do_ADBG_EndSubCase(c, "Test extend file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200870
James Kung98c0ba12015-09-09 15:51:59 +0800871 Do_ADBG_BeginSubCase(c, "Test file hole");
872 test_file_hole(c);
873 Do_ADBG_EndSubCase(c, "Test file hole");
Pascal Brandc639ac82015-07-02 08:53:34 +0200874}
875
876static void xtest_tee_test_6008(ADBG_Case_t *c)
877{
878 TEEC_Session sess;
879 uint32_t obj;
880 uint8_t out[10] = { 0 };
881 uint32_t count;
882 uint32_t orig;
883
884 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
885 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
886 return;
887
888 /* create */
889 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
890 fs_create(&sess, file_02, sizeof(file_02),
891 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
892 sizeof(data_01), &obj)))
893 goto exit;
894
895 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
896 goto exit;
897
898 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
899 fs_open(&sess, file_02, sizeof(file_02),
900 TEE_DATA_FLAG_ACCESS_WRITE |
901 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
902 goto exit;
903
904 /* write new data */
905 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
906 fs_write(&sess, obj, data_00, sizeof(data_00))))
907 goto exit;
908
909 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
910 fs_rename(&sess, obj, file_03, sizeof(file_03))))
911 goto exit;
912
913 /* close */
914 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
915 goto exit;
916
917 /* verify */
918 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
919 fs_open(&sess, file_03, sizeof(file_03),
920 TEE_DATA_FLAG_ACCESS_READ |
921 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
922 goto exit;
923
924 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
925 goto exit;
926
927 /* check buffer */
928 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
929
930 /* clean */
931 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
932 goto exit;
933
934exit:
935 TEEC_CloseSession(&sess);
936}
937
938static void xtest_tee_test_6009(ADBG_Case_t *c)
939{
940 TEEC_Session sess;
941 uint32_t obj0;
942 uint32_t obj1;
943 uint32_t obj2;
944 uint32_t e = 0;
945 uint8_t info[200];
946 uint8_t id[200];
947 uint32_t orig;
948
949 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
950 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
951 return;
952
953 /* create file 00 */
954 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
955 fs_create(&sess, file_00, sizeof(file_00),
956 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
957 sizeof(data_01), &obj0)))
958 goto exit;
959
960 /* create file 01 */
961 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
962 fs_create(&sess, file_01, sizeof(file_01),
963 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
964 sizeof(data_01), &obj1)))
965 goto exit;
966
967 /* create file 02 */
968 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
969 fs_create(&sess, file_02, sizeof(file_02),
970 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
971 sizeof(data_01), &obj2)))
972 goto exit;
973
974 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj0)))
975 goto exit;
976
977 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj1)))
978 goto exit;
979
980 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj2)))
981 goto exit;
982
983 /* iterate */
984 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e)))
985 goto exit;
986
987 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_start_enum(&sess, e)))
988 goto exit;
989
990 /* get 00 */
991 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
992 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
993 goto exit;
994
995 /* get 01 */
996 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc603e0d2016-04-25 12:37:18 +0200997 fs_next_enum(&sess, e, NULL, 0, id, sizeof(id))))
Pascal Brandc639ac82015-07-02 08:53:34 +0200998 goto exit;
999
1000 /* get 02 */
1001 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1002 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1003 goto exit;
1004
1005 /* we should not have more files */
1006 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
1007 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1008 goto exit;
1009
1010 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e)))
1011 goto exit;
1012
1013 /* clean */
1014 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1015 fs_open(&sess, file_00, sizeof(file_00),
1016 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj0)))
1017 goto exit;
1018
1019 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj0)))
1020 goto exit;
1021
1022 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1023 fs_open(&sess, file_01, sizeof(file_01),
1024 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj1)))
1025 goto exit;
1026
1027 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj1)))
1028 goto exit;
1029
1030 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1031 fs_open(&sess, file_02, sizeof(file_02),
1032 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj2)))
1033 goto exit;
1034
1035 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj2)))
1036 goto exit;
1037
1038exit:
1039 TEEC_CloseSession(&sess);
1040}
1041
Jerome Forissiere3688342015-09-24 10:45:17 -07001042#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001043static void xtest_tee_test_6010(ADBG_Case_t *c)
1044{
1045 TEEC_Session sess;
1046 uint32_t orig;
1047 uint8_t out[4000] = {0};
1048 uint8_t in[0x12c] = {'b'};
Pascal Brand30844922015-09-17 12:12:42 +02001049 int i;
1050
1051 for (i=0; i<sizeof(in); i++)
1052 in[i] = i;
Pascal Brand8a74e362015-09-10 12:41:52 +02001053
1054 if (!ADBG_EXPECT_TEEC_SUCCESS(
1055 c, xtest_teec_open_session(
1056 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1057 return;
1058
1059 Do_ADBG_BeginSubCase(
1060 c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)");
1061
1062 if (!ADBG_EXPECT_TEEC_RESULT(
1063 c, TEEC_ERROR_ACCESS_CONFLICT, ds_open_access_conf(&sess)))
1064 goto exit;
1065
1066 Do_ADBG_EndSubCase(
1067 c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)");
1068 Do_ADBG_BeginSubCase(
1069 c, "GP DS RestrictObjectUsagePanic (9d-5d-46)");
1070
1071 if (!ADBG_EXPECT_TEEC_RESULT(
1072 c, TEE_ERROR_TARGET_DEAD, ds_res_obj_panic(&sess)))
1073 goto exit;
1074
1075 TEEC_CloseSession(&sess);
1076
1077 Do_ADBG_EndSubCase(
1078 c, "GP DS RestrictObjectUsagePanic (9d-5d-46)");
1079 Do_ADBG_BeginSubCase(
1080 c, "GP DS SeekObjectData BadHandle (9d-c3-c8)");
1081
1082 if (!ADBG_EXPECT_TEEC_SUCCESS(
1083 c, xtest_teec_open_session(
1084 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1085 return;
1086
1087 if (!ADBG_EXPECT_TEEC_RESULT(
1088 c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_bad_handle(&sess)))
1089 goto exit;
1090
1091 TEEC_CloseSession(&sess);
1092
1093 Do_ADBG_EndSubCase(
1094 c, "GP DS SeekObjectData BadHandle (9d-c3-c8)");
1095 Do_ADBG_BeginSubCase(
1096 c, "GP DS SeekObjectData NotPersist (9d-db-4a)");
1097
1098 if (!ADBG_EXPECT_TEEC_SUCCESS(
1099 c, xtest_teec_open_session(
1100 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1101 return;
1102
1103 if (!ADBG_EXPECT_TEEC_RESULT(
1104 c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_inv_handle(&sess)))
1105 goto exit;
1106
1107 TEEC_CloseSession(&sess);
1108
1109 Do_ADBG_EndSubCase(
1110 c, "GP DS SeekObjectData NotPersist (9d-db-4a)");
1111 Do_ADBG_BeginSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)");
1112
1113 if (!ADBG_EXPECT_TEEC_SUCCESS(
1114 c, xtest_teec_open_session(
1115 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1116 return;
1117
1118 if (!ADBG_EXPECT_TEEC_SUCCESS(
1119 c, ds_seek_gp(
1120 &sess, TEE_DATA_SEEK_END, 0, 2, data_00, sizeof(data_00), out,
1121 sizeof(out))))
1122 goto exit;
1123
1124 /* check buffer */
1125 (void)ADBG_EXPECT_BUFFER(
1126 c, data_00, sizeof(data_00), out, sizeof(data_00));
Pascal Brand30844922015-09-17 12:12:42 +02001127 memset(out, 0xab, sizeof(out));
Pascal Brand8a74e362015-09-10 12:41:52 +02001128
1129 if (!ADBG_EXPECT_TEEC_SUCCESS(
1130 c, ds_seek_gp(
Pascal Brand30844922015-09-17 12:12:42 +02001131 &sess, TEE_DATA_SEEK_END, sizeof(in)/2, 0, in, sizeof(in), out,
Pascal Brand8a74e362015-09-10 12:41:52 +02001132 sizeof(out))))
1133 goto exit;
1134
Pascal Brand30844922015-09-17 12:12:42 +02001135 (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2,
1136 out + (sizeof(in) / 2), sizeof(in) / 2);
1137 memset(in, 0, sizeof(in));
1138 (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2,
1139 out, sizeof(in)/2);
1140 memset(out, 0xab, sizeof(out));
Pascal Brand8a74e362015-09-10 12:41:52 +02001141
1142 Do_ADBG_EndSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)");
1143 Do_ADBG_BeginSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)");
1144
1145 if (!ADBG_EXPECT_TEEC_RESULT(
1146 c, TEE_ERROR_ACCESS_CONFLICT, ds_rename_access_conflict(&sess)))
1147 goto exit;
1148
1149 Do_ADBG_EndSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)");
1150 Do_ADBG_BeginSubCase(
1151 c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)");
1152
1153 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_start_enum_no_item(&sess)))
1154 goto exit;
1155
1156 Do_ADBG_EndSubCase(
1157 c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)");
1158 Do_ADBG_BeginSubCase(
1159 c, "GP DS RenamePersistent ReadWrite (9d-19-88)");
1160
1161 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_rename_success(&sess)))
1162 goto exit;
1163
1164 Do_ADBG_EndSubCase(
1165 c, "GP DS RenamePersistent ReadWrite (9d-19-88)");
1166 Do_ADBG_BeginSubCase(
1167 c, "GP DS Close Free Reset Null (9d-6d-87)");
1168
1169 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_null_close_free_reset(&sess)))
1170 goto exit;
1171
1172 Do_ADBG_EndSubCase(
1173 c, "GP DS Close Free Reset Null (9d-6d-87)");
1174
1175exit:
1176 TEEC_CloseSession(&sess);
1177}
1178
1179static void xtest_tee_test_6011(ADBG_Case_t *c)
1180{
1181 TEEC_Session sess;
1182 uint32_t orig;
1183 /*
1184 * Test data from
1185 * Invoke_InitObjectAndAttributes_TEE_TYPE_AES_success_attribute_
1186 * TEE_ATTR_SECRET_VALUE_correct_size (9d-9a-91)
1187 */
1188 static const uint8_t attr_meta[] = {
11890xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
11900x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11910x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11920x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1193 };
1194 static const uint8_t attr_data[] = {
11950x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,
11960x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,
11970xdf,0xf4,
1198 };
1199
1200 if (!ADBG_EXPECT_TEEC_SUCCESS(
1201 c, xtest_teec_open_session(
1202 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1203 return;
1204
1205 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_init_object_and_attributes(&sess,
1206 0xa0000010, 0x100, attr_meta, sizeof(attr_meta), attr_data,
1207 sizeof(attr_data), 0)))
1208 goto exit;
1209
1210exit:
1211 TEEC_CloseSession(&sess);
1212}
1213#endif
1214
Pascal Brandeb84c442016-04-19 17:49:49 +02001215static void xtest_tee_test_6012(ADBG_Case_t *c)
1216{
1217 TEEC_Session sess;
1218 uint32_t orig;
1219 uint32_t obj;
1220
1221 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1222 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1223 return;
1224
1225 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1226 fs_create_overwrite(&sess, file_04, sizeof(file_04))))
1227 goto exit;
1228
1229 TEEC_CloseSession(&sess);
1230
1231 /* re-create the same */
1232 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1233 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1234 return;
1235
1236 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1237 fs_create_overwrite(&sess, file_04, sizeof(file_04))))
1238 goto exit;
1239
1240 /*
1241 * recreate it with an object, and remove it so that xtest 6009
1242 * can be replayed
1243 */
1244 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1245 fs_create(&sess, file_04, sizeof(file_04),
1246 TEE_DATA_FLAG_ACCESS_WRITE |
1247 TEE_DATA_FLAG_ACCESS_WRITE_META | TEE_DATA_FLAG_OVERWRITE, 0, NULL, 0, &obj)))
1248 goto exit;
1249
1250 /* clean */
1251 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
1252 goto exit;
1253
1254exit:
1255 TEEC_CloseSession(&sess);
1256}
1257
Pascal Brand90f23352016-05-19 15:15:47 +02001258static void xtest_tee_test_6013(ADBG_Case_t *c)
1259{
1260 TEEC_Session sess;
1261 uint32_t orig;
1262 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1263
1264 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1265 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1266 return;
1267
1268 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE,
1269 TEEC_NONE, TEEC_NONE);
1270
1271 ADBG_EXPECT_TEEC_SUCCESS(c,
1272 TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_KEY_IN_PERSISTENT,
1273 &op, &orig));
1274
1275 TEEC_CloseSession(&sess);
1276}
1277
Pascal Brandc639ac82015-07-02 08:53:34 +02001278ADBG_CASE_DEFINE(
1279 XTEST_TEE_6001, xtest_tee_test_6001,
1280 /* Title */
1281 "Test TEE_CreatePersistentObject",
1282 /* Short description */
1283 "Short description ...",
1284 /* Requirement IDs */
1285 "TEE-??",
1286 /* How to implement */
1287 "Description of how to implement ..."
1288 );
1289
1290ADBG_CASE_DEFINE(
1291 XTEST_TEE_6002, xtest_tee_test_6002,
1292 /* Title */
1293 "Test TEE_OpenPersistentObject",
1294 /* Short description */
1295 "Short description ...",
1296 /* Requirement IDs */
1297 "TEE-??",
1298 /* How to implement */
1299 "Description of how to implement ..."
1300 );
1301
1302ADBG_CASE_DEFINE(
1303 XTEST_TEE_6003, xtest_tee_test_6003,
1304 /* Title */
1305 "Test TEE_ReadObjectData",
1306 /* Short description */
1307 "Short description ...",
1308 /* Requirement IDs */
1309 "TEE-??",
1310 /* How to implement */
1311 "Description of how to implement ..."
1312 );
1313
1314ADBG_CASE_DEFINE(
1315 XTEST_TEE_6004, xtest_tee_test_6004,
1316 /* Title */
1317 "Test TEE_WriteObjectData",
1318 /* Short description */
1319 "Short description ...",
1320 /* Requirement IDs */
1321 "TEE-??",
1322 /* How to implement */
1323 "Description of how to implement ..."
1324 );
1325
1326ADBG_CASE_DEFINE(
1327 XTEST_TEE_6005, xtest_tee_test_6005,
1328 /* Title */
1329 "Test TEE_SeekObjectData",
1330 /* Short description */
1331 "Short description ...",
1332 /* Requirement IDs */
1333 "TEE-??",
1334 /* How to implement */
1335 "Description of how to implement ..."
1336 );
1337
1338ADBG_CASE_DEFINE(
1339 XTEST_TEE_6006, xtest_tee_test_6006,
1340 /* Title */
1341 "Test TEE_CloseAndDeletePersistentObject",
1342 /* Short description */
1343 "Short description ...",
1344 /* Requirement IDs */
1345 "TEE-??",
1346 /* How to implement */
1347 "Description of how to implement ..."
1348 );
1349
1350ADBG_CASE_DEFINE(
1351 XTEST_TEE_6007, xtest_tee_test_6007,
1352 /* Title */
1353 "Test TEE_TruncateObjectData",
1354 /* Short description */
1355 "Short description ...",
1356 /* Requirement IDs */
1357 "TEE-??",
1358 /* How to implement */
1359 "Description of how to implement ..."
1360 );
1361
1362ADBG_CASE_DEFINE(
1363 XTEST_TEE_6008, xtest_tee_test_6008,
1364 /* Title */
1365 "Test TEE_RenamePersistentObject",
1366 /* Short description */
1367 "Short description ...",
1368 /* Requirement IDs */
1369 "TEE-??",
1370 /* How to implement */
1371 "Description of how to implement ..."
1372 );
1373
1374ADBG_CASE_DEFINE(
1375 XTEST_TEE_6009, xtest_tee_test_6009,
1376 /* Title */
1377 "Test TEE Internal API Persistent Object Enumeration Functions",
1378 /* Short description */
1379 "Short description ...",
1380 /* Requirement IDs */
1381 "TEE-??",
1382 /* How to implement */
1383 "Description of how to implement ..."
1384 );
Pascal Brand8a74e362015-09-10 12:41:52 +02001385
Jerome Forissiere3688342015-09-24 10:45:17 -07001386#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001387ADBG_CASE_DEFINE(
1388 XTEST_TEE_6010, xtest_tee_test_6010,
1389 /* Title */
1390 "Test TEE GP TTA DS storage",
1391 /* Short description */
1392 "Short description ...",
1393 /* Requirement IDs */
1394 "TEE-??",
1395 /* How to implement */
1396 "Description of how to implement ..."
1397);
1398
1399ADBG_CASE_DEFINE(
1400 XTEST_TEE_6011, xtest_tee_test_6011,
1401 /* Title */
1402 "Test TEE GP TTA DS init objects",
1403 /* Short description */
1404 "Short description ...",
1405 /* Requirement IDs */
1406 "TEE-??",
1407 /* How to implement */
1408 "Description of how to implement ..."
1409);
1410#endif
Pascal Brandeb84c442016-04-19 17:49:49 +02001411
1412ADBG_CASE_DEFINE(
1413 XTEST_TEE_6012, xtest_tee_test_6012,
1414 /* Title */
1415 "Test TEE GP TTA DS init objects",
1416 /* Short description */
1417 "Short description ...",
1418 /* Requirement IDs */
1419 "TEE-??",
1420 /* How to implement */
1421 "Description of how to implement ..."
1422);
Pascal Brand90f23352016-05-19 15:15:47 +02001423
1424ADBG_CASE_DEFINE(
1425 XTEST_TEE_6013, xtest_tee_test_6013,
1426 /* Title */
1427 "Key usage in Persistent objects",
1428 /* Short description */
1429 "Short description ...",
1430 /* Requirement IDs */
1431 "TEE-??",
1432 /* How to implement */
1433 "Description of how to implement ..."
1434);