1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2014, STMicroelectronics International N.V.
4 * All rights reserved.
5 */
6 #include <stdint.h>
7 #include <init.h>
8 #include <os_test.h>
9 #include <ta_os_test.h>
10 #include <tee_internal_api_extensions.h>
11 #include <tee_ta_api.h>
12
13 /*
14 * Trusted Application Entry Points
15 */
16
17 /* Called each time a new instance is created */
TA_CreateEntryPoint(void)18 TEE_Result TA_CreateEntryPoint(void)
19 {
20 DMSG("TA_CreateEntryPoint");
21 return TEE_SUCCESS;
22 }
23
24 /* Called each time an instance is destroyed */
TA_DestroyEntryPoint(void)25 void TA_DestroyEntryPoint(void)
26 {
27 DMSG("TA_DestroyEntryPoint");
28 }
29
30 /* Called each time a session is opened */
TA_OpenSessionEntryPoint(uint32_t nParamTypes,TEE_Param pParams[4],void ** ppSessionContext)31 TEE_Result TA_OpenSessionEntryPoint(uint32_t nParamTypes,
32 TEE_Param pParams[4],
33 void **ppSessionContext)
34 {
35 (void)nParamTypes;
36 (void)pParams;
37 (void)ppSessionContext;
38 DMSG("TA_OpenSessionEntryPoint");
39 TEE_UnmaskCancellation();
40 return TEE_SUCCESS;
41 }
42
43 /* Called each time a session is closed */
TA_CloseSessionEntryPoint(void * pSessionContext)44 void TA_CloseSessionEntryPoint(void *pSessionContext)
45 {
46 (void)pSessionContext;
47 DMSG("TA_CloseSessionEntryPoint");
48 }
49
ta_entry_pauth_test_nop(void)50 __weak TEE_Result ta_entry_pauth_test_nop(void)
51 {
52 return TEE_ERROR_NOT_SUPPORTED;
53 }
54
ta_entry_pauth_corrupt_pac(void)55 __weak TEE_Result ta_entry_pauth_corrupt_pac(void)
56 {
57 return TEE_ERROR_NOT_SUPPORTED;
58 }
59
60 /* Called when a command is invoked */
TA_InvokeCommandEntryPoint(void * pSessionContext,uint32_t nCommandID,uint32_t nParamTypes,TEE_Param pParams[4])61 TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext,
62 uint32_t nCommandID, uint32_t nParamTypes,
63 TEE_Param pParams[4])
64 {
65 (void)pSessionContext;
66
67 switch (nCommandID) {
68 case TA_OS_TEST_CMD_INIT:
69 return ta_entry_init(nParamTypes, pParams);
70
71 case TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT:
72 return ta_entry_client_with_timeout(nParamTypes, pParams);
73
74 case TA_OS_TEST_CMD_BASIC:
75 return ta_entry_basic(nParamTypes, pParams);
76
77 case TA_OS_TEST_CMD_PANIC:
78 return ta_entry_panic(nParamTypes, pParams);
79
80 case TA_OS_TEST_CMD_CLIENT:
81 return ta_entry_client(nParamTypes, pParams);
82
83 case TA_OS_TEST_CMD_PARAMS_ACCESS:
84 return ta_entry_params_access_rights(nParamTypes, pParams);
85
86 case TA_OS_TEST_CMD_WAIT:
87 return ta_entry_wait(nParamTypes, pParams);
88
89 case TA_OS_TEST_CMD_BAD_MEM_ACCESS:
90 return ta_entry_bad_mem_access(nParamTypes, pParams);
91
92 case TA_OS_TEST_CMD_TA2TA_MEMREF:
93 return ta_entry_ta2ta_memref(nParamTypes, pParams);
94
95 case TA_OS_TEST_CMD_TA2TA_MEMREF_MIX:
96 return ta_entry_ta2ta_memref_mix(nParamTypes, pParams);
97
98 case TA_OS_TEST_CMD_PARAMS:
99 return ta_entry_params(nParamTypes, pParams);
100
101 case TA_OS_TEST_CMD_NULL_MEMREF_PARAMS:
102 return ta_entry_null_memref(nParamTypes, pParams);
103
104 case TA_OS_TEST_CMD_CALL_LIB:
105 return ta_entry_call_lib(nParamTypes, pParams);
106
107 case TA_OS_TEST_CMD_CALL_LIB_PANIC:
108 return ta_entry_call_lib_panic(nParamTypes, pParams);
109
110 case TA_OS_TEST_CMD_CALL_LIB_DL:
111 return ta_entry_call_lib_dl(nParamTypes, pParams);
112
113 case TA_OS_TEST_CMD_CALL_LIB_DL_PANIC:
114 return ta_entry_call_lib_dl_panic(nParamTypes, pParams);
115
116 case TA_OS_TEST_CMD_GET_GLOBAL_VAR:
117 return ta_entry_get_global_var(nParamTypes, pParams);
118
119 case TA_OS_TEST_CMD_CLIENT_IDENTITY:
120 return ta_entry_client_identity(nParamTypes, pParams);
121
122 case TA_OS_TEST_CMD_TLS_TEST_MAIN:
123 return ta_entry_tls_test_main();
124
125 case TA_OS_TEST_CMD_TLS_TEST_SHLIB:
126 return ta_entry_tls_test_shlib();
127
128 case TA_OS_TEST_CMD_DL_PHDR:
129 return ta_entry_dl_phdr();
130
131 case TA_OS_TEST_CMD_DL_PHDR_DL:
132 return ta_entry_dl_phdr_dl();
133
134 #if defined(WITH_CXX_TESTS)
135 case TA_OS_TEST_CMD_CXX_CTOR_MAIN:
136 return ta_entry_cxx_ctor_main();
137
138 case TA_OS_TEST_CMD_CXX_CTOR_SHLIB:
139 return ta_entry_cxx_ctor_shlib();
140
141 case TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL:
142 return ta_entry_cxx_ctor_shlib_dl();
143
144 case TA_OS_TEST_CMD_CXX_EXC_MAIN:
145 return ta_entry_cxx_exc_main();
146
147 case TA_OS_TEST_CMD_CXX_EXC_MIXED:
148 return ta_entry_cxx_exc_mixed();
149 #else
150 case TA_OS_TEST_CMD_CXX_CTOR_MAIN:
151 case TA_OS_TEST_CMD_CXX_CTOR_SHLIB:
152 case TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL:
153 case TA_OS_TEST_CMD_CXX_EXC_MAIN:
154 case TA_OS_TEST_CMD_CXX_EXC_MIXED:
155 return TEE_ERROR_NOT_SUPPORTED;
156 #endif
157
158 #if defined(CFG_TA_PAUTH)
159 case TA_OS_TEST_CMD_PAUTH_NOP:
160 return ta_entry_pauth_test_nop();
161
162 case TA_OS_TEST_CMD_PAUTH_CORRUPT_PAC:
163 return ta_entry_pauth_corrupt_pac();
164 #else
165 case TA_OS_TEST_CMD_PAUTH_NOP:
166 case TA_OS_TEST_CMD_PAUTH_CORRUPT_PAC:
167 return TEE_ERROR_NOT_SUPPORTED;
168 #endif
169 case TA_OS_TEST_CMD_MEMTAG_USE_AFTER_FREE:
170 return ta_entry_memtag_use_after_free();
171 case TA_OS_TEST_CMD_MEMTAG_INVALID_TAG:
172 return ta_entry_memtag_invalid_tag();
173 case TA_OS_TEST_CMD_MEMTAG_DOUBLE_FREE:
174 return ta_entry_memtag_double_free();
175 case TA_OS_TEST_CMD_MEMTAG_BUFFER_OVERRUN:
176 return ta_entry_memtag_buffer_overrun();
177
178 case TA_OS_TEST_CMD_ATTESTATION:
179 return ta_entry_attestation(nParamTypes, pParams);
180
181 default:
182 return TEE_ERROR_BAD_PARAMETERS;
183 }
184 }
185