]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpBootDxe/HttpBootDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootDxe.c
CommitLineData
d933e70a
JW
1/** @file\r
2 Driver Binding functions implementation for UEFI HTTP boot.\r
3\r
f75a7f56 4Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
ecf98fbc 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
d933e70a
JW
6\r
7**/\r
8\r
9#include "HttpBootDxe.h"\r
10\r
11///\r
12/// Driver Binding Protocol instance\r
13///\r
d1050b9d 14EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp4DxeDriverBinding = {\r
d933e70a
JW
15 HttpBootIp4DxeDriverBindingSupported,\r
16 HttpBootIp4DxeDriverBindingStart,\r
17 HttpBootIp4DxeDriverBindingStop,\r
18 HTTP_BOOT_DXE_VERSION,\r
19 NULL,\r
20 NULL\r
21};\r
22\r
d1050b9d 23EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp6DxeDriverBinding = {\r
b659408b
ZL
24 HttpBootIp6DxeDriverBindingSupported,\r
25 HttpBootIp6DxeDriverBindingStart,\r
26 HttpBootIp6DxeDriverBindingStop,\r
27 HTTP_BOOT_DXE_VERSION,\r
28 NULL,\r
29 NULL\r
30};\r
31\r
ed247d86
JW
32/**\r
33 Check whether UNDI protocol supports IPv6.\r
34\r
35 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.\r
36 @param[out] Ipv6Support TRUE if UNDI supports IPv6.\r
37\r
38 @retval EFI_SUCCESS Get the result whether UNDI supports IPv6 by NII or AIP protocol successfully.\r
39 @retval EFI_NOT_FOUND Don't know whether UNDI supports IPv6 since NII or AIP is not available.\r
40\r
41**/\r
42EFI_STATUS\r
43HttpBootCheckIpv6Support (\r
d1050b9d
MK
44 IN HTTP_BOOT_PRIVATE_DATA *Private,\r
45 OUT BOOLEAN *Ipv6Support\r
ed247d86
JW
46 )\r
47{\r
d1050b9d
MK
48 EFI_HANDLE Handle;\r
49 EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
50 EFI_STATUS Status;\r
51 EFI_GUID *InfoTypesBuffer;\r
52 UINTN InfoTypeBufferCount;\r
53 UINTN TypeIndex;\r
54 BOOLEAN Supported;\r
55 VOID *InfoBlock;\r
56 UINTN InfoBlockSize;\r
ed247d86
JW
57\r
58 ASSERT (Private != NULL && Ipv6Support != NULL);\r
59\r
60 //\r
61 // Check whether the UNDI supports IPv6 by NII protocol.\r
62 //\r
63 if (Private->Nii != NULL) {\r
64 *Ipv6Support = Private->Nii->Ipv6Supported;\r
65 return EFI_SUCCESS;\r
66 }\r
67\r
68 //\r
69 // Get the NIC handle by SNP protocol.\r
f75a7f56 70 //\r
ed247d86
JW
71 Handle = NetLibGetSnpHandle (Private->Controller, NULL);\r
72 if (Handle == NULL) {\r
73 return EFI_NOT_FOUND;\r
74 }\r
75\r
76 Aip = NULL;\r
77 Status = gBS->HandleProtocol (\r
78 Handle,\r
79 &gEfiAdapterInformationProtocolGuid,\r
d1050b9d 80 (VOID *)&Aip\r
ed247d86 81 );\r
d1050b9d 82 if (EFI_ERROR (Status) || (Aip == NULL)) {\r
ed247d86
JW
83 return EFI_NOT_FOUND;\r
84 }\r
85\r
86 InfoTypesBuffer = NULL;\r
87 InfoTypeBufferCount = 0;\r
d1050b9d
MK
88 Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, &InfoTypeBufferCount);\r
89 if (EFI_ERROR (Status) || (InfoTypesBuffer == NULL)) {\r
ed247d86
JW
90 FreePool (InfoTypesBuffer);\r
91 return EFI_NOT_FOUND;\r
92 }\r
93\r
94 Supported = FALSE;\r
95 for (TypeIndex = 0; TypeIndex < InfoTypeBufferCount; TypeIndex++) {\r
96 if (CompareGuid (&InfoTypesBuffer[TypeIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {\r
97 Supported = TRUE;\r
98 break;\r
99 }\r
100 }\r
101\r
102 FreePool (InfoTypesBuffer);\r
103 if (!Supported) {\r
104 return EFI_NOT_FOUND;\r
105 }\r
106\r
107 //\r
108 // We now have adapter information block.\r
109 //\r
110 InfoBlock = NULL;\r
111 InfoBlockSize = 0;\r
d1050b9d
MK
112 Status = Aip->GetInformation (Aip, &gEfiAdapterInfoUndiIpv6SupportGuid, &InfoBlock, &InfoBlockSize);\r
113 if (EFI_ERROR (Status) || (InfoBlock == NULL)) {\r
ed247d86
JW
114 FreePool (InfoBlock);\r
115 return EFI_NOT_FOUND;\r
f75a7f56 116 }\r
ed247d86 117\r
d1050b9d 118 *Ipv6Support = ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *)InfoBlock)->Ipv6Support;\r
ed247d86 119 FreePool (InfoBlock);\r
f75a7f56 120\r
ed247d86
JW
121 return EFI_SUCCESS;\r
122}\r
123\r
d933e70a
JW
124/**\r
125 Destroy the HTTP child based on IPv4 stack.\r
126\r
127 @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.\r
128 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.\r
129\r
130**/\r
131VOID\r
132HttpBootDestroyIp4Children (\r
133 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
134 IN HTTP_BOOT_PRIVATE_DATA *Private\r
135 )\r
136{\r
137 ASSERT (This != NULL);\r
138 ASSERT (Private != NULL);\r
d933e70a
JW
139\r
140 if (Private->Dhcp4Child != NULL) {\r
141 gBS->CloseProtocol (\r
b659408b
ZL
142 Private->Dhcp4Child,\r
143 &gEfiDhcp4ProtocolGuid,\r
144 This->DriverBindingHandle,\r
145 Private->Controller\r
146 );\r
d933e70a
JW
147\r
148 NetLibDestroyServiceChild (\r
149 Private->Controller,\r
150 This->DriverBindingHandle,\r
151 &gEfiDhcp4ServiceBindingProtocolGuid,\r
152 Private->Dhcp4Child\r
153 );\r
154 }\r
155\r
d1050b9d 156 if ((Private->Ip6Nic == NULL) && Private->HttpCreated) {\r
d933e70a
JW
157 HttpIoDestroyIo (&Private->HttpIo);\r
158 Private->HttpCreated = FALSE;\r
159 }\r
160\r
b659408b 161 if (Private->Ip4Nic != NULL) {\r
b659408b
ZL
162 gBS->CloseProtocol (\r
163 Private->Controller,\r
164 &gEfiCallerIdGuid,\r
165 This->DriverBindingHandle,\r
166 Private->Ip4Nic->Controller\r
167 );\r
f75a7f56 168\r
b659408b
ZL
169 gBS->UninstallMultipleProtocolInterfaces (\r
170 Private->Ip4Nic->Controller,\r
171 &gEfiLoadFileProtocolGuid,\r
172 &Private->Ip4Nic->LoadFile,\r
173 &gEfiDevicePathProtocolGuid,\r
174 Private->Ip4Nic->DevicePath,\r
175 NULL\r
176 );\r
177 FreePool (Private->Ip4Nic);\r
178 Private->Ip4Nic = NULL;\r
179 }\r
b659408b
ZL
180}\r
181\r
182/**\r
183 Destroy the HTTP child based on IPv6 stack.\r
184\r
185 @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.\r
186 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.\r
187\r
188**/\r
189VOID\r
190HttpBootDestroyIp6Children (\r
191 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
192 IN HTTP_BOOT_PRIVATE_DATA *Private\r
193 )\r
194{\r
195 ASSERT (This != NULL);\r
196 ASSERT (Private != NULL);\r
f75a7f56 197\r
b659408b
ZL
198 if (Private->Ip6Child != NULL) {\r
199 gBS->CloseProtocol (\r
200 Private->Ip6Child,\r
201 &gEfiIp6ProtocolGuid,\r
202 This->DriverBindingHandle,\r
203 Private->Controller\r
204 );\r
205\r
206 NetLibDestroyServiceChild (\r
207 Private->Controller,\r
208 This->DriverBindingHandle,\r
209 &gEfiIp6ServiceBindingProtocolGuid,\r
210 Private->Ip6Child\r
211 );\r
212 }\r
213\r
214 if (Private->Dhcp6Child != NULL) {\r
215 gBS->CloseProtocol (\r
216 Private->Dhcp6Child,\r
217 &gEfiDhcp6ProtocolGuid,\r
218 This->DriverBindingHandle,\r
219 Private->Controller\r
220 );\r
d933e70a 221\r
b659408b
ZL
222 NetLibDestroyServiceChild (\r
223 Private->Controller,\r
224 This->DriverBindingHandle,\r
225 &gEfiDhcp6ServiceBindingProtocolGuid,\r
226 Private->Dhcp6Child\r
227 );\r
228 }\r
d933e70a 229\r
d1050b9d
MK
230 if ((Private->Ip4Nic == NULL) && Private->HttpCreated) {\r
231 HttpIoDestroyIo (&Private->HttpIo);\r
b659408b
ZL
232 Private->HttpCreated = FALSE;\r
233 }\r
f75a7f56 234\r
b659408b 235 if (Private->Ip6Nic != NULL) {\r
b659408b
ZL
236 gBS->CloseProtocol (\r
237 Private->Controller,\r
238 &gEfiCallerIdGuid,\r
239 This->DriverBindingHandle,\r
240 Private->Ip6Nic->Controller\r
241 );\r
f75a7f56 242\r
b659408b
ZL
243 gBS->UninstallMultipleProtocolInterfaces (\r
244 Private->Ip6Nic->Controller,\r
245 &gEfiLoadFileProtocolGuid,\r
246 &Private->Ip6Nic->LoadFile,\r
247 &gEfiDevicePathProtocolGuid,\r
248 Private->Ip6Nic->DevicePath,\r
249 NULL\r
250 );\r
251 FreePool (Private->Ip6Nic);\r
252 Private->Ip6Nic = NULL;\r
d933e70a
JW
253 }\r
254}\r
255\r
256/**\r
f75a7f56 257 Tests to see if this driver supports a given controller. If a child device is provided,\r
d933e70a
JW
258 it further tests to see if this driver supports creating a handle for the specified child device.\r
259\r
f75a7f56
LG
260 This function checks to see if the driver specified by This supports the device specified by\r
261 ControllerHandle. Drivers will typically use the device path attached to\r
262 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
263 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
264 may be called many times during platform initialization. In order to reduce boot times, the tests\r
265 performed by this function must be very small, and take as little time as possible to execute. This\r
266 function must not change the state of any hardware devices, and this function must be aware that the\r
267 device specified by ControllerHandle may already be managed by the same driver or a\r
268 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
269 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
270 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
271 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
d933e70a
JW
272 to guarantee the state of ControllerHandle is not modified by this function.\r
273\r
274 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
275 @param[in] ControllerHandle The handle of the controller to test. This handle\r
276 must support a protocol interface that supplies\r
d933e70a 277 an I/O abstraction to the driver.\r
f75a7f56
LG
278 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
279 parameter is ignored by device drivers, and is optional for bus\r
280 drivers. For bus drivers, if this parameter is not NULL, then\r
281 the bus driver must determine if the bus controller specified\r
282 by ControllerHandle and the child controller specified\r
283 by RemainingDevicePath are both supported by this\r
d933e70a
JW
284 bus driver.\r
285\r
286 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
287 RemainingDevicePath is supported by the driver specified by This.\r
288 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
289 RemainingDevicePath is already being managed by the driver\r
290 specified by This.\r
291 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
292 RemainingDevicePath is already being managed by a different\r
293 driver or an application that requires exclusive access.\r
294 Currently not implemented.\r
295 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
296 RemainingDevicePath is not supported by the driver specified by This.\r
297**/\r
298EFI_STATUS\r
299EFIAPI\r
300HttpBootIp4DxeDriverBindingSupported (\r
301 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
302 IN EFI_HANDLE ControllerHandle,\r
303 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
304 )\r
305{\r
d1050b9d 306 EFI_STATUS Status;\r
f75a7f56 307\r
d933e70a
JW
308 //\r
309 // Try to open the DHCP4, HTTP4 and Device Path protocol.\r
310 //\r
311 Status = gBS->OpenProtocol (\r
b659408b
ZL
312 ControllerHandle,\r
313 &gEfiDhcp4ServiceBindingProtocolGuid,\r
314 NULL,\r
315 This->DriverBindingHandle,\r
316 ControllerHandle,\r
317 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
318 );\r
d933e70a
JW
319 if (EFI_ERROR (Status)) {\r
320 return Status;\r
321 }\r
322\r
323 Status = gBS->OpenProtocol (\r
b659408b
ZL
324 ControllerHandle,\r
325 &gEfiHttpServiceBindingProtocolGuid,\r
326 NULL,\r
327 This->DriverBindingHandle,\r
328 ControllerHandle,\r
329 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
330 );\r
d933e70a
JW
331 if (EFI_ERROR (Status)) {\r
332 return Status;\r
333 }\r
334\r
335 Status = gBS->OpenProtocol (\r
b659408b
ZL
336 ControllerHandle,\r
337 &gEfiDevicePathProtocolGuid,\r
338 NULL,\r
339 This->DriverBindingHandle,\r
340 ControllerHandle,\r
341 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
342 );\r
d933e70a
JW
343\r
344 return Status;\r
345}\r
346\r
d933e70a
JW
347/**\r
348 Starts a device controller or a bus controller.\r
349\r
350 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
f75a7f56
LG
351 As a result, much of the error checking on the parameters to Start() has been moved into this\r
352 common boot service. It is legal to call Start() from other locations,\r
d933e70a
JW
353 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
354 1. ControllerHandle must be a valid EFI_HANDLE.\r
355 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
356 EFI_DEVICE_PATH_PROTOCOL.\r
357 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
f75a7f56 358 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
d933e70a
JW
359\r
360 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
361 @param[in] ControllerHandle The handle of the controller to start. This handle\r
362 must support a protocol interface that supplies\r
d933e70a 363 an I/O abstraction to the driver.\r
f75a7f56
LG
364 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
365 parameter is ignored by device drivers, and is optional for bus\r
366 drivers. For a bus driver, if this parameter is NULL, then handles\r
367 for all the children of Controller are created by this driver.\r
368 If this parameter is not NULL and the first Device Path Node is\r
369 not the End of Device Path Node, then only the handle for the\r
370 child device specified by the first Device Path Node of\r
d933e70a 371 RemainingDevicePath is created by this driver.\r
f75a7f56 372 If the first Device Path Node of RemainingDevicePath is\r
d933e70a
JW
373 the End of Device Path Node, no child handle is created by this\r
374 driver.\r
375\r
376 @retval EFI_SUCCESS The device was started.\r
377 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
378 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
c36b7b51 379 @retval Others The driver failed to start the device.\r
d933e70a
JW
380\r
381**/\r
382EFI_STATUS\r
383EFIAPI\r
384HttpBootIp4DxeDriverBindingStart (\r
385 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
386 IN EFI_HANDLE ControllerHandle,\r
387 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
388 )\r
389{\r
d1050b9d
MK
390 EFI_STATUS Status;\r
391 HTTP_BOOT_PRIVATE_DATA *Private;\r
392 EFI_DEV_PATH *Node;\r
393 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
394 UINT32 *Id;\r
395 BOOLEAN FirstStart;\r
ed247d86
JW
396\r
397 FirstStart = FALSE;\r
d933e70a
JW
398\r
399 Status = gBS->OpenProtocol (\r
400 ControllerHandle,\r
401 &gEfiCallerIdGuid,\r
d1050b9d 402 (VOID **)&Id,\r
d933e70a
JW
403 This->DriverBindingHandle,\r
404 ControllerHandle,\r
405 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
406 );\r
b659408b 407\r
d933e70a 408 if (!EFI_ERROR (Status)) {\r
d1050b9d 409 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
b659408b 410 } else {\r
ed247d86 411 FirstStart = TRUE;\r
f75a7f56 412\r
b659408b
ZL
413 //\r
414 // Initialize the private data structure.\r
415 //\r
416 Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));\r
417 if (Private == NULL) {\r
418 return EFI_OUT_OF_RESOURCES;\r
419 }\r
d1050b9d
MK
420\r
421 Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r
b659408b 422 Private->Controller = ControllerHandle;\r
b659408b
ZL
423 InitializeListHead (&Private->CacheList);\r
424 //\r
425 // Get the NII interface if it exists, it's not required.\r
426 //\r
427 Status = gBS->OpenProtocol (\r
428 ControllerHandle,\r
429 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
d1050b9d 430 (VOID **)&Private->Nii,\r
b659408b
ZL
431 This->DriverBindingHandle,\r
432 ControllerHandle,\r
433 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
434 );\r
435 if (EFI_ERROR (Status)) {\r
436 Private->Nii = NULL;\r
437 }\r
d933e70a 438\r
b659408b
ZL
439 //\r
440 // Open Device Path Protocol to prepare for appending IP and URI node.\r
441 //\r
442 Status = gBS->OpenProtocol (\r
443 ControllerHandle,\r
444 &gEfiDevicePathProtocolGuid,\r
d1050b9d 445 (VOID **)&Private->ParentDevicePath,\r
b659408b
ZL
446 This->DriverBindingHandle,\r
447 ControllerHandle,\r
448 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
449 );\r
450 if (EFI_ERROR (Status)) {\r
451 goto ON_ERROR;\r
452 }\r
453\r
fa848a40
FS
454 //\r
455 // Initialize the HII configuration form.\r
456 //\r
457 Status = HttpBootConfigFormInit (Private);\r
458 if (EFI_ERROR (Status)) {\r
459 goto ON_ERROR;\r
460 }\r
461\r
b659408b
ZL
462 //\r
463 // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between\r
464 // NIC handle and the private data.\r
465 //\r
466 Status = gBS->InstallProtocolInterface (\r
467 &ControllerHandle,\r
468 &gEfiCallerIdGuid,\r
469 EFI_NATIVE_INTERFACE,\r
470 &Private->Id\r
471 );\r
472 if (EFI_ERROR (Status)) {\r
473 goto ON_ERROR;\r
474 }\r
b659408b 475 }\r
f75a7f56 476\r
b659408b
ZL
477 if (Private->Ip4Nic != NULL) {\r
478 //\r
479 // Already created before\r
480 //\r
481 return EFI_SUCCESS;\r
482 }\r
f75a7f56 483\r
b659408b
ZL
484 Private->Ip4Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r
485 if (Private->Ip4Nic == NULL) {\r
ed247d86
JW
486 Status = EFI_OUT_OF_RESOURCES;\r
487 goto ON_ERROR;\r
d933e70a 488 }\r
d1050b9d 489\r
75372581
FS
490 Private->Ip4Nic->Private = Private;\r
491 Private->Ip4Nic->ImageHandle = This->DriverBindingHandle;\r
492 Private->Ip4Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r
f75a7f56 493\r
d933e70a 494 //\r
b659408b 495 // Create DHCP4 child instance.\r
d933e70a
JW
496 //\r
497 Status = NetLibCreateServiceChild (\r
498 ControllerHandle,\r
499 This->DriverBindingHandle,\r
500 &gEfiDhcp4ServiceBindingProtocolGuid,\r
501 &Private->Dhcp4Child\r
502 );\r
503 if (EFI_ERROR (Status)) {\r
504 goto ON_ERROR;\r
505 }\r
f75a7f56 506\r
d933e70a
JW
507 Status = gBS->OpenProtocol (\r
508 Private->Dhcp4Child,\r
509 &gEfiDhcp4ProtocolGuid,\r
d1050b9d 510 (VOID **)&Private->Dhcp4,\r
d933e70a
JW
511 This->DriverBindingHandle,\r
512 ControllerHandle,\r
513 EFI_OPEN_PROTOCOL_BY_DRIVER\r
514 );\r
515 if (EFI_ERROR (Status)) {\r
516 goto ON_ERROR;\r
517 }\r
f75a7f56 518\r
d933e70a
JW
519 //\r
520 // Get the Ip4Config2 protocol, it's required to configure the default gateway address.\r
521 //\r
522 Status = gBS->OpenProtocol (\r
523 ControllerHandle,\r
524 &gEfiIp4Config2ProtocolGuid,\r
d1050b9d 525 (VOID **)&Private->Ip4Config2,\r
d933e70a
JW
526 This->DriverBindingHandle,\r
527 ControllerHandle,\r
528 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
529 );\r
530 if (EFI_ERROR (Status)) {\r
531 goto ON_ERROR;\r
532 }\r
f75a7f56 533\r
d933e70a
JW
534 //\r
535 // Append IPv4 device path node.\r
536 //\r
537 Node = AllocateZeroPool (sizeof (IPv4_DEVICE_PATH));\r
538 if (Node == NULL) {\r
539 Status = EFI_OUT_OF_RESOURCES;\r
540 goto ON_ERROR;\r
541 }\r
d1050b9d
MK
542\r
543 Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH;\r
d933e70a
JW
544 Node->Ipv4.Header.SubType = MSG_IPv4_DP;\r
545 SetDevicePathNodeLength (Node, sizeof (IPv4_DEVICE_PATH));\r
546 Node->Ipv4.StaticIpAddress = FALSE;\r
d1050b9d 547 DevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);\r
d933e70a
JW
548 FreePool (Node);\r
549 if (DevicePath == NULL) {\r
550 Status = EFI_OUT_OF_RESOURCES;\r
551 goto ON_ERROR;\r
552 }\r
f75a7f56 553\r
d933e70a
JW
554 //\r
555 // Append URI device path node.\r
556 //\r
557 Node = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
558 if (Node == NULL) {\r
559 Status = EFI_OUT_OF_RESOURCES;\r
560 goto ON_ERROR;\r
561 }\r
d1050b9d
MK
562\r
563 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
d933e70a
JW
564 Node->DevPath.SubType = MSG_URI_DP;\r
565 SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
d1050b9d 566 Private->Ip4Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);\r
d933e70a
JW
567 FreePool (Node);\r
568 FreePool (DevicePath);\r
b659408b 569 if (Private->Ip4Nic->DevicePath == NULL) {\r
d933e70a
JW
570 Status = EFI_OUT_OF_RESOURCES;\r
571 goto ON_ERROR;\r
572 }\r
f75a7f56 573\r
d933e70a
JW
574 //\r
575 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r
576 //\r
b659408b 577 CopyMem (&Private->Ip4Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (EFI_LOAD_FILE_PROTOCOL));\r
d933e70a 578 Status = gBS->InstallMultipleProtocolInterfaces (\r
b659408b 579 &Private->Ip4Nic->Controller,\r
d933e70a 580 &gEfiLoadFileProtocolGuid,\r
b659408b 581 &Private->Ip4Nic->LoadFile,\r
d933e70a 582 &gEfiDevicePathProtocolGuid,\r
b659408b 583 Private->Ip4Nic->DevicePath,\r
d933e70a
JW
584 NULL\r
585 );\r
586 if (EFI_ERROR (Status)) {\r
587 goto ON_ERROR;\r
588 }\r
f75a7f56 589\r
d933e70a
JW
590 //\r
591 // Open the Caller Id child to setup a parent-child relationship between\r
b659408b 592 // real NIC handle and the HTTP boot Ipv4 NIC handle.\r
d933e70a
JW
593 //\r
594 Status = gBS->OpenProtocol (\r
595 ControllerHandle,\r
596 &gEfiCallerIdGuid,\r
d1050b9d 597 (VOID **)&Id,\r
d933e70a 598 This->DriverBindingHandle,\r
b659408b 599 Private->Ip4Nic->Controller,\r
d933e70a
JW
600 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
601 );\r
602 if (EFI_ERROR (Status)) {\r
603 goto ON_ERROR;\r
604 }\r
f75a7f56 605\r
d933e70a 606 return EFI_SUCCESS;\r
f75a7f56 607\r
d933e70a 608ON_ERROR:\r
770f9aae
JW
609 if (Private != NULL) {\r
610 if (FirstStart) {\r
611 gBS->UninstallProtocolInterface (\r
612 ControllerHandle,\r
613 &gEfiCallerIdGuid,\r
614 &Private->Id\r
615 );\r
616 }\r
f75a7f56 617\r
770f9aae
JW
618 HttpBootDestroyIp4Children (This, Private);\r
619 HttpBootConfigFormUnload (Private);\r
ed247d86 620\r
770f9aae
JW
621 if (FirstStart) {\r
622 FreePool (Private);\r
623 }\r
ed247d86 624 }\r
d933e70a
JW
625\r
626 return Status;\r
627}\r
628\r
629/**\r
630 Stops a device controller or a bus controller.\r
f75a7f56
LG
631\r
632 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
633 As a result, much of the error checking on the parameters to Stop() has been moved\r
634 into this common boot service. It is legal to call Stop() from other locations,\r
d933e70a
JW
635 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
636 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
637 same driver's Start() function.\r
638 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
639 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
640 Start() function, and the Start() function must have called OpenProtocol() on\r
641 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
f75a7f56 642\r
d933e70a 643 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
644 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
645 support a bus specific I/O protocol for the driver\r
d933e70a
JW
646 to use to stop the device.\r
647 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
f75a7f56 648 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
d933e70a
JW
649 if NumberOfChildren is 0.\r
650\r
651 @retval EFI_SUCCESS The device was stopped.\r
652 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
653\r
654**/\r
655EFI_STATUS\r
656EFIAPI\r
657HttpBootIp4DxeDriverBindingStop (\r
658 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
659 IN EFI_HANDLE ControllerHandle,\r
660 IN UINTN NumberOfChildren,\r
661 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
662 )\r
663{\r
d1050b9d
MK
664 EFI_STATUS Status;\r
665 EFI_LOAD_FILE_PROTOCOL *LoadFile;\r
666 HTTP_BOOT_PRIVATE_DATA *Private;\r
667 EFI_HANDLE NicHandle;\r
668 UINT32 *Id;\r
d933e70a
JW
669\r
670 //\r
671 // Try to get the Load File Protocol from the controller handle.\r
672 //\r
673 Status = gBS->OpenProtocol (\r
674 ControllerHandle,\r
675 &gEfiLoadFileProtocolGuid,\r
d1050b9d 676 (VOID **)&LoadFile,\r
d933e70a
JW
677 This->DriverBindingHandle,\r
678 ControllerHandle,\r
679 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
680 );\r
681 if (EFI_ERROR (Status)) {\r
682 //\r
683 // If failed, try to find the NIC handle for this controller.\r
684 //\r
685 NicHandle = HttpBootGetNicByIp4Children (ControllerHandle);\r
686 if (NicHandle == NULL) {\r
687 return EFI_SUCCESS;\r
688 }\r
689\r
690 //\r
691 // Try to retrieve the private data by the Caller Id Guid.\r
692 //\r
693 Status = gBS->OpenProtocol (\r
694 NicHandle,\r
695 &gEfiCallerIdGuid,\r
d1050b9d 696 (VOID **)&Id,\r
d933e70a
JW
697 This->DriverBindingHandle,\r
698 ControllerHandle,\r
699 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
700 );\r
701 if (EFI_ERROR (Status)) {\r
702 return Status;\r
703 }\r
d1050b9d 704\r
d933e70a
JW
705 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
706 } else {\r
d1050b9d 707 Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r
d933e70a
JW
708 NicHandle = Private->Controller;\r
709 }\r
710\r
711 //\r
712 // Disable the HTTP boot function.\r
713 //\r
714 Status = HttpBootStop (Private);\r
d1050b9d 715 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_STARTED)) {\r
d933e70a
JW
716 return Status;\r
717 }\r
718\r
719 //\r
c36b7b51 720 // Destroy all child instance and uninstall protocol interface.\r
d933e70a
JW
721 //\r
722 HttpBootDestroyIp4Children (This, Private);\r
f75a7f56 723\r
d1050b9d 724 if ((Private->Ip4Nic == NULL) && (Private->Ip6Nic == NULL)) {\r
b659408b
ZL
725 //\r
726 // Release the cached data.\r
727 //\r
728 HttpBootFreeCacheList (Private);\r
fa848a40
FS
729\r
730 //\r
731 // Unload the config form.\r
732 //\r
733 HttpBootConfigFormUnload (Private);\r
f75a7f56 734\r
b659408b
ZL
735 gBS->UninstallProtocolInterface (\r
736 NicHandle,\r
737 &gEfiCallerIdGuid,\r
738 &Private->Id\r
739 );\r
740 FreePool (Private);\r
b659408b 741 }\r
d933e70a
JW
742\r
743 return EFI_SUCCESS;\r
744}\r
745\r
746/**\r
f75a7f56 747 Tests to see if this driver supports a given controller. If a child device is provided,\r
b659408b 748 it further tests to see if this driver supports creating a handle for the specified child device.\r
d933e70a 749\r
f75a7f56
LG
750 This function checks to see if the driver specified by This supports the device specified by\r
751 ControllerHandle. Drivers will typically use the device path attached to\r
752 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
753 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
754 may be called many times during platform initialization. In order to reduce boot times, the tests\r
755 performed by this function must be very small, and take as little time as possible to execute. This\r
756 function must not change the state of any hardware devices, and this function must be aware that the\r
757 device specified by ControllerHandle may already be managed by the same driver or a\r
758 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
759 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
760 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
761 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
b659408b 762 to guarantee the state of ControllerHandle is not modified by this function.\r
d933e70a 763\r
b659408b 764 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
765 @param[in] ControllerHandle The handle of the controller to test. This handle\r
766 must support a protocol interface that supplies\r
b659408b 767 an I/O abstraction to the driver.\r
f75a7f56
LG
768 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
769 parameter is ignored by device drivers, and is optional for bus\r
770 drivers. For bus drivers, if this parameter is not NULL, then\r
771 the bus driver must determine if the bus controller specified\r
772 by ControllerHandle and the child controller specified\r
773 by RemainingDevicePath are both supported by this\r
b659408b 774 bus driver.\r
d933e70a 775\r
b659408b
ZL
776 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
777 RemainingDevicePath is supported by the driver specified by This.\r
778 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
779 RemainingDevicePath is already being managed by the driver\r
780 specified by This.\r
781 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
782 RemainingDevicePath is already being managed by a different\r
783 driver or an application that requires exclusive access.\r
784 Currently not implemented.\r
785 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
786 RemainingDevicePath is not supported by the driver specified by This.\r
d933e70a
JW
787**/\r
788EFI_STATUS\r
789EFIAPI\r
b659408b
ZL
790HttpBootIp6DxeDriverBindingSupported (\r
791 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
792 IN EFI_HANDLE ControllerHandle,\r
793 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
d933e70a
JW
794 )\r
795{\r
d1050b9d 796 EFI_STATUS Status;\r
f75a7f56 797\r
d933e70a 798 //\r
b659408b 799 // Try to open the DHCP6, HTTP and Device Path protocol.\r
d933e70a 800 //\r
b659408b
ZL
801 Status = gBS->OpenProtocol (\r
802 ControllerHandle,\r
803 &gEfiDhcp6ServiceBindingProtocolGuid,\r
804 NULL,\r
805 This->DriverBindingHandle,\r
806 ControllerHandle,\r
807 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
808 );\r
809 if (EFI_ERROR (Status)) {\r
810 return Status;\r
811 }\r
812\r
813 Status = gBS->OpenProtocol (\r
814 ControllerHandle,\r
815 &gEfiHttpServiceBindingProtocolGuid,\r
816 NULL,\r
817 This->DriverBindingHandle,\r
818 ControllerHandle,\r
819 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
820 );\r
821 if (EFI_ERROR (Status)) {\r
822 return Status;\r
823 }\r
824\r
825 Status = gBS->OpenProtocol (\r
826 ControllerHandle,\r
827 &gEfiDevicePathProtocolGuid,\r
828 NULL,\r
829 This->DriverBindingHandle,\r
830 ControllerHandle,\r
831 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
832 );\r
833\r
834 return Status;\r
b659408b
ZL
835}\r
836\r
837/**\r
838 Starts a device controller or a bus controller.\r
839\r
840 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
f75a7f56
LG
841 As a result, much of the error checking on the parameters to Start() has been moved into this\r
842 common boot service. It is legal to call Start() from other locations,\r
b659408b
ZL
843 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
844 1. ControllerHandle must be a valid EFI_HANDLE.\r
845 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
846 EFI_DEVICE_PATH_PROTOCOL.\r
847 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
f75a7f56 848 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
b659408b
ZL
849\r
850 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
851 @param[in] ControllerHandle The handle of the controller to start. This handle\r
852 must support a protocol interface that supplies\r
b659408b 853 an I/O abstraction to the driver.\r
f75a7f56
LG
854 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
855 parameter is ignored by device drivers, and is optional for bus\r
856 drivers. For a bus driver, if this parameter is NULL, then handles\r
857 for all the children of Controller are created by this driver.\r
858 If this parameter is not NULL and the first Device Path Node is\r
859 not the End of Device Path Node, then only the handle for the\r
860 child device specified by the first Device Path Node of\r
b659408b 861 RemainingDevicePath is created by this driver.\r
f75a7f56 862 If the first Device Path Node of RemainingDevicePath is\r
b659408b
ZL
863 the End of Device Path Node, no child handle is created by this\r
864 driver.\r
865\r
866 @retval EFI_SUCCESS The device was started.\r
867 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
868 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
c36b7b51 869 @retval Others The driver failed to start the device.\r
b659408b
ZL
870\r
871**/\r
872EFI_STATUS\r
873EFIAPI\r
874HttpBootIp6DxeDriverBindingStart (\r
875 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
876 IN EFI_HANDLE ControllerHandle,\r
877 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
878 )\r
879{\r
d1050b9d
MK
880 EFI_STATUS Status;\r
881 HTTP_BOOT_PRIVATE_DATA *Private;\r
882 EFI_DEV_PATH *Node;\r
883 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
884 UINT32 *Id;\r
885 BOOLEAN Ipv6Available;\r
886 BOOLEAN FirstStart;\r
ed247d86
JW
887\r
888 FirstStart = FALSE;\r
f75a7f56 889\r
b659408b
ZL
890 Status = gBS->OpenProtocol (\r
891 ControllerHandle,\r
892 &gEfiCallerIdGuid,\r
d1050b9d 893 (VOID **)&Id,\r
b659408b
ZL
894 This->DriverBindingHandle,\r
895 ControllerHandle,\r
896 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
897 );\r
f75a7f56 898\r
b659408b 899 if (!EFI_ERROR (Status)) {\r
d1050b9d 900 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
b659408b 901 } else {\r
ed247d86 902 FirstStart = TRUE;\r
f75a7f56 903\r
b659408b
ZL
904 //\r
905 // Initialize the private data structure.\r
906 //\r
907 Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));\r
908 if (Private == NULL) {\r
909 return EFI_OUT_OF_RESOURCES;\r
910 }\r
d1050b9d
MK
911\r
912 Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r
b659408b 913 Private->Controller = ControllerHandle;\r
b659408b
ZL
914 InitializeListHead (&Private->CacheList);\r
915 //\r
916 // Get the NII interface if it exists, it's not required.\r
917 //\r
918 Status = gBS->OpenProtocol (\r
919 ControllerHandle,\r
920 &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
d1050b9d 921 (VOID **)&Private->Nii,\r
b659408b
ZL
922 This->DriverBindingHandle,\r
923 ControllerHandle,\r
924 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
925 );\r
926 if (EFI_ERROR (Status)) {\r
927 Private->Nii = NULL;\r
928 }\r
929\r
930 //\r
931 // Open Device Path Protocol to prepare for appending IP and URI node.\r
932 //\r
933 Status = gBS->OpenProtocol (\r
934 ControllerHandle,\r
935 &gEfiDevicePathProtocolGuid,\r
d1050b9d 936 (VOID **)&Private->ParentDevicePath,\r
b659408b
ZL
937 This->DriverBindingHandle,\r
938 ControllerHandle,\r
939 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
940 );\r
941 if (EFI_ERROR (Status)) {\r
942 goto ON_ERROR;\r
943 }\r
944\r
fa848a40
FS
945 //\r
946 // Initialize the HII configuration form.\r
947 //\r
948 Status = HttpBootConfigFormInit (Private);\r
949 if (EFI_ERROR (Status)) {\r
950 goto ON_ERROR;\r
951 }\r
952\r
b659408b
ZL
953 //\r
954 // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between\r
955 // NIC handle and the private data.\r
956 //\r
957 Status = gBS->InstallProtocolInterface (\r
958 &ControllerHandle,\r
959 &gEfiCallerIdGuid,\r
960 EFI_NATIVE_INTERFACE,\r
961 &Private->Id\r
962 );\r
963 if (EFI_ERROR (Status)) {\r
964 goto ON_ERROR;\r
965 }\r
b659408b 966 }\r
ed247d86
JW
967\r
968 //\r
969 // Set IPv6 available flag.\r
f75a7f56 970 //\r
ed247d86
JW
971 Status = HttpBootCheckIpv6Support (Private, &Ipv6Available);\r
972 if (EFI_ERROR (Status)) {\r
973 //\r
f75a7f56 974 // Fail to get the data whether UNDI supports IPv6.\r
ed247d86
JW
975 // Set default value to TRUE.\r
976 //\r
977 Ipv6Available = TRUE;\r
978 }\r
979\r
980 if (!Ipv6Available) {\r
981 Status = EFI_UNSUPPORTED;\r
982 goto ON_ERROR;\r
983 }\r
f75a7f56 984\r
b659408b
ZL
985 if (Private->Ip6Nic != NULL) {\r
986 //\r
987 // Already created before\r
988 //\r
989 return EFI_SUCCESS;\r
990 }\r
f75a7f56 991\r
b659408b
ZL
992 Private->Ip6Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r
993 if (Private->Ip6Nic == NULL) {\r
ed247d86
JW
994 Status = EFI_OUT_OF_RESOURCES;\r
995 goto ON_ERROR;\r
b659408b 996 }\r
d1050b9d 997\r
75372581
FS
998 Private->Ip6Nic->Private = Private;\r
999 Private->Ip6Nic->ImageHandle = This->DriverBindingHandle;\r
1000 Private->Ip6Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r
f75a7f56 1001\r
b659408b
ZL
1002 //\r
1003 // Create Dhcp6 child and open Dhcp6 protocol\r
1004 Status = NetLibCreateServiceChild (\r
1005 ControllerHandle,\r
1006 This->DriverBindingHandle,\r
1007 &gEfiDhcp6ServiceBindingProtocolGuid,\r
1008 &Private->Dhcp6Child\r
1009 );\r
1010 if (EFI_ERROR (Status)) {\r
1011 goto ON_ERROR;\r
1012 }\r
1013\r
1014 Status = gBS->OpenProtocol (\r
1015 Private->Dhcp6Child,\r
1016 &gEfiDhcp6ProtocolGuid,\r
d1050b9d 1017 (VOID **)&Private->Dhcp6,\r
b659408b
ZL
1018 This->DriverBindingHandle,\r
1019 ControllerHandle,\r
1020 EFI_OPEN_PROTOCOL_BY_DRIVER\r
1021 );\r
1022 if (EFI_ERROR (Status)) {\r
1023 goto ON_ERROR;\r
1024 }\r
1025\r
1026 //\r
1027 // Create Ip6 child and open Ip6 protocol for background ICMP packets.\r
1028 //\r
1029 Status = NetLibCreateServiceChild (\r
d1050b9d
MK
1030 ControllerHandle,\r
1031 This->DriverBindingHandle,\r
1032 &gEfiIp6ServiceBindingProtocolGuid,\r
1033 &Private->Ip6Child\r
1034 );\r
b659408b
ZL
1035 if (EFI_ERROR (Status)) {\r
1036 goto ON_ERROR;\r
1037 }\r
1038\r
1039 Status = gBS->OpenProtocol (\r
1040 Private->Ip6Child,\r
1041 &gEfiIp6ProtocolGuid,\r
d1050b9d 1042 (VOID **)&Private->Ip6,\r
b659408b
ZL
1043 This->DriverBindingHandle,\r
1044 ControllerHandle,\r
1045 EFI_OPEN_PROTOCOL_BY_DRIVER\r
1046 );\r
1047 if (EFI_ERROR (Status)) {\r
1048 goto ON_ERROR;\r
1049 }\r
1050\r
1051 //\r
1052 // Locate Ip6Config protocol, it's required to configure the default gateway address.\r
1053 //\r
1054 Status = gBS->OpenProtocol (\r
1055 ControllerHandle,\r
1056 &gEfiIp6ConfigProtocolGuid,\r
d1050b9d 1057 (VOID **)&Private->Ip6Config,\r
b659408b
ZL
1058 This->DriverBindingHandle,\r
1059 ControllerHandle,\r
1060 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1061 );\r
1062 if (EFI_ERROR (Status)) {\r
1063 goto ON_ERROR;\r
1064 }\r
1065\r
1066 //\r
1067 // Append IPv6 device path node.\r
1068 //\r
1069 Node = AllocateZeroPool (sizeof (IPv6_DEVICE_PATH));\r
1070 if (Node == NULL) {\r
1071 Status = EFI_OUT_OF_RESOURCES;\r
1072 goto ON_ERROR;\r
1073 }\r
d1050b9d
MK
1074\r
1075 Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH;\r
b659408b 1076 Node->Ipv6.Header.SubType = MSG_IPv6_DP;\r
d1050b9d 1077 Node->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;\r
b659408b 1078 SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));\r
d1050b9d
MK
1079 DevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH *)Node);\r
1080 FreePool (Node);\r
b659408b
ZL
1081 if (DevicePath == NULL) {\r
1082 Status = EFI_OUT_OF_RESOURCES;\r
1083 goto ON_ERROR;\r
1084 }\r
1085\r
1086 //\r
1087 // Append URI device path node.\r
1088 //\r
1089 Node = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
1090 if (Node == NULL) {\r
1091 Status = EFI_OUT_OF_RESOURCES;\r
1092 goto ON_ERROR;\r
1093 }\r
d1050b9d
MK
1094\r
1095 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
b659408b
ZL
1096 Node->DevPath.SubType = MSG_URI_DP;\r
1097 SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
d1050b9d 1098 Private->Ip6Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);\r
b659408b
ZL
1099 FreePool (Node);\r
1100 FreePool (DevicePath);\r
1101 if (Private->Ip6Nic->DevicePath == NULL) {\r
1102 Status = EFI_OUT_OF_RESOURCES;\r
1103 goto ON_ERROR;\r
1104 }\r
1105\r
1106 //\r
1107 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r
1108 //\r
1109 CopyMem (&Private->Ip6Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (Private->LoadFile));\r
1110 Status = gBS->InstallMultipleProtocolInterfaces (\r
1111 &Private->Ip6Nic->Controller,\r
1112 &gEfiLoadFileProtocolGuid,\r
1113 &Private->Ip6Nic->LoadFile,\r
1114 &gEfiDevicePathProtocolGuid,\r
1115 Private->Ip6Nic->DevicePath,\r
1116 NULL\r
1117 );\r
1118 if (EFI_ERROR (Status)) {\r
1119 goto ON_ERROR;\r
1120 }\r
1121\r
1122 //\r
1123 // Open the Caller Id child to setup a parent-child relationship between\r
1124 // real NIC handle and the HTTP boot child handle.\r
1125 //\r
1126 Status = gBS->OpenProtocol (\r
1127 ControllerHandle,\r
1128 &gEfiCallerIdGuid,\r
d1050b9d 1129 (VOID **)&Id,\r
b659408b
ZL
1130 This->DriverBindingHandle,\r
1131 Private->Ip6Nic->Controller,\r
1132 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
1133 );\r
1134 if (EFI_ERROR (Status)) {\r
1135 goto ON_ERROR;\r
1136 }\r
1137\r
1138 return EFI_SUCCESS;\r
f75a7f56 1139\r
b659408b 1140ON_ERROR:\r
770f9aae
JW
1141 if (Private != NULL) {\r
1142 if (FirstStart) {\r
1143 gBS->UninstallProtocolInterface (\r
1144 ControllerHandle,\r
1145 &gEfiCallerIdGuid,\r
1146 &Private->Id\r
1147 );\r
1148 }\r
b659408b 1149\r
d1050b9d 1150 HttpBootDestroyIp6Children (This, Private);\r
770f9aae 1151 HttpBootConfigFormUnload (Private);\r
ed247d86 1152\r
770f9aae
JW
1153 if (FirstStart) {\r
1154 FreePool (Private);\r
1155 }\r
ed247d86 1156 }\r
fa848a40
FS
1157\r
1158 return Status;\r
b659408b
ZL
1159}\r
1160\r
1161/**\r
1162 Stops a device controller or a bus controller.\r
f75a7f56
LG
1163\r
1164 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
1165 As a result, much of the error checking on the parameters to Stop() has been moved\r
1166 into this common boot service. It is legal to call Stop() from other locations,\r
b659408b
ZL
1167 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
1168 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
1169 same driver's Start() function.\r
1170 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
1171 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
1172 Start() function, and the Start() function must have called OpenProtocol() on\r
1173 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
f75a7f56 1174\r
b659408b 1175 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
1176 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
1177 support a bus specific I/O protocol for the driver\r
b659408b
ZL
1178 to use to stop the device.\r
1179 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
f75a7f56 1180 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
b659408b
ZL
1181 if NumberOfChildren is 0.\r
1182\r
1183 @retval EFI_SUCCESS The device was stopped.\r
1184 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
1185\r
1186**/\r
1187EFI_STATUS\r
1188EFIAPI\r
1189HttpBootIp6DxeDriverBindingStop (\r
1190 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
1191 IN EFI_HANDLE ControllerHandle,\r
1192 IN UINTN NumberOfChildren,\r
1193 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
1194 )\r
1195{\r
d1050b9d
MK
1196 EFI_STATUS Status;\r
1197 EFI_LOAD_FILE_PROTOCOL *LoadFile;\r
1198 HTTP_BOOT_PRIVATE_DATA *Private;\r
1199 EFI_HANDLE NicHandle;\r
1200 UINT32 *Id;\r
b659408b
ZL
1201\r
1202 //\r
1203 // Try to get the Load File Protocol from the controller handle.\r
1204 //\r
1205 Status = gBS->OpenProtocol (\r
1206 ControllerHandle,\r
1207 &gEfiLoadFileProtocolGuid,\r
d1050b9d 1208 (VOID **)&LoadFile,\r
b659408b
ZL
1209 This->DriverBindingHandle,\r
1210 ControllerHandle,\r
1211 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1212 );\r
1213 if (EFI_ERROR (Status)) {\r
1214 //\r
1215 // If failed, try to find the NIC handle for this controller.\r
1216 //\r
1217 NicHandle = HttpBootGetNicByIp6Children (ControllerHandle);\r
1218 if (NicHandle == NULL) {\r
1219 return EFI_SUCCESS;\r
1220 }\r
1221\r
1222 //\r
1223 // Try to retrieve the private data by the Caller Id Guid.\r
1224 //\r
1225 Status = gBS->OpenProtocol (\r
1226 NicHandle,\r
1227 &gEfiCallerIdGuid,\r
d1050b9d 1228 (VOID **)&Id,\r
b659408b
ZL
1229 This->DriverBindingHandle,\r
1230 ControllerHandle,\r
1231 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1232 );\r
1233 if (EFI_ERROR (Status)) {\r
1234 return Status;\r
1235 }\r
d1050b9d 1236\r
b659408b
ZL
1237 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
1238 } else {\r
d1050b9d 1239 Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r
b659408b
ZL
1240 NicHandle = Private->Controller;\r
1241 }\r
1242\r
1243 //\r
1244 // Disable the HTTP boot function.\r
1245 //\r
1246 Status = HttpBootStop (Private);\r
d1050b9d 1247 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_STARTED)) {\r
b659408b
ZL
1248 return Status;\r
1249 }\r
1250\r
1251 //\r
c36b7b51 1252 // Destroy all child instance and uninstall protocol interface.\r
b659408b
ZL
1253 //\r
1254 HttpBootDestroyIp6Children (This, Private);\r
1255\r
d1050b9d 1256 if ((Private->Ip4Nic == NULL) && (Private->Ip6Nic == NULL)) {\r
b659408b
ZL
1257 //\r
1258 // Release the cached data.\r
1259 //\r
1260 HttpBootFreeCacheList (Private);\r
fa848a40
FS
1261\r
1262 //\r
1263 // Unload the config form.\r
1264 //\r
1265 HttpBootConfigFormUnload (Private);\r
1266\r
b659408b
ZL
1267 gBS->UninstallProtocolInterface (\r
1268 NicHandle,\r
1269 &gEfiCallerIdGuid,\r
1270 &Private->Id\r
1271 );\r
1272 FreePool (Private);\r
b659408b
ZL
1273 }\r
1274\r
1275 return EFI_SUCCESS;\r
1276}\r
d1050b9d 1277\r
b659408b
ZL
1278/**\r
1279 This is the declaration of an EFI image entry point. This entry point is\r
1280 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
1281 both device drivers and bus drivers.\r
1282\r
1283 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
1284 @param[in] SystemTable A pointer to the EFI System Table.\r
1285\r
1286 @retval EFI_SUCCESS The operation completed successfully.\r
1287 @retval Others An unexpected error occurred.\r
1288\r
1289**/\r
1290EFI_STATUS\r
1291EFIAPI\r
1292HttpBootDxeDriverEntryPoint (\r
1293 IN EFI_HANDLE ImageHandle,\r
1294 IN EFI_SYSTEM_TABLE *SystemTable\r
1295 )\r
1296{\r
d1050b9d 1297 EFI_STATUS Status;\r
fa848a40 1298\r
b659408b
ZL
1299 //\r
1300 // Install UEFI Driver Model protocol(s).\r
1301 //\r
1302 Status = EfiLibInstallDriverBindingComponentName2 (\r
1303 ImageHandle,\r
1304 SystemTable,\r
1305 &gHttpBootIp4DxeDriverBinding,\r
1306 ImageHandle,\r
1307 &gHttpBootDxeComponentName,\r
1308 &gHttpBootDxeComponentName2\r
1309 );\r
1310 if (EFI_ERROR (Status)) {\r
1311 return Status;\r
1312 }\r
f75a7f56 1313\r
b659408b
ZL
1314 Status = EfiLibInstallDriverBindingComponentName2 (\r
1315 ImageHandle,\r
1316 SystemTable,\r
1317 &gHttpBootIp6DxeDriverBinding,\r
1318 NULL,\r
1319 &gHttpBootDxeComponentName,\r
1320 &gHttpBootDxeComponentName2\r
1321 );\r
1322 if (EFI_ERROR (Status)) {\r
d1050b9d 1323 EfiLibUninstallDriverBindingComponentName2 (\r
22b35e8b
AS
1324 &gHttpBootIp4DxeDriverBinding,\r
1325 &gHttpBootDxeComponentName,\r
1326 &gHttpBootDxeComponentName2\r
1327 );\r
b659408b 1328 }\r
d1050b9d 1329\r
b659408b 1330 return Status;\r
d933e70a 1331}\r