]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
NetworkPkg: remove unnecessary timeout event when setting IPv6 address.
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcDhcp6.c
index 07f1724365f4dc7078d2c833ec4abefe9808ae93..6ad5f5f1ac9fd5eb318a3fcd55e597d13e92dbd7 100644 (file)
@@ -2,7 +2,7 @@
   Functions implementation related with DHCPv6 for UefiPxeBc Driver.\r
 \r
   (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -793,8 +793,8 @@ PxeBcRequestBootService (
     \r
   Status = PxeBc->UdpRead (\r
                     PxeBc,\r
-                    EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP,\r
-                    &Private->StationIp,\r
+                    EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP | EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP,\r
+                    NULL,\r
                     &SrcPort,\r
                     &Private->ServerIp,\r
                     &DestPort,\r
@@ -1376,16 +1376,15 @@ PxeBcRegisterIp6Address (
   EFI_IP6_CONFIG_MANUAL_ADDRESS    CfgAddr;\r
   EFI_IPv6_ADDRESS                 GatewayAddr;\r
   UINTN                            DataSize;\r
-  EFI_EVENT                        TimeOutEvt;\r
   EFI_EVENT                        MappedEvt;\r
   EFI_STATUS                       Status;\r
-  UINT64                           DadTriggerTime;\r
-  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS    DadXmits;\r
   BOOLEAN                          NoGateway;\r
+  EFI_IPv6_ADDRESS                 *Ip6Addr;\r
+  UINTN                            Index;\r
 \r
   Status     = EFI_SUCCESS;\r
-  TimeOutEvt = NULL;\r
   MappedEvt  = NULL;\r
+  Ip6Addr    = NULL;\r
   DataSize   = sizeof (EFI_IP6_CONFIG_POLICY);\r
   Ip6Cfg     = Private->Ip6Cfg;\r
   Ip6        = Private->Ip6;\r
@@ -1426,34 +1425,6 @@ PxeBcRegisterIp6Address (
     goto ON_EXIT;\r
   }\r
 \r
-  //\r
-  // Get Duplicate Address Detection Transmits count.\r
-  //\r
-  DataSize = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS);\r
-  Status = Ip6Cfg->GetData (\r
-                     Ip6Cfg,\r
-                     Ip6ConfigDataTypeDupAddrDetectTransmits,\r
-                     &DataSize,\r
-                     &DadXmits\r
-                     );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  //\r
-  // Create a timer as setting address timeout event since DAD in IP6 driver.\r
-  //\r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER,\r
-                  TPL_CALLBACK,\r
-                  NULL,\r
-                  NULL,\r
-                  &TimeOutEvt\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
   //\r
   // Create a notify event to set address flag when DAD if IP6 driver succeeded.\r
   //\r
@@ -1468,6 +1439,7 @@ PxeBcRegisterIp6Address (
     goto ON_EXIT;\r
   }\r
 \r
+  Private->IsAddressOk = FALSE;\r
   Status = Ip6Cfg->RegisterDataNotify (\r
                      Ip6Cfg,\r
                      Ip6ConfigDataTypeManualAddress,\r
@@ -1485,23 +1457,54 @@ PxeBcRegisterIp6Address (
                      );\r
   if (EFI_ERROR(Status) && Status != EFI_NOT_READY) {\r
     goto ON_EXIT;\r
-  }\r
+  } else if (Status == EFI_NOT_READY) {\r
+    //\r
+    // Poll the network until the asynchronous process is finished.\r
+    //\r
+    while (!Private->IsAddressOk) {\r
+      Ip6->Poll (Ip6);\r
+    }\r
+    //\r
+    // Check whether the IP6 address setting is successed.\r
+    //\r
+    DataSize = 0;\r
+    Status = Ip6Cfg->GetData (\r
+                       Ip6Cfg,\r
+                       Ip6ConfigDataTypeManualAddress,\r
+                       &DataSize,\r
+                       NULL\r
+                       );\r
+    if (Status != EFI_BUFFER_TOO_SMALL || DataSize == 0) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_EXIT;\r
+    }\r
 \r
-  //\r
-  // Start the 5 secondes timer to wait for setting address.\r
-  //\r
-  Status = EFI_NO_MAPPING;\r
-  DadTriggerTime = TICKS_PER_SECOND * DadXmits.DupAddrDetectTransmits + PXEBC_DAD_ADDITIONAL_DELAY;\r
-  gBS->SetTimer (TimeOutEvt, TimerRelative, DadTriggerTime);\r
+    Ip6Addr = AllocatePool (DataSize);\r
+    if (Ip6Addr == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Status = Ip6Cfg->GetData (\r
+                       Ip6Cfg,\r
+                       Ip6ConfigDataTypeManualAddress,\r
+                       &DataSize,\r
+                       (VOID*) Ip6Addr\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_EXIT;\r
+    }\r
 \r
-  while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {\r
-    Ip6->Poll (Ip6);\r
-    if (Private->IsAddressOk) {\r
-      Status = EFI_SUCCESS;\r
-      break;\r
+    for (Index = 0; Index < DataSize / sizeof (EFI_IPv6_ADDRESS); Index++) {\r
+      if (CompareMem (Ip6Addr + Index, Address, sizeof (EFI_IPv6_ADDRESS)) == 0) {\r
+        break;\r
+      }\r
+    }\r
+    if (Index == DataSize / sizeof (EFI_IPv6_ADDRESS)) {\r
+      Status = EFI_ABORTED;\r
+      goto ON_EXIT;\r
     }\r
   }\r
-\r
+  \r
   //\r
   // Set the default gateway address back if needed.\r
   //\r
@@ -1526,8 +1529,8 @@ ON_EXIT:
               );\r
     gBS->CloseEvent (MappedEvt);\r
   }\r
-  if (TimeOutEvt != NULL) {\r
-    gBS->CloseEvent (TimeOutEvt);\r
+  if (Ip6Addr != NULL) {\r
+    FreePool (Ip6Addr);\r
   }\r
   return Status;\r
 }\r
@@ -1807,7 +1810,6 @@ PxeBcDhcp6Discover (
   UINT8                               *RequestOpt;\r
   UINT8                               *DiscoverOpt;\r
   UINTN                               ReadSize;\r
-  UINT16                              OpFlags;\r
   UINT16                              OpCode;\r
   UINT16                              OpLen;\r
   UINT32                              Xid;\r
@@ -1818,7 +1820,6 @@ PxeBcDhcp6Discover (
   Request     = Private->Dhcp6Request;\r
   SrcPort     = PXEBC_BS_DISCOVER_PORT;\r
   DestPort    = PXEBC_BS_DISCOVER_PORT;\r
-  OpFlags     = 0;\r
 \r
   if (!UseBis && Layer != NULL) {\r
     *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK;\r
@@ -1862,7 +1863,7 @@ PxeBcDhcp6Discover (
 \r
   Status = PxeBc->UdpWrite (\r
                     PxeBc,\r
-                    OpFlags,\r
+                    0,\r
                     &Private->ServerIp,\r
                     &DestPort,\r
                     NULL,\r
@@ -1899,8 +1900,8 @@ PxeBcDhcp6Discover (
   \r
   Status = PxeBc->UdpRead (\r
                     PxeBc,\r
-                    OpFlags,\r
-                    &Private->StationIp,\r
+                    EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP,\r
+                    NULL,\r
                     &SrcPort,\r
                     &Private->ServerIp,\r
                     &DestPort,\r