Fix source file permissions in the project
[platform/core/security/tef-simulator.git] / include / include / tee_client_api.h
1 /*
2  * =====================================================================================
3  *
4  *       Filename:  tee_client_api.h
5  *
6  *    Description:  TEEC API Header file
7  *
8  *        Version:  1.0
9  *        Created:  Thursday 26 March 2015 12:42:45  IST
10  *       Revision:  Original
11  *       Compiler:  gcc
12  *
13  *         Author:  CHERYL (cb), cheryl.b@samsung.com
14  *   Organization:  Samsung Electronics
15  *
16  * =====================================================================================
17  */
18
19 #ifndef __TEE_CLIENT_API_H__
20 #define __TEE_CLIENT_API_H__
21
22 /*-----------------------------------------------------------------------------
23  *  Include files
24  *-----------------------------------------------------------------------------*/
25 #include <stdint.h>
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35
36 /*-----------------------------------------------------------------------------
37  * TEE Client API types and constants definitions
38  *-----------------------------------------------------------------------------*/
39 #define TEEC_SUCCESS                    0x00000000 // The operation was successful
40 #define TEEC_ERROR_GENERIC              0xFFFF0000 // Non-specific cause
41 #define TEEC_ERROR_ACCESS_DENIED        0xFFFF0001 // Access privileges are not sufficient
42 #define TEEC_ERROR_CANCEL               0xFFFF0002 // The operation was cancelled
43 #define TEEC_ERROR_ACCESS_CONFLICT      0xFFFF0003 // Concurrent accesses caused conflict
44 #define TEEC_ERROR_EXCESS_DATA          0xFFFF0004 // Too much data for the requested operation was passed
45 #define TEEC_ERROR_BAD_FORMAT           0xFFFF0005 // Input data was of invalid format
46 #define TEEC_ERROR_BAD_PARAMETERS       0xFFFF0006 // Input parameters were invalid
47 #define TEEC_ERROR_BAD_STATE            0xFFFF0007 // Operation is not valid in the current state
48 #define TEEC_ERROR_ITEM_NOT_FOUND       0xFFFF0008 // The requested data item is not found
49 #define TEEC_ERROR_NOT_IMPLEMENTED      0xFFFF0009 // The requested operation should exist but is not yet implemented
50 #define TEEC_ERROR_NOT_SUPPORTED        0xFFFF000A // The requested operation is valid but is not supported in this Implementation
51 #define TEEC_ERROR_NO_DATA              0xFFFF000B // Expected data was missing
52 #define TEEC_ERROR_OUT_OF_MEMORY        0xFFFF000C // System ran out of resources
53 #define TEEC_ERROR_BUSY                 0xFFFF000D // The system is busy working on something else.
54 #define TEEC_ERROR_COMMUNICATION        0xFFFF000E // Communication with a remote party failed.
55 #define TEEC_ERROR_SECURITY             0xFFFF000F // A security fault was detected.
56 #define TEEC_ERROR_SHORT_BUFFER         0xFFFF0010 // The supplied buffer is too short for the generated output.
57 #define TEEC_ERROR_TARGET_DEAD          0xFFFF3024 // Targed TA panic'ed
58 #define TEEC_IMP_MIN                    0x00000001
59 #define TEEC_IMP_MAX                    0xFFFEFFFF
60 #define TEEC_RFU_MIN                    0xFFFF0011
61 #define TEEC_RFU_MAX                    0xFFFFFFFF
62
63 #define TEEC_ORIGIN_API                 0x1
64 #define TEEC_ORIGIN_COMMS               0x2
65 #define TEEC_ORIGIN_TEE                 0x3
66 #define TEEC_ORIGIN_TRUSTED_APP         0x4
67
68 #define TEEC_CONFIG_SHAREDMEM_MAX_SIZE  0x800000
69
70 #define TEEC_MEM_INPUT                  (1 << 0)
71 #define TEEC_MEM_OUTPUT                 (1 << 1)
72
73 #define TEEC_NONE                       0x00000000
74 #define TEEC_VALUE_INPUT                0x00000001
75 #define TEEC_VALUE_OUTPUT               0x00000002
76 #define TEEC_VALUE_INOUT                0x00000003
77 #define TEEC_MEMREF_TEMP_INPUT          0x00000005
78 #define TEEC_MEMREF_TEMP_OUTPUT         0x00000006
79 #define TEEC_MEMREF_TEMP_INOUT          0x00000007
80 #define TEEC_MEMREF_WHOLE               0x0000000C
81 #define TEEC_MEMREF_PARTIAL_INPUT       0x0000000D
82 #define TEEC_MEMREF_PARTIAL_OUTPUT      0x0000000E
83 #define TEEC_MEMREF_PARTIAL_INOUT       0x0000000F
84
85 #define TEE_PARAM_TYPE_NONE             0x00000000
86 #define TEE_PARAM_TYPE_VALUE_INPUT      0x00000001
87 #define TEE_PARAM_TYPE_VALUE_OUTPUT     0x00000002
88 #define TEE_PARAM_TYPE_VALUE_INOUT      0x00000003
89 #define TEE_PARAM_TYPE_MEMREF_INPUT     0x00000005
90 #define TEE_PARAM_TYPE_MEMREF_OUTPUT    0x00000006
91 #define TEE_PARAM_TYPE_MEMREF_INOUT     0x00000007
92
93 #define TEEC_LOGIN_PUBLIC               0x00000000
94 #define TEEC_LOGIN_USER                 0x00000001
95 #define TEEC_LOGIN_GROUP                0x00000002
96 #define TEEC_LOGIN_APPLICATION          0x00000004 
97 #define TEEC_LOGIN_USER_APPLICATION     0x00000005
98 #define TEEC_LOGIN_GROUP_APPLICATION    0x00000006
99
100 #define MAX_CONTEXT_NAME_LEN 128
101
102 typedef uint32_t TEEC_Result;
103
104 typedef struct {
105         uint32_t timeLow;
106         uint16_t timeMid;
107         uint16_t timeHiAndVersion;
108         uint8_t clockSeqAndNode[8];
109 } TEEC_UUID;
110
111 typedef struct {
112         void* imp;
113 } TEEC_Context;
114
115 typedef struct {
116         void *imp;
117 } TEEC_Session;
118
119 typedef struct {
120         void *buffer;
121         size_t size;
122         uint32_t flags;
123         void *imp;
124 } TEEC_SharedMemory;
125
126 typedef struct {
127         void *buffer;
128         size_t size;
129 } TEEC_TempMemoryReference;
130
131 typedef struct {
132         TEEC_SharedMemory* parent;
133         size_t size;
134         size_t offset;
135 } TEEC_RegisteredMemoryReference;
136
137 typedef struct {
138         uint32_t a;
139         uint32_t b;
140 } TEEC_Value;
141
142 typedef union {
143         TEEC_TempMemoryReference tmpref;
144         TEEC_RegisteredMemoryReference memref;
145         TEEC_Value value;
146 } TEEC_Parameter;
147
148 typedef struct {
149         uint32_t started;
150         uint32_t paramTypes;
151         TEEC_Parameter params[4];
152         void *imp;
153 } TEEC_Operation;
154
155 /*-----------------------------------------------------------------------------
156  * TEE Client API functions and macros definitions
157  *-----------------------------------------------------------------------------*/
158 TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
159
160 void TEEC_FinalizeContext(TEEC_Context *context);
161
162 TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
163     TEEC_SharedMemory *sharedMem);
164
165 TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
166     TEEC_SharedMemory *sharedMem);
167
168 void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMem);
169
170 TEEC_Result TEEC_OpenSession(TEEC_Context *context,
171     TEEC_Session *session,
172     const TEEC_UUID *destination,
173     uint32_t connectionMethod,
174     const void *connectionData,
175     TEEC_Operation *operation,
176     uint32_t *returnOrigin);
177
178 void TEEC_CloseSession(TEEC_Session *session);
179
180 TEEC_Result TEEC_InvokeCommand(TEEC_Session *session,
181     uint32_t commandID,
182     TEEC_Operation *operation,
183     uint32_t *returnOrigin);
184
185 void TEEC_RequestCancellation(TEEC_Operation *operation);
186
187 #define TEEC_PARAM_TYPES(param0Type, param1Type, param2Type, param3Type) \
188                 (uint32_t)(((param0Type) & 0x7f) | \
189                                 (((param1Type) & 0x7f) << 8) | \
190                                 (((param2Type) & 0x7f) << 16) | \
191                                 (((param3Type) & 0x7f) << 24))
192
193 #ifdef  __cplusplus
194 }
195 #endif
196
197 #endif /* __TEE_CLIENT_API_H__ */