1 /* 2 * Copyright 2017, Rockchip Electronics Co., Ltd 3 * hisping lin, <hisping.lin@rock-chips.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <optee_include/OpteeClientApiLib.h> 10 #include <optee_include/tee_client_api.h> 11 #include <optee_include/tee_api_defines.h> 12 #include <boot_rkimg.h> 13 #include <stdlib.h> 14 #include <attestation_key.h> 15 16 #define BOOT_FROM_EMMC (1 << 1) 17 18 void test_optee(void) 19 { 20 TEEC_Result TeecResult; 21 TEEC_Context TeecContext; 22 TEEC_Session TeecSession; 23 uint32_t ErrorOrigin; 24 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, \ 25 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 26 TEEC_UUID *TeecUuid = &tempuuid; 27 TEEC_Operation TeecOperation = {0}; 28 struct blk_desc *dev_desc; 29 dev_desc = rockchip_get_bootdev(); 30 if (!dev_desc) { 31 printf("%s: dev_desc is NULL!\n", __func__); 32 return; 33 } 34 35 debug("testmm start\n"); 36 OpteeClientApiLibInitialize(); 37 38 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 39 40 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 41 TEEC_NONE, 42 TEEC_NONE, 43 TEEC_NONE); 44 /*0 nand or emmc "security" partition , 1 rpmb*/ 45 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 46 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 47 TeecOperation.params[0].value.a = 0; 48 #endif 49 50 TeecResult = TEEC_OpenSession(&TeecContext, 51 &TeecSession, 52 TeecUuid, 53 TEEC_LOGIN_PUBLIC, 54 NULL, 55 &TeecOperation, 56 &ErrorOrigin); 57 58 TEEC_SharedMemory SharedMem0 = {0}; 59 60 SharedMem0.size = sizeof("filename_test"); 61 SharedMem0.flags = 0; 62 63 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 64 65 memcpy(SharedMem0.buffer, "filename_test", SharedMem0.size); 66 67 TEEC_SharedMemory SharedMem1 = {0}; 68 69 SharedMem1.size = 32; 70 SharedMem1.flags = 0; 71 72 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 73 74 memset(SharedMem1.buffer, 'a', SharedMem1.size); 75 76 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 77 TeecOperation.params[0].tmpref.size = SharedMem0.size; 78 79 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 80 TeecOperation.params[1].tmpref.size = SharedMem1.size; 81 82 83 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 84 TEEC_MEMREF_TEMP_INOUT, 85 TEEC_NONE, 86 TEEC_NONE); 87 88 TeecResult = TEEC_InvokeCommand(&TeecSession, 89 1, 90 &TeecOperation, 91 &ErrorOrigin); 92 93 TEEC_ReleaseSharedMemory(&SharedMem0); 94 TEEC_ReleaseSharedMemory(&SharedMem1); 95 96 TEEC_CloseSession(&TeecSession); 97 98 TEEC_FinalizeContext(&TeecContext); 99 100 debug("testmm end\n"); 101 debug("TeecResult %x\n", TeecResult); 102 } 103 104 static uint8_t b2hs_add_base(uint8_t in) 105 { 106 if (in > 9) 107 return in + 55; 108 else 109 return in + 48; 110 } 111 112 uint32_t b2hs(uint8_t *b, uint8_t *hs, uint32_t blen, uint32_t hslen) 113 { 114 uint32_t i = 0; 115 116 if (blen * 2 + 1 > hslen) 117 return 0; 118 119 for (; i < blen; i++) { 120 hs[i * 2 + 1] = b2hs_add_base(b[i] & 0xf); 121 hs[i * 2] = b2hs_add_base(b[i] >> 4); 122 } 123 hs[blen * 2] = 0; 124 125 return blen * 2; 126 } 127 128 129 uint32_t trusty_read_rollback_index(uint32_t slot, uint64_t *value) 130 { 131 TEEC_Result TeecResult; 132 TEEC_Context TeecContext; 133 TEEC_Session TeecSession; 134 uint32_t ErrorOrigin; 135 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 136 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 137 TEEC_UUID *TeecUuid = &tempuuid; 138 TEEC_Operation TeecOperation = {0}; 139 uint8_t hs[9]; 140 141 struct blk_desc *dev_desc; 142 dev_desc = rockchip_get_bootdev(); 143 if (!dev_desc) { 144 printf("%s: dev_desc is NULL!\n", __func__); 145 return -TEEC_ERROR_GENERIC; 146 } 147 148 b2hs((uint8_t *)&slot, hs, 4, 9); 149 debug("testmm start\n"); 150 OpteeClientApiLibInitialize(); 151 152 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 153 154 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 155 TEEC_NONE, 156 TEEC_NONE, 157 TEEC_NONE); 158 /*0 nand or emmc "security" partition , 1 rpmb*/ 159 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 160 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 161 TeecOperation.params[0].value.a = 0; 162 #endif 163 164 TeecResult = TEEC_OpenSession(&TeecContext, 165 &TeecSession, 166 TeecUuid, 167 TEEC_LOGIN_PUBLIC, 168 NULL, 169 &TeecOperation, 170 171 &ErrorOrigin); 172 173 TEEC_SharedMemory SharedMem0 = {0}; 174 175 SharedMem0.size = 8; 176 SharedMem0.flags = 0; 177 178 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 179 180 memcpy(SharedMem0.buffer, hs, SharedMem0.size); 181 182 TEEC_SharedMemory SharedMem1 = {0}; 183 184 SharedMem1.size = 8; 185 SharedMem1.flags = 0; 186 187 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 188 189 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 190 TeecOperation.params[0].tmpref.size = SharedMem0.size; 191 192 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 193 TeecOperation.params[1].tmpref.size = SharedMem1.size; 194 195 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 196 TEEC_MEMREF_TEMP_INOUT, 197 TEEC_NONE, 198 TEEC_NONE); 199 200 TeecResult = TEEC_InvokeCommand(&TeecSession, 201 0, 202 &TeecOperation, 203 &ErrorOrigin); 204 if (TeecResult == TEEC_SUCCESS) 205 memcpy((char *)value, SharedMem1.buffer, SharedMem1.size); 206 207 TEEC_ReleaseSharedMemory(&SharedMem0); 208 TEEC_ReleaseSharedMemory(&SharedMem1); 209 210 TEEC_CloseSession(&TeecSession); 211 212 TEEC_FinalizeContext(&TeecContext); 213 214 debug("testmm end\n"); 215 return TeecResult; 216 } 217 218 uint32_t trusty_write_rollback_index(uint32_t slot, uint64_t value) 219 { 220 TEEC_Result TeecResult; 221 TEEC_Context TeecContext; 222 TEEC_Session TeecSession; 223 uint32_t ErrorOrigin; 224 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 225 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 226 TEEC_UUID *TeecUuid = &tempuuid; 227 TEEC_Operation TeecOperation = {0}; 228 uint8_t hs[9]; 229 struct blk_desc *dev_desc; 230 dev_desc = rockchip_get_bootdev(); 231 if (!dev_desc) { 232 printf("%s: dev_desc is NULL!\n", __func__); 233 return -TEEC_ERROR_GENERIC; 234 } 235 236 b2hs((uint8_t *)&slot, hs, 4, 9); 237 OpteeClientApiLibInitialize(); 238 239 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 240 241 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 242 TEEC_NONE, 243 TEEC_NONE, 244 TEEC_NONE); 245 /*0 nand or emmc "security" partition , 1 rpmb*/ 246 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 247 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 248 TeecOperation.params[0].value.a = 0; 249 #endif 250 251 TeecResult = TEEC_OpenSession(&TeecContext, 252 &TeecSession, 253 TeecUuid, 254 TEEC_LOGIN_PUBLIC, 255 NULL, 256 &TeecOperation, 257 &ErrorOrigin); 258 259 TEEC_SharedMemory SharedMem0 = {0}; 260 261 SharedMem0.size = 8; 262 SharedMem0.flags = 0; 263 264 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 265 266 memcpy(SharedMem0.buffer, hs, SharedMem0.size); 267 268 TEEC_SharedMemory SharedMem1 = {0}; 269 270 SharedMem1.size = 8; 271 SharedMem1.flags = 0; 272 273 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 274 275 memcpy(SharedMem1.buffer, (char *)&value, SharedMem1.size); 276 277 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 278 TeecOperation.params[0].tmpref.size = SharedMem0.size; 279 280 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 281 TeecOperation.params[1].tmpref.size = SharedMem1.size; 282 283 284 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 285 TEEC_MEMREF_TEMP_INOUT, 286 TEEC_NONE, 287 TEEC_NONE); 288 289 TeecResult = TEEC_InvokeCommand(&TeecSession, 290 1, 291 &TeecOperation, 292 &ErrorOrigin); 293 294 TEEC_ReleaseSharedMemory(&SharedMem0); 295 TEEC_ReleaseSharedMemory(&SharedMem1); 296 297 TEEC_CloseSession(&TeecSession); 298 299 TEEC_FinalizeContext(&TeecContext); 300 301 debug("testmm end\n"); 302 303 return TeecResult; 304 } 305 306 uint32_t trusty_read_permanent_attributes(uint8_t *attributes, uint32_t size) 307 { 308 TEEC_Result TeecResult; 309 TEEC_Context TeecContext; 310 TEEC_Session TeecSession; 311 uint32_t ErrorOrigin; 312 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 313 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 314 TEEC_UUID *TeecUuid = &tempuuid; 315 TEEC_Operation TeecOperation = {0}; 316 struct blk_desc *dev_desc; 317 dev_desc = rockchip_get_bootdev(); 318 if (!dev_desc) { 319 printf("%s: dev_desc is NULL!\n", __func__); 320 return -TEEC_ERROR_GENERIC; 321 } 322 323 debug("testmm start\n"); 324 OpteeClientApiLibInitialize(); 325 326 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 327 328 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 329 TEEC_NONE, 330 TEEC_NONE, 331 TEEC_NONE); 332 /*0 nand or emmc "security" partition , 1 rpmb*/ 333 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 334 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 335 TeecOperation.params[0].value.a = 0; 336 #endif 337 338 TeecResult = TEEC_OpenSession(&TeecContext, 339 &TeecSession, 340 TeecUuid, 341 TEEC_LOGIN_PUBLIC, 342 NULL, 343 &TeecOperation, 344 &ErrorOrigin); 345 346 TEEC_SharedMemory SharedMem0 = {0}; 347 348 SharedMem0.size = sizeof("attributes"); 349 SharedMem0.flags = 0; 350 351 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 352 353 memcpy(SharedMem0.buffer, "attributes", SharedMem0.size); 354 355 TEEC_SharedMemory SharedMem1 = {0}; 356 357 SharedMem1.size = size; 358 SharedMem1.flags = 0; 359 360 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 361 362 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 363 TeecOperation.params[0].tmpref.size = SharedMem0.size; 364 365 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 366 TeecOperation.params[1].tmpref.size = SharedMem1.size; 367 368 369 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 370 TEEC_MEMREF_TEMP_INOUT, 371 TEEC_NONE, 372 TEEC_NONE); 373 374 TeecResult = TEEC_InvokeCommand(&TeecSession, 375 0, 376 &TeecOperation, 377 &ErrorOrigin); 378 if (TeecResult == TEEC_SUCCESS) 379 memcpy(attributes, SharedMem1.buffer, SharedMem1.size); 380 TEEC_ReleaseSharedMemory(&SharedMem0); 381 TEEC_ReleaseSharedMemory(&SharedMem1); 382 TEEC_CloseSession(&TeecSession); 383 TEEC_FinalizeContext(&TeecContext); 384 debug("testmm end\n"); 385 386 return TeecResult; 387 } 388 389 uint32_t trusty_write_permanent_attributes(uint8_t *attributes, uint32_t size) 390 { 391 TEEC_Result TeecResult; 392 TEEC_Context TeecContext; 393 TEEC_Session TeecSession; 394 uint32_t ErrorOrigin; 395 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 396 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 397 TEEC_UUID *TeecUuid = &tempuuid; 398 TEEC_Operation TeecOperation = {0}; 399 struct blk_desc *dev_desc; 400 dev_desc = rockchip_get_bootdev(); 401 if (!dev_desc) { 402 printf("%s: dev_desc is NULL!\n", __func__); 403 return -TEEC_ERROR_GENERIC; 404 } 405 406 debug("testmm start\n"); 407 OpteeClientApiLibInitialize(); 408 409 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 410 411 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 412 TEEC_NONE, 413 TEEC_NONE, 414 TEEC_NONE); 415 /*0 nand or emmc "security" partition , 1 rpmb*/ 416 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 417 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 418 TeecOperation.params[0].value.a = 0; 419 #endif 420 421 TeecResult = TEEC_OpenSession(&TeecContext, 422 &TeecSession, 423 TeecUuid, 424 TEEC_LOGIN_PUBLIC, 425 NULL, 426 &TeecOperation, 427 &ErrorOrigin); 428 429 TEEC_SharedMemory SharedMem0 = {0}; 430 431 SharedMem0.size = sizeof("attributes"); 432 SharedMem0.flags = 0; 433 434 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 435 436 memcpy(SharedMem0.buffer, "attributes", SharedMem0.size); 437 438 TEEC_SharedMemory SharedMem1 = {0}; 439 440 SharedMem1.size = size; 441 SharedMem1.flags = 0; 442 443 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 444 445 memcpy(SharedMem1.buffer, attributes, SharedMem1.size); 446 447 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 448 TeecOperation.params[0].tmpref.size = SharedMem0.size; 449 450 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 451 TeecOperation.params[1].tmpref.size = SharedMem1.size; 452 453 454 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 455 TEEC_MEMREF_TEMP_INOUT, 456 TEEC_NONE, 457 TEEC_NONE); 458 459 TeecResult = TEEC_InvokeCommand(&TeecSession, 460 1, 461 &TeecOperation, 462 &ErrorOrigin); 463 464 TEEC_ReleaseSharedMemory(&SharedMem0); 465 TEEC_ReleaseSharedMemory(&SharedMem1); 466 TEEC_CloseSession(&TeecSession); 467 TEEC_FinalizeContext(&TeecContext); 468 debug("testmm end\n"); 469 470 return TeecResult; 471 } 472 473 uint32_t trusty_read_permanent_attributes_cer(uint8_t *attributes, 474 uint32_t size) 475 { 476 TEEC_Result TeecResult; 477 TEEC_Context TeecContext; 478 TEEC_Session TeecSession; 479 uint32_t ErrorOrigin; 480 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 481 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 482 TEEC_UUID *TeecUuid = &tempuuid; 483 TEEC_Operation TeecOperation = {0}; 484 struct blk_desc *dev_desc; 485 486 dev_desc = rockchip_get_bootdev(); 487 if (!dev_desc) { 488 printf("%s: dev_desc is NULL!\n", __func__); 489 return -TEEC_ERROR_GENERIC; 490 } 491 492 debug("testmm start\n"); 493 OpteeClientApiLibInitialize(); 494 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 495 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 496 TEEC_NONE, 497 TEEC_NONE, 498 TEEC_NONE); 499 /*0 nand or emmc "security" partition , 1 rpmb*/ 500 TeecOperation.params[0].value.a = 501 (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 502 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 503 TeecOperation.params[0].value.a = 0; 504 #endif 505 506 TeecResult = TEEC_OpenSession(&TeecContext, 507 &TeecSession, 508 TeecUuid, 509 TEEC_LOGIN_PUBLIC, 510 NULL, 511 &TeecOperation, 512 &ErrorOrigin); 513 514 TEEC_SharedMemory SharedMem0 = {0}; 515 516 SharedMem0.size = sizeof("rsacer"); 517 SharedMem0.flags = 0; 518 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 519 memcpy(SharedMem0.buffer, "rsacer", SharedMem0.size); 520 TEEC_SharedMemory SharedMem1 = {0}; 521 522 SharedMem1.size = size; 523 SharedMem1.flags = 0; 524 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 525 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 526 TeecOperation.params[0].tmpref.size = SharedMem0.size; 527 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 528 TeecOperation.params[1].tmpref.size = SharedMem1.size; 529 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 530 TEEC_MEMREF_TEMP_INOUT, 531 TEEC_NONE, 532 TEEC_NONE); 533 534 TeecResult = TEEC_InvokeCommand(&TeecSession, 535 0, 536 &TeecOperation, 537 &ErrorOrigin); 538 if (TeecResult == TEEC_SUCCESS) 539 memcpy(attributes, SharedMem1.buffer, SharedMem1.size); 540 TEEC_ReleaseSharedMemory(&SharedMem0); 541 TEEC_ReleaseSharedMemory(&SharedMem1); 542 TEEC_CloseSession(&TeecSession); 543 TEEC_FinalizeContext(&TeecContext); 544 debug("testmm end\n"); 545 546 return TeecResult; 547 } 548 549 uint32_t trusty_write_permanent_attributes_cer(uint8_t *attributes, 550 uint32_t size) 551 { 552 TEEC_Result TeecResult; 553 TEEC_Context TeecContext; 554 TEEC_Session TeecSession; 555 uint32_t ErrorOrigin; 556 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 557 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 558 TEEC_UUID *TeecUuid = &tempuuid; 559 TEEC_Operation TeecOperation = {0}; 560 struct blk_desc *dev_desc; 561 562 dev_desc = rockchip_get_bootdev(); 563 if (!dev_desc) { 564 printf("%s: dev_desc is NULL!\n", __func__); 565 return -TEEC_ERROR_GENERIC; 566 } 567 568 debug("testmm start\n"); 569 OpteeClientApiLibInitialize(); 570 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 571 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 572 TEEC_NONE, 573 TEEC_NONE, 574 TEEC_NONE); 575 /*0 nand or emmc "security" partition , 1 rpmb*/ 576 TeecOperation.params[0].value.a = 577 (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 578 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 579 TeecOperation.params[0].value.a = 0; 580 #endif 581 582 TeecResult = TEEC_OpenSession(&TeecContext, 583 &TeecSession, 584 TeecUuid, 585 TEEC_LOGIN_PUBLIC, 586 NULL, 587 &TeecOperation, 588 &ErrorOrigin); 589 590 TEEC_SharedMemory SharedMem0 = {0}; 591 592 SharedMem0.size = sizeof("rsacer"); 593 SharedMem0.flags = 0; 594 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 595 memcpy(SharedMem0.buffer, "rsacer", SharedMem0.size); 596 TEEC_SharedMemory SharedMem1 = {0}; 597 598 SharedMem1.size = size; 599 SharedMem1.flags = 0; 600 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 601 memcpy(SharedMem1.buffer, attributes, SharedMem1.size); 602 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 603 TeecOperation.params[0].tmpref.size = SharedMem0.size; 604 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 605 TeecOperation.params[1].tmpref.size = SharedMem1.size; 606 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 607 TEEC_MEMREF_TEMP_INOUT, 608 TEEC_NONE, 609 TEEC_NONE); 610 611 TeecResult = TEEC_InvokeCommand(&TeecSession, 612 1, 613 &TeecOperation, 614 &ErrorOrigin); 615 616 TEEC_ReleaseSharedMemory(&SharedMem0); 617 TEEC_ReleaseSharedMemory(&SharedMem1); 618 TEEC_CloseSession(&TeecSession); 619 TEEC_FinalizeContext(&TeecContext); 620 debug("testmm end\n"); 621 622 return TeecResult; 623 } 624 625 uint32_t trusty_read_lock_state(uint8_t *lock_state) 626 { 627 TEEC_Result TeecResult; 628 TEEC_Context TeecContext; 629 TEEC_Session TeecSession; 630 uint32_t ErrorOrigin; 631 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 632 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 633 TEEC_UUID *TeecUuid = &tempuuid; 634 TEEC_Operation TeecOperation = {0}; 635 struct blk_desc *dev_desc; 636 dev_desc = rockchip_get_bootdev(); 637 if (!dev_desc) { 638 printf("%s: dev_desc is NULL!\n", __func__); 639 return -TEEC_ERROR_GENERIC; 640 } 641 642 debug("testmm start\n"); 643 OpteeClientApiLibInitialize(); 644 645 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 646 647 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 648 TEEC_NONE, 649 TEEC_NONE, 650 TEEC_NONE); 651 /*0 nand or emmc "security" partition , 1 rpmb*/ 652 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 653 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 654 TeecOperation.params[0].value.a = 0; 655 #endif 656 657 TeecResult = TEEC_OpenSession(&TeecContext, 658 &TeecSession, 659 TeecUuid, 660 TEEC_LOGIN_PUBLIC, 661 NULL, 662 &TeecOperation, 663 &ErrorOrigin); 664 665 TEEC_SharedMemory SharedMem0 = {0}; 666 667 SharedMem0.size = sizeof("lock_state"); 668 SharedMem0.flags = 0; 669 670 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 671 672 memcpy(SharedMem0.buffer, "lock_state", SharedMem0.size); 673 674 TEEC_SharedMemory SharedMem1 = {0}; 675 676 SharedMem1.size = 1; 677 SharedMem1.flags = 0; 678 679 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 680 681 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 682 TeecOperation.params[0].tmpref.size = SharedMem0.size; 683 684 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 685 TeecOperation.params[1].tmpref.size = SharedMem1.size; 686 687 688 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 689 TEEC_MEMREF_TEMP_INOUT, 690 TEEC_NONE, 691 TEEC_NONE); 692 693 TeecResult = TEEC_InvokeCommand(&TeecSession, 694 0, 695 &TeecOperation, 696 &ErrorOrigin); 697 if (TeecResult == TEEC_SUCCESS) 698 memcpy(lock_state, SharedMem1.buffer, SharedMem1.size); 699 TEEC_ReleaseSharedMemory(&SharedMem0); 700 TEEC_ReleaseSharedMemory(&SharedMem1); 701 TEEC_CloseSession(&TeecSession); 702 TEEC_FinalizeContext(&TeecContext); 703 debug("testmm end\n"); 704 705 return TeecResult; 706 } 707 708 uint32_t trusty_write_lock_state(uint8_t lock_state) 709 { 710 TEEC_Result TeecResult; 711 TEEC_Context TeecContext; 712 TEEC_Session TeecSession; 713 uint32_t ErrorOrigin; 714 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 715 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 716 TEEC_UUID *TeecUuid = &tempuuid; 717 TEEC_Operation TeecOperation = {0}; 718 struct blk_desc *dev_desc; 719 dev_desc = rockchip_get_bootdev(); 720 if (!dev_desc) { 721 printf("%s: dev_desc is NULL!\n", __func__); 722 return -TEEC_ERROR_GENERIC; 723 } 724 725 debug("testmm start\n"); 726 OpteeClientApiLibInitialize(); 727 728 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 729 730 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 731 TEEC_NONE, 732 TEEC_NONE, 733 TEEC_NONE); 734 /*0 nand or emmc "security" partition , 1 rpmb*/ 735 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 736 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 737 TeecOperation.params[0].value.a = 0; 738 #endif 739 740 TeecResult = TEEC_OpenSession(&TeecContext, 741 &TeecSession, 742 TeecUuid, 743 TEEC_LOGIN_PUBLIC, 744 NULL, 745 &TeecOperation, 746 &ErrorOrigin); 747 748 TEEC_SharedMemory SharedMem0 = {0}; 749 750 SharedMem0.size = sizeof("lock_state"); 751 SharedMem0.flags = 0; 752 753 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 754 755 memcpy(SharedMem0.buffer, "lock_state", SharedMem0.size); 756 757 TEEC_SharedMemory SharedMem1 = {0}; 758 759 SharedMem1.size = 1; 760 SharedMem1.flags = 0; 761 762 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 763 764 memcpy(SharedMem1.buffer, &lock_state, SharedMem1.size); 765 766 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 767 TeecOperation.params[0].tmpref.size = SharedMem0.size; 768 769 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 770 TeecOperation.params[1].tmpref.size = SharedMem1.size; 771 772 773 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 774 TEEC_MEMREF_TEMP_INOUT, 775 TEEC_NONE, 776 TEEC_NONE); 777 778 TeecResult = TEEC_InvokeCommand(&TeecSession, 779 1, 780 &TeecOperation, 781 &ErrorOrigin); 782 783 TEEC_ReleaseSharedMemory(&SharedMem0); 784 TEEC_ReleaseSharedMemory(&SharedMem1); 785 TEEC_CloseSession(&TeecSession); 786 TEEC_FinalizeContext(&TeecContext); 787 debug("testmm end\n"); 788 789 return TeecResult; 790 } 791 792 uint32_t trusty_read_flash_lock_state(uint8_t *flash_lock_state) 793 { 794 TEEC_Result TeecResult; 795 TEEC_Context TeecContext; 796 TEEC_Session TeecSession; 797 uint32_t ErrorOrigin; 798 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 799 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 800 TEEC_UUID *TeecUuid = &tempuuid; 801 TEEC_Operation TeecOperation = {0}; 802 struct blk_desc *dev_desc; 803 dev_desc = rockchip_get_bootdev(); 804 if (!dev_desc) { 805 printf("%s: dev_desc is NULL!\n", __func__); 806 return -TEEC_ERROR_GENERIC; 807 } 808 809 debug("testmm start\n"); 810 OpteeClientApiLibInitialize(); 811 812 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 813 814 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 815 TEEC_NONE, 816 TEEC_NONE, 817 TEEC_NONE); 818 /*0 nand or emmc "security" partition , 1 rpmb*/ 819 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 820 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 821 TeecOperation.params[0].value.a = 0; 822 #endif 823 824 TeecResult = TEEC_OpenSession(&TeecContext, 825 &TeecSession, 826 TeecUuid, 827 TEEC_LOGIN_PUBLIC, 828 NULL, 829 &TeecOperation, 830 &ErrorOrigin); 831 832 TEEC_SharedMemory SharedMem0 = {0}; 833 834 SharedMem0.size = sizeof("flash_lock_state"); 835 SharedMem0.flags = 0; 836 837 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 838 839 memcpy(SharedMem0.buffer, "flash_lock_state", SharedMem0.size); 840 841 TEEC_SharedMemory SharedMem1 = {0}; 842 843 SharedMem1.size = 1; 844 SharedMem1.flags = 0; 845 846 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 847 848 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 849 TeecOperation.params[0].tmpref.size = SharedMem0.size; 850 851 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 852 TeecOperation.params[1].tmpref.size = SharedMem1.size; 853 854 855 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 856 TEEC_MEMREF_TEMP_INOUT, 857 TEEC_NONE, 858 TEEC_NONE); 859 860 TeecResult = TEEC_InvokeCommand(&TeecSession, 861 0, 862 &TeecOperation, 863 &ErrorOrigin); 864 if (TeecResult == TEEC_SUCCESS) 865 memcpy(flash_lock_state, SharedMem1.buffer, SharedMem1.size); 866 TEEC_ReleaseSharedMemory(&SharedMem0); 867 TEEC_ReleaseSharedMemory(&SharedMem1); 868 TEEC_CloseSession(&TeecSession); 869 TEEC_FinalizeContext(&TeecContext); 870 debug("testmm end\n"); 871 872 return TeecResult; 873 } 874 875 876 uint32_t trusty_write_flash_lock_state(uint8_t flash_lock_state) 877 { 878 TEEC_Result TeecResult; 879 TEEC_Context TeecContext; 880 TEEC_Session TeecSession; 881 uint32_t ErrorOrigin; 882 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 883 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 884 TEEC_UUID *TeecUuid = &tempuuid; 885 TEEC_Operation TeecOperation = {0}; 886 struct blk_desc *dev_desc; 887 dev_desc = rockchip_get_bootdev(); 888 if (!dev_desc) { 889 printf("%s: dev_desc is NULL!\n", __func__); 890 return -TEEC_ERROR_GENERIC; 891 } 892 893 debug("testmm start\n"); 894 OpteeClientApiLibInitialize(); 895 896 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 897 898 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 899 TEEC_NONE, 900 TEEC_NONE, 901 TEEC_NONE); 902 /*0 nand or emmc "security" partition , 1 rpmb*/ 903 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 904 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 905 TeecOperation.params[0].value.a = 0; 906 #endif 907 908 TeecResult = TEEC_OpenSession(&TeecContext, 909 &TeecSession, 910 TeecUuid, 911 TEEC_LOGIN_PUBLIC, 912 NULL, 913 &TeecOperation, 914 &ErrorOrigin); 915 916 TEEC_SharedMemory SharedMem0 = {0}; 917 918 SharedMem0.size = sizeof("flash_lock_state"); 919 SharedMem0.flags = 0; 920 921 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 922 923 memcpy(SharedMem0.buffer, "flash_lock_state", SharedMem0.size); 924 925 TEEC_SharedMemory SharedMem1 = {0}; 926 927 SharedMem1.size = 1; 928 SharedMem1.flags = 0; 929 930 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 931 932 memcpy(SharedMem1.buffer, &flash_lock_state, SharedMem1.size); 933 934 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 935 TeecOperation.params[0].tmpref.size = SharedMem0.size; 936 937 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 938 TeecOperation.params[1].tmpref.size = SharedMem1.size; 939 940 941 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 942 TEEC_MEMREF_TEMP_INOUT, 943 TEEC_NONE, 944 TEEC_NONE); 945 946 TeecResult = TEEC_InvokeCommand(&TeecSession, 947 1, 948 &TeecOperation, 949 &ErrorOrigin); 950 951 TEEC_ReleaseSharedMemory(&SharedMem0); 952 TEEC_ReleaseSharedMemory(&SharedMem1); 953 TEEC_CloseSession(&TeecSession); 954 TEEC_FinalizeContext(&TeecContext); 955 debug("testmm end\n"); 956 957 return TeecResult; 958 } 959 960 uint32_t trusty_read_attribute_hash(uint32_t *buf, uint32_t length) 961 { 962 TEEC_Result TeecResult; 963 TEEC_Context TeecContext; 964 TEEC_Session TeecSession; 965 uint32_t ErrorOrigin; 966 967 TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8, \ 968 { 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } }; 969 TEEC_UUID *TeecUuid = &tempuuid; 970 TEEC_Operation TeecOperation = {0}; 971 972 OpteeClientApiLibInitialize(); 973 974 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 975 976 TeecResult = TEEC_OpenSession(&TeecContext, 977 &TeecSession, 978 TeecUuid, 979 TEEC_LOGIN_PUBLIC, 980 NULL, 981 NULL, 982 &ErrorOrigin); 983 984 TEEC_SharedMemory SharedMem0 = {0}; 985 986 SharedMem0.size = length * sizeof(uint32_t); 987 SharedMem0.flags = 0; 988 989 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 990 991 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 992 TeecOperation.params[0].tmpref.size = SharedMem0.size; 993 994 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, 995 TEEC_NONE, 996 TEEC_NONE, 997 TEEC_NONE); 998 999 TeecResult = TEEC_InvokeCommand(&TeecSession, 1000 0, 1001 &TeecOperation, 1002 &ErrorOrigin); 1003 1004 if (TeecResult == TEEC_SUCCESS) 1005 memcpy(buf, SharedMem0.buffer, SharedMem0.size); 1006 1007 TEEC_ReleaseSharedMemory(&SharedMem0); 1008 TEEC_CloseSession(&TeecSession); 1009 TEEC_FinalizeContext(&TeecContext); 1010 1011 return TeecResult; 1012 } 1013 1014 uint32_t trusty_write_attribute_hash(uint32_t *buf, uint32_t length) 1015 { 1016 TEEC_Result TeecResult; 1017 TEEC_Context TeecContext; 1018 TEEC_Session TeecSession; 1019 uint32_t ErrorOrigin; 1020 1021 TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8, \ 1022 { 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } }; 1023 TEEC_UUID *TeecUuid = &tempuuid; 1024 TEEC_Operation TeecOperation = {0}; 1025 1026 OpteeClientApiLibInitialize(); 1027 1028 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1029 1030 TeecResult = TEEC_OpenSession(&TeecContext, 1031 &TeecSession, 1032 TeecUuid, 1033 TEEC_LOGIN_PUBLIC, 1034 NULL, 1035 NULL, 1036 &ErrorOrigin); 1037 1038 TEEC_SharedMemory SharedMem0 = {0}; 1039 1040 SharedMem0.size = length * sizeof(uint32_t); 1041 SharedMem0.flags = 0; 1042 1043 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1044 1045 memcpy(SharedMem0.buffer, buf, SharedMem0.size); 1046 1047 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1048 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1049 1050 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 1051 TEEC_NONE, 1052 TEEC_NONE, 1053 TEEC_NONE); 1054 1055 TeecResult = TEEC_InvokeCommand(&TeecSession, 1056 1, 1057 &TeecOperation, 1058 &ErrorOrigin); 1059 1060 TEEC_ReleaseSharedMemory(&SharedMem0); 1061 TEEC_CloseSession(&TeecSession); 1062 TEEC_FinalizeContext(&TeecContext); 1063 1064 return TeecResult; 1065 } 1066 1067 uint32_t notify_optee_rpmb_ta(void) 1068 { 1069 TEEC_Result TeecResult; 1070 TEEC_Context TeecContext; 1071 TEEC_Session TeecSession; 1072 uint32_t ErrorOrigin; 1073 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 1074 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 1075 TEEC_UUID *TeecUuid = &tempuuid; 1076 TEEC_Operation TeecOperation = {0}; 1077 1078 OpteeClientApiLibInitialize(); 1079 1080 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1081 1082 TeecResult = TEEC_OpenSession(&TeecContext, 1083 &TeecSession, 1084 TeecUuid, 1085 TEEC_LOGIN_PUBLIC, 1086 NULL, 1087 NULL, 1088 &ErrorOrigin); 1089 1090 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, 1091 TEEC_NONE, 1092 TEEC_NONE, 1093 TEEC_NONE); 1094 1095 TeecResult = TEEC_InvokeCommand(&TeecSession, 1096 2, 1097 &TeecOperation, 1098 &ErrorOrigin); 1099 1100 TEEC_CloseSession(&TeecSession); 1101 TEEC_FinalizeContext(&TeecContext); 1102 1103 return TeecResult; 1104 } 1105 1106 uint32_t notify_optee_efuse_ta(void) 1107 { 1108 TEEC_Result TeecResult; 1109 TEEC_Context TeecContext; 1110 TEEC_Session TeecSession; 1111 uint32_t ErrorOrigin; 1112 TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8, \ 1113 { 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } }; 1114 1115 TEEC_UUID *TeecUuid = &tempuuid; 1116 TEEC_Operation TeecOperation = {0}; 1117 1118 OpteeClientApiLibInitialize(); 1119 1120 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1121 1122 TeecResult = TEEC_OpenSession(&TeecContext, 1123 &TeecSession, 1124 TeecUuid, 1125 TEEC_LOGIN_PUBLIC, 1126 NULL, 1127 NULL, 1128 &ErrorOrigin); 1129 1130 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, 1131 TEEC_NONE, 1132 TEEC_NONE, 1133 TEEC_NONE); 1134 1135 TeecResult = TEEC_InvokeCommand(&TeecSession, 1136 2, 1137 &TeecOperation, 1138 &ErrorOrigin); 1139 1140 TEEC_CloseSession(&TeecSession); 1141 TEEC_FinalizeContext(&TeecContext); 1142 1143 return TeecResult; 1144 } 1145 1146 uint32_t trusty_notify_optee_uboot_end(void) 1147 { 1148 TEEC_Result res; 1149 res = notify_optee_rpmb_ta(); 1150 res |= notify_optee_efuse_ta(); 1151 return res; 1152 } 1153 1154 uint32_t trusty_read_vbootkey_hash(uint32_t *buf, uint32_t length) 1155 { 1156 TEEC_Result TeecResult; 1157 TEEC_Context TeecContext; 1158 TEEC_Session TeecSession; 1159 uint32_t ErrorOrigin; 1160 1161 TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8, \ 1162 { 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } }; 1163 TEEC_UUID *TeecUuid = &tempuuid; 1164 TEEC_Operation TeecOperation = {0}; 1165 1166 OpteeClientApiLibInitialize(); 1167 1168 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1169 1170 TeecResult = TEEC_OpenSession(&TeecContext, 1171 &TeecSession, 1172 TeecUuid, 1173 TEEC_LOGIN_PUBLIC, 1174 NULL, 1175 NULL, 1176 &ErrorOrigin); 1177 1178 TEEC_SharedMemory SharedMem0 = {0}; 1179 1180 SharedMem0.size = length * sizeof(uint32_t); 1181 SharedMem0.flags = 0; 1182 1183 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1184 1185 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1186 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1187 1188 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, 1189 TEEC_NONE, 1190 TEEC_NONE, 1191 TEEC_NONE); 1192 1193 TeecResult = TEEC_InvokeCommand(&TeecSession, 1194 3, 1195 &TeecOperation, 1196 &ErrorOrigin); 1197 1198 if (TeecResult == TEEC_SUCCESS) 1199 memcpy(buf, SharedMem0.buffer, SharedMem0.size); 1200 1201 TEEC_ReleaseSharedMemory(&SharedMem0); 1202 TEEC_CloseSession(&TeecSession); 1203 TEEC_FinalizeContext(&TeecContext); 1204 1205 return TeecResult; 1206 } 1207 uint32_t trusty_write_vbootkey_hash(uint32_t *buf, uint32_t length) 1208 { 1209 TEEC_Result TeecResult; 1210 TEEC_Context TeecContext; 1211 TEEC_Session TeecSession; 1212 uint32_t ErrorOrigin; 1213 1214 TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8, \ 1215 { 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } }; 1216 TEEC_UUID *TeecUuid = &tempuuid; 1217 TEEC_Operation TeecOperation = {0}; 1218 1219 OpteeClientApiLibInitialize(); 1220 1221 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1222 1223 TeecResult = TEEC_OpenSession(&TeecContext, 1224 &TeecSession, 1225 TeecUuid, 1226 TEEC_LOGIN_PUBLIC, 1227 NULL, 1228 NULL, 1229 &ErrorOrigin); 1230 1231 TEEC_SharedMemory SharedMem0 = {0}; 1232 1233 SharedMem0.size = length * sizeof(uint32_t); 1234 SharedMem0.flags = 0; 1235 1236 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1237 1238 memcpy(SharedMem0.buffer, buf, SharedMem0.size); 1239 1240 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1241 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1242 1243 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 1244 TEEC_NONE, 1245 TEEC_NONE, 1246 TEEC_NONE); 1247 1248 TeecResult = TEEC_InvokeCommand(&TeecSession, 1249 4, 1250 &TeecOperation, 1251 &ErrorOrigin); 1252 1253 TEEC_ReleaseSharedMemory(&SharedMem0); 1254 TEEC_CloseSession(&TeecSession); 1255 TEEC_FinalizeContext(&TeecContext); 1256 1257 return TeecResult; 1258 } 1259 1260 uint32_t trusty_read_vbootkey_enable_flag(uint8_t *flag) 1261 { 1262 TEEC_Result TeecResult; 1263 TEEC_Context TeecContext; 1264 TEEC_Session TeecSession; 1265 uint32_t ErrorOrigin; 1266 uint32_t bootflag; 1267 1268 TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8, \ 1269 { 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } }; 1270 TEEC_UUID *TeecUuid = &tempuuid; 1271 TEEC_Operation TeecOperation = {0}; 1272 1273 OpteeClientApiLibInitialize(); 1274 1275 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1276 1277 TeecResult = TEEC_OpenSession(&TeecContext, 1278 &TeecSession, 1279 TeecUuid, 1280 TEEC_LOGIN_PUBLIC, 1281 NULL, 1282 NULL, 1283 &ErrorOrigin); 1284 1285 TEEC_SharedMemory SharedMem0 = {0}; 1286 1287 SharedMem0.size = 1 * sizeof(uint32_t); 1288 SharedMem0.flags = 0; 1289 1290 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1291 1292 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1293 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1294 1295 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, 1296 TEEC_NONE, 1297 TEEC_NONE, 1298 TEEC_NONE); 1299 1300 TeecResult = TEEC_InvokeCommand(&TeecSession, 1301 5, 1302 &TeecOperation, 1303 &ErrorOrigin); 1304 1305 if (TeecResult == TEEC_SUCCESS) { 1306 memcpy(&bootflag, SharedMem0.buffer, SharedMem0.size); 1307 if (bootflag == 0x000000FF) 1308 *flag = 1; 1309 } 1310 1311 TEEC_ReleaseSharedMemory(&SharedMem0); 1312 TEEC_CloseSession(&TeecSession); 1313 TEEC_FinalizeContext(&TeecContext); 1314 1315 return TeecResult; 1316 } 1317 1318 uint32_t trusty_read_permanent_attributes_flag(uint8_t *attributes) 1319 { 1320 TEEC_Result TeecResult; 1321 TEEC_Context TeecContext; 1322 TEEC_Session TeecSession; 1323 uint32_t ErrorOrigin; 1324 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 1325 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 1326 TEEC_UUID *TeecUuid = &tempuuid; 1327 TEEC_Operation TeecOperation = {0}; 1328 struct blk_desc *dev_desc; 1329 dev_desc = rockchip_get_bootdev(); 1330 if (!dev_desc) { 1331 printf("%s: dev_desc is NULL!\n", __func__); 1332 return -TEEC_ERROR_GENERIC; 1333 } 1334 1335 debug("testmm start\n"); 1336 OpteeClientApiLibInitialize(); 1337 1338 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1339 1340 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 1341 TEEC_NONE, 1342 TEEC_NONE, 1343 TEEC_NONE); 1344 /*0 nand or emmc "security" partition , 1 rpmb*/ 1345 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 1346 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 1347 TeecOperation.params[0].value.a = 0; 1348 #endif 1349 1350 TeecResult = TEEC_OpenSession(&TeecContext, 1351 &TeecSession, 1352 TeecUuid, 1353 TEEC_LOGIN_PUBLIC, 1354 NULL, 1355 &TeecOperation, 1356 &ErrorOrigin); 1357 1358 TEEC_SharedMemory SharedMem0 = {0}; 1359 1360 SharedMem0.size = sizeof("attributes_flag"); 1361 SharedMem0.flags = 0; 1362 1363 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1364 1365 memcpy(SharedMem0.buffer, "attributes_flag", SharedMem0.size); 1366 1367 TEEC_SharedMemory SharedMem1 = {0}; 1368 1369 SharedMem1.size = 1; 1370 SharedMem1.flags = 0; 1371 1372 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 1373 1374 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1375 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1376 1377 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 1378 TeecOperation.params[1].tmpref.size = SharedMem1.size; 1379 1380 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 1381 TEEC_MEMREF_TEMP_INOUT, 1382 TEEC_NONE, 1383 TEEC_NONE); 1384 1385 TeecResult = TEEC_InvokeCommand(&TeecSession, 1386 0, 1387 &TeecOperation, 1388 &ErrorOrigin); 1389 if (TeecResult == TEEC_SUCCESS) 1390 memcpy(attributes, SharedMem1.buffer, SharedMem1.size); 1391 TEEC_ReleaseSharedMemory(&SharedMem0); 1392 TEEC_ReleaseSharedMemory(&SharedMem1); 1393 TEEC_CloseSession(&TeecSession); 1394 TEEC_FinalizeContext(&TeecContext); 1395 debug("testmm end\n"); 1396 1397 return TeecResult; 1398 } 1399 1400 uint32_t trusty_write_permanent_attributes_flag(uint8_t attributes) 1401 { 1402 TEEC_Result TeecResult; 1403 TEEC_Context TeecContext; 1404 TEEC_Session TeecSession; 1405 uint32_t ErrorOrigin; 1406 TEEC_UUID tempuuid = { 0x1b484ea5, 0x698b, 0x4142, 1407 { 0x82, 0xb8, 0x3a, 0xcf, 0x16, 0xe9, 0x9e, 0x2a } }; 1408 TEEC_UUID *TeecUuid = &tempuuid; 1409 TEEC_Operation TeecOperation = {0}; 1410 struct blk_desc *dev_desc; 1411 dev_desc = rockchip_get_bootdev(); 1412 if (!dev_desc) { 1413 printf("%s: dev_desc is NULL!\n", __func__); 1414 return -TEEC_ERROR_GENERIC; 1415 } 1416 1417 debug("testmm start\n"); 1418 OpteeClientApiLibInitialize(); 1419 1420 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1421 1422 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 1423 TEEC_NONE, 1424 TEEC_NONE, 1425 TEEC_NONE); 1426 /*0 nand or emmc "security" partition , 1 rpmb*/ 1427 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 1428 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 1429 TeecOperation.params[0].value.a = 0; 1430 #endif 1431 1432 TeecResult = TEEC_OpenSession(&TeecContext, 1433 &TeecSession, 1434 TeecUuid, 1435 TEEC_LOGIN_PUBLIC, 1436 NULL, 1437 &TeecOperation, 1438 &ErrorOrigin); 1439 1440 TEEC_SharedMemory SharedMem0 = {0}; 1441 1442 SharedMem0.size = sizeof("attributes_flag"); 1443 SharedMem0.flags = 0; 1444 1445 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1446 1447 memcpy(SharedMem0.buffer, "attributes_flag", SharedMem0.size); 1448 1449 TEEC_SharedMemory SharedMem1 = {0}; 1450 1451 SharedMem1.size = 1; 1452 SharedMem1.flags = 0; 1453 1454 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 1455 1456 memcpy(SharedMem1.buffer, (char *)&attributes, SharedMem1.size); 1457 1458 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1459 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1460 1461 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 1462 TeecOperation.params[1].tmpref.size = SharedMem1.size; 1463 1464 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, 1465 TEEC_MEMREF_TEMP_INOUT, 1466 TEEC_NONE, 1467 TEEC_NONE); 1468 1469 TeecResult = TEEC_InvokeCommand(&TeecSession, 1470 1, 1471 &TeecOperation, 1472 &ErrorOrigin); 1473 1474 TEEC_ReleaseSharedMemory(&SharedMem0); 1475 TEEC_ReleaseSharedMemory(&SharedMem1); 1476 TEEC_CloseSession(&TeecSession); 1477 TEEC_FinalizeContext(&TeecContext); 1478 debug("testmm end\n"); 1479 1480 return TeecResult; 1481 } 1482 1483 uint32_t trusty_attest_dh(uint8_t *dh, uint32_t *dh_size) 1484 { 1485 TEEC_Result TeecResult; 1486 TEEC_Context TeecContext; 1487 TEEC_Session TeecSession; 1488 uint32_t ErrorOrigin; 1489 TEEC_UUID tempuuid = { 0x258be795, 0xf9ca, 0x40e6, 1490 { 0xa8, 0x69, 0x9c, 0xe6, 1491 0x88, 0x6c, 0x5d, 0x5d 1492 } 1493 }; 1494 TEEC_UUID *TeecUuid = &tempuuid; 1495 TEEC_Operation TeecOperation = {0}; 1496 struct blk_desc *dev_desc; 1497 dev_desc = rockchip_get_bootdev(); 1498 if (!dev_desc) { 1499 printf("%s: dev_desc is NULL!\n", __func__); 1500 return -TEEC_ERROR_GENERIC; 1501 } 1502 1503 OpteeClientApiLibInitialize(); 1504 1505 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1506 1507 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 1508 TEEC_NONE, 1509 TEEC_NONE, 1510 TEEC_NONE); 1511 /*0 nand or emmc "security" partition , 1 rpmb*/ 1512 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 1513 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 1514 TeecOperation.params[0].value.a = 0; 1515 #endif 1516 1517 TeecResult = TEEC_OpenSession(&TeecContext, 1518 &TeecSession, 1519 TeecUuid, 1520 TEEC_LOGIN_PUBLIC, 1521 NULL, 1522 &TeecOperation, 1523 &ErrorOrigin); 1524 1525 TEEC_SharedMemory SharedMem0 = {0}; 1526 1527 SharedMem0.size = *dh_size; 1528 SharedMem0.flags = 0; 1529 1530 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1531 1532 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1533 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1534 1535 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, 1536 TEEC_NONE, 1537 TEEC_NONE, 1538 TEEC_NONE); 1539 1540 TeecResult = TEEC_InvokeCommand(&TeecSession, 1541 143, 1542 &TeecOperation, 1543 &ErrorOrigin); 1544 1545 *dh_size = TeecOperation.params[0].tmpref.size; 1546 memcpy(dh, SharedMem0.buffer, SharedMem0.size); 1547 1548 TEEC_ReleaseSharedMemory(&SharedMem0); 1549 1550 TEEC_CloseSession(&TeecSession); 1551 TeecResult = TEEC_FinalizeContext(&TeecContext); 1552 1553 return TeecResult; 1554 } 1555 1556 uint32_t trusty_attest_uuid(uint8_t *uuid, uint32_t *uuid_size) 1557 { 1558 TEEC_Result TeecResult; 1559 TEEC_Context TeecContext; 1560 TEEC_Session TeecSession; 1561 uint32_t ErrorOrigin; 1562 TEEC_UUID tempuuid = { 0x258be795, 0xf9ca, 0x40e6, 1563 { 0xa8, 0x69, 0x9c, 0xe6, 1564 0x88, 0x6c, 0x5d, 0x5d 1565 } 1566 }; 1567 TEEC_UUID *TeecUuid = &tempuuid; 1568 TEEC_Operation TeecOperation = {0}; 1569 struct blk_desc *dev_desc; 1570 dev_desc = rockchip_get_bootdev(); 1571 if (!dev_desc) { 1572 printf("%s: dev_desc is NULL!\n", __func__); 1573 return -TEEC_ERROR_GENERIC; 1574 } 1575 1576 OpteeClientApiLibInitialize(); 1577 1578 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1579 1580 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 1581 TEEC_NONE, 1582 TEEC_NONE, 1583 TEEC_NONE); 1584 /*0 nand or emmc "security" partition , 1 rpmb*/ 1585 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 1586 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 1587 TeecOperation.params[0].value.a = 0; 1588 #endif 1589 1590 TeecResult = TEEC_OpenSession(&TeecContext, 1591 &TeecSession, 1592 TeecUuid, 1593 TEEC_LOGIN_PUBLIC, 1594 NULL, 1595 &TeecOperation, 1596 &ErrorOrigin); 1597 1598 TEEC_SharedMemory SharedMem0 = {0}; 1599 1600 SharedMem0.size = *uuid_size; 1601 SharedMem0.flags = 0; 1602 1603 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1604 1605 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1606 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1607 1608 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, 1609 TEEC_NONE, 1610 TEEC_NONE, 1611 TEEC_NONE); 1612 1613 TeecResult = TEEC_InvokeCommand(&TeecSession, 1614 144, 1615 &TeecOperation, 1616 &ErrorOrigin); 1617 1618 *uuid_size = TeecOperation.params[0].tmpref.size; 1619 memcpy(uuid, SharedMem0.buffer, SharedMem0.size); 1620 1621 TEEC_ReleaseSharedMemory(&SharedMem0); 1622 1623 TEEC_CloseSession(&TeecSession); 1624 TeecResult = TEEC_FinalizeContext(&TeecContext); 1625 1626 return TeecResult; 1627 } 1628 1629 uint32_t trusty_attest_get_ca(uint8_t *operation_start, 1630 uint32_t *operation_size, 1631 uint8_t *out, 1632 uint32_t *out_len) 1633 { 1634 TEEC_Result TeecResult; 1635 TEEC_Context TeecContext; 1636 TEEC_Session TeecSession; 1637 uint32_t ErrorOrigin; 1638 1639 OpteeClientApiLibInitialize(); 1640 1641 TEEC_UUID tempuuid = { 0x258be795, 0xf9ca, 0x40e6, 1642 { 0xa8, 0x69, 0x9c, 0xe6, 1643 0x88, 0x6c, 0x5d, 0x5d 1644 } 1645 }; 1646 1647 TEEC_UUID *TeecUuid = &tempuuid; 1648 TEEC_Operation TeecOperation = {0}; 1649 struct blk_desc *dev_desc; 1650 dev_desc = rockchip_get_bootdev(); 1651 if (!dev_desc) { 1652 printf("%s: dev_desc is NULL!\n", __func__); 1653 return -TEEC_ERROR_GENERIC; 1654 } 1655 1656 OpteeClientApiLibInitialize(); 1657 1658 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1659 1660 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 1661 TEEC_NONE, 1662 TEEC_NONE, 1663 TEEC_NONE); 1664 /*0 nand or emmc "security" partition , 1 rpmb*/ 1665 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 1666 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 1667 TeecOperation.params[0].value.a = 0; 1668 #endif 1669 1670 TeecResult = TEEC_OpenSession(&TeecContext, 1671 &TeecSession, 1672 TeecUuid, 1673 TEEC_LOGIN_PUBLIC, 1674 NULL, 1675 &TeecOperation, 1676 &ErrorOrigin); 1677 1678 TEEC_SharedMemory SharedMem0 = {0}; 1679 1680 SharedMem0.size = *operation_size; 1681 SharedMem0.flags = 0; 1682 1683 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1684 1685 memcpy(SharedMem0.buffer, operation_start, SharedMem0.size); 1686 1687 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1688 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1689 1690 TEEC_SharedMemory SharedMem1 = {0}; 1691 1692 SharedMem1.size = *out_len; 1693 SharedMem1.flags = 0; 1694 1695 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem1); 1696 1697 TeecOperation.params[1].tmpref.buffer = SharedMem1.buffer; 1698 TeecOperation.params[1].tmpref.size = SharedMem1.size; 1699 1700 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, 1701 TEEC_MEMREF_TEMP_INOUT, 1702 TEEC_NONE, 1703 TEEC_NONE); 1704 1705 TeecResult = TEEC_InvokeCommand(&TeecSession, 1706 145, 1707 &TeecOperation, 1708 &ErrorOrigin); 1709 1710 *out_len = TeecOperation.params[1].tmpref.size; 1711 memcpy(out, SharedMem1.buffer, SharedMem1.size); 1712 TEEC_ReleaseSharedMemory(&SharedMem0); 1713 TEEC_ReleaseSharedMemory(&SharedMem1); 1714 1715 return TeecResult; 1716 } 1717 1718 uint32_t trusty_attest_set_ca(uint8_t *ca_response, uint32_t *ca_response_size) 1719 { 1720 TEEC_Result TeecResult; 1721 TEEC_Context TeecContext; 1722 TEEC_Session TeecSession; 1723 uint32_t ErrorOrigin; 1724 TEEC_UUID tempuuid = { 0x258be795, 0xf9ca, 0x40e6, 1725 { 0xa8, 0x69, 0x9c, 0xe6, 1726 0x88, 0x6c, 0x5d, 0x5d 1727 } 1728 }; 1729 TEEC_UUID *TeecUuid = &tempuuid; 1730 TEEC_Operation TeecOperation = {0}; 1731 struct blk_desc *dev_desc; 1732 dev_desc = rockchip_get_bootdev(); 1733 if (!dev_desc) { 1734 printf("%s: dev_desc is NULL!\n", __func__); 1735 return -TEEC_ERROR_GENERIC; 1736 } 1737 1738 TeecResult = TEEC_InitializeContext(NULL, &TeecContext); 1739 1740 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, 1741 TEEC_NONE, 1742 TEEC_NONE, 1743 TEEC_NONE); 1744 /*0 nand or emmc "security" partition , 1 rpmb*/ 1745 TeecOperation.params[0].value.a = (dev_desc->if_type == IF_TYPE_MMC) ? 1 : 0; 1746 #ifdef CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION 1747 TeecOperation.params[0].value.a = 0; 1748 #endif 1749 1750 TeecResult = TEEC_OpenSession(&TeecContext, 1751 &TeecSession, 1752 TeecUuid, 1753 TEEC_LOGIN_PUBLIC, 1754 NULL, 1755 &TeecOperation, 1756 &ErrorOrigin); 1757 1758 TEEC_SharedMemory SharedMem0 = {0}; 1759 1760 SharedMem0.size = *ca_response_size; 1761 SharedMem0.flags = 0; 1762 1763 TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem0); 1764 1765 memcpy(SharedMem0.buffer, ca_response, SharedMem0.size); 1766 1767 TeecOperation.params[0].tmpref.buffer = SharedMem0.buffer; 1768 TeecOperation.params[0].tmpref.size = SharedMem0.size; 1769 1770 TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, 1771 TEEC_NONE, 1772 TEEC_NONE, 1773 TEEC_NONE); 1774 1775 TeecResult = TEEC_InvokeCommand(&TeecSession, 1776 146, 1777 &TeecOperation, 1778 &ErrorOrigin); 1779 1780 TEEC_ReleaseSharedMemory(&SharedMem0); 1781 1782 TEEC_CloseSession(&TeecSession); 1783 TeecResult = TEEC_FinalizeContext(&TeecContext); 1784 1785 return TeecResult; 1786 } 1787