2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalHiiLib.h"
17 #define GUID_CONFIG_STRING_TYPE 0x00
18 #define NAME_CONFIG_STRING_TYPE 0x01
19 #define PATH_CONFIG_STRING_TYPE 0x02
21 #define ACTION_SET_DEFAUTL_VALUE 0x01
22 #define ACTION_VALIDATE_SETTING 0x02
24 #define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200
27 LIST_ENTRY Entry
; // Link to Block array
35 EFI_VARSTORE_ID VarStoreId
;
37 } IFR_VARSTORAGE_DATA
;
40 // <ConfigHdr> Template
42 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate
[] = L
"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
44 EFI_FORM_BROWSER2_PROTOCOL
*mUefiFormBrowser2
= NULL
;
47 // Template used to mark the end of a list of packages
49 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList
= {
50 sizeof (EFI_HII_PACKAGE_HEADER
),
55 Extract Hii package list GUID for given HII handle.
57 If HiiHandle could not be found in the HII database, then ASSERT.
58 If Guid is NULL, then ASSERT.
60 @param Handle Hii handle
61 @param Guid Package list GUID
63 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
68 InternalHiiExtractGuidFromHiiHandle (
69 IN EFI_HII_HANDLE Handle
,
75 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
77 ASSERT (Guid
!= NULL
);
78 ASSERT (Handle
!= NULL
);
81 // Get HII PackageList
84 HiiPackageList
= NULL
;
86 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
87 ASSERT (Status
!= EFI_NOT_FOUND
);
89 if (Status
== EFI_BUFFER_TOO_SMALL
) {
90 HiiPackageList
= AllocatePool (BufferSize
);
91 ASSERT (HiiPackageList
!= NULL
);
93 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
95 if (EFI_ERROR (Status
)) {
96 FreePool (HiiPackageList
);
103 CopyGuid (Guid
, &HiiPackageList
->PackageListGuid
);
105 FreePool (HiiPackageList
);
111 Registers a list of packages in the HII Database and returns the HII Handle
112 associated with that registration. If an HII Handle has already been registered
113 with the same PackageListGuid and DeviceHandle, then NULL is returned. If there
114 are not enough resources to perform the registration, then NULL is returned.
115 If an empty list of packages is passed in, then NULL is returned. If the size of
116 the list of package is 0, then NULL is returned.
118 The variable arguments are pointers which point to package header that defined
119 by UEFI VFR compiler and StringGather tool.
121 #pragma pack (push, 1)
124 EFI_HII_PACKAGE_HEADER PackageHeader;
125 } EDKII_AUTOGEN_PACKAGES_HEADER;
128 @param[in] PackageListGuid The GUID of the package list.
129 @param[in] DeviceHandle If not NULL, the Device Handle on which
130 an instance of DEVICE_PATH_PROTOCOL is installed.
131 This Device Handle uniquely defines the device that
132 the added packages are associated with.
133 @param[in] ... The variable argument list that contains pointers
134 to packages terminated by a NULL.
136 @retval NULL A HII Handle has already been registered in the HII Database with
137 the same PackageListGuid and DeviceHandle.
138 @retval NULL The HII Handle could not be created.
139 @retval NULL An empty list of packages was passed in.
140 @retval NULL All packages are empty.
141 @retval Other The HII Handle associated with the newly registered package list.
147 IN CONST EFI_GUID
*PackageListGuid
,
148 IN EFI_HANDLE DeviceHandle OPTIONAL
,
155 EFI_HII_PACKAGE_LIST_HEADER
*PackageListHeader
;
156 EFI_HII_HANDLE HiiHandle
;
160 ASSERT (PackageListGuid
!= NULL
);
163 // Calculate the length of all the packages in the variable argument list
165 for (Length
= 0, VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
166 Length
+= (ReadUnaligned32 (Package
) - sizeof (UINT32
));
171 // If there are no packages in the variable argument list or all the packages
172 // are empty, then return a NULL HII Handle
179 // Add the length of the Package List Header and the terminating Package Header
181 Length
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + sizeof (EFI_HII_PACKAGE_HEADER
);
184 // Allocate the storage for the entire Package List
186 PackageListHeader
= AllocateZeroPool (Length
);
189 // If the Package List can not be allocated, then return a NULL HII Handle
191 if (PackageListHeader
== NULL
) {
196 // Fill in the GUID and Length of the Package List Header
198 CopyGuid (&PackageListHeader
->PackageListGuid
, PackageListGuid
);
199 PackageListHeader
->PackageLength
= Length
;
202 // Initialize a pointer to the beginning if the Package List data
204 Data
= (UINT8
*)(PackageListHeader
+ 1);
207 // Copy the data from each package in the variable argument list
209 for (VA_START (Args
, DeviceHandle
); (Package
= VA_ARG (Args
, UINT32
*)) != NULL
; ) {
210 Length
= ReadUnaligned32 (Package
) - sizeof (UINT32
);
211 CopyMem (Data
, Package
+ 1, Length
);
217 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
219 CopyMem (Data
, &mEndOfPakageList
, sizeof (mEndOfPakageList
));
222 // Register the package list with the HII Database
224 Status
= gHiiDatabase
->NewPackageList (
230 if (EFI_ERROR (Status
)) {
235 // Free the allocated package list
237 FreePool (PackageListHeader
);
240 // Return the new HII Handle
246 Removes a package list from the HII database.
248 If HiiHandle is NULL, then ASSERT.
249 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
251 @param[in] HiiHandle The handle that was previously registered in the HII database
257 IN EFI_HII_HANDLE HiiHandle
262 ASSERT (HiiHandle
!= NULL
);
263 Status
= gHiiDatabase
->RemovePackageList (gHiiDatabase
, HiiHandle
);
264 ASSERT_EFI_ERROR (Status
);
269 Retrieves the array of all the HII Handles or the HII handles of a specific
270 package list GUID in the HII Database.
271 This array is terminated with a NULL HII Handle.
272 This function allocates the returned array using AllocatePool().
273 The caller is responsible for freeing the array with FreePool().
275 @param[in] PackageListGuid An optional parameter that is used to request
276 HII Handles associated with a specific
277 Package List GUID. If this parameter is NULL,
278 then all the HII Handles in the HII Database
279 are returned. If this parameter is not NULL,
280 then zero or more HII Handles associated with
281 PackageListGuid are returned.
283 @retval NULL No HII handles were found in the HII database
284 @retval NULL The array of HII Handles could not be retrieved
285 @retval Other A pointer to the NULL terminated array of HII Handles
291 IN CONST EFI_GUID
*PackageListGuid OPTIONAL
295 UINTN HandleBufferLength
;
296 EFI_HII_HANDLE TempHiiHandleBuffer
;
297 EFI_HII_HANDLE
*HiiHandleBuffer
;
303 // Retrieve the size required for the buffer of all HII handles.
305 HandleBufferLength
= 0;
306 Status
= gHiiDatabase
->ListPackageLists (
308 EFI_HII_PACKAGE_TYPE_ALL
,
315 // If ListPackageLists() returns EFI_SUCCESS for a zero size,
316 // then there are no HII handles in the HII database. If ListPackageLists()
317 // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII
318 // handles in the HII database.
320 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
322 // Return NULL if the size can not be retrieved, or if there are no HII
323 // handles in the HII Database
329 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
331 HiiHandleBuffer
= AllocateZeroPool (HandleBufferLength
+ sizeof (EFI_HII_HANDLE
));
332 if (HiiHandleBuffer
== NULL
) {
334 // Return NULL if allocation fails.
340 // Retrieve the array of HII Handles in the HII Database
342 Status
= gHiiDatabase
->ListPackageLists (
344 EFI_HII_PACKAGE_TYPE_ALL
,
349 if (EFI_ERROR (Status
)) {
351 // Free the buffer and return NULL if the HII handles can not be retrieved.
353 FreePool (HiiHandleBuffer
);
357 if (PackageListGuid
== NULL
) {
359 // Return the NULL terminated array of HII handles in the HII Database
361 return HiiHandleBuffer
;
363 for (Index1
= 0, Index2
= 0; HiiHandleBuffer
[Index1
] != NULL
; Index1
++) {
364 Status
= InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer
[Index1
], &Guid
);
365 ASSERT_EFI_ERROR (Status
);
366 if (CompareGuid (&Guid
, PackageListGuid
)) {
367 HiiHandleBuffer
[Index2
++] = HiiHandleBuffer
[Index1
];
371 HiiHandleBuffer
[Index2
] = NULL
;
372 return HiiHandleBuffer
;
374 FreePool (HiiHandleBuffer
);
381 This function allows a caller to extract the form set opcode form the Hii Handle.
382 The returned buffer is allocated using AllocatePool().The caller is responsible
383 for freeing the allocated buffer using FreePool().
385 @param Handle The HII handle.
386 @param Buffer On return, points to a pointer which point to the buffer that contain the formset opcode.
387 @param BufferSize On return, points to the length of the buffer.
389 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
390 @retval EFI_NOT_FOUND Can't find the package data for the input Handle.
391 @retval EFI_INVALID_PARAMETER The input parameters are not correct.
392 @retval EFI_SUCCESS Get the formset opcode from the hii handle successfully.
397 HiiGetFormSetFromHiiHandle(
398 IN EFI_HII_HANDLE Handle
,
399 OUT EFI_IFR_FORM_SET
**Buffer
,
400 OUT UINTN
*BufferSize
404 UINTN PackageListSize
;
406 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
409 UINT8
*FormSetBuffer
;
413 UINT32 PackageListLength
;
414 EFI_HII_PACKAGE_HEADER PackageHeader
;
417 FormSetBuffer
= NULL
;
421 // Get HII PackageList
424 HiiPackageList
= NULL
;
425 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &PackageListSize
, HiiPackageList
);
426 if (EFI_ERROR (Status
) && (Status
!= EFI_BUFFER_TOO_SMALL
)) {
430 HiiPackageList
= AllocatePool (PackageListSize
);
431 if (HiiPackageList
== NULL
) {
432 return EFI_OUT_OF_RESOURCES
;
435 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &PackageListSize
, HiiPackageList
);
436 ASSERT_EFI_ERROR (Status
);
439 // Get Form package from this HII package List
441 Status
= EFI_NOT_FOUND
;
442 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
443 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
445 while (Offset
< PackageListLength
) {
446 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
447 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
448 Offset
+= PackageHeader
.Length
;
450 if (PackageHeader
.Type
!= EFI_HII_PACKAGE_FORMS
) {
455 // Search FormSet Opcode in this Form Package
457 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
458 while (Offset2
< PackageHeader
.Length
) {
459 OpCodeData
= Package
+ Offset2
;
460 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
462 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
!= EFI_IFR_FORM_SET_OP
) {
466 if (FormSetBuffer
!= NULL
){
467 TempBuffer
= ReallocatePool (
469 TempSize
+ ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
,
472 if (TempBuffer
== NULL
) {
473 Status
= EFI_OUT_OF_RESOURCES
;
476 CopyMem (TempBuffer
+ TempSize
, OpCodeData
, ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
);
477 FormSetBuffer
= NULL
;
479 TempBuffer
= AllocatePool (TempSize
+ ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
);
480 if (TempBuffer
== NULL
) {
481 Status
= EFI_OUT_OF_RESOURCES
;
484 CopyMem (TempBuffer
, OpCodeData
, ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
);
486 TempSize
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
487 FormSetBuffer
= TempBuffer
;
489 Status
= EFI_SUCCESS
;
491 //One form package has one formset, exit current form package to search other form package in the packagelist.
497 FreePool (HiiPackageList
);
499 *BufferSize
= TempSize
;
500 *Buffer
= (EFI_IFR_FORM_SET
*)FormSetBuffer
;
506 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
507 hex digits that appear between a '=' and a '&' in a config string.
509 If ConfigString is NULL, then ASSERT().
511 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
513 @return Pointer to the Null-terminated Unicode result string.
518 InternalHiiLowerConfigString (
519 IN EFI_STRING ConfigString
525 ASSERT (ConfigString
!= NULL
);
528 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
530 for (String
= ConfigString
, Lower
= FALSE
; *String
!= L
'\0'; String
++) {
531 if (*String
== L
'=') {
533 } else if (*String
== L
'&') {
535 } else if (Lower
&& *String
>= L
'A' && *String
<= L
'F') {
536 *String
= (CHAR16
) (*String
- L
'A' + L
'a');
544 Uses the BlockToConfig() service of the Config Routing Protocol to
545 convert <ConfigRequest> and a buffer to a <ConfigResp>
547 If ConfigRequest is NULL, then ASSERT().
548 If Block is NULL, then ASSERT().
550 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
551 @param[in] Block Pointer to a block of data.
552 @param[in] BlockSize The zie, in bytes, of Block.
554 @retval NULL The <ConfigResp> string could not be generated.
555 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
560 InternalHiiBlockToConfig (
561 IN CONST EFI_STRING ConfigRequest
,
562 IN CONST UINT8
*Block
,
567 EFI_STRING ConfigResp
;
570 ASSERT (ConfigRequest
!= NULL
);
571 ASSERT (Block
!= NULL
);
574 // Convert <ConfigRequest> to <ConfigResp>
576 Status
= gHiiConfigRouting
->BlockToConfig (
584 if (EFI_ERROR (Status
)) {
591 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
592 or set uncommitted data. If sata i being retrieved, then the buffer is
593 allocated using AllocatePool(). The caller is then responsible for freeing
594 the buffer using FreePool().
596 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
597 parameter that may be NULL.
598 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
599 is an optional parameter that may be NULL.
600 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
601 of uncommited data to set. If this parameter is NULL,
602 then the caller is requesting to get the uncommited data
603 from the Form Browser.
605 @retval NULL The uncommitted data could not be retrieved.
606 @retval Other A pointer to a buffer containing the uncommitted data.
611 InternalHiiBrowserCallback (
612 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
613 IN CONST CHAR16
*VariableName
, OPTIONAL
614 IN CONST EFI_STRING SetResultsData OPTIONAL
618 UINTN ResultsDataSize
;
619 EFI_STRING ResultsData
;
620 CHAR16 TempResultsData
;
625 if (mUefiFormBrowser2
== NULL
) {
626 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &mUefiFormBrowser2
);
627 if (EFI_ERROR (Status
) || mUefiFormBrowser2
== NULL
) {
634 if (SetResultsData
!= NULL
) {
636 // Request to to set data in the uncommitted browser state information
638 ResultsData
= SetResultsData
;
641 // Retrieve the length of the buffer required ResultsData from the Browser Callback
643 Status
= mUefiFormBrowser2
->BrowserCallback (
652 if (!EFI_ERROR (Status
)) {
654 // No Resluts Data, only allocate one char for '\0'
656 ResultsData
= AllocateZeroPool (sizeof (CHAR16
));
660 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
665 // Allocate the ResultsData buffer
667 ResultsData
= AllocateZeroPool (ResultsDataSize
);
668 if (ResultsData
== NULL
) {
674 // Retrieve or set the ResultsData from the Browser Callback
676 Status
= mUefiFormBrowser2
->BrowserCallback (
680 (BOOLEAN
)(SetResultsData
== NULL
),
684 if (EFI_ERROR (Status
)) {
692 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
693 information that includes a GUID, an optional Unicode string name, and a device
694 path. The string returned is allocated with AllocatePool(). The caller is
695 responsible for freeing the allocated string with FreePool().
697 The format of a <ConfigHdr> is as follows:
699 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
701 @param[in] Guid Pointer to an EFI_GUID that is the routing information
702 GUID. Each of the 16 bytes in Guid is converted to
703 a 2 Unicode character hexadecimal string. This is
704 an optional parameter that may be NULL.
705 @param[in] Name Pointer to a Null-terminated Unicode string that is
706 the routing information NAME. This is an optional
707 parameter that may be NULL. Each 16-bit Unicode
708 character in Name is converted to a 4 character Unicode
710 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
711 that is the routing information PATH. Each byte of
712 the Device Path associated with DriverHandle is converted
713 to a 2 Unicode character hexadecimal string.
715 @retval NULL DriverHandle does not support the Device Path Protocol.
716 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
721 HiiConstructConfigHdr (
722 IN CONST EFI_GUID
*Guid
, OPTIONAL
723 IN CONST CHAR16
*Name
, OPTIONAL
724 IN EFI_HANDLE DriverHandle
728 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
729 UINTN DevicePathSize
;
731 CHAR16
*ReturnString
;
737 // Compute the length of Name in Unicode characters.
738 // If Name is NULL, then the length is 0.
742 NameLength
= StrLen (Name
);
748 // Retrieve DevicePath Protocol associated with DriverHandle
750 if (DriverHandle
!= NULL
) {
751 DevicePath
= DevicePathFromHandle (DriverHandle
);
752 if (DevicePath
== NULL
) {
756 // Compute the size of the device path in bytes
758 DevicePathSize
= GetDevicePathSize (DevicePath
);
762 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
763 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
765 MaxLen
= 5 + sizeof (EFI_GUID
) * 2 + 6 + NameLength
* 4 + 6 + DevicePathSize
* 2 + 1;
766 String
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
767 if (String
== NULL
) {
772 // Start with L"GUID="
774 StrCpyS (String
, MaxLen
, L
"GUID=");
775 ReturnString
= String
;
776 String
+= StrLen (String
);
780 // Append Guid converted to <HexCh>32
782 for (Index
= 0, Buffer
= (UINT8
*)Guid
; Index
< sizeof (EFI_GUID
); Index
++) {
783 UnicodeValueToStringS (
785 MaxLen
* sizeof (CHAR16
) - ((UINTN
)String
- (UINTN
)ReturnString
),
786 PREFIX_ZERO
| RADIX_HEX
,
790 String
+= StrnLenS (String
, MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
) / sizeof (CHAR16
));
797 StrCatS (ReturnString
, MaxLen
, L
"&NAME=");
798 String
+= StrLen (String
);
802 // Append Name converted to <Char>NameLength
804 for (; *Name
!= L
'\0'; Name
++) {
805 UnicodeValueToStringS (
807 sizeof (CHAR16
) * MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
),
808 PREFIX_ZERO
| RADIX_HEX
,
812 String
+= StrnLenS (String
, MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
) / sizeof (CHAR16
));
819 StrCatS (ReturnString
, MaxLen
, L
"&PATH=");
820 String
+= StrLen (String
);
823 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
825 for (Index
= 0, Buffer
= (UINT8
*)DevicePath
; Index
< DevicePathSize
; Index
++) {
826 UnicodeValueToStringS (
828 sizeof (CHAR16
) * MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
),
829 PREFIX_ZERO
| RADIX_HEX
,
833 String
+= StrnLenS (String
, MaxLen
- ((UINTN
)String
- (UINTN
)ReturnString
) / sizeof (CHAR16
));
837 // Null terminate the Unicode string
842 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
844 return InternalHiiLowerConfigString (ReturnString
);
848 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
849 to binary buffer from <ConfigHdr>.
851 This is a internal function.
853 @param String UEFI configuration string.
854 @param Flag Flag specifies what type buffer will be retrieved.
855 @param Buffer Binary of Guid, Name or Device path.
857 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
858 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
859 @retval EFI_SUCCESS The buffer data is retrieved and translated to
864 InternalHiiGetBufferFromString (
865 IN EFI_STRING String
,
871 EFI_STRING ConfigHdr
;
878 if (String
== NULL
|| Buffer
== NULL
) {
879 return EFI_INVALID_PARAMETER
;
886 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
887 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
889 for (Length
= 0; *String
!= 0 && *String
!= L
'&'; String
++, Length
++);
892 case GUID_CONFIG_STRING_TYPE
:
893 case PATH_CONFIG_STRING_TYPE
:
895 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
896 // as the device path and Guid resides in RAM memory.
897 // Translate the data into binary.
899 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
900 if (DataBuffer
== NULL
) {
901 return EFI_OUT_OF_RESOURCES
;
904 // Convert binary byte one by one
906 ZeroMem (TemStr
, sizeof (TemStr
));
907 for (Index
= 0; Index
< Length
; Index
++) {
908 TemStr
[0] = ConfigHdr
[Index
];
909 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
910 if ((Index
& 1) == 0) {
911 DataBuffer
[Index
/2] = DigitUint8
;
913 DataBuffer
[Index
/2] = (UINT8
) ((DataBuffer
[Index
/2] << 4) + DigitUint8
);
917 *Buffer
= DataBuffer
;
920 case NAME_CONFIG_STRING_TYPE
:
922 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
926 // Add the tailling char L'\0'
928 DataBuffer
= (UINT8
*) AllocateZeroPool ((Length
/4 + 1) * sizeof (CHAR16
));
929 if (DataBuffer
== NULL
) {
930 return EFI_OUT_OF_RESOURCES
;
933 // Convert character one by one
935 StringPtr
= (CHAR16
*) DataBuffer
;
936 ZeroMem (TemStr
, sizeof (TemStr
));
937 for (Index
= 0; Index
< Length
; Index
+= 4) {
938 StrnCpyS (TemStr
, sizeof (TemStr
) / sizeof (CHAR16
), ConfigHdr
+ Index
, 4);
939 StringPtr
[Index
/4] = (CHAR16
) StrHexToUint64 (TemStr
);
942 // Add tailing L'\0' character
944 StringPtr
[Index
/4] = L
'\0';
946 *Buffer
= DataBuffer
;
950 return EFI_INVALID_PARAMETER
;
957 This function checks VarOffset and VarWidth is in the block range.
959 @param BlockArray The block array is to be checked.
960 @param VarOffset Offset of var to the structure
961 @param VarWidth Width of var.
963 @retval TRUE This Var is in the block range.
964 @retval FALSE This Var is not in the block range.
968 IN IFR_BLOCK_DATA
*BlockArray
,
974 IFR_BLOCK_DATA
*BlockData
;
977 // No Request Block array, all vars are got.
979 if (BlockArray
== NULL
) {
984 // Check the input var is in the request block range.
986 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
987 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
988 if ((VarOffset
>= BlockData
->Offset
) && ((VarOffset
+ VarWidth
) <= (BlockData
->Offset
+ BlockData
->Width
))) {
997 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
999 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
1001 @param ValueString String in <BlockConfig> format and points to the
1002 first character of <Number>.
1003 @param ValueData The output value. Caller takes the responsibility
1005 @param ValueLength Length of the <Number>, in characters.
1007 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
1009 @retval EFI_SUCCESS Value of <Number> is outputted in Number
1015 InternalHiiGetValueOfNumber (
1016 IN EFI_STRING ValueString
,
1017 OUT UINT8
**ValueData
,
1018 OUT UINTN
*ValueLength
1021 EFI_STRING StringPtr
;
1028 ASSERT (ValueString
!= NULL
&& ValueData
!= NULL
&& ValueLength
!= NULL
);
1029 ASSERT (*ValueString
!= L
'\0');
1032 // Get the length of value string
1034 StringPtr
= ValueString
;
1035 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
1038 Length
= StringPtr
- ValueString
;
1041 // Allocate buffer to store the value
1043 Buf
= (UINT8
*) AllocateZeroPool ((Length
+ 1) / 2);
1045 return EFI_OUT_OF_RESOURCES
;
1049 // Convert character one by one to the value buffer
1051 ZeroMem (TemStr
, sizeof (TemStr
));
1052 for (Index
= 0; Index
< Length
; Index
++) {
1053 TemStr
[0] = ValueString
[Length
- Index
- 1];
1054 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
1055 if ((Index
& 1) == 0) {
1056 Buf
[Index
/2] = DigitUint8
;
1058 Buf
[Index
/2] = (UINT8
) ((DigitUint8
<< 4) + Buf
[Index
/2]);
1063 // Set the converted value and string length.
1066 *ValueLength
= Length
;
1071 Get value from config request resp string.
1073 @param ConfigElement ConfigResp string contains the current setting.
1074 @param VarName The variable name which need to get value.
1075 @param VarValue The return value.
1077 @retval EFI_SUCCESS Get the value for the VarName
1078 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1081 GetValueFromRequest (
1082 IN CHAR16
*ConfigElement
,
1084 OUT UINT64
*VarValue
1093 // Find VarName related string.
1095 StringPtr
= StrStr (ConfigElement
, VarName
);
1096 ASSERT (StringPtr
!= NULL
);
1099 // Skip the "VarName=" string
1101 StringPtr
+= StrLen (VarName
) + 1;
1106 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1107 if (EFI_ERROR (Status
)) {
1112 CopyMem (VarValue
, TmpBuffer
, (((Length
+ 1) / 2) < sizeof (UINT64
)) ? ((Length
+ 1) / 2) : sizeof (UINT64
));
1114 FreePool (TmpBuffer
);
1120 This internal function parses IFR data to validate current setting.
1122 Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid;
1123 else the VarBuffer and CurrentBlockArray is valid.
1125 @param HiiPackageList Point to Hii package list.
1126 @param PackageListLength The length of the pacakge.
1127 @param VarGuid Guid of the buffer storage.
1128 @param VarName Name of the buffer storage.
1129 @param VarBuffer The data buffer for the storage.
1130 @param CurrentBlockArray The block array from the config Requst string.
1131 @param RequestElement The config string for this storage.
1132 @param HiiHandle The HiiHandle for this formset.
1133 @param NameValueType Whether current storage is name/value varstore or not.
1135 @retval EFI_SUCCESS The current setting is valid.
1136 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1137 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1140 ValidateQuestionFromVfr (
1141 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
1142 IN UINTN PackageListLength
,
1143 IN EFI_GUID
*VarGuid
,
1145 IN UINT8
*VarBuffer
,
1146 IN IFR_BLOCK_DATA
*CurrentBlockArray
,
1147 IN CHAR16
*RequestElement
,
1148 IN EFI_HII_HANDLE HiiHandle
,
1149 IN BOOLEAN NameValueType
1152 IFR_BLOCK_DATA VarBlockData
;
1156 EFI_IFR_TYPE_VALUE TmpValue
;
1158 EFI_HII_PACKAGE_HEADER PackageHeader
;
1159 UINT32 PackageOffset
;
1162 EFI_IFR_OP_HEADER
*IfrOpHdr
;
1163 EFI_IFR_VARSTORE
*IfrVarStore
;
1164 EFI_IFR_VARSTORE_NAME_VALUE
*IfrNameValueStore
;
1165 EFI_IFR_VARSTORE_EFI
*IfrEfiVarStore
;
1166 IFR_VARSTORAGE_DATA VarStoreData
;
1167 EFI_IFR_ONE_OF
*IfrOneOf
;
1168 EFI_IFR_NUMERIC
*IfrNumeric
;
1169 EFI_IFR_ONE_OF_OPTION
*IfrOneOfOption
;
1170 EFI_IFR_CHECKBOX
*IfrCheckBox
;
1171 EFI_IFR_STRING
*IfrString
;
1172 CHAR8
*VarStoreName
;
1174 CHAR16
*QuestionName
;
1181 BOOLEAN QuestionReferBitField
;
1185 // Initialize the local variables.
1188 VarStoreName
= NULL
;
1189 Status
= EFI_SUCCESS
;
1192 IfrNameValueStore
= NULL
;
1193 IfrEfiVarStore
= NULL
;
1194 ZeroMem (&VarStoreData
, sizeof (IFR_VARSTORAGE_DATA
));
1195 ZeroMem (&VarBlockData
, sizeof (VarBlockData
));
1198 QuestionReferBitField
= FALSE
;
1201 // Check IFR value is in block data, then Validate Value
1203 PackageOffset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1204 while (PackageOffset
< PackageListLength
) {
1205 CopyMem (&PackageHeader
, (UINT8
*) HiiPackageList
+ PackageOffset
, sizeof (PackageHeader
));
1208 // Parse IFR opcode from the form package.
1210 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1211 IfrOffset
= sizeof (PackageHeader
);
1212 PackageData
= (UINT8
*) HiiPackageList
+ PackageOffset
;
1213 while (IfrOffset
< PackageHeader
.Length
) {
1214 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) (PackageData
+ IfrOffset
);
1216 // Validate current setting to the value built in IFR opcode
1218 switch (IfrOpHdr
->OpCode
) {
1219 case EFI_IFR_VARSTORE_OP
:
1221 // VarStoreId has been found. No further found.
1223 if (VarStoreData
.VarStoreId
!= 0) {
1227 // Find the matched VarStoreId to the input VarGuid and VarName
1229 IfrVarStore
= (EFI_IFR_VARSTORE
*) IfrOpHdr
;
1230 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrVarStore
->Guid
, VarGuid
)) {
1231 VarStoreName
= (CHAR8
*) IfrVarStore
->Name
;
1232 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1233 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1238 // The matched VarStore is found.
1240 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1247 if (IfrVarStore
!= NULL
) {
1248 VarStoreData
.VarStoreId
= IfrVarStore
->VarStoreId
;
1249 VarStoreData
.Size
= IfrVarStore
->Size
;
1252 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1254 // VarStoreId has been found. No further found.
1256 if (VarStoreData
.VarStoreId
!= 0) {
1260 // Find the matched VarStoreId to the input VarGuid
1262 IfrNameValueStore
= (EFI_IFR_VARSTORE_NAME_VALUE
*) IfrOpHdr
;
1263 if (!CompareGuid ((EFI_GUID
*) (VOID
*) &IfrNameValueStore
->Guid
, VarGuid
)) {
1264 IfrNameValueStore
= NULL
;
1267 if (IfrNameValueStore
!= NULL
) {
1268 VarStoreData
.VarStoreId
= IfrNameValueStore
->VarStoreId
;
1271 case EFI_IFR_VARSTORE_EFI_OP
:
1273 // VarStore is found. Don't need to search any more.
1275 if (VarStoreData
.VarStoreId
!= 0) {
1279 IfrEfiVarStore
= (EFI_IFR_VARSTORE_EFI
*) IfrOpHdr
;
1282 // If the length is small than the structure, this is from old efi
1283 // varstore definition. Old efi varstore get config directly from
1284 // GetVariable function.
1286 if (IfrOpHdr
->Length
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1290 if (CompareGuid ((EFI_GUID
*) (VOID
*) &IfrEfiVarStore
->Guid
, VarGuid
)) {
1291 VarStoreName
= (CHAR8
*) IfrEfiVarStore
->Name
;
1292 for (Index
= 0; VarStoreName
[Index
] != 0; Index
++) {
1293 if ((CHAR16
) VarStoreName
[Index
] != VarName
[Index
]) {
1298 // The matched VarStore is found.
1300 if ((VarStoreName
[Index
] != 0) || (VarName
[Index
] != 0)) {
1301 IfrEfiVarStore
= NULL
;
1304 IfrEfiVarStore
= NULL
;
1307 if (IfrEfiVarStore
!= NULL
) {
1309 // Find the matched VarStore
1311 VarStoreData
.VarStoreId
= IfrEfiVarStore
->VarStoreId
;
1312 VarStoreData
.Size
= IfrEfiVarStore
->Size
;
1315 case EFI_IFR_FORM_OP
:
1316 case EFI_IFR_FORM_MAP_OP
:
1318 // Check the matched VarStoreId is found.
1320 if (VarStoreData
.VarStoreId
== 0) {
1324 case EFI_IFR_ONE_OF_OP
:
1326 // Check whether current value is the one of option.
1330 // OneOf question is not in IFR Form. This IFR form is not valid.
1332 if (VarStoreData
.VarStoreId
== 0) {
1333 return EFI_INVALID_PARAMETER
;
1336 // Check whether this question is for the requested varstore.
1338 IfrOneOf
= (EFI_IFR_ONE_OF
*) IfrOpHdr
;
1339 if (IfrOneOf
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1343 if (NameValueType
) {
1344 QuestionName
= HiiGetString (HiiHandle
, IfrOneOf
->Question
.VarStoreInfo
.VarName
, NULL
);
1345 ASSERT (QuestionName
!= NULL
);
1347 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1349 // This question is not in the current configuration string. Skip it.
1354 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1355 if (EFI_ERROR (Status
)) {
1360 // Get Offset by Question header and Width by DataType Flags
1362 if (QuestionReferBitField
) {
1364 // Get the byte offset/width for bit field.
1366 BitOffset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1367 BitWidth
= IfrOneOf
->Flags
& EDKII_IFR_NUMERIC_SIZE_BIT
;
1368 Offset
= BitOffset
/ 8;
1369 TotalBits
= BitOffset
% 8 + BitWidth
;
1370 Width
= (TotalBits
% 8 == 0 ? TotalBits
/ 8: TotalBits
/ 8 + 1);
1372 Offset
= IfrOneOf
->Question
.VarStoreInfo
.VarOffset
;
1373 Width
= (UINT16
) (1 << (IfrOneOf
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1376 // Check whether this question is in current block array.
1378 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1380 // This question is not in the current configuration string. Skip it.
1385 // Check this var question is in the var storage
1387 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1389 // This question exceeds the var store size.
1391 return EFI_INVALID_PARAMETER
;
1395 // Get the current value for oneof opcode
1398 if (QuestionReferBitField
) {
1400 // Get the value in bit fields.
1402 StartBit
= BitOffset
% 8;
1403 EndBit
= StartBit
+ BitWidth
- 1;
1404 CopyMem ((UINT8
*) &BufferValue
, VarBuffer
+ Offset
, Width
);
1405 VarValue
= BitFieldRead32 (BufferValue
, StartBit
, EndBit
);
1407 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1411 // Set Block Data, to be checked in the following Oneof option opcode.
1413 VarBlockData
.OpCode
= IfrOpHdr
->OpCode
;
1414 VarBlockData
.Scope
= IfrOpHdr
->Scope
;
1416 case EFI_IFR_NUMERIC_OP
:
1418 // Check the current value is in the numeric range.
1422 // Numeric question is not in IFR Form. This IFR form is not valid.
1424 if (VarStoreData
.VarStoreId
== 0) {
1425 return EFI_INVALID_PARAMETER
;
1428 // Check whether this question is for the requested varstore.
1430 IfrNumeric
= (EFI_IFR_NUMERIC
*) IfrOpHdr
;
1431 if (IfrNumeric
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1435 if (NameValueType
) {
1436 QuestionName
= HiiGetString (HiiHandle
, IfrNumeric
->Question
.VarStoreInfo
.VarName
, NULL
);
1437 ASSERT (QuestionName
!= NULL
);
1439 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1441 // This question is not in the current configuration string. Skip it.
1446 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1447 if (EFI_ERROR (Status
)) {
1452 // Get Offset by Question header and Width by DataType Flags
1454 if (QuestionReferBitField
) {
1456 // Get the byte offset/width for bit field.
1458 BitOffset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1459 BitWidth
= IfrNumeric
->Flags
& EDKII_IFR_NUMERIC_SIZE_BIT
;
1460 Offset
= BitOffset
/ 8;
1461 TotalBits
= BitOffset
% 8 + BitWidth
;
1462 Width
= (TotalBits
% 8 == 0 ? TotalBits
/ 8: TotalBits
/ 8 + 1);
1464 Offset
= IfrNumeric
->Question
.VarStoreInfo
.VarOffset
;
1465 Width
= (UINT16
) (1 << (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
));
1468 // Check whether this question is in current block array.
1470 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1472 // This question is not in the current configuration string. Skip it.
1477 // Check this var question is in the var storage
1479 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1481 // This question exceeds the var store size.
1483 return EFI_INVALID_PARAMETER
;
1487 // Check the current value is in the numeric range.
1490 if (QuestionReferBitField
) {
1492 // Get the value in the bit fields.
1494 StartBit
= BitOffset
% 8;
1495 EndBit
= StartBit
+ BitWidth
- 1;
1496 CopyMem ((UINT8
*) &BufferValue
, VarBuffer
+ Offset
, Width
);
1497 VarValue
= BitFieldRead32 (BufferValue
, StartBit
, EndBit
);
1499 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1502 if ( QuestionReferBitField
) {
1504 // Value in bit fields was stored as UINt32 type.
1506 if ((IfrNumeric
->Flags
& EDKII_IFR_DISPLAY_BIT
) == 0) {
1507 if ((INT32
) VarValue
< (INT32
) IfrNumeric
->data
.u32
.MinValue
|| (INT32
) VarValue
> (INT32
) IfrNumeric
->data
.u32
.MaxValue
) {
1509 // Not in the valid range.
1511 return EFI_INVALID_PARAMETER
;
1514 if (VarValue
< IfrNumeric
->data
.u32
.MinValue
|| VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1516 // Not in the valid range.
1518 return EFI_INVALID_PARAMETER
;
1522 if ((IfrNumeric
->Flags
& EFI_IFR_DISPLAY
) == 0) {
1523 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1524 case EFI_IFR_NUMERIC_SIZE_1
:
1525 if ((INT8
) VarValue
< (INT8
) IfrNumeric
->data
.u8
.MinValue
|| (INT8
) VarValue
> (INT8
) IfrNumeric
->data
.u8
.MaxValue
) {
1527 // Not in the valid range.
1529 return EFI_INVALID_PARAMETER
;
1532 case EFI_IFR_NUMERIC_SIZE_2
:
1533 if ((INT16
) VarValue
< (INT16
) IfrNumeric
->data
.u16
.MinValue
|| (INT16
) VarValue
> (INT16
) IfrNumeric
->data
.u16
.MaxValue
) {
1535 // Not in the valid range.
1537 return EFI_INVALID_PARAMETER
;
1540 case EFI_IFR_NUMERIC_SIZE_4
:
1541 if ((INT32
) VarValue
< (INT32
) IfrNumeric
->data
.u32
.MinValue
|| (INT32
) VarValue
> (INT32
) IfrNumeric
->data
.u32
.MaxValue
) {
1543 // Not in the valid range.
1545 return EFI_INVALID_PARAMETER
;
1548 case EFI_IFR_NUMERIC_SIZE_8
:
1549 if ((INT64
) VarValue
< (INT64
) IfrNumeric
->data
.u64
.MinValue
|| (INT64
) VarValue
> (INT64
) IfrNumeric
->data
.u64
.MaxValue
) {
1551 // Not in the valid range.
1553 return EFI_INVALID_PARAMETER
;
1558 switch (IfrNumeric
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1559 case EFI_IFR_NUMERIC_SIZE_1
:
1560 if ((UINT8
) VarValue
< IfrNumeric
->data
.u8
.MinValue
|| (UINT8
) VarValue
> IfrNumeric
->data
.u8
.MaxValue
) {
1562 // Not in the valid range.
1564 return EFI_INVALID_PARAMETER
;
1567 case EFI_IFR_NUMERIC_SIZE_2
:
1568 if ((UINT16
) VarValue
< IfrNumeric
->data
.u16
.MinValue
|| (UINT16
) VarValue
> IfrNumeric
->data
.u16
.MaxValue
) {
1570 // Not in the valid range.
1572 return EFI_INVALID_PARAMETER
;
1575 case EFI_IFR_NUMERIC_SIZE_4
:
1576 if ((UINT32
) VarValue
< IfrNumeric
->data
.u32
.MinValue
|| (UINT32
) VarValue
> IfrNumeric
->data
.u32
.MaxValue
) {
1578 // Not in the valid range.
1580 return EFI_INVALID_PARAMETER
;
1583 case EFI_IFR_NUMERIC_SIZE_8
:
1584 if ((UINT64
) VarValue
< IfrNumeric
->data
.u64
.MinValue
|| (UINT64
) VarValue
> IfrNumeric
->data
.u64
.MaxValue
) {
1586 // Not in the valid range.
1588 return EFI_INVALID_PARAMETER
;
1595 case EFI_IFR_CHECKBOX_OP
:
1597 // Check value is BOOLEAN type, only 0 and 1 is valid.
1601 // CheckBox question is not in IFR Form. This IFR form is not valid.
1603 if (VarStoreData
.VarStoreId
== 0) {
1604 return EFI_INVALID_PARAMETER
;
1608 // Check whether this question is for the requested varstore.
1610 IfrCheckBox
= (EFI_IFR_CHECKBOX
*) IfrOpHdr
;
1611 if (IfrCheckBox
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1615 if (NameValueType
) {
1616 QuestionName
= HiiGetString (HiiHandle
, IfrCheckBox
->Question
.VarStoreInfo
.VarName
, NULL
);
1617 ASSERT (QuestionName
!= NULL
);
1619 if (StrStr (RequestElement
, QuestionName
) == NULL
) {
1621 // This question is not in the current configuration string. Skip it.
1626 Status
= GetValueFromRequest (RequestElement
, QuestionName
, &VarValue
);
1627 if (EFI_ERROR (Status
)) {
1632 // Get Offset by Question header
1634 if (QuestionReferBitField
) {
1636 // Get the byte offset/width for bit field.
1638 BitOffset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1640 Offset
= BitOffset
/ 8;
1641 TotalBits
= BitOffset
% 8 + BitWidth
;
1642 Width
= (TotalBits
% 8 == 0 ? TotalBits
/ 8: TotalBits
/ 8 + 1);
1644 Offset
= IfrCheckBox
->Question
.VarStoreInfo
.VarOffset
;
1645 Width
= (UINT16
) sizeof (BOOLEAN
);
1648 // Check whether this question is in current block array.
1650 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1652 // This question is not in the current configuration string. Skip it.
1657 // Check this var question is in the var storage
1659 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1661 // This question exceeds the var store size.
1663 return EFI_INVALID_PARAMETER
;
1666 // Check the current value is in the numeric range.
1669 if (QuestionReferBitField
) {
1671 // Get the value in bit fields.
1673 StartBit
= BitOffset
% 8;
1674 EndBit
= StartBit
+ BitWidth
- 1;
1675 CopyMem ((UINT8
*) &BufferValue
, VarBuffer
+ Offset
, Width
);
1676 VarValue
= BitFieldRead32 (BufferValue
, StartBit
, EndBit
);
1678 CopyMem (&VarValue
, VarBuffer
+ Offset
, Width
);
1682 // Boolean type, only 1 and 0 is valid.
1685 return EFI_INVALID_PARAMETER
;
1688 case EFI_IFR_STRING_OP
:
1690 // Check current string length is less than maxsize
1694 // CheckBox question is not in IFR Form. This IFR form is not valid.
1696 if (VarStoreData
.VarStoreId
== 0) {
1697 return EFI_INVALID_PARAMETER
;
1701 // Check whether this question is for the requested varstore.
1703 IfrString
= (EFI_IFR_STRING
*) IfrOpHdr
;
1704 if (IfrString
->Question
.VarStoreId
!= VarStoreData
.VarStoreId
) {
1708 // Get the Max size of the string.
1710 Width
= (UINT16
) (IfrString
->MaxSize
* sizeof (UINT16
));
1711 if (NameValueType
) {
1712 QuestionName
= HiiGetString (HiiHandle
, IfrString
->Question
.VarStoreInfo
.VarName
, NULL
);
1713 ASSERT (QuestionName
!= NULL
);
1715 StringPtr
= StrStr (RequestElement
, QuestionName
);
1716 if (StringPtr
== NULL
) {
1718 // This question is not in the current configuration string. Skip it.
1723 // Skip the VarName.
1725 StringPtr
+= StrLen (QuestionName
);
1733 // Check current string length is less than maxsize
1734 // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.
1735 // Config string format in UEFI spec.
1736 // <NvConfig> ::= <Label>'='<String>
1737 // <String> ::= [<Char>]+
1738 // <Char> ::= <HexCh>4
1740 if (StrLen (StringPtr
) / 4 > IfrString
->MaxSize
) {
1741 return EFI_INVALID_PARAMETER
;
1745 // Get Offset/Width by Question header and OneOf Flags
1747 Offset
= IfrString
->Question
.VarStoreInfo
.VarOffset
;
1749 // Check whether this question is in current block array.
1751 if (!BlockArrayCheck (CurrentBlockArray
, Offset
, Width
)) {
1753 // This question is not in the current configuration string. Skip it.
1758 // Check this var question is in the var storage
1760 if ((Offset
+ Width
) > VarStoreData
.Size
) {
1762 // This question exceeds the var store size.
1764 return EFI_INVALID_PARAMETER
;
1768 // Check current string length is less than maxsize
1770 if (StrLen ((CHAR16
*) (VarBuffer
+ Offset
)) > IfrString
->MaxSize
) {
1771 return EFI_INVALID_PARAMETER
;
1775 case EFI_IFR_ONE_OF_OPTION_OP
:
1777 // Opcode Scope is zero. This one of option is not to be checked.
1779 if (VarBlockData
.Scope
== 0) {
1784 // Only check for OneOf and OrderList opcode
1786 IfrOneOfOption
= (EFI_IFR_ONE_OF_OPTION
*) IfrOpHdr
;
1787 if (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
) {
1789 // Check current value is the value of one of option.
1791 ASSERT (IfrOneOfOption
->Type
<= EFI_IFR_TYPE_NUM_SIZE_64
);
1792 ZeroMem (&TmpValue
, sizeof (EFI_IFR_TYPE_VALUE
));
1793 CopyMem (&TmpValue
, &IfrOneOfOption
->Value
, IfrOneOfOption
->Header
.Length
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
1794 if (VarValue
== TmpValue
.u64
) {
1796 // The value is one of option value.
1797 // Set OpCode to Zero, don't need check again.
1799 VarBlockData
.OpCode
= 0;
1803 case EFI_IFR_END_OP
:
1804 QuestionReferBitField
= FALSE
;
1806 // Decrease opcode scope for the validated opcode
1808 if (VarBlockData
.Scope
> 0) {
1809 VarBlockData
.Scope
--;
1813 // OneOf value doesn't belong to one of option value.
1815 if ((VarBlockData
.Scope
== 0) && (VarBlockData
.OpCode
== EFI_IFR_ONE_OF_OP
)) {
1816 return EFI_INVALID_PARAMETER
;
1819 case EFI_IFR_GUID_OP
:
1820 if (CompareGuid ((EFI_GUID
*)((UINT8
*)IfrOpHdr
+ sizeof (EFI_IFR_OP_HEADER
)), &gEdkiiIfrBitVarstoreGuid
)) {
1821 QuestionReferBitField
= TRUE
;
1826 // Increase Scope for the validated opcode
1828 if (VarBlockData
.Scope
> 0) {
1829 VarBlockData
.Scope
= (UINT8
) (VarBlockData
.Scope
+ IfrOpHdr
->Scope
);
1834 // Go to the next opcode
1836 IfrOffset
+= IfrOpHdr
->Length
;
1839 // Only one form is in a package list.
1845 // Go to next package.
1847 PackageOffset
+= PackageHeader
.Length
;
1854 This internal function parses IFR data to validate current setting.
1856 @param ConfigElement ConfigResp element string contains the current setting.
1857 @param CurrentBlockArray Current block array.
1858 @param VarBuffer Data buffer for this varstore.
1860 @retval EFI_SUCCESS The current setting is valid.
1861 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1862 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1866 IN CHAR16
*ConfigElement
,
1867 OUT IFR_BLOCK_DATA
**CurrentBlockArray
,
1868 OUT UINT8
**VarBuffer
1871 IFR_BLOCK_DATA
*BlockData
;
1872 IFR_BLOCK_DATA
*NewBlockData
;
1873 EFI_STRING StringPtr
;
1879 UINTN MaxBufferSize
;
1881 IFR_BLOCK_DATA
*BlockArray
;
1885 // Initialize the local variables.
1887 Status
= EFI_SUCCESS
;
1889 NewBlockData
= NULL
;
1892 MaxBufferSize
= HII_LIB_DEFAULT_VARSTORE_SIZE
;
1893 DataBuffer
= AllocateZeroPool (MaxBufferSize
);
1894 if (DataBuffer
== NULL
) {
1895 return EFI_OUT_OF_RESOURCES
;
1901 BlockArray
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
1902 if (BlockArray
== NULL
) {
1903 Status
= EFI_OUT_OF_RESOURCES
;
1906 InitializeListHead (&BlockArray
->Entry
);
1908 StringPtr
= StrStr (ConfigElement
, L
"&OFFSET=");
1909 ASSERT (StringPtr
!= NULL
);
1912 // Parse each <RequestElement> if exists
1913 // Only <BlockName> format is supported by this help function.
1914 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1916 while (*StringPtr
!= 0 && StrnCmp (StringPtr
, L
"&OFFSET=", StrLen (L
"&OFFSET=")) == 0) {
1918 // Skip the &OFFSET= string
1920 StringPtr
+= StrLen (L
"&OFFSET=");
1925 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1926 if (EFI_ERROR (Status
)) {
1933 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1935 FreePool (TmpBuffer
);
1938 StringPtr
+= Length
;
1939 if (StrnCmp (StringPtr
, L
"&WIDTH=", StrLen (L
"&WIDTH=")) != 0) {
1940 Status
= EFI_INVALID_PARAMETER
;
1943 StringPtr
+= StrLen (L
"&WIDTH=");
1948 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1949 if (EFI_ERROR (Status
)) {
1956 (((Length
+ 1) / 2) < sizeof (UINT16
)) ? ((Length
+ 1) / 2) : sizeof (UINT16
)
1958 FreePool (TmpBuffer
);
1961 StringPtr
+= Length
;
1962 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1963 Status
= EFI_INVALID_PARAMETER
;
1967 if (StrnCmp (StringPtr
, L
"&VALUE=", StrLen (L
"&VALUE=")) != 0) {
1968 Status
= EFI_INVALID_PARAMETER
;
1971 StringPtr
+= StrLen (L
"&VALUE=");
1976 Status
= InternalHiiGetValueOfNumber (StringPtr
, &TmpBuffer
, &Length
);
1977 if (EFI_ERROR (Status
)) {
1981 StringPtr
+= Length
;
1982 if (*StringPtr
!= 0 && *StringPtr
!= L
'&') {
1983 Status
= EFI_INVALID_PARAMETER
;
1988 // Check whether VarBuffer is enough
1990 if ((UINT32
)Offset
+ Width
> MaxBufferSize
) {
1991 DataBuffer
= ReallocatePool (
1993 Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
,
1996 if (DataBuffer
== NULL
) {
1997 Status
= EFI_OUT_OF_RESOURCES
;
2000 MaxBufferSize
= Offset
+ Width
+ HII_LIB_DEFAULT_VARSTORE_SIZE
;
2004 // Update the Block with configuration info
2006 CopyMem (DataBuffer
+ Offset
, TmpBuffer
, Width
);
2007 FreePool (TmpBuffer
);
2011 // Set new Block Data
2013 NewBlockData
= (IFR_BLOCK_DATA
*) AllocateZeroPool (sizeof (IFR_BLOCK_DATA
));
2014 if (NewBlockData
== NULL
) {
2015 Status
= EFI_OUT_OF_RESOURCES
;
2018 NewBlockData
->Offset
= Offset
;
2019 NewBlockData
->Width
= Width
;
2022 // Insert the new block data into the block data array.
2024 for (Link
= BlockArray
->Entry
.ForwardLink
; Link
!= &BlockArray
->Entry
; Link
= Link
->ForwardLink
) {
2025 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
2026 if (NewBlockData
->Offset
== BlockData
->Offset
) {
2027 if (NewBlockData
->Width
> BlockData
->Width
) {
2028 BlockData
->Width
= NewBlockData
->Width
;
2030 FreePool (NewBlockData
);
2032 } else if (NewBlockData
->Offset
< BlockData
->Offset
) {
2034 // Insert new block data as the previous one of this link.
2036 InsertTailList (Link
, &NewBlockData
->Entry
);
2042 // Insert new block data into the array tail.
2044 if (Link
== &BlockArray
->Entry
) {
2045 InsertTailList (Link
, &NewBlockData
->Entry
);
2049 // If '\0', parsing is finished.
2051 if (*StringPtr
== 0) {
2055 // Go to next ConfigBlock
2060 // Merge the aligned block data into the single block data.
2062 Link
= BlockArray
->Entry
.ForwardLink
;
2063 while ((Link
!= &BlockArray
->Entry
) && (Link
->ForwardLink
!= &BlockArray
->Entry
)) {
2064 BlockData
= BASE_CR (Link
, IFR_BLOCK_DATA
, Entry
);
2065 NewBlockData
= BASE_CR (Link
->ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2066 if ((NewBlockData
->Offset
>= BlockData
->Offset
) && (NewBlockData
->Offset
<= (BlockData
->Offset
+ BlockData
->Width
))) {
2067 if ((NewBlockData
->Offset
+ NewBlockData
->Width
) > (BlockData
->Offset
+ BlockData
->Width
)) {
2068 BlockData
->Width
= (UINT16
) (NewBlockData
->Offset
+ NewBlockData
->Width
- BlockData
->Offset
);
2070 RemoveEntryList (Link
->ForwardLink
);
2071 FreePool (NewBlockData
);
2074 Link
= Link
->ForwardLink
;
2077 *VarBuffer
= DataBuffer
;
2078 *CurrentBlockArray
= BlockArray
;
2082 if (DataBuffer
!= NULL
) {
2083 FreePool (DataBuffer
);
2086 if (BlockArray
!= NULL
) {
2088 // Free Link Array CurrentBlockArray
2090 while (!IsListEmpty (&BlockArray
->Entry
)) {
2091 BlockData
= BASE_CR (BlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2092 RemoveEntryList (&BlockData
->Entry
);
2093 FreePool (BlockData
);
2095 FreePool (BlockArray
);
2102 This internal function parses IFR data to validate current setting.
2104 @param ConfigResp ConfigResp string contains the current setting.
2105 @param HiiPackageList Point to Hii package list.
2106 @param PackageListLength The length of the pacakge.
2107 @param VarGuid Guid of the buffer storage.
2108 @param VarName Name of the buffer storage.
2109 @param HiiHandle The HiiHandle for this package.
2111 @retval EFI_SUCCESS The current setting is valid.
2112 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
2113 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
2117 InternalHiiValidateCurrentSetting (
2118 IN EFI_STRING ConfigResp
,
2119 IN EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
,
2120 IN UINTN PackageListLength
,
2121 IN EFI_GUID
*VarGuid
,
2123 IN EFI_HII_HANDLE HiiHandle
2128 IFR_BLOCK_DATA
*CurrentBlockArray
;
2129 IFR_BLOCK_DATA
*BlockData
;
2131 BOOLEAN NameValueType
;
2133 CurrentBlockArray
= NULL
;
2136 Status
= EFI_SUCCESS
;
2139 // If StringPtr != NULL, get the request elements.
2141 if (StrStr (ConfigResp
, L
"&OFFSET=") != NULL
) {
2142 Status
= GetBlockDataInfo(ConfigResp
, &CurrentBlockArray
, &VarBuffer
);
2143 if (EFI_ERROR (Status
)) {
2146 NameValueType
= FALSE
;
2149 // Skip header part.
2151 StringPtr
= StrStr (ConfigResp
, L
"PATH=");
2152 ASSERT (StringPtr
!= NULL
);
2154 if (StrStr (StringPtr
, L
"&") != NULL
) {
2155 NameValueType
= TRUE
;
2158 // Not found Request element, return success.
2164 Status
= ValidateQuestionFromVfr(
2176 if (VarBuffer
!= NULL
) {
2177 FreePool (VarBuffer
);
2180 if (CurrentBlockArray
!= NULL
) {
2182 // Free Link Array CurrentBlockArray
2184 while (!IsListEmpty (&CurrentBlockArray
->Entry
)) {
2185 BlockData
= BASE_CR (CurrentBlockArray
->Entry
.ForwardLink
, IFR_BLOCK_DATA
, Entry
);
2186 RemoveEntryList (&BlockData
->Entry
);
2187 FreePool (BlockData
);
2189 FreePool (CurrentBlockArray
);
2196 Check whether the ConfigRequest string has the request elements.
2197 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
2198 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
2200 @param ConfigRequest The input config request string.
2202 @retval TRUE The input include config request elements.
2203 @retval FALSE The input string not includes.
2207 GetElementsFromRequest (
2208 IN EFI_STRING ConfigRequest
2211 EFI_STRING TmpRequest
;
2213 TmpRequest
= StrStr (ConfigRequest
, L
"PATH=");
2214 ASSERT (TmpRequest
!= NULL
);
2216 if ((StrStr (TmpRequest
, L
"&OFFSET=") != NULL
) || (StrStr (TmpRequest
, L
"&") != NULL
)) {
2224 This function parses the input ConfigRequest string and its matched IFR code
2225 string for setting default value and validating current setting.
2227 1. For setting default action, Reset the default value specified by DefaultId
2228 to the driver configuration got by Request string.
2229 2. For validating current setting, Validate the current configuration
2230 by parsing HII form IFR opcode.
2232 NULL request string support depends on the ExportConfig interface of
2233 HiiConfigRouting protocol in UEFI specification.
2235 @param Request A null-terminated Unicode string in
2236 <MultiConfigRequest> format. It can be NULL.
2237 If it is NULL, all current configuration for the
2238 entirety of the current HII database will be validated.
2239 If it is NULL, all configuration for the
2240 entirety of the current HII database will be reset.
2241 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
2242 @param ActionType Action supports setting defaults and validate current setting.
2244 @retval TRUE Action runs successfully.
2245 @retval FALSE Action is not valid or Action can't be executed successfully..
2249 InternalHiiIfrValueAction (
2250 IN CONST EFI_STRING Request
, OPTIONAL
2251 IN UINT16 DefaultId
,
2255 EFI_STRING ConfigAltResp
;
2256 EFI_STRING ConfigAltHdr
;
2257 EFI_STRING ConfigResp
;
2258 EFI_STRING Progress
;
2259 EFI_STRING StringPtr
;
2260 EFI_STRING StringHdr
;
2262 EFI_HANDLE DriverHandle
;
2263 EFI_HANDLE TempDriverHandle
;
2264 EFI_HII_HANDLE
*HiiHandleBuffer
;
2265 EFI_HII_HANDLE HiiHandle
;
2270 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
2271 UINTN PackageListLength
;
2273 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2274 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
2276 ConfigAltResp
= NULL
;
2281 ConfigAltHdr
= NULL
;
2282 HiiHandleBuffer
= NULL
;
2284 TempDriverHandle
= NULL
;
2286 HiiPackageList
= NULL
;
2289 // Only support set default and validate setting action.
2291 if ((ActionType
!= ACTION_SET_DEFAUTL_VALUE
) && (ActionType
!= ACTION_VALIDATE_SETTING
)) {
2296 // Get the full requested value and deault value string.
2298 if (Request
!= NULL
) {
2299 Status
= gHiiConfigRouting
->ExtractConfig (
2306 Status
= gHiiConfigRouting
->ExportConfig (
2312 if (EFI_ERROR (Status
)) {
2316 StringPtr
= ConfigAltResp
;
2317 ASSERT (StringPtr
!= NULL
);
2319 while (*StringPtr
!= L
'\0') {
2321 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
2323 StringHdr
= StringPtr
;
2328 if (StrnCmp (StringPtr
, L
"GUID=", StrLen (L
"GUID=")) != 0) {
2329 Status
= EFI_INVALID_PARAMETER
;
2332 StringPtr
+= StrLen (L
"GUID=");
2333 Status
= InternalHiiGetBufferFromString (StringPtr
, GUID_CONFIG_STRING_TYPE
, (UINT8
**) &VarGuid
);
2334 if (EFI_ERROR (Status
)) {
2339 // Get Name value VarName
2341 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&NAME=", StrLen (L
"&NAME=")) != 0) {
2344 if (*StringPtr
== L
'\0') {
2345 Status
= EFI_INVALID_PARAMETER
;
2348 StringPtr
+= StrLen (L
"&NAME=");
2349 Status
= InternalHiiGetBufferFromString (StringPtr
, NAME_CONFIG_STRING_TYPE
, (UINT8
**) &VarName
);
2350 if (EFI_ERROR (Status
)) {
2355 // Get Path value DevicePath
2357 while (*StringPtr
!= L
'\0' && StrnCmp (StringPtr
, L
"&PATH=", StrLen (L
"&PATH=")) != 0) {
2360 if (*StringPtr
== L
'\0') {
2361 Status
= EFI_INVALID_PARAMETER
;
2364 StringPtr
+= StrLen (L
"&PATH=");
2365 Status
= InternalHiiGetBufferFromString (StringPtr
, PATH_CONFIG_STRING_TYPE
, (UINT8
**) &DevicePath
);
2366 if (EFI_ERROR (Status
)) {
2371 // Get the Driver handle by the got device path.
2373 TempDevicePath
= DevicePath
;
2374 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &TempDevicePath
, &DriverHandle
);
2375 if (EFI_ERROR (Status
)) {
2380 // Find the matched Hii Handle for the found Driver handle
2382 HiiHandleBuffer
= HiiGetHiiHandles (NULL
);
2383 if (HiiHandleBuffer
== NULL
) {
2384 Status
= EFI_NOT_FOUND
;
2388 for (Index
= 0; HiiHandleBuffer
[Index
] != NULL
; Index
++) {
2389 gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, HiiHandleBuffer
[Index
], &TempDriverHandle
);
2390 if (TempDriverHandle
== DriverHandle
) {
2395 HiiHandle
= HiiHandleBuffer
[Index
];
2396 FreePool (HiiHandleBuffer
);
2398 if (HiiHandle
== NULL
) {
2400 // This request string has no its Hii package.
2401 // Its default value and validating can't execute by parsing IFR data.
2402 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
2404 Status
= EFI_SUCCESS
;
2405 goto NextConfigAltResp
;
2409 // 2. Get HiiPackage by HiiHandle
2411 PackageListLength
= 0;
2412 HiiPackageList
= NULL
;
2413 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
2416 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
2418 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
2419 Status
= EFI_INVALID_PARAMETER
;
2423 HiiPackageList
= AllocatePool (PackageListLength
);
2424 if (HiiPackageList
== NULL
) {
2425 Status
= EFI_OUT_OF_RESOURCES
;
2430 // Get PackageList on HiiHandle
2432 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &PackageListLength
, HiiPackageList
);
2433 if (EFI_ERROR (Status
)) {
2438 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
2439 // Get the default configuration string according to the default ID.
2441 Status
= gHiiConfigRouting
->GetAltConfig (
2447 (ActionType
== ACTION_SET_DEFAUTL_VALUE
) ? &DefaultId
:NULL
, // it can be NULL to get the current setting.
2452 // The required setting can't be found. So, it is not required to be validated and set.
2454 if (EFI_ERROR (Status
)) {
2455 Status
= EFI_SUCCESS
;
2456 goto NextConfigAltResp
;
2459 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
2461 if (!GetElementsFromRequest (ConfigResp
)) {
2462 goto NextConfigAltResp
;
2466 // 4. Set the default configuration information or Validate current setting by parse IFR code.
2467 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2469 if (ActionType
== ACTION_SET_DEFAUTL_VALUE
) {
2471 // Set the default configuration information.
2473 Status
= gHiiConfigRouting
->RouteConfig (gHiiConfigRouting
, ConfigResp
, &Progress
);
2476 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2478 Status
= InternalHiiValidateCurrentSetting (ConfigResp
, HiiPackageList
, PackageListLength
, VarGuid
, VarName
, HiiHandle
);
2481 if (EFI_ERROR (Status
)) {
2487 // Free the allocated pacakge buffer and the got ConfigResp string.
2489 if (HiiPackageList
!= NULL
) {
2490 FreePool (HiiPackageList
);
2491 HiiPackageList
= NULL
;
2494 if (ConfigResp
!= NULL
) {
2495 FreePool (ConfigResp
);
2500 // Free the allocated buffer.
2508 FreePool (DevicePath
);
2512 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
2516 // Get and Skip ConfigHdr
2518 while (*StringPtr
!= L
'\0' && *StringPtr
!= L
'&') {
2521 if (*StringPtr
== L
'\0') {
2526 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
2527 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
2529 MaxLen
= 1 + StringPtr
- StringHdr
+ 8 + 1;
2530 ConfigAltHdr
= AllocateZeroPool ( MaxLen
* sizeof (CHAR16
));
2531 if (ConfigAltHdr
== NULL
) {
2532 Status
= EFI_OUT_OF_RESOURCES
;
2535 StrCpyS (ConfigAltHdr
, MaxLen
, L
"&");
2536 StrnCatS (ConfigAltHdr
, MaxLen
, StringHdr
, StringPtr
- StringHdr
);
2537 StrCatS (ConfigAltHdr
, MaxLen
, L
"&ALTCFG=");
2540 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
2542 while ((StringHdr
= StrStr (StringPtr
, ConfigAltHdr
)) != NULL
) {
2543 StringPtr
= StringHdr
+ StrLen (ConfigAltHdr
);
2544 if (*StringPtr
== L
'\0') {
2550 // Free the allocated ConfigAltHdr string
2552 FreePool (ConfigAltHdr
);
2553 if (*StringPtr
== L
'\0') {
2558 // Find &GUID as the next ConfigHdr
2560 StringPtr
= StrStr (StringPtr
, L
"&GUID");
2561 if (StringPtr
== NULL
) {
2572 if (VarGuid
!= NULL
) {
2576 if (VarName
!= NULL
) {
2580 if (DevicePath
!= NULL
) {
2581 FreePool (DevicePath
);
2584 if (ConfigResp
!= NULL
) {
2585 FreePool (ConfigResp
);
2588 if (ConfigAltResp
!= NULL
) {
2589 FreePool (ConfigAltResp
);
2592 if (HiiPackageList
!= NULL
) {
2593 FreePool (HiiPackageList
);
2596 if (EFI_ERROR (Status
)) {
2604 Validate the current configuration by parsing HII form IFR opcode.
2606 NULL request string support depends on the ExportConfig interface of
2607 HiiConfigRouting protocol in UEFI specification.
2609 @param Request A null-terminated Unicode string in
2610 <MultiConfigRequest> format. It can be NULL.
2611 If it is NULL, all current configuration for the
2612 entirety of the current HII database will be validated.
2614 @retval TRUE Current configuration is valid.
2615 @retval FALSE Current configuration is invalid.
2619 HiiValidateSettings (
2620 IN CONST EFI_STRING Request OPTIONAL
2623 return InternalHiiIfrValueAction (Request
, 0, ACTION_VALIDATE_SETTING
);
2627 Reset the default value specified by DefaultId to the driver
2628 configuration got by Request string.
2630 NULL request string support depends on the ExportConfig interface of
2631 HiiConfigRouting protocol in UEFI specification.
2633 @param Request A null-terminated Unicode string in
2634 <MultiConfigRequest> format. It can be NULL.
2635 If it is NULL, all configuration for the
2636 entirety of the current HII database will be reset.
2637 @param DefaultId Specifies the type of defaults to retrieve.
2639 @retval TRUE The default value is set successfully.
2640 @retval FALSE The default value can't be found and set.
2645 IN CONST EFI_STRING Request
, OPTIONAL
2649 return InternalHiiIfrValueAction (Request
, DefaultId
, ACTION_SET_DEFAUTL_VALUE
);
2653 Determines if two values in config strings match.
2655 Compares the substring between StartSearchString and StopSearchString in
2656 FirstString to the substring between StartSearchString and StopSearchString
2657 in SecondString. If the two substrings match, then TRUE is returned. If the
2658 two substrings do not match, then FALSE is returned.
2660 If FirstString is NULL, then ASSERT().
2661 If SecondString is NULL, then ASSERT().
2662 If StartSearchString is NULL, then ASSERT().
2663 If StopSearchString is NULL, then ASSERT().
2665 @param FirstString Pointer to the first Null-terminated Unicode string.
2666 @param SecondString Pointer to the second Null-terminated Unicode string.
2667 @param StartSearchString Pointer to the Null-terminated Unicode string that
2668 marks the start of the value string to compare.
2669 @param StopSearchString Pointer to the Null-terminated Unicode string that
2670 marks the end of the value string to compare.
2672 @retval FALSE StartSearchString is not present in FirstString.
2673 @retval FALSE StartSearchString is not present in SecondString.
2674 @retval FALSE StopSearchString is not present in FirstString.
2675 @retval FALSE StopSearchString is not present in SecondString.
2676 @retval FALSE The length of the substring in FirstString is not the
2677 same length as the substring in SecondString.
2678 @retval FALSE The value string in FirstString does not matche the
2679 value string in SecondString.
2680 @retval TRUE The value string in FirstString matches the value
2681 string in SecondString.
2686 InternalHiiCompareSubString (
2687 IN CHAR16
*FirstString
,
2688 IN CHAR16
*SecondString
,
2689 IN CHAR16
*StartSearchString
,
2690 IN CHAR16
*StopSearchString
2693 CHAR16
*EndFirstString
;
2694 CHAR16
*EndSecondString
;
2696 ASSERT (FirstString
!= NULL
);
2697 ASSERT (SecondString
!= NULL
);
2698 ASSERT (StartSearchString
!= NULL
);
2699 ASSERT (StopSearchString
!= NULL
);
2701 FirstString
= StrStr (FirstString
, StartSearchString
);
2702 if (FirstString
== NULL
) {
2706 SecondString
= StrStr (SecondString
, StartSearchString
);
2707 if (SecondString
== NULL
) {
2711 EndFirstString
= StrStr (FirstString
, StopSearchString
);
2712 if (EndFirstString
== NULL
) {
2716 EndSecondString
= StrStr (SecondString
, StopSearchString
);
2717 if (EndSecondString
== NULL
) {
2721 if ((EndFirstString
- FirstString
) != (EndSecondString
- SecondString
)) {
2725 return (BOOLEAN
)(StrnCmp (FirstString
, SecondString
, EndFirstString
- FirstString
) == 0);
2729 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2731 If ConfigHdr is NULL, then ASSERT().
2733 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2734 @param[in] Guid GUID of the storage.
2735 @param[in] Name NAME of the storage.
2737 @retval TRUE Routing information matches <ConfigHdr>.
2738 @retval FALSE Routing information does not match <ConfigHdr>.
2743 HiiIsConfigHdrMatch (
2744 IN CONST EFI_STRING ConfigHdr
,
2745 IN CONST EFI_GUID
*Guid
, OPTIONAL
2746 IN CONST CHAR16
*Name OPTIONAL
2749 EFI_STRING CompareConfigHdr
;
2752 ASSERT (ConfigHdr
!= NULL
);
2755 // Use Guid and Name to generate a <ConfigHdr> string
2757 CompareConfigHdr
= HiiConstructConfigHdr (Guid
, Name
, NULL
);
2758 if (CompareConfigHdr
== NULL
) {
2765 // Compare GUID value strings
2767 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"GUID=", L
"&NAME=");
2770 if (Result
&& Name
!= NULL
) {
2772 // Compare NAME value strings
2774 Result
= InternalHiiCompareSubString (ConfigHdr
, CompareConfigHdr
, L
"&NAME=", L
"&PATH=");
2778 // Free the <ConfigHdr> string
2780 FreePool (CompareConfigHdr
);
2786 Retrieves uncommitted data from the Form Browser and converts it to a binary
2789 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2790 parameter that may be NULL.
2791 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2792 is an optional parameter that may be NULL.
2793 @param[in] BufferSize Length in bytes of buffer to hold retrieved data.
2794 @param[out] Buffer Buffer of data to be updated.
2796 @retval FALSE The uncommitted data could not be retrieved.
2797 @retval TRUE The uncommitted data was retrieved.
2803 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2804 IN CONST CHAR16
*VariableName
, OPTIONAL
2805 IN UINTN BufferSize
,
2809 EFI_STRING ResultsData
;
2811 EFI_STRING ConfigResp
;
2816 // Retrieve the results data from the Browser Callback
2818 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, NULL
);
2819 if (ResultsData
== NULL
) {
2824 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2826 Size
= (StrLen (mConfigHdrTemplate
) + 1) * sizeof (CHAR16
);
2827 Size
= Size
+ (StrLen (ResultsData
) + 1) * sizeof (CHAR16
);
2828 ConfigResp
= AllocateZeroPool (Size
);
2829 UnicodeSPrint (ConfigResp
, Size
, L
"%s&%s", mConfigHdrTemplate
, ResultsData
);
2832 // Free the allocated buffer
2834 FreePool (ResultsData
);
2835 if (ConfigResp
== NULL
) {
2840 // Convert <ConfigResp> to a buffer
2842 Status
= gHiiConfigRouting
->ConfigToBlock (
2850 // Free the allocated buffer
2852 FreePool (ConfigResp
);
2854 if (EFI_ERROR (Status
)) {
2862 Updates uncommitted data in the Form Browser.
2864 If Buffer is NULL, then ASSERT().
2866 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2867 parameter that may be NULL.
2868 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2869 is an optional parameter that may be NULL.
2870 @param[in] BufferSize Length, in bytes, of Buffer.
2871 @param[in] Buffer Buffer of data to commit.
2872 @param[in] RequestElement An optional field to specify which part of the
2873 buffer data will be send back to Browser. If NULL,
2874 the whole buffer of data will be committed to
2876 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2878 @retval FALSE The uncommitted data could not be updated.
2879 @retval TRUE The uncommitted data was updated.
2885 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
2886 IN CONST CHAR16
*VariableName
, OPTIONAL
2887 IN UINTN BufferSize
,
2888 IN CONST UINT8
*Buffer
,
2889 IN CONST CHAR16
*RequestElement OPTIONAL
2893 EFI_STRING ConfigRequest
;
2894 EFI_STRING ConfigResp
;
2895 EFI_STRING ResultsData
;
2897 ASSERT (Buffer
!= NULL
);
2900 // Construct <ConfigRequest>
2902 if (RequestElement
== NULL
) {
2904 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2905 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2907 Size
= (StrLen (mConfigHdrTemplate
) + 32 + 1) * sizeof (CHAR16
);
2908 ConfigRequest
= AllocateZeroPool (Size
);
2909 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate
, (UINT64
)BufferSize
);
2912 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2913 // followed by <RequestElement> followed by a Null-terminator
2915 Size
= StrLen (mConfigHdrTemplate
) * sizeof (CHAR16
);
2916 Size
= Size
+ (StrLen (RequestElement
) + 1) * sizeof (CHAR16
);
2917 ConfigRequest
= AllocateZeroPool (Size
);
2918 UnicodeSPrint (ConfigRequest
, Size
, L
"%s%s", mConfigHdrTemplate
, RequestElement
);
2920 if (ConfigRequest
== NULL
) {
2925 // Convert <ConfigRequest> to <ConfigResp>
2927 ConfigResp
= InternalHiiBlockToConfig (ConfigRequest
, Buffer
, BufferSize
);
2928 FreePool (ConfigRequest
);
2929 if (ConfigResp
== NULL
) {
2934 // Set data in the uncommitted browser state information
2936 ResultsData
= InternalHiiBrowserCallback (VariableGuid
, VariableName
, ConfigResp
+ StrLen(mConfigHdrTemplate
) + 1);
2937 FreePool (ConfigResp
);
2939 return (BOOLEAN
)(ResultsData
!= NULL
);
2942 /////////////////////////////////////////
2943 /////////////////////////////////////////
2945 /////////////////////////////////////////
2946 /////////////////////////////////////////
2948 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2954 } HII_LIB_OPCODE_BUFFER
;
2957 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2959 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth
[] = {
2960 1, // EFI_IFR_TYPE_NUM_SIZE_8
2961 2, // EFI_IFR_TYPE_NUM_SIZE_16
2962 4, // EFI_IFR_TYPE_NUM_SIZE_32
2963 8, // EFI_IFR_TYPE_NUM_SIZE_64
2964 1, // EFI_IFR_TYPE_BOOLEAN
2965 3, // EFI_IFR_TYPE_TIME
2966 4, // EFI_IFR_TYPE_DATE
2967 2 // EFI_IFR_TYPE_STRING
2971 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2972 HiiFreeOpCodeHandle().
2974 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2975 @retval Other A new OpCode handle.
2980 HiiAllocateOpCodeHandle (
2984 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
2986 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER
));
2987 if (OpCodeBuffer
== NULL
) {
2990 OpCodeBuffer
->Buffer
= (UINT8
*)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE
);
2991 if (OpCodeBuffer
->Buffer
== NULL
) {
2992 FreePool (OpCodeBuffer
);
2995 OpCodeBuffer
->BufferSize
= HII_LIB_OPCODE_ALLOCATION_SIZE
;
2996 OpCodeBuffer
->Position
= 0;
2997 return (VOID
*)OpCodeBuffer
;
3001 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().
3002 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
3003 Handle are also freed.
3005 If OpCodeHandle is NULL, then ASSERT().
3007 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3012 HiiFreeOpCodeHandle (
3016 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
3018 ASSERT (OpCodeHandle
!= NULL
);
3020 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
3021 if (OpCodeBuffer
->Buffer
!= NULL
) {
3022 FreePool (OpCodeBuffer
->Buffer
);
3024 FreePool (OpCodeBuffer
);
3028 Internal function gets the current position of opcode buffer.
3030 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3032 @return Current position of opcode buffer.
3036 InternalHiiOpCodeHandlePosition (
3037 IN VOID
*OpCodeHandle
3040 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Position
;
3044 Internal function gets the start pointer of opcode buffer.
3046 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3048 @return Pointer to the opcode buffer base.
3052 InternalHiiOpCodeHandleBuffer (
3053 IN VOID
*OpCodeHandle
3056 return ((HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
)->Buffer
;
3060 Internal function reserves the enough buffer for current opcode.
3061 When the buffer is not enough, Opcode buffer will be extended.
3063 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3064 @param[in] Size Size of current opcode.
3066 @return Pointer to the current opcode.
3070 InternalHiiGrowOpCodeHandle (
3071 IN VOID
*OpCodeHandle
,
3075 HII_LIB_OPCODE_BUFFER
*OpCodeBuffer
;
3078 ASSERT (OpCodeHandle
!= NULL
);
3080 OpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)OpCodeHandle
;
3081 if (OpCodeBuffer
->Position
+ Size
> OpCodeBuffer
->BufferSize
) {
3082 Buffer
= ReallocatePool (
3083 OpCodeBuffer
->BufferSize
,
3084 OpCodeBuffer
->BufferSize
+ (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
),
3085 OpCodeBuffer
->Buffer
3087 ASSERT (Buffer
!= NULL
);
3088 OpCodeBuffer
->Buffer
= Buffer
;
3089 OpCodeBuffer
->BufferSize
+= (Size
+ HII_LIB_OPCODE_ALLOCATION_SIZE
);
3091 Buffer
= OpCodeBuffer
->Buffer
+ OpCodeBuffer
->Position
;
3092 OpCodeBuffer
->Position
+= Size
;
3097 Internal function creates opcode based on the template opcode.
3099 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3100 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
3101 @param[in] OpCode OpCode IFR value.
3102 @param[in] OpCodeSize Size of opcode.
3103 @param[in] ExtensionSize Size of extended opcode.
3104 @param[in] Scope Scope bit of opcode.
3106 @return Pointer to the current opcode with opcode data.
3110 InternalHiiCreateOpCodeExtended (
3111 IN VOID
*OpCodeHandle
,
3112 IN VOID
*OpCodeTemplate
,
3114 IN UINTN OpCodeSize
,
3115 IN UINTN ExtensionSize
,
3119 EFI_IFR_OP_HEADER
*Header
;
3122 ASSERT (OpCodeTemplate
!= NULL
);
3123 ASSERT ((OpCodeSize
+ ExtensionSize
) <= 0x7F);
3125 Header
= (EFI_IFR_OP_HEADER
*)OpCodeTemplate
;
3126 Header
->OpCode
= OpCode
;
3127 Header
->Scope
= Scope
;
3128 Header
->Length
= (UINT8
)(OpCodeSize
+ ExtensionSize
);
3129 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, Header
->Length
);
3130 return (UINT8
*)CopyMem (Buffer
, Header
, OpCodeSize
);
3134 Internal function creates opcode based on the template opcode for the normal opcode.
3136 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3137 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
3138 @param[in] OpCode OpCode IFR value.
3139 @param[in] OpCodeSize Size of opcode.
3141 @return Pointer to the current opcode with opcode data.
3145 InternalHiiCreateOpCode (
3146 IN VOID
*OpCodeHandle
,
3147 IN VOID
*OpCodeTemplate
,
3152 return InternalHiiCreateOpCodeExtended (OpCodeHandle
, OpCodeTemplate
, OpCode
, OpCodeSize
, 0, 0);
3156 Append raw opcodes to an OpCodeHandle.
3158 If OpCodeHandle is NULL, then ASSERT().
3159 If RawBuffer is NULL, then ASSERT();
3161 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3162 @param[in] RawBuffer Buffer of opcodes to append.
3163 @param[in] RawBufferSize The size, in bytes, of Buffer.
3165 @retval NULL There is not enough space left in Buffer to add the opcode.
3166 @retval Other A pointer to the appended opcodes.
3171 HiiCreateRawOpCodes (
3172 IN VOID
*OpCodeHandle
,
3173 IN UINT8
*RawBuffer
,
3174 IN UINTN RawBufferSize
3179 ASSERT (RawBuffer
!= NULL
);
3181 Buffer
= InternalHiiGrowOpCodeHandle (OpCodeHandle
, RawBufferSize
);
3182 return (UINT8
*)CopyMem (Buffer
, RawBuffer
, RawBufferSize
);
3186 Append opcodes from one OpCode Handle to another OpCode handle.
3188 If OpCodeHandle is NULL, then ASSERT().
3189 If RawOpCodeHandle is NULL, then ASSERT();
3191 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3192 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
3194 @retval NULL There is not enough space left in Buffer to add the opcode.
3195 @retval Other A pointer to the appended opcodes.
3200 InternalHiiAppendOpCodes (
3201 IN VOID
*OpCodeHandle
,
3202 IN VOID
*RawOpCodeHandle
3205 HII_LIB_OPCODE_BUFFER
*RawOpCodeBuffer
;
3207 ASSERT (RawOpCodeHandle
!= NULL
);
3209 RawOpCodeBuffer
= (HII_LIB_OPCODE_BUFFER
*)RawOpCodeHandle
;
3210 return HiiCreateRawOpCodes (OpCodeHandle
, RawOpCodeBuffer
->Buffer
, RawOpCodeBuffer
->Position
);
3214 Create EFI_IFR_END_OP opcode.
3216 If OpCodeHandle is NULL, then ASSERT().
3218 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3220 @retval NULL There is not enough space left in Buffer to add the opcode.
3221 @retval Other A pointer to the created opcode.
3226 HiiCreateEndOpCode (
3227 IN VOID
*OpCodeHandle
3232 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_END_OP
, sizeof (OpCode
));
3236 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
3238 If OpCodeHandle is NULL, then ASSERT().
3239 If Type is invalid, then ASSERT().
3240 If Flags is invalid, then ASSERT().
3242 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3243 @param[in] StringId StringId for the option
3244 @param[in] Flags Flags for the option
3245 @param[in] Type Type for the option
3246 @param[in] Value Value for the option
3248 @retval NULL There is not enough space left in Buffer to add the opcode.
3249 @retval Other A pointer to the created opcode.
3254 HiiCreateOneOfOptionOpCode (
3255 IN VOID
*OpCodeHandle
,
3262 EFI_IFR_ONE_OF_OPTION OpCode
;
3264 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
3266 ZeroMem (&OpCode
, sizeof (OpCode
));
3267 OpCode
.Option
= StringId
;
3268 OpCode
.Flags
= (UINT8
) (Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
));
3270 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
3272 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OPTION_OP
, OFFSET_OF(EFI_IFR_ONE_OF_OPTION
, Value
) + mHiiDefaultTypeToWidth
[Type
]);
3276 Create EFI_IFR_DEFAULT_OP opcode.
3278 If OpCodeHandle is NULL, then ASSERT().
3279 If Type is invalid, then ASSERT().
3281 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3282 @param[in] DefaultId DefaultId for the default
3283 @param[in] Type Type for the default
3284 @param[in] Value Value for the default
3286 @retval NULL There is not enough space left in Buffer to add the opcode.
3287 @retval Other A pointer to the created opcode.
3292 HiiCreateDefaultOpCode (
3293 IN VOID
*OpCodeHandle
,
3294 IN UINT16 DefaultId
,
3299 EFI_IFR_DEFAULT OpCode
;
3301 ASSERT (Type
< EFI_IFR_TYPE_OTHER
);
3303 ZeroMem (&OpCode
, sizeof (OpCode
));
3305 OpCode
.DefaultId
= DefaultId
;
3306 CopyMem (&OpCode
.Value
, &Value
, mHiiDefaultTypeToWidth
[Type
]);
3308 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DEFAULT_OP
, OFFSET_OF(EFI_IFR_DEFAULT
, Value
) + mHiiDefaultTypeToWidth
[Type
]);
3312 Create EFI_IFR_GUID opcode.
3314 If OpCodeHandle is NULL, then ASSERT().
3315 If Guid is NULL, then ASSERT().
3316 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
3318 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3319 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
3320 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
3321 optional parameter that may be NULL. If this
3322 parameter is NULL, then the GUID extension
3323 region of the created opcode is filled with zeros.
3324 If this parameter is not NULL, then the GUID
3325 extension region of GuidData will be copied to
3326 the GUID extension region of the created opcode.
3327 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
3328 must be >= sizeof(EFI_IFR_GUID).
3330 @retval NULL There is not enough space left in Buffer to add the opcode.
3331 @retval Other A pointer to the created opcode.
3336 HiiCreateGuidOpCode (
3337 IN VOID
*OpCodeHandle
,
3338 IN CONST EFI_GUID
*Guid
,
3339 IN CONST VOID
*GuidOpCode
, OPTIONAL
3343 EFI_IFR_GUID OpCode
;
3344 EFI_IFR_GUID
*OpCodePointer
;
3346 ASSERT (Guid
!= NULL
);
3347 ASSERT (OpCodeSize
>= sizeof (OpCode
));
3349 ZeroMem (&OpCode
, sizeof (OpCode
));
3350 CopyGuid ((EFI_GUID
*)(VOID
*)&OpCode
.Guid
, Guid
);
3352 OpCodePointer
= (EFI_IFR_GUID
*)InternalHiiCreateOpCodeExtended (
3357 OpCodeSize
- sizeof (OpCode
),
3360 if (OpCodePointer
!= NULL
&& GuidOpCode
!= NULL
) {
3361 CopyMem (OpCodePointer
+ 1, (EFI_IFR_GUID
*)GuidOpCode
+ 1, OpCodeSize
- sizeof (OpCode
));
3363 return (UINT8
*)OpCodePointer
;
3367 Create EFI_IFR_ACTION_OP opcode.
3369 If OpCodeHandle is NULL, then ASSERT().
3370 If any reserved bits are set in QuestionFlags, then ASSERT().
3372 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3373 @param[in] QuestionId Question ID
3374 @param[in] Prompt String ID for Prompt
3375 @param[in] Help String ID for Help
3376 @param[in] QuestionFlags Flags in Question Header
3377 @param[in] QuestionConfig String ID for configuration
3379 @retval NULL There is not enough space left in Buffer to add the opcode.
3380 @retval Other A pointer to the created opcode.
3385 HiiCreateActionOpCode (
3386 IN VOID
*OpCodeHandle
,
3387 IN EFI_QUESTION_ID QuestionId
,
3388 IN EFI_STRING_ID Prompt
,
3389 IN EFI_STRING_ID Help
,
3390 IN UINT8 QuestionFlags
,
3391 IN EFI_STRING_ID QuestionConfig
3394 EFI_IFR_ACTION OpCode
;
3396 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3398 ZeroMem (&OpCode
, sizeof (OpCode
));
3399 OpCode
.Question
.QuestionId
= QuestionId
;
3400 OpCode
.Question
.Header
.Prompt
= Prompt
;
3401 OpCode
.Question
.Header
.Help
= Help
;
3402 OpCode
.Question
.Flags
= QuestionFlags
;
3403 OpCode
.QuestionConfig
= QuestionConfig
;
3405 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_ACTION_OP
, sizeof (OpCode
));
3409 Create EFI_IFR_SUBTITLE_OP opcode.
3411 If OpCodeHandle is NULL, then ASSERT().
3412 If any reserved bits are set in Flags, then ASSERT().
3413 If Scope > 1, then ASSERT().
3415 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3416 @param[in] Prompt String ID for Prompt
3417 @param[in] Help String ID for Help
3418 @param[in] Flags Subtitle opcode flags
3419 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
3420 0 if this opcode is within the current scope.
3422 @retval NULL There is not enough space left in Buffer to add the opcode.
3423 @retval Other A pointer to the created opcode.
3428 HiiCreateSubTitleOpCode (
3429 IN VOID
*OpCodeHandle
,
3430 IN EFI_STRING_ID Prompt
,
3431 IN EFI_STRING_ID Help
,
3436 EFI_IFR_SUBTITLE OpCode
;
3438 ASSERT (Scope
<= 1);
3439 ASSERT ((Flags
& (~(EFI_IFR_FLAGS_HORIZONTAL
))) == 0);
3441 ZeroMem (&OpCode
, sizeof (OpCode
));
3442 OpCode
.Statement
.Prompt
= Prompt
;
3443 OpCode
.Statement
.Help
= Help
;
3444 OpCode
.Flags
= Flags
;
3446 return InternalHiiCreateOpCodeExtended (
3449 EFI_IFR_SUBTITLE_OP
,
3457 Create EFI_IFR_REF_OP opcode.
3459 If OpCodeHandle is NULL, then ASSERT().
3460 If any reserved bits are set in QuestionFlags, then ASSERT().
3462 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3463 @param[in] FormId Destination Form ID
3464 @param[in] Prompt String ID for Prompt
3465 @param[in] Help String ID for Help
3466 @param[in] QuestionFlags Flags in Question Header
3467 @param[in] QuestionId Question ID
3469 @retval NULL There is not enough space left in Buffer to add the opcode.
3470 @retval Other A pointer to the created opcode.
3475 HiiCreateGotoOpCode (
3476 IN VOID
*OpCodeHandle
,
3477 IN EFI_FORM_ID FormId
,
3478 IN EFI_STRING_ID Prompt
,
3479 IN EFI_STRING_ID Help
,
3480 IN UINT8 QuestionFlags
,
3481 IN EFI_QUESTION_ID QuestionId
3486 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3488 ZeroMem (&OpCode
, sizeof (OpCode
));
3489 OpCode
.Question
.Header
.Prompt
= Prompt
;
3490 OpCode
.Question
.Header
.Help
= Help
;
3491 OpCode
.Question
.QuestionId
= QuestionId
;
3492 OpCode
.Question
.Flags
= QuestionFlags
;
3493 OpCode
.FormId
= FormId
;
3495 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, sizeof (OpCode
));
3499 Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode.
3501 When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created.
3502 When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created.
3503 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created.
3504 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created.
3506 If OpCodeHandle is NULL, then ASSERT().
3507 If any reserved bits are set in QuestionFlags, then ASSERT().
3509 @param[in] OpCodeHandle The handle to the buffer of opcodes.
3510 @param[in] RefFormId The Destination Form ID.
3511 @param[in] Prompt The string ID for Prompt.
3512 @param[in] Help The string ID for Help.
3513 @param[in] QuestionFlags The flags in Question Header
3514 @param[in] QuestionId Question ID.
3515 @param[in] RefQuestionId The question on the form to which this link is referring.
3516 If its value is zero, then the link refers to the top of the form.
3517 @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is
3518 zero, then the link is to the current form set.
3519 @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of
3520 the device path to which the form set containing the form specified by FormId.
3521 If its value is zero, then the link refers to the current page.
3523 @retval NULL There is not enough space left in Buffer to add the opcode.
3524 @retval Other A pointer to the created opcode.
3529 HiiCreateGotoExOpCode (
3530 IN VOID
*OpCodeHandle
,
3531 IN EFI_FORM_ID RefFormId
,
3532 IN EFI_STRING_ID Prompt
,
3533 IN EFI_STRING_ID Help
,
3534 IN UINT8 QuestionFlags
,
3535 IN EFI_QUESTION_ID QuestionId
,
3536 IN EFI_QUESTION_ID RefQuestionId
,
3537 IN EFI_GUID
*RefFormSetId
, OPTIONAL
3538 IN EFI_STRING_ID RefDevicePath
3541 EFI_IFR_REF4 OpCode
;
3544 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3546 ZeroMem (&OpCode
, sizeof (OpCode
));
3547 OpCode
.Question
.Header
.Prompt
= Prompt
;
3548 OpCode
.Question
.Header
.Help
= Help
;
3549 OpCode
.Question
.QuestionId
= QuestionId
;
3550 OpCode
.Question
.Flags
= QuestionFlags
;
3551 OpCode
.FormId
= RefFormId
;
3552 OpCode
.QuestionId
= RefQuestionId
;
3553 OpCode
.DevicePath
= RefDevicePath
;
3554 if (RefFormSetId
!= NULL
) {
3555 CopyMem (&OpCode
.FormSetId
, RefFormSetId
, sizeof (OpCode
.FormSetId
));
3559 // Cacluate OpCodeSize based on the input Ref value.
3560 // Try to use the small OpCode to save size.
3562 OpCodeSize
= sizeof (EFI_IFR_REF
);
3563 if (RefDevicePath
!= 0) {
3564 OpCodeSize
= sizeof (EFI_IFR_REF4
);
3565 } else if (RefFormSetId
!= NULL
) {
3566 OpCodeSize
= sizeof (EFI_IFR_REF3
);
3567 } else if (RefQuestionId
!= 0) {
3568 OpCodeSize
= sizeof (EFI_IFR_REF2
);
3571 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_REF_OP
, OpCodeSize
);
3575 Create EFI_IFR_CHECKBOX_OP opcode.
3577 If OpCodeHandle is NULL, then ASSERT().
3578 If any reserved bits are set in QuestionFlags, then ASSERT().
3579 If any reserved bits are set in CheckBoxFlags, then ASSERT().
3581 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3582 @param[in] QuestionId Question ID
3583 @param[in] VarStoreId Storage ID
3584 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3585 for this name/value pair.
3586 @param[in] Prompt String ID for Prompt
3587 @param[in] Help String ID for Help
3588 @param[in] QuestionFlags Flags in Question Header
3589 @param[in] CheckBoxFlags Flags for checkbox opcode
3590 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3591 is an optional parameter that may be NULL.
3593 @retval NULL There is not enough space left in Buffer to add the opcode.
3594 @retval Other A pointer to the created opcode.
3599 HiiCreateCheckBoxOpCode (
3600 IN VOID
*OpCodeHandle
,
3601 IN EFI_QUESTION_ID QuestionId
,
3602 IN EFI_VARSTORE_ID VarStoreId
,
3603 IN UINT16 VarOffset
,
3604 IN EFI_STRING_ID Prompt
,
3605 IN EFI_STRING_ID Help
,
3606 IN UINT8 QuestionFlags
,
3607 IN UINT8 CheckBoxFlags
,
3608 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3611 EFI_IFR_CHECKBOX OpCode
;
3614 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3616 ZeroMem (&OpCode
, sizeof (OpCode
));
3617 OpCode
.Question
.QuestionId
= QuestionId
;
3618 OpCode
.Question
.VarStoreId
= VarStoreId
;
3619 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3620 OpCode
.Question
.Header
.Prompt
= Prompt
;
3621 OpCode
.Question
.Header
.Help
= Help
;
3622 OpCode
.Question
.Flags
= QuestionFlags
;
3623 OpCode
.Flags
= CheckBoxFlags
;
3625 if (DefaultsOpCodeHandle
== NULL
) {
3626 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
));
3629 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3630 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_CHECKBOX_OP
, sizeof (OpCode
), 0, 1);
3631 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3632 HiiCreateEndOpCode (OpCodeHandle
);
3633 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3637 Create EFI_IFR_NUMERIC_OP opcode.
3639 If OpCodeHandle is NULL, then ASSERT().
3640 If any reserved bits are set in QuestionFlags, then ASSERT().
3641 If any reserved bits are set in NumericFlags, then ASSERT().
3643 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3644 @param[in] QuestionId Question ID
3645 @param[in] VarStoreId Storage ID
3646 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3647 for this name/value pair.
3648 @param[in] Prompt String ID for Prompt
3649 @param[in] Help String ID for Help
3650 @param[in] QuestionFlags Flags in Question Header
3651 @param[in] NumericFlags Flags for numeric opcode
3652 @param[in] Minimum Numeric minimum value
3653 @param[in] Maximum Numeric maximum value
3654 @param[in] Step Numeric step for edit
3655 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3656 is an optional parameter that may be NULL.
3658 @retval NULL There is not enough space left in Buffer to add the opcode.
3659 @retval Other A pointer to the created opcode.
3664 HiiCreateNumericOpCode (
3665 IN VOID
*OpCodeHandle
,
3666 IN EFI_QUESTION_ID QuestionId
,
3667 IN EFI_VARSTORE_ID VarStoreId
,
3668 IN UINT16 VarOffset
,
3669 IN EFI_STRING_ID Prompt
,
3670 IN EFI_STRING_ID Help
,
3671 IN UINT8 QuestionFlags
,
3672 IN UINT8 NumericFlags
,
3676 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3679 EFI_IFR_NUMERIC OpCode
;
3683 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3686 ZeroMem (&OpCode
, sizeof (OpCode
));
3687 OpCode
.Question
.QuestionId
= QuestionId
;
3688 OpCode
.Question
.VarStoreId
= VarStoreId
;
3689 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3690 OpCode
.Question
.Header
.Prompt
= Prompt
;
3691 OpCode
.Question
.Header
.Help
= Help
;
3692 OpCode
.Question
.Flags
= QuestionFlags
;
3693 OpCode
.Flags
= NumericFlags
;
3695 switch (NumericFlags
& EFI_IFR_NUMERIC_SIZE
) {
3696 case EFI_IFR_NUMERIC_SIZE_1
:
3697 OpCode
.data
.u8
.MinValue
= (UINT8
)Minimum
;
3698 OpCode
.data
.u8
.MaxValue
= (UINT8
)Maximum
;
3699 OpCode
.data
.u8
.Step
= (UINT8
)Step
;
3703 case EFI_IFR_NUMERIC_SIZE_2
:
3704 OpCode
.data
.u16
.MinValue
= (UINT16
)Minimum
;
3705 OpCode
.data
.u16
.MaxValue
= (UINT16
)Maximum
;
3706 OpCode
.data
.u16
.Step
= (UINT16
)Step
;
3710 case EFI_IFR_NUMERIC_SIZE_4
:
3711 OpCode
.data
.u32
.MinValue
= (UINT32
)Minimum
;
3712 OpCode
.data
.u32
.MaxValue
= (UINT32
)Maximum
;
3713 OpCode
.data
.u32
.Step
= (UINT32
)Step
;
3717 case EFI_IFR_NUMERIC_SIZE_8
:
3718 OpCode
.data
.u64
.MinValue
= Minimum
;
3719 OpCode
.data
.u64
.MaxValue
= Maximum
;
3720 OpCode
.data
.u64
.Step
= Step
;
3725 Length
+= OFFSET_OF (EFI_IFR_NUMERIC
, data
);
3727 if (DefaultsOpCodeHandle
== NULL
) {
3728 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, Length
);
3731 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3732 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_NUMERIC_OP
, Length
, 0, 1);
3733 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3734 HiiCreateEndOpCode (OpCodeHandle
);
3735 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3739 Create EFI_IFR_STRING_OP opcode.
3741 If OpCodeHandle is NULL, then ASSERT().
3742 If any reserved bits are set in QuestionFlags, then ASSERT().
3743 If any reserved bits are set in StringFlags, then ASSERT().
3745 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3746 @param[in] QuestionId Question ID
3747 @param[in] VarStoreId Storage ID
3748 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3749 for this name/value pair.
3750 @param[in] Prompt String ID for Prompt
3751 @param[in] Help String ID for Help
3752 @param[in] QuestionFlags Flags in Question Header
3753 @param[in] StringFlags Flags for string opcode
3754 @param[in] MinSize String minimum length
3755 @param[in] MaxSize String maximum length
3756 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3757 is an optional parameter that may be NULL.
3759 @retval NULL There is not enough space left in Buffer to add the opcode.
3760 @retval Other A pointer to the created opcode.
3765 HiiCreateStringOpCode (
3766 IN VOID
*OpCodeHandle
,
3767 IN EFI_QUESTION_ID QuestionId
,
3768 IN EFI_VARSTORE_ID VarStoreId
,
3769 IN UINT16 VarOffset
,
3770 IN EFI_STRING_ID Prompt
,
3771 IN EFI_STRING_ID Help
,
3772 IN UINT8 QuestionFlags
,
3773 IN UINT8 StringFlags
,
3776 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3779 EFI_IFR_STRING OpCode
;
3782 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
3784 ZeroMem (&OpCode
, sizeof (OpCode
));
3785 OpCode
.Question
.Header
.Prompt
= Prompt
;
3786 OpCode
.Question
.Header
.Help
= Help
;
3787 OpCode
.Question
.QuestionId
= QuestionId
;
3788 OpCode
.Question
.VarStoreId
= VarStoreId
;
3789 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3790 OpCode
.Question
.Flags
= QuestionFlags
;
3791 OpCode
.MinSize
= MinSize
;
3792 OpCode
.MaxSize
= MaxSize
;
3793 OpCode
.Flags
= (UINT8
) (StringFlags
& EFI_IFR_STRING_MULTI_LINE
);
3795 if (DefaultsOpCodeHandle
== NULL
) {
3796 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
));
3799 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3800 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_STRING_OP
, sizeof (OpCode
), 0, 1);
3801 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3802 HiiCreateEndOpCode (OpCodeHandle
);
3803 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3807 Create EFI_IFR_ONE_OF_OP opcode.
3809 If OpCodeHandle is NULL, then ASSERT().
3810 If any reserved bits are set in QuestionFlags, then ASSERT().
3811 If any reserved bits are set in OneOfFlags, then ASSERT().
3813 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3814 @param[in] QuestionId Question ID
3815 @param[in] VarStoreId Storage ID
3816 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3817 for this name/value pair.
3818 @param[in] Prompt String ID for Prompt
3819 @param[in] Help String ID for Help
3820 @param[in] QuestionFlags Flags in Question Header
3821 @param[in] OneOfFlags Flags for oneof opcode
3822 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3823 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3824 is an optional parameter that may be NULL.
3826 @retval NULL There is not enough space left in Buffer to add the opcode.
3827 @retval Other A pointer to the created opcode.
3832 HiiCreateOneOfOpCode (
3833 IN VOID
*OpCodeHandle
,
3834 IN EFI_QUESTION_ID QuestionId
,
3835 IN EFI_VARSTORE_ID VarStoreId
,
3836 IN UINT16 VarOffset
,
3837 IN EFI_STRING_ID Prompt
,
3838 IN EFI_STRING_ID Help
,
3839 IN UINT8 QuestionFlags
,
3840 IN UINT8 OneOfFlags
,
3841 IN VOID
*OptionsOpCodeHandle
,
3842 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3845 EFI_IFR_ONE_OF OpCode
;
3849 ASSERT (OptionsOpCodeHandle
!= NULL
);
3850 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3852 ZeroMem (&OpCode
, sizeof (OpCode
));
3853 OpCode
.Question
.Header
.Prompt
= Prompt
;
3854 OpCode
.Question
.Header
.Help
= Help
;
3855 OpCode
.Question
.QuestionId
= QuestionId
;
3856 OpCode
.Question
.VarStoreId
= VarStoreId
;
3857 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3858 OpCode
.Question
.Flags
= QuestionFlags
;
3859 OpCode
.Flags
= OneOfFlags
;
3861 Length
= OFFSET_OF (EFI_IFR_ONE_OF
, data
);
3862 Length
+= (1 << (OneOfFlags
& EFI_IFR_NUMERIC_SIZE
)) * 3;
3864 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3865 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ONE_OF_OP
, Length
, 0, 1);
3866 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3867 if (DefaultsOpCodeHandle
!= NULL
) {
3868 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3870 HiiCreateEndOpCode (OpCodeHandle
);
3871 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3875 Create EFI_IFR_ORDERED_LIST_OP opcode.
3877 If OpCodeHandle is NULL, then ASSERT().
3878 If any reserved bits are set in QuestionFlags, then ASSERT().
3879 If any reserved bits are set in OrderedListFlags, then ASSERT().
3881 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3882 @param[in] QuestionId Question ID
3883 @param[in] VarStoreId Storage ID
3884 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3885 for this name/value pair.
3886 @param[in] Prompt String ID for Prompt
3887 @param[in] Help String ID for Help
3888 @param[in] QuestionFlags Flags in Question Header
3889 @param[in] OrderedListFlags Flags for ordered list opcode
3890 @param[in] DataType Type for option value
3891 @param[in] MaxContainers Maximum count for options in this ordered list
3892 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3893 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3894 is an optional parameter that may be NULL.
3896 @retval NULL There is not enough space left in Buffer to add the opcode.
3897 @retval Other A pointer to the created opcode.
3902 HiiCreateOrderedListOpCode (
3903 IN VOID
*OpCodeHandle
,
3904 IN EFI_QUESTION_ID QuestionId
,
3905 IN EFI_VARSTORE_ID VarStoreId
,
3906 IN UINT16 VarOffset
,
3907 IN EFI_STRING_ID Prompt
,
3908 IN EFI_STRING_ID Help
,
3909 IN UINT8 QuestionFlags
,
3910 IN UINT8 OrderedListFlags
,
3912 IN UINT8 MaxContainers
,
3913 IN VOID
*OptionsOpCodeHandle
,
3914 IN VOID
*DefaultsOpCodeHandle OPTIONAL
3917 EFI_IFR_ORDERED_LIST OpCode
;
3920 ASSERT (OptionsOpCodeHandle
!= NULL
);
3921 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
| EFI_IFR_FLAG_OPTIONS_ONLY
))) == 0);
3923 ZeroMem (&OpCode
, sizeof (OpCode
));
3924 OpCode
.Question
.Header
.Prompt
= Prompt
;
3925 OpCode
.Question
.Header
.Help
= Help
;
3926 OpCode
.Question
.QuestionId
= QuestionId
;
3927 OpCode
.Question
.VarStoreId
= VarStoreId
;
3928 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
3929 OpCode
.Question
.Flags
= QuestionFlags
;
3930 OpCode
.MaxContainers
= MaxContainers
;
3931 OpCode
.Flags
= OrderedListFlags
;
3933 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
3934 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_ORDERED_LIST_OP
, sizeof (OpCode
), 0, 1);
3935 InternalHiiAppendOpCodes (OpCodeHandle
, OptionsOpCodeHandle
);
3936 if (DefaultsOpCodeHandle
!= NULL
) {
3937 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
3939 HiiCreateEndOpCode (OpCodeHandle
);
3940 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
3944 Create EFI_IFR_TEXT_OP opcode.
3946 If OpCodeHandle is NULL, then ASSERT().
3948 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3949 @param[in] Prompt String ID for Prompt.
3950 @param[in] Help String ID for Help.
3951 @param[in] TextTwo String ID for TextTwo.
3953 @retval NULL There is not enough space left in Buffer to add the opcode.
3954 @retval Other A pointer to the created opcode.
3959 HiiCreateTextOpCode (
3960 IN VOID
*OpCodeHandle
,
3961 IN EFI_STRING_ID Prompt
,
3962 IN EFI_STRING_ID Help
,
3963 IN EFI_STRING_ID TextTwo
3966 EFI_IFR_TEXT OpCode
;
3968 ZeroMem (&OpCode
, sizeof (OpCode
));
3969 OpCode
.Statement
.Prompt
= Prompt
;
3970 OpCode
.Statement
.Help
= Help
;
3971 OpCode
.TextTwo
= TextTwo
;
3973 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TEXT_OP
, sizeof (OpCode
));
3977 Create EFI_IFR_DATE_OP opcode.
3979 If OpCodeHandle is NULL, then ASSERT().
3980 If any reserved bits are set in QuestionFlags, then ASSERT().
3981 If any reserved bits are set in DateFlags, then ASSERT().
3983 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3984 @param[in] QuestionId Question ID
3985 @param[in] VarStoreId Storage ID, optional. If DateFlags is not
3986 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3987 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3988 for this name/value pair, optional. If DateFlags is not
3989 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3990 @param[in] Prompt String ID for Prompt
3991 @param[in] Help String ID for Help
3992 @param[in] QuestionFlags Flags in Question Header
3993 @param[in] DateFlags Flags for date opcode
3994 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3995 is an optional parameter that may be NULL.
3997 @retval NULL There is not enough space left in Buffer to add the opcode.
3998 @retval Other A pointer to the created opcode.
4003 HiiCreateDateOpCode (
4004 IN VOID
*OpCodeHandle
,
4005 IN EFI_QUESTION_ID QuestionId
,
4006 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
4007 IN UINT16 VarOffset
, OPTIONAL
4008 IN EFI_STRING_ID Prompt
,
4009 IN EFI_STRING_ID Help
,
4010 IN UINT8 QuestionFlags
,
4012 IN VOID
*DefaultsOpCodeHandle OPTIONAL
4015 EFI_IFR_DATE OpCode
;
4018 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
4019 ASSERT ((DateFlags
& (~(EFI_QF_DATE_YEAR_SUPPRESS
| EFI_QF_DATE_MONTH_SUPPRESS
| EFI_QF_DATE_DAY_SUPPRESS
| EFI_QF_DATE_STORAGE
))) == 0);
4021 ZeroMem (&OpCode
, sizeof (OpCode
));
4022 OpCode
.Question
.Header
.Prompt
= Prompt
;
4023 OpCode
.Question
.Header
.Help
= Help
;
4024 OpCode
.Question
.QuestionId
= QuestionId
;
4025 OpCode
.Question
.VarStoreId
= VarStoreId
;
4026 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
4027 OpCode
.Question
.Flags
= QuestionFlags
;
4028 OpCode
.Flags
= DateFlags
;
4030 if (DefaultsOpCodeHandle
== NULL
) {
4031 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
));
4034 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
4035 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_DATE_OP
, sizeof (OpCode
), 0, 1);
4036 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
4037 HiiCreateEndOpCode (OpCodeHandle
);
4038 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
4042 Create EFI_IFR_TIME_OP opcode.
4044 If OpCodeHandle is NULL, then ASSERT().
4045 If any reserved bits are set in QuestionFlags, then ASSERT().
4046 If any reserved bits are set in TimeFlags, then ASSERT().
4048 @param[in] OpCodeHandle Handle to the buffer of opcodes.
4049 @param[in] QuestionId Question ID
4050 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not
4051 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
4052 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
4053 for this name/value pair, optional. If TimeFlags is not
4054 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
4055 @param[in] Prompt String ID for Prompt
4056 @param[in] Help String ID for Help
4057 @param[in] QuestionFlags Flags in Question Header
4058 @param[in] TimeFlags Flags for time opcode
4059 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
4060 is an optional parameter that may be NULL.
4062 @retval NULL There is not enough space left in Buffer to add the opcode.
4063 @retval Other A pointer to the created opcode.
4068 HiiCreateTimeOpCode (
4069 IN VOID
*OpCodeHandle
,
4070 IN EFI_QUESTION_ID QuestionId
,
4071 IN EFI_VARSTORE_ID VarStoreId
, OPTIONAL
4072 IN UINT16 VarOffset
, OPTIONAL
4073 IN EFI_STRING_ID Prompt
,
4074 IN EFI_STRING_ID Help
,
4075 IN UINT8 QuestionFlags
,
4077 IN VOID
*DefaultsOpCodeHandle OPTIONAL
4080 EFI_IFR_TIME OpCode
;
4083 ASSERT ((QuestionFlags
& (~(EFI_IFR_FLAG_READ_ONLY
| EFI_IFR_FLAG_CALLBACK
| EFI_IFR_FLAG_RESET_REQUIRED
))) == 0);
4084 ASSERT ((TimeFlags
& (~(QF_TIME_HOUR_SUPPRESS
| QF_TIME_MINUTE_SUPPRESS
| QF_TIME_SECOND_SUPPRESS
| QF_TIME_STORAGE
))) == 0);
4086 ZeroMem (&OpCode
, sizeof (OpCode
));
4087 OpCode
.Question
.Header
.Prompt
= Prompt
;
4088 OpCode
.Question
.Header
.Help
= Help
;
4089 OpCode
.Question
.QuestionId
= QuestionId
;
4090 OpCode
.Question
.VarStoreId
= VarStoreId
;
4091 OpCode
.Question
.VarStoreInfo
.VarOffset
= VarOffset
;
4092 OpCode
.Question
.Flags
= QuestionFlags
;
4093 OpCode
.Flags
= TimeFlags
;
4095 if (DefaultsOpCodeHandle
== NULL
) {
4096 return InternalHiiCreateOpCode (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
));
4099 Position
= InternalHiiOpCodeHandlePosition (OpCodeHandle
);
4100 InternalHiiCreateOpCodeExtended (OpCodeHandle
, &OpCode
, EFI_IFR_TIME_OP
, sizeof (OpCode
), 0, 1);
4101 InternalHiiAppendOpCodes (OpCodeHandle
, DefaultsOpCodeHandle
);
4102 HiiCreateEndOpCode (OpCodeHandle
);
4103 return InternalHiiOpCodeHandleBuffer (OpCodeHandle
) + Position
;
4107 This is the internal worker function to update the data in
4108 a form specified by FormSetGuid, FormId and Label.
4110 @param[in] FormSetGuid The optional Formset GUID.
4111 @param[in] FormId The Form ID.
4112 @param[in] Package The package header.
4113 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR
4114 opcodes to be inserted or replaced in the form.
4115 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode
4116 that marks the end of a replace operation in the form.
4117 @param[out] TempPackage The resultant package.
4119 @retval EFI_SUCCESS The function completes successfully.
4120 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.
4125 InternalHiiUpdateFormPackageData (
4126 IN EFI_GUID
*FormSetGuid
, OPTIONAL
4127 IN EFI_FORM_ID FormId
,
4128 IN EFI_HII_PACKAGE_HEADER
*Package
,
4129 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
,
4130 IN HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
, OPTIONAL
4131 OUT EFI_HII_PACKAGE_HEADER
*TempPackage
4136 EFI_HII_PACKAGE_HEADER PackageHeader
;
4138 EFI_IFR_OP_HEADER
*IfrOpHdr
;
4139 EFI_IFR_OP_HEADER
*UpdateIfrOpHdr
;
4143 UINTN UpdatePackageLength
;
4145 CopyMem (TempPackage
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4146 UpdatePackageLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
4147 BufferPos
= (UINT8
*) (TempPackage
+ 1);
4149 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4150 IfrOpHdr
= (EFI_IFR_OP_HEADER
*)((UINT8
*) Package
+ sizeof (EFI_HII_PACKAGE_HEADER
));
4151 Offset
= sizeof (EFI_HII_PACKAGE_HEADER
);
4152 GetFormSet
= (BOOLEAN
) ((FormSetGuid
== NULL
) ? TRUE
: FALSE
);
4156 while (Offset
< PackageHeader
.Length
) {
4157 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
4158 BufferPos
+= IfrOpHdr
->Length
;
4159 UpdatePackageLength
+= IfrOpHdr
->Length
;
4162 // Find the matched FormSet and Form
4164 if ((IfrOpHdr
->OpCode
== EFI_IFR_FORM_SET_OP
) && (FormSetGuid
!= NULL
)) {
4165 if (CompareGuid((GUID
*)(VOID
*)&((EFI_IFR_FORM_SET
*) IfrOpHdr
)->Guid
, FormSetGuid
)) {
4170 } else if (IfrOpHdr
->OpCode
== EFI_IFR_FORM_OP
|| IfrOpHdr
->OpCode
== EFI_IFR_FORM_MAP_OP
) {
4171 if (CompareMem (&((EFI_IFR_FORM
*) IfrOpHdr
)->FormId
, &FormId
, sizeof (EFI_FORM_ID
)) == 0) {
4179 // The matched Form is found, and Update data in this form
4181 if (GetFormSet
&& GetForm
) {
4182 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
;
4183 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
4184 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
4186 // Remove the original data when End OpCode buffer exist.
4188 if (OpCodeBufferEnd
!= NULL
) {
4189 Offset
+= IfrOpHdr
->Length
;
4190 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
4191 UpdateIfrOpHdr
= (EFI_IFR_OP_HEADER
*) OpCodeBufferEnd
->Buffer
;
4192 while (Offset
< PackageHeader
.Length
) {
4194 // Search the matched end opcode
4196 if ((UpdateIfrOpHdr
->Length
== IfrOpHdr
->Length
) && \
4197 (CompareMem (IfrOpHdr
, UpdateIfrOpHdr
, UpdateIfrOpHdr
->Length
) == 0)) {
4201 // Go to the next Op-Code
4203 Offset
+= IfrOpHdr
->Length
;
4204 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((UINT8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
4207 if (Offset
>= PackageHeader
.Length
) {
4209 // The end opcode is not found.
4211 return EFI_NOT_FOUND
;
4216 // Insert the updated data
4218 AddSize
= ((EFI_IFR_OP_HEADER
*) OpCodeBufferStart
->Buffer
)->Length
;
4219 CopyMem (BufferPos
, OpCodeBufferStart
->Buffer
+ AddSize
, OpCodeBufferStart
->Position
- AddSize
);
4220 BufferPos
+= OpCodeBufferStart
->Position
- AddSize
;
4221 UpdatePackageLength
+= OpCodeBufferStart
->Position
- AddSize
;
4223 if (OpCodeBufferEnd
!= NULL
) {
4225 // Add the end opcode
4227 CopyMem (BufferPos
, IfrOpHdr
, IfrOpHdr
->Length
);
4228 BufferPos
+= IfrOpHdr
->Length
;
4229 UpdatePackageLength
+= IfrOpHdr
->Length
;
4233 // Copy the left package data.
4235 Offset
+= IfrOpHdr
->Length
;
4236 CopyMem (BufferPos
, (UINT8
*) Package
+ Offset
, PackageHeader
.Length
- Offset
);
4237 UpdatePackageLength
+= PackageHeader
.Length
- Offset
;
4248 // Go to the next Op-Code
4250 Offset
+= IfrOpHdr
->Length
;
4251 IfrOpHdr
= (EFI_IFR_OP_HEADER
*) ((CHAR8
*) (IfrOpHdr
) + IfrOpHdr
->Length
);
4256 // The updated opcode buffer is not found.
4258 return EFI_NOT_FOUND
;
4261 // Update the package length.
4263 PackageHeader
.Length
= (UINT32
) UpdatePackageLength
;
4264 CopyMem (TempPackage
, &PackageHeader
, sizeof (EFI_HII_PACKAGE_HEADER
));
4270 This function updates a form that has previously been registered with the HII
4271 Database. This function will perform at most one update operation.
4273 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
4274 comparisons of IFR opcodes are performed from the beginning of the form being
4275 updated until an IFR opcode is found that exactly matches the first IFR opcode
4276 specified by StartOpCodeHandle. The following rules are used to determine if
4277 an insert, replace, or delete operation is performed.
4279 1) If no matches are found, then NULL is returned.
4280 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
4281 from StartOpCodeHandle except the first opcode are inserted immediately after
4282 the matching IFR opcode in the form to be updated.
4283 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
4284 from the matching IFR opcode until an IFR opcode exactly matches the first
4285 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
4286 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
4287 is found, then all of the IFR opcodes between the start match and the end
4288 match are deleted from the form being updated and all of the IFR opcodes
4289 from StartOpCodeHandle except the first opcode are inserted immediately after
4290 the matching start IFR opcode. If StartOpCcodeHandle only contains one
4291 IFR instruction, then the result of this operation will delete all of the IFR
4292 opcodes between the start end matches.
4294 If HiiHandle is NULL, then ASSERT().
4295 If StartOpCodeHandle is NULL, then ASSERT().
4297 @param[in] HiiHandle The HII Handle of the form to update.
4298 @param[in] FormSetGuid The Formset GUID of the form to update. This
4299 is an optional parameter that may be NULL.
4300 If it is NULL, all FormSet will be updated.
4301 @param[in] FormId The ID of the form to update.
4302 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
4303 opcodes to be inserted or replaced in the form.
4304 The first IFR instruction in StartOpCodeHandle
4305 is used to find matching IFR opcode in the
4307 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
4308 that marks the end of a replace operation in
4309 the form. This is an optional parameter that
4310 may be NULL. If it is NULL, then an the IFR
4311 opcodes specified by StartOpCodeHandle are
4312 inserted into the form.
4314 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
4315 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
4316 1) The form specified by HiiHandle, FormSetGuid,
4317 and FormId could not be found in the HII Database.
4318 2) No IFR opcodes in the target form match the first
4319 IFR opcode in StartOpCodeHandle.
4320 3) EndOpCOde is not NULL, and no IFR opcodes in the
4321 target form following a matching start opcode match
4322 the first IFR opcode in EndOpCodeHandle.
4323 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
4329 IN EFI_HII_HANDLE HiiHandle
,
4330 IN EFI_GUID
*FormSetGuid
, OPTIONAL
4331 IN EFI_FORM_ID FormId
,
4332 IN VOID
*StartOpCodeHandle
,
4333 IN VOID
*EndOpCodeHandle OPTIONAL
4337 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
4338 UINT32 PackageListLength
;
4340 EFI_HII_PACKAGE_LIST_HEADER
*UpdatePackageList
;
4342 UINT8
*UpdateBufferPos
;
4343 EFI_HII_PACKAGE_HEADER
*Package
;
4344 EFI_HII_PACKAGE_HEADER
*TempPackage
;
4345 EFI_HII_PACKAGE_HEADER PackageHeader
;
4347 HII_LIB_OPCODE_BUFFER
*OpCodeBufferStart
;
4348 HII_LIB_OPCODE_BUFFER
*OpCodeBufferEnd
;
4351 // Input update data can't be NULL.
4353 ASSERT (HiiHandle
!= NULL
);
4354 ASSERT (StartOpCodeHandle
!= NULL
);
4355 UpdatePackageList
= NULL
;
4357 HiiPackageList
= NULL
;
4360 // Retrieve buffer data from Opcode Handle
4362 OpCodeBufferStart
= (HII_LIB_OPCODE_BUFFER
*) StartOpCodeHandle
;
4363 OpCodeBufferEnd
= (HII_LIB_OPCODE_BUFFER
*) EndOpCodeHandle
;
4366 // Get the original package list
4369 HiiPackageList
= NULL
;
4370 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
4372 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
4374 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
4378 HiiPackageList
= AllocatePool (BufferSize
);
4379 if (HiiPackageList
== NULL
) {
4380 Status
= EFI_OUT_OF_RESOURCES
;
4384 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, HiiHandle
, &BufferSize
, HiiPackageList
);
4385 if (EFI_ERROR (Status
)) {
4390 // Calculate and allocate space for retrieval of IFR data
4392 BufferSize
+= OpCodeBufferStart
->Position
;
4393 UpdatePackageList
= AllocateZeroPool (BufferSize
);
4394 if (UpdatePackageList
== NULL
) {
4395 Status
= EFI_OUT_OF_RESOURCES
;
4400 // Allocate temp buffer to store the temp updated package buffer
4402 TempPackage
= AllocateZeroPool (BufferSize
);
4403 if (TempPackage
== NULL
) {
4404 Status
= EFI_OUT_OF_RESOURCES
;
4408 UpdateBufferPos
= (UINT8
*) UpdatePackageList
;
4411 // Copy the package list header
4413 CopyMem (UpdateBufferPos
, HiiPackageList
, sizeof (EFI_HII_PACKAGE_LIST_HEADER
));
4414 UpdateBufferPos
+= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4417 // Go through each package to find the matched package and update one by one
4420 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
4421 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
4422 while (Offset
< PackageListLength
) {
4423 Package
= (EFI_HII_PACKAGE_HEADER
*) (((UINT8
*) HiiPackageList
) + Offset
);
4424 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4425 Offset
+= Package
->Length
;
4427 if (Package
->Type
== EFI_HII_PACKAGE_FORMS
) {
4429 // Check this package is the matched package.
4431 Status
= InternalHiiUpdateFormPackageData (FormSetGuid
, FormId
, Package
, OpCodeBufferStart
, OpCodeBufferEnd
, TempPackage
);
4433 // The matched package is found. Its package buffer will be updated by the input new data.
4435 if (!EFI_ERROR(Status
)) {
4441 // Add updated package buffer
4443 Package
= TempPackage
;
4448 // Add pacakge buffer
4450 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
4451 CopyMem (UpdateBufferPos
, Package
, PackageHeader
.Length
);
4452 UpdateBufferPos
+= PackageHeader
.Length
;
4457 // Update package list length
4459 BufferSize
= UpdateBufferPos
- (UINT8
*) UpdatePackageList
;
4460 WriteUnaligned32 (&UpdatePackageList
->PackageLength
, (UINT32
) BufferSize
);
4463 // Update Package to show form
4465 Status
= gHiiDatabase
->UpdatePackageList (gHiiDatabase
, HiiHandle
, UpdatePackageList
);
4468 // Not matched form is found and updated.
4470 Status
= EFI_NOT_FOUND
;
4474 if (HiiPackageList
!= NULL
) {
4475 FreePool (HiiPackageList
);
4478 if (UpdatePackageList
!= NULL
) {
4479 FreePool (UpdatePackageList
);
4482 if (TempPackage
!= NULL
) {
4483 FreePool (TempPackage
);