]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2CommandLib/Tpm2Startup.c
Add TPM2 implementation.
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Startup.c
1 /** @file
2 Implement TPM2 Startup related command.
3
4 Copyright (c) 2013, 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
9
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.
12
13 **/
14
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>
21
22 #pragma pack(1)
23
24 typedef struct {
25 TPM2_COMMAND_HEADER Header;
26 TPM_SU StartupType;
27 } TPM2_STARTUP_COMMAND;
28
29 typedef struct {
30 TPM2_RESPONSE_HEADER Header;
31 } TPM2_STARTUP_RESPONSE;
32
33 typedef struct {
34 TPM2_COMMAND_HEADER Header;
35 TPM_SU ShutdownType;
36 } TPM2_SHUTDOWN_COMMAND;
37
38 typedef struct {
39 TPM2_RESPONSE_HEADER Header;
40 } TPM2_SHUTDOWN_RESPONSE;
41
42 #pragma pack()
43
44 /**
45 Send Startup command to TPM2.
46
47 @param[in] StartupType TPM_SU_CLEAR or TPM_SU_STATE
48
49 @retval EFI_SUCCESS Operation completed successfully.
50 @retval EFI_DEVICE_ERROR Unexpected device behavior.
51 **/
52 EFI_STATUS
53 EFIAPI
54 Tpm2Startup (
55 IN TPM_SU StartupType
56 )
57 {
58 EFI_STATUS Status;
59 TPM2_STARTUP_COMMAND Cmd;
60 TPM2_STARTUP_RESPONSE Res;
61 UINT32 ResultBufSize;
62
63 Cmd.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);
64 Cmd.Header.paramSize = SwapBytes32(sizeof(Cmd));
65 Cmd.Header.commandCode = SwapBytes32(TPM_CC_Startup);
66 Cmd.StartupType = SwapBytes16(StartupType);
67
68 ResultBufSize = sizeof(Res);
69 Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
70
71 return Status;
72 }
73
74 /**
75 Send Shutdown command to TPM2.
76
77 @param[in] ShutdownType TPM_SU_CLEAR or TPM_SU_STATE.
78
79 @retval EFI_SUCCESS Operation completed successfully.
80 @retval EFI_DEVICE_ERROR Unexpected device behavior.
81 **/
82 EFI_STATUS
83 EFIAPI
84 Tpm2Shutdown (
85 IN TPM_SU ShutdownType
86 )
87 {
88 EFI_STATUS Status;
89 TPM2_SHUTDOWN_COMMAND Cmd;
90 TPM2_SHUTDOWN_RESPONSE Res;
91 UINT32 ResultBufSize;
92
93 Cmd.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);
94 Cmd.Header.paramSize = SwapBytes32(sizeof(Cmd));
95 Cmd.Header.commandCode = SwapBytes32(TPM_CC_Shutdown);
96 Cmd.ShutdownType = SwapBytes16(ShutdownType);
97
98 ResultBufSize = sizeof(Res);
99 Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
100
101 return Status;
102 }