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