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 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size) { | 114 uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size) { |
115 struct s_tpm_nv_definespace_cmd cmd; | 115 struct s_tpm_nv_definespace_cmd cmd; |
116 VBDEBUG(("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size)); | 116 VBDEBUG(("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size)); |
117 Memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd)); | 117 Memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd)); |
118 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.index, index); | 118 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.index, index); |
119 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm); | 119 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm); |
120 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.size, size); | 120 ToTpmUint32(cmd.buffer + tpm_nv_definespace_cmd.size, size); |
121 return Send(cmd.buffer); | 121 return Send(cmd.buffer); |
122 } | 122 } |
123 | 123 |
124 uint32_t TlclWrite(uint32_t index, uint8_t* data, uint32_t length) { | 124 uint32_t TlclWrite(uint32_t index, const void* data, uint32_t length) { |
125 struct s_tpm_nv_write_cmd cmd; | 125 struct s_tpm_nv_write_cmd cmd; |
126 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; | 126 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
127 const int total_length = | 127 const int total_length = |
128 kTpmRequestHeaderLength + kWriteInfoLength + length; | 128 kTpmRequestHeaderLength + kWriteInfoLength + length; |
129 | 129 |
130 VBDEBUG(("TPM: TlclWrite(0x%x, %d)\n", index, length)); | 130 VBDEBUG(("TPM: TlclWrite(0x%x, %d)\n", index, length)); |
131 Memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd)); | 131 Memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd)); |
132 assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); | 132 assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE); |
133 SetTpmCommandSize(cmd.buffer, total_length); | 133 SetTpmCommandSize(cmd.buffer, total_length); |
134 | 134 |
135 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.index, index); | 135 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.index, index); |
136 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.length, length); | 136 ToTpmUint32(cmd.buffer + tpm_nv_write_cmd.length, length); |
137 Memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length); | 137 Memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length); |
138 | 138 |
139 return TlclSendReceive(cmd.buffer, response, sizeof(response)); | 139 return TlclSendReceive(cmd.buffer, response, sizeof(response)); |
140 } | 140 } |
141 | 141 |
142 uint32_t TlclRead(uint32_t index, uint8_t* data, uint32_t length) { | 142 uint32_t TlclRead(uint32_t index, void* data, uint32_t length) { |
143 struct s_tpm_nv_read_cmd cmd; | 143 struct s_tpm_nv_read_cmd cmd; |
144 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; | 144 uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE]; |
145 uint32_t result_length; | 145 uint32_t result_length; |
146 uint32_t result; | 146 uint32_t result; |
147 | 147 |
148 VBDEBUG(("TPM: TlclRead(0x%x, %d)\n", index, length)); | 148 VBDEBUG(("TPM: TlclRead(0x%x, %d)\n", index, length)); |
149 Memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd)); | 149 Memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd)); |
150 ToTpmUint32(cmd.buffer + tpm_nv_read_cmd.index, index); | 150 ToTpmUint32(cmd.buffer + tpm_nv_read_cmd.index, index); |
151 ToTpmUint32(cmd.buffer + tpm_nv_read_cmd.length, length); | 151 ToTpmUint32(cmd.buffer + tpm_nv_read_cmd.length, length); |
152 | 152 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 Memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd)); | 280 Memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd)); |
281 ToTpmUint32(cmd.buffer + tpm_getpermissions_cmd.index, index); | 281 ToTpmUint32(cmd.buffer + tpm_getpermissions_cmd.index, index); |
282 result = TlclSendReceive(cmd.buffer, response, sizeof(response)); | 282 result = TlclSendReceive(cmd.buffer, response, sizeof(response)); |
283 if (result != TPM_SUCCESS) | 283 if (result != TPM_SUCCESS) |
284 return result; | 284 return result; |
285 | 285 |
286 nvdata = response + kTpmResponseHeaderLength + sizeof(size); | 286 nvdata = response + kTpmResponseHeaderLength + sizeof(size); |
287 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); | 287 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); |
288 return result; | 288 return result; |
289 } | 289 } |
OLD | NEW |