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 pub memref_null: bool,
84 }
85
86 #[repr(C)]
87 pub struct TEEC_UUID {
88 pub timeLow: u32,
89 pub timeMid: u16,
90 pub timeHiAndVersion: u16,
91 pub clockSeqAndNode: [u8; 8],
92 }
93
94 #[repr(C)]
95 pub struct TEEC_Session {
96 pub ctx: *mut TEEC_Context,
97 pub session_id: u32,
98 }
99
100 #[repr(C)]
101 pub union SharedMemoryFlagsCompat {
102 dummy: bool,
103 flags: u8,
104 }
105
106 #[repr(C)]
107 pub struct TEEC_SharedMemory {
108 pub buffer: *mut c_void,
109 pub size: size_t,
110 pub flags: u32,
111 pub id: c_int,
112 pub alloced_size: size_t,
113 pub shadow_buffer: *mut c_void,
114 pub registered_fd: c_int,
115 pub internal: SharedMemoryFlagsCompat,
116 }
117
118 #[derive(Copy, Clone)]
119 #[repr(C)]
120 pub struct TEEC_TempMemoryReference {
121 pub buffer: *mut c_void,
122 pub size: size_t,
123 }
124
125 #[derive(Copy, Clone)]
126 #[repr(C)]
127 pub struct TEEC_RegisteredMemoryReference {
128 pub parent: *mut TEEC_SharedMemory,
129 pub size: size_t,
130 pub offset: size_t,
131 }
132
133 #[derive(Copy, Clone)]
134 #[repr(C)]
135 pub struct TEEC_Value {
136 pub a: u32,
137 pub b: u32,
138 }
139
140 #[repr(C)]
141 #[derive(Copy, Clone)]
142 pub union TEEC_Parameter {
143 pub tmpref: TEEC_TempMemoryReference,
144 pub memref: TEEC_RegisteredMemoryReference,
145 pub value: TEEC_Value,
146 }
147
148 #[repr(C)]
149 pub struct TEEC_Operation {
150 pub started: u32,
151 pub paramTypes: u32,
152 pub params: [TEEC_Parameter; TEEC_CONFIG_PAYLOAD_REF_COUNT as usize],
153 pub session: *mut TEEC_Session,
154 }
155
156 extern "C" {
TEEC_InitializeContext(name: *const c_char, context: *mut TEEC_Context) -> TEEC_Result157 pub fn TEEC_InitializeContext(name: *const c_char, context: *mut TEEC_Context) -> TEEC_Result;
TEEC_FinalizeContext(context: *mut TEEC_Context)158 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_Result159 pub fn TEEC_OpenSession(context: *mut TEEC_Context,
160 session: *mut TEEC_Session,
161 destination: *const TEEC_UUID,
162 connectionMethod: u32,
163 connectionData: *const c_void,
164 operation: *mut TEEC_Operation,
165 returnOrigin: *mut u32) -> TEEC_Result;
TEEC_CloseSession(session: *mut TEEC_Session)166 pub fn TEEC_CloseSession(session: *mut TEEC_Session);
TEEC_InvokeCommand(session: *mut TEEC_Session, commandID: u32, operation: *mut TEEC_Operation, returnOrigin: *mut u32) -> TEEC_Result167 pub fn TEEC_InvokeCommand(session: *mut TEEC_Session,
168 commandID: u32,
169 operation: *mut TEEC_Operation,
170 returnOrigin: *mut u32) -> TEEC_Result;
TEEC_RegisterSharedMemory(context: *mut TEEC_Context, sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result171 pub fn TEEC_RegisterSharedMemory(context: *mut TEEC_Context,
172 sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result;
TEEC_AllocateSharedMemory(context: *mut TEEC_Context, sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result173 pub fn TEEC_AllocateSharedMemory(context: *mut TEEC_Context,
174 sharedMem: *mut TEEC_SharedMemory) -> TEEC_Result;
TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory)175 pub fn TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory);
TEEC_RequestCancellation(operation: *mut TEEC_Operation)176 pub fn TEEC_RequestCancellation(operation: *mut TEEC_Operation);
177 }
178