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