]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/DnsDxe/DnsDriver.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / DnsDxe / DnsDriver.c
CommitLineData
99c048ef 1/** @file\r
2The driver binding and service binding protocol for DnsDxe driver.\r
3\r
62a623de 4Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
ecf98fbc 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
99c048ef 6\r
7**/\r
8\r
9#include "DnsImpl.h"\r
10\r
d1050b9d 11EFI_DRIVER_BINDING_PROTOCOL gDns4DriverBinding = {\r
99c048ef 12 Dns4DriverBindingSupported,\r
13 Dns4DriverBindingStart,\r
14 Dns4DriverBindingStop,\r
15 DNS_VERSION,\r
16 NULL,\r
17 NULL\r
18};\r
19\r
d1050b9d 20EFI_DRIVER_BINDING_PROTOCOL gDns6DriverBinding = {\r
99c048ef 21 Dns6DriverBindingSupported,\r
22 Dns6DriverBindingStart,\r
23 Dns6DriverBindingStop,\r
24 DNS_VERSION,\r
25 NULL,\r
26 NULL\r
27};\r
28\r
d1050b9d 29EFI_SERVICE_BINDING_PROTOCOL mDns4ServiceBinding = {\r
99c048ef 30 Dns4ServiceBindingCreateChild,\r
31 Dns4ServiceBindingDestroyChild\r
32};\r
33\r
d1050b9d 34EFI_SERVICE_BINDING_PROTOCOL mDns6ServiceBinding = {\r
99c048ef 35 Dns6ServiceBindingCreateChild,\r
36 Dns6ServiceBindingDestroyChild\r
37};\r
38\r
d1050b9d 39DNS_DRIVER_DATA *mDriverData = NULL;\r
99c048ef 40\r
41/**\r
42 Destroy the DNS instance and recycle the resources.\r
43\r
44 @param[in] Instance The pointer to the DNS instance.\r
45\r
46**/\r
47VOID\r
48DnsDestroyInstance (\r
d1050b9d 49 IN DNS_INSTANCE *Instance\r
99c048ef 50 )\r
51{\r
52 ZeroMem (&Instance->Dns4CfgData, sizeof (EFI_DNS4_CONFIG_DATA));\r
f75a7f56 53\r
99c048ef 54 ZeroMem (&Instance->Dns6CfgData, sizeof (EFI_DNS6_CONFIG_DATA));\r
f75a7f56 55\r
99c048ef 56 if (!NetMapIsEmpty (&Instance->Dns4TxTokens)) {\r
57 Dns4InstanceCancelToken (Instance, NULL);\r
58 }\r
59\r
60 if (!NetMapIsEmpty (&Instance->Dns6TxTokens)) {\r
61 Dns6InstanceCancelToken (Instance, NULL);\r
62 }\r
f75a7f56 63\r
d1050b9d 64 if (Instance->UdpIo != NULL) {\r
99c048ef 65 UdpIoFreeIo (Instance->UdpIo);\r
66 }\r
f75a7f56 67\r
99c048ef 68 FreePool (Instance);\r
69}\r
70\r
71/**\r
72 Create the DNS instance and initialize it.\r
73\r
74 @param[in] Service The pointer to the DNS service.\r
75 @param[out] Instance The pointer to the DNS instance.\r
76\r
77 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
78 @retval EFI_SUCCESS The DNS instance is created.\r
79\r
80**/\r
81EFI_STATUS\r
82DnsCreateInstance (\r
d1050b9d
MK
83 IN DNS_SERVICE *Service,\r
84 OUT DNS_INSTANCE **Instance\r
99c048ef 85 )\r
86{\r
d1050b9d 87 DNS_INSTANCE *DnsIns;\r
99c048ef 88\r
89 *Instance = NULL;\r
f75a7f56 90\r
99c048ef 91 DnsIns = AllocateZeroPool (sizeof (DNS_INSTANCE));\r
92 if (DnsIns == NULL) {\r
93 return EFI_OUT_OF_RESOURCES;\r
94 }\r
95\r
96 DnsIns->Signature = DNS_INSTANCE_SIGNATURE;\r
97 InitializeListHead (&DnsIns->Link);\r
98 DnsIns->State = DNS_STATE_UNCONFIGED;\r
99 DnsIns->InDestroy = FALSE;\r
100 DnsIns->Service = Service;\r
f75a7f56 101\r
99c048ef 102 if (Service->IpVersion == IP_VERSION_4) {\r
103 CopyMem (&DnsIns->Dns4, &mDns4Protocol, sizeof (DnsIns->Dns4));\r
104 NetMapInit (&DnsIns->Dns4TxTokens);\r
105 } else {\r
106 CopyMem (&DnsIns->Dns6, &mDns6Protocol, sizeof (DnsIns->Dns6));\r
107 NetMapInit (&DnsIns->Dns6TxTokens);\r
108 }\r
109\r
110 DnsIns->UdpIo = UdpIoCreateIo (\r
111 Service->ControllerHandle, /// NicHandle\r
112 Service->ImageHandle,\r
113 DnsConfigNullUdp,\r
114 Service->IpVersion,\r
115 DnsIns\r
116 );\r
117 if (DnsIns->UdpIo == NULL) {\r
118 FreePool (DnsIns);\r
119 return EFI_OUT_OF_RESOURCES;\r
120 }\r
f75a7f56 121\r
99c048ef 122 *Instance = DnsIns;\r
123\r
124 return EFI_SUCCESS;\r
125}\r
126\r
127/**\r
128 Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
f75a7f56 129\r
99c048ef 130 @param[in] Entry The entry to be removed.\r
131 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
132\r
133 @retval EFI_SUCCESS The entry has been removed successfully.\r
134 @retval Others Fail to remove the entry.\r
135\r
136**/\r
137EFI_STATUS\r
138EFIAPI\r
139DnsDestroyChildEntryInHandleBuffer (\r
d1050b9d
MK
140 IN LIST_ENTRY *Entry,\r
141 IN VOID *Context\r
99c048ef 142 )\r
143{\r
144 DNS_INSTANCE *Instance;\r
145 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
146 UINTN NumberOfChildren;\r
147 EFI_HANDLE *ChildHandleBuffer;\r
148\r
d1050b9d 149 if ((Entry == NULL) || (Context == NULL)) {\r
99c048ef 150 return EFI_INVALID_PARAMETER;\r
151 }\r
152\r
d1050b9d
MK
153 Instance = NET_LIST_USER_STRUCT_S (Entry, DNS_INSTANCE, Link, DNS_INSTANCE_SIGNATURE);\r
154 ServiceBinding = ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ServiceBinding;\r
155 NumberOfChildren = ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->NumberOfChildren;\r
156 ChildHandleBuffer = ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ChildHandleBuffer;\r
99c048ef 157\r
158 if (!NetIsInHandleBuffer (Instance->ChildHandle, NumberOfChildren, ChildHandleBuffer)) {\r
159 return EFI_SUCCESS;\r
160 }\r
161\r
162 return ServiceBinding->DestroyChild (ServiceBinding, Instance->ChildHandle);\r
163}\r
164\r
165/**\r
166 Config a NULL UDP that is used to keep the connection between UDP and DNS.\r
167\r
168 Just leave the Udp child unconfigured. When UDP is unloaded,\r
169 DNS will be informed with DriverBinding Stop.\r
170\r
171 @param UdpIo The UDP_IO to configure\r
172 @param Context The opaque parameter to the callback\r
173\r
174 @retval EFI_SUCCESS It always return EFI_SUCCESS directly.\r
175\r
176**/\r
177EFI_STATUS\r
178EFIAPI\r
179DnsConfigNullUdp (\r
d1050b9d
MK
180 IN UDP_IO *UdpIo,\r
181 IN VOID *Context\r
99c048ef 182 )\r
183{\r
184 return EFI_SUCCESS;\r
185}\r
186\r
187/**\r
188 Release all the resource used the DNS service binding instance.\r
189\r
190 @param DnsSb The Dns service binding instance.\r
191\r
192**/\r
193VOID\r
194DnsDestroyService (\r
d1050b9d 195 IN DNS_SERVICE *DnsSb\r
99c048ef 196 )\r
197{\r
198 UdpIoFreeIo (DnsSb->ConnectUdp);\r
f75a7f56 199\r
4ad1bd63 200 if (DnsSb->TimerToGetMap != NULL) {\r
99c048ef 201 gBS->CloseEvent (DnsSb->TimerToGetMap);\r
202 }\r
203\r
4ad1bd63 204 if (DnsSb->Timer != NULL) {\r
99c048ef 205 gBS->CloseEvent (DnsSb->Timer);\r
206 }\r
207\r
208 FreePool (DnsSb);\r
209}\r
210\r
211/**\r
212 Create then initialize a Dns service binding instance.\r
213\r
214 @param Controller The controller to install the DNS service\r
215 binding on\r
216 @param Image The driver binding image of the DNS driver\r
217 @param IpVersion IpVersion for this service\r
218 @param Service The variable to receive the created service\r
219 binding instance.\r
220\r
221 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to create the instance.\r
222 @retval EFI_DEVICE_ERROR Failed to create a NULL UDP port to keep\r
223 connection with UDP.\r
224 @retval EFI_SUCCESS The service instance is created for the\r
225 controller.\r
226\r
227**/\r
228EFI_STATUS\r
229DnsCreateService (\r
d1050b9d
MK
230 IN EFI_HANDLE Controller,\r
231 IN EFI_HANDLE Image,\r
232 IN UINT8 IpVersion,\r
233 OUT DNS_SERVICE **Service\r
99c048ef 234 )\r
235{\r
d1050b9d
MK
236 EFI_STATUS Status;\r
237 DNS_SERVICE *DnsSb;\r
f75a7f56 238\r
d1050b9d
MK
239 Status = EFI_SUCCESS;\r
240 DnsSb = NULL;\r
99c048ef 241\r
d1050b9d 242 *Service = NULL;\r
99c048ef 243\r
244 DnsSb = AllocateZeroPool (sizeof (DNS_SERVICE));\r
245 if (DnsSb == NULL) {\r
246 return EFI_OUT_OF_RESOURCES;\r
247 }\r
248\r
249 DnsSb->Signature = DNS_SERVICE_SIGNATURE;\r
250\r
251 if (IpVersion == IP_VERSION_4) {\r
252 DnsSb->ServiceBinding = mDns4ServiceBinding;\r
253 } else {\r
254 DnsSb->ServiceBinding = mDns6ServiceBinding;\r
255 }\r
f75a7f56 256\r
99c048ef 257 DnsSb->Dns4ChildrenNum = 0;\r
258 InitializeListHead (&DnsSb->Dns4ChildrenList);\r
259\r
260 DnsSb->Dns6ChildrenNum = 0;\r
261 InitializeListHead (&DnsSb->Dns6ChildrenList);\r
262\r
263 DnsSb->ControllerHandle = Controller;\r
264 DnsSb->ImageHandle = Image;\r
265\r
d1050b9d 266 DnsSb->TimerToGetMap = NULL;\r
f75a7f56 267\r
d1050b9d 268 DnsSb->Timer = NULL;\r
f75a7f56 269\r
d1050b9d 270 DnsSb->IpVersion = IpVersion;\r
99c048ef 271\r
272 //\r
273 // Create the timer used to time out the procedure which is used to\r
274 // get the default IP address.\r
275 //\r
eed4585b
JW
276 Status = gBS->CreateEvent (\r
277 EVT_TIMER,\r
278 TPL_CALLBACK,\r
279 NULL,\r
280 NULL,\r
281 &DnsSb->TimerToGetMap\r
282 );\r
283 if (EFI_ERROR (Status)) {\r
284 FreePool (DnsSb);\r
285 return Status;\r
99c048ef 286 }\r
f75a7f56 287\r
99c048ef 288 //\r
289 // Create the timer to retransmit packets.\r
290 //\r
291 Status = gBS->CreateEvent (\r
292 EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
293 TPL_CALLBACK,\r
294 DnsOnTimerRetransmit,\r
295 DnsSb,\r
296 &DnsSb->Timer\r
297 );\r
298 if (EFI_ERROR (Status)) {\r
299 if (DnsSb->TimerToGetMap != NULL) {\r
300 gBS->CloseEvent (DnsSb->TimerToGetMap);\r
301 }\r
d1050b9d 302\r
99c048ef 303 FreePool (DnsSb);\r
304 return Status;\r
305 }\r
f75a7f56 306\r
99c048ef 307 DnsSb->ConnectUdp = NULL;\r
308 DnsSb->ConnectUdp = UdpIoCreateIo (\r
309 Controller,\r
310 Image,\r
311 DnsConfigNullUdp,\r
312 DnsSb->IpVersion,\r
313 NULL\r
314 );\r
315 if (DnsSb->ConnectUdp == NULL) {\r
316 if (DnsSb->TimerToGetMap != NULL) {\r
317 gBS->CloseEvent (DnsSb->TimerToGetMap);\r
318 }\r
d1050b9d 319\r
99c048ef 320 gBS->CloseEvent (DnsSb->Timer);\r
321 FreePool (DnsSb);\r
322 return EFI_DEVICE_ERROR;\r
323 }\r
324\r
325 *Service = DnsSb;\r
326 return Status;\r
327}\r
328\r
329/**\r
330 Unloads an image.\r
331\r
332 @param ImageHandle Handle that identifies the image to be unloaded.\r
333\r
334 @retval EFI_SUCCESS The image has been unloaded.\r
335 @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.\r
336\r
337**/\r
f75a7f56 338EFI_STATUS\r
99c048ef 339EFIAPI\r
340DnsUnload (\r
341 IN EFI_HANDLE ImageHandle\r
342 )\r
343{\r
344 EFI_STATUS Status;\r
345\r
d1050b9d
MK
346 LIST_ENTRY *Entry;\r
347 DNS4_CACHE *ItemCache4;\r
348 DNS4_SERVER_IP *ItemServerIp4;\r
349 DNS6_CACHE *ItemCache6;\r
350 DNS6_SERVER_IP *ItemServerIp6;\r
99c048ef 351\r
352 ItemCache4 = NULL;\r
353 ItemServerIp4 = NULL;\r
354 ItemCache6 = NULL;\r
355 ItemServerIp6 = NULL;\r
f75a7f56 356\r
99c048ef 357 //\r
358 // Disconnect the driver specified by ImageHandle\r
359 //\r
d1050b9d 360 Status = NetLibDefaultUnload (ImageHandle);\r
99c048ef 361 if (EFI_ERROR (Status)) {\r
362 return Status;\r
363 }\r
364\r
365 //\r
366 // Free mDriverData.\r
367 //\r
368 if (mDriverData != NULL) {\r
369 if (mDriverData->Timer != NULL) {\r
370 gBS->CloseEvent (mDriverData->Timer);\r
371 }\r
f75a7f56 372\r
99c048ef 373 while (!IsListEmpty (&mDriverData->Dns4CacheList)) {\r
374 Entry = NetListRemoveHead (&mDriverData->Dns4CacheList);\r
62a623de 375 ASSERT (Entry != NULL);\r
99c048ef 376 ItemCache4 = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);\r
62a623de
JW
377 FreePool (ItemCache4->DnsCache.HostName);\r
378 FreePool (ItemCache4->DnsCache.IpAddress);\r
99c048ef 379 FreePool (ItemCache4);\r
380 }\r
381\r
382 while (!IsListEmpty (&mDriverData->Dns4ServerList)) {\r
383 Entry = NetListRemoveHead (&mDriverData->Dns4ServerList);\r
62a623de 384 ASSERT (Entry != NULL);\r
99c048ef 385 ItemServerIp4 = NET_LIST_USER_STRUCT (Entry, DNS4_SERVER_IP, AllServerLink);\r
386 FreePool (ItemServerIp4);\r
387 }\r
388\r
389 while (!IsListEmpty (&mDriverData->Dns6CacheList)) {\r
390 Entry = NetListRemoveHead (&mDriverData->Dns6CacheList);\r
62a623de 391 ASSERT (Entry != NULL);\r
99c048ef 392 ItemCache6 = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);\r
62a623de
JW
393 FreePool (ItemCache6->DnsCache.HostName);\r
394 FreePool (ItemCache6->DnsCache.IpAddress);\r
99c048ef 395 FreePool (ItemCache6);\r
396 }\r
397\r
398 while (!IsListEmpty (&mDriverData->Dns6ServerList)) {\r
399 Entry = NetListRemoveHead (&mDriverData->Dns6ServerList);\r
62a623de 400 ASSERT (Entry != NULL);\r
99c048ef 401 ItemServerIp6 = NET_LIST_USER_STRUCT (Entry, DNS6_SERVER_IP, AllServerLink);\r
402 FreePool (ItemServerIp6);\r
403 }\r
f75a7f56 404\r
99c048ef 405 FreePool (mDriverData);\r
406 }\r
f75a7f56 407\r
99c048ef 408 return Status;\r
409}\r
410\r
411/**\r
412 This is the declaration of an EFI image entry point. This entry point is\r
413 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
414 both device drivers and bus drivers.\r
415\r
416 @param ImageHandle The firmware allocated handle for the UEFI image.\r
417 @param SystemTable A pointer to the EFI System Table.\r
418\r
419 @retval EFI_SUCCESS The operation completed successfully.\r
420 @retval Others An unexpected error occurred.\r
421**/\r
422EFI_STATUS\r
423EFIAPI\r
424DnsDriverEntryPoint (\r
425 IN EFI_HANDLE ImageHandle,\r
426 IN EFI_SYSTEM_TABLE *SystemTable\r
427 )\r
428{\r
429 EFI_STATUS Status;\r
430\r
431 Status = EFI_SUCCESS;\r
432\r
433 //\r
434 // Install the Dns4 Driver Binding Protocol.\r
435 //\r
436 Status = EfiLibInstallDriverBindingComponentName2 (\r
437 ImageHandle,\r
438 SystemTable,\r
439 &gDns4DriverBinding,\r
440 ImageHandle,\r
441 &gDnsComponentName,\r
442 &gDnsComponentName2\r
443 );\r
444 if (EFI_ERROR (Status)) {\r
445 return Status;\r
446 }\r
447\r
448 //\r
449 // Install the Dns6 Driver Binding Protocol.\r
450 //\r
451 Status = EfiLibInstallDriverBindingComponentName2 (\r
452 ImageHandle,\r
453 SystemTable,\r
454 &gDns6DriverBinding,\r
455 NULL,\r
456 &gDnsComponentName,\r
457 &gDnsComponentName2\r
458 );\r
459 if (EFI_ERROR (Status)) {\r
460 goto Error1;\r
461 }\r
462\r
463 //\r
464 // Create the driver data structures.\r
465 //\r
466 mDriverData = AllocateZeroPool (sizeof (DNS_DRIVER_DATA));\r
467 if (mDriverData == NULL) {\r
468 Status = EFI_OUT_OF_RESOURCES;\r
469 goto Error2;\r
470 }\r
471\r
472 //\r
473 // Create the timer event to update DNS cache list.\r
474 //\r
475 Status = gBS->CreateEvent (\r
476 EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
477 TPL_CALLBACK,\r
478 DnsOnTimerUpdate,\r
479 NULL,\r
480 &mDriverData->Timer\r
481 );\r
482 if (EFI_ERROR (Status)) {\r
483 goto Error3;\r
484 }\r
f75a7f56 485\r
99c048ef 486 Status = gBS->SetTimer (mDriverData->Timer, TimerPeriodic, TICKS_PER_SECOND);\r
487 if (EFI_ERROR (Status)) {\r
488 goto Error4;\r
489 }\r
490\r
491 InitializeListHead (&mDriverData->Dns4CacheList);\r
492 InitializeListHead (&mDriverData->Dns4ServerList);\r
493 InitializeListHead (&mDriverData->Dns6CacheList);\r
494 InitializeListHead (&mDriverData->Dns6ServerList);\r
f75a7f56 495\r
99c048ef 496 return Status;\r
497\r
d1050b9d
MK
498Error4:\r
499 gBS->CloseEvent (mDriverData->Timer);\r
99c048ef 500\r
d1050b9d
MK
501Error3:\r
502 FreePool (mDriverData);\r
f75a7f56 503\r
d1050b9d
MK
504Error2:\r
505 EfiLibUninstallDriverBindingComponentName2 (\r
506 &gDns6DriverBinding,\r
507 &gDnsComponentName,\r
508 &gDnsComponentName2\r
509 );\r
99c048ef 510\r
d1050b9d
MK
511Error1:\r
512 EfiLibUninstallDriverBindingComponentName2 (\r
513 &gDns4DriverBinding,\r
514 &gDnsComponentName,\r
515 &gDnsComponentName2\r
516 );\r
f75a7f56 517\r
99c048ef 518 return Status;\r
519}\r
520\r
521/**\r
f75a7f56 522 Tests to see if this driver supports a given controller. If a child device is provided,\r
99c048ef 523 it further tests to see if this driver supports creating a handle for the specified child device.\r
524\r
f75a7f56
LG
525 This function checks to see if the driver specified by This supports the device specified by\r
526 ControllerHandle. Drivers will typically use the device path attached to\r
527 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
528 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
529 may be called many times during platform initialization. In order to reduce boot times, the tests\r
530 performed by this function must be very small, and take as little time as possible to execute. This\r
531 function must not change the state of any hardware devices, and this function must be aware that the\r
532 device specified by ControllerHandle may already be managed by the same driver or a\r
533 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
534 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
535 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
536 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
99c048ef 537 to guarantee the state of ControllerHandle is not modified by this function.\r
538\r
539 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
540 @param[in] ControllerHandle The handle of the controller to test. This handle\r
541 must support a protocol interface that supplies\r
99c048ef 542 an I/O abstraction to the driver.\r
f75a7f56
LG
543 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
544 parameter is ignored by device drivers, and is optional for bus\r
545 drivers. For bus drivers, if this parameter is not NULL, then\r
546 the bus driver must determine if the bus controller specified\r
547 by ControllerHandle and the child controller specified\r
548 by RemainingDevicePath are both supported by this\r
99c048ef 549 bus driver.\r
550\r
551 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
552 RemainingDevicePath is supported by the driver specified by This.\r
553 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
554 RemainingDevicePath is already being managed by the driver\r
555 specified by This.\r
556 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
557 RemainingDevicePath is already being managed by a different\r
558 driver or an application that requires exclusive access.\r
559 Currently not implemented.\r
560 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
561 RemainingDevicePath is not supported by the driver specified by This.\r
562**/\r
563EFI_STATUS\r
564EFIAPI\r
565Dns4DriverBindingSupported (\r
566 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
567 IN EFI_HANDLE ControllerHandle,\r
568 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
569 )\r
570{\r
571 EFI_STATUS Status;\r
572\r
573 //\r
574 // Test for the Dns4ServiceBinding Protocol.\r
575 //\r
576 Status = gBS->OpenProtocol (\r
577 ControllerHandle,\r
578 &gEfiDns4ServiceBindingProtocolGuid,\r
579 NULL,\r
580 This->DriverBindingHandle,\r
581 ControllerHandle,\r
582 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
583 );\r
584 if (!EFI_ERROR (Status)) {\r
585 return EFI_ALREADY_STARTED;\r
586 }\r
587\r
588 //\r
589 // Test for the Udp4ServiceBinding Protocol.\r
590 //\r
591 Status = gBS->OpenProtocol (\r
592 ControllerHandle,\r
593 &gEfiUdp4ServiceBindingProtocolGuid,\r
594 NULL,\r
595 This->DriverBindingHandle,\r
596 ControllerHandle,\r
597 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
598 );\r
599\r
600 return Status;\r
601}\r
602\r
603/**\r
604 Starts a device controller or a bus controller.\r
605\r
606 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
f75a7f56
LG
607 As a result, much of the error checking on the parameters to Start() has been moved into this\r
608 common boot service. It is legal to call Start() from other locations,\r
99c048ef 609 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
610 1. ControllerHandle must be a valid EFI_HANDLE.\r
611 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
612 EFI_DEVICE_PATH_PROTOCOL.\r
613 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
f75a7f56 614 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
99c048ef 615\r
616 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
617 @param[in] ControllerHandle The handle of the controller to start. This handle\r
618 must support a protocol interface that supplies\r
99c048ef 619 an I/O abstraction to the driver.\r
f75a7f56
LG
620 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
621 parameter is ignored by device drivers, and is optional for bus\r
622 drivers. For a bus driver, if this parameter is NULL, then handles\r
623 for all the children of Controller are created by this driver.\r
624 If this parameter is not NULL and the first Device Path Node is\r
625 not the End of Device Path Node, then only the handle for the\r
626 child device specified by the first Device Path Node of\r
99c048ef 627 RemainingDevicePath is created by this driver.\r
f75a7f56 628 If the first Device Path Node of RemainingDevicePath is\r
99c048ef 629 the End of Device Path Node, no child handle is created by this\r
630 driver.\r
631\r
632 @retval EFI_SUCCESS The device was started.\r
633 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
634 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
81a46615 635 @retval Others The driver failed to start the device.\r
99c048ef 636\r
637**/\r
638EFI_STATUS\r
639EFIAPI\r
640Dns4DriverBindingStart (\r
641 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
642 IN EFI_HANDLE ControllerHandle,\r
643 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
644 )\r
645{\r
d1050b9d
MK
646 DNS_SERVICE *DnsSb;\r
647 EFI_STATUS Status;\r
99c048ef 648\r
649 Status = DnsCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_4, &DnsSb);\r
650 if (EFI_ERROR (Status)) {\r
651 return Status;\r
652 }\r
f75a7f56 653\r
99c048ef 654 ASSERT (DnsSb != NULL);\r
f75a7f56 655\r
99c048ef 656 Status = gBS->SetTimer (DnsSb->Timer, TimerPeriodic, TICKS_PER_SECOND);\r
657 if (EFI_ERROR (Status)) {\r
658 goto ON_ERROR;\r
659 }\r
f75a7f56 660\r
99c048ef 661 //\r
662 // Install the Dns4ServiceBinding Protocol onto ControllerHandle.\r
663 //\r
664 Status = gBS->InstallMultipleProtocolInterfaces (\r
665 &ControllerHandle,\r
666 &gEfiDns4ServiceBindingProtocolGuid,\r
667 &DnsSb->ServiceBinding,\r
668 NULL\r
669 );\r
670 if (EFI_ERROR (Status)) {\r
671 goto ON_ERROR;\r
672 }\r
673\r
674 return EFI_SUCCESS;\r
675\r
676ON_ERROR:\r
677 DnsDestroyService (DnsSb);\r
678\r
679 return Status;\r
680}\r
681\r
682/**\r
683 Stops a device controller or a bus controller.\r
f75a7f56
LG
684\r
685 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
686 As a result, much of the error checking on the parameters to Stop() has been moved\r
687 into this common boot service. It is legal to call Stop() from other locations,\r
99c048ef 688 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
689 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
690 same driver's Start() function.\r
691 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
692 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
693 Start() function, and the Start() function must have called OpenProtocol() on\r
694 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
f75a7f56 695\r
99c048ef 696 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
697 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
698 support a bus specific I/O protocol for the driver\r
99c048ef 699 to use to stop the device.\r
700 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
f75a7f56 701 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
99c048ef 702 if NumberOfChildren is 0.\r
703\r
704 @retval EFI_SUCCESS The device was stopped.\r
705 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
706\r
707**/\r
708EFI_STATUS\r
709EFIAPI\r
710Dns4DriverBindingStop (\r
711 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
712 IN EFI_HANDLE ControllerHandle,\r
713 IN UINTN NumberOfChildren,\r
714 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
715 )\r
716{\r
d1050b9d
MK
717 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
718 DNS_SERVICE *DnsSb;\r
719 EFI_HANDLE NicHandle;\r
720 EFI_STATUS Status;\r
721 LIST_ENTRY *List;\r
722 DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r
99c048ef 723\r
724 //\r
725 // DNS driver opens UDP child, So, Controller is a UDP\r
726 // child handle. Locate the Nic handle first. Then get the\r
727 // DNS private data back.\r
728 //\r
729 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);\r
730\r
731 if (NicHandle == NULL) {\r
732 return EFI_SUCCESS;\r
733 }\r
734\r
735 Status = gBS->OpenProtocol (\r
736 NicHandle,\r
737 &gEfiDns4ServiceBindingProtocolGuid,\r
d1050b9d 738 (VOID **)&ServiceBinding,\r
99c048ef 739 This->DriverBindingHandle,\r
740 NicHandle,\r
741 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
742 );\r
743 if (EFI_ERROR (Status)) {\r
744 return EFI_DEVICE_ERROR;\r
745 }\r
746\r
747 DnsSb = DNS_SERVICE_FROM_THIS (ServiceBinding);\r
748\r
749 if (!IsListEmpty (&DnsSb->Dns4ChildrenList)) {\r
750 //\r
751 // Destroy the Dns child instance in ChildHandleBuffer.\r
752 //\r
d1050b9d 753 List = &DnsSb->Dns4ChildrenList;\r
99c048ef 754 Context.ServiceBinding = ServiceBinding;\r
755 Context.NumberOfChildren = NumberOfChildren;\r
756 Context.ChildHandleBuffer = ChildHandleBuffer;\r
d1050b9d
MK
757 Status = NetDestroyLinkList (\r
758 List,\r
759 DnsDestroyChildEntryInHandleBuffer,\r
760 &Context,\r
761 NULL\r
762 );\r
99c048ef 763 }\r
764\r
d1050b9d 765 if ((NumberOfChildren == 0) && IsListEmpty (&DnsSb->Dns4ChildrenList)) {\r
99c048ef 766 gBS->UninstallProtocolInterface (\r
767 NicHandle,\r
768 &gEfiDns4ServiceBindingProtocolGuid,\r
769 ServiceBinding\r
770 );\r
771\r
772 DnsDestroyService (DnsSb);\r
f75a7f56 773\r
99c048ef 774 if (gDnsControllerNameTable != NULL) {\r
775 FreeUnicodeStringTable (gDnsControllerNameTable);\r
776 gDnsControllerNameTable = NULL;\r
777 }\r
778\r
779 Status = EFI_SUCCESS;\r
780 }\r
781\r
782 return Status;\r
783}\r
784\r
785/**\r
f75a7f56 786 Tests to see if this driver supports a given controller. If a child device is provided,\r
99c048ef 787 it further tests to see if this driver supports creating a handle for the specified child device.\r
788\r
f75a7f56
LG
789 This function checks to see if the driver specified by This supports the device specified by\r
790 ControllerHandle. Drivers will typically use the device path attached to\r
791 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
792 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
793 may be called many times during platform initialization. In order to reduce boot times, the tests\r
794 performed by this function must be very small, and take as little time as possible to execute. This\r
795 function must not change the state of any hardware devices, and this function must be aware that the\r
796 device specified by ControllerHandle may already be managed by the same driver or a\r
797 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
798 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
799 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
800 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
99c048ef 801 to guarantee the state of ControllerHandle is not modified by this function.\r
802\r
803 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
804 @param[in] ControllerHandle The handle of the controller to test. This handle\r
805 must support a protocol interface that supplies\r
99c048ef 806 an I/O abstraction to the driver.\r
f75a7f56
LG
807 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
808 parameter is ignored by device drivers, and is optional for bus\r
809 drivers. For bus drivers, if this parameter is not NULL, then\r
810 the bus driver must determine if the bus controller specified\r
811 by ControllerHandle and the child controller specified\r
812 by RemainingDevicePath are both supported by this\r
99c048ef 813 bus driver.\r
814\r
815 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
816 RemainingDevicePath is supported by the driver specified by This.\r
817 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
818 RemainingDevicePath is already being managed by the driver\r
819 specified by This.\r
820 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
821 RemainingDevicePath is already being managed by a different\r
822 driver or an application that requires exclusive access.\r
823 Currently not implemented.\r
824 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
825 RemainingDevicePath is not supported by the driver specified by This.\r
826**/\r
827EFI_STATUS\r
828EFIAPI\r
829Dns6DriverBindingSupported (\r
830 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
831 IN EFI_HANDLE ControllerHandle,\r
832 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
833 )\r
834{\r
835 EFI_STATUS Status;\r
836\r
837 //\r
838 // Test for the Dns6ServiceBinding Protocol\r
839 //\r
840 Status = gBS->OpenProtocol (\r
841 ControllerHandle,\r
842 &gEfiDns6ServiceBindingProtocolGuid,\r
843 NULL,\r
844 This->DriverBindingHandle,\r
845 ControllerHandle,\r
846 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
847 );\r
848 if (!EFI_ERROR (Status)) {\r
849 return EFI_ALREADY_STARTED;\r
850 }\r
851\r
852 //\r
853 // Test for the Udp6ServiceBinding Protocol\r
854 //\r
855 Status = gBS->OpenProtocol (\r
856 ControllerHandle,\r
857 &gEfiUdp6ServiceBindingProtocolGuid,\r
858 NULL,\r
859 This->DriverBindingHandle,\r
860 ControllerHandle,\r
861 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
862 );\r
863\r
864 return Status;\r
865}\r
866\r
867/**\r
868 Starts a device controller or a bus controller.\r
869\r
870 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
f75a7f56
LG
871 As a result, much of the error checking on the parameters to Start() has been moved into this\r
872 common boot service. It is legal to call Start() from other locations,\r
99c048ef 873 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
874 1. ControllerHandle must be a valid EFI_HANDLE.\r
875 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
876 EFI_DEVICE_PATH_PROTOCOL.\r
877 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
f75a7f56 878 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
99c048ef 879\r
880 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
881 @param[in] ControllerHandle The handle of the controller to start. This handle\r
882 must support a protocol interface that supplies\r
99c048ef 883 an I/O abstraction to the driver.\r
f75a7f56
LG
884 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
885 parameter is ignored by device drivers, and is optional for bus\r
886 drivers. For a bus driver, if this parameter is NULL, then handles\r
887 for all the children of Controller are created by this driver.\r
888 If this parameter is not NULL and the first Device Path Node is\r
889 not the End of Device Path Node, then only the handle for the\r
890 child device specified by the first Device Path Node of\r
99c048ef 891 RemainingDevicePath is created by this driver.\r
f75a7f56 892 If the first Device Path Node of RemainingDevicePath is\r
99c048ef 893 the End of Device Path Node, no child handle is created by this\r
894 driver.\r
895\r
896 @retval EFI_SUCCESS The device was started.\r
897 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
898 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
81a46615 899 @retval Others The driver failed to start the device.\r
99c048ef 900\r
901**/\r
902EFI_STATUS\r
903EFIAPI\r
904Dns6DriverBindingStart (\r
905 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
906 IN EFI_HANDLE ControllerHandle,\r
907 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
908 )\r
909{\r
d1050b9d
MK
910 DNS_SERVICE *DnsSb;\r
911 EFI_STATUS Status;\r
99c048ef 912\r
913 Status = DnsCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_6, &DnsSb);\r
914 if (EFI_ERROR (Status)) {\r
915 return Status;\r
916 }\r
f75a7f56 917\r
99c048ef 918 ASSERT (DnsSb != NULL);\r
f75a7f56 919\r
99c048ef 920 Status = gBS->SetTimer (DnsSb->Timer, TimerPeriodic, TICKS_PER_SECOND);\r
921 if (EFI_ERROR (Status)) {\r
922 goto ON_ERROR;\r
923 }\r
f75a7f56 924\r
99c048ef 925 //\r
926 // Install the Dns6ServiceBinding Protocol onto ControllerHandle\r
927 //\r
928 Status = gBS->InstallMultipleProtocolInterfaces (\r
929 &ControllerHandle,\r
930 &gEfiDns6ServiceBindingProtocolGuid,\r
931 &DnsSb->ServiceBinding,\r
932 NULL\r
933 );\r
934\r
935 if (EFI_ERROR (Status)) {\r
936 goto ON_ERROR;\r
937 }\r
938\r
939 return EFI_SUCCESS;\r
940\r
941ON_ERROR:\r
942 DnsDestroyService (DnsSb);\r
943\r
944 return Status;\r
945}\r
946\r
947/**\r
948 Stops a device controller or a bus controller.\r
f75a7f56
LG
949\r
950 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
951 As a result, much of the error checking on the parameters to Stop() has been moved\r
952 into this common boot service. It is legal to call Stop() from other locations,\r
99c048ef 953 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
954 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
955 same driver's Start() function.\r
956 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
957 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
958 Start() function, and the Start() function must have called OpenProtocol() on\r
959 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
f75a7f56 960\r
99c048ef 961 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
f75a7f56
LG
962 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
963 support a bus specific I/O protocol for the driver\r
99c048ef 964 to use to stop the device.\r
965 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
f75a7f56 966 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
99c048ef 967 if NumberOfChildren is 0.\r
968\r
969 @retval EFI_SUCCESS The device was stopped.\r
970 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
971\r
972**/\r
973EFI_STATUS\r
974EFIAPI\r
975Dns6DriverBindingStop (\r
976 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
977 IN EFI_HANDLE ControllerHandle,\r
978 IN UINTN NumberOfChildren,\r
979 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
980 )\r
981{\r
d1050b9d
MK
982 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
983 DNS_SERVICE *DnsSb;\r
984 EFI_HANDLE NicHandle;\r
985 EFI_STATUS Status;\r
986 LIST_ENTRY *List;\r
987 DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r
99c048ef 988\r
989 //\r
990 // DNS driver opens UDP child, So, Controller is a UDP\r
991 // child handle. Locate the Nic handle first. Then get the\r
992 // DNS private data back.\r
993 //\r
994 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp6ProtocolGuid);\r
995\r
996 if (NicHandle == NULL) {\r
997 return EFI_SUCCESS;\r
998 }\r
999\r
1000 Status = gBS->OpenProtocol (\r
1001 NicHandle,\r
1002 &gEfiDns6ServiceBindingProtocolGuid,\r
d1050b9d 1003 (VOID **)&ServiceBinding,\r
99c048ef 1004 This->DriverBindingHandle,\r
1005 NicHandle,\r
1006 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1007 );\r
1008 if (EFI_ERROR (Status)) {\r
1009 return EFI_DEVICE_ERROR;\r
1010 }\r
1011\r
1012 DnsSb = DNS_SERVICE_FROM_THIS (ServiceBinding);\r
1013\r
1014 if (!IsListEmpty (&DnsSb->Dns6ChildrenList)) {\r
1015 //\r
1016 // Destroy the Dns child instance in ChildHandleBuffer.\r
1017 //\r
d1050b9d 1018 List = &DnsSb->Dns6ChildrenList;\r
99c048ef 1019 Context.ServiceBinding = ServiceBinding;\r
1020 Context.NumberOfChildren = NumberOfChildren;\r
1021 Context.ChildHandleBuffer = ChildHandleBuffer;\r
d1050b9d
MK
1022 Status = NetDestroyLinkList (\r
1023 List,\r
1024 DnsDestroyChildEntryInHandleBuffer,\r
1025 &Context,\r
1026 NULL\r
1027 );\r
99c048ef 1028 }\r
1029\r
d1050b9d 1030 if ((NumberOfChildren == 0) && IsListEmpty (&DnsSb->Dns6ChildrenList)) {\r
99c048ef 1031 gBS->UninstallProtocolInterface (\r
1032 NicHandle,\r
1033 &gEfiDns6ServiceBindingProtocolGuid,\r
1034 ServiceBinding\r
1035 );\r
1036\r
1037 DnsDestroyService (DnsSb);\r
f75a7f56 1038\r
99c048ef 1039 if (gDnsControllerNameTable != NULL) {\r
1040 FreeUnicodeStringTable (gDnsControllerNameTable);\r
1041 gDnsControllerNameTable = NULL;\r
1042 }\r
f75a7f56 1043\r
99c048ef 1044 Status = EFI_SUCCESS;\r
1045 }\r
1046\r
1047 return Status;\r
1048}\r
1049\r
1050/**\r
1051 Creates a child handle and installs a protocol.\r
f75a7f56
LG
1052\r
1053 The CreateChild() function installs a protocol on ChildHandle.\r
1054 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r
99c048ef 1055 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r
1056\r
1057 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
1058 @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,\r
f75a7f56 1059 then a new handle is created. If it is a pointer to an existing UEFI handle,\r
99c048ef 1060 then the protocol is added to the existing UEFI handle.\r
1061\r
81a46615 1062 @retval EFI_SUCCESS The protocol was added to ChildHandle.\r
99c048ef 1063 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
c2adf51f 1064 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r
99c048ef 1065 the child\r
1066 @retval other The child handle was not created\r
1067\r
1068**/\r
1069EFI_STATUS\r
1070EFIAPI\r
1071Dns4ServiceBindingCreateChild (\r
1072 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
1073 IN EFI_HANDLE *ChildHandle\r
1074 )\r
1075{\r
d1050b9d
MK
1076 DNS_SERVICE *DnsSb;\r
1077 DNS_INSTANCE *Instance;\r
1078 EFI_STATUS Status;\r
1079 EFI_TPL OldTpl;\r
1080 VOID *Udp4;\r
99c048ef 1081\r
1082 if ((This == NULL) || (ChildHandle == NULL)) {\r
1083 return EFI_INVALID_PARAMETER;\r
1084 }\r
1085\r
1086 DnsSb = DNS_SERVICE_FROM_THIS (This);\r
1087\r
1088 Status = DnsCreateInstance (DnsSb, &Instance);\r
1089 if (EFI_ERROR (Status)) {\r
1090 return Status;\r
1091 }\r
d1050b9d 1092\r
99c048ef 1093 ASSERT (Instance != NULL);\r
1094\r
1095 //\r
1096 // Install the DNS protocol onto ChildHandle\r
1097 //\r
1098 Status = gBS->InstallMultipleProtocolInterfaces (\r
1099 ChildHandle,\r
1100 &gEfiDns4ProtocolGuid,\r
1101 &Instance->Dns4,\r
1102 NULL\r
1103 );\r
1104 if (EFI_ERROR (Status)) {\r
1105 goto ON_ERROR;\r
1106 }\r
1107\r
1108 Instance->ChildHandle = *ChildHandle;\r
1109\r
1110 //\r
1111 // Open the Udp4 protocol BY_CHILD.\r
1112 //\r
1113 Status = gBS->OpenProtocol (\r
1114 DnsSb->ConnectUdp->UdpHandle,\r
1115 &gEfiUdp4ProtocolGuid,\r
d1050b9d 1116 (VOID **)&Udp4,\r
99c048ef 1117 gDns4DriverBinding.DriverBindingHandle,\r
1118 Instance->ChildHandle,\r
1119 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
1120 );\r
1121 if (EFI_ERROR (Status)) {\r
1122 gBS->UninstallMultipleProtocolInterfaces (\r
1123 Instance->ChildHandle,\r
1124 &gEfiDns4ProtocolGuid,\r
1125 &Instance->Dns4,\r
1126 NULL\r
1127 );\r
f75a7f56 1128\r
99c048ef 1129 goto ON_ERROR;\r
1130 }\r
1131\r
1132 //\r
1133 // Open the Udp4 protocol by child.\r
1134 //\r
1135 Status = gBS->OpenProtocol (\r
1136 Instance->UdpIo->UdpHandle,\r
1137 &gEfiUdp4ProtocolGuid,\r
d1050b9d 1138 (VOID **)&Udp4,\r
99c048ef 1139 gDns4DriverBinding.DriverBindingHandle,\r
1140 Instance->ChildHandle,\r
1141 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
1142 );\r
1143 if (EFI_ERROR (Status)) {\r
1144 //\r
1145 // Close the Udp4 protocol.\r
1146 //\r
1147 gBS->CloseProtocol (\r
1148 DnsSb->ConnectUdp->UdpHandle,\r
1149 &gEfiUdp4ProtocolGuid,\r
1150 gDns4DriverBinding.DriverBindingHandle,\r
bf7249df 1151 *ChildHandle\r
99c048ef 1152 );\r
f75a7f56 1153\r
d1050b9d
MK
1154 gBS->UninstallMultipleProtocolInterfaces (\r
1155 Instance->ChildHandle,\r
1156 &gEfiDns4ProtocolGuid,\r
1157 &Instance->Dns4,\r
1158 NULL\r
1159 );\r
f75a7f56 1160\r
99c048ef 1161 goto ON_ERROR;\r
1162 }\r
1163\r
1164 //\r
1165 // Add it to the parent's child list.\r
1166 //\r
1167 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
1168\r
1169 InsertTailList (&DnsSb->Dns4ChildrenList, &Instance->Link);\r
1170 DnsSb->Dns4ChildrenNum++;\r
1171\r
1172 gBS->RestoreTPL (OldTpl);\r
1173\r
1174 return EFI_SUCCESS;\r
1175\r
1176ON_ERROR:\r
1177\r
1178 DnsDestroyInstance (Instance);\r
1179 return Status;\r
1180}\r
1181\r
1182/**\r
1183 Destroys a child handle with a protocol installed on it.\r
f75a7f56
LG
1184\r
1185 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r
1186 that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r
99c048ef 1187 last protocol on ChildHandle, then ChildHandle is destroyed.\r
1188\r
1189 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
1190 @param[in] ChildHandle Handle of the child to destroy\r
1191\r
81a46615 1192 @retval EFI_SUCCESS The protocol was removed from ChildHandle.\r
99c048ef 1193 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
1194 @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
1195 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r
1196 because its services are being used.\r
1197 @retval other The child handle was not destroyed\r
1198\r
1199**/\r
1200EFI_STATUS\r
1201EFIAPI\r
1202Dns4ServiceBindingDestroyChild (\r
1203 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
1204 IN EFI_HANDLE ChildHandle\r
1205 )\r
1206{\r
d1050b9d
MK
1207 DNS_SERVICE *DnsSb;\r
1208 DNS_INSTANCE *Instance;\r
99c048ef 1209\r
d1050b9d
MK
1210 EFI_DNS4_PROTOCOL *Dns4;\r
1211 EFI_STATUS Status;\r
1212 EFI_TPL OldTpl;\r
99c048ef 1213\r
1214 if ((This == NULL) || (ChildHandle == NULL)) {\r
1215 return EFI_INVALID_PARAMETER;\r
1216 }\r
1217\r
1218 //\r
1219 // Retrieve the private context data structures\r
1220 //\r
1221 Status = gBS->OpenProtocol (\r
1222 ChildHandle,\r
1223 &gEfiDns4ProtocolGuid,\r
d1050b9d 1224 (VOID **)&Dns4,\r
99c048ef 1225 gDns4DriverBinding.DriverBindingHandle,\r
1226 ChildHandle,\r
1227 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1228 );\r
1229\r
1230 if (EFI_ERROR (Status)) {\r
1231 return EFI_UNSUPPORTED;\r
1232 }\r
1233\r
d1050b9d
MK
1234 Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (Dns4);\r
1235 DnsSb = DNS_SERVICE_FROM_THIS (This);\r
99c048ef 1236\r
1237 if (Instance->Service != DnsSb) {\r
1238 return EFI_INVALID_PARAMETER;\r
1239 }\r
1240\r
1241 if (Instance->InDestroy) {\r
1242 return EFI_SUCCESS;\r
1243 }\r
1244\r
1245 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
f75a7f56 1246\r
99c048ef 1247 Instance->InDestroy = TRUE;\r
1248\r
1249 //\r
1250 // Close the Udp4 protocol.\r
1251 //\r
1252 gBS->CloseProtocol (\r
1253 DnsSb->ConnectUdp->UdpHandle,\r
1254 &gEfiUdp4ProtocolGuid,\r
1255 gDns4DriverBinding.DriverBindingHandle,\r
1256 ChildHandle\r
1257 );\r
1258\r
1259 gBS->CloseProtocol (\r
1260 Instance->UdpIo->UdpHandle,\r
1261 &gEfiUdp4ProtocolGuid,\r
1262 gDns4DriverBinding.DriverBindingHandle,\r
1263 ChildHandle\r
1264 );\r
1265\r
1266 gBS->RestoreTPL (OldTpl);\r
1267\r
1268 //\r
1269 // Uninstall the DNS protocol first to enable a top down destruction.\r
1270 //\r
1271 Status = gBS->UninstallProtocolInterface (\r
1272 ChildHandle,\r
1273 &gEfiDns4ProtocolGuid,\r
1274 Dns4\r
1275 );\r
1276\r
1277 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
f75a7f56 1278\r
99c048ef 1279 if (EFI_ERROR (Status)) {\r
1280 Instance->InDestroy = FALSE;\r
1281 gBS->RestoreTPL (OldTpl);\r
1282 return Status;\r
1283 }\r
1284\r
1285 RemoveEntryList (&Instance->Link);\r
1286 DnsSb->Dns4ChildrenNum--;\r
1287\r
1288 gBS->RestoreTPL (OldTpl);\r
1289\r
1290 DnsDestroyInstance (Instance);\r
1291 return EFI_SUCCESS;\r
1292}\r
1293\r
1294/**\r
1295 Creates a child handle and installs a protocol.\r
f75a7f56
LG
1296\r
1297 The CreateChild() function installs a protocol on ChildHandle.\r
1298 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r
99c048ef 1299 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r
1300\r
1301 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
1302 @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,\r
f75a7f56 1303 then a new handle is created. If it is a pointer to an existing UEFI handle,\r
99c048ef 1304 then the protocol is added to the existing UEFI handle.\r
1305\r
81a46615 1306 @retval EFI_SUCCESS The protocol was added to ChildHandle.\r
99c048ef 1307 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
c2adf51f 1308 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r
99c048ef 1309 the child\r
1310 @retval other The child handle was not created\r
1311\r
1312**/\r
1313EFI_STATUS\r
1314EFIAPI\r
1315Dns6ServiceBindingCreateChild (\r
1316 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
1317 IN EFI_HANDLE *ChildHandle\r
1318 )\r
1319{\r
d1050b9d
MK
1320 DNS_SERVICE *DnsSb;\r
1321 DNS_INSTANCE *Instance;\r
1322 EFI_STATUS Status;\r
1323 EFI_TPL OldTpl;\r
1324 VOID *Udp6;\r
99c048ef 1325\r
1326 if ((This == NULL) || (ChildHandle == NULL)) {\r
1327 return EFI_INVALID_PARAMETER;\r
1328 }\r
1329\r
1330 DnsSb = DNS_SERVICE_FROM_THIS (This);\r
1331\r
1332 Status = DnsCreateInstance (DnsSb, &Instance);\r
1333 if (EFI_ERROR (Status)) {\r
1334 return Status;\r
1335 }\r
d1050b9d 1336\r
99c048ef 1337 ASSERT (Instance != NULL);\r
1338\r
1339 //\r
1340 // Install the DNS protocol onto ChildHandle\r
1341 //\r
1342 Status = gBS->InstallMultipleProtocolInterfaces (\r
1343 ChildHandle,\r
1344 &gEfiDns6ProtocolGuid,\r
1345 &Instance->Dns6,\r
1346 NULL\r
1347 );\r
1348 if (EFI_ERROR (Status)) {\r
1349 goto ON_ERROR;\r
1350 }\r
1351\r
1352 Instance->ChildHandle = *ChildHandle;\r
1353\r
1354 //\r
1355 // Open the Udp6 protocol BY_CHILD.\r
1356 //\r
1357 Status = gBS->OpenProtocol (\r
1358 DnsSb->ConnectUdp->UdpHandle,\r
1359 &gEfiUdp6ProtocolGuid,\r
d1050b9d 1360 (VOID **)&Udp6,\r
99c048ef 1361 gDns6DriverBinding.DriverBindingHandle,\r
1362 Instance->ChildHandle,\r
1363 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
1364 );\r
1365 if (EFI_ERROR (Status)) {\r
1366 gBS->UninstallMultipleProtocolInterfaces (\r
1367 Instance->ChildHandle,\r
1368 &gEfiDns6ProtocolGuid,\r
1369 &Instance->Dns6,\r
1370 NULL\r
1371 );\r
f75a7f56 1372\r
99c048ef 1373 goto ON_ERROR;\r
1374 }\r
1375\r
1376 //\r
1377 // Open the Udp6 protocol by child.\r
1378 //\r
1379 Status = gBS->OpenProtocol (\r
1380 Instance->UdpIo->UdpHandle,\r
1381 &gEfiUdp6ProtocolGuid,\r
d1050b9d 1382 (VOID **)&Udp6,\r
99c048ef 1383 gDns6DriverBinding.DriverBindingHandle,\r
1384 Instance->ChildHandle,\r
1385 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
1386 );\r
1387 if (EFI_ERROR (Status)) {\r
1388 //\r
1389 // Close the Udp6 protocol.\r
1390 //\r
1391 gBS->CloseProtocol (\r
1392 DnsSb->ConnectUdp->UdpHandle,\r
1393 &gEfiUdp6ProtocolGuid,\r
1394 gDns6DriverBinding.DriverBindingHandle,\r
bf7249df 1395 *ChildHandle\r
99c048ef 1396 );\r
f75a7f56 1397\r
d1050b9d
MK
1398 gBS->UninstallMultipleProtocolInterfaces (\r
1399 Instance->ChildHandle,\r
1400 &gEfiDns6ProtocolGuid,\r
1401 &Instance->Dns6,\r
1402 NULL\r
1403 );\r
f75a7f56 1404\r
99c048ef 1405 goto ON_ERROR;\r
1406 }\r
1407\r
1408 //\r
1409 // Add it to the parent's child list.\r
1410 //\r
1411 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
1412\r
1413 InsertTailList (&DnsSb->Dns6ChildrenList, &Instance->Link);\r
1414 DnsSb->Dns6ChildrenNum++;\r
1415\r
1416 gBS->RestoreTPL (OldTpl);\r
1417\r
1418 return EFI_SUCCESS;\r
1419\r
1420ON_ERROR:\r
1421\r
1422 DnsDestroyInstance (Instance);\r
1423 return Status;\r
1424}\r
1425\r
1426/**\r
1427 Destroys a child handle with a protocol installed on it.\r
f75a7f56
LG
1428\r
1429 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r
1430 that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r
99c048ef 1431 last protocol on ChildHandle, then ChildHandle is destroyed.\r
1432\r
1433 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r
1434 @param[in] ChildHandle Handle of the child to destroy\r
1435\r
81a46615 1436 @retval EFI_SUCCESS The protocol was removed from ChildHandle.\r
99c048ef 1437 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
1438 @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
1439 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r
1440 because its services are being used.\r
1441 @retval other The child handle was not destroyed\r
1442\r
1443**/\r
1444EFI_STATUS\r
1445EFIAPI\r
1446Dns6ServiceBindingDestroyChild (\r
1447 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
1448 IN EFI_HANDLE ChildHandle\r
1449 )\r
1450{\r
d1050b9d
MK
1451 DNS_SERVICE *DnsSb;\r
1452 DNS_INSTANCE *Instance;\r
99c048ef 1453\r
d1050b9d
MK
1454 EFI_DNS6_PROTOCOL *Dns6;\r
1455 EFI_STATUS Status;\r
1456 EFI_TPL OldTpl;\r
99c048ef 1457\r
1458 if ((This == NULL) || (ChildHandle == NULL)) {\r
1459 return EFI_INVALID_PARAMETER;\r
1460 }\r
1461\r
1462 //\r
1463 // Retrieve the private context data structures\r
1464 //\r
1465 Status = gBS->OpenProtocol (\r
1466 ChildHandle,\r
1467 &gEfiDns6ProtocolGuid,\r
d1050b9d 1468 (VOID **)&Dns6,\r
99c048ef 1469 gDns6DriverBinding.DriverBindingHandle,\r
1470 ChildHandle,\r
1471 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1472 );\r
1473\r
1474 if (EFI_ERROR (Status)) {\r
1475 return EFI_UNSUPPORTED;\r
1476 }\r
1477\r
d1050b9d
MK
1478 Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (Dns6);\r
1479 DnsSb = DNS_SERVICE_FROM_THIS (This);\r
99c048ef 1480\r
1481 if (Instance->Service != DnsSb) {\r
1482 return EFI_INVALID_PARAMETER;\r
1483 }\r
1484\r
1485 if (Instance->InDestroy) {\r
1486 return EFI_SUCCESS;\r
1487 }\r
1488\r
1489 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
1490\r
1491 Instance->InDestroy = TRUE;\r
1492\r
1493 //\r
1494 // Close the Udp6 protocol.\r
1495 //\r
1496 gBS->CloseProtocol (\r
1497 DnsSb->ConnectUdp->UdpHandle,\r
1498 &gEfiUdp6ProtocolGuid,\r
1499 gDns6DriverBinding.DriverBindingHandle,\r
1500 ChildHandle\r
1501 );\r
1502\r
1503 gBS->CloseProtocol (\r
1504 Instance->UdpIo->UdpHandle,\r
1505 &gEfiUdp6ProtocolGuid,\r
1506 gDns6DriverBinding.DriverBindingHandle,\r
1507 ChildHandle\r
1508 );\r
1509\r
1510 gBS->RestoreTPL (OldTpl);\r
1511\r
1512 //\r
1513 // Uninstall the DNS protocol first to enable a top down destruction.\r
1514 //\r
1515 Status = gBS->UninstallProtocolInterface (\r
1516 ChildHandle,\r
1517 &gEfiDns6ProtocolGuid,\r
1518 Dns6\r
1519 );\r
1520\r
1521 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
1522\r
1523 if (EFI_ERROR (Status)) {\r
1524 Instance->InDestroy = FALSE;\r
1525 gBS->RestoreTPL (OldTpl);\r
1526 return Status;\r
1527 }\r
1528\r
1529 RemoveEntryList (&Instance->Link);\r
1530 DnsSb->Dns6ChildrenNum--;\r
1531\r
1532 gBS->RestoreTPL (OldTpl);\r
1533\r
1534 DnsDestroyInstance (Instance);\r
1535 return EFI_SUCCESS;\r
1536}\r