TianoCore EDK2 master
Loading...
Searching...
No Matches
Tpm2Context.c
Go to the documentation of this file.
1
13#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15
16#pragma pack(1)
17
18typedef struct {
20 TPMI_DH_CONTEXT FlushHandle;
22
23typedef struct {
26
27#pragma pack()
28
38EFIAPI
40 IN TPMI_DH_CONTEXT FlushHandle
41 )
42{
43 EFI_STATUS Status;
46 UINT32 SendBufferSize;
47 UINT32 RecvBufferSize;
48
49 //
50 // Construct command
51 //
52 SendBuffer.Header.tag = SwapBytes16 (TPM_ST_NO_SESSIONS);
53 SendBuffer.Header.commandCode = SwapBytes32 (TPM_CC_FlushContext);
54
55 SendBuffer.FlushHandle = SwapBytes32 (FlushHandle);
56
57 SendBufferSize = (UINT32)sizeof (SendBuffer);
58 SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);
59
60 //
61 // send Tpm command
62 //
63 RecvBufferSize = sizeof (RecvBuffer);
64 Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
65 if (EFI_ERROR (Status)) {
66 return Status;
67 }
68
69 if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {
70 DEBUG ((DEBUG_ERROR, "Tpm2FlushContext - RecvBufferSize Error - %x\n", RecvBufferSize));
71 return EFI_DEVICE_ERROR;
72 }
73
74 if (SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
75 DEBUG ((DEBUG_ERROR, "Tpm2FlushContext - responseCode - %x\n", SwapBytes32 (RecvBuffer.Header.responseCode)));
76 return EFI_DEVICE_ERROR;
77 }
78
79 return EFI_SUCCESS;
80}
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI Tpm2FlushContext(IN TPMI_DH_CONTEXT FlushHandle)
Definition: Tpm2Context.c:39
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112