]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c
1.Fix a bug in Dhcp4Dxe driver to correct the ‘secs’ field in DHCP message.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcDriver.c
index 102f68586ac421bc03d4ff1d1a0c3de99b0b9241..0efcda58e56ea3ebfdaf69b22fa3a52ec5084693 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   The driver binding for UEFI PXEBC protocol.\r
-  \r
-Copyright (c) 2007 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+\r
+Copyright (c) 2007 - 2011, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -60,7 +60,7 @@ PxeBcDriverEntryPoint (
   order to make drivers as small as possible, there are a few calling\r
   restrictions for this service. ConnectController() must\r
   follow these calling restrictions. If any other agent wishes to call\r
-  Supported() it must also follow these calling restrictions.  \r
+  Supported() it must also follow these calling restrictions.\r
   PxeBc requires DHCP4 and MTFTP4 protocols.\r
 \r
   @param  This                Protocol instance pointer.\r
@@ -152,6 +152,7 @@ PxeBcDriverBindingStart (
   PXEBC_PRIVATE_DATA  *Private;\r
   UINTN               Index;\r
   EFI_STATUS          Status;\r
+  EFI_IP4_MODE_DATA   Ip4ModeData;\r
 \r
   Private = AllocateZeroPool (sizeof (PXEBC_PRIVATE_DATA));\r
   if (Private == NULL) {\r
@@ -174,7 +175,7 @@ PxeBcDriverBindingStart (
   }\r
 \r
   //\r
-  // Get the NII interface\r
+  // Get the NII interface if it exists.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -185,7 +186,7 @@ PxeBcDriverBindingStart (
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
+    Private->Nii = NULL;\r
   }\r
 \r
   Status = NetLibCreateServiceChild (\r
@@ -253,6 +254,16 @@ PxeBcDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     goto ON_ERROR;\r
   }\r
+
+  //
+  // Get max packet size from Ip4 to calculate block size for Tftp later.\r
+  //
+  Status = Private->Ip4->GetModeData (Private->Ip4, &Ip4ModeData, NULL, NULL);
+  if (EFI_ERROR (Status)) {
+    goto ON_ERROR;
+  }
+
+  Private->Ip4MaxPacketSize = Ip4ModeData.MaxPacketSize;\r
 \r
   Status = NetLibCreateServiceChild (\r
              ControllerHandle,\r
@@ -309,7 +320,7 @@ PxeBcDriverBindingStart (
   // The UDP instance for EfiPxeBcUdpWrite\r
   //\r
   Status = NetLibCreateServiceChild (\r
-             ControllerHandle, \r
+             ControllerHandle,\r
              This->DriverBindingHandle,\r
              &gEfiUdp4ServiceBindingProtocolGuid,\r
              &Private->Udp4WriteChild\r
@@ -330,14 +341,14 @@ PxeBcDriverBindingStart (
     goto ON_ERROR;\r
   }\r
   ZeroMem (&Private->Udp4CfgData, sizeof (EFI_UDP4_CONFIG_DATA));\r
-  Private->Udp4CfgData.AcceptBroadcast    = TRUE;\r
+  Private->Udp4CfgData.AcceptBroadcast    = FALSE;\r
   Private->Udp4CfgData.AcceptPromiscuous  = FALSE;\r
   Private->Udp4CfgData.AcceptAnyPort      = TRUE;\r
   Private->Udp4CfgData.AllowDuplicatePort = TRUE;\r
   Private->Udp4CfgData.TypeOfService      = DEFAULT_ToS;\r
   Private->Udp4CfgData.TimeToLive         = DEFAULT_TTL;\r
   Private->Udp4CfgData.DoNotFragment      = FALSE;\r
-  Private->Udp4CfgData.ReceiveTimeout     = 50000;  // 50 milliseconds\r
+  Private->Udp4CfgData.ReceiveTimeout     = PXEBC_DEFAULT_LIFETIME;\r
   Private->Udp4CfgData.UseDefaultAddress  = FALSE;\r
 \r
   PxeBcInitSeedPacket (&Private->SeedPacket, Private->Udp4Read);\r
@@ -463,7 +474,7 @@ ON_ERROR:
       );\r
   }\r
 \r
-  gBS->FreePool (Private);\r
+  FreePool (Private);\r
 \r
   return Status;\r
 }\r
@@ -476,7 +487,7 @@ ON_ERROR:
   restrictions for this service. DisconnectController()\r
   must follow these calling restrictions. If any other agent wishes\r
   to call Stop() it must also follow these calling restrictions.\r
-  \r
+\r
   @param  This              Protocol instance pointer.\r
   @param  ControllerHandle  Handle of device to stop driver on\r
   @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
@@ -535,6 +546,14 @@ PxeBcDriverBindingStop (
     return Status;\r
   }\r
 \r
+  //\r
+  // Stop functionality of PXE Base Code protocol\r
+  //\r
+  Status = PxeBc->Stop (PxeBc);\r
+  if (Status != EFI_SUCCESS && Status != EFI_NOT_STARTED) {\r
+    return Status;\r
+  }\r
+\r
   Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (PxeBc);\r
 \r
   Status = gBS->UninstallMultipleProtocolInterfaces (\r
@@ -626,7 +645,7 @@ PxeBcDriverBindingStop (
       Private->ArpChild\r
       );\r
 \r
-    gBS->FreePool (Private);\r
+    FreePool (Private);\r
   }\r
 \r
   return Status;\r