]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to calculate the packet live time.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Impl.c
index 03b7f28171a3e5befa9049ec1f9b7c97f141d401..d8c48ec8b2b563ef00b7927d8b15d432628f68cf 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Interface routine for Mtftp4.\r
   \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
+Copyright (c) 2006 - 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
@@ -191,7 +192,7 @@ Mtftp4OverrideValid (
   IP4_ADDR                  Gateway;\r
 \r
   CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));\r
-  if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {\r
+  if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
     return FALSE;\r
   }\r
 \r
@@ -207,7 +208,7 @@ Mtftp4OverrideValid (
     Netmask = NTOHL (Netmask);\r
     Ip      = NTOHL (Ip);\r
 \r
-    if (!NetIp4IsUnicast (Gateway, Netmask) || !IP4_NET_EQUAL (Gateway, Ip, Netmask)) {\r
+    if ((Netmask != 0 && !NetIp4IsUnicast (Gateway, Netmask)) || !IP4_NET_EQUAL (Gateway, Ip, Netmask)) {\r
       return FALSE;\r
     }\r
   }\r
@@ -257,7 +258,7 @@ Mtftp4GetMapping (
     return FALSE;\r
   }\r
 \r
-  while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {\r
+  while (EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {\r
     Udp->Poll (Udp);\r
 \r
     if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip4Mode, NULL, NULL)) &&\r
@@ -305,13 +306,13 @@ Mtftp4ConfigUnicastPort (
   UdpConfig.ReceiveTimeout     = 0;\r
   UdpConfig.TransmitTimeout    = 0;\r
   UdpConfig.UseDefaultAddress  = Config->UseDefaultSetting;\r
-  UdpConfig.StationAddress     = Config->StationIp;\r
-  UdpConfig.SubnetMask         = Config->SubnetMask;\r
+  IP4_COPY_ADDRESS (&UdpConfig.StationAddress, &Config->StationIp);\r
+  IP4_COPY_ADDRESS (&UdpConfig.SubnetMask, &Config->SubnetMask);\r
   UdpConfig.StationPort        = 0;\r
   UdpConfig.RemotePort         = 0;\r
 \r
   Ip = HTONL (Instance->ServerIp);\r
-  CopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+  IP4_COPY_ADDRESS (&UdpConfig.RemoteAddress, &Ip);\r
 \r
   Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfig);\r
 \r
@@ -408,6 +409,12 @@ Mtftp4Start (
     return Status;\r
   }\r
 \r
+  if ((Token->OverrideData != NULL) && !Mtftp4OverrideValid (Instance, Token->OverrideData)) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Set the Operation now to prevent the application start other\r
   // operations.\r
@@ -415,11 +422,6 @@ Mtftp4Start (
   Instance->Operation = Operation;\r
   Override            = Token->OverrideData;\r
 \r
-  if ((Override != NULL) && !Mtftp4OverrideValid (Instance, Override)) {\r
-    Status = EFI_INVALID_PARAMETER;\r
-    goto ON_ERROR;\r
-  }\r
-\r
   if (Token->OptionCount != 0) {\r
     Status = Mtftp4ParseOption (\r
                Token->OptionList,\r
@@ -429,6 +431,7 @@ Mtftp4Start (
                );\r
 \r
     if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
       goto ON_ERROR;\r
     }\r
   }\r
@@ -483,6 +486,7 @@ Mtftp4Start (
   Status = Mtftp4ConfigUnicastPort (Instance->UnicastPort, Instance);\r
 \r
   if (EFI_ERROR (Status)) {\r
+    Status = EFI_DEVICE_ERROR;\r
     goto ON_ERROR;\r
   }\r
 \r
@@ -500,13 +504,13 @@ Mtftp4Start (
     Status = Mtftp4RrqStart (Instance, Operation);\r
   }\r
 \r
-  gBS->RestoreTPL (OldTpl);\r
-\r
   if (EFI_ERROR (Status)) {\r
+    Status = EFI_DEVICE_ERROR;\r
     goto ON_ERROR;\r
   }\r
 \r
   if (Token->Event != NULL) {\r
+    gBS->RestoreTPL (OldTpl);\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -518,6 +522,7 @@ Mtftp4Start (
     This->Poll (This);\r
   }\r
 \r
+  gBS->RestoreTPL (OldTpl);\r
   return Token->Status;\r
 \r
 ON_ERROR:\r
@@ -666,18 +671,18 @@ EfiMtftp4Configure (
     Gateway  = NTOHL (Gateway);\r
     ServerIp = NTOHL (ServerIp);\r
 \r
-    if (!NetIp4IsUnicast (ServerIp, 0)) {\r
+    if (ServerIp == 0 || IP4_IS_LOCAL_BROADCAST (ServerIp)) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
     if (!ConfigData->UseDefaultSetting &&\r
-       ((!IP4_IS_VALID_NETMASK (Netmask) || !NetIp4IsUnicast (Ip, Netmask)))) {\r
+        ((!IP4_IS_VALID_NETMASK (Netmask) || (Netmask != 0 && !NetIp4IsUnicast (Ip, Netmask))))) {\r
 \r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    if ((Gateway != 0) &&\r
-        (!IP4_NET_EQUAL (Gateway, Ip, Netmask) || !NetIp4IsUnicast (Gateway, Netmask))) {\r
+    if ((Gateway != 0) && \r
+        (!IP4_NET_EQUAL (Gateway, Ip, Netmask) || (Netmask != 0 && !NetIp4IsUnicast (Gateway, Netmask)))) {\r
 \r
       return EFI_INVALID_PARAMETER;\r
     }\r
@@ -1077,6 +1082,7 @@ EfiMtftp4Poll (
 {\r
   MTFTP4_PROTOCOL           *Instance;\r
   EFI_UDP4_PROTOCOL         *Udp;\r
+  EFI_STATUS                Status;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1091,7 +1097,9 @@ EfiMtftp4Poll (
   }\r
 \r
   Udp = Instance->UnicastPort->Protocol.Udp4;\r
-  return Udp->Poll (Udp);\r
+  Status = Udp->Poll (Udp);\r
+  Mtftp4OnTimerTick (NULL, Instance->Service);\r
+  return Status;\r
 }\r
 \r
 EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate = {\r