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 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol
;
36 // Handle to the list of HII packages (forms and strings) for this driver
38 EFI_HII_HANDLE gHiiPackageListHandle
= NULL
;
41 // Package List GUID containing all form and string packages
43 const EFI_GUID gHiiPackageListGuid
= PACKAGE_LIST_GUID
;
44 const EFI_GUID gHiiSetupVariableGuid
= SETUP_VARIABLE_GUID
;
47 // Structure that contains state of the HII
48 // This structure is updated by Hii.cpp and its contents
49 // is rendered in the HII.
51 OPAL_HII_CONFIGURATION gHiiConfiguration
;
53 CHAR8 gHiiOldPassword
[MAX_PASSWORD_CHARACTER_LENGTH
] = {0};
54 UINT32 gHiiOldPasswordLength
= 0;
57 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
59 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath
= {
65 (UINT8
)(sizeof(VENDOR_DEVICE_PATH
)),
66 (UINT8
)((sizeof(VENDOR_DEVICE_PATH
)) >> 8)
69 OPAL_PASSWORD_CONFIG_GUID
73 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
75 (UINT8
)(END_DEVICE_PATH_LENGTH
),
76 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
83 Sets the current system state of global config variables.
87 HiiSetCurrentConfiguration(
92 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
95 gHiiConfiguration
.NumDisks
= GetDeviceCount();
97 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
98 Status
= gRT
->GetVariable (
99 OPAL_EXTRA_INFO_VAR_NAME
,
100 &gOpalExtraInfoVariableGuid
,
105 DEBUG ((DEBUG_INFO
, "GetVariable for OpalExtraInfo @ HiiSetCurrentConfiguration, Status: %r\n", Status
));
106 if (!EFI_ERROR (Status
)) {
107 gHiiConfiguration
.EnableBlockSid
= OpalExtraInfo
.EnableBlockSid
;
112 Check that all required protocols for HII are available.
114 @retval EFI_SUCCESS All required protocols are installed.
115 @retval EFI_NOT_FOUND One or more protocol are not installed.
118 HiiCheckForRequiredProtocols (
125 Status
= gBS
->LocateProtocol(&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
126 if (EFI_ERROR (Status
)) {
127 return EFI_NOT_FOUND
;
130 Status
= gBS
->LocateProtocol(&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
131 if (EFI_ERROR (Status
)) {
132 return EFI_NOT_FOUND
;
135 Status
= gBS
->LocateProtocol(&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
136 if (EFI_ERROR (Status
)) {
137 return EFI_NOT_FOUND
;
140 Status
= gBS
->LocateProtocol(&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
141 if (EFI_ERROR (Status
)) {
142 return EFI_NOT_FOUND
;
149 Install the HII related resources.
151 @retval EFI_SUCCESS Install all the resources success.
152 @retval other Error occur when install the resources.
160 EFI_HANDLE DriverHandle
;
163 // Check that all required protocols are available for HII.
164 // If not, fail the install
166 Status
= HiiCheckForRequiredProtocols();
167 if (EFI_ERROR(Status
)) {
172 // Clear the global configuration.
174 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
177 // Obtain the driver handle that the BIOS assigned us
179 DriverHandle
= HiiGetDriverImageHandleCB();
182 // Populate the config access protocol with the three functions we are publishing
184 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
185 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
186 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
189 // Associate the required protocols with our driver handle
191 Status
= gBS
->InstallMultipleProtocolInterfaces(
193 &gEfiHiiConfigAccessProtocolGuid
,
194 &gHiiConfigAccessProtocol
, // HII callback
195 &gEfiDevicePathProtocolGuid
,
196 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
200 if (EFI_ERROR(Status
)) {
204 return OpalHiiAddPackages();
208 Install the HII form and string packages.
210 @retval EFI_SUCCESS Install all the resources success.
211 @retval EFI_OUT_OF_RESOURCES Out of resource error.
218 EFI_HANDLE DriverHandle
;
221 DriverHandle
= HiiGetDriverImageHandleCB();
224 // Publish the HII form and HII string packages
226 gHiiPackageListHandle
= HiiAddPackages(
227 &gHiiPackageListGuid
,
229 OpalPasswordDxeStrings
,
235 // Make sure the packages installed successfully
237 if (gHiiPackageListHandle
== NULL
) {
238 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
239 return EFI_OUT_OF_RESOURCES
;
243 // Update Version String in main window
245 NewString
= HiiGetDriverNameCB ();
246 if (HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_MAIN_OPAL_VERSION
), NewString
, NULL
) == 0) {
247 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
248 return EFI_OUT_OF_RESOURCES
;
255 Uninstall the HII capability.
257 @retval EFI_SUCCESS Uninstall all the resources success.
258 @retval others Other errors occur when unistall the hii resource.
268 // Remove the packages we've provided to the BIOS
270 HiiRemovePackages(gHiiPackageListHandle
);
273 // Remove the protocols from our driver handle
275 Status
= gBS
->UninstallMultipleProtocolInterfaces(
276 HiiGetDriverImageHandleCB(),
277 &gEfiHiiConfigAccessProtocolGuid
,
278 &gHiiConfigAccessProtocol
, // HII callback
279 &gEfiDevicePathProtocolGuid
,
280 &gHiiVendorDevicePath
, // required for HII callback
283 if (EFI_ERROR(Status
)) {
284 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
291 Updates the main menu form.
293 @retval EFI_SUCCESS update the main form success.
296 HiiPopulateMainMenuForm (
302 EFI_STRING_ID DiskNameId
;
305 HiiSetCurrentConfiguration();
307 gHiiConfiguration
.SupportedDisks
= 0;
309 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
310 OpalDisk
= HiiGetOpalDiskCB (Index
);
311 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
312 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
313 DiskNameId
= GetDiskNameStringId (Index
);
314 DiskName
= HiiDiskGetNameCB (Index
);
315 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
316 return EFI_UNSUPPORTED
;
318 HiiSetFormString(DiskNameId
, DiskName
);
322 OpalHiiSetBrowserData ();
327 Update the disk action info.
330 @param SelectedAction
332 @retval EFI_SUCCESS Uninstall all the resources success.
335 HiiSelectDiskAction (
341 OPAL_DISK_ACTIONS AvailActions
;
343 OpalHiiGetBrowserData ();
345 HiiSetFormString(STRING_TOKEN(STR_DISK_ACTION_LBL
), ActionString
);
346 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), " ");
348 gHiiConfiguration
.SelectedAction
= SelectedAction
;
349 gHiiConfiguration
.AvailableFields
= 0;
351 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
352 if (OpalDisk
== NULL
) {
353 return EFI_INVALID_PARAMETER
;
356 if (OpalSupportGetAvailableActions (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
) != TcgResultSuccess
) {
357 return EFI_DEVICE_ERROR
;
360 switch (SelectedAction
) {
361 case HII_KEY_ID_GOTO_LOCK
:
362 case HII_KEY_ID_GOTO_UNLOCK
:
363 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
364 case HII_KEY_ID_GOTO_SET_USER_PWD
:
365 case HII_KEY_ID_GOTO_SECURE_ERASE
:
366 case HII_KEY_ID_GOTO_DISABLE_USER
:
367 case HII_KEY_ID_GOTO_ENABLE_FEATURE
: // User is required to enter Password to enable Feature
368 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
371 case HII_KEY_ID_GOTO_PSID_REVERT
:
372 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PSID
;
375 case HII_KEY_ID_GOTO_REVERT
:
376 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
377 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA
;
378 if (AvailActions
.RevertKeepDataForced
) {
379 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA_FORCED
;
384 OpalHiiSetBrowserData ();
390 Get disk name string id.
392 @param DiskIndex The input disk index info.
394 @retval The disk name string id.
403 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
404 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
405 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
406 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
407 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
408 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
414 This function processes the results of changes in configuration.
416 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
417 @param Action Specifies the type of action taken by the browser.
418 @param QuestionId A unique value which is sent to the original
419 exporting driver so that it can identify the type
421 @param Type The type of value for the question.
422 @param Value A pointer to the data being sent to the original
424 @param ActionRequest On return, points to the action requested by the
427 @retval EFI_SUCCESS The callback successfully handled the action.
428 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
429 variable and its data.
430 @retval EFI_DEVICE_ERROR The variable could not be saved.
431 @retval EFI_UNSUPPORTED The specified Action is not supported by the
438 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
439 EFI_BROWSER_ACTION Action
,
440 EFI_QUESTION_ID QuestionId
,
442 EFI_IFR_TYPE_VALUE
*Value
,
443 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
449 if (ActionRequest
!= NULL
) {
450 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
452 return EFI_INVALID_PARAMETER
;
456 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
458 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
462 HiiKey
.Raw
= QuestionId
;
463 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
465 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
467 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
468 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
469 return HiiPopulateMainMenuForm ();
471 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
472 return HiiPopulateDiskInfoForm();
474 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
476 case HII_KEY_ID_GOTO_DISK_INFO
:
477 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
479 case HII_KEY_ID_GOTO_LOCK
:
480 return HiiSelectDiskAction("Action: Lock", HiiKeyId
);
482 case HII_KEY_ID_GOTO_UNLOCK
:
483 return HiiSelectDiskAction("Action: Unlock", HiiKeyId
);
485 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
486 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId
);
488 case HII_KEY_ID_GOTO_SET_USER_PWD
:
489 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId
);
491 case HII_KEY_ID_GOTO_SECURE_ERASE
:
492 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId
);
494 case HII_KEY_ID_GOTO_PSID_REVERT
:
495 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId
);
497 case HII_KEY_ID_GOTO_REVERT
:
498 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId
);
500 case HII_KEY_ID_GOTO_DISABLE_USER
:
501 return HiiSelectDiskAction("Action: Disable User", HiiKeyId
);
503 case HII_KEY_ID_GOTO_ENABLE_FEATURE
:
504 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId
);
506 case HII_KEY_ID_ENTER_PASSWORD
:
507 return HiiPasswordEntered(Value
->string
);
509 case HII_KEY_ID_BLOCKSID
:
510 return HiiSetBlockSid(Value
->b
);
512 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
514 case HII_KEY_ID_ENTER_PSID
:
516 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
521 return EFI_UNSUPPORTED
;
525 Update the global Disk index info.
527 @param Index The input disk index info.
529 @retval EFI_SUCCESS Update the disk index info success.
537 OpalHiiGetBrowserData();
538 gHiiConfiguration
.SelectedDiskIndex
= Index
;
539 OpalHiiSetBrowserData ();
545 Draws the disk info form.
547 @retval EFI_SUCCESS Draw the disk info success.
551 HiiPopulateDiskInfoForm(
556 OPAL_DISK_ACTIONS AvailActions
;
560 OpalHiiGetBrowserData();
562 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
563 if (DiskName
== NULL
) {
564 return EFI_UNSUPPORTED
;
566 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
568 ZeroMem(gHiiConfiguration
.Psid
, sizeof(gHiiConfiguration
.Psid
));
570 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
572 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
574 if (OpalDisk
!= NULL
) {
575 OpalDiskUpdateStatus (OpalDisk
);
576 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
577 if (Ret
== TcgResultSuccess
) {
579 // Update actions, always allow PSID Revert
581 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
584 // Always allow unlock to handle device migration
586 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
588 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
589 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
590 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
595 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
597 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
600 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
601 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
602 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
603 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
604 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
605 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_BLOCKSID
;
607 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
610 // Determine revert options for disk
611 // Default initialize keep user Data to be true
613 gHiiConfiguration
.KeepUserData
= 1;
619 // Pass the current configuration to the BIOS
621 OpalHiiSetBrowserData ();
627 Reverts the Opal disk to factory default.
629 @retval EFI_SUCCESS Do the required action success.
637 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
641 OPAL_SESSION Session
;
643 Ret
= TcgResultFailure
;
645 OpalHiiGetBrowserData();
647 UnicodeStrToAsciiStr(gHiiConfiguration
.Psid
, (CHAR8
*)Psid
.Psid
);
649 OpalDisk
= HiiGetOpalDiskCB (gHiiConfiguration
.SelectedDiskIndex
);
650 if (OpalDisk
!= NULL
) {
651 ZeroMem(&Session
, sizeof(Session
));
652 Session
.Sscp
= OpalDisk
->Sscp
;
653 Session
.MediaId
= OpalDisk
->MediaId
;
654 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
656 Ret
= OpalSupportPsidRevert(&Session
, Psid
.Psid
, (UINT32
)sizeof(Psid
.Psid
), OpalDisk
->OpalDevicePath
);
659 if (Ret
== TcgResultSuccess
) {
660 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Success" );
662 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Failure" );
665 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
671 Set password for the disk.
673 @param OpalDisk The disk need to set the password.
674 @param Password The input password.
675 @param PassLength The input password length.
677 @retval EFI_SUCCESS Do the required action success.
687 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
689 BOOLEAN ExistingPassword
;
690 OPAL_SESSION Session
;
692 ExistingPassword
= FALSE
;
695 // PassLength = 0 means check whether exist old password.
697 if (PassLength
== 0) {
698 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
699 gHiiOldPasswordLength
= 0;
701 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_ENABLE_FEATURE
) {
702 ExistingPassword
= FALSE
;
703 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_ADMIN_PWD
) {
704 ExistingPassword
= OpalUtilAdminPasswordExists(OpalDisk
->Owner
, &OpalDisk
->LockingFeature
);
705 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
707 // Set user Password option shall only be shown if an Admin Password exists
708 // so a Password is always required (Admin or Existing User Password)
710 ExistingPassword
= TRUE
;
714 // Return error if there is a previous Password
715 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
717 return ExistingPassword
? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
720 ZeroMem(&Session
, sizeof(Session
));
721 Session
.Sscp
= OpalDisk
->Sscp
;
722 Session
.MediaId
= OpalDisk
->MediaId
;
723 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
725 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Failure");
728 // No current Owner, so set new Password, must be admin Password
730 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
731 Ret
= OpalSupportEnableOpalFeature (&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
,Password
, PassLength
, OpalDisk
->OpalDevicePath
);
732 if (Ret
== TcgResultSuccess
) {
733 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
736 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
741 // 1st Password entered
743 if (OpalDisk
->Owner
== OpalOwnershipUnknown
&& gHiiOldPasswordLength
== 0) {
746 // Unknown ownership - prompt for old Password, then new
747 // old Password is not set yet - first time through
748 // assume authority provided is admin1, overwritten if user1 authority works below
750 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
752 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
754 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_USER1_AUTHORITY
);
755 if (Ret
== TcgResultSuccess
) {
757 // User1 worked so authority 1 means user 1
759 CopyMem(gHiiOldPassword
, Password
, PassLength
);
760 gHiiOldPasswordLength
= PassLength
;
767 // Else try admin1 below
769 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_ADMIN1_AUTHORITY
);
770 if (Ret
== TcgResultSuccess
) {
771 CopyMem(gHiiOldPassword
, Password
, PassLength
);
772 gHiiOldPasswordLength
= PassLength
;
776 DEBUG ((DEBUG_INFO
, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
777 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Authentication Failure");
779 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
780 gHiiOldPasswordLength
= 0;
782 return EFI_NOT_READY
;
787 // New Password entered
789 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
790 Ret
= OpalSupportSetPassword(
793 gHiiOldPasswordLength
,
796 OpalDisk
->OpalDevicePath
,
800 Ret
= OpalSupportSetPassword(
803 gHiiOldPasswordLength
,
806 OpalDisk
->OpalDevicePath
,
811 if (Ret
== TcgResultSuccess
) {
812 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
816 // Reset old Password storage
818 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
819 gHiiOldPasswordLength
= 0;
821 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
822 return Ret
== TcgResultSuccess
? EFI_SUCCESS
: EFI_NOT_READY
;
826 Secure Erases Opal Disk.
828 @param OpalDisk The disk need to erase data.
829 @param Password The input password.
830 @param PassLength The input password length.
832 @retval EFI_SUCCESS Do the required action success.
838 const VOID
*Password
,
842 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
843 BOOLEAN PasswordFailed
;
845 OPAL_SESSION AdminSpSession
;
847 if (PassLength
== 0) {
848 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
851 ZeroMem(&AdminSpSession
, sizeof(AdminSpSession
));
852 AdminSpSession
.Sscp
= OpalDisk
->Sscp
;
853 AdminSpSession
.MediaId
= OpalDisk
->MediaId
;
854 AdminSpSession
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
856 Ret
= OpalUtilSecureErase(&AdminSpSession
, Password
, PassLength
, &PasswordFailed
);
857 if (Ret
== TcgResultSuccess
) {
858 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Success" );
860 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Failure" );
862 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
865 // If Password failed, return invalid passowrd
867 if (PasswordFailed
) {
868 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
869 return EFI_NOT_READY
;
873 // Indicates Password was valid and is not changing to UEFI
874 // Response string will indicate action error
876 return EFI_DEVICE_ERROR
;
881 Disables User for Opal Disk.
883 @param OpalDisk The disk need to the action.
884 @param Password The input password.
885 @param PassLength The input password length.
887 @retval EFI_SUCCESS Do the required action success.
897 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
898 BOOLEAN PasswordFailed
;
900 OPAL_SESSION Session
;
902 if (PassLength
== 0) {
903 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
906 ZeroMem(&Session
, sizeof(Session
));
907 Session
.Sscp
= OpalDisk
->Sscp
;
908 Session
.MediaId
= OpalDisk
->MediaId
;
909 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
911 Ret
= OpalSupportDisableUser(&Session
, Password
, PassLength
, &PasswordFailed
, OpalDisk
->OpalDevicePath
);
912 if (Ret
== TcgResultSuccess
) {
913 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Success" );
915 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Failure" );
917 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS
), Response
);
920 // If Password failed, return invalid passowrd
922 if (PasswordFailed
) {
923 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
924 return EFI_NOT_READY
;
928 // Indicates Password was valid and is not changing to UEFI
929 // Response string will indicate action error
931 return EFI_DEVICE_ERROR
;
935 Revert Opal Disk as Admin1.
937 @param OpalDisk The disk need to the action.
938 @param Password The input password.
939 @param PassLength The input password length.
940 @param KeepUserData Whether need to keey user data.
942 @retval EFI_SUCCESS Do the required action success.
953 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
954 BOOLEAN PasswordFailed
;
956 OPAL_SESSION Session
;
958 if (PassLength
== 0) {
959 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
960 // return error to indicate there is an existing Password
961 return EFI_DEVICE_ERROR
;
964 ZeroMem(&Session
, sizeof(Session
));
965 Session
.Sscp
= OpalDisk
->Sscp
;
966 Session
.MediaId
= OpalDisk
->MediaId
;
967 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
969 Ret
= OpalSupportRevert(
975 OpalDisk
->MsidLength
,
977 OpalDisk
->OpalDevicePath
979 if (Ret
== TcgResultSuccess
) {
980 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Success" );
982 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Failure" );
984 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
987 // If Password failed, return invalid passowrd
989 if (PasswordFailed
) {
990 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
991 return EFI_NOT_READY
;
995 // Indicates Password was valid and is not changing to UEFI
996 // Response string will indicate action error
998 return EFI_DEVICE_ERROR
;
1004 @param OpalDisk The disk need to the action.
1005 @param Password The input password.
1006 @param PassLength The input password length.
1008 @retval EFI_SUCCESS Do the required action success.
1013 OPAL_DISK
*OpalDisk
,
1018 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
1020 OPAL_SESSION Session
;
1022 if (PassLength
== 0) {
1023 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
1024 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
1027 ZeroMem(&Session
, sizeof(Session
));
1028 Session
.Sscp
= OpalDisk
->Sscp
;
1029 Session
.MediaId
= OpalDisk
->MediaId
;
1030 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1032 Ret
= OpalSupportUnlock(&Session
, Password
, PassLength
, OpalDisk
->OpalDevicePath
);
1033 if (Ret
== TcgResultSuccess
) {
1034 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Success" );
1036 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Failure" );
1039 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1041 if (Ret
== TcgResultSuccess
) {
1042 DEBUG ((DEBUG_INFO
, "returning error to indicate Password was correct but is not changing\n"));
1043 return EFI_DEVICE_ERROR
;
1045 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1046 return EFI_NOT_READY
;
1051 Use the input password to do the specified action.
1053 @param Str The input password saved in.
1055 @retval EFI_SUCCESS Do the required action success.
1056 @retval Others Other error occur.
1064 OPAL_DISK
* OpalDisk
;
1065 CHAR8 Password
[MAX_PASSWORD_CHARACTER_LENGTH
+ 1];
1070 OpalHiiGetBrowserData();
1072 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
1073 if (OpalDisk
== NULL
) {
1074 DEBUG ((DEBUG_INFO
, "ERROR: disk %u not found\n", gHiiConfiguration
.SelectedDiskIndex
));
1075 return EFI_NOT_FOUND
;
1079 DEBUG ((DEBUG_INFO
, "ERROR: str=NULL\n"));
1080 return EFI_INVALID_PARAMETER
;
1083 ZeroMem(Password
, sizeof(Password
));
1085 UniStr
= HiiGetString(gHiiPackageListHandle
, Str
, NULL
);
1086 if (UniStr
== NULL
) {
1087 return EFI_NOT_FOUND
;
1089 PassLength
= (UINT32
) StrLen (UniStr
);
1090 if (PassLength
>= sizeof(Password
)) {
1091 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Password too long");
1092 gBS
->FreePool(UniStr
);
1093 return EFI_BUFFER_TOO_SMALL
;
1096 UnicodeStrToAsciiStr(UniStr
, Password
);
1097 gBS
->FreePool(UniStr
);
1099 DEBUG ((DEBUG_INFO
, "Password: '%s'\n", Password
));
1101 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_UNLOCK
) {
1102 Status
= HiiUnlock (OpalDisk
, Password
, PassLength
);
1103 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SECURE_ERASE
) {
1104 Status
= HiiSecureErase (OpalDisk
, Password
, PassLength
);
1105 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_DISABLE_USER
) {
1106 Status
= HiiDisableUser (OpalDisk
, Password
, PassLength
);
1107 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_REVERT
) {
1108 DEBUG ((DEBUG_INFO
, "gHiiConfiguration.KeepUserData %u\n", gHiiConfiguration
.KeepUserData
));
1109 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, gHiiConfiguration
.KeepUserData
);
1111 Status
= HiiSetPassword(OpalDisk
, Password
, PassLength
);
1114 OpalHiiSetBrowserData ();
1120 Update block sid info.
1122 @param Enable Enable/disable BlockSid.
1124 @retval EFI_SUCCESS Do the required action success.
1125 @retval Others Other error occur.
1134 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
1137 Status
= EFI_SUCCESS
;
1139 DEBUG ((DEBUG_INFO
, "HiiSetBlockSid(enable: %x)\n", Enable
));
1141 OpalExtraInfo
.EnableBlockSid
= Enable
;
1142 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
1143 Status
= gRT
->SetVariable (
1144 OPAL_EXTRA_INFO_VAR_NAME
,
1145 &gOpalExtraInfoVariableGuid
,
1146 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1150 DEBUG ((DEBUG_INFO
, "SetVariable, Status: %r\n", Status
));
1156 This function processes the results of changes in configuration.
1158 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1159 @param Configuration A null-terminated Unicode string in <ConfigResp>
1161 @param Progress A pointer to a string filled in with the offset of
1162 the most recent '&' before the first failing
1163 name/value pair (or the beginning of the string if
1164 the failure is in the first name/value pair) or
1165 the terminating NULL if all was successful.
1167 @retval EFI_SUCCESS The Results is processed successfully.
1168 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1169 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1176 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1177 CONST EFI_STRING Configuration
,
1178 EFI_STRING
*Progress
1181 DEBUG ((DEBUG_INFO
, "RouteConfig( )\n"));
1182 if (Configuration
== NULL
|| Progress
== NULL
) {
1183 return (EFI_INVALID_PARAMETER
);
1190 This function allows a caller to extract the current configuration for one
1191 or more named elements from the target driver.
1193 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1194 @param Request A null-terminated Unicode string in
1195 <ConfigRequest> format.
1196 @param Progress On return, points to a character in the Request
1197 string. Points to the string's null terminator if
1198 request was successful. Points to the most recent
1199 '&' before the first failing name/value pair (or
1200 the beginning of the string if the failure is in
1201 the first name/value pair) if the request was not
1203 @param Results A null-terminated Unicode string in
1204 <ConfigAltResp> format which has all values filled
1205 in for the names in the Request string. String to
1206 be allocated by the called function.
1208 @retval EFI_SUCCESS The Results is filled with the requested values.
1209 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1210 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
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 Request
,
1220 EFI_STRING
*Progress
,
1226 DEBUG ((DEBUG_INFO
, "ExtractConfig( )\n"));
1229 // Check for valid parameters
1231 if (Progress
== NULL
|| Results
== NULL
) {
1232 return (EFI_INVALID_PARAMETER
);
1236 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1238 Status
= gHiiConfigRouting
->BlockToConfig(
1241 (UINT8
*)&gHiiConfiguration
,
1242 sizeof(OPAL_HII_CONFIGURATION
),
1253 Pass the current system state to the bios via the hii_G_Configuration.
1257 OpalHiiSetBrowserData (
1261 DEBUG ((DEBUG_INFO
, "OpalHiiSetBrowserData( )\n"));
1263 &gHiiSetupVariableGuid
,
1264 (CHAR16
*)L
"OpalHiiConfig",
1265 sizeof(gHiiConfiguration
),
1266 (UINT8
*)&gHiiConfiguration
,
1274 Populate the hii_g_Configuraton with the browser Data.
1278 OpalHiiGetBrowserData (
1282 DEBUG ((DEBUG_INFO
, "OpalHiiGetBrowserData( )\n"));
1284 &gHiiSetupVariableGuid
,
1285 (CHAR16
*)L
"OpalHiiConfig",
1286 sizeof(gHiiConfiguration
),
1287 (UINT8
*)&gHiiConfiguration
1292 Set a string Value in a form.
1294 @param DestStringId The stringid which need to update.
1295 @param SrcAsciiStr The string nned to update.
1297 @retval EFI_SUCCESS Do the required action success.
1298 @retval Others Other error occur.
1303 EFI_STRING_ID DestStringId
,
1311 DEBUG ((DEBUG_INFO
, "HiiSetFormString( )\n"));
1314 // Determine the Length of the sting
1316 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1319 // Allocate space for the unicode string, including terminator
1321 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1322 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1325 // Copy into unicode string, then copy into string id
1327 AsciiStrToUnicodeStr( SrcAsciiStr
, UniStr
);
1330 // Update the string in the form
1332 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1333 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1335 return (EFI_OUT_OF_RESOURCES
);
1343 return (EFI_SUCCESS
);
1347 Initialize the Opal disk base on the hardware info get from device.
1349 @param Dev The Opal device.
1351 @retval EFI_SUCESS Initialize the device success.
1352 @retval EFI_DEVICE_ERROR Get info from device failed.
1356 OpalDiskInitialize (
1357 IN OPAL_DRIVER_DEVICE
*Dev
1360 TCG_RESULT TcgResult
;
1361 OPAL_SESSION Session
;
1363 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1364 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1365 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1366 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1368 ZeroMem(&Session
, sizeof(Session
));
1369 Session
.Sscp
= Dev
->Sscp
;
1370 Session
.MediaId
= Dev
->MediaId
;
1372 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1373 if (TcgResult
!= TcgResultSuccess
) {
1374 return EFI_DEVICE_ERROR
;
1376 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1378 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1379 if (TcgResult
!= TcgResultSuccess
) {
1380 return EFI_DEVICE_ERROR
;
1383 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1387 Update the device info.
1389 @param OpalDisk The Opal device.
1391 @retval EFI_SUCESS Initialize the device success.
1392 @retval EFI_DEVICE_ERROR Get info from device failed.
1393 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1397 OpalDiskUpdateStatus (
1401 TCG_RESULT TcgResult
;
1402 OPAL_SESSION Session
;
1404 ZeroMem(&Session
, sizeof(Session
));
1405 Session
.Sscp
= OpalDisk
->Sscp
;
1406 Session
.MediaId
= OpalDisk
->MediaId
;
1407 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1409 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1410 if (TcgResult
!= TcgResultSuccess
) {
1411 return EFI_DEVICE_ERROR
;
1414 if (OpalDisk
->MsidLength
== 0) {
1415 return EFI_INVALID_PARAMETER
;
1418 // Base on the Msid info to get the ownership, so Msid info must get first.
1420 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);