mTower
tee_client_api.h
1 /*
2  * Copyright (c) 2014, STMicroelectronics International N.V.
3  * All rights reserved.
4  * Copyright (c) 2015, Linaro Limited
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 #ifndef TEE_CLIENT_API_H
30 #define TEE_CLIENT_API_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 #include <stdbool.h>
39 #include <limits.h>
40 
41 /*
42  * Defines the number of available memory references in an open session or
43  * invoke command operation payload.
44  */
45 #define TEEC_CONFIG_PAYLOAD_REF_COUNT 4
46 
53 #define TEEC_CONFIG_SHAREDMEM_MAX_SIZE ULONG_MAX
54 
109 #define TEEC_NONE 0x00000000
110 #define TEEC_VALUE_INPUT 0x00000001
111 #define TEEC_VALUE_OUTPUT 0x00000002
112 #define TEEC_VALUE_INOUT 0x00000003
113 #define TEEC_MEMREF_TEMP_INPUT 0x00000005
114 #define TEEC_MEMREF_TEMP_OUTPUT 0x00000006
115 #define TEEC_MEMREF_TEMP_INOUT 0x00000007
116 #define TEEC_MEMREF_WHOLE 0x0000000C
117 #define TEEC_MEMREF_PARTIAL_INPUT 0x0000000D
118 #define TEEC_MEMREF_PARTIAL_OUTPUT 0x0000000E
119 #define TEEC_MEMREF_PARTIAL_INOUT 0x0000000F
120 
132 #define TEEC_MEM_INPUT 0x00000001
133 #define TEEC_MEM_OUTPUT 0x00000002
134 
167 #define TEEC_SUCCESS 0x00000000
168 #define TEEC_ERROR_GENERIC 0xFFFF0000
169 #define TEEC_ERROR_ACCESS_DENIED 0xFFFF0001
170 #define TEEC_ERROR_CANCEL 0xFFFF0002
171 #define TEEC_ERROR_ACCESS_CONFLICT 0xFFFF0003
172 #define TEEC_ERROR_EXCESS_DATA 0xFFFF0004
173 #define TEEC_ERROR_BAD_FORMAT 0xFFFF0005
174 #define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
175 #define TEEC_ERROR_BAD_STATE 0xFFFF0007
176 #define TEEC_ERROR_ITEM_NOT_FOUND 0xFFFF0008
177 #define TEEC_ERROR_NOT_IMPLEMENTED 0xFFFF0009
178 #define TEEC_ERROR_NOT_SUPPORTED 0xFFFF000A
179 #define TEEC_ERROR_NO_DATA 0xFFFF000B
180 #define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
181 #define TEEC_ERROR_BUSY 0xFFFF000D
182 #define TEEC_ERROR_COMMUNICATION 0xFFFF000E
183 #define TEEC_ERROR_SECURITY 0xFFFF000F
184 #define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
185 #define TEEC_ERROR_EXTERNAL_CANCEL 0xFFFF0011
186 #define TEEC_ERROR_TARGET_DEAD 0xFFFF3024
187 
201 #define TEEC_ORIGIN_API 0x00000001
202 #define TEEC_ORIGIN_COMMS 0x00000002
203 #define TEEC_ORIGIN_TEE 0x00000003
204 #define TEEC_ORIGIN_TRUSTED_APP 0x00000004
205 
222 #define TEEC_LOGIN_PUBLIC 0x00000000
223 #define TEEC_LOGIN_USER 0x00000001
224 #define TEEC_LOGIN_GROUP 0x00000002
225 #define TEEC_LOGIN_APPLICATION 0x00000004
226 #define TEEC_LOGIN_USER_APPLICATION 0x00000005
227 #define TEEC_LOGIN_GROUP_APPLICATION 0x00000006
228 
237 #define TEEC_PARAM_TYPES(p0, p1, p2, p3) \
238  ((p0) | ((p1) << 4) | ((p2) << 8) | ((p3) << 12))
239 
246 #define TEEC_PARAM_TYPE_GET(p, i) (((p) >> (i * 4)) & 0xF)
247 
248 typedef uint32_t TEEC_Result;
249 
254 typedef struct {
255  /* Implementation defined */
256  int fd;
257  bool reg_mem;
258 } TEEC_Context;
259 
265 typedef struct {
266  uint32_t timeLow;
267  uint16_t timeMid;
268  uint16_t timeHiAndVersion;
269  uint8_t clockSeqAndNode[8];
270 } TEEC_UUID;
271 
288 typedef struct {
289  void *buffer;
290  size_t size;
291  uint32_t flags;
292  /*
293  * Implementation-Defined
294  */
295  int id;
296  size_t alloced_size;
297  void *shadow_buffer;
298  int registered_fd;
299  bool buffer_allocated;
301 
314 typedef struct {
315  void *buffer;
316  size_t size;
318 
334 typedef struct {
335  TEEC_SharedMemory *parent;
336  size_t size;
337  size_t offset;
339 
350 typedef struct {
351  uint32_t a;
352  uint32_t b;
353 } TEEC_Value;
354 
369 typedef union {
372  TEEC_Value value;
374 
379 typedef struct {
380  /* Implementation defined */
381  TEEC_Context *ctx;
382  uint32_t session_id;
383 } TEEC_Session;
384 
399 typedef struct {
400  uint32_t started;
401  uint32_t paramTypes;
402  TEEC_Parameter params[TEEC_CONFIG_PAYLOAD_REF_COUNT];
403  /* Implementation-Defined */
404  TEEC_Session *session;
406 
421 TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
422 
434 void TEEC_FinalizeContext(TEEC_Context *context);
435 
462 TEEC_Result TEEC_OpenSession(TEEC_Context *context,
463  TEEC_Session *session,
464  const TEEC_UUID *destination,
465  uint32_t connectionMethod,
466  const void *connectionData,
467  TEEC_Operation *operation,
468  uint32_t *returnOrigin);
469 
476 void TEEC_CloseSession(TEEC_Session *session);
477 
495 TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
496  uint32_t commandID,
497  TEEC_Operation *operation,
498  uint32_t *returnOrigin);
499 
512 TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
513  TEEC_SharedMemory *sharedMem);
514 
526 TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
527  TEEC_SharedMemory *sharedMem);
528 
534 void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMemory);
535 
543 void TEEC_RequestCancellation(TEEC_Operation *operation);
544 
545 #ifdef __cplusplus
546 }
547 #endif
548 
549 #endif
Definition: tee_client_api.h:334
Definition: tee_client_api.h:254
Definition: tee_client_api.h:379
Definition: tee_client_api.h:265
Definition: tee_client_api.h:288
Definition: tee_client_api.h:399
Definition: tee_client_api.h:314
Definition: tee_client_api.h:369
Definition: tee_client_api.h:350