blob: 0bfcb9bdabc94775958fdb999a9cc7cc3782f48e [file] [log] [blame]
Dinesh K Garg02ab8bf2015-08-17 15:53:33 -07001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <partition_parser.h>
30#include <qseecom_lk.h>
31#include <scm.h>
32
33//#include "qseecom_legacy.h"
34#include "qseecom_lk_api.h"
35#include <debug.h>
36#include <kernel/mutex.h>
37#include <malloc.h>
38#include <stdlib.h>
39#include <arch/defines.h>
40#include <string.h>
41
42/* commands supported from sample client */
43#define CLIENT_CMD0_GET_VERSION 0
44#define CLIENT_CMD1_BASIC_DATA 1
45#define CLIENT_CMD2_REGISTER_SB_PTR 2
46#define CLIENT_CMD3_RUN_CRYTPO_TEST 3
47#define CLIENT_CMD4_RUN_CRYTPO_PERF 4
48#define CLIENT_CMD5_RUN_SFS_TEST 5
49#define CLIENT_CMD6_RUN_BUF_ALIGNMENT_TEST 6
50#define CLIENT_CMD7_RUN_CRYPTO_RSA_TEST 7
51#define CLIENT_CMD8_RUN_RSA_PERF_TEST 8
52#define CLIENT_CMD9_RUN_CMNLIB_TEST 9
53#define CLIENT_CMD10_RUN_CORE_TEST 10
54#define CLIENT_CMD11_RUN_SECURECHANNEL_TEST 11
55#define CLIENT_CMD12_RUN_SERVICES_TEST 12
56#define CLIENT_CMD13_RUN_MISC_TEST 13
57#define CLIENT_CMD17_RUN_STORAGE_TEST 17
58#define CLIENT_APPSBL_QSEECOM_RUN_LISTENER_FRAMEWORK_TEST_1 50
59
60#define __64KB__ 0x10000
61#define __32KB__ 0x8000
62#define __16KB__ 0x4000
63#define __8KB__ 0x2000
64#define __4KB__ 0x1000
65#define __2KB__ 0x800
66#define __1KB__ 0x400
67
68#define LISTENER_TEST_SERVICE 0x100
69
70struct qsc_send_cmd {
71 unsigned int cmd_id;
72 unsigned int data;
73 unsigned int data2;
74 unsigned int len;
75 unsigned int start_pkt;
76 unsigned int end_pkt;
77 unsigned int test_buf_size;
78};
79
80struct qsc_send_cmd_rsp {
81 unsigned int data;
82 int status;
83};
84
85
86int listener_test_cmd_handler (void* buf, uint32_t size)
87{
88 uint32 *req = 0;
89 uint32 rsp = 0;
90
91 if ((!buf) || (size < 4)) {
92 dprintf(CRITICAL, "Invalid listener cmd handler inputs\n");
93 return -1;
94 }
95
96 req = (uint32 *)buf;
97 if (*req == (100 * 100)) {
98 dprintf(CRITICAL, "Listener Success\n");
99 rsp = *req * 100;
100 dprintf(CRITICAL, "rsp = %u\n", rsp);
101 memcpy (buf, &rsp, sizeof(uint32));
102 return 0;
103 } else {
104 dprintf(CRITICAL, "Listener Failure, req:%u\n", *req);
105 rsp = 0;
106 memcpy (buf, &rsp, sizeof(uint32));
107 return 0;
108 }
109}
110
111static struct qseecom_listener_services listeners[] = {
112 {
113 .service_name = "Listener Test service",
114 .id = LISTENER_TEST_SERVICE,
115 .sb_size = (20 * 1024),
116 .service_cmd_handler = listener_test_cmd_handler,
117 },
118};
119
120int qsc_run_get_version(char *appname, uint32_t iterations)
121{
122 struct qsc_send_cmd send_cmd;
123 struct qsc_send_cmd_rsp msgrsp={0}; /* response data sent from QSEE */
124 uint32_t i = 0, ret = 0, err = -1;
125
126 dprintf(CRITICAL, "%s:Get_version\n", __func__);
127
128 dprintf(CRITICAL, "(This may take a few minutes please wait....)\n");
129 /* Start the application */
130 for (i = 0; i < iterations; i++) {
131 dprintf(CRITICAL, "iteration %d\n", i);
132 ret = qseecom_start_app(appname);
133 if (ret <= 0) {
134 dprintf(CRITICAL, "Start app: fail: ret:%d\n", ret);
135 err = -1;
136 goto err_ret;
137 }
138 dprintf(CRITICAL, "apphandle %u\n", ret);
139 ret = qseecom_start_app(appname);
140 if (ret <= 0) {
141 dprintf(CRITICAL, "Start app: fail: ret:%d\n", ret);
142 err = -1;
143 goto err_ret_shutdown;
144 }
145 dprintf(CRITICAL, "apphandle %u\n", ret);
146 send_cmd.cmd_id = CLIENT_CMD0_GET_VERSION;
147 err = qseecom_send_command(ret, &send_cmd, sizeof(struct qsc_send_cmd), &msgrsp, sizeof(struct qsc_send_cmd_rsp));
148 if (err) {
149 dprintf(CRITICAL, "Send app: fail\n");
150 goto err_ret_shutdown;
151 }
152 dprintf(ALWAYS, "The version of %s is: %u\n", appname, msgrsp.data);
153 /* Shutdown the application */
154 dprintf(ALWAYS, "Shutting down %s\n", appname);
155 err = qseecom_shutdown_app(ret);
156 if (err) {
157 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
158 goto err_ret;
159 }
160 dprintf(ALWAYS, "Shutting down %s\n", appname);
161 err = qseecom_shutdown_app(ret);
162 if (err) {
163 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
164 goto err_ret;
165 }
166
167 }
168err_ret_shutdown:
169 if (err) {
170 if (qseecom_shutdown_app(ret))
171 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
172 }
173err_ret:
174 if (err)
175 dprintf(CRITICAL, "Test %u failed with error %d, shutting down %s\n", CLIENT_CMD0_GET_VERSION, err, appname);
176 else
177 dprintf(CRITICAL, "Test %u passed for iterations %u executing %s\n", CLIENT_CMD0_GET_VERSION, iterations, appname);
178 return err;
179}
180
181
182int qsc_run_start_stop_app_basic_test(char *appname, uint32_t iterations)
183{
184 uint32_t i = 0;
185 int ret = 0; /* return value */
186 int err = 0; /* return value */
187 struct qsc_send_cmd send_cmd = {0};
188 struct qsc_send_cmd_rsp msgrsp={0}; /* response data sent from QSEE */
189
190 dprintf(CRITICAL, "%s:Basic_start_stop_test\n", __func__);
191
192 dprintf(CRITICAL, "(This may take a few minutes please wait....)\n");
193 /* Start the application */
194 for (i = 0; i < iterations; i++) {
195 dprintf(CRITICAL, "iteration %d\n", i);
196 ret = qseecom_start_app(appname);
197 if (ret <= 0) {
198 dprintf(CRITICAL, "Start app: fail: ret:%d\n", ret);
199 err = -1;
200 goto err_ret;
201 }
202 /* Send data using send command to QSEE application */
203 send_cmd.cmd_id = CLIENT_CMD1_BASIC_DATA;
204 send_cmd.start_pkt = 0;
205 send_cmd.end_pkt = 0;
206 send_cmd.test_buf_size = 0;
207 send_cmd.data = 100;
208 err = qseecom_send_command(ret, &send_cmd, sizeof(struct qsc_send_cmd), &msgrsp, sizeof(struct qsc_send_cmd_rsp));
209 if (err) {
210 dprintf(CRITICAL, "Send app: fail\n");
211 goto err_ret_shutdown;
212 }
213 if (((msgrsp.data)/100) != 10) {
214 dprintf(CRITICAL, "App Comm Error:%u\n", msgrsp.data);
215 err = -1;
216 goto err_ret_shutdown;
217 }
218 dprintf(CRITICAL, "msg.rsp:%u\n", msgrsp.data);
219 /* Shutdown the application */
220 err = qseecom_shutdown_app(ret);
221 if (err) {
222 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
223 goto err_ret;
224 }
225 }
226err_ret_shutdown:
227 if (err) {
228 if (qseecom_shutdown_app(ret))
229 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
230 }
231err_ret:
232 if (err)
233 dprintf(CRITICAL, "Test %u failed with error %d, shutting down %s\n", CLIENT_CMD0_GET_VERSION, err, appname);
234 else
235 dprintf(CRITICAL, "Test %u passed for iterations %u executing %s\n", CLIENT_CMD0_GET_VERSION, iterations, appname);
236 return err;
237}
238
239
240
241int qsc_run_start_stop_app_listener_test(char *appname, uint32_t iterations)
242{
243 uint32_t i = 0;
244 int ret = 0; /* return value */
245 int err = 0; /* return value */
246 struct qsc_send_cmd send_cmd;
247 struct qsc_send_cmd_rsp msgrsp={0}; /* response data sent from QSEE */
248
249 dprintf(CRITICAL, "%s:qsc_run_start_stop_app_listener_test\n", __func__);
250
251 dprintf(CRITICAL, "(This may take a few minutes please wait....)\n");
252
253 ret = qseecom_register_listener(&listeners[0]);
254 if (ret < 0) {
255 dprintf(CRITICAL, "Reg Listener: fail: ret:%d\n", ret);
256 err = -1;
257 goto err_ret;
258 }
259 /* Start the application */
260 for (i = 0; i < iterations; i++) {
261 dprintf(CRITICAL, "iteration %d\n", i);
262 ret = qseecom_start_app(appname);
263 if (ret <= 0) {
264 dprintf(CRITICAL, "Start app: fail: ret:%d\n", ret);
265 err = -1;
266 goto err_dereg;
267 }
268 /* Send data using send command to QSEE application */
269 send_cmd.cmd_id = CLIENT_APPSBL_QSEECOM_RUN_LISTENER_FRAMEWORK_TEST_1;
270 send_cmd.start_pkt = 0;
271 send_cmd.end_pkt = 0;
272 send_cmd.test_buf_size = 0;
273 send_cmd.data = 100;
274 err = qseecom_send_command(ret, &send_cmd, sizeof(struct qsc_send_cmd), &msgrsp, sizeof(struct qsc_send_cmd_rsp));
275 if (err) {
276 dprintf(CRITICAL, "Send app: fail\n");
277 goto err_ret_shutdown;
278 }
279 if (((msgrsp.data)/100) != 10) {
280 dprintf(CRITICAL, "App Comm Error:%u Status:%d\n", msgrsp.data, msgrsp.status);
281 err = -1;
282 goto err_ret_shutdown;
283 }
284 /* Shutdown the application */
285 err = qseecom_shutdown_app(ret);
286 if (err) {
287 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
288 goto err_dereg;
289 }
290 }
291
292err_ret_shutdown:
293 if (err) {
294 if (qseecom_shutdown_app(ret))
295 dprintf(CRITICAL, "Failed to shutdown app: %d\n",err);
296 }
297err_dereg:
298 ret = qseecom_deregister_listener(listeners[0].id);
299 if (ret < 0) {
300 dprintf(CRITICAL, "DeReg Listener: fail: ret:%d\n", ret);
301 err = -1;
302 }
303err_ret:
304 if (err)
305 dprintf(CRITICAL, "Test %u failed with error %d, shutting down %s\n", CLIENT_CMD0_GET_VERSION, err, appname);
306 else
307 dprintf(CRITICAL, "Test %u passed for iterations %u executing %s\n", CLIENT_CMD0_GET_VERSION, iterations, appname);
308 return err;
309}
310
311int qseecom_test_cmd_handler(const char *arg) {
312 char *token = NULL;
313 char * appname = NULL;
314 uint32_t test = 0;
315 uint32_t iterations = 0;
316
317 token = strtok((char *)arg, " ");
318 if (!token) {
319 dprintf(CRITICAL, "Appname not provided, error\n");
320 return -1;
321 }
322 appname = token;
323
324 token = strtok(NULL, " ");
325 if (!token) {
326 dprintf(CRITICAL, "Test not provided, error\n");
327 return -1;
328 }
329 test = atoi(token);
330
331 token = strtok(NULL, " ");
332 if (token)
333 iterations = atoi(token);
334 else
335 dprintf(CRITICAL, "iterations not provided\n");
336
337 switch (test) {
338 case CLIENT_CMD0_GET_VERSION:
339 {
340 qsc_run_get_version(appname, iterations);
341 break;
342 }
343 case CLIENT_CMD1_BASIC_DATA:
344 {
345 qsc_run_start_stop_app_basic_test(appname, iterations);
346 break;
347 }
348
349 case CLIENT_APPSBL_QSEECOM_RUN_LISTENER_FRAMEWORK_TEST_1:
350 {
351 qsc_run_start_stop_app_listener_test(appname, iterations);
352 break;
353 }
354 }
355 dprintf(CRITICAL, "test:%u iterations:%u\n", test, iterations);
356 return 0;
357}
358