]>
Commit | Line | Data |
---|---|---|
08e4b3cf | 1 | /** @file\r |
2 | Utility functions which helps in opcode creation, HII configuration string manipulations, \r | |
3 | pop up window creations, setup browser persistence data set and get.\r | |
4 | \r | |
5 | Copyright (c) 2007- 2008, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "UefiIfrLibraryInternal.h"\r | |
17 | \r | |
18 | CONST EFI_FORM_BROWSER2_PROTOCOL *mFormBrowser2 = NULL;\r | |
19 | CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mIfrSupportLibHiiConfigRouting = NULL;\r | |
20 | \r | |
21 | /**\r | |
22 | This function locate FormBrowser2 protocols for later usage.\r | |
23 | \r | |
24 | @return Status the status to locate protocol.\r | |
25 | **/\r | |
26 | EFI_STATUS\r | |
27 | LocateFormBrowser2Protocols (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | EFI_STATUS Status;\r | |
32 | //\r | |
33 | // Locate protocols for later usage\r | |
34 | //\r | |
35 | if (mFormBrowser2 == NULL) {\r | |
36 | Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mFormBrowser2);\r | |
37 | if (EFI_ERROR (Status)) {\r | |
38 | return Status;\r | |
39 | }\r | |
40 | }\r | |
41 | \r | |
42 | if (mIfrSupportLibHiiConfigRouting == NULL) {\r | |
43 | Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mIfrSupportLibHiiConfigRouting);\r | |
44 | if (EFI_ERROR (Status)) {\r | |
45 | return Status;\r | |
46 | }\r | |
47 | }\r | |
48 | \r | |
49 | return EFI_SUCCESS;\r | |
50 | }\r | |
51 | \r | |
52 | //\r | |
53 | // Fake <ConfigHdr>\r | |
54 | //\r | |
55 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mFakeConfigHdr[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=0";\r | |
56 | \r | |
57 | /**\r | |
58 | Draw a dialog and return the selected key.\r | |
59 | \r | |
60 | @param NumberOfLines The number of lines for the dialog box\r | |
61 | @param KeyValue The EFI_KEY value returned if HotKey is TRUE..\r | |
35d59af3 | 62 | @param String The first String to be displayed in the Pop-Up.\r |
08e4b3cf | 63 | @param Marker A series of (quantity == NumberOfLines - 1) text\r |
64 | strings which will be used to construct the dialog\r | |
65 | box\r | |
66 | \r | |
67 | @retval EFI_SUCCESS Displayed dialog and received user interaction\r | |
68 | @retval EFI_INVALID_PARAMETER One of the parameters was invalid.\r | |
69 | @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.\r | |
70 | \r | |
71 | **/\r | |
72 | EFI_STATUS\r | |
73 | EFIAPI\r | |
74 | IfrLibCreatePopUp2 (\r | |
75 | IN UINTN NumberOfLines,\r | |
76 | OUT EFI_INPUT_KEY *KeyValue,\r | |
35d59af3 | 77 | IN CHAR16 *String,\r |
08e4b3cf | 78 | IN VA_LIST Marker\r |
79 | )\r | |
80 | {\r | |
81 | UINTN Index;\r | |
82 | UINTN Count;\r | |
83 | UINTN Start;\r | |
84 | UINTN Top;\r | |
85 | CHAR16 *StringPtr;\r | |
86 | UINTN LeftColumn;\r | |
87 | UINTN RightColumn;\r | |
88 | UINTN TopRow;\r | |
89 | UINTN BottomRow;\r | |
90 | UINTN DimensionsWidth;\r | |
91 | UINTN DimensionsHeight;\r | |
92 | EFI_INPUT_KEY Key;\r | |
93 | UINTN LargestString;\r | |
94 | CHAR16 *StackString;\r | |
95 | EFI_STATUS Status;\r | |
96 | UINTN StringLen;\r | |
97 | CHAR16 *LineBuffer;\r | |
98 | CHAR16 **StringArray;\r | |
99 | EFI_EVENT TimerEvent;\r | |
100 | EFI_EVENT WaitList[2];\r | |
101 | UINTN CurrentAttribute;\r | |
102 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r | |
08e4b3cf | 103 | \r |
08e4b3cf | 104 | if ((KeyValue == NULL) || (String == NULL)) {\r |
105 | return EFI_INVALID_PARAMETER;\r | |
106 | }\r | |
107 | \r | |
108 | TopRow = 0;\r | |
109 | BottomRow = 0;\r | |
110 | LeftColumn = 0;\r | |
111 | RightColumn = 0;\r | |
112 | \r | |
113 | ConOut = gST->ConOut;\r | |
114 | ConOut->QueryMode (ConOut, ConOut->Mode->Mode, &RightColumn, &BottomRow);\r | |
115 | \r | |
116 | DimensionsWidth = RightColumn - LeftColumn;\r | |
117 | DimensionsHeight = BottomRow - TopRow;\r | |
118 | \r | |
119 | CurrentAttribute = ConOut->Mode->Attribute;\r | |
120 | \r | |
121 | LineBuffer = AllocateZeroPool (DimensionsWidth * sizeof (CHAR16));\r | |
122 | if (LineBuffer == NULL) {\r | |
123 | return EFI_OUT_OF_RESOURCES;\r | |
124 | }\r | |
125 | \r | |
126 | //\r | |
127 | // Determine the largest string in the dialog box\r | |
128 | // Notice we are starting with 1 since String is the first string\r | |
129 | //\r | |
130 | StringArray = AllocateZeroPool (NumberOfLines * sizeof (CHAR16 *));\r | |
131 | if (StringArray == NULL) {\r | |
132 | FreePool (LineBuffer);\r | |
133 | return EFI_OUT_OF_RESOURCES;\r | |
134 | }\r | |
135 | LargestString = StrLen (String);\r | |
136 | StringArray[0] = String;\r | |
137 | \r | |
138 | for (Index = 1; Index < NumberOfLines; Index++) {\r | |
139 | StackString = VA_ARG (Marker, CHAR16 *);\r | |
140 | \r | |
141 | if (StackString == NULL) {\r | |
142 | FreePool (LineBuffer);\r | |
143 | FreePool (StringArray);\r | |
144 | return EFI_INVALID_PARAMETER;\r | |
145 | }\r | |
146 | \r | |
147 | StringArray[Index] = StackString;\r | |
148 | StringLen = StrLen (StackString);\r | |
149 | if (StringLen > LargestString) {\r | |
150 | LargestString = StringLen;\r | |
151 | }\r | |
152 | }\r | |
153 | \r | |
154 | if ((LargestString + 2) > DimensionsWidth) {\r | |
155 | LargestString = DimensionsWidth - 2;\r | |
156 | }\r | |
157 | \r | |
158 | //\r | |
159 | // Subtract the PopUp width from total Columns, allow for one space extra on\r | |
160 | // each end plus a border.\r | |
161 | //\r | |
162 | Start = (DimensionsWidth - LargestString - 2) / 2 + LeftColumn + 1;\r | |
163 | \r | |
164 | Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + TopRow - 1;\r | |
165 | \r | |
166 | //\r | |
167 | // Disable cursor\r | |
168 | //\r | |
169 | ConOut->EnableCursor (ConOut, FALSE);\r | |
170 | ConOut->SetAttribute (ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE);\r | |
171 | \r | |
172 | StringPtr = &LineBuffer[0];\r | |
173 | *StringPtr++ = BOXDRAW_DOWN_RIGHT;\r | |
174 | for (Index = 0; Index < LargestString; Index++) {\r | |
175 | *StringPtr++ = BOXDRAW_HORIZONTAL;\r | |
176 | }\r | |
177 | *StringPtr++ = BOXDRAW_DOWN_LEFT;\r | |
178 | *StringPtr = L'\0';\r | |
179 | \r | |
180 | ConOut->SetCursorPosition (ConOut, Start, Top);\r | |
181 | ConOut->OutputString (ConOut, LineBuffer);\r | |
182 | \r | |
183 | for (Index = 0; Index < NumberOfLines; Index++) {\r | |
184 | StringPtr = &LineBuffer[0];\r | |
185 | *StringPtr++ = BOXDRAW_VERTICAL;\r | |
186 | \r | |
187 | for (Count = 0; Count < LargestString; Count++) {\r | |
188 | StringPtr[Count] = L' ';\r | |
189 | }\r | |
190 | \r | |
191 | StringLen = StrLen (StringArray[Index]);\r | |
192 | if (StringLen > LargestString) {\r | |
193 | StringLen = LargestString;\r | |
194 | }\r | |
195 | CopyMem (\r | |
196 | StringPtr + ((LargestString - StringLen) / 2),\r | |
197 | StringArray[Index],\r | |
198 | StringLen * sizeof (CHAR16)\r | |
199 | );\r | |
200 | StringPtr += LargestString;\r | |
201 | \r | |
202 | *StringPtr++ = BOXDRAW_VERTICAL;\r | |
203 | *StringPtr = L'\0';\r | |
204 | \r | |
205 | ConOut->SetCursorPosition (ConOut, Start, Top + 1 + Index);\r | |
206 | ConOut->OutputString (ConOut, LineBuffer);\r | |
207 | }\r | |
208 | \r | |
209 | StringPtr = &LineBuffer[0];\r | |
210 | *StringPtr++ = BOXDRAW_UP_RIGHT;\r | |
211 | for (Index = 0; Index < LargestString; Index++) {\r | |
212 | *StringPtr++ = BOXDRAW_HORIZONTAL;\r | |
213 | }\r | |
214 | *StringPtr++ = BOXDRAW_UP_LEFT;\r | |
215 | *StringPtr = L'\0';\r | |
216 | \r | |
217 | ConOut->SetCursorPosition (ConOut, Start, Top + NumberOfLines + 1);\r | |
218 | ConOut->OutputString (ConOut, LineBuffer);\r | |
219 | \r | |
220 | do {\r | |
221 | Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r | |
222 | \r | |
223 | //\r | |
224 | // Set a timer event of 1 second expiration\r | |
225 | //\r | |
226 | gBS->SetTimer (\r | |
227 | TimerEvent,\r | |
228 | TimerRelative,\r | |
229 | 10000000\r | |
230 | );\r | |
231 | \r | |
232 | //\r | |
233 | // Wait for the keystroke event or the timer\r | |
234 | //\r | |
235 | WaitList[0] = gST->ConIn->WaitForKey;\r | |
236 | WaitList[1] = TimerEvent;\r | |
237 | Status = gBS->WaitForEvent (2, WaitList, &Index);\r | |
238 | \r | |
239 | //\r | |
240 | // Check for the timer expiration\r | |
241 | //\r | |
242 | if (!EFI_ERROR (Status) && Index == 1) {\r | |
243 | Status = EFI_TIMEOUT;\r | |
244 | }\r | |
245 | \r | |
246 | gBS->CloseEvent (TimerEvent);\r | |
247 | } while (Status == EFI_TIMEOUT);\r | |
248 | \r | |
249 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
250 | CopyMem (KeyValue, &Key, sizeof (EFI_INPUT_KEY));\r | |
251 | \r | |
252 | ConOut->SetAttribute (ConOut, CurrentAttribute);\r | |
253 | ConOut->EnableCursor (ConOut, TRUE);\r | |
254 | \r | |
255 | FreePool (LineBuffer);\r | |
256 | FreePool (StringArray);\r | |
257 | \r | |
258 | return Status;\r | |
259 | }\r | |
260 | \r | |
261 | \r | |
262 | /**\r | |
263 | Draw a dialog and return the selected key.\r | |
264 | \r | |
265 | @param NumberOfLines The number of lines for the dialog box\r | |
266 | @param KeyValue The EFI_KEY value returned if HotKey is TRUE..\r | |
267 | @param String Pointer to the first string in the list\r | |
268 | @param ... A series of (quantity == NumberOfLines - 1) text\r | |
269 | strings which will be used to construct the dialog\r | |
270 | box\r | |
271 | \r | |
272 | @retval EFI_SUCCESS Displayed dialog and received user interaction\r | |
273 | @retval EFI_INVALID_PARAMETER One of the parameters was invalid.\r | |
274 | \r | |
275 | **/\r | |
276 | EFI_STATUS\r | |
277 | EFIAPI\r | |
278 | IfrLibCreatePopUp (\r | |
279 | IN UINTN NumberOfLines,\r | |
280 | OUT EFI_INPUT_KEY *KeyValue,\r | |
281 | IN CHAR16 *String,\r | |
282 | ...\r | |
283 | )\r | |
284 | {\r | |
285 | EFI_STATUS Status;\r | |
286 | VA_LIST Marker;\r | |
287 | \r | |
35d59af3 | 288 | VA_START (Marker, String);\r |
08e4b3cf | 289 | \r |
35d59af3 | 290 | Status = IfrLibCreatePopUp2 (NumberOfLines, KeyValue, String, Marker);\r |
08e4b3cf | 291 | \r |
292 | VA_END (Marker);\r | |
293 | \r | |
294 | return Status;\r | |
295 | }\r | |
296 | \r | |
297 | /**\r | |
298 | Extract block name from the array generated by VFR compiler. The name of\r | |
299 | this array is "Vfr + <StorageName> + BlockName", e.g. "VfrMyIfrNVDataBlockName".\r | |
300 | Format of this array is:\r | |
301 | Array length | 4-bytes\r | |
302 | Offset | 2-bytes\r | |
303 | Width | 2-bytes\r | |
304 | Offset | 2-bytes\r | |
305 | Width | 2-bytes\r | |
306 | ... ...\r | |
307 | \r | |
308 | @param Buffer Array generated by VFR compiler.\r | |
309 | @param BlockName The returned <BlockName>\r | |
310 | \r | |
311 | @retval EFI_OUT_OF_RESOURCES Run out of memory resource.\r | |
312 | @retval EFI_INVALID_PARAMETER Buffer is NULL or BlockName is NULL.\r | |
313 | @retval EFI_SUCCESS Operation successful.\r | |
314 | \r | |
315 | **/\r | |
316 | EFI_STATUS\r | |
317 | ExtractBlockName (\r | |
318 | IN UINT8 *Buffer,\r | |
319 | OUT CHAR16 **BlockName\r | |
320 | )\r | |
321 | \r | |
322 | {\r | |
323 | UINTN Index;\r | |
324 | UINT32 Length;\r | |
325 | UINT32 BlockNameNumber;\r | |
326 | UINTN HexStringBufferLen;\r | |
327 | CHAR16 *StringPtr;\r | |
328 | \r | |
329 | if ((Buffer == NULL) || (BlockName == NULL)) {\r | |
330 | return EFI_INVALID_PARAMETER;\r | |
331 | }\r | |
332 | \r | |
333 | //\r | |
334 | // Calculate number of Offset/Width pair\r | |
335 | //\r | |
336 | CopyMem (&Length, Buffer, sizeof (UINT32));\r | |
337 | BlockNameNumber = (Length - sizeof (UINT32)) / (sizeof (UINT16) * 2);\r | |
338 | \r | |
339 | //\r | |
340 | // <BlockName> ::= &OFFSET=1234&WIDTH=1234\r | |
341 | // | 8 | 4 | 7 | 4 |\r | |
342 | //\r | |
343 | StringPtr = AllocateZeroPool ((BlockNameNumber * (8 + 4 + 7 + 4) + 1) * sizeof (CHAR16));\r | |
344 | *BlockName = StringPtr;\r | |
345 | if (StringPtr == NULL) {\r | |
346 | return EFI_OUT_OF_RESOURCES;\r | |
347 | }\r | |
348 | \r | |
349 | Buffer += sizeof (UINT32);\r | |
350 | for (Index = 0; Index < BlockNameNumber; Index++) {\r | |
351 | StrCpy (StringPtr, L"&OFFSET=");\r | |
352 | StringPtr += 8;\r | |
353 | \r | |
354 | HexStringBufferLen = 5;\r | |
355 | BufToHexString (StringPtr, &HexStringBufferLen, Buffer, sizeof (UINT16));\r | |
356 | Buffer += sizeof (UINT16);\r | |
357 | StringPtr += 4;\r | |
358 | \r | |
359 | StrCpy (StringPtr, L"&WIDTH=");\r | |
360 | StringPtr += 7;\r | |
361 | \r | |
362 | HexStringBufferLen = 5;\r | |
363 | BufToHexString (StringPtr, &HexStringBufferLen, Buffer, sizeof (UINT16));\r | |
364 | Buffer += sizeof (UINT16);\r | |
365 | StringPtr += 4;\r | |
366 | }\r | |
367 | \r | |
368 | return EFI_SUCCESS;\r | |
369 | }\r | |
370 | \r | |
371 | /**\r | |
372 | \r | |
373 | Extract block config from the array generated by VFR compiler. The name of\r | |
374 | this array is "Vfr + <StorageName> + Default<HexCh>4", e.g. "VfrMyIfrNVDataDefault0000".\r | |
375 | \r | |
376 | @param Buffer - Array generated by VFR compiler.\r | |
377 | @param BlockConfig - The returned <BlockConfig>\r | |
378 | \r | |
379 | @retval EFI_OUT_OF_RESOURCES - Run out of memory resource.\r | |
380 | @retval EFI_INVALID_PARAMETER - Buffer is NULL or BlockConfig is NULL.\r | |
381 | @retval EFI_SUCCESS - Operation successful.\r | |
382 | \r | |
383 | **/\r | |
384 | EFI_STATUS\r | |
385 | ExtractBlockConfig (\r | |
386 | IN UINT8 *Buffer,\r | |
387 | OUT CHAR16 **BlockConfig\r | |
388 | )\r | |
389 | {\r | |
390 | UINT32 Length;\r | |
391 | UINT16 Width;\r | |
392 | UINTN HexStringBufferLen;\r | |
393 | CHAR16 *StringPtr;\r | |
394 | UINT8 *BufferEnd;\r | |
395 | CHAR16 *StringEnd;\r | |
396 | EFI_STATUS Status;\r | |
397 | \r | |
398 | if ((Buffer == NULL) || (BlockConfig == NULL)) {\r | |
399 | return EFI_INVALID_PARAMETER;\r | |
400 | }\r | |
401 | \r | |
402 | //\r | |
403 | // Calculate length of AltResp string\r | |
404 | // Format of Default value array is:\r | |
405 | // Array length | 4-bytes\r | |
406 | // Offset | 2-bytes\r | |
407 | // Width | 2-bytes\r | |
408 | // Value | Variable length\r | |
409 | // Offset | 2-bytes\r | |
410 | // Width | 2-bytes\r | |
411 | // Value | Variable length\r | |
412 | // ... ...\r | |
413 | // When value is 1 byte in length, overhead of AltResp string will be maximum,\r | |
414 | // BlockConfig ::= <&OFFSET=1234&WIDTH=1234&VALUE=12>+\r | |
415 | // | 8 | 4 | 7 | 4 | 7 |2|\r | |
416 | // so the maximum length of BlockConfig could be calculated as:\r | |
417 | // (ArrayLength / 5) * (8 + 4 + 7 + 4 + 7 + 2) = ArrayLength * 6.4 < ArrayLength * 7\r | |
418 | //\r | |
419 | CopyMem (&Length, Buffer, sizeof (UINT32));\r | |
420 | BufferEnd = Buffer + Length;\r | |
421 | StringPtr = AllocatePool (Length * 7 * sizeof (CHAR16));\r | |
422 | *BlockConfig = StringPtr;\r | |
423 | if (StringPtr == NULL) {\r | |
424 | return EFI_OUT_OF_RESOURCES;\r | |
425 | }\r | |
426 | StringEnd = StringPtr + (Length * 7);\r | |
427 | \r | |
428 | Buffer += sizeof (UINT32);\r | |
429 | while (Buffer < BufferEnd) {\r | |
430 | StrCpy (StringPtr, L"&OFFSET=");\r | |
431 | StringPtr += 8;\r | |
432 | \r | |
433 | HexStringBufferLen = 5;\r | |
434 | BufToHexString (StringPtr, &HexStringBufferLen, Buffer, sizeof (UINT16));\r | |
435 | Buffer += sizeof (UINT16);\r | |
436 | StringPtr += 4;\r | |
437 | \r | |
438 | StrCpy (StringPtr, L"&WIDTH=");\r | |
439 | StringPtr += 7;\r | |
440 | \r | |
441 | HexStringBufferLen = 5;\r | |
442 | BufToHexString (StringPtr, &HexStringBufferLen, Buffer, sizeof (UINT16));\r | |
443 | CopyMem (&Width, Buffer, sizeof (UINT16));\r | |
444 | Buffer += sizeof (UINT16);\r | |
445 | StringPtr += 4;\r | |
446 | \r | |
447 | StrCpy (StringPtr, L"&VALUE=");\r | |
448 | StringPtr += 7;\r | |
449 | \r | |
450 | HexStringBufferLen = StringEnd - StringPtr;\r | |
451 | Status = BufToHexString (StringPtr, &HexStringBufferLen, Buffer, Width);\r | |
452 | if (EFI_ERROR (Status)) {\r | |
453 | return Status;\r | |
454 | }\r | |
455 | Buffer += Width;\r | |
456 | StringPtr += (Width * 2);\r | |
457 | }\r | |
458 | \r | |
459 | return EFI_SUCCESS;\r | |
460 | }\r | |
461 | \r | |
462 | /**\r | |
463 | Construct <ConfigAltResp> for a buffer storage.\r | |
464 | \r | |
465 | @param ConfigRequest The Config request string. If set to NULL, all the\r | |
466 | configurable elements will be extracted from BlockNameArray.\r | |
467 | @param ConfigAltResp The returned <ConfigAltResp>.\r | |
468 | @param Progress On return, points to a character in the Request.\r | |
469 | @param Guid GUID of the buffer storage.\r | |
470 | @param Name Name of the buffer storage.\r | |
471 | @param DriverHandle The DriverHandle which is used to invoke HiiDatabase\r | |
472 | protocol interface NewPackageList().\r | |
473 | @param BufferStorage Content of the buffer storage.\r | |
474 | @param BufferStorageSize Length in bytes of the buffer storage.\r | |
475 | @param BlockNameArray Array generated by VFR compiler.\r | |
476 | @param NumberAltCfg Number of Default value array generated by VFR compiler.\r | |
477 | The sequential input parameters will be number of\r | |
478 | AltCfgId and DefaultValueArray pairs. When set to 0,\r | |
479 | there will be no <AltResp>.\r | |
480 | \r | |
481 | retval EFI_OUT_OF_RESOURCES Run out of memory resource.\r | |
482 | retval EFI_INVALID_PARAMETER ConfigAltResp is NULL.\r | |
483 | retval EFI_SUCCESS Operation successful.\r | |
484 | \r | |
485 | **/\r | |
486 | EFI_STATUS\r | |
487 | ConstructConfigAltResp (\r | |
488 | IN EFI_STRING ConfigRequest, OPTIONAL\r | |
489 | OUT EFI_STRING *Progress,\r | |
490 | OUT EFI_STRING *ConfigAltResp,\r | |
491 | IN EFI_GUID *Guid,\r | |
492 | IN CHAR16 *Name,\r | |
493 | IN EFI_HANDLE *DriverHandle,\r | |
494 | IN VOID *BufferStorage,\r | |
495 | IN UINTN BufferStorageSize,\r | |
496 | IN VOID *BlockNameArray, OPTIONAL\r | |
497 | IN UINTN NumberAltCfg,\r | |
498 | ...\r | |
499 | //IN UINT16 AltCfgId,\r | |
500 | //IN VOID *DefaultValueArray,\r | |
501 | )\r | |
502 | {\r | |
503 | EFI_STATUS Status;\r | |
504 | CHAR16 *ConfigHdr;\r | |
505 | CHAR16 *BlockName;\r | |
506 | CHAR16 *DescHdr;\r | |
507 | CHAR16 *StringPtr;\r | |
508 | CHAR16 **AltCfg;\r | |
509 | UINT16 AltCfgId;\r | |
510 | VOID *DefaultValueArray;\r | |
511 | UINTN StrBufferLen;\r | |
512 | EFI_STRING ConfigResp;\r | |
513 | EFI_STRING TempStr;\r | |
514 | VA_LIST Args;\r | |
515 | UINTN AltRespLen;\r | |
516 | UINTN Index;\r | |
517 | BOOLEAN NeedFreeConfigRequest;\r | |
518 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r | |
519 | UINTN Len;\r | |
520 | \r | |
521 | if (ConfigAltResp == NULL) {\r | |
522 | return EFI_INVALID_PARAMETER;\r | |
523 | }\r | |
524 | \r | |
525 | //\r | |
526 | // Construct <ConfigHdr> : "GUID=...&NAME=...&PATH=..."\r | |
527 | //\r | |
528 | ConfigHdr = NULL;\r | |
529 | StrBufferLen = 0;\r | |
530 | Status = ConstructConfigHdr (\r | |
531 | ConfigHdr,\r | |
532 | &StrBufferLen,\r | |
533 | Guid,\r | |
534 | Name,\r | |
535 | DriverHandle\r | |
536 | );\r | |
537 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
538 | ConfigHdr = AllocateZeroPool (StrBufferLen);\r | |
539 | Status = ConstructConfigHdr (\r | |
540 | ConfigHdr,\r | |
541 | &StrBufferLen,\r | |
542 | Guid,\r | |
543 | Name,\r | |
544 | DriverHandle\r | |
545 | );\r | |
546 | }\r | |
547 | \r | |
548 | if (EFI_ERROR (Status)) {\r | |
549 | return Status;\r | |
550 | }\r | |
551 | \r | |
552 | //\r | |
553 | // Construct <ConfigResp>\r | |
554 | //\r | |
555 | NeedFreeConfigRequest = FALSE;\r | |
556 | if (ConfigRequest == NULL) {\r | |
557 | //\r | |
558 | // If ConfigRequest is set to NULL, export all configurable elements in BlockNameArray\r | |
559 | //\r | |
560 | Status = ExtractBlockName (BlockNameArray, &BlockName);\r | |
561 | if (EFI_ERROR (Status)) {\r | |
562 | return Status;\r | |
563 | }\r | |
564 | \r | |
565 | Len = StrSize (ConfigHdr);\r | |
566 | ConfigRequest = AllocateZeroPool (Len + StrSize (BlockName) - sizeof (CHAR16));\r | |
567 | StrCpy (ConfigRequest, ConfigHdr);\r | |
568 | StrCat (ConfigRequest, BlockName);\r | |
569 | NeedFreeConfigRequest = TRUE;\r | |
570 | }\r | |
571 | \r | |
572 | Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);\r | |
573 | if (EFI_ERROR (Status)) {\r | |
574 | return Status;\r | |
575 | }\r | |
576 | \r | |
577 | Status = HiiConfigRouting->BlockToConfig (\r | |
578 | HiiConfigRouting,\r | |
579 | ConfigRequest,\r | |
580 | BufferStorage,\r | |
581 | BufferStorageSize,\r | |
582 | &ConfigResp,\r | |
583 | (Progress == NULL) ? &TempStr : Progress\r | |
584 | );\r | |
585 | if (EFI_ERROR (Status)) {\r | |
586 | return Status;\r | |
587 | }\r | |
588 | \r | |
589 | //\r | |
590 | // Construct <AltResp>\r | |
591 | //\r | |
592 | DescHdr = AllocateZeroPool (NumberAltCfg * 16 * sizeof (CHAR16));\r | |
593 | StringPtr = DescHdr;\r | |
594 | AltCfg = AllocateZeroPool (NumberAltCfg * sizeof (CHAR16 *));\r | |
595 | AltRespLen = 0;\r | |
596 | VA_START (Args, NumberAltCfg);\r | |
597 | for (Index = 0; Index < NumberAltCfg; Index++) {\r | |
598 | AltCfgId = (UINT16) VA_ARG (Args, UINT16);\r | |
599 | DefaultValueArray = (UINT8 *) VA_ARG (Args, VOID *);\r | |
600 | \r | |
601 | //\r | |
602 | // '&' <ConfigHdr>\r | |
603 | //\r | |
604 | AltRespLen += (StrLen (ConfigHdr) + 1);\r | |
605 | \r | |
606 | StringPtr = DescHdr + Index * 16;\r | |
607 | StrCpy (StringPtr, L"&ALTCFG=");\r | |
608 | AltRespLen += (8 + sizeof (UINT16) * 2);\r | |
609 | \r | |
610 | StrBufferLen = 5;\r | |
611 | BufToHexString (StringPtr + 8, &StrBufferLen, (UINT8 *) &AltCfgId, sizeof (UINT16));\r | |
612 | Status = ExtractBlockConfig (DefaultValueArray, &AltCfg[Index]);\r | |
613 | if (EFI_ERROR (Status)) {\r | |
614 | return Status;\r | |
615 | }\r | |
616 | AltRespLen += StrLen (AltCfg[Index]);\r | |
617 | }\r | |
618 | VA_END (Args);\r | |
619 | \r | |
620 | //\r | |
621 | // Generate the final <ConfigAltResp>\r | |
622 | //\r | |
623 | StrBufferLen = (StrLen ((CHAR16 *) ConfigResp) + AltRespLen + 1) * sizeof (CHAR16);\r | |
624 | TempStr = AllocateZeroPool (StrBufferLen);\r | |
625 | *ConfigAltResp = TempStr;\r | |
626 | if (TempStr == NULL) {\r | |
627 | return EFI_OUT_OF_RESOURCES;\r | |
628 | }\r | |
629 | \r | |
630 | //\r | |
631 | // <ConfigAltResp> ::= <ConfigResp> ['&' <AltResp>]*\r | |
632 | //\r | |
633 | StrCpy (TempStr, ConfigResp);\r | |
634 | for (Index = 0; Index < NumberAltCfg; Index++) {\r | |
635 | StrCat (TempStr, L"&");\r | |
636 | StrCat (TempStr, ConfigHdr);\r | |
637 | StrCat (TempStr, DescHdr + Index * 16);\r | |
638 | StrCat (TempStr, AltCfg[Index]);\r | |
639 | \r | |
640 | gBS->FreePool (AltCfg[Index]);\r | |
641 | }\r | |
642 | \r | |
643 | if (NeedFreeConfigRequest) {\r | |
644 | gBS->FreePool (ConfigRequest);\r | |
645 | }\r | |
646 | gBS->FreePool (ConfigHdr);\r | |
647 | gBS->FreePool (ConfigResp);\r | |
648 | gBS->FreePool (DescHdr);\r | |
649 | gBS->FreePool (AltCfg);\r | |
650 | \r | |
651 | return EFI_SUCCESS;\r | |
652 | }\r | |
653 | \r | |
654 | /**\r | |
655 | Swap bytes in the buffer. This is a internal function.\r | |
656 | \r | |
657 | @param Buffer Binary buffer.\r | |
658 | @param BufferSize Size of the buffer in bytes.\r | |
659 | \r | |
660 | @return None.\r | |
661 | \r | |
662 | **/\r | |
663 | VOID\r | |
664 | SwapBuffer (\r | |
665 | IN OUT UINT8 *Buffer,\r | |
666 | IN UINTN BufferSize\r | |
667 | )\r | |
668 | {\r | |
669 | UINTN Index;\r | |
670 | UINT8 Temp;\r | |
671 | UINTN SwapCount;\r | |
672 | \r | |
673 | SwapCount = BufferSize / 2;\r | |
674 | for (Index = 0; Index < SwapCount; Index++) {\r | |
675 | Temp = Buffer[Index];\r | |
676 | Buffer[Index] = Buffer[BufferSize - 1 - Index];\r | |
677 | Buffer[BufferSize - 1 - Index] = Temp;\r | |
678 | }\r | |
679 | }\r | |
680 | \r | |
681 | /**\r | |
682 | Converts the unicode character of the string from uppercase to lowercase.\r | |
683 | This is a internal function.\r | |
684 | \r | |
685 | @param Str String to be converted\r | |
686 | \r | |
687 | **/\r | |
688 | VOID\r | |
689 | EFIAPI\r | |
690 | ToLower (\r | |
691 | IN OUT CHAR16 *Str\r | |
692 | )\r | |
693 | {\r | |
694 | CHAR16 *Ptr;\r | |
695 | \r | |
696 | for (Ptr = Str; *Ptr != L'\0'; Ptr++) {\r | |
697 | if (*Ptr >= L'A' && *Ptr <= L'Z') {\r | |
698 | *Ptr = (CHAR16) (*Ptr - L'A' + L'a');\r | |
699 | }\r | |
700 | }\r | |
701 | }\r | |
702 | \r | |
703 | \r | |
704 | /**\r | |
705 | Converts binary buffer to Unicode string in reversed byte order from BufToHexString().\r | |
706 | \r | |
707 | @param Str String for output\r | |
708 | @param Buffer Binary buffer.\r | |
709 | @param BufferSize Size of the buffer in bytes.\r | |
710 | \r | |
711 | @retval EFI_SUCCESS The function completed successfully.\r | |
712 | @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.\r | |
713 | \r | |
714 | **/\r | |
715 | EFI_STATUS\r | |
716 | EFIAPI\r | |
717 | BufInReverseOrderToHexString (\r | |
718 | IN OUT CHAR16 *Str,\r | |
719 | IN UINT8 *Buffer,\r | |
720 | IN UINTN BufferSize\r | |
721 | )\r | |
722 | {\r | |
723 | EFI_STATUS Status;\r | |
724 | UINT8 *NewBuffer;\r | |
725 | UINTN StrBufferLen;\r | |
726 | \r | |
727 | NewBuffer = AllocateCopyPool (BufferSize, Buffer);\r | |
728 | if (NewBuffer == NULL) {\r | |
729 | return EFI_OUT_OF_RESOURCES;\r | |
730 | }\r | |
731 | SwapBuffer (NewBuffer, BufferSize);\r | |
732 | \r | |
733 | StrBufferLen = BufferSize * sizeof (CHAR16) + 1;\r | |
734 | Status = BufToHexString (Str, &StrBufferLen, NewBuffer, BufferSize);\r | |
735 | \r | |
736 | FreePool (NewBuffer);\r | |
737 | //\r | |
738 | // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r | |
739 | //\r | |
740 | ToLower (Str);\r | |
741 | \r | |
742 | return Status;\r | |
743 | }\r | |
744 | \r | |
745 | \r | |
746 | /**\r | |
747 | Converts Hex String to binary buffer in reversed byte order from HexStringToBuf().\r | |
748 | \r | |
749 | @param Buffer Pointer to buffer that receives the data.\r | |
750 | @param BufferSize Length in bytes of the buffer to hold converted\r | |
751 | data. If routine return with EFI_SUCCESS,\r | |
752 | containing length of converted data. If routine\r | |
753 | return with EFI_BUFFER_TOO_SMALL, containg length\r | |
754 | of buffer desired.\r | |
755 | @param Str String to be converted from.\r | |
756 | \r | |
757 | @retval EFI_SUCCESS The function completed successfully.\r | |
758 | @retval RETURN_BUFFER_TOO_SMALL The input BufferSize is too small to hold the output. BufferSize\r | |
759 | will be updated to the size required for the converstion.\r | |
760 | \r | |
761 | **/\r | |
762 | EFI_STATUS\r | |
763 | EFIAPI\r | |
764 | HexStringToBufInReverseOrder (\r | |
765 | IN OUT UINT8 *Buffer,\r | |
766 | IN OUT UINTN *BufferSize,\r | |
767 | IN CHAR16 *Str\r | |
768 | )\r | |
769 | {\r | |
770 | EFI_STATUS Status;\r | |
771 | UINTN ConvertedStrLen;\r | |
772 | \r | |
773 | ConvertedStrLen = 0;\r | |
774 | Status = HexStringToBuf (Buffer, BufferSize, Str, &ConvertedStrLen);\r | |
775 | if (!EFI_ERROR (Status)) {\r | |
776 | SwapBuffer (Buffer, (ConvertedStrLen + 1) / 2);\r | |
777 | }\r | |
778 | \r | |
779 | return Status;\r | |
780 | }\r | |
781 | \r | |
782 | /**\r | |
783 | Convert binary representation Config string (e.g. "0041004200430044") to the\r | |
784 | original string (e.g. "ABCD"). Config string appears in <ConfigHdr> (i.e.\r | |
785 | "&NAME=<string>"), or Name/Value pair in <ConfigBody> (i.e. "label=<string>").\r | |
786 | \r | |
787 | @param UnicodeString Original Unicode string.\r | |
788 | @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string.\r | |
789 | Includes tailing '\0' character.\r | |
790 | On output:\r | |
791 | If return EFI_SUCCESS, containing length of Unicode string buffer.\r | |
792 | If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.\r | |
793 | @param ConfigString Binary representation of Unicode String, <string> := (<HexCh>4)+\r | |
794 | \r | |
795 | @retval EFI_SUCCESS Operation completes successfully.\r | |
796 | @retval EFI_BUFFER_TOO_SMALL The string buffer is too small.\r | |
797 | \r | |
798 | **/\r | |
799 | EFI_STATUS\r | |
800 | EFIAPI\r | |
801 | ConfigStringToUnicode (\r | |
802 | IN OUT CHAR16 *UnicodeString,\r | |
803 | IN OUT UINTN *StrBufferLen,\r | |
804 | IN CHAR16 *ConfigString\r | |
805 | )\r | |
806 | {\r | |
807 | UINTN Index;\r | |
808 | UINTN Len;\r | |
809 | UINTN BufferSize;\r | |
810 | CHAR16 BackupChar;\r | |
811 | \r | |
812 | Len = StrLen (ConfigString) / 4;\r | |
813 | BufferSize = (Len + 1) * sizeof (CHAR16);\r | |
814 | \r | |
815 | if (*StrBufferLen < BufferSize) {\r | |
816 | *StrBufferLen = BufferSize;\r | |
817 | return EFI_BUFFER_TOO_SMALL;\r | |
818 | }\r | |
819 | \r | |
820 | *StrBufferLen = BufferSize;\r | |
821 | \r | |
822 | for (Index = 0; Index < Len; Index++) {\r | |
823 | BackupChar = ConfigString[4];\r | |
824 | ConfigString[4] = L'\0';\r | |
825 | \r | |
826 | HexStringToBuf ((UINT8 *) UnicodeString, &BufferSize, ConfigString, NULL);\r | |
827 | \r | |
828 | ConfigString[4] = BackupChar;\r | |
829 | \r | |
830 | ConfigString += 4;\r | |
831 | UnicodeString += 1;\r | |
832 | }\r | |
833 | \r | |
834 | //\r | |
835 | // Add tailing '\0' character\r | |
836 | //\r | |
837 | *UnicodeString = L'\0';\r | |
838 | \r | |
839 | return EFI_SUCCESS;\r | |
840 | }\r | |
841 | \r | |
842 | /**\r | |
843 | Convert Unicode string to binary representation Config string, e.g.\r | |
844 | "ABCD" => "0041004200430044". Config string appears in <ConfigHdr> (i.e.\r | |
845 | "&NAME=<string>"), or Name/Value pair in <ConfigBody> (i.e. "label=<string>").\r | |
846 | \r | |
847 | @param ConfigString Binary representation of Unicode String, <string> := (<HexCh>4)+\r | |
848 | @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string.\r | |
849 | Includes tailing '\0' character.\r | |
850 | On output:\r | |
851 | If return EFI_SUCCESS, containing length of Unicode string buffer.\r | |
852 | If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired.\r | |
853 | @param UnicodeString Original Unicode string.\r | |
854 | \r | |
855 | @retval EFI_SUCCESS Operation completes successfully.\r | |
856 | @retval EFI_BUFFER_TOO_SMALL The string buffer is too small.\r | |
857 | \r | |
858 | **/\r | |
859 | EFI_STATUS\r | |
860 | EFIAPI\r | |
861 | UnicodeToConfigString (\r | |
862 | IN OUT CHAR16 *ConfigString,\r | |
863 | IN OUT UINTN *StrBufferLen,\r | |
864 | IN CHAR16 *UnicodeString\r | |
865 | )\r | |
866 | {\r | |
867 | UINTN Index;\r | |
868 | UINTN Len;\r | |
869 | UINTN BufferSize;\r | |
870 | CHAR16 *String;\r | |
871 | \r | |
872 | Len = StrLen (UnicodeString);\r | |
873 | BufferSize = (Len * 4 + 1) * sizeof (CHAR16);\r | |
874 | \r | |
875 | if (*StrBufferLen < BufferSize) {\r | |
876 | *StrBufferLen = BufferSize;\r | |
877 | return EFI_BUFFER_TOO_SMALL;\r | |
878 | }\r | |
879 | \r | |
880 | *StrBufferLen = BufferSize;\r | |
881 | String = ConfigString;\r | |
882 | \r | |
883 | for (Index = 0; Index < Len; Index++) {\r | |
884 | BufToHexString (ConfigString, &BufferSize, (UINT8 *) UnicodeString, 2);\r | |
885 | \r | |
886 | ConfigString += 4;\r | |
887 | UnicodeString += 1;\r | |
888 | }\r | |
889 | \r | |
890 | //\r | |
891 | // Add tailing '\0' character\r | |
892 | //\r | |
893 | *ConfigString = L'\0';\r | |
894 | \r | |
895 | //\r | |
896 | // Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.\r | |
897 | //\r | |
898 | ToLower (String); \r | |
899 | return EFI_SUCCESS;\r | |
900 | }\r | |
901 | \r | |
902 | /**\r | |
903 | Construct <ConfigHdr> using routing information GUID/NAME/PATH.\r | |
904 | \r | |
905 | @param ConfigHdr Pointer to the ConfigHdr string.\r | |
906 | @param StrBufferLen On input: Length in bytes of buffer to hold the\r | |
907 | ConfigHdr string. Includes tailing '\0' character.\r | |
908 | On output: If return EFI_SUCCESS, containing\r | |
909 | length of ConfigHdr string buffer. If return\r | |
910 | EFI_BUFFER_TOO_SMALL, containg length of string\r | |
911 | buffer desired.\r | |
912 | @param Guid Routing information: GUID.\r | |
913 | @param Name Routing information: NAME.\r | |
914 | @param DriverHandle Driver handle which contains the routing\r | |
915 | information: PATH.\r | |
916 | \r | |
917 | @retval EFI_SUCCESS Operation completes successfully.\r | |
918 | @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small.\r | |
919 | \r | |
920 | **/\r | |
921 | EFI_STATUS\r | |
922 | EFIAPI\r | |
923 | ConstructConfigHdr (\r | |
924 | IN OUT CHAR16 *ConfigHdr,\r | |
925 | IN OUT UINTN *StrBufferLen,\r | |
926 | IN CONST EFI_GUID *Guid,\r | |
927 | IN CHAR16 *Name, OPTIONAL\r | |
928 | IN EFI_HANDLE *DriverHandle\r | |
929 | )\r | |
930 | {\r | |
931 | EFI_STATUS Status;\r | |
932 | UINTN NameStrLen;\r | |
933 | UINTN DevicePathSize;\r | |
934 | UINTN BufferSize;\r | |
935 | CHAR16 *StrPtr;\r | |
936 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
937 | \r | |
938 | if (Name == NULL) {\r | |
939 | //\r | |
940 | // There will be no "NAME" in <ConfigHdr> for Name/Value storage\r | |
941 | //\r | |
942 | NameStrLen = 0;\r | |
943 | } else {\r | |
944 | //\r | |
945 | // For buffer storage\r | |
946 | //\r | |
947 | NameStrLen = StrLen (Name);\r | |
948 | }\r | |
949 | \r | |
950 | //\r | |
951 | // Retrieve DevicePath Protocol associated with this HiiPackageList\r | |
952 | //\r | |
953 | Status = gBS->HandleProtocol (\r | |
954 | DriverHandle,\r | |
955 | &gEfiDevicePathProtocolGuid,\r | |
956 | (VOID **) &DevicePath\r | |
957 | );\r | |
958 | if (EFI_ERROR (Status)) {\r | |
959 | return Status;\r | |
960 | }\r | |
961 | \r | |
962 | DevicePathSize = GetDevicePathSize (DevicePath);\r | |
963 | \r | |
964 | //\r | |
965 | // GUID=<HexCh>32&NAME=<Char>NameStrLen&PATH=<HexChar>DevicePathStrLen <NULL>\r | |
966 | // | 5 | 32 | 6 | NameStrLen*4 | 6 | DevicePathStrLen | 1 |\r | |
967 | //\r | |
968 | BufferSize = (5 + 32 + 6 + NameStrLen * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16);\r | |
969 | if (*StrBufferLen < BufferSize) {\r | |
970 | *StrBufferLen = BufferSize;\r | |
971 | return EFI_BUFFER_TOO_SMALL;\r | |
972 | }\r | |
973 | \r | |
974 | *StrBufferLen = BufferSize;\r | |
975 | \r | |
976 | StrPtr = ConfigHdr;\r | |
977 | \r | |
978 | StrCpy (StrPtr, L"GUID=");\r | |
979 | StrPtr += 5;\r | |
980 | BufInReverseOrderToHexString (StrPtr, (UINT8 *) Guid, sizeof (EFI_GUID));\r | |
981 | StrPtr += 32;\r | |
982 | \r | |
983 | //\r | |
984 | // Convert name string, e.g. name "ABCD" => "&NAME=0041004200430044"\r | |
985 | //\r | |
986 | StrCpy (StrPtr, L"&NAME=");\r | |
987 | StrPtr += 6;\r | |
988 | if (Name != NULL) {\r | |
989 | BufferSize = (NameStrLen * 4 + 1) * sizeof (CHAR16);\r | |
990 | UnicodeToConfigString (StrPtr, &BufferSize, Name);\r | |
991 | StrPtr += (NameStrLen * 4);\r | |
992 | }\r | |
993 | \r | |
994 | StrCpy (StrPtr, L"&PATH=");\r | |
995 | StrPtr += 6;\r | |
996 | BufInReverseOrderToHexString (StrPtr, (UINT8 *) DevicePath, DevicePathSize);\r | |
997 | \r | |
998 | return EFI_SUCCESS;\r | |
999 | }\r | |
1000 | \r | |
1001 | /**\r | |
1002 | Determines if the Routing data (Guid and Name) is correct in <ConfigHdr>.\r | |
1003 | \r | |
1004 | @param ConfigString Either <ConfigRequest> or <ConfigResp>.\r | |
1005 | @param StorageGuid GUID of the storage.\r | |
1006 | @param StorageName Name of the stoarge.\r | |
1007 | \r | |
1008 | @retval TRUE Routing information is correct in ConfigString.\r | |
1009 | @retval FALSE Routing information is incorrect in ConfigString.\r | |
1010 | \r | |
1011 | **/\r | |
1012 | BOOLEAN\r | |
1013 | IsConfigHdrMatch (\r | |
1014 | IN EFI_STRING ConfigString,\r | |
1015 | IN EFI_GUID *StorageGuid, OPTIONAL\r | |
1016 | IN CHAR16 *StorageName OPTIONAL\r | |
1017 | )\r | |
1018 | {\r | |
1019 | EFI_STATUS Status;\r | |
1020 | BOOLEAN Match;\r | |
1021 | EFI_GUID Guid;\r | |
1022 | CHAR16 *Name;\r | |
1023 | CHAR16 *StrPtr;\r | |
1024 | UINTN BufferSize;\r | |
1025 | \r | |
1026 | //\r | |
1027 | // <ConfigHdr> ::=\r | |
1028 | // GUID=<HexCh>32&NAME=<Char>NameStrLen&PATH=<HexChar>DevicePathStrLen <NULL>\r | |
1029 | // | 5 | 32 | 6 | NameStrLen*4 | 6 | DevicePathStrLen | 1 |\r | |
1030 | //\r | |
1031 | if (StrLen (ConfigString) <= (5 + 32 + 6)) {\r | |
1032 | return FALSE;\r | |
1033 | }\r | |
1034 | \r | |
1035 | //\r | |
1036 | // Compare GUID\r | |
1037 | //\r | |
1038 | if (StorageGuid != NULL) {\r | |
1039 | \r | |
1040 | StrPtr = ConfigString + 5 + 32;\r | |
1041 | if (*StrPtr != L'&') {\r | |
1042 | return FALSE;\r | |
1043 | }\r | |
1044 | *StrPtr = L'\0';\r | |
1045 | \r | |
1046 | BufferSize = sizeof (EFI_GUID);\r | |
1047 | Status = HexStringToBufInReverseOrder (\r | |
1048 | (UINT8 *) &Guid,\r | |
1049 | &BufferSize,\r | |
1050 | ConfigString + 5\r | |
1051 | );\r | |
1052 | *StrPtr = L'&';\r | |
1053 | \r | |
1054 | if (EFI_ERROR (Status)) {\r | |
1055 | return FALSE;\r | |
1056 | }\r | |
1057 | \r | |
1058 | if (!CompareGuid (&Guid, StorageGuid)) {\r | |
1059 | return FALSE;\r | |
1060 | }\r | |
1061 | }\r | |
1062 | \r | |
1063 | //\r | |
1064 | // Compare Name\r | |
1065 | //\r | |
1066 | Match = TRUE;\r | |
1067 | if (StorageName != NULL) {\r | |
1068 | StrPtr = ConfigString + 5 + 32 + 6;\r | |
1069 | while (*StrPtr != L'\0' && *StrPtr != L'&') {\r | |
1070 | StrPtr++;\r | |
1071 | }\r | |
1072 | if (*StrPtr != L'&') {\r | |
1073 | return FALSE;\r | |
1074 | }\r | |
1075 | \r | |
1076 | *StrPtr = L'\0';\r | |
1077 | BufferSize = (((UINTN) StrPtr) - ((UINTN) &ConfigString[5 + 32 + 6])) / 4 + sizeof (CHAR16);\r | |
1078 | Name = AllocatePool (BufferSize);\r | |
1079 | ASSERT (Name != NULL);\r | |
1080 | Status = ConfigStringToUnicode (\r | |
1081 | Name,\r | |
1082 | &BufferSize,\r | |
1083 | ConfigString + 5 + 32 + 6\r | |
1084 | );\r | |
1085 | *StrPtr = L'&';\r | |
1086 | \r | |
1087 | if (EFI_ERROR (Status) || (StrCmp (Name, StorageName) != 0)) {\r | |
1088 | Match = FALSE;\r | |
1089 | }\r | |
1090 | gBS->FreePool (Name);\r | |
1091 | }\r | |
1092 | \r | |
1093 | return Match;\r | |
1094 | }\r | |
1095 | \r | |
1096 | /**\r | |
1097 | Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string.\r | |
1098 | \r | |
1099 | @param String The string to be searched in.\r | |
1100 | @param Offset Offset in BlockName.\r | |
1101 | @param Width Width in BlockName.\r | |
1102 | \r | |
1103 | @retval TRUE Block name found.\r | |
1104 | @retval FALSE Block name not found.\r | |
1105 | \r | |
1106 | **/\r | |
1107 | BOOLEAN\r | |
1108 | EFIAPI\r | |
1109 | FindBlockName (\r | |
1110 | IN OUT CHAR16 *String,\r | |
1111 | IN UINTN Offset,\r | |
1112 | IN UINTN Width\r | |
1113 | )\r | |
1114 | {\r | |
1115 | EFI_STATUS Status;\r | |
1116 | UINTN Data;\r | |
1117 | UINTN BufferSize;\r | |
1118 | UINTN ConvertedStrLen;\r | |
1119 | \r | |
1120 | while ((String = StrStr (String, L"&OFFSET=")) != NULL) {\r | |
1121 | //\r | |
1122 | // Skip '&OFFSET='\r | |
1123 | //\r | |
1124 | String = String + 8;\r | |
1125 | \r | |
1126 | Data = 0;\r | |
1127 | BufferSize = sizeof (UINTN);\r | |
1128 | Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen);\r | |
1129 | if (EFI_ERROR (Status)) {\r | |
1130 | return FALSE;\r | |
1131 | }\r | |
1132 | String = String + ConvertedStrLen;\r | |
1133 | \r | |
1134 | if (Data != Offset) {\r | |
1135 | continue;\r | |
1136 | }\r | |
1137 | \r | |
1138 | if (StrnCmp (String, L"&WIDTH=", 7) != 0) {\r | |
1139 | return FALSE;\r | |
1140 | }\r | |
1141 | String = String + 7;\r | |
1142 | \r | |
1143 | Data = 0;\r | |
1144 | BufferSize = sizeof (UINTN);\r | |
1145 | Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen);\r | |
1146 | if (EFI_ERROR (Status)) {\r | |
1147 | return FALSE;\r | |
1148 | }\r | |
1149 | if (Data == Width) {\r | |
1150 | return TRUE;\r | |
1151 | }\r | |
1152 | \r | |
1153 | String = String + ConvertedStrLen;\r | |
1154 | }\r | |
1155 | \r | |
1156 | return FALSE;\r | |
1157 | }\r | |
1158 | \r | |
1159 | \r | |
1160 | /**\r | |
1161 | This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser.\r | |
1162 | \r | |
1163 | @param VariableGuid An optional field to indicate the target variable\r | |
1164 | GUID name to use.\r | |
1165 | @param VariableName An optional field to indicate the target\r | |
1166 | human-readable variable name.\r | |
1167 | @param BufferSize On input: Length in bytes of buffer to hold\r | |
1168 | retrived data. On output: If return\r | |
1169 | EFI_BUFFER_TOO_SMALL, containg length of buffer\r | |
1170 | desired.\r | |
1171 | @param Buffer Buffer to hold retrived data.\r | |
1172 | \r | |
1173 | @retval EFI_SUCCESS Operation completes successfully.\r | |
1174 | @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small.\r | |
1175 | @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.\r | |
1176 | \r | |
1177 | **/\r | |
1178 | EFI_STATUS\r | |
1179 | EFIAPI\r | |
1180 | GetBrowserData (\r | |
1181 | IN CONST EFI_GUID *VariableGuid, OPTIONAL\r | |
1182 | IN CONST CHAR16 *VariableName, OPTIONAL\r | |
1183 | IN OUT UINTN *BufferSize,\r | |
1184 | IN OUT UINT8 *Buffer\r | |
1185 | )\r | |
1186 | {\r | |
1187 | EFI_STATUS Status;\r | |
1188 | CONST CHAR16 *ConfigHdr;\r | |
1189 | CHAR16 *ConfigResp;\r | |
1190 | CHAR16 *StringPtr;\r | |
1191 | UINTN HeaderLen;\r | |
1192 | UINTN BufferLen;\r | |
1193 | CHAR16 *Progress;\r | |
1194 | \r | |
1195 | //\r | |
1196 | // Locate protocols for use\r | |
1197 | //\r | |
1198 | Status = LocateFormBrowser2Protocols ();\r | |
1199 | if (EFI_ERROR (Status)) {\r | |
1200 | return Status;\r | |
1201 | }\r | |
1202 | \r | |
1203 | //\r | |
1204 | // Retrive formset storage data from Form Browser\r | |
1205 | //\r | |
1206 | ConfigHdr = mFakeConfigHdr;\r | |
1207 | HeaderLen = StrLen (ConfigHdr);\r | |
1208 | \r | |
1209 | //\r | |
1210 | // First try allocate 0x4000 buffer for the formet storage data.\r | |
1211 | //\r | |
1212 | BufferLen = 0x4000;\r | |
1213 | ConfigResp = AllocateZeroPool (BufferLen + HeaderLen);\r | |
1214 | if (ConfigResp == NULL) {\r | |
1215 | BufferLen = 0;\r | |
1216 | }\r | |
1217 | \r | |
1218 | StringPtr = ConfigResp + HeaderLen;\r | |
1219 | *StringPtr = L'&';\r | |
1220 | StringPtr++;\r | |
1221 | \r | |
1222 | Status = mFormBrowser2->BrowserCallback (\r | |
1223 | mFormBrowser2,\r | |
1224 | &BufferLen,\r | |
1225 | StringPtr,\r | |
1226 | TRUE,\r | |
1227 | VariableGuid,\r | |
1228 | VariableName\r | |
1229 | );\r | |
1230 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
1231 | if (ConfigResp != NULL) {\r | |
1232 | FreePool (ConfigResp);\r | |
1233 | }\r | |
1234 | \r | |
1235 | ConfigResp = AllocateZeroPool (BufferLen + HeaderLen);\r | |
1236 | if (ConfigResp == NULL) {\r | |
1237 | return EFI_OUT_OF_RESOURCES;\r | |
1238 | }\r | |
1239 | \r | |
1240 | StringPtr = ConfigResp + HeaderLen;\r | |
1241 | *StringPtr = L'&';\r | |
1242 | StringPtr++;\r | |
1243 | \r | |
1244 | Status = mFormBrowser2->BrowserCallback (\r | |
1245 | mFormBrowser2,\r | |
1246 | &BufferLen,\r | |
1247 | StringPtr,\r | |
1248 | TRUE,\r | |
1249 | VariableGuid,\r | |
1250 | VariableName\r | |
1251 | );\r | |
1252 | }\r | |
1253 | if (EFI_ERROR (Status)) {\r | |
1254 | FreePool (ConfigResp);\r | |
1255 | return Status;\r | |
1256 | }\r | |
1257 | CopyMem (ConfigResp, ConfigHdr, HeaderLen * sizeof (UINT16));\r | |
1258 | \r | |
1259 | //\r | |
1260 | // Convert <ConfigResp> to buffer data\r | |
1261 | //\r | |
1262 | Status = mIfrSupportLibHiiConfigRouting->ConfigToBlock (\r | |
1263 | mIfrSupportLibHiiConfigRouting,\r | |
1264 | ConfigResp,\r | |
1265 | Buffer,\r | |
1266 | BufferSize,\r | |
1267 | &Progress\r | |
1268 | );\r | |
1269 | FreePool (ConfigResp);\r | |
1270 | \r | |
1271 | return Status;\r | |
1272 | }\r | |
1273 | \r | |
1274 | \r | |
1275 | /**\r | |
1276 | This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser.\r | |
1277 | \r | |
1278 | @param VariableGuid An optional field to indicate the target variable\r | |
1279 | GUID name to use.\r | |
1280 | @param VariableName An optional field to indicate the target\r | |
1281 | human-readable variable name.\r | |
1282 | @param BufferSize Length in bytes of buffer to hold retrived data.\r | |
1283 | @param Buffer Buffer to hold retrived data.\r | |
1284 | @param RequestElement An optional field to specify which part of the\r | |
1285 | buffer data will be send back to Browser. If NULL,\r | |
1286 | the whole buffer of data will be committed to\r | |
1287 | Browser. <RequestElement> ::=\r | |
1288 | &OFFSET=<Number>&WIDTH=<Number>*\r | |
1289 | \r | |
1290 | @retval EFI_SUCCESS Operation completes successfully.\r | |
1291 | @retval EFI_OUT_OF_RESOURCES There is no enough available memory space.\r | |
1292 | @retval Other Updating Browser uncommitted data failed.\r | |
1293 | \r | |
1294 | **/\r | |
1295 | EFI_STATUS\r | |
1296 | EFIAPI\r | |
1297 | SetBrowserData (\r | |
1298 | IN CONST EFI_GUID *VariableGuid, OPTIONAL\r | |
1299 | IN CONST CHAR16 *VariableName, OPTIONAL\r | |
1300 | IN UINTN BufferSize,\r | |
1301 | IN CONST UINT8 *Buffer,\r | |
1302 | IN CONST CHAR16 *RequestElement OPTIONAL\r | |
1303 | )\r | |
1304 | {\r | |
1305 | EFI_STATUS Status;\r | |
1306 | CONST CHAR16 *ConfigHdr;\r | |
1307 | CHAR16 *ConfigResp;\r | |
1308 | CHAR16 *StringPtr;\r | |
1309 | UINTN HeaderLen;\r | |
1310 | UINTN BufferLen;\r | |
1311 | CHAR16 *Progress;\r | |
1312 | CHAR16 BlockName[33];\r | |
1313 | CHAR16 *ConfigRequest;\r | |
1314 | CONST CHAR16 *Request;\r | |
1315 | \r | |
1316 | //\r | |
1317 | // Locate protocols for use\r | |
1318 | //\r | |
1319 | Status = LocateFormBrowser2Protocols ();\r | |
1320 | if (EFI_ERROR (Status)) {\r | |
1321 | return Status;\r | |
1322 | }\r | |
1323 | \r | |
1324 | //\r | |
1325 | // Prepare <ConfigRequest>\r | |
1326 | //\r | |
1327 | ConfigHdr = mFakeConfigHdr;\r | |
1328 | HeaderLen = StrLen (ConfigHdr);\r | |
1329 | \r | |
1330 | if (RequestElement == NULL) {\r | |
1331 | //\r | |
1332 | // RequestElement not specified, use "&OFFSET=0&WIDTH=<BufferSize>" as <BlockName>\r | |
1333 | //\r | |
1334 | BlockName[0] = L'\0';\r | |
1335 | StrCpy (BlockName, L"&OFFSET=0&WIDTH=");\r | |
1336 | \r | |
1337 | //\r | |
1338 | // String lenghth of L"&OFFSET=0&WIDTH=" is 16\r | |
1339 | //\r | |
1340 | StringPtr = BlockName + 16;\r | |
1341 | BufferLen = sizeof (BlockName) - (16 * sizeof (CHAR16));\r | |
1342 | BufToHexString (StringPtr, &BufferLen, (UINT8 *) &BufferSize, sizeof (UINTN));\r | |
1343 | \r | |
1344 | Request = BlockName;\r | |
1345 | } else {\r | |
1346 | Request = RequestElement;\r | |
1347 | }\r | |
1348 | \r | |
1349 | BufferLen = HeaderLen * sizeof (CHAR16) + StrSize (Request);\r | |
1350 | ConfigRequest = AllocateZeroPool (BufferLen);\r | |
1351 | if (ConfigRequest == NULL) {\r | |
1352 | return EFI_OUT_OF_RESOURCES;\r | |
1353 | }\r | |
1354 | \r | |
1355 | CopyMem (ConfigRequest, ConfigHdr, HeaderLen * sizeof (CHAR16));\r | |
1356 | StringPtr = ConfigRequest + HeaderLen;\r | |
1357 | StrCpy (StringPtr, Request);\r | |
1358 | \r | |
1359 | //\r | |
1360 | // Convert buffer to <ConfigResp>\r | |
1361 | //\r | |
1362 | Status = mIfrSupportLibHiiConfigRouting->BlockToConfig (\r | |
1363 | mIfrSupportLibHiiConfigRouting,\r | |
1364 | ConfigRequest,\r | |
1365 | Buffer,\r | |
1366 | BufferSize,\r | |
1367 | &ConfigResp,\r | |
1368 | &Progress\r | |
1369 | );\r | |
1370 | if (EFI_ERROR (Status)) {\r | |
1371 | FreePool (ConfigRequest);\r | |
1372 | return Status;\r | |
1373 | }\r | |
1374 | \r | |
1375 | //\r | |
1376 | // Skip <ConfigHdr> and '&'\r | |
1377 | //\r | |
1378 | StringPtr = ConfigResp + HeaderLen + 1;\r | |
1379 | \r | |
1380 | //\r | |
1381 | // Change uncommitted data in Browser\r | |
1382 | //\r | |
1383 | Status = mFormBrowser2->BrowserCallback (\r | |
1384 | mFormBrowser2,\r | |
1385 | &BufferSize,\r | |
1386 | StringPtr,\r | |
1387 | FALSE,\r | |
1388 | VariableGuid,\r | |
1389 | VariableName\r | |
1390 | );\r | |
1391 | FreePool (ConfigRequest);\r | |
1392 | return Status;\r | |
1393 | }\r |