2 Driver Binding functions implementation for UEFI HTTP boot.
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "HttpBootDxe.h"
12 /// Driver Binding Protocol instance
14 EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp4DxeDriverBinding
= {
15 HttpBootIp4DxeDriverBindingSupported
,
16 HttpBootIp4DxeDriverBindingStart
,
17 HttpBootIp4DxeDriverBindingStop
,
18 HTTP_BOOT_DXE_VERSION
,
23 EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp6DxeDriverBinding
= {
24 HttpBootIp6DxeDriverBindingSupported
,
25 HttpBootIp6DxeDriverBindingStart
,
26 HttpBootIp6DxeDriverBindingStop
,
27 HTTP_BOOT_DXE_VERSION
,
33 Check whether UNDI protocol supports IPv6.
35 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.
36 @param[out] Ipv6Support TRUE if UNDI supports IPv6.
38 @retval EFI_SUCCESS Get the result whether UNDI supports IPv6 by NII or AIP protocol successfully.
39 @retval EFI_NOT_FOUND Don't know whether UNDI supports IPv6 since NII or AIP is not available.
43 HttpBootCheckIpv6Support (
44 IN HTTP_BOOT_PRIVATE_DATA
*Private
,
45 OUT BOOLEAN
*Ipv6Support
49 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
51 EFI_GUID
*InfoTypesBuffer
;
52 UINTN InfoTypeBufferCount
;
58 ASSERT (Private
!= NULL
&& Ipv6Support
!= NULL
);
61 // Check whether the UNDI supports IPv6 by NII protocol.
63 if (Private
->Nii
!= NULL
) {
64 *Ipv6Support
= Private
->Nii
->Ipv6Supported
;
69 // Get the NIC handle by SNP protocol.
71 Handle
= NetLibGetSnpHandle (Private
->Controller
, NULL
);
77 Status
= gBS
->HandleProtocol (
79 &gEfiAdapterInformationProtocolGuid
,
82 if (EFI_ERROR (Status
) || (Aip
== NULL
)) {
86 InfoTypesBuffer
= NULL
;
87 InfoTypeBufferCount
= 0;
88 Status
= Aip
->GetSupportedTypes (Aip
, &InfoTypesBuffer
, &InfoTypeBufferCount
);
89 if (EFI_ERROR (Status
) || (InfoTypesBuffer
== NULL
)) {
90 FreePool (InfoTypesBuffer
);
95 for (TypeIndex
= 0; TypeIndex
< InfoTypeBufferCount
; TypeIndex
++) {
96 if (CompareGuid (&InfoTypesBuffer
[TypeIndex
], &gEfiAdapterInfoUndiIpv6SupportGuid
)) {
102 FreePool (InfoTypesBuffer
);
104 return EFI_NOT_FOUND
;
108 // We now have adapter information block.
112 Status
= Aip
->GetInformation (Aip
, &gEfiAdapterInfoUndiIpv6SupportGuid
, &InfoBlock
, &InfoBlockSize
);
113 if (EFI_ERROR (Status
) || (InfoBlock
== NULL
)) {
114 FreePool (InfoBlock
);
115 return EFI_NOT_FOUND
;
118 *Ipv6Support
= ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT
*)InfoBlock
)->Ipv6Support
;
119 FreePool (InfoBlock
);
125 Destroy the HTTP child based on IPv4 stack.
127 @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.
128 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.
132 HttpBootDestroyIp4Children (
133 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
134 IN HTTP_BOOT_PRIVATE_DATA
*Private
137 ASSERT (This
!= NULL
);
138 ASSERT (Private
!= NULL
);
140 if (Private
->Dhcp4Child
!= NULL
) {
143 &gEfiDhcp4ProtocolGuid
,
144 This
->DriverBindingHandle
,
148 NetLibDestroyServiceChild (
150 This
->DriverBindingHandle
,
151 &gEfiDhcp4ServiceBindingProtocolGuid
,
156 if ((Private
->Ip6Nic
== NULL
) && Private
->HttpCreated
) {
157 HttpIoDestroyIo (&Private
->HttpIo
);
158 Private
->HttpCreated
= FALSE
;
161 if (Private
->Ip4Nic
!= NULL
) {
165 This
->DriverBindingHandle
,
166 Private
->Ip4Nic
->Controller
169 gBS
->UninstallMultipleProtocolInterfaces (
170 Private
->Ip4Nic
->Controller
,
171 &gEfiLoadFileProtocolGuid
,
172 &Private
->Ip4Nic
->LoadFile
,
173 &gEfiDevicePathProtocolGuid
,
174 Private
->Ip4Nic
->DevicePath
,
177 FreePool (Private
->Ip4Nic
);
178 Private
->Ip4Nic
= NULL
;
183 Destroy the HTTP child based on IPv6 stack.
185 @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.
186 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.
190 HttpBootDestroyIp6Children (
191 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
192 IN HTTP_BOOT_PRIVATE_DATA
*Private
195 ASSERT (This
!= NULL
);
196 ASSERT (Private
!= NULL
);
198 if (Private
->Ip6Child
!= NULL
) {
201 &gEfiIp6ProtocolGuid
,
202 This
->DriverBindingHandle
,
206 NetLibDestroyServiceChild (
208 This
->DriverBindingHandle
,
209 &gEfiIp6ServiceBindingProtocolGuid
,
214 if (Private
->Dhcp6Child
!= NULL
) {
217 &gEfiDhcp6ProtocolGuid
,
218 This
->DriverBindingHandle
,
222 NetLibDestroyServiceChild (
224 This
->DriverBindingHandle
,
225 &gEfiDhcp6ServiceBindingProtocolGuid
,
230 if ((Private
->Ip4Nic
== NULL
) && Private
->HttpCreated
) {
231 HttpIoDestroyIo (&Private
->HttpIo
);
232 Private
->HttpCreated
= FALSE
;
235 if (Private
->Ip6Nic
!= NULL
) {
239 This
->DriverBindingHandle
,
240 Private
->Ip6Nic
->Controller
243 gBS
->UninstallMultipleProtocolInterfaces (
244 Private
->Ip6Nic
->Controller
,
245 &gEfiLoadFileProtocolGuid
,
246 &Private
->Ip6Nic
->LoadFile
,
247 &gEfiDevicePathProtocolGuid
,
248 Private
->Ip6Nic
->DevicePath
,
251 FreePool (Private
->Ip6Nic
);
252 Private
->Ip6Nic
= NULL
;
257 Tests to see if this driver supports a given controller. If a child device is provided,
258 it further tests to see if this driver supports creating a handle for the specified child device.
260 This function checks to see if the driver specified by This supports the device specified by
261 ControllerHandle. Drivers will typically use the device path attached to
262 ControllerHandle and/or the services from the bus I/O abstraction attached to
263 ControllerHandle to determine if the driver supports ControllerHandle. This function
264 may be called many times during platform initialization. In order to reduce boot times, the tests
265 performed by this function must be very small, and take as little time as possible to execute. This
266 function must not change the state of any hardware devices, and this function must be aware that the
267 device specified by ControllerHandle may already be managed by the same driver or a
268 different driver. This function must match its calls to AllocatePages() with FreePages(),
269 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
270 Because ControllerHandle may have been previously started by the same driver, if a protocol is
271 already in the opened state, then it must not be closed with CloseProtocol(). This is required
272 to guarantee the state of ControllerHandle is not modified by this function.
274 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
275 @param[in] ControllerHandle The handle of the controller to test. This handle
276 must support a protocol interface that supplies
277 an I/O abstraction to the driver.
278 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
279 parameter is ignored by device drivers, and is optional for bus
280 drivers. For bus drivers, if this parameter is not NULL, then
281 the bus driver must determine if the bus controller specified
282 by ControllerHandle and the child controller specified
283 by RemainingDevicePath are both supported by this
286 @retval EFI_SUCCESS The device specified by ControllerHandle and
287 RemainingDevicePath is supported by the driver specified by This.
288 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
289 RemainingDevicePath is already being managed by the driver
291 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
292 RemainingDevicePath is already being managed by a different
293 driver or an application that requires exclusive access.
294 Currently not implemented.
295 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
296 RemainingDevicePath is not supported by the driver specified by This.
300 HttpBootIp4DxeDriverBindingSupported (
301 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
302 IN EFI_HANDLE ControllerHandle
,
303 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
309 // Try to open the DHCP4, HTTP4 and Device Path protocol.
311 Status
= gBS
->OpenProtocol (
313 &gEfiDhcp4ServiceBindingProtocolGuid
,
315 This
->DriverBindingHandle
,
317 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
319 if (EFI_ERROR (Status
)) {
323 Status
= gBS
->OpenProtocol (
325 &gEfiHttpServiceBindingProtocolGuid
,
327 This
->DriverBindingHandle
,
329 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
331 if (EFI_ERROR (Status
)) {
335 Status
= gBS
->OpenProtocol (
337 &gEfiDevicePathProtocolGuid
,
339 This
->DriverBindingHandle
,
341 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
348 Starts a device controller or a bus controller.
350 The Start() function is designed to be invoked from the EFI boot service ConnectController().
351 As a result, much of the error checking on the parameters to Start() has been moved into this
352 common boot service. It is legal to call Start() from other locations,
353 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
354 1. ControllerHandle must be a valid EFI_HANDLE.
355 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
356 EFI_DEVICE_PATH_PROTOCOL.
357 3. Prior to calling Start(), the Supported() function for the driver specified by This must
358 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
360 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
361 @param[in] ControllerHandle The handle of the controller to start. This handle
362 must support a protocol interface that supplies
363 an I/O abstraction to the driver.
364 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
365 parameter is ignored by device drivers, and is optional for bus
366 drivers. For a bus driver, if this parameter is NULL, then handles
367 for all the children of Controller are created by this driver.
368 If this parameter is not NULL and the first Device Path Node is
369 not the End of Device Path Node, then only the handle for the
370 child device specified by the first Device Path Node of
371 RemainingDevicePath is created by this driver.
372 If the first Device Path Node of RemainingDevicePath is
373 the End of Device Path Node, no child handle is created by this
376 @retval EFI_SUCCESS The device was started.
377 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
378 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
379 @retval Others The driver failed to start the device.
384 HttpBootIp4DxeDriverBindingStart (
385 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
386 IN EFI_HANDLE ControllerHandle
,
387 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
391 HTTP_BOOT_PRIVATE_DATA
*Private
;
393 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
399 Status
= gBS
->OpenProtocol (
403 This
->DriverBindingHandle
,
405 EFI_OPEN_PROTOCOL_GET_PROTOCOL
408 if (!EFI_ERROR (Status
)) {
409 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id
);
414 // Initialize the private data structure.
416 Private
= AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA
));
417 if (Private
== NULL
) {
418 return EFI_OUT_OF_RESOURCES
;
421 Private
->Signature
= HTTP_BOOT_PRIVATE_DATA_SIGNATURE
;
422 Private
->Controller
= ControllerHandle
;
423 InitializeListHead (&Private
->CacheList
);
425 // Get the NII interface if it exists, it's not required.
427 Status
= gBS
->OpenProtocol (
429 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
430 (VOID
**)&Private
->Nii
,
431 This
->DriverBindingHandle
,
433 EFI_OPEN_PROTOCOL_GET_PROTOCOL
435 if (EFI_ERROR (Status
)) {
440 // Open Device Path Protocol to prepare for appending IP and URI node.
442 Status
= gBS
->OpenProtocol (
444 &gEfiDevicePathProtocolGuid
,
445 (VOID
**)&Private
->ParentDevicePath
,
446 This
->DriverBindingHandle
,
448 EFI_OPEN_PROTOCOL_GET_PROTOCOL
450 if (EFI_ERROR (Status
)) {
455 // Initialize the HII configuration form.
457 Status
= HttpBootConfigFormInit (Private
);
458 if (EFI_ERROR (Status
)) {
463 // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between
464 // NIC handle and the private data.
466 Status
= gBS
->InstallProtocolInterface (
469 EFI_NATIVE_INTERFACE
,
472 if (EFI_ERROR (Status
)) {
477 if (Private
->Ip4Nic
!= NULL
) {
479 // Already created before
484 Private
->Ip4Nic
= AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC
));
485 if (Private
->Ip4Nic
== NULL
) {
486 Status
= EFI_OUT_OF_RESOURCES
;
490 Private
->Ip4Nic
->Private
= Private
;
491 Private
->Ip4Nic
->ImageHandle
= This
->DriverBindingHandle
;
492 Private
->Ip4Nic
->Signature
= HTTP_BOOT_VIRTUAL_NIC_SIGNATURE
;
495 // Create DHCP4 child instance.
497 Status
= NetLibCreateServiceChild (
499 This
->DriverBindingHandle
,
500 &gEfiDhcp4ServiceBindingProtocolGuid
,
503 if (EFI_ERROR (Status
)) {
507 Status
= gBS
->OpenProtocol (
509 &gEfiDhcp4ProtocolGuid
,
510 (VOID
**)&Private
->Dhcp4
,
511 This
->DriverBindingHandle
,
513 EFI_OPEN_PROTOCOL_BY_DRIVER
515 if (EFI_ERROR (Status
)) {
520 // Get the Ip4Config2 protocol, it's required to configure the default gateway address.
522 Status
= gBS
->OpenProtocol (
524 &gEfiIp4Config2ProtocolGuid
,
525 (VOID
**)&Private
->Ip4Config2
,
526 This
->DriverBindingHandle
,
528 EFI_OPEN_PROTOCOL_GET_PROTOCOL
530 if (EFI_ERROR (Status
)) {
535 // Append IPv4 device path node.
537 Node
= AllocateZeroPool (sizeof (IPv4_DEVICE_PATH
));
539 Status
= EFI_OUT_OF_RESOURCES
;
543 Node
->Ipv4
.Header
.Type
= MESSAGING_DEVICE_PATH
;
544 Node
->Ipv4
.Header
.SubType
= MSG_IPv4_DP
;
545 SetDevicePathNodeLength (Node
, sizeof (IPv4_DEVICE_PATH
));
546 Node
->Ipv4
.StaticIpAddress
= FALSE
;
547 DevicePath
= AppendDevicePathNode (Private
->ParentDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)Node
);
549 if (DevicePath
== NULL
) {
550 Status
= EFI_OUT_OF_RESOURCES
;
555 // Append URI device path node.
557 Node
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
559 Status
= EFI_OUT_OF_RESOURCES
;
563 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
564 Node
->DevPath
.SubType
= MSG_URI_DP
;
565 SetDevicePathNodeLength (Node
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
566 Private
->Ip4Nic
->DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)Node
);
568 FreePool (DevicePath
);
569 if (Private
->Ip4Nic
->DevicePath
== NULL
) {
570 Status
= EFI_OUT_OF_RESOURCES
;
575 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.
577 CopyMem (&Private
->Ip4Nic
->LoadFile
, &gHttpBootDxeLoadFile
, sizeof (EFI_LOAD_FILE_PROTOCOL
));
578 Status
= gBS
->InstallMultipleProtocolInterfaces (
579 &Private
->Ip4Nic
->Controller
,
580 &gEfiLoadFileProtocolGuid
,
581 &Private
->Ip4Nic
->LoadFile
,
582 &gEfiDevicePathProtocolGuid
,
583 Private
->Ip4Nic
->DevicePath
,
586 if (EFI_ERROR (Status
)) {
591 // Open the Caller Id child to setup a parent-child relationship between
592 // real NIC handle and the HTTP boot Ipv4 NIC handle.
594 Status
= gBS
->OpenProtocol (
598 This
->DriverBindingHandle
,
599 Private
->Ip4Nic
->Controller
,
600 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
602 if (EFI_ERROR (Status
)) {
609 if (Private
!= NULL
) {
611 gBS
->UninstallProtocolInterface (
618 HttpBootDestroyIp4Children (This
, Private
);
619 HttpBootConfigFormUnload (Private
);
630 Stops a device controller or a bus controller.
632 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
633 As a result, much of the error checking on the parameters to Stop() has been moved
634 into this common boot service. It is legal to call Stop() from other locations,
635 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
636 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
637 same driver's Start() function.
638 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
639 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
640 Start() function, and the Start() function must have called OpenProtocol() on
641 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
643 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
644 @param[in] ControllerHandle A handle to the device being stopped. The handle must
645 support a bus specific I/O protocol for the driver
646 to use to stop the device.
647 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
648 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
649 if NumberOfChildren is 0.
651 @retval EFI_SUCCESS The device was stopped.
652 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
657 HttpBootIp4DxeDriverBindingStop (
658 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
659 IN EFI_HANDLE ControllerHandle
,
660 IN UINTN NumberOfChildren
,
661 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
665 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
666 HTTP_BOOT_PRIVATE_DATA
*Private
;
667 EFI_HANDLE NicHandle
;
671 // Try to get the Load File Protocol from the controller handle.
673 Status
= gBS
->OpenProtocol (
675 &gEfiLoadFileProtocolGuid
,
677 This
->DriverBindingHandle
,
679 EFI_OPEN_PROTOCOL_GET_PROTOCOL
681 if (EFI_ERROR (Status
)) {
683 // If failed, try to find the NIC handle for this controller.
685 NicHandle
= HttpBootGetNicByIp4Children (ControllerHandle
);
686 if (NicHandle
== NULL
) {
691 // Try to retrieve the private data by the Caller Id Guid.
693 Status
= gBS
->OpenProtocol (
697 This
->DriverBindingHandle
,
699 EFI_OPEN_PROTOCOL_GET_PROTOCOL
701 if (EFI_ERROR (Status
)) {
705 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id
);
707 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile
);
708 NicHandle
= Private
->Controller
;
712 // Disable the HTTP boot function.
714 Status
= HttpBootStop (Private
);
715 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_NOT_STARTED
)) {
720 // Destroy all child instance and uninstall protocol interface.
722 HttpBootDestroyIp4Children (This
, Private
);
724 if ((Private
->Ip4Nic
== NULL
) && (Private
->Ip6Nic
== NULL
)) {
726 // Release the cached data.
728 HttpBootFreeCacheList (Private
);
731 // Unload the config form.
733 HttpBootConfigFormUnload (Private
);
735 gBS
->UninstallProtocolInterface (
747 Tests to see if this driver supports a given controller. If a child device is provided,
748 it further tests to see if this driver supports creating a handle for the specified child device.
750 This function checks to see if the driver specified by This supports the device specified by
751 ControllerHandle. Drivers will typically use the device path attached to
752 ControllerHandle and/or the services from the bus I/O abstraction attached to
753 ControllerHandle to determine if the driver supports ControllerHandle. This function
754 may be called many times during platform initialization. In order to reduce boot times, the tests
755 performed by this function must be very small, and take as little time as possible to execute. This
756 function must not change the state of any hardware devices, and this function must be aware that the
757 device specified by ControllerHandle may already be managed by the same driver or a
758 different driver. This function must match its calls to AllocatePages() with FreePages(),
759 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
760 Because ControllerHandle may have been previously started by the same driver, if a protocol is
761 already in the opened state, then it must not be closed with CloseProtocol(). This is required
762 to guarantee the state of ControllerHandle is not modified by this function.
764 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
765 @param[in] ControllerHandle The handle of the controller to test. This handle
766 must support a protocol interface that supplies
767 an I/O abstraction to the driver.
768 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
769 parameter is ignored by device drivers, and is optional for bus
770 drivers. For bus drivers, if this parameter is not NULL, then
771 the bus driver must determine if the bus controller specified
772 by ControllerHandle and the child controller specified
773 by RemainingDevicePath are both supported by this
776 @retval EFI_SUCCESS The device specified by ControllerHandle and
777 RemainingDevicePath is supported by the driver specified by This.
778 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
779 RemainingDevicePath is already being managed by the driver
781 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
782 RemainingDevicePath is already being managed by a different
783 driver or an application that requires exclusive access.
784 Currently not implemented.
785 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
786 RemainingDevicePath is not supported by the driver specified by This.
790 HttpBootIp6DxeDriverBindingSupported (
791 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
792 IN EFI_HANDLE ControllerHandle
,
793 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
799 // Try to open the DHCP6, HTTP and Device Path protocol.
801 Status
= gBS
->OpenProtocol (
803 &gEfiDhcp6ServiceBindingProtocolGuid
,
805 This
->DriverBindingHandle
,
807 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
809 if (EFI_ERROR (Status
)) {
813 Status
= gBS
->OpenProtocol (
815 &gEfiHttpServiceBindingProtocolGuid
,
817 This
->DriverBindingHandle
,
819 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
821 if (EFI_ERROR (Status
)) {
825 Status
= gBS
->OpenProtocol (
827 &gEfiDevicePathProtocolGuid
,
829 This
->DriverBindingHandle
,
831 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
838 Starts a device controller or a bus controller.
840 The Start() function is designed to be invoked from the EFI boot service ConnectController().
841 As a result, much of the error checking on the parameters to Start() has been moved into this
842 common boot service. It is legal to call Start() from other locations,
843 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
844 1. ControllerHandle must be a valid EFI_HANDLE.
845 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
846 EFI_DEVICE_PATH_PROTOCOL.
847 3. Prior to calling Start(), the Supported() function for the driver specified by This must
848 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
850 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
851 @param[in] ControllerHandle The handle of the controller to start. This handle
852 must support a protocol interface that supplies
853 an I/O abstraction to the driver.
854 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
855 parameter is ignored by device drivers, and is optional for bus
856 drivers. For a bus driver, if this parameter is NULL, then handles
857 for all the children of Controller are created by this driver.
858 If this parameter is not NULL and the first Device Path Node is
859 not the End of Device Path Node, then only the handle for the
860 child device specified by the first Device Path Node of
861 RemainingDevicePath is created by this driver.
862 If the first Device Path Node of RemainingDevicePath is
863 the End of Device Path Node, no child handle is created by this
866 @retval EFI_SUCCESS The device was started.
867 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
868 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
869 @retval Others The driver failed to start the device.
874 HttpBootIp6DxeDriverBindingStart (
875 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
876 IN EFI_HANDLE ControllerHandle
,
877 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
881 HTTP_BOOT_PRIVATE_DATA
*Private
;
883 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
885 BOOLEAN Ipv6Available
;
890 Status
= gBS
->OpenProtocol (
894 This
->DriverBindingHandle
,
896 EFI_OPEN_PROTOCOL_GET_PROTOCOL
899 if (!EFI_ERROR (Status
)) {
900 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id
);
905 // Initialize the private data structure.
907 Private
= AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA
));
908 if (Private
== NULL
) {
909 return EFI_OUT_OF_RESOURCES
;
912 Private
->Signature
= HTTP_BOOT_PRIVATE_DATA_SIGNATURE
;
913 Private
->Controller
= ControllerHandle
;
914 InitializeListHead (&Private
->CacheList
);
916 // Get the NII interface if it exists, it's not required.
918 Status
= gBS
->OpenProtocol (
920 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
921 (VOID
**)&Private
->Nii
,
922 This
->DriverBindingHandle
,
924 EFI_OPEN_PROTOCOL_GET_PROTOCOL
926 if (EFI_ERROR (Status
)) {
931 // Open Device Path Protocol to prepare for appending IP and URI node.
933 Status
= gBS
->OpenProtocol (
935 &gEfiDevicePathProtocolGuid
,
936 (VOID
**)&Private
->ParentDevicePath
,
937 This
->DriverBindingHandle
,
939 EFI_OPEN_PROTOCOL_GET_PROTOCOL
941 if (EFI_ERROR (Status
)) {
946 // Initialize the HII configuration form.
948 Status
= HttpBootConfigFormInit (Private
);
949 if (EFI_ERROR (Status
)) {
954 // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between
955 // NIC handle and the private data.
957 Status
= gBS
->InstallProtocolInterface (
960 EFI_NATIVE_INTERFACE
,
963 if (EFI_ERROR (Status
)) {
969 // Set IPv6 available flag.
971 Status
= HttpBootCheckIpv6Support (Private
, &Ipv6Available
);
972 if (EFI_ERROR (Status
)) {
974 // Fail to get the data whether UNDI supports IPv6.
975 // Set default value to TRUE.
977 Ipv6Available
= TRUE
;
980 if (!Ipv6Available
) {
981 Status
= EFI_UNSUPPORTED
;
985 if (Private
->Ip6Nic
!= NULL
) {
987 // Already created before
992 Private
->Ip6Nic
= AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC
));
993 if (Private
->Ip6Nic
== NULL
) {
994 Status
= EFI_OUT_OF_RESOURCES
;
998 Private
->Ip6Nic
->Private
= Private
;
999 Private
->Ip6Nic
->ImageHandle
= This
->DriverBindingHandle
;
1000 Private
->Ip6Nic
->Signature
= HTTP_BOOT_VIRTUAL_NIC_SIGNATURE
;
1003 // Create Dhcp6 child and open Dhcp6 protocol
1004 Status
= NetLibCreateServiceChild (
1006 This
->DriverBindingHandle
,
1007 &gEfiDhcp6ServiceBindingProtocolGuid
,
1008 &Private
->Dhcp6Child
1010 if (EFI_ERROR (Status
)) {
1014 Status
= gBS
->OpenProtocol (
1015 Private
->Dhcp6Child
,
1016 &gEfiDhcp6ProtocolGuid
,
1017 (VOID
**)&Private
->Dhcp6
,
1018 This
->DriverBindingHandle
,
1020 EFI_OPEN_PROTOCOL_BY_DRIVER
1022 if (EFI_ERROR (Status
)) {
1027 // Create Ip6 child and open Ip6 protocol for background ICMP packets.
1029 Status
= NetLibCreateServiceChild (
1031 This
->DriverBindingHandle
,
1032 &gEfiIp6ServiceBindingProtocolGuid
,
1035 if (EFI_ERROR (Status
)) {
1039 Status
= gBS
->OpenProtocol (
1041 &gEfiIp6ProtocolGuid
,
1042 (VOID
**)&Private
->Ip6
,
1043 This
->DriverBindingHandle
,
1045 EFI_OPEN_PROTOCOL_BY_DRIVER
1047 if (EFI_ERROR (Status
)) {
1052 // Locate Ip6Config protocol, it's required to configure the default gateway address.
1054 Status
= gBS
->OpenProtocol (
1056 &gEfiIp6ConfigProtocolGuid
,
1057 (VOID
**)&Private
->Ip6Config
,
1058 This
->DriverBindingHandle
,
1060 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1062 if (EFI_ERROR (Status
)) {
1067 // Append IPv6 device path node.
1069 Node
= AllocateZeroPool (sizeof (IPv6_DEVICE_PATH
));
1071 Status
= EFI_OUT_OF_RESOURCES
;
1075 Node
->Ipv6
.Header
.Type
= MESSAGING_DEVICE_PATH
;
1076 Node
->Ipv6
.Header
.SubType
= MSG_IPv6_DP
;
1077 Node
->Ipv6
.PrefixLength
= IP6_PREFIX_LENGTH
;
1078 SetDevicePathNodeLength (Node
, sizeof (IPv6_DEVICE_PATH
));
1079 DevicePath
= AppendDevicePathNode (Private
->ParentDevicePath
, (EFI_DEVICE_PATH
*)Node
);
1081 if (DevicePath
== NULL
) {
1082 Status
= EFI_OUT_OF_RESOURCES
;
1087 // Append URI device path node.
1089 Node
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1091 Status
= EFI_OUT_OF_RESOURCES
;
1095 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
1096 Node
->DevPath
.SubType
= MSG_URI_DP
;
1097 SetDevicePathNodeLength (Node
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1098 Private
->Ip6Nic
->DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)Node
);
1100 FreePool (DevicePath
);
1101 if (Private
->Ip6Nic
->DevicePath
== NULL
) {
1102 Status
= EFI_OUT_OF_RESOURCES
;
1107 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.
1109 CopyMem (&Private
->Ip6Nic
->LoadFile
, &gHttpBootDxeLoadFile
, sizeof (Private
->LoadFile
));
1110 Status
= gBS
->InstallMultipleProtocolInterfaces (
1111 &Private
->Ip6Nic
->Controller
,
1112 &gEfiLoadFileProtocolGuid
,
1113 &Private
->Ip6Nic
->LoadFile
,
1114 &gEfiDevicePathProtocolGuid
,
1115 Private
->Ip6Nic
->DevicePath
,
1118 if (EFI_ERROR (Status
)) {
1123 // Open the Caller Id child to setup a parent-child relationship between
1124 // real NIC handle and the HTTP boot child handle.
1126 Status
= gBS
->OpenProtocol (
1130 This
->DriverBindingHandle
,
1131 Private
->Ip6Nic
->Controller
,
1132 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1134 if (EFI_ERROR (Status
)) {
1141 if (Private
!= NULL
) {
1143 gBS
->UninstallProtocolInterface (
1150 HttpBootDestroyIp6Children (This
, Private
);
1151 HttpBootConfigFormUnload (Private
);
1162 Stops a device controller or a bus controller.
1164 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1165 As a result, much of the error checking on the parameters to Stop() has been moved
1166 into this common boot service. It is legal to call Stop() from other locations,
1167 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1168 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1169 same driver's Start() function.
1170 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1171 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1172 Start() function, and the Start() function must have called OpenProtocol() on
1173 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1175 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1176 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1177 support a bus specific I/O protocol for the driver
1178 to use to stop the device.
1179 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1180 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1181 if NumberOfChildren is 0.
1183 @retval EFI_SUCCESS The device was stopped.
1184 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1189 HttpBootIp6DxeDriverBindingStop (
1190 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1191 IN EFI_HANDLE ControllerHandle
,
1192 IN UINTN NumberOfChildren
,
1193 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1197 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
1198 HTTP_BOOT_PRIVATE_DATA
*Private
;
1199 EFI_HANDLE NicHandle
;
1203 // Try to get the Load File Protocol from the controller handle.
1205 Status
= gBS
->OpenProtocol (
1207 &gEfiLoadFileProtocolGuid
,
1209 This
->DriverBindingHandle
,
1211 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1213 if (EFI_ERROR (Status
)) {
1215 // If failed, try to find the NIC handle for this controller.
1217 NicHandle
= HttpBootGetNicByIp6Children (ControllerHandle
);
1218 if (NicHandle
== NULL
) {
1223 // Try to retrieve the private data by the Caller Id Guid.
1225 Status
= gBS
->OpenProtocol (
1229 This
->DriverBindingHandle
,
1231 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1233 if (EFI_ERROR (Status
)) {
1237 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id
);
1239 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile
);
1240 NicHandle
= Private
->Controller
;
1244 // Disable the HTTP boot function.
1246 Status
= HttpBootStop (Private
);
1247 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_NOT_STARTED
)) {
1252 // Destroy all child instance and uninstall protocol interface.
1254 HttpBootDestroyIp6Children (This
, Private
);
1256 if ((Private
->Ip4Nic
== NULL
) && (Private
->Ip6Nic
== NULL
)) {
1258 // Release the cached data.
1260 HttpBootFreeCacheList (Private
);
1263 // Unload the config form.
1265 HttpBootConfigFormUnload (Private
);
1267 gBS
->UninstallProtocolInterface (
1279 This is the declaration of an EFI image entry point. This entry point is
1280 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1281 both device drivers and bus drivers.
1283 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1284 @param[in] SystemTable A pointer to the EFI System Table.
1286 @retval EFI_SUCCESS The operation completed successfully.
1287 @retval Others An unexpected error occurred.
1292 HttpBootDxeDriverEntryPoint (
1293 IN EFI_HANDLE ImageHandle
,
1294 IN EFI_SYSTEM_TABLE
*SystemTable
1300 // Install UEFI Driver Model protocol(s).
1302 Status
= EfiLibInstallDriverBindingComponentName2 (
1305 &gHttpBootIp4DxeDriverBinding
,
1307 &gHttpBootDxeComponentName
,
1308 &gHttpBootDxeComponentName2
1310 if (EFI_ERROR (Status
)) {
1314 Status
= EfiLibInstallDriverBindingComponentName2 (
1317 &gHttpBootIp6DxeDriverBinding
,
1319 &gHttpBootDxeComponentName
,
1320 &gHttpBootDxeComponentName2
1322 if (EFI_ERROR (Status
)) {
1323 EfiLibUninstallDriverBindingComponentName2 (
1324 &gHttpBootIp4DxeDriverBinding
,
1325 &gHttpBootDxeComponentName
,
1326 &gHttpBootDxeComponentName2