]>
Commit | Line | Data |
---|---|---|
c1d93242 JY |
1 | /** @file\r |
2 | Implement TPM2 Capability related command.\r | |
3 | \r | |
4 | Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include <IndustryStandard/UefiTcgPlatform.h>\r | |
16 | #include <Library/Tpm2CommandLib.h>\r | |
17 | #include <Library/Tpm2DeviceLib.h>\r | |
18 | #include <Library/BaseMemoryLib.h>\r | |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | \r | |
22 | #pragma pack(1)\r | |
23 | \r | |
24 | typedef struct {\r | |
25 | TPM2_COMMAND_HEADER Header;\r | |
26 | TPM_CAP Capability;\r | |
27 | UINT32 Property;\r | |
28 | UINT32 PropertyCount;\r | |
29 | } TPM2_GET_CAPABILITY_COMMAND;\r | |
30 | \r | |
31 | typedef struct {\r | |
32 | TPM2_RESPONSE_HEADER Header;\r | |
33 | TPMI_YES_NO MoreData;\r | |
34 | TPMS_CAPABILITY_DATA CapabilityData;\r | |
35 | } TPM2_GET_CAPABILITY_RESPONSE;\r | |
36 | \r | |
37 | typedef struct {\r | |
38 | TPM2_COMMAND_HEADER Header;\r | |
39 | TPMT_PUBLIC_PARMS Parameters;\r | |
40 | } TPM2_TEST_PARMS_COMMAND;\r | |
41 | \r | |
42 | typedef struct {\r | |
43 | TPM2_RESPONSE_HEADER Header;\r | |
44 | } TPM2_TEST_PARMS_RESPONSE;\r | |
45 | \r | |
46 | #pragma pack()\r | |
47 | \r | |
48 | /**\r | |
49 | This command returns various information regarding the TPM and its current state.\r | |
50 | \r | |
51 | The capability parameter determines the category of data returned. The property parameter \r | |
52 | selects the first value of the selected category to be returned. If there is no property \r | |
53 | that corresponds to the value of property, the next higher value is returned, if it exists.\r | |
54 | The moreData parameter will have a value of YES if there are more values of the requested \r | |
55 | type that were not returned.\r | |
56 | If no next capability exists, the TPM will return a zero-length list and moreData will have \r | |
57 | a value of NO.\r | |
58 | \r | |
59 | NOTE: \r | |
60 | To simplify this function, leave returned CapabilityData for caller to unpack since there are \r | |
61 | many capability categories and only few categories will be used in firmware. It means the caller\r | |
62 | need swap the byte order for the feilds in CapabilityData.\r | |
63 | \r | |
64 | @param[in] Capability Group selection; determines the format of the response.\r | |
65 | @param[in] Property Further definition of information. \r | |
66 | @param[in] PropertyCount Number of properties of the indicated type to return.\r | |
67 | @param[out] MoreData Flag to indicate if there are more values of this type.\r | |
68 | @param[out] CapabilityData The capability data.\r | |
69 | \r | |
70 | @retval EFI_SUCCESS Operation completed successfully.\r | |
71 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
72 | **/\r | |
73 | EFI_STATUS\r | |
74 | EFIAPI\r | |
75 | Tpm2GetCapability (\r | |
76 | IN TPM_CAP Capability,\r | |
77 | IN UINT32 Property,\r | |
78 | IN UINT32 PropertyCount,\r | |
79 | OUT TPMI_YES_NO *MoreData,\r | |
80 | OUT TPMS_CAPABILITY_DATA *CapabilityData\r | |
81 | )\r | |
82 | {\r | |
83 | EFI_STATUS Status;\r | |
84 | TPM2_GET_CAPABILITY_COMMAND SendBuffer;\r | |
85 | TPM2_GET_CAPABILITY_RESPONSE RecvBuffer;\r | |
86 | UINT32 SendBufferSize;\r | |
87 | UINT32 RecvBufferSize;\r | |
88 | \r | |
89 | //\r | |
90 | // Construct command\r | |
91 | //\r | |
92 | SendBuffer.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);\r | |
93 | SendBuffer.Header.commandCode = SwapBytes32(TPM_CC_GetCapability);\r | |
94 | \r | |
95 | SendBuffer.Capability = SwapBytes32 (Capability);\r | |
96 | SendBuffer.Property = SwapBytes32 (Property);\r | |
97 | SendBuffer.PropertyCount = SwapBytes32 (PropertyCount);\r | |
98 | \r | |
99 | SendBufferSize = (UINT32) sizeof (SendBuffer);\r | |
100 | SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);\r | |
101 | \r | |
102 | //\r | |
103 | // send Tpm command\r | |
104 | //\r | |
105 | RecvBufferSize = sizeof (RecvBuffer);\r | |
106 | Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer );\r | |
107 | if (EFI_ERROR (Status)) {\r | |
108 | return Status;\r | |
109 | }\r | |
110 | \r | |
111 | if (RecvBufferSize <= sizeof (TPM2_RESPONSE_HEADER) + sizeof (UINT8)) {\r | |
112 | return EFI_DEVICE_ERROR;\r | |
113 | }\r | |
114 | \r | |
115 | //\r | |
116 | // Return the response\r | |
117 | //\r | |
118 | *MoreData = RecvBuffer.MoreData;\r | |
119 | //\r | |
120 | // Does not unpack all possiable property here, the caller should unpack it and note the byte order.\r | |
121 | //\r | |
122 | CopyMem (CapabilityData, &RecvBuffer.CapabilityData, RecvBufferSize - sizeof (TPM2_RESPONSE_HEADER) - sizeof (UINT8));\r | |
123 | \r | |
124 | return EFI_SUCCESS;\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | This command returns the information of TPM Family.\r | |
129 | \r | |
130 | This function parse the value got from TPM2_GetCapability and return the Family.\r | |
131 | \r | |
132 | @param[out] Family The Family of TPM. (a 4-octet character string)\r | |
133 | \r | |
134 | @retval EFI_SUCCESS Operation completed successfully.\r | |
135 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
136 | **/\r | |
137 | EFI_STATUS\r | |
138 | EFIAPI\r | |
139 | Tpm2GetCapabilityFamily (\r | |
140 | OUT CHAR8 *Family\r | |
141 | )\r | |
142 | {\r | |
143 | TPMS_CAPABILITY_DATA TpmCap;\r | |
144 | TPMI_YES_NO MoreData;\r | |
145 | EFI_STATUS Status; \r | |
146 | \r | |
147 | Status = Tpm2GetCapability (\r | |
148 | TPM_CAP_TPM_PROPERTIES, \r | |
149 | TPM_PT_FAMILY_INDICATOR, \r | |
150 | 1, \r | |
151 | &MoreData, \r | |
152 | &TpmCap\r | |
153 | );\r | |
154 | if (EFI_ERROR (Status)) {\r | |
155 | return Status;\r | |
156 | }\r | |
157 | CopyMem (Family, &TpmCap.data.tpmProperties.tpmProperty->value, 4);\r | |
158 | \r | |
159 | return EFI_SUCCESS;\r | |
160 | }\r | |
161 | \r | |
162 | /**\r | |
163 | This command returns the information of TPM manufacture ID.\r | |
164 | \r | |
165 | This function parse the value got from TPM2_GetCapability and return the TPM manufacture ID.\r | |
166 | \r | |
167 | @param[out] ManufactureId The manufacture ID of TPM.\r | |
168 | \r | |
169 | @retval EFI_SUCCESS Operation completed successfully.\r | |
170 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
171 | **/\r | |
172 | EFI_STATUS\r | |
173 | EFIAPI\r | |
174 | Tpm2GetCapabilityManufactureID (\r | |
175 | OUT UINT32 *ManufactureId\r | |
176 | )\r | |
177 | {\r | |
178 | TPMS_CAPABILITY_DATA TpmCap;\r | |
179 | TPMI_YES_NO MoreData;\r | |
180 | EFI_STATUS Status; \r | |
181 | \r | |
182 | Status = Tpm2GetCapability (\r | |
183 | TPM_CAP_TPM_PROPERTIES, \r | |
184 | TPM_PT_MANUFACTURER, \r | |
185 | 1, \r | |
186 | &MoreData, \r | |
187 | &TpmCap\r | |
188 | );\r | |
189 | if (EFI_ERROR (Status)) {\r | |
190 | return Status;\r | |
191 | }\r | |
192 | *ManufactureId = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
193 | \r | |
194 | return EFI_SUCCESS;\r | |
195 | }\r | |
196 | \r | |
197 | /**\r | |
198 | This command returns the information of TPM FirmwareVersion.\r | |
199 | \r | |
200 | This function parse the value got from TPM2_GetCapability and return the TPM FirmwareVersion.\r | |
201 | \r | |
202 | @param[out] FirmwareVersion1 The FirmwareVersion1.\r | |
203 | @param[out] FirmwareVersion2 The FirmwareVersion2.\r | |
204 | \r | |
205 | @retval EFI_SUCCESS Operation completed successfully.\r | |
206 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
207 | **/\r | |
208 | EFI_STATUS\r | |
209 | EFIAPI\r | |
210 | Tpm2GetCapabilityFirmwareVersion (\r | |
211 | OUT UINT32 *FirmwareVersion1,\r | |
212 | OUT UINT32 *FirmwareVersion2\r | |
213 | )\r | |
214 | {\r | |
215 | TPMS_CAPABILITY_DATA TpmCap;\r | |
216 | TPMI_YES_NO MoreData;\r | |
217 | EFI_STATUS Status; \r | |
218 | \r | |
219 | Status = Tpm2GetCapability (\r | |
220 | TPM_CAP_TPM_PROPERTIES, \r | |
221 | TPM_PT_FIRMWARE_VERSION_1, \r | |
222 | 1, \r | |
223 | &MoreData, \r | |
224 | &TpmCap\r | |
225 | );\r | |
226 | if (EFI_ERROR (Status)) {\r | |
227 | return Status;\r | |
228 | }\r | |
229 | *FirmwareVersion1 = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
230 | \r | |
231 | Status = Tpm2GetCapability (\r | |
232 | TPM_CAP_TPM_PROPERTIES, \r | |
233 | TPM_PT_FIRMWARE_VERSION_2, \r | |
234 | 1, \r | |
235 | &MoreData, \r | |
236 | &TpmCap\r | |
237 | );\r | |
238 | if (EFI_ERROR (Status)) {\r | |
239 | return Status;\r | |
240 | }\r | |
241 | *FirmwareVersion2 = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
242 | \r | |
243 | return EFI_SUCCESS;\r | |
244 | }\r | |
245 | \r | |
246 | /**\r | |
247 | This command returns the information of the maximum value for commandSize and responseSize in a command.\r | |
248 | \r | |
249 | This function parse the value got from TPM2_GetCapability and return the max command size and response size\r | |
250 | \r | |
251 | @param[out] MaxCommandSize The maximum value for commandSize in a command.\r | |
252 | @param[out] MaxResponseSize The maximum value for responseSize in a command.\r | |
253 | \r | |
254 | @retval EFI_SUCCESS Operation completed successfully.\r | |
255 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
256 | **/\r | |
257 | EFI_STATUS\r | |
258 | EFIAPI\r | |
259 | Tpm2GetCapabilityMaxCommandResponseSize (\r | |
260 | OUT UINT32 *MaxCommandSize,\r | |
261 | OUT UINT32 *MaxResponseSize\r | |
262 | )\r | |
263 | {\r | |
264 | TPMS_CAPABILITY_DATA TpmCap;\r | |
265 | TPMI_YES_NO MoreData;\r | |
266 | EFI_STATUS Status;\r | |
267 | \r | |
268 | Status = Tpm2GetCapability (\r | |
269 | TPM_CAP_TPM_PROPERTIES, \r | |
270 | TPM_PT_MAX_COMMAND_SIZE, \r | |
271 | 1, \r | |
272 | &MoreData, \r | |
273 | &TpmCap\r | |
274 | );\r | |
275 | if (EFI_ERROR (Status)) {\r | |
276 | return Status;\r | |
277 | }\r | |
278 | \r | |
279 | *MaxCommandSize = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
280 | \r | |
281 | Status = Tpm2GetCapability (\r | |
282 | TPM_CAP_TPM_PROPERTIES, \r | |
283 | TPM_PT_MAX_RESPONSE_SIZE, \r | |
284 | 1, \r | |
285 | &MoreData, \r | |
286 | &TpmCap\r | |
287 | );\r | |
288 | if (EFI_ERROR (Status)) {\r | |
289 | return Status;\r | |
290 | }\r | |
291 | \r | |
292 | *MaxResponseSize = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
293 | return EFI_SUCCESS; \r | |
294 | }\r | |
295 | \r | |
296 | /**\r | |
297 | This command returns Returns a list of TPMS_ALG_PROPERTIES. Each entry is an\r | |
298 | algorithm ID and a set of properties of the algorithm. \r | |
299 | \r | |
300 | This function parse the value got from TPM2_GetCapability and return the list.\r | |
301 | \r | |
302 | @param[out] AlgList List of algorithm.\r | |
303 | \r | |
304 | @retval EFI_SUCCESS Operation completed successfully.\r | |
305 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
306 | **/\r | |
307 | EFI_STATUS\r | |
308 | EFIAPI\r | |
309 | Tpm2GetCapabilitySupportedAlg (\r | |
310 | OUT TPML_ALG_PROPERTY *AlgList\r | |
311 | )\r | |
312 | {\r | |
313 | TPMS_CAPABILITY_DATA TpmCap;\r | |
314 | TPMI_YES_NO MoreData;\r | |
315 | UINTN Index;\r | |
316 | EFI_STATUS Status;\r | |
317 | \r | |
318 | Status = Tpm2GetCapability (\r | |
319 | TPM_CAP_ALGS, \r | |
320 | 1, \r | |
321 | MAX_CAP_ALGS, \r | |
322 | &MoreData, \r | |
323 | &TpmCap\r | |
324 | );\r | |
325 | if (EFI_ERROR (Status)) {\r | |
326 | return Status;\r | |
327 | }\r | |
328 | \r | |
329 | CopyMem (AlgList, &TpmCap.data.algorithms, sizeof (TPML_ALG_PROPERTY));\r | |
330 | \r | |
331 | AlgList->count = SwapBytes32 (AlgList->count);\r | |
332 | for (Index = 0; Index < AlgList->count; Index++) {\r | |
333 | AlgList->algProperties[Index].alg = SwapBytes16 (AlgList->algProperties[Index].alg);\r | |
334 | WriteUnaligned32 ((UINT32 *)&AlgList->algProperties[Index].algProperties, SwapBytes32 (ReadUnaligned32 ((UINT32 *)&AlgList->algProperties[Index].algProperties)));\r | |
335 | }\r | |
336 | \r | |
337 | return EFI_SUCCESS;\r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | This command returns the information of TPM LockoutCounter.\r | |
342 | \r | |
343 | This function parse the value got from TPM2_GetCapability and return the LockoutCounter.\r | |
344 | \r | |
345 | @param[out] LockoutCounter The LockoutCounter of TPM.\r | |
346 | \r | |
347 | @retval EFI_SUCCESS Operation completed successfully.\r | |
348 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
349 | **/\r | |
350 | EFI_STATUS\r | |
351 | EFIAPI\r | |
352 | Tpm2GetCapabilityLockoutCounter (\r | |
353 | OUT UINT32 *LockoutCounter\r | |
354 | )\r | |
355 | {\r | |
356 | TPMS_CAPABILITY_DATA TpmCap;\r | |
357 | TPMI_YES_NO MoreData;\r | |
358 | EFI_STATUS Status; \r | |
359 | \r | |
360 | Status = Tpm2GetCapability (\r | |
361 | TPM_CAP_TPM_PROPERTIES, \r | |
362 | TPM_PT_LOCKOUT_COUNTER, \r | |
363 | 1, \r | |
364 | &MoreData, \r | |
365 | &TpmCap\r | |
366 | );\r | |
367 | if (EFI_ERROR (Status)) {\r | |
368 | return Status;\r | |
369 | }\r | |
370 | *LockoutCounter = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
371 | \r | |
372 | return EFI_SUCCESS;\r | |
373 | }\r | |
374 | \r | |
375 | /**\r | |
376 | This command returns the information of TPM LockoutInterval.\r | |
377 | \r | |
378 | This function parse the value got from TPM2_GetCapability and return the LockoutInterval.\r | |
379 | \r | |
380 | @param[out] LockoutInterval The LockoutInterval of TPM.\r | |
381 | \r | |
382 | @retval EFI_SUCCESS Operation completed successfully.\r | |
383 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
384 | **/\r | |
385 | EFI_STATUS\r | |
386 | EFIAPI\r | |
387 | Tpm2GetCapabilityLockoutInterval (\r | |
388 | OUT UINT32 *LockoutInterval\r | |
389 | )\r | |
390 | {\r | |
391 | TPMS_CAPABILITY_DATA TpmCap;\r | |
392 | TPMI_YES_NO MoreData;\r | |
393 | EFI_STATUS Status; \r | |
394 | \r | |
395 | Status = Tpm2GetCapability (\r | |
396 | TPM_CAP_TPM_PROPERTIES, \r | |
397 | TPM_PT_LOCKOUT_INTERVAL, \r | |
398 | 1, \r | |
399 | &MoreData, \r | |
400 | &TpmCap\r | |
401 | );\r | |
402 | if (EFI_ERROR (Status)) {\r | |
403 | return Status;\r | |
404 | }\r | |
405 | *LockoutInterval = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
406 | \r | |
407 | return EFI_SUCCESS;\r | |
408 | }\r | |
409 | \r | |
410 | /**\r | |
411 | This command returns the information of TPM InputBufferSize.\r | |
412 | \r | |
413 | This function parse the value got from TPM2_GetCapability and return the InputBufferSize.\r | |
414 | \r | |
415 | @param[out] InputBufferSize The InputBufferSize of TPM.\r | |
416 | the maximum size of a parameter (typically, a TPM2B_MAX_BUFFER)\r | |
417 | \r | |
418 | @retval EFI_SUCCESS Operation completed successfully.\r | |
419 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
420 | **/\r | |
421 | EFI_STATUS\r | |
422 | EFIAPI\r | |
423 | Tpm2GetCapabilityInputBufferSize (\r | |
424 | OUT UINT32 *InputBufferSize\r | |
425 | )\r | |
426 | {\r | |
427 | TPMS_CAPABILITY_DATA TpmCap;\r | |
428 | TPMI_YES_NO MoreData;\r | |
429 | EFI_STATUS Status; \r | |
430 | \r | |
431 | Status = Tpm2GetCapability (\r | |
432 | TPM_CAP_TPM_PROPERTIES, \r | |
433 | TPM_PT_INPUT_BUFFER, \r | |
434 | 1, \r | |
435 | &MoreData, \r | |
436 | &TpmCap\r | |
437 | );\r | |
438 | if (EFI_ERROR (Status)) {\r | |
439 | return Status;\r | |
440 | }\r | |
441 | *InputBufferSize = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
442 | \r | |
443 | return EFI_SUCCESS;\r | |
444 | }\r | |
445 | \r | |
446 | /**\r | |
447 | This command returns the information of TPM PCRs.\r | |
448 | \r | |
449 | This function parse the value got from TPM2_GetCapability and return the PcrSelection.\r | |
450 | \r | |
451 | @param[out] Pcrs The Pcr Selection\r | |
452 | \r | |
453 | @retval EFI_SUCCESS Operation completed successfully.\r | |
454 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
455 | **/\r | |
456 | EFI_STATUS\r | |
457 | EFIAPI\r | |
458 | Tpm2GetCapabilityPcrs (\r | |
459 | OUT TPML_PCR_SELECTION *Pcrs\r | |
460 | )\r | |
461 | {\r | |
462 | TPMS_CAPABILITY_DATA TpmCap;\r | |
463 | TPMI_YES_NO MoreData;\r | |
464 | EFI_STATUS Status;\r | |
465 | UINTN Index;\r | |
466 | \r | |
467 | Status = Tpm2GetCapability (\r | |
468 | TPM_CAP_PCRS, \r | |
469 | 0, \r | |
470 | 1, \r | |
471 | &MoreData, \r | |
472 | &TpmCap\r | |
473 | );\r | |
474 | if (EFI_ERROR (Status)) {\r | |
475 | return Status;\r | |
476 | }\r | |
477 | \r | |
478 | Pcrs->count = SwapBytes32 (TpmCap.data.assignedPCR.count);\r | |
479 | for (Index = 0; Index < Pcrs->count; Index++) {\r | |
480 | Pcrs->pcrSelections[Index].hash = SwapBytes16 (TpmCap.data.assignedPCR.pcrSelections[Index].hash);\r | |
481 | Pcrs->pcrSelections[Index].sizeofSelect = TpmCap.data.assignedPCR.pcrSelections[Index].sizeofSelect;\r | |
482 | CopyMem (Pcrs->pcrSelections[Index].pcrSelect, TpmCap.data.assignedPCR.pcrSelections[Index].pcrSelect, Pcrs->pcrSelections[Index].sizeofSelect);\r | |
483 | }\r | |
484 | \r | |
485 | return EFI_SUCCESS;\r | |
486 | }\r | |
487 | \r | |
488 | /**\r | |
489 | This command returns the information of TPM AlgorithmSet.\r | |
490 | \r | |
491 | This function parse the value got from TPM2_GetCapability and return the AlgorithmSet.\r | |
492 | \r | |
493 | @param[out] AlgorithmSet The AlgorithmSet of TPM.\r | |
494 | \r | |
495 | @retval EFI_SUCCESS Operation completed successfully.\r | |
496 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
497 | **/\r | |
498 | EFI_STATUS\r | |
499 | EFIAPI\r | |
500 | Tpm2GetCapabilityAlgorithmSet (\r | |
501 | OUT UINT32 *AlgorithmSet\r | |
502 | )\r | |
503 | {\r | |
504 | TPMS_CAPABILITY_DATA TpmCap;\r | |
505 | TPMI_YES_NO MoreData;\r | |
506 | EFI_STATUS Status; \r | |
507 | \r | |
508 | Status = Tpm2GetCapability (\r | |
509 | TPM_CAP_TPM_PROPERTIES, \r | |
510 | TPM_PT_ALGORITHM_SET, \r | |
511 | 1, \r | |
512 | &MoreData, \r | |
513 | &TpmCap\r | |
514 | );\r | |
515 | if (EFI_ERROR (Status)) {\r | |
516 | return Status;\r | |
517 | }\r | |
518 | *AlgorithmSet = SwapBytes32 (TpmCap.data.tpmProperties.tpmProperty->value);\r | |
519 | \r | |
520 | return EFI_SUCCESS;\r | |
521 | }\r | |
522 | \r | |
523 | /**\r | |
524 | This command is used to check to see if specific combinations of algorithm parameters are supported.\r | |
525 | \r | |
526 | @param[in] Parameters Algorithm parameters to be validated\r | |
527 | \r | |
528 | @retval EFI_SUCCESS Operation completed successfully.\r | |
529 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
530 | **/\r | |
531 | EFI_STATUS\r | |
532 | EFIAPI\r | |
533 | Tpm2TestParms (\r | |
534 | IN TPMT_PUBLIC_PARMS *Parameters\r | |
535 | )\r | |
536 | {\r | |
537 | EFI_STATUS Status;\r | |
538 | TPM2_TEST_PARMS_COMMAND SendBuffer;\r | |
539 | TPM2_TEST_PARMS_RESPONSE RecvBuffer;\r | |
540 | UINT32 SendBufferSize;\r | |
541 | UINT32 RecvBufferSize;\r | |
542 | UINT8 *Buffer;\r | |
543 | \r | |
544 | //\r | |
545 | // Construct command\r | |
546 | //\r | |
547 | SendBuffer.Header.tag = SwapBytes16(TPM_ST_NO_SESSIONS);\r | |
548 | SendBuffer.Header.commandCode = SwapBytes32(TPM_CC_TestParms);\r | |
549 | \r | |
550 | Buffer = (UINT8 *)&SendBuffer.Parameters;\r | |
551 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->type));\r | |
552 | Buffer += sizeof(UINT16);\r | |
553 | switch (Parameters->type) {\r | |
554 | case TPM_ALG_KEYEDHASH:\r | |
555 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.keyedHashDetail.scheme.scheme));\r | |
556 | Buffer += sizeof(UINT16);\r | |
557 | switch (Parameters->parameters.keyedHashDetail.scheme.scheme) {\r | |
558 | case TPM_ALG_HMAC:\r | |
559 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.keyedHashDetail.scheme.details.hmac.hashAlg));\r | |
560 | Buffer += sizeof(UINT16);\r | |
561 | break;\r | |
562 | case TPM_ALG_XOR:\r | |
563 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.keyedHashDetail.scheme.details.xor.hashAlg));\r | |
564 | Buffer += sizeof(UINT16);\r | |
565 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.keyedHashDetail.scheme.details.xor.kdf));\r | |
566 | Buffer += sizeof(UINT16);\r | |
567 | break;\r | |
568 | default:\r | |
569 | return EFI_INVALID_PARAMETER;\r | |
570 | }\r | |
571 | case TPM_ALG_SYMCIPHER:\r | |
572 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.symDetail.algorithm));\r | |
573 | Buffer += sizeof(UINT16);\r | |
574 | switch (Parameters->parameters.symDetail.algorithm) {\r | |
575 | case TPM_ALG_AES:\r | |
576 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.symDetail.keyBits.aes));\r | |
577 | Buffer += sizeof(UINT16);\r | |
578 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.symDetail.mode.aes));\r | |
579 | Buffer += sizeof(UINT16);\r | |
580 | break;\r | |
581 | case TPM_ALG_SM4:\r | |
582 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.symDetail.keyBits.SM4));\r | |
583 | Buffer += sizeof(UINT16);\r | |
584 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.symDetail.mode.SM4));\r | |
585 | Buffer += sizeof(UINT16);\r | |
586 | break;\r | |
587 | case TPM_ALG_XOR:\r | |
588 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.symDetail.keyBits.xor));\r | |
589 | Buffer += sizeof(UINT16);\r | |
590 | break;\r | |
591 | case TPM_ALG_NULL:\r | |
592 | break;\r | |
593 | default:\r | |
594 | return EFI_INVALID_PARAMETER;\r | |
595 | }\r | |
596 | break;\r | |
597 | case TPM_ALG_RSA:\r | |
598 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.symmetric.algorithm));\r | |
599 | Buffer += sizeof(UINT16);\r | |
600 | switch (Parameters->parameters.rsaDetail.symmetric.algorithm) {\r | |
601 | case TPM_ALG_AES:\r | |
602 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.symmetric.keyBits.aes));\r | |
603 | Buffer += sizeof(UINT16);\r | |
604 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.symmetric.mode.aes));\r | |
605 | Buffer += sizeof(UINT16);\r | |
606 | break;\r | |
607 | case TPM_ALG_SM4:\r | |
608 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.symmetric.keyBits.SM4));\r | |
609 | Buffer += sizeof(UINT16);\r | |
610 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.symmetric.mode.SM4));\r | |
611 | Buffer += sizeof(UINT16);\r | |
612 | break;\r | |
613 | case TPM_ALG_NULL:\r | |
614 | break;\r | |
615 | default:\r | |
616 | return EFI_INVALID_PARAMETER;\r | |
617 | }\r | |
618 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.scheme.scheme));\r | |
619 | Buffer += sizeof(UINT16);\r | |
620 | switch (Parameters->parameters.rsaDetail.scheme.scheme) {\r | |
621 | case TPM_ALG_RSASSA:\r | |
622 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.scheme.details.rsassa.hashAlg));\r | |
623 | Buffer += sizeof(UINT16);\r | |
624 | break;\r | |
625 | case TPM_ALG_RSAPSS:\r | |
626 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.scheme.details.rsapss.hashAlg));\r | |
627 | Buffer += sizeof(UINT16);\r | |
628 | break;\r | |
629 | case TPM_ALG_RSAES:\r | |
630 | break;\r | |
631 | case TPM_ALG_OAEP:\r | |
632 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.scheme.details.oaep.hashAlg));\r | |
633 | Buffer += sizeof(UINT16);\r | |
634 | break;\r | |
635 | case TPM_ALG_NULL:\r | |
636 | break;\r | |
637 | default:\r | |
638 | return EFI_INVALID_PARAMETER;\r | |
639 | }\r | |
640 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.rsaDetail.keyBits));\r | |
641 | Buffer += sizeof(UINT16);\r | |
642 | WriteUnaligned32 ((UINT32 *)Buffer, SwapBytes32 (Parameters->parameters.rsaDetail.exponent));\r | |
643 | Buffer += sizeof(UINT32);\r | |
644 | break;\r | |
645 | case TPM_ALG_ECC:\r | |
646 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.symmetric.algorithm));\r | |
647 | Buffer += sizeof(UINT16);\r | |
648 | switch (Parameters->parameters.eccDetail.symmetric.algorithm) {\r | |
649 | case TPM_ALG_AES:\r | |
650 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.symmetric.keyBits.aes));\r | |
651 | Buffer += sizeof(UINT16);\r | |
652 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.symmetric.mode.aes));\r | |
653 | Buffer += sizeof(UINT16);\r | |
654 | break;\r | |
655 | case TPM_ALG_SM4:\r | |
656 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.symmetric.keyBits.SM4));\r | |
657 | Buffer += sizeof(UINT16);\r | |
658 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.symmetric.mode.SM4));\r | |
659 | Buffer += sizeof(UINT16);\r | |
660 | break;\r | |
661 | case TPM_ALG_NULL:\r | |
662 | break;\r | |
663 | default:\r | |
664 | return EFI_INVALID_PARAMETER;\r | |
665 | }\r | |
666 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.scheme.scheme));\r | |
667 | Buffer += sizeof(UINT16);\r | |
668 | switch (Parameters->parameters.eccDetail.scheme.scheme) {\r | |
669 | case TPM_ALG_ECDSA:\r | |
670 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.scheme.details.ecdsa.hashAlg));\r | |
671 | Buffer += sizeof(UINT16);\r | |
672 | break;\r | |
673 | case TPM_ALG_ECDAA:\r | |
674 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.scheme.details.ecdaa.hashAlg));\r | |
675 | Buffer += sizeof(UINT16);\r | |
676 | break;\r | |
677 | case TPM_ALG_ECSCHNORR:\r | |
678 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.scheme.details.ecSchnorr.hashAlg));\r | |
679 | Buffer += sizeof(UINT16);\r | |
680 | break;\r | |
681 | case TPM_ALG_ECDH:\r | |
682 | break;\r | |
683 | case TPM_ALG_NULL:\r | |
684 | break;\r | |
685 | default:\r | |
686 | return EFI_INVALID_PARAMETER;\r | |
687 | }\r | |
688 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.curveID));\r | |
689 | Buffer += sizeof(UINT16);\r | |
690 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.kdf.scheme));\r | |
691 | Buffer += sizeof(UINT16);\r | |
692 | switch (Parameters->parameters.eccDetail.kdf.scheme) {\r | |
693 | case TPM_ALG_MGF1:\r | |
694 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.kdf.details.mgf1.hashAlg));\r | |
695 | Buffer += sizeof(UINT16);\r | |
696 | break;\r | |
697 | case TPM_ALG_KDF1_SP800_108:\r | |
698 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.kdf.details.kdf1_sp800_108.hashAlg));\r | |
699 | Buffer += sizeof(UINT16);\r | |
700 | break;\r | |
701 | case TPM_ALG_KDF1_SP800_56a:\r | |
702 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.kdf.details.kdf1_SP800_56a.hashAlg));\r | |
703 | Buffer += sizeof(UINT16);\r | |
704 | break;\r | |
705 | case TPM_ALG_KDF2:\r | |
706 | WriteUnaligned16 ((UINT16 *)Buffer, SwapBytes16 (Parameters->parameters.eccDetail.kdf.details.kdf2.hashAlg));\r | |
707 | Buffer += sizeof(UINT16);\r | |
708 | break;\r | |
709 | case TPM_ALG_NULL:\r | |
710 | break;\r | |
711 | default:\r | |
712 | return EFI_INVALID_PARAMETER;\r | |
713 | }\r | |
714 | break;\r | |
715 | default:\r | |
716 | return EFI_INVALID_PARAMETER;\r | |
717 | }\r | |
718 | \r | |
719 | SendBufferSize = (UINT32)((UINTN)Buffer - (UINTN)&SendBuffer);\r | |
720 | SendBuffer.Header.paramSize = SwapBytes32 (SendBufferSize);\r | |
721 | \r | |
722 | //\r | |
723 | // send Tpm command\r | |
724 | //\r | |
725 | RecvBufferSize = sizeof (RecvBuffer);\r | |
726 | Status = Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer);\r | |
727 | if (EFI_ERROR (Status)) {\r | |
728 | return Status;\r | |
729 | }\r | |
730 | \r | |
731 | if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {\r | |
732 | DEBUG ((EFI_D_ERROR, "Tpm2TestParms - RecvBufferSize Error - %x\n", RecvBufferSize));\r | |
733 | return EFI_DEVICE_ERROR;\r | |
734 | }\r | |
735 | if (SwapBytes32(RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {\r | |
736 | DEBUG ((EFI_D_ERROR, "Tpm2TestParms - responseCode - %x\n", SwapBytes32(RecvBuffer.Header.responseCode)));\r | |
737 | return EFI_UNSUPPORTED;\r | |
738 | }\r | |
739 | \r | |
740 | return EFI_SUCCESS;\r | |
741 | }\r |