Chromium Code Reviews| 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 close(tpm_fd); |
|
Randall Spangler
2010/12/14 18:12:28
if (tpm_fd != -1)
close(tpm_fd);
(don't close i
Che-Liang Chiou
2010/12/15 03:04:37
Done.
| |
| 109 tpm_fd = -1; | 109 tpm_fd = -1; |
| 110 return 0; | |
| 110 } | 111 } |
| 111 | 112 |
| 112 | 113 |
| 113 void TlclOpenDevice(void) { | 114 uint32_t TlclOpenDevice(void) { |
| 114 char* device_path; | 115 char* device_path; |
| 115 | 116 |
| 116 if (tpm_fd >= 0) | 117 if (tpm_fd >= 0) |
| 117 return; /* Already open */ | 118 return 0; /* Already open */ |
| 118 | 119 |
| 119 device_path = getenv("TPM_DEVICE_PATH"); | 120 device_path = getenv("TPM_DEVICE_PATH"); |
| 120 if (device_path == NULL) { | 121 if (device_path == NULL) { |
| 121 device_path = TPM_DEVICE_PATH; | 122 device_path = TPM_DEVICE_PATH; |
| 122 } | 123 } |
| 123 | 124 |
| 124 tpm_fd = open(device_path, O_RDWR); | 125 tpm_fd = open(device_path, O_RDWR); |
| 125 if (tpm_fd < 0) { | 126 if (tpm_fd < 0) { |
| 126 error("cannot open TPM device %s: %s\n", device_path, strerror(errno)); | 127 error("cannot open TPM device %s: %s\n", device_path, strerror(errno)); |
| 128 return TPM_E_IOERROR; | |
| 127 } | 129 } |
| 130 | |
| 131 return 0; | |
| 128 } | 132 } |
| 129 | 133 |
| 130 | 134 |
| 131 uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, | 135 uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, |
| 132 uint8_t* response, int max_length) { | 136 uint8_t* response, int max_length) { |
| 133 /* | 137 /* |
| 134 * In a real firmware implementation, this function should contain | 138 * In a real firmware implementation, this function should contain |
| 135 * the equivalent API call for the firmware TPM driver which takes a | 139 * 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 | 140 * raw sequence of bytes as input command and a pointer to the |
| 137 * output buffer for putting in the results. | 141 * 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 && | 182 (tag == TPM_TAG_RQU_COMMAND && |
| 179 response_tag == TPM_TAG_RSP_COMMAND) || | 183 response_tag == TPM_TAG_RSP_COMMAND) || |
| 180 (tag == TPM_TAG_RQU_AUTH1_COMMAND && | 184 (tag == TPM_TAG_RQU_AUTH1_COMMAND && |
| 181 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || | 185 response_tag == TPM_TAG_RSP_AUTH1_COMMAND) || |
| 182 (tag == TPM_TAG_RQU_AUTH2_COMMAND && | 186 (tag == TPM_TAG_RQU_AUTH2_COMMAND && |
| 183 response_tag == TPM_TAG_RSP_AUTH2_COMMAND)); | 187 response_tag == TPM_TAG_RSP_AUTH2_COMMAND)); |
| 184 assert(response_length == TpmResponseSize(response)); | 188 assert(response_length == TpmResponseSize(response)); |
| 185 | 189 |
| 186 return 0; /* Success */ | 190 return 0; /* Success */ |
| 187 } | 191 } |
| OLD | NEW |