]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm12CommandLib/Tpm12GetCapability.c
SecurityPkg: Fix bug in TPM 1.2 SelfTest
[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
4Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>\r
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
82 ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));\r
83 CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), Response.ResponseSize));\r
84\r
85 return Status;\r
86}\r
87\r
88/**\r
89Get TPM capability volatile flags.\r
90\r
91@param[out] VolatileFlags Pointer to the buffer for returned flag structure.\r
92\r
93@retval EFI_SUCCESS Operation completed successfully.\r
94@retval EFI_DEVICE_ERROR The command was unsuccessful.\r
95\r
96**/\r
97EFI_STATUS\r
98EFIAPI\r
99Tpm12GetCapabilityFlagVolatile (\r
100 OUT TPM_STCLEAR_FLAGS *VolatileFlags\r
101 )\r
102{\r
103 EFI_STATUS Status;\r
104 TPM_CMD_GET_CAPABILITY Command;\r
105 TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS Response;\r
106 UINT32 Length;\r
107\r
108 //\r
109 // send Tpm command TPM_ORD_GetCapability\r
110 //\r
111 Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
112 Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));\r
113 Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_GetCapability);\r
114 Command.Capability = SwapBytes32 (TPM_CAP_FLAG);\r
115 Command.CapabilityFlagSize = SwapBytes32 (sizeof (TPM_CAP_FLAG_VOLATILE));\r
116 Command.CapabilityFlag = SwapBytes32 (TPM_CAP_FLAG_VOLATILE);\r
117 Length = sizeof (Response);\r
118 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
119 if (EFI_ERROR (Status)) {\r
120 return Status;\r
121 }\r
122\r
123 ZeroMem (VolatileFlags, sizeof (*VolatileFlags));\r
124 CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), Response.ResponseSize));\r
125\r
126 return Status;\r
127}\r