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