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 if (OpalDisk
->SupportedAttributes
.PyriteSsc
!= 1) {
379 // According to current Pyrite SSC Spec 1.00, there is no parameter for RevertSP method.
380 // So issue RevertSP method without any parameter by suppress KeepUserData option.
382 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA
;
384 if (AvailActions
.RevertKeepDataForced
) {
385 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA_FORCED
;
390 OpalHiiSetBrowserData ();
396 Get disk name string id.
398 @param DiskIndex The input disk index info.
400 @retval The disk name string id.
409 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
410 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
411 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
412 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
413 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
414 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
420 This function processes the results of changes in configuration.
422 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
423 @param Action Specifies the type of action taken by the browser.
424 @param QuestionId A unique value which is sent to the original
425 exporting driver so that it can identify the type
427 @param Type The type of value for the question.
428 @param Value A pointer to the data being sent to the original
430 @param ActionRequest On return, points to the action requested by the
433 @retval EFI_SUCCESS The callback successfully handled the action.
434 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
435 variable and its data.
436 @retval EFI_DEVICE_ERROR The variable could not be saved.
437 @retval EFI_UNSUPPORTED The specified Action is not supported by the
444 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
445 EFI_BROWSER_ACTION Action
,
446 EFI_QUESTION_ID QuestionId
,
448 EFI_IFR_TYPE_VALUE
*Value
,
449 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
455 if (ActionRequest
!= NULL
) {
456 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
458 return EFI_INVALID_PARAMETER
;
462 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
464 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
468 HiiKey
.Raw
= QuestionId
;
469 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
471 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
473 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
474 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
475 return HiiPopulateMainMenuForm ();
477 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
478 return HiiPopulateDiskInfoForm();
480 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
482 case HII_KEY_ID_GOTO_DISK_INFO
:
483 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
485 case HII_KEY_ID_GOTO_LOCK
:
486 return HiiSelectDiskAction("Action: Lock", HiiKeyId
);
488 case HII_KEY_ID_GOTO_UNLOCK
:
489 return HiiSelectDiskAction("Action: Unlock", HiiKeyId
);
491 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
492 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId
);
494 case HII_KEY_ID_GOTO_SET_USER_PWD
:
495 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId
);
497 case HII_KEY_ID_GOTO_SECURE_ERASE
:
498 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId
);
500 case HII_KEY_ID_GOTO_PSID_REVERT
:
501 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId
);
503 case HII_KEY_ID_GOTO_REVERT
:
504 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId
);
506 case HII_KEY_ID_GOTO_DISABLE_USER
:
507 return HiiSelectDiskAction("Action: Disable User", HiiKeyId
);
509 case HII_KEY_ID_GOTO_ENABLE_FEATURE
:
510 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId
);
512 case HII_KEY_ID_ENTER_PASSWORD
:
513 return HiiPasswordEntered(Value
->string
);
515 case HII_KEY_ID_BLOCKSID
:
516 return HiiSetBlockSid(Value
->b
);
518 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
520 case HII_KEY_ID_ENTER_PSID
:
522 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
527 return EFI_UNSUPPORTED
;
531 Update the global Disk index info.
533 @param Index The input disk index info.
535 @retval EFI_SUCCESS Update the disk index info success.
543 OpalHiiGetBrowserData();
544 gHiiConfiguration
.SelectedDiskIndex
= Index
;
545 OpalHiiSetBrowserData ();
551 Draws the disk info form.
553 @retval EFI_SUCCESS Draw the disk info success.
557 HiiPopulateDiskInfoForm(
562 OPAL_DISK_ACTIONS AvailActions
;
566 OpalHiiGetBrowserData();
568 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
569 if (DiskName
== NULL
) {
570 return EFI_UNSUPPORTED
;
572 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
574 ZeroMem(gHiiConfiguration
.Psid
, sizeof(gHiiConfiguration
.Psid
));
576 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
578 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
580 if (OpalDisk
!= NULL
) {
581 OpalDiskUpdateStatus (OpalDisk
);
582 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
583 if (Ret
== TcgResultSuccess
) {
585 // Update actions, always allow PSID Revert
587 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
590 // Always allow unlock to handle device migration
592 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
594 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
595 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
596 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
601 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
603 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
606 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
607 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
608 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
609 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
610 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
611 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_BLOCKSID
;
613 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
616 // Determine revert options for disk
617 // Default initialize keep user Data to be true
619 gHiiConfiguration
.KeepUserData
= 1;
620 if (OpalDisk
->SupportedAttributes
.PyriteSsc
== 1) {
622 // According to current Pyrite SSC Spec 1.00, there is no parameter for RevertSP method.
623 // So issue RevertSP method without any parameter by set default value to FALSE.
625 gHiiConfiguration
.KeepUserData
= 0;
633 // Pass the current configuration to the BIOS
635 OpalHiiSetBrowserData ();
641 Reverts the Opal disk to factory default.
643 @retval EFI_SUCCESS Do the required action success.
651 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
655 OPAL_SESSION Session
;
657 Ret
= TcgResultFailure
;
659 OpalHiiGetBrowserData();
661 UnicodeStrToAsciiStr(gHiiConfiguration
.Psid
, (CHAR8
*)Psid
.Psid
);
663 OpalDisk
= HiiGetOpalDiskCB (gHiiConfiguration
.SelectedDiskIndex
);
664 if (OpalDisk
!= NULL
) {
665 ZeroMem(&Session
, sizeof(Session
));
666 Session
.Sscp
= OpalDisk
->Sscp
;
667 Session
.MediaId
= OpalDisk
->MediaId
;
668 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
670 Ret
= OpalSupportPsidRevert(&Session
, Psid
.Psid
, (UINT32
)sizeof(Psid
.Psid
), OpalDisk
->OpalDevicePath
);
673 if (Ret
== TcgResultSuccess
) {
674 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Success" );
676 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Failure" );
679 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
685 Set password for the disk.
687 @param OpalDisk The disk need to set the password.
688 @param Password The input password.
689 @param PassLength The input password length.
691 @retval EFI_SUCCESS Do the required action success.
701 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
703 BOOLEAN ExistingPassword
;
704 OPAL_SESSION Session
;
706 ExistingPassword
= FALSE
;
709 // PassLength = 0 means check whether exist old password.
711 if (PassLength
== 0) {
712 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
713 gHiiOldPasswordLength
= 0;
715 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_ENABLE_FEATURE
) {
716 ExistingPassword
= FALSE
;
717 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_ADMIN_PWD
) {
718 ExistingPassword
= OpalUtilAdminPasswordExists(OpalDisk
->Owner
, &OpalDisk
->LockingFeature
);
719 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
721 // Set user Password option shall only be shown if an Admin Password exists
722 // so a Password is always required (Admin or Existing User Password)
724 ExistingPassword
= TRUE
;
728 // Return error if there is a previous Password
729 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
731 return ExistingPassword
? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
734 ZeroMem(&Session
, sizeof(Session
));
735 Session
.Sscp
= OpalDisk
->Sscp
;
736 Session
.MediaId
= OpalDisk
->MediaId
;
737 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
739 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Failure");
742 // No current Owner, so set new Password, must be admin Password
744 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
745 Ret
= OpalSupportEnableOpalFeature (&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
,Password
, PassLength
, OpalDisk
->OpalDevicePath
);
746 if (Ret
== TcgResultSuccess
) {
747 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
750 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
755 // 1st Password entered
757 if (OpalDisk
->Owner
== OpalOwnershipUnknown
&& gHiiOldPasswordLength
== 0) {
760 // Unknown ownership - prompt for old Password, then new
761 // old Password is not set yet - first time through
762 // assume authority provided is admin1, overwritten if user1 authority works below
764 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
766 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
768 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_USER1_AUTHORITY
);
769 if (Ret
== TcgResultSuccess
) {
771 // User1 worked so authority 1 means user 1
773 CopyMem(gHiiOldPassword
, Password
, PassLength
);
774 gHiiOldPasswordLength
= PassLength
;
781 // Else try admin1 below
783 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_ADMIN1_AUTHORITY
);
784 if (Ret
== TcgResultSuccess
) {
785 CopyMem(gHiiOldPassword
, Password
, PassLength
);
786 gHiiOldPasswordLength
= PassLength
;
790 DEBUG ((DEBUG_INFO
, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
791 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Authentication Failure");
793 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
794 gHiiOldPasswordLength
= 0;
796 return EFI_NOT_READY
;
801 // New Password entered
803 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
804 Ret
= OpalSupportSetPassword(
807 gHiiOldPasswordLength
,
810 OpalDisk
->OpalDevicePath
,
814 Ret
= OpalSupportSetPassword(
817 gHiiOldPasswordLength
,
820 OpalDisk
->OpalDevicePath
,
825 if (Ret
== TcgResultSuccess
) {
826 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
830 // Reset old Password storage
832 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
833 gHiiOldPasswordLength
= 0;
835 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
836 return Ret
== TcgResultSuccess
? EFI_SUCCESS
: EFI_NOT_READY
;
840 Secure Erases Opal Disk.
842 @param OpalDisk The disk need to erase data.
843 @param Password The input password.
844 @param PassLength The input password length.
846 @retval EFI_SUCCESS Do the required action success.
852 const VOID
*Password
,
856 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
857 BOOLEAN PasswordFailed
;
859 OPAL_SESSION AdminSpSession
;
861 if (PassLength
== 0) {
862 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
865 ZeroMem(&AdminSpSession
, sizeof(AdminSpSession
));
866 AdminSpSession
.Sscp
= OpalDisk
->Sscp
;
867 AdminSpSession
.MediaId
= OpalDisk
->MediaId
;
868 AdminSpSession
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
870 Ret
= OpalUtilSecureErase(&AdminSpSession
, Password
, PassLength
, &PasswordFailed
);
871 if (Ret
== TcgResultSuccess
) {
872 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Success" );
874 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Failure" );
876 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
879 // If Password failed, return invalid passowrd
881 if (PasswordFailed
) {
882 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
883 return EFI_NOT_READY
;
887 // Indicates Password was valid and is not changing to UEFI
888 // Response string will indicate action error
890 return EFI_DEVICE_ERROR
;
895 Disables User for Opal Disk.
897 @param OpalDisk The disk need to the action.
898 @param Password The input password.
899 @param PassLength The input password length.
901 @retval EFI_SUCCESS Do the required action success.
911 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
912 BOOLEAN PasswordFailed
;
914 OPAL_SESSION Session
;
916 if (PassLength
== 0) {
917 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
920 ZeroMem(&Session
, sizeof(Session
));
921 Session
.Sscp
= OpalDisk
->Sscp
;
922 Session
.MediaId
= OpalDisk
->MediaId
;
923 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
925 Ret
= OpalSupportDisableUser(&Session
, Password
, PassLength
, &PasswordFailed
, OpalDisk
->OpalDevicePath
);
926 if (Ret
== TcgResultSuccess
) {
927 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Success" );
929 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Failure" );
931 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS
), Response
);
934 // If Password failed, return invalid passowrd
936 if (PasswordFailed
) {
937 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
938 return EFI_NOT_READY
;
942 // Indicates Password was valid and is not changing to UEFI
943 // Response string will indicate action error
945 return EFI_DEVICE_ERROR
;
949 Revert Opal Disk as Admin1.
951 @param OpalDisk The disk need to the action.
952 @param Password The input password.
953 @param PassLength The input password length.
954 @param KeepUserData Whether need to keey user data.
956 @retval EFI_SUCCESS Do the required action success.
967 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
968 BOOLEAN PasswordFailed
;
970 OPAL_SESSION Session
;
972 if (PassLength
== 0) {
973 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
974 // return error to indicate there is an existing Password
975 return EFI_DEVICE_ERROR
;
978 ZeroMem(&Session
, sizeof(Session
));
979 Session
.Sscp
= OpalDisk
->Sscp
;
980 Session
.MediaId
= OpalDisk
->MediaId
;
981 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
983 Ret
= OpalSupportRevert(
989 OpalDisk
->MsidLength
,
991 OpalDisk
->OpalDevicePath
993 if (Ret
== TcgResultSuccess
) {
994 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Success" );
996 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Failure" );
998 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1001 // If Password failed, return invalid passowrd
1003 if (PasswordFailed
) {
1004 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1005 return EFI_NOT_READY
;
1009 // Indicates Password was valid and is not changing to UEFI
1010 // Response string will indicate action error
1012 return EFI_DEVICE_ERROR
;
1018 @param OpalDisk The disk need to the action.
1019 @param Password The input password.
1020 @param PassLength The input password length.
1022 @retval EFI_SUCCESS Do the required action success.
1027 OPAL_DISK
*OpalDisk
,
1032 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
1034 OPAL_SESSION Session
;
1036 if (PassLength
== 0) {
1037 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
1038 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
1041 ZeroMem(&Session
, sizeof(Session
));
1042 Session
.Sscp
= OpalDisk
->Sscp
;
1043 Session
.MediaId
= OpalDisk
->MediaId
;
1044 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1046 Ret
= OpalSupportUnlock(&Session
, Password
, PassLength
, OpalDisk
->OpalDevicePath
);
1047 if (Ret
== TcgResultSuccess
) {
1048 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Success" );
1050 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Failure" );
1053 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1055 if (Ret
== TcgResultSuccess
) {
1056 DEBUG ((DEBUG_INFO
, "returning error to indicate Password was correct but is not changing\n"));
1057 return EFI_DEVICE_ERROR
;
1059 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1060 return EFI_NOT_READY
;
1065 Use the input password to do the specified action.
1067 @param Str The input password saved in.
1069 @retval EFI_SUCCESS Do the required action success.
1070 @retval Others Other error occur.
1078 OPAL_DISK
* OpalDisk
;
1079 CHAR8 Password
[MAX_PASSWORD_CHARACTER_LENGTH
+ 1];
1084 OpalHiiGetBrowserData();
1086 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
1087 if (OpalDisk
== NULL
) {
1088 DEBUG ((DEBUG_INFO
, "ERROR: disk %u not found\n", gHiiConfiguration
.SelectedDiskIndex
));
1089 return EFI_NOT_FOUND
;
1093 DEBUG ((DEBUG_INFO
, "ERROR: str=NULL\n"));
1094 return EFI_INVALID_PARAMETER
;
1097 ZeroMem(Password
, sizeof(Password
));
1099 UniStr
= HiiGetString(gHiiPackageListHandle
, Str
, NULL
);
1100 if (UniStr
== NULL
) {
1101 return EFI_NOT_FOUND
;
1103 PassLength
= (UINT32
) StrLen (UniStr
);
1104 if (PassLength
>= sizeof(Password
)) {
1105 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Password too long");
1106 gBS
->FreePool(UniStr
);
1107 return EFI_BUFFER_TOO_SMALL
;
1110 UnicodeStrToAsciiStr(UniStr
, Password
);
1111 gBS
->FreePool(UniStr
);
1113 DEBUG ((DEBUG_INFO
, "Password: '%s'\n", Password
));
1115 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_UNLOCK
) {
1116 Status
= HiiUnlock (OpalDisk
, Password
, PassLength
);
1117 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SECURE_ERASE
) {
1118 Status
= HiiSecureErase (OpalDisk
, Password
, PassLength
);
1119 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_DISABLE_USER
) {
1120 Status
= HiiDisableUser (OpalDisk
, Password
, PassLength
);
1121 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_REVERT
) {
1122 DEBUG ((DEBUG_INFO
, "gHiiConfiguration.KeepUserData %u\n", gHiiConfiguration
.KeepUserData
));
1123 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, gHiiConfiguration
.KeepUserData
);
1125 Status
= HiiSetPassword(OpalDisk
, Password
, PassLength
);
1128 OpalHiiSetBrowserData ();
1134 Update block sid info.
1136 @param Enable Enable/disable BlockSid.
1138 @retval EFI_SUCCESS Do the required action success.
1139 @retval Others Other error occur.
1148 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
1151 Status
= EFI_SUCCESS
;
1153 DEBUG ((DEBUG_INFO
, "HiiSetBlockSid(enable: %x)\n", Enable
));
1155 OpalExtraInfo
.EnableBlockSid
= Enable
;
1156 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
1157 Status
= gRT
->SetVariable (
1158 OPAL_EXTRA_INFO_VAR_NAME
,
1159 &gOpalExtraInfoVariableGuid
,
1160 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1164 DEBUG ((DEBUG_INFO
, "SetVariable, Status: %r\n", Status
));
1170 This function processes the results of changes in configuration.
1172 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1173 @param Configuration A null-terminated Unicode string in <ConfigResp>
1175 @param Progress A pointer to a string filled in with the offset of
1176 the most recent '&' before the first failing
1177 name/value pair (or the beginning of the string if
1178 the failure is in the first name/value pair) or
1179 the terminating NULL if all was successful.
1181 @retval EFI_SUCCESS The Results is processed successfully.
1182 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1183 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1190 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1191 CONST EFI_STRING Configuration
,
1192 EFI_STRING
*Progress
1195 DEBUG ((DEBUG_INFO
, "RouteConfig( )\n"));
1196 if (Configuration
== NULL
|| Progress
== NULL
) {
1197 return (EFI_INVALID_PARAMETER
);
1204 This function allows a caller to extract the current configuration for one
1205 or more named elements from the target driver.
1207 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1208 @param Request A null-terminated Unicode string in
1209 <ConfigRequest> format.
1210 @param Progress On return, points to a character in the Request
1211 string. Points to the string's null terminator if
1212 request was successful. Points to the most recent
1213 '&' before the first failing name/value pair (or
1214 the beginning of the string if the failure is in
1215 the first name/value pair) if the request was not
1217 @param Results A null-terminated Unicode string in
1218 <ConfigAltResp> format which has all values filled
1219 in for the names in the Request string. String to
1220 be allocated by the called function.
1222 @retval EFI_SUCCESS The Results is filled with the requested values.
1223 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1224 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1225 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1232 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1233 CONST EFI_STRING Request
,
1234 EFI_STRING
*Progress
,
1240 DEBUG ((DEBUG_INFO
, "ExtractConfig( )\n"));
1243 // Check for valid parameters
1245 if (Progress
== NULL
|| Results
== NULL
) {
1246 return (EFI_INVALID_PARAMETER
);
1250 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1252 Status
= gHiiConfigRouting
->BlockToConfig(
1255 (UINT8
*)&gHiiConfiguration
,
1256 sizeof(OPAL_HII_CONFIGURATION
),
1267 Pass the current system state to the bios via the hii_G_Configuration.
1271 OpalHiiSetBrowserData (
1275 DEBUG ((DEBUG_INFO
, "OpalHiiSetBrowserData( )\n"));
1277 &gHiiSetupVariableGuid
,
1278 (CHAR16
*)L
"OpalHiiConfig",
1279 sizeof(gHiiConfiguration
),
1280 (UINT8
*)&gHiiConfiguration
,
1288 Populate the hii_g_Configuraton with the browser Data.
1292 OpalHiiGetBrowserData (
1296 DEBUG ((DEBUG_INFO
, "OpalHiiGetBrowserData( )\n"));
1298 &gHiiSetupVariableGuid
,
1299 (CHAR16
*)L
"OpalHiiConfig",
1300 sizeof(gHiiConfiguration
),
1301 (UINT8
*)&gHiiConfiguration
1306 Set a string Value in a form.
1308 @param DestStringId The stringid which need to update.
1309 @param SrcAsciiStr The string nned to update.
1311 @retval EFI_SUCCESS Do the required action success.
1312 @retval Others Other error occur.
1317 EFI_STRING_ID DestStringId
,
1325 DEBUG ((DEBUG_INFO
, "HiiSetFormString( )\n"));
1328 // Determine the Length of the sting
1330 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1333 // Allocate space for the unicode string, including terminator
1335 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1336 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1339 // Copy into unicode string, then copy into string id
1341 AsciiStrToUnicodeStr( SrcAsciiStr
, UniStr
);
1344 // Update the string in the form
1346 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1347 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1349 return (EFI_OUT_OF_RESOURCES
);
1357 return (EFI_SUCCESS
);
1361 Initialize the Opal disk base on the hardware info get from device.
1363 @param Dev The Opal device.
1365 @retval EFI_SUCESS Initialize the device success.
1366 @retval EFI_DEVICE_ERROR Get info from device failed.
1370 OpalDiskInitialize (
1371 IN OPAL_DRIVER_DEVICE
*Dev
1374 TCG_RESULT TcgResult
;
1375 OPAL_SESSION Session
;
1377 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1378 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1379 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1380 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1382 ZeroMem(&Session
, sizeof(Session
));
1383 Session
.Sscp
= Dev
->Sscp
;
1384 Session
.MediaId
= Dev
->MediaId
;
1386 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1387 if (TcgResult
!= TcgResultSuccess
) {
1388 return EFI_DEVICE_ERROR
;
1390 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1392 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1393 if (TcgResult
!= TcgResultSuccess
) {
1394 return EFI_DEVICE_ERROR
;
1397 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1401 Update the device info.
1403 @param OpalDisk The Opal device.
1405 @retval EFI_SUCESS Initialize the device success.
1406 @retval EFI_DEVICE_ERROR Get info from device failed.
1407 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1411 OpalDiskUpdateStatus (
1415 TCG_RESULT TcgResult
;
1416 OPAL_SESSION Session
;
1418 ZeroMem(&Session
, sizeof(Session
));
1419 Session
.Sscp
= OpalDisk
->Sscp
;
1420 Session
.MediaId
= OpalDisk
->MediaId
;
1421 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1423 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1424 if (TcgResult
!= TcgResultSuccess
) {
1425 return EFI_DEVICE_ERROR
;
1428 if (OpalDisk
->MsidLength
== 0) {
1429 return EFI_INVALID_PARAMETER
;
1432 // Base on the Msid info to get the ownership, so Msid info must get first.
1434 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);