1*b0104773SPascal Brand /* 2*b0104773SPascal Brand * Copyright (c) 2014, STMicroelectronics International N.V. 3*b0104773SPascal Brand * All rights reserved. 4*b0104773SPascal Brand * 5*b0104773SPascal Brand * Redistribution and use in source and binary forms, with or without 6*b0104773SPascal Brand * modification, are permitted provided that the following conditions are met: 7*b0104773SPascal Brand * 8*b0104773SPascal Brand * 1. Redistributions of source code must retain the above copyright notice, 9*b0104773SPascal Brand * this list of conditions and the following disclaimer. 10*b0104773SPascal Brand * 11*b0104773SPascal Brand * 2. Redistributions in binary form must reproduce the above copyright notice, 12*b0104773SPascal Brand * this list of conditions and the following disclaimer in the documentation 13*b0104773SPascal Brand * and/or other materials provided with the distribution. 14*b0104773SPascal Brand * 15*b0104773SPascal Brand * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16*b0104773SPascal Brand * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*b0104773SPascal Brand * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*b0104773SPascal Brand * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19*b0104773SPascal Brand * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*b0104773SPascal Brand * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*b0104773SPascal Brand * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*b0104773SPascal Brand * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*b0104773SPascal Brand * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*b0104773SPascal Brand * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*b0104773SPascal Brand * POSSIBILITY OF SUCH DAMAGE. 26*b0104773SPascal Brand */ 27*b0104773SPascal Brand 28*b0104773SPascal Brand /* Based on GP TEE Internal API Specification Version 0.22 */ 29*b0104773SPascal Brand #ifndef TEE_TA_API_H 30*b0104773SPascal Brand #define TEE_TA_API_H 31*b0104773SPascal Brand 32*b0104773SPascal Brand #include <tee_api_defines.h> 33*b0104773SPascal Brand #include <tee_api_types.h> 34*b0104773SPascal Brand 35*b0104773SPascal Brand /* This is a null define in STE TEE environment */ 36*b0104773SPascal Brand #define TA_EXPORT 37*b0104773SPascal Brand 38*b0104773SPascal Brand /* 39*b0104773SPascal Brand * TA Interface 40*b0104773SPascal Brand * 41*b0104773SPascal Brand * Each Trusted Application must provide the Implementation with a number 42*b0104773SPascal Brand * of functions, collectively called the “TA interface”. These functions 43*b0104773SPascal Brand * are the entry points called by the Trusted Core Framework to create the 44*b0104773SPascal Brand * instance, notify the instance that a new client is connecting, notify 45*b0104773SPascal Brand * the instance when the client invokes a command, etc. 46*b0104773SPascal Brand * 47*b0104773SPascal Brand * Trusted Application Entry Points: 48*b0104773SPascal Brand */ 49*b0104773SPascal Brand 50*b0104773SPascal Brand /* 51*b0104773SPascal Brand * The function TA_CreateEntryPoint is the Trusted Application's 52*b0104773SPascal Brand * constructor, which the Framework calls when it creates a new instance of 53*b0104773SPascal Brand * the Trusted Application. To register instance data, the implementation 54*b0104773SPascal Brand * of this constructor can use either global variables or the function 55*b0104773SPascal Brand * TEE_InstanceSetData. 56*b0104773SPascal Brand * 57*b0104773SPascal Brand * Return Value: 58*b0104773SPascal Brand * - TEE_SUCCESS: if the instance is successfully created, the function 59*b0104773SPascal Brand * must return TEE_SUCCESS. 60*b0104773SPascal Brand * - Any other value: if any other code is returned the instance is not 61*b0104773SPascal Brand * created, and no other entry points of this instance will be called. 62*b0104773SPascal Brand * The Framework MUST reclaim all resources and dereference all objects 63*b0104773SPascal Brand * related to the creation of the instance. 64*b0104773SPascal Brand * 65*b0104773SPascal Brand * If this entry point was called as a result of a client opening a 66*b0104773SPascal Brand * session, the error code is returned to the client and the session is 67*b0104773SPascal Brand * not opened. 68*b0104773SPascal Brand */ 69*b0104773SPascal Brand TEE_Result TA_EXPORT TA_CreateEntryPoint(void); 70*b0104773SPascal Brand 71*b0104773SPascal Brand /* 72*b0104773SPascal Brand * The function TA_DestroyEntryPoint is the Trusted Application‟s 73*b0104773SPascal Brand * destructor, which the Framework calls when the instance is being 74*b0104773SPascal Brand * destroyed. 75*b0104773SPascal Brand * 76*b0104773SPascal Brand * When the function TA_DestroyEntryPoint is called, the Framework 77*b0104773SPascal Brand * guarantees that no client session is currently open. Once the call to 78*b0104773SPascal Brand * TA_DestroyEntryPoint has been completed, no other entry point of this 79*b0104773SPascal Brand * instance will ever be called. 80*b0104773SPascal Brand * 81*b0104773SPascal Brand * Note that when this function is called, all resources opened by the 82*b0104773SPascal Brand * instance are still available. It is only after the function returns that 83*b0104773SPascal Brand * the Implementation MUST start automatically reclaiming resources left 84*b0104773SPascal Brand * opened. 85*b0104773SPascal Brand * 86*b0104773SPascal Brand * Return Value: 87*b0104773SPascal Brand * This function can return no success or error code. After this function 88*b0104773SPascal Brand * returns the Implementation MUST consider the instance destroyed and 89*b0104773SPascal Brand * reclaims all resources left open by the instance. 90*b0104773SPascal Brand */ 91*b0104773SPascal Brand void TA_EXPORT TA_DestroyEntryPoint(void); 92*b0104773SPascal Brand 93*b0104773SPascal Brand /* 94*b0104773SPascal Brand * The Framework calls the function TA_OpenSessionEntryPoint when a client 95*b0104773SPascal Brand * requests to open a session with the Trusted Application. The open 96*b0104773SPascal Brand * session request may result in a new Trusted Application instance being 97*b0104773SPascal Brand * created as defined in section 4.5. 98*b0104773SPascal Brand * 99*b0104773SPascal Brand * The client can specify parameters in an open operation which are passed 100*b0104773SPascal Brand * to the Trusted Application instance in the arguments paramTypes and 101*b0104773SPascal Brand * params. These arguments can also be used by the Trusted Application 102*b0104773SPascal Brand * instance to transfer response data back to the client. See section 4.3.6 103*b0104773SPascal Brand * for a specification of how to handle the operation parameters. 104*b0104773SPascal Brand * 105*b0104773SPascal Brand * If this function returns TEE_SUCCESS, the client is connected to a 106*b0104773SPascal Brand * Trusted Application instance and can invoke Trusted Application 107*b0104773SPascal Brand * commands. When the client disconnects, the Framework will eventually 108*b0104773SPascal Brand * call the TA_CloseSessionEntryPoint entry point. 109*b0104773SPascal Brand * 110*b0104773SPascal Brand * If the function returns any error, the Framework rejects the connection 111*b0104773SPascal Brand * and returns the error code and the current content of the parameters the 112*b0104773SPascal Brand * client. The return origin is then set to TEE_ORIGIN_TRUSTED_APP. 113*b0104773SPascal Brand * 114*b0104773SPascal Brand * The Trusted Application instance can register a session data pointer by 115*b0104773SPascal Brand * setting *psessionContext. The value of this pointer is not interpreted 116*b0104773SPascal Brand * by the Framework, and is simply passed back to other TA_ functions 117*b0104773SPascal Brand * within this session. Note that *sessionContext may be set with a pointer 118*b0104773SPascal Brand * to a memory allocated by the Trusted Application instance or with 119*b0104773SPascal Brand * anything else, like an integer, a handle etc. The Framework will not 120*b0104773SPascal Brand * automatically free *sessionContext when the session is closed; the 121*b0104773SPascal Brand * Trusted Application instance is responsible for freeing memory if 122*b0104773SPascal Brand * required. 123*b0104773SPascal Brand * 124*b0104773SPascal Brand * During the call to TA_OpenSessionEntryPoint the client may request to 125*b0104773SPascal Brand * cancel the operation. See section 4.10 for more details on 126*b0104773SPascal Brand * cancellations. If the call to TA_OpenSessionEntryPoint returns 127*b0104773SPascal Brand * TEE_SUCCESS, the client must consider the session as successfully opened 128*b0104773SPascal Brand * and explicitly close it if necessary. 129*b0104773SPascal Brand * 130*b0104773SPascal Brand * Parameters: 131*b0104773SPascal Brand * - paramTypes: the types of the four parameters. 132*b0104773SPascal Brand * - params: a pointer to an array of four parameters. 133*b0104773SPascal Brand * - sessionContext: A pointer to a variable that can be filled by the 134*b0104773SPascal Brand * Trusted Application instance with an opaque void* data pointer 135*b0104773SPascal Brand * 136*b0104773SPascal Brand * Return Value: 137*b0104773SPascal Brand * - TEE_SUCCESS if the session is successfully opened. 138*b0104773SPascal Brand * - Any other value if the session could not be open. 139*b0104773SPascal Brand * o The error code may be one of the pre-defined codes, or may be a new 140*b0104773SPascal Brand * error code defined by the Trusted Application implementation itself. 141*b0104773SPascal Brand */ 142*b0104773SPascal Brand TEE_Result TA_EXPORT TA_OpenSessionEntryPoint(uint32_t paramTypes, 143*b0104773SPascal Brand TEE_Param params[4], 144*b0104773SPascal Brand void **sessionContext); 145*b0104773SPascal Brand 146*b0104773SPascal Brand /* 147*b0104773SPascal Brand * The Framework calls this function to close a client session. During the 148*b0104773SPascal Brand * call to this function the implementation can use any session functions. 149*b0104773SPascal Brand * 150*b0104773SPascal Brand * The Trusted Application implementation is responsible for freeing any 151*b0104773SPascal Brand * resources consumed by the session being closed. Note that the Trusted 152*b0104773SPascal Brand * Application cannot refuse to close a session, but can hold the closing 153*b0104773SPascal Brand * until it returns from TA_CloseSessionEntryPoint. This is why this 154*b0104773SPascal Brand * function cannot return an error code. 155*b0104773SPascal Brand * 156*b0104773SPascal Brand * Parameters: 157*b0104773SPascal Brand * - sessionContext: The value of the void* opaque data pointer set by the 158*b0104773SPascal Brand * Trusted Application in the function TA_OpenSessionEntryPoint for this 159*b0104773SPascal Brand * session. 160*b0104773SPascal Brand */ 161*b0104773SPascal Brand void TA_EXPORT TA_CloseSessionEntryPoint(void *sessionContext); 162*b0104773SPascal Brand 163*b0104773SPascal Brand /* 164*b0104773SPascal Brand * The Framework calls this function when the client invokes a command 165*b0104773SPascal Brand * within the given session. 166*b0104773SPascal Brand * 167*b0104773SPascal Brand * The Trusted Application can access the parameters sent by the client 168*b0104773SPascal Brand * through the paramTypes and params arguments. It can also use these 169*b0104773SPascal Brand * arguments to transfer response data back to the client. 170*b0104773SPascal Brand * 171*b0104773SPascal Brand * During the call to TA_InvokeCommandEntryPoint the client may request to 172*b0104773SPascal Brand * cancel the operation. 173*b0104773SPascal Brand * 174*b0104773SPascal Brand * A command is always invoked within the context of a client session. 175*b0104773SPascal Brand * Thus, any session function can be called by the command implementation. 176*b0104773SPascal Brand * 177*b0104773SPascal Brand * Parameter: 178*b0104773SPascal Brand * - sessionContext: The value of the void* opaque data pointer set by the 179*b0104773SPascal Brand * Trusted Application in the function TA_OpenSessionEntryPoint. 180*b0104773SPascal Brand * - commandID: A Trusted Application-specific code that identifies the 181*b0104773SPascal Brand * command to be invoked. 182*b0104773SPascal Brand * - paramTypes: the types of the four parameters. 183*b0104773SPascal Brand * - params: a pointer to an array of four parameters. 184*b0104773SPascal Brand * 185*b0104773SPascal Brand * Return Value: 186*b0104773SPascal Brand * - TEE_SUCCESS: if the command is successfully executed, the function 187*b0104773SPascal Brand * must return this value. 188*b0104773SPascal Brand * - Any other value: if the invocation of the command fails for any 189*b0104773SPascal Brand * reason. 190*b0104773SPascal Brand * o The error code may be one of the pre-defined codes, or may be a new 191*b0104773SPascal Brand * error code defined by the Trusted Application implementation itself. 192*b0104773SPascal Brand */ 193*b0104773SPascal Brand 194*b0104773SPascal Brand TEE_Result TA_EXPORT TA_InvokeCommandEntryPoint(void *sessionContext, 195*b0104773SPascal Brand uint32_t commandID, 196*b0104773SPascal Brand uint32_t paramTypes, 197*b0104773SPascal Brand TEE_Param params[4]); 198*b0104773SPascal Brand 199*b0104773SPascal Brand /* 200*b0104773SPascal Brand * Correspondance Client Functions <--> TA Functions 201*b0104773SPascal Brand * 202*b0104773SPascal Brand * TEE_OpenSession or TEE_OpenTASession: 203*b0104773SPascal Brand * If a new Trusted Application instance is needed to handle the session, 204*b0104773SPascal Brand * TA_CreateEntryPoint is called. 205*b0104773SPascal Brand * Then, TA_OpenSessionEntryPoint is called. 206*b0104773SPascal Brand * 207*b0104773SPascal Brand * 208*b0104773SPascal Brand * TEE_InvokeCommand or TEE_InvokeTACommand: 209*b0104773SPascal Brand * TA_InvokeCommandEntryPoint is called. 210*b0104773SPascal Brand * 211*b0104773SPascal Brand * 212*b0104773SPascal Brand * TEE_CloseSession or TEE_CloseTASession: 213*b0104773SPascal Brand * TA_CloseSessionEntryPoint is called. 214*b0104773SPascal Brand * For a multi-instance TA or for a single-instance, non keep-alive TA, if 215*b0104773SPascal Brand * the session closed was the last session on the instance, then 216*b0104773SPascal Brand * TA_DestroyEntryPoint is called. Otherwise, the instance is kept until 217*b0104773SPascal Brand * the TEE shuts down. 218*b0104773SPascal Brand * 219*b0104773SPascal Brand */ 220*b0104773SPascal Brand 221*b0104773SPascal Brand #endif 222