]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2CommandLib/Tpm2Miscellaneous.c
SecurityPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Miscellaneous.c
1 /** @file
2 Implement TPM2 Miscellanenous related command.
3
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <IndustryStandard/UefiTcgPlatform.h>
10 #include <Library/Tpm2CommandLib.h>
11 #include <Library/Tpm2DeviceLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/BaseLib.h>
14 #include <Library/DebugLib.h>
15
16 #pragma pack(1)
17
18 typedef struct {
19 TPM2_COMMAND_HEADER Header;
20 TPMI_RH_HIERARCHY_AUTH AuthHandle;
21 UINT32 AuthSessionSize;
22 TPMS_AUTH_COMMAND AuthSession;
23 UINT32 AlgorithmSet;
24 } TPM2_SET_ALGORITHM_SET_COMMAND;
25
26 typedef struct {
27 TPM2_RESPONSE_HEADER Header;
28 UINT32 AuthSessionSize;
29 TPMS_AUTH_RESPONSE AuthSession;
30 } TPM2_SET_ALGORITHM_SET_RESPONSE;
31
32 #pragma pack()
33
34 /**
35 This command allows the platform to change the set of algorithms that are used by the TPM.
36 The algorithmSet setting is a vendor-dependent value.
37
38 @param[in] AuthHandle TPM_RH_PLATFORM
39 @param[in] AuthSession Auth Session context
40 @param[in] AlgorithmSet A TPM vendor-dependent value indicating the
41 algorithm set selection
42
43 @retval EFI_SUCCESS Operation completed successfully.
44 @retval EFI_DEVICE_ERROR Unexpected device behavior.
45 **/
46 EFI_STATUS
47 EFIAPI
48 Tpm2SetAlgorithmSet (
49 IN TPMI_RH_PLATFORM AuthHandle,
50 IN TPMS_AUTH_COMMAND *AuthSession,
51 IN UINT32 AlgorithmSet
52 )
53 {
54 EFI_STATUS Status;
55 TPM2_SET_ALGORITHM_SET_COMMAND SendBuffer;
56 TPM2_SET_ALGORITHM_SET_RESPONSE RecvBuffer;
57 UINT32 SendBufferSize;
58 UINT32 RecvBufferSize;
59 UINT8 *Buffer;
60 UINT32 SessionInfoSize;
61
62 //
63 // Construct command
64 //
65 SendBuffer.Header.tag = SwapBytes16(TPM_ST_SESSIONS);
66 SendBuffer.Header.commandCode = SwapBytes32(TPM_CC_SetAlgorithmSet);
67
68 SendBuffer.AuthHandle = SwapBytes32 (AuthHandle);
69
70 //
71 // Add in Auth session
72 //
73 Buffer = (UINT8 *)&SendBuffer.AuthSession;
74
75 // sessionInfoSize
76 SessionInfoSize = CopyAuthSessionCommand (AuthSession, Buffer);
77 Buffer += SessionInfoSize;
78 SendBuffer.AuthSessionSize = SwapBytes32(SessionInfoSize);
79
80 //
81 // Real data
82 //
83 WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32(AlgorithmSet));
84 Buffer += sizeof(UINT32);
85
86 SendBufferSize = (UINT32)((UINTN)Buffer - (UINTN)&SendBuffer);
87 SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);
88
89 //
90 // send Tpm command
91 //
92 RecvBufferSize = sizeof (RecvBuffer);
93 Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);
94 if (EFI_ERROR (Status)) {
95 goto Done;
96 }
97
98 if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {
99 DEBUG ((EFI_D_ERROR, "Tpm2SetAlgorithmSet - RecvBufferSize Error - %x\n", RecvBufferSize));
100 Status = EFI_DEVICE_ERROR;
101 goto Done;
102 }
103 if (SwapBytes32(RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
104 DEBUG ((EFI_D_ERROR, "Tpm2SetAlgorithmSet - responseCode - %x\n", SwapBytes32(RecvBuffer.Header.responseCode)));
105 Status = EFI_DEVICE_ERROR;
106 goto Done;
107 }
108
109 Done:
110 //
111 // Clear AuthSession Content
112 //
113 ZeroMem (&SendBuffer, sizeof(SendBuffer));
114 ZeroMem (&RecvBuffer, sizeof(RecvBuffer));
115 return Status;
116 }