]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
SecurityPkg Tpm12CommandLib: Fix TPM12 GetCapability response error
[mirror_edk2.git] / SecurityPkg / Library / Tpm12CommandLib / Tpm12GetCapability.c
CommitLineData
83b9662f
MK
1/** @file\r
2 Implement TPM1.2 Get Capabilities related commands.\r
3\r
28892d76 4Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. <BR>\r
83b9662f
MK
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include <Library/Tpm12CommandLib.h>\r
17#include <Library/BaseLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/Tpm12DeviceLib.h>\r
21\r
22#pragma pack(1)\r
23\r
24typedef struct {\r
25 TPM_RQU_COMMAND_HDR Hdr;\r
26 UINT32 Capability;\r
27 UINT32 CapabilityFlagSize;\r
28 UINT32 CapabilityFlag;\r
29} TPM_CMD_GET_CAPABILITY;\r
30\r
31typedef struct {\r
32 TPM_RSP_COMMAND_HDR Hdr;\r
33 UINT32 ResponseSize;\r
34 TPM_PERMANENT_FLAGS Flags;\r
35} TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS;\r
36\r
37typedef struct {\r
38 TPM_RSP_COMMAND_HDR Hdr;\r
39 UINT32 ResponseSize;\r
40 TPM_STCLEAR_FLAGS Flags;\r
41} TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS;\r
42\r
43#pragma pack()\r
44\r
45/**\r
46Get TPM capability permanent flags.\r
47\r
48@param[out] TpmPermanentFlags Pointer to the buffer for returned flag structure.\r
49\r
50@retval EFI_SUCCESS Operation completed successfully.\r
51@retval EFI_TIMEOUT The register can't run into the expected status in time.\r
52@retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.\r
53@retval EFI_DEVICE_ERROR Unexpected device behavior.\r
54\r
55**/\r
56EFI_STATUS\r
57EFIAPI\r
58Tpm12GetCapabilityFlagPermanent (\r
59 OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags\r
60 )\r
61{\r
62 EFI_STATUS Status;\r
63 TPM_CMD_GET_CAPABILITY Command;\r
64 TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS Response;\r
65 UINT32 Length;\r
66\r
67 //\r
68 // send Tpm command TPM_ORD_GetCapability\r
69 //\r
70 Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
71 Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));\r
72 Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);\r
73 Command.Capability = SwapBytes32 (TPM_CAP_FLAG);\r
74 Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT));\r
75 Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_PERMANENT);\r
76 Length = sizeof (Response);\r
77 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
78 if (EFI_ERROR (Status)) {\r
79 return Status;\r
80 }\r
81\r
8b17ad86
MK
82 if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {\r
83 DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagPermanent: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));\r
84 return EFI_DEVICE_ERROR;\r
85 }\r
86\r
83b9662f 87 ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));\r
28892d76 88 CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), SwapBytes32(Response.ResponseSize)));\r
83b9662f
MK
89\r
90 return Status;\r
91}\r
92\r
93/**\r
94Get TPM capability volatile flags.\r
95\r
96@param[out] VolatileFlags Pointer to the buffer for returned flag structure.\r
97\r
98@retval EFI_SUCCESS Operation completed successfully.\r
99@retval EFI_DEVICE_ERROR The command was unsuccessful.\r
100\r
101**/\r
102EFI_STATUS\r
103EFIAPI\r
104Tpm12GetCapabilityFlagVolatile (\r
105 OUT TPM_STCLEAR_FLAGS *VolatileFlags\r
106 )\r
107{\r
108 EFI_STATUS Status;\r
109 TPM_CMD_GET_CAPABILITY Command;\r
110 TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS Response;\r
111 UINT32 Length;\r
112\r
113 //\r
114 // send Tpm command TPM_ORD_GetCapability\r
115 //\r
116 Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
117 Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));\r
118 Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);\r
119 Command.Capability = SwapBytes32 (TPM_CAP_FLAG);\r
120 Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_VOLATILE));\r
121 Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_VOLATILE);\r
122 Length = sizeof (Response);\r
123 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
124 if (EFI_ERROR (Status)) {\r
125 return Status;\r
126 }\r
127\r
8b17ad86
MK
128 if (SwapBytes32 (Response.Hdr.returnCode) != TPM_SUCCESS) {\r
129 DEBUG ((DEBUG_ERROR, "Tpm12GetCapabilityFlagVolatile: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.Hdr.returnCode)));\r
130 return EFI_DEVICE_ERROR;\r
131 }\r
132\r
83b9662f 133 ZeroMem (VolatileFlags, sizeof (*VolatileFlags));\r
28892d76 134 CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), SwapBytes32(Response.ResponseSize)));\r
83b9662f
MK
135\r
136 return Status;\r
137}\r