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