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