]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c
1. Fix timer unit bug in MNP: default rx/tx timeout value should be 10,000,000 (10s...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpMain.c
index 2ca3d7917f3a80c39fd09212616559022413a02a..86004cda84323ef21ad87e78d2c8613edbd18194 100644 (file)
@@ -1,8 +1,7 @@
 /** @file\r
   Implementation of Managed Network Protocol public services.\r
-  \r
-Copyright (c) 2005 - 2007, Intel Corporation.<BR>\r
 \r
+Copyright (c) 2005 - 2009, 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
@@ -12,11 +11,8 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
-#include "MnpImpl.h"\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/BaseLib.h>\r
-\r
 \r
+#include "MnpImpl.h"\r
 \r
 /**\r
   Returns the operational parameters for the current MNP child driver. May also\r
@@ -40,14 +36,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @retval EFI_NOT_STARTED       This MNP child driver instance has not been\r
                                 configured. The default values are returned in\r
                                 MnpConfigData if it is not NULL.\r
-  @retval Other                 The mode data could not be read.\r
+  @retval Others                The mode data could not be read.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 MnpGetModeData (\r
   IN  EFI_MANAGED_NETWORK_PROTOCOL     *This,\r
-  OUT EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData  OPTIONAL,\r
+  OUT EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData, OPTIONAL\r
   OUT EFI_SIMPLE_NETWORK_MODE          *SnpModeData    OPTIONAL\r
   )\r
 {\r
@@ -76,7 +72,7 @@ MnpGetModeData (
     //\r
     // Copy the underlayer Snp mode data.\r
     //\r
-    Snp           = Instance->MnpServiceData->Snp;\r
+    Snp = Instance->MnpServiceData->Snp;\r
     CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r
   }\r
 \r
@@ -114,13 +110,13 @@ MnpGetModeData (
   Note: Warning: Receive filter settings that overlap will consume extra\r
   processor and/or DMA resources and degrade system and network performance.\r
 \r
-  @param[in]  This             Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
-  @param[in]  MnpConfigData    Pointer to configuration data that will be assigned\r
-                               to the MNP child driver instance. If NULL, the MNP\r
-                               child driver instance is reset to startup defaults\r
-                               and all pending transmit and receive requests are\r
-                               flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is\r
-                               defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().\r
+  @param[in]  This           Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
+  @param[in]  MnpConfigData  Pointer to configuration data that will be assigned\r
+                             to the MNP child driver instance. If NULL, the MNP\r
+                             child driver instance is reset to startup defaults\r
+                             and all pending transmit and receive requests are\r
+                             flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is\r
+                             defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().\r
 \r
   @retval EFI_SUCCESS            The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER  One or more of the following conditions is\r
@@ -140,7 +136,7 @@ MnpGetModeData (
   @retval EFI_DEVICE_ERROR       An unexpected network or system error\r
                                  occurred. The MNP child driver instance has\r
                                  been reset to startup defaults.\r
-  @retval Other                  The MNP child driver instance has been reset to\r
+  @retval Others                 The MNP child driver instance has been reset to\r
                                  startup defaults.\r
 \r
 **/\r
@@ -193,15 +189,15 @@ ON_EXIT:
    \r
   The McastIpToMac() function translates an IP multicast address to a hardware\r
   (MAC) multicast address. This function may be implemented by calling the\r
-  underlying EFI_SIMPLE_NETWORK.MCastIpToMac() function, which may also be\r
+  underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be\r
   unsupported in some MNP implementations.\r
 \r
-  @param[in]  This       Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
-  @param[in]  Ipv6Flag   Set to TRUE to if IpAddress is an IPv6 multicast address.\r
-                         Set to FALSE if IpAddress is an IPv4 multicast address.\r
-  @param[in]  IpAddress  Pointer to the multicast IP address (in network byte order)\r
-                         to convert.\r
-  @param[out] MacAddress Pointer to the resulting multicast MAC address. \r
+  @param[in]  This        Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
+  @param[in]  Ipv6Flag    Set to TRUE to if IpAddress is an IPv6 multicast address.\r
+                          Set to FALSE if IpAddress is an IPv4 multicast address.\r
+  @param[in]  IpAddress   Pointer to the multicast IP address (in network byte\r
+                          order) to convert.\r
+  @param[out] MacAddress  Pointer to the resulting multicast MAC address. \r
 \r
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r
@@ -215,7 +211,7 @@ ON_EXIT:
   @retval EFI_UNSUPPORTED       The requested feature is unsupported in this\r
                                 MNP implementation.\r
   @retval EFI_DEVICE_ERROR      An unexpected network or system error occurred.\r
-  @retval Other                 The address could not be converted.\r
+  @retval Others                The address could not be converted.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -230,22 +226,20 @@ MnpMcastIpToMac (
   MNP_INSTANCE_DATA           *Instance;\r
   EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
   EFI_TPL                     OldTpl;\r
+  EFI_IPv6_ADDRESS            *Ip6Address;\r
 \r
   if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (Ipv6Flag) {\r
-    //\r
-    // Currently IPv6 isn't supported.\r
-    //\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  Ip6Address = &IpAddress->v6;\r
 \r
-  if (!IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress))) {\r
+  if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||\r
+      (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))\r
+      ) {\r
     //\r
-    // The IPv4 address passed in is not a multicast address.\r
+    // The IP address passed in is not a multicast address.\r
     //\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -263,17 +257,33 @@ MnpMcastIpToMac (
   Snp = Instance->MnpServiceData->Snp;\r
   ASSERT (Snp != NULL);\r
 \r
+  ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));  \r
+\r
   if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
-    //\r
-    // Translate the IPv4 address into a multicast MAC address if the NIC is an\r
-    // ethernet NIC.\r
-    //\r
-    MacAddress->Addr[0] = 0x01;\r
-    MacAddress->Addr[1] = 0x00;\r
-    MacAddress->Addr[2] = 0x5E;\r
-    MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);\r
-    MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r
-    MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r
+    if (!Ipv6Flag) {\r
+      //\r
+      // Translate the IPv4 address into a multicast MAC address if the NIC is an\r
+      // ethernet NIC according to RFC1112..\r
+      //\r
+      MacAddress->Addr[0] = 0x01;\r
+      MacAddress->Addr[1] = 0x00;\r
+      MacAddress->Addr[2] = 0x5E;\r
+      MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);\r
+      MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r
+      MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r
+    } else {\r
+      //\r
+      // Translate the IPv6 address into a multicast MAC address if the NIC is an \r
+      // ethernet NIC according to RFC2464.\r
+      //\r
+      \r
+      MacAddress->Addr[0] = 0x33;\r
+      MacAddress->Addr[1] = 0x33;\r
+      MacAddress->Addr[2] = Ip6Address->Addr[12];\r
+      MacAddress->Addr[3] = Ip6Address->Addr[13];\r
+      MacAddress->Addr[4] = Ip6Address->Addr[14];\r
+      MacAddress->Addr[5] = Ip6Address->Addr[15];\r
+    }\r
 \r
     Status = EFI_SUCCESS;\r
   } else {\r
@@ -326,7 +336,7 @@ ON_EXIT:
                                 startup defaults.\r
   @retval EFI_UNSUPPORTED       The requested feature is unsupported in this MNP\r
                                 implementation.\r
-  @retval Other                 The requested operation could not be completed.\r
+  @retval Others                The requested operation could not be completed.\r
                                 The MNP multicast group settings are unchanged.\r
 \r
 **/\r
@@ -457,8 +467,8 @@ ON_EXIT:
  \r
   @param[in]  This    Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token   Pointer to a token associated with the transmit data\r
-                      descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN is\r
-                      defined in "Related Definitions" below.\r
+                      descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN\r
+                      is defined in "Related Definitions" below.\r
 \r
   @retval EFI_SUCCESS            The transmit completion token was cached.\r
   @retval EFI_NOT_STARTED        This MNP child driver instance has not been\r
@@ -562,11 +572,11 @@ ON_EXIT:
   updates the Token.Status and Token.RxData fields and the Token.Event is\r
   signaled.\r
    \r
-  @param[in]  This          Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
-  @param[in]  Token         Pointer to a token associated with the receive\r
-                            data descriptor. Type\r
-                            EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r
-                            EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r
+  @param[in]  This      Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
+  @param[in]  Token     Pointer to a token associated with the receive\r
+                        data descriptor. Type\r
+                        EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r
+                        EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r
 \r
   @retval EFI_SUCCESS            The receive completion token was cached.\r
   @retval EFI_NOT_STARTED        This MNP child driver instance has not been\r
@@ -636,7 +646,7 @@ MnpReceive (
     //\r
     // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
     //\r
-    NetLibDispatchDpc ();\r
+    DispatchDpc ();\r
   }\r
 \r
 ON_EXIT:\r
@@ -658,8 +668,8 @@ ON_EXIT:
   @param[in]  This     Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  Token    Pointer to a token that has been issued by\r
                        EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r
-                       EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all pending\r
-                       tokens are aborted.\r
+                       EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all \r
+                       pending tokens are aborted.\r
 \r
   @retval EFI_SUCCESS            The asynchronous I/O request was aborted and\r
                                  Token.Event was signaled. When Token is NULL,\r
@@ -713,7 +723,7 @@ MnpCancel (
   //\r
   // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.\r
   //\r
-  NetLibDispatchDpc ();\r
+  DispatchDpc ();\r
 \r
 ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r
@@ -733,7 +743,7 @@ ON_EXIT:
   applications that are experiencing packet loss should try calling the Poll()\r
   function more often.\r
 \r
-  @param[in]  This            Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
+  @param[in]  This         Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
 \r
   @retval EFI_SUCCESS      Incoming or outgoing data was processed.\r
   @retval EFI_NOT_STARTED  This MNP child driver instance has not been\r
@@ -775,7 +785,10 @@ MnpPoll (
   //\r
   Status = MnpReceivePacket (Instance->MnpServiceData);\r
 \r
-  NetLibDispatchDpc ();\r
+  //\r
+  // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
+  //\r
+  DispatchDpc ();\r
 \r
 ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r