| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 * | 5 * |
| 6 * Alternatively, this software may be distributed under the terms of the | 6 * Alternatively, this software may be distributed under the terms of the |
| 7 * GNU General Public License ("GPL") version 2 as published by the Free | 7 * GNU General Public License ("GPL") version 2 as published by the Free |
| 8 * Software Foundation. | 8 * Software Foundation. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <config.h> | 11 #include <config.h> |
| 12 #include <common.h> | 12 #include <common.h> |
| 13 #include <tlcl_stub.h> | 13 #include <tlcl_stub.h> |
| 14 #include <tpm.h> | 14 #include <tpm.h> |
| 15 | 15 |
| 16 /* A simple TPM library implementation for now */ | 16 /* A simple TPM library implementation for now */ |
| 17 | 17 |
| 18 uint32_t TlclStubInit(void) | 18 uint32_t TlclStubInit(void) |
| 19 { | 19 { |
| 20 #ifdef CONFIG_HARDWARE_TPM | 20 #ifdef CONFIG_HARDWARE_TPM |
| 21 » return tpm_init(); | 21 » int ret = tis_init(); |
| 22 #else | 22 » if (ret) |
| 23 » » return TPM_E_IOERROR; |
| 24 » /* tpm-lite lib doesn't call TlclOpenDevice after TlclStubInit */ |
| 25 » ret = tis_open(); |
| 26 » if (ret) |
| 27 » » return TPM_E_IOERROR; |
| 28 #endif |
| 23 return TPM_SUCCESS; | 29 return TPM_SUCCESS; |
| 24 #endif | |
| 25 } | 30 } |
| 26 | 31 |
| 27 uint32_t TlclCloseDevice(void) | 32 uint32_t TlclCloseDevice(void) |
| 28 { | 33 { |
| 34 #ifdef CONFIG_HARDWARE_TPM |
| 35 int ret = tis_close(); |
| 36 if (ret) |
| 37 return TPM_E_IOERROR; |
| 38 #endif |
| 29 return TPM_SUCCESS; | 39 return TPM_SUCCESS; |
| 30 } | 40 } |
| 31 | 41 |
| 32 uint32_t TlclOpenDevice(void) | 42 uint32_t TlclOpenDevice(void) |
| 33 { | 43 { |
| 44 #ifdef CONFIG_HARDWARE_TPM |
| 45 int ret = tis_open(); |
| 46 if (ret) |
| 47 return TPM_E_IOERROR; |
| 48 #endif |
| 34 return TPM_SUCCESS; | 49 return TPM_SUCCESS; |
| 35 } | 50 } |
| 36 | 51 |
| 37 uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, | 52 uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, |
| 38 uint8_t* response, int max_length) | 53 uint8_t* response, int max_length) |
| 39 { | 54 { |
| 40 #ifdef CONFIG_HARDWARE_TPM | 55 #ifdef CONFIG_HARDWARE_TPM |
| 41 » int ret_code; | 56 » int ret; |
| 42 » ret_code = tpm_send(request, request_length); | 57 » size_t recv_len = (size_t) max_length; |
| 43 » if (ret_code) | 58 » ret= tis_sendrecv(request, request_length, response, &recv_len); |
| 59 » if (ret) |
| 44 return TPM_E_IOERROR; | 60 return TPM_E_IOERROR; |
| 45 » ret_code = tpm_receive(response, max_length); | 61 #endif |
| 46 » if (ret_code) | |
| 47 » » return TPM_E_IOERROR; | |
| 48 return TPM_SUCCESS; | 62 return TPM_SUCCESS; |
| 49 #else | |
| 50 return TPM_SUCCESS; | |
| 51 #endif | |
| 52 } | 63 } |
| 53 | 64 |
| OLD | NEW |