X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FDhcp4Dxe%2FDhcp4Driver.c;h=5ccbefd4321373257a73f0a68ee5f0338cbf34e2;hp=d14697262cb18beab134b5574eec1406921d9d12;hb=a4df47f1090a723108cdd7ae45c9adce8ab5bcca;hpb=da1d02010d73465a9c2b21f619e8c01cb00bd1fa diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c index d14697262c..5ccbefd432 100644 --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2006 - 2007, Intel Corporation +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 @@ -9,14 +9,6 @@ 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. - -Module Name: - - Dhcp4Driver.c - -Abstract: - - **/ #include "Dhcp4Impl.h" @@ -31,58 +23,59 @@ EFI_DRIVER_BINDING_PROTOCOL gDhcp4DriverBinding = { NULL }; -EFI_SERVICE_BINDING_PROTOCOL mDhcp4ServiceBindingTemplete = { +EFI_SERVICE_BINDING_PROTOCOL mDhcp4ServiceBindingTemplate = { Dhcp4ServiceBindingCreateChild, Dhcp4ServiceBindingDestroyChild }; +/** + 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. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + +**/ EFI_STATUS EFIAPI Dhcp4DriverEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) -/*++ - -Routine Description: - - Entry point of the DHCP driver to install various protocols. - -Arguments: - - ImageHandle - The driver's image handle - SystemTable - The system table - -Returns: - - EFI_SUCCESS - All the related protocols are installed. - Others - Failed to install the protocols. - ---*/ { - return EfiLibInstallAllDriverProtocols ( + return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, &gDhcp4DriverBinding, ImageHandle, &gDhcp4ComponentName, - NULL, - NULL + &gDhcp4ComponentName2 ); } /** - Test to see if DHCP driver supports the ControllerHandle. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to test - @param RemainingDevicePath Optional parameter use to pick a specific child - device to start. - - @retval EFI_SUCCES This driver supports this device - @retval other This driver does not support this device + Test to see if this driver supports ControllerHandle. This service + is called by the EFI boot service ConnectController(). In + order to make drivers as small as possible, there are a few calling + restrictions for this service. ConnectController() must + follow these calling restrictions. If any other agent wishes to call + Supported() it must also follow these calling restrictions. + + @param[in] This Protocol instance pointer. + @param[in] ControllerHandle Handle of device to test + @param[in] RemainingDevicePath Optional parameter use to pick a specific child + device to start. + + @retval EFI_SUCCESS This driver supports this device + @retval EFI_ALREADY_STARTED This driver is already running on this device + @retval other This driver does not support this device **/ EFI_STATUS @@ -113,8 +106,8 @@ Dhcp4DriverBindingSupported ( Configure the default UDP child to receive all the DHCP traffics on this network interface. - @param UdpIo The UDP IO port to configure - @param Context The context to the function + @param[in] UdpIo The UDP IO port to configure + @param[in] Context The context to the function @retval EFI_SUCCESS The UDP IO port is successfully configured. @retval Others Failed to configure the UDP child. @@ -142,9 +135,9 @@ DhcpConfigUdpIo ( UdpConfigData.StationPort = DHCP_CLIENT_PORT; UdpConfigData.RemotePort = DHCP_SERVER_PORT; - NetZeroMem (&UdpConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS)); - NetZeroMem (&UdpConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); - NetZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&UdpConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&UdpConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS)); + ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS)); return UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);; } @@ -153,12 +146,12 @@ DhcpConfigUdpIo ( /** Destory the DHCP service. The Dhcp4 service may be partly initialized, - or partly destoried. If a resource is destoried, it is marked as so in - case the destory failed and being called again later. + or partly destroyed. If a resource is destroyed, it is marked as so in + case the destroy failed and being called again later. - @param DhcpSb The DHCP service instance to destory. + @param[in] DhcpSb The DHCP service instance to destory. - @retval EFI_SUCCESS The DHCP service is successfully closed. + @retval EFI_SUCCESS Always return success. **/ EFI_STATUS @@ -188,14 +181,15 @@ Dhcp4CloseService ( /** Create a new DHCP service binding instance for the controller. - @param Controller The controller to install DHCP service binding - protocol onto - @param ImageHandle The driver's image handle - @param Service The variable to receive the created DHCP service - instance. + @param[in] Controller The controller to install DHCP service binding + protocol onto + @param[in] ImageHandle The driver's image handle + @param[out] Service The variable to receive the created DHCP service + instance. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource . @retval EFI_SUCCESS The DHCP service instance is created. + @retval other Other error occurs. **/ EFI_STATUS @@ -209,22 +203,25 @@ Dhcp4CreateService ( EFI_STATUS Status; *Service = NULL; - DhcpSb = NetAllocateZeroPool (sizeof (DHCP_SERVICE)); + DhcpSb = AllocateZeroPool (sizeof (DHCP_SERVICE)); if (DhcpSb == NULL) { return EFI_OUT_OF_RESOURCES; } DhcpSb->Signature = DHCP_SERVICE_SIGNATURE; - DhcpSb->ServiceBinding = mDhcp4ServiceBindingTemplete; DhcpSb->ServiceState = DHCP_UNCONFIGED; DhcpSb->InDestory = FALSE; DhcpSb->Controller = Controller; DhcpSb->Image = ImageHandle; - NetListInit (&DhcpSb->Children); + InitializeListHead (&DhcpSb->Children); DhcpSb->DhcpState = Dhcp4Stopped; DhcpSb->Xid = NET_RANDOM (NetRandomInitSeed ()); - + CopyMem ( + &DhcpSb->ServiceBinding, + &mDhcp4ServiceBindingTemplate, + sizeof (EFI_SERVICE_BINDING_PROTOCOL) + ); // // Create various resources, UdpIo, Timer, and get Mac address // @@ -256,23 +253,28 @@ Dhcp4CreateService ( ON_ERROR: Dhcp4CloseService (DhcpSb); - NetFreePool (DhcpSb); + FreePool (DhcpSb); return Status; } /** - Start this driver on ControllerHandle. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to bind driver to - @param RemainingDevicePath Optional parameter use to pick a specific child - device to start. - - @retval EFI_SUCCES This driver is added to ControllerHandle - @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle - @retval other This driver does not support this device + Start this driver on ControllerHandle. This service is called by the + EFI boot service ConnectController(). In order to make + drivers as small as possible, there are a few calling restrictions for + this service. ConnectController() must follow these + calling restrictions. If any other agent wishes to call Start() it + must also follow these calling restrictions. + + @param[in] This Protocol instance pointer. + @param[in] ControllerHandle Handle of device to bind driver to + @param[in] RemainingDevicePath Optional parameter use to pick a specific child + device to start. + + @retval EFI_SUCCESS This driver is added to ControllerHandle + @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle + @retval other This driver does not support this device **/ EFI_STATUS @@ -332,22 +334,27 @@ Dhcp4DriverBindingStart ( ON_ERROR: Dhcp4CloseService (DhcpSb); - NetFreePool (DhcpSb); + FreePool (DhcpSb); return Status; } /** - Stop this driver on ControllerHandle. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to stop driver on - @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number - of children is zero stop the entire bus driver. - @param ChildHandleBuffer List of Child Handles to Stop. - - @retval EFI_SUCCES This driver is removed ControllerHandle - @retval other This driver was not removed from this device + Stop this driver on ControllerHandle. This service is called by the + EFI boot service DisconnectController(). In order to + make drivers as small as possible, there are a few calling + 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 + children is zero stop the entire bus driver. + @param[in] ChildHandleBuffer List of Child Handles to Stop. + + @retval EFI_SUCCESS This driver is removed ControllerHandle + @retval other This driver was not removed from this device **/ EFI_STATUS @@ -373,7 +380,7 @@ Dhcp4DriverBindingStop ( NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid); if (NicHandle == NULL) { - return EFI_SUCCESS; + return EFI_DEVICE_ERROR; } Status = gBS->OpenProtocol ( @@ -395,88 +402,87 @@ Dhcp4DriverBindingStop ( return EFI_SUCCESS; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); - DhcpSb->InDestory = TRUE; + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - // - // Don't use NET_LIST_FOR_EACH_SAFE here, Dhcp4ServiceBindingDestoryChild - // may cause other child to be deleted. - // - while (!NetListIsEmpty (&DhcpSb->Children)) { - Instance = NET_LIST_HEAD (&DhcpSb->Children, DHCP_PROTOCOL, Link); - Dhcp4ServiceBindingDestroyChild (ServiceBinding, Instance->Handle); - } + if (NumberOfChildren == 0) { - if (DhcpSb->NumChildren != 0) { - Status = EFI_DEVICE_ERROR; - goto ON_ERROR; - } - - DhcpSb->ServiceState = DHCP_DESTORY; + DhcpSb->InDestory = TRUE; + DhcpSb->ServiceState = DHCP_DESTORY; - Status = gBS->UninstallProtocolInterface ( - NicHandle, - &gEfiDhcp4ServiceBindingProtocolGuid, - ServiceBinding - ); + gBS->UninstallProtocolInterface ( + NicHandle, + &gEfiDhcp4ServiceBindingProtocolGuid, + ServiceBinding + ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; + Dhcp4CloseService (DhcpSb); + + 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 (DhcpSb->NumChildren != 0) { + Status = EFI_DEVICE_ERROR; + } } - Dhcp4CloseService (DhcpSb); - NET_RESTORE_TPL (OldTpl); - - NetFreePool (DhcpSb); - return EFI_SUCCESS; + gBS->RestoreTPL (OldTpl); -ON_ERROR: - DhcpSb->InDestory = FALSE; - NET_RESTORE_TPL (OldTpl); return Status; } /** - Initialize a new DHCP child + Initialize a new DHCP instance. @param DhcpSb The dhcp service instance @param Instance The dhcp instance to initialize - @return None - **/ VOID DhcpInitProtocol ( - IN DHCP_SERVICE *DhcpSb, - IN DHCP_PROTOCOL *Instance + IN DHCP_SERVICE *DhcpSb, + IN OUT DHCP_PROTOCOL *Instance ) { Instance->Signature = DHCP_PROTOCOL_SIGNATURE; CopyMem (&Instance->Dhcp4Protocol, &mDhcp4ProtocolTemplate, sizeof (Instance->Dhcp4Protocol)); - NetListInit (&Instance->Link); + InitializeListHead (&Instance->Link); Instance->Handle = NULL; Instance->Service = DhcpSb; Instance->InDestory = FALSE; Instance->CompletionEvent = NULL; Instance->RenewRebindEvent = NULL; Instance->Token = NULL; + Instance->UdpIo = NULL; + NetbufQueInit (&Instance->ResponseQueue); } /** - Creates a child handle with a set of DHCP4 services. - - @param This Protocol instance pointer. - @param ChildHandle Pointer to the handle of the child to create. If - it is NULL, then a new handle is created. If it - is not NULL, then the DHCP4 services are added to - the existing child handle. - - @retval EFI_SUCCES The child handle was created with the DHCP4 - services - @retval EFI_OUT_OF_RESOURCES There are not enough resources to create the child - @retval other The child handle was not created + 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. + 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 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 + the child + @retval other The child handle was not created **/ EFI_STATUS @@ -496,7 +502,7 @@ Dhcp4ServiceBindingCreateChild ( return EFI_INVALID_PARAMETER; } - Instance = NetAllocatePool (sizeof (*Instance)); + Instance = AllocatePool (sizeof (*Instance)); if (Instance == NULL) { return EFI_OUT_OF_RESOURCES; @@ -516,7 +522,7 @@ Dhcp4ServiceBindingCreateChild ( ); if (EFI_ERROR (Status)) { - NetFreePool (Instance); + FreePool (Instance); return Status; } @@ -541,34 +547,37 @@ Dhcp4ServiceBindingCreateChild ( NULL ); - NetFreePool (Instance); + FreePool (Instance); return Status; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - NetListInsertTail (&DhcpSb->Children, &Instance->Link); + InsertTailList (&DhcpSb->Children, &Instance->Link); DhcpSb->NumChildren++; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; } /** - Destroys a child handle with a set of DHCP4 services. - - @param This Protocol instance pointer. - @param ChildHandle Handle of the child to destroy - - @retval EFI_SUCCES The DHCP4 service is removed from the child handle - @retval EFI_UNSUPPORTED The child handle does not support the DHCP4 - service - @retval EFI_INVALID_PARAMETER Child handle is not a valid EFI Handle. - @retval EFI_ACCESS_DENIED The child handle could not be destroyed because - its DHCP4 services are being used. - @retval other The child handle was not destroyed + 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 + last protocol on ChildHandle, then ChildHandle is destroyed. + + @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. + @param ChildHandle Handle of the child to destroy + + @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_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 **/ EFI_STATUS @@ -612,8 +621,8 @@ Dhcp4ServiceBindingDestroyChild ( } // - // A child can be destoried more than once. For example, - // Dhcp4DriverBindingStop will destory all of its children. + // 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 // dhcp child it opens. // @@ -621,7 +630,7 @@ Dhcp4ServiceBindingDestroyChild ( return EFI_SUCCESS; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); Instance->InDestory = TRUE; // @@ -646,7 +655,7 @@ Dhcp4ServiceBindingDestroyChild ( if (EFI_ERROR (Status)) { Instance->InDestory = FALSE; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } @@ -654,11 +663,11 @@ Dhcp4ServiceBindingDestroyChild ( DhcpYieldControl (DhcpSb); } - NetListRemoveEntry (&Instance->Link); + RemoveEntryList (&Instance->Link); DhcpSb->NumChildren--; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); - NetFreePool (Instance); + FreePool (Instance); return EFI_SUCCESS; }