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 /* A lightweight TPM command library. | 6 /* A lightweight TPM command library. |
7 * | 7 * |
8 * The general idea is that TPM commands are array of bytes whose | 8 * The general idea is that TPM commands are array of bytes whose |
9 * fields are mostly compile-time constant. The goal is to build much | 9 * fields are mostly compile-time constant. The goal is to build much |
10 * of the commands at compile time (or build time) and change some of | 10 * of the commands at compile time (or build time) and change some of |
11 * the fields at run time as needed. The code in | 11 * the fields at run time as needed. The code in |
12 * utility/tlcl_generator.c builds structures containing the commands, | 12 * utility/tlcl_generator.c builds structures containing the commands, |
13 * as well as the offsets of the fields that need to be set at run | 13 * as well as the offsets of the fields that need to be set at run |
14 * time. | 14 * time. |
15 */ | 15 */ |
16 | 16 |
17 #include "sysincludes.h" | 17 #include "sysincludes.h" |
18 #include "tlcl.h" | 18 #include "tlcl.h" |
19 #include "tlcl_internal.h" | 19 #include "tlcl_internal.h" |
20 #include "tlcl_structures.h" | 20 #include "tlcl_structures.h" |
21 #include "tss_constants.h" | 21 #include "tss_constants.h" |
22 #include "utility.h" | 22 #include "utility.h" |
23 | 23 |
24 #define EXTRA_LOGGING 0 | |
25 | |
26 #if EXTRA_LOGGING | |
27 #include <stdio.h> | |
28 #endif | |
24 | 29 |
25 /* Sets the size field of a TPM command. */ | 30 /* Sets the size field of a TPM command. */ |
26 static INLINE void SetTpmCommandSize(uint8_t* buffer, uint32_t size) { | 31 static INLINE void SetTpmCommandSize(uint8_t* buffer, uint32_t size) { |
27 ToTpmUint32(buffer + sizeof(uint16_t), size); | 32 ToTpmUint32(buffer + sizeof(uint16_t), size); |
28 } | 33 } |
29 | 34 |
30 /* Gets the size field of a TPM command. */ | 35 /* Gets the size field of a TPM command. */ |
31 POSSIBLY_UNUSED static INLINE int TpmCommandSize(const uint8_t* buffer) { | 36 POSSIBLY_UNUSED static INLINE int TpmCommandSize(const uint8_t* buffer) { |
32 uint32_t size; | 37 uint32_t size; |
33 FromTpmUint32(buffer + sizeof(uint16_t), &size); | 38 FromTpmUint32(buffer + sizeof(uint16_t), &size); |
(...skipping 21 matching lines...) Expand all Loading... | |
55 VBDEBUG(("TPM: command 0x%x failed: 0x%x\n", command, result)); | 60 VBDEBUG(("TPM: command 0x%x failed: 0x%x\n", command, result)); |
56 else | 61 else |
57 error("TPM: command 0x%x failed: 0x%x\n", command, result); | 62 error("TPM: command 0x%x failed: 0x%x\n", command, result); |
58 } | 63 } |
59 } | 64 } |
60 | 65 |
61 /* Sends a TPM command and gets a response. */ | 66 /* Sends a TPM command and gets a response. */ |
62 static void TlclSendReceive(uint8_t* request, uint8_t* response, | 67 static void TlclSendReceive(uint8_t* request, uint8_t* response, |
63 int max_length) { | 68 int max_length) { |
64 | 69 |
70 #if EXTRA_LOGGING | |
71 printf("command: %x%x %x%x%x%x %x%x%x%x\n", | |
Randall Spangler
2010/08/04 16:27:26
Better to use VBDEBUG here, so that we can turn on
| |
72 request[0], request[1], | |
73 request[2], request[3], request[4], request[5], | |
74 request[6], request[7], request[8], request[9]); | |
75 #endif | |
65 TlclStubSendReceive(request, TpmCommandSize(request), | 76 TlclStubSendReceive(request, TpmCommandSize(request), |
66 response, max_length); | 77 response, max_length); |
78 #if EXTRA_LOGGING | |
79 printf("response: %x%x %x%x%x%x %x%x%x%x\n", | |
80 response[0], response[1], | |
81 response[2], response[3], response[4], response[5], | |
82 response[6], response[7], response[8], response[9]); | |
83 #endif | |
67 | 84 |
68 #ifdef VBOOT_DEBUG | 85 #ifdef VBOOT_DEBUG |
69 { | 86 { |
70 int command = TpmCommandCode(request); | 87 int command = TpmCommandCode(request); |
71 int result = TpmReturnCode(response); | 88 int result = TpmReturnCode(response); |
72 VBDEBUG(("TPM: command 0x%x returned 0x%x\n", command, result)); | 89 VBDEBUG(("TPM: command 0x%x returned 0x%x\n", command, result)); |
73 } | 90 } |
74 #endif | 91 #endif |
75 } | 92 } |
76 | 93 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 | 132 |
116 uint32_t TlclWrite(uint32_t index, uint8_t* data, uint32_t length) { | 133 uint32_t TlclWrite(uint32_t index, uint8_t* data, uint32_t length) { |
117 struct s_tpm_nv_write_cmd cmd; | 134 struct s_tpm_nv_write_cmd cmd; |
118 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; | 135 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
119 const int total_length = | 136 const int total_length = |
120 kTpmRequestHeaderLength + kWriteInfoLength + length; | 137 kTpmRequestHeaderLength + kWriteInfoLength + length; |
121 | 138 |
122 VBDEBUG(("TPM: TlclWrite(0x%x, %d)\n", index, length)); | 139 VBDEBUG(("TPM: TlclWrite(0x%x, %d)\n", index, length)); |
123 Memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd)); | 140 Memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd)); |
124 assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); | 141 assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); |
125 SetTpmCommandSize(tpm_nv_write_cmd.buffer, total_length); | 142 SetTpmCommandSize(cmd.buffer, total_length); |
126 | 143 |
127 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.index, index); | 144 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.index, index); |
128 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.length, length); | 145 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.length, length); |
129 Memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length); | 146 Memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length); |
130 | 147 |
131 TlclSendReceive(cmd.buffer, response, sizeof(response)); | 148 TlclSendReceive(cmd.buffer, response, sizeof(response)); |
132 CheckResult(cmd.buffer, response, 1); | 149 CheckResult(cmd.buffer, response, 1); |
133 | 150 |
134 return TpmReturnCode(response); | 151 return TpmReturnCode(response); |
135 } | 152 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 } | 224 } |
208 | 225 |
209 uint32_t TlclClearEnable(void) { | 226 uint32_t TlclClearEnable(void) { |
210 VBDEBUG(("TPM: Disabling TPM\n")); | 227 VBDEBUG(("TPM: Disabling TPM\n")); |
211 return Send(tpm_physicaldisable_cmd.buffer); | 228 return Send(tpm_physicaldisable_cmd.buffer); |
212 } | 229 } |
213 | 230 |
214 uint32_t TlclSetDeactivated(uint8_t flag) { | 231 uint32_t TlclSetDeactivated(uint8_t flag) { |
215 struct s_tpm_physicalsetdeactivated_cmd cmd; | 232 struct s_tpm_physicalsetdeactivated_cmd cmd; |
216 VBDEBUG(("TPM: SetDeactivated(%d)\n", flag)); | 233 VBDEBUG(("TPM: SetDeactivated(%d)\n", flag)); |
217 Memcpy(&cmd, &tpm_physicaldisable_cmd, sizeof(cmd)); | 234 Memcpy(&cmd, &tpm_physicalsetdeactivated_cmd, sizeof(cmd)); |
218 *(cmd.buffer + cmd.deactivated) = flag; | 235 *(cmd.buffer + cmd.deactivated) = flag; |
219 return Send(cmd.buffer); | 236 return Send(cmd.buffer); |
220 } | 237 } |
221 | 238 |
222 uint32_t TlclGetFlags(uint8_t* disable, uint8_t* deactivated, uint8_t *nvlocked) { | 239 uint32_t TlclGetFlags(uint8_t* disable, uint8_t* deactivated, uint8_t *nvlocked) { |
223 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; | 240 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
224 TPM_PERMANENT_FLAGS* pflags; | 241 TPM_PERMANENT_FLAGS* pflags; |
225 uint32_t result; | 242 uint32_t result; |
226 uint32_t size; | 243 uint32_t size; |
227 VBDEBUG(("TPM: Get flags\n")); | 244 VBDEBUG(("TPM: Get flags\n")); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 ToTpmUint32(cmd.buffer + tpm_getpermissions_cmd.index, index); | 292 ToTpmUint32(cmd.buffer + tpm_getpermissions_cmd.index, index); |
276 TlclSendReceive(tpm_getpermissions_cmd.buffer, response, sizeof(response)); | 293 TlclSendReceive(tpm_getpermissions_cmd.buffer, response, sizeof(response)); |
277 result = TpmReturnCode(response); | 294 result = TpmReturnCode(response); |
278 if (result != TPM_SUCCESS) { | 295 if (result != TPM_SUCCESS) { |
279 return result; | 296 return result; |
280 } | 297 } |
281 nvdata = response + kTpmResponseHeaderLength + sizeof(size); | 298 nvdata = response + kTpmResponseHeaderLength + sizeof(size); |
282 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); | 299 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); |
283 return result; | 300 return result; |
284 } | 301 } |
OLD | NEW |