2 Implement TPM2 Startup related command.
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <IndustryStandard/UefiTcgPlatform.h>
17 #include <Library/Tpm2CommandLib.h>
18 #include <Library/Tpm2DeviceLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
26 TPM2_COMMAND_HEADER Header
;
28 } TPM2_STARTUP_COMMAND
;
31 TPM2_RESPONSE_HEADER Header
;
32 } TPM2_STARTUP_RESPONSE
;
35 TPM2_COMMAND_HEADER Header
;
37 } TPM2_SHUTDOWN_COMMAND
;
40 TPM2_RESPONSE_HEADER Header
;
41 } TPM2_SHUTDOWN_RESPONSE
;
46 Send Startup command to TPM2.
48 @param[in] StartupType TPM_SU_CLEAR or TPM_SU_STATE
50 @retval EFI_SUCCESS Operation completed successfully.
51 @retval EFI_DEVICE_ERROR Unexpected device behavior.
60 TPM2_STARTUP_COMMAND Cmd
;
61 TPM2_STARTUP_RESPONSE Res
;
65 Cmd
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
66 Cmd
.Header
.paramSize
= SwapBytes32(sizeof(Cmd
));
67 Cmd
.Header
.commandCode
= SwapBytes32(TPM_CC_Startup
);
68 Cmd
.StartupType
= SwapBytes16(StartupType
);
70 ResultBufSize
= sizeof(Res
);
71 Status
= Tpm2SubmitCommand (sizeof(Cmd
), (UINT8
*)&Cmd
, &ResultBufSize
, (UINT8
*)&Res
);
72 if (EFI_ERROR(Status
)) {
76 ResponseCode
= SwapBytes32(Res
.Header
.responseCode
);
77 switch (ResponseCode
) {
79 DEBUG ((DEBUG_INFO
, "TPM2Startup: TPM_RC_SUCCESS\n"));
81 case TPM_RC_INITIALIZE
:
82 // TPM_RC_INITIALIZE can be returned if Tpm2Startup is not required.
83 DEBUG ((DEBUG_INFO
, "TPM2Startup: TPM_RC_INITIALIZE\n"));
86 DEBUG ((EFI_D_ERROR
, "Tpm2Startup: Response Code error! 0x%08x\r\n", ResponseCode
));
87 return EFI_DEVICE_ERROR
;
92 Send Shutdown command to TPM2.
94 @param[in] ShutdownType TPM_SU_CLEAR or TPM_SU_STATE.
96 @retval EFI_SUCCESS Operation completed successfully.
97 @retval EFI_DEVICE_ERROR Unexpected device behavior.
102 IN TPM_SU ShutdownType
106 TPM2_SHUTDOWN_COMMAND Cmd
;
107 TPM2_SHUTDOWN_RESPONSE Res
;
108 UINT32 ResultBufSize
;
110 Cmd
.Header
.tag
= SwapBytes16(TPM_ST_NO_SESSIONS
);
111 Cmd
.Header
.paramSize
= SwapBytes32(sizeof(Cmd
));
112 Cmd
.Header
.commandCode
= SwapBytes32(TPM_CC_Shutdown
);
113 Cmd
.ShutdownType
= SwapBytes16(ShutdownType
);
115 ResultBufSize
= sizeof(Res
);
116 Status
= Tpm2SubmitCommand (sizeof(Cmd
), (UINT8
*)&Cmd
, &ResultBufSize
, (UINT8
*)&Res
);
117 if (EFI_ERROR(Status
)) {
121 if (SwapBytes32(Res
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
122 DEBUG ((EFI_D_ERROR
, "Tpm2Shutdown: Response Code error! 0x%08x\r\n", SwapBytes32(Res
.Header
.responseCode
)));
123 return EFI_DEVICE_ERROR
;