blob: 66d372cf42b74ec851d2f33a96627f5292760853 [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#ifndef XTEST_HELPERS_H
15#define XTEST_HELPERS_H
16
Pascal Brandc639ac82015-07-02 08:53:34 +020017#include <adbg.h>
Jens Wiklandere2ca6062016-12-21 14:00:30 +010018#include <pthread.h>
19#include <tee_api_types.h>
20#include <tee_client_api.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020021
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020022extern unsigned int level;
23
Pascal Brandc639ac82015-07-02 08:53:34 +020024/* Global context to use if any context is needed as input to a function */
25extern TEEC_Context xtest_teec_ctx;
26
27/*
28 * Initializes the context above, should be called before the ADBG test
29 * cases are run.
30 */
31TEEC_Result xtest_teec_ctx_init(void);
32void xtest_teec_ctx_deinit(void);
33
34/* Opens a session */
35TEEC_Result xtest_teec_open_session(TEEC_Session *session,
36 const TEEC_UUID *uuid, TEEC_Operation *op,
37 uint32_t *ret_orig);
38
39TEEC_Result xtest_teec_open_static_session(TEEC_Session *session,
40 TEEC_Operation *op,
41 uint32_t *ret_orig);
42
Aijun Sun9dbed272015-10-15 15:44:19 +080043#define TEEC_OPERATION_INITIALIZER { 0 }
Pascal Brandc639ac82015-07-02 08:53:34 +020044
45/* IO access macro */
46#define IO(addr) (*((volatile unsigned long *)(addr)))
47
Igor Opaniuk136644a2016-09-13 13:40:56 +030048#define UNUSED(x) (void)(x)
Pascal Brandc639ac82015-07-02 08:53:34 +020049/*
50 * Helpers for commands towards the crypt TA
51 */
52TEEC_Result ta_crypt_cmd_allocate_operation(ADBG_Case_t *c,
53 TEEC_Session *s,
54 TEE_OperationHandle *oph,
55 uint32_t algo,
56 uint32_t mode,
57 uint32_t max_key_size);
58
59TEEC_Result ta_crypt_cmd_allocate_transient_object(ADBG_Case_t *c,
60 TEEC_Session *s,
61 TEE_ObjectType obj_type, uint32_t max_obj_size,
62 TEE_ObjectHandle *o);
63
64TEEC_Result ta_crypt_cmd_populate_transient_object(ADBG_Case_t *c,
65 TEEC_Session *s,
66 TEE_ObjectHandle o,
67 const TEE_Attribute *attrs,
68 uint32_t attr_count);
69
70TEE_Result ta_crypt_cmd_set_operation_key(ADBG_Case_t *c,
71 TEEC_Session *s,
72 TEE_OperationHandle oph,
73 TEE_ObjectHandle key);
74
75TEEC_Result ta_crypt_cmd_free_transient_object(ADBG_Case_t *c,
76 TEEC_Session *s,
77 TEE_ObjectHandle o);
78
79TEEC_Result ta_crypt_cmd_derive_key(ADBG_Case_t *c,
80 TEEC_Session *s,
81 TEE_OperationHandle oph,
82 TEE_ObjectHandle o,
83 const TEE_Attribute *params,
84 uint32_t paramCount);
85
86TEEC_Result ta_crypt_cmd_get_object_buffer_attribute(ADBG_Case_t *c,
87 TEEC_Session *s,
88 TEE_ObjectHandle o,
89 uint32_t attr_id,
90 void *buf,
91 size_t *blen);
92
93TEEC_Result ta_crypt_cmd_free_operation(ADBG_Case_t *c,
94 TEEC_Session *s,
95 TEE_OperationHandle oph);
96
97void xtest_add_attr(size_t *attr_count, TEE_Attribute *attrs,
98 uint32_t attr_id, const void *buf, size_t len);
Pascal Brande61133f2015-07-08 15:38:37 +020099void xtest_add_attr_value(size_t *attr_count, TEE_Attribute *attrs,
100 uint32_t attr_id, uint32_t value_a, uint32_t value_b);
Pascal Brandc639ac82015-07-02 08:53:34 +0200101
102TEE_Result pack_attrs(const TEE_Attribute *attrs, uint32_t attr_count,
103 uint8_t **buf, size_t *blen);
104
Jerome Forissiere3854162016-08-12 12:40:12 +0200105int ree_fs_get_ta_dirname(TEEC_UUID *p_uuid, char *buffer, uint32_t len);
106
Jens Wiklandere2ca6062016-12-21 14:00:30 +0100107void xtest_mutex_init(pthread_mutex_t *mutex);
108void xtest_mutex_destroy(pthread_mutex_t *mutex);
109void xtest_mutex_lock(pthread_mutex_t *mutex);
110void xtest_mutex_unlock(pthread_mutex_t *mutex);
111
112void xtest_barrier_init(pthread_barrier_t *barrier, unsigned count);
113void xtest_barrier_destroy(pthread_barrier_t *barrier);
114int xtest_barrier_wait(pthread_barrier_t *barrier);
115
Pascal Brandc639ac82015-07-02 08:53:34 +0200116#endif /*XTEST_HELPERS_H*/