]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
For network dynamic media support:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Impl.c
index 05fd96d634cd98c2badf90b214265316fe543c65..06358f06ef46ce26e882f755f8e51e387cbaeeda 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
+Copyright (c) 2005 - 2010, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -17,7 +17,7 @@ EFI_IPSEC_PROTOCOL    *mIpSec = NULL;
 \r
 /**\r
   Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.\r
-  \r
+\r
   The GetModeData() function returns the current operational mode data for this\r
   driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This\r
   function is used optionally to retrieve the operational mode data of underlying\r
@@ -41,10 +41,10 @@ EfiIp4GetModeData (
   OUT       EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData   OPTIONAL,\r
   OUT       EFI_SIMPLE_NETWORK_MODE         *SnpModeData     OPTIONAL\r
   );\r
-  \r
+\r
 /**\r
   Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.\r
-  \r
+\r
   The Configure() function is used to set, change, or reset the operational\r
   parameters and filter settings for this EFI IPv4 Protocol instance. Until these\r
   parameters have been set, no network traffic can be sent or received by this\r
@@ -53,14 +53,14 @@ EfiIp4GetModeData (
   parameters have been set again. Each EFI IPv4 Protocol instance can be started\r
   and stopped independently of each other by enabling or disabling their receive\r
   filter settings with the Configure() function.\r
-  \r
+\r
   When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will\r
   be appended as an alias address into the addresses list in the EFI IPv4 Protocol\r
   driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL\r
   to retrieve the default IPv4 address if it is not available yet. Clients could\r
   frequently call GetModeData() to check the status to ensure that the default IPv4\r
   address is ready.\r
-  \r
+\r
   If operational parameters are reset or changed, any pending transmit and receive\r
   requests will be cancelled. Their completion token status will be set to EFI_ABORTED\r
   and their events will be signaled.\r
@@ -91,14 +91,14 @@ EfiIp4Configure (
   IN EFI_IP4_PROTOCOL       *This,\r
   IN EFI_IP4_CONFIG_DATA    *IpConfigData       OPTIONAL\r
   );\r
-  \r
+\r
 /**\r
   Joins and leaves multicast groups.\r
-  \r
+\r
   The Groups() function is used to join and leave multicast group sessions. Joining\r
   a group will enable reception of matching multicast packets. Leaving a group will\r
   disable the multicast packet reception.\r
-  \r
+\r
   If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.\r
 \r
   @param[in]  This                  Pointer to the EFI_IP4_PROTOCOL instance.\r
@@ -129,25 +129,25 @@ EfiIp4Groups (
   IN BOOLEAN                JoinFlag,\r
   IN EFI_IPv4_ADDRESS       *GroupAddress     OPTIONAL\r
   );\r
-  \r
+\r
 /**\r
   Adds and deletes routing table entries.\r
 \r
   The Routes() function adds a route to or deletes a route from the routing table.\r
-  \r
+\r
   Routes are determined by comparing the SubnetAddress with the destination IPv4\r
   address arithmetically AND-ed with the SubnetMask. The gateway address must be\r
   on the same subnet as the configured station address.\r
-  \r
+\r
   The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.\r
   The default route matches all destination IPv4 addresses that do not match any\r
   other routes.\r
-  \r
+\r
   A GatewayAddress that is zero is a nonroute. Packets are sent to the destination\r
   IP address if it can be found in the ARP cache or on the local subnet. One automatic\r
   nonroute entry will be inserted into the routing table for outgoing packets that\r
   are addressed to a local subnet (gateway address of 0.0.0.0).\r
-  \r
+\r
   Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI\r
   IPv4 Protocol instances that use the default IPv4 address will also have copies\r
   of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these\r
@@ -178,7 +178,7 @@ EfiIp4Groups (
   @retval EFI_NOT_FOUND          This route is not in the routing table (when DeleteRoute is TRUE).\r
   @retval EFI_ACCESS_DENIED      The route is already defined in the routing table (when\r
                                   DeleteRoute is FALSE).\r
-                                 \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -189,7 +189,7 @@ EfiIp4Routes (
   IN EFI_IPv4_ADDRESS       *SubnetMask,\r
   IN EFI_IPv4_ADDRESS       *GatewayAddress\r
   );\r
-  \r
+\r
 /**\r
   Places outgoing data packets into the transmit queue.\r
 \r
@@ -208,7 +208,7 @@ EfiIp4Routes (
   @retval  EFI_ACCESS_DENIED     The transmit completion token with the same Token.Event\r
                                  was already in the transmit queue.\r
   @retval  EFI_NOT_READY         The completion token could not be queued because the transmit\r
-                                 queue is full. \r
+                                 queue is full.\r
   @retval  EFI_NOT_FOUND         Not route is found to destination address.\r
   @retval  EFI_OUT_OF_RESOURCES  Could not queue the transmit data.\r
   @retval  EFI_BUFFER_TOO_SMALL  Token.Packet.TxData.TotalDataLength is too\r
@@ -225,13 +225,13 @@ EfiIp4Transmit (
   IN EFI_IP4_PROTOCOL         *This,\r
   IN EFI_IP4_COMPLETION_TOKEN *Token\r
   );\r
-  \r
+\r
 /**\r
   Places a receiving request into the receiving queue.\r
-  \r
+\r
   The Receive() function places a completion token into the receive packet queue.\r
   This function is always asynchronous.\r
-  \r
+\r
   The Token.Event field in the completion token must be filled in by the caller\r
   and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol\r
   driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event\r
@@ -264,10 +264,10 @@ EfiIp4Receive (
   IN EFI_IP4_PROTOCOL         *This,\r
   IN EFI_IP4_COMPLETION_TOKEN *Token\r
   );\r
-  \r
+\r
 /**\r
   Abort an asynchronous transmit or receive request.\r
-  \r
+\r
   The Cancel() function is used to abort a pending transmit or receive request.\r
   If the token is in the transmit or receive request queues, after calling this\r
   function, Token->Status will be set to EFI_ABORTED and then Token->Event will\r
@@ -300,15 +300,15 @@ EfiIp4Cancel (
   IN EFI_IP4_PROTOCOL         *This,\r
   IN EFI_IP4_COMPLETION_TOKEN *Token    OPTIONAL\r
   );\r
-  \r
+\r
 /**\r
   Polls for incoming data packets and processes outgoing data packets.\r
-  \r
+\r
   The Poll() function polls for incoming data packets and processes outgoing data\r
   packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()\r
   function to increase the rate that data packets are moved between the communications\r
   device and the transmit and receive queues.\r
-  \r
+\r
   In some systems the periodic timer event may not poll the underlying communications\r
   device fast enough to transmit and/or receive all data packets without missing\r
   incoming packets or dropping outgoing packets. Drivers and applications that are\r
@@ -348,7 +348,7 @@ mEfiIp4ProtocolTemplete = {
 \r
 /**\r
   Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.\r
-  \r
+\r
   The GetModeData() function returns the current operational mode data for this\r
   driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This\r
   function is used optionally to retrieve the operational mode data of underlying\r
@@ -440,16 +440,13 @@ EfiIp4GetModeData (
     }\r
   }\r
 \r
-  if (MnpConfigData != NULL) {\r
-    CopyMem (MnpConfigData, &IpSb->MnpConfigData, sizeof (*MnpConfigData));\r
-  }\r
-\r
-  if (SnpModeData != NULL) {\r
-    CopyMem (SnpModeData, &IpSb->SnpMode, sizeof (*SnpModeData));\r
-  }\r
+  //\r
+  // Get fresh mode data from MNP, since underlying media status may change\r
+  //\r
+  Status = IpSb->Mnp->GetModeData (IpSb->Mnp, MnpConfigData, SnpModeData);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 \r
@@ -687,7 +684,7 @@ ON_EXIT:
 \r
 /**\r
   Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.\r
-  \r
+\r
   @param Event     The event that is signalled.\r
   @param Context   The IP4 service binding instance.\r
 \r
@@ -1126,7 +1123,7 @@ Ip4StationAddressValid (
 \r
 /**\r
   Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.\r
-  \r
+\r
   The Configure() function is used to set, change, or reset the operational\r
   parameters and filter settings for this EFI IPv4 Protocol instance. Until these\r
   parameters have been set, no network traffic can be sent or received by this\r
@@ -1135,14 +1132,14 @@ Ip4StationAddressValid (
   parameters have been set again. Each EFI IPv4 Protocol instance can be started\r
   and stopped independently of each other by enabling or disabling their receive\r
   filter settings with the Configure() function.\r
-  \r
+\r
   When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will\r
   be appended as an alias address into the addresses list in the EFI IPv4 Protocol\r
   driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL\r
   to retrieve the default IPv4 address if it is not available yet. Clients could\r
   frequently call GetModeData() to check the status to ensure that the default IPv4\r
   address is ready.\r
-  \r
+\r
   If operational parameters are reset or changed, any pending transmit and receive\r
   requests will be cancelled. Their completion token status will be set to EFI_ABORTED\r
   and their events will be signaled.\r
@@ -1318,7 +1315,7 @@ Ip4Groups (
   // host byte order\r
   //\r
   if (JoinFlag) {\r
-    //  \r
+    //\r
     // When JoinFlag is TRUE, GroupAddress shouldn't be NULL.\r
     //\r
     ASSERT (GroupAddress != NULL);\r
@@ -1386,11 +1383,11 @@ Ip4Groups (
 \r
 /**\r
   Joins and leaves multicast groups.\r
-  \r
+\r
   The Groups() function is used to join and leave multicast group sessions. Joining\r
   a group will enable reception of matching multicast packets. Leaving a group will\r
   disable the multicast packet reception.\r
-  \r
+\r
   If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.\r
 \r
   @param[in]  This                  Pointer to the EFI_IP4_PROTOCOL instance.\r
@@ -1464,20 +1461,20 @@ ON_EXIT:
   Adds and deletes routing table entries.\r
 \r
   The Routes() function adds a route to or deletes a route from the routing table.\r
-  \r
+\r
   Routes are determined by comparing the SubnetAddress with the destination IPv4\r
   address arithmetically AND-ed with the SubnetMask. The gateway address must be\r
   on the same subnet as the configured station address.\r
-  \r
+\r
   The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.\r
   The default route matches all destination IPv4 addresses that do not match any\r
   other routes.\r
-  \r
+\r
   A GatewayAddress that is zero is a nonroute. Packets are sent to the destination\r
   IP address if it can be found in the ARP cache or on the local subnet. One automatic\r
   nonroute entry will be inserted into the routing table for outgoing packets that\r
   are addressed to a local subnet (gateway address of 0.0.0.0).\r
-  \r
+\r
   Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI\r
   IPv4 Protocol instances that use the default IPv4 address will also have copies\r
   of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these\r
@@ -1508,7 +1505,7 @@ ON_EXIT:
   @retval EFI_NOT_FOUND          This route is not in the routing table (when DeleteRoute is TRUE).\r
   @retval EFI_ACCESS_DENIED      The route is already defined in the routing table (when\r
                                   DeleteRoute is FALSE).\r
-                                 \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1693,7 +1690,7 @@ Ip4TxTokenValid (
   // Check the source and gateway: they must be a valid unicast.\r
   // Gateway must also be on the connected network.\r
   //\r
-  if (TxData->OverrideData) {\r
+  if (TxData->OverrideData != NULL) {\r
     Override = TxData->OverrideData;\r
 \r
     CopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR));\r
@@ -1857,7 +1854,7 @@ Ip4OnPacketSent (
   @retval  EFI_ACCESS_DENIED     The transmit completion token with the same Token.Event\r
                                  was already in the transmit queue.\r
   @retval  EFI_NOT_READY         The completion token could not be queued because the transmit\r
-                                 queue is full. \r
+                                 queue is full.\r
   @retval  EFI_NOT_FOUND         Not route is found to destination address.\r
   @retval  EFI_OUT_OF_RESOURCES  Could not queue the transmit data.\r
   @retval  EFI_BUFFER_TOO_SMALL  Token.Packet.TxData.TotalDataLength is too\r
@@ -1936,7 +1933,7 @@ EfiIp4Transmit (
   CopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR));\r
   Head.Dst = NTOHL (Head.Dst);\r
 \r
-  if (TxData->OverrideData) {\r
+  if (TxData->OverrideData != NULL) {\r
     Override      = TxData->OverrideData;\r
     Head.Protocol = Override->Protocol;\r
     Head.Tos      = Override->TypeOfService;\r
@@ -2039,10 +2036,10 @@ ON_EXIT:
 \r
 /**\r
   Places a receiving request into the receiving queue.\r
-  \r
+\r
   The Receive() function places a completion token into the receive packet queue.\r
   This function is always asynchronous.\r
-  \r
+\r
   The Token.Event field in the completion token must be filled in by the caller\r
   and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol\r
   driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event\r
@@ -2310,7 +2307,7 @@ Ip4Cancel (
 \r
 /**\r
   Abort an asynchronous transmit or receive request.\r
-  \r
+\r
   The Cancel() function is used to abort a pending transmit or receive request.\r
   If the token is in the transmit or receive request queues, after calling this\r
   function, Token->Status will be set to EFI_ABORTED and then Token->Event will\r
@@ -2376,12 +2373,12 @@ ON_EXIT:
 \r
 /**\r
   Polls for incoming data packets and processes outgoing data packets.\r
-  \r
+\r
   The Poll() function polls for incoming data packets and processes outgoing data\r
   packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()\r
   function to increase the rate that data packets are moved between the communications\r
   device and the transmit and receive queues.\r
-  \r
+\r
   In some systems the periodic timer event may not poll the underlying communications\r
   device fast enough to transmit and/or receive all data packets without missing\r
   incoming packets or dropping outgoing packets. Drivers and applications that are\r