2 Implement TPM2 Miscellanenous related command.
4 Copyright (c) 2013 - 2016, 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_RH_HIERARCHY_AUTH AuthHandle
;
27 UINT32 AuthSessionSize
;
28 TPMS_AUTH_COMMAND AuthSession
;
30 } TPM2_SET_ALGORITHM_SET_COMMAND
;
33 TPM2_RESPONSE_HEADER Header
;
34 UINT32 AuthSessionSize
;
35 TPMS_AUTH_RESPONSE AuthSession
;
36 } TPM2_SET_ALGORITHM_SET_RESPONSE
;
41 This command allows the platform to change the set of algorithms that are used by the TPM.
42 The algorithmSet setting is a vendor-dependent value.
44 @param[in] AuthHandle TPM_RH_PLATFORM
45 @param[in] AuthSession Auth Session context
46 @param[in] AlgorithmSet A TPM vendor-dependent value indicating the
47 algorithm set selection
49 @retval EFI_SUCCESS Operation completed successfully.
50 @retval EFI_DEVICE_ERROR Unexpected device behavior.
55 IN TPMI_RH_PLATFORM AuthHandle
,
56 IN TPMS_AUTH_COMMAND
*AuthSession
,
57 IN UINT32 AlgorithmSet
61 TPM2_SET_ALGORITHM_SET_COMMAND SendBuffer
;
62 TPM2_SET_ALGORITHM_SET_RESPONSE RecvBuffer
;
63 UINT32 SendBufferSize
;
64 UINT32 RecvBufferSize
;
66 UINT32 SessionInfoSize
;
71 SendBuffer
.Header
.tag
= SwapBytes16(TPM_ST_SESSIONS
);
72 SendBuffer
.Header
.commandCode
= SwapBytes32(TPM_CC_SetAlgorithmSet
);
74 SendBuffer
.AuthHandle
= SwapBytes32 (AuthHandle
);
77 // Add in Auth session
79 Buffer
= (UINT8
*)&SendBuffer
.AuthSession
;
82 SessionInfoSize
= CopyAuthSessionCommand (AuthSession
, Buffer
);
83 Buffer
+= SessionInfoSize
;
84 SendBuffer
.AuthSessionSize
= SwapBytes32(SessionInfoSize
);
89 WriteUnaligned32 ((UINT32
*)Buffer
, SwapBytes32(AlgorithmSet
));
90 Buffer
+= sizeof(UINT32
);
92 SendBufferSize
= (UINT32
)((UINTN
)Buffer
- (UINTN
)&SendBuffer
);
93 SendBuffer
.Header
.paramSize
= SwapBytes32 (SendBufferSize
);
98 RecvBufferSize
= sizeof (RecvBuffer
);
99 Status
= Tpm2SubmitCommand (SendBufferSize
, (UINT8
*)&SendBuffer
, &RecvBufferSize
, (UINT8
*)&RecvBuffer
);
100 if (EFI_ERROR (Status
)) {
104 if (RecvBufferSize
< sizeof (TPM2_RESPONSE_HEADER
)) {
105 DEBUG ((EFI_D_ERROR
, "Tpm2SetAlgorithmSet - RecvBufferSize Error - %x\n", RecvBufferSize
));
106 Status
= EFI_DEVICE_ERROR
;
109 if (SwapBytes32(RecvBuffer
.Header
.responseCode
) != TPM_RC_SUCCESS
) {
110 DEBUG ((EFI_D_ERROR
, "Tpm2SetAlgorithmSet - responseCode - %x\n", SwapBytes32(RecvBuffer
.Header
.responseCode
)));
111 Status
= EFI_DEVICE_ERROR
;
117 // Clear AuthSession Content
119 ZeroMem (&SendBuffer
, sizeof(SendBuffer
));
120 ZeroMem (&RecvBuffer
, sizeof(RecvBuffer
));