Etienne Carriere | 9b7b70d | 2020-05-16 10:27:23 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014, STMicroelectronics International N.V. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef XTEST_HELPERS_H |
| 7 | #define XTEST_HELPERS_H |
| 8 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 9 | #include <adbg.h> |
Jens Wiklander | e2ca606 | 2016-12-21 14:00:30 +0100 | [diff] [blame] | 10 | #include <pthread.h> |
| 11 | #include <tee_api_types.h> |
| 12 | #include <tee_client_api.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 13 | |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 14 | extern unsigned int level; |
| 15 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 16 | /* Global context to use if any context is needed as input to a function */ |
| 17 | extern TEEC_Context xtest_teec_ctx; |
| 18 | |
| 19 | /* |
| 20 | * Initializes the context above, should be called before the ADBG test |
| 21 | * cases are run. |
| 22 | */ |
| 23 | TEEC_Result xtest_teec_ctx_init(void); |
| 24 | void xtest_teec_ctx_deinit(void); |
| 25 | |
| 26 | /* Opens a session */ |
| 27 | TEEC_Result xtest_teec_open_session(TEEC_Session *session, |
| 28 | const TEEC_UUID *uuid, TEEC_Operation *op, |
| 29 | uint32_t *ret_orig); |
| 30 | |
| 31 | TEEC_Result xtest_teec_open_static_session(TEEC_Session *session, |
| 32 | TEEC_Operation *op, |
| 33 | uint32_t *ret_orig); |
| 34 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 35 | #define TEEC_OPERATION_INITIALIZER { } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 36 | |
| 37 | /* IO access macro */ |
| 38 | #define IO(addr) (*((volatile unsigned long *)(addr))) |
| 39 | |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 40 | #define UNUSED(x) (void)(x) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 41 | /* |
| 42 | * Helpers for commands towards the crypt TA |
| 43 | */ |
| 44 | TEEC_Result ta_crypt_cmd_allocate_operation(ADBG_Case_t *c, |
| 45 | TEEC_Session *s, |
| 46 | TEE_OperationHandle *oph, |
| 47 | uint32_t algo, |
| 48 | uint32_t mode, |
| 49 | uint32_t max_key_size); |
| 50 | |
| 51 | TEEC_Result ta_crypt_cmd_allocate_transient_object(ADBG_Case_t *c, |
| 52 | TEEC_Session *s, |
| 53 | TEE_ObjectType obj_type, uint32_t max_obj_size, |
| 54 | TEE_ObjectHandle *o); |
| 55 | |
| 56 | TEEC_Result ta_crypt_cmd_populate_transient_object(ADBG_Case_t *c, |
| 57 | TEEC_Session *s, |
| 58 | TEE_ObjectHandle o, |
| 59 | const TEE_Attribute *attrs, |
| 60 | uint32_t attr_count); |
| 61 | |
| 62 | TEE_Result ta_crypt_cmd_set_operation_key(ADBG_Case_t *c, |
| 63 | TEEC_Session *s, |
| 64 | TEE_OperationHandle oph, |
| 65 | TEE_ObjectHandle key); |
| 66 | |
| 67 | TEEC_Result ta_crypt_cmd_free_transient_object(ADBG_Case_t *c, |
| 68 | TEEC_Session *s, |
| 69 | TEE_ObjectHandle o); |
| 70 | |
| 71 | TEEC_Result ta_crypt_cmd_derive_key(ADBG_Case_t *c, |
| 72 | TEEC_Session *s, |
| 73 | TEE_OperationHandle oph, |
| 74 | TEE_ObjectHandle o, |
| 75 | const TEE_Attribute *params, |
| 76 | uint32_t paramCount); |
| 77 | |
| 78 | TEEC_Result ta_crypt_cmd_get_object_buffer_attribute(ADBG_Case_t *c, |
| 79 | TEEC_Session *s, |
| 80 | TEE_ObjectHandle o, |
| 81 | uint32_t attr_id, |
| 82 | void *buf, |
| 83 | size_t *blen); |
| 84 | |
| 85 | TEEC_Result ta_crypt_cmd_free_operation(ADBG_Case_t *c, |
| 86 | TEEC_Session *s, |
| 87 | TEE_OperationHandle oph); |
| 88 | |
Jerome Forissier | 6635c96 | 2020-01-22 17:49:00 +0100 | [diff] [blame] | 89 | bool ta_crypt_cmd_is_algo_supported(ADBG_Case_t *c, TEEC_Session *s, |
| 90 | uint32_t alg, uint32_t element); |
| 91 | |
Vesa Jääskeläinen | e8c0c8d | 2020-04-05 20:11:53 +0300 | [diff] [blame] | 92 | TEEC_Result ta_os_test_cmd_client_identity(TEEC_Session *session, |
| 93 | uint32_t *login, |
| 94 | TEEC_UUID *client_uuid); |
| 95 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 96 | void xtest_add_attr(size_t *attr_count, TEE_Attribute *attrs, |
| 97 | uint32_t attr_id, const void *buf, size_t len); |
Pascal Brand | e61133f | 2015-07-08 15:38:37 +0200 | [diff] [blame] | 98 | void xtest_add_attr_value(size_t *attr_count, TEE_Attribute *attrs, |
| 99 | uint32_t attr_id, uint32_t value_a, uint32_t value_b); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 100 | |
| 101 | TEE_Result pack_attrs(const TEE_Attribute *attrs, uint32_t attr_count, |
| 102 | uint8_t **buf, size_t *blen); |
| 103 | |
Jens Wiklander | e2ca606 | 2016-12-21 14:00:30 +0100 | [diff] [blame] | 104 | void xtest_mutex_init(pthread_mutex_t *mutex); |
| 105 | void xtest_mutex_destroy(pthread_mutex_t *mutex); |
| 106 | void xtest_mutex_lock(pthread_mutex_t *mutex); |
| 107 | void xtest_mutex_unlock(pthread_mutex_t *mutex); |
| 108 | |
| 109 | void xtest_barrier_init(pthread_barrier_t *barrier, unsigned count); |
| 110 | void xtest_barrier_destroy(pthread_barrier_t *barrier); |
| 111 | int xtest_barrier_wait(pthread_barrier_t *barrier); |
| 112 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 113 | #endif /*XTEST_HELPERS_H*/ |