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 
50 /* Called when a command is invoked */
TA_InvokeCommandEntryPoint(void * pSessionContext,uint32_t nCommandID,uint32_t nParamTypes,TEE_Param pParams[4])51 TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext,
52 				      uint32_t nCommandID, uint32_t nParamTypes,
53 				      TEE_Param pParams[4])
54 {
55 	(void)pSessionContext;
56 
57 	switch (nCommandID) {
58 	case TA_OS_TEST_CMD_INIT:
59 		return ta_entry_init(nParamTypes, pParams);
60 
61 	case TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT:
62 		return ta_entry_client_with_timeout(nParamTypes, pParams);
63 
64 	case TA_OS_TEST_CMD_BASIC:
65 		return ta_entry_basic(nParamTypes, pParams);
66 
67 	case TA_OS_TEST_CMD_PANIC:
68 		return ta_entry_panic(nParamTypes, pParams);
69 
70 	case TA_OS_TEST_CMD_CLIENT:
71 		return ta_entry_client(nParamTypes, pParams);
72 
73 	case TA_OS_TEST_CMD_PARAMS_ACCESS:
74 		return ta_entry_params_access_rights(nParamTypes, pParams);
75 
76 	case TA_OS_TEST_CMD_WAIT:
77 		return ta_entry_wait(nParamTypes, pParams);
78 
79 	case TA_OS_TEST_CMD_BAD_MEM_ACCESS:
80 		return ta_entry_bad_mem_access(nParamTypes, pParams);
81 
82 	case TA_OS_TEST_CMD_TA2TA_MEMREF:
83 		return ta_entry_ta2ta_memref(nParamTypes, pParams);
84 
85 	case TA_OS_TEST_CMD_TA2TA_MEMREF_MIX:
86 		return ta_entry_ta2ta_memref_mix(nParamTypes, pParams);
87 
88 	case TA_OS_TEST_CMD_PARAMS:
89 		return ta_entry_params(nParamTypes, pParams);
90 
91 	case TA_OS_TEST_CMD_NULL_MEMREF_PARAMS:
92 		return ta_entry_null_memref(nParamTypes, pParams);
93 
94 	case TA_OS_TEST_CMD_CALL_LIB:
95 		return ta_entry_call_lib(nParamTypes, pParams);
96 
97 	case TA_OS_TEST_CMD_CALL_LIB_PANIC:
98 		return ta_entry_call_lib_panic(nParamTypes, pParams);
99 
100 	case TA_OS_TEST_CMD_CALL_LIB_DL:
101 		return ta_entry_call_lib_dl(nParamTypes, pParams);
102 
103 	case TA_OS_TEST_CMD_CALL_LIB_DL_PANIC:
104 		return ta_entry_call_lib_dl_panic(nParamTypes, pParams);
105 
106 	case TA_OS_TEST_CMD_GET_GLOBAL_VAR:
107 		return ta_entry_get_global_var(nParamTypes, pParams);
108 
109 	case TA_OS_TEST_CMD_CLIENT_IDENTITY:
110 		return ta_entry_client_identity(nParamTypes, pParams);
111 
112 	case TA_OS_TEST_CMD_TLS_TEST_MAIN:
113 		return ta_entry_tls_test_main();
114 
115 	case TA_OS_TEST_CMD_TLS_TEST_SHLIB:
116 		return ta_entry_tls_test_shlib();
117 
118 	case TA_OS_TEST_CMD_DL_PHDR:
119 		return ta_entry_dl_phdr();
120 
121 	case TA_OS_TEST_CMD_DL_PHDR_DL:
122 		return ta_entry_dl_phdr_dl();
123 
124 #if defined(WITH_CXX_TESTS)
125 	case TA_OS_TEST_CMD_CXX_CTOR_MAIN:
126 		return ta_entry_cxx_ctor_main();
127 
128 	case TA_OS_TEST_CMD_CXX_CTOR_SHLIB:
129 		return ta_entry_cxx_ctor_shlib();
130 
131 	case TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL:
132 		return ta_entry_cxx_ctor_shlib_dl();
133 
134 	case TA_OS_TEST_CMD_CXX_EXC_MAIN:
135 		return ta_entry_cxx_exc_main();
136 
137 	case TA_OS_TEST_CMD_CXX_EXC_MIXED:
138 		return ta_entry_cxx_exc_mixed();
139 #else
140 	case TA_OS_TEST_CMD_CXX_CTOR_MAIN:
141 	case TA_OS_TEST_CMD_CXX_CTOR_SHLIB:
142 	case TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL:
143 	case TA_OS_TEST_CMD_CXX_EXC_MAIN:
144 	case TA_OS_TEST_CMD_CXX_EXC_MIXED:
145 		return TEE_ERROR_NOT_SUPPORTED;
146 #endif
147 
148 	default:
149 		return TEE_ERROR_BAD_PARAMETERS;
150 	}
151 }
152