1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2014, STMicroelectronics International N.V. 4 */ 5 6 /* Based on GP TEE Internal API Specification Version 0.27 */ 7 #ifndef TEE_INTERNAL_API_H 8 #define TEE_INTERNAL_API_H 9 10 #ifdef __TEE_API_COMPAT_H 11 #error "<tee_api_compat.h> must not be included before <tee_internal_api.h>" 12 #endif 13 14 #include <compiler.h> 15 #include <stddef.h> 16 #include <tee_api_defines.h> 17 #include <tee_api_types.h> 18 #include <trace.h> 19 20 /* Property access functions */ 21 22 TEE_Result TEE_GetPropertyAsString(TEE_PropSetHandle propsetOrEnumerator, 23 const char *name, char *valueBuffer, 24 size_t *valueBufferLen); 25 TEE_Result __GP11_TEE_GetPropertyAsString(TEE_PropSetHandle propsetOrEnumerator, 26 const char *name, char *valueBuffer, 27 uint32_t *valueBufferLen); 28 29 TEE_Result TEE_GetPropertyAsBool(TEE_PropSetHandle propsetOrEnumerator, 30 const char *name, bool *value); 31 32 TEE_Result TEE_GetPropertyAsU32(TEE_PropSetHandle propsetOrEnumerator, 33 const char *name, uint32_t *value); 34 35 TEE_Result TEE_GetPropertyAsU64(TEE_PropSetHandle propsetOrEnumerator, 36 const char *name, uint64_t *value); 37 38 TEE_Result TEE_GetPropertyAsBinaryBlock(TEE_PropSetHandle propsetOrEnumerator, 39 const char *name, void *valueBuffer, 40 size_t *valueBufferLen); 41 TEE_Result 42 __GP11_TEE_GetPropertyAsBinaryBlock(TEE_PropSetHandle propsetOrEnumerator, 43 const char *name, void *valueBuffer, 44 uint32_t *valueBufferLen); 45 46 TEE_Result TEE_GetPropertyAsUUID(TEE_PropSetHandle propsetOrEnumerator, 47 const char *name, TEE_UUID *value); 48 49 TEE_Result TEE_GetPropertyAsIdentity(TEE_PropSetHandle propsetOrEnumerator, 50 const char *name, TEE_Identity *value); 51 52 TEE_Result TEE_AllocatePropertyEnumerator(TEE_PropSetHandle *enumerator); 53 54 void TEE_FreePropertyEnumerator(TEE_PropSetHandle enumerator); 55 56 void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator, 57 TEE_PropSetHandle propSet); 58 59 void TEE_ResetPropertyEnumerator(TEE_PropSetHandle enumerator); 60 61 TEE_Result TEE_GetPropertyName(TEE_PropSetHandle enumerator, 62 void *nameBuffer, size_t *nameBufferLen); 63 TEE_Result __GP11_TEE_GetPropertyName(TEE_PropSetHandle enumerator, 64 void *nameBuffer, 65 uint32_t *nameBufferLen); 66 67 TEE_Result TEE_GetNextProperty(TEE_PropSetHandle enumerator); 68 69 /* System API - Misc */ 70 71 void TEE_Panic(TEE_Result panicCode); 72 73 /* System API - Internal Client API */ 74 75 TEE_Result TEE_OpenTASession(const TEE_UUID *destination, 76 uint32_t cancellationRequestTimeout, 77 uint32_t paramTypes, 78 TEE_Param params[TEE_NUM_PARAMS], 79 TEE_TASessionHandle *session, 80 uint32_t *returnOrigin); 81 TEE_Result __GP11_TEE_OpenTASession(const TEE_UUID *destination, 82 uint32_t cancellationRequestTimeout, 83 uint32_t paramTypes, 84 __GP11_TEE_Param params[TEE_NUM_PARAMS], 85 TEE_TASessionHandle *session, 86 uint32_t *returnOrigin); 87 88 void TEE_CloseTASession(TEE_TASessionHandle session); 89 90 TEE_Result TEE_InvokeTACommand(TEE_TASessionHandle session, 91 uint32_t cancellationRequestTimeout, 92 uint32_t commandID, uint32_t paramTypes, 93 TEE_Param params[TEE_NUM_PARAMS], 94 uint32_t *returnOrigin); 95 TEE_Result __GP11_TEE_InvokeTACommand(TEE_TASessionHandle session, 96 uint32_t cancellationRequestTimeout, 97 uint32_t commandID, uint32_t paramTypes, 98 __GP11_TEE_Param params[TEE_NUM_PARAMS], 99 uint32_t *returnOrigin); 100 101 /* System API - Cancellations */ 102 103 bool TEE_GetCancellationFlag(void); 104 105 bool TEE_UnmaskCancellation(void); 106 107 bool TEE_MaskCancellation(void); 108 109 /* System API - Memory Management */ 110 111 TEE_Result TEE_CheckMemoryAccessRights(uint32_t accessFlags, void *buffer, 112 size_t size); 113 TEE_Result __GP11_TEE_CheckMemoryAccessRights(uint32_t accessFlags, 114 void *buffer, uint32_t size); 115 116 void TEE_SetInstanceData(const void *instanceData); 117 118 const void *TEE_GetInstanceData(void); 119 120 void *TEE_Malloc(size_t size, uint32_t hint); 121 void *__GP11_TEE_Malloc(uint32_t size, uint32_t hint); 122 123 void *TEE_Realloc(void *buffer, size_t newSize); 124 void *__GP11_TEE_Realloc(void *buffer, uint32_t newSize); 125 126 void TEE_Free(void *buffer); 127 128 void *TEE_MemMove(void *dest, const void *src, size_t size); 129 void *__GP11_TEE_MemMove(void *dest, const void *src, uint32_t size); 130 131 /* 132 * Note: TEE_MemCompare() has a constant-time implementation (execution time 133 * does not depend on buffer content but only on buffer size). It is the main 134 * difference with memcmp(). 135 */ 136 int32_t TEE_MemCompare(const void *buffer1, const void *buffer2, size_t size); 137 int32_t __GP11_TEE_MemCompare(const void *buffer1, const void *buffer2, 138 uint32_t size); 139 140 void TEE_MemFill(void *buff, uint32_t x, size_t size); 141 void __GP11_TEE_MemFill(void *buff, uint32_t x, uint32_t size); 142 143 /* Data and Key Storage API - Generic Object Functions */ 144 145 void TEE_GetObjectInfo(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo); 146 void __GP11_TEE_GetObjectInfo(TEE_ObjectHandle object, 147 __GP11_TEE_ObjectInfo *objectInfo); 148 149 TEE_Result TEE_GetObjectInfo1(TEE_ObjectHandle object, 150 TEE_ObjectInfo *objectInfo); 151 TEE_Result __GP11_TEE_GetObjectInfo1(TEE_ObjectHandle object, 152 __GP11_TEE_ObjectInfo *objectInfo); 153 154 void TEE_RestrictObjectUsage(TEE_ObjectHandle object, uint32_t objectUsage); 155 TEE_Result TEE_RestrictObjectUsage1(TEE_ObjectHandle object, 156 uint32_t objectUsage); 157 158 TEE_Result TEE_GetObjectBufferAttribute(TEE_ObjectHandle object, 159 uint32_t attributeID, void *buffer, 160 uint32_t *size); 161 162 TEE_Result TEE_GetObjectValueAttribute(TEE_ObjectHandle object, 163 uint32_t attributeID, uint32_t *a, 164 uint32_t *b); 165 166 void TEE_CloseObject(TEE_ObjectHandle object); 167 168 /* Data and Key Storage API - Transient Object Functions */ 169 170 TEE_Result TEE_AllocateTransientObject(TEE_ObjectType objectType, 171 uint32_t maxKeySize, 172 TEE_ObjectHandle *object); 173 174 void TEE_FreeTransientObject(TEE_ObjectHandle object); 175 176 void TEE_ResetTransientObject(TEE_ObjectHandle object); 177 178 TEE_Result TEE_PopulateTransientObject(TEE_ObjectHandle object, 179 const TEE_Attribute *attrs, 180 uint32_t attrCount); 181 TEE_Result __GP11_TEE_PopulateTransientObject(TEE_ObjectHandle object, 182 const __GP11_TEE_Attribute *attrs, 183 uint32_t attrCount); 184 185 void TEE_InitRefAttribute(TEE_Attribute *attr, uint32_t attributeID, 186 const void *buffer, uint32_t length); 187 void __GP11_TEE_InitRefAttribute(__GP11_TEE_Attribute *attr, 188 uint32_t attributeID, 189 const void *buffer, uint32_t length); 190 191 void TEE_InitValueAttribute(TEE_Attribute *attr, uint32_t attributeID, 192 uint32_t a, uint32_t b); 193 void __GP11_TEE_InitValueAttribute(__GP11_TEE_Attribute *attr, 194 uint32_t attributeID, 195 uint32_t a, uint32_t b); 196 197 void TEE_CopyObjectAttributes(TEE_ObjectHandle destObject, 198 TEE_ObjectHandle srcObject); 199 200 TEE_Result TEE_CopyObjectAttributes1(TEE_ObjectHandle destObject, 201 TEE_ObjectHandle srcObject); 202 203 TEE_Result TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize, 204 const TEE_Attribute *params, uint32_t paramCount); 205 TEE_Result __GP11_TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize, 206 const __GP11_TEE_Attribute *params, 207 uint32_t paramCount); 208 209 /* Data and Key Storage API - Persistent Object Functions */ 210 211 TEE_Result TEE_OpenPersistentObject(uint32_t storageID, const void *objectID, 212 uint32_t objectIDLen, uint32_t flags, 213 TEE_ObjectHandle *object); 214 215 TEE_Result TEE_CreatePersistentObject(uint32_t storageID, const void *objectID, 216 uint32_t objectIDLen, uint32_t flags, 217 TEE_ObjectHandle attributes, 218 const void *initialData, 219 uint32_t initialDataLen, 220 TEE_ObjectHandle *object); 221 222 void TEE_CloseAndDeletePersistentObject(TEE_ObjectHandle object); 223 224 TEE_Result TEE_CloseAndDeletePersistentObject1(TEE_ObjectHandle object); 225 226 TEE_Result TEE_RenamePersistentObject(TEE_ObjectHandle object, 227 const void *newObjectID, 228 uint32_t newObjectIDLen); 229 230 TEE_Result TEE_AllocatePersistentObjectEnumerator(TEE_ObjectEnumHandle * 231 objectEnumerator); 232 233 void TEE_FreePersistentObjectEnumerator(TEE_ObjectEnumHandle objectEnumerator); 234 235 void TEE_ResetPersistentObjectEnumerator(TEE_ObjectEnumHandle objectEnumerator); 236 237 TEE_Result TEE_StartPersistentObjectEnumerator(TEE_ObjectEnumHandle 238 objectEnumerator, 239 uint32_t storageID); 240 241 TEE_Result TEE_GetNextPersistentObject(TEE_ObjectEnumHandle objectEnumerator, 242 TEE_ObjectInfo *objectInfo, 243 void *objectID, uint32_t *objectIDLen); 244 TEE_Result 245 __GP11_TEE_GetNextPersistentObject(TEE_ObjectEnumHandle objectEnumerator, 246 __GP11_TEE_ObjectInfo *objectInfo, 247 void *objectID, uint32_t *objectIDLen); 248 249 /* Data and Key Storage API - Data Stream Access Functions */ 250 251 TEE_Result TEE_ReadObjectData(TEE_ObjectHandle object, void *buffer, 252 uint32_t size, uint32_t *count); 253 254 TEE_Result TEE_WriteObjectData(TEE_ObjectHandle object, const void *buffer, 255 uint32_t size); 256 257 TEE_Result TEE_TruncateObjectData(TEE_ObjectHandle object, uint32_t size); 258 259 TEE_Result TEE_SeekObjectData(TEE_ObjectHandle object, int32_t offset, 260 TEE_Whence whence); 261 262 /* Cryptographic Operations API - Generic Operation Functions */ 263 264 TEE_Result TEE_AllocateOperation(TEE_OperationHandle *operation, 265 uint32_t algorithm, uint32_t mode, 266 uint32_t maxKeySize); 267 268 void TEE_FreeOperation(TEE_OperationHandle operation); 269 270 void TEE_GetOperationInfo(TEE_OperationHandle operation, 271 TEE_OperationInfo *operationInfo); 272 273 TEE_Result 274 TEE_GetOperationInfoMultiple(TEE_OperationHandle operation, 275 TEE_OperationInfoMultiple *operationInfoMultiple, 276 uint32_t *operationSize); 277 278 void TEE_ResetOperation(TEE_OperationHandle operation); 279 280 TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, 281 TEE_ObjectHandle key); 282 283 TEE_Result TEE_SetOperationKey2(TEE_OperationHandle operation, 284 TEE_ObjectHandle key1, TEE_ObjectHandle key2); 285 286 void TEE_CopyOperation(TEE_OperationHandle dstOperation, 287 TEE_OperationHandle srcOperation); 288 289 TEE_Result TEE_IsAlgorithmSupported(uint32_t algId, uint32_t element); 290 291 /* Cryptographic Operations API - Message Digest Functions */ 292 293 void TEE_DigestUpdate(TEE_OperationHandle operation, 294 const void *chunk, uint32_t chunkSize); 295 296 TEE_Result TEE_DigestDoFinal(TEE_OperationHandle operation, const void *chunk, 297 uint32_t chunkLen, void *hash, uint32_t *hashLen); 298 299 /* Cryptographic Operations API - Symmetric Cipher Functions */ 300 301 void TEE_CipherInit(TEE_OperationHandle operation, const void *IV, 302 uint32_t IVLen); 303 304 TEE_Result TEE_CipherUpdate(TEE_OperationHandle operation, const void *srcData, 305 uint32_t srcLen, void *destData, uint32_t *destLen); 306 307 TEE_Result TEE_CipherDoFinal(TEE_OperationHandle operation, 308 const void *srcData, uint32_t srcLen, 309 void *destData, uint32_t *destLen); 310 311 /* Cryptographic Operations API - MAC Functions */ 312 313 void TEE_MACInit(TEE_OperationHandle operation, const void *IV, 314 uint32_t IVLen); 315 316 void TEE_MACUpdate(TEE_OperationHandle operation, const void *chunk, 317 uint32_t chunkSize); 318 319 TEE_Result TEE_MACComputeFinal(TEE_OperationHandle operation, 320 const void *message, uint32_t messageLen, 321 void *mac, uint32_t *macLen); 322 323 TEE_Result TEE_MACCompareFinal(TEE_OperationHandle operation, 324 const void *message, uint32_t messageLen, 325 const void *mac, uint32_t macLen); 326 327 /* Cryptographic Operations API - Authenticated Encryption Functions */ 328 329 TEE_Result TEE_AEInit(TEE_OperationHandle operation, const void *nonce, 330 uint32_t nonceLen, uint32_t tagLen, uint32_t AADLen, 331 uint32_t payloadLen); 332 333 void TEE_AEUpdateAAD(TEE_OperationHandle operation, const void *AADdata, 334 uint32_t AADdataLen); 335 336 TEE_Result TEE_AEUpdate(TEE_OperationHandle operation, const void *srcData, 337 uint32_t srcLen, void *destData, uint32_t *destLen); 338 339 TEE_Result TEE_AEEncryptFinal(TEE_OperationHandle operation, 340 const void *srcData, uint32_t srcLen, 341 void *destData, uint32_t *destLen, void *tag, 342 uint32_t *tagLen); 343 344 TEE_Result TEE_AEDecryptFinal(TEE_OperationHandle operation, 345 const void *srcData, uint32_t srcLen, 346 void *destData, uint32_t *destLen, void *tag, 347 uint32_t tagLen); 348 349 /* Cryptographic Operations API - Asymmetric Functions */ 350 351 TEE_Result TEE_AsymmetricEncrypt(TEE_OperationHandle operation, 352 const TEE_Attribute *params, 353 uint32_t paramCount, const void *srcData, 354 uint32_t srcLen, void *destData, 355 uint32_t *destLen); 356 TEE_Result __GP11_TEE_AsymmetricEncrypt(TEE_OperationHandle operation, 357 const __GP11_TEE_Attribute *params, 358 uint32_t paramCount, 359 const void *srcData, uint32_t srcLen, 360 void *destData, uint32_t *destLen); 361 362 TEE_Result TEE_AsymmetricDecrypt(TEE_OperationHandle operation, 363 const TEE_Attribute *params, 364 uint32_t paramCount, const void *srcData, 365 uint32_t srcLen, void *destData, 366 uint32_t *destLen); 367 TEE_Result __GP11_TEE_AsymmetricDecrypt(TEE_OperationHandle operation, 368 const __GP11_TEE_Attribute *params, 369 uint32_t paramCount, 370 const void *srcData, uint32_t srcLen, 371 void *destData, uint32_t *destLen); 372 373 TEE_Result TEE_AsymmetricSignDigest(TEE_OperationHandle operation, 374 const TEE_Attribute *params, 375 uint32_t paramCount, const void *digest, 376 uint32_t digestLen, void *signature, 377 uint32_t *signatureLen); 378 TEE_Result __GP11_TEE_AsymmetricSignDigest(TEE_OperationHandle operation, 379 const __GP11_TEE_Attribute *params, 380 uint32_t paramCount, 381 const void *digest, 382 uint32_t digestLen, void *signature, 383 uint32_t *signatureLen); 384 385 TEE_Result TEE_AsymmetricVerifyDigest(TEE_OperationHandle operation, 386 const TEE_Attribute *params, 387 uint32_t paramCount, const void *digest, 388 uint32_t digestLen, const void *signature, 389 uint32_t signatureLen); 390 TEE_Result __GP11_TEE_AsymmetricVerifyDigest(TEE_OperationHandle operation, 391 const __GP11_TEE_Attribute *params, 392 uint32_t paramCount, 393 const void *digest, 394 uint32_t digestLen, 395 const void *signature, 396 uint32_t signatureLen); 397 398 /* Cryptographic Operations API - Key Derivation Functions */ 399 400 void TEE_DeriveKey(TEE_OperationHandle operation, 401 const TEE_Attribute *params, uint32_t paramCount, 402 TEE_ObjectHandle derivedKey); 403 void __GP11_TEE_DeriveKey(TEE_OperationHandle operation, 404 const __GP11_TEE_Attribute *params, 405 uint32_t paramCount, TEE_ObjectHandle derivedKey); 406 407 /* Cryptographic Operations API - Random Number Generation Functions */ 408 409 void TEE_GenerateRandom(void *randomBuffer, uint32_t randomBufferLen); 410 411 /* Date & Time API */ 412 413 void TEE_GetSystemTime(TEE_Time *time); 414 415 TEE_Result TEE_Wait(uint32_t timeout); 416 417 TEE_Result TEE_GetTAPersistentTime(TEE_Time *time); 418 419 TEE_Result TEE_SetTAPersistentTime(const TEE_Time *time); 420 421 void TEE_GetREETime(TEE_Time *time); 422 423 /* TEE Arithmetical API - Memory allocation and size of objects */ 424 425 uint32_t TEE_BigIntFMMSizeInU32(uint32_t modulusSizeInBits); 426 427 uint32_t TEE_BigIntFMMContextSizeInU32(uint32_t modulusSizeInBits); 428 429 /* TEE Arithmetical API - Initialization functions */ 430 431 void TEE_BigIntInit(TEE_BigInt *bigInt, uint32_t len); 432 433 void TEE_BigIntInitFMMContext(TEE_BigIntFMMContext *context, uint32_t len, 434 const TEE_BigInt *modulus); 435 436 void TEE_BigIntInitFMM(TEE_BigIntFMM *bigIntFMM, uint32_t len); 437 438 /* TEE Arithmetical API - Converter functions */ 439 440 TEE_Result TEE_BigIntConvertFromOctetString(TEE_BigInt *dest, 441 const uint8_t *buffer, 442 uint32_t bufferLen, 443 int32_t sign); 444 445 TEE_Result TEE_BigIntConvertToOctetString(uint8_t *buffer, uint32_t *bufferLen, 446 const TEE_BigInt *bigInt); 447 448 void TEE_BigIntConvertFromS32(TEE_BigInt *dest, int32_t shortVal); 449 450 TEE_Result TEE_BigIntConvertToS32(int32_t *dest, const TEE_BigInt *src); 451 452 /* TEE Arithmetical API - Logical operations */ 453 454 int32_t TEE_BigIntCmp(const TEE_BigInt *op1, const TEE_BigInt *op2); 455 456 int32_t TEE_BigIntCmpS32(const TEE_BigInt *op, int32_t shortVal); 457 458 void TEE_BigIntShiftRight(TEE_BigInt *dest, const TEE_BigInt *op, 459 size_t bits); 460 461 bool TEE_BigIntGetBit(const TEE_BigInt *src, uint32_t bitIndex); 462 463 uint32_t TEE_BigIntGetBitCount(const TEE_BigInt *src); 464 465 void TEE_BigIntAdd(TEE_BigInt *dest, const TEE_BigInt *op1, 466 const TEE_BigInt *op2); 467 468 void TEE_BigIntSub(TEE_BigInt *dest, const TEE_BigInt *op1, 469 const TEE_BigInt *op2); 470 471 void TEE_BigIntNeg(TEE_BigInt *dest, const TEE_BigInt *op); 472 473 void TEE_BigIntMul(TEE_BigInt *dest, const TEE_BigInt *op1, 474 const TEE_BigInt *op2); 475 476 void TEE_BigIntSquare(TEE_BigInt *dest, const TEE_BigInt *op); 477 478 void TEE_BigIntDiv(TEE_BigInt *dest_q, TEE_BigInt *dest_r, 479 const TEE_BigInt *op1, const TEE_BigInt *op2); 480 481 /* TEE Arithmetical API - Modular arithmetic operations */ 482 483 void TEE_BigIntMod(TEE_BigInt *dest, const TEE_BigInt *op, 484 const TEE_BigInt *n); 485 486 void TEE_BigIntAddMod(TEE_BigInt *dest, const TEE_BigInt *op1, 487 const TEE_BigInt *op2, const TEE_BigInt *n); 488 489 void TEE_BigIntSubMod(TEE_BigInt *dest, const TEE_BigInt *op1, 490 const TEE_BigInt *op2, const TEE_BigInt *n); 491 492 void TEE_BigIntMulMod(TEE_BigInt *dest, const TEE_BigInt *op1, 493 const TEE_BigInt *op2, const TEE_BigInt *n); 494 495 void TEE_BigIntSquareMod(TEE_BigInt *dest, const TEE_BigInt *op, 496 const TEE_BigInt *n); 497 498 void TEE_BigIntInvMod(TEE_BigInt *dest, const TEE_BigInt *op, 499 const TEE_BigInt *n); 500 501 /* TEE Arithmetical API - Other arithmetic operations */ 502 503 bool TEE_BigIntRelativePrime(const TEE_BigInt *op1, const TEE_BigInt *op2); 504 505 void TEE_BigIntComputeExtendedGcd(TEE_BigInt *gcd, TEE_BigInt *u, 506 TEE_BigInt *v, const TEE_BigInt *op1, 507 const TEE_BigInt *op2); 508 509 int32_t TEE_BigIntIsProbablePrime(const TEE_BigInt *op, 510 uint32_t confidenceLevel); 511 512 /* TEE Arithmetical API - Fast modular multiplication operations */ 513 514 void TEE_BigIntConvertToFMM(TEE_BigIntFMM *dest, const TEE_BigInt *src, 515 const TEE_BigInt *n, 516 const TEE_BigIntFMMContext *context); 517 518 void TEE_BigIntConvertFromFMM(TEE_BigInt *dest, const TEE_BigIntFMM *src, 519 const TEE_BigInt *n, 520 const TEE_BigIntFMMContext *context); 521 522 void TEE_BigIntFMMConvertToBigInt(TEE_BigInt *dest, const TEE_BigIntFMM *src, 523 const TEE_BigInt *n, 524 const TEE_BigIntFMMContext *context); 525 526 void TEE_BigIntComputeFMM(TEE_BigIntFMM *dest, const TEE_BigIntFMM *op1, 527 const TEE_BigIntFMM *op2, const TEE_BigInt *n, 528 const TEE_BigIntFMMContext *context); 529 530 #define TA_EXPORT 531 532 /* 533 * TA Interface 534 * 535 * Each Trusted Application must provide the Implementation with a number 536 * of functions, collectively called the “TA interface”. These functions 537 * are the entry points called by the Trusted Core Framework to create the 538 * instance, notify the instance that a new client is connecting, notify 539 * the instance when the client invokes a command, etc. 540 * 541 * Trusted Application Entry Points: 542 */ 543 544 /* 545 * The function TA_CreateEntryPoint is the Trusted Application's 546 * constructor, which the Framework calls when it creates a new instance of 547 * the Trusted Application. To register instance data, the implementation 548 * of this constructor can use either global variables or the function 549 * TEE_InstanceSetData. 550 * 551 * Return Value: 552 * - TEE_SUCCESS: if the instance is successfully created, the function 553 * must return TEE_SUCCESS. 554 * - Any other value: if any other code is returned the instance is not 555 * created, and no other entry points of this instance will be called. 556 * The Framework MUST reclaim all resources and dereference all objects 557 * related to the creation of the instance. 558 * 559 * If this entry point was called as a result of a client opening a 560 * session, the error code is returned to the client and the session is 561 * not opened. 562 */ 563 TEE_Result TA_EXPORT TA_CreateEntryPoint(void); 564 565 /* 566 * The function TA_DestroyEntryPoint is the Trusted Application‟s 567 * destructor, which the Framework calls when the instance is being 568 * destroyed. 569 * 570 * When the function TA_DestroyEntryPoint is called, the Framework 571 * guarantees that no client session is currently open. Once the call to 572 * TA_DestroyEntryPoint has been completed, no other entry point of this 573 * instance will ever be called. 574 * 575 * Note that when this function is called, all resources opened by the 576 * instance are still available. It is only after the function returns that 577 * the Implementation MUST start automatically reclaiming resources left 578 * opened. 579 * 580 * Return Value: 581 * This function can return no success or error code. After this function 582 * returns the Implementation MUST consider the instance destroyed and 583 * reclaims all resources left open by the instance. 584 */ 585 void TA_EXPORT TA_DestroyEntryPoint(void); 586 587 /* 588 * The Framework calls the function TA_OpenSessionEntryPoint when a client 589 * requests to open a session with the Trusted Application. The open 590 * session request may result in a new Trusted Application instance being 591 * created as defined in section 4.5. 592 * 593 * The client can specify parameters in an open operation which are passed 594 * to the Trusted Application instance in the arguments paramTypes and 595 * params. These arguments can also be used by the Trusted Application 596 * instance to transfer response data back to the client. See section 4.3.6 597 * for a specification of how to handle the operation parameters. 598 * 599 * If this function returns TEE_SUCCESS, the client is connected to a 600 * Trusted Application instance and can invoke Trusted Application 601 * commands. When the client disconnects, the Framework will eventually 602 * call the TA_CloseSessionEntryPoint entry point. 603 * 604 * If the function returns any error, the Framework rejects the connection 605 * and returns the error code and the current content of the parameters the 606 * client. The return origin is then set to TEE_ORIGIN_TRUSTED_APP. 607 * 608 * The Trusted Application instance can register a session data pointer by 609 * setting *psessionContext. The value of this pointer is not interpreted 610 * by the Framework, and is simply passed back to other TA_ functions 611 * within this session. Note that *sessionContext may be set with a pointer 612 * to a memory allocated by the Trusted Application instance or with 613 * anything else, like an integer, a handle etc. The Framework will not 614 * automatically free *sessionContext when the session is closed; the 615 * Trusted Application instance is responsible for freeing memory if 616 * required. 617 * 618 * During the call to TA_OpenSessionEntryPoint the client may request to 619 * cancel the operation. See section 4.10 for more details on 620 * cancellations. If the call to TA_OpenSessionEntryPoint returns 621 * TEE_SUCCESS, the client must consider the session as successfully opened 622 * and explicitly close it if necessary. 623 * 624 * Parameters: 625 * - paramTypes: the types of the four parameters. 626 * - params: a pointer to an array of four parameters. 627 * - sessionContext: A pointer to a variable that can be filled by the 628 * Trusted Application instance with an opaque void* data pointer 629 * 630 * Return Value: 631 * - TEE_SUCCESS if the session is successfully opened. 632 * - Any other value if the session could not be open. 633 * o The error code may be one of the pre-defined codes, or may be a new 634 * error code defined by the Trusted Application implementation itself. 635 */ 636 TEE_Result TA_EXPORT TA_OpenSessionEntryPoint(uint32_t paramTypes, 637 TEE_Param params[TEE_NUM_PARAMS], 638 void **sessionContext); 639 TEE_Result TA_EXPORT 640 __GP11_TA_OpenSessionEntryPoint(uint32_t paramTypes, 641 __GP11_TEE_Param params[TEE_NUM_PARAMS], 642 void **sessionContext); 643 644 /* 645 * The Framework calls this function to close a client session. During the 646 * call to this function the implementation can use any session functions. 647 * 648 * The Trusted Application implementation is responsible for freeing any 649 * resources consumed by the session being closed. Note that the Trusted 650 * Application cannot refuse to close a session, but can hold the closing 651 * until it returns from TA_CloseSessionEntryPoint. This is why this 652 * function cannot return an error code. 653 * 654 * Parameters: 655 * - sessionContext: The value of the void* opaque data pointer set by the 656 * Trusted Application in the function TA_OpenSessionEntryPoint for this 657 * session. 658 */ 659 void TA_EXPORT TA_CloseSessionEntryPoint(void *sessionContext); 660 661 /* 662 * The Framework calls this function when the client invokes a command 663 * within the given session. 664 * 665 * The Trusted Application can access the parameters sent by the client 666 * through the paramTypes and params arguments. It can also use these 667 * arguments to transfer response data back to the client. 668 * 669 * During the call to TA_InvokeCommandEntryPoint the client may request to 670 * cancel the operation. 671 * 672 * A command is always invoked within the context of a client session. 673 * Thus, any session function can be called by the command implementation. 674 * 675 * Parameter: 676 * - sessionContext: The value of the void* opaque data pointer set by the 677 * Trusted Application in the function TA_OpenSessionEntryPoint. 678 * - commandID: A Trusted Application-specific code that identifies the 679 * command to be invoked. 680 * - paramTypes: the types of the four parameters. 681 * - params: a pointer to an array of four parameters. 682 * 683 * Return Value: 684 * - TEE_SUCCESS: if the command is successfully executed, the function 685 * must return this value. 686 * - Any other value: if the invocation of the command fails for any 687 * reason. 688 * o The error code may be one of the pre-defined codes, or may be a new 689 * error code defined by the Trusted Application implementation itself. 690 */ 691 692 TEE_Result TA_EXPORT 693 TA_InvokeCommandEntryPoint(void *sessionContext, uint32_t commandID, 694 uint32_t paramTypes, 695 TEE_Param params[TEE_NUM_PARAMS]); 696 TEE_Result TA_EXPORT 697 __GP11_TA_InvokeCommandEntryPoint(void *sessionContext, uint32_t commandID, 698 uint32_t paramTypes, 699 __GP11_TEE_Param params[TEE_NUM_PARAMS]); 700 701 /* 702 * Matching Client Functions <--> TA Functions 703 * 704 * TEE_OpenSession or TEE_OpenTASession: 705 * If a new Trusted Application instance is needed to handle the session, 706 * TA_CreateEntryPoint is called. 707 * Then, TA_OpenSessionEntryPoint is called. 708 * 709 * TEE_InvokeCommand or TEE_InvokeTACommand: 710 * TA_InvokeCommandEntryPoint is called. 711 * 712 * TEE_CloseSession or TEE_CloseTASession: 713 * TA_CloseSessionEntryPoint is called. 714 * For a multi-instance TA or for a single-instance, non keep-alive TA, if 715 * the session closed was the last session on the instance, then 716 * TA_DestroyEntryPoint is called. Otherwise, the instance is kept until 717 * the TEE shuts down. 718 */ 719 720 #include <tee_api_compat.h> 721 722 #endif /*TEE_INTERNAL_API_H*/ 723