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_DYNAMIC_SRV_H_
17#define _TEE_DYNAMIC_SRV_H_
18
19/**
20 * @addtogroup TeeTrusted
21 * @{
22 *
23 * @brief TEE(Trusted Excution Environment) API.
24 * Provides security capability APIs such as trusted storage, encryption and decryption,
25 * and trusted time for trusted application development.
26 *
27 * @since 12
28 */
29
30/**
31 * @file tee_dynamic_srv.h
32 *
33 * @brief Provides APIs related to dynamic service development.
34 *
35 * @library NA
36 * @kit TEEKit
37 * @syscap SystemCapability.Tee.TeeClient
38 * @since 12
39 * @version 1.0
40 */
41
42#include <pthread.h>
43#include "tee_service_public.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * @brief Defines thread initialization information of the dynamic service.
51 *
52 * @since 12
53 */
54struct srv_thread_init_info {
55    void *(*func)(void *arg);
56    /** The maximum number of parallel threads. */
57    uint32_t max_thread;
58    int32_t shadow;
59    /** The stack size of the thread. */
60    uint32_t stack_size;
61    /** The timeout period for thread (in seconds).*/
62    uint32_t time_out_sec;
63};
64
65typedef void (*srv_dispatch_fn_t)(tee_service_ipc_msg *msg,
66    uint32_t sndr, tee_service_ipc_msg_rsp *rsp);
67
68struct srv_dispatch_t {
69    uint32_t cmd;
70    srv_dispatch_fn_t fn;
71};
72
73/**
74 * @brief Get UUID by sender.
75 *
76 * @param sender [IN] Indicates the sender's task Id.
77 * @param uuid [OUT] Indicates the universally unique identifier.
78 *
79 * @return Returns {@code TEE_SUCCESS} if the operation is successful.
80 *         Returns {@code TEE_ERROR_BAD_PARAMETERS} if the input parameter is incorrect,
81 * or the file name is longer than 64 bytes.
82 *         Returns {@code TEE_ERROR_ITEM_NOT_FOUND} if failed to find the corresponding UUID by sender.
83 *         Returns {@code TEE_ERROR_GENERIC} if failed to obtain the UUID.
84 *
85 * @since 12
86 * @version 1.0
87 */
88TEE_Result tee_srv_get_uuid_by_sender(uint32_t sender, TEE_UUID *uuid);
89
90/**
91 * @brief Releasing the object mapping of a specified address area.
92 *
93 * @param va_addr [IN] Indicates the address of the memory area to be released.
94 * @param size [IN] Indicates the size of the released memory area.
95 *
96 * @since 12
97 * @version 1.0
98 */
99void tee_srv_unmap_from_task(uint32_t va_addr, uint32_t size);
100
101/**
102 * @brief Create a new mapping in the virtual address space of the calling process.
103 *
104 * @param in_task_id [IN] Indicates the task Id.
105 * @param va_addr [IN] Indicates the address of the memory area to be mapped.
106 * @param size [IN] Indicates the size of the memory area to be mapped.
107 * @param virt_addr [OUT] Indicates the new mapping vitural address.
108 *
109 * @return Returns <b>0</b> if the operation is successful.
110 * @return Returns <b>-1</b> if the operation is failed.
111 *
112 * @since 12
113 * @version 1.0
114 */
115int tee_srv_map_from_task(uint32_t in_task_id, uint32_t va_addr, uint32_t size, uint32_t *virt_addr);
116
117/**
118 * @brief Dispatch task by task name.
119  *
120 * @param task_name [IN] Indicates the task name.
121 * @param dispatch [IN] Indicates the dispatch information.
122 * @param n_dispatch [IN] Indicates the dispatch number.
123 * @param cur_thread [IN] Indicates the current thread information.
124 *
125 * @since 12
126 * @version 1.0
127 */
128void tee_srv_cs_server_loop(const char *task_name, const struct srv_dispatch_t *dispatch,
129    uint32_t n_dispatch, struct srv_thread_init_info *cur_thread);
130#ifdef __cplusplus
131}
132#endif
133/** @} */
134#endif
135