]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Dhcp4Dxe/Dhcp4Driver.c
NetworkPkg: Move Network library and drivers from MdeModulePkg to NetworkPkg
[mirror_edk2.git] / NetworkPkg / Dhcp4Dxe / Dhcp4Driver.c
1 /** @file
2
3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
5
6 **/
7
8 #include "Dhcp4Impl.h"
9 #include "Dhcp4Driver.h"
10
11 EFI_DRIVER_BINDING_PROTOCOL gDhcp4DriverBinding = {
12 Dhcp4DriverBindingSupported,
13 Dhcp4DriverBindingStart,
14 Dhcp4DriverBindingStop,
15 0xa,
16 NULL,
17 NULL
18 };
19
20 EFI_SERVICE_BINDING_PROTOCOL mDhcp4ServiceBindingTemplate = {
21 Dhcp4ServiceBindingCreateChild,
22 Dhcp4ServiceBindingDestroyChild
23 };
24
25 /**
26 This is the declaration of an EFI image entry point. This entry point is
27 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
28 both device drivers and bus drivers.
29
30 Entry point of the DHCP driver to install various protocols.
31
32 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
33 @param[in] SystemTable A pointer to the EFI System Table.
34
35 @retval EFI_SUCCESS The operation completed successfully.
36 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 Dhcp4DriverEntryPoint (
42 IN EFI_HANDLE ImageHandle,
43 IN EFI_SYSTEM_TABLE *SystemTable
44 )
45 {
46 return EfiLibInstallDriverBindingComponentName2 (
47 ImageHandle,
48 SystemTable,
49 &gDhcp4DriverBinding,
50 ImageHandle,
51 &gDhcp4ComponentName,
52 &gDhcp4ComponentName2
53 );
54 }
55
56
57 /**
58 Test to see if this driver supports ControllerHandle. This service
59 is called by the EFI boot service ConnectController(). In
60 order to make drivers as small as possible, there are a few calling
61 restrictions for this service. ConnectController() must
62 follow these calling restrictions. If any other agent wishes to call
63 Supported() it must also follow these calling restrictions.
64
65 @param[in] This Protocol instance pointer.
66 @param[in] ControllerHandle Handle of device to test
67 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
68 device to start.
69
70 @retval EFI_SUCCESS This driver supports this device
71 @retval EFI_ALREADY_STARTED This driver is already running on this device
72 @retval other This driver does not support this device
73
74 **/
75 EFI_STATUS
76 EFIAPI
77 Dhcp4DriverBindingSupported (
78 IN EFI_DRIVER_BINDING_PROTOCOL *This,
79 IN EFI_HANDLE ControllerHandle,
80 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
81 )
82 {
83 EFI_STATUS Status;
84
85 Status = gBS->OpenProtocol (
86 ControllerHandle,
87 &gEfiUdp4ServiceBindingProtocolGuid,
88 NULL,
89 This->DriverBindingHandle,
90 ControllerHandle,
91 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
92 );
93
94 return Status;
95 }
96
97
98
99 /**
100 Configure the default UDP child to receive all the DHCP traffics
101 on this network interface.
102
103 @param[in] UdpIo The UDP IO to configure
104 @param[in] Context The context to the function
105
106 @retval EFI_SUCCESS The UDP IO is successfully configured.
107 @retval Others Failed to configure the UDP child.
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 DhcpConfigUdpIo (
113 IN UDP_IO *UdpIo,
114 IN VOID *Context
115 )
116 {
117 EFI_UDP4_CONFIG_DATA UdpConfigData;
118
119 UdpConfigData.AcceptBroadcast = TRUE;
120 UdpConfigData.AcceptPromiscuous = FALSE;
121 UdpConfigData.AcceptAnyPort = FALSE;
122 UdpConfigData.AllowDuplicatePort = TRUE;
123 UdpConfigData.TypeOfService = 0;
124 UdpConfigData.TimeToLive = 64;
125 UdpConfigData.DoNotFragment = FALSE;
126 UdpConfigData.ReceiveTimeout = 0;
127 UdpConfigData.TransmitTimeout = 0;
128
129 UdpConfigData.UseDefaultAddress = FALSE;
130 UdpConfigData.StationPort = DHCP_CLIENT_PORT;
131 UdpConfigData.RemotePort = DHCP_SERVER_PORT;
132
133 ZeroMem (&UdpConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
134 ZeroMem (&UdpConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
135 ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS));
136
137 return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);;
138 }
139
140
141
142 /**
143 Destroy the DHCP service. The Dhcp4 service may be partly initialized,
144 or partly destroyed. If a resource is destroyed, it is marked as so in
145 case the destroy failed and being called again later.
146
147 @param[in] DhcpSb The DHCP service instance to destroy.
148
149 @retval EFI_SUCCESS Always return success.
150
151 **/
152 EFI_STATUS
153 Dhcp4CloseService (
154 IN DHCP_SERVICE *DhcpSb
155 )
156 {
157 DhcpCleanLease (DhcpSb);
158
159 if (DhcpSb->UdpIo != NULL) {
160 UdpIoFreeIo (DhcpSb->UdpIo);
161 DhcpSb->UdpIo = NULL;
162 }
163
164 if (DhcpSb->Timer != NULL) {
165 gBS->SetTimer (DhcpSb->Timer, TimerCancel, 0);
166 gBS->CloseEvent (DhcpSb->Timer);
167
168 DhcpSb->Timer = NULL;
169 }
170
171 return EFI_SUCCESS;
172 }
173
174
175
176 /**
177 Create a new DHCP service binding instance for the controller.
178
179 @param[in] Controller The controller to install DHCP service binding
180 protocol onto
181 @param[in] ImageHandle The driver's image handle
182 @param[out] Service The variable to receive the created DHCP service
183 instance.
184
185 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource .
186 @retval EFI_SUCCESS The DHCP service instance is created.
187 @retval other Other error occurs.
188
189 **/
190 EFI_STATUS
191 Dhcp4CreateService (
192 IN EFI_HANDLE Controller,
193 IN EFI_HANDLE ImageHandle,
194 OUT DHCP_SERVICE **Service
195 )
196 {
197 DHCP_SERVICE *DhcpSb;
198 EFI_STATUS Status;
199
200 *Service = NULL;
201 DhcpSb = AllocateZeroPool (sizeof (DHCP_SERVICE));
202
203 if (DhcpSb == NULL) {
204 return EFI_OUT_OF_RESOURCES;
205 }
206
207 DhcpSb->Signature = DHCP_SERVICE_SIGNATURE;
208 DhcpSb->ServiceState = DHCP_UNCONFIGED;
209 DhcpSb->Controller = Controller;
210 DhcpSb->Image = ImageHandle;
211 InitializeListHead (&DhcpSb->Children);
212 DhcpSb->DhcpState = Dhcp4Stopped;
213 DhcpSb->Xid = NET_RANDOM (NetRandomInitSeed ());
214 CopyMem (
215 &DhcpSb->ServiceBinding,
216 &mDhcp4ServiceBindingTemplate,
217 sizeof (EFI_SERVICE_BINDING_PROTOCOL)
218 );
219 //
220 // Create various resources, UdpIo, Timer, and get Mac address
221 //
222 Status = gBS->CreateEvent (
223 EVT_NOTIFY_SIGNAL | EVT_TIMER,
224 TPL_CALLBACK,
225 DhcpOnTimerTick,
226 DhcpSb,
227 &DhcpSb->Timer
228 );
229
230 if (EFI_ERROR (Status)) {
231 goto ON_ERROR;
232 }
233
234 DhcpSb->UdpIo = UdpIoCreateIo (
235 Controller,
236 ImageHandle,
237 DhcpConfigUdpIo,
238 UDP_IO_UDP4_VERSION,
239 NULL
240 );
241
242 if (DhcpSb->UdpIo == NULL) {
243 Status = EFI_OUT_OF_RESOURCES;
244 goto ON_ERROR;
245 }
246
247 DhcpSb->HwLen = (UINT8) DhcpSb->UdpIo->SnpMode.HwAddressSize;
248 DhcpSb->HwType = DhcpSb->UdpIo->SnpMode.IfType;
249 CopyMem (&DhcpSb->Mac, &DhcpSb->UdpIo->SnpMode.CurrentAddress, sizeof (DhcpSb->Mac));
250
251 *Service = DhcpSb;
252 return EFI_SUCCESS;
253
254 ON_ERROR:
255 Dhcp4CloseService (DhcpSb);
256 FreePool (DhcpSb);
257
258 return Status;
259 }
260
261
262 /**
263 Start this driver on ControllerHandle. This service is called by the
264 EFI boot service ConnectController(). In order to make
265 drivers as small as possible, there are a few calling restrictions for
266 this service. ConnectController() must follow these
267 calling restrictions. If any other agent wishes to call Start() it
268 must also follow these calling restrictions.
269
270 @param[in] This Protocol instance pointer.
271 @param[in] ControllerHandle Handle of device to bind driver to
272 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
273 device to start.
274
275 @retval EFI_SUCCESS This driver is added to ControllerHandle
276 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
277 @retval other This driver does not support this device
278
279 **/
280 EFI_STATUS
281 EFIAPI
282 Dhcp4DriverBindingStart (
283 IN EFI_DRIVER_BINDING_PROTOCOL *This,
284 IN EFI_HANDLE ControllerHandle,
285 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
286 )
287 {
288 DHCP_SERVICE *DhcpSb;
289 EFI_STATUS Status;
290
291 //
292 // First: test for the DHCP4 Protocol
293 //
294 Status = gBS->OpenProtocol (
295 ControllerHandle,
296 &gEfiDhcp4ServiceBindingProtocolGuid,
297 NULL,
298 This->DriverBindingHandle,
299 ControllerHandle,
300 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
301 );
302
303 if (Status == EFI_SUCCESS) {
304 return EFI_ALREADY_STARTED;
305 }
306
307 Status = Dhcp4CreateService (ControllerHandle, This->DriverBindingHandle, &DhcpSb);
308
309 if (EFI_ERROR (Status)) {
310 return Status;
311 }
312 ASSERT (DhcpSb != NULL);
313
314 //
315 // Start the receiving
316 //
317 Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);
318
319 if (EFI_ERROR (Status)) {
320 goto ON_ERROR;
321 }
322 Status = gBS->SetTimer (DhcpSb->Timer, TimerPeriodic, TICKS_PER_SECOND);
323
324 if (EFI_ERROR (Status)) {
325 goto ON_ERROR;
326 }
327
328 //
329 // Install the Dhcp4ServiceBinding Protocol onto ControlerHandle
330 //
331 Status = gBS->InstallMultipleProtocolInterfaces (
332 &ControllerHandle,
333 &gEfiDhcp4ServiceBindingProtocolGuid,
334 &DhcpSb->ServiceBinding,
335 NULL
336 );
337
338 if (EFI_ERROR (Status)) {
339 goto ON_ERROR;
340 }
341
342 return Status;
343
344 ON_ERROR:
345 Dhcp4CloseService (DhcpSb);
346 FreePool (DhcpSb);
347 return Status;
348 }
349
350 /**
351 Callback function which provided by user to remove one node in NetDestroyLinkList process.
352
353 @param[in] Entry The entry to be removed.
354 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
355
356 @retval EFI_SUCCESS The entry has been removed successfully.
357 @retval Others Fail to remove the entry.
358
359 **/
360 EFI_STATUS
361 EFIAPI
362 Dhcp4DestroyChildEntry (
363 IN LIST_ENTRY *Entry,
364 IN VOID *Context
365 )
366 {
367 DHCP_PROTOCOL *Instance;
368 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
369
370 if (Entry == NULL || Context == NULL) {
371 return EFI_INVALID_PARAMETER;
372 }
373
374 Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP_PROTOCOL, Link, DHCP_PROTOCOL_SIGNATURE);
375 ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;
376
377 return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
378 }
379
380
381 /**
382 Stop this driver on ControllerHandle. This service is called by the
383 EFI boot service DisconnectController(). In order to
384 make drivers as small as possible, there are a few calling
385 restrictions for this service. DisconnectController()
386 must follow these calling restrictions. If any other agent wishes
387 to call Stop() it must also follow these calling restrictions.
388
389 @param[in] This Protocol instance pointer.
390 @param[in] ControllerHandle Handle of device to stop driver on
391 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
392 children is zero stop the entire bus driver.
393 @param[in] ChildHandleBuffer List of Child Handles to Stop.
394
395 @retval EFI_SUCCESS This driver is removed ControllerHandle
396 @retval other This driver was not removed from this device
397
398 **/
399 EFI_STATUS
400 EFIAPI
401 Dhcp4DriverBindingStop (
402 IN EFI_DRIVER_BINDING_PROTOCOL *This,
403 IN EFI_HANDLE ControllerHandle,
404 IN UINTN NumberOfChildren,
405 IN EFI_HANDLE *ChildHandleBuffer
406 )
407 {
408 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
409 DHCP_SERVICE *DhcpSb;
410 EFI_HANDLE NicHandle;
411 EFI_STATUS Status;
412 LIST_ENTRY *List;
413 UINTN ListLength;
414
415 //
416 // DHCP driver opens UDP child, So, the ControllerHandle is the
417 // UDP child handle. locate the Nic handle first.
418 //
419 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);
420
421 if (NicHandle == NULL) {
422 return EFI_SUCCESS;
423 }
424
425 Status = gBS->OpenProtocol (
426 NicHandle,
427 &gEfiDhcp4ServiceBindingProtocolGuid,
428 (VOID **) &ServiceBinding,
429 This->DriverBindingHandle,
430 NicHandle,
431 EFI_OPEN_PROTOCOL_GET_PROTOCOL
432 );
433
434 if (EFI_ERROR (Status)) {
435 return EFI_DEVICE_ERROR;
436 }
437
438 DhcpSb = DHCP_SERVICE_FROM_THIS (ServiceBinding);
439 if (!IsListEmpty (&DhcpSb->Children)) {
440 //
441 // Destroy all the children instances before destory the service.
442 //
443 List = &DhcpSb->Children;
444 Status = NetDestroyLinkList (
445 List,
446 Dhcp4DestroyChildEntry,
447 ServiceBinding,
448 &ListLength
449 );
450 if (EFI_ERROR (Status) || ListLength != 0) {
451 Status = EFI_DEVICE_ERROR;
452 }
453 }
454
455 if (NumberOfChildren == 0 && !IsListEmpty (&DhcpSb->Children)) {
456 Status = EFI_DEVICE_ERROR;
457 }
458
459 if (NumberOfChildren == 0 && IsListEmpty (&DhcpSb->Children)) {
460 //
461 // Destroy the service itself if no child instance left.
462 //
463 DhcpSb->ServiceState = DHCP_DESTROY;
464
465 gBS->UninstallProtocolInterface (
466 NicHandle,
467 &gEfiDhcp4ServiceBindingProtocolGuid,
468 ServiceBinding
469 );
470
471 Dhcp4CloseService (DhcpSb);
472
473 if (gDhcpControllerNameTable != NULL) {
474 FreeUnicodeStringTable (gDhcpControllerNameTable);
475 gDhcpControllerNameTable = NULL;
476 }
477 FreePool (DhcpSb);
478
479 Status = EFI_SUCCESS;
480 }
481
482 return Status;
483 }
484
485
486 /**
487 Initialize a new DHCP instance.
488
489 @param DhcpSb The dhcp service instance
490 @param Instance The dhcp instance to initialize
491
492 **/
493 VOID
494 DhcpInitProtocol (
495 IN DHCP_SERVICE *DhcpSb,
496 IN OUT DHCP_PROTOCOL *Instance
497 )
498 {
499 Instance->Signature = DHCP_PROTOCOL_SIGNATURE;
500 CopyMem (&Instance->Dhcp4Protocol, &mDhcp4ProtocolTemplate, sizeof (Instance->Dhcp4Protocol));
501 InitializeListHead (&Instance->Link);
502 Instance->Handle = NULL;
503 Instance->Service = DhcpSb;
504 Instance->InDestroy = FALSE;
505 Instance->CompletionEvent = NULL;
506 Instance->RenewRebindEvent = NULL;
507 Instance->Token = NULL;
508 Instance->UdpIo = NULL;
509 Instance->ElaspedTime = 0;
510 NetbufQueInit (&Instance->ResponseQueue);
511 }
512
513
514 /**
515 Creates a child handle and installs a protocol.
516
517 The CreateChild() function installs a protocol on ChildHandle.
518 If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
519 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
520
521 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
522 @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
523 then a new handle is created. If it is a pointer to an existing UEFI handle,
524 then the protocol is added to the existing UEFI handle.
525
526 @retval EFI_SUCCES The protocol was added to ChildHandle.
527 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
528 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
529 the child
530 @retval other The child handle was not created
531
532 **/
533 EFI_STATUS
534 EFIAPI
535 Dhcp4ServiceBindingCreateChild (
536 IN EFI_SERVICE_BINDING_PROTOCOL *This,
537 IN EFI_HANDLE *ChildHandle
538 )
539 {
540 DHCP_SERVICE *DhcpSb;
541 DHCP_PROTOCOL *Instance;
542 EFI_STATUS Status;
543 EFI_TPL OldTpl;
544 VOID *Udp4;
545
546 if ((This == NULL) || (ChildHandle == NULL)) {
547 return EFI_INVALID_PARAMETER;
548 }
549
550 Instance = AllocatePool (sizeof (*Instance));
551
552 if (Instance == NULL) {
553 return EFI_OUT_OF_RESOURCES;
554 }
555
556 DhcpSb = DHCP_SERVICE_FROM_THIS (This);
557 DhcpInitProtocol (DhcpSb, Instance);
558
559 //
560 // Install DHCP4 onto ChildHandle
561 //
562 Status = gBS->InstallMultipleProtocolInterfaces (
563 ChildHandle,
564 &gEfiDhcp4ProtocolGuid,
565 &Instance->Dhcp4Protocol,
566 NULL
567 );
568
569 if (EFI_ERROR (Status)) {
570 FreePool (Instance);
571 return Status;
572 }
573
574 Instance->Handle = *ChildHandle;
575
576 //
577 // Open the Udp4 protocol BY_CHILD.
578 //
579 Status = gBS->OpenProtocol (
580 DhcpSb->UdpIo->UdpHandle,
581 &gEfiUdp4ProtocolGuid,
582 (VOID **) &Udp4,
583 gDhcp4DriverBinding.DriverBindingHandle,
584 Instance->Handle,
585 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
586 );
587 if (EFI_ERROR (Status)) {
588 gBS->UninstallMultipleProtocolInterfaces (
589 Instance->Handle,
590 &gEfiDhcp4ProtocolGuid,
591 &Instance->Dhcp4Protocol,
592 NULL
593 );
594
595 FreePool (Instance);
596 return Status;
597 }
598
599 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
600
601 InsertTailList (&DhcpSb->Children, &Instance->Link);
602 DhcpSb->NumChildren++;
603
604 gBS->RestoreTPL (OldTpl);
605
606 return EFI_SUCCESS;
607 }
608
609
610 /**
611 Destroys a child handle with a protocol installed on it.
612
613 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
614 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
615 last protocol on ChildHandle, then ChildHandle is destroyed.
616
617 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
618 @param ChildHandle Handle of the child to destroy
619
620 @retval EFI_SUCCES The protocol was removed from ChildHandle.
621 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
622 @retval EFI_INVALID_PARAMETER Child handle is NULL.
623 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
624 because its services are being used.
625 @retval other The child handle was not destroyed
626
627 **/
628 EFI_STATUS
629 EFIAPI
630 Dhcp4ServiceBindingDestroyChild (
631 IN EFI_SERVICE_BINDING_PROTOCOL *This,
632 IN EFI_HANDLE ChildHandle
633 )
634 {
635 DHCP_SERVICE *DhcpSb;
636 DHCP_PROTOCOL *Instance;
637 EFI_DHCP4_PROTOCOL *Dhcp;
638 EFI_TPL OldTpl;
639 EFI_STATUS Status;
640
641 if ((This == NULL) || (ChildHandle == NULL)) {
642 return EFI_INVALID_PARAMETER;
643 }
644
645 //
646 // Retrieve the private context data structures
647 //
648 Status = gBS->OpenProtocol (
649 ChildHandle,
650 &gEfiDhcp4ProtocolGuid,
651 (VOID **) &Dhcp,
652 gDhcp4DriverBinding.DriverBindingHandle,
653 ChildHandle,
654 EFI_OPEN_PROTOCOL_GET_PROTOCOL
655 );
656
657 if (EFI_ERROR (Status)) {
658 return EFI_UNSUPPORTED;
659 }
660
661 Instance = DHCP_INSTANCE_FROM_THIS (Dhcp);
662 DhcpSb = DHCP_SERVICE_FROM_THIS (This);
663
664 if (Instance->Service != DhcpSb) {
665 return EFI_INVALID_PARAMETER;
666 }
667
668 //
669 // A child can be destroyed more than once. For example,
670 // Dhcp4DriverBindingStop will destroy all of its children.
671 // when caller driver is being stopped, it will destroy the
672 // dhcp child it opens.
673 //
674 if (Instance->InDestroy) {
675 return EFI_SUCCESS;
676 }
677
678 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
679 Instance->InDestroy = TRUE;
680
681 //
682 // Close the Udp4 protocol.
683 //
684 gBS->CloseProtocol (
685 DhcpSb->UdpIo->UdpHandle,
686 &gEfiUdp4ProtocolGuid,
687 gDhcp4DriverBinding.DriverBindingHandle,
688 ChildHandle
689 );
690
691 //
692 // Uninstall the DHCP4 protocol first to enable a top down destruction.
693 //
694 gBS->RestoreTPL (OldTpl);
695 Status = gBS->UninstallProtocolInterface (
696 ChildHandle,
697 &gEfiDhcp4ProtocolGuid,
698 Dhcp
699 );
700 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
701 if (EFI_ERROR (Status)) {
702 Instance->InDestroy = FALSE;
703
704 gBS->RestoreTPL (OldTpl);
705 return Status;
706 }
707
708 if (DhcpSb->ActiveChild == Instance) {
709 DhcpYieldControl (DhcpSb);
710 }
711
712 RemoveEntryList (&Instance->Link);
713 DhcpSb->NumChildren--;
714
715 if (Instance->UdpIo != NULL) {
716 UdpIoCleanIo (Instance->UdpIo);
717 gBS->CloseProtocol (
718 Instance->UdpIo->UdpHandle,
719 &gEfiUdp4ProtocolGuid,
720 Instance->Service->Image,
721 Instance->Handle
722 );
723 UdpIoFreeIo (Instance->UdpIo);
724 Instance->UdpIo = NULL;
725 Instance->Token = NULL;
726 }
727
728 gBS->RestoreTPL (OldTpl);
729
730 FreePool (Instance);
731 return EFI_SUCCESS;
732 }