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