Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, STMicroelectronics International N.V. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <string.h> |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame^] | 16 | #include <limits.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 17 | |
| 18 | #ifdef USER_SPACE |
| 19 | #include <pthread.h> |
| 20 | #include <unistd.h> |
| 21 | #endif |
| 22 | |
| 23 | #include "xtest_test.h" |
| 24 | #include "xtest_helpers.h" |
| 25 | |
| 26 | #include <ta_crypt.h> |
| 27 | #include <ta_os_test.h> |
| 28 | #include <ta_create_fail_test.h> |
| 29 | #include <ta_rpc_test.h> |
| 30 | #include <ta_sims_test.h> |
| 31 | |
| 32 | static void xtest_tee_test_1001(ADBG_Case_t *Case_p); |
| 33 | static void xtest_tee_test_1004(ADBG_Case_t *Case_p); |
| 34 | static void xtest_tee_test_1005(ADBG_Case_t *Case_p); |
| 35 | static void xtest_tee_test_1006(ADBG_Case_t *Case_p); |
| 36 | static void xtest_tee_test_1007(ADBG_Case_t *Case_p); |
| 37 | static void xtest_tee_test_1008(ADBG_Case_t *Case_p); |
| 38 | static void xtest_tee_test_1009(ADBG_Case_t *Case_p); |
| 39 | static void xtest_tee_test_1010(ADBG_Case_t *Case_p); |
| 40 | static void xtest_tee_test_1011(ADBG_Case_t *Case_p); |
| 41 | static void xtest_tee_test_1012(ADBG_Case_t *Case_p); |
| 42 | |
| 43 | ADBG_CASE_DEFINE(XTEST_TEE_1001, xtest_tee_test_1001, |
| 44 | /* Title */ |
| 45 | "Registering TAs", |
| 46 | /* Short description */ |
| 47 | "Short description ...", |
| 48 | /* Requirement IDs */ |
| 49 | "TEE-??", |
| 50 | /* How to implement */ |
| 51 | "Description of how to implement ..." |
| 52 | ); |
| 53 | |
| 54 | ADBG_CASE_DEFINE(XTEST_TEE_1004, xtest_tee_test_1004, |
| 55 | /* Title */ |
| 56 | "Test User Crypt TA", |
| 57 | /* Short description */ |
| 58 | "Short description ...", |
| 59 | /* Requirement IDs */ |
| 60 | "TEE-??", |
| 61 | /* How to implement */ |
| 62 | "Description of how to implement ..." |
| 63 | ); |
| 64 | |
| 65 | ADBG_CASE_DEFINE(XTEST_TEE_1005, xtest_tee_test_1005, |
| 66 | /* Title */ |
| 67 | "Many sessions", |
| 68 | /* Short description */ |
| 69 | "Short description ...", |
| 70 | /* Requirement IDs */ |
| 71 | "TEE-??", |
| 72 | /* How to implement */ |
| 73 | "Description of how to implement ..." |
| 74 | ); |
| 75 | |
| 76 | ADBG_CASE_DEFINE(XTEST_TEE_1006, xtest_tee_test_1006, |
| 77 | /* Title */ |
| 78 | "Test Basic OS features", |
| 79 | /* Short description */ |
| 80 | "Short description ...", |
| 81 | /* Requirement IDs */ |
| 82 | "TEE-??", |
| 83 | /* How to implement */ |
| 84 | "Description of how to implement ..." |
| 85 | ); |
| 86 | |
| 87 | ADBG_CASE_DEFINE(XTEST_TEE_1007, xtest_tee_test_1007, |
| 88 | /* Title */ |
| 89 | "Test Panic", |
| 90 | /* Short description */ |
| 91 | "Short description ...", |
| 92 | /* Requirement IDs */ |
| 93 | "TEE-??", |
| 94 | /* How to implement */ |
| 95 | "Description of how to implement ..." |
| 96 | ); |
| 97 | |
| 98 | ADBG_CASE_DEFINE(XTEST_TEE_1008, xtest_tee_test_1008, |
| 99 | /* Title */ |
| 100 | "TEE internal client API", |
| 101 | /* Short description */ |
| 102 | "Short description ...", |
| 103 | /* Requirement IDs */ |
| 104 | "TEE-??", |
| 105 | /* How to implement */ |
| 106 | "Description of how to implement ..." |
| 107 | ); |
| 108 | |
| 109 | ADBG_CASE_DEFINE(XTEST_TEE_1009, xtest_tee_test_1009, |
| 110 | /* Title */ |
| 111 | "TEE Wait", |
| 112 | /* Short description */ |
| 113 | "Short description ...", |
| 114 | /* Requirement IDs */ |
| 115 | "TEE-??", |
| 116 | /* How to implement */ |
| 117 | "Description of how to implement ..." |
| 118 | ); |
| 119 | |
| 120 | ADBG_CASE_DEFINE(XTEST_TEE_1010, xtest_tee_test_1010, |
| 121 | /* Title */ |
| 122 | "Invalid memory access", |
| 123 | /* Short description */ |
| 124 | "Short description ...", |
| 125 | /* Requirement IDs */ |
| 126 | "TEE-??", |
| 127 | /* How to implement */ |
| 128 | "Description of how to implement ..." |
| 129 | ); |
| 130 | |
| 131 | ADBG_CASE_DEFINE(XTEST_TEE_1011, xtest_tee_test_1011, |
| 132 | /* Title */ |
| 133 | "Test RPC features with User Crypt TA", |
| 134 | /* Short description */ |
| 135 | "Short description ...", |
| 136 | /* Requirement IDs */ |
| 137 | "TEE-??", |
| 138 | /* How to implement */ |
| 139 | "Description of how to implement ..." |
| 140 | ); |
| 141 | |
| 142 | ADBG_CASE_DEFINE(XTEST_TEE_1012, xtest_tee_test_1012, |
| 143 | /* Title */ |
| 144 | "Test Single Instance Multi Session features with SIMS TA", |
| 145 | /* Short description */ |
| 146 | "Short description ...", |
| 147 | /* Requirement IDs */ |
| 148 | "TEE-??", |
| 149 | /* How to implement */ |
| 150 | "Description of how to implement ..." |
| 151 | ); |
| 152 | |
| 153 | struct xtest_crypto_session { |
| 154 | ADBG_Case_t *c; |
| 155 | TEEC_Session *session; |
| 156 | uint32_t cmd_id_sha256; |
| 157 | uint32_t cmd_id_aes256ecb_encrypt; |
| 158 | uint32_t cmd_id_aes256ecb_decrypt; |
| 159 | }; |
| 160 | |
| 161 | static void xtest_crypto_test(struct xtest_crypto_session *cs) |
| 162 | { |
| 163 | uint32_t ret_orig; |
| 164 | uint8_t crypt_out[16]; |
| 165 | uint8_t crypt_in[16] = { 22, 17 }; |
| 166 | |
| 167 | crypt_in[15] = 60; |
| 168 | |
| 169 | Do_ADBG_BeginSubCase(cs->c, "AES encrypt"); |
| 170 | { |
| 171 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 172 | |
| 173 | op.params[0].tmpref.buffer = crypt_in; |
| 174 | op.params[0].tmpref.size = sizeof(crypt_in); |
| 175 | op.params[1].tmpref.buffer = crypt_out; |
| 176 | op.params[1].tmpref.size = sizeof(crypt_out); |
| 177 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 178 | TEEC_MEMREF_TEMP_OUTPUT, |
| 179 | TEEC_NONE, TEEC_NONE); |
| 180 | |
| 181 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 182 | TEEC_InvokeCommand(cs->session, |
| 183 | cs-> |
| 184 | cmd_id_aes256ecb_encrypt, |
| 185 | &op, |
| 186 | &ret_orig)); |
| 187 | } |
| 188 | Do_ADBG_EndSubCase(cs->c, "AES encrypt"); |
| 189 | |
| 190 | Do_ADBG_BeginSubCase(cs->c, "AES decrypt"); |
| 191 | { |
| 192 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 193 | uint8_t out[16]; |
| 194 | |
| 195 | op.params[0].tmpref.buffer = crypt_out; |
| 196 | op.params[0].tmpref.size = sizeof(crypt_out); |
| 197 | op.params[1].tmpref.buffer = out; |
| 198 | op.params[1].tmpref.size = sizeof(out); |
| 199 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 200 | TEEC_MEMREF_TEMP_OUTPUT, |
| 201 | TEEC_NONE, TEEC_NONE); |
| 202 | |
| 203 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 204 | TEEC_InvokeCommand(cs->session, |
| 205 | cs-> |
| 206 | cmd_id_aes256ecb_decrypt, |
| 207 | &op, |
| 208 | &ret_orig)); |
| 209 | |
| 210 | if (!ADBG_EXPECT(cs->c, 0, |
| 211 | memcmp(crypt_in, out, sizeof(crypt_in)))) { |
| 212 | Do_ADBG_Log("crypt_in:"); |
| 213 | Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16); |
| 214 | Do_ADBG_Log("out:"); |
| 215 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 216 | } |
| 217 | } |
| 218 | Do_ADBG_EndSubCase(cs->c, "AES decrypt"); |
| 219 | |
| 220 | Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 221 | { |
| 222 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 223 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 224 | static const uint8_t sha256_out[] = { |
| 225 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 226 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 227 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 228 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 229 | }; |
| 230 | uint8_t out[32] = { 0 }; |
| 231 | |
| 232 | op.params[0].tmpref.buffer = (void *)sha256_in; |
| 233 | op.params[0].tmpref.size = sizeof(sha256_in); |
| 234 | op.params[1].tmpref.buffer = out; |
| 235 | op.params[1].tmpref.size = sizeof(out); |
| 236 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 237 | TEEC_MEMREF_TEMP_OUTPUT, |
| 238 | TEEC_NONE, TEEC_NONE); |
| 239 | |
| 240 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 241 | TEEC_InvokeCommand(cs->session, |
| 242 | cs-> |
| 243 | cmd_id_sha256, |
| 244 | &op, |
| 245 | &ret_orig)); |
| 246 | |
| 247 | if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out, |
| 248 | sizeof(sha256_out)))) { |
| 249 | Do_ADBG_Log("sha256_out:"); |
| 250 | Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16); |
| 251 | Do_ADBG_Log("out:"); |
| 252 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 253 | } |
| 254 | } |
| 255 | Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 256 | |
| 257 | Do_ADBG_BeginSubCase(cs->c, |
| 258 | "AES-256 ECB encrypt test, 32 bytes input, with fixed key"); |
| 259 | { |
| 260 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 261 | static const uint8_t in[] = { |
| 262 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 263 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 264 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 265 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 266 | }; |
| 267 | static const uint8_t exp_out[] = { |
| 268 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 269 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 270 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 271 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 272 | }; |
| 273 | uint8_t out[sizeof(exp_out)]; |
| 274 | |
| 275 | op.params[0].tmpref.buffer = (void *)in; |
| 276 | op.params[0].tmpref.size = sizeof(in); |
| 277 | op.params[1].tmpref.buffer = out; |
| 278 | op.params[1].tmpref.size = sizeof(out); |
| 279 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 280 | TEEC_MEMREF_TEMP_OUTPUT, |
| 281 | TEEC_NONE, TEEC_NONE); |
| 282 | |
| 283 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 284 | TEEC_InvokeCommand(cs->session, |
| 285 | cs-> |
| 286 | cmd_id_aes256ecb_encrypt, |
| 287 | &op, |
| 288 | &ret_orig)); |
| 289 | |
| 290 | if (!ADBG_EXPECT(cs->c, 0, |
| 291 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 292 | Do_ADBG_Log("exp_out:"); |
| 293 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 294 | Do_ADBG_Log("out:"); |
| 295 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 296 | } |
| 297 | } |
| 298 | Do_ADBG_EndSubCase(cs->c, |
| 299 | "AES-256 ECB encrypt test, 32 bytes input, with fixed key"); |
| 300 | |
| 301 | Do_ADBG_BeginSubCase(cs->c, |
| 302 | "AES-256 ECB decrypt test, 32 bytes input, with fixed key"); |
| 303 | { |
| 304 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 305 | static const uint8_t in[] = { |
| 306 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 307 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 308 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 309 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 310 | }; |
| 311 | static const uint8_t exp_out[] = { |
| 312 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 313 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 314 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 315 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 316 | }; |
| 317 | uint8_t out[sizeof(exp_out)]; |
| 318 | |
| 319 | op.params[0].tmpref.buffer = (void *)in; |
| 320 | op.params[0].tmpref.size = sizeof(in); |
| 321 | op.params[1].tmpref.buffer = out; |
| 322 | op.params[1].tmpref.size = sizeof(out); |
| 323 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 324 | TEEC_MEMREF_TEMP_OUTPUT, |
| 325 | TEEC_NONE, TEEC_NONE); |
| 326 | |
| 327 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 328 | TEEC_InvokeCommand(cs->session, |
| 329 | cs-> |
| 330 | cmd_id_aes256ecb_decrypt, |
| 331 | &op, |
| 332 | &ret_orig)); |
| 333 | |
| 334 | if (!ADBG_EXPECT(cs->c, 0, |
| 335 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 336 | Do_ADBG_Log("exp_out:"); |
| 337 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 338 | Do_ADBG_Log("out:"); |
| 339 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 340 | } |
| 341 | } |
| 342 | Do_ADBG_EndSubCase(cs->c, |
| 343 | "AES-256 ECB decrypt test, 32 bytes input, with fixed key"); |
| 344 | } |
| 345 | |
| 346 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 347 | { |
| 348 | #ifdef USER_SPACE |
| 349 | (void)c; |
| 350 | #else |
| 351 | #define REG_TA(name) \ |
| 352 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, \ |
| 353 | TEEC_RegisterTA(name, name ## _size)) |
| 354 | |
| 355 | REG_TA(crypt_user_ta); |
| 356 | REG_TA(os_test_ta); |
| 357 | REG_TA(create_fail_test_ta); |
| 358 | REG_TA(rpc_test_ta); |
| 359 | REG_TA(sims_test_ta); |
| 360 | |
| 361 | TEEC_UnregisterTA(crypt_user_ta); |
| 362 | TEEC_UnregisterTA(os_test_ta); |
| 363 | TEEC_UnregisterTA(create_fail_test_ta); |
| 364 | TEEC_UnregisterTA(rpc_test_ta); |
| 365 | TEEC_UnregisterTA(sims_test_ta); |
| 366 | |
| 367 | REG_TA(crypt_user_ta); |
| 368 | REG_TA(os_test_ta); |
| 369 | REG_TA(create_fail_test_ta); |
| 370 | REG_TA(rpc_test_ta); |
| 371 | REG_TA(sims_test_ta); |
| 372 | REG_TA(storage_ta); |
| 373 | |
| 374 | REG_TA(gp_tta_testing_client_api_ta); |
| 375 | REG_TA(gp_tta_answer_success_to_open_session_invoke_ta); |
| 376 | REG_TA(gp_tta_answer_error_to_invoke_ta); |
| 377 | REG_TA(gp_tta_answer_error_to_open_session_ta); |
| 378 | REG_TA(gp_tta_check_open_session_with_4_parameters_ta); |
| 379 | REG_TA(gp_tta_time_ta); |
| 380 | REG_TA(gp_tta_ds_ta); |
| 381 | REG_TA(gp_tta_tcf_ta); |
| 382 | REG_TA(gp_tta_crypto_ta); |
| 383 | REG_TA(gp_tta_arithm_ta); |
| 384 | REG_TA(gp_tta_ica_ta); |
| 385 | REG_TA(gp_tta_ica2_ta); |
| 386 | REG_TA(gp_tta_tcf_singleinstance_ta); |
| 387 | REG_TA(gp_tta_tcf_multipleinstance_ta); |
| 388 | #endif /*!USER_SPACE*/ |
| 389 | } |
| 390 | |
| 391 | static void xtest_tee_test_1004(ADBG_Case_t *c) |
| 392 | { |
| 393 | TEEC_Session session = { 0 }; |
| 394 | uint32_t ret_orig; |
| 395 | struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256, |
| 396 | TA_CRYPT_CMD_AES256ECB_ENC, |
| 397 | TA_CRYPT_CMD_AES256ECB_DEC }; |
| 398 | |
| 399 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session( |
| 400 | &session, &crypt_user_ta_uuid, |
| 401 | NULL, &ret_orig))) |
| 402 | return; |
| 403 | |
| 404 | /* Run the "complete crypto test suite" */ |
| 405 | xtest_crypto_test(&cs); |
| 406 | |
| 407 | TEEC_CloseSession(&session); |
| 408 | } |
| 409 | |
| 410 | #ifndef TEEC_ERROR_TARGET_DEAD |
| 411 | /* To be removed when we have TEEC_ERROR_TARGET_DEAD from tee_client_api.h */ |
| 412 | #define TEEC_ERROR_TARGET_DEAD 0xFFFF3024 |
| 413 | #endif |
| 414 | |
| 415 | static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, uint32_t n) |
| 416 | { |
| 417 | TEEC_Session session = { 0 }; |
| 418 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 419 | uint32_t ret_orig; |
| 420 | |
| 421 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 422 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 423 | &ret_orig)); |
| 424 | |
| 425 | op.params[0].value.a = n; |
| 426 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 427 | TEEC_NONE); |
| 428 | |
| 429 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 430 | TEEC_ERROR_TARGET_DEAD, |
| 431 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 432 | &ret_orig)); |
| 433 | |
| 434 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 435 | TEEC_InvokeCommand(&session, |
| 436 | TA_OS_TEST_CMD_BAD_MEM_ACCESS, |
| 437 | &op, |
| 438 | &ret_orig)); |
| 439 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 440 | |
| 441 | TEEC_CloseSession(&session); |
| 442 | } |
| 443 | |
| 444 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 445 | { |
| 446 | uint32_t ret_orig; |
| 447 | #define MAX_SESSIONS 3 |
| 448 | TEEC_Session sessions[MAX_SESSIONS]; |
| 449 | int i; |
| 450 | |
| 451 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 452 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 453 | xtest_teec_open_session(&sessions[i], &os_test_ta_uuid, |
| 454 | NULL, &ret_orig))) |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | for (; --i >= 0; ) |
| 459 | TEEC_CloseSession(&sessions[i]); |
| 460 | } |
| 461 | |
| 462 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 463 | { |
| 464 | TEEC_Session session = { 0 }; |
| 465 | uint32_t ret_orig; |
| 466 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 467 | uint8_t buf[32]; |
| 468 | |
| 469 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 470 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 471 | &ret_orig))) |
| 472 | return; |
| 473 | |
| 474 | op.params[0].tmpref.buffer = buf; |
| 475 | op.params[0].tmpref.size = sizeof(buf); |
| 476 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 477 | TEEC_NONE, TEEC_NONE); |
| 478 | |
| 479 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 480 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 481 | &ret_orig)); |
| 482 | |
| 483 | TEEC_CloseSession(&session); |
| 484 | } |
| 485 | |
| 486 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 487 | { |
| 488 | TEEC_Session session = { 0 }; |
| 489 | uint32_t ret_orig; |
| 490 | |
| 491 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 492 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 493 | &ret_orig)); |
| 494 | |
| 495 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 496 | TEEC_ERROR_TARGET_DEAD, |
| 497 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 498 | &ret_orig)); |
| 499 | |
| 500 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 501 | |
| 502 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 503 | TEEC_ERROR_TARGET_DEAD, |
| 504 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 505 | &ret_orig)); |
| 506 | |
| 507 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 508 | |
| 509 | TEEC_CloseSession(&session); |
| 510 | } |
| 511 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame^] | 512 | static void uuid_to_full_name(char *buf, size_t blen, const TEEC_UUID *uuid, |
| 513 | const char *extra_suffix) |
| 514 | { |
| 515 | static const char ta_dir[] = "/lib/teetz"; |
| 516 | |
| 517 | snprintf(buf, blen, |
| 518 | "%s/%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x.ta%s", |
| 519 | ta_dir, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
| 520 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 521 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 522 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
| 523 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7], |
| 524 | extra_suffix ? extra_suffix : ""); |
| 525 | } |
| 526 | |
| 527 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *extra_suffix, |
| 528 | const char *mode) |
| 529 | { |
| 530 | char buf[PATH_MAX]; |
| 531 | |
| 532 | uuid_to_full_name(buf, sizeof(buf), uuid, extra_suffix); |
| 533 | return fopen(buf, mode); |
| 534 | } |
| 535 | |
| 536 | static bool rm_file(const TEEC_UUID *uuid, const char *extra_suffix) |
| 537 | { |
| 538 | char buf[PATH_MAX]; |
| 539 | |
| 540 | uuid_to_full_name(buf, sizeof(buf), uuid, extra_suffix); |
| 541 | return !unlink(buf); |
| 542 | } |
| 543 | |
| 544 | static bool copy_file(FILE *src, FILE *dst) |
| 545 | { |
| 546 | char buf[4 * 1024]; |
| 547 | size_t r; |
| 548 | size_t w; |
| 549 | |
| 550 | while (true) { |
| 551 | r = fread(buf, 1, sizeof(buf), src); |
| 552 | if (!r) |
| 553 | return !!feof(src); |
| 554 | w = fwrite(buf, 1, r, dst); |
| 555 | if (w != r) |
| 556 | return false; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | static void load_fake_ta(ADBG_Case_t *c) |
| 561 | { |
| 562 | static const TEEC_UUID fake_uuid = { |
| 563 | 0x7e0a0900, 0x586b, 0x11e5, |
| 564 | { 0x93, 0x1f, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } |
| 565 | }; |
| 566 | TEEC_Session session = { 0 }; |
| 567 | TEEC_Result res; |
| 568 | uint32_t ret_orig; |
| 569 | FILE *fsrc; |
| 570 | FILE *fdst; |
| 571 | bool r; |
| 572 | size_t n; |
| 573 | |
| 574 | fsrc = open_ta_file(&create_fail_test_ta_uuid, NULL, "r"); |
| 575 | if (!ADBG_EXPECT_NOT_NULL(c, fsrc)) |
| 576 | return; |
| 577 | fdst = open_ta_file(&fake_uuid, NULL, "w"); |
| 578 | if (!ADBG_EXPECT_NOT_NULL(c, fdst)) { |
| 579 | fclose(fsrc); |
| 580 | return; |
| 581 | } |
| 582 | r = copy_file(fsrc, fdst); |
| 583 | fclose(fsrc); |
| 584 | fclose(fdst); |
| 585 | |
| 586 | if (ADBG_EXPECT_TRUE(c, r)) { |
| 587 | /* |
| 588 | * Run this several times to see that there's no memory leakage. |
| 589 | */ |
| 590 | for (n = 0; n < 10; n++) { |
| 591 | Do_ADBG_Log("n = %zu", n); |
| 592 | res = xtest_teec_open_session(&session, &fake_uuid, |
| 593 | NULL, &ret_orig); |
| 594 | if (res == TEEC_SUCCESS) |
| 595 | TEEC_CloseSession(&session); |
| 596 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, |
| 597 | res)) |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | ADBG_EXPECT_TRUE(c, rm_file(&fake_uuid, NULL)); |
| 603 | } |
| 604 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 605 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 606 | { |
| 607 | TEEC_Session session = { 0 }; |
| 608 | TEEC_Session session_crypt = { 0 }; |
| 609 | uint32_t ret_orig; |
| 610 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame^] | 611 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 612 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 613 | { |
| 614 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 615 | xtest_teec_open_session(&session_crypt, |
| 616 | &crypt_user_ta_uuid, NULL, |
| 617 | &ret_orig)); |
| 618 | |
| 619 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 620 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 621 | NULL, &ret_orig)); |
| 622 | |
| 623 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 624 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 625 | NULL, &ret_orig)); |
| 626 | |
| 627 | TEEC_CloseSession(&session); |
| 628 | TEEC_CloseSession(&session_crypt); |
| 629 | } |
| 630 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 631 | |
| 632 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 633 | { |
| 634 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 635 | |
| 636 | op.params[0].value.a = 2000; |
| 637 | op.paramTypes = TEEC_PARAM_TYPES( |
| 638 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 639 | |
| 640 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 641 | xtest_teec_open_session(&session, |
| 642 | &os_test_ta_uuid, |
| 643 | NULL, |
| 644 | &ret_orig)); |
| 645 | |
| 646 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 647 | TEEC_InvokeCommand(&session, |
| 648 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 649 | &op, &ret_orig)); |
| 650 | |
| 651 | TEEC_CloseSession(&session); |
| 652 | } |
| 653 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 654 | |
| 655 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 656 | { |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame^] | 657 | size_t n; |
| 658 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 659 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 660 | xtest_teec_open_session(&session_crypt, |
| 661 | &create_fail_test_ta_uuid, NULL, |
| 662 | &ret_orig)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 663 | /* |
| 664 | * Run this several times to see that there's no memory leakage. |
| 665 | */ |
| 666 | for (n = 0; n < 100; n++) { |
| 667 | Do_ADBG_Log("n = %zu", n); |
| 668 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 669 | xtest_teec_open_session(&session_crypt, |
| 670 | &create_fail_test_ta_uuid, |
| 671 | NULL, &ret_orig)); |
| 672 | } |
| 673 | } |
| 674 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame^] | 675 | |
| 676 | Do_ADBG_BeginSubCase(c, "Load fake uuid TA"); |
| 677 | load_fake_ta(c); |
| 678 | Do_ADBG_EndSubCase(c, "Load fake uuid TA"); |
| 679 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | #ifdef USER_SPACE |
| 683 | static void *cancellation_thread(void *arg) |
| 684 | { |
| 685 | /* |
| 686 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 687 | * thread is in RPC_WAIT. |
| 688 | */ |
| 689 | (void)usleep(500000); |
| 690 | TEEC_RequestCancellation(arg); |
| 691 | return NULL; |
| 692 | } |
| 693 | #endif |
| 694 | |
| 695 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 696 | { |
| 697 | TEEC_Session session = { 0 }; |
| 698 | uint32_t ret_orig; |
| 699 | |
| 700 | Do_ADBG_BeginSubCase(c, "TEE Wait 0.1s"); |
| 701 | { |
| 702 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 703 | |
| 704 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 705 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 706 | NULL, &ret_orig)); |
| 707 | |
| 708 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 709 | ret_orig); |
| 710 | |
| 711 | op.params[0].value.a = 100; |
| 712 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 713 | TEEC_NONE, TEEC_NONE); |
| 714 | |
| 715 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 716 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_WAIT, &op, |
| 717 | &ret_orig)); |
| 718 | TEEC_CloseSession(&session); |
| 719 | } |
| 720 | Do_ADBG_EndSubCase(c, "TEE Wait 0.1s"); |
| 721 | |
| 722 | Do_ADBG_BeginSubCase(c, "TEE Wait 0.5s"); |
| 723 | { |
| 724 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 725 | |
| 726 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 727 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 728 | NULL, &ret_orig)); |
| 729 | |
| 730 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 731 | ret_orig); |
| 732 | |
| 733 | op.params[0].value.a = 500; |
| 734 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 735 | TEEC_NONE, TEEC_NONE); |
| 736 | |
| 737 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 738 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_WAIT, &op, |
| 739 | &ret_orig)); |
| 740 | |
| 741 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 742 | ret_orig); |
| 743 | TEEC_CloseSession(&session); |
| 744 | } |
| 745 | Do_ADBG_EndSubCase(c, "TEE Wait 0.5s"); |
| 746 | |
| 747 | #ifdef USER_SPACE |
| 748 | Do_ADBG_BeginSubCase(c, "TEE Wait 2s cancel"); |
| 749 | { |
| 750 | pthread_t thr; |
| 751 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 752 | |
| 753 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 754 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 755 | NULL, &ret_orig)); |
| 756 | |
| 757 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 758 | ret_orig); |
| 759 | |
| 760 | op.params[0].value.a = 2000; |
| 761 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 762 | TEEC_NONE, TEEC_NONE); |
| 763 | |
| 764 | (void)ADBG_EXPECT(c, 0, |
| 765 | pthread_create(&thr, NULL, cancellation_thread, &op)); |
| 766 | |
| 767 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_CANCEL, |
| 768 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_WAIT, &op, |
| 769 | &ret_orig)); |
| 770 | |
| 771 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 772 | ret_orig); |
| 773 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
| 774 | TEEC_CloseSession(&session); |
| 775 | } |
| 776 | Do_ADBG_EndSubCase(c, "TEE Wait 2s cancel"); |
| 777 | #endif |
| 778 | |
| 779 | Do_ADBG_BeginSubCase(c, "TEE Wait 2s"); |
| 780 | { |
| 781 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 782 | |
| 783 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 784 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 785 | NULL, &ret_orig)); |
| 786 | |
| 787 | op.params[0].value.a = 2000; |
| 788 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 789 | TEEC_NONE, TEEC_NONE); |
| 790 | |
| 791 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 792 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_WAIT, &op, |
| 793 | &ret_orig)); |
| 794 | |
| 795 | TEEC_CloseSession(&session); |
| 796 | } |
| 797 | Do_ADBG_EndSubCase(c, "TEE Wait 2s"); |
| 798 | } |
| 799 | |
| 800 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 801 | { |
| 802 | unsigned n; |
| 803 | |
| 804 | for (n = 1; n <= 5; n++) { |
| 805 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 806 | xtest_tee_test_invalid_mem_access(c, n); |
| 807 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 812 | { |
| 813 | TEEC_Session session = { 0 }; |
| 814 | uint32_t ret_orig; |
| 815 | struct xtest_crypto_session cs = { |
| 816 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 817 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 818 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 819 | }; |
| 820 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 821 | |
| 822 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 823 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 824 | return; |
| 825 | |
| 826 | /* |
| 827 | * Run the "complete crypto test suite" using RPC |
| 828 | */ |
| 829 | xtest_crypto_test(&cs); |
| 830 | TEEC_CloseSession(&session); |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | * Note that this test is failing when |
| 835 | * - running twice in a raw |
| 836 | * - and the user TA is statically linked |
| 837 | * This is because the counter is not reseted when opening the first session |
| 838 | * in case the TA is statically linked |
| 839 | */ |
| 840 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 841 | { |
| 842 | TEEC_Session session1 = { 0 }; |
| 843 | TEEC_Session session2 = { 0 }; |
| 844 | uint32_t ret_orig; |
| 845 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 846 | |
| 847 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 848 | { |
| 849 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 850 | static const uint8_t in[] = { |
| 851 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 852 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 853 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 854 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 855 | }; |
| 856 | uint8_t out[32] = { 0 }; |
| 857 | int i; |
| 858 | |
| 859 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 860 | xtest_teec_open_session(&session1, &uuid, NULL, |
| 861 | &ret_orig)); |
| 862 | |
| 863 | op.params[0].value.a = 0; |
| 864 | op.params[1].tmpref.buffer = (void *)in; |
| 865 | op.params[1].tmpref.size = sizeof(in); |
| 866 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 867 | TEEC_MEMREF_TEMP_INPUT, |
| 868 | TEEC_NONE, TEEC_NONE); |
| 869 | |
| 870 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 871 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 872 | &ret_orig)); |
| 873 | |
| 874 | for (i = 1; i < 1000; i++) { |
| 875 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 876 | xtest_teec_open_session(&session2, &uuid, NULL, |
| 877 | &ret_orig)); |
| 878 | |
| 879 | op.params[0].value.a = 0; |
| 880 | op.params[1].tmpref.buffer = out; |
| 881 | op.params[1].tmpref.size = sizeof(out); |
| 882 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 883 | TEEC_MEMREF_TEMP_OUTPUT, |
| 884 | TEEC_NONE, TEEC_NONE); |
| 885 | |
| 886 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 887 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 888 | &op, &ret_orig)); |
| 889 | |
| 890 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 891 | sizeof(out))) { |
| 892 | Do_ADBG_Log("in:"); |
| 893 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 894 | Do_ADBG_Log("out:"); |
| 895 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 896 | } |
| 897 | |
| 898 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 899 | TEEC_NONE, TEEC_NONE, |
| 900 | TEEC_NONE); |
| 901 | |
| 902 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 903 | TEEC_InvokeCommand(&session1, |
| 904 | TA_SIMS_CMD_GET_COUNTER, |
| 905 | &op, &ret_orig)); |
| 906 | |
| 907 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 908 | |
| 909 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 910 | TEEC_InvokeCommand(&session2, |
| 911 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 912 | &ret_orig)); |
| 913 | |
| 914 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 915 | TEEC_CloseSession(&session2); |
| 916 | } |
| 917 | |
| 918 | memset(out, 0, sizeof(out)); |
| 919 | op.params[0].value.a = 0; |
| 920 | op.params[1].tmpref.buffer = out; |
| 921 | op.params[1].tmpref.size = sizeof(out); |
| 922 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 923 | TEEC_MEMREF_TEMP_OUTPUT, |
| 924 | TEEC_NONE, TEEC_NONE); |
| 925 | |
| 926 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 927 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 928 | &ret_orig)); |
| 929 | |
| 930 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 931 | Do_ADBG_Log("in:"); |
| 932 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 933 | Do_ADBG_Log("out:"); |
| 934 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 935 | } |
| 936 | |
| 937 | TEEC_CloseSession(&session1); |
| 938 | } |
| 939 | } |