]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm12CommandLib/Tpm12PhysicalPresence.c
SecurityPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Library / Tpm12CommandLib / Tpm12PhysicalPresence.c
1 /** @file
2 Implement TPM1.2 Physical Presence related command.
3
4 Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10 #include <Library/Tpm12CommandLib.h>
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/Tpm12DeviceLib.h>
14
15 #pragma pack(1)
16
17 typedef struct {
18 TPM_RQU_COMMAND_HDR Hdr;
19 TPM_PHYSICAL_PRESENCE PhysicalPresence;
20 } TPM_CMD_PHYSICAL_PRESENCE;
21
22 #pragma pack()
23
24 /**
25 Send TSC_PhysicalPresence command to TPM.
26
27 @param[in] PhysicalPresence The state to set the TPMs Physical Presence flags.
28
29 @retval EFI_SUCCESS Operation completed successfully.
30 @retval EFI_TIMEOUT The register can't run into the expected status in time.
31 @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
32 @retval EFI_DEVICE_ERROR Unexpected device behavior.
33
34 **/
35 EFI_STATUS
36 EFIAPI
37 Tpm12PhysicalPresence (
38 IN TPM_PHYSICAL_PRESENCE PhysicalPresence
39 )
40 {
41 EFI_STATUS Status;
42 TPM_CMD_PHYSICAL_PRESENCE Command;
43 TPM_RSP_COMMAND_HDR Response;
44 UINT32 Length;
45
46 //
47 // send Tpm command TSC_ORD_PhysicalPresence
48 //
49 Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
50 Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
51 Command.Hdr.ordinal = SwapBytes32 (TSC_ORD_PhysicalPresence);
52 Command.PhysicalPresence = SwapBytes16 (PhysicalPresence);
53 Length = sizeof (Response);
54
55 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
56 if (EFI_ERROR (Status)) {
57 return Status;
58 }
59
60 if (SwapBytes32(Response.returnCode) != TPM_SUCCESS) {
61 DEBUG ((EFI_D_ERROR, "Tpm12PhysicalPresence: Response Code error! 0x%08x\r\n", SwapBytes32(Response.returnCode)));
62 return EFI_DEVICE_ERROR;
63 }
64
65 return EFI_SUCCESS;
66 }