Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 1 | // Implementation of the TCG BIOS extension according to the specification |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 2 | // described in specs found at |
| 3 | // http://www.trustedcomputinggroup.org/resources/pc_client_work_group_specific_implementation_specification_for_conventional_bios |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 4 | // |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 5 | // Copyright (C) 2006-2011, 2014, 2015 IBM Corporation |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 6 | // |
| 7 | // Authors: |
| 8 | // Stefan Berger <stefanb@linux.vnet.ibm.com> |
| 9 | // |
| 10 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 11 | |
Kevin O'Connor | df50aaa | 2015-11-19 09:24:18 -0500 | [diff] [blame] | 12 | #include "bregs.h" // struct bregs |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 13 | #include "byteorder.h" // cpu_to_* |
Kevin O'Connor | df50aaa | 2015-11-19 09:24:18 -0500 | [diff] [blame] | 14 | #include "config.h" // CONFIG_TCGBIOS |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 15 | #include "farptr.h" // MAKE_FLATPTR |
Kevin O'Connor | df50aaa | 2015-11-19 09:24:18 -0500 | [diff] [blame] | 16 | #include "fw/paravirt.h" // runningOnXen |
| 17 | #include "hw/tpm_drivers.h" // tpm_drivers[] |
| 18 | #include "output.h" // dprintf |
| 19 | #include "sha1.h" // sha1 |
| 20 | #include "std/acpi.h" // RSDP_SIGNATURE, rsdt_descriptor |
| 21 | #include "std/smbios.h" // struct smbios_entry_point |
| 22 | #include "std/tcg.h" // TCG_PC_LOGOVERFLOW |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 23 | #include "string.h" // checksum |
| 24 | #include "tcgbios.h"// tpm_*, prototypes |
| 25 | #include "util.h" // printf, get_keystroke |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 26 | #include "stacks.h" // wait_threads, reset |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 27 | |
Stefan Berger | 0d289b5 | 2015-06-09 19:56:29 -0400 | [diff] [blame] | 28 | static const u8 Startup_ST_CLEAR[] = { 0x00, TPM_ST_CLEAR }; |
| 29 | static const u8 Startup_ST_STATE[] = { 0x00, TPM_ST_STATE }; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 30 | |
Stefan Berger | 0d289b5 | 2015-06-09 19:56:29 -0400 | [diff] [blame] | 31 | static const u8 PhysicalPresence_CMD_ENABLE[] = { 0x00, 0x20 }; |
| 32 | static const u8 PhysicalPresence_CMD_DISABLE[] = { 0x01, 0x00 }; |
| 33 | static const u8 PhysicalPresence_PRESENT[] = { 0x00, 0x08 }; |
| 34 | static const u8 PhysicalPresence_NOT_PRESENT_LOCK[] = { 0x00, 0x14 }; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 35 | |
| 36 | static const u8 CommandFlag_FALSE[1] = { 0x00 }; |
| 37 | static const u8 CommandFlag_TRUE[1] = { 0x01 }; |
| 38 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 39 | typedef u8 tpm_ppi_code; |
| 40 | |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 41 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 42 | /**************************************************************** |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 43 | * ACPI TCPA table interface |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 44 | ****************************************************************/ |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 45 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 46 | struct { |
Stefan Berger | 60bb9e9 | 2015-11-21 14:54:42 -0500 | [diff] [blame] | 47 | /* length of the TCPA log buffer */ |
| 48 | u32 log_area_minimum_length; |
| 49 | |
| 50 | /* start address of TCPA log buffer */ |
| 51 | u8 * log_area_start_address; |
| 52 | |
| 53 | /* number of log entries written */ |
| 54 | u32 entry_count; |
| 55 | |
| 56 | /* address to write next log entry to */ |
| 57 | u8 * log_area_next_entry; |
| 58 | |
| 59 | /* address of last entry written (need for TCG_StatusCheck) */ |
| 60 | u8 * log_area_last_entry; |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 61 | } tpm_state VARLOW; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 62 | |
| 63 | static struct tcpa_descriptor_rev2 * |
| 64 | find_tcpa_by_rsdp(struct rsdp_descriptor *rsdp) |
| 65 | { |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 66 | if (!rsdp) { |
| 67 | dprintf(DEBUG_tcg, |
| 68 | "TCGBIOS: RSDP was NOT found! -- Disabling interface.\n"); |
| 69 | return NULL; |
| 70 | } |
| 71 | struct rsdt_descriptor *rsdt = (void*)rsdp->rsdt_physical_address; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 72 | if (!rsdt) |
| 73 | return NULL; |
| 74 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 75 | u32 length = rsdt->length; |
| 76 | u16 off = offsetof(struct rsdt_descriptor, entry); |
| 77 | u32 ctr = 0; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 78 | while ((off + sizeof(rsdt->entry[0])) <= length) { |
| 79 | /* try all pointers to structures */ |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 80 | struct tcpa_descriptor_rev2 *tcpa = (void*)rsdt->entry[ctr]; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 81 | |
| 82 | /* valid TCPA ACPI table ? */ |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 83 | if (tcpa->signature == TCPA_SIGNATURE |
| 84 | && checksum(tcpa, tcpa->length) == 0) |
| 85 | return tcpa; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 86 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 87 | off += sizeof(rsdt->entry[0]); |
| 88 | ctr++; |
| 89 | } |
| 90 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 91 | dprintf(DEBUG_tcg, "TCGBIOS: TCPA ACPI was NOT found!\n"); |
| 92 | return NULL; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 95 | static int |
| 96 | tpm_tcpa_probe(void) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 97 | { |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 98 | struct tcpa_descriptor_rev2 *tcpa = find_tcpa_by_rsdp(RsdpAddr); |
| 99 | if (!tcpa) |
| 100 | return -1; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 101 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 102 | u8 *log_area_start_address = (u8*)(long)tcpa->log_area_start_address; |
| 103 | u32 log_area_minimum_length = tcpa->log_area_minimum_length; |
| 104 | if (!log_area_start_address || !log_area_minimum_length) |
| 105 | return -1; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 106 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 107 | memset(log_area_start_address, 0, log_area_minimum_length); |
| 108 | tpm_state.log_area_start_address = log_area_start_address; |
| 109 | tpm_state.log_area_minimum_length = log_area_minimum_length; |
| 110 | tpm_state.log_area_next_entry = log_area_start_address; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 111 | tpm_state.log_area_last_entry = NULL; |
| 112 | tpm_state.entry_count = 0; |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 113 | return 0; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 116 | /* |
| 117 | * Extend the ACPI log with the given entry by copying the |
| 118 | * entry data into the log. |
| 119 | * Input |
| 120 | * pcpes : Pointer to the event 'header' to be copied into the log |
| 121 | * event : Pointer to the event 'body' to be copied into the log |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 122 | * |
| 123 | * Output: |
| 124 | * Returns an error code in case of faiure, 0 in case of success |
| 125 | */ |
| 126 | static u32 |
Kevin O'Connor | 4e7cf9c | 2015-11-22 18:51:31 -0500 | [diff] [blame] | 127 | tpm_log_event(struct pcpes *pcpes, const void *event) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 128 | { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 129 | dprintf(DEBUG_tcg, "TCGBIOS: LASA = %p, next entry = %p\n", |
| 130 | tpm_state.log_area_start_address, tpm_state.log_area_next_entry); |
| 131 | |
Kevin O'Connor | f4820ac | 2015-11-22 11:00:06 -0500 | [diff] [blame] | 132 | if (tpm_state.log_area_next_entry == NULL) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 133 | return TCG_PC_LOGOVERFLOW; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 134 | |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 135 | u32 size = sizeof(*pcpes) + pcpes->eventdatasize; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 136 | |
| 137 | if ((tpm_state.log_area_next_entry + size - tpm_state.log_area_start_address) > |
| 138 | tpm_state.log_area_minimum_length) { |
| 139 | dprintf(DEBUG_tcg, "TCGBIOS: LOG OVERFLOW: size = %d\n", size); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 140 | return TCG_PC_LOGOVERFLOW; |
| 141 | } |
| 142 | |
Kevin O'Connor | bad6f96 | 2015-11-23 22:32:09 -0500 | [diff] [blame] | 143 | memcpy(tpm_state.log_area_next_entry, pcpes, sizeof(*pcpes)); |
| 144 | memcpy(tpm_state.log_area_next_entry + sizeof(*pcpes), |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 145 | event, pcpes->eventdatasize); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 146 | |
| 147 | tpm_state.log_area_last_entry = tpm_state.log_area_next_entry; |
| 148 | tpm_state.log_area_next_entry += size; |
| 149 | tpm_state.entry_count++; |
| 150 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | /**************************************************************** |
| 156 | * Helper functions |
| 157 | ****************************************************************/ |
| 158 | |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 159 | u8 TPM_working VARLOW; |
| 160 | |
| 161 | int |
| 162 | tpm_is_working(void) |
| 163 | { |
| 164 | return CONFIG_TCGBIOS && TPM_working; |
| 165 | } |
| 166 | |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 167 | /* |
| 168 | * Send a TPM command with the given ordinal. Append the given buffer |
| 169 | * containing all data in network byte order to the command (this is |
| 170 | * the custom part per command) and expect a response of the given size. |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 171 | */ |
| 172 | static u32 |
Stefan Berger | 47b9df5 | 2015-11-21 14:54:40 -0500 | [diff] [blame] | 173 | build_and_send_cmd(u8 locty, u32 ordinal, const u8 *append, u32 append_size, |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 174 | u32 *returnCode, enum tpmDurationType to_t) |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 175 | { |
Kevin O'Connor | b82bc51 | 2015-11-22 17:56:53 -0500 | [diff] [blame] | 176 | struct { |
| 177 | struct tpm_req_header trqh; |
| 178 | u8 cmd[20]; |
| 179 | } PACKED req = { |
| 180 | .trqh.tag = cpu_to_be16(TPM_TAG_RQU_CMD), |
Kevin O'Connor | 7ba0568 | 2015-11-22 18:21:45 -0500 | [diff] [blame] | 181 | .trqh.totlen = cpu_to_be32(sizeof(req.trqh) + append_size), |
Kevin O'Connor | b82bc51 | 2015-11-22 17:56:53 -0500 | [diff] [blame] | 182 | .trqh.ordinal = cpu_to_be32(ordinal), |
| 183 | }; |
Stefan Berger | ece2561 | 2015-11-12 10:14:46 -0500 | [diff] [blame] | 184 | u8 obuffer[64]; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 185 | struct tpm_rsp_header *trsh = (struct tpm_rsp_header *)obuffer; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 186 | u32 obuffer_len = sizeof(obuffer); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 187 | memset(obuffer, 0x0, sizeof(obuffer)); |
| 188 | |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 189 | if (append_size > sizeof(req.cmd)) { |
Kevin O'Connor | b82bc51 | 2015-11-22 17:56:53 -0500 | [diff] [blame] | 190 | warn_internalerror(); |
| 191 | return TCG_FIRMWARE_ERROR; |
| 192 | } |
| 193 | if (append_size) |
| 194 | memcpy(req.cmd, append, append_size); |
| 195 | |
Kevin O'Connor | 2df7028 | 2015-11-28 13:43:22 -0500 | [diff] [blame] | 196 | u32 rc = tpmhw_transmit(locty, &req.trqh, obuffer, &obuffer_len, to_t); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 197 | if (rc) |
| 198 | return rc; |
| 199 | |
| 200 | *returnCode = be32_to_cpu(trsh->errcode); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 204 | static void |
| 205 | tpm_set_failure(void) |
| 206 | { |
| 207 | u32 returnCode; |
| 208 | |
| 209 | /* we will try to deactivate the TPM now - ignoring all errors */ |
| 210 | build_and_send_cmd(0, TPM_ORD_PhysicalPresence, |
| 211 | PhysicalPresence_CMD_ENABLE, |
| 212 | sizeof(PhysicalPresence_CMD_ENABLE), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 213 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 214 | |
| 215 | build_and_send_cmd(0, TPM_ORD_PhysicalPresence, |
| 216 | PhysicalPresence_PRESENT, |
| 217 | sizeof(PhysicalPresence_PRESENT), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 218 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 219 | |
| 220 | build_and_send_cmd(0, TPM_ORD_SetTempDeactivated, |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 221 | NULL, 0, &returnCode, TPM_DURATION_TYPE_SHORT); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 222 | |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 223 | TPM_working = 0; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 224 | } |
| 225 | |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 226 | static int |
| 227 | tpm_get_capability(u32 cap, u32 subcap, struct tpm_rsp_header *rsp, u32 rsize) |
| 228 | { |
| 229 | struct tpm_req_getcap trgc = { |
| 230 | .hdr.tag = cpu_to_be16(TPM_TAG_RQU_CMD), |
| 231 | .hdr.totlen = cpu_to_be32(sizeof(trgc)), |
| 232 | .hdr.ordinal = cpu_to_be32(TPM_ORD_GetCapability), |
| 233 | .capArea = cpu_to_be32(cap), |
| 234 | .subCapSize = cpu_to_be32(sizeof(trgc.subCap)), |
| 235 | .subCap = cpu_to_be32(subcap) |
| 236 | }; |
| 237 | u32 resp_size = rsize; |
| 238 | u32 rc = tpmhw_transmit(0, &trgc.hdr, rsp, &resp_size, |
| 239 | TPM_DURATION_TYPE_SHORT); |
| 240 | int ret = (rc || resp_size != rsize) ? -1 : be32_to_cpu(rsp->errcode); |
| 241 | dprintf(DEBUG_tcg, "TCGBIOS: Return code from TPM_GetCapability(%d, %d)" |
| 242 | " = %x\n", cap, subcap, ret); |
| 243 | if (ret) { |
| 244 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 245 | tpm_set_failure(); |
| 246 | } |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | static int |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 251 | determine_timeouts(void) |
| 252 | { |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 253 | struct tpm_res_getcap_timeouts timeouts; |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 254 | int ret = tpm_get_capability(TPM_CAP_PROPERTY, TPM_CAP_PROP_TIS_TIMEOUT |
| 255 | , &timeouts.hdr, sizeof(timeouts)); |
| 256 | if (ret) |
| 257 | return ret; |
| 258 | |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 259 | struct tpm_res_getcap_durations durations; |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 260 | ret = tpm_get_capability(TPM_CAP_PROPERTY, TPM_CAP_PROP_DURATION |
| 261 | , &durations.hdr, sizeof(durations)); |
| 262 | if (ret) |
| 263 | return ret; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 264 | |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 265 | int i; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 266 | for (i = 0; i < 3; i++) |
| 267 | durations.durations[i] = be32_to_cpu(durations.durations[i]); |
| 268 | |
| 269 | for (i = 0; i < 4; i++) |
| 270 | timeouts.timeouts[i] = be32_to_cpu(timeouts.timeouts[i]); |
| 271 | |
| 272 | dprintf(DEBUG_tcg, "TCGBIOS: timeouts: %u %u %u %u\n", |
| 273 | timeouts.timeouts[0], |
| 274 | timeouts.timeouts[1], |
| 275 | timeouts.timeouts[2], |
| 276 | timeouts.timeouts[3]); |
| 277 | |
| 278 | dprintf(DEBUG_tcg, "TCGBIOS: durations: %u %u %u\n", |
| 279 | durations.durations[0], |
| 280 | durations.durations[1], |
| 281 | durations.durations[2]); |
| 282 | |
Kevin O'Connor | ba86edb | 2015-11-19 18:03:35 -0500 | [diff] [blame] | 283 | tpmhw_set_timeouts(timeouts.timeouts, durations.durations); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 284 | |
| 285 | return 0; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 288 | static u32 |
Kevin O'Connor | 4e7cf9c | 2015-11-22 18:51:31 -0500 | [diff] [blame] | 289 | tpm_log_extend_event(struct pcpes *pcpes, const void *event) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 290 | { |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 291 | if (!tpm_is_working()) |
Kevin O'Connor | f4820ac | 2015-11-22 11:00:06 -0500 | [diff] [blame] | 292 | return TCG_GENERAL_ERROR; |
| 293 | |
Kevin O'Connor | 4e7cf9c | 2015-11-22 18:51:31 -0500 | [diff] [blame] | 294 | if (pcpes->pcrindex >= 24) |
| 295 | return TCG_INVALID_INPUT_PARA; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 296 | |
Kevin O'Connor | 948f3c9 | 2015-11-22 19:16:16 -0500 | [diff] [blame] | 297 | struct tpm_req_extend tre = { |
Kevin O'Connor | a059915 | 2015-11-28 08:08:57 -0500 | [diff] [blame] | 298 | .hdr.tag = cpu_to_be16(TPM_TAG_RQU_CMD), |
| 299 | .hdr.totlen = cpu_to_be32(sizeof(tre)), |
| 300 | .hdr.ordinal = cpu_to_be32(TPM_ORD_Extend), |
| 301 | .pcrindex = cpu_to_be32(pcpes->pcrindex), |
Kevin O'Connor | 948f3c9 | 2015-11-22 19:16:16 -0500 | [diff] [blame] | 302 | }; |
| 303 | memcpy(tre.digest, pcpes->digest, sizeof(tre.digest)); |
| 304 | |
| 305 | struct tpm_rsp_extend rsp; |
| 306 | u32 resp_length = sizeof(rsp); |
Kevin O'Connor | 2df7028 | 2015-11-28 13:43:22 -0500 | [diff] [blame] | 307 | u32 rc = tpmhw_transmit(0, &tre.hdr, &rsp, &resp_length, |
| 308 | TPM_DURATION_TYPE_SHORT); |
Kevin O'Connor | 948f3c9 | 2015-11-22 19:16:16 -0500 | [diff] [blame] | 309 | if (rc || resp_length != sizeof(rsp)) { |
Kevin O'Connor | 4e7cf9c | 2015-11-22 18:51:31 -0500 | [diff] [blame] | 310 | tpm_set_failure(); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 311 | return rc; |
Kevin O'Connor | 4e7cf9c | 2015-11-22 18:51:31 -0500 | [diff] [blame] | 312 | } |
Kevin O'Connor | 948f3c9 | 2015-11-22 19:16:16 -0500 | [diff] [blame] | 313 | |
| 314 | rc = tpm_log_event(pcpes, event); |
| 315 | if (rc) |
| 316 | tpm_set_failure(); |
| 317 | return rc; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Kevin O'Connor | 9224440 | 2015-11-22 16:54:18 -0500 | [diff] [blame] | 320 | static void |
| 321 | tpm_fill_hash(struct pcpes *pcpes, const void *hashdata, u32 hashdata_length) |
| 322 | { |
| 323 | if (hashdata) |
| 324 | sha1(hashdata, hashdata_length, pcpes->digest); |
| 325 | } |
| 326 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 327 | /* |
| 328 | * Add a measurement to the log; the data at data_seg:data/length are |
| 329 | * appended to the TCG_PCClientPCREventStruct |
| 330 | * |
| 331 | * Input parameters: |
| 332 | * pcrindex : which PCR to extend |
| 333 | * event_type : type of event; specs section on 'Event Types' |
| 334 | * event : pointer to info (e.g., string) to be added to log as-is |
| 335 | * event_length: length of the event |
| 336 | * hashdata : pointer to the data to be hashed |
| 337 | * hashdata_length: length of the data to be hashed |
| 338 | */ |
| 339 | static u32 |
| 340 | tpm_add_measurement_to_log(u32 pcrindex, u32 event_type, |
| 341 | const char *event, u32 event_length, |
| 342 | const u8 *hashdata, u32 hashdata_length) |
| 343 | { |
| 344 | struct pcpes pcpes = { |
| 345 | .pcrindex = pcrindex, |
| 346 | .eventtype = event_type, |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 347 | .eventdatasize = event_length, |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 348 | }; |
Kevin O'Connor | 9224440 | 2015-11-22 16:54:18 -0500 | [diff] [blame] | 349 | tpm_fill_hash(&pcpes, hashdata, hashdata_length); |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 350 | return tpm_log_extend_event(&pcpes, event); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
| 354 | /**************************************************************** |
| 355 | * Setup and Measurements |
| 356 | ****************************************************************/ |
| 357 | |
Kevin O'Connor | a617542 | 2015-11-22 11:28:14 -0500 | [diff] [blame] | 358 | // Add an EV_ACTION measurement to the list of measurements |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 359 | static u32 |
Kevin O'Connor | a617542 | 2015-11-22 11:28:14 -0500 | [diff] [blame] | 360 | tpm_add_action(u32 pcrIndex, const char *string) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 361 | { |
Kevin O'Connor | a617542 | 2015-11-22 11:28:14 -0500 | [diff] [blame] | 362 | u32 len = strlen(string); |
| 363 | return tpm_add_measurement_to_log(pcrIndex, EV_ACTION, |
| 364 | string, len, (u8 *)string, len); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 365 | } |
| 366 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 367 | /* |
| 368 | * Add event separators for PCRs 0 to 7; specs on 'Measuring Boot Events' |
| 369 | */ |
| 370 | static u32 |
| 371 | tpm_add_event_separators(void) |
| 372 | { |
| 373 | u32 rc; |
| 374 | u32 pcrIndex = 0; |
| 375 | |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 376 | if (!tpm_is_working()) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 377 | return TCG_GENERAL_ERROR; |
| 378 | |
Kevin O'Connor | a617542 | 2015-11-22 11:28:14 -0500 | [diff] [blame] | 379 | static const u8 evt_separator[] = {0xff,0xff,0xff,0xff}; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 380 | while (pcrIndex <= 7) { |
Kevin O'Connor | a617542 | 2015-11-22 11:28:14 -0500 | [diff] [blame] | 381 | rc = tpm_add_measurement_to_log(pcrIndex, EV_SEPARATOR, |
| 382 | NULL, 0, |
| 383 | (u8 *)evt_separator, |
| 384 | sizeof(evt_separator)); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 385 | if (rc) |
| 386 | break; |
| 387 | pcrIndex ++; |
| 388 | } |
| 389 | |
| 390 | return rc; |
| 391 | } |
| 392 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 393 | static u32 |
| 394 | tpm_smbios_measure(void) |
| 395 | { |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 396 | if (!tpm_is_working()) |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 397 | return TCG_GENERAL_ERROR; |
| 398 | |
| 399 | u32 rc; |
| 400 | struct pcctes pcctes = { |
| 401 | .eventid = 1, |
| 402 | .eventdatasize = SHA1_BUFSIZE, |
| 403 | }; |
| 404 | struct smbios_entry_point *sep = SMBiosAddr; |
| 405 | |
| 406 | dprintf(DEBUG_tcg, "TCGBIOS: SMBIOS at %p\n", sep); |
| 407 | |
| 408 | if (!sep) |
| 409 | return 0; |
| 410 | |
| 411 | rc = sha1((const u8 *)sep->structure_table_address, |
| 412 | sep->structure_table_length, pcctes.digest); |
| 413 | if (rc) |
| 414 | return rc; |
| 415 | |
| 416 | return tpm_add_measurement_to_log(1, |
| 417 | EV_EVENT_TAG, |
| 418 | (const char *)&pcctes, sizeof(pcctes), |
| 419 | (u8 *)&pcctes, sizeof(pcctes)); |
| 420 | } |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 421 | |
| 422 | static u32 |
| 423 | tpm_startup(void) |
| 424 | { |
| 425 | u32 rc; |
| 426 | u32 returnCode; |
| 427 | |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 428 | if (!tpm_is_working()) |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 429 | return TCG_GENERAL_ERROR; |
| 430 | |
| 431 | dprintf(DEBUG_tcg, "TCGBIOS: Starting with TPM_Startup(ST_CLEAR)\n"); |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 432 | rc = build_and_send_cmd(0, TPM_ORD_Startup, |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 433 | Startup_ST_CLEAR, sizeof(Startup_ST_CLEAR), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 434 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 435 | |
| 436 | dprintf(DEBUG_tcg, "Return code from TPM_Startup = 0x%08x\n", |
| 437 | returnCode); |
| 438 | |
| 439 | if (CONFIG_COREBOOT) { |
| 440 | /* with other firmware on the system the TPM may already have been |
| 441 | * initialized |
| 442 | */ |
| 443 | if (returnCode == TPM_INVALID_POSTINIT) |
| 444 | returnCode = 0; |
| 445 | } |
| 446 | |
| 447 | if (rc || returnCode) |
| 448 | goto err_exit; |
| 449 | |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 450 | int ret = determine_timeouts(); |
| 451 | if (ret) |
| 452 | return TCG_TCG_COMMAND_ERROR; |
Stefan Berger | ec42c8d | 2015-11-21 14:54:41 -0500 | [diff] [blame] | 453 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 454 | rc = build_and_send_cmd(0, TPM_ORD_SelfTestFull, NULL, 0, |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 455 | &returnCode, TPM_DURATION_TYPE_LONG); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 456 | |
| 457 | dprintf(DEBUG_tcg, "Return code from TPM_SelfTestFull = 0x%08x\n", |
| 458 | returnCode); |
| 459 | |
| 460 | if (rc || returnCode) |
| 461 | goto err_exit; |
| 462 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 463 | rc = build_and_send_cmd(3, TSC_ORD_ResetEstablishmentBit, NULL, 0, |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 464 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 465 | |
| 466 | dprintf(DEBUG_tcg, "Return code from TSC_ResetEstablishmentBit = 0x%08x\n", |
| 467 | returnCode); |
| 468 | |
| 469 | if (rc || (returnCode != 0 && returnCode != TPM_BAD_LOCALITY)) |
| 470 | goto err_exit; |
| 471 | |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 472 | rc = tpm_smbios_measure(); |
| 473 | if (rc) |
| 474 | goto err_exit; |
| 475 | |
Kevin O'Connor | 1257533 | 2015-11-22 11:34:38 -0500 | [diff] [blame] | 476 | rc = tpm_add_action(2, "Start Option ROM Scan"); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 477 | if (rc) |
| 478 | goto err_exit; |
| 479 | |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 480 | return 0; |
| 481 | |
| 482 | err_exit: |
| 483 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 484 | |
Stefan Berger | 7fce1d9 | 2015-11-12 10:14:45 -0500 | [diff] [blame] | 485 | tpm_set_failure(); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 486 | if (rc) |
| 487 | return rc; |
| 488 | return TCG_TCG_COMMAND_ERROR; |
| 489 | } |
| 490 | |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 491 | void |
| 492 | tpm_setup(void) |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 493 | { |
| 494 | if (!CONFIG_TCGBIOS) |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 495 | return; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 496 | |
Kevin O'Connor | 2706532 | 2015-11-28 14:25:41 -0500 | [diff] [blame] | 497 | int ret = tpmhw_probe(); |
| 498 | if (ret) |
| 499 | return; |
| 500 | |
| 501 | ret = tpm_tcpa_probe(); |
| 502 | if (ret) |
| 503 | return; |
| 504 | |
| 505 | TPM_working = 1; |
| 506 | |
Quan Xu | 6764395 | 2015-04-30 19:43:04 -0400 | [diff] [blame] | 507 | if (runningOnXen()) |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 508 | return; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 509 | |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 510 | tpm_startup(); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 511 | } |
| 512 | |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 513 | void |
| 514 | tpm_prepboot(void) |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 515 | { |
| 516 | u32 rc; |
| 517 | u32 returnCode; |
| 518 | |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 519 | if (!tpm_is_working()) |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 520 | return; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 521 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 522 | rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence, |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 523 | PhysicalPresence_CMD_ENABLE, |
| 524 | sizeof(PhysicalPresence_CMD_ENABLE), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 525 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 526 | if (rc || returnCode) |
| 527 | goto err_exit; |
| 528 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 529 | rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence, |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 530 | PhysicalPresence_NOT_PRESENT_LOCK, |
| 531 | sizeof(PhysicalPresence_NOT_PRESENT_LOCK), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 532 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 533 | if (rc || returnCode) |
| 534 | goto err_exit; |
| 535 | |
Kevin O'Connor | 1257533 | 2015-11-22 11:34:38 -0500 | [diff] [blame] | 536 | rc = tpm_add_action(4, "Calling INT 19h"); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 537 | if (rc) |
| 538 | goto err_exit; |
| 539 | |
| 540 | rc = tpm_add_event_separators(); |
| 541 | if (rc) |
| 542 | goto err_exit; |
| 543 | |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 544 | return; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 545 | |
| 546 | err_exit: |
| 547 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 548 | |
Stefan Berger | 7fce1d9 | 2015-11-12 10:14:45 -0500 | [diff] [blame] | 549 | tpm_set_failure(); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 552 | /* |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 553 | * Add measurement to the log about an option rom |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 554 | */ |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 555 | u32 |
| 556 | tpm_option_rom(const void *addr, u32 len) |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 557 | { |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 558 | if (!tpm_is_working()) |
Stefan Berger | 7fce1d9 | 2015-11-12 10:14:45 -0500 | [diff] [blame] | 559 | return TCG_GENERAL_ERROR; |
| 560 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 561 | u32 rc; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 562 | struct pcctes_romex pcctes = { |
| 563 | .eventid = 7, |
| 564 | .eventdatasize = sizeof(u16) + sizeof(u16) + SHA1_BUFSIZE, |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 565 | }; |
| 566 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 567 | rc = sha1((const u8 *)addr, len, pcctes.digest); |
Stefan Berger | 6c376b4 | 2015-11-12 10:14:49 -0500 | [diff] [blame] | 568 | if (rc) |
| 569 | return rc; |
| 570 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 571 | return tpm_add_measurement_to_log(2, |
| 572 | EV_EVENT_TAG, |
| 573 | (const char *)&pcctes, sizeof(pcctes), |
| 574 | (u8 *)&pcctes, sizeof(pcctes)); |
Stefan Berger | 6c376b4 | 2015-11-12 10:14:49 -0500 | [diff] [blame] | 575 | } |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 576 | |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 577 | u32 |
| 578 | tpm_add_bcv(u32 bootdrv, const u8 *addr, u32 length) |
| 579 | { |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 580 | if (!tpm_is_working()) |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 581 | return TCG_GENERAL_ERROR; |
| 582 | |
Stefan Berger | 4cdbc41 | 2015-11-30 11:14:18 -0500 | [diff] [blame] | 583 | if (length < 0x200) |
| 584 | return TCG_INVALID_INPUT_PARA; |
| 585 | |
Kevin O'Connor | 8bd4a08 | 2015-11-19 17:43:27 -0500 | [diff] [blame] | 586 | const char *string = "Booting BCV device 00h (Floppy)"; |
| 587 | if (bootdrv == 0x80) |
| 588 | string = "Booting BCV device 80h (HDD)"; |
| 589 | u32 rc = tpm_add_action(4, string); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 590 | if (rc) |
| 591 | return rc; |
| 592 | |
Kevin O'Connor | 7ea191b | 2015-11-22 11:15:51 -0500 | [diff] [blame] | 593 | /* specs: see section 'Hard Disk Device or Hard Disk-Like Devices' */ |
| 594 | /* equivalent to: dd if=/dev/hda ibs=1 count=440 | sha1sum */ |
Kevin O'Connor | 8bd4a08 | 2015-11-19 17:43:27 -0500 | [diff] [blame] | 595 | string = "MBR"; |
Kevin O'Connor | 7ea191b | 2015-11-22 11:15:51 -0500 | [diff] [blame] | 596 | rc = tpm_add_measurement_to_log(4, EV_IPL, |
| 597 | string, strlen(string), |
| 598 | addr, 0x1b8); |
| 599 | if (rc) |
| 600 | return rc; |
| 601 | |
| 602 | /* equivalent to: dd if=/dev/hda ibs=1 count=72 skip=440 | sha1sum */ |
| 603 | string = "MBR PARTITION_TABLE"; |
| 604 | return tpm_add_measurement_to_log(5, EV_IPL_PARTITION_DATA, |
| 605 | string, strlen(string), |
| 606 | addr + 0x1b8, 0x48); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | u32 |
| 610 | tpm_add_cdrom(u32 bootdrv, const u8 *addr, u32 length) |
| 611 | { |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 612 | if (!tpm_is_working()) |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 613 | return TCG_GENERAL_ERROR; |
| 614 | |
Kevin O'Connor | 8bd4a08 | 2015-11-19 17:43:27 -0500 | [diff] [blame] | 615 | u32 rc = tpm_add_action(4, "Booting from CD ROM device"); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 616 | if (rc) |
| 617 | return rc; |
| 618 | |
Kevin O'Connor | 7ea191b | 2015-11-22 11:15:51 -0500 | [diff] [blame] | 619 | /* specs: see section 'El Torito' */ |
| 620 | const char *string = "EL TORITO IPL"; |
| 621 | return tpm_add_measurement_to_log(4, EV_IPL, |
| 622 | string, strlen(string), |
| 623 | addr, length); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | u32 |
| 627 | tpm_add_cdrom_catalog(const u8 *addr, u32 length) |
| 628 | { |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 629 | if (!tpm_is_working()) |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 630 | return TCG_GENERAL_ERROR; |
| 631 | |
Kevin O'Connor | 8bd4a08 | 2015-11-19 17:43:27 -0500 | [diff] [blame] | 632 | u32 rc = tpm_add_action(4, "Booting from CD ROM device"); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 633 | if (rc) |
| 634 | return rc; |
| 635 | |
Kevin O'Connor | 7ea191b | 2015-11-22 11:15:51 -0500 | [diff] [blame] | 636 | /* specs: see section 'El Torito' */ |
| 637 | const char *string = "BOOT CATALOG"; |
| 638 | return tpm_add_measurement_to_log(5, EV_IPL_PARTITION_DATA, |
| 639 | string, strlen(string), |
| 640 | addr, length); |
Stefan Berger | 2aff1c1 | 2015-05-26 15:48:33 -0400 | [diff] [blame] | 641 | } |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 642 | |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 643 | void |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 644 | tpm_s3_resume(void) |
| 645 | { |
| 646 | u32 rc; |
| 647 | u32 returnCode; |
| 648 | |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 649 | if (!tpm_is_working()) |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 650 | return; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 651 | |
| 652 | dprintf(DEBUG_tcg, "TCGBIOS: Resuming with TPM_Startup(ST_STATE)\n"); |
| 653 | |
Stefan Berger | 5aa2a75 | 2015-03-23 14:22:17 -0400 | [diff] [blame] | 654 | rc = build_and_send_cmd(0, TPM_ORD_Startup, |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 655 | Startup_ST_STATE, sizeof(Startup_ST_STATE), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 656 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 657 | |
| 658 | dprintf(DEBUG_tcg, "TCGBIOS: ReturnCode from TPM_Startup = 0x%08x\n", |
| 659 | returnCode); |
| 660 | |
| 661 | if (rc || returnCode) |
| 662 | goto err_exit; |
| 663 | |
Kevin O'Connor | d6aca44 | 2015-06-10 11:00:17 -0400 | [diff] [blame] | 664 | return; |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 665 | |
| 666 | err_exit: |
| 667 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 668 | |
Stefan Berger | 7fce1d9 | 2015-11-12 10:14:45 -0500 | [diff] [blame] | 669 | tpm_set_failure(); |
Stefan Berger | b310dfa | 2015-03-23 14:22:16 -0400 | [diff] [blame] | 670 | } |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 671 | |
| 672 | |
| 673 | /**************************************************************** |
| 674 | * BIOS interface |
| 675 | ****************************************************************/ |
| 676 | |
Kevin O'Connor | 5907613 | 2015-11-28 13:55:09 -0500 | [diff] [blame] | 677 | u8 TPM_interface_shutdown VARLOW; |
| 678 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 679 | static inline void *input_buf32(struct bregs *regs) |
| 680 | { |
| 681 | return MAKE_FLATPTR(regs->es, regs->di); |
| 682 | } |
| 683 | |
| 684 | static inline void *output_buf32(struct bregs *regs) |
| 685 | { |
| 686 | return MAKE_FLATPTR(regs->ds, regs->si); |
| 687 | } |
| 688 | |
| 689 | static u32 |
| 690 | hash_log_extend_event_int(const struct hleei_short *hleei_s, |
| 691 | struct hleeo *hleeo) |
| 692 | { |
| 693 | u32 rc = 0; |
| 694 | struct hleo hleo; |
| 695 | struct hleei_long *hleei_l = (struct hleei_long *)hleei_s; |
| 696 | const void *logdataptr; |
| 697 | u32 logdatalen; |
| 698 | struct pcpes *pcpes; |
| 699 | u32 pcrindex; |
| 700 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 701 | /* short or long version? */ |
| 702 | switch (hleei_s->ipblength) { |
| 703 | case sizeof(struct hleei_short): |
| 704 | /* short */ |
| 705 | logdataptr = hleei_s->logdataptr; |
| 706 | logdatalen = hleei_s->logdatalen; |
| 707 | pcrindex = hleei_s->pcrindex; |
| 708 | break; |
| 709 | |
| 710 | case sizeof(struct hleei_long): |
| 711 | /* long */ |
| 712 | logdataptr = hleei_l->logdataptr; |
| 713 | logdatalen = hleei_l->logdatalen; |
| 714 | pcrindex = hleei_l->pcrindex; |
| 715 | break; |
| 716 | |
| 717 | default: |
| 718 | /* bad input block */ |
| 719 | rc = TCG_INVALID_INPUT_PARA; |
| 720 | goto err_exit; |
| 721 | } |
| 722 | |
| 723 | pcpes = (struct pcpes *)logdataptr; |
| 724 | |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 725 | if (pcpes->pcrindex >= 24 || pcpes->pcrindex != pcrindex |
| 726 | || logdatalen != sizeof(*pcpes) + pcpes->eventdatasize) { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 727 | rc = TCG_INVALID_INPUT_PARA; |
| 728 | goto err_exit; |
| 729 | } |
| 730 | |
Kevin O'Connor | 9224440 | 2015-11-22 16:54:18 -0500 | [diff] [blame] | 731 | tpm_fill_hash(pcpes, hleei_s->hashdataptr, hleei_s->hashdatalen); |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 732 | rc = tpm_log_extend_event(pcpes, pcpes->event); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 733 | if (rc) |
| 734 | goto err_exit; |
| 735 | |
| 736 | hleeo->opblength = sizeof(struct hleeo); |
| 737 | hleeo->reserved = 0; |
| 738 | hleeo->eventnumber = hleo.eventnumber; |
| 739 | |
| 740 | err_exit: |
| 741 | if (rc != 0) { |
| 742 | hleeo->opblength = 4; |
| 743 | hleeo->reserved = 0; |
| 744 | } |
| 745 | |
| 746 | return rc; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | static u32 |
| 750 | pass_through_to_tpm_int(struct pttti *pttti, struct pttto *pttto) |
| 751 | { |
| 752 | u32 rc = 0; |
Kevin O'Connor | 7ba0568 | 2015-11-22 18:21:45 -0500 | [diff] [blame] | 753 | struct tpm_req_header *trh = (void*)pttti->tpmopin; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 754 | |
Kevin O'Connor | 7ba0568 | 2015-11-22 18:21:45 -0500 | [diff] [blame] | 755 | if (pttti->ipblength < sizeof(struct pttti) + sizeof(trh) |
| 756 | || pttti->ipblength != sizeof(struct pttti) + be32_to_cpu(trh->totlen) |
| 757 | || pttti->opblength < sizeof(struct pttto)) { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 758 | rc = TCG_INVALID_INPUT_PARA; |
| 759 | goto err_exit; |
| 760 | } |
| 761 | |
Kevin O'Connor | 7ba0568 | 2015-11-22 18:21:45 -0500 | [diff] [blame] | 762 | u32 resbuflen = pttti->opblength - offsetof(struct pttto, tpmopout); |
Kevin O'Connor | 2df7028 | 2015-11-28 13:43:22 -0500 | [diff] [blame] | 763 | rc = tpmhw_transmit(0, trh, pttto->tpmopout, &resbuflen, |
| 764 | TPM_DURATION_TYPE_LONG /* worst case */); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 765 | if (rc) |
| 766 | goto err_exit; |
| 767 | |
| 768 | pttto->opblength = offsetof(struct pttto, tpmopout) + resbuflen; |
| 769 | pttto->reserved = 0; |
| 770 | |
| 771 | err_exit: |
| 772 | if (rc != 0) { |
| 773 | pttto->opblength = 4; |
| 774 | pttto->reserved = 0; |
| 775 | } |
| 776 | |
| 777 | return rc; |
| 778 | } |
| 779 | |
| 780 | static u32 |
| 781 | shutdown_preboot_interface(void) |
| 782 | { |
Kevin O'Connor | 5907613 | 2015-11-28 13:55:09 -0500 | [diff] [blame] | 783 | TPM_interface_shutdown = 1; |
| 784 | return 0; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | static u32 |
| 788 | hash_log_event_int(const struct hlei *hlei, struct hleo *hleo) |
| 789 | { |
| 790 | u32 rc = 0; |
| 791 | u16 size; |
| 792 | struct pcpes *pcpes; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 793 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 794 | size = hlei->ipblength; |
| 795 | if (size != sizeof(*hlei)) { |
| 796 | rc = TCG_INVALID_INPUT_PARA; |
| 797 | goto err_exit; |
| 798 | } |
| 799 | |
| 800 | pcpes = (struct pcpes *)hlei->logdataptr; |
| 801 | |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 802 | if (pcpes->pcrindex >= 24 || pcpes->pcrindex != hlei->pcrindex |
| 803 | || pcpes->eventtype != hlei->logeventtype |
| 804 | || hlei->logdatalen != sizeof(*pcpes) + pcpes->eventdatasize) { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 805 | rc = TCG_INVALID_INPUT_PARA; |
| 806 | goto err_exit; |
| 807 | } |
| 808 | |
Kevin O'Connor | 9224440 | 2015-11-22 16:54:18 -0500 | [diff] [blame] | 809 | tpm_fill_hash(pcpes, hlei->hashdataptr, hlei->hashdatalen); |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 810 | rc = tpm_log_event(pcpes, pcpes->event); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 811 | if (rc) |
| 812 | goto err_exit; |
| 813 | |
| 814 | /* updating the log was fine */ |
| 815 | hleo->opblength = sizeof(struct hleo); |
| 816 | hleo->reserved = 0; |
Kevin O'Connor | 5afdced | 2015-11-22 16:39:59 -0500 | [diff] [blame] | 817 | hleo->eventnumber = tpm_state.entry_count; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 818 | |
| 819 | err_exit: |
| 820 | if (rc != 0) { |
| 821 | hleo->opblength = 2; |
| 822 | hleo->reserved = 0; |
| 823 | } |
| 824 | |
| 825 | return rc; |
| 826 | } |
| 827 | |
| 828 | static u32 |
| 829 | hash_all_int(const struct hai *hai, u8 *hash) |
| 830 | { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 831 | if (hai->ipblength != sizeof(struct hai) || |
| 832 | hai->hashdataptr == 0 || |
| 833 | hai->hashdatalen == 0 || |
| 834 | hai->algorithmid != TPM_ALG_SHA) |
| 835 | return TCG_INVALID_INPUT_PARA; |
| 836 | |
| 837 | return sha1((const u8 *)hai->hashdataptr, hai->hashdatalen, hash); |
| 838 | } |
| 839 | |
| 840 | static u32 |
| 841 | tss_int(struct ti *ti, struct to *to) |
| 842 | { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 843 | to->opblength = sizeof(struct to); |
| 844 | to->reserved = 0; |
| 845 | |
Kevin O'Connor | 5907613 | 2015-11-28 13:55:09 -0500 | [diff] [blame] | 846 | return TCG_PC_UNSUPPORTED; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static u32 |
| 850 | compact_hash_log_extend_event_int(u8 *buffer, |
| 851 | u32 info, |
| 852 | u32 length, |
| 853 | u32 pcrindex, |
| 854 | u32 *edx_ptr) |
| 855 | { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 856 | struct pcpes pcpes = { |
| 857 | .pcrindex = pcrindex, |
| 858 | .eventtype = EV_COMPACT_HASH, |
| 859 | .eventdatasize = sizeof(info), |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 860 | }; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 861 | |
Kevin O'Connor | 9224440 | 2015-11-22 16:54:18 -0500 | [diff] [blame] | 862 | tpm_fill_hash(&pcpes, buffer, length); |
Kevin O'Connor | 7bf7738 | 2015-11-22 17:28:36 -0500 | [diff] [blame] | 863 | u32 rc = tpm_log_extend_event(&pcpes, &info); |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 864 | if (rc == 0) |
Kevin O'Connor | 5afdced | 2015-11-22 16:39:59 -0500 | [diff] [blame] | 865 | *edx_ptr = tpm_state.entry_count; |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 866 | |
| 867 | return rc; |
| 868 | } |
| 869 | |
| 870 | void VISIBLE32FLAT |
| 871 | tpm_interrupt_handler32(struct bregs *regs) |
| 872 | { |
| 873 | if (!CONFIG_TCGBIOS) |
| 874 | return; |
| 875 | |
| 876 | set_cf(regs, 0); |
| 877 | |
Kevin O'Connor | 5907613 | 2015-11-28 13:55:09 -0500 | [diff] [blame] | 878 | if (TPM_interface_shutdown && regs->al) { |
| 879 | regs->eax = TCG_INTERFACE_SHUTDOWN; |
| 880 | return; |
| 881 | } |
| 882 | |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 883 | switch ((enum irq_ids)regs->al) { |
| 884 | case TCG_StatusCheck: |
Kevin O'Connor | d559a23 | 2015-11-28 08:35:26 -0500 | [diff] [blame] | 885 | if (!tpmhw_is_present()) { |
Kevin O'Connor | f51c50a | 2015-11-22 10:57:52 -0500 | [diff] [blame] | 886 | /* no TPM available */ |
| 887 | regs->eax = TCG_PC_TPM_NOT_PRESENT; |
| 888 | } else { |
| 889 | regs->eax = 0; |
| 890 | regs->ebx = TCG_MAGIC; |
| 891 | regs->ch = TCG_VERSION_MAJOR; |
| 892 | regs->cl = TCG_VERSION_MINOR; |
| 893 | regs->edx = 0x0; |
| 894 | regs->esi = (u32)tpm_state.log_area_start_address; |
| 895 | regs->edi = (u32)tpm_state.log_area_last_entry; |
| 896 | } |
| 897 | break; |
| 898 | |
| 899 | case TCG_HashLogExtendEvent: |
| 900 | regs->eax = |
| 901 | hash_log_extend_event_int( |
| 902 | (struct hleei_short *)input_buf32(regs), |
| 903 | (struct hleeo *)output_buf32(regs)); |
| 904 | break; |
| 905 | |
| 906 | case TCG_PassThroughToTPM: |
| 907 | regs->eax = |
| 908 | pass_through_to_tpm_int((struct pttti *)input_buf32(regs), |
| 909 | (struct pttto *)output_buf32(regs)); |
| 910 | break; |
| 911 | |
| 912 | case TCG_ShutdownPreBootInterface: |
| 913 | regs->eax = shutdown_preboot_interface(); |
| 914 | break; |
| 915 | |
| 916 | case TCG_HashLogEvent: |
| 917 | regs->eax = hash_log_event_int((struct hlei*)input_buf32(regs), |
| 918 | (struct hleo*)output_buf32(regs)); |
| 919 | break; |
| 920 | |
| 921 | case TCG_HashAll: |
| 922 | regs->eax = |
| 923 | hash_all_int((struct hai*)input_buf32(regs), |
| 924 | (u8 *)output_buf32(regs)); |
| 925 | break; |
| 926 | |
| 927 | case TCG_TSS: |
| 928 | regs->eax = tss_int((struct ti*)input_buf32(regs), |
| 929 | (struct to*)output_buf32(regs)); |
| 930 | break; |
| 931 | |
| 932 | case TCG_CompactHashLogExtendEvent: |
| 933 | regs->eax = |
| 934 | compact_hash_log_extend_event_int((u8 *)input_buf32(regs), |
| 935 | regs->esi, |
| 936 | regs->ecx, |
| 937 | regs->edx, |
| 938 | ®s->edx); |
| 939 | break; |
| 940 | |
| 941 | default: |
| 942 | set_cf(regs, 1); |
| 943 | } |
| 944 | |
| 945 | return; |
| 946 | } |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 947 | |
Kevin O'Connor | 26e3617 | 2015-12-29 12:20:23 -0500 | [diff] [blame] | 948 | |
| 949 | /**************************************************************** |
| 950 | * TPM Configuration Menu |
| 951 | ****************************************************************/ |
| 952 | |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 953 | static u32 |
| 954 | read_stclear_flags(char *buf, int buf_len) |
| 955 | { |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 956 | memset(buf, 0, buf_len); |
| 957 | |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 958 | struct tpm_res_getcap_stclear_flags stcf; |
| 959 | int ret = tpm_get_capability(TPM_CAP_FLAG, TPM_CAP_FLAG_VOLATILE |
| 960 | , &stcf.hdr, sizeof(stcf)); |
| 961 | if (ret) |
| 962 | return TCG_TCG_COMMAND_ERROR; |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 963 | |
| 964 | memcpy(buf, &stcf.stclear_flags, buf_len); |
| 965 | |
| 966 | return 0; |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | static u32 |
| 970 | assert_physical_presence(int verbose) |
| 971 | { |
| 972 | u32 rc = 0; |
| 973 | u32 returnCode; |
| 974 | struct tpm_stclear_flags stcf; |
| 975 | |
| 976 | rc = read_stclear_flags((char *)&stcf, sizeof(stcf)); |
| 977 | if (rc) { |
| 978 | dprintf(DEBUG_tcg, |
| 979 | "Error reading STClear flags: 0x%08x\n", rc); |
| 980 | return rc; |
| 981 | } |
| 982 | |
| 983 | if (stcf.flags[STCLEAR_FLAG_IDX_PHYSICAL_PRESENCE]) |
| 984 | /* physical presence already asserted */ |
| 985 | return 0; |
| 986 | |
| 987 | rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence, |
| 988 | PhysicalPresence_CMD_ENABLE, |
| 989 | sizeof(PhysicalPresence_CMD_ENABLE), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 990 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 991 | |
| 992 | dprintf(DEBUG_tcg, |
| 993 | "Return code from TSC_PhysicalPresence(CMD_ENABLE) = 0x%08x\n", |
| 994 | returnCode); |
| 995 | |
| 996 | if (rc || returnCode) { |
| 997 | if (verbose) |
| 998 | printf("Error: Could not enable physical presence.\n\n"); |
| 999 | goto err_exit; |
| 1000 | } |
| 1001 | |
| 1002 | rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence, |
| 1003 | PhysicalPresence_PRESENT, |
| 1004 | sizeof(PhysicalPresence_PRESENT), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 1005 | &returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1006 | |
| 1007 | dprintf(DEBUG_tcg, |
| 1008 | "Return code from TSC_PhysicalPresence(PRESENT) = 0x%08x\n", |
| 1009 | returnCode); |
| 1010 | |
| 1011 | if (rc || returnCode) { |
| 1012 | if (verbose) |
| 1013 | printf("Error: Could not set presence flag.\n\n"); |
| 1014 | goto err_exit; |
| 1015 | } |
| 1016 | |
| 1017 | return 0; |
| 1018 | |
| 1019 | err_exit: |
| 1020 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 1021 | |
| 1022 | tpm_set_failure(); |
| 1023 | if (rc) |
| 1024 | return rc; |
| 1025 | return TCG_TCG_COMMAND_ERROR; |
| 1026 | } |
| 1027 | |
| 1028 | static u32 |
| 1029 | read_permanent_flags(char *buf, int buf_len) |
| 1030 | { |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1031 | memset(buf, 0, buf_len); |
| 1032 | |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 1033 | struct tpm_res_getcap_perm_flags pf; |
| 1034 | int ret = tpm_get_capability(TPM_CAP_FLAG, TPM_CAP_FLAG_PERMANENT |
| 1035 | , &pf.hdr, sizeof(pf)); |
| 1036 | if (ret) |
| 1037 | return TCG_TCG_COMMAND_ERROR; |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1038 | |
| 1039 | memcpy(buf, &pf.perm_flags, buf_len); |
| 1040 | |
| 1041 | return 0; |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | static u32 |
| 1045 | read_has_owner(int *has_owner) |
| 1046 | { |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1047 | struct tpm_res_getcap_ownerauth oauth; |
Kevin O'Connor | ca60636 | 2015-12-29 14:21:29 -0500 | [diff] [blame] | 1048 | int ret = tpm_get_capability(TPM_CAP_PROPERTY, TPM_CAP_PROP_OWNER |
| 1049 | , &oauth.hdr, sizeof(oauth)); |
| 1050 | if (ret) |
| 1051 | return TCG_TCG_COMMAND_ERROR; |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1052 | |
| 1053 | *has_owner = oauth.flag; |
| 1054 | |
| 1055 | return 0; |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static u32 |
| 1059 | enable_tpm(int enable, u32 *returnCode, int verbose) |
| 1060 | { |
| 1061 | u32 rc; |
| 1062 | struct tpm_permanent_flags pf; |
| 1063 | |
| 1064 | rc = read_permanent_flags((char *)&pf, sizeof(pf)); |
| 1065 | if (rc) |
| 1066 | return rc; |
| 1067 | |
| 1068 | if (pf.flags[PERM_FLAG_IDX_DISABLE] && !enable) |
| 1069 | return 0; |
| 1070 | |
| 1071 | rc = assert_physical_presence(verbose); |
| 1072 | if (rc) { |
| 1073 | dprintf(DEBUG_tcg, "TCGBIOS: Asserting physical presence failed.\n"); |
| 1074 | return rc; |
| 1075 | } |
| 1076 | |
| 1077 | rc = build_and_send_cmd(0, enable ? TPM_ORD_PhysicalEnable |
| 1078 | : TPM_ORD_PhysicalDisable, |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 1079 | NULL, 0, returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1080 | if (enable) |
| 1081 | dprintf(DEBUG_tcg, "Return code from TPM_PhysicalEnable = 0x%08x\n", |
| 1082 | *returnCode); |
| 1083 | else |
| 1084 | dprintf(DEBUG_tcg, "Return code from TPM_PhysicalDisable = 0x%08x\n", |
| 1085 | *returnCode); |
| 1086 | |
| 1087 | if (rc || *returnCode) |
| 1088 | goto err_exit; |
| 1089 | |
| 1090 | return 0; |
| 1091 | |
| 1092 | err_exit: |
| 1093 | if (enable) |
| 1094 | dprintf(DEBUG_tcg, "TCGBIOS: Enabling the TPM failed.\n"); |
| 1095 | else |
| 1096 | dprintf(DEBUG_tcg, "TCGBIOS: Disabling the TPM failed.\n"); |
| 1097 | |
| 1098 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 1099 | |
| 1100 | tpm_set_failure(); |
| 1101 | if (rc) |
| 1102 | return rc; |
| 1103 | return TCG_TCG_COMMAND_ERROR; |
| 1104 | } |
| 1105 | |
| 1106 | static u32 |
| 1107 | activate_tpm(int activate, int allow_reset, u32 *returnCode, int verbose) |
| 1108 | { |
| 1109 | u32 rc; |
| 1110 | struct tpm_permanent_flags pf; |
| 1111 | |
| 1112 | rc = read_permanent_flags((char *)&pf, sizeof(pf)); |
| 1113 | if (rc) |
| 1114 | return rc; |
| 1115 | |
| 1116 | if (pf.flags[PERM_FLAG_IDX_DEACTIVATED] && !activate) |
| 1117 | return 0; |
| 1118 | |
| 1119 | if (pf.flags[PERM_FLAG_IDX_DISABLE]) |
| 1120 | return 0; |
| 1121 | |
| 1122 | rc = assert_physical_presence(verbose); |
| 1123 | if (rc) { |
| 1124 | dprintf(DEBUG_tcg, "TCGBIOS: Asserting physical presence failed.\n"); |
| 1125 | return rc; |
| 1126 | } |
| 1127 | |
| 1128 | rc = build_and_send_cmd(0, TPM_ORD_PhysicalSetDeactivated, |
| 1129 | activate ? CommandFlag_FALSE |
| 1130 | : CommandFlag_TRUE, |
| 1131 | activate ? sizeof(CommandFlag_FALSE) |
| 1132 | : sizeof(CommandFlag_TRUE), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 1133 | returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1134 | |
| 1135 | dprintf(DEBUG_tcg, |
| 1136 | "Return code from PhysicalSetDeactivated(%d) = 0x%08x\n", |
| 1137 | activate ? 0 : 1, *returnCode); |
| 1138 | |
| 1139 | if (rc || *returnCode) |
| 1140 | goto err_exit; |
| 1141 | |
| 1142 | if (activate && allow_reset) { |
| 1143 | if (verbose) { |
| 1144 | printf("Requiring a reboot to activate the TPM.\n"); |
| 1145 | |
| 1146 | msleep(2000); |
| 1147 | } |
| 1148 | reset(); |
| 1149 | } |
| 1150 | |
| 1151 | return 0; |
| 1152 | |
| 1153 | err_exit: |
| 1154 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 1155 | |
| 1156 | tpm_set_failure(); |
| 1157 | if (rc) |
| 1158 | return rc; |
| 1159 | return TCG_TCG_COMMAND_ERROR; |
| 1160 | } |
| 1161 | |
| 1162 | static u32 |
| 1163 | enable_activate(int allow_reset, u32 *returnCode, int verbose) |
| 1164 | { |
| 1165 | u32 rc; |
| 1166 | |
| 1167 | rc = enable_tpm(1, returnCode, verbose); |
| 1168 | if (rc) |
| 1169 | return rc; |
| 1170 | |
| 1171 | rc = activate_tpm(1, allow_reset, returnCode, verbose); |
| 1172 | |
| 1173 | return rc; |
| 1174 | } |
| 1175 | |
| 1176 | static u32 |
| 1177 | force_clear(int enable_activate_before, int enable_activate_after, |
| 1178 | u32 *returnCode, int verbose) |
| 1179 | { |
| 1180 | u32 rc; |
| 1181 | int has_owner; |
| 1182 | |
| 1183 | rc = read_has_owner(&has_owner); |
| 1184 | if (rc) |
| 1185 | return rc; |
| 1186 | if (!has_owner) { |
| 1187 | if (verbose) |
| 1188 | printf("TPM does not have an owner.\n"); |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | if (enable_activate_before) { |
| 1193 | rc = enable_activate(0, returnCode, verbose); |
| 1194 | if (rc) { |
| 1195 | dprintf(DEBUG_tcg, |
| 1196 | "TCGBIOS: Enabling/activating the TPM failed.\n"); |
| 1197 | return rc; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | rc = assert_physical_presence(verbose); |
| 1202 | if (rc) { |
| 1203 | dprintf(DEBUG_tcg, "TCGBIOS: Asserting physical presence failed.\n"); |
| 1204 | return rc; |
| 1205 | } |
| 1206 | |
| 1207 | rc = build_and_send_cmd(0, TPM_ORD_ForceClear, |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 1208 | NULL, 0, returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1209 | |
| 1210 | dprintf(DEBUG_tcg, "Return code from TPM_ForceClear() = 0x%08x\n", |
| 1211 | *returnCode); |
| 1212 | |
| 1213 | if (rc || *returnCode) |
| 1214 | goto err_exit; |
| 1215 | |
| 1216 | if (!enable_activate_after) { |
| 1217 | if (verbose) |
| 1218 | printf("Owner successfully cleared.\n" |
| 1219 | "You will need to enable/activate the TPM again.\n\n"); |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | enable_activate(1, returnCode, verbose); |
| 1224 | |
| 1225 | return 0; |
| 1226 | |
| 1227 | err_exit: |
| 1228 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 1229 | |
| 1230 | tpm_set_failure(); |
| 1231 | if (rc) |
| 1232 | return rc; |
| 1233 | return TCG_TCG_COMMAND_ERROR; |
| 1234 | } |
| 1235 | |
| 1236 | static u32 |
| 1237 | set_owner_install(int allow, u32 *returnCode, int verbose) |
| 1238 | { |
| 1239 | u32 rc; |
| 1240 | int has_owner; |
| 1241 | struct tpm_permanent_flags pf; |
| 1242 | |
| 1243 | rc = read_has_owner(&has_owner); |
| 1244 | if (rc) |
| 1245 | return rc; |
| 1246 | if (has_owner) { |
| 1247 | if (verbose) |
| 1248 | printf("Must first remove owner.\n"); |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
| 1252 | rc = read_permanent_flags((char *)&pf, sizeof(pf)); |
| 1253 | if (rc) |
| 1254 | return rc; |
| 1255 | |
| 1256 | if (pf.flags[PERM_FLAG_IDX_DISABLE]) { |
| 1257 | if (verbose) |
| 1258 | printf("TPM must first be enable.\n"); |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | rc = assert_physical_presence(verbose); |
| 1263 | if (rc) { |
| 1264 | dprintf(DEBUG_tcg, "TCGBIOS: Asserting physical presence failed.\n"); |
| 1265 | return rc; |
| 1266 | } |
| 1267 | |
| 1268 | rc = build_and_send_cmd(0, TPM_ORD_SetOwnerInstall, |
| 1269 | (allow) ? CommandFlag_TRUE : |
| 1270 | CommandFlag_FALSE, |
| 1271 | sizeof(CommandFlag_TRUE), |
Kevin O'Connor | 7147961 | 2015-12-29 14:32:19 -0500 | [diff] [blame^] | 1272 | returnCode, TPM_DURATION_TYPE_SHORT); |
Stefan Berger | 320df85 | 2015-11-30 11:14:19 -0500 | [diff] [blame] | 1273 | |
| 1274 | dprintf(DEBUG_tcg, "Return code from TPM_SetOwnerInstall() = 0x%08x\n", |
| 1275 | *returnCode); |
| 1276 | |
| 1277 | if (rc || *returnCode) |
| 1278 | goto err_exit; |
| 1279 | |
| 1280 | if (verbose) |
| 1281 | printf("Installation of owner %s.\n", allow ? "enabled" : "disabled"); |
| 1282 | |
| 1283 | return 0; |
| 1284 | |
| 1285 | err_exit: |
| 1286 | dprintf(DEBUG_tcg, "TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__); |
| 1287 | tpm_set_failure(); |
| 1288 | if (rc) |
| 1289 | return rc; |
| 1290 | return TCG_TCG_COMMAND_ERROR; |
| 1291 | } |
| 1292 | |
| 1293 | static u32 |
| 1294 | tpm_process_cfg(tpm_ppi_code msgCode, int verbose, u32 *returnCode) |
| 1295 | { |
| 1296 | u32 rc = 0; |
| 1297 | |
| 1298 | switch (msgCode) { |
| 1299 | case TPM_PPI_OP_NOOP: /* no-op */ |
| 1300 | break; |
| 1301 | |
| 1302 | case TPM_PPI_OP_ENABLE: |
| 1303 | rc = enable_tpm(1, returnCode, verbose); |
| 1304 | break; |
| 1305 | |
| 1306 | case TPM_PPI_OP_DISABLE: |
| 1307 | rc = enable_tpm(0, returnCode, verbose); |
| 1308 | break; |
| 1309 | |
| 1310 | case TPM_PPI_OP_ACTIVATE: |
| 1311 | rc = activate_tpm(1, 1, returnCode, verbose); |
| 1312 | break; |
| 1313 | |
| 1314 | case TPM_PPI_OP_DEACTIVATE: |
| 1315 | rc = activate_tpm(0, 1, returnCode, verbose); |
| 1316 | break; |
| 1317 | |
| 1318 | case TPM_PPI_OP_CLEAR: |
| 1319 | rc = force_clear(1, 0, returnCode, verbose); |
| 1320 | break; |
| 1321 | |
| 1322 | case TPM_PPI_OP_SET_OWNERINSTALL_TRUE: |
| 1323 | rc = set_owner_install(1, returnCode, verbose); |
| 1324 | break; |
| 1325 | |
| 1326 | case TPM_PPI_OP_SET_OWNERINSTALL_FALSE: |
| 1327 | rc = set_owner_install(0, returnCode, verbose); |
| 1328 | break; |
| 1329 | |
| 1330 | default: |
| 1331 | break; |
| 1332 | } |
| 1333 | |
| 1334 | if (rc) |
| 1335 | printf("Op %d: An error occurred: 0x%x TPM return code: 0x%x\n", |
| 1336 | msgCode, rc, *returnCode); |
| 1337 | |
| 1338 | return rc; |
| 1339 | } |
| 1340 | |
| 1341 | static int |
| 1342 | get_tpm_state(void) |
| 1343 | { |
| 1344 | int state = 0; |
| 1345 | struct tpm_permanent_flags pf; |
| 1346 | int has_owner; |
| 1347 | |
| 1348 | if (read_permanent_flags((char *)&pf, sizeof(pf)) || |
| 1349 | read_has_owner(&has_owner)) |
| 1350 | return ~0; |
| 1351 | |
| 1352 | if (!pf.flags[PERM_FLAG_IDX_DISABLE]) |
| 1353 | state |= TPM_STATE_ENABLED; |
| 1354 | |
| 1355 | if (!pf.flags[PERM_FLAG_IDX_DEACTIVATED]) |
| 1356 | state |= TPM_STATE_ACTIVE; |
| 1357 | |
| 1358 | if (has_owner) { |
| 1359 | state |= TPM_STATE_OWNED; |
| 1360 | } else { |
| 1361 | if (pf.flags[PERM_FLAG_IDX_OWNERSHIP]) |
| 1362 | state |= TPM_STATE_OWNERINSTALL; |
| 1363 | } |
| 1364 | |
| 1365 | return state; |
| 1366 | } |
| 1367 | |
| 1368 | static void |
| 1369 | show_tpm_menu(int state, int next_scancodes[7]) |
| 1370 | { |
| 1371 | int i = 0; |
| 1372 | |
| 1373 | printf("\nThe current state of the TPM is:\n"); |
| 1374 | |
| 1375 | if (state & TPM_STATE_ENABLED) |
| 1376 | printf(" Enabled"); |
| 1377 | else |
| 1378 | printf(" Disabled"); |
| 1379 | |
| 1380 | if (state & TPM_STATE_ACTIVE) |
| 1381 | printf(" and active\n"); |
| 1382 | else |
| 1383 | printf(" and deactivated\n"); |
| 1384 | |
| 1385 | if (state & TPM_STATE_OWNED) |
| 1386 | printf(" Ownership has been taken\n"); |
| 1387 | else { |
| 1388 | printf(" Ownership has not been taken\n"); |
| 1389 | if (state & TPM_STATE_OWNERINSTALL) |
| 1390 | printf(" A user can take ownership of the TPM\n"); |
| 1391 | else |
| 1392 | printf(" Taking ownership of the TPM has been disabled\n"); |
| 1393 | } |
| 1394 | |
| 1395 | if ((state & (TPM_STATE_ENABLED | TPM_STATE_ACTIVE)) != |
| 1396 | (TPM_STATE_ENABLED | TPM_STATE_ACTIVE)) { |
| 1397 | printf("\nNote: To make use of all functionality, the TPM must be " |
| 1398 | "enabled and active.\n"); |
| 1399 | } |
| 1400 | |
| 1401 | printf("\nAvailable options are:\n"); |
| 1402 | if (state & TPM_STATE_ENABLED) { |
| 1403 | printf(" d. Disable the TPM\n"); |
| 1404 | next_scancodes[i++] = 32; |
| 1405 | |
| 1406 | if (state & TPM_STATE_ACTIVE) { |
| 1407 | printf(" v. Deactivate the TPM\n"); |
| 1408 | next_scancodes[i++] = 47; |
| 1409 | |
| 1410 | if (state & TPM_STATE_OWNERINSTALL) { |
| 1411 | printf(" p. Prevent installation of an owner\n"); |
| 1412 | next_scancodes[i++] = 25; |
| 1413 | } else { |
| 1414 | printf(" s. Allow installation of an owner\n"); |
| 1415 | next_scancodes[i++] = 31; |
| 1416 | } |
| 1417 | } else { |
| 1418 | printf(" a. Activate the TPM\n"); |
| 1419 | next_scancodes[i++] = 30; |
| 1420 | } |
| 1421 | |
| 1422 | } else { |
| 1423 | printf(" e. Enable the TPM\n"); |
| 1424 | next_scancodes[i++] = 18; |
| 1425 | } |
| 1426 | |
| 1427 | if (state & TPM_STATE_OWNED) { |
| 1428 | printf(" c. Clear ownership\n"); |
| 1429 | next_scancodes[i++] = 46; |
| 1430 | } |
| 1431 | |
| 1432 | next_scancodes[i++] = 0; |
| 1433 | } |
| 1434 | |
| 1435 | void |
| 1436 | tpm_menu(void) |
| 1437 | { |
| 1438 | if (!CONFIG_TCGBIOS) |
| 1439 | return; |
| 1440 | |
| 1441 | int scancode, next_scancodes[7]; |
| 1442 | u32 rc, returnCode; |
| 1443 | tpm_ppi_code msgCode; |
| 1444 | int state = 0, i; |
| 1445 | int waitkey; |
| 1446 | |
| 1447 | while (get_keystroke(0) >= 0) |
| 1448 | ; |
| 1449 | wait_threads(); |
| 1450 | |
| 1451 | printf("The Trusted Platform Module (TPM) is a hardware device in " |
| 1452 | "this machine.\n" |
| 1453 | "It can help verify the integrity of system software.\n\n"); |
| 1454 | |
| 1455 | for (;;) { |
| 1456 | if ((state = get_tpm_state()) != ~0) { |
| 1457 | show_tpm_menu(state, next_scancodes); |
| 1458 | } else { |
| 1459 | printf("TPM is not working correctly.\n"); |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | printf("\nIf no change is desired or if this menu was reached by " |
| 1464 | "mistake, press ESC to\n" |
| 1465 | "reboot the machine.\n"); |
| 1466 | |
| 1467 | msgCode = TPM_PPI_OP_NOOP; |
| 1468 | |
| 1469 | waitkey = 1; |
| 1470 | |
| 1471 | while (waitkey) { |
| 1472 | while ((scancode = get_keystroke(1000)) == ~0) |
| 1473 | ; |
| 1474 | |
| 1475 | switch (scancode) { |
| 1476 | case 1: |
| 1477 | // ESC |
| 1478 | reset(); |
| 1479 | break; |
| 1480 | case 18: /* e. enable */ |
| 1481 | msgCode = TPM_PPI_OP_ENABLE; |
| 1482 | break; |
| 1483 | case 32: /* d. disable */ |
| 1484 | msgCode = TPM_PPI_OP_DISABLE; |
| 1485 | break; |
| 1486 | case 30: /* a. activate */ |
| 1487 | msgCode = TPM_PPI_OP_ACTIVATE; |
| 1488 | break; |
| 1489 | case 47: /* v. deactivate */ |
| 1490 | msgCode = TPM_PPI_OP_DEACTIVATE; |
| 1491 | break; |
| 1492 | case 46: /* c. clear owner */ |
| 1493 | msgCode = TPM_PPI_OP_CLEAR; |
| 1494 | break; |
| 1495 | case 25: /* p. prevent ownerinstall */ |
| 1496 | msgCode = TPM_PPI_OP_SET_OWNERINSTALL_FALSE; |
| 1497 | break; |
| 1498 | case 31: /* s. allow ownerinstall */ |
| 1499 | msgCode = TPM_PPI_OP_SET_OWNERINSTALL_TRUE; |
| 1500 | break; |
| 1501 | default: |
| 1502 | continue; |
| 1503 | } |
| 1504 | |
| 1505 | /* |
| 1506 | * Using the next_scancodes array, check whether the |
| 1507 | * pressed key is currently a valid option. |
| 1508 | */ |
| 1509 | for (i = 0; i < sizeof(next_scancodes); i++) { |
| 1510 | if (next_scancodes[i] == 0) |
| 1511 | break; |
| 1512 | |
| 1513 | if (next_scancodes[i] == scancode) { |
| 1514 | rc = tpm_process_cfg(msgCode, 1, &returnCode); |
| 1515 | |
| 1516 | if (rc) |
| 1517 | printf("An error occurred: 0x%x\n", rc); |
| 1518 | waitkey = 0; |
| 1519 | break; |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | } |