]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - NetworkPkg/HttpBootDxe/HttpBootDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootDxe.c
... / ...
CommitLineData
1/** @file\r
2 Driver Binding functions implementation for UEFI HTTP boot.\r
3\r
4Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include "HttpBootDxe.h"\r
10\r
11///\r
12/// Driver Binding Protocol instance\r
13///\r
14EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp4DxeDriverBinding = {\r
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
23EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp6DxeDriverBinding = {\r
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
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
44 IN HTTP_BOOT_PRIVATE_DATA *Private,\r
45 OUT BOOLEAN *Ipv6Support\r
46 )\r
47{\r
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
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
70 //\r
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
80 (VOID *)&Aip\r
81 );\r
82 if (EFI_ERROR (Status) || (Aip == NULL)) {\r
83 return EFI_NOT_FOUND;\r
84 }\r
85\r
86 InfoTypesBuffer = NULL;\r
87 InfoTypeBufferCount = 0;\r
88 Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, &InfoTypeBufferCount);\r
89 if (EFI_ERROR (Status) || (InfoTypesBuffer == NULL)) {\r
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
112 Status = Aip->GetInformation (Aip, &gEfiAdapterInfoUndiIpv6SupportGuid, &InfoBlock, &InfoBlockSize);\r
113 if (EFI_ERROR (Status) || (InfoBlock == NULL)) {\r
114 FreePool (InfoBlock);\r
115 return EFI_NOT_FOUND;\r
116 }\r
117\r
118 *Ipv6Support = ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *)InfoBlock)->Ipv6Support;\r
119 FreePool (InfoBlock);\r
120\r
121 return EFI_SUCCESS;\r
122}\r
123\r
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
139\r
140 if (Private->Dhcp4Child != NULL) {\r
141 gBS->CloseProtocol (\r
142 Private->Dhcp4Child,\r
143 &gEfiDhcp4ProtocolGuid,\r
144 This->DriverBindingHandle,\r
145 Private->Controller\r
146 );\r
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
156 if ((Private->Ip6Nic == NULL) && Private->HttpCreated) {\r
157 HttpIoDestroyIo (&Private->HttpIo);\r
158 Private->HttpCreated = FALSE;\r
159 }\r
160\r
161 if (Private->Ip4Nic != NULL) {\r
162 gBS->CloseProtocol (\r
163 Private->Controller,\r
164 &gEfiCallerIdGuid,\r
165 This->DriverBindingHandle,\r
166 Private->Ip4Nic->Controller\r
167 );\r
168\r
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
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
197\r
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
221\r
222 NetLibDestroyServiceChild (\r
223 Private->Controller,\r
224 This->DriverBindingHandle,\r
225 &gEfiDhcp6ServiceBindingProtocolGuid,\r
226 Private->Dhcp6Child\r
227 );\r
228 }\r
229\r
230 if ((Private->Ip4Nic == NULL) && Private->HttpCreated) {\r
231 HttpIoDestroyIo (&Private->HttpIo);\r
232 Private->HttpCreated = FALSE;\r
233 }\r
234\r
235 if (Private->Ip6Nic != NULL) {\r
236 gBS->CloseProtocol (\r
237 Private->Controller,\r
238 &gEfiCallerIdGuid,\r
239 This->DriverBindingHandle,\r
240 Private->Ip6Nic->Controller\r
241 );\r
242\r
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
253 }\r
254}\r
255\r
256/**\r
257 Tests to see if this driver supports a given controller. If a child device is provided,\r
258 it further tests to see if this driver supports creating a handle for the specified child device.\r
259\r
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
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
275 @param[in] ControllerHandle The handle of the controller to test. This handle\r
276 must support a protocol interface that supplies\r
277 an I/O abstraction to the driver.\r
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
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
306 EFI_STATUS Status;\r
307\r
308 //\r
309 // Try to open the DHCP4, HTTP4 and Device Path protocol.\r
310 //\r
311 Status = gBS->OpenProtocol (\r
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
319 if (EFI_ERROR (Status)) {\r
320 return Status;\r
321 }\r
322\r
323 Status = gBS->OpenProtocol (\r
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
331 if (EFI_ERROR (Status)) {\r
332 return Status;\r
333 }\r
334\r
335 Status = gBS->OpenProtocol (\r
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
343\r
344 return Status;\r
345}\r
346\r
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
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
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
358 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
359\r
360 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
361 @param[in] ControllerHandle The handle of the controller to start. This handle\r
362 must support a protocol interface that supplies\r
363 an I/O abstraction to the driver.\r
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
371 RemainingDevicePath is created by this driver.\r
372 If the first Device Path Node of RemainingDevicePath is\r
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
379 @retval Others The driver failed to start the device.\r
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
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
396\r
397 FirstStart = FALSE;\r
398\r
399 Status = gBS->OpenProtocol (\r
400 ControllerHandle,\r
401 &gEfiCallerIdGuid,\r
402 (VOID **)&Id,\r
403 This->DriverBindingHandle,\r
404 ControllerHandle,\r
405 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
406 );\r
407\r
408 if (!EFI_ERROR (Status)) {\r
409 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
410 } else {\r
411 FirstStart = TRUE;\r
412\r
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
420\r
421 Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r
422 Private->Controller = ControllerHandle;\r
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
430 (VOID **)&Private->Nii,\r
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
438\r
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
445 (VOID **)&Private->ParentDevicePath,\r
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
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
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
475 }\r
476\r
477 if (Private->Ip4Nic != NULL) {\r
478 //\r
479 // Already created before\r
480 //\r
481 return EFI_SUCCESS;\r
482 }\r
483\r
484 Private->Ip4Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r
485 if (Private->Ip4Nic == NULL) {\r
486 Status = EFI_OUT_OF_RESOURCES;\r
487 goto ON_ERROR;\r
488 }\r
489\r
490 Private->Ip4Nic->Private = Private;\r
491 Private->Ip4Nic->ImageHandle = This->DriverBindingHandle;\r
492 Private->Ip4Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r
493\r
494 //\r
495 // Create DHCP4 child instance.\r
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
506\r
507 Status = gBS->OpenProtocol (\r
508 Private->Dhcp4Child,\r
509 &gEfiDhcp4ProtocolGuid,\r
510 (VOID **)&Private->Dhcp4,\r
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
518\r
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
525 (VOID **)&Private->Ip4Config2,\r
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
533\r
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
542\r
543 Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH;\r
544 Node->Ipv4.Header.SubType = MSG_IPv4_DP;\r
545 SetDevicePathNodeLength (Node, sizeof (IPv4_DEVICE_PATH));\r
546 Node->Ipv4.StaticIpAddress = FALSE;\r
547 DevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);\r
548 FreePool (Node);\r
549 if (DevicePath == NULL) {\r
550 Status = EFI_OUT_OF_RESOURCES;\r
551 goto ON_ERROR;\r
552 }\r
553\r
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
562\r
563 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
564 Node->DevPath.SubType = MSG_URI_DP;\r
565 SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
566 Private->Ip4Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);\r
567 FreePool (Node);\r
568 FreePool (DevicePath);\r
569 if (Private->Ip4Nic->DevicePath == NULL) {\r
570 Status = EFI_OUT_OF_RESOURCES;\r
571 goto ON_ERROR;\r
572 }\r
573\r
574 //\r
575 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r
576 //\r
577 CopyMem (&Private->Ip4Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (EFI_LOAD_FILE_PROTOCOL));\r
578 Status = gBS->InstallMultipleProtocolInterfaces (\r
579 &Private->Ip4Nic->Controller,\r
580 &gEfiLoadFileProtocolGuid,\r
581 &Private->Ip4Nic->LoadFile,\r
582 &gEfiDevicePathProtocolGuid,\r
583 Private->Ip4Nic->DevicePath,\r
584 NULL\r
585 );\r
586 if (EFI_ERROR (Status)) {\r
587 goto ON_ERROR;\r
588 }\r
589\r
590 //\r
591 // Open the Caller Id child to setup a parent-child relationship between\r
592 // real NIC handle and the HTTP boot Ipv4 NIC handle.\r
593 //\r
594 Status = gBS->OpenProtocol (\r
595 ControllerHandle,\r
596 &gEfiCallerIdGuid,\r
597 (VOID **)&Id,\r
598 This->DriverBindingHandle,\r
599 Private->Ip4Nic->Controller,\r
600 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
601 );\r
602 if (EFI_ERROR (Status)) {\r
603 goto ON_ERROR;\r
604 }\r
605\r
606 return EFI_SUCCESS;\r
607\r
608ON_ERROR:\r
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
617\r
618 HttpBootDestroyIp4Children (This, Private);\r
619 HttpBootConfigFormUnload (Private);\r
620\r
621 if (FirstStart) {\r
622 FreePool (Private);\r
623 }\r
624 }\r
625\r
626 return Status;\r
627}\r
628\r
629/**\r
630 Stops a device controller or a bus controller.\r
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
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
642\r
643 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
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
646 to use to stop the device.\r
647 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
648 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
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
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
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
676 (VOID **)&LoadFile,\r
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
696 (VOID **)&Id,\r
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
704\r
705 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
706 } else {\r
707 Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r
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
715 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_STARTED)) {\r
716 return Status;\r
717 }\r
718\r
719 //\r
720 // Destroy all child instance and uninstall protocol interface.\r
721 //\r
722 HttpBootDestroyIp4Children (This, Private);\r
723\r
724 if ((Private->Ip4Nic == NULL) && (Private->Ip6Nic == NULL)) {\r
725 //\r
726 // Release the cached data.\r
727 //\r
728 HttpBootFreeCacheList (Private);\r
729\r
730 //\r
731 // Unload the config form.\r
732 //\r
733 HttpBootConfigFormUnload (Private);\r
734\r
735 gBS->UninstallProtocolInterface (\r
736 NicHandle,\r
737 &gEfiCallerIdGuid,\r
738 &Private->Id\r
739 );\r
740 FreePool (Private);\r
741 }\r
742\r
743 return EFI_SUCCESS;\r
744}\r
745\r
746/**\r
747 Tests to see if this driver supports a given controller. If a child device is provided,\r
748 it further tests to see if this driver supports creating a handle for the specified child device.\r
749\r
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
762 to guarantee the state of ControllerHandle is not modified by this function.\r
763\r
764 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
765 @param[in] ControllerHandle The handle of the controller to test. This handle\r
766 must support a protocol interface that supplies\r
767 an I/O abstraction to the driver.\r
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
774 bus driver.\r
775\r
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
787**/\r
788EFI_STATUS\r
789EFIAPI\r
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
794 )\r
795{\r
796 EFI_STATUS Status;\r
797\r
798 //\r
799 // Try to open the DHCP6, HTTP and Device Path protocol.\r
800 //\r
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
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
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
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
848 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
849\r
850 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
851 @param[in] ControllerHandle The handle of the controller to start. This handle\r
852 must support a protocol interface that supplies\r
853 an I/O abstraction to the driver.\r
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
861 RemainingDevicePath is created by this driver.\r
862 If the first Device Path Node of RemainingDevicePath is\r
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
869 @retval Others The driver failed to start the device.\r
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
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
887\r
888 FirstStart = FALSE;\r
889\r
890 Status = gBS->OpenProtocol (\r
891 ControllerHandle,\r
892 &gEfiCallerIdGuid,\r
893 (VOID **)&Id,\r
894 This->DriverBindingHandle,\r
895 ControllerHandle,\r
896 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
897 );\r
898\r
899 if (!EFI_ERROR (Status)) {\r
900 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
901 } else {\r
902 FirstStart = TRUE;\r
903\r
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
911\r
912 Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r
913 Private->Controller = ControllerHandle;\r
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
921 (VOID **)&Private->Nii,\r
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
936 (VOID **)&Private->ParentDevicePath,\r
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
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
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
966 }\r
967\r
968 //\r
969 // Set IPv6 available flag.\r
970 //\r
971 Status = HttpBootCheckIpv6Support (Private, &Ipv6Available);\r
972 if (EFI_ERROR (Status)) {\r
973 //\r
974 // Fail to get the data whether UNDI supports IPv6.\r
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
984\r
985 if (Private->Ip6Nic != NULL) {\r
986 //\r
987 // Already created before\r
988 //\r
989 return EFI_SUCCESS;\r
990 }\r
991\r
992 Private->Ip6Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r
993 if (Private->Ip6Nic == NULL) {\r
994 Status = EFI_OUT_OF_RESOURCES;\r
995 goto ON_ERROR;\r
996 }\r
997\r
998 Private->Ip6Nic->Private = Private;\r
999 Private->Ip6Nic->ImageHandle = This->DriverBindingHandle;\r
1000 Private->Ip6Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r
1001\r
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
1017 (VOID **)&Private->Dhcp6,\r
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
1030 ControllerHandle,\r
1031 This->DriverBindingHandle,\r
1032 &gEfiIp6ServiceBindingProtocolGuid,\r
1033 &Private->Ip6Child\r
1034 );\r
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
1042 (VOID **)&Private->Ip6,\r
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
1057 (VOID **)&Private->Ip6Config,\r
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
1074\r
1075 Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH;\r
1076 Node->Ipv6.Header.SubType = MSG_IPv6_DP;\r
1077 Node->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;\r
1078 SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));\r
1079 DevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH *)Node);\r
1080 FreePool (Node);\r
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
1094\r
1095 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
1096 Node->DevPath.SubType = MSG_URI_DP;\r
1097 SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
1098 Private->Ip6Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);\r
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
1129 (VOID **)&Id,\r
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
1139\r
1140ON_ERROR:\r
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
1149\r
1150 HttpBootDestroyIp6Children (This, Private);\r
1151 HttpBootConfigFormUnload (Private);\r
1152\r
1153 if (FirstStart) {\r
1154 FreePool (Private);\r
1155 }\r
1156 }\r
1157\r
1158 return Status;\r
1159}\r
1160\r
1161/**\r
1162 Stops a device controller or a bus controller.\r
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
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
1174\r
1175 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
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
1178 to use to stop the device.\r
1179 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
1180 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
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
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
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
1208 (VOID **)&LoadFile,\r
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
1228 (VOID **)&Id,\r
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
1236\r
1237 Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r
1238 } else {\r
1239 Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r
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
1247 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_STARTED)) {\r
1248 return Status;\r
1249 }\r
1250\r
1251 //\r
1252 // Destroy all child instance and uninstall protocol interface.\r
1253 //\r
1254 HttpBootDestroyIp6Children (This, Private);\r
1255\r
1256 if ((Private->Ip4Nic == NULL) && (Private->Ip6Nic == NULL)) {\r
1257 //\r
1258 // Release the cached data.\r
1259 //\r
1260 HttpBootFreeCacheList (Private);\r
1261\r
1262 //\r
1263 // Unload the config form.\r
1264 //\r
1265 HttpBootConfigFormUnload (Private);\r
1266\r
1267 gBS->UninstallProtocolInterface (\r
1268 NicHandle,\r
1269 &gEfiCallerIdGuid,\r
1270 &Private->Id\r
1271 );\r
1272 FreePool (Private);\r
1273 }\r
1274\r
1275 return EFI_SUCCESS;\r
1276}\r
1277\r
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
1297 EFI_STATUS Status;\r
1298\r
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
1313\r
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
1323 EfiLibUninstallDriverBindingComponentName2 (\r
1324 &gHttpBootIp4DxeDriverBinding,\r
1325 &gHttpBootDxeComponentName,\r
1326 &gHttpBootDxeComponentName2\r
1327 );\r
1328 }\r
1329\r
1330 return Status;\r
1331}\r