]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
1. Mark the network volatile variables as deprecated in code comments and remove...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Misc.c
index f36a5bd1bf1a7da4cd20bb08c0a34c469812d998..5b18d20497d782b75152dc5e465336320ce42585 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Misc support routines for tcp.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 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
@@ -77,7 +77,9 @@ TcpInitTcbLocal (
   //\r
   // First window size is never scaled\r
   //\r
-  Tcb->RcvWndScale = 0;\r
+  Tcb->RcvWndScale  = 0;\r
+\r
+  Tcb->ProbeTimerOn = FALSE;\r
 }\r
 \r
 \r
@@ -171,7 +173,7 @@ TcpInitTcbPeer (
   @param  Local                 Pointer to the local (IP, Port).\r
   @param  Remote                Pointer to the remote (IP, Port).\r
 \r
-  @return  Pointer to the TCP_CB with the least number of wildcard, \r
+  @return  Pointer to the TCP_CB with the least number of wildcard,\r
            if NULL no match is found.\r
 \r
 **/\r
@@ -390,7 +392,6 @@ TcpInsertTcb (
   InsertHeadList (Head, &Tcb->List);\r
 \r
   TcpProto = (TCP4_PROTO_DATA *) Tcb->Sk->ProtoReserved;\r
-  TcpSetVariableData (TcpProto->TcpService);\r
 \r
   return 0;\r
 }\r
@@ -478,7 +479,7 @@ TcpGetRcvMss (
   ASSERT (Sock != NULL);\r
 \r
   TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
-  Ip       = (EFI_IP4_PROTOCOL *) (TcpProto->TcpService->IpIo->Ip);\r
+  Ip       = TcpProto->TcpService->IpIo->Ip.Ip4;\r
   ASSERT (Ip != NULL);\r
 \r
   Ip->GetModeData (Ip, &Ip4Mode, NULL, NULL);\r
@@ -500,6 +501,9 @@ TcpSetState (
   IN     UINT8   State\r
   )\r
 {\r
+  ASSERT (Tcb->State < (sizeof (mTcpStateName) / sizeof (CHAR16 *)));\r
+  ASSERT (State < (sizeof (mTcpStateName) / sizeof (CHAR16 *)));\r
+\r
   DEBUG (\r
     (EFI_D_INFO,\r
     "Tcb (%p) state %s --> %s\n",\r
@@ -587,6 +591,7 @@ TcpFormatNetbuf (
 \r
   Seg       = TCPSEG_NETBUF (Nbuf);\r
   Head      = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);\r
+  ASSERT (Head != NULL);\r
   Nbuf->Tcp = Head;\r
 \r
   Seg->Seq  = NTOHL (Head->Seq);\r
@@ -652,7 +657,7 @@ TcpResetConnection (
   Nhead->Ack      = HTONL (Tcb->RcvNxt);\r
   Nhead->SrcPort  = Tcb->LocalEnd.Port;\r
   Nhead->DstPort  = Tcb->RemoteEnd.Port;\r
-  Nhead->HeadLen  = (sizeof (TCP_HEAD) >> 2);\r
+  Nhead->HeadLen  = (UINT8) (sizeof (TCP_HEAD) >> 2);\r
   Nhead->Res      = 0;\r
   Nhead->Wnd      = HTONS (0xFFFF);\r
   Nhead->Checksum = 0;\r
@@ -872,205 +877,6 @@ TcpOnAppAbort (
   TcpSetState (Tcb, TCP_CLOSED);\r
 }\r
 \r
-\r
-/**\r
-  Set the Tdp4 variable data.\r
-\r
-  @param  Tcp4Service           Pointer to Tcp4 service data.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to set the variable.\r
-  @retval other                 Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-TcpSetVariableData (\r
-  IN TCP4_SERVICE_DATA  *Tcp4Service\r
-  )\r
-{\r
-  UINT32                  NumConfiguredInstance;\r
-  LIST_ENTRY              *Entry;\r
-  TCP_CB                  *TcpPcb;\r
-  TCP4_PROTO_DATA         *TcpProto;\r
-  UINTN                   VariableDataSize;\r
-  EFI_TCP4_VARIABLE_DATA  *Tcp4VariableData;\r
-  EFI_TCP4_SERVICE_POINT  *Tcp4ServicePoint;\r
-  CHAR16                  *NewMacString;\r
-  EFI_STATUS              Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
-  //\r
-  // Go through the running queue to count the instances.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpRunQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Go through the listening queue to count the instances.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpListenQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Tcp4VariableData. As there may be no Tcp4 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_TCP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_TCP4_SERVICE_POINT) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Tcp4VariableData = AllocatePool (VariableDataSize);\r
-  if (Tcp4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Tcp4VariableData->DriverHandle = Tcp4Service->DriverBindingHandle;\r
-  Tcp4VariableData->ServiceCount = NumConfiguredInstance;\r
-\r
-  Tcp4ServicePoint = &Tcp4VariableData->Services[0];\r
-\r
-  //\r
-  // Go through the running queue to fill the service points.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpRunQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      Tcp4ServicePoint->InstanceHandle          = TcpPcb->Sk->SockHandle;\r
-      CopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->LocalPort               = NTOHS (TcpPcb->LocalEnd.Port);\r
-      CopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->RemotePort              = NTOHS (TcpPcb->RemoteEnd.Port);\r
-\r
-      Tcp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Go through the listening queue to fill the service points.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &mTcpListenQue) {\r
-    TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);\r
-\r
-    TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved;\r
-\r
-    if (TcpProto->TcpService == Tcp4Service) {\r
-      //\r
-      // This tcp instance belongs to the Tcp4Service.\r
-      //\r
-      Tcp4ServicePoint->InstanceHandle          = TcpPcb->Sk->SockHandle;\r
-      CopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->LocalPort               = NTOHS (TcpPcb->LocalEnd.Port);\r
-      CopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
-      Tcp4ServicePoint->RemotePort              = NTOHS (TcpPcb->RemoteEnd.Port);\r
-\r
-      Tcp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (\r
-             Tcp4Service->ControllerHandle,\r
-             Tcp4Service->DriverBindingHandle,\r
-             &NewMacString\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (Tcp4Service->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (Tcp4Service->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             Tcp4Service->MacString,\r
-             &gEfiTcp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    FreePool (Tcp4Service->MacString);\r
-  }\r
-\r
-  Tcp4Service->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  Tcp4Service->MacString,\r
-                  &gEfiTcp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Tcp4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  FreePool (Tcp4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param  Tcp4Service           Pointer to Tcp4 service data.\r
-\r
-**/\r
-VOID\r
-TcpClearVariableData (\r
-  IN TCP4_SERVICE_DATA  *Tcp4Service\r
-  )\r
-{\r
-  ASSERT (Tcp4Service->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         Tcp4Service->MacString,\r
-         &gEfiTcp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  FreePool (Tcp4Service->MacString);\r
-  Tcp4Service->MacString = NULL;\r
-}\r
-\r
 /**\r
   Install the device path protocol on the TCP instance.\r
 \r
@@ -1110,6 +916,8 @@ TcpInstallDevicePath (
     Tcb->UseDefaultAddr\r
     );\r
 \r
+  IP4_COPY_ADDRESS (&Ip4DPathNode.SubnetMask, &Tcb->SubnetMask);\r
+\r
   Sock->DevicePath = AppendDevicePathNode (\r
                        Sock->ParentDevicePath,\r
                        (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode\r