Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/tlcl/tlcl.c

Issue 2822042: Add device open/close. (Closed) Base URL: ssh://git@chromiumos-git/tpm_lite.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/tlcl/tlcl.h ('k') | src/tlcl/version.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 fields are 8 * The general idea is that TPM commands are array of bytes whose fields are
9 * mostly compile-time constant. The goal is to build much of the commands at 9 * mostly compile-time constant. The goal is to build much of the commands at
10 * compile time (or build time) and change some of the fields at run time as 10 * compile time (or build time) and change some of the fields at run time as
(...skipping 21 matching lines...) Expand all
32 #endif /* FIRMWARE */ 32 #endif /* FIRMWARE */
33 33
34 #include "structures.h" 34 #include "structures.h"
35 #include "tlcl_internal.h" 35 #include "tlcl_internal.h"
36 #include "version.h" 36 #include "version.h"
37 37
38 #if USE_TPM_EMULATOR 38 #if USE_TPM_EMULATOR
39 #include "tpmemu.h" 39 #include "tpmemu.h"
40 #endif 40 #endif
41 41
42 #define TPM_DEVICE_PATH "/dev/tpm0"
43
42 /* The file descriptor for the TPM device. 44 /* The file descriptor for the TPM device.
43 */ 45 */
44 int tpm_fd = -1; 46 int tpm_fd = -1;
45 47
46 /* Log level. 0 is quietest. Be verbose by default. 48 /* Log level. 0 is quietest. Be verbose by default.
47 */ 49 */
48 int tlcl_log_level = 1; 50 int tlcl_log_level = 1;
49 51
50 /* Print |n| bytes from array |a|, with newlines. 52 /* Print |n| bytes from array |a|, with newlines.
51 */ 53 */
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 226 }
225 227
226 void TlclSetLogLevel(int level) { 228 void TlclSetLogLevel(int level) {
227 tlcl_log_level = level; 229 tlcl_log_level = level;
228 } 230 }
229 231
230 void TlclLibInit(void) { 232 void TlclLibInit(void) {
231 #if USE_TPM_EMULATOR 233 #if USE_TPM_EMULATOR
232 tpmemu_init(); 234 tpmemu_init();
233 #else 235 #else
234 #if !FIRMWARE 236 TlclOpenDevice();
235 tpm_fd = open("/dev/tpm0", O_RDWR);
236 if (tpm_fd < 0) {
237 error("cannot open TPM device: %s\n", strerror(errno));
238 }
239 #endif /* !FIRMWARE */
240 #endif /* USE_TPM_EMULATOR */ 237 #endif /* USE_TPM_EMULATOR */
241 } 238 }
242 239
240 void TlclCloseDevice(void) {
241 #if !FIRMWARE
242 close(tpm_fd);
243 tpm_fd = -1;
244 #endif /* !FIRMWARE */
245 }
246
247 void TlclOpenDevice(void) {
248 #if !FIRMWARE
249 tpm_fd = open(TPM_DEVICE_PATH, O_RDWR);
250 if (tpm_fd < 0) {
251 error("cannot open TPM device %s: %s\n", TPM_DEVICE_PATH, strerror(errno));
252 }
253 #endif /* !FIRMWARE */
254 }
255
243 uint32_t TlclStartup(void) { 256 uint32_t TlclStartup(void) {
244 return Send(tpm_startup_cmd.buffer); 257 return Send(tpm_startup_cmd.buffer);
245 } 258 }
246 259
247 uint32_t TlclSelftestfull(void) { 260 uint32_t TlclSelftestfull(void) {
248 return Send(tpm_selftestfull_cmd.buffer); 261 return Send(tpm_selftestfull_cmd.buffer);
249 } 262 }
250 263
251 uint32_t TlclContinueSelfTest(void) { 264 uint32_t TlclContinueSelfTest(void) {
252 return Send(tpm_continueselftest_cmd.buffer); 265 return Send(tpm_continueselftest_cmd.buffer);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 ToTpmUint32(tpm_getpermissions_cmd.index, index); 404 ToTpmUint32(tpm_getpermissions_cmd.index, index);
392 SendReceive(tpm_getpermissions_cmd.buffer, response, sizeof(response)); 405 SendReceive(tpm_getpermissions_cmd.buffer, response, sizeof(response));
393 result = TpmReturnCode(response); 406 result = TpmReturnCode(response);
394 if (result != TPM_SUCCESS) { 407 if (result != TPM_SUCCESS) {
395 return result; 408 return result;
396 } 409 }
397 nvdata = response + kTpmResponseHeaderLength + sizeof(size); 410 nvdata = response + kTpmResponseHeaderLength + sizeof(size);
398 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions); 411 FromTpmUint32(nvdata + kNvDataPublicPermissionsOffset, permissions);
399 return result; 412 return result;
400 } 413 }
OLDNEW
« no previous file with comments | « src/tlcl/tlcl.h ('k') | src/tlcl/version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698