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