| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 /* Gets the size field of a TPM command. | 93 /* Gets the size field of a TPM command. |
| 94 */ | 94 */ |
| 95 POSSIBLY_UNUSED static INLINE int TpmResponseSize(const uint8_t* buffer) { | 95 POSSIBLY_UNUSED static INLINE int TpmResponseSize(const uint8_t* buffer) { |
| 96 uint32_t size; | 96 uint32_t size; |
| 97 FromTpmUint32(buffer + sizeof(uint16_t), &size); | 97 FromTpmUint32(buffer + sizeof(uint16_t), &size); |
| 98 return (int) size; | 98 return (int) size; |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 void TlclStubInit(void) { | 102 uint32_t TlclStubInit(void) { |
| 103 TlclOpenDevice(); | 103 return TlclOpenDevice(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 void TlclCloseDevice(void) { | 107 uint32_t TlclCloseDevice(void) { |
| 108 close(tpm_fd); | 108 if (tpm_fd != -1) { |
| 109 tpm_fd = -1; | 109 close(tpm_fd); |
| 110 tpm_fd = -1; |
| 111 } |
| 112 return 0; |
| 110 } | 113 } |
| 111 | 114 |
| 112 | 115 |
| 113 void TlclOpenDevice(void) { | 116 uint32_t TlclOpenDevice(void) { |
| 114 char* device_path; | 117 char* device_path; |
| 115 | 118 |
| 116 if (tpm_fd >= 0) | 119 if (tpm_fd >= 0) |
| 117 return; /* Already open */ | 120 return 0; /* Already open */ |
| 118 | 121 |
| 119 device_path = getenv("TPM_DEVICE_PATH"); | 122 device_path = getenv("TPM_DEVICE_PATH"); |
| 120 if (device_path == NULL) { | 123 if (device_path == NULL) { |
| 121 device_path = TPM_DEVICE_PATH; | 124 device_path = TPM_DEVICE_PATH; |
| 122 } | 125 } |
| 123 | 126 |
| 124 tpm_fd = open(device_path, O_RDWR); | 127 tpm_fd = open(device_path, O_RDWR); |
| 125 if (tpm_fd < 0) { | 128 if (tpm_fd < 0) { |
| 126 error("cannot open TPM device %s: %s\n", device_path, strerror(errno)); | 129 VBDEBUG(("TPM: Cannot open TPM device %s: %s\n", device_path, |
| 130 strerror(errno))); |
| 131 return TPM_E_IOERROR; |
| 127 } | 132 } |
| 133 |
| 134 return 0; |
| 128 } | 135 } |
| 129 | 136 |
| 130 | 137 |
| 131 uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, | 138 uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, |
| 132 uint8_t* response, int max_length) { | 139 uint8_t* response, int max_length) { |
| 133 /* | 140 /* |
| 134 * In a real firmware implementation, this function should contain | 141 * In a real firmware implementation, this function should contain |
| 135 * the equivalent API call for the firmware TPM driver which takes a | 142 * the equivalent API call for the firmware TPM driver which takes a |
| 136 * raw sequence of bytes as input command and a pointer to the | 143 * raw sequence of bytes as input command and a pointer to the |
| 137 * output buffer for putting in the results. | 144 * output buffer for putting in the results. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 (tag == TPM_TAG_RQU_COMMAND && | 185 (tag == TPM_TAG_RQU_COMMAND && |
| 179 response_tag == TPM_TAG_RSP_COMMAND) || | 186 response_tag == TPM_TAG_RSP_COMMAND) || |
| 180 (tag == TPM_TAG_RQU_AUTH1_COMMAND && | 187 (tag == TPM_TAG_RQU_AUTH1_COMMAND && |
| 181 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || | 188 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || |
| 182 (tag == TPM_TAG_RQU_AUTH2_COMMAND && | 189 (tag == TPM_TAG_RQU_AUTH2_COMMAND && |
| 183 response_tag == TPM_TAG_RSP_AUTH2_COMMAND)); | 190 response_tag == TPM_TAG_RSP_AUTH2_COMMAND)); |
| 184 assert(response_length == TpmResponseSize(response)); | 191 assert(response_length == TpmResponseSize(response)); |
| 185 | 192 |
| 186 return 0; /* Success */ | 193 return 0; /* Success */ |
| 187 } | 194 } |
| OLD | NEW |