• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TeeTrusted
18  * @{
19  *
20  * @brief TEE(Trusted Excution Environment) API.
21  * Provides security capability APIs such as trusted storage, encryption and decryption,
22  * and trusted time for trusted application development.
23  *
24  * @since 20
25  */
26 
27 /**
28  * @file tee_defines.h
29  *
30  * @brief Defines basic data types and data structures of TEE.
31  *
32  * @library NA
33  * @kit TEEKit
34  * @syscap SystemCapability.Tee.TeeClient
35  * @since 20
36  * @version 1.0
37  */
38 
39 #ifndef __TEE_DEFINES_H
40 #define __TEE_DEFINES_H
41 
42 #include <stdint.h>
43 #include <stdbool.h>
44 #include <stddef.h>
45 #include <tee_uuid.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #ifndef TA_EXPORT
52 
53 /**
54  * @brief Represents the export attribute for Trusted Applications.
55  *
56  * @since 20
57  */
58 #define TA_EXPORT
59 #endif
60 
61 #define API_LEVEL1_0   1
62 #define API_LEVEL1_1_1 2
63 
64 /**
65  * @brief Represents API level 1.2.
66  *
67  * @since 20
68  */
69 #define API_LEVEL1_2   3
70 
71 /**
72  * @brief Represents the number of TEE parameters.
73  *
74  * @since 20
75  */
76 #define TEE_PARAMS_NUM 4
77 
78 #ifndef NULL
79 /**
80  * @brief Represents a null pointer constant.
81  *
82  * @since 20
83  */
84 #define NULL ((void*)0)
85 #endif
86 
87 /**
88  * @brief Marks a parameter as unused.
89  *
90  * @since 20
91  */
92 #define PARAM_NOT_USED(val) ((void)(val))
93 
94 /**
95  * @brief Enumerates the TEE parameter.
96  *
97  * @since 20
98  */
99 typedef union {
100     /**
101      * @brief Describes a memory reference.
102      *
103      * @since 20
104      */
105     struct {
106         /** Pointer to the memory buffer. */
107         void *buffer;
108         /** Size of the memory buffer. */
109         size_t size;
110     } memref;
111     /**
112      * @brief Describes value parameters.
113      *
114      * @since 20
115      */
116     struct {
117         /** First value. */
118         unsigned int a;
119         /** Second value. */
120         unsigned int b;
121     } value;
122     /**
123      * @brief Describes shared memory reference.
124      *
125      * @since 20
126      */
127     struct {
128         /** Pointer to the shared memory buffer. */
129         void *buffer;
130         /** Size of the shared memory buffer. */
131         size_t size;
132     } sharedmem;
133 } TEE_Param;
134 
135 /**
136  * @brief Constructs the TEE parameter types from the provided types.
137  *
138  * @since 20
139  */
140 #define TEE_PARAM_TYPES(param0Type, param1Type, param2Type, param3Type) \
141     (((param3Type) << 12) | ((param2Type) << 8) | ((param1Type) << 4) | (param0Type))
142 
143 /**
144  * @brief Extracts the parameter type at the specified index from the TEE parameter types.
145  *
146  * @since 20
147  */
148 #define TEE_PARAM_TYPE_GET(paramTypes, index) (((paramTypes) >> (4U * (index))) & 0x0F)
149 
150 /**
151  * @brief Checks parameter types.
152  *
153  * @param param_to_check Indicates the expected parameter values.
154  * @param valid0 Indicates the first parameter type to check.
155  * @param valid1 Indicates the second parameter type to check.
156  * @param valid2 Indicates the third parameter type to check.
157  * @param valid3 Indicates the fourth parameter type to check.
158  *
159  * @return Returns <b>true</b> if the parameter types are correct.
160  *         Returns <b>false</b> otherwise.
161  * @since 20
162  */
check_param_type(uint32_t param_to_check,uint32_t valid0,uint32_t valid1,uint32_t valid2,uint32_t valid3)163 static inline bool check_param_type(uint32_t param_to_check, uint32_t valid0, uint32_t valid1, uint32_t valid2,
164                                     uint32_t valid3)
165 {
166     return (TEE_PARAM_TYPES(valid0, valid1, valid2, valid3) == param_to_check);
167 }
168 
169 /**
170  * @brief Enumerates the types of the TEE parameter.
171  *
172  * @since 20
173  */
174 enum TEE_ParamType {
175     /** Represents no parameter type. */
176     TEE_PARAM_TYPE_NONE             = 0x0,
177     /** Represents a value input type. */
178     TEE_PARAM_TYPE_VALUE_INPUT      = 0x1,
179     /** Represents a value output type. */
180     TEE_PARAM_TYPE_VALUE_OUTPUT     = 0x2,
181     /** Represents a value inout type. */
182     TEE_PARAM_TYPE_VALUE_INOUT      = 0x3,
183     /** Represents a memory reference input type. */
184     TEE_PARAM_TYPE_MEMREF_INPUT     = 0x5,
185     /** Represents a memory reference output type. */
186     TEE_PARAM_TYPE_MEMREF_OUTPUT    = 0x6,
187     /** Represents a memory reference inout type. */
188     TEE_PARAM_TYPE_MEMREF_INOUT     = 0x7,
189     /** Represents an ION input type. */
190     TEE_PARAM_TYPE_ION_INPUT        = 0x8,
191     /** Represents an ION single list input type. */
192     TEE_PARAM_TYPE_ION_SGLIST_INPUT = 0x9,
193     /** Represents a shared memory reference inout type. */
194     TEE_PARAM_TYPE_MEMREF_SHARED_INOUT = 0xa,
195     /** Represents a resource memory input type. */
196     TEE_PARAM_TYPE_RESMEM_INPUT        = 0xc,
197     /** Represents a resource memory output type. */
198     TEE_PARAM_TYPE_RESMEM_OUTPUT       = 0xd,
199     /** Represents a resource memory inout type. */
200     TEE_PARAM_TYPE_RESMEM_INOUT        = 0xe,
201 };
202 
203 /**
204  * @brief Marks a variable as unused.
205  *
206  * @since 20
207  */
208 #define S_VAR_NOT_USED(variable) \
209     do {                         \
210         (void)(variable);        \
211     } while (0)
212 
213 /**
214  * @brief Defines an object information.
215  *
216  * @since 20
217  */
218 typedef struct {
219     /** Type of the object. */
220     uint32_t objectType;
221     /** Size of the object. */
222     uint32_t objectSize;
223     /** Maximum allowed size for the object. */
224     uint32_t maxObjectSize;
225     /** Usage flags of the object. */
226     uint32_t objectUsage;
227     /** Size of the data associated with the object. */
228     uint32_t dataSize;
229     /** Position of the data within the object. */
230     uint32_t dataPosition;
231     /** Flags associated with the handle. */
232     uint32_t handleFlags;
233 } TEE_ObjectInfo;
234 
235 /**
236  * @brief Defines an object attribute.
237  *
238  * @since 20
239  */
240 typedef struct {
241     /** Attribute ID. */
242     uint32_t attributeID;
243     /**
244      * @brief Attribute content.
245      *
246      * @since 20
247      */
248     union {
249         /**
250          * @brief Reference type content.
251          *
252          * @since 20
253          */
254         struct {
255             /** Buffer pointer. */
256             void *buffer;
257             /** Length of the buffer. */
258             size_t length;
259         } ref;
260         /**
261          * @brief Value type content.
262          *
263          * @since 20
264          */
265         struct {
266             /** First value. */
267             uint32_t a;
268             /** Second value. */
269             uint32_t b;
270         } value;
271     } content;
272 } TEE_Attribute;
273 
274 /**
275  * @brief Enumerates the types of object attribute.
276  *
277  * @since 20
278  */
279 enum TEE_ObjectAttribute {
280     /** Secret value attribute. */
281     TEE_ATTR_SECRET_VALUE          = 0xC0000000,
282     /** RSA modulus attribute. */
283     TEE_ATTR_RSA_MODULUS           = 0xD0000130,
284     /** RSA public exponent attribute. */
285     TEE_ATTR_RSA_PUBLIC_EXPONENT   = 0xD0000230,
286     /** RSA private exponent attribute. */
287     TEE_ATTR_RSA_PRIVATE_EXPONENT  = 0xC0000330,
288     /** RSA prime1 attribute. */
289     TEE_ATTR_RSA_PRIME1            = 0xC0000430,
290     /** RSA prime2 attribute. */
291     TEE_ATTR_RSA_PRIME2            = 0xC0000530,
292     /** RSA exponent1 attribute. */
293     TEE_ATTR_RSA_EXPONENT1         = 0xC0000630,
294     /** RSA exponent2 attribute. */
295     TEE_ATTR_RSA_EXPONENT2         = 0xC0000730,
296     /** RSA coefficient attribute. */
297     TEE_ATTR_RSA_COEFFICIENT       = 0xC0000830,
298     /** RSA MGF1 hash attribute. */
299     TEE_ATTR_RSA_MGF1_HASH         = 0xF0000830,
300     /** DSA prime attribute. */
301     TEE_ATTR_DSA_PRIME             = 0xD0001031,
302     /** DSA subprime attribute. */
303     TEE_ATTR_DSA_SUBPRIME          = 0xD0001131,
304     /** DSA base attribute. */
305     TEE_ATTR_DSA_BASE              = 0xD0001231,
306     /** DSA public value attribute. */
307     TEE_ATTR_DSA_PUBLIC_VALUE      = 0xD0000131,
308     /** DSA private value attribute. */
309     TEE_ATTR_DSA_PRIVATE_VALUE     = 0xC0000231,
310     /** DH prime attribute. */
311     TEE_ATTR_DH_PRIME              = 0xD0001032,
312     /** DH subprime attribute. */
313     TEE_ATTR_DH_SUBPRIME           = 0xD0001132,
314     /** DH base attribute. */
315     TEE_ATTR_DH_BASE               = 0xD0001232,
316     /** DH X bits attribute. */
317     TEE_ATTR_DH_X_BITS             = 0xF0001332,
318     /** DH public value attribute. */
319     TEE_ATTR_DH_PUBLIC_VALUE       = 0xD0000132,
320     /** DH private value attribute. */
321     TEE_ATTR_DH_PRIVATE_VALUE      = 0xC0000232,
322     /** RSA OAEP label attribute. */
323     TEE_ATTR_RSA_OAEP_LABEL        = 0xD0000930,
324     /** RSA PSS salt length attribute. */
325     TEE_ATTR_RSA_PSS_SALT_LENGTH   = 0xF0000A30,
326     /** ECC public value X attribute. */
327     TEE_ATTR_ECC_PUBLIC_VALUE_X    = 0xD0000141,
328     /** ECC public value Y attribute. */
329     TEE_ATTR_ECC_PUBLIC_VALUE_Y    = 0xD0000241,
330     /** ECC private value attribute. */
331     TEE_ATTR_ECC_PRIVATE_VALUE     = 0xC0000341,
332     /** ECC curve attribute. */
333     TEE_ATTR_ECC_CURVE             = 0xF0000441,
334     /** ED25519 context attribute. */
335     TEE_ATTR_ED25519_CTX           = 0xD0000643,
336     /** ED25519 public value attribute. */
337     TEE_ATTR_ED25519_PUBLIC_VALUE  = 0xD0000743,
338     /** ED25519 private value attribute. */
339     TEE_ATTR_ED25519_PRIVATE_VALUE = 0xC0000843,
340     /** ED25519 PH attribute. */
341     TEE_ATTR_ED25519_PH            = 0xF0000543,
342     /** X25519 public value attribute. */
343     TEE_ATTR_X25519_PUBLIC_VALUE   = 0xD0000944,
344     /** X25519 private value attribute. */
345     TEE_ATTR_X25519_PRIVATE_VALUE  = 0xC0000A44,
346     /** PBKDF2 HMAC password attribute. */
347     TEE_ATTR_PBKDF2_HMAC_PASSWORD  = 0xD0000133,
348     /** PBKDF2 HMAC salt attribute. */
349     TEE_ATTR_PBKDF2_HMAC_SALT      = 0xD0000134,
350     /** PRF label attribute. */
351     TEE_ATTR_PRF_LABEL             = 0xD0000136,
352     /** PRF seed attribute. */
353     TEE_ATTR_PRF_SEED              = 0xD0000137,
354     /** PRF hash algorithm attribute. */
355     TEE_ATTR_PRF_HASH_ALGORITHM    = 0xF0000138,
356     /** HKDF salt attribute. */
357     TEE_ATTR_HKDF_SALT             = 0xD0000946,
358     /** HKDF info attribute. */
359     TEE_ATTR_HKDF_INFO             = 0xD0000A46,
360     /** PBKDF2 HMAC digest attribute. */
361     TEE_ATTR_PBKDF2_HMAC_DIGEST    = 0xF0000135,
362     /** HKDF hash algorithm attribute. */
363     TEE_ATTR_HKDF_HASH_ALGORITHM   = 0xF0000B46,
364     /** KDF key size attribute. */
365     TEE_ATTR_KDF_KEY_SIZE          = 0xF0000C46,
366 };
367 
368 /**
369  * @brief Enumerates the types of object.
370  *
371  * @since 20
372  */
373 enum TEE_ObjectType {
374     /** AES object type. */
375     TEE_TYPE_AES                = 0xA0000010,
376     /** DES object type. */
377     TEE_TYPE_DES                = 0xA0000011,
378     /** DES3 object type. */
379     TEE_TYPE_DES3               = 0xA0000013,
380     /** HMAC MD5 object type. */
381     TEE_TYPE_HMAC_MD5           = 0xA0000001,
382     /** HMAC SHA1 object type. */
383     TEE_TYPE_HMAC_SHA1          = 0xA0000002,
384     /** HMAC SHA224 object type. */
385     TEE_TYPE_HMAC_SHA224        = 0xA0000003,
386     /** HMAC SHA256 object type. */
387     TEE_TYPE_HMAC_SHA256        = 0xA0000004,
388     /** HMAC SHA384 object type. */
389     TEE_TYPE_HMAC_SHA384        = 0xA0000005,
390     /** HMAC SHA512 object type. */
391     TEE_TYPE_HMAC_SHA512        = 0xA0000006,
392     /** RSA public key object type. */
393     TEE_TYPE_RSA_PUBLIC_KEY     = 0xA0000030,
394     /** RSA keypair object type. */
395     TEE_TYPE_RSA_KEYPAIR        = 0xA1000030,
396     /** DSA public key object type. */
397     TEE_TYPE_DSA_PUBLIC_KEY     = 0xA0000031,
398     /** DSA keypair object type. */
399     TEE_TYPE_DSA_KEYPAIR        = 0xA1000031,
400     /** DH keypair object type. */
401     TEE_TYPE_DH_KEYPAIR         = 0xA1000032,
402     /** Generic secret object type. */
403     TEE_TYPE_GENERIC_SECRET     = 0xA0000000,
404     /** Data object type. */
405     TEE_TYPE_DATA               = 0xA1000033,
406     /** Data GP1.1 object type. */
407     TEE_TYPE_DATA_GP1_1         = 0xA00000BF,
408     /** ECDSA public key object type. */
409     TEE_TYPE_ECDSA_PUBLIC_KEY   = 0xA0000041,
410     /** ECDSA keypair object type. */
411     TEE_TYPE_ECDSA_KEYPAIR      = 0xA1000041,
412     /** ECDH public key object type. */
413     TEE_TYPE_ECDH_PUBLIC_KEY    = 0xA0000042,
414     /** ECDH keypair object type. */
415     TEE_TYPE_ECDH_KEYPAIR       = 0xA1000042,
416     /** ED25519 public key object type. */
417     TEE_TYPE_ED25519_PUBLIC_KEY = 0xA0000043,
418     /** ED25519 keypair object type. */
419     TEE_TYPE_ED25519_KEYPAIR    = 0xA1000043,
420     /** X25519 public key object type. */
421     TEE_TYPE_X25519_PUBLIC_KEY  = 0xA0000044,
422     /** X25519 keypair object type. */
423     TEE_TYPE_X25519_KEYPAIR     = 0xA1000044,
424     /** SM2 DSA public key object type. */
425     TEE_TYPE_SM2_DSA_PUBLIC_KEY = 0xA0000045,
426     /** SM2 DSA keypair object type. */
427     TEE_TYPE_SM2_DSA_KEYPAIR    = 0xA1000045,
428     /** SM2 KEP public key object type. */
429     TEE_TYPE_SM2_KEP_PUBLIC_KEY = 0xA0000046,
430     /** SM2 KEP keypair object type. */
431     TEE_TYPE_SM2_KEP_KEYPAIR    = 0xA1000046,
432     /** SM2 PKE public key object type. */
433     TEE_TYPE_SM2_PKE_PUBLIC_KEY = 0xA0000047,
434     /** SM2 PKE keypair object type. */
435     TEE_TYPE_SM2_PKE_KEYPAIR    = 0xA1000047,
436     /** HMAC SM3 object type. */
437     TEE_TYPE_HMAC_SM3           = 0xA0000007,
438     /** SM4 object type. */
439     TEE_TYPE_SM4                = 0xA0000014,
440     /** HKDF object type. */
441     TEE_TYPE_HKDF               = 0xA000004A,
442     /** SIP Hash object type. */
443     TEE_TYPE_SIP_HASH           = 0xF0000002,
444     /** PBKDF2 HMAC object type. */
445     TEE_TYPE_PBKDF2_HMAC        = 0xF0000004,
446     /** PRF object type. */
447     TEE_TYPE_PRF                = 0xF0000005,
448     /** Corrupted object type. */
449     TEE_TYPE_CORRUPTED_OBJECT = 0xA00000BE,
450 };
451 
452 /**
453  * @brief Maximum length for the object name.
454  *
455  * @since 20
456  */
457 #define OBJECT_NAME_LEN_MAX 256
458 
459 /**
460  * @brief Defines an object handle.
461  *
462  * @since 20
463  */
464 struct __TEE_ObjectHandle {
465     /** Pointer to the data. */
466     void *dataPtr;
467     /** Length of the data. */
468     uint32_t dataLen;
469     /** Name of the data. */
470     uint8_t dataName[OBJECT_NAME_LEN_MAX];
471     /** Pointer to the object information. */
472     TEE_ObjectInfo *ObjectInfo;
473     /** Pointer to the attributes of the object. */
474     TEE_Attribute *Attribute;
475     /** Length of the attributes. */
476     uint32_t attributesLen;
477     /** CRT mode. */
478     uint32_t CRTMode;
479     /** File descriptor for info attributes. */
480     void *infoattrfd;
481     /** Flag for object generation. */
482     uint32_t generate_flag;
483     /** Storage ID for the object. */
484     uint32_t storage_id;
485 };
486 
487 /**
488  * @brief Defines the <b>__TEE_ObjectHandle</b> struct.
489  *
490  * @see __TEE_ObjectHandle
491  *
492  * @since 20
493  */
494 typedef struct __TEE_ObjectHandle *TEE_ObjectHandle;
495 
496 /**
497  * @brief Enumerates the result codes used in the TEEKit APIs.
498  *
499  * @since 20
500  */
501 enum TEE_Result_Value {
502     /** The operation is successful. */
503     TEE_SUCCESS                        = 0x00000000,
504     /** The command is invalid. */
505     TEE_ERROR_INVALID_CMD              = 0x00000001,
506     /** The service does not exist. */
507     TEE_ERROR_SERVICE_NOT_EXIST        = 0x00000002,
508     /** The session does not exist. */
509     TEE_ERROR_SESSION_NOT_EXIST        = 0x00000003,
510     /** The number of sessions exceeds the limit. */
511     TEE_ERROR_SESSION_MAXIMUM          = 0x00000004,
512     /** The service has been already registered. */
513     TEE_ERROR_REGISTER_EXIST_SERVICE   = 0x00000005,
514     /** An internal error occurs. */
515     TEE_ERROR_TARGET_DEAD_FATAL        = 0x00000006,
516     /** Failed to read data. */
517     TEE_ERROR_READ_DATA                = 0x00000007,
518     /** Failed to write data. */
519     TEE_ERROR_WRITE_DATA               = 0x00000008,
520     /** Failed to truncate data. */
521     TEE_ERROR_TRUNCATE_OBJECT          = 0x00000009,
522     /** Failed to seek data. */
523     TEE_ERROR_SEEK_DATA                = 0x0000000A,
524     /** Failed to synchronize data. */
525     TEE_ERROR_SYNC_DATA                = 0x0000000B,
526     /** Failed to rename the file. */
527     TEE_ERROR_RENAME_OBJECT            = 0x0000000C,
528     /** An error occurs when the TA is loaded. */
529     TEE_ERROR_TRUSTED_APP_LOAD_ERROR   = 0x0000000D,
530     /** TA type is inconsistent with the loading mode. */
531     TEE_ERROR_OTRP_LOAD_NOT_MATCHED    = 0x80000100,
532     /** The not open session's otrp service num exceeds. */
533     TEE_ERROR_OTRP_LOAD_EXCEED         = 0x80000101,
534     /** UUID of load cmd is not inconsistent with the sec file. */
535     TEE_ERROR_OTRP_ACCESS_DENIED       = 0x80000102,
536     /** Otrp service is aged. */
537     TEE_ERROR_OTRP_SERVICE_AGED        = 0x80000103,
538     /** An I/O error occurs when data is stored. */
539     TEE_ERROR_STORAGE_EIO              = 0x80001001,
540     /** The storage section is unavailable. */
541     TEE_ERROR_STORAGE_EAGAIN           = 0x80001002,
542     /** The operation target is not a directory. */
543     TEE_ERROR_STORAGE_ENOTDIR          = 0x80001003,
544     /** This operation cannot be performed on a directory. */
545     TEE_ERROR_STORAGE_EISDIR           = 0x80001004,
546     /** The number of opened files exceeds the limit in system. */
547     TEE_ERROR_STORAGE_ENFILE           = 0x80001005,
548     /** The number of files opened for the process exceeds the limit.*/
549     TEE_ERROR_STORAGE_EMFILE           = 0x80001006,
550     /** The storage section is read only. */
551     TEE_ERROR_STORAGE_EROFS            = 0x80001007,
552     /** The file object has been rolled back. */
553     TEE_ERROR_STORAGE_EROLLBACK        = 0x80001008,
554     /** The file path is not correct. */
555     TEE_ERROR_STORAGE_PATH_WRONG       = 0x8000100A,
556     /** The service message queue overflows. */
557     TEE_ERROR_MSG_QUEUE_OVERFLOW       = 0x8000100B,
558     /** The subthread created by TA cannot access the service */
559     TEE_ERROR_SUBTHREAD_ACCESS         = 0x8000100C,
560     /** Enable backup feature, original partition is inactive */
561     TEE_ERROR_ORIGIN_PARTITION_INACTIVE = 0x8000100D,
562     /** Enable backup feature, backup partition is inactive */
563     TEE_ERROR_BACKUP_PARTITION_INACTIVE = 0x8000100E,
564     /** The file object is corrupted. */
565     TEE_ERROR_CORRUPT_OBJECT           = 0xF0100001,
566     /** The storage section is unavailable. */
567     TEE_ERROR_STORAGE_NOT_AVAILABLE    = 0xF0100003,
568     /** The cipher text is incorrect. */
569     TEE_ERROR_CIPHERTEXT_INVALID       = 0xF0100006,
570     /** Protocol error in socket connection. */
571     TEE_ISOCKET_ERROR_PROTOCOL         = 0xF1007001,
572     /** The socket is closed by the remote end. */
573     TEE_ISOCKET_ERROR_REMOTE_CLOSED    = 0xF1007002,
574     /** The socket connection timed out. */
575     TEE_ISOCKET_ERROR_TIMEOUT          = 0xF1007003,
576     /** There is no resource available for the socket connection. */
577     TEE_ISOCKET_ERROR_OUT_OF_RESOURCES = 0xF1007004,
578     /** The buffer is too large for the socket connection. */
579     TEE_ISOCKET_ERROR_LARGE_BUFFER     = 0xF1007005,
580     /** A warning is given in the socket connection. */
581     TEE_ISOCKET_WARNING_PROTOCOL       = 0xF1007006,
582     /** Generic error. */
583     TEE_ERROR_GENERIC                  = 0xFFFF0000,
584     /** The access is denied. */
585     TEE_ERROR_ACCESS_DENIED            = 0xFFFF0001,
586     /** The operation has been canceled. */
587     TEE_ERROR_CANCEL                   = 0xFFFF0002,
588     /** An access conflict occurs. */
589     TEE_ERROR_ACCESS_CONFLICT          = 0xFFFF0003,
590     /** The data size exceeds the maximum. */
591     TEE_ERROR_EXCESS_DATA              = 0xFFFF0004,
592     /** Incorrect data format. */
593     TEE_ERROR_BAD_FORMAT               = 0xFFFF0005,
594     /** Incorrect parameters. */
595     TEE_ERROR_BAD_PARAMETERS           = 0xFFFF0006,
596     /** The current state does not support the operation. */
597     TEE_ERROR_BAD_STATE                = 0xFFFF0007,
598     /** Failed to find the target item. */
599     TEE_ERROR_ITEM_NOT_FOUND           = 0xFFFF0008,
600     /** The API is not implemented. */
601     TEE_ERROR_NOT_IMPLEMENTED          = 0xFFFF0009,
602     /** The API is not supported. */
603     TEE_ERROR_NOT_SUPPORTED            = 0xFFFF000A,
604     /** There is no data available for this operation. */
605     TEE_ERROR_NO_DATA                  = 0xFFFF000B,
606     /** There is no memory available for this operation. */
607     TEE_ERROR_OUT_OF_MEMORY            = 0xFFFF000C,
608     /** The system does not respond to this operation. */
609     TEE_ERROR_BUSY                     = 0xFFFF000D,
610     /** Failed to communicate with the target. */
611     TEE_ERROR_COMMUNICATION            = 0xFFFF000E,
612     /** A security error occurs. */
613     TEE_ERROR_SECURITY                 = 0xFFFF000F,
614     /** The buffer is insufficient for this operation. */
615     TEE_ERROR_SHORT_BUFFER             = 0xFFFF0010,
616     /** The operation has been canceled. */
617     TEE_ERROR_EXTERNAL_CANCEL          = 0xFFFF0011,
618     /** The service is in the pending state (asynchronous state). */
619     TEE_PENDING                        = 0xFFFF2000,
620     /** The service is in the pending state(). */
621     TEE_PENDING2                       = 0xFFFF2001,
622     /** Reserved. */
623     TEE_PENDING3                       = 0xFFFF2002,
624     /** The operation timed out. */
625     TEE_ERROR_TIMEOUT                  = 0xFFFF3001,
626     /** Overflow occurs. */
627     TEE_ERROR_OVERFLOW                 = 0xFFFF300f,
628     /** The TA is crashed. */
629     TEE_ERROR_TARGET_DEAD              = 0xFFFF3024,
630     /** There is no enough space to store data. */
631     TEE_ERROR_STORAGE_NO_SPACE         = 0xFFFF3041,
632     /** The MAC operation failed. */
633     TEE_ERROR_MAC_INVALID              = 0xFFFF3071,
634     /** The signature verification failed. */
635     TEE_ERROR_SIGNATURE_INVALID        = 0xFFFF3072,
636     /** Thecertificate verify failed. */
637     TEE_ERROR_CERTIFICATE_INVALID      = 0xFFFF3073,
638     /** Interrupted by CFC. Broken control flow is detected. */
639     TEE_CLIENT_INTR                    = 0xFFFF4000,
640     /** Time is not set. */
641     TEE_ERROR_TIME_NOT_SET             = 0xFFFF5000,
642     /** Time needs to be reset. */
643     TEE_ERROR_TIME_NEEDS_RESET         = 0xFFFF5001,
644     /** System error. */
645     TEE_FAIL                           = 0xFFFF5002,
646     /** Base value of the timer error code. */
647     TEE_ERROR_TIMER                    = 0xFFFF6000,
648     /** Failed to create the timer. */
649     TEE_ERROR_TIMER_CREATE_FAILED      = 0xFFFF6001,
650     /** Failed to destroy the timer. */
651     TEE_ERROR_TIMER_DESTROY_FAILED     = 0xFFFF6002,
652     /** The timer is not found. */
653     TEE_ERROR_TIMER_NOT_FOUND          = 0xFFFF6003,
654     /** Base value of RPMB error codes. */
655     TEE_ERROR_RPMB_BASE                = 0xFFFF7000,
656     /** Generic error of RPMB operations. */
657     TEE_ERROR_RPMB_GENERIC             = 0xFFFF7001,
658     /** Verify MAC failed in RPMB operations. */
659     TEE_ERROR_RPMB_MAC_FAIL            = 0xFFFF7002,
660     /** Invalid counter in RPMB operations. */
661     TEE_ERROR_RPMB_COUNTER_FAIL        = 0xFFFF7003,
662     /** Address check failed in RPMB operations. */
663     TEE_ERROR_RPMB_ADDR_FAIL           = 0xFFFF7004,
664     /** Fail to write data to RPMB. */
665     TEE_ERROR_RPMB_WRITE_FAIL          = 0xFFFF7005,
666     /** Fail to read data in RPMB.  */
667     TEE_ERROR_RPMB_READ_FAIL           = 0xFFFF7006,
668     /** Key is not provisioned in RPMB. */
669     TEE_ERROR_RPMB_KEY_NOT_PROGRAM     = 0xFFFF7007,
670     /** Incorrect message type in RPMB response. */
671     TEE_ERROR_RPMB_RESP_UNEXPECT_MSGTYPE = 0xFFFF7100,
672     /** Incorrect message data block count in RPMB response. */
673     TEE_ERROR_RPMB_RESP_UNEXPECT_BLKCNT = 0xFFFF7101,
674     /** Incorrect message data block count in RPMB response. */
675     TEE_ERROR_RPMB_RESP_UNEXPECT_BLKIDX = 0xFFFF7102,
676     /** Incorrect message data counter in RPMB response. */
677     TEE_ERROR_RPMB_RESP_UNEXPECT_WRCNT = 0xFFFF7103,
678     /** Incorrect message data nonce in RPMB response. */
679     TEE_ERROR_RPMB_RESP_UNEXPECT_NONCE = 0xFFFF7104,
680     /** Incorrect message data MAC in RPMB response. */
681     TEE_ERROR_RPMB_RESP_UNEXPECT_MAC   = 0xFFFF7105,
682     /** The file is not found in RPMB.  */
683     TEE_ERROR_RPMB_FILE_NOT_FOUND      = 0xFFFF7106,
684     /** No spece left for RPMB operations. */
685     TEE_ERROR_RPMB_NOSPC               = 0xFFFF7107,
686     /** Exceeds max space of RPMB for this TA. */
687     TEE_ERROR_RPMB_SPC_CONFLICT        = 0xFFFF7108,
688     /** RPMB service not ready. */
689     TEE_ERROR_RPMB_NOT_AVAILABLE       = 0xFFFF7109,
690     /** RPMB partition is damaged. */
691     TEE_ERROR_RPMB_DAMAGED             = 0xFFFF710A,
692     /** TUI is being used. */
693     TEE_ERROR_TUI_IN_USE               = 0xFFFF7110,
694     /** Incorrect message switch channal in TUI response. */
695     TEE_ERROR_TUI_SWITCH_CHANNAL       = 0xFFFF7111,
696     /** Incorrect message configurator driver in TUI response. */
697     TEE_ERROR_TUI_CFG_DRIVER           = 0xFFFF7112,
698     /** Invalid TUI event. */
699     TEE_ERROR_TUI_INVALID_EVENT        = 0xFFFF7113,
700     /** Incorrect message polling events in TUI response. */
701     TEE_ERROR_TUI_POLL_EVENT           = 0xFFFF7114,
702     /** TUI is cancelled. */
703     TEE_ERROR_TUI_CANCELED             = 0xFFFF7115,
704     /** TUI is exited. */
705     TEE_ERROR_TUI_EXIT                 = 0xFFFF7116,
706     /** TUI unavailable. */
707     TEE_ERROR_TUI_NOT_AVAILABLE        = 0xFFFF7117,
708     /** sec flash is not available. */
709     TEE_ERROR_SEC_FLASH_NOT_AVAILABLE  = 0xFFFF7118,
710     /** SE service has crashed or not enable. */
711     TEE_ERROR_SESRV_NOT_AVAILABLE      = 0xFFFF7119,
712     /** The BIO service is not available. */
713     TEE_ERROR_BIOSRV_NOT_AVAILABLE     = 0xFFFF711A,
714     /** The ROT service is not available. */
715     TEE_ERROR_ROTSRV_NOT_AVAILABLE     = 0xFFFF711B,
716     /** The TA Anti-Rollback service is not available. */
717     TEE_ERROR_ARTSRV_NOT_AVAILABLE     = 0xFFFF711C,
718     /** The HSM service is not available. */
719     TEE_ERROR_HSMSRV_NOT_AVAILABLE     = 0xFFFF711D,
720     /** REE vrpmb agent check magic failed, maybe cache fail. */
721     TEE_ERROR_VRPMB_AGENT_FAIL              = 0xFFFF7200,
722     /** REE ssd driver rw failed. */
723     TEE_ERROR_VRPMB_RW_FAIL                 = 0xFFFF7201,
724     /** vrpmb check super block mac failed. */
725     TEE_ERROR_VRPMB_SUPER_MAC_FAILED        = 0xFFFF7202,
726     /** reject write to vrpmb. */
727     TEE_ERROR_VRPMB_WRITE_REJECT            = 0xFFFF7203,
728     /** Failed to verify AntiRoot response. */
729     TEE_ERROR_ANTIROOT_RSP_FAIL        = 0xFFFF9110,
730     /** AntiRoot error in invokeCmd(). */
731     TEE_ERROR_ANTIROOT_INVOKE_ERROR    = 0xFFFF9111,
732     /** Audit failed. */
733     TEE_ERROR_AUDIT_FAIL               = 0xFFFF9112,
734     /** Unused. */
735     TEE_FAIL2                          = 0xFFFF9113,
736     /** IPC Channel overflow error. */
737     TEE_ERROR_IPC_OVERFLOW             = 0xFFFF9114,
738     /** APM error. */
739     TEE_ERROR_APM                           = 0xFFFF9115,
740     /** CA auth file not exist. */
741     TEE_ERROR_CA_AUTHFILE_NOT_EXIST         = 0xFFFF9116,
742     /** CA caller access is denied. */
743     TEE_ERROR_CA_CALLER_ACCESS_DENIED       = 0xFFFF9117,
744     /** Invalid TA format. */
745     TEE_ERROR_INVALID_TA_FORMAT             = 0xFFFF9118,
746     /** local dstb service sign report error. */
747     TEE_DSTB_LOCAL_SIGN_REPORT_ERROR        = 0xFFFF9200,
748     /** remote dstb service sign report error. */
749     TEE_DSTB_REMOTE_SIGN_REPORT_ERROR       = 0xFFFF9201,
750     /** local dstb service report cert chain error. */
751     TEE_DSTB_LOCAL_REPORT_CERT_CHAIN_ERROR  = 0xFFFF9202,
752     /** remote dstb service report cert chain error. */
753     TEE_DSTB_REMOTE_REPORT_CERT_CHAIN_ERROR = 0xFFFF9203,
754     /** local dstb service verify report error. */
755     TEE_DSTB_LOCAL_REPORT_VERIFY_ERROR      = 0xFFFF9204,
756     /** remote dstb service verify report error. */
757     TEE_DSTB_REMOTE_REPORT_VERIFY_ERROR     = 0xFFFF9205,
758     /** local dstb service verify cert chain error. */
759     TEE_DSTB_LOCAL_CERT_CHAIN_VERIFY_ERROR  = 0xFFFF9206,
760     /** remote dstb service verify cert chain error. */
761     TEE_DSTB_REMOTE_CERT_CHAIN_VERIFY_ERROR = 0xFFFF9207,
762     /** local dstb service key version error. */
763     TEE_DSTB_LOCAL_INVALID_KEY_VERSION_ERROR = 0xFFFF9208,
764     /** remote dstb service key version error. */
765     TEE_DSTB_REMOTE_INVALID_KEY_VERSION_ERROR = 0xFFFF9209,
766     /** udid is invalid. */
767     TEE_DSTB_INVALID_UDID                   = 0xFFFF920A,
768     /** dstb service derive key error. */
769     TEE_DSTB_DERIVE_KEY_ERROR               = 0xFFFF920B,
770     /** dstb service of ree error. */
771     TEE_DSTB_REE_SRV_ERROR                  = 0xFFFF920C,
772     /** TA load fail becauce of anti-rollback. */
773     TEE_ERROR_TA_ANTI_ROLLBACK              = 0xFFFF920D,
774     /** open_session fail becauce of race with close_session. */
775     TEE_ERROR_RETRY_OPEN_SESSION            = 0xFFFF920E,
776     /** TA control file load fail. */
777     TEE_ERROR_TA_CTRL_FILE_LOAD_FAIL        = 0xFFFF920F,
778     /** TA control file verify fail. */
779     TEE_ERROR_TA_CTRL_FILE_VERIFY_FAIL      = 0xFFFF9210,
780     /** TA version is below the verison in control file. */
781     TEE_ERROR_TA_VER_BELOW_CONTROL_VER      = 0xFFFF9211,
782     /** Local dstb cert chain validity check failed. */
783     TEE_DSTB_LOCAL_CERT_VALIDITY_ERROR      = 0xFFFF9212,
784     /** Remote dstb cert chain validity check failed. */
785     TEE_DSTB_REMOTE_CERT_VALIDITY_ERROR     = 0xFFFF9213,
786 };
787 
788 /**
789  * @brief Login type definitions
790  *
791  * @since 20
792  */
793 enum TEE_LoginMethod {
794     /** Public login method. */
795     TEE_LOGIN_PUBLIC = 0x0,
796     /** User login method. */
797     TEE_LOGIN_USER,
798     /** Group login method. */
799     TEE_LOGIN_GROUP,
800     /** Application login method. */
801     TEE_LOGIN_APPLICATION = 0x4,
802     /** User-application login method. */
803     TEE_LOGIN_USER_APPLICATION = 0x5,
804     /** Group-application login method. */
805     TEE_LOGIN_GROUP_APPLICATION = 0x6,
806     /** Customized login type. */
807     TEE_LOGIN_IDENTIFY = 0x7,
808     /** Login type from the Linux kernel. */
809     TEEK_LOGIN_IDENTIFY = 0x80000001,
810 };
811 
812 /**
813  * @brief Definitions the TEE Identity.
814  *
815  * @since 20
816  */
817 typedef struct {
818     /** Login method. */
819     uint32_t login;
820     /** The UUID of the identity. */
821     TEE_UUID uuid;
822 } TEE_Identity;
823 
824 /**
825  * @brief Defines the return values.
826  *
827  * @since 20
828  * @version 1.0
829  */
830 typedef uint32_t TEE_Result;
831 
832 /**
833  * @brief Defines the return values.
834  *
835  * @since 20
836  * @version 1.0
837  */
838 typedef TEE_Result TEEC_Result;
839 
840 /**
841  * @brief Origin of the TEE.
842  *
843  * @since 20
844  */
845 #define TEE_ORIGIN_TEE             0x00000003
846 
847 /**
848  * @brief Origin of the Trusted Application.
849  *
850  * @since 20
851  */
852 #define TEE_ORIGIN_TRUSTED_APP     0x00000004
853 
854 #ifndef _TEE_TA_SESSION_HANDLE
855 /**
856  * @brief Defines the handle for a TA session.
857  *
858  * @since 20
859  */
860 #define _TEE_TA_SESSION_HANDLE
861 /**
862  * @brief Defines the handle of TA session.
863  *
864  * @since 20
865  */
866 typedef uint32_t TEE_TASessionHandle;
867 #endif
868 
869 /**
870  * @brief Defines the pointer to <b>TEE_ObjectEnumHandle</b>.
871  *
872  * @see __TEE_ObjectEnumHandle
873  *
874  * @since 20
875  */
876 typedef struct __TEE_ObjectEnumHandle *TEE_ObjectEnumHandle;
877 
878 /**
879  * @brief Defines the pointer to <b>__TEE_OperationHandle</b>.
880  *
881  * @see __TEE_OperationHandle
882  *
883  * @since 20
884  */
885 typedef struct __TEE_OperationHandle *TEE_OperationHandle;
886 
887 /**
888  * @brief Defines the infinite timeout value.
889  *
890  * @since 20
891  */
892 #define TEE_TIMEOUT_INFINITE (0xFFFFFFFF)
893 
894 /**
895  * @brief Definitions the TEE time.
896  *
897  * @since 20
898  */
899 typedef struct {
900     /** Seconds part of the time. */
901     uint32_t seconds;
902     /** Milliseconds part of the time. */
903     uint32_t millis;
904 } TEE_Time;
905 
906 /**
907  * @brief Definitions the date time of TEE.
908  *
909  * @since 20
910  */
911 typedef struct {
912     /** Seconds part of the date time. */
913     int32_t seconds;
914     /** Milliseconds part of the date time. */
915     int32_t millis;
916     /** Minutes part of the date time. */
917     int32_t min;
918     /** Hours part of the date time. */
919     int32_t hour;
920     /** Day part of the date time. */
921     int32_t day;
922     /** Month part of the date time. */
923     int32_t month;
924     /** Year part of the date time. */
925     int32_t year;
926 } TEE_Date_Time;
927 
928 /**
929  * @brief Definitions the timer property of TEE.
930  *
931  * @since 20
932  */
933 typedef struct {
934     /** Type of the timer. */
935     uint32_t type;
936     /** Timer ID. */
937     uint32_t timer_id;
938     /** Timer class. */
939     uint32_t timer_class;
940     /** Reserved field for future use. */
941     uint32_t reserved2;
942 } TEE_timer_property;
943 
944 #ifdef __cplusplus
945 }
946 #endif
947 
948 #endif
949 /** @} */