]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Impl.c
index ca6d83f0428109cd7d30bbd8b7475a98b6b240f5..b31a50209aecfad18e782f7dafc45062b822449f 100644 (file)
@@ -22,7 +22,6 @@ Abstract:
 \r
 #include "Mtftp4Impl.h"\r
 \r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4ReadFile (\r
@@ -41,7 +40,6 @@ EfiMtftp4ReadFile (
   @retval EFI_SUCCESS            The operation parameter is saved in ModeData\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4GetModeData (\r
@@ -56,16 +54,16 @@ EfiMtftp4GetModeData (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  OldTpl = NET_RAISE_TPL (NET_TPL_LOCK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   Instance                         = MTFTP4_PROTOCOL_FROM_THIS (This);\r
   CopyMem(&ModeData->ConfigData, &Instance->Config, sizeof (Instance->Config));\r
   ModeData->SupportedOptionCount   = MTFTP4_SUPPORTED_OPTIONS;\r
-  ModeData->SupportedOptoins       = mMtftp4SupportedOptions;\r
+  ModeData->SupportedOptoins       = (UINT8 **) mMtftp4SupportedOptions;\r
   ModeData->UnsupportedOptionCount = 0;\r
   ModeData->UnsupportedOptoins     = NULL;\r
 \r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -87,8 +85,8 @@ Mtftp4CleanOperation (
   IN EFI_STATUS             Result\r
   )\r
 {\r
-  NET_LIST_ENTRY            *Entry;\r
-  NET_LIST_ENTRY            *Next;\r
+  LIST_ENTRY                *Entry;\r
+  LIST_ENTRY                *Next;\r
   MTFTP4_BLOCK_RANGE        *Block;\r
   EFI_MTFTP4_TOKEN          *Token;\r
 \r
@@ -122,11 +120,11 @@ Mtftp4CleanOperation (
 \r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &Instance->Blocks) {\r
     Block = NET_LIST_USER_STRUCT (Entry, MTFTP4_BLOCK_RANGE, Link);\r
-    NetListRemoveEntry (Entry);\r
-    NetFreePool (Block);\r
+    RemoveEntryList (Entry);\r
+    gBS->FreePool (Block);\r
   }\r
 \r
-  NetZeroMem (&Instance->RequestOption, sizeof (MTFTP4_OPTION));\r
+  ZeroMem (&Instance->RequestOption, sizeof (MTFTP4_OPTION));\r
 \r
   Instance->Operation     = 0;\r
 \r
@@ -158,7 +156,6 @@ Mtftp4CleanOperation (
   @retval EFI_SUCCESS            The instance is configured for operation.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4Configure (\r
@@ -183,22 +180,22 @@ EfiMtftp4Configure (
     //\r
     // Reset the operation if ConfigData is NULL\r
     //\r
-    OldTpl = NET_RAISE_TPL (NET_TPL_LOCK);\r
+    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
     Mtftp4CleanOperation (Instance, EFI_ABORTED);\r
-    NetZeroMem (&Instance->Config, sizeof (EFI_MTFTP4_CONFIG_DATA));\r
+    ZeroMem (&Instance->Config, sizeof (EFI_MTFTP4_CONFIG_DATA));\r
     Instance->State = MTFTP4_STATE_UNCONFIGED;\r
 \r
-    NET_RESTORE_TPL (OldTpl);\r
+    gBS->RestoreTPL (OldTpl);\r
 \r
   } else {\r
     //\r
     // Configure the parameters for new operation.\r
     //\r
-    NetCopyMem (&Ip, &ConfigData->StationIp, sizeof (IP4_ADDR));\r
-    NetCopyMem (&Netmask, &ConfigData->SubnetMask, sizeof (IP4_ADDR));\r
-    NetCopyMem (&Gateway, &ConfigData->GatewayIp, sizeof (IP4_ADDR));\r
-    NetCopyMem (&ServerIp, &ConfigData->ServerIp, sizeof (IP4_ADDR));\r
+    CopyMem (&Ip, &ConfigData->StationIp, sizeof (IP4_ADDR));\r
+    CopyMem (&Netmask, &ConfigData->SubnetMask, sizeof (IP4_ADDR));\r
+    CopyMem (&Gateway, &ConfigData->GatewayIp, sizeof (IP4_ADDR));\r
+    CopyMem (&ServerIp, &ConfigData->ServerIp, sizeof (IP4_ADDR));\r
 \r
     Ip       = NTOHL (Ip);\r
     Netmask  = NTOHL (Netmask);\r
@@ -221,17 +218,17 @@ EfiMtftp4Configure (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    OldTpl = NET_RAISE_TPL (NET_TPL_LOCK);\r
+    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
     if ((Instance->State == MTFTP4_STATE_CONFIGED) && (Instance->Operation != 0)) {\r
-      NET_RESTORE_TPL (OldTpl);\r
+      gBS->RestoreTPL (OldTpl);\r
       return EFI_ACCESS_DENIED;\r
     }\r
 \r
     CopyMem(&Instance->Config, ConfigData, sizeof (*ConfigData));;\r
     Instance->State = MTFTP4_STATE_CONFIGED;\r
 \r
-    NET_RESTORE_TPL (OldTpl);\r
+    gBS->RestoreTPL (OldTpl);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -251,7 +248,6 @@ EfiMtftp4Configure (
   @retval EFI_ABORTED            Abort the ReadFile operation and return.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Mtftp4GetInfoCheckPacket (\r
   IN EFI_MTFTP4_PROTOCOL    *This,\r
@@ -287,7 +283,7 @@ Mtftp4GetInfoCheckPacket (
 \r
   //\r
   // Allocate buffer then copy the packet over. Use gBS->AllocatePool\r
-  // in case NetAllocatePool will implements something tricky.\r
+  // in case AllocatePool will implements something tricky.\r
   //\r
   Status = gBS->AllocatePool (EfiBootServicesData, PacketLen, (VOID **) State->Packet);\r
 \r
@@ -297,7 +293,7 @@ Mtftp4GetInfoCheckPacket (
   }\r
 \r
   *(State->PacketLen) = PacketLen;\r
-  NetCopyMem (*(State->Packet), Packet, PacketLen);\r
+  CopyMem (*(State->Packet), Packet, PacketLen);\r
 \r
   return EFI_ABORTED;\r
 }\r
@@ -322,7 +318,6 @@ Mtftp4GetInfoCheckPacket (
   @retval Others                 Failed to get the information.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4GetInfo (\r
@@ -399,7 +394,6 @@ EfiMtftp4GetInfo (
   @retval EFI_SUCCESS            The packet is parsed.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4ParseOptions (\r
@@ -444,7 +438,6 @@ EfiMtftp4ParseOptions (
   @return TRUE if the override data is valid, otherwise FALSE.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 Mtftp4OverrideValid (\r
   IN MTFTP4_PROTOCOL          *Instance,\r
@@ -456,19 +449,19 @@ Mtftp4OverrideValid (
   IP4_ADDR                  Netmask;\r
   IP4_ADDR                  Gateway;\r
 \r
-  NetCopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));\r
+  CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));\r
   if (!Ip4IsUnicast (NTOHL (Ip), 0)) {\r
     return FALSE;\r
   }\r
 \r
   Config = &Instance->Config;\r
 \r
-  NetCopyMem (&Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));\r
+  CopyMem (&Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));\r
   Gateway = NTOHL (Gateway);\r
 \r
   if (!Config->UseDefaultSetting && (Gateway != 0)) {\r
-    NetCopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR));\r
-    NetCopyMem (&Ip, &Config->StationIp, sizeof (IP4_ADDR));\r
+    CopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR));\r
+    CopyMem (&Ip, &Config->StationIp, sizeof (IP4_ADDR));\r
 \r
     Netmask = NTOHL (Netmask);\r
     Ip      = NTOHL (Ip);\r
@@ -547,7 +540,6 @@ Mtftp4GetMapping (
                                  session to unicast receive.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Mtftp4ConfigUnicastPort (\r
   IN UDP_IO_PORT            *UdpIo,\r
@@ -577,7 +569,7 @@ Mtftp4ConfigUnicastPort (
   UdpConfig.RemotePort         = 0;\r
 \r
   Ip = HTONL (Instance->ServerIp);\r
-  NetCopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfig);\r
 \r
@@ -585,6 +577,16 @@ Mtftp4ConfigUnicastPort (
     return EFI_SUCCESS;\r
   }\r
 \r
+  if (!Config->UseDefaultSetting && !EFI_IP4_EQUAL (&mZeroIp4Addr, &Config->GatewayIp)) {\r
+    //\r
+    // The station IP address is manually configured and the Gateway IP is not 0.\r
+    // Add the default route for this UDP instance.\r
+    //\r
+    Status = UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, &Config->GatewayIp);\r
+    if (EFI_ERROR (Status)) {\r
+      UdpIo->Udp->Configure (UdpIo->Udp, NULL);\r
+    }\r
+  }\r
   return Status;\r
 }\r
 \r
@@ -603,7 +605,6 @@ Mtftp4ConfigUnicastPort (
   @retval EFI_SUCCESS            The operation is successfully started.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Mtftp4Start (\r
   IN EFI_MTFTP4_PROTOCOL    *This,\r
@@ -644,7 +645,7 @@ Mtftp4Start (
   Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
 \r
   Status = EFI_SUCCESS;\r
-  OldTpl = NET_RAISE_TPL (NET_TPL_LOCK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (Instance->State != MTFTP4_STATE_CONFIGED) {\r
     Status = EFI_NOT_STARTED;\r
@@ -655,7 +656,7 @@ Mtftp4Start (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_RESTORE_TPL (OldTpl);\r
+    gBS->RestoreTPL (OldTpl);\r
     return Status;\r
   }\r
 \r
@@ -691,13 +692,13 @@ Mtftp4Start (
   Instance->Token         = Token;\r
   Instance->BlkSize       = MTFTP4_DEFAULT_BLKSIZE;\r
 \r
-  NetCopyMem (&Instance->ServerIp, &Config->ServerIp, sizeof (IP4_ADDR));\r
+  CopyMem (&Instance->ServerIp, &Config->ServerIp, sizeof (IP4_ADDR));\r
   Instance->ServerIp      = NTOHL (Instance->ServerIp);\r
 \r
   Instance->ListeningPort = Config->InitialServerPort;\r
   Instance->ConnectedPort = 0;\r
 \r
-  NetCopyMem (&Instance->Gateway, &Config->GatewayIp, sizeof (IP4_ADDR));\r
+  CopyMem (&Instance->Gateway, &Config->GatewayIp, sizeof (IP4_ADDR));\r
   Instance->Gateway       = NTOHL (Instance->Gateway);\r
 \r
   Instance->MaxRetry      = Config->TryCount;\r
@@ -705,8 +706,8 @@ Mtftp4Start (
   Instance->Master        = TRUE;\r
 \r
   if (Override != NULL) {\r
-    NetCopyMem (&Instance->ServerIp, &Override->ServerIp, sizeof (IP4_ADDR));\r
-    NetCopyMem (&Instance->Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));\r
+    CopyMem (&Instance->ServerIp, &Override->ServerIp, sizeof (IP4_ADDR));\r
+    CopyMem (&Instance->Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));\r
 \r
     Instance->ServerIp      = NTOHL (Instance->ServerIp);\r
     Instance->Gateway       = NTOHL (Instance->Gateway);\r
@@ -737,6 +738,11 @@ Mtftp4Start (
     goto ON_ERROR;\r
   }\r
 \r
+  //\r
+  // Set initial status.\r
+  //\r
+  Token->Status = EFI_NOT_READY;\r
+\r
   //\r
   // Build and send an initial requests\r
   //\r
@@ -746,21 +752,20 @@ Mtftp4Start (
     Status = Mtftp4RrqStart (Instance, Operation);\r
   }\r
 \r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
   if (EFI_ERROR (Status)) {\r
     goto ON_ERROR;\r
   }\r
-  //\r
-  // Return immediately for asynchronous operation or poll the\r
-  // instance for synchronous operation.\r
-  //\r
-  Token->Status = EFI_NOT_READY;\r
 \r
   if (Token->Event != NULL) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  //\r
+  // Return immediately for asynchronous operation or poll the\r
+  // instance for synchronous operation.\r
+  //\r
   while (Token->Status == EFI_NOT_READY) {\r
     This->Poll (This);\r
   }\r
@@ -769,7 +774,7 @@ Mtftp4Start (
 \r
 ON_ERROR:\r
   Mtftp4CleanOperation (Instance, Status);\r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r
 }\r
@@ -787,7 +792,6 @@ ON_ERROR:
   @retval Others                 Some error happened.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4ReadFile (\r
@@ -811,7 +815,6 @@ EfiMtftp4ReadFile (
   @retval Others                 Some error happened.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4WriteFile (\r
@@ -836,7 +839,6 @@ EfiMtftp4WriteFile (
   @retval Others                 Some error happened.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4ReadDirectory (\r
@@ -858,7 +860,6 @@ EfiMtftp4ReadDirectory (
   @retval EFI_DEVICE_ERROR       The MTFTP session has been destoried.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 EfiMtftp4Poll (\r