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