]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
FmpDevicePkg FmpDxe: Return UNSUPPORTED if device has been locked
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcImpl.c
index 36477e9f80d9d12087460296984c96bc003851bf..13396903f5853176d55667488ff4095641f4842f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This implementation of EFI_PXE_BASE_CODE_PROTOCOL and EFI_LOAD_FILE_PROTOCOL.\r
 \r
-  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2018, 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
@@ -91,7 +91,7 @@ EfiPxeBcStart (
     if (EFI_ERROR (Status)) {\r
       goto ON_ERROR;\r
     }\r
-    \r
+\r
     //\r
     // Configure block size for TFTP as a default value to handle all link layers.\r
     //\r
@@ -144,7 +144,7 @@ EfiPxeBcStart (
     if (EFI_ERROR (Status)) {\r
       goto ON_ERROR;\r
     }\r
-    \r
+\r
     //\r
     // Configure block size for TFTP as a default value to handle all link layers.\r
     //\r
@@ -206,10 +206,10 @@ 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
@@ -745,13 +745,13 @@ ON_EXIT:
   if (NewCreatedInfo != NULL && NewCreatedInfo != &DefaultInfo) {\r
     FreePool (NewCreatedInfo);\r
   }\r
-  \r
+\r
   if (Mode->UsingIpv6) {\r
     Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData);\r
   } else {\r
     Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r
   }\r
-  \r
+\r
   //\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
@@ -855,11 +855,19 @@ EfiPxeBcMtftp (
       (Filename == NULL) ||\r
       (BufferSize == NULL) ||\r
       (ServerIp == NULL) ||\r
-      ((BufferPtr == NULL) && DontUseBuffer) ||\r
       ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (Operation == EFI_PXE_BASE_CODE_TFTP_READ_FILE ||\r
+      Operation == EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY ||\r
+      Operation == EFI_PXE_BASE_CODE_MTFTP_READ_FILE ||\r
+      Operation == EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY) {\r
+    if (BufferPtr == NULL && !DontUseBuffer) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
   Config    = NULL;\r
   Status    = EFI_DEVICE_ERROR;\r
   Private   = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r
@@ -1085,7 +1093,8 @@ EfiPxeBcUdpWrite (
     DoNotFragment = TRUE;\r
   }\r
 \r
-  if (!Mode->UsingIpv6 && GatewayIp != NULL && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), EFI_NTOHL(Mode->SubnetMask))) {\r
+  if (!Mode->UsingIpv6 && GatewayIp != NULL && Mode->SubnetMask.Addr[0] != 0 &&\r
+      !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), EFI_NTOHL(Mode->SubnetMask))) {\r
     //\r
     // Gateway is provided but it's not a unicast IPv4 address, while it will be ignored for IPv6.\r
     //\r
@@ -1650,13 +1659,13 @@ EfiPxeBcSetIpFilter (
     //\r
     Udp4Cfg = &Private->Udp4CfgData;\r
     if ((AcceptPromiscuous != Udp4Cfg->AcceptPromiscuous)   ||\r
-         (AcceptBroadcast != Udp4Cfg->AcceptBroadcast)     || MultiCastUpdate) {\r
+        (AcceptBroadcast != Udp4Cfg->AcceptBroadcast)     || MultiCastUpdate) {\r
       //\r
       // Clear the UDP4 instance configuration, all joined groups will be left\r
       // during the operation.\r
       //\r
       Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
-  \r
+\r
       //\r
       // Configure the UDP instance with the new configuration.\r
       //\r
@@ -1666,7 +1675,7 @@ EfiPxeBcSetIpFilter (
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
-  \r
+\r
       //\r
       // In not Promiscuous mode, need to join the new multicast group.\r
       //\r
@@ -1695,7 +1704,7 @@ EfiPxeBcSetIpFilter (
       // during the operation.\r
       //\r
       Private->Udp6Read->Configure (Private->Udp6Read, NULL);\r
-  \r
+\r
       //\r
       // Configure the UDP instance with the new configuration.\r
       //\r
@@ -1704,7 +1713,7 @@ EfiPxeBcSetIpFilter (
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
-  \r
+\r
       //\r
       // In not Promiscuous mode, need to join the new multicast group.\r
       //\r
@@ -1924,7 +1933,7 @@ EfiPxeBcSetParameters (
       // Update the previous PxeBcCallback protocol.\r
       //\r
       Status = gBS->HandleProtocol (\r
-                      Private->Controller,\r
+                      Mode->UsingIpv6 ? Private->Ip6Nic->Controller : Private->Ip4Nic->Controller,\r
                       &gEfiPxeBaseCodeCallbackProtocolGuid,\r
                       (VOID **) &Private->PxeBcCallback\r
                       );\r
@@ -1940,6 +1949,7 @@ EfiPxeBcSetParameters (
 \r
   if (NewSendGUID != NULL) {\r
     if (*NewSendGUID && EFI_ERROR (NetLibGetSystemGuid (&SystemGuid))) {\r
+      DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbios table!\n"));\r
       return EFI_INVALID_PARAMETER;\r
     }\r
     Mode->SendGUID = *NewSendGUID;\r
@@ -1993,7 +2003,6 @@ EfiPxeBcSetStationIP (
   EFI_STATUS              Status;\r
   PXEBC_PRIVATE_DATA      *Private;\r
   EFI_PXE_BASE_CODE_MODE  *Mode;\r
-  EFI_ARP_CONFIG_DATA     ArpConfigData;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2014,13 +2023,13 @@ EfiPxeBcSetStationIP (
   }\r
 \r
   if (!Mode->UsingIpv6 && NewStationIp != NULL) {\r
-    if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) || \r
+    if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) ||\r
         IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp->Addr[0])) ||\r
-        (NewSubnetMask != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->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
+\r
   if (!Mode->Started) {\r
     return EFI_NOT_STARTED;\r
   }\r
@@ -2033,27 +2042,6 @@ EfiPxeBcSetStationIP (
     if (EFI_ERROR (Status)) {\r
       goto ON_EXIT;\r
     }\r
-  } else if (!Mode->UsingIpv6 && NewStationIp != NULL) {\r
-    //\r
-    // Configure the corresponding ARP with the IPv4 address.\r
-    //\r
-    ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r
-\r
-    ArpConfigData.SwAddressType   = 0x0800;\r
-    ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);\r
-    ArpConfigData.StationAddress  = &NewStationIp->v4;\r
-\r
-    Private->Arp->Configure (Private->Arp, NULL);\r
-    Private->Arp->Configure (Private->Arp, &ArpConfigData);\r
-\r
-    if (NewSubnetMask != NULL) {\r
-      Mode->RouteTableEntries                = 1;\r
-      Mode->RouteTable[0].IpAddr.Addr[0]     = NewStationIp->Addr[0] & NewSubnetMask->Addr[0];\r
-      Mode->RouteTable[0].SubnetMask.Addr[0] = NewSubnetMask->Addr[0];\r
-      Mode->RouteTable[0].GwAddr.Addr[0]     = 0;\r
-    }\r
-\r
-    Private->IsAddressOk = TRUE;\r
   }\r
 \r
   if (NewStationIp != NULL) {\r
@@ -2067,6 +2055,10 @@ EfiPxeBcSetStationIP (
   }\r
 \r
   Status = PxeBcFlushStationIp (Private, NewStationIp, NewSubnetMask);\r
+  if (!EFI_ERROR (Status)) {\r
+    Private->IsAddressOk = TRUE;\r
+  }\r
+\r
 ON_EXIT:\r
   return Status;\r
 }\r
@@ -2346,19 +2338,9 @@ EfiPxeLoadFile (
   EFI_PXE_BASE_CODE_PROTOCOL  *PxeBc;\r
   BOOLEAN                     UsingIpv6;\r
   EFI_STATUS                  Status;\r
-  BOOLEAN                     MediaPresent;\r
+  EFI_STATUS                  MediaStatus;\r
 \r
-  if (FilePath == NULL || !IsDevicePathEnd (FilePath)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  VirtualNic = PXEBC_VIRTUAL_NIC_FROM_LOADFILE (This);\r
-  Private    = VirtualNic->Private;\r
-  PxeBc      = &Private->PxeBc;\r
-  UsingIpv6  = FALSE;\r
-  Status     = EFI_DEVICE_ERROR;\r
-\r
-  if (This == NULL || BufferSize == NULL) {\r
+  if (This == NULL || BufferSize == NULL || FilePath == NULL || !IsDevicePathEnd (FilePath)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -2369,12 +2351,18 @@ EfiPxeLoadFile (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  VirtualNic = PXEBC_VIRTUAL_NIC_FROM_LOADFILE (This);\r
+  Private    = VirtualNic->Private;\r
+  PxeBc      = &Private->PxeBc;\r
+  UsingIpv6  = FALSE;\r
+  Status     = EFI_DEVICE_ERROR;\r
+\r
   //\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
@@ -2415,7 +2403,7 @@ EfiPxeLoadFile (
   } else {\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 these programs which \r
+    // reset the DHCP4 child before we return. Otherwise these programs which\r
     // also need to use DHCP4 will be impacted.\r
     //\r
     if (!PxeBc->Mode->UsingIpv6) {\r