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