2 Utility functions which helps in opcode creation, HII configuration string manipulations,
3 pop up window creations, setup browser persistence data set and get.
5 Copyright (c) 2007- 2008, Intel Corporation
6 All rights reserved. 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
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.
16 #include "UefiIfrLibraryInternal.h"
18 CONST EFI_FORM_BROWSER2_PROTOCOL
*mFormBrowser2
= NULL
;
19 CONST EFI_HII_CONFIG_ROUTING_PROTOCOL
*mIfrSupportLibHiiConfigRouting
= NULL
;
22 This function locate FormBrowser2 protocols for later usage.
24 @return Status the status to locate protocol.
27 LocateFormBrowser2Protocols (
33 // Locate protocols for later usage
35 if (mFormBrowser2
== NULL
) {
36 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mFormBrowser2
);
37 if (EFI_ERROR (Status
)) {
42 if (mIfrSupportLibHiiConfigRouting
== NULL
) {
43 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &mIfrSupportLibHiiConfigRouting
);
44 if (EFI_ERROR (Status
)) {
55 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mFakeConfigHdr
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=0";
58 Draw a dialog and return the selected key.
60 @param NumberOfLines The number of lines for the dialog box
61 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
62 @param String The first String to be displayed in the Pop-Up.
63 @param Marker A series of (quantity == NumberOfLines - 1) text
64 strings which will be used to construct the dialog
67 @retval EFI_SUCCESS Displayed dialog and received user interaction
68 @retval EFI_INVALID_PARAMETER One of the parameters was invalid.
69 @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.
75 IN UINTN NumberOfLines
,
76 OUT EFI_INPUT_KEY
*KeyValue
,
90 UINTN DimensionsWidth
;
91 UINTN DimensionsHeight
;
100 EFI_EVENT WaitList
[2];
101 UINTN CurrentAttribute
;
102 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ConOut
;
104 if ((KeyValue
== NULL
) || (String
== NULL
)) {
105 return EFI_INVALID_PARAMETER
;
113 ConOut
= gST
->ConOut
;
114 ConOut
->QueryMode (ConOut
, ConOut
->Mode
->Mode
, &RightColumn
, &BottomRow
);
116 DimensionsWidth
= RightColumn
- LeftColumn
;
117 DimensionsHeight
= BottomRow
- TopRow
;
119 CurrentAttribute
= ConOut
->Mode
->Attribute
;
121 LineBuffer
= AllocateZeroPool (DimensionsWidth
* sizeof (CHAR16
));
122 if (LineBuffer
== NULL
) {
123 return EFI_OUT_OF_RESOURCES
;
127 // Determine the largest string in the dialog box
128 // Notice we are starting with 1 since String is the first string
130 StringArray
= AllocateZeroPool (NumberOfLines
* sizeof (CHAR16
*));
131 if (StringArray
== NULL
) {
132 FreePool (LineBuffer
);
133 return EFI_OUT_OF_RESOURCES
;
135 LargestString
= StrLen (String
);
136 StringArray
[0] = String
;
138 for (Index
= 1; Index
< NumberOfLines
; Index
++) {
139 StackString
= VA_ARG (Marker
, CHAR16
*);
141 if (StackString
== NULL
) {
142 FreePool (LineBuffer
);
143 FreePool (StringArray
);
144 return EFI_INVALID_PARAMETER
;
147 StringArray
[Index
] = StackString
;
148 StringLen
= StrLen (StackString
);
149 if (StringLen
> LargestString
) {
150 LargestString
= StringLen
;
154 if ((LargestString
+ 2) > DimensionsWidth
) {
155 LargestString
= DimensionsWidth
- 2;
159 // Subtract the PopUp width from total Columns, allow for one space extra on
160 // each end plus a border.
162 Start
= (DimensionsWidth
- LargestString
- 2) / 2 + LeftColumn
+ 1;
164 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + TopRow
- 1;
169 ConOut
->EnableCursor (ConOut
, FALSE
);
170 ConOut
->SetAttribute (ConOut
, EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
);
172 StringPtr
= &LineBuffer
[0];
173 *StringPtr
++ = BOXDRAW_DOWN_RIGHT
;
174 for (Index
= 0; Index
< LargestString
; Index
++) {
175 *StringPtr
++ = BOXDRAW_HORIZONTAL
;
177 *StringPtr
++ = BOXDRAW_DOWN_LEFT
;
180 ConOut
->SetCursorPosition (ConOut
, Start
, Top
);
181 ConOut
->OutputString (ConOut
, LineBuffer
);
183 for (Index
= 0; Index
< NumberOfLines
; Index
++) {
184 StringPtr
= &LineBuffer
[0];
185 *StringPtr
++ = BOXDRAW_VERTICAL
;
187 for (Count
= 0; Count
< LargestString
; Count
++) {
188 StringPtr
[Count
] = L
' ';
191 StringLen
= StrLen (StringArray
[Index
]);
192 if (StringLen
> LargestString
) {
193 StringLen
= LargestString
;
196 StringPtr
+ ((LargestString
- StringLen
) / 2),
198 StringLen
* sizeof (CHAR16
)
200 StringPtr
+= LargestString
;
202 *StringPtr
++ = BOXDRAW_VERTICAL
;
205 ConOut
->SetCursorPosition (ConOut
, Start
, Top
+ 1 + Index
);
206 ConOut
->OutputString (ConOut
, LineBuffer
);
209 StringPtr
= &LineBuffer
[0];
210 *StringPtr
++ = BOXDRAW_UP_RIGHT
;
211 for (Index
= 0; Index
< LargestString
; Index
++) {
212 *StringPtr
++ = BOXDRAW_HORIZONTAL
;
214 *StringPtr
++ = BOXDRAW_UP_LEFT
;
217 ConOut
->SetCursorPosition (ConOut
, Start
, Top
+ NumberOfLines
+ 1);
218 ConOut
->OutputString (ConOut
, LineBuffer
);
221 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
224 // Set a timer event of 1 second expiration
233 // Wait for the keystroke event or the timer
235 WaitList
[0] = gST
->ConIn
->WaitForKey
;
236 WaitList
[1] = TimerEvent
;
237 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
240 // Check for the timer expiration
242 if (!EFI_ERROR (Status
) && Index
== 1) {
243 Status
= EFI_TIMEOUT
;
246 gBS
->CloseEvent (TimerEvent
);
247 } while (Status
== EFI_TIMEOUT
);
249 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
250 CopyMem (KeyValue
, &Key
, sizeof (EFI_INPUT_KEY
));
252 ConOut
->SetAttribute (ConOut
, CurrentAttribute
);
253 ConOut
->EnableCursor (ConOut
, TRUE
);
255 FreePool (LineBuffer
);
256 FreePool (StringArray
);
263 Draw a dialog and return the selected key.
265 @param NumberOfLines The number of lines for the dialog box
266 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
267 @param String Pointer to the first string in the list
268 @param ... A series of (quantity == NumberOfLines - 1) text
269 strings which will be used to construct the dialog
272 @retval EFI_SUCCESS Displayed dialog and received user interaction
273 @retval EFI_INVALID_PARAMETER One of the parameters was invalid.
279 IN UINTN NumberOfLines
,
280 OUT EFI_INPUT_KEY
*KeyValue
,
288 VA_START (Marker
, String
);
290 Status
= IfrLibCreatePopUp2 (NumberOfLines
, KeyValue
, String
, Marker
);
298 Extract block name from the array generated by VFR compiler. The name of
299 this array is "Vfr + <StorageName> + BlockName", e.g. "VfrMyIfrNVDataBlockName".
300 Format of this array is:
301 Array length | 4-bytes
308 @param Buffer Array generated by VFR compiler.
309 @param BlockName The returned <BlockName>
311 @retval EFI_OUT_OF_RESOURCES Run out of memory resource.
312 @retval EFI_INVALID_PARAMETER Buffer is NULL or BlockName is NULL.
313 @retval EFI_SUCCESS Operation successful.
319 OUT CHAR16
**BlockName
325 UINT32 BlockNameNumber
;
326 UINTN HexStringBufferLen
;
329 if ((Buffer
== NULL
) || (BlockName
== NULL
)) {
330 return EFI_INVALID_PARAMETER
;
334 // Calculate number of Offset/Width pair
336 CopyMem (&Length
, Buffer
, sizeof (UINT32
));
337 BlockNameNumber
= (Length
- sizeof (UINT32
)) / (sizeof (UINT16
) * 2);
340 // <BlockName> ::= &OFFSET=1234&WIDTH=1234
343 StringPtr
= AllocateZeroPool ((BlockNameNumber
* (8 + 4 + 7 + 4) + 1) * sizeof (CHAR16
));
344 *BlockName
= StringPtr
;
345 if (StringPtr
== NULL
) {
346 return EFI_OUT_OF_RESOURCES
;
349 Buffer
+= sizeof (UINT32
);
350 for (Index
= 0; Index
< BlockNameNumber
; Index
++) {
351 StrCpy (StringPtr
, L
"&OFFSET=");
354 HexStringBufferLen
= 5;
355 BufToHexString (StringPtr
, &HexStringBufferLen
, Buffer
, sizeof (UINT16
));
356 Buffer
+= sizeof (UINT16
);
359 StrCpy (StringPtr
, L
"&WIDTH=");
362 HexStringBufferLen
= 5;
363 BufToHexString (StringPtr
, &HexStringBufferLen
, Buffer
, sizeof (UINT16
));
364 Buffer
+= sizeof (UINT16
);
373 Extract block config from the array generated by VFR compiler. The name of
374 this array is "Vfr + <StorageName> + Default<HexCh>4", e.g. "VfrMyIfrNVDataDefault0000".
376 @param Buffer - Array generated by VFR compiler.
377 @param BlockConfig - The returned <BlockConfig>
379 @retval EFI_OUT_OF_RESOURCES - Run out of memory resource.
380 @retval EFI_INVALID_PARAMETER - Buffer is NULL or BlockConfig is NULL.
381 @retval EFI_SUCCESS - Operation successful.
387 OUT CHAR16
**BlockConfig
392 UINTN HexStringBufferLen
;
398 if ((Buffer
== NULL
) || (BlockConfig
== NULL
)) {
399 return EFI_INVALID_PARAMETER
;
403 // Calculate length of AltResp string
404 // Format of Default value array is:
405 // Array length | 4-bytes
408 // Value | Variable length
411 // Value | Variable length
413 // When value is 1 byte in length, overhead of AltResp string will be maximum,
414 // BlockConfig ::= <&OFFSET=1234&WIDTH=1234&VALUE=12>+
415 // | 8 | 4 | 7 | 4 | 7 |2|
416 // so the maximum length of BlockConfig could be calculated as:
417 // (ArrayLength / 5) * (8 + 4 + 7 + 4 + 7 + 2) = ArrayLength * 6.4 < ArrayLength * 7
419 CopyMem (&Length
, Buffer
, sizeof (UINT32
));
420 BufferEnd
= Buffer
+ Length
;
421 StringPtr
= AllocatePool (Length
* 7 * sizeof (CHAR16
));
422 *BlockConfig
= StringPtr
;
423 if (StringPtr
== NULL
) {
424 return EFI_OUT_OF_RESOURCES
;
426 StringEnd
= StringPtr
+ (Length
* 7);
428 Buffer
+= sizeof (UINT32
);
429 while (Buffer
< BufferEnd
) {
430 StrCpy (StringPtr
, L
"&OFFSET=");
433 HexStringBufferLen
= 5;
434 BufToHexString (StringPtr
, &HexStringBufferLen
, Buffer
, sizeof (UINT16
));
435 Buffer
+= sizeof (UINT16
);
438 StrCpy (StringPtr
, L
"&WIDTH=");
441 HexStringBufferLen
= 5;
442 BufToHexString (StringPtr
, &HexStringBufferLen
, Buffer
, sizeof (UINT16
));
443 CopyMem (&Width
, Buffer
, sizeof (UINT16
));
444 Buffer
+= sizeof (UINT16
);
447 StrCpy (StringPtr
, L
"&VALUE=");
450 HexStringBufferLen
= StringEnd
- StringPtr
;
451 Status
= BufToHexString (StringPtr
, &HexStringBufferLen
, Buffer
, Width
);
452 if (EFI_ERROR (Status
)) {
456 StringPtr
+= (Width
* 2);
463 Construct <ConfigAltResp> for a buffer storage.
465 @param ConfigRequest The Config request string. If set to NULL, all the
466 configurable elements will be extracted from BlockNameArray.
467 @param ConfigAltResp The returned <ConfigAltResp>.
468 @param Progress On return, points to a character in the Request.
469 @param Guid GUID of the buffer storage.
470 @param Name Name of the buffer storage.
471 @param DriverHandle The DriverHandle which is used to invoke HiiDatabase
472 protocol interface NewPackageList().
473 @param BufferStorage Content of the buffer storage.
474 @param BufferStorageSize Length in bytes of the buffer storage.
475 @param BlockNameArray Array generated by VFR compiler.
476 @param NumberAltCfg Number of Default value array generated by VFR compiler.
477 The sequential input parameters will be number of
478 AltCfgId and DefaultValueArray pairs. When set to 0,
479 there will be no <AltResp>.
481 retval EFI_OUT_OF_RESOURCES Run out of memory resource.
482 retval EFI_INVALID_PARAMETER ConfigAltResp is NULL.
483 retval EFI_SUCCESS Operation successful.
487 ConstructConfigAltResp (
488 IN EFI_STRING ConfigRequest
, OPTIONAL
489 OUT EFI_STRING
*Progress
,
490 OUT EFI_STRING
*ConfigAltResp
,
493 IN EFI_HANDLE
*DriverHandle
,
494 IN VOID
*BufferStorage
,
495 IN UINTN BufferStorageSize
,
496 IN VOID
*BlockNameArray
, OPTIONAL
497 IN UINTN NumberAltCfg
,
499 //IN UINT16 AltCfgId,
500 //IN VOID *DefaultValueArray,
510 VOID
*DefaultValueArray
;
512 EFI_STRING ConfigResp
;
517 BOOLEAN NeedFreeConfigRequest
;
518 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
521 if (ConfigAltResp
== NULL
) {
522 return EFI_INVALID_PARAMETER
;
526 // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..."
530 Status
= ConstructConfigHdr (
537 if (Status
== EFI_BUFFER_TOO_SMALL
) {
538 ConfigHdr
= AllocateZeroPool (StrBufferLen
);
539 Status
= ConstructConfigHdr (
548 if (EFI_ERROR (Status
)) {
553 // Construct <ConfigResp>
555 NeedFreeConfigRequest
= FALSE
;
556 if (ConfigRequest
== NULL
) {
558 // If ConfigRequest is set to NULL, export all configurable elements in BlockNameArray
560 Status
= ExtractBlockName (BlockNameArray
, &BlockName
);
561 if (EFI_ERROR (Status
)) {
565 Len
= StrSize (ConfigHdr
);
566 ConfigRequest
= AllocateZeroPool (Len
+ StrSize (BlockName
) - sizeof (CHAR16
));
567 StrCpy (ConfigRequest
, ConfigHdr
);
568 StrCat (ConfigRequest
, BlockName
);
569 NeedFreeConfigRequest
= TRUE
;
572 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
573 if (EFI_ERROR (Status
)) {
577 Status
= HiiConfigRouting
->BlockToConfig (
583 (Progress
== NULL
) ? &TempStr
: Progress
585 if (EFI_ERROR (Status
)) {
590 // Construct <AltResp>
592 DescHdr
= AllocateZeroPool (NumberAltCfg
* 16 * sizeof (CHAR16
));
594 AltCfg
= AllocateZeroPool (NumberAltCfg
* sizeof (CHAR16
*));
596 VA_START (Args
, NumberAltCfg
);
597 for (Index
= 0; Index
< NumberAltCfg
; Index
++) {
598 AltCfgId
= (UINT16
) VA_ARG (Args
, UINT16
);
599 DefaultValueArray
= (UINT8
*) VA_ARG (Args
, VOID
*);
604 AltRespLen
+= (StrLen (ConfigHdr
) + 1);
606 StringPtr
= DescHdr
+ Index
* 16;
607 StrCpy (StringPtr
, L
"&ALTCFG=");
608 AltRespLen
+= (8 + sizeof (UINT16
) * 2);
611 BufToHexString (StringPtr
+ 8, &StrBufferLen
, (UINT8
*) &AltCfgId
, sizeof (UINT16
));
612 Status
= ExtractBlockConfig (DefaultValueArray
, &AltCfg
[Index
]);
613 if (EFI_ERROR (Status
)) {
616 AltRespLen
+= StrLen (AltCfg
[Index
]);
621 // Generate the final <ConfigAltResp>
623 StrBufferLen
= (StrLen ((CHAR16
*) ConfigResp
) + AltRespLen
+ 1) * sizeof (CHAR16
);
624 TempStr
= AllocateZeroPool (StrBufferLen
);
625 *ConfigAltResp
= TempStr
;
626 if (TempStr
== NULL
) {
627 return EFI_OUT_OF_RESOURCES
;
631 // <ConfigAltResp> ::= <ConfigResp> ['&' <AltResp>]*
633 StrCpy (TempStr
, ConfigResp
);
634 for (Index
= 0; Index
< NumberAltCfg
; Index
++) {
635 StrCat (TempStr
, L
"&");
636 StrCat (TempStr
, ConfigHdr
);
637 StrCat (TempStr
, DescHdr
+ Index
* 16);
638 StrCat (TempStr
, AltCfg
[Index
]);
640 gBS
->FreePool (AltCfg
[Index
]);
643 if (NeedFreeConfigRequest
) {
644 gBS
->FreePool (ConfigRequest
);
646 gBS
->FreePool (ConfigHdr
);
647 gBS
->FreePool (ConfigResp
);
648 gBS
->FreePool (DescHdr
);
649 gBS
->FreePool (AltCfg
);
655 Swap bytes in the buffer. This is a internal function.
657 @param Buffer Binary buffer.
658 @param BufferSize Size of the buffer in bytes.
665 IN OUT UINT8
*Buffer
,
673 SwapCount
= BufferSize
/ 2;
674 for (Index
= 0; Index
< SwapCount
; Index
++) {
675 Temp
= Buffer
[Index
];
676 Buffer
[Index
] = Buffer
[BufferSize
- 1 - Index
];
677 Buffer
[BufferSize
- 1 - Index
] = Temp
;
682 Converts the unicode character of the string from uppercase to lowercase.
683 This is a internal function.
685 @param Str String to be converted
696 for (Ptr
= Str
; *Ptr
!= L
'\0'; Ptr
++) {
697 if (*Ptr
>= L
'A' && *Ptr
<= L
'Z') {
698 *Ptr
= (CHAR16
) (*Ptr
- L
'A' + L
'a');
705 Converts binary buffer to Unicode string in reversed byte order from BufToHexString().
707 @param Str String for output
708 @param Buffer Binary buffer.
709 @param BufferSize Size of the buffer in bytes.
711 @retval EFI_SUCCESS The function completed successfully.
712 @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.
717 BufInReverseOrderToHexString (
727 NewBuffer
= AllocateCopyPool (BufferSize
, Buffer
);
728 if (NewBuffer
== NULL
) {
729 return EFI_OUT_OF_RESOURCES
;
731 SwapBuffer (NewBuffer
, BufferSize
);
733 StrBufferLen
= BufferSize
* sizeof (CHAR16
) + 1;
734 Status
= BufToHexString (Str
, &StrBufferLen
, NewBuffer
, BufferSize
);
736 FreePool (NewBuffer
);
738 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
747 Converts Hex String to binary buffer in reversed byte order from HexStringToBuf().
749 @param Buffer Pointer to buffer that receives the data.
750 @param BufferSize Length in bytes of the buffer to hold converted
751 data. If routine return with EFI_SUCCESS,
752 containing length of converted data. If routine
753 return with EFI_BUFFER_TOO_SMALL, containg length
755 @param Str String to be converted from.
757 @retval EFI_SUCCESS The function completed successfully.
758 @retval RETURN_BUFFER_TOO_SMALL The input BufferSize is too small to hold the output. BufferSize
759 will be updated to the size required for the converstion.
764 HexStringToBufInReverseOrder (
765 IN OUT UINT8
*Buffer
,
766 IN OUT UINTN
*BufferSize
,
771 UINTN ConvertedStrLen
;
774 Status
= HexStringToBuf (Buffer
, BufferSize
, Str
, &ConvertedStrLen
);
775 if (!EFI_ERROR (Status
)) {
776 SwapBuffer (Buffer
, (ConvertedStrLen
+ 1) / 2);
783 Convert binary representation Config string (e.g. "0041004200430044") to the
784 original string (e.g. "ABCD"). Config string appears in <ConfigHdr> (i.e.
785 "&NAME=<string>"), or Name/Value pair in <ConfigBody> (i.e. "label=<string>").
787 @param UnicodeString Original Unicode string.
788 @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string.
789 Includes tailing '\0' character.
791 If return EFI_SUCCESS, containing length of Unicode string buffer.
792 If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.
793 @param ConfigString Binary representation of Unicode String, <string> := (<HexCh>4)+
795 @retval EFI_SUCCESS Operation completes successfully.
796 @retval EFI_BUFFER_TOO_SMALL The string buffer is too small.
801 ConfigStringToUnicode (
802 IN OUT CHAR16
*UnicodeString
,
803 IN OUT UINTN
*StrBufferLen
,
804 IN CHAR16
*ConfigString
812 Len
= StrLen (ConfigString
) / 4;
813 BufferSize
= (Len
+ 1) * sizeof (CHAR16
);
815 if (*StrBufferLen
< BufferSize
) {
816 *StrBufferLen
= BufferSize
;
817 return EFI_BUFFER_TOO_SMALL
;
820 *StrBufferLen
= BufferSize
;
822 for (Index
= 0; Index
< Len
; Index
++) {
823 BackupChar
= ConfigString
[4];
824 ConfigString
[4] = L
'\0';
826 HexStringToBuf ((UINT8
*) UnicodeString
, &BufferSize
, ConfigString
, NULL
);
828 ConfigString
[4] = BackupChar
;
835 // Add tailing '\0' character
837 *UnicodeString
= L
'\0';
843 Convert Unicode string to binary representation Config string, e.g.
844 "ABCD" => "0041004200430044". Config string appears in <ConfigHdr> (i.e.
845 "&NAME=<string>"), or Name/Value pair in <ConfigBody> (i.e. "label=<string>").
847 @param ConfigString Binary representation of Unicode String, <string> := (<HexCh>4)+
848 @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string.
849 Includes tailing '\0' character.
851 If return EFI_SUCCESS, containing length of Unicode string buffer.
852 If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.
853 @param UnicodeString Original Unicode string.
855 @retval EFI_SUCCESS Operation completes successfully.
856 @retval EFI_BUFFER_TOO_SMALL The string buffer is too small.
861 UnicodeToConfigString (
862 IN OUT CHAR16
*ConfigString
,
863 IN OUT UINTN
*StrBufferLen
,
864 IN CHAR16
*UnicodeString
872 Len
= StrLen (UnicodeString
);
873 BufferSize
= (Len
* 4 + 1) * sizeof (CHAR16
);
875 if (*StrBufferLen
< BufferSize
) {
876 *StrBufferLen
= BufferSize
;
877 return EFI_BUFFER_TOO_SMALL
;
880 *StrBufferLen
= BufferSize
;
881 String
= ConfigString
;
883 for (Index
= 0; Index
< Len
; Index
++) {
884 BufToHexString (ConfigString
, &BufferSize
, (UINT8
*) UnicodeString
, 2);
891 // Add tailing '\0' character
893 *ConfigString
= L
'\0';
896 // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
903 Construct <ConfigHdr> using routing information GUID/NAME/PATH.
905 @param ConfigHdr Pointer to the ConfigHdr string.
906 @param StrBufferLen On input: Length in bytes of buffer to hold the
907 ConfigHdr string. Includes tailing '\0' character.
908 On output: If return EFI_SUCCESS, containing
909 length of ConfigHdr string buffer. If return
910 EFI_BUFFER_TOO_SMALL, containg length of string
912 @param Guid Routing information: GUID.
913 @param Name Routing information: NAME.
914 @param DriverHandle Driver handle which contains the routing
917 @retval EFI_SUCCESS Operation completes successfully.
918 @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small.
924 IN OUT CHAR16
*ConfigHdr
,
925 IN OUT UINTN
*StrBufferLen
,
926 IN CONST EFI_GUID
*Guid
,
927 IN CHAR16
*Name
, OPTIONAL
928 IN EFI_HANDLE
*DriverHandle
933 UINTN DevicePathSize
;
936 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
940 // There will be no "NAME" in <ConfigHdr> for Name/Value storage
945 // For buffer storage
947 NameStrLen
= StrLen (Name
);
951 // Retrieve DevicePath Protocol associated with this HiiPackageList
953 Status
= gBS
->HandleProtocol (
955 &gEfiDevicePathProtocolGuid
,
956 (VOID
**) &DevicePath
958 if (EFI_ERROR (Status
)) {
962 DevicePathSize
= GetDevicePathSize (DevicePath
);
965 // GUID=<HexCh>32&NAME=<Char>NameStrLen&PATH=<HexChar>DevicePathStrLen <NULL>
966 // | 5 | 32 | 6 | NameStrLen*4 | 6 | DevicePathStrLen | 1 |
968 BufferSize
= (5 + 32 + 6 + NameStrLen
* 4 + 6 + DevicePathSize
* 2 + 1) * sizeof (CHAR16
);
969 if (*StrBufferLen
< BufferSize
) {
970 *StrBufferLen
= BufferSize
;
971 return EFI_BUFFER_TOO_SMALL
;
974 *StrBufferLen
= BufferSize
;
978 StrCpy (StrPtr
, L
"GUID=");
980 BufInReverseOrderToHexString (StrPtr
, (UINT8
*) Guid
, sizeof (EFI_GUID
));
984 // Convert name string, e.g. name "ABCD" => "&NAME=0041004200430044"
986 StrCpy (StrPtr
, L
"&NAME=");
989 BufferSize
= (NameStrLen
* 4 + 1) * sizeof (CHAR16
);
990 UnicodeToConfigString (StrPtr
, &BufferSize
, Name
);
991 StrPtr
+= (NameStrLen
* 4);
994 StrCpy (StrPtr
, L
"&PATH=");
996 BufInReverseOrderToHexString (StrPtr
, (UINT8
*) DevicePath
, DevicePathSize
);
1002 Determines if the Routing data (Guid and Name) is correct in <ConfigHdr>.
1004 @param ConfigString Either <ConfigRequest> or <ConfigResp>.
1005 @param StorageGuid GUID of the storage.
1006 @param StorageName Name of the stoarge.
1008 @retval TRUE Routing information is correct in ConfigString.
1009 @retval FALSE Routing information is incorrect in ConfigString.
1014 IN EFI_STRING ConfigString
,
1015 IN EFI_GUID
*StorageGuid
, OPTIONAL
1016 IN CHAR16
*StorageName OPTIONAL
1028 // GUID=<HexCh>32&NAME=<Char>NameStrLen&PATH=<HexChar>DevicePathStrLen <NULL>
1029 // | 5 | 32 | 6 | NameStrLen*4 | 6 | DevicePathStrLen | 1 |
1031 if (StrLen (ConfigString
) <= (5 + 32 + 6)) {
1038 if (StorageGuid
!= NULL
) {
1040 StrPtr
= ConfigString
+ 5 + 32;
1041 if (*StrPtr
!= L
'&') {
1046 BufferSize
= sizeof (EFI_GUID
);
1047 Status
= HexStringToBufInReverseOrder (
1054 if (EFI_ERROR (Status
)) {
1058 if (!CompareGuid (&Guid
, StorageGuid
)) {
1067 if (StorageName
!= NULL
) {
1068 StrPtr
= ConfigString
+ 5 + 32 + 6;
1069 while (*StrPtr
!= L
'\0' && *StrPtr
!= L
'&') {
1072 if (*StrPtr
!= L
'&') {
1077 BufferSize
= (((UINTN
) StrPtr
) - ((UINTN
) &ConfigString
[5 + 32 + 6])) / 4 + sizeof (CHAR16
);
1078 Name
= AllocatePool (BufferSize
);
1079 ASSERT (Name
!= NULL
);
1080 Status
= ConfigStringToUnicode (
1083 ConfigString
+ 5 + 32 + 6
1087 if (EFI_ERROR (Status
) || (StrCmp (Name
, StorageName
) != 0)) {
1090 gBS
->FreePool (Name
);
1097 Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string.
1099 @param String The string to be searched in.
1100 @param Offset Offset in BlockName.
1101 @param Width Width in BlockName.
1103 @retval TRUE Block name found.
1104 @retval FALSE Block name not found.
1110 IN OUT CHAR16
*String
,
1118 UINTN ConvertedStrLen
;
1120 while ((String
= StrStr (String
, L
"&OFFSET=")) != NULL
) {
1124 String
= String
+ 8;
1127 BufferSize
= sizeof (UINTN
);
1128 Status
= HexStringToBuf ((UINT8
*) &Data
, &BufferSize
, String
, &ConvertedStrLen
);
1129 if (EFI_ERROR (Status
)) {
1132 String
= String
+ ConvertedStrLen
;
1134 if (Data
!= Offset
) {
1138 if (StrnCmp (String
, L
"&WIDTH=", 7) != 0) {
1141 String
= String
+ 7;
1144 BufferSize
= sizeof (UINTN
);
1145 Status
= HexStringToBuf ((UINT8
*) &Data
, &BufferSize
, String
, &ConvertedStrLen
);
1146 if (EFI_ERROR (Status
)) {
1149 if (Data
== Width
) {
1153 String
= String
+ ConvertedStrLen
;
1161 This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser.
1163 @param VariableGuid An optional field to indicate the target variable
1165 @param VariableName An optional field to indicate the target
1166 human-readable variable name.
1167 @param BufferSize On input: Length in bytes of buffer to hold
1168 retrived data. On output: If return
1169 EFI_BUFFER_TOO_SMALL, containg length of buffer
1171 @param Buffer Buffer to hold retrived data.
1173 @retval EFI_SUCCESS Operation completes successfully.
1174 @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small.
1175 @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.
1181 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
1182 IN CONST CHAR16
*VariableName
, OPTIONAL
1183 IN OUT UINTN
*BufferSize
,
1184 IN OUT UINT8
*Buffer
1188 CONST CHAR16
*ConfigHdr
;
1196 // Locate protocols for use
1198 Status
= LocateFormBrowser2Protocols ();
1199 if (EFI_ERROR (Status
)) {
1204 // Retrive formset storage data from Form Browser
1206 ConfigHdr
= mFakeConfigHdr
;
1207 HeaderLen
= StrLen (ConfigHdr
);
1210 // First try allocate 0x4000 buffer for the formet storage data.
1213 ConfigResp
= AllocateZeroPool (BufferLen
+ HeaderLen
);
1214 if (ConfigResp
== NULL
) {
1218 StringPtr
= ConfigResp
+ HeaderLen
;
1222 Status
= mFormBrowser2
->BrowserCallback (
1230 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1231 if (ConfigResp
!= NULL
) {
1232 FreePool (ConfigResp
);
1235 ConfigResp
= AllocateZeroPool (BufferLen
+ HeaderLen
);
1236 if (ConfigResp
== NULL
) {
1237 return EFI_OUT_OF_RESOURCES
;
1240 StringPtr
= ConfigResp
+ HeaderLen
;
1244 Status
= mFormBrowser2
->BrowserCallback (
1253 if (EFI_ERROR (Status
)) {
1254 FreePool (ConfigResp
);
1257 CopyMem (ConfigResp
, ConfigHdr
, HeaderLen
* sizeof (UINT16
));
1260 // Convert <ConfigResp> to buffer data
1262 Status
= mIfrSupportLibHiiConfigRouting
->ConfigToBlock (
1263 mIfrSupportLibHiiConfigRouting
,
1269 FreePool (ConfigResp
);
1276 This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser.
1278 @param VariableGuid An optional field to indicate the target variable
1280 @param VariableName An optional field to indicate the target
1281 human-readable variable name.
1282 @param BufferSize Length in bytes of buffer to hold retrived data.
1283 @param Buffer Buffer to hold retrived data.
1284 @param RequestElement An optional field to specify which part of the
1285 buffer data will be send back to Browser. If NULL,
1286 the whole buffer of data will be committed to
1287 Browser. <RequestElement> ::=
1288 &OFFSET=<Number>&WIDTH=<Number>*
1290 @retval EFI_SUCCESS Operation completes successfully.
1291 @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.
1292 @retval Other Updating Browser uncommitted data failed.
1298 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
1299 IN CONST CHAR16
*VariableName
, OPTIONAL
1300 IN UINTN BufferSize
,
1301 IN CONST UINT8
*Buffer
,
1302 IN CONST CHAR16
*RequestElement OPTIONAL
1306 CONST CHAR16
*ConfigHdr
;
1312 CHAR16 BlockName
[33];
1313 CHAR16
*ConfigRequest
;
1314 CONST CHAR16
*Request
;
1317 // Locate protocols for use
1319 Status
= LocateFormBrowser2Protocols ();
1320 if (EFI_ERROR (Status
)) {
1325 // Prepare <ConfigRequest>
1327 ConfigHdr
= mFakeConfigHdr
;
1328 HeaderLen
= StrLen (ConfigHdr
);
1330 if (RequestElement
== NULL
) {
1332 // RequestElement not specified, use "&OFFSET=0&WIDTH=<BufferSize>" as <BlockName>
1334 BlockName
[0] = L
'\0';
1335 StrCpy (BlockName
, L
"&OFFSET=0&WIDTH=");
1338 // String lenghth of L"&OFFSET=0&WIDTH=" is 16
1340 StringPtr
= BlockName
+ 16;
1341 BufferLen
= sizeof (BlockName
) - (16 * sizeof (CHAR16
));
1342 BufToHexString (StringPtr
, &BufferLen
, (UINT8
*) &BufferSize
, sizeof (UINTN
));
1344 Request
= BlockName
;
1346 Request
= RequestElement
;
1349 BufferLen
= HeaderLen
* sizeof (CHAR16
) + StrSize (Request
);
1350 ConfigRequest
= AllocateZeroPool (BufferLen
);
1351 if (ConfigRequest
== NULL
) {
1352 return EFI_OUT_OF_RESOURCES
;
1355 CopyMem (ConfigRequest
, ConfigHdr
, HeaderLen
* sizeof (CHAR16
));
1356 StringPtr
= ConfigRequest
+ HeaderLen
;
1357 StrCpy (StringPtr
, Request
);
1360 // Convert buffer to <ConfigResp>
1362 Status
= mIfrSupportLibHiiConfigRouting
->BlockToConfig (
1363 mIfrSupportLibHiiConfigRouting
,
1370 if (EFI_ERROR (Status
)) {
1371 FreePool (ConfigRequest
);
1376 // Skip <ConfigHdr> and '&'
1378 StringPtr
= ConfigResp
+ HeaderLen
+ 1;
1381 // Change uncommitted data in Browser
1383 Status
= mFormBrowser2
->BrowserCallback (
1391 FreePool (ConfigRequest
);