2 Driver Binding functions implementation for UEFI HTTP boot.
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "HttpBootDxe.h"
18 /// Driver Binding Protocol instance
20 EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp4DxeDriverBinding
= {
21 HttpBootIp4DxeDriverBindingSupported
,
22 HttpBootIp4DxeDriverBindingStart
,
23 HttpBootIp4DxeDriverBindingStop
,
24 HTTP_BOOT_DXE_VERSION
,
29 EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp6DxeDriverBinding
= {
30 HttpBootIp6DxeDriverBindingSupported
,
31 HttpBootIp6DxeDriverBindingStart
,
32 HttpBootIp6DxeDriverBindingStop
,
33 HTTP_BOOT_DXE_VERSION
,
41 Check whether UNDI protocol supports IPv6.
43 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.
44 @param[out] Ipv6Support TRUE if UNDI supports IPv6.
46 @retval EFI_SUCCESS Get the result whether UNDI supports IPv6 by NII or AIP protocol successfully.
47 @retval EFI_NOT_FOUND Don't know whether UNDI supports IPv6 since NII or AIP is not available.
51 HttpBootCheckIpv6Support (
52 IN HTTP_BOOT_PRIVATE_DATA
*Private
,
53 OUT BOOLEAN
*Ipv6Support
57 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
59 EFI_GUID
*InfoTypesBuffer
;
60 UINTN InfoTypeBufferCount
;
66 ASSERT (Private
!= NULL
&& Ipv6Support
!= NULL
);
69 // Check whether the UNDI supports IPv6 by NII protocol.
71 if (Private
->Nii
!= NULL
) {
72 *Ipv6Support
= Private
->Nii
->Ipv6Supported
;
77 // Get the NIC handle by SNP protocol.
79 Handle
= NetLibGetSnpHandle (Private
->Controller
, NULL
);
85 Status
= gBS
->HandleProtocol (
87 &gEfiAdapterInformationProtocolGuid
,
90 if (EFI_ERROR (Status
) || Aip
== NULL
) {
94 InfoTypesBuffer
= NULL
;
95 InfoTypeBufferCount
= 0;
96 Status
= Aip
->GetSupportedTypes (Aip
, &InfoTypesBuffer
, &InfoTypeBufferCount
);
97 if (EFI_ERROR (Status
) || InfoTypesBuffer
== NULL
) {
98 FreePool (InfoTypesBuffer
);
103 for (TypeIndex
= 0; TypeIndex
< InfoTypeBufferCount
; TypeIndex
++) {
104 if (CompareGuid (&InfoTypesBuffer
[TypeIndex
], &gEfiAdapterInfoUndiIpv6SupportGuid
)) {
110 FreePool (InfoTypesBuffer
);
112 return EFI_NOT_FOUND
;
116 // We now have adapter information block.
120 Status
= Aip
->GetInformation (Aip
, &gEfiAdapterInfoUndiIpv6SupportGuid
, &InfoBlock
, &InfoBlockSize
);
121 if (EFI_ERROR (Status
) || InfoBlock
== NULL
) {
122 FreePool (InfoBlock
);
123 return EFI_NOT_FOUND
;
126 *Ipv6Support
= ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT
*) InfoBlock
)->Ipv6Support
;
127 FreePool (InfoBlock
);
133 Destroy the HTTP child based on IPv4 stack.
135 @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.
136 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.
140 HttpBootDestroyIp4Children (
141 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
142 IN HTTP_BOOT_PRIVATE_DATA
*Private
145 ASSERT (This
!= NULL
);
146 ASSERT (Private
!= NULL
);
148 if (Private
->Dhcp4Child
!= NULL
) {
151 &gEfiDhcp4ProtocolGuid
,
152 This
->DriverBindingHandle
,
156 NetLibDestroyServiceChild (
158 This
->DriverBindingHandle
,
159 &gEfiDhcp4ServiceBindingProtocolGuid
,
164 if (Private
->Ip6Nic
== NULL
&& Private
->HttpCreated
) {
165 HttpIoDestroyIo (&Private
->HttpIo
);
166 Private
->HttpCreated
= FALSE
;
169 if (Private
->Ip4Nic
!= NULL
) {
174 This
->DriverBindingHandle
,
175 Private
->Ip4Nic
->Controller
178 gBS
->UninstallMultipleProtocolInterfaces (
179 Private
->Ip4Nic
->Controller
,
180 &gEfiLoadFileProtocolGuid
,
181 &Private
->Ip4Nic
->LoadFile
,
182 &gEfiDevicePathProtocolGuid
,
183 Private
->Ip4Nic
->DevicePath
,
186 FreePool (Private
->Ip4Nic
);
187 Private
->Ip4Nic
= NULL
;
193 Destroy the HTTP child based on IPv6 stack.
195 @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.
196 @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.
200 HttpBootDestroyIp6Children (
201 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
202 IN HTTP_BOOT_PRIVATE_DATA
*Private
205 ASSERT (This
!= NULL
);
206 ASSERT (Private
!= NULL
);
208 if (Private
->Ip6Child
!= NULL
) {
211 &gEfiIp6ProtocolGuid
,
212 This
->DriverBindingHandle
,
216 NetLibDestroyServiceChild (
218 This
->DriverBindingHandle
,
219 &gEfiIp6ServiceBindingProtocolGuid
,
224 if (Private
->Dhcp6Child
!= NULL
) {
227 &gEfiDhcp6ProtocolGuid
,
228 This
->DriverBindingHandle
,
232 NetLibDestroyServiceChild (
234 This
->DriverBindingHandle
,
235 &gEfiDhcp6ServiceBindingProtocolGuid
,
240 if (Private
->Ip4Nic
== NULL
&& Private
->HttpCreated
) {
241 HttpIoDestroyIo(&Private
->HttpIo
);
242 Private
->HttpCreated
= FALSE
;
245 if (Private
->Ip6Nic
!= NULL
) {
250 This
->DriverBindingHandle
,
251 Private
->Ip6Nic
->Controller
254 gBS
->UninstallMultipleProtocolInterfaces (
255 Private
->Ip6Nic
->Controller
,
256 &gEfiLoadFileProtocolGuid
,
257 &Private
->Ip6Nic
->LoadFile
,
258 &gEfiDevicePathProtocolGuid
,
259 Private
->Ip6Nic
->DevicePath
,
262 FreePool (Private
->Ip6Nic
);
263 Private
->Ip6Nic
= NULL
;
268 Tests to see if this driver supports a given controller. If a child device is provided,
269 it further tests to see if this driver supports creating a handle for the specified child device.
271 This function checks to see if the driver specified by This supports the device specified by
272 ControllerHandle. Drivers will typically use the device path attached to
273 ControllerHandle and/or the services from the bus I/O abstraction attached to
274 ControllerHandle to determine if the driver supports ControllerHandle. This function
275 may be called many times during platform initialization. In order to reduce boot times, the tests
276 performed by this function must be very small, and take as little time as possible to execute. This
277 function must not change the state of any hardware devices, and this function must be aware that the
278 device specified by ControllerHandle may already be managed by the same driver or a
279 different driver. This function must match its calls to AllocatePages() with FreePages(),
280 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
281 Because ControllerHandle may have been previously started by the same driver, if a protocol is
282 already in the opened state, then it must not be closed with CloseProtocol(). This is required
283 to guarantee the state of ControllerHandle is not modified by this function.
285 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
286 @param[in] ControllerHandle The handle of the controller to test. This handle
287 must support a protocol interface that supplies
288 an I/O abstraction to the driver.
289 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
290 parameter is ignored by device drivers, and is optional for bus
291 drivers. For bus drivers, if this parameter is not NULL, then
292 the bus driver must determine if the bus controller specified
293 by ControllerHandle and the child controller specified
294 by RemainingDevicePath are both supported by this
297 @retval EFI_SUCCESS The device specified by ControllerHandle and
298 RemainingDevicePath is supported by the driver specified by This.
299 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
300 RemainingDevicePath is already being managed by the driver
302 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
303 RemainingDevicePath is already being managed by a different
304 driver or an application that requires exclusive access.
305 Currently not implemented.
306 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
307 RemainingDevicePath is not supported by the driver specified by This.
311 HttpBootIp4DxeDriverBindingSupported (
312 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
313 IN EFI_HANDLE ControllerHandle
,
314 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
320 // Try to open the DHCP4, HTTP4 and Device Path protocol.
322 Status
= gBS
->OpenProtocol (
324 &gEfiDhcp4ServiceBindingProtocolGuid
,
326 This
->DriverBindingHandle
,
328 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
330 if (EFI_ERROR (Status
)) {
334 Status
= gBS
->OpenProtocol (
336 &gEfiHttpServiceBindingProtocolGuid
,
338 This
->DriverBindingHandle
,
340 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
342 if (EFI_ERROR (Status
)) {
346 Status
= gBS
->OpenProtocol (
348 &gEfiDevicePathProtocolGuid
,
350 This
->DriverBindingHandle
,
352 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
360 Starts a device controller or a bus controller.
362 The Start() function is designed to be invoked from the EFI boot service ConnectController().
363 As a result, much of the error checking on the parameters to Start() has been moved into this
364 common boot service. It is legal to call Start() from other locations,
365 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
366 1. ControllerHandle must be a valid EFI_HANDLE.
367 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
368 EFI_DEVICE_PATH_PROTOCOL.
369 3. Prior to calling Start(), the Supported() function for the driver specified by This must
370 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
372 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
373 @param[in] ControllerHandle The handle of the controller to start. This handle
374 must support a protocol interface that supplies
375 an I/O abstraction to the driver.
376 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
377 parameter is ignored by device drivers, and is optional for bus
378 drivers. For a bus driver, if this parameter is NULL, then handles
379 for all the children of Controller are created by this driver.
380 If this parameter is not NULL and the first Device Path Node is
381 not the End of Device Path Node, then only the handle for the
382 child device specified by the first Device Path Node of
383 RemainingDevicePath is created by this driver.
384 If the first Device Path Node of RemainingDevicePath is
385 the End of Device Path Node, no child handle is created by this
388 @retval EFI_SUCCESS The device was started.
389 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
390 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
391 @retval Others The driver failded to start the device.
396 HttpBootIp4DxeDriverBindingStart (
397 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
398 IN EFI_HANDLE ControllerHandle
,
399 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
403 HTTP_BOOT_PRIVATE_DATA
*Private
;
405 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
411 Status
= gBS
->OpenProtocol (
415 This
->DriverBindingHandle
,
417 EFI_OPEN_PROTOCOL_GET_PROTOCOL
420 if (!EFI_ERROR (Status
)) {
421 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id
);
426 // Initialize the private data structure.
428 Private
= AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA
));
429 if (Private
== NULL
) {
430 return EFI_OUT_OF_RESOURCES
;
432 Private
->Signature
= HTTP_BOOT_PRIVATE_DATA_SIGNATURE
;
433 Private
->Controller
= ControllerHandle
;
434 InitializeListHead (&Private
->CacheList
);
436 // Get the NII interface if it exists, it's not required.
438 Status
= gBS
->OpenProtocol (
440 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
441 (VOID
**) &Private
->Nii
,
442 This
->DriverBindingHandle
,
444 EFI_OPEN_PROTOCOL_GET_PROTOCOL
446 if (EFI_ERROR (Status
)) {
451 // Open Device Path Protocol to prepare for appending IP and URI node.
453 Status
= gBS
->OpenProtocol (
455 &gEfiDevicePathProtocolGuid
,
456 (VOID
**) &Private
->ParentDevicePath
,
457 This
->DriverBindingHandle
,
459 EFI_OPEN_PROTOCOL_GET_PROTOCOL
461 if (EFI_ERROR (Status
)) {
466 // Initialize the HII configuration form.
468 Status
= HttpBootConfigFormInit (Private
);
469 if (EFI_ERROR (Status
)) {
474 // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between
475 // NIC handle and the private data.
477 Status
= gBS
->InstallProtocolInterface (
480 EFI_NATIVE_INTERFACE
,
483 if (EFI_ERROR (Status
)) {
489 if (Private
->Ip4Nic
!= NULL
) {
491 // Already created before
496 Private
->Ip4Nic
= AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC
));
497 if (Private
->Ip4Nic
== NULL
) {
498 Status
= EFI_OUT_OF_RESOURCES
;
501 Private
->Ip4Nic
->Private
= Private
;
502 Private
->Ip4Nic
->ImageHandle
= This
->DriverBindingHandle
;
503 Private
->Ip4Nic
->Signature
= HTTP_BOOT_VIRTUAL_NIC_SIGNATURE
;
506 // Create DHCP4 child instance.
508 Status
= NetLibCreateServiceChild (
510 This
->DriverBindingHandle
,
511 &gEfiDhcp4ServiceBindingProtocolGuid
,
514 if (EFI_ERROR (Status
)) {
518 Status
= gBS
->OpenProtocol (
520 &gEfiDhcp4ProtocolGuid
,
521 (VOID
**) &Private
->Dhcp4
,
522 This
->DriverBindingHandle
,
524 EFI_OPEN_PROTOCOL_BY_DRIVER
526 if (EFI_ERROR (Status
)) {
531 // Get the Ip4Config2 protocol, it's required to configure the default gateway address.
533 Status
= gBS
->OpenProtocol (
535 &gEfiIp4Config2ProtocolGuid
,
536 (VOID
**) &Private
->Ip4Config2
,
537 This
->DriverBindingHandle
,
539 EFI_OPEN_PROTOCOL_GET_PROTOCOL
541 if (EFI_ERROR (Status
)) {
546 // Append IPv4 device path node.
548 Node
= AllocateZeroPool (sizeof (IPv4_DEVICE_PATH
));
550 Status
= EFI_OUT_OF_RESOURCES
;
553 Node
->Ipv4
.Header
.Type
= MESSAGING_DEVICE_PATH
;
554 Node
->Ipv4
.Header
.SubType
= MSG_IPv4_DP
;
555 SetDevicePathNodeLength (Node
, sizeof (IPv4_DEVICE_PATH
));
556 Node
->Ipv4
.StaticIpAddress
= FALSE
;
557 DevicePath
= AppendDevicePathNode (Private
->ParentDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*) Node
);
559 if (DevicePath
== NULL
) {
560 Status
= EFI_OUT_OF_RESOURCES
;
565 // Append URI device path node.
567 Node
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
569 Status
= EFI_OUT_OF_RESOURCES
;
572 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
573 Node
->DevPath
.SubType
= MSG_URI_DP
;
574 SetDevicePathNodeLength (Node
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
575 Private
->Ip4Nic
->DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*) Node
);
577 FreePool (DevicePath
);
578 if (Private
->Ip4Nic
->DevicePath
== NULL
) {
579 Status
= EFI_OUT_OF_RESOURCES
;
584 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.
586 CopyMem (&Private
->Ip4Nic
->LoadFile
, &gHttpBootDxeLoadFile
, sizeof (EFI_LOAD_FILE_PROTOCOL
));
587 Status
= gBS
->InstallMultipleProtocolInterfaces (
588 &Private
->Ip4Nic
->Controller
,
589 &gEfiLoadFileProtocolGuid
,
590 &Private
->Ip4Nic
->LoadFile
,
591 &gEfiDevicePathProtocolGuid
,
592 Private
->Ip4Nic
->DevicePath
,
595 if (EFI_ERROR (Status
)) {
600 // Open the Caller Id child to setup a parent-child relationship between
601 // real NIC handle and the HTTP boot Ipv4 NIC handle.
603 Status
= gBS
->OpenProtocol (
607 This
->DriverBindingHandle
,
608 Private
->Ip4Nic
->Controller
,
609 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
611 if (EFI_ERROR (Status
)) {
618 if (Private
!= NULL
) {
620 gBS
->UninstallProtocolInterface (
627 HttpBootDestroyIp4Children (This
, Private
);
628 HttpBootConfigFormUnload (Private
);
640 Stops a device controller or a bus controller.
642 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
643 As a result, much of the error checking on the parameters to Stop() has been moved
644 into this common boot service. It is legal to call Stop() from other locations,
645 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
646 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
647 same driver's Start() function.
648 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
649 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
650 Start() function, and the Start() function must have called OpenProtocol() on
651 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
653 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
654 @param[in] ControllerHandle A handle to the device being stopped. The handle must
655 support a bus specific I/O protocol for the driver
656 to use to stop the device.
657 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
658 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
659 if NumberOfChildren is 0.
661 @retval EFI_SUCCESS The device was stopped.
662 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
667 HttpBootIp4DxeDriverBindingStop (
668 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
669 IN EFI_HANDLE ControllerHandle
,
670 IN UINTN NumberOfChildren
,
671 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
675 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
676 HTTP_BOOT_PRIVATE_DATA
*Private
;
677 EFI_HANDLE NicHandle
;
681 // Try to get the Load File Protocol from the controller handle.
683 Status
= gBS
->OpenProtocol (
685 &gEfiLoadFileProtocolGuid
,
687 This
->DriverBindingHandle
,
689 EFI_OPEN_PROTOCOL_GET_PROTOCOL
691 if (EFI_ERROR (Status
)) {
693 // If failed, try to find the NIC handle for this controller.
695 NicHandle
= HttpBootGetNicByIp4Children (ControllerHandle
);
696 if (NicHandle
== NULL
) {
701 // Try to retrieve the private data by the Caller Id Guid.
703 Status
= gBS
->OpenProtocol (
707 This
->DriverBindingHandle
,
709 EFI_OPEN_PROTOCOL_GET_PROTOCOL
711 if (EFI_ERROR (Status
)) {
714 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id
);
716 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile
);
717 NicHandle
= Private
->Controller
;
721 // Disable the HTTP boot function.
723 Status
= HttpBootStop (Private
);
724 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_NOT_STARTED
) {
729 // Destory all child instance and uninstall protocol interface.
731 HttpBootDestroyIp4Children (This
, Private
);
733 if (Private
->Ip4Nic
== NULL
&& Private
->Ip6Nic
== NULL
) {
735 // Release the cached data.
737 HttpBootFreeCacheList (Private
);
740 // Unload the config form.
742 HttpBootConfigFormUnload (Private
);
744 gBS
->UninstallProtocolInterface (
757 Tests to see if this driver supports a given controller. If a child device is provided,
758 it further tests to see if this driver supports creating a handle for the specified child device.
760 This function checks to see if the driver specified by This supports the device specified by
761 ControllerHandle. Drivers will typically use the device path attached to
762 ControllerHandle and/or the services from the bus I/O abstraction attached to
763 ControllerHandle to determine if the driver supports ControllerHandle. This function
764 may be called many times during platform initialization. In order to reduce boot times, the tests
765 performed by this function must be very small, and take as little time as possible to execute. This
766 function must not change the state of any hardware devices, and this function must be aware that the
767 device specified by ControllerHandle may already be managed by the same driver or a
768 different driver. This function must match its calls to AllocatePages() with FreePages(),
769 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
770 Because ControllerHandle may have been previously started by the same driver, if a protocol is
771 already in the opened state, then it must not be closed with CloseProtocol(). This is required
772 to guarantee the state of ControllerHandle is not modified by this function.
774 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
775 @param[in] ControllerHandle The handle of the controller to test. This handle
776 must support a protocol interface that supplies
777 an I/O abstraction to the driver.
778 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
779 parameter is ignored by device drivers, and is optional for bus
780 drivers. For bus drivers, if this parameter is not NULL, then
781 the bus driver must determine if the bus controller specified
782 by ControllerHandle and the child controller specified
783 by RemainingDevicePath are both supported by this
786 @retval EFI_SUCCESS The device specified by ControllerHandle and
787 RemainingDevicePath is supported by the driver specified by This.
788 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
789 RemainingDevicePath is already being managed by the driver
791 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
792 RemainingDevicePath is already being managed by a different
793 driver or an application that requires exclusive access.
794 Currently not implemented.
795 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
796 RemainingDevicePath is not supported by the driver specified by This.
800 HttpBootIp6DxeDriverBindingSupported (
801 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
802 IN EFI_HANDLE ControllerHandle
,
803 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
809 // Try to open the DHCP6, HTTP and Device Path protocol.
811 Status
= gBS
->OpenProtocol (
813 &gEfiDhcp6ServiceBindingProtocolGuid
,
815 This
->DriverBindingHandle
,
817 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
819 if (EFI_ERROR (Status
)) {
823 Status
= gBS
->OpenProtocol (
825 &gEfiHttpServiceBindingProtocolGuid
,
827 This
->DriverBindingHandle
,
829 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
831 if (EFI_ERROR (Status
)) {
835 Status
= gBS
->OpenProtocol (
837 &gEfiDevicePathProtocolGuid
,
839 This
->DriverBindingHandle
,
841 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
849 Starts a device controller or a bus controller.
851 The Start() function is designed to be invoked from the EFI boot service ConnectController().
852 As a result, much of the error checking on the parameters to Start() has been moved into this
853 common boot service. It is legal to call Start() from other locations,
854 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
855 1. ControllerHandle must be a valid EFI_HANDLE.
856 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
857 EFI_DEVICE_PATH_PROTOCOL.
858 3. Prior to calling Start(), the Supported() function for the driver specified by This must
859 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
861 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
862 @param[in] ControllerHandle The handle of the controller to start. This handle
863 must support a protocol interface that supplies
864 an I/O abstraction to the driver.
865 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
866 parameter is ignored by device drivers, and is optional for bus
867 drivers. For a bus driver, if this parameter is NULL, then handles
868 for all the children of Controller are created by this driver.
869 If this parameter is not NULL and the first Device Path Node is
870 not the End of Device Path Node, then only the handle for the
871 child device specified by the first Device Path Node of
872 RemainingDevicePath is created by this driver.
873 If the first Device Path Node of RemainingDevicePath is
874 the End of Device Path Node, no child handle is created by this
877 @retval EFI_SUCCESS The device was started.
878 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
879 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
880 @retval Others The driver failded to start the device.
885 HttpBootIp6DxeDriverBindingStart (
886 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
887 IN EFI_HANDLE ControllerHandle
,
888 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
892 HTTP_BOOT_PRIVATE_DATA
*Private
;
894 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
896 BOOLEAN Ipv6Available
;
901 Status
= gBS
->OpenProtocol (
905 This
->DriverBindingHandle
,
907 EFI_OPEN_PROTOCOL_GET_PROTOCOL
910 if (!EFI_ERROR (Status
)) {
911 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id
);
916 // Initialize the private data structure.
918 Private
= AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA
));
919 if (Private
== NULL
) {
920 return EFI_OUT_OF_RESOURCES
;
922 Private
->Signature
= HTTP_BOOT_PRIVATE_DATA_SIGNATURE
;
923 Private
->Controller
= ControllerHandle
;
924 InitializeListHead (&Private
->CacheList
);
926 // Get the NII interface if it exists, it's not required.
928 Status
= gBS
->OpenProtocol (
930 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
931 (VOID
**) &Private
->Nii
,
932 This
->DriverBindingHandle
,
934 EFI_OPEN_PROTOCOL_GET_PROTOCOL
936 if (EFI_ERROR (Status
)) {
941 // Open Device Path Protocol to prepare for appending IP and URI node.
943 Status
= gBS
->OpenProtocol (
945 &gEfiDevicePathProtocolGuid
,
946 (VOID
**) &Private
->ParentDevicePath
,
947 This
->DriverBindingHandle
,
949 EFI_OPEN_PROTOCOL_GET_PROTOCOL
951 if (EFI_ERROR (Status
)) {
956 // Initialize the HII configuration form.
958 Status
= HttpBootConfigFormInit (Private
);
959 if (EFI_ERROR (Status
)) {
964 // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between
965 // NIC handle and the private data.
967 Status
= gBS
->InstallProtocolInterface (
970 EFI_NATIVE_INTERFACE
,
973 if (EFI_ERROR (Status
)) {
980 // Set IPv6 available flag.
982 Status
= HttpBootCheckIpv6Support (Private
, &Ipv6Available
);
983 if (EFI_ERROR (Status
)) {
985 // Fail to get the data whether UNDI supports IPv6.
986 // Set default value to TRUE.
988 Ipv6Available
= TRUE
;
991 if (!Ipv6Available
) {
992 Status
= EFI_UNSUPPORTED
;
996 if (Private
->Ip6Nic
!= NULL
) {
998 // Already created before
1003 Private
->Ip6Nic
= AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC
));
1004 if (Private
->Ip6Nic
== NULL
) {
1005 Status
= EFI_OUT_OF_RESOURCES
;
1008 Private
->Ip6Nic
->Private
= Private
;
1009 Private
->Ip6Nic
->ImageHandle
= This
->DriverBindingHandle
;
1010 Private
->Ip6Nic
->Signature
= HTTP_BOOT_VIRTUAL_NIC_SIGNATURE
;
1013 // Create Dhcp6 child and open Dhcp6 protocol
1014 Status
= NetLibCreateServiceChild (
1016 This
->DriverBindingHandle
,
1017 &gEfiDhcp6ServiceBindingProtocolGuid
,
1018 &Private
->Dhcp6Child
1020 if (EFI_ERROR (Status
)) {
1024 Status
= gBS
->OpenProtocol (
1025 Private
->Dhcp6Child
,
1026 &gEfiDhcp6ProtocolGuid
,
1027 (VOID
**) &Private
->Dhcp6
,
1028 This
->DriverBindingHandle
,
1030 EFI_OPEN_PROTOCOL_BY_DRIVER
1032 if (EFI_ERROR (Status
)) {
1037 // Create Ip6 child and open Ip6 protocol for background ICMP packets.
1039 Status
= NetLibCreateServiceChild (
1041 This
->DriverBindingHandle
,
1042 &gEfiIp6ServiceBindingProtocolGuid
,
1045 if (EFI_ERROR (Status
)) {
1049 Status
= gBS
->OpenProtocol (
1051 &gEfiIp6ProtocolGuid
,
1052 (VOID
**) &Private
->Ip6
,
1053 This
->DriverBindingHandle
,
1055 EFI_OPEN_PROTOCOL_BY_DRIVER
1057 if (EFI_ERROR (Status
)) {
1062 // Locate Ip6Config protocol, it's required to configure the default gateway address.
1064 Status
= gBS
->OpenProtocol (
1066 &gEfiIp6ConfigProtocolGuid
,
1067 (VOID
**) &Private
->Ip6Config
,
1068 This
->DriverBindingHandle
,
1070 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1072 if (EFI_ERROR (Status
)) {
1077 // Append IPv6 device path node.
1079 Node
= AllocateZeroPool (sizeof (IPv6_DEVICE_PATH
));
1081 Status
= EFI_OUT_OF_RESOURCES
;
1084 Node
->Ipv6
.Header
.Type
= MESSAGING_DEVICE_PATH
;
1085 Node
->Ipv6
.Header
.SubType
= MSG_IPv6_DP
;
1086 Node
->Ipv6
.PrefixLength
= IP6_PREFIX_LENGTH
;
1087 SetDevicePathNodeLength (Node
, sizeof (IPv6_DEVICE_PATH
));
1088 DevicePath
= AppendDevicePathNode(Private
->ParentDevicePath
, (EFI_DEVICE_PATH
*) Node
);
1090 if (DevicePath
== NULL
) {
1091 Status
= EFI_OUT_OF_RESOURCES
;
1096 // Append URI device path node.
1098 Node
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1100 Status
= EFI_OUT_OF_RESOURCES
;
1103 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
1104 Node
->DevPath
.SubType
= MSG_URI_DP
;
1105 SetDevicePathNodeLength (Node
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1106 Private
->Ip6Nic
->DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*) Node
);
1108 FreePool (DevicePath
);
1109 if (Private
->Ip6Nic
->DevicePath
== NULL
) {
1110 Status
= EFI_OUT_OF_RESOURCES
;
1115 // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.
1117 CopyMem (&Private
->Ip6Nic
->LoadFile
, &gHttpBootDxeLoadFile
, sizeof (Private
->LoadFile
));
1118 Status
= gBS
->InstallMultipleProtocolInterfaces (
1119 &Private
->Ip6Nic
->Controller
,
1120 &gEfiLoadFileProtocolGuid
,
1121 &Private
->Ip6Nic
->LoadFile
,
1122 &gEfiDevicePathProtocolGuid
,
1123 Private
->Ip6Nic
->DevicePath
,
1126 if (EFI_ERROR (Status
)) {
1131 // Open the Caller Id child to setup a parent-child relationship between
1132 // real NIC handle and the HTTP boot child handle.
1134 Status
= gBS
->OpenProtocol (
1138 This
->DriverBindingHandle
,
1139 Private
->Ip6Nic
->Controller
,
1140 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1142 if (EFI_ERROR (Status
)) {
1149 if (Private
!= NULL
) {
1151 gBS
->UninstallProtocolInterface (
1158 HttpBootDestroyIp6Children(This
, Private
);
1159 HttpBootConfigFormUnload (Private
);
1170 Stops a device controller or a bus controller.
1172 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1173 As a result, much of the error checking on the parameters to Stop() has been moved
1174 into this common boot service. It is legal to call Stop() from other locations,
1175 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
1176 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1177 same driver's Start() function.
1178 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1179 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1180 Start() function, and the Start() function must have called OpenProtocol() on
1181 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1183 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1184 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1185 support a bus specific I/O protocol for the driver
1186 to use to stop the device.
1187 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1188 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1189 if NumberOfChildren is 0.
1191 @retval EFI_SUCCESS The device was stopped.
1192 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1197 HttpBootIp6DxeDriverBindingStop (
1198 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1199 IN EFI_HANDLE ControllerHandle
,
1200 IN UINTN NumberOfChildren
,
1201 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1205 EFI_LOAD_FILE_PROTOCOL
*LoadFile
;
1206 HTTP_BOOT_PRIVATE_DATA
*Private
;
1207 EFI_HANDLE NicHandle
;
1211 // Try to get the Load File Protocol from the controller handle.
1213 Status
= gBS
->OpenProtocol (
1215 &gEfiLoadFileProtocolGuid
,
1216 (VOID
**) &LoadFile
,
1217 This
->DriverBindingHandle
,
1219 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1221 if (EFI_ERROR (Status
)) {
1223 // If failed, try to find the NIC handle for this controller.
1225 NicHandle
= HttpBootGetNicByIp6Children (ControllerHandle
);
1226 if (NicHandle
== NULL
) {
1231 // Try to retrieve the private data by the Caller Id Guid.
1233 Status
= gBS
->OpenProtocol (
1237 This
->DriverBindingHandle
,
1239 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1241 if (EFI_ERROR (Status
)) {
1244 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id
);
1246 Private
= HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile
);
1247 NicHandle
= Private
->Controller
;
1251 // Disable the HTTP boot function.
1253 Status
= HttpBootStop (Private
);
1254 if (Status
!= EFI_SUCCESS
&& Status
!= EFI_NOT_STARTED
) {
1259 // Destory all child instance and uninstall protocol interface.
1261 HttpBootDestroyIp6Children (This
, Private
);
1263 if (Private
->Ip4Nic
== NULL
&& Private
->Ip6Nic
== NULL
) {
1265 // Release the cached data.
1267 HttpBootFreeCacheList (Private
);
1270 // Unload the config form.
1272 HttpBootConfigFormUnload (Private
);
1274 gBS
->UninstallProtocolInterface (
1286 This is the declaration of an EFI image entry point. This entry point is
1287 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1288 both device drivers and bus drivers.
1290 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1291 @param[in] SystemTable A pointer to the EFI System Table.
1293 @retval EFI_SUCCESS The operation completed successfully.
1294 @retval Others An unexpected error occurred.
1299 HttpBootDxeDriverEntryPoint (
1300 IN EFI_HANDLE ImageHandle
,
1301 IN EFI_SYSTEM_TABLE
*SystemTable
1307 // Install UEFI Driver Model protocol(s).
1309 Status
= EfiLibInstallDriverBindingComponentName2 (
1312 &gHttpBootIp4DxeDriverBinding
,
1314 &gHttpBootDxeComponentName
,
1315 &gHttpBootDxeComponentName2
1317 if (EFI_ERROR (Status
)) {
1321 Status
= EfiLibInstallDriverBindingComponentName2 (
1324 &gHttpBootIp6DxeDriverBinding
,
1326 &gHttpBootDxeComponentName
,
1327 &gHttpBootDxeComponentName2
1329 if (EFI_ERROR (Status
)) {
1330 gBS
->UninstallMultipleProtocolInterfaces(
1332 &gEfiDriverBindingProtocolGuid
,
1333 &gHttpBootIp4DxeDriverBinding
,
1334 &gEfiComponentName2ProtocolGuid
,
1335 &gHttpBootDxeComponentName2
,
1336 &gEfiComponentNameProtocolGuid
,
1337 &gHttpBootDxeComponentName
,