2 The driver binding and service binding protocol for DnsDxe driver.
4 Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 EFI_DRIVER_BINDING_PROTOCOL gDns4DriverBinding
= {
12 Dns4DriverBindingSupported
,
13 Dns4DriverBindingStart
,
14 Dns4DriverBindingStop
,
20 EFI_DRIVER_BINDING_PROTOCOL gDns6DriverBinding
= {
21 Dns6DriverBindingSupported
,
22 Dns6DriverBindingStart
,
23 Dns6DriverBindingStop
,
29 EFI_SERVICE_BINDING_PROTOCOL mDns4ServiceBinding
= {
30 Dns4ServiceBindingCreateChild
,
31 Dns4ServiceBindingDestroyChild
34 EFI_SERVICE_BINDING_PROTOCOL mDns6ServiceBinding
= {
35 Dns6ServiceBindingCreateChild
,
36 Dns6ServiceBindingDestroyChild
39 DNS_DRIVER_DATA
*mDriverData
= NULL
;
42 Destroy the DNS instance and recycle the resources.
44 @param[in] Instance The pointer to the DNS instance.
49 IN DNS_INSTANCE
*Instance
52 ZeroMem (&Instance
->Dns4CfgData
, sizeof (EFI_DNS4_CONFIG_DATA
));
54 ZeroMem (&Instance
->Dns6CfgData
, sizeof (EFI_DNS6_CONFIG_DATA
));
56 if (!NetMapIsEmpty (&Instance
->Dns4TxTokens
)) {
57 Dns4InstanceCancelToken (Instance
, NULL
);
60 if (!NetMapIsEmpty (&Instance
->Dns6TxTokens
)) {
61 Dns6InstanceCancelToken (Instance
, NULL
);
64 if (Instance
->UdpIo
!= NULL
) {
65 UdpIoFreeIo (Instance
->UdpIo
);
72 Create the DNS instance and initialize it.
74 @param[in] Service The pointer to the DNS service.
75 @param[out] Instance The pointer to the DNS instance.
77 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
78 @retval EFI_SUCCESS The DNS instance is created.
83 IN DNS_SERVICE
*Service
,
84 OUT DNS_INSTANCE
**Instance
91 DnsIns
= AllocateZeroPool (sizeof (DNS_INSTANCE
));
93 return EFI_OUT_OF_RESOURCES
;
96 DnsIns
->Signature
= DNS_INSTANCE_SIGNATURE
;
97 InitializeListHead (&DnsIns
->Link
);
98 DnsIns
->State
= DNS_STATE_UNCONFIGED
;
99 DnsIns
->InDestroy
= FALSE
;
100 DnsIns
->Service
= Service
;
102 if (Service
->IpVersion
== IP_VERSION_4
) {
103 CopyMem (&DnsIns
->Dns4
, &mDns4Protocol
, sizeof (DnsIns
->Dns4
));
104 NetMapInit (&DnsIns
->Dns4TxTokens
);
106 CopyMem (&DnsIns
->Dns6
, &mDns6Protocol
, sizeof (DnsIns
->Dns6
));
107 NetMapInit (&DnsIns
->Dns6TxTokens
);
110 DnsIns
->UdpIo
= UdpIoCreateIo (
111 Service
->ControllerHandle
, /// NicHandle
112 Service
->ImageHandle
,
117 if (DnsIns
->UdpIo
== NULL
) {
119 return EFI_OUT_OF_RESOURCES
;
128 Callback function which provided by user to remove one node in NetDestroyLinkList process.
130 @param[in] Entry The entry to be removed.
131 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
133 @retval EFI_SUCCESS The entry has been removed successfully.
134 @retval Others Fail to remove the entry.
139 DnsDestroyChildEntryInHandleBuffer (
140 IN LIST_ENTRY
*Entry
,
144 DNS_INSTANCE
*Instance
;
145 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
146 UINTN NumberOfChildren
;
147 EFI_HANDLE
*ChildHandleBuffer
;
149 if ((Entry
== NULL
) || (Context
== NULL
)) {
150 return EFI_INVALID_PARAMETER
;
153 Instance
= NET_LIST_USER_STRUCT_S (Entry
, DNS_INSTANCE
, Link
, DNS_INSTANCE_SIGNATURE
);
154 ServiceBinding
= ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->ServiceBinding
;
155 NumberOfChildren
= ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->NumberOfChildren
;
156 ChildHandleBuffer
= ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->ChildHandleBuffer
;
158 if (!NetIsInHandleBuffer (Instance
->ChildHandle
, NumberOfChildren
, ChildHandleBuffer
)) {
162 return ServiceBinding
->DestroyChild (ServiceBinding
, Instance
->ChildHandle
);
166 Config a NULL UDP that is used to keep the connection between UDP and DNS.
168 Just leave the Udp child unconfigured. When UDP is unloaded,
169 DNS will be informed with DriverBinding Stop.
171 @param UdpIo The UDP_IO to configure
172 @param Context The opaque parameter to the callback
174 @retval EFI_SUCCESS It always return EFI_SUCCESS directly.
188 Release all the resource used the DNS service binding instance.
190 @param DnsSb The Dns service binding instance.
195 IN DNS_SERVICE
*DnsSb
198 UdpIoFreeIo (DnsSb
->ConnectUdp
);
200 if (DnsSb
->TimerToGetMap
!= NULL
) {
201 gBS
->CloseEvent (DnsSb
->TimerToGetMap
);
204 if (DnsSb
->Timer
!= NULL
) {
205 gBS
->CloseEvent (DnsSb
->Timer
);
212 Create then initialize a Dns service binding instance.
214 @param Controller The controller to install the DNS service
216 @param Image The driver binding image of the DNS driver
217 @param IpVersion IpVersion for this service
218 @param Service The variable to receive the created service
221 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to create the instance.
222 @retval EFI_DEVICE_ERROR Failed to create a NULL UDP port to keep
224 @retval EFI_SUCCESS The service instance is created for the
230 IN EFI_HANDLE Controller
,
233 OUT DNS_SERVICE
**Service
239 Status
= EFI_SUCCESS
;
244 DnsSb
= AllocateZeroPool (sizeof (DNS_SERVICE
));
246 return EFI_OUT_OF_RESOURCES
;
249 DnsSb
->Signature
= DNS_SERVICE_SIGNATURE
;
251 if (IpVersion
== IP_VERSION_4
) {
252 DnsSb
->ServiceBinding
= mDns4ServiceBinding
;
254 DnsSb
->ServiceBinding
= mDns6ServiceBinding
;
257 DnsSb
->Dns4ChildrenNum
= 0;
258 InitializeListHead (&DnsSb
->Dns4ChildrenList
);
260 DnsSb
->Dns6ChildrenNum
= 0;
261 InitializeListHead (&DnsSb
->Dns6ChildrenList
);
263 DnsSb
->ControllerHandle
= Controller
;
264 DnsSb
->ImageHandle
= Image
;
266 DnsSb
->TimerToGetMap
= NULL
;
270 DnsSb
->IpVersion
= IpVersion
;
273 // Create the timer used to time out the procedure which is used to
274 // get the default IP address.
276 Status
= gBS
->CreateEvent (
281 &DnsSb
->TimerToGetMap
283 if (EFI_ERROR (Status
)) {
289 // Create the timer to retransmit packets.
291 Status
= gBS
->CreateEvent (
292 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
294 DnsOnTimerRetransmit
,
298 if (EFI_ERROR (Status
)) {
299 if (DnsSb
->TimerToGetMap
!= NULL
) {
300 gBS
->CloseEvent (DnsSb
->TimerToGetMap
);
307 DnsSb
->ConnectUdp
= NULL
;
308 DnsSb
->ConnectUdp
= UdpIoCreateIo (
315 if (DnsSb
->ConnectUdp
== NULL
) {
316 if (DnsSb
->TimerToGetMap
!= NULL
) {
317 gBS
->CloseEvent (DnsSb
->TimerToGetMap
);
320 gBS
->CloseEvent (DnsSb
->Timer
);
322 return EFI_DEVICE_ERROR
;
332 @param ImageHandle Handle that identifies the image to be unloaded.
334 @retval EFI_SUCCESS The image has been unloaded.
335 @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
341 IN EFI_HANDLE ImageHandle
347 DNS4_CACHE
*ItemCache4
;
348 DNS4_SERVER_IP
*ItemServerIp4
;
349 DNS6_CACHE
*ItemCache6
;
350 DNS6_SERVER_IP
*ItemServerIp6
;
353 ItemServerIp4
= NULL
;
355 ItemServerIp6
= NULL
;
358 // Disconnect the driver specified by ImageHandle
360 Status
= NetLibDefaultUnload (ImageHandle
);
361 if (EFI_ERROR (Status
)) {
368 if (mDriverData
!= NULL
) {
369 if (mDriverData
->Timer
!= NULL
) {
370 gBS
->CloseEvent (mDriverData
->Timer
);
373 while (!IsListEmpty (&mDriverData
->Dns4CacheList
)) {
374 Entry
= NetListRemoveHead (&mDriverData
->Dns4CacheList
);
375 ASSERT (Entry
!= NULL
);
376 ItemCache4
= NET_LIST_USER_STRUCT (Entry
, DNS4_CACHE
, AllCacheLink
);
377 FreePool (ItemCache4
->DnsCache
.HostName
);
378 FreePool (ItemCache4
->DnsCache
.IpAddress
);
379 FreePool (ItemCache4
);
382 while (!IsListEmpty (&mDriverData
->Dns4ServerList
)) {
383 Entry
= NetListRemoveHead (&mDriverData
->Dns4ServerList
);
384 ASSERT (Entry
!= NULL
);
385 ItemServerIp4
= NET_LIST_USER_STRUCT (Entry
, DNS4_SERVER_IP
, AllServerLink
);
386 FreePool (ItemServerIp4
);
389 while (!IsListEmpty (&mDriverData
->Dns6CacheList
)) {
390 Entry
= NetListRemoveHead (&mDriverData
->Dns6CacheList
);
391 ASSERT (Entry
!= NULL
);
392 ItemCache6
= NET_LIST_USER_STRUCT (Entry
, DNS6_CACHE
, AllCacheLink
);
393 FreePool (ItemCache6
->DnsCache
.HostName
);
394 FreePool (ItemCache6
->DnsCache
.IpAddress
);
395 FreePool (ItemCache6
);
398 while (!IsListEmpty (&mDriverData
->Dns6ServerList
)) {
399 Entry
= NetListRemoveHead (&mDriverData
->Dns6ServerList
);
400 ASSERT (Entry
!= NULL
);
401 ItemServerIp6
= NET_LIST_USER_STRUCT (Entry
, DNS6_SERVER_IP
, AllServerLink
);
402 FreePool (ItemServerIp6
);
405 FreePool (mDriverData
);
412 This is the declaration of an EFI image entry point. This entry point is
413 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
414 both device drivers and bus drivers.
416 @param ImageHandle The firmware allocated handle for the UEFI image.
417 @param SystemTable A pointer to the EFI System Table.
419 @retval EFI_SUCCESS The operation completed successfully.
420 @retval Others An unexpected error occurred.
424 DnsDriverEntryPoint (
425 IN EFI_HANDLE ImageHandle
,
426 IN EFI_SYSTEM_TABLE
*SystemTable
431 Status
= EFI_SUCCESS
;
434 // Install the Dns4 Driver Binding Protocol.
436 Status
= EfiLibInstallDriverBindingComponentName2 (
444 if (EFI_ERROR (Status
)) {
449 // Install the Dns6 Driver Binding Protocol.
451 Status
= EfiLibInstallDriverBindingComponentName2 (
459 if (EFI_ERROR (Status
)) {
464 // Create the driver data structures.
466 mDriverData
= AllocateZeroPool (sizeof (DNS_DRIVER_DATA
));
467 if (mDriverData
== NULL
) {
468 Status
= EFI_OUT_OF_RESOURCES
;
473 // Create the timer event to update DNS cache list.
475 Status
= gBS
->CreateEvent (
476 EVT_NOTIFY_SIGNAL
| EVT_TIMER
,
482 if (EFI_ERROR (Status
)) {
486 Status
= gBS
->SetTimer (mDriverData
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
487 if (EFI_ERROR (Status
)) {
491 InitializeListHead (&mDriverData
->Dns4CacheList
);
492 InitializeListHead (&mDriverData
->Dns4ServerList
);
493 InitializeListHead (&mDriverData
->Dns6CacheList
);
494 InitializeListHead (&mDriverData
->Dns6ServerList
);
499 gBS
->CloseEvent (mDriverData
->Timer
);
502 FreePool (mDriverData
);
505 EfiLibUninstallDriverBindingComponentName2 (
512 EfiLibUninstallDriverBindingComponentName2 (
522 Tests to see if this driver supports a given controller. If a child device is provided,
523 it further tests to see if this driver supports creating a handle for the specified child device.
525 This function checks to see if the driver specified by This supports the device specified by
526 ControllerHandle. Drivers will typically use the device path attached to
527 ControllerHandle and/or the services from the bus I/O abstraction attached to
528 ControllerHandle to determine if the driver supports ControllerHandle. This function
529 may be called many times during platform initialization. In order to reduce boot times, the tests
530 performed by this function must be very small, and take as little time as possible to execute. This
531 function must not change the state of any hardware devices, and this function must be aware that the
532 device specified by ControllerHandle may already be managed by the same driver or a
533 different driver. This function must match its calls to AllocatePages() with FreePages(),
534 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
535 Because ControllerHandle may have been previously started by the same driver, if a protocol is
536 already in the opened state, then it must not be closed with CloseProtocol(). This is required
537 to guarantee the state of ControllerHandle is not modified by this function.
539 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
540 @param[in] ControllerHandle The handle of the controller to test. This handle
541 must support a protocol interface that supplies
542 an I/O abstraction to the driver.
543 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
544 parameter is ignored by device drivers, and is optional for bus
545 drivers. For bus drivers, if this parameter is not NULL, then
546 the bus driver must determine if the bus controller specified
547 by ControllerHandle and the child controller specified
548 by RemainingDevicePath are both supported by this
551 @retval EFI_SUCCESS The device specified by ControllerHandle and
552 RemainingDevicePath is supported by the driver specified by This.
553 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
554 RemainingDevicePath is already being managed by the driver
556 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
557 RemainingDevicePath is already being managed by a different
558 driver or an application that requires exclusive access.
559 Currently not implemented.
560 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
561 RemainingDevicePath is not supported by the driver specified by This.
565 Dns4DriverBindingSupported (
566 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
567 IN EFI_HANDLE ControllerHandle
,
568 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
574 // Test for the Dns4ServiceBinding Protocol.
576 Status
= gBS
->OpenProtocol (
578 &gEfiDns4ServiceBindingProtocolGuid
,
580 This
->DriverBindingHandle
,
582 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
584 if (!EFI_ERROR (Status
)) {
585 return EFI_ALREADY_STARTED
;
589 // Test for the Udp4ServiceBinding Protocol.
591 Status
= gBS
->OpenProtocol (
593 &gEfiUdp4ServiceBindingProtocolGuid
,
595 This
->DriverBindingHandle
,
597 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
604 Starts a device controller or a bus controller.
606 The Start() function is designed to be invoked from the EFI boot service ConnectController().
607 As a result, much of the error checking on the parameters to Start() has been moved into this
608 common boot service. It is legal to call Start() from other locations,
609 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
610 1. ControllerHandle must be a valid EFI_HANDLE.
611 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
612 EFI_DEVICE_PATH_PROTOCOL.
613 3. Prior to calling Start(), the Supported() function for the driver specified by This must
614 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
616 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
617 @param[in] ControllerHandle The handle of the controller to start. This handle
618 must support a protocol interface that supplies
619 an I/O abstraction to the driver.
620 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
621 parameter is ignored by device drivers, and is optional for bus
622 drivers. For a bus driver, if this parameter is NULL, then handles
623 for all the children of Controller are created by this driver.
624 If this parameter is not NULL and the first Device Path Node is
625 not the End of Device Path Node, then only the handle for the
626 child device specified by the first Device Path Node of
627 RemainingDevicePath is created by this driver.
628 If the first Device Path Node of RemainingDevicePath is
629 the End of Device Path Node, no child handle is created by this
632 @retval EFI_SUCCESS The device was started.
633 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
634 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
635 @retval Others The driver failed to start the device.
640 Dns4DriverBindingStart (
641 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
642 IN EFI_HANDLE ControllerHandle
,
643 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
649 Status
= DnsCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_4
, &DnsSb
);
650 if (EFI_ERROR (Status
)) {
654 ASSERT (DnsSb
!= NULL
);
656 Status
= gBS
->SetTimer (DnsSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
657 if (EFI_ERROR (Status
)) {
662 // Install the Dns4ServiceBinding Protocol onto ControllerHandle.
664 Status
= gBS
->InstallMultipleProtocolInterfaces (
666 &gEfiDns4ServiceBindingProtocolGuid
,
667 &DnsSb
->ServiceBinding
,
670 if (EFI_ERROR (Status
)) {
677 DnsDestroyService (DnsSb
);
683 Stops a device controller or a bus controller.
685 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
686 As a result, much of the error checking on the parameters to Stop() has been moved
687 into this common boot service. It is legal to call Stop() from other locations,
688 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
689 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
690 same driver's Start() function.
691 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
692 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
693 Start() function, and the Start() function must have called OpenProtocol() on
694 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
696 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
697 @param[in] ControllerHandle A handle to the device being stopped. The handle must
698 support a bus specific I/O protocol for the driver
699 to use to stop the device.
700 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
701 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
702 if NumberOfChildren is 0.
704 @retval EFI_SUCCESS The device was stopped.
705 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
710 Dns4DriverBindingStop (
711 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
712 IN EFI_HANDLE ControllerHandle
,
713 IN UINTN NumberOfChildren
,
714 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
717 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
719 EFI_HANDLE NicHandle
;
722 DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
725 // DNS driver opens UDP child, So, Controller is a UDP
726 // child handle. Locate the Nic handle first. Then get the
727 // DNS private data back.
729 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiUdp4ProtocolGuid
);
731 if (NicHandle
== NULL
) {
735 Status
= gBS
->OpenProtocol (
737 &gEfiDns4ServiceBindingProtocolGuid
,
738 (VOID
**)&ServiceBinding
,
739 This
->DriverBindingHandle
,
741 EFI_OPEN_PROTOCOL_GET_PROTOCOL
743 if (EFI_ERROR (Status
)) {
744 return EFI_DEVICE_ERROR
;
747 DnsSb
= DNS_SERVICE_FROM_THIS (ServiceBinding
);
749 if (!IsListEmpty (&DnsSb
->Dns4ChildrenList
)) {
751 // Destroy the Dns child instance in ChildHandleBuffer.
753 List
= &DnsSb
->Dns4ChildrenList
;
754 Context
.ServiceBinding
= ServiceBinding
;
755 Context
.NumberOfChildren
= NumberOfChildren
;
756 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
757 Status
= NetDestroyLinkList (
759 DnsDestroyChildEntryInHandleBuffer
,
765 if ((NumberOfChildren
== 0) && IsListEmpty (&DnsSb
->Dns4ChildrenList
)) {
766 gBS
->UninstallProtocolInterface (
768 &gEfiDns4ServiceBindingProtocolGuid
,
772 DnsDestroyService (DnsSb
);
774 if (gDnsControllerNameTable
!= NULL
) {
775 FreeUnicodeStringTable (gDnsControllerNameTable
);
776 gDnsControllerNameTable
= NULL
;
779 Status
= EFI_SUCCESS
;
786 Tests to see if this driver supports a given controller. If a child device is provided,
787 it further tests to see if this driver supports creating a handle for the specified child device.
789 This function checks to see if the driver specified by This supports the device specified by
790 ControllerHandle. Drivers will typically use the device path attached to
791 ControllerHandle and/or the services from the bus I/O abstraction attached to
792 ControllerHandle to determine if the driver supports ControllerHandle. This function
793 may be called many times during platform initialization. In order to reduce boot times, the tests
794 performed by this function must be very small, and take as little time as possible to execute. This
795 function must not change the state of any hardware devices, and this function must be aware that the
796 device specified by ControllerHandle may already be managed by the same driver or a
797 different driver. This function must match its calls to AllocatePages() with FreePages(),
798 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
799 Because ControllerHandle may have been previously started by the same driver, if a protocol is
800 already in the opened state, then it must not be closed with CloseProtocol(). This is required
801 to guarantee the state of ControllerHandle is not modified by this function.
803 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
804 @param[in] ControllerHandle The handle of the controller to test. This handle
805 must support a protocol interface that supplies
806 an I/O abstraction to the driver.
807 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
808 parameter is ignored by device drivers, and is optional for bus
809 drivers. For bus drivers, if this parameter is not NULL, then
810 the bus driver must determine if the bus controller specified
811 by ControllerHandle and the child controller specified
812 by RemainingDevicePath are both supported by this
815 @retval EFI_SUCCESS The device specified by ControllerHandle and
816 RemainingDevicePath is supported by the driver specified by This.
817 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
818 RemainingDevicePath is already being managed by the driver
820 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
821 RemainingDevicePath is already being managed by a different
822 driver or an application that requires exclusive access.
823 Currently not implemented.
824 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
825 RemainingDevicePath is not supported by the driver specified by This.
829 Dns6DriverBindingSupported (
830 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
831 IN EFI_HANDLE ControllerHandle
,
832 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
838 // Test for the Dns6ServiceBinding Protocol
840 Status
= gBS
->OpenProtocol (
842 &gEfiDns6ServiceBindingProtocolGuid
,
844 This
->DriverBindingHandle
,
846 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
848 if (!EFI_ERROR (Status
)) {
849 return EFI_ALREADY_STARTED
;
853 // Test for the Udp6ServiceBinding Protocol
855 Status
= gBS
->OpenProtocol (
857 &gEfiUdp6ServiceBindingProtocolGuid
,
859 This
->DriverBindingHandle
,
861 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
868 Starts a device controller or a bus controller.
870 The Start() function is designed to be invoked from the EFI boot service ConnectController().
871 As a result, much of the error checking on the parameters to Start() has been moved into this
872 common boot service. It is legal to call Start() from other locations,
873 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
874 1. ControllerHandle must be a valid EFI_HANDLE.
875 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
876 EFI_DEVICE_PATH_PROTOCOL.
877 3. Prior to calling Start(), the Supported() function for the driver specified by This must
878 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
880 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
881 @param[in] ControllerHandle The handle of the controller to start. This handle
882 must support a protocol interface that supplies
883 an I/O abstraction to the driver.
884 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
885 parameter is ignored by device drivers, and is optional for bus
886 drivers. For a bus driver, if this parameter is NULL, then handles
887 for all the children of Controller are created by this driver.
888 If this parameter is not NULL and the first Device Path Node is
889 not the End of Device Path Node, then only the handle for the
890 child device specified by the first Device Path Node of
891 RemainingDevicePath is created by this driver.
892 If the first Device Path Node of RemainingDevicePath is
893 the End of Device Path Node, no child handle is created by this
896 @retval EFI_SUCCESS The device was started.
897 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
898 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
899 @retval Others The driver failed to start the device.
904 Dns6DriverBindingStart (
905 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
906 IN EFI_HANDLE ControllerHandle
,
907 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
913 Status
= DnsCreateService (ControllerHandle
, This
->DriverBindingHandle
, IP_VERSION_6
, &DnsSb
);
914 if (EFI_ERROR (Status
)) {
918 ASSERT (DnsSb
!= NULL
);
920 Status
= gBS
->SetTimer (DnsSb
->Timer
, TimerPeriodic
, TICKS_PER_SECOND
);
921 if (EFI_ERROR (Status
)) {
926 // Install the Dns6ServiceBinding Protocol onto ControllerHandle
928 Status
= gBS
->InstallMultipleProtocolInterfaces (
930 &gEfiDns6ServiceBindingProtocolGuid
,
931 &DnsSb
->ServiceBinding
,
935 if (EFI_ERROR (Status
)) {
942 DnsDestroyService (DnsSb
);
948 Stops a device controller or a bus controller.
950 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
951 As a result, much of the error checking on the parameters to Stop() has been moved
952 into this common boot service. It is legal to call Stop() from other locations,
953 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
954 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
955 same driver's Start() function.
956 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
957 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
958 Start() function, and the Start() function must have called OpenProtocol() on
959 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
961 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
962 @param[in] ControllerHandle A handle to the device being stopped. The handle must
963 support a bus specific I/O protocol for the driver
964 to use to stop the device.
965 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
966 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
967 if NumberOfChildren is 0.
969 @retval EFI_SUCCESS The device was stopped.
970 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
975 Dns6DriverBindingStop (
976 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
977 IN EFI_HANDLE ControllerHandle
,
978 IN UINTN NumberOfChildren
,
979 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
982 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
984 EFI_HANDLE NicHandle
;
987 DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
990 // DNS driver opens UDP child, So, Controller is a UDP
991 // child handle. Locate the Nic handle first. Then get the
992 // DNS private data back.
994 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiUdp6ProtocolGuid
);
996 if (NicHandle
== NULL
) {
1000 Status
= gBS
->OpenProtocol (
1002 &gEfiDns6ServiceBindingProtocolGuid
,
1003 (VOID
**)&ServiceBinding
,
1004 This
->DriverBindingHandle
,
1006 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1008 if (EFI_ERROR (Status
)) {
1009 return EFI_DEVICE_ERROR
;
1012 DnsSb
= DNS_SERVICE_FROM_THIS (ServiceBinding
);
1014 if (!IsListEmpty (&DnsSb
->Dns6ChildrenList
)) {
1016 // Destroy the Dns child instance in ChildHandleBuffer.
1018 List
= &DnsSb
->Dns6ChildrenList
;
1019 Context
.ServiceBinding
= ServiceBinding
;
1020 Context
.NumberOfChildren
= NumberOfChildren
;
1021 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
1022 Status
= NetDestroyLinkList (
1024 DnsDestroyChildEntryInHandleBuffer
,
1030 if ((NumberOfChildren
== 0) && IsListEmpty (&DnsSb
->Dns6ChildrenList
)) {
1031 gBS
->UninstallProtocolInterface (
1033 &gEfiDns6ServiceBindingProtocolGuid
,
1037 DnsDestroyService (DnsSb
);
1039 if (gDnsControllerNameTable
!= NULL
) {
1040 FreeUnicodeStringTable (gDnsControllerNameTable
);
1041 gDnsControllerNameTable
= NULL
;
1044 Status
= EFI_SUCCESS
;
1051 Creates a child handle and installs a protocol.
1053 The CreateChild() function installs a protocol on ChildHandle.
1054 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
1055 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
1057 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
1058 @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,
1059 then a new handle is created. If it is a pointer to an existing UEFI handle,
1060 then the protocol is added to the existing UEFI handle.
1062 @retval EFI_SUCCESS The protocol was added to ChildHandle.
1063 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
1064 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
1066 @retval other The child handle was not created
1071 Dns4ServiceBindingCreateChild (
1072 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
1073 IN EFI_HANDLE
*ChildHandle
1077 DNS_INSTANCE
*Instance
;
1082 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
1083 return EFI_INVALID_PARAMETER
;
1086 DnsSb
= DNS_SERVICE_FROM_THIS (This
);
1088 Status
= DnsCreateInstance (DnsSb
, &Instance
);
1089 if (EFI_ERROR (Status
)) {
1093 ASSERT (Instance
!= NULL
);
1096 // Install the DNS protocol onto ChildHandle
1098 Status
= gBS
->InstallMultipleProtocolInterfaces (
1100 &gEfiDns4ProtocolGuid
,
1104 if (EFI_ERROR (Status
)) {
1108 Instance
->ChildHandle
= *ChildHandle
;
1111 // Open the Udp4 protocol BY_CHILD.
1113 Status
= gBS
->OpenProtocol (
1114 DnsSb
->ConnectUdp
->UdpHandle
,
1115 &gEfiUdp4ProtocolGuid
,
1117 gDns4DriverBinding
.DriverBindingHandle
,
1118 Instance
->ChildHandle
,
1119 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1121 if (EFI_ERROR (Status
)) {
1122 gBS
->UninstallMultipleProtocolInterfaces (
1123 Instance
->ChildHandle
,
1124 &gEfiDns4ProtocolGuid
,
1133 // Open the Udp4 protocol by child.
1135 Status
= gBS
->OpenProtocol (
1136 Instance
->UdpIo
->UdpHandle
,
1137 &gEfiUdp4ProtocolGuid
,
1139 gDns4DriverBinding
.DriverBindingHandle
,
1140 Instance
->ChildHandle
,
1141 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1143 if (EFI_ERROR (Status
)) {
1145 // Close the Udp4 protocol.
1147 gBS
->CloseProtocol (
1148 DnsSb
->ConnectUdp
->UdpHandle
,
1149 &gEfiUdp4ProtocolGuid
,
1150 gDns4DriverBinding
.DriverBindingHandle
,
1154 gBS
->UninstallMultipleProtocolInterfaces (
1155 Instance
->ChildHandle
,
1156 &gEfiDns4ProtocolGuid
,
1165 // Add it to the parent's child list.
1167 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1169 InsertTailList (&DnsSb
->Dns4ChildrenList
, &Instance
->Link
);
1170 DnsSb
->Dns4ChildrenNum
++;
1172 gBS
->RestoreTPL (OldTpl
);
1178 DnsDestroyInstance (Instance
);
1183 Destroys a child handle with a protocol installed on it.
1185 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
1186 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
1187 last protocol on ChildHandle, then ChildHandle is destroyed.
1189 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
1190 @param[in] ChildHandle Handle of the child to destroy
1192 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
1193 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
1194 @retval EFI_INVALID_PARAMETER Child handle is NULL.
1195 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
1196 because its services are being used.
1197 @retval other The child handle was not destroyed
1202 Dns4ServiceBindingDestroyChild (
1203 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
1204 IN EFI_HANDLE ChildHandle
1208 DNS_INSTANCE
*Instance
;
1210 EFI_DNS4_PROTOCOL
*Dns4
;
1214 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
1215 return EFI_INVALID_PARAMETER
;
1219 // Retrieve the private context data structures
1221 Status
= gBS
->OpenProtocol (
1223 &gEfiDns4ProtocolGuid
,
1225 gDns4DriverBinding
.DriverBindingHandle
,
1227 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1230 if (EFI_ERROR (Status
)) {
1231 return EFI_UNSUPPORTED
;
1234 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL4 (Dns4
);
1235 DnsSb
= DNS_SERVICE_FROM_THIS (This
);
1237 if (Instance
->Service
!= DnsSb
) {
1238 return EFI_INVALID_PARAMETER
;
1241 if (Instance
->InDestroy
) {
1245 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1247 Instance
->InDestroy
= TRUE
;
1250 // Close the Udp4 protocol.
1252 gBS
->CloseProtocol (
1253 DnsSb
->ConnectUdp
->UdpHandle
,
1254 &gEfiUdp4ProtocolGuid
,
1255 gDns4DriverBinding
.DriverBindingHandle
,
1259 gBS
->CloseProtocol (
1260 Instance
->UdpIo
->UdpHandle
,
1261 &gEfiUdp4ProtocolGuid
,
1262 gDns4DriverBinding
.DriverBindingHandle
,
1266 gBS
->RestoreTPL (OldTpl
);
1269 // Uninstall the DNS protocol first to enable a top down destruction.
1271 Status
= gBS
->UninstallProtocolInterface (
1273 &gEfiDns4ProtocolGuid
,
1277 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1279 if (EFI_ERROR (Status
)) {
1280 Instance
->InDestroy
= FALSE
;
1281 gBS
->RestoreTPL (OldTpl
);
1285 RemoveEntryList (&Instance
->Link
);
1286 DnsSb
->Dns4ChildrenNum
--;
1288 gBS
->RestoreTPL (OldTpl
);
1290 DnsDestroyInstance (Instance
);
1295 Creates a child handle and installs a protocol.
1297 The CreateChild() function installs a protocol on ChildHandle.
1298 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
1299 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
1301 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
1302 @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,
1303 then a new handle is created. If it is a pointer to an existing UEFI handle,
1304 then the protocol is added to the existing UEFI handle.
1306 @retval EFI_SUCCESS The protocol was added to ChildHandle.
1307 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
1308 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
1310 @retval other The child handle was not created
1315 Dns6ServiceBindingCreateChild (
1316 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
1317 IN EFI_HANDLE
*ChildHandle
1321 DNS_INSTANCE
*Instance
;
1326 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
1327 return EFI_INVALID_PARAMETER
;
1330 DnsSb
= DNS_SERVICE_FROM_THIS (This
);
1332 Status
= DnsCreateInstance (DnsSb
, &Instance
);
1333 if (EFI_ERROR (Status
)) {
1337 ASSERT (Instance
!= NULL
);
1340 // Install the DNS protocol onto ChildHandle
1342 Status
= gBS
->InstallMultipleProtocolInterfaces (
1344 &gEfiDns6ProtocolGuid
,
1348 if (EFI_ERROR (Status
)) {
1352 Instance
->ChildHandle
= *ChildHandle
;
1355 // Open the Udp6 protocol BY_CHILD.
1357 Status
= gBS
->OpenProtocol (
1358 DnsSb
->ConnectUdp
->UdpHandle
,
1359 &gEfiUdp6ProtocolGuid
,
1361 gDns6DriverBinding
.DriverBindingHandle
,
1362 Instance
->ChildHandle
,
1363 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1365 if (EFI_ERROR (Status
)) {
1366 gBS
->UninstallMultipleProtocolInterfaces (
1367 Instance
->ChildHandle
,
1368 &gEfiDns6ProtocolGuid
,
1377 // Open the Udp6 protocol by child.
1379 Status
= gBS
->OpenProtocol (
1380 Instance
->UdpIo
->UdpHandle
,
1381 &gEfiUdp6ProtocolGuid
,
1383 gDns6DriverBinding
.DriverBindingHandle
,
1384 Instance
->ChildHandle
,
1385 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1387 if (EFI_ERROR (Status
)) {
1389 // Close the Udp6 protocol.
1391 gBS
->CloseProtocol (
1392 DnsSb
->ConnectUdp
->UdpHandle
,
1393 &gEfiUdp6ProtocolGuid
,
1394 gDns6DriverBinding
.DriverBindingHandle
,
1398 gBS
->UninstallMultipleProtocolInterfaces (
1399 Instance
->ChildHandle
,
1400 &gEfiDns6ProtocolGuid
,
1409 // Add it to the parent's child list.
1411 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1413 InsertTailList (&DnsSb
->Dns6ChildrenList
, &Instance
->Link
);
1414 DnsSb
->Dns6ChildrenNum
++;
1416 gBS
->RestoreTPL (OldTpl
);
1422 DnsDestroyInstance (Instance
);
1427 Destroys a child handle with a protocol installed on it.
1429 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
1430 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
1431 last protocol on ChildHandle, then ChildHandle is destroyed.
1433 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
1434 @param[in] ChildHandle Handle of the child to destroy
1436 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
1437 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
1438 @retval EFI_INVALID_PARAMETER Child handle is NULL.
1439 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
1440 because its services are being used.
1441 @retval other The child handle was not destroyed
1446 Dns6ServiceBindingDestroyChild (
1447 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
1448 IN EFI_HANDLE ChildHandle
1452 DNS_INSTANCE
*Instance
;
1454 EFI_DNS6_PROTOCOL
*Dns6
;
1458 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
1459 return EFI_INVALID_PARAMETER
;
1463 // Retrieve the private context data structures
1465 Status
= gBS
->OpenProtocol (
1467 &gEfiDns6ProtocolGuid
,
1469 gDns6DriverBinding
.DriverBindingHandle
,
1471 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1474 if (EFI_ERROR (Status
)) {
1475 return EFI_UNSUPPORTED
;
1478 Instance
= DNS_INSTANCE_FROM_THIS_PROTOCOL6 (Dns6
);
1479 DnsSb
= DNS_SERVICE_FROM_THIS (This
);
1481 if (Instance
->Service
!= DnsSb
) {
1482 return EFI_INVALID_PARAMETER
;
1485 if (Instance
->InDestroy
) {
1489 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1491 Instance
->InDestroy
= TRUE
;
1494 // Close the Udp6 protocol.
1496 gBS
->CloseProtocol (
1497 DnsSb
->ConnectUdp
->UdpHandle
,
1498 &gEfiUdp6ProtocolGuid
,
1499 gDns6DriverBinding
.DriverBindingHandle
,
1503 gBS
->CloseProtocol (
1504 Instance
->UdpIo
->UdpHandle
,
1505 &gEfiUdp6ProtocolGuid
,
1506 gDns6DriverBinding
.DriverBindingHandle
,
1510 gBS
->RestoreTPL (OldTpl
);
1513 // Uninstall the DNS protocol first to enable a top down destruction.
1515 Status
= gBS
->UninstallProtocolInterface (
1517 &gEfiDns6ProtocolGuid
,
1521 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1523 if (EFI_ERROR (Status
)) {
1524 Instance
->InDestroy
= FALSE
;
1525 gBS
->RestoreTPL (OldTpl
);
1529 RemoveEntryList (&Instance
->Link
);
1530 DnsSb
->Dns6ChildrenNum
--;
1532 gBS
->RestoreTPL (OldTpl
);
1534 DnsDestroyInstance (Instance
);