]>
Commit | Line | Data |
---|---|---|
fc72a6ce LE |
1 | /** @file\r |
2 | Implement the InternalTpm12Detect() function on top of the Tpm12DeviceLib\r | |
3 | class.\r | |
4 | \r | |
5 | Copyright (C) 2020, Red Hat, Inc.\r | |
6 | \r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
8 | **/\r | |
9 | \r | |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/Tpm12DeviceLib.h>\r | |
12 | \r | |
13 | #include "Tpm12Support.h"\r | |
14 | \r | |
15 | #pragma pack (1)\r | |
16 | typedef struct {\r | |
17 | TPM_RSP_COMMAND_HDR Hdr;\r | |
18 | TPM_CURRENT_TICKS CurrentTicks;\r | |
19 | } TPM_RSP_GET_TICKS;\r | |
20 | #pragma pack ()\r | |
21 | \r | |
22 | /**\r | |
23 | Probe for the TPM for 1.2 version, by sending TPM1.2 GetTicks\r | |
24 | \r | |
25 | Sending a TPM1.2 command to a TPM2 should return a TPM1.2\r | |
26 | header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)\r | |
27 | \r | |
28 | @retval EFI_SUCCESS TPM version 1.2 probing successful.\r | |
29 | \r | |
30 | @return Error codes propagated from Tpm12SubmitCommand().\r | |
31 | **/\r | |
32 | STATIC\r | |
33 | EFI_STATUS\r | |
34 | TestTpm12 (\r | |
35 | )\r | |
36 | {\r | |
37 | EFI_STATUS Status;\r | |
38 | TPM_RQU_COMMAND_HDR Command;\r | |
39 | TPM_RSP_GET_TICKS Response;\r | |
40 | UINT32 Length;\r | |
41 | \r | |
42 | Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r | |
43 | Command.paramSize = SwapBytes32 (sizeof (Command));\r | |
44 | Command.ordinal = SwapBytes32 (TPM_ORD_GetTicks);\r | |
45 | \r | |
46 | Length = sizeof (Response);\r | |
47 | Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length,\r | |
48 | (UINT8 *)&Response);\r | |
49 | if (EFI_ERROR (Status)) {\r | |
50 | return Status;\r | |
51 | }\r | |
52 | \r | |
53 | return EFI_SUCCESS;\r | |
54 | }\r | |
55 | \r | |
56 | /**\r | |
57 | Detect the presence of a TPM with interface version 1.2.\r | |
58 | \r | |
59 | @retval EFI_SUCCESS TPM-1.2 available. The Tpm12RequestUseTpm() and\r | |
60 | Tpm12SubmitCommand(TPM_ORD_GetTicks) operations\r | |
61 | (from the Tpm12DeviceLib class) have succeeded.\r | |
62 | \r | |
63 | @return Error codes propagated from Tpm12RequestUseTpm() and\r | |
64 | Tpm12SubmitCommand().\r | |
65 | **/\r | |
66 | EFI_STATUS\r | |
67 | InternalTpm12Detect (\r | |
68 | VOID\r | |
69 | )\r | |
70 | {\r | |
71 | EFI_STATUS Status;\r | |
72 | \r | |
73 | Status = Tpm12RequestUseTpm ();\r | |
74 | if (EFI_ERROR (Status)) {\r | |
75 | return Status;\r | |
76 | }\r | |
77 | \r | |
78 | return TestTpm12 ();\r | |
79 | }\r |