MdeModulePkg: Add match2 opcode support in SetupBrowserDxe and sample code in DriverS...
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
CommitLineData
93e3992d 1/** @file\r
53cf48e0 2This is an example of how a driver might export data to the HII protocol to be\r
3later utilized by the Setup Protocol\r
4\r
2c775600 5Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 6This program and the accompanying materials\r
93e3992d 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
93e3992d 14**/\r
15\r
16\r
17#include "DriverSample.h"\r
18\r
7e3bcccb 19#define DISPLAY_ONLY_MY_ITEM 0x0002\r
93e3992d 20\r
93e3992d 21CHAR16 VariableName[] = L"MyIfrNVData";\r
78c2b9a3 22CHAR16 MyEfiVar[] = L"MyEfiVar";\r
2f3065c0
LG
23EFI_HANDLE DriverHandle[2] = {NULL, NULL};\r
24DRIVER_SAMPLE_PRIVATE_DATA *PrivateData = NULL;\r
211cc6e5 25EFI_EVENT mEvent;\r
2f3065c0
LG
26\r
27HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {\r
f6f910dd 28 {\r
29 {\r
30 HARDWARE_DEVICE_PATH,\r
31 HW_VENDOR_DP,\r
32 {\r
33 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
34 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
35 }\r
36 },\r
c8ad2d7a 37 DRIVER_SAMPLE_FORMSET_GUID\r
f6f910dd 38 },\r
39 {\r
40 END_DEVICE_PATH_TYPE,\r
41 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
a6973cff 42 {\r
f6f910dd 43 (UINT8) (END_DEVICE_PATH_LENGTH),\r
44 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
45 }\r
46 }\r
47};\r
48\r
2f3065c0 49HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {\r
f6f910dd 50 {\r
51 {\r
52 HARDWARE_DEVICE_PATH,\r
53 HW_VENDOR_DP,\r
54 {\r
55 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
56 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
57 }\r
58 },\r
c8ad2d7a 59 DRIVER_SAMPLE_INVENTORY_GUID\r
f6f910dd 60 },\r
61 {\r
62 END_DEVICE_PATH_TYPE,\r
63 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
a6973cff 64 {\r
f6f910dd 65 (UINT8) (END_DEVICE_PATH_LENGTH),\r
66 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
67 }\r
68 }\r
69};\r
70\r
211cc6e5
ED
71/**\r
72 Add empty function for event process function.\r
73\r
74 @param Event The Event need to be process\r
75 @param Context The context of the event.\r
76\r
77**/\r
78VOID\r
79EFIAPI\r
80DriverSampleInternalEmptyFunction (\r
81 IN EFI_EVENT Event,\r
82 IN VOID *Context\r
83 )\r
84{\r
85}\r
86\r
87/**\r
88 Notification function for keystrokes.\r
89\r
90 @param[in] KeyData The key that was pressed.\r
91\r
92 @retval EFI_SUCCESS The operation was successful.\r
93**/\r
94EFI_STATUS\r
95EFIAPI\r
96NotificationFunction(\r
97 IN EFI_KEY_DATA *KeyData\r
98 )\r
99{\r
100 gBS->SignalEvent (mEvent);\r
101 \r
102 return EFI_SUCCESS;\r
103}\r
104\r
105/**\r
106 Function to start monitoring for CTRL-C using SimpleTextInputEx. \r
107\r
108 @retval EFI_SUCCESS The feature is enabled.\r
109 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
113InternalStartMonitor(\r
114 VOID\r
115 )\r
116{\r
117 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
118 EFI_KEY_DATA KeyData;\r
119 EFI_STATUS Status;\r
120 EFI_HANDLE *Handles;\r
121 UINTN HandleCount;\r
122 UINTN HandleIndex;\r
123 EFI_HANDLE NotifyHandle;\r
124\r
125 Status = gBS->LocateHandleBuffer (\r
126 ByProtocol,\r
127 &gEfiSimpleTextInputExProtocolGuid,\r
128 NULL,\r
129 &HandleCount,\r
130 &Handles\r
131 );\r
132 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
133 Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);\r
134 ASSERT_EFI_ERROR (Status);\r
135\r
136 KeyData.KeyState.KeyToggleState = 0;\r
137 KeyData.Key.ScanCode = 0;\r
138 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
139 KeyData.Key.UnicodeChar = L'c';\r
140\r
141 Status = SimpleEx->RegisterKeyNotify(\r
142 SimpleEx,\r
143 &KeyData,\r
144 NotificationFunction,\r
145 &NotifyHandle);\r
146 if (EFI_ERROR (Status)) {\r
147 break;\r
148 }\r
149 \r
150 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
151 Status = SimpleEx->RegisterKeyNotify(\r
152 SimpleEx,\r
153 &KeyData,\r
154 NotificationFunction,\r
155 &NotifyHandle);\r
156 if (EFI_ERROR (Status)) {\r
157 break;\r
158 }\r
159 }\r
160\r
161 return EFI_SUCCESS;\r
162}\r
163\r
164/**\r
165 Function to stop monitoring for CTRL-C using SimpleTextInputEx. \r
166\r
167 @retval EFI_SUCCESS The feature is enabled.\r
168 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.\r
169**/\r
170EFI_STATUS\r
171EFIAPI\r
172InternalStopMonitor(\r
173 VOID\r
174 )\r
175{\r
176 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
177 EFI_STATUS Status;\r
178 EFI_HANDLE *Handles;\r
179 EFI_KEY_DATA KeyData; \r
180 UINTN HandleCount;\r
181 UINTN HandleIndex;\r
182 EFI_HANDLE NotifyHandle;\r
183\r
184 Status = gBS->LocateHandleBuffer (\r
185 ByProtocol,\r
186 &gEfiSimpleTextInputExProtocolGuid,\r
187 NULL,\r
188 &HandleCount,\r
189 &Handles\r
190 );\r
191 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
192 Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);\r
193 ASSERT_EFI_ERROR (Status);\r
194\r
195 KeyData.KeyState.KeyToggleState = 0;\r
196 KeyData.Key.ScanCode = 0;\r
197 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
198 KeyData.Key.UnicodeChar = L'c';\r
199\r
200 Status = SimpleEx->RegisterKeyNotify(\r
201 SimpleEx,\r
202 &KeyData,\r
203 NotificationFunction,\r
204 &NotifyHandle);\r
205 if (!EFI_ERROR (Status)) {\r
206 Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);\r
207 }\r
208\r
209 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
210 Status = SimpleEx->RegisterKeyNotify(\r
211 SimpleEx,\r
212 &KeyData,\r
213 NotificationFunction,\r
214 &NotifyHandle);\r
215 if (!EFI_ERROR (Status)) {\r
216 Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);\r
217 }\r
218 }\r
219 return EFI_SUCCESS;\r
220}\r
221\r
222\r
7064c0a5 223/**\r
224 Encode the password using a simple algorithm.\r
a6973cff 225\r
7064c0a5 226 @param Password The string to be encoded.\r
227 @param MaxSize The size of the string.\r
a6973cff 228\r
7064c0a5 229**/\r
93e3992d 230VOID\r
231EncodePassword (\r
232 IN CHAR16 *Password,\r
5a829f56 233 IN UINTN MaxSize\r
93e3992d 234 )\r
235{\r
236 UINTN Index;\r
237 UINTN Loop;\r
238 CHAR16 *Buffer;\r
239 CHAR16 *Key;\r
240\r
241 Key = L"MAR10648567";\r
242 Buffer = AllocateZeroPool (MaxSize);\r
243 ASSERT (Buffer != NULL);\r
244\r
245 for (Index = 0; Key[Index] != 0; Index++) {\r
246 for (Loop = 0; Loop < (UINT8) (MaxSize / 2); Loop++) {\r
247 Buffer[Loop] = (CHAR16) (Password[Loop] ^ Key[Index]);\r
248 }\r
249 }\r
250\r
251 CopyMem (Password, Buffer, MaxSize);\r
252\r
53cf48e0 253 FreePool (Buffer);\r
93e3992d 254 return ;\r
255}\r
256\r
7064c0a5 257/**\r
258 Validate the user's password.\r
a6973cff 259\r
7064c0a5 260 @param PrivateData This driver's private context data.\r
261 @param StringId The user's input.\r
a6973cff 262\r
7064c0a5 263 @retval EFI_SUCCESS The user's input matches the password.\r
264 @retval EFI_NOT_READY The user's input does not match the password.\r
265**/\r
93e3992d 266EFI_STATUS\r
267ValidatePassword (\r
7064c0a5 268 IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,\r
269 IN EFI_STRING_ID StringId\r
93e3992d 270 )\r
271{\r
272 EFI_STATUS Status;\r
273 UINTN Index;\r
274 UINTN BufferSize;\r
84f9a9ec 275 UINTN PasswordMaxSize;\r
93e3992d 276 CHAR16 *Password;\r
277 CHAR16 *EncodedPassword;\r
278 BOOLEAN OldPassword;\r
279\r
280 //\r
281 // Get encoded password first\r
282 //\r
283 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
284 Status = gRT->GetVariable (\r
285 VariableName,\r
c8ad2d7a 286 &gDriverSampleFormSetGuid,\r
93e3992d 287 NULL,\r
288 &BufferSize,\r
289 &PrivateData->Configuration\r
290 );\r
291 if (EFI_ERROR (Status)) {\r
292 //\r
293 // Old password not exist, prompt for new password\r
294 //\r
295 return EFI_SUCCESS;\r
296 }\r
297\r
298 OldPassword = FALSE;\r
84f9a9ec 299 PasswordMaxSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);\r
93e3992d 300 //\r
301 // Check whether we have any old password set\r
302 //\r
84f9a9ec 303 for (Index = 0; Index < PasswordMaxSize / sizeof (UINT16); Index++) {\r
93e3992d 304 if (PrivateData->Configuration.WhatIsThePassword2[Index] != 0) {\r
305 OldPassword = TRUE;\r
306 break;\r
307 }\r
308 }\r
309 if (!OldPassword) {\r
310 //\r
311 // Old password not exist, return EFI_SUCCESS to prompt for new password\r
312 //\r
313 return EFI_SUCCESS;\r
314 }\r
315\r
316 //\r
317 // Get user input password\r
318 //\r
cb7d01c0 319 Password = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);\r
320 if (Password == NULL) {\r
321 return EFI_NOT_READY;\r
322 }\r
84f9a9ec 323 if (StrSize (Password) > PasswordMaxSize) {\r
53cf48e0 324 FreePool (Password);\r
cb7d01c0 325 return EFI_NOT_READY;\r
93e3992d 326 }\r
327\r
328 //\r
329 // Validate old password\r
330 //\r
84f9a9ec 331 EncodedPassword = AllocateZeroPool (PasswordMaxSize);\r
93e3992d 332 ASSERT (EncodedPassword != NULL);\r
84f9a9ec
LG
333 StrnCpy (EncodedPassword, Password, StrLen (Password));\r
334 EncodePassword (EncodedPassword, StrLen (EncodedPassword) * sizeof (CHAR16));\r
e35eb8af 335 if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, PasswordMaxSize) != 0) {\r
93e3992d 336 //\r
337 // Old password mismatch, return EFI_NOT_READY to prompt for error message\r
338 //\r
339 Status = EFI_NOT_READY;\r
340 } else {\r
341 Status = EFI_SUCCESS;\r
342 }\r
343\r
53cf48e0 344 FreePool (Password);\r
345 FreePool (EncodedPassword);\r
93e3992d 346\r
347 return Status;\r
348}\r
349\r
7064c0a5 350/**\r
351 Encode the password using a simple algorithm.\r
a6973cff 352\r
7064c0a5 353 @param PrivateData This driver's private context data.\r
354 @param StringId The password from User.\r
a6973cff 355\r
7064c0a5 356 @retval EFI_SUCESS The operation is successful.\r
357 @return Other value if gRT->SetVariable () fails.\r
a6973cff 358\r
7064c0a5 359**/\r
93e3992d 360EFI_STATUS\r
361SetPassword (\r
7064c0a5 362 IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,\r
363 IN EFI_STRING_ID StringId\r
93e3992d 364 )\r
365{\r
366 EFI_STATUS Status;\r
93e3992d 367 CHAR16 *Password;\r
cb7d01c0 368 CHAR16 *TempPassword;\r
5a829f56 369 UINTN PasswordSize;\r
93e3992d 370 DRIVER_SAMPLE_CONFIGURATION *Configuration;\r
7e3bcccb 371 UINTN BufferSize;\r
93e3992d 372\r
373 //\r
374 // Get Buffer Storage data from EFI variable\r
375 //\r
376 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
377 Status = gRT->GetVariable (\r
378 VariableName,\r
c8ad2d7a 379 &gDriverSampleFormSetGuid,\r
93e3992d 380 NULL,\r
381 &BufferSize,\r
382 &PrivateData->Configuration\r
383 );\r
384 if (EFI_ERROR (Status)) {\r
385 return Status;\r
386 }\r
387\r
388 //\r
389 // Get user input password\r
390 //\r
523f48e7 391 Password = PrivateData->Configuration.WhatIsThePassword2;\r
a6973cff 392 PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);\r
5a829f56 393 ZeroMem (Password, PasswordSize);\r
a6973cff 394\r
cb7d01c0 395 TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);\r
396 if (TempPassword == NULL) {\r
397 return EFI_NOT_READY;\r
398 }\r
84f9a9ec 399 if (StrSize (TempPassword) > PasswordSize) {\r
cb7d01c0 400 FreePool (TempPassword);\r
401 return EFI_NOT_READY;\r
93e3992d 402 }\r
84f9a9ec 403 StrnCpy (Password, TempPassword, StrLen (TempPassword));\r
cb7d01c0 404 FreePool (TempPassword);\r
93e3992d 405\r
406 //\r
407 // Retrive uncommitted data from Browser\r
408 //\r
1d451ff9
LG
409 Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
410 ASSERT (Configuration != NULL);\r
c8ad2d7a 411 if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
93e3992d 412 //\r
413 // Update password's clear text in the screen\r
414 //\r
84f9a9ec 415 CopyMem (Configuration->PasswordClearText, Password, StrSize (Password));\r
93e3992d 416\r
417 //\r
418 // Update uncommitted data of Browser\r
419 //\r
7e3bcccb 420 HiiSetBrowserData (\r
c8ad2d7a 421 &gDriverSampleFormSetGuid,\r
7e3bcccb
LG
422 VariableName,\r
423 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
424 (UINT8 *) Configuration,\r
425 NULL\r
426 );\r
93e3992d 427 }\r
7e3bcccb 428\r
1d451ff9
LG
429 //\r
430 // Free Configuration Buffer\r
431 //\r
432 FreePool (Configuration);\r
433\r
93e3992d 434\r
435 //\r
436 // Set password\r
437 //\r
84f9a9ec 438 EncodePassword (Password, StrLen (Password) * 2);\r
93e3992d 439 Status = gRT->SetVariable(\r
440 VariableName,\r
c8ad2d7a 441 &gDriverSampleFormSetGuid,\r
93e3992d 442 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
443 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
444 &PrivateData->Configuration\r
445 );\r
446 return Status;\r
447}\r
448\r
38ebfecb
LG
449/**\r
450 Update names of Name/Value storage to current language.\r
451\r
452 @param PrivateData Points to the driver private data.\r
453\r
454 @retval EFI_SUCCESS All names are successfully updated.\r
455 @retval EFI_NOT_FOUND Failed to get Name from HII database.\r
456\r
457**/\r
458EFI_STATUS\r
459LoadNameValueNames (\r
460 IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData\r
461 )\r
462{\r
463 UINTN Index;\r
464\r
465 //\r
466 // Get Name/Value name string of current language\r
467 //\r
468 for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {\r
469 PrivateData->NameValueName[Index] = HiiGetString (\r
470 PrivateData->HiiHandle[0],\r
471 PrivateData->NameStringId[Index],\r
472 NULL\r
473 );\r
474 if (PrivateData->NameValueName[Index] == NULL) {\r
475 return EFI_NOT_FOUND;\r
476 }\r
477 }\r
478\r
479 return EFI_SUCCESS;\r
480}\r
93e3992d 481\r
ee31d1be
ED
482\r
483/**\r
484 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET\r
485 or WIDTH or VALUE.\r
486 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>\r
487\r
488 This is a internal function.\r
489\r
490 @param StringPtr String in <BlockConfig> format and points to the\r
491 first character of <Number>.\r
492 @param Number The output value. Caller takes the responsibility\r
493 to free memory.\r
494 @param Len Length of the <Number>, in characters.\r
495\r
496 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary\r
497 structures.\r
498 @retval EFI_SUCCESS Value of <Number> is outputted in Number\r
499 successfully.\r
500\r
501**/\r
502EFI_STATUS\r
503GetValueOfNumber (\r
504 IN EFI_STRING StringPtr,\r
505 OUT UINT8 **Number,\r
506 OUT UINTN *Len\r
507 )\r
508{\r
509 EFI_STRING TmpPtr;\r
510 UINTN Length;\r
511 EFI_STRING Str;\r
512 UINT8 *Buf;\r
513 EFI_STATUS Status;\r
514 UINT8 DigitUint8;\r
515 UINTN Index;\r
516 CHAR16 TemStr[2];\r
517\r
518 if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) {\r
519 return EFI_INVALID_PARAMETER;\r
520 }\r
521\r
522 Buf = NULL;\r
523\r
524 TmpPtr = StringPtr;\r
525 while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
526 StringPtr++;\r
527 }\r
528 *Len = StringPtr - TmpPtr;\r
529 Length = *Len + 1;\r
530\r
531 Str = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));\r
532 if (Str == NULL) {\r
533 Status = EFI_OUT_OF_RESOURCES;\r
534 goto Exit;\r
535 }\r
536 CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));\r
537 *(Str + *Len) = L'\0';\r
538\r
539 Length = (Length + 1) / 2;\r
540 Buf = (UINT8 *) AllocateZeroPool (Length);\r
541 if (Buf == NULL) {\r
542 Status = EFI_OUT_OF_RESOURCES;\r
543 goto Exit;\r
544 }\r
545 \r
546 Length = *Len;\r
547 ZeroMem (TemStr, sizeof (TemStr));\r
548 for (Index = 0; Index < Length; Index ++) {\r
549 TemStr[0] = Str[Length - Index - 1];\r
550 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
551 if ((Index & 1) == 0) {\r
552 Buf [Index/2] = DigitUint8;\r
553 } else {\r
554 Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);\r
555 }\r
556 }\r
557\r
558 *Number = Buf;\r
559 Status = EFI_SUCCESS;\r
560\r
561Exit:\r
562 if (Str != NULL) {\r
563 FreePool (Str);\r
564 }\r
565\r
566 return Status;\r
567}\r
568\r
569/**\r
570 Create altcfg string. \r
571\r
572 @param Result The request result string.\r
573 @param ConfigHdr The request head info. <ConfigHdr> format.\r
574 @param Offset The offset of the parameter int he structure.\r
575 @param Width The width of the parameter.\r
576\r
577\r
578 @retval The string with altcfg info append at the end.\r
579**/\r
580EFI_STRING \r
581CreateAltCfgString (\r
582 IN EFI_STRING Result,\r
583 IN EFI_STRING ConfigHdr,\r
584 IN UINTN Offset,\r
585 IN UINTN Width\r
586 )\r
587{\r
588 EFI_STRING StringPtr;\r
589 EFI_STRING TmpStr;\r
590 UINTN NewLen;\r
591\r
46cc3885 592 NewLen = StrLen (Result);\r
33d41385
ED
593 //\r
594 // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")\r
595 //\r
46cc3885 596 NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);\r
ee31d1be
ED
597 StringPtr = AllocateZeroPool (NewLen);\r
598 if (StringPtr == NULL) {\r
599 return NULL;\r
600 }\r
601\r
602 TmpStr = StringPtr;\r
603 if (Result != NULL) {\r
604 StrCpy (StringPtr, Result);\r
605 StringPtr += StrLen (Result); \r
606 FreePool (Result);\r
607 }\r
608 \r
609 UnicodeSPrint (\r
610 StringPtr, \r
611 (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), \r
612 L"&%s&ALTCFG=%04x", \r
613 ConfigHdr, \r
614 EFI_HII_DEFAULT_CLASS_STANDARD\r
615 );\r
616 StringPtr += StrLen (StringPtr);\r
617\r
618 UnicodeSPrint (\r
619 StringPtr, \r
620 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),\r
621 L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x", \r
622 Offset, \r
623 Width,\r
624 DEFAULT_CLASS_STANDARD_VALUE\r
625 );\r
626 StringPtr += StrLen (StringPtr); \r
627\r
628 UnicodeSPrint (\r
629 StringPtr, \r
630 (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16), \r
631 L"&%s&ALTCFG=%04x", \r
632 ConfigHdr, \r
633 EFI_HII_DEFAULT_CLASS_MANUFACTURING\r
634 );\r
635 StringPtr += StrLen (StringPtr);\r
636\r
637 UnicodeSPrint (\r
638 StringPtr, \r
639 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),\r
640 L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x", \r
641 Offset, \r
642 Width,\r
643 DEFAULT_CLASS_MANUFACTURING_VALUE\r
644 );\r
645 StringPtr += StrLen (StringPtr); \r
646\r
647 return TmpStr;\r
648}\r
649\r
650/**\r
651 Check whether need to add the altcfg string. if need to add, add the altcfg \r
652 string.\r
653\r
654 @param RequestResult The request result string.\r
655 @param ConfigRequestHdr The request head info. <ConfigHdr> format.\r
656\r
657**/\r
658VOID \r
659AppendAltCfgString (\r
660 IN OUT EFI_STRING *RequestResult,\r
661 IN EFI_STRING ConfigRequestHdr\r
662 )\r
663{\r
664 EFI_STRING StringPtr;\r
ee31d1be
ED
665 UINTN Length;\r
666 UINT8 *TmpBuffer;\r
667 UINTN Offset;\r
668 UINTN Width;\r
669 UINTN BlockSize;\r
670 UINTN ValueOffset;\r
671 UINTN ValueWidth;\r
672 EFI_STATUS Status;\r
673\r
4e1005ec 674 TmpBuffer = NULL;\r
ee31d1be
ED
675 StringPtr = *RequestResult;\r
676 StringPtr = StrStr (StringPtr, L"OFFSET");\r
677 BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
678 ValueOffset = OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, GetDefaultValueFromAccess);\r
679 ValueWidth = sizeof (((DRIVER_SAMPLE_CONFIGURATION *)0)->GetDefaultValueFromAccess);\r
680\r
681 if (StringPtr == NULL) {\r
682 return;\r
683 }\r
684\r
685 while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {\r
ee31d1be
ED
686 StringPtr += StrLen (L"OFFSET=");\r
687 //\r
688 // Get Offset\r
689 //\r
690 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
691 if (EFI_ERROR (Status)) {\r
692 return;\r
693 }\r
694 Offset = 0;\r
695 CopyMem (\r
696 &Offset,\r
697 TmpBuffer,\r
698 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
699 );\r
700 FreePool (TmpBuffer);\r
701\r
702 StringPtr += Length;\r
703 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {\r
704 return;\r
705 }\r
706 StringPtr += StrLen (L"&WIDTH=");\r
707\r
708 //\r
709 // Get Width\r
710 //\r
711 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
712 if (EFI_ERROR (Status)) {\r
713 return;\r
714 }\r
715 Width = 0;\r
716 CopyMem (\r
717 &Width,\r
718 TmpBuffer,\r
719 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)\r
720 );\r
721 FreePool (TmpBuffer);\r
722\r
723 StringPtr += Length;\r
724 if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {\r
725 return;\r
726 }\r
727 StringPtr += StrLen (L"&VALUE=");\r
728\r
729 //\r
b18e7050 730 // Get Value\r
ee31d1be
ED
731 //\r
732 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
733 if (EFI_ERROR (Status)) {\r
734 return;\r
735 }\r
736 StringPtr += Length;\r
737\r
738 //\r
739 // Calculate Value and convert it to hex string.\r
740 //\r
741 if (Offset + Width > BlockSize) {\r
742 return;\r
743 }\r
744\r
745 if (Offset <= ValueOffset && Offset + Width >= ValueOffset + ValueWidth) {\r
33d41385
ED
746 *RequestResult = CreateAltCfgString(*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth);\r
747 return;\r
ee31d1be
ED
748 }\r
749 }\r
750}\r
751\r
93e3992d 752/**\r
753 This function allows a caller to extract the current configuration for one\r
754 or more named elements from the target driver.\r
755\r
756 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
757 @param Request A null-terminated Unicode string in\r
758 <ConfigRequest> format.\r
759 @param Progress On return, points to a character in the Request\r
760 string. Points to the string's null terminator if\r
761 request was successful. Points to the most recent\r
762 '&' before the first failing name/value pair (or\r
763 the beginning of the string if the failure is in\r
764 the first name/value pair) if the request was not\r
765 successful.\r
766 @param Results A null-terminated Unicode string in\r
767 <ConfigAltResp> format which has all values filled\r
768 in for the names in the Request string. String to\r
769 be allocated by the called function.\r
770\r
771 @retval EFI_SUCCESS The Results is filled with the requested values.\r
772 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
e35eb8af 773 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
93e3992d 774 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
775 driver.\r
776\r
777**/\r
778EFI_STATUS\r
779EFIAPI\r
780ExtractConfig (\r
781 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
782 IN CONST EFI_STRING Request,\r
783 OUT EFI_STRING *Progress,\r
784 OUT EFI_STRING *Results\r
785 )\r
786{\r
787 EFI_STATUS Status;\r
788 UINTN BufferSize;\r
789 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;\r
790 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
84f9a9ec 791 EFI_STRING ConfigRequest;\r
086cd2c8 792 EFI_STRING ConfigRequestHdr;\r
84f9a9ec 793 UINTN Size;\r
38ebfecb
LG
794 EFI_STRING Value;\r
795 UINTN ValueStrLen;\r
796 CHAR16 BackupChar;\r
797 CHAR16 *StrPointer;\r
59aefb7e 798 BOOLEAN AllocatedRequest;\r
38ebfecb 799\r
59aefb7e 800 if (Progress == NULL || Results == NULL) {\r
ae79d2f9
LG
801 return EFI_INVALID_PARAMETER;\r
802 }\r
84f9a9ec
LG
803 //\r
804 // Initialize the local variables.\r
805 //\r
086cd2c8
LG
806 ConfigRequestHdr = NULL;\r
807 ConfigRequest = NULL;\r
808 Size = 0;\r
809 *Progress = Request;\r
59aefb7e 810 AllocatedRequest = FALSE;\r
93e3992d 811\r
812 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
813 HiiConfigRouting = PrivateData->HiiConfigRouting;\r
814\r
8d00a0f1 815 //\r
84f9a9ec
LG
816 // Get Buffer Storage data from EFI variable.\r
817 // Try to get the current setting from variable.\r
93e3992d 818 //\r
819 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
04da0b4a
LG
820 Status = gRT->GetVariable (\r
821 VariableName,\r
c8ad2d7a 822 &gDriverSampleFormSetGuid,\r
04da0b4a
LG
823 NULL,\r
824 &BufferSize,\r
825 &PrivateData->Configuration\r
826 );\r
827 if (EFI_ERROR (Status)) {\r
de482998 828 return EFI_NOT_FOUND;\r
04da0b4a 829 }\r
a6973cff 830\r
8d00a0f1 831 if (Request == NULL) {\r
832 //\r
84f9a9ec 833 // Request is set to NULL, construct full request string.\r
7e3bcccb 834 //\r
84f9a9ec 835\r
84f9a9ec 836 //\r
a6973cff 837 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
84f9a9ec
LG
838 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
839 //\r
c8ad2d7a 840 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
59aefb7e 841 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
84f9a9ec 842 ConfigRequest = AllocateZeroPool (Size);\r
1bd57b6e 843 ASSERT (ConfigRequest != NULL);\r
59aefb7e 844 AllocatedRequest = TRUE;\r
086cd2c8
LG
845 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
846 FreePool (ConfigRequestHdr);\r
ee31d1be 847 ConfigRequestHdr = NULL;\r
84f9a9ec 848 } else {\r
de482998
LG
849 //\r
850 // Check routing data in <ConfigHdr>.\r
851 // Note: if only one Storage is used, then this checking could be skipped.\r
852 //\r
c8ad2d7a 853 if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {\r
de482998 854 return EFI_NOT_FOUND;\r
84f9a9ec 855 }\r
59aefb7e 856 //\r
78c2b9a3
ED
857 // Check whether request for EFI Varstore. EFI varstore get data\r
858 // through hii database, not support in this path.\r
859 //\r
c8ad2d7a 860 if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) {\r
78c2b9a3
ED
861 return EFI_UNSUPPORTED;\r
862 }\r
863 //\r
59aefb7e
LG
864 // Set Request to the unified request string.\r
865 //\r
de482998 866 ConfigRequest = Request;\r
38ebfecb 867 //\r
59aefb7e 868 // Check whether Request includes Request Element.\r
38ebfecb
LG
869 //\r
870 if (StrStr (Request, L"OFFSET") == NULL) {\r
871 //\r
59aefb7e 872 // Check Request Element does exist in Reques String\r
38ebfecb 873 //\r
59aefb7e
LG
874 StrPointer = StrStr (Request, L"PATH");\r
875 if (StrPointer == NULL) {\r
876 return EFI_INVALID_PARAMETER;\r
877 }\r
878 if (StrStr (StrPointer, L"&") == NULL) {\r
879 Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16);\r
880 ConfigRequest = AllocateZeroPool (Size);\r
1bd57b6e 881 ASSERT (ConfigRequest != NULL);\r
59aefb7e
LG
882 AllocatedRequest = TRUE;\r
883 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", Request, (UINT64)BufferSize);\r
38ebfecb 884 }\r
59aefb7e
LG
885 }\r
886 }\r
38ebfecb 887\r
59aefb7e
LG
888 //\r
889 // Check if requesting Name/Value storage\r
890 //\r
891 if (StrStr (ConfigRequest, L"OFFSET") == NULL) {\r
892 //\r
893 // Update Name/Value storage Names\r
894 //\r
895 Status = LoadNameValueNames (PrivateData);\r
896 if (EFI_ERROR (Status)) {\r
897 return Status;\r
898 }\r
38ebfecb 899\r
59aefb7e
LG
900 //\r
901 // Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"\r
902 // <Request> ::=<ConfigHdr>&Name0&Name1&Name2\r
903 // <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044\r
904 //\r
905 BufferSize = (StrLen (ConfigRequest) +\r
906 1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 +\r
907 1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 +\r
908 1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16);\r
909 *Results = AllocateZeroPool (BufferSize);\r
910 ASSERT (*Results != NULL);\r
911 StrCpy (*Results, ConfigRequest);\r
912 Value = *Results;\r
38ebfecb 913\r
59aefb7e
LG
914 //\r
915 // Append value of NameValueVar0, type is UINT8\r
916 //\r
917 if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) {\r
918 Value += StrLen (PrivateData->NameValueName[0]);\r
919 ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1);\r
920 CopyMem (Value + ValueStrLen, Value, StrSize (Value));\r
921\r
922 BackupChar = Value[ValueStrLen];\r
923 *Value++ = L'=';\r
924 Value += UnicodeValueToString (\r
925 Value, \r
926 PREFIX_ZERO | RADIX_HEX, \r
927 PrivateData->Configuration.NameValueVar0, \r
928 sizeof (PrivateData->Configuration.NameValueVar0) * 2\r
929 );\r
930 *Value = BackupChar;\r
931 }\r
932\r
933 //\r
934 // Append value of NameValueVar1, type is UINT16\r
935 //\r
936 if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) {\r
937 Value += StrLen (PrivateData->NameValueName[1]);\r
938 ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1);\r
939 CopyMem (Value + ValueStrLen, Value, StrSize (Value));\r
940\r
941 BackupChar = Value[ValueStrLen];\r
942 *Value++ = L'=';\r
943 Value += UnicodeValueToString (\r
944 Value, \r
945 PREFIX_ZERO | RADIX_HEX, \r
946 PrivateData->Configuration.NameValueVar1, \r
947 sizeof (PrivateData->Configuration.NameValueVar1) * 2\r
948 );\r
949 *Value = BackupChar;\r
950 }\r
951\r
952 //\r
953 // Append value of NameValueVar2, type is CHAR16 *\r
954 //\r
955 if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) {\r
956 Value += StrLen (PrivateData->NameValueName[2]);\r
957 ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1;\r
958 CopyMem (Value + ValueStrLen, Value, StrSize (Value));\r
38ebfecb 959\r
59aefb7e 960 *Value++ = L'=';\r
38ebfecb 961 //\r
59aefb7e 962 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
38ebfecb 963 //\r
59aefb7e
LG
964 StrPointer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;\r
965 for (; *StrPointer != L'\0'; StrPointer++) {\r
966 Value += UnicodeValueToString (Value, PREFIX_ZERO | RADIX_HEX, *StrPointer, 4);\r
38ebfecb 967 }\r
38ebfecb 968 }\r
59aefb7e
LG
969 \r
970 Status = EFI_SUCCESS;\r
971 } else {\r
972 //\r
973 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
974 //\r
975 Status = HiiConfigRouting->BlockToConfig (\r
976 HiiConfigRouting,\r
977 ConfigRequest,\r
978 (UINT8 *) &PrivateData->Configuration,\r
979 BufferSize,\r
980 Results,\r
981 Progress\r
982 );\r
33d41385 983 if (!EFI_ERROR (Status)) {\r
c8ad2d7a 984 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
33d41385
ED
985 AppendAltCfgString(Results, ConfigRequestHdr);\r
986 }\r
8d00a0f1 987 }\r
988\r
93e3992d 989 //\r
59aefb7e 990 // Free the allocated config request string.\r
93e3992d 991 //\r
59aefb7e 992 if (AllocatedRequest) {\r
84f9a9ec 993 FreePool (ConfigRequest);\r
59aefb7e 994 }\r
ee31d1be
ED
995\r
996 if (ConfigRequestHdr != NULL) {\r
997 FreePool (ConfigRequestHdr);\r
998 }\r
59aefb7e
LG
999 //\r
1000 // Set Progress string to the original request string.\r
1001 //\r
1002 if (Request == NULL) {\r
1f1cb2f2 1003 *Progress = NULL;\r
59aefb7e
LG
1004 } else if (StrStr (Request, L"OFFSET") == NULL) {\r
1005 *Progress = Request + StrLen (Request);\r
84f9a9ec
LG
1006 }\r
1007\r
93e3992d 1008 return Status;\r
1009}\r
1010\r
1011\r
1012/**\r
1013 This function processes the results of changes in configuration.\r
1014\r
1015 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
1016 @param Configuration A null-terminated Unicode string in <ConfigResp>\r
1017 format.\r
1018 @param Progress A pointer to a string filled in with the offset of\r
1019 the most recent '&' before the first failing\r
1020 name/value pair (or the beginning of the string if\r
1021 the failure is in the first name/value pair) or\r
1022 the terminating NULL if all was successful.\r
1023\r
1024 @retval EFI_SUCCESS The Results is processed successfully.\r
1025 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
1026 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
1027 driver.\r
1028\r
1029**/\r
1030EFI_STATUS\r
1031EFIAPI\r
1032RouteConfig (\r
1033 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
1034 IN CONST EFI_STRING Configuration,\r
1035 OUT EFI_STRING *Progress\r
1036 )\r
1037{\r
1038 EFI_STATUS Status;\r
1039 UINTN BufferSize;\r
1040 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;\r
1041 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
38ebfecb
LG
1042 CHAR16 *Value;\r
1043 CHAR16 *StrPtr;\r
1044 CHAR16 TemStr[5];\r
1045 UINT8 *DataBuffer;\r
1046 UINT8 DigitUint8;\r
1047 UINTN Index;\r
1048 CHAR16 *StrBuffer;\r
93e3992d 1049\r
f5e9ff82 1050 if (Configuration == NULL || Progress == NULL) {\r
8d00a0f1 1051 return EFI_INVALID_PARAMETER;\r
1052 }\r
1053\r
93e3992d 1054 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
1055 HiiConfigRouting = PrivateData->HiiConfigRouting;\r
f5e9ff82 1056 *Progress = Configuration;\r
93e3992d 1057\r
84f9a9ec 1058 //\r
8d00a0f1 1059 // Check routing data in <ConfigHdr>.\r
1060 // Note: if only one Storage is used, then this checking could be skipped.\r
1061 //\r
c8ad2d7a 1062 if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {\r
8d00a0f1 1063 return EFI_NOT_FOUND;\r
1064 }\r
1065\r
78c2b9a3
ED
1066 //\r
1067 // Check whether request for EFI Varstore. EFI varstore get data\r
1068 // through hii database, not support in this path.\r
1069 //\r
c8ad2d7a 1070 if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {\r
78c2b9a3
ED
1071 return EFI_UNSUPPORTED;\r
1072 }\r
1073\r
93e3992d 1074 //\r
1075 // Get Buffer Storage data from EFI variable\r
1076 //\r
1077 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
04da0b4a
LG
1078 Status = gRT->GetVariable (\r
1079 VariableName,\r
c8ad2d7a 1080 &gDriverSampleFormSetGuid,\r
04da0b4a
LG
1081 NULL,\r
1082 &BufferSize,\r
1083 &PrivateData->Configuration\r
1084 );\r
1085 if (EFI_ERROR (Status)) {\r
1086 return Status;\r
1087 }\r
93e3992d 1088\r
38ebfecb
LG
1089 //\r
1090 // Check if configuring Name/Value storage\r
1091 //\r
1092 if (StrStr (Configuration, L"OFFSET") == NULL) {\r
1093 //\r
1094 // Update Name/Value storage Names\r
1095 //\r
1096 Status = LoadNameValueNames (PrivateData);\r
1097 if (EFI_ERROR (Status)) {\r
1098 return Status;\r
1099 }\r
1100\r
1101 //\r
1102 // Convert value for NameValueVar0\r
1103 //\r
1104 if ((Value = StrStr (Configuration, PrivateData->NameValueName[0])) != NULL) {\r
1105 //\r
1106 // Skip "Name="\r
1107 //\r
1108 Value += StrLen (PrivateData->NameValueName[0]);\r
1109 Value++;\r
1110 //\r
1111 // Get Value String\r
1112 //\r
1113 StrPtr = StrStr (Value, L"&");\r
1114 if (StrPtr == NULL) {\r
1115 StrPtr = Value + StrLen (Value);\r
1116 }\r
1117 //\r
1118 // Convert Value to Buffer data\r
1119 //\r
1120 DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar0;\r
1121 ZeroMem (TemStr, sizeof (TemStr));\r
1122 for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {\r
1123 TemStr[0] = *StrPtr;\r
1124 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
1125 if ((Index & 1) == 0) {\r
1126 DataBuffer [Index/2] = DigitUint8;\r
1127 } else {\r
1128 DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);\r
1129 }\r
1130 }\r
1131 }\r
1132\r
1133 //\r
1134 // Convert value for NameValueVar1\r
1135 //\r
1136 if ((Value = StrStr (Configuration, PrivateData->NameValueName[1])) != NULL) {\r
1137 //\r
1138 // Skip "Name="\r
1139 //\r
1140 Value += StrLen (PrivateData->NameValueName[1]);\r
1141 Value++;\r
1142 //\r
1143 // Get Value String\r
1144 //\r
1145 StrPtr = StrStr (Value, L"&");\r
1146 if (StrPtr == NULL) {\r
1147 StrPtr = Value + StrLen (Value);\r
1148 }\r
1149 //\r
1150 // Convert Value to Buffer data\r
1151 //\r
1152 DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar1;\r
1153 ZeroMem (TemStr, sizeof (TemStr));\r
1154 for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {\r
1155 TemStr[0] = *StrPtr;\r
1156 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
1157 if ((Index & 1) == 0) {\r
1158 DataBuffer [Index/2] = DigitUint8;\r
1159 } else {\r
1160 DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);\r
1161 }\r
1162 }\r
1163 }\r
1164\r
1165 //\r
1166 // Convert value for NameValueVar2\r
1167 //\r
1168 if ((Value = StrStr (Configuration, PrivateData->NameValueName[2])) != NULL) {\r
1169 //\r
1170 // Skip "Name="\r
1171 //\r
1172 Value += StrLen (PrivateData->NameValueName[2]);\r
1173 Value++;\r
1174 //\r
1175 // Get Value String\r
1176 //\r
1177 StrPtr = StrStr (Value, L"&");\r
1178 if (StrPtr == NULL) {\r
1179 StrPtr = Value + StrLen (Value);\r
1180 }\r
1181 //\r
1182 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"\r
1183 //\r
1184 StrBuffer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;\r
1185 ZeroMem (TemStr, sizeof (TemStr));\r
1186 while (Value < StrPtr) {\r
1187 StrnCpy (TemStr, Value, 4);\r
1188 *(StrBuffer++) = (CHAR16) StrHexToUint64 (TemStr);\r
1189 Value += 4;\r
1190 }\r
1191 *StrBuffer = L'\0';\r
1192 }\r
1193\r
1194 //\r
1195 // Store Buffer Storage back to EFI variable\r
1196 //\r
1197 Status = gRT->SetVariable(\r
1198 VariableName,\r
c8ad2d7a 1199 &gDriverSampleFormSetGuid,\r
38ebfecb
LG
1200 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
1201 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
1202 &PrivateData->Configuration\r
1203 );\r
1204\r
1205 return Status;\r
1206 }\r
1207\r
93e3992d 1208 //\r
1209 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()\r
1210 //\r
1211 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
1212 Status = HiiConfigRouting->ConfigToBlock (\r
1213 HiiConfigRouting,\r
1214 Configuration,\r
1215 (UINT8 *) &PrivateData->Configuration,\r
1216 &BufferSize,\r
1217 Progress\r
1218 );\r
1219 if (EFI_ERROR (Status)) {\r
1220 return Status;\r
1221 }\r
1222\r
1223 //\r
1224 // Store Buffer Storage back to EFI variable\r
1225 //\r
1226 Status = gRT->SetVariable(\r
1227 VariableName,\r
c8ad2d7a 1228 &gDriverSampleFormSetGuid,\r
93e3992d 1229 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
1230 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
1231 &PrivateData->Configuration\r
1232 );\r
1233\r
1234 return Status;\r
1235}\r
1236\r
1237\r
1238/**\r
1239 This function processes the results of changes in configuration.\r
1240\r
1241 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
1242 @param Action Specifies the type of action taken by the browser.\r
1243 @param QuestionId A unique value which is sent to the original\r
1244 exporting driver so that it can identify the type\r
1245 of data to expect.\r
1246 @param Type The type of value for the question.\r
1247 @param Value A pointer to the data being sent to the original\r
1248 exporting driver.\r
1249 @param ActionRequest On return, points to the action requested by the\r
1250 callback function.\r
1251\r
1252 @retval EFI_SUCCESS The callback successfully handled the action.\r
1253 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
1254 variable and its data.\r
1255 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
1256 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
1257 callback.\r
1258\r
1259**/\r
1260EFI_STATUS\r
1261EFIAPI\r
1262DriverCallback (\r
1263 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
1264 IN EFI_BROWSER_ACTION Action,\r
1265 IN EFI_QUESTION_ID QuestionId,\r
1266 IN UINT8 Type,\r
1267 IN EFI_IFR_TYPE_VALUE *Value,\r
1268 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
1269 )\r
1270{\r
1271 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;\r
1272 EFI_STATUS Status;\r
7e3bcccb
LG
1273 VOID *StartOpCodeHandle;\r
1274 VOID *OptionsOpCodeHandle;\r
1275 EFI_IFR_GUID_LABEL *StartLabel;\r
1276 VOID *EndOpCodeHandle;\r
1277 EFI_IFR_GUID_LABEL *EndLabel;\r
a6973cff 1278 EFI_INPUT_KEY Key;\r
1279 DRIVER_SAMPLE_CONFIGURATION *Configuration;\r
78c2b9a3 1280 MY_EFI_VARSTORE_DATA *EfiData;\r
211cc6e5 1281 EFI_FORM_ID FormId;\r
4a22b9bc
ED
1282 \r
1283 if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||\r
1284 (ActionRequest == NULL)) {\r
1285 return EFI_INVALID_PARAMETER;\r
1286 }\r
a6973cff 1287\r
a6973cff 1288\r
211cc6e5 1289 FormId = 0;\r
4a22b9bc
ED
1290 Status = EFI_SUCCESS;\r
1291 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
1292\r
1293 switch (Action) {\r
1294 case EFI_BROWSER_ACTION_FORM_OPEN:\r
1295 {\r
1296 if (QuestionId == 0x1234) {\r
1297 //\r
1298 // Sample CallBack for UEFI FORM_OPEN action:\r
1299 // Add Save action into Form 3 when Form 1 is opened.\r
1300 // This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.\r
1301 //\r
1302 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
1303\r
1304 //\r
1305 // Initialize the container for dynamic opcodes\r
1306 //\r
1307 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1308 ASSERT (StartOpCodeHandle != NULL);\r
1309\r
1310 //\r
1311 // Create Hii Extend Label OpCode as the start opcode\r
1312 //\r
1313 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1314 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1315 StartLabel->Number = LABEL_UPDATE2;\r
1316\r
1317 HiiCreateActionOpCode (\r
1318 StartOpCodeHandle, // Container for dynamic created opcodes\r
1319 0x1238, // Question ID\r
1320 STRING_TOKEN(STR_SAVE_TEXT), // Prompt text\r
1321 STRING_TOKEN(STR_SAVE_TEXT), // Help text\r
1322 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1323 0 // Action String ID\r
1324 );\r
1325\r
1326 HiiUpdateForm (\r
1327 PrivateData->HiiHandle[0], // HII handle\r
c8ad2d7a 1328 &gDriverSampleFormSetGuid, // Formset GUID\r
4a22b9bc
ED
1329 0x3, // Form ID\r
1330 StartOpCodeHandle, // Label for where to insert opcodes\r
1331 NULL // Insert data\r
1332 );\r
1333\r
1334 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1335 }\r
211cc6e5
ED
1336\r
1337 if (QuestionId == 0x1247) {\r
1338 Status = InternalStartMonitor ();\r
1339 ASSERT_EFI_ERROR (Status);\r
1340 }\r
4a22b9bc
ED
1341 }\r
1342 break;\r
1343\r
1344 case EFI_BROWSER_ACTION_FORM_CLOSE:\r
1345 {\r
1346 if (QuestionId == 0x5678) {\r
1347 //\r
1348 // Sample CallBack for UEFI FORM_CLOSE action:\r
1349 // Show up a pop-up to specify Form 3 will be closed when exit Form 3.\r
1350 //\r
1351 do {\r
1352 CreatePopUp (\r
1353 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1354 &Key,\r
1355 L"",\r
1356 L"You are going to leave third Form!",\r
1357 L"Press ESC or ENTER to continue ...",\r
1358 L"",\r
1359 NULL\r
1360 );\r
1361 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1362 }\r
211cc6e5
ED
1363\r
1364 if (QuestionId == 0x1247) {\r
1365 Status = InternalStopMonitor ();\r
1366 ASSERT_EFI_ERROR (Status);\r
1367 }\r
4a22b9bc
ED
1368 }\r
1369 break;\r
1370 \r
1371 case EFI_BROWSER_ACTION_RETRIEVE:\r
1372 {\r
78c2b9a3
ED
1373 if (QuestionId == 0x1248) {\r
1374 {\r
1375 if (Type != EFI_IFR_TYPE_REF) {\r
1376 return EFI_INVALID_PARAMETER;\r
1377 }\r
1378 \r
1379 Value->ref.FormId = 0x3;\r
1380 }\r
4a22b9bc
ED
1381 }\r
1382 }\r
1383 break;\r
1384\r
ee31d1be
ED
1385 case EFI_BROWSER_ACTION_DEFAULT_STANDARD:\r
1386 {\r
1387 switch (QuestionId) {\r
1388 case 0x1240:\r
1389 Value->u8 = DEFAULT_CLASS_STANDARD_VALUE;\r
1390 break;\r
1391\r
1392 default:\r
1393 Status = EFI_UNSUPPORTED;\r
1394 break;\r
1395 }\r
1396 }\r
1397 break;\r
1398\r
1399 case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING:\r
1400 {\r
1401 switch (QuestionId) {\r
1402 case 0x1240:\r
1403 Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE;\r
1404 break;\r
1405\r
1406 default:\r
1407 Status = EFI_UNSUPPORTED; \r
1408 break;\r
1409 }\r
1410 }\r
1411 break;\r
1412\r
4a22b9bc
ED
1413 case EFI_BROWSER_ACTION_CHANGING:\r
1414 {\r
1415 switch (QuestionId) {\r
78c2b9a3
ED
1416 case 0x1249:\r
1417 {\r
1418 if (Type != EFI_IFR_TYPE_REF) {\r
1419 return EFI_INVALID_PARAMETER;\r
1420 }\r
1421\r
1422 Value->ref.FormId = 0x1234;\r
1423 }\r
1424 break;\r
4a22b9bc 1425 case 0x1234:\r
5adb8db7
LG
1426 //\r
1427 // Initialize the container for dynamic opcodes\r
1428 //\r
1429 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1430 ASSERT (StartOpCodeHandle != NULL);\r
a6973cff 1431\r
4a22b9bc
ED
1432 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1433 ASSERT (EndOpCodeHandle != NULL);\r
1434\r
5adb8db7
LG
1435 //\r
1436 // Create Hii Extend Label OpCode as the start opcode\r
1437 //\r
1438 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1439 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
4a22b9bc
ED
1440 StartLabel->Number = LABEL_UPDATE1;\r
1441\r
1442 //\r
1443 // Create Hii Extend Label OpCode as the end opcode\r
1444 //\r
1445 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1446 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1447 EndLabel->Number = LABEL_END;\r
5adb8db7
LG
1448\r
1449 HiiCreateActionOpCode (\r
1450 StartOpCodeHandle, // Container for dynamic created opcodes\r
4a22b9bc
ED
1451 0x1237, // Question ID\r
1452 STRING_TOKEN(STR_EXIT_TEXT), // Prompt text\r
1453 STRING_TOKEN(STR_EXIT_TEXT), // Help text\r
5adb8db7
LG
1454 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1455 0 // Action String ID\r
a6973cff 1456 );\r
1457\r
4a22b9bc
ED
1458 //\r
1459 // Create Option OpCode\r
1460 //\r
1461 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1462 ASSERT (OptionsOpCodeHandle != NULL);\r
1463\r
1464 HiiCreateOneOfOptionOpCode (\r
1465 OptionsOpCodeHandle,\r
1466 STRING_TOKEN (STR_BOOT_OPTION1),\r
1467 0,\r
1468 EFI_IFR_NUMERIC_SIZE_1,\r
1469 1\r
5adb8db7
LG
1470 );\r
1471\r
4a22b9bc
ED
1472 HiiCreateOneOfOptionOpCode (\r
1473 OptionsOpCodeHandle,\r
1474 STRING_TOKEN (STR_BOOT_OPTION2),\r
1475 0,\r
1476 EFI_IFR_NUMERIC_SIZE_1,\r
1477 2\r
1478 );\r
1479\r
1480 //\r
1481 // Prepare initial value for the dynamic created oneof Question\r
1482 //\r
1483 PrivateData->Configuration.DynamicOneof = 2;\r
1484 Status = gRT->SetVariable(\r
1485 VariableName,\r
c8ad2d7a 1486 &gDriverSampleFormSetGuid,\r
4a22b9bc
ED
1487 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
1488 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
1489 &PrivateData->Configuration\r
1490 );\r
a6973cff 1491\r
5adb8db7 1492 //\r
4a22b9bc 1493 // Set initial vlaue of dynamic created oneof Question in Form Browser\r
5adb8db7 1494 //\r
4a22b9bc
ED
1495 Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
1496 ASSERT (Configuration != NULL);\r
c8ad2d7a 1497 if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
4a22b9bc
ED
1498 Configuration->DynamicOneof = 2;\r
1499\r
1500 //\r
1501 // Update uncommitted data of Browser\r
1502 //\r
1503 HiiSetBrowserData (\r
c8ad2d7a 1504 &gDriverSampleFormSetGuid,\r
4a22b9bc
ED
1505 VariableName,\r
1506 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
1507 (UINT8 *) Configuration,\r
5adb8db7
LG
1508 NULL\r
1509 );\r
4a22b9bc
ED
1510 }\r
1511 FreePool (Configuration);\r
1512\r
1513 HiiCreateOneOfOpCode (\r
1514 StartOpCodeHandle, // Container for dynamic created opcodes\r
1515 0x8001, // Question ID (or call it "key")\r
1516 CONFIGURATION_VARSTORE_ID, // VarStore ID\r
1517 (UINT16) DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage\r
1518 STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text\r
1519 STRING_TOKEN (STR_ONE_OF_HELP), // Question help text\r
1520 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1521 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value\r
1522 OptionsOpCodeHandle, // Option Opcode list\r
1523 NULL // Default Opcode is NULl\r
1524 );\r
7e3bcccb 1525\r
4a22b9bc
ED
1526 HiiCreateOrderedListOpCode (\r
1527 StartOpCodeHandle, // Container for dynamic created opcodes\r
1528 0x8002, // Question ID\r
1529 CONFIGURATION_VARSTORE_ID, // VarStore ID\r
1530 (UINT16) DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage\r
1531 STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text\r
1532 STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text\r
1533 EFI_IFR_FLAG_RESET_REQUIRED, // Question flag\r
1534 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET\r
1535 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value\r
1536 5, // Maximum container\r
1537 OptionsOpCodeHandle, // Option Opcode list\r
1538 NULL // Default Opcode is NULl\r
1539 );\r
7e3bcccb 1540\r
4a22b9bc
ED
1541 HiiCreateTextOpCode (\r
1542 StartOpCodeHandle,\r
1543 STRING_TOKEN(STR_TEXT_SAMPLE_HELP),\r
1544 STRING_TOKEN(STR_TEXT_SAMPLE_HELP),\r
1545 STRING_TOKEN(STR_TEXT_SAMPLE_STRING)\r
7e3bcccb
LG
1546 );\r
1547\r
4a22b9bc
ED
1548 HiiCreateDateOpCode (\r
1549 StartOpCodeHandle,\r
1550 0x8004,\r
1551 0x0,\r
1552 0x0,\r
1553 STRING_TOKEN(STR_DATE_SAMPLE_HELP),\r
1554 STRING_TOKEN(STR_DATE_SAMPLE_HELP),\r
1555 0,\r
1556 QF_DATE_STORAGE_TIME,\r
1557 NULL\r
1558 );\r
7e3bcccb 1559\r
4a22b9bc
ED
1560 HiiCreateTimeOpCode (\r
1561 StartOpCodeHandle,\r
1562 0x8005,\r
1563 0x0,\r
1564 0x0,\r
1565 STRING_TOKEN(STR_TIME_SAMPLE_HELP),\r
1566 STRING_TOKEN(STR_TIME_SAMPLE_HELP),\r
1567 0,\r
1568 QF_TIME_STORAGE_TIME,\r
1569 NULL\r
1570 );\r
7e3bcccb 1571\r
4a22b9bc
ED
1572 HiiCreateGotoOpCode (\r
1573 StartOpCodeHandle, // Container for dynamic created opcodes\r
1574 1, // Target Form ID\r
1575 STRING_TOKEN (STR_GOTO_FORM1), // Prompt text\r
1576 STRING_TOKEN (STR_GOTO_HELP), // Help text\r
1577 0, // Question flag\r
1578 0x8003 // Question ID\r
1579 );\r
a6973cff 1580\r
4a22b9bc
ED
1581 HiiUpdateForm (\r
1582 PrivateData->HiiHandle[0], // HII handle\r
c8ad2d7a 1583 &gDriverSampleFormSetGuid, // Formset GUID\r
4a22b9bc
ED
1584 0x1234, // Form ID\r
1585 StartOpCodeHandle, // Label for where to insert opcodes\r
1586 EndOpCodeHandle // Replace data\r
a6973cff 1587 );\r
7e3bcccb 1588\r
4a22b9bc
ED
1589 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1590 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1591 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1592 break;\r
7e3bcccb 1593\r
4a22b9bc 1594 case 0x5678:\r
211cc6e5 1595 case 0x1247:\r
4a22b9bc
ED
1596 //\r
1597 // We will reach here once the Question is refreshed\r
1598 //\r
5adb8db7 1599\r
4a22b9bc
ED
1600 //\r
1601 // Initialize the container for dynamic opcodes\r
1602 //\r
1603 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1604 ASSERT (StartOpCodeHandle != NULL);\r
5adb8db7 1605\r
4a22b9bc
ED
1606 //\r
1607 // Create Hii Extend Label OpCode as the start opcode\r
1608 //\r
1609 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1610 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
211cc6e5
ED
1611 if (QuestionId == 0x5678) {\r
1612 StartLabel->Number = LABEL_UPDATE2;\r
1613 FormId = 0x03;\r
1614 PrivateData->Configuration.DynamicRefresh++;\r
1615 } else if (QuestionId == 0x1247 ) {\r
1616 StartLabel->Number = LABEL_UPDATE3;\r
78c2b9a3 1617 FormId = 0x06;\r
211cc6e5
ED
1618 PrivateData->Configuration.RefreshGuidCount++;\r
1619 }\r
7e3bcccb 1620\r
4a22b9bc
ED
1621 HiiCreateActionOpCode (\r
1622 StartOpCodeHandle, // Container for dynamic created opcodes\r
1623 0x1237, // Question ID\r
1624 STRING_TOKEN(STR_EXIT_TEXT), // Prompt text\r
1625 STRING_TOKEN(STR_EXIT_TEXT), // Help text\r
1626 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1627 0 // Action String ID\r
7e3bcccb
LG
1628 );\r
1629\r
4a22b9bc
ED
1630 HiiUpdateForm (\r
1631 PrivateData->HiiHandle[0], // HII handle\r
c8ad2d7a 1632 &gDriverSampleFormSetGuid, // Formset GUID\r
211cc6e5 1633 FormId, // Form ID\r
4a22b9bc
ED
1634 StartOpCodeHandle, // Label for where to insert opcodes\r
1635 NULL // Insert data\r
1636 );\r
7e3bcccb 1637\r
4a22b9bc 1638 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
7e3bcccb 1639\r
4a22b9bc
ED
1640 //\r
1641 // Refresh the Question value\r
1642 //\r
4a22b9bc
ED
1643 Status = gRT->SetVariable(\r
1644 VariableName,\r
c8ad2d7a 1645 &gDriverSampleFormSetGuid,\r
4a22b9bc
ED
1646 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
1647 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
1648 &PrivateData->Configuration\r
1649 );\r
7e3bcccb 1650\r
211cc6e5
ED
1651 if (QuestionId == 0x5678) {\r
1652 //\r
78c2b9a3 1653 // Update uncommitted data of Browser\r
211cc6e5 1654 //\r
78c2b9a3
ED
1655 EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));\r
1656 ASSERT (EfiData != NULL);\r
c8ad2d7a 1657 if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *) EfiData)) {\r
78c2b9a3
ED
1658 EfiData->Field8 = 111;\r
1659 HiiSetBrowserData (\r
c8ad2d7a 1660 &gDriverSampleFormSetGuid,\r
78c2b9a3
ED
1661 MyEfiVar,\r
1662 sizeof (MY_EFI_VARSTORE_DATA),\r
1663 (UINT8 *) EfiData,\r
1664 NULL\r
1665 );\r
1666 }\r
1667 FreePool (EfiData);\r
211cc6e5 1668 }\r
4a22b9bc 1669 break;\r
a6973cff 1670\r
4a22b9bc
ED
1671 case 0x2000:\r
1672 //\r
1673 // Only used to update the state.\r
1674 //\r
1675 if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0) && \r
1676 (PrivateData->PasswordState == BROWSER_STATE_SET_PASSWORD)) {\r
1677 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;\r
1678 return EFI_INVALID_PARAMETER;\r
1679 }\r
93e3992d 1680\r
4a22b9bc
ED
1681 //\r
1682 // When try to set a new password, user will be chanlleged with old password.\r
1683 // The Callback is responsible for validating old password input by user,\r
1684 // If Callback return EFI_SUCCESS, it indicates validation pass.\r
1685 //\r
1686 switch (PrivateData->PasswordState) {\r
1687 case BROWSER_STATE_VALIDATE_PASSWORD:\r
1688 Status = ValidatePassword (PrivateData, Value->string);\r
1689 if (Status == EFI_SUCCESS) {\r
1690 PrivateData->PasswordState = BROWSER_STATE_SET_PASSWORD;\r
1691 }\r
1692 break;\r
93e3992d 1693\r
4a22b9bc
ED
1694 case BROWSER_STATE_SET_PASSWORD:\r
1695 Status = SetPassword (PrivateData, Value->string);\r
1696 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;\r
1697 break;\r
e2100bfa 1698\r
4a22b9bc
ED
1699 default:\r
1700 break;\r
93e3992d 1701 }\r
93e3992d 1702\r
93e3992d 1703 break;\r
1704\r
1705 default:\r
1706 break;\r
1707 }\r
4a22b9bc
ED
1708 }\r
1709 break;\r
93e3992d 1710\r
3a4e7a3e
ED
1711 case EFI_BROWSER_ACTION_CHANGED:\r
1712 switch (QuestionId) {\r
1713 case 0x1237:\r
1714 //\r
1715 // User press "Exit now", request Browser to exit\r
1716 //\r
1717 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
1718 break;\r
1719 \r
1720 case 0x1238:\r
1721 //\r
1722 // User press "Save now", request Browser to save the uncommitted data.\r
1723 //\r
1724 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
1725 break;\r
1726 \r
1727 case 0x1241:\r
1728 case 0x1246:\r
1729 //\r
1730 // User press "Submit current form and Exit now", request Browser to submit current form and exit\r
1731 //\r
1732 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
1733 break;\r
1734 \r
1735 case 0x1242:\r
1736 //\r
1737 // User press "Discard current form now", request Browser to discard the uncommitted data.\r
1738 //\r
1739 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;\r
1740 break;\r
1741 \r
1742 case 0x1243:\r
1743 //\r
1744 // User press "Submit current form now", request Browser to save the uncommitted data.\r
1745 //\r
1746 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
1747 break;\r
1748 \r
1749 case 0x1244:\r
1750 case 0x1245:\r
1751 //\r
1752 // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.\r
1753 //\r
1754 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
1755 break;\r
1756 \r
1757 default:\r
1758 break;\r
1759 }\r
1760 break;\r
1761\r
93e3992d 1762 default:\r
4a22b9bc 1763 Status = EFI_UNSUPPORTED;\r
93e3992d 1764 break;\r
1765 }\r
1766\r
1767 return Status;\r
1768}\r
1769\r
7064c0a5 1770/**\r
1771 Main entry for this driver.\r
a6973cff 1772\r
7064c0a5 1773 @param ImageHandle Image handle this driver.\r
1774 @param SystemTable Pointer to SystemTable.\r
1775\r
1776 @retval EFI_SUCESS This function always complete successfully.\r
1777\r
1778**/\r
93e3992d 1779EFI_STATUS\r
1780EFIAPI\r
1781DriverSampleInit (\r
1782 IN EFI_HANDLE ImageHandle,\r
1783 IN EFI_SYSTEM_TABLE *SystemTable\r
1784 )\r
1785{\r
1786 EFI_STATUS Status;\r
93e3992d 1787 EFI_HII_HANDLE HiiHandle[2];\r
93e3992d 1788 EFI_SCREEN_DESCRIPTOR Screen;\r
1789 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
1790 EFI_HII_STRING_PROTOCOL *HiiString;\r
1791 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;\r
1792 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
1793 CHAR16 *NewString;\r
1794 UINTN BufferSize;\r
1795 DRIVER_SAMPLE_CONFIGURATION *Configuration;\r
84f9a9ec 1796 BOOLEAN ActionFlag;\r
a6973cff 1797 EFI_STRING ConfigRequestHdr;\r
82e8c138 1798 EFI_STRING NameRequestHdr;\r
78c2b9a3 1799 MY_EFI_VARSTORE_DATA *VarStoreConfig;\r
2b826e21
LG
1800 EFI_INPUT_KEY HotKey;\r
1801 EFI_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;\r
a6973cff 1802\r
93e3992d 1803 //\r
84f9a9ec 1804 // Initialize the local variables.\r
93e3992d 1805 //\r
84f9a9ec 1806 ConfigRequestHdr = NULL;\r
33efdf51
ED
1807 NewString = NULL;\r
1808\r
93e3992d 1809 //\r
1810 // Initialize screen dimensions for SendForm().\r
1811 // Remove 3 characters from top and bottom\r
1812 //\r
1813 ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));\r
1814 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);\r
1815\r
1816 Screen.TopRow = 3;\r
1817 Screen.BottomRow = Screen.BottomRow - 3;\r
1818\r
1819 //\r
1820 // Initialize driver private data\r
1821 //\r
ccee6099 1822 PrivateData = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));\r
93e3992d 1823 if (PrivateData == NULL) {\r
1824 return EFI_OUT_OF_RESOURCES;\r
1825 }\r
1826\r
1827 PrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;\r
1828\r
1829 PrivateData->ConfigAccess.ExtractConfig = ExtractConfig;\r
1830 PrivateData->ConfigAccess.RouteConfig = RouteConfig;\r
1831 PrivateData->ConfigAccess.Callback = DriverCallback;\r
1832 PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;\r
1833\r
1834 //\r
1835 // Locate Hii Database protocol\r
1836 //\r
1837 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase);\r
1838 if (EFI_ERROR (Status)) {\r
1839 return Status;\r
1840 }\r
1841 PrivateData->HiiDatabase = HiiDatabase;\r
1842\r
1843 //\r
1844 // Locate HiiString protocol\r
1845 //\r
1846 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);\r
1847 if (EFI_ERROR (Status)) {\r
1848 return Status;\r
1849 }\r
1850 PrivateData->HiiString = HiiString;\r
1851\r
1852 //\r
1853 // Locate Formbrowser2 protocol\r
1854 //\r
1855 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);\r
1856 if (EFI_ERROR (Status)) {\r
1857 return Status;\r
1858 }\r
1859 PrivateData->FormBrowser2 = FormBrowser2;\r
1860\r
1861 //\r
1862 // Locate ConfigRouting protocol\r
1863 //\r
1864 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);\r
1865 if (EFI_ERROR (Status)) {\r
1866 return Status;\r
1867 }\r
1868 PrivateData->HiiConfigRouting = HiiConfigRouting;\r
1869\r
f6f910dd 1870 Status = gBS->InstallMultipleProtocolInterfaces (\r
93e3992d 1871 &DriverHandle[0],\r
f6f910dd 1872 &gEfiDevicePathProtocolGuid,\r
2f3065c0 1873 &mHiiVendorDevicePath0,\r
93e3992d 1874 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 1875 &PrivateData->ConfigAccess,\r
1876 NULL\r
93e3992d 1877 );\r
1878 ASSERT_EFI_ERROR (Status);\r
1879\r
f6f910dd 1880 PrivateData->DriverHandle[0] = DriverHandle[0];\r
1881\r
93e3992d 1882 //\r
1883 // Publish our HII data\r
1884 //\r
cb7d01c0 1885 HiiHandle[0] = HiiAddPackages (\r
c8ad2d7a 1886 &gDriverSampleFormSetGuid,\r
cb7d01c0 1887 DriverHandle[0],\r
1888 DriverSampleStrings,\r
1889 VfrBin,\r
1890 NULL\r
1891 );\r
1892 if (HiiHandle[0] == NULL) {\r
93e3992d 1893 return EFI_OUT_OF_RESOURCES;\r
1894 }\r
1895\r
93e3992d 1896 PrivateData->HiiHandle[0] = HiiHandle[0];\r
1897\r
1898 //\r
1899 // Publish another Fromset\r
1900 //\r
f6f910dd 1901 Status = gBS->InstallMultipleProtocolInterfaces (\r
1902 &DriverHandle[1],\r
1903 &gEfiDevicePathProtocolGuid,\r
2f3065c0 1904 &mHiiVendorDevicePath1,\r
f6f910dd 1905 NULL\r
1906 );\r
1907 ASSERT_EFI_ERROR (Status);\r
1908\r
93e3992d 1909 PrivateData->DriverHandle[1] = DriverHandle[1];\r
1910\r
cb7d01c0 1911 HiiHandle[1] = HiiAddPackages (\r
c8ad2d7a 1912 &gDriverSampleInventoryGuid,\r
cb7d01c0 1913 DriverHandle[1],\r
1914 DriverSampleStrings,\r
1915 InventoryBin,\r
1916 NULL\r
1917 );\r
1918 if (HiiHandle[1] == NULL) {\r
38ebfecb 1919 DriverSampleUnload (ImageHandle);\r
93e3992d 1920 return EFI_OUT_OF_RESOURCES;\r
1921 }\r
1922\r
93e3992d 1923 PrivateData->HiiHandle[1] = HiiHandle[1];\r
1924\r
b204f2b5
ED
1925 //\r
1926 // Update the device path string.\r
1927 //\r
863986b3 1928 NewString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0, FALSE, FALSE);\r
33efdf51 1929 if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {\r
b204f2b5
ED
1930 DriverSampleUnload (ImageHandle);\r
1931 return EFI_OUT_OF_RESOURCES;\r
1932 }\r
33efdf51
ED
1933 if (NewString != NULL) {\r
1934 FreePool (NewString);\r
1935 }\r
1936\r
93e3992d 1937 //\r
1938 // Very simple example of how one would update a string that is already\r
1939 // in the HII database\r
1940 //\r
1941 NewString = L"700 Mhz";\r
1942\r
cb7d01c0 1943 if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {\r
38ebfecb 1944 DriverSampleUnload (ImageHandle);\r
cb7d01c0 1945 return EFI_OUT_OF_RESOURCES;\r
93e3992d 1946 }\r
1947\r
38ebfecb
LG
1948 HiiSetString (HiiHandle[0], 0, NewString, NULL);\r
1949\r
1950 //\r
1951 // Initialize Name/Value name String ID\r
1952 //\r
1953 PrivateData->NameStringId[0] = STR_NAME_VALUE_VAR_NAME0;\r
1954 PrivateData->NameStringId[1] = STR_NAME_VALUE_VAR_NAME1;\r
1955 PrivateData->NameStringId[2] = STR_NAME_VALUE_VAR_NAME2;\r
1956\r
93e3992d 1957 //\r
1958 // Initialize configuration data\r
1959 //\r
1960 Configuration = &PrivateData->Configuration;\r
1961 ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
1962\r
1963 //\r
1964 // Try to read NV config EFI variable first\r
1965 //\r
c8ad2d7a 1966 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);\r
84f9a9ec
LG
1967 ASSERT (ConfigRequestHdr != NULL);\r
1968\r
82e8c138
ED
1969 NameRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, NULL, DriverHandle[0]);\r
1970 ASSERT (NameRequestHdr != NULL);\r
1971\r
93e3992d 1972 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
c8ad2d7a 1973 Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);\r
84f9a9ec 1974 if (EFI_ERROR (Status)) {\r
04da0b4a
LG
1975 //\r
1976 // Store zero data Buffer Storage to EFI variable\r
1977 //\r
1978 Status = gRT->SetVariable(\r
1979 VariableName,\r
c8ad2d7a 1980 &gDriverSampleFormSetGuid,\r
04da0b4a
LG
1981 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
1982 sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
1983 Configuration\r
1984 );\r
2c775600
ED
1985 if (EFI_ERROR (Status)) {\r
1986 DriverSampleUnload (ImageHandle);\r
1987 return Status;\r
1988 }\r
93e3992d 1989 //\r
1990 // EFI variable for NV config doesn't exit, we should build this variable\r
1991 // based on default values stored in IFR\r
1992 //\r
82e8c138 1993 ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
2c775600
ED
1994 if (!ActionFlag) {\r
1995 DriverSampleUnload (ImageHandle);\r
1996 return EFI_INVALID_PARAMETER;\r
1997 }\r
82e8c138 1998\r
84f9a9ec 1999 ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
2c775600
ED
2000 if (!ActionFlag) {\r
2001 DriverSampleUnload (ImageHandle);\r
2002 return EFI_INVALID_PARAMETER;\r
2003 }\r
84f9a9ec
LG
2004 } else {\r
2005 //\r
2006 // EFI variable does exist and Validate Current Setting\r
2007 //\r
82e8c138 2008 ActionFlag = HiiValidateSettings (NameRequestHdr);\r
2c775600
ED
2009 if (!ActionFlag) {\r
2010 DriverSampleUnload (ImageHandle);\r
2011 return EFI_INVALID_PARAMETER;\r
2012 }\r
82e8c138 2013\r
84f9a9ec 2014 ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
2c775600
ED
2015 if (!ActionFlag) {\r
2016 DriverSampleUnload (ImageHandle);\r
2017 return EFI_INVALID_PARAMETER;\r
2018 }\r
93e3992d 2019 }\r
78c2b9a3 2020 FreePool (ConfigRequestHdr);\r
a6973cff 2021\r
78c2b9a3
ED
2022 //\r
2023 // Initialize efi varstore configuration data\r
2024 //\r
2025 VarStoreConfig = &PrivateData->VarStoreConfig;\r
2026 ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));\r
2027\r
c8ad2d7a 2028 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);\r
78c2b9a3
ED
2029 ASSERT (ConfigRequestHdr != NULL);\r
2030\r
2031 BufferSize = sizeof (MY_EFI_VARSTORE_DATA);\r
c8ad2d7a 2032 Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);\r
78c2b9a3
ED
2033 if (EFI_ERROR (Status)) {\r
2034 //\r
2035 // Store zero data to EFI variable Storage.\r
2036 //\r
2037 Status = gRT->SetVariable(\r
2038 MyEfiVar,\r
c8ad2d7a 2039 &gDriverSampleFormSetGuid,\r
78c2b9a3
ED
2040 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
2041 sizeof (MY_EFI_VARSTORE_DATA),\r
2042 VarStoreConfig\r
2043 );\r
2c775600
ED
2044 if (EFI_ERROR (Status)) {\r
2045 DriverSampleUnload (ImageHandle);\r
2046 return Status;\r
2047 }\r
78c2b9a3
ED
2048 //\r
2049 // EFI variable for NV config doesn't exit, we should build this variable\r
2050 // based on default values stored in IFR\r
2051 //\r
2052 ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
2c775600
ED
2053 if (!ActionFlag) {\r
2054 DriverSampleUnload (ImageHandle);\r
2055 return EFI_INVALID_PARAMETER;\r
2056 }\r
78c2b9a3
ED
2057 } else {\r
2058 //\r
2059 // EFI variable does exist and Validate Current Setting\r
2060 //\r
2061 ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
2c775600
ED
2062 if (!ActionFlag) {\r
2063 DriverSampleUnload (ImageHandle);\r
2064 return EFI_INVALID_PARAMETER;\r
2065 }\r
78c2b9a3 2066 }\r
84f9a9ec
LG
2067 FreePool (ConfigRequestHdr);\r
2068\r
211cc6e5
ED
2069 Status = gBS->CreateEventEx (\r
2070 EVT_NOTIFY_SIGNAL, \r
2071 TPL_NOTIFY,\r
2072 DriverSampleInternalEmptyFunction,\r
2073 NULL,\r
c8ad2d7a 2074 &gEfiIfrRefreshIdOpGuid,\r
211cc6e5
ED
2075 &mEvent\r
2076 );\r
2077 ASSERT_EFI_ERROR (Status);\r
2b826e21
LG
2078\r
2079 //\r
2080 // Example of how to use BrowserEx protocol to register HotKey.\r
2081 // \r
2082 Status = gBS->LocateProtocol (&gEfiFormBrowserExProtocolGuid, NULL, (VOID **) &FormBrowserEx);\r
2083 if (!EFI_ERROR (Status)) {\r
2084 //\r
2085 // First unregister the default hot key F9 and F10.\r
2086 //\r
2087 HotKey.UnicodeChar = CHAR_NULL;\r
2088 HotKey.ScanCode = SCAN_F9;\r
2089 FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);\r
2090 HotKey.ScanCode = SCAN_F10;\r
2091 FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);\r
2092 \r
2093 //\r
2094 // Register the default HotKey F9 and F10 again.\r
2095 //\r
2096 HotKey.ScanCode = SCAN_F10;\r
2097 NewString = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL);\r
2098 ASSERT (NewString != NULL);\r
2099 FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);\r
2100 HotKey.ScanCode = SCAN_F9;\r
2101 NewString = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL);\r
2102 ASSERT (NewString != NULL);\r
2103 FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);\r
2104 }\r
2105\r
93e3992d 2106 //\r
a6973cff 2107 // In default, this driver is built into Flash device image,\r
7e3bcccb 2108 // the following code doesn't run.\r
93e3992d 2109 //\r
7e3bcccb 2110\r
2f3065c0 2111 //\r
7e3bcccb 2112 // Example of how to display only the item we sent to HII\r
a6973cff 2113 // When this driver is not built into Flash device image,\r
7e3bcccb 2114 // it need to call SendForm to show front page by itself.\r
2f3065c0 2115 //\r
7e3bcccb
LG
2116 if (DISPLAY_ONLY_MY_ITEM <= 1) {\r
2117 //\r
2118 // Have the browser pull out our copy of the data, and only display our data\r
2119 //\r
2120 Status = FormBrowser2->SendForm (\r
2121 FormBrowser2,\r
2122 &(HiiHandle[DISPLAY_ONLY_MY_ITEM]),\r
2123 1,\r
2124 NULL,\r
2125 0,\r
2126 NULL,\r
2127 NULL\r
2128 );\r
a6973cff 2129\r
14d59fa1 2130 HiiRemovePackages (HiiHandle[0]);\r
a6973cff 2131\r
14d59fa1 2132 HiiRemovePackages (HiiHandle[1]);\r
2f3065c0
LG
2133 }\r
2134\r
84f9a9ec 2135 return EFI_SUCCESS;\r
2f3065c0
LG
2136}\r
2137\r
2138/**\r
2139 Unloads the application and its installed protocol.\r
2140\r
2141 @param[in] ImageHandle Handle that identifies the image to be unloaded.\r
2142\r
2143 @retval EFI_SUCCESS The image has been unloaded.\r
2144**/\r
2145EFI_STATUS\r
2146EFIAPI\r
2147DriverSampleUnload (\r
2148 IN EFI_HANDLE ImageHandle\r
2149 )\r
2150{\r
38ebfecb 2151 UINTN Index;\r
f0c855b2 2152\r
2153 ASSERT (PrivateData != NULL);\r
2154\r
2f3065c0
LG
2155 if (DriverHandle[0] != NULL) {\r
2156 gBS->UninstallMultipleProtocolInterfaces (\r
2157 DriverHandle[0],\r
2158 &gEfiDevicePathProtocolGuid,\r
2159 &mHiiVendorDevicePath0,\r
2160 &gEfiHiiConfigAccessProtocolGuid,\r
2161 &PrivateData->ConfigAccess,\r
2162 NULL\r
2163 );\r
ccee6099 2164 DriverHandle[0] = NULL;\r
2f3065c0
LG
2165 }\r
2166\r
2167 if (DriverHandle[1] != NULL) {\r
2168 gBS->UninstallMultipleProtocolInterfaces (\r
2169 DriverHandle[1],\r
2170 &gEfiDevicePathProtocolGuid,\r
2171 &mHiiVendorDevicePath1,\r
2172 NULL\r
2173 );\r
ccee6099 2174 DriverHandle[1] = NULL;\r
2f3065c0
LG
2175 }\r
2176\r
14d59fa1
LG
2177 if (PrivateData->HiiHandle[0] != NULL) {\r
2178 HiiRemovePackages (PrivateData->HiiHandle[0]);\r
2179 }\r
2180\r
2181 if (PrivateData->HiiHandle[1] != NULL) {\r
2182 HiiRemovePackages (PrivateData->HiiHandle[1]);\r
2183 }\r
2184\r
f0c855b2 2185 for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {\r
2186 if (PrivateData->NameValueName[Index] != NULL) {\r
2187 FreePool (PrivateData->NameValueName[Index]);\r
38ebfecb 2188 }\r
93e3992d 2189 }\r
f0c855b2 2190 FreePool (PrivateData);\r
2191 PrivateData = NULL;\r
93e3992d 2192\r
211cc6e5
ED
2193 gBS->CloseEvent (mEvent);\r
2194\r
93e3992d 2195 return EFI_SUCCESS;\r
2196}\r