2 The implementation of a dispatch routine for processing TCP requests.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Add or remove a route entry in the IP route table associated with this TCP instance.
21 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
22 @param[in] RouteInfo Pointer to the route information to be processed.
24 @retval EFI_SUCCESS The operation completed successfully.
25 @retval EFI_NOT_STARTED The driver instance has not been started.
26 @retval EFI_NO_MAPPING When using the default address, configuration(DHCP,
27 BOOTP, RARP, etc.) is not finished yet.
28 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
29 @retval EFI_NOT_FOUND This route is not in the routing table
30 (when RouteInfo->DeleteRoute is TRUE).
31 @retval EFI_ACCESS_DENIED The route is already defined in the routing table
32 (when RouteInfo->DeleteRoute is FALSE).
37 IN TCP4_ROUTE_INFO
*RouteInfo
44 ASSERT (Ip
.Ip4
!= NULL
);
46 return Ip
.Ip4
->Routes (
48 RouteInfo
->DeleteRoute
,
49 RouteInfo
->SubnetAddress
,
50 RouteInfo
->SubnetMask
,
51 RouteInfo
->GatewayAddress
57 Get the operational settings of this TCPv4 instance.
59 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
60 @param[in, out] Mode Pointer to the buffer to store the operational
63 @retval EFI_SUCCESS The mode data was read.
64 @retval EFI_NOT_STARTED No configuration data is available because this
65 instance hasn't been started.
71 IN OUT TCP4_MODE_DATA
*Mode
75 EFI_TCP4_CONFIG_DATA
*ConfigData
;
76 EFI_TCP4_ACCESS_POINT
*AccessPoint
;
77 EFI_TCP4_OPTION
*Option
;
82 if (!SOCK_IS_CONFIGURED (Sock
) && (Mode
->Tcp4ConfigData
!= NULL
)) {
83 return EFI_NOT_STARTED
;
86 if (Mode
->Tcp4State
!= NULL
) {
87 *(Mode
->Tcp4State
) = (EFI_TCP4_CONNECTION_STATE
) Tcb
->State
;
90 if (Mode
->Tcp4ConfigData
!= NULL
) {
92 ConfigData
= Mode
->Tcp4ConfigData
;
93 AccessPoint
= &(ConfigData
->AccessPoint
);
94 Option
= ConfigData
->ControlOption
;
96 ConfigData
->TypeOfService
= Tcb
->Tos
;
97 ConfigData
->TimeToLive
= Tcb
->Ttl
;
99 AccessPoint
->UseDefaultAddress
= Tcb
->UseDefaultAddr
;
101 CopyMem (&AccessPoint
->StationAddress
, &Tcb
->LocalEnd
.Ip
, sizeof (EFI_IPv4_ADDRESS
));
103 AccessPoint
->SubnetMask
= Tcb
->SubnetMask
;
104 AccessPoint
->StationPort
= NTOHS (Tcb
->LocalEnd
.Port
);
106 CopyMem (&AccessPoint
->RemoteAddress
, &Tcb
->RemoteEnd
.Ip
, sizeof (EFI_IPv4_ADDRESS
));
108 AccessPoint
->RemotePort
= NTOHS (Tcb
->RemoteEnd
.Port
);
109 AccessPoint
->ActiveFlag
= (BOOLEAN
) (Tcb
->State
!= TCP_LISTEN
);
111 if (Option
!= NULL
) {
112 Option
->ReceiveBufferSize
= GET_RCV_BUFFSIZE (Tcb
->Sk
);
113 Option
->SendBufferSize
= GET_SND_BUFFSIZE (Tcb
->Sk
);
114 Option
->MaxSynBackLog
= GET_BACKLOG (Tcb
->Sk
);
116 Option
->ConnectionTimeout
= Tcb
->ConnectTimeout
/ TCP_TICK_HZ
;
117 Option
->DataRetries
= Tcb
->MaxRexmit
;
118 Option
->FinTimeout
= Tcb
->FinWait2Timeout
/ TCP_TICK_HZ
;
119 Option
->TimeWaitTimeout
= Tcb
->TimeWaitTimeout
/ TCP_TICK_HZ
;
120 Option
->KeepAliveProbes
= Tcb
->MaxKeepAlive
;
121 Option
->KeepAliveTime
= Tcb
->KeepAliveIdle
/ TCP_TICK_HZ
;
122 Option
->KeepAliveInterval
= Tcb
->KeepAlivePeriod
/ TCP_TICK_HZ
;
124 Option
->EnableNagle
= (BOOLEAN
) (!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
));
125 Option
->EnableTimeStamp
= (BOOLEAN
) (!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_TS
));
126 Option
->EnableWindowScaling
= (BOOLEAN
) (!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_WS
));
128 Option
->EnableSelectiveAck
= FALSE
;
129 Option
->EnablePathMtuDiscovery
= FALSE
;
133 Ip
= Tcb
->IpInfo
->Ip
.Ip4
;
136 return Ip
->GetModeData (Ip
, Mode
->Ip4ModeData
, Mode
->MnpConfigData
, Mode
->SnpModeData
);
140 Get the operational settings of this TCPv6 instance.
142 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
143 @param[in, out] Mode Pointer to the buffer to store the operational
146 @retval EFI_SUCCESS The mode data was read.
147 @retval EFI_NOT_STARTED No configuration data is available because this
148 instance hasn't been started.
154 IN OUT TCP6_MODE_DATA
*Mode
158 EFI_TCP6_CONFIG_DATA
*ConfigData
;
159 EFI_TCP6_ACCESS_POINT
*AccessPoint
;
160 EFI_TCP6_OPTION
*Option
;
161 EFI_IP6_PROTOCOL
*Ip
;
165 if (!SOCK_IS_CONFIGURED (Sock
) && (Mode
->Tcp6ConfigData
!= NULL
)) {
166 return EFI_NOT_STARTED
;
169 if (Mode
->Tcp6State
!= NULL
) {
170 *(Mode
->Tcp6State
) = (EFI_TCP6_CONNECTION_STATE
) (Tcb
->State
);
173 if (Mode
->Tcp6ConfigData
!= NULL
) {
175 ConfigData
= Mode
->Tcp6ConfigData
;
176 AccessPoint
= &(ConfigData
->AccessPoint
);
177 Option
= ConfigData
->ControlOption
;
179 ConfigData
->TrafficClass
= Tcb
->Tos
;
180 ConfigData
->HopLimit
= Tcb
->Ttl
;
182 AccessPoint
->StationPort
= NTOHS (Tcb
->LocalEnd
.Port
);
183 AccessPoint
->RemotePort
= NTOHS (Tcb
->RemoteEnd
.Port
);
184 AccessPoint
->ActiveFlag
= (BOOLEAN
) (Tcb
->State
!= TCP_LISTEN
);
186 IP6_COPY_ADDRESS (&AccessPoint
->StationAddress
, &Tcb
->LocalEnd
.Ip
);
187 IP6_COPY_ADDRESS (&AccessPoint
->RemoteAddress
, &Tcb
->RemoteEnd
.Ip
);
189 if (Option
!= NULL
) {
190 Option
->ReceiveBufferSize
= GET_RCV_BUFFSIZE (Tcb
->Sk
);
191 Option
->SendBufferSize
= GET_SND_BUFFSIZE (Tcb
->Sk
);
192 Option
->MaxSynBackLog
= GET_BACKLOG (Tcb
->Sk
);
194 Option
->ConnectionTimeout
= Tcb
->ConnectTimeout
/ TCP_TICK_HZ
;
195 Option
->DataRetries
= Tcb
->MaxRexmit
;
196 Option
->FinTimeout
= Tcb
->FinWait2Timeout
/ TCP_TICK_HZ
;
197 Option
->TimeWaitTimeout
= Tcb
->TimeWaitTimeout
/ TCP_TICK_HZ
;
198 Option
->KeepAliveProbes
= Tcb
->MaxKeepAlive
;
199 Option
->KeepAliveTime
= Tcb
->KeepAliveIdle
/ TCP_TICK_HZ
;
200 Option
->KeepAliveInterval
= Tcb
->KeepAlivePeriod
/ TCP_TICK_HZ
;
202 Option
->EnableNagle
= (BOOLEAN
) (!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
));
203 Option
->EnableTimeStamp
= (BOOLEAN
) (!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_TS
));
204 Option
->EnableWindowScaling
= (BOOLEAN
) (!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_WS
));
206 Option
->EnableSelectiveAck
= FALSE
;
207 Option
->EnablePathMtuDiscovery
= FALSE
;
211 Ip
= Tcb
->IpInfo
->Ip
.Ip6
;
214 return Ip
->GetModeData (Ip
, Mode
->Ip6ModeData
, Mode
->MnpConfigData
, Mode
->SnpModeData
);
218 If TcpAp->StationPort isn't zero, check whether the access point
219 is registered, else generate a random station port for this
222 @param[in] TcpAp Pointer to the access point.
223 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6
225 @retval EFI_SUCCESS The check passed or the port is assigned.
226 @retval EFI_INVALID_PARAMETER The non-zero station port is already used.
227 @retval EFI_OUT_OF_RESOURCES No port can be allocated.
232 IN TCP_ACCESS_POINT
*TcpAp
,
237 EFI_IP_ADDRESS Local
;
241 if (IpVersion
== IP_VERSION_4
) {
242 CopyMem (&Local
, &TcpAp
->Tcp4Ap
.StationAddress
, sizeof (EFI_IPv4_ADDRESS
));
243 Port
= &TcpAp
->Tcp4Ap
.StationPort
;
244 RandomPort
= &mTcp4RandomPort
;
246 IP6_COPY_ADDRESS (&Local
, &TcpAp
->Tcp6Ap
.StationAddress
);
247 Port
= &TcpAp
->Tcp6Ap
.StationPort
;
248 RandomPort
= &mTcp6RandomPort
;
253 // Check if a same endpoing is bound.
255 if (TcpFindTcbByPeer (&Local
, *Port
, IpVersion
)) {
257 return EFI_INVALID_PARAMETER
;
261 // generate a random port
265 if (TCP_PORT_USER_RESERVED
== *RandomPort
) {
266 *RandomPort
= TCP_PORT_KNOWN
;
271 while (TcpFindTcbByPeer (&Local
, *RandomPort
, IpVersion
)) {
274 if (*RandomPort
<= TCP_PORT_KNOWN
) {
278 "TcpBind: no port can be allocated for this pcb\n")
280 return EFI_OUT_OF_RESOURCES
;
283 *RandomPort
= TCP_PORT_KNOWN
+ 1;
296 Flush the Tcb add its associated protocols.
298 @param[in, out] Tcb Pointer to the TCP_CB to be flushed.
307 TCP_PROTO_DATA
*TcpProto
;
309 IpIoConfigIp (Tcb
->IpInfo
, NULL
);
312 TcpProto
= (TCP_PROTO_DATA
*) Sock
->ProtoReserved
;
314 if (SOCK_IS_CONFIGURED (Sock
)) {
315 RemoveEntryList (&Tcb
->List
);
317 if (Sock
->DevicePath
!= NULL
) {
319 // Uninstall the device path protocl.
321 gBS
->UninstallProtocolInterface (
323 &gEfiDevicePathProtocolGuid
,
327 FreePool (Sock
->DevicePath
);
328 Sock
->DevicePath
= NULL
;
331 TcpSetVariableData (TcpProto
->TcpService
);
334 NetbufFreeList (&Tcb
->SndQue
);
335 NetbufFreeList (&Tcb
->RcvQue
);
336 Tcb
->State
= TCP_CLOSED
;
340 Attach a Pcb to the socket.
342 @param[in] Sk Pointer to the socket of this TCP instance.
344 @retval EFI_SUCCESS The operation completed successfully.
345 @retval EFI_OUT_OF_RESOURCES Failed due to resource limits.
354 TCP_PROTO_DATA
*ProtoData
;
357 Tcb
= AllocateZeroPool (sizeof (TCP_CB
));
361 DEBUG ((EFI_D_ERROR
, "TcpConfigurePcb: failed to allocate a TCB\n"));
363 return EFI_OUT_OF_RESOURCES
;
366 ProtoData
= (TCP_PROTO_DATA
*) Sk
->ProtoReserved
;
367 IpIo
= ProtoData
->TcpService
->IpIo
;
370 // Create an IpInfo for this Tcb.
372 Tcb
->IpInfo
= IpIoAddIp (IpIo
);
373 if (Tcb
->IpInfo
== NULL
) {
376 return EFI_OUT_OF_RESOURCES
;
379 InitializeListHead (&Tcb
->List
);
380 InitializeListHead (&Tcb
->SndQue
);
381 InitializeListHead (&Tcb
->RcvQue
);
383 Tcb
->State
= TCP_CLOSED
;
385 ProtoData
->TcpPcb
= Tcb
;
391 Detach the Pcb of the socket.
393 @param[in, out] Sk Pointer to the socket of this TCP instance.
401 TCP_PROTO_DATA
*ProtoData
;
404 ProtoData
= (TCP_PROTO_DATA
*) Sk
->ProtoReserved
;
405 Tcb
= ProtoData
->TcpPcb
;
407 ASSERT (Tcb
!= NULL
);
411 IpIoRemoveIp (ProtoData
->TcpService
->IpIo
, Tcb
->IpInfo
);
415 ProtoData
->TcpPcb
= NULL
;
419 Configure the Pcb using CfgData.
421 @param[in] Sk Pointer to the socket of this TCP instance.
422 @param[in] CfgData Pointer to the TCP configuration data.
424 @retval EFI_SUCCESS The operation completed successfully.
425 @retval EFI_INVALID_PARAMETER A same access point has been configured in
426 another TCP instance.
427 @retval EFI_OUT_OF_RESOURCES Failed due to resource limits.
433 IN TCP_CONFIG_DATA
*CfgData
436 IP_IO_IP_CONFIG_DATA IpCfgData
;
438 EFI_TCP4_OPTION
*Option
;
439 TCP_PROTO_DATA
*TcpProto
;
441 TCP_ACCESS_POINT
*TcpAp
;
443 ASSERT ((CfgData
!= NULL
) && (Sk
!= NULL
) && (Sk
->SockHandle
!= NULL
));
445 TcpProto
= (TCP_PROTO_DATA
*) Sk
->ProtoReserved
;
446 Tcb
= TcpProto
->TcpPcb
;
448 ASSERT (Tcb
!= NULL
);
450 if (Sk
->IpVersion
== IP_VERSION_4
) {
452 // Add Ip for send pkt to the peer
454 CopyMem (&IpCfgData
.Ip4CfgData
, &mIp4IoDefaultIpConfigData
, sizeof (EFI_IP4_CONFIG_DATA
));
455 IpCfgData
.Ip4CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
456 IpCfgData
.Ip4CfgData
.TypeOfService
= CfgData
->Tcp4CfgData
.TypeOfService
;
457 IpCfgData
.Ip4CfgData
.TimeToLive
= CfgData
->Tcp4CfgData
.TimeToLive
;
458 IpCfgData
.Ip4CfgData
.UseDefaultAddress
= CfgData
->Tcp4CfgData
.AccessPoint
.UseDefaultAddress
;
459 IpCfgData
.Ip4CfgData
.SubnetMask
= CfgData
->Tcp4CfgData
.AccessPoint
.SubnetMask
;
460 IpCfgData
.Ip4CfgData
.ReceiveTimeout
= (UINT32
) (-1);
462 &IpCfgData
.Ip4CfgData
.StationAddress
,
463 &CfgData
->Tcp4CfgData
.AccessPoint
.StationAddress
,
464 sizeof (EFI_IPv4_ADDRESS
)
468 ASSERT (Sk
->IpVersion
== IP_VERSION_6
);
470 CopyMem (&IpCfgData
.Ip6CfgData
, &mIp6IoDefaultIpConfigData
, sizeof (EFI_IP6_CONFIG_DATA
));
471 IpCfgData
.Ip6CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
472 IpCfgData
.Ip6CfgData
.TrafficClass
= CfgData
->Tcp6CfgData
.TrafficClass
;
473 IpCfgData
.Ip6CfgData
.HopLimit
= CfgData
->Tcp6CfgData
.HopLimit
;
474 IpCfgData
.Ip6CfgData
.ReceiveTimeout
= (UINT32
) (-1);
476 &IpCfgData
.Ip6CfgData
.StationAddress
,
477 &CfgData
->Tcp6CfgData
.AccessPoint
.StationAddress
480 &IpCfgData
.Ip6CfgData
.DestinationAddress
,
481 &CfgData
->Tcp6CfgData
.AccessPoint
.RemoteAddress
486 // Configure the IP instance this Tcb consumes.
488 Status
= IpIoConfigIp (Tcb
->IpInfo
, &IpCfgData
);
489 if (EFI_ERROR (Status
)) {
493 if (Sk
->IpVersion
== IP_VERSION_4
) {
495 // Get the default address information if the instance is configured to use default address.
497 CfgData
->Tcp4CfgData
.AccessPoint
.StationAddress
= IpCfgData
.Ip4CfgData
.StationAddress
;
498 CfgData
->Tcp4CfgData
.AccessPoint
.SubnetMask
= IpCfgData
.Ip4CfgData
.SubnetMask
;
500 TcpAp
= (TCP_ACCESS_POINT
*) &CfgData
->Tcp4CfgData
.AccessPoint
;
503 &CfgData
->Tcp6CfgData
.AccessPoint
.StationAddress
,
504 &IpCfgData
.Ip6CfgData
.StationAddress
507 TcpAp
= (TCP_ACCESS_POINT
*) &CfgData
->Tcp6CfgData
.AccessPoint
;
511 // check if we can bind this endpoint in CfgData
513 Status
= TcpBind (TcpAp
, Sk
->IpVersion
);
515 if (EFI_ERROR (Status
)) {
518 "TcpConfigurePcb: Bind endpoint failed with %r\n",
526 // Initalize the operating information in this Tcb
528 ASSERT (Tcb
->State
== TCP_CLOSED
&&
529 IsListEmpty (&Tcb
->SndQue
) &&
530 IsListEmpty (&Tcb
->RcvQue
));
532 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_KEEPALIVE
);
533 Tcb
->State
= TCP_CLOSED
;
536 Tcb
->RcvMss
= TcpGetRcvMss (Sk
);
539 Tcb
->Rto
= 3 * TCP_TICK_HZ
;
541 Tcb
->CWnd
= Tcb
->SndMss
;
542 Tcb
->Ssthresh
= 0xffffffff;
544 Tcb
->CongestState
= TCP_CONGEST_OPEN
;
546 Tcb
->KeepAliveIdle
= TCP_KEEPALIVE_IDLE_MIN
;
547 Tcb
->KeepAlivePeriod
= TCP_KEEPALIVE_PERIOD
;
548 Tcb
->MaxKeepAlive
= TCP_MAX_KEEPALIVE
;
549 Tcb
->MaxRexmit
= TCP_MAX_LOSS
;
550 Tcb
->FinWait2Timeout
= TCP_FIN_WAIT2_TIME
;
551 Tcb
->TimeWaitTimeout
= TCP_TIME_WAIT_TIME
;
552 Tcb
->ConnectTimeout
= TCP_CONNECT_TIME
;
554 if (Sk
->IpVersion
== IP_VERSION_4
) {
556 // initialize Tcb in the light of CfgData
558 Tcb
->Ttl
= CfgData
->Tcp4CfgData
.TimeToLive
;
559 Tcb
->Tos
= CfgData
->Tcp4CfgData
.TypeOfService
;
561 Tcb
->UseDefaultAddr
= CfgData
->Tcp4CfgData
.AccessPoint
.UseDefaultAddress
;
563 CopyMem (&Tcb
->LocalEnd
.Ip
, &CfgData
->Tcp4CfgData
.AccessPoint
.StationAddress
, sizeof (IP4_ADDR
));
564 Tcb
->LocalEnd
.Port
= HTONS (CfgData
->Tcp4CfgData
.AccessPoint
.StationPort
);
565 Tcb
->SubnetMask
= CfgData
->Tcp4CfgData
.AccessPoint
.SubnetMask
;
567 CopyMem (&Tcb
->RemoteEnd
.Ip
, &CfgData
->Tcp4CfgData
.AccessPoint
.RemoteAddress
, sizeof (IP4_ADDR
));
568 Tcb
->RemoteEnd
.Port
= HTONS (CfgData
->Tcp4CfgData
.AccessPoint
.RemotePort
);
570 Option
= CfgData
->Tcp4CfgData
.ControlOption
;
572 Tcb
->Ttl
= CfgData
->Tcp6CfgData
.HopLimit
;
573 Tcb
->Tos
= CfgData
->Tcp6CfgData
.TrafficClass
;
575 IP6_COPY_ADDRESS (&Tcb
->LocalEnd
.Ip
, &CfgData
->Tcp6CfgData
.AccessPoint
.StationAddress
);
576 Tcb
->LocalEnd
.Port
= HTONS (CfgData
->Tcp6CfgData
.AccessPoint
.StationPort
);
578 IP6_COPY_ADDRESS (&Tcb
->RemoteEnd
.Ip
, &CfgData
->Tcp6CfgData
.AccessPoint
.RemoteAddress
);
579 Tcb
->RemoteEnd
.Port
= HTONS (CfgData
->Tcp6CfgData
.AccessPoint
.RemotePort
);
582 // Type EFI_TCP4_OPTION and EFI_TCP6_OPTION are the same.
584 Option
= (EFI_TCP4_OPTION
*) CfgData
->Tcp6CfgData
.ControlOption
;
587 if (Option
!= NULL
) {
590 (UINT32
) (TCP_COMP_VAL (
591 TCP_RCV_BUF_SIZE_MIN
,
594 Option
->ReceiveBufferSize
600 (UINT32
) (TCP_COMP_VAL (
601 TCP_SND_BUF_SIZE_MIN
,
604 Option
->SendBufferSize
611 (UINT32
) (TCP_COMP_VAL (
615 Option
->MaxSynBackLog
620 Tcb
->MaxRexmit
= (UINT16
) TCP_COMP_VAL (
626 Tcb
->FinWait2Timeout
= TCP_COMP_VAL (
628 TCP_FIN_WAIT2_TIME_MAX
,
630 (UINT32
) (Option
->FinTimeout
* TCP_TICK_HZ
)
633 if (Option
->TimeWaitTimeout
!= 0) {
634 Tcb
->TimeWaitTimeout
= TCP_COMP_VAL (
636 TCP_TIME_WAIT_TIME_MAX
,
638 (UINT32
) (Option
->TimeWaitTimeout
* TCP_TICK_HZ
)
641 Tcb
->TimeWaitTimeout
= 0;
644 if (Option
->KeepAliveProbes
!= 0) {
645 TCP_CLEAR_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_KEEPALIVE
);
647 Tcb
->MaxKeepAlive
= (UINT8
) TCP_COMP_VAL (
648 TCP_MAX_KEEPALIVE_MIN
,
651 Option
->KeepAliveProbes
653 Tcb
->KeepAliveIdle
= TCP_COMP_VAL (
654 TCP_KEEPALIVE_IDLE_MIN
,
655 TCP_KEEPALIVE_IDLE_MAX
,
656 TCP_KEEPALIVE_IDLE_MIN
,
657 (UINT32
) (Option
->KeepAliveTime
* TCP_TICK_HZ
)
659 Tcb
->KeepAlivePeriod
= TCP_COMP_VAL (
660 TCP_KEEPALIVE_PERIOD_MIN
,
661 TCP_KEEPALIVE_PERIOD
,
662 TCP_KEEPALIVE_PERIOD
,
663 (UINT32
) (Option
->KeepAliveInterval
* TCP_TICK_HZ
)
667 Tcb
->ConnectTimeout
= TCP_COMP_VAL (
668 TCP_CONNECT_TIME_MIN
,
671 (UINT32
) (Option
->ConnectionTimeout
* TCP_TICK_HZ
)
674 if (!Option
->EnableNagle
) {
675 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
);
678 if (!Option
->EnableTimeStamp
) {
679 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_TS
);
682 if (!Option
->EnableWindowScaling
) {
683 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_WS
);
688 // The socket is bound, the <SrcIp, SrcPort, DstIp, DstPort> is
689 // determined, construct the IP device path and install it.
691 Status
= TcpInstallDevicePath (Sk
);
692 if (EFI_ERROR (Status
)) {
697 // update state of Tcb and socket
699 if (((Sk
->IpVersion
== IP_VERSION_4
) && !CfgData
->Tcp4CfgData
.AccessPoint
.ActiveFlag
) ||
700 ((Sk
->IpVersion
== IP_VERSION_6
) && !CfgData
->Tcp6CfgData
.AccessPoint
.ActiveFlag
)
703 TcpSetState (Tcb
, TCP_LISTEN
);
704 SockSetState (Sk
, SO_LISTENING
);
706 Sk
->ConfigureState
= SO_CONFIGURED_PASSIVE
;
709 Sk
->ConfigureState
= SO_CONFIGURED_ACTIVE
;
712 if (Sk
->IpVersion
== IP_VERSION_6
) {
713 Tcb
->Tick
= TCP6_REFRESH_NEIGHBOR_TICK
;
724 The procotol handler provided to the socket layer, which is used to
725 dispatch the socket level requests by calling the corresponding
728 @param[in] Sock Pointer to the socket of this TCP instance.
729 @param[in] Request The code of this operation request.
730 @param[in] Data Pointer to the operation specific data passed in
731 together with the operation request. This is an
732 optional parameter that may be NULL.
734 @retval EFI_SUCCESS The socket request completed successfully.
735 @retval other The error status returned by the corresponding TCP
743 IN VOID
*Data OPTIONAL
747 TCP_PROTO_DATA
*ProtoData
;
749 ProtoData
= (TCP_PROTO_DATA
*) Sock
->ProtoReserved
;
750 Tcb
= ProtoData
->TcpPcb
;
754 if (Tcb
->Sk
->IpVersion
== IP_VERSION_4
) {
755 ProtoData
->TcpService
->IpIo
->Ip
.Ip4
->Poll (ProtoData
->TcpService
->IpIo
->Ip
.Ip4
);
757 ProtoData
->TcpService
->IpIo
->Ip
.Ip6
->Poll (ProtoData
->TcpService
->IpIo
->Ip
.Ip6
);
764 // After user received data from socket buffer, socket will
765 // notify TCP using this message to give it a chance to send out
766 // window update information
768 ASSERT (Tcb
!= NULL
);
769 TcpOnAppConsume (Tcb
);
774 ASSERT (Tcb
!= NULL
);
791 Tcb
->SndPsh
= TcpGetMaxSndNxt (Tcb
) + GET_SND_DATASIZE (Tcb
->Sk
);
792 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_SND_PSH
);
797 Tcb
->SndUp
= TcpGetMaxSndNxt (Tcb
) + GET_SND_DATASIZE (Tcb
->Sk
) - 1;
798 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_SND_URG
);
804 TcpOnAppConnect (Tcb
);
810 return TcpAttachPcb (Sock
);
828 return TcpConfigurePcb (
830 (TCP_CONFIG_DATA
*) Data
837 ASSERT ((Data
!= NULL
) && (Tcb
!= NULL
));
839 if (Tcb
->Sk
->IpVersion
== IP_VERSION_4
) {
841 return Tcp4GetMode (Tcb
, (TCP4_MODE_DATA
*) Data
);
844 return Tcp6GetMode (Tcb
, (TCP6_MODE_DATA
*) Data
);
851 ASSERT ((Data
!= NULL
) && (Tcb
!= NULL
) && (Tcb
->Sk
->IpVersion
== IP_VERSION_4
));
853 return Tcp4Route (Tcb
, (TCP4_ROUTE_INFO
*) Data
);
857 return EFI_UNSUPPORTED
;