]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
SecurityPkg: Replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPasswordDxe / OpalHii.c
1 /** @file
2 Implementation of the HII for the Opal UEFI Driver.
3
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
9
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.
12
13 **/
14
15 #include "OpalHii.h"
16 #include "OpalDriver.h"
17 #include "OpalHiiPrivate.h"
18
19 //
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).
23 //
24 extern UINT8 OpalPasswordFormBin[];
25
26 //
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).
30 //
31 extern UINT8 OpalPasswordDxeStrings[];
32
33 CHAR16 OpalPasswordStorageName[] = L"OpalHiiConfig";
34
35 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol;
36
37 //
38 // Handle to the list of HII packages (forms and strings) for this driver
39 //
40 EFI_HII_HANDLE gHiiPackageListHandle = NULL;
41
42 //
43 // Package List GUID containing all form and string packages
44 //
45 const EFI_GUID gHiiPackageListGuid = PACKAGE_LIST_GUID;
46 const EFI_GUID gHiiSetupVariableGuid = SETUP_VARIABLE_GUID;
47
48 //
49 // Structure that contains state of the HII
50 // This structure is updated by Hii.cpp and its contents
51 // is rendered in the HII.
52 //
53 OPAL_HII_CONFIGURATION gHiiConfiguration;
54
55 CHAR8 gHiiOldPassword[MAX_PASSWORD_CHARACTER_LENGTH] = {0};
56 UINT32 gHiiOldPasswordLength = 0;
57
58 //
59 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
60 //
61 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath = {
62 {
63 {
64 HARDWARE_DEVICE_PATH,
65 HW_VENDOR_DP,
66 {
67 (UINT8)(sizeof(VENDOR_DEVICE_PATH)),
68 (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8)
69 }
70 },
71 OPAL_PASSWORD_CONFIG_GUID
72 },
73 {
74 END_DEVICE_PATH_TYPE,
75 END_ENTIRE_DEVICE_PATH_SUBTYPE,
76 {
77 (UINT8)(END_DEVICE_PATH_LENGTH),
78 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
79 }
80 }
81 };
82
83
84 /**
85 Sets the current system state of global config variables.
86
87 **/
88 VOID
89 HiiSetCurrentConfiguration(
90 VOID
91 )
92 {
93 EFI_STATUS Status;
94 OPAL_EXTRA_INFO_VAR OpalExtraInfo;
95 UINTN DataSize;
96
97 gHiiConfiguration.NumDisks = GetDeviceCount();
98
99 DataSize = sizeof (OPAL_EXTRA_INFO_VAR);
100 Status = gRT->GetVariable (
101 OPAL_EXTRA_INFO_VAR_NAME,
102 &gOpalExtraInfoVariableGuid,
103 NULL,
104 &DataSize,
105 &OpalExtraInfo
106 );
107 if (!EFI_ERROR (Status)) {
108 gHiiConfiguration.EnableBlockSid = OpalExtraInfo.EnableBlockSid;
109 }
110 }
111
112 /**
113 Install the HII related resources.
114
115 @retval EFI_SUCCESS Install all the resources success.
116 @retval other Error occur when install the resources.
117 **/
118 EFI_STATUS
119 HiiInstall(
120 VOID
121 )
122 {
123 EFI_STATUS Status;
124 EFI_HANDLE DriverHandle;
125
126 //
127 // Clear the global configuration.
128 //
129 ZeroMem(&gHiiConfiguration, sizeof(gHiiConfiguration));
130
131 //
132 // Obtain the driver handle that the BIOS assigned us
133 //
134 DriverHandle = HiiGetDriverImageHandleCB();
135
136 //
137 // Populate the config access protocol with the three functions we are publishing
138 //
139 gHiiConfigAccessProtocol.ExtractConfig = ExtractConfig;
140 gHiiConfigAccessProtocol.RouteConfig = RouteConfig;
141 gHiiConfigAccessProtocol.Callback = DriverCallback;
142
143 //
144 // Associate the required protocols with our driver handle
145 //
146 Status = gBS->InstallMultipleProtocolInterfaces(
147 &DriverHandle,
148 &gEfiHiiConfigAccessProtocolGuid,
149 &gHiiConfigAccessProtocol, // HII callback
150 &gEfiDevicePathProtocolGuid,
151 &gHiiVendorDevicePath, // required for HII callback allow all disks to be shown in same hii
152 NULL
153 );
154
155 if (EFI_ERROR(Status)) {
156 return Status;
157 }
158
159 return OpalHiiAddPackages();
160 }
161
162 /**
163 Install the HII form and string packages.
164
165 @retval EFI_SUCCESS Install all the resources success.
166 @retval EFI_OUT_OF_RESOURCES Out of resource error.
167 **/
168 EFI_STATUS
169 OpalHiiAddPackages(
170 VOID
171 )
172 {
173 EFI_HANDLE DriverHandle;
174 CHAR16 *NewString;
175
176 DriverHandle = HiiGetDriverImageHandleCB();
177
178 //
179 // Publish the HII form and HII string packages
180 //
181 gHiiPackageListHandle = HiiAddPackages(
182 &gHiiPackageListGuid,
183 DriverHandle,
184 OpalPasswordDxeStrings,
185 OpalPasswordFormBin,
186 (VOID*)NULL
187 );
188
189 //
190 // Make sure the packages installed successfully
191 //
192 if (gHiiPackageListHandle == NULL) {
193 DEBUG ((DEBUG_INFO, "OpalHiiAddPackages failed\n"));
194 return EFI_OUT_OF_RESOURCES;
195 }
196
197 //
198 // Update Version String in main window
199 //
200 NewString = HiiGetDriverNameCB ();
201 if (HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_MAIN_OPAL_VERSION), NewString, NULL) == 0) {
202 DEBUG ((DEBUG_INFO, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
203 return EFI_OUT_OF_RESOURCES;
204 }
205
206 return EFI_SUCCESS;
207 }
208
209 /**
210 Uninstall the HII capability.
211
212 @retval EFI_SUCCESS Uninstall all the resources success.
213 @retval others Other errors occur when unistall the hii resource.
214 **/
215 EFI_STATUS
216 HiiUninstall(
217 VOID
218 )
219 {
220 EFI_STATUS Status;
221
222 //
223 // Remove the packages we've provided to the BIOS
224 //
225 HiiRemovePackages(gHiiPackageListHandle);
226
227 //
228 // Remove the protocols from our driver handle
229 //
230 Status = gBS->UninstallMultipleProtocolInterfaces(
231 HiiGetDriverImageHandleCB(),
232 &gEfiHiiConfigAccessProtocolGuid,
233 &gHiiConfigAccessProtocol, // HII callback
234 &gEfiDevicePathProtocolGuid,
235 &gHiiVendorDevicePath, // required for HII callback
236 NULL
237 );
238 if (EFI_ERROR(Status)) {
239 DEBUG ((DEBUG_INFO, "Cannot uninstall Hii Protocols: %r\n", Status));
240 }
241
242 return Status;
243 }
244
245 /**
246 Updates the main menu form.
247
248 @retval EFI_SUCCESS update the main form success.
249 **/
250 EFI_STATUS
251 HiiPopulateMainMenuForm (
252 VOID
253 )
254 {
255 UINT8 Index;
256 CHAR8 *DiskName;
257 EFI_STRING_ID DiskNameId;
258 OPAL_DISK *OpalDisk;
259
260 HiiSetCurrentConfiguration();
261
262 gHiiConfiguration.SupportedDisks = 0;
263
264 for (Index = 0; Index < gHiiConfiguration.NumDisks; Index++) {
265 OpalDisk = HiiGetOpalDiskCB (Index);
266 if ((OpalDisk != NULL) && OpalFeatureSupported (&OpalDisk->SupportedAttributes)) {
267 gHiiConfiguration.SupportedDisks |= (1 << Index);
268 DiskNameId = GetDiskNameStringId (Index);
269 DiskName = HiiDiskGetNameCB (Index);
270 if ((DiskName == NULL) || (DiskNameId == 0)) {
271 return EFI_UNSUPPORTED;
272 }
273 HiiSetFormString(DiskNameId, DiskName);
274 }
275 }
276
277 OpalHiiSetBrowserData ();
278 return EFI_SUCCESS;
279 }
280
281 /**
282 Update the disk action info.
283
284 @param ActionString
285 @param SelectedAction
286
287 @retval EFI_SUCCESS Uninstall all the resources success.
288 **/
289 EFI_STATUS
290 HiiSelectDiskAction (
291 CHAR8 *ActionString,
292 UINT8 SelectedAction
293 )
294 {
295 OPAL_DISK *OpalDisk;
296 OPAL_DISK_ACTIONS AvailActions;
297
298 OpalHiiGetBrowserData ();
299
300 HiiSetFormString(STRING_TOKEN(STR_DISK_ACTION_LBL), ActionString);
301 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), " ");
302
303 gHiiConfiguration.SelectedAction = SelectedAction;
304 gHiiConfiguration.AvailableFields = 0;
305
306 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
307 if (OpalDisk == NULL) {
308 return EFI_INVALID_PARAMETER;
309 }
310
311 if (OpalSupportGetAvailableActions (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature, OpalDisk->Owner, &AvailActions) != TcgResultSuccess) {
312 return EFI_DEVICE_ERROR;
313 }
314
315 switch (SelectedAction) {
316 case HII_KEY_ID_GOTO_LOCK:
317 case HII_KEY_ID_GOTO_UNLOCK:
318 case HII_KEY_ID_GOTO_SET_ADMIN_PWD:
319 case HII_KEY_ID_GOTO_SET_USER_PWD:
320 case HII_KEY_ID_GOTO_SECURE_ERASE:
321 case HII_KEY_ID_GOTO_DISABLE_USER:
322 case HII_KEY_ID_GOTO_ENABLE_FEATURE: // User is required to enter Password to enable Feature
323 gHiiConfiguration.AvailableFields |= HII_FIELD_PASSWORD;
324 break;
325
326 case HII_KEY_ID_GOTO_PSID_REVERT:
327 gHiiConfiguration.AvailableFields |= HII_FIELD_PSID;
328 break;
329
330 case HII_KEY_ID_GOTO_REVERT:
331 gHiiConfiguration.AvailableFields |= HII_FIELD_PASSWORD;
332 gHiiConfiguration.AvailableFields |= HII_FIELD_KEEP_USER_DATA;
333 if (AvailActions.RevertKeepDataForced) {
334 gHiiConfiguration.AvailableFields |= HII_FIELD_KEEP_USER_DATA_FORCED;
335 }
336 break;
337 }
338
339 OpalHiiSetBrowserData ();
340
341 return EFI_SUCCESS;
342 }
343
344 /**
345 Get disk name string id.
346
347 @param DiskIndex The input disk index info.
348
349 @retval The disk name string id.
350
351 **/
352 EFI_STRING_ID
353 GetDiskNameStringId(
354 UINT8 DiskIndex
355 )
356 {
357 switch (DiskIndex) {
358 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0);
359 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1);
360 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2);
361 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3);
362 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4);
363 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5);
364 }
365 return 0;
366 }
367
368 /**
369 This function processes the results of changes in configuration.
370
371 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
372 @param Action Specifies the type of action taken by the browser.
373 @param QuestionId A unique value which is sent to the original
374 exporting driver so that it can identify the type
375 of data to expect.
376 @param Type The type of value for the question.
377 @param Value A pointer to the data being sent to the original
378 exporting driver.
379 @param ActionRequest On return, points to the action requested by the
380 callback function.
381
382 @retval EFI_SUCCESS The callback successfully handled the action.
383 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
384 variable and its data.
385 @retval EFI_DEVICE_ERROR The variable could not be saved.
386 @retval EFI_UNSUPPORTED The specified Action is not supported by the
387 callback.
388
389 **/
390 EFI_STATUS
391 EFIAPI
392 DriverCallback(
393 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
394 EFI_BROWSER_ACTION Action,
395 EFI_QUESTION_ID QuestionId,
396 UINT8 Type,
397 EFI_IFR_TYPE_VALUE *Value,
398 EFI_BROWSER_ACTION_REQUEST *ActionRequest
399 )
400 {
401 HII_KEY HiiKey;
402 UINT8 HiiKeyId;
403
404 if (ActionRequest != NULL) {
405 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
406 } else {
407 return EFI_INVALID_PARAMETER;
408 }
409
410 //
411 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
412 //
413 if ((QuestionId & HII_KEY_FLAG) == 0) {
414 return EFI_SUCCESS;
415 }
416
417 HiiKey.Raw = QuestionId;
418 HiiKeyId = (UINT8) HiiKey.KeyBits.Id;
419
420 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
421 switch (HiiKeyId) {
422 case HII_KEY_ID_VAR_SUPPORTED_DISKS:
423 DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
424 return HiiPopulateMainMenuForm ();
425
426 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS:
427 return HiiPopulateDiskInfoForm();
428 }
429 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {
430 switch (HiiKeyId) {
431 case HII_KEY_ID_GOTO_DISK_INFO:
432 return HiiSelectDisk((UINT8)HiiKey.KeyBits.Index);
433
434 case HII_KEY_ID_GOTO_LOCK:
435 return HiiSelectDiskAction("Action: Lock", HiiKeyId);
436
437 case HII_KEY_ID_GOTO_UNLOCK:
438 return HiiSelectDiskAction("Action: Unlock", HiiKeyId);
439
440 case HII_KEY_ID_GOTO_SET_ADMIN_PWD:
441 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId);
442
443 case HII_KEY_ID_GOTO_SET_USER_PWD:
444 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId);
445
446 case HII_KEY_ID_GOTO_SECURE_ERASE:
447 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId);
448
449 case HII_KEY_ID_GOTO_PSID_REVERT:
450 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId);
451
452 case HII_KEY_ID_GOTO_REVERT:
453 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId);
454
455 case HII_KEY_ID_GOTO_DISABLE_USER:
456 return HiiSelectDiskAction("Action: Disable User", HiiKeyId);
457
458 case HII_KEY_ID_GOTO_ENABLE_FEATURE:
459 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId);
460
461 case HII_KEY_ID_ENTER_PASSWORD:
462 return HiiPasswordEntered(Value->string);
463 }
464 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
465 switch (HiiKeyId) {
466 case HII_KEY_ID_ENTER_PSID:
467 HiiPsidRevert();
468 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
469 return EFI_SUCCESS;
470
471 case HII_KEY_ID_BLOCKSID:
472 HiiSetBlockSid(Value->b);
473 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
474 return EFI_SUCCESS;
475 }
476 }
477
478 return EFI_UNSUPPORTED;
479 }
480
481 /**
482 Update the global Disk index info.
483
484 @param Index The input disk index info.
485
486 @retval EFI_SUCCESS Update the disk index info success.
487
488 **/
489 EFI_STATUS
490 HiiSelectDisk(
491 UINT8 Index
492 )
493 {
494 OpalHiiGetBrowserData();
495 gHiiConfiguration.SelectedDiskIndex = Index;
496 OpalHiiSetBrowserData ();
497
498 return EFI_SUCCESS;
499 }
500
501 /**
502 Draws the disk info form.
503
504 @retval EFI_SUCCESS Draw the disk info success.
505
506 **/
507 EFI_STATUS
508 HiiPopulateDiskInfoForm(
509 VOID
510 )
511 {
512 OPAL_DISK* OpalDisk;
513 OPAL_DISK_ACTIONS AvailActions;
514 TCG_RESULT Ret;
515 CHAR8 *DiskName;
516
517 OpalHiiGetBrowserData();
518
519 DiskName = HiiDiskGetNameCB (gHiiConfiguration.SelectedDiskIndex);
520 if (DiskName == NULL) {
521 return EFI_UNSUPPORTED;
522 }
523 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME), DiskName);
524
525 ZeroMem(gHiiConfiguration.Psid, sizeof(gHiiConfiguration.Psid));
526
527 gHiiConfiguration.SelectedDiskAvailableActions = HII_ACTION_NONE;
528
529 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
530
531 if (OpalDisk != NULL) {
532 OpalDiskUpdateStatus (OpalDisk);
533 Ret = OpalSupportGetAvailableActions(&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature, OpalDisk->Owner, &AvailActions);
534 if (Ret == TcgResultSuccess) {
535 //
536 // Update actions, always allow PSID Revert
537 //
538 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.PsidRevert == 1) ? HII_ACTION_PSID_REVERT : HII_ACTION_NONE;
539
540 //
541 // Always allow unlock to handle device migration
542 //
543 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Unlock == 1) ? HII_ACTION_UNLOCK : HII_ACTION_NONE;
544
545 if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {
546 if (OpalDisk->Owner == OpalOwnershipNobody) {
547 gHiiConfiguration.SelectedDiskAvailableActions |= HII_ACTION_ENABLE_FEATURE;
548
549 //
550 // Update strings
551 //
552 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default");
553 } else {
554 DEBUG ((DEBUG_INFO, "Feature disabled but ownership != nobody\n"));
555 }
556 } else {
557 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Revert == 1) ? HII_ACTION_REVERT : HII_ACTION_NONE;
558 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.AdminPass == 1) ? HII_ACTION_SET_ADMIN_PWD : HII_ACTION_NONE;
559 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.UserPass == 1) ? HII_ACTION_SET_USER_PWD : HII_ACTION_NONE;
560 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.SecureErase == 1) ? HII_ACTION_SECURE_ERASE : HII_ACTION_NONE;
561 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.DisableUser == 1) ? HII_ACTION_DISABLE_USER : HII_ACTION_NONE;
562
563 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default and Disable");
564
565 //
566 // Determine revert options for disk
567 // Default initialize keep user Data to be true
568 //
569 gHiiConfiguration.KeepUserData = 1;
570 }
571 }
572 }
573
574 //
575 // Pass the current configuration to the BIOS
576 //
577 OpalHiiSetBrowserData ();
578
579 return EFI_SUCCESS;
580 }
581
582 /**
583 Reverts the Opal disk to factory default.
584
585 @retval EFI_SUCCESS Do the required action success.
586
587 **/
588 EFI_STATUS
589 HiiPsidRevert(
590 VOID
591 )
592 {
593 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
594 TCG_PSID Psid;
595 OPAL_DISK *OpalDisk;
596 TCG_RESULT Ret;
597 OPAL_SESSION Session;
598
599 Ret = TcgResultFailure;
600
601 OpalHiiGetBrowserData();
602
603 UnicodeStrToAsciiStrS (gHiiConfiguration.Psid, (CHAR8*)Psid.Psid, PSID_CHARACTER_LENGTH);
604
605 OpalDisk = HiiGetOpalDiskCB (gHiiConfiguration.SelectedDiskIndex);
606 if (OpalDisk != NULL) {
607 ZeroMem(&Session, sizeof(Session));
608 Session.Sscp = OpalDisk->Sscp;
609 Session.MediaId = OpalDisk->MediaId;
610 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
611
612 Ret = OpalSupportPsidRevert(&Session, Psid.Psid, (UINT32)sizeof(Psid.Psid), OpalDisk->OpalDevicePath);
613 }
614
615 if (Ret == TcgResultSuccess) {
616 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "PSID Revert: Success" );
617 } else {
618 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "PSID Revert: Failure" );
619 }
620
621 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
622
623 return EFI_SUCCESS;
624 }
625
626 /**
627 Set password for the disk.
628
629 @param OpalDisk The disk need to set the password.
630 @param Password The input password.
631 @param PassLength The input password length.
632
633 @retval EFI_SUCCESS Do the required action success.
634
635 **/
636 EFI_STATUS
637 HiiSetPassword(
638 OPAL_DISK *OpalDisk,
639 VOID *Password,
640 UINT32 PassLength
641 )
642 {
643 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
644 TCG_RESULT Ret;
645 BOOLEAN ExistingPassword;
646 OPAL_SESSION Session;
647
648 ExistingPassword = FALSE;
649
650 //
651 // PassLength = 0 means check whether exist old password.
652 //
653 if (PassLength == 0) {
654 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
655 gHiiOldPasswordLength = 0;
656
657 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_ENABLE_FEATURE) {
658 ExistingPassword = FALSE;
659 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_ADMIN_PWD) {
660 ExistingPassword = OpalUtilAdminPasswordExists(OpalDisk->Owner, &OpalDisk->LockingFeature);
661 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
662 //
663 // Set user Password option shall only be shown if an Admin Password exists
664 // so a Password is always required (Admin or Existing User Password)
665 //
666 ExistingPassword = TRUE;
667 }
668
669 //
670 // Return error if there is a previous Password
671 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
672 //
673 return ExistingPassword ? EFI_DEVICE_ERROR : EFI_SUCCESS;
674 }
675
676 ZeroMem(&Session, sizeof(Session));
677 Session.Sscp = OpalDisk->Sscp;
678 Session.MediaId = OpalDisk->MediaId;
679 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
680
681 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Failure");
682 //
683 // Password entered.
684 // No current Owner, so set new Password, must be admin Password
685 //
686 if (OpalDisk->Owner == OpalOwnershipNobody) {
687 Ret = OpalSupportEnableOpalFeature (&Session, OpalDisk->Msid, OpalDisk->MsidLength,Password, PassLength, OpalDisk->OpalDevicePath);
688 if (Ret == TcgResultSuccess) {
689 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Success");
690 }
691
692 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
693 return EFI_SUCCESS;
694 }
695
696 //
697 // 1st Password entered
698 //
699 if (OpalDisk->Owner == OpalOwnershipUnknown && gHiiOldPasswordLength == 0) {
700
701 //
702 // Unknown ownership - prompt for old Password, then new
703 // old Password is not set yet - first time through
704 // assume authority provided is admin1, overwritten if user1 authority works below
705 //
706 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
707 //
708 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
709 //
710 Ret = OpalUtilVerifyPassword (&Session, Password, PassLength, OPAL_LOCKING_SP_USER1_AUTHORITY);
711 if (Ret == TcgResultSuccess) {
712 //
713 // User1 worked so authority 1 means user 1
714 //
715 CopyMem(gHiiOldPassword, Password, PassLength);
716 gHiiOldPasswordLength = PassLength;
717
718 return EFI_SUCCESS;
719 }
720 }
721
722 //
723 // Else try admin1 below
724 //
725 Ret = OpalUtilVerifyPassword (&Session, Password, PassLength, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);
726 if (Ret == TcgResultSuccess) {
727 CopyMem(gHiiOldPassword, Password, PassLength);
728 gHiiOldPasswordLength = PassLength;
729
730 return EFI_SUCCESS;
731 } else {
732 DEBUG ((DEBUG_INFO, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
733 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), "Authentication Failure");
734
735 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
736 gHiiOldPasswordLength = 0;
737
738 return EFI_NOT_READY;
739 }
740 }
741
742 //
743 // New Password entered
744 //
745 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
746 Ret = OpalSupportSetPassword(
747 &Session,
748 gHiiOldPassword,
749 gHiiOldPasswordLength,
750 Password,
751 PassLength,
752 OpalDisk->OpalDevicePath,
753 FALSE
754 );
755 } else {
756 Ret = OpalSupportSetPassword(
757 &Session,
758 gHiiOldPassword,
759 gHiiOldPasswordLength,
760 Password,
761 PassLength,
762 OpalDisk->OpalDevicePath,
763 TRUE
764 );
765 }
766
767 if (Ret == TcgResultSuccess) {
768 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Success");
769 }
770
771 //
772 // Reset old Password storage
773 //
774 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
775 gHiiOldPasswordLength = 0;
776
777 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
778 return Ret == TcgResultSuccess ? EFI_SUCCESS : EFI_NOT_READY;
779 }
780
781 /**
782 Secure Erases Opal Disk.
783
784 @param OpalDisk The disk need to erase data.
785 @param Password The input password.
786 @param PassLength The input password length.
787
788 @retval EFI_SUCCESS Do the required action success.
789
790 **/
791 EFI_STATUS
792 HiiSecureErase(
793 OPAL_DISK *OpalDisk,
794 const VOID *Password,
795 UINT32 PassLength
796 )
797 {
798 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
799 BOOLEAN PasswordFailed;
800 TCG_RESULT Ret;
801 OPAL_SESSION AdminSpSession;
802
803 if (PassLength == 0) {
804 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
805 }
806
807 ZeroMem(&AdminSpSession, sizeof(AdminSpSession));
808 AdminSpSession.Sscp = OpalDisk->Sscp;
809 AdminSpSession.MediaId = OpalDisk->MediaId;
810 AdminSpSession.OpalBaseComId = OpalDisk->OpalBaseComId;
811
812 Ret = OpalUtilSecureErase(&AdminSpSession, Password, PassLength, &PasswordFailed);
813 if (Ret == TcgResultSuccess) {
814 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Secure Erase: Success" );
815 } else {
816 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Secure Erase: Failure" );
817 }
818 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
819
820 //
821 // If Password failed, return invalid passowrd
822 //
823 if (PasswordFailed) {
824 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
825 return EFI_NOT_READY;
826 }
827
828 //
829 // Indicates Password was valid and is not changing to UEFI
830 // Response string will indicate action error
831 //
832 return EFI_DEVICE_ERROR;
833 }
834
835
836 /**
837 Disables User for Opal Disk.
838
839 @param OpalDisk The disk need to the action.
840 @param Password The input password.
841 @param PassLength The input password length.
842
843 @retval EFI_SUCCESS Do the required action success.
844
845 **/
846 EFI_STATUS
847 HiiDisableUser(
848 OPAL_DISK *OpalDisk,
849 VOID *Password,
850 UINT32 PassLength
851 )
852 {
853 CHAR8 Response[ DEFAULT_RESPONSE_SIZE ];
854 BOOLEAN PasswordFailed;
855 TCG_RESULT Ret;
856 OPAL_SESSION Session;
857
858 if (PassLength == 0) {
859 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
860 }
861
862 ZeroMem(&Session, sizeof(Session));
863 Session.Sscp = OpalDisk->Sscp;
864 Session.MediaId = OpalDisk->MediaId;
865 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
866
867 Ret = OpalSupportDisableUser(&Session, Password, PassLength, &PasswordFailed, OpalDisk->OpalDevicePath);
868 if (Ret == TcgResultSuccess) {
869 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Disable User: Success" );
870 } else {
871 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Disable User: Failure" );
872 }
873 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS), Response);
874
875 //
876 // If Password failed, return invalid passowrd
877 //
878 if (PasswordFailed) {
879 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
880 return EFI_NOT_READY;
881 }
882
883 //
884 // Indicates Password was valid and is not changing to UEFI
885 // Response string will indicate action error
886 //
887 return EFI_DEVICE_ERROR;
888 }
889
890 /**
891 Revert Opal Disk as Admin1.
892
893 @param OpalDisk The disk need to the action.
894 @param Password The input password.
895 @param PassLength The input password length.
896 @param KeepUserData Whether need to keey user data.
897
898 @retval EFI_SUCCESS Do the required action success.
899
900 **/
901 EFI_STATUS
902 HiiRevert(
903 OPAL_DISK *OpalDisk,
904 VOID *Password,
905 UINT32 PassLength,
906 BOOLEAN KeepUserData
907 )
908 {
909 CHAR8 Response[ DEFAULT_RESPONSE_SIZE ];
910 BOOLEAN PasswordFailed;
911 TCG_RESULT Ret;
912 OPAL_SESSION Session;
913
914 if (PassLength == 0) {
915 DEBUG ((DEBUG_INFO, "Returning error to indicate there is an existing Password\n"));
916 // return error to indicate there is an existing Password
917 return EFI_DEVICE_ERROR;
918 }
919
920 ZeroMem(&Session, sizeof(Session));
921 Session.Sscp = OpalDisk->Sscp;
922 Session.MediaId = OpalDisk->MediaId;
923 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
924
925 Ret = OpalSupportRevert(
926 &Session,
927 KeepUserData,
928 Password,
929 PassLength,
930 OpalDisk->Msid,
931 OpalDisk->MsidLength,
932 &PasswordFailed,
933 OpalDisk->OpalDevicePath
934 );
935 if (Ret == TcgResultSuccess) {
936 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Revert: Success" );
937 } else {
938 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Revert: Failure" );
939 }
940 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
941
942 //
943 // If Password failed, return invalid passowrd
944 //
945 if (PasswordFailed) {
946 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
947 return EFI_NOT_READY;
948 }
949
950 //
951 // Indicates Password was valid and is not changing to UEFI
952 // Response string will indicate action error
953 //
954 return EFI_DEVICE_ERROR;
955 }
956
957 /**
958 Unlocks Opal Disk.
959
960 @param OpalDisk The disk need to the action.
961 @param Password The input password.
962 @param PassLength The input password length.
963
964 @retval EFI_SUCCESS Do the required action success.
965
966 **/
967 EFI_STATUS
968 HiiUnlock(
969 OPAL_DISK *OpalDisk,
970 VOID *Password,
971 UINT32 PassLength
972 )
973 {
974 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
975 TCG_RESULT Ret;
976 OPAL_SESSION Session;
977
978 if (PassLength == 0) {
979 DEBUG ((DEBUG_INFO, "Returning error to indicate there is an existing Password\n"));
980 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
981 }
982
983 ZeroMem(&Session, sizeof(Session));
984 Session.Sscp = OpalDisk->Sscp;
985 Session.MediaId = OpalDisk->MediaId;
986 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
987
988 Ret = OpalSupportUnlock(&Session, Password, PassLength, OpalDisk->OpalDevicePath);
989 if (Ret == TcgResultSuccess) {
990 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Unlock: Success" );
991 } else {
992 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Unlock: Failure" );
993 }
994
995 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
996
997 if (Ret == TcgResultSuccess) {
998 DEBUG ((DEBUG_INFO, "returning error to indicate Password was correct but is not changing\n"));
999 return EFI_DEVICE_ERROR;
1000 } else {
1001 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1002 return EFI_NOT_READY;
1003 }
1004 }
1005
1006 /**
1007 Use the input password to do the specified action.
1008
1009 @param Str The input password saved in.
1010
1011 @retval EFI_SUCCESS Do the required action success.
1012 @retval Others Other error occur.
1013
1014 **/
1015 EFI_STATUS
1016 HiiPasswordEntered(
1017 EFI_STRING_ID Str
1018 )
1019 {
1020 OPAL_DISK* OpalDisk;
1021 CHAR8 Password[MAX_PASSWORD_CHARACTER_LENGTH + 1];
1022 CHAR16* UniStr;
1023 UINT32 PassLength;
1024 EFI_STATUS Status;
1025
1026 OpalHiiGetBrowserData();
1027
1028 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
1029 if (OpalDisk == NULL) {
1030 DEBUG ((DEBUG_INFO, "ERROR: disk %u not found\n", gHiiConfiguration.SelectedDiskIndex));
1031 return EFI_NOT_FOUND;
1032 }
1033
1034 if (Str == 0) {
1035 DEBUG ((DEBUG_INFO, "ERROR: str=NULL\n"));
1036 return EFI_INVALID_PARAMETER;
1037 }
1038
1039 ZeroMem(Password, sizeof(Password));
1040
1041 UniStr = HiiGetString(gHiiPackageListHandle, Str, NULL);
1042 if (UniStr == NULL) {
1043 return EFI_NOT_FOUND;
1044 }
1045 PassLength = (UINT32) StrLen (UniStr);
1046 if (PassLength >= sizeof(Password)) {
1047 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), "Password too long");
1048 gBS->FreePool(UniStr);
1049 return EFI_BUFFER_TOO_SMALL;
1050 }
1051
1052 UnicodeStrToAsciiStrS (UniStr, Password, sizeof (Password));
1053 gBS->FreePool(UniStr);
1054
1055 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_UNLOCK) {
1056 Status = HiiUnlock (OpalDisk, Password, PassLength);
1057 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SECURE_ERASE) {
1058 Status = HiiSecureErase (OpalDisk, Password, PassLength);
1059 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_DISABLE_USER) {
1060 Status = HiiDisableUser (OpalDisk, Password, PassLength);
1061 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_REVERT) {
1062 if (OpalDisk->SupportedAttributes.PyriteSsc == 1 && OpalDisk->LockingFeature.MediaEncryption == 0) {
1063 //
1064 // For pyrite type device which also not supports media encryption, it not accept "Keep User Data" parameter.
1065 // So here hardcode a FALSE for this case.
1066 //
1067 Status = HiiRevert(OpalDisk, Password, PassLength, FALSE);
1068 } else {
1069 Status = HiiRevert(OpalDisk, Password, PassLength, gHiiConfiguration.KeepUserData);
1070 }
1071 } else {
1072 Status = HiiSetPassword(OpalDisk, Password, PassLength);
1073 }
1074
1075 OpalHiiSetBrowserData ();
1076
1077 return Status;
1078 }
1079
1080 /**
1081 Update block sid info.
1082
1083 @param Enable Enable/disable BlockSid.
1084
1085 @retval EFI_SUCCESS Do the required action success.
1086 @retval Others Other error occur.
1087
1088 **/
1089 EFI_STATUS
1090 HiiSetBlockSid (
1091 BOOLEAN Enable
1092 )
1093 {
1094 EFI_STATUS Status;
1095 OPAL_EXTRA_INFO_VAR OpalExtraInfo;
1096 UINTN DataSize;
1097
1098 Status = EFI_SUCCESS;
1099
1100 OpalExtraInfo.EnableBlockSid = Enable;
1101 DataSize = sizeof (OPAL_EXTRA_INFO_VAR);
1102 Status = gRT->SetVariable (
1103 OPAL_EXTRA_INFO_VAR_NAME,
1104 &gOpalExtraInfoVariableGuid,
1105 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1106 DataSize,
1107 &OpalExtraInfo
1108 );
1109
1110 return Status;
1111 }
1112
1113 /**
1114 This function processes the results of changes in configuration.
1115
1116 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1117 @param Configuration A null-terminated Unicode string in <ConfigResp>
1118 format.
1119 @param Progress A pointer to a string filled in with the offset of
1120 the most recent '&' before the first failing
1121 name/value pair (or the beginning of the string if
1122 the failure is in the first name/value pair) or
1123 the terminating NULL if all was successful.
1124
1125 @retval EFI_SUCCESS The Results is processed successfully.
1126 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1127 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1128 driver.
1129
1130 **/
1131 EFI_STATUS
1132 EFIAPI
1133 RouteConfig(
1134 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1135 CONST EFI_STRING Configuration,
1136 EFI_STRING *Progress
1137 )
1138 {
1139 if (Configuration == NULL || Progress == NULL) {
1140 return (EFI_INVALID_PARAMETER);
1141 }
1142
1143 *Progress = Configuration;
1144 if (!HiiIsConfigHdrMatch (Configuration, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
1145 return EFI_NOT_FOUND;
1146 }
1147
1148 *Progress = Configuration + StrLen (Configuration);
1149
1150 return EFI_SUCCESS;
1151 }
1152
1153 /**
1154 This function allows a caller to extract the current configuration for one
1155 or more named elements from the target driver.
1156
1157 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1158 @param Request A null-terminated Unicode string in
1159 <ConfigRequest> format.
1160 @param Progress On return, points to a character in the Request
1161 string. Points to the string's null terminator if
1162 request was successful. Points to the most recent
1163 '&' before the first failing name/value pair (or
1164 the beginning of the string if the failure is in
1165 the first name/value pair) if the request was not
1166 successful.
1167 @param Results A null-terminated Unicode string in
1168 <ConfigAltResp> format which has all values filled
1169 in for the names in the Request string. String to
1170 be allocated by the called function.
1171
1172 @retval EFI_SUCCESS The Results is filled with the requested values.
1173 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1174 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1175 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1176 driver.
1177
1178 **/
1179 EFI_STATUS
1180 EFIAPI
1181 ExtractConfig(
1182 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1183 CONST EFI_STRING Request,
1184 EFI_STRING *Progress,
1185 EFI_STRING *Results
1186 )
1187 {
1188 EFI_STATUS Status;
1189
1190 //
1191 // Check for valid parameters
1192 //
1193 if (Progress == NULL || Results == NULL) {
1194 return (EFI_INVALID_PARAMETER);
1195 }
1196
1197 *Progress = Request;
1198 if ((Request != NULL) &&
1199 !HiiIsConfigHdrMatch (Request, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
1200 return EFI_NOT_FOUND;
1201 }
1202
1203 //
1204 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1205 //
1206 Status = gHiiConfigRouting->BlockToConfig(
1207 gHiiConfigRouting,
1208 Request,
1209 (UINT8*)&gHiiConfiguration,
1210 sizeof(OPAL_HII_CONFIGURATION),
1211 Results,
1212 Progress
1213 );
1214
1215 return (Status);
1216 }
1217
1218
1219 /**
1220
1221 Pass the current system state to the bios via the hii_G_Configuration.
1222
1223 **/
1224 VOID
1225 OpalHiiSetBrowserData (
1226 VOID
1227 )
1228 {
1229 HiiSetBrowserData(
1230 &gHiiSetupVariableGuid,
1231 (CHAR16*)L"OpalHiiConfig",
1232 sizeof(gHiiConfiguration),
1233 (UINT8*)&gHiiConfiguration,
1234 NULL
1235 );
1236 }
1237
1238
1239 /**
1240
1241 Populate the hii_g_Configuraton with the browser Data.
1242
1243 **/
1244 VOID
1245 OpalHiiGetBrowserData (
1246 VOID
1247 )
1248 {
1249 HiiGetBrowserData(
1250 &gHiiSetupVariableGuid,
1251 (CHAR16*)L"OpalHiiConfig",
1252 sizeof(gHiiConfiguration),
1253 (UINT8*)&gHiiConfiguration
1254 );
1255 }
1256
1257 /**
1258 Set a string Value in a form.
1259
1260 @param DestStringId The stringid which need to update.
1261 @param SrcAsciiStr The string nned to update.
1262
1263 @retval EFI_SUCCESS Do the required action success.
1264 @retval Others Other error occur.
1265
1266 **/
1267 EFI_STATUS
1268 HiiSetFormString(
1269 EFI_STRING_ID DestStringId,
1270 CHAR8 *SrcAsciiStr
1271 )
1272 {
1273 UINT32 Len;
1274 UINT32 UniSize;
1275 CHAR16* UniStr;
1276
1277 //
1278 // Determine the Length of the sting
1279 //
1280 Len = ( UINT32 )AsciiStrLen( SrcAsciiStr );
1281
1282 //
1283 // Allocate space for the unicode string, including terminator
1284 //
1285 UniSize = (Len + 1) * sizeof(CHAR16);
1286 UniStr = (CHAR16*)AllocateZeroPool(UniSize);
1287
1288 //
1289 // Copy into unicode string, then copy into string id
1290 //
1291 AsciiStrToUnicodeStrS ( SrcAsciiStr, UniStr, Len + 1);
1292
1293 //
1294 // Update the string in the form
1295 //
1296 if (HiiSetString(gHiiPackageListHandle, DestStringId, UniStr, NULL) == 0) {
1297 DEBUG ((DEBUG_INFO, "HiiSetFormString( ) failed\n"));
1298 FreePool(UniStr);
1299 return (EFI_OUT_OF_RESOURCES);
1300 }
1301
1302 //
1303 // Free the memory
1304 //
1305 FreePool(UniStr);
1306
1307 return (EFI_SUCCESS);
1308 }
1309
1310 /**
1311 Initialize the Opal disk base on the hardware info get from device.
1312
1313 @param Dev The Opal device.
1314
1315 @retval EFI_SUCESS Initialize the device success.
1316 @retval EFI_DEVICE_ERROR Get info from device failed.
1317
1318 **/
1319 EFI_STATUS
1320 OpalDiskInitialize (
1321 IN OPAL_DRIVER_DEVICE *Dev
1322 )
1323 {
1324 TCG_RESULT TcgResult;
1325 OPAL_SESSION Session;
1326
1327 ZeroMem(&Dev->OpalDisk, sizeof(OPAL_DISK));
1328 Dev->OpalDisk.Sscp = Dev->Sscp;
1329 Dev->OpalDisk.MediaId = Dev->MediaId;
1330 Dev->OpalDisk.OpalDevicePath = Dev->OpalDevicePath;
1331
1332 ZeroMem(&Session, sizeof(Session));
1333 Session.Sscp = Dev->Sscp;
1334 Session.MediaId = Dev->MediaId;
1335
1336 TcgResult = OpalGetSupportedAttributesInfo (&Session, &Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.OpalBaseComId);
1337 if (TcgResult != TcgResultSuccess) {
1338 return EFI_DEVICE_ERROR;
1339 }
1340 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1341
1342 TcgResult = OpalUtilGetMsid (&Session, Dev->OpalDisk.Msid, OPAL_MSID_LENGHT, &Dev->OpalDisk.MsidLength);
1343 if (TcgResult != TcgResultSuccess) {
1344 return EFI_DEVICE_ERROR;
1345 }
1346
1347 return OpalDiskUpdateStatus (&Dev->OpalDisk);
1348 }
1349
1350 /**
1351 Update the device info.
1352
1353 @param OpalDisk The Opal device.
1354
1355 @retval EFI_SUCESS Initialize the device success.
1356 @retval EFI_DEVICE_ERROR Get info from device failed.
1357 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1358
1359 **/
1360 EFI_STATUS
1361 OpalDiskUpdateStatus (
1362 OPAL_DISK *OpalDisk
1363 )
1364 {
1365 TCG_RESULT TcgResult;
1366 OPAL_SESSION Session;
1367
1368 ZeroMem(&Session, sizeof(Session));
1369 Session.Sscp = OpalDisk->Sscp;
1370 Session.MediaId = OpalDisk->MediaId;
1371 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1372
1373 TcgResult = OpalGetLockingInfo(&Session, &OpalDisk->LockingFeature);
1374 if (TcgResult != TcgResultSuccess) {
1375 return EFI_DEVICE_ERROR;
1376 }
1377
1378 if (OpalDisk->MsidLength == 0) {
1379 return EFI_INVALID_PARAMETER;
1380 } else {
1381 //
1382 // Base on the Msid info to get the ownership, so Msid info must get first.
1383 //
1384 OpalDisk->Owner = OpalUtilDetermineOwnership(&Session, OpalDisk->Msid, OpalDisk->MsidLength);
1385 }
1386
1387 return EFI_SUCCESS;
1388 }
1389