]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpBootDxe/HttpBootConfig.c
NetworkPkg: Replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootConfig.c
CommitLineData
fa848a40
FS
1/** @file\r
2 Helper functions for configuring or getting the parameters relating to HTTP Boot.\r
3\r
4Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "HttpBootDxe.h"\r
50a65824 16#include <Library/UefiBootManagerLib.h>\r
fa848a40
FS
17\r
18CHAR16 mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA";\r
19\r
20/**\r
21 Add new boot option for HTTP boot.\r
22\r
23 @param[in] Private Pointer to the driver private data.\r
24 @param[in] UsingIpv6 Set to TRUE if creating boot option for IPv6.\r
25 @param[in] Description The description text of the boot option.\r
26 @param[in] Uri The URI string of the boot file.\r
27 \r
28 @retval EFI_SUCCESS The boot option is created successfully.\r
29 @retval Others Failed to create new boot option.\r
30\r
31**/\r
32EFI_STATUS\r
33HttpBootAddBootOption (\r
34 IN HTTP_BOOT_PRIVATE_DATA *Private,\r
35 IN BOOLEAN UsingIpv6,\r
36 IN CHAR16 *Description,\r
37 IN CHAR16 *Uri\r
38 )\r
39{\r
50a65824
FS
40 EFI_DEV_PATH *Node;\r
41 EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r
42 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
43 UINTN Length;\r
44 CHAR8 AsciiUri[URI_STR_MAX_SIZE];\r
45 EFI_STATUS Status;\r
46 UINTN Index;\r
47 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
48\r
fa848a40 49 NewDevicePath = NULL;\r
fa848a40
FS
50 Node = NULL;\r
51 TmpDevicePath = NULL;\r
fa848a40
FS
52\r
53 if (StrLen (Description) == 0) {\r
54 return EFI_INVALID_PARAMETER;\r
55 }\r
56\r
57 //\r
58 // Convert the scheme to all lower case.\r
59 //\r
60 for (Index = 0; Index < StrLen (Uri); Index++) {\r
61 if (Uri[Index] == L':') {\r
62 break;\r
63 }\r
64 if (Uri[Index] >= L'A' && Uri[Index] <= L'Z') {\r
65 Uri[Index] -= (CHAR16)(L'A' - L'a');\r
66 }\r
67 }\r
68\r
69 //\r
0aa0beca 70 // Only accept empty URI, or http and https URI.\r
fa848a40 71 //\r
0aa0beca 72 if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) {\r
fa848a40
FS
73 return EFI_INVALID_PARAMETER;\r
74 }\r
75 \r
76 //\r
77 // Create a new device path by appending the IP node and URI node to\r
78 // the driver's parent device path\r
79 //\r
80 if (!UsingIpv6) {\r
81 Node = AllocateZeroPool (sizeof (IPv4_DEVICE_PATH));\r
82 if (Node == NULL) {\r
83 Status = EFI_OUT_OF_RESOURCES;\r
84 goto ON_EXIT;\r
85 }\r
86 Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH;\r
87 Node->Ipv4.Header.SubType = MSG_IPv4_DP;\r
88 SetDevicePathNodeLength (Node, sizeof (IPv4_DEVICE_PATH));\r
89 } else {\r
90 Node = AllocateZeroPool (sizeof (IPv6_DEVICE_PATH));\r
91 if (Node == NULL) {\r
92 Status = EFI_OUT_OF_RESOURCES;\r
93 goto ON_EXIT;\r
94 }\r
95 Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH;\r
96 Node->Ipv6.Header.SubType = MSG_IPv6_DP;\r
97 SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));\r
98 }\r
99 TmpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r
100 FreePool (Node);\r
101 if (TmpDevicePath == NULL) {\r
102 return EFI_OUT_OF_RESOURCES;\r
103 }\r
104 //\r
105 // Update the URI node with the input boot file URI.\r
106 //\r
b9679cd7 107 UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri));\r
fa848a40
FS
108 Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (AsciiUri);\r
109 Node = AllocatePool (Length);\r
110 if (Node == NULL) {\r
111 Status = EFI_OUT_OF_RESOURCES;\r
112 FreePool (TmpDevicePath);\r
113 goto ON_EXIT;\r
114 }\r
115 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
116 Node->DevPath.SubType = MSG_URI_DP;\r
117 SetDevicePathNodeLength (Node, Length);\r
118 CopyMem ((UINT8*) Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), AsciiUri, AsciiStrSize (AsciiUri));\r
119 NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r
120 FreePool (Node);\r
121 FreePool (TmpDevicePath);\r
122 if (NewDevicePath == NULL) {\r
123 Status = EFI_OUT_OF_RESOURCES;\r
124 goto ON_EXIT;\r
125 }\r
126\r
127 //\r
50a65824 128 // Add a new load option.\r
fa848a40 129 //\r
50a65824
FS
130 Status = EfiBootManagerInitializeLoadOption (\r
131 &NewOption,\r
132 LoadOptionNumberUnassigned,\r
133 LoadOptionTypeBoot,\r
134 LOAD_OPTION_ACTIVE,\r
135 Description,\r
136 NewDevicePath,\r
137 NULL,\r
138 0\r
139 );\r
fa848a40
FS
140 if (EFI_ERROR (Status)) {\r
141 goto ON_EXIT;\r
142 }\r
143\r
50a65824 144 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
a1522257 145 EfiBootManagerFreeLoadOption (&NewOption);\r
fa848a40
FS
146\r
147ON_EXIT:\r
148\r
fa848a40
FS
149 if (NewDevicePath != NULL) {\r
150 FreePool (NewDevicePath);\r
151 }\r
152\r
153 return Status;\r
154}\r
155\r
156/**\r
157 \r
158 This function allows the caller to request the current\r
159 configuration for one or more named elements. The resulting\r
160 string is in <ConfigAltResp> format. Also, any and all alternative\r
161 configuration strings shall be appended to the end of the\r
162 current configuration string. If they are, they must appear\r
163 after the current configuration. They must contain the same\r
164 routing (GUID, NAME, PATH) as the current configuration string.\r
165 They must have an additional description indicating the type of\r
166 alternative configuration the string represents,\r
167 "ALTCFG=<StringToken>". That <StringToken> (when\r
168 converted from Hex UNICODE to binary) is a reference to a\r
169 string in the associated string pack.\r
170\r
171 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
172\r
173 @param[in] Request A null-terminated Unicode string in\r
174 <ConfigRequest> format. Note that this\r
175 includes the routing information as well as\r
176 the configurable name / value pairs. It is\r
177 invalid for this string to be in\r
178 <MultiConfigRequest> format.\r
179\r
180 @param[out] Progress On return, points to a character in the\r
181 Request string. Points to the string's null\r
182 terminator if request was successful. Points\r
183 to the most recent "&" before the first\r
184 failing name / value pair (or the beginning\r
185 of the string if the failure is in the first\r
186 name / value pair) if the request was not successful. \r
187\r
188 @param[out] Results A null-terminated Unicode string in\r
189 <ConfigAltResp> format which has all values\r
190 filled in for the names in the Request string.\r
191 String to be allocated by the called function.\r
192\r
193 @retval EFI_SUCCESS The Results string is filled with the\r
194 values corresponding to all requested\r
195 names.\r
196\r
197 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
198 parts of the results that must be\r
199 stored awaiting possible future\r
200 protocols.\r
201\r
202 @retval EFI_INVALID_PARAMETER For example, passing in a NULL\r
203 for the Request parameter\r
204 would result in this type of\r
205 error. In this case, the\r
206 Progress parameter would be\r
207 set to NULL. \r
208\r
209 @retval EFI_NOT_FOUND Routing data doesn't match any\r
210 known driver. Progress set to the\r
211 first character in the routing header.\r
212 Note: There is no requirement that the\r
213 driver validate the routing data. It\r
214 must skip the <ConfigHdr> in order to\r
215 process the names.\r
216\r
217 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r
218 to most recent "&" before the\r
219 error or the beginning of the\r
220 string.\r
221\r
222 @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r
223 to the & before the name in\r
224 question.\r
225\r
226**/\r
227EFI_STATUS\r
228EFIAPI\r
229HttpBootFormExtractConfig (\r
230 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
231 IN CONST EFI_STRING Request,\r
232 OUT EFI_STRING *Progress,\r
233 OUT EFI_STRING *Results\r
234 )\r
235{\r
236 EFI_STATUS Status;\r
237 UINTN BufferSize;\r
238 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
239 EFI_STRING ConfigRequestHdr;\r
240 EFI_STRING ConfigRequest;\r
241 BOOLEAN AllocatedRequest;\r
242 UINTN Size;\r
243\r
244 if (Progress == NULL || Results == NULL) {\r
245 return EFI_INVALID_PARAMETER;\r
246 }\r
247\r
248 *Progress = Request;\r
249 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gHttpBootConfigGuid, mHttpBootConfigStorageName)) {\r
250 return EFI_NOT_FOUND;\r
251 }\r
252 \r
253 ConfigRequestHdr = NULL;\r
254 ConfigRequest = NULL;\r
255 AllocatedRequest = FALSE;\r
256 Size = 0;\r
257\r
258 CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);\r
259 //\r
260 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
261 //\r
262 BufferSize = sizeof (HTTP_BOOT_CONFIG_IFR_NVDATA);\r
263 ZeroMem (&CallbackInfo->HttpBootNvData, BufferSize);\r
a5acc842 264 StrCpyS (CallbackInfo->HttpBootNvData.Description, DESCRIPTION_STR_MAX_SIZE / sizeof (CHAR16), HTTP_BOOT_DEFAULT_DESCRIPTION_STR);\r
fa848a40
FS
265\r
266 ConfigRequest = Request;\r
267 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
268 //\r
269 // Request has no request element, construct full request string.\r
270 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
271 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
272 //\r
273 ConfigRequestHdr = HiiConstructConfigHdr (&gHttpBootConfigGuid, mHttpBootConfigStorageName, CallbackInfo->ChildHandle);\r
274 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
275 ConfigRequest = AllocateZeroPool (Size);\r
276 ASSERT (ConfigRequest != NULL);\r
277 AllocatedRequest = TRUE;\r
278 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
279 FreePool (ConfigRequestHdr);\r
280 }\r
281\r
282 Status = gHiiConfigRouting->BlockToConfig (\r
283 gHiiConfigRouting,\r
284 ConfigRequest,\r
285 (UINT8 *) &CallbackInfo->HttpBootNvData,\r
286 BufferSize,\r
287 Results,\r
288 Progress\r
289 );\r
fa848a40
FS
290 \r
291 //\r
292 // Free the allocated config request string.\r
293 //\r
294 if (AllocatedRequest) {\r
295 FreePool (ConfigRequest);\r
296 ConfigRequest = NULL;\r
297 }\r
298 //\r
299 // Set Progress string to the original request string.\r
300 //\r
301 if (Request == NULL) {\r
302 *Progress = NULL;\r
303 } else if (StrStr (Request, L"OFFSET") == NULL) {\r
304 *Progress = Request + StrLen (Request);\r
305 }\r
306\r
307 return Status;\r
308}\r
309\r
310/**\r
311 \r
312 This function applies changes in a driver's configuration.\r
313 Input is a Configuration, which has the routing data for this\r
314 driver followed by name / value configuration pairs. The driver\r
315 must apply those pairs to its configurable storage. If the\r
316 driver's configuration is stored in a linear block of data\r
317 and the driver's name / value pairs are in <BlockConfig>\r
318 format, it may use the ConfigToBlock helper function (above) to\r
319 simplify the job.\r
320\r
321 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
322\r
323 @param[in] Configuration A null-terminated Unicode string in\r
324 <ConfigString> format. \r
325 \r
326 @param[out] Progress A pointer to a string filled in with the\r
327 offset of the most recent '&' before the\r
328 first failing name / value pair (or the\r
329 beginning of the string if the failure\r
330 is in the first name / value pair) or\r
331 the terminating NULL if all was\r
332 successful.\r
333\r
334 @retval EFI_SUCCESS The results have been distributed or are\r
335 awaiting distribution.\r
336 \r
337 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
338 parts of the results that must be\r
339 stored awaiting possible future\r
340 protocols.\r
341 \r
342 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r
343 Results parameter would result\r
344 in this type of error.\r
345 \r
346 @retval EFI_NOT_FOUND Target for the specified routing data\r
347 was not found.\r
348\r
349**/\r
350EFI_STATUS\r
351EFIAPI\r
352HttpBootFormRouteConfig (\r
353 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
354 IN CONST EFI_STRING Configuration,\r
355 OUT EFI_STRING *Progress\r
356 )\r
357{\r
358 EFI_STATUS Status;\r
359 UINTN BufferSize;\r
360 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
361 HTTP_BOOT_PRIVATE_DATA *Private;\r
362\r
363 if (Progress == NULL) {\r
364 return EFI_INVALID_PARAMETER;\r
365 }\r
366 *Progress = Configuration;\r
367\r
368 if (Configuration == NULL) {\r
369 return EFI_INVALID_PARAMETER;\r
370 }\r
371\r
372 //\r
373 // Check routing data in <ConfigHdr>.\r
374 // Note: there is no name for Name/Value storage, only GUID will be checked\r
375 //\r
376 if (!HiiIsConfigHdrMatch (Configuration, &gHttpBootConfigGuid, mHttpBootConfigStorageName)) {\r
377 return EFI_NOT_FOUND;\r
378 }\r
379\r
380 CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);\r
381 Private = HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_INFO (CallbackInfo);\r
382 \r
383 BufferSize = sizeof (HTTP_BOOT_CONFIG_IFR_NVDATA);\r
384 ZeroMem (&CallbackInfo->HttpBootNvData, BufferSize);\r
385\r
386 Status = gHiiConfigRouting->ConfigToBlock (\r
387 gHiiConfigRouting,\r
388 Configuration,\r
389 (UINT8 *) &CallbackInfo->HttpBootNvData,\r
390 &BufferSize,\r
391 Progress\r
392 );\r
393 if (EFI_ERROR (Status)) {\r
394 return Status;\r
395 }\r
396\r
397 //\r
398 // Create a new boot option according to the configuration data.\r
399 //\r
a5acc842
FS
400 HttpBootAddBootOption (\r
401 Private,\r
402 (CallbackInfo->HttpBootNvData.IpVersion == HTTP_BOOT_IP_VERSION_6) ? TRUE : FALSE,\r
403 CallbackInfo->HttpBootNvData.Description,\r
404 CallbackInfo->HttpBootNvData.Uri\r
405 );\r
fa848a40 406 \r
a5acc842 407 return EFI_SUCCESS;\r
fa848a40
FS
408}\r
409\r
410/**\r
411 \r
412 This function is called to provide results data to the driver.\r
413 This data consists of a unique key that is used to identify\r
414 which data is either being passed back or being asked for.\r
415\r
416 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
417 @param[in] Action Specifies the type of action taken by the browser.\r
418 @param[in] QuestionId A unique value which is sent to the original\r
419 exporting driver so that it can identify the type\r
420 of data to expect. The format of the data tends to \r
421 vary based on the opcode that generated the callback.\r
422 @param[in] Type The type of value for the question.\r
423 @param[in, out] Value A pointer to the data being sent to the original\r
424 exporting driver.\r
425 @param[out] ActionRequest On return, points to the action requested by the\r
426 callback function.\r
427\r
428 @retval EFI_SUCCESS The callback successfully handled the action.\r
429 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
430 variable and its data.\r
431 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
432 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
433 callback.\r
434**/\r
435EFI_STATUS\r
436EFIAPI\r
437HttpBootFormCallback (\r
438 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
439 IN EFI_BROWSER_ACTION Action,\r
440 IN EFI_QUESTION_ID QuestionId,\r
441 IN UINT8 Type,\r
442 IN OUT EFI_IFR_TYPE_VALUE *Value,\r
443 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
444 )\r
445{\r
a5acc842
FS
446 EFI_INPUT_KEY Key;\r
447 UINTN Index;\r
448 CHAR16 *Uri;\r
449 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
450 \r
451 if (This == NULL || Value == NULL) {\r
452 return EFI_INVALID_PARAMETER;\r
453 }\r
454\r
455 CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);\r
456 \r
457 if (Action != EFI_BROWSER_ACTION_CHANGING) {\r
458 return EFI_UNSUPPORTED;\r
459 }\r
460 \r
461 switch (QuestionId) {\r
462 case KEY_INITIATOR_URI:\r
463 //\r
464 // Get user input URI string\r
465 //\r
466 Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);\r
d9ba76b4
FS
467 ASSERT (Uri != NULL);\r
468 if (Uri == NULL) {\r
469 return EFI_UNSUPPORTED;\r
470 }\r
a5acc842
FS
471\r
472 //\r
473 // Convert the scheme to all lower case.\r
474 //\r
475 for (Index = 0; Index < StrLen (Uri); Index++) {\r
476 if (Uri[Index] == L':') {\r
477 break;\r
478 }\r
479 if (Uri[Index] >= L'A' && Uri[Index] <= L'Z') {\r
480 Uri[Index] -= (CHAR16)(L'A' - L'a');\r
481 }\r
482 }\r
483\r
484 //\r
485 // Set the converted URI string back\r
486 //\r
487 HiiSetString (CallbackInfo->RegisteredHandle, Value->string, Uri, NULL);\r
488\r
489 //\r
0aa0beca
FS
490 // The URI should be either an empty string (for corporate environment) ,or http(s) for home environment.\r
491 // Pop up a message box for other unsupported URI.\r
a5acc842 492 //\r
0aa0beca 493 if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) {\r
a5acc842
FS
494 CreatePopUp (\r
495 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
496 &Key,\r
497 L"ERROR: Unsupported URI!",\r
498 L"Only supports HTTP and HTTPS",\r
499 NULL\r
500 );\r
501 }\r
502\r
503 FreePool (Uri);\r
504 break;\r
505\r
506 default:\r
507 break;\r
508 }\r
509\r
510 return EFI_SUCCESS;\r
fa848a40
FS
511}\r
512\r
513/**\r
514 Initialize the configuration form.\r
515\r
516 @param[in] Private Pointer to the driver private data.\r
517\r
518 @retval EFI_SUCCESS The configuration form is initialized.\r
519 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
520\r
521**/\r
522EFI_STATUS\r
523HttpBootConfigFormInit (\r
524 IN HTTP_BOOT_PRIVATE_DATA *Private\r
525 )\r
526{\r
527 EFI_STATUS Status;\r
528 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
529 VENDOR_DEVICE_PATH VendorDeviceNode;\r
fa848a40
FS
530 CHAR16 *MacString;\r
531 CHAR16 *OldMenuString;\r
532 CHAR16 MenuString[128];\r
533\r
534 CallbackInfo = &Private->CallbackInfo;\r
535\r
536 if (CallbackInfo->Initilized) {\r
537 return EFI_SUCCESS;\r
538 }\r
539 \r
540 CallbackInfo->Signature = HTTP_BOOT_FORM_CALLBACK_INFO_SIGNATURE;\r
541\r
542 //\r
543 // Construct device path node for EFI HII Config Access protocol,\r
544 // which consists of controller physical device path and one hardware\r
545 // vendor guid node.\r
546 //\r
547 ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));\r
548 VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;\r
549 VendorDeviceNode.Header.SubType = HW_VENDOR_DP;\r
550 CopyGuid (&VendorDeviceNode.Guid, &gEfiCallerIdGuid);\r
551 SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));\r
552 CallbackInfo->HiiVendorDevicePath = AppendDevicePathNode (\r
553 Private->ParentDevicePath,\r
554 (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode\r
555 );\r
556 if (CallbackInfo->HiiVendorDevicePath == NULL) {\r
557 Status = EFI_OUT_OF_RESOURCES;\r
558 goto Error;\r
559 }\r
560\r
561 CallbackInfo->ConfigAccess.ExtractConfig = HttpBootFormExtractConfig;\r
562 CallbackInfo->ConfigAccess.RouteConfig = HttpBootFormRouteConfig;\r
563 CallbackInfo->ConfigAccess.Callback = HttpBootFormCallback;\r
564 \r
565 //\r
566 // Install Device Path Protocol and Config Access protocol to driver handle.\r
567 //\r
568 Status = gBS->InstallMultipleProtocolInterfaces (\r
569 &CallbackInfo->ChildHandle,\r
570 &gEfiDevicePathProtocolGuid,\r
571 CallbackInfo->HiiVendorDevicePath,\r
572 &gEfiHiiConfigAccessProtocolGuid,\r
573 &CallbackInfo->ConfigAccess,\r
574 NULL\r
575 );\r
fa848a40
FS
576 if (EFI_ERROR (Status)) {\r
577 goto Error;\r
578 }\r
579\r
580 //\r
581 // Publish our HII data.\r
582 //\r
583 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
584 &gHttpBootConfigGuid,\r
585 CallbackInfo->ChildHandle,\r
586 HttpBootDxeStrings,\r
587 HttpBootConfigVfrBin,\r
588 NULL\r
589 );\r
590 if (CallbackInfo->RegisteredHandle == NULL) {\r
591 Status = EFI_OUT_OF_RESOURCES;\r
592 goto Error;\r
593 }\r
594\r
595 //\r
596 // Append MAC string in the menu help string\r
597 //\r
75372581 598 Status = NetLibGetMacString (Private->Controller, NULL, &MacString);\r
fa848a40
FS
599 if (!EFI_ERROR (Status)) {\r
600 OldMenuString = HiiGetString (\r
601 CallbackInfo->RegisteredHandle, \r
602 STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP), \r
603 NULL\r
604 );\r
605 UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);\r
606 HiiSetString (\r
607 CallbackInfo->RegisteredHandle, \r
608 STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP), \r
609 MenuString, \r
610 NULL\r
611 );\r
612 \r
613 FreePool (MacString);\r
614 FreePool (OldMenuString);\r
615\r
75372581 616 CallbackInfo->Initilized = TRUE;\r
fa848a40
FS
617 return EFI_SUCCESS;\r
618 }\r
619 \r
620Error:\r
621\r
622 HttpBootConfigFormUnload (Private);\r
623 return Status;\r
624}\r
625\r
626/**\r
627 Unload the configuration form, this includes: delete all the configuration\r
628 entries, uninstall the form callback protocol, and free the resources used.\r
75372581 629 The form will only be unload completely when both IP4 and IP6 stack are stopped.\r
fa848a40
FS
630\r
631 @param[in] Private Pointer to the driver private data.\r
632\r
633 @retval EFI_SUCCESS The configuration form is unloaded.\r
634 @retval Others Failed to unload the form.\r
635\r
636**/\r
637EFI_STATUS\r
638HttpBootConfigFormUnload (\r
639 IN HTTP_BOOT_PRIVATE_DATA *Private\r
640 )\r
641{\r
642 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
643\r
75372581 644 if (Private->Ip4Nic != NULL || Private->Ip6Nic != NULL) {\r
fa848a40 645 //\r
75372581 646 // Only unload the configuration form when both IP4 and IP6 stack are stopped.\r
fa848a40 647 //\r
75372581
FS
648 return EFI_SUCCESS;\r
649 }\r
650\r
651 CallbackInfo = &Private->CallbackInfo;\r
652 if (CallbackInfo->ChildHandle != NULL) {\r
fa848a40
FS
653 //\r
654 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
655 //\r
656 gBS->UninstallMultipleProtocolInterfaces (\r
657 CallbackInfo->ChildHandle,\r
658 &gEfiDevicePathProtocolGuid,\r
659 CallbackInfo->HiiVendorDevicePath,\r
660 &gEfiHiiConfigAccessProtocolGuid,\r
661 &CallbackInfo->ConfigAccess,\r
662 NULL\r
663 );\r
664 CallbackInfo->ChildHandle = NULL;\r
665 }\r
666\r
667 if (CallbackInfo->HiiVendorDevicePath != NULL) {\r
668 FreePool (CallbackInfo->HiiVendorDevicePath);\r
669 CallbackInfo->HiiVendorDevicePath = NULL;\r
670 }\r
671\r
672 if (CallbackInfo->RegisteredHandle != NULL) {\r
673 //\r
674 // Remove HII package list\r
675 //\r
676 HiiRemovePackages (CallbackInfo->RegisteredHandle);\r
677 CallbackInfo->RegisteredHandle = NULL;\r
678 }\r
679\r
680 return EFI_SUCCESS;\r
681}\r