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