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