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