]>
Commit | Line | Data |
---|---|---|
83b9662f MK |
1 | /** @file\r |
2 | Implement TPM1.2 Get Capabilities related commands.\r | |
3 | \r | |
28892d76 | 4 | Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. <BR>\r |
289b714b | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
83b9662f MK |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
10 | #include <Library/Tpm12CommandLib.h>\r | |
11 | #include <Library/BaseLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
13 | #include <Library/BaseMemoryLib.h>\r | |
14 | #include <Library/Tpm12DeviceLib.h>\r | |
15 | \r | |
16 | #pragma pack(1)\r | |
17 | \r | |
18 | typedef struct {\r | |
c411b485 MK |
19 | TPM_RQU_COMMAND_HDR Hdr;\r |
20 | UINT32 Capability;\r | |
21 | UINT32 CapabilityFlagSize;\r | |
22 | UINT32 CapabilityFlag;\r | |
83b9662f MK |
23 | } TPM_CMD_GET_CAPABILITY;\r |
24 | \r | |
25 | typedef struct {\r | |
c411b485 MK |
26 | TPM_RSP_COMMAND_HDR Hdr;\r |
27 | UINT32 ResponseSize;\r | |
28 | TPM_PERMANENT_FLAGS Flags;\r | |
83b9662f MK |
29 | } TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS;\r |
30 | \r | |
31 | typedef struct {\r | |
c411b485 MK |
32 | TPM_RSP_COMMAND_HDR Hdr;\r |
33 | UINT32 ResponseSize;\r | |
34 | TPM_STCLEAR_FLAGS Flags;\r | |
83b9662f MK |
35 | } TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS;\r |
36 | \r | |
37 | #pragma pack()\r | |
38 | \r | |
39 | /**\r | |
40 | Get TPM capability permanent flags.\r | |
41 | \r | |
42 | @param[out] TpmPermanentFlags Pointer to the buffer for returned flag structure.\r | |
43 | \r | |
44 | @retval EFI_SUCCESS Operation completed successfully.\r | |
45 | @retval EFI_TIMEOUT The register can't run into the expected status in time.\r | |
46 | @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.\r | |
47 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
48 | \r | |
49 | **/\r | |
50 | EFI_STATUS\r | |
51 | EFIAPI\r | |
52 | Tpm12GetCapabilityFlagPermanent (\r | |
53 | OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags\r | |
54 | )\r | |
55 | {\r | |
56 | EFI_STATUS Status;\r | |
57 | TPM_CMD_GET_CAPABILITY Command;\r | |
58 | TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS Response;\r | |
59 | UINT32 Length;\r | |
60 | \r | |
61 | //\r | |
62 | // send Tpm command TPM_ORD_GetCapability\r | |
63 | //\r | |
64 | Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r | |
65 | Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));\r | |
66 | Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);\r | |
67 | Command.Capability = SwapBytes32 (TPM_CAP_FLAG);\r | |
68 | Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT));\r | |
69 | Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_PERMANENT);\r | |
c411b485 MK |
70 | Length = sizeof (Response);\r |
71 | Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r | |
83b9662f MK |
72 | if (EFI_ERROR (Status)) {\r |
73 | return Status;\r | |
74 | }\r | |
75 | \r | |
8b17ad86 MK |
76 | if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {\r |
77 | DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagPermanent: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));\r | |
78 | return EFI_DEVICE_ERROR;\r | |
79 | }\r | |
80 | \r | |
83b9662f | 81 | ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));\r |
c411b485 | 82 | CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), SwapBytes32 (Response.ResponseSize)));\r |
83b9662f MK |
83 | \r |
84 | return Status;\r | |
85 | }\r | |
86 | \r | |
87 | /**\r | |
88 | Get TPM capability volatile flags.\r | |
89 | \r | |
90 | @param[out] VolatileFlags Pointer to the buffer for returned flag structure.\r | |
91 | \r | |
92 | @retval EFI_SUCCESS Operation completed successfully.\r | |
93 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
94 | \r | |
95 | **/\r | |
96 | EFI_STATUS\r | |
97 | EFIAPI\r | |
98 | Tpm12GetCapabilityFlagVolatile (\r | |
99 | OUT TPM_STCLEAR_FLAGS *VolatileFlags\r | |
100 | )\r | |
101 | {\r | |
102 | EFI_STATUS Status;\r | |
103 | TPM_CMD_GET_CAPABILITY Command;\r | |
104 | TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS Response;\r | |
105 | UINT32 Length;\r | |
106 | \r | |
107 | //\r | |
108 | // send Tpm command TPM_ORD_GetCapability\r | |
109 | //\r | |
110 | Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r | |
111 | Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));\r | |
112 | Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);\r | |
113 | Command.Capability = SwapBytes32 (TPM_CAP_FLAG);\r | |
114 | Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_VOLATILE));\r | |
115 | Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_VOLATILE);\r | |
c411b485 MK |
116 | Length = sizeof (Response);\r |
117 | Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r | |
83b9662f MK |
118 | if (EFI_ERROR (Status)) {\r |
119 | return Status;\r | |
120 | }\r | |
121 | \r | |
8b17ad86 MK |
122 | if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {\r |
123 | DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagVolatile: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));\r | |
124 | return EFI_DEVICE_ERROR;\r | |
125 | }\r | |
126 | \r | |
83b9662f | 127 | ZeroMem (VolatileFlags, sizeof (*VolatileFlags));\r |
c411b485 | 128 | CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), SwapBytes32 (Response.ResponseSize)));\r |
83b9662f MK |
129 | \r |
130 | return Status;\r | |
131 | }\r |