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 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 Command* BuildExtendCommand(void) { | 246 Command* BuildExtendCommand(void) { |
247 int size = kTpmRequestHeaderLength + sizeof(uint32_t) + kPcrDigestLength; | 247 int size = kTpmRequestHeaderLength + sizeof(uint32_t) + kPcrDigestLength; |
248 Command* cmd = newCommand(TPM_ORD_Extend, size); | 248 Command* cmd = newCommand(TPM_ORD_Extend, size); |
249 cmd->name = "tpm_extend_cmd"; | 249 cmd->name = "tpm_extend_cmd"; |
250 AddVisibleField(cmd, "pcrNum", kTpmRequestHeaderLength); | 250 AddVisibleField(cmd, "pcrNum", kTpmRequestHeaderLength); |
251 AddVisibleField(cmd, "inDigest", kTpmRequestHeaderLength + sizeof(uint32_t)); | 251 AddVisibleField(cmd, "inDigest", kTpmRequestHeaderLength + sizeof(uint32_t)); |
252 return cmd; | 252 return cmd; |
253 } | 253 } |
254 | 254 |
255 Command* BuildGetCapabilityCommand(void) { | 255 Command* BuildGetFlagsCommand(void) { |
256 int size = (kTpmRequestHeaderLength + | 256 int size = (kTpmRequestHeaderLength + |
257 sizeof(TPM_CAPABILITY_AREA) + /* capArea */ | 257 sizeof(TPM_CAPABILITY_AREA) + /* capArea */ |
258 sizeof(uint32_t) + /* subCapSize */ | 258 sizeof(uint32_t) + /* subCapSize */ |
259 sizeof(uint32_t)); /* subCap */ | 259 sizeof(uint32_t)); /* subCap */ |
260 | 260 |
261 Command* cmd = newCommand(TPM_ORD_GetCapability, size); | 261 Command* cmd = newCommand(TPM_ORD_GetCapability, size); |
262 cmd->name = "tpm_getcapability_cmd"; | 262 cmd->name = "tpm_getflags_cmd"; |
263 AddInitializedField(cmd, kTpmRequestHeaderLength, | 263 AddInitializedField(cmd, kTpmRequestHeaderLength, |
264 sizeof(TPM_CAPABILITY_AREA), TPM_CAP_FLAG); | 264 sizeof(TPM_CAPABILITY_AREA), TPM_CAP_FLAG); |
265 AddInitializedField(cmd, kTpmRequestHeaderLength + | 265 AddInitializedField(cmd, kTpmRequestHeaderLength + |
266 sizeof(TPM_CAPABILITY_AREA), | 266 sizeof(TPM_CAPABILITY_AREA), |
267 sizeof(uint32_t), sizeof(uint32_t)); | 267 sizeof(uint32_t), sizeof(uint32_t)); |
268 AddInitializedField(cmd, kTpmRequestHeaderLength + | 268 AddInitializedField(cmd, kTpmRequestHeaderLength + |
269 sizeof(TPM_CAPABILITY_AREA) + sizeof(uint32_t), | 269 sizeof(TPM_CAPABILITY_AREA) + sizeof(uint32_t), |
270 sizeof(uint32_t), TPM_CAP_FLAG_PERMANENT); | 270 sizeof(uint32_t), TPM_CAP_FLAG_PERMANENT); |
271 return cmd; | 271 return cmd; |
272 } | 272 } |
273 | 273 |
| 274 Command* BuildGetPermissionsCommand(void) { |
| 275 int size = (kTpmRequestHeaderLength + |
| 276 sizeof(TPM_CAPABILITY_AREA) + /* capArea */ |
| 277 sizeof(uint32_t) + /* subCapSize */ |
| 278 sizeof(uint32_t)); /* subCap */ |
| 279 |
| 280 Command* cmd = newCommand(TPM_ORD_GetCapability, size); |
| 281 cmd->name = "tpm_getpermissions_cmd"; |
| 282 AddInitializedField(cmd, kTpmRequestHeaderLength, |
| 283 sizeof(TPM_CAPABILITY_AREA), TPM_CAP_NV_INDEX); |
| 284 AddInitializedField(cmd, kTpmRequestHeaderLength + |
| 285 sizeof(TPM_CAPABILITY_AREA), |
| 286 sizeof(uint32_t), sizeof(uint32_t)); |
| 287 AddVisibleField(cmd, "index", kTpmRequestHeaderLength + |
| 288 sizeof(TPM_CAPABILITY_AREA) + sizeof(uint32_t)); |
| 289 return cmd; |
| 290 } |
| 291 |
274 /* Output the fields of a structure. | 292 /* Output the fields of a structure. |
275 */ | 293 */ |
276 void OutputFields(Field* fld) { | 294 void OutputFields(Field* fld) { |
277 /* | 295 /* |
278 * Field order is reversed. | 296 * Field order is reversed. |
279 */ | 297 */ |
280 if (fld != NULL) { | 298 if (fld != NULL) { |
281 OutputFields(fld->next); | 299 OutputFields(fld->next); |
282 if (fld->visible) { | 300 if (fld->visible) { |
283 printf(" uint8_t* %s;\n", fld->name); | 301 printf(" uint8_t* %s;\n", fld->name); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 BuildReadCommand, | 390 BuildReadCommand, |
373 BuildPPAssertCommand, | 391 BuildPPAssertCommand, |
374 BuildPPLockCommand, | 392 BuildPPLockCommand, |
375 BuildStartupCommand, | 393 BuildStartupCommand, |
376 BuildSelftestfullCommand, | 394 BuildSelftestfullCommand, |
377 BuildContinueSelfTestCommand, | 395 BuildContinueSelfTestCommand, |
378 BuildReadPubekCommand, | 396 BuildReadPubekCommand, |
379 BuildForceClearCommand, | 397 BuildForceClearCommand, |
380 BuildPhysicalEnableCommand, | 398 BuildPhysicalEnableCommand, |
381 BuildPhysicalSetDeactivatedCommand, | 399 BuildPhysicalSetDeactivatedCommand, |
382 BuildGetCapabilityCommand, | 400 BuildGetFlagsCommand, |
| 401 BuildGetPermissionsCommand, |
383 BuildExtendCommand, | 402 BuildExtendCommand, |
384 }; | 403 }; |
385 | 404 |
386 static void FreeFields(Field* fld) { | 405 static void FreeFields(Field* fld) { |
387 if (fld != NULL) { | 406 if (fld != NULL) { |
388 Field* next_field = fld->next; | 407 Field* next_field = fld->next; |
389 free(fld); | 408 free(fld); |
390 FreeFields(next_field); | 409 FreeFields(next_field); |
391 } | 410 } |
392 } | 411 } |
(...skipping 12 matching lines...) Expand all Loading... |
405 int i; | 424 int i; |
406 for (i = 0; i < sizeof(builders) / sizeof(builders[0]); i++) { | 425 for (i = 0; i < sizeof(builders) / sizeof(builders[0]); i++) { |
407 Command* cmd = builders[i](); | 426 Command* cmd = builders[i](); |
408 cmd->next = commands; | 427 cmd->next = commands; |
409 commands = cmd; | 428 commands = cmd; |
410 } | 429 } |
411 | 430 |
412 printf("/* This file is automatically generated */\n\n"); | 431 printf("/* This file is automatically generated */\n\n"); |
413 OutputCommands(commands); | 432 OutputCommands(commands); |
414 printf("const int kWriteInfoLength = %d;\n", (int) sizeof(TPM_WRITE_INFO)); | 433 printf("const int kWriteInfoLength = %d;\n", (int) sizeof(TPM_WRITE_INFO)); |
| 434 printf("const int kNvDataPublicPermissionsOffset = %d;\n", |
| 435 (int) (offsetof(TPM_NV_DATA_PUBLIC, permission) + |
| 436 2 * PCR_SELECTION_FIX + |
| 437 offsetof(TPM_NV_ATTRIBUTES, attributes))); |
415 | 438 |
416 FreeCommands(commands); | 439 FreeCommands(commands); |
417 return 0; | 440 return 0; |
418 } | 441 } |
OLD | NEW |