]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpMain.c
index 86004cda84323ef21ad87e78d2c8613edbd18194..d96178a1d9943a3b835c030a38be35a6d4b21094 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Implementation of Managed Network Protocol public services.\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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -16,10 +10,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 /**\r
   Returns the operational parameters for the current MNP child driver. May also\r
-  support returning the underlying SNP driver mode data.   \r
-   \r
+  support returning the underlying SNP driver mode data.\r
+\r
   The GetModeData() function is used to read the current mode data (operational\r
-  parameters) from the MNP or the underlying SNP. \r
+  parameters) from the MNP or the underlying SNP.\r
 \r
   @param[in]  This          Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type\r
@@ -28,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @param[out] SnpModeData   Pointer to storage for SNP operational parameters. This\r
                             feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE\r
                             is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.\r
\r
+\r
   @retval EFI_SUCCESS           The operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER This is NULL.\r
   @retval EFI_UNSUPPORTED       The requested feature is unsupported in this\r
@@ -42,18 +36,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 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_SIMPLE_NETWORK_MODE          *SnpModeData    OPTIONAL\r
+  IN     EFI_MANAGED_NETWORK_PROTOCOL      *This,\r
+     OUT EFI_MANAGED_NETWORK_CONFIG_DATA   *MnpConfigData OPTIONAL,\r
+     OUT EFI_SIMPLE_NETWORK_MODE           *SnpModeData OPTIONAL\r
   )\r
 {\r
   MNP_INSTANCE_DATA           *Instance;\r
   EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
   EFI_TPL                     OldTpl;\r
   EFI_STATUS                  Status;\r
+  UINT32                      InterruptStatus;\r
 \r
   if (This == NULL) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -72,7 +66,13 @@ MnpGetModeData (
     //\r
     // Copy the underlayer Snp mode data.\r
     //\r
-    Snp = Instance->MnpServiceData->Snp;\r
+    Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
+\r
+    //\r
+    // Upon successful return of GetStatus(), the Snp->Mode->MediaPresent\r
+    // will be updated to reflect any change of media status\r
+    //\r
+    Snp->GetStatus (Snp, &InterruptStatus, NULL);\r
     CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r
   }\r
 \r
@@ -89,9 +89,9 @@ MnpGetModeData (
 \r
 \r
 /**\r
-  Sets or clears the operational parameters for the MNP child driver. \r
-   \r
-  The Configure() function is used to set, change, or reset the operational \r
+  Sets or clears the operational parameters for the MNP child driver.\r
+\r
+  The Configure() function is used to set, change, or reset the operational\r
   parameters for the MNP child driver instance. Until the operational parameters\r
   have been set, no network traffic can be sent or received by this MNP child\r
   driver instance. Once the operational parameters have been reset, no more\r
@@ -143,8 +143,8 @@ MnpGetModeData (
 EFI_STATUS\r
 EFIAPI\r
 MnpConfigure (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL     *This,\r
-  IN EFI_MANAGED_NETWORK_CONFIG_DATA  *MnpConfigData OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL        *This,\r
+  IN EFI_MANAGED_NETWORK_CONFIG_DATA     *MnpConfigData OPTIONAL\r
   )\r
 {\r
   MNP_INSTANCE_DATA  *Instance;\r
@@ -152,10 +152,10 @@ MnpConfigure (
   EFI_STATUS         Status;\r
 \r
   if ((This == NULL) ||\r
-    ((MnpConfigData != NULL) &&\r
-    (MnpConfigData->ProtocolTypeFilter > 0) &&\r
-    (MnpConfigData->ProtocolTypeFilter <= 1500))) {\r
-\r
+      ((MnpConfigData != NULL) &&\r
+       (MnpConfigData->ProtocolTypeFilter > 0) &&\r
+       (MnpConfigData->ProtocolTypeFilter <= 1500))\r
+     ) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -184,9 +184,9 @@ ON_EXIT:
 \r
 \r
 /**\r
-  Translates an IP multicast address to a hardware (MAC) multicast address. This \r
-  function may be unsupported in some MNP implementations. \r
-   \r
+  Translates an IP multicast address to a hardware (MAC) multicast address. This\r
+  function may be unsupported in some MNP implementations.\r
+\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
@@ -197,7 +197,7 @@ ON_EXIT:
                           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
+  @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
@@ -216,10 +216,10 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpMcastIpToMac (\r
-  IN  EFI_MANAGED_NETWORK_PROTOCOL  *This,\r
-  IN  BOOLEAN                       Ipv6Flag,\r
-  IN  EFI_IP_ADDRESS                *IpAddress,\r
-  OUT EFI_MAC_ADDRESS               *MacAddress\r
+  IN     EFI_MANAGED_NETWORK_PROTOCOL    *This,\r
+  IN     BOOLEAN                         Ipv6Flag,\r
+  IN     EFI_IP_ADDRESS                  *IpAddress,\r
+     OUT EFI_MAC_ADDRESS                 *MacAddress\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -229,7 +229,6 @@ MnpMcastIpToMac (
   EFI_IPv6_ADDRESS            *Ip6Address;\r
 \r
   if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -254,10 +253,10 @@ MnpMcastIpToMac (
     goto ON_EXIT;\r
   }\r
 \r
-  Snp = Instance->MnpServiceData->Snp;\r
+  Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
   ASSERT (Snp != NULL);\r
 \r
-  ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));  \r
+  ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));\r
 \r
   if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
     if (!Ipv6Flag) {\r
@@ -273,10 +272,10 @@ MnpMcastIpToMac (
       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
+      // Translate the IPv6 address into a multicast MAC address if the NIC is an\r
       // ethernet NIC according to RFC2464.\r
       //\r
-      \r
+\r
       MacAddress->Addr[0] = 0x33;\r
       MacAddress->Addr[1] = 0x33;\r
       MacAddress->Addr[2] = Ip6Address->Addr[12];\r
@@ -305,14 +304,14 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  Enables and disables receive filters for multicast address. This function may \r
+  Enables and disables receive filters for multicast address. This function may\r
   be unsupported in some MNP implementations.\r
-   \r
-  The Groups() function only adds and removes multicast MAC addresses from the \r
+\r
+  The Groups() function only adds and removes multicast MAC addresses from the\r
   filter list. The MNP driver does not transmit or process Internet Group\r
   Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r
   NULL, then all joined groups are left.\r
-   \r
+\r
   @param[in]  This        Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
   @param[in]  JoinFlag    Set to TRUE to join this multicast group.\r
                           Set to FALSE to leave this multicast group.\r
@@ -343,9 +342,9 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpGroups (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL  *This,\r
-  IN BOOLEAN                       JoinFlag,\r
-  IN EFI_MAC_ADDRESS               *MacAddress OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL    *This,\r
+  IN BOOLEAN                         JoinFlag,\r
+  IN EFI_MAC_ADDRESS                 *MacAddress OPTIONAL\r
   )\r
 {\r
   MNP_INSTANCE_DATA       *Instance;\r
@@ -365,12 +364,11 @@ MnpGroups (
   }\r
 \r
   Instance  = MNP_INSTANCE_DATA_FROM_THIS (This);\r
-  SnpMode   = Instance->MnpServiceData->Snp->Mode;\r
+  SnpMode   = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (!Instance->Configured) {\r
-\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
@@ -452,8 +450,8 @@ ON_EXIT:
 \r
 /**\r
   Places asynchronous outgoing data packets into the transmit queue.\r
-   \r
-  The Transmit() function places a completion token into the transmit packet \r
+\r
+  The Transmit() function places a completion token into the transmit packet\r
   queue. This function is always asynchronous.\r
   The caller must fill in the Token.Event and Token.TxData fields in the\r
   completion token, and these fields cannot be NULL. When the transmit operation\r
@@ -463,8 +461,8 @@ ON_EXIT:
   defragmented before it can be transmitted by the network device. Systems in\r
   which performance is critical should review the requirements and features of\r
   the underlying communications device and drivers.\r
\r
\r
+\r
+\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\r
@@ -497,7 +495,7 @@ ON_EXIT:
   @retval EFI_ACCESS_DENIED      The transmit completion token is already in the\r
                                  transmit queue.\r
   @retval EFI_OUT_OF_RESOURCES   The transmit data could not be queued due to a\r
-                                 lack of system resources (usually memory). \r
+                                 lack of system resources (usually memory).\r
   @retval EFI_DEVICE_ERROR       An unexpected system or network error occurred.\r
                                  The MNP child driver instance has been reset to\r
                                  startup defaults.\r
@@ -508,8 +506,8 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpTransmit (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   )\r
 {\r
   EFI_STATUS        Status;\r
@@ -520,7 +518,6 @@ MnpTransmit (
   EFI_TPL           OldTpl;\r
 \r
   if ((This == NULL) || (Token == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -548,7 +545,10 @@ MnpTransmit (
   //\r
   // Build the tx packet\r
   //\r
-  MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r
+  Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
 \r
   //\r
   //  OK, send the packet synchronously.\r
@@ -564,14 +564,14 @@ ON_EXIT:
 \r
 /**\r
   Places an asynchronous receiving request into the receiving queue.\r
-   \r
-  The Receive() function places a completion token into the receive packet \r
+\r
+  The Receive() function places a completion token into the receive packet\r
   queue. This function is always asynchronous.\r
   The caller must fill in the Token.Event field in the completion token, and\r
   this field cannot be NULL. When the receive operation completes, the MNP\r
   updates the Token.Status and Token.RxData fields and the Token.Event is\r
   signaled.\r
-   \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
@@ -600,8 +600,8 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpReceive (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token\r
   )\r
 {\r
   EFI_STATUS         Status;\r
@@ -609,7 +609,6 @@ MnpReceive (
   EFI_TPL            OldTpl;\r
 \r
   if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -618,7 +617,6 @@ MnpReceive (
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (!Instance->Configured) {\r
-\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
@@ -628,7 +626,6 @@ MnpReceive (
   //\r
   Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);\r
   if (EFI_ERROR (Status)) {\r
-\r
     goto ON_EXIT;\r
   }\r
 \r
@@ -636,7 +633,6 @@ MnpReceive (
   // Insert the Token into the RxTokenMap.\r
   //\r
   Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);\r
-\r
   if (!EFI_ERROR (Status)) {\r
     //\r
     // Try to deliver any buffered packets.\r
@@ -656,8 +652,8 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  Aborts an asynchronous transmit or receive request. \r
-   \r
+  Aborts an asynchronous transmit or receive request.\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 be\r
@@ -668,7 +664,7 @@ 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 \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
@@ -687,8 +683,8 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpCancel (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token OPTIONAL\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL            *This,\r
+  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN    *Token OPTIONAL\r
   )\r
 {\r
   EFI_STATUS         Status;\r
@@ -696,7 +692,6 @@ MnpCancel (
   EFI_TPL            OldTpl;\r
 \r
   if (This == NULL) {\r
-\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -705,7 +700,6 @@ MnpCancel (
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (!Instance->Configured) {\r
-\r
     Status = EFI_NOT_STARTED;\r
     goto ON_EXIT;\r
   }\r
@@ -714,9 +708,7 @@ MnpCancel (
   // Iterate the RxTokenMap to cancel the specified Token.\r
   //\r
   Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);\r
-\r
   if (Token != NULL) {\r
-\r
     Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
   }\r
 \r
@@ -732,9 +724,9 @@ ON_EXIT:
 }\r
 \r
 /**\r
-  Polls for incoming data packets and processes outgoing data packets. \r
-   \r
-  The Poll() function can be used by network drivers and applications to \r
+  Polls for incoming data packets and processes outgoing data packets.\r
+\r
+  The Poll() function can be used by network drivers and applications to\r
   increase the rate that data packets are moved between the communications\r
   device and the transmit and receive queues.\r
   Normally, a periodic timer event internally calls the Poll() function. But, in\r
@@ -760,7 +752,7 @@ ON_EXIT:
 EFI_STATUS\r
 EFIAPI\r
 MnpPoll (\r
-  IN EFI_MANAGED_NETWORK_PROTOCOL  *This\r
+  IN EFI_MANAGED_NETWORK_PROTOCOL    *This\r
   )\r
 {\r
   EFI_STATUS         Status;\r
@@ -783,7 +775,7 @@ MnpPoll (
   //\r
   // Try to receive packets.\r
   //\r
-  Status = MnpReceivePacket (Instance->MnpServiceData);\r
+  Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);\r
 \r
   //\r
   // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
@@ -795,4 +787,3 @@ ON_EXIT:
 \r
   return Status;\r
 }\r
-\r