3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
10 EFI_DRIVER_BINDING_PROTOCOL gUdp4DriverBinding
= {
11 Udp4DriverBindingSupported
,
12 Udp4DriverBindingStart
,
13 Udp4DriverBindingStop
,
19 EFI_SERVICE_BINDING_PROTOCOL mUdp4ServiceBinding
= {
20 Udp4ServiceBindingCreateChild
,
21 Udp4ServiceBindingDestroyChild
25 Callback function which provided by user to remove one node in NetDestroyLinkList process.
27 @param[in] Entry The entry to be removed.
28 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
30 @retval EFI_SUCCESS The entry has been removed successfully.
31 @retval Others Fail to remove the entry.
36 Udp4DestroyChildEntryInHandleBuffer (
41 UDP4_INSTANCE_DATA
*Instance
;
42 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
43 UINTN NumberOfChildren
;
44 EFI_HANDLE
*ChildHandleBuffer
;
46 if ((Entry
== NULL
) || (Context
== NULL
)) {
47 return EFI_INVALID_PARAMETER
;
50 Instance
= NET_LIST_USER_STRUCT_S (Entry
, UDP4_INSTANCE_DATA
, Link
, UDP4_INSTANCE_DATA_SIGNATURE
);
51 ServiceBinding
= ((UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->ServiceBinding
;
52 NumberOfChildren
= ((UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->NumberOfChildren
;
53 ChildHandleBuffer
= ((UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
*)Context
)->ChildHandleBuffer
;
55 if (!NetIsInHandleBuffer (Instance
->ChildHandle
, NumberOfChildren
, ChildHandleBuffer
)) {
59 return ServiceBinding
->DestroyChild (ServiceBinding
, Instance
->ChildHandle
);
63 Test to see if this driver supports ControllerHandle. This service
64 is called by the EFI boot service ConnectController(). In
65 order to make drivers as small as possible, there are a few calling
66 restrictions for this service. ConnectController() must
67 follow these calling restrictions. If any other agent wishes to call
68 Supported() it must also follow these calling restrictions.
70 @param[in] This Protocol instance pointer.
71 @param[in] ControllerHandle Handle of device to test
72 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
75 @retval EFI_SUCCESS This driver supports this device
76 @retval EFI_ALREADY_STARTED This driver is already running on this device
77 @retval other This driver does not support this device
82 Udp4DriverBindingSupported (
83 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
84 IN EFI_HANDLE ControllerHandle
,
85 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
91 // Test for the Udp4ServiceBinding Protocol
93 Status
= gBS
->OpenProtocol (
95 &gEfiUdp4ServiceBindingProtocolGuid
,
97 This
->DriverBindingHandle
,
99 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
101 if (!EFI_ERROR (Status
)) {
102 return EFI_ALREADY_STARTED
;
106 // Test for the Ip4 Protocol
108 Status
= gBS
->OpenProtocol (
110 &gEfiIp4ServiceBindingProtocolGuid
,
112 This
->DriverBindingHandle
,
114 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
121 Start this driver on ControllerHandle. This service is called by the
122 EFI boot service ConnectController(). In order to make
123 drivers as small as possible, there are a few calling restrictions for
124 this service. ConnectController() must follow these
125 calling restrictions. If any other agent wishes to call Start() it
126 must also follow these calling restrictions.
128 @param[in] This Protocol instance pointer.
129 @param[in] ControllerHandle Handle of device to bind driver to
130 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
133 @retval EFI_SUCCESS This driver is added to ControllerHandle
134 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
135 @retval other This driver does not support this device
140 Udp4DriverBindingStart (
141 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
142 IN EFI_HANDLE ControllerHandle
,
143 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
147 UDP4_SERVICE_DATA
*Udp4Service
;
150 // Allocate Private Context Data Structure.
152 Udp4Service
= AllocatePool (sizeof (UDP4_SERVICE_DATA
));
153 if (Udp4Service
== NULL
) {
154 return EFI_OUT_OF_RESOURCES
;
157 Status
= Udp4CreateService (Udp4Service
, This
->DriverBindingHandle
, ControllerHandle
);
158 if (EFI_ERROR (Status
)) {
159 FreePool (Udp4Service
);
164 // Install the Udp4ServiceBindingProtocol on the ControllerHandle.
166 Status
= gBS
->InstallMultipleProtocolInterfaces (
168 &gEfiUdp4ServiceBindingProtocolGuid
,
169 &Udp4Service
->ServiceBinding
,
172 if (EFI_ERROR (Status
)) {
173 Udp4CleanService (Udp4Service
);
174 FreePool (Udp4Service
);
181 Stop this driver on ControllerHandle. This service is called by the
182 EFI boot service DisconnectController(). In order to
183 make drivers as small as possible, there are a few calling
184 restrictions for this service. DisconnectController()
185 must follow these calling restrictions. If any other agent wishes
186 to call Stop() it must also follow these calling restrictions.
188 @param[in] This Protocol instance pointer.
189 @param[in] ControllerHandle Handle of device to stop driver on
190 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
191 children is zero stop the entire bus driver.
192 @param[in] ChildHandleBuffer List of Child Handles to Stop.
194 @retval EFI_SUCCESS This driver is removed ControllerHandle
195 @retval other This driver was not removed from this device
200 Udp4DriverBindingStop (
201 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
202 IN EFI_HANDLE ControllerHandle
,
203 IN UINTN NumberOfChildren
,
204 IN EFI_HANDLE
*ChildHandleBuffer
208 EFI_HANDLE NicHandle
;
209 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
210 UDP4_SERVICE_DATA
*Udp4Service
;
211 UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context
;
215 // Find the NicHandle where UDP4 ServiceBinding Protocol is installed.
217 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiIp4ProtocolGuid
);
218 if (NicHandle
== NULL
) {
223 // Retrieve the UDP4 ServiceBinding Protocol.
225 Status
= gBS
->OpenProtocol (
227 &gEfiUdp4ServiceBindingProtocolGuid
,
228 (VOID
**)&ServiceBinding
,
229 This
->DriverBindingHandle
,
231 EFI_OPEN_PROTOCOL_GET_PROTOCOL
233 if (EFI_ERROR (Status
)) {
234 return EFI_DEVICE_ERROR
;
237 Udp4Service
= UDP4_SERVICE_DATA_FROM_THIS (ServiceBinding
);
238 if (NumberOfChildren
!= 0) {
240 // NumberOfChildren is not zero, destroy the children instances in ChildHandleBuffer.
242 List
= &Udp4Service
->ChildrenList
;
243 Context
.ServiceBinding
= ServiceBinding
;
244 Context
.NumberOfChildren
= NumberOfChildren
;
245 Context
.ChildHandleBuffer
= ChildHandleBuffer
;
246 Status
= NetDestroyLinkList (
248 Udp4DestroyChildEntryInHandleBuffer
,
253 gBS
->UninstallMultipleProtocolInterfaces (
255 &gEfiUdp4ServiceBindingProtocolGuid
,
256 &Udp4Service
->ServiceBinding
,
260 Udp4CleanService (Udp4Service
);
262 if (gUdpControllerNameTable
!= NULL
) {
263 FreeUnicodeStringTable (gUdpControllerNameTable
);
264 gUdpControllerNameTable
= NULL
;
267 FreePool (Udp4Service
);
274 Creates a child handle and installs a protocol.
276 The CreateChild() function installs a protocol on ChildHandle.
277 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
278 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
280 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
281 @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,
282 then a new handle is created. If it is a pointer to an existing UEFI handle,
283 then the protocol is added to the existing UEFI handle.
285 @retval EFI_SUCCESS The protocol was added to ChildHandle.
286 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
287 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
289 @retval other The child handle was not created
294 Udp4ServiceBindingCreateChild (
295 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
296 IN EFI_HANDLE
*ChildHandle
300 UDP4_SERVICE_DATA
*Udp4Service
;
301 UDP4_INSTANCE_DATA
*Instance
;
305 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
306 return EFI_INVALID_PARAMETER
;
309 Udp4Service
= UDP4_SERVICE_DATA_FROM_THIS (This
);
312 // Allocate the instance private data structure.
314 Instance
= AllocateZeroPool (sizeof (UDP4_INSTANCE_DATA
));
315 if (Instance
== NULL
) {
316 return EFI_OUT_OF_RESOURCES
;
319 Udp4InitInstance (Udp4Service
, Instance
);
322 // Add an IpInfo for this instance.
324 Instance
->IpInfo
= IpIoAddIp (Udp4Service
->IpIo
);
325 if (Instance
->IpInfo
== NULL
) {
326 Status
= EFI_OUT_OF_RESOURCES
;
331 // Install the Udp4Protocol for this instance.
333 Status
= gBS
->InstallMultipleProtocolInterfaces (
335 &gEfiUdp4ProtocolGuid
,
336 &Instance
->Udp4Proto
,
339 if (EFI_ERROR (Status
)) {
343 Instance
->ChildHandle
= *ChildHandle
;
346 // Open the default Ip4 protocol in the IP_IO BY_CHILD.
348 Status
= gBS
->OpenProtocol (
349 Udp4Service
->IpIo
->ChildHandle
,
350 &gEfiIp4ProtocolGuid
,
352 gUdp4DriverBinding
.DriverBindingHandle
,
353 Instance
->ChildHandle
,
354 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
356 if (EFI_ERROR (Status
)) {
361 // Open this instance's Ip4 protocol in the IpInfo BY_CHILD.
363 Status
= gBS
->OpenProtocol (
364 Instance
->IpInfo
->ChildHandle
,
365 &gEfiIp4ProtocolGuid
,
367 gUdp4DriverBinding
.DriverBindingHandle
,
368 Instance
->ChildHandle
,
369 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
371 if (EFI_ERROR (Status
)) {
375 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
378 // Link this instance into the service context data and increase the ChildrenNumber.
380 InsertTailList (&Udp4Service
->ChildrenList
, &Instance
->Link
);
381 Udp4Service
->ChildrenNumber
++;
383 gBS
->RestoreTPL (OldTpl
);
389 if (Instance
->ChildHandle
!= NULL
) {
390 gBS
->UninstallMultipleProtocolInterfaces (
391 Instance
->ChildHandle
,
392 &gEfiUdp4ProtocolGuid
,
393 &Instance
->Udp4Proto
,
398 if (Instance
->IpInfo
!= NULL
) {
399 IpIoRemoveIp (Udp4Service
->IpIo
, Instance
->IpInfo
);
402 Udp4CleanInstance (Instance
);
410 Destroys a child handle with a protocol installed on it.
412 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
413 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
414 last protocol on ChildHandle, then ChildHandle is destroyed.
416 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
417 @param[in] ChildHandle Handle of the child to destroy
419 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
420 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
421 @retval EFI_INVALID_PARAMETER Child handle is NULL.
422 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
423 because its services are being used.
424 @retval other The child handle was not destroyed
429 Udp4ServiceBindingDestroyChild (
430 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
431 IN EFI_HANDLE ChildHandle
435 UDP4_SERVICE_DATA
*Udp4Service
;
436 EFI_UDP4_PROTOCOL
*Udp4Proto
;
437 UDP4_INSTANCE_DATA
*Instance
;
440 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
441 return EFI_INVALID_PARAMETER
;
444 Udp4Service
= UDP4_SERVICE_DATA_FROM_THIS (This
);
447 // Try to get the Udp4 protocol from the ChildHandle.
449 Status
= gBS
->OpenProtocol (
451 &gEfiUdp4ProtocolGuid
,
453 gUdp4DriverBinding
.DriverBindingHandle
,
455 EFI_OPEN_PROTOCOL_GET_PROTOCOL
457 if (EFI_ERROR (Status
)) {
458 return EFI_UNSUPPORTED
;
461 Instance
= UDP4_INSTANCE_DATA_FROM_THIS (Udp4Proto
);
463 if (Instance
->InDestroy
) {
468 // Use the Destroyed flag to avoid the re-entering of the following code.
470 Instance
->InDestroy
= TRUE
;
473 // Close the Ip4 protocol.
476 Udp4Service
->IpIo
->ChildHandle
,
477 &gEfiIp4ProtocolGuid
,
478 gUdp4DriverBinding
.DriverBindingHandle
,
479 Instance
->ChildHandle
482 // Close the Ip4 protocol on this instance's IpInfo.
485 Instance
->IpInfo
->ChildHandle
,
486 &gEfiIp4ProtocolGuid
,
487 gUdp4DriverBinding
.DriverBindingHandle
,
488 Instance
->ChildHandle
492 // Uninstall the Udp4Protocol previously installed on the ChildHandle.
494 Status
= gBS
->UninstallMultipleProtocolInterfaces (
496 &gEfiUdp4ProtocolGuid
,
497 (VOID
*)&Instance
->Udp4Proto
,
500 if (EFI_ERROR (Status
)) {
501 Instance
->InDestroy
= FALSE
;
506 // Reset the configuration in case the instance's consumer forgets to do this.
508 Udp4Proto
->Configure (Udp4Proto
, NULL
);
511 // Remove the IpInfo this instance consumes.
513 IpIoRemoveIp (Udp4Service
->IpIo
, Instance
->IpInfo
);
515 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
518 // Remove this instance from the service context data's ChildrenList.
520 RemoveEntryList (&Instance
->Link
);
521 Udp4Service
->ChildrenNumber
--;
524 // Clean the instance.
526 Udp4CleanInstance (Instance
);
528 gBS
->RestoreTPL (OldTpl
);
536 This is the declaration of an EFI image entry point. This entry point is
537 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
538 both device drivers and bus drivers.
540 The entry point for Udp4 driver which installs the driver binding
541 and component name protocol on its ImageHandle.
543 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
544 @param[in] SystemTable A pointer to the EFI System Table.
546 @retval EFI_SUCCESS The operation completed successfully.
547 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
552 Udp4DriverEntryPoint (
553 IN EFI_HANDLE ImageHandle
,
554 IN EFI_SYSTEM_TABLE
*SystemTable
560 // Install the Udp4DriverBinding and Udp4ComponentName protocols.
562 Status
= EfiLibInstallDriverBindingComponentName2 (
570 if (!EFI_ERROR (Status
)) {
572 // Initialize the UDP random port.
574 mUdp4RandomPort
= (UINT16
)(((UINT16
)NetRandomInitSeed ()) % UDP4_PORT_KNOWN
+ UDP4_PORT_KNOWN
);