Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1 | /* |
| 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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 17 | #include <adbg.h> |
Jens Wiklander | e2ca606 | 2016-12-21 14:00:30 +0100 | [diff] [blame] | 18 | #include <pthread.h> |
| 19 | #include <tee_api_types.h> |
| 20 | #include <tee_client_api.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 21 | |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 22 | extern unsigned int level; |
| 23 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 24 | /* Global context to use if any context is needed as input to a function */ |
| 25 | extern TEEC_Context xtest_teec_ctx; |
| 26 | |
| 27 | /* |
| 28 | * Initializes the context above, should be called before the ADBG test |
| 29 | * cases are run. |
| 30 | */ |
| 31 | TEEC_Result xtest_teec_ctx_init(void); |
| 32 | void xtest_teec_ctx_deinit(void); |
| 33 | |
| 34 | /* Opens a session */ |
| 35 | TEEC_Result xtest_teec_open_session(TEEC_Session *session, |
| 36 | const TEEC_UUID *uuid, TEEC_Operation *op, |
| 37 | uint32_t *ret_orig); |
| 38 | |
| 39 | TEEC_Result xtest_teec_open_static_session(TEEC_Session *session, |
| 40 | TEEC_Operation *op, |
| 41 | uint32_t *ret_orig); |
| 42 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 43 | #define TEEC_OPERATION_INITIALIZER { } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 44 | |
| 45 | /* IO access macro */ |
| 46 | #define IO(addr) (*((volatile unsigned long *)(addr))) |
| 47 | |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 48 | #define UNUSED(x) (void)(x) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 49 | /* |
| 50 | * Helpers for commands towards the crypt TA |
| 51 | */ |
| 52 | TEEC_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 | |
| 59 | TEEC_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 | |
| 64 | TEEC_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 | |
| 70 | TEE_Result ta_crypt_cmd_set_operation_key(ADBG_Case_t *c, |
| 71 | TEEC_Session *s, |
| 72 | TEE_OperationHandle oph, |
| 73 | TEE_ObjectHandle key); |
| 74 | |
| 75 | TEEC_Result ta_crypt_cmd_free_transient_object(ADBG_Case_t *c, |
| 76 | TEEC_Session *s, |
| 77 | TEE_ObjectHandle o); |
| 78 | |
| 79 | TEEC_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 | |
| 86 | TEEC_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 | |
| 93 | TEEC_Result ta_crypt_cmd_free_operation(ADBG_Case_t *c, |
| 94 | TEEC_Session *s, |
| 95 | TEE_OperationHandle oph); |
| 96 | |
Jerome Forissier | 6635c96 | 2020-01-22 17:49:00 +0100 | [diff] [blame^] | 97 | bool ta_crypt_cmd_is_algo_supported(ADBG_Case_t *c, TEEC_Session *s, |
| 98 | uint32_t alg, uint32_t element); |
| 99 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 100 | void xtest_add_attr(size_t *attr_count, TEE_Attribute *attrs, |
| 101 | uint32_t attr_id, const void *buf, size_t len); |
Pascal Brand | e61133f | 2015-07-08 15:38:37 +0200 | [diff] [blame] | 102 | void xtest_add_attr_value(size_t *attr_count, TEE_Attribute *attrs, |
| 103 | uint32_t attr_id, uint32_t value_a, uint32_t value_b); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 104 | |
| 105 | TEE_Result pack_attrs(const TEE_Attribute *attrs, uint32_t attr_count, |
| 106 | uint8_t **buf, size_t *blen); |
| 107 | |
Jens Wiklander | e2ca606 | 2016-12-21 14:00:30 +0100 | [diff] [blame] | 108 | void xtest_mutex_init(pthread_mutex_t *mutex); |
| 109 | void xtest_mutex_destroy(pthread_mutex_t *mutex); |
| 110 | void xtest_mutex_lock(pthread_mutex_t *mutex); |
| 111 | void xtest_mutex_unlock(pthread_mutex_t *mutex); |
| 112 | |
| 113 | void xtest_barrier_init(pthread_barrier_t *barrier, unsigned count); |
| 114 | void xtest_barrier_destroy(pthread_barrier_t *barrier); |
| 115 | int xtest_barrier_wait(pthread_barrier_t *barrier); |
| 116 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 117 | #endif /*XTEST_HELPERS_H*/ |