]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
Changed the POLL&TIMEOUT timer values from 50ms to 10ms.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcImpl.c
index abe5a85d4e47821173fb0a169b537edc778cd18f..40f7277a677ae0d35d8b4db5d1003dd8d3ca0fb5 100644 (file)
@@ -32,7 +32,6 @@ Abstract:
   @retval others                  If error occurs when updating arp cache\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 UpdateArpCache (\r
   IN EFI_PXE_BASE_CODE_PROTOCOL     * This\r
@@ -74,7 +73,6 @@ UpdateArpCache (
   @param  Context            Context of the timer event\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EFIAPI\r
 ArpCacheUpdateTimeout (\r
@@ -92,7 +90,6 @@ ArpCacheUpdateTimeout (
   @param  Context\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 FindInArpCache (\r
   EFI_PXE_BASE_CODE_MODE    *PxeBcMode,\r
@@ -121,7 +118,6 @@ FindInArpCache (
   @return None.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EFIAPI\r
 IcmpErrorListenHandlerDpc (\r
@@ -208,7 +204,6 @@ Resume:
   @return None.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EFIAPI\r
 IcmpErrorListenHandler (\r
@@ -251,7 +246,6 @@ EfiPxeBcStart (
   EFI_PXE_BASE_CODE_MODE  *Mode;\r
   EFI_STATUS              Status;\r
 \r
-  CpuDeadLoop ();\r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -273,7 +267,7 @@ EfiPxeBcStart (
   //\r
   // Configure the udp4 instance to let it receive data\r
   //\r
-  Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);\r
+  Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -422,13 +416,9 @@ EfiPxeBcStop (
 \r
   Mode->Started = FALSE;\r
 \r
-\r
-  //\r
-  // Reset and leave joined groups\r
-  //\r
-  Private->Udp4->Groups (Private->Udp4, FALSE, NULL);\r
-\r
-  Private->Udp4->Configure (Private->Udp4, NULL);\r
+  Private->CurrentUdpSrcPort = 0;\r
+  Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r
+  Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
 \r
   Private->Dhcp4->Stop (Private->Dhcp4);\r
   Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
@@ -518,8 +508,9 @@ EfiPxeBcDhcp (
     //\r
     // Zero those arrays to record the varies numbers of DHCP OFFERS.\r
     //\r
-    Private->NumOffers   = 0;\r
-    Private->BootpIndex  = 0;\r
+    Private->GotProxyOffer = FALSE;\r
+    Private->NumOffers     = 0;\r
+    Private->BootpIndex    = 0;\r
     ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r
     ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r
 \r
@@ -1077,7 +1068,6 @@ EfiPxeBcUdpWrite (
   EFI_UDP4_SESSION_DATA     Udp4Session;\r
   EFI_STATUS                Status;\r
   BOOLEAN                   IsDone;\r
-  UINT16                    RandomSrcPort;\r
   EFI_PXE_BASE_CODE_MODE    *Mode;\r
   EFI_MAC_ADDRESS           TempMacAddr;\r
 \r
@@ -1107,8 +1097,11 @@ EfiPxeBcUdpWrite (
   }\r
 \r
   Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
-  Udp4    = Private->Udp4;\r
+  Udp4    = Private->Udp4Write;\r
   Mode    = &Private->Mode;\r
+  if (!Mode->Started) {\r
+    return EFI_NOT_STARTED;\r
+  }\r
 \r
   if (!Private->AddressIsOk && (SrcIp == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1126,23 +1119,25 @@ EfiPxeBcUdpWrite (
 \r
   Mode->IcmpErrorReceived = FALSE;\r
 \r
-  if (SrcIp == NULL) {\r
-    SrcIp = &Private->StationIp;\r
-\r
-    if (GatewayIp == NULL) {\r
-      GatewayIp = &Private->GatewayIp;\r
+  if ((Private->CurrentUdpSrcPort == 0) ||\r
+    ((SrcPort != NULL) && (*SrcPort != Private->CurrentUdpSrcPort))) {\r
+    //\r
+    // Port is changed, (re)configure the Udp4Write instance\r
+    //\r
+    if (SrcPort != NULL) {\r
+      Private->CurrentUdpSrcPort = *SrcPort;\r
     }\r
-  }\r
 \r
-  if ((SrcPort == NULL) || (OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT)) {\r
-    RandomSrcPort = (UINT16) (NET_RANDOM (NetRandomInitSeed ()) % 10000 + 1024);\r
-\r
-    if (SrcPort == NULL) {\r
-\r
-      SrcPort  = &RandomSrcPort;\r
-    } else {\r
-\r
-      *SrcPort = RandomSrcPort;\r
+    Status = PxeBcConfigureUdpWriteInstance (\r
+               Udp4,\r
+               &Private->StationIp.v4,\r
+               &Private->SubnetMask.v4,\r
+               &Private->GatewayIp.v4,\r
+               &Private->CurrentUdpSrcPort\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      Private->CurrentUdpSrcPort = 0;\r
+      return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
 \r
@@ -1151,11 +1146,15 @@ EfiPxeBcUdpWrite (
 \r
   CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r
   Udp4Session.DestinationPort = *DestPort;\r
-  CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r
-  Udp4Session.SourcePort = *SrcPort;\r
+  if (SrcIp != NULL) {\r
+    CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r
+  }\r
+  if (SrcPort != NULL) {\r
+    Udp4Session.SourcePort = *SrcPort;\r
+  }\r
 \r
   FragCount = (HeaderSize != NULL) ? 2 : 1;\r
-  Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocatePool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r
+  Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r
   if (Udp4TxData == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -1172,7 +1171,9 @@ EfiPxeBcUdpWrite (
     DataLength += (UINT32) *HeaderSize;\r
   }\r
 \r
-  Udp4TxData->GatewayAddress  = (EFI_IPv4_ADDRESS *) GatewayIp;\r
+  if (GatewayIp != NULL) {\r
+    Udp4TxData->GatewayAddress  = (EFI_IPv4_ADDRESS *) GatewayIp;\r
+  }\r
   Udp4TxData->UdpSessionData  = &Udp4Session;\r
   Udp4TxData->DataLength      = DataLength;\r
   Token.Packet.TxData         = Udp4TxData;\r
@@ -1226,7 +1227,6 @@ ON_EXIT:
   @retval FLASE              The UDP package doesn't matches IP filters\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 CheckIpByFilter (\r
   EFI_PXE_BASE_CODE_MODE    *PxeBcMode,\r
@@ -1345,7 +1345,7 @@ EfiPxeBcUdpRead (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderPtr == NULL) && (*HeaderSize != 0))) {\r
+  if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderSize != NULL) && (HeaderPtr == NULL))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1355,7 +1355,7 @@ EfiPxeBcUdpRead (
 \r
   Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
   Mode    = Private->PxeBc.Mode;\r
-  Udp4    = Private->Udp4;\r
+  Udp4    = Private->Udp4Read;\r
 \r
   if (!Mode->Started) {\r
     return EFI_NOT_STARTED;\r
@@ -1374,6 +1374,8 @@ EfiPxeBcUdpRead (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+TRY_AGAIN:\r
+\r
   IsDone = FALSE;\r
   Status = Udp4->Receive (Udp4, &Token);\r
   if (EFI_ERROR (Status)) {\r
@@ -1411,6 +1413,8 @@ EfiPxeBcUdpRead (
     }\r
 \r
     if (Matched) {\r
+      Matched = FALSE;\r
+\r
       //\r
       // Match the destination ip of the received udp dgram\r
       //\r
@@ -1511,6 +1515,10 @@ EfiPxeBcUdpRead (
     // Recycle the RxData\r
     //\r
     gBS->SignalEvent (RxData->RecycleSignal);\r
+\r
+    if (!Matched) {\r
+      goto TRY_AGAIN;\r
+    }\r
   }\r
 \r
 ON_EXIT:\r
@@ -1595,7 +1603,7 @@ EfiPxeBcSetIpFilter (
   // Clear the UDP instance configuration, all joined groups will be left\r
   // during the operation.\r
   //\r
-  Private->Udp4->Configure (Private->Udp4, NULL);\r
+  Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
   Private->Udp4CfgData.AcceptPromiscuous  = FALSE;\r
   Private->Udp4CfgData.AcceptBroadcast    = FALSE;\r
 \r
@@ -1611,7 +1619,7 @@ EfiPxeBcSetIpFilter (
     //\r
     // Configure the UDP instance with the new configuration.\r
     //\r
-    Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);\r
+    Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -1628,7 +1636,7 @@ EfiPxeBcSetIpFilter (
     //\r
     // Configure the UDP instance with the new configuration.\r
     //\r
-    Status = Private->Udp4->Configure (Private->Udp4, &Private->Udp4CfgData);\r
+    Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -1640,7 +1648,7 @@ EfiPxeBcSetIpFilter (
           //\r
           // Join the mutilcast group\r
           //\r
-          Status = Private->Udp4->Groups (Private->Udp4, TRUE, &NewFilter->IpList[Index].v4);\r
+          Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
@@ -1901,13 +1909,13 @@ EfiPxeBcSetStationIP (
   }\r
 \r
   if (NewStationIp != NULL) {\r
-    Mode->StationIp    = *NewStationIp;\r
-    Private->StationIp = *NewStationIp;\r
+    CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r
+    CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r
   }\r
 \r
   if (NewSubnetMask != NULL) {\r
-    Mode->SubnetMask    = *NewSubnetMask;\r
-    Private->SubnetMask = *NewSubnetMask;\r
+    CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r
+    CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r
   }\r
 \r
   Private->AddressIsOk = TRUE;\r
@@ -2356,7 +2364,6 @@ EfiPxeLoadFile (
   BlockSize       = 0x8000;\r
   Status          = EFI_DEVICE_ERROR;\r
 \r
-  CpuDeadLoop ();\r
   if (This == NULL || BufferSize == NULL) {\r
 \r
     return EFI_INVALID_PARAMETER;\r
@@ -2444,57 +2451,46 @@ EfiPxeLoadFile (
           &Private->LoadFileCallback\r
           );\r
   }\r
+\r
   //\r
   // Check download status\r
   //\r
-  switch (Status) {\r
-\r
-  case EFI_SUCCESS:\r
-    break;\r
+  if (Status == EFI_SUCCESS) {\r
+    return EFI_SUCCESS;\r
 \r
-  case EFI_BUFFER_TOO_SMALL:\r
+  } else if (Status == EFI_BUFFER_TOO_SMALL) {\r
     if (Buffer != NULL) {\r
       AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");\r
     } else {\r
       return Status;\r
     }\r
-    break;\r
 \r
-  case EFI_DEVICE_ERROR:\r
+  } else if (Status == EFI_DEVICE_ERROR) {\r
     AsciiPrint ("PXE-E07: Network device error.\n");\r
-    break;\r
 \r
-  case EFI_OUT_OF_RESOURCES:\r
+  } else if (Status == EFI_OUT_OF_RESOURCES) {\r
     AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");\r
-    break;\r
 \r
-  case EFI_NO_MEDIA:\r
+  } else if (Status == EFI_NO_MEDIA) {\r
     AsciiPrint ("PXE-E12: Could not detect network connection.\n");\r
-    break;\r
 \r
-  case EFI_NO_RESPONSE:\r
+  } else if (Status == EFI_NO_RESPONSE) {\r
     AsciiPrint ("PXE-E16: No offer received.\n");\r
-    break;\r
 \r
-  case EFI_TIMEOUT:\r
+  } else if (Status == EFI_TIMEOUT) {\r
     AsciiPrint ("PXE-E18: Server response timeout.\n");\r
-    break;\r
 \r
-  case EFI_ABORTED:\r
+  } else if (Status == EFI_ABORTED) {\r
     AsciiPrint ("PXE-E21: Remote boot cancelled.\n");\r
-    break;\r
 \r
-  case EFI_ICMP_ERROR:\r
+  } else if (Status == EFI_ICMP_ERROR) {\r
     AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");\r
-    break;\r
 \r
-  case EFI_TFTP_ERROR:\r
+  } else if (Status == EFI_TFTP_ERROR) {\r
     AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");\r
-    break;\r
 \r
-  default:\r
+  } else {\r
     AsciiPrint ("PXE-E99: Unexpected network error.\n");\r
-    break;\r
   }\r
 \r
   PxeBc->Stop (PxeBc);\r