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-2023 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 #include <linux/uuid.h>
37
38 #ifndef METEE_DLL
39 #define METEE_DLL_API
40 #else
41 #ifdef METEE_DLL_EXPORT
42 #define METEE_DLL_API __attribute__((__visibility__("default")))
43 #else
44 #define METEE_DLL_API
45 #endif /* METEE_DLL_EXPORT */
46 #endif /* METEE_DLL */
47 #define TEEAPI METEE_DLL_API
48 #define GUID uuid_le
49 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
50 const uuid_le name = UUID_LE(l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
51 #define TEE_DEVICE_HANDLE int
52 #define TEE_INVALID_DEVICE_HANDLE (-1)
53 #ifndef IN
54 #define IN
55 #endif
56 #ifndef OUT
57 #define OUT
58 #endif
59 #ifndef OPTIONAL
60 #define OPTIONAL
61 #endif
62#endif /* _WIN32 */
64
67 enum tee_log_level {
68 TEE_LOG_LEVEL_QUIET = 0,
69 TEE_LOG_LEVEL_ERROR = 1,
70 TEE_LOG_LEVEL_VERBOSE = 2,
71 TEE_LOG_LEVEL_MAX = 3,
72};
73
76 typedef void(*TeeLogCallback)(bool is_error, const char* fmt, ...);
77
81 typedef struct _TEEHANDLE {
82
83 void *handle;
84 size_t maxMsgLen;
85 uint8_t protcolVer;
86 enum tee_log_level log_level;
87 TeeLogCallback log_callback;
88} TEEHANDLE;
89
94 typedef TEEHANDLE *PTEEHANDLE;
95
98 struct tee_device_address {
101 enum {
102 TEE_DEVICE_TYPE_NONE = 0,
103 TEE_DEVICE_TYPE_PATH = 1,
104 TEE_DEVICE_TYPE_HANDLE = 2,
105 TEE_DEVICE_TYPE_GUID = 3,
106 TEE_DEVICE_TYPE_MAX = 4,
107 } type;
109 union {
110 const char* path;
111 const GUID* guid;
112 TEE_DEVICE_HANDLE handle;
113 } data;
114};
115
117#define TEEHANDLE_ZERO {0}
118
119 typedef uint16_t TEESTATUS;
121#define TEE_ERROR_BASE 0x0000U
123#define TEE_SUCCESS (TEE_ERROR_BASE + 0)
125#define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1)
127#define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2)
129#define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3)
131#define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4)
133#define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5)
135#define TEE_TIMEOUT (TEE_ERROR_BASE + 6)
137#define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7)
139#define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8)
141#define TEE_BUSY (TEE_ERROR_BASE + 9)
143#define TEE_DISCONNECTED (TEE_ERROR_BASE + 10)
145#define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11)
147#define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12)
148
151#define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS)
152
162 TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid,
163 IN const struct tee_device_address device,
164 IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback);
165
173 TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid,
174 IN OPTIONAL const char *device);
175
176#ifdef _WIN32
185 TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid,
186 IN OPTIONAL const GUID *device);
187#endif /* _WIN32 */
188
196 TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid,
197 IN const TEE_DEVICE_HANDLE device_handle);
198
203 TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle);
204
214 TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize,
215 OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout);
216
226 TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize,
227 OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout);
228
235 TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle,
236 IN uint32_t fwStatusNum, OUT uint32_t *fwStatus);
237
243 TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val);
244
250 void TEEAPI TeeDisconnect(IN PTEEHANDLE handle);
251
257TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle);
258
261 typedef struct {
262 uint16_t major;
263 uint16_t minor;
264 uint16_t hotfix;
265 uint16_t build;
266} teeDriverVersion_t;
267
274 TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion);
275
282uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level);
283
289uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle);
290
297 TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback);
298
299#ifdef __cplusplus
300}
301#endif
302
303#endif /* __METEE_H */
TEESTATUS
uint16_t TEESTATUS
Definition metee.h:119
TeeLogCallback
void(* TeeLogCallback)(bool is_error, const char *fmt,...)
Definition metee.h:76
TeeSetLogCallback
TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback)
tee_log_level
tee_log_level
Definition metee.h:67
TEE_LOG_LEVEL_ERROR
@ TEE_LOG_LEVEL_ERROR
Definition metee.h:69
TEE_LOG_LEVEL_MAX
@ TEE_LOG_LEVEL_MAX
Definition metee.h:71
TEE_LOG_LEVEL_VERBOSE
@ TEE_LOG_LEVEL_VERBOSE
Definition metee.h:70
TEE_LOG_LEVEL_QUIET
@ TEE_LOG_LEVEL_QUIET
Definition metee.h:68
PTEEHANDLE
TEEHANDLE * PTEEHANDLE
A type definition for pointer to TEEHANDLE.
Definition metee.h:94
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)
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:81
_TEEHANDLE::protcolVer
uint8_t protcolVer
Definition metee.h:85
_TEEHANDLE::log_callback
TeeLogCallback log_callback
Definition metee.h:87
_TEEHANDLE::log_level
enum tee_log_level log_level
Definition metee.h:86
_TEEHANDLE::maxMsgLen
size_t maxMsgLen
Definition metee.h:84
_TEEHANDLE::handle
void * handle
Definition metee.h:83
teeDriverVersion_t
Definition metee.h:261
teeDriverVersion_t::major
uint16_t major
Definition metee.h:262
teeDriverVersion_t::build
uint16_t build
Definition metee.h:265
teeDriverVersion_t::minor
uint16_t minor
Definition metee.h:263
teeDriverVersion_t::hotfix
uint16_t hotfix
Definition metee.h:264
tee_device_address
Definition metee.h:98
tee_device_address::data
union tee_device_address::@1 data
tee_device_address::handle
TEE_DEVICE_HANDLE handle
Definition metee.h:112
tee_device_address::TEE_DEVICE_TYPE_NONE
@ TEE_DEVICE_TYPE_NONE
Definition metee.h:102
tee_device_address::TEE_DEVICE_TYPE_GUID
@ TEE_DEVICE_TYPE_GUID
Definition metee.h:105
tee_device_address::TEE_DEVICE_TYPE_HANDLE
@ TEE_DEVICE_TYPE_HANDLE
Definition metee.h:104
tee_device_address::TEE_DEVICE_TYPE_PATH
@ TEE_DEVICE_TYPE_PATH
Definition metee.h:103
tee_device_address::TEE_DEVICE_TYPE_MAX
@ TEE_DEVICE_TYPE_MAX
Definition metee.h:106
tee_device_address::type
enum tee_device_address::@0 type
tee_device_address::guid
const GUID * guid
Definition metee.h:111