TianoCore EDK2 master
Loading...
Searching...
No Matches
Tpm2Miscellaneous.c
Go to the documentation of this file.
1
13#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
15
16#pragma pack(1)
17
18typedef struct {
20 TPMI_RH_HIERARCHY_AUTH AuthHandle;
21 UINT32 AuthSessionSize;
22 TPMS_AUTH_COMMAND AuthSession;
23 UINT32 AlgorithmSet;
25
26typedef struct {
28 UINT32 AuthSessionSize;
29 TPMS_AUTH_RESPONSE AuthSession;
31
32#pragma pack()
33
47EFIAPI
49 IN TPMI_RH_PLATFORM AuthHandle,
50 IN TPMS_AUTH_COMMAND *AuthSession,
51 IN UINT32 AlgorithmSet
52 )
53{
54 EFI_STATUS Status;
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 ((DEBUG_ERROR, "Tpm2SetAlgorithmSet - RecvBufferSize Error - %x\n", RecvBufferSize));
100 Status = EFI_DEVICE_ERROR;
101 goto Done;
102 }
103
104 if (SwapBytes32 (RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
105 DEBUG ((DEBUG_ERROR, "Tpm2SetAlgorithmSet - responseCode - %x\n", SwapBytes32 (RecvBuffer.Header.responseCode)));
106 Status = EFI_DEVICE_ERROR;
107 goto Done;
108 }
109
110Done:
111 //
112 // Clear AuthSession Content
113 //
114 ZeroMem (&SendBuffer, sizeof (SendBuffer));
115 ZeroMem (&RecvBuffer, sizeof (RecvBuffer));
116 return Status;
117}
UINT64 UINTN
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:177
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT32 EFIAPI CopyAuthSessionCommand(IN TPMS_AUTH_COMMAND *AuthSessionIn OPTIONAL, OUT UINT8 *AuthSessionOut)
Definition: Tpm2Help.c:88
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS EFIAPI Tpm2SetAlgorithmSet(IN TPMI_RH_PLATFORM AuthHandle, IN TPMS_AUTH_COMMAND *AuthSession, IN UINT32 AlgorithmSet)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29