@@ -58,6 +58,29 @@ TEEC_Result ocall_handler(TEEC_UUID *taUUID, uint32_t commandId,
58
58
printf ("\n" );
59
59
60
60
switch (commandId ) {
61
+ case CA_OCALL_CMD_REPLY_SESSION_OPEN :
62
+ expected_pt = TEEC_PARAM_TYPES (TEEC_VALUE_INOUT ,
63
+ TEEC_NONE ,
64
+ TEEC_NONE ,
65
+ TEEC_MEMREF_TEMP_INPUT );
66
+ if (paramTypes != expected_pt ) {
67
+ fprintf (stderr , "Bad parameter types\n" );
68
+ return TEEC_ERROR_BAD_PARAMETERS ;
69
+ }
70
+ if (!params [3 ].tmpref .buffer ) {
71
+ fprintf (stderr , "No buffer\n" );
72
+ return TEEC_ERROR_BAD_PARAMETERS ;
73
+ }
74
+
75
+ /* Print out the OCALL's INPUT/INOUT parameters */
76
+ printf ("Input values: 0x%x, 0x%x\n" , params [0 ].value .a ,
77
+ params [0 ].value .b );
78
+ printf ("Input string: %s\n" , (char * )params [3 ].tmpref .buffer );
79
+
80
+ /* Set the OCALL's INOUT parameters */
81
+ params [0 ].value .a = 0xCDDC1001 ;
82
+ params [0 ].value .b = 0xFFFFCAFE ;
83
+ break ;
61
84
case CA_OCALL_CMD_REPLY_TA :
62
85
expected_pt = TEEC_PARAM_TYPES (TEEC_VALUE_INPUT ,
63
86
TEEC_VALUE_INOUT ,
@@ -94,13 +117,13 @@ TEEC_Result ocall_handler(TEEC_UUID *taUUID, uint32_t commandId,
94
117
95
118
params [3 ].tmpref .size = strlen (msg ) + 1 ;
96
119
memcpy (params [3 ].tmpref .buffer , msg , params [3 ].tmpref .size );
97
-
98
- printf ("OCALL handled\n" );
99
120
break ;
100
121
default :
101
122
fprintf (stderr , "Bad function ID\n" );
102
123
return TEEC_ERROR_BAD_PARAMETERS ;
103
124
}
125
+
126
+ printf ("OCALL handled\n" );
104
127
return TEEC_SUCCESS ;
105
128
}
106
129
@@ -109,24 +132,26 @@ int main(int argc, char* argv[])
109
132
TEEC_Context ctx ;
110
133
TEEC_Session sess ;
111
134
TEEC_UUID uuid = TA_OCALL_UUID ;
112
- TEEC_Operation op = { 0 } ;
135
+ TEEC_Operation op ;
113
136
114
137
TEEC_Result res ;
115
138
uint32_t err_origin ;
116
139
117
140
char buf [128 ];
141
+ char buf2 [128 ];
118
142
char * msg1 = "This string was sent by the CA" ;
119
143
const char * msg2 = "The CA thinks this is a fun riddle" ;
120
144
121
145
/*
122
- * The TEE context OCALL setting allows setting the callback handler for
123
- * when an OCALL arrives from the TA. This handler is effectively the
124
- * equivalent of TA_InvokeCommandEntryPoint. Additionally, one may set
125
- * an arbitrary pointer that will be passed to the OCALL handler when
126
- * invoked.
146
+ * The TEE context OCALL setting allows specifying the callback handler
147
+ * for when an OCALL arrives from the TA. This handler is effectively
148
+ * the equivalent of TA_InvokeCommandEntryPoint, but on the CA side.
149
+ * Additionally, one may set an arbitrary pointer that will be passed
150
+ * to the OCALL handler when invoked.
127
151
*
128
152
* NOTE: You must pass this setting to the TEE context initialization
129
- * routine to receive OCALLs.
153
+ * routine to receive OCALLs; otherwise, all OCALLs will return
154
+ * a failure code.
130
155
*/
131
156
TEEC_ContextSettingOcall ocall_setting = {
132
157
.handler = ocall_handler ,
@@ -145,8 +170,8 @@ int main(int argc, char* argv[])
145
170
errx (1 , "TEEC_InitializeContext failed with code 0x%x" , res );
146
171
147
172
/*
148
- * The session data settings allows attaching an arbitrary pointer to
149
- * the session. This pointer will be passed to the OCALL handler when
173
+ * The session data setting allows attaching an arbitrary pointer to the
174
+ * session. This pointer will be passed to the OCALL handler when
150
175
* invoked.
151
176
*
152
177
* NOTE: This is optional; you can use TEEC_OpenSession as well even if
@@ -162,13 +187,32 @@ int main(int argc, char* argv[])
162
187
.u .data = & data_setting ,
163
188
};
164
189
165
- /* Open a session with settings */
190
+ /* Set up the parameters for the TA's session open handler */
191
+ memset (& op , 0 , sizeof (op ));
192
+ op .paramTypes = TEEC_PARAM_TYPES (
193
+ TEEC_VALUE_INPUT ,
194
+ TEEC_MEMREF_TEMP_INPUT ,
195
+ TEEC_NONE ,
196
+ TEEC_NONE );
197
+
198
+ op .params [0 ].value .a = 0x0000CAFE ;
199
+ op .params [0 ].value .b = 0xCAFE0000 ;
200
+
201
+ op .params [1 ].tmpref .buffer = (void * )msg2 ;
202
+ op .params [1 ].tmpref .size = strlen (msg2 ) + 1 ;
203
+
204
+ /* Open a session with settings; the sample TA will issue an OCALL */
166
205
res = TEEC_OpenSession2 (& ctx , & sess , & uuid , TEEC_LOGIN_PUBLIC , NULL ,
167
- NULL , & err_origin , & session_settings , 1 );
206
+ & op , & err_origin , & session_settings , 1 );
168
207
if (res != TEEC_SUCCESS )
169
208
errx (1 , "TEEC_OpenSessionEx failed with code 0x%x origin 0x%x" ,
170
209
res , err_origin );
171
210
211
+ /*
212
+ * The code below executes after the OCALL has been handled in the
213
+ * callback at the top of this file.
214
+ */
215
+
172
216
/*
173
217
* Set up the parameters for the function invocation. These are just to
174
218
* show that the CA can pass parameters to the TA and that during the
@@ -177,6 +221,7 @@ int main(int argc, char* argv[])
177
221
* parameters passed from the CA to the TA do not interfere with those
178
222
* passed from the TA to the CA, and vice-versa.
179
223
*/
224
+ memset (& op , 0 , sizeof (op ));
180
225
op .paramTypes = TEEC_PARAM_TYPES (
181
226
TEEC_VALUE_INPUT ,
182
227
TEEC_VALUE_INOUT ,
@@ -203,8 +248,8 @@ int main(int argc, char* argv[])
203
248
res , err_origin );
204
249
205
250
/*
206
- * The code below executes after the OCALL has been handled in the
207
- * callback at the top of this file.
251
+ * The code below once again executes after the OCALL has been handled
252
+ * in the callback at the top of this file.
208
253
*/
209
254
210
255
/*
0 commit comments