Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Security.TEEC / Interop / Interop.Libteec.cs
1 /*
2  *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 //using Interop.Liibteec.Types;
20
21 internal static partial class Interop
22 {
23     internal static partial class Libteec
24     {
25         /// <summary>
26         /// This function initializes a new TEE Context, forming a connection between this Client Application and the
27         /// TEE identified by the string identifier name.
28         /// The Client Application MAY pass name with a value of NULL, which means that the Implementation MUST
29         /// select a default TEE to connect to. The supported name strings, the mapping of these names to a specific
30         /// TEE, and the nature of the default TEE are implementation-defined.
31         /// </summary>
32         //TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
33         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_InitializeContext", CallingConvention = CallingConvention.Cdecl)]
34         static public extern int InitializeContext(string name, ref TEEC_Context context);
35
36         /// <summary>
37         /// This function destroys an initialized TEE Context, closing the connection between the Client Application
38         /// and the TEE. The Client Application MUST only call this function when all Sessions inside this TEE
39         /// Context have been closed and all Shared Memory blocks have been released.
40         /// The implementation of this function MUST NOT be able to fail; after this function returns the Client
41         /// Application must be able to consider that the Context has been closed.
42         /// The function implementation MUST do nothing if the value of the context pointer is NULL.
43         /// </summary>
44         //void TEEC_FinalizeContext(TEEC_Context *context);
45         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_FinalizeContext", CallingConvention = CallingConvention.Cdecl)]
46         static public extern void FinalizeContext(ref TEEC_Context context);
47
48         /// <summary>
49         /// This function registers a block of existing Client Application memory as a block of Shared Memory within
50         /// the scope of the specified TEE Context, in accordance with the parameters which have been set by the
51         /// Client Application inside the sharedMem structure.
52         /// The input context MUST point to an initialized TEE Context.
53         /// The input sharedMem MUST point to the Shared Memory structure defining the memory region to register
54         /// </summary>
55         //EEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem);
56         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_RegisterSharedMemory", CallingConvention = CallingConvention.Cdecl)]
57         static public extern int RegisterSharedMemory(ref TEEC_Context context, ref TEEC_SharedMemory sharedMem);
58
59         /// <summary>
60         /// This function allocates a new block of memory as a block of Shared Memory within the scope of the
61         /// specified TEE Context, in accordance with the parameters which have been set by the Client Application
62         /// inside the sharedMem structure.
63         /// The input context MUST point to an initialized TEE Context.
64         /// The input sharedMem MUST point to the Shared Memory structure defining the region to allocate.
65         /// </summary>
66         //TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem);
67         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_AllocateSharedMemory", CallingConvention = CallingConvention.Cdecl)]
68         static public extern int AllocateSharedMemory(ref TEEC_Context context, ref TEEC_SharedMemory sharedMem);
69
70         /// <summary>
71         /// This function deregisters or deallocates a previously initialized block of Shared Memory.
72         /// For a memory buffer allocated using AllocateSharedMemory the Implementation MUST free the
73         /// underlying memory and the Client Application MUST NOT access this region after this function has been
74         /// called. In this case the Implementation MUST set the buffer and size fields of the sharedMem
75         /// structure to NULL and 0 respectively before returning.
76         /// For memory registered using RegisterSharedMemory the implementation MUST deregister the
77         /// underlying memory from the TEE, but the memory region will stay available to the Client Application for
78         /// other purposes as the memory is owned by it.
79         /// The implementation MUST do nothing if the value of the sharedMem parameter is NULL.
80         /// </summary>
81         //void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMem);
82         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_ReleaseSharedMemory", CallingConvention = CallingConvention.Cdecl)]
83         static public extern void ReleaseSharedMemory(ref TEEC_SharedMemory sharedMem);
84
85         /// <summary>
86         /// This function opens a new Session between the Client Application and the specified Trusted Application.
87         /// The Implementation MUST assume that all fields of this session structure are in an undefined state.
88         /// When this function returns TEEC_SUCCESS the Implementation MUST have populated this structure with
89         /// any information necessary for subsequent operations within the Session.
90         /// The target Trusted Application is identified by a UUID passed in the parameter destination.
91         /// </summary>
92         //TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session, const TEEC_UUID *destination, uint connectionMethod, const void *connectionData, TEEC_Operation *operation, uint *returnOrigin);
93         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_OpenSession", CallingConvention = CallingConvention.Cdecl)]
94         static public extern int OpenSession(ref TEEC_Context context, ref TEEC_Session session, TEEC_UUID destination, uint connectionMethod, byte[] connectionData, ref TEEC_Operation operation, out uint returnOrigin);
95
96         /// <summary>
97         /// This function closes a Session which has been opened with a Trusted Application.
98         /// All Commands within the Session MUST have completed before this function can be called.
99         /// The Implementation MUST do nothing if the input session parameter is NULL.
100         /// The implementation of this function MUST NOT be able to fail; after this function returns the Client
101         /// Application must be able to consider that the Session has been closed.
102         /// </summary>
103         //void TEEC_CloseSession(TEEC_Session *session);
104         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_CloseSession", CallingConvention = CallingConvention.Cdecl)]
105         static public extern void CloseSession(ref TEEC_Session session);
106
107         /// <summary>
108         /// This function invokes a Command within the specified Session.
109         /// The parameter session MUST point to a valid open Session.
110         /// The parameter commandID is an identifier that is used to indicate which of the exposed Trusted
111         /// Application functions should be invoked. The supported command identifier values are defined by the
112         /// Trusted Application‟s protocol.
113         /// </summary>
114         //TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint commandID, TEEC_Operation *operation, uint *returnOrigin);
115         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_InvokeCommand", CallingConvention = CallingConvention.Cdecl)]
116         static public extern int InvokeCommand(ref TEEC_Session session, uint commandID, ref TEEC_Operation operation, out uint returnOrigin);
117
118         /// <summary>
119         /// This function requests the cancellation of a pending open Session operation or a Command invocation
120         /// operation. As this is a synchronous API, this function must be called from a thread other than the one
121         /// executing the OpenSession or InvokeCommand function.
122         /// This function just sends a cancellation signal to the TEE and returns immediately; the operation is not
123         /// guaranteed to have been cancelled when this function returns. In addition, the cancellation request is just
124         /// a hint; the TEE or the Trusted Application MAY ignore the cancellation request.
125         /// </summary>
126         //void TEEC_RequestCancellation(TEEC_Operation *operation);
127         [DllImport(Libraries.Libteec, EntryPoint = "TEEC_RequestCancellation", CallingConvention = CallingConvention.Cdecl)]
128         static public extern void RequestCancellation(ref TEEC_Operation operation);
129     }
130 }