blob: 5ad58dac1bc98a7c6d0705a880452fe79c23476a [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>
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +080016#include <pthread.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020017
18#include <adbg.h>
19#include <xtest_test.h>
20#include <xtest_helpers.h>
21
22#include <tee_client_api.h>
23#include <ta_storage.h>
24#include <tee_api_defines.h>
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020025#include <tee_api_defines_extensions.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020026#include <tee_api_types.h>
Jerome Forissiere3688342015-09-24 10:45:17 -070027#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +020028#include <TTA_DS_protocol.h>
29#endif
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020030#include <util.h>
31
32static uint32_t storage_ids[] = {
33 TEE_STORAGE_PRIVATE,
34#ifdef CFG_REE_FS
35 TEE_STORAGE_PRIVATE_REE,
36#endif
37#ifdef CFG_RPMB_FS
38 TEE_STORAGE_PRIVATE_RPMB,
39#endif
Jerome Forissiera966bb42016-08-16 16:41:47 +020040#ifdef CFG_SQL_FS
41 TEE_STORAGE_PRIVATE_SQL,
42#endif
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020043};
Pascal Brandc639ac82015-07-02 08:53:34 +020044
45static uint8_t file_00[] = {
46 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
47 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
48 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
49 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
50};
51
52static uint8_t file_01[] = {
53 0x01, 0x00
54};
55
56static uint8_t file_02[] = {
57 0x02, 0x11, 0x02
58};
59
60static uint8_t file_03[] = {
61 0x03, 0x13, 0x03
62};
63
Pascal Brandeb84c442016-04-19 17:49:49 +020064static uint8_t file_04[] = {
65 0x00, 0x01, 0x02
66};
67
Pascal Brandc639ac82015-07-02 08:53:34 +020068static uint8_t data_00[] = {
69 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
70 0x00, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
71 0x00, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
72 0x00, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x00
73};
74
75static uint8_t data_01[] = {
76 0x01, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
77 0x01, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
78 0x01, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
79 0x01, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x01
80};
81
82static TEEC_Result fs_open(TEEC_Session *sess, void *id, uint32_t id_size,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020083 uint32_t flags, uint32_t *obj, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +020084{
Aijun Sun473d9072015-08-06 15:24:49 +080085 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020086 TEEC_Result res;
87 uint32_t org;
88
89 op.params[0].tmpref.buffer = id;
90 op.params[0].tmpref.size = id_size;
91 op.params[1].value.a = flags;
92 op.params[1].value.b = 0;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020093 op.params[2].value.a = storage_id;
Pascal Brandc639ac82015-07-02 08:53:34 +020094
95 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020096 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
Pascal Brandc639ac82015-07-02 08:53:34 +020097 TEEC_NONE);
98
99 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_OPEN, &op, &org);
100
101 if (res == TEEC_SUCCESS)
102 *obj = op.params[1].value.b;
103
104 return res;
105}
106
107static TEEC_Result fs_create(TEEC_Session *sess, void *id, uint32_t id_size,
108 uint32_t flags, uint32_t attr, void *data,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200109 uint32_t data_size, uint32_t *obj,
110 uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200111{
Aijun Sun473d9072015-08-06 15:24:49 +0800112 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200113 TEEC_Result res;
114 uint32_t org;
115
116 op.params[0].tmpref.buffer = id;
117 op.params[0].tmpref.size = id_size;
118 op.params[1].value.a = flags;
119 op.params[1].value.b = 0;
120 op.params[2].value.a = attr;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200121 op.params[2].value.b = storage_id;
Pascal Brandc639ac82015-07-02 08:53:34 +0200122 op.params[3].tmpref.buffer = data;
123 op.params[3].tmpref.size = data_size;
124
125 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
126 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
127 TEEC_MEMREF_TEMP_INPUT);
128
129 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE, &op, &org);
130
131 if (res == TEEC_SUCCESS)
132 *obj = op.params[1].value.b;
133
134 return res;
135}
136
Pascal Brandeb84c442016-04-19 17:49:49 +0200137static TEEC_Result fs_create_overwrite(TEEC_Session *sess, void *id,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200138 uint32_t id_size, uint32_t storage_id)
Pascal Brandeb84c442016-04-19 17:49:49 +0200139{
140 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
141 TEEC_Result res;
142 uint32_t org;
143
144 op.params[0].tmpref.buffer = id;
145 op.params[0].tmpref.size = id_size;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200146 op.params[1].value.a = storage_id;
Pascal Brandeb84c442016-04-19 17:49:49 +0200147
148 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200149 TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brandeb84c442016-04-19 17:49:49 +0200150 TEEC_NONE);
151
152 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE_OVERWRITE, &op, &org);
153
154 return res;
155}
156
Pascal Brandc639ac82015-07-02 08:53:34 +0200157static TEEC_Result fs_close(TEEC_Session *sess, uint32_t obj)
158{
Aijun Sun473d9072015-08-06 15:24:49 +0800159 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200160 uint32_t org;
161
162 op.params[0].value.a = obj;
163
164 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
165 TEEC_NONE, TEEC_NONE);
166
167 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CLOSE, &op, &org);
168}
169
170static TEEC_Result fs_read(TEEC_Session *sess, uint32_t obj, void *data,
171 uint32_t data_size, uint32_t *count)
172{
173 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800174 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200175 uint32_t org;
176
177 op.params[0].tmpref.buffer = data;
178 op.params[0].tmpref.size = data_size;
179 op.params[1].value.a = obj;
180 op.params[1].value.b = 0;
181
182 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
183 TEEC_VALUE_INOUT, TEEC_NONE,
184 TEEC_NONE);
185
186 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_READ, &op, &org);
187
188 if (res == TEEC_SUCCESS)
189 *count = op.params[1].value.b;
190
191 return res;
192}
193
194static TEEC_Result fs_write(TEEC_Session *sess, uint32_t obj, void *data,
195 uint32_t data_size)
196{
Aijun Sun473d9072015-08-06 15:24:49 +0800197 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200198 uint32_t org;
199
200 op.params[0].tmpref.buffer = data;
201 op.params[0].tmpref.size = data_size;
202 op.params[1].value.a = obj;
203 op.params[1].value.b = 0;
204
205 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
206 TEEC_VALUE_INPUT, TEEC_NONE,
207 TEEC_NONE);
208
209 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_WRITE, &op, &org);
210}
211
212static TEEC_Result fs_seek(TEEC_Session *sess, uint32_t obj, int32_t offset,
213 int32_t whence)
214{
Aijun Sun473d9072015-08-06 15:24:49 +0800215 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200216 uint32_t org;
217
218 op.params[0].value.a = obj;
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +0200219 op.params[0].value.b = *(uint32_t *)&offset;
Pascal Brandc639ac82015-07-02 08:53:34 +0200220 op.params[1].value.a = whence;
221
222 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INOUT,
223 TEEC_NONE, TEEC_NONE);
224
225 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_SEEK, &op, &org);
226}
227
228static TEEC_Result fs_unlink(TEEC_Session *sess, uint32_t obj)
229{
Aijun Sun473d9072015-08-06 15:24:49 +0800230 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200231 uint32_t org;
232
233 op.params[0].value.a = obj;
234
235 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
236 TEEC_NONE, TEEC_NONE);
237
238 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_UNLINK, &op, &org);
239}
240
241static TEEC_Result fs_trunc(TEEC_Session *sess, uint32_t obj, uint32_t len)
242{
Aijun Sun473d9072015-08-06 15:24:49 +0800243 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200244 uint32_t org;
245
246 op.params[0].value.a = obj;
247 op.params[0].value.b = len;
248
249 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
250 TEEC_NONE, TEEC_NONE);
251
252 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_TRUNC, &op, &org);
253}
254
255static TEEC_Result fs_rename(TEEC_Session *sess, uint32_t obj, void *id,
256 uint32_t id_size)
257{
Aijun Sun473d9072015-08-06 15:24:49 +0800258 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200259 uint32_t org;
260
261 op.params[0].value.a = obj;
262 op.params[1].tmpref.buffer = id;
263 op.params[1].tmpref.size = id_size;
264
265 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
266 TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
267 TEEC_NONE);
268
269 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RENAME, &op, &org);
270}
271
272static TEEC_Result fs_alloc_enum(TEEC_Session *sess, uint32_t *e)
273{
274 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800275 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200276 uint32_t org;
277
278 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
279 TEEC_NONE, TEEC_NONE);
280
281 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_ENUM, &op, &org);
282
283 if (res == TEEC_SUCCESS)
284 *e = op.params[0].value.a;
285
286 return res;
287}
288
289static TEEC_Result fs_free_enum(TEEC_Session *sess, uint32_t e)
290{
Aijun Sun473d9072015-08-06 15:24:49 +0800291 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200292 uint32_t org;
293
294 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
295 TEEC_NONE);
296
297 op.params[0].value.a = e;
298
299 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_ENUM, &op, &org);
300}
301
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200302static TEEC_Result fs_start_enum(TEEC_Session *sess, uint32_t e,
303 uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200304{
Aijun Sun473d9072015-08-06 15:24:49 +0800305 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200306 uint32_t org;
307
308 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
309 TEEC_NONE, TEEC_NONE);
310
311 op.params[0].value.a = e;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200312 op.params[0].value.b = storage_id;
Pascal Brandc639ac82015-07-02 08:53:34 +0200313
314 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_START_ENUM, &op, &org);
315}
316
317static TEEC_Result fs_next_enum(TEEC_Session *sess, uint32_t e, void *obj_info,
318 size_t info_size, void *id, uint32_t id_size)
319{
Aijun Sun473d9072015-08-06 15:24:49 +0800320 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200321 uint32_t org;
322
Pascal Brandc603e0d2016-04-25 12:37:18 +0200323 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brandc639ac82015-07-02 08:53:34 +0200324 TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE);
Pascal Brandc603e0d2016-04-25 12:37:18 +0200325 if (obj_info && info_size)
326 op.paramTypes |= (TEEC_MEMREF_TEMP_OUTPUT << 4);
Pascal Brandc639ac82015-07-02 08:53:34 +0200327
328 op.params[0].value.a = e;
329 op.params[1].tmpref.buffer = obj_info;
330 op.params[1].tmpref.size = info_size;
331 op.params[2].tmpref.buffer = id;
332 op.params[2].tmpref.size = id_size;
333
334 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_NEXT_ENUM, &op, &org);
335}
336
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +0200337static TEEC_Result fs_restrict_usage(TEEC_Session *sess, uint32_t obj,
338 uint32_t obj_usage)
339{
340 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
341 uint32_t org;
342
343 op.params[0].value.a = obj;
344 op.params[0].value.b = obj_usage;
345
346 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
347 TEEC_NONE, TEEC_NONE);
348
349 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RESTRICT_USAGE,
350 &op, &org);
351}
352
353static TEEC_Result fs_alloc_obj(TEEC_Session *sess, uint32_t obj_type,
354 uint32_t max_key_size, uint32_t *obj)
355{
356 TEEC_Result res;
357 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
358 uint32_t org;
359
360 op.params[0].value.a = obj_type;
361 op.params[0].value.b = max_key_size;
362
363 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_OUTPUT,
364 TEEC_NONE, TEEC_NONE);
365
366 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_OBJ, &op, &org);
367 *obj = op.params[1].value.a;
368 return res;
369}
370
371static TEEC_Result fs_free_obj(TEEC_Session *sess, uint32_t obj)
372{
373 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
374 uint32_t org;
375
376 op.params[0].value.a = obj;
377
378 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
379 TEEC_NONE, TEEC_NONE);
380
381 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_OBJ, &op, &org);
382}
383
384static TEEC_Result fs_reset_obj(TEEC_Session *sess, uint32_t obj)
385{
386 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
387 uint32_t org;
388
389 op.params[0].value.a = obj;
390
391 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
392 TEEC_NONE, TEEC_NONE);
393
394 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RESET_OBJ, &op, &org);
395}
396
James Kung98c0ba12015-09-09 15:51:59 +0800397/* trunc */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200398static void test_truncate_file_length(ADBG_Case_t *c, uint32_t storage_id)
James Kung98c0ba12015-09-09 15:51:59 +0800399{
400 TEEC_Session sess;
401 uint32_t obj;
402 uint8_t out[10] = { 0 };
403 uint32_t count;
404 uint32_t orig;
405
406 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
407 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
408 return;
409
410 /* create */
411 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
412 fs_create(&sess, file_01, sizeof(file_01),
413 TEE_DATA_FLAG_ACCESS_WRITE |
414 TEE_DATA_FLAG_ACCESS_READ |
415 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200416 sizeof(data_00), &obj, storage_id)))
James Kung98c0ba12015-09-09 15:51:59 +0800417 goto exit;
418
419 /* trunc */
420 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 10)))
421 goto exit;
422
423 /* seek */
424 if (!ADBG_EXPECT_TEEC_SUCCESS(
425 c, fs_seek(&sess, obj, 5, TEE_DATA_SEEK_SET)))
426 goto exit;
427
428 /* verify */
429 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
430 goto exit;
431
432 /* check buffer */
433 (void)ADBG_EXPECT_BUFFER(c, &data_00[5], 5, out, count);
434
435 /* clean */
436 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
437 goto exit;
438
439exit:
440 TEEC_CloseSession(&sess);
441}
442
443/* extend */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200444static void test_extend_file_length(ADBG_Case_t *c, uint32_t storage_id)
James Kung98c0ba12015-09-09 15:51:59 +0800445{
446 TEEC_Session sess;
447 uint32_t obj;
448 uint8_t out[10] = { 0 };
449 uint8_t expect[10] = { 0 };
450 uint32_t count;
451 uint32_t orig;
452
453 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
454 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
455 return;
456
457 /* create */
458 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
459 fs_create(&sess, file_01, sizeof(file_01),
460 TEE_DATA_FLAG_ACCESS_WRITE |
461 TEE_DATA_FLAG_ACCESS_READ |
462 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200463 sizeof(data_00), &obj, storage_id)))
James Kung98c0ba12015-09-09 15:51:59 +0800464 goto exit;
465
466 /* extend */
467 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 40)))
468 goto exit;
469
470 /* seek */
471 if (!ADBG_EXPECT_TEEC_SUCCESS(
472 c, fs_seek(&sess, obj, 30, TEE_DATA_SEEK_SET)))
473 goto exit;
474
475 /* verify */
476 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
477 goto exit;
478
479 /* check buffer */
480 expect[0] = data_00[30];
481 expect[1] = data_00[31];
482 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
483
484 /* clean */
485 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
486 goto exit;
487
488exit:
489 TEEC_CloseSession(&sess);
490}
491
492/* file hole */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200493static void test_file_hole(ADBG_Case_t *c, uint32_t storage_id)
James Kung98c0ba12015-09-09 15:51:59 +0800494{
495 TEEC_Session sess;
496 uint32_t obj;
497 uint8_t out[10] = { 0 };
498 uint8_t expect[10] = { 0 };
499 uint32_t count;
500 uint32_t orig;
501
502 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
503 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
504 return;
505
506 /* create */
507 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
508 fs_create(&sess, file_01, sizeof(file_01),
509 TEE_DATA_FLAG_ACCESS_WRITE |
510 TEE_DATA_FLAG_ACCESS_READ |
511 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200512 sizeof(data_00), &obj, storage_id)))
James Kung98c0ba12015-09-09 15:51:59 +0800513 goto exit;
514
515 /* seek */
516 if (!ADBG_EXPECT_TEEC_SUCCESS(
517 c, fs_seek(&sess, obj, 80, TEE_DATA_SEEK_SET)))
518 goto exit;
519
520 /* write */
521 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_write(&sess, obj, data_00,
522 sizeof(data_00))))
523 goto exit;
524
525 /* seek */
526 if (!ADBG_EXPECT_TEEC_SUCCESS(
527 c, fs_seek(&sess, obj, 74, TEE_DATA_SEEK_SET)))
528 goto exit;
529
530 /* verify */
531 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
532 goto exit;
533
534 /* check buffer */
535 expect[6] = data_00[0];
536 expect[7] = data_00[1];
537 expect[8] = data_00[2];
538 expect[9] = data_00[3];
539 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
540
541 /* clean */
542 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
543 goto exit;
544
545exit:
546 TEEC_CloseSession(&sess);
547}
548
Jerome Forissiere3688342015-09-24 10:45:17 -0700549#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +0200550static TEEC_Result ds_seek_obj_inv_handle(TEEC_Session *sess)
551{
552 TEEC_Operation op;
553 uint32_t org;
554
555 op.paramTypes = TEEC_PARAM_TYPES(
556 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
557
558 op.params[0].value.a = CASE_DATA_OBJECT_NOT_PERSISTENT;
559
560 return TEEC_InvokeCommand(
561 sess, CMD_SeekObjectData_panic, &op, &org);
562}
563
Pascal Brand8a74e362015-09-10 12:41:52 +0200564static TEEC_Result ds_seek_gp(
565 TEEC_Session *sess, TEE_Whence wh, uint32_t wh_off, uint32_t set_off,
566 void *in, size_t in_size, void *out, size_t out_size)
567{
568 TEEC_Operation op;
569 uint32_t org;
570
571 op.paramTypes = TEEC_PARAM_TYPES(
572 TEEC_VALUE_INPUT, TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
573 TEEC_MEMREF_TEMP_OUTPUT);
574
575 op.params[0].value.a = wh;
576 op.params[0].value.b = wh_off;
577 op.params[1].value.a = set_off;
578 op.params[2].tmpref.buffer = in;
579 op.params[2].tmpref.size = in_size;
580 op.params[3].tmpref.buffer = out;
581 op.params[3].tmpref.size = out_size;
582
583 return TEEC_InvokeCommand(sess, CMD_SeekWriteReadObjectData, &op, &org);
584}
585
586static TEEC_Result ds_init_object_and_attributes(TEEC_Session *sess,
587 uint32_t obj_type, uint32_t obj_size, const void *attr_meta,
588 size_t attr_meta_len, const void *attr_data, size_t attr_data_len,
589 uint32_t option)
590{
591 TEEC_Operation op;
592 uint32_t org;
593
594 op.paramTypes = TEEC_PARAM_TYPES(
595 TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
596 TEEC_MEMREF_TEMP_INPUT, TEEC_VALUE_INPUT);
597
598 op.params[0].value.a = obj_type;
599 op.params[0].value.b = obj_size;
600 op.params[1].tmpref.buffer = (void *)attr_meta;
601 op.params[1].tmpref.size = attr_meta_len;
602 op.params[2].tmpref.buffer = (void *)attr_data;
603 op.params[2].tmpref.size = attr_data_len;
604 op.params[3].value.a = option;
605
606 return TEEC_InvokeCommand(sess, CMD_InitObjectAndAttributes, &op, &org);
607}
608
609static TEEC_Result ds_rename_access_conflict(TEEC_Session *sess)
610{
611 TEEC_Operation op;
612 uint32_t org;
613
614 op.paramTypes = TEEC_PARAM_TYPES(
615 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
616
617 return TEEC_InvokeCommand(
618 sess, CMD_RenamePersistentObject_AccessConflict, &op, &org);
619}
620
621static TEEC_Result ds_start_enum_no_item(TEEC_Session *sess)
622{
623 TEEC_Operation op;
624 uint32_t org;
625 TEEC_Result res;
626
627 op.paramTypes = TEEC_PARAM_TYPES(
628 TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
629
630 res = TEEC_InvokeCommand(
631 sess, CMD_StartNGetPersistentObjectEnumerator_itemNotFound, &op, &org);
632
633 if (res != TEEC_SUCCESS)
634 return res;
635
636 if (op.params[0].value.a != 0 || op.params[0].value.b != 0)
637 return TEEC_ERROR_GENERIC;
638
639 return res;
640}
641
642static TEEC_Result ds_rename_success(TEEC_Session *sess)
643{
644 TEEC_Operation op;
645 uint32_t org;
646
647 op.paramTypes = TEEC_PARAM_TYPES(
648 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
649
650 return TEEC_InvokeCommand(
651 sess, CMD_RenamePersistentObject_Success, &op, &org);
652}
653
654static TEEC_Result ds_null_close_free_reset(TEEC_Session *sess)
655{
656 TEEC_Operation op;
657 uint32_t org;
658
659 op.paramTypes = TEEC_PARAM_TYPES(
660 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
661
662 return TEEC_InvokeCommand(
663 sess, CMD_CloseFreeAndResetObjectSuccessHandleNull, &op, &org);
664}
665#endif
666
Pascal Brandc639ac82015-07-02 08:53:34 +0200667/* create */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200668static void xtest_tee_test_6001_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200669{
670 TEEC_Session sess;
671 uint32_t obj;
672 uint32_t orig;
673
674 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
675 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
676 return;
677
678 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
679 fs_create(&sess, file_00, sizeof(file_00),
680 TEE_DATA_FLAG_ACCESS_WRITE |
681 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200682 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200683 goto exit;
684
685 /* clean */
686 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
687 goto exit;
688
689exit:
690 TEEC_CloseSession(&sess);
691}
692
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200693#define DEFINE_TEST_MULTIPLE_STORAGE_IDS(test_name) \
694static void test_name(ADBG_Case_t *c) \
695{ \
696 size_t i; \
697 \
698 for (i = 0; i < ARRAY_SIZE(storage_ids); i++) { \
699 Do_ADBG_BeginSubCase(c, "Storage id: %08x", storage_ids[i]); \
700 test_name##_single(c, storage_ids[i]); \
701 Do_ADBG_EndSubCase(c, "Storage id: %08x", storage_ids[i]); \
702 } \
703}
704
705DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6001)
706
Pascal Brandc639ac82015-07-02 08:53:34 +0200707/* open */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200708static void xtest_tee_test_6002_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200709{
710 TEEC_Session sess;
711 uint32_t obj;
712 uint32_t orig;
713
714 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
715 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
716 return;
717
718 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
719 fs_create(&sess, file_01, sizeof(file_01),
720 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200721 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200722 goto exit;
723
724 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
725 goto exit;
726
727 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
728 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200729 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200730 goto exit;
731
732 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
733 goto exit;
734
735 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
736 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200737 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200738 goto exit;
739
740 /* clean */
741 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
742 goto exit;
743
744exit:
745 TEEC_CloseSession(&sess);
746}
747
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200748DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6002)
749
Pascal Brandc639ac82015-07-02 08:53:34 +0200750/* read */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200751static void xtest_tee_test_6003_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200752{
753 TEEC_Session sess;
754 uint32_t obj;
755 uint8_t out[10] = { 0 };
756 uint32_t count;
757 uint32_t orig;
758
759 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
760 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
761 return;
762
763 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
764 fs_create(&sess, file_02, sizeof(file_02),
765 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200766 sizeof(data_01), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200767 goto exit;
768
769 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
770 goto exit;
771
772 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
773 fs_open(&sess, file_02, sizeof(file_02),
774 TEE_DATA_FLAG_ACCESS_READ |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200775 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200776 goto exit;
777
778 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
779 goto exit;
780
781 (void)ADBG_EXPECT_BUFFER(c, data_01, 10, out, count);
782
783 /* clean */
784 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
785 goto exit;
786
787exit:
788 TEEC_CloseSession(&sess);
789}
790
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200791DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6003)
792
Pascal Brandc639ac82015-07-02 08:53:34 +0200793/* write */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200794static void xtest_tee_test_6004_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200795{
796 TEEC_Session sess;
797 uint32_t obj;
798 uint8_t out[10] = { 0 };
799 uint32_t count;
800 uint32_t orig;
801
802 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
803 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
804 return;
805
806 /* create */
807 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
808 fs_create(&sess, file_02, sizeof(file_02),
809 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200810 sizeof(data_01), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200811 goto exit;
812
813 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
814 goto exit;
815
816 /* write new data */
817 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
818 fs_open(&sess, file_02, sizeof(file_02),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200819 TEE_DATA_FLAG_ACCESS_WRITE, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200820 goto exit;
821
822 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
823 fs_write(&sess, obj, data_00, sizeof(data_00))))
824 goto exit;
825
826 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
827 goto exit;
828
829 /* verify */
830 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
831 fs_open(&sess, file_02, sizeof(file_02),
832 TEE_DATA_FLAG_ACCESS_READ |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200833 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200834 goto exit;
835
836 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
837 goto exit;
838
839 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
840
841 /* clean */
842 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
843 goto exit;
844
845exit:
846 TEEC_CloseSession(&sess);
847}
848
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200849DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6004)
850
Pascal Brandc639ac82015-07-02 08:53:34 +0200851/* seek */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200852static void xtest_tee_test_6005_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200853{
854 TEEC_Session sess;
855 uint32_t obj;
856 uint8_t out[10] = { 0 };
857 uint32_t count;
858 uint32_t orig;
859
860 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
861 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
862 return;
863
864 /* create */
865 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
866 fs_create(&sess, file_01, sizeof(file_01),
867 TEE_DATA_FLAG_ACCESS_WRITE |
868 TEE_DATA_FLAG_ACCESS_READ |
869 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200870 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200871 goto exit;
872
873 /* seek */
874 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
875 fs_seek(&sess, obj, 10, TEE_DATA_SEEK_SET)))
876 goto exit;
877
878 /* verify */
879 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
880 goto exit;
881
882 (void)ADBG_EXPECT_BUFFER(c, &data_00[10], 10, out, count);
883
884 /* clean */
885 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
886 goto exit;
887
888exit:
889 TEEC_CloseSession(&sess);
890}
891
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200892DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6005)
893
Pascal Brandc639ac82015-07-02 08:53:34 +0200894/* unlink */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200895static void xtest_tee_test_6006_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200896{
897 TEEC_Session sess;
898 uint32_t obj;
899 uint32_t orig;
900
901 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
902 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
903 return;
904
905 /* create */
906 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
907 fs_create(&sess, file_01, sizeof(file_01),
908 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200909 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200910 goto exit;
911
912 /* del & close */
913 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
914 goto exit;
915
916 /* check result */
917 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
918 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200919 TEE_DATA_FLAG_ACCESS_READ, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200920 goto exit;
921
922exit:
923 TEEC_CloseSession(&sess);
924}
925
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200926DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6006)
927
928static void xtest_tee_test_6007_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200929{
James Kung98c0ba12015-09-09 15:51:59 +0800930 Do_ADBG_BeginSubCase(c, "Test truncate file length");
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200931 test_truncate_file_length(c, storage_id);
James Kung98c0ba12015-09-09 15:51:59 +0800932 Do_ADBG_EndSubCase(c, "Test truncate file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200933
James Kung98c0ba12015-09-09 15:51:59 +0800934 Do_ADBG_BeginSubCase(c, "Test extend file length");
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200935 test_extend_file_length(c, storage_id);
James Kung98c0ba12015-09-09 15:51:59 +0800936 Do_ADBG_EndSubCase(c, "Test extend file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200937
James Kung98c0ba12015-09-09 15:51:59 +0800938 Do_ADBG_BeginSubCase(c, "Test file hole");
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200939 test_file_hole(c, storage_id);
James Kung98c0ba12015-09-09 15:51:59 +0800940 Do_ADBG_EndSubCase(c, "Test file hole");
Pascal Brandc639ac82015-07-02 08:53:34 +0200941}
942
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200943DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6007)
944
945static void xtest_tee_test_6008_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200946{
947 TEEC_Session sess;
948 uint32_t obj;
949 uint8_t out[10] = { 0 };
950 uint32_t count;
951 uint32_t orig;
952
953 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
954 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
955 return;
956
957 /* create */
958 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
959 fs_create(&sess, file_02, sizeof(file_02),
960 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200961 sizeof(data_01), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200962 goto exit;
963
964 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
965 goto exit;
966
967 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
968 fs_open(&sess, file_02, sizeof(file_02),
969 TEE_DATA_FLAG_ACCESS_WRITE |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200970 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200971 goto exit;
972
973 /* write new data */
974 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
975 fs_write(&sess, obj, data_00, sizeof(data_00))))
976 goto exit;
977
978 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
979 fs_rename(&sess, obj, file_03, sizeof(file_03))))
980 goto exit;
981
982 /* close */
983 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
984 goto exit;
985
986 /* verify */
987 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
988 fs_open(&sess, file_03, sizeof(file_03),
989 TEE_DATA_FLAG_ACCESS_READ |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200990 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200991 goto exit;
992
993 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
994 goto exit;
995
996 /* check buffer */
997 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
998
999 /* clean */
1000 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
1001 goto exit;
1002
1003exit:
1004 TEEC_CloseSession(&sess);
1005}
1006
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001007DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6008)
1008
1009static void xtest_tee_test_6009_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +02001010{
1011 TEEC_Session sess;
1012 uint32_t obj0;
1013 uint32_t obj1;
1014 uint32_t obj2;
1015 uint32_t e = 0;
1016 uint8_t info[200];
1017 uint8_t id[200];
1018 uint32_t orig;
1019
1020 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1021 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1022 return;
1023
1024 /* create file 00 */
1025 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1026 fs_create(&sess, file_00, sizeof(file_00),
1027 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001028 sizeof(data_01), &obj0, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001029 goto exit;
1030
1031 /* create file 01 */
1032 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1033 fs_create(&sess, file_01, sizeof(file_01),
1034 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001035 sizeof(data_01), &obj1, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001036 goto exit;
1037
1038 /* create file 02 */
1039 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1040 fs_create(&sess, file_02, sizeof(file_02),
1041 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001042 sizeof(data_01), &obj2, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001043 goto exit;
1044
1045 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj0)))
1046 goto exit;
1047
1048 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj1)))
1049 goto exit;
1050
1051 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj2)))
1052 goto exit;
1053
1054 /* iterate */
1055 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e)))
1056 goto exit;
1057
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001058 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_start_enum(&sess, e, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001059 goto exit;
1060
1061 /* get 00 */
1062 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1063 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1064 goto exit;
1065
1066 /* get 01 */
1067 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc603e0d2016-04-25 12:37:18 +02001068 fs_next_enum(&sess, e, NULL, 0, id, sizeof(id))))
Pascal Brandc639ac82015-07-02 08:53:34 +02001069 goto exit;
1070
1071 /* get 02 */
1072 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1073 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1074 goto exit;
1075
1076 /* we should not have more files */
1077 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
1078 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1079 goto exit;
1080
1081 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e)))
1082 goto exit;
1083
1084 /* clean */
1085 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1086 fs_open(&sess, file_00, sizeof(file_00),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001087 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj0, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001088 goto exit;
1089
1090 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj0)))
1091 goto exit;
1092
1093 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1094 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001095 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj1, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001096 goto exit;
1097
1098 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj1)))
1099 goto exit;
1100
1101 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1102 fs_open(&sess, file_02, sizeof(file_02),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001103 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj2, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001104 goto exit;
1105
1106 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj2)))
1107 goto exit;
1108
1109exit:
1110 TEEC_CloseSession(&sess);
1111}
1112
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001113DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6009)
1114
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001115static void xtest_tee_test_6010_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brand8a74e362015-09-10 12:41:52 +02001116{
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001117 TEEC_Session sess;
1118 uint32_t orig;
1119 uint32_t o1;
1120 uint32_t o2;
1121 uint32_t e;
1122 uint32_t f;
1123 uint8_t data[1024];
1124 uint8_t out[1024];
1125 uint32_t n;
Pascal Brand30844922015-09-17 12:12:42 +02001126
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001127 for (n = 0; n < ARRAY_SIZE(data); n++)
1128 data[n] = n;
Pascal Brand8a74e362015-09-10 12:41:52 +02001129
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001130 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1131 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1132 return;
Pascal Brand8a74e362015-09-10 12:41:52 +02001133
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001134 Do_ADBG_BeginSubCase(c, "CreatePersistentObject AccessConflict");
Pascal Brand8a74e362015-09-10 12:41:52 +02001135
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001136 o1 = TEE_HANDLE_NULL;
1137 o2 = TEE_HANDLE_NULL;
1138 f = TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE |
1139 TEE_DATA_FLAG_ACCESS_WRITE_META | TEE_DATA_FLAG_SHARE_READ |
1140 TEE_DATA_FLAG_SHARE_WRITE | TEE_DATA_FLAG_OVERWRITE;
Pascal Brand8a74e362015-09-10 12:41:52 +02001141
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001142 ADBG_EXPECT_TEEC_SUCCESS(c,
1143 fs_create(&sess, file_00, sizeof(file_00), f, 0, data,
1144 sizeof(data), &o1, storage_id));
Pascal Brand8a74e362015-09-10 12:41:52 +02001145
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001146 f = TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE;
1147 ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ACCESS_CONFLICT,
1148 fs_create(&sess, file_00, sizeof(file_00), f, 0, data,
1149 sizeof(data), &o2, storage_id));
Pascal Brand8a74e362015-09-10 12:41:52 +02001150
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001151 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, o1));
1152 if (o2)
1153 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, o2));
Pascal Brand8a74e362015-09-10 12:41:52 +02001154
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001155 Do_ADBG_EndSubCase(c, "CreatePersistentObject AccessConflict");
Pascal Brand8a74e362015-09-10 12:41:52 +02001156
Pascal Brand8a74e362015-09-10 12:41:52 +02001157
Pascal Brand8a74e362015-09-10 12:41:52 +02001158
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001159 Do_ADBG_BeginSubCase(c, "RestrictObjectUsage Panic");
1160 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_TARGET_DEAD,
1161 fs_restrict_usage(&sess, 0xffffbad0, 0xffffffff));
1162 Do_ADBG_EndSubCase(c, "RestrictObjectUsage Panic");
Pascal Brand8a74e362015-09-10 12:41:52 +02001163
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001164 TEEC_CloseSession(&sess);
1165 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1166 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1167 return;
Pascal Brand8a74e362015-09-10 12:41:52 +02001168
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001169 Do_ADBG_BeginSubCase(c, "SeekObjectData BadHandle");
1170 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_TARGET_DEAD,
1171 fs_seek(&sess, 0xffffbad0, 5, TEE_DATA_SEEK_SET));
1172 Do_ADBG_EndSubCase(c, "SeekObjectData BadHandle");
Pascal Brand8a74e362015-09-10 12:41:52 +02001173
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001174 TEEC_CloseSession(&sess);
1175 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1176 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1177 return;
Pascal Brand8a74e362015-09-10 12:41:52 +02001178
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001179 Do_ADBG_BeginSubCase(c, "SeekObjectData NotPersist");
1180 o1 = 0;
1181 ADBG_EXPECT_TEEC_SUCCESS(c,
1182 fs_alloc_obj(&sess, TEE_TYPE_AES, 256, &o1));
1183 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_TARGET_DEAD,
1184 fs_seek(&sess, o1, 5, TEE_DATA_SEEK_SET));
1185 Do_ADBG_EndSubCase(c, "SeekObjectData NotPersist");
Pascal Brand8a74e362015-09-10 12:41:52 +02001186
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001187 TEEC_CloseSession(&sess);
1188 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1189 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1190 return;
Pascal Brand8a74e362015-09-10 12:41:52 +02001191
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001192 Do_ADBG_BeginSubCase(c, "SeekWriteRead");
1193 o1 = 0;
1194 f = TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE |
1195 TEE_DATA_FLAG_ACCESS_WRITE_META | TEE_DATA_FLAG_SHARE_READ |
1196 TEE_DATA_FLAG_SHARE_WRITE | TEE_DATA_FLAG_OVERWRITE;
1197 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1198 fs_create(&sess, file_00, sizeof(file_00), f, 0, data,
1199 sizeof(data), &o1, storage_id)))
1200 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001201
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001202 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1203 fs_seek(&sess, o1, 2, TEE_DATA_SEEK_SET)))
1204 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001205
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001206 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1207 fs_seek(&sess, o1, 0, TEE_DATA_SEEK_END)))
1208 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001209
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001210 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1211 fs_write(&sess, o1, data, sizeof(data))))
1212 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001213
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001214 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1215 fs_seek(&sess, o1, sizeof(data), TEE_DATA_SEEK_SET)))
1216 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001217
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001218 memset(out, 0xab, sizeof(out));
1219 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1220 fs_read(&sess, o1, out, sizeof(out), &n)))
1221 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001222
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001223 ADBG_EXPECT_BUFFER(c, data, sizeof(data), out, n);
Pascal Brand8a74e362015-09-10 12:41:52 +02001224
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001225 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1226 fs_seek(&sess, o1, -(int32_t)sizeof(data) / 2,
1227 TEE_DATA_SEEK_END)))
1228 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001229
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001230 memset(out, 0xab, sizeof(out) / 2);
1231 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1232 fs_read(&sess, o1, out, sizeof(out) / 2, &n)))
1233 goto seek_write_read_out;
Pascal Brand8a74e362015-09-10 12:41:52 +02001234
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001235 ADBG_EXPECT_BUFFER(c,
1236 data + sizeof(data) / 2, sizeof(data) / 2,
1237 out + sizeof(data) / 2, n);
Pascal Brand8a74e362015-09-10 12:41:52 +02001238
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001239seek_write_read_out:
1240 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, o1));
1241 Do_ADBG_EndSubCase(c, "SeekWriteRead");
Pascal Brand8a74e362015-09-10 12:41:52 +02001242
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001243 Do_ADBG_BeginSubCase(c, "Rename Access Conflict");
Pascal Brand8a74e362015-09-10 12:41:52 +02001244
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001245 o1 = TEE_HANDLE_NULL;
1246 o2 = TEE_HANDLE_NULL;
1247 f = TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE |
1248 TEE_DATA_FLAG_ACCESS_WRITE_META | TEE_DATA_FLAG_SHARE_READ |
1249 TEE_DATA_FLAG_SHARE_WRITE | TEE_DATA_FLAG_OVERWRITE;
1250 ADBG_EXPECT_TEEC_SUCCESS(c,
1251 fs_create(&sess, file_00, sizeof(file_00), f, 0, data,
1252 sizeof(data), &o1, storage_id));
1253 ADBG_EXPECT_TEEC_SUCCESS(c,
1254 fs_create(&sess, file_01, sizeof(file_01), f, 0, data,
1255 sizeof(data) / 2, &o2, storage_id));
Pascal Brand8a74e362015-09-10 12:41:52 +02001256
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001257 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_ACCESS_CONFLICT,
1258 fs_rename(&sess, o2, file_00, sizeof(file_00)));
Pascal Brand8a74e362015-09-10 12:41:52 +02001259
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001260 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, o1));
1261 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, o2));
1262
1263 Do_ADBG_EndSubCase(c, "Rename Access Conflict");
1264
1265 Do_ADBG_BeginSubCase(c, "StartPersistentObjectEnumerator ItemNotFound");
1266 e = TEE_HANDLE_NULL;
1267 ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e));
1268 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_ITEM_NOT_FOUND,
1269 fs_next_enum(&sess, e, NULL, 0, out, sizeof(out)));
1270 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_ITEM_NOT_FOUND,
1271 fs_start_enum(&sess, e, storage_id));
1272 ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e));
1273 Do_ADBG_EndSubCase(c, "StartPersistentObjectEnumerator ItemNotFound");
1274
1275 Do_ADBG_BeginSubCase(c, "RenamePersistent ReadWrite");
1276 o1 = TEE_HANDLE_NULL;
1277 f = TEE_DATA_FLAG_ACCESS_READ | TEE_DATA_FLAG_ACCESS_WRITE |
1278 TEE_DATA_FLAG_ACCESS_WRITE_META | TEE_DATA_FLAG_SHARE_READ |
1279 TEE_DATA_FLAG_SHARE_WRITE | TEE_DATA_FLAG_OVERWRITE;
1280 ADBG_EXPECT_TEEC_SUCCESS(c,
1281 fs_create(&sess, file_00, sizeof(file_00), f, 0, data,
1282 sizeof(data), &o1, storage_id));
1283 ADBG_EXPECT_TEEC_SUCCESS(c,
1284 fs_rename(&sess, o1, file_01, sizeof(file_01)));
1285 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, o1));
1286 Do_ADBG_EndSubCase(c, "RenamePersistent ReadWrite");
1287
1288 Do_ADBG_BeginSubCase(c, "Close Free Reset Null");
1289 ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, TEE_HANDLE_NULL));
1290 ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_obj(&sess, TEE_HANDLE_NULL));
1291 ADBG_EXPECT_TEEC_SUCCESS(c, fs_reset_obj(&sess, TEE_HANDLE_NULL));
1292 Do_ADBG_EndSubCase(c, "Close Free Reset Null");
1293
1294 TEEC_CloseSession(&sess);
Pascal Brand8a74e362015-09-10 12:41:52 +02001295}
1296
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001297DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6010)
1298
1299#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001300static void xtest_tee_test_6011(ADBG_Case_t *c)
1301{
1302 TEEC_Session sess;
1303 uint32_t orig;
1304 /*
1305 * Test data from
1306 * Invoke_InitObjectAndAttributes_TEE_TYPE_AES_success_attribute_
1307 * TEE_ATTR_SECRET_VALUE_correct_size (9d-9a-91)
1308 */
1309 static const uint8_t attr_meta[] = {
13100xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
13110x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
13120x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
13130x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1314 };
1315 static const uint8_t attr_data[] = {
13160x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,
13170x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,
13180xdf,0xf4,
1319 };
1320
1321 if (!ADBG_EXPECT_TEEC_SUCCESS(
1322 c, xtest_teec_open_session(
1323 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1324 return;
1325
1326 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_init_object_and_attributes(&sess,
1327 0xa0000010, 0x100, attr_meta, sizeof(attr_meta), attr_data,
1328 sizeof(attr_data), 0)))
1329 goto exit;
1330
1331exit:
1332 TEEC_CloseSession(&sess);
1333}
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001334#endif /*WITH_GP_TESTS*/
Pascal Brand8a74e362015-09-10 12:41:52 +02001335
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001336static void xtest_tee_test_6012_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandeb84c442016-04-19 17:49:49 +02001337{
1338 TEEC_Session sess;
1339 uint32_t orig;
1340 uint32_t obj;
1341
1342 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1343 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1344 return;
1345
1346 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001347 fs_create_overwrite(&sess, file_04, sizeof(file_04), storage_id)))
Pascal Brandeb84c442016-04-19 17:49:49 +02001348 goto exit;
1349
1350 TEEC_CloseSession(&sess);
1351
1352 /* re-create the same */
1353 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1354 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1355 return;
1356
1357 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001358 fs_create_overwrite(&sess, file_04, sizeof(file_04),
1359 storage_id)))
Pascal Brandeb84c442016-04-19 17:49:49 +02001360 goto exit;
1361
1362 /*
1363 * recreate it with an object, and remove it so that xtest 6009
1364 * can be replayed
1365 */
1366 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1367 fs_create(&sess, file_04, sizeof(file_04),
1368 TEE_DATA_FLAG_ACCESS_WRITE |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001369 TEE_DATA_FLAG_ACCESS_WRITE_META |
1370 TEE_DATA_FLAG_OVERWRITE, 0, NULL, 0, &obj,
1371 storage_id)))
Pascal Brandeb84c442016-04-19 17:49:49 +02001372 goto exit;
1373
1374 /* clean */
1375 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
1376 goto exit;
1377
1378exit:
1379 TEEC_CloseSession(&sess);
1380}
1381
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001382DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6012)
1383
1384static void xtest_tee_test_6013_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brand90f23352016-05-19 15:15:47 +02001385{
1386 TEEC_Session sess;
1387 uint32_t orig;
1388 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1389
1390 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1391 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1392 return;
1393
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001394 op.params[0].value.a = storage_id;
1395 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brand90f23352016-05-19 15:15:47 +02001396 TEEC_NONE, TEEC_NONE);
1397
1398 ADBG_EXPECT_TEEC_SUCCESS(c,
1399 TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_KEY_IN_PERSISTENT,
1400 &op, &orig));
1401
1402 TEEC_CloseSession(&sess);
1403}
1404
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001405DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6013)
1406
1407static void xtest_tee_test_6014_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brand29ee18f2016-05-23 14:13:56 +02001408{
1409 TEEC_Session sess;
1410 uint32_t orig;
1411 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1412
1413 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1414 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1415 return;
1416
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001417 op.params[0].value.a = storage_id;
1418 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brand29ee18f2016-05-23 14:13:56 +02001419 TEEC_NONE, TEEC_NONE);
1420
1421 ADBG_EXPECT_TEEC_SUCCESS(c,
1422 TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_LOOP, &op, &orig));
1423
1424 TEEC_CloseSession(&sess);
1425}
1426
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001427DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6014)
1428
Jerome Forissiere3854162016-08-12 12:40:12 +02001429static int get_ta_storage_path(TEEC_UUID *p_uuid, char *buffer, uint32_t len)
1430{
1431 int s;
1432
1433 if (!p_uuid || !buffer)
1434 return -1;
1435
1436 s = snprintf(buffer, len, "/data/tee/");
1437 if (s < 0 || s >= (int)len)
1438 return -1;
1439
1440 len -= s;
1441 buffer += s;
1442
1443 s = ree_fs_get_ta_dirname(p_uuid, buffer, len);
1444 return s;
1445}
1446
1447static int rename_data_dir(TEEC_UUID *old, TEEC_UUID *nw)
1448{
1449 char opath[150];
1450 char npath[150];
1451 int s;
1452
1453 s = get_ta_storage_path(old, opath, sizeof(opath));
1454 if (s < 0 || s >= (int)sizeof(opath)) {
1455 s = -1;
1456 goto exit;
1457 }
1458 s = get_ta_storage_path(nw, npath, sizeof(npath));
1459 if (s < 0 || s >= (int)sizeof(opath)) {
1460 s = -1;
1461 goto exit;
1462 }
1463 s = rename(opath, npath);
1464exit:
1465 if (s < 0)
1466 fprintf(stderr, "Warning: could not rename %s -> %s\n", opath,
1467 npath);
1468 return s;
1469}
1470
1471static void xtest_tee_test_6015_single(ADBG_Case_t *c, uint32_t storage_id)
1472{
1473 TEEC_Session sess;
1474 TEEC_Session sess2;
1475 uint32_t orig;
1476 uint32_t obj;
1477 uint32_t obj2;
1478 TEEC_UUID uuid = TA_STORAGE_UUID;
1479 TEEC_UUID uuid2 = TA_STORAGE2_UUID;
1480
1481 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1482 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1483 return;
1484
1485 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1486 xtest_teec_open_session(&sess2, &storage2_ta_uuid, NULL,
1487 &orig)))
1488 goto exit2;
1489
1490 /* TA #1 creates a persistent object */
1491 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1492 fs_create(&sess, file_01, sizeof(file_01),
1493 TEE_DATA_FLAG_ACCESS_WRITE |
1494 TEE_DATA_FLAG_ACCESS_READ |
1495 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
1496 sizeof(data_00), &obj, storage_id)))
1497 goto exit;
1498
1499 /* TA #2 tries to open the object created by TA #1 */
1500 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
1501 fs_open(&sess2, file_01, sizeof(file_01),
1502 TEE_DATA_FLAG_ACCESS_READ, &obj2, storage_id)))
1503 goto clean;
1504
1505 if (storage_id == TEE_STORAGE_PRIVATE_REE) {
1506 /*
1507 * When the storage backend is the REE filesystem, we can
1508 * simulate a hack attempt by renaming the TA storage. Should
1509 * be detected by the TEE.
1510 */
1511 if (rename_data_dir(&uuid, &uuid2) < 0)
1512 goto clean;
1513
1514 /* TA #2 tries to open the object created by TA #1 */
1515 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_CORRUPT_OBJECT,
1516 fs_open(&sess2, file_01, sizeof(file_01),
1517 TEE_DATA_FLAG_ACCESS_READ, &obj2, storage_id));
1518 /*
1519 * At this point, the TEE is expected to have removed the
1520 * corrupt object, so there is no need to try and restore the
1521 * directory name.
1522 */
1523 goto exit;
1524 }
1525
1526clean:
1527 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj));
1528exit:
1529 TEEC_CloseSession(&sess2);
1530exit2:
1531 TEEC_CloseSession(&sess);
1532}
1533
1534DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6015)
1535
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001536
Jerome Forissier327672c2016-09-01 18:34:11 +02001537#ifdef CFG_RPMB_FS
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001538struct test_6016_thread_arg {
1539 ADBG_Case_t *case_t;
1540 uint32_t storage_id;
Jerome Forissier54cfbef2016-08-31 18:34:31 +02001541 char file_name[8];
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001542 TEEC_Session session;
1543};
1544
1545static void *test_6016_thread(void *arg)
1546{
1547 struct test_6016_thread_arg *a = arg;
1548 TEEC_Session sess = a->session;
1549 uint32_t obj;
1550 uint8_t out[10] = { 0 };
1551 uint32_t count;
1552
1553 /* create */
1554 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1555 fs_create(&sess, a->file_name, sizeof(a->file_name),
1556 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
1557 sizeof(data_01), &obj, a->storage_id)))
1558 goto exit;
1559
1560 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_close(&sess, obj)))
1561 goto exit;
1562
1563 /* write new data */
1564 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1565 fs_open(&sess, a->file_name, sizeof(a->file_name),
1566 TEE_DATA_FLAG_ACCESS_WRITE, &obj, a->storage_id)))
1567 goto exit;
1568
1569 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1570 fs_write(&sess, obj, data_00, sizeof(data_00))))
1571 goto exit;
1572
1573 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_close(&sess, obj)))
1574 goto exit;
1575
1576 /* verify */
1577 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1578 fs_open(&sess, a->file_name, sizeof(a->file_name),
1579 TEE_DATA_FLAG_ACCESS_READ |
1580 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, a->storage_id)))
1581 goto exit;
1582
1583 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1584 fs_read(&sess, obj, out, 10, &count)))
1585 goto exit;
1586
1587 (void)ADBG_EXPECT_BUFFER(a->case_t, data_00, 10, out, count);
1588
1589 /* clean */
1590 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_unlink(&sess, obj)))
1591 goto exit;
1592
1593exit:
1594 return NULL;
1595}
1596
1597
1598#define NUM_THREADS 4
1599static void xtest_tee_test_6016_loop(ADBG_Case_t *c, uint32_t storage_id)
1600{
1601 size_t num_threads = NUM_THREADS;
1602 struct test_6016_thread_arg arg[num_threads];
1603 pthread_t thr[num_threads];
1604 uint32_t orig;
1605 size_t i;
1606 size_t n = 0;
1607 size_t m;
1608
1609 memset(arg, 0, sizeof(arg));
1610
1611 for (m = 0; m < num_threads; m++)
1612 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1613 xtest_teec_open_session(&arg[m].session,
1614 &storage_ta_uuid, NULL, &orig)))
1615 goto out;
1616
1617 for (n = 0; n < num_threads; n++) {
1618 arg[n].case_t = c;
1619 arg[n].storage_id = storage_id;
Jerome Forissiercb10f832016-09-01 14:53:05 +02001620 snprintf(arg[n].file_name, sizeof(arg[n].file_name),
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001621 "file_%d", n);
1622 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1623 test_6016_thread, arg + n)))
1624 goto out;
1625 }
1626
1627out:
1628 for (i = 0; i < n; i++)
1629 ADBG_EXPECT(c, 0, pthread_join(thr[i], NULL));
1630 for (i = 0; i < m; i++)
1631 TEEC_CloseSession(&arg[i].session);
1632}
1633
1634/* concurency */
1635static void xtest_tee_test_6016_single(ADBG_Case_t *c, uint32_t storage_id)
1636{
1637 int i;
1638 int loops = 8;
1639
1640 Do_ADBG_Log(" threads: %d, loops: %d", NUM_THREADS, loops);
1641 for (i = 0; i < loops; i++)
1642 xtest_tee_test_6016_loop(c, storage_id);
1643}
1644
1645/*
1646 * To be replaced with: DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6016)
1647 * when all filesystems support concurrency
1648 */
1649static void xtest_tee_test_6016(ADBG_Case_t *c)
1650{
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001651 Do_ADBG_BeginSubCase(c, "Storage id: %08x", TEE_STORAGE_PRIVATE_RPMB);
1652 xtest_tee_test_6016_single(c, TEE_STORAGE_PRIVATE_RPMB);
1653 Do_ADBG_EndSubCase(c, "Storage id: %08x", TEE_STORAGE_PRIVATE_RPMB);
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001654}
1655
Jerome Forissier327672c2016-09-01 18:34:11 +02001656#else
1657
1658static void xtest_tee_test_6016(ADBG_Case_t *c)
1659{
1660 (void)c;
1661 Do_ADBG_Log(" Only RPMB supports concurrency. Test disabled.");
1662}
1663
1664#endif /* CFG_RPMB_FS */
1665
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001666
Pascal Brandc639ac82015-07-02 08:53:34 +02001667ADBG_CASE_DEFINE(
1668 XTEST_TEE_6001, xtest_tee_test_6001,
1669 /* Title */
1670 "Test TEE_CreatePersistentObject",
1671 /* Short description */
1672 "Short description ...",
1673 /* Requirement IDs */
1674 "TEE-??",
1675 /* How to implement */
1676 "Description of how to implement ..."
1677 );
1678
1679ADBG_CASE_DEFINE(
1680 XTEST_TEE_6002, xtest_tee_test_6002,
1681 /* Title */
1682 "Test TEE_OpenPersistentObject",
1683 /* Short description */
1684 "Short description ...",
1685 /* Requirement IDs */
1686 "TEE-??",
1687 /* How to implement */
1688 "Description of how to implement ..."
1689 );
1690
1691ADBG_CASE_DEFINE(
1692 XTEST_TEE_6003, xtest_tee_test_6003,
1693 /* Title */
1694 "Test TEE_ReadObjectData",
1695 /* Short description */
1696 "Short description ...",
1697 /* Requirement IDs */
1698 "TEE-??",
1699 /* How to implement */
1700 "Description of how to implement ..."
1701 );
1702
1703ADBG_CASE_DEFINE(
1704 XTEST_TEE_6004, xtest_tee_test_6004,
1705 /* Title */
1706 "Test TEE_WriteObjectData",
1707 /* Short description */
1708 "Short description ...",
1709 /* Requirement IDs */
1710 "TEE-??",
1711 /* How to implement */
1712 "Description of how to implement ..."
1713 );
1714
1715ADBG_CASE_DEFINE(
1716 XTEST_TEE_6005, xtest_tee_test_6005,
1717 /* Title */
1718 "Test TEE_SeekObjectData",
1719 /* Short description */
1720 "Short description ...",
1721 /* Requirement IDs */
1722 "TEE-??",
1723 /* How to implement */
1724 "Description of how to implement ..."
1725 );
1726
1727ADBG_CASE_DEFINE(
1728 XTEST_TEE_6006, xtest_tee_test_6006,
1729 /* Title */
1730 "Test TEE_CloseAndDeletePersistentObject",
1731 /* Short description */
1732 "Short description ...",
1733 /* Requirement IDs */
1734 "TEE-??",
1735 /* How to implement */
1736 "Description of how to implement ..."
1737 );
1738
1739ADBG_CASE_DEFINE(
1740 XTEST_TEE_6007, xtest_tee_test_6007,
1741 /* Title */
1742 "Test TEE_TruncateObjectData",
1743 /* Short description */
1744 "Short description ...",
1745 /* Requirement IDs */
1746 "TEE-??",
1747 /* How to implement */
1748 "Description of how to implement ..."
1749 );
1750
1751ADBG_CASE_DEFINE(
1752 XTEST_TEE_6008, xtest_tee_test_6008,
1753 /* Title */
1754 "Test TEE_RenamePersistentObject",
1755 /* Short description */
1756 "Short description ...",
1757 /* Requirement IDs */
1758 "TEE-??",
1759 /* How to implement */
1760 "Description of how to implement ..."
1761 );
1762
1763ADBG_CASE_DEFINE(
1764 XTEST_TEE_6009, xtest_tee_test_6009,
1765 /* Title */
1766 "Test TEE Internal API Persistent Object Enumeration Functions",
1767 /* Short description */
1768 "Short description ...",
1769 /* Requirement IDs */
1770 "TEE-??",
1771 /* How to implement */
1772 "Description of how to implement ..."
1773 );
Pascal Brand8a74e362015-09-10 12:41:52 +02001774
Pascal Brand8a74e362015-09-10 12:41:52 +02001775ADBG_CASE_DEFINE(
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001776 XTEST_TEE_6010, xtest_tee_test_6010,
1777 /* Title */
1778 "Test Storage",
1779 /* Short description */
1780 "Short description ...",
1781 /* Requirement IDs */
1782 "TEE-??",
1783 /* How to implement */
1784 "Description of how to implement ..."
Pascal Brand8a74e362015-09-10 12:41:52 +02001785);
1786
Jens Wiklandere6d4ddd2016-09-14 15:50:48 +02001787#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001788ADBG_CASE_DEFINE(
1789 XTEST_TEE_6011, xtest_tee_test_6011,
1790 /* Title */
1791 "Test TEE GP TTA DS init objects",
1792 /* Short description */
1793 "Short description ...",
1794 /* Requirement IDs */
1795 "TEE-??",
1796 /* How to implement */
1797 "Description of how to implement ..."
1798);
1799#endif
Pascal Brandeb84c442016-04-19 17:49:49 +02001800
1801ADBG_CASE_DEFINE(
1802 XTEST_TEE_6012, xtest_tee_test_6012,
1803 /* Title */
1804 "Test TEE GP TTA DS init objects",
1805 /* Short description */
1806 "Short description ...",
1807 /* Requirement IDs */
1808 "TEE-??",
1809 /* How to implement */
1810 "Description of how to implement ..."
1811);
Pascal Brand90f23352016-05-19 15:15:47 +02001812
1813ADBG_CASE_DEFINE(
1814 XTEST_TEE_6013, xtest_tee_test_6013,
1815 /* Title */
1816 "Key usage in Persistent objects",
1817 /* Short description */
1818 "Short description ...",
1819 /* Requirement IDs */
1820 "TEE-??",
1821 /* How to implement */
1822 "Description of how to implement ..."
1823);
Pascal Brand29ee18f2016-05-23 14:13:56 +02001824
1825ADBG_CASE_DEFINE(
1826 XTEST_TEE_6014, xtest_tee_test_6014,
1827 /* Title */
1828 "Loop on Persistent objects",
1829 /* Short description */
1830 "Short description ...",
1831 /* Requirement IDs */
1832 "TEE-??",
1833 /* How to implement */
1834 "Description of how to implement ..."
1835);
Jerome Forissiere3854162016-08-12 12:40:12 +02001836
1837ADBG_CASE_DEFINE(
1838 XTEST_TEE_6015, xtest_tee_test_6015,
1839 /* Title */
1840 "Storage isolation",
1841 /* Short description */
1842 "TA #2 tries to open object created by TA #1, should fail",
1843 /* Requirement IDs */
1844 "",
1845 /* How to implement */
1846 ""
1847);
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001848
1849ADBG_CASE_DEFINE(
1850 XTEST_TEE_6016, xtest_tee_test_6016,
1851 /* Title */
1852 "Storage concurency",
1853 /* Short description */
1854 "Multiple thread operate secure storage",
1855 /* Requirement IDs */
1856 "",
1857 /* How to implement */
1858 ""
1859);