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