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