1 /** @file
2   This library is used by other modules to send TPM12 command.
3 
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _TPM12_COMMAND_LIB_H_
10 #define _TPM12_COMMAND_LIB_H_
11 
12 #include <IndustryStandard/Tpm12.h>
13 
14 /**
15   Send Startup command to TPM1.2.
16 
17   @param TpmSt           Startup Type.
18 
19   @retval EFI_SUCCESS      Operation completed successfully.
20   @retval EFI_DEVICE_ERROR Unexpected device behavior.
21 **/
22 EFI_STATUS
23 EFIAPI
24 Tpm12Startup (
25   IN TPM_STARTUP_TYPE          TpmSt
26   );
27 
28 /**
29   Send SaveState command to TPM1.2.
30 
31   @retval EFI_SUCCESS      Operation completed successfully.
32   @retval EFI_DEVICE_ERROR Unexpected device behavior.
33 **/
34 EFI_STATUS
35 EFIAPI
36 Tpm12SaveState (
37   VOID
38   );
39 
40 /**
41   Send ForceClear command to TPM1.2.
42 
43   @retval EFI_SUCCESS      Operation completed successfully.
44   @retval EFI_DEVICE_ERROR Unexpected device behavior.
45 **/
46 EFI_STATUS
47 EFIAPI
48 Tpm12ForceClear (
49   VOID
50   );
51 
52 #pragma pack(1)
53 
54 typedef struct {
55   UINT16                            sizeOfSelect;
56   UINT8                             pcrSelect[3];
57 } TPM12_PCR_SELECTION;
58 
59 typedef struct {
60   TPM12_PCR_SELECTION               pcrSelection;
61   TPM_LOCALITY_SELECTION            localityAtRelease;
62   TPM_COMPOSITE_HASH                digestAtRelease;
63 } TPM12_PCR_INFO_SHORT;
64 
65 typedef struct {
66   TPM_STRUCTURE_TAG               tag;
67   TPM_NV_INDEX                    nvIndex;
68   TPM12_PCR_INFO_SHORT            pcrInfoRead;
69   TPM12_PCR_INFO_SHORT            pcrInfoWrite;
70   TPM_NV_ATTRIBUTES               permission;
71   BOOLEAN                         bReadSTClear;
72   BOOLEAN                         bWriteSTClear;
73   BOOLEAN                         bWriteDefine;
74   UINT32                          dataSize;
75 } TPM12_NV_DATA_PUBLIC;
76 
77 #pragma pack()
78 
79 /**
80   Send NV DefineSpace command to TPM1.2.
81 
82   @param PubInfo           The public parameters of the NV area.
83   @param EncAuth           The encrypted AuthData, only valid if the attributes require subsequent authorization.
84 
85   @retval EFI_SUCCESS      Operation completed successfully.
86   @retval EFI_DEVICE_ERROR Unexpected device behavior.
87 **/
88 EFI_STATUS
89 EFIAPI
90 Tpm12NvDefineSpace (
91   IN TPM12_NV_DATA_PUBLIC  *PubInfo,
92   IN TPM_ENCAUTH           *EncAuth
93   );
94 
95 /**
96   Send NV ReadValue command to TPM1.2.
97 
98   @param NvIndex           The index of the area to set.
99   @param Offset            The offset into the area.
100   @param DataSize          The size of the data area.
101   @param Data              The data to set the area to.
102 
103   @retval EFI_SUCCESS      Operation completed successfully.
104   @retval EFI_DEVICE_ERROR Unexpected device behavior.
105 **/
106 EFI_STATUS
107 EFIAPI
108 Tpm12NvReadValue (
109   IN TPM_NV_INDEX   NvIndex,
110   IN UINT32         Offset,
111   IN OUT UINT32     *DataSize,
112   OUT UINT8         *Data
113   );
114 
115 /**
116   Send NV WriteValue command to TPM1.2.
117 
118   @param NvIndex           The index of the area to set.
119   @param Offset            The offset into the NV Area.
120   @param DataSize          The size of the data parameter.
121   @param Data              The data to set the area to.
122 
123   @retval EFI_SUCCESS      Operation completed successfully.
124   @retval EFI_DEVICE_ERROR Unexpected device behavior.
125 **/
126 EFI_STATUS
127 EFIAPI
128 Tpm12NvWriteValue (
129   IN TPM_NV_INDEX   NvIndex,
130   IN UINT32         Offset,
131   IN UINT32         DataSize,
132   IN UINT8          *Data
133   );
134 
135 /**
136 Extend a TPM PCR.
137 
138 @param[in]  DigestToExtend    The 160 bit value representing the event to be recorded.
139 @param[in]  PcrIndex          The PCR to be updated.
140 @param[out] NewPcrValue       New PCR value after extend.
141 
142 @retval EFI_SUCCESS           Operation completed successfully.
143 @retval EFI_TIMEOUT           The register can't run into the expected status in time.
144 @retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.
145 @retval EFI_DEVICE_ERROR      Unexpected device behavior.
146 
147 **/
148 EFI_STATUS
149 EFIAPI
150 Tpm12Extend (
151   IN  TPM_DIGEST    *DigestToExtend,
152   IN  TPM_PCRINDEX  PcrIndex,
153   OUT TPM_DIGEST    *NewPcrValue
154   );
155 
156 /**
157 Send TSC_PhysicalPresence command to TPM.
158 
159 @param[in] PhysicalPresence   The state to set the TPMs Physical Presence flags.
160 
161 @retval EFI_SUCCESS           Operation completed successfully.
162 @retval EFI_TIMEOUT           The register can't run into the expected status in time.
163 @retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.
164 @retval EFI_DEVICE_ERROR      Unexpected device behavior.
165 
166 **/
167 EFI_STATUS
168 EFIAPI
169 Tpm12PhysicalPresence (
170   IN      TPM_PHYSICAL_PRESENCE     PhysicalPresence
171   );
172 
173 /**
174 Send TPM_ContinueSelfTest command to TPM.
175 
176 @retval EFI_SUCCESS           Operation completed successfully.
177 @retval EFI_TIMEOUT           The register can't run into the expected status in time.
178 @retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.
179 @retval EFI_DEVICE_ERROR      Unexpected device behavior.
180 
181 **/
182 EFI_STATUS
183 EFIAPI
184 Tpm12ContinueSelfTest (
185   VOID
186   );
187 
188 /**
189 Get TPM capability permanent flags.
190 
191 @param[out] TpmPermanentFlags   Pointer to the buffer for returned flag structure.
192 
193 @retval EFI_SUCCESS           Operation completed successfully.
194 @retval EFI_TIMEOUT           The register can't run into the expected status in time.
195 @retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.
196 @retval EFI_DEVICE_ERROR      Unexpected device behavior.
197 
198 **/
199 EFI_STATUS
200 EFIAPI
201 Tpm12GetCapabilityFlagPermanent (
202   OUT TPM_PERMANENT_FLAGS  *TpmPermanentFlags
203   );
204 
205 /**
206 Get TPM capability volatile flags.
207 
208 @param[out] VolatileFlags   Pointer to the buffer for returned flag structure.
209 
210 @retval EFI_SUCCESS      Operation completed successfully.
211 @retval EFI_DEVICE_ERROR The command was unsuccessful.
212 
213 **/
214 EFI_STATUS
215 EFIAPI
216 Tpm12GetCapabilityFlagVolatile (
217   OUT TPM_STCLEAR_FLAGS                 *VolatileFlags
218   );
219 #endif
220