2 Implement TPM1.2 Get Capabilities related commands.
4 Copyright (c) 2016 - 2018, 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
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.
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>
25 TPM_RQU_COMMAND_HDR Hdr
;
27 UINT32 CapabilityFlagSize
;
28 UINT32 CapabilityFlag
;
29 } TPM_CMD_GET_CAPABILITY
;
32 TPM_RSP_COMMAND_HDR Hdr
;
34 TPM_PERMANENT_FLAGS Flags
;
35 } TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS
;
38 TPM_RSP_COMMAND_HDR Hdr
;
40 TPM_STCLEAR_FLAGS Flags
;
41 } TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS
;
46 Get TPM capability permanent flags.
48 @param[out] TpmPermanentFlags Pointer to the buffer for returned flag structure.
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.
58 Tpm12GetCapabilityFlagPermanent (
59 OUT TPM_PERMANENT_FLAGS
*TpmPermanentFlags
63 TPM_CMD_GET_CAPABILITY Command
;
64 TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS Response
;
68 // send Tpm command TPM_ORD_GetCapability
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
)) {
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
;
87 ZeroMem (TpmPermanentFlags
, sizeof (*TpmPermanentFlags
));
88 CopyMem (TpmPermanentFlags
, &Response
.Flags
, MIN (sizeof (*TpmPermanentFlags
), SwapBytes32(Response
.ResponseSize
)));
94 Get TPM capability volatile flags.
96 @param[out] VolatileFlags Pointer to the buffer for returned flag structure.
98 @retval EFI_SUCCESS Operation completed successfully.
99 @retval EFI_DEVICE_ERROR The command was unsuccessful.
104 Tpm12GetCapabilityFlagVolatile (
105 OUT TPM_STCLEAR_FLAGS
*VolatileFlags
109 TPM_CMD_GET_CAPABILITY Command
;
110 TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS Response
;
114 // send Tpm command TPM_ORD_GetCapability
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
)) {
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
;
133 ZeroMem (VolatileFlags
, sizeof (*VolatileFlags
));
134 CopyMem (VolatileFlags
, &Response
.Flags
, MIN (sizeof (*VolatileFlags
), SwapBytes32(Response
.ResponseSize
)));