1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _TEE_CLIENT_TYPE_H_ 33 #define _TEE_CLIENT_TYPE_H_ 34 #define SECURITY_AUTH_ENHANCE 35 #include "teek_client_constants.h" 36 #include "teek_client_list.h" 37 #define TOKEN_SAVE_LEN 24 38 #define CLOCK_NODE_LEN 8 39 #define TEE_PARAM_NUM 4 40 41 /* 42 * @ingroup teec_common_data 43 * define NULL 44 */ 45 #ifndef NULL 46 #define NULL 0 47 #endif 48 49 /* 50 * @ingroup teec_common_data 51 * Function return value type 52 */ 53 typedef uint32_t TeecResult; 54 55 /* 56 * @ingroup teec_common_data 57 * uuid type def 58 * 59 * uuid type follow rfc4122 [2],is used to identify the security service. 60 */ 61 typedef struct { 62 /* Lower 4 bytes of the timestamp */ 63 uint32_t timeLow; 64 /* Middle 2 bytes of the timestamp */ 65 uint16_t timeMid; 66 /* Combination of higher 2 bytes of the timestamp and version */ 67 uint16_t timeHiAndVersion; 68 /* Combination of clock sequence and node identifier */ 69 uint8_t clockseqAndNode[CLOCK_NODE_LEN]; 70 } TeecUuid; 71 72 /* 73 * @ingroup teec_common_data 74 * teec_context struct definition 75 * 76 * Describes the connect context between client applications and the secure world. 77 */ 78 typedef struct { 79 void *dev; 80 uint8_t *ta_path; 81 /* session list */ 82 struct ListNode sessionList; 83 /* shared memory list */ 84 struct ListNode shrdMemList; 85 } TeecContext; 86 87 /* 88 * @ingroup teec_common_data 89 * teec_session 90 * 91 * Describes the sessions established between CAs and the TEE. 92 */ 93 typedef struct { 94 /* Session ID, which is returned by the TEE. */ 95 uint32_t sessionId; 96 /* Indicates the UUID of a security service. Each TA has a unique UUID. */ 97 TeecUuid serviceId; 98 /* Number of operations in a session. */ 99 uint32_t opsCnt; 100 /* Session linked list header */ 101 struct ListNode head; 102 /* Point to the Tee context to which the session belongs */ 103 TeecContext *context; 104 #ifdef SECURITY_AUTH_ENHANCE 105 /* token_save_len 24byte = token 16byte + timestamp 8byte */ 106 uint8_t teecToken[TOKEN_SAVE_LEN]; 107 #endif 108 } TeecSession; 109 110 /* 111 * @ingroup teec_common_data 112 * teec_sharedmemory 113 * 114 * Describes a piece of shared memory that can be registered or allocated. 115 */ 116 typedef struct { 117 /* Memory pointer */ 118 void *buffer; 119 /* Memory Size */ 120 size_t size; 121 /* Memory flags which is used to distinguish between input and output, range is as follows:#teec_sharedmemctl */ 122 uint32_t flags; 123 /* Number of memory operations */ 124 uint32_t opsCnt; 125 /* Memory allocation identifier, which is used to identify whether the memory is registered or allocated. */ 126 bool isAllocated; 127 /* Linked list header of the shared memory */ 128 struct ListNode head; 129 /* The Tee context to which the object belongs. */ 130 TeecContext *context; 131 } TeecSharedMemory; 132 133 /* 134 * @ingroup teec_common_data 135 * teec_tempmemory_reference 136 * 137 * A temporary buffer is used for #teec_parameter, corresponding to which can be 138 * #teec_memref_temp_input, #teec_memref_temp_output,or #teec_memref_temp_inout 139 */ 140 typedef struct { 141 /* temporary buffer pointer */ 142 void *buffer; 143 /* temporary buffer size */ 144 size_t size; 145 } TeecTempmemoryReference; 146 147 /* 148 * @ingroup teec_common_data 149 * teec_registeredmemory_reference 150 * 151 * Indicates the pointer of the shared memory, which points to the registered or allocated shared memory. 152 * The type that can be used for #teec_parameter, corresponding to which can be 153 * #teec_memref_whole, #teec_memref_partial_input, 154 * #teec_memref_partial_output,or #teec_memref_partial_inout 155 */ 156 typedef struct { 157 /* shared memory pointer */ 158 TeecSharedMemory *parent; 159 /* shared memory size */ 160 size_t size; 161 /* shared memory offset */ 162 size_t offset; 163 } TeecRegisteredmemoryReference; 164 165 /* 166 * @ingroup teec_common_data 167 * teec_value 168 * 169 * Describe a small amount of data 170 * The type that can be used for #teec_parameter, corresponding to which can be 171 * #teec_value_input, #teec_value_output, or #teec_value_inout 172 */ 173 typedef struct { 174 uint32_t a; 175 uint32_t b; 176 } TeecValue; 177 178 /* 179 * @ingroup teec_common_data 180 * teec_parameter 181 * 182 * Parameter type corresponding to #teec_operation. 183 */ 184 typedef union { 185 TeecTempmemoryReference tmpref; 186 TeecRegisteredmemoryReference memref; 187 TeecValue value; 188 } TeecParameter; 189 190 /* 191 * @ingroup teec_common_data 192 * teec_operation 193 * 194 * Parameters used for opening a session or sending a command, 195 * can also be used to cancel an operation 196 */ 197 typedef struct { 198 /* Indicates whether the operation is canceled. 0 indicates canceled. */ 199 uint32_t started; 200 uint32_t paramTypes; 201 TeecParameter params[TEE_PARAM_NUM]; 202 TeecSession *session; 203 bool cancelFlag; 204 } TeecOperation; 205 206 #endif 207