• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TEE_CLIENT_CONSTANTS_H
17 #define TEE_CLIENT_CONSTANTS_H
18 /**
19  * @addtogroup TeeClient
20  * @{
21  *
22  * @brief Provides APIs for the client applications (CAs) in the Rich Execution Environment (normal mode) to
23  * access the trusted applications (TAs) in a Trusted Execution Environment (TEE).
24  *
25  * @since 12
26  * @version 1.0
27  */
28 
29 /**
30  * @file tee_client_constants.h
31  *
32  * @brief Defines public data and constants.
33  *
34  * @library libteec.so
35  * @kit TEEKit
36  * @syscap SystemCapability.Tee.TeeClient
37  * @since 12
38  * @version 1.0
39  */
40 
41 /**
42  * @brief Defines the number of <b>TEEC_Parameter</b>s in <b>TEEC_Operation</b>.
43  *
44  * @since 12
45  * @version 1.0
46  */
47 #define TEEC_PARAM_NUM 4
48 
49 /**
50  * @brief Defines the error codes returned.
51  *
52  * @since 12
53  * @version 1.0
54  */
55 enum TEEC_ReturnCode {
56     /** The operation is successful. */
57     TEEC_SUCCESS = 0x0,
58     /** Invalid command. The command is not supported by the TA. */
59     TEEC_ERROR_INVALID_CMD,
60     /** The TA does not exist. */
61     TEEC_ERROR_SERVICE_NOT_EXIST,
62     /** The session between the CA and TA does not exist. */
63     TEEC_ERROR_SESSION_NOT_EXIST,
64     /** The number of connections to the TA has reached the limit. */
65     TEEC_ERROR_SESSION_MAXIMUM,
66     /** The TA to be registered already exists. */
67     TEEC_ERROR_REGISTER_EXIST_SERVICE,
68     /** Secure OS framework error. */
69     TEEC_ERROR_TAGET_DEAD_FATAL,
70     /** Failed to read the file. */
71     TEEC_ERROR_READ_DATA,
72     /** Failed to write the file. */
73     TEEC_ERROR_WRITE_DATA,
74     /** Failed to truncate the file. */
75     TEEC_ERROR_TRUNCATE_OBJECT,
76     /** Failed to seek data. */
77     TEEC_ERROR_SEEK_DATA,
78     /** File synchronization error. */
79     TEEC_ERROR_FSYNC_DATA,
80     /** Failed to rename the file. */
81     TEEC_ERROR_RENAME_OBJECT,
82     /** Failed to load the TA when opening a session. */
83     TEEC_ERROR_TRUSTED_APP_LOAD_ERROR,
84     /** Failed to initialize the TA. */
85     TEEC_ERROR_GENERIC = 0xFFFF0000,
86     /** Permission verification failed. Permission verification is performed before a TEE or session is opened or
87      a command is sent. */
88     TEEC_ERROR_ACCESS_DENIED = 0xFFFF0001,
89     /** The operation is canceled. This error code is returned when you operate the parameter with
90      the cancallation flag. */
91     TEEC_ERROR_CANCEL = 0xFFFF0002,
92     /** Concurrent access causes permission conflict. Concurrent access to files in the trusted storage
93      service may cause this error. */
94     TEEC_ERROR_ACCESS_CONFLICT = 0xFFFF0003,
95     /** Too much data is passed in the requested operation for the TA to parse. */
96     TEEC_ERROR_EXCESS_DATA = 0xFFFF0004,
97     /** Incorrect data format. The TA failed to parse the parameters sent from the CA. */
98     TEEC_ERROR_BAD_FORMAT = 0xFFFF0005,
99     /** Invalid parameter. The input parameter is null or invalid. */
100     TEEC_ERROR_BAD_PARAMETERS = 0xFFFF0006,
101     /** The operation in the current state is invalid. This error code is returned if the trusted storage service is not
102      initialized when a trusted storage service operation is requested. */
103     TEEC_ERROR_BAD_STATE = 0xFFFF0007,
104     /** The requested data is not found. */
105     TEEC_ERROR_ITEM_NOT_FOUND = 0xFFFF0008,
106     /** The requested operation has not been implemented yet. This error code is returned when
107      <b>TEEC_RequestCancellation</b> is called. */
108     TEEC_ERROR_NOT_IMPLEMENTED = 0xFFFF0009,
109     /** The requested operation is valid but is not supported in this implementation. This error code is returned
110      when certain algorithms of the secure encryption and decryption service, such as DSA, are requested. */
111     TEEC_ERROR_NOT_SUPPORTED = 0xFFFF000A,
112     /** Expected data for the requested operation is not found. */
113     TEEC_ERROR_NO_DATA = 0xFFFF000B,
114     /** The available system resources are insufficient. */
115     TEEC_ERROR_OUT_OF_MEMORY = 0xFFFF000C,
116     /** The system is busy. Some resources are exclusively used by the system. */
117     TEEC_ERROR_BUSY = 0xFFFF000D,
118     /** Communication between an application in the REE and a TA failed. */
119     TEEC_ERROR_COMMUNICATION = 0xFFFF000E,
120     /** A security fault is detected in the TEE. */
121     TEEC_ERROR_SECURITY = 0xFFFF000F,
122     /** The supplied buffer is too short for the output generated.
123      This error may occur when {@code TEEC_MEMREF_TEMP_OUTPUT} is used. */
124     TEEC_ERROR_SHORT_BUFFER = 0xFFFF0010,
125     /** MAC value check error. */
126     TEEC_ERROR_MAC_INVALID = 0xFFFF3071,
127     /** The TA crashed. */
128     TEEC_ERROR_TARGET_DEAD = 0xFFFF3024,
129     /** Common error. */
130     TEEC_FAIL = 0xFFFF5002
131 };
132 
133 /**
134  * @brief Defines the sources of the error codes returned.
135  *
136  * @since 12
137  * @version 1.0
138  */
139 enum TEEC_ReturnCodeOrigin {
140     /** The error code indicates an error originated from the client API. */
141     TEEC_ORIGIN_API = 0x1,
142     /** The error code indicates an error originated from the communication between the REE and TEE. */
143     TEEC_ORIGIN_COMMS = 0x2,
144     /** The error code indicates an error originated within the TEE code. */
145     TEEC_ORIGIN_TEE = 0x3,
146     /** The error code indicates an error originated within the TA code. */
147     TEEC_ORIGIN_TRUSTED_APP = 0x4,
148 };
149 
150 /**
151  * @brief Defines the identifiers of the shared memory.
152  *
153  * @since 12
154  * @version 1.0
155  */
156 enum TEEC_SharedMemCtl {
157     /** The shared memory can carry data from CAs to TAs. */
158     TEEC_MEM_INPUT = 0x1,
159     /** The shared memory can carry data from TAs to CAs. */
160     TEEC_MEM_OUTPUT = 0x2,
161     /** The shared memory can carry data transmitted between CAs and TAs. */
162     TEEC_MEM_INOUT = 0x3,
163 };
164 
165 /**
166  * @brief Defines the parameter types.
167  *
168  * @since 12
169  * @version 1.0
170  */
171 enum TEEC_ParamType {
172     /** The parameter is not used. */
173     TEEC_NONE = 0x0,
174     /** The parameter is a {@code TEEC_Value} tagged as input. Data flows from a CA to a TA. */
175     TEEC_VALUE_INPUT = 0x01,
176     /** The parameter is a {@code TEEC_Value} tagged as output. Data flows from a TA to a CA. */
177     TEEC_VALUE_OUTPUT = 0x02,
178     /** The parameter is a {@code TEEC_Value} tagged as both input and output. */
179     TEEC_VALUE_INOUT = 0x03,
180     /** The parameter is a {@code TEEC_TempMemoryReference} tagged as input. Data flows from a CA to a TA. */
181     TEEC_MEMREF_TEMP_INPUT = 0x05,
182     /** The parameter is a {@code TEEC_TempMemoryReference} tagged as output. Data flows from a TA to a CA. */
183     TEEC_MEMREF_TEMP_OUTPUT = 0x06,
184     /** The parameter is a {@code TEEC_TempMemoryReference} tagged as both input and output.
185      Data is transmitted between a TA and a CA. */
186     TEEC_MEMREF_TEMP_INOUT = 0x07,
187     /** The parameter is a {@code TEEC_IonReference} tagged as input. Data flows from a CA to a TA**/
188     TEEC_ION_INPUT = 0x08,
189     /** The parameter is a {@code TEEC_IonSglistReference} tagged as input. Data flows from a CA to a TA**/
190     TEEC_ION_SGLIST_INPUT = 0x09,
191     /** The parameter is a {@code TEEC_RegisteredMemoryReference} that refers to the entire memory block.
192      The data flow is the same as that of {@code TEEC_SharedMemCtl}. */
193     TEEC_MEMREF_WHOLE = 0xc,
194     /** The parameter is a {@code TEEC_RegisteredMemoryReference} tagged as input. Data flows from a CA to a TA. */
195     TEEC_MEMREF_PARTIAL_INPUT = 0xd,
196     /** The parameter is a {@code TEEC_RegisteredMemoryReference} tagged as output. Data flows from a TA to a CA. */
197     TEEC_MEMREF_PARTIAL_OUTPUT = 0xe,
198     /** The parameter is a {@code TEEC_RegisteredMemoryReference} tagged as both input and output.
199      Data is transmitted between a TA and a CA. */
200     TEEC_MEMREF_PARTIAL_INOUT = 0xf
201 };
202 
203 /**
204  * @brief Defines the login methods.
205  *
206  * @since 12
207  * @version 1.0
208 */
209 enum TEEC_LoginMethod {
210     /** No login data is provided. */
211     TEEC_LOGIN_PUBLIC = 0x0,
212     /** The login data about the user running the CA process is provided. */
213     TEEC_LOGIN_USER,
214     /** The login data about the group running the CA process is provided. */
215     TEEC_LOGIN_GROUP,
216     /** The login data about the running CA is provided. */
217     TEEC_LOGIN_APPLICATION = 0x4,
218     /** The login data about the user running the CA process and about the CA are provided. */
219     TEEC_LOGIN_USER_APPLICATION = 0x5,
220     /** The login data about the group running the CA process and about the CA are provided. */
221     TEEC_LOGIN_GROUP_APPLICATION = 0x6,
222     /** Login method reserved for TEEOS. */
223     TEEC_LOGIN_IDENTIFY = 0x7,
224 };
225 
226 /** @} */
227 #endif
228