1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 #include <stdio.h>
6 #include <string.h>
7
8 #include <zircon/syscalls.h>
9 #include <zircon/types.h>
10
11 #include <tee-client-api/tee_client_api.h>
12
13 const TEEC_UUID hello_world_ta = {0x8aaaf200,
14 0x2450,
15 0x11e4,
16 {0xab, 0xe2, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
17
18 #define TA_HELLO_WORLD_CMD_INC_VALUE 0
19
main(int argc,const char ** argv)20 int main(int argc, const char** argv) {
21 const char* prog_name = argv[0];
22
23 TEEC_Result result;
24 TEEC_Context context;
25 TEEC_Session session;
26 uint32_t return_origin;
27
28 result = TEEC_InitializeContext(NULL, &context);
29 if (result != TEEC_SUCCESS) {
30 printf("%s: Failed to initialize context (%x)\n", prog_name, result);
31 return result;
32 }
33
34 result = TEEC_OpenSession(&context, &session, &hello_world_ta,
35 TEEC_LOGIN_PUBLIC, NULL, NULL, &return_origin);
36 if (result != TEEC_SUCCESS) {
37 printf("%s: Failed to open session (%x %x)\n", prog_name, result, return_origin);
38 goto out_finalize;
39 }
40
41 TEEC_Operation op;
42 memset(&op, 0, sizeof(op));
43
44 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
45 op.params[0].value.a = 42;
46
47 printf("Invoking TA to increment %d\n", op.params[0].value.a);
48
49 result = TEEC_InvokeCommand(&session, TA_HELLO_WORLD_CMD_INC_VALUE, &op, &return_origin);
50
51 if (result != TEEC_SUCCESS) {
52 printf("TEEC_InvokeCommand failed with code 0x%x origin 0x%x\n",
53 result, return_origin);
54 goto out_close_session;
55 }
56
57 printf("TA incremented value to %d\n", op.params[0].value.a);
58
59 out_close_session:
60 TEEC_CloseSession(&session);
61
62 out_finalize:
63 TEEC_FinalizeContext(&context);
64
65 return result;
66 }
67