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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return cmd; | 197 return cmd; |
198 } | 198 } |
199 | 199 |
200 Command* BuildReadPubekCommand(void) { | 200 Command* BuildReadPubekCommand(void) { |
201 int size = kTpmRequestHeaderLength + sizeof(TPM_NONCE); | 201 int size = kTpmRequestHeaderLength + sizeof(TPM_NONCE); |
202 Command* cmd = newCommand(TPM_ORD_ReadPubek, size); | 202 Command* cmd = newCommand(TPM_ORD_ReadPubek, size); |
203 cmd->name = "tpm_readpubek_cmd"; | 203 cmd->name = "tpm_readpubek_cmd"; |
204 return cmd; | 204 return cmd; |
205 } | 205 } |
206 | 206 |
| 207 Command* BuildForceClearCommand(void) { |
| 208 int size = kTpmRequestHeaderLength; |
| 209 Command* cmd = newCommand(TPM_ORD_ForceClear, size); |
| 210 cmd->name = "tpm_forceclear_cmd"; |
| 211 return cmd; |
| 212 } |
| 213 |
| 214 Command* BuildPhysicalEnableCommand(void) { |
| 215 int size = kTpmRequestHeaderLength; |
| 216 Command* cmd = newCommand(TPM_ORD_PhysicalEnable, size); |
| 217 cmd->name = "tpm_physicalenable_cmd"; |
| 218 return cmd; |
| 219 } |
| 220 |
| 221 Command* BuildPhysicalSetDeactivatedCommand(void) { |
| 222 int size = kTpmRequestHeaderLength + sizeof(uint8_t); |
| 223 Command* cmd = newCommand(TPM_ORD_PhysicalSetDeactivated, size); |
| 224 cmd->name = "tpm_physicalsetdeactivated_cmd"; |
| 225 AddVisibleField(cmd, "deactivated", kTpmRequestHeaderLength); |
| 226 return cmd; |
| 227 } |
| 228 |
| 229 Command* BuildGetCapabilityCommand(void) { |
| 230 int size = (kTpmRequestHeaderLength + |
| 231 sizeof(TPM_CAPABILITY_AREA) + /* capArea */ |
| 232 sizeof(uint32_t) + /* subCapSize */ |
| 233 sizeof(uint32_t)); /* subCap */ |
| 234 |
| 235 Command* cmd = newCommand(TPM_ORD_GetCapability, size); |
| 236 cmd->name = "tpm_getcapability_cmd"; |
| 237 AddInitializedField(cmd, kTpmRequestHeaderLength, |
| 238 sizeof(TPM_CAPABILITY_AREA), TPM_CAP_FLAG); |
| 239 AddInitializedField(cmd, kTpmRequestHeaderLength + |
| 240 sizeof(TPM_CAPABILITY_AREA), |
| 241 sizeof(uint32_t), sizeof(uint32_t)); |
| 242 AddInitializedField(cmd, kTpmRequestHeaderLength + |
| 243 sizeof(TPM_CAPABILITY_AREA) + sizeof(uint32_t), |
| 244 sizeof(uint32_t), TPM_CAP_FLAG_PERMANENT); |
| 245 return cmd; |
| 246 } |
| 247 |
207 /* Output the fields of a structure. | 248 /* Output the fields of a structure. |
208 */ | 249 */ |
209 void OutputFields(Field* fld) { | 250 void OutputFields(Field* fld) { |
210 /* | 251 /* |
211 * Field order is reversed. | 252 * Field order is reversed. |
212 */ | 253 */ |
213 if (fld != NULL) { | 254 if (fld != NULL) { |
214 OutputFields(fld->next); | 255 OutputFields(fld->next); |
215 if (fld->visible) { | 256 if (fld->visible) { |
216 printf(" uint8_t* %s;\n", fld->name); | 257 printf(" uint8_t* %s;\n", fld->name); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 341 } |
301 | 342 |
302 Command* (*builders[])(void) = { | 343 Command* (*builders[])(void) = { |
303 BuildDefineSpaceCommand, | 344 BuildDefineSpaceCommand, |
304 BuildWriteCommand, | 345 BuildWriteCommand, |
305 BuildReadCommand, | 346 BuildReadCommand, |
306 BuildPhysicalPresenceCommand, | 347 BuildPhysicalPresenceCommand, |
307 BuildStartupCommand, | 348 BuildStartupCommand, |
308 BuildSelftestfullCommand, | 349 BuildSelftestfullCommand, |
309 BuildReadPubekCommand, | 350 BuildReadPubekCommand, |
| 351 BuildForceClearCommand, |
| 352 BuildPhysicalEnableCommand, |
| 353 BuildPhysicalSetDeactivatedCommand, |
| 354 BuildGetCapabilityCommand, |
310 }; | 355 }; |
311 | 356 |
312 static void FreeFields(Field* fld) { | 357 static void FreeFields(Field* fld) { |
313 if (fld != NULL) { | 358 if (fld != NULL) { |
314 Field* next_field = fld->next; | 359 Field* next_field = fld->next; |
315 free(fld); | 360 free(fld); |
316 FreeFields(next_field); | 361 FreeFields(next_field); |
317 } | 362 } |
318 } | 363 } |
319 | 364 |
(...skipping 15 matching lines...) Expand all Loading... |
335 commands = cmd; | 380 commands = cmd; |
336 } | 381 } |
337 | 382 |
338 printf("/* This file is automatically generated */\n\n"); | 383 printf("/* This file is automatically generated */\n\n"); |
339 OutputCommands(commands); | 384 OutputCommands(commands); |
340 printf("const int kWriteInfoLength = %d;\n", (int) sizeof(TPM_WRITE_INFO)); | 385 printf("const int kWriteInfoLength = %d;\n", (int) sizeof(TPM_WRITE_INFO)); |
341 | 386 |
342 FreeCommands(commands); | 387 FreeCommands(commands); |
343 return 0; | 388 return 0; |
344 } | 389 } |
OLD | NEW |