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