2 Implement TPM1.2 Get Capabilities related commands.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/Tpm12CommandLib.h>
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/Tpm12DeviceLib.h>
19 TPM_RQU_COMMAND_HDR Hdr
;
21 UINT32 CapabilityFlagSize
;
22 UINT32 CapabilityFlag
;
23 } TPM_CMD_GET_CAPABILITY
;
26 TPM_RSP_COMMAND_HDR Hdr
;
28 TPM_PERMANENT_FLAGS Flags
;
29 } TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS
;
32 TPM_RSP_COMMAND_HDR Hdr
;
34 TPM_STCLEAR_FLAGS Flags
;
35 } TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS
;
40 Get TPM capability permanent flags.
42 @param[out] TpmPermanentFlags Pointer to the buffer for returned flag structure.
44 @retval EFI_SUCCESS Operation completed successfully.
45 @retval EFI_TIMEOUT The register can't run into the expected status in time.
46 @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
47 @retval EFI_DEVICE_ERROR Unexpected device behavior.
52 Tpm12GetCapabilityFlagPermanent (
53 OUT TPM_PERMANENT_FLAGS
*TpmPermanentFlags
57 TPM_CMD_GET_CAPABILITY Command
;
58 TPM_RSP_GET_CAPABILITY_PERMANENT_FLAGS Response
;
62 // send Tpm command TPM_ORD_GetCapability
64 Command
.Hdr
.tag
= SwapBytes16 (TPM_TAG_RQU_COMMAND
);
65 Command
.Hdr
.paramSize
= SwapBytes32 (sizeof (Command
));
66 Command
.Hdr
.ordinal
= SwapBytes32 (TPM_ORD_GetCapability
);
67 Command
.Capability
= SwapBytes32 (TPM_CAP_FLAG
);
68 Command
.CapabilityFlagSize
= SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT
));
69 Command
.CapabilityFlag
= SwapBytes32 (TPM_CAP_FLAG_PERMANENT
);
70 Length
= sizeof (Response
);
71 Status
= Tpm12SubmitCommand (sizeof (Command
), (UINT8
*)&Command
, &Length
, (UINT8
*)&Response
);
72 if (EFI_ERROR (Status
)) {
76 if (SwapBytes32 (Response
.Hdr
.returnCode
) != TPM_SUCCESS
) {
77 DEBUG ((DEBUG_ERROR
, "Tpm12GetCapabilityFlagPermanent: Response Code error! 0x%08x\r\n", SwapBytes32 (Response
.Hdr
.returnCode
)));
78 return EFI_DEVICE_ERROR
;
81 ZeroMem (TpmPermanentFlags
, sizeof (*TpmPermanentFlags
));
82 CopyMem (TpmPermanentFlags
, &Response
.Flags
, MIN (sizeof (*TpmPermanentFlags
), SwapBytes32(Response
.ResponseSize
)));
88 Get TPM capability volatile flags.
90 @param[out] VolatileFlags Pointer to the buffer for returned flag structure.
92 @retval EFI_SUCCESS Operation completed successfully.
93 @retval EFI_DEVICE_ERROR The command was unsuccessful.
98 Tpm12GetCapabilityFlagVolatile (
99 OUT TPM_STCLEAR_FLAGS
*VolatileFlags
103 TPM_CMD_GET_CAPABILITY Command
;
104 TPM_RSP_GET_CAPABILITY_STCLEAR_FLAGS Response
;
108 // send Tpm command TPM_ORD_GetCapability
110 Command
.Hdr
.tag
= SwapBytes16 (TPM_TAG_RQU_COMMAND
);
111 Command
.Hdr
.paramSize
= SwapBytes32 (sizeof (Command
));
112 Command
.Hdr
.ordinal
= SwapBytes32 (TPM_ORD_GetCapability
);
113 Command
.Capability
= SwapBytes32 (TPM_CAP_FLAG
);
114 Command
.CapabilityFlagSize
= SwapBytes32 (sizeof (TPM_CAP_FLAG_VOLATILE
));
115 Command
.CapabilityFlag
= SwapBytes32 (TPM_CAP_FLAG_VOLATILE
);
116 Length
= sizeof (Response
);
117 Status
= Tpm12SubmitCommand (sizeof (Command
), (UINT8
*)&Command
, &Length
, (UINT8
*)&Response
);
118 if (EFI_ERROR (Status
)) {
122 if (SwapBytes32 (Response
.Hdr
.returnCode
) != TPM_SUCCESS
) {
123 DEBUG ((DEBUG_ERROR
, "Tpm12GetCapabilityFlagVolatile: Response Code error! 0x%08x\r\n", SwapBytes32 (Response
.Hdr
.returnCode
)));
124 return EFI_DEVICE_ERROR
;
127 ZeroMem (VolatileFlags
, sizeof (*VolatileFlags
));
128 CopyMem (VolatileFlags
, &Response
.Flags
, MIN (sizeof (*VolatileFlags
), SwapBytes32(Response
.ResponseSize
)));