]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
MdeModulePkg: Replace [Ascii|Unicode]ValueToString
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
1 /** @file
2 HII Library implementation that uses DXE protocols and services.
3
4 Copyright (c) 2006 - 2017, 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
9
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.
12
13 **/
14
15 #include "InternalHiiLib.h"
16
17 #define GUID_CONFIG_STRING_TYPE 0x00
18 #define NAME_CONFIG_STRING_TYPE 0x01
19 #define PATH_CONFIG_STRING_TYPE 0x02
20
21 #define ACTION_SET_DEFAUTL_VALUE 0x01
22 #define ACTION_VALIDATE_SETTING 0x02
23
24 #define HII_LIB_DEFAULT_VARSTORE_SIZE 0x200
25
26 typedef struct {
27 LIST_ENTRY Entry; // Link to Block array
28 UINT16 Offset;
29 UINT16 Width;
30 UINT8 OpCode;
31 UINT8 Scope;
32 } IFR_BLOCK_DATA;
33
34 typedef struct {
35 EFI_VARSTORE_ID VarStoreId;
36 UINT16 Size;
37 } IFR_VARSTORAGE_DATA;
38
39 //
40 // <ConfigHdr> Template
41 //
42 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";
43
44 EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL;
45
46 //
47 // Template used to mark the end of a list of packages
48 //
49 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = {
50 sizeof (EFI_HII_PACKAGE_HEADER),
51 EFI_HII_PACKAGE_END
52 };
53
54 /**
55 Extract Hii package list GUID for given HII handle.
56
57 If HiiHandle could not be found in the HII database, then ASSERT.
58 If Guid is NULL, then ASSERT.
59
60 @param Handle Hii handle
61 @param Guid Package list GUID
62
63 @retval EFI_SUCCESS Successfully extract GUID from Hii database.
64
65 **/
66 EFI_STATUS
67 EFIAPI
68 InternalHiiExtractGuidFromHiiHandle (
69 IN EFI_HII_HANDLE Handle,
70 OUT EFI_GUID *Guid
71 )
72 {
73 EFI_STATUS Status;
74 UINTN BufferSize;
75 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
76
77 ASSERT (Guid != NULL);
78 ASSERT (Handle != NULL);
79
80 //
81 // Get HII PackageList
82 //
83 BufferSize = 0;
84 HiiPackageList = NULL;
85
86 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
87 ASSERT (Status != EFI_NOT_FOUND);
88
89 if (Status == EFI_BUFFER_TOO_SMALL) {
90 HiiPackageList = AllocatePool (BufferSize);
91 ASSERT (HiiPackageList != NULL);
92
93 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
94 }
95 if (EFI_ERROR (Status)) {
96 FreePool (HiiPackageList);
97 return Status;
98 }
99
100 //
101 // Extract GUID
102 //
103 CopyGuid (Guid, &HiiPackageList->PackageListGuid);
104
105 FreePool (HiiPackageList);
106
107 return EFI_SUCCESS;
108 }
109
110 /**
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.
117
118 The variable arguments are pointers which point to package header that defined
119 by UEFI VFR compiler and StringGather tool.
120
121 #pragma pack (push, 1)
122 typedef struct {
123 UINT32 BinaryLength;
124 EFI_HII_PACKAGE_HEADER PackageHeader;
125 } EDKII_AUTOGEN_PACKAGES_HEADER;
126 #pragma pack (pop)
127
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.
135
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.
142
143 **/
144 EFI_HII_HANDLE
145 EFIAPI
146 HiiAddPackages (
147 IN CONST EFI_GUID *PackageListGuid,
148 IN EFI_HANDLE DeviceHandle OPTIONAL,
149 ...
150 )
151 {
152 EFI_STATUS Status;
153 VA_LIST Args;
154 UINT32 *Package;
155 EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
156 EFI_HII_HANDLE HiiHandle;
157 UINT32 Length;
158 UINT8 *Data;
159
160 ASSERT (PackageListGuid != NULL);
161
162 //
163 // Calculate the length of all the packages in the variable argument list
164 //
165 for (Length = 0, VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {
166 Length += (ReadUnaligned32 (Package) - sizeof (UINT32));
167 }
168 VA_END (Args);
169
170 //
171 // If there are no packages in the variable argument list or all the packages
172 // are empty, then return a NULL HII Handle
173 //
174 if (Length == 0) {
175 return NULL;
176 }
177
178 //
179 // Add the length of the Package List Header and the terminating Package Header
180 //
181 Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER);
182
183 //
184 // Allocate the storage for the entire Package List
185 //
186 PackageListHeader = AllocateZeroPool (Length);
187
188 //
189 // If the Package List can not be allocated, then return a NULL HII Handle
190 //
191 if (PackageListHeader == NULL) {
192 return NULL;
193 }
194
195 //
196 // Fill in the GUID and Length of the Package List Header
197 //
198 CopyGuid (&PackageListHeader->PackageListGuid, PackageListGuid);
199 PackageListHeader->PackageLength = Length;
200
201 //
202 // Initialize a pointer to the beginning if the Package List data
203 //
204 Data = (UINT8 *)(PackageListHeader + 1);
205
206 //
207 // Copy the data from each package in the variable argument list
208 //
209 for (VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {
210 Length = ReadUnaligned32 (Package) - sizeof (UINT32);
211 CopyMem (Data, Package + 1, Length);
212 Data += Length;
213 }
214 VA_END (Args);
215
216 //
217 // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list
218 //
219 CopyMem (Data, &mEndOfPakageList, sizeof (mEndOfPakageList));
220
221 //
222 // Register the package list with the HII Database
223 //
224 Status = gHiiDatabase->NewPackageList (
225 gHiiDatabase,
226 PackageListHeader,
227 DeviceHandle,
228 &HiiHandle
229 );
230 if (EFI_ERROR (Status)) {
231 HiiHandle = NULL;
232 }
233
234 //
235 // Free the allocated package list
236 //
237 FreePool (PackageListHeader);
238
239 //
240 // Return the new HII Handle
241 //
242 return HiiHandle;
243 }
244
245 /**
246 Removes a package list from the HII database.
247
248 If HiiHandle is NULL, then ASSERT.
249 If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.
250
251 @param[in] HiiHandle The handle that was previously registered in the HII database
252
253 **/
254 VOID
255 EFIAPI
256 HiiRemovePackages (
257 IN EFI_HII_HANDLE HiiHandle
258 )
259 {
260 EFI_STATUS Status;
261
262 ASSERT (HiiHandle != NULL);
263 Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
264 ASSERT_EFI_ERROR (Status);
265 }
266
267
268 /**
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().
274
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.
282
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
286
287 **/
288 EFI_HII_HANDLE *
289 EFIAPI
290 HiiGetHiiHandles (
291 IN CONST EFI_GUID *PackageListGuid OPTIONAL
292 )
293 {
294 EFI_STATUS Status;
295 UINTN HandleBufferLength;
296 EFI_HII_HANDLE TempHiiHandleBuffer;
297 EFI_HII_HANDLE *HiiHandleBuffer;
298 EFI_GUID Guid;
299 UINTN Index1;
300 UINTN Index2;
301
302 //
303 // Retrieve the size required for the buffer of all HII handles.
304 //
305 HandleBufferLength = 0;
306 Status = gHiiDatabase->ListPackageLists (
307 gHiiDatabase,
308 EFI_HII_PACKAGE_TYPE_ALL,
309 NULL,
310 &HandleBufferLength,
311 &TempHiiHandleBuffer
312 );
313
314 //
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.
319 //
320 if (Status != EFI_BUFFER_TOO_SMALL) {
321 //
322 // Return NULL if the size can not be retrieved, or if there are no HII
323 // handles in the HII Database
324 //
325 return NULL;
326 }
327
328 //
329 // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator
330 //
331 HiiHandleBuffer = AllocateZeroPool (HandleBufferLength + sizeof (EFI_HII_HANDLE));
332 if (HiiHandleBuffer == NULL) {
333 //
334 // Return NULL if allocation fails.
335 //
336 return NULL;
337 }
338
339 //
340 // Retrieve the array of HII Handles in the HII Database
341 //
342 Status = gHiiDatabase->ListPackageLists (
343 gHiiDatabase,
344 EFI_HII_PACKAGE_TYPE_ALL,
345 NULL,
346 &HandleBufferLength,
347 HiiHandleBuffer
348 );
349 if (EFI_ERROR (Status)) {
350 //
351 // Free the buffer and return NULL if the HII handles can not be retrieved.
352 //
353 FreePool (HiiHandleBuffer);
354 return NULL;
355 }
356
357 if (PackageListGuid == NULL) {
358 //
359 // Return the NULL terminated array of HII handles in the HII Database
360 //
361 return HiiHandleBuffer;
362 } else {
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];
368 }
369 }
370 if (Index2 > 0) {
371 HiiHandleBuffer[Index2] = NULL;
372 return HiiHandleBuffer;
373 } else {
374 FreePool (HiiHandleBuffer);
375 return NULL;
376 }
377 }
378 }
379
380 /**
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().
384
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.
388
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.
393
394 **/
395 EFI_STATUS
396 EFIAPI
397 HiiGetFormSetFromHiiHandle(
398 IN EFI_HII_HANDLE Handle,
399 OUT EFI_IFR_FORM_SET **Buffer,
400 OUT UINTN *BufferSize
401 )
402 {
403 EFI_STATUS Status;
404 UINTN PackageListSize;
405 UINTN TempSize;
406 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
407 UINT8 *Package;
408 UINT8 *OpCodeData;
409 UINT8 *FormSetBuffer;
410 UINT8 *TempBuffer;
411 UINT32 Offset;
412 UINT32 Offset2;
413 UINT32 PackageListLength;
414 EFI_HII_PACKAGE_HEADER PackageHeader;
415
416 TempSize = 0;
417 FormSetBuffer = NULL;
418 TempBuffer = NULL;
419
420 //
421 // Get HII PackageList
422 //
423 PackageListSize = 0;
424 HiiPackageList = NULL;
425 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &PackageListSize, HiiPackageList);
426 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
427 return Status;
428 }
429
430 HiiPackageList = AllocatePool (PackageListSize);
431 if (HiiPackageList == NULL) {
432 return EFI_OUT_OF_RESOURCES;
433 }
434
435 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &PackageListSize, HiiPackageList);
436 ASSERT_EFI_ERROR (Status);
437
438 //
439 // Get Form package from this HII package List
440 //
441 Status = EFI_NOT_FOUND;
442 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
443 PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);
444
445 while (Offset < PackageListLength) {
446 Package = ((UINT8 *) HiiPackageList) + Offset;
447 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
448 Offset += PackageHeader.Length;
449
450 if (PackageHeader.Type != EFI_HII_PACKAGE_FORMS) {
451 continue;
452 }
453
454 //
455 // Search FormSet Opcode in this Form Package
456 //
457 Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);
458 while (Offset2 < PackageHeader.Length) {
459 OpCodeData = Package + Offset2;
460 Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
461
462 if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode != EFI_IFR_FORM_SET_OP) {
463 continue;
464 }
465
466 if (FormSetBuffer != NULL){
467 TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, FormSetBuffer);
468 FreePool(FormSetBuffer);
469 FormSetBuffer = NULL;
470 if (TempBuffer == NULL) {
471 Status = EFI_OUT_OF_RESOURCES;
472 goto Done;
473 }
474 CopyMem (TempBuffer + TempSize, OpCodeData, ((EFI_IFR_OP_HEADER *) OpCodeData)->Length);
475 } else {
476 TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, OpCodeData);
477 if (TempBuffer == NULL) {
478 Status = EFI_OUT_OF_RESOURCES;
479 goto Done;
480 }
481 }
482 TempSize += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
483 FormSetBuffer = TempBuffer;
484
485 Status = EFI_SUCCESS;
486 //
487 //One form package has one formset, exit current form package to search other form package in the packagelist.
488 //
489 break;
490 }
491 }
492 Done:
493 FreePool (HiiPackageList);
494
495 *BufferSize = TempSize;
496 *Buffer = (EFI_IFR_FORM_SET *)FormSetBuffer;
497
498 return Status;
499 }
500
501 /**
502 Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for
503 hex digits that appear between a '=' and a '&' in a config string.
504
505 If ConfigString is NULL, then ASSERT().
506
507 @param[in] ConfigString Pointer to a Null-terminated Unicode string.
508
509 @return Pointer to the Null-terminated Unicode result string.
510
511 **/
512 EFI_STRING
513 EFIAPI
514 InternalHiiLowerConfigString (
515 IN EFI_STRING ConfigString
516 )
517 {
518 EFI_STRING String;
519 BOOLEAN Lower;
520
521 ASSERT (ConfigString != NULL);
522
523 //
524 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
525 //
526 for (String = ConfigString, Lower = FALSE; *String != L'\0'; String++) {
527 if (*String == L'=') {
528 Lower = TRUE;
529 } else if (*String == L'&') {
530 Lower = FALSE;
531 } else if (Lower && *String >= L'A' && *String <= L'F') {
532 *String = (CHAR16) (*String - L'A' + L'a');
533 }
534 }
535
536 return ConfigString;
537 }
538
539 /**
540 Uses the BlockToConfig() service of the Config Routing Protocol to
541 convert <ConfigRequest> and a buffer to a <ConfigResp>
542
543 If ConfigRequest is NULL, then ASSERT().
544 If Block is NULL, then ASSERT().
545
546 @param[in] ConfigRequest Pointer to a Null-terminated Unicode string.
547 @param[in] Block Pointer to a block of data.
548 @param[in] BlockSize The zie, in bytes, of Block.
549
550 @retval NULL The <ConfigResp> string could not be generated.
551 @retval Other Pointer to the Null-terminated Unicode <ConfigResp> string.
552
553 **/
554 EFI_STRING
555 EFIAPI
556 InternalHiiBlockToConfig (
557 IN CONST EFI_STRING ConfigRequest,
558 IN CONST UINT8 *Block,
559 IN UINTN BlockSize
560 )
561 {
562 EFI_STATUS Status;
563 EFI_STRING ConfigResp;
564 CHAR16 *Progress;
565
566 ASSERT (ConfigRequest != NULL);
567 ASSERT (Block != NULL);
568
569 //
570 // Convert <ConfigRequest> to <ConfigResp>
571 //
572 Status = gHiiConfigRouting->BlockToConfig (
573 gHiiConfigRouting,
574 ConfigRequest,
575 Block,
576 BlockSize,
577 &ConfigResp,
578 &Progress
579 );
580 if (EFI_ERROR (Status)) {
581 return NULL;
582 }
583 return ConfigResp;
584 }
585
586 /**
587 Uses the BrowserCallback() service of the Form Browser Protocol to retrieve
588 or set uncommitted data. If sata i being retrieved, then the buffer is
589 allocated using AllocatePool(). The caller is then responsible for freeing
590 the buffer using FreePool().
591
592 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
593 parameter that may be NULL.
594 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
595 is an optional parameter that may be NULL.
596 @param[in] SetResultsData If not NULL, then this parameter specified the buffer
597 of uncommited data to set. If this parameter is NULL,
598 then the caller is requesting to get the uncommited data
599 from the Form Browser.
600
601 @retval NULL The uncommitted data could not be retrieved.
602 @retval Other A pointer to a buffer containing the uncommitted data.
603
604 **/
605 EFI_STRING
606 EFIAPI
607 InternalHiiBrowserCallback (
608 IN CONST EFI_GUID *VariableGuid, OPTIONAL
609 IN CONST CHAR16 *VariableName, OPTIONAL
610 IN CONST EFI_STRING SetResultsData OPTIONAL
611 )
612 {
613 EFI_STATUS Status;
614 UINTN ResultsDataSize;
615 EFI_STRING ResultsData;
616 CHAR16 TempResultsData;
617
618 //
619 // Locate protocols
620 //
621 if (mUefiFormBrowser2 == NULL) {
622 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mUefiFormBrowser2);
623 if (EFI_ERROR (Status) || mUefiFormBrowser2 == NULL) {
624 return NULL;
625 }
626 }
627
628 ResultsDataSize = 0;
629
630 if (SetResultsData != NULL) {
631 //
632 // Request to to set data in the uncommitted browser state information
633 //
634 ResultsData = SetResultsData;
635 } else {
636 //
637 // Retrieve the length of the buffer required ResultsData from the Browser Callback
638 //
639 Status = mUefiFormBrowser2->BrowserCallback (
640 mUefiFormBrowser2,
641 &ResultsDataSize,
642 &TempResultsData,
643 TRUE,
644 VariableGuid,
645 VariableName
646 );
647
648 if (!EFI_ERROR (Status)) {
649 //
650 // No Resluts Data, only allocate one char for '\0'
651 //
652 ResultsData = AllocateZeroPool (sizeof (CHAR16));
653 return ResultsData;
654 }
655
656 if (Status != EFI_BUFFER_TOO_SMALL) {
657 return NULL;
658 }
659
660 //
661 // Allocate the ResultsData buffer
662 //
663 ResultsData = AllocateZeroPool (ResultsDataSize);
664 if (ResultsData == NULL) {
665 return NULL;
666 }
667 }
668
669 //
670 // Retrieve or set the ResultsData from the Browser Callback
671 //
672 Status = mUefiFormBrowser2->BrowserCallback (
673 mUefiFormBrowser2,
674 &ResultsDataSize,
675 ResultsData,
676 (BOOLEAN)(SetResultsData == NULL),
677 VariableGuid,
678 VariableName
679 );
680 if (EFI_ERROR (Status)) {
681 return NULL;
682 }
683
684 return ResultsData;
685 }
686
687 /**
688 Allocates and returns a Null-terminated Unicode <ConfigHdr> string using routing
689 information that includes a GUID, an optional Unicode string name, and a device
690 path. The string returned is allocated with AllocatePool(). The caller is
691 responsible for freeing the allocated string with FreePool().
692
693 The format of a <ConfigHdr> is as follows:
694
695 GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize<Null>
696
697 @param[in] Guid Pointer to an EFI_GUID that is the routing information
698 GUID. Each of the 16 bytes in Guid is converted to
699 a 2 Unicode character hexadecimal string. This is
700 an optional parameter that may be NULL.
701 @param[in] Name Pointer to a Null-terminated Unicode string that is
702 the routing information NAME. This is an optional
703 parameter that may be NULL. Each 16-bit Unicode
704 character in Name is converted to a 4 character Unicode
705 hexadecimal string.
706 @param[in] DriverHandle The driver handle which supports a Device Path Protocol
707 that is the routing information PATH. Each byte of
708 the Device Path associated with DriverHandle is converted
709 to a 2 Unicode character hexadecimal string.
710
711 @retval NULL DriverHandle does not support the Device Path Protocol.
712 @retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string
713
714 **/
715 EFI_STRING
716 EFIAPI
717 HiiConstructConfigHdr (
718 IN CONST EFI_GUID *Guid, OPTIONAL
719 IN CONST CHAR16 *Name, OPTIONAL
720 IN EFI_HANDLE DriverHandle
721 )
722 {
723 UINTN NameLength;
724 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
725 UINTN DevicePathSize;
726 CHAR16 *String;
727 CHAR16 *ReturnString;
728 UINTN Index;
729 UINT8 *Buffer;
730 UINTN MaxLen;
731
732 //
733 // Compute the length of Name in Unicode characters.
734 // If Name is NULL, then the length is 0.
735 //
736 NameLength = 0;
737 if (Name != NULL) {
738 NameLength = StrLen (Name);
739 }
740
741 DevicePath = NULL;
742 DevicePathSize = 0;
743 //
744 // Retrieve DevicePath Protocol associated with DriverHandle
745 //
746 if (DriverHandle != NULL) {
747 DevicePath = DevicePathFromHandle (DriverHandle);
748 if (DevicePath == NULL) {
749 return NULL;
750 }
751 //
752 // Compute the size of the device path in bytes
753 //
754 DevicePathSize = GetDevicePathSize (DevicePath);
755 }
756
757 //
758 // GUID=<HexCh>32&NAME=<Char>NameLength&PATH=<HexChar>DevicePathSize <Null>
759 // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 |
760 //
761 MaxLen = 5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1;
762 String = AllocateZeroPool (MaxLen * sizeof (CHAR16));
763 if (String == NULL) {
764 return NULL;
765 }
766
767 //
768 // Start with L"GUID="
769 //
770 StrCpyS (String, MaxLen, L"GUID=");
771 ReturnString = String;
772 String += StrLen (String);
773
774 if (Guid != NULL) {
775 //
776 // Append Guid converted to <HexCh>32
777 //
778 for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {
779 UnicodeValueToStringS (
780 String,
781 MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),
782 PREFIX_ZERO | RADIX_HEX,
783 *(Buffer++),
784 2
785 );
786 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));
787 }
788 }
789
790 //
791 // Append L"&NAME="
792 //
793 StrCatS (ReturnString, MaxLen, L"&NAME=");
794 String += StrLen (String);
795
796 if (Name != NULL) {
797 //
798 // Append Name converted to <Char>NameLength
799 //
800 for (; *Name != L'\0'; Name++) {
801 UnicodeValueToStringS (
802 String,
803 sizeof (CHAR16) * MaxLen - ((UINTN)String - (UINTN)ReturnString),
804 PREFIX_ZERO | RADIX_HEX,
805 *Name,
806 4
807 );
808 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));
809 }
810 }
811
812 //
813 // Append L"&PATH="
814 //
815 StrCatS (ReturnString, MaxLen, L"&PATH=");
816 String += StrLen (String);
817
818 //
819 // Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize
820 //
821 for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {
822 UnicodeValueToStringS (
823 String,
824 sizeof (CHAR16) * MaxLen - ((UINTN)String - (UINTN)ReturnString),
825 PREFIX_ZERO | RADIX_HEX,
826 *(Buffer++),
827 2
828 );
829 String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));
830 }
831
832 //
833 // Null terminate the Unicode string
834 //
835 *String = L'\0';
836
837 //
838 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
839 //
840 return InternalHiiLowerConfigString (ReturnString);
841 }
842
843 /**
844 Convert the hex UNICODE encoding string of UEFI GUID, NAME or device path
845 to binary buffer from <ConfigHdr>.
846
847 This is a internal function.
848
849 @param String UEFI configuration string.
850 @param Flag Flag specifies what type buffer will be retrieved.
851 @param Buffer Binary of Guid, Name or Device path.
852
853 @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid.
854 @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.
855 @retval EFI_SUCCESS The buffer data is retrieved and translated to
856 binary format.
857
858 **/
859 EFI_STATUS
860 InternalHiiGetBufferFromString (
861 IN EFI_STRING String,
862 IN UINT8 Flag,
863 OUT UINT8 **Buffer
864 )
865 {
866 UINTN Length;
867 EFI_STRING ConfigHdr;
868 CHAR16 *StringPtr;
869 UINT8 *DataBuffer;
870 CHAR16 TemStr[5];
871 UINTN Index;
872 UINT8 DigitUint8;
873
874 if (String == NULL || Buffer == NULL) {
875 return EFI_INVALID_PARAMETER;
876 }
877
878 DataBuffer = NULL;
879 StringPtr = NULL;
880 ConfigHdr = String;
881 //
882 // The content between 'GUID', 'NAME', 'PATH' of <ConfigHdr> and '&' of next element
883 // or '\0' (end of configuration string) is the UNICODE %02x bytes encoding string.
884 //
885 for (Length = 0; *String != 0 && *String != L'&'; String++, Length++);
886
887 switch (Flag) {
888 case GUID_CONFIG_STRING_TYPE:
889 case PATH_CONFIG_STRING_TYPE:
890 //
891 // The data in <ConfigHdr> is encoded as hex UNICODE %02x bytes in the same order
892 // as the device path and Guid resides in RAM memory.
893 // Translate the data into binary.
894 //
895 DataBuffer = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);
896 if (DataBuffer == NULL) {
897 return EFI_OUT_OF_RESOURCES;
898 }
899 //
900 // Convert binary byte one by one
901 //
902 ZeroMem (TemStr, sizeof (TemStr));
903 for (Index = 0; Index < Length; Index ++) {
904 TemStr[0] = ConfigHdr[Index];
905 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
906 if ((Index & 1) == 0) {
907 DataBuffer [Index/2] = DigitUint8;
908 } else {
909 DataBuffer [Index/2] = (UINT8) ((DataBuffer [Index/2] << 4) + DigitUint8);
910 }
911 }
912
913 *Buffer = DataBuffer;
914 break;
915
916 case NAME_CONFIG_STRING_TYPE:
917 //
918 // Convert Config String to Unicode String, e.g. "0041004200430044" => "ABCD"
919 //
920
921 //
922 // Add the tailling char L'\0'
923 //
924 DataBuffer = (UINT8 *) AllocateZeroPool ((Length/4 + 1) * sizeof (CHAR16));
925 if (DataBuffer == NULL) {
926 return EFI_OUT_OF_RESOURCES;
927 }
928 //
929 // Convert character one by one
930 //
931 StringPtr = (CHAR16 *) DataBuffer;
932 ZeroMem (TemStr, sizeof (TemStr));
933 for (Index = 0; Index < Length; Index += 4) {
934 StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), ConfigHdr + Index, 4);
935 StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
936 }
937 //
938 // Add tailing L'\0' character
939 //
940 StringPtr[Index/4] = L'\0';
941
942 *Buffer = DataBuffer;
943 break;
944
945 default:
946 return EFI_INVALID_PARAMETER;
947 }
948
949 return EFI_SUCCESS;
950 }
951
952 /**
953 This function checks VarOffset and VarWidth is in the block range.
954
955 @param BlockArray The block array is to be checked.
956 @param VarOffset Offset of var to the structure
957 @param VarWidth Width of var.
958
959 @retval TRUE This Var is in the block range.
960 @retval FALSE This Var is not in the block range.
961 **/
962 BOOLEAN
963 BlockArrayCheck (
964 IN IFR_BLOCK_DATA *BlockArray,
965 IN UINT16 VarOffset,
966 IN UINT16 VarWidth
967 )
968 {
969 LIST_ENTRY *Link;
970 IFR_BLOCK_DATA *BlockData;
971
972 //
973 // No Request Block array, all vars are got.
974 //
975 if (BlockArray == NULL) {
976 return TRUE;
977 }
978
979 //
980 // Check the input var is in the request block range.
981 //
982 for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) {
983 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);
984 if ((VarOffset >= BlockData->Offset) && ((VarOffset + VarWidth) <= (BlockData->Offset + BlockData->Width))) {
985 return TRUE;
986 }
987 }
988
989 return FALSE;
990 }
991
992 /**
993 Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
994 or WIDTH or VALUE.
995 <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
996
997 @param ValueString String in <BlockConfig> format and points to the
998 first character of <Number>.
999 @param ValueData The output value. Caller takes the responsibility
1000 to free memory.
1001 @param ValueLength Length of the <Number>, in characters.
1002
1003 @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
1004 structures.
1005 @retval EFI_SUCCESS Value of <Number> is outputted in Number
1006 successfully.
1007
1008 **/
1009 EFI_STATUS
1010 EFIAPI
1011 InternalHiiGetValueOfNumber (
1012 IN EFI_STRING ValueString,
1013 OUT UINT8 **ValueData,
1014 OUT UINTN *ValueLength
1015 )
1016 {
1017 EFI_STRING StringPtr;
1018 UINTN Length;
1019 UINT8 *Buf;
1020 UINT8 DigitUint8;
1021 UINTN Index;
1022 CHAR16 TemStr[2];
1023
1024 ASSERT (ValueString != NULL && ValueData != NULL && ValueLength != NULL);
1025 ASSERT (*ValueString != L'\0');
1026
1027 //
1028 // Get the length of value string
1029 //
1030 StringPtr = ValueString;
1031 while (*StringPtr != L'\0' && *StringPtr != L'&') {
1032 StringPtr++;
1033 }
1034 Length = StringPtr - ValueString;
1035
1036 //
1037 // Allocate buffer to store the value
1038 //
1039 Buf = (UINT8 *) AllocateZeroPool ((Length + 1) / 2);
1040 if (Buf == NULL) {
1041 return EFI_OUT_OF_RESOURCES;
1042 }
1043
1044 //
1045 // Convert character one by one to the value buffer
1046 //
1047 ZeroMem (TemStr, sizeof (TemStr));
1048 for (Index = 0; Index < Length; Index ++) {
1049 TemStr[0] = ValueString[Length - Index - 1];
1050 DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
1051 if ((Index & 1) == 0) {
1052 Buf [Index/2] = DigitUint8;
1053 } else {
1054 Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);
1055 }
1056 }
1057
1058 //
1059 // Set the converted value and string length.
1060 //
1061 *ValueData = Buf;
1062 *ValueLength = Length;
1063 return EFI_SUCCESS;
1064 }
1065
1066 /**
1067 Get value from config request resp string.
1068
1069 @param ConfigElement ConfigResp string contains the current setting.
1070 @param VarName The variable name which need to get value.
1071 @param VarValue The return value.
1072
1073 @retval EFI_SUCCESS Get the value for the VarName
1074 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1075 **/
1076 EFI_STATUS
1077 GetValueFromRequest (
1078 IN CHAR16 *ConfigElement,
1079 IN CHAR16 *VarName,
1080 OUT UINT64 *VarValue
1081 )
1082 {
1083 UINT8 *TmpBuffer;
1084 CHAR16 *StringPtr;
1085 UINTN Length;
1086 EFI_STATUS Status;
1087
1088 //
1089 // Find VarName related string.
1090 //
1091 StringPtr = StrStr (ConfigElement, VarName);
1092 ASSERT (StringPtr != NULL);
1093
1094 //
1095 // Skip the "VarName=" string
1096 //
1097 StringPtr += StrLen (VarName) + 1;
1098
1099 //
1100 // Get Offset
1101 //
1102 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);
1103 if (EFI_ERROR (Status)) {
1104 return Status;
1105 }
1106
1107 *VarValue = 0;
1108 CopyMem (VarValue, TmpBuffer, (((Length + 1) / 2) < sizeof (UINT64)) ? ((Length + 1) / 2) : sizeof (UINT64));
1109
1110 FreePool (TmpBuffer);
1111
1112 return EFI_SUCCESS;
1113 }
1114
1115 /**
1116 This internal function parses IFR data to validate current setting.
1117
1118 Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid;
1119 else the VarBuffer and CurrentBlockArray is valid.
1120
1121 @param HiiPackageList Point to Hii package list.
1122 @param PackageListLength The length of the pacakge.
1123 @param VarGuid Guid of the buffer storage.
1124 @param VarName Name of the buffer storage.
1125 @param VarBuffer The data buffer for the storage.
1126 @param CurrentBlockArray The block array from the config Requst string.
1127 @param RequestElement The config string for this storage.
1128 @param HiiHandle The HiiHandle for this formset.
1129 @param NameValueType Whether current storage is name/value varstore or not.
1130
1131 @retval EFI_SUCCESS The current setting is valid.
1132 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1133 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1134 **/
1135 EFI_STATUS
1136 ValidateQuestionFromVfr (
1137 IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList,
1138 IN UINTN PackageListLength,
1139 IN EFI_GUID *VarGuid,
1140 IN CHAR16 *VarName,
1141 IN UINT8 *VarBuffer,
1142 IN IFR_BLOCK_DATA *CurrentBlockArray,
1143 IN CHAR16 *RequestElement,
1144 IN EFI_HII_HANDLE HiiHandle,
1145 IN BOOLEAN NameValueType
1146 )
1147 {
1148 IFR_BLOCK_DATA VarBlockData;
1149 UINT16 Offset;
1150 UINT16 Width;
1151 UINT64 VarValue;
1152 EFI_IFR_TYPE_VALUE TmpValue;
1153 EFI_STATUS Status;
1154 EFI_HII_PACKAGE_HEADER PackageHeader;
1155 UINT32 PackageOffset;
1156 UINT8 *PackageData;
1157 UINTN IfrOffset;
1158 EFI_IFR_OP_HEADER *IfrOpHdr;
1159 EFI_IFR_VARSTORE *IfrVarStore;
1160 EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueStore;
1161 EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;
1162 IFR_VARSTORAGE_DATA VarStoreData;
1163 EFI_IFR_ONE_OF *IfrOneOf;
1164 EFI_IFR_NUMERIC *IfrNumeric;
1165 EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;
1166 EFI_IFR_CHECKBOX *IfrCheckBox;
1167 EFI_IFR_STRING *IfrString;
1168 CHAR8 *VarStoreName;
1169 UINTN Index;
1170 CHAR16 *QuestionName;
1171 CHAR16 *StringPtr;
1172
1173 //
1174 // Initialize the local variables.
1175 //
1176 Index = 0;
1177 VarStoreName = NULL;
1178 Status = EFI_SUCCESS;
1179 VarValue = 0;
1180 IfrVarStore = NULL;
1181 IfrNameValueStore = NULL;
1182 IfrEfiVarStore = NULL;
1183 ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA));
1184 ZeroMem (&VarBlockData, sizeof (VarBlockData));
1185
1186 //
1187 // Check IFR value is in block data, then Validate Value
1188 //
1189 PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
1190 while (PackageOffset < PackageListLength) {
1191 CopyMem (&PackageHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PackageHeader));
1192
1193 //
1194 // Parse IFR opcode from the form package.
1195 //
1196 if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {
1197 IfrOffset = sizeof (PackageHeader);
1198 PackageData = (UINT8 *) HiiPackageList + PackageOffset;
1199 while (IfrOffset < PackageHeader.Length) {
1200 IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset);
1201 //
1202 // Validate current setting to the value built in IFR opcode
1203 //
1204 switch (IfrOpHdr->OpCode) {
1205 case EFI_IFR_VARSTORE_OP:
1206 //
1207 // VarStoreId has been found. No further found.
1208 //
1209 if (VarStoreData.VarStoreId != 0) {
1210 break;
1211 }
1212 //
1213 // Find the matched VarStoreId to the input VarGuid and VarName
1214 //
1215 IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr;
1216 if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) {
1217 VarStoreName = (CHAR8 *) IfrVarStore->Name;
1218 for (Index = 0; VarStoreName[Index] != 0; Index ++) {
1219 if ((CHAR16) VarStoreName[Index] != VarName[Index]) {
1220 break;
1221 }
1222 }
1223 //
1224 // The matched VarStore is found.
1225 //
1226 if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) {
1227 IfrVarStore = NULL;
1228 }
1229 } else {
1230 IfrVarStore = NULL;
1231 }
1232
1233 if (IfrVarStore != NULL) {
1234 VarStoreData.VarStoreId = IfrVarStore->VarStoreId;
1235 VarStoreData.Size = IfrVarStore->Size;
1236 }
1237 break;
1238 case EFI_IFR_VARSTORE_NAME_VALUE_OP:
1239 //
1240 // VarStoreId has been found. No further found.
1241 //
1242 if (VarStoreData.VarStoreId != 0) {
1243 break;
1244 }
1245 //
1246 // Find the matched VarStoreId to the input VarGuid
1247 //
1248 IfrNameValueStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr;
1249 if (!CompareGuid ((EFI_GUID *) (VOID *) &IfrNameValueStore->Guid, VarGuid)) {
1250 IfrNameValueStore = NULL;
1251 }
1252
1253 if (IfrNameValueStore != NULL) {
1254 VarStoreData.VarStoreId = IfrNameValueStore->VarStoreId;
1255 }
1256 break;
1257 case EFI_IFR_VARSTORE_EFI_OP:
1258 //
1259 // VarStore is found. Don't need to search any more.
1260 //
1261 if (VarStoreData.VarStoreId != 0) {
1262 break;
1263 }
1264
1265 IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;
1266
1267 //
1268 // If the length is small than the structure, this is from old efi
1269 // varstore definition. Old efi varstore get config directly from
1270 // GetVariable function.
1271 //
1272 if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) {
1273 break;
1274 }
1275
1276 if (CompareGuid ((EFI_GUID *) (VOID *) &IfrEfiVarStore->Guid, VarGuid)) {
1277 VarStoreName = (CHAR8 *) IfrEfiVarStore->Name;
1278 for (Index = 0; VarStoreName[Index] != 0; Index ++) {
1279 if ((CHAR16) VarStoreName[Index] != VarName[Index]) {
1280 break;
1281 }
1282 }
1283 //
1284 // The matched VarStore is found.
1285 //
1286 if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) {
1287 IfrEfiVarStore = NULL;
1288 }
1289 } else {
1290 IfrEfiVarStore = NULL;
1291 }
1292
1293 if (IfrEfiVarStore != NULL) {
1294 //
1295 // Find the matched VarStore
1296 //
1297 VarStoreData.VarStoreId = IfrEfiVarStore->VarStoreId;
1298 VarStoreData.Size = IfrEfiVarStore->Size;
1299 }
1300 break;
1301 case EFI_IFR_FORM_OP:
1302 case EFI_IFR_FORM_MAP_OP:
1303 //
1304 // Check the matched VarStoreId is found.
1305 //
1306 if (VarStoreData.VarStoreId == 0) {
1307 return EFI_SUCCESS;
1308 }
1309 break;
1310 case EFI_IFR_ONE_OF_OP:
1311 //
1312 // Check whether current value is the one of option.
1313 //
1314
1315 //
1316 // OneOf question is not in IFR Form. This IFR form is not valid.
1317 //
1318 if (VarStoreData.VarStoreId == 0) {
1319 return EFI_INVALID_PARAMETER;
1320 }
1321 //
1322 // Check whether this question is for the requested varstore.
1323 //
1324 IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr;
1325 if (IfrOneOf->Question.VarStoreId != VarStoreData.VarStoreId) {
1326 break;
1327 }
1328
1329 if (NameValueType) {
1330 QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL);
1331 ASSERT (QuestionName != NULL);
1332
1333 if (StrStr (RequestElement, QuestionName) == NULL) {
1334 //
1335 // This question is not in the current configuration string. Skip it.
1336 //
1337 break;
1338 }
1339
1340 Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);
1341 if (EFI_ERROR (Status)) {
1342 return Status;
1343 }
1344 } else {
1345 //
1346 // Get Offset by Question header and Width by DataType Flags
1347 //
1348 Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;
1349 Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
1350 //
1351 // Check whether this question is in current block array.
1352 //
1353 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
1354 //
1355 // This question is not in the current configuration string. Skip it.
1356 //
1357 break;
1358 }
1359 //
1360 // Check this var question is in the var storage
1361 //
1362 if ((Offset + Width) > VarStoreData.Size) {
1363 //
1364 // This question exceeds the var store size.
1365 //
1366 return EFI_INVALID_PARAMETER;
1367 }
1368
1369 //
1370 // Get the current value for oneof opcode
1371 //
1372 VarValue = 0;
1373 CopyMem (&VarValue, VarBuffer + Offset, Width);
1374 }
1375 //
1376 // Set Block Data, to be checked in the following Oneof option opcode.
1377 //
1378 VarBlockData.OpCode = IfrOpHdr->OpCode;
1379 VarBlockData.Scope = IfrOpHdr->Scope;
1380 break;
1381 case EFI_IFR_NUMERIC_OP:
1382 //
1383 // Check the current value is in the numeric range.
1384 //
1385
1386 //
1387 // Numeric question is not in IFR Form. This IFR form is not valid.
1388 //
1389 if (VarStoreData.VarStoreId == 0) {
1390 return EFI_INVALID_PARAMETER;
1391 }
1392 //
1393 // Check whether this question is for the requested varstore.
1394 //
1395 IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpHdr;
1396 if (IfrNumeric->Question.VarStoreId != VarStoreData.VarStoreId) {
1397 break;
1398 }
1399
1400 if (NameValueType) {
1401 QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL);
1402 ASSERT (QuestionName != NULL);
1403
1404 if (StrStr (RequestElement, QuestionName) == NULL) {
1405 //
1406 // This question is not in the current configuration string. Skip it.
1407 //
1408 break;
1409 }
1410
1411 Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);
1412 if (EFI_ERROR (Status)) {
1413 return Status;
1414 }
1415 } else {
1416 //
1417 // Get Offset by Question header and Width by DataType Flags
1418 //
1419 Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;
1420 Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
1421 //
1422 // Check whether this question is in current block array.
1423 //
1424 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
1425 //
1426 // This question is not in the current configuration string. Skip it.
1427 //
1428 break;
1429 }
1430 //
1431 // Check this var question is in the var storage
1432 //
1433 if ((Offset + Width) > VarStoreData.Size) {
1434 //
1435 // This question exceeds the var store size.
1436 //
1437 return EFI_INVALID_PARAMETER;
1438 }
1439
1440 //
1441 // Check the current value is in the numeric range.
1442 //
1443 VarValue = 0;
1444 CopyMem (&VarValue, VarBuffer + Offset, Width);
1445 }
1446 if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {
1447 switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
1448 case EFI_IFR_NUMERIC_SIZE_1:
1449 if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {
1450 //
1451 // Not in the valid range.
1452 //
1453 return EFI_INVALID_PARAMETER;
1454 }
1455 break;
1456 case EFI_IFR_NUMERIC_SIZE_2:
1457 if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {
1458 //
1459 // Not in the valid range.
1460 //
1461 return EFI_INVALID_PARAMETER;
1462 }
1463 break;
1464 case EFI_IFR_NUMERIC_SIZE_4:
1465 if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {
1466 //
1467 // Not in the valid range.
1468 //
1469 return EFI_INVALID_PARAMETER;
1470 }
1471 break;
1472 case EFI_IFR_NUMERIC_SIZE_8:
1473 if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {
1474 //
1475 // Not in the valid range.
1476 //
1477 return EFI_INVALID_PARAMETER;
1478 }
1479 break;
1480 }
1481 } else {
1482 switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
1483 case EFI_IFR_NUMERIC_SIZE_1:
1484 if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {
1485 //
1486 // Not in the valid range.
1487 //
1488 return EFI_INVALID_PARAMETER;
1489 }
1490 break;
1491 case EFI_IFR_NUMERIC_SIZE_2:
1492 if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {
1493 //
1494 // Not in the valid range.
1495 //
1496 return EFI_INVALID_PARAMETER;
1497 }
1498 break;
1499 case EFI_IFR_NUMERIC_SIZE_4:
1500 if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {
1501 //
1502 // Not in the valid range.
1503 //
1504 return EFI_INVALID_PARAMETER;
1505 }
1506 break;
1507 case EFI_IFR_NUMERIC_SIZE_8:
1508 if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {
1509 //
1510 // Not in the valid range.
1511 //
1512 return EFI_INVALID_PARAMETER;
1513 }
1514 break;
1515 }
1516 }
1517 break;
1518 case EFI_IFR_CHECKBOX_OP:
1519 //
1520 // Check value is BOOLEAN type, only 0 and 1 is valid.
1521 //
1522
1523 //
1524 // CheckBox question is not in IFR Form. This IFR form is not valid.
1525 //
1526 if (VarStoreData.VarStoreId == 0) {
1527 return EFI_INVALID_PARAMETER;
1528 }
1529
1530 //
1531 // Check whether this question is for the requested varstore.
1532 //
1533 IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr;
1534 if (IfrCheckBox->Question.VarStoreId != VarStoreData.VarStoreId) {
1535 break;
1536 }
1537
1538 if (NameValueType) {
1539 QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL);
1540 ASSERT (QuestionName != NULL);
1541
1542 if (StrStr (RequestElement, QuestionName) == NULL) {
1543 //
1544 // This question is not in the current configuration string. Skip it.
1545 //
1546 break;
1547 }
1548
1549 Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue);
1550 if (EFI_ERROR (Status)) {
1551 return Status;
1552 }
1553 } else {
1554 //
1555 // Get Offset by Question header
1556 //
1557 Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;
1558 Width = (UINT16) sizeof (BOOLEAN);
1559 //
1560 // Check whether this question is in current block array.
1561 //
1562 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
1563 //
1564 // This question is not in the current configuration string. Skip it.
1565 //
1566 break;
1567 }
1568 //
1569 // Check this var question is in the var storage
1570 //
1571 if ((Offset + Width) > VarStoreData.Size) {
1572 //
1573 // This question exceeds the var store size.
1574 //
1575 return EFI_INVALID_PARAMETER;
1576 }
1577 //
1578 // Check the current value is in the numeric range.
1579 //
1580 VarValue = 0;
1581 CopyMem (&VarValue, VarBuffer + Offset, Width);
1582 }
1583 //
1584 // Boolean type, only 1 and 0 is valid.
1585 //
1586 if (VarValue > 1) {
1587 return EFI_INVALID_PARAMETER;
1588 }
1589 break;
1590 case EFI_IFR_STRING_OP:
1591 //
1592 // Check current string length is less than maxsize
1593 //
1594
1595 //
1596 // CheckBox question is not in IFR Form. This IFR form is not valid.
1597 //
1598 if (VarStoreData.VarStoreId == 0) {
1599 return EFI_INVALID_PARAMETER;
1600 }
1601
1602 //
1603 // Check whether this question is for the requested varstore.
1604 //
1605 IfrString = (EFI_IFR_STRING *) IfrOpHdr;
1606 if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) {
1607 break;
1608 }
1609 //
1610 // Get Width by OneOf Flags
1611 //
1612 Width = (UINT16) (IfrString->MaxSize * sizeof (UINT16));
1613 if (NameValueType) {
1614 QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL);
1615 ASSERT (QuestionName != NULL);
1616
1617 StringPtr = StrStr (RequestElement, QuestionName);
1618 if (StringPtr == NULL) {
1619 //
1620 // This question is not in the current configuration string. Skip it.
1621 //
1622 break;
1623 }
1624
1625 //
1626 // Skip the "=".
1627 //
1628 StringPtr += 1;
1629
1630 //
1631 // Check current string length is less than maxsize
1632 //
1633 if (StrSize (StringPtr) > Width) {
1634 return EFI_INVALID_PARAMETER;
1635 }
1636 } else {
1637 //
1638 // Get Offset/Width by Question header and OneOf Flags
1639 //
1640 Offset = IfrString->Question.VarStoreInfo.VarOffset;
1641 //
1642 // Check whether this question is in current block array.
1643 //
1644 if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
1645 //
1646 // This question is not in the current configuration string. Skip it.
1647 //
1648 break;
1649 }
1650 //
1651 // Check this var question is in the var storage
1652 //
1653 if ((Offset + Width) > VarStoreData.Size) {
1654 //
1655 // This question exceeds the var store size.
1656 //
1657 return EFI_INVALID_PARAMETER;
1658 }
1659
1660 //
1661 // Check current string length is less than maxsize
1662 //
1663 if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) {
1664 return EFI_INVALID_PARAMETER;
1665 }
1666 }
1667 break;
1668 case EFI_IFR_ONE_OF_OPTION_OP:
1669 //
1670 // Opcode Scope is zero. This one of option is not to be checked.
1671 //
1672 if (VarBlockData.Scope == 0) {
1673 break;
1674 }
1675
1676 //
1677 // Only check for OneOf and OrderList opcode
1678 //
1679 IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;
1680 if (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP) {
1681 //
1682 // Check current value is the value of one of option.
1683 //
1684 ASSERT (IfrOneOfOption->Type <= EFI_IFR_TYPE_NUM_SIZE_64);
1685 ZeroMem (&TmpValue, sizeof (EFI_IFR_TYPE_VALUE));
1686 CopyMem (&TmpValue, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));
1687 if (VarValue == TmpValue.u64) {
1688 //
1689 // The value is one of option value.
1690 // Set OpCode to Zero, don't need check again.
1691 //
1692 VarBlockData.OpCode = 0;
1693 }
1694 }
1695 break;
1696 case EFI_IFR_END_OP:
1697 //
1698 // Decrease opcode scope for the validated opcode
1699 //
1700 if (VarBlockData.Scope > 0) {
1701 VarBlockData.Scope --;
1702 }
1703
1704 //
1705 // OneOf value doesn't belong to one of option value.
1706 //
1707 if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) {
1708 return EFI_INVALID_PARAMETER;
1709 }
1710 break;
1711 default:
1712 //
1713 // Increase Scope for the validated opcode
1714 //
1715 if (VarBlockData.Scope > 0) {
1716 VarBlockData.Scope = (UINT8) (VarBlockData.Scope + IfrOpHdr->Scope);
1717 }
1718 break;
1719 }
1720 //
1721 // Go to the next opcode
1722 //
1723 IfrOffset += IfrOpHdr->Length;
1724 }
1725 //
1726 // Only one form is in a package list.
1727 //
1728 break;
1729 }
1730
1731 //
1732 // Go to next package.
1733 //
1734 PackageOffset += PackageHeader.Length;
1735 }
1736
1737 return EFI_SUCCESS;
1738 }
1739
1740 /**
1741 This internal function parses IFR data to validate current setting.
1742
1743 @param ConfigElement ConfigResp element string contains the current setting.
1744 @param CurrentBlockArray Current block array.
1745 @param VarBuffer Data buffer for this varstore.
1746
1747 @retval EFI_SUCCESS The current setting is valid.
1748 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
1749 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
1750 **/
1751 EFI_STATUS
1752 GetBlockDataInfo (
1753 IN CHAR16 *ConfigElement,
1754 OUT IFR_BLOCK_DATA **CurrentBlockArray,
1755 OUT UINT8 **VarBuffer
1756 )
1757 {
1758 IFR_BLOCK_DATA *BlockData;
1759 IFR_BLOCK_DATA *NewBlockData;
1760 EFI_STRING StringPtr;
1761 UINTN Length;
1762 UINT8 *TmpBuffer;
1763 UINT16 Offset;
1764 UINT16 Width;
1765 LIST_ENTRY *Link;
1766 UINTN MaxBufferSize;
1767 EFI_STATUS Status;
1768 IFR_BLOCK_DATA *BlockArray;
1769 UINT8 *DataBuffer;
1770
1771 //
1772 // Initialize the local variables.
1773 //
1774 Status = EFI_SUCCESS;
1775 BlockData = NULL;
1776 NewBlockData = NULL;
1777 TmpBuffer = NULL;
1778 BlockArray = NULL;
1779 MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE;
1780 DataBuffer = AllocateZeroPool (MaxBufferSize);
1781 if (DataBuffer == NULL) {
1782 return EFI_OUT_OF_RESOURCES;
1783 }
1784
1785 //
1786 // Init BlockArray
1787 //
1788 BlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));
1789 if (BlockArray == NULL) {
1790 Status = EFI_OUT_OF_RESOURCES;
1791 goto Done;
1792 }
1793 InitializeListHead (&BlockArray->Entry);
1794
1795 StringPtr = StrStr (ConfigElement, L"&OFFSET=");
1796 ASSERT (StringPtr != NULL);
1797
1798 //
1799 // Parse each <RequestElement> if exists
1800 // Only <BlockName> format is supported by this help function.
1801 // <BlockName> ::= &'OFFSET='<Number>&'WIDTH='<Number>
1802 //
1803 while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) {
1804 //
1805 // Skip the &OFFSET= string
1806 //
1807 StringPtr += StrLen (L"&OFFSET=");
1808
1809 //
1810 // Get Offset
1811 //
1812 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);
1813 if (EFI_ERROR (Status)) {
1814 goto Done;
1815 }
1816 Offset = 0;
1817 CopyMem (
1818 &Offset,
1819 TmpBuffer,
1820 (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)
1821 );
1822 FreePool (TmpBuffer);
1823 TmpBuffer = NULL;
1824
1825 StringPtr += Length;
1826 if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {
1827 Status = EFI_INVALID_PARAMETER;
1828 goto Done;
1829 }
1830 StringPtr += StrLen (L"&WIDTH=");
1831
1832 //
1833 // Get Width
1834 //
1835 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);
1836 if (EFI_ERROR (Status)) {
1837 goto Done;
1838 }
1839 Width = 0;
1840 CopyMem (
1841 &Width,
1842 TmpBuffer,
1843 (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16)
1844 );
1845 FreePool (TmpBuffer);
1846 TmpBuffer = NULL;
1847
1848 StringPtr += Length;
1849 if (*StringPtr != 0 && *StringPtr != L'&') {
1850 Status = EFI_INVALID_PARAMETER;
1851 goto Done;
1852 }
1853
1854 if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {
1855 Status = EFI_INVALID_PARAMETER;
1856 goto Done;
1857 }
1858 StringPtr += StrLen (L"&VALUE=");
1859
1860 //
1861 // Get Value
1862 //
1863 Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length);
1864 if (EFI_ERROR (Status)) {
1865 goto Done;
1866 }
1867
1868 StringPtr += Length;
1869 if (*StringPtr != 0 && *StringPtr != L'&') {
1870 Status = EFI_INVALID_PARAMETER;
1871 goto Done;
1872 }
1873
1874 //
1875 // Check whether VarBuffer is enough
1876 //
1877 if ((UINTN) (Offset + Width) > MaxBufferSize) {
1878 DataBuffer = ReallocatePool (
1879 MaxBufferSize,
1880 Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE,
1881 DataBuffer
1882 );
1883 if (DataBuffer == NULL) {
1884 Status = EFI_OUT_OF_RESOURCES;
1885 goto Done;
1886 }
1887 MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE;
1888 }
1889
1890 //
1891 // Update the Block with configuration info
1892 //
1893 CopyMem (DataBuffer + Offset, TmpBuffer, Width);
1894 FreePool (TmpBuffer);
1895 TmpBuffer = NULL;
1896
1897 //
1898 // Set new Block Data
1899 //
1900 NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA));
1901 if (NewBlockData == NULL) {
1902 Status = EFI_OUT_OF_RESOURCES;
1903 goto Done;
1904 }
1905 NewBlockData->Offset = Offset;
1906 NewBlockData->Width = Width;
1907
1908 //
1909 // Insert the new block data into the block data array.
1910 //
1911 for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) {
1912 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);
1913 if (NewBlockData->Offset == BlockData->Offset) {
1914 if (NewBlockData->Width > BlockData->Width) {
1915 BlockData->Width = NewBlockData->Width;
1916 }
1917 FreePool (NewBlockData);
1918 break;
1919 } else if (NewBlockData->Offset < BlockData->Offset) {
1920 //
1921 // Insert new block data as the previous one of this link.
1922 //
1923 InsertTailList (Link, &NewBlockData->Entry);
1924 break;
1925 }
1926 }
1927
1928 //
1929 // Insert new block data into the array tail.
1930 //
1931 if (Link == &BlockArray->Entry) {
1932 InsertTailList (Link, &NewBlockData->Entry);
1933 }
1934
1935 //
1936 // If '\0', parsing is finished.
1937 //
1938 if (*StringPtr == 0) {
1939 break;
1940 }
1941 //
1942 // Go to next ConfigBlock
1943 //
1944 }
1945
1946 //
1947 // Merge the aligned block data into the single block data.
1948 //
1949 Link = BlockArray->Entry.ForwardLink;
1950 while ((Link != &BlockArray->Entry) && (Link->ForwardLink != &BlockArray->Entry)) {
1951 BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry);
1952 NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry);
1953 if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) {
1954 if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) {
1955 BlockData->Width = (UINT16) (NewBlockData->Offset + NewBlockData->Width - BlockData->Offset);
1956 }
1957 RemoveEntryList (Link->ForwardLink);
1958 FreePool (NewBlockData);
1959 continue;
1960 }
1961 Link = Link->ForwardLink;
1962 }
1963
1964 *VarBuffer = DataBuffer;
1965 *CurrentBlockArray = BlockArray;
1966 return EFI_SUCCESS;
1967
1968 Done:
1969 if (DataBuffer != NULL) {
1970 FreePool (DataBuffer);
1971 }
1972
1973 if (BlockArray != NULL) {
1974 //
1975 // Free Link Array CurrentBlockArray
1976 //
1977 while (!IsListEmpty (&BlockArray->Entry)) {
1978 BlockData = BASE_CR (BlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);
1979 RemoveEntryList (&BlockData->Entry);
1980 FreePool (BlockData);
1981 }
1982 FreePool (BlockArray);
1983 }
1984
1985 return Status;
1986 }
1987
1988 /**
1989 This internal function parses IFR data to validate current setting.
1990
1991 @param ConfigResp ConfigResp string contains the current setting.
1992 @param HiiPackageList Point to Hii package list.
1993 @param PackageListLength The length of the pacakge.
1994 @param VarGuid Guid of the buffer storage.
1995 @param VarName Name of the buffer storage.
1996 @param HiiHandle The HiiHandle for this package.
1997
1998 @retval EFI_SUCCESS The current setting is valid.
1999 @retval EFI_OUT_OF_RESOURCES The memory is not enough.
2000 @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid.
2001 **/
2002 EFI_STATUS
2003 EFIAPI
2004 InternalHiiValidateCurrentSetting (
2005 IN EFI_STRING ConfigResp,
2006 IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList,
2007 IN UINTN PackageListLength,
2008 IN EFI_GUID *VarGuid,
2009 IN CHAR16 *VarName,
2010 IN EFI_HII_HANDLE HiiHandle
2011 )
2012 {
2013 CHAR16 *StringPtr;
2014 EFI_STATUS Status;
2015 IFR_BLOCK_DATA *CurrentBlockArray;
2016 IFR_BLOCK_DATA *BlockData;
2017 UINT8 *VarBuffer;
2018 BOOLEAN NameValueType;
2019
2020 CurrentBlockArray = NULL;
2021 VarBuffer = NULL;
2022 StringPtr = NULL;
2023 Status = EFI_SUCCESS;
2024
2025 //
2026 // If StringPtr != NULL, get the request elements.
2027 //
2028 if (StrStr (ConfigResp, L"&OFFSET=") != NULL) {
2029 Status = GetBlockDataInfo(ConfigResp, &CurrentBlockArray, &VarBuffer);
2030 if (EFI_ERROR (Status)) {
2031 return Status;
2032 }
2033 NameValueType = FALSE;
2034 } else {
2035 //
2036 // Skip header part.
2037 //
2038 StringPtr = StrStr (ConfigResp, L"PATH=");
2039 ASSERT (StringPtr != NULL);
2040
2041 if (StrStr (StringPtr, L"&") != NULL) {
2042 NameValueType = TRUE;
2043 } else {
2044 //
2045 // Not found Request element, return success.
2046 //
2047 return EFI_SUCCESS;
2048 }
2049 }
2050
2051 Status = ValidateQuestionFromVfr(
2052 HiiPackageList,
2053 PackageListLength,
2054 VarGuid,
2055 VarName,
2056 VarBuffer,
2057 CurrentBlockArray,
2058 ConfigResp,
2059 HiiHandle,
2060 NameValueType
2061 );
2062
2063 if (VarBuffer != NULL) {
2064 FreePool (VarBuffer);
2065 }
2066
2067 if (CurrentBlockArray != NULL) {
2068 //
2069 // Free Link Array CurrentBlockArray
2070 //
2071 while (!IsListEmpty (&CurrentBlockArray->Entry)) {
2072 BlockData = BASE_CR (CurrentBlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry);
2073 RemoveEntryList (&BlockData->Entry);
2074 FreePool (BlockData);
2075 }
2076 FreePool (CurrentBlockArray);
2077 }
2078
2079 return Status;
2080 }
2081
2082 /**
2083 Check whether the ConfigRequest string has the request elements.
2084 For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format.
2085 For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format.
2086
2087 @param ConfigRequest The input config request string.
2088
2089 @retval TRUE The input include config request elements.
2090 @retval FALSE The input string not includes.
2091
2092 **/
2093 BOOLEAN
2094 GetElementsFromRequest (
2095 IN EFI_STRING ConfigRequest
2096 )
2097 {
2098 EFI_STRING TmpRequest;
2099
2100 TmpRequest = StrStr (ConfigRequest, L"PATH=");
2101 ASSERT (TmpRequest != NULL);
2102
2103 if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) {
2104 return TRUE;
2105 }
2106
2107 return FALSE;
2108 }
2109
2110 /**
2111 This function parses the input ConfigRequest string and its matched IFR code
2112 string for setting default value and validating current setting.
2113
2114 1. For setting default action, Reset the default value specified by DefaultId
2115 to the driver configuration got by Request string.
2116 2. For validating current setting, Validate the current configuration
2117 by parsing HII form IFR opcode.
2118
2119 NULL request string support depends on the ExportConfig interface of
2120 HiiConfigRouting protocol in UEFI specification.
2121
2122 @param Request A null-terminated Unicode string in
2123 <MultiConfigRequest> format. It can be NULL.
2124 If it is NULL, all current configuration for the
2125 entirety of the current HII database will be validated.
2126 If it is NULL, all configuration for the
2127 entirety of the current HII database will be reset.
2128 @param DefaultId Specifies the type of defaults to retrieve only for setting default action.
2129 @param ActionType Action supports setting defaults and validate current setting.
2130
2131 @retval TRUE Action runs successfully.
2132 @retval FALSE Action is not valid or Action can't be executed successfully..
2133 **/
2134 BOOLEAN
2135 EFIAPI
2136 InternalHiiIfrValueAction (
2137 IN CONST EFI_STRING Request, OPTIONAL
2138 IN UINT16 DefaultId,
2139 IN UINT8 ActionType
2140 )
2141 {
2142 EFI_STRING ConfigAltResp;
2143 EFI_STRING ConfigAltHdr;
2144 EFI_STRING ConfigResp;
2145 EFI_STRING Progress;
2146 EFI_STRING StringPtr;
2147 EFI_STRING StringHdr;
2148 EFI_STATUS Status;
2149 EFI_HANDLE DriverHandle;
2150 EFI_HANDLE TempDriverHandle;
2151 EFI_HII_HANDLE *HiiHandleBuffer;
2152 EFI_HII_HANDLE HiiHandle;
2153 UINT32 Index;
2154 EFI_GUID *VarGuid;
2155 EFI_STRING VarName;
2156
2157 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
2158 UINTN PackageListLength;
2159 UINTN MaxLen;
2160 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2161 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
2162
2163 ConfigAltResp = NULL;
2164 ConfigResp = NULL;
2165 VarGuid = NULL;
2166 VarName = NULL;
2167 DevicePath = NULL;
2168 ConfigAltHdr = NULL;
2169 HiiHandleBuffer = NULL;
2170 Index = 0;
2171 TempDriverHandle = NULL;
2172 HiiHandle = NULL;
2173 HiiPackageList = NULL;
2174
2175 //
2176 // Only support set default and validate setting action.
2177 //
2178 if ((ActionType != ACTION_SET_DEFAUTL_VALUE) && (ActionType != ACTION_VALIDATE_SETTING)) {
2179 return FALSE;
2180 }
2181
2182 //
2183 // Get the full requested value and deault value string.
2184 //
2185 if (Request != NULL) {
2186 Status = gHiiConfigRouting->ExtractConfig (
2187 gHiiConfigRouting,
2188 Request,
2189 &Progress,
2190 &ConfigAltResp
2191 );
2192 } else {
2193 Status = gHiiConfigRouting->ExportConfig (
2194 gHiiConfigRouting,
2195 &ConfigAltResp
2196 );
2197 }
2198
2199 if (EFI_ERROR (Status)) {
2200 return FALSE;
2201 }
2202
2203 StringPtr = ConfigAltResp;
2204
2205 while (StringPtr != L'\0') {
2206 //
2207 // 1. Find <ConfigHdr> GUID=...&NAME=...&PATH=...
2208 //
2209 StringHdr = StringPtr;
2210
2211 //
2212 // Get Guid value
2213 //
2214 if (StrnCmp (StringPtr, L"GUID=", StrLen (L"GUID=")) != 0) {
2215 Status = EFI_INVALID_PARAMETER;
2216 goto Done;
2217 }
2218 StringPtr += StrLen (L"GUID=");
2219 Status = InternalHiiGetBufferFromString (StringPtr, GUID_CONFIG_STRING_TYPE, (UINT8 **) &VarGuid);
2220 if (EFI_ERROR (Status)) {
2221 goto Done;
2222 }
2223
2224 //
2225 // Get Name value VarName
2226 //
2227 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&NAME=", StrLen (L"&NAME=")) != 0) {
2228 StringPtr++;
2229 }
2230 if (*StringPtr == L'\0') {
2231 Status = EFI_INVALID_PARAMETER;
2232 goto Done;
2233 }
2234 StringPtr += StrLen (L"&NAME=");
2235 Status = InternalHiiGetBufferFromString (StringPtr, NAME_CONFIG_STRING_TYPE, (UINT8 **) &VarName);
2236 if (EFI_ERROR (Status)) {
2237 goto Done;
2238 }
2239
2240 //
2241 // Get Path value DevicePath
2242 //
2243 while (*StringPtr != L'\0' && StrnCmp (StringPtr, L"&PATH=", StrLen (L"&PATH=")) != 0) {
2244 StringPtr++;
2245 }
2246 if (*StringPtr == L'\0') {
2247 Status = EFI_INVALID_PARAMETER;
2248 goto Done;
2249 }
2250 StringPtr += StrLen (L"&PATH=");
2251 Status = InternalHiiGetBufferFromString (StringPtr, PATH_CONFIG_STRING_TYPE, (UINT8 **) &DevicePath);
2252 if (EFI_ERROR (Status)) {
2253 goto Done;
2254 }
2255
2256 //
2257 // Get the Driver handle by the got device path.
2258 //
2259 TempDevicePath = DevicePath;
2260 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &TempDevicePath, &DriverHandle);
2261 if (EFI_ERROR (Status)) {
2262 goto Done;
2263 }
2264
2265 //
2266 // Find the matched Hii Handle for the found Driver handle
2267 //
2268 HiiHandleBuffer = HiiGetHiiHandles (NULL);
2269 if (HiiHandleBuffer == NULL) {
2270 Status = EFI_NOT_FOUND;
2271 goto Done;
2272 }
2273
2274 for (Index = 0; HiiHandleBuffer[Index] != NULL; Index ++) {
2275 gHiiDatabase->GetPackageListHandle (gHiiDatabase, HiiHandleBuffer[Index], &TempDriverHandle);
2276 if (TempDriverHandle == DriverHandle) {
2277 break;
2278 }
2279 }
2280
2281 HiiHandle = HiiHandleBuffer[Index];
2282 FreePool (HiiHandleBuffer);
2283
2284 if (HiiHandle == NULL) {
2285 //
2286 // This request string has no its Hii package.
2287 // Its default value and validating can't execute by parsing IFR data.
2288 // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path.
2289 //
2290 Status = EFI_SUCCESS;
2291 goto NextConfigAltResp;
2292 }
2293
2294 //
2295 // 2. Get HiiPackage by HiiHandle
2296 //
2297 PackageListLength = 0;
2298 HiiPackageList = NULL;
2299 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList);
2300
2301 //
2302 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
2303 //
2304 if (Status != EFI_BUFFER_TOO_SMALL) {
2305 Status = EFI_INVALID_PARAMETER;
2306 goto Done;
2307 }
2308
2309 HiiPackageList = AllocatePool (PackageListLength);
2310 if (HiiPackageList == NULL) {
2311 Status = EFI_OUT_OF_RESOURCES;
2312 goto Done;
2313 }
2314
2315 //
2316 // Get PackageList on HiiHandle
2317 //
2318 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &PackageListLength, HiiPackageList);
2319 if (EFI_ERROR (Status)) {
2320 goto Done;
2321 }
2322
2323 //
2324 // 3. Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
2325 // Get the default configuration string according to the default ID.
2326 //
2327 Status = gHiiConfigRouting->GetAltConfig (
2328 gHiiConfigRouting,
2329 ConfigAltResp,
2330 VarGuid,
2331 VarName,
2332 DevicePath,
2333 (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultId:NULL, // it can be NULL to get the current setting.
2334 &ConfigResp
2335 );
2336
2337 //
2338 // The required setting can't be found. So, it is not required to be validated and set.
2339 //
2340 if (EFI_ERROR (Status)) {
2341 Status = EFI_SUCCESS;
2342 goto NextConfigAltResp;
2343 }
2344 //
2345 // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set.
2346 //
2347 if (!GetElementsFromRequest (ConfigResp)) {
2348 goto NextConfigAltResp;
2349 }
2350
2351 //
2352 // 4. Set the default configuration information or Validate current setting by parse IFR code.
2353 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2354 //
2355 if (ActionType == ACTION_SET_DEFAUTL_VALUE) {
2356 //
2357 // Set the default configuration information.
2358 //
2359 Status = gHiiConfigRouting->RouteConfig (gHiiConfigRouting, ConfigResp, &Progress);
2360 } else {
2361 //
2362 // Current Setting is in ConfigResp, will be set into buffer, then check it again.
2363 //
2364 Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName, HiiHandle);
2365 }
2366
2367 if (EFI_ERROR (Status)) {
2368 goto Done;
2369 }
2370
2371 NextConfigAltResp:
2372 //
2373 // Free the allocated pacakge buffer and the got ConfigResp string.
2374 //
2375 if (HiiPackageList != NULL) {
2376 FreePool (HiiPackageList);
2377 HiiPackageList = NULL;
2378 }
2379
2380 if (ConfigResp != NULL) {
2381 FreePool (ConfigResp);
2382 ConfigResp = NULL;
2383 }
2384
2385 //
2386 // Free the allocated buffer.
2387 //
2388 FreePool (VarGuid);
2389 VarGuid = NULL;
2390
2391 FreePool (VarName);
2392 VarName = NULL;
2393
2394 FreePool (DevicePath);
2395 DevicePath = NULL;
2396
2397 //
2398 // 5. Jump to next ConfigAltResp for another Guid, Name, Path.
2399 //
2400
2401 //
2402 // Get and Skip ConfigHdr
2403 //
2404 while (*StringPtr != L'\0' && *StringPtr != L'&') {
2405 StringPtr++;
2406 }
2407 if (*StringPtr == L'\0') {
2408 break;
2409 }
2410
2411 //
2412 // Construct ConfigAltHdr string "&<ConfigHdr>&ALTCFG=\0"
2413 // | 1 | StrLen (ConfigHdr) | 8 | 1 |
2414 //
2415 MaxLen = 1 + StringPtr - StringHdr + 8 + 1;
2416 ConfigAltHdr = AllocateZeroPool ( MaxLen * sizeof (CHAR16));
2417 if (ConfigAltHdr == NULL) {
2418 Status = EFI_OUT_OF_RESOURCES;
2419 goto Done;
2420 }
2421 StrCpyS (ConfigAltHdr, MaxLen, L"&");
2422 StrnCatS (ConfigAltHdr, MaxLen, StringHdr, StringPtr - StringHdr);
2423 StrCatS (ConfigAltHdr, MaxLen, L"&ALTCFG=");
2424
2425 //
2426 // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr
2427 //
2428 while ((StringHdr = StrStr (StringPtr, ConfigAltHdr)) != NULL) {
2429 StringPtr = StringHdr + StrLen (ConfigAltHdr);
2430 if (*StringPtr == L'\0') {
2431 break;
2432 }
2433 }
2434
2435 //
2436 // Free the allocated ConfigAltHdr string
2437 //
2438 FreePool (ConfigAltHdr);
2439 if (*StringPtr == L'\0') {
2440 break;
2441 }
2442
2443 //
2444 // Find &GUID as the next ConfigHdr
2445 //
2446 StringPtr = StrStr (StringPtr, L"&GUID");
2447 if (StringPtr == NULL) {
2448 break;
2449 }
2450
2451 //
2452 // Skip char '&'
2453 //
2454 StringPtr ++;
2455 }
2456
2457 Done:
2458 if (VarGuid != NULL) {
2459 FreePool (VarGuid);
2460 }
2461
2462 if (VarName != NULL) {
2463 FreePool (VarName);
2464 }
2465
2466 if (DevicePath != NULL) {
2467 FreePool (DevicePath);
2468 }
2469
2470 if (ConfigResp != NULL) {
2471 FreePool (ConfigResp);
2472 }
2473
2474 if (ConfigAltResp != NULL) {
2475 FreePool (ConfigAltResp);
2476 }
2477
2478 if (HiiPackageList != NULL) {
2479 FreePool (HiiPackageList);
2480 }
2481
2482 if (EFI_ERROR (Status)) {
2483 return FALSE;
2484 }
2485
2486 return TRUE;
2487 }
2488
2489 /**
2490 Validate the current configuration by parsing HII form IFR opcode.
2491
2492 NULL request string support depends on the ExportConfig interface of
2493 HiiConfigRouting protocol in UEFI specification.
2494
2495 @param Request A null-terminated Unicode string in
2496 <MultiConfigRequest> format. It can be NULL.
2497 If it is NULL, all current configuration for the
2498 entirety of the current HII database will be validated.
2499
2500 @retval TRUE Current configuration is valid.
2501 @retval FALSE Current configuration is invalid.
2502 **/
2503 BOOLEAN
2504 EFIAPI
2505 HiiValidateSettings (
2506 IN CONST EFI_STRING Request OPTIONAL
2507 )
2508 {
2509 return InternalHiiIfrValueAction (Request, 0, ACTION_VALIDATE_SETTING);
2510 }
2511
2512 /**
2513 Reset the default value specified by DefaultId to the driver
2514 configuration got by Request string.
2515
2516 NULL request string support depends on the ExportConfig interface of
2517 HiiConfigRouting protocol in UEFI specification.
2518
2519 @param Request A null-terminated Unicode string in
2520 <MultiConfigRequest> format. It can be NULL.
2521 If it is NULL, all configuration for the
2522 entirety of the current HII database will be reset.
2523 @param DefaultId Specifies the type of defaults to retrieve.
2524
2525 @retval TRUE The default value is set successfully.
2526 @retval FALSE The default value can't be found and set.
2527 **/
2528 BOOLEAN
2529 EFIAPI
2530 HiiSetToDefaults (
2531 IN CONST EFI_STRING Request, OPTIONAL
2532 IN UINT16 DefaultId
2533 )
2534 {
2535 return InternalHiiIfrValueAction (Request, DefaultId, ACTION_SET_DEFAUTL_VALUE);
2536 }
2537
2538 /**
2539 Determines if two values in config strings match.
2540
2541 Compares the substring between StartSearchString and StopSearchString in
2542 FirstString to the substring between StartSearchString and StopSearchString
2543 in SecondString. If the two substrings match, then TRUE is returned. If the
2544 two substrings do not match, then FALSE is returned.
2545
2546 If FirstString is NULL, then ASSERT().
2547 If SecondString is NULL, then ASSERT().
2548 If StartSearchString is NULL, then ASSERT().
2549 If StopSearchString is NULL, then ASSERT().
2550
2551 @param FirstString Pointer to the first Null-terminated Unicode string.
2552 @param SecondString Pointer to the second Null-terminated Unicode string.
2553 @param StartSearchString Pointer to the Null-terminated Unicode string that
2554 marks the start of the value string to compare.
2555 @param StopSearchString Pointer to the Null-terminated Unicode string that
2556 marks the end of the value string to compare.
2557
2558 @retval FALSE StartSearchString is not present in FirstString.
2559 @retval FALSE StartSearchString is not present in SecondString.
2560 @retval FALSE StopSearchString is not present in FirstString.
2561 @retval FALSE StopSearchString is not present in SecondString.
2562 @retval FALSE The length of the substring in FirstString is not the
2563 same length as the substring in SecondString.
2564 @retval FALSE The value string in FirstString does not matche the
2565 value string in SecondString.
2566 @retval TRUE The value string in FirstString matches the value
2567 string in SecondString.
2568
2569 **/
2570 BOOLEAN
2571 EFIAPI
2572 InternalHiiCompareSubString (
2573 IN CHAR16 *FirstString,
2574 IN CHAR16 *SecondString,
2575 IN CHAR16 *StartSearchString,
2576 IN CHAR16 *StopSearchString
2577 )
2578 {
2579 CHAR16 *EndFirstString;
2580 CHAR16 *EndSecondString;
2581
2582 ASSERT (FirstString != NULL);
2583 ASSERT (SecondString != NULL);
2584 ASSERT (StartSearchString != NULL);
2585 ASSERT (StopSearchString != NULL);
2586
2587 FirstString = StrStr (FirstString, StartSearchString);
2588 if (FirstString == NULL) {
2589 return FALSE;
2590 }
2591
2592 SecondString = StrStr (SecondString, StartSearchString);
2593 if (SecondString == NULL) {
2594 return FALSE;
2595 }
2596
2597 EndFirstString = StrStr (FirstString, StopSearchString);
2598 if (EndFirstString == NULL) {
2599 return FALSE;
2600 }
2601
2602 EndSecondString = StrStr (SecondString, StopSearchString);
2603 if (EndSecondString == NULL) {
2604 return FALSE;
2605 }
2606
2607 if ((EndFirstString - FirstString) != (EndSecondString - SecondString)) {
2608 return FALSE;
2609 }
2610
2611 return (BOOLEAN)(StrnCmp (FirstString, SecondString, EndFirstString - FirstString) == 0);
2612 }
2613
2614 /**
2615 Determines if the routing data specified by GUID and NAME match a <ConfigHdr>.
2616
2617 If ConfigHdr is NULL, then ASSERT().
2618
2619 @param[in] ConfigHdr Either <ConfigRequest> or <ConfigResp>.
2620 @param[in] Guid GUID of the storage.
2621 @param[in] Name NAME of the storage.
2622
2623 @retval TRUE Routing information matches <ConfigHdr>.
2624 @retval FALSE Routing information does not match <ConfigHdr>.
2625
2626 **/
2627 BOOLEAN
2628 EFIAPI
2629 HiiIsConfigHdrMatch (
2630 IN CONST EFI_STRING ConfigHdr,
2631 IN CONST EFI_GUID *Guid, OPTIONAL
2632 IN CONST CHAR16 *Name OPTIONAL
2633 )
2634 {
2635 EFI_STRING CompareConfigHdr;
2636 BOOLEAN Result;
2637
2638 ASSERT (ConfigHdr != NULL);
2639
2640 //
2641 // Use Guid and Name to generate a <ConfigHdr> string
2642 //
2643 CompareConfigHdr = HiiConstructConfigHdr (Guid, Name, NULL);
2644 if (CompareConfigHdr == NULL) {
2645 return FALSE;
2646 }
2647
2648 Result = TRUE;
2649 if (Guid != NULL) {
2650 //
2651 // Compare GUID value strings
2652 //
2653 Result = InternalHiiCompareSubString (ConfigHdr, CompareConfigHdr, L"GUID=", L"&NAME=");
2654 }
2655
2656 if (Result && Name != NULL) {
2657 //
2658 // Compare NAME value strings
2659 //
2660 Result = InternalHiiCompareSubString (ConfigHdr, CompareConfigHdr, L"&NAME=", L"&PATH=");
2661 }
2662
2663 //
2664 // Free the <ConfigHdr> string
2665 //
2666 FreePool (CompareConfigHdr);
2667
2668 return Result;
2669 }
2670
2671 /**
2672 Retrieves uncommitted data from the Form Browser and converts it to a binary
2673 buffer.
2674
2675 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2676 parameter that may be NULL.
2677 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2678 is an optional parameter that may be NULL.
2679 @param[in] BufferSize Length in bytes of buffer to hold retrieved data.
2680 @param[out] Buffer Buffer of data to be updated.
2681
2682 @retval FALSE The uncommitted data could not be retrieved.
2683 @retval TRUE The uncommitted data was retrieved.
2684
2685 **/
2686 BOOLEAN
2687 EFIAPI
2688 HiiGetBrowserData (
2689 IN CONST EFI_GUID *VariableGuid, OPTIONAL
2690 IN CONST CHAR16 *VariableName, OPTIONAL
2691 IN UINTN BufferSize,
2692 OUT UINT8 *Buffer
2693 )
2694 {
2695 EFI_STRING ResultsData;
2696 UINTN Size;
2697 EFI_STRING ConfigResp;
2698 EFI_STATUS Status;
2699 CHAR16 *Progress;
2700
2701 //
2702 // Retrieve the results data from the Browser Callback
2703 //
2704 ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, NULL);
2705 if (ResultsData == NULL) {
2706 return FALSE;
2707 }
2708
2709 //
2710 // Construct <ConfigResp> mConfigHdrTemplate L'&' ResultsData L'\0'
2711 //
2712 Size = (StrLen (mConfigHdrTemplate) + 1) * sizeof (CHAR16);
2713 Size = Size + (StrLen (ResultsData) + 1) * sizeof (CHAR16);
2714 ConfigResp = AllocateZeroPool (Size);
2715 UnicodeSPrint (ConfigResp, Size, L"%s&%s", mConfigHdrTemplate, ResultsData);
2716
2717 //
2718 // Free the allocated buffer
2719 //
2720 FreePool (ResultsData);
2721 if (ConfigResp == NULL) {
2722 return FALSE;
2723 }
2724
2725 //
2726 // Convert <ConfigResp> to a buffer
2727 //
2728 Status = gHiiConfigRouting->ConfigToBlock (
2729 gHiiConfigRouting,
2730 ConfigResp,
2731 Buffer,
2732 &BufferSize,
2733 &Progress
2734 );
2735 //
2736 // Free the allocated buffer
2737 //
2738 FreePool (ConfigResp);
2739
2740 if (EFI_ERROR (Status)) {
2741 return FALSE;
2742 }
2743
2744 return TRUE;
2745 }
2746
2747 /**
2748 Updates uncommitted data in the Form Browser.
2749
2750 If Buffer is NULL, then ASSERT().
2751
2752 @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional
2753 parameter that may be NULL.
2754 @param[in] VariableName Pointer to a Null-terminated Unicode string. This
2755 is an optional parameter that may be NULL.
2756 @param[in] BufferSize Length, in bytes, of Buffer.
2757 @param[in] Buffer Buffer of data to commit.
2758 @param[in] RequestElement An optional field to specify which part of the
2759 buffer data will be send back to Browser. If NULL,
2760 the whole buffer of data will be committed to
2761 Browser.
2762 <RequestElement> ::= &OFFSET=<Number>&WIDTH=<Number>*
2763
2764 @retval FALSE The uncommitted data could not be updated.
2765 @retval TRUE The uncommitted data was updated.
2766
2767 **/
2768 BOOLEAN
2769 EFIAPI
2770 HiiSetBrowserData (
2771 IN CONST EFI_GUID *VariableGuid, OPTIONAL
2772 IN CONST CHAR16 *VariableName, OPTIONAL
2773 IN UINTN BufferSize,
2774 IN CONST UINT8 *Buffer,
2775 IN CONST CHAR16 *RequestElement OPTIONAL
2776 )
2777 {
2778 UINTN Size;
2779 EFI_STRING ConfigRequest;
2780 EFI_STRING ConfigResp;
2781 EFI_STRING ResultsData;
2782
2783 ASSERT (Buffer != NULL);
2784
2785 //
2786 // Construct <ConfigRequest>
2787 //
2788 if (RequestElement == NULL) {
2789 //
2790 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2791 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2792 //
2793 Size = (StrLen (mConfigHdrTemplate) + 32 + 1) * sizeof (CHAR16);
2794 ConfigRequest = AllocateZeroPool (Size);
2795 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate, (UINT64)BufferSize);
2796 } else {
2797 //
2798 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2799 // followed by <RequestElement> followed by a Null-terminator
2800 //
2801 Size = StrLen (mConfigHdrTemplate) * sizeof (CHAR16);
2802 Size = Size + (StrLen (RequestElement) + 1) * sizeof (CHAR16);
2803 ConfigRequest = AllocateZeroPool (Size);
2804 UnicodeSPrint (ConfigRequest, Size, L"%s%s", mConfigHdrTemplate, RequestElement);
2805 }
2806 if (ConfigRequest == NULL) {
2807 return FALSE;
2808 }
2809
2810 //
2811 // Convert <ConfigRequest> to <ConfigResp>
2812 //
2813 ConfigResp = InternalHiiBlockToConfig (ConfigRequest, Buffer, BufferSize);
2814 FreePool (ConfigRequest);
2815 if (ConfigResp == NULL) {
2816 return FALSE;
2817 }
2818
2819 //
2820 // Set data in the uncommitted browser state information
2821 //
2822 ResultsData = InternalHiiBrowserCallback (VariableGuid, VariableName, ConfigResp + StrLen(mConfigHdrTemplate) + 1);
2823 FreePool (ConfigResp);
2824
2825 return (BOOLEAN)(ResultsData != NULL);
2826 }
2827
2828 /////////////////////////////////////////
2829 /////////////////////////////////////////
2830 /// IFR Functions
2831 /////////////////////////////////////////
2832 /////////////////////////////////////////
2833
2834 #define HII_LIB_OPCODE_ALLOCATION_SIZE 0x200
2835
2836 typedef struct {
2837 UINT8 *Buffer;
2838 UINTN BufferSize;
2839 UINTN Position;
2840 } HII_LIB_OPCODE_BUFFER;
2841
2842 ///
2843 /// Lookup table that converts EFI_IFR_TYPE_X enum values to a width in bytes
2844 ///
2845 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 mHiiDefaultTypeToWidth[] = {
2846 1, // EFI_IFR_TYPE_NUM_SIZE_8
2847 2, // EFI_IFR_TYPE_NUM_SIZE_16
2848 4, // EFI_IFR_TYPE_NUM_SIZE_32
2849 8, // EFI_IFR_TYPE_NUM_SIZE_64
2850 1, // EFI_IFR_TYPE_BOOLEAN
2851 3, // EFI_IFR_TYPE_TIME
2852 4, // EFI_IFR_TYPE_DATE
2853 2 // EFI_IFR_TYPE_STRING
2854 };
2855
2856 /**
2857 Allocates and returns a new OpCode Handle. OpCode Handles must be freed with
2858 HiiFreeOpCodeHandle().
2859
2860 @retval NULL There are not enough resources to allocate a new OpCode Handle.
2861 @retval Other A new OpCode handle.
2862
2863 **/
2864 VOID *
2865 EFIAPI
2866 HiiAllocateOpCodeHandle (
2867 VOID
2868 )
2869 {
2870 HII_LIB_OPCODE_BUFFER *OpCodeBuffer;
2871
2872 OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)AllocatePool (sizeof (HII_LIB_OPCODE_BUFFER));
2873 if (OpCodeBuffer == NULL) {
2874 return NULL;
2875 }
2876 OpCodeBuffer->Buffer = (UINT8 *)AllocatePool (HII_LIB_OPCODE_ALLOCATION_SIZE);
2877 if (OpCodeBuffer->Buffer == NULL) {
2878 FreePool (OpCodeBuffer);
2879 return NULL;
2880 }
2881 OpCodeBuffer->BufferSize = HII_LIB_OPCODE_ALLOCATION_SIZE;
2882 OpCodeBuffer->Position = 0;
2883 return (VOID *)OpCodeBuffer;
2884 }
2885
2886 /**
2887 Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle().
2888 When an OpCode Handle is freed, all of the opcodes associated with the OpCode
2889 Handle are also freed.
2890
2891 If OpCodeHandle is NULL, then ASSERT().
2892
2893 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2894
2895 **/
2896 VOID
2897 EFIAPI
2898 HiiFreeOpCodeHandle (
2899 VOID *OpCodeHandle
2900 )
2901 {
2902 HII_LIB_OPCODE_BUFFER *OpCodeBuffer;
2903
2904 ASSERT (OpCodeHandle != NULL);
2905
2906 OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;
2907 if (OpCodeBuffer->Buffer != NULL) {
2908 FreePool (OpCodeBuffer->Buffer);
2909 }
2910 FreePool (OpCodeBuffer);
2911 }
2912
2913 /**
2914 Internal function gets the current position of opcode buffer.
2915
2916 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2917
2918 @return Current position of opcode buffer.
2919 **/
2920 UINTN
2921 EFIAPI
2922 InternalHiiOpCodeHandlePosition (
2923 IN VOID *OpCodeHandle
2924 )
2925 {
2926 return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Position;
2927 }
2928
2929 /**
2930 Internal function gets the start pointer of opcode buffer.
2931
2932 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2933
2934 @return Pointer to the opcode buffer base.
2935 **/
2936 UINT8 *
2937 EFIAPI
2938 InternalHiiOpCodeHandleBuffer (
2939 IN VOID *OpCodeHandle
2940 )
2941 {
2942 return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Buffer;
2943 }
2944
2945 /**
2946 Internal function reserves the enough buffer for current opcode.
2947 When the buffer is not enough, Opcode buffer will be extended.
2948
2949 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2950 @param[in] Size Size of current opcode.
2951
2952 @return Pointer to the current opcode.
2953 **/
2954 UINT8 *
2955 EFIAPI
2956 InternalHiiGrowOpCodeHandle (
2957 IN VOID *OpCodeHandle,
2958 IN UINTN Size
2959 )
2960 {
2961 HII_LIB_OPCODE_BUFFER *OpCodeBuffer;
2962 UINT8 *Buffer;
2963
2964 ASSERT (OpCodeHandle != NULL);
2965
2966 OpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)OpCodeHandle;
2967 if (OpCodeBuffer->Position + Size > OpCodeBuffer->BufferSize) {
2968 Buffer = ReallocatePool (
2969 OpCodeBuffer->BufferSize,
2970 OpCodeBuffer->BufferSize + (Size + HII_LIB_OPCODE_ALLOCATION_SIZE),
2971 OpCodeBuffer->Buffer
2972 );
2973 ASSERT (Buffer != NULL);
2974 OpCodeBuffer->Buffer = Buffer;
2975 OpCodeBuffer->BufferSize += (Size + HII_LIB_OPCODE_ALLOCATION_SIZE);
2976 }
2977 Buffer = OpCodeBuffer->Buffer + OpCodeBuffer->Position;
2978 OpCodeBuffer->Position += Size;
2979 return Buffer;
2980 }
2981
2982 /**
2983 Internal function creates opcode based on the template opcode.
2984
2985 @param[in] OpCodeHandle Handle to the buffer of opcodes.
2986 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
2987 @param[in] OpCode OpCode IFR value.
2988 @param[in] OpCodeSize Size of opcode.
2989 @param[in] ExtensionSize Size of extended opcode.
2990 @param[in] Scope Scope bit of opcode.
2991
2992 @return Pointer to the current opcode with opcode data.
2993 **/
2994 UINT8 *
2995 EFIAPI
2996 InternalHiiCreateOpCodeExtended (
2997 IN VOID *OpCodeHandle,
2998 IN VOID *OpCodeTemplate,
2999 IN UINT8 OpCode,
3000 IN UINTN OpCodeSize,
3001 IN UINTN ExtensionSize,
3002 IN UINT8 Scope
3003 )
3004 {
3005 EFI_IFR_OP_HEADER *Header;
3006 UINT8 *Buffer;
3007
3008 ASSERT (OpCodeTemplate != NULL);
3009 ASSERT ((OpCodeSize + ExtensionSize) <= 0x7F);
3010
3011 Header = (EFI_IFR_OP_HEADER *)OpCodeTemplate;
3012 Header->OpCode = OpCode;
3013 Header->Scope = Scope;
3014 Header->Length = (UINT8)(OpCodeSize + ExtensionSize);
3015 Buffer = InternalHiiGrowOpCodeHandle (OpCodeHandle, Header->Length);
3016 return (UINT8 *)CopyMem (Buffer, Header, OpCodeSize);
3017 }
3018
3019 /**
3020 Internal function creates opcode based on the template opcode for the normal opcode.
3021
3022 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3023 @param[in] OpCodeTemplate Pointer to the template buffer of opcode.
3024 @param[in] OpCode OpCode IFR value.
3025 @param[in] OpCodeSize Size of opcode.
3026
3027 @return Pointer to the current opcode with opcode data.
3028 **/
3029 UINT8 *
3030 EFIAPI
3031 InternalHiiCreateOpCode (
3032 IN VOID *OpCodeHandle,
3033 IN VOID *OpCodeTemplate,
3034 IN UINT8 OpCode,
3035 IN UINTN OpCodeSize
3036 )
3037 {
3038 return InternalHiiCreateOpCodeExtended (OpCodeHandle, OpCodeTemplate, OpCode, OpCodeSize, 0, 0);
3039 }
3040
3041 /**
3042 Append raw opcodes to an OpCodeHandle.
3043
3044 If OpCodeHandle is NULL, then ASSERT().
3045 If RawBuffer is NULL, then ASSERT();
3046
3047 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3048 @param[in] RawBuffer Buffer of opcodes to append.
3049 @param[in] RawBufferSize The size, in bytes, of Buffer.
3050
3051 @retval NULL There is not enough space left in Buffer to add the opcode.
3052 @retval Other A pointer to the appended opcodes.
3053
3054 **/
3055 UINT8 *
3056 EFIAPI
3057 HiiCreateRawOpCodes (
3058 IN VOID *OpCodeHandle,
3059 IN UINT8 *RawBuffer,
3060 IN UINTN RawBufferSize
3061 )
3062 {
3063 UINT8 *Buffer;
3064
3065 ASSERT (RawBuffer != NULL);
3066
3067 Buffer = InternalHiiGrowOpCodeHandle (OpCodeHandle, RawBufferSize);
3068 return (UINT8 *)CopyMem (Buffer, RawBuffer, RawBufferSize);
3069 }
3070
3071 /**
3072 Append opcodes from one OpCode Handle to another OpCode handle.
3073
3074 If OpCodeHandle is NULL, then ASSERT().
3075 If RawOpCodeHandle is NULL, then ASSERT();
3076
3077 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3078 @param[in] RawOpCodeHandle Handle to the buffer of opcodes.
3079
3080 @retval NULL There is not enough space left in Buffer to add the opcode.
3081 @retval Other A pointer to the appended opcodes.
3082
3083 **/
3084 UINT8 *
3085 EFIAPI
3086 InternalHiiAppendOpCodes (
3087 IN VOID *OpCodeHandle,
3088 IN VOID *RawOpCodeHandle
3089 )
3090 {
3091 HII_LIB_OPCODE_BUFFER *RawOpCodeBuffer;
3092
3093 ASSERT (RawOpCodeHandle != NULL);
3094
3095 RawOpCodeBuffer = (HII_LIB_OPCODE_BUFFER *)RawOpCodeHandle;
3096 return HiiCreateRawOpCodes (OpCodeHandle, RawOpCodeBuffer->Buffer, RawOpCodeBuffer->Position);
3097 }
3098
3099 /**
3100 Create EFI_IFR_END_OP opcode.
3101
3102 If OpCodeHandle is NULL, then ASSERT().
3103
3104 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3105
3106 @retval NULL There is not enough space left in Buffer to add the opcode.
3107 @retval Other A pointer to the created opcode.
3108
3109 **/
3110 UINT8 *
3111 EFIAPI
3112 HiiCreateEndOpCode (
3113 IN VOID *OpCodeHandle
3114 )
3115 {
3116 EFI_IFR_END OpCode;
3117
3118 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_END_OP, sizeof (OpCode));
3119 }
3120
3121 /**
3122 Create EFI_IFR_ONE_OF_OPTION_OP opcode.
3123
3124 If OpCodeHandle is NULL, then ASSERT().
3125 If Type is invalid, then ASSERT().
3126 If Flags is invalid, then ASSERT().
3127
3128 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3129 @param[in] StringId StringId for the option
3130 @param[in] Flags Flags for the option
3131 @param[in] Type Type for the option
3132 @param[in] Value Value for the option
3133
3134 @retval NULL There is not enough space left in Buffer to add the opcode.
3135 @retval Other A pointer to the created opcode.
3136
3137 **/
3138 UINT8 *
3139 EFIAPI
3140 HiiCreateOneOfOptionOpCode (
3141 IN VOID *OpCodeHandle,
3142 IN UINT16 StringId,
3143 IN UINT8 Flags,
3144 IN UINT8 Type,
3145 IN UINT64 Value
3146 )
3147 {
3148 EFI_IFR_ONE_OF_OPTION OpCode;
3149
3150 ASSERT (Type < EFI_IFR_TYPE_OTHER);
3151
3152 ZeroMem (&OpCode, sizeof (OpCode));
3153 OpCode.Option = StringId;
3154 OpCode.Flags = (UINT8) (Flags & (EFI_IFR_OPTION_DEFAULT | EFI_IFR_OPTION_DEFAULT_MFG));
3155 OpCode.Type = Type;
3156 CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]);
3157
3158 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, OFFSET_OF(EFI_IFR_ONE_OF_OPTION, Value) + mHiiDefaultTypeToWidth[Type]);
3159 }
3160
3161 /**
3162 Create EFI_IFR_DEFAULT_OP opcode.
3163
3164 If OpCodeHandle is NULL, then ASSERT().
3165 If Type is invalid, then ASSERT().
3166
3167 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3168 @param[in] DefaultId DefaultId for the default
3169 @param[in] Type Type for the default
3170 @param[in] Value Value for the default
3171
3172 @retval NULL There is not enough space left in Buffer to add the opcode.
3173 @retval Other A pointer to the created opcode.
3174
3175 **/
3176 UINT8 *
3177 EFIAPI
3178 HiiCreateDefaultOpCode (
3179 IN VOID *OpCodeHandle,
3180 IN UINT16 DefaultId,
3181 IN UINT8 Type,
3182 IN UINT64 Value
3183 )
3184 {
3185 EFI_IFR_DEFAULT OpCode;
3186
3187 ASSERT (Type < EFI_IFR_TYPE_OTHER);
3188
3189 ZeroMem (&OpCode, sizeof (OpCode));
3190 OpCode.Type = Type;
3191 OpCode.DefaultId = DefaultId;
3192 CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]);
3193
3194 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, OFFSET_OF(EFI_IFR_DEFAULT, Value) + mHiiDefaultTypeToWidth[Type]);
3195 }
3196
3197 /**
3198 Create EFI_IFR_GUID opcode.
3199
3200 If OpCodeHandle is NULL, then ASSERT().
3201 If Guid is NULL, then ASSERT().
3202 If OpCodeSize < sizeof (EFI_IFR_GUID), then ASSERT().
3203
3204 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3205 @param[in] Guid Pointer to EFI_GUID of this guided opcode.
3206 @param[in] GuidOpCode Pointer to an EFI_IFR_GUID opcode. This is an
3207 optional parameter that may be NULL. If this
3208 parameter is NULL, then the GUID extension
3209 region of the created opcode is filled with zeros.
3210 If this parameter is not NULL, then the GUID
3211 extension region of GuidData will be copied to
3212 the GUID extension region of the created opcode.
3213 @param[in] OpCodeSize The size, in bytes, of created opcode. This value
3214 must be >= sizeof(EFI_IFR_GUID).
3215
3216 @retval NULL There is not enough space left in Buffer to add the opcode.
3217 @retval Other A pointer to the created opcode.
3218
3219 **/
3220 UINT8 *
3221 EFIAPI
3222 HiiCreateGuidOpCode (
3223 IN VOID *OpCodeHandle,
3224 IN CONST EFI_GUID *Guid,
3225 IN CONST VOID *GuidOpCode, OPTIONAL
3226 IN UINTN OpCodeSize
3227 )
3228 {
3229 EFI_IFR_GUID OpCode;
3230 EFI_IFR_GUID *OpCodePointer;
3231
3232 ASSERT (Guid != NULL);
3233 ASSERT (OpCodeSize >= sizeof (OpCode));
3234
3235 ZeroMem (&OpCode, sizeof (OpCode));
3236 CopyGuid ((EFI_GUID *)(VOID *)&OpCode.Guid, Guid);
3237
3238 OpCodePointer = (EFI_IFR_GUID *)InternalHiiCreateOpCodeExtended (
3239 OpCodeHandle,
3240 &OpCode,
3241 EFI_IFR_GUID_OP,
3242 sizeof (OpCode),
3243 OpCodeSize - sizeof (OpCode),
3244 0
3245 );
3246 if (OpCodePointer != NULL && GuidOpCode != NULL) {
3247 CopyMem (OpCodePointer + 1, (EFI_IFR_GUID *)GuidOpCode + 1, OpCodeSize - sizeof (OpCode));
3248 }
3249 return (UINT8 *)OpCodePointer;
3250 }
3251
3252 /**
3253 Create EFI_IFR_ACTION_OP opcode.
3254
3255 If OpCodeHandle is NULL, then ASSERT().
3256 If any reserved bits are set in QuestionFlags, then ASSERT().
3257
3258 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3259 @param[in] QuestionId Question ID
3260 @param[in] Prompt String ID for Prompt
3261 @param[in] Help String ID for Help
3262 @param[in] QuestionFlags Flags in Question Header
3263 @param[in] QuestionConfig String ID for configuration
3264
3265 @retval NULL There is not enough space left in Buffer to add the opcode.
3266 @retval Other A pointer to the created opcode.
3267
3268 **/
3269 UINT8 *
3270 EFIAPI
3271 HiiCreateActionOpCode (
3272 IN VOID *OpCodeHandle,
3273 IN EFI_QUESTION_ID QuestionId,
3274 IN EFI_STRING_ID Prompt,
3275 IN EFI_STRING_ID Help,
3276 IN UINT8 QuestionFlags,
3277 IN EFI_STRING_ID QuestionConfig
3278 )
3279 {
3280 EFI_IFR_ACTION OpCode;
3281
3282 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3283
3284 ZeroMem (&OpCode, sizeof (OpCode));
3285 OpCode.Question.QuestionId = QuestionId;
3286 OpCode.Question.Header.Prompt = Prompt;
3287 OpCode.Question.Header.Help = Help;
3288 OpCode.Question.Flags = QuestionFlags;
3289 OpCode.QuestionConfig = QuestionConfig;
3290
3291 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ACTION_OP, sizeof (OpCode));
3292 }
3293
3294 /**
3295 Create EFI_IFR_SUBTITLE_OP opcode.
3296
3297 If OpCodeHandle is NULL, then ASSERT().
3298 If any reserved bits are set in Flags, then ASSERT().
3299 If Scope > 1, then ASSERT().
3300
3301 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3302 @param[in] Prompt String ID for Prompt
3303 @param[in] Help String ID for Help
3304 @param[in] Flags Subtitle opcode flags
3305 @param[in] Scope 1 if this opcpde is the beginning of a new scope.
3306 0 if this opcode is within the current scope.
3307
3308 @retval NULL There is not enough space left in Buffer to add the opcode.
3309 @retval Other A pointer to the created opcode.
3310
3311 **/
3312 UINT8 *
3313 EFIAPI
3314 HiiCreateSubTitleOpCode (
3315 IN VOID *OpCodeHandle,
3316 IN EFI_STRING_ID Prompt,
3317 IN EFI_STRING_ID Help,
3318 IN UINT8 Flags,
3319 IN UINT8 Scope
3320 )
3321 {
3322 EFI_IFR_SUBTITLE OpCode;
3323
3324 ASSERT (Scope <= 1);
3325 ASSERT ((Flags & (~(EFI_IFR_FLAGS_HORIZONTAL))) == 0);
3326
3327 ZeroMem (&OpCode, sizeof (OpCode));
3328 OpCode.Statement.Prompt = Prompt;
3329 OpCode.Statement.Help = Help;
3330 OpCode.Flags = Flags;
3331
3332 return InternalHiiCreateOpCodeExtended (
3333 OpCodeHandle,
3334 &OpCode,
3335 EFI_IFR_SUBTITLE_OP,
3336 sizeof (OpCode),
3337 0,
3338 Scope
3339 );
3340 }
3341
3342 /**
3343 Create EFI_IFR_REF_OP opcode.
3344
3345 If OpCodeHandle is NULL, then ASSERT().
3346 If any reserved bits are set in QuestionFlags, then ASSERT().
3347
3348 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3349 @param[in] FormId Destination Form ID
3350 @param[in] Prompt String ID for Prompt
3351 @param[in] Help String ID for Help
3352 @param[in] QuestionFlags Flags in Question Header
3353 @param[in] QuestionId Question ID
3354
3355 @retval NULL There is not enough space left in Buffer to add the opcode.
3356 @retval Other A pointer to the created opcode.
3357
3358 **/
3359 UINT8 *
3360 EFIAPI
3361 HiiCreateGotoOpCode (
3362 IN VOID *OpCodeHandle,
3363 IN EFI_FORM_ID FormId,
3364 IN EFI_STRING_ID Prompt,
3365 IN EFI_STRING_ID Help,
3366 IN UINT8 QuestionFlags,
3367 IN EFI_QUESTION_ID QuestionId
3368 )
3369 {
3370 EFI_IFR_REF OpCode;
3371
3372 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3373
3374 ZeroMem (&OpCode, sizeof (OpCode));
3375 OpCode.Question.Header.Prompt = Prompt;
3376 OpCode.Question.Header.Help = Help;
3377 OpCode.Question.QuestionId = QuestionId;
3378 OpCode.Question.Flags = QuestionFlags;
3379 OpCode.FormId = FormId;
3380
3381 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, sizeof (OpCode));
3382 }
3383
3384 /**
3385 Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode.
3386
3387 When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created.
3388 When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created.
3389 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created.
3390 When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created.
3391
3392 If OpCodeHandle is NULL, then ASSERT().
3393 If any reserved bits are set in QuestionFlags, then ASSERT().
3394
3395 @param[in] OpCodeHandle The handle to the buffer of opcodes.
3396 @param[in] RefFormId The Destination Form ID.
3397 @param[in] Prompt The string ID for Prompt.
3398 @param[in] Help The string ID for Help.
3399 @param[in] QuestionFlags The flags in Question Header
3400 @param[in] QuestionId Question ID.
3401 @param[in] RefQuestionId The question on the form to which this link is referring.
3402 If its value is zero, then the link refers to the top of the form.
3403 @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is
3404 zero, then the link is to the current form set.
3405 @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of
3406 the device path to which the form set containing the form specified by FormId.
3407 If its value is zero, then the link refers to the current page.
3408
3409 @retval NULL There is not enough space left in Buffer to add the opcode.
3410 @retval Other A pointer to the created opcode.
3411
3412 **/
3413 UINT8 *
3414 EFIAPI
3415 HiiCreateGotoExOpCode (
3416 IN VOID *OpCodeHandle,
3417 IN EFI_FORM_ID RefFormId,
3418 IN EFI_STRING_ID Prompt,
3419 IN EFI_STRING_ID Help,
3420 IN UINT8 QuestionFlags,
3421 IN EFI_QUESTION_ID QuestionId,
3422 IN EFI_QUESTION_ID RefQuestionId,
3423 IN EFI_GUID *RefFormSetId, OPTIONAL
3424 IN EFI_STRING_ID RefDevicePath
3425 )
3426 {
3427 EFI_IFR_REF4 OpCode;
3428 UINTN OpCodeSize;
3429
3430 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3431
3432 ZeroMem (&OpCode, sizeof (OpCode));
3433 OpCode.Question.Header.Prompt = Prompt;
3434 OpCode.Question.Header.Help = Help;
3435 OpCode.Question.QuestionId = QuestionId;
3436 OpCode.Question.Flags = QuestionFlags;
3437 OpCode.FormId = RefFormId;
3438 OpCode.QuestionId = RefQuestionId;
3439 OpCode.DevicePath = RefDevicePath;
3440 if (RefFormSetId != NULL) {
3441 CopyMem (&OpCode.FormSetId, RefFormSetId, sizeof (OpCode.FormSetId));
3442 }
3443
3444 //
3445 // Cacluate OpCodeSize based on the input Ref value.
3446 // Try to use the small OpCode to save size.
3447 //
3448 OpCodeSize = sizeof (EFI_IFR_REF);
3449 if (RefDevicePath != 0) {
3450 OpCodeSize = sizeof (EFI_IFR_REF4);
3451 } else if (RefFormSetId != NULL) {
3452 OpCodeSize = sizeof (EFI_IFR_REF3);
3453 } else if (RefQuestionId != 0) {
3454 OpCodeSize = sizeof (EFI_IFR_REF2);
3455 }
3456
3457 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, OpCodeSize);
3458 }
3459
3460 /**
3461 Create EFI_IFR_CHECKBOX_OP opcode.
3462
3463 If OpCodeHandle is NULL, then ASSERT().
3464 If any reserved bits are set in QuestionFlags, then ASSERT().
3465 If any reserved bits are set in CheckBoxFlags, then ASSERT().
3466
3467 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3468 @param[in] QuestionId Question ID
3469 @param[in] VarStoreId Storage ID
3470 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3471 for this name/value pair.
3472 @param[in] Prompt String ID for Prompt
3473 @param[in] Help String ID for Help
3474 @param[in] QuestionFlags Flags in Question Header
3475 @param[in] CheckBoxFlags Flags for checkbox opcode
3476 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3477 is an optional parameter that may be NULL.
3478
3479 @retval NULL There is not enough space left in Buffer to add the opcode.
3480 @retval Other A pointer to the created opcode.
3481
3482 **/
3483 UINT8 *
3484 EFIAPI
3485 HiiCreateCheckBoxOpCode (
3486 IN VOID *OpCodeHandle,
3487 IN EFI_QUESTION_ID QuestionId,
3488 IN EFI_VARSTORE_ID VarStoreId,
3489 IN UINT16 VarOffset,
3490 IN EFI_STRING_ID Prompt,
3491 IN EFI_STRING_ID Help,
3492 IN UINT8 QuestionFlags,
3493 IN UINT8 CheckBoxFlags,
3494 IN VOID *DefaultsOpCodeHandle OPTIONAL
3495 )
3496 {
3497 EFI_IFR_CHECKBOX OpCode;
3498 UINTN Position;
3499
3500 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3501
3502 ZeroMem (&OpCode, sizeof (OpCode));
3503 OpCode.Question.QuestionId = QuestionId;
3504 OpCode.Question.VarStoreId = VarStoreId;
3505 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3506 OpCode.Question.Header.Prompt = Prompt;
3507 OpCode.Question.Header.Help = Help;
3508 OpCode.Question.Flags = QuestionFlags;
3509 OpCode.Flags = CheckBoxFlags;
3510
3511 if (DefaultsOpCodeHandle == NULL) {
3512 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_CHECKBOX_OP, sizeof (OpCode));
3513 }
3514
3515 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3516 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_CHECKBOX_OP, sizeof (OpCode), 0, 1);
3517 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3518 HiiCreateEndOpCode (OpCodeHandle);
3519 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3520 }
3521
3522 /**
3523 Create EFI_IFR_NUMERIC_OP opcode.
3524
3525 If OpCodeHandle is NULL, then ASSERT().
3526 If any reserved bits are set in QuestionFlags, then ASSERT().
3527 If any reserved bits are set in NumericFlags, then ASSERT().
3528
3529 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3530 @param[in] QuestionId Question ID
3531 @param[in] VarStoreId Storage ID
3532 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3533 for this name/value pair.
3534 @param[in] Prompt String ID for Prompt
3535 @param[in] Help String ID for Help
3536 @param[in] QuestionFlags Flags in Question Header
3537 @param[in] NumericFlags Flags for numeric opcode
3538 @param[in] Minimum Numeric minimum value
3539 @param[in] Maximum Numeric maximum value
3540 @param[in] Step Numeric step for edit
3541 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3542 is an optional parameter that may be NULL.
3543
3544 @retval NULL There is not enough space left in Buffer to add the opcode.
3545 @retval Other A pointer to the created opcode.
3546
3547 **/
3548 UINT8 *
3549 EFIAPI
3550 HiiCreateNumericOpCode (
3551 IN VOID *OpCodeHandle,
3552 IN EFI_QUESTION_ID QuestionId,
3553 IN EFI_VARSTORE_ID VarStoreId,
3554 IN UINT16 VarOffset,
3555 IN EFI_STRING_ID Prompt,
3556 IN EFI_STRING_ID Help,
3557 IN UINT8 QuestionFlags,
3558 IN UINT8 NumericFlags,
3559 IN UINT64 Minimum,
3560 IN UINT64 Maximum,
3561 IN UINT64 Step,
3562 IN VOID *DefaultsOpCodeHandle OPTIONAL
3563 )
3564 {
3565 EFI_IFR_NUMERIC OpCode;
3566 UINTN Position;
3567 UINTN Length;
3568
3569 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3570
3571 Length = 0;
3572 ZeroMem (&OpCode, sizeof (OpCode));
3573 OpCode.Question.QuestionId = QuestionId;
3574 OpCode.Question.VarStoreId = VarStoreId;
3575 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3576 OpCode.Question.Header.Prompt = Prompt;
3577 OpCode.Question.Header.Help = Help;
3578 OpCode.Question.Flags = QuestionFlags;
3579 OpCode.Flags = NumericFlags;
3580
3581 switch (NumericFlags & EFI_IFR_NUMERIC_SIZE) {
3582 case EFI_IFR_NUMERIC_SIZE_1:
3583 OpCode.data.u8.MinValue = (UINT8)Minimum;
3584 OpCode.data.u8.MaxValue = (UINT8)Maximum;
3585 OpCode.data.u8.Step = (UINT8)Step;
3586 Length = 3;
3587 break;
3588
3589 case EFI_IFR_NUMERIC_SIZE_2:
3590 OpCode.data.u16.MinValue = (UINT16)Minimum;
3591 OpCode.data.u16.MaxValue = (UINT16)Maximum;
3592 OpCode.data.u16.Step = (UINT16)Step;
3593 Length = 6;
3594 break;
3595
3596 case EFI_IFR_NUMERIC_SIZE_4:
3597 OpCode.data.u32.MinValue = (UINT32)Minimum;
3598 OpCode.data.u32.MaxValue = (UINT32)Maximum;
3599 OpCode.data.u32.Step = (UINT32)Step;
3600 Length = 12;
3601 break;
3602
3603 case EFI_IFR_NUMERIC_SIZE_8:
3604 OpCode.data.u64.MinValue = Minimum;
3605 OpCode.data.u64.MaxValue = Maximum;
3606 OpCode.data.u64.Step = Step;
3607 Length = 24;
3608 break;
3609 }
3610
3611 Length += OFFSET_OF (EFI_IFR_NUMERIC, data);
3612
3613 if (DefaultsOpCodeHandle == NULL) {
3614 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length);
3615 }
3616
3617 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3618 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length, 0, 1);
3619 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3620 HiiCreateEndOpCode (OpCodeHandle);
3621 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3622 }
3623
3624 /**
3625 Create EFI_IFR_STRING_OP opcode.
3626
3627 If OpCodeHandle is NULL, then ASSERT().
3628 If any reserved bits are set in QuestionFlags, then ASSERT().
3629 If any reserved bits are set in StringFlags, then ASSERT().
3630
3631 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3632 @param[in] QuestionId Question ID
3633 @param[in] VarStoreId Storage ID
3634 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3635 for this name/value pair.
3636 @param[in] Prompt String ID for Prompt
3637 @param[in] Help String ID for Help
3638 @param[in] QuestionFlags Flags in Question Header
3639 @param[in] StringFlags Flags for string opcode
3640 @param[in] MinSize String minimum length
3641 @param[in] MaxSize String maximum length
3642 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3643 is an optional parameter that may be NULL.
3644
3645 @retval NULL There is not enough space left in Buffer to add the opcode.
3646 @retval Other A pointer to the created opcode.
3647
3648 **/
3649 UINT8 *
3650 EFIAPI
3651 HiiCreateStringOpCode (
3652 IN VOID *OpCodeHandle,
3653 IN EFI_QUESTION_ID QuestionId,
3654 IN EFI_VARSTORE_ID VarStoreId,
3655 IN UINT16 VarOffset,
3656 IN EFI_STRING_ID Prompt,
3657 IN EFI_STRING_ID Help,
3658 IN UINT8 QuestionFlags,
3659 IN UINT8 StringFlags,
3660 IN UINT8 MinSize,
3661 IN UINT8 MaxSize,
3662 IN VOID *DefaultsOpCodeHandle OPTIONAL
3663 )
3664 {
3665 EFI_IFR_STRING OpCode;
3666 UINTN Position;
3667
3668 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3669
3670 ZeroMem (&OpCode, sizeof (OpCode));
3671 OpCode.Question.Header.Prompt = Prompt;
3672 OpCode.Question.Header.Help = Help;
3673 OpCode.Question.QuestionId = QuestionId;
3674 OpCode.Question.VarStoreId = VarStoreId;
3675 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3676 OpCode.Question.Flags = QuestionFlags;
3677 OpCode.MinSize = MinSize;
3678 OpCode.MaxSize = MaxSize;
3679 OpCode.Flags = (UINT8) (StringFlags & EFI_IFR_STRING_MULTI_LINE);
3680
3681 if (DefaultsOpCodeHandle == NULL) {
3682 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_STRING_OP, sizeof (OpCode));
3683 }
3684
3685 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3686 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_STRING_OP, sizeof (OpCode), 0, 1);
3687 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3688 HiiCreateEndOpCode (OpCodeHandle);
3689 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3690 }
3691
3692 /**
3693 Create EFI_IFR_ONE_OF_OP opcode.
3694
3695 If OpCodeHandle is NULL, then ASSERT().
3696 If any reserved bits are set in QuestionFlags, then ASSERT().
3697 If any reserved bits are set in OneOfFlags, then ASSERT().
3698
3699 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3700 @param[in] QuestionId Question ID
3701 @param[in] VarStoreId Storage ID
3702 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3703 for this name/value pair.
3704 @param[in] Prompt String ID for Prompt
3705 @param[in] Help String ID for Help
3706 @param[in] QuestionFlags Flags in Question Header
3707 @param[in] OneOfFlags Flags for oneof opcode
3708 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3709 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3710 is an optional parameter that may be NULL.
3711
3712 @retval NULL There is not enough space left in Buffer to add the opcode.
3713 @retval Other A pointer to the created opcode.
3714
3715 **/
3716 UINT8 *
3717 EFIAPI
3718 HiiCreateOneOfOpCode (
3719 IN VOID *OpCodeHandle,
3720 IN EFI_QUESTION_ID QuestionId,
3721 IN EFI_VARSTORE_ID VarStoreId,
3722 IN UINT16 VarOffset,
3723 IN EFI_STRING_ID Prompt,
3724 IN EFI_STRING_ID Help,
3725 IN UINT8 QuestionFlags,
3726 IN UINT8 OneOfFlags,
3727 IN VOID *OptionsOpCodeHandle,
3728 IN VOID *DefaultsOpCodeHandle OPTIONAL
3729 )
3730 {
3731 EFI_IFR_ONE_OF OpCode;
3732 UINTN Position;
3733 UINTN Length;
3734
3735 ASSERT (OptionsOpCodeHandle != NULL);
3736 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);
3737
3738 ZeroMem (&OpCode, sizeof (OpCode));
3739 OpCode.Question.Header.Prompt = Prompt;
3740 OpCode.Question.Header.Help = Help;
3741 OpCode.Question.QuestionId = QuestionId;
3742 OpCode.Question.VarStoreId = VarStoreId;
3743 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3744 OpCode.Question.Flags = QuestionFlags;
3745 OpCode.Flags = OneOfFlags;
3746
3747 Length = OFFSET_OF (EFI_IFR_ONE_OF, data);
3748 Length += (1 << (OneOfFlags & EFI_IFR_NUMERIC_SIZE)) * 3;
3749
3750 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3751 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, Length, 0, 1);
3752 InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle);
3753 if (DefaultsOpCodeHandle != NULL) {
3754 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3755 }
3756 HiiCreateEndOpCode (OpCodeHandle);
3757 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3758 }
3759
3760 /**
3761 Create EFI_IFR_ORDERED_LIST_OP opcode.
3762
3763 If OpCodeHandle is NULL, then ASSERT().
3764 If any reserved bits are set in QuestionFlags, then ASSERT().
3765 If any reserved bits are set in OrderedListFlags, then ASSERT().
3766
3767 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3768 @param[in] QuestionId Question ID
3769 @param[in] VarStoreId Storage ID
3770 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3771 for this name/value pair.
3772 @param[in] Prompt String ID for Prompt
3773 @param[in] Help String ID for Help
3774 @param[in] QuestionFlags Flags in Question Header
3775 @param[in] OrderedListFlags Flags for ordered list opcode
3776 @param[in] DataType Type for option value
3777 @param[in] MaxContainers Maximum count for options in this ordered list
3778 @param[in] OptionsOpCodeHandle Handle for a buffer of ONE_OF_OPTION opcodes.
3779 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3780 is an optional parameter that may be NULL.
3781
3782 @retval NULL There is not enough space left in Buffer to add the opcode.
3783 @retval Other A pointer to the created opcode.
3784
3785 **/
3786 UINT8 *
3787 EFIAPI
3788 HiiCreateOrderedListOpCode (
3789 IN VOID *OpCodeHandle,
3790 IN EFI_QUESTION_ID QuestionId,
3791 IN EFI_VARSTORE_ID VarStoreId,
3792 IN UINT16 VarOffset,
3793 IN EFI_STRING_ID Prompt,
3794 IN EFI_STRING_ID Help,
3795 IN UINT8 QuestionFlags,
3796 IN UINT8 OrderedListFlags,
3797 IN UINT8 DataType,
3798 IN UINT8 MaxContainers,
3799 IN VOID *OptionsOpCodeHandle,
3800 IN VOID *DefaultsOpCodeHandle OPTIONAL
3801 )
3802 {
3803 EFI_IFR_ORDERED_LIST OpCode;
3804 UINTN Position;
3805
3806 ASSERT (OptionsOpCodeHandle != NULL);
3807 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0);
3808
3809 ZeroMem (&OpCode, sizeof (OpCode));
3810 OpCode.Question.Header.Prompt = Prompt;
3811 OpCode.Question.Header.Help = Help;
3812 OpCode.Question.QuestionId = QuestionId;
3813 OpCode.Question.VarStoreId = VarStoreId;
3814 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3815 OpCode.Question.Flags = QuestionFlags;
3816 OpCode.MaxContainers = MaxContainers;
3817 OpCode.Flags = OrderedListFlags;
3818
3819 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3820 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ORDERED_LIST_OP, sizeof (OpCode), 0, 1);
3821 InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle);
3822 if (DefaultsOpCodeHandle != NULL) {
3823 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3824 }
3825 HiiCreateEndOpCode (OpCodeHandle);
3826 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3827 }
3828
3829 /**
3830 Create EFI_IFR_TEXT_OP opcode.
3831
3832 If OpCodeHandle is NULL, then ASSERT().
3833
3834 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3835 @param[in] Prompt String ID for Prompt.
3836 @param[in] Help String ID for Help.
3837 @param[in] TextTwo String ID for TextTwo.
3838
3839 @retval NULL There is not enough space left in Buffer to add the opcode.
3840 @retval Other A pointer to the created opcode.
3841
3842 **/
3843 UINT8 *
3844 EFIAPI
3845 HiiCreateTextOpCode (
3846 IN VOID *OpCodeHandle,
3847 IN EFI_STRING_ID Prompt,
3848 IN EFI_STRING_ID Help,
3849 IN EFI_STRING_ID TextTwo
3850 )
3851 {
3852 EFI_IFR_TEXT OpCode;
3853
3854 ZeroMem (&OpCode, sizeof (OpCode));
3855 OpCode.Statement.Prompt = Prompt;
3856 OpCode.Statement.Help = Help;
3857 OpCode.TextTwo = TextTwo;
3858
3859 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_TEXT_OP, sizeof (OpCode));
3860 }
3861
3862 /**
3863 Create EFI_IFR_DATE_OP opcode.
3864
3865 If OpCodeHandle is NULL, then ASSERT().
3866 If any reserved bits are set in QuestionFlags, then ASSERT().
3867 If any reserved bits are set in DateFlags, then ASSERT().
3868
3869 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3870 @param[in] QuestionId Question ID
3871 @param[in] VarStoreId Storage ID, optional. If DateFlags is not
3872 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3873 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3874 for this name/value pair, optional. If DateFlags is not
3875 QF_DATE_STORAGE_NORMAL, this parameter is ignored.
3876 @param[in] Prompt String ID for Prompt
3877 @param[in] Help String ID for Help
3878 @param[in] QuestionFlags Flags in Question Header
3879 @param[in] DateFlags Flags for date opcode
3880 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3881 is an optional parameter that may be NULL.
3882
3883 @retval NULL There is not enough space left in Buffer to add the opcode.
3884 @retval Other A pointer to the created opcode.
3885
3886 **/
3887 UINT8 *
3888 EFIAPI
3889 HiiCreateDateOpCode (
3890 IN VOID *OpCodeHandle,
3891 IN EFI_QUESTION_ID QuestionId,
3892 IN EFI_VARSTORE_ID VarStoreId, OPTIONAL
3893 IN UINT16 VarOffset, OPTIONAL
3894 IN EFI_STRING_ID Prompt,
3895 IN EFI_STRING_ID Help,
3896 IN UINT8 QuestionFlags,
3897 IN UINT8 DateFlags,
3898 IN VOID *DefaultsOpCodeHandle OPTIONAL
3899 )
3900 {
3901 EFI_IFR_DATE OpCode;
3902 UINTN Position;
3903
3904 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3905 ASSERT ((DateFlags & (~(EFI_QF_DATE_YEAR_SUPPRESS | EFI_QF_DATE_MONTH_SUPPRESS | EFI_QF_DATE_DAY_SUPPRESS | EFI_QF_DATE_STORAGE))) == 0);
3906
3907 ZeroMem (&OpCode, sizeof (OpCode));
3908 OpCode.Question.Header.Prompt = Prompt;
3909 OpCode.Question.Header.Help = Help;
3910 OpCode.Question.QuestionId = QuestionId;
3911 OpCode.Question.VarStoreId = VarStoreId;
3912 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3913 OpCode.Question.Flags = QuestionFlags;
3914 OpCode.Flags = DateFlags;
3915
3916 if (DefaultsOpCodeHandle == NULL) {
3917 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DATE_OP, sizeof (OpCode));
3918 }
3919
3920 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3921 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_DATE_OP, sizeof (OpCode), 0, 1);
3922 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3923 HiiCreateEndOpCode (OpCodeHandle);
3924 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3925 }
3926
3927 /**
3928 Create EFI_IFR_TIME_OP opcode.
3929
3930 If OpCodeHandle is NULL, then ASSERT().
3931 If any reserved bits are set in QuestionFlags, then ASSERT().
3932 If any reserved bits are set in TimeFlags, then ASSERT().
3933
3934 @param[in] OpCodeHandle Handle to the buffer of opcodes.
3935 @param[in] QuestionId Question ID
3936 @param[in] VarStoreId Storage ID, optional. If TimeFlags is not
3937 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3938 @param[in] VarOffset Offset in Storage or String ID of the name (VarName)
3939 for this name/value pair, optional. If TimeFlags is not
3940 QF_TIME_STORAGE_NORMAL, this parameter is ignored.
3941 @param[in] Prompt String ID for Prompt
3942 @param[in] Help String ID for Help
3943 @param[in] QuestionFlags Flags in Question Header
3944 @param[in] TimeFlags Flags for time opcode
3945 @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This
3946 is an optional parameter that may be NULL.
3947
3948 @retval NULL There is not enough space left in Buffer to add the opcode.
3949 @retval Other A pointer to the created opcode.
3950
3951 **/
3952 UINT8 *
3953 EFIAPI
3954 HiiCreateTimeOpCode (
3955 IN VOID *OpCodeHandle,
3956 IN EFI_QUESTION_ID QuestionId,
3957 IN EFI_VARSTORE_ID VarStoreId, OPTIONAL
3958 IN UINT16 VarOffset, OPTIONAL
3959 IN EFI_STRING_ID Prompt,
3960 IN EFI_STRING_ID Help,
3961 IN UINT8 QuestionFlags,
3962 IN UINT8 TimeFlags,
3963 IN VOID *DefaultsOpCodeHandle OPTIONAL
3964 )
3965 {
3966 EFI_IFR_TIME OpCode;
3967 UINTN Position;
3968
3969 ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0);
3970 ASSERT ((TimeFlags & (~(QF_TIME_HOUR_SUPPRESS | QF_TIME_MINUTE_SUPPRESS | QF_TIME_SECOND_SUPPRESS | QF_TIME_STORAGE))) == 0);
3971
3972 ZeroMem (&OpCode, sizeof (OpCode));
3973 OpCode.Question.Header.Prompt = Prompt;
3974 OpCode.Question.Header.Help = Help;
3975 OpCode.Question.QuestionId = QuestionId;
3976 OpCode.Question.VarStoreId = VarStoreId;
3977 OpCode.Question.VarStoreInfo.VarOffset = VarOffset;
3978 OpCode.Question.Flags = QuestionFlags;
3979 OpCode.Flags = TimeFlags;
3980
3981 if (DefaultsOpCodeHandle == NULL) {
3982 return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_TIME_OP, sizeof (OpCode));
3983 }
3984
3985 Position = InternalHiiOpCodeHandlePosition (OpCodeHandle);
3986 InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_TIME_OP, sizeof (OpCode), 0, 1);
3987 InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle);
3988 HiiCreateEndOpCode (OpCodeHandle);
3989 return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position;
3990 }
3991
3992 /**
3993 This is the internal worker function to update the data in
3994 a form specified by FormSetGuid, FormId and Label.
3995
3996 @param[in] FormSetGuid The optional Formset GUID.
3997 @param[in] FormId The Form ID.
3998 @param[in] Package The package header.
3999 @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR
4000 opcodes to be inserted or replaced in the form.
4001 @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode
4002 that marks the end of a replace operation in the form.
4003 @param[out] TempPackage The resultant package.
4004
4005 @retval EFI_SUCCESS The function completes successfully.
4006 @retval EFI_NOT_FOUND The updated opcode or endopcode is not found.
4007
4008 **/
4009 EFI_STATUS
4010 EFIAPI
4011 InternalHiiUpdateFormPackageData (
4012 IN EFI_GUID *FormSetGuid, OPTIONAL
4013 IN EFI_FORM_ID FormId,
4014 IN EFI_HII_PACKAGE_HEADER *Package,
4015 IN HII_LIB_OPCODE_BUFFER *OpCodeBufferStart,
4016 IN HII_LIB_OPCODE_BUFFER *OpCodeBufferEnd, OPTIONAL
4017 OUT EFI_HII_PACKAGE_HEADER *TempPackage
4018 )
4019 {
4020 UINTN AddSize;
4021 UINT8 *BufferPos;
4022 EFI_HII_PACKAGE_HEADER PackageHeader;
4023 UINTN Offset;
4024 EFI_IFR_OP_HEADER *IfrOpHdr;
4025 EFI_IFR_OP_HEADER *UpdateIfrOpHdr;
4026 BOOLEAN GetFormSet;
4027 BOOLEAN GetForm;
4028 BOOLEAN Updated;
4029 UINTN UpdatePackageLength;
4030
4031 CopyMem (TempPackage, Package, sizeof (EFI_HII_PACKAGE_HEADER));
4032 UpdatePackageLength = sizeof (EFI_HII_PACKAGE_HEADER);
4033 BufferPos = (UINT8 *) (TempPackage + 1);
4034
4035 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
4036 IfrOpHdr = (EFI_IFR_OP_HEADER *)((UINT8 *) Package + sizeof (EFI_HII_PACKAGE_HEADER));
4037 Offset = sizeof (EFI_HII_PACKAGE_HEADER);
4038 GetFormSet = (BOOLEAN) ((FormSetGuid == NULL) ? TRUE : FALSE);
4039 GetForm = FALSE;
4040 Updated = FALSE;
4041
4042 while (Offset < PackageHeader.Length) {
4043 CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);
4044 BufferPos += IfrOpHdr->Length;
4045 UpdatePackageLength += IfrOpHdr->Length;
4046
4047 //
4048 // Find the matched FormSet and Form
4049 //
4050 if ((IfrOpHdr->OpCode == EFI_IFR_FORM_SET_OP) && (FormSetGuid != NULL)) {
4051 if (CompareGuid((GUID *)(VOID *)&((EFI_IFR_FORM_SET *) IfrOpHdr)->Guid, FormSetGuid)) {
4052 GetFormSet = TRUE;
4053 } else {
4054 GetFormSet = FALSE;
4055 }
4056 } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP || IfrOpHdr->OpCode == EFI_IFR_FORM_MAP_OP) {
4057 if (CompareMem (&((EFI_IFR_FORM *) IfrOpHdr)->FormId, &FormId, sizeof (EFI_FORM_ID)) == 0) {
4058 GetForm = TRUE;
4059 } else {
4060 GetForm = FALSE;
4061 }
4062 }
4063
4064 //
4065 // The matched Form is found, and Update data in this form
4066 //
4067 if (GetFormSet && GetForm) {
4068 UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferStart->Buffer;
4069 if ((UpdateIfrOpHdr->Length == IfrOpHdr->Length) && \
4070 (CompareMem (IfrOpHdr, UpdateIfrOpHdr, UpdateIfrOpHdr->Length) == 0)) {
4071 //
4072 // Remove the original data when End OpCode buffer exist.
4073 //
4074 if (OpCodeBufferEnd != NULL) {
4075 Offset += IfrOpHdr->Length;
4076 IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);
4077 UpdateIfrOpHdr = (EFI_IFR_OP_HEADER *) OpCodeBufferEnd->Buffer;
4078 while (Offset < PackageHeader.Length) {
4079 //
4080 // Search the matched end opcode
4081 //
4082 if ((UpdateIfrOpHdr->Length == IfrOpHdr->Length) && \
4083 (CompareMem (IfrOpHdr, UpdateIfrOpHdr, UpdateIfrOpHdr->Length) == 0)) {
4084 break;
4085 }
4086 //
4087 // Go to the next Op-Code
4088 //
4089 Offset += IfrOpHdr->Length;
4090 IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) (IfrOpHdr) + IfrOpHdr->Length);
4091 }
4092
4093 if (Offset >= PackageHeader.Length) {
4094 //
4095 // The end opcode is not found.
4096 //
4097 return EFI_NOT_FOUND;
4098 }
4099 }
4100
4101 //
4102 // Insert the updated data
4103 //
4104 AddSize = ((EFI_IFR_OP_HEADER *) OpCodeBufferStart->Buffer)->Length;
4105 CopyMem (BufferPos, OpCodeBufferStart->Buffer + AddSize, OpCodeBufferStart->Position - AddSize);
4106 BufferPos += OpCodeBufferStart->Position - AddSize;
4107 UpdatePackageLength += OpCodeBufferStart->Position - AddSize;
4108
4109 if (OpCodeBufferEnd != NULL) {
4110 //
4111 // Add the end opcode
4112 //
4113 CopyMem (BufferPos, IfrOpHdr, IfrOpHdr->Length);
4114 BufferPos += IfrOpHdr->Length;
4115 UpdatePackageLength += IfrOpHdr->Length;
4116 }
4117
4118 //
4119 // Copy the left package data.
4120 //
4121 Offset += IfrOpHdr->Length;
4122 CopyMem (BufferPos, (UINT8 *) Package + Offset, PackageHeader.Length - Offset);
4123 UpdatePackageLength += PackageHeader.Length - Offset;
4124
4125 //
4126 // Set update flag
4127 //
4128 Updated = TRUE;
4129 break;
4130 }
4131 }
4132
4133 //
4134 // Go to the next Op-Code
4135 //
4136 Offset += IfrOpHdr->Length;
4137 IfrOpHdr = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (IfrOpHdr) + IfrOpHdr->Length);
4138 }
4139
4140 if (!Updated) {
4141 //
4142 // The updated opcode buffer is not found.
4143 //
4144 return EFI_NOT_FOUND;
4145 }
4146 //
4147 // Update the package length.
4148 //
4149 PackageHeader.Length = (UINT32) UpdatePackageLength;
4150 CopyMem (TempPackage, &PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));
4151
4152 return EFI_SUCCESS;
4153 }
4154
4155 /**
4156 This function updates a form that has previously been registered with the HII
4157 Database. This function will perform at most one update operation.
4158
4159 The form to update is specified by Handle, FormSetGuid, and FormId. Binary
4160 comparisons of IFR opcodes are performed from the beginning of the form being
4161 updated until an IFR opcode is found that exactly matches the first IFR opcode
4162 specified by StartOpCodeHandle. The following rules are used to determine if
4163 an insert, replace, or delete operation is performed.
4164
4165 1) If no matches are found, then NULL is returned.
4166 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes
4167 from StartOpCodeHandle except the first opcode are inserted immediately after
4168 the matching IFR opcode in the form to be updated.
4169 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made
4170 from the matching IFR opcode until an IFR opcode exactly matches the first
4171 IFR opcode specified by EndOpCodeHandle. If no match is found for the first
4172 IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match
4173 is found, then all of the IFR opcodes between the start match and the end
4174 match are deleted from the form being updated and all of the IFR opcodes
4175 from StartOpCodeHandle except the first opcode are inserted immediately after
4176 the matching start IFR opcode. If StartOpCcodeHandle only contains one
4177 IFR instruction, then the result of this operation will delete all of the IFR
4178 opcodes between the start end matches.
4179
4180 If HiiHandle is NULL, then ASSERT().
4181 If StartOpCodeHandle is NULL, then ASSERT().
4182
4183 @param[in] HiiHandle The HII Handle of the form to update.
4184 @param[in] FormSetGuid The Formset GUID of the form to update. This
4185 is an optional parameter that may be NULL.
4186 If it is NULL, all FormSet will be updated.
4187 @param[in] FormId The ID of the form to update.
4188 @param[in] StartOpCodeHandle An OpCode Handle that contains the set of IFR
4189 opcodes to be inserted or replaced in the form.
4190 The first IFR instruction in StartOpCodeHandle
4191 is used to find matching IFR opcode in the
4192 form.
4193 @param[in] EndOpCodeHandle An OpCcode Handle that contains the IFR opcode
4194 that marks the end of a replace operation in
4195 the form. This is an optional parameter that
4196 may be NULL. If it is NULL, then an the IFR
4197 opcodes specified by StartOpCodeHandle are
4198 inserted into the form.
4199
4200 @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated.
4201 @retval EFI_NOT_FOUND The following cases will return EFI_NOT_FOUND.
4202 1) The form specified by HiiHandle, FormSetGuid,
4203 and FormId could not be found in the HII Database.
4204 2) No IFR opcodes in the target form match the first
4205 IFR opcode in StartOpCodeHandle.
4206 3) EndOpCOde is not NULL, and no IFR opcodes in the
4207 target form following a matching start opcode match
4208 the first IFR opcode in EndOpCodeHandle.
4209 @retval EFI_SUCCESS The matched form is updated by StartOpcode.
4210
4211 **/
4212 EFI_STATUS
4213 EFIAPI
4214 HiiUpdateForm (
4215 IN EFI_HII_HANDLE HiiHandle,
4216 IN EFI_GUID *FormSetGuid, OPTIONAL
4217 IN EFI_FORM_ID FormId,
4218 IN VOID *StartOpCodeHandle,
4219 IN VOID *EndOpCodeHandle OPTIONAL
4220 )
4221 {
4222 EFI_STATUS Status;
4223 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
4224 UINT32 PackageListLength;
4225 UINT32 Offset;
4226 EFI_HII_PACKAGE_LIST_HEADER *UpdatePackageList;
4227 UINTN BufferSize;
4228 UINT8 *UpdateBufferPos;
4229 EFI_HII_PACKAGE_HEADER *Package;
4230 EFI_HII_PACKAGE_HEADER *TempPackage;
4231 EFI_HII_PACKAGE_HEADER PackageHeader;
4232 BOOLEAN Updated;
4233 HII_LIB_OPCODE_BUFFER *OpCodeBufferStart;
4234 HII_LIB_OPCODE_BUFFER *OpCodeBufferEnd;
4235
4236 //
4237 // Input update data can't be NULL.
4238 //
4239 ASSERT (HiiHandle != NULL);
4240 ASSERT (StartOpCodeHandle != NULL);
4241 UpdatePackageList = NULL;
4242 TempPackage = NULL;
4243 HiiPackageList = NULL;
4244
4245 //
4246 // Retrieve buffer data from Opcode Handle
4247 //
4248 OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpCodeHandle;
4249 OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpCodeHandle;
4250
4251 //
4252 // Get the original package list
4253 //
4254 BufferSize = 0;
4255 HiiPackageList = NULL;
4256 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &BufferSize, HiiPackageList);
4257 //
4258 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
4259 //
4260 if (Status != EFI_BUFFER_TOO_SMALL) {
4261 return Status;
4262 }
4263
4264 HiiPackageList = AllocatePool (BufferSize);
4265 if (HiiPackageList == NULL) {
4266 Status = EFI_OUT_OF_RESOURCES;
4267 goto Finish;
4268 }
4269
4270 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, HiiHandle, &BufferSize, HiiPackageList);
4271 if (EFI_ERROR (Status)) {
4272 goto Finish;
4273 }
4274
4275 //
4276 // Calculate and allocate space for retrieval of IFR data
4277 //
4278 BufferSize += OpCodeBufferStart->Position;
4279 UpdatePackageList = AllocateZeroPool (BufferSize);
4280 if (UpdatePackageList == NULL) {
4281 Status = EFI_OUT_OF_RESOURCES;
4282 goto Finish;
4283 }
4284
4285 //
4286 // Allocate temp buffer to store the temp updated package buffer
4287 //
4288 TempPackage = AllocateZeroPool (BufferSize);
4289 if (TempPackage == NULL) {
4290 Status = EFI_OUT_OF_RESOURCES;
4291 goto Finish;
4292 }
4293
4294 UpdateBufferPos = (UINT8 *) UpdatePackageList;
4295
4296 //
4297 // Copy the package list header
4298 //
4299 CopyMem (UpdateBufferPos, HiiPackageList, sizeof (EFI_HII_PACKAGE_LIST_HEADER));
4300 UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER);
4301
4302 //
4303 // Go through each package to find the matched package and update one by one
4304 //
4305 Updated = FALSE;
4306 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
4307 PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);
4308 while (Offset < PackageListLength) {
4309 Package = (EFI_HII_PACKAGE_HEADER *) (((UINT8 *) HiiPackageList) + Offset);
4310 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
4311 Offset += Package->Length;
4312
4313 if (Package->Type == EFI_HII_PACKAGE_FORMS) {
4314 //
4315 // Check this package is the matched package.
4316 //
4317 Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPackage);
4318 //
4319 // The matched package is found. Its package buffer will be updated by the input new data.
4320 //
4321 if (!EFI_ERROR(Status)) {
4322 //
4323 // Set Update Flag
4324 //
4325 Updated = TRUE;
4326 //
4327 // Add updated package buffer
4328 //
4329 Package = TempPackage;
4330 }
4331 }
4332
4333 //
4334 // Add pacakge buffer
4335 //
4336 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
4337 CopyMem (UpdateBufferPos, Package, PackageHeader.Length);
4338 UpdateBufferPos += PackageHeader.Length;
4339 }
4340
4341 if (Updated) {
4342 //
4343 // Update package list length
4344 //
4345 BufferSize = UpdateBufferPos - (UINT8 *) UpdatePackageList;
4346 WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize);
4347
4348 //
4349 // Update Package to show form
4350 //
4351 Status = gHiiDatabase->UpdatePackageList (gHiiDatabase, HiiHandle, UpdatePackageList);
4352 } else {
4353 //
4354 // Not matched form is found and updated.
4355 //
4356 Status = EFI_NOT_FOUND;
4357 }
4358
4359 Finish:
4360 if (HiiPackageList != NULL) {
4361 FreePool (HiiPackageList);
4362 }
4363
4364 if (UpdatePackageList != NULL) {
4365 FreePool (UpdatePackageList);
4366 }
4367
4368 if (TempPackage != NULL) {
4369 FreePool (TempPackage);
4370 }
4371
4372 return Status;
4373 }