metee

Loading...
Searching...
No Matches
metee.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: Apache-2.0 */
2/*
3 * Copyright (C) 2014-2024 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>
17#include <stdbool.h>
19#ifdef _WIN32
20 #include <Windows.h>
21 #include <initguid.h>
22
23 #ifndef METEE_DLL
24 #define METEE_DLL_API
25 #else /* METEE_DLL */
26 #ifdef METEE_DLL_EXPORT
27 #define METEE_DLL_API __declspec(dllexport)
28 #else
29 #define METEE_DLL_API __declspec(dllimport)
30 #endif /* METEE_DLL_EXPORT */
31 #endif /* METEE_DLL */
32 #define TEEAPI METEE_DLL_API __stdcall
33 #define TEE_DEVICE_HANDLE HANDLE
34 #define TEE_INVALID_DEVICE_HANDLE ((void*)0)
35#else /* _WIN32 */
36 #ifndef METEE_DLL
37 #define METEE_DLL_API
38 #else
39 #ifdef METEE_DLL_EXPORT
40 #define METEE_DLL_API __attribute__((__visibility__("default")))
41 #else
42 #define METEE_DLL_API
43 #endif /* METEE_DLL_EXPORT */
44 #endif /* METEE_DLL */
45 #define TEEAPI METEE_DLL_API
46
47 #ifndef GUID_DEFINED
48 #define GUID_DEFINED 1
49 typedef struct _GUID {
50 uint32_t l;
51 uint16_t w1;
52 uint16_t w2;
53 uint8_t b[8];
54 } GUID;
55 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
56 const GUID name \
57 = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
58 #endif /* GUID_DEFINED */
59
60 #define TEE_DEVICE_HANDLE int
61 #define TEE_INVALID_DEVICE_HANDLE (-1)
62 #ifndef IN
63 #define IN
64 #endif
65 #ifndef OUT
66 #define OUT
67 #endif
68 #ifndef OPTIONAL
69 #define OPTIONAL
70 #endif
71#endif /* _WIN32 */
73
76 enum tee_log_level {
77 TEE_LOG_LEVEL_QUIET = 0,
78 TEE_LOG_LEVEL_ERROR = 1,
79 TEE_LOG_LEVEL_VERBOSE = 2,
80 TEE_LOG_LEVEL_MAX = 3,
81};
82
85 typedef void(*TeeLogCallback)(bool is_error, const char* fmt, ...);
86
90 typedef struct _TEEHANDLE {
91
92 void *handle;
93 size_t maxMsgLen;
94 uint8_t protcolVer;
95 enum tee_log_level log_level;
96 TeeLogCallback log_callback;
97} TEEHANDLE;
98
103 typedef TEEHANDLE *PTEEHANDLE;
104
107 struct tee_device_address {
110 enum {
111 TEE_DEVICE_TYPE_NONE = 0,
112 TEE_DEVICE_TYPE_PATH = 1,
113 TEE_DEVICE_TYPE_HANDLE = 2,
114 TEE_DEVICE_TYPE_GUID = 3,
115 TEE_DEVICE_TYPE_MAX = 4,
116 } type;
118 union {
119 const char* path;
120 const GUID* guid;
121 TEE_DEVICE_HANDLE handle;
122 } data;
123};
124
126#define TEEHANDLE_ZERO {0}
127
128 typedef uint16_t TEESTATUS;
130#define TEE_ERROR_BASE 0x0000U
132#define TEE_SUCCESS (TEE_ERROR_BASE + 0)
134#define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1)
136#define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2)
138#define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3)
140#define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4)
142#define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5)
144#define TEE_TIMEOUT (TEE_ERROR_BASE + 6)
146#define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7)
148#define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8)
150#define TEE_BUSY (TEE_ERROR_BASE + 9)
152#define TEE_DISCONNECTED (TEE_ERROR_BASE + 10)
154#define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11)
156#define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12)
157
160#define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS)
161
171 TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid,
172 IN const struct tee_device_address device,
173 IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback);
174
182 TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid,
183 IN OPTIONAL const char *device);
184
185#ifdef _WIN32
194 TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid,
195 IN OPTIONAL const GUID *device);
196#endif /* _WIN32 */
197
205 TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid,
206 IN const TEE_DEVICE_HANDLE device_handle);
207
212 TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle);
213
223 TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize,
224 OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout);
225
235 TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize,
236 OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout);
237
244 TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle,
245 IN uint32_t fwStatusNum, OUT uint32_t *fwStatus);
246
252 TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val);
253
259 void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);
260
266TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle);
267
270 typedef struct {
271 uint16_t major;
272 uint16_t minor;
273 uint16_t hotfix;
274 uint16_t build;
275} teeDriverVersion_t;
276
283 TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion);
284
291uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level);
292
298uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle);
299
306 TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback);
307
308#ifdef __cplusplus
309}
310#endif
311
312#endif /* __METEE_H */
TEESTATUS
uint16_t TEESTATUS
Definition metee.h:128
TeeLogCallback
void(* TeeLogCallback)(bool is_error, const char *fmt,...)
Definition metee.h:85
TeeSetLogCallback
TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback)
tee_log_level
tee_log_level
Definition metee.h:76
TEE_LOG_LEVEL_ERROR
@ TEE_LOG_LEVEL_ERROR
Definition metee.h:78
TEE_LOG_LEVEL_MAX
@ TEE_LOG_LEVEL_MAX
Definition metee.h:80
TEE_LOG_LEVEL_VERBOSE
@ TEE_LOG_LEVEL_VERBOSE
Definition metee.h:79
TEE_LOG_LEVEL_QUIET
@ TEE_LOG_LEVEL_QUIET
Definition metee.h:77
GetDriverVersion
TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion)
PTEEHANDLE
TEEHANDLE * PTEEHANDLE
A type definition for pointer to TEEHANDLE.
Definition metee.h:103
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)
TeeGetLogLevel
uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle)
TeeGetTRC
TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t *trc_val)
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)
TeeInitFull
TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback)
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
TeeSetLogLevel
uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level)
_TEEHANDLE
Definition metee.h:90
_TEEHANDLE::protcolVer
uint8_t protcolVer
Definition metee.h:94
_TEEHANDLE::log_callback
TeeLogCallback log_callback
Definition metee.h:96
_TEEHANDLE::log_level
enum tee_log_level log_level
Definition metee.h:95
_TEEHANDLE::maxMsgLen
size_t maxMsgLen
Definition metee.h:93
_TEEHANDLE::handle
void * handle
Definition metee.h:92
teeDriverVersion_t
Definition metee.h:270
teeDriverVersion_t::major
uint16_t major
Definition metee.h:271
teeDriverVersion_t::build
uint16_t build
Definition metee.h:274
teeDriverVersion_t::minor
uint16_t minor
Definition metee.h:272
teeDriverVersion_t::hotfix
uint16_t hotfix
Definition metee.h:273
tee_device_address
Definition metee.h:107
tee_device_address::data
union tee_device_address::@1 data
tee_device_address::handle
TEE_DEVICE_HANDLE handle
Definition metee.h:121
tee_device_address::TEE_DEVICE_TYPE_NONE
@ TEE_DEVICE_TYPE_NONE
Definition metee.h:111
tee_device_address::TEE_DEVICE_TYPE_GUID
@ TEE_DEVICE_TYPE_GUID
Definition metee.h:114
tee_device_address::TEE_DEVICE_TYPE_HANDLE
@ TEE_DEVICE_TYPE_HANDLE
Definition metee.h:113
tee_device_address::TEE_DEVICE_TYPE_PATH
@ TEE_DEVICE_TYPE_PATH
Definition metee.h:112
tee_device_address::TEE_DEVICE_TYPE_MAX
@ TEE_DEVICE_TYPE_MAX
Definition metee.h:115
tee_device_address::type
enum tee_device_address::@0 type
tee_device_address::guid
const GUID * guid
Definition metee.h:120