]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
MdeModulePkg/CapsuleApp: remove unused definition.
[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 UINT8 TmpBuf[PSID_CHARACTER_STRING_END_LENGTH];
599
600 Ret = TcgResultFailure;
601
602 OpalHiiGetBrowserData();
603
604 ZeroMem (TmpBuf, sizeof (TmpBuf));
605 UnicodeStrToAsciiStrS (gHiiConfiguration.Psid, (CHAR8*)TmpBuf, PSID_CHARACTER_STRING_END_LENGTH);
606 CopyMem (Psid.Psid, TmpBuf, PSID_CHARACTER_LENGTH);
607
608 OpalDisk = HiiGetOpalDiskCB (gHiiConfiguration.SelectedDiskIndex);
609 if (OpalDisk != NULL) {
610 ZeroMem(&Session, sizeof(Session));
611 Session.Sscp = OpalDisk->Sscp;
612 Session.MediaId = OpalDisk->MediaId;
613 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
614
615 Ret = OpalSupportPsidRevert(&Session, Psid.Psid, (UINT32)sizeof(Psid.Psid), OpalDisk->OpalDevicePath);
616 }
617
618 if (Ret == TcgResultSuccess) {
619 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "PSID Revert: Success" );
620 } else {
621 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "PSID Revert: Failure" );
622 }
623
624 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
625
626 return EFI_SUCCESS;
627 }
628
629 /**
630 Set password for the disk.
631
632 @param OpalDisk The disk need to set the password.
633 @param Password The input password.
634 @param PassLength The input password length.
635
636 @retval EFI_SUCCESS Do the required action success.
637
638 **/
639 EFI_STATUS
640 HiiSetPassword(
641 OPAL_DISK *OpalDisk,
642 VOID *Password,
643 UINT32 PassLength
644 )
645 {
646 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
647 TCG_RESULT Ret;
648 BOOLEAN ExistingPassword;
649 OPAL_SESSION Session;
650
651 ExistingPassword = FALSE;
652
653 //
654 // PassLength = 0 means check whether exist old password.
655 //
656 if (PassLength == 0) {
657 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
658 gHiiOldPasswordLength = 0;
659
660 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_ENABLE_FEATURE) {
661 ExistingPassword = FALSE;
662 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_ADMIN_PWD) {
663 ExistingPassword = OpalUtilAdminPasswordExists(OpalDisk->Owner, &OpalDisk->LockingFeature);
664 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
665 //
666 // Set user Password option shall only be shown if an Admin Password exists
667 // so a Password is always required (Admin or Existing User Password)
668 //
669 ExistingPassword = TRUE;
670 }
671
672 //
673 // Return error if there is a previous Password
674 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
675 //
676 return ExistingPassword ? EFI_DEVICE_ERROR : EFI_SUCCESS;
677 }
678
679 ZeroMem(&Session, sizeof(Session));
680 Session.Sscp = OpalDisk->Sscp;
681 Session.MediaId = OpalDisk->MediaId;
682 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
683
684 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Failure");
685 //
686 // Password entered.
687 // No current Owner, so set new Password, must be admin Password
688 //
689 if (OpalDisk->Owner == OpalOwnershipNobody) {
690 Ret = OpalSupportEnableOpalFeature (&Session, OpalDisk->Msid, OpalDisk->MsidLength,Password, PassLength, OpalDisk->OpalDevicePath);
691 if (Ret == TcgResultSuccess) {
692 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Success");
693 }
694
695 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
696 return EFI_SUCCESS;
697 }
698
699 //
700 // 1st Password entered
701 //
702 if (OpalDisk->Owner == OpalOwnershipUnknown && gHiiOldPasswordLength == 0) {
703
704 //
705 // Unknown ownership - prompt for old Password, then new
706 // old Password is not set yet - first time through
707 // assume authority provided is admin1, overwritten if user1 authority works below
708 //
709 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
710 //
711 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
712 //
713 Ret = OpalUtilVerifyPassword (&Session, Password, PassLength, OPAL_LOCKING_SP_USER1_AUTHORITY);
714 if (Ret == TcgResultSuccess) {
715 //
716 // User1 worked so authority 1 means user 1
717 //
718 CopyMem(gHiiOldPassword, Password, PassLength);
719 gHiiOldPasswordLength = PassLength;
720
721 return EFI_SUCCESS;
722 }
723 }
724
725 //
726 // Else try admin1 below
727 //
728 Ret = OpalUtilVerifyPassword (&Session, Password, PassLength, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);
729 if (Ret == TcgResultSuccess) {
730 CopyMem(gHiiOldPassword, Password, PassLength);
731 gHiiOldPasswordLength = PassLength;
732
733 return EFI_SUCCESS;
734 } else {
735 DEBUG ((DEBUG_INFO, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
736 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), "Authentication Failure");
737
738 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
739 gHiiOldPasswordLength = 0;
740
741 return EFI_NOT_READY;
742 }
743 }
744
745 //
746 // New Password entered
747 //
748 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
749 Ret = OpalSupportSetPassword(
750 &Session,
751 gHiiOldPassword,
752 gHiiOldPasswordLength,
753 Password,
754 PassLength,
755 OpalDisk->OpalDevicePath,
756 FALSE
757 );
758 } else {
759 Ret = OpalSupportSetPassword(
760 &Session,
761 gHiiOldPassword,
762 gHiiOldPasswordLength,
763 Password,
764 PassLength,
765 OpalDisk->OpalDevicePath,
766 TRUE
767 );
768 }
769
770 if (Ret == TcgResultSuccess) {
771 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Success");
772 }
773
774 //
775 // Reset old Password storage
776 //
777 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
778 gHiiOldPasswordLength = 0;
779
780 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
781 return Ret == TcgResultSuccess ? EFI_SUCCESS : EFI_NOT_READY;
782 }
783
784 /**
785 Secure Erases Opal Disk.
786
787 @param OpalDisk The disk need to erase data.
788 @param Password The input password.
789 @param PassLength The input password length.
790
791 @retval EFI_SUCCESS Do the required action success.
792
793 **/
794 EFI_STATUS
795 HiiSecureErase(
796 OPAL_DISK *OpalDisk,
797 const VOID *Password,
798 UINT32 PassLength
799 )
800 {
801 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
802 BOOLEAN PasswordFailed;
803 TCG_RESULT Ret;
804 OPAL_SESSION AdminSpSession;
805
806 if (PassLength == 0) {
807 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
808 }
809
810 ZeroMem(&AdminSpSession, sizeof(AdminSpSession));
811 AdminSpSession.Sscp = OpalDisk->Sscp;
812 AdminSpSession.MediaId = OpalDisk->MediaId;
813 AdminSpSession.OpalBaseComId = OpalDisk->OpalBaseComId;
814
815 Ret = OpalUtilSecureErase(&AdminSpSession, Password, PassLength, &PasswordFailed);
816 if (Ret == TcgResultSuccess) {
817 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Secure Erase: Success" );
818 } else {
819 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Secure Erase: Failure" );
820 }
821 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
822
823 //
824 // If Password failed, return invalid passowrd
825 //
826 if (PasswordFailed) {
827 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
828 return EFI_NOT_READY;
829 }
830
831 //
832 // Indicates Password was valid and is not changing to UEFI
833 // Response string will indicate action error
834 //
835 return EFI_DEVICE_ERROR;
836 }
837
838
839 /**
840 Disables User for Opal Disk.
841
842 @param OpalDisk The disk need to the action.
843 @param Password The input password.
844 @param PassLength The input password length.
845
846 @retval EFI_SUCCESS Do the required action success.
847
848 **/
849 EFI_STATUS
850 HiiDisableUser(
851 OPAL_DISK *OpalDisk,
852 VOID *Password,
853 UINT32 PassLength
854 )
855 {
856 CHAR8 Response[ DEFAULT_RESPONSE_SIZE ];
857 BOOLEAN PasswordFailed;
858 TCG_RESULT Ret;
859 OPAL_SESSION Session;
860
861 if (PassLength == 0) {
862 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
863 }
864
865 ZeroMem(&Session, sizeof(Session));
866 Session.Sscp = OpalDisk->Sscp;
867 Session.MediaId = OpalDisk->MediaId;
868 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
869
870 Ret = OpalSupportDisableUser(&Session, Password, PassLength, &PasswordFailed, OpalDisk->OpalDevicePath);
871 if (Ret == TcgResultSuccess) {
872 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Disable User: Success" );
873 } else {
874 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Disable User: Failure" );
875 }
876 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS), Response);
877
878 //
879 // If Password failed, return invalid passowrd
880 //
881 if (PasswordFailed) {
882 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
883 return EFI_NOT_READY;
884 }
885
886 //
887 // Indicates Password was valid and is not changing to UEFI
888 // Response string will indicate action error
889 //
890 return EFI_DEVICE_ERROR;
891 }
892
893 /**
894 Revert Opal Disk as Admin1.
895
896 @param OpalDisk The disk need to the action.
897 @param Password The input password.
898 @param PassLength The input password length.
899 @param KeepUserData Whether need to keey user data.
900
901 @retval EFI_SUCCESS Do the required action success.
902
903 **/
904 EFI_STATUS
905 HiiRevert(
906 OPAL_DISK *OpalDisk,
907 VOID *Password,
908 UINT32 PassLength,
909 BOOLEAN KeepUserData
910 )
911 {
912 CHAR8 Response[ DEFAULT_RESPONSE_SIZE ];
913 BOOLEAN PasswordFailed;
914 TCG_RESULT Ret;
915 OPAL_SESSION Session;
916
917 if (PassLength == 0) {
918 DEBUG ((DEBUG_INFO, "Returning error to indicate there is an existing Password\n"));
919 // return error to indicate there is an existing Password
920 return EFI_DEVICE_ERROR;
921 }
922
923 ZeroMem(&Session, sizeof(Session));
924 Session.Sscp = OpalDisk->Sscp;
925 Session.MediaId = OpalDisk->MediaId;
926 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
927
928 Ret = OpalSupportRevert(
929 &Session,
930 KeepUserData,
931 Password,
932 PassLength,
933 OpalDisk->Msid,
934 OpalDisk->MsidLength,
935 &PasswordFailed,
936 OpalDisk->OpalDevicePath
937 );
938 if (Ret == TcgResultSuccess) {
939 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Revert: Success" );
940 } else {
941 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Revert: Failure" );
942 }
943 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
944
945 //
946 // If Password failed, return invalid passowrd
947 //
948 if (PasswordFailed) {
949 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
950 return EFI_NOT_READY;
951 }
952
953 //
954 // Indicates Password was valid and is not changing to UEFI
955 // Response string will indicate action error
956 //
957 return EFI_DEVICE_ERROR;
958 }
959
960 /**
961 Unlocks Opal Disk.
962
963 @param OpalDisk The disk need to the action.
964 @param Password The input password.
965 @param PassLength The input password length.
966
967 @retval EFI_SUCCESS Do the required action success.
968
969 **/
970 EFI_STATUS
971 HiiUnlock(
972 OPAL_DISK *OpalDisk,
973 VOID *Password,
974 UINT32 PassLength
975 )
976 {
977 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
978 TCG_RESULT Ret;
979 OPAL_SESSION Session;
980
981 if (PassLength == 0) {
982 DEBUG ((DEBUG_INFO, "Returning error to indicate there is an existing Password\n"));
983 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
984 }
985
986 ZeroMem(&Session, sizeof(Session));
987 Session.Sscp = OpalDisk->Sscp;
988 Session.MediaId = OpalDisk->MediaId;
989 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
990
991 Ret = OpalSupportUnlock(&Session, Password, PassLength, OpalDisk->OpalDevicePath);
992 if (Ret == TcgResultSuccess) {
993 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Unlock: Success" );
994 } else {
995 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Unlock: Failure" );
996 }
997
998 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
999
1000 if (Ret == TcgResultSuccess) {
1001 DEBUG ((DEBUG_INFO, "returning error to indicate Password was correct but is not changing\n"));
1002 return EFI_DEVICE_ERROR;
1003 } else {
1004 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1005 return EFI_NOT_READY;
1006 }
1007 }
1008
1009 /**
1010 Use the input password to do the specified action.
1011
1012 @param Str The input password saved in.
1013
1014 @retval EFI_SUCCESS Do the required action success.
1015 @retval Others Other error occur.
1016
1017 **/
1018 EFI_STATUS
1019 HiiPasswordEntered(
1020 EFI_STRING_ID Str
1021 )
1022 {
1023 OPAL_DISK* OpalDisk;
1024 CHAR8 Password[MAX_PASSWORD_CHARACTER_LENGTH + 1];
1025 CHAR16* UniStr;
1026 UINT32 PassLength;
1027 EFI_STATUS Status;
1028
1029 OpalHiiGetBrowserData();
1030
1031 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
1032 if (OpalDisk == NULL) {
1033 DEBUG ((DEBUG_INFO, "ERROR: disk %u not found\n", gHiiConfiguration.SelectedDiskIndex));
1034 return EFI_NOT_FOUND;
1035 }
1036
1037 if (Str == 0) {
1038 DEBUG ((DEBUG_INFO, "ERROR: str=NULL\n"));
1039 return EFI_INVALID_PARAMETER;
1040 }
1041
1042 ZeroMem(Password, sizeof(Password));
1043
1044 UniStr = HiiGetString(gHiiPackageListHandle, Str, NULL);
1045 if (UniStr == NULL) {
1046 return EFI_NOT_FOUND;
1047 }
1048 PassLength = (UINT32) StrLen (UniStr);
1049 if (PassLength >= sizeof(Password)) {
1050 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), "Password too long");
1051 gBS->FreePool(UniStr);
1052 return EFI_BUFFER_TOO_SMALL;
1053 }
1054
1055 UnicodeStrToAsciiStrS (UniStr, Password, sizeof (Password));
1056 gBS->FreePool(UniStr);
1057
1058 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_UNLOCK) {
1059 Status = HiiUnlock (OpalDisk, Password, PassLength);
1060 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SECURE_ERASE) {
1061 Status = HiiSecureErase (OpalDisk, Password, PassLength);
1062 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_DISABLE_USER) {
1063 Status = HiiDisableUser (OpalDisk, Password, PassLength);
1064 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_REVERT) {
1065 if (OpalDisk->SupportedAttributes.PyriteSsc == 1 && OpalDisk->LockingFeature.MediaEncryption == 0) {
1066 //
1067 // For pyrite type device which also not supports media encryption, it not accept "Keep User Data" parameter.
1068 // So here hardcode a FALSE for this case.
1069 //
1070 Status = HiiRevert(OpalDisk, Password, PassLength, FALSE);
1071 } else {
1072 Status = HiiRevert(OpalDisk, Password, PassLength, gHiiConfiguration.KeepUserData);
1073 }
1074 } else {
1075 Status = HiiSetPassword(OpalDisk, Password, PassLength);
1076 }
1077
1078 OpalHiiSetBrowserData ();
1079
1080 return Status;
1081 }
1082
1083 /**
1084 Update block sid info.
1085
1086 @param Enable Enable/disable BlockSid.
1087
1088 @retval EFI_SUCCESS Do the required action success.
1089 @retval Others Other error occur.
1090
1091 **/
1092 EFI_STATUS
1093 HiiSetBlockSid (
1094 BOOLEAN Enable
1095 )
1096 {
1097 EFI_STATUS Status;
1098 OPAL_EXTRA_INFO_VAR OpalExtraInfo;
1099 UINTN DataSize;
1100
1101 Status = EFI_SUCCESS;
1102
1103 OpalExtraInfo.EnableBlockSid = Enable;
1104 DataSize = sizeof (OPAL_EXTRA_INFO_VAR);
1105 Status = gRT->SetVariable (
1106 OPAL_EXTRA_INFO_VAR_NAME,
1107 &gOpalExtraInfoVariableGuid,
1108 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1109 DataSize,
1110 &OpalExtraInfo
1111 );
1112
1113 return Status;
1114 }
1115
1116 /**
1117 This function processes the results of changes in configuration.
1118
1119 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1120 @param Configuration A null-terminated Unicode string in <ConfigResp>
1121 format.
1122 @param Progress A pointer to a string filled in with the offset of
1123 the most recent '&' before the first failing
1124 name/value pair (or the beginning of the string if
1125 the failure is in the first name/value pair) or
1126 the terminating NULL if all was successful.
1127
1128 @retval EFI_SUCCESS The Results is processed successfully.
1129 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1130 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1131 driver.
1132
1133 **/
1134 EFI_STATUS
1135 EFIAPI
1136 RouteConfig(
1137 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1138 CONST EFI_STRING Configuration,
1139 EFI_STRING *Progress
1140 )
1141 {
1142 if (Configuration == NULL || Progress == NULL) {
1143 return (EFI_INVALID_PARAMETER);
1144 }
1145
1146 *Progress = Configuration;
1147 if (!HiiIsConfigHdrMatch (Configuration, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
1148 return EFI_NOT_FOUND;
1149 }
1150
1151 *Progress = Configuration + StrLen (Configuration);
1152
1153 return EFI_SUCCESS;
1154 }
1155
1156 /**
1157 This function allows a caller to extract the current configuration for one
1158 or more named elements from the target driver.
1159
1160 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1161 @param Request A null-terminated Unicode string in
1162 <ConfigRequest> format.
1163 @param Progress On return, points to a character in the Request
1164 string. Points to the string's null terminator if
1165 request was successful. Points to the most recent
1166 '&' before the first failing name/value pair (or
1167 the beginning of the string if the failure is in
1168 the first name/value pair) if the request was not
1169 successful.
1170 @param Results A null-terminated Unicode string in
1171 <ConfigAltResp> format which has all values filled
1172 in for the names in the Request string. String to
1173 be allocated by the called function.
1174
1175 @retval EFI_SUCCESS The Results is filled with the requested values.
1176 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1177 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1178 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1179 driver.
1180
1181 **/
1182 EFI_STATUS
1183 EFIAPI
1184 ExtractConfig(
1185 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1186 CONST EFI_STRING Request,
1187 EFI_STRING *Progress,
1188 EFI_STRING *Results
1189 )
1190 {
1191 EFI_STATUS Status;
1192
1193 //
1194 // Check for valid parameters
1195 //
1196 if (Progress == NULL || Results == NULL) {
1197 return (EFI_INVALID_PARAMETER);
1198 }
1199
1200 *Progress = Request;
1201 if ((Request != NULL) &&
1202 !HiiIsConfigHdrMatch (Request, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
1203 return EFI_NOT_FOUND;
1204 }
1205
1206 //
1207 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1208 //
1209 Status = gHiiConfigRouting->BlockToConfig(
1210 gHiiConfigRouting,
1211 Request,
1212 (UINT8*)&gHiiConfiguration,
1213 sizeof(OPAL_HII_CONFIGURATION),
1214 Results,
1215 Progress
1216 );
1217
1218 return (Status);
1219 }
1220
1221
1222 /**
1223
1224 Pass the current system state to the bios via the hii_G_Configuration.
1225
1226 **/
1227 VOID
1228 OpalHiiSetBrowserData (
1229 VOID
1230 )
1231 {
1232 HiiSetBrowserData(
1233 &gHiiSetupVariableGuid,
1234 (CHAR16*)L"OpalHiiConfig",
1235 sizeof(gHiiConfiguration),
1236 (UINT8*)&gHiiConfiguration,
1237 NULL
1238 );
1239 }
1240
1241
1242 /**
1243
1244 Populate the hii_g_Configuraton with the browser Data.
1245
1246 **/
1247 VOID
1248 OpalHiiGetBrowserData (
1249 VOID
1250 )
1251 {
1252 HiiGetBrowserData(
1253 &gHiiSetupVariableGuid,
1254 (CHAR16*)L"OpalHiiConfig",
1255 sizeof(gHiiConfiguration),
1256 (UINT8*)&gHiiConfiguration
1257 );
1258 }
1259
1260 /**
1261 Set a string Value in a form.
1262
1263 @param DestStringId The stringid which need to update.
1264 @param SrcAsciiStr The string nned to update.
1265
1266 @retval EFI_SUCCESS Do the required action success.
1267 @retval Others Other error occur.
1268
1269 **/
1270 EFI_STATUS
1271 HiiSetFormString(
1272 EFI_STRING_ID DestStringId,
1273 CHAR8 *SrcAsciiStr
1274 )
1275 {
1276 UINT32 Len;
1277 UINT32 UniSize;
1278 CHAR16* UniStr;
1279
1280 //
1281 // Determine the Length of the sting
1282 //
1283 Len = ( UINT32 )AsciiStrLen( SrcAsciiStr );
1284
1285 //
1286 // Allocate space for the unicode string, including terminator
1287 //
1288 UniSize = (Len + 1) * sizeof(CHAR16);
1289 UniStr = (CHAR16*)AllocateZeroPool(UniSize);
1290
1291 //
1292 // Copy into unicode string, then copy into string id
1293 //
1294 AsciiStrToUnicodeStrS ( SrcAsciiStr, UniStr, Len + 1);
1295
1296 //
1297 // Update the string in the form
1298 //
1299 if (HiiSetString(gHiiPackageListHandle, DestStringId, UniStr, NULL) == 0) {
1300 DEBUG ((DEBUG_INFO, "HiiSetFormString( ) failed\n"));
1301 FreePool(UniStr);
1302 return (EFI_OUT_OF_RESOURCES);
1303 }
1304
1305 //
1306 // Free the memory
1307 //
1308 FreePool(UniStr);
1309
1310 return (EFI_SUCCESS);
1311 }
1312
1313 /**
1314 Initialize the Opal disk base on the hardware info get from device.
1315
1316 @param Dev The Opal device.
1317
1318 @retval EFI_SUCESS Initialize the device success.
1319 @retval EFI_DEVICE_ERROR Get info from device failed.
1320
1321 **/
1322 EFI_STATUS
1323 OpalDiskInitialize (
1324 IN OPAL_DRIVER_DEVICE *Dev
1325 )
1326 {
1327 TCG_RESULT TcgResult;
1328 OPAL_SESSION Session;
1329
1330 ZeroMem(&Dev->OpalDisk, sizeof(OPAL_DISK));
1331 Dev->OpalDisk.Sscp = Dev->Sscp;
1332 Dev->OpalDisk.MediaId = Dev->MediaId;
1333 Dev->OpalDisk.OpalDevicePath = Dev->OpalDevicePath;
1334
1335 ZeroMem(&Session, sizeof(Session));
1336 Session.Sscp = Dev->Sscp;
1337 Session.MediaId = Dev->MediaId;
1338
1339 TcgResult = OpalGetSupportedAttributesInfo (&Session, &Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.OpalBaseComId);
1340 if (TcgResult != TcgResultSuccess) {
1341 return EFI_DEVICE_ERROR;
1342 }
1343 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1344
1345 TcgResult = OpalUtilGetMsid (&Session, Dev->OpalDisk.Msid, OPAL_MSID_LENGHT, &Dev->OpalDisk.MsidLength);
1346 if (TcgResult != TcgResultSuccess) {
1347 return EFI_DEVICE_ERROR;
1348 }
1349
1350 return OpalDiskUpdateStatus (&Dev->OpalDisk);
1351 }
1352
1353 /**
1354 Update the device info.
1355
1356 @param OpalDisk The Opal device.
1357
1358 @retval EFI_SUCESS Initialize the device success.
1359 @retval EFI_DEVICE_ERROR Get info from device failed.
1360 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1361
1362 **/
1363 EFI_STATUS
1364 OpalDiskUpdateStatus (
1365 OPAL_DISK *OpalDisk
1366 )
1367 {
1368 TCG_RESULT TcgResult;
1369 OPAL_SESSION Session;
1370
1371 ZeroMem(&Session, sizeof(Session));
1372 Session.Sscp = OpalDisk->Sscp;
1373 Session.MediaId = OpalDisk->MediaId;
1374 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1375
1376 TcgResult = OpalGetLockingInfo(&Session, &OpalDisk->LockingFeature);
1377 if (TcgResult != TcgResultSuccess) {
1378 return EFI_DEVICE_ERROR;
1379 }
1380
1381 if (OpalDisk->MsidLength == 0) {
1382 return EFI_INVALID_PARAMETER;
1383 } else {
1384 //
1385 // Base on the Msid info to get the ownership, so Msid info must get first.
1386 //
1387 OpalDisk->Owner = OpalUtilDetermineOwnership(&Session, OpalDisk->Msid, OpalDisk->MsidLength);
1388 }
1389
1390 return EFI_SUCCESS;
1391 }
1392