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