]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Fix DHCP TransmitReceive EFI_NO_MAPPING return in DnsDxe
authorJiaxin Wu <jiaxin.wu@intel.com>
Thu, 20 Aug 2015 07:01:47 +0000 (07:01 +0000)
committerjiaxinwu <jiaxinwu@Edk2>
Thu, 20 Aug 2015 07:01:47 +0000 (07:01 +0000)
v2:
* Add Timeout check, if time out, return EFI_DEVICE_ERROR.

If the default station address is not available, TransmitReceive
function will return EFI_NO_MAPPING. DNS driver should handle this
case. This issue is caused by the r18201 fix.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Zhang Lubo <lubo.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Lubo Zhang <lubo.zhang@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18248 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/DnsDxe/DnsDhcp.c
NetworkPkg/DnsDxe/DnsDxe.inf

index 1cc337f0cfdca84b5878f253384c432e7331569a..a9fdfb65b4f61b04651d8da7a1cda5e1a63485ca 100644 (file)
@@ -14,6 +14,152 @@ Intel Corporation.
 \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
+\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
+\r
 /**\r
   This function initialize the DHCP4 message instance.\r
 \r
@@ -322,6 +468,16 @@ GetDns4ServerFromDhcp4 (
     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
index bed0bd399ed6a6b8e85aac12b4d88fad31f232f5..d63bbbebc47e5ddc60da23c71645a3318b124411 100644 (file)
@@ -61,6 +61,8 @@
   gEfiDhcp4ServiceBindingProtocolGuid             ## SOMETIMES_CONSUMES\r
   gEfiDhcp4ProtocolGuid                           ## SOMETIMES_CONSUMES\r
   gEfiIp4Config2ProtocolGuid                      ## SOMETIMES_CONSUMES\r
+  gEfiIp4ServiceBindingProtocolGuid               ## SOMETIMES_CONSUMES\r
+  gEfiIp4ProtocolGuid                             ## SOMETIMES_CONSUMES\r
   gEfiManagedNetworkServiceBindingProtocolGuid    ## SOMETIMES_CONSUMES\r
   gEfiManagedNetworkProtocolGuid                  ## SOMETIMES_CONSUMES\r
   \r