]> 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 89977e6690b91c5b612e59587c5de2f44edcecec..3fa3be99c1786e34d96dc5ce289d622ca82c4e29 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface routines for PxeBc.\r
 \r
-Copyright (c) 2007 - 2015, 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,17 +166,21 @@ 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
-      !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) {\r
+      (NTOHL (Mode->SubnetMask.Addr[0]) != 0) &&\r
+      IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) &&\r
+      !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0]))) {\r
     //\r
     // The source address is not zero and it's not a unicast IP address, discard it.\r
     //\r
@@ -214,8 +218,6 @@ IcmpErrorListenHandlerDpc (
     CopiedPointer += CopiedLen;\r
   }\r
 \r
-  goto Resume;\r
-\r
 CleanUp:\r
   gBS->SignalEvent (RxData->RecycleSignal);\r
 \r
@@ -336,6 +338,8 @@ EfiPxeBcStart (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  AsciiPrint ("\n>>Start PXE over IPv4");\r
+\r
   //\r
   // Configure the udp4 instance to let it receive data\r
   //\r
@@ -350,16 +354,16 @@ EfiPxeBcStart (
 \r
   //\r
   // Configure block size for TFTP as a default value to handle all link layers.\r
-  // \r
-  Private->BlockSize   = (UINTN) (MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) - \r
-                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);\r
+  //\r
+  Private->BlockSize   = MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) -\r
+                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;\r
   //\r
   // If PcdTftpBlockSize is set to non-zero, override the default value.\r
   //\r
   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
@@ -411,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
@@ -665,6 +669,11 @@ EfiPxeBcDhcp (
   //\r
   Status = PxeBcCheckSelectedOffer (Private);\r
 \r
+  AsciiPrint ("\n  Station IP address is ");\r
+\r
+  PxeBcShowIp4Addr (&Private->StationIp.v4);\r
+  AsciiPrint ("\n");\r
+\r
 ON_EXIT:\r
   if (EFI_ERROR (Status)) {\r
     Dhcp4->Stop (Dhcp4);\r
@@ -717,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
@@ -855,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
@@ -879,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
@@ -927,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
@@ -956,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
@@ -996,7 +1005,7 @@ EfiPxeBcDiscover (
                 );\r
       if (!EFI_ERROR (Status)) {\r
         break;\r
-      }                \r
+      }\r
     }\r
 \r
   } else if (Info->UseMCast) {\r
@@ -1054,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
@@ -1163,7 +1172,9 @@ EfiPxeBcMtftp (
   if ((This == NULL)                                                          ||\r
       (Filename == NULL)                                                      ||\r
       (BufferSize == NULL)                                                    ||\r
-      ((ServerIp == NULL) || !NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 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
 \r
@@ -1296,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
@@ -1378,7 +1389,7 @@ EfiPxeBcUdpWrite (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if ((GatewayIp != NULL) && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {\r
+  if ((GatewayIp != NULL) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp->Addr[0])))) {\r
     //\r
     // Gateway is provided but it's not a unicast IP address.\r
     //\r
@@ -1435,13 +1446,15 @@ EfiPxeBcUdpWrite (
              &Private->StationIp.v4,\r
              &Private->SubnetMask.v4,\r
              &Private->GatewayIp.v4,\r
-             &Private->CurrentUdpSrcPort\r
+             &Private->CurrentUdpSrcPort,\r
+             Private->Mode.TTL,\r
+             Private->Mode.ToS\r
              );\r
   if (EFI_ERROR (Status)) {\r
     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
@@ -1962,9 +1975,11 @@ EfiPxeBcSetIpFilter (
       DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    if (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) &&\r
-        ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)\r
-       ) {\r
+    if ((EFI_NTOHL(Mode->StationIp) != 0) &&\r
+        (EFI_NTOHL(Mode->SubnetMask) != 0) &&\r
+        IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r
+        NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r
+        ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) {\r
       //\r
       // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,\r
       // promiscuous mode is needed.\r
@@ -2007,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
@@ -2306,12 +2321,16 @@ EfiPxeBcSetStationIP (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0)) {\r
+  if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r
-    return EFI_INVALID_PARAMETER;\r
+  if (NewStationIp != NULL) {\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
   Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
@@ -2728,6 +2747,14 @@ DiscoverBootFile (
 \r
   Private->FileSize = (UINTN) *BufferSize;\r
 \r
+  //\r
+  // Display all the information: boot server address, boot file name and boot file size.\r
+  //\r
+  AsciiPrint ("\n  Server IP address is ");\r
+  PxeBcShowIp4Addr (&Private->ServerIp.v4);\r
+  AsciiPrint ("\n  NBP filename is %a", Private->BootFileName);\r
+  AsciiPrint ("\n  NBP filesize is %d Bytes", Private->FileSize);\r
+\r
   return Status;\r
 }\r
 \r
@@ -2774,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
@@ -2800,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
@@ -2843,6 +2870,7 @@ EfiPxeLoadFile (
     if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) {\r
       Status = EFI_DEVICE_ERROR;\r
     } else if (TmpBufSize > 0 && *BufferSize >= (UINTN) TmpBufSize && Buffer != NULL) {\r
+      AsciiPrint ("\n Downloading NBP file...\n");\r
       *BufferSize = (UINTN) TmpBufSize;\r
       Status = PxeBc->Mtftp (\r
                         PxeBc,\r
@@ -2867,6 +2895,7 @@ EfiPxeLoadFile (
     //\r
     // Download the file.\r
     //\r
+    AsciiPrint ("\n Downloading NBP file...\n");\r
     TmpBufSize = (UINT64) (*BufferSize);\r
     Status = PxeBc->Mtftp (\r
                       PxeBc,\r
@@ -2901,9 +2930,10 @@ EfiPxeLoadFile (
   // Check download status\r
   //\r
   if (Status == EFI_SUCCESS) {\r
+    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