metee

metee.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /*
3 * Copyright (C) 2014-2020 Intel Corporation
4 */
8 #ifndef __METEE_H
9 #define __METEE_H
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 #include <stddef.h>
16 #include <stdint.h>
18 #ifdef _WIN32
19 #include <Windows.h>
20 #include <initguid.h>
21
22 #ifndef METEE_DLL
23 #define METEE_DLL_API
24 #else /* METEE_DLL */
25 #ifdef METEE_DLL_EXPORT
26 #define METEE_DLL_API __declspec(dllexport)
27 #else
28 #define METEE_DLL_API __declspec(dllimport)
29 #endif /* METEE_DLL_EXPORT */
30 #endif /* METEE_DLL */
31 #define TEEAPI METEE_DLL_API __stdcall
32 #define TEE_DEVICE_HANDLE HANDLE
33 #define TEE_INVALID_DEVICE_HANDLE ((void*)0)
34 #else /* _WIN32 */
35 #include <linux/uuid.h>
36
37 #ifndef METEE_DLL
38 #define METEE_DLL_API
39 #else
40 #ifdef METEE_DLL_EXPORT
41 #define METEE_DLL_API __attribute__((__visibility__("default")))
42 #else
43 #define METEE_DLL_API
44 #endif /* METEE_DLL_EXPORT */
45 #endif /* METEE_DLL */
46 #define TEEAPI METEE_DLL_API
47 #define GUID uuid_le
48 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
49 const uuid_le name = UUID_LE(l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
50 #define TEE_DEVICE_HANDLE int
51 #define TEE_INVALID_DEVICE_HANDLE (-1)
52 #ifndef IN
53 #define IN
54 #endif
55 #ifndef OUT
56 #define OUT
57 #endif
58 #ifndef OPTIONAL
59 #define OPTIONAL
60 #endif
61 #endif /* _WIN32 */
63
67 typedef struct _TEEHANDLE {
68
69 void *handle;
70 size_t maxMsgLen;
71 uint8_t protcolVer;
72 } TEEHANDLE;
73
78 typedef TEEHANDLE *PTEEHANDLE;
79
80
81
83 #define TEEHANDLE_ZERO {0}
84
85 typedef uint16_t TEESTATUS;
87 #define TEE_ERROR_BASE 0x0000U
89 #define TEE_SUCCESS (TEE_ERROR_BASE + 0)
91 #define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1)
93 #define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2)
95 #define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3)
97 #define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4)
99 #define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5)
101 #define TEE_TIMEOUT (TEE_ERROR_BASE + 6)
103 #define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7)
105 #define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8)
107 #define TEE_BUSY (TEE_ERROR_BASE + 9)
109 #define TEE_DISCONNECTED (TEE_ERROR_BASE + 10)
111 #define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11)
113 #define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12)
114
117 #define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS)
118
126 TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid,
127 IN OPTIONAL const char *device);
128
129 #ifdef _WIN32
138 TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid,
139 IN OPTIONAL const GUID *device);
140 #endif /* _WIN32 */
141
149 TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid,
150 IN const TEE_DEVICE_HANDLE device_handle);
151
156 TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle);
157
167 TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize,
168 OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout);
169
179 TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize,
180 OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout);
181
188 TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle,
189 IN uint32_t fwStatusNum, OUT uint32_t *fwStatus);
190
196 void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);
197
202 TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle);
203
206 typedef struct {
207 uint16_t major;
208 uint16_t minor;
209 uint16_t hotfix;
210 uint16_t build;
211 } teeDriverVersion_t;
212
218 TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion);
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif /* __METEE_H */
TEESTATUS
uint16_t TEESTATUS
Definition: metee.h:85
PTEEHANDLE
TEEHANDLE * PTEEHANDLE
A type definition for pointer to TEEHANDLE.
Definition: metee.h:78
GetDriverVersion
TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion)
TeeRead
TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout)
TeeGetDeviceHandle
TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle)
TeeFWStatus
TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle, IN uint32_t fwStatusNum, OUT uint32_t *fwStatus)
TeeInitHandle
TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const TEE_DEVICE_HANDLE device_handle)
TeeInit
TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN OPTIONAL const char *device)
TeeDisconnect
void TEEAPI TeeDisconnect(IN PTEEHANDLE handle)
TeeConnect
TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle)
TeeWrite
TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout)
TEEHANDLE
struct _TEEHANDLE TEEHANDLE
_TEEHANDLE
Definition: metee.h:67
_TEEHANDLE::protcolVer
uint8_t protcolVer
Definition: metee.h:71
_TEEHANDLE::maxMsgLen
size_t maxMsgLen
Definition: metee.h:70
_TEEHANDLE::handle
void * handle
Definition: metee.h:69
teeDriverVersion_t
Definition: metee.h:206
teeDriverVersion_t::major
uint16_t major
Definition: metee.h:207
teeDriverVersion_t::build
uint16_t build
Definition: metee.h:210
teeDriverVersion_t::minor
uint16_t minor
Definition: metee.h:208
teeDriverVersion_t::hotfix
uint16_t hotfix
Definition: metee.h:209