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