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