2 HII Config Access protocol implementation of TCG configuration module.
4 Copyright (c) 2011 - 2014, 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 "TcgConfigImpl.h"
17 CHAR16 mTcgStorageName
[] = L
"TCG_CONFIGURATION";
19 TCG_CONFIG_PRIVATE_DATA mTcgConfigPrivateDateTemplate
= {
20 TCG_CONFIG_PRIVATE_DATA_SIGNATURE
,
28 HII_VENDOR_DEVICE_PATH mTcgHiiVendorDevicePath
= {
34 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
35 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
38 TCG_CONFIG_FORM_SET_GUID
42 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
44 (UINT8
) (END_DEVICE_PATH_LENGTH
),
45 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
51 Get current state of TPM device.
53 @param[in] TcgProtocol Point to EFI_TCG_PROTOCOL instance.
54 @param[out] TpmEnable Flag to indicate TPM is enabled or not.
55 @param[out] TpmActivate Flag to indicate TPM is activated or not.
57 @retval EFI_SUCCESS State is successfully returned.
58 @retval EFI_DEVICE_ERROR Failed to get TPM response.
59 @retval Others Other errors as indicated.
64 IN EFI_TCG_PROTOCOL
*TcgProtocol
,
65 OUT BOOLEAN
*TpmEnable
, OPTIONAL
66 OUT BOOLEAN
*TpmActivate OPTIONAL
70 TPM_RSP_COMMAND_HDR
*TpmRsp
;
72 TPM_PERMANENT_FLAGS
*TpmPermanentFlags
;
75 ASSERT (TcgProtocol
!= NULL
);
78 // Get TPM Permanent flags (TpmEnable, TpmActivate)
80 if ((TpmEnable
!= NULL
) || (TpmActivate
!= NULL
)) {
81 TpmSendSize
= sizeof (TPM_RQU_COMMAND_HDR
) + sizeof (UINT32
) * 3;
82 *(UINT16
*)&CmdBuf
[0] = SwapBytes16 (TPM_TAG_RQU_COMMAND
);
83 *(UINT32
*)&CmdBuf
[2] = SwapBytes32 (TpmSendSize
);
84 *(UINT32
*)&CmdBuf
[6] = SwapBytes32 (TPM_ORD_GetCapability
);
86 *(UINT32
*)&CmdBuf
[10] = SwapBytes32 (TPM_CAP_FLAG
);
87 *(UINT32
*)&CmdBuf
[14] = SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMANENT
));
88 *(UINT32
*)&CmdBuf
[18] = SwapBytes32 (TPM_CAP_FLAG_PERMANENT
);
90 Status
= TcgProtocol
->PassThroughToTpm (
97 TpmRsp
= (TPM_RSP_COMMAND_HDR
*) &CmdBuf
[0];
98 if (EFI_ERROR (Status
) || (TpmRsp
->tag
!= SwapBytes16 (TPM_TAG_RSP_COMMAND
)) || (TpmRsp
->returnCode
!= 0)) {
99 return EFI_DEVICE_ERROR
;
102 TpmPermanentFlags
= (TPM_PERMANENT_FLAGS
*) &CmdBuf
[sizeof (TPM_RSP_COMMAND_HDR
) + sizeof (UINT32
)];
104 if (TpmEnable
!= NULL
) {
105 *TpmEnable
= (BOOLEAN
) !TpmPermanentFlags
->disable
;
108 if (TpmActivate
!= NULL
) {
109 *TpmActivate
= (BOOLEAN
) !TpmPermanentFlags
->deactivated
;
117 This function allows a caller to extract the current configuration for one
118 or more named elements from the target driver.
120 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
121 @param[in] Request A null-terminated Unicode string in
122 <ConfigRequest> format.
123 @param[out] Progress On return, points to a character in the Request
124 string. Points to the string's null terminator if
125 request was successful. Points to the most recent
126 '&' before the first failing name/value pair (or
127 the beginning of the string if the failure is in
128 the first name/value pair) if the request was not
130 @param[out] Results A null-terminated Unicode string in
131 <ConfigAltResp> format which has all values filled
132 in for the names in the Request string. String to
133 be allocated by the called function.
135 @retval EFI_SUCCESS The Results is filled with the requested values.
136 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
137 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
138 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
145 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
146 IN CONST EFI_STRING Request
,
147 OUT EFI_STRING
*Progress
,
148 OUT EFI_STRING
*Results
153 TCG_CONFIGURATION Configuration
;
154 TCG_CONFIG_PRIVATE_DATA
*PrivateData
;
155 EFI_STRING ConfigRequestHdr
;
156 EFI_STRING ConfigRequest
;
157 BOOLEAN AllocatedRequest
;
163 if (Progress
== NULL
|| Results
== NULL
) {
164 return EFI_INVALID_PARAMETER
;
168 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &gTcgConfigFormSetGuid
, mTcgStorageName
)) {
169 return EFI_NOT_FOUND
;
172 ConfigRequestHdr
= NULL
;
173 ConfigRequest
= NULL
;
174 AllocatedRequest
= FALSE
;
177 PrivateData
= TCG_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
180 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
182 ZeroMem (&Configuration
, sizeof (TCG_CONFIGURATION
));
184 Configuration
.TpmOperation
= PHYSICAL_PRESENCE_ENABLE
;
187 // Display current TPM state.
189 if (PrivateData
->TcgProtocol
!= NULL
) {
190 Status
= GetTpmState (PrivateData
->TcgProtocol
, &TpmEnable
, &TpmActivate
);
191 if (EFI_ERROR (Status
)) {
199 TpmEnable
? L
"Enabled" : L
"Disabled",
200 TpmActivate
? L
"Activated" : L
"Deactivated"
202 Configuration
.TpmEnable
= TpmEnable
;
203 Configuration
.TpmActivate
= TpmActivate
;
205 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM_STATE_CONTENT
), State
, NULL
);
208 BufferSize
= sizeof (Configuration
);
209 ConfigRequest
= Request
;
210 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
212 // Request has no request element, construct full request string.
213 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
214 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
216 ConfigRequestHdr
= HiiConstructConfigHdr (&gTcgConfigFormSetGuid
, mTcgStorageName
, PrivateData
->DriverHandle
);
217 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
218 ConfigRequest
= AllocateZeroPool (Size
);
219 ASSERT (ConfigRequest
!= NULL
);
220 AllocatedRequest
= TRUE
;
221 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
) BufferSize
);
222 FreePool (ConfigRequestHdr
);
225 Status
= gHiiConfigRouting
->BlockToConfig (
228 (UINT8
*) &Configuration
,
234 // Free the allocated config request string.
236 if (AllocatedRequest
) {
237 FreePool (ConfigRequest
);
240 // Set Progress string to the original request string.
242 if (Request
== NULL
) {
244 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
245 *Progress
= Request
+ StrLen (Request
);
252 This function processes the results of changes in configuration.
254 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
255 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
257 @param[out] Progress A pointer to a string filled in with the offset of
258 the most recent '&' before the first failing
259 name/value pair (or the beginning of the string if
260 the failure is in the first name/value pair) or
261 the terminating NULL if all was successful.
263 @retval EFI_SUCCESS The Results is processed successfully.
264 @retval EFI_INVALID_PARAMETER Configuration is NULL.
265 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
272 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
273 IN CONST EFI_STRING Configuration
,
274 OUT EFI_STRING
*Progress
279 TCG_CONFIGURATION TcgConfiguration
;
281 if (Configuration
== NULL
|| Progress
== NULL
) {
282 return EFI_INVALID_PARAMETER
;
285 *Progress
= Configuration
;
286 if (!HiiIsConfigHdrMatch (Configuration
, &gTcgConfigFormSetGuid
, mTcgStorageName
)) {
287 return EFI_NOT_FOUND
;
291 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
293 BufferSize
= sizeof (TCG_CONFIGURATION
);
294 Status
= gHiiConfigRouting
->ConfigToBlock (
297 (UINT8
*) &TcgConfiguration
,
301 if (EFI_ERROR (Status
)) {
309 Save TPM request to variable space.
311 @param[in] PpRequest Physical Presence request command.
313 @retval EFI_SUCCESS The operation is finished successfully.
314 @retval Others Other errors as indicated.
324 EFI_PHYSICAL_PRESENCE PpData
;
327 // Save TPM command to variable.
329 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
330 Status
= gRT
->GetVariable (
331 PHYSICAL_PRESENCE_VARIABLE
,
332 &gEfiPhysicalPresenceGuid
,
337 if (EFI_ERROR (Status
)) {
341 PpData
.PPRequest
= PpRequest
;
342 Status
= gRT
->SetVariable (
343 PHYSICAL_PRESENCE_VARIABLE
,
344 &gEfiPhysicalPresenceGuid
,
345 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
349 if (EFI_ERROR(Status
)) {
357 This function processes the results of changes in configuration.
359 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
360 @param[in] Action Specifies the type of action taken by the browser.
361 @param[in] QuestionId A unique value which is sent to the original
362 exporting driver so that it can identify the type
364 @param[in] Type The type of value for the question.
365 @param[in] Value A pointer to the data being sent to the original
367 @param[out] ActionRequest On return, points to the action requested by the
370 @retval EFI_SUCCESS The callback successfully handled the action.
371 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
372 variable and its data.
373 @retval EFI_DEVICE_ERROR The variable could not be saved.
374 @retval EFI_UNSUPPORTED The specified Action is not supported by the
381 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
382 IN EFI_BROWSER_ACTION Action
,
383 IN EFI_QUESTION_ID QuestionId
,
385 IN EFI_IFR_TYPE_VALUE
*Value
,
386 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
389 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
390 return EFI_INVALID_PARAMETER
;
393 if ((Action
!= EFI_BROWSER_ACTION_CHANGED
) || (QuestionId
!= KEY_TPM_ACTION
)) {
394 return EFI_UNSUPPORTED
;
397 SavePpRequest (Value
->u8
);
398 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
404 This function publish the TCG configuration Form for TPM device.
406 @param[in, out] PrivateData Points to TCG configuration private data.
408 @retval EFI_SUCCESS HII Form is installed for this network device.
409 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
410 @retval Others Other errors as indicated.
414 InstallTcgConfigForm (
415 IN OUT TCG_CONFIG_PRIVATE_DATA
*PrivateData
419 EFI_HII_HANDLE HiiHandle
;
420 EFI_HANDLE DriverHandle
;
421 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
424 ConfigAccess
= &PrivateData
->ConfigAccess
;
425 Status
= gBS
->InstallMultipleProtocolInterfaces (
427 &gEfiDevicePathProtocolGuid
,
428 &mTcgHiiVendorDevicePath
,
429 &gEfiHiiConfigAccessProtocolGuid
,
433 if (EFI_ERROR (Status
)) {
437 PrivateData
->DriverHandle
= DriverHandle
;
440 // Publish the HII package list
442 HiiHandle
= HiiAddPackages (
443 &gTcgConfigFormSetGuid
,
449 if (HiiHandle
== NULL
) {
450 gBS
->UninstallMultipleProtocolInterfaces (
452 &gEfiDevicePathProtocolGuid
,
453 &mTcgHiiVendorDevicePath
,
454 &gEfiHiiConfigAccessProtocolGuid
,
459 return EFI_OUT_OF_RESOURCES
;
462 PrivateData
->HiiHandle
= HiiHandle
;
468 This function removes TCG configuration Form.
470 @param[in, out] PrivateData Points to TCG configuration private data.
474 UninstallTcgConfigForm (
475 IN OUT TCG_CONFIG_PRIVATE_DATA
*PrivateData
479 // Uninstall HII package list
481 if (PrivateData
->HiiHandle
!= NULL
) {
482 HiiRemovePackages (PrivateData
->HiiHandle
);
483 PrivateData
->HiiHandle
= NULL
;
487 // Uninstall HII Config Access Protocol
489 if (PrivateData
->DriverHandle
!= NULL
) {
490 gBS
->UninstallMultipleProtocolInterfaces (
491 PrivateData
->DriverHandle
,
492 &gEfiDevicePathProtocolGuid
,
493 &mTcgHiiVendorDevicePath
,
494 &gEfiHiiConfigAccessProtocolGuid
,
495 &PrivateData
->ConfigAccess
,
498 PrivateData
->DriverHandle
= NULL
;
501 FreePool (PrivateData
);