]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpBootDxe/HttpBootConfig.c
NetworkPkg: Add PCD to enable the HTTP connections switch
[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
221463c2 4Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
fa848a40
FS
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 448 EFI_INPUT_KEY Key;\r
a5acc842 449 CHAR16 *Uri;\r
221463c2
JW
450 UINTN UriLen;\r
451 CHAR8 *AsciiUri;\r
a5acc842 452 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
221463c2
JW
453 EFI_STATUS Status;\r
454\r
455 Uri = NULL;\r
456 UriLen = 0;\r
457 AsciiUri = NULL;\r
458 Status = EFI_SUCCESS;\r
a5acc842
FS
459 \r
460 if (This == NULL || Value == NULL) {\r
461 return EFI_INVALID_PARAMETER;\r
462 }\r
463\r
464 CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);\r
465 \r
466 if (Action != EFI_BROWSER_ACTION_CHANGING) {\r
467 return EFI_UNSUPPORTED;\r
468 }\r
469 \r
470 switch (QuestionId) {\r
471 case KEY_INITIATOR_URI:\r
472 //\r
473 // Get user input URI string\r
474 //\r
475 Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);\r
476\r
477 //\r
221463c2
JW
478 // The URI should be either an empty string (for corporate environment) ,or http(s) for home environment.\r
479 // Pop up a message box for the unsupported URI.\r
a5acc842 480 //\r
221463c2
JW
481 if (StrLen (Uri) != 0) {\r
482 UriLen = StrLen (Uri) + 1;\r
483 AsciiUri = AllocateZeroPool (UriLen);\r
484 if (AsciiUri == NULL) {\r
485 FreePool (Uri);\r
486 return EFI_OUT_OF_RESOURCES;\r
a5acc842 487 }\r
221463c2
JW
488\r
489 UnicodeStrToAsciiStrS (Uri, AsciiUri, UriLen);\r
490\r
491 Status = HttpBootCheckUriScheme (AsciiUri);\r
492 \r
493 if (Status == EFI_INVALID_PARAMETER) {\r
494\r
495 DEBUG ((EFI_D_ERROR, "HttpBootFormCallback: %r.\n", Status));\r
496\r
497 CreatePopUp (\r
498 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
499 &Key,\r
500 L"ERROR: Unsupported URI!",\r
501 L"Only supports HTTP and HTTPS",\r
502 NULL\r
503 ); \r
504 } else if (Status == EFI_ACCESS_DENIED) {\r
505 \r
506 DEBUG ((EFI_D_ERROR, "HttpBootFormCallback: %r.\n", Status));\r
507 \r
508 CreatePopUp (\r
509 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
510 &Key,\r
511 L"ERROR: Unsupported URI!",\r
512 L"HTTP is disabled",\r
513 NULL\r
514 );\r
a5acc842
FS
515 }\r
516 }\r
517\r
221463c2
JW
518 if (Uri != NULL) {\r
519 FreePool (Uri);\r
a5acc842
FS
520 }\r
521\r
221463c2
JW
522 if (AsciiUri != NULL) {\r
523 FreePool (AsciiUri);\r
524 } \r
525 \r
a5acc842
FS
526 break;\r
527\r
528 default:\r
529 break;\r
530 }\r
531\r
221463c2 532 return Status;\r
fa848a40
FS
533}\r
534\r
535/**\r
536 Initialize the configuration form.\r
537\r
538 @param[in] Private Pointer to the driver private data.\r
539\r
540 @retval EFI_SUCCESS The configuration form is initialized.\r
541 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
542\r
543**/\r
544EFI_STATUS\r
545HttpBootConfigFormInit (\r
546 IN HTTP_BOOT_PRIVATE_DATA *Private\r
547 )\r
548{\r
549 EFI_STATUS Status;\r
550 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
551 VENDOR_DEVICE_PATH VendorDeviceNode;\r
fa848a40
FS
552 CHAR16 *MacString;\r
553 CHAR16 *OldMenuString;\r
554 CHAR16 MenuString[128];\r
555\r
556 CallbackInfo = &Private->CallbackInfo;\r
557\r
558 if (CallbackInfo->Initilized) {\r
559 return EFI_SUCCESS;\r
560 }\r
561 \r
562 CallbackInfo->Signature = HTTP_BOOT_FORM_CALLBACK_INFO_SIGNATURE;\r
563\r
564 //\r
565 // Construct device path node for EFI HII Config Access protocol,\r
566 // which consists of controller physical device path and one hardware\r
567 // vendor guid node.\r
568 //\r
569 ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));\r
570 VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;\r
571 VendorDeviceNode.Header.SubType = HW_VENDOR_DP;\r
572 CopyGuid (&VendorDeviceNode.Guid, &gEfiCallerIdGuid);\r
573 SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));\r
574 CallbackInfo->HiiVendorDevicePath = AppendDevicePathNode (\r
575 Private->ParentDevicePath,\r
576 (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode\r
577 );\r
578 if (CallbackInfo->HiiVendorDevicePath == NULL) {\r
579 Status = EFI_OUT_OF_RESOURCES;\r
580 goto Error;\r
581 }\r
582\r
583 CallbackInfo->ConfigAccess.ExtractConfig = HttpBootFormExtractConfig;\r
584 CallbackInfo->ConfigAccess.RouteConfig = HttpBootFormRouteConfig;\r
585 CallbackInfo->ConfigAccess.Callback = HttpBootFormCallback;\r
586 \r
587 //\r
588 // Install Device Path Protocol and Config Access protocol to driver handle.\r
589 //\r
590 Status = gBS->InstallMultipleProtocolInterfaces (\r
591 &CallbackInfo->ChildHandle,\r
592 &gEfiDevicePathProtocolGuid,\r
593 CallbackInfo->HiiVendorDevicePath,\r
594 &gEfiHiiConfigAccessProtocolGuid,\r
595 &CallbackInfo->ConfigAccess,\r
596 NULL\r
597 );\r
fa848a40
FS
598 if (EFI_ERROR (Status)) {\r
599 goto Error;\r
600 }\r
601\r
602 //\r
603 // Publish our HII data.\r
604 //\r
605 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
606 &gHttpBootConfigGuid,\r
607 CallbackInfo->ChildHandle,\r
608 HttpBootDxeStrings,\r
609 HttpBootConfigVfrBin,\r
610 NULL\r
611 );\r
612 if (CallbackInfo->RegisteredHandle == NULL) {\r
613 Status = EFI_OUT_OF_RESOURCES;\r
614 goto Error;\r
615 }\r
616\r
617 //\r
618 // Append MAC string in the menu help string\r
619 //\r
75372581 620 Status = NetLibGetMacString (Private->Controller, NULL, &MacString);\r
fa848a40
FS
621 if (!EFI_ERROR (Status)) {\r
622 OldMenuString = HiiGetString (\r
623 CallbackInfo->RegisteredHandle, \r
624 STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP), \r
625 NULL\r
626 );\r
627 UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);\r
628 HiiSetString (\r
629 CallbackInfo->RegisteredHandle, \r
630 STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP), \r
631 MenuString, \r
632 NULL\r
633 );\r
634 \r
635 FreePool (MacString);\r
636 FreePool (OldMenuString);\r
637\r
75372581 638 CallbackInfo->Initilized = TRUE;\r
fa848a40
FS
639 return EFI_SUCCESS;\r
640 }\r
641 \r
642Error:\r
643\r
644 HttpBootConfigFormUnload (Private);\r
645 return Status;\r
646}\r
647\r
648/**\r
649 Unload the configuration form, this includes: delete all the configuration\r
650 entries, uninstall the form callback protocol, and free the resources used.\r
75372581 651 The form will only be unload completely when both IP4 and IP6 stack are stopped.\r
fa848a40
FS
652\r
653 @param[in] Private Pointer to the driver private data.\r
654\r
655 @retval EFI_SUCCESS The configuration form is unloaded.\r
656 @retval Others Failed to unload the form.\r
657\r
658**/\r
659EFI_STATUS\r
660HttpBootConfigFormUnload (\r
661 IN HTTP_BOOT_PRIVATE_DATA *Private\r
662 )\r
663{\r
664 HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;\r
665\r
75372581 666 if (Private->Ip4Nic != NULL || Private->Ip6Nic != NULL) {\r
fa848a40 667 //\r
75372581 668 // Only unload the configuration form when both IP4 and IP6 stack are stopped.\r
fa848a40 669 //\r
75372581
FS
670 return EFI_SUCCESS;\r
671 }\r
672\r
673 CallbackInfo = &Private->CallbackInfo;\r
674 if (CallbackInfo->ChildHandle != NULL) {\r
fa848a40
FS
675 //\r
676 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
677 //\r
678 gBS->UninstallMultipleProtocolInterfaces (\r
679 CallbackInfo->ChildHandle,\r
680 &gEfiDevicePathProtocolGuid,\r
681 CallbackInfo->HiiVendorDevicePath,\r
682 &gEfiHiiConfigAccessProtocolGuid,\r
683 &CallbackInfo->ConfigAccess,\r
684 NULL\r
685 );\r
686 CallbackInfo->ChildHandle = NULL;\r
687 }\r
688\r
689 if (CallbackInfo->HiiVendorDevicePath != NULL) {\r
690 FreePool (CallbackInfo->HiiVendorDevicePath);\r
691 CallbackInfo->HiiVendorDevicePath = NULL;\r
692 }\r
693\r
694 if (CallbackInfo->RegisteredHandle != NULL) {\r
695 //\r
696 // Remove HII package list\r
697 //\r
698 HiiRemovePackages (CallbackInfo->RegisteredHandle);\r
699 CallbackInfo->RegisteredHandle = NULL;\r
700 }\r
701\r
702 return EFI_SUCCESS;\r
703}\r