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_dynamic_srv.h 29 * 30 * @brief Provides APIs related to dynamic service development. 31 * 32 * @library NA 33 * @kit TEEKit 34 * @syscap SystemCapability.Tee.TeeClient 35 * @since 20 36 */ 37 38 #ifndef _TEE_DYNAMIC_SRV_H_ 39 #define _TEE_DYNAMIC_SRV_H_ 40 41 #include <pthread.h> 42 #include "tee_service_public.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /** 49 * @brief Defines a structure for service thread initialize informations. 50 * 51 * @since 20 52 */ 53 struct srv_thread_init_info { 54 /** Function pointer to the thread function. */ 55 void *(*func)(void *arg); 56 /** The maximum number of parallel threads. */ 57 uint32_t max_thread; 58 /** Shadow parameter, its purpose depends on the implementation. */ 59 int32_t shadow; 60 /** The stack size of the thread. */ 61 uint32_t stack_size; 62 /** The timeout period for the thread (in seconds). */ 63 uint32_t time_out_sec; 64 }; 65 66 /** 67 * @brief Defines a function pointer type for service dispatch function. 68 * 69 * @param msg A pointer to the IPC message to be processed. 70 * @param sndr The sender of the IPC message. 71 * @param rsp A pointer to the IPC response message. 72 * 73 * @since 20 74 */ 75 typedef void (*srv_dispatch_fn_t)(tee_service_ipc_msg *msg, 76 uint32_t sndr, tee_service_ipc_msg_rsp *rsp); 77 78 /** 79 * @brief Defines a structure for service dispatch information. 80 * 81 * @since 20 82 */ 83 struct srv_dispatch_t { 84 /** The command associated with the dispatch. */ 85 uint32_t cmd; 86 /** Function pointer for the dispatch handler. */ 87 srv_dispatch_fn_t fn; 88 }; 89 90 /** 91 * @brief Get UUID by sender. 92 * 93 * @param sender [IN] Indicates the sender's task Id. 94 * @param uuid [OUT] Indicates the universally unique identifier. 95 * 96 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 97 * Returns {@code TEE_ERROR_BAD_PARAMETERS} if the input parameter is incorrect, 98 * or the file name is longer than 64 bytes. 99 * Returns {@code TEE_ERROR_ITEM_NOT_FOUND} if failed to find the corresponding UUID by sender. 100 * Returns {@code TEE_ERROR_GENERIC} if failed to obtain the UUID. 101 * 102 * @since 20 103 */ 104 TEE_Result tee_srv_get_uuid_by_sender(uint32_t sender, TEE_UUID *uuid); 105 106 /** 107 * @brief Releasing the object mapping of a specified address area. 108 * 109 * @param va_addr [IN] Indicates the address of the memory area to be released. 110 * @param size [IN] Indicates the size of the released memory area. 111 * 112 * @since 20 113 */ 114 void tee_srv_unmap_from_task(uint32_t va_addr, uint32_t size); 115 116 /** 117 * @brief Create a new mapping in the virtual address space of the calling process. 118 * 119 * @param in_task_id [IN] Indicates the task Id. 120 * @param va_addr [IN] Indicates the address of the memory area to be mapped. 121 * @param size [IN] Indicates the size of the memory area to be mapped. 122 * @param virt_addr [OUT] Indicates the new mapping vitural address. 123 * 124 * @return Returns <b>0</b> if the operation is successful. 125 * @return Returns <b>-1</b> if the operation is failed. 126 * 127 * @since 20 128 */ 129 int tee_srv_map_from_task(uint32_t in_task_id, uint32_t va_addr, uint32_t size, uint32_t *virt_addr); 130 131 /** 132 * @brief Dispatch task by task name. 133 * 134 * @param task_name [IN] Indicates the task name. 135 * @param dispatch [IN] Indicates the dispatch information. 136 * @param n_dispatch [IN] Indicates the dispatch number. 137 * @param cur_thread [IN] Indicates the current thread information. 138 * 139 * @since 20 140 */ 141 void tee_srv_cs_server_loop(const char *task_name, const struct srv_dispatch_t *dispatch, 142 uint32_t n_dispatch, struct srv_thread_init_info *cur_thread); 143 144 #ifdef __cplusplus 145 } 146 #endif 147 148 #endif 149 /** @} */