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