]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpBootDxe/HttpBootConfig.c
NetworkPkg/HttpDxe: HTTPS support over IPv4 and IPv6
[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
7c275b3c
ZL
276 if (ConfigRequest == NULL) {\r
277 return EFI_OUT_OF_RESOURCES;\r
278 }\r
fa848a40
FS
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 if (Uri == NULL) {\r
470 return EFI_UNSUPPORTED;\r
471 }\r
a5acc842
FS
472\r
473 //\r
474 // Convert the scheme to all lower case.\r
475 //\r
476 for (Index = 0; Index < StrLen (Uri); Index++) {\r
477 if (Uri[Index] == L':') {\r
478 break;\r
479 }\r
480 if (Uri[Index] >= L'A' && Uri[Index] <= L'Z') {\r
481 Uri[Index] -= (CHAR16)(L'A' - L'a');\r
482 }\r
483 }\r
484\r
485 //\r
486 // Set the converted URI string back\r
487 //\r
488 HiiSetString (CallbackInfo->RegisteredHandle, Value->string, Uri, NULL);\r
489\r
490 //\r
0aa0beca
FS
491 // The URI should be either an empty string (for corporate environment) ,or http(s) for home environment.\r
492 // Pop up a message box for other unsupported URI.\r
a5acc842 493 //\r
0aa0beca 494 if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) {\r
a5acc842
FS
495 CreatePopUp (\r
496 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
497 &Key,\r
498 L"ERROR: Unsupported URI!",\r
499 L"Only supports HTTP and HTTPS",\r
500 NULL\r
501 );\r
502 }\r
503\r
504 FreePool (Uri);\r
505 break;\r
506\r
507 default:\r
508 break;\r
509 }\r
510\r
511 return EFI_SUCCESS;\r
fa848a40
FS
512}\r
513\r
514/**\r
515 Initialize the configuration form.\r
516\r
517 @param[in] Private Pointer to the driver private data.\r
518\r
519 @retval EFI_SUCCESS The configuration form is initialized.\r
520 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
521\r
522**/\r
523EFI_STATUS\r
524HttpBootConfigFormInit (\r
525 IN HTTP_BOOT_PRIVATE_DATA *Private\r
526 )\r
527{\r
528 EFI_STATUS Status;\r
529 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
530 VENDOR_DEVICE_PATH VendorDeviceNode;\r
fa848a40
FS
531 CHAR16 *MacString;\r
532 CHAR16 *OldMenuString;\r
533 CHAR16 MenuString[128];\r
534\r
535 CallbackInfo = &Private->CallbackInfo;\r
536\r
537 if (CallbackInfo->Initilized) {\r
538 return EFI_SUCCESS;\r
539 }\r
540 \r
541 CallbackInfo->Signature = HTTP_BOOT_FORM_CALLBACK_INFO_SIGNATURE;\r
542\r
543 //\r
544 // Construct device path node for EFI HII Config Access protocol,\r
545 // which consists of controller physical device path and one hardware\r
546 // vendor guid node.\r
547 //\r
548 ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));\r
549 VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;\r
550 VendorDeviceNode.Header.SubType = HW_VENDOR_DP;\r
551 CopyGuid (&VendorDeviceNode.Guid, &gEfiCallerIdGuid);\r
552 SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));\r
553 CallbackInfo->HiiVendorDevicePath = AppendDevicePathNode (\r
554 Private->ParentDevicePath,\r
555 (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode\r
556 );\r
557 if (CallbackInfo->HiiVendorDevicePath == NULL) {\r
558 Status = EFI_OUT_OF_RESOURCES;\r
559 goto Error;\r
560 }\r
561\r
562 CallbackInfo->ConfigAccess.ExtractConfig = HttpBootFormExtractConfig;\r
563 CallbackInfo->ConfigAccess.RouteConfig = HttpBootFormRouteConfig;\r
564 CallbackInfo->ConfigAccess.Callback = HttpBootFormCallback;\r
565 \r
566 //\r
567 // Install Device Path Protocol and Config Access protocol to driver handle.\r
568 //\r
569 Status = gBS->InstallMultipleProtocolInterfaces (\r
570 &CallbackInfo->ChildHandle,\r
571 &gEfiDevicePathProtocolGuid,\r
572 CallbackInfo->HiiVendorDevicePath,\r
573 &gEfiHiiConfigAccessProtocolGuid,\r
574 &CallbackInfo->ConfigAccess,\r
575 NULL\r
576 );\r
fa848a40
FS
577 if (EFI_ERROR (Status)) {\r
578 goto Error;\r
579 }\r
580\r
581 //\r
582 // Publish our HII data.\r
583 //\r
584 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
585 &gHttpBootConfigGuid,\r
586 CallbackInfo->ChildHandle,\r
587 HttpBootDxeStrings,\r
588 HttpBootConfigVfrBin,\r
589 NULL\r
590 );\r
591 if (CallbackInfo->RegisteredHandle == NULL) {\r
592 Status = EFI_OUT_OF_RESOURCES;\r
593 goto Error;\r
594 }\r
595\r
596 //\r
597 // Append MAC string in the menu help string\r
598 //\r
75372581 599 Status = NetLibGetMacString (Private->Controller, NULL, &MacString);\r
fa848a40
FS
600 if (!EFI_ERROR (Status)) {\r
601 OldMenuString = HiiGetString (\r
602 CallbackInfo->RegisteredHandle, \r
603 STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP), \r
604 NULL\r
605 );\r
606 UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);\r
607 HiiSetString (\r
608 CallbackInfo->RegisteredHandle, \r
609 STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP), \r
610 MenuString, \r
611 NULL\r
612 );\r
613 \r
614 FreePool (MacString);\r
615 FreePool (OldMenuString);\r
616\r
75372581 617 CallbackInfo->Initilized = TRUE;\r
fa848a40
FS
618 return EFI_SUCCESS;\r
619 }\r
620 \r
621Error:\r
622\r
623 HttpBootConfigFormUnload (Private);\r
624 return Status;\r
625}\r
626\r
627/**\r
628 Unload the configuration form, this includes: delete all the configuration\r
629 entries, uninstall the form callback protocol, and free the resources used.\r
75372581 630 The form will only be unload completely when both IP4 and IP6 stack are stopped.\r
fa848a40
FS
631\r
632 @param[in] Private Pointer to the driver private data.\r
633\r
634 @retval EFI_SUCCESS The configuration form is unloaded.\r
635 @retval Others Failed to unload the form.\r
636\r
637**/\r
638EFI_STATUS\r
639HttpBootConfigFormUnload (\r
640 IN HTTP_BOOT_PRIVATE_DATA *Private\r
641 )\r
642{\r
643 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
644\r
75372581 645 if (Private->Ip4Nic != NULL || Private->Ip6Nic != NULL) {\r
fa848a40 646 //\r
75372581 647 // Only unload the configuration form when both IP4 and IP6 stack are stopped.\r
fa848a40 648 //\r
75372581
FS
649 return EFI_SUCCESS;\r
650 }\r
651\r
652 CallbackInfo = &Private->CallbackInfo;\r
653 if (CallbackInfo->ChildHandle != NULL) {\r
fa848a40
FS
654 //\r
655 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
656 //\r
657 gBS->UninstallMultipleProtocolInterfaces (\r
658 CallbackInfo->ChildHandle,\r
659 &gEfiDevicePathProtocolGuid,\r
660 CallbackInfo->HiiVendorDevicePath,\r
661 &gEfiHiiConfigAccessProtocolGuid,\r
662 &CallbackInfo->ConfigAccess,\r
663 NULL\r
664 );\r
665 CallbackInfo->ChildHandle = NULL;\r
666 }\r
667\r
668 if (CallbackInfo->HiiVendorDevicePath != NULL) {\r
669 FreePool (CallbackInfo->HiiVendorDevicePath);\r
670 CallbackInfo->HiiVendorDevicePath = NULL;\r
671 }\r
672\r
673 if (CallbackInfo->RegisteredHandle != NULL) {\r
674 //\r
675 // Remove HII package list\r
676 //\r
677 HiiRemovePackages (CallbackInfo->RegisteredHandle);\r
678 CallbackInfo->RegisteredHandle = NULL;\r
679 }\r
680\r
681 return EFI_SUCCESS;\r
682}\r