X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Driver.c;h=e891b68883070733d0e419a97c8e7e32c5c2c202;hp=6a4ac62acdea5a12f1b4eee08ee10b4835272156;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=3e8c18da0441069591e5aa218f378001b29512dd diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c index 6a4ac62acd..e891b68883 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c @@ -1,13 +1,7 @@ /** @file -Copyright (c) 2006 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -32,7 +26,7 @@ EFI_SERVICE_BINDING_PROTOCOL mDhcp4ServiceBindingTemplate = { This is the declaration of an EFI image entry point. This entry point is the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including both device drivers and bus drivers. - + Entry point of the DHCP driver to install various protocols. @param[in] ImageHandle The firmware allocated handle for the UEFI image. @@ -106,16 +100,17 @@ Dhcp4DriverBindingSupported ( Configure the default UDP child to receive all the DHCP traffics on this network interface. - @param[in] UdpIo The UDP IO port to configure + @param[in] UdpIo The UDP IO to configure @param[in] Context The context to the function - @retval EFI_SUCCESS The UDP IO port is successfully configured. + @retval EFI_SUCCESS The UDP IO is successfully configured. @retval Others Failed to configure the UDP child. **/ EFI_STATUS +EFIAPI DhcpConfigUdpIo ( - IN UDP_IO_PORT *UdpIo, + IN UDP_IO *UdpIo, IN VOID *Context ) { @@ -139,17 +134,17 @@ DhcpConfigUdpIo ( ZeroMem (&UdpConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS)); - return UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);; + return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);; } /** - Destory the DHCP service. The Dhcp4 service may be partly initialized, + Destroy the DHCP service. The Dhcp4 service may be partly initialized, or partly destroyed. If a resource is destroyed, it is marked as so in case the destroy failed and being called again later. - @param[in] DhcpSb The DHCP service instance to destory. + @param[in] DhcpSb The DHCP service instance to destroy. @retval EFI_SUCCESS Always return success. @@ -162,7 +157,7 @@ Dhcp4CloseService ( DhcpCleanLease (DhcpSb); if (DhcpSb->UdpIo != NULL) { - UdpIoFreePort (DhcpSb->UdpIo); + UdpIoFreeIo (DhcpSb->UdpIo); DhcpSb->UdpIo = NULL; } @@ -211,7 +206,6 @@ Dhcp4CreateService ( DhcpSb->Signature = DHCP_SERVICE_SIGNATURE; DhcpSb->ServiceState = DHCP_UNCONFIGED; - DhcpSb->InDestory = FALSE; DhcpSb->Controller = Controller; DhcpSb->Image = ImageHandle; InitializeListHead (&DhcpSb->Children); @@ -237,7 +231,13 @@ Dhcp4CreateService ( goto ON_ERROR; } - DhcpSb->UdpIo = UdpIoCreatePort (Controller, ImageHandle, DhcpConfigUdpIo, NULL); + DhcpSb->UdpIo = UdpIoCreateIo ( + Controller, + ImageHandle, + DhcpConfigUdpIo, + UDP_IO_UDP4_VERSION, + NULL + ); if (DhcpSb->UdpIo == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -253,7 +253,7 @@ Dhcp4CreateService ( ON_ERROR: Dhcp4CloseService (DhcpSb); - gBS->FreePool (DhcpSb); + FreePool (DhcpSb); return Status; } @@ -309,7 +309,16 @@ Dhcp4DriverBindingStart ( if (EFI_ERROR (Status)) { return Status; } + ASSERT (DhcpSb != NULL); + // + // Start the receiving + // + Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0); + + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } Status = gBS->SetTimer (DhcpSb->Timer, TimerPeriodic, TICKS_PER_SECOND); if (EFI_ERROR (Status)) { @@ -334,10 +343,40 @@ Dhcp4DriverBindingStart ( ON_ERROR: Dhcp4CloseService (DhcpSb); - gBS->FreePool (DhcpSb); + FreePool (DhcpSb); return Status; } +/** + Callback function which provided by user to remove one node in NetDestroyLinkList process. + + @param[in] Entry The entry to be removed. + @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList. + + @retval EFI_SUCCESS The entry has been removed successfully. + @retval Others Fail to remove the entry. + +**/ +EFI_STATUS +EFIAPI +Dhcp4DestroyChildEntry ( + IN LIST_ENTRY *Entry, + IN VOID *Context + ) +{ + DHCP_PROTOCOL *Instance; + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + + if (Entry == NULL || Context == NULL) { + return EFI_INVALID_PARAMETER; + } + + Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP_PROTOCOL, Link, DHCP_PROTOCOL_SIGNATURE); + ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context; + + return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); +} + /** Stop this driver on ControllerHandle. This service is called by the @@ -346,7 +385,7 @@ ON_ERROR: restrictions for this service. DisconnectController() must follow these calling restrictions. If any other agent wishes to call Stop() it must also follow these calling restrictions. - + @param[in] This Protocol instance pointer. @param[in] ControllerHandle Handle of device to stop driver on @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of @@ -368,10 +407,10 @@ Dhcp4DriverBindingStop ( { EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; DHCP_SERVICE *DhcpSb; - DHCP_PROTOCOL *Instance; EFI_HANDLE NicHandle; EFI_STATUS Status; - EFI_TPL OldTpl; + LIST_ENTRY *List; + UINTN ListLength; // // DHCP driver opens UDP child, So, the ControllerHandle is the @@ -380,7 +419,7 @@ Dhcp4DriverBindingStop ( NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid); if (NicHandle == NULL) { - return EFI_DEVICE_ERROR; + return EFI_SUCCESS; } Status = gBS->OpenProtocol ( @@ -397,17 +436,31 @@ Dhcp4DriverBindingStop ( } DhcpSb = DHCP_SERVICE_FROM_THIS (ServiceBinding); - - if (DhcpSb->InDestory) { - return EFI_SUCCESS; + if (!IsListEmpty (&DhcpSb->Children)) { + // + // Destroy all the children instances before destory the service. + // + List = &DhcpSb->Children; + Status = NetDestroyLinkList ( + List, + Dhcp4DestroyChildEntry, + ServiceBinding, + &ListLength + ); + if (EFI_ERROR (Status) || ListLength != 0) { + Status = EFI_DEVICE_ERROR; + } } - OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - - if (NumberOfChildren == 0) { + if (NumberOfChildren == 0 && !IsListEmpty (&DhcpSb->Children)) { + Status = EFI_DEVICE_ERROR; + } - DhcpSb->InDestory = TRUE; - DhcpSb->ServiceState = DHCP_DESTORY; + if (NumberOfChildren == 0 && IsListEmpty (&DhcpSb->Children)) { + // + // Destroy the service itself if no child instance left. + // + DhcpSb->ServiceState = DHCP_DESTROY; gBS->UninstallProtocolInterface ( NicHandle, @@ -417,24 +470,15 @@ Dhcp4DriverBindingStop ( Dhcp4CloseService (DhcpSb); - gBS->FreePool (DhcpSb); - } else { - // - // Don't use NET_LIST_FOR_EACH_SAFE here, Dhcp4ServiceBindingDestoryChild - // may cause other child to be deleted. - // - while (!IsListEmpty (&DhcpSb->Children)) { - Instance = NET_LIST_HEAD (&DhcpSb->Children, DHCP_PROTOCOL, Link); - ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); + if (gDhcpControllerNameTable != NULL) { + FreeUnicodeStringTable (gDhcpControllerNameTable); + gDhcpControllerNameTable = NULL; } + FreePool (DhcpSb); - if (DhcpSb->NumChildren != 0) { - Status = EFI_DEVICE_ERROR; - } + Status = EFI_SUCCESS; } - gBS->RestoreTPL (OldTpl); - return Status; } @@ -457,30 +501,31 @@ DhcpInitProtocol ( InitializeListHead (&Instance->Link); Instance->Handle = NULL; Instance->Service = DhcpSb; - Instance->InDestory = FALSE; + Instance->InDestroy = FALSE; Instance->CompletionEvent = NULL; Instance->RenewRebindEvent = NULL; Instance->Token = NULL; Instance->UdpIo = NULL; + Instance->ElaspedTime = 0; NetbufQueInit (&Instance->ResponseQueue); } /** Creates a child handle and installs a protocol. - - The CreateChild() function installs a protocol on ChildHandle. - If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. + + The CreateChild() function installs a protocol on ChildHandle. + If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. @param ChildHandle Pointer to the handle of the child to create. If it is NULL, - then a new handle is created. If it is a pointer to an existing UEFI handle, + then a new handle is created. If it is a pointer to an existing UEFI handle, then the protocol is added to the existing UEFI handle. @retval EFI_SUCCES The protocol was added to ChildHandle. @retval EFI_INVALID_PARAMETER ChildHandle is NULL. - @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create the child @retval other The child handle was not created @@ -522,7 +567,7 @@ Dhcp4ServiceBindingCreateChild ( ); if (EFI_ERROR (Status)) { - gBS->FreePool (Instance); + FreePool (Instance); return Status; } @@ -547,7 +592,7 @@ Dhcp4ServiceBindingCreateChild ( NULL ); - gBS->FreePool (Instance); + FreePool (Instance); return Status; } @@ -564,9 +609,9 @@ Dhcp4ServiceBindingCreateChild ( /** Destroys a child handle with a protocol installed on it. - - The DestroyChild() function does the opposite of CreateChild(). It removes a protocol - that was installed by CreateChild() from ChildHandle. If the removed protocol is the + + The DestroyChild() function does the opposite of CreateChild(). It removes a protocol + that was installed by CreateChild() from ChildHandle. If the removed protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. @@ -574,7 +619,7 @@ Dhcp4ServiceBindingCreateChild ( @retval EFI_SUCCES The protocol was removed from ChildHandle. @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed. - @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle. + @retval EFI_INVALID_PARAMETER Child handle is NULL. @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle because its services are being used. @retval other The child handle was not destroyed @@ -623,15 +668,15 @@ Dhcp4ServiceBindingDestroyChild ( // // A child can be destroyed more than once. For example, // Dhcp4DriverBindingStop will destroy all of its children. - // when caller driver is being stopped, it will destory the + // when caller driver is being stopped, it will destroy the // dhcp child it opens. // - if (Instance->InDestory) { + if (Instance->InDestroy) { return EFI_SUCCESS; } OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - Instance->InDestory = TRUE; + Instance->InDestroy = TRUE; // // Close the Udp4 protocol. @@ -646,14 +691,15 @@ Dhcp4ServiceBindingDestroyChild ( // // Uninstall the DHCP4 protocol first to enable a top down destruction. // + gBS->RestoreTPL (OldTpl); Status = gBS->UninstallProtocolInterface ( ChildHandle, &gEfiDhcp4ProtocolGuid, Dhcp ); - + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (EFI_ERROR (Status)) { - Instance->InDestory = FALSE; + Instance->InDestroy = FALSE; gBS->RestoreTPL (OldTpl); return Status; @@ -666,8 +712,21 @@ Dhcp4ServiceBindingDestroyChild ( RemoveEntryList (&Instance->Link); DhcpSb->NumChildren--; + if (Instance->UdpIo != NULL) { + UdpIoCleanIo (Instance->UdpIo); + gBS->CloseProtocol ( + Instance->UdpIo->UdpHandle, + &gEfiUdp4ProtocolGuid, + Instance->Service->Image, + Instance->Handle + ); + UdpIoFreeIo (Instance->UdpIo); + Instance->UdpIo = NULL; + Instance->Token = NULL; + } + gBS->RestoreTPL (OldTpl); - gBS->FreePool (Instance); + FreePool (Instance); return EFI_SUCCESS; }