TianoCore EDK2 master
Loading...
Searching...
No Matches
Tpm12GetCapability.c
Go to the documentation of this file.
1
9#include <PiPei.h>
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
15
16#pragma pack(1)
17
18typedef struct {
20 UINT32 Capability;
21 UINT32 CapabilityFlagSize;
22 UINT32 CapabilityFlag;
24
25typedef struct {
27 UINT32 ResponseSize;
30
31typedef struct {
33 UINT32 ResponseSize;
36
37#pragma pack()
38
51EFIAPI
53 OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags
54 )
55{
56 EFI_STATUS Status;
59 UINT32 Length;
60
61 //
62 // send Tpm command TPM_ORD_GetCapability
63 //
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)) {
73 return Status;
74 }
75
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;
79 }
80
81 ZeroMem (TpmPermanentFlags, sizeof (*TpmPermanentFlags));
82 CopyMem (TpmPermanentFlags, &Response.Flags, MIN (sizeof (*TpmPermanentFlags), SwapBytes32 (Response.ResponseSize)));
83
84 return Status;
85}
86
97EFIAPI
99 OUT TPM_STCLEAR_FLAGS *VolatileFlags
100 )
101{
102 EFI_STATUS Status;
105 UINT32 Length;
106
107 //
108 // send Tpm command TPM_ORD_GetCapability
109 //
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)) {
119 return Status;
120 }
121
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;
125 }
126
127 ZeroMem (VolatileFlags, sizeof (*VolatileFlags));
128 CopyMem (VolatileFlags, &Response.Flags, MIN (sizeof (*VolatileFlags), SwapBytes32 (Response.ResponseSize)));
129
130 return Status;
131}
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define MIN(a, b)
Definition: Base.h:1007
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI Tpm12SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
Definition: Tpm12Tis.c:453
EFI_STATUS EFIAPI Tpm12GetCapabilityFlagVolatile(OUT TPM_STCLEAR_FLAGS *VolatileFlags)
EFI_STATUS EFIAPI Tpm12GetCapabilityFlagPermanent(OUT TPM_PERMANENT_FLAGS *TpmPermanentFlags)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29