Skip to main content

optee_teec_sys/
tee_client_api.rs

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
18use crate::size_t;
19use core::ffi::*;
20
21pub fn TEEC_PARAM_TYPES(p0: u32, p1: u32, p2: u32, p3: u32) -> u32 {
22    let tmp = p1 << 4 | p2 << 8 | p3 << 12;
23    p0 | tmp
24}
25
26pub const TEEC_CONFIG_PAYLOAD_REF_COUNT: u32 = 4;
27
28pub const TEEC_CONFIG_SHAREDMEM_MAX_SIZE: c_ulong = -1 as c_long as c_ulong;
29
30pub const TEEC_NONE: u32 = 0x00000000;
31pub const TEEC_VALUE_INPUT: u32 = 0x00000001;
32pub const TEEC_VALUE_OUTPUT: u32 = 0x00000002;
33pub const TEEC_VALUE_INOUT: u32 = 0x00000003;
34pub const TEEC_MEMREF_TEMP_INPUT: u32 = 0x00000005;
35pub const TEEC_MEMREF_TEMP_OUTPUT: u32 = 0x00000006;
36pub const TEEC_MEMREF_TEMP_INOUT: u32 = 0x00000007;
37pub const TEEC_MEMREF_WHOLE: u32 = 0x0000000C;
38pub const TEEC_MEMREF_PARTIAL_INPUT: u32 = 0x0000000D;
39pub const TEEC_MEMREF_PARTIAL_OUTPUT: u32 = 0x0000000E;
40pub const TEEC_MEMREF_PARTIAL_INOUT: u32 = 0x0000000F;
41
42pub const TEEC_MEM_INPUT: u32 = 0x00000001;
43pub const TEEC_MEM_OUTPUT: u32 = 0x00000002;
44
45pub const TEEC_SUCCESS: u32 = 0x00000000;
46pub const TEEC_ERROR_GENERIC: u32 = 0xFFFF0000;
47pub const TEEC_ERROR_ACCESS_DENIED: u32 = 0xFFFF0001;
48pub const TEEC_ERROR_CANCEL: u32 = 0xFFFF0002;
49pub const TEEC_ERROR_ACCESS_CONFLICT: u32 = 0xFFFF0003;
50pub const TEEC_ERROR_EXCESS_DATA: u32 = 0xFFFF0004;
51pub const TEEC_ERROR_BAD_FORMAT: u32 = 0xFFFF0005;
52pub const TEEC_ERROR_BAD_PARAMETERS: u32 = 0xFFFF0006;
53pub const TEEC_ERROR_BAD_STATE: u32 = 0xFFFF0007;
54pub const TEEC_ERROR_ITEM_NOT_FOUND: u32 = 0xFFFF0008;
55pub const TEEC_ERROR_NOT_IMPLEMENTED: u32 = 0xFFFF0009;
56pub const TEEC_ERROR_NOT_SUPPORTED: u32 = 0xFFFF000A;
57pub const TEEC_ERROR_NO_DATA: u32 = 0xFFFF000B;
58pub const TEEC_ERROR_OUT_OF_MEMORY: u32 = 0xFFFF000C;
59pub const TEEC_ERROR_BUSY: u32 = 0xFFFF000D;
60pub const TEEC_ERROR_COMMUNICATION: u32 = 0xFFFF000E;
61pub const TEEC_ERROR_SECURITY: u32 = 0xFFFF000F;
62pub const TEEC_ERROR_SHORT_BUFFER: u32 = 0xFFFF0010;
63pub const TEEC_ERROR_EXTERNAL_CANCEL: u32 = 0xFFFF0011;
64pub const TEEC_ERROR_TARGET_DEAD: u32 = 0xFFFF3024;
65
66pub const TEEC_ORIGIN_API: u32 = 0x00000001;
67pub const TEEC_ORIGIN_COMMS: u32 = 0x00000002;
68pub const TEEC_ORIGIN_TEE: u32 = 0x00000003;
69pub const TEEC_ORIGIN_TRUSTED_APP: u32 = 0x00000004;
70
71pub const TEEC_LOGIN_PUBLIC: u32 = 0x00000000;
72pub const TEEC_LOGIN_USER: u32 = 0x00000001;
73pub const TEEC_LOGIN_GROUP: u32 = 0x00000002;
74pub const TEEC_LOGIN_APPLICATION: u32 = 0x00000004;
75pub const TEEC_LOGIN_USER_APPLICATION: u32 = 0x00000005;
76pub const TEEC_LOGIN_GROUP_APPLICATION: u32 = 0x00000006;
77
78#[allow(non_camel_case_types)]
79pub type TEEC_Result = u32;
80
81#[repr(C)]
82pub struct TEEC_Context__Imp {
83    pub fd: c_int,
84    pub reg_mem: bool,
85    pub memref_null: bool,
86}
87
88#[repr(C)]
89pub struct TEEC_Context {
90    pub imp: TEEC_Context__Imp,
91}
92
93#[repr(C)]
94pub struct TEEC_UUID {
95    pub timeLow: u32,
96    pub timeMid: u16,
97    pub timeHiAndVersion: u16,
98    pub clockSeqAndNode: [u8; 8],
99}
100
101#[repr(C)]
102pub struct TEEC_Session__Imp {
103    pub ctx: *mut TEEC_Context,
104    pub session_id: u32,
105}
106
107#[repr(C)]
108pub struct TEEC_Session {
109    pub imp: TEEC_Session__Imp,
110}
111
112#[repr(C)]
113pub struct TEEC_SharedMemory__Imp {
114    pub id: c_int,
115    pub alloced_size: size_t,
116    pub shadow_buffer: *mut c_void,
117    pub registered_fd: c_int,
118    pub flags: u32,
119}
120
121#[repr(C)]
122pub struct TEEC_SharedMemory {
123    pub buffer: *mut c_void,
124    pub size: size_t,
125    pub flags: u32,
126    pub imp: TEEC_SharedMemory__Imp,
127}
128
129#[derive(Copy, Clone)]
130#[repr(C)]
131pub struct TEEC_TempMemoryReference {
132    pub buffer: *mut c_void,
133    pub size: size_t,
134}
135
136#[derive(Copy, Clone)]
137#[repr(C)]
138pub struct TEEC_RegisteredMemoryReference {
139    pub parent: *mut TEEC_SharedMemory,
140    pub size: size_t,
141    pub offset: size_t,
142}
143
144#[derive(Copy, Clone)]
145#[repr(C)]
146pub struct TEEC_Value {
147    pub a: u32,
148    pub b: u32,
149}
150
151#[repr(C)]
152#[derive(Copy, Clone)]
153pub union TEEC_Parameter {
154    pub tmpref: TEEC_TempMemoryReference,
155    pub memref: TEEC_RegisteredMemoryReference,
156    pub value: TEEC_Value,
157}
158
159#[repr(C)]
160pub struct TEEC_Operation__Imp {
161    pub session: *mut TEEC_Session,
162}
163
164#[repr(C)]
165pub struct TEEC_Operation {
166    pub started: u32,
167    pub paramTypes: u32,
168    pub params: [TEEC_Parameter; TEEC_CONFIG_PAYLOAD_REF_COUNT as usize],
169    pub imp: TEEC_Operation__Imp,
170}
171
172unsafe extern "C" {
173    pub fn TEEC_InitializeContext(name: *const c_char, context: *mut TEEC_Context) -> TEEC_Result;
174    pub fn TEEC_FinalizeContext(context: *mut TEEC_Context);
175    pub fn TEEC_OpenSession(
176        context: *mut TEEC_Context,
177        session: *mut TEEC_Session,
178        destination: *const TEEC_UUID,
179        connectionMethod: u32,
180        connectionData: *const c_void,
181        operation: *mut TEEC_Operation,
182        returnOrigin: *mut u32,
183    ) -> TEEC_Result;
184    pub fn TEEC_CloseSession(session: *mut TEEC_Session);
185    pub fn TEEC_InvokeCommand(
186        session: *mut TEEC_Session,
187        commandID: u32,
188        operation: *mut TEEC_Operation,
189        returnOrigin: *mut u32,
190    ) -> TEEC_Result;
191    pub fn TEEC_RegisterSharedMemory(
192        context: *mut TEEC_Context,
193        sharedMem: *mut TEEC_SharedMemory,
194    ) -> TEEC_Result;
195    pub fn TEEC_AllocateSharedMemory(
196        context: *mut TEEC_Context,
197        sharedMem: *mut TEEC_SharedMemory,
198    ) -> TEEC_Result;
199    pub fn TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory);
200    pub fn TEEC_RequestCancellation(operation: *mut TEEC_Operation);
201}