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