1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 13 #ifndef TEE_CLIENT_TYPE_H 14 #define TEE_CLIENT_TYPE_H 15 /** 16 * @addtogroup TeeClient 17 * @{ 18 * 19 * @brief Provides APIs for the client applications (CAs) in the Rich Execution Environment (normal mode) to 20 * access the trusted applications (TAs) in a Trusted Execution Environment (TEE). 21 * 22 * @syscap SystemCapability.Tee.TeeClient 23 * @since 8 24 */ 25 26 /** 27 * @file tee_client_type.h 28 * 29 * @brief Defines basic data types and data structures. 30 * 31 * @since 8 32 */ 33 34 #include <semaphore.h> 35 #include <stdbool.h> 36 #include <stddef.h> 37 #include <stdint.h> 38 #include <stdio.h> 39 #include "tee_client_constants.h" 40 41 /** 42 * @brief Defines the linked list type. 43 * 44 * @since 8 45 */ 46 struct ListNode { 47 struct ListNode *next; 48 struct ListNode *prev; 49 }; 50 51 /** 52 * @brief Defines the return values. 53 * 54 * @since 8 55 */ 56 typedef enum TEEC_ReturnCode TEEC_Result; 57 58 /** 59 * @brief Defines the universally unique identifier (UUID) as defined in RFC4122 [2]. The UUIDs are used to identify TAs. 60 * 61 * @since 8 62 */ 63 typedef struct { 64 uint32_t timeLow; 65 uint16_t timeMid; 66 uint16_t timeHiAndVersion; 67 uint8_t clockSeqAndNode[8]; 68 } TEEC_UUID; 69 70 /** 71 * @brief Defines the context, a logical connection between a CA and a TEE. 72 * 73 * @since 8 74 */ 75 typedef struct { 76 int32_t fd; 77 uint8_t *ta_path; 78 struct ListNode session_list; 79 struct ListNode shrd_mem_list; 80 union { 81 struct { 82 void *buffer; 83 sem_t buffer_barrier; 84 } share_buffer; 85 uint64_t imp; 86 }; 87 } TEEC_Context; 88 89 /** 90 * @brief Defines the session between a CA and a TA. 91 * 92 * @since 8 93 */ 94 typedef struct { 95 uint32_t session_id; 96 TEEC_UUID service_id; 97 uint32_t ops_cnt; 98 union { 99 struct ListNode head; 100 uint64_t imp; 101 }; 102 TEEC_Context *context; 103 } TEEC_Session; 104 105 /** 106 * @brief Defines a shared memory block, which can be registered or allocated. 107 * 108 * @since 8 109 */ 110 typedef struct { 111 void *buffer; 112 uint32_t size; 113 uint32_t flags; 114 uint32_t ops_cnt; 115 bool is_allocated; 116 union { 117 struct ListNode head; 118 void* imp; 119 }; 120 TEEC_Context *context; 121 } TEEC_SharedMemory; 122 123 /** 124 * @brief Defines a pointer to a temporary buffer. 125 * 126 * @since 8 127 */ 128 typedef struct { 129 void *buffer; 130 uint32_t size; 131 } TEEC_TempMemoryReference; 132 133 /** 134 * @brief Defines a pointer to the shared memory that is registered or allocated. 135 * 136 * @since 8 137 */ 138 typedef struct { 139 TEEC_SharedMemory *parent; 140 uint32_t size; 141 uint32_t offset; 142 } TEEC_RegisteredMemoryReference; 143 144 /** 145 * @brief Describes a parameter that carries small raw data passed by <b>value</b>. 146 * 147 * @since 8 148 */ 149 typedef struct { 150 uint32_t a; 151 uint32_t b; 152 } TEEC_Value; 153 154 /** 155 * @brief Describes the size and handle of the ION memory. 156 * 157 * @since 8 158 */ 159 typedef struct { 160 int ion_share_fd; 161 uint32_t ion_size; 162 } TEEC_IonReference; 163 164 /** 165 * @brief Defines a parameter of {@code TEEC_Operation}. 166 * 167 * @since 8 168 */ 169 typedef union { 170 TEEC_TempMemoryReference tmpref; 171 TEEC_RegisteredMemoryReference memref; 172 TEEC_Value value; 173 TEEC_IonReference ionref; 174 } TEEC_Parameter; 175 176 /** 177 * @brief Defines the parameters for opening a session or sending a command. 178 * 179 * @since 8 180 */ 181 typedef struct { 182 /** The value 0 means to cancel the command, and other values mean to execute the command. */ 183 uint32_t started; 184 /** Use {@code TEEC_PARAM_TYPES} to create this parameter. */ 185 uint32_t paramTypes; 186 TEEC_Parameter params[TEEC_PARAM_NUM]; 187 TEEC_Session *session; 188 bool cancel_flag; 189 } TEEC_Operation; 190 191 /** @} */ 192 #endif 193