2 Implement TPM2 Context related command.
4 Copyright (c) 2014, 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.
15 #include <IndustryStandard/UefiTcgPlatform.h>
16 #include <Library/Tpm2CommandLib.h>
17 #include <Library/Tpm2DeviceLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
25 TPM2_COMMAND_HEADER Header
;
26 TPMI_DH_CONTEXT FlushHandle
;
27 } TPM2_FLUSH_CONTEXT_COMMAND
;
30 TPM2_RESPONSE_HEADER Header
;
31 } TPM2_FLUSH_CONTEXT_RESPONSE
;
36 This command causes all context associated with a loaded object or session to be removed from TPM memory.
38 @param[in] FlushHandle The handle of the item to flush.
40 @retval EFI_SUCCESS Operation completed successfully.
41 @retval EFI_DEVICE_ERROR The command was unsuccessful.
46 IN TPMI_DH_CONTEXT FlushHandle
50 TPM2_FLUSH_CONTEXT_COMMAND SendBuffer
;
51 TPM2_FLUSH_CONTEXT_RESPONSE RecvBuffer
;
52 UINT32 SendBufferSize
;
53 UINT32 RecvBufferSize
;
58 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
59 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_FlushContext
);
61 SendBuffer
.FlushHandle
= SwapBytes32 (FlushHandle
);
63 SendBufferSize
= (UINT32
) sizeof (SendBuffer
);
64 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
69 RecvBufferSize
= sizeof (RecvBuffer
);
70 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
71 if (EFI_ERROR (Status
)) {
75 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
76 DEBUG ((EFI_D_ERROR
, "Tpm2FlushContext - RecvBufferSize Error - %x\n", RecvBufferSize
));
77 return EFI_DEVICE_ERROR
;
79 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
80 DEBUG ((EFI_D_ERROR
, "Tpm2FlushContext - responseCode - %x\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
81 return EFI_DEVICE_ERROR
;