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