X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Driver.c;h=fb83784da96a6403487bb8637bbe384ec41d5ee8;hp=4ce85a3f51823d86d2ac12d000b84d9c683b7d11;hb=4f0f2316ed7699e233b362b83c7fbd63c2adf97e;hpb=75dce340624dba5e4a79b2e5b2dbe943bae0d0e9 diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 4ce85a3f51..fb83784da9 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -1,7 +1,9 @@ /** @file The driver binding and service binding protocol for IP4 driver. -Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett-Packard Development Company, L.P.
+ 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 @@ -23,6 +25,30 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding = { NULL }; +BOOLEAN mIpSec2Installed = FALSE; + +/** + Callback function for IpSec2 Protocol install. + + @param[in] Event Event whose notification function is being invoked + @param[in] Context Pointer to the notification function's context + +**/ +VOID +EFIAPI +IpSec2InstalledCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Close the event so it does not get called again. + // + gBS->CloseEvent (Event); + + mIpSec2Installed = TRUE; +} + /** 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 @@ -45,6 +71,16 @@ Ip4DriverEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable ) { + VOID *Registration; + + EfiCreateProtocolNotifyEvent ( + &gEfiIpSec2ProtocolGuid, + TPL_CALLBACK, + IpSec2InstalledCallback, + NULL, + &Registration + ); + return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, @@ -121,7 +157,7 @@ Ip4DriverBindingSupported ( destroyed, it is marked as that in case the destroy failed and being called again later. - @param[in] IpSb The IP4 serviceing binding instance to clean up + @param[in] IpSb The IP4 service binding instance to clean up @retval EFI_SUCCESS The resource used by the instance are cleaned up @retval other Failed to clean up some of the resources. @@ -166,7 +202,7 @@ Ip4CreateService ( // empty resources, so if any thing goes wrong when allocating // resources, Ip4CleanService can be called to clean it up. // - IpSb = AllocatePool (sizeof (IP4_SERVICE)); + IpSb = AllocateZeroPool (sizeof (IP4_SERVICE)); if (IpSb == NULL) { return EFI_OUT_OF_RESOURCES; @@ -176,7 +212,6 @@ Ip4CreateService ( IpSb->ServiceBinding.CreateChild = Ip4ServiceBindingCreateChild; IpSb->ServiceBinding.DestroyChild = Ip4ServiceBindingDestroyChild; IpSb->State = IP4_SERVICE_UNSTARTED; - IpSb->InDestroy = FALSE; IpSb->NumChildren = 0; InitializeListHead (&IpSb->Children); @@ -209,15 +244,17 @@ Ip4CreateService ( ZeroMem (&IpSb->SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE)); - IpSb->Timer = NULL; - IpSb->Ip4Config = NULL; - IpSb->DoneEvent = NULL; - IpSb->ReconfigEvent = NULL; - IpSb->ActiveEvent = NULL; + IpSb->Timer = NULL; + + IpSb->ReconfigEvent = NULL; + + IpSb->Reconfig = FALSE; + + IpSb->MediaPresent = TRUE; // // Create various resources. First create the route table, timer - // event and MNP child. IGMP, interface's initialization depend + // event, ReconfigEvent and MNP child. IGMP, interface's initialization depend // on the MNP child. // IpSb->DefaultRouteTable = Ip4CreateRouteTable (); @@ -239,6 +276,17 @@ Ip4CreateService ( goto ON_ERROR; } + Status = gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + Ip4AutoReconfigCallBack, + IpSb, + &IpSb->ReconfigEvent + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + Status = NetLibCreateServiceChild ( Controller, ImageHandle, @@ -281,6 +329,13 @@ Ip4CreateService ( goto ON_ERROR; } + IpSb->MacString = NULL; + Status = NetLibGetMacString (IpSb->Controller, IpSb->Image, &IpSb->MacString); + + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + IpSb->DefaultInterface = Ip4CreateInterface (IpSb->Mnp, Controller, ImageHandle); if (IpSb->DefaultInterface == NULL) { @@ -290,6 +345,14 @@ Ip4CreateService ( InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link); + ZeroMem (&IpSb->Ip4Config2Instance, sizeof (IP4_CONFIG2_INSTANCE)); + + Status = Ip4Config2InitInstance (&IpSb->Ip4Config2Instance); + + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + IpSb->MaxPacketSize = IpSb->SnpMode.MaxPacketSize - sizeof (IP4_HEAD); if (NetLibGetVlanId (IpSb->Controller) != 0) { // @@ -298,9 +361,8 @@ Ip4CreateService ( IpSb->MaxPacketSize -= NET_VLAN_TAG_LEN; } IpSb->OldMaxPacketSize = IpSb->MaxPacketSize; - IpSb->MacString = NULL; - *Service = IpSb; + return EFI_SUCCESS; ON_ERROR: @@ -318,7 +380,7 @@ ON_ERROR: destroyed, it is marked as that in case the destroy failed and being called again later. - @param[in] IpSb The IP4 serviceing binding instance to clean up + @param[in] IpSb The IP4 service binding instance to clean up @retval EFI_SUCCESS The resource used by the instance are cleaned up @retval other Failed to clean up some of the resources. @@ -377,25 +439,60 @@ Ip4CleanService ( IpSb->Timer = NULL; } - if (IpSb->Ip4Config != NULL) { - IpSb->Ip4Config->Stop (IpSb->Ip4Config); + if (IpSb->ReconfigEvent != NULL) { + gBS->CloseEvent (IpSb->ReconfigEvent); - gBS->CloseProtocol ( - IpSb->Controller, - &gEfiIp4ConfigProtocolGuid, - IpSb->Image, - IpSb->Controller - ); + IpSb->ReconfigEvent = NULL; + } - gBS->CloseEvent (IpSb->DoneEvent); - gBS->CloseEvent (IpSb->ReconfigEvent); - IpSb->ActiveEvent = NULL; - IpSb->Ip4Config = NULL; + IpSb->Reconfig = FALSE; + + if (IpSb->MacString != NULL) { + FreePool (IpSb->MacString); } + Ip4Config2CleanInstance (&IpSb->Ip4Config2Instance); + return EFI_SUCCESS; } +/** + 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 +Ip4DestroyChildEntryInHandleBuffer ( + IN LIST_ENTRY *Entry, + IN VOID *Context + ) +{ + IP4_PROTOCOL *IpInstance; + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + UINTN NumberOfChildren; + EFI_HANDLE *ChildHandleBuffer; + + if (Entry == NULL || Context == NULL) { + return EFI_INVALID_PARAMETER; + } + + IpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, Link, IP4_PROTOCOL_SIGNATURE); + ServiceBinding = ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding; + NumberOfChildren = ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren; + ChildHandleBuffer = ((IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer; + + if (!NetIsInHandleBuffer (IpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) { + return EFI_SUCCESS; + } + + return ServiceBinding->DestroyChild (ServiceBinding, IpInstance->Handle); +} /** Start this driver on ControllerHandle. This service is called by the @@ -418,13 +515,20 @@ Ip4CleanService ( EFI_STATUS EFIAPI Ip4DriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, + IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) -{ - IP4_SERVICE *IpSb; - EFI_STATUS Status; +{ + EFI_STATUS Status; + IP4_SERVICE *IpSb; + EFI_IP4_CONFIG2_PROTOCOL *Ip4Cfg2; + UINTN Index; + IP4_CONFIG2_DATA_ITEM *DataItem; + + IpSb = NULL; + Ip4Cfg2 = NULL; + DataItem = NULL; // // Test for the Ip4 service binding protocol @@ -441,14 +545,17 @@ Ip4DriverBindingStart ( if (Status == EFI_SUCCESS) { return EFI_ALREADY_STARTED; } - + Status = Ip4CreateService (ControllerHandle, This->DriverBindingHandle, &IpSb); - + if (EFI_ERROR (Status)) { return Status; } + ASSERT (IpSb != NULL); + Ip4Cfg2 = &IpSb->Ip4Config2Instance.Ip4Config2; + // // Install the Ip4ServiceBinding Protocol onto ControlerHandle // @@ -456,6 +563,8 @@ Ip4DriverBindingStart ( &ControllerHandle, &gEfiIp4ServiceBindingProtocolGuid, &IpSb->ServiceBinding, + &gEfiIp4Config2ProtocolGuid, + Ip4Cfg2, NULL ); @@ -464,11 +573,40 @@ Ip4DriverBindingStart ( } // - // ready to go: start the receiving and timer + // Read the config data from NV variable again. + // The default data can be changed by other drivers. + // + Status = Ip4Config2ReadConfigData (IpSb->MacString, &IpSb->Ip4Config2Instance); + if (EFI_ERROR (Status)) { + goto UNINSTALL_PROTOCOL; + } + + // + // Consume the installed EFI_IP4_CONFIG2_PROTOCOL to set the default data items. + // + for (Index = Ip4Config2DataTypePolicy; Index < Ip4Config2DataTypeMaximum; Index++) { + DataItem = &IpSb->Ip4Config2Instance.DataItem[Index]; + if (DataItem->Data.Ptr != NULL) { + Status = Ip4Cfg2->SetData ( + Ip4Cfg2, + Index, + DataItem->DataSize, + DataItem->Data.Ptr + ); + if (EFI_ERROR(Status)) { + goto UNINSTALL_PROTOCOL; + } + } + } + + // + // Ready to go: start the receiving and timer. + // Ip4Config2SetPolicy maybe call Ip4ReceiveFrame() to set the default interface's RecvRequest first after + // Ip4Config2 instance is initialized. So, EFI_ALREADY_STARTED is the allowed return status. // Status = Ip4ReceiveFrame (IpSb->DefaultInterface, NULL, Ip4AccpetFrame, IpSb); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { goto UNINSTALL_PROTOCOL; } @@ -483,8 +621,6 @@ Ip4DriverBindingStart ( // mIp4Id = (UINT16)NET_RANDOM (NetRandomInitSeed ()); - Ip4SetVariableData (IpSb); - return Status; UNINSTALL_PROTOCOL: @@ -497,7 +633,6 @@ UNINSTALL_PROTOCOL: FREE_SERVICE: Ip4CleanService (IpSb); FreePool (IpSb); - return Status; } @@ -529,111 +664,33 @@ Ip4DriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; - IP4_SERVICE *IpSb; - IP4_PROTOCOL *IpInstance; - EFI_HANDLE NicHandle; - EFI_STATUS Status; - EFI_TPL OldTpl; - INTN State; - BOOLEAN IsArp; - - // - // IP4 driver opens the MNP child, ARP children or the IP4_CONFIG protocol - // by driver. So the ControllerHandle may be the MNP child handle, ARP child - // handle, or the NIC (UNDI) handle because IP4_CONFIG protocol is installed - // in the NIC handle. - // - // - // First, check whether it is the IP4_CONFIG protocol being uninstalled. - // IP4_CONFIG protocol is installed on the NIC handle. It isn't necessary - // to clean up the default configuration if IP4_CONFIG is being stopped. - // - Status = gBS->OpenProtocol ( - ControllerHandle, - &gEfiIp4ConfigProtocolGuid, - NULL, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL - ); - - if (Status == EFI_SUCCESS) { - // - // Retrieve the IP4 service binding protocol. If failed, it is - // likely that Ip4 ServiceBinding is uninstalled already. In this - // case, return immediately. - // - Status = gBS->OpenProtocol ( - ControllerHandle, - &gEfiIp4ServiceBindingProtocolGuid, - (VOID **) &ServiceBinding, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - IpSb = IP4_SERVICE_FROM_PROTOCOL (ServiceBinding); - - OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - - if (IpSb->Ip4Config != NULL && (IpSb->State != IP4_SERVICE_DESTROY)) { - - IpSb->Ip4Config->Stop (IpSb->Ip4Config); - - Status = gBS->CloseProtocol ( - ControllerHandle, - &gEfiIp4ConfigProtocolGuid, - IpSb->Image, - ControllerHandle - ); - - if (EFI_ERROR (Status)) { - gBS->RestoreTPL (OldTpl); - return Status; - } - - // - // If the auto configure hasn't complete, mark it as not started. - // - if (IpSb->State == IP4_SERVICE_STARTED) { - IpSb->State = IP4_SERVICE_UNSTARTED; - } - - IpSb->Ip4Config = NULL; - gBS->CloseEvent (IpSb->DoneEvent); - gBS->CloseEvent (IpSb->ReconfigEvent); - } - - gBS->RestoreTPL (OldTpl); - return EFI_SUCCESS; - } - - // - // Either MNP or ARP protocol is being uninstalled. The controller - // handle is either the MNP child or ARP child. But, the IP4's - // service binding is installed on the NIC handle. So, need to open - // the protocol info to find the NIC handle. - // - IsArp = FALSE; + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + IP4_SERVICE *IpSb; + EFI_HANDLE NicHandle; + EFI_STATUS Status; + INTN State; + LIST_ENTRY *List; + IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context; + IP4_INTERFACE *IpIf; + IP4_ROUTE_TABLE *RouteTable; + + BOOLEAN IsDhcp4; + + IsDhcp4 = FALSE; + NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiManagedNetworkProtocolGuid); - if (NicHandle == NULL) { NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid); - IsArp = TRUE; - } - - if (NicHandle == NULL) { - return EFI_DEVICE_ERROR; + if (NicHandle == NULL) { + NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4ProtocolGuid); + if (NicHandle != NULL) { + IsDhcp4 = TRUE; + } else { + return EFI_SUCCESS; + } + } } - - // - // Retrieve the IP4 service binding protocol - // + Status = gBS->OpenProtocol ( NicHandle, &gEfiIp4ServiceBindingProtocolGuid, @@ -642,103 +699,85 @@ Ip4DriverBindingStop ( NicHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); - if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } - - IpSb = IP4_SERVICE_FROM_PROTOCOL (ServiceBinding); - - OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - - if (IpSb->InDestroy) { - gBS->RestoreTPL (OldTpl); - return EFI_SUCCESS; - } - - if (IsArp) { - while (!IsListEmpty (&IpSb->Children)) { - IpInstance = NET_LIST_HEAD (&IpSb->Children, IP4_PROTOCOL, Link); - - ServiceBinding->DestroyChild (ServiceBinding, IpInstance->Handle); - } - - if (IpSb->NumChildren != 0) { - Status = EFI_DEVICE_ERROR; - goto ON_ERROR; - } - - IpSb->InDestroy = TRUE; - - State = IpSb->State; - IpSb->State = IP4_SERVICE_DESTROY; - + + IpSb = IP4_SERVICE_FROM_PROTOCOL (ServiceBinding); + + if (IsDhcp4) { + Status = Ip4Config2DestroyDhcp4 (&IpSb->Ip4Config2Instance); + gBS->CloseEvent (IpSb->Ip4Config2Instance.Dhcp4Event); + IpSb->Ip4Config2Instance.Dhcp4Event = NULL; + } else if (NumberOfChildren != 0) { + List = &IpSb->Children; + Context.ServiceBinding = ServiceBinding; + Context.NumberOfChildren = NumberOfChildren; + Context.ChildHandleBuffer = ChildHandleBuffer; + Status = NetDestroyLinkList ( + List, + Ip4DestroyChildEntryInHandleBuffer, + &Context, + NULL + ); + } else if (IpSb->DefaultInterface->ArpHandle == ControllerHandle) { + // - // Clear the variable data. + // The ARP protocol for the default interface is being uninstalled and all + // its IP child handles should have been destroyed before. So, release the + // default interface and route table, create a new one and mark it as not started. // - Ip4ClearVariableData (IpSb); - - // - // OK, clean other resources then uninstall the service binding protocol. - // - Status = Ip4CleanService (IpSb); - - if (EFI_ERROR (Status)) { - IpSb->State = State; + Ip4CancelReceive (IpSb->DefaultInterface); + Ip4FreeInterface (IpSb->DefaultInterface, NULL); + Ip4FreeRouteTable (IpSb->DefaultRouteTable); + + IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image); + if (IpIf == NULL) { goto ON_ERROR; } + RouteTable = Ip4CreateRouteTable (); + if (RouteTable == NULL) { + Ip4FreeInterface (IpIf, NULL); + goto ON_ERROR;; + } + + IpSb->DefaultInterface = IpIf; + InsertHeadList (&IpSb->Interfaces, &IpIf->Link); + IpSb->DefaultRouteTable = RouteTable; + Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb); - gBS->UninstallProtocolInterface ( - NicHandle, - &gEfiIp4ServiceBindingProtocolGuid, - ServiceBinding - ); - - FreePool (IpSb); - } else if (NumberOfChildren == 0) { - IpSb->InDestroy = TRUE; + IpSb->State = IP4_SERVICE_UNSTARTED; + } else if (IsListEmpty (&IpSb->Children)) { State = IpSb->State; IpSb->State = IP4_SERVICE_DESTROY; - // - // Clear the variable data. - // - Ip4ClearVariableData (IpSb); - // // OK, clean other resources then uninstall the service binding protocol. // Status = Ip4CleanService (IpSb); - if (EFI_ERROR (Status)) { IpSb->State = State; goto ON_ERROR; } - gBS->UninstallProtocolInterface ( + gBS->UninstallMultipleProtocolInterfaces ( NicHandle, &gEfiIp4ServiceBindingProtocolGuid, - ServiceBinding + ServiceBinding, + &gEfiIp4Config2ProtocolGuid, + &IpSb->Ip4Config2Instance.Ip4Config2, + NULL ); - - FreePool (IpSb); - } else { - - while (!IsListEmpty (&IpSb->Children)) { - IpInstance = NET_LIST_HEAD (&IpSb->Children, IP4_PROTOCOL, Link); - - ServiceBinding->DestroyChild (ServiceBinding, IpInstance->Handle); - } - - if (IpSb->NumChildren != 0) { - Status = EFI_DEVICE_ERROR; + + if (gIp4ControllerNameTable != NULL) { + FreeUnicodeStringTable (gIp4ControllerNameTable); + gIp4ControllerNameTable = NULL; } + FreePool (IpSb); } ON_ERROR: - - gBS->RestoreTPL (OldTpl); return Status; } @@ -935,6 +974,15 @@ Ip4ServiceBindingDestroyChild ( ChildHandle ); + if (IpInstance->Interface != NULL && IpInstance->Interface->Arp != NULL) { + gBS->CloseProtocol ( + IpInstance->Interface->ArpHandle, + &gEfiArpProtocolGuid, + gIp4DriverBinding.DriverBindingHandle, + ChildHandle + ); + } + // // Uninstall the IP4 protocol first. Many thing happens during // this: @@ -949,20 +997,18 @@ Ip4ServiceBindingDestroyChild ( // will be called back before preceeding. If any packets not recycled, // that means there is a resource leak. // + gBS->RestoreTPL (OldTpl); Status = gBS->UninstallProtocolInterface ( ChildHandle, &gEfiIp4ProtocolGuid, &IpInstance->Ip4Proto ); - + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (EFI_ERROR (Status)) { goto ON_ERROR; } Status = Ip4CleanProtocol (IpInstance); - - Ip4SetVariableData (IpSb); - if (EFI_ERROR (Status)) { gBS->InstallMultipleProtocolInterfaces ( &ChildHandle,