• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXT_API_H
17 #define TEE_EXT_API_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_ext_api.h
32  *
33  * @brief Provides extended interfaces.
34  *
35  * @library NA
36  * @kit TEE Kit
37  * @syscap SystemCapability.Tee.TeeClient
38  * @since 12
39  * @version 1.0
40  */
41 
42 #include "tee_defines.h"
43 #include "tee_hw_ext_api.h"
44 
45 #ifdef __cplusplus
46 #if __cplusplus
47 extern "C" {
48 #endif /* __cpluscplus */
49 #endif /* __cpluscplus */
50 
51 /**
52  * @brief Defines the value of invalid user ID.
53  *
54  * @since 12
55  */
56 #define INVALID_USERID 0xFFFFFFFU
57 
58 /**
59  * @brief Defines the SMC from user mode.
60  *
61  * @since 12
62  */
63 #define TEE_SMC_FROM_USR 0
64 
65 /**
66  * @brief Defines the SMC from kernel mode.
67  *
68  * @since 12
69  */
70 #define TEE_SMC_FROM_KERNEL 1
71 
72 /**
73  * @brief Defines the szie of reserved buffer.
74  *
75  * @since 12
76  */
77 #define RESERVED_BUF_SIZE 32
78 
79 /**
80  * @brief Defines the caller information.
81  *
82  * @since 12
83  */
84 typedef struct ta_caller_info {
85     uint32_t session_type;
86     union {
87         struct {
88             TEE_UUID caller_uuid;
89             uint32_t group_id;
90         };
91         uint8_t ca_info[RESERVED_BUF_SIZE];
92     } caller_identity;
93     uint8_t smc_from_kernel_mode;
94     uint8_t reserved[RESERVED_BUF_SIZE - 1];
95 } caller_info;
96 
97 /**
98  * @brief Get caller info of current session, refer caller_info struct for more details.
99  *
100  * @param ca_name Indicates the process name of the caller of the CA.
101  * @param ca_uid Indicates the UID of the caller.
102  *
103  * @return Returns <b>TEE_SUCCESS</b> if the operation is successful.
104  * @return Returns other information otherwise.
105  *
106  * @since 12
107  * @version 1.0
108  */
109 TEE_Result tee_ext_get_caller_info(caller_info *caller_info_data, uint32_t length);
110 
111 /**
112  * @brief Get user ID of current TA.
113  *
114  * @param user_id Indicates the user ID to be returned.
115  *
116  * @return Returns <b>TEE_SUCCESS</b> if the operation is successful.
117  * @return Returns other information otherwise.
118  *
119  * @since 12
120  * @version 1.0
121  */
122 TEE_Result tee_ext_get_caller_userid(uint32_t *user_id);
123 
124 /**
125  * @brief Adds information about a caller that can invoke this TA.
126  * This API applies to the client applications (CAs) in the binary executable file format.
127  *
128  * @param ca_name Indicates the process name of the caller of the CA.
129  * @param ca_uid Indicates the UID of the caller.
130  *
131  * @return Returns <b>TEE_SUCCESS</b> if the operation is successful.
132  * @return Returns other information otherwise.
133  *
134  * @since 12
135  * @version 1.0
136  */
137 TEE_Result AddCaller_CA_exec(const char *ca_name, uint32_t ca_uid);
138 
139 /**
140  * @brief Adds information about a caller that can invoke this TA.
141  * This API applies to the client applications (CAs) in the native CA and HAP format.
142  *
143  * @param cainfo_hash Indicates the hash value of the CA caller information.
144  * @param length Indicates the length of the hash value.
145  *
146  * @return Returns <b>TEE_SUCCESS</b> if the operation is successful.
147  * @return Returns other information otherwise.
148  *
149  * @since 12
150  * @version 1.0
151  */
152 TEE_Result AddCaller_CA(const uint8_t *cainfo_hash, uint32_t length);
153 
154 /**
155  * @brief TA call this API allow others TA open session with itself.
156  *
157  * @return Returns <b>TEE_SUCCESS</b> if the operation is successful.
158  * @return Returns other information otherwise.
159   *
160  * @since 12
161  * @version 1.0
162  */
163 TEE_Result AddCaller_TA_all(void);
164 
165 /**
166  * @brief Defines the session caller from CA.
167  *
168  * @since 12
169  */
170 #define SESSION_FROM_CA   0
171 
172 /**
173  * @brief Defines the session caller from TA.
174  *
175  * @since 12
176  */
177 #define SESSION_FROM_TA   1
178 
179 /**
180  * @brief Defines the TA task is not found, for example, from TA sub thread.
181  *
182  * @since 12
183  */
184 #define SESSION_FROM_NOT_SUPPORTED   0xFE
185 
186 /**
187  * @brief Defines the TA caller is not found.
188  *
189  * @since 12
190  */
191 #define SESSION_FROM_UNKNOWN   0xFF
192 
193 /**
194  * @brief Obtains the session type.
195  *
196  * @return Returns the session type obtained.
197   *
198  * @since 12
199  * @version 1.0
200  */
201 uint32_t tee_get_session_type(void);
202 
203 #ifdef __cplusplus
204 #if __cplusplus
205 }
206 #endif /* __cpluscplus */
207 #endif /* __cpluscplus */
208 
209 #endif
210