VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/SecurityPkg/Library/Tpm2CommandLib/Tpm2Context.c

Last change on this file was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1/** @file
2 Implement TPM2 Context related command.
3
4Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved. <BR>
5SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <IndustryStandard/UefiTcgPlatform.h>
10#include <Library/Tpm2CommandLib.h>
11#include <Library/Tpm2DeviceLib.h>
12#include <Library/BaseMemoryLib.h>
13#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15
16#pragma pack(1)
17
18typedef struct {
19 TPM2_COMMAND_HEADER Header;
20 TPMI_DH_CONTEXT FlushHandle;
21} TPM2_FLUSH_CONTEXT_COMMAND;
22
23typedef struct {
24 TPM2_RESPONSE_HEADER Header;
25} TPM2_FLUSH_CONTEXT_RESPONSE;
26
27#pragma pack()
28
29/**
30 This command causes all context associated with a loaded object or session to be removed from TPM memory.
31
32 @param[in] FlushHandle The handle of the item to flush.
33
34 @retval EFI_SUCCESS Operation completed successfully.
35 @retval EFI_DEVICE_ERROR The command was unsuccessful.
36**/
37EFI_STATUS
38EFIAPI
39Tpm2FlushContext (
40 IN TPMI_DH_CONTEXT FlushHandle
41 )
42{
43 EFI_STATUS Status;
44 TPM2_FLUSH_CONTEXT_COMMAND SendBuffer;
45 TPM2_FLUSH_CONTEXT_RESPONSE RecvBuffer;
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}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette