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