]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
1. Mark the network volatile variables as deprecated in code comments and remove...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Udp4Dxe / Udp4Impl.c
index 710d0f9f59bfb64c23750010cf59f01fc72719bc..ce952b1e2d19b148d41b88a607e682d79768b07e 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   The implementation of the Udp4 protocol.\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>                                                         \r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2014, 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
@@ -59,16 +59,17 @@ Udp4FindInstanceByPort (
 \r
   @param[in]  Status                 The completion status of the output udp datagram.\r
   @param[in]  Context                Pointer to the context data.\r
-  @param[in]  Sender                 Pointer to the Ip sender of the udp datagram.\r
+  @param[in]  Sender                 Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
   @param[in]  NotifyData             Pointer to the notify data.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4DgramSent (\r
-  IN EFI_STATUS  Status,\r
-  IN VOID        *Context,\r
-  IN VOID        *Sender,\r
-  IN VOID        *NotifyData\r
+  IN EFI_STATUS        Status,\r
+  IN VOID              *Context,\r
+  IN IP_IO_IP_PROTOCOL Sender,\r
+  IN VOID              *NotifyData\r
   );\r
 \r
 /**\r
@@ -84,6 +85,7 @@ Udp4DgramSent (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4DgramRcvd (\r
   IN EFI_STATUS            Status,\r
   IN UINT8                 IcmpError,\r
@@ -109,6 +111,7 @@ Udp4DgramRcvd (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4CancelTokens (\r
   IN NET_MAP       *Map,\r
   IN NET_MAP_ITEM  *Item,\r
@@ -253,14 +256,14 @@ Udp4SendPortUnreach (
 /**\r
   Create the Udp service context data.\r
 \r
-  @param  Udp4Service            Pointer to the UDP4_SERVICE_DATA.\r
-  @param  ImageHandle            The image handle of this udp4 driver.\r
-  @param  ControllerHandle       The controller handle this udp4 driver binds on.\r
+  @param[in, out] Udp4Service      Pointer to the UDP4_SERVICE_DATA.\r
+  @param[in]      ImageHandle      The image handle of this udp4 driver.\r
+  @param[in]      ControllerHandle The controller handle this udp4 driver binds on.\r
 \r
-  @retval EFI_SUCCESS            The udp4 service context data is created and\r
-                                 initialized.\r
-  @retval EFI_OUT_OF_RESOURCES   Cannot allocate memory.\r
-  @retval other                  Other error occurs.\r
+  @retval EFI_SUCCESS              The udp4 service context data is created and\r
+                                   initialized.\r
+  @retval EFI_OUT_OF_RESOURCES     Cannot allocate memory.\r
+  @retval other                    Other error occurs.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -428,7 +431,7 @@ Udp4CheckTimeout (
       //\r
       // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
       //\r
-      if (Wrap->TimeoutTick <= (UDP4_TIMEOUT_INTERVAL / 10)) {\r
+      if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) {\r
         //\r
         // Remove this RxData if it timeouts.\r
         //\r
@@ -444,8 +447,8 @@ Udp4CheckTimeout (
 /**\r
   This function intializes the new created udp instance.\r
 \r
-  @param  Udp4Service            Pointer to the UDP4_SERVICE_DATA.\r
-  @param  Instance               Pointer to the un-initialized UDP4_INSTANCE_DATA.\r
+  @param[in]      Udp4Service       Pointer to the UDP4_SERVICE_DATA.\r
+  @param[in, out] Instance          Pointer to the un-initialized UDP4_INSTANCE_DATA.\r
 \r
 **/\r
 VOID\r
@@ -481,7 +484,7 @@ Udp4InitInstance (
   Instance->IcmpError   = EFI_SUCCESS;\r
   Instance->Configured  = FALSE;\r
   Instance->IsNoMapping = FALSE;\r
-  Instance->Destroyed   = FALSE;\r
+  Instance->InDestroy   = FALSE;\r
 }\r
 \r
 \r
@@ -560,9 +563,9 @@ Udp4FindInstanceByPort (
   This function tries to bind the udp instance according to the configured port\r
   allocation strategy.\r
 \r
-  @param  InstanceList           Pointer to the head of the list linking the udp\r
+  @param[in]      InstanceList   Pointer to the head of the list linking the udp\r
                                  instances.\r
-  @param  ConfigData             Pointer to the ConfigData of the instance to be\r
+  @param[in, out] ConfigData     Pointer to the ConfigData of the instance to be\r
                                  bound. ConfigData->StationPort will be assigned\r
                                  with an available port value on success.\r
 \r
@@ -890,6 +893,7 @@ Udp4ValidateTxToken (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4TokenExist (\r
   IN NET_MAP       *Map,\r
   IN NET_MAP_ITEM  *Item,\r
@@ -945,8 +949,8 @@ Udp4Checksum (
 /**\r
   This function removes the specified Token from the TokenMap.\r
 \r
-  @param  TokenMap           Pointer to the NET_MAP containing the tokens.\r
-  @param  Token              Pointer to the Token to be removed.\r
+  @param[in, out] TokenMap       Pointer to the NET_MAP containing the tokens.\r
+  @param[in]      Token          Pointer to the Token to be removed.\r
 \r
   @retval EFI_SUCCESS            The specified Token is removed from the TokenMap.\r
   @retval EFI_NOT_FOUND          The specified Token is not found in the TokenMap.\r
@@ -985,16 +989,17 @@ Udp4RemoveToken (
 \r
   @param[in]  Status                 The completion status of the output udp datagram.\r
   @param[in]  Context                Pointer to the context data.\r
-  @param[in]  Sender                 Pointer to the Ip sender of the udp datagram.\r
+  @param[in]  Sender                 Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
   @param[in]  NotifyData             Pointer to the notify data.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4DgramSent (\r
-  IN EFI_STATUS  Status,\r
-  IN VOID        *Context,\r
-  IN VOID        *Sender,\r
-  IN VOID        *NotifyData\r
+  IN EFI_STATUS        Status,\r
+  IN VOID              *Context,\r
+  IN IP_IO_IP_PROTOCOL Sender,\r
+  IN VOID              *NotifyData\r
   )\r
 {\r
   UDP4_INSTANCE_DATA         *Instance;\r
@@ -1027,6 +1032,7 @@ Udp4DgramSent (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4DgramRcvd (\r
   IN EFI_STATUS            Status,\r
   IN UINT8                 IcmpError,\r
@@ -1063,9 +1069,9 @@ Udp4DgramRcvd (
 /**\r
   This function removes the multicast group specified by Arg from the Map.\r
 \r
-  @param  Map                    Pointer to the NET_MAP.\r
-  @param  Item                   Pointer to the NET_MAP_ITEM.\r
-  @param  Arg                    Pointer to the Arg, it's the pointer to a\r
+  @param[in, out] Map            Pointer to the NET_MAP.\r
+  @param[in]      Item           Pointer to the NET_MAP_ITEM.\r
+  @param[in]      Arg            Pointer to the Arg, it's the pointer to a\r
                                  multicast IPv4 Address.\r
 \r
   @retval EFI_SUCCESS            The multicast address is removed.\r
@@ -1074,6 +1080,7 @@ Udp4DgramRcvd (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4LeaveGroup (\r
   IN OUT NET_MAP       *Map,\r
   IN     NET_MAP_ITEM  *Item,\r
@@ -1125,6 +1132,7 @@ Udp4LeaveGroup (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4CancelTokens (\r
   IN NET_MAP       *Map,\r
   IN NET_MAP_ITEM  *Item,\r
@@ -1604,6 +1612,7 @@ Udp4Demultiplex (
   // Get the datagram header from the packet buffer.\r
   //\r
   Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  ASSERT (Udp4Header != NULL);\r
 \r
   if (Udp4Header->Checksum != 0) {\r
     //\r
@@ -1624,8 +1633,6 @@ Udp4Demultiplex (
     }\r
   }\r
 \r
-  gRT->GetTime (&RxData.TimeStamp, NULL);\r
-\r
   Udp4Session                  = &RxData.UdpSession;\r
   Udp4Session->SourcePort      = NTOHS (Udp4Header->SrcPort);\r
   Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort);\r
@@ -1791,6 +1798,7 @@ Udp4IcmpHandler (
   UDP4_INSTANCE_DATA     *Instance;\r
 \r
   Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  ASSERT (Udp4Header != NULL);\r
 \r
   CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
   CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
@@ -1804,16 +1812,7 @@ Udp4IcmpHandler (
     //\r
     Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
 \r
-    if (!Instance->Configured ||\r
-        Instance->ConfigData.AcceptPromiscuous ||\r
-        Instance->ConfigData.AcceptAnyPort ||\r
-        EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr)\r
-        ) {\r
-      //\r
-      // Don't try to deliver the ICMP error to this instance if it is not configured,\r
-      // or it's configured to be promiscuous or accept any port or accept all the\r
-      // datagrams.\r
-      //\r
+    if (!Instance->Configured) {\r
       continue;\r
     }\r
 \r
@@ -1890,170 +1889,9 @@ Udp4ReportIcmpError (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4NetVectorExtFree (\r
   VOID  *Context\r
   )\r
 {\r
-}\r
-\r
-\r
-/**\r
-  Set the Udp4 variable data.\r
-\r
-  @param  Udp4Service            Udp4 service data.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES   There are not enough resources to set the\r
-                                 variable.\r
-  @retval EFI_SUCCESS            Set variable successfully.\r
-  @retval other                  Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-Udp4SetVariableData (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service\r
-  )\r
-{\r
-  UINT32                  NumConfiguredInstance;\r
-  LIST_ENTRY              *Entry;\r
-  UINTN                   VariableDataSize;\r
-  EFI_UDP4_VARIABLE_DATA  *Udp4VariableData;\r
-  EFI_UDP4_SERVICE_POINT  *Udp4ServicePoint;\r
-  UDP4_INSTANCE_DATA      *Udp4Instance;\r
-  CHAR16                  *NewMacString;\r
-  EFI_STATUS              Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
-  //\r
-  // Go through the children list to count the configured children.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
-    Udp4Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP4_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP4_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp4Instance->Configured) {\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Udp4VariableData. As there may be no Udp4 child,\r
-  // we should add extra buffer for the service points only if the number of configured\r
-  // children is more than 1.\r
-  //\r
-  VariableDataSize = sizeof (EFI_UDP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_UDP4_SERVICE_POINT) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Udp4VariableData = AllocatePool (VariableDataSize);\r
-  if (Udp4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Udp4VariableData->DriverHandle = Udp4Service->ImageHandle;\r
-  Udp4VariableData->ServiceCount = NumConfiguredInstance;\r
-\r
-  Udp4ServicePoint = &Udp4VariableData->Services[0];\r
-\r
-  //\r
-  // Go through the children list to fill the configured children's address pairs.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
-    Udp4Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP4_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP4_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp4Instance->Configured) {\r
-      Udp4ServicePoint->InstanceHandle = Udp4Instance->ChildHandle;\r
-      Udp4ServicePoint->LocalAddress   = Udp4Instance->ConfigData.StationAddress;\r
-      Udp4ServicePoint->LocalPort      = Udp4Instance->ConfigData.StationPort;\r
-      Udp4ServicePoint->RemoteAddress  = Udp4Instance->ConfigData.RemoteAddress;\r
-      Udp4ServicePoint->RemotePort     = Udp4Instance->ConfigData.RemotePort;\r
-\r
-      Udp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (\r
-             Udp4Service->ControllerHandle,\r
-             Udp4Service->ImageHandle,\r
-             &NewMacString\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (Udp4Service->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (Udp4Service->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             Udp4Service->MacString,\r
-             &gEfiUdp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    FreePool (Udp4Service->MacString);\r
-  }\r
-\r
-  Udp4Service->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  Udp4Service->MacString,\r
-                  &gEfiUdp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Udp4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  FreePool (Udp4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param[[in]  Udp4Service            Udp4 service data.\r
-\r
-**/\r
-VOID\r
-Udp4ClearVariableData (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service\r
-  )\r
-{\r
-  ASSERT (Udp4Service->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         Udp4Service->MacString,\r
-         &gEfiUdp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  FreePool (Udp4Service->MacString);\r
-  Udp4Service->MacString = NULL;\r
-}\r
+}
\ No newline at end of file