]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/DnsDxe/DnsDhcp.c
NetworkPkg: Clean up source files
[mirror_edk2.git] / NetworkPkg / DnsDxe / DnsDhcp.c
index a9fdfb65b4f61b04651d8da7a1cda5e1a63485ca..df8f615911bdb78f072e18a02d6745759d2d91d9 100644 (file)
 /** @file\r
 Functions implementation related with DHCPv4/v6 for DNS driver.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
-This software and associated documentation (if any) is furnished\r
-under a license and may only be used or copied in accordance\r
-with the terms of the license. Except as permitted by such\r
-license, no part of this software or documentation may be\r
-reproduced, stored in a retrieval system, or transmitted in any\r
-form or by any means without the express written consent of\r
-Intel Corporation.\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
 \r
-**/\r
-\r
-#include "DnsImpl.h"\r
-\r
-/**\r
-  The callback function for the timer event used to get map.\r
-\r
-  @param[in] Event    The event this function is registered to.\r
-  @param[in] Context  The context registered to the event.\r
-**/\r
-VOID\r
-EFIAPI\r
-TimeoutToGetMap (\r
-  IN EFI_EVENT      Event,\r
-  IN VOID           *Context\r
-  )\r
-{\r
-  *((BOOLEAN *) Context) = TRUE;\r
-  return ;\r
-}\r
-\r
-/**\r
-  Create an IP child, use it to start the auto configuration, then destroy it.\r
-\r
-  @param[in] Controller       The controller which has the service installed.\r
-  @param[in] Image            The image handle used to open service.\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  @retval EFI_SUCCESS         The configuration is done.\r
-  @retval Others              Other errors as indicated.\r
 **/\r
-EFI_STATUS\r
-EFIAPI\r
-DnsStartIp4(\r
-  IN  EFI_HANDLE            Controller,\r
-  IN  EFI_HANDLE            Image\r
-  )\r
-{\r
-  EFI_IP4_PROTOCOL              *Ip4;\r
-  EFI_HANDLE                    Ip4Handle;\r
-  EFI_EVENT                     TimerToGetMap;\r
-  EFI_IP4_CONFIG_DATA           Ip4ConfigData;\r
-  EFI_IP4_MODE_DATA             Ip4Mode;\r
-  EFI_STATUS                    Status;\r
-\r
-  BOOLEAN                       Timeout;\r
 \r
-  //\r
-  // Get the Ip4ServiceBinding Protocol\r
-  //\r
-  Ip4Handle     = NULL;\r
-  Ip4           = NULL;\r
-  TimerToGetMap = NULL;\r
-  \r
-  Timeout      = FALSE;\r
-\r
-  Status = NetLibCreateServiceChild (\r
-             Controller,\r
-             Image,\r
-             &gEfiIp4ServiceBindingProtocolGuid,\r
-             &Ip4Handle\r
-             );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->OpenProtocol (\r
-                 Ip4Handle,\r
-                 &gEfiIp4ProtocolGuid,\r
-                 (VOID **) &Ip4,\r
-                 Controller,\r
-                 Image,\r
-                 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                 );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  Ip4ConfigData.DefaultProtocol          = EFI_IP_PROTO_ICMP;\r
-  Ip4ConfigData.AcceptAnyProtocol        = FALSE;\r
-  Ip4ConfigData.AcceptIcmpErrors         = FALSE;\r
-  Ip4ConfigData.AcceptBroadcast          = FALSE;\r
-  Ip4ConfigData.AcceptPromiscuous        = FALSE;\r
-  Ip4ConfigData.UseDefaultAddress        = TRUE;\r
-  ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));\r
-  ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-  Ip4ConfigData.TypeOfService            = 0;\r
-  Ip4ConfigData.TimeToLive               = 1;\r
-  Ip4ConfigData.DoNotFragment            = FALSE;\r
-  Ip4ConfigData.RawData                  = FALSE;\r
-  Ip4ConfigData.ReceiveTimeout           = 0;\r
-  Ip4ConfigData.TransmitTimeout          = 0;\r
-\r
-  Status = Ip4->Configure (Ip4, &Ip4ConfigData);\r
-\r
-  if (Status == EFI_NO_MAPPING) {\r
-    Status  = gBS->CreateEvent (\r
-                    EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
-                    TPL_CALLBACK,\r
-                    TimeoutToGetMap,\r
-                    &Timeout,\r
-                    &TimerToGetMap\r
-                    );\r
-    \r
-    if (EFI_ERROR (Status)) {\r
-      goto ON_EXIT;\r
-    }\r
-    \r
-    Status = gBS->SetTimer (\r
-                   TimerToGetMap,\r
-                   TimerRelative,\r
-                   MultU64x32 (10000000, 5)\r
-                   );\r
-    \r
-    if (EFI_ERROR (Status)) {\r
-      goto ON_EXIT;\r
-    }\r
-    \r
-    while (!Timeout) {\r
-      Ip4->Poll (Ip4);\r
-  \r
-      if (!EFI_ERROR (Ip4->GetModeData (Ip4, &Ip4Mode, NULL, NULL)) && \r
-          Ip4Mode.IsConfigured) {       \r
-        break;\r
-      }\r
-    }\r
-\r
-    if (Timeout) {\r
-      Status = EFI_DEVICE_ERROR;\r
-    }\r
-  }\r
-  \r
-ON_EXIT: \r
-\r
-  if (TimerToGetMap != NULL) {\r
-    gBS->SetTimer (TimerToGetMap, TimerCancel, 0);\r
-    gBS->CloseEvent (TimerToGetMap);\r
-  }\r
-\r
-  NetLibDestroyServiceChild (\r
-    Controller,\r
-    Image,\r
-    &gEfiIp4ServiceBindingProtocolGuid,\r
-    Ip4Handle\r
-    );\r
-  \r
-  return Status;\r
-}\r
+#include "DnsImpl.h"\r
 \r
 /**\r
   This function initialize the DHCP4 message instance.\r
@@ -194,7 +48,7 @@ DnsInitSeedPacket (
 }\r
 \r
 /**\r
-  The common notify function. \r
+  The common notify function.\r
 \r
   @param[in]  Event   The event signaled.\r
   @param[in]  Context The context.\r
@@ -295,16 +149,16 @@ ParseDhcp4Ack (
   }\r
 \r
   gBS->FreePool (OptionList);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
 /**\r
-  EFI_DHCP6_INFO_CALLBACK is provided by the consumer of the EFI DHCPv6 Protocol \r
+  EFI_DHCP6_INFO_CALLBACK is provided by the consumer of the EFI DHCPv6 Protocol\r
   instance to intercept events that occurs in the DHCPv6 Information Request\r
   exchange process.\r
 \r
-  @param  This                  Pointer to the EFI_DHCP6_PROTOCOL instance that \r
+  @param  This                  Pointer to the EFI_DHCP6_PROTOCOL instance that\r
                                 is used to configure this  callback function.\r
   @param  Context               Pointer to the context that is initialized in\r
                                 the EFI_DHCP6_PROTOCOL.InfoRequest().\r
@@ -332,11 +186,11 @@ ParseDhcp6Ack (
   EFI_IPv6_ADDRESS            *ServerList;\r
   UINT32                      Index;\r
   UINT32                      Count;\r
\r
+\r
   OptionCount = 0;\r
   ServerCount = 0;\r
   ServerList  = NULL;\r
-  \r
+\r
   Status      = This->Parse (This, Packet, &OptionCount, NULL);\r
   if (Status != EFI_BUFFER_TOO_SMALL) {\r
     return EFI_DEVICE_ERROR;\r
@@ -352,7 +206,7 @@ ParseDhcp6Ack (
     gBS->FreePool (OptionList);\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
+\r
   DnsServerInfor = (DNS6_SERVER_INFOR *) Context;\r
 \r
   for (Index = 0; Index < OptionCount; Index++) {\r
@@ -369,7 +223,7 @@ ParseDhcp6Ack (
         gBS->FreePool (OptionList);\r
         return Status;\r
       }\r
-      \r
+\r
       ServerCount = OptionList[Index]->OpLen/16;\r
       ServerList = AllocatePool (ServerCount * sizeof (EFI_IPv6_ADDRESS));\r
       if (ServerList == NULL) {\r
@@ -387,7 +241,7 @@ ParseDhcp6Ack (
   }\r
 \r
   gBS->FreePool (OptionList);\r
-  \r
+\r
   return Status;\r
 \r
 }\r
@@ -415,11 +269,11 @@ GetDns4ServerFromDhcp4 (
   EFI_STATUS                          Status;\r
   EFI_HANDLE                          Image;\r
   EFI_HANDLE                          Controller;\r
-  BOOLEAN                             MediaPresent;\r
-  EFI_HANDLE                          MnpChildHandle;  \r
+  EFI_STATUS                          MediaStatus;\r
+  EFI_HANDLE                          MnpChildHandle;\r
   EFI_MANAGED_NETWORK_PROTOCOL        *Mnp;\r
   EFI_MANAGED_NETWORK_CONFIG_DATA     MnpConfigData;\r
-  EFI_HANDLE                          Dhcp4Handle;  \r
+  EFI_HANDLE                          Dhcp4Handle;\r
   EFI_DHCP4_PROTOCOL                  *Dhcp4;\r
   EFI_IP4_CONFIG2_PROTOCOL            *Ip4Config2;\r
   UINTN                               DataSize;\r
@@ -432,13 +286,13 @@ GetDns4ServerFromDhcp4 (
   EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN    Token;\r
   BOOLEAN                             IsDone;\r
   UINTN                               Index;\r
-  \r
+\r
   Image                      = Instance->Service->ImageHandle;\r
   Controller                 = Instance->Service->ControllerHandle;\r
 \r
   MnpChildHandle             = NULL;\r
   Mnp                        = NULL;\r
-  \r
+\r
   Dhcp4Handle                = NULL;\r
   Dhcp4                      = NULL;\r
 \r
@@ -450,11 +304,11 @@ GetDns4ServerFromDhcp4 (
   ZeroMem ((UINT8 *) ParaList, sizeof (ParaList));\r
 \r
   ZeroMem (&MnpConfigData, sizeof (EFI_MANAGED_NETWORK_CONFIG_DATA));\r
-  \r
+\r
   ZeroMem (&DnsServerInfor, sizeof (DNS4_SERVER_INFOR));\r
-  \r
+\r
   ZeroMem (&Token, sizeof (EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN));\r
-  \r
+\r
   DnsServerInfor.ServerCount = DnsServerCount;\r
 \r
   IsDone = FALSE;\r
@@ -462,22 +316,12 @@ GetDns4ServerFromDhcp4 (
   //\r
   // Check media.\r
   //\r
-  MediaPresent = TRUE;\r
-  NetLibDetectMedia (Controller, &MediaPresent);\r
-  if (!MediaPresent) {\r
+  MediaStatus = EFI_SUCCESS;\r
+  NetLibDetectMediaWaitTimeout (Controller, DNS_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);\r
+  if (MediaStatus != EFI_SUCCESS) {\r
     return EFI_NO_MEDIA;\r
   }\r
 \r
-  //\r
-  // Start the auto configuration if UseDefaultSetting.\r
-  //\r
-  if (Instance->Dns4CfgData.UseDefaultSetting) {\r
-    Status = DnsStartIp4 (Controller, Image);\r
-    if (EFI_ERROR(Status)) {\r
-      return Status;\r
-    }\r
-  }\r
-  \r
   //\r
   // Create a Mnp child instance, get the protocol and config for it.\r
   //\r
@@ -502,7 +346,7 @@ GetDns4ServerFromDhcp4 (
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   MnpConfigData.ReceivedQueueTimeoutValue = 0;\r
   MnpConfigData.TransmitQueueTimeoutValue = 0;\r
   MnpConfigData.ProtocolTypeFilter        = IP4_ETHER_PROTO;\r
@@ -518,7 +362,7 @@ GetDns4ServerFromDhcp4 (
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   //\r
   // Create a DHCP4 child instance and get the protocol.\r
   //\r
@@ -551,7 +395,7 @@ GetDns4ServerFromDhcp4 (
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   Status = Ip4Config2->GetData (Ip4Config2, Ip4Config2DataTypeInterfaceInfo, &DataSize, Data);\r
   if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
     goto ON_EXIT;\r
@@ -569,7 +413,7 @@ GetDns4ServerFromDhcp4 (
   }\r
 \r
   InterfaceInfo = (EFI_IP4_CONFIG2_INTERFACE_INFO *)Data;\r
-  \r
+\r
   //\r
   // Build required Token.\r
   //\r
@@ -583,13 +427,13 @@ GetDns4ServerFromDhcp4 (
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);\r
-  \r
+\r
   Token.RemotePort = 67;\r
 \r
   Token.ListenPointCount = 1;\r
-  \r
+\r
   Token.ListenPoints = AllocateZeroPool (Token.ListenPointCount * sizeof (EFI_DHCP4_LISTEN_POINT));\r
   if (Token.ListenPoints == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -603,9 +447,9 @@ GetDns4ServerFromDhcp4 (
     CopyMem (&(Token.ListenPoints[0].ListenAddress), &(Instance->Dns4CfgData.StationIp), sizeof (EFI_IPv4_ADDRESS));\r
     CopyMem (&(Token.ListenPoints[0].SubnetMask), &(Instance->Dns4CfgData.SubnetMask), sizeof (EFI_IPv4_ADDRESS));\r
   }\r
-  \r
+\r
   Token.ListenPoints[0].ListenPort = 68;\r
-  \r
+\r
   Token.TimeoutValue = DNS_TIME_TO_GETMAP;\r
 \r
   DnsInitSeedPacket (&SeedPacket, InterfaceInfo);\r
@@ -615,35 +459,35 @@ GetDns4ServerFromDhcp4 (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   ParaList[0]->OpCode  = DHCP4_TAG_TYPE;\r
   ParaList[0]->Length  = 1;\r
-  ParaList[0]->Data[0] = DHCP4_MSG_INFORM;\r
-  \r
+  ParaList[0]->Data[0] = DHCP4_MSG_REQUEST;\r
+\r
   ParaList[1] = AllocateZeroPool (sizeof (EFI_DHCP4_PACKET_OPTION));\r
   if (ParaList[1] == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   ParaList[1]->OpCode  = DHCP4_TAG_PARA_LIST;\r
   ParaList[1]->Length  = 1;\r
   ParaList[1]->Data[0] = DHCP4_TAG_DNS_SERVER;\r
 \r
-  Status = Dhcp4->Build (Dhcp4, &SeedPacket, 0, NULL, 2, ParaList, &Token.Packet); \r
+  Status = Dhcp4->Build (Dhcp4, &SeedPacket, 0, NULL, 2, ParaList, &Token.Packet);\r
 \r
   Token.Packet->Dhcp4.Header.Xid      = HTONL(NET_RANDOM (NetRandomInitSeed ()));\r
-  \r
+\r
   Token.Packet->Dhcp4.Header.Reserved = HTONS ((UINT16)0x8000);\r
-  \r
+\r
   if (Instance->Dns4CfgData.UseDefaultSetting) {\r
     CopyMem (&(Token.Packet->Dhcp4.Header.ClientAddr), &(InterfaceInfo->StationAddress), sizeof (EFI_IPv4_ADDRESS));\r
   } else {\r
     CopyMem (&(Token.Packet->Dhcp4.Header.ClientAddr), &(Instance->Dns4CfgData.StationIp), sizeof (EFI_IPv4_ADDRESS));\r
   }\r
-  \r
-  CopyMem (Token.Packet->Dhcp4.Header.ClientHwAddr, &(InterfaceInfo->HwAddress), InterfaceInfo->HwAddressSize); \r
-  \r
+\r
+  CopyMem (Token.Packet->Dhcp4.Header.ClientHwAddr, &(InterfaceInfo->HwAddress), InterfaceInfo->HwAddressSize);\r
+\r
   Token.Packet->Dhcp4.Header.HwAddrLen = (UINT8)(InterfaceInfo->HwAddressSize);\r
 \r
   //\r
@@ -660,7 +504,7 @@ GetDns4ServerFromDhcp4 (
   do {\r
     Status = Mnp->Poll (Mnp);\r
   } while (!IsDone);\r
-  \r
+\r
   //\r
   // Parse the ACK to get required information if received done.\r
   //\r
@@ -676,7 +520,7 @@ GetDns4ServerFromDhcp4 (
   } else {\r
     Status = Token.Status;\r
   }\r
-  \r
+\r
 ON_EXIT:\r
 \r
   if (Data != NULL) {\r
@@ -696,15 +540,15 @@ ON_EXIT:
   if (Token.Packet) {\r
     FreePool (Token.Packet);\r
   }\r
-  \r
+\r
   if (Token.ResponseList != NULL) {\r
     FreePool (Token.ResponseList);\r
   }\r
-  \r
+\r
   if (Token.CompletionEvent != NULL) {\r
     gBS->CloseEvent (Token.CompletionEvent);\r
   }\r
-  \r
+\r
   if (Dhcp4 != NULL) {\r
     Dhcp4->Stop (Dhcp4);\r
     Dhcp4->Configure (Dhcp4, NULL);\r
@@ -716,7 +560,7 @@ ON_EXIT:
            Controller\r
            );\r
   }\r
-  \r
+\r
   if (Dhcp4Handle != NULL) {\r
     NetLibDestroyServiceChild (\r
       Controller,\r
@@ -736,14 +580,14 @@ ON_EXIT:
            Controller\r
            );\r
   }\r
-  \r
+\r
   NetLibDestroyServiceChild (\r
     Controller,\r
     Image,\r
     &gEfiManagedNetworkServiceBindingProtocolGuid,\r
     MnpChildHandle\r
     );\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -776,7 +620,7 @@ GetDns6ServerFromDhcp6 (
   EFI_DHCP6_PACKET_OPTION   *Oro;\r
   EFI_DHCP6_RETRANSMISSION  InfoReqReXmit;\r
   EFI_EVENT                 Timer;\r
-  BOOLEAN                   MediaPresent;\r
+  EFI_STATUS                MediaStatus;\r
   DNS6_SERVER_INFOR         DnsServerInfor;\r
 \r
   Dhcp6Handle = NULL;\r
@@ -791,9 +635,9 @@ GetDns6ServerFromDhcp6 (
   //\r
   // Check media status before doing DHCP.\r
   //\r
-  MediaPresent = TRUE;\r
-  NetLibDetectMedia (Controller, &MediaPresent);\r
-  if (!MediaPresent) {\r
+  MediaStatus = EFI_SUCCESS;\r
+  NetLibDetectMediaWaitTimeout (Controller, DNS_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);\r
+  if (MediaStatus != EFI_SUCCESS) {\r
     return EFI_NO_MEDIA;\r
   }\r
 \r
@@ -885,14 +729,14 @@ GetDns6ServerFromDhcp6 (
       }\r
     } while (TimerStatus == EFI_NOT_READY);\r
   }\r
-  \r
+\r
   *DnsServerList  = DnsServerInfor.ServerList;\r
 \r
 ON_EXIT:\r
 \r
   if (Oro != NULL) {\r
     FreePool (Oro);\r
-  }  \r
+  }\r
 \r
   if (Timer != NULL) {\r
     gBS->CloseEvent (Timer);\r
@@ -915,6 +759,6 @@ ON_EXIT:
     );\r
 \r
   return Status;\r
-  \r
+\r
 }\r
 \r