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