-
Notifications
You must be signed in to change notification settings - Fork 1
/
QSEEComAPI.h
299 lines (273 loc) · 10.5 KB
/
QSEEComAPI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* Copyright (c) 2012, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#ifndef __QSEECOMAPI_H_
#define __QSEECOMAPI_H_
/*----------------------------------------------------------------------------
* Include Files
* -------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#define QSEECOM_ALIGN_SIZE 0x40
#define QSEECOM_ALIGN_MASK (QSEECOM_ALIGN_SIZE - 1)
#define QSEECOM_ALIGN(x) \
((x + QSEECOM_ALIGN_SIZE) & (~QSEECOM_ALIGN_MASK))
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------
* Preprocessor Definitions and Constants
* -------------------------------------------------------------------------*/
/** The memory is locked and non-pageable */
#define MEM_LOCKED 0x00000001
/** The memory is marked non-cacheable */
#define MEM_NON_CACHED 0x00000002
#define QSEECOM_APP_QUERY_FAILED -6
#define QSEECOM_APP_NOT_LOADED -5
#define QSEECOM_APP_ALREADY_LOADED -4
#define QSEECOM_LISTENER_UNREGISTERED -3
#define QSEECOM_LISTENER_ALREADY_REGISTERED -2
#define QSEECOM_LISTENER_REGISTER_FAIL -1
/*----------------------------------------------------------------------------
* Type Declarations
* -------------------------------------------------------------------------*/
struct QSEECom_handle {
unsigned char *ion_sbuffer;
};
struct QSEECom_ion_fd_data {
int32_t fd;
uint32_t cmd_buf_offset;
};
struct QSEECom_ion_fd_info {
struct QSEECom_ion_fd_data data[4];
};
/*----------------------------------------------------------------------------
* Function Declarations and Documentation
* -------------------------------------------------------------------------*/
/**
* @brief Open a handle to the QSEECom device.
*
* - Load a secure application. The application will be verified that it is
* secure by digital signature verification.
* Allocate memory for sending requests to the QSAPP
*
* Note/Comments:
* There is a one-to-one relation for a HLOS client and a QSAPP;
* meaning that only one app can communicate to a QSAPP at a time.
*
* Please note that there is difference between an application and a listener
* service. A QSAPP must be loaded at the request of the HLOS,
* and all requests are orginated by the HLOS client.
* A listener service on the otherhand is started during start-up by a
* daemon, qseecomd.
*
* A HLOS application may create mutiple handles to the QSAPP
*
* @param[in/out] handle The device handle
* @param[in] fname The directory and filename to load.
* @param[in] sb_size Size of the shared buffer memory for sending requests.
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_start_app(struct QSEECom_handle **clnt_handle, const char *path,
const char *fname, uint32_t sb_size);
/**
* @brief Close the application associated with the handle.
*
* - Unload a secure application. The driver will verify if there exists
* any other applications that are communicating with the QSAPP to which
* the "handle" is tied.
* - De-allocate memory for sending requests to QSAPP.
*
* @param[in] handle The device handle
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_shutdown_app(struct QSEECom_handle **handle);
/**
* @brief Open a handle to the QSEECom device.
*
* - Load an external elf. The elf will be verified that it is
* secure by digital signature verification.
*
* A HLOS application may create mutiple opens (only one is permitted for the
* app, but each listener service can open a unique device in the same HLOS app
* /executable.
* @param[in/out] handle The device handle
* @param[in] fname The directory and filename to load.
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_load_external_elf(struct QSEECom_handle **clnt_handle, const char *path,
const char *fname);
/**
* @brief Close the external elf
*
* - Unload an external elf.
*
* @param[in] handle The device handle
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_unload_external_elf(struct QSEECom_handle **handle);
/**
* @brief Register an HLOS listener service. This allows messages from QSAPP
* to be received.
*
* @param[in] handle The device handle
* @param[in] lstnr_id The listener service identifier. This ID must be uniquely
* assigned to avoid any collisions.
* @param[in] sb_length Shared memory buffer between OS and QSE.
* @param[in] flags Provide the shared memory flags attributes.
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*
*/
int QSEECom_register_listener(struct QSEECom_handle **handle,
uint32_t lstnr_id, uint32_t sb_length, uint32_t flags);
/**
* @brief Unregister a listener service.
*
* @param[in] handle The device handle
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_unregister_listener(struct QSEECom_handle *handle);
/**
* @brief Send QSAPP a "user" defined buffer (may contain some message/
* command request) and receives a response from QSAPP in receive buffer.
* The HLOS client writes to the send_buf, where QSAPP writes to the rcv_buf.
* This is a blocking call.
*
* @param[in] handle The device handle
* @param[in] send_buf The buffer to be sent.
* If using ion_sbuffer, ensure this
* QSEECOM_BUFFER_ALIGN'ed.
* @param[in] sbuf_len The send buffer length
* If using ion_sbuffer, ensure length is
* multiple of QSEECOM_BUFFER_ALIGN.
* @param[in] rcv_buf The QSEOS returned buffer.
* If using ion_sbuffer, ensure this is
* QSEECOM_BUFFER_ALIGN'ed.
* @param[in] rbuf_len The returned buffer length.
* If using ion_sbuffer, ensure length is
* multiple of QSEECOM_BUFFER_ALIGN.
* @param[in] rbuf_len The returned buffer length.
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_send_cmd(struct QSEECom_handle *handle, void *send_buf,
uint32_t sbuf_len, void *rcv_buf, uint32_t rbuf_len);
/**
* @brief Send QSAPP a "user" defined buffer (may contain some message/
* command request) and receives a response from QSAPP in receive buffer.
* This API is same as send_cmd except it takes in addition parameter,
* "ifd_data". This "ifd_data" holds information (ion fd handle and
* cmd_buf_offset) used for modifying data in the message in send_buf
* at an offset. Essentailly, it has the ion fd handle information to
* retrieve physical address and modify the message in send_buf at the
* mentioned offset.
*
* The HLOS client writes to the send_buf, where QSAPP writes to the rcv_buf.
* This is a blocking call.
*
* @param[in] handle The device handle
* @param[in] send_buf The buffer to be sent.
* If using ion_sbuffer, ensure this
* QSEECOM_BUFFER_ALIGN'ed.
* @param[in] sbuf_len The send buffer length
* If using ion_sbuffer, ensure length is
* multiple of QSEECOM_BUFFER_ALIGN.
* @param[in] rcv_buf The QSEOS returned buffer.
* If using ion_sbuffer, ensure this is
* QSEECOM_BUFFER_ALIGN'ed.
* @param[in] rbuf_len The returned buffer length.
* If using ion_sbuffer, ensure length is
* multiple of QSEECOM_BUFFER_ALIGN.
* @param[in] QSEECom_ion_fd_info data related to memory allocated by ion.
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_send_modified_cmd(struct QSEECom_handle *handle, void *send_buf,
uint32_t sbuf_len, void *resp_buf, uint32_t rbuf_len,
struct QSEECom_ion_fd_info *ifd_data);
/**
* @brief Receive a service defined buffer.
*
* @param[in] handle The device handle
* @param[out] buf The buffer that is received
* @param[in] len The receive buffer length
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_receive_req(struct QSEECom_handle *handle,
void *buf, uint32_t len);
/**
* @brief Send a response based on the previous QSEECom_receive_req.
*
* This allows a listener service to receive a command (e.g. read file abc).
* The service can then handle the request from QSEECom_receive_req, and provide
* that information back to QSAPP.
*
* This allows the HLOS to act as the server and QSAPP to behave as the client.
*
* @param[in] handle The device handle
* @param[out] send_buf The buffer to be returned back to QSAPP
* @param[in] len The send buffer length
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_send_resp(struct QSEECom_handle *handle,
void *send_buf, uint32_t len);
/**
* @brief Set the bandwidth for QSEE.
*
* This API resulst in improving the performance on the Crypto hardware
* in QSEE. It should be called before issuing send_cmd/send_modified_cmd
* for commands that requires using the crypto hardware on the QSEE.
* Typically this API should be called before issuing the send request to
* enable high performance mode and after completion of the send_cmd to
* resume to low performance and hence to low power mode.
*
* This allows the clients of QSEECom to set the QSEE cyptpo HW bus
* bandwidth to high/low.
*
* @param[in] high Set to 1 to enable bandwidth.
*
* @return Zero on success, negative on failure. errno will be set on
* error.
*/
int QSEECom_set_bandwidth(struct QSEECom_handle *handle, bool high);
/**
* @brief Query QSEE to check if app is loaded.
*
* This API queries QSEE to see if the app is loaded or not.
*
* @param[in] app_name Name of the app.
*
* @return QSEECOM_APP_QUERY_FAILED/QSEECOM_APP_NOT_LOADED/QSEECOM_APP_LOADED.
*/
int QSEECom_app_load_query(struct QSEECom_handle *handle, char *app_name);
#ifdef __cplusplus
}
#endif
#endif