2 The implementation of a dispatch routine for processing TCP requests.
4 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
14 Add or remove a route entry in the IP route table associated with this TCP instance.
16 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
17 @param[in] RouteInfo Pointer to the route information to be processed.
19 @retval EFI_SUCCESS The operation completed successfully.
20 @retval EFI_NOT_STARTED The driver instance has not been started.
21 @retval EFI_NO_MAPPING When using the default address, configuration(DHCP,
22 BOOTP, RARP, etc.) is not finished yet.
23 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
24 @retval EFI_NOT_FOUND This route is not in the routing table
25 (when RouteInfo->DeleteRoute is TRUE).
26 @retval EFI_ACCESS_DENIED The route is already defined in the routing table
27 (when RouteInfo->DeleteRoute is FALSE).
32 IN TCP4_ROUTE_INFO
*RouteInfo
39 ASSERT (Ip
.Ip4
!= NULL
);
41 return Ip
.Ip4
->Routes (
43 RouteInfo
->DeleteRoute
,
44 RouteInfo
->SubnetAddress
,
45 RouteInfo
->SubnetMask
,
46 RouteInfo
->GatewayAddress
51 Get the operational settings of this TCPv4 instance.
53 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
54 @param[in, out] Mode Pointer to the buffer to store the operational
57 @retval EFI_SUCCESS The mode data was read.
58 @retval EFI_NOT_STARTED No configuration data is available because this
59 instance hasn't been started.
65 IN OUT TCP4_MODE_DATA
*Mode
69 EFI_TCP4_CONFIG_DATA
*ConfigData
;
70 EFI_TCP4_ACCESS_POINT
*AccessPoint
;
71 EFI_TCP4_OPTION
*Option
;
76 if (!SOCK_IS_CONFIGURED (Sock
) && (Mode
->Tcp4ConfigData
!= NULL
)) {
77 return EFI_NOT_STARTED
;
80 if (Mode
->Tcp4State
!= NULL
) {
81 *(Mode
->Tcp4State
) = (EFI_TCP4_CONNECTION_STATE
)Tcb
->State
;
84 if (Mode
->Tcp4ConfigData
!= NULL
) {
85 ConfigData
= Mode
->Tcp4ConfigData
;
86 AccessPoint
= &(ConfigData
->AccessPoint
);
87 Option
= ConfigData
->ControlOption
;
89 ConfigData
->TypeOfService
= Tcb
->Tos
;
90 ConfigData
->TimeToLive
= Tcb
->Ttl
;
92 AccessPoint
->UseDefaultAddress
= Tcb
->UseDefaultAddr
;
94 IP4_COPY_ADDRESS (&AccessPoint
->StationAddress
, &Tcb
->LocalEnd
.Ip
);
96 IP4_COPY_ADDRESS (&AccessPoint
->SubnetMask
, &Tcb
->SubnetMask
);
97 AccessPoint
->StationPort
= NTOHS (Tcb
->LocalEnd
.Port
);
99 IP4_COPY_ADDRESS (&AccessPoint
->RemoteAddress
, &Tcb
->RemoteEnd
.Ip
);
101 AccessPoint
->RemotePort
= NTOHS (Tcb
->RemoteEnd
.Port
);
102 AccessPoint
->ActiveFlag
= (BOOLEAN
)(Tcb
->State
!= TCP_LISTEN
);
104 if (Option
!= NULL
) {
105 Option
->ReceiveBufferSize
= GET_RCV_BUFFSIZE (Tcb
->Sk
);
106 Option
->SendBufferSize
= GET_SND_BUFFSIZE (Tcb
->Sk
);
107 Option
->MaxSynBackLog
= GET_BACKLOG (Tcb
->Sk
);
109 Option
->ConnectionTimeout
= Tcb
->ConnectTimeout
/ TCP_TICK_HZ
;
110 Option
->DataRetries
= Tcb
->MaxRexmit
;
111 Option
->FinTimeout
= Tcb
->FinWait2Timeout
/ TCP_TICK_HZ
;
112 Option
->TimeWaitTimeout
= Tcb
->TimeWaitTimeout
/ TCP_TICK_HZ
;
113 Option
->KeepAliveProbes
= Tcb
->MaxKeepAlive
;
114 Option
->KeepAliveTime
= Tcb
->KeepAliveIdle
/ TCP_TICK_HZ
;
115 Option
->KeepAliveInterval
= Tcb
->KeepAlivePeriod
/ TCP_TICK_HZ
;
117 Option
->EnableNagle
= (BOOLEAN
)(!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
));
118 Option
->EnableTimeStamp
= (BOOLEAN
)(!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_TS
));
119 Option
->EnableWindowScaling
= (BOOLEAN
)(!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_WS
));
121 Option
->EnableSelectiveAck
= FALSE
;
122 Option
->EnablePathMtuDiscovery
= FALSE
;
126 Ip
= Tcb
->IpInfo
->Ip
.Ip4
;
129 return Ip
->GetModeData (Ip
, Mode
->Ip4ModeData
, Mode
->MnpConfigData
, Mode
->SnpModeData
);
133 Get the operational settings of this TCPv6 instance.
135 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
136 @param[in, out] Mode Pointer to the buffer to store the operational
139 @retval EFI_SUCCESS The mode data was read.
140 @retval EFI_NOT_STARTED No configuration data is available because this
141 instance hasn't been started.
147 IN OUT TCP6_MODE_DATA
*Mode
151 EFI_TCP6_CONFIG_DATA
*ConfigData
;
152 EFI_TCP6_ACCESS_POINT
*AccessPoint
;
153 EFI_TCP6_OPTION
*Option
;
154 EFI_IP6_PROTOCOL
*Ip
;
158 if (!SOCK_IS_CONFIGURED (Sock
) && (Mode
->Tcp6ConfigData
!= NULL
)) {
159 return EFI_NOT_STARTED
;
162 if (Mode
->Tcp6State
!= NULL
) {
163 *(Mode
->Tcp6State
) = (EFI_TCP6_CONNECTION_STATE
)(Tcb
->State
);
166 if (Mode
->Tcp6ConfigData
!= NULL
) {
167 ConfigData
= Mode
->Tcp6ConfigData
;
168 AccessPoint
= &(ConfigData
->AccessPoint
);
169 Option
= ConfigData
->ControlOption
;
171 ConfigData
->TrafficClass
= Tcb
->Tos
;
172 ConfigData
->HopLimit
= Tcb
->Ttl
;
174 AccessPoint
->StationPort
= NTOHS (Tcb
->LocalEnd
.Port
);
175 AccessPoint
->RemotePort
= NTOHS (Tcb
->RemoteEnd
.Port
);
176 AccessPoint
->ActiveFlag
= (BOOLEAN
)(Tcb
->State
!= TCP_LISTEN
);
178 IP6_COPY_ADDRESS (&AccessPoint
->StationAddress
, &Tcb
->LocalEnd
.Ip
);
179 IP6_COPY_ADDRESS (&AccessPoint
->RemoteAddress
, &Tcb
->RemoteEnd
.Ip
);
181 if (Option
!= NULL
) {
182 Option
->ReceiveBufferSize
= GET_RCV_BUFFSIZE (Tcb
->Sk
);
183 Option
->SendBufferSize
= GET_SND_BUFFSIZE (Tcb
->Sk
);
184 Option
->MaxSynBackLog
= GET_BACKLOG (Tcb
->Sk
);
186 Option
->ConnectionTimeout
= Tcb
->ConnectTimeout
/ TCP_TICK_HZ
;
187 Option
->DataRetries
= Tcb
->MaxRexmit
;
188 Option
->FinTimeout
= Tcb
->FinWait2Timeout
/ TCP_TICK_HZ
;
189 Option
->TimeWaitTimeout
= Tcb
->TimeWaitTimeout
/ TCP_TICK_HZ
;
190 Option
->KeepAliveProbes
= Tcb
->MaxKeepAlive
;
191 Option
->KeepAliveTime
= Tcb
->KeepAliveIdle
/ TCP_TICK_HZ
;
192 Option
->KeepAliveInterval
= Tcb
->KeepAlivePeriod
/ TCP_TICK_HZ
;
194 Option
->EnableNagle
= (BOOLEAN
)(!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
));
195 Option
->EnableTimeStamp
= (BOOLEAN
)(!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_TS
));
196 Option
->EnableWindowScaling
= (BOOLEAN
)(!TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_WS
));
198 Option
->EnableSelectiveAck
= FALSE
;
199 Option
->EnablePathMtuDiscovery
= FALSE
;
203 Ip
= Tcb
->IpInfo
->Ip
.Ip6
;
206 return Ip
->GetModeData (Ip
, Mode
->Ip6ModeData
, Mode
->MnpConfigData
, Mode
->SnpModeData
);
210 If TcpAp->StationPort isn't zero, check whether the access point
211 is registered, else generate a random station port for this
214 @param[in] TcpAp Pointer to the access point.
215 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6
217 @retval EFI_SUCCESS The check passed or the port is assigned.
218 @retval EFI_INVALID_PARAMETER The non-zero station port is already used.
219 @retval EFI_OUT_OF_RESOURCES No port can be allocated.
224 IN TCP_ACCESS_POINT
*TcpAp
,
229 EFI_IP_ADDRESS Local
;
233 if (IpVersion
== IP_VERSION_4
) {
234 IP4_COPY_ADDRESS (&Local
, &TcpAp
->Tcp4Ap
.StationAddress
);
235 Port
= &TcpAp
->Tcp4Ap
.StationPort
;
236 RandomPort
= &mTcp4RandomPort
;
238 IP6_COPY_ADDRESS (&Local
, &TcpAp
->Tcp6Ap
.StationAddress
);
239 Port
= &TcpAp
->Tcp6Ap
.StationPort
;
240 RandomPort
= &mTcp6RandomPort
;
245 // Check if a same endpoing is bound.
247 if (TcpFindTcbByPeer (&Local
, *Port
, IpVersion
)) {
248 return EFI_INVALID_PARAMETER
;
252 // generate a random port
256 if (TCP_PORT_USER_RESERVED
== *RandomPort
) {
257 *RandomPort
= TCP_PORT_KNOWN
;
262 while (TcpFindTcbByPeer (&Local
, *RandomPort
, IpVersion
)) {
265 if (*RandomPort
<= TCP_PORT_KNOWN
) {
269 "TcpBind: no port can be allocated for this pcb\n")
271 return EFI_OUT_OF_RESOURCES
;
274 *RandomPort
= TCP_PORT_KNOWN
+ 1;
287 Flush the Tcb add its associated protocols.
289 @param[in, out] Tcb Pointer to the TCP_CB to be flushed.
299 IpIoConfigIp (Tcb
->IpInfo
, NULL
);
303 if (SOCK_IS_CONFIGURED (Sock
)) {
304 RemoveEntryList (&Tcb
->List
);
306 if (Sock
->DevicePath
!= NULL
) {
308 // Uninstall the device path protocol.
310 gBS
->UninstallProtocolInterface (
312 &gEfiDevicePathProtocolGuid
,
316 FreePool (Sock
->DevicePath
);
317 Sock
->DevicePath
= NULL
;
321 NetbufFreeList (&Tcb
->SndQue
);
322 NetbufFreeList (&Tcb
->RcvQue
);
323 Tcb
->State
= TCP_CLOSED
;
324 Tcb
->RemoteIpZero
= FALSE
;
328 Attach a Pcb to the socket.
330 @param[in] Sk Pointer to the socket of this TCP instance.
332 @retval EFI_SUCCESS The operation completed successfully.
333 @retval EFI_OUT_OF_RESOURCES Failed due to resource limits.
342 TCP_PROTO_DATA
*ProtoData
;
346 EFI_GUID
*IpProtocolGuid
;
348 if (Sk
->IpVersion
== IP_VERSION_4
) {
349 IpProtocolGuid
= &gEfiIp4ProtocolGuid
;
351 IpProtocolGuid
= &gEfiIp6ProtocolGuid
;
354 Tcb
= AllocateZeroPool (sizeof (TCP_CB
));
357 DEBUG ((DEBUG_ERROR
, "TcpConfigurePcb: failed to allocate a TCB\n"));
359 return EFI_OUT_OF_RESOURCES
;
362 ProtoData
= (TCP_PROTO_DATA
*)Sk
->ProtoReserved
;
363 IpIo
= ProtoData
->TcpService
->IpIo
;
366 // Create an IpInfo for this Tcb.
368 Tcb
->IpInfo
= IpIoAddIp (IpIo
);
369 if (Tcb
->IpInfo
== NULL
) {
371 return EFI_OUT_OF_RESOURCES
;
375 // Open the new created IP instance BY_CHILD.
377 Status
= gBS
->OpenProtocol (
378 Tcb
->IpInfo
->ChildHandle
,
383 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
385 if (EFI_ERROR (Status
)) {
386 IpIoRemoveIp (IpIo
, Tcb
->IpInfo
);
391 InitializeListHead (&Tcb
->List
);
392 InitializeListHead (&Tcb
->SndQue
);
393 InitializeListHead (&Tcb
->RcvQue
);
395 Tcb
->State
= TCP_CLOSED
;
397 ProtoData
->TcpPcb
= Tcb
;
403 Detach the Pcb of the socket.
405 @param[in, out] Sk Pointer to the socket of this TCP instance.
413 TCP_PROTO_DATA
*ProtoData
;
416 ProtoData
= (TCP_PROTO_DATA
*)Sk
->ProtoReserved
;
417 Tcb
= ProtoData
->TcpPcb
;
419 ASSERT (Tcb
!= NULL
);
423 IpIoRemoveIp (ProtoData
->TcpService
->IpIo
, Tcb
->IpInfo
);
427 ProtoData
->TcpPcb
= NULL
;
431 Configure the Pcb using CfgData.
433 @param[in] Sk Pointer to the socket of this TCP instance.
434 @param[in] CfgData Pointer to the TCP configuration data.
436 @retval EFI_SUCCESS The operation completed successfully.
437 @retval EFI_INVALID_PARAMETER A same access point has been configured in
438 another TCP instance.
439 @retval EFI_OUT_OF_RESOURCES Failed due to resource limits.
445 IN TCP_CONFIG_DATA
*CfgData
448 IP_IO_IP_CONFIG_DATA IpCfgData
;
450 EFI_TCP4_OPTION
*Option
;
451 TCP_PROTO_DATA
*TcpProto
;
453 TCP_ACCESS_POINT
*TcpAp
;
455 ASSERT ((CfgData
!= NULL
) && (Sk
!= NULL
) && (Sk
->SockHandle
!= NULL
));
457 TcpProto
= (TCP_PROTO_DATA
*)Sk
->ProtoReserved
;
458 Tcb
= TcpProto
->TcpPcb
;
460 ASSERT (Tcb
!= NULL
);
462 if (Sk
->IpVersion
== IP_VERSION_4
) {
464 // Add Ip for send pkt to the peer
466 CopyMem (&IpCfgData
.Ip4CfgData
, &mIp4IoDefaultIpConfigData
, sizeof (EFI_IP4_CONFIG_DATA
));
467 IpCfgData
.Ip4CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
468 IpCfgData
.Ip4CfgData
.TypeOfService
= CfgData
->Tcp4CfgData
.TypeOfService
;
469 IpCfgData
.Ip4CfgData
.TimeToLive
= CfgData
->Tcp4CfgData
.TimeToLive
;
470 IpCfgData
.Ip4CfgData
.UseDefaultAddress
= CfgData
->Tcp4CfgData
.AccessPoint
.UseDefaultAddress
;
472 &IpCfgData
.Ip4CfgData
.SubnetMask
,
473 &CfgData
->Tcp4CfgData
.AccessPoint
.SubnetMask
475 IpCfgData
.Ip4CfgData
.ReceiveTimeout
= (UINT32
)(-1);
477 &IpCfgData
.Ip4CfgData
.StationAddress
,
478 &CfgData
->Tcp4CfgData
.AccessPoint
.StationAddress
481 ASSERT (Sk
->IpVersion
== IP_VERSION_6
);
483 CopyMem (&IpCfgData
.Ip6CfgData
, &mIp6IoDefaultIpConfigData
, sizeof (EFI_IP6_CONFIG_DATA
));
484 IpCfgData
.Ip6CfgData
.DefaultProtocol
= EFI_IP_PROTO_TCP
;
485 IpCfgData
.Ip6CfgData
.TrafficClass
= CfgData
->Tcp6CfgData
.TrafficClass
;
486 IpCfgData
.Ip6CfgData
.HopLimit
= CfgData
->Tcp6CfgData
.HopLimit
;
487 IpCfgData
.Ip6CfgData
.ReceiveTimeout
= (UINT32
)(-1);
489 &IpCfgData
.Ip6CfgData
.StationAddress
,
490 &CfgData
->Tcp6CfgData
.AccessPoint
.StationAddress
493 &IpCfgData
.Ip6CfgData
.DestinationAddress
,
494 &CfgData
->Tcp6CfgData
.AccessPoint
.RemoteAddress
499 // Configure the IP instance this Tcb consumes.
501 Status
= IpIoConfigIp (Tcb
->IpInfo
, &IpCfgData
);
502 if (EFI_ERROR (Status
)) {
506 if (Sk
->IpVersion
== IP_VERSION_4
) {
508 // Get the default address information if the instance is configured to use default address.
511 &CfgData
->Tcp4CfgData
.AccessPoint
.StationAddress
,
512 &IpCfgData
.Ip4CfgData
.StationAddress
515 &CfgData
->Tcp4CfgData
.AccessPoint
.SubnetMask
,
516 &IpCfgData
.Ip4CfgData
.SubnetMask
519 TcpAp
= (TCP_ACCESS_POINT
*)&CfgData
->Tcp4CfgData
.AccessPoint
;
522 &CfgData
->Tcp6CfgData
.AccessPoint
.StationAddress
,
523 &IpCfgData
.Ip6CfgData
.StationAddress
526 TcpAp
= (TCP_ACCESS_POINT
*)&CfgData
->Tcp6CfgData
.AccessPoint
;
530 // check if we can bind this endpoint in CfgData
532 Status
= TcpBind (TcpAp
, Sk
->IpVersion
);
534 if (EFI_ERROR (Status
)) {
537 "TcpConfigurePcb: Bind endpoint failed with %r\n",
545 // Initialize the operating information in this Tcb
548 Tcb
->State
== TCP_CLOSED
&&
549 IsListEmpty (&Tcb
->SndQue
) &&
550 IsListEmpty (&Tcb
->RcvQue
)
553 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_KEEPALIVE
);
554 Tcb
->State
= TCP_CLOSED
;
557 Tcb
->RcvMss
= TcpGetRcvMss (Sk
);
560 Tcb
->Rto
= 3 * TCP_TICK_HZ
;
562 Tcb
->CWnd
= Tcb
->SndMss
;
563 Tcb
->Ssthresh
= 0xffffffff;
565 Tcb
->CongestState
= TCP_CONGEST_OPEN
;
567 Tcb
->KeepAliveIdle
= TCP_KEEPALIVE_IDLE_MIN
;
568 Tcb
->KeepAlivePeriod
= TCP_KEEPALIVE_PERIOD
;
569 Tcb
->MaxKeepAlive
= TCP_MAX_KEEPALIVE
;
570 Tcb
->MaxRexmit
= TCP_MAX_LOSS
;
571 Tcb
->FinWait2Timeout
= TCP_FIN_WAIT2_TIME
;
572 Tcb
->TimeWaitTimeout
= TCP_TIME_WAIT_TIME
;
573 Tcb
->ConnectTimeout
= TCP_CONNECT_TIME
;
575 if (Sk
->IpVersion
== IP_VERSION_4
) {
577 // initialize Tcb in the light of CfgData
579 Tcb
->Ttl
= CfgData
->Tcp4CfgData
.TimeToLive
;
580 Tcb
->Tos
= CfgData
->Tcp4CfgData
.TypeOfService
;
582 Tcb
->UseDefaultAddr
= CfgData
->Tcp4CfgData
.AccessPoint
.UseDefaultAddress
;
584 CopyMem (&Tcb
->LocalEnd
.Ip
, &CfgData
->Tcp4CfgData
.AccessPoint
.StationAddress
, sizeof (IP4_ADDR
));
585 Tcb
->LocalEnd
.Port
= HTONS (CfgData
->Tcp4CfgData
.AccessPoint
.StationPort
);
586 IP4_COPY_ADDRESS (&Tcb
->SubnetMask
, &CfgData
->Tcp4CfgData
.AccessPoint
.SubnetMask
);
588 CopyMem (&Tcb
->RemoteEnd
.Ip
, &CfgData
->Tcp4CfgData
.AccessPoint
.RemoteAddress
, sizeof (IP4_ADDR
));
589 Tcb
->RemoteEnd
.Port
= HTONS (CfgData
->Tcp4CfgData
.AccessPoint
.RemotePort
);
591 Option
= CfgData
->Tcp4CfgData
.ControlOption
;
593 Tcb
->Ttl
= CfgData
->Tcp6CfgData
.HopLimit
;
594 Tcb
->Tos
= CfgData
->Tcp6CfgData
.TrafficClass
;
596 IP6_COPY_ADDRESS (&Tcb
->LocalEnd
.Ip
, &CfgData
->Tcp6CfgData
.AccessPoint
.StationAddress
);
597 Tcb
->LocalEnd
.Port
= HTONS (CfgData
->Tcp6CfgData
.AccessPoint
.StationPort
);
599 IP6_COPY_ADDRESS (&Tcb
->RemoteEnd
.Ip
, &CfgData
->Tcp6CfgData
.AccessPoint
.RemoteAddress
);
600 Tcb
->RemoteEnd
.Port
= HTONS (CfgData
->Tcp6CfgData
.AccessPoint
.RemotePort
);
603 // Type EFI_TCP4_OPTION and EFI_TCP6_OPTION are the same.
605 Option
= (EFI_TCP4_OPTION
*)CfgData
->Tcp6CfgData
.ControlOption
;
608 if (Option
!= NULL
) {
611 (UINT32
)(TCP_COMP_VAL (
612 TCP_RCV_BUF_SIZE_MIN
,
615 Option
->ReceiveBufferSize
621 (UINT32
)(TCP_COMP_VAL (
622 TCP_SND_BUF_SIZE_MIN
,
625 Option
->SendBufferSize
632 (UINT32
)(TCP_COMP_VAL (
636 Option
->MaxSynBackLog
641 Tcb
->MaxRexmit
= (UINT16
)TCP_COMP_VAL (
647 Tcb
->FinWait2Timeout
= TCP_COMP_VAL (
649 TCP_FIN_WAIT2_TIME_MAX
,
651 (UINT32
)(Option
->FinTimeout
* TCP_TICK_HZ
)
654 if (Option
->TimeWaitTimeout
!= 0) {
655 Tcb
->TimeWaitTimeout
= TCP_COMP_VAL (
657 TCP_TIME_WAIT_TIME_MAX
,
659 (UINT32
)(Option
->TimeWaitTimeout
* TCP_TICK_HZ
)
662 Tcb
->TimeWaitTimeout
= 0;
665 if (Option
->KeepAliveProbes
!= 0) {
666 TCP_CLEAR_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_KEEPALIVE
);
668 Tcb
->MaxKeepAlive
= (UINT8
)TCP_COMP_VAL (
669 TCP_MAX_KEEPALIVE_MIN
,
672 Option
->KeepAliveProbes
674 Tcb
->KeepAliveIdle
= TCP_COMP_VAL (
675 TCP_KEEPALIVE_IDLE_MIN
,
676 TCP_KEEPALIVE_IDLE_MAX
,
677 TCP_KEEPALIVE_IDLE_MIN
,
678 (UINT32
)(Option
->KeepAliveTime
* TCP_TICK_HZ
)
680 Tcb
->KeepAlivePeriod
= TCP_COMP_VAL (
681 TCP_KEEPALIVE_PERIOD_MIN
,
682 TCP_KEEPALIVE_PERIOD
,
683 TCP_KEEPALIVE_PERIOD
,
684 (UINT32
)(Option
->KeepAliveInterval
* TCP_TICK_HZ
)
688 Tcb
->ConnectTimeout
= TCP_COMP_VAL (
689 TCP_CONNECT_TIME_MIN
,
692 (UINT32
)(Option
->ConnectionTimeout
* TCP_TICK_HZ
)
695 if (!Option
->EnableNagle
) {
696 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
);
699 if (!Option
->EnableTimeStamp
) {
700 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_TS
);
703 if (!Option
->EnableWindowScaling
) {
704 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_NO_WS
);
709 // The socket is bound, the <SrcIp, SrcPort, DstIp, DstPort> is
710 // determined, construct the IP device path and install it.
712 Status
= TcpInstallDevicePath (Sk
);
713 if (EFI_ERROR (Status
)) {
718 // update state of Tcb and socket
720 if (((Sk
->IpVersion
== IP_VERSION_4
) && !CfgData
->Tcp4CfgData
.AccessPoint
.ActiveFlag
) ||
721 ((Sk
->IpVersion
== IP_VERSION_6
) && !CfgData
->Tcp6CfgData
.AccessPoint
.ActiveFlag
)
724 TcpSetState (Tcb
, TCP_LISTEN
);
725 SockSetState (Sk
, SO_LISTENING
);
727 Sk
->ConfigureState
= SO_CONFIGURED_PASSIVE
;
729 Sk
->ConfigureState
= SO_CONFIGURED_ACTIVE
;
732 if (Sk
->IpVersion
== IP_VERSION_6
) {
733 Tcb
->Tick
= TCP6_REFRESH_NEIGHBOR_TICK
;
735 if (NetIp6IsUnspecifiedAddr (&Tcb
->RemoteEnd
.Ip
.v6
)) {
736 Tcb
->RemoteIpZero
= TRUE
;
748 The protocol handler provided to the socket layer, which is used to
749 dispatch the socket level requests by calling the corresponding
752 @param[in] Sock Pointer to the socket of this TCP instance.
753 @param[in] Request The code of this operation request.
754 @param[in] Data Pointer to the operation specific data passed in
755 together with the operation request. This is an
756 optional parameter that may be NULL.
758 @retval EFI_SUCCESS The socket request completed successfully.
759 @retval other The error status returned by the corresponding TCP
767 IN VOID
*Data OPTIONAL
771 TCP_PROTO_DATA
*ProtoData
;
773 ProtoData
= (TCP_PROTO_DATA
*)Sock
->ProtoReserved
;
774 Tcb
= ProtoData
->TcpPcb
;
778 if (Tcb
->Sk
->IpVersion
== IP_VERSION_4
) {
779 ProtoData
->TcpService
->IpIo
->Ip
.Ip4
->Poll (ProtoData
->TcpService
->IpIo
->Ip
.Ip4
);
781 ProtoData
->TcpService
->IpIo
->Ip
.Ip6
->Poll (ProtoData
->TcpService
->IpIo
->Ip
.Ip6
);
788 // After user received data from socket buffer, socket will
789 // notify TCP using this message to give it a chance to send out
790 // window update information
792 ASSERT (Tcb
!= NULL
);
793 TcpOnAppConsume (Tcb
);
798 ASSERT (Tcb
!= NULL
);
815 Tcb
->SndPsh
= TcpGetMaxSndNxt (Tcb
) + GET_SND_DATASIZE (Tcb
->Sk
);
816 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_SND_PSH
);
821 Tcb
->SndUp
= TcpGetMaxSndNxt (Tcb
) + GET_SND_DATASIZE (Tcb
->Sk
) - 1;
822 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_SND_URG
);
828 TcpOnAppConnect (Tcb
);
834 return TcpAttachPcb (Sock
);
852 return TcpConfigurePcb (
854 (TCP_CONFIG_DATA
*)Data
861 ASSERT ((Data
!= NULL
) && (Tcb
!= NULL
));
863 if (Tcb
->Sk
->IpVersion
== IP_VERSION_4
) {
864 return Tcp4GetMode (Tcb
, (TCP4_MODE_DATA
*)Data
);
866 return Tcp6GetMode (Tcb
, (TCP6_MODE_DATA
*)Data
);
873 ASSERT ((Data
!= NULL
) && (Tcb
!= NULL
) && (Tcb
->Sk
->IpVersion
== IP_VERSION_4
));
875 return Tcp4Route (Tcb
, (TCP4_ROUTE_INFO
*)Data
);
879 return EFI_UNSUPPORTED
;