• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * teek_client_api.h
3  *
4  * function declaration for libteec interface for kernel CA.
5  *
6  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  */
17 
18 #ifndef TEEK_CLIENT_API_H
19 #define TEEK_CLIENT_API_H
20 #include "teek_ns_client.h"
21 #include "teek_client_type.h"
22 
23 #define TEEC_PARAM_TYPES(param0_type, param1_type, param2_type, param3_type) \
24 		((param3_type) << 12 | (param2_type) << 8 | \
25 		 (param1_type) << 4 | (param0_type))
26 
27 #define TEEC_PARAM_TYPE_GET(param_types, index) \
28 		(((param_types) >> ((index) << 2)) & 0x0F)
29 
30 #define TEEC_VALUE_UNDEF 0xFFFFFFFF
31 
32 int TC_NS_RegisterServiceCallbackFunc(const char *uuid, void *func, const void *private_data);
33 
34 #ifdef CONFIG_KERNEL_CLIENT
35 
36 /*
37  * for history reason, we supply two set interface
38  * first set is uncapitalized and satisfies kernel code rule
39  * second set is capitalized for compatibility
40  */
41 int teek_is_agent_alive(unsigned int agent_id);
42 
43 uint32_t teek_initialize_context(const char *name,
44 	struct teec_context *context);
45 
46 void teek_finalize_context(struct teec_context *context);
47 
48 uint32_t teek_open_session(struct teec_context *context,
49 	struct teec_session *session,
50 	const struct teec_uuid *destination,
51 	uint32_t connection_method,
52 	const void *connection_data,
53 	const struct teec_operation *operation,
54 	uint32_t *return_origin);
55 
56 void teek_close_session(struct teec_session *session);
57 
58 uint32_t teek_send_secfile(struct teec_session *session,
59 	const char *file_buffer, unsigned int file_size);
60 
61 TEEC_Result TEEK_SendSecfile(TEEC_Session *session,
62 	const char *file_buffer, unsigned int file_size);
63 
64 uint32_t teek_invoke_command(struct teec_session *session,
65 	uint32_t cmd_id, struct teec_operation *operation,
66 	uint32_t *return_origin);
67 
68 uint32_t teek_register_shared_memory(struct teec_context *context,
69 	struct teec_sharedmemory *sharedmem);
70 
71 uint32_t teek_allocate_shared_memory(struct teec_context *context,
72 	struct teec_sharedmemory *sharedmem);
73 
74 void teek_release_shared_memory(struct teec_sharedmemory *sharedmem);
75 
76 void teek_request_cancellation(struct teec_operation *operation);
77 
78 int TEEK_IsAgentAlive(unsigned int agent_id);
79 
80 TEEC_Result TEEK_InitializeContext(const char *name, TEEC_Context *context);
81 
82 void TEEK_FinalizeContext(TEEC_Context *context);
83 
84 TEEC_Result TEEK_OpenSession(TEEC_Context *context,
85 	TEEC_Session *session,
86 	const TEEC_UUID *destination,
87 	uint32_t connectionMethod,
88 	const void *connectionData,
89 	TEEC_Operation *operation,
90 	uint32_t *returnOrigin);
91 
92 void TEEK_CloseSession(TEEC_Session *session);
93 
94 TEEC_Result TEEK_InvokeCommand(TEEC_Session *session,
95 	uint32_t commandID,
96 	TEEC_Operation *operation,
97 	uint32_t *returnOrigin);
98 
99 #else
100 
teek_is_agent_alive(unsigned int agent_id)101 static inline int teek_is_agent_alive(unsigned int agent_id)
102 {
103 	return TEEC_SUCCESS;
104 }
105 
TEEK_IsAgentAlive(unsigned int agent_id)106 static inline int TEEK_IsAgentAlive(unsigned int agent_id)
107 {
108 	return TEEC_SUCCESS;
109 }
110 
teek_initialize_context(const char * name,struct teec_context * context)111 static inline uint32_t teek_initialize_context(const char *name,
112 	struct teec_context *context)
113 {
114 	return TEEC_SUCCESS;
115 }
116 
TEEK_InitializeContext(const char * name,TEEC_Context * context)117 static inline TEEC_Result TEEK_InitializeContext(const char *name,
118 	TEEC_Context *context)
119 {
120 	return TEEC_SUCCESS;
121 }
122 
teek_finalize_context(struct teec_context * context)123 static inline void teek_finalize_context(struct teec_context *context)
124 {
125 	(void)context;
126 }
127 
TEEK_FinalizeContext(TEEC_Context * context)128 static inline void TEEK_FinalizeContext(TEEC_Context *context)
129 {
130 	(void)context;
131 }
132 
teek_open_session(struct teec_context * context,struct teec_session * session,const struct teec_uuid * destination,uint32_t connection_method,const void * connection_data,const struct teec_operation * operation,uint32_t * return_origin)133 static inline uint32_t teek_open_session(struct teec_context *context,
134 	struct teec_session *session,
135 	const struct teec_uuid *destination,
136 	uint32_t connection_method,
137 	const void *connection_data,
138 	const struct teec_operation *operation,
139 	uint32_t *return_origin)
140 {
141 	return TEEC_SUCCESS;
142 }
143 
TEEK_OpenSession(TEEC_Context * context,TEEC_Session * session,const TEEC_UUID * destination,uint32_t connectionMethod,const void * connectionData,TEEC_Operation * operation,uint32_t * returnOrigin)144 static inline TEEC_Result TEEK_OpenSession(TEEC_Context *context,
145 	TEEC_Session *session, const TEEC_UUID *destination,
146 	uint32_t connectionMethod, const void *connectionData,
147 	TEEC_Operation *operation, uint32_t *returnOrigin)
148 {
149 	return TEEC_SUCCESS;
150 }
151 
teek_close_session(struct teec_session * session)152 static inline void teek_close_session(struct teec_session *session)
153 {
154 	(void)session;
155 }
156 
TEEK_CloseSession(TEEC_Session * session)157 static inline void TEEK_CloseSession(TEEC_Session *session)
158 {
159 	(void)session;
160 }
161 
teek_invoke_command(struct teec_session * session,uint32_t cmd_id,struct teec_operation * operation,uint32_t * return_origin)162 static inline uint32_t teek_invoke_command(struct teec_session *session,
163 	uint32_t cmd_id, struct teec_operation *operation,
164 	uint32_t *return_origin)
165 {
166 	return TEEC_SUCCESS;
167 }
168 
TEEK_InvokeCommand(TEEC_Session * session,uint32_t commandID,TEEC_Operation * operation,uint32_t * returnOrigin)169 static inline TEEC_Result TEEK_InvokeCommand(TEEC_Session *session,
170 	uint32_t commandID, TEEC_Operation *operation, uint32_t *returnOrigin)
171 {
172 	return TEEC_SUCCESS;
173 }
174 
teek_send_secfile(struct teec_session * session,const char * file_buffer,unsigned int file_size)175 static inline uint32_t teek_send_secfile(struct teec_session *session,
176 	const char *file_buffer, unsigned int file_size)
177 {
178 	return TEEC_SUCCESS;
179 }
180 
181 #endif
182 
183 #endif
184