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 if (!EFI_ERROR (Status
)) {
106 gHiiConfiguration
.EnableBlockSid
= OpalExtraInfo
.EnableBlockSid
;
111 Check that all required protocols for HII are available.
113 @retval EFI_SUCCESS All required protocols are installed.
114 @retval EFI_NOT_FOUND One or more protocol are not installed.
117 HiiCheckForRequiredProtocols (
124 Status
= gBS
->LocateProtocol(&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
125 if (EFI_ERROR (Status
)) {
126 return EFI_NOT_FOUND
;
129 Status
= gBS
->LocateProtocol(&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
130 if (EFI_ERROR (Status
)) {
131 return EFI_NOT_FOUND
;
134 Status
= gBS
->LocateProtocol(&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
135 if (EFI_ERROR (Status
)) {
136 return EFI_NOT_FOUND
;
139 Status
= gBS
->LocateProtocol(&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**)&TempProtocol
);
140 if (EFI_ERROR (Status
)) {
141 return EFI_NOT_FOUND
;
148 Install the HII related resources.
150 @retval EFI_SUCCESS Install all the resources success.
151 @retval other Error occur when install the resources.
159 EFI_HANDLE DriverHandle
;
162 // Check that all required protocols are available for HII.
163 // If not, fail the install
165 Status
= HiiCheckForRequiredProtocols();
166 if (EFI_ERROR(Status
)) {
171 // Clear the global configuration.
173 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
176 // Obtain the driver handle that the BIOS assigned us
178 DriverHandle
= HiiGetDriverImageHandleCB();
181 // Populate the config access protocol with the three functions we are publishing
183 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
184 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
185 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
188 // Associate the required protocols with our driver handle
190 Status
= gBS
->InstallMultipleProtocolInterfaces(
192 &gEfiHiiConfigAccessProtocolGuid
,
193 &gHiiConfigAccessProtocol
, // HII callback
194 &gEfiDevicePathProtocolGuid
,
195 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
199 if (EFI_ERROR(Status
)) {
203 return OpalHiiAddPackages();
207 Install the HII form and string packages.
209 @retval EFI_SUCCESS Install all the resources success.
210 @retval EFI_OUT_OF_RESOURCES Out of resource error.
217 EFI_HANDLE DriverHandle
;
220 DriverHandle
= HiiGetDriverImageHandleCB();
223 // Publish the HII form and HII string packages
225 gHiiPackageListHandle
= HiiAddPackages(
226 &gHiiPackageListGuid
,
228 OpalPasswordDxeStrings
,
234 // Make sure the packages installed successfully
236 if (gHiiPackageListHandle
== NULL
) {
237 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
238 return EFI_OUT_OF_RESOURCES
;
242 // Update Version String in main window
244 NewString
= HiiGetDriverNameCB ();
245 if (HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_MAIN_OPAL_VERSION
), NewString
, NULL
) == 0) {
246 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
247 return EFI_OUT_OF_RESOURCES
;
254 Uninstall the HII capability.
256 @retval EFI_SUCCESS Uninstall all the resources success.
257 @retval others Other errors occur when unistall the hii resource.
267 // Remove the packages we've provided to the BIOS
269 HiiRemovePackages(gHiiPackageListHandle
);
272 // Remove the protocols from our driver handle
274 Status
= gBS
->UninstallMultipleProtocolInterfaces(
275 HiiGetDriverImageHandleCB(),
276 &gEfiHiiConfigAccessProtocolGuid
,
277 &gHiiConfigAccessProtocol
, // HII callback
278 &gEfiDevicePathProtocolGuid
,
279 &gHiiVendorDevicePath
, // required for HII callback
282 if (EFI_ERROR(Status
)) {
283 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
290 Updates the main menu form.
292 @retval EFI_SUCCESS update the main form success.
295 HiiPopulateMainMenuForm (
301 EFI_STRING_ID DiskNameId
;
304 HiiSetCurrentConfiguration();
306 gHiiConfiguration
.SupportedDisks
= 0;
308 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
309 OpalDisk
= HiiGetOpalDiskCB (Index
);
310 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
311 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
312 DiskNameId
= GetDiskNameStringId (Index
);
313 DiskName
= HiiDiskGetNameCB (Index
);
314 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
315 return EFI_UNSUPPORTED
;
317 HiiSetFormString(DiskNameId
, DiskName
);
321 OpalHiiSetBrowserData ();
326 Update the disk action info.
329 @param SelectedAction
331 @retval EFI_SUCCESS Uninstall all the resources success.
334 HiiSelectDiskAction (
340 OPAL_DISK_ACTIONS AvailActions
;
342 OpalHiiGetBrowserData ();
344 HiiSetFormString(STRING_TOKEN(STR_DISK_ACTION_LBL
), ActionString
);
345 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), " ");
347 gHiiConfiguration
.SelectedAction
= SelectedAction
;
348 gHiiConfiguration
.AvailableFields
= 0;
350 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
351 if (OpalDisk
== NULL
) {
352 return EFI_INVALID_PARAMETER
;
355 if (OpalSupportGetAvailableActions (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
) != TcgResultSuccess
) {
356 return EFI_DEVICE_ERROR
;
359 switch (SelectedAction
) {
360 case HII_KEY_ID_GOTO_LOCK
:
361 case HII_KEY_ID_GOTO_UNLOCK
:
362 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
363 case HII_KEY_ID_GOTO_SET_USER_PWD
:
364 case HII_KEY_ID_GOTO_SECURE_ERASE
:
365 case HII_KEY_ID_GOTO_DISABLE_USER
:
366 case HII_KEY_ID_GOTO_ENABLE_FEATURE
: // User is required to enter Password to enable Feature
367 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
370 case HII_KEY_ID_GOTO_PSID_REVERT
:
371 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PSID
;
374 case HII_KEY_ID_GOTO_REVERT
:
375 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
376 if (OpalDisk
->SupportedAttributes
.PyriteSsc
!= 1) {
378 // According to current Pyrite SSC Spec 1.00, there is no parameter for RevertSP method.
379 // So issue RevertSP method without any parameter by suppress KeepUserData option.
381 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA
;
383 if (AvailActions
.RevertKeepDataForced
) {
384 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA_FORCED
;
389 OpalHiiSetBrowserData ();
395 Get disk name string id.
397 @param DiskIndex The input disk index info.
399 @retval The disk name string id.
408 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
409 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
410 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
411 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
412 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
413 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
419 This function processes the results of changes in configuration.
421 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
422 @param Action Specifies the type of action taken by the browser.
423 @param QuestionId A unique value which is sent to the original
424 exporting driver so that it can identify the type
426 @param Type The type of value for the question.
427 @param Value A pointer to the data being sent to the original
429 @param ActionRequest On return, points to the action requested by the
432 @retval EFI_SUCCESS The callback successfully handled the action.
433 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
434 variable and its data.
435 @retval EFI_DEVICE_ERROR The variable could not be saved.
436 @retval EFI_UNSUPPORTED The specified Action is not supported by the
443 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
444 EFI_BROWSER_ACTION Action
,
445 EFI_QUESTION_ID QuestionId
,
447 EFI_IFR_TYPE_VALUE
*Value
,
448 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
454 if (ActionRequest
!= NULL
) {
455 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
457 return EFI_INVALID_PARAMETER
;
461 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
463 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
467 HiiKey
.Raw
= QuestionId
;
468 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
470 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
472 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
473 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
474 return HiiPopulateMainMenuForm ();
476 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
477 return HiiPopulateDiskInfoForm();
479 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
481 case HII_KEY_ID_GOTO_DISK_INFO
:
482 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
484 case HII_KEY_ID_GOTO_LOCK
:
485 return HiiSelectDiskAction("Action: Lock", HiiKeyId
);
487 case HII_KEY_ID_GOTO_UNLOCK
:
488 return HiiSelectDiskAction("Action: Unlock", HiiKeyId
);
490 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
491 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId
);
493 case HII_KEY_ID_GOTO_SET_USER_PWD
:
494 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId
);
496 case HII_KEY_ID_GOTO_SECURE_ERASE
:
497 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId
);
499 case HII_KEY_ID_GOTO_PSID_REVERT
:
500 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId
);
502 case HII_KEY_ID_GOTO_REVERT
:
503 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId
);
505 case HII_KEY_ID_GOTO_DISABLE_USER
:
506 return HiiSelectDiskAction("Action: Disable User", HiiKeyId
);
508 case HII_KEY_ID_GOTO_ENABLE_FEATURE
:
509 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId
);
511 case HII_KEY_ID_ENTER_PASSWORD
:
512 return HiiPasswordEntered(Value
->string
);
514 case HII_KEY_ID_BLOCKSID
:
515 return HiiSetBlockSid(Value
->b
);
517 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
519 case HII_KEY_ID_ENTER_PSID
:
521 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
526 return EFI_UNSUPPORTED
;
530 Update the global Disk index info.
532 @param Index The input disk index info.
534 @retval EFI_SUCCESS Update the disk index info success.
542 OpalHiiGetBrowserData();
543 gHiiConfiguration
.SelectedDiskIndex
= Index
;
544 OpalHiiSetBrowserData ();
550 Draws the disk info form.
552 @retval EFI_SUCCESS Draw the disk info success.
556 HiiPopulateDiskInfoForm(
561 OPAL_DISK_ACTIONS AvailActions
;
565 OpalHiiGetBrowserData();
567 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
568 if (DiskName
== NULL
) {
569 return EFI_UNSUPPORTED
;
571 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
573 ZeroMem(gHiiConfiguration
.Psid
, sizeof(gHiiConfiguration
.Psid
));
575 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
577 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
579 if (OpalDisk
!= NULL
) {
580 OpalDiskUpdateStatus (OpalDisk
);
581 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
582 if (Ret
== TcgResultSuccess
) {
584 // Update actions, always allow PSID Revert
586 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
589 // Always allow unlock to handle device migration
591 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
593 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
594 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
595 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
600 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
602 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
605 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
606 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
607 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
608 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
609 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
610 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_BLOCKSID
;
612 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
615 // Determine revert options for disk
616 // Default initialize keep user Data to be true
618 gHiiConfiguration
.KeepUserData
= 1;
619 if (OpalDisk
->SupportedAttributes
.PyriteSsc
== 1) {
621 // According to current Pyrite SSC Spec 1.00, there is no parameter for RevertSP method.
622 // So issue RevertSP method without any parameter by set default value to FALSE.
624 gHiiConfiguration
.KeepUserData
= 0;
632 // Pass the current configuration to the BIOS
634 OpalHiiSetBrowserData ();
640 Reverts the Opal disk to factory default.
642 @retval EFI_SUCCESS Do the required action success.
650 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
654 OPAL_SESSION Session
;
656 Ret
= TcgResultFailure
;
658 OpalHiiGetBrowserData();
660 UnicodeStrToAsciiStr(gHiiConfiguration
.Psid
, (CHAR8
*)Psid
.Psid
);
662 OpalDisk
= HiiGetOpalDiskCB (gHiiConfiguration
.SelectedDiskIndex
);
663 if (OpalDisk
!= NULL
) {
664 ZeroMem(&Session
, sizeof(Session
));
665 Session
.Sscp
= OpalDisk
->Sscp
;
666 Session
.MediaId
= OpalDisk
->MediaId
;
667 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
669 Ret
= OpalSupportPsidRevert(&Session
, Psid
.Psid
, (UINT32
)sizeof(Psid
.Psid
), OpalDisk
->OpalDevicePath
);
672 if (Ret
== TcgResultSuccess
) {
673 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Success" );
675 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Failure" );
678 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
684 Set password for the disk.
686 @param OpalDisk The disk need to set the password.
687 @param Password The input password.
688 @param PassLength The input password length.
690 @retval EFI_SUCCESS Do the required action success.
700 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
702 BOOLEAN ExistingPassword
;
703 OPAL_SESSION Session
;
705 ExistingPassword
= FALSE
;
708 // PassLength = 0 means check whether exist old password.
710 if (PassLength
== 0) {
711 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
712 gHiiOldPasswordLength
= 0;
714 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_ENABLE_FEATURE
) {
715 ExistingPassword
= FALSE
;
716 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_ADMIN_PWD
) {
717 ExistingPassword
= OpalUtilAdminPasswordExists(OpalDisk
->Owner
, &OpalDisk
->LockingFeature
);
718 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
720 // Set user Password option shall only be shown if an Admin Password exists
721 // so a Password is always required (Admin or Existing User Password)
723 ExistingPassword
= TRUE
;
727 // Return error if there is a previous Password
728 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
730 return ExistingPassword
? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
733 ZeroMem(&Session
, sizeof(Session
));
734 Session
.Sscp
= OpalDisk
->Sscp
;
735 Session
.MediaId
= OpalDisk
->MediaId
;
736 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
738 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Failure");
741 // No current Owner, so set new Password, must be admin Password
743 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
744 Ret
= OpalSupportEnableOpalFeature (&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
,Password
, PassLength
, OpalDisk
->OpalDevicePath
);
745 if (Ret
== TcgResultSuccess
) {
746 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
749 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
754 // 1st Password entered
756 if (OpalDisk
->Owner
== OpalOwnershipUnknown
&& gHiiOldPasswordLength
== 0) {
759 // Unknown ownership - prompt for old Password, then new
760 // old Password is not set yet - first time through
761 // assume authority provided is admin1, overwritten if user1 authority works below
763 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
765 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
767 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_USER1_AUTHORITY
);
768 if (Ret
== TcgResultSuccess
) {
770 // User1 worked so authority 1 means user 1
772 CopyMem(gHiiOldPassword
, Password
, PassLength
);
773 gHiiOldPasswordLength
= PassLength
;
780 // Else try admin1 below
782 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_ADMIN1_AUTHORITY
);
783 if (Ret
== TcgResultSuccess
) {
784 CopyMem(gHiiOldPassword
, Password
, PassLength
);
785 gHiiOldPasswordLength
= PassLength
;
789 DEBUG ((DEBUG_INFO
, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
790 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Authentication Failure");
792 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
793 gHiiOldPasswordLength
= 0;
795 return EFI_NOT_READY
;
800 // New Password entered
802 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
803 Ret
= OpalSupportSetPassword(
806 gHiiOldPasswordLength
,
809 OpalDisk
->OpalDevicePath
,
813 Ret
= OpalSupportSetPassword(
816 gHiiOldPasswordLength
,
819 OpalDisk
->OpalDevicePath
,
824 if (Ret
== TcgResultSuccess
) {
825 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
829 // Reset old Password storage
831 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
832 gHiiOldPasswordLength
= 0;
834 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
835 return Ret
== TcgResultSuccess
? EFI_SUCCESS
: EFI_NOT_READY
;
839 Secure Erases Opal Disk.
841 @param OpalDisk The disk need to erase data.
842 @param Password The input password.
843 @param PassLength The input password length.
845 @retval EFI_SUCCESS Do the required action success.
851 const VOID
*Password
,
855 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
856 BOOLEAN PasswordFailed
;
858 OPAL_SESSION AdminSpSession
;
860 if (PassLength
== 0) {
861 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
864 ZeroMem(&AdminSpSession
, sizeof(AdminSpSession
));
865 AdminSpSession
.Sscp
= OpalDisk
->Sscp
;
866 AdminSpSession
.MediaId
= OpalDisk
->MediaId
;
867 AdminSpSession
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
869 Ret
= OpalUtilSecureErase(&AdminSpSession
, Password
, PassLength
, &PasswordFailed
);
870 if (Ret
== TcgResultSuccess
) {
871 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Success" );
873 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Failure" );
875 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
878 // If Password failed, return invalid passowrd
880 if (PasswordFailed
) {
881 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
882 return EFI_NOT_READY
;
886 // Indicates Password was valid and is not changing to UEFI
887 // Response string will indicate action error
889 return EFI_DEVICE_ERROR
;
894 Disables User for Opal Disk.
896 @param OpalDisk The disk need to the action.
897 @param Password The input password.
898 @param PassLength The input password length.
900 @retval EFI_SUCCESS Do the required action success.
910 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
911 BOOLEAN PasswordFailed
;
913 OPAL_SESSION Session
;
915 if (PassLength
== 0) {
916 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
919 ZeroMem(&Session
, sizeof(Session
));
920 Session
.Sscp
= OpalDisk
->Sscp
;
921 Session
.MediaId
= OpalDisk
->MediaId
;
922 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
924 Ret
= OpalSupportDisableUser(&Session
, Password
, PassLength
, &PasswordFailed
, OpalDisk
->OpalDevicePath
);
925 if (Ret
== TcgResultSuccess
) {
926 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Success" );
928 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Failure" );
930 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS
), Response
);
933 // If Password failed, return invalid passowrd
935 if (PasswordFailed
) {
936 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
937 return EFI_NOT_READY
;
941 // Indicates Password was valid and is not changing to UEFI
942 // Response string will indicate action error
944 return EFI_DEVICE_ERROR
;
948 Revert Opal Disk as Admin1.
950 @param OpalDisk The disk need to the action.
951 @param Password The input password.
952 @param PassLength The input password length.
953 @param KeepUserData Whether need to keey user data.
955 @retval EFI_SUCCESS Do the required action success.
966 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
967 BOOLEAN PasswordFailed
;
969 OPAL_SESSION Session
;
971 if (PassLength
== 0) {
972 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
973 // return error to indicate there is an existing Password
974 return EFI_DEVICE_ERROR
;
977 ZeroMem(&Session
, sizeof(Session
));
978 Session
.Sscp
= OpalDisk
->Sscp
;
979 Session
.MediaId
= OpalDisk
->MediaId
;
980 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
982 Ret
= OpalSupportRevert(
988 OpalDisk
->MsidLength
,
990 OpalDisk
->OpalDevicePath
992 if (Ret
== TcgResultSuccess
) {
993 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Success" );
995 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Failure" );
997 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1000 // If Password failed, return invalid passowrd
1002 if (PasswordFailed
) {
1003 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1004 return EFI_NOT_READY
;
1008 // Indicates Password was valid and is not changing to UEFI
1009 // Response string will indicate action error
1011 return EFI_DEVICE_ERROR
;
1017 @param OpalDisk The disk need to the action.
1018 @param Password The input password.
1019 @param PassLength The input password length.
1021 @retval EFI_SUCCESS Do the required action success.
1026 OPAL_DISK
*OpalDisk
,
1031 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
1033 OPAL_SESSION Session
;
1035 if (PassLength
== 0) {
1036 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
1037 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
1040 ZeroMem(&Session
, sizeof(Session
));
1041 Session
.Sscp
= OpalDisk
->Sscp
;
1042 Session
.MediaId
= OpalDisk
->MediaId
;
1043 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1045 Ret
= OpalSupportUnlock(&Session
, Password
, PassLength
, OpalDisk
->OpalDevicePath
);
1046 if (Ret
== TcgResultSuccess
) {
1047 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Success" );
1049 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Failure" );
1052 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1054 if (Ret
== TcgResultSuccess
) {
1055 DEBUG ((DEBUG_INFO
, "returning error to indicate Password was correct but is not changing\n"));
1056 return EFI_DEVICE_ERROR
;
1058 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1059 return EFI_NOT_READY
;
1064 Use the input password to do the specified action.
1066 @param Str The input password saved in.
1068 @retval EFI_SUCCESS Do the required action success.
1069 @retval Others Other error occur.
1077 OPAL_DISK
* OpalDisk
;
1078 CHAR8 Password
[MAX_PASSWORD_CHARACTER_LENGTH
+ 1];
1083 OpalHiiGetBrowserData();
1085 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
1086 if (OpalDisk
== NULL
) {
1087 DEBUG ((DEBUG_INFO
, "ERROR: disk %u not found\n", gHiiConfiguration
.SelectedDiskIndex
));
1088 return EFI_NOT_FOUND
;
1092 DEBUG ((DEBUG_INFO
, "ERROR: str=NULL\n"));
1093 return EFI_INVALID_PARAMETER
;
1096 ZeroMem(Password
, sizeof(Password
));
1098 UniStr
= HiiGetString(gHiiPackageListHandle
, Str
, NULL
);
1099 if (UniStr
== NULL
) {
1100 return EFI_NOT_FOUND
;
1102 PassLength
= (UINT32
) StrLen (UniStr
);
1103 if (PassLength
>= sizeof(Password
)) {
1104 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Password too long");
1105 gBS
->FreePool(UniStr
);
1106 return EFI_BUFFER_TOO_SMALL
;
1109 UnicodeStrToAsciiStr(UniStr
, Password
);
1110 gBS
->FreePool(UniStr
);
1112 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_UNLOCK
) {
1113 Status
= HiiUnlock (OpalDisk
, Password
, PassLength
);
1114 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SECURE_ERASE
) {
1115 Status
= HiiSecureErase (OpalDisk
, Password
, PassLength
);
1116 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_DISABLE_USER
) {
1117 Status
= HiiDisableUser (OpalDisk
, Password
, PassLength
);
1118 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_REVERT
) {
1119 DEBUG ((DEBUG_INFO
, "gHiiConfiguration.KeepUserData %u\n", gHiiConfiguration
.KeepUserData
));
1120 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, gHiiConfiguration
.KeepUserData
);
1122 Status
= HiiSetPassword(OpalDisk
, Password
, PassLength
);
1125 OpalHiiSetBrowserData ();
1131 Update block sid info.
1133 @param Enable Enable/disable BlockSid.
1135 @retval EFI_SUCCESS Do the required action success.
1136 @retval Others Other error occur.
1145 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
1148 Status
= EFI_SUCCESS
;
1150 OpalExtraInfo
.EnableBlockSid
= Enable
;
1151 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
1152 Status
= gRT
->SetVariable (
1153 OPAL_EXTRA_INFO_VAR_NAME
,
1154 &gOpalExtraInfoVariableGuid
,
1155 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1164 This function processes the results of changes in configuration.
1166 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1167 @param Configuration A null-terminated Unicode string in <ConfigResp>
1169 @param Progress A pointer to a string filled in with the offset of
1170 the most recent '&' before the first failing
1171 name/value pair (or the beginning of the string if
1172 the failure is in the first name/value pair) or
1173 the terminating NULL if all was successful.
1175 @retval EFI_SUCCESS The Results is processed successfully.
1176 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1177 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1184 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1185 CONST EFI_STRING Configuration
,
1186 EFI_STRING
*Progress
1189 if (Configuration
== NULL
|| Progress
== NULL
) {
1190 return (EFI_INVALID_PARAMETER
);
1197 This function allows a caller to extract the current configuration for one
1198 or more named elements from the target driver.
1200 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1201 @param Request A null-terminated Unicode string in
1202 <ConfigRequest> format.
1203 @param Progress On return, points to a character in the Request
1204 string. Points to the string's null terminator if
1205 request was successful. Points to the most recent
1206 '&' before the first failing name/value pair (or
1207 the beginning of the string if the failure is in
1208 the first name/value pair) if the request was not
1210 @param Results A null-terminated Unicode string in
1211 <ConfigAltResp> format which has all values filled
1212 in for the names in the Request string. String to
1213 be allocated by the called function.
1215 @retval EFI_SUCCESS The Results is filled with the requested values.
1216 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1217 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1218 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1225 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1226 CONST EFI_STRING Request
,
1227 EFI_STRING
*Progress
,
1234 // Check for valid parameters
1236 if (Progress
== NULL
|| Results
== NULL
) {
1237 return (EFI_INVALID_PARAMETER
);
1241 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1243 Status
= gHiiConfigRouting
->BlockToConfig(
1246 (UINT8
*)&gHiiConfiguration
,
1247 sizeof(OPAL_HII_CONFIGURATION
),
1258 Pass the current system state to the bios via the hii_G_Configuration.
1262 OpalHiiSetBrowserData (
1267 &gHiiSetupVariableGuid
,
1268 (CHAR16
*)L
"OpalHiiConfig",
1269 sizeof(gHiiConfiguration
),
1270 (UINT8
*)&gHiiConfiguration
,
1278 Populate the hii_g_Configuraton with the browser Data.
1282 OpalHiiGetBrowserData (
1287 &gHiiSetupVariableGuid
,
1288 (CHAR16
*)L
"OpalHiiConfig",
1289 sizeof(gHiiConfiguration
),
1290 (UINT8
*)&gHiiConfiguration
1295 Set a string Value in a form.
1297 @param DestStringId The stringid which need to update.
1298 @param SrcAsciiStr The string nned to update.
1300 @retval EFI_SUCCESS Do the required action success.
1301 @retval Others Other error occur.
1306 EFI_STRING_ID DestStringId
,
1315 // Determine the Length of the sting
1317 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1320 // Allocate space for the unicode string, including terminator
1322 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1323 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1326 // Copy into unicode string, then copy into string id
1328 AsciiStrToUnicodeStr( SrcAsciiStr
, UniStr
);
1331 // Update the string in the form
1333 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1334 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1336 return (EFI_OUT_OF_RESOURCES
);
1344 return (EFI_SUCCESS
);
1348 Initialize the Opal disk base on the hardware info get from device.
1350 @param Dev The Opal device.
1352 @retval EFI_SUCESS Initialize the device success.
1353 @retval EFI_DEVICE_ERROR Get info from device failed.
1357 OpalDiskInitialize (
1358 IN OPAL_DRIVER_DEVICE
*Dev
1361 TCG_RESULT TcgResult
;
1362 OPAL_SESSION Session
;
1364 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1365 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1366 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1367 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1369 ZeroMem(&Session
, sizeof(Session
));
1370 Session
.Sscp
= Dev
->Sscp
;
1371 Session
.MediaId
= Dev
->MediaId
;
1373 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1374 if (TcgResult
!= TcgResultSuccess
) {
1375 return EFI_DEVICE_ERROR
;
1377 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1379 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1380 if (TcgResult
!= TcgResultSuccess
) {
1381 return EFI_DEVICE_ERROR
;
1384 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1388 Update the device info.
1390 @param OpalDisk The Opal device.
1392 @retval EFI_SUCESS Initialize the device success.
1393 @retval EFI_DEVICE_ERROR Get info from device failed.
1394 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1398 OpalDiskUpdateStatus (
1402 TCG_RESULT TcgResult
;
1403 OPAL_SESSION Session
;
1405 ZeroMem(&Session
, sizeof(Session
));
1406 Session
.Sscp
= OpalDisk
->Sscp
;
1407 Session
.MediaId
= OpalDisk
->MediaId
;
1408 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1410 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1411 if (TcgResult
!= TcgResultSuccess
) {
1412 return EFI_DEVICE_ERROR
;
1415 if (OpalDisk
->MsidLength
== 0) {
1416 return EFI_INVALID_PARAMETER
;
1419 // Base on the Msid info to get the ownership, so Msid info must get first.
1421 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);