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