]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm2CommandLib/Tpm2Startup.c
SecurityPkg: Convert all .uni files to utf-8
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Startup.c
CommitLineData
c1d93242
JY
1/** @file\r
2 Implement TPM2 Startup related command.\r
3\r
4Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <IndustryStandard/UefiTcgPlatform.h>\r
16#include <Library/Tpm2CommandLib.h>\r
17#include <Library/Tpm2DeviceLib.h>\r
18#include <Library/BaseMemoryLib.h>\r
19#include <Library/BaseLib.h>\r
20#include <Library/DebugLib.h>\r
21\r
22#pragma pack(1)\r
23\r
24typedef struct {\r
25 TPM2_COMMAND_HEADER Header;\r
26 TPM_SU StartupType;\r
27} TPM2_STARTUP_COMMAND;\r
28\r
29typedef struct {\r
30 TPM2_RESPONSE_HEADER Header;\r
31} TPM2_STARTUP_RESPONSE;\r
32\r
33typedef struct {\r
34 TPM2_COMMAND_HEADER Header;\r
35 TPM_SU ShutdownType;\r
36} TPM2_SHUTDOWN_COMMAND;\r
37\r
38typedef struct {\r
39 TPM2_RESPONSE_HEADER Header;\r
40} TPM2_SHUTDOWN_RESPONSE;\r
41\r
42#pragma pack()\r
43\r
44/**\r
45 Send Startup command to TPM2.\r
46\r
47 @param[in] StartupType TPM_SU_CLEAR or TPM_SU_STATE\r
48\r
49 @retval EFI_SUCCESS Operation completed successfully.\r
50 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
51**/\r
52EFI_STATUS\r
53EFIAPI\r
54Tpm2Startup (\r
55 IN TPM_SU StartupType\r
56 )\r
57{\r
58 EFI_STATUS Status;\r
59 TPM2_STARTUP_COMMAND Cmd;\r
60 TPM2_STARTUP_RESPONSE Res;\r
61 UINT32 ResultBufSize;\r
62\r
63 Cmd.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);\r
64 Cmd.Header.paramSize = SwapBytes32(sizeof(Cmd));\r
65 Cmd.Header.commandCode = SwapBytes32(TPM_CC_Startup);\r
66 Cmd.StartupType = SwapBytes16(StartupType);\r
67\r
68 ResultBufSize = sizeof(Res);\r
69 Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
70\r
71 return Status;\r
72}\r
73\r
74/**\r
75 Send Shutdown command to TPM2.\r
76\r
77 @param[in] ShutdownType TPM_SU_CLEAR or TPM_SU_STATE.\r
78\r
79 @retval EFI_SUCCESS Operation completed successfully.\r
80 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
81**/\r
82EFI_STATUS\r
83EFIAPI\r
84Tpm2Shutdown (\r
85 IN TPM_SU ShutdownType\r
86 )\r
87{\r
88 EFI_STATUS Status;\r
89 TPM2_SHUTDOWN_COMMAND Cmd;\r
90 TPM2_SHUTDOWN_RESPONSE Res;\r
91 UINT32 ResultBufSize;\r
92\r
93 Cmd.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);\r
94 Cmd.Header.paramSize = SwapBytes32(sizeof(Cmd));\r
95 Cmd.Header.commandCode = SwapBytes32(TPM_CC_Shutdown);\r
96 Cmd.ShutdownType = SwapBytes16(ShutdownType);\r
97\r
98 ResultBufSize = sizeof(Res);\r
99 Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);\r
100\r
101 return Status;\r
102}\r