TianoCore EDK2 master
Loading...
Searching...
No Matches
OpalDriver.c
Go to the documentation of this file.
1
10// This UEFI driver consumes EFI_STORAGE_SECURITY_PROTOCOL instances and installs an
11// HII GUI to manage Opal features if the device is Opal capable
12// If the Opal device is being managed by the UEFI Driver, it shall provide a popup
13// window during boot requesting a user password
14
15#include "OpalDriver.h"
16#include "OpalHii.h"
17
18EFI_GUID mOpalDeviceLockBoxGuid = OPAL_DEVICE_LOCKBOX_GUID;
19
20BOOLEAN mOpalEndOfDxe = FALSE;
21OPAL_REQUEST_VARIABLE *mOpalRequestVariable = NULL;
22UINTN mOpalRequestVariableSize = 0;
23CHAR16 mPopUpString[100];
24
25OPAL_DRIVER mOpalDriver;
26
27//
28// Globals
29//
30EFI_DRIVER_BINDING_PROTOCOL gOpalDriverBinding = {
34 0x1b,
35 NULL,
36 NULL
37};
38
50EFIAPI
52 IN OPAL_DISK_SUPPORT_ATTRIBUTE *SupportedAttributes,
53 IN TCG_LOCKING_FEATURE_DESCRIPTOR *LockingFeature,
54 IN UINT16 OwnerShip,
55 OUT OPAL_DISK_ACTIONS *AvalDiskActions
56 )
57{
58 BOOLEAN ExistingPassword;
59
60 NULL_CHECK (AvalDiskActions);
61
62 AvalDiskActions->AdminPass = 1;
63 AvalDiskActions->UserPass = 0;
64 AvalDiskActions->DisableUser = 0;
65 AvalDiskActions->Unlock = 0;
66
67 //
68 // Revert is performed on locking sp, so only allow if locking sp is enabled
69 //
70 if (LockingFeature->LockingEnabled) {
71 AvalDiskActions->Revert = 1;
72 }
73
74 //
75 // Psid revert is available for any device with media encryption support or pyrite 2.0 type support.
76 //
77 if (SupportedAttributes->PyriteSscV2 || SupportedAttributes->MediaEncryption) {
78 //
79 // Only allow psid revert if media encryption is enabled or pyrite 2.0 type support..
80 // Otherwise, someone who steals a disk can psid revert the disk and the user Data is still
81 // intact and accessible
82 //
83 AvalDiskActions->PsidRevert = 1;
84 AvalDiskActions->RevertKeepDataForced = 0;
85
86 //
87 // Secure erase is performed by generating a new encryption key
88 // this is only available if encryption is supported
89 //
90 if (SupportedAttributes->MediaEncryption) {
91 AvalDiskActions->SecureErase = 1;
92 } else {
93 AvalDiskActions->SecureErase = 0;
94 }
95 } else {
96 AvalDiskActions->PsidRevert = 0;
97 AvalDiskActions->SecureErase = 0;
98
99 //
100 // If no media encryption is supported, then a revert (using password) will not
101 // erase the Data (since you can't generate a new encryption key)
102 //
103 AvalDiskActions->RevertKeepDataForced = 1;
104 }
105
106 if (LockingFeature->Locked) {
107 AvalDiskActions->Unlock = 1;
108 } else {
109 AvalDiskActions->Unlock = 0;
110 }
111
112 //
113 // Only allow user to set password if an admin password exists
114 //
115 ExistingPassword = OpalUtilAdminPasswordExists (OwnerShip, LockingFeature);
116 AvalDiskActions->UserPass = ExistingPassword;
117
118 //
119 // This will still show up even if there isn't a user, which is fine
120 //
121 AvalDiskActions->DisableUser = ExistingPassword;
122
123 return TcgResultSuccess;
124}
125
137EFIAPI
139 IN OPAL_SESSION *Session,
140 IN VOID *Msid,
141 IN UINT32 MsidLength,
142 IN VOID *Password,
143 IN UINT32 PassLength
144 )
145{
146 TCG_RESULT Ret;
147
148 NULL_CHECK (Session);
149 NULL_CHECK (Msid);
150 NULL_CHECK (Password);
151
153 Session,
154 Msid,
155 MsidLength,
156 Password,
157 PassLength
158 );
159 if (Ret == TcgResultSuccess) {
160 //
161 // Enable global locking range
162 //
164 Session,
165 Password,
166 PassLength,
167 OPAL_LOCKING_SP_LOCKING_GLOBALRANGE,
168 0,
169 0,
170 TRUE,
171 TRUE,
172 FALSE,
173 FALSE
174 );
175 }
176
177 return Ret;
178}
179
188VOID
190 IN OUT OPAL_DISK *OpalDisk,
191 IN VOID *Password,
192 IN UINT32 PasswordLength
193 )
194{
195 CopyMem (OpalDisk->Password, Password, PasswordLength);
196 OpalDisk->PasswordLength = (UINT8)PasswordLength;
197}
198
207VOID
209 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
210 OUT UINT32 *DevInfoLength,
211 OUT OPAL_DEVICE_LOCKBOX_DATA *DevInfo OPTIONAL
212 )
213{
214 EFI_DEVICE_PATH_PROTOCOL *TmpDevPath;
215 EFI_DEVICE_PATH_PROTOCOL *TmpDevPath2;
216 PCI_DEVICE_PATH *PciDevPath;
217 UINT8 DeviceType;
218 UINT8 BusNum;
219 OPAL_PCI_DEVICE *PciDevice;
220
221 ASSERT (DevicePath != NULL);
222 ASSERT (DevInfoLength != NULL);
223
224 DeviceType = OPAL_DEVICE_TYPE_UNKNOWN;
225 *DevInfoLength = 0;
226
227 TmpDevPath = DevicePath;
228
229 //
230 // Get device type.
231 //
232 while (!IsDevicePathEnd (TmpDevPath)) {
233 if ((TmpDevPath->Type == MESSAGING_DEVICE_PATH) &&
234 ((TmpDevPath->SubType == MSG_SATA_DP) || (TmpDevPath->SubType == MSG_NVME_NAMESPACE_DP)))
235 {
236 if (DevInfo != NULL) {
237 DevInfo->DevicePathLength = (UINT32)GetDevicePathSize (DevicePath);
238 CopyMem (DevInfo->DevicePath, DevicePath, DevInfo->DevicePathLength);
239 }
240
241 DeviceType = (TmpDevPath->SubType == MSG_SATA_DP) ? OPAL_DEVICE_TYPE_ATA : OPAL_DEVICE_TYPE_NVME;
242 *DevInfoLength = sizeof (OPAL_DEVICE_LOCKBOX_DATA) + (UINT32)GetDevicePathSize (DevicePath);
243 break;
244 }
245
246 TmpDevPath = NextDevicePathNode (TmpDevPath);
247 }
248
249 //
250 // Get device info.
251 //
252 BusNum = 0;
253 TmpDevPath = DevicePath;
254 TmpDevPath2 = NextDevicePathNode (DevicePath);
255 while (!IsDevicePathEnd (TmpDevPath2)) {
256 if ((TmpDevPath->Type == HARDWARE_DEVICE_PATH) && (TmpDevPath->SubType == HW_PCI_DP)) {
257 PciDevPath = (PCI_DEVICE_PATH *)TmpDevPath;
258 if ((TmpDevPath2->Type == MESSAGING_DEVICE_PATH) &&
259 ((TmpDevPath2->SubType == MSG_SATA_DP) || (TmpDevPath2->SubType == MSG_NVME_NAMESPACE_DP)))
260 {
261 if (DevInfo != NULL) {
262 PciDevice = &DevInfo->Device;
263 PciDevice->Segment = 0;
264 PciDevice->Bus = BusNum;
265 PciDevice->Device = PciDevPath->Device;
266 PciDevice->Function = PciDevPath->Function;
267 }
268 } else {
269 if ((TmpDevPath2->Type == HARDWARE_DEVICE_PATH) && (TmpDevPath2->SubType == HW_PCI_DP)) {
270 BusNum = PciRead8 (PCI_LIB_ADDRESS (BusNum, PciDevPath->Device, PciDevPath->Function, PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET));
271 }
272 }
273 }
274
275 TmpDevPath = NextDevicePathNode (TmpDevPath);
276 TmpDevPath2 = NextDevicePathNode (TmpDevPath2);
277 }
278
279 ASSERT (DeviceType != OPAL_DEVICE_TYPE_UNKNOWN);
280 return;
281}
282
287VOID
289 VOID
290 )
291{
292 EFI_STATUS Status;
294 OPAL_DEVICE_LOCKBOX_DATA *TempDevInfo;
295 UINTN TotalDevInfoLength;
296 UINT32 DevInfoLength;
297 OPAL_DRIVER_DEVICE *TmpDev;
298 UINT8 DummyData;
299 BOOLEAN S3InitDevicesExist;
300 UINTN S3InitDevicesLength;
301 EFI_DEVICE_PATH_PROTOCOL *S3InitDevices;
302 EFI_DEVICE_PATH_PROTOCOL *S3InitDevicesBak;
303
304 //
305 // Build OPAL device info and save them to LockBox.
306 //
307 TotalDevInfoLength = 0;
308 TmpDev = mOpalDriver.DeviceList;
309 while (TmpDev != NULL) {
311 TmpDev->OpalDisk.OpalDevicePath,
312 &DevInfoLength,
313 NULL
314 );
315 TotalDevInfoLength += DevInfoLength;
316 TmpDev = TmpDev->Next;
317 }
318
319 if (TotalDevInfoLength == 0) {
320 return;
321 }
322
323 S3InitDevicesLength = sizeof (DummyData);
324 Status = RestoreLockBox (
325 &gS3StorageDeviceInitListGuid,
326 &DummyData,
327 &S3InitDevicesLength
328 );
329 ASSERT ((Status == EFI_NOT_FOUND) || (Status == EFI_BUFFER_TOO_SMALL));
330 if (Status == EFI_NOT_FOUND) {
331 S3InitDevices = NULL;
332 S3InitDevicesExist = FALSE;
333 } else if (Status == EFI_BUFFER_TOO_SMALL) {
334 S3InitDevices = AllocatePool (S3InitDevicesLength);
335 ASSERT (S3InitDevices != NULL);
336 if (S3InitDevices == NULL) {
337 return;
338 }
339
340 Status = RestoreLockBox (
341 &gS3StorageDeviceInitListGuid,
342 S3InitDevices,
343 &S3InitDevicesLength
344 );
345 ASSERT_EFI_ERROR (Status);
346 S3InitDevicesExist = TRUE;
347 } else {
348 return;
349 }
350
351 DevInfo = AllocateZeroPool (TotalDevInfoLength);
352 ASSERT (DevInfo != NULL);
353 if (DevInfo == NULL) {
354 return;
355 }
356
357 TempDevInfo = DevInfo;
358 TmpDev = mOpalDriver.DeviceList;
359 while (TmpDev != NULL) {
361 TmpDev->OpalDisk.OpalDevicePath,
362 &DevInfoLength,
363 TempDevInfo
364 );
365 TempDevInfo->Length = DevInfoLength;
366 TempDevInfo->OpalBaseComId = TmpDev->OpalDisk.OpalBaseComId;
367 CopyMem (
368 TempDevInfo->Password,
369 TmpDev->OpalDisk.Password,
370 TmpDev->OpalDisk.PasswordLength
371 );
372 TempDevInfo->PasswordLength = TmpDev->OpalDisk.PasswordLength;
373
374 S3InitDevicesBak = S3InitDevices;
375 S3InitDevices = AppendDevicePathInstance (
376 S3InitDevicesBak,
377 TmpDev->OpalDisk.OpalDevicePath
378 );
379 if (S3InitDevicesBak != NULL) {
380 FreePool (S3InitDevicesBak);
381 }
382
383 ASSERT (S3InitDevices != NULL);
384 if (S3InitDevices == NULL) {
385 return;
386 }
387
388 TempDevInfo = (OPAL_DEVICE_LOCKBOX_DATA *)((UINTN)TempDevInfo + DevInfoLength);
389 TmpDev = TmpDev->Next;
390 }
391
392 Status = SaveLockBox (
393 &mOpalDeviceLockBoxGuid,
394 DevInfo,
395 TotalDevInfoLength
396 );
397 ASSERT_EFI_ERROR (Status);
398
399 Status = SetLockBoxAttributes (
400 &mOpalDeviceLockBoxGuid,
401 LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY
402 );
403 ASSERT_EFI_ERROR (Status);
404
405 S3InitDevicesLength = GetDevicePathSize (S3InitDevices);
406 if (S3InitDevicesExist) {
407 Status = UpdateLockBox (
408 &gS3StorageDeviceInitListGuid,
409 0,
410 S3InitDevices,
411 S3InitDevicesLength
412 );
413 ASSERT_EFI_ERROR (Status);
414 } else {
415 Status = SaveLockBox (
416 &gS3StorageDeviceInitListGuid,
417 S3InitDevices,
418 S3InitDevicesLength
419 );
420 ASSERT_EFI_ERROR (Status);
421
422 Status = SetLockBoxAttributes (
423 &gS3StorageDeviceInitListGuid,
424 LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY
425 );
426 ASSERT_EFI_ERROR (Status);
427 }
428
429 ZeroMem (DevInfo, TotalDevInfoLength);
430 FreePool (DevInfo);
431 FreePool (S3InitDevices);
432}
433
439VOID
441 VOID
442 )
443{
445 TCG_RESULT Result;
446 OPAL_SESSION Session;
447 UINT32 PpStorageFlag;
448
450 if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID) != 0) {
451 //
452 // Send BlockSID command to each Opal disk
453 //
454 Itr = mOpalDriver.DeviceList;
455 while (Itr != NULL) {
456 if (Itr->OpalDisk.SupportedAttributes.BlockSid) {
457 ZeroMem (&Session, sizeof (Session));
458 Session.Sscp = Itr->OpalDisk.Sscp;
459 Session.MediaId = Itr->OpalDisk.MediaId;
460 Session.OpalBaseComId = Itr->OpalDisk.OpalBaseComId;
461
462 DEBUG ((DEBUG_INFO, "OpalPassword: EndOfDxe point, send BlockSid command to device!\n"));
463 Result = OpalBlockSid (&Session, TRUE); // HardwareReset must always be TRUE
464 if (Result != TcgResultSuccess) {
465 DEBUG ((DEBUG_ERROR, "OpalBlockSid fail\n"));
466 break;
467 }
468
469 //
470 // Record BlockSID command has been sent.
471 //
472 Itr->OpalDisk.SentBlockSID = TRUE;
473 }
474
475 Itr = Itr->Next;
476 }
477 }
478}
479
489VOID
490EFIAPI
492 EFI_EVENT Event,
493 VOID *Context
494 )
495{
496 OPAL_DRIVER_DEVICE *TmpDev;
497
498 DEBUG ((DEBUG_INFO, "%a() - enter\n", __func__));
499
500 mOpalEndOfDxe = TRUE;
501
502 if (mOpalRequestVariable != NULL) {
503 //
504 // Free the OPAL request variable buffer here
505 // as the OPAL requests should have been processed.
506 //
507 FreePool (mOpalRequestVariable);
508 mOpalRequestVariable = NULL;
509 mOpalRequestVariableSize = 0;
510 }
511
512 //
513 // If no any device, return directly.
514 //
515 if (mOpalDriver.DeviceList == NULL) {
516 gBS->CloseEvent (Event);
517 return;
518 }
519
521
522 //
523 // Zero passsword.
524 //
525 TmpDev = mOpalDriver.DeviceList;
526 while (TmpDev != NULL) {
527 ZeroMem (TmpDev->OpalDisk.Password, TmpDev->OpalDisk.PasswordLength);
528 TmpDev = TmpDev->Next;
529 }
530
531 //
532 // Send BlockSid command if needed.
533 //
535
536 DEBUG ((DEBUG_INFO, "%a() - exit\n", __func__));
537
538 gBS->CloseEvent (Event);
539}
540
555CHAR8 *
558 IN CHAR16 *PopUpString,
559 IN CHAR16 *PopUpString2,
560 IN CHAR16 *PopUpString3,
561 OUT BOOLEAN *PressEsc
562 )
563{
564 EFI_INPUT_KEY InputKey;
565 UINTN InputLength;
566 CHAR16 Mask[PSID_CHARACTER_LENGTH + 1];
567 CHAR16 Unicode[PSID_CHARACTER_LENGTH + 1];
568 CHAR8 *Ascii;
569
570 ZeroMem (Unicode, sizeof (Unicode));
571 ZeroMem (Mask, sizeof (Mask));
572
573 *PressEsc = FALSE;
574
575 gST->ConOut->ClearScreen (gST->ConOut);
576
577 InputLength = 0;
578 while (TRUE) {
579 Mask[InputLength] = L'_';
580 if (PopUpString2 == NULL) {
582 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
583 &InputKey,
584 PopUpString,
585 L"---------------------",
586 Mask,
587 NULL
588 );
589 } else {
590 if (PopUpString3 == NULL) {
592 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
593 &InputKey,
594 PopUpString,
595 PopUpString2,
596 L"---------------------",
597 Mask,
598 NULL
599 );
600 } else {
602 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
603 &InputKey,
604 PopUpString,
605 PopUpString2,
606 PopUpString3,
607 L"---------------------",
608 Mask,
609 NULL
610 );
611 }
612 }
613
614 //
615 // Check key.
616 //
617 if (InputKey.ScanCode == SCAN_NULL) {
618 //
619 // password finished
620 //
621 if (InputKey.UnicodeChar == CHAR_CARRIAGE_RETURN) {
622 //
623 // Add the null terminator.
624 //
625 Unicode[InputLength] = 0;
626 Mask[InputLength] = 0;
627 break;
628 } else if ((InputKey.UnicodeChar == CHAR_NULL) ||
629 (InputKey.UnicodeChar == CHAR_TAB) ||
630 (InputKey.UnicodeChar == CHAR_LINEFEED)
631 )
632 {
633 continue;
634 } else {
635 //
636 // delete last key entered
637 //
638 if (InputKey.UnicodeChar == CHAR_BACKSPACE) {
639 if (InputLength > 0) {
640 Unicode[InputLength] = 0;
641 Mask[InputLength] = 0;
642 InputLength--;
643 }
644 } else {
645 //
646 // add Next key entry
647 //
648 Unicode[InputLength] = InputKey.UnicodeChar;
649 Mask[InputLength] = InputKey.UnicodeChar;
650 InputLength++;
651 if (InputLength == PSID_CHARACTER_LENGTH) {
652 //
653 // Add the null terminator.
654 //
655 Unicode[InputLength] = 0;
656 Mask[InputLength] = 0;
657 break;
658 }
659 }
660 }
661 }
662
663 //
664 // exit on ESC
665 //
666 if (InputKey.ScanCode == SCAN_ESC) {
667 *PressEsc = TRUE;
668 break;
669 }
670 }
671
672 gST->ConOut->ClearScreen (gST->ConOut);
673
674 if ((InputLength == 0) || (InputKey.ScanCode == SCAN_ESC)) {
675 ZeroMem (Unicode, sizeof (Unicode));
676 ZeroMem (Mask, sizeof (Mask));
677 return NULL;
678 }
679
680 Ascii = AllocateZeroPool (PSID_CHARACTER_LENGTH + 1);
681 if (Ascii == NULL) {
682 ZeroMem (Unicode, sizeof (Unicode));
683 ZeroMem (Mask, sizeof (Mask));
684 return NULL;
685 }
686
687 UnicodeStrToAsciiStrS (Unicode, Ascii, PSID_CHARACTER_LENGTH + 1);
688 ZeroMem (Unicode, sizeof (Unicode));
689 ZeroMem (Mask, sizeof (Mask));
690
691 return Ascii;
692}
693
707CHAR8 *
710 IN CHAR16 *PopUpString1,
711 IN CHAR16 *PopUpString2,
712 IN CHAR16 *PopUpString3,
713 OUT BOOLEAN *PressEsc
714 )
715{
716 EFI_INPUT_KEY InputKey;
717 UINTN InputLength;
718 CHAR16 Mask[OPAL_MAX_PASSWORD_SIZE + 1];
719 CHAR16 Unicode[OPAL_MAX_PASSWORD_SIZE + 1];
720 CHAR8 *Ascii;
721
722 ZeroMem (Unicode, sizeof (Unicode));
723 ZeroMem (Mask, sizeof (Mask));
724
725 *PressEsc = FALSE;
726
727 gST->ConOut->ClearScreen (gST->ConOut);
728
729 InputLength = 0;
730 while (TRUE) {
731 Mask[InputLength] = L'_';
732 if (PopUpString2 == NULL) {
734 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
735 &InputKey,
736 PopUpString1,
737 L"---------------------",
738 Mask,
739 NULL
740 );
741 } else {
742 if (PopUpString3 == NULL) {
744 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
745 &InputKey,
746 PopUpString1,
747 PopUpString2,
748 L"---------------------",
749 Mask,
750 NULL
751 );
752 } else {
754 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
755 &InputKey,
756 PopUpString1,
757 PopUpString2,
758 PopUpString3,
759 L"---------------------",
760 Mask,
761 NULL
762 );
763 }
764 }
765
766 //
767 // Check key.
768 //
769 if (InputKey.ScanCode == SCAN_NULL) {
770 //
771 // password finished
772 //
773 if (InputKey.UnicodeChar == CHAR_CARRIAGE_RETURN) {
774 //
775 // Add the null terminator.
776 //
777 Unicode[InputLength] = 0;
778 Mask[InputLength] = 0;
779 break;
780 } else if ((InputKey.UnicodeChar == CHAR_NULL) ||
781 (InputKey.UnicodeChar == CHAR_TAB) ||
782 (InputKey.UnicodeChar == CHAR_LINEFEED)
783 )
784 {
785 continue;
786 } else {
787 //
788 // delete last key entered
789 //
790 if (InputKey.UnicodeChar == CHAR_BACKSPACE) {
791 if (InputLength > 0) {
792 Unicode[InputLength] = 0;
793 Mask[InputLength] = 0;
794 InputLength--;
795 }
796 } else {
797 //
798 // add Next key entry
799 //
800 Unicode[InputLength] = InputKey.UnicodeChar;
801 Mask[InputLength] = L'*';
802 InputLength++;
803 if (InputLength == OPAL_MAX_PASSWORD_SIZE) {
804 //
805 // Add the null terminator.
806 //
807 Unicode[InputLength] = 0;
808 Mask[InputLength] = 0;
809 break;
810 }
811 }
812 }
813 }
814
815 //
816 // exit on ESC
817 //
818 if (InputKey.ScanCode == SCAN_ESC) {
819 *PressEsc = TRUE;
820 break;
821 }
822 }
823
824 gST->ConOut->ClearScreen (gST->ConOut);
825
826 if ((InputLength == 0) || (InputKey.ScanCode == SCAN_ESC)) {
827 ZeroMem (Unicode, sizeof (Unicode));
828 return NULL;
829 }
830
831 Ascii = AllocateZeroPool (OPAL_MAX_PASSWORD_SIZE + 1);
832 if (Ascii == NULL) {
833 ZeroMem (Unicode, sizeof (Unicode));
834 return NULL;
835 }
836
837 UnicodeStrToAsciiStrS (Unicode, Ascii, OPAL_MAX_PASSWORD_SIZE + 1);
838 ZeroMem (Unicode, sizeof (Unicode));
839
840 return Ascii;
841}
842
852CHAR16 *
855 IN CHAR16 *RequestString
856 )
857{
858 if (Dev->Name16 == NULL) {
859 UnicodeSPrint (mPopUpString, sizeof (mPopUpString), L"%s Disk", RequestString);
860 } else {
861 UnicodeSPrint (mPopUpString, sizeof (mPopUpString), L"%s %s", RequestString, Dev->Name16);
862 }
863
864 return mPopUpString;
865}
866
874VOID
877 IN CHAR16 *RequestString
878 )
879{
880 UINT8 Count;
881 BOOLEAN IsEnabled;
882 BOOLEAN IsLocked;
883 CHAR8 *Password;
884 UINT32 PasswordLen;
885 OPAL_SESSION Session;
886 BOOLEAN PressEsc;
887 EFI_INPUT_KEY Key;
888 TCG_RESULT Ret;
889 CHAR16 *PopUpString;
890
891 if (Dev == NULL) {
892 return;
893 }
894
895 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
896
897 PopUpString = OpalGetPopUpString (Dev, RequestString);
898
899 Count = 0;
900
901 IsEnabled = OpalFeatureEnabled (&Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.LockingFeature);
902 if (IsEnabled) {
903 ZeroMem (&Session, sizeof (Session));
904 Session.Sscp = Dev->OpalDisk.Sscp;
905 Session.MediaId = Dev->OpalDisk.MediaId;
906 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
907
908 IsLocked = OpalDeviceLocked (&Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.LockingFeature);
909
910 //
911 // Add PcdSkipOpalPasswordPrompt to determin whether to skip password prompt.
912 // Due to board design, device may not power off during system warm boot, which result in
913 // security status remain unlocked status, hence we add device security status check here.
914 //
915 // If device is in the locked status, device keeps locked and system continues booting.
916 // If device is in the unlocked status, system is forced shutdown to support security requirement.
917 //
918 if (PcdGetBool (PcdSkipOpalPasswordPrompt)) {
919 if (IsLocked) {
920 return;
921 } else {
922 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);
923 }
924 }
925
926 while (Count < MAX_PASSWORD_TRY_COUNT) {
927 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, NULL, NULL, &PressEsc);
928 if (PressEsc) {
929 if (IsLocked) {
930 //
931 // Current device in the lock status and
932 // User not input password and press ESC,
933 // keep device in lock status and continue boot.
934 //
935 do {
937 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
938 &Key,
939 L"Press ENTER to skip the request and continue boot,",
940 L"Press ESC to input password again",
941 NULL
942 );
943 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
944
945 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
946 gST->ConOut->ClearScreen (gST->ConOut);
947 //
948 // Keep lock and continue boot.
949 //
950 return;
951 } else {
952 //
953 // Let user input password again.
954 //
955 continue;
956 }
957 } else {
958 //
959 // Current device in the unlock status and
960 // User not input password and press ESC,
961 // Shutdown the device.
962 //
963 do {
965 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
966 &Key,
967 L"Press ENTER to shutdown, Press ESC to input password again",
968 NULL
969 );
970 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
971
972 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
973 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);
974 } else {
975 //
976 // Let user input password again.
977 //
978 continue;
979 }
980 }
981 }
982
983 if (Password == NULL) {
984 Count++;
985 continue;
986 }
987
988 PasswordLen = (UINT32)AsciiStrLen (Password);
989
990 if (IsLocked) {
991 Ret = OpalUtilUpdateGlobalLockingRange (&Session, Password, PasswordLen, FALSE, FALSE);
992 } else {
993 Ret = OpalUtilUpdateGlobalLockingRange (&Session, Password, PasswordLen, TRUE, TRUE);
994 if (Ret == TcgResultSuccess) {
995 Ret = OpalUtilUpdateGlobalLockingRange (&Session, Password, PasswordLen, FALSE, FALSE);
996 }
997 }
998
999 if (Ret == TcgResultSuccess) {
1000 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
1001 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1002 } else {
1003 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1004 }
1005
1006 if (Password != NULL) {
1007 ZeroMem (Password, PasswordLen);
1008 FreePool (Password);
1009 }
1010
1011 if (Ret == TcgResultSuccess) {
1012 break;
1013 }
1014
1015 //
1016 // Check whether opal device's Tries value has reach the TryLimit value, if yes, force a shutdown
1017 // before accept new password.
1018 //
1019 if (Ret == TcgResultFailureInvalidType) {
1020 Count = MAX_PASSWORD_TRY_COUNT;
1021 break;
1022 }
1023
1024 Count++;
1025
1026 do {
1027 CreatePopUp (
1028 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1029 &Key,
1030 L"Invalid password.",
1031 L"Press ENTER to retry",
1032 NULL
1033 );
1034 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1035 }
1036
1037 if (Count >= MAX_PASSWORD_TRY_COUNT) {
1038 do {
1039 CreatePopUp (
1040 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1041 &Key,
1042 L"Opal password retry count exceeds the limit. Must shutdown!",
1043 L"Press ENTER to shutdown",
1044 NULL
1045 );
1046 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1047
1048 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);
1049 }
1050 }
1051}
1052
1060VOID
1063 IN CHAR16 *RequestString
1064 )
1065{
1066 UINT8 Count;
1067 CHAR8 *Password;
1068 UINT32 PasswordLen;
1069 CHAR8 *PasswordConfirm;
1070 UINT32 PasswordLenConfirm;
1071 OPAL_SESSION Session;
1072 BOOLEAN PressEsc;
1073 EFI_INPUT_KEY Key;
1074 TCG_RESULT Ret;
1075 CHAR16 *PopUpString;
1076
1077 if (Dev == NULL) {
1078 return;
1079 }
1080
1081 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1082
1083 PopUpString = OpalGetPopUpString (Dev, RequestString);
1084
1085 Count = 0;
1086
1087 ZeroMem (&Session, sizeof (Session));
1088 Session.Sscp = Dev->OpalDisk.Sscp;
1089 Session.MediaId = Dev->OpalDisk.MediaId;
1090 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1091
1092 while (Count < MAX_PASSWORD_TRY_COUNT) {
1093 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your new password", NULL, &PressEsc);
1094 if (PressEsc) {
1095 do {
1096 CreatePopUp (
1097 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1098 &Key,
1099 L"Press ENTER to skip the request and continue boot,",
1100 L"Press ESC to input password again",
1101 NULL
1102 );
1103 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1104
1105 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1106 gST->ConOut->ClearScreen (gST->ConOut);
1107 return;
1108 } else {
1109 //
1110 // Let user input password again.
1111 //
1112 continue;
1113 }
1114 }
1115
1116 if (Password == NULL) {
1117 Count++;
1118 continue;
1119 }
1120
1121 PasswordLen = (UINT32)AsciiStrLen (Password);
1122
1123 PasswordConfirm = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please confirm your new password", NULL, &PressEsc);
1124 if (PasswordConfirm == NULL) {
1125 ZeroMem (Password, PasswordLen);
1126 FreePool (Password);
1127 Count++;
1128 continue;
1129 }
1130
1131 PasswordLenConfirm = (UINT32)AsciiStrLen (PasswordConfirm);
1132 if ((PasswordLen != PasswordLenConfirm) ||
1133 (CompareMem (Password, PasswordConfirm, PasswordLen) != 0))
1134 {
1135 ZeroMem (Password, PasswordLen);
1136 FreePool (Password);
1137 ZeroMem (PasswordConfirm, PasswordLenConfirm);
1138 FreePool (PasswordConfirm);
1139 do {
1140 CreatePopUp (
1141 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1142 &Key,
1143 L"Passwords are not the same.",
1144 L"Press ENTER to retry",
1145 NULL
1146 );
1147 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1148
1149 Count++;
1150 continue;
1151 }
1152
1153 if (PasswordConfirm != NULL) {
1154 ZeroMem (PasswordConfirm, PasswordLenConfirm);
1155 FreePool (PasswordConfirm);
1156 }
1157
1158 Ret = OpalSupportEnableOpalFeature (&Session, Dev->OpalDisk.Msid, Dev->OpalDisk.MsidLength, Password, PasswordLen);
1159 if (Ret == TcgResultSuccess) {
1160 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
1161 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1162 } else {
1163 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1164 }
1165
1166 if (Password != NULL) {
1167 ZeroMem (Password, PasswordLen);
1168 FreePool (Password);
1169 }
1170
1171 if (Ret == TcgResultSuccess) {
1172 break;
1173 }
1174
1175 Count++;
1176
1177 do {
1178 CreatePopUp (
1179 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1180 &Key,
1181 L"Request failed.",
1182 L"Press ENTER to retry",
1183 NULL
1184 );
1185 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1186 }
1187
1188 if (Count >= MAX_PASSWORD_TRY_COUNT) {
1189 do {
1190 CreatePopUp (
1191 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1192 &Key,
1193 L"Opal password retry count exceeds the limit.",
1194 L"Press ENTER to skip the request and continue boot",
1195 NULL
1196 );
1197 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1198
1199 gST->ConOut->ClearScreen (gST->ConOut);
1200 }
1201}
1202
1210VOID
1213 IN CHAR16 *RequestString
1214 )
1215{
1216 UINT8 Count;
1217 CHAR8 *Password;
1218 UINT32 PasswordLen;
1219 OPAL_SESSION Session;
1220 BOOLEAN PressEsc;
1221 EFI_INPUT_KEY Key;
1222 TCG_RESULT Ret;
1223 BOOLEAN PasswordFailed;
1224 CHAR16 *PopUpString;
1225
1226 if (Dev == NULL) {
1227 return;
1228 }
1229
1230 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1231
1232 PopUpString = OpalGetPopUpString (Dev, RequestString);
1233
1234 Count = 0;
1235
1236 ZeroMem (&Session, sizeof (Session));
1237 Session.Sscp = Dev->OpalDisk.Sscp;
1238 Session.MediaId = Dev->OpalDisk.MediaId;
1239 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1240
1241 while (Count < MAX_PASSWORD_TRY_COUNT) {
1242 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, NULL, NULL, &PressEsc);
1243 if (PressEsc) {
1244 do {
1245 CreatePopUp (
1246 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1247 &Key,
1248 L"Press ENTER to skip the request and continue boot,",
1249 L"Press ESC to input password again",
1250 NULL
1251 );
1252 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1253
1254 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1255 gST->ConOut->ClearScreen (gST->ConOut);
1256 return;
1257 } else {
1258 //
1259 // Let user input password again.
1260 //
1261 continue;
1262 }
1263 }
1264
1265 if (Password == NULL) {
1266 Count++;
1267 continue;
1268 }
1269
1270 PasswordLen = (UINT32)AsciiStrLen (Password);
1271
1272 Ret = OpalUtilDisableUser (&Session, Password, PasswordLen, &PasswordFailed);
1273 if (Ret == TcgResultSuccess) {
1274 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
1275 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1276 } else {
1277 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1278 }
1279
1280 if (Password != NULL) {
1281 ZeroMem (Password, PasswordLen);
1282 FreePool (Password);
1283 }
1284
1285 if (Ret == TcgResultSuccess) {
1286 break;
1287 }
1288
1289 Count++;
1290
1291 do {
1292 CreatePopUp (
1293 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1294 &Key,
1295 L"Invalid password, request failed.",
1296 L"Press ENTER to retry",
1297 NULL
1298 );
1299 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1300 }
1301
1302 if (Count >= MAX_PASSWORD_TRY_COUNT) {
1303 do {
1304 CreatePopUp (
1305 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1306 &Key,
1307 L"Opal password retry count exceeds the limit.",
1308 L"Press ENTER to skip the request and continue boot",
1309 NULL
1310 );
1311 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1312
1313 gST->ConOut->ClearScreen (gST->ConOut);
1314 }
1315}
1316
1324VOID
1327 IN CHAR16 *RequestString
1328 )
1329{
1330 UINT8 Count;
1331 CHAR8 *Psid;
1332 UINT32 PsidLen;
1333 OPAL_SESSION Session;
1334 BOOLEAN PressEsc;
1335 EFI_INPUT_KEY Key;
1336 TCG_RESULT Ret;
1337 CHAR16 *PopUpString;
1338 CHAR16 *PopUpString2;
1339 CHAR16 *PopUpString3;
1340 UINTN BufferSize;
1341
1342 if (Dev == NULL) {
1343 return;
1344 }
1345
1346 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1347
1348 PopUpString = OpalGetPopUpString (Dev, RequestString);
1349
1350 if (Dev->OpalDisk.EstimateTimeCost > MAX_ACCEPTABLE_REVERTING_TIME) {
1351 BufferSize = StrSize (L"Warning: Revert action will take about ####### seconds");
1352 PopUpString2 = AllocateZeroPool (BufferSize);
1353 ASSERT (PopUpString2 != NULL);
1355 PopUpString2,
1356 BufferSize,
1357 L"WARNING: Revert action will take about %d seconds",
1358 Dev->OpalDisk.EstimateTimeCost
1359 );
1360 PopUpString3 = L"DO NOT power off system during the revert action!";
1361 } else {
1362 PopUpString2 = NULL;
1363 PopUpString3 = NULL;
1364 }
1365
1366 Count = 0;
1367
1368 ZeroMem (&Session, sizeof (Session));
1369 Session.Sscp = Dev->OpalDisk.Sscp;
1370 Session.MediaId = Dev->OpalDisk.MediaId;
1371 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1372
1373 while (Count < MAX_PSID_TRY_COUNT) {
1374 Psid = OpalDriverPopUpPsidInput (Dev, PopUpString, PopUpString2, PopUpString3, &PressEsc);
1375 if (PressEsc) {
1376 do {
1377 CreatePopUp (
1378 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1379 &Key,
1380 L"Press ENTER to skip the request and continue boot,",
1381 L"Press ESC to input Psid again",
1382 NULL
1383 );
1384 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1385
1386 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1387 gST->ConOut->ClearScreen (gST->ConOut);
1388 goto Done;
1389 } else {
1390 //
1391 // Let user input Psid again.
1392 //
1393 continue;
1394 }
1395 }
1396
1397 if (Psid == NULL) {
1398 Count++;
1399 continue;
1400 }
1401
1402 PsidLen = (UINT32)AsciiStrLen (Psid);
1403
1404 Ret = OpalUtilPsidRevert (&Session, Psid, PsidLen);
1405 if (Ret == TcgResultSuccess) {
1406 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1407 } else {
1408 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1409 }
1410
1411 if (Psid != NULL) {
1412 ZeroMem (Psid, PsidLen);
1413 FreePool (Psid);
1414 }
1415
1416 if (Ret == TcgResultSuccess) {
1417 break;
1418 }
1419
1420 Count++;
1421
1422 do {
1423 CreatePopUp (
1424 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1425 &Key,
1426 L"Invalid Psid, request failed.",
1427 L"Press ENTER to retry",
1428 NULL
1429 );
1430 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1431 }
1432
1433 if (Count >= MAX_PSID_TRY_COUNT) {
1434 do {
1435 CreatePopUp (
1436 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1437 &Key,
1438 L"Opal Psid retry count exceeds the limit.",
1439 L"Press ENTER to skip the request and continue boot",
1440 NULL
1441 );
1442 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1443
1444 gST->ConOut->ClearScreen (gST->ConOut);
1445 }
1446
1447Done:
1448 if (PopUpString2 != NULL) {
1449 FreePool (PopUpString2);
1450 }
1451}
1452
1461VOID
1464 IN BOOLEAN KeepUserData,
1465 IN CHAR16 *RequestString
1466 )
1467{
1468 UINT8 Count;
1469 CHAR8 *Password;
1470 UINT32 PasswordLen;
1471 OPAL_SESSION Session;
1472 BOOLEAN PressEsc;
1473 EFI_INPUT_KEY Key;
1474 TCG_RESULT Ret;
1475 BOOLEAN PasswordFailed;
1476 CHAR16 *PopUpString;
1477 CHAR16 *PopUpString2;
1478 CHAR16 *PopUpString3;
1479 UINTN BufferSize;
1480
1481 if (Dev == NULL) {
1482 return;
1483 }
1484
1485 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1486
1487 PopUpString = OpalGetPopUpString (Dev, RequestString);
1488
1489 if ((!KeepUserData) &&
1490 (Dev->OpalDisk.EstimateTimeCost > MAX_ACCEPTABLE_REVERTING_TIME))
1491 {
1492 BufferSize = StrSize (L"Warning: Revert action will take about ####### seconds");
1493 PopUpString2 = AllocateZeroPool (BufferSize);
1494 ASSERT (PopUpString2 != NULL);
1496 PopUpString2,
1497 BufferSize,
1498 L"WARNING: Revert action will take about %d seconds",
1499 Dev->OpalDisk.EstimateTimeCost
1500 );
1501 PopUpString3 = L"DO NOT power off system during the revert action!";
1502 } else {
1503 PopUpString2 = NULL;
1504 PopUpString3 = NULL;
1505 }
1506
1507 Count = 0;
1508
1509 ZeroMem (&Session, sizeof (Session));
1510 Session.Sscp = Dev->OpalDisk.Sscp;
1511 Session.MediaId = Dev->OpalDisk.MediaId;
1512 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1513
1514 while (Count < MAX_PASSWORD_TRY_COUNT) {
1515 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, PopUpString2, PopUpString3, &PressEsc);
1516 if (PressEsc) {
1517 do {
1518 CreatePopUp (
1519 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1520 &Key,
1521 L"Press ENTER to skip the request and continue boot,",
1522 L"Press ESC to input password again",
1523 NULL
1524 );
1525 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1526
1527 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1528 gST->ConOut->ClearScreen (gST->ConOut);
1529 goto Done;
1530 } else {
1531 //
1532 // Let user input password again.
1533 //
1534 continue;
1535 }
1536 }
1537
1538 if (Password == NULL) {
1539 Count++;
1540 continue;
1541 }
1542
1543 PasswordLen = (UINT32)AsciiStrLen (Password);
1544
1545 if ((Dev->OpalDisk.SupportedAttributes.PyriteSsc == 1) &&
1546 (Dev->OpalDisk.LockingFeature.MediaEncryption == 0))
1547 {
1548 //
1549 // For pyrite type device which does not support media encryption,
1550 // it does not accept "Keep User Data" parameter.
1551 // So here hardcode a FALSE for this case.
1552 //
1553 Ret = OpalUtilRevert (
1554 &Session,
1555 FALSE,
1556 Password,
1557 PasswordLen,
1558 &PasswordFailed,
1559 Dev->OpalDisk.Msid,
1560 Dev->OpalDisk.MsidLength
1561 );
1562 } else {
1563 Ret = OpalUtilRevert (
1564 &Session,
1565 KeepUserData,
1566 Password,
1567 PasswordLen,
1568 &PasswordFailed,
1569 Dev->OpalDisk.Msid,
1570 Dev->OpalDisk.MsidLength
1571 );
1572 }
1573
1574 if (Ret == TcgResultSuccess) {
1575 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
1576 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1577 } else {
1578 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1579 }
1580
1581 if (Password != NULL) {
1582 ZeroMem (Password, PasswordLen);
1583 FreePool (Password);
1584 }
1585
1586 if (Ret == TcgResultSuccess) {
1587 break;
1588 }
1589
1590 Count++;
1591
1592 do {
1593 CreatePopUp (
1594 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1595 &Key,
1596 L"Invalid password, request failed.",
1597 L"Press ENTER to retry",
1598 NULL
1599 );
1600 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1601 }
1602
1603 if (Count >= MAX_PASSWORD_TRY_COUNT) {
1604 do {
1605 CreatePopUp (
1606 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1607 &Key,
1608 L"Opal password retry count exceeds the limit.",
1609 L"Press ENTER to skip the request and continue boot",
1610 NULL
1611 );
1612 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1613
1614 gST->ConOut->ClearScreen (gST->ConOut);
1615 }
1616
1617Done:
1618 if (PopUpString2 != NULL) {
1619 FreePool (PopUpString2);
1620 }
1621}
1622
1630VOID
1633 IN CHAR16 *RequestString
1634 )
1635{
1636 UINT8 Count;
1637 CHAR8 *Password;
1638 UINT32 PasswordLen;
1639 OPAL_SESSION Session;
1640 BOOLEAN PressEsc;
1641 EFI_INPUT_KEY Key;
1642 TCG_RESULT Ret;
1643 BOOLEAN PasswordFailed;
1644 CHAR16 *PopUpString;
1645 CHAR16 *PopUpString2;
1646 CHAR16 *PopUpString3;
1647 UINTN BufferSize;
1648
1649 if (Dev == NULL) {
1650 return;
1651 }
1652
1653 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1654
1655 PopUpString = OpalGetPopUpString (Dev, RequestString);
1656
1657 if (Dev->OpalDisk.EstimateTimeCost > MAX_ACCEPTABLE_REVERTING_TIME) {
1658 BufferSize = StrSize (L"Warning: Secure erase action will take about ####### seconds");
1659 PopUpString2 = AllocateZeroPool (BufferSize);
1660 ASSERT (PopUpString2 != NULL);
1662 PopUpString2,
1663 BufferSize,
1664 L"WARNING: Secure erase action will take about %d seconds",
1665 Dev->OpalDisk.EstimateTimeCost
1666 );
1667 PopUpString3 = L"DO NOT power off system during the action!";
1668 } else {
1669 PopUpString2 = NULL;
1670 PopUpString3 = NULL;
1671 }
1672
1673 Count = 0;
1674
1675 ZeroMem (&Session, sizeof (Session));
1676 Session.Sscp = Dev->OpalDisk.Sscp;
1677 Session.MediaId = Dev->OpalDisk.MediaId;
1678 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1679
1680 while (Count < MAX_PASSWORD_TRY_COUNT) {
1681 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, PopUpString2, PopUpString3, &PressEsc);
1682 if (PressEsc) {
1683 do {
1684 CreatePopUp (
1685 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1686 &Key,
1687 L"Press ENTER to skip the request and continue boot,",
1688 L"Press ESC to input password again",
1689 NULL
1690 );
1691 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1692
1693 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1694 gST->ConOut->ClearScreen (gST->ConOut);
1695 goto Done;
1696 } else {
1697 //
1698 // Let user input password again.
1699 //
1700 continue;
1701 }
1702 }
1703
1704 if (Password == NULL) {
1705 Count++;
1706 continue;
1707 }
1708
1709 PasswordLen = (UINT32)AsciiStrLen (Password);
1710
1711 Ret = OpalUtilSecureErase (&Session, Password, PasswordLen, &PasswordFailed);
1712 if (Ret == TcgResultSuccess) {
1713 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
1714 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1715 } else {
1716 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1717 }
1718
1719 if (Password != NULL) {
1720 ZeroMem (Password, PasswordLen);
1721 FreePool (Password);
1722 }
1723
1724 if (Ret == TcgResultSuccess) {
1725 break;
1726 }
1727
1728 Count++;
1729
1730 do {
1731 CreatePopUp (
1732 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1733 &Key,
1734 L"Invalid password, request failed.",
1735 L"Press ENTER to retry",
1736 NULL
1737 );
1738 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1739 }
1740
1741 if (Count >= MAX_PASSWORD_TRY_COUNT) {
1742 do {
1743 CreatePopUp (
1744 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1745 &Key,
1746 L"Opal password retry count exceeds the limit.",
1747 L"Press ENTER to skip the request and continue boot",
1748 NULL
1749 );
1750 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1751
1752 gST->ConOut->ClearScreen (gST->ConOut);
1753 }
1754
1755Done:
1756 if (PopUpString2 != NULL) {
1757 FreePool (PopUpString2);
1758 }
1759}
1760
1768VOID
1771 IN CHAR16 *RequestString
1772 )
1773{
1774 UINT8 Count;
1775 CHAR8 *OldPassword;
1776 UINT32 OldPasswordLen;
1777 CHAR8 *Password;
1778 UINT32 PasswordLen;
1779 CHAR8 *PasswordConfirm;
1780 UINT32 PasswordLenConfirm;
1781 OPAL_SESSION Session;
1782 BOOLEAN PressEsc;
1783 EFI_INPUT_KEY Key;
1784 TCG_RESULT Ret;
1785 CHAR16 *PopUpString;
1786
1787 if (Dev == NULL) {
1788 return;
1789 }
1790
1791 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1792
1793 PopUpString = OpalGetPopUpString (Dev, RequestString);
1794
1795 Count = 0;
1796
1797 while (Count < MAX_PASSWORD_TRY_COUNT) {
1798 OldPassword = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your password", NULL, &PressEsc);
1799 if (PressEsc) {
1800 do {
1801 CreatePopUp (
1802 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1803 &Key,
1804 L"Press ENTER to skip the request and continue boot,",
1805 L"Press ESC to input password again",
1806 NULL
1807 );
1808 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1809
1810 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1811 gST->ConOut->ClearScreen (gST->ConOut);
1812 return;
1813 } else {
1814 //
1815 // Let user input password again.
1816 //
1817 continue;
1818 }
1819 }
1820
1821 if (OldPassword == NULL) {
1822 Count++;
1823 continue;
1824 }
1825
1826 OldPasswordLen = (UINT32)AsciiStrLen (OldPassword);
1827
1828 ZeroMem (&Session, sizeof (Session));
1829 Session.Sscp = Dev->OpalDisk.Sscp;
1830 Session.MediaId = Dev->OpalDisk.MediaId;
1831 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1832 Ret = OpalUtilVerifyPassword (&Session, OldPassword, OldPasswordLen, OPAL_LOCKING_SP_USER1_AUTHORITY);
1833 if (Ret == TcgResultSuccess) {
1834 DEBUG ((DEBUG_INFO, "Verify with USER1 authority : Success\n"));
1835 } else {
1836 Ret = OpalUtilVerifyPassword (&Session, OldPassword, OldPasswordLen, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);
1837 if (Ret == TcgResultSuccess) {
1838 DEBUG ((DEBUG_INFO, "Verify with ADMIN1 authority: Success\n"));
1839 } else {
1840 ZeroMem (OldPassword, OldPasswordLen);
1841 FreePool (OldPassword);
1842 DEBUG ((DEBUG_INFO, "Verify: Failure\n"));
1843 do {
1844 CreatePopUp (
1845 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1846 &Key,
1847 L"Incorrect password.",
1848 L"Press ENTER to retry",
1849 NULL
1850 );
1851 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1852
1853 Count++;
1854 continue;
1855 }
1856 }
1857
1858 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your new password", NULL, &PressEsc);
1859 if (Password == NULL) {
1860 ZeroMem (OldPassword, OldPasswordLen);
1861 FreePool (OldPassword);
1862 Count++;
1863 continue;
1864 }
1865
1866 PasswordLen = (UINT32)AsciiStrLen (Password);
1867
1868 PasswordConfirm = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please confirm your new password", NULL, &PressEsc);
1869 if (PasswordConfirm == NULL) {
1870 ZeroMem (OldPassword, OldPasswordLen);
1871 FreePool (OldPassword);
1872 ZeroMem (Password, PasswordLen);
1873 FreePool (Password);
1874 Count++;
1875 continue;
1876 }
1877
1878 PasswordLenConfirm = (UINT32)AsciiStrLen (PasswordConfirm);
1879 if ((PasswordLen != PasswordLenConfirm) ||
1880 (CompareMem (Password, PasswordConfirm, PasswordLen) != 0))
1881 {
1882 ZeroMem (OldPassword, OldPasswordLen);
1883 FreePool (OldPassword);
1884 ZeroMem (Password, PasswordLen);
1885 FreePool (Password);
1886 ZeroMem (PasswordConfirm, PasswordLenConfirm);
1887 FreePool (PasswordConfirm);
1888 do {
1889 CreatePopUp (
1890 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1891 &Key,
1892 L"Passwords are not the same.",
1893 L"Press ENTER to retry",
1894 NULL
1895 );
1896 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1897
1898 Count++;
1899 continue;
1900 }
1901
1902 if (PasswordConfirm != NULL) {
1903 ZeroMem (PasswordConfirm, PasswordLenConfirm);
1904 FreePool (PasswordConfirm);
1905 }
1906
1907 ZeroMem (&Session, sizeof (Session));
1908 Session.Sscp = Dev->OpalDisk.Sscp;
1909 Session.MediaId = Dev->OpalDisk.MediaId;
1910 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1912 &Session,
1913 OldPassword,
1914 OldPasswordLen,
1915 Password,
1916 PasswordLen
1917 );
1918 if (Ret == TcgResultSuccess) {
1919 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
1920 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
1921 } else {
1922 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
1923 }
1924
1925 if (OldPassword != NULL) {
1926 ZeroMem (OldPassword, OldPasswordLen);
1927 FreePool (OldPassword);
1928 }
1929
1930 if (Password != NULL) {
1931 ZeroMem (Password, PasswordLen);
1932 FreePool (Password);
1933 }
1934
1935 if (Ret == TcgResultSuccess) {
1936 break;
1937 }
1938
1939 Count++;
1940
1941 do {
1942 CreatePopUp (
1943 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1944 &Key,
1945 L"Request failed.",
1946 L"Press ENTER to retry",
1947 NULL
1948 );
1949 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1950 }
1951
1952 if (Count >= MAX_PASSWORD_TRY_COUNT) {
1953 do {
1954 CreatePopUp (
1955 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1956 &Key,
1957 L"Opal password retry count exceeds the limit.",
1958 L"Press ENTER to skip the request and continue boot",
1959 NULL
1960 );
1961 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1962
1963 gST->ConOut->ClearScreen (gST->ConOut);
1964 }
1965}
1966
1974VOID
1977 IN CHAR16 *RequestString
1978 )
1979{
1980 UINT8 Count;
1981 CHAR8 *OldPassword;
1982 UINT32 OldPasswordLen;
1983 CHAR8 *Password;
1984 UINT32 PasswordLen;
1985 CHAR8 *PasswordConfirm;
1986 UINT32 PasswordLenConfirm;
1987 OPAL_SESSION Session;
1988 BOOLEAN PressEsc;
1989 EFI_INPUT_KEY Key;
1990 TCG_RESULT Ret;
1991 CHAR16 *PopUpString;
1992
1993 if (Dev == NULL) {
1994 return;
1995 }
1996
1997 DEBUG ((DEBUG_INFO, "%a()\n", __func__));
1998
1999 PopUpString = OpalGetPopUpString (Dev, RequestString);
2000
2001 Count = 0;
2002
2003 while (Count < MAX_PASSWORD_TRY_COUNT) {
2004 OldPassword = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your password", NULL, &PressEsc);
2005 if (PressEsc) {
2006 do {
2007 CreatePopUp (
2008 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
2009 &Key,
2010 L"Press ENTER to skip the request and continue boot,",
2011 L"Press ESC to input password again",
2012 NULL
2013 );
2014 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
2015
2016 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
2017 gST->ConOut->ClearScreen (gST->ConOut);
2018 return;
2019 } else {
2020 //
2021 // Let user input password again.
2022 //
2023 continue;
2024 }
2025 }
2026
2027 if (OldPassword == NULL) {
2028 Count++;
2029 continue;
2030 }
2031
2032 OldPasswordLen = (UINT32)AsciiStrLen (OldPassword);
2033
2034 ZeroMem (&Session, sizeof (Session));
2035 Session.Sscp = Dev->OpalDisk.Sscp;
2036 Session.MediaId = Dev->OpalDisk.MediaId;
2037 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
2038 Ret = OpalUtilVerifyPassword (&Session, OldPassword, OldPasswordLen, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);
2039 if (Ret == TcgResultSuccess) {
2040 DEBUG ((DEBUG_INFO, "Verify: Success\n"));
2041 } else {
2042 ZeroMem (OldPassword, OldPasswordLen);
2043 FreePool (OldPassword);
2044 DEBUG ((DEBUG_INFO, "Verify: Failure\n"));
2045 do {
2046 CreatePopUp (
2047 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
2048 &Key,
2049 L"Incorrect password.",
2050 L"Press ENTER to retry",
2051 NULL
2052 );
2053 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
2054
2055 Count++;
2056 continue;
2057 }
2058
2059 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your new password", NULL, &PressEsc);
2060 if (Password == NULL) {
2061 ZeroMem (OldPassword, OldPasswordLen);
2062 FreePool (OldPassword);
2063 Count++;
2064 continue;
2065 }
2066
2067 PasswordLen = (UINT32)AsciiStrLen (Password);
2068
2069 PasswordConfirm = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please confirm your new password", NULL, &PressEsc);
2070 if (PasswordConfirm == NULL) {
2071 ZeroMem (OldPassword, OldPasswordLen);
2072 FreePool (OldPassword);
2073 ZeroMem (Password, PasswordLen);
2074 FreePool (Password);
2075 Count++;
2076 continue;
2077 }
2078
2079 PasswordLenConfirm = (UINT32)AsciiStrLen (PasswordConfirm);
2080 if ((PasswordLen != PasswordLenConfirm) ||
2081 (CompareMem (Password, PasswordConfirm, PasswordLen) != 0))
2082 {
2083 ZeroMem (OldPassword, OldPasswordLen);
2084 FreePool (OldPassword);
2085 ZeroMem (Password, PasswordLen);
2086 FreePool (Password);
2087 ZeroMem (PasswordConfirm, PasswordLenConfirm);
2088 FreePool (PasswordConfirm);
2089 do {
2090 CreatePopUp (
2091 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
2092 &Key,
2093 L"Passwords are not the same.",
2094 L"Press ENTER to retry",
2095 NULL
2096 );
2097 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
2098
2099 Count++;
2100 continue;
2101 }
2102
2103 if (PasswordConfirm != NULL) {
2104 ZeroMem (PasswordConfirm, PasswordLenConfirm);
2105 FreePool (PasswordConfirm);
2106 }
2107
2108 ZeroMem (&Session, sizeof (Session));
2109 Session.Sscp = Dev->OpalDisk.Sscp;
2110 Session.MediaId = Dev->OpalDisk.MediaId;
2111 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
2113 &Session,
2114 OldPassword,
2115 OldPasswordLen,
2116 Password,
2117 PasswordLen
2118 );
2119 if (Ret == TcgResultSuccess) {
2120 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);
2121 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));
2122 } else {
2123 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));
2124 }
2125
2126 if (OldPassword != NULL) {
2127 ZeroMem (OldPassword, OldPasswordLen);
2128 FreePool (OldPassword);
2129 }
2130
2131 if (Password != NULL) {
2132 ZeroMem (Password, PasswordLen);
2133 FreePool (Password);
2134 }
2135
2136 if (Ret == TcgResultSuccess) {
2137 break;
2138 }
2139
2140 Count++;
2141
2142 do {
2143 CreatePopUp (
2144 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
2145 &Key,
2146 L"Request failed.",
2147 L"Press ENTER to retry",
2148 NULL
2149 );
2150 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
2151 }
2152
2153 if (Count >= MAX_PASSWORD_TRY_COUNT) {
2154 do {
2155 CreatePopUp (
2156 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
2157 &Key,
2158 L"Opal password retry count exceeds the limit.",
2159 L"Press ENTER to skip the request and continue boot",
2160 NULL
2161 );
2162 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
2163
2164 gST->ConOut->ClearScreen (gST->ConOut);
2165 }
2166}
2167
2174VOID
2177 )
2178{
2179 EFI_STATUS Status;
2180 OPAL_REQUEST_VARIABLE *TempVariable;
2181 OPAL_REQUEST_VARIABLE *Variable;
2182 UINTN VariableSize;
2183 EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;
2184 UINTN DevicePathSizeInVariable;
2185 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2186 UINTN DevicePathSize;
2187 BOOLEAN KeepUserData;
2188
2189 DEBUG ((DEBUG_INFO, "%a() - enter\n", __func__));
2190
2191 if (mOpalRequestVariable == NULL) {
2192 Status = GetVariable2 (
2193 OPAL_REQUEST_VARIABLE_NAME,
2194 &gHiiSetupVariableGuid,
2195 (VOID **)&Variable,
2196 &VariableSize
2197 );
2198 if (EFI_ERROR (Status) || (Variable == NULL)) {
2199 return;
2200 }
2201
2202 mOpalRequestVariable = Variable;
2203 mOpalRequestVariableSize = VariableSize;
2204
2205 //
2206 // Delete the OPAL request variable.
2207 //
2208 Status = gRT->SetVariable (
2209 OPAL_REQUEST_VARIABLE_NAME,
2210 (EFI_GUID *)&gHiiSetupVariableGuid,
2211 0,
2212 0,
2213 NULL
2214 );
2215 ASSERT_EFI_ERROR (Status);
2216 } else {
2217 Variable = mOpalRequestVariable;
2218 VariableSize = mOpalRequestVariableSize;
2219 }
2220
2221 //
2222 // Process the OPAL requests.
2223 //
2224 TempVariable = Variable;
2225 while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
2226 (VariableSize >= TempVariable->Length) &&
2227 (TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
2228 {
2229 DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
2230 DevicePathSizeInVariable = GetDevicePathSize (DevicePathInVariable);
2231 DevicePath = Dev->OpalDisk.OpalDevicePath;
2232 DevicePathSize = GetDevicePathSize (DevicePath);
2233 if ((DevicePathSize == DevicePathSizeInVariable) &&
2234 (CompareMem (DevicePath, DevicePathInVariable, DevicePathSize) == 0))
2235 {
2236 //
2237 // Found the node for the OPAL device.
2238 //
2239 if (TempVariable->OpalRequest.SetAdminPwd != 0) {
2240 ProcessOpalRequestSetAdminPwd (Dev, L"Update Admin Pwd:");
2241 }
2242
2243 if (TempVariable->OpalRequest.SetUserPwd != 0) {
2244 ProcessOpalRequestSetUserPwd (Dev, L"Set User Pwd:");
2245 }
2246
2247 if (TempVariable->OpalRequest.SecureErase != 0) {
2248 ProcessOpalRequestSecureErase (Dev, L"Secure Erase:");
2249 }
2250
2251 if (TempVariable->OpalRequest.Revert != 0) {
2252 KeepUserData = (BOOLEAN)TempVariable->OpalRequest.KeepUserData;
2254 Dev,
2255 KeepUserData,
2256 KeepUserData ? L"Admin Revert(keep):" : L"Admin Revert:"
2257 );
2258 }
2259
2260 if (TempVariable->OpalRequest.PsidRevert != 0) {
2261 ProcessOpalRequestPsidRevert (Dev, L"Psid Revert:");
2262 }
2263
2264 if (TempVariable->OpalRequest.DisableUser != 0) {
2265 ProcessOpalRequestDisableUser (Dev, L"Disable User:");
2266 }
2267
2268 if (TempVariable->OpalRequest.EnableFeature != 0) {
2269 ProcessOpalRequestEnableFeature (Dev, L"Enable Feature:");
2270 }
2271
2272 //
2273 // Update Device ownership.
2274 // Later BlockSID command may block the update.
2275 //
2276 OpalDiskUpdateOwnerShip (&Dev->OpalDisk);
2277
2278 break;
2279 }
2280
2281 VariableSize -= TempVariable->Length;
2282 TempVariable = (OPAL_REQUEST_VARIABLE *)((UINTN)TempVariable + TempVariable->Length);
2283 }
2284
2285 DEBUG ((DEBUG_INFO, "%a() - exit\n", __func__));
2286}
2287
2294VOID
2297 )
2298{
2299 OPAL_DRIVER_DEVICE *TmpDev;
2300
2301 if (mOpalDriver.DeviceList == NULL) {
2302 mOpalDriver.DeviceList = Dev;
2303 } else {
2304 TmpDev = mOpalDriver.DeviceList;
2305 while (TmpDev->Next != NULL) {
2306 TmpDev = TmpDev->Next;
2307 }
2308
2309 TmpDev->Next = Dev;
2310 }
2311}
2312
2319VOID
2322 )
2323{
2324 OPAL_DRIVER_DEVICE *TmpDev;
2325
2326 if (mOpalDriver.DeviceList == NULL) {
2327 return;
2328 }
2329
2330 if (mOpalDriver.DeviceList == Dev) {
2331 mOpalDriver.DeviceList = NULL;
2332 return;
2333 }
2334
2335 TmpDev = mOpalDriver.DeviceList;
2336 while (TmpDev->Next != NULL) {
2337 if (TmpDev->Next == Dev) {
2338 TmpDev->Next = Dev->Next;
2339 break;
2340 }
2341 }
2342}
2343
2350UINT8
2352 VOID
2353 )
2354{
2355 UINT8 Count;
2356 OPAL_DRIVER_DEVICE *TmpDev;
2357
2358 Count = 0;
2359 TmpDev = mOpalDriver.DeviceList;
2360
2361 while (TmpDev != NULL) {
2362 Count++;
2363 TmpDev = TmpDev->Next;
2364 }
2365
2366 return Count;
2367}
2368
2376 VOID
2377 )
2378{
2379 return mOpalDriver.DeviceList;
2380}
2381
2388VOID
2391 )
2392{
2393 //
2394 // free each name
2395 //
2396 FreePool (Dev->Name16);
2397
2398 //
2399 // remove OPAL_DRIVER_DEVICE from the list
2400 // it updates the controllerList pointer
2401 //
2402 RemoveDevice (Dev);
2403
2404 //
2405 // close protocols that were opened
2406 //
2407 gBS->CloseProtocol (
2408 Dev->Handle,
2409 &gEfiStorageSecurityCommandProtocolGuid,
2410 gOpalDriverBinding.DriverBindingHandle,
2411 Dev->Handle
2412 );
2413
2414 gBS->CloseProtocol (
2415 Dev->Handle,
2416 &gEfiBlockIoProtocolGuid,
2417 gOpalDriverBinding.DriverBindingHandle,
2418 Dev->Handle
2419 );
2420
2421 FreePool (Dev);
2422}
2423
2435BOOLEAN
2437 EFI_HANDLE *AllHandlesBuffer,
2438 UINTN NumAllHandles,
2439 OPAL_DRIVER_DEVICE *Dev,
2440 BOOLEAN UseComp1
2441 )
2442{
2443 EFI_HANDLE *ProtocolHandlesBuffer;
2444 UINTN NumProtocolHandles;
2445 EFI_STATUS Status;
2446 EFI_COMPONENT_NAME2_PROTOCOL *Cnp1_2; // efi component name and componentName2 have same layout
2447 EFI_GUID Protocol;
2448 UINTN StrLength;
2449 EFI_DEVICE_PATH_PROTOCOL *TmpDevPath;
2450 UINTN Index1;
2451 UINTN Index2;
2452 EFI_HANDLE TmpHandle;
2453 CHAR16 *DevName;
2454
2455 if ((Dev == NULL) || (AllHandlesBuffer == NULL) || (NumAllHandles == 0)) {
2456 return FALSE;
2457 }
2458
2459 Protocol = UseComp1 ? gEfiComponentNameProtocolGuid : gEfiComponentName2ProtocolGuid;
2460
2461 //
2462 // Find all EFI_HANDLES with protocol
2463 //
2464 Status = gBS->LocateHandleBuffer (
2465 ByProtocol,
2466 &Protocol,
2467 NULL,
2468 &NumProtocolHandles,
2469 &ProtocolHandlesBuffer
2470 );
2471 if (EFI_ERROR (Status)) {
2472 return FALSE;
2473 }
2474
2475 //
2476 // Exit early if no supported devices
2477 //
2478 if (NumProtocolHandles == 0) {
2479 return FALSE;
2480 }
2481
2482 //
2483 // Get printable name by iterating through all protocols
2484 // using the handle as the child, and iterate through all handles for the controller
2485 // exit loop early once found, if not found, then delete device
2486 // storage security protocol instances already exist, add them to internal list
2487 //
2488 Status = EFI_DEVICE_ERROR;
2489 for (Index1 = 0; Index1 < NumProtocolHandles; Index1++) {
2490 DevName = NULL;
2491
2492 if (Dev->Name16 != NULL) {
2493 return TRUE;
2494 }
2495
2496 TmpHandle = ProtocolHandlesBuffer[Index1];
2497
2498 Status = gBS->OpenProtocol (
2499 TmpHandle,
2500 &Protocol,
2501 (VOID **)&Cnp1_2,
2503 NULL,
2504 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2505 );
2506 if (EFI_ERROR (Status) || (Cnp1_2 == NULL)) {
2507 continue;
2508 }
2509
2510 //
2511 // Use all handles array as controller handle
2512 //
2513 for (Index2 = 0; Index2 < NumAllHandles; Index2++) {
2514 Status = Cnp1_2->GetControllerName (
2515 Cnp1_2,
2516 AllHandlesBuffer[Index2],
2517 Dev->Handle,
2518 LANGUAGE_ISO_639_2_ENGLISH,
2519 &DevName
2520 );
2521 if (EFI_ERROR (Status)) {
2522 Status = Cnp1_2->GetControllerName (
2523 Cnp1_2,
2524 AllHandlesBuffer[Index2],
2525 Dev->Handle,
2526 LANGUAGE_RFC_3066_ENGLISH,
2527 &DevName
2528 );
2529 }
2530
2531 if (!EFI_ERROR (Status) && (DevName != NULL)) {
2532 StrLength = StrLen (DevName) + 1; // Add one for NULL terminator
2533 Dev->Name16 = AllocateZeroPool (StrLength * sizeof (CHAR16));
2534 ASSERT (Dev->Name16 != NULL);
2535 StrCpyS (Dev->Name16, StrLength, DevName);
2536 Dev->NameZ = (CHAR8 *)AllocateZeroPool (StrLength);
2537 UnicodeStrToAsciiStrS (DevName, Dev->NameZ, StrLength);
2538
2539 //
2540 // Retrieve bridge BDF info and port number or namespace depending on type
2541 //
2542 TmpDevPath = NULL;
2543 Status = gBS->OpenProtocol (
2544 Dev->Handle,
2545 &gEfiDevicePathProtocolGuid,
2546 (VOID **)&TmpDevPath,
2548 NULL,
2549 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2550 );
2551 if (!EFI_ERROR (Status)) {
2552 Dev->OpalDevicePath = DuplicateDevicePath (TmpDevPath);
2553 return TRUE;
2554 }
2555
2556 if (Dev->Name16 != NULL) {
2557 FreePool (Dev->Name16);
2558 Dev->Name16 = NULL;
2559 }
2560
2561 if (Dev->NameZ != NULL) {
2562 FreePool (Dev->NameZ);
2563 Dev->NameZ = NULL;
2564 }
2565 }
2566 }
2567 }
2568
2569 return FALSE;
2570}
2571
2580BOOLEAN
2583 )
2584{
2585 EFI_HANDLE *AllHandlesBuffer;
2586 UINTN NumAllHandles;
2587 EFI_STATUS Status;
2588
2589 if (Dev == NULL) {
2590 DEBUG ((DEBUG_ERROR | DEBUG_INIT, "OpalDriverGetDriverDeviceName Exiting, Dev=NULL\n"));
2591 return FALSE;
2592 }
2593
2594 //
2595 // Iterate through ComponentName2 handles to get name, if fails, try ComponentName
2596 //
2597 if (Dev->Name16 == NULL) {
2598 DEBUG ((DEBUG_ERROR | DEBUG_INIT, "Name is null, update it\n"));
2599 //
2600 // Find all EFI_HANDLES
2601 //
2602 Status = gBS->LocateHandleBuffer (
2603 AllHandles,
2604 NULL,
2605 NULL,
2606 &NumAllHandles,
2607 &AllHandlesBuffer
2608 );
2609 if (EFI_ERROR (Status)) {
2610 DEBUG ((DEBUG_INFO, "LocateHandleBuffer for AllHandles failed %r\n", Status));
2611 return FALSE;
2612 }
2613
2614 //
2615 // Try component Name2
2616 //
2617 if (!OpalDriverGetDeviceNameByProtocol (AllHandlesBuffer, NumAllHandles, Dev, FALSE)) {
2618 DEBUG ((DEBUG_ERROR | DEBUG_INIT, "ComponentName2 failed to get device name, try ComponentName\n"));
2619 if (!OpalDriverGetDeviceNameByProtocol (AllHandlesBuffer, NumAllHandles, Dev, TRUE)) {
2620 DEBUG ((DEBUG_ERROR | DEBUG_INIT, "ComponentName failed to get device name, skip device\n"));
2621 return FALSE;
2622 }
2623 }
2624 }
2625
2626 return TRUE;
2627}
2628
2638EFIAPI
2640 IN EFI_HANDLE ImageHandle,
2641 IN EFI_SYSTEM_TABLE *SystemTable
2642 )
2643{
2644 EFI_STATUS Status;
2645 EFI_EVENT EndOfDxeEvent;
2646
2648 ImageHandle,
2649 SystemTable,
2650 &gOpalDriverBinding,
2651 ImageHandle,
2652 &gOpalComponentName,
2653 &gOpalComponentName2
2654 );
2655
2656 if (EFI_ERROR (Status)) {
2657 DEBUG ((DEBUG_ERROR, "Install protocols to Opal driver Handle failed\n"));
2658 return Status;
2659 }
2660
2661 //
2662 // Initialize Driver object
2663 //
2664 ZeroMem (&mOpalDriver, sizeof (mOpalDriver));
2665 mOpalDriver.Handle = ImageHandle;
2666
2667 Status = gBS->CreateEventEx (
2668 EVT_NOTIFY_SIGNAL,
2669 TPL_CALLBACK,
2671 NULL,
2672 &gEfiEndOfDxeEventGroupGuid,
2673 &EndOfDxeEvent
2674 );
2675 ASSERT_EFI_ERROR (Status);
2676
2677 //
2678 // Install Hii packages.
2679 //
2680 HiiInstall ();
2681
2682 return Status;
2683}
2684
2710EFIAPI
2713 IN EFI_HANDLE Controller,
2714 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
2715 )
2716{
2717 EFI_STATUS Status;
2719
2720 if (mOpalEndOfDxe) {
2721 return EFI_UNSUPPORTED;
2722 }
2723
2724 //
2725 // Test EFI_STORAGE_SECURITY_COMMAND_PROTOCOL on controller Handle.
2726 //
2727 Status = gBS->OpenProtocol (
2728 Controller,
2729 &gEfiStorageSecurityCommandProtocolGuid,
2730 (VOID **)&SecurityCommand,
2731 This->DriverBindingHandle,
2732 Controller,
2733 EFI_OPEN_PROTOCOL_BY_DRIVER
2734 );
2735
2736 if (Status == EFI_ALREADY_STARTED) {
2737 return EFI_SUCCESS;
2738 }
2739
2740 if (EFI_ERROR (Status)) {
2741 return Status;
2742 }
2743
2744 //
2745 // Close protocol and reopen in Start call
2746 //
2747 gBS->CloseProtocol (
2748 Controller,
2749 &gEfiStorageSecurityCommandProtocolGuid,
2750 This->DriverBindingHandle,
2751 Controller
2752 );
2753
2754 return EFI_SUCCESS;
2755}
2756
2789EFIAPI
2792 IN EFI_HANDLE Controller,
2793 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
2794 )
2795{
2796 EFI_STATUS Status;
2797 EFI_BLOCK_IO_PROTOCOL *BlkIo;
2798 OPAL_DRIVER_DEVICE *Dev;
2799 OPAL_DRIVER_DEVICE *Itr;
2800 BOOLEAN Result;
2801
2802 Itr = mOpalDriver.DeviceList;
2803 while (Itr != NULL) {
2804 if (Controller == Itr->Handle) {
2805 return EFI_SUCCESS;
2806 }
2807
2808 Itr = Itr->Next;
2809 }
2810
2811 //
2812 // Create internal device for tracking. This allows all disks to be tracked
2813 // by same HII form
2814 //
2816 if (Dev == NULL) {
2817 return EFI_OUT_OF_RESOURCES;
2818 }
2819
2820 Dev->Handle = Controller;
2821
2822 //
2823 // Open EFI_STORAGE_SECURITY_COMMAND_PROTOCOL to perform Opal supported checks
2824 //
2825 Status = gBS->OpenProtocol (
2826 Controller,
2827 &gEfiStorageSecurityCommandProtocolGuid,
2828 (VOID **)&Dev->Sscp,
2829 This->DriverBindingHandle,
2830 Controller,
2831 EFI_OPEN_PROTOCOL_BY_DRIVER
2832 );
2833 if (EFI_ERROR (Status)) {
2834 FreePool (Dev);
2835 return Status;
2836 }
2837
2838 //
2839 // Open EFI_BLOCK_IO_PROTOCOL on controller Handle, required by EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
2840 // function APIs
2841 //
2842 Status = gBS->OpenProtocol (
2843 Controller,
2844 &gEfiBlockIoProtocolGuid,
2845 (VOID **)&BlkIo,
2846 This->DriverBindingHandle,
2847 Controller,
2848 EFI_OPEN_PROTOCOL_BY_DRIVER
2849 );
2850 if (EFI_ERROR (Status)) {
2851 //
2852 // Block_IO not supported on handle
2853 //
2854 if (Status == EFI_UNSUPPORTED) {
2855 BlkIo = NULL;
2856 } else {
2857 //
2858 // Close storage security that was opened
2859 //
2860 gBS->CloseProtocol (
2861 Controller,
2862 &gEfiStorageSecurityCommandProtocolGuid,
2863 This->DriverBindingHandle,
2864 Controller
2865 );
2866
2867 FreePool (Dev);
2868 return Status;
2869 }
2870 }
2871
2872 //
2873 // Save mediaId
2874 //
2875 if (BlkIo == NULL) {
2876 // If no Block IO present, use defined MediaId value.
2877 Dev->MediaId = 0x0;
2878 } else {
2879 Dev->MediaId = BlkIo->Media->MediaId;
2880
2881 gBS->CloseProtocol (
2882 Controller,
2883 &gEfiBlockIoProtocolGuid,
2884 This->DriverBindingHandle,
2885 Controller
2886 );
2887 }
2888
2889 //
2890 // Acquire Ascii printable name of child, if not found, then ignore device
2891 //
2892 Result = OpalDriverGetDriverDeviceName (Dev);
2893 if (!Result) {
2894 goto Done;
2895 }
2896
2897 Status = OpalDiskInitialize (Dev);
2898 if (EFI_ERROR (Status)) {
2899 goto Done;
2900 }
2901
2902 AddDeviceToTail (Dev);
2903
2904 //
2905 // Check if device is locked and prompt for password.
2906 //
2907 OpalDriverRequestPassword (Dev, L"Unlock:");
2908
2909 //
2910 // Process OPAL request from last boot.
2911 //
2912 ProcessOpalRequest (Dev);
2913
2914 return EFI_SUCCESS;
2915
2916Done:
2917 //
2918 // free device, close protocols and exit
2919 //
2920 gBS->CloseProtocol (
2921 Controller,
2922 &gEfiStorageSecurityCommandProtocolGuid,
2923 This->DriverBindingHandle,
2924 Controller
2925 );
2926
2927 FreePool (Dev);
2928
2929 return EFI_DEVICE_ERROR;
2930}
2931
2946EFIAPI
2949 EFI_HANDLE Controller,
2950 UINTN NumberOfChildren,
2951 EFI_HANDLE *ChildHandleBuffer
2952 )
2953{
2954 OPAL_DRIVER_DEVICE *Itr;
2955
2956 Itr = mOpalDriver.DeviceList;
2957
2958 //
2959 // does Controller match any of the devices we are managing for Opal
2960 //
2961 while (Itr != NULL) {
2962 if (Itr->Handle == Controller) {
2964 return EFI_SUCCESS;
2965 }
2966
2967 Itr = Itr->Next;
2968 }
2969
2970 return EFI_NOT_FOUND;
2971}
2972
2982EFIAPI
2984 IN EFI_HANDLE ImageHandle
2985 )
2986{
2987 EFI_STATUS Status;
2988 OPAL_DRIVER_DEVICE *Itr;
2989
2990 Status = EFI_SUCCESS;
2991
2992 if (ImageHandle != gImageHandle) {
2993 return (EFI_INVALID_PARAMETER);
2994 }
2995
2996 //
2997 // Uninstall any interface added to each device by us
2998 //
2999 while (mOpalDriver.DeviceList) {
3000 Itr = mOpalDriver.DeviceList;
3001 //
3002 // Remove OPAL_DRIVER_DEVICE from the list
3003 // it updates the controllerList pointer
3004 //
3006 }
3007
3008 //
3009 // Uninstall the HII capability
3010 //
3011 Status = HiiUninstall ();
3012
3013 return Status;
3014}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2650
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define MSG_NVME_NAMESPACE_DP
Definition: DevicePath.h:833
#define MSG_SATA_DP
Definition: DevicePath.h:510
#define HW_PCI_DP
Definition: DevicePath.h:73
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathInstance(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DuplicateDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
RETURN_STATUS EFIAPI SetLockBoxAttributes(IN GUID *Guid, IN UINT64 Attributes)
RETURN_STATUS EFIAPI RestoreLockBox(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
RETURN_STATUS EFIAPI UpdateLockBox(IN GUID *Guid, IN UINTN Offset, IN VOID *Buffer, IN UINTN Length)
RETURN_STATUS EFIAPI SaveLockBox(IN GUID *Guid, IN VOID *Buffer, IN UINTN Length)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT8 EFIAPI PciRead8(IN UINTN Address)
Definition: PciLib.c:62
#define PCI_LIB_ADDRESS(Bus, Device, Function, Register)
Definition: PciLib.h:34
VOID OpalSupportUpdatePassword(IN OUT OPAL_DISK *OpalDisk, IN VOID *Password, IN UINT32 PasswordLength)
Definition: OpalDriver.c:189
VOID ProcessOpalRequest(IN OPAL_DRIVER_DEVICE *Dev)
Definition: OpalDriver.c:2175
VOID EFIAPI OpalEndOfDxeEventNotify(EFI_EVENT Event, VOID *Context)
Definition: OpalDriver.c:491
CHAR8 * OpalDriverPopUpPasswordInput(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *PopUpString1, IN CHAR16 *PopUpString2, IN CHAR16 *PopUpString3, OUT BOOLEAN *PressEsc)
Definition: OpalDriver.c:708
VOID ProcessOpalRequestRevert(IN OPAL_DRIVER_DEVICE *Dev, IN BOOLEAN KeepUserData, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1462
VOID SendBlockSidCommand(VOID)
Definition: OpalDriver.c:440
VOID BuildOpalDeviceInfo(VOID)
Definition: OpalDriver.c:288
EFI_STATUS EFIAPI OpalEfiDriverBindingStop(EFI_DRIVER_BINDING_PROTOCOL *This, EFI_HANDLE Controller, UINTN NumberOfChildren, EFI_HANDLE *ChildHandleBuffer)
Definition: OpalDriver.c:2947
VOID ProcessOpalRequestEnableFeature(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1061
VOID AddDeviceToTail(IN OPAL_DRIVER_DEVICE *Dev)
Definition: OpalDriver.c:2295
VOID OpalDriverRequestPassword(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:875
UINT8 GetDeviceCount(VOID)
Definition: OpalDriver.c:2351
VOID ProcessOpalRequestDisableUser(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1211
EFI_STATUS EFIAPI OpalEfiDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: OpalDriver.c:2790
CHAR8 * OpalDriverPopUpPsidInput(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *PopUpString, IN CHAR16 *PopUpString2, IN CHAR16 *PopUpString3, OUT BOOLEAN *PressEsc)
Definition: OpalDriver.c:556
OPAL_DRIVER_DEVICE * OpalDriverGetDeviceList(VOID)
Definition: OpalDriver.c:2375
BOOLEAN OpalDriverGetDriverDeviceName(OPAL_DRIVER_DEVICE *Dev)
Definition: OpalDriver.c:2581
EFI_STATUS EFIAPI EfiDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: OpalDriver.c:2639
VOID RemoveDevice(IN OPAL_DRIVER_DEVICE *Dev)
Definition: OpalDriver.c:2320
TCG_RESULT EFIAPI OpalSupportEnableOpalFeature(IN OPAL_SESSION *Session, IN VOID *Msid, IN UINT32 MsidLength, IN VOID *Password, IN UINT32 PassLength)
Definition: OpalDriver.c:138
EFI_STATUS EFIAPI OpalEfiDriverUnload(IN EFI_HANDLE ImageHandle)
Definition: OpalDriver.c:2983
VOID OpalDriverStopDevice(OPAL_DRIVER_DEVICE *Dev)
Definition: OpalDriver.c:2389
VOID ProcessOpalRequestSecureErase(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1631
BOOLEAN OpalDriverGetDeviceNameByProtocol(EFI_HANDLE *AllHandlesBuffer, UINTN NumAllHandles, OPAL_DRIVER_DEVICE *Dev, BOOLEAN UseComp1)
Definition: OpalDriver.c:2436
EFI_STATUS EFIAPI OpalEfiDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: OpalDriver.c:2711
VOID ProcessOpalRequestSetAdminPwd(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1975
VOID ExtractDeviceInfoFromDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINT32 *DevInfoLength, OUT OPAL_DEVICE_LOCKBOX_DATA *DevInfo OPTIONAL)
Definition: OpalDriver.c:208
VOID ProcessOpalRequestSetUserPwd(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1769
VOID ProcessOpalRequestPsidRevert(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:1325
CHAR16 * OpalGetPopUpString(IN OPAL_DRIVER_DEVICE *Dev, IN CHAR16 *RequestString)
Definition: OpalDriver.c:853
TCG_RESULT EFIAPI OpalSupportGetAvailableActions(IN OPAL_DISK_SUPPORT_ATTRIBUTE *SupportedAttributes, IN TCG_LOCKING_FEATURE_DESCRIPTOR *LockingFeature, IN UINT16 OwnerShip, OUT OPAL_DISK_ACTIONS *AvalDiskActions)
Definition: OpalDriver.c:51
EFI_STATUS OpalDiskUpdateOwnerShip(OPAL_DISK *OpalDisk)
Definition: OpalHii.c:1314
EFI_STATUS HiiUninstall(VOID)
Definition: OpalHii.c:436
EFI_STATUS HiiInstall(VOID)
Definition: OpalHii.c:349
EFI_STATUS OpalDiskInitialize(IN OPAL_DRIVER_DEVICE *Dev)
Definition: OpalHii.c:1256
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT32 EFIAPI Tcg2PhysicalPresenceLibGetManagementFlags(VOID)
TCG_RESULT
TCG_RESULT EFIAPI OpalUtilSetAdminPasswordAsSid(OPAL_SESSION *AdminSpSession, const VOID *GeneratedSid, UINT32 SidLength, const VOID *Password, UINT32 PassLength)
TCG_RESULT EFIAPI OpalUtilSecureErase(OPAL_SESSION *LockingSpSession, const VOID *Password, UINT32 PasswordLength, BOOLEAN *PasswordFailed)
TCG_RESULT EFIAPI OpalBlockSid(OPAL_SESSION *Session, BOOLEAN HardwareReset)
TCG_RESULT EFIAPI OpalUtilUpdateGlobalLockingRange(OPAL_SESSION *LockingSpSession, const VOID *Password, UINT32 PasswordLength, BOOLEAN ReadLocked, BOOLEAN WriteLocked)
BOOLEAN OpalDeviceLocked(OPAL_DISK_SUPPORT_ATTRIBUTE *SupportedAttributes, TCG_LOCKING_FEATURE_DESCRIPTOR *LockingFeature)
TCG_RESULT EFIAPI OpalUtilVerifyPassword(OPAL_SESSION *LockingSpSession, const VOID *Password, UINT32 PasswordLength, TCG_UID HostSigningAuthority)
TCG_RESULT EFIAPI OpalUtilDisableUser(OPAL_SESSION *LockingSpSession, const VOID *Password, UINT32 PasswordLength, BOOLEAN *PasswordFailed)
BOOLEAN EFIAPI OpalUtilAdminPasswordExists(IN UINT16 OwnerShip, IN TCG_LOCKING_FEATURE_DESCRIPTOR *LockingFeature)
TCG_RESULT EFIAPI OpalUtilSetAdminPassword(OPAL_SESSION *AdminSpSession, const VOID *OldPassword, UINT32 OldPasswordLength, const VOID *NewPassword, UINT32 NewPasswordLength)
TCG_RESULT EFIAPI OpalUtilRevert(OPAL_SESSION *LockingSpSession, BOOLEAN KeepUserData, const VOID *Password, UINT32 PasswordLength, BOOLEAN *PasswordFailed, UINT8 *Msid, UINT32 MsidLength)
TCG_RESULT EFIAPI OpalUtilPsidRevert(OPAL_SESSION *AdminSpSession, const VOID *Psid, UINT32 PsidLength)
TCG_RESULT EFIAPI OpalUtilSetUserPassword(OPAL_SESSION *LockingSpSession, const VOID *OldPassword, UINT32 OldPasswordLength, const VOID *NewPassword, UINT32 NewPasswordLength)
TCG_RESULT EFIAPI OpalUtilSetOpalLockingRange(OPAL_SESSION *LockingSpSession, const VOID *Password, UINT32 PassLength, TCG_UID LockingRangeUid, UINT64 RangeStart, UINT64 RangeLength, BOOLEAN ReadLockEnabled, BOOLEAN WriteLockEnabled, BOOLEAN ReadLocked, BOOLEAN WriteLocked)
BOOLEAN EFIAPI OpalFeatureEnabled(OPAL_DISK_SUPPORT_ATTRIBUTE *SupportedAttributes, TCG_LOCKING_FEATURE_DESCRIPTOR *LockingFeature)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1317
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
VOID EFIAPI CreatePopUp(IN UINTN Attribute, OUT EFI_INPUT_KEY *Key OPTIONAL,...)
Definition: Console.c:393
@ EfiResetShutdown
@ ByProtocol
Definition: UefiSpec.h:1518
@ AllHandles
Definition: UefiSpec.h:1509
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo.h:224
CHAR8 * NameZ
Allocated/freed by UEFI Filter Driver at device creation/removal.
Definition: OpalDriver.h:160
EFI_HANDLE Handle
Device handle.
Definition: OpalDriver.h:157
EFI_DEVICE_PATH_PROTOCOL * OpalDevicePath
Device protocols consumed.
Definition: OpalDriver.h:164
CHAR16 * Name16
Allocated/freed by UEFI Filter Driver at device creation/removal.
Definition: OpalDriver.h:159
UINT32 MediaId
Required parameter for EFI_STORAGE_SECURITY_COMMAND_PROTOCOL, from BLOCK_IO_MEDIA.
Definition: OpalDriver.h:161
OPAL_DISK OpalDisk
User context.
Definition: OpalDriver.h:158
OPAL_DRIVER_DEVICE * Next
Linked list pointer.
Definition: OpalDriver.h:156
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064
Definition: Base.h:213
EFI_HANDLE Handle
Driver image handle.
Definition: OpalDriver.h:171
OPAL_DRIVER_DEVICE * DeviceList
Linked list of controllers owned by this Driver.
Definition: OpalDriver.h:172