]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcImpl.c
index 6d4f33f0dbaef59d5e578fb64d422e6445202c07..3fa3be99c1786e34d96dc5ce289d622ca82c4e29 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface routines for PxeBc.\r
 \r
-Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 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
@@ -166,13 +166,15 @@ IcmpErrorListenHandlerDpc (
     return;\r
   }\r
 \r
-  if (EFI_ERROR (Status) || (RxData == NULL)) {\r
+  if (RxData == NULL) {\r
+    goto Resume;\r
+  }\r
+\r
+  if (Status != EFI_ICMP_ERROR) {\r
     //\r
-    // Only process the normal packets and the icmp error packets, if RxData is NULL\r
-    // with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although\r
-    // this should be a bug of the low layer (IP).\r
+    // The return status should be recognized as EFI_ICMP_ERROR.\r
     //\r
-    goto Resume;\r
+    goto CleanUp;\r
   }\r
 \r
   if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&\r
@@ -216,8 +218,6 @@ IcmpErrorListenHandlerDpc (
     CopiedPointer += CopiedLen;\r
   }\r
 \r
-  goto Resume;\r
-\r
 CleanUp:\r
   gBS->SignalEvent (RxData->RecycleSignal);\r
 \r
@@ -354,7 +354,7 @@ EfiPxeBcStart (
 \r
   //\r
   // Configure block size for TFTP as a default value to handle all link layers.\r
-  // \r
+  //\r
   Private->BlockSize   = MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) -\r
                            PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;\r
   //\r
@@ -363,7 +363,7 @@ EfiPxeBcStart (
   if (PcdGet64 (PcdTftpBlockSize) != 0) {\r
     Private->BlockSize   = (UINTN) PcdGet64 (PcdTftpBlockSize);\r
   }\r
-  \r
+\r
   Private->AddressIsOk = FALSE;\r
 \r
   ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));\r
@@ -415,17 +415,17 @@ EfiPxeBcStart (
   }\r
 \r
   //\r
-  //DHCP4 service allows only one of its children to be configured in  \r
-  //the active state, If the DHCP4 D.O.R.A started by IP4 auto  \r
-  //configuration and has not been completed, the Dhcp4 state machine \r
-  //will not be in the right state for the PXE to start a new round D.O.R.A. \r
+  //DHCP4 service allows only one of its children to be configured in\r
+  //the active state, If the DHCP4 D.O.R.A started by IP4 auto\r
+  //configuration and has not been completed, the Dhcp4 state machine\r
+  //will not be in the right state for the PXE to start a new round D.O.R.A.\r
   //so we need to switch it's policy to static.\r
   //\r
   Status = PxeBcSetIp4Policy (Private);\r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-    \r
+\r
   Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
@@ -726,35 +726,35 @@ ON_EXIT:
       CopyMem (&Private->Udp4CfgData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
       CopyMem (&Private->Ip4ConfigData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
       CopyMem (&Private->Ip4ConfigData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-  \r
+\r
       //\r
       // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.\r
       //\r
       Private->Ip4->Cancel (Private->Ip4, &Private->IcmpErrorRcvToken);\r
       Private->Ip4->Configure (Private->Ip4, NULL);\r
-  \r
+\r
       Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r
       if (EFI_ERROR (Status)) {\r
         goto ON_EXIT;\r
       }\r
-  \r
+\r
       Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);\r
       if (EFI_ERROR (Status)) {\r
         goto ON_EXIT;\r
-      } \r
+      }\r
     }\r
   }\r
 \r
   Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
 \r
   //\r
-  // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP \r
+  // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP\r
   // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
   //\r
   ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r
   IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r
   This->SetIpFilter (This, &IpFilter);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -864,7 +864,7 @@ EfiPxeBcDiscover (
     if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r
 \r
       Status = EFI_INVALID_PARAMETER;\r
-      goto ON_EXIT;  \r
+      goto ON_EXIT;\r
     }\r
 \r
     DefaultInfo.IpCnt                 = 1;\r
@@ -888,7 +888,7 @@ EfiPxeBcDiscover (
       // Address is not acquired or no discovery options.\r
       //\r
       Status = EFI_INVALID_PARAMETER;\r
-      goto ON_EXIT;  \r
+      goto ON_EXIT;\r
     }\r
 \r
     DefaultInfo.UseMCast    = (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
@@ -936,9 +936,9 @@ EfiPxeBcDiscover (
         if (CreatedInfo == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           goto ON_EXIT;\r
-          \r
-        }     \r
-      \r
+\r
+        }\r
+\r
         CopyMem (CreatedInfo, &DefaultInfo, sizeof (DefaultInfo));\r
         Info    = CreatedInfo;\r
         SrvList = Info->SrvList;\r
@@ -965,7 +965,7 @@ EfiPxeBcDiscover (
 \r
       if (Index != Info->IpCnt) {\r
         Status = EFI_INVALID_PARAMETER;\r
-        goto ON_EXIT;        \r
+        goto ON_EXIT;\r
       }\r
     }\r
   }\r
@@ -1005,7 +1005,7 @@ EfiPxeBcDiscover (
                 );\r
       if (!EFI_ERROR (Status)) {\r
         break;\r
-      }                \r
+      }\r
     }\r
 \r
   } else if (Info->UseMCast) {\r
@@ -1063,15 +1063,15 @@ EfiPxeBcDiscover (
 ON_EXIT:\r
 \r
   Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
-  \r
+\r
   //\r
-  // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP \r
+  // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP\r
   // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
   //\r
   ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r
   IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;\r
   This->SetIpFilter (This, &IpFilter);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -1172,8 +1172,8 @@ EfiPxeBcMtftp (
   if ((This == NULL)                                                          ||\r
       (Filename == NULL)                                                      ||\r
       (BufferSize == NULL)                                                    ||\r
-      ((ServerIp == NULL) || \r
-       (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || \r
+      ((ServerIp == NULL) ||\r
+       (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) ||\r
         IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0]))))                  ||\r
       ((BufferPtr == NULL) && DontUseBuffer)                                  ||\r
       ((BlockSize != NULL) && (*BlockSize < 512))) {\r
@@ -1307,7 +1307,7 @@ EfiPxeBcMtftp (
 ON_EXIT:\r
   Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
   //\r
-  // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP \r
+  // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP\r
   // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r
   //\r
   ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));\r
@@ -1454,7 +1454,7 @@ EfiPxeBcUdpWrite (
     Private->CurrentUdpSrcPort = 0;\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));\r
   ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));\r
 \r
@@ -2022,13 +2022,13 @@ EfiPxeBcSetIpFilter (
       }\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Check whether we need reconfigure the UDP instance.\r
   //\r
   Udp4Cfg = &Private->Udp4CfgData;\r
   if ((AcceptPromiscuous != Udp4Cfg->AcceptPromiscuous) ||\r
-         (AcceptBroadcast != Udp4Cfg->AcceptBroadcast)     || MultiCastUpdate) {\r
+      (AcceptBroadcast != Udp4Cfg->AcceptBroadcast)     || MultiCastUpdate) {\r
     //\r
     // Clear the UDP instance configuration, all joined groups will be left\r
     // during the operation.\r
@@ -2326,13 +2326,13 @@ EfiPxeBcSetStationIP (
   }\r
 \r
   if (NewStationIp != NULL) {\r
-    if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) || \r
+    if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) ||\r
         IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp->Addr[0])) ||\r
         (NewSubnetMask != NULL && NewSubnetMask->Addr[0] != 0 && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0])))) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
-  \r
+\r
   Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
   Mode    = Private->PxeBc.Mode;\r
 \r
@@ -2801,12 +2801,12 @@ EfiPxeLoadFile (
   BOOLEAN                     NewMakeCallback;\r
   EFI_STATUS                  Status;\r
   UINT64                      TmpBufSize;\r
-  BOOLEAN                     MediaPresent;\r
+  EFI_STATUS                  MediaStatus;\r
 \r
   if (FilePath == NULL || !IsDevicePathEnd (FilePath)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   Private         = PXEBC_PRIVATE_DATA_FROM_LOADFILE (This);\r
   PxeBc           = &Private->PxeBc;\r
   NewMakeCallback = FALSE;\r
@@ -2827,9 +2827,9 @@ EfiPxeLoadFile (
   //\r
   // Check media status before PXE start\r
   //\r
-  MediaPresent = TRUE;\r
-  NetLibDetectMedia (Private->Controller, &MediaPresent);\r
-  if (!MediaPresent) {\r
+  MediaStatus = EFI_SUCCESS;\r
+  NetLibDetectMediaWaitTimeout (Private->Controller, PXEBC_CHECK_MEDIA_WAITING_TIME, &MediaStatus);\r
+  if (MediaStatus != EFI_SUCCESS) {\r
     return EFI_NO_MEDIA;\r
   }\r
 \r
@@ -2933,7 +2933,7 @@ EfiPxeLoadFile (
     AsciiPrint ("\n  NBP file downloaded successfully.\n");\r
     //\r
     // The DHCP4 can have only one configured child instance so we need to stop\r
-    // reset the DHCP4 child before we return. Otherwise the other programs which \r
+    // reset the DHCP4 child before we return. Otherwise the other programs which\r
     // also need to use DHCP4 will be impacted.\r
     // The functionality of PXE Base Code protocol will not be stopped,\r
     // when downloading is successfully.\r