1
2
3
4
5
6
7
8#ifndef _TPM_IOCTL_H_
9#define _TPM_IOCTL_H_
10
11#if defined(__CYGWIN__)
12# define __USE_LINUX_IOCTL_DEFS
13#endif
14
15#ifndef _WIN32
16#include <sys/uio.h>
17#include <sys/ioctl.h>
18#endif
19
20#ifdef HAVE_SYS_IOCCOM_H
21#include <sys/ioccom.h>
22#endif
23
24
25
26
27
28
29
30typedef uint32_t ptm_res;
31
32
33struct ptm_est {
34 union {
35 struct {
36 ptm_res tpm_result;
37 unsigned char bit;
38 } resp;
39 } u;
40};
41
42
43struct ptm_reset_est {
44 union {
45 struct {
46 uint8_t loc;
47 } req;
48 struct {
49 ptm_res tpm_result;
50 } resp;
51 } u;
52};
53
54
55struct ptm_init {
56 union {
57 struct {
58 uint32_t init_flags;
59 } req;
60 struct {
61 ptm_res tpm_result;
62 } resp;
63 } u;
64};
65
66
67#define PTM_INIT_FLAG_DELETE_VOLATILE (1 << 0)
68
69
70
71struct ptm_loc {
72 union {
73 struct {
74 uint8_t loc;
75 } req;
76 struct {
77 ptm_res tpm_result;
78 } resp;
79 } u;
80};
81
82
83struct ptm_hdata {
84 union {
85 struct {
86 uint32_t length;
87 uint8_t data[4096];
88 } req;
89 struct {
90 ptm_res tpm_result;
91 } resp;
92 } u;
93};
94
95
96
97
98
99#define PTM_STATE_BLOB_SIZE (3 * 1024)
100
101
102
103
104
105
106
107
108
109
110
111
112struct ptm_getstate {
113 union {
114 struct {
115 uint32_t state_flags;
116 uint32_t type;
117 uint32_t offset;
118 } req;
119 struct {
120 ptm_res tpm_result;
121 uint32_t state_flags;
122 uint32_t totlength;
123 uint32_t length;
124 uint8_t data[PTM_STATE_BLOB_SIZE];
125 } resp;
126 } u;
127};
128
129
130#define PTM_BLOB_TYPE_PERMANENT 1
131#define PTM_BLOB_TYPE_VOLATILE 2
132#define PTM_BLOB_TYPE_SAVESTATE 3
133
134
135#define PTM_STATE_FLAG_DECRYPTED 1
136#define PTM_STATE_FLAG_ENCRYPTED 2
137
138
139
140
141
142
143
144
145
146
147
148struct ptm_setstate {
149 union {
150 struct {
151 uint32_t state_flags;
152 uint32_t type;
153 uint32_t length;
154
155
156 uint8_t data[PTM_STATE_BLOB_SIZE];
157 } req;
158 struct {
159 ptm_res tpm_result;
160 } resp;
161 } u;
162};
163
164
165
166
167
168struct ptm_getconfig {
169 union {
170 struct {
171 ptm_res tpm_result;
172 uint32_t flags;
173 } resp;
174 } u;
175};
176
177#define PTM_CONFIG_FLAG_FILE_KEY 0x1
178#define PTM_CONFIG_FLAG_MIGRATION_KEY 0x2
179
180
181
182
183
184
185
186
187
188struct ptm_setbuffersize {
189 union {
190 struct {
191 uint32_t buffersize;
192 } req;
193 struct {
194 ptm_res tpm_result;
195 uint32_t buffersize;
196 uint32_t minsize;
197 uint32_t maxsize;
198 } resp;
199 } u;
200};
201
202#define PTM_GETINFO_SIZE (3 * 1024)
203
204
205
206
207
208
209
210
211
212struct ptm_getinfo {
213 union {
214 struct {
215 uint64_t flags;
216 uint32_t offset;
217 uint32_t pad;
218 } req;
219 struct {
220 ptm_res tpm_result;
221 uint32_t totlength;
222 uint32_t length;
223 char buffer[PTM_GETINFO_SIZE];
224 } resp;
225 } u;
226};
227
228#define SWTPM_INFO_TPMSPECIFICATION ((uint64_t)1 << 0)
229#define SWTPM_INFO_TPMATTRIBUTES ((uint64_t)1 << 1)
230
231
232
233
234struct ptm_lockstorage {
235 union {
236 struct {
237 uint32_t retries;
238 } req;
239 struct {
240 ptm_res tpm_result;
241 } resp;
242 } u;
243};
244
245typedef uint64_t ptm_cap;
246typedef struct ptm_est ptm_est;
247typedef struct ptm_reset_est ptm_reset_est;
248typedef struct ptm_loc ptm_loc;
249typedef struct ptm_hdata ptm_hdata;
250typedef struct ptm_init ptm_init;
251typedef struct ptm_getstate ptm_getstate;
252typedef struct ptm_setstate ptm_setstate;
253typedef struct ptm_getconfig ptm_getconfig;
254typedef struct ptm_setbuffersize ptm_setbuffersize;
255typedef struct ptm_getinfo ptm_getinfo;
256typedef struct ptm_lockstorage ptm_lockstorage;
257
258
259#define PTM_CAP_INIT (1)
260#define PTM_CAP_SHUTDOWN (1 << 1)
261#define PTM_CAP_GET_TPMESTABLISHED (1 << 2)
262#define PTM_CAP_SET_LOCALITY (1 << 3)
263#define PTM_CAP_HASHING (1 << 4)
264#define PTM_CAP_CANCEL_TPM_CMD (1 << 5)
265#define PTM_CAP_STORE_VOLATILE (1 << 6)
266#define PTM_CAP_RESET_TPMESTABLISHED (1 << 7)
267#define PTM_CAP_GET_STATEBLOB (1 << 8)
268#define PTM_CAP_SET_STATEBLOB (1 << 9)
269#define PTM_CAP_STOP (1 << 10)
270#define PTM_CAP_GET_CONFIG (1 << 11)
271#define PTM_CAP_SET_DATAFD (1 << 12)
272#define PTM_CAP_SET_BUFFERSIZE (1 << 13)
273#define PTM_CAP_GET_INFO (1 << 14)
274#define PTM_CAP_SEND_COMMAND_HEADER (1 << 15)
275#define PTM_CAP_LOCK_STORAGE (1 << 16)
276
277#ifndef _WIN32
278enum {
279 PTM_GET_CAPABILITY = _IOR('P', 0, ptm_cap),
280 PTM_INIT = _IOWR('P', 1, ptm_init),
281 PTM_SHUTDOWN = _IOR('P', 2, ptm_res),
282 PTM_GET_TPMESTABLISHED = _IOR('P', 3, ptm_est),
283 PTM_SET_LOCALITY = _IOWR('P', 4, ptm_loc),
284 PTM_HASH_START = _IOR('P', 5, ptm_res),
285 PTM_HASH_DATA = _IOWR('P', 6, ptm_hdata),
286 PTM_HASH_END = _IOR('P', 7, ptm_res),
287 PTM_CANCEL_TPM_CMD = _IOR('P', 8, ptm_res),
288 PTM_STORE_VOLATILE = _IOR('P', 9, ptm_res),
289 PTM_RESET_TPMESTABLISHED = _IOWR('P', 10, ptm_reset_est),
290 PTM_GET_STATEBLOB = _IOWR('P', 11, ptm_getstate),
291 PTM_SET_STATEBLOB = _IOWR('P', 12, ptm_setstate),
292 PTM_STOP = _IOR('P', 13, ptm_res),
293 PTM_GET_CONFIG = _IOR('P', 14, ptm_getconfig),
294 PTM_SET_DATAFD = _IOR('P', 15, ptm_res),
295 PTM_SET_BUFFERSIZE = _IOWR('P', 16, ptm_setbuffersize),
296 PTM_GET_INFO = _IOWR('P', 17, ptm_getinfo),
297 PTM_LOCK_STORAGE = _IOWR('P', 18, ptm_lockstorage),
298};
299#endif
300
301
302
303
304
305
306
307
308
309
310
311enum {
312 CMD_GET_CAPABILITY = 1,
313 CMD_INIT,
314 CMD_SHUTDOWN,
315 CMD_GET_TPMESTABLISHED,
316 CMD_SET_LOCALITY,
317 CMD_HASH_START,
318 CMD_HASH_DATA,
319 CMD_HASH_END,
320 CMD_CANCEL_TPM_CMD,
321 CMD_STORE_VOLATILE,
322 CMD_RESET_TPMESTABLISHED,
323 CMD_GET_STATEBLOB,
324 CMD_SET_STATEBLOB,
325 CMD_STOP,
326 CMD_GET_CONFIG,
327 CMD_SET_DATAFD,
328 CMD_SET_BUFFERSIZE,
329 CMD_GET_INFO,
330 CMD_LOCK_STORAGE,
331};
332
333#endif
334