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(
94 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
97 gHiiConfiguration
.NumDisks
= GetDeviceCount();
99 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
100 Status
= gRT
->GetVariable (
101 OPAL_EXTRA_INFO_VAR_NAME
,
102 &gOpalExtraInfoVariableGuid
,
107 if (!EFI_ERROR (Status
)) {
108 gHiiConfiguration
.EnableBlockSid
= OpalExtraInfo
.EnableBlockSid
;
113 Install the HII related resources.
115 @retval EFI_SUCCESS Install all the resources success.
116 @retval other Error occur when install the resources.
124 EFI_HANDLE DriverHandle
;
127 // Clear the global configuration.
129 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
132 // Obtain the driver handle that the BIOS assigned us
134 DriverHandle
= HiiGetDriverImageHandleCB();
137 // Populate the config access protocol with the three functions we are publishing
139 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
140 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
141 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
144 // Associate the required protocols with our driver handle
146 Status
= gBS
->InstallMultipleProtocolInterfaces(
148 &gEfiHiiConfigAccessProtocolGuid
,
149 &gHiiConfigAccessProtocol
, // HII callback
150 &gEfiDevicePathProtocolGuid
,
151 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
155 if (EFI_ERROR(Status
)) {
159 return OpalHiiAddPackages();
163 Install the HII form and string packages.
165 @retval EFI_SUCCESS Install all the resources success.
166 @retval EFI_OUT_OF_RESOURCES Out of resource error.
173 EFI_HANDLE DriverHandle
;
176 DriverHandle
= HiiGetDriverImageHandleCB();
179 // Publish the HII form and HII string packages
181 gHiiPackageListHandle
= HiiAddPackages(
182 &gHiiPackageListGuid
,
184 OpalPasswordDxeStrings
,
190 // Make sure the packages installed successfully
192 if (gHiiPackageListHandle
== NULL
) {
193 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
194 return EFI_OUT_OF_RESOURCES
;
198 // Update Version String in main window
200 NewString
= HiiGetDriverNameCB ();
201 if (HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_MAIN_OPAL_VERSION
), NewString
, NULL
) == 0) {
202 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
203 return EFI_OUT_OF_RESOURCES
;
210 Uninstall the HII capability.
212 @retval EFI_SUCCESS Uninstall all the resources success.
213 @retval others Other errors occur when unistall the hii resource.
223 // Remove the packages we've provided to the BIOS
225 HiiRemovePackages(gHiiPackageListHandle
);
228 // Remove the protocols from our driver handle
230 Status
= gBS
->UninstallMultipleProtocolInterfaces(
231 HiiGetDriverImageHandleCB(),
232 &gEfiHiiConfigAccessProtocolGuid
,
233 &gHiiConfigAccessProtocol
, // HII callback
234 &gEfiDevicePathProtocolGuid
,
235 &gHiiVendorDevicePath
, // required for HII callback
238 if (EFI_ERROR(Status
)) {
239 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
246 Updates the main menu form.
248 @retval EFI_SUCCESS update the main form success.
251 HiiPopulateMainMenuForm (
257 EFI_STRING_ID DiskNameId
;
260 HiiSetCurrentConfiguration();
262 gHiiConfiguration
.SupportedDisks
= 0;
264 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
265 OpalDisk
= HiiGetOpalDiskCB (Index
);
266 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
267 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
268 DiskNameId
= GetDiskNameStringId (Index
);
269 DiskName
= HiiDiskGetNameCB (Index
);
270 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
271 return EFI_UNSUPPORTED
;
273 HiiSetFormString(DiskNameId
, DiskName
);
277 OpalHiiSetBrowserData ();
282 Update the disk action info.
285 @param SelectedAction
287 @retval EFI_SUCCESS Uninstall all the resources success.
290 HiiSelectDiskAction (
296 OPAL_DISK_ACTIONS AvailActions
;
298 OpalHiiGetBrowserData ();
300 HiiSetFormString(STRING_TOKEN(STR_DISK_ACTION_LBL
), ActionString
);
301 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), " ");
303 gHiiConfiguration
.SelectedAction
= SelectedAction
;
304 gHiiConfiguration
.AvailableFields
= 0;
306 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
307 if (OpalDisk
== NULL
) {
308 return EFI_INVALID_PARAMETER
;
311 if (OpalSupportGetAvailableActions (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
) != TcgResultSuccess
) {
312 return EFI_DEVICE_ERROR
;
315 switch (SelectedAction
) {
316 case HII_KEY_ID_GOTO_LOCK
:
317 case HII_KEY_ID_GOTO_UNLOCK
:
318 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
319 case HII_KEY_ID_GOTO_SET_USER_PWD
:
320 case HII_KEY_ID_GOTO_SECURE_ERASE
:
321 case HII_KEY_ID_GOTO_DISABLE_USER
:
322 case HII_KEY_ID_GOTO_ENABLE_FEATURE
: // User is required to enter Password to enable Feature
323 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
326 case HII_KEY_ID_GOTO_PSID_REVERT
:
327 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PSID
;
330 case HII_KEY_ID_GOTO_REVERT
:
331 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
332 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA
;
333 if (AvailActions
.RevertKeepDataForced
) {
334 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA_FORCED
;
339 OpalHiiSetBrowserData ();
345 Get disk name string id.
347 @param DiskIndex The input disk index info.
349 @retval The disk name string id.
358 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
359 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
360 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
361 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
362 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
363 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
369 This function processes the results of changes in configuration.
371 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
372 @param Action Specifies the type of action taken by the browser.
373 @param QuestionId A unique value which is sent to the original
374 exporting driver so that it can identify the type
376 @param Type The type of value for the question.
377 @param Value A pointer to the data being sent to the original
379 @param ActionRequest On return, points to the action requested by the
382 @retval EFI_SUCCESS The callback successfully handled the action.
383 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
384 variable and its data.
385 @retval EFI_DEVICE_ERROR The variable could not be saved.
386 @retval EFI_UNSUPPORTED The specified Action is not supported by the
393 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
394 EFI_BROWSER_ACTION Action
,
395 EFI_QUESTION_ID QuestionId
,
397 EFI_IFR_TYPE_VALUE
*Value
,
398 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
404 if (ActionRequest
!= NULL
) {
405 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
407 return EFI_INVALID_PARAMETER
;
411 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
413 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
417 HiiKey
.Raw
= QuestionId
;
418 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
420 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
422 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
423 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
424 return HiiPopulateMainMenuForm ();
426 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
427 return HiiPopulateDiskInfoForm();
429 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
431 case HII_KEY_ID_GOTO_DISK_INFO
:
432 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
434 case HII_KEY_ID_GOTO_LOCK
:
435 return HiiSelectDiskAction("Action: Lock", HiiKeyId
);
437 case HII_KEY_ID_GOTO_UNLOCK
:
438 return HiiSelectDiskAction("Action: Unlock", HiiKeyId
);
440 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
441 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId
);
443 case HII_KEY_ID_GOTO_SET_USER_PWD
:
444 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId
);
446 case HII_KEY_ID_GOTO_SECURE_ERASE
:
447 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId
);
449 case HII_KEY_ID_GOTO_PSID_REVERT
:
450 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId
);
452 case HII_KEY_ID_GOTO_REVERT
:
453 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId
);
455 case HII_KEY_ID_GOTO_DISABLE_USER
:
456 return HiiSelectDiskAction("Action: Disable User", HiiKeyId
);
458 case HII_KEY_ID_GOTO_ENABLE_FEATURE
:
459 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId
);
461 case HII_KEY_ID_ENTER_PASSWORD
:
462 return HiiPasswordEntered(Value
->string
);
464 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
466 case HII_KEY_ID_ENTER_PSID
:
468 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
471 case HII_KEY_ID_BLOCKSID
:
472 HiiSetBlockSid(Value
->b
);
473 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
478 return EFI_UNSUPPORTED
;
482 Update the global Disk index info.
484 @param Index The input disk index info.
486 @retval EFI_SUCCESS Update the disk index info success.
494 OpalHiiGetBrowserData();
495 gHiiConfiguration
.SelectedDiskIndex
= Index
;
496 OpalHiiSetBrowserData ();
502 Draws the disk info form.
504 @retval EFI_SUCCESS Draw the disk info success.
508 HiiPopulateDiskInfoForm(
513 OPAL_DISK_ACTIONS AvailActions
;
517 OpalHiiGetBrowserData();
519 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
520 if (DiskName
== NULL
) {
521 return EFI_UNSUPPORTED
;
523 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
525 ZeroMem(gHiiConfiguration
.Psid
, sizeof(gHiiConfiguration
.Psid
));
527 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
529 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
531 if (OpalDisk
!= NULL
) {
532 OpalDiskUpdateStatus (OpalDisk
);
533 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
534 if (Ret
== TcgResultSuccess
) {
536 // Update actions, always allow PSID Revert
538 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
541 // Always allow unlock to handle device migration
543 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
545 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
546 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
547 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
552 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
554 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
557 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
558 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
559 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
560 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
561 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
563 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
566 // Determine revert options for disk
567 // Default initialize keep user Data to be true
569 gHiiConfiguration
.KeepUserData
= 1;
575 // Pass the current configuration to the BIOS
577 OpalHiiSetBrowserData ();
583 Reverts the Opal disk to factory default.
585 @retval EFI_SUCCESS Do the required action success.
593 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
597 OPAL_SESSION Session
;
599 Ret
= TcgResultFailure
;
601 OpalHiiGetBrowserData();
603 UnicodeStrToAsciiStrS (gHiiConfiguration
.Psid
, (CHAR8
*)Psid
.Psid
, PSID_CHARACTER_LENGTH
);
605 OpalDisk
= HiiGetOpalDiskCB (gHiiConfiguration
.SelectedDiskIndex
);
606 if (OpalDisk
!= NULL
) {
607 ZeroMem(&Session
, sizeof(Session
));
608 Session
.Sscp
= OpalDisk
->Sscp
;
609 Session
.MediaId
= OpalDisk
->MediaId
;
610 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
612 Ret
= OpalSupportPsidRevert(&Session
, Psid
.Psid
, (UINT32
)sizeof(Psid
.Psid
), OpalDisk
->OpalDevicePath
);
615 if (Ret
== TcgResultSuccess
) {
616 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Success" );
618 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Failure" );
621 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
627 Set password for the disk.
629 @param OpalDisk The disk need to set the password.
630 @param Password The input password.
631 @param PassLength The input password length.
633 @retval EFI_SUCCESS Do the required action success.
643 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
645 BOOLEAN ExistingPassword
;
646 OPAL_SESSION Session
;
648 ExistingPassword
= FALSE
;
651 // PassLength = 0 means check whether exist old password.
653 if (PassLength
== 0) {
654 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
655 gHiiOldPasswordLength
= 0;
657 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_ENABLE_FEATURE
) {
658 ExistingPassword
= FALSE
;
659 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_ADMIN_PWD
) {
660 ExistingPassword
= OpalUtilAdminPasswordExists(OpalDisk
->Owner
, &OpalDisk
->LockingFeature
);
661 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
663 // Set user Password option shall only be shown if an Admin Password exists
664 // so a Password is always required (Admin or Existing User Password)
666 ExistingPassword
= TRUE
;
670 // Return error if there is a previous Password
671 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
673 return ExistingPassword
? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
676 ZeroMem(&Session
, sizeof(Session
));
677 Session
.Sscp
= OpalDisk
->Sscp
;
678 Session
.MediaId
= OpalDisk
->MediaId
;
679 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
681 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Failure");
684 // No current Owner, so set new Password, must be admin Password
686 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
687 Ret
= OpalSupportEnableOpalFeature (&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
,Password
, PassLength
, OpalDisk
->OpalDevicePath
);
688 if (Ret
== TcgResultSuccess
) {
689 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
692 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
697 // 1st Password entered
699 if (OpalDisk
->Owner
== OpalOwnershipUnknown
&& gHiiOldPasswordLength
== 0) {
702 // Unknown ownership - prompt for old Password, then new
703 // old Password is not set yet - first time through
704 // assume authority provided is admin1, overwritten if user1 authority works below
706 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
708 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
710 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_USER1_AUTHORITY
);
711 if (Ret
== TcgResultSuccess
) {
713 // User1 worked so authority 1 means user 1
715 CopyMem(gHiiOldPassword
, Password
, PassLength
);
716 gHiiOldPasswordLength
= PassLength
;
723 // Else try admin1 below
725 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_ADMIN1_AUTHORITY
);
726 if (Ret
== TcgResultSuccess
) {
727 CopyMem(gHiiOldPassword
, Password
, PassLength
);
728 gHiiOldPasswordLength
= PassLength
;
732 DEBUG ((DEBUG_INFO
, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
733 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Authentication Failure");
735 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
736 gHiiOldPasswordLength
= 0;
738 return EFI_NOT_READY
;
743 // New Password entered
745 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
746 Ret
= OpalSupportSetPassword(
749 gHiiOldPasswordLength
,
752 OpalDisk
->OpalDevicePath
,
756 Ret
= OpalSupportSetPassword(
759 gHiiOldPasswordLength
,
762 OpalDisk
->OpalDevicePath
,
767 if (Ret
== TcgResultSuccess
) {
768 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
772 // Reset old Password storage
774 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
775 gHiiOldPasswordLength
= 0;
777 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
778 return Ret
== TcgResultSuccess
? EFI_SUCCESS
: EFI_NOT_READY
;
782 Secure Erases Opal Disk.
784 @param OpalDisk The disk need to erase data.
785 @param Password The input password.
786 @param PassLength The input password length.
788 @retval EFI_SUCCESS Do the required action success.
794 const VOID
*Password
,
798 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
799 BOOLEAN PasswordFailed
;
801 OPAL_SESSION AdminSpSession
;
803 if (PassLength
== 0) {
804 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
807 ZeroMem(&AdminSpSession
, sizeof(AdminSpSession
));
808 AdminSpSession
.Sscp
= OpalDisk
->Sscp
;
809 AdminSpSession
.MediaId
= OpalDisk
->MediaId
;
810 AdminSpSession
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
812 Ret
= OpalUtilSecureErase(&AdminSpSession
, Password
, PassLength
, &PasswordFailed
);
813 if (Ret
== TcgResultSuccess
) {
814 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Success" );
816 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Failure" );
818 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
821 // If Password failed, return invalid passowrd
823 if (PasswordFailed
) {
824 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
825 return EFI_NOT_READY
;
829 // Indicates Password was valid and is not changing to UEFI
830 // Response string will indicate action error
832 return EFI_DEVICE_ERROR
;
837 Disables User for Opal Disk.
839 @param OpalDisk The disk need to the action.
840 @param Password The input password.
841 @param PassLength The input password length.
843 @retval EFI_SUCCESS Do the required action success.
853 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
854 BOOLEAN PasswordFailed
;
856 OPAL_SESSION Session
;
858 if (PassLength
== 0) {
859 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
862 ZeroMem(&Session
, sizeof(Session
));
863 Session
.Sscp
= OpalDisk
->Sscp
;
864 Session
.MediaId
= OpalDisk
->MediaId
;
865 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
867 Ret
= OpalSupportDisableUser(&Session
, Password
, PassLength
, &PasswordFailed
, OpalDisk
->OpalDevicePath
);
868 if (Ret
== TcgResultSuccess
) {
869 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Success" );
871 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Failure" );
873 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS
), Response
);
876 // If Password failed, return invalid passowrd
878 if (PasswordFailed
) {
879 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
880 return EFI_NOT_READY
;
884 // Indicates Password was valid and is not changing to UEFI
885 // Response string will indicate action error
887 return EFI_DEVICE_ERROR
;
891 Revert Opal Disk as Admin1.
893 @param OpalDisk The disk need to the action.
894 @param Password The input password.
895 @param PassLength The input password length.
896 @param KeepUserData Whether need to keey user data.
898 @retval EFI_SUCCESS Do the required action success.
909 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
910 BOOLEAN PasswordFailed
;
912 OPAL_SESSION Session
;
914 if (PassLength
== 0) {
915 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
916 // return error to indicate there is an existing Password
917 return EFI_DEVICE_ERROR
;
920 ZeroMem(&Session
, sizeof(Session
));
921 Session
.Sscp
= OpalDisk
->Sscp
;
922 Session
.MediaId
= OpalDisk
->MediaId
;
923 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
925 Ret
= OpalSupportRevert(
931 OpalDisk
->MsidLength
,
933 OpalDisk
->OpalDevicePath
935 if (Ret
== TcgResultSuccess
) {
936 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Success" );
938 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Failure" );
940 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
943 // If Password failed, return invalid passowrd
945 if (PasswordFailed
) {
946 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
947 return EFI_NOT_READY
;
951 // Indicates Password was valid and is not changing to UEFI
952 // Response string will indicate action error
954 return EFI_DEVICE_ERROR
;
960 @param OpalDisk The disk need to the action.
961 @param Password The input password.
962 @param PassLength The input password length.
964 @retval EFI_SUCCESS Do the required action success.
974 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
976 OPAL_SESSION Session
;
978 if (PassLength
== 0) {
979 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
980 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
983 ZeroMem(&Session
, sizeof(Session
));
984 Session
.Sscp
= OpalDisk
->Sscp
;
985 Session
.MediaId
= OpalDisk
->MediaId
;
986 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
988 Ret
= OpalSupportUnlock(&Session
, Password
, PassLength
, OpalDisk
->OpalDevicePath
);
989 if (Ret
== TcgResultSuccess
) {
990 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Success" );
992 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Failure" );
995 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
997 if (Ret
== TcgResultSuccess
) {
998 DEBUG ((DEBUG_INFO
, "returning error to indicate Password was correct but is not changing\n"));
999 return EFI_DEVICE_ERROR
;
1001 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1002 return EFI_NOT_READY
;
1007 Use the input password to do the specified action.
1009 @param Str The input password saved in.
1011 @retval EFI_SUCCESS Do the required action success.
1012 @retval Others Other error occur.
1020 OPAL_DISK
* OpalDisk
;
1021 CHAR8 Password
[MAX_PASSWORD_CHARACTER_LENGTH
+ 1];
1026 OpalHiiGetBrowserData();
1028 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
1029 if (OpalDisk
== NULL
) {
1030 DEBUG ((DEBUG_INFO
, "ERROR: disk %u not found\n", gHiiConfiguration
.SelectedDiskIndex
));
1031 return EFI_NOT_FOUND
;
1035 DEBUG ((DEBUG_INFO
, "ERROR: str=NULL\n"));
1036 return EFI_INVALID_PARAMETER
;
1039 ZeroMem(Password
, sizeof(Password
));
1041 UniStr
= HiiGetString(gHiiPackageListHandle
, Str
, NULL
);
1042 if (UniStr
== NULL
) {
1043 return EFI_NOT_FOUND
;
1045 PassLength
= (UINT32
) StrLen (UniStr
);
1046 if (PassLength
>= sizeof(Password
)) {
1047 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Password too long");
1048 gBS
->FreePool(UniStr
);
1049 return EFI_BUFFER_TOO_SMALL
;
1052 UnicodeStrToAsciiStrS (UniStr
, Password
, sizeof (Password
));
1053 gBS
->FreePool(UniStr
);
1055 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_UNLOCK
) {
1056 Status
= HiiUnlock (OpalDisk
, Password
, PassLength
);
1057 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SECURE_ERASE
) {
1058 Status
= HiiSecureErase (OpalDisk
, Password
, PassLength
);
1059 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_DISABLE_USER
) {
1060 Status
= HiiDisableUser (OpalDisk
, Password
, PassLength
);
1061 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_REVERT
) {
1062 if (OpalDisk
->SupportedAttributes
.PyriteSsc
== 1 && OpalDisk
->LockingFeature
.MediaEncryption
== 0) {
1064 // For pyrite type device which also not supports media encryption, it not accept "Keep User Data" parameter.
1065 // So here hardcode a FALSE for this case.
1067 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, FALSE
);
1069 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, gHiiConfiguration
.KeepUserData
);
1072 Status
= HiiSetPassword(OpalDisk
, Password
, PassLength
);
1075 OpalHiiSetBrowserData ();
1081 Update block sid info.
1083 @param Enable Enable/disable BlockSid.
1085 @retval EFI_SUCCESS Do the required action success.
1086 @retval Others Other error occur.
1095 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
1098 Status
= EFI_SUCCESS
;
1100 OpalExtraInfo
.EnableBlockSid
= Enable
;
1101 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
1102 Status
= gRT
->SetVariable (
1103 OPAL_EXTRA_INFO_VAR_NAME
,
1104 &gOpalExtraInfoVariableGuid
,
1105 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1114 This function processes the results of changes in configuration.
1116 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1117 @param Configuration A null-terminated Unicode string in <ConfigResp>
1119 @param Progress A pointer to a string filled in with the offset of
1120 the most recent '&' before the first failing
1121 name/value pair (or the beginning of the string if
1122 the failure is in the first name/value pair) or
1123 the terminating NULL if all was successful.
1125 @retval EFI_SUCCESS The Results is processed successfully.
1126 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1127 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1134 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1135 CONST EFI_STRING Configuration
,
1136 EFI_STRING
*Progress
1139 if (Configuration
== NULL
|| Progress
== NULL
) {
1140 return (EFI_INVALID_PARAMETER
);
1143 *Progress
= Configuration
;
1144 if (!HiiIsConfigHdrMatch (Configuration
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1145 return EFI_NOT_FOUND
;
1148 *Progress
= Configuration
+ StrLen (Configuration
);
1154 This function allows a caller to extract the current configuration for one
1155 or more named elements from the target driver.
1157 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1158 @param Request A null-terminated Unicode string in
1159 <ConfigRequest> format.
1160 @param Progress On return, points to a character in the Request
1161 string. Points to the string's null terminator if
1162 request was successful. Points to the most recent
1163 '&' before the first failing name/value pair (or
1164 the beginning of the string if the failure is in
1165 the first name/value pair) if the request was not
1167 @param Results A null-terminated Unicode string in
1168 <ConfigAltResp> format which has all values filled
1169 in for the names in the Request string. String to
1170 be allocated by the called function.
1172 @retval EFI_SUCCESS The Results is filled with the requested values.
1173 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1174 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1175 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1182 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1183 CONST EFI_STRING Request
,
1184 EFI_STRING
*Progress
,
1191 // Check for valid parameters
1193 if (Progress
== NULL
|| Results
== NULL
) {
1194 return (EFI_INVALID_PARAMETER
);
1197 *Progress
= Request
;
1198 if ((Request
!= NULL
) &&
1199 !HiiIsConfigHdrMatch (Request
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1200 return EFI_NOT_FOUND
;
1204 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1206 Status
= gHiiConfigRouting
->BlockToConfig(
1209 (UINT8
*)&gHiiConfiguration
,
1210 sizeof(OPAL_HII_CONFIGURATION
),
1221 Pass the current system state to the bios via the hii_G_Configuration.
1225 OpalHiiSetBrowserData (
1230 &gHiiSetupVariableGuid
,
1231 (CHAR16
*)L
"OpalHiiConfig",
1232 sizeof(gHiiConfiguration
),
1233 (UINT8
*)&gHiiConfiguration
,
1241 Populate the hii_g_Configuraton with the browser Data.
1245 OpalHiiGetBrowserData (
1250 &gHiiSetupVariableGuid
,
1251 (CHAR16
*)L
"OpalHiiConfig",
1252 sizeof(gHiiConfiguration
),
1253 (UINT8
*)&gHiiConfiguration
1258 Set a string Value in a form.
1260 @param DestStringId The stringid which need to update.
1261 @param SrcAsciiStr The string nned to update.
1263 @retval EFI_SUCCESS Do the required action success.
1264 @retval Others Other error occur.
1269 EFI_STRING_ID DestStringId
,
1278 // Determine the Length of the sting
1280 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1283 // Allocate space for the unicode string, including terminator
1285 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1286 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1289 // Copy into unicode string, then copy into string id
1291 AsciiStrToUnicodeStrS ( SrcAsciiStr
, UniStr
, Len
+ 1);
1294 // Update the string in the form
1296 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1297 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1299 return (EFI_OUT_OF_RESOURCES
);
1307 return (EFI_SUCCESS
);
1311 Initialize the Opal disk base on the hardware info get from device.
1313 @param Dev The Opal device.
1315 @retval EFI_SUCESS Initialize the device success.
1316 @retval EFI_DEVICE_ERROR Get info from device failed.
1320 OpalDiskInitialize (
1321 IN OPAL_DRIVER_DEVICE
*Dev
1324 TCG_RESULT TcgResult
;
1325 OPAL_SESSION Session
;
1327 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1328 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1329 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1330 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1332 ZeroMem(&Session
, sizeof(Session
));
1333 Session
.Sscp
= Dev
->Sscp
;
1334 Session
.MediaId
= Dev
->MediaId
;
1336 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1337 if (TcgResult
!= TcgResultSuccess
) {
1338 return EFI_DEVICE_ERROR
;
1340 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1342 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1343 if (TcgResult
!= TcgResultSuccess
) {
1344 return EFI_DEVICE_ERROR
;
1347 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1351 Update the device info.
1353 @param OpalDisk The Opal device.
1355 @retval EFI_SUCESS Initialize the device success.
1356 @retval EFI_DEVICE_ERROR Get info from device failed.
1357 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1361 OpalDiskUpdateStatus (
1365 TCG_RESULT TcgResult
;
1366 OPAL_SESSION Session
;
1368 ZeroMem(&Session
, sizeof(Session
));
1369 Session
.Sscp
= OpalDisk
->Sscp
;
1370 Session
.MediaId
= OpalDisk
->MediaId
;
1371 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1373 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1374 if (TcgResult
!= TcgResultSuccess
) {
1375 return EFI_DEVICE_ERROR
;
1378 if (OpalDisk
->MsidLength
== 0) {
1379 return EFI_INVALID_PARAMETER
;
1382 // Base on the Msid info to get the ownership, so Msid info must get first.
1384 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);