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
32int 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 */
41int teek_is_agent_alive(unsigned int agent_id);
42
43uint32_t teek_initialize_context(const char *name,
44	struct teec_context *context);
45
46void teek_finalize_context(struct teec_context *context);
47
48uint32_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
56void teek_close_session(struct teec_session *session);
57
58uint32_t teek_send_secfile(struct teec_session *session,
59	const char *file_buffer, unsigned int file_size);
60
61TEEC_Result TEEK_SendSecfile(TEEC_Session *session,
62	const char *file_buffer, unsigned int file_size);
63
64uint32_t teek_invoke_command(struct teec_session *session,
65	uint32_t cmd_id, struct teec_operation *operation,
66	uint32_t *return_origin);
67
68uint32_t teek_register_shared_memory(struct teec_context *context,
69	struct teec_sharedmemory *sharedmem);
70
71uint32_t teek_allocate_shared_memory(struct teec_context *context,
72	struct teec_sharedmemory *sharedmem);
73
74void teek_release_shared_memory(struct teec_sharedmemory *sharedmem);
75
76void teek_request_cancellation(struct teec_operation *operation);
77
78int TEEK_IsAgentAlive(unsigned int agent_id);
79
80TEEC_Result TEEK_InitializeContext(const char *name, TEEC_Context *context);
81
82void TEEK_FinalizeContext(TEEC_Context *context);
83
84TEEC_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
92void TEEK_CloseSession(TEEC_Session *session);
93
94TEEC_Result TEEK_InvokeCommand(TEEC_Session *session,
95	uint32_t commandID,
96	TEEC_Operation *operation,
97	uint32_t *returnOrigin);
98
99#else
100
101static inline int teek_is_agent_alive(unsigned int agent_id)
102{
103	return TEEC_SUCCESS;
104}
105
106static inline int TEEK_IsAgentAlive(unsigned int agent_id)
107{
108	return TEEC_SUCCESS;
109}
110
111static inline uint32_t teek_initialize_context(const char *name,
112	struct teec_context *context)
113{
114	return TEEC_SUCCESS;
115}
116
117static inline TEEC_Result TEEK_InitializeContext(const char *name,
118	TEEC_Context *context)
119{
120	return TEEC_SUCCESS;
121}
122
123static inline void teek_finalize_context(struct teec_context *context)
124{
125	(void)context;
126}
127
128static inline void TEEK_FinalizeContext(TEEC_Context *context)
129{
130	(void)context;
131}
132
133static 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
144static 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
152static inline void teek_close_session(struct teec_session *session)
153{
154	(void)session;
155}
156
157static inline void TEEK_CloseSession(TEEC_Session *session)
158{
159	(void)session;
160}
161
162static 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
169static 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
175static 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