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