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