OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /* This program generates partially filled TPM datagrams and other compile-time | 6 /* This program generates partially filled TPM datagrams and other compile-time |
7 * constants (e.g. structure sizes and offsets). Compile this file---and ONLY | 7 * constants (e.g. structure sizes and offsets). Compile this file---and ONLY |
8 * this file---with -fpack-struct. We take advantage of the fact that the | 8 * this file---with -fpack-struct. We take advantage of the fact that the |
9 * (packed) TPM structures layout (mostly) match the TPM request and response | 9 * (packed) TPM structures layout (mostly) match the TPM request and response |
10 * datagram layout. When they don't completely match, some fixing is necessary | 10 * datagram layout. When they don't completely match, some fixing is necessary |
11 * (see PCR_SELECTION_FIX below). | 11 * (see PCR_SELECTION_FIX below). |
12 */ | 12 */ |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 #include <tss/tcs.h> | 17 #include <tss/tcs.h> |
18 | 18 |
| 19 #include "tlcl.h" |
19 #include "tlcl_internal.h" | 20 #include "tlcl_internal.h" |
20 #include "tpmextras.h" | 21 #include "tpmextras.h" |
21 | 22 |
22 /* See struct Command below. This structure represent a field in a TPM | 23 /* See struct Command below. This structure represent a field in a TPM |
23 * command. [name] is the field name. [visible] is true if the field is | 24 * command. [name] is the field name. [visible] is true if the field is |
24 * modified by the run-time. Non-visible fields are initialized at build time | 25 * modified by the run-time. Non-visible fields are initialized at build time |
25 * and remain constant. [size] is the field size in bytes. [value] is the | 26 * and remain constant. [size] is the field size in bytes. [value] is the |
26 * fixed value of non-visible fields. | 27 * fixed value of non-visible fields. |
27 */ | 28 */ |
28 typedef struct Field { | 29 typedef struct Field { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return cmd; | 190 return cmd; |
190 } | 191 } |
191 | 192 |
192 Command* BuildSelftestfullCommand(void) { | 193 Command* BuildSelftestfullCommand(void) { |
193 int size = kTpmRequestHeaderLength + sizeof(TPM_PHYSICAL_PRESENCE); | 194 int size = kTpmRequestHeaderLength + sizeof(TPM_PHYSICAL_PRESENCE); |
194 Command* cmd = newCommand(TPM_ORD_SelfTestFull, size); | 195 Command* cmd = newCommand(TPM_ORD_SelfTestFull, size); |
195 cmd->name = "tpm_selftestfull_cmd"; | 196 cmd->name = "tpm_selftestfull_cmd"; |
196 return cmd; | 197 return cmd; |
197 } | 198 } |
198 | 199 |
| 200 Command* BuildReadPubekCommand(void) { |
| 201 int size = kTpmRequestHeaderLength + sizeof(TPM_NONCE); |
| 202 Command* cmd = newCommand(TPM_ORD_ReadPubek, size); |
| 203 cmd->name = "tpm_readpubek_cmd"; |
| 204 return cmd; |
| 205 } |
| 206 |
199 /* Output the fields of a structure. | 207 /* Output the fields of a structure. |
200 */ | 208 */ |
201 void OutputFields(Field* fld) { | 209 void OutputFields(Field* fld) { |
202 /* | 210 /* |
203 * Field order is reversed. | 211 * Field order is reversed. |
204 */ | 212 */ |
205 if (fld != NULL) { | 213 if (fld != NULL) { |
206 OutputFields(fld->next); | 214 OutputFields(fld->next); |
207 if (fld->visible) { | 215 if (fld->visible) { |
208 printf(" uint8_t* %s;\n", fld->name); | 216 printf(" uint8_t* %s;\n", fld->name); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 OutputCommands(cmd->next); | 299 OutputCommands(cmd->next); |
292 } | 300 } |
293 | 301 |
294 Command* (*builders[])(void) = { | 302 Command* (*builders[])(void) = { |
295 BuildDefineSpaceCommand, | 303 BuildDefineSpaceCommand, |
296 BuildWriteCommand, | 304 BuildWriteCommand, |
297 BuildReadCommand, | 305 BuildReadCommand, |
298 BuildPhysicalPresenceCommand, | 306 BuildPhysicalPresenceCommand, |
299 BuildStartupCommand, | 307 BuildStartupCommand, |
300 BuildSelftestfullCommand, | 308 BuildSelftestfullCommand, |
| 309 BuildReadPubekCommand, |
301 }; | 310 }; |
302 | 311 |
303 static void FreeFields(Field* fld) { | 312 static void FreeFields(Field* fld) { |
304 if (fld != NULL) { | 313 if (fld != NULL) { |
305 Field* next_field = fld->next; | 314 Field* next_field = fld->next; |
306 free(fld); | 315 free(fld); |
307 FreeFields(next_field); | 316 FreeFields(next_field); |
308 } | 317 } |
309 } | 318 } |
310 | 319 |
311 static void FreeCommands(Command* cmd) { | 320 static void FreeCommands(Command* cmd) { |
312 if (cmd != NULL) { | 321 if (cmd != NULL) { |
313 Command* next_command = cmd->next; | 322 Command* next_command = cmd->next; |
314 free(cmd); | 323 free(cmd); |
| 324 FreeFields(cmd->fields); |
315 FreeCommands(next_command); | 325 FreeCommands(next_command); |
316 } | 326 } |
317 } | 327 } |
318 | 328 |
319 int main(void) { | 329 int main(void) { |
320 Command* commands = NULL; | 330 Command* commands = NULL; |
321 int i; | 331 int i; |
322 for (i = 0; i < sizeof(builders) / sizeof(builders[0]); i++) { | 332 for (i = 0; i < sizeof(builders) / sizeof(builders[0]); i++) { |
323 Command* cmd = builders[i](); | 333 Command* cmd = builders[i](); |
324 cmd->next = commands; | 334 cmd->next = commands; |
325 commands = cmd; | 335 commands = cmd; |
326 } | 336 } |
327 | 337 |
328 printf("/* This file is automatically generated */\n\n"); | 338 printf("/* This file is automatically generated */\n\n"); |
329 OutputCommands(commands); | 339 OutputCommands(commands); |
330 printf("const int kWriteInfoLength = %ld;\n", sizeof(TPM_WRITE_INFO)); | 340 printf("const int kWriteInfoLength = %d;\n", (int) sizeof(TPM_WRITE_INFO)); |
331 | 341 |
332 FreeCommands(commands); | 342 FreeCommands(commands); |
333 return 0; | 343 return 0; |
334 } | 344 } |
OLD | NEW |