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_TYPE_H 17 #define TEE_CLIENT_TYPE_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_type.h 31 * 32 * @brief Defines basic data types and data structures. 33 * 34 * @library libteec.so 35 * @kit TEEKit 36 * @syscap SystemCapability.Tee.TeeClient 37 * @since 12 38 * @version 1.0 39 */ 40 41 #include <semaphore.h> 42 #include <stdbool.h> 43 #include <stddef.h> 44 #include <stdint.h> 45 #include <stdio.h> 46 #include "tee_client_constants.h" 47 48 /** 49 * @brief Defines the linked list type. 50 * 51 * @since 12 52 * @version 1.0 53 */ 54 struct ListNode { 55 struct ListNode *next; 56 struct ListNode *prev; 57 }; 58 59 /** 60 * @brief Defines the return values. 61 * 62 * @since 12 63 * @version 1.0 64 */ 65 typedef enum TEEC_ReturnCode TEEC_Result; 66 67 /** 68 * @brief Defines the universally unique identifier (UUID) as defined in RFC4122 [2]. 69 * The UUIDs are used to identify TAs. 70 * 71 * @since 12 72 * @version 1.0 73 */ 74 typedef struct { 75 uint32_t timeLow; 76 uint16_t timeMid; 77 uint16_t timeHiAndVersion; 78 uint8_t clockSeqAndNode[8]; 79 } TEEC_UUID; 80 81 /** 82 * @brief Defines the context, a logical connection between a CA and a TEE. 83 * 84 * @since 12 85 * @version 1.0 86 */ 87 typedef struct { 88 int32_t fd; 89 uint8_t *ta_path; 90 struct ListNode session_list; 91 struct ListNode shrd_mem_list; 92 union { 93 struct { 94 void *buffer; 95 sem_t buffer_barrier; 96 } share_buffer; 97 uint64_t imp; 98 }; 99 } TEEC_Context; 100 101 /** 102 * @brief Defines the session between a CA and a TA. 103 * 104 * @since 12 105 * @version 1.0 106 */ 107 typedef struct { 108 uint32_t session_id; 109 TEEC_UUID service_id; 110 uint32_t ops_cnt; 111 union { 112 struct ListNode head; 113 uint64_t imp; 114 }; 115 TEEC_Context *context; 116 } TEEC_Session; 117 118 /** 119 * @brief Defines a shared memory block, which can be registered or allocated. 120 * 121 * @since 12 122 * @version 1.0 123 */ 124 typedef struct { 125 void *buffer; 126 uint32_t size; 127 uint32_t flags; 128 uint32_t ops_cnt; 129 bool is_allocated; 130 union { 131 struct ListNode head; 132 void* imp; 133 }; 134 TEEC_Context *context; 135 } TEEC_SharedMemory; 136 137 /** 138 * @brief Defines a pointer to a temporary buffer. 139 * 140 * @since 12 141 * @version 1.0 142 */ 143 typedef struct { 144 void *buffer; 145 uint32_t size; 146 } TEEC_TempMemoryReference; 147 148 /** 149 * @brief Defines a pointer to the shared memory that is registered or allocated. 150 * 151 * @since 12 152 * @version 1.0 153 */ 154 typedef struct { 155 TEEC_SharedMemory *parent; 156 uint32_t size; 157 uint32_t offset; 158 } TEEC_RegisteredMemoryReference; 159 160 /** 161 * @brief Describes a parameter that carries small raw data passed by <b>value</b>. 162 * 163 * @since 12 164 * @version 1.0 165 */ 166 typedef struct { 167 uint32_t a; 168 uint32_t b; 169 } TEEC_Value; 170 171 /** 172 * @brief Describes the size and handle of the ION memory. 173 * 174 * @since 12 175 * @version 1.0 176 */ 177 typedef struct { 178 int ionShareFd; 179 uint32_t ionSize; 180 } TEEC_IonReference; 181 182 /** 183 * @brief Defines a parameter of {@code TEEC_Operation}. 184 * 185 * @since 12 186 * @version 1.0 187 */ 188 typedef union { 189 TEEC_TempMemoryReference tmpref; 190 TEEC_RegisteredMemoryReference memref; 191 TEEC_Value value; 192 TEEC_IonReference ionref; 193 } TEEC_Parameter; 194 195 /** 196 * @brief Defines the parameters for opening a session or sending a command. 197 * 198 * @since 12 199 * @version 1.0 200 */ 201 typedef struct { 202 /** The value 0 means to cancel the command, and other values mean to execute the command. */ 203 uint32_t started; 204 /** Use {@code TEEC_PARAM_TYPES} to create this parameter. */ 205 uint32_t paramTypes; 206 TEEC_Parameter params[TEEC_PARAM_NUM]; 207 TEEC_Session *session; 208 bool cancel_flag; 209 } TEEC_Operation; 210 211 /** @} */ 212 #endif 213