1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*
* Copyright (c) 2013 The Chromium OS Authors.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef __TPM_H
#define __TPM_H
#include <tis.h>
/*
* Here is a partial implementation of TPM commands. Please consult TCG Main
* Specification for definitions of TPM commands.
*/
enum tpm_startup_type {
TPM_ST_CLEAR = 0x0001,
TPM_ST_STATE = 0x0002,
TPM_ST_DEACTIVATED = 0x0003,
};
enum tpm_physical_presence {
TPM_PHYSICAL_PRESENCE_HW_DISABLE = 0x0200,
TPM_PHYSICAL_PRESENCE_CMD_DISABLE = 0x0100,
TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK = 0x0080,
TPM_PHYSICAL_PRESENCE_HW_ENABLE = 0x0040,
TPM_PHYSICAL_PRESENCE_CMD_ENABLE = 0x0020,
TPM_PHYSICAL_PRESENCE_NOTPRESENT = 0x0010,
TPM_PHYSICAL_PRESENCE_PRESENT = 0x0008,
TPM_PHYSICAL_PRESENCE_LOCK = 0x0004,
};
enum tpm_nv_index {
TPM_NV_INDEX_LOCK = 0xffffffff,
TPM_NV_INDEX_0 = 0x00000000,
TPM_NV_INDEX_DIR = 0x10000001,
};
/**
* Initialize TPM device. It must be called before any TPM commands.
*
* @return 0 on success, non-0 on error.
*/
uint32_t tpm_init(void);
/**
* Issue a TPM_Startup command.
*
* @param mode TPM startup mode
* @return return code of the operation
*/
uint32_t tpm_startup(enum tpm_startup_type mode);
/**
* Issue a TPM_SelfTestFull command.
*
* @return return code of the operation
*/
uint32_t tpm_self_test_full(void);
/**
* Issue a TPM_ContinueSelfTest command.
*
* @return return code of the operation
*/
uint32_t tpm_continue_self_test(void);
/**
* Issue a TPM_NV_DefineSpace command. The implementation is limited
* to specify TPM_NV_ATTRIBUTES and size of the area. The area index
* could be one of the special value listed in enum tpm_nv_index.
*
* @param index index of the area
* @param perm TPM_NV_ATTRIBUTES of the area
* @param size size of the area
* @return return code of the operation
*/
uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size);
/**
* Issue a TPM_NV_ReadValue command. This implementation is limited
* to read the area from offset 0. The area index could be one of
* the special value listed in enum tpm_nv_index.
*
* @param index index of the area
* @param data output buffer of the area contents
* @param count size of output buffer
* @return return code of the operation
*/
uint32_t tpm_nv_read_value(uint32_t index, void *data, uint32_t count);
/**
* Issue a TPM_NV_WriteValue command. This implementation is limited
* to write the area from offset 0. The area index could be one of
* the special value listed in enum tpm_nv_index.
*
* @param index index of the area
* @param data input buffer to be wrote to the area
* @param length length of data bytes of input buffer
* @return return code of the operation
*/
uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length);
/**
* Issue a TPM_Extend command.
*
* @param index index of the PCR
* @param in_digest 160-bit value representing the event to be
* recorded
* @param out_digest 160-bit PCR value after execution of the
* command
* @return return code of the operation
*/
uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest);
/**
* Issue a TPM_PCRRead command.
*
* @param index index of the PCR
* @param data output buffer for contents of the named PCR
* @param count size of output buffer
* @return return code of the operation
*/
uint32_t tpm_pcr_read(uint32_t index, void *data, size_t count);
/**
* Issue a TSC_PhysicalPresence command. TPM physical presence flag
* is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
*
* @param presence TPM physical presence flag
* @return return code of the operation
*/
uint32_t tpm_tsc_physical_presence(uint16_t presence);
/**
* Issue a TPM_ReadPubek command.
*
* @param data output buffer for the public endorsement key
* @param count size of ouput buffer
* @return return code of the operation
*/
uint32_t tpm_read_pubek(void *data, size_t count);
/**
* Issue a TPM_ForceClear command.
*
* @return return code of the operation
*/
uint32_t tpm_force_clear(void);
/**
* Issue a TPM_PhysicalEnable command.
*
* @return return code of the operation
*/
uint32_t tpm_physical_enable(void);
/**
* Issue a TPM_PhysicalDisable command.
*
* @return return code of the operation
*/
uint32_t tpm_physical_disable(void);
/**
* Issue a TPM_PhysicalSetDeactivated command.
*
* @param state boolean state of the deactivated flag
* @return return code of the operation
*/
uint32_t tpm_physical_set_deactivated(uint8_t state);
/**
* Issue a TPM_GetCapability command. This implementation is limited
* to query sub_cap index that is 4-byte wide.
*
* @param cap_area partition of capabilities
* @param sub_cap further definition of capability, which is
* limited to be 4-byte wide
* @param cap output buffer for capability information
* @param count size of ouput buffer
* @return return code of the operation
*/
uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
void *cap, size_t count);
#endif /* __TPM_H */
|