1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 use libc::*;
19
TEEC_PARAM_TYPES(p0:u32, p1:u32, p2:u32, p3:u32) -> u3220 pub fn TEEC_PARAM_TYPES(p0:u32, p1:u32, p2:u32, p3:u32) -> u32 {
21 let tmp = p1 << 4 | p2 << 8 | p3 << 12;
22 return p0 | tmp;
23 }
24
25 pub const TEEC_CONFIG_PAYLOAD_REF_COUNT: u32 = 4;
26
27 pub const TEEC_CONFIG_SHAREDMEM_MAX_SIZE: c_ulong = -1 as c_long as c_ulong;
28
29 pub const TEEC_NONE: u32 = 0x00000000;
30 pub const TEEC_VALUE_INPUT: u32 = 0x00000001;
31 pub const TEEC_VALUE_OUTPUT: u32 = 0x00000002;
32 pub const TEEC_VALUE_INOUT: u32 = 0x00000003;
33 pub const TEEC_MEMREF_TEMP_INPUT: u32 = 0x00000005;
34 pub const TEEC_MEMREF_TEMP_OUTPUT: u32 = 0x00000006;
35 pub const TEEC_MEMREF_TEMP_INOUT: u32 = 0x00000007;
36 pub const TEEC_MEMREF_WHOLE: u32 = 0x0000000C;
37 pub const TEEC_MEMREF_PARTIAL_INPUT: u32 = 0x0000000D;
38 pub const TEEC_MEMREF_PARTIAL_OUTPUT: u32 = 0x0000000E;
39 pub const TEEC_MEMREF_PARTIAL_INOUT: u32 = 0x0000000F;
40
41 pub const TEEC_MEM_INPUT: u32 = 0x00000001;
42 pub const TEEC_MEM_OUTPUT: u32 = 0x00000002;
43
44 pub const TEEC_SUCCESS: u32 = 0x00000000;
45 pub const TEEC_ERROR_GENERIC: u32 = 0xFFFF0000;
46 pub const TEEC_ERROR_ACCESS_DENIED: u32 = 0xFFFF0001;
47 pub const TEEC_ERROR_CANCEL: u32 = 0xFFFF0002;
48 pub const TEEC_ERROR_ACCESS_CONFLICT: u32 = 0xFFFF0003;
49 pub const TEEC_ERROR_EXCESS_DATA: u32 = 0xFFFF0004;
50 pub const TEEC_ERROR_BAD_FORMAT: u32 = 0xFFFF0005;
51 pub const TEEC_ERROR_BAD_PARAMETERS: u32 = 0xFFFF0006;
52 pub const TEEC_ERROR_BAD_STATE: u32 = 0xFFFF0007;
53 pub const TEEC_ERROR_ITEM_NOT_FOUND: u32 = 0xFFFF0008;
54 pub const TEEC_ERROR_NOT_IMPLEMENTED: u32 = 0xFFFF0009;
55 pub const TEEC_ERROR_NOT_SUPPORTED: u32 = 0xFFFF000A;
56 pub const TEEC_ERROR_NO_DATA: u32 = 0xFFFF000B;
57 pub const TEEC_ERROR_OUT_OF_MEMORY: u32 = 0xFFFF000C;
58 pub const TEEC_ERROR_BUSY: u32 = 0xFFFF000D;
59 pub const TEEC_ERROR_COMMUNICATION: u32 = 0xFFFF000E;
60 pub const TEEC_ERROR_SECURITY: u32 = 0xFFFF000F;
61 pub const TEEC_ERROR_SHORT_BUFFER: u32 = 0xFFFF0010;
62 pub const TEEC_ERROR_EXTERNAL_CANCEL: u32 = 0xFFFF0011;
63 pub const TEEC_ERROR_TARGET_DEAD: u32 = 0xFFFF3024;
64
65 pub const TEEC_ORIGIN_API: u32 = 0x00000001;
66 pub const TEEC_ORIGIN_COMMS: u32 = 0x00000002;
67 pub const TEEC_ORIGIN_TEE: u32 = 0x00000003;
68 pub const TEEC_ORIGIN_TRUSTED_APP: u32 = 0x00000004;
69
70 pub const TEEC_LOGIN_PUBLIC: u32 = 0x00000000;
71 pub const TEEC_LOGIN_USER: u32 = 0x00000001;
72 pub const TEEC_LOGIN_GROUP: u32 = 0x00000002;
73 pub const TEEC_LOGIN_APPLICATION: u32 = 0x00000004;
74 pub const TEEC_LOGIN_USER_APPLICATION: u32 = 0x00000005;
75 pub const TEEC_LOGIN_GROUP_APPLICATION: u32 = 0x00000006;
76
77 pub type TEEC_Result = u32;
78
79 #[repr(C)]
80 pub struct TEEC_Context {
81 pub fd: c_int,
82 pub reg_mem: bool,
83 }
84
85 #[repr(C)]
86 pub struct TEEC_UUID {
87 pub timeLow: u32,
88 pub timeMid: u16,
89 pub timeHiAndVersion: u16,
90 pub clockSeqAndNode: [u8; 8],
91 }
92
93 #[repr(C)]
94 pub struct TEEC_Session {
95 pub ctx: *mut TEEC_Context,
96 pub session_id: u32,
97 }
98
99 #[repr(C)]
100 pub struct TEEC_SharedMemory {
101 pub buffer: *mut c_void,
102 pub size: size_t,
103 pub flags: u32,
104 pub id: c_int,
105 pub alloced_size: size_t,
106 pub shadow_buffer: *mut c_void,
107 pub registered_fd: c_int,
108 pub buffer_allocated: bool,
109 }
110
111 #[derive(Copy, Clone)]
112 #[repr(C)]
113 pub struct TEEC_TempMemoryReference {
114 pub buffer: *mut c_void,
115 pub size: size_t,
116 }
117
118 #[derive(Copy, Clone)]
119 #[repr(C)]
120 pub struct TEEC_RegisteredMemoryReference {
121 pub parent: *mut TEEC_SharedMemory,
122 pub size: size_t,
123 pub offset: size_t,
124 }
125
126 #[derive(Copy, Clone)]
127 #[repr(C)]
128 pub struct TEEC_Value {
129 pub a: u32,
130 pub b: u32,
131 }
132
133 #[repr(C)]
134 #[derive(Copy, Clone)]
135 pub union TEEC_Parameter {
136 pub tmpref: TEEC_TempMemoryReference,
137 pub memref: TEEC_RegisteredMemoryReference,
138 pub value: TEEC_Value,
139 }
140
141 #[repr(C)]
142 pub struct TEEC_Operation {
143 pub started: u32,
144 pub paramTypes: u32,
145 pub params: [TEEC_Parameter; TEEC_CONFIG_PAYLOAD_REF_COUNT as usize],
146 pub session: *mut TEEC_Session,
147 }
148
149 extern "C" {
TEEC_InitializeContext(name: *const c_char, context: *mut TEEC_Context) -> TEEC_Result150 pub fn TEEC_InitializeContext(name: *const c_char, context: *mut TEEC_Context) -> TEEC_Result;
TEEC_FinalizeContext(context: *mut TEEC_Context)151 pub fn TEEC_FinalizeContext(context: *mut TEEC_Context);
TEEC_OpenSession(context: *mut TEEC_Context, session: *mut TEEC_Session, destination: *const TEEC_UUID, connectionMethod: u32, connectionData: *const c_void, operation: *mut TEEC_Operation, returnOrigin: *mut u32) -> TEEC_Result152 pub fn TEEC_OpenSession(context: *mut TEEC_Context,
153 session: *mut TEEC_Session,
154 destination: *const TEEC_UUID,
155 connectionMethod: u32,
156 connectionData: *const c_void,
157 operation: *mut TEEC_Operation,
158 returnOrigin: *mut u32) -> TEEC_Result;
TEEC_CloseSession(session: *mut TEEC_Session)159 pub fn TEEC_CloseSession(session: *mut TEEC_Session);
TEEC_InvokeCommand(session: *mut TEEC_Session, commandID: u32, operation: *mut TEEC_Operation, returnOrigin: *mut u32) -> TEEC_Result160 pub fn TEEC_InvokeCommand(session: *mut TEEC_Session,
161 commandID: u32,
162 operation: *mut TEEC_Operation,
163 returnOrigin: *mut u32) -> TEEC_Result;
TEEC_RegisterSharedMemory(context: *mut TEEC_Context, sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result164 pub fn TEEC_RegisterSharedMemory(context: *mut TEEC_Context,
165 sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result;
TEEC_AllocateSharedMemory(context: *mut TEEC_Context, sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result166 pub fn TEEC_AllocateSharedMemory(context: *mut TEEC_Context,
167 sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result;
TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory)168 pub fn TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory);
TEEC_RequestCancellation(operation: *mut TEEC_Operation)169 pub fn TEEC_RequestCancellation(operation: *mut TEEC_Operation);
170 }
171