]> 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 f3a49523601be666d1fac39e043a7f0a7b2f6cee..d8c48ec8b2b563ef00b7927d8b15d432628f68cf 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Interface routine for Mtftp4.\r
   \r
-Copyright (c) 2006 - 2012, 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
@@ -120,6 +121,7 @@ Mtftp4GetInfoCheckPacket (
   MTFTP4_GETINFO_STATE      *State;\r
   EFI_STATUS                Status;\r
   UINT16                    OpCode;\r
+  EFI_MTFTP4_ERROR_HEADER  *ErrorHeader;\r
 \r
   State   = (MTFTP4_GETINFO_STATE *) Token->Context;\r
   OpCode   = NTOHS (Packet->OpCode);\r
@@ -129,6 +131,12 @@ Mtftp4GetInfoCheckPacket (
   //\r
   switch (OpCode) {\r
   case EFI_MTFTP4_OPCODE_ERROR:\r
+    ErrorHeader = (EFI_MTFTP4_ERROR_HEADER *) Packet;\r
+    if (ErrorHeader->ErrorCode == EFI_MTFTP4_ERRORCODE_FILE_NOT_FOUND) {\r
+      DEBUG ((EFI_D_ERROR, "TFTP error code 1 (File Not Found)\n"));\r
+    } else {\r
+      DEBUG ((EFI_D_ERROR, "TFTP error code %d\n", ErrorHeader->ErrorCode));\r
+    }\r
     State->Status = EFI_TFTP_ERROR;\r
     break;\r
 \r
@@ -184,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
@@ -200,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
@@ -250,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
@@ -298,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
@@ -401,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
@@ -408,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
@@ -422,6 +431,7 @@ Mtftp4Start (
                );\r
 \r
     if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
       goto ON_ERROR;\r
     }\r
   }\r
@@ -476,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
@@ -493,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
@@ -511,6 +522,7 @@ Mtftp4Start (
     This->Poll (This);\r
   }\r
 \r
+  gBS->RestoreTPL (OldTpl);\r
   return Token->Status;\r
 \r
 ON_ERROR:\r
@@ -659,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
@@ -1070,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
@@ -1084,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