]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Udp6Dxe/Udp6Main.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / Udp6Dxe / Udp6Main.c
index 8495bc332a908507380cc07ab4ce14051745b9c7..e64319fafbfde1b580b88d02963de3c08fde4be1 100644 (file)
@@ -3,13 +3,7 @@
 \r
   Copyright (c) 2009 - 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
-  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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -25,7 +19,6 @@ EFI_UDP6_PROTOCOL  mUdp6Protocol = {
   Udp6Poll\r
 };\r
 \r
-\r
 /**\r
   This function copies the current operational settings of this EFI UDPv6 Protocol\r
   instance into user-supplied buffers. This function is used optionally to retrieve\r
@@ -97,7 +90,6 @@ Udp6GetModeData (
   return Status;\r
 }\r
 \r
-\r
 /**\r
   This function is used to do the following:\r
   Initialize and start this instance of the EFI UDPv6 Protocol.\r
@@ -110,7 +102,7 @@ Udp6GetModeData (
 \r
   @retval EFI_SUCCESS            The configuration settings were set, changed, or\r
                                  reset successfully.\r
-  @retval EFI_NO_MAPPING         When the UdpConifgData.UseAnyStationAddress is set\r
+  @retval EFI_NO_MAPPING         When the UdpConfigData.UseAnyStationAddress is set\r
                                  to true and there is no address available for the IP6\r
                                  driver to bind a source address to this instance.\r
   @retval EFI_INVALID_PARAMETER  One or more following conditions are TRUE:\r
@@ -165,16 +157,16 @@ Udp6Configure (
   Status      = EFI_SUCCESS;\r
   ASSERT (Udp6Service != NULL);\r
 \r
-  OldTpl      = gBS->RaiseTPL (TPL_CALLBACK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   if (UdpConfigData != NULL) {\r
-\r
     IP6_COPY_ADDRESS (&StationAddress, &UdpConfigData->StationAddress);\r
     IP6_COPY_ADDRESS (&RemoteAddress, &UdpConfigData->RemoteAddress);\r
 \r
     if ((!NetIp6IsUnspecifiedAddr (&StationAddress) && !NetIp6IsValidUnicast (&StationAddress)) ||\r
         (!NetIp6IsUnspecifiedAddr (&RemoteAddress) && !NetIp6IsValidUnicast (&RemoteAddress))\r
-        ){\r
+        )\r
+    {\r
       //\r
       // If not use default address, and StationAddress is not a valid unicast\r
       // if it is not IPv6 address or RemoteAddress is not a valid unicast IPv6\r
@@ -284,7 +276,7 @@ Udp6Configure (
 \r
     ASSERT (IsListEmpty (&Instance->DeliveredDgramQue));\r
   }\r
\r
+\r
 ON_EXIT:\r
 \r
   gBS->RestoreTPL (OldTpl);\r
@@ -292,7 +284,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   This function is used to enable and disable the multicast group filtering.\r
 \r
@@ -354,12 +345,13 @@ Udp6Groups (
     if (McastIp != NULL) {\r
       FreePool (McastIp);\r
     }\r
+\r
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  Ip      = Instance->IpInfo->Ip.Ip6;\r
+  Ip = Instance->IpInfo->Ip.Ip6;\r
 \r
-  OldTpl  = gBS->RaiseTPL (TPL_CALLBACK);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   //\r
   // Invoke the Ip instance the Udp6 instance consumes to do the group operation.\r
@@ -374,14 +366,15 @@ Udp6Groups (
   // Keep a local copy of the configured multicast IPs because IpIo receives\r
   // datagrams from the 0 station address IP instance and then UDP delivers to\r
   // the matched instance. This copy of multicast IPs is used to avoid receive\r
-  // the mutlicast datagrams destinated to multicast IPs the other instances configured.\r
+  // the multicast datagrams destinated to multicast IPs the other instances configured.\r
   //\r
   if (JoinFlag) {\r
-\r
-    Status = NetMapInsertTail (&Instance->McastIps, (VOID *) McastIp, NULL);\r
+    Status = NetMapInsertTail (&Instance->McastIps, (VOID *)McastIp, NULL);\r
   } else {\r
-\r
-    NetMapIterate (&Instance->McastIps, Udp6LeaveGroup, MulticastAddress);\r
+    Status = NetMapIterate (&Instance->McastIps, Udp6LeaveGroup, MulticastAddress);\r
+    if ((MulticastAddress != NULL) && (Status == EFI_ABORTED)) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
   }\r
 \r
 ON_EXIT:\r
@@ -397,8 +390,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
-\r
 /**\r
   This function places a sending request to this instance of the EFI UDPv6 Protocol,\r
   alongside the transmit data that was filled by the user.\r
@@ -426,13 +417,13 @@ ON_EXIT:
                                  One or more of the\r
                                  Token.Packet.TxData.FragmentTable[].FragmentBuffer\r
                                  fields is NULL. One or more of the\r
-                                 Token.Packet.TxData.UdpSessionData.DestinationAddres\r
+                                 Token.Packet.TxData.UdpSessionData.DestinationAddress\r
                                  are not valid unicast IPv6\r
                                  addresses if the  UdpSessionData is not NULL.\r
                                  Token.Packet.TxData.UdpSessionData.\r
                                  DestinationAddress is NULL\r
                                  Token.Packet.TxData.UdpSessionData.\r
-                                 DestinatioPort\r
+                                 DestinationPort\r
                                  is zero.\r
                                  Token.Packet.TxData.UdpSessionData is NULL and this\r
                                  instance's UdpConfigData.RemoteAddress  is unspecified.\r
@@ -493,7 +484,8 @@ Udp6Transmit (
 \r
   if (EFI_ERROR (NetMapIterate (&Instance->TxTokens, Udp6TokenExist, Token)) ||\r
       EFI_ERROR (NetMapIterate (&Instance->RxTokens, Udp6TokenExist, Token))\r
-      ){\r
+      )\r
+  {\r
     //\r
     // Try to find a duplicate token in the two token maps, if found, return\r
     // EFI_ACCESS_DENIED.\r
@@ -508,7 +500,7 @@ Udp6Transmit (
   // Create a net buffer to hold the user buffer and the udp header.\r
   //\r
   Packet = NetbufFromExt (\r
-             (NET_FRAGMENT *) TxData->FragmentTable,\r
+             (NET_FRAGMENT *)TxData->FragmentTable,\r
              TxData->FragmentCount,\r
              UDP6_HEADER_SIZE,\r
              0,\r
@@ -523,25 +515,25 @@ Udp6Transmit (
   //\r
   // Store the IpIo in ProtoData.\r
   //\r
-  Udp6Service                        = Instance->Udp6Service;\r
-  *((UINTN *) &Packet->ProtoData[0]) = (UINTN) (Udp6Service->IpIo);\r
+  Udp6Service                       = Instance->Udp6Service;\r
+  *((UINTN *)&Packet->ProtoData[0]) = (UINTN)(Udp6Service->IpIo);\r
 \r
-  Udp6Header = (EFI_UDP_HEADER *) NetbufAllocSpace (Packet, UDP6_HEADER_SIZE, TRUE);\r
+  Udp6Header = (EFI_UDP_HEADER *)NetbufAllocSpace (Packet, UDP6_HEADER_SIZE, TRUE);\r
   ASSERT (Udp6Header != NULL);\r
   if (Udp6Header == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   ConfigData = &Instance->ConfigData;\r
 \r
   //\r
   // Fill the udp header.\r
   //\r
-  Udp6Header->SrcPort      = HTONS (ConfigData->StationPort);\r
-  Udp6Header->DstPort      = HTONS (ConfigData->RemotePort);\r
-  Udp6Header->Length       = HTONS ((UINT16) Packet->TotalSize);\r
-  Udp6Header->Checksum     = 0;\r
+  Udp6Header->SrcPort  = HTONS (ConfigData->StationPort);\r
+  Udp6Header->DstPort  = HTONS (ConfigData->RemotePort);\r
+  Udp6Header->Length   = HTONS ((UINT16)Packet->TotalSize);\r
+  Udp6Header->Checksum = 0;\r
   //\r
   // Set the UDP Header in NET_BUF, this UDP header is for IP6 can fast get the\r
   // Udp header for pseudoHeadCheckSum.\r
@@ -567,7 +559,7 @@ Udp6Transmit (
     }\r
 \r
     //\r
-    //Calculate the pseudo head checksum using the overridden parameters.\r
+    // Calculate the pseudo head checksum using the overridden parameters.\r
     //\r
     if (!NetIp6IsUnspecifiedAddr (&ConfigData->StationAddress)) {\r
       HeadSum = NetIp6PseudoHeadChecksum (\r
@@ -585,15 +577,14 @@ Udp6Transmit (
         //\r
         // If the calculated checksum is 0, fill the Checksum field with all ones.\r
         //\r
-        Udp6Header->Checksum = 0XFFFF;\r
+        Udp6Header->Checksum = 0xffff;\r
       }\r
     } else {\r
       //\r
-      // Set the checksum is zero if the ConfigData->StationAddress is unspcified\r
+      // Set the checksum is zero if the ConfigData->StationAddress is unspecified\r
       // and the Ipv6 will fill the correct value of this checksum.\r
       //\r
       Udp6Header->Checksum = 0;\r
-\r
     }\r
   } else {\r
     //\r
@@ -614,8 +605,6 @@ Udp6Transmit (
     }\r
   }\r
 \r
-\r
-\r
   //\r
   // Fill the IpIo Override data.\r
   //\r
@@ -634,7 +623,7 @@ Udp6Transmit (
   //\r
   // Send out this datagram through IpIo.\r
   //\r
-  if (UdpSessionData != NULL){\r
+  if (UdpSessionData != NULL) {\r
     IP6_COPY_ADDRESS (&(IpDestAddr.v6), &Destination);\r
   } else {\r
     ZeroMem (&IpDestAddr.v6, sizeof (EFI_IPv6_ADDRESS));\r
@@ -667,7 +656,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   This function places a completion token into the receive packet queue. This function\r
   is always asynchronous.\r
@@ -720,7 +708,8 @@ Udp6Receive (
 \r
   if (EFI_ERROR (NetMapIterate (&Instance->RxTokens, Udp6TokenExist, Token)) ||\r
       EFI_ERROR (NetMapIterate (&Instance->TxTokens, Udp6TokenExist, Token))\r
-      ){\r
+      )\r
+  {\r
     //\r
     // Return EFI_ACCESS_DENIED if the specified token is already in the TxTokens or\r
     // RxTokens map.\r
@@ -762,7 +751,6 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   This function is used to abort a pending transmit or receive request.\r
 \r
@@ -810,7 +798,7 @@ Udp6Cancel (
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
   //\r
-  // Cancle the tokens specified by Token for this instance.\r
+  // Cancel the tokens specified by Token for this instance.\r
   //\r
   Status = Udp6InstanceCancelToken (Instance, Token);\r
 \r
@@ -824,7 +812,6 @@ Udp6Cancel (
   return Status;\r
 }\r
 \r
-\r
 /**\r
   This function can be used by network drivers and applications to increase the rate that\r
   data packets are moved between the communications device and the transmit/receive queues.\r