TianoCore EDK2 master
Loading...
Searching...
No Matches
DriverSample.c
Go to the documentation of this file.
1
10#include "DriverSample.h"
11
12#define DISPLAY_ONLY_MY_ITEM 0x0002
13
14CHAR16 VariableName[] = L"MyIfrNVData";
15CHAR16 MyEfiVar[] = L"MyEfiVar";
16CHAR16 MyEfiBitVar[] = L"MyEfiBitVar";
17CHAR16 MyEfiUnionVar[] = L"MyEfiUnionVar";
18
19EFI_HANDLE DriverHandle[2] = { NULL, NULL };
20DRIVER_SAMPLE_PRIVATE_DATA *mPrivateData = NULL;
21EFI_EVENT mEvent;
22
23HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {
24 {
25 {
28 {
29 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
30 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
31 }
32 },
33 DRIVER_SAMPLE_FORMSET_GUID
34 },
35 {
36 END_DEVICE_PATH_TYPE,
37 END_ENTIRE_DEVICE_PATH_SUBTYPE,
38 {
39 (UINT8)(END_DEVICE_PATH_LENGTH),
40 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
41 }
42 }
43};
44
45HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
46 {
47 {
50 {
51 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
52 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
53 }
54 },
55 DRIVER_SAMPLE_INVENTORY_GUID
56 },
57 {
58 END_DEVICE_PATH_TYPE,
59 END_ENTIRE_DEVICE_PATH_SUBTYPE,
60 {
61 (UINT8)(END_DEVICE_PATH_LENGTH),
62 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
63 }
64 }
65};
66
76VOID
78 IN VOID *Array,
79 IN UINT8 Type,
80 IN UINTN Index,
81 IN UINT64 Value
82 )
83{
84 ASSERT (Array != NULL);
85
86 switch (Type) {
87 case EFI_IFR_TYPE_NUM_SIZE_8:
88 *(((UINT8 *)Array) + Index) = (UINT8)Value;
89 break;
90
91 case EFI_IFR_TYPE_NUM_SIZE_16:
92 *(((UINT16 *)Array) + Index) = (UINT16)Value;
93 break;
94
95 case EFI_IFR_TYPE_NUM_SIZE_32:
96 *(((UINT32 *)Array) + Index) = (UINT32)Value;
97 break;
98
99 case EFI_IFR_TYPE_NUM_SIZE_64:
100 *(((UINT64 *)Array) + Index) = (UINT64)Value;
101 break;
102
103 default:
104 break;
105 }
106}
107
116EFIAPI
118 IN EFI_KEY_DATA *KeyData
119 )
120{
121 gBS->SignalEvent (mEvent);
122
123 return EFI_SUCCESS;
124}
125
133EFIAPI
135 VOID
136 )
137{
139 EFI_KEY_DATA KeyData;
140 EFI_STATUS Status;
141 EFI_HANDLE *Handles;
142 UINTN HandleCount;
143 UINTN HandleIndex;
144 VOID *NotifyHandle;
145
146 Status = gBS->LocateHandleBuffer (
148 &gEfiSimpleTextInputExProtocolGuid,
149 NULL,
150 &HandleCount,
151 &Handles
152 );
153 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
154 Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **)&SimpleEx);
155 ASSERT_EFI_ERROR (Status);
156
157 KeyData.KeyState.KeyToggleState = 0;
158 KeyData.Key.ScanCode = 0;
159 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
160 KeyData.Key.UnicodeChar = L'c';
161
162 Status = SimpleEx->RegisterKeyNotify (
163 SimpleEx,
164 &KeyData,
166 &NotifyHandle
167 );
168 if (EFI_ERROR (Status)) {
169 break;
170 }
171
172 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
173 Status = SimpleEx->RegisterKeyNotify (
174 SimpleEx,
175 &KeyData,
177 &NotifyHandle
178 );
179 if (EFI_ERROR (Status)) {
180 break;
181 }
182 }
183
184 return EFI_SUCCESS;
185}
186
194EFIAPI
196 VOID
197 )
198{
200 EFI_STATUS Status;
201 EFI_HANDLE *Handles;
202 EFI_KEY_DATA KeyData;
203 UINTN HandleCount;
204 UINTN HandleIndex;
205 VOID *NotifyHandle;
206
207 Status = gBS->LocateHandleBuffer (
209 &gEfiSimpleTextInputExProtocolGuid,
210 NULL,
211 &HandleCount,
212 &Handles
213 );
214 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
215 Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **)&SimpleEx);
216 ASSERT_EFI_ERROR (Status);
217
218 KeyData.KeyState.KeyToggleState = 0;
219 KeyData.Key.ScanCode = 0;
220 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
221 KeyData.Key.UnicodeChar = L'c';
222
223 Status = SimpleEx->RegisterKeyNotify (
224 SimpleEx,
225 &KeyData,
227 &NotifyHandle
228 );
229 if (!EFI_ERROR (Status)) {
230 Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
231 }
232
233 KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
234 Status = SimpleEx->RegisterKeyNotify (
235 SimpleEx,
236 &KeyData,
238 &NotifyHandle
239 );
240 if (!EFI_ERROR (Status)) {
241 Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
242 }
243 }
244
245 return EFI_SUCCESS;
246}
247
259 IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData
260 )
261{
262 UINTN Index;
263
264 //
265 // Get Name/Value name string of current language
266 //
267 for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
268 PrivateData->NameValueName[Index] = HiiGetString (
269 PrivateData->HiiHandle[0],
270 PrivateData->NameStringId[Index],
271 NULL
272 );
273 if (PrivateData->NameValueName[Index] == NULL) {
274 return EFI_NOT_FOUND;
275 }
276 }
277
278 return EFI_SUCCESS;
279}
280
302 IN EFI_STRING StringPtr,
303 OUT UINT8 **Number,
304 OUT UINTN *Len
305 )
306{
307 EFI_STRING TmpPtr;
308 UINTN Length;
309 EFI_STRING Str;
310 UINT8 *Buf;
311 EFI_STATUS Status;
312 UINT8 DigitUint8;
313 UINTN Index;
314 CHAR16 TemStr[2];
315
316 if ((StringPtr == NULL) || (*StringPtr == L'\0') || (Number == NULL) || (Len == NULL)) {
317 return EFI_INVALID_PARAMETER;
318 }
319
320 Buf = NULL;
321
322 TmpPtr = StringPtr;
323 while (*StringPtr != L'\0' && *StringPtr != L'&') {
324 StringPtr++;
325 }
326
327 *Len = StringPtr - TmpPtr;
328 Length = *Len + 1;
329
330 Str = (EFI_STRING)AllocateZeroPool (Length * sizeof (CHAR16));
331 if (Str == NULL) {
332 Status = EFI_OUT_OF_RESOURCES;
333 goto Exit;
334 }
335
336 CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));
337 *(Str + *Len) = L'\0';
338
339 Length = (Length + 1) / 2;
340 Buf = (UINT8 *)AllocateZeroPool (Length);
341 if (Buf == NULL) {
342 Status = EFI_OUT_OF_RESOURCES;
343 goto Exit;
344 }
345
346 Length = *Len;
347 ZeroMem (TemStr, sizeof (TemStr));
348 for (Index = 0; Index < Length; Index++) {
349 TemStr[0] = Str[Length - Index - 1];
350 DigitUint8 = (UINT8)StrHexToUint64 (TemStr);
351 if ((Index & 1) == 0) {
352 Buf[Index/2] = DigitUint8;
353 } else {
354 Buf[Index/2] = (UINT8)((DigitUint8 << 4) + Buf[Index/2]);
355 }
356 }
357
358 *Number = Buf;
359 Status = EFI_SUCCESS;
360
361Exit:
362 if (Str != NULL) {
363 FreePool (Str);
364 }
365
366 return Status;
367}
368
380EFI_STRING
382 IN EFI_STRING Result,
383 IN EFI_STRING ConfigHdr,
384 IN UINTN Offset,
385 IN UINTN Width
386 )
387{
388 EFI_STRING StringPtr;
389 EFI_STRING TmpStr;
390 UINTN NewLen;
391
392 NewLen = StrLen (Result);
393 //
394 // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
395 //
396 NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);
397 StringPtr = AllocateZeroPool (NewLen);
398 if (StringPtr == NULL) {
399 return NULL;
400 }
401
402 TmpStr = StringPtr;
403 if (Result != NULL) {
404 StrCpyS (StringPtr, NewLen / sizeof (CHAR16), Result);
405 StringPtr += StrLen (Result);
406 FreePool (Result);
407 }
408
410 StringPtr,
411 (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
412 L"&%s&ALTCFG=%04x",
413 ConfigHdr,
414 EFI_HII_DEFAULT_CLASS_STANDARD
415 );
416 StringPtr += StrLen (StringPtr);
417
419 StringPtr,
420 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
421 L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
422 Offset,
423 Width,
424 DEFAULT_CLASS_STANDARD_VALUE
425 );
426 StringPtr += StrLen (StringPtr);
427
429 StringPtr,
430 (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
431 L"&%s&ALTCFG=%04x",
432 ConfigHdr,
433 EFI_HII_DEFAULT_CLASS_MANUFACTURING
434 );
435 StringPtr += StrLen (StringPtr);
436
438 StringPtr,
439 (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
440 L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
441 Offset,
442 Width,
443 DEFAULT_CLASS_MANUFACTURING_VALUE
444 );
445 StringPtr += StrLen (StringPtr);
446
447 return TmpStr;
448}
449
458VOID
460 IN OUT EFI_STRING *RequestResult,
461 IN EFI_STRING ConfigRequestHdr
462 )
463{
464 EFI_STRING StringPtr;
465 UINTN Length;
466 UINT8 *TmpBuffer;
467 UINTN Offset;
468 UINTN Width;
469 UINTN BlockSize;
470 UINTN ValueOffset;
471 UINTN ValueWidth;
472 EFI_STATUS Status;
473
474 TmpBuffer = NULL;
475 StringPtr = *RequestResult;
476 StringPtr = StrStr (StringPtr, L"OFFSET");
477 BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
478 ValueOffset = OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, GetDefaultValueFromAccess);
479 ValueWidth = sizeof (((DRIVER_SAMPLE_CONFIGURATION *)0)->GetDefaultValueFromAccess);
480
481 if (StringPtr == NULL) {
482 return;
483 }
484
485 while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {
486 StringPtr += StrLen (L"OFFSET=");
487 //
488 // Get Offset
489 //
490 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
491 if (EFI_ERROR (Status)) {
492 return;
493 }
494
495 Offset = 0;
496 CopyMem (
497 &Offset,
498 TmpBuffer,
499 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
500 );
501 FreePool (TmpBuffer);
502
503 StringPtr += Length;
504 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {
505 return;
506 }
507
508 StringPtr += StrLen (L"&WIDTH=");
509
510 //
511 // Get Width
512 //
513 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
514 if (EFI_ERROR (Status)) {
515 return;
516 }
517
518 Width = 0;
519 CopyMem (
520 &Width,
521 TmpBuffer,
522 (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
523 );
524 FreePool (TmpBuffer);
525
526 StringPtr += Length;
527 if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {
528 return;
529 }
530
531 StringPtr += StrLen (L"&VALUE=");
532
533 //
534 // Get Value
535 //
536 Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
537 if (EFI_ERROR (Status)) {
538 return;
539 }
540
541 StringPtr += Length;
542
543 //
544 // Skip the character "&" before "OFFSET".
545 //
546 StringPtr++;
547
548 //
549 // Calculate Value and convert it to hex string.
550 //
551 if (Offset + Width > BlockSize) {
552 return;
553 }
554
555 if ((Offset <= ValueOffset) && (Offset + Width >= ValueOffset + ValueWidth)) {
556 *RequestResult = CreateAltCfgString (*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth);
557 return;
558 }
559 }
560}
561
589EFIAPI
592 IN CONST EFI_STRING Request,
593 OUT EFI_STRING *Progress,
594 OUT EFI_STRING *Results
595 )
596{
597 EFI_STATUS Status;
598 UINTN BufferSize;
599 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
600 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
601 EFI_STRING ConfigRequest;
602 EFI_STRING ConfigRequestHdr;
603 UINTN Size;
604 EFI_STRING Value;
605 UINTN ValueStrLen;
606 CHAR16 BackupChar;
607 CHAR16 *StrPointer;
608 BOOLEAN AllocatedRequest;
609
610 if ((Progress == NULL) || (Results == NULL)) {
611 return EFI_INVALID_PARAMETER;
612 }
613
614 //
615 // Initialize the local variables.
616 //
617 ConfigRequestHdr = NULL;
618 ConfigRequest = NULL;
619 Size = 0;
620 *Progress = Request;
621 AllocatedRequest = FALSE;
622
623 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
624 HiiConfigRouting = PrivateData->HiiConfigRouting;
625
626 //
627 // Get Buffer Storage data from EFI variable.
628 // Try to get the current setting from variable.
629 //
630 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
631 Status = gRT->GetVariable (
632 VariableName,
633 &gDriverSampleFormSetGuid,
634 NULL,
635 &BufferSize,
636 &PrivateData->Configuration
637 );
638 if (EFI_ERROR (Status)) {
639 return EFI_NOT_FOUND;
640 }
641
642 if (Request == NULL) {
643 //
644 // Request is set to NULL, construct full request string.
645 //
646
647 //
648 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
649 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
650 //
651 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
652 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
653 ConfigRequest = AllocateZeroPool (Size);
654 ASSERT (ConfigRequest != NULL);
655 AllocatedRequest = TRUE;
656 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
657 FreePool (ConfigRequestHdr);
658 ConfigRequestHdr = NULL;
659 } else {
660 //
661 // Check routing data in <ConfigHdr>.
662 // Note: if only one Storage is used, then this checking could be skipped.
663 //
664 if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {
665 return EFI_NOT_FOUND;
666 }
667
668 //
669 // Check whether request for EFI Varstore. EFI varstore get data
670 // through hii database, not support in this path.
671 //
672 if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiVar)) {
673 return EFI_UNSUPPORTED;
674 }
675
676 if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiBitVar)) {
677 return EFI_UNSUPPORTED;
678 }
679
680 if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiUnionVar)) {
681 return EFI_UNSUPPORTED;
682 }
683
684 //
685 // Set Request to the unified request string.
686 //
687 ConfigRequest = Request;
688 //
689 // Check whether Request includes Request Element.
690 //
691 if (StrStr (Request, L"OFFSET") == NULL) {
692 //
693 // Check Request Element does exist in Reques String
694 //
695 StrPointer = StrStr (Request, L"PATH");
696 if (StrPointer == NULL) {
697 return EFI_INVALID_PARAMETER;
698 }
699
700 if (StrStr (StrPointer, L"&") == NULL) {
701 Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16);
702 ConfigRequest = AllocateZeroPool (Size);
703 ASSERT (ConfigRequest != NULL);
704 AllocatedRequest = TRUE;
705 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", Request, (UINT64)BufferSize);
706 }
707 }
708 }
709
710 //
711 // Check if requesting Name/Value storage
712 //
713 if (StrStr (ConfigRequest, L"OFFSET") == NULL) {
714 //
715 // Update Name/Value storage Names
716 //
717 Status = LoadNameValueNames (PrivateData);
718 if (EFI_ERROR (Status)) {
719 return Status;
720 }
721
722 //
723 // Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
724 // <Request> ::=<ConfigHdr>&Name0&Name1&Name2
725 // <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
726 //
727 BufferSize = (StrLen (ConfigRequest) +
728 1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 +
729 1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 +
730 1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16);
731 *Results = AllocateZeroPool (BufferSize);
732 ASSERT (*Results != NULL);
733 StrCpyS (*Results, BufferSize / sizeof (CHAR16), ConfigRequest);
734 Value = *Results;
735
736 //
737 // Append value of NameValueVar0, type is UINT8
738 //
739 if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) {
740 Value += StrLen (PrivateData->NameValueName[0]);
741 ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1);
742 CopyMem (Value + ValueStrLen, Value, StrSize (Value));
743
744 BackupChar = Value[ValueStrLen];
745 *Value++ = L'=';
747 Value,
748 BufferSize - ((UINTN)Value - (UINTN)*Results),
749 PREFIX_ZERO | RADIX_HEX,
750 PrivateData->Configuration.NameValueVar0,
751 sizeof (PrivateData->Configuration.NameValueVar0) * 2
752 );
753 Value += StrnLenS (Value, (BufferSize - ((UINTN)Value - (UINTN)*Results)) / sizeof (CHAR16));
754 *Value = BackupChar;
755 }
756
757 //
758 // Append value of NameValueVar1, type is UINT16
759 //
760 if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) {
761 Value += StrLen (PrivateData->NameValueName[1]);
762 ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1);
763 CopyMem (Value + ValueStrLen, Value, StrSize (Value));
764
765 BackupChar = Value[ValueStrLen];
766 *Value++ = L'=';
768 Value,
769 BufferSize - ((UINTN)Value - (UINTN)*Results),
770 PREFIX_ZERO | RADIX_HEX,
771 PrivateData->Configuration.NameValueVar1,
772 sizeof (PrivateData->Configuration.NameValueVar1) * 2
773 );
774 Value += StrnLenS (Value, (BufferSize - ((UINTN)Value - (UINTN)*Results)) / sizeof (CHAR16));
775 *Value = BackupChar;
776 }
777
778 //
779 // Append value of NameValueVar2, type is CHAR16 *
780 //
781 if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) {
782 Value += StrLen (PrivateData->NameValueName[2]);
783 ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1;
784 CopyMem (Value + ValueStrLen, Value, StrSize (Value));
785
786 *Value++ = L'=';
787 //
788 // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
789 //
790 StrPointer = (CHAR16 *)PrivateData->Configuration.NameValueVar2;
791 for ( ; *StrPointer != L'\0'; StrPointer++) {
793 Value,
794 BufferSize - ((UINTN)Value - (UINTN)*Results),
795 PREFIX_ZERO | RADIX_HEX,
796 *StrPointer,
797 4
798 );
799 Value += StrnLenS (Value, (BufferSize - ((UINTN)Value - (UINTN)*Results)) / sizeof (CHAR16));
800 }
801 }
802
803 Status = EFI_SUCCESS;
804 } else {
805 //
806 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
807 //
808 Status = HiiConfigRouting->BlockToConfig (
809 HiiConfigRouting,
810 ConfigRequest,
811 (UINT8 *)&PrivateData->Configuration,
812 BufferSize,
813 Results,
814 Progress
815 );
816 if (!EFI_ERROR (Status)) {
817 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
818 AppendAltCfgString (Results, ConfigRequestHdr);
819 }
820 }
821
822 //
823 // Free the allocated config request string.
824 //
825 if (AllocatedRequest) {
826 FreePool (ConfigRequest);
827 }
828
829 if (ConfigRequestHdr != NULL) {
830 FreePool (ConfigRequestHdr);
831 }
832
833 //
834 // Set Progress string to the original request string.
835 //
836 if (Request == NULL) {
837 *Progress = NULL;
838 } else if (StrStr (Request, L"OFFSET") == NULL) {
839 *Progress = Request + StrLen (Request);
840 }
841
842 return Status;
843}
844
865EFIAPI
868 IN CONST EFI_STRING Configuration,
869 OUT EFI_STRING *Progress
870 )
871{
872 EFI_STATUS Status;
873 UINTN BufferSize;
874 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
875 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
876 CHAR16 *Value;
877 CHAR16 *StrPtr;
878 CHAR16 TemStr[5];
879 UINT8 *DataBuffer;
880 UINT8 DigitUint8;
881 UINTN Index;
882 CHAR16 *StrBuffer;
883
884 if ((Configuration == NULL) || (Progress == NULL)) {
885 return EFI_INVALID_PARAMETER;
886 }
887
888 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
889 HiiConfigRouting = PrivateData->HiiConfigRouting;
890 *Progress = Configuration;
891
892 //
893 // Check routing data in <ConfigHdr>.
894 // Note: if only one Storage is used, then this checking could be skipped.
895 //
896 if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {
897 return EFI_NOT_FOUND;
898 }
899
900 //
901 // Check whether request for EFI Varstore. EFI varstore get data
902 // through hii database, not support in this path.
903 //
904 if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {
905 return EFI_UNSUPPORTED;
906 }
907
908 if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiBitVar)) {
909 return EFI_UNSUPPORTED;
910 }
911
912 if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiUnionVar)) {
913 return EFI_UNSUPPORTED;
914 }
915
916 //
917 // Get Buffer Storage data from EFI variable
918 //
919 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
920 Status = gRT->GetVariable (
921 VariableName,
922 &gDriverSampleFormSetGuid,
923 NULL,
924 &BufferSize,
925 &PrivateData->Configuration
926 );
927 if (EFI_ERROR (Status)) {
928 return Status;
929 }
930
931 //
932 // Check if configuring Name/Value storage
933 //
934 if (StrStr (Configuration, L"OFFSET") == NULL) {
935 //
936 // Update Name/Value storage Names
937 //
938 Status = LoadNameValueNames (PrivateData);
939 if (EFI_ERROR (Status)) {
940 return Status;
941 }
942
943 //
944 // Convert value for NameValueVar0
945 //
946 if ((Value = StrStr (Configuration, PrivateData->NameValueName[0])) != NULL) {
947 //
948 // Skip "Name="
949 //
950 Value += StrLen (PrivateData->NameValueName[0]);
951 Value++;
952 //
953 // Get Value String
954 //
955 StrPtr = StrStr (Value, L"&");
956 if (StrPtr == NULL) {
957 StrPtr = Value + StrLen (Value);
958 }
959
960 //
961 // Convert Value to Buffer data
962 //
963 DataBuffer = (UINT8 *)&PrivateData->Configuration.NameValueVar0;
964 ZeroMem (TemStr, sizeof (TemStr));
965 for (Index = 0, StrPtr--; StrPtr >= Value; StrPtr--, Index++) {
966 TemStr[0] = *StrPtr;
967 DigitUint8 = (UINT8)StrHexToUint64 (TemStr);
968 if ((Index & 1) == 0) {
969 DataBuffer[Index/2] = DigitUint8;
970 } else {
971 DataBuffer[Index/2] = (UINT8)((UINT8)(DigitUint8 << 4) + DataBuffer[Index/2]);
972 }
973 }
974 }
975
976 //
977 // Convert value for NameValueVar1
978 //
979 if ((Value = StrStr (Configuration, PrivateData->NameValueName[1])) != NULL) {
980 //
981 // Skip "Name="
982 //
983 Value += StrLen (PrivateData->NameValueName[1]);
984 Value++;
985 //
986 // Get Value String
987 //
988 StrPtr = StrStr (Value, L"&");
989 if (StrPtr == NULL) {
990 StrPtr = Value + StrLen (Value);
991 }
992
993 //
994 // Convert Value to Buffer data
995 //
996 DataBuffer = (UINT8 *)&PrivateData->Configuration.NameValueVar1;
997 ZeroMem (TemStr, sizeof (TemStr));
998 for (Index = 0, StrPtr--; StrPtr >= Value; StrPtr--, Index++) {
999 TemStr[0] = *StrPtr;
1000 DigitUint8 = (UINT8)StrHexToUint64 (TemStr);
1001 if ((Index & 1) == 0) {
1002 DataBuffer[Index/2] = DigitUint8;
1003 } else {
1004 DataBuffer[Index/2] = (UINT8)((UINT8)(DigitUint8 << 4) + DataBuffer[Index/2]);
1005 }
1006 }
1007 }
1008
1009 //
1010 // Convert value for NameValueVar2
1011 //
1012 if ((Value = StrStr (Configuration, PrivateData->NameValueName[2])) != NULL) {
1013 //
1014 // Skip "Name="
1015 //
1016 Value += StrLen (PrivateData->NameValueName[2]);
1017 Value++;
1018 //
1019 // Get Value String
1020 //
1021 StrPtr = StrStr (Value, L"&");
1022 if (StrPtr == NULL) {
1023 StrPtr = Value + StrLen (Value);
1024 }
1025
1026 //
1027 // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
1028 //
1029 StrBuffer = (CHAR16 *)PrivateData->Configuration.NameValueVar2;
1030 ZeroMem (TemStr, sizeof (TemStr));
1031 while (Value < StrPtr) {
1032 StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value, 4);
1033 *(StrBuffer++) = (CHAR16)StrHexToUint64 (TemStr);
1034 Value += 4;
1035 }
1036
1037 *StrBuffer = L'\0';
1038 }
1039
1040 //
1041 // Store Buffer Storage back to EFI variable
1042 //
1043 Status = gRT->SetVariable (
1044 VariableName,
1045 &gDriverSampleFormSetGuid,
1046 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1048 &PrivateData->Configuration
1049 );
1050
1051 return Status;
1052 }
1053
1054 //
1055 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
1056 //
1057 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
1058 Status = HiiConfigRouting->ConfigToBlock (
1059 HiiConfigRouting,
1060 Configuration,
1061 (UINT8 *)&PrivateData->Configuration,
1062 &BufferSize,
1063 Progress
1064 );
1065 if (EFI_ERROR (Status)) {
1066 return Status;
1067 }
1068
1069 if (PrivateData->Configuration.QuestionApply == 44) {
1070 // Return error for verify the error handling of caller.
1071 return EFI_DEVICE_ERROR;
1072 }
1073
1074 //
1075 // Store Buffer Storage back to EFI variable
1076 //
1077 Status = gRT->SetVariable (
1078 VariableName,
1079 &gDriverSampleFormSetGuid,
1080 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1082 &PrivateData->Configuration
1083 );
1084
1085 return Status;
1086}
1087
1111EFIAPI
1114 IN EFI_BROWSER_ACTION Action,
1115 IN EFI_QUESTION_ID QuestionId,
1116 IN UINT8 Type,
1117 IN EFI_IFR_TYPE_VALUE *Value,
1118 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
1119 )
1120{
1121 DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
1122 EFI_STATUS Status;
1123 VOID *StartOpCodeHandle;
1124 VOID *OptionsOpCodeHandle;
1125 EFI_IFR_GUID_LABEL *StartLabel;
1126 VOID *EndOpCodeHandle;
1127 EFI_IFR_GUID_LABEL *EndLabel;
1128 EFI_INPUT_KEY Key;
1129 DRIVER_SAMPLE_CONFIGURATION *Configuration;
1130 MY_EFI_VARSTORE_DATA *EfiData;
1131 EFI_FORM_ID FormId;
1132 EFI_STRING Progress;
1133 EFI_STRING Results;
1134 UINT32 ProgressErr;
1135 CHAR16 *TmpStr;
1136 UINTN Index;
1137 UINT64 BufferValue;
1138 EFI_HII_POPUP_SELECTION UserSelection;
1139
1140 UserSelection = 0xFF;
1141
1142 if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) ||
1143 (ActionRequest == NULL))
1144 {
1145 return EFI_INVALID_PARAMETER;
1146 }
1147
1148 FormId = 0;
1149 ProgressErr = 0;
1150 Status = EFI_SUCCESS;
1151 BufferValue = 3;
1152 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
1153
1154 switch (Action) {
1155 case EFI_BROWSER_ACTION_FORM_OPEN:
1156 {
1157 if (QuestionId == 0x1234) {
1158 //
1159 // Sample CallBack for UEFI FORM_OPEN action:
1160 // Add Save action into Form 3 when Form 1 is opened.
1161 // This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
1162 //
1163 PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
1164
1165 //
1166 // Initialize the container for dynamic opcodes
1167 //
1168 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
1169 ASSERT (StartOpCodeHandle != NULL);
1170
1171 //
1172 // Create Hii Extend Label OpCode as the start opcode
1173 //
1174 StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1176 StartLabel->Number = LABEL_UPDATE2;
1177
1179 StartOpCodeHandle, // Container for dynamic created opcodes
1180 0x1238, // Question ID
1181 STRING_TOKEN (STR_SAVE_TEXT), // Prompt text
1182 STRING_TOKEN (STR_SAVE_TEXT), // Help text
1183 EFI_IFR_FLAG_CALLBACK, // Question flag
1184 0 // Action String ID
1185 );
1186
1188 PrivateData->HiiHandle[0], // HII handle
1189 &gDriverSampleFormSetGuid, // Formset GUID
1190 0x3, // Form ID
1191 StartOpCodeHandle, // Label for where to insert opcodes
1192 NULL // Insert data
1193 );
1194
1195 HiiFreeOpCodeHandle (StartOpCodeHandle);
1196 }
1197
1198 if (QuestionId == 0x1247) {
1199 Status = InternalStartMonitor ();
1200 ASSERT_EFI_ERROR (Status);
1201 }
1202
1203 break;
1204 }
1205
1206 case EFI_BROWSER_ACTION_FORM_CLOSE:
1207 {
1208 if (QuestionId == 0x5678) {
1209 //
1210 // Sample CallBack for UEFI FORM_CLOSE action:
1211 // Show up a pop-up to specify Form 3 will be closed when exit Form 3.
1212 //
1213 do {
1214 CreatePopUp (
1215 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1216 &Key,
1217 L"",
1218 L"You are going to leave third Form!",
1219 L"Press ESC or ENTER to continue ...",
1220 L"",
1221 NULL
1222 );
1223 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1224 }
1225
1226 if (QuestionId == 0x1247) {
1227 Status = InternalStopMonitor ();
1228 ASSERT_EFI_ERROR (Status);
1229 }
1230
1231 break;
1232 }
1233
1234 case EFI_BROWSER_ACTION_RETRIEVE:
1235 {
1236 switch (QuestionId ) {
1237 case 0x1248:
1238 if (Type != EFI_IFR_TYPE_REF) {
1239 return EFI_INVALID_PARAMETER;
1240 }
1241
1242 Value->ref.FormId = 0x3;
1243 break;
1244
1245 case 0x5678:
1246 case 0x1247:
1247 //
1248 // We will reach here once the Question is refreshed
1249 //
1250
1251 //
1252 // Initialize the container for dynamic opcodes
1253 //
1254 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
1255 ASSERT (StartOpCodeHandle != NULL);
1256
1257 //
1258 // Create Hii Extend Label OpCode as the start opcode
1259 //
1260 StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1262 if (QuestionId == 0x5678) {
1263 StartLabel->Number = LABEL_UPDATE2;
1264 FormId = 0x03;
1265 PrivateData->Configuration.DynamicRefresh++;
1266 } else if (QuestionId == 0x1247 ) {
1267 StartLabel->Number = LABEL_UPDATE3;
1268 FormId = 0x06;
1269 PrivateData->Configuration.RefreshGuidCount++;
1270 }
1271
1273 StartOpCodeHandle, // Container for dynamic created opcodes
1274 0x1237, // Question ID
1275 STRING_TOKEN (STR_EXIT_TEXT), // Prompt text
1276 STRING_TOKEN (STR_EXIT_TEXT), // Help text
1277 EFI_IFR_FLAG_CALLBACK, // Question flag
1278 0 // Action String ID
1279 );
1280
1282 PrivateData->HiiHandle[0], // HII handle
1283 &gDriverSampleFormSetGuid, // Formset GUID
1284 FormId, // Form ID
1285 StartOpCodeHandle, // Label for where to insert opcodes
1286 NULL // Insert data
1287 );
1288
1289 HiiFreeOpCodeHandle (StartOpCodeHandle);
1290
1291 //
1292 // Refresh the Question value
1293 //
1294 Status = gRT->SetVariable (
1295 VariableName,
1296 &gDriverSampleFormSetGuid,
1297 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1299 &PrivateData->Configuration
1300 );
1301
1302 if (QuestionId == 0x5678) {
1303 //
1304 // Update uncommitted data of Browser
1305 //
1306 EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));
1307 ASSERT (EfiData != NULL);
1308 if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *)EfiData)) {
1309 EfiData->Field8 = 111;
1311 &gDriverSampleFormSetGuid,
1312 MyEfiVar,
1313 sizeof (MY_EFI_VARSTORE_DATA),
1314 (UINT8 *)EfiData,
1315 NULL
1316 );
1317 }
1318
1319 FreePool (EfiData);
1320 }
1321
1322 break;
1323 }
1324
1325 break;
1326 }
1327
1328 case EFI_BROWSER_ACTION_DEFAULT_STANDARD:
1329 {
1330 switch (QuestionId) {
1331 case 0x1240:
1332 Value->u8 = DEFAULT_CLASS_STANDARD_VALUE;
1333 break;
1334
1335 case 0x1252:
1336 for (Index = 0; Index < 3; Index++) {
1337 SetArrayData (Value, EFI_IFR_TYPE_NUM_SIZE_8, Index, BufferValue--);
1338 }
1339
1340 break;
1341
1342 case 0x6666:
1343 Value->u8 = 12;
1344 break;
1345
1346 default:
1347 Status = EFI_UNSUPPORTED;
1348 break;
1349 }
1350
1351 break;
1352 }
1353
1354 case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING:
1355 {
1356 switch (QuestionId) {
1357 case 0x1240:
1358 Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE;
1359 break;
1360
1361 case 0x6666:
1362 Value->u8 = 13;
1363 break;
1364
1365 default:
1366 Status = EFI_UNSUPPORTED;
1367 break;
1368 }
1369
1370 break;
1371 }
1372
1373 case EFI_BROWSER_ACTION_CHANGING:
1374 {
1375 switch (QuestionId) {
1376 case 0x1249:
1377 {
1378 if (Type != EFI_IFR_TYPE_REF) {
1379 return EFI_INVALID_PARAMETER;
1380 }
1381
1382 Value->ref.FormId = 0x1234;
1383 break;
1384 }
1385 case 0x1234:
1386 //
1387 // Initialize the container for dynamic opcodes
1388 //
1389 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
1390 ASSERT (StartOpCodeHandle != NULL);
1391
1392 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
1393 ASSERT (EndOpCodeHandle != NULL);
1394
1395 //
1396 // Create Hii Extend Label OpCode as the start opcode
1397 //
1398 StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1400 StartLabel->Number = LABEL_UPDATE1;
1401
1402 //
1403 // Create Hii Extend Label OpCode as the end opcode
1404 //
1405 EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
1407 EndLabel->Number = LABEL_END;
1408
1410 StartOpCodeHandle, // Container for dynamic created opcodes
1411 0x1237, // Question ID
1412 STRING_TOKEN (STR_EXIT_TEXT), // Prompt text
1413 STRING_TOKEN (STR_EXIT_TEXT), // Help text
1414 EFI_IFR_FLAG_CALLBACK, // Question flag
1415 0 // Action String ID
1416 );
1417
1418 //
1419 // Create Option OpCode
1420 //
1421 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
1422 ASSERT (OptionsOpCodeHandle != NULL);
1423
1425 OptionsOpCodeHandle,
1426 STRING_TOKEN (STR_BOOT_OPTION1),
1427 0,
1428 EFI_IFR_NUMERIC_SIZE_1,
1429 1
1430 );
1431
1433 OptionsOpCodeHandle,
1434 STRING_TOKEN (STR_BOOT_OPTION2),
1435 0,
1436 EFI_IFR_NUMERIC_SIZE_1,
1437 2
1438 );
1439
1440 //
1441 // Prepare initial value for the dynamic created oneof Question
1442 //
1443 PrivateData->Configuration.DynamicOneof = 2;
1444 Status = gRT->SetVariable (
1445 VariableName,
1446 &gDriverSampleFormSetGuid,
1447 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1449 &PrivateData->Configuration
1450 );
1451
1452 //
1453 // Set initial vlaue of dynamic created oneof Question in Form Browser
1454 //
1455 Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
1456 ASSERT (Configuration != NULL);
1457 if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *)Configuration)) {
1458 Configuration->DynamicOneof = 2;
1459
1460 //
1461 // Update uncommitted data of Browser
1462 //
1464 &gDriverSampleFormSetGuid,
1465 VariableName,
1467 (UINT8 *)Configuration,
1468 NULL
1469 );
1470 }
1471
1472 FreePool (Configuration);
1473
1475 StartOpCodeHandle, // Container for dynamic created opcodes
1476 0x8001, // Question ID (or call it "key")
1477 CONFIGURATION_VARSTORE_ID, // VarStore ID
1478 (UINT16)DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage
1479 STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text
1480 STRING_TOKEN (STR_ONE_OF_HELP), // Question help text
1481 EFI_IFR_FLAG_CALLBACK, // Question flag
1482 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value
1483 OptionsOpCodeHandle, // Option Opcode list
1484 NULL // Default Opcode is NULl
1485 );
1486
1488 StartOpCodeHandle, // Container for dynamic created opcodes
1489 0x8002, // Question ID
1490 CONFIGURATION_VARSTORE_ID, // VarStore ID
1491 (UINT16)DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage
1492 STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text
1493 STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text
1494 EFI_IFR_FLAG_RESET_REQUIRED, // Question flag
1495 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
1496 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value
1497 5, // Maximum container
1498 OptionsOpCodeHandle, // Option Opcode list
1499 NULL // Default Opcode is NULl
1500 );
1501
1503 StartOpCodeHandle,
1504 STRING_TOKEN (STR_TEXT_SAMPLE_HELP),
1505 STRING_TOKEN (STR_TEXT_SAMPLE_HELP),
1506 STRING_TOKEN (STR_TEXT_SAMPLE_STRING)
1507 );
1508
1510 StartOpCodeHandle,
1511 0x8004,
1512 0x0,
1513 0x0,
1514 STRING_TOKEN (STR_DATE_SAMPLE_HELP),
1515 STRING_TOKEN (STR_DATE_SAMPLE_HELP),
1516 0,
1517 QF_DATE_STORAGE_TIME,
1518 NULL
1519 );
1520
1522 StartOpCodeHandle,
1523 0x8005,
1524 0x0,
1525 0x0,
1526 STRING_TOKEN (STR_TIME_SAMPLE_HELP),
1527 STRING_TOKEN (STR_TIME_SAMPLE_HELP),
1528 0,
1529 QF_TIME_STORAGE_TIME,
1530 NULL
1531 );
1532
1534 StartOpCodeHandle, // Container for dynamic created opcodes
1535 1, // Target Form ID
1536 STRING_TOKEN (STR_GOTO_FORM1), // Prompt text
1537 STRING_TOKEN (STR_GOTO_HELP), // Help text
1538 0, // Question flag
1539 0x8003 // Question ID
1540 );
1541
1543 PrivateData->HiiHandle[0], // HII handle
1544 &gDriverSampleFormSetGuid, // Formset GUID
1545 0x1234, // Form ID
1546 StartOpCodeHandle, // Label for where to insert opcodes
1547 EndOpCodeHandle // Replace data
1548 );
1549
1550 HiiFreeOpCodeHandle (StartOpCodeHandle);
1551 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
1552 HiiFreeOpCodeHandle (EndOpCodeHandle);
1553 break;
1554
1555 default:
1556 break;
1557 }
1558
1559 break;
1560 }
1561
1562 case EFI_BROWSER_ACTION_CHANGED:
1563 switch (QuestionId) {
1564 case 0x1237:
1565 //
1566 // User press "Exit now", request Browser to exit
1567 //
1568 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
1569 break;
1570
1571 case 0x1238:
1572 //
1573 // User press "Save now", request Browser to save the uncommitted data.
1574 //
1575 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
1576 break;
1577
1578 case 0x1241:
1579 case 0x1246:
1580 //
1581 // User press "Submit current form and Exit now", request Browser to submit current form and exit
1582 //
1583 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
1584 break;
1585
1586 case 0x1242:
1587 //
1588 // User press "Discard current form now", request Browser to discard the uncommitted data.
1589 //
1590 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;
1591 break;
1592
1593 case 0x1243:
1594 //
1595 // User press "Submit current form now", request Browser to save the uncommitted data.
1596 //
1597 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
1598 break;
1599
1600 case 0x1244:
1601 case 0x1245:
1602 //
1603 // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
1604 //
1605 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
1606 break;
1607
1608 case 0x1253:
1609 //
1610 // User change the value of "Question apply test".
1611 //
1612 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_QUESTION_APPLY;
1613 break;
1614
1615 case 0x1231:
1616 //
1617 // 1. Check to see whether system support keyword.
1618 //
1619 Status = PrivateData->HiiKeywordHandler->GetData (
1620 PrivateData->HiiKeywordHandler,
1621 L"NAMESPACE=x-UEFI-ns",
1622 L"KEYWORD=iSCSIBootEnable",
1623 &Progress,
1624 &ProgressErr,
1625 &Results
1626 );
1627 if (EFI_ERROR (Status)) {
1628 do {
1629 CreatePopUp (
1630 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1631 &Key,
1632 L"",
1633 L"This system not support this keyword!",
1634 L"Press ENTER to continue ...",
1635 L"",
1636 NULL
1637 );
1638 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1639
1640 Status = EFI_SUCCESS;
1641 break;
1642 }
1643
1644 //
1645 // 2. If system support this keyword, just try to change value.
1646 //
1647
1648 //
1649 // Change value from '0' to '1' or from '1' to '0'
1650 //
1651 TmpStr = StrStr (Results, L"&VALUE=");
1652 ASSERT (TmpStr != NULL);
1653 TmpStr += StrLen (L"&VALUE=");
1654 TmpStr++;
1655 if (*TmpStr == L'0') {
1656 *TmpStr = L'1';
1657 } else {
1658 *TmpStr = L'0';
1659 }
1660
1661 //
1662 // 3. Call the keyword handler protocol to change the value.
1663 //
1664 Status = PrivateData->HiiKeywordHandler->SetData (
1665 PrivateData->HiiKeywordHandler,
1666 Results,
1667 &Progress,
1668 &ProgressErr
1669 );
1670 if (EFI_ERROR (Status)) {
1671 do {
1672 CreatePopUp (
1673 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1674 &Key,
1675 L"",
1676 L"Set keyword to the system failed!",
1677 L"Press ENTER to continue ...",
1678 L"",
1679 NULL
1680 );
1681 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1682
1683 Status = EFI_SUCCESS;
1684 break;
1685 }
1686
1687 break;
1688
1689 case 0x1330:
1690 Status = mPrivateData->HiiPopup->CreatePopup (
1691 mPrivateData->HiiPopup,
1692 EfiHiiPopupStyleInfo,
1693 EfiHiiPopupTypeYesNo,
1694 mPrivateData->HiiHandle[0],
1695 STRING_TOKEN (STR_POPUP_STRING),
1696 &UserSelection
1697 );
1698 if (!EFI_ERROR (Status)) {
1699 if (UserSelection == EfiHiiPopupSelectionYes) {
1700 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
1701 }
1702 }
1703
1704 break;
1705
1706 default:
1707 break;
1708 }
1709
1710 break;
1711
1712 case EFI_BROWSER_ACTION_SUBMITTED:
1713 {
1714 if (QuestionId == 0x1250) {
1715 //
1716 // Sample CallBack for EFI_BROWSER_ACTION_SUBMITTED action:
1717 // Show up a pop-up to show SUBMITTED callback has been triggered.
1718 //
1719 do {
1720 CreatePopUp (
1721 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
1722 &Key,
1723 L"",
1724 L"EfiVarstore value has been submitted!",
1725 L"Press ESC or ENTER to continue ...",
1726 L"",
1727 NULL
1728 );
1729 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1730 }
1731
1732 break;
1733 }
1734
1735 default:
1736 Status = EFI_UNSUPPORTED;
1737 break;
1738 }
1739
1740 return Status;
1741}
1742
1753EFIAPI
1755 IN EFI_HANDLE ImageHandle,
1756 IN EFI_SYSTEM_TABLE *SystemTable
1757 )
1758{
1759 EFI_STATUS Status;
1760 EFI_HII_HANDLE HiiHandle[2];
1761 EFI_SCREEN_DESCRIPTOR Screen;
1762 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
1763 EFI_HII_STRING_PROTOCOL *HiiString;
1764 EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
1765 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
1766 EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;
1767 EFI_HII_POPUP_PROTOCOL *PopupHandler;
1768 CHAR16 *NewString;
1769 UINTN BufferSize;
1770 DRIVER_SAMPLE_CONFIGURATION *Configuration;
1771 BOOLEAN ActionFlag;
1772 EFI_STRING ConfigRequestHdr;
1773 EFI_STRING NameRequestHdr;
1774 MY_EFI_VARSTORE_DATA *VarStoreConfig;
1775 MY_EFI_BITS_VARSTORE_DATA *BitsVarStoreConfig;
1776 MY_EFI_UNION_DATA *UnionConfig;
1777 EFI_INPUT_KEY HotKey;
1779
1780 //
1781 // Initialize the local variables.
1782 //
1783 ConfigRequestHdr = NULL;
1784 NewString = NULL;
1785
1786 //
1787 // Initialize screen dimensions for SendForm().
1788 // Remove 3 characters from top and bottom
1789 //
1790 ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
1791 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
1792
1793 Screen.TopRow = 3;
1794 Screen.BottomRow = Screen.BottomRow - 3;
1795
1796 //
1797 // Initialize driver private data
1798 //
1799 mPrivateData = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
1800 if (mPrivateData == NULL) {
1801 return EFI_OUT_OF_RESOURCES;
1802 }
1803
1804 mPrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
1805
1806 mPrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
1807 mPrivateData->ConfigAccess.RouteConfig = RouteConfig;
1808 mPrivateData->ConfigAccess.Callback = DriverCallback;
1809
1810 //
1811 // Locate Hii Database protocol
1812 //
1813 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);
1814 if (EFI_ERROR (Status)) {
1815 return Status;
1816 }
1817
1818 mPrivateData->HiiDatabase = HiiDatabase;
1819
1820 //
1821 // Locate HiiString protocol
1822 //
1823 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **)&HiiString);
1824 if (EFI_ERROR (Status)) {
1825 return Status;
1826 }
1827
1828 mPrivateData->HiiString = HiiString;
1829
1830 //
1831 // Locate Formbrowser2 protocol
1832 //
1833 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **)&FormBrowser2);
1834 if (EFI_ERROR (Status)) {
1835 return Status;
1836 }
1837
1838 mPrivateData->FormBrowser2 = FormBrowser2;
1839
1840 //
1841 // Locate ConfigRouting protocol
1842 //
1843 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&HiiConfigRouting);
1844 if (EFI_ERROR (Status)) {
1845 return Status;
1846 }
1847
1848 mPrivateData->HiiConfigRouting = HiiConfigRouting;
1849
1850 //
1851 // Locate keyword handler protocol
1852 //
1853 Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **)&HiiKeywordHandler);
1854 if (EFI_ERROR (Status)) {
1855 return Status;
1856 }
1857
1858 mPrivateData->HiiKeywordHandler = HiiKeywordHandler;
1859
1860 //
1861 // Locate HiiPopup protocol
1862 //
1863 Status = gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VOID **)&PopupHandler);
1864 if (EFI_ERROR (Status)) {
1865 return Status;
1866 }
1867
1868 mPrivateData->HiiPopup = PopupHandler;
1869
1870 Status = gBS->InstallMultipleProtocolInterfaces (
1871 &DriverHandle[0],
1872 &gEfiDevicePathProtocolGuid,
1873 &mHiiVendorDevicePath0,
1874 &gEfiHiiConfigAccessProtocolGuid,
1875 &mPrivateData->ConfigAccess,
1876 NULL
1877 );
1878 ASSERT_EFI_ERROR (Status);
1879
1880 mPrivateData->DriverHandle[0] = DriverHandle[0];
1881
1882 //
1883 // Publish our HII data
1884 //
1885 HiiHandle[0] = HiiAddPackages (
1886 &gDriverSampleFormSetGuid,
1887 DriverHandle[0],
1888 DriverSampleStrings,
1889 VfrBin,
1890 NULL
1891 );
1892 if (HiiHandle[0] == NULL) {
1893 return EFI_OUT_OF_RESOURCES;
1894 }
1895
1896 mPrivateData->HiiHandle[0] = HiiHandle[0];
1897
1898 //
1899 // Publish another Fromset
1900 //
1901 Status = gBS->InstallMultipleProtocolInterfaces (
1902 &DriverHandle[1],
1903 &gEfiDevicePathProtocolGuid,
1904 &mHiiVendorDevicePath1,
1905 &gEfiHiiConfigAccessProtocolGuid,
1906 &mPrivateData->ConfigAccess,
1907 NULL
1908 );
1909 ASSERT_EFI_ERROR (Status);
1910
1911 mPrivateData->DriverHandle[1] = DriverHandle[1];
1912
1913 HiiHandle[1] = HiiAddPackages (
1914 &gDriverSampleInventoryGuid,
1915 DriverHandle[1],
1916 DriverSampleStrings,
1917 InventoryBin,
1918 NULL
1919 );
1920 if (HiiHandle[1] == NULL) {
1921 DriverSampleUnload (ImageHandle);
1922 return EFI_OUT_OF_RESOURCES;
1923 }
1924
1925 mPrivateData->HiiHandle[1] = HiiHandle[1];
1926
1927 //
1928 // Update the device path string.
1929 //
1931 if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {
1932 DriverSampleUnload (ImageHandle);
1933 return EFI_OUT_OF_RESOURCES;
1934 }
1935
1936 if (NewString != NULL) {
1938 }
1939
1940 //
1941 // Very simple example of how one would update a string that is already
1942 // in the HII database
1943 //
1944 NewString = L"700 Mhz";
1945
1946 if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {
1947 DriverSampleUnload (ImageHandle);
1948 return EFI_OUT_OF_RESOURCES;
1949 }
1950
1951 HiiSetString (HiiHandle[0], 0, NewString, NULL);
1952
1953 //
1954 // Initialize Name/Value name String ID
1955 //
1956 mPrivateData->NameStringId[0] = STR_NAME_VALUE_VAR_NAME0;
1957 mPrivateData->NameStringId[1] = STR_NAME_VALUE_VAR_NAME1;
1958 mPrivateData->NameStringId[2] = STR_NAME_VALUE_VAR_NAME2;
1959
1960 //
1961 // Initialize configuration data
1962 //
1963 Configuration = &mPrivateData->Configuration;
1964 ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
1965
1966 //
1967 // Try to read NV config EFI variable first
1968 //
1969 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);
1970 ASSERT (ConfigRequestHdr != NULL);
1971
1972 NameRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, NULL, DriverHandle[0]);
1973 ASSERT (NameRequestHdr != NULL);
1974
1975 BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
1976 Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);
1977 if (EFI_ERROR (Status)) {
1978 //
1979 // Store zero data Buffer Storage to EFI variable
1980 //
1981 Status = gRT->SetVariable (
1982 VariableName,
1983 &gDriverSampleFormSetGuid,
1984 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
1986 Configuration
1987 );
1988 if (EFI_ERROR (Status)) {
1989 DriverSampleUnload (ImageHandle);
1990 return Status;
1991 }
1992
1993 //
1994 // EFI variable for NV config doesn't exit, we should build this variable
1995 // based on default values stored in IFR
1996 //
1997 ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
1998 if (!ActionFlag) {
1999 DriverSampleUnload (ImageHandle);
2000 return EFI_INVALID_PARAMETER;
2001 }
2002
2003 ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
2004 if (!ActionFlag) {
2005 DriverSampleUnload (ImageHandle);
2006 return EFI_INVALID_PARAMETER;
2007 }
2008 } else {
2009 //
2010 // EFI variable does exist and Validate Current Setting
2011 //
2012 ActionFlag = HiiValidateSettings (NameRequestHdr);
2013 if (!ActionFlag) {
2014 DriverSampleUnload (ImageHandle);
2015 return EFI_INVALID_PARAMETER;
2016 }
2017
2018 ActionFlag = HiiValidateSettings (ConfigRequestHdr);
2019 if (!ActionFlag) {
2020 DriverSampleUnload (ImageHandle);
2021 return EFI_INVALID_PARAMETER;
2022 }
2023 }
2024
2025 FreePool (ConfigRequestHdr);
2026
2027 //
2028 // Initialize efi varstore configuration data
2029 //
2030 VarStoreConfig = &mPrivateData->VarStoreConfig;
2031 ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));
2032
2033 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);
2034 ASSERT (ConfigRequestHdr != NULL);
2035
2036 BufferSize = sizeof (MY_EFI_VARSTORE_DATA);
2037 Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);
2038 if (EFI_ERROR (Status)) {
2039 //
2040 // Store zero data to EFI variable Storage.
2041 //
2042 Status = gRT->SetVariable (
2043 MyEfiVar,
2044 &gDriverSampleFormSetGuid,
2045 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
2046 sizeof (MY_EFI_VARSTORE_DATA),
2047 VarStoreConfig
2048 );
2049 if (EFI_ERROR (Status)) {
2050 DriverSampleUnload (ImageHandle);
2051 return Status;
2052 }
2053
2054 //
2055 // EFI variable for NV config doesn't exit, we should build this variable
2056 // based on default values stored in IFR
2057 //
2058 ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
2059 if (!ActionFlag) {
2060 DriverSampleUnload (ImageHandle);
2061 return EFI_INVALID_PARAMETER;
2062 }
2063 } else {
2064 //
2065 // EFI variable does exist and Validate Current Setting
2066 //
2067 ActionFlag = HiiValidateSettings (ConfigRequestHdr);
2068 if (!ActionFlag) {
2069 DriverSampleUnload (ImageHandle);
2070 return EFI_INVALID_PARAMETER;
2071 }
2072 }
2073
2074 FreePool (ConfigRequestHdr);
2075
2076 //
2077 // Initialize Bits efi varstore configuration data
2078 //
2079 BitsVarStoreConfig = &mPrivateData->BitsVarStoreConfig;
2080 ZeroMem (BitsVarStoreConfig, sizeof (MY_EFI_BITS_VARSTORE_DATA));
2081
2082 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiBitVar, DriverHandle[0]);
2083 ASSERT (ConfigRequestHdr != NULL);
2084
2085 BufferSize = sizeof (MY_EFI_BITS_VARSTORE_DATA);
2086 Status = gRT->GetVariable (MyEfiBitVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, BitsVarStoreConfig);
2087 if (EFI_ERROR (Status)) {
2088 //
2089 // Store zero data to EFI variable Storage.
2090 //
2091 Status = gRT->SetVariable (
2092 MyEfiBitVar,
2093 &gDriverSampleFormSetGuid,
2094 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
2096 BitsVarStoreConfig
2097 );
2098 if (EFI_ERROR (Status)) {
2099 DriverSampleUnload (ImageHandle);
2100 return Status;
2101 }
2102
2103 //
2104 // EFI variable for NV config doesn't exit, we should build this variable
2105 // based on default values stored in IFR
2106 //
2107 ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
2108 if (!ActionFlag) {
2109 DriverSampleUnload (ImageHandle);
2110 return EFI_INVALID_PARAMETER;
2111 }
2112 } else {
2113 //
2114 // EFI variable does exist and Validate Current Setting
2115 //
2116 ActionFlag = HiiValidateSettings (ConfigRequestHdr);
2117 if (!ActionFlag) {
2118 DriverSampleUnload (ImageHandle);
2119 return EFI_INVALID_PARAMETER;
2120 }
2121 }
2122
2123 FreePool (ConfigRequestHdr);
2124
2125 //
2126 // Initialize Union efi varstore configuration data
2127 //
2128 UnionConfig = &mPrivateData->UnionConfig;
2129 ZeroMem (UnionConfig, sizeof (MY_EFI_UNION_DATA));
2130
2131 ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiUnionVar, DriverHandle[0]);
2132 ASSERT (ConfigRequestHdr != NULL);
2133
2134 BufferSize = sizeof (MY_EFI_UNION_DATA);
2135 Status = gRT->GetVariable (MyEfiUnionVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, UnionConfig);
2136 if (EFI_ERROR (Status)) {
2137 //
2138 // Store zero data to EFI variable Storage.
2139 //
2140 Status = gRT->SetVariable (
2141 MyEfiUnionVar,
2142 &gDriverSampleFormSetGuid,
2143 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
2144 sizeof (MY_EFI_UNION_DATA),
2145 UnionConfig
2146 );
2147 if (EFI_ERROR (Status)) {
2148 DriverSampleUnload (ImageHandle);
2149 return Status;
2150 }
2151
2152 //
2153 // EFI variable for NV config doesn't exit, we should build this variable
2154 // based on default values stored in IFR
2155 //
2156 ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
2157 if (!ActionFlag) {
2158 DriverSampleUnload (ImageHandle);
2159 return EFI_INVALID_PARAMETER;
2160 }
2161 } else {
2162 //
2163 // EFI variable does exist and Validate Current Setting
2164 //
2165 ActionFlag = HiiValidateSettings (ConfigRequestHdr);
2166 if (!ActionFlag) {
2167 DriverSampleUnload (ImageHandle);
2168 return EFI_INVALID_PARAMETER;
2169 }
2170 }
2171
2172 FreePool (ConfigRequestHdr);
2173
2174 Status = gBS->CreateEventEx (
2175 EVT_NOTIFY_SIGNAL,
2176 TPL_NOTIFY,
2178 NULL,
2179 &gEfiIfrRefreshIdOpGuid,
2180 &mEvent
2181 );
2182 ASSERT_EFI_ERROR (Status);
2183
2184 //
2185 // Example of how to use BrowserEx protocol to register HotKey.
2186 //
2187 Status = gBS->LocateProtocol (&gEdkiiFormBrowserExProtocolGuid, NULL, (VOID **)&FormBrowserEx);
2188 if (!EFI_ERROR (Status)) {
2189 //
2190 // First unregister the default hot key F9 and F10.
2191 //
2192 HotKey.UnicodeChar = CHAR_NULL;
2193 HotKey.ScanCode = SCAN_F9;
2194 FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
2195 HotKey.ScanCode = SCAN_F10;
2196 FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
2197
2198 //
2199 // Register the default HotKey F9 and F10 again.
2200 //
2201 HotKey.ScanCode = SCAN_F10;
2202 NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL);
2203 ASSERT (NewString != NULL);
2204 FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);
2205 HotKey.ScanCode = SCAN_F9;
2206 NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL);
2207 ASSERT (NewString != NULL);
2208 FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);
2209 }
2210
2211 //
2212 // In default, this driver is built into Flash device image,
2213 // the following code doesn't run.
2214 //
2215
2216 //
2217 // Example of how to display only the item we sent to HII
2218 // When this driver is not built into Flash device image,
2219 // it need to call SendForm to show front page by itself.
2220 //
2221 if (DISPLAY_ONLY_MY_ITEM <= 1) {
2222 //
2223 // Have the browser pull out our copy of the data, and only display our data
2224 //
2225 Status = FormBrowser2->SendForm (
2226 FormBrowser2,
2227 &(HiiHandle[DISPLAY_ONLY_MY_ITEM]),
2228 1,
2229 NULL,
2230 0,
2231 NULL,
2232 NULL
2233 );
2234
2235 HiiRemovePackages (HiiHandle[0]);
2236
2237 HiiRemovePackages (HiiHandle[1]);
2238 }
2239
2240 return EFI_SUCCESS;
2241}
2242
2251EFIAPI
2253 IN EFI_HANDLE ImageHandle
2254 )
2255{
2256 UINTN Index;
2257
2258 ASSERT (mPrivateData != NULL);
2259
2260 if (DriverHandle[0] != NULL) {
2261 gBS->UninstallMultipleProtocolInterfaces (
2262 DriverHandle[0],
2263 &gEfiDevicePathProtocolGuid,
2264 &mHiiVendorDevicePath0,
2265 &gEfiHiiConfigAccessProtocolGuid,
2266 &mPrivateData->ConfigAccess,
2267 NULL
2268 );
2269 DriverHandle[0] = NULL;
2270 }
2271
2272 if (DriverHandle[1] != NULL) {
2273 gBS->UninstallMultipleProtocolInterfaces (
2274 DriverHandle[1],
2275 &gEfiDevicePathProtocolGuid,
2276 &mHiiVendorDevicePath1,
2277 &gEfiHiiConfigAccessProtocolGuid,
2278 &mPrivateData->ConfigAccess,
2279 NULL
2280 );
2281 DriverHandle[1] = NULL;
2282 }
2283
2284 if (mPrivateData->HiiHandle[0] != NULL) {
2285 HiiRemovePackages (mPrivateData->HiiHandle[0]);
2286 }
2287
2288 if (mPrivateData->HiiHandle[1] != NULL) {
2289 HiiRemovePackages (mPrivateData->HiiHandle[1]);
2290 }
2291
2292 for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
2293 if (mPrivateData->NameValueName[Index] != NULL) {
2294 FreePool (mPrivateData->NameValueName[Index]);
2295 }
2296 }
2297
2298 FreePool (mPrivateData);
2299 mPrivateData = NULL;
2300
2301 gBS->CloseEvent (mEvent);
2302
2303 return EFI_SUCCESS;
2304}
UINT64 UINTN
UINT64 EFIAPI StrHexToUint64(IN CONST CHAR16 *String)
Definition: String.c:560
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
UINTN EFIAPI StrnLenS(IN CONST CHAR16 *String, IN UINTN MaxSize)
Definition: SafeString.c:119
INTN EFIAPI StrnCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString, IN UINTN Length)
Definition: String.c:162
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
Definition: SafeString.c:310
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_VENDOR_DP
Definition: DevicePath.h:133
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
EFI_STATUS LoadNameValueNames(IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData)
Definition: DriverSample.c:258
EFI_STATUS EFIAPI ExtractConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Request, OUT EFI_STRING *Progress, OUT EFI_STRING *Results)
Definition: DriverSample.c:590
EFI_STATUS EFIAPI DriverSampleUnload(IN EFI_HANDLE ImageHandle)
EFI_STATUS EFIAPI NotificationFunction(IN EFI_KEY_DATA *KeyData)
Definition: DriverSample.c:117
VOID AppendAltCfgString(IN OUT EFI_STRING *RequestResult, IN EFI_STRING ConfigRequestHdr)
Definition: DriverSample.c:459
EFI_STRING CreateAltCfgString(IN EFI_STRING Result, IN EFI_STRING ConfigHdr, IN UINTN Offset, IN UINTN Width)
Definition: DriverSample.c:381
EFI_STATUS EFIAPI InternalStartMonitor(VOID)
Definition: DriverSample.c:134
EFI_STATUS GetValueOfNumber(IN EFI_STRING StringPtr, OUT UINT8 **Number, OUT UINTN *Len)
Definition: DriverSample.c:301
VOID SetArrayData(IN VOID *Array, IN UINT8 Type, IN UINTN Index, IN UINT64 Value)
Definition: DriverSample.c:77
EFI_STATUS EFIAPI DriverCallback(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN EFI_BROWSER_ACTION Action, IN EFI_QUESTION_ID QuestionId, IN UINT8 Type, IN EFI_IFR_TYPE_VALUE *Value, OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest)
EFI_STATUS EFIAPI DriverSampleInit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI RouteConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Configuration, OUT EFI_STRING *Progress)
Definition: DriverSample.c:866
EFI_STATUS EFIAPI InternalStopMonitor(VOID)
Definition: DriverSample.c:195
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING EFIAPI HiiConstructConfigHdr(IN CONST EFI_GUID *Guid OPTIONAL, IN CONST CHAR16 *Name OPTIONAL, IN EFI_HANDLE DriverHandle)
Definition: HiiLib.c:723
UINT8 *EFIAPI HiiCreateDateOpCode(IN VOID *OpCodeHandle, IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId OPTIONAL, IN UINT16 VarOffset OPTIONAL, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 DateFlags, IN VOID *DefaultsOpCodeHandle OPTIONAL)
Definition: HiiLib.c:4081
BOOLEAN EFIAPI HiiGetBrowserData(IN CONST EFI_GUID *VariableGuid OPTIONAL, IN CONST CHAR16 *VariableName OPTIONAL, IN UINTN BufferSize, OUT UINT8 *Buffer)
Definition: HiiLib.c:2872
UINT8 *EFIAPI HiiCreateGotoOpCode(IN VOID *OpCodeHandle, IN EFI_FORM_ID FormId, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN EFI_QUESTION_ID QuestionId)
Definition: HiiLib.c:3551
VOID *EFIAPI HiiAllocateOpCodeHandle(VOID)
Definition: HiiLib.c:3051
UINT8 *EFIAPI HiiCreateTimeOpCode(IN VOID *OpCodeHandle, IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId OPTIONAL, IN UINT16 VarOffset OPTIONAL, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 TimeFlags, IN VOID *DefaultsOpCodeHandle OPTIONAL)
Definition: HiiLib.c:4146
VOID EFIAPI HiiFreeOpCodeHandle(VOID *OpCodeHandle)
Definition: HiiLib.c:3085
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
UINT8 *EFIAPI HiiCreateGuidOpCode(IN VOID *OpCodeHandle, IN CONST EFI_GUID *Guid, IN CONST VOID *GuidOpCode OPTIONAL, IN UINTN OpCodeSize)
Definition: HiiLib.c:3411
BOOLEAN EFIAPI HiiSetBrowserData(IN CONST EFI_GUID *VariableGuid OPTIONAL, IN CONST CHAR16 *VariableName OPTIONAL, IN UINTN BufferSize, IN CONST UINT8 *Buffer, IN CONST CHAR16 *RequestElement OPTIONAL)
Definition: HiiLib.c:2954
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
UINT8 *EFIAPI HiiCreateOneOfOptionOpCode(IN VOID *OpCodeHandle, IN UINT16 StringId, IN UINT8 Flags, IN UINT8 Type, IN UINT64 Value)
Definition: HiiLib.c:3329
EFI_STATUS EFIAPI HiiUpdateForm(IN EFI_HII_HANDLE HiiHandle, IN EFI_GUID *FormSetGuid OPTIONAL, IN EFI_FORM_ID FormId, IN VOID *StartOpCodeHandle, IN VOID *EndOpCodeHandle OPTIONAL)
Definition: HiiLib.c:4410
BOOLEAN EFIAPI HiiIsConfigHdrMatch(IN CONST EFI_STRING ConfigHdr, IN CONST EFI_GUID *Guid OPTIONAL, IN CONST CHAR16 *Name OPTIONAL)
Definition: HiiLib.c:2813
UINT8 *EFIAPI HiiCreateOneOfOpCode(IN VOID *OpCodeHandle, IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 OneOfFlags, IN VOID *OptionsOpCodeHandle, IN VOID *DefaultsOpCodeHandle OPTIONAL)
Definition: HiiLib.c:3908
EFI_STRING_ID EFIAPI HiiSetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId OPTIONAL, IN CONST EFI_STRING String, IN CONST CHAR8 *SupportedLanguages OPTIONAL)
Definition: HiiString.c:52
UINT8 *EFIAPI HiiCreateActionOpCode(IN VOID *OpCodeHandle, IN EFI_QUESTION_ID QuestionId, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN EFI_STRING_ID QuestionConfig)
Definition: HiiLib.c:3461
UINT8 *EFIAPI HiiCreateOrderedListOpCode(IN VOID *OpCodeHandle, IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 OrderedListFlags, IN UINT8 DataType, IN UINT8 MaxContainers, IN VOID *OptionsOpCodeHandle, IN VOID *DefaultsOpCodeHandle OPTIONAL)
Definition: HiiLib.c:3979
UINT8 *EFIAPI HiiCreateTextOpCode(IN VOID *OpCodeHandle, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN EFI_STRING_ID TextTwo)
Definition: HiiLib.c:4037
BOOLEAN EFIAPI HiiValidateSettings(IN CONST EFI_STRING Request OPTIONAL)
Definition: HiiLib.c:2689
BOOLEAN EFIAPI HiiSetToDefaults(IN CONST EFI_STRING Request OPTIONAL, IN UINT16 DefaultId)
Definition: HiiLib.c:2714
VOID EFIAPI HiiRemovePackages(IN EFI_HII_HANDLE HiiHandle)
Definition: HiiLib.c:253
#define EFI_IFR_EXTEND_OP_LABEL
Definition: MdeModuleHii.h:33
RETURN_STATUS EFIAPI UnicodeValueToStringS(IN OUT CHAR16 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN INT64 Value, IN UINTN Width)
Definition: PrintLib.c:652
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
EFI_STRING_ID NewString(IN CHAR16 *String, IN EFI_HII_HANDLE HiiHandle)
Definition: Setup.c:981
VOID EFIAPI Exit(IN EFI_STATUS Status)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
VOID * EFI_HII_HANDLE
VOID EFIAPI EfiEventEmptyFunction(IN EFI_EVENT Event, IN VOID *Context)
Definition: UefiLib.c:354
VOID EFIAPI CreatePopUp(IN UINTN Attribute, OUT EFI_INPUT_KEY *Key OPTIONAL,...)
Definition: Console.c:393
#define EFI_VARIABLE_NON_VOLATILE
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_KEY_TOGGLE_STATE KeyToggleState
UINT32 KeyShiftState
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
EFI_INPUT_KEY Key
EFI_KEY_STATE KeyState
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064