]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
eb7d59b52c2a0da7e89aa5750d5a46079fc6b085
[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 gHiiConfiguration.AvailableFields |= HII_FIELD_KEEP_USER_DATA;
378 if (AvailActions.RevertKeepDataForced) {
379 gHiiConfiguration.AvailableFields |= HII_FIELD_KEEP_USER_DATA_FORCED;
380 }
381 break;
382 }
383
384 OpalHiiSetBrowserData ();
385
386 return EFI_SUCCESS;
387 }
388
389 /**
390 Get disk name string id.
391
392 @param DiskIndex The input disk index info.
393
394 @retval The disk name string id.
395
396 **/
397 EFI_STRING_ID
398 GetDiskNameStringId(
399 UINT8 DiskIndex
400 )
401 {
402 switch (DiskIndex) {
403 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0);
404 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1);
405 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2);
406 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3);
407 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4);
408 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5);
409 }
410 return 0;
411 }
412
413 /**
414 This function processes the results of changes in configuration.
415
416 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
417 @param Action Specifies the type of action taken by the browser.
418 @param QuestionId A unique value which is sent to the original
419 exporting driver so that it can identify the type
420 of data to expect.
421 @param Type The type of value for the question.
422 @param Value A pointer to the data being sent to the original
423 exporting driver.
424 @param ActionRequest On return, points to the action requested by the
425 callback function.
426
427 @retval EFI_SUCCESS The callback successfully handled the action.
428 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
429 variable and its data.
430 @retval EFI_DEVICE_ERROR The variable could not be saved.
431 @retval EFI_UNSUPPORTED The specified Action is not supported by the
432 callback.
433
434 **/
435 EFI_STATUS
436 EFIAPI
437 DriverCallback(
438 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
439 EFI_BROWSER_ACTION Action,
440 EFI_QUESTION_ID QuestionId,
441 UINT8 Type,
442 EFI_IFR_TYPE_VALUE *Value,
443 EFI_BROWSER_ACTION_REQUEST *ActionRequest
444 )
445 {
446 HII_KEY HiiKey;
447 UINT8 HiiKeyId;
448
449 if (ActionRequest != NULL) {
450 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
451 } else {
452 return EFI_INVALID_PARAMETER;
453 }
454
455 //
456 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
457 //
458 if ((QuestionId & HII_KEY_FLAG) == 0) {
459 return EFI_SUCCESS;
460 }
461
462 HiiKey.Raw = QuestionId;
463 HiiKeyId = (UINT8) HiiKey.KeyBits.Id;
464
465 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
466 switch (HiiKeyId) {
467 case HII_KEY_ID_VAR_SUPPORTED_DISKS:
468 DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
469 return HiiPopulateMainMenuForm ();
470
471 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS:
472 return HiiPopulateDiskInfoForm();
473 }
474 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {
475 switch (HiiKeyId) {
476 case HII_KEY_ID_GOTO_DISK_INFO:
477 return HiiSelectDisk((UINT8)HiiKey.KeyBits.Index);
478
479 case HII_KEY_ID_GOTO_LOCK:
480 return HiiSelectDiskAction("Action: Lock", HiiKeyId);
481
482 case HII_KEY_ID_GOTO_UNLOCK:
483 return HiiSelectDiskAction("Action: Unlock", HiiKeyId);
484
485 case HII_KEY_ID_GOTO_SET_ADMIN_PWD:
486 return HiiSelectDiskAction("Action: Set Administrator Password", HiiKeyId);
487
488 case HII_KEY_ID_GOTO_SET_USER_PWD:
489 return HiiSelectDiskAction("Action: Set User Password", HiiKeyId);
490
491 case HII_KEY_ID_GOTO_SECURE_ERASE:
492 return HiiSelectDiskAction("Action: Secure Erase", HiiKeyId);
493
494 case HII_KEY_ID_GOTO_PSID_REVERT:
495 return HiiSelectDiskAction("Action: Revert to Factory Defaults with PSID", HiiKeyId);
496
497 case HII_KEY_ID_GOTO_REVERT:
498 return HiiSelectDiskAction("Action: Revert to Factory Defaults", HiiKeyId);
499
500 case HII_KEY_ID_GOTO_DISABLE_USER:
501 return HiiSelectDiskAction("Action: Disable User", HiiKeyId);
502
503 case HII_KEY_ID_GOTO_ENABLE_FEATURE:
504 return HiiSelectDiskAction("Action: Enable Feature", HiiKeyId);
505
506 case HII_KEY_ID_ENTER_PASSWORD:
507 return HiiPasswordEntered(Value->string);
508
509 case HII_KEY_ID_BLOCKSID:
510 return HiiSetBlockSid(Value->b);
511 }
512 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
513 switch (HiiKeyId) {
514 case HII_KEY_ID_ENTER_PSID:
515 HiiPsidRevert();
516 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
517 return EFI_SUCCESS;
518 }
519 }
520
521 return EFI_UNSUPPORTED;
522 }
523
524 /**
525 Update the global Disk index info.
526
527 @param Index The input disk index info.
528
529 @retval EFI_SUCCESS Update the disk index info success.
530
531 **/
532 EFI_STATUS
533 HiiSelectDisk(
534 UINT8 Index
535 )
536 {
537 OpalHiiGetBrowserData();
538 gHiiConfiguration.SelectedDiskIndex = Index;
539 OpalHiiSetBrowserData ();
540
541 return EFI_SUCCESS;
542 }
543
544 /**
545 Draws the disk info form.
546
547 @retval EFI_SUCCESS Draw the disk info success.
548
549 **/
550 EFI_STATUS
551 HiiPopulateDiskInfoForm(
552 VOID
553 )
554 {
555 OPAL_DISK* OpalDisk;
556 OPAL_DISK_ACTIONS AvailActions;
557 TCG_RESULT Ret;
558 CHAR8 *DiskName;
559
560 OpalHiiGetBrowserData();
561
562 DiskName = HiiDiskGetNameCB (gHiiConfiguration.SelectedDiskIndex);
563 if (DiskName == NULL) {
564 return EFI_UNSUPPORTED;
565 }
566 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME), DiskName);
567
568 ZeroMem(gHiiConfiguration.Psid, sizeof(gHiiConfiguration.Psid));
569
570 gHiiConfiguration.SelectedDiskAvailableActions = HII_ACTION_NONE;
571
572 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
573
574 if (OpalDisk != NULL) {
575 OpalDiskUpdateStatus (OpalDisk);
576 Ret = OpalSupportGetAvailableActions(&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature, OpalDisk->Owner, &AvailActions);
577 if (Ret == TcgResultSuccess) {
578 //
579 // Update actions, always allow PSID Revert
580 //
581 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.PsidRevert == 1) ? HII_ACTION_PSID_REVERT : HII_ACTION_NONE;
582
583 //
584 // Always allow unlock to handle device migration
585 //
586 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Unlock == 1) ? HII_ACTION_UNLOCK : HII_ACTION_NONE;
587
588 if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {
589 if (OpalDisk->Owner == OpalOwnershipNobody) {
590 gHiiConfiguration.SelectedDiskAvailableActions |= HII_ACTION_ENABLE_FEATURE;
591
592 //
593 // Update strings
594 //
595 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default");
596 } else {
597 DEBUG ((DEBUG_INFO, "Feature disabled but ownership != nobody\n"));
598 }
599 } else {
600 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Revert == 1) ? HII_ACTION_REVERT : HII_ACTION_NONE;
601 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.AdminPass == 1) ? HII_ACTION_SET_ADMIN_PWD : HII_ACTION_NONE;
602 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.UserPass == 1) ? HII_ACTION_SET_USER_PWD : HII_ACTION_NONE;
603 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.SecureErase == 1) ? HII_ACTION_SECURE_ERASE : HII_ACTION_NONE;
604 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.DisableUser == 1) ? HII_ACTION_DISABLE_USER : HII_ACTION_NONE;
605 gHiiConfiguration.SelectedDiskAvailableActions |= HII_ACTION_ENABLE_BLOCKSID;
606
607 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default and Disable");
608
609 //
610 // Determine revert options for disk
611 // Default initialize keep user Data to be true
612 //
613 gHiiConfiguration.KeepUserData = 1;
614 }
615 }
616 }
617
618 //
619 // Pass the current configuration to the BIOS
620 //
621 OpalHiiSetBrowserData ();
622
623 return EFI_SUCCESS;
624 }
625
626 /**
627 Reverts the Opal disk to factory default.
628
629 @retval EFI_SUCCESS Do the required action success.
630
631 **/
632 EFI_STATUS
633 HiiPsidRevert(
634 VOID
635 )
636 {
637 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
638 TCG_PSID Psid;
639 OPAL_DISK *OpalDisk;
640 TCG_RESULT Ret;
641 OPAL_SESSION Session;
642
643 Ret = TcgResultFailure;
644
645 OpalHiiGetBrowserData();
646
647 UnicodeStrToAsciiStr(gHiiConfiguration.Psid, (CHAR8*)Psid.Psid);
648
649 OpalDisk = HiiGetOpalDiskCB (gHiiConfiguration.SelectedDiskIndex);
650 if (OpalDisk != NULL) {
651 ZeroMem(&Session, sizeof(Session));
652 Session.Sscp = OpalDisk->Sscp;
653 Session.MediaId = OpalDisk->MediaId;
654 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
655
656 Ret = OpalSupportPsidRevert(&Session, Psid.Psid, (UINT32)sizeof(Psid.Psid), OpalDisk->OpalDevicePath);
657 }
658
659 if (Ret == TcgResultSuccess) {
660 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "PSID Revert: Success" );
661 } else {
662 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "PSID Revert: Failure" );
663 }
664
665 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
666
667 return EFI_SUCCESS;
668 }
669
670 /**
671 Set password for the disk.
672
673 @param OpalDisk The disk need to set the password.
674 @param Password The input password.
675 @param PassLength The input password length.
676
677 @retval EFI_SUCCESS Do the required action success.
678
679 **/
680 EFI_STATUS
681 HiiSetPassword(
682 OPAL_DISK *OpalDisk,
683 VOID *Password,
684 UINT32 PassLength
685 )
686 {
687 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
688 TCG_RESULT Ret;
689 BOOLEAN ExistingPassword;
690 OPAL_SESSION Session;
691
692 ExistingPassword = FALSE;
693
694 //
695 // PassLength = 0 means check whether exist old password.
696 //
697 if (PassLength == 0) {
698 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
699 gHiiOldPasswordLength = 0;
700
701 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_ENABLE_FEATURE) {
702 ExistingPassword = FALSE;
703 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_ADMIN_PWD) {
704 ExistingPassword = OpalUtilAdminPasswordExists(OpalDisk->Owner, &OpalDisk->LockingFeature);
705 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
706 //
707 // Set user Password option shall only be shown if an Admin Password exists
708 // so a Password is always required (Admin or Existing User Password)
709 //
710 ExistingPassword = TRUE;
711 }
712
713 //
714 // Return error if there is a previous Password
715 // see UEFI 2.4 errata B, Figure 121. Password Flowchart
716 //
717 return ExistingPassword ? EFI_DEVICE_ERROR : EFI_SUCCESS;
718 }
719
720 ZeroMem(&Session, sizeof(Session));
721 Session.Sscp = OpalDisk->Sscp;
722 Session.MediaId = OpalDisk->MediaId;
723 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
724
725 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Failure");
726 //
727 // Password entered.
728 // No current Owner, so set new Password, must be admin Password
729 //
730 if (OpalDisk->Owner == OpalOwnershipNobody) {
731 Ret = OpalSupportEnableOpalFeature (&Session, OpalDisk->Msid, OpalDisk->MsidLength,Password, PassLength, OpalDisk->OpalDevicePath);
732 if (Ret == TcgResultSuccess) {
733 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Success");
734 }
735
736 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
737 return EFI_SUCCESS;
738 }
739
740 //
741 // 1st Password entered
742 //
743 if (OpalDisk->Owner == OpalOwnershipUnknown && gHiiOldPasswordLength == 0) {
744
745 //
746 // Unknown ownership - prompt for old Password, then new
747 // old Password is not set yet - first time through
748 // assume authority provided is admin1, overwritten if user1 authority works below
749 //
750 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
751 //
752 // First try to login as USER1 to Locking SP to see if we're simply updating its Password
753 //
754 Ret = OpalUtilVerifyPassword (&Session, Password, PassLength, OPAL_LOCKING_SP_USER1_AUTHORITY);
755 if (Ret == TcgResultSuccess) {
756 //
757 // User1 worked so authority 1 means user 1
758 //
759 CopyMem(gHiiOldPassword, Password, PassLength);
760 gHiiOldPasswordLength = PassLength;
761
762 return EFI_SUCCESS;
763 }
764 }
765
766 //
767 // Else try admin1 below
768 //
769 Ret = OpalUtilVerifyPassword (&Session, Password, PassLength, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);
770 if (Ret == TcgResultSuccess) {
771 CopyMem(gHiiOldPassword, Password, PassLength);
772 gHiiOldPasswordLength = PassLength;
773
774 return EFI_SUCCESS;
775 } else {
776 DEBUG ((DEBUG_INFO, "start session with old PW failed - return EFI_NOT_READY - mistyped old PW\n"));
777 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), "Authentication Failure");
778
779 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
780 gHiiOldPasswordLength = 0;
781
782 return EFI_NOT_READY;
783 }
784 }
785
786 //
787 // New Password entered
788 //
789 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SET_USER_PWD) {
790 Ret = OpalSupportSetPassword(
791 &Session,
792 gHiiOldPassword,
793 gHiiOldPasswordLength,
794 Password,
795 PassLength,
796 OpalDisk->OpalDevicePath,
797 FALSE
798 );
799 } else {
800 Ret = OpalSupportSetPassword(
801 &Session,
802 gHiiOldPassword,
803 gHiiOldPasswordLength,
804 Password,
805 PassLength,
806 OpalDisk->OpalDevicePath,
807 TRUE
808 );
809 }
810
811 if (Ret == TcgResultSuccess) {
812 AsciiSPrint(Response, DEFAULT_RESPONSE_SIZE, "%a", "Set Password: Success");
813 }
814
815 //
816 // Reset old Password storage
817 //
818 ZeroMem(gHiiOldPassword, sizeof(gHiiOldPassword));
819 gHiiOldPasswordLength = 0;
820
821 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
822 return Ret == TcgResultSuccess ? EFI_SUCCESS : EFI_NOT_READY;
823 }
824
825 /**
826 Secure Erases Opal Disk.
827
828 @param OpalDisk The disk need to erase data.
829 @param Password The input password.
830 @param PassLength The input password length.
831
832 @retval EFI_SUCCESS Do the required action success.
833
834 **/
835 EFI_STATUS
836 HiiSecureErase(
837 OPAL_DISK *OpalDisk,
838 const VOID *Password,
839 UINT32 PassLength
840 )
841 {
842 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
843 BOOLEAN PasswordFailed;
844 TCG_RESULT Ret;
845 OPAL_SESSION AdminSpSession;
846
847 if (PassLength == 0) {
848 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
849 }
850
851 ZeroMem(&AdminSpSession, sizeof(AdminSpSession));
852 AdminSpSession.Sscp = OpalDisk->Sscp;
853 AdminSpSession.MediaId = OpalDisk->MediaId;
854 AdminSpSession.OpalBaseComId = OpalDisk->OpalBaseComId;
855
856 Ret = OpalUtilSecureErase(&AdminSpSession, Password, PassLength, &PasswordFailed);
857 if (Ret == TcgResultSuccess) {
858 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Secure Erase: Success" );
859 } else {
860 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Secure Erase: Failure" );
861 }
862 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
863
864 //
865 // If Password failed, return invalid passowrd
866 //
867 if (PasswordFailed) {
868 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
869 return EFI_NOT_READY;
870 }
871
872 //
873 // Indicates Password was valid and is not changing to UEFI
874 // Response string will indicate action error
875 //
876 return EFI_DEVICE_ERROR;
877 }
878
879
880 /**
881 Disables User for Opal Disk.
882
883 @param OpalDisk The disk need to the action.
884 @param Password The input password.
885 @param PassLength The input password length.
886
887 @retval EFI_SUCCESS Do the required action success.
888
889 **/
890 EFI_STATUS
891 HiiDisableUser(
892 OPAL_DISK *OpalDisk,
893 VOID *Password,
894 UINT32 PassLength
895 )
896 {
897 CHAR8 Response[ DEFAULT_RESPONSE_SIZE ];
898 BOOLEAN PasswordFailed;
899 TCG_RESULT Ret;
900 OPAL_SESSION Session;
901
902 if (PassLength == 0) {
903 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
904 }
905
906 ZeroMem(&Session, sizeof(Session));
907 Session.Sscp = OpalDisk->Sscp;
908 Session.MediaId = OpalDisk->MediaId;
909 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
910
911 Ret = OpalSupportDisableUser(&Session, Password, PassLength, &PasswordFailed, OpalDisk->OpalDevicePath);
912 if (Ret == TcgResultSuccess) {
913 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Disable User: Success" );
914 } else {
915 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Disable User: Failure" );
916 }
917 HiiSetFormString (STRING_TOKEN(STR_ACTION_STATUS), Response);
918
919 //
920 // If Password failed, return invalid passowrd
921 //
922 if (PasswordFailed) {
923 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
924 return EFI_NOT_READY;
925 }
926
927 //
928 // Indicates Password was valid and is not changing to UEFI
929 // Response string will indicate action error
930 //
931 return EFI_DEVICE_ERROR;
932 }
933
934 /**
935 Revert Opal Disk as Admin1.
936
937 @param OpalDisk The disk need to the action.
938 @param Password The input password.
939 @param PassLength The input password length.
940 @param KeepUserData Whether need to keey user data.
941
942 @retval EFI_SUCCESS Do the required action success.
943
944 **/
945 EFI_STATUS
946 HiiRevert(
947 OPAL_DISK *OpalDisk,
948 VOID *Password,
949 UINT32 PassLength,
950 BOOLEAN KeepUserData
951 )
952 {
953 CHAR8 Response[ DEFAULT_RESPONSE_SIZE ];
954 BOOLEAN PasswordFailed;
955 TCG_RESULT Ret;
956 OPAL_SESSION Session;
957
958 if (PassLength == 0) {
959 DEBUG ((DEBUG_INFO, "Returning error to indicate there is an existing Password\n"));
960 // return error to indicate there is an existing Password
961 return EFI_DEVICE_ERROR;
962 }
963
964 ZeroMem(&Session, sizeof(Session));
965 Session.Sscp = OpalDisk->Sscp;
966 Session.MediaId = OpalDisk->MediaId;
967 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
968
969 Ret = OpalSupportRevert(
970 &Session,
971 KeepUserData,
972 Password,
973 PassLength,
974 OpalDisk->Msid,
975 OpalDisk->MsidLength,
976 &PasswordFailed,
977 OpalDisk->OpalDevicePath
978 );
979 if (Ret == TcgResultSuccess) {
980 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Revert: Success" );
981 } else {
982 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Revert: Failure" );
983 }
984 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
985
986 //
987 // If Password failed, return invalid passowrd
988 //
989 if (PasswordFailed) {
990 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
991 return EFI_NOT_READY;
992 }
993
994 //
995 // Indicates Password was valid and is not changing to UEFI
996 // Response string will indicate action error
997 //
998 return EFI_DEVICE_ERROR;
999 }
1000
1001 /**
1002 Unlocks Opal Disk.
1003
1004 @param OpalDisk The disk need to the action.
1005 @param Password The input password.
1006 @param PassLength The input password length.
1007
1008 @retval EFI_SUCCESS Do the required action success.
1009
1010 **/
1011 EFI_STATUS
1012 HiiUnlock(
1013 OPAL_DISK *OpalDisk,
1014 VOID *Password,
1015 UINT32 PassLength
1016 )
1017 {
1018 CHAR8 Response[DEFAULT_RESPONSE_SIZE];
1019 TCG_RESULT Ret;
1020 OPAL_SESSION Session;
1021
1022 if (PassLength == 0) {
1023 DEBUG ((DEBUG_INFO, "Returning error to indicate there is an existing Password\n"));
1024 return EFI_DEVICE_ERROR; // return error to indicate there is an existing Password
1025 }
1026
1027 ZeroMem(&Session, sizeof(Session));
1028 Session.Sscp = OpalDisk->Sscp;
1029 Session.MediaId = OpalDisk->MediaId;
1030 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1031
1032 Ret = OpalSupportUnlock(&Session, Password, PassLength, OpalDisk->OpalDevicePath);
1033 if (Ret == TcgResultSuccess) {
1034 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Unlock: Success" );
1035 } else {
1036 AsciiSPrint( Response, DEFAULT_RESPONSE_SIZE, "%a", "Unlock: Failure" );
1037 }
1038
1039 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), Response);
1040
1041 if (Ret == TcgResultSuccess) {
1042 DEBUG ((DEBUG_INFO, "returning error to indicate Password was correct but is not changing\n"));
1043 return EFI_DEVICE_ERROR;
1044 } else {
1045 DEBUG ((DEBUG_INFO, "returning EFI_NOT_READY to indicate Password was not correct\n"));
1046 return EFI_NOT_READY;
1047 }
1048 }
1049
1050 /**
1051 Use the input password to do the specified action.
1052
1053 @param Str The input password saved in.
1054
1055 @retval EFI_SUCCESS Do the required action success.
1056 @retval Others Other error occur.
1057
1058 **/
1059 EFI_STATUS
1060 HiiPasswordEntered(
1061 EFI_STRING_ID Str
1062 )
1063 {
1064 OPAL_DISK* OpalDisk;
1065 CHAR8 Password[MAX_PASSWORD_CHARACTER_LENGTH + 1];
1066 CHAR16* UniStr;
1067 UINT32 PassLength;
1068 EFI_STATUS Status;
1069
1070 OpalHiiGetBrowserData();
1071
1072 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
1073 if (OpalDisk == NULL) {
1074 DEBUG ((DEBUG_INFO, "ERROR: disk %u not found\n", gHiiConfiguration.SelectedDiskIndex));
1075 return EFI_NOT_FOUND;
1076 }
1077
1078 if (Str == 0) {
1079 DEBUG ((DEBUG_INFO, "ERROR: str=NULL\n"));
1080 return EFI_INVALID_PARAMETER;
1081 }
1082
1083 ZeroMem(Password, sizeof(Password));
1084
1085 UniStr = HiiGetString(gHiiPackageListHandle, Str, NULL);
1086 if (UniStr == NULL) {
1087 return EFI_NOT_FOUND;
1088 }
1089 PassLength = (UINT32) StrLen (UniStr);
1090 if (PassLength >= sizeof(Password)) {
1091 HiiSetFormString(STRING_TOKEN(STR_ACTION_STATUS), "Password too long");
1092 gBS->FreePool(UniStr);
1093 return EFI_BUFFER_TOO_SMALL;
1094 }
1095
1096 UnicodeStrToAsciiStr(UniStr, Password);
1097 gBS->FreePool(UniStr);
1098
1099 DEBUG ((DEBUG_INFO, "Password: '%s'\n", Password));
1100
1101 if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_UNLOCK) {
1102 Status = HiiUnlock (OpalDisk, Password, PassLength);
1103 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_SECURE_ERASE) {
1104 Status = HiiSecureErase (OpalDisk, Password, PassLength);
1105 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_DISABLE_USER) {
1106 Status = HiiDisableUser (OpalDisk, Password, PassLength);
1107 } else if (gHiiConfiguration.SelectedAction == HII_KEY_ID_GOTO_REVERT) {
1108 DEBUG ((DEBUG_INFO, "gHiiConfiguration.KeepUserData %u\n", gHiiConfiguration.KeepUserData));
1109 Status = HiiRevert(OpalDisk, Password, PassLength, gHiiConfiguration.KeepUserData);
1110 } else {
1111 Status = HiiSetPassword(OpalDisk, Password, PassLength);
1112 }
1113
1114 OpalHiiSetBrowserData ();
1115
1116 return Status;
1117 }
1118
1119 /**
1120 Update block sid info.
1121
1122 @param Enable Enable/disable BlockSid.
1123
1124 @retval EFI_SUCCESS Do the required action success.
1125 @retval Others Other error occur.
1126
1127 **/
1128 EFI_STATUS
1129 HiiSetBlockSid (
1130 BOOLEAN Enable
1131 )
1132 {
1133 EFI_STATUS Status;
1134 OPAL_EXTRA_INFO_VAR OpalExtraInfo;
1135 UINTN DataSize;
1136
1137 Status = EFI_SUCCESS;
1138
1139 DEBUG ((DEBUG_INFO, "HiiSetBlockSid(enable: %x)\n", Enable));
1140
1141 OpalExtraInfo.EnableBlockSid = Enable;
1142 DataSize = sizeof (OPAL_EXTRA_INFO_VAR);
1143 Status = gRT->SetVariable (
1144 OPAL_EXTRA_INFO_VAR_NAME,
1145 &gOpalExtraInfoVariableGuid,
1146 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1147 DataSize,
1148 &OpalExtraInfo
1149 );
1150 DEBUG ((DEBUG_INFO, "SetVariable, Status: %r\n", Status));
1151
1152 return Status;
1153 }
1154
1155 /**
1156 This function processes the results of changes in configuration.
1157
1158 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1159 @param Configuration A null-terminated Unicode string in <ConfigResp>
1160 format.
1161 @param Progress A pointer to a string filled in with the offset of
1162 the most recent '&' before the first failing
1163 name/value pair (or the beginning of the string if
1164 the failure is in the first name/value pair) or
1165 the terminating NULL if all was successful.
1166
1167 @retval EFI_SUCCESS The Results is processed successfully.
1168 @retval EFI_INVALID_PARAMETER Configuration is NULL.
1169 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1170 driver.
1171
1172 **/
1173 EFI_STATUS
1174 EFIAPI
1175 RouteConfig(
1176 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1177 CONST EFI_STRING Configuration,
1178 EFI_STRING *Progress
1179 )
1180 {
1181 DEBUG ((DEBUG_INFO, "RouteConfig( )\n"));
1182 if (Configuration == NULL || Progress == NULL) {
1183 return (EFI_INVALID_PARAMETER);
1184 }
1185
1186 return EFI_SUCCESS;
1187 }
1188
1189 /**
1190 This function allows a caller to extract the current configuration for one
1191 or more named elements from the target driver.
1192
1193 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1194 @param Request A null-terminated Unicode string in
1195 <ConfigRequest> format.
1196 @param Progress On return, points to a character in the Request
1197 string. Points to the string's null terminator if
1198 request was successful. Points to the most recent
1199 '&' before the first failing name/value pair (or
1200 the beginning of the string if the failure is in
1201 the first name/value pair) if the request was not
1202 successful.
1203 @param Results A null-terminated Unicode string in
1204 <ConfigAltResp> format which has all values filled
1205 in for the names in the Request string. String to
1206 be allocated by the called function.
1207
1208 @retval EFI_SUCCESS The Results is filled with the requested values.
1209 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
1210 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
1211 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
1212 driver.
1213
1214 **/
1215 EFI_STATUS
1216 EFIAPI
1217 ExtractConfig(
1218 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
1219 CONST EFI_STRING Request,
1220 EFI_STRING *Progress,
1221 EFI_STRING *Results
1222 )
1223 {
1224 EFI_STATUS Status;
1225
1226 DEBUG ((DEBUG_INFO, "ExtractConfig( )\n"));
1227
1228 //
1229 // Check for valid parameters
1230 //
1231 if (Progress == NULL || Results == NULL) {
1232 return (EFI_INVALID_PARAMETER);
1233 }
1234
1235 //
1236 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1237 //
1238 Status = gHiiConfigRouting->BlockToConfig(
1239 gHiiConfigRouting,
1240 Request,
1241 (UINT8*)&gHiiConfiguration,
1242 sizeof(OPAL_HII_CONFIGURATION),
1243 Results,
1244 Progress
1245 );
1246
1247 return (Status);
1248 }
1249
1250
1251 /**
1252
1253 Pass the current system state to the bios via the hii_G_Configuration.
1254
1255 **/
1256 VOID
1257 OpalHiiSetBrowserData (
1258 VOID
1259 )
1260 {
1261 DEBUG ((DEBUG_INFO, "OpalHiiSetBrowserData( )\n"));
1262 HiiSetBrowserData(
1263 &gHiiSetupVariableGuid,
1264 (CHAR16*)L"OpalHiiConfig",
1265 sizeof(gHiiConfiguration),
1266 (UINT8*)&gHiiConfiguration,
1267 NULL
1268 );
1269 }
1270
1271
1272 /**
1273
1274 Populate the hii_g_Configuraton with the browser Data.
1275
1276 **/
1277 VOID
1278 OpalHiiGetBrowserData (
1279 VOID
1280 )
1281 {
1282 DEBUG ((DEBUG_INFO, "OpalHiiGetBrowserData( )\n"));
1283 HiiGetBrowserData(
1284 &gHiiSetupVariableGuid,
1285 (CHAR16*)L"OpalHiiConfig",
1286 sizeof(gHiiConfiguration),
1287 (UINT8*)&gHiiConfiguration
1288 );
1289 }
1290
1291 /**
1292 Set a string Value in a form.
1293
1294 @param DestStringId The stringid which need to update.
1295 @param SrcAsciiStr The string nned to update.
1296
1297 @retval EFI_SUCCESS Do the required action success.
1298 @retval Others Other error occur.
1299
1300 **/
1301 EFI_STATUS
1302 HiiSetFormString(
1303 EFI_STRING_ID DestStringId,
1304 CHAR8 *SrcAsciiStr
1305 )
1306 {
1307 UINT32 Len;
1308 UINT32 UniSize;
1309 CHAR16* UniStr;
1310
1311 DEBUG ((DEBUG_INFO, "HiiSetFormString( )\n"));
1312
1313 //
1314 // Determine the Length of the sting
1315 //
1316 Len = ( UINT32 )AsciiStrLen( SrcAsciiStr );
1317
1318 //
1319 // Allocate space for the unicode string, including terminator
1320 //
1321 UniSize = (Len + 1) * sizeof(CHAR16);
1322 UniStr = (CHAR16*)AllocateZeroPool(UniSize);
1323
1324 //
1325 // Copy into unicode string, then copy into string id
1326 //
1327 AsciiStrToUnicodeStr( SrcAsciiStr, UniStr );
1328
1329 //
1330 // Update the string in the form
1331 //
1332 if (HiiSetString(gHiiPackageListHandle, DestStringId, UniStr, NULL) == 0) {
1333 DEBUG ((DEBUG_INFO, "HiiSetFormString( ) failed\n"));
1334 FreePool(UniStr);
1335 return (EFI_OUT_OF_RESOURCES);
1336 }
1337
1338 //
1339 // Free the memory
1340 //
1341 FreePool(UniStr);
1342
1343 return (EFI_SUCCESS);
1344 }
1345
1346 /**
1347 Initialize the Opal disk base on the hardware info get from device.
1348
1349 @param Dev The Opal device.
1350
1351 @retval EFI_SUCESS Initialize the device success.
1352 @retval EFI_DEVICE_ERROR Get info from device failed.
1353
1354 **/
1355 EFI_STATUS
1356 OpalDiskInitialize (
1357 IN OPAL_DRIVER_DEVICE *Dev
1358 )
1359 {
1360 TCG_RESULT TcgResult;
1361 OPAL_SESSION Session;
1362
1363 ZeroMem(&Dev->OpalDisk, sizeof(OPAL_DISK));
1364 Dev->OpalDisk.Sscp = Dev->Sscp;
1365 Dev->OpalDisk.MediaId = Dev->MediaId;
1366 Dev->OpalDisk.OpalDevicePath = Dev->OpalDevicePath;
1367
1368 ZeroMem(&Session, sizeof(Session));
1369 Session.Sscp = Dev->Sscp;
1370 Session.MediaId = Dev->MediaId;
1371
1372 TcgResult = OpalGetSupportedAttributesInfo (&Session, &Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.OpalBaseComId);
1373 if (TcgResult != TcgResultSuccess) {
1374 return EFI_DEVICE_ERROR;
1375 }
1376 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1377
1378 TcgResult = OpalUtilGetMsid (&Session, Dev->OpalDisk.Msid, OPAL_MSID_LENGHT, &Dev->OpalDisk.MsidLength);
1379 if (TcgResult != TcgResultSuccess) {
1380 return EFI_DEVICE_ERROR;
1381 }
1382
1383 return OpalDiskUpdateStatus (&Dev->OpalDisk);
1384 }
1385
1386 /**
1387 Update the device info.
1388
1389 @param OpalDisk The Opal device.
1390
1391 @retval EFI_SUCESS Initialize the device success.
1392 @retval EFI_DEVICE_ERROR Get info from device failed.
1393 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1394
1395 **/
1396 EFI_STATUS
1397 OpalDiskUpdateStatus (
1398 OPAL_DISK *OpalDisk
1399 )
1400 {
1401 TCG_RESULT TcgResult;
1402 OPAL_SESSION Session;
1403
1404 ZeroMem(&Session, sizeof(Session));
1405 Session.Sscp = OpalDisk->Sscp;
1406 Session.MediaId = OpalDisk->MediaId;
1407 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1408
1409 TcgResult = OpalGetLockingInfo(&Session, &OpalDisk->LockingFeature);
1410 if (TcgResult != TcgResultSuccess) {
1411 return EFI_DEVICE_ERROR;
1412 }
1413
1414 if (OpalDisk->MsidLength == 0) {
1415 return EFI_INVALID_PARAMETER;
1416 } else {
1417 //
1418 // Base on the Msid info to get the ownership, so Msid info must get first.
1419 //
1420 OpalDisk->Owner = OpalUtilDetermineOwnership(&Session, OpalDisk->Msid, OpalDisk->MsidLength);
1421 }
1422
1423 return EFI_SUCCESS;
1424 }
1425