| 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 * Stub implementations of utility functions which call their linux-specific | 5 * Stub implementations of utility functions which call their linux-specific |
| 6 * equivalents. | 6 * equivalents. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #define _STUB_IMPLEMENTATION_ | 9 #define _STUB_IMPLEMENTATION_ |
| 10 #include "tlcl.h" | 10 #include "tlcl.h" |
| 11 #include "tlcl_internal.h" | 11 #include "tlcl_internal.h" |
| 12 #include "utility.h" | 12 #include "utility.h" |
| 13 | 13 |
| 14 #include <errno.h> | 14 #include <errno.h> |
| 15 #include <fcntl.h> | 15 #include <fcntl.h> |
| 16 #include <stdarg.h> | 16 #include <stdarg.h> |
| 17 #include <stdio.h> | 17 #include <stdio.h> |
| 18 #include <stdlib.h> |
| 18 #include <string.h> | 19 #include <string.h> |
| 19 #include <sys/time.h> | 20 #include <sys/time.h> |
| 20 #include <sys/types.h> | 21 #include <sys/types.h> |
| 21 #include <sys/stat.h> | 22 #include <sys/stat.h> |
| 22 #include <unistd.h> | 23 #include <unistd.h> |
| 23 #include <tss/tcs.h> | 24 #include <tss/tcs.h> |
| 24 #include "tpmextras.h" | 25 #include "tpmextras.h" |
| 25 #define TPM_DEVICE_PATH "/dev/tpm0" | 26 #define TPM_DEVICE_PATH "/dev/tpm0" |
| 26 | 27 |
| 27 /* TODO: these functions should pass errors back rather than returning void */ | 28 /* TODO: these functions should pass errors back rather than returning void */ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 105 } |
| 105 | 106 |
| 106 | 107 |
| 107 void TlclCloseDevice(void) { | 108 void TlclCloseDevice(void) { |
| 108 close(tpm_fd); | 109 close(tpm_fd); |
| 109 tpm_fd = -1; | 110 tpm_fd = -1; |
| 110 } | 111 } |
| 111 | 112 |
| 112 | 113 |
| 113 void TlclOpenDevice(void) { | 114 void TlclOpenDevice(void) { |
| 115 char* device_path; |
| 116 |
| 114 if (tpm_fd >= 0) | 117 if (tpm_fd >= 0) |
| 115 return; /* Already open */ | 118 return; /* Already open */ |
| 116 | 119 |
| 117 tpm_fd = open(TPM_DEVICE_PATH, O_RDWR); | 120 device_path = getenv("TPM_DEVICE_PATH"); |
| 121 if (device_path == NULL) { |
| 122 device_path = TPM_DEVICE_PATH; |
| 123 } |
| 124 |
| 125 tpm_fd = open(device_path, O_RDWR); |
| 118 if (tpm_fd < 0) { | 126 if (tpm_fd < 0) { |
| 119 error("cannot open TPM device %s: %s\n", TPM_DEVICE_PATH, strerror(errno)); | 127 error("cannot open TPM device %s: %s\n", device_path, strerror(errno)); |
| 120 } | 128 } |
| 121 } | 129 } |
| 122 | 130 |
| 123 | 131 |
| 124 void TlclStubSendReceive(uint8_t* request, int request_length, | 132 void TlclStubSendReceive(uint8_t* request, int request_length, |
| 125 uint8_t* response, int max_length) { | 133 uint8_t* response, int max_length) { |
| 126 /* | 134 /* |
| 127 * In a real firmware implementation, this function should contain | 135 * In a real firmware implementation, this function should contain |
| 128 * the equivalent API call for the firmware TPM driver which takes a | 136 * the equivalent API call for the firmware TPM driver which takes a |
| 129 * raw sequence of bytes as input command and a pointer to the | 137 * raw sequence of bytes as input command and a pointer to the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 response_tag = TpmTag(response); | 177 response_tag = TpmTag(response); |
| 170 assert( | 178 assert( |
| 171 (tag == TPM_TAG_RQU_COMMAND && | 179 (tag == TPM_TAG_RQU_COMMAND && |
| 172 response_tag == TPM_TAG_RSP_COMMAND) || | 180 response_tag == TPM_TAG_RSP_COMMAND) || |
| 173 (tag == TPM_TAG_RQU_AUTH1_COMMAND && | 181 (tag == TPM_TAG_RQU_AUTH1_COMMAND && |
| 174 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || | 182 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || |
| 175 (tag == TPM_TAG_RQU_AUTH2_COMMAND && | 183 (tag == TPM_TAG_RQU_AUTH2_COMMAND && |
| 176 response_tag == TPM_TAG_RSP_AUTH2_COMMAND)); | 184 response_tag == TPM_TAG_RSP_AUTH2_COMMAND)); |
| 177 assert(response_length == TpmResponseSize(response)); | 185 assert(response_length == TpmResponseSize(response)); |
| 178 } | 186 } |
| OLD | NEW |