]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
SecurityPkg: Fix spelling errors
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPassword / OpalHii.c
1 /** @file
2 Implementation of the HII for the Opal UEFI Driver.
3
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "OpalHii.h"
10 //
11 // Character definitions
12 //
13 #define UPPER_LOWER_CASE_OFFSET 0x20
14
15 //
16 // This is the generated IFR binary Data for each formset defined in VFR.
17 // This Data array is ready to be used as input of HiiAddPackages() to
18 // create a packagelist (which contains Form packages, String packages, etc).
19 //
20 extern UINT8 OpalPasswordFormBin[];
21
22 //
23 // This is the generated String package Data for all .UNI files.
24 // This Data array is ready to be used as input of HiiAddPackages() to
25 // create a packagelist (which contains Form packages, String packages, etc).
26 //
27 extern UINT8 OpalPasswordDxeStrings[];
28
29 CHAR16 OpalPasswordStorageName[] = L"OpalHiiConfig";
30
31 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol;
32
33 //
34 // Handle to the list of HII packages (forms and strings) for this driver
35 //
36 EFI_HII_HANDLE gHiiPackageListHandle = NULL;
37
38 //
39 // Package List GUID containing all form and string packages
40 //
41 const EFI_GUID gHiiPackageListGuid = PACKAGE_LIST_GUID;
42 const EFI_GUID gHiiSetupVariableGuid = SETUP_VARIABLE_GUID;
43
44 //
45 // Structure that contains state of the HII
46 // This structure is updated by Hii.cpp and its contents
47 // is rendered in the HII.
48 //
49 OPAL_HII_CONFIGURATION gHiiConfiguration;
50
51 //
52 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
53 //
54 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath = {
55 {
56 {
57 HARDWARE_DEVICE_PATH,
58 HW_VENDOR_DP,
59 {
60 (UINT8)(sizeof(VENDOR_DEVICE_PATH)),
61 (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8)
62 }
63 },
64 OPAL_PASSWORD_CONFIG_GUID
65 },
66 {
67 END_DEVICE_PATH_TYPE,
68 END_ENTIRE_DEVICE_PATH_SUBTYPE,
69 {
70 (UINT8)(END_DEVICE_PATH_LENGTH),
71 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
72 }
73 }
74 };
75
76 /**
77 Get saved OPAL request.
78
79 @param[in] OpalDisk The disk needs to get the saved OPAL request.
80 @param[out] OpalRequest OPAL request got.
81
82 **/
83 VOID
84 GetSavedOpalRequest (
85 IN OPAL_DISK *OpalDisk,
86 OUT OPAL_REQUEST *OpalRequest
87 )
88 {
89 EFI_STATUS Status;
90 OPAL_REQUEST_VARIABLE *TempVariable;
91 OPAL_REQUEST_VARIABLE *Variable;
92 UINTN VariableSize;
93 EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;
94 UINTN DevicePathSizeInVariable;
95 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
96 UINTN DevicePathSize;
97
98 DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));
99
100 Variable = NULL;
101 VariableSize = 0;
102
103 Status = GetVariable2 (
104 OPAL_REQUEST_VARIABLE_NAME,
105 &gHiiSetupVariableGuid,
106 (VOID **) &Variable,
107 &VariableSize
108 );
109 if (EFI_ERROR (Status) || (Variable == NULL)) {
110 return;
111 }
112
113 TempVariable = Variable;
114 while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
115 (VariableSize >= TempVariable->Length) &&
116 (TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE))) {
117 DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
118 DevicePathSizeInVariable = GetDevicePathSize (DevicePathInVariable);
119 DevicePath = OpalDisk->OpalDevicePath;
120 DevicePathSize = GetDevicePathSize (DevicePath);
121 if ((DevicePathSize == DevicePathSizeInVariable) &&
122 (CompareMem (DevicePath, DevicePathInVariable, DevicePathSize) == 0)) {
123 //
124 // Found the node for the OPAL device.
125 // Get the OPAL request.
126 //
127 CopyMem (OpalRequest, &TempVariable->OpalRequest, sizeof (OPAL_REQUEST));
128 DEBUG ((
129 DEBUG_INFO,
130 "OpalRequest got: 0x%x\n",
131 *OpalRequest
132 ));
133 break;
134 }
135 VariableSize -= TempVariable->Length;
136 TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);
137 }
138
139 FreePool (Variable);
140
141 DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));
142 }
143
144 /**
145 Save OPAL request.
146
147 @param[in] OpalDisk The disk has OPAL request to save.
148 @param[in] OpalRequest OPAL request to save.
149
150 **/
151 VOID
152 SaveOpalRequest (
153 IN OPAL_DISK *OpalDisk,
154 IN OPAL_REQUEST OpalRequest
155 )
156 {
157 EFI_STATUS Status;
158 OPAL_REQUEST_VARIABLE *TempVariable;
159 UINTN TempVariableSize;
160 OPAL_REQUEST_VARIABLE *Variable;
161 UINTN VariableSize;
162 OPAL_REQUEST_VARIABLE *NewVariable;
163 UINTN NewVariableSize;
164 EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;
165 UINTN DevicePathSizeInVariable;
166 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
167 UINTN DevicePathSize;
168
169 DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));
170
171 DEBUG ((
172 DEBUG_INFO,
173 "OpalRequest to save: 0x%x\n",
174 OpalRequest
175 ));
176
177 Variable = NULL;
178 VariableSize = 0;
179 NewVariable = NULL;
180 NewVariableSize = 0;
181
182 Status = GetVariable2 (
183 OPAL_REQUEST_VARIABLE_NAME,
184 &gHiiSetupVariableGuid,
185 (VOID **) &Variable,
186 &VariableSize
187 );
188 if (!EFI_ERROR (Status) && (Variable != NULL)) {
189 TempVariable = Variable;
190 TempVariableSize = VariableSize;
191 while ((TempVariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
192 (TempVariableSize >= TempVariable->Length) &&
193 (TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE))) {
194 DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
195 DevicePathSizeInVariable = GetDevicePathSize (DevicePathInVariable);
196 DevicePath = OpalDisk->OpalDevicePath;
197 DevicePathSize = GetDevicePathSize (DevicePath);
198 if ((DevicePathSize == DevicePathSizeInVariable) &&
199 (CompareMem (DevicePath, DevicePathInVariable, DevicePathSize) == 0)) {
200 //
201 // Found the node for the OPAL device.
202 // Update the OPAL request.
203 //
204 CopyMem (&TempVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
205 NewVariable = Variable;
206 NewVariableSize = VariableSize;
207 break;
208 }
209 TempVariableSize -= TempVariable->Length;
210 TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);
211 }
212 if (NewVariable == NULL) {
213 //
214 // The node for the OPAL device is not found.
215 // Create node for the OPAL device.
216 //
217 DevicePath = OpalDisk->OpalDevicePath;
218 DevicePathSize = GetDevicePathSize (DevicePath);
219 NewVariableSize = VariableSize + sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
220 NewVariable = AllocatePool (NewVariableSize);
221 ASSERT (NewVariable != NULL);
222 CopyMem (NewVariable, Variable, VariableSize);
223 TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) NewVariable + VariableSize);
224 TempVariable->Length = (UINT32) (sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
225 CopyMem (&TempVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
226 DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
227 CopyMem (DevicePathInVariable, DevicePath, DevicePathSize);
228 }
229 } else {
230 DevicePath = OpalDisk->OpalDevicePath;
231 DevicePathSize = GetDevicePathSize (DevicePath);
232 NewVariableSize = sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
233 NewVariable = AllocatePool (NewVariableSize);
234 ASSERT (NewVariable != NULL);
235 NewVariable->Length = (UINT32) (sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
236 CopyMem (&NewVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
237 DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) NewVariable + sizeof (OPAL_REQUEST_VARIABLE));
238 CopyMem (DevicePathInVariable, DevicePath, DevicePathSize);
239 }
240 Status = gRT->SetVariable (
241 OPAL_REQUEST_VARIABLE_NAME,
242 (EFI_GUID *) &gHiiSetupVariableGuid,
243 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
244 NewVariableSize,
245 NewVariable
246 );
247 if (EFI_ERROR (Status)) {
248 DEBUG ((DEBUG_INFO, "OpalRequest variable set failed (%r)\n", Status));
249 }
250 if (NewVariable != Variable) {
251 FreePool (NewVariable);
252 }
253 if (Variable != NULL) {
254 FreePool (Variable);
255 }
256
257 DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));
258 }
259
260 /**
261 Sets the current system state of global config variables.
262
263 **/
264 VOID
265 HiiSetCurrentConfiguration(
266 VOID
267 )
268 {
269 UINT32 PpStorageFlag;
270 EFI_STRING NewString;
271
272 gHiiConfiguration.NumDisks = GetDeviceCount();
273
274 //
275 // Update the BlockSID status string.
276 //
277 PpStorageFlag = Tcg2PhysicalPresenceLibGetManagementFlags ();
278
279 if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID) != 0) {
280 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_ENABLED), NULL);
281 if (NewString == NULL) {
282 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
283 return;
284 }
285 } else {
286 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISABLED), NULL);
287 if (NewString == NULL) {
288 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
289 return;
290 }
291 }
292 HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS1), NewString, NULL);
293 FreePool (NewString);
294
295 if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) != 0) {
296 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_TRUE), NULL);
297 if (NewString == NULL) {
298 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
299 return;
300 }
301 } else {
302 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_FALSE), NULL);
303 if (NewString == NULL) {
304 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
305 return;
306 }
307 }
308 HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS2), NewString, NULL);
309 FreePool (NewString);
310
311 if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) != 0) {
312 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_TRUE), NULL);
313 if (NewString == NULL) {
314 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
315 return;
316 }
317 } else {
318 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_FALSE), NULL);
319 if (NewString == NULL) {
320 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
321 return;
322 }
323 }
324 HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS3), NewString, NULL);
325 FreePool (NewString);
326 }
327
328 /**
329 Install the HII related resources.
330
331 @retval EFI_SUCCESS Install all the resources success.
332 @retval other Error occur when install the resources.
333 **/
334 EFI_STATUS
335 HiiInstall(
336 VOID
337 )
338 {
339 EFI_STATUS Status;
340 EFI_HANDLE DriverHandle;
341
342 //
343 // Clear the global configuration.
344 //
345 ZeroMem(&gHiiConfiguration, sizeof(gHiiConfiguration));
346
347 //
348 // Obtain the driver handle that the BIOS assigned us
349 //
350 DriverHandle = HiiGetDriverImageHandleCB();
351
352 //
353 // Populate the config access protocol with the three functions we are publishing
354 //
355 gHiiConfigAccessProtocol.ExtractConfig = ExtractConfig;
356 gHiiConfigAccessProtocol.RouteConfig = RouteConfig;
357 gHiiConfigAccessProtocol.Callback = DriverCallback;
358
359 //
360 // Associate the required protocols with our driver handle
361 //
362 Status = gBS->InstallMultipleProtocolInterfaces(
363 &DriverHandle,
364 &gEfiHiiConfigAccessProtocolGuid,
365 &gHiiConfigAccessProtocol, // HII callback
366 &gEfiDevicePathProtocolGuid,
367 &gHiiVendorDevicePath, // required for HII callback allow all disks to be shown in same hii
368 NULL
369 );
370
371 if (EFI_ERROR(Status)) {
372 return Status;
373 }
374
375 return OpalHiiAddPackages();
376 }
377
378 /**
379 Install the HII form and string packages.
380
381 @retval EFI_SUCCESS Install all the resources success.
382 @retval EFI_OUT_OF_RESOURCES Out of resource error.
383 **/
384 EFI_STATUS
385 OpalHiiAddPackages(
386 VOID
387 )
388 {
389 EFI_HANDLE DriverHandle;
390
391 DriverHandle = HiiGetDriverImageHandleCB();
392
393 //
394 // Publish the HII form and HII string packages
395 //
396 gHiiPackageListHandle = HiiAddPackages(
397 &gHiiPackageListGuid,
398 DriverHandle,
399 OpalPasswordDxeStrings,
400 OpalPasswordFormBin,
401 (VOID*)NULL
402 );
403
404 //
405 // Make sure the packages installed successfully
406 //
407 if (gHiiPackageListHandle == NULL) {
408 DEBUG ((DEBUG_INFO, "OpalHiiAddPackages failed\n"));
409 return EFI_OUT_OF_RESOURCES;
410 }
411
412 return EFI_SUCCESS;
413 }
414
415 /**
416 Uninstall the HII capability.
417
418 @retval EFI_SUCCESS Uninstall all the resources success.
419 @retval others Other errors occur when unistall the hii resource.
420 **/
421 EFI_STATUS
422 HiiUninstall(
423 VOID
424 )
425 {
426 EFI_STATUS Status;
427
428 //
429 // Remove the packages we've provided to the BIOS
430 //
431 HiiRemovePackages(gHiiPackageListHandle);
432
433 //
434 // Remove the protocols from our driver handle
435 //
436 Status = gBS->UninstallMultipleProtocolInterfaces(
437 HiiGetDriverImageHandleCB(),
438 &gEfiHiiConfigAccessProtocolGuid,
439 &gHiiConfigAccessProtocol, // HII callback
440 &gEfiDevicePathProtocolGuid,
441 &gHiiVendorDevicePath, // required for HII callback
442 NULL
443 );
444 if (EFI_ERROR(Status)) {
445 DEBUG ((DEBUG_INFO, "Cannot uninstall Hii Protocols: %r\n", Status));
446 }
447
448 return Status;
449 }
450
451 /**
452 Updates the main menu form.
453
454 @retval EFI_SUCCESS update the main form success.
455 **/
456 EFI_STATUS
457 HiiPopulateMainMenuForm (
458 VOID
459 )
460 {
461 UINT8 Index;
462 CHAR8 *DiskName;
463 EFI_STRING_ID DiskNameId;
464 OPAL_DISK *OpalDisk;
465
466 HiiSetCurrentConfiguration();
467
468 gHiiConfiguration.SupportedDisks = 0;
469
470 for (Index = 0; Index < gHiiConfiguration.NumDisks; Index++) {
471 OpalDisk = HiiGetOpalDiskCB (Index);
472 if ((OpalDisk != NULL) && OpalFeatureSupported (&OpalDisk->SupportedAttributes)) {
473 gHiiConfiguration.SupportedDisks |= (1 << Index);
474 DiskNameId = GetDiskNameStringId (Index);
475 DiskName = HiiDiskGetNameCB (Index);
476 if ((DiskName == NULL) || (DiskNameId == 0)) {
477 return EFI_UNSUPPORTED;
478 }
479 HiiSetFormString(DiskNameId, DiskName);
480 }
481 }
482
483 OpalHiiSetBrowserData ();
484 return EFI_SUCCESS;
485 }
486
487 /**
488 Get disk name string id.
489
490 @param DiskIndex The input disk index info.
491
492 @retval The disk name string id.
493
494 **/
495 EFI_STRING_ID
496 GetDiskNameStringId(
497 UINT8 DiskIndex
498 )
499 {
500 switch (DiskIndex) {
501 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0);
502 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1);
503 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2);
504 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3);
505 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4);
506 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5);
507 }
508 return 0;
509 }
510
511 /**
512 Confirm whether user truly want to do the revert action.
513
514 @param OpalDisk The device which need to perform data removal action.
515 @param ActionString Specifies the action name shown on pop up menu.
516
517 @retval EFI_SUCCESS Confirmed user want to do the revert action.
518 **/
519 EFI_STATUS
520 HiiConfirmDataRemovalAction (
521 IN OPAL_DISK *OpalDisk,
522 IN CHAR16 *ActionString
523
524 )
525 {
526 CHAR16 Unicode[512];
527 EFI_INPUT_KEY Key;
528 CHAR16 ApproveResponse;
529 CHAR16 RejectResponse;
530
531 //
532 // When the estimate cost time bigger than MAX_ACCEPTABLE_REVERTING_TIME, pop up dialog to let user confirm
533 // the revert action.
534 //
535 if (OpalDisk->EstimateTimeCost < MAX_ACCEPTABLE_REVERTING_TIME) {
536 return EFI_SUCCESS;
537 }
538
539 ApproveResponse = L'Y';
540 RejectResponse = L'N';
541
542 UnicodeSPrint(Unicode, StrSize(L"WARNING: ############# action needs about ####### seconds"), L"WARNING: %s action needs about %d seconds", ActionString, OpalDisk->EstimateTimeCost);
543
544 do {
545 CreatePopUp(
546 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
547 &Key,
548 Unicode,
549 L" System should not be powered off until action completion ",
550 L" ",
551 L" Press 'Y/y' to continue, press 'N/n' to cancal ",
552 NULL
553 );
554 } while (
555 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (ApproveResponse | UPPER_LOWER_CASE_OFFSET)) &&
556 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (RejectResponse | UPPER_LOWER_CASE_OFFSET))
557 );
558
559 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (RejectResponse | UPPER_LOWER_CASE_OFFSET)) {
560 return EFI_ABORTED;
561 }
562
563 return EFI_SUCCESS;
564 }
565
566 /**
567 This function processes the results of changes in configuration.
568
569 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
570 @param Action Specifies the type of action taken by the browser.
571 @param QuestionId A unique value which is sent to the original
572 exporting driver so that it can identify the type
573 of data to expect.
574 @param Type The type of value for the question.
575 @param Value A pointer to the data being sent to the original
576 exporting driver.
577 @param ActionRequest On return, points to the action requested by the
578 callback function.
579
580 @retval EFI_SUCCESS The callback successfully handled the action.
581 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
582 variable and its data.
583 @retval EFI_DEVICE_ERROR The variable could not be saved.
584 @retval EFI_UNSUPPORTED The specified Action is not supported by the
585 callback.
586
587 **/
588 EFI_STATUS
589 EFIAPI
590 DriverCallback(
591 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
592 EFI_BROWSER_ACTION Action,
593 EFI_QUESTION_ID QuestionId,
594 UINT8 Type,
595 EFI_IFR_TYPE_VALUE *Value,
596 EFI_BROWSER_ACTION_REQUEST *ActionRequest
597 )
598 {
599 HII_KEY HiiKey;
600 UINT8 HiiKeyId;
601 UINT32 PpRequest;
602 OPAL_DISK *OpalDisk;
603
604 if (ActionRequest != NULL) {
605 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
606 } else {
607 return EFI_INVALID_PARAMETER;
608 }
609
610 //
611 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
612 //
613 if ((QuestionId & HII_KEY_FLAG) == 0) {
614 return EFI_SUCCESS;
615 }
616
617 HiiKey.Raw = QuestionId;
618 HiiKeyId = (UINT8) HiiKey.KeyBits.Id;
619
620 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
621 switch (HiiKeyId) {
622 case HII_KEY_ID_VAR_SUPPORTED_DISKS:
623 DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
624 return HiiPopulateMainMenuForm ();
625
626 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS:
627 DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS\n"));
628 return HiiPopulateDiskInfoForm();
629 }
630 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {
631 switch (HiiKeyId) {
632 case HII_KEY_ID_GOTO_DISK_INFO:
633 return HiiSelectDisk((UINT8)HiiKey.KeyBits.Index);
634
635 case HII_KEY_ID_REVERT:
636 case HII_KEY_ID_PSID_REVERT:
637 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
638 if (OpalDisk != NULL) {
639 return HiiConfirmDataRemovalAction (OpalDisk, L"Revert");
640 } else {
641 ASSERT (FALSE);
642 return EFI_SUCCESS;
643 }
644
645 case HII_KEY_ID_SECURE_ERASE:
646 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
647 if (OpalDisk != NULL) {
648 return HiiConfirmDataRemovalAction (OpalDisk, L"Secure erase");
649 } else {
650 ASSERT (FALSE);
651 return EFI_SUCCESS;
652 }
653
654 }
655 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
656 switch (HiiKeyId) {
657 case HII_KEY_ID_BLOCKSID:
658 switch (Value->u8) {
659 case 0:
660 PpRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
661 break;
662
663 case 1:
664 PpRequest = TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID;
665 break;
666
667 case 2:
668 PpRequest = TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID;
669 break;
670
671 case 3:
672 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE;
673 break;
674
675 case 4:
676 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE;
677 break;
678
679 case 5:
680 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE;
681 break;
682
683 case 6:
684 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE;
685 break;
686
687 default:
688 PpRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
689 DEBUG ((DEBUG_ERROR, "Invalid value input!\n"));
690 break;
691 }
692 HiiSetBlockSidAction(PpRequest);
693
694 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
695 return EFI_SUCCESS;
696
697 case HII_KEY_ID_SET_ADMIN_PWD:
698 DEBUG ((DEBUG_INFO, "HII_KEY_ID_SET_ADMIN_PWD\n"));
699 gHiiConfiguration.OpalRequest.SetAdminPwd = Value->b;
700 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
701 if (OpalDisk != NULL) {
702 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
703 }
704 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
705 return EFI_SUCCESS;
706
707 case HII_KEY_ID_SET_USER_PWD:
708 DEBUG ((DEBUG_INFO, "HII_KEY_ID_SET_USER_PWD\n"));
709 gHiiConfiguration.OpalRequest.SetUserPwd = Value->b;
710 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
711 if (OpalDisk != NULL) {
712 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
713 }
714 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
715 return EFI_SUCCESS;
716
717 case HII_KEY_ID_SECURE_ERASE:
718 DEBUG ((DEBUG_INFO, "HII_KEY_ID_SECURE_ERASE\n"));
719 gHiiConfiguration.OpalRequest.SecureErase = Value->b;
720 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
721 if (OpalDisk != NULL) {
722 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
723 }
724 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
725 return EFI_SUCCESS;
726
727 case HII_KEY_ID_REVERT:
728 DEBUG ((DEBUG_INFO, "HII_KEY_ID_REVERT\n"));
729 gHiiConfiguration.OpalRequest.Revert = Value->b;
730 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
731 if (OpalDisk != NULL) {
732 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
733 }
734 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
735 return EFI_SUCCESS;
736 case HII_KEY_ID_KEEP_USER_DATA:
737 DEBUG ((DEBUG_INFO, "HII_KEY_ID_KEEP_USER_DATA\n"));
738 gHiiConfiguration.OpalRequest.KeepUserData = Value->b;
739 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
740 if (OpalDisk != NULL) {
741 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
742 }
743 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
744 return EFI_SUCCESS;
745
746 case HII_KEY_ID_PSID_REVERT:
747 DEBUG ((DEBUG_INFO, "HII_KEY_ID_PSID_REVERT\n"));
748 gHiiConfiguration.OpalRequest.PsidRevert = Value->b;
749 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
750 if (OpalDisk != NULL) {
751 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
752 }
753 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
754 return EFI_SUCCESS;
755
756 case HII_KEY_ID_DISABLE_USER:
757 DEBUG ((DEBUG_INFO, "HII_KEY_ID_DISABLE_USER\n"));
758 gHiiConfiguration.OpalRequest.DisableUser = Value->b;
759 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
760 if (OpalDisk != NULL) {
761 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
762 }
763 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
764 return EFI_SUCCESS;
765
766 case HII_KEY_ID_ENABLE_FEATURE:
767 DEBUG ((DEBUG_INFO, "HII_KEY_ID_ENABLE_FEATURE\n"));
768 gHiiConfiguration.OpalRequest.EnableFeature = Value->b;
769 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
770 if (OpalDisk != NULL) {
771 SaveOpalRequest (OpalDisk, gHiiConfiguration.OpalRequest);
772 }
773 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
774 return EFI_SUCCESS;
775
776 default:
777 break;
778 }
779 }
780
781 return EFI_UNSUPPORTED;
782 }
783
784 /**
785 Update the global Disk index info.
786
787 @param Index The input disk index info.
788
789 @retval EFI_SUCCESS Update the disk index info success.
790
791 **/
792 EFI_STATUS
793 HiiSelectDisk(
794 UINT8 Index
795 )
796 {
797 OpalHiiGetBrowserData();
798 gHiiConfiguration.SelectedDiskIndex = Index;
799 OpalHiiSetBrowserData ();
800
801 return EFI_SUCCESS;
802 }
803
804 /**
805 Draws the disk info form.
806
807 @retval EFI_SUCCESS Draw the disk info success.
808
809 **/
810 EFI_STATUS
811 HiiPopulateDiskInfoForm(
812 VOID
813 )
814 {
815 OPAL_DISK* OpalDisk;
816 OPAL_DISK_ACTIONS AvailActions;
817 TCG_RESULT Ret;
818 CHAR8 *DiskName;
819
820 OpalHiiGetBrowserData();
821
822 DiskName = HiiDiskGetNameCB (gHiiConfiguration.SelectedDiskIndex);
823 if (DiskName == NULL) {
824 return EFI_UNSUPPORTED;
825 }
826 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME), DiskName);
827
828 gHiiConfiguration.SelectedDiskAvailableActions = HII_ACTION_NONE;
829 ZeroMem (&gHiiConfiguration.OpalRequest, sizeof (OPAL_REQUEST));
830 gHiiConfiguration.KeepUserDataForced = FALSE;
831
832 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
833
834 if (OpalDisk != NULL) {
835 OpalDiskUpdateStatus (OpalDisk);
836 Ret = OpalSupportGetAvailableActions(&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature, OpalDisk->Owner, &AvailActions);
837 if (Ret == TcgResultSuccess) {
838 //
839 // Update actions, always allow PSID Revert
840 //
841 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.PsidRevert == 1) ? HII_ACTION_PSID_REVERT : HII_ACTION_NONE;
842
843 //
844 // Always allow unlock to handle device migration
845 //
846 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Unlock == 1) ? HII_ACTION_UNLOCK : HII_ACTION_NONE;
847
848 if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {
849 if (OpalDisk->Owner == OpalOwnershipNobody) {
850 gHiiConfiguration.SelectedDiskAvailableActions |= HII_ACTION_ENABLE_FEATURE;
851
852 //
853 // Update strings
854 //
855 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default");
856 } else {
857 DEBUG ((DEBUG_INFO, "Feature disabled but ownership != nobody\n"));
858 }
859 } else {
860 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Revert == 1) ? HII_ACTION_REVERT : HII_ACTION_NONE;
861 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.AdminPass == 1) ? HII_ACTION_SET_ADMIN_PWD : HII_ACTION_NONE;
862 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.UserPass == 1) ? HII_ACTION_SET_USER_PWD : HII_ACTION_NONE;
863 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.SecureErase == 1) ? HII_ACTION_SECURE_ERASE : HII_ACTION_NONE;
864 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.DisableUser == 1) ? HII_ACTION_DISABLE_USER : HII_ACTION_NONE;
865
866 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default and Disable");
867
868 //
869 // Determine revert options for disk
870 // Default initialize keep user Data to be true
871 //
872 gHiiConfiguration.OpalRequest.KeepUserData = 1;
873 if (AvailActions.RevertKeepDataForced) {
874 gHiiConfiguration.KeepUserDataForced = TRUE;
875 }
876 }
877 }
878
879 GetSavedOpalRequest (OpalDisk, &gHiiConfiguration.OpalRequest);
880 }
881
882 //
883 // Pass the current configuration to the BIOS
884 //
885 OpalHiiSetBrowserData ();
886
887 return EFI_SUCCESS;
888 }
889
890 /**
891 Send BlockSid request through TPM physical presence module.
892
893 @param PpRequest TPM physical presence operation request.
894
895 @retval EFI_SUCCESS Do the required action success.
896 @retval Others Other error occur.
897
898 **/
899 EFI_STATUS
900 HiiSetBlockSidAction (
901 IN UINT32 PpRequest
902 )
903 {
904 UINT32 ReturnCode;
905 EFI_STATUS Status;
906
907 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest, 0);
908 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
909 Status = EFI_SUCCESS;
910 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {
911 Status = EFI_OUT_OF_RESOURCES;
912 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {
913 Status = EFI_UNSUPPORTED;
914 } else {
915 Status = EFI_DEVICE_ERROR;
916 }
917
918 return Status;
919 }
920
921 /**
922 This function processes the results of changes in configuration.
923
924 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
925 @param Configuration A null-terminated Unicode string in <ConfigResp>
926 format.
927 @param Progress A pointer to a string filled in with the offset of
928 the most recent '&' before the first failing
929 name/value pair (or the beginning of the string if
930 the failure is in the first name/value pair) or
931 the terminating NULL if all was successful.
932
933 @retval EFI_SUCCESS The Results is processed successfully.
934 @retval EFI_INVALID_PARAMETER Configuration is NULL.
935 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
936 driver.
937
938 **/
939 EFI_STATUS
940 EFIAPI
941 RouteConfig(
942 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
943 CONST EFI_STRING Configuration,
944 EFI_STRING *Progress
945 )
946 {
947 if (Configuration == NULL || Progress == NULL) {
948 return (EFI_INVALID_PARAMETER);
949 }
950
951 *Progress = Configuration;
952 if (!HiiIsConfigHdrMatch (Configuration, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
953 return EFI_NOT_FOUND;
954 }
955
956 *Progress = Configuration + StrLen (Configuration);
957
958 return EFI_SUCCESS;
959 }
960
961 /**
962 This function allows a caller to extract the current configuration for one
963 or more named elements from the target driver.
964
965 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
966 @param Request A null-terminated Unicode string in
967 <ConfigRequest> format.
968 @param Progress On return, points to a character in the Request
969 string. Points to the string's null terminator if
970 request was successful. Points to the most recent
971 '&' before the first failing name/value pair (or
972 the beginning of the string if the failure is in
973 the first name/value pair) if the request was not
974 successful.
975 @param Results A null-terminated Unicode string in
976 <ConfigAltResp> format which has all values filled
977 in for the names in the Request string. String to
978 be allocated by the called function.
979
980 @retval EFI_SUCCESS The Results is filled with the requested values.
981 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
982 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
983 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
984 driver.
985
986 **/
987 EFI_STATUS
988 EFIAPI
989 ExtractConfig(
990 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
991 CONST EFI_STRING Request,
992 EFI_STRING *Progress,
993 EFI_STRING *Results
994 )
995 {
996 EFI_STATUS Status;
997 EFI_STRING ConfigRequest;
998 EFI_STRING ConfigRequestHdr;
999 UINTN BufferSize;
1000 UINTN Size;
1001 BOOLEAN AllocatedRequest;
1002 EFI_HANDLE DriverHandle;
1003
1004 //
1005 // Check for valid parameters
1006 //
1007 if (Progress == NULL || Results == NULL) {
1008 return (EFI_INVALID_PARAMETER);
1009 }
1010
1011 *Progress = Request;
1012 if ((Request != NULL) &&
1013 !HiiIsConfigHdrMatch (Request, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
1014 return EFI_NOT_FOUND;
1015 }
1016
1017 AllocatedRequest = FALSE;
1018 BufferSize = sizeof (OPAL_HII_CONFIGURATION);
1019 ConfigRequest = Request;
1020 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
1021 //
1022 // Request has no request element, construct full request string.
1023 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1024 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1025 //
1026 DriverHandle = HiiGetDriverImageHandleCB();
1027 ConfigRequestHdr = HiiConstructConfigHdr (&gHiiSetupVariableGuid, OpalPasswordStorageName, DriverHandle);
1028 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
1029 ConfigRequest = AllocateZeroPool (Size);
1030 if (ConfigRequest == NULL) {
1031 return EFI_OUT_OF_RESOURCES;
1032 }
1033 AllocatedRequest = TRUE;
1034 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
1035 FreePool (ConfigRequestHdr);
1036 }
1037
1038 //
1039 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1040 //
1041 Status = gHiiConfigRouting->BlockToConfig(
1042 gHiiConfigRouting,
1043 ConfigRequest,
1044 (UINT8*)&gHiiConfiguration,
1045 sizeof(OPAL_HII_CONFIGURATION),
1046 Results,
1047 Progress
1048 );
1049
1050 //
1051 // Free the allocated config request string.
1052 //
1053 if (AllocatedRequest) {
1054 FreePool (ConfigRequest);
1055 ConfigRequest = NULL;
1056 }
1057
1058 //
1059 // Set Progress string to the original request string.
1060 //
1061 if (Request == NULL) {
1062 *Progress = NULL;
1063 } else if (StrStr (Request, L"OFFSET") == NULL) {
1064 *Progress = Request + StrLen (Request);
1065 }
1066
1067 return (Status);
1068 }
1069
1070
1071 /**
1072
1073 Pass the current system state to the bios via the hii_G_Configuration.
1074
1075 **/
1076 VOID
1077 OpalHiiSetBrowserData (
1078 VOID
1079 )
1080 {
1081 HiiSetBrowserData(
1082 &gHiiSetupVariableGuid,
1083 (CHAR16*)L"OpalHiiConfig",
1084 sizeof(gHiiConfiguration),
1085 (UINT8*)&gHiiConfiguration,
1086 NULL
1087 );
1088 }
1089
1090
1091 /**
1092
1093 Populate the hii_g_Configuration with the browser Data.
1094
1095 **/
1096 VOID
1097 OpalHiiGetBrowserData (
1098 VOID
1099 )
1100 {
1101 HiiGetBrowserData(
1102 &gHiiSetupVariableGuid,
1103 (CHAR16*)L"OpalHiiConfig",
1104 sizeof(gHiiConfiguration),
1105 (UINT8*)&gHiiConfiguration
1106 );
1107 }
1108
1109 /**
1110 Set a string Value in a form.
1111
1112 @param DestStringId The stringid which need to update.
1113 @param SrcAsciiStr The string nned to update.
1114
1115 @retval EFI_SUCCESS Do the required action success.
1116 @retval Others Other error occur.
1117
1118 **/
1119 EFI_STATUS
1120 HiiSetFormString(
1121 EFI_STRING_ID DestStringId,
1122 CHAR8 *SrcAsciiStr
1123 )
1124 {
1125 UINT32 Len;
1126 UINT32 UniSize;
1127 CHAR16* UniStr;
1128
1129 //
1130 // Determine the Length of the sting
1131 //
1132 Len = ( UINT32 )AsciiStrLen( SrcAsciiStr );
1133
1134 //
1135 // Allocate space for the unicode string, including terminator
1136 //
1137 UniSize = (Len + 1) * sizeof(CHAR16);
1138 UniStr = (CHAR16*)AllocateZeroPool(UniSize);
1139
1140 //
1141 // Copy into unicode string, then copy into string id
1142 //
1143 AsciiStrToUnicodeStrS ( SrcAsciiStr, UniStr, Len + 1);
1144
1145 //
1146 // Update the string in the form
1147 //
1148 if (HiiSetString(gHiiPackageListHandle, DestStringId, UniStr, NULL) == 0) {
1149 DEBUG ((DEBUG_INFO, "HiiSetFormString( ) failed\n"));
1150 FreePool(UniStr);
1151 return (EFI_OUT_OF_RESOURCES);
1152 }
1153
1154 //
1155 // Free the memory
1156 //
1157 FreePool(UniStr);
1158
1159 return (EFI_SUCCESS);
1160 }
1161
1162 /**
1163 Initialize the Opal disk base on the hardware info get from device.
1164
1165 @param Dev The Opal device.
1166
1167 @retval EFI_SUCCESS Initialize the device success.
1168 @retval EFI_DEVICE_ERROR Get info from device failed.
1169
1170 **/
1171 EFI_STATUS
1172 OpalDiskInitialize (
1173 IN OPAL_DRIVER_DEVICE *Dev
1174 )
1175 {
1176 TCG_RESULT TcgResult;
1177 OPAL_SESSION Session;
1178 UINT8 ActiveDataRemovalMechanism;
1179 UINT32 RemovalMechanishLists[ResearvedMechanism];
1180
1181 ZeroMem(&Dev->OpalDisk, sizeof(OPAL_DISK));
1182 Dev->OpalDisk.Sscp = Dev->Sscp;
1183 Dev->OpalDisk.MediaId = Dev->MediaId;
1184 Dev->OpalDisk.OpalDevicePath = Dev->OpalDevicePath;
1185
1186 ZeroMem(&Session, sizeof(Session));
1187 Session.Sscp = Dev->Sscp;
1188 Session.MediaId = Dev->MediaId;
1189
1190 TcgResult = OpalGetSupportedAttributesInfo (&Session, &Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.OpalBaseComId);
1191 if (TcgResult != TcgResultSuccess) {
1192 return EFI_DEVICE_ERROR;
1193 }
1194 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1195
1196 TcgResult = OpalUtilGetMsid (&Session, Dev->OpalDisk.Msid, OPAL_MSID_LENGTH, &Dev->OpalDisk.MsidLength);
1197 if (TcgResult != TcgResultSuccess) {
1198 return EFI_DEVICE_ERROR;
1199 }
1200
1201 if (Dev->OpalDisk.SupportedAttributes.DataRemoval) {
1202 TcgResult = OpalUtilGetDataRemovalMechanismLists (&Session, RemovalMechanishLists);
1203 if (TcgResult != TcgResultSuccess) {
1204 return EFI_DEVICE_ERROR;
1205 }
1206
1207 TcgResult = OpalUtilGetActiveDataRemovalMechanism (&Session, Dev->OpalDisk.Msid, Dev->OpalDisk.MsidLength, &ActiveDataRemovalMechanism);
1208 if (TcgResult != TcgResultSuccess) {
1209 return EFI_DEVICE_ERROR;
1210 }
1211
1212 Dev->OpalDisk.EstimateTimeCost = RemovalMechanishLists[ActiveDataRemovalMechanism];
1213 }
1214
1215 return OpalDiskUpdateStatus (&Dev->OpalDisk);
1216 }
1217
1218 /**
1219 Update the device ownship
1220
1221 @param OpalDisk The Opal device.
1222
1223 @retval EFI_SUCCESS Get ownership success.
1224 @retval EFI_ACCESS_DENIED Has send BlockSID command, can't change ownership.
1225 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1226
1227 **/
1228 EFI_STATUS
1229 OpalDiskUpdateOwnerShip (
1230 OPAL_DISK *OpalDisk
1231 )
1232 {
1233 OPAL_SESSION Session;
1234
1235 if (OpalDisk->MsidLength == 0) {
1236 return EFI_INVALID_PARAMETER;
1237 }
1238
1239 if (OpalDisk->SentBlockSID) {
1240 return EFI_ACCESS_DENIED;
1241 }
1242
1243 ZeroMem(&Session, sizeof(Session));
1244 Session.Sscp = OpalDisk->Sscp;
1245 Session.MediaId = OpalDisk->MediaId;
1246 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1247
1248 OpalDisk->Owner = OpalUtilDetermineOwnership(&Session, OpalDisk->Msid, OpalDisk->MsidLength);
1249 return EFI_SUCCESS;
1250 }
1251
1252 /**
1253 Update the device info.
1254
1255 @param OpalDisk The Opal device.
1256
1257 @retval EFI_SUCCESS Initialize the device success.
1258 @retval EFI_DEVICE_ERROR Get info from device failed.
1259 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1260 @retval EFI_ACCESS_DENIED Has send BlockSID command, can't change ownership.
1261
1262 **/
1263 EFI_STATUS
1264 OpalDiskUpdateStatus (
1265 OPAL_DISK *OpalDisk
1266 )
1267 {
1268 TCG_RESULT TcgResult;
1269 OPAL_SESSION Session;
1270
1271 ZeroMem(&Session, sizeof(Session));
1272 Session.Sscp = OpalDisk->Sscp;
1273 Session.MediaId = OpalDisk->MediaId;
1274 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1275
1276 TcgResult = OpalGetLockingInfo(&Session, &OpalDisk->LockingFeature);
1277 if (TcgResult != TcgResultSuccess) {
1278 return EFI_DEVICE_ERROR;
1279 }
1280
1281 return OpalDiskUpdateOwnerShip (OpalDisk);
1282 }
1283