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 Install the HII related resources.
113 @retval EFI_SUCCESS Install all the resources success.
114 @retval other Error occur when install the resources.
122 EFI_HANDLE DriverHandle
;
125 // Clear the global configuration.
127 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
130 // Obtain the driver handle that the BIOS assigned us
132 DriverHandle
= HiiGetDriverImageHandleCB();
135 // Populate the config access protocol with the three functions we are publishing
137 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
138 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
139 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
142 // Associate the required protocols with our driver handle
144 Status
= gBS
->InstallMultipleProtocolInterfaces(
146 &gEfiHiiConfigAccessProtocolGuid
,
147 &gHiiConfigAccessProtocol
, // HII callback
148 &gEfiDevicePathProtocolGuid
,
149 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
153 if (EFI_ERROR(Status
)) {
157 return OpalHiiAddPackages();
161 Install the HII form and string packages.
163 @retval EFI_SUCCESS Install all the resources success.
164 @retval EFI_OUT_OF_RESOURCES Out of resource error.
171 EFI_HANDLE DriverHandle
;
174 DriverHandle
= HiiGetDriverImageHandleCB();
177 // Publish the HII form and HII string packages
179 gHiiPackageListHandle
= HiiAddPackages(
180 &gHiiPackageListGuid
,
182 OpalPasswordDxeStrings
,
188 // Make sure the packages installed successfully
190 if (gHiiPackageListHandle
== NULL
) {
191 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
192 return EFI_OUT_OF_RESOURCES
;
196 // Update Version String in main window
198 NewString
= HiiGetDriverNameCB ();
199 if (HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_MAIN_OPAL_VERSION
), NewString
, NULL
) == 0) {
200 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
201 return EFI_OUT_OF_RESOURCES
;
208 Uninstall the HII capability.
210 @retval EFI_SUCCESS Uninstall all the resources success.
211 @retval others Other errors occur when unistall the hii resource.
221 // Remove the packages we've provided to the BIOS
223 HiiRemovePackages(gHiiPackageListHandle
);
226 // Remove the protocols from our driver handle
228 Status
= gBS
->UninstallMultipleProtocolInterfaces(
229 HiiGetDriverImageHandleCB(),
230 &gEfiHiiConfigAccessProtocolGuid
,
231 &gHiiConfigAccessProtocol
, // HII callback
232 &gEfiDevicePathProtocolGuid
,
233 &gHiiVendorDevicePath
, // required for HII callback
236 if (EFI_ERROR(Status
)) {
237 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
244 Updates the main menu form.
246 @retval EFI_SUCCESS update the main form success.
249 HiiPopulateMainMenuForm (
255 EFI_STRING_ID DiskNameId
;
258 HiiSetCurrentConfiguration();
260 gHiiConfiguration
.SupportedDisks
= 0;
262 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
263 OpalDisk
= HiiGetOpalDiskCB (Index
);
264 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
265 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
266 DiskNameId
= GetDiskNameStringId (Index
);
267 DiskName
= HiiDiskGetNameCB (Index
);
268 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
269 return EFI_UNSUPPORTED
;
271 HiiSetFormString(DiskNameId
, DiskName
);
275 OpalHiiSetBrowserData ();
280 Update the disk action info.
283 @param SelectedAction
285 @retval EFI_SUCCESS Uninstall all the resources success.
288 HiiSelectDiskAction (
294 OPAL_DISK_ACTIONS AvailActions
;
296 OpalHiiGetBrowserData ();
298 HiiSetFormString(STRING_TOKEN(STR_DISK_ACTION_LBL
), ActionString
);
299 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), " ");
301 gHiiConfiguration
.SelectedAction
= SelectedAction
;
302 gHiiConfiguration
.AvailableFields
= 0;
304 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
305 if (OpalDisk
== NULL
) {
306 return EFI_INVALID_PARAMETER
;
309 if (OpalSupportGetAvailableActions (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
) != TcgResultSuccess
) {
310 return EFI_DEVICE_ERROR
;
313 switch (SelectedAction
) {
314 case HII_KEY_ID_GOTO_LOCK
:
315 case HII_KEY_ID_GOTO_UNLOCK
:
316 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
317 case HII_KEY_ID_GOTO_SET_USER_PWD
:
318 case HII_KEY_ID_GOTO_SECURE_ERASE
:
319 case HII_KEY_ID_GOTO_DISABLE_USER
:
320 case HII_KEY_ID_GOTO_ENABLE_FEATURE
: // User is required to enter Password to enable Feature
321 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
324 case HII_KEY_ID_GOTO_PSID_REVERT
:
325 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PSID
;
328 case HII_KEY_ID_GOTO_REVERT
:
329 gHiiConfiguration
.AvailableFields
|= HII_FIELD_PASSWORD
;
330 if (OpalDisk
->SupportedAttributes
.PyriteSsc
!= 1) {
332 // According to current Pyrite SSC Spec 1.00, there is no parameter for RevertSP method.
333 // So issue RevertSP method without any parameter by suppress KeepUserData option.
335 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA
;
337 if (AvailActions
.RevertKeepDataForced
) {
338 gHiiConfiguration
.AvailableFields
|= HII_FIELD_KEEP_USER_DATA_FORCED
;
343 OpalHiiSetBrowserData ();
349 Get disk name string id.
351 @param DiskIndex The input disk index info.
353 @retval The disk name string id.
362 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
363 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
364 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
365 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
366 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
367 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
373 This function processes the results of changes in configuration.
375 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
376 @param Action Specifies the type of action taken by the browser.
377 @param QuestionId A unique value which is sent to the original
378 exporting driver so that it can identify the type
380 @param Type The type of value for the question.
381 @param Value A pointer to the data being sent to the original
383 @param ActionRequest On return, points to the action requested by the
386 @retval EFI_SUCCESS The callback successfully handled the action.
387 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
388 variable and its data.
389 @retval EFI_DEVICE_ERROR The variable could not be saved.
390 @retval EFI_UNSUPPORTED The specified Action is not supported by the
397 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
398 EFI_BROWSER_ACTION Action
,
399 EFI_QUESTION_ID QuestionId
,
401 EFI_IFR_TYPE_VALUE
*Value
,
402 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
408 if (ActionRequest
!= NULL
) {
409 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
411 return EFI_INVALID_PARAMETER
;
415 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
417 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
421 HiiKey
.Raw
= QuestionId
;
422 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
424 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
426 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
427 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
428 return HiiPopulateMainMenuForm ();
430 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
431 return HiiPopulateDiskInfoForm();
433 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
435 case HII_KEY_ID_GOTO_DISK_INFO
:
436 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
438 case HII_KEY_ID_GOTO_LOCK
:
439 return HiiSelectDiskAction("Action: Lock", HiiKeyId
);
441 case HII_KEY_ID_GOTO_UNLOCK
:
442 return HiiSelectDiskAction("Action: Unlock", HiiKeyId
);
444 case HII_KEY_ID_GOTO_SET_ADMIN_PWD
:
445 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId
);
447 case HII_KEY_ID_GOTO_SET_USER_PWD
:
448 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId
);
450 case HII_KEY_ID_GOTO_SECURE_ERASE
:
451 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId
);
453 case HII_KEY_ID_GOTO_PSID_REVERT
:
454 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId
);
456 case HII_KEY_ID_GOTO_REVERT
:
457 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId
);
459 case HII_KEY_ID_GOTO_DISABLE_USER
:
460 return HiiSelectDiskAction("Action: Disable User", HiiKeyId
);
462 case HII_KEY_ID_GOTO_ENABLE_FEATURE
:
463 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId
);
465 case HII_KEY_ID_ENTER_PASSWORD
:
466 return HiiPasswordEntered(Value
->string
);
468 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
470 case HII_KEY_ID_ENTER_PSID
:
472 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
475 case HII_KEY_ID_BLOCKSID
:
476 HiiSetBlockSid(Value
->b
);
477 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
482 return EFI_UNSUPPORTED
;
486 Update the global Disk index info.
488 @param Index The input disk index info.
490 @retval EFI_SUCCESS Update the disk index info success.
498 OpalHiiGetBrowserData();
499 gHiiConfiguration
.SelectedDiskIndex
= Index
;
500 OpalHiiSetBrowserData ();
506 Draws the disk info form.
508 @retval EFI_SUCCESS Draw the disk info success.
512 HiiPopulateDiskInfoForm(
517 OPAL_DISK_ACTIONS AvailActions
;
521 OpalHiiGetBrowserData();
523 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
524 if (DiskName
== NULL
) {
525 return EFI_UNSUPPORTED
;
527 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
529 ZeroMem(gHiiConfiguration
.Psid
, sizeof(gHiiConfiguration
.Psid
));
531 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
533 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
535 if (OpalDisk
!= NULL
) {
536 OpalDiskUpdateStatus (OpalDisk
);
537 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
538 if (Ret
== TcgResultSuccess
) {
540 // Update actions, always allow PSID Revert
542 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
545 // Always allow unlock to handle device migration
547 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
549 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
550 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
551 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
556 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
558 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
561 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
562 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
563 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
564 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
565 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
567 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
570 // Determine revert options for disk
571 // Default initialize keep user Data to be true
573 gHiiConfiguration
.KeepUserData
= 1;
574 if (OpalDisk
->SupportedAttributes
.PyriteSsc
== 1) {
576 // According to current Pyrite SSC Spec 1.00, there is no parameter for RevertSP method.
577 // So issue RevertSP method without any parameter by set default value to FALSE.
579 gHiiConfiguration
.KeepUserData
= 0;
587 // Pass the current configuration to the BIOS
589 OpalHiiSetBrowserData ();
595 Reverts the Opal disk to factory default.
597 @retval EFI_SUCCESS Do the required action success.
605 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
609 OPAL_SESSION Session
;
611 Ret
= TcgResultFailure
;
613 OpalHiiGetBrowserData();
615 UnicodeStrToAsciiStr(gHiiConfiguration
.Psid
, (CHAR8
*)Psid
.Psid
);
617 OpalDisk
= HiiGetOpalDiskCB (gHiiConfiguration
.SelectedDiskIndex
);
618 if (OpalDisk
!= NULL
) {
619 ZeroMem(&Session
, sizeof(Session
));
620 Session
.Sscp
= OpalDisk
->Sscp
;
621 Session
.MediaId
= OpalDisk
->MediaId
;
622 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
624 Ret
= OpalSupportPsidRevert(&Session
, Psid
.Psid
, (UINT32
)sizeof(Psid
.Psid
), OpalDisk
->OpalDevicePath
);
627 if (Ret
== TcgResultSuccess
) {
628 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Success" );
630 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "PSID Revert: Failure" );
633 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
639 Set password for the disk.
641 @param OpalDisk The disk need to set the password.
642 @param Password The input password.
643 @param PassLength The input password length.
645 @retval EFI_SUCCESS Do the required action success.
655 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
657 BOOLEAN ExistingPassword
;
658 OPAL_SESSION Session
;
660 ExistingPassword
= FALSE
;
663 // PassLength = 0 means check whether exist old password.
665 if (PassLength
== 0) {
666 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
667 gHiiOldPasswordLength
= 0;
669 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_ENABLE_FEATURE
) {
670 ExistingPassword
= FALSE
;
671 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_ADMIN_PWD
) {
672 ExistingPassword
= OpalUtilAdminPasswordExists(OpalDisk
->Owner
, &OpalDisk
->LockingFeature
);
673 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
675 // Set user Password option shall only be shown if an Admin Password exists
676 // so a Password is always required (Admin or Existing User Password)
678 ExistingPassword
= TRUE
;
682 // Return error if there is a previous Password
683 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
685 return ExistingPassword
? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
688 ZeroMem(&Session
, sizeof(Session
));
689 Session
.Sscp
= OpalDisk
->Sscp
;
690 Session
.MediaId
= OpalDisk
->MediaId
;
691 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
693 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Failure");
696 // No current Owner, so set new Password, must be admin Password
698 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
699 Ret
= OpalSupportEnableOpalFeature (&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
,Password
, PassLength
, OpalDisk
->OpalDevicePath
);
700 if (Ret
== TcgResultSuccess
) {
701 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
704 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
709 // 1st Password entered
711 if (OpalDisk
->Owner
== OpalOwnershipUnknown
&& gHiiOldPasswordLength
== 0) {
714 // Unknown ownership - prompt for old Password, then new
715 // old Password is not set yet - first time through
716 // assume authority provided is admin1, overwritten if user1 authority works below
718 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
720 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
722 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_USER1_AUTHORITY
);
723 if (Ret
== TcgResultSuccess
) {
725 // User1 worked so authority 1 means user 1
727 CopyMem(gHiiOldPassword
, Password
, PassLength
);
728 gHiiOldPasswordLength
= PassLength
;
735 // Else try admin1 below
737 Ret
= OpalUtilVerifyPassword (&Session
, Password
, PassLength
, OPAL_LOCKING_SP_ADMIN1_AUTHORITY
);
738 if (Ret
== TcgResultSuccess
) {
739 CopyMem(gHiiOldPassword
, Password
, PassLength
);
740 gHiiOldPasswordLength
= PassLength
;
744 DEBUG ((DEBUG_INFO
, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
745 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Authentication Failure");
747 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
748 gHiiOldPasswordLength
= 0;
750 return EFI_NOT_READY
;
755 // New Password entered
757 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SET_USER_PWD
) {
758 Ret
= OpalSupportSetPassword(
761 gHiiOldPasswordLength
,
764 OpalDisk
->OpalDevicePath
,
768 Ret
= OpalSupportSetPassword(
771 gHiiOldPasswordLength
,
774 OpalDisk
->OpalDevicePath
,
779 if (Ret
== TcgResultSuccess
) {
780 AsciiSPrint(Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Set Password: Success");
784 // Reset old Password storage
786 ZeroMem(gHiiOldPassword
, sizeof(gHiiOldPassword
));
787 gHiiOldPasswordLength
= 0;
789 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
790 return Ret
== TcgResultSuccess
? EFI_SUCCESS
: EFI_NOT_READY
;
794 Secure Erases Opal Disk.
796 @param OpalDisk The disk need to erase data.
797 @param Password The input password.
798 @param PassLength The input password length.
800 @retval EFI_SUCCESS Do the required action success.
806 const VOID
*Password
,
810 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
811 BOOLEAN PasswordFailed
;
813 OPAL_SESSION AdminSpSession
;
815 if (PassLength
== 0) {
816 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
819 ZeroMem(&AdminSpSession
, sizeof(AdminSpSession
));
820 AdminSpSession
.Sscp
= OpalDisk
->Sscp
;
821 AdminSpSession
.MediaId
= OpalDisk
->MediaId
;
822 AdminSpSession
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
824 Ret
= OpalUtilSecureErase(&AdminSpSession
, Password
, PassLength
, &PasswordFailed
);
825 if (Ret
== TcgResultSuccess
) {
826 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Success" );
828 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Secure Erase: Failure" );
830 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
833 // If Password failed, return invalid passowrd
835 if (PasswordFailed
) {
836 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
837 return EFI_NOT_READY
;
841 // Indicates Password was valid and is not changing to UEFI
842 // Response string will indicate action error
844 return EFI_DEVICE_ERROR
;
849 Disables User for Opal Disk.
851 @param OpalDisk The disk need to the action.
852 @param Password The input password.
853 @param PassLength The input password length.
855 @retval EFI_SUCCESS Do the required action success.
865 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
866 BOOLEAN PasswordFailed
;
868 OPAL_SESSION Session
;
870 if (PassLength
== 0) {
871 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
874 ZeroMem(&Session
, sizeof(Session
));
875 Session
.Sscp
= OpalDisk
->Sscp
;
876 Session
.MediaId
= OpalDisk
->MediaId
;
877 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
879 Ret
= OpalSupportDisableUser(&Session
, Password
, PassLength
, &PasswordFailed
, OpalDisk
->OpalDevicePath
);
880 if (Ret
== TcgResultSuccess
) {
881 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Success" );
883 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Disable User: Failure" );
885 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS
), Response
);
888 // If Password failed, return invalid passowrd
890 if (PasswordFailed
) {
891 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
892 return EFI_NOT_READY
;
896 // Indicates Password was valid and is not changing to UEFI
897 // Response string will indicate action error
899 return EFI_DEVICE_ERROR
;
903 Revert Opal Disk as Admin1.
905 @param OpalDisk The disk need to the action.
906 @param Password The input password.
907 @param PassLength The input password length.
908 @param KeepUserData Whether need to keey user data.
910 @retval EFI_SUCCESS Do the required action success.
921 CHAR8 Response
[ DEFAULT_RESPONSE_SIZE
];
922 BOOLEAN PasswordFailed
;
924 OPAL_SESSION Session
;
926 if (PassLength
== 0) {
927 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
928 // return error to indicate there is an existing Password
929 return EFI_DEVICE_ERROR
;
932 ZeroMem(&Session
, sizeof(Session
));
933 Session
.Sscp
= OpalDisk
->Sscp
;
934 Session
.MediaId
= OpalDisk
->MediaId
;
935 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
937 Ret
= OpalSupportRevert(
943 OpalDisk
->MsidLength
,
945 OpalDisk
->OpalDevicePath
947 if (Ret
== TcgResultSuccess
) {
948 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Success" );
950 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Revert: Failure" );
952 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
955 // If Password failed, return invalid passowrd
957 if (PasswordFailed
) {
958 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
959 return EFI_NOT_READY
;
963 // Indicates Password was valid and is not changing to UEFI
964 // Response string will indicate action error
966 return EFI_DEVICE_ERROR
;
972 @param OpalDisk The disk need to the action.
973 @param Password The input password.
974 @param PassLength The input password length.
976 @retval EFI_SUCCESS Do the required action success.
986 CHAR8 Response
[DEFAULT_RESPONSE_SIZE
];
988 OPAL_SESSION Session
;
990 if (PassLength
== 0) {
991 DEBUG ((DEBUG_INFO
, "Returning error to indicate there is an existing Password\n"));
992 return EFI_DEVICE_ERROR
; // return error to indicate there is an existing Password
995 ZeroMem(&Session
, sizeof(Session
));
996 Session
.Sscp
= OpalDisk
->Sscp
;
997 Session
.MediaId
= OpalDisk
->MediaId
;
998 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1000 Ret
= OpalSupportUnlock(&Session
, Password
, PassLength
, OpalDisk
->OpalDevicePath
);
1001 if (Ret
== TcgResultSuccess
) {
1002 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Success" );
1004 AsciiSPrint( Response
, DEFAULT_RESPONSE_SIZE
, "%a", "Unlock: Failure" );
1007 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), Response
);
1009 if (Ret
== TcgResultSuccess
) {
1010 DEBUG ((DEBUG_INFO
, "returning error to indicate Password was correct but is not changing\n"));
1011 return EFI_DEVICE_ERROR
;
1013 DEBUG ((DEBUG_INFO
, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1014 return EFI_NOT_READY
;
1019 Use the input password to do the specified action.
1021 @param Str The input password saved in.
1023 @retval EFI_SUCCESS Do the required action success.
1024 @retval Others Other error occur.
1032 OPAL_DISK
* OpalDisk
;
1033 CHAR8 Password
[MAX_PASSWORD_CHARACTER_LENGTH
+ 1];
1038 OpalHiiGetBrowserData();
1040 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
1041 if (OpalDisk
== NULL
) {
1042 DEBUG ((DEBUG_INFO
, "ERROR: disk %u not found\n", gHiiConfiguration
.SelectedDiskIndex
));
1043 return EFI_NOT_FOUND
;
1047 DEBUG ((DEBUG_INFO
, "ERROR: str=NULL\n"));
1048 return EFI_INVALID_PARAMETER
;
1051 ZeroMem(Password
, sizeof(Password
));
1053 UniStr
= HiiGetString(gHiiPackageListHandle
, Str
, NULL
);
1054 if (UniStr
== NULL
) {
1055 return EFI_NOT_FOUND
;
1057 PassLength
= (UINT32
) StrLen (UniStr
);
1058 if (PassLength
>= sizeof(Password
)) {
1059 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS
), "Password too long");
1060 gBS
->FreePool(UniStr
);
1061 return EFI_BUFFER_TOO_SMALL
;
1064 UnicodeStrToAsciiStr(UniStr
, Password
);
1065 gBS
->FreePool(UniStr
);
1067 if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_UNLOCK
) {
1068 Status
= HiiUnlock (OpalDisk
, Password
, PassLength
);
1069 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_SECURE_ERASE
) {
1070 Status
= HiiSecureErase (OpalDisk
, Password
, PassLength
);
1071 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_DISABLE_USER
) {
1072 Status
= HiiDisableUser (OpalDisk
, Password
, PassLength
);
1073 } else if (gHiiConfiguration
.SelectedAction
== HII_KEY_ID_GOTO_REVERT
) {
1074 DEBUG ((DEBUG_INFO
, "gHiiConfiguration.KeepUserData %u\n", gHiiConfiguration
.KeepUserData
));
1075 Status
= HiiRevert(OpalDisk
, Password
, PassLength
, gHiiConfiguration
.KeepUserData
);
1077 Status
= HiiSetPassword(OpalDisk
, Password
, PassLength
);
1080 OpalHiiSetBrowserData ();
1086 Update block sid info.
1088 @param Enable Enable/disable BlockSid.
1090 @retval EFI_SUCCESS Do the required action success.
1091 @retval Others Other error occur.
1100 OPAL_EXTRA_INFO_VAR OpalExtraInfo
;
1103 Status
= EFI_SUCCESS
;
1105 OpalExtraInfo
.EnableBlockSid
= Enable
;
1106 DataSize
= sizeof (OPAL_EXTRA_INFO_VAR
);
1107 Status
= gRT
->SetVariable (
1108 OPAL_EXTRA_INFO_VAR_NAME
,
1109 &gOpalExtraInfoVariableGuid
,
1110 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1119 This function processes the results of changes in configuration.
1121 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1122 @param Configuration A null-terminated Unicode string in <ConfigResp>
1124 @param Progress A pointer to a string filled in with the offset of
1125 the most recent '&' before the first failing
1126 name/value pair (or the beginning of the string if
1127 the failure is in the first name/value pair) or
1128 the terminating NULL if all was successful.
1130 @retval EFI_SUCCESS The Results is processed successfully.
1131 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1132 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1139 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1140 CONST EFI_STRING Configuration
,
1141 EFI_STRING
*Progress
1144 if (Configuration
== NULL
|| Progress
== NULL
) {
1145 return (EFI_INVALID_PARAMETER
);
1152 This function allows a caller to extract the current configuration for one
1153 or more named elements from the target driver.
1155 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1156 @param Request A null-terminated Unicode string in
1157 <ConfigRequest> format.
1158 @param Progress On return, points to a character in the Request
1159 string. Points to the string's null terminator if
1160 request was successful. Points to the most recent
1161 '&' before the first failing name/value pair (or
1162 the beginning of the string if the failure is in
1163 the first name/value pair) if the request was not
1165 @param Results A null-terminated Unicode string in
1166 <ConfigAltResp> format which has all values filled
1167 in for the names in the Request string. String to
1168 be allocated by the called function.
1170 @retval EFI_SUCCESS The Results is filled with the requested values.
1171 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1172 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1173 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1180 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1181 CONST EFI_STRING Request
,
1182 EFI_STRING
*Progress
,
1189 // Check for valid parameters
1191 if (Progress
== NULL
|| Results
== NULL
) {
1192 return (EFI_INVALID_PARAMETER
);
1196 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1198 Status
= gHiiConfigRouting
->BlockToConfig(
1201 (UINT8
*)&gHiiConfiguration
,
1202 sizeof(OPAL_HII_CONFIGURATION
),
1213 Pass the current system state to the bios via the hii_G_Configuration.
1217 OpalHiiSetBrowserData (
1222 &gHiiSetupVariableGuid
,
1223 (CHAR16
*)L
"OpalHiiConfig",
1224 sizeof(gHiiConfiguration
),
1225 (UINT8
*)&gHiiConfiguration
,
1233 Populate the hii_g_Configuraton with the browser Data.
1237 OpalHiiGetBrowserData (
1242 &gHiiSetupVariableGuid
,
1243 (CHAR16
*)L
"OpalHiiConfig",
1244 sizeof(gHiiConfiguration
),
1245 (UINT8
*)&gHiiConfiguration
1250 Set a string Value in a form.
1252 @param DestStringId The stringid which need to update.
1253 @param SrcAsciiStr The string nned to update.
1255 @retval EFI_SUCCESS Do the required action success.
1256 @retval Others Other error occur.
1261 EFI_STRING_ID DestStringId
,
1270 // Determine the Length of the sting
1272 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1275 // Allocate space for the unicode string, including terminator
1277 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1278 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1281 // Copy into unicode string, then copy into string id
1283 AsciiStrToUnicodeStr( SrcAsciiStr
, UniStr
);
1286 // Update the string in the form
1288 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1289 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1291 return (EFI_OUT_OF_RESOURCES
);
1299 return (EFI_SUCCESS
);
1303 Initialize the Opal disk base on the hardware info get from device.
1305 @param Dev The Opal device.
1307 @retval EFI_SUCESS Initialize the device success.
1308 @retval EFI_DEVICE_ERROR Get info from device failed.
1312 OpalDiskInitialize (
1313 IN OPAL_DRIVER_DEVICE
*Dev
1316 TCG_RESULT TcgResult
;
1317 OPAL_SESSION Session
;
1319 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1320 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1321 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1322 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1324 ZeroMem(&Session
, sizeof(Session
));
1325 Session
.Sscp
= Dev
->Sscp
;
1326 Session
.MediaId
= Dev
->MediaId
;
1328 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1329 if (TcgResult
!= TcgResultSuccess
) {
1330 return EFI_DEVICE_ERROR
;
1332 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1334 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1335 if (TcgResult
!= TcgResultSuccess
) {
1336 return EFI_DEVICE_ERROR
;
1339 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1343 Update the device info.
1345 @param OpalDisk The Opal device.
1347 @retval EFI_SUCESS Initialize the device success.
1348 @retval EFI_DEVICE_ERROR Get info from device failed.
1349 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1353 OpalDiskUpdateStatus (
1357 TCG_RESULT TcgResult
;
1358 OPAL_SESSION Session
;
1360 ZeroMem(&Session
, sizeof(Session
));
1361 Session
.Sscp
= OpalDisk
->Sscp
;
1362 Session
.MediaId
= OpalDisk
->MediaId
;
1363 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1365 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1366 if (TcgResult
!= TcgResultSuccess
) {
1367 return EFI_DEVICE_ERROR
;
1370 if (OpalDisk
->MsidLength
== 0) {
1371 return EFI_INVALID_PARAMETER
;
1374 // Base on the Msid info to get the ownership, so Msid info must get first.
1376 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);