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_service_public.h 29 * 30 * @brief Provides the TEE service public function for developers. 31 * 32 * @library NA 33 * @kit TEEKit 34 * @syscap SystemCapability.Tee.TeeClient 35 * @since 20 36 */ 37 38 #ifndef _TEE_SERVICE_PUBLIC_H_ 39 #define _TEE_SERVICE_PUBLIC_H_ 40 41 #include "tee_defines.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Defines a function pointer type. 49 * 50 * @since 20 51 */ 52 typedef void (*func_ptr)(void); 53 54 /** 55 * @brief Defines the size of the message queue for the TEE service 56 * 57 * @since 20 58 */ 59 #define TEE_SERVICE_MSG_QUEUE_SIZE 100 60 61 /** 62 * @brief Defines the maximum size of the image hash. 63 * 64 * @since 20 65 */ 66 #define MAX_IMAGE_HASH_SIZE 64 67 68 /** 69 * @brief Defines the arguments of a message. 70 * 71 * @since 20 72 */ 73 typedef struct { 74 /** Argument 0. */ 75 uint64_t arg0; 76 /** Argument 1. */ 77 uint64_t arg1; 78 /** Argument 2. */ 79 uint64_t arg2; 80 /** Argument 3. */ 81 uint64_t arg3; 82 /** Argument 4. */ 83 uint64_t arg4; 84 /** Argument 5. */ 85 uint64_t arg5; 86 /** Argument 6. */ 87 uint64_t arg6; 88 /** Argument 7. */ 89 uint64_t arg7; 90 } args_t; 91 92 /** 93 * @brief Defines the register information of TA. 94 * 95 * @since 20 96 */ 97 struct reg_ta_info { 98 /** TA's task ID. */ 99 uint32_t taskid; 100 /** TA's UUID (Universally Unique Identifier). */ 101 TEE_UUID uuid; 102 /** User ID. */ 103 uint32_t userid; 104 /** Used only for SSA; other tasks should ignore this field. */ 105 bool ssa_enum_enable; 106 }; 107 108 /** 109 * @brief Defines the IPC message of TEE service. 110 * 111 * @since 20 112 */ 113 typedef union { 114 /** Parameter data. */ 115 args_t args_data; 116 /** TA's registration information. */ 117 struct reg_ta_info reg_ta; 118 } tee_service_ipc_msg; 119 120 /** 121 * @brief Defines the IPC request message of TEE service. 122 * 123 * @since 20 124 */ 125 struct tee_service_ipc_msg_req { 126 /** Command identifier for the request. */ 127 uint32_t cmd; 128 /** IPC message carried by the request. */ 129 tee_service_ipc_msg msg; 130 }; 131 132 /** 133 * @brief Defines the IPC response message of TEE service. 134 * 135 * @since 20 136 */ 137 typedef struct { 138 /** Return result of the request. */ 139 TEE_Result ret; 140 /** IPC message carried by the response. */ 141 tee_service_ipc_msg msg; 142 } tee_service_ipc_msg_rsp; 143 144 /** 145 * @brief Defines the message of the TEE service. 146 * 147 * @since 20 148 */ 149 typedef struct { 150 /** Message ID, a unique identifier for the message. */ 151 uint32_t msg_id; 152 /** Sender ID of the message. */ 153 uint32_t sender; 154 /** Message data. */ 155 tee_service_ipc_msg msg; 156 } tee_service_msg_t; 157 158 /** 159 * @brief Defines the message queue for the TEE service. 160 * 161 * @since 20 162 */ 163 typedef struct { 164 /** Pointer to the input position of the queue. */ 165 uint32_t in; 166 /** Pointer to the output position of the queue. */ 167 uint32_t out; 168 /** Array of messages, storing the messages in the queue. */ 169 tee_service_msg_t msg[TEE_SERVICE_MSG_QUEUE_SIZE]; 170 } tee_service_msg_queue_t; 171 172 /** 173 * @brief Provides to send IPC synchronization messages to a specified service 174 * and receive responses from the service. 175 * 176 * @param task_name Indicates the task name of recipient. 177 * @param snd_cmd Indicates the command ID of the send message. 178 * @param snd_msg Indicates the send message. 179 * @param ack_cmd Indicates the ID of the ack cmd to be received. 180 * @param rsp_msg Indicates the service response message. 181 * 182 * @since 20 183 */ 184 void tee_common_ipc_proc_cmd(const char *task_name, 185 uint32_t snd_cmd, const tee_service_ipc_msg *snd_msg, 186 uint32_t ack_cmd, tee_service_ipc_msg_rsp *rsp_msg); 187 188 #ifdef __cplusplus 189 } 190 #endif 191 192 #endif 193 /** @} */