From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EA34D211A2D99 for ; Wed, 19 Dec 2018 21:00:00 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2018 21:00:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,375,1539673200"; d="scan'208";a="108767476" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga007.fm.intel.com with ESMTP; 19 Dec 2018 20:59:59 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 19 Dec 2018 20:59:58 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.59]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.203]) with mapi id 14.03.0415.000; Thu, 20 Dec 2018 12:59:55 +0800 From: "Wang, Jian J" To: "Fu, Siyuan" , "edk2-devel@lists.01.org" CC: "Wu, Hao A" , "Ni, Ruiyu" , "Zeng, Star" , "Wu, Jiaxin" Thread-Topic: [PATCH v2 1/6] MdeModulePkg: Delete Tcp4Dxe in MdeModulePkg. Thread-Index: AQHUmAU5qtNd6nryEUmNa8DaqvkhQKWHEZTw Date: Thu, 20 Dec 2018 04:59:54 +0000 Message-ID: References: <20181220014110.20324-1-siyuan.fu@intel.com> <20181220014110.20324-2-siyuan.fu@intel.com> In-Reply-To: <20181220014110.20324-2-siyuan.fu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWE1OTNiNmQtMThiYi00YjJjLTlkYzctOWJiMTA3ZDZkODNmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiV1BtS2RDM2E3M2gwXC96M0F2TlZidldIMFZMaE8zQURqUDFxOGVIRHBhakVnNVZmVTVnN3YzdFJDOFNCTUlXS2oifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: request-justification,no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 1/6] MdeModulePkg: Delete Tcp4Dxe in MdeModulePkg. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Dec 2018 05:00:01 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jian J Wang > -----Original Message----- > From: Fu, Siyuan > Sent: Thursday, December 20, 2018 9:41 AM > To: edk2-devel@lists.01.org > Cc: Wang, Jian J ; Wu, Hao A ; > Ni, Ruiyu ; Zeng, Star ; Wu, Jia= xin > > Subject: [PATCH v2 1/6] MdeModulePkg: Delete Tcp4Dxe in MdeModulePkg. >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1278 >=20 > This patch is to delete the Tcp4Dxe driver in MdeModulePkg. The driver > will not be maintained and can't co-work with the dual-stack TcpDxe in > NetworkPkg. >=20 > People should use below NetworkPkg drivers instead: > NetworkPkg/TcpDxe/TcpDxe.inf > Which is actively maintained with more bug fixes and new feature support. >=20 > Cc: Jian J Wang > Cc: Hao Wu > Cc: Ruiyu Ni > Cc: Star Zeng > Cc: Jiaxin Wu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Siyuan Fu > --- >=20 > Notes: > v2: > Break original patch to separate commits per module. >=20 > MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c | 433 ------ > MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c | 1201 ---------= ----- > -- > MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c | 990 ---------= --- > - > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c | 717 ---------= - > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c | 782 ---------= - > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c | 1497 ---------= ----- > ------ > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c | 112 -- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c | 674 --------- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c | 940 ---------= --- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.c | 352 ----- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c | 1238 ---------= --- > ---- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Timer.c | 584 -------- > MdeModulePkg/MdeModulePkg.dsc | 1 - > MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h | 131 -- > MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h | 954 ---------= ---- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.h | 342 ----- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf | 94 -- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.uni | 23 - > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4DxeExtra.uni | 20 - > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h | 781 ---------= - > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.h | 494 ------- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.h | 130 -- > MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Proto.h | 357 ----- > 23 files changed, 12847 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c > deleted file mode 100644 > index f1227691ec21..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c > +++ /dev/null > @@ -1,433 +0,0 @@ > -/** @file > - UEFI Component Name(2) protocol implementation for Tcp4Dxe driver. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > -/** > - Retrieves a Unicode string that is the user readable name of the drive= r. > - > - This function retrieves the user readable name of a driver in the form= of a > - Unicode string. If the driver specified by This has a user readable na= me in > - the language specified by Language, then a pointer to the driver name = is > - returned in DriverName, and EFI_SUCCESS is returned. If the driver spe= cified > - by This does not support the language specified by Language, > - then EFI_UNSUPPORTED is returned. > - > - @param[in] This A pointer to the > EFI_COMPONENT_NAME2_PROTOCOL or > - EFI_COMPONENT_NAME_PROTOCOL instance. > - > - @param[in] Language A pointer to a Null-terminated ASCII str= ing > - array indicating the language. This is t= he > - language of the driver name that the cal= ler is > - requesting, and it must match one of the > - languages specified in SupportedLanguage= s. The > - number of languages supported by a drive= r is up > - to the driver writer. Language is specif= ied > - in RFC 4646 or ISO 639-2 language code f= ormat. > - > - @param[out] DriverName A pointer to the Unicode string to retur= n. > - This Unicode string is the name of the > - driver specified by This in the language > - specified by Language. > - > - @retval EFI_SUCCESS The Unicode string for the Driver specif= ied by > - This and the language specified by Langu= age was > - returned in DriverName. > - > - @retval EFI_INVALID_PARAMETER Language is NULL. > - > - @retval EFI_INVALID_PARAMETER DriverName is NULL. > - > - @retval EFI_UNSUPPORTED The driver specified by This does not su= pport > - the language specified by Language. > - > -**/ > -EFI_STATUS > -EFIAPI > -TcpComponentNameGetDriverName ( > - IN EFI_COMPONENT_NAME_PROTOCOL *This, > - IN CHAR8 *Language, > - OUT CHAR16 **DriverName > - ); > - > - > -/** > - Retrieves a Unicode string that is the user readable name of the contr= oller > - that is being managed by a driver. > - > - This function retrieves the user readable name of the controller speci= fied by > - ControllerHandle and ChildHandle in the form of a Unicode string. If t= he > - driver specified by This has a user readable name in the language spec= ified by > - Language, then a pointer to the controller name is returned in Control= lerName, > - and EFI_SUCCESS is returned. If the driver specified by This is not c= urrently > - managing the controller specified by ControllerHandle and ChildHandle, > - then EFI_UNSUPPORTED is returned. If the driver specified by This doe= s not > - support the language specified by Language, then EFI_UNSUPPORTED is > returned. > - > - @param[in] This A pointer to the > EFI_COMPONENT_NAME2_PROTOCOL or > - EFI_COMPONENT_NAME_PROTOCOL instance. > - > - @param[in] ControllerHandle The handle of a controller that the driv= er > - specified by This is managing. This han= dle > - specifies the controller whose name is t= o be > - returned. > - > - @param[in] ChildHandle The handle of the child controller to re= trieve > - the name of. This is an optional parame= ter that > - may be NULL. It will be NULL for device > - drivers. It will also be NULL for a bus= drivers > - that wish to retrieve the name of the bu= s > - controller. It will not be NULL for a b= us > - driver that wishes to retrieve the name = of a > - child controller. > - > - @param[in] Language A pointer to a Null-terminated ASCII str= ing > - array indicating the language. This is = the > - language of the driver name that the cal= ler is > - requesting, and it must match one of the > - languages specified in SupportedLanguage= s. The > - number of languages supported by a drive= r is up > - to the driver writer. Language is specif= ied in > - RFC 4646 or ISO 639-2 language code form= at. > - > - @param[out] ControllerName A pointer to the Unicode string to retur= n. > - This Unicode string is the name of the > - controller specified by ControllerHandle= and > - ChildHandle in the language specified by > - Language from the point of view of the d= river > - specified by This. > - > - @retval EFI_SUCCESS The Unicode string for the user readable= name in > - the language specified by Language for t= he > - driver specified by This was returned in > - DriverName. > - > - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. > - > - @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a = valid > - EFI_HANDLE. > - > - @retval EFI_INVALID_PARAMETER Language is NULL. > - > - @retval EFI_INVALID_PARAMETER ControllerName is NULL. > - > - @retval EFI_UNSUPPORTED The driver specified by This is not curr= ently > - managing the controller specified by > - ControllerHandle and ChildHandle. > - > - @retval EFI_UNSUPPORTED The driver specified by This does not su= pport > - the language specified by Language. > - > -**/ > -EFI_STATUS > -EFIAPI > -TcpComponentNameGetControllerName ( > - IN EFI_COMPONENT_NAME_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN EFI_HANDLE ChildHandle OPTIONAL, > - IN CHAR8 *Language, > - OUT CHAR16 **ControllerName > - ); > - > - > -/// > -/// EFI Component Name Protocol > -/// > -GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL > gTcp4ComponentName =3D { > - TcpComponentNameGetDriverName, > - TcpComponentNameGetControllerName, > - "eng" > -}; > - > -/// > -/// EFI Component Name 2 Protocol > -/// > -GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL > gTcp4ComponentName2 =3D { > - (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) > TcpComponentNameGetDriverName, > - (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) > TcpComponentNameGetControllerName, > - "en" > -}; > - > - > -GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE > mTcpDriverNameTable[] =3D { > - { > - "eng;en", > - L"Tcp Network Service Driver" > - }, > - { > - NULL, > - NULL > - } > -}; > - > -GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE > *gTcpControllerNameTable =3D NULL; > - > -/** > - Retrieves a Unicode string that is the user readable name of the drive= r. > - > - This function retrieves the user readable name of a driver in the form= of a > - Unicode string. If the driver specified by This has a user readable na= me in > - the language specified by Language, then a pointer to the driver name = is > - returned in DriverName, and EFI_SUCCESS is returned. If the driver spe= cified > - by This does not support the language specified by Language, > - then EFI_UNSUPPORTED is returned. > - > - @param[in] This A pointer to the > EFI_COMPONENT_NAME2_PROTOCOL or > - EFI_COMPONENT_NAME_PROTOCOL instance. > - > - @param[in] Language A pointer to a Null-terminated ASCII str= ing > - array indicating the language. This is t= he > - language of the driver name that the cal= ler is > - requesting, and it must match one of the > - languages specified in SupportedLanguage= s. The > - number of languages supported by a drive= r is up > - to the driver writer. Language is specif= ied > - in RFC 4646 or ISO 639-2 language code f= ormat. > - > - @param[out] DriverName A pointer to the Unicode string to retur= n. > - This Unicode string is the name of the > - driver specified by This in the language > - specified by Language. > - > - @retval EFI_SUCCESS The Unicode string for the Driver specif= ied by > - This and the language specified by Langu= age was > - returned in DriverName. > - > - @retval EFI_INVALID_PARAMETER Language is NULL. > - > - @retval EFI_INVALID_PARAMETER DriverName is NULL. > - > - @retval EFI_UNSUPPORTED The driver specified by This does not su= pport > - the language specified by Language. > - > -**/ > -EFI_STATUS > -EFIAPI > -TcpComponentNameGetDriverName ( > - IN EFI_COMPONENT_NAME_PROTOCOL *This, > - IN CHAR8 *Language, > - OUT CHAR16 **DriverName > - ) > -{ > - return LookupUnicodeString2 ( > - Language, > - This->SupportedLanguages, > - mTcpDriverNameTable, > - DriverName, > - (BOOLEAN) (This =3D=3D &gTcp4ComponentName) > - ); > -} > - > -/** > - Update the component name for the Tcp4 child handle. > - > - @param Tcp4[in] A pointer to the EFI_TCP4_PROTOCOL. > - > - > - @retval EFI_SUCCESS Update the ControllerNameTable of t= his > instance successfully. > - @retval EFI_INVALID_PARAMETER The input parameter is invalid. > - > -**/ > -EFI_STATUS > -UpdateName ( > - IN EFI_TCP4_PROTOCOL *Tcp4 > - ) > -{ > - EFI_STATUS Status; > - CHAR16 HandleName[80]; > - EFI_TCP4_CONFIG_DATA Tcp4ConfigData; > - > - if (Tcp4 =3D=3D NULL) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Format the child name into the string buffer as: > - // TCPv4 (SrcPort=3D59, DestPort=3D60, ActiveFlag=3DTRUE) > - // > - ZeroMem (&Tcp4ConfigData, sizeof (Tcp4ConfigData)); > - Status =3D Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, > NULL); > - if (!EFI_ERROR (Status)) { > - UnicodeSPrint (HandleName, sizeof (HandleName), > - L"TCPv4 (SrcPort=3D%d, DestPort=3D%d, ActiveFlag=3D%s)", > - Tcp4ConfigData.AccessPoint.StationPort, > - Tcp4ConfigData.AccessPoint.RemotePort, > - (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE") > - ); > - } else if (Status =3D=3D EFI_NOT_STARTED) { > - UnicodeSPrint ( > - HandleName, > - sizeof (HandleName), > - L"TCPv4 (Not started)" > - ); > - } else { > - return Status; > - } > - > - if (gTcpControllerNameTable !=3D NULL) { > - FreeUnicodeStringTable (gTcpControllerNameTable); > - gTcpControllerNameTable =3D NULL; > - } > - > - Status =3D AddUnicodeString2 ( > - "eng", > - gTcp4ComponentName.SupportedLanguages, > - &gTcpControllerNameTable, > - HandleName, > - TRUE > - ); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - return AddUnicodeString2 ( > - "en", > - gTcp4ComponentName2.SupportedLanguages, > - &gTcpControllerNameTable, > - HandleName, > - FALSE > - ); > -} > - > -/** > - Retrieves a Unicode string that is the user readable name of the contr= oller > - that is being managed by a driver. > - > - This function retrieves the user readable name of the controller speci= fied by > - ControllerHandle and ChildHandle in the form of a Unicode string. If t= he > - driver specified by This has a user readable name in the language spec= ified by > - Language, then a pointer to the controller name is returned in Control= lerName, > - and EFI_SUCCESS is returned. If the driver specified by This is not c= urrently > - managing the controller specified by ControllerHandle and ChildHandle, > - then EFI_UNSUPPORTED is returned. If the driver specified by This doe= s not > - support the language specified by Language, then EFI_UNSUPPORTED is > returned. > - > - @param[in] This A pointer to the > EFI_COMPONENT_NAME2_PROTOCOL or > - EFI_COMPONENT_NAME_PROTOCOL instance. > - > - @param[in] ControllerHandle The handle of a controller that the driv= er > - specified by This is managing. This han= dle > - specifies the controller whose name is t= o be > - returned. > - > - @param[in] ChildHandle The handle of the child controller to r= etrieve > - the name of. This is an optional parame= ter that > - may be NULL. It will be NULL for device > - drivers. It will also be NULL for a bus= drivers > - that wish to retrieve the name of the bu= s > - controller. It will not be NULL for a b= us > - driver that wishes to retrieve the name = of a > - child controller. > - > - @param[in] Language A pointer to a Null-terminated ASCII str= ing > - array indicating the language. This is = the > - language of the driver name that the cal= ler is > - requesting, and it must match one of the > - languages specified in SupportedLanguage= s. The > - number of languages supported by a drive= r is up > - to the driver writer. Language is specif= ied in > - RFC 4646 or ISO 639-2 language code form= at. > - > - @param[out] ControllerName A pointer to the Unicode string to retur= n. > - This Unicode string is the name of the > - controller specified by ControllerHandle= and > - ChildHandle in the language specified by > - Language from the point of view of the d= river > - specified by This. > - > - @retval EFI_SUCCESS The Unicode string for the user readable= name in > - the language specified by Language for t= he > - driver specified by This was returned in > - DriverName. > - > - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. > - > - @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a = valid > - EFI_HANDLE. > - > - @retval EFI_INVALID_PARAMETER Language is NULL. > - > - @retval EFI_INVALID_PARAMETER ControllerName is NULL. > - > - @retval EFI_UNSUPPORTED The driver specified by This is not curr= ently > - managing the controller specified by > - ControllerHandle and ChildHandle. > - > - @retval EFI_UNSUPPORTED The driver specified by This does not su= pport > - the language specified by Language. > - > -**/ > -EFI_STATUS > -EFIAPI > -TcpComponentNameGetControllerName ( > - IN EFI_COMPONENT_NAME_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN EFI_HANDLE ChildHandle OPTIONAL, > - IN CHAR8 *Language, > - OUT CHAR16 **ControllerName > - ) > -{ > - EFI_STATUS Status; > - EFI_TCP4_PROTOCOL *Tcp4; > - > - // > - // Only provide names for child handles. > - // > - if (ChildHandle =3D=3D NULL) { > - return EFI_UNSUPPORTED; > - } > - > - // > - // Make sure this driver produced ChildHandle > - // > - Status =3D EfiTestChildHandle ( > - ControllerHandle, > - ChildHandle, > - &gEfiIp4ProtocolGuid > - ); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - // > - // Retrieve an instance of a produced protocol from ChildHandle > - // > - Status =3D gBS->OpenProtocol ( > - ChildHandle, > - &gEfiTcp4ProtocolGuid, > - (VOID **)&Tcp4, > - NULL, > - NULL, > - EFI_OPEN_PROTOCOL_GET_PROTOCOL > - ); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - // > - // Update the component name for this child handle. > - // > - Status =3D UpdateName (Tcp4); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - return LookupUnicodeString2 ( > - Language, > - This->SupportedLanguages, > - gTcpControllerNameTable, > - ControllerName, > - (BOOLEAN)(This =3D=3D &gTcp4ComponentName) > - ); > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c > deleted file mode 100644 > index adb5aa35cdf2..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c > +++ /dev/null > @@ -1,1201 +0,0 @@ > -/** @file > - Implementation of the Socket. > - > -Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "SockImpl.h" > - > -/** > - Get the length of the data that can be retrieved from the socket > - receive buffer. > - > - @param SockBuffer Pointer to the socket receive buffer. > - @param IsUrg Pointer to a BOOLEAN variable. If TRUE t= he data is > - OOB. > - @param BufLen The maximum length of the data buffer to= store the > - received data in socket layer. > - > - @return The length of the data can be retreived. > - > -**/ > -UINT32 > -SockTcpDataToRcv ( > - IN SOCK_BUFFER *SockBuffer, > - OUT BOOLEAN *IsUrg, > - IN UINT32 BufLen > - ); > - > -/** > - Process the send token. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockProcessSndToken ( > - IN OUT SOCKET *Sock > - ); > - > -/** > - Supporting function for both SockImpl and SockInterface. > - > - @param Event The Event this notify function registered to,= ignored. > - > -**/ > -VOID > -EFIAPI > -SockFreeFoo ( > - IN EFI_EVENT Event > - ) > -{ > - return ; > -} > - > - > -/** > - Get the length of the data that can be retrieved from the socket > - receive buffer. > - > - @param SockBuffer Pointer to the socket receive buffer. > - @param IsUrg Pointer to a BOOLEAN variable. If TRUE t= he data is > - OOB. > - @param BufLen The maximum length of the data buffer to= store the > - received data in socket layer. > - > - @return The length of the data can be retreived. > - > -**/ > -UINT32 > -SockTcpDataToRcv ( > - IN SOCK_BUFFER *SockBuffer, > - OUT BOOLEAN *IsUrg, > - IN UINT32 BufLen > - ) > -{ > - NET_BUF *RcvBufEntry; > - UINT32 DataLen; > - TCP_RSV_DATA *TcpRsvData; > - BOOLEAN Urg; > - ASSERT ((SockBuffer !=3D NULL) && (IsUrg !=3D NULL) && (BufLen > 0)); > - > - RcvBufEntry =3D SockBufFirst (SockBuffer); > - ASSERT (RcvBufEntry !=3D NULL); > - > - TcpRsvData =3D (TCP_RSV_DATA *) RcvBufEntry->ProtoData; > - > - *IsUrg =3D (BOOLEAN) ((TcpRsvData->UrgLen > 0) ? TRUE : FALSE); > - > - if (*IsUrg && TcpRsvData->UrgLen < RcvBufEntry->TotalSize) { > - > - DataLen =3D MIN (TcpRsvData->UrgLen, BufLen); > - > - if (DataLen < TcpRsvData->UrgLen) { > - TcpRsvData->UrgLen =3D TcpRsvData->UrgLen - DataLen; > - } else { > - TcpRsvData->UrgLen =3D 0; > - } > - > - return DataLen; > - > - } > - > - DataLen =3D RcvBufEntry->TotalSize; > - > - RcvBufEntry =3D SockBufNext (SockBuffer, RcvBufEntry); > - > - while ((BufLen > DataLen) && (RcvBufEntry !=3D NULL)) { > - > - TcpRsvData =3D (TCP_RSV_DATA *) RcvBufEntry->ProtoData; > - > - Urg =3D (BOOLEAN) ((TcpRsvData->UrgLen > 0) ? TRUE : FALSE); > - > - if (*IsUrg !=3D Urg) { > - break; > - } > - > - if (*IsUrg && TcpRsvData->UrgLen < RcvBufEntry->TotalSize) { > - > - if (TcpRsvData->UrgLen + DataLen < BufLen) { > - TcpRsvData->UrgLen =3D 0; > - } else { > - TcpRsvData->UrgLen =3D TcpRsvData->UrgLen - (BufLen - DataLen); > - } > - > - return MIN (TcpRsvData->UrgLen + DataLen, BufLen); > - > - } > - > - DataLen +=3D RcvBufEntry->TotalSize; > - > - RcvBufEntry =3D SockBufNext (SockBuffer, RcvBufEntry); > - } > - > - DataLen =3D MIN (BufLen, DataLen); > - return DataLen; > -} > - > - > -/** > - Copy data from socket buffer to application provided receive buffer. > - > - @param Sock Pointer to the socket. > - @param TcpRxData Pointer to the application provided rece= ive buffer. > - @param RcvdBytes The maximum length of the data can be co= pied. > - @param IsOOB If TRUE the data is OOB, FALSE the data = is normal. > - > -**/ > -VOID > -SockSetTcpRxData ( > - IN SOCKET *Sock, > - IN VOID *TcpRxData, > - IN UINT32 RcvdBytes, > - IN BOOLEAN IsOOB > - ) > -{ > - UINT32 Index; > - UINT32 CopyBytes; > - UINT32 OffSet; > - EFI_TCP4_RECEIVE_DATA *RxData; > - EFI_TCP4_FRAGMENT_DATA *Fragment; > - > - RxData =3D (EFI_TCP4_RECEIVE_DATA *) TcpRxData; > - > - OffSet =3D 0; > - > - ASSERT (RxData->DataLength >=3D RcvdBytes); > - > - RxData->DataLength =3D RcvdBytes; > - RxData->UrgentFlag =3D IsOOB; > - > - for (Index =3D 0; (Index < RxData->FragmentCount) && (RcvdBytes > 0); = Index++) > { > - > - Fragment =3D &RxData->FragmentTable[Index]; > - CopyBytes =3D MIN ((UINT32) (Fragment->FragmentLength), RcvdBytes); > - > - NetbufQueCopy ( > - Sock->RcvBuffer.DataQueue, > - OffSet, > - CopyBytes, > - Fragment->FragmentBuffer > - ); > - > - Fragment->FragmentLength =3D CopyBytes; > - RcvdBytes -=3D CopyBytes; > - OffSet +=3D CopyBytes; > - } > -} > - > - > -/** > - Get received data from the socket layer to the receive token. > - > - @param Sock Pointer to the socket. > - @param RcvToken Pointer to the application provided rece= ive token. > - > - @return The length of data received in this token. > - > -**/ > -UINT32 > -SockProcessRcvToken ( > - IN SOCKET *Sock, > - IN OUT SOCK_IO_TOKEN *RcvToken > - ) > -{ > - UINT32 TokenRcvdBytes; > - EFI_TCP4_RECEIVE_DATA *RxData; > - BOOLEAN IsUrg; > - > - ASSERT (Sock !=3D NULL); > - > - ASSERT (SockStream =3D=3D Sock->Type); > - > - RxData =3D RcvToken->Packet.RxData; > - > - TokenRcvdBytes =3D SockTcpDataToRcv ( > - &Sock->RcvBuffer, > - &IsUrg, > - (UINT32) RxData->DataLength > - ); > - > - // > - // Copy data from RcvBuffer of socket to user > - // provided RxData and set the fields in TCP RxData > - // > - SockSetTcpRxData (Sock, RxData, TokenRcvdBytes, IsUrg); > - > - NetbufQueTrim (Sock->RcvBuffer.DataQueue, TokenRcvdBytes); > - SIGNAL_TOKEN (&(RcvToken->Token), EFI_SUCCESS); > - > - return TokenRcvdBytes; > -} > - > - > -/** > - Process the TCP send data, buffer the tcp txdata and append > - the buffer to socket send buffer,then try to send it. > - > - @param Sock Pointer to the socket. > - @param TcpTxData Pointer to the application provided send= buffer. > - > - @retval EFI_SUCCESS The operation is completed successfully. > - @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. > - > -**/ > -EFI_STATUS > -SockProcessTcpSndData ( > - IN SOCKET *Sock, > - IN VOID *TcpTxData > - ) > -{ > - NET_BUF *SndData; > - EFI_STATUS Status; > - EFI_TCP4_TRANSMIT_DATA *TxData; > - > - TxData =3D (EFI_TCP4_TRANSMIT_DATA *) TcpTxData; > - > - // > - // transform this TxData into a NET_BUFFER > - // and insert it into Sock->SndBuffer > - // > - SndData =3D NetbufFromExt ( > - (NET_FRAGMENT *) TxData->FragmentTable, > - (UINT32) TxData->FragmentCount, > - 0, > - 0, > - SockFreeFoo, > - NULL > - ); > - > - if (NULL =3D=3D SndData) { > - DEBUG ((EFI_D_ERROR, "SockKProcessSndData: Failed to" > - " call NetBufferFromExt\n")); > - > - return EFI_OUT_OF_RESOURCES; > - } > - > - NetbufQueAppend (Sock->SndBuffer.DataQueue, SndData); > - > - // > - // notify the low layer protocol to handle this send token > - // > - if (TxData->Urgent) { > - Status =3D Sock->ProtoHandler (Sock, SOCK_SNDURG, NULL); > - > - if (EFI_ERROR (Status)) { > - return Status; > - } > - } > - > - if (TxData->Push) { > - Status =3D Sock->ProtoHandler (Sock, SOCK_SNDPUSH, NULL); > - > - if (EFI_ERROR (Status)) { > - return Status; > - } > - } > - > - // > - // low layer protocol should really handle the sending > - // process when catching SOCK_SND request > - // > - Status =3D Sock->ProtoHandler (Sock, SOCK_SND, NULL); > - > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - return EFI_SUCCESS; > -} > - > - > -/** > - Flush the tokens in the specific token list. > - > - @param Sock Pointer to the socket. > - @param PendingTokenList Pointer to the token list to be flushed. > - > -**/ > -VOID > -SockFlushPendingToken ( > - IN SOCKET *Sock, > - IN LIST_ENTRY *PendingTokenList > - ) > -{ > - SOCK_TOKEN *SockToken; > - SOCK_COMPLETION_TOKEN *Token; > - > - ASSERT ((Sock !=3D NULL) && (PendingTokenList !=3D NULL)); > - > - while (!IsListEmpty (PendingTokenList)) { > - SockToken =3D NET_LIST_HEAD ( > - PendingTokenList, > - SOCK_TOKEN, > - TokenList > - ); > - > - Token =3D SockToken->Token; > - SIGNAL_TOKEN (Token, Sock->SockError); > - > - RemoveEntryList (&(SockToken->TokenList)); > - FreePool (SockToken); > - } > -} > - > - > -/** > - Wake up the connection token while the connection is successfully esta= blished, > - then try to process any pending send token. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockWakeConnToken ( > - IN OUT SOCKET *Sock > - ) > -{ > - ASSERT (Sock->ConnectionToken !=3D NULL); > - > - SIGNAL_TOKEN (Sock->ConnectionToken, EFI_SUCCESS); > - Sock->ConnectionToken =3D NULL; > - > - // > - // check to see if some pending send token existed? > - // > - SockProcessSndToken (Sock); > - return ; > -} > - > - > -/** > - Wake up the listen token while the connection is established successfu= lly. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockWakeListenToken ( > - IN OUT SOCKET *Sock > - ) > -{ > - SOCKET *Parent; > - SOCK_TOKEN *SockToken; > - EFI_TCP4_LISTEN_TOKEN *ListenToken; > - > - Parent =3D Sock->Parent; > - > - ASSERT ((Parent !=3D NULL) && SOCK_IS_LISTENING (Parent) && > SOCK_IS_CONNECTED (Sock)); > - > - if (!IsListEmpty (&Parent->ListenTokenList)) { > - SockToken =3D NET_LIST_HEAD ( > - &Parent->ListenTokenList, > - SOCK_TOKEN, > - TokenList > - ); > - > - ListenToken =3D (EFI_TCP4_LISTEN_TOKEN *) SockToken->Token; > - ListenToken->NewChildHandle =3D Sock->SockHandle; > - > - SIGNAL_TOKEN (&(ListenToken->CompletionToken), EFI_SUCCESS); > - > - RemoveEntryList (&SockToken->TokenList); > - FreePool (SockToken); > - > - RemoveEntryList (&Sock->ConnectionList); > - > - Parent->ConnCnt--; > - DEBUG ((EFI_D_NET, "SockWakeListenToken: accept a socket, now conncn= t > is %d", Parent->ConnCnt)); > - > - Sock->Parent =3D NULL; > - } > -} > - > - > -/** > - Wake up the receive token while some data is received. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockWakeRcvToken ( > - IN SOCKET *Sock > - ) > -{ > - UINT32 RcvdBytes; > - UINT32 TokenRcvdBytes; > - SOCK_TOKEN *SockToken; > - SOCK_IO_TOKEN *RcvToken; > - > - ASSERT (Sock->RcvBuffer.DataQueue !=3D NULL); > - > - RcvdBytes =3D (Sock->RcvBuffer.DataQueue)->BufSize; > - > - ASSERT (RcvdBytes > 0); > - > - while (RcvdBytes > 0 && !IsListEmpty (&Sock->RcvTokenList)) { > - > - SockToken =3D NET_LIST_HEAD ( > - &Sock->RcvTokenList, > - SOCK_TOKEN, > - TokenList > - ); > - > - RcvToken =3D (SOCK_IO_TOKEN *) SockToken->Token; > - TokenRcvdBytes =3D SockProcessRcvToken (Sock, RcvToken); > - > - if (0 =3D=3D TokenRcvdBytes) { > - return ; > - } > - > - RemoveEntryList (&(SockToken->TokenList)); > - FreePool (SockToken); > - RcvdBytes -=3D TokenRcvdBytes; > - } > -} > - > - > -/** > - Process the send token. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockProcessSndToken ( > - IN OUT SOCKET *Sock > - ) > -{ > - UINT32 FreeSpace; > - SOCK_TOKEN *SockToken; > - UINT32 DataLen; > - SOCK_IO_TOKEN *SndToken; > - EFI_TCP4_TRANSMIT_DATA *TxData; > - EFI_STATUS Status; > - > - ASSERT ((Sock !=3D NULL) && (SockStream =3D=3D Sock->Type)); > - > - FreeSpace =3D SockGetFreeSpace (Sock, SOCK_SND_BUF); > - > - // > - // to determine if process a send token using > - // socket layer flow control policy > - // > - while ((FreeSpace >=3D Sock->SndBuffer.LowWater) && > - !IsListEmpty (&Sock->SndTokenList)) { > - > - SockToken =3D NET_LIST_HEAD ( > - &(Sock->SndTokenList), > - SOCK_TOKEN, > - TokenList > - ); > - > - // > - // process this token > - // > - RemoveEntryList (&(SockToken->TokenList)); > - InsertTailList ( > - &(Sock->ProcessingSndTokenList), > - &(SockToken->TokenList) > - ); > - > - // > - // Proceess it in the light of SockType > - // > - SndToken =3D (SOCK_IO_TOKEN *) SockToken->Token; > - TxData =3D SndToken->Packet.TxData; > - > - DataLen =3D (UINT32) TxData->DataLength; > - Status =3D SockProcessTcpSndData (Sock, TxData); > - > - if (EFI_ERROR (Status)) { > - goto OnError; > - } > - > - if (DataLen >=3D FreeSpace) { > - FreeSpace =3D 0; > - > - } else { > - FreeSpace -=3D DataLen; > - > - } > - } > - > - return ; > - > -OnError: > - > - RemoveEntryList (&SockToken->TokenList); > - SIGNAL_TOKEN (SockToken->Token, Status); > - FreePool (SockToken); > -} > - > - > -/** > - Create a socket with initial data SockInitData. > - > - @param SockInitData Pointer to the initial data of the socke= t. > - > - @return Pointer to the newly created socket, return NULL when exceptio= n > occured. > - > -**/ > -SOCKET * > -SockCreate ( > - IN SOCK_INIT_DATA *SockInitData > - ) > -{ > - SOCKET *Sock; > - SOCKET *Parent; > - EFI_STATUS Status; > - > - ASSERT ((SockInitData !=3D NULL) && (SockInitData->ProtoHandler !=3D N= ULL)); > - ASSERT (SockInitData->Type =3D=3D SockStream); > - ASSERT ((SockInitData->ProtoData !=3D NULL) && (SockInitData->DataSize= <=3D > PROTO_RESERVED_LEN)); > - > - Parent =3D SockInitData->Parent; > - > - if ((Parent !=3D NULL) && (Parent->ConnCnt =3D=3D Parent->BackLog)) { > - DEBUG ( > - (EFI_D_ERROR, > - "SockCreate: Socket parent has " > - "reached its connection limit with %d ConnCnt and %d BackLog\n", > - Parent->ConnCnt, > - Parent->BackLog) > - ); > - > - return NULL; > - } > - > - Sock =3D AllocateZeroPool (sizeof (SOCKET)); > - if (NULL =3D=3D Sock) { > - > - DEBUG ((EFI_D_ERROR, "SockCreate: No resource to create a new > socket\n")); > - return NULL; > - } > - > - InitializeListHead (&Sock->Link); > - InitializeListHead (&Sock->ConnectionList); > - InitializeListHead (&Sock->ListenTokenList); > - InitializeListHead (&Sock->RcvTokenList); > - InitializeListHead (&Sock->SndTokenList); > - InitializeListHead (&Sock->ProcessingSndTokenList); > - > - EfiInitializeLock (&(Sock->Lock), TPL_CALLBACK); > - > - Sock->SndBuffer.DataQueue =3D NetbufQueAlloc (); > - if (NULL =3D=3D Sock->SndBuffer.DataQueue) { > - DEBUG ((EFI_D_ERROR, "SockCreate: No resource to allocate" > - " SndBuffer for new socket\n")); > - > - goto OnError; > - } > - > - Sock->RcvBuffer.DataQueue =3D NetbufQueAlloc (); > - if (NULL =3D=3D Sock->RcvBuffer.DataQueue) { > - DEBUG ((EFI_D_ERROR, "SockCreate: No resource to allocate " > - "RcvBuffer for new socket\n")); > - > - goto OnError; > - } > - > - Sock->Signature =3D SOCK_SIGNATURE; > - > - Sock->Parent =3D Parent; > - Sock->BackLog =3D SockInitData->BackLog; > - Sock->ProtoHandler =3D SockInitData->ProtoHandler; > - Sock->SndBuffer.HighWater =3D SockInitData->SndBufferSize; > - Sock->RcvBuffer.HighWater =3D SockInitData->RcvBufferSize; > - Sock->Type =3D SockInitData->Type; > - Sock->DriverBinding =3D SockInitData->DriverBinding; > - Sock->State =3D SockInitData->State; > - Sock->CreateCallback =3D SockInitData->CreateCallback; > - Sock->DestroyCallback =3D SockInitData->DestroyCallback; > - Sock->Context =3D SockInitData->Context; > - > - Sock->SockError =3D EFI_ABORTED; > - Sock->SndBuffer.LowWater =3D SOCK_BUFF_LOW_WATER; > - Sock->RcvBuffer.LowWater =3D SOCK_BUFF_LOW_WATER; > - > - // > - // Install protocol on Sock->SockHandle > - // > - CopyMem ( > - &(Sock->NetProtocol.TcpProtocol), > - SockInitData->Protocol, > - sizeof (EFI_TCP4_PROTOCOL) > - ); > - > - // > - // copy the protodata into socket > - // > - CopyMem (Sock->ProtoReserved, SockInitData->ProtoData, SockInitData- > >DataSize); > - > - Status =3D gBS->InstallMultipleProtocolInterfaces ( > - &Sock->SockHandle, > - &gEfiTcp4ProtocolGuid, > - &(Sock->NetProtocol.TcpProtocol), > - NULL > - ); > - > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "SockCreate: Install TCP protocol in " > - "socket failed with %r\n", Status)); > - > - goto OnError; > - } > - > - if (Parent !=3D NULL) { > - ASSERT (Parent->BackLog > 0); > - ASSERT (SOCK_IS_LISTENING (Parent)); > - > - // > - // need to add it into Parent->ConnectionList > - // if the Parent->ConnCnt < Parent->BackLog > - // > - Parent->ConnCnt++; > - > - DEBUG ( > - (EFI_D_NET, > - "SockCreate: Create a new socket and add to parent, now conncnt is= %d\n", > - Parent->ConnCnt) > - ); > - > - InsertTailList (&Parent->ConnectionList, &Sock->ConnectionList); > - } > - > - if (Sock->CreateCallback !=3D NULL) { > - Status =3D Sock->CreateCallback (Sock, Sock->Context); > - if (EFI_ERROR (Status)) { > - goto OnError; > - } > - } > - > - return Sock; > - > -OnError: > - > - if (Sock->SockHandle !=3D NULL) { > - gBS->UninstallMultipleProtocolInterfaces ( > - Sock->SockHandle, > - &gEfiTcp4ProtocolGuid, > - &(Sock->NetProtocol.TcpProtocol), > - NULL > - ); > - } > - > - if (NULL !=3D Sock->SndBuffer.DataQueue) { > - NetbufQueFree (Sock->SndBuffer.DataQueue); > - } > - > - if (NULL !=3D Sock->RcvBuffer.DataQueue) { > - NetbufQueFree (Sock->RcvBuffer.DataQueue); > - } > - > - FreePool (Sock); > - > - return NULL; > -} > - > - > -/** > - Destroy a socket. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockDestroy ( > - IN OUT SOCKET *Sock > - ) > -{ > - ASSERT (SockStream =3D=3D Sock->Type); > - > - // > - // Flush the completion token buffered > - // by sock and rcv, snd buffer > - // > - if (!SOCK_IS_UNCONFIGURED (Sock)) { > - > - SockConnFlush (Sock); > - SockSetState (Sock, SO_CLOSED); > - Sock->ConfigureState =3D SO_UNCONFIGURED; > - > - } > - // > - // Destroy the RcvBuffer Queue and SendBuffer Queue > - // > - NetbufQueFree (Sock->RcvBuffer.DataQueue); > - NetbufQueFree (Sock->SndBuffer.DataQueue); > - > - // > - // Remove it from parent connection list if needed > - // > - if (Sock->Parent !=3D NULL) { > - > - RemoveEntryList (&(Sock->ConnectionList)); > - (Sock->Parent->ConnCnt)--; > - > - DEBUG ( > - (EFI_D_NET, > - "SockDestroy: Delete a unaccepted socket from parent" > - "now conncnt is %d\n", > - Sock->Parent->ConnCnt) > - ); > - > - Sock->Parent =3D NULL; > - } > - > - FreePool (Sock); > - return ; > -} > - > - > -/** > - Flush the sndBuffer and rcvBuffer of socket. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockConnFlush ( > - IN OUT SOCKET *Sock > - ) > -{ > - SOCKET *Child; > - > - ASSERT (Sock !=3D NULL); > - > - // > - // Clear the flag in this socket > - // > - Sock->Flag =3D 0; > - > - // > - // Flush the SndBuffer and RcvBuffer of Sock > - // > - NetbufQueFlush (Sock->SndBuffer.DataQueue); > - NetbufQueFlush (Sock->RcvBuffer.DataQueue); > - > - // > - // Signal the pending token > - // > - if (Sock->ConnectionToken !=3D NULL) { > - SIGNAL_TOKEN (Sock->ConnectionToken, Sock->SockError); > - Sock->ConnectionToken =3D NULL; > - } > - > - if (Sock->CloseToken !=3D NULL) { > - SIGNAL_TOKEN (Sock->CloseToken, Sock->SockError); > - Sock->CloseToken =3D NULL; > - } > - > - SockFlushPendingToken (Sock, &(Sock->ListenTokenList)); > - SockFlushPendingToken (Sock, &(Sock->RcvTokenList)); > - SockFlushPendingToken (Sock, &(Sock->SndTokenList)); > - SockFlushPendingToken (Sock, &(Sock->ProcessingSndTokenList)); > - > - // > - // Destroy the pending connection, if it is a listening socket > - // > - if (SOCK_IS_LISTENING (Sock)) { > - while (!IsListEmpty (&Sock->ConnectionList)) { > - Child =3D NET_LIST_HEAD ( > - &Sock->ConnectionList, > - SOCKET, > - ConnectionList > - ); > - > - SockDestroyChild (Child); > - } > - > - Sock->ConnCnt =3D 0; > - } > - > - return ; > -} > - > - > -/** > - Set the state of the socket. > - > - @param Sock Pointer to the socket. > - @param State The new socket state to be set. > - > -**/ > -VOID > -SockSetState ( > - IN OUT SOCKET *Sock, > - IN UINT8 State > - ) > -{ > - Sock->State =3D State; > -} > - > - > -/** > - Clone a new socket including its associated protocol control block. > - > - @param Sock Pointer to the socket to be cloned. > - > - @return Pointer to the newly cloned socket. If NULL, error condition o= ccurred. > - > -**/ > -SOCKET * > -SockClone ( > - IN SOCKET *Sock > - ) > -{ > - SOCKET *ClonedSock; > - SOCK_INIT_DATA InitData; > - > - InitData.BackLog =3D Sock->BackLog; > - InitData.Parent =3D Sock; > - InitData.State =3D Sock->State; > - InitData.ProtoHandler =3D Sock->ProtoHandler; > - InitData.Type =3D Sock->Type; > - InitData.RcvBufferSize =3D Sock->RcvBuffer.HighWater; > - InitData.SndBufferSize =3D Sock->SndBuffer.HighWater; > - InitData.DriverBinding =3D Sock->DriverBinding; > - InitData.Protocol =3D &(Sock->NetProtocol); > - InitData.CreateCallback =3D Sock->CreateCallback; > - InitData.DestroyCallback =3D Sock->DestroyCallback; > - InitData.Context =3D Sock->Context; > - InitData.ProtoData =3D Sock->ProtoReserved; > - InitData.DataSize =3D sizeof (Sock->ProtoReserved); > - > - ClonedSock =3D SockCreate (&InitData); > - > - if (NULL =3D=3D ClonedSock) { > - DEBUG ((EFI_D_ERROR, "SockClone: no resource to create a cloned sock= \n")); > - return NULL; > - } > - > - SockSetState (ClonedSock, SO_CONNECTING); > - ClonedSock->ConfigureState =3D Sock->ConfigureState; > - > - return ClonedSock; > -} > - > - > -/** > - Called by the low layer protocol to indicate the socket a connection i= s > - established. > - > - This function just changes the socket's state to SO_CONNECTED > - and signals the token used for connection establishment. > - > - @param Sock Pointer to the socket associated with th= e > - established connection. > -**/ > -VOID > -SockConnEstablished ( > - IN SOCKET *Sock > - ) > -{ > - > - ASSERT (SO_CONNECTING =3D=3D Sock->State); > - > - SockSetState (Sock, SO_CONNECTED); > - > - if (NULL =3D=3D Sock->Parent) { > - SockWakeConnToken (Sock); > - } else { > - SockWakeListenToken (Sock); > - } > - > - return ; > -} > - > - > -/** > - Called by the low layer protocol to indicate the connection is closed. > - > - This function flushes the socket, sets the state to SO_CLOSED and sign= als > - the close token. > - > - @param Sock Pointer to the socket associated with th= e closed > - connection. > - > -**/ > -VOID > -SockConnClosed ( > - IN OUT SOCKET *Sock > - ) > -{ > - if (Sock->CloseToken !=3D NULL) { > - SIGNAL_TOKEN (Sock->CloseToken, EFI_SUCCESS); > - Sock->CloseToken =3D NULL; > - } > - > - SockConnFlush (Sock); > - SockSetState (Sock, SO_CLOSED); > - > - if (Sock->Parent !=3D NULL) { > - SockDestroyChild (Sock); > - } > - > -} > - > - > -/** > - Called by low layer protocol to indicate that some data is sent or pro= cessed. > - > - This function trims the sent data in the socket send buffer, signals t= he data > - token if proper. > - > - @param Sock Pointer to the socket. > - @param Count The length of the data processed or sent= , in bytes. > - > -**/ > -VOID > -SockDataSent ( > - IN SOCKET *Sock, > - IN UINT32 Count > - ) > -{ > - SOCK_TOKEN *SockToken; > - SOCK_COMPLETION_TOKEN *SndToken; > - > - ASSERT (!IsListEmpty (&Sock->ProcessingSndTokenList)); > - ASSERT (Count <=3D (Sock->SndBuffer.DataQueue)->BufSize); > - > - NetbufQueTrim (Sock->SndBuffer.DataQueue, Count); > - > - // > - // To check if we can signal some snd token in this socket > - // > - while (Count > 0) { > - SockToken =3D NET_LIST_HEAD ( > - &(Sock->ProcessingSndTokenList), > - SOCK_TOKEN, > - TokenList > - ); > - > - SndToken =3D SockToken->Token; > - > - if (SockToken->RemainDataLen <=3D Count) { > - > - RemoveEntryList (&(SockToken->TokenList)); > - SIGNAL_TOKEN (SndToken, EFI_SUCCESS); > - Count -=3D SockToken->RemainDataLen; > - FreePool (SockToken); > - } else { > - > - SockToken->RemainDataLen -=3D Count; > - Count =3D 0; > - } > - } > - > - // > - // to judge if we can process some send token in > - // Sock->SndTokenList, if so process those send token > - // > - SockProcessSndToken (Sock); > - return ; > -} > - > - > -/** > - Called by the low layer protocol to copy some data in socket send > - buffer starting from the specific offset to a buffer provided by > - the caller. > - > - @param Sock Pointer to the socket. > - @param Offset The start point of the data to be copied= . > - @param Len The length of the data to be copied. > - @param Dest Pointer to the destination to copy the d= ata. > - > - @return The data size copied. > - > -**/ > -UINT32 > -SockGetDataToSend ( > - IN SOCKET *Sock, > - IN UINT32 Offset, > - IN UINT32 Len, > - IN UINT8 *Dest > - ) > -{ > - ASSERT ((Sock !=3D NULL) && SockStream =3D=3D Sock->Type); > - > - return NetbufQueCopy ( > - Sock->SndBuffer.DataQueue, > - Offset, > - Len, > - Dest > - ); > -} > - > - > -/** > - Called by the low layer protocol to deliver received data to socket la= yer. > - > - This function will append the data to the socket receive buffer, set t= her > - urgent data length and then check if any receive token can be signaled= . > - > - @param Sock Pointer to the socket. > - @param NetBuffer Pointer to the buffer that contains the = received > - data. > - @param UrgLen The length of the urgent data in the rec= eived data. > - > -**/ > -VOID > -SockDataRcvd ( > - IN SOCKET *Sock, > - IN OUT NET_BUF *NetBuffer, > - IN UINT32 UrgLen > - ) > -{ > - ASSERT ((Sock !=3D NULL) && (Sock->RcvBuffer.DataQueue !=3D NULL) && > - UrgLen <=3D NetBuffer->TotalSize); > - > - NET_GET_REF (NetBuffer); > - > - ((TCP_RSV_DATA *) (NetBuffer->ProtoData))->UrgLen =3D UrgLen; > - > - NetbufQueAppend (Sock->RcvBuffer.DataQueue, NetBuffer); > - > - SockWakeRcvToken (Sock); > - return ; > -} > - > - > -/** > - Get the length of the free space of the specific socket buffer. > - > - @param Sock Pointer to the socket. > - @param Which Flag to indicate which socket buffer to = check, > - either send buffer or receive buffer. > - > - @return The length of the free space, in bytes. > - > -**/ > -UINT32 > -SockGetFreeSpace ( > - IN SOCKET *Sock, > - IN UINT32 Which > - ) > -{ > - UINT32 BufferCC; > - SOCK_BUFFER *SockBuffer; > - > - ASSERT ((Sock !=3D NULL) && ((SOCK_SND_BUF =3D=3D Which) || (SOCK_RCV_= BUF > =3D=3D Which))); > - > - if (SOCK_SND_BUF =3D=3D Which) { > - SockBuffer =3D &(Sock->SndBuffer); > - } else { > - SockBuffer =3D &(Sock->RcvBuffer); > - } > - > - BufferCC =3D (SockBuffer->DataQueue)->BufSize; > - > - if (BufferCC >=3D SockBuffer->HighWater) { > - > - return 0; > - } > - > - return SockBuffer->HighWater - BufferCC; > -} > - > - > - > -/** > - Called by the low layer protocol to indicate that there will be no mor= e data > - from the communication peer. > - > - This function set the socket's state to SO_NO_MORE_DATA and signal all > queued > - IO tokens with the error status EFI_CONNECTION_FIN. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockNoMoreData ( > - IN OUT SOCKET *Sock > - ) > -{ > - EFI_STATUS Err; > - > - SOCK_NO_MORE_DATA (Sock); > - > - if (!IsListEmpty (&Sock->RcvTokenList)) { > - > - ASSERT (0 =3D=3D GET_RCV_DATASIZE (Sock)); > - > - Err =3D Sock->SockError; > - > - SOCK_ERROR (Sock, EFI_CONNECTION_FIN); > - > - SockFlushPendingToken (Sock, &Sock->RcvTokenList); > - > - SOCK_ERROR (Sock, Err); > - > - } > - > -} > - > - > -/** > - Get the first buffer block in the specific socket buffer. > - > - @param Sockbuf Pointer to the socket buffer. > - > - @return Pointer to the first buffer in the queue. NULL if the queue is= empty. > - > -**/ > -NET_BUF * > -SockBufFirst ( > - IN SOCK_BUFFER *Sockbuf > - ) > -{ > - LIST_ENTRY *NetbufList; > - > - NetbufList =3D &(Sockbuf->DataQueue->BufList); > - > - if (IsListEmpty (NetbufList)) { > - return NULL; > - } > - > - return NET_LIST_HEAD (NetbufList, NET_BUF, List); > -} > - > - > -/** > - Get the next buffer block in the specific socket buffer. > - > - @param Sockbuf Pointer to the socket buffer. > - @param SockEntry Pointer to the buffer block prior to the= required > - one. > - > - @return Pointer to the buffer block next to SockEntry. NULL if SockEnt= ry is > - the tail or head entry. > - > -**/ > -NET_BUF * > -SockBufNext ( > - IN SOCK_BUFFER *Sockbuf, > - IN NET_BUF *SockEntry > - ) > -{ > - LIST_ENTRY *NetbufList; > - > - NetbufList =3D &(Sockbuf->DataQueue->BufList); > - > - if ((SockEntry->List.ForwardLink =3D=3D NetbufList) || > - (SockEntry->List.BackLink =3D=3D &SockEntry->List) || > - (SockEntry->List.ForwardLink =3D=3D &SockEntry->List)) { > - > - return NULL; > - } > - > - return NET_LIST_USER_STRUCT (SockEntry->List.ForwardLink, NET_BUF, Lis= t); > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c > deleted file mode 100644 > index cd20b8bcb2dd..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c > +++ /dev/null > @@ -1,990 +0,0 @@ > -/** @file > - Interface function of the Socket. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > - > -#include "SockImpl.h" > - > - > -/** > - Check whether the Event is in the List. > - > - @param List Pointer to the token list to be searched. > - @param Event The event to be checked. > - > - @retval TRUE The specific Event exists in the List. > - @retval FALSE The specific Event is not in the List. > - > -**/ > -BOOLEAN > -SockTokenExistedInList ( > - IN LIST_ENTRY *List, > - IN EFI_EVENT Event > - ) > -{ > - LIST_ENTRY *ListEntry; > - SOCK_TOKEN *SockToken; > - > - NET_LIST_FOR_EACH (ListEntry, List) { > - SockToken =3D NET_LIST_USER_STRUCT ( > - ListEntry, > - SOCK_TOKEN, > - TokenList > - ); > - > - if (Event =3D=3D SockToken->Token->Event) { > - return TRUE; > - } > - } > - > - return FALSE; > -} > - > - > -/** > - Call SockTokenExistedInList() to check whether the Event is > - in the related socket's lists. > - > - @param Sock Pointer to the instance's socket. > - @param Event The event to be checked. > - > - @retval TRUE The Event exists in related socket's list= s. > - @retval FALSE The Event is not in related socket's list= s. > - > -**/ > -BOOLEAN > -SockTokenExisted ( > - IN SOCKET *Sock, > - IN EFI_EVENT Event > - ) > -{ > - > - if (SockTokenExistedInList (&Sock->SndTokenList, Event) || > - SockTokenExistedInList (&Sock->ProcessingSndTokenList, Event) || > - SockTokenExistedInList (&Sock->RcvTokenList, Event) || > - SockTokenExistedInList (&Sock->ListenTokenList, Event)) { > - > - return TRUE; > - } > - > - if ((Sock->ConnectionToken !=3D NULL) && > - (Sock->ConnectionToken->Event =3D=3D Event)) { > - > - return TRUE; > - } > - > - if ((Sock->CloseToken !=3D NULL) && (Sock->CloseToken->Event =3D=3D Ev= ent)) { > - return TRUE; > - } > - > - return FALSE; > -} > - > - > -/** > - Buffer a token into the specific list of socket Sock. > - > - @param Sock Pointer to the instance's socket. > - @param List Pointer to the list to store the token. > - @param Token Pointer to the token to be buffered. > - @param DataLen The data length of the buffer contained i= n Token. > - > - @return Pointer to the token that wraps Token. If NULL, error conditio= n > occurred. > - > -**/ > -SOCK_TOKEN * > -SockBufferToken ( > - IN SOCKET *Sock, > - IN LIST_ENTRY *List, > - IN VOID *Token, > - IN UINT32 DataLen > - ) > -{ > - SOCK_TOKEN *SockToken; > - > - SockToken =3D AllocatePool (sizeof (SOCK_TOKEN)); > - if (NULL =3D=3D SockToken) { > - > - DEBUG ((EFI_D_ERROR, "SockBufferIOToken: No Memory " > - "to allocate SockToken\n")); > - > - return NULL; > - } > - > - SockToken->Sock =3D Sock; > - SockToken->Token =3D (SOCK_COMPLETION_TOKEN *) Token; > - SockToken->RemainDataLen =3D DataLen; > - InsertTailList (List, &SockToken->TokenList); > - > - return SockToken; > -} > - > - > -/** > - Destroy the socket Sock and its associated protocol control block. > - > - @param Sock The socket to be destroyed. > - > - @retval EFI_SUCCESS The socket Sock is destroyed successfully= . > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et. > - > -**/ > -EFI_STATUS > -SockDestroyChild ( > - IN SOCKET *Sock > - ) > -{ > - EFI_STATUS Status; > - TCP4_PROTO_DATA *ProtoData; > - TCP_CB *Tcb; > - VOID *SockProtocol; > - > - ASSERT ((Sock !=3D NULL) && (Sock->ProtoHandler !=3D NULL)); > - > - if (Sock->InDestroy) { > - return EFI_SUCCESS; > - } > - > - Sock->InDestroy =3D TRUE; > - > - ProtoData =3D (TCP4_PROTO_DATA *) Sock->ProtoReserved; > - Tcb =3D ProtoData->TcpPcb; > - > - ASSERT (Tcb !=3D NULL); > - > - // > - // Close the IP protocol. > - // > - gBS->CloseProtocol ( > - Tcb->IpInfo->ChildHandle, > - &gEfiIp4ProtocolGuid, > - ProtoData->TcpService->IpIo->Image, > - Sock->SockHandle > - ); > - > - if (Sock->DestroyCallback !=3D NULL) { > - Sock->DestroyCallback (Sock, Sock->Context); > - } > - > - // > - // Retrieve the protocol installed on this sock > - // > - Status =3D gBS->OpenProtocol ( > - Sock->SockHandle, > - &gEfiTcp4ProtocolGuid, > - &SockProtocol, > - Sock->DriverBinding, > - Sock->SockHandle, > - EFI_OPEN_PROTOCOL_GET_PROTOCOL > - ); > - > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockDestroyChild: Open protocol installed " > - "on socket failed with %r\n", Status)); > - } > - > - // > - // Uninstall the protocol installed on this sock > - // in the light of Sock->SockType > - // > - gBS->UninstallMultipleProtocolInterfaces ( > - Sock->SockHandle, > - &gEfiTcp4ProtocolGuid, > - SockProtocol, > - NULL > - ); > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockDestroyChild: Get the lock to " > - "access socket failed with %r\n", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - // > - // force protocol layer to detach the PCB > - // > - Status =3D Sock->ProtoHandler (Sock, SOCK_DETACH, NULL); > - > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockDestroyChild: Protocol detach socket" > - " failed with %r\n", Status)); > - > - Sock->InDestroy =3D FALSE; > - } else if (SOCK_IS_CONFIGURED (Sock)) { > - > - SockConnFlush (Sock); > - SockSetState (Sock, SO_CLOSED); > - > - Sock->ConfigureState =3D SO_UNCONFIGURED; > - } > - > - EfiReleaseLock (&(Sock->Lock)); > - > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - SockDestroy (Sock); > - return EFI_SUCCESS; > -} > - > - > -/** > - Create a socket and its associated protocol control block > - with the intial data SockInitData and protocol specific > - data ProtoData. > - > - @param SockInitData Inital data to setting the socket. > - > - @return Pointer to the newly created socket. If NULL, error condition = occured. > - > -**/ > -SOCKET * > -SockCreateChild ( > - IN SOCK_INIT_DATA *SockInitData > - ) > -{ > - SOCKET *Sock; > - VOID *SockProtocol; > - EFI_STATUS Status; > - > - // > - // create a new socket > - // > - Sock =3D SockCreate (SockInitData); > - if (NULL =3D=3D Sock) { > - > - DEBUG ((EFI_D_ERROR, "SockCreateChild: No resource to " > - "create a new socket\n")); > - > - return NULL; > - } > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockCreateChild: Get the lock to " > - "access socket failed with %r\n", Status)); > - > - goto ERROR; > - } > - // > - // inform the protocol layer to attach the socket > - // with a new protocol control block > - // > - Status =3D Sock->ProtoHandler (Sock, SOCK_ATTACH, NULL); > - EfiReleaseLock (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockCreateChild: Protocol failed to" > - " attach a socket with %r\n", Status)); > - > - goto ERROR; > - } > - > - return Sock; > - > -ERROR: > - > - if (Sock->DestroyCallback !=3D NULL) { > - Sock->DestroyCallback (Sock, Sock->Context); > - } > - > - gBS->OpenProtocol ( > - Sock->SockHandle, > - &gEfiTcp4ProtocolGuid, > - &SockProtocol, > - Sock->DriverBinding, > - Sock->SockHandle, > - EFI_OPEN_PROTOCOL_GET_PROTOCOL > - ); > - // > - // Uninstall the protocol installed on this sock > - // > - gBS->UninstallMultipleProtocolInterfaces ( > - Sock->SockHandle, > - &gEfiTcp4ProtocolGuid, > - SockProtocol, > - NULL > - ); > - SockDestroy (Sock); > - return NULL; > -} > - > - > -/** > - Configure the specific socket Sock using configuration data ConfigData= . > - > - @param Sock Pointer to the socket to be configured. > - @param ConfigData Pointer to the configuration data. > - > - @retval EFI_SUCCESS The socket is configured successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et or > the > - socket is already configured. > - > -**/ > -EFI_STATUS > -SockConfigure ( > - IN SOCKET *Sock, > - IN VOID *ConfigData > - ) > -{ > - EFI_STATUS Status; > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockConfigure: Get the access for " > - "socket failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_CONFIGURED (Sock)) { > - Status =3D EFI_ACCESS_DENIED; > - goto OnExit; > - } > - > - ASSERT (Sock->State =3D=3D SO_CLOSED); > - > - Status =3D Sock->ProtoHandler (Sock, SOCK_CONFIGURE, ConfigData); > - > -OnExit: > - EfiReleaseLock (&(Sock->Lock)); > - > - return Status; > -} > - > - > -/** > - Initiate a connection establishment process. > - > - @param Sock Pointer to the socket to initiate the ini= tate the > - connection. > - @param Token Pointer to the token used for the connect= ion > - operation. > - > - @retval EFI_SUCCESS The connection is initialized successfull= y. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not co= nfigured to > - be an active one, or the token is already= in one of > - this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockConnect ( > - IN SOCKET *Sock, > - IN VOID *Token > - ) > -{ > - EFI_STATUS Status; > - EFI_EVENT Event; > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockConnect: Get the access for " > - "socket failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_NO_MAPPING (Sock)) { > - Status =3D EFI_NO_MAPPING; > - goto OnExit; > - } > - > - if (SOCK_IS_UNCONFIGURED (Sock)) { > - > - Status =3D EFI_NOT_STARTED; > - goto OnExit; > - } > - > - if (!SOCK_IS_CLOSED (Sock) || !SOCK_IS_CONFIGURED_ACTIVE (Sock)) { > - > - Status =3D EFI_ACCESS_DENIED; > - goto OnExit; > - } > - > - Event =3D ((SOCK_COMPLETION_TOKEN *) Token)->Event; > - > - if (SockTokenExisted (Sock, Event)) { > - > - Status =3D EFI_ACCESS_DENIED; > - goto OnExit; > - } > - > - Sock->ConnectionToken =3D (SOCK_COMPLETION_TOKEN *) Token; > - SockSetState (Sock, SO_CONNECTING); > - Status =3D Sock->ProtoHandler (Sock, SOCK_CONNECT, NULL); > - > -OnExit: > - EfiReleaseLock (&(Sock->Lock)); > - return Status; > -} > - > - > -/** > - Issue a listen token to get an existed connected network instance > - or wait for a connection if there is none. > - > - @param Sock Pointer to the socket to accept connectio= ns. > - @param Token The token to accept a connection. > - > - @retval EFI_SUCCESS Either a connection is accpeted or the To= ken is > - buffered for further acception. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not co= nfigured to > - be a passive one, or the token is already= in one of > - this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory > limit. > - > -**/ > -EFI_STATUS > -SockAccept ( > - IN SOCKET *Sock, > - IN VOID *Token > - ) > -{ > - EFI_TCP4_LISTEN_TOKEN *ListenToken; > - LIST_ENTRY *ListEntry; > - EFI_STATUS Status; > - SOCKET *Socket; > - EFI_EVENT Event; > - > - ASSERT (SockStream =3D=3D Sock->Type); > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockAccept: Get the access for socket" > - " failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_NO_MAPPING (Sock)) { > - Status =3D EFI_NO_MAPPING; > - goto Exit; > - } > - > - if (SOCK_IS_UNCONFIGURED (Sock)) { > - > - Status =3D EFI_NOT_STARTED; > - goto Exit; > - } > - > - if (!SOCK_IS_LISTENING (Sock)) { > - > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - Event =3D ((SOCK_COMPLETION_TOKEN *) Token)->Event; > - > - if (SockTokenExisted (Sock, Event)) { > - > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - ListenToken =3D (EFI_TCP4_LISTEN_TOKEN *) Token; > - > - // > - // Check if a connection has already in this Sock->ConnectionList > - // > - NET_LIST_FOR_EACH (ListEntry, &Sock->ConnectionList) { > - > - Socket =3D NET_LIST_USER_STRUCT (ListEntry, SOCKET, ConnectionList); > - > - if (SOCK_IS_CONNECTED (Socket)) { > - ListenToken->NewChildHandle =3D Socket->SockHandle; > - SIGNAL_TOKEN (&(ListenToken->CompletionToken), EFI_SUCCESS); > - > - RemoveEntryList (ListEntry); > - > - ASSERT (Socket->Parent !=3D NULL); > - > - Socket->Parent->ConnCnt--; > - > - DEBUG ( > - (EFI_D_NET, > - "SockAccept: Accept a socket, now conncount is %d", > - Socket->Parent->ConnCnt) > - ); > - Socket->Parent =3D NULL; > - > - goto Exit; > - } > - } > - > - // > - // Buffer this token for latter incoming connection request > - // > - if (NULL =3D=3D SockBufferToken (Sock, &(Sock->ListenTokenList), Token= , 0)) { > - > - Status =3D EFI_OUT_OF_RESOURCES; > - } > - > -Exit: > - EfiReleaseLock (&(Sock->Lock)); > - > - return Status; > -} > - > - > -/** > - Issue a token with data to the socket to send out. > - > - @param Sock Pointer to the socket to process the toke= n with > - data. > - @param Token The token with data that needs to send ou= t. > - > - @retval EFI_SUCCESS The token is processed successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not in= a > - synchronized state , or the token is alre= ady in one > - of this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory > limit. > - > -**/ > -EFI_STATUS > -SockSend ( > - IN SOCKET *Sock, > - IN VOID *Token > - ) > -{ > - SOCK_IO_TOKEN *SndToken; > - EFI_EVENT Event; > - UINT32 FreeSpace; > - EFI_TCP4_TRANSMIT_DATA *TxData; > - EFI_STATUS Status; > - SOCK_TOKEN *SockToken; > - UINT32 DataLen; > - > - ASSERT (SockStream =3D=3D Sock->Type); > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockSend: Get the access for socket" > - " failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_NO_MAPPING (Sock)) { > - Status =3D EFI_NO_MAPPING; > - goto Exit; > - } > - > - SndToken =3D (SOCK_IO_TOKEN *) Token; > - TxData =3D (EFI_TCP4_TRANSMIT_DATA *) SndToken->Packet.TxData; > - > - if (SOCK_IS_UNCONFIGURED (Sock)) { > - Status =3D EFI_NOT_STARTED; > - goto Exit; > - } > - > - if (!(SOCK_IS_CONNECTING (Sock) || SOCK_IS_CONNECTED (Sock))) { > - > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - // > - // check if a token is already in the token buffer > - // > - Event =3D SndToken->Token.Event; > - > - if (SockTokenExisted (Sock, Event)) { > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - DataLen =3D (UINT32) TxData->DataLength; > - > - // > - // process this sending token now or buffer it only? > - // > - FreeSpace =3D SockGetFreeSpace (Sock, SOCK_SND_BUF); > - > - if ((FreeSpace < Sock->SndBuffer.LowWater) || !SOCK_IS_CONNECTED (Sock= )) > { > - > - SockToken =3D SockBufferToken ( > - Sock, > - &Sock->SndTokenList, > - SndToken, > - DataLen > - ); > - > - if (NULL =3D=3D SockToken) { > - Status =3D EFI_OUT_OF_RESOURCES; > - } > - } else { > - > - SockToken =3D SockBufferToken ( > - Sock, > - &Sock->ProcessingSndTokenList, > - SndToken, > - DataLen > - ); > - > - if (NULL =3D=3D SockToken) { > - DEBUG ((EFI_D_ERROR, "SockSend: Failed to buffer IO token into" > - " socket processing SndToken List\n", Status)); > - > - Status =3D EFI_OUT_OF_RESOURCES; > - goto Exit; > - } > - > - Status =3D SockProcessTcpSndData (Sock, TxData); > - > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "SockSend: Failed to process " > - "Snd Data\n", Status)); > - > - RemoveEntryList (&(SockToken->TokenList)); > - FreePool (SockToken); > - } > - } > - > -Exit: > - EfiReleaseLock (&(Sock->Lock)); > - return Status; > -} > - > - > -/** > - Issue a token to get data from the socket. > - > - @param Sock Pointer to the socket to get data from. > - @param Token The token to store the received data from= the > - socket. > - > - @retval EFI_SUCCESS The token is processed successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not in= a > - synchronized state , or the token is alre= ady in one > - of this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - @retval EFI_CONNECTION_FIN The connection is closed and there is no > more data. > - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory > limit. > - > -**/ > -EFI_STATUS > -SockRcv ( > - IN SOCKET *Sock, > - IN VOID *Token > - ) > -{ > - SOCK_IO_TOKEN *RcvToken; > - UINT32 RcvdBytes; > - EFI_STATUS Status; > - EFI_EVENT Event; > - > - ASSERT (SockStream =3D=3D Sock->Type); > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockRcv: Get the access for socket" > - " failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_NO_MAPPING (Sock)) { > - > - Status =3D EFI_NO_MAPPING; > - goto Exit; > - } > - > - if (SOCK_IS_UNCONFIGURED (Sock)) { > - > - Status =3D EFI_NOT_STARTED; > - goto Exit; > - } > - > - if (!(SOCK_IS_CONNECTED (Sock) || SOCK_IS_CONNECTING (Sock))) { > - > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - RcvToken =3D (SOCK_IO_TOKEN *) Token; > - > - // > - // check if a token is already in the token buffer of this socket > - // > - Event =3D RcvToken->Token.Event; > - if (SockTokenExisted (Sock, Event)) { > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - RcvToken =3D (SOCK_IO_TOKEN *) Token; > - RcvdBytes =3D GET_RCV_DATASIZE (Sock); > - > - // > - // check whether an error has happened before > - // > - if (EFI_ABORTED !=3D Sock->SockError) { > - > - SIGNAL_TOKEN (&(RcvToken->Token), Sock->SockError); > - Sock->SockError =3D EFI_ABORTED; > - goto Exit; > - } > - > - // > - // check whether can not receive and there is no any > - // data buffered in Sock->RcvBuffer > - // > - if (SOCK_IS_NO_MORE_DATA (Sock) && (0 =3D=3D RcvdBytes)) { > - > - Status =3D EFI_CONNECTION_FIN; > - goto Exit; > - } > - > - if (RcvdBytes !=3D 0) { > - SockProcessRcvToken (Sock, RcvToken); > - > - Status =3D Sock->ProtoHandler (Sock, SOCK_CONSUMED, NULL); > - } else { > - > - if (NULL =3D=3D SockBufferToken (Sock, &Sock->RcvTokenList, RcvToken= , 0)) { > - Status =3D EFI_OUT_OF_RESOURCES; > - } > - } > - > -Exit: > - EfiReleaseLock (&(Sock->Lock)); > - return Status; > -} > - > - > -/** > - Reset the socket and its associated protocol control block. > - > - @param Sock Pointer to the socket to be flushed. > - > - @retval EFI_SUCCESS The socket is flushed successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et. > - > -**/ > -EFI_STATUS > -SockFlush ( > - IN SOCKET *Sock > - ) > -{ > - EFI_STATUS Status; > - > - ASSERT (SockStream =3D=3D Sock->Type); > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockFlush: Get the access for socket" > - " failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (!SOCK_IS_CONFIGURED (Sock)) { > - goto Exit; > - } > - > - Status =3D Sock->ProtoHandler (Sock, SOCK_FLUSH, NULL); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "SockFlush: Protocol failed handling" > - " SOCK_FLUSH with %r", Status)); > - > - goto Exit; > - } > - > - SOCK_ERROR (Sock, EFI_ABORTED); > - SockConnFlush (Sock); > - SockSetState (Sock, SO_CLOSED); > - > - Sock->ConfigureState =3D SO_UNCONFIGURED; > - > -Exit: > - EfiReleaseLock (&(Sock->Lock)); > - return Status; > -} > - > - > -/** > - Close or abort the socket associated connection. > - > - @param Sock Pointer to the socket of the connection t= o close or > - abort. > - @param Token The token for close operation. > - @param OnAbort TRUE for aborting the connection, FALSE t= o close it. > - > - @retval EFI_SUCCESS The close or abort operation is initializ= ed > - successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not in= a > - synchronized state , or the token is alre= ady in one > - of this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockClose ( > - IN SOCKET *Sock, > - IN VOID *Token, > - IN BOOLEAN OnAbort > - ) > -{ > - EFI_STATUS Status; > - EFI_EVENT Event; > - > - ASSERT (SockStream =3D=3D Sock->Type); > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "SockClose: Get the access for socket" > - " failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_NO_MAPPING (Sock)) { > - Status =3D EFI_NO_MAPPING; > - goto Exit; > - } > - > - if (SOCK_IS_UNCONFIGURED (Sock)) { > - Status =3D EFI_NOT_STARTED; > - goto Exit; > - } > - > - if (SOCK_IS_DISCONNECTING (Sock)) { > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - Event =3D ((SOCK_COMPLETION_TOKEN *) Token)->Event; > - > - if (SockTokenExisted (Sock, Event)) { > - Status =3D EFI_ACCESS_DENIED; > - goto Exit; > - } > - > - Sock->CloseToken =3D Token; > - SockSetState (Sock, SO_DISCONNECTING); > - > - if (OnAbort) { > - Status =3D Sock->ProtoHandler (Sock, SOCK_ABORT, NULL); > - } else { > - Status =3D Sock->ProtoHandler (Sock, SOCK_CLOSE, NULL); > - } > - > -Exit: > - EfiReleaseLock (&(Sock->Lock)); > - return Status; > -} > - > - > -/** > - Get the mode data of the low layer protocol. > - > - @param Sock Pointer to the socket to get mode data fr= om. > - @param Mode Pointer to the data to store the low laye= r mode > - information. > - > - @retval EFI_SUCCESS The mode data is got successfully. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockGetMode ( > - IN SOCKET *Sock, > - IN OUT VOID *Mode > - ) > -{ > - return Sock->ProtoHandler (Sock, SOCK_MODE, Mode); > -} > - > - > - > - > - > -/** > - Add or remove route information in IP route table associated > - with this socket. > - > - @param Sock Pointer to the socket associated with the= IP route > - table to operate on. > - @param RouteInfo Pointer to the route information to be pr= ocessed. > - > - @retval EFI_SUCCESS The route table is updated successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockRoute ( > - IN SOCKET *Sock, > - IN VOID *RouteInfo > - ) > -{ > - EFI_STATUS Status; > - > - Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "SockRoute: Get the access for socket" > - " failed with %r", Status)); > - > - return EFI_ACCESS_DENIED; > - } > - > - if (SOCK_IS_NO_MAPPING (Sock)) { > - Status =3D EFI_NO_MAPPING; > - goto Exit; > - } > - > - if (SOCK_IS_UNCONFIGURED (Sock)) { > - Status =3D EFI_NOT_STARTED; > - goto Exit; > - } > - > - Status =3D Sock->ProtoHandler (Sock, SOCK_ROUTE, RouteInfo); > - > -Exit: > - EfiReleaseLock (&(Sock->Lock)); > - return Status; > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c > deleted file mode 100644 > index a0f97d603171..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c > +++ /dev/null > @@ -1,717 +0,0 @@ > -/** @file > - Tcp request dispatcher implementation. > - > -(C) Copyright 2014 Hewlett-Packard Development Company, L.P.
> -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > -#define TCP_COMP_VAL(Min, Max, Default, Val) \ > - ((((Val) <=3D (Max)) && ((Val) >=3D (Min))) ? (Val) : (Default)) > - > -/** > - Add or remove a route entry in the IP route table associated with this= TCP > instance. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param RouteInfo Pointer to the route info to be processe= d. > - > - @retval EFI_SUCCESS The operation completed successfully. > - @retval EFI_NOT_STARTED The driver instance has not been started= . > - @retval EFI_NO_MAPPING When using the default address, > configuration(DHCP, > - BOOTP, RARP, etc.) is not finished yet. > - @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing > table. > - @retval EFI_NOT_FOUND This route is not in the routing table > - (when RouteInfo->DeleteRoute is TRUE). > - @retval EFI_ACCESS_DENIED The route is already defined in the rout= ing > table > - (when RouteInfo->DeleteRoute is FALSE). > -**/ > -EFI_STATUS > -Tcp4Route ( > - IN TCP_CB *Tcb, > - IN TCP4_ROUTE_INFO *RouteInfo > - ) > -{ > - EFI_IP4_PROTOCOL *Ip4; > - > - Ip4 =3D Tcb->IpInfo->Ip.Ip4; > - > - ASSERT (Ip4 !=3D NULL); > - > - return Ip4->Routes ( > - Ip4, > - RouteInfo->DeleteRoute, > - RouteInfo->SubnetAddress, > - RouteInfo->SubnetMask, > - RouteInfo->GatewayAddress > - ); > - > -} > - > - > -/** > - Get the operational settings of this TCP instance. > - > - @param Tcb Pointer to the TCP_CB of this TCP insta= nce. > - @param Mode Pointer to the buffer to store the oper= ational > - settings. > - > - @retval EFI_SUCCESS The mode data is read. > - @retval EFI_NOT_STARTED No configuration data is available beca= use this > - instance hasn't been started. > - > -**/ > -EFI_STATUS > -Tcp4GetMode ( > - IN TCP_CB *Tcb, > - IN OUT TCP4_MODE_DATA *Mode > - ) > -{ > - SOCKET *Sock; > - EFI_TCP4_CONFIG_DATA *ConfigData; > - EFI_TCP4_ACCESS_POINT *AccessPoint; > - EFI_TCP4_OPTION *Option; > - EFI_IP4_PROTOCOL *Ip; > - > - Sock =3D Tcb->Sk; > - > - if (!SOCK_IS_CONFIGURED (Sock) && (Mode->Tcp4ConfigData !=3D NULL)) { > - return EFI_NOT_STARTED; > - } > - > - if (Mode->Tcp4State !=3D NULL) { > - *(Mode->Tcp4State) =3D (EFI_TCP4_CONNECTION_STATE) Tcb->State; > - } > - > - if (Mode->Tcp4ConfigData !=3D NULL) { > - > - ConfigData =3D Mode->Tcp4ConfigData; > - AccessPoint =3D &(ConfigData->AccessPoint); > - Option =3D ConfigData->ControlOption; > - > - ConfigData->TypeOfService =3D Tcb->Tos; > - ConfigData->TimeToLive =3D Tcb->Ttl; > - > - AccessPoint->UseDefaultAddress =3D Tcb->UseDefaultAddr; > - > - IP4_COPY_ADDRESS (&AccessPoint->StationAddress, &Tcb->LocalEnd.Ip); > - IP4_COPY_ADDRESS (&AccessPoint->SubnetMask, &Tcb->SubnetMask); > - AccessPoint->StationPort =3D NTOHS (Tcb->LocalEnd.Port); > - > - IP4_COPY_ADDRESS (&AccessPoint->RemoteAddress, &Tcb->RemoteEnd.Ip); > - AccessPoint->RemotePort =3D NTOHS (Tcb->RemoteEnd.Port); > - AccessPoint->ActiveFlag =3D (BOOLEAN) (Tcb->State !=3D TCP_L= ISTEN); > - > - if (Option !=3D NULL) { > - Option->ReceiveBufferSize =3D GET_RCV_BUFFSIZE (Tcb->Sk); > - Option->SendBufferSize =3D GET_SND_BUFFSIZE (Tcb->Sk); > - Option->MaxSynBackLog =3D GET_BACKLOG (Tcb->Sk); > - > - Option->ConnectionTimeout =3D Tcb->ConnectTimeout / TCP_TICK= _HZ; > - Option->DataRetries =3D Tcb->MaxRexmit; > - Option->FinTimeout =3D Tcb->FinWait2Timeout / TCP_TIC= K_HZ; > - Option->TimeWaitTimeout =3D Tcb->TimeWaitTimeout / TCP_TIC= K_HZ; > - Option->KeepAliveProbes =3D Tcb->MaxKeepAlive; > - Option->KeepAliveTime =3D Tcb->KeepAliveIdle / TCP_TICK_= HZ; > - Option->KeepAliveInterval =3D Tcb->KeepAlivePeriod / TCP_TIC= K_HZ; > - > - Option->EnableNagle =3D (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlF= lag, > TCP_CTRL_NO_NAGLE)); > - Option->EnableTimeStamp =3D (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlF= lag, > TCP_CTRL_NO_TS)); > - Option->EnableWindowScaling =3D (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlF= lag, > TCP_CTRL_NO_WS)); > - > - Option->EnableSelectiveAck =3D FALSE; > - Option->EnablePathMtuDiscovery =3D FALSE; > - } > - } > - > - Ip =3D Tcb->IpInfo->Ip.Ip4; > - ASSERT (Ip !=3D NULL); > - > - return Ip->GetModeData (Ip, Mode->Ip4ModeData, Mode->MnpConfigData, > Mode->SnpModeData); > -} > - > - > -/** > - If AP->StationPort isn't zero, check whether the access point > - is registered, else generate a random station port for this > - access point. > - > - @param AP Pointer to the access point. > - > - @retval EFI_SUCCESS The check is passed or the port is assi= gned. > - @retval EFI_INVALID_PARAMETER The non-zero station port is already us= ed. > - @retval EFI_OUT_OF_RESOURCES No port can be allocated. > - > -**/ > -EFI_STATUS > -Tcp4Bind ( > - IN EFI_TCP4_ACCESS_POINT *AP > - ) > -{ > - BOOLEAN Cycle; > - > - if (0 !=3D AP->StationPort) { > - // > - // check if a same endpoint is bound > - // > - if (TcpFindTcbByPeer (&AP->StationAddress, AP->StationPort)) { > - > - return EFI_INVALID_PARAMETER; > - } > - } else { > - // > - // generate a random port > - // > - Cycle =3D FALSE; > - > - if (TCP4_PORT_USER_RESERVED =3D=3D mTcp4RandomPort) { > - mTcp4RandomPort =3D TCP4_PORT_KNOWN; > - } > - > - mTcp4RandomPort++; > - > - while (TcpFindTcbByPeer (&AP->StationAddress, mTcp4RandomPort)) { > - > - mTcp4RandomPort++; > - > - if (mTcp4RandomPort <=3D TCP4_PORT_KNOWN) { > - > - if (Cycle) { > - DEBUG ((EFI_D_ERROR, "Tcp4Bind: no port can be allocated " > - "for this pcb\n")); > - > - return EFI_OUT_OF_RESOURCES; > - } > - > - mTcp4RandomPort =3D TCP4_PORT_KNOWN + 1; > - > - Cycle =3D TRUE; > - } > - > - } > - > - AP->StationPort =3D mTcp4RandomPort; > - } > - > - return EFI_SUCCESS; > -} > - > - > -/** > - Flush the Tcb add its associated protocols. > - > - @param Tcb Pointer to the TCP_CB to be flushed. > - > -**/ > -VOID > -Tcp4FlushPcb ( > - IN TCP_CB *Tcb > - ) > -{ > - SOCKET *Sock; > - > - IpIoConfigIp (Tcb->IpInfo, NULL); > - > - Sock =3D Tcb->Sk; > - > - if (SOCK_IS_CONFIGURED (Sock)) { > - RemoveEntryList (&Tcb->List); > - > - // > - // Uninstall the device path protocol. > - // > - if (Sock->DevicePath !=3D NULL) { > - gBS->UninstallProtocolInterface ( > - Sock->SockHandle, > - &gEfiDevicePathProtocolGuid, > - Sock->DevicePath > - ); > - FreePool (Sock->DevicePath); > - } > - } > - > - NetbufFreeList (&Tcb->SndQue); > - NetbufFreeList (&Tcb->RcvQue); > - Tcb->State =3D TCP_CLOSED; > -} > - > -/** > - Attach a Pcb to the socket. > - > - @param Sk Pointer to the socket of this TCP insta= nce. > - > - @retval EFI_SUCCESS The operation is completed successfully= . > - @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. > - > -**/ > -EFI_STATUS > -Tcp4AttachPcb ( > - IN SOCKET *Sk > - ) > -{ > - TCP_CB *Tcb; > - TCP4_PROTO_DATA *ProtoData; > - IP_IO *IpIo; > - EFI_STATUS Status; > - VOID *Ip; > - > - Tcb =3D AllocateZeroPool (sizeof (TCP_CB)); > - > - if (Tcb =3D=3D NULL) { > - > - DEBUG ((EFI_D_ERROR, "Tcp4ConfigurePcb: failed to allocate a TCB\n")= ); > - > - return EFI_OUT_OF_RESOURCES; > - } > - > - ProtoData =3D (TCP4_PROTO_DATA *) Sk->ProtoReserved; > - IpIo =3D ProtoData->TcpService->IpIo; > - > - // > - // Create an IpInfo for this Tcb. > - // > - Tcb->IpInfo =3D IpIoAddIp (IpIo); > - if (Tcb->IpInfo =3D=3D NULL) { > - > - FreePool (Tcb); > - return EFI_OUT_OF_RESOURCES; > - } > - > - // > - // Open the new created IP instance BY_CHILD. > - // > - Status =3D gBS->OpenProtocol ( > - Tcb->IpInfo->ChildHandle, > - &gEfiIp4ProtocolGuid, > - &Ip, > - IpIo->Image, > - Sk->SockHandle, > - EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER > - ); > - if (EFI_ERROR (Status)) { > - IpIoRemoveIp (IpIo, Tcb->IpInfo); > - return Status; > - } > - > - InitializeListHead (&Tcb->List); > - InitializeListHead (&Tcb->SndQue); > - InitializeListHead (&Tcb->RcvQue); > - > - Tcb->State =3D TCP_CLOSED; > - Tcb->Sk =3D Sk; > - ProtoData->TcpPcb =3D Tcb; > - > - return EFI_SUCCESS; > -} > - > -/** > - Detach the Pcb of the socket. > - > - @param Sk Pointer to the socket of this TCP insta= nce. > - > -**/ > -VOID > -Tcp4DetachPcb ( > - IN SOCKET *Sk > - ) > -{ > - TCP4_PROTO_DATA *ProtoData; > - TCP_CB *Tcb; > - > - ProtoData =3D (TCP4_PROTO_DATA *) Sk->ProtoReserved; > - Tcb =3D ProtoData->TcpPcb; > - > - ASSERT (Tcb !=3D NULL); > - > - Tcp4FlushPcb (Tcb); > - > - IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo); > - > - FreePool (Tcb); > - > - ProtoData->TcpPcb =3D NULL; > -} > - > - > -/** > - Configure the Pcb using CfgData. > - > - @param Sk Pointer to the socket of this TCP insta= nce. > - @param CfgData Pointer to the TCP configuration data. > - > - @retval EFI_SUCCESS The operation is completed successfully= . > - @retval EFI_INVALID_PARAMETER A same access point has been configured > in > - another TCP instance. > - @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. > - > -**/ > -EFI_STATUS > -Tcp4ConfigurePcb ( > - IN SOCKET *Sk, > - IN EFI_TCP4_CONFIG_DATA *CfgData > - ) > -{ > - EFI_IP4_CONFIG_DATA IpCfgData; > - EFI_STATUS Status; > - EFI_TCP4_OPTION *Option; > - TCP4_PROTO_DATA *TcpProto; > - TCP_CB *Tcb; > - > - ASSERT ((CfgData !=3D NULL) && (Sk !=3D NULL) && (Sk->SockHandle !=3D = NULL)); > - > - TcpProto =3D (TCP4_PROTO_DATA *) Sk->ProtoReserved; > - Tcb =3D TcpProto->TcpPcb; > - > - ASSERT (Tcb !=3D NULL); > - > - // > - // Add Ip for send pkt to the peer > - // > - CopyMem (&IpCfgData, &mIp4IoDefaultIpConfigData, sizeof (IpCfgData)); > - IpCfgData.DefaultProtocol =3D EFI_IP_PROTO_TCP; > - IpCfgData.UseDefaultAddress =3D CfgData->AccessPoint.UseDefaultAddress= ; > - IpCfgData.StationAddress =3D CfgData->AccessPoint.StationAddress; > - IpCfgData.SubnetMask =3D CfgData->AccessPoint.SubnetMask; > - IpCfgData.ReceiveTimeout =3D (UINT32) (-1); > - > - // > - // Configure the IP instance this Tcb consumes. > - // > - Status =3D IpIoConfigIp (Tcb->IpInfo, &IpCfgData); > - if (EFI_ERROR (Status)) { > - goto OnExit; > - } > - > - // > - // Get the default address info if the instance is configured to use d= efault > address. > - // > - if (CfgData->AccessPoint.UseDefaultAddress) { > - CfgData->AccessPoint.StationAddress =3D IpCfgData.StationAddress; > - CfgData->AccessPoint.SubnetMask =3D IpCfgData.SubnetMask; > - } > - > - // > - // check if we can bind this endpoint in CfgData > - // > - Status =3D Tcp4Bind (&(CfgData->AccessPoint)); > - > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "Tcp4ConfigurePcb: Bind endpoint failed " > - "with %r\n", Status)); > - > - goto OnExit; > - } > - > - // > - // Initalize the operating information in this Tcb > - // > - ASSERT (Tcb->State =3D=3D TCP_CLOSED && > - IsListEmpty (&Tcb->SndQue) && > - IsListEmpty (&Tcb->RcvQue)); > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE); > - Tcb->State =3D TCP_CLOSED; > - > - Tcb->SndMss =3D 536; > - Tcb->RcvMss =3D TcpGetRcvMss (Sk); > - > - Tcb->SRtt =3D 0; > - Tcb->Rto =3D 3 * TCP_TICK_HZ; > - > - Tcb->CWnd =3D Tcb->SndMss; > - Tcb->Ssthresh =3D 0xffffffff; > - > - Tcb->CongestState =3D TCP_CONGEST_OPEN; > - > - Tcb->KeepAliveIdle =3D TCP_KEEPALIVE_IDLE_MIN; > - Tcb->KeepAlivePeriod =3D TCP_KEEPALIVE_PERIOD; > - Tcb->MaxKeepAlive =3D TCP_MAX_KEEPALIVE; > - Tcb->MaxRexmit =3D TCP_MAX_LOSS; > - Tcb->FinWait2Timeout =3D TCP_FIN_WAIT2_TIME; > - Tcb->TimeWaitTimeout =3D TCP_TIME_WAIT_TIME; > - Tcb->ConnectTimeout =3D TCP_CONNECT_TIME; > - > - // > - // initialize Tcb in the light of CfgData > - // > - Tcb->Ttl =3D CfgData->TimeToLive; > - Tcb->Tos =3D CfgData->TypeOfService; > - > - Tcb->UseDefaultAddr =3D CfgData->AccessPoint.UseDefaultAddress; > - > - CopyMem (&Tcb->LocalEnd.Ip, &CfgData->AccessPoint.StationAddress, size= of > (IP4_ADDR)); > - Tcb->LocalEnd.Port =3D HTONS (CfgData->AccessPoint.StationPort); > - IP4_COPY_ADDRESS (&Tcb->SubnetMask, &CfgData- > >AccessPoint.SubnetMask); > - > - if (CfgData->AccessPoint.ActiveFlag) { > - CopyMem (&Tcb->RemoteEnd.Ip, &CfgData->AccessPoint.RemoteAddress, > sizeof (IP4_ADDR)); > - Tcb->RemoteEnd.Port =3D HTONS (CfgData->AccessPoint.RemotePort); > - } else { > - Tcb->RemoteEnd.Ip =3D 0; > - Tcb->RemoteEnd.Port =3D 0; > - } > - > - Option =3D CfgData->ControlOption; > - > - if (Option !=3D NULL) { > - SET_RCV_BUFFSIZE ( > - Sk, > - (UINT32) (TCP_COMP_VAL ( > - TCP_RCV_BUF_SIZE_MIN, > - TCP_RCV_BUF_SIZE, > - TCP_RCV_BUF_SIZE, > - Option->ReceiveBufferSize > - ) > - ) > - ); > - SET_SND_BUFFSIZE ( > - Sk, > - (UINT32) (TCP_COMP_VAL ( > - TCP_SND_BUF_SIZE_MIN, > - TCP_SND_BUF_SIZE, > - TCP_SND_BUF_SIZE, > - Option->SendBufferSize > - ) > - ) > - ); > - > - SET_BACKLOG ( > - Sk, > - (UINT32) (TCP_COMP_VAL ( > - TCP_BACKLOG_MIN, > - TCP_BACKLOG, > - TCP_BACKLOG, > - Option->MaxSynBackLog > - ) > - ) > - ); > - > - Tcb->MaxRexmit =3D (UINT16) TCP_COMP_VAL ( > - TCP_MAX_LOSS_MIN, > - TCP_MAX_LOSS, > - TCP_MAX_LOSS, > - Option->DataRetries > - ); > - Tcb->FinWait2Timeout =3D TCP_COMP_VAL ( > - TCP_FIN_WAIT2_TIME, > - TCP_FIN_WAIT2_TIME_MAX, > - TCP_FIN_WAIT2_TIME, > - (UINT32) (Option->FinTimeout * TCP_TICK_HZ= ) > - ); > - > - if (Option->TimeWaitTimeout !=3D 0) { > - Tcb->TimeWaitTimeout =3D TCP_COMP_VAL ( > - TCP_TIME_WAIT_TIME, > - TCP_TIME_WAIT_TIME_MAX, > - TCP_TIME_WAIT_TIME, > - (UINT32) (Option->TimeWaitTimeout * TCP_T= ICK_HZ) > - ); > - } else { > - Tcb->TimeWaitTimeout =3D 0; > - } > - > - if (Option->KeepAliveProbes !=3D 0) { > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE); > - > - Tcb->MaxKeepAlive =3D (UINT8) TCP_COMP_VAL ( > - TCP_MAX_KEEPALIVE_MIN, > - TCP_MAX_KEEPALIVE, > - TCP_MAX_KEEPALIVE, > - Option->KeepAliveProbes > - ); > - Tcb->KeepAliveIdle =3D TCP_COMP_VAL ( > - TCP_KEEPALIVE_IDLE_MIN, > - TCP_KEEPALIVE_IDLE_MAX, > - TCP_KEEPALIVE_IDLE_MIN, > - (UINT32) (Option->KeepAliveTime * TCP_TICK_= HZ) > - ); > - Tcb->KeepAlivePeriod =3D TCP_COMP_VAL ( > - TCP_KEEPALIVE_PERIOD_MIN, > - TCP_KEEPALIVE_PERIOD, > - TCP_KEEPALIVE_PERIOD, > - (UINT32) (Option->KeepAliveInterval * TCP= _TICK_HZ) > - ); > - } > - > - Tcb->ConnectTimeout =3D TCP_COMP_VAL ( > - TCP_CONNECT_TIME_MIN, > - TCP_CONNECT_TIME, > - TCP_CONNECT_TIME, > - (UINT32) (Option->ConnectionTimeout * TCP_TI= CK_HZ) > - ); > - > - if (!Option->EnableNagle) { > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_NAGLE); > - } > - > - if (!Option->EnableTimeStamp) { > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_TS); > - } > - > - if (!Option->EnableWindowScaling) { > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_WS); > - } > - } > - > - // > - // The socket is bound, the is > - // determined, construct the IP device path and install it. > - // > - Status =3D TcpInstallDevicePath (Sk); > - if (EFI_ERROR (Status)) { > - goto OnExit; > - } > - > - // > - // update state of Tcb and socket > - // > - if (!CfgData->AccessPoint.ActiveFlag) { > - > - TcpSetState (Tcb, TCP_LISTEN); > - SockSetState (Sk, SO_LISTENING); > - > - Sk->ConfigureState =3D SO_CONFIGURED_PASSIVE; > - } else { > - > - Sk->ConfigureState =3D SO_CONFIGURED_ACTIVE; > - } > - > - TcpInsertTcb (Tcb); > - > -OnExit: > - > - return Status; > -} > - > - > -/** > - The procotol handler provided to the socket layer, used to > - dispatch the socket level requests by calling the corresponding > - TCP layer functions. > - > - @param Sock Pointer to the socket of this TCP insta= nce. > - @param Request The code of this operation request. > - @param Data Pointer to the operation specific data = passed in > - together with the operation request. > - > - @retval EFI_SUCCESS The socket request is completed success= fully. > - @retval other The error status returned by the corres= ponding TCP > - layer function. > - > -**/ > -EFI_STATUS > -Tcp4Dispatcher ( > - IN SOCKET *Sock, > - IN UINT8 Request, > - IN VOID *Data OPTIONAL > - ) > -{ > - TCP_CB *Tcb; > - TCP4_PROTO_DATA *ProtoData; > - EFI_IP4_PROTOCOL *Ip; > - > - ProtoData =3D (TCP4_PROTO_DATA *) Sock->ProtoReserved; > - Tcb =3D ProtoData->TcpPcb; > - > - switch (Request) { > - case SOCK_POLL: > - Ip =3D ProtoData->TcpService->IpIo->Ip.Ip4; > - Ip->Poll (Ip); > - break; > - > - case SOCK_CONSUMED: > - // > - // After user received data from socket buffer, socket will > - // notify TCP using this message to give it a chance to send out > - // window update information > - // > - ASSERT (Tcb !=3D NULL); > - TcpOnAppConsume (Tcb); > - break; > - > - case SOCK_SND: > - > - ASSERT (Tcb !=3D NULL); > - TcpOnAppSend (Tcb); > - break; > - > - case SOCK_CLOSE: > - > - TcpOnAppClose (Tcb); > - > - break; > - > - case SOCK_ABORT: > - > - TcpOnAppAbort (Tcb); > - > - break; > - > - case SOCK_SNDPUSH: > - Tcb->SndPsh =3D TcpGetMaxSndNxt (Tcb) + GET_SND_DATASIZE (Tcb->Sk); > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_PSH); > - > - break; > - > - case SOCK_SNDURG: > - Tcb->SndUp =3D TcpGetMaxSndNxt (Tcb) + GET_SND_DATASIZE (Tcb->Sk) - = 1; > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_URG); > - > - break; > - > - case SOCK_CONNECT: > - > - TcpOnAppConnect (Tcb); > - > - break; > - > - case SOCK_ATTACH: > - > - return Tcp4AttachPcb (Sock); > - > - case SOCK_FLUSH: > - > - Tcp4FlushPcb (Tcb); > - > - break; > - > - case SOCK_DETACH: > - > - Tcp4DetachPcb (Sock); > - > - break; > - > - case SOCK_CONFIGURE: > - > - return Tcp4ConfigurePcb ( > - Sock, > - (EFI_TCP4_CONFIG_DATA *) Data > - ); > - > - case SOCK_MODE: > - > - ASSERT ((Data !=3D NULL) && (Tcb !=3D NULL)); > - > - return Tcp4GetMode (Tcb, (TCP4_MODE_DATA *) Data); > - > - case SOCK_ROUTE: > - > - ASSERT ((Data !=3D NULL) && (Tcb !=3D NULL)); > - > - return Tcp4Route (Tcb, (TCP4_ROUTE_INFO *) Data); > - > - default: > - return EFI_UNSUPPORTED; > - } > - > - return EFI_SUCCESS; > - > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c > deleted file mode 100644 > index 2ff8eee8693b..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c > +++ /dev/null > @@ -1,782 +0,0 @@ > -/** @file > - Tcp driver function. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > - > -UINT16 mTcp4RandomPort; > -extern EFI_COMPONENT_NAME_PROTOCOL gTcp4ComponentName; > -extern EFI_COMPONENT_NAME2_PROTOCOL gTcp4ComponentName2; > -extern EFI_UNICODE_STRING_TABLE *gTcpControllerNameTable; > - > -TCP4_HEARTBEAT_TIMER mTcp4Timer =3D { > - NULL, > - 0 > -}; > - > -EFI_TCP4_PROTOCOL mTcp4ProtocolTemplate =3D { > - Tcp4GetModeData, > - Tcp4Configure, > - Tcp4Routes, > - Tcp4Connect, > - Tcp4Accept, > - Tcp4Transmit, > - Tcp4Receive, > - Tcp4Close, > - Tcp4Cancel, > - Tcp4Poll > -}; > - > -SOCK_INIT_DATA mTcp4DefaultSockData =3D { > - SockStream, > - 0, > - NULL, > - TCP_BACKLOG, > - TCP_SND_BUF_SIZE, > - TCP_RCV_BUF_SIZE, > - &mTcp4ProtocolTemplate, > - Tcp4CreateSocketCallback, > - Tcp4DestroySocketCallback, > - NULL, > - NULL, > - 0, > - Tcp4Dispatcher, > - NULL, > -}; > - > -EFI_DRIVER_BINDING_PROTOCOL mTcp4DriverBinding =3D { > - Tcp4DriverBindingSupported, > - Tcp4DriverBindingStart, > - Tcp4DriverBindingStop, > - 0xa, > - NULL, > - NULL > -}; > - > -EFI_SERVICE_BINDING_PROTOCOL mTcp4ServiceBinding =3D { > - Tcp4ServiceBindingCreateChild, > - Tcp4ServiceBindingDestroyChild > -}; > - > - > -/** > - Create and start the heartbeat timer for TCP driver. > - > - @retval EFI_SUCCESS The timer is successfully created and s= tarted. > - @retval other The timer is not created. > - > -**/ > -EFI_STATUS > -Tcp4CreateTimer ( > - VOID > - ) > -{ > - EFI_STATUS Status; > - > - Status =3D EFI_SUCCESS; > - > - if (mTcp4Timer.RefCnt =3D=3D 0) { > - > - Status =3D gBS->CreateEvent ( > - EVT_TIMER | EVT_NOTIFY_SIGNAL, > - TPL_NOTIFY, > - TcpTicking, > - NULL, > - &mTcp4Timer.TimerEvent > - ); > - if (!EFI_ERROR (Status)) { > - > - Status =3D gBS->SetTimer ( > - mTcp4Timer.TimerEvent, > - TimerPeriodic, > - (UINT64) (TICKS_PER_SECOND / TCP_TICK_HZ) > - ); > - } > - } > - > - if (!EFI_ERROR (Status)) { > - > - mTcp4Timer.RefCnt++; > - } > - > - return Status; > -} > - > - > -/** > - Stop and destroy the heartbeat timer for TCP driver. > - > -**/ > -VOID > -Tcp4DestroyTimer ( > - VOID > - ) > -{ > - ASSERT (mTcp4Timer.RefCnt > 0); > - > - mTcp4Timer.RefCnt--; > - > - if (mTcp4Timer.RefCnt > 0) { > - return; > - } > - > - gBS->SetTimer (mTcp4Timer.TimerEvent, TimerCancel, 0); > - gBS->CloseEvent (mTcp4Timer.TimerEvent); > - mTcp4Timer.TimerEvent =3D NULL; > -} > - > -/** > - Callback function which provided by user to remove one node in > NetDestroyLinkList process. > - > - @param[in] Entry The entry to be removed. > - @param[in] Context Pointer to the callback context correspo= nds to the > Context in NetDestroyLinkList. > - > - @retval EFI_SUCCESS The entry has been removed successfully. > - @retval Others Fail to remove the entry. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DestroyChildEntryInHandleBuffer ( > - IN LIST_ENTRY *Entry, > - IN VOID *Context > - ) > -{ > - SOCKET *Sock; > - EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; > - UINTN NumberOfChildren; > - EFI_HANDLE *ChildHandleBuffer; > - > - if (Entry =3D=3D NULL || Context =3D=3D NULL) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D NET_LIST_USER_STRUCT_S (Entry, SOCKET, Link, SOCK_SIGNATURE); > - ServiceBinding =3D ((TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) > Context)->ServiceBinding; > - NumberOfChildren =3D ((TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) > Context)->NumberOfChildren; > - ChildHandleBuffer =3D ((TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) > Context)->ChildHandleBuffer; > - > - if (!NetIsInHandleBuffer (Sock->SockHandle, NumberOfChildren, > ChildHandleBuffer)) { > - return EFI_SUCCESS; > - } > - > - return ServiceBinding->DestroyChild (ServiceBinding, Sock->SockHandle)= ; > -} > - > -/** > - The entry point for Tcp4 driver, used to install Tcp4 driver on the Im= ageHandle. > - > - @param ImageHandle The firmware allocated handle for this > - driver image. > - @param SystemTable Pointer to the EFI system table. > - > - @retval EFI_SUCCESS Driver loaded. > - @retval other Driver not loaded. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverEntryPoint ( > - IN EFI_HANDLE ImageHandle, > - IN EFI_SYSTEM_TABLE *SystemTable > - ) > -{ > - EFI_STATUS Status; > - UINT32 Seed; > - > - // > - // Install the TCP4 Driver Binding Protocol > - // > - Status =3D EfiLibInstallDriverBindingComponentName2 ( > - ImageHandle, > - SystemTable, > - &mTcp4DriverBinding, > - ImageHandle, > - &gTcp4ComponentName, > - &gTcp4ComponentName2 > - ); > - ASSERT_EFI_ERROR (Status); > - // > - // Initialize ISS and random port. > - // > - Seed =3D NetRandomInitSeed (); > - mTcpGlobalIss =3D NET_RANDOM (Seed) % mTcpGlobalIss; > - mTcp4RandomPort =3D (UINT16) (TCP4_PORT_KNOWN + > - (UINT16) (NET_RANDOM(Seed) % TCP4_PORT_KNOWN)); > - > - return Status; > -} > - > - > -/** > - Tests to see if this driver supports a given controller. > - > - If a child device is provided, it further tests to see if this driver = supports > - creating a handle for the specified child device. > - > - @param This A pointer to the EFI_DRIVER_BINDING_PROTO= COL > instance. > - @param ControllerHandle The handle of the controller to test. Thi= s handle > - must support a protocol interface that su= pplies > - an I/O abstraction to the driver. > - @param RemainingDevicePath A pointer to the remaining portion of a d= evice > path. > - This parameter is ignored by device drive= rs, and is optional for > bus drivers. > - > - > - @retval EFI_SUCCESS The device specified by ControllerHandle = and > - RemainingDevicePath is supported by the d= river > - specified by This. > - @retval EFI_ALREADY_STARTED The device specified by ControllerHandle = and > - RemainingDevicePath is already being mana= ged by > - the driver specified by This. > - @retval EFI_ACCESS_DENIED The device specified by ControllerHandle = and > - RemainingDevicePath is already being mana= ged by a > - different driver or an application that r= equires > - exclusive access. > - @retval EFI_UNSUPPORTED The device specified by ControllerHandle = and > - RemainingDevicePath is not supported by t= he driver > - specified by This. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverBindingSupported ( > - IN EFI_DRIVER_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL > - ) > -{ > - EFI_STATUS Status; > - > - // > - // Test for the Tcp4ServiceBinding Protocol > - // > - Status =3D gBS->OpenProtocol ( > - ControllerHandle, > - &gEfiTcp4ServiceBindingProtocolGuid, > - NULL, > - This->DriverBindingHandle, > - ControllerHandle, > - EFI_OPEN_PROTOCOL_TEST_PROTOCOL > - ); > - if (!EFI_ERROR (Status)) { > - return EFI_ALREADY_STARTED; > - } > - > - // > - // Test for the Ip4 Protocol > - // > - Status =3D gBS->OpenProtocol ( > - ControllerHandle, > - &gEfiIp4ServiceBindingProtocolGuid, > - NULL, > - This->DriverBindingHandle, > - ControllerHandle, > - EFI_OPEN_PROTOCOL_TEST_PROTOCOL > - ); > - > - return Status; > -} > - > - > -/** > - Start this driver on ControllerHandle. > - > - The Start() function is designed to be invoked from the EFI boot servi= ce > - ConnectController(). As a result, much of the error checking on the pa= rameters > - to Start() has been moved into this common boot service. It is legal t= o call > - Start() from other locations, but the following calling restrictions m= ust be > - followed or the system behavior will not be deterministic. > - 1. ControllerHandle must be a valid EFI_HANDLE. > - 2. If RemainingDevicePath is not NULL, then it must be a pointer to a = naturally > - aligned EFI_DEVICE_PATH_PROTOCOL. > - 3. Prior to calling Start(), the Supported() function for the driver s= pecified > - by This must have been called with the same calling parameters, and > Supported() > - must have returned EFI_SUCCESS. > - > - @param This A pointer to the EFI_DRIVER_BINDING_PROTO= COL > instance. > - @param ControllerHandle The handle of the controller to start. Th= is handle > - must support a protocol interface that su= pplies > - an I/O abstraction to the driver. > - @param RemainingDevicePath A pointer to the remaining portion of a d= evice > path. > - This parameter is ignored by device drive= rs, and is > - optional for bus drivers. > - > - @retval EFI_SUCCESS The device was started. > - @retval EFI_ALREADY_STARTED The device could not be started due to a > device error. > - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to > a lack > - of resources. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverBindingStart ( > - IN EFI_DRIVER_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL > - ) > -{ > - EFI_STATUS Status; > - TCP4_SERVICE_DATA *TcpServiceData; > - IP_IO_OPEN_DATA OpenData; > - > - TcpServiceData =3D AllocateZeroPool (sizeof (TCP4_SERVICE_DATA)); > - > - if (NULL =3D=3D TcpServiceData) { > - DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough" > - " resource to create a Tcp Servcie Data\n")); > - > - return EFI_OUT_OF_RESOURCES; > - } > - > - // > - // Create a new IP IO to Consume it > - // > - TcpServiceData->IpIo =3D IpIoCreate ( > - This->DriverBindingHandle, > - ControllerHandle, > - IP_VERSION_4 > - ); > - if (NULL =3D=3D TcpServiceData->IpIo) { > - > - DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough" > - " resource to create an Ip Io\n")); > - > - Status =3D EFI_OUT_OF_RESOURCES; > - goto ON_ERROR; > - } > - > - // > - // Configure and start IpIo. > - // > - ZeroMem (&OpenData, sizeof (IP_IO_OPEN_DATA)); > - > - CopyMem ( > - &OpenData.IpConfigData.Ip4CfgData, > - &mIp4IoDefaultIpConfigData, > - sizeof (EFI_IP4_CONFIG_DATA) > - ); > - > - OpenData.IpConfigData.Ip4CfgData.DefaultProtocol =3D EFI_IP_PROTO_TCP; > - > - OpenData.PktRcvdNotify =3D Tcp4RxCallback; > - Status =3D IpIoOpen (TcpServiceData->IpIo, &OpenData); > - > - if (EFI_ERROR (Status)) { > - goto ON_ERROR; > - } > - > - // > - // Create the timer event used by TCP driver > - // > - Status =3D Tcp4CreateTimer (); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Create TcpTimer" > - " Event failed with %r\n", Status)); > - > - goto ON_ERROR; > - } > - > - // > - // Install the Tcp4ServiceBinding Protocol on the > - // controller handle > - // > - TcpServiceData->Tcp4ServiceBinding =3D mTcp4ServiceBinding; > - > - Status =3D gBS->InstallMultipleProtocolInterfaces ( > - &ControllerHandle, > - &gEfiTcp4ServiceBindingProtocolGuid, > - &TcpServiceData->Tcp4ServiceBinding, > - NULL > - ); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Install Tcp4 Service B= inding" > - " Protocol failed for %r\n", Status)); > - > - Tcp4DestroyTimer (); > - goto ON_ERROR; > - } > - > - // > - // Initialize member in TcpServiceData > - // > - TcpServiceData->ControllerHandle =3D ControllerHandle; > - TcpServiceData->Signature =3D TCP4_DRIVER_SIGNATURE; > - TcpServiceData->DriverBindingHandle =3D This->DriverBindingHandle; > - > - InitializeListHead (&TcpServiceData->SocketList); > - > - return EFI_SUCCESS; > - > -ON_ERROR: > - > - if (TcpServiceData->IpIo !=3D NULL) { > - IpIoDestroy (TcpServiceData->IpIo); > - TcpServiceData->IpIo =3D NULL; > - } > - > - FreePool (TcpServiceData); > - > - return Status; > -} > - > - > -/** > - Stop this driver on ControllerHandle. > - > - The Stop() function is designed to be invoked from the EFI boot servic= e > - DisconnectController(). As a result, much of the error checking on the > parameters > - to Stop() has been moved into this common boot service. It is legal to= call > Stop() > - from other locations, but the following calling restrictions must be f= ollowed > - or the system behavior will not be deterministic. > - 1. ControllerHandle must be a valid EFI_HANDLE that was used on a prev= ious > call > - to this same driver's Start() function. > - 2. The first NumberOfChildren handles of ChildHandleBuffer must all be= a valid > - EFI_HANDLE. In addition, all of these handles must have been create= d in this > - driver's Start() function, and the Start() function must have calle= d > OpenProtocol() > - on ControllerHandle with an Attribute of > EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. > - > - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL > instance. > - @param ControllerHandle A handle to the device being stopped. The ha= ndle > must > - support a bus specific I/O protocol for the = driver > - to use to stop the device. > - @param NumberOfChildren The number of child device handles in > ChildHandleBuffer. > - @param ChildHandleBuffer An array of child handles to be freed. May b= e > NULL if > - NumberOfChildren is 0. > - > - @retval EFI_SUCCESS The device was stopped. > - @retval EFI_DEVICE_ERROR The device could not be stopped due to a dev= ice > error. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverBindingStop ( > - IN EFI_DRIVER_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN UINTN NumberOfChildren, > - IN EFI_HANDLE *ChildHandleBuffer > - ) > -{ > - EFI_STATUS Status; > - EFI_HANDLE NicHandle; > - EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; > - TCP4_SERVICE_DATA *TcpServiceData; > - LIST_ENTRY *List; > - TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context; > - > - // Find the NicHandle where Tcp4 ServiceBinding Protocol is installed. > - // > - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGu= id); > - if (NicHandle =3D=3D NULL) { > - return EFI_SUCCESS; > - } > - > - // > - // Retrieve the TCP driver Data Structure > - // > - Status =3D gBS->OpenProtocol ( > - NicHandle, > - &gEfiTcp4ServiceBindingProtocolGuid, > - (VOID **) &ServiceBinding, > - This->DriverBindingHandle, > - ControllerHandle, > - EFI_OPEN_PROTOCOL_GET_PROTOCOL > - ); > - if (EFI_ERROR (Status)) { > - > - DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStop: Locate Tcp4 Service " > - " Binding Protocol failed with %r\n", Status)); > - > - return EFI_DEVICE_ERROR; > - } > - > - TcpServiceData =3D TCP4_FROM_THIS (ServiceBinding); > - > - if (NumberOfChildren !=3D 0) { > - List =3D &TcpServiceData->SocketList; > - Context.ServiceBinding =3D ServiceBinding; > - Context.NumberOfChildren =3D NumberOfChildren; > - Context.ChildHandleBuffer =3D ChildHandleBuffer; > - Status =3D NetDestroyLinkList ( > - List, > - Tcp4DestroyChildEntryInHandleBuffer, > - &Context, > - NULL > - ); > - } else if (IsListEmpty (&TcpServiceData->SocketList)) { > - // > - // Uninstall TCP servicebinding protocol > - // > - gBS->UninstallMultipleProtocolInterfaces ( > - NicHandle, > - &gEfiTcp4ServiceBindingProtocolGuid, > - ServiceBinding, > - NULL > - ); > - > - // > - // Destroy the IpIO consumed by TCP driver > - // > - IpIoDestroy (TcpServiceData->IpIo); > - TcpServiceData->IpIo =3D NULL; > - > - // > - // Destroy the heartbeat timer. > - // > - Tcp4DestroyTimer (); > - > - if (gTcpControllerNameTable !=3D NULL) { > - FreeUnicodeStringTable (gTcpControllerNameTable); > - gTcpControllerNameTable =3D NULL; > - } > - > - // > - // Release the TCP service data > - // > - FreePool (TcpServiceData); > - > - Status =3D EFI_SUCCESS; > - } > - > - return Status; > -} > - > -/** > - Open Ip4 and device path protocols for a created socket, and insert it= in > - socket list. > - > - @param This Pointer to the socket just created > - @param Context Context of the socket > - > - @retval EFI_SUCCESS This protocol is installed successfully. > - @retval other Some error occured. > - > -**/ > -EFI_STATUS > -Tcp4CreateSocketCallback ( > - IN SOCKET *This, > - IN VOID *Context > - ) > -{ > - EFI_STATUS Status; > - TCP4_SERVICE_DATA *TcpServiceData; > - EFI_IP4_PROTOCOL *Ip4; > - > - TcpServiceData =3D ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpServi= ce; > - > - // > - // Open the default Ip4 protocol of IP_IO BY_DRIVER. > - // > - Status =3D gBS->OpenProtocol ( > - TcpServiceData->IpIo->ChildHandle, > - &gEfiIp4ProtocolGuid, > - (VOID **) &Ip4, > - TcpServiceData->DriverBindingHandle, > - This->SockHandle, > - EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER > - ); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - // > - // Open the device path on the handle where service binding resides on= . > - // > - Status =3D gBS->OpenProtocol ( > - TcpServiceData->ControllerHandle, > - &gEfiDevicePathProtocolGuid, > - (VOID **) &This->ParentDevicePath, > - TcpServiceData->DriverBindingHandle, > - This->SockHandle, > - EFI_OPEN_PROTOCOL_GET_PROTOCOL > - ); > - if (EFI_ERROR (Status)) { > - gBS->CloseProtocol ( > - TcpServiceData->IpIo->ChildHandle, > - &gEfiIp4ProtocolGuid, > - TcpServiceData->DriverBindingHandle, > - This->SockHandle > - ); > - } else { > - // > - // Insert this socket into the SocketList. > - // > - InsertTailList (&TcpServiceData->SocketList, &This->Link); > - } > - > - return Status; > -} > - > -/** > - Close Ip4 and device path protocols for a socket, and remove it from s= ocket > list. > - > - @param This Pointer to the socket to be removed > - @param Context Context of the socket > - > -**/ > -VOID > -Tcp4DestroySocketCallback ( > - IN SOCKET *This, > - IN VOID *Context > - ) > -{ > - TCP4_SERVICE_DATA *TcpServiceData; > - > - TcpServiceData =3D ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpServi= ce; > - > - // > - // Remove this node from the list. > - // > - RemoveEntryList (&This->Link); > - > - // > - // Close the Ip4 protocol. > - // > - gBS->CloseProtocol ( > - TcpServiceData->IpIo->ChildHandle, > - &gEfiIp4ProtocolGuid, > - TcpServiceData->DriverBindingHandle, > - This->SockHandle > - ); > -} > - > -/** > - Creates a child handle and installs a protocol. > - > - The CreateChild() function installs a protocol on ChildHandle. If Chil= dHandle > - is a pointer to NULL, then a new handle is created and returned in Chi= ldHandle. > - If ChildHandle is not a pointer to NULL, then the protocol installs on= the > existing > - ChildHandle. > - > - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instan= ce. > - @param ChildHandle Pointer to the handle of the child to create. If i= t is NULL, > then > - a new handle is created. If it is a pointer to an = existing UEFI > - handle, then the protocol is added to the existing= UEFI handle. > - > - @retval EFI_SUCCES The protocol was added to ChildHandle. > - @retval EFI_INVALID_PARAMETER ChildHandle is NULL. > - @retval EFI_OUT_OF_RESOURCES There are not enough resources available > to create > - the child. > - @retval other The child handle was not created. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4ServiceBindingCreateChild ( > - IN EFI_SERVICE_BINDING_PROTOCOL *This, > - IN OUT EFI_HANDLE *ChildHandle > - ) > -{ > - SOCKET *Sock; > - TCP4_SERVICE_DATA *TcpServiceData; > - TCP4_PROTO_DATA TcpProto; > - EFI_STATUS Status; > - EFI_TPL OldTpl; > - > - if (NULL =3D=3D This || NULL =3D=3D ChildHandle) { > - return EFI_INVALID_PARAMETER; > - } > - > - OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); > - Status =3D EFI_SUCCESS; > - TcpServiceData =3D TCP4_FROM_THIS (This); > - TcpProto.TcpService =3D TcpServiceData; > - TcpProto.TcpPcb =3D NULL; > - > - // > - // Create a tcp instance with defualt Tcp default > - // sock init data and TcpProto > - // > - mTcp4DefaultSockData.ProtoData =3D &TcpProto; > - mTcp4DefaultSockData.DataSize =3D sizeof (TCP4_PROTO_DATA); > - mTcp4DefaultSockData.DriverBinding =3D TcpServiceData->DriverBindingHa= ndle; > - > - Sock =3D SockCreateChild (&mTcp4DefaultSockData); > - if (NULL =3D=3D Sock) { > - DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingCreateChild: " > - "No resource to create a Tcp Child\n")); > - > - Status =3D EFI_OUT_OF_RESOURCES; > - } else { > - *ChildHandle =3D Sock->SockHandle; > - } > - > - mTcp4DefaultSockData.ProtoData =3D NULL; > - > - gBS->RestoreTPL (OldTpl); > - return Status; > -} > - > - > -/** > - Destroys a child handle with a protocol installed on it. > - > - The DestroyChild() function does the opposite of CreateChild(). It rem= oves a > protocol > - that was installed by CreateChild() from ChildHandle. If the removed p= rotocol > is the > - last protocol on ChildHandle, then ChildHandle is destroyed. > - > - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL insta= nce. > - @param ChildHandle Handle of the child to destroy > - > - @retval EFI_SUCCES The protocol was removed from ChildHandl= e. > - @retval EFI_UNSUPPORTED ChildHandle does not support the protoco= l > that is > - being removed. > - @retval EFI_INVALID_PARAMETER Child handle is NULL. > - @retval EFI_ACCESS_DENIED The protocol could not be removed from t= he > ChildHandle > - because its services are being used. > - @retval other The child handle was not destroyed. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4ServiceBindingDestroyChild ( > - IN EFI_SERVICE_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ChildHandle > - ) > -{ > - EFI_STATUS Status; > - EFI_TCP4_PROTOCOL *Tcp4; > - SOCKET *Sock; > - > - if (NULL =3D=3D This || NULL =3D=3D ChildHandle) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // retrieve the Tcp4 protocol from ChildHandle > - // > - Status =3D gBS->OpenProtocol ( > - ChildHandle, > - &gEfiTcp4ProtocolGuid, > - (VOID **) &Tcp4, > - mTcp4DriverBinding.DriverBindingHandle, > - ChildHandle, > - EFI_OPEN_PROTOCOL_GET_PROTOCOL > - ); > - if (EFI_ERROR (Status)) { > - Status =3D EFI_UNSUPPORTED; > - } else { > - // > - // destroy this sock and related Tcp protocol control > - // block > - // > - Sock =3D SOCK_FROM_THIS (Tcp4); > - > - SockDestroyChild (Sock); > - } > - > - return Status; > -} > - > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c > deleted file mode 100644 > index f48efdac7cd8..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c > +++ /dev/null > @@ -1,1497 +0,0 @@ > -/** @file > - TCP input process routines. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > - > -#include "Tcp4Main.h" > - > - > -/** > - Check whether the sequence number of the incoming segment is acceptabl= e. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seg Pointer to the incoming segment. > - > - @retval 1 The sequence number is acceptable. > - @retval 0 The sequence number is not acceptable. > - > -**/ > -INTN > -TcpSeqAcceptable ( > - IN TCP_CB *Tcb, > - IN TCP_SEG *Seg > - ) > -{ > - return (TCP_SEQ_LEQ (Tcb->RcvNxt, Seg->End) && > - TCP_SEQ_LT (Seg->Seq, Tcb->RcvWl2 + Tcb->RcvWnd)); > -} > - > - > -/** > - NewReno fast recovery, RFC3782. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seg Segment that triggers the fast recovery. > - > -**/ > -VOID > -TcpFastRecover ( > - IN OUT TCP_CB *Tcb, > - IN TCP_SEG *Seg > - ) > -{ > - UINT32 FlightSize; > - UINT32 Acked; > - > - // > - // Step 1: Three duplicate ACKs and not in fast recovery > - // > - if (Tcb->CongestState !=3D TCP_CONGEST_RECOVER) { > - > - // > - // Step 1A: Invoking fast retransmission. > - // > - FlightSize =3D TCP_SUB_SEQ (Tcb->SndNxt, Tcb->SndUna); > - > - Tcb->Ssthresh =3D MAX (FlightSize >> 1, (UINT32) (2 * Tcb->SndMs= s)); > - Tcb->Recover =3D Tcb->SndNxt; > - > - Tcb->CongestState =3D TCP_CONGEST_RECOVER; > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON); > - > - // > - // Step 2: Entering fast retransmission > - // > - TcpRetransmit (Tcb, Tcb->SndUna); > - Tcb->CWnd =3D Tcb->Ssthresh + 3 * Tcb->SndMss; > - > - DEBUG ((EFI_D_NET, "TcpFastRecover: enter fast retransmission" > - " for TCB %p, recover point is %d\n", Tcb, Tcb->Recover)); > - return; > - } > - > - // > - // During fast recovery, execute Step 3, 4, 5 of RFC3782 > - // > - if (Seg->Ack =3D=3D Tcb->SndUna) { > - > - // > - // Step 3: Fast Recovery, > - // If this is a duplicated ACK, increse Cwnd by SMSS. > - // > - > - // Step 4 is skipped here only to be executed later > - // by TcpToSendData > - // > - Tcb->CWnd +=3D Tcb->SndMss; > - DEBUG ((EFI_D_NET, "TcpFastRecover: received another" > - " duplicated ACK (%d) for TCB %p\n", Seg->Ack, Tcb)); > - > - } else { > - > - // > - // New data is ACKed, check whether it is a > - // full ACK or partial ACK > - // > - if (TCP_SEQ_GEQ (Seg->Ack, Tcb->Recover)) { > - > - // > - // Step 5 - Full ACK: > - // deflate the congestion window, and exit fast recovery > - // > - FlightSize =3D TCP_SUB_SEQ (Tcb->SndNxt, Tcb->SndUna); > - > - Tcb->CWnd =3D MIN (Tcb->Ssthresh, FlightSize + Tcb->SndMss= ); > - > - Tcb->CongestState =3D TCP_CONGEST_OPEN; > - DEBUG ((EFI_D_NET, "TcpFastRecover: received a full ACK(%d)" > - " for TCB %p, exit fast recovery\n", Seg->Ack, Tcb)); > - > - } else { > - > - // > - // Step 5 - Partial ACK: > - // fast retransmit the first unacknowledge field > - // , then deflate the CWnd > - // > - TcpRetransmit (Tcb, Seg->Ack); > - Acked =3D TCP_SUB_SEQ (Seg->Ack, Tcb->SndUna); > - > - // > - // Deflate the CWnd by the amount of new data > - // ACKed by SEG.ACK. If more than one SMSS data > - // is ACKed, add back SMSS byte to CWnd after > - // > - if (Acked >=3D Tcb->SndMss) { > - Acked -=3D Tcb->SndMss; > - > - } > - > - Tcb->CWnd -=3D Acked; > - > - DEBUG ((EFI_D_NET, "TcpFastRecover: received a partial" > - " ACK(%d) for TCB %p\n", Seg->Ack, Tcb)); > - > - } > - } > -} > - > - > -/** > - NewReno fast loss recovery, RFC3792. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seg Segment that triggers the fast loss recovery. > - > -**/ > -VOID > -TcpFastLossRecover ( > - IN OUT TCP_CB *Tcb, > - IN TCP_SEG *Seg > - ) > -{ > - if (TCP_SEQ_GT (Seg->Ack, Tcb->SndUna)) { > - > - // > - // New data is ACKed, check whether it is a > - // full ACK or partial ACK > - // > - if (TCP_SEQ_GEQ (Seg->Ack, Tcb->LossRecover)) { > - > - // > - // Full ACK: exit the loss recovery. > - // > - Tcb->LossTimes =3D 0; > - Tcb->CongestState =3D TCP_CONGEST_OPEN; > - > - DEBUG ((EFI_D_NET, "TcpFastLossRecover: received a " > - "full ACK(%d) for TCB %p\n", Seg->Ack, Tcb)); > - > - } else { > - > - // > - // Partial ACK: > - // fast retransmit the first unacknowledge field. > - // > - TcpRetransmit (Tcb, Seg->Ack); > - DEBUG ((EFI_D_NET, "TcpFastLossRecover: received a " > - "partial ACK(%d) for TCB %p\n", Seg->Ack, Tcb)); > - } > - } > -} > - > - > -/** > - Compute the RTT as specified in RFC2988. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Measure Currently measured RTT in heart beats. > - > -**/ > -VOID > -TcpComputeRtt ( > - IN OUT TCP_CB *Tcb, > - IN UINT32 Measure > - ) > -{ > - INT32 Var; > - > - // > - // Step 2.3: Compute the RTO for subsequent RTT measurement. > - // > - if (Tcb->SRtt !=3D 0) { > - > - Var =3D Tcb->SRtt - (Measure << TCP_RTT_SHIFT); > - > - if (Var < 0) { > - Var =3D -Var; > - } > - > - Tcb->RttVar =3D (3 * Tcb->RttVar + Var) >> 2; > - Tcb->SRtt =3D 7 * (Tcb->SRtt >> 3) + Measure; > - > - } else { > - // > - // Step 2.2: compute the first RTT measure > - // > - Tcb->SRtt =3D Measure << TCP_RTT_SHIFT; > - Tcb->RttVar =3D Measure << (TCP_RTT_SHIFT - 1); > - } > - > - Tcb->Rto =3D (Tcb->SRtt + MAX (8, 4 * Tcb->RttVar)) >> TCP_RTT_SHIFT; > - > - // > - // Step 2.4: Limit the RTO to at least 1 second > - // Step 2.5: Limit the RTO to a maxium value that > - // is at least 60 second > - // > - if (Tcb->Rto < TCP_RTO_MIN) { > - Tcb->Rto =3D TCP_RTO_MIN; > - > - } else if (Tcb->Rto > TCP_RTO_MAX) { > - Tcb->Rto =3D TCP_RTO_MAX; > - > - } > - > - DEBUG ((EFI_D_NET, "TcpComputeRtt: new RTT for TCB %p" > - " computed SRTT: %d RTTVAR: %d RTO: %d\n", > - Tcb, Tcb->SRtt, Tcb->RttVar, Tcb->Rto)); > - > -} > - > - > -/** > - Trim the data, SYN and FIN to fit into the window defined by Left and = Right. > - > - @param Nbuf Buffer that contains received TCP segment without IP = header. > - @param Left The sequence number of the window's left edge. > - @param Right The sequence number of the window's right edge. > - > -**/ > -VOID > -TcpTrimSegment ( > - IN NET_BUF *Nbuf, > - IN TCP_SEQNO Left, > - IN TCP_SEQNO Right > - ) > -{ > - TCP_SEG *Seg; > - TCP_SEQNO Urg; > - UINT32 Drop; > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - > - // > - // If the segment is completely out of window, > - // truncate every thing, include SYN and FIN. > - // > - if (TCP_SEQ_LEQ (Seg->End, Left) || TCP_SEQ_LEQ (Right, Seg->Seq)) { > - > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_SYN); > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_FIN); > - > - Seg->Seq =3D Seg->End; > - NetbufTrim (Nbuf, Nbuf->TotalSize, NET_BUF_HEAD); > - return; > - } > - > - // > - // Adjust the buffer header > - // > - if (TCP_SEQ_LT (Seg->Seq, Left)) { > - > - Drop =3D TCP_SUB_SEQ (Left, Seg->Seq); > - Urg =3D Seg->Seq + Seg->Urg; > - Seg->Seq =3D Left; > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_SYN); > - Drop--; > - } > - > - // > - // Adjust the urgent point > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_URG)) { > - > - if (TCP_SEQ_LT (Urg, Seg->Seq)) { > - > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_URG); > - } else { > - Seg->Urg =3D (UINT16) TCP_SUB_SEQ (Urg, Seg->Seq); > - } > - } > - > - if (Drop !=3D 0) { > - NetbufTrim (Nbuf, Drop, NET_BUF_HEAD); > - } > - } > - > - // > - // Adjust the buffer tail > - // > - if (TCP_SEQ_GT (Seg->End, Right)) { > - > - Drop =3D TCP_SUB_SEQ (Seg->End, Right); > - Seg->End =3D Right; > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) { > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_FIN); > - Drop--; > - } > - > - if (Drop !=3D 0) { > - NetbufTrim (Nbuf, Drop, NET_BUF_TAIL); > - } > - } > - > - ASSERT (TcpVerifySegment (Nbuf) !=3D 0); > -} > - > - > -/** > - Trim off the data outside the tcb's receive window. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the NET_BUF containing the received tcp se= gment. > - > -**/ > -VOID > -TcpTrimInWnd ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ) > -{ > - TcpTrimSegment (Nbuf, Tcb->RcvNxt, Tcb->RcvWl2 + Tcb->RcvWnd); > -} > - > - > -/** > - Process the data and FIN flag, check whether to deliver > - data to the socket layer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @retval 0 No error occurred to deliver data. > - @retval -1 Error condition occurred. Proper response is to reset= the > - connection. > - > -**/ > -INTN > -TcpDeliverData ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - LIST_ENTRY *Entry; > - NET_BUF *Nbuf; > - TCP_SEQNO Seq; > - TCP_SEG *Seg; > - UINT32 Urgent; > - > - ASSERT ((Tcb !=3D NULL) && (Tcb->Sk !=3D NULL)); > - > - // > - // make sure there is some data queued, > - // and TCP is in a proper state > - // > - if (IsListEmpty (&Tcb->RcvQue) || !TCP_CONNECTED (Tcb->State)) { > - > - return 0; > - } > - > - // > - // Deliver data to the socket layer > - // > - Entry =3D Tcb->RcvQue.ForwardLink; > - Seq =3D Tcb->RcvNxt; > - > - while (Entry !=3D &Tcb->RcvQue) { > - Nbuf =3D NET_LIST_USER_STRUCT (Entry, NET_BUF, List); > - Seg =3D TCPSEG_NETBUF (Nbuf); > - > - ASSERT (TcpVerifySegment (Nbuf) !=3D 0); > - ASSERT (Nbuf->Tcp =3D=3D NULL); > - > - if (TCP_SEQ_GT (Seg->Seq, Seq)) { > - break; > - } > - > - Entry =3D Entry->ForwardLink; > - Seq =3D Seg->End; > - Tcb->RcvNxt =3D Seq; > - > - RemoveEntryList (&Nbuf->List); > - > - // > - // RFC793 Eighth step: process FIN in sequence > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) { > - > - // > - // The peer sends to us junky data after FIN, > - // reset the connection. > - // > - if (!IsListEmpty (&Tcb->RcvQue)) { > - DEBUG ((EFI_D_ERROR, "TcpDeliverData: data received after" > - " FIN from peer of TCB %p, reset connection\n", Tcb)); > - > - NetbufFree (Nbuf); > - return -1; > - } > - > - DEBUG ((EFI_D_NET, "TcpDeliverData: processing FIN " > - "from peer of TCB %p\n", Tcb)); > - > - switch (Tcb->State) { > - case TCP_SYN_RCVD: > - case TCP_ESTABLISHED: > - > - TcpSetState (Tcb, TCP_CLOSE_WAIT); > - break; > - > - case TCP_FIN_WAIT_1: > - > - if (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_FIN_ACKED)) { > - > - TcpSetState (Tcb, TCP_CLOSING); > - break; > - } > - > - // > - // fall through > - // > - case TCP_FIN_WAIT_2: > - > - TcpSetState (Tcb, TCP_TIME_WAIT); > - TcpClearAllTimer (Tcb); > - > - if (Tcb->TimeWaitTimeout !=3D 0) { > - > - TcpSetTimer (Tcb, TCP_TIMER_2MSL, Tcb->TimeWaitTimeout); > - } else { > - > - DEBUG ((EFI_D_WARN, "Connection closed immediately " > - "because app disables TIME_WAIT timer for %p\n", Tcb)); > - > - TcpSendAck (Tcb); > - TcpClose (Tcb); > - } > - break; > - > - case TCP_CLOSE_WAIT: > - case TCP_CLOSING: > - case TCP_LAST_ACK: > - case TCP_TIME_WAIT: > - // > - // The peer sends to us junk FIN byte. Discard > - // the buffer then reset the connection > - // > - NetbufFree (Nbuf); > - return -1; > - default: > - break; > - } > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - > - Seg->End--; > - } > - > - // > - // Don't delay the ack if PUSH flag is on. > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_PSH)) { > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - } > - > - if (Nbuf->TotalSize !=3D 0) { > - Urgent =3D 0; > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RCVD_URG) && > - TCP_SEQ_LEQ (Seg->Seq, Tcb->RcvUp)) { > - > - if (TCP_SEQ_LEQ (Seg->End, Tcb->RcvUp)) { > - Urgent =3D Nbuf->TotalSize; > - } else { > - Urgent =3D TCP_SUB_SEQ (Tcb->RcvUp, Seg->Seq) + 1; > - } > - } > - > - SockDataRcvd (Tcb->Sk, Nbuf, Urgent); > - } > - > - if (TCP_FIN_RCVD (Tcb->State)) { > - > - SockNoMoreData (Tcb->Sk); > - } > - > - NetbufFree (Nbuf); > - } > - > - return 0; > -} > - > - > -/** > - Store the data into the reassemble queue. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer containing the data to be queue= d. > - > -**/ > -VOID > -TcpQueueData ( > - IN OUT TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ) > -{ > - TCP_SEG *Seg; > - LIST_ENTRY *Head; > - LIST_ENTRY *Prev; > - LIST_ENTRY *Cur; > - NET_BUF *Node; > - > - ASSERT ((Tcb !=3D NULL) && (Nbuf !=3D NULL) && (Nbuf->Tcp =3D=3D NULL)= ); > - > - NET_GET_REF (Nbuf); > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - Head =3D &Tcb->RcvQue; > - > - // > - // Fast path to process normal case. That is, > - // no out-of-order segments are received. > - // > - if (IsListEmpty (Head)) { > - > - InsertTailList (Head, &Nbuf->List); > - return; > - } > - > - // > - // Find the point to insert the buffer > - // > - for (Prev =3D Head, Cur =3D Head->ForwardLink; > - Cur !=3D Head; > - Prev =3D Cur, Cur =3D Cur->ForwardLink) { > - > - Node =3D NET_LIST_USER_STRUCT (Cur, NET_BUF, List); > - > - if (TCP_SEQ_LT (Seg->Seq, TCPSEG_NETBUF (Node)->Seq)) { > - break; > - } > - } > - > - // > - // Check whether the current segment overlaps with the > - // previous segment. > - // > - if (Prev !=3D Head) { > - Node =3D NET_LIST_USER_STRUCT (Prev, NET_BUF, List); > - > - if (TCP_SEQ_LT (Seg->Seq, TCPSEG_NETBUF (Node)->End)) { > - > - if (TCP_SEQ_LEQ (Seg->End, TCPSEG_NETBUF (Node)->End)) { > - > - NetbufFree (Nbuf); > - return; > - } > - > - TcpTrimSegment (Nbuf, TCPSEG_NETBUF (Node)->End, Seg->End); > - } > - } > - > - InsertHeadList (Prev, &Nbuf->List); > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - > - // > - // Check the segments after the insert point. > - // > - while (Cur !=3D Head) { > - Node =3D NET_LIST_USER_STRUCT (Cur, NET_BUF, List); > - > - if (TCP_SEQ_LEQ (TCPSEG_NETBUF (Node)->End, Seg->End)) { > - > - Cur =3D Cur->ForwardLink; > - > - RemoveEntryList (&Node->List); > - NetbufFree (Node); > - continue; > - } > - > - if (TCP_SEQ_LT (TCPSEG_NETBUF (Node)->Seq, Seg->End)) { > - > - if (TCP_SEQ_LEQ (TCPSEG_NETBUF (Node)->Seq, Seg->Seq)) { > - > - RemoveEntryList (&Nbuf->List); > - NetbufFree (Nbuf); > - return ; > - } > - > - TcpTrimSegment (Nbuf, Seg->Seq, TCPSEG_NETBUF (Node)->Seq); > - break; > - } > - > - Cur =3D Cur->ForwardLink; > - } > -} > - > - > -/** > - Ajust the send queue or the retransmit queue. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Ack The acknowledge seuqence number of the received segme= nt. > - > -**/ > -VOID > -TcpAdjustSndQue ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Ack > - ) > -{ > - LIST_ENTRY *Head; > - LIST_ENTRY *Cur; > - NET_BUF *Node; > - TCP_SEG *Seg; > - > - Head =3D &Tcb->SndQue; > - Cur =3D Head->ForwardLink; > - > - while (Cur !=3D Head) { > - Node =3D NET_LIST_USER_STRUCT (Cur, NET_BUF, List); > - Seg =3D TCPSEG_NETBUF (Node); > - > - if (TCP_SEQ_GEQ (Seg->Seq, Ack)) { > - break; > - } > - > - // > - // Remove completely ACKed segments > - // > - if (TCP_SEQ_LEQ (Seg->End, Ack)) { > - Cur =3D Cur->ForwardLink; > - > - RemoveEntryList (&Node->List); > - NetbufFree (Node); > - continue; > - } > - > - TcpTrimSegment (Node, Ack, Seg->End); > - break; > - } > -} > - > - > -/** > - Process the received TCP segments. > - > - @param Nbuf Buffer that contains received TCP segment without IP = header. > - @param Src Source address of the segment, or the peer's IP addre= ss. > - @param Dst Destination address of the segment, or the local end'= s IP > - address. > - > - @retval 0 Segment is processed successfully. It is either accep= ted or > - discarded. But no connection is reset by the segment. > - @retval -1 A connection is reset by the segment. > - > -**/ > -INTN > -TcpInput ( > - IN NET_BUF *Nbuf, > - IN UINT32 Src, > - IN UINT32 Dst > - ) > -{ > - TCP_CB *Tcb; > - TCP_CB *Parent; > - TCP_OPTION Option; > - TCP_HEAD *Head; > - INT32 Len; > - TCP_SEG *Seg; > - TCP_SEQNO Right; > - TCP_SEQNO Urg; > - INT32 Usable; > - > - NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE); > - > - Parent =3D NULL; > - Tcb =3D NULL; > - > - Head =3D (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); > - ASSERT (Head !=3D NULL); > - > - if (Nbuf->TotalSize < sizeof (TCP_HEAD)) { > - DEBUG ((EFI_D_NET, "TcpInput: received a malformed packet\n")); > - goto DISCARD; > - } > - > - Len =3D Nbuf->TotalSize - (Head->HeadLen << 2); > - > - if ((Head->HeadLen < 5) || (Len < 0) || > - (TcpChecksum (Nbuf, NetPseudoHeadChecksum (Src, Dst, 6, 0)) !=3D 0= )) { > - > - DEBUG ((EFI_D_NET, "TcpInput: received a malformed packet\n")); > - goto DISCARD; > - } > - > - if (TCP_FLG_ON (Head->Flag, TCP_FLG_SYN)) { > - Len++; > - } > - > - if (TCP_FLG_ON (Head->Flag, TCP_FLG_FIN)) { > - Len++; > - } > - > - Tcb =3D TcpLocateTcb ( > - Head->DstPort, > - Dst, > - Head->SrcPort, > - Src, > - (BOOLEAN) TCP_FLG_ON (Head->Flag, TCP_FLG_SYN) > - ); > - > - if ((Tcb =3D=3D NULL) || (Tcb->State =3D=3D TCP_CLOSED)) { > - DEBUG ((EFI_D_NET, "TcpInput: send reset because no TCB found\n")); > - > - Tcb =3D NULL; > - goto SEND_RESET; > - } > - > - Seg =3D TcpFormatNetbuf (Tcb, Nbuf); > - > - // > - // RFC1122 recommended reaction to illegal option > - // (in fact, an illegal option length) is reset. > - // > - if (TcpParseOption (Nbuf->Tcp, &Option) =3D=3D -1) { > - DEBUG ((EFI_D_ERROR, "TcpInput: reset the peer because" > - " of malformed option for TCB %p\n", Tcb)); > - > - goto SEND_RESET; > - } > - > - // > - // From now on, the segment is headless > - // > - NetbufTrim (Nbuf, (Head->HeadLen << 2), NET_BUF_HEAD); > - Nbuf->Tcp =3D NULL; > - > - // > - // Process the segment in LISTEN state. > - // > - if (Tcb->State =3D=3D TCP_LISTEN) { > - // > - // First step: Check RST > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_RST)) { > - DEBUG ((EFI_D_WARN, "TcpInput: discard a reset segment " > - "for TCB %p in listening\n", Tcb)); > - > - goto DISCARD; > - } > - > - // > - // Second step: Check ACK. > - // Any ACK sent to TCP in LISTEN is reseted. > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK)) { > - DEBUG ((EFI_D_WARN, "TcpInput: send reset because of" > - " segment with ACK for TCB %p in listening\n", Tcb)); > - > - goto SEND_RESET; > - } > - > - // > - // Third step: Check SYN > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - // > - // create a child TCB to handle the data > - // > - Parent =3D Tcb; > - > - Tcb =3D TcpCloneTcb (Parent); > - if (Tcb =3D=3D NULL) { > - DEBUG ((EFI_D_ERROR, "TcpInput: discard a segment because" > - " failed to clone a child for TCB %p\n", Tcb)); > - > - goto DISCARD; > - } > - > - DEBUG ((EFI_D_NET, "TcpInput: create a child for TCB %p" > - " in listening\n", Tcb)); > - > - // > - // init the TCB structure > - // > - Tcb->LocalEnd.Ip =3D Dst; > - Tcb->LocalEnd.Port =3D Head->DstPort; > - Tcb->RemoteEnd.Ip =3D Src; > - Tcb->RemoteEnd.Port =3D Head->SrcPort; > - > - TcpInitTcbLocal (Tcb); > - TcpInitTcbPeer (Tcb, Seg, &Option); > - > - TcpSetState (Tcb, TCP_SYN_RCVD); > - TcpSetTimer (Tcb, TCP_TIMER_CONNECT, Tcb->ConnectTimeout); > - TcpTrimInWnd (Tcb, Nbuf); > - > - goto StepSix; > - } > - > - goto DISCARD; > - > - } else if (Tcb->State =3D=3D TCP_SYN_SENT) { > - // > - // First step: Check ACK bit > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK) && (Seg->Ack !=3D Tcb->Iss += 1)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: send reset because of " > - "wrong ACK received for TCB %p in SYN_SENT\n", Tcb)); > - > - goto SEND_RESET; > - } > - > - // > - // Second step: Check RST bit > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_RST)) { > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: connection reset by" > - " peer for TCB %p in SYN_SENT\n", Tcb)); > - > - SOCK_ERROR (Tcb->Sk, EFI_CONNECTION_RESET); > - goto DROP_CONNECTION; > - } else { > - > - DEBUG ((EFI_D_WARN, "TcpInput: discard a reset segment " > - "because of no ACK for TCB %p in SYN_SENT\n", Tcb)); > - > - goto DISCARD; > - } > - } > - > - // > - // Third step: Check security and precedence. Skipped > - // > - > - // > - // Fourth step: Check SYN. Pay attention to simultaneous open > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - > - TcpInitTcbPeer (Tcb, Seg, &Option); > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK)) { > - > - Tcb->SndUna =3D Seg->Ack; > - } > - > - TcpClearTimer (Tcb, TCP_TIMER_REXMIT); > - > - if (TCP_SEQ_GT (Tcb->SndUna, Tcb->Iss)) { > - > - TcpSetState (Tcb, TCP_ESTABLISHED); > - > - TcpClearTimer (Tcb, TCP_TIMER_CONNECT); > - TcpDeliverData (Tcb); > - > - if ((Tcb->CongestState =3D=3D TCP_CONGEST_OPEN) && > - TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RTT_ON)) { > - > - TcpComputeRtt (Tcb, Tcb->RttMeasure); > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON); > - } > - > - TcpTrimInWnd (Tcb, Nbuf); > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - > - DEBUG ((EFI_D_NET, "TcpInput: connection established" > - " for TCB %p in SYN_SENT\n", Tcb)); > - > - goto StepSix; > - } else { > - // > - // Received a SYN segment without ACK, simultaneous open. > - // > - TcpSetState (Tcb, TCP_SYN_RCVD); > - > - ASSERT (Tcb->SndNxt =3D=3D Tcb->Iss + 1); > - TcpAdjustSndQue (Tcb, Tcb->SndNxt); > - > - TcpTrimInWnd (Tcb, Nbuf); > - > - DEBUG ((EFI_D_WARN, "TcpInput: simultaneous open " > - "for TCB %p in SYN_SENT\n", Tcb)); > - > - goto StepSix; > - } > - } > - > - goto DISCARD; > - } > - > - // > - // Process segment in SYN_RCVD or TCP_CONNECTED states > - // > - > - // > - // Clear probe timer since the RecvWindow is opened. > - // > - if (Tcb->ProbeTimerOn && (Seg->Wnd !=3D 0)) { > - TcpClearTimer (Tcb, TCP_TIMER_PROBE); > - Tcb->ProbeTimerOn =3D FALSE; > - } > - > - // > - // First step: Check whether SEG.SEQ is acceptable > - // > - if (TcpSeqAcceptable (Tcb, Seg) =3D=3D 0) { > - DEBUG ((EFI_D_WARN, "TcpInput: sequence acceptance" > - " test failed for segment of TCB %p\n", Tcb)); > - > - if (!TCP_FLG_ON (Seg->Flag, TCP_FLG_RST)) { > - TcpSendAck (Tcb); > - } > - > - goto DISCARD; > - } > - > - if ((TCP_SEQ_LT (Seg->Seq, Tcb->RcvWl2)) && > - (Tcb->RcvWl2 =3D=3D Seg->End) && > - !TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN | TCP_FLG_FIN)) { > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - } > - > - // > - // Second step: Check the RST > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_RST)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: connection reset for TCB %p\n", Tcb))= ; > - > - if (Tcb->State =3D=3D TCP_SYN_RCVD) { > - > - SOCK_ERROR (Tcb->Sk, EFI_CONNECTION_REFUSED); > - > - // > - // This TCB comes from either a LISTEN TCB, > - // or active open TCB with simultanous open. > - // Do NOT signal user CONNECTION refused > - // if it comes from a LISTEN TCB. > - // > - } else if ((Tcb->State =3D=3D TCP_ESTABLISHED) || > - (Tcb->State =3D=3D TCP_FIN_WAIT_1) || > - (Tcb->State =3D=3D TCP_FIN_WAIT_2) || > - (Tcb->State =3D=3D TCP_CLOSE_WAIT)) { > - > - SOCK_ERROR (Tcb->Sk, EFI_CONNECTION_RESET); > - > - } else { > - > - } > - > - goto DROP_CONNECTION; > - } > - > - // > - // Trim the data and flags. > - // > - TcpTrimInWnd (Tcb, Nbuf); > - > - // > - // Third step: Check security and precedence, Ignored > - // > - > - // > - // Fourth step: Check the SYN bit. > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: connection reset " > - "because received extra SYN for TCB %p\n", Tcb)); > - > - SOCK_ERROR (Tcb->Sk, EFI_CONNECTION_RESET); > - goto RESET_THEN_DROP; > - } > - > - // > - // Fifth step: Check the ACK > - // > - if (!TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK)) { > - DEBUG ((EFI_D_WARN, "TcpInput: segment discard because" > - " of no ACK for connected TCB %p\n", Tcb)); > - > - goto DISCARD; > - > - } > - > - if (Tcb->State =3D=3D TCP_SYN_RCVD) { > - > - if (TCP_SEQ_LT (Tcb->SndUna, Seg->Ack) && > - TCP_SEQ_LEQ (Seg->Ack, Tcb->SndNxt)) { > - > - Tcb->SndWnd =3D Seg->Wnd; > - Tcb->SndWndMax =3D MAX (Tcb->SndWnd, Tcb->SndWndMax); > - Tcb->SndWl1 =3D Seg->Seq; > - Tcb->SndWl2 =3D Seg->Ack; > - TcpSetState (Tcb, TCP_ESTABLISHED); > - > - TcpClearTimer (Tcb, TCP_TIMER_CONNECT); > - TcpDeliverData (Tcb); > - > - DEBUG ((EFI_D_NET, "TcpInput: connection established " > - " for TCB %p in SYN_RCVD\n", Tcb)); > - > - // > - // Continue the process as ESTABLISHED state > - // > - } else { > - DEBUG ((EFI_D_WARN, "TcpInput: send reset because of" > - " wrong ACK for TCB %p in SYN_RCVD\n", Tcb)); > - > - goto SEND_RESET; > - } > - } > - > - if (TCP_SEQ_LT (Seg->Ack, Tcb->SndUna)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: ignore the out-of-data" > - " ACK for connected TCB %p\n", Tcb)); > - > - goto StepSix; > - > - } else if (TCP_SEQ_GT (Seg->Ack, Tcb->SndNxt)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: discard segment for " > - "future ACK for connected TCB %p\n", Tcb)); > - > - TcpSendAck (Tcb); > - goto DISCARD; > - } > - > - // > - // From now on: SND.UNA <=3D SEG.ACK <=3D SND.NXT. > - // > - if (TCP_FLG_ON (Option.Flag, TCP_OPTION_RCVD_TS)) { > - // > - // update TsRecent as specified in page 16 RFC1323. > - // RcvWl2 equals to the variable "LastAckSent" > - // defined there. > - // > - if (TCP_SEQ_LEQ (Seg->Seq, Tcb->RcvWl2) && > - TCP_SEQ_LT (Tcb->RcvWl2, Seg->End)) { > - > - Tcb->TsRecent =3D Option.TSVal; > - Tcb->TsRecentAge =3D mTcpTick; > - } > - > - TcpComputeRtt (Tcb, TCP_SUB_TIME (mTcpTick, Option.TSEcr)); > - > - } else if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RTT_ON)) { > - > - ASSERT (Tcb->CongestState =3D=3D TCP_CONGEST_OPEN); > - > - TcpComputeRtt (Tcb, Tcb->RttMeasure); > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON); > - } > - > - if (Seg->Ack =3D=3D Tcb->SndNxt) { > - > - TcpClearTimer (Tcb, TCP_TIMER_REXMIT); > - } else { > - > - TcpSetTimer (Tcb, TCP_TIMER_REXMIT, Tcb->Rto); > - } > - > - // > - // Count duplicate acks. > - // > - if ((Seg->Ack =3D=3D Tcb->SndUna) && > - (Tcb->SndUna !=3D Tcb->SndNxt) && > - (Seg->Wnd =3D=3D Tcb->SndWnd) && > - (0 =3D=3D Len)) { > - > - Tcb->DupAck++; > - } else { > - > - Tcb->DupAck =3D 0; > - } > - > - // > - // Congestion avoidance, fast recovery and fast retransmission. > - // > - if (((Tcb->CongestState =3D=3D TCP_CONGEST_OPEN) && (Tcb->DupAck < 3))= || > - (Tcb->CongestState =3D=3D TCP_CONGEST_LOSS)) { > - > - if (TCP_SEQ_GT (Seg->Ack, Tcb->SndUna)) { > - > - if (Tcb->CWnd < Tcb->Ssthresh) { > - > - Tcb->CWnd +=3D Tcb->SndMss; > - } else { > - > - Tcb->CWnd +=3D MAX (Tcb->SndMss * Tcb->SndMss / Tcb->CWnd, 1); > - } > - > - Tcb->CWnd =3D MIN (Tcb->CWnd, TCP_MAX_WIN << Tcb->SndWndScale); > - } > - > - if (Tcb->CongestState =3D=3D TCP_CONGEST_LOSS) { > - TcpFastLossRecover (Tcb, Seg); > - } > - } else { > - > - TcpFastRecover (Tcb, Seg); > - } > - > - if (TCP_SEQ_GT (Seg->Ack, Tcb->SndUna)) { > - > - TcpAdjustSndQue (Tcb, Seg->Ack); > - Tcb->SndUna =3D Seg->Ack; > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_SND_URG) && > - TCP_SEQ_LT (Tcb->SndUp, Seg->Ack)) { > - > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_URG); > - } > - } > - > - // > - // Update window info > - // > - if (TCP_SEQ_LT (Tcb->SndWl1, Seg->Seq) || > - ((Tcb->SndWl1 =3D=3D Seg->Seq) && TCP_SEQ_LEQ (Tcb->SndWl2, Seg->A= ck))) { > - > - Right =3D Seg->Ack + Seg->Wnd; > - > - if (TCP_SEQ_LT (Right, Tcb->SndWl2 + Tcb->SndWnd)) { > - > - if ((Tcb->SndWl1 =3D=3D Seg->Seq) && > - (Tcb->SndWl2 =3D=3D Seg->Ack) && > - (Len =3D=3D 0)) { > - > - goto NO_UPDATE; > - } > - > - DEBUG ((EFI_D_WARN, "TcpInput: peer shrinks the" > - " window for connected TCB %p\n", Tcb)); > - > - if ((Tcb->CongestState =3D=3D TCP_CONGEST_RECOVER) && > - (TCP_SEQ_LT (Right, Tcb->Recover))) { > - > - Tcb->Recover =3D Right; > - } > - > - if ((Tcb->CongestState =3D=3D TCP_CONGEST_LOSS) && > - (TCP_SEQ_LT (Right, Tcb->LossRecover))) { > - > - Tcb->LossRecover =3D Right; > - } > - > - if (TCP_SEQ_LT (Right, Tcb->SndNxt)) { > - // > - // Check for Window Retraction in RFC7923 section 2.4. > - // The lower n bits of the peer's actual receive window is wiped= out if TCP > - // window scale is enabled, it will look like the peer is shrink= ing the window. > - // Check whether the SndNxt is out of the advertised receive win= dow by > more than > - // 2^Rcv.Wind.Shift before moving the SndNxt to the left. > - // > - DEBUG ( > - (EFI_D_WARN, > - "TcpInput: peer advise negative useable window for connected T= CB %p\n", > - Tcb) > - ); > - Usable =3D TCP_SUB_SEQ (Tcb->SndNxt, Right); > - if ((Usable >> Tcb->SndWndScale) > 0) { > - DEBUG ( > - (EFI_D_WARN, > - "TcpInput: SndNxt is out of window by more than window scale= for > TCB %p\n", > - Tcb) > - ); > - Tcb->SndNxt =3D Right; > - } > - if (Right =3D=3D Tcb->SndUna) { > - > - TcpClearTimer (Tcb, TCP_TIMER_REXMIT); > - TcpSetProbeTimer (Tcb); > - } > - } > - } > - > - Tcb->SndWnd =3D Seg->Wnd; > - Tcb->SndWndMax =3D MAX (Tcb->SndWnd, Tcb->SndWndMax); > - Tcb->SndWl1 =3D Seg->Seq; > - Tcb->SndWl2 =3D Seg->Ack; > - } > - > -NO_UPDATE: > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_FIN_SENT) && > - (Tcb->SndUna =3D=3D Tcb->SndNxt)) { > - > - DEBUG ((EFI_D_NET, "TcpInput: local FIN is ACKed by" > - " peer for connected TCB %p\n", Tcb)); > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_FIN_ACKED); > - } > - > - // > - // Transit the state if proper. > - // > - switch (Tcb->State) { > - case TCP_FIN_WAIT_1: > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_FIN_ACKED)) { > - > - TcpSetState (Tcb, TCP_FIN_WAIT_2); > - > - TcpClearAllTimer (Tcb); > - TcpSetTimer (Tcb, TCP_TIMER_FINWAIT2, Tcb->FinWait2Timeout); > - } > - > - case TCP_FIN_WAIT_2: > - > - break; > - > - case TCP_CLOSE_WAIT: > - break; > - > - case TCP_CLOSING: > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_FIN_ACKED)) { > - > - TcpSetState (Tcb, TCP_TIME_WAIT); > - > - TcpClearAllTimer (Tcb); > - > - if (Tcb->TimeWaitTimeout !=3D 0) { > - > - TcpSetTimer (Tcb, TCP_TIMER_2MSL, Tcb->TimeWaitTimeout); > - } else { > - > - DEBUG ((EFI_D_WARN, "Connection closed immediately " > - "because app disables TIME_WAIT timer for %p\n", Tcb)); > - > - TcpClose (Tcb); > - } > - } > - break; > - > - case TCP_LAST_ACK: > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_FIN_ACKED)) { > - > - TcpSetState (Tcb, TCP_CLOSED); > - } > - > - break; > - > - case TCP_TIME_WAIT: > - > - TcpSendAck (Tcb); > - > - if (Tcb->TimeWaitTimeout !=3D 0) { > - > - TcpSetTimer (Tcb, TCP_TIMER_2MSL, Tcb->TimeWaitTimeout); > - } else { > - > - DEBUG ((EFI_D_WARN, "Connection closed immediately " > - "because app disables TIME_WAIT timer for %p\n", Tcb)); > - > - TcpClose (Tcb); > - } > - break; > - > - default: > - break; > - } > - > - // > - // Sixth step: Check the URG bit.update the Urg point > - // if in TCP_CAN_RECV, otherwise, leave the RcvUp intact. > - // > -StepSix: > - > - Tcb->Idle =3D 0; > - TcpSetKeepaliveTimer (Tcb); > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_URG) && > - !TCP_FIN_RCVD (Tcb->State)) > - { > - > - DEBUG ((EFI_D_NET, "TcpInput: received urgent data " > - "from peer for connected TCB %p\n", Tcb)); > - > - Urg =3D Seg->Seq + Seg->Urg; > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RCVD_URG) && > - TCP_SEQ_GT (Urg, Tcb->RcvUp)) { > - > - Tcb->RcvUp =3D Urg; > - } else { > - > - Tcb->RcvUp =3D Urg; > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_URG); > - } > - } > - > - // > - // Seventh step: Process the segment data > - // > - if (Seg->End !=3D Seg->Seq) { > - > - if (TCP_FIN_RCVD (Tcb->State)) { > - > - DEBUG ((EFI_D_WARN, "TcpInput: connection reset because" > - " data is lost for connected TCB %p\n", Tcb)); > - > - goto RESET_THEN_DROP; > - } > - > - if (TCP_LOCAL_CLOSED (Tcb->State) && (Nbuf->TotalSize !=3D 0)) { > - DEBUG ((EFI_D_WARN, "TcpInput: connection reset because" > - " data is lost for connected TCB %p\n", Tcb)); > - > - goto RESET_THEN_DROP; > - } > - > - TcpQueueData (Tcb, Nbuf); > - if (TcpDeliverData (Tcb) =3D=3D -1) { > - goto RESET_THEN_DROP; > - } > - > - if (!IsListEmpty (&Tcb->RcvQue)) { > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - } > - } > - > - // > - // Eighth step: check the FIN. > - // This step is moved to TcpDeliverData. FIN will be > - // processed in sequence there. Check the comments in > - // the beginning of the file header for information. > - // > - > - // > - // Tcb is a new child of the listening Parent, > - // commit it. > - // > - if (Parent !=3D NULL) { > - Tcb->Parent =3D Parent; > - TcpInsertTcb (Tcb); > - } > - > - if ((Tcb->State !=3D TCP_CLOSED) && > - (TcpToSendData (Tcb, 0) =3D=3D 0) && > - (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW) || (Nbuf->TotalSize = !=3D > 0))) { > - > - TcpToSendAck (Tcb); > - } > - > - NetbufFree (Nbuf); > - return 0; > - > -RESET_THEN_DROP: > - TcpSendReset (Tcb, Head, Len, Dst, Src); > - > -DROP_CONNECTION: > - ASSERT ((Tcb !=3D NULL) && (Tcb->Sk !=3D NULL)); > - > - NetbufFree (Nbuf); > - TcpClose (Tcb); > - > - return -1; > - > -SEND_RESET: > - > - TcpSendReset (Tcb, Head, Len, Dst, Src); > - > -DISCARD: > - > - // > - // Tcb is a child of Parent, and it doesn't survive > - // > - DEBUG ((EFI_D_WARN, "Tcp4Input: Discard a packet\n")); > - NetbufFree (Nbuf); > - > - if ((Parent !=3D NULL) && (Tcb !=3D NULL)) { > - > - ASSERT (Tcb->Sk !=3D NULL); > - TcpClose (Tcb); > - } > - > - return 0; > -} > - > - > -/** > - Process the received ICMP error messages for TCP. > - > - @param Nbuf Buffer that contains part of the TCP segment without = IP > header > - truncated from the ICMP error packet. > - @param IcmpErr The ICMP error code interpreted from ICMP error packe= t. > - @param Src Source address of the ICMP error message. > - @param Dst Destination address of the ICMP error message. > - > -**/ > -VOID > -TcpIcmpInput ( > - IN NET_BUF *Nbuf, > - IN UINT8 IcmpErr, > - IN UINT32 Src, > - IN UINT32 Dst > - ) > -{ > - TCP_HEAD *Head; > - TCP_CB *Tcb; > - TCP_SEQNO Seq; > - EFI_STATUS IcmpErrStatus; > - BOOLEAN IcmpErrIsHard; > - BOOLEAN IcmpErrNotify; > - > - if (Nbuf->TotalSize < sizeof (TCP_HEAD)) { > - goto CLEAN_EXIT; > - } > - > - Head =3D (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); > - ASSERT (Head !=3D NULL); > - Tcb =3D TcpLocateTcb ( > - Head->DstPort, > - Dst, > - Head->SrcPort, > - Src, > - FALSE > - ); > - if (Tcb =3D=3D NULL || Tcb->State =3D=3D TCP_CLOSED) { > - > - goto CLEAN_EXIT; > - } > - > - // > - // Validate the sequence number. > - // > - Seq =3D NTOHL (Head->Seq); > - if (!(TCP_SEQ_LEQ (Tcb->SndUna, Seq) && TCP_SEQ_LT (Seq, Tcb->SndNxt))= ) { > - > - goto CLEAN_EXIT; > - } > - > - IcmpErrStatus =3D IpIoGetIcmpErrStatus ( > - IcmpErr, > - IP_VERSION_4, > - &IcmpErrIsHard, > - &IcmpErrNotify > - ); > - > - if (IcmpErrNotify) { > - > - SOCK_ERROR (Tcb->Sk, IcmpErrStatus); > - } > - > - if (IcmpErrIsHard) { > - > - TcpClose (Tcb); > - } > - > -CLEAN_EXIT: > - NetbufFree (Nbuf); > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c > deleted file mode 100644 > index b98d1e783a2f..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Io.c > +++ /dev/null > @@ -1,112 +0,0 @@ > -/** @file > - I/O interfaces between TCP and IpIo. > - > -Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > - > -/** > - Packet receive callback function provided to IP_IO, used to call > - the proper function to handle the packet received by IP. > - > - @param Status Status of the received packet. > - @param IcmpErr ICMP error number. > - @param NetSession Pointer to the net session of this packet. > - @param Pkt Pointer to the recieved packet. > - @param Context Pointer to the context configured in IpIoOpen(), n= ot used > - now. > - > -**/ > -VOID > -EFIAPI > -Tcp4RxCallback ( > - IN EFI_STATUS Status, > - IN UINT8 IcmpErr, > - IN EFI_NET_SESSION_DATA *NetSession, > - IN NET_BUF *Pkt, > - IN VOID *Context OPTIONAL > - ) > -{ > - if (EFI_SUCCESS =3D=3D Status) { > - TcpInput (Pkt, NetSession->Source.Addr[0], NetSession->Dest.Addr[0])= ; > - } else { > - TcpIcmpInput (Pkt, IcmpErr, NetSession->Source.Addr[0], NetSession- > >Dest.Addr[0]); > - } > -} > - > - > -/** > - Send the segment to IP via IpIo function. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the TCP segment to be sent. > - @param Src Source address of the TCP segment. > - @param Dest Destination address of the TCP segment. > - > - @retval 0 The segment was sent out successfully. > - @retval -1 The segment was failed to send. > - > -**/ > -INTN > -TcpSendIpPacket ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf, > - IN UINT32 Src, > - IN UINT32 Dest > - ) > -{ > - EFI_STATUS Status; > - IP_IO *IpIo; > - IP_IO_OVERRIDE Override; > - SOCKET *Sock; > - VOID *IpSender; > - TCP4_PROTO_DATA *TcpProto; > - EFI_IP_ADDRESS Source; > - EFI_IP_ADDRESS Destination; > - > - Source.Addr[0] =3D Src; > - Destination.Addr[0] =3D Dest; > - > - if (NULL =3D=3D Tcb) { > - > - IpIo =3D NULL; > - IpSender =3D IpIoFindSender (&IpIo, IP_VERSION_4, &Source); > - > - if (IpSender =3D=3D NULL) { > - DEBUG ((EFI_D_WARN, "TcpSendIpPacket: No appropriate IpSender.\n")= ); > - return -1; > - } > - } else { > - > - Sock =3D Tcb->Sk; > - TcpProto =3D (TCP4_PROTO_DATA *) Sock->ProtoReserved; > - IpIo =3D TcpProto->TcpService->IpIo; > - IpSender =3D Tcb->IpInfo; > - } > - > - Override.Ip4OverrideData.TypeOfService =3D 0; > - Override.Ip4OverrideData.TimeToLive =3D 255; > - Override.Ip4OverrideData.DoNotFragment =3D FALSE; > - Override.Ip4OverrideData.Protocol =3D EFI_IP_PROTO_TCP= ; > - ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof > (EFI_IPv4_ADDRESS)); > - CopyMem (&Override.Ip4OverrideData.SourceAddress, &Src, sizeof > (EFI_IPv4_ADDRESS)); > - > - Status =3D IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, &Destination, &= Override); > - > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "TcpSendIpPacket: return %r error\n", Status)); > - return -1; > - } > - > - return 0; > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c > deleted file mode 100644 > index d8fc68c0a97d..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c > +++ /dev/null > @@ -1,674 +0,0 @@ > -/** @file > - Implementation of TCP4 protocol services. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > - > -#include "Tcp4Main.h" > - > - > -/** > - Check the integrity of the data buffer. > - > - @param DataLen The total length of the data buffer. > - @param FragmentCount The fragment count of the fragment ta= ble. > - @param FragmentTable Pointer to the fragment table of the = data > - buffer. > - > - @retval EFI_SUCCESS The integrity check is passed. > - @retval EFI_INVALID_PARAMETER The integrity check is failed. > - > -**/ > -EFI_STATUS > -Tcp4ChkDataBuf ( > - IN UINT32 DataLen, > - IN UINT32 FragmentCount, > - IN EFI_TCP4_FRAGMENT_DATA *FragmentTable > - ) > -{ > - UINT32 Index; > - > - UINT32 Len; > - > - for (Index =3D 0, Len =3D 0; Index < FragmentCount; Index++) { > - Len =3D Len + (UINT32) FragmentTable[Index].FragmentLength; > - } > - > - if (DataLen !=3D Len) { > - return EFI_INVALID_PARAMETER; > - } > - > - return EFI_SUCCESS; > -} > - > - > -/** > - Get the current operational status. > - > - The GetModeData() function copies the current operational settings of = this > - EFI TCPv4 Protocol instance into user-supplied buffers. This function = can > - also be used to retrieve the operational setting of underlying drivers > - such as IPv4, MNP, or SNP. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param Tcp4State Pointer to the buffer to receive the = current TCP > - state. > - @param Tcp4ConfigData Pointer to the buffer to receive the = current > TCP > - configuration. > - @param Ip4ModeData Pointer to the buffer to receive the = current > IPv4 > - configuration data used by the TCPv4 = instance. > - @param MnpConfigData Pointer to the buffer to receive the = current > MNP > - configuration data indirectly used by= the TCPv4 > - Instance. > - @param SnpModeData Pointer to the buffer to receive the = current > SNP > - configuration data indirectly used by= the TCPv4 > - Instance. > - > - @retval EFI_SUCCESS The mode data was read. > - @retval EFI_NOT_STARTED No configuration data is available be= cause > this > - instance hasn't been started. > - @retval EFI_INVALID_PARAMETER This is NULL. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4GetModeData ( > - IN EFI_TCP4_PROTOCOL *This, > - OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL, > - OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL, > - OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL, > - OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData > OPTIONAL, > - OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL > - ) > -{ > - TCP4_MODE_DATA TcpMode; > - SOCKET *Sock; > - > - if (NULL =3D=3D This) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - TcpMode.Tcp4State =3D Tcp4State; > - TcpMode.Tcp4ConfigData =3D Tcp4ConfigData; > - TcpMode.Ip4ModeData =3D Ip4ModeData; > - TcpMode.MnpConfigData =3D MnpConfigData; > - TcpMode.SnpModeData =3D SnpModeData; > - > - return SockGetMode (Sock, &TcpMode); > -} > - > - > -/** > - Initialize or brutally reset the operational parameters for > - this EFI TCPv4 instance. > - > - The Configure() function does the following: > - * Initialize this EFI TCPv4 instance, i.e., initialize the communicati= on end > - setting, specify active open or passive open for an instance. > - * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchr= onous > - tokens, flush transmission and receiving buffer directly without infor= ming > - the communication peer. > - No other TCPv4 Protocol operation can be executed by this instance > - until it is configured properly. For an active TCP4 instance, after a = proper > - configuration it may call Connect() to initiates the three-way handsha= ke. > - For a passive TCP4 instance, its state will transit to Tcp4StateListen= after > - configuration, and Accept() may be called to listen the incoming TCP > connection > - request. If TcpConfigData is set to NULL, the instance is reset. Reset= ting > - process will be done brutally, the state machine will be set to Tcp4St= ateClosed > - directly, the receive queue and transmit queue will be flushed, and no= traffic is > - allowed through this instance. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param TcpConfigData Pointer to the configure data to conf= igure the > - instance. > - > - @retval EFI_SUCCESS The operational settings are set, cha= nged, or > - reset successfully. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (through DHCP, BOOTP, RARP, etc.) is = not > - finished. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_ACCESS_DENIED Configuring TCP instance when it is a= lready > - configured. > - @retval EFI_DEVICE_ERROR An unexpected network or system error > occurred. > - @retval EFI_UNSUPPORTED One or more of the control options ar= e not > - supported in the implementation. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough system > resources. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Configure ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL > - ) > -{ > - EFI_TCP4_OPTION *Option; > - SOCKET *Sock; > - EFI_STATUS Status; > - IP4_ADDR Ip; > - IP4_ADDR SubnetMask; > - > - if (NULL =3D=3D This) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Tcp protocol related parameter check will be conducted here > - // > - if (NULL !=3D TcpConfigData) { > - > - CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof > (IP4_ADDR)); > - if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) { > - return EFI_INVALID_PARAMETER; > - } > - > - if (TcpConfigData->AccessPoint.ActiveFlag && > - (0 =3D=3D TcpConfigData->AccessPoint.RemotePort || (Ip =3D=3D 0)))= { > - return EFI_INVALID_PARAMETER; > - } > - > - if (!TcpConfigData->AccessPoint.UseDefaultAddress) { > - > - CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof > (IP4_ADDR)); > - CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, > sizeof (IP4_ADDR)); > - if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) || > - (SubnetMask !=3D 0 && !NetIp4IsUnicast (NTOHL (Ip), NTOHL > (SubnetMask)))) { > - return EFI_INVALID_PARAMETER; > - } > - } > - > - Option =3D TcpConfigData->ControlOption; > - if ((NULL !=3D Option) && > - (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) = { > - return EFI_UNSUPPORTED; > - } > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - if (NULL =3D=3D TcpConfigData) { > - return SockFlush (Sock); > - } > - > - Status =3D SockConfigure (Sock, TcpConfigData); > - > - if (EFI_NO_MAPPING =3D=3D Status) { > - Sock->ConfigureState =3D SO_NO_MAPPING; > - } > - > - return Status; > -} > - > - > -/** > - Add or delete routing entries. > - > - The Routes() function adds or deletes a route from the instance's rout= ing table. > - The most specific route is selected by comparing the SubnetAddress wit= h the > - destination IP address's arithmetical AND to the SubnetMask. > - The default route is added with both SubnetAddress and SubnetMask set = to > 0.0.0.0. > - The default route matches all destination IP addresses if there is no = more > specific route. > - Direct route is added with GatewayAddress set to 0.0.0.0. Packets are = sent to > - the destination host if its address can be found in the Address Resolu= tion > Protocol (ARP) > - cache or it is on the local subnet. If the instance is configured to u= se default > - address, a direct route to the local network will be added automatical= ly. > - Each TCP instance has its own independent routing table. Instance that= uses > the > - default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's > routing table. > - The copy will be updated automatically whenever the IP driver reconfig= ures its > - instance. As a result, the previous modification to the instance's loc= al copy > - will be lost. The priority of checking the route table is specific wit= h IP > - implementation and every IP implementation must comply with RFC 1122. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param DeleteRoute If TRUE, delete the specified route f= rom routing > - table; if FALSE, add the specified ro= ute to > - routing table. > - DestinationAddress and SubnetMask are= used as > - the keywords to search route entry. > - @param SubnetAddress The destination network. > - @param SubnetMask The subnet mask for the destination n= etwork. > - @param GatewayAddress The gateway address for this route. > - It must be on the same subnet with th= e station > - address unless a direct route is spec= ified. > - > - @retval EFI_SUCCESS The operation completed successfully. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has no= t > been > - configured. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (through DHCP, BOOTP, RARP, etc.) is = not > - finished. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources t= o > add the > - entry to the routing table. > - @retval EFI_NOT_FOUND This route is not in the routing tabl= e. > - @retval EFI_ACCESS_DENIED This route is already in the routing = table. > - @retval EFI_UNSUPPORTED The TCP driver does not support this > operation. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Routes ( > - IN EFI_TCP4_PROTOCOL *This, > - IN BOOLEAN DeleteRoute, > - IN EFI_IPv4_ADDRESS *SubnetAddress, > - IN EFI_IPv4_ADDRESS *SubnetMask, > - IN EFI_IPv4_ADDRESS *GatewayAddress > - ) > -{ > - SOCKET *Sock; > - TCP4_ROUTE_INFO RouteInfo; > - > - if (NULL =3D=3D This) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - RouteInfo.DeleteRoute =3D DeleteRoute; > - RouteInfo.SubnetAddress =3D SubnetAddress; > - RouteInfo.SubnetMask =3D SubnetMask; > - RouteInfo.GatewayAddress =3D GatewayAddress; > - > - return SockRoute (Sock, &RouteInfo); > -} > - > - > -/** > - Initiate a nonblocking TCP connection request for an active TCP instan= ce. > - > - The Connect() function will initiate an active open to the remote peer > configured > - in current TCP instance if it is configured active. If the connection = succeeds > - or fails due to any error, the ConnectionToken->CompletionToken.Event = will > be > - signaled and ConnectionToken->CompletionToken.Status will be updated > accordingly. > - This function can only be called for the TCP instance in Tcp4StateClos= ed state. > - The instance will transfer into Tcp4StateSynSent if the function retur= ns > EFI_SUCCESS. > - If TCP three way handshake succeeds, its state will become > Tcp4StateEstablished, > - otherwise, the state will return to Tcp4StateClosed. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance > - @param ConnectionToken Pointer to the connection token to re= turn > when > - the TCP three way handshake finishes. > - > - @retval EFI_SUCCESS The connection request is successfull= y initiated > - and the state of this TCPv4 instance = has > - been changed to Tcp4StateSynSent. > - @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn'= t > been > - configured. > - @retval EFI_ACCESS_DENIED The instance is not configured as an = active > one > - or it is not in Tcp4StateClosed state= . > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough > resource to > - initiate the active open. > - @retval EFI_DEVICE_ERROR An unexpected system or network error > occurred. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Connect ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken > - ) > -{ > - SOCKET *Sock; > - > - if (NULL =3D=3D This || > - NULL =3D=3D ConnectionToken || > - NULL =3D=3D ConnectionToken->CompletionToken.Event) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - return SockConnect (Sock, ConnectionToken); > -} > - > - > -/** > - Listen on the passive instance to accept an incoming connection reques= t. > - > - The Accept() function initiates an asynchronous accept request to wait= for an > - incoming connection on the passive TCP instance. If a remote peer > successfully > - establishes a connection with this instance, a new TCP instance will b= e created > - and its handle will be returned in ListenToken->NewChildHandle. The ne= wly > created > - instance is configured by inheriting the passive instance's configurat= ion and is > - ready for use upon return. The instance is in the Tcp4StateEstablished= state. > - The ListenToken->CompletionToken.Event will be signaled when a new > connection > - is accepted, user aborts the listen or connection is reset. This funct= ion only > - can be called when current TCP instance is in Tcp4StateListen state. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance > - @param ListenToken Pointer to the listen token to return= when > - operation finishes. > - > - @retval EFI_SUCCESS The listen token has been queued succ= essfully. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_ACCESS_DENIED The instatnce is not a passive one or= it is not > - in Tcp4StateListen state or a same li= sten token > - has already existed in the listen tok= en queue of > - this TCP instance. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources t= o > finish > - the operation. > - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to ab= ove > category error. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Accept ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_LISTEN_TOKEN *ListenToken > - ) > -{ > - SOCKET *Sock; > - > - if (NULL =3D=3D This || > - NULL =3D=3D ListenToken || > - NULL =3D=3D ListenToken->CompletionToken.Event) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - return SockAccept (Sock, ListenToken); > -} > - > - > -/** > - Queues outgoing data into the transmit queue. > - > - The Transmit() function queues a sending request to this TCPv4 instanc= e along > - with the user data. The status of the token is updated and the event i= n the > token > - will be signaled once the data is sent out or some error occurs. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance > - @param Token Pointer to the completion token to qu= eue to the > - transmit queue > - > - @retval EFI_SUCCESS The data has been queued for transmis= sion. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (DHCP, BOOTP, RARP, etc.) is not fini= shed yet. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_ACCESS_DENIED One or more of the following conditio= ns is > TRUE: > - * A transmit completion token with th= e same > - Token-> CompletionToken.Event was a= lready in the > - transmission queue. > - * The current instance is in Tcp4Stat= eClosed state > - * The current instance is a passive o= ne and > - it is in Tcp4StateListen state. > - * User has called Close() to disconne= ct this > - connection. > - @retval EFI_NOT_READY The completion token could not be que= ued > because > - the transmit queue is full. > - @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data > because of > - resource shortage. > - @retval EFI_NETWORK_UNREACHABLE There is no route to the destination > network or > - address. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Transmit ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_IO_TOKEN *Token > - ) > -{ > - SOCKET *Sock; > - EFI_STATUS Status; > - > - if (NULL =3D=3D This || > - NULL =3D=3D Token || > - NULL =3D=3D Token->CompletionToken.Event || > - NULL =3D=3D Token->Packet.TxData || > - 0 =3D=3D Token->Packet.TxData->FragmentCount || > - 0 =3D=3D Token->Packet.TxData->DataLength > - ) { > - return EFI_INVALID_PARAMETER; > - } > - > - Status =3D Tcp4ChkDataBuf ( > - (UINT32) Token->Packet.TxData->DataLength, > - (UINT32) Token->Packet.TxData->FragmentCount, > - Token->Packet.TxData->FragmentTable > - ); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - return SockSend (Sock, Token); > - > -} > - > - > -/** > - Place an asynchronous receive request into the receiving queue. > - > - The Receive() function places a completion token into the receive pack= et > queue. > - This function is always asynchronous. The caller must allocate the > - Token->CompletionToken.Event and the FragmentBuffer used to receive da= ta. > He also > - must fill the DataLength which represents the whole length of all > FragmentBuffer. > - When the receive operation completes, the EFI TCPv4 Protocol driver up= dates > the > - Token->CompletionToken.Status and Token->Packet.RxData fields and the > - Token->CompletionToken.Event is signaled. If got data the data and its= length > - will be copy into the FragmentTable, in the same time the full length = of > received > - data will be recorded in the DataLength fields. Providing a proper not= ification > - function and context for the event will enable the user to receive the > notification > - and receiving status. That notification function is guaranteed to not = be re- > entered. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param Token Pointer to a token that is associated= with the > - receive data descriptor. > - > - @retval EFI_SUCCESS The receive completion token was cach= ed. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (DHCP, BOOTP, RARP, etc.) is not fini= shed yet. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES The receive completion token could no= t > be queued > - due to a lack of system resources. > - @retval EFI_DEVICE_ERROR An unexpected system or network error > occurred. > - The EFI TCPv4 Protocol instance has b= een reset > - to startup defaults. > - @retval EFI_ACCESS_DENIED One or more of the following conditio= ns is > TRUE: > - * A receive completion token with the= same > - Token->CompletionToken.Event was al= ready in > - the receive queue. > - * The current instance is in Tcp4Stat= eClosed state. > - * The current instance is a passive o= ne and it > - is in Tcp4StateListen state. > - * User has called Close() to disconne= ct this > - connection. > - @retval EFI_CONNECTION_FIN The communication peer has closed the > connection > - and there is no any buffered data in = the receive > - buffer of this instance. > - @retval EFI_NOT_READY The receive request could not be queu= ed > because > - the receive queue is full. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Receive ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_IO_TOKEN *Token > - ) > -{ > - SOCKET *Sock; > - EFI_STATUS Status; > - > - if (NULL =3D=3D This || > - NULL =3D=3D Token || > - NULL =3D=3D Token->CompletionToken.Event || > - NULL =3D=3D Token->Packet.RxData || > - 0 =3D=3D Token->Packet.RxData->FragmentCount || > - 0 =3D=3D Token->Packet.RxData->DataLength > - ) { > - return EFI_INVALID_PARAMETER; > - } > - > - Status =3D Tcp4ChkDataBuf ( > - (UINT32) Token->Packet.RxData->DataLength, > - (UINT32) Token->Packet.RxData->FragmentCount, > - Token->Packet.RxData->FragmentTable > - ); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - return SockRcv (Sock, Token); > - > -} > - > - > -/** > - Disconnecting a TCP connection gracefully or reset a TCP connection. > - > - Initiate an asynchronous close token to TCP driver. After Close() is c= alled, > - any buffered transmission data will be sent by TCP driver and the curr= ent > - instance will have a graceful close working flow described as RFC 793 = if > - AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by= TCP > - driver to fast disconnect this connection. When the close operation co= mpletes > - successfully the TCP instance is in Tcp4StateClosed state, all pending > - asynchronous operation is signaled and any buffers used for TCP networ= k > traffic > - is flushed. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param CloseToken Pointer to the close token to return = when > - operation finishes. > - > - @retval EFI_SUCCESS The operation completed successfully. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_ACCESS_DENIED One or more of the following are TRUE= : > - * Configure() has been called with Tc= pConfigData > - set to NULL and this function has n= ot returned. > - * Previous Close() call on this insta= nce has not > - finished. > - @retval EFI_INVALID_PARAMETER One ore more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to > finish the > - operation. > - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to ab= ove > - category error. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Close ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_CLOSE_TOKEN *CloseToken > - ) > -{ > - SOCKET *Sock; > - > - if (NULL =3D=3D This || > - NULL =3D=3D CloseToken || > - NULL =3D=3D CloseToken->CompletionToken.Event) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - return SockClose (Sock, CloseToken, CloseToken->AbortOnClose); > -} > - > - > -/** > - Abort an asynchronous connection, listen, transmission or receive requ= est. > - > - The Cancel() function aborts a pending connection, listen, transmit or= receive > - request. If Token is not NULL and the token is in the connection, list= en, > - transmission or receive queue when it is being cancelled, its Token->S= tatus > - will be set to EFI_ABORTED and then Token->Event will be signaled. If = the > token > - is not in one of the queues, which usually means that the asynchronous > operation > - has completed, EFI_NOT_FOUND is returned. If Token is NULL all > asynchronous token > - issued by Connect(), Accept(), Transmit() and Receive()will be aborted= . > - NOTE: It has not been implemented currently. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param Token Pointer to a token that has been issu= ed by > - Connect(), Accept(), Transmit() or Re= ceive(). If > - NULL, all pending tokens issued by ab= ove four > - functions will be aborted. > - > - @retval EFI_SUCCESS The asynchronous I/O request is abort= ed and > Token->Event > - is signaled. > - @retval EFI_INVALID_PARAMETER This is NULL. > - @retval EFI_NOT_STARTED This instance hasn's been configured. > - @retval EFI_NO_MAPPING When using the default address, > configuration > - (DHCP, BOOTP,RARP, etc.) hasn's finis= hed yet. > - @retval EFI_NOT_FOUND The asynchronous I/O request isn's fo= und in > the > - transmission or receive queue. It has= either > - completed or wasn's issued by Transmi= t() and Receive(). > - @retval EFI_UNSUPPORTED The operation is not supported in cur= rent > - implementation. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Cancel ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL > - ) > -{ > - return EFI_UNSUPPORTED; > -} > - > - > -/** > - Poll to receive incoming data and transmit outgoing segments. > - > - The Poll() function increases the rate that data is moved between the = network > - and application and can be called when the TCP instance is created > successfully. > - Its use is optional. In some implementations, the periodical timer in = the MNP > - driver may not poll the underlying communications device fast enough t= o > avoid > - drop packets. Drivers and applications that are experiencing packet lo= ss should > - try calling the Poll() function in a high frequency. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - > - @retval EFI_SUCCESS Incoming or outgoing data was process= ed. > - @retval EFI_INVALID_PARAMETER This is NULL. > - @retval EFI_DEVICE_ERROR An unexpected system or network error > occurred. > - @retval EFI_NOT_READY No incoming or outgoing data was proc= essed. > - @retval EFI_TIMEOUT Data was dropped out of the transmiss= ion or > - receive queue. Consider increasing th= e polling > - rate. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Poll ( > - IN EFI_TCP4_PROTOCOL *This > - ) > -{ > - SOCKET *Sock; > - EFI_STATUS Status; > - > - if (NULL =3D=3D This) { > - return EFI_INVALID_PARAMETER; > - } > - > - Sock =3D SOCK_FROM_THIS (This); > - > - Status =3D Sock->ProtoHandler (Sock, SOCK_POLL, NULL); > - > - return Status; > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c > deleted file mode 100644 > index 7fd8bb1fbe09..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c > +++ /dev/null > @@ -1,940 +0,0 @@ > -/** @file > - Misc support routines for tcp. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > - > -#include "Tcp4Main.h" > - > -#include > - > -LIST_ENTRY mTcpRunQue =3D { > - &mTcpRunQue, > - &mTcpRunQue > -}; > - > -LIST_ENTRY mTcpListenQue =3D { > - &mTcpListenQue, > - &mTcpListenQue > -}; > - > -TCP_SEQNO mTcpGlobalIss =3D 0x4d7e980b; > - > -CHAR16 *mTcpStateName[] =3D { > - L"TCP_CLOSED", > - L"TCP_LISTEN", > - L"TCP_SYN_SENT", > - L"TCP_SYN_RCVD", > - L"TCP_ESTABLISHED", > - L"TCP_FIN_WAIT_1", > - L"TCP_FIN_WAIT_2", > - L"TCP_CLOSING", > - L"TCP_TIME_WAIT", > - L"TCP_CLOSE_WAIT", > - L"TCP_LAST_ACK" > -}; > - > - > -/** > - Initialize the Tcb local related members. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > -**/ > -VOID > -TcpInitTcbLocal ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - // > - // Compute the checksum of the fixed parts of pseudo header > - // > - Tcb->HeadSum =3D NetPseudoHeadChecksum ( > - Tcb->LocalEnd.Ip, > - Tcb->RemoteEnd.Ip, > - 0x06, > - 0 > - ); > - > - Tcb->Iss =3D TcpGetIss (); > - Tcb->SndUna =3D Tcb->Iss; > - Tcb->SndNxt =3D Tcb->Iss; > - > - Tcb->SndWl2 =3D Tcb->Iss; > - Tcb->SndWnd =3D 536; > - > - Tcb->RcvWnd =3D GET_RCV_BUFFSIZE (Tcb->Sk); > - > - // > - // First window size is never scaled > - // > - Tcb->RcvWndScale =3D 0; > - Tcb->RetxmitSeqMax =3D 0; > - > - Tcb->ProbeTimerOn =3D FALSE; > -} > - > - > -/** > - Initialize the peer related members. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param Seg Pointer to the segment that contains the= peer's > - intial info. > - @param Opt Pointer to the options announced by the = peer. > - > -**/ > -VOID > -TcpInitTcbPeer ( > - IN OUT TCP_CB *Tcb, > - IN TCP_SEG *Seg, > - IN TCP_OPTION *Opt > - ) > -{ > - UINT16 RcvMss; > - > - ASSERT ((Tcb !=3D NULL) && (Seg !=3D NULL) && (Opt !=3D NULL)); > - ASSERT (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)); > - > - Tcb->SndWnd =3D Seg->Wnd; > - Tcb->SndWndMax =3D Tcb->SndWnd; > - Tcb->SndWl1 =3D Seg->Seq; > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_ACK)) { > - Tcb->SndWl2 =3D Seg->Ack; > - } else { > - Tcb->SndWl2 =3D Tcb->Iss + 1; > - } > - > - if (TCP_FLG_ON (Opt->Flag, TCP_OPTION_RCVD_MSS)) { > - Tcb->SndMss =3D (UINT16) MAX (64, Opt->Mss); > - > - RcvMss =3D TcpGetRcvMss (Tcb->Sk); > - if (Tcb->SndMss > RcvMss) { > - Tcb->SndMss =3D RcvMss; > - } > - > - } else { > - // > - // One end doesn't support MSS option, use default. > - // > - Tcb->RcvMss =3D 536; > - } > - > - Tcb->CWnd =3D Tcb->SndMss; > - > - Tcb->Irs =3D Seg->Seq; > - Tcb->RcvNxt =3D Tcb->Irs + 1; > - > - Tcb->RcvWl2 =3D Tcb->RcvNxt; > - > - if (TCP_FLG_ON (Opt->Flag, TCP_OPTION_RCVD_WS) && > - !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_WS)) { > - > - Tcb->SndWndScale =3D Opt->WndScale; > - > - Tcb->RcvWndScale =3D TcpComputeScale (Tcb); > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_WS); > - > - } else { > - // > - // One end doesn't support window scale option. use zero. > - // > - Tcb->RcvWndScale =3D 0; > - } > - > - if (TCP_FLG_ON (Opt->Flag, TCP_OPTION_RCVD_TS) && > - !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_TS)) { > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_TS); > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_TS); > - > - Tcb->TsRecent =3D Opt->TSVal; > - > - // > - // Compute the effective SndMss per RFC1122 > - // section 4.2.2.6. If timestamp option is > - // enabled, it will always occupy 12 bytes. > - // > - Tcb->SndMss -=3D TCP_OPTION_TS_ALIGNED_LEN; > - } > -} > - > - > -/** > - Locate a listen TCB that matchs the Local and Remote. > - > - @param Local Pointer to the local (IP, Port). > - @param Remote Pointer to the remote (IP, Port). > - > - @return Pointer to the TCP_CB with the least number of wildcard, > - if NULL no match is found. > - > -**/ > -TCP_CB * > -TcpLocateListenTcb ( > - IN TCP_PEER *Local, > - IN TCP_PEER *Remote > - ) > -{ > - LIST_ENTRY *Entry; > - TCP_CB *Node; > - TCP_CB *Match; > - INTN Last; > - INTN Cur; > - > - Last =3D 4; > - Match =3D NULL; > - > - NET_LIST_FOR_EACH (Entry, &mTcpListenQue) { > - Node =3D NET_LIST_USER_STRUCT (Entry, TCP_CB, List); > - > - if ((Local->Port !=3D Node->LocalEnd.Port) || > - !TCP_PEER_MATCH (Remote, &Node->RemoteEnd) || > - !TCP_PEER_MATCH (Local, &Node->LocalEnd)) { > - > - continue; > - } > - > - // > - // Compute the number of wildcard > - // > - Cur =3D 0; > - if (Node->RemoteEnd.Ip =3D=3D 0) { > - Cur++; > - } > - > - if (Node->RemoteEnd.Port =3D=3D 0) { > - Cur++; > - } > - > - if (Node->LocalEnd.Ip =3D=3D 0) { > - Cur++; > - } > - > - if (Cur < Last) { > - if (Cur =3D=3D 0) { > - return Node; > - } > - > - Last =3D Cur; > - Match =3D Node; > - } > - } > - > - return Match; > -} > - > - > -/** > - Try to find one Tcb whose equals to . > - > - @param Addr Pointer to the IP address needs to match= . > - @param Port The port number needs to match. > - > - @return The Tcb which matches the paire exists or not. > - > -**/ > -BOOLEAN > -TcpFindTcbByPeer ( > - IN EFI_IPv4_ADDRESS *Addr, > - IN TCP_PORTNO Port > - ) > -{ > - TCP_PORTNO LocalPort; > - LIST_ENTRY *Entry; > - TCP_CB *Tcb; > - > - ASSERT ((Addr !=3D NULL) && (Port !=3D 0)); > - > - LocalPort =3D HTONS (Port); > - > - NET_LIST_FOR_EACH (Entry, &mTcpListenQue) { > - Tcb =3D NET_LIST_USER_STRUCT (Entry, TCP_CB, List); > - > - if (EFI_IP4_EQUAL (Addr, &Tcb->LocalEnd.Ip) && > - (LocalPort =3D=3D Tcb->LocalEnd.Port)) { > - > - return TRUE; > - } > - } > - > - NET_LIST_FOR_EACH (Entry, &mTcpRunQue) { > - Tcb =3D NET_LIST_USER_STRUCT (Entry, TCP_CB, List); > - > - if (EFI_IP4_EQUAL (Addr, &Tcb->LocalEnd.Ip) && > - (LocalPort =3D=3D Tcb->LocalEnd.Port)) { > - > - return TRUE; > - } > - } > - > - return FALSE; > -} > - > - > -/** > - Locate the TCP_CB related to the socket pair. > - > - @param LocalPort The local port number. > - @param LocalIp The local IP address. > - @param RemotePort The remote port number. > - @param RemoteIp The remote IP address. > - @param Syn Whether to search the listen sockets, if= TRUE, the > - listen sockets are searched. > - > - @return Pointer to the related TCP_CB, if NULL no match is found. > - > -**/ > -TCP_CB * > -TcpLocateTcb ( > - IN TCP_PORTNO LocalPort, > - IN UINT32 LocalIp, > - IN TCP_PORTNO RemotePort, > - IN UINT32 RemoteIp, > - IN BOOLEAN Syn > - ) > -{ > - TCP_PEER Local; > - TCP_PEER Remote; > - LIST_ENTRY *Entry; > - TCP_CB *Tcb; > - > - Local.Port =3D LocalPort; > - Local.Ip =3D LocalIp; > - > - Remote.Port =3D RemotePort; > - Remote.Ip =3D RemoteIp; > - > - // > - // First check for exact match. > - // > - NET_LIST_FOR_EACH (Entry, &mTcpRunQue) { > - Tcb =3D NET_LIST_USER_STRUCT (Entry, TCP_CB, List); > - > - if (TCP_PEER_EQUAL (&Remote, &Tcb->RemoteEnd) && > - TCP_PEER_EQUAL (&Local, &Tcb->LocalEnd)) { > - > - RemoveEntryList (&Tcb->List); > - InsertHeadList (&mTcpRunQue, &Tcb->List); > - > - return Tcb; > - } > - } > - > - // > - // Only check listen queue when SYN flag is on > - // > - if (Syn) { > - return TcpLocateListenTcb (&Local, &Remote); > - } > - > - return NULL; > -} > - > - > -/** > - Insert a Tcb into the proper queue. > - > - @param Tcb Pointer to the TCP_CB to be inserted. > - > - @retval 0 The Tcb is inserted successfully. > - @retval -1 Error condition occurred. > - > -**/ > -INTN > -TcpInsertTcb ( > - IN TCP_CB *Tcb > - ) > -{ > - LIST_ENTRY *Entry; > - LIST_ENTRY *Head; > - TCP_CB *Node; > - > - ASSERT ( > - (Tcb !=3D NULL) && > - ((Tcb->State =3D=3D TCP_LISTEN) || > - (Tcb->State =3D=3D TCP_SYN_SENT) || > - (Tcb->State =3D=3D TCP_SYN_RCVD) || > - (Tcb->State =3D=3D TCP_CLOSED)) > - ); > - > - if (Tcb->LocalEnd.Port =3D=3D 0) { > - return -1; > - } > - > - Head =3D &mTcpRunQue; > - > - if (Tcb->State =3D=3D TCP_LISTEN) { > - Head =3D &mTcpListenQue; > - } > - > - // > - // Check that Tcb isn't already on the list. > - // > - NET_LIST_FOR_EACH (Entry, Head) { > - Node =3D NET_LIST_USER_STRUCT (Entry, TCP_CB, List); > - > - if (TCP_PEER_EQUAL (&Tcb->LocalEnd, &Node->LocalEnd) && > - TCP_PEER_EQUAL (&Tcb->RemoteEnd, &Node->RemoteEnd)) { > - > - return -1; > - } > - } > - > - InsertHeadList (Head, &Tcb->List); > - > - return 0; > -} > - > - > -/** > - Clone a TCB_CB from Tcb. > - > - @param Tcb Pointer to the TCP_CB to be cloned. > - > - @return Pointer to the new cloned TCP_CB, if NULL error condition occ= urred. > - > -**/ > -TCP_CB * > -TcpCloneTcb ( > - IN TCP_CB *Tcb > - ) > -{ > - TCP_CB *Clone; > - > - Clone =3D AllocatePool (sizeof (TCP_CB)); > - > - if (Clone =3D=3D NULL) { > - return NULL; > - > - } > - > - CopyMem (Clone, Tcb, sizeof (TCP_CB)); > - > - // > - // Increate the reference count of the shared IpInfo. > - // > - NET_GET_REF (Tcb->IpInfo); > - > - InitializeListHead (&Clone->List); > - InitializeListHead (&Clone->SndQue); > - InitializeListHead (&Clone->RcvQue); > - > - Clone->Sk =3D SockClone (Tcb->Sk); > - if (Clone->Sk =3D=3D NULL) { > - DEBUG ((EFI_D_ERROR, "TcpCloneTcb: failed to clone a sock\n")); > - FreePool (Clone); > - return NULL; > - } > - > - ((TCP4_PROTO_DATA *) (Clone->Sk->ProtoReserved))->TcpPcb =3D Clone; > - > - return Clone; > -} > - > - > -/** > - Compute an ISS to be used by a new connection. > - > - @return The result ISS. > - > -**/ > -TCP_SEQNO > -TcpGetIss ( > - VOID > - ) > -{ > - mTcpGlobalIss +=3D 2048; > - return mTcpGlobalIss; > -} > - > - > -/** > - Get the local mss. > - > - @param Sock Pointer to the socket to get mss > - > - @return The mss size. > - > -**/ > -UINT16 > -TcpGetRcvMss ( > - IN SOCKET *Sock > - ) > -{ > - EFI_IP4_MODE_DATA Ip4Mode; > - TCP4_PROTO_DATA *TcpProto; > - EFI_IP4_PROTOCOL *Ip; > - > - ASSERT (Sock !=3D NULL); > - > - TcpProto =3D (TCP4_PROTO_DATA *) Sock->ProtoReserved; > - Ip =3D TcpProto->TcpService->IpIo->Ip.Ip4; > - ASSERT (Ip !=3D NULL); > - > - Ip->GetModeData (Ip, &Ip4Mode, NULL, NULL); > - > - return (UINT16) (Ip4Mode.MaxPacketSize - sizeof (TCP_HEAD)); > -} > - > - > -/** > - Set the Tcb's state. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param State The state to be set. > - > -**/ > -VOID > -TcpSetState ( > - IN OUT TCP_CB *Tcb, > - IN UINT8 State > - ) > -{ > - ASSERT (Tcb->State < (sizeof (mTcpStateName) / sizeof (CHAR16 *))); > - ASSERT (State < (sizeof (mTcpStateName) / sizeof (CHAR16 *))); > - > - DEBUG ( > - (EFI_D_NET, > - "Tcb (%p) state %s --> %s\n", > - Tcb, > - mTcpStateName[Tcb->State], > - mTcpStateName[State]) > - ); > - > - Tcb->State =3D State; > - > - switch (State) { > - case TCP_ESTABLISHED: > - > - SockConnEstablished (Tcb->Sk); > - > - if (Tcb->Parent !=3D NULL) { > - // > - // A new connection is accepted by a listening socket, install > - // the device path. > - // > - TcpInstallDevicePath (Tcb->Sk); > - } > - > - break; > - > - case TCP_CLOSED: > - > - SockConnClosed (Tcb->Sk); > - > - break; > - default: > - break; > - } > -} > - > - > -/** > - Compute the TCP segment's checksum. > - > - @param Nbuf Pointer to the buffer that contains the = TCP > - segment. > - @param HeadSum The checksum value of the fixed part of = pseudo > - header. > - > - @return The checksum value. > - > -**/ > -UINT16 > -TcpChecksum ( > - IN NET_BUF *Nbuf, > - IN UINT16 HeadSum > - ) > -{ > - UINT16 Checksum; > - > - Checksum =3D NetbufChecksum (Nbuf); > - Checksum =3D NetAddChecksum (Checksum, HeadSum); > - > - Checksum =3D NetAddChecksum ( > - Checksum, > - HTONS ((UINT16) Nbuf->TotalSize) > - ); > - > - return (UINT16) ~Checksum; > -} > - > -/** > - Translate the information from the head of the received TCP > - segment Nbuf contains and fill it into a TCP_SEG structure. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param Nbuf Pointer to the buffer contains the TCP s= egment. > - > - @return Pointer to the TCP_SEG that contains the translated TCP head > information. > - > -**/ > -TCP_SEG * > -TcpFormatNetbuf ( > - IN TCP_CB *Tcb, > - IN OUT NET_BUF *Nbuf > - ) > -{ > - TCP_SEG *Seg; > - TCP_HEAD *Head; > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - Head =3D (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); > - ASSERT (Head !=3D NULL); > - Nbuf->Tcp =3D Head; > - > - Seg->Seq =3D NTOHL (Head->Seq); > - Seg->Ack =3D NTOHL (Head->Ack); > - Seg->End =3D Seg->Seq + (Nbuf->TotalSize - (Head->HeadLen << 2)); > - > - Seg->Urg =3D NTOHS (Head->Urg); > - Seg->Wnd =3D (NTOHS (Head->Wnd) << Tcb->SndWndScale); > - Seg->Flag =3D Head->Flag; > - > - // > - // SYN and FIN flag occupy one sequence space each. > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - // > - // RFC requires that initial window not be scaled > - // > - Seg->Wnd =3D NTOHS (Head->Wnd); > - Seg->End++; > - } > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) { > - Seg->End++; > - } > - > - return Seg; > -} > - > - > -/** > - Reset the connection related with Tcb. > - > - @param Tcb Pointer to the TCP_CB of the connection = to be > - reset. > - > -**/ > -VOID > -TcpResetConnection ( > - IN TCP_CB *Tcb > - ) > -{ > - NET_BUF *Nbuf; > - TCP_HEAD *Nhead; > - > - Nbuf =3D NetbufAlloc (TCP_MAX_HEAD); > - > - if (Nbuf =3D=3D NULL) { > - return ; > - } > - > - Nhead =3D (TCP_HEAD *) NetbufAllocSpace ( > - Nbuf, > - sizeof (TCP_HEAD), > - NET_BUF_TAIL > - ); > - > - ASSERT (Nhead !=3D NULL); > - > - Nbuf->Tcp =3D Nhead; > - > - Nhead->Flag =3D TCP_FLG_RST; > - Nhead->Seq =3D HTONL (Tcb->SndNxt); > - Nhead->Ack =3D HTONL (Tcb->RcvNxt); > - Nhead->SrcPort =3D Tcb->LocalEnd.Port; > - Nhead->DstPort =3D Tcb->RemoteEnd.Port; > - Nhead->HeadLen =3D (UINT8) (sizeof (TCP_HEAD) >> 2); > - Nhead->Res =3D 0; > - Nhead->Wnd =3D HTONS (0xFFFF); > - Nhead->Checksum =3D 0; > - Nhead->Urg =3D 0; > - Nhead->Checksum =3D TcpChecksum (Nbuf, Tcb->HeadSum); > - > - TcpSendIpPacket (Tcb, Nbuf, Tcb->LocalEnd.Ip, Tcb->RemoteEnd.Ip); > - > - NetbufFree (Nbuf); > -} > - > - > -/** > - Initialize an active connection. > - > - @param Tcb Pointer to the TCP_CB that wants to init= iate a > - connection. > - > -**/ > -VOID > -TcpOnAppConnect ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - TcpInitTcbLocal (Tcb); > - TcpSetState (Tcb, TCP_SYN_SENT); > - > - TcpSetTimer (Tcb, TCP_TIMER_CONNECT, Tcb->ConnectTimeout); > - TcpToSendData (Tcb, 1); > -} > - > - > -/** > - Initiate the connection close procedure, called when > - applications want to close the connection. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > -**/ > -VOID > -TcpOnAppClose ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - ASSERT (Tcb !=3D NULL); > - > - if (!IsListEmpty (&Tcb->RcvQue) || GET_RCV_DATASIZE (Tcb->Sk) !=3D 0) = { > - > - DEBUG ((EFI_D_WARN, "TcpOnAppClose: connection reset " > - "because data is lost for TCB %p\n", Tcb)); > - > - TcpResetConnection (Tcb); > - TcpClose (Tcb); > - return; > - } > - > - switch (Tcb->State) { > - case TCP_CLOSED: > - case TCP_LISTEN: > - case TCP_SYN_SENT: > - TcpSetState (Tcb, TCP_CLOSED); > - break; > - > - case TCP_SYN_RCVD: > - case TCP_ESTABLISHED: > - TcpSetState (Tcb, TCP_FIN_WAIT_1); > - break; > - > - case TCP_CLOSE_WAIT: > - TcpSetState (Tcb, TCP_LAST_ACK); > - break; > - default: > - break; > - } > - > - TcpToSendData (Tcb, 1); > -} > - > - > -/** > - Check whether the application's newly delivered data can be sent out. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > - @retval 0 Whether the data is sent out or is buffe= red for > - further sending. > - @retval -1 The Tcb is not in a state that data is p= ermitted to > - be sent out. > - > -**/ > -INTN > -TcpOnAppSend ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - > - switch (Tcb->State) { > - case TCP_CLOSED: > - return -1; > - > - case TCP_LISTEN: > - return -1; > - > - case TCP_SYN_SENT: > - case TCP_SYN_RCVD: > - return 0; > - > - case TCP_ESTABLISHED: > - case TCP_CLOSE_WAIT: > - TcpToSendData (Tcb, 0); > - return 0; > - > - case TCP_FIN_WAIT_1: > - case TCP_FIN_WAIT_2: > - case TCP_CLOSING: > - case TCP_LAST_ACK: > - case TCP_TIME_WAIT: > - return -1; > - > - default: > - break; > - } > - > - return 0; > -} > - > - > -/** > - Application has consumed some data, check whether > - to send a window updata ack or a delayed ack. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > -**/ > -VOID > -TcpOnAppConsume ( > - IN TCP_CB *Tcb > - ) > -{ > - UINT32 TcpOld; > - > - switch (Tcb->State) { > - case TCP_CLOSED: > - return; > - > - case TCP_LISTEN: > - return; > - > - case TCP_SYN_SENT: > - case TCP_SYN_RCVD: > - return; > - > - case TCP_ESTABLISHED: > - TcpOld =3D TcpRcvWinOld (Tcb); > - if (TcpRcvWinNow (Tcb) > TcpOld) { > - > - if (TcpOld < Tcb->RcvMss) { > - > - DEBUG ((EFI_D_NET, "TcpOnAppConsume: send a window" > - " update for a window closed Tcb %p\n", Tcb)); > - > - TcpSendAck (Tcb); > - } else if (Tcb->DelayedAck =3D=3D 0) { > - > - DEBUG ((EFI_D_NET, "TcpOnAppConsume: scheduled a delayed" > - " ACK to update window for Tcb %p\n", Tcb)); > - > - Tcb->DelayedAck =3D 1; > - } > - } > - > - break; > - > - case TCP_CLOSE_WAIT: > - return; > - > - case TCP_FIN_WAIT_1: > - case TCP_FIN_WAIT_2: > - case TCP_CLOSING: > - case TCP_LAST_ACK: > - case TCP_TIME_WAIT: > - return; > - > - default: > - break; > - } > -} > - > - > -/** > - Abort the connection by sending a reset segment, called > - when the application wants to abort the connection. > - > - @param Tcb Pointer to the TCP_CB of the TCP instanc= e. > - > -**/ > -VOID > -TcpOnAppAbort ( > - IN TCP_CB *Tcb > - ) > -{ > - DEBUG ((EFI_D_WARN, "TcpOnAppAbort: connection reset " > - "issued by application for TCB %p\n", Tcb)); > - > - switch (Tcb->State) { > - case TCP_SYN_RCVD: > - case TCP_ESTABLISHED: > - case TCP_FIN_WAIT_1: > - case TCP_FIN_WAIT_2: > - case TCP_CLOSE_WAIT: > - TcpResetConnection (Tcb); > - break; > - default: > - break; > - } > - > - TcpSetState (Tcb, TCP_CLOSED); > -} > - > -/** > - Install the device path protocol on the TCP instance. > - > - @param Sock Pointer to the socket representing the TCP in= stance. > - > - @retval EFI_SUCCESS The device path protocol is installed. > - @retval other Failed to install the device path protocol. > - > -**/ > -EFI_STATUS > -TcpInstallDevicePath ( > - IN SOCKET *Sock > - ) > -{ > - TCP4_PROTO_DATA *TcpProto; > - TCP4_SERVICE_DATA *TcpService; > - TCP_CB *Tcb; > - IPv4_DEVICE_PATH Ip4DPathNode; > - EFI_STATUS Status; > - TCP_PORTNO LocalPort; > - TCP_PORTNO RemotePort; > - > - TcpProto =3D (TCP4_PROTO_DATA *) Sock->ProtoReserved; > - TcpService =3D TcpProto->TcpService; > - Tcb =3D TcpProto->TcpPcb; > - > - LocalPort =3D NTOHS (Tcb->LocalEnd.Port); > - RemotePort =3D NTOHS (Tcb->RemoteEnd.Port); > - NetLibCreateIPv4DPathNode ( > - &Ip4DPathNode, > - TcpService->ControllerHandle, > - Tcb->LocalEnd.Ip, > - LocalPort, > - Tcb->RemoteEnd.Ip, > - RemotePort, > - EFI_IP_PROTO_TCP, > - Tcb->UseDefaultAddr > - ); > - > - IP4_COPY_ADDRESS (&Ip4DPathNode.SubnetMask, &Tcb->SubnetMask); > - > - Sock->DevicePath =3D AppendDevicePathNode ( > - Sock->ParentDevicePath, > - (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode > - ); > - if (Sock->DevicePath =3D=3D NULL) { > - return EFI_OUT_OF_RESOURCES; > - } > - > - Status =3D gBS->InstallProtocolInterface ( > - &Sock->SockHandle, > - &gEfiDevicePathProtocolGuid, > - EFI_NATIVE_INTERFACE, > - Sock->DevicePath > - ); > - if (EFI_ERROR (Status)) { > - FreePool (Sock->DevicePath); > - } > - > - return Status; > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.c > deleted file mode 100644 > index e84310f6c693..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.c > +++ /dev/null > @@ -1,352 +0,0 @@ > -/** @file > - Routines to process TCP option. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > -/** > - Get a UINT16 value from buffer. > - > - @param Buf Pointer to input buffer. > - > - @return The UINT16 value get from buffer. > - > -**/ > -UINT16 > -TcpGetUint16 ( > - IN UINT8 *Buf > - ) > -{ > - UINT16 Value; > - CopyMem (&Value, Buf, sizeof (UINT16)); > - return NTOHS (Value); > -} > - > -/** > - Get a UINT32 value from buffer. > - > - @param Buf Pointer to input buffer. > - > - @return The UINT32 value get from buffer. > - > -**/ > -UINT32 > -TcpGetUint32 ( > - IN UINT8 *Buf > - ) > -{ > - UINT32 Value; > - CopyMem (&Value, Buf, sizeof (UINT32)); > - return NTOHL (Value); > -} > - > -/** > - Put a UINT32 value in buffer. > - > - @param Buf Pointer to the buffer. > - @param Data The UINT32 Date to put in buffer > - > -**/ > -VOID > -TcpPutUint32 ( > - OUT UINT8 *Buf, > - IN UINT32 Data > - ) > -{ > - Data =3D HTONL (Data); > - CopyMem (Buf, &Data, sizeof (UINT32)); > -} > - > - > -/** > - Compute the window scale value according to the given buffer size. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The scale value. > - > -**/ > -UINT8 > -TcpComputeScale ( > - IN TCP_CB *Tcb > - ) > -{ > - UINT8 Scale; > - UINT32 BufSize; > - > - ASSERT ((Tcb !=3D NULL) && (Tcb->Sk !=3D NULL)); > - > - BufSize =3D GET_RCV_BUFFSIZE (Tcb->Sk); > - > - Scale =3D 0; > - while ((Scale < TCP_OPTION_MAX_WS) && > - ((UINT32) (TCP_OPTION_MAX_WIN << Scale) < BufSize)) { > - > - Scale++; > - } > - > - return Scale; > -} > - > - > -/** > - Build the TCP option in three-way handshake. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer to store the options. > - > - @return The total length of the TCP option field. > - > -**/ > -UINT16 > -TcpSynBuildOption ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ) > -{ > - UINT8 *Data; > - UINT16 Len; > - > - ASSERT ((Tcb !=3D NULL) && (Nbuf !=3D NULL) && (Nbuf->Tcp =3D=3D NULL)= ); > - > - Len =3D 0; > - > - // > - // Add timestamp option if not disabled by application > - // and it is the first SYN segment or the peer has sent > - // us its timestamp. > - // > - if (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_TS) && > - (!TCP_FLG_ON (TCPSEG_NETBUF (Nbuf)->Flag, TCP_FLG_ACK) || > - TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RCVD_TS))) { > - > - Data =3D NetbufAllocSpace ( > - Nbuf, > - TCP_OPTION_TS_ALIGNED_LEN, > - NET_BUF_HEAD > - ); > - > - ASSERT (Data !=3D NULL); > - Len +=3D TCP_OPTION_TS_ALIGNED_LEN; > - > - TcpPutUint32 (Data, TCP_OPTION_TS_FAST); > - TcpPutUint32 (Data + 4, mTcpTick); > - TcpPutUint32 (Data + 8, 0); > - } > - > - // > - // Build window scale option, only when are configured > - // to send WS option, and either we are doing active > - // open or we have received WS option from peer. > - // > - if (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_WS) && > - (!TCP_FLG_ON (TCPSEG_NETBUF (Nbuf)->Flag, TCP_FLG_ACK) || > - TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RCVD_WS))) { > - > - Data =3D NetbufAllocSpace ( > - Nbuf, > - TCP_OPTION_WS_ALIGNED_LEN, > - NET_BUF_HEAD > - ); > - > - ASSERT (Data !=3D NULL); > - > - Len +=3D TCP_OPTION_WS_ALIGNED_LEN; > - TcpPutUint32 (Data, TCP_OPTION_WS_FAST | TcpComputeScale (Tcb)); > - } > - > - // > - // Build MSS option > - // > - Data =3D NetbufAllocSpace (Nbuf, TCP_OPTION_MSS_LEN, 1); > - ASSERT (Data !=3D NULL); > - > - Len +=3D TCP_OPTION_MSS_LEN; > - TcpPutUint32 (Data, TCP_OPTION_MSS_FAST | Tcb->RcvMss); > - > - return Len; > -} > - > - > -/** > - Build the TCP option in synchronized states. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer to store the options. > - > - @return The total length of the TCP option field. > - > -**/ > -UINT16 > -TcpBuildOption ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ) > -{ > - UINT8 *Data; > - UINT16 Len; > - > - ASSERT ((Tcb !=3D NULL) && (Nbuf !=3D NULL) && (Nbuf->Tcp =3D=3D NULL)= ); > - Len =3D 0; > - > - // > - // Build Timestamp option > - // > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_SND_TS) && > - !TCP_FLG_ON (TCPSEG_NETBUF (Nbuf)->Flag, TCP_FLG_RST)) { > - > - Data =3D NetbufAllocSpace ( > - Nbuf, > - TCP_OPTION_TS_ALIGNED_LEN, > - NET_BUF_HEAD > - ); > - > - ASSERT (Data !=3D NULL); > - Len +=3D TCP_OPTION_TS_ALIGNED_LEN; > - > - TcpPutUint32 (Data, TCP_OPTION_TS_FAST); > - TcpPutUint32 (Data + 4, mTcpTick); > - TcpPutUint32 (Data + 8, Tcb->TsRecent); > - } > - > - return Len; > -} > - > - > -/** > - Parse the supported options. > - > - @param Tcp Pointer to the TCP_CB of this TCP instance. > - @param Option Pointer to the TCP_OPTION used to store the successful= ly > pasrsed > - options. > - > - @retval 0 The options are successfully pasrsed. > - @retval -1 Ilegal option was found. > - > -**/ > -INTN > -TcpParseOption ( > - IN TCP_HEAD *Tcp, > - IN OUT TCP_OPTION *Option > - ) > -{ > - UINT8 *Head; > - UINT8 TotalLen; > - UINT8 Cur; > - UINT8 Type; > - UINT8 Len; > - > - ASSERT ((Tcp !=3D NULL) && (Option !=3D NULL)); > - > - Option->Flag =3D 0; > - > - TotalLen =3D (UINT8) ((Tcp->HeadLen << 2) - sizeof (TCP_HEAD)); > - if (TotalLen <=3D 0) { > - return 0; > - } > - > - Head =3D (UINT8 *) (Tcp + 1); > - > - // > - // Fast process of timestamp option > - // > - if ((TotalLen =3D=3D TCP_OPTION_TS_ALIGNED_LEN) && > - (TcpGetUint32 (Head) =3D=3D TCP_OPTION_TS_FAST)) { > - > - Option->TSVal =3D TcpGetUint32 (Head + 4); > - Option->TSEcr =3D TcpGetUint32 (Head + 8); > - Option->Flag =3D TCP_OPTION_RCVD_TS; > - > - return 0; > - } > - > - // > - // Slow path to process the options. > - // > - Cur =3D 0; > - > - while (Cur < TotalLen) { > - Type =3D Head[Cur]; > - > - switch (Type) { > - case TCP_OPTION_MSS: > - Len =3D Head[Cur + 1]; > - > - if ((Len !=3D TCP_OPTION_MSS_LEN) || > - (TotalLen - Cur < TCP_OPTION_MSS_LEN)) { > - > - return -1; > - } > - > - Option->Mss =3D TcpGetUint16 (&Head[Cur + 2]); > - TCP_SET_FLG (Option->Flag, TCP_OPTION_RCVD_MSS); > - > - Cur +=3D TCP_OPTION_MSS_LEN; > - break; > - > - case TCP_OPTION_WS: > - Len =3D Head[Cur + 1]; > - > - if ((Len !=3D TCP_OPTION_WS_LEN) || > - (TotalLen - Cur < TCP_OPTION_WS_LEN)) { > - > - return -1; > - } > - > - Option->WndScale =3D (UINT8) MIN (14, Head[Cur + 2]); > - TCP_SET_FLG (Option->Flag, TCP_OPTION_RCVD_WS); > - > - Cur +=3D TCP_OPTION_WS_LEN; > - break; > - > - case TCP_OPTION_TS: > - Len =3D Head[Cur + 1]; > - > - if ((Len !=3D TCP_OPTION_TS_LEN) || > - (TotalLen - Cur < TCP_OPTION_TS_LEN)) { > - > - return -1; > - } > - > - Option->TSVal =3D TcpGetUint32 (&Head[Cur + 2]); > - Option->TSEcr =3D TcpGetUint32 (&Head[Cur + 6]); > - TCP_SET_FLG (Option->Flag, TCP_OPTION_RCVD_TS); > - > - Cur +=3D TCP_OPTION_TS_LEN; > - break; > - > - case TCP_OPTION_NOP: > - Cur++; > - break; > - > - case TCP_OPTION_EOP: > - Cur =3D TotalLen; > - break; > - > - default: > - Len =3D Head[Cur + 1]; > - > - if ((TotalLen - Cur) < Len || Len < 2) { > - return -1; > - } > - > - Cur =3D (UINT8) (Cur + Len); > - break; > - } > - > - } > - > - return 0; > -} > - > - > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c > deleted file mode 100644 > index 760b09a1eda1..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c > +++ /dev/null > @@ -1,1238 +0,0 @@ > -/** @file > - TCP output process routines. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > -UINT8 mTcpOutFlag[] =3D { > - 0, // TCP_CLOSED > - 0, // TCP_LISTEN > - TCP_FLG_SYN, // TCP_SYN_SENT > - TCP_FLG_SYN | TCP_FLG_ACK, // TCP_SYN_RCVD > - TCP_FLG_ACK, // TCP_ESTABLISHED > - TCP_FLG_FIN | TCP_FLG_ACK, // TCP_FIN_WAIT_1 > - TCP_FLG_ACK, // TCP_FIN_WAIT_2 > - TCP_FLG_ACK | TCP_FLG_FIN, // TCP_CLOSING > - TCP_FLG_ACK, // TCP_TIME_WAIT > - TCP_FLG_ACK, // TCP_CLOSE_WAIT > - TCP_FLG_FIN | TCP_FLG_ACK // TCP_LAST_ACK > -}; > - > - > -/** > - Compute the sequence space left in the old receive window. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The sequence space left in the old receive window. > - > -**/ > -UINT32 > -TcpRcvWinOld ( > - IN TCP_CB *Tcb > - ) > -{ > - UINT32 OldWin; > - > - OldWin =3D 0; > - > - if (TCP_SEQ_GT (Tcb->RcvWl2 + Tcb->RcvWnd, Tcb->RcvNxt)) { > - > - OldWin =3D TCP_SUB_SEQ ( > - Tcb->RcvWl2 + Tcb->RcvWnd, > - Tcb->RcvNxt > - ); > - } > - > - return OldWin; > -} > - > - > -/** > - Compute the current receive window. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The size of the current receive window, in bytes. > - > -**/ > -UINT32 > -TcpRcvWinNow ( > - IN TCP_CB *Tcb > - ) > -{ > - SOCKET *Sk; > - UINT32 Win; > - UINT32 Increase; > - UINT32 OldWin; > - > - Sk =3D Tcb->Sk; > - ASSERT (Sk !=3D NULL); > - > - OldWin =3D TcpRcvWinOld (Tcb); > - > - Win =3D SockGetFreeSpace (Sk, SOCK_RCV_BUF); > - > - Increase =3D 0; > - if (Win > OldWin) { > - Increase =3D Win - OldWin; > - } > - > - // > - // Receiver's SWS: don't advertise a bigger window > - // unless it can be increased by at least one Mss or > - // half of the receive buffer. > - // > - if ((Increase > Tcb->SndMss) || > - (2 * Increase >=3D GET_RCV_BUFFSIZE (Sk))) { > - > - return Win; > - } > - > - return OldWin; > -} > - > - > -/** > - Compute the value to fill in the window size field of the outgoing seg= ment. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Syn The flag to indicate whether the outgoing segment is a= SYN > - segment. > - > - @return The value of the local receive window size used to fill the ou= ting > segment. > - > -**/ > -UINT16 > -TcpComputeWnd ( > - IN OUT TCP_CB *Tcb, > - IN BOOLEAN Syn > - ) > -{ > - UINT32 Wnd; > - > - // > - // RFC requires that initial window not be scaled > - // > - if (Syn) { > - > - Wnd =3D GET_RCV_BUFFSIZE (Tcb->Sk); > - } else { > - > - Wnd =3D TcpRcvWinNow (Tcb); > - > - Tcb->RcvWnd =3D Wnd; > - } > - > - Wnd =3D MIN (Wnd >> Tcb->RcvWndScale, 0xffff); > - return NTOHS ((UINT16) Wnd); > -} > - > - > -/** > - Get the maximum SndNxt. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The sequence number of the maximum SndNxt. > - > -**/ > -TCP_SEQNO > -TcpGetMaxSndNxt ( > - IN TCP_CB *Tcb > - ) > -{ > - LIST_ENTRY *Entry; > - NET_BUF *Nbuf; > - > - if (IsListEmpty (&Tcb->SndQue)) { > - return Tcb->SndNxt; > - } > - > - Entry =3D Tcb->SndQue.BackLink; > - Nbuf =3D NET_LIST_USER_STRUCT (Entry, NET_BUF, List); > - > - ASSERT (TCP_SEQ_GEQ (TCPSEG_NETBUF (Nbuf)->End, Tcb->SndNxt)); > - return TCPSEG_NETBUF (Nbuf)->End; > -} > - > - > -/** > - Compute how much data to send. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Force Whether to ignore the sender's SWS avoidance algorithm= and > send > - out data by force. > - > - @return The length of the data can be sent, if 0, no data can be sent. > - > -**/ > -UINT32 > -TcpDataToSend ( > - IN TCP_CB *Tcb, > - IN INTN Force > - ) > -{ > - SOCKET *Sk; > - UINT32 Win; > - UINT32 Len; > - UINT32 Left; > - UINT32 Limit; > - > - Sk =3D Tcb->Sk; > - ASSERT (Sk !=3D NULL); > - > - // > - // TCP should NOT send data beyond the send window > - // and congestion window. The right edge of send > - // window is defined as SND.WL2 + SND.WND. The right > - // edge of congestion window is defined as SND.UNA + > - // CWND. > - // > - Win =3D 0; > - Limit =3D Tcb->SndWl2 + Tcb->SndWnd; > - > - if (TCP_SEQ_GT (Limit, Tcb->SndUna + Tcb->CWnd)) { > - > - Limit =3D Tcb->SndUna + Tcb->CWnd; > - } > - > - if (TCP_SEQ_GT (Limit, Tcb->SndNxt)) { > - Win =3D TCP_SUB_SEQ (Limit, Tcb->SndNxt); > - } > - > - // > - // The data to send contains two parts: the data on the > - // socket send queue, and the data on the TCB's send > - // buffer. The later can be non-zero if the peer shrinks > - // its advertised window. > - // > - Left =3D GET_SND_DATASIZE (Sk) + > - TCP_SUB_SEQ (TcpGetMaxSndNxt (Tcb), Tcb->SndNxt); > - > - Len =3D MIN (Win, Left); > - > - if (Len > Tcb->SndMss) { > - Len =3D Tcb->SndMss; > - } > - > - if ((Force !=3D 0)|| (Len =3D=3D 0 && Left =3D=3D 0)) { > - return Len; > - } > - > - if (Len =3D=3D 0 && Left !=3D 0) { > - goto SetPersistTimer; > - } > - > - // > - // Sender's SWS avoidance: Don't send a small segment unless > - // a)A full-sized segment can be sent, > - // b)at least one-half of the maximum sized windows that > - // the other end has ever advertised. > - // c)It can send everything it has and either it isn't > - // expecting an ACK or the Nagle algorithm is disabled. > - // > - if ((Len =3D=3D Tcb->SndMss) || (2 * Len >=3D Tcb->SndWndMax)) { > - > - return Len; > - } > - > - if ((Len =3D=3D Left) && > - ((Tcb->SndNxt =3D=3D Tcb->SndUna) || > - TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_NAGLE))) { > - > - return Len; > - } > - > - // > - // RFC1122 suggests to set a timer when SWSA forbids TCP > - // sending more data, and combine it with probe timer. > - // > -SetPersistTimer: > - if (!TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_REXMIT)) { > - > - DEBUG ( > - (EFI_D_WARN, > - "TcpDataToSend: enter persistent state for TCB %p\n", > - Tcb) > - ); > - > - if (!Tcb->ProbeTimerOn) { > - TcpSetProbeTimer (Tcb); > - } > - } > - > - return 0; > -} > - > - > -/** > - Build the TCP header of the TCP segment and transmit the segment by IP= . > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer containing the segment to be sen= t out. > - > - @retval 0 The segment is sent out successfully. > - @retval other Error condition occurred. > - > -**/ > -INTN > -TcpTransmitSegment ( > - IN OUT TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ) > -{ > - UINT16 Len; > - TCP_HEAD *Head; > - TCP_SEG *Seg; > - BOOLEAN Syn; > - UINT32 DataLen; > - > - ASSERT ((Nbuf !=3D NULL) && (Nbuf->Tcp =3D=3D NULL) && (TcpVerifySegme= nt > (Nbuf) !=3D 0)); > - > - DataLen =3D Nbuf->TotalSize; > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - Syn =3D TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN); > - > - if (Syn) { > - > - Len =3D TcpSynBuildOption (Tcb, Nbuf); > - } else { > - > - Len =3D TcpBuildOption (Tcb, Nbuf); > - } > - > - ASSERT ((Len % 4 =3D=3D 0) && (Len <=3D 40)); > - > - Len +=3D sizeof (TCP_HEAD); > - > - Head =3D (TCP_HEAD *) NetbufAllocSpace ( > - Nbuf, > - sizeof (TCP_HEAD), > - NET_BUF_HEAD > - ); > - > - ASSERT (Head !=3D NULL); > - > - Nbuf->Tcp =3D Head; > - > - Head->SrcPort =3D Tcb->LocalEnd.Port; > - Head->DstPort =3D Tcb->RemoteEnd.Port; > - Head->Seq =3D NTOHL (Seg->Seq); > - Head->Ack =3D NTOHL (Tcb->RcvNxt); > - Head->HeadLen =3D (UINT8) (Len >> 2); > - Head->Res =3D 0; > - Head->Wnd =3D TcpComputeWnd (Tcb, Syn); > - Head->Checksum =3D 0; > - > - // > - // Check whether to set the PSH flag. > - // > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_PSH); > - > - if (DataLen !=3D 0) { > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_SND_PSH) && > - TCP_SEQ_BETWEEN (Seg->Seq, Tcb->SndPsh, Seg->End)) { > - > - TCP_SET_FLG (Seg->Flag, TCP_FLG_PSH); > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_PSH); > - > - } else if ((Seg->End =3D=3D Tcb->SndNxt) && > - (GET_SND_DATASIZE (Tcb->Sk) =3D=3D 0)) { > - > - TCP_SET_FLG (Seg->Flag, TCP_FLG_PSH); > - } > - } > - > - // > - // Check whether to set the URG flag and the urgent pointer. > - // > - TCP_CLEAR_FLG (Seg->Flag, TCP_FLG_URG); > - > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_SND_URG) && > - TCP_SEQ_LEQ (Seg->Seq, Tcb->SndUp)) { > - > - TCP_SET_FLG (Seg->Flag, TCP_FLG_URG); > - > - if (TCP_SEQ_LT (Tcb->SndUp, Seg->End)) { > - > - Seg->Urg =3D (UINT16) TCP_SUB_SEQ (Tcb->SndUp, Seg->Seq); > - } else { > - > - Seg->Urg =3D (UINT16) MIN ( > - TCP_SUB_SEQ (Tcb->SndUp, > - Seg->Seq), > - 0xffff > - ); > - } > - } > - > - Head->Flag =3D Seg->Flag; > - Head->Urg =3D NTOHS (Seg->Urg); > - Head->Checksum =3D TcpChecksum (Nbuf, Tcb->HeadSum); > - > - // > - // update the TCP session's control information > - // > - Tcb->RcvWl2 =3D Tcb->RcvNxt; > - if (Syn) { > - Tcb->RcvWnd =3D NTOHS (Head->Wnd); > - } > - > - // > - // clear delayedack flag > - // > - Tcb->DelayedAck =3D 0; > - > - return TcpSendIpPacket (Tcb, Nbuf, Tcb->LocalEnd.Ip, Tcb->RemoteEnd.Ip= ); > -} > - > - > -/** > - Get a segment from the Tcb's SndQue. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment. > - @param Len The maximum length of the segment. > - > - @return Pointer to the segment, if NULL some error occurred. > - > -**/ > -NET_BUF * > -TcpGetSegmentSndQue ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq, > - IN UINT32 Len > - ) > -{ > - LIST_ENTRY *Head; > - LIST_ENTRY *Cur; > - NET_BUF *Node; > - TCP_SEG *Seg; > - NET_BUF *Nbuf; > - TCP_SEQNO End; > - UINT8 *Data; > - UINT8 Flag; > - INT32 Offset; > - INT32 CopyLen; > - > - ASSERT ((Tcb !=3D NULL) && TCP_SEQ_LEQ (Seq, Tcb->SndNxt) && (Len > 0)= ); > - > - // > - // Find the segment that contains the Seq. > - // > - Head =3D &Tcb->SndQue; > - > - Node =3D NULL; > - Seg =3D NULL; > - > - NET_LIST_FOR_EACH (Cur, Head) { > - Node =3D NET_LIST_USER_STRUCT (Cur, NET_BUF, List); > - Seg =3D TCPSEG_NETBUF (Node); > - > - if (TCP_SEQ_LT (Seq, Seg->End) && TCP_SEQ_LEQ (Seg->Seq, Seq)) { > - > - break; > - } > - } > - > - ASSERT (Cur !=3D Head); > - ASSERT (Node !=3D NULL); > - ASSERT (Seg !=3D NULL); > - > - // > - // Return the buffer if it can be returned without > - // adjustment: > - // > - if ((Seg->Seq =3D=3D Seq) && > - TCP_SEQ_LEQ (Seg->End, Seg->Seq + Len) && > - !NET_BUF_SHARED (Node)) { > - > - NET_GET_REF (Node); > - return Node; > - } > - > - // > - // Create a new buffer and copy data there. > - // > - Nbuf =3D NetbufAlloc (Len + TCP_MAX_HEAD); > - > - if (Nbuf =3D=3D NULL) { > - return NULL; > - } > - > - NetbufReserve (Nbuf, TCP_MAX_HEAD); > - > - Flag =3D Seg->Flag; > - End =3D Seg->End; > - > - if (TCP_SEQ_LT (Seq + Len, Seg->End)) { > - End =3D Seq + Len; > - } > - > - CopyLen =3D TCP_SUB_SEQ (End, Seq); > - Offset =3D TCP_SUB_SEQ (Seq, Seg->Seq); > - > - // > - // If SYN is set and out of the range, clear the flag. > - // Because the sequence of the first byte is SEG.SEQ+1, > - // adjust Offset by -1. If SYN is in the range, copy > - // one byte less. > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - > - if (TCP_SEQ_LT (Seg->Seq, Seq)) { > - > - TCP_CLEAR_FLG (Flag, TCP_FLG_SYN); > - Offset--; > - } else { > - > - CopyLen--; > - } > - } > - > - // > - // If FIN is set and in the range, copy one byte less, > - // and if it is out of the range, clear the flag. > - // > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) { > - > - if (Seg->End =3D=3D End) { > - > - CopyLen--; > - } else { > - > - TCP_CLEAR_FLG (Flag, TCP_FLG_FIN); > - } > - } > - > - ASSERT (CopyLen >=3D 0); > - > - // > - // copy data to the segment > - // > - if (CopyLen !=3D 0) { > - Data =3D NetbufAllocSpace (Nbuf, CopyLen, NET_BUF_TAIL); > - ASSERT (Data !=3D NULL); > - > - if ((INT32) NetbufCopy (Node, Offset, CopyLen, Data) !=3D CopyLen) { > - goto OnError; > - } > - } > - > - CopyMem (TCPSEG_NETBUF (Nbuf), Seg, sizeof (TCP_SEG)); > - > - TCPSEG_NETBUF (Nbuf)->Seq =3D Seq; > - TCPSEG_NETBUF (Nbuf)->End =3D End; > - TCPSEG_NETBUF (Nbuf)->Flag =3D Flag; > - > - return Nbuf; > - > -OnError: > - NetbufFree (Nbuf); > - return NULL; > -} > - > - > -/** > - Get a segment from the Tcb's socket buffer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment. > - @param Len The maximum length of the segment. > - > - @return Pointer to the segment, if NULL some error occurred. > - > -**/ > -NET_BUF * > -TcpGetSegmentSock ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq, > - IN UINT32 Len > - ) > -{ > - NET_BUF *Nbuf; > - UINT8 *Data; > - UINT32 DataGet; > - > - ASSERT ((Tcb !=3D NULL) && (Tcb->Sk !=3D NULL)); > - > - Nbuf =3D NetbufAlloc (Len + TCP_MAX_HEAD); > - > - if (Nbuf =3D=3D NULL) { > - DEBUG ((EFI_D_ERROR, "TcpGetSegmentSock: failed to allocate " > - "a netbuf for TCB %p\n",Tcb)); > - > - return NULL; > - } > - > - NetbufReserve (Nbuf, TCP_MAX_HEAD); > - > - DataGet =3D 0; > - > - if (Len !=3D 0) { > - // > - // copy data to the segment. > - // > - Data =3D NetbufAllocSpace (Nbuf, Len, NET_BUF_TAIL); > - ASSERT (Data !=3D NULL); > - > - DataGet =3D SockGetDataToSend (Tcb->Sk, 0, Len, Data); > - } > - > - NET_GET_REF (Nbuf); > - > - TCPSEG_NETBUF (Nbuf)->Seq =3D Seq; > - TCPSEG_NETBUF (Nbuf)->End =3D Seq + Len; > - > - InsertTailList (&(Tcb->SndQue), &(Nbuf->List)); > - > - if (DataGet !=3D 0) { > - > - SockDataSent (Tcb->Sk, DataGet); > - } > - > - return Nbuf; > -} > - > - > -/** > - Get a segment starting from sequence Seq of a maximum > - length of Len. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment. > - @param Len The maximum length of the segment. > - > - @return Pointer to the segment, if NULL some error occurred. > - > -**/ > -NET_BUF * > -TcpGetSegment ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq, > - IN UINT32 Len > - ) > -{ > - NET_BUF *Nbuf; > - > - ASSERT (Tcb !=3D NULL); > - > - // > - // Compare the SndNxt with the max sequence number sent. > - // > - if ((Len !=3D 0) && TCP_SEQ_LT (Seq, TcpGetMaxSndNxt (Tcb))) { > - > - Nbuf =3D TcpGetSegmentSndQue (Tcb, Seq, Len); > - } else { > - > - Nbuf =3D TcpGetSegmentSock (Tcb, Seq, Len); > - } > - > - ASSERT (TcpVerifySegment (Nbuf) !=3D 0); > - return Nbuf; > -} > - > - > -/** > - Retransmit the segment from sequence Seq. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment to be retransmitted= . > - > - @retval 0 Retransmission succeeded. > - @retval -1 Error condition occurred. > - > -**/ > -INTN > -TcpRetransmit ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq > - ) > -{ > - NET_BUF *Nbuf; > - UINT32 Len; > - > - // > - // Compute the maxium length of retransmission. It is > - // limited by three factors: > - // 1. Less than SndMss > - // 2. must in the current send window > - // 3. will not change the boundaries of queued segments. > - // > - > - // > - // Handle the Window Retraction if TCP window scale is enabled accordi= ng to > RFC7323: > - // On first retransmission, or if the sequence number is out of > - // window by less than 2^Rcv.Wind.Shift, then do normal > - // retransmission(s) without regard to the receiver window as long > - // as the original segment was in window when it was sent. > - // > - if ((Tcb->SndWndScale !=3D 0) && > - (TCP_SEQ_GT (Seq, Tcb->RetxmitSeqMax) || TCP_SEQ_BETWEEN (Tcb- > >SndWl2 + Tcb->SndWnd, Seq, Tcb->SndWl2 + Tcb->SndWnd + (1 << Tcb- > >SndWndScale)))) { > - Len =3D TCP_SUB_SEQ (Tcb->SndNxt, Seq); > - DEBUG ( > - (EFI_D_WARN, > - "TcpRetransmit: retransmission without regard to the receiver wind= ow for > TCB %p\n", > - Tcb) > - ); > - > - } else if (TCP_SEQ_GEQ (Tcb->SndWl2 + Tcb->SndWnd, Seq)) { > - Len =3D TCP_SUB_SEQ (Tcb->SndWl2 + Tcb->SndWnd, Seq); > - > - } else { > - DEBUG ( > - (EFI_D_WARN, > - "TcpRetransmit: retransmission cancelled because send window too s= mall > for TCB %p\n", > - Tcb) > - ); > - > - return 0; > - } > - > - Len =3D MIN (Len, Tcb->SndMss); > - > - Nbuf =3D TcpGetSegmentSndQue (Tcb, Seq, Len); > - if (Nbuf =3D=3D NULL) { > - return -1; > - } > - > - ASSERT (TcpVerifySegment (Nbuf) !=3D 0); > - > - if (TcpTransmitSegment (Tcb, Nbuf) !=3D 0) { > - goto OnError; > - } > - > - if (TCP_SEQ_GT (Seq, Tcb->RetxmitSeqMax)) { > - Tcb->RetxmitSeqMax =3D Seq; > - } > - > - // > - // The retransmitted buffer may be on the SndQue, > - // trim TCP head because all the buffer on SndQue > - // are headless. > - // > - ASSERT (Nbuf->Tcp !=3D NULL); > - NetbufTrim (Nbuf, (Nbuf->Tcp->HeadLen << 2), NET_BUF_HEAD); > - Nbuf->Tcp =3D NULL; > - > - NetbufFree (Nbuf); > - return 0; > - > -OnError: > - if (Nbuf !=3D NULL) { > - NetbufFree (Nbuf); > - } > - > - return -1; > -} > - > - > -/** > - Check whether to send data/SYN/FIN and piggy back an ACK. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Force Whether to ignore the sender's SWS avoidance algorithm= and > send > - out data by force. > - > - @return The number of bytes sent. > - > -**/ > -INTN > -TcpToSendData ( > - IN OUT TCP_CB *Tcb, > - IN INTN Force > - ) > -{ > - UINT32 Len; > - INTN Sent; > - UINT8 Flag; > - NET_BUF *Nbuf; > - TCP_SEG *Seg; > - TCP_SEQNO Seq; > - TCP_SEQNO End; > - > - ASSERT ((Tcb !=3D NULL) && (Tcb->Sk !=3D NULL) && (Tcb->State !=3D TCP= _LISTEN)); > - > - Sent =3D 0; > - > - if ((Tcb->State =3D=3D TCP_CLOSED) || > - TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_FIN_SENT)) { > - > - return 0; > - } > - > -SEND_AGAIN: > - // > - // compute how much data can be sent > - // > - Len =3D TcpDataToSend (Tcb, Force); > - Seq =3D Tcb->SndNxt; > - > - ASSERT ((Tcb->State) < (ARRAY_SIZE (mTcpOutFlag))); > - Flag =3D mTcpOutFlag[Tcb->State]; > - > - if ((Flag & TCP_FLG_SYN) !=3D 0) { > - > - Seq =3D Tcb->Iss; > - Len =3D 0; > - } > - > - // > - // only send a segment without data if SYN or > - // FIN is set. > - // > - if ((Len =3D=3D 0) && > - ((Flag & (TCP_FLG_SYN | TCP_FLG_FIN)) =3D=3D 0)) { > - return Sent; > - } > - > - Nbuf =3D TcpGetSegment (Tcb, Seq, Len); > - > - if (Nbuf =3D=3D NULL) { > - DEBUG ( > - (EFI_D_ERROR, > - "TcpToSendData: failed to get a segment for TCB %p\n", > - Tcb) > - ); > - > - goto OnError; > - } > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - > - // > - // Set the TcpSeg in Nbuf. > - // > - Len =3D Nbuf->TotalSize; > - End =3D Seq + Len; > - if (TCP_FLG_ON (Flag, TCP_FLG_SYN)) { > - End++; > - } > - > - if ((Flag & TCP_FLG_FIN) !=3D 0) { > - // > - // Send FIN if all data is sent, and FIN is > - // in the window > - // > - if ((TcpGetMaxSndNxt (Tcb) =3D=3D Tcb->SndNxt) && > - (GET_SND_DATASIZE (Tcb->Sk) =3D=3D 0) && > - TCP_SEQ_LT (End + 1, Tcb->SndWnd + Tcb->SndWl2)) { > - > - DEBUG ( > - (EFI_D_NET, > - "TcpToSendData: send FIN " > - "to peer for TCB %p in state %s\n", > - Tcb, > - mTcpStateName[Tcb->State]) > - ); > - > - End++; > - } else { > - TCP_CLEAR_FLG (Flag, TCP_FLG_FIN); > - } > - } > - > - Seg->Seq =3D Seq; > - Seg->End =3D End; > - Seg->Flag =3D Flag; > - > - ASSERT (TcpVerifySegment (Nbuf) !=3D 0); > - ASSERT (TcpCheckSndQue (&Tcb->SndQue) !=3D 0); > - > - // > - // don't send an empty segment here. > - // > - if (Seg->End =3D=3D Seg->Seq) { > - DEBUG ((EFI_D_WARN, "TcpToSendData: created a empty" > - " segment for TCB %p, free it now\n", Tcb)); > - > - NetbufFree (Nbuf); > - return Sent; > - } > - > - if (TcpTransmitSegment (Tcb, Nbuf) !=3D 0) { > - NetbufTrim (Nbuf, (Nbuf->Tcp->HeadLen << 2), NET_BUF_HEAD); > - Nbuf->Tcp =3D NULL; > - > - if ((Flag & TCP_FLG_FIN) !=3D 0) { > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_FIN_SENT); > - } > - > - goto OnError; > - } > - > - Sent +=3D TCP_SUB_SEQ (End, Seq); > - > - // > - // All the buffer in the SndQue is headless > - // > - ASSERT (Nbuf->Tcp !=3D NULL); > - > - NetbufTrim (Nbuf, (Nbuf->Tcp->HeadLen << 2), NET_BUF_HEAD); > - Nbuf->Tcp =3D NULL; > - > - NetbufFree (Nbuf); > - > - // > - // update status in TCB > - // > - Tcb->DelayedAck =3D 0; > - > - if ((Flag & TCP_FLG_FIN) !=3D 0) { > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_FIN_SENT); > - } > - > - if (TCP_SEQ_GT (End, Tcb->SndNxt)) { > - Tcb->SndNxt =3D End; > - } > - > - if (!TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_REXMIT)) { > - TcpSetTimer (Tcb, TCP_TIMER_REXMIT, Tcb->Rto); > - } > - > - // > - // Enable RTT measurement only if not in retransmit. > - // Karn's algorithm reqires not to update RTT when in loss. > - // > - if ((Tcb->CongestState =3D=3D TCP_CONGEST_OPEN) && > - !TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RTT_ON)) { > - > - DEBUG ((EFI_D_NET, "TcpToSendData: set RTT measure " > - "sequence %d for TCB %p\n", Seq, Tcb)); > - > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON); > - Tcb->RttSeq =3D Seq; > - Tcb->RttMeasure =3D 0; > - } > - > - if (Len =3D=3D Tcb->SndMss) { > - goto SEND_AGAIN; > - } > - > - return Sent; > - > -OnError: > - if (Nbuf !=3D NULL) { > - NetbufFree (Nbuf); > - } > - > - return Sent; > -} > - > - > -/** > - Send an ACK immediately. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpSendAck ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - NET_BUF *Nbuf; > - TCP_SEG *Seg; > - > - Nbuf =3D NetbufAlloc (TCP_MAX_HEAD); > - > - if (Nbuf =3D=3D NULL) { > - return; > - } > - > - NetbufReserve (Nbuf, TCP_MAX_HEAD); > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - Seg->Seq =3D Tcb->SndNxt; > - Seg->End =3D Tcb->SndNxt; > - Seg->Flag =3D TCP_FLG_ACK; > - > - if (TcpTransmitSegment (Tcb, Nbuf) =3D=3D 0) { > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW); > - Tcb->DelayedAck =3D 0; > - } > - > - NetbufFree (Nbuf); > -} > - > - > -/** > - Send a zero probe segment. It can be used by keepalive and zero window > probe. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @retval 0 The zero probe segment was sent out successfully. > - @retval other Error condition occurred. > - > -**/ > -INTN > -TcpSendZeroProbe ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - NET_BUF *Nbuf; > - TCP_SEG *Seg; > - INTN Result; > - > - Nbuf =3D NetbufAlloc (TCP_MAX_HEAD); > - > - if (Nbuf =3D=3D NULL) { > - return -1; > - } > - > - NetbufReserve (Nbuf, TCP_MAX_HEAD); > - > - // > - // SndNxt-1 is out of window. The peer should respond > - // with an ACK. > - // > - Seg =3D TCPSEG_NETBUF (Nbuf); > - Seg->Seq =3D Tcb->SndNxt - 1; > - Seg->End =3D Tcb->SndNxt - 1; > - Seg->Flag =3D TCP_FLG_ACK; > - > - Result =3D TcpTransmitSegment (Tcb, Nbuf); > - NetbufFree (Nbuf); > - > - return Result; > -} > - > - > -/** > - Check whether to send an ACK or delayed ACK. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpToSendAck ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - UINT32 TcpNow; > - > - TcpNow =3D TcpRcvWinNow (Tcb); > - // > - // Generally, TCP should send a delayed ACK unless: > - // 1. ACK at least every other FULL sized segment received, > - // 2. Packets received out of order > - // 3. Receiving window is open > - // > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_ACK_NOW) || > - (Tcb->DelayedAck >=3D 1) || > - (TcpNow > TcpRcvWinOld (Tcb))) { > - TcpSendAck (Tcb); > - return; > - } > - > - DEBUG ((EFI_D_NET, "TcpToSendAck: scheduled a delayed" > - " ACK for TCB %p\n", Tcb)); > - > - // > - // schedule a delayed ACK > - // > - Tcb->DelayedAck++; > -} > - > - > -/** > - Send a RESET segment in response to the segment received. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance, may be NUL= L. > - @param Head TCP header of the segment that triggers the reset. > - @param Len Length of the segment that triggers the reset. > - @param Local Local IP address. > - @param Remote Remote peer's IP address. > - > - @retval 0 A reset is sent or no need to send it. > - @retval -1 No reset is sent. > - > -**/ > -INTN > -TcpSendReset ( > - IN TCP_CB *Tcb, > - IN TCP_HEAD *Head, > - IN INT32 Len, > - IN UINT32 Local, > - IN UINT32 Remote > - ) > -{ > - NET_BUF *Nbuf; > - TCP_HEAD *Nhead; > - UINT16 HeadSum; > - > - // > - // Don't respond to a Reset with reset > - // > - if ((Head->Flag & TCP_FLG_RST) !=3D 0) { > - return 0; > - } > - > - Nbuf =3D NetbufAlloc (TCP_MAX_HEAD); > - > - if (Nbuf =3D=3D NULL) { > - return -1; > - } > - > - Nhead =3D (TCP_HEAD *) NetbufAllocSpace ( > - Nbuf, > - sizeof (TCP_HEAD), > - NET_BUF_TAIL > - ); > - > - ASSERT (Nhead !=3D NULL); > - > - Nbuf->Tcp =3D Nhead; > - Nhead->Flag =3D TCP_FLG_RST; > - > - // > - // Derive Seq/ACK from the segment if no TCB > - // associated with it, otherwise from the Tcb > - // > - if (Tcb =3D=3D NULL) { > - > - if (TCP_FLG_ON (Head->Flag, TCP_FLG_ACK)) { > - Nhead->Seq =3D Head->Ack; > - Nhead->Ack =3D 0; > - } else { > - Nhead->Seq =3D 0; > - TCP_SET_FLG (Nhead->Flag, TCP_FLG_ACK); > - Nhead->Ack =3D HTONL (NTOHL (Head->Seq) + Len); > - } > - } else { > - > - Nhead->Seq =3D HTONL (Tcb->SndNxt); > - Nhead->Ack =3D HTONL (Tcb->RcvNxt); > - TCP_SET_FLG (Nhead->Flag, TCP_FLG_ACK); > - } > - > - Nhead->SrcPort =3D Head->DstPort; > - Nhead->DstPort =3D Head->SrcPort; > - Nhead->HeadLen =3D (UINT8) (sizeof (TCP_HEAD) >> 2); > - Nhead->Res =3D 0; > - Nhead->Wnd =3D HTONS (0xFFFF); > - Nhead->Checksum =3D 0; > - Nhead->Urg =3D 0; > - > - HeadSum =3D NetPseudoHeadChecksum (Local, Remote, 6, 0); > - Nhead->Checksum =3D TcpChecksum (Nbuf, HeadSum); > - > - TcpSendIpPacket (Tcb, Nbuf, Local, Remote); > - > - NetbufFree (Nbuf); > - return 0; > -} > - > - > -/** > - Verify that the segment is in good shape. > - > - @param Nbuf Buffer that contains the segment to be checked. > - > - @retval 0 The segment is broken. > - @retval 1 The segment is in good shape. > - > -**/ > -INTN > -TcpVerifySegment ( > - IN NET_BUF *Nbuf > - ) > -{ > - TCP_HEAD *Head; > - TCP_SEG *Seg; > - UINT32 Len; > - > - if (Nbuf =3D=3D NULL) { > - return 1; > - } > - > - NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE); > - > - Seg =3D TCPSEG_NETBUF (Nbuf); > - Len =3D Nbuf->TotalSize; > - Head =3D Nbuf->Tcp; > - > - if (Head !=3D NULL) { > - if (Head->Flag !=3D Seg->Flag) { > - return 0; > - } > - > - Len -=3D (Head->HeadLen << 2); > - } > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)) { > - Len++; > - } > - > - if (TCP_FLG_ON (Seg->Flag, TCP_FLG_FIN)) { > - Len++; > - } > - > - if (Seg->Seq + Len !=3D Seg->End) { > - return 0; > - } > - > - return 1; > -} > - > - > -/** > - Verify that all the segments in SndQue are in good shape. > - > - @param Head Pointer to the head node of the SndQue. > - > - @retval 0 At least one segment is broken. > - @retval 1 All segments in the specific queue are in good shape. > - > -**/ > -INTN > -TcpCheckSndQue ( > - IN LIST_ENTRY *Head > - ) > -{ > - LIST_ENTRY *Entry; > - NET_BUF *Nbuf; > - TCP_SEQNO Seq; > - > - if (IsListEmpty (Head)) { > - return 1; > - } > - // > - // Initialize the Seq > - // > - Entry =3D Head->ForwardLink; > - Nbuf =3D NET_LIST_USER_STRUCT (Entry, NET_BUF, List); > - Seq =3D TCPSEG_NETBUF (Nbuf)->Seq; > - > - NET_LIST_FOR_EACH (Entry, Head) { > - Nbuf =3D NET_LIST_USER_STRUCT (Entry, NET_BUF, List); > - > - if (TcpVerifySegment (Nbuf) =3D=3D 0) { > - return 0; > - } > - > - // > - // All the node in the SndQue should has: > - // SEG.SEQ =3D LAST_SEG.END > - // > - if (Seq !=3D TCPSEG_NETBUF (Nbuf)->Seq) { > - return 0; > - } > - > - Seq =3D TCPSEG_NETBUF (Nbuf)->End; > - } > - > - return 1; > -} > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Timer.c > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Timer.c > deleted file mode 100644 > index 4cb0ee7b5e6f..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Timer.c > +++ /dev/null > @@ -1,584 +0,0 @@ > -/** @file > - TCP timer related functions. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#include "Tcp4Main.h" > - > -UINT32 mTcpTick =3D 1000; > - > -/** > - Connect timeout handler. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpConnectTimeout ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Timeout handler for TCP retransmission timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpRexmitTimeout ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Timeout handler for window probe timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpProbeTimeout ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Timeout handler for keepalive timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpKeepaliveTimeout ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Timeout handler for FIN_WAIT_2 timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpFinwait2Timeout ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Timeout handler for 2MSL timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -Tcp2MSLTimeout ( > - IN OUT TCP_CB *Tcb > - ); > - > -TCP_TIMER_HANDLER mTcpTimerHandler[TCP_TIMER_NUMBER] =3D { > - TcpConnectTimeout, > - TcpRexmitTimeout, > - TcpProbeTimeout, > - TcpKeepaliveTimeout, > - TcpFinwait2Timeout, > - Tcp2MSLTimeout, > -}; > - > -/** > - Close the TCP connection. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpClose ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - NetbufFreeList (&Tcb->SndQue); > - NetbufFreeList (&Tcb->RcvQue); > - > - TcpSetState (Tcb, TCP_CLOSED); > -} > - > - > -/** > - Connect timeout handler. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpConnectTimeout ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - if (!TCP_CONNECTED (Tcb->State)) { > - DEBUG ((EFI_D_ERROR, "TcpConnectTimeout: connection closed " > - "because conenction timer timeout for TCB %p\n", Tcb)); > - > - if (EFI_ABORTED =3D=3D Tcb->Sk->SockError) { > - SOCK_ERROR (Tcb->Sk, EFI_TIMEOUT); > - } > - > - if (TCP_SYN_RCVD =3D=3D Tcb->State) { > - DEBUG ((EFI_D_WARN, "TcpConnectTimeout: send reset because " > - "connection timer timeout for TCB %p\n", Tcb)); > - > - TcpResetConnection (Tcb); > - > - } > - > - TcpClose (Tcb); > - } > -} > - > - > -/** > - Timeout handler for TCP retransmission timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpRexmitTimeout ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - UINT32 FlightSize; > - > - DEBUG ((EFI_D_WARN, "TcpRexmitTimeout: transmission " > - "timeout for TCB %p\n", Tcb)); > - > - // > - // Set the congestion window. FlightSize is the > - // amount of data that has been sent but not > - // yet ACKed. > - // > - FlightSize =3D TCP_SUB_SEQ (Tcb->SndNxt, Tcb->SndUna); > - Tcb->Ssthresh =3D MAX ((UINT32) (2 * Tcb->SndMss), FlightSize / 2)= ; > - > - Tcb->CWnd =3D Tcb->SndMss; > - Tcb->LossRecover =3D Tcb->SndNxt; > - > - Tcb->LossTimes++; > - if ((Tcb->LossTimes > Tcb->MaxRexmit) && > - !TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_CONNECT)) { > - > - DEBUG ((EFI_D_ERROR, "TcpRexmitTimeout: connection closed " > - "because too many timeouts for TCB %p\n", Tcb)); > - > - if (EFI_ABORTED =3D=3D Tcb->Sk->SockError) { > - SOCK_ERROR (Tcb->Sk, EFI_TIMEOUT); > - } > - > - TcpClose (Tcb); > - return ; > - } > - > - TcpBackoffRto (Tcb); > - TcpRetransmit (Tcb, Tcb->SndUna); > - TcpSetTimer (Tcb, TCP_TIMER_REXMIT, Tcb->Rto); > - > - Tcb->CongestState =3D TCP_CONGEST_LOSS; > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON); > -} > - > - > -/** > - Timeout handler for window probe timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpProbeTimeout ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - // > - // This is the timer for sender's SWSA. RFC1122 requires > - // a timer set for sender's SWSA, and suggest combine it > - // with window probe timer. If data is sent, don't set > - // the probe timer, since retransmit timer is on. > - // > - if ((TcpDataToSend (Tcb, 1) !=3D 0) && (TcpToSendData (Tcb, 1) > 0)) { > - > - ASSERT (TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_REXMIT) !=3D 0); > - Tcb->ProbeTimerOn =3D FALSE; > - return ; > - } > - > - TcpSendZeroProbe (Tcb); > - TcpSetProbeTimer (Tcb); > -} > - > - > -/** > - Timeout handler for keepalive timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpKeepaliveTimeout ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - Tcb->KeepAliveProbes++; > - > - // > - // Too many Keep-alive probes, drop the connection > - // > - if (Tcb->KeepAliveProbes > Tcb->MaxKeepAlive) { > - > - if (EFI_ABORTED =3D=3D Tcb->Sk->SockError) { > - SOCK_ERROR (Tcb->Sk, EFI_TIMEOUT); > - } > - > - TcpClose (Tcb); > - return ; > - } > - > - TcpSendZeroProbe (Tcb); > - TcpSetKeepaliveTimer (Tcb); > -} > - > - > -/** > - Timeout handler for FIN_WAIT_2 timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpFinwait2Timeout ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - DEBUG ((EFI_D_WARN, "TcpFinwait2Timeout: connection closed " > - "because FIN_WAIT2 timer timeouts for TCB %p\n", Tcb)); > - > - TcpClose (Tcb); > -} > - > - > -/** > - Timeout handler for 2MSL timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -Tcp2MSLTimeout ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - DEBUG ((EFI_D_WARN, "Tcp2MSLTimeout: connection closed " > - "because TIME_WAIT timer timeouts for TCB %p\n", Tcb)); > - > - TcpClose (Tcb); > -} > - > - > -/** > - Update the timer status and the next expire time according to the time= rs > - to expire in a specific future time slot. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpUpdateTimer ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - UINT16 Index; > - > - // > - // Don't use a too large value to init NextExpire > - // since mTcpTick wraps around as sequence no does. > - // > - Tcb->NextExpire =3D 65535; > - TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_TIMER_ON); > - > - for (Index =3D 0; Index < TCP_TIMER_NUMBER; Index++) { > - > - if (TCP_TIMER_ON (Tcb->EnabledTimer, Index) && > - TCP_TIME_LT (Tcb->Timer[Index], mTcpTick + Tcb->NextExpire)) { > - > - Tcb->NextExpire =3D TCP_SUB_TIME (Tcb->Timer[Index], mTcpTick); > - TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_TIMER_ON); > - } > - } > -} > - > - > -/** > - Enable a TCP timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Timer The index of the timer to be enabled. > - @param TimeOut The timeout value of this timer. > - > -**/ > -VOID > -TcpSetTimer ( > - IN OUT TCP_CB *Tcb, > - IN UINT16 Timer, > - IN UINT32 TimeOut > - ) > -{ > - TCP_SET_TIMER (Tcb->EnabledTimer, Timer); > - Tcb->Timer[Timer] =3D mTcpTick + TimeOut; > - > - TcpUpdateTimer (Tcb); > -} > - > - > -/** > - Clear one TCP timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Timer The index of the timer to be cleared. > - > -**/ > -VOID > -TcpClearTimer ( > - IN OUT TCP_CB *Tcb, > - IN UINT16 Timer > - ) > -{ > - TCP_CLEAR_TIMER (Tcb->EnabledTimer, Timer); > - TcpUpdateTimer (Tcb); > -} > - > - > -/** > - Clear all TCP timers. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpClearAllTimer ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - Tcb->EnabledTimer =3D 0; > - TcpUpdateTimer (Tcb); > -} > - > - > -/** > - Enable the window prober timer and set the timeout value. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpSetProbeTimer ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - if (!Tcb->ProbeTimerOn) { > - Tcb->ProbeTime =3D Tcb->Rto; > - Tcb->ProbeTimerOn =3D TRUE; > - > - } else { > - Tcb->ProbeTime <<=3D 1; > - } > - > - if (Tcb->ProbeTime < TCP_RTO_MIN) { > - > - Tcb->ProbeTime =3D TCP_RTO_MIN; > - } else if (Tcb->ProbeTime > TCP_RTO_MAX) { > - > - Tcb->ProbeTime =3D TCP_RTO_MAX; > - } > - > - TcpSetTimer (Tcb, TCP_TIMER_PROBE, Tcb->ProbeTime); > -} > - > - > -/** > - Enable the keepalive timer and set the timeout value. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpSetKeepaliveTimer ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE)) { > - return ; > - > - } > - > - // > - // Set the timer to KeepAliveIdle if either > - // 1. the keepalive timer is off > - // 2. The keepalive timer is on, but the idle > - // is less than KeepAliveIdle, that means the > - // connection is alive since our last probe. > - // > - if (!TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_KEEPALIVE) || > - (Tcb->Idle < Tcb->KeepAliveIdle)) { > - > - TcpSetTimer (Tcb, TCP_TIMER_KEEPALIVE, Tcb->KeepAliveIdle); > - Tcb->KeepAliveProbes =3D 0; > - > - } else { > - > - TcpSetTimer (Tcb, TCP_TIMER_KEEPALIVE, Tcb->KeepAlivePeriod); > - } > -} > - > - > -/** > - Backoff the RTO. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpBackoffRto ( > - IN OUT TCP_CB *Tcb > - ) > -{ > - // > - // Fold the RTT estimate if too many times, the estimate > - // may be wrong, fold it. So the next time a valid > - // measurement is sampled, we can start fresh. > - // > - if ((Tcb->LossTimes >=3D TCP_FOLD_RTT) && (Tcb->SRtt !=3D 0)) { > - Tcb->RttVar +=3D Tcb->SRtt >> 2; > - Tcb->SRtt =3D 0; > - } > - > - Tcb->Rto <<=3D 1; > - > - if (Tcb->Rto < TCP_RTO_MIN) { > - > - Tcb->Rto =3D TCP_RTO_MIN; > - } else if (Tcb->Rto > TCP_RTO_MAX) { > - > - Tcb->Rto =3D TCP_RTO_MAX; > - } > -} > - > - > -/** > - Heart beat timer handler. > - > - @param Context Context of the timer event, ignored. > - > -**/ > -VOID > -EFIAPI > -TcpTickingDpc ( > - IN VOID *Context > - ) > -{ > - LIST_ENTRY *Entry; > - LIST_ENTRY *Next; > - TCP_CB *Tcb; > - INT16 Index; > - > - mTcpTick++; > - mTcpGlobalIss +=3D 100; > - > - // > - // Don't use LIST_FOR_EACH, which isn't delete safe. > - // > - for (Entry =3D mTcpRunQue.ForwardLink; Entry !=3D &mTcpRunQue; Entry = =3D Next) { > - > - Next =3D Entry->ForwardLink; > - > - Tcb =3D NET_LIST_USER_STRUCT (Entry, TCP_CB, List); > - > - if (Tcb->State =3D=3D TCP_CLOSED) { > - continue; > - } > - // > - // The connection is doing RTT measurement. > - // > - if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RTT_ON)) { > - Tcb->RttMeasure++; > - } > - > - Tcb->Idle++; > - > - if (Tcb->DelayedAck !=3D 0) { > - TcpSendAck (Tcb); > - } > - > - // > - // No timer is active or no timer expired > - // > - if (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_TIMER_ON) || > - ((--Tcb->NextExpire) > 0)) { > - > - continue; > - } > - > - // > - // Call the timeout handler for each expired timer. > - // > - for (Index =3D 0; Index < TCP_TIMER_NUMBER; Index++) { > - > - if (TCP_TIMER_ON (Tcb->EnabledTimer, Index) && > - TCP_TIME_LEQ (Tcb->Timer[Index], mTcpTick)) { > - // > - // disable the timer before calling the handler > - // in case the handler enables it again. > - // > - TCP_CLEAR_TIMER (Tcb->EnabledTimer, Index); > - mTcpTimerHandler[Index](Tcb); > - > - // > - // The Tcb may have been deleted by the timer, or > - // no other timer is set. > - // > - if ((Next->BackLink !=3D Entry) || > - (Tcb->EnabledTimer =3D=3D 0)) { > - break; > - } > - } > - } > - > - // > - // If the Tcb still exist or some timer is set, update the timer > - // > - if (Index =3D=3D TCP_TIMER_NUMBER) { > - TcpUpdateTimer (Tcb); > - } > - } > -} > - > -/** > - Heart beat timer handler, queues the DPC at TPL_CALLBACK. > - > - @param Event Timer event signaled, ignored. > - @param Context Context of the timer event, ignored. > - > -**/ > -VOID > -EFIAPI > -TcpTicking ( > - IN EFI_EVENT Event, > - IN VOID *Context > - ) > -{ > - QueueDpc (TPL_CALLBACK, TcpTickingDpc, Context); > -} > - > diff --git a/MdeModulePkg/MdeModulePkg.dsc > b/MdeModulePkg/MdeModulePkg.dsc > index 2465d39fd744..3529c8d30365 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -359,7 +359,6 @@ [Components] > MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf > MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf > MdeModulePkg/Universal/Network/SnpDxe/SnpDxe.inf > - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf > MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf >=20 >=20 > MdeModulePkg/Universal/PcatSingleSegmentPciCfg2Pei/PcatSingleSegmentPci > Cfg2Pei.inf > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h > deleted file mode 100644 > index bea7479eb222..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h > +++ /dev/null > @@ -1,131 +0,0 @@ > -/** @file > - Socket implementation header file. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _SOCK_IMPL_H_ > -#define _SOCK_IMPL_H_ > - > -#include "Socket.h" > -#include "Tcp4Main.h" > - > -/** > - Signal a event with the given status. > - > - @param Token The token's event is to be signaled. > - @param TokenStatus The status to be sent with the event. > - > -**/ > -#define SIGNAL_TOKEN(Token, TokenStatus) \ > - do { \ > - (Token)->Status =3D (TokenStatus); \ > - gBS->SignalEvent ((Token)->Event); \ > - } while (0) > - > - > -/** > - Supporting function for both SockImpl and SockInterface. > - > - @param Event The Event this notify function registered to, ignored. > - > -**/ > -VOID > -EFIAPI > -SockFreeFoo ( > - IN EFI_EVENT Event > - ); > - > -/** > - Process the TCP send data, buffer the tcp txdata and append > - the buffer to socket send buffer,then try to send it. > - > - @param Sock Pointer to the socket. > - @param TcpTxData Pointer to the tcp txdata. > - > - @retval EFI_SUCCESS The operation is completed successfully. > - @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. > - > -**/ > -EFI_STATUS > -SockProcessTcpSndData ( > - IN SOCKET *Sock, > - IN VOID *TcpTxData > - ); > - > -/** > - Copy data from socket buffer to application provided receive buffer. > - > - @param Sock Pointer to the socket. > - @param TcpRxData Pointer to the application provided rece= ive buffer. > - @param RcvdBytes The maximum length of the data can be co= pied. > - @param IsOOB If TRUE the data is OOB, else the data i= s normal. > - > -**/ > -VOID > -SockSetTcpRxData ( > - IN SOCKET *Sock, > - IN VOID *TcpRxData, > - IN UINT32 RcvdBytes, > - IN BOOLEAN IsOOB > - ); > - > -/** > - Get received data from the socket layer to the receive token. > - > - @param Sock Pointer to the socket. > - @param RcvToken Pointer to the application provided rece= ive token. > - > - @return The length of data received in this token. > - > -**/ > -UINT32 > -SockProcessRcvToken ( > - IN SOCKET *Sock, > - IN OUT SOCK_IO_TOKEN *RcvToken > - ); > - > -/** > - Flush the socket. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockConnFlush ( > - IN OUT SOCKET *Sock > - ); > - > -/** > - Create a socket with initial data SockInitData. > - > - @param SockInitData Pointer to the initial data of the socke= t. > - > - @return Pointer to the newly created socket. > - > -**/ > -SOCKET * > -SockCreate ( > - IN SOCK_INIT_DATA *SockInitData > - ); > - > -/** > - Destroy a socket. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockDestroy ( > - IN OUT SOCKET *Sock > - ); > - > -#endif > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h > deleted file mode 100644 > index 650a7dd8651f..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h > +++ /dev/null > @@ -1,954 +0,0 @@ > -/** @file > - Socket header file. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _SOCKET_H_ > -#define _SOCKET_H_ > - > -#include > - > -#include > -#include > -#include > - > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > - > -#define SOCK_SND_BUF 0 > -#define SOCK_RCV_BUF 1 > - > -#define SOCK_BUFF_LOW_WATER (2 * 1024) > -#define SOCK_RCV_BUFF_SIZE (8 * 1024) > -#define SOCK_SND_BUFF_SIZE (8 * 1024) > -#define SOCK_BACKLOG 5 > - > -#define PROTO_RESERVED_LEN 20 > - > -#define SO_NO_MORE_DATA 0x0001 > - > -// > -// > -// > -// When a socket is created it enters into SO_UNCONFIGURED, > -// no actions can be taken on this socket, only after calling > -// SockConfigure. The state transition diagram of socket is > -// as following: > -// > -// SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING > -// ^ | | > -// | ---> SO_LISTENING | > -// | | > -// |------------------SO_DISCONNECTING<-- SO_CONNECTED > -// > -// A passive socket can only go into SO_LISTENING and > -// SO_UNCONFIGURED state. SO_XXXING state is a middle state > -// when a socket is undergoing a protocol procedure such > -// as requesting a TCP connection. > -// > -// > -// > - > -/// > -/// Socket state > -/// > -#define SO_CLOSED 0 > -#define SO_LISTENING 1 > -#define SO_CONNECTING 2 > -#define SO_CONNECTED 3 > -#define SO_DISCONNECTING 4 > - > -/// > -/// Socket configure state > -/// > -#define SO_UNCONFIGURED 0 > -#define SO_CONFIGURED_ACTIVE 1 > -#define SO_CONFIGURED_PASSIVE 2 > -#define SO_NO_MAPPING 3 > - > -/** > - Set socket SO_NO_MORE_DATA flag. > - > - @param Sock Pointer to the socket > - > -**/ > -#define SOCK_NO_MORE_DATA(Sock) ((Sock)->Flag |=3D SO_NO_MORE_DATA) > - > -/** > - Check whether the socket is unconfigured. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is unconfigued > - @retval False The socket is not unconfigued > - > -**/ > -#define SOCK_IS_UNCONFIGURED(Sock) ((Sock)->ConfigureState =3D=3D > SO_UNCONFIGURED) > - > -/** > - Check whether the socket is configured. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is configued > - @retval False The socket is not configued > - > -**/ > -#define SOCK_IS_CONFIGURED(Sock) \ > - (((Sock)->ConfigureState =3D=3D SO_CONFIGURED_ACTIVE) || \ > - ((Sock)->ConfigureState =3D=3D SO_CONFIGURED_PASSIVE)) > - > -/** > - Check whether the socket is configured to active mode. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is configued to active mode > - @retval False The socket is not configued to active mode > - > -**/ > -#define SOCK_IS_CONFIGURED_ACTIVE(Sock) \ > - ((Sock)->ConfigureState =3D=3D SO_CONFIGURED_ACTIVE) > - > -/** > - Check whether the socket is configured to passive mode. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is configued to passive mode > - @retval False The socket is not configued to passive mode > - > -**/ > -#define SOCK_IS_CONNECTED_PASSIVE(Sock) \ > - ((Sock)->ConfigureState =3D=3D SO_CONFIGURED_PASSIVE) > - > -/** > - Check whether the socket is mapped. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is no mapping > - @retval False The socket is mapped > - > -**/ > -#define SOCK_IS_NO_MAPPING(Sock) \ > - ((Sock)->ConfigureState =3D=3D SO_NO_MAPPING) > - > -/** > - Check whether the socket is closed. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is closed > - @retval False The socket is not closed > - > -**/ > -#define SOCK_IS_CLOSED(Sock) ((Sock)->State =3D=3D SO_CLOSED) > - > -/** > - Check whether the socket is listening. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is listening > - @retval False The socket is not listening > - > -**/ > -#define SOCK_IS_LISTENING(Sock) ((Sock)->State =3D=3D SO_LISTENING= ) > - > -/** > - Check whether the socket is connecting. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is connecting > - @retval False The socket is not connecting > - > -**/ > -#define SOCK_IS_CONNECTING(Sock) ((Sock)->State =3D=3D SO_CONNECTIN= G) > - > -/** > - Check whether the socket has connected. > - > - @param Sock Pointer to the socket > - > - @retval True The socket has connected > - @retval False The socket has not connected > - > -**/ > -#define SOCK_IS_CONNECTED(Sock) ((Sock)->State =3D=3D SO_CONNECTED= ) > - > -/** > - Check whether the socket is disconnecting. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is disconnecting > - @retval False The socket is not disconnecting > - > -**/ > -#define SOCK_IS_DISCONNECTING(Sock) ((Sock)->State =3D=3D > SO_DISCONNECTING) > - > -/** > - Check whether the socket is no more data. > - > - @param Sock Pointer to the socket > - > - @retval True The socket is no more data > - @retval False The socket still has data > - > -**/ > -#define SOCK_IS_NO_MORE_DATA(Sock) (0 !=3D ((Sock)->Flag & > SO_NO_MORE_DATA)) > - > -/** > - Set the size of the receive buffer. > - > - @param Sock Pointer to the socket > - @param Size The size to set > - > -**/ > -#define SET_RCV_BUFFSIZE(Sock, Size) ((Sock)->RcvBuffer.HighWater =3D (= Size)) > - > -/** > - Get the size of the receive buffer. > - > - @param Sock Pointer to the socket > - > - @return The receive buffer size > - > -**/ > -#define GET_RCV_BUFFSIZE(Sock) ((Sock)->RcvBuffer.HighWater) > - > -/** > - Get the size of the receive data. > - > - @param Sock Pointer to the socket > - > - @return The received data size > - > -**/ > -#define GET_RCV_DATASIZE(Sock) (((Sock)->RcvBuffer.DataQueue)- > >BufSize) > - > -/** > - Set the size of the send buffer. > - > - @param Sock Pointer to the socket > - @param Size The size to set > - > -**/ > -#define SET_SND_BUFFSIZE(Sock, Size) ((Sock)->SndBuffer.HighWater =3D (= Size)) > - > -/** > - Get the size of the send buffer. > - > - @param Sock Pointer to the socket > - > - @return The send buffer size > - > -**/ > -#define GET_SND_BUFFSIZE(Sock) ((Sock)->SndBuffer.HighWater) > - > -/** > - Get the size of the send data. > - > - @param Sock Pointer to the socket > - > - @return The send data size > - > -**/ > -#define GET_SND_DATASIZE(Sock) (((Sock)->SndBuffer.DataQueue)- > >BufSize) > - > -/** > - Set the backlog value of the socket. > - > - @param Sock Pointer to the socket > - @param Value The value to set > - > -**/ > -#define SET_BACKLOG(Sock, Value) ((Sock)->BackLog =3D (Value)) > - > -/** > - Get the backlog value of the socket. > - > - @param Sock Pointer to the socket > - > - @return The backlog value > - > -**/ > -#define GET_BACKLOG(Sock) ((Sock)->BackLog) > - > -/** > - Set the socket with error state. > - > - @param Sock Pointer to the socket > - @param Error The error state > - > -**/ > -#define SOCK_ERROR(Sock, Error) ((Sock)->SockError =3D (Error)) > - > -#define SND_BUF_HDR_LEN(Sock) \ > - ((SockBufFirst (&((Sock)->SndBuffer)))->TotalSize) > - > -#define RCV_BUF_HDR_LEN(Sock) \ > - ((SockBufFirst (&((Sock)->RcvBuffer)))->TotalSize) > - > -#define SOCK_SIGNATURE SIGNATURE_32 ('S', 'O', 'C', 'K') > - > -#define SOCK_FROM_THIS(a) CR ((a), SOCKET, NetProtocol, > SOCK_SIGNATURE) > - > -#define SOCK_FROM_TOKEN(Token) (((SOCK_TOKEN *) (Token))->Sock) > - > -#define PROTO_TOKEN_FORM_SOCK(SockToken, Type) \ > - ((Type *) (((SOCK_TOKEN *) (SockToken))->Token)) > - > -typedef struct _SOCKET SOCKET; > - > -/// > -/// Socket completion token > -/// > -typedef struct _SOCK_COMPLETION_TOKEN { > - EFI_EVENT Event; ///< The event to be issued > - EFI_STATUS Status; ///< The status to be issued > -} SOCK_COMPLETION_TOKEN; > - > -typedef union { > - VOID *RxData; > - VOID *TxData; > -} SOCK_IO_DATA; > - > -/// > -/// The application token with data packet > -/// > -typedef struct _SOCK_IO_TOKEN { > - SOCK_COMPLETION_TOKEN Token; > - SOCK_IO_DATA Packet; > -} SOCK_IO_TOKEN; > - > -/// > -/// The request issued from socket layer to protocol layer. > -/// > -#define SOCK_ATTACH 0 ///< Attach current socket to a new PCB > -#define SOCK_DETACH 1 ///< Detach current socket from the PCB > -#define SOCK_CONFIGURE 2 ///< Configure attached PCB > -#define SOCK_FLUSH 3 ///< Flush attached PCB > -#define SOCK_SND 4 ///< Need protocol to send something > -#define SOCK_SNDPUSH 5 ///< Need protocol to send pushed data > -#define SOCK_SNDURG 6 ///< Need protocol to send urgent data > -#define SOCK_CONSUMED 7 ///< Application has retrieved data from so= cket > -#define SOCK_CONNECT 8 ///< Need to connect to a peer > -#define SOCK_CLOSE 9 ///< Need to close the protocol process > -#define SOCK_ABORT 10 ///< Need to reset the protocol process > -#define SOCK_POLL 11 ///< Need to poll to the protocol layer > -#define SOCK_ROUTE 12 ///< Need to add a route information > -#define SOCK_MODE 13 ///< Need to get the mode data of the proto= col > -#define SOCK_GROUP 14 ///< Need to join a mcast group > - > -/// > -/// The socket type. > -/// > -typedef enum { > - SockDgram, ///< This socket providing datagram service > - SockStream ///< This socket providing stream service > -} SOCK_TYPE; > - > -/// > -/// The buffer structure of rcvd data and send data used by socket. > -/// > -typedef struct _SOCK_BUFFER { > - UINT32 HighWater; ///< The buffersize upper limit of sock_buff= er > - UINT32 LowWater; ///< The low water mark of sock_buffer > - NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data > -} SOCK_BUFFER; > - > -/** > - The handler of protocol for request from socket. > - > - @param Socket The socket issuing the request to protocol > - @param Request The request issued by socket > - @param RequestData The request related data > - > - @retval EFI_SUCCESS The socket request is completed successfull= y. > - @retval other The error status returned by the correspond= ing TCP > - layer function. > - > -**/ > -typedef > -EFI_STATUS > -(*SOCK_PROTO_HANDLER) ( > - IN SOCKET *Socket, > - IN UINT8 Request, > - IN VOID *RequestData > - ); > - > - > -// > -// Socket provided oprerations for low layer protocol > -// > - > -// > -// Socket provided operations for user interface > -// > - > -/** > - Set the state of the socket. > - > - @param Sock Pointer to the socket. > - @param State The new socket state to be set. > - > -**/ > -VOID > -SockSetState ( > - IN OUT SOCKET *Sock, > - IN UINT8 State > - ); > - > -/** > - Called by the low layer protocol to indicate the socket a connection i= s > - established. > - > - This function just changes the socket's state to SO_CONNECTED > - and signals the token used for connection establishment. > - > - @param Sock Pointer to the socket associated with th= e > - established connection. > - > -**/ > -VOID > -SockConnEstablished ( > - IN SOCKET *Sock > - ); > - > -/** > - Called by the low layer protocol to indicate the connection is closed. > - > - This function flushes the socket, sets the state to SO_CLOSED and sign= als > - the close token. > - > - @param Sock Pointer to the socket associated with th= e closed > - connection. > - > -**/ > -VOID > -SockConnClosed ( > - IN OUT SOCKET *Sock > - ); > - > -/** > - Called by low layer protocol to indicate that some data is sent or pro= cessed. > - > - This function trims the sent data in the socket send buffer, signals t= he data > - token if proper. > - > - @param Sock Pointer to the socket. > - @param Count The length of the data processed or sent= , in bytes. > - > -**/ > -VOID > -SockDataSent ( > - IN SOCKET *Sock, > - IN UINT32 Count > - ); > - > -/** > - Called by the low layer protocol to copy some data in socket send > - buffer starting from the specific offset to a buffer provided by > - the caller. > - > - @param Sock Pointer to the socket. > - @param Offset The start point of the data to be copied= . > - @param Len The length of the data to be copied. > - @param Dest Pointer to the destination to copy the d= ata. > - > - @return The data size copied. > - > -**/ > -UINT32 > -SockGetDataToSend ( > - IN SOCKET *Sock, > - IN UINT32 Offset, > - IN UINT32 Len, > - IN UINT8 *Dest > - ); > - > -/** > - Called by the low layer protocol to indicate that there > - will be no more data from the communication peer. > - > - This function set the socket's state to SO_NO_MORE_DATA and > - signal all queued IO tokens with the error status EFI_CONNECTION_FIN. > - > - @param Sock Pointer to the socket. > - > -**/ > -VOID > -SockNoMoreData ( > - IN OUT SOCKET *Sock > - ); > - > -/** > - Called by the low layer protocol to deliver received data to socket la= yer. > - > - This function will append the data to the socket receive buffer, set t= her > - urgent data length and then check if any receive token can be signaled= . > - > - @param Sock Pointer to the socket. > - @param NetBuffer Pointer to the buffer that contains the = received > - data. > - @param UrgLen The length of the urgent data in the rec= eived data. > - > -**/ > -VOID > -SockDataRcvd ( > - IN SOCKET *Sock, > - IN OUT NET_BUF *NetBuffer, > - IN UINT32 UrgLen > - ); > - > -/** > - Get the length of the free space of the specific socket buffer. > - > - @param Sock Pointer to the socket. > - @param Which Flag to indicate which socket buffer to = check, > - either send buffer or receive buffer. > - > - @return The length of the free space, in bytes. > - > -**/ > -UINT32 > -SockGetFreeSpace ( > - IN SOCKET *Sock, > - IN UINT32 Which > - ); > - > -/** > - Clone a new socket including its associated protocol control block. > - > - @param Sock Pointer to the socket to be cloned. > - > - @return Pointer to the newly cloned socket. If NULL, error condition o= ccurred. > - > -**/ > -SOCKET * > -SockClone ( > - IN SOCKET *Sock > - ); > - > - > -/// > -/// Proto type of the create callback > -/// > -typedef > -EFI_STATUS > -(*SOCK_CREATE_CALLBACK) ( > - IN SOCKET *This, > - IN VOID *Context > - ); > - > -/// > -/// Proto type of the destroy callback > -/// > -typedef > -VOID > -(*SOCK_DESTROY_CALLBACK) ( > - IN SOCKET *This, > - IN VOID *Context > - ); > - > -/// > -/// The initialize data for create a new socket. > -/// > -typedef struct _SOCK_INIT_DATA { > - SOCK_TYPE Type; > - UINT8 State; > - > - SOCKET *Parent; ///< The parent of this socket > - UINT32 BackLog; ///< The connection limit for listening so= cket > - UINT32 SndBufferSize; ///< The high water mark of send buffer > - UINT32 RcvBufferSize; ///< The high water mark of receive buffer > - VOID *Protocol; ///< The pointer to protocol function temp= late > - ///< wanted to install on socket > - > - // > - // Callbacks after socket is created and before socket is to be destro= yed. > - // > - SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created > - SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied > - VOID *Context; ///< The context of the callba= ck > - > - // > - // Opaque protocol data. > - // > - VOID *ProtoData; > - UINT32 DataSize; > - > - SOCK_PROTO_HANDLER ProtoHandler; ///< The handler of protocol for > socket request > - > - EFI_HANDLE DriverBinding; ///< The driver binding handle > -} SOCK_INIT_DATA; > - > -/// > -/// The union type of TCP and UDP protocol. > -/// > -typedef union _NET_PROTOCOL { > - EFI_TCP4_PROTOCOL TcpProtocol; ///< Tcp protocol > - EFI_UDP4_PROTOCOL UdpProtocol; ///< Udp protocol > -} NET_PROTOCOL; > - > -/// > -/// The socket structure representing a network service access point > -/// > -struct _SOCKET { > - > - // > - // Socket description information > - // > - UINT32 Signature; ///< Signature of the socket > - EFI_HANDLE SockHandle; ///< The virtual handle of the s= ocket > - EFI_HANDLE DriverBinding; ///< Socket's driver binding pro= tocol > - EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; > - EFI_DEVICE_PATH_PROTOCOL *DevicePath; > - LIST_ENTRY Link; > - UINT8 ConfigureState; > - SOCK_TYPE Type; > - UINT8 State; > - UINT16 Flag; > - EFI_LOCK Lock; ///< The lock of socket > - SOCK_BUFFER SndBuffer; ///< Send buffer of application's da= ta > - SOCK_BUFFER RcvBuffer; ///< Receive buffer of received data > - EFI_STATUS SockError; ///< The error returned by low layer= protocol > - BOOLEAN InDestroy; > - > - // > - // Fields used to manage the connection request > - // > - UINT32 BackLog; ///< the limit of connection to this s= ocket > - UINT32 ConnCnt; ///< the current count of connections = to it > - SOCKET *Parent; ///< listening parent that accept the = connection > - LIST_ENTRY ConnectionList; ///< the connections maintained by thi= s socket > - > - // > - // The queue to buffer application's asynchronous token > - // > - LIST_ENTRY ListenTokenList; > - LIST_ENTRY RcvTokenList; > - LIST_ENTRY SndTokenList; > - LIST_ENTRY ProcessingSndTokenList; > - > - SOCK_COMPLETION_TOKEN *ConnectionToken; ///< app's token to signal if > connected > - SOCK_COMPLETION_TOKEN *CloseToken; ///< app's token to signal if > closed > - > - // > - // Interface for low level protocol > - // > - SOCK_PROTO_HANDLER ProtoHandler; ///< The request handler of > protocol > - UINT8 ProtoReserved[PROTO_RESERVED_LEN]; ///< Data fields reserved fo= r > protocol > - NET_PROTOCOL NetProtocol; ///< TCP or UDP protocol soc= ket used > - > - // > - // Callbacks after socket is created and before socket is to be destro= yed. > - // > - SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created > - SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroi= ed > - VOID *Context; ///< The context of the call= back > -}; > - > -/// > -/// The token structure buffered in socket layer. > -/// > -typedef struct _SOCK_TOKEN { > - LIST_ENTRY TokenList; ///< The entry to add in the tok= en list > - SOCK_COMPLETION_TOKEN *Token; ///< The application's token > - UINT32 RemainDataLen; ///< Unprocessed data length > - SOCKET *Sock; ///< The poninter to the socket = this token > - ///< belongs to > -} SOCK_TOKEN; > - > -/// > -/// Reserved data to access the NET_BUF delivered by UDP driver. > -/// > -typedef struct _UDP_RSV_DATA { > - EFI_TIME TimeStamp; > - EFI_UDP4_SESSION_DATA Session; > -} UDP_RSV_DATA; > - > -/// > -/// Reserved data to access the NET_BUF delivered by TCP driver. > -/// > -typedef struct _TCP_RSV_DATA { > - UINT32 UrgLen; > -} TCP_RSV_DATA; > - > -/** > - Create a socket and its associated protocol control block > - with the intial data SockInitData and protocol specific > - data ProtoData. > - > - @param SockInitData Inital data to setting the socket. > - > - @return Pointer to the newly created socket. If NULL, error condition = occured. > - > -**/ > -SOCKET * > -SockCreateChild ( > - IN SOCK_INIT_DATA *SockInitData > - ); > - > -/** > - Destroy the socket Sock and its associated protocol control block. > - > - @param Sock The socket to be destroyed. > - > - @retval EFI_SUCCESS The socket Sock is destroyed successfully= . > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et. > - > -**/ > -EFI_STATUS > -SockDestroyChild ( > - IN SOCKET *Sock > - ); > - > -/** > - Configure the specific socket Sock using configuration data ConfigData= . > - > - @param Sock Pointer to the socket to be configured. > - @param ConfigData Pointer to the configuration data. > - > - @retval EFI_SUCCESS The socket is configured successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et or > the > - socket is already configured. > - > -**/ > -EFI_STATUS > -SockConfigure ( > - IN SOCKET *Sock, > - IN VOID *ConfigData > - ); > - > -/** > - Initiate a connection establishment process. > - > - @param Sock Pointer to the socket to initiate the ini= tate the > - connection. > - @param Token Pointer to the token used for the connect= ion > - operation. > - > - @retval EFI_SUCCESS The connection is initialized successfull= y. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not co= nfigured to > - be an active one, or the token is already= in one of > - this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockConnect ( > - IN SOCKET *Sock, > - IN VOID *Token > - ); > - > -/** > - Issue a listen token to get an existed connected network instance > - or wait for a connection if there is none. > - > - @param Sock Pointer to the socket to accept connectio= ns. > - @param Token The token to accept a connection. > - > - @retval EFI_SUCCESS Either a connection is accpeted or the To= ken is > - buffered for further acception. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not co= nfigured to > - be a passive one, or the token is already= in one of > - this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory > limit. > - > -**/ > -EFI_STATUS > -SockAccept ( > - IN SOCKET *Sock, > - IN VOID *Token > - ); > - > -/** > - Issue a token with data to the socket to send out. > - > - @param Sock Pointer to the socket to process the toke= n with > - data. > - @param Token The token with data that needs to send ou= t. > - > - @retval EFI_SUCCESS The token is processed successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not in= a > - synchronized state , or the token is alre= ady in one > - of this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory > limit. > - > -**/ > -EFI_STATUS > -SockSend ( > - IN SOCKET *Sock, > - IN VOID *Token > - ); > - > -/** > - Issue a token to get data from the socket. > - > - @param Sock Pointer to the socket to get data from. > - @param Token The token to store the received data from= the > - socket. > - > - @retval EFI_SUCCESS The token is processed successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not in= a > - synchronized state , or the token is alre= ady in one > - of this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - @retval EFI_CONNECTION_FIN The connection is closed and there is no > more data. > - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory > limit. > - > -**/ > -EFI_STATUS > -SockRcv ( > - IN SOCKET *Sock, > - IN VOID *Token > - ); > - > -/** > - Reset the socket and its associated protocol control block. > - > - @param Sock Pointer to the socket to be flushed. > - > - @retval EFI_SUCCESS The socket is flushed successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et. > - > -**/ > -EFI_STATUS > -SockFlush ( > - IN SOCKET *Sock > - ); > - > -/** > - Close or abort the socket associated connection. > - > - @param Sock Pointer to the socket of the connection t= o close or > - abort. > - @param Token The token for close operation. > - @param OnAbort TRUE for aborting the connection, FALSE t= o close it. > - > - @retval EFI_SUCCESS The close or abort operation is initializ= ed > - successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et, or > the > - socket is closed, or the socket is not in= a > - synchronized state , or the token is alre= ady in one > - of this socket's lists. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockClose ( > - IN SOCKET *Sock, > - IN VOID *Token, > - IN BOOLEAN OnAbort > - ); > - > -/** > - Get the mode data of the low layer protocol. > - > - @param Sock Pointer to the socket to get mode data fr= om. > - @param Mode Pointer to the data to store the low laye= r mode > - information. > - > - @retval EFI_SUCCESS The mode data is got successfully. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockGetMode ( > - IN SOCKET *Sock, > - IN OUT VOID *Mode > - ); > - > -/** > - Add or remove route information in IP route table associated > - with this socket. > - > - @param Sock Pointer to the socket associated with the= IP route > - table to operate on. > - @param RouteInfo Pointer to the route information to be pr= ocessed. > - > - @retval EFI_SUCCESS The route table is updated successfully. > - @retval EFI_ACCESS_DENIED Failed to get the lock to access the sock= et. > - @retval EFI_NO_MAPPING The IP address configuration operation is= not > - finished. > - @retval EFI_NOT_STARTED The socket is not configured. > - > -**/ > -EFI_STATUS > -SockRoute ( > - IN SOCKET *Sock, > - IN VOID *RouteInfo > - ); > - > -// > -// Supporting function to operate on socket buffer > -// > - > -/** > - Get the first buffer block in the specific socket buffer. > - > - @param Sockbuf Pointer to the socket buffer. > - > - @return Pointer to the first buffer in the queue. NULL if the queue is= empty. > - > -**/ > -NET_BUF * > -SockBufFirst ( > - IN SOCK_BUFFER *Sockbuf > - ); > - > -/** > - Get the next buffer block in the specific socket buffer. > - > - @param Sockbuf Pointer to the socket buffer. > - @param SockEntry Pointer to the buffer block prior to the= required > - one. > - > - @return Pointer to the buffer block next to SockEntry. NULL if SockEnt= ry is > - the tail or head entry. > - > -**/ > -NET_BUF * > -SockBufNext ( > - IN SOCK_BUFFER *Sockbuf, > - IN NET_BUF *SockEntry > - ); > - > -#endif > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.h > deleted file mode 100644 > index 368f49c4ddb1..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.h > +++ /dev/null > @@ -1,342 +0,0 @@ > -/** @file > - Tcp driver function header. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _TCP4_DRIVER_H_ > -#define _TCP4_DRIVER_H_ > - > -#include > -#include > - > -#define TCP4_DRIVER_SIGNATURE SIGNATURE_32 ('T', 'C', 'P', '4') > - > -#define TCP4_PORT_KNOWN 1024 > -#define TCP4_PORT_USER_RESERVED 65535 > - > -#define TCP4_FROM_THIS(a) \ > - CR ( \ > - (a), \ > - TCP4_SERVICE_DATA, \ > - Tcp4ServiceBinding, \ > - TCP4_DRIVER_SIGNATURE \ > - ) > - > -/// > -/// TCP heartbeat tick timer. > -/// > -typedef struct _TCP4_HEARTBEAT_TIMER { > - EFI_EVENT TimerEvent; ///< The event assoiated with the timer > - INTN RefCnt; ///< Number of reference > -} TCP4_HEARTBEAT_TIMER; > - > -/// > -/// TCP service data > -/// > -typedef struct _TCP4_SERVICE_DATA { > - UINT32 Signature; > - EFI_HANDLE ControllerHandle; > - IP_IO *IpIo; // IP Io consumed by TCP4 > - EFI_SERVICE_BINDING_PROTOCOL Tcp4ServiceBinding; > - EFI_HANDLE DriverBindingHandle; > - LIST_ENTRY SocketList; > -} TCP4_SERVICE_DATA; > - > -/// > -/// TCP protocol data > -/// > -typedef struct _TCP4_PROTO_DATA { > - TCP4_SERVICE_DATA *TcpService; > - TCP_CB *TcpPcb; > -} TCP4_PROTO_DATA; > - > - > -/** > - Packet receive callback function provided to IP_IO, used to call > - the proper function to handle the packet received by IP. > - > - @param Status Status of the received packet. > - @param IcmpErr ICMP error number. > - @param NetSession Pointer to the net session of this packet. > - @param Pkt Pointer to the recieved packet. > - @param Context Pointer to the context configured in IpIoOpen(), n= ot used > - now. > - > - @return None > - > -**/ > -VOID > -EFIAPI > -Tcp4RxCallback ( > - IN EFI_STATUS Status, > - IN UINT8 IcmpErr, > - IN EFI_NET_SESSION_DATA *NetSession, > - IN NET_BUF *Pkt, > - IN VOID *Context OPTIONAL > - ); > - > -/** > - Send the segment to IP via IpIo function. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the TCP segment to be sent. > - @param Src Source address of the TCP segment. > - @param Dest Destination address of the TCP segment. > - > - @retval 0 The segment was sent out successfully. > - @retval -1 The segment was failed to send. > - > -**/ > -INTN > -TcpSendIpPacket ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf, > - IN UINT32 Src, > - IN UINT32 Dest > - ); > - > -/** > - The procotol handler provided to the socket layer, used to > - dispatch the socket level requests by calling the corresponding > - TCP layer functions. > - > - @param Sock Pointer to the socket of this TCP insta= nce. > - @param Request The code of this operation request. > - @param Data Pointer to the operation specific data = passed in > - together with the operation request. > - > - @retval EFI_SUCCESS The socket request is completed success= fully. > - @retval other The error status returned by the corres= ponding TCP > - layer function. > - > -**/ > -EFI_STATUS > -Tcp4Dispatcher ( > - IN SOCKET *Sock, > - IN UINT8 Request, > - IN VOID *Data OPTIONAL > - ); > - > - > -/** > - The entry point for Tcp4 driver, used to install Tcp4 driver on the Im= ageHandle. > - > - @param ImageHandle The firmware allocated handle for this > - driver image. > - @param SystemTable Pointer to the EFI system table. > - > - @retval EFI_SUCCESS Driver loaded. > - @retval other Driver not loaded. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverEntryPoint ( > - IN EFI_HANDLE ImageHandle, > - IN EFI_SYSTEM_TABLE *SystemTable > - ); > - > - > -/** > - Tests to see if this driver supports a given controller. > - > - If a child device is provided, it further tests to see if this driver = supports > - creating a handle for the specified child device. > - > - @param This A pointer to the EFI_DRIVER_BINDING_PROTO= COL > instance. > - @param ControllerHandle The handle of the controller to test. Thi= s handle > - must support a protocol interface that su= pplies > - an I/O abstraction to the driver. > - @param RemainingDevicePath A pointer to the remaining portion of a d= evice > path. > - This parameter is ignored by device drive= rs, and is optional for > bus drivers. > - > - > - @retval EFI_SUCCESS The device specified by ControllerHandle = and > - RemainingDevicePath is supported by the d= river > - specified by This. > - @retval EFI_ALREADY_STARTED The device specified by ControllerHandle = and > - RemainingDevicePath is already being mana= ged by > - the driver specified by This. > - @retval EFI_ACCESS_DENIED The device specified by ControllerHandle = and > - RemainingDevicePath is already being mana= ged by a > - different driver or an application that r= equires > - exclusive access. > - @retval EFI_UNSUPPORTED The device specified by ControllerHandle = and > - RemainingDevicePath is not supported by t= he driver > - specified by This. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverBindingSupported ( > - IN EFI_DRIVER_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL > - ); > - > -/** > - Start this driver on ControllerHandle. > - > - The Start() function is designed to be invoked from the EFI boot servi= ce > - ConnectController(). As a result, much of the error checking on the pa= rameters > - to Start() has been moved into this common boot service. It is legal t= o call > - Start() from other locations, but the following calling restrictions m= ust be > - followed or the system behavior will not be deterministic. > - 1. ControllerHandle must be a valid EFI_HANDLE. > - 2. If RemainingDevicePath is not NULL, then it must be a pointer to a = naturally > - aligned EFI_DEVICE_PATH_PROTOCOL. > - 3. Prior to calling Start(), the Supported() function for the driver s= pecified > - by This must have been called with the same calling parameters, and > Supported() > - must have returned EFI_SUCCESS. > - > - @param This A pointer to the EFI_DRIVER_BINDING_PROTO= COL > instance. > - @param ControllerHandle The handle of the controller to start. Th= is handle > - must support a protocol interface that su= pplies > - an I/O abstraction to the driver. > - @param RemainingDevicePath A pointer to the remaining portion of a d= evice > path. > - This parameter is ignored by device drive= rs, and is > - optional for bus drivers. > - > - @retval EFI_SUCCESS The device was started. > - @retval EFI_ALREADY_STARTED The device could not be started due to a > device error. > - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to > a lack > - of resources. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverBindingStart ( > - IN EFI_DRIVER_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL > - ); > - > -/** > - Stop this driver on ControllerHandle. > - > - The Stop() function is designed to be invoked from the EFI boot servic= e > - DisconnectController(). As a result, much of the error checking on the > parameters > - to Stop() has been moved into this common boot service. It is legal to= call > Stop() > - from other locations, but the following calling restrictions must be f= ollowed > - or the system behavior will not be deterministic. > - 1. ControllerHandle must be a valid EFI_HANDLE that was used on a prev= ious > call > - to this same driver's Start() function. > - 2. The first NumberOfChildren handles of ChildHandleBuffer must all be= a valid > - EFI_HANDLE. In addition, all of these handles must have been create= d in this > - driver's Start() function, and the Start() function must have calle= d > OpenProtocol() > - on ControllerHandle with an Attribute of > EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. > - > - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL > instance. > - @param ControllerHandle A handle to the device being stopped. The ha= ndle > must > - support a bus specific I/O protocol for the = driver > - to use to stop the device. > - @param NumberOfChildren The number of child device handles in > ChildHandleBuffer. > - @param ChildHandleBuffer An array of child handles to be freed. May b= e > NULL if > - NumberOfChildren is 0. > - > - @retval EFI_SUCCESS The device was stopped. > - @retval EFI_DEVICE_ERROR The device could not be stopped due to a dev= ice > error. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4DriverBindingStop ( > - IN EFI_DRIVER_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ControllerHandle, > - IN UINTN NumberOfChildren, > - IN EFI_HANDLE *ChildHandleBuffer > - ); > - > -/** > - Open Ip4 and device path protocols for a created socket, and insert it= in > - socket list. > - > - @param This Pointer to the socket just created > - @param Context Context of the socket > - > - @retval EFI_SUCCESS This protocol is installed successfully. > - @retval other Some error occured. > - > -**/ > -EFI_STATUS > -Tcp4CreateSocketCallback ( > - IN SOCKET *This, > - IN VOID *Context > - ); > - > -/** > - Close Ip4 and device path protocols for a socket, and remove it from s= ocket > list. > - > - @param This Pointer to the socket to be removed > - @param Context Context of the socket > - > -**/ > -VOID > -Tcp4DestroySocketCallback ( > - IN SOCKET *This, > - IN VOID *Context > - ); > - > -/** > - Creates a child handle and installs a protocol. > - > - The CreateChild() function installs a protocol on ChildHandle. If Chil= dHandle > - is a pointer to NULL, then a new handle is created and returned in Chi= ldHandle. > - If ChildHandle is not a pointer to NULL, then the protocol installs on= the > existing > - ChildHandle. > - > - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instan= ce. > - @param ChildHandle Pointer to the handle of the child to create. If i= t is NULL, > then > - a new handle is created. If it is a pointer to an = existing UEFI > - handle, then the protocol is added to the existing= UEFI handle. > - > - @retval EFI_SUCCES The protocol was added to ChildHandle. > - @retval EFI_INVALID_PARAMETER ChildHandle is NULL. > - @retval EFI_OUT_OF_RESOURCES There are not enough resources available > to create > - the child. > - @retval other The child handle was not created. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4ServiceBindingCreateChild ( > - IN EFI_SERVICE_BINDING_PROTOCOL *This, > - IN OUT EFI_HANDLE *ChildHandle > - ); > - > -/** > - Destroys a child handle with a protocol installed on it. > - > - The DestroyChild() function does the opposite of CreateChild(). It rem= oves a > protocol > - that was installed by CreateChild() from ChildHandle. If the removed p= rotocol > is the > - last protocol on ChildHandle, then ChildHandle is destroyed. > - > - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL insta= nce. > - @param ChildHandle Handle of the child to destroy > - > - @retval EFI_SUCCES The protocol was removed from ChildHandl= e. > - @retval EFI_UNSUPPORTED ChildHandle does not support the protoco= l > that is > - being removed. > - @retval EFI_INVALID_PARAMETER Child handle is NULL. > - @retval EFI_ACCESS_DENIED The protocol could not be removed from t= he > ChildHandle > - because its services are being used. > - @retval other The child handle was not destroyed. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4ServiceBindingDestroyChild ( > - IN EFI_SERVICE_BINDING_PROTOCOL *This, > - IN EFI_HANDLE ChildHandle > - ); > - > -#endif > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf > deleted file mode 100644 > index 7c0504770b48..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf > +++ /dev/null > @@ -1,94 +0,0 @@ > -## @file > -# This module produces EFI TCPv4 Protocol and EFI TCPv4 Service Binding > Protocol. > -# > -# This module produces EFI TCPv4(Transmission Control Protocol version = 4) > Protocol > -# upon EFI IPv4 Protocol, to provide basic TCPv4 I/O services. This dri= ver only > -# supports IPv4 network stack. > -# > -# Notes: > -# 1) This driver can't co-work with the TcpDxe driver in NetworkPkg. > -# 2) This driver might have some issues that have been fixed in the Tcp= Dxe > driver > -# in NetworkPkg. > -# 3) This driver supports fewer features than the TcpDxe driver in Netw= orkPkg > (e.g. IPv6, > -# TCP Cancel function). > -# 4) TcpDxe driver in NetworkPkg is recommended for use instead of this= one > even though > -# both of them can be used. > -# > -# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. > -# This program and the accompanying materials > -# are licensed and made available under the terms and conditions of the= BSD > License > -# which accompanies this distribution. The full text of the license may= be found > at > -# http://opensource.org/licenses/bsd-license.php > -# > -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > -# > -# > -## > - > -[Defines] > - INF_VERSION =3D 0x00010005 > - BASE_NAME =3D Tcp4Dxe > - MODULE_UNI_FILE =3D Tcp4Dxe.uni > - FILE_GUID =3D 6d6963ab-906d-4a65-a7ca-bd40e5d6af4= d > - MODULE_TYPE =3D UEFI_DRIVER > - VERSION_STRING =3D 1.0 > - ENTRY_POINT =3D Tcp4DriverEntryPoint > - UNLOAD_IMAGE =3D NetLibDefaultUnload > -# > -# The following information is for reference only and not required by th= e build > tools. > -# > -# VALID_ARCHITECTURES =3D IA32 X64 EBC > -# > -# DRIVER_BINDING =3D mTcp4DriverBinding > -# COMPONENT_NAME =3D gTcp4ComponentName > -# COMPONENT_NAME2 =3D gTcp4ComponentName2 > -# > - > -[Sources] > - SockImpl.c > - SockInterface.c > - Tcp4Proto.h > - Tcp4Main.h > - SockImpl.h > - Tcp4Output.c > - Tcp4Timer.c > - Tcp4Option.h > - Tcp4Dispatcher.c > - Tcp4Input.c > - Tcp4Misc.c > - Tcp4Main.c > - Socket.h > - ComponentName.c > - Tcp4Driver.h > - Tcp4Io.c > - Tcp4Driver.c > - Tcp4Func.h > - Tcp4Option.c > - > - > -[Packages] > - MdePkg/MdePkg.dec > - MdeModulePkg/MdeModulePkg.dec > - > -[LibraryClasses] > - UefiLib > - UefiBootServicesTableLib > - UefiDriverEntryPoint > - UefiRuntimeServicesTableLib > - BaseMemoryLib > - MemoryAllocationLib > - DebugLib > - NetLib > - IpIoLib > - DevicePathLib > - DpcLib > - > -[Protocols] > - gEfiTcp4ServiceBindingProtocolGuid ## BY_START > - gEfiIp4ServiceBindingProtocolGuid ## TO_START > - gEfiTcp4ProtocolGuid ## BY_START > - gEfiIp4ProtocolGuid ## TO_START > - > -[UserExtensions.TianoCore."ExtraFiles"] > - Tcp4DxeExtra.uni > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.uni > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.uni > deleted file mode 100644 > index 1514a3917766..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.uni > +++ /dev/null > @@ -1,23 +0,0 @@ > -// /** @file > -// This module produces EFI TCPv4 Protocol and EFI TCPv4 Service Binding > Protocol. > -// > -// This module produces EFI TCPv4(Transmission Control Protocol version = 4) > Protocol > -// upon EFI IPv4 Protocol, to provide basic TCPv4 I/O services. > -// > -// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. > -// > -// This program and the accompanying materials > -// are licensed and made available under the terms and conditions of the= BSD > License > -// which accompanies this distribution. The full text of the license may= be found > at > -// http://opensource.org/licenses/bsd-license.php > -// > -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > -// > -// **/ > - > - > -#string STR_MODULE_ABSTRACT #language en-US "Produces EFI TC= Pv4 > Protocol and EFI TCPv4 Service Binding Protocol" > - > -#string STR_MODULE_DESCRIPTION #language en-US "This module > produces EFI TCPv4(Transmission Control Protocol version 4) Protocol upon= EFI > IPv4 Protocol to provide basic TCPv4 I/O services." > - > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4DxeExtra.uni > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4DxeExtra.uni > deleted file mode 100644 > index 0e6d2f2896f3..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4DxeExtra.uni > +++ /dev/null > @@ -1,20 +0,0 @@ > -// /** @file > -// Tcp4Dxe Localized Strings and Content > -// > -// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. > -// > -// This program and the accompanying materials > -// are licensed and made available under the terms and conditions of the= BSD > License > -// which accompanies this distribution. The full text of the license may= be found > at > -// http://opensource.org/licenses/bsd-license.php > -// > -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > -// > -// **/ > - > -#string STR_PROPERTIES_MODULE_NAME > -#language en-US > -"TCP v4 DXE Driver" > - > - > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h > deleted file mode 100644 > index 53b7aac8ae98..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h > +++ /dev/null > @@ -1,781 +0,0 @@ > -/** @file > - Tcp function header file. > - > -Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _TCP4_FUNC_H_ > -#define _TCP4_FUNC_H_ > - > -// > -// Declaration of all the functions in TCP > -// protocol. It is intended to keep tcp.h > -// clear. > -// > - > -// > -// Functions in tcp.c > -// > - > -/** > - Try to find one Tcb whose equals to . > - > - @param Addr Pointer to the IP address needs to match= . > - @param Port The port number needs to match. > - > - @return The Tcb which matches the paire exists or not. > - > -**/ > -BOOLEAN > -TcpFindTcbByPeer ( > - IN EFI_IPv4_ADDRESS *Addr, > - IN TCP_PORTNO Port > - ); > - > -/** > - Locate the TCP_CB related to the socket pair. > - > - @param LocalPort The local port number. > - @param LocalIp The local IP address. > - @param RemotePort The remote port number. > - @param RemoteIp The remote IP address. > - @param Syn Whether to search the listen sockets, if= TRUE, the > - listen sockets are searched. > - > - @return Pointer to the related TCP_CB, if NULL no match is found. > - > -**/ > -TCP_CB * > -TcpLocateTcb ( > - IN TCP_PORTNO LocalPort, > - IN UINT32 LocalIp, > - IN TCP_PORTNO RemotePort, > - IN UINT32 RemoteIp, > - IN BOOLEAN Syn > - ); > - > -/** > - Insert a Tcb into the proper queue. > - > - @param Tcb Pointer to the TCP_CB to be inserted. > - > - @retval 0 The Tcb is inserted successfully. > - @retval -1 Error condition occurred. > - > -**/ > -INTN > -TcpInsertTcb ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Clone a TCP_CB from Tcb. > - > - @param Tcb Pointer to the TCP_CB to be cloned. > - > - @return Pointer to the new cloned TCP_CB, if NULL error condition occ= urred. > - > -**/ > -TCP_CB * > -TcpCloneTcb ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Compute an ISS to be used by a new connection. > - > - @return The result ISS. > - > -**/ > -TCP_SEQNO > -TcpGetIss ( > - VOID > - ); > - > -/** > - Initialize the Tcb local related members. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > -**/ > -VOID > -TcpInitTcbLocal ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Initialize the peer related members. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param Seg Pointer to the segment that contains the= peer's > - intial info. > - @param Opt Pointer to the options announced by the = peer. > - > -**/ > -VOID > -TcpInitTcbPeer ( > - IN OUT TCP_CB *Tcb, > - IN TCP_SEG *Seg, > - IN TCP_OPTION *Opt > - ); > - > -/** > - Get the local mss. > - > - @param Sock Pointer to the socket to get mss > - > - @return The mss size. > - > -**/ > -UINT16 > -TcpGetRcvMss ( > - IN SOCKET *Sock > - ); > - > -/** > - Set the Tcb's state. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param State The state to be set. > - > -**/ > -VOID > -TcpSetState ( > - IN OUT TCP_CB *Tcb, > - IN UINT8 State > - ); > - > -// > -// Functions in Tcp4Output.c > -// > -/** > - Send the segment to IP via IpIo function. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the TCP segment to be sent. > - @param Src Source address of the TCP segment. > - @param Dest Destination address of the TCP segment. > - > - @retval 0 The segment was sent out successfully. > - @retval -1 The segment was failed to send. > - > -**/ > -INTN > -TcpSendIpPacket ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf, > - IN UINT32 Src, > - IN UINT32 Dest > - ); > - > -/** > - Check whether to send data/SYN/FIN and piggy back an ACK. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Force Whether to ignore the sender's SWS avoidance algorithm= and > send > - out data by force. > - > - @return The number of bytes sent. > - > -**/ > -INTN > -TcpToSendData ( > - IN OUT TCP_CB *Tcb, > - IN INTN Force > - ); > - > -/** > - Check whether to send an ACK or delayed ACK. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpToSendAck ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Send an ACK immediately. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpSendAck ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Send a zero probe segment. It can be used by keepalive and zero window > probe. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @retval 0 The zero probe segment was sent out successfully. > - @retval other Error condition occurred. > - > -**/ > -INTN > -TcpSendZeroProbe ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Process the data and FIN flag, check whether to deliver > - data to the socket layer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @retval 0 No error occurred to deliver data. > - @retval -1 Error condition occurred. Proper response is to reset= the > - connection. > - > -**/ > -INTN > -TcpDeliverData ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Send a RESET segment in response to the segment received. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance, may be NUL= L. > - @param Head TCP header of the segment that triggers the reset. > - @param Len Length of the segment that triggers the reset. > - @param Local Local IP address. > - @param Remote Remote peer's IP address. > - > - @retval 0 A reset is sent or no need to send it. > - @retval -1 No reset is sent. > - > -**/ > -INTN > -TcpSendReset ( > - IN TCP_CB *Tcb, > - IN TCP_HEAD *Head, > - IN INT32 Len, > - IN UINT32 Local, > - IN UINT32 Remote > - ); > - > -/** > - Compute the sequence space left in the old receive window. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The sequence space left in the old receive window. > - > -**/ > -UINT32 > -TcpRcvWinOld ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Compute the current receive window. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The size of the current receive window, in bytes. > - > -**/ > -UINT32 > -TcpRcvWinNow ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Retransmit the segment from sequence Seq. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment to be retransmitted= . > - > - @retval 0 Retransmission succeeded. > - @retval -1 Error condition occurred. > - > -**/ > -INTN > -TcpRetransmit ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq > - ); > - > -/** > - Compute how much data to send. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Force Whether to ignore the sender's SWS avoidance algorithm= and > send > - out data by force. > - > - @return The length of the data can be sent, if 0, no data can be sent. > - > -**/ > -UINT32 > -TcpDataToSend ( > - IN TCP_CB *Tcb, > - IN INTN Force > - ); > - > -/** > - Verify that the segment is in good shape. > - > - @param Nbuf Buffer that contains the segment to be checked. > - > - @retval 0 The segment is broken. > - @retval 1 The segment is in good shape. > - > -**/ > -INTN > -TcpVerifySegment ( > - IN NET_BUF *Nbuf > - ); > - > -/** > - Verify that all the segments in SndQue are in good shape. > - > - @param Head Pointer to the head node of the SndQue. > - > - @retval 0 At least one segment is broken. > - @retval 1 All segments in the specific queue are in good shape. > - > -**/ > -INTN > -TcpCheckSndQue ( > - IN LIST_ENTRY *Head > - ); > - > -/** > - Get a segment from the Tcb's SndQue. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment. > - @param Len The maximum length of the segment. > - > - @return Pointer to the segment, if NULL some error occurred. > - > -**/ > -NET_BUF * > -TcpGetSegmentSndQue ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq, > - IN UINT32 Len > - ); > - > -/** > - Get a segment from the Tcb's socket buffer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment. > - @param Len The maximum length of the segment. > - > - @return Pointer to the segment, if NULL some error occurred. > - > -**/ > -NET_BUF * > -TcpGetSegmentSock ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq, > - IN UINT32 Len > - ); > - > -/** > - Get a segment starting from sequence Seq of a maximum > - length of Len. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seq The sequence number of the segment. > - @param Len The maximum length of the segment. > - > - @return Pointer to the segment, if NULL some error occurred. > - > -**/ > -NET_BUF * > -TcpGetSegment ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Seq, > - IN UINT32 Len > - ); > - > -/** > - Get the maximum SndNxt. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The sequence number of the maximum SndNxt. > - > -**/ > -TCP_SEQNO > -TcpGetMaxSndNxt ( > - IN TCP_CB *Tcb > - ); > - > -// > -// Functions from Tcp4Input.c > -// > -/** > - Process the received ICMP error messages for TCP. > - > - @param Nbuf Buffer that contains part of the TCP segment without = IP > header > - truncated from the ICMP error packet. > - @param IcmpErr The ICMP error code interpreted from ICMP error packe= t. > - @param Src Source address of the ICMP error message. > - @param Dst Destination address of the ICMP error message. > - > -**/ > -VOID > -TcpIcmpInput ( > - IN NET_BUF *Nbuf, > - IN UINT8 IcmpErr, > - IN UINT32 Src, > - IN UINT32 Dst > - ); > - > -/** > - Process the received TCP segments. > - > - @param Nbuf Buffer that contains received TCP segment without IP = header. > - @param Src Source address of the segment, or the peer's IP addre= ss. > - @param Dst Destination address of the segment, or the local end'= s IP > - address. > - > - @retval 0 Segment is processed successfully. It is either accep= ted or > - discarded. But no connection is reset by the segment. > - @retval -1 A connection is reset by the segment. > - > -**/ > -INTN > -TcpInput ( > - IN NET_BUF *Nbuf, > - IN UINT32 Src, > - IN UINT32 Dst > - ); > - > -/** > - Check whether the sequence number of the incoming segment is acceptabl= e. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seg Pointer to the incoming segment. > - > - @retval 1 The sequence number is acceptable. > - @retval 0 The sequence number is not acceptable. > - > -**/ > -INTN > -TcpSeqAcceptable ( > - IN TCP_CB *Tcb, > - IN TCP_SEG *Seg > - ); > - > -/** > - NewReno fast recovery, RFC3782. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seg Segment that triggers the fast recovery. > - > -**/ > -VOID > -TcpFastRecover ( > - IN OUT TCP_CB *Tcb, > - IN TCP_SEG *Seg > - ); > - > -/** > - NewReno fast loss recovery, RFC3792. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Seg Segment that triggers the fast loss recovery. > - > -**/ > -VOID > -TcpFastLossRecover ( > - IN OUT TCP_CB *Tcb, > - IN TCP_SEG *Seg > - ); > - > -/** > - Compute the RTT as specified in RFC2988. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Measure Currently measured RTT in heart beats. > - > -**/ > -VOID > -TcpComputeRtt ( > - IN OUT TCP_CB *Tcb, > - IN UINT32 Measure > - ); > - > -/** > - Trim off the data outside the tcb's receive window. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the NET_BUF containing the received tcp se= gment. > - > -**/ > -VOID > -TcpTrimInWnd ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ); > - > -/** > - Store the data into the reassemble queue. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer containing the data to be queue= d. > - > -**/ > -VOID > -TcpQueueData ( > - IN OUT TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ); > - > -/** > - Ajust the send queue or the retransmit queue. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Ack The acknowledge seuqence number of the received segme= nt. > - > -**/ > -VOID > -TcpAdjustSndQue ( > - IN TCP_CB *Tcb, > - IN TCP_SEQNO Ack > - ); > - > -// > -// Functions from Tcp4Misc.c > -// > -/** > - Compute the TCP segment's checksum. > - > - @param Nbuf Pointer to the buffer that contains the = TCP > - segment. > - @param HeadSum The checksum value of the fixed part of = pseudo > - header. > - > - @return The checksum value. > - > -**/ > -UINT16 > -TcpChecksum ( > - IN NET_BUF *Nbuf, > - IN UINT16 HeadSum > - ); > - > -/** > - Translate the information from the head of the received TCP > - segment Nbuf contains and fill it into a TCP_SEG structure. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - @param Nbuf Pointer to the buffer contains the TCP s= egment. > - > - @return Pointer to the TCP_SEG that contains the translated TCP head > information. > - > -**/ > -TCP_SEG * > -TcpFormatNetbuf ( > - IN TCP_CB *Tcb, > - IN OUT NET_BUF *Nbuf > - ); > - > -/** > - Initialize an active connection. > - > - @param Tcb Pointer to the TCP_CB that wants to init= iate a > - connection. > - > -**/ > -VOID > -TcpOnAppConnect ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Application has consumed some data, check whether > - to send a window updata ack or a delayed ack. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > -**/ > -VOID > -TcpOnAppConsume ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Initiate the connection close procedure, called when > - applications want to close the connection. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > -**/ > -VOID > -TcpOnAppClose ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Check whether the application's newly delivered data can be sent out. > - > - @param Tcb Pointer to the TCP_CB of this TCP instan= ce. > - > - @retval 0 Whether the data is sent out or is buffe= red for > - further sending. > - @retval -1 The Tcb is not in a state that data is p= ermitted to > - be sent out. > - > -**/ > -INTN > -TcpOnAppSend ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Abort the connection by sending a reset segment, called > - when the application wants to abort the connection. > - > - @param Tcb Pointer to the TCP_CB of the TCP instanc= e. > - > -**/ > -VOID > -TcpOnAppAbort ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Reset the connection related with Tcb. > - > - @param Tcb Pointer to the TCP_CB of the connection = to be > - reset. > - > -**/ > -VOID > -TcpResetConnection ( > - IN TCP_CB *Tcb > - ); > - > -// > -// Functions in Tcp4Timer.c > -// > -/** > - Close the TCP connection. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpClose ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Heart beat timer handler, queues the DPC at TPL_CALLBACK. > - > - @param Event Timer event signaled, ignored. > - @param Context Context of the timer event, ignored. > - > -**/ > -VOID > -EFIAPI > -TcpTicking ( > - IN EFI_EVENT Event, > - IN VOID *Context > - ); > - > -/** > - Enable a TCP timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Timer The index of the timer to be enabled. > - @param TimeOut The timeout value of this timer. > - > -**/ > -VOID > -TcpSetTimer ( > - IN OUT TCP_CB *Tcb, > - IN UINT16 Timer, > - IN UINT32 TimeOut > - ); > - > -/** > - Clear one TCP timer. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Timer The index of the timer to be cleared. > - > -**/ > -VOID > -TcpClearTimer ( > - IN OUT TCP_CB *Tcb, > - IN UINT16 Timer > - ); > - > -/** > - Clear all TCP timers. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpClearAllTimer ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Enable the window prober timer and set the timeout value. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpSetProbeTimer ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Enable the keepalive timer and set the timeout value. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpSetKeepaliveTimer ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Backoff the RTO. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > -**/ > -VOID > -TcpBackoffRto ( > - IN OUT TCP_CB *Tcb > - ); > - > -/** > - Install the device path protocol on the TCP instance. > - > - @param Sock Pointer to the socket representing the TCP in= stance. > - > - @retval EFI_SUCCESS The device path protocol is installed. > - @retval other Failed to install the device path protocol. > - > -**/ > -EFI_STATUS > -TcpInstallDevicePath ( > - IN SOCKET *Sock > - ); > - > -#endif > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.h > deleted file mode 100644 > index c898a7ee2dd0..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.h > +++ /dev/null > @@ -1,494 +0,0 @@ > -/** @file > - TCP4 protocol services header file. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _TCP4_MAIN_H_ > -#define _TCP4_MAIN_H_ > - > -#include "Socket.h" > - > -#include "Tcp4Proto.h" > -#include "Tcp4Func.h" > -#include "Tcp4Driver.h" > - > - > -extern UINT16 mTcp4RandomPort; > -extern CHAR16 *mTcpStateName[]; > - > -// > -// Driver Produced Protocol Prototypes > -// > - > -// > -// Function prototype for the Tcp4 socket request handler > -// > -/** > - The procotol handler provided to the socket layer, used to > - dispatch the socket level requests by calling the corresponding > - TCP layer functions. > - > - @param Sock Pointer to the socket of this TCP insta= nce. > - @param Request The code of this operation request. > - @param Data Pointer to the operation specific data = passed in > - together with the operation request. > - > - @retval EFI_SUCCESS The socket request is completed success= fully. > - @retval other The error status returned by the corres= ponding TCP > - layer function. > - > -**/ > -EFI_STATUS > -Tcp4Dispatcher ( > - IN SOCKET *Sock, > - IN UINT8 Request, > - IN VOID *Data OPTIONAL > - ); > - > -/// > -/// TCP mode data > -/// > -typedef struct _TCP4_MODE_DATA { > - EFI_TCP4_CONNECTION_STATE *Tcp4State; > - EFI_TCP4_CONFIG_DATA *Tcp4ConfigData; > - EFI_IP4_MODE_DATA *Ip4ModeData; > - EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData; > - EFI_SIMPLE_NETWORK_MODE *SnpModeData; > -} TCP4_MODE_DATA; > - > -/// > -/// TCP route infomation data > -/// > -typedef struct _TCP4_ROUTE_INFO { > - BOOLEAN DeleteRoute; > - EFI_IPv4_ADDRESS *SubnetAddress; > - EFI_IPv4_ADDRESS *SubnetMask; > - EFI_IPv4_ADDRESS *GatewayAddress; > -} TCP4_ROUTE_INFO; > - > -typedef struct { > - EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; > - UINTN NumberOfChildren; > - EFI_HANDLE *ChildHandleBuffer; > -} TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT; > - > -/** > - Get the current operational status of a TCP instance. > - > - The GetModeData() function copies the current operational settings of = this > - EFI TCPv4 Protocol instance into user-supplied buffers. This function = can > - also be used to retrieve the operational setting of underlying drivers > - such as IPv4, MNP, or SNP. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param Tcp4State Pointer to the buffer to receive the = current TCP > - state. > - @param Tcp4ConfigData Pointer to the buffer to receive the = current > TCP > - configuration. > - @param Ip4ModeData Pointer to the buffer to receive the = current > IPv4 > - configuration data used by the TCPv4 = instance. > - @param MnpConfigData Pointer to the buffer to receive the = current > MNP > - configuration data indirectly used by= the TCPv4 > - Instance. > - @param SnpModeData Pointer to the buffer to receive the = current > SNP > - configuration data indirectly used by= the TCPv4 > - Instance. > - > - @retval EFI_SUCCESS The mode data was read. > - @retval EFI_NOT_STARTED No configuration data is available be= cause > this > - instance hasn't been started. > - @retval EFI_INVALID_PARAMETER This is NULL. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4GetModeData ( > - IN EFI_TCP4_PROTOCOL *This, > - OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL, > - OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL, > - OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL, > - OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData > OPTIONAL, > - OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL > - ); > - > - > -/** > - Initialize or brutally reset the operational parameters for > - this EFI TCPv4 instance. > - > - The Configure() function does the following: > - * Initialize this EFI TCPv4 instance, i.e., initialize the communicati= on end > - setting, specify active open or passive open for an instance. > - * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchr= onous > - tokens, flush transmission and receiving buffer directly without infor= ming > - the communication peer. > - No other TCPv4 Protocol operation can be executed by this instance > - until it is configured properly. For an active TCP4 instance, after a = proper > - configuration it may call Connect() to initiates the three-way handsha= ke. > - For a passive TCP4 instance, its state will transit to Tcp4StateListen= after > - configuration, and Accept() may be called to listen the incoming TCP > connection > - request. If TcpConfigData is set to NULL, the instance is reset. Reset= ting > - process will be done brutally, the state machine will be set to Tcp4St= ateClosed > - directly, the receive queue and transmit queue will be flushed, and no= traffic is > - allowed through this instance. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param TcpConfigData Pointer to the configure data to conf= igure the > - instance. > - > - @retval EFI_SUCCESS The operational settings are set, cha= nged, or > - reset successfully. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (through DHCP, BOOTP, RARP, etc.) is = not > - finished. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_ACCESS_DENIED Configuring TCP instance when it is a= lready > - configured. > - @retval EFI_DEVICE_ERROR An unexpected network or system error > occurred. > - @retval EFI_UNSUPPORTED One or more of the control options ar= e not > - supported in the implementation. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough system > resources. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Configure ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL > - ); > - > -/** > - Add or delete routing entries. > - > - The Routes() function adds or deletes a route from the instance's rout= ing table. > - The most specific route is selected by comparing the SubnetAddress wit= h the > - destination IP address's arithmetical AND to the SubnetMask. > - The default route is added with both SubnetAddress and SubnetMask set = to > 0.0.0.0. > - The default route matches all destination IP addresses if there is no = more > specific route. > - Direct route is added with GatewayAddress set to 0.0.0.0. Packets are = sent to > - the destination host if its address can be found in the Address Resolu= tion > Protocol (ARP) > - cache or it is on the local subnet. If the instance is configured to u= se default > - address, a direct route to the local network will be added automatical= ly. > - Each TCP instance has its own independent routing table. Instance that= uses > the > - default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's > routing table. > - The copy will be updated automatically whenever the IP driver reconfig= ures its > - instance. As a result, the previous modification to the instance's loc= al copy > - will be lost. The priority of checking the route table is specific wit= h IP > - implementation and every IP implementation must comply with RFC 1122. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param DeleteRoute If TRUE, delete the specified route f= rom routing > - table; if FALSE, add the specified ro= ute to > - routing table. > - DestinationAddress and SubnetMask are= used as > - the keywords to search route entry. > - @param SubnetAddress The destination network. > - @param SubnetMask The subnet mask for the destination n= etwork. > - @param GatewayAddress The gateway address for this route. > - It must be on the same subnet with th= e station > - address unless a direct route is spec= ified. > - > - @retval EFI_SUCCESS The operation completed successfully. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has no= t > been > - configured. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (through DHCP, BOOTP, RARP, etc.) is = not > - finished. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources t= o > add the > - entry to the routing table. > - @retval EFI_NOT_FOUND This route is not in the routing tabl= e. > - @retval EFI_ACCESS_DENIED This route is already in the routing = table. > - @retval EFI_UNSUPPORTED The TCP driver does not support this > operation. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Routes ( > - IN EFI_TCP4_PROTOCOL *This, > - IN BOOLEAN DeleteRoute, > - IN EFI_IPv4_ADDRESS *SubnetAddress, > - IN EFI_IPv4_ADDRESS *SubnetMask, > - IN EFI_IPv4_ADDRESS *GatewayAddress > - ); > - > -/** > - Initiate a nonblocking TCP connection request for an active TCP instan= ce. > - > - The Connect() function will initiate an active open to the remote peer > configured > - in current TCP instance if it is configured active. If the connection = succeeds > - or fails due to any error, the ConnectionToken->CompletionToken.Event = will > be > - signaled and ConnectionToken->CompletionToken.Status will be updated > accordingly. > - This function can only be called for the TCP instance in Tcp4StateClos= ed state. > - The instance will transfer into Tcp4StateSynSent if the function retur= ns > EFI_SUCCESS. > - If TCP three way handshake succeeds, its state will become > Tcp4StateEstablished, > - otherwise, the state will return to Tcp4StateClosed. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance > - @param ConnectionToken Pointer to the connection token to re= turn > when > - the TCP three way handshake finishes. > - > - @retval EFI_SUCCESS The connection request is successfull= y initiated > - and the state of this TCPv4 instance = has > - been changed to Tcp4StateSynSent. > - @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn'= t > been > - configured. > - @retval EFI_ACCESS_DENIED The instance is not configured as an = active > one > - or it is not in Tcp4StateClosed state= . > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough > resource to > - initiate the active open. > - @retval EFI_DEVICE_ERROR An unexpected system or network error > occurred. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Connect ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken > - ); > - > -/** > - Listen on the passive instance to accept an incoming connection reques= t. > - > - The Accept() function initiates an asynchronous accept request to wait= for an > - incoming connection on the passive TCP instance. If a remote peer > successfully > - establishes a connection with this instance, a new TCP instance will b= e created > - and its handle will be returned in ListenToken->NewChildHandle. The ne= wly > created > - instance is configured by inheriting the passive instance's configurat= ion and is > - ready for use upon return. The instance is in the Tcp4StateEstablished= state. > - The ListenToken->CompletionToken.Event will be signaled when a new > connection > - is accepted, user aborts the listen or connection is reset. This funct= ion only > - can be called when current TCP instance is in Tcp4StateListen state. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance > - @param ListenToken Pointer to the listen token to return= when > - operation finishes. > - > - @retval EFI_SUCCESS The listen token has been queued succ= essfully. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_ACCESS_DENIED The instatnce is not a passive one or= it is not > - in Tcp4StateListen state or a same li= sten token > - has already existed in the listen tok= en queue of > - this TCP instance. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources t= o > finish > - the operation. > - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to ab= ove > category error. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Accept ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_LISTEN_TOKEN *ListenToken > - ); > - > -/** > - Queues outgoing data into the transmit queue. > - > - The Transmit() function queues a sending request to this TCPv4 instanc= e along > - with the user data. The status of the token is updated and the event i= n the > token > - will be signaled once the data is sent out or some error occurs. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance > - @param Token Pointer to the completion token to qu= eue to the > - transmit queue > - > - @retval EFI_SUCCESS The data has been queued for transmis= sion. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (DHCP, BOOTP, RARP, etc.) is not fini= shed yet. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_ACCESS_DENIED One or more of the following conditio= ns is > TRUE: > - * A transmit completion token with th= e same > - Token-> CompletionToken.Event was a= lready in the > - transmission queue. > - * The current instance is in Tcp4Stat= eClosed state > - * The current instance is a passive o= ne and > - it is in Tcp4StateListen state. > - * User has called Close() to disconne= ct this > - connection. > - @retval EFI_NOT_READY The completion token could not be que= ued > because > - the transmit queue is full. > - @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data > because of > - resource shortage. > - @retval EFI_NETWORK_UNREACHABLE There is no route to the destination > network or > - address. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Transmit ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_IO_TOKEN *Token > - ); > - > -/** > - Place an asynchronous receive request into the receiving queue. > - > - The Receive() function places a completion token into the receive pack= et > queue. > - This function is always asynchronous. The caller must allocate the > - Token->CompletionToken.Event and the FragmentBuffer used to receive da= ta. > He also > - must fill the DataLength which represents the whole length of all > FragmentBuffer. > - When the receive operation completes, the EFI TCPv4 Protocol driver up= dates > the > - Token->CompletionToken.Status and Token->Packet.RxData fields and the > - Token->CompletionToken.Event is signaled. If got data the data and its= length > - will be copy into the FragmentTable, in the same time the full length = of > received > - data will be recorded in the DataLength fields. Providing a proper not= ification > - function and context for the event will enable the user to receive the > notification > - and receiving status. That notification function is guaranteed to not = be re- > entered. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param Token Pointer to a token that is associated= with the > - receive data descriptor. > - > - @retval EFI_SUCCESS The receive completion token was cach= ed. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_NO_MAPPING When using a default address, configu= ration > - (DHCP, BOOTP, RARP, etc.) is not fini= shed yet. > - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES The receive completion token could no= t > be queued > - due to a lack of system resources. > - @retval EFI_DEVICE_ERROR An unexpected system or network error > occurred. > - The EFI TCPv4 Protocol instance has b= een reset > - to startup defaults. > - @retval EFI_ACCESS_DENIED One or more of the following conditio= ns is > TRUE: > - * A receive completion token with the= same > - Token->CompletionToken.Event was al= ready in > - the receive queue. > - * The current instance is in Tcp4Stat= eClosed state. > - * The current instance is a passive o= ne and it > - is in Tcp4StateListen state. > - * User has called Close() to disconne= ct this > - connection. > - @retval EFI_CONNECTION_FIN The communication peer has closed the > connection > - and there is no any buffered data in = the receive > - buffer of this instance. > - @retval EFI_NOT_READY The receive request could not be queu= ed > because > - the receive queue is full. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Receive ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_IO_TOKEN *Token > - ); > - > -/** > - Disconnecting a TCP connection gracefully or reset a TCP connection. > - > - Initiate an asynchronous close token to TCP driver. After Close() is c= alled, > - any buffered transmission data will be sent by TCP driver and the curr= ent > - instance will have a graceful close working flow described as RFC 793 = if > - AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by= TCP > - driver to fast disconnect this connection. When the close operation co= mpletes > - successfully the TCP instance is in Tcp4StateClosed state, all pending > - asynchronous operation is signaled and any buffers used for TCP networ= k > traffic > - is flushed. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param CloseToken Pointer to the close token to return = when > - operation finishes. > - > - @retval EFI_SUCCESS The operation completed successfully. > - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't > been > - configured. > - @retval EFI_ACCESS_DENIED One or more of the following are TRUE= : > - * Configure() has been called with Tc= pConfigData > - set to NULL and this function has n= ot returned. > - * Previous Close() call on this insta= nce has not > - finished. > - @retval EFI_INVALID_PARAMETER One ore more parameters are invalid. > - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to > finish the > - operation. > - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to ab= ove > - category error. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Close ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_CLOSE_TOKEN *CloseToken > - ); > - > -/** > - Abort an asynchronous connection, listen, transmission or receive requ= est. > - > - The Cancel() function aborts a pending connection, listen, transmit or= receive > - request. If Token is not NULL and the token is in the connection, list= en, > - transmission or receive queue when it is being cancelled, its Token->S= tatus > - will be set to EFI_ABORTED and then Token->Event will be signaled. If = the > token > - is not in one of the queues, which usually means that the asynchronous > operation > - has completed, EFI_NOT_FOUND is returned. If Token is NULL all > asynchronous token > - issued by Connect(), Accept(), Transmit() and Receive()will be aborted= . > - NOTE: It has not been implemented currently. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - @param Token Pointer to a token that has been issu= ed by > - Connect(), Accept(), Transmit() or Re= ceive(). If > - NULL, all pending tokens issued by ab= ove four > - functions will be aborted. > - > - @retval EFI_SUCCESS The asynchronous I/O request is abort= ed and > Token->Event > - is signaled. > - @retval EFI_INVALID_PARAMETER This is NULL. > - @retval EFI_NOT_STARTED This instance hasn's been configured. > - @retval EFI_NO_MAPPING When using the default address, > configuration > - (DHCP, BOOTP,RARP, etc.) hasn's finis= hed yet. > - @retval EFI_NOT_FOUND The asynchronous I/O request isn's fo= und in > the > - transmission or receive queue. It has= either > - completed or wasn's issued by Transmi= t() and Receive(). > - @retval EFI_UNSUPPORTED The operation is not supported in cur= rent > - implementation. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Cancel ( > - IN EFI_TCP4_PROTOCOL *This, > - IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL > - ); > - > -/** > - Poll to receive incoming data and transmit outgoing segments. > - > - The Poll() function increases the rate that data is moved between the = network > - and application and can be called when the TCP instance is created > successfully. > - Its use is optional. In some implementations, the periodical timer in = the MNP > - driver may not poll the underlying communications device fast enough t= o > avoid > - drop packets. Drivers and applications that are experiencing packet lo= ss should > - try calling the Poll() function in a high frequency. > - > - @param This Pointer to the EFI_TCP4_PROTOCOL inst= ance. > - > - @retval EFI_SUCCESS Incoming or outgoing data was process= ed. > - @retval EFI_INVALID_PARAMETER This is NULL. > - @retval EFI_DEVICE_ERROR An unexpected system or network error > occurred. > - @retval EFI_NOT_READY No incoming or outgoing data was proc= essed. > - @retval EFI_TIMEOUT Data was dropped out of the transmiss= ion or > - receive queue. Consider increasing th= e polling > - rate. > - > -**/ > -EFI_STATUS > -EFIAPI > -Tcp4Poll ( > - IN EFI_TCP4_PROTOCOL *This > - ); > - > -#endif > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.h > deleted file mode 100644 > index f9782cb59801..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.h > +++ /dev/null > @@ -1,130 +0,0 @@ > -/** @file > - Tcp option's routine header file. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _TCP4_OPTION_H_ > -#define _TCP4_OPTION_H_ > - > -/// > -/// The structure to store the parse option value. > -/// ParseOption only parse the options, don't process them. > -/// > -typedef struct _TCP_OPTION { > - UINT8 Flag; ///< Flag such as TCP_OPTION_RCVD_MSS > - UINT8 WndScale; ///< The WndScale received > - UINT16 Mss; ///< The Mss received > - UINT32 TSVal; ///< The TSVal field in a timestamp option > - UINT32 TSEcr; ///< The TSEcr field in a timestamp option > -} TCP_OPTION; > - > -// > -// supported TCP option type and their length > -// > -#define TCP_OPTION_EOP 0 ///< End Of oPtion > -#define TCP_OPTION_NOP 1 ///< No-Option. > -#define TCP_OPTION_MSS 2 ///< Maximum Segment Size > -#define TCP_OPTION_WS 3 ///< Window scale > -#define TCP_OPTION_TS 8 ///< Timestamp > -#define TCP_OPTION_MSS_LEN 4 ///< Length of MSS option > -#define TCP_OPTION_WS_LEN 3 ///< Length of window scale option > -#define TCP_OPTION_TS_LEN 10 ///< Length of timestamp option > -#define TCP_OPTION_WS_ALIGNED_LEN 4 ///< Length of window scale > option, aligned > -#define TCP_OPTION_TS_ALIGNED_LEN 12 ///< Length of timestamp option, > aligned > - > -// > -// recommend format of timestamp window scale > -// option for fast process. > -// > -#define TCP_OPTION_TS_FAST ((TCP_OPTION_NOP << 24) | \ > - (TCP_OPTION_NOP << 16) | \ > - (TCP_OPTION_TS << 8) | \ > - (TCP_OPTION_TS_LEN)) > - > -#define TCP_OPTION_WS_FAST ((TCP_OPTION_NOP << 24) | \ > - (TCP_OPTION_WS << 16) | \ > - (TCP_OPTION_WS_LEN << 8)) > - > -#define TCP_OPTION_MSS_FAST ((TCP_OPTION_MSS << 24) | > (TCP_OPTION_MSS_LEN << 16)) > - > -// > -// Other misc definations > -// > -#define TCP_OPTION_RCVD_MSS 0x01 > -#define TCP_OPTION_RCVD_WS 0x02 > -#define TCP_OPTION_RCVD_TS 0x04 > -#define TCP_OPTION_MAX_WS 14 ///< Maxium window scale valu= e > -#define TCP_OPTION_MAX_WIN 0xffff ///< Max window size in TCP > header > - > - > -/** > - Compute the window scale value according to the given buffer size. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - > - @return The scale value. > - > -**/ > -UINT8 > -TcpComputeScale ( > - IN TCP_CB *Tcb > - ); > - > -/** > - Build the TCP option in three-way handshake. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer to store the options. > - > - @return The total length of the TCP option field. > - > -**/ > -UINT16 > -TcpSynBuildOption ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ); > - > -/** > - Build the TCP option in synchronized states. > - > - @param Tcb Pointer to the TCP_CB of this TCP instance. > - @param Nbuf Pointer to the buffer to store the options. > - > - @return The total length of the TCP option field. > - > -**/ > -UINT16 > -TcpBuildOption ( > - IN TCP_CB *Tcb, > - IN NET_BUF *Nbuf > - ); > - > -/** > - Parse the supported options. > - > - @param Tcp Pointer to the TCP_CB of this TCP instance. > - @param Option Pointer to the TCP_OPTION used to store the successful= ly > pasrsed > - options. > - > - @retval 0 The options are successfully pasrsed. > - @retval -1 Ilegal option was found. > - > -**/ > -INTN > -TcpParseOption ( > - IN TCP_HEAD *Tcp, > - IN OUT TCP_OPTION *Option > - ); > - > - > -#endif > diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Proto.h > b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Proto.h > deleted file mode 100644 > index 37191fe65112..000000000000 > --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Proto.h > +++ /dev/null > @@ -1,357 +0,0 @@ > -/** @file > - Tcp Protocol header file. > - > -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> -This program and the accompanying materials > -are licensed and made available under the terms and conditions of the BS= D > License > -which accompanies this distribution. The full text of the license may b= e found > at > -http://opensource.org/licenses/bsd-license.php
> - > -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > - > -**/ > - > -#ifndef _TCP4_PROTO_H_ > -#define _TCP4_PROTO_H_ > - > -typedef struct _TCP_CB TCP_CB; > - > -#include "Tcp4Driver.h" > -#include "Socket.h" > -#include "Tcp4Option.h" > - > - > - > -/// > -/// Tcp states, Don't change their order, it is used as > -/// index to mTcpOutFlag and other macros > -/// > -#define TCP_CLOSED 0 > -#define TCP_LISTEN 1 > -#define TCP_SYN_SENT 2 > -#define TCP_SYN_RCVD 3 > -#define TCP_ESTABLISHED 4 > -#define TCP_FIN_WAIT_1 5 > -#define TCP_FIN_WAIT_2 6 > -#define TCP_CLOSING 7 > -#define TCP_TIME_WAIT 8 > -#define TCP_CLOSE_WAIT 9 > -#define TCP_LAST_ACK 10 > - > - > -/// > -/// Flags in the TCP header > -/// > -#define TCP_FLG_FIN 0x01 > -#define TCP_FLG_SYN 0x02 > -#define TCP_FLG_RST 0x04 > -#define TCP_FLG_PSH 0x08 > -#define TCP_FLG_ACK 0x10 > -#define TCP_FLG_URG 0x20 > - > - // > - // mask for all the flags > - // > -#define TCP_FLG_FLAG 0x3F > - > - > -#define TCP_CONNECT_REFUSED (-1) ///< TCP error status > -#define TCP_CONNECT_RESET (-2) ///< TCP error status > -#define TCP_CONNECT_CLOSED (-3) ///< TCP error status > - > -// > -// Current congestion status as suggested by RFC3782. > -// > -#define TCP_CONGEST_RECOVER 1 ///< During the NewReno fast recover= y > -#define TCP_CONGEST_LOSS 2 ///< Retxmit because of retxmit time= out > -#define TCP_CONGEST_OPEN 3 ///< TCP is opening its congestion w= indow > - > -// > -// TCP control flags > -// > -#define TCP_CTRL_NO_NAGLE 0x0001 ///< Disable Nagle algorithm > -#define TCP_CTRL_NO_KEEPALIVE 0x0002 ///< Disable keepalive timer > -#define TCP_CTRL_NO_WS 0x0004 ///< Disable window scale option > -#define TCP_CTRL_RCVD_WS 0x0008 ///< Received a wnd scale option= in > syn > -#define TCP_CTRL_NO_TS 0x0010 ///< Disable Timestamp option > -#define TCP_CTRL_RCVD_TS 0x0020 ///< Received a Timestamp option= in > syn > -#define TCP_CTRL_SND_TS 0x0040 ///< Send Timestamp option to re= mote > -#define TCP_CTRL_SND_URG 0x0080 ///< In urgent send mode > -#define TCP_CTRL_RCVD_URG 0x0100 ///< In urgent receive mode > -#define TCP_CTRL_SND_PSH 0x0200 ///< In PUSH send mode > -#define TCP_CTRL_FIN_SENT 0x0400 ///< FIN is sent > -#define TCP_CTRL_FIN_ACKED 0x0800 ///< FIN is ACKed. > -#define TCP_CTRL_TIMER_ON 0x1000 ///< At least one of the timer i= s on > -#define TCP_CTRL_RTT_ON 0x2000 ///< The RTT measurement is on > -#define TCP_CTRL_ACK_NOW 0x4000 ///< Send the ACK now, don't del= ay > - > -// > -// Timer related values > -// > -#define TCP_TIMER_CONNECT 0 ///< Connection esta= blishment > timer > -#define TCP_TIMER_REXMIT 1 ///< Retransmit time= r > -#define TCP_TIMER_PROBE 2 ///< Window probe ti= mer > -#define TCP_TIMER_KEEPALIVE 3 ///< Keepalive timer > -#define TCP_TIMER_FINWAIT2 4 ///< FIN_WAIT_2 time= r > -#define TCP_TIMER_2MSL 5 ///< TIME_WAIT tiemr > -#define TCP_TIMER_NUMBER 6 ///< The total numbe= r of TCP > timer. > -#define TCP_TICK 200 ///< Every TCP tick = is 200ms > -#define TCP_TICK_HZ 5 ///< The frequence o= f TCP tick > -#define TCP_RTT_SHIFT 3 ///< SRTT & RTTVAR s= caled by 8 > -#define TCP_RTO_MIN TCP_TICK_HZ ///< The minium valu= e of RTO > -#define TCP_RTO_MAX (TCP_TICK_HZ * 60) ///< The maxium valu= e of > RTO > -#define TCP_FOLD_RTT 4 ///< Timeout thresho= d to fold RTT > - > -// > -// Default values for some timers > -// > -#define TCP_MAX_LOSS 12 ///< Defaul= t max times to > retxmit > -#define TCP_KEEPALIVE_IDLE_MIN (TCP_TICK_HZ * 60 * 60 * 2) ///< First = keep > alive > -#define TCP_KEEPALIVE_PERIOD (TCP_TICK_HZ * 60) > -#define TCP_MAX_KEEPALIVE 8 > -#define TCP_FIN_WAIT2_TIME (2 * TCP_TICK_HZ) > -#define TCP_TIME_WAIT_TIME (2 * TCP_TICK_HZ) > -#define TCP_PAWS_24DAY (24 * 24 * 60 * 60 * TCP_TICK_HZ) > -#define TCP_CONNECT_TIME (75 * TCP_TICK_HZ) > - > -// > -// The header space to be reserved before TCP data to accomodate : > -// 60byte IP head + 60byte TCP head + link layer head > -// > -#define TCP_MAX_HEAD 192 > - > -// > -// Value ranges for some control option > -// > -#define TCP_RCV_BUF_SIZE (2 * 1024 * 1024) > -#define TCP_RCV_BUF_SIZE_MIN (8 * 1024) > -#define TCP_SND_BUF_SIZE (2 * 1024 * 1024) > -#define TCP_SND_BUF_SIZE_MIN (8 * 1024) > -#define TCP_BACKLOG 10 > -#define TCP_BACKLOG_MIN 5 > -#define TCP_MAX_LOSS_MIN 6 > -#define TCP_CONNECT_TIME_MIN (60 * TCP_TICK_HZ) > -#define TCP_MAX_KEEPALIVE_MIN 4 > -#define TCP_KEEPALIVE_IDLE_MAX (TCP_TICK_HZ * 60 * 60 * 4) > -#define TCP_KEEPALIVE_PERIOD_MIN (TCP_TICK_HZ * 30) > -#define TCP_FIN_WAIT2_TIME_MAX (4 * TCP_TICK_HZ) > -#define TCP_TIME_WAIT_TIME_MAX (60 * TCP_TICK_HZ) > - > -/// > -/// TCP segmentation data > -/// > -typedef struct _TCP_SEG { > - TCP_SEQNO Seq; ///< Starting sequence number > - TCP_SEQNO End; ///< The sequence of the last byte + 1, include SYN/FI= N. > End-Seq =3D SEG.LEN > - TCP_SEQNO Ack; ///< ACK field in the segment > - UINT8 Flag; ///< TCP header flags > - UINT16 Urg; ///< Valid if URG flag is set. > - UINT32 Wnd; ///< TCP window size field > -} TCP_SEG; > - > -/// > -/// Network endpoint, IP+Port structure > -/// > -typedef struct _TCP_PEER { > - UINT32 Ip; ///< IP address, network byte order > - TCP_PORTNO Port; ///< Port number, network byte order > -} TCP_PEER; > - > -/// > -/// TCP control block, it includes various states > -/// > -struct _TCP_CB { > - LIST_ENTRY List; ///< Back and forward link entry > - TCP_CB *Parent; ///< The parent TCP_CB structure > - > - SOCKET *Sk; ///< The socket it controled. > - TCP_PEER LocalEnd; ///< Local endpoint > - TCP_PEER RemoteEnd;///< Remote endpoint > - > - LIST_ENTRY SndQue; ///< Retxmission queue > - LIST_ENTRY RcvQue; ///< Reassemble queue > - UINT32 CtrlFlag; ///< Control flags, such as NO_NAGLE > - INT32 Error; ///< Soft error status, such as TCP_CONNEC= T_RESET > - > - // > - // RFC793 and RFC1122 defined variables > - // > - UINT8 State; ///< TCP state, such as SYN_SENT, LISTEN > - UINT8 DelayedAck; ///< Number of delayed ACKs > - UINT16 HeadSum; ///< Checksum of the fixed parts of pesu= do > - ///< header: Src IP, Dst IP, 0, Protocol= , > - ///< not include the TCP length. > - > - TCP_SEQNO Iss; ///< Initial Sending Sequence > - TCP_SEQNO SndUna; ///< First unacknowledged data > - TCP_SEQNO SndNxt; ///< Next data sequence to send. > - TCP_SEQNO SndPsh; ///< Send PUSH point > - TCP_SEQNO SndUp; ///< Send urgent point > - UINT32 SndWnd; ///< Window advertised by the remote pee= r > - UINT32 SndWndMax; ///< Max send window advertised by the p= eer > - TCP_SEQNO SndWl1; ///< Seq number used for last window upd= ate > - TCP_SEQNO SndWl2; ///< Ack no of last window update > - UINT16 SndMss; ///< Max send segment size > - TCP_SEQNO RcvNxt; ///< Next sequence no to receive > - UINT32 RcvWnd; ///< Window advertised by the local peer > - TCP_SEQNO RcvWl2; ///< The RcvNxt (or ACK) of last window = update. > - ///< It is necessary because of delayed = ACK > - > - TCP_SEQNO RcvUp; ///< Urgent point; > - TCP_SEQNO Irs; ///< Initial Receiving Sequ= ence > - UINT16 RcvMss; ///< Max receive segment si= ze > - UINT16 EnabledTimer; ///< Which timer is current= ly enabled > - UINT32 Timer[TCP_TIMER_NUMBER]; ///< When the timer will ex= pire > - INT32 NextExpire; ///< Count down offset for the nearest = timer > - UINT32 Idle; ///< How long the connection is in idle > - UINT32 ProbeTime; ///< The time out value for current win= dow prober > - BOOLEAN ProbeTimerOn;///< If TRUE, the probe time is on. > - > - // > - // RFC1323 defined variables, about window scale, > - // timestamp and PAWS > - // > - UINT8 SndWndScale; ///< Wndscale received from the peer > - UINT8 RcvWndScale; ///< Wndscale used to scale local buff= er > - UINT32 TsRecent; ///< TsRecent to echo to the remote pe= er > - UINT32 TsRecentAge; ///< When this TsRecent is updated > - > - // > - // RFC2988 defined variables. about RTT measurement > - // > - TCP_SEQNO RttSeq; ///< The seq of measured segment now > - UINT32 RttMeasure; ///< Currently measured RTT in heart bea= ts > - UINT32 SRtt; ///< Smoothed RTT, scaled by 8 > - UINT32 RttVar; ///< RTT variance, scaled by 8 > - UINT32 Rto; ///< Current RTO, not scaled > - > - // > - // RFC2581, and 3782 variables. > - // Congestion control + NewReno fast recovery. > - // > - UINT32 CWnd; ///< Sender's congestion window > - UINT32 Ssthresh; ///< Slow start threshold. > - TCP_SEQNO Recover; ///< Recover point for NewReno > - UINT16 DupAck; ///< Number of duplicate ACKs > - UINT8 CongestState; ///< The current congestion state(RFC3= 782) > - UINT8 LossTimes; ///< Number of retxmit timeouts in a r= ow > - TCP_SEQNO LossRecover; ///< Recover point for retxmit > - > - // > - // configuration parameters, for EFI_TCP4_PROTOCOL specification > - // > - UINT32 KeepAliveIdle; ///< Idle time before sending first= probe > - UINT32 KeepAlivePeriod; ///< Interval for subsequent keep a= live probe > - UINT8 MaxKeepAlive; ///< Maxium keep alive probe times. > - UINT8 KeepAliveProbes; ///< The number of keep alive probe= . > - UINT16 MaxRexmit; ///< The maxium number of retxmit b= efore > abort > - UINT32 FinWait2Timeout; ///< The FIN_WAIT_2 time out > - UINT32 TimeWaitTimeout; ///< The TIME_WAIT time out > - UINT32 ConnectTimeout; ///< The connect establishment time= out > - > - // > - // RFC7323 > - // Addressing Window Retraction for TCP Window Scale Option. > - // > - TCP_SEQNO RetxmitSeqMax; ///< Max Seq number in previous > retransmission. > - > - // > - // configuration for tcp provided by user > - // > - BOOLEAN UseDefaultAddr; > - UINT8 Tos; > - UINT8 Ttl; > - EFI_IPv4_ADDRESS SubnetMask; > - > - IP_IO_IP_INFO *IpInfo; /// -}; > - > -extern LIST_ENTRY mTcpRunQue; > -extern LIST_ENTRY mTcpListenQue; > -extern TCP_SEQNO mTcpGlobalIss; > -extern UINT32 mTcpTick; > - > -/// > -/// TCP_CONNECTED: both ends have synchronized their ISN. > -/// > -#define TCP_CONNECTED(state) ((state) > TCP_SYN_RCVD) > - > -#define TCP_FIN_RCVD(State) \ > - (((State) =3D=3D TCP_CLOSE_WAIT) || \ > - ((State) =3D=3D TCP_LAST_ACK) || \ > - ((State) =3D=3D TCP_CLOSING) || \ > - ((State) =3D=3D TCP_TIME_WAIT)) > - > -#define TCP_LOCAL_CLOSED(State) \ > - (((State) =3D=3D TCP_FIN_WAIT_1) || \ > - ((State) =3D=3D TCP_FIN_WAIT_2) || \ > - ((State) =3D=3D TCP_CLOSING) || \ > - ((State) =3D=3D TCP_TIME_WAIT) || \ > - ((State) =3D=3D TCP_LAST_ACK)) > - > -// > -// Get the TCP_SEG point from a net buffer's ProtoData > -// > -#define TCPSEG_NETBUF(NBuf) ((TCP_SEG *) ((NBuf)->ProtoData)) > - > -// > -// macros to compare sequence no > -// > -#define TCP_SEQ_LT(SeqA, SeqB) ((INT32) ((SeqA) - (SeqB)) < 0) > -#define TCP_SEQ_LEQ(SeqA, SeqB) ((INT32) ((SeqA) - (SeqB)) <=3D 0) > -#define TCP_SEQ_GT(SeqA, SeqB) ((INT32) ((SeqB) - (SeqA)) < 0) > -#define TCP_SEQ_GEQ(SeqA, SeqB) ((INT32) ((SeqB) - (SeqA)) <=3D 0) > - > -// > -// TCP_SEQ_BETWEEN return whether b <=3D m <=3D e > -// > -#define TCP_SEQ_BETWEEN(b, m, e) ((e) - (b) >=3D (m) - (b)) > - > -// > -// TCP_SUB_SEQ returns Seq1 - Seq2. Make sure Seq1 >=3D Seq2 > -// > -#define TCP_SUB_SEQ(Seq1, Seq2) ((UINT32) ((Seq1) - (Seq2))) > - > -// > -// Check whether Flag is on > -// > -#define TCP_FLG_ON(Value, Flag) ((BOOLEAN) (((Value) & (Flag)) !=3D = 0)) > - > -// > -// Set and Clear operation on a Flag > -// > -#define TCP_SET_FLG(Value, Flag) ((Value) |=3D (Flag)) > -#define TCP_CLEAR_FLG(Value, Flag) ((Value) &=3D ~(Flag)) > - > -// > -// Test whether two peers are equal > -// > -#define TCP_PEER_EQUAL(Pa, Pb) \ > - (((Pa)->Ip =3D=3D (Pb)->Ip) && ((Pa)->Port =3D=3D (Pb)->Port)) > - > -// > -// Test whether Pa matches Pb, or Pa is more specific > -// than pb. Zero means wildcard. > -// > -#define TCP_PEER_MATCH(Pa, Pb) \ > - ((((Pb)->Ip =3D=3D 0) || ((Pb)->Ip =3D=3D (Pa)->Ip)) && \ > - (((Pb)->Port =3D=3D 0) || ((Pb)->Port =3D=3D (Pa)->Port))) > - > -#define TCP_TIMER_ON(Flag, Timer) ((Flag) & (1 << (Timer))) > -#define TCP_SET_TIMER(Flag, Timer) ((Flag) =3D (UINT16) ((Flag) | (1 = << (Timer)))) > -#define TCP_CLEAR_TIMER(Flag, Timer) ((Flag) =3D (UINT16) ((Flag) & (~(= 1 << > (Timer))))) > - > -#define TCP_TIME_LT(Ta, Tb) ((INT32) ((Ta) - (Tb)) < 0) > -#define TCP_TIME_LEQ(Ta, Tb) ((INT32) ((Ta) - (Tb)) <=3D 0) > -#define TCP_SUB_TIME(Ta, Tb) ((UINT32) ((Ta) - (Tb))) > - > -#define TCP_MAX_WIN 0xFFFFU > - > -typedef > -VOID > -(*TCP_TIMER_HANDLER) ( > - IN OUT TCP_CB *Tcb > - ); > - > -#endif > -- > 2.19.1.windows.1