2 Implementation of the HII for the Opal UEFI Driver.
4 Copyright (c) 2016, 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.
16 #include "OpalDriver.h"
17 #include "OpalHiiPrivate.h"
20 // This is the generated IFR binary Data for each formset defined in VFR.
21 // This Data array is ready to be used as input of HiiAddPackages() to
22 // create a packagelist (which contains Form packages, String packages, etc).
24 extern UINT8 OpalPasswordFormBin
[];
27 // This is the generated String package Data for all .UNI files.
28 // This Data array is ready to be used as input of HiiAddPackages() to
29 // create a packagelist (which contains Form packages, String packages, etc).
31 extern UINT8 OpalPasswordDxeStrings
[];
33 CHAR16 OpalPasswordStorageName
[] = L
"OpalHiiConfig";
35 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol
;
38 // Handle to the list of HII packages (forms and strings) for this driver
40 EFI_HII_HANDLE gHiiPackageListHandle
= NULL
;
43 // Package List GUID containing all form and string packages
45 const EFI_GUID gHiiPackageListGuid
= PACKAGE_LIST_GUID
;
46 const EFI_GUID gHiiSetupVariableGuid
= SETUP_VARIABLE_GUID
;
49 // Structure that contains state of the HII
50 // This structure is updated by Hii.cpp and its contents
51 // is rendered in the HII.
53 OPAL_HII_CONFIGURATION gHiiConfiguration
;
55 CHAR8 gHiiOldPassword
[MAX_PASSWORD_CHARACTER_LENGTH
] = {0};
56 UINT32 gHiiOldPasswordLength
= 0;
59 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
61 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath
= {
67 (UINT8
)(sizeof(VENDOR_DEVICE_PATH
)),
68 (UINT8
)((sizeof(VENDOR_DEVICE_PATH
)) >> 8)
71 OPAL_PASSWORD_CONFIG_GUID
75 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
77 (UINT8
)(END_DEVICE_PATH_LENGTH
),
78 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
85 Sets the current system state of global config variables.
89 HiiSetCurrentConfiguration(
96 gHiiConfiguration
.NumDisks
= GetDeviceCount();
99 // Update the BlockSID status string.
101 PpStorageFlag
= TcgPhysicalPresenceStorageLibReturnStorageFlags();
103 if ((PpStorageFlag
& TCG_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID
) != 0) {
104 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_ENABLED
), NULL
);
105 if (NewString
== NULL
) {
106 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
110 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISABLED
), NULL
);
111 if (NewString
== NULL
) {
112 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
116 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS1
), NewString
, NULL
);
117 FreePool (NewString
);
119 if ((PpStorageFlag
& TCG_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID
) != 0) {
120 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_TRUE
), NULL
);
121 if (NewString
== NULL
) {
122 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
126 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_FALSE
), NULL
);
127 if (NewString
== NULL
) {
128 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
132 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS2
), NewString
, NULL
);
133 FreePool (NewString
);
135 if ((PpStorageFlag
& TCG_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID
) != 0) {
136 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_TRUE
), NULL
);
137 if (NewString
== NULL
) {
138 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
142 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_FALSE
), NULL
);
143 if (NewString
== NULL
) {
144 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
148 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS3
), NewString
, NULL
);
149 FreePool (NewString
);
153 Install the HII related resources.
155 @retval EFI_SUCCESS Install all the resources success.
156 @retval other Error occur when install the resources.
164 EFI_HANDLE DriverHandle
;
167 // Clear the global configuration.
169 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
172 // Obtain the driver handle that the BIOS assigned us
174 DriverHandle
= HiiGetDriverImageHandleCB();
177 // Populate the config access protocol with the three functions we are publishing
179 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
180 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
181 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
184 // Associate the required protocols with our driver handle
186 Status
= gBS
->InstallMultipleProtocolInterfaces(
188 &gEfiHiiConfigAccessProtocolGuid
,
189 &gHiiConfigAccessProtocol
, // HII callback
190 &gEfiDevicePathProtocolGuid
,
191 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
195 if (EFI_ERROR(Status
)) {
199 return OpalHiiAddPackages();
203 Install the HII form and string packages.
205 @retval EFI_SUCCESS Install all the resources success.
206 @retval EFI_OUT_OF_RESOURCES Out of resource error.
213 EFI_HANDLE DriverHandle
;
216 DriverHandle
= HiiGetDriverImageHandleCB();
219 // Publish the HII form and HII string packages
221 gHiiPackageListHandle
= HiiAddPackages(
222 &gHiiPackageListGuid
,
224 OpalPasswordDxeStrings
,
230 // Make sure the packages installed successfully
232 if (gHiiPackageListHandle
== NULL
) {
233 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
234 return EFI_OUT_OF_RESOURCES
;
238 // Update Version String in main window
240 NewString
= HiiGetDriverNameCB ();
241 if (HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_MAIN_OPAL_VERSION
), NewString
, NULL
) == 0) {
242 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
243 return EFI_OUT_OF_RESOURCES
;
250 Uninstall the HII capability.
252 @retval EFI_SUCCESS Uninstall all the resources success.
253 @retval others Other errors occur when unistall the hii resource.
263 // Remove the packages we've provided to the BIOS
265 HiiRemovePackages(gHiiPackageListHandle
);
268 // Remove the protocols from our driver handle
270 Status
= gBS
->UninstallMultipleProtocolInterfaces(
271 HiiGetDriverImageHandleCB(),
272 &gEfiHiiConfigAccessProtocolGuid
,
273 &gHiiConfigAccessProtocol
, // HII callback
274 &gEfiDevicePathProtocolGuid
,
275 &gHiiVendorDevicePath
, // required for HII callback
278 if (EFI_ERROR(Status
)) {
279 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
286 Updates the main menu form.
288 @retval EFI_SUCCESS update the main form success.
291 HiiPopulateMainMenuForm (
297 EFI_STRING_ID DiskNameId
;
300 HiiSetCurrentConfiguration();
302 gHiiConfiguration
.SupportedDisks
= 0;
304 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
305 OpalDisk
= HiiGetOpalDiskCB (Index
);
306 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
307 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
308 DiskNameId
= GetDiskNameStringId (Index
);
309 DiskName
= HiiDiskGetNameCB (Index
);
310 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
311 return EFI_UNSUPPORTED
;
313 HiiSetFormString(DiskNameId
, DiskName
);
317 OpalHiiSetBrowserData ();
322 Update the disk action info.
325 @param SelectedAction
327 @retval EFI_SUCCESS Uninstall all the resources success.
330 HiiSelectDiskAction (
336 OPAL_DISK_ACTIONS AvailActions
;
338 OpalHiiGetBrowserData ();
340 HiiSetFormString(STRING_TOKEN(STR_DISK_ACTION_LBL
), ActionString
);
341 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), " ");
343 gHiiConfiguration
.SelectedAction
= SelectedAction
;
344 gHiiConfiguration
.AvailableFields
= 0;
346 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
347 if (OpalDisk
== NULL
) {
348 return EFI_INVALID_PARAMETER
;
351 if (OpalSupportGetAvailableActions (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
) != TcgResultSuccess
) {
352 return EFI_DEVICE_ERROR
;
355 switch (SelectedAction
) {
356 case HII_KEY_ID_GOTO_LOCK
:
357 case HII_KEY_ID_GOTO_UNLOCK
:
358 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
359 case HII_KEY_ID_GOTO_SET_USER_PWD
:
360 case HII_KEY_ID_GOTO_SECURE_ERASE
:
361 case HII_KEY_ID_GOTO_DISABLE_USER
:
362 case HII_KEY_ID_GOTO_ENABLE_FEATURE
: // User is required to enter Password to enable Feature
363 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
366 case HII_KEY_ID_GOTO_PSID_REVERT
:
367 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PSID
;
370 case HII_KEY_ID_GOTO_REVERT
:
371 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
372 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA
;
373 if (AvailActions
.RevertKeepDataForced
) {
374 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA_FORCED
;
379 OpalHiiSetBrowserData ();
385 Get disk name string id.
387 @param DiskIndex The input disk index info.
389 @retval The disk name string id.
398 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
399 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
400 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
401 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
402 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
403 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
409 This function processes the results of changes in configuration.
411 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
412 @param Action Specifies the type of action taken by the browser.
413 @param QuestionId A unique value which is sent to the original
414 exporting driver so that it can identify the type
416 @param Type The type of value for the question.
417 @param Value A pointer to the data being sent to the original
419 @param ActionRequest On return, points to the action requested by the
422 @retval EFI_SUCCESS The callback successfully handled the action.
423 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
424 variable and its data.
425 @retval EFI_DEVICE_ERROR The variable could not be saved.
426 @retval EFI_UNSUPPORTED The specified Action is not supported by the
433 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
434 EFI_BROWSER_ACTION Action
,
435 EFI_QUESTION_ID QuestionId
,
437 EFI_IFR_TYPE_VALUE
*Value
,
438 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
445 if (ActionRequest
!= NULL
) {
446 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
448 return EFI_INVALID_PARAMETER
;
452 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
454 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
458 HiiKey
.Raw
= QuestionId
;
459 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
461 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
463 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
464 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
465 return HiiPopulateMainMenuForm ();
467 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
468 return HiiPopulateDiskInfoForm();
470 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
472 case HII_KEY_ID_GOTO_DISK_INFO
:
473 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
475 case HII_KEY_ID_GOTO_LOCK
:
476 return HiiSelectDiskAction("Action: Lock", HiiKeyId
);
478 case HII_KEY_ID_GOTO_UNLOCK
:
479 return HiiSelectDiskAction("Action: Unlock", HiiKeyId
);
481 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
482 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId
);
484 case HII_KEY_ID_GOTO_SET_USER_PWD
:
485 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId
);
487 case HII_KEY_ID_GOTO_SECURE_ERASE
:
488 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId
);
490 case HII_KEY_ID_GOTO_PSID_REVERT
:
491 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId
);
493 case HII_KEY_ID_GOTO_REVERT
:
494 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId
);
496 case HII_KEY_ID_GOTO_DISABLE_USER
:
497 return HiiSelectDiskAction("Action: Disable User", HiiKeyId
);
499 case HII_KEY_ID_GOTO_ENABLE_FEATURE
:
500 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId
);
502 case HII_KEY_ID_ENTER_PASSWORD
:
503 return HiiPasswordEntered(Value
->string
);
505 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
507 case HII_KEY_ID_ENTER_PSID
:
509 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
512 case HII_KEY_ID_BLOCKSID
:
515 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
519 PpRequest
= TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID
;
523 PpRequest
= TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID
;
527 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE
;
531 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE
;
535 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE
;
539 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE
;
543 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
544 DEBUG ((DEBUG_ERROR
, "Invalid value input!\n"));
547 HiiSetBlockSidAction(PpRequest
);
549 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
557 return EFI_UNSUPPORTED
;
561 Update the global Disk index info.
563 @param Index The input disk index info.
565 @retval EFI_SUCCESS Update the disk index info success.
573 OpalHiiGetBrowserData();
574 gHiiConfiguration
.SelectedDiskIndex
= Index
;
575 OpalHiiSetBrowserData ();
581 Draws the disk info form.
583 @retval EFI_SUCCESS Draw the disk info success.
587 HiiPopulateDiskInfoForm(
592 OPAL_DISK_ACTIONS AvailActions
;
596 OpalHiiGetBrowserData();
598 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
599 if (DiskName
== NULL
) {
600 return EFI_UNSUPPORTED
;
602 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
604 ZeroMem(gHiiConfiguration
.Psid
, sizeof(gHiiConfiguration
.Psid
));
606 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
608 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
610 if (OpalDisk
!= NULL
) {
611 OpalDiskUpdateStatus (OpalDisk
);
612 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
613 if (Ret
== TcgResultSuccess
) {
615 // Update actions, always allow PSID Revert
617 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
620 // Always allow unlock to handle device migration
622 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
624 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
625 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
626 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
631 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
633 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
636 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
637 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
638 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
639 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
640 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
642 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
645 // Determine revert options for disk
646 // Default initialize keep user Data to be true
648 gHiiConfiguration
.KeepUserData
= 1;
654 // Pass the current configuration to the BIOS
656 OpalHiiSetBrowserData ();
662 Reverts the Opal disk to factory default.
664 @retval EFI_SUCCESS Do the required action success.
672 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
676 OPAL_SESSION Session
;
677 UINT8 TmpBuf
[PSID_CHARACTER_STRING_END_LENGTH
];
679 Ret
= TcgResultFailure
;
681 OpalHiiGetBrowserData();
683 ZeroMem (TmpBuf
, sizeof (TmpBuf
));
684 UnicodeStrToAsciiStrS (gHiiConfiguration
.Psid
, (CHAR8
*)TmpBuf
, PSID_CHARACTER_STRING_END_LENGTH
);
685 CopyMem (Psid
.Psid
, TmpBuf
, PSID_CHARACTER_LENGTH
);
687 OpalDisk
= HiiGetOpalDiskCB (gHiiConfiguration
.SelectedDiskIndex
);
688 if (OpalDisk
!= NULL
) {
689 ZeroMem(&Session
, sizeof(Session
));
690 Session
.Sscp
= OpalDisk
->Sscp
;
691 Session
.MediaId
= OpalDisk
->MediaId
;
692 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
694 Ret
= OpalSupportPsidRevert(&Session
, Psid
.Psid
, (UINT32
)sizeof(Psid
.Psid
), OpalDisk
->OpalDevicePath
);
697 if (Ret
== TcgResultSuccess
) {
698 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Success" );
700 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Failure" );
703 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
709 Set password for the disk.
711 @param OpalDisk The disk need to set the password.
712 @param Password The input password.
713 @param PassLength The input password length.
715 @retval EFI_SUCCESS Do the required action success.
725 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
727 BOOLEAN ExistingPassword
;
728 OPAL_SESSION Session
;
730 ExistingPassword
= FALSE
;
733 // PassLength = 0 means check whether exist old password.
735 if (PassLength
== 0) {
736 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
737 gHiiOldPasswordLength
= 0;
739 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_ENABLE_FEATURE
) {
740 ExistingPassword
= FALSE
;
741 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_ADMIN_PWD
) {
742 ExistingPassword
= OpalUtilAdminPasswordExists(OpalDisk
->Owner
, &OpalDisk
->LockingFeature
);
743 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
745 // Set user Password option shall only be shown if an Admin Password exists
746 // so a Password is always required (Admin or Existing User Password)
748 ExistingPassword
= TRUE
;
752 // Return error if there is a previous Password
753 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
755 return ExistingPassword
? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
758 ZeroMem(&Session
, sizeof(Session
));
759 Session
.Sscp
= OpalDisk
->Sscp
;
760 Session
.MediaId
= OpalDisk
->MediaId
;
761 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
763 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Failure");
766 // No current Owner, so set new Password, must be admin Password
768 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
769 Ret
= OpalSupportEnableOpalFeature (&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
,Password
, PassLength
, OpalDisk
->OpalDevicePath
);
770 if (Ret
== TcgResultSuccess
) {
771 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
774 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
779 // 1st Password entered
781 if (OpalDisk
->Owner
== OpalOwnershipUnknown
&& gHiiOldPasswordLength
== 0) {
784 // Unknown ownership - prompt for old Password, then new
785 // old Password is not set yet - first time through
786 // assume authority provided is admin1, overwritten if user1 authority works below
788 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
790 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
792 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_USER1_AUTHORITY
);
793 if (Ret
== TcgResultSuccess
) {
795 // User1 worked so authority 1 means user 1
797 CopyMem(gHiiOldPassword
, Password
, PassLength
);
798 gHiiOldPasswordLength
= PassLength
;
805 // Else try admin1 below
807 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_ADMIN1_AUTHORITY
);
808 if (Ret
== TcgResultSuccess
) {
809 CopyMem(gHiiOldPassword
, Password
, PassLength
);
810 gHiiOldPasswordLength
= PassLength
;
814 DEBUG ((DEBUG_INFO
, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
815 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Authentication Failure");
817 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
818 gHiiOldPasswordLength
= 0;
820 return EFI_NOT_READY
;
825 // New Password entered
827 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
828 Ret
= OpalSupportSetPassword(
831 gHiiOldPasswordLength
,
834 OpalDisk
->OpalDevicePath
,
838 Ret
= OpalSupportSetPassword(
841 gHiiOldPasswordLength
,
844 OpalDisk
->OpalDevicePath
,
849 if (Ret
== TcgResultSuccess
) {
850 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
854 // Reset old Password storage
856 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
857 gHiiOldPasswordLength
= 0;
859 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
860 return Ret
== TcgResultSuccess
? EFI_SUCCESS
: EFI_NOT_READY
;
864 Secure Erases Opal Disk.
866 @param OpalDisk The disk need to erase data.
867 @param Password The input password.
868 @param PassLength The input password length.
870 @retval EFI_SUCCESS Do the required action success.
876 const VOID
*Password
,
880 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
881 BOOLEAN PasswordFailed
;
883 OPAL_SESSION AdminSpSession
;
885 if (PassLength
== 0) {
886 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
889 ZeroMem(&AdminSpSession
, sizeof(AdminSpSession
));
890 AdminSpSession
.Sscp
= OpalDisk
->Sscp
;
891 AdminSpSession
.MediaId
= OpalDisk
->MediaId
;
892 AdminSpSession
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
894 Ret
= OpalUtilSecureErase(&AdminSpSession
, Password
, PassLength
, &PasswordFailed
);
895 if (Ret
== TcgResultSuccess
) {
896 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Success" );
898 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Failure" );
900 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
903 // If Password failed, return invalid passowrd
905 if (PasswordFailed
) {
906 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
907 return EFI_NOT_READY
;
911 // Indicates Password was valid and is not changing to UEFI
912 // Response string will indicate action error
914 return EFI_DEVICE_ERROR
;
919 Disables User for Opal Disk.
921 @param OpalDisk The disk need to the action.
922 @param Password The input password.
923 @param PassLength The input password length.
925 @retval EFI_SUCCESS Do the required action success.
935 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
936 BOOLEAN PasswordFailed
;
938 OPAL_SESSION Session
;
940 if (PassLength
== 0) {
941 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
944 ZeroMem(&Session
, sizeof(Session
));
945 Session
.Sscp
= OpalDisk
->Sscp
;
946 Session
.MediaId
= OpalDisk
->MediaId
;
947 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
949 Ret
= OpalSupportDisableUser(&Session
, Password
, PassLength
, &PasswordFailed
, OpalDisk
->OpalDevicePath
);
950 if (Ret
== TcgResultSuccess
) {
951 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Success" );
953 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Failure" );
955 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS
), Response
);
958 // If Password failed, return invalid passowrd
960 if (PasswordFailed
) {
961 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
962 return EFI_NOT_READY
;
966 // Indicates Password was valid and is not changing to UEFI
967 // Response string will indicate action error
969 return EFI_DEVICE_ERROR
;
973 Revert Opal Disk as Admin1.
975 @param OpalDisk The disk need to the action.
976 @param Password The input password.
977 @param PassLength The input password length.
978 @param KeepUserData Whether need to keey user data.
980 @retval EFI_SUCCESS Do the required action success.
991 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
992 BOOLEAN PasswordFailed
;
994 OPAL_SESSION Session
;
996 if (PassLength
== 0) {
997 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
998 // return error to indicate there is an existing Password
999 return EFI_DEVICE_ERROR
;
1002 ZeroMem(&Session
, sizeof(Session
));
1003 Session
.Sscp
= OpalDisk
->Sscp
;
1004 Session
.MediaId
= OpalDisk
->MediaId
;
1005 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1007 Ret
= OpalSupportRevert(
1013 OpalDisk
->MsidLength
,
1015 OpalDisk
->OpalDevicePath
1017 if (Ret
== TcgResultSuccess
) {
1018 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Success" );
1020 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Failure" );
1022 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1025 // If Password failed, return invalid passowrd
1027 if (PasswordFailed
) {
1028 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1029 return EFI_NOT_READY
;
1033 // Indicates Password was valid and is not changing to UEFI
1034 // Response string will indicate action error
1036 return EFI_DEVICE_ERROR
;
1042 @param OpalDisk The disk need to the action.
1043 @param Password The input password.
1044 @param PassLength The input password length.
1046 @retval EFI_SUCCESS Do the required action success.
1051 OPAL_DISK
*OpalDisk
,
1056 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
1058 OPAL_SESSION Session
;
1060 if (PassLength
== 0) {
1061 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
1062 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
1065 ZeroMem(&Session
, sizeof(Session
));
1066 Session
.Sscp
= OpalDisk
->Sscp
;
1067 Session
.MediaId
= OpalDisk
->MediaId
;
1068 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1070 Ret
= OpalSupportUnlock(&Session
, Password
, PassLength
, OpalDisk
->OpalDevicePath
);
1071 if (Ret
== TcgResultSuccess
) {
1072 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Success" );
1074 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Failure" );
1077 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1079 if (Ret
== TcgResultSuccess
) {
1080 DEBUG ((DEBUG_INFO
, "returning error to indicate Password was correct but is not changing\n"));
1081 return EFI_DEVICE_ERROR
;
1083 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1084 return EFI_NOT_READY
;
1089 Use the input password to do the specified action.
1091 @param Str The input password saved in.
1093 @retval EFI_SUCCESS Do the required action success.
1094 @retval Others Other error occur.
1102 OPAL_DISK
* OpalDisk
;
1103 CHAR8 Password
[MAX_PASSWORD_CHARACTER_LENGTH
+ 1];
1108 OpalHiiGetBrowserData();
1110 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
1111 if (OpalDisk
== NULL
) {
1112 DEBUG ((DEBUG_INFO
, "ERROR: disk %u not found\n", gHiiConfiguration
.SelectedDiskIndex
));
1113 return EFI_NOT_FOUND
;
1117 DEBUG ((DEBUG_INFO
, "ERROR: str=NULL\n"));
1118 return EFI_INVALID_PARAMETER
;
1121 ZeroMem(Password
, sizeof(Password
));
1123 UniStr
= HiiGetString(gHiiPackageListHandle
, Str
, NULL
);
1124 if (UniStr
== NULL
) {
1125 return EFI_NOT_FOUND
;
1127 PassLength
= (UINT32
) StrLen (UniStr
);
1128 if (PassLength
>= sizeof(Password
)) {
1129 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Password too long");
1130 gBS
->FreePool(UniStr
);
1131 return EFI_BUFFER_TOO_SMALL
;
1134 UnicodeStrToAsciiStrS (UniStr
, Password
, sizeof (Password
));
1135 gBS
->FreePool(UniStr
);
1137 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_UNLOCK
) {
1138 Status
= HiiUnlock (OpalDisk
, Password
, PassLength
);
1139 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SECURE_ERASE
) {
1140 Status
= HiiSecureErase (OpalDisk
, Password
, PassLength
);
1141 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_DISABLE_USER
) {
1142 Status
= HiiDisableUser (OpalDisk
, Password
, PassLength
);
1143 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_REVERT
) {
1144 if (OpalDisk
->SupportedAttributes
.PyriteSsc
== 1 && OpalDisk
->LockingFeature
.MediaEncryption
== 0) {
1146 // For pyrite type device which also not supports media encryption, it not accept "Keep User Data" parameter.
1147 // So here hardcode a FALSE for this case.
1149 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, FALSE
);
1151 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, gHiiConfiguration
.KeepUserData
);
1154 Status
= HiiSetPassword(OpalDisk
, Password
, PassLength
);
1157 OpalHiiSetBrowserData ();
1163 Update block sid info.
1165 @param Enable Enable/disable BlockSid.
1167 @retval EFI_SUCCESS Do the required action success.
1168 @retval Others Other error occur.
1172 HiiSetBlockSidAction (
1180 // Process TCG Physical Presence request just after trusted console is ready
1181 // Platform can connect trusted consoles and then call the below function.
1183 ReturnCode
= TcgPhysicalPresenceStorageLibSubmitRequestToPreOSFunction (PpRequest
, 0);
1184 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1185 Status
= EFI_SUCCESS
;
1186 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1187 Status
= EFI_OUT_OF_RESOURCES
;
1188 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1189 Status
= EFI_UNSUPPORTED
;
1191 Status
= EFI_DEVICE_ERROR
;
1198 This function processes the results of changes in configuration.
1200 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1201 @param Configuration A null-terminated Unicode string in <ConfigResp>
1203 @param Progress A pointer to a string filled in with the offset of
1204 the most recent '&' before the first failing
1205 name/value pair (or the beginning of the string if
1206 the failure is in the first name/value pair) or
1207 the terminating NULL if all was successful.
1209 @retval EFI_SUCCESS The Results is processed successfully.
1210 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1211 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1218 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1219 CONST EFI_STRING Configuration
,
1220 EFI_STRING
*Progress
1223 if (Configuration
== NULL
|| Progress
== NULL
) {
1224 return (EFI_INVALID_PARAMETER
);
1227 *Progress
= Configuration
;
1228 if (!HiiIsConfigHdrMatch (Configuration
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1229 return EFI_NOT_FOUND
;
1232 *Progress
= Configuration
+ StrLen (Configuration
);
1238 This function allows a caller to extract the current configuration for one
1239 or more named elements from the target driver.
1241 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1242 @param Request A null-terminated Unicode string in
1243 <ConfigRequest> format.
1244 @param Progress On return, points to a character in the Request
1245 string. Points to the string's null terminator if
1246 request was successful. Points to the most recent
1247 '&' before the first failing name/value pair (or
1248 the beginning of the string if the failure is in
1249 the first name/value pair) if the request was not
1251 @param Results A null-terminated Unicode string in
1252 <ConfigAltResp> format which has all values filled
1253 in for the names in the Request string. String to
1254 be allocated by the called function.
1256 @retval EFI_SUCCESS The Results is filled with the requested values.
1257 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1258 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1259 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1266 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1267 CONST EFI_STRING Request
,
1268 EFI_STRING
*Progress
,
1275 // Check for valid parameters
1277 if (Progress
== NULL
|| Results
== NULL
) {
1278 return (EFI_INVALID_PARAMETER
);
1281 *Progress
= Request
;
1282 if ((Request
!= NULL
) &&
1283 !HiiIsConfigHdrMatch (Request
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1284 return EFI_NOT_FOUND
;
1288 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1290 Status
= gHiiConfigRouting
->BlockToConfig(
1293 (UINT8
*)&gHiiConfiguration
,
1294 sizeof(OPAL_HII_CONFIGURATION
),
1305 Pass the current system state to the bios via the hii_G_Configuration.
1309 OpalHiiSetBrowserData (
1314 &gHiiSetupVariableGuid
,
1315 (CHAR16
*)L
"OpalHiiConfig",
1316 sizeof(gHiiConfiguration
),
1317 (UINT8
*)&gHiiConfiguration
,
1325 Populate the hii_g_Configuraton with the browser Data.
1329 OpalHiiGetBrowserData (
1334 &gHiiSetupVariableGuid
,
1335 (CHAR16
*)L
"OpalHiiConfig",
1336 sizeof(gHiiConfiguration
),
1337 (UINT8
*)&gHiiConfiguration
1342 Set a string Value in a form.
1344 @param DestStringId The stringid which need to update.
1345 @param SrcAsciiStr The string nned to update.
1347 @retval EFI_SUCCESS Do the required action success.
1348 @retval Others Other error occur.
1353 EFI_STRING_ID DestStringId
,
1362 // Determine the Length of the sting
1364 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1367 // Allocate space for the unicode string, including terminator
1369 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1370 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1373 // Copy into unicode string, then copy into string id
1375 AsciiStrToUnicodeStrS ( SrcAsciiStr
, UniStr
, Len
+ 1);
1378 // Update the string in the form
1380 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1381 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1383 return (EFI_OUT_OF_RESOURCES
);
1391 return (EFI_SUCCESS
);
1395 Initialize the Opal disk base on the hardware info get from device.
1397 @param Dev The Opal device.
1399 @retval EFI_SUCESS Initialize the device success.
1400 @retval EFI_DEVICE_ERROR Get info from device failed.
1404 OpalDiskInitialize (
1405 IN OPAL_DRIVER_DEVICE
*Dev
1408 TCG_RESULT TcgResult
;
1409 OPAL_SESSION Session
;
1411 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1412 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1413 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1414 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1416 ZeroMem(&Session
, sizeof(Session
));
1417 Session
.Sscp
= Dev
->Sscp
;
1418 Session
.MediaId
= Dev
->MediaId
;
1420 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1421 if (TcgResult
!= TcgResultSuccess
) {
1422 return EFI_DEVICE_ERROR
;
1424 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1426 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1427 if (TcgResult
!= TcgResultSuccess
) {
1428 return EFI_DEVICE_ERROR
;
1431 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1435 Update the device info.
1437 @param OpalDisk The Opal device.
1439 @retval EFI_SUCESS Initialize the device success.
1440 @retval EFI_DEVICE_ERROR Get info from device failed.
1441 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1445 OpalDiskUpdateStatus (
1449 TCG_RESULT TcgResult
;
1450 OPAL_SESSION Session
;
1452 ZeroMem(&Session
, sizeof(Session
));
1453 Session
.Sscp
= OpalDisk
->Sscp
;
1454 Session
.MediaId
= OpalDisk
->MediaId
;
1455 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1457 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1458 if (TcgResult
!= TcgResultSuccess
) {
1459 return EFI_DEVICE_ERROR
;
1462 if (OpalDisk
->MsidLength
== 0) {
1463 return EFI_INVALID_PARAMETER
;
1466 // Base on the Msid info to get the ownership, so Msid info must get first.
1468 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);