]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
[Description]:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcImpl.c
index c0fff3d5479b61af02d6ee2584df17459c42bc2b..8fc528f3161adb6f6d24ebd15b02749f4db6d1b3 100644 (file)
@@ -272,7 +272,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
@@ -421,13 +421,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
@@ -1076,7 +1072,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
@@ -1106,8 +1101,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
@@ -1125,23 +1123,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
@@ -1150,8 +1150,12 @@ 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
@@ -1171,7 +1175,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
@@ -1344,7 +1350,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
@@ -1354,7 +1360,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
@@ -1373,6 +1379,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
@@ -1410,6 +1418,8 @@ EfiPxeBcUdpRead (
     }\r
 \r
     if (Matched) {\r
+      Matched = FALSE;\r
+\r
       //\r
       // Match the destination ip of the received udp dgram\r
       //\r
@@ -1510,6 +1520,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
@@ -1594,7 +1608,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
@@ -1610,7 +1624,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
@@ -1627,7 +1641,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
@@ -1639,7 +1653,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
@@ -2448,7 +2462,7 @@ EfiPxeLoadFile (
   switch (Status) {\r
 \r
   case EFI_SUCCESS:\r
-    break;\r
+    return EFI_SUCCESS;\r
 \r
   case EFI_BUFFER_TOO_SMALL:\r
     if (Buffer != NULL) {\r