/** @file\r
Misc support routines for tcp.\r
\r
-Copyright (c) 2005 - 2009, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2017, 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<BR>\r
//\r
// First window size is never scaled\r
//\r
- Tcb->RcvWndScale = 0;\r
+ Tcb->RcvWndScale = 0;\r
+ Tcb->RetxmitSeqMax = 0;\r
+ \r
+ Tcb->ProbeTimerOn = FALSE;\r
}\r
\r
\r
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_TS);\r
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_TS);\r
\r
+ Tcb->TsRecent = Opt->TSVal;\r
+\r
//\r
// Compute the effective SndMss per RFC1122\r
// section 4.2.2.6. If timestamp option is\r
@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
LIST_ENTRY *Entry;\r
LIST_ENTRY *Head;\r
TCP_CB *Node;\r
- TCP4_PROTO_DATA *TcpProto;\r
\r
ASSERT (\r
(Tcb != NULL) &&\r
\r
InsertHeadList (Head, &Tcb->List);\r
\r
- TcpProto = (TCP4_PROTO_DATA *) Tcb->Sk->ProtoReserved;\r
- TcpSetVariableData (TcpProto->TcpService);\r
-\r
return 0;\r
}\r
\r
Clone->Sk = SockClone (Tcb->Sk);\r
if (Clone->Sk == NULL) {\r
DEBUG ((EFI_D_ERROR, "TcpCloneTcb: failed to clone a sock\n"));\r
- gBS->FreePool (Clone);\r
+ FreePool (Clone);\r
return NULL;\r
}\r
\r
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
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
+ (EFI_D_NET,\r
"Tcb (%p) state %s --> %s\n",\r
Tcb,\r
mTcpStateName[Tcb->State],\r
\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
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
\r
if (TcpOld < Tcb->RcvMss) {\r
\r
- DEBUG ((EFI_D_INFO, "TcpOnAppConsume: send a window"\r
+ DEBUG ((EFI_D_NET, "TcpOnAppConsume: send a window"\r
" update for a window closed Tcb %p\n", Tcb));\r
\r
TcpSendAck (Tcb);\r
} else if (Tcb->DelayedAck == 0) {\r
\r
- DEBUG ((EFI_D_INFO, "TcpOnAppConsume: scheduled a delayed"\r
+ DEBUG ((EFI_D_NET, "TcpOnAppConsume: scheduled a delayed"\r
" ACK to update window for Tcb %p\n", Tcb));\r
\r
Tcb->DelayedAck = 1;\r
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
- gBS->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
- gBS->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
- gBS->FreePool (Tcp4Service->MacString);\r
- Tcp4Service->MacString = NULL;\r
-}\r
-\r
/**\r
Install the device path protocol on the TCP instance.\r
\r
TCP_CB *Tcb;\r
IPv4_DEVICE_PATH Ip4DPathNode;\r
EFI_STATUS Status;\r
+ TCP_PORTNO LocalPort;\r
+ TCP_PORTNO RemotePort;\r
\r
TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
TcpService = TcpProto->TcpService;\r
Tcb = TcpProto->TcpPcb;\r
\r
+ LocalPort = NTOHS (Tcb->LocalEnd.Port);\r
+ RemotePort = NTOHS (Tcb->RemoteEnd.Port);\r
NetLibCreateIPv4DPathNode (\r
&Ip4DPathNode,\r
TcpService->ControllerHandle,\r
Tcb->LocalEnd.Ip,\r
- NTOHS (Tcb->LocalEnd.Port),\r
+ LocalPort,\r
Tcb->RemoteEnd.Ip,\r
- NTOHS (Tcb->RemoteEnd.Port),\r
+ RemotePort,\r
EFI_IP_PROTO_TCP,\r
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
Sock->DevicePath\r
);\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (Sock->DevicePath);\r
+ FreePool (Sock->DevicePath);\r
}\r
\r
return Status;\r