]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
NetworkPkg: Remove redundant check in PXE driver.
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcSupport.c
index f918d6a29893e1fc24e0e566bde06f86820e852c..720287583e5ff12ba8e065fbf005f8ef8cf9b436 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support functions implementation for UefiPxeBc Driver.\r
 \r
 /** @file\r
   Support functions implementation for UefiPxeBc Driver.\r
 \r
-  Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2017, 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-PxeBcFlushStaionIp (\r
+PxeBcFlushStationIp (\r
   PXEBC_PRIVATE_DATA       *Private,\r
   PXEBC_PRIVATE_DATA       *Private,\r
-  EFI_IP_ADDRESS           *StationIp,\r
+  EFI_IP_ADDRESS           *StationIp,     OPTIONAL\r
   EFI_IP_ADDRESS           *SubnetMask     OPTIONAL\r
   )\r
 {\r
   EFI_PXE_BASE_CODE_MODE   *Mode;\r
   EFI_STATUS               Status;\r
 \r
   EFI_IP_ADDRESS           *SubnetMask     OPTIONAL\r
   )\r
 {\r
   EFI_PXE_BASE_CODE_MODE   *Mode;\r
   EFI_STATUS               Status;\r
 \r
-  ASSERT (StationIp != NULL);\r
-\r
   Mode   = Private->PxeBc.Mode;\r
   Status = EFI_SUCCESS;\r
 \r
   if (Mode->UsingIpv6) {\r
 \r
   Mode   = Private->PxeBc.Mode;\r
   Status = EFI_SUCCESS;\r
 \r
   if (Mode->UsingIpv6) {\r
 \r
-    CopyMem (&Private->Udp6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
-    CopyMem (&Private->Ip6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
+    if (StationIp != NULL) {\r
+      CopyMem (&Private->Udp6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
+      CopyMem (&Private->Ip6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
+    }\r
 \r
     //\r
     // Reconfigure the Ip6 instance to capture background ICMP6 packets with new station Ip address.\r
 \r
     //\r
     // Reconfigure the Ip6 instance to capture background ICMP6 packets with new station Ip address.\r
@@ -59,16 +59,16 @@ PxeBcFlushStaionIp (
     }\r
 \r
     Status = Private->Ip6->Receive (Private->Ip6, &Private->Icmp6Token);\r
     }\r
 \r
     Status = Private->Ip6->Receive (Private->Ip6, &Private->Icmp6Token);\r
-    if (EFI_ERROR (Status)) {\r
-      goto ON_EXIT;\r
-    }\r
-\r
   } else {\r
   } else {\r
-    ASSERT (SubnetMask != NULL);\r
-    CopyMem (&Private->Udp4CfgData.StationAddress, StationIp, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Private->Udp4CfgData.SubnetMask, SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Private->Ip4CfgData.StationAddress, StationIp, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Private->Ip4CfgData.SubnetMask, SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+    if (StationIp != NULL) {\r
+      CopyMem (&Private->Udp4CfgData.StationAddress, StationIp, sizeof (EFI_IPv4_ADDRESS));\r
+      CopyMem (&Private->Ip4CfgData.StationAddress, StationIp, sizeof (EFI_IPv4_ADDRESS));\r
+    }\r
+    \r
+    if (SubnetMask != NULL) {\r
+      CopyMem (&Private->Udp4CfgData.SubnetMask, SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+      CopyMem (&Private->Ip4CfgData.SubnetMask, 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
     //\r
     // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.\r
@@ -82,10 +82,6 @@ PxeBcFlushStaionIp (
     }\r
 \r
     Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpToken);\r
     }\r
 \r
     Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpToken);\r
-    if (EFI_ERROR (Status)) {\r
-      goto ON_EXIT;\r
-    }\r
-\r
   }\r
 \r
 ON_EXIT:\r
   }\r
 \r
 ON_EXIT:\r
@@ -266,7 +262,9 @@ PxeBcIcmpErrorDpcHandle (
   }\r
 \r
   if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&\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 of the received packet should be a valid unicast address.\r
     //\r
     //\r
     // The source address of the received packet should be a valid unicast address.\r
     //\r
@@ -281,14 +279,11 @@ PxeBcIcmpErrorDpcHandle (
     gBS->SignalEvent (RxData->RecycleSignal);\r
     goto ON_EXIT;\r
   }\r
     gBS->SignalEvent (RxData->RecycleSignal);\r
     goto ON_EXIT;\r
   }\r
-\r
-  if (RxData->Header->Protocol != EFI_IP_PROTO_ICMP) {\r
-    //\r
-    // The protocol value in the header of the receveid packet should be EFI_IP_PROTO_ICMP.\r
-    //\r
-    gBS->SignalEvent (RxData->RecycleSignal);\r
-    goto ON_EXIT;\r
-  }\r
+  \r
+  //\r
+  // The protocol has been configured to only receive ICMP packet.\r
+  //\r
+  ASSERT (RxData->Header->Protocol == EFI_IP_PROTO_ICMP);\r
 \r
   Type = *((UINT8 *) RxData->FragmentTable[0].FragmentBuffer);\r
 \r
 \r
   Type = *((UINT8 *) RxData->FragmentTable[0].FragmentBuffer);\r
 \r
@@ -418,19 +413,16 @@ PxeBcIcmp6ErrorDpcHandle (
     goto ON_EXIT;\r
   }\r
 \r
     goto ON_EXIT;\r
   }\r
 \r
-  if (RxData->Header->NextHeader != IP6_ICMP) {\r
-    //\r
-    // The nextheader in the header of the receveid packet should be IP6_ICMP.\r
-    //\r
-    gBS->SignalEvent (RxData->RecycleSignal);\r
-    goto ON_EXIT;\r
-  }\r
+  //\r
+  // The protocol has been configured to only receive ICMP packet.\r
+  //\r
+  ASSERT (RxData->Header->NextHeader == IP6_ICMP);\r
 \r
   Type = *((UINT8 *) RxData->FragmentTable[0].FragmentBuffer);\r
 \r
   if (Type != ICMP_V6_DEST_UNREACHABLE &&\r
       Type != ICMP_V6_PACKET_TOO_BIG &&\r
 \r
   Type = *((UINT8 *) RxData->FragmentTable[0].FragmentBuffer);\r
 \r
   if (Type != ICMP_V6_DEST_UNREACHABLE &&\r
       Type != ICMP_V6_PACKET_TOO_BIG &&\r
-      Type != ICMP_V6_PACKET_TOO_BIG &&\r
+      Type != ICMP_V6_TIME_EXCEEDED &&\r
       Type != ICMP_V6_PARAMETER_PROBLEM) {\r
     //\r
     // The type of the receveid packet should be an ICMP6 error message.\r
       Type != ICMP_V6_PARAMETER_PROBLEM) {\r
     //\r
     // The type of the receveid packet should be an ICMP6 error message.\r
@@ -497,6 +489,8 @@ PxeBcIcmp6ErrorUpdate (
   @param[in, out]  SrcPort              The pointer to the source port.\r
   @param[in]       DoNotFragment        If TRUE, fragment is not enabled.\r
                                         Otherwise, fragment is enabled.\r
   @param[in, out]  SrcPort              The pointer to the source port.\r
   @param[in]       DoNotFragment        If TRUE, fragment is not enabled.\r
                                         Otherwise, fragment is enabled.\r
+  @param[in]       Ttl                  The time to live field of the IP header. \r
+  @param[in]       ToS                  The type of service field of the IP header.\r
 \r
   @retval          EFI_SUCCESS          Successfully configured this instance.\r
   @retval          Others               Failed to configure this instance.\r
 \r
   @retval          EFI_SUCCESS          Successfully configured this instance.\r
   @retval          Others               Failed to configure this instance.\r
@@ -509,7 +503,9 @@ PxeBcConfigUdp4Write (
   IN     EFI_IPv4_ADDRESS   *SubnetMask,\r
   IN     EFI_IPv4_ADDRESS   *Gateway,\r
   IN OUT UINT16             *SrcPort,\r
   IN     EFI_IPv4_ADDRESS   *SubnetMask,\r
   IN     EFI_IPv4_ADDRESS   *Gateway,\r
   IN OUT UINT16             *SrcPort,\r
-  IN     BOOLEAN            DoNotFragment\r
+  IN     BOOLEAN            DoNotFragment,\r
+  IN     UINT8              Ttl,\r
+  IN     UINT8              ToS\r
   )\r
 {\r
   EFI_UDP4_CONFIG_DATA  Udp4CfgData;\r
   )\r
 {\r
   EFI_UDP4_CONFIG_DATA  Udp4CfgData;\r
@@ -519,8 +515,8 @@ PxeBcConfigUdp4Write (
 \r
   Udp4CfgData.TransmitTimeout    = PXEBC_DEFAULT_LIFETIME;\r
   Udp4CfgData.ReceiveTimeout     = PXEBC_DEFAULT_LIFETIME;\r
 \r
   Udp4CfgData.TransmitTimeout    = PXEBC_DEFAULT_LIFETIME;\r
   Udp4CfgData.ReceiveTimeout     = PXEBC_DEFAULT_LIFETIME;\r
-  Udp4CfgData.TypeOfService      = DEFAULT_ToS;\r
-  Udp4CfgData.TimeToLive         = DEFAULT_TTL;\r
+  Udp4CfgData.TypeOfService      = ToS;\r
+  Udp4CfgData.TimeToLive         = Ttl;\r
   Udp4CfgData.AllowDuplicatePort = TRUE;\r
   Udp4CfgData.DoNotFragment      = DoNotFragment;\r
 \r
   Udp4CfgData.AllowDuplicatePort = TRUE;\r
   Udp4CfgData.DoNotFragment      = DoNotFragment;\r
 \r
@@ -1385,11 +1381,10 @@ PxeBcUintnToAscDecWithFormat (
 {\r
   UINTN                          Remainder;\r
 \r
 {\r
   UINTN                          Remainder;\r
 \r
-  while (Length > 0) {\r
-    Length--;\r
+  for (; Length > 0; Length--) {\r
     Remainder      = Number % 10;\r
     Number        /= 10;\r
     Remainder      = Number % 10;\r
     Number        /= 10;\r
-    Buffer[Length] = (UINT8) ('0' + Remainder);\r
+    Buffer[Length - 1] = (UINT8) ('0' + Remainder);\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r
@@ -1400,6 +1395,7 @@ PxeBcUintnToAscDecWithFormat (
 \r
   @param[in]  Number         Numeric value to be converted.\r
   @param[in]  Buffer         The pointer to the buffer for ASCII string.\r
 \r
   @param[in]  Number         Numeric value to be converted.\r
   @param[in]  Buffer         The pointer to the buffer for ASCII string.\r
+  @param[in]  BufferSize     The maxsize of the buffer.\r
 \r
   @return     Length         The actual length of the ASCII string.\r
 \r
 \r
   @return     Length         The actual length of the ASCII string.\r
 \r
@@ -1407,7 +1403,8 @@ PxeBcUintnToAscDecWithFormat (
 UINTN\r
 PxeBcUintnToAscDec (\r
   IN UINTN               Number,\r
 UINTN\r
 PxeBcUintnToAscDec (\r
   IN UINTN               Number,\r
-  IN UINT8               *Buffer\r
+  IN UINT8               *Buffer,\r
+  IN UINTN               BufferSize\r
   )\r
 {\r
   UINTN           Index;\r
   )\r
 {\r
   UINTN           Index;\r
@@ -1423,7 +1420,7 @@ PxeBcUintnToAscDec (
     Number         = (UINTN) (Number / 10);\r
   } while (Number != 0);\r
 \r
     Number         = (UINTN) (Number / 10);\r
   } while (Number != 0);\r
 \r
-  AsciiStrCpy ((CHAR8 *) Buffer, &TempStr[Index]);\r
+  AsciiStrCpyS ((CHAR8 *) Buffer, BufferSize, &TempStr[Index]);\r
 \r
   Length = AsciiStrLen ((CHAR8 *) Buffer);\r
 \r
 \r
   Length = AsciiStrLen ((CHAR8 *) Buffer);\r
 \r