blob: 6312c038569db137aeab8d4332fcab65ec092c00 [file] [log] [blame]
Etienne Carriere9b7b70d2020-05-16 10:27:23 +02001/* SPDX-License-Identifier: GPL-2.0 */
Pascal Brandc639ac82015-07-02 08:53:34 +02002/*
3 * Copyright (c) 2014, STMicroelectronics International N.V.
Pascal Brandc639ac82015-07-02 08:53:34 +02004 */
5
6#ifndef XTEST_HELPERS_H
7#define XTEST_HELPERS_H
8
Pascal Brandc639ac82015-07-02 08:53:34 +02009#include <adbg.h>
Jens Wiklandere2ca6062016-12-21 14:00:30 +010010#include <pthread.h>
11#include <tee_api_types.h>
12#include <tee_client_api.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020013
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020014extern unsigned int level;
15
Pascal Brandc639ac82015-07-02 08:53:34 +020016/* Global context to use if any context is needed as input to a function */
17extern TEEC_Context xtest_teec_ctx;
18
19/*
20 * Initializes the context above, should be called before the ADBG test
21 * cases are run.
22 */
23TEEC_Result xtest_teec_ctx_init(void);
24void xtest_teec_ctx_deinit(void);
25
26/* Opens a session */
27TEEC_Result xtest_teec_open_session(TEEC_Session *session,
28 const TEEC_UUID *uuid, TEEC_Operation *op,
29 uint32_t *ret_orig);
30
31TEEC_Result xtest_teec_open_static_session(TEEC_Session *session,
32 TEEC_Operation *op,
33 uint32_t *ret_orig);
34
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010035#define TEEC_OPERATION_INITIALIZER { }
Pascal Brandc639ac82015-07-02 08:53:34 +020036
37/* IO access macro */
38#define IO(addr) (*((volatile unsigned long *)(addr)))
39
Igor Opaniuk136644a2016-09-13 13:40:56 +030040#define UNUSED(x) (void)(x)
Pascal Brandc639ac82015-07-02 08:53:34 +020041/*
42 * Helpers for commands towards the crypt TA
43 */
44TEEC_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
51TEEC_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
56TEEC_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
62TEE_Result ta_crypt_cmd_set_operation_key(ADBG_Case_t *c,
63 TEEC_Session *s,
64 TEE_OperationHandle oph,
65 TEE_ObjectHandle key);
66
67TEEC_Result ta_crypt_cmd_free_transient_object(ADBG_Case_t *c,
68 TEEC_Session *s,
69 TEE_ObjectHandle o);
70
71TEEC_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
78TEEC_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
85TEEC_Result ta_crypt_cmd_free_operation(ADBG_Case_t *c,
86 TEEC_Session *s,
87 TEE_OperationHandle oph);
88
Jerome Forissier6635c962020-01-22 17:49:00 +010089bool ta_crypt_cmd_is_algo_supported(ADBG_Case_t *c, TEEC_Session *s,
90 uint32_t alg, uint32_t element);
91
Vesa Jääskeläinene8c0c8d2020-04-05 20:11:53 +030092TEEC_Result ta_os_test_cmd_client_identity(TEEC_Session *session,
93 uint32_t *login,
94 TEEC_UUID *client_uuid);
95
Pascal Brandc639ac82015-07-02 08:53:34 +020096void xtest_add_attr(size_t *attr_count, TEE_Attribute *attrs,
97 uint32_t attr_id, const void *buf, size_t len);
Pascal Brande61133f2015-07-08 15:38:37 +020098void 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 Brandc639ac82015-07-02 08:53:34 +0200100
101TEE_Result pack_attrs(const TEE_Attribute *attrs, uint32_t attr_count,
102 uint8_t **buf, size_t *blen);
103
Jens Wiklandere2ca6062016-12-21 14:00:30 +0100104void xtest_mutex_init(pthread_mutex_t *mutex);
105void xtest_mutex_destroy(pthread_mutex_t *mutex);
106void xtest_mutex_lock(pthread_mutex_t *mutex);
107void xtest_mutex_unlock(pthread_mutex_t *mutex);
108
109void xtest_barrier_init(pthread_barrier_t *barrier, unsigned count);
110void xtest_barrier_destroy(pthread_barrier_t *barrier);
111int xtest_barrier_wait(pthread_barrier_t *barrier);
112
Pascal Brandc639ac82015-07-02 08:53:34 +0200113#endif /*XTEST_HELPERS_H*/