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.88; helo=mga01.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 3961D21188C48 for ; Wed, 31 Oct 2018 20:08:33 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Oct 2018 20:08:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,450,1534834800"; d="scan'208";a="104450454" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga001.jf.intel.com with ESMTP; 31 Oct 2018 20:08:30 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 31 Oct 2018 20:08:25 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.84]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.214]) with mapi id 14.03.0415.000; Thu, 1 Nov 2018 11:08:22 +0800 From: "Zeng, Star" To: "Fu, Siyuan" , "edk2-devel@lists.01.org" CC: "Wang, Jian J" , "Wu, Jiaxin" , "Zeng, Star" Thread-Topic: [PATCH v1 6/7] MdeModulePkg: Delete the TCP/PXE/ISCSI drivers in MdeModulePkg. Thread-Index: AQHUcCLyx/8GYMZ5fkOS09jTQAFx56U6P5Og Date: Thu, 1 Nov 2018 03:08:20 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB048310401E24F5@shsmsx102.ccr.corp.intel.com> References: <20181030073328.62924-1-siyuan.fu@intel.com> <20181030073328.62924-7-siyuan.fu@intel.com> In-Reply-To: <20181030073328.62924-7-siyuan.fu@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 31 Oct 2018 20:15:31 -0700 Subject: Re: [PATCH v1 6/7] MdeModulePkg: Delete the TCP/PXE/ISCSI drivers 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, 01 Nov 2018 03:08:34 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Star Zeng after you update all the refer= ences in platform to use NetworkPkg. Thanks, Star -----Original Message----- From: Fu, Siyuan=20 Sent: Tuesday, October 30, 2018 3:33 PM To: edk2-devel@lists.01.org Cc: Zeng, Star ; Wang, Jian J ;= Wu, Jiaxin Subject: [PATCH v1 6/7] MdeModulePkg: Delete the TCP/PXE/ISCSI drivers in M= deModulePkg. This patch is to delete the Tcp4Dxe, UefiPxeBcDxe and IScsi4Dxe drivers in MdeModulePkg. These drivers will not be maintained and can't co-work with the dual-stack drivers in NetworkPkg. People should use below NetworkPkg drivers instead: NetworkPkg/IScsiDxe/IScsiDxe.inf NetworkPkg/TcpDxe/TcpDxe.inf NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf These drivers are actively maintained with more bug fixes and new feature support. Cc: Star Zeng Cc: Jian J Wang Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Fu Siyuan --- MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.c | 283 = -- MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.c | 430 = --- MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c | 1264 = --------- MdeModulePkg/Universal/Network/IScsiDxe/IScsiDhcp.c | 472 = ---- MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c | 676 = ----- MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c | 412 = --- MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c | 539 = ---- MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.c | 116 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c | 948 = ------- MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c | 2799 = ------------------ MdeModulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.c | 487 = ---- MdeModulePkg/Universal/Network/IScsiDxe/Md5.c | 350 = --- 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/Universal/Network/UefiPxeBcDxe/ComponentName.c | 365 = --- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c | 1999 = ------------- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c | 665 = ----- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 2989 = -------------------- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c | 454 = --- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c | 221 = -- MdeModulePkg/MdeModulePkg.dsc | 3 = - MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.h | 165 = -- MdeModulePkg/Universal/Network/IScsiDxe/IScsi4Dxe.uni | 25 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsi4DxeExtra.uni | 20 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.h | 106 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiCommon.h | 22 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h | 166 = -- MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxe.vfr | 219 = -- MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxeStrings.uni | 62 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigNVDataStruc.h | 109 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiDhcp.h | 55 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.h | 140 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf | 134 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.h | 22 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.h | 38 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiImpl.h | 168 = -- MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.h | 74 = - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h | 317 = --- MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.h | 1005 = ------- MdeModulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.h | 142 = - MdeModulePkg/Universal/Network/IScsiDxe/Md5.h | 80 = - 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 = --- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h | 502 = ---- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h | 102 = - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h | 189 = -- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h | 137 = - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h | 134 = - MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxe.uni | 25 = - MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxeExtra.uni | 20 = - MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf | 102 = - 69 files changed, 32598 deletions(-) diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.c b/MdeM= odulePkg/Universal/Network/IScsiDxe/ComponentName.c deleted file mode 100644 index 3f561e93439d..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.c +++ /dev/null @@ -1,283 +0,0 @@ -/** @file - UEFI Component Name(2) protocol implementation for iSCSI. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -// -// EFI Component Name Protocol -// -GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiCompon= entName =3D { - IScsiComponentNameGetDriverName, - IScsiComponentNameGetControllerName, - "eng" -}; - -// -// EFI Component Name 2 Protocol -// -GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIScsiCompon= entName2 =3D { - (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IScsiComponentNameGetDriverName, - (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IScsiComponentNameGetControlle= rName, - "en" -}; - -GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTab= le[] =3D { - {"eng;en", L"iSCSI Driver"}, - {NULL, NULL} -}; - -GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *mIScsiControllerN= ameTable =3D NULL; - -/** - Retrieves a Unicode string that is the user readable name of the EFI Dri= ver. - - This function retrieves the user readable name of a driver in the form o= f a - Unicode string. If the driver specified by This has a user readable name= 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 speci= fied - by This does not support the language specified by Language, - then EFI_UNSUPPORTED is returned. - - @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCOL ins= tance. - @param[in] Language A pointer to a three character ISO 639-2 languag= e identifier. - This is the language of the driver name that tha= t the caller - is requesting, and it must match one of the lang= uages specified - in SupportedLanguages. The number of languages = supported by a - driver is up to the driver writer. - @param[out] DriverName A pointer to the Unicode string to return. This= Unicode string - is the name of the driver specified by This in t= he language - specified by Language. - - @retval EFI_SUCCESS The Unicode string for the Driver specifie= d by This - and the language specified by Language 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 supp= ort the - language specified by Language. -**/ -EFI_STATUS -EFIAPI -IScsiComponentNameGetDriverName ( - IN EFI_COMPONENT_NAME_PROTOCOL *This, - IN CHAR8 *Language, - OUT CHAR16 **DriverName - ) -{ - return LookupUnicodeString2 ( - Language, - This->SupportedLanguages, - mIScsiDriverNameTable, - DriverName, - (BOOLEAN)(This =3D=3D &gIScsiComponentName) - ); -} - -/** - Update the component name for the iSCSI instance. - - @param[in] IScsiExtScsiPassThru A pointer to the EFI_EXT_SCSI_PASS_THR= U_PROTOCOL instance. - - @retval EFI_SUCCESS Update the ControllerNameTable of this= instance successfully. - @retval EFI_INVALID_PARAMETER The input parameter is invalid. - @retval EFI_UNSUPPORTED Can't get the corresponding NIC info f= rom the Controller handle. - -**/ -EFI_STATUS -UpdateName ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru - ) -{ - EFI_STATUS Status; - CHAR16 HandleName[150]; - ISCSI_DRIVER_DATA *Private; - EFI_MAC_ADDRESS MacAddress; - UINTN HwAddressSize; - UINT16 VlanId; - CHAR16 MacString[70]; - - if (IScsiExtScsiPassThru =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPass= Thru); - - // - // Get the mac string, it's the name of various variable - // - Status =3D NetLibGetMacAddress (Private->Controller, &MacAddress, &HwAdd= ressSize); - if (EFI_ERROR (Status)) { - return Status; - } - VlanId =3D NetLibGetVlanId (Private->Controller); - IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacStrin= g); - - UnicodeSPrint ( - HandleName, - sizeof (HandleName), - L"iSCSI IPv4 (MacString=3D%s)", - MacString - ); - - if (mIScsiControllerNameTable !=3D NULL) { - FreeUnicodeStringTable (mIScsiControllerNameTable); - mIScsiControllerNameTable =3D NULL; - } - - Status =3D AddUnicodeString2 ( - "eng", - gIScsiComponentName.SupportedLanguages, - &mIScsiControllerNameTable, - HandleName, - TRUE - ); - if (EFI_ERROR (Status)) { - return Status; - } - - return AddUnicodeString2 ( - "en", - gIScsiComponentName2.SupportedLanguages, - &mIScsiControllerNameTable, - HandleName, - FALSE - ); -} - -/** - Retrieves a Unicode string that is the user readable name of the control= ler - that is being managed by an EFI Driver.Currently not implemented. - - @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCO= L instance. - @param[in] ControllerHandle The handle of a controller that the driver = specified by - This is managing. This handle specifies th= e controller - whose name is to be returned. - @param[in] ChildHandle The handle of the child controller to retri= eve the name - of. This is an optional parameter that may= be NULL. It - will be NULL for device drivers. It will a= lso be NULL - for a bus drivers that wish to retrieve the= name of the - bus controller. It will not be NULL for a = bus driver - that wishes to retrieve the name of a child= controller. - @param[in] Language A pointer to a three character ISO 639-2 la= nguage - identifier. This is the language of the co= ntroller name - that that the caller is requesting, and it = must match one - of the languages specified in SupportedLang= uages. The - number of languages supported by a driver i= s up to the - driver writer. - @param[out] ControllerName A pointer to the Unicode string to return. = This Unicode - string is the name of the controller specif= ied by - ControllerHandle and ChildHandle in the lan= guage 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 n= ame in the - language specified by Language for the dri= ver - specified by This was returned in DriverNa= me. - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. - @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a va= lid 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 curren= tly managing - the controller specified by ControllerHand= le and - ChildHandle. - @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort the - language specified by Language. -**/ -EFI_STATUS -EFIAPI -IScsiComponentNameGetControllerName ( - 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_HANDLE IScsiController; - ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier; - - EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru; - - if (ControllerHandle =3D=3D NULL) { - return EFI_UNSUPPORTED; - } - - // - // Get the handle of the controller we are controling. - // - IScsiController =3D NetLibGetNicHandle (ControllerHandle, &gEfiTcp4Proto= colGuid); - if (IScsiController =3D=3D NULL) { - return EFI_UNSUPPORTED; - } - - Status =3D gBS->OpenProtocol ( - IScsiController, - &gEfiCallerIdGuid, - (VOID **)&IScsiIdentifier, - NULL, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return Status; - } - - if (ChildHandle !=3D NULL) { - // - // Make sure this driver produced ChildHandle - // - Status =3D EfiTestChildHandle ( - ControllerHandle, - ChildHandle, - &gEfiTcp4ProtocolGuid - ); - if (!EFI_ERROR (Status)) { - // - // Retrieve an instance of a produced protocol from ChildHandle - // - Status =3D gBS->OpenProtocol ( - ChildHandle, - &gEfiExtScsiPassThruProtocolGuid, - (VOID **)&IScsiExtScsiPassThru, - NULL, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Update the component name for this child handle. - // - Status =3D UpdateName (IScsiExtScsiPassThru); - if (EFI_ERROR (Status)) { - return Status; - } - } else { - return Status; - } - } - - return LookupUnicodeString2 ( - Language, - This->SupportedLanguages, - mIScsiControllerNameTable, - ControllerName, - (BOOLEAN)(This =3D=3D &gIScsiComponentName) - ); -} - diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.c b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiCHAP.c deleted file mode 100644 index 6307684ff05b..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.c +++ /dev/null @@ -1,430 +0,0 @@ -/** @file - This file is for Challenge-Handshake Authentication Protocol (CHAP) Conf= iguration. - -Copyright (c) 2004 - 2015, 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" -#include "Md5.h" - -/** - Initator calculates its own expected hash value. - - @param[in] ChapIdentifier iSCSI CHAP identifier sent by authentica= tor. - @param[in] ChapSecret iSCSI CHAP secret of the authenticator. - @param[in] SecretLength The length of iSCSI CHAP secret. - @param[in] ChapChallenge The challenge message sent by authentica= tor. - @param[in] ChallengeLength The length of iSCSI CHAP challenge messa= ge. - @param[out] ChapResponse The calculation of the expected hash val= ue. - - @retval EFI_SUCCESS The expected hash value was calculatedly= successfully. - @retval EFI_PROTOCOL_ERROR The length of the secret should be at le= ast the - length of the hash value for the hashing= algorithm chosen. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiCHAPCalculateResponse ( - IN UINT32 ChapIdentifier, - IN CHAR8 *ChapSecret, - IN UINT32 SecretLength, - IN UINT8 *ChapChallenge, - IN UINT32 ChallengeLength, - OUT UINT8 *ChapResponse - ) -{ - MD5_CTX Md5Ctx; - CHAR8 IdByte[1]; - EFI_STATUS Status; - - Status =3D MD5Init (&Md5Ctx); - - // - // Hash Identifier - Only calculate 1 byte data (RFC1994) - // - IdByte[0] =3D (CHAR8) ChapIdentifier; - MD5Update (&Md5Ctx, IdByte, 1); - - // - // Hash Secret - // - if (SecretLength < ISCSI_CHAP_SECRET_MIN_LEN - 1) { - return EFI_PROTOCOL_ERROR; - } - - MD5Update (&Md5Ctx, ChapSecret, SecretLength); - - // - // Hash Challenge received from Target - // - MD5Update (&Md5Ctx, ChapChallenge, ChallengeLength); - - Status =3D MD5Final (&Md5Ctx, ChapResponse); - - return Status; -} - -/** - The initator checks the CHAP response replied by target against its own - calculation of the expected hash value. - - @param[in] AuthData iSCSI CHAP authentication data. - @param[in] TargetResponse The response from target. - - @retval EFI_SUCCESS The response from target passed authen= tication. - @retval EFI_SECURITY_VIOLATION The response from target was not expec= ted value. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiCHAPAuthTarget ( - IN ISCSI_CHAP_AUTH_DATA *AuthData, - IN UINT8 *TargetResponse - ) -{ - EFI_STATUS Status; - UINT32 SecretSize; - UINT8 VerifyRsp[ISCSI_CHAP_RSP_LEN]; - - Status =3D EFI_SUCCESS; - - SecretSize =3D (UINT32) AsciiStrLen (AuthData->AuthConfig.ReverseCHAPSe= cret); - Status =3D IScsiCHAPCalculateResponse ( - AuthData->OutIdentifier, - AuthData->AuthConfig.ReverseCHAPSecret, - SecretSize, - AuthData->OutChallenge, - AuthData->OutChallengeLength, - VerifyRsp - ); - - if (CompareMem (VerifyRsp, TargetResponse, ISCSI_CHAP_RSP_LEN) !=3D 0) { - Status =3D EFI_SECURITY_VIOLATION; - } - - return Status; -} - -/** - This function checks the received iSCSI Login Response during the securi= ty - negotiation stage. - - @param[in] Conn The iSCSI connection. - - @retval EFI_SUCCESS The Login Response passed the CHAP validati= on. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_PROTOCOL_ERROR Some kind of protocol error happend. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiCHAPOnRspReceived ( - IN ISCSI_CONNECTION *Conn - ) -{ - EFI_STATUS Status; - ISCSI_SESSION *Session; - ISCSI_CHAP_AUTH_DATA *AuthData; - CHAR8 *Value; - UINT8 *Data; - UINT32 Len; - LIST_ENTRY *KeyValueList; - UINTN Algorithm; - CHAR8 *Identifier; - CHAR8 *Challenge; - CHAR8 *Name; - CHAR8 *Response; - UINT8 TargetRsp[ISCSI_CHAP_RSP_LEN]; - UINT32 RspLen; - - ASSERT (Conn->CurrentStage =3D=3D ISCSI_SECURITY_NEGOTIATION); - ASSERT (Conn->RspQue.BufNum !=3D 0); - - Session =3D Conn->Session; - AuthData =3D &Session->AuthData; - - Len =3D Conn->RspQue.BufSize; - Data =3D AllocatePool (Len); - if (Data =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // Copy the data in case the data spans over multiple PDUs. - // - NetbufQueCopy (&Conn->RspQue, 0, Len, Data); - - // - // Build the key-value list from the data segment of the Login Response. - // - KeyValueList =3D IScsiBuildKeyValueList ((CHAR8 *) Data, Len); - if (KeyValueList =3D=3D NULL) { - FreePool (Data); - return EFI_OUT_OF_RESOURCES; - } - - Status =3D EFI_PROTOCOL_ERROR; - - switch (Conn->CHAPStep) { - case ISCSI_CHAP_INITIAL: - // - // The first Login Response. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_P= ORTAL_GROUP_TAG); - if (Value =3D=3D NULL) { - goto ON_EXIT; - } - - Session->TargetPortalGroupTag =3D (UINT16) AsciiStrDecimalToUintn (Val= ue); - - Value =3D IScsiGetValueByKeyFromList (KeyValue= List, ISCSI_KEY_AUTH_METHOD); - if (Value =3D=3D NULL) { - goto ON_EXIT; - } - // - // Initiator mandates CHAP authentication but target replies without "= CHAP" or - // initiator suggets "None" but target replies with some kind of auth = method. - // - if (AsciiStrCmp (Value, ISCSI_AUTH_METHOD_CHAP) =3D=3D 0) { - if (AuthData->AuthConfig.CHAPType =3D=3D ISCSI_CHAP_NONE) { - goto ON_EXIT; - } - } else { - if (AuthData->AuthConfig.CHAPType !=3D ISCSI_CHAP_NONE) { - goto ON_EXIT; - } - } - // - // Transit to CHAP step one. - // - Conn->CHAPStep =3D ISCSI_CHAP_STEP_ONE; - Status =3D EFI_SUCCESS; - break; - - case ISCSI_CHAP_STEP_TWO: - // - // The Target replies with CHAP_A=3D CHAP_I=3D CHAP_C=3D - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_ALG= ORITHM); - if (Value =3D=3D NULL) { - goto ON_EXIT; - } - - Algorithm =3D AsciiStrDecimalToUintn (Value); - if (Algorithm !=3D ISCSI_CHAP_ALGORITHM_MD5) { - // - // Unsupported algorithm is chosen by target. - // - goto ON_EXIT; - } - - Identifier =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHA= P_IDENTIFIER); - if (Identifier =3D=3D NULL) { - goto ON_EXIT; - } - - Challenge =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP= _CHALLENGE); - if (Challenge =3D=3D NULL) { - goto ON_EXIT; - } - // - // Process the CHAP identifier and CHAP Challenge from Target - // Calculate Response value - // - AuthData->InIdentifier =3D (UINT32) AsciiStrDecimalToUintn (Ident= ifier); - AuthData->InChallengeLength =3D ISCSI_CHAP_AUTH_MAX_LEN; - IScsiHexToBin ((UINT8 *) AuthData->InChallenge, &AuthData->InChallenge= Length, Challenge); - Status =3D IScsiCHAPCalculateResponse ( - AuthData->InIdentifier, - AuthData->AuthConfig.CHAPSecret, - (UINT32) AsciiStrLen (AuthData->AuthConfig.CHAPSecret), - AuthData->InChallenge, - AuthData->InChallengeLength, - AuthData->CHAPResponse - ); - - // - // Transit to next step. - // - Conn->CHAPStep =3D ISCSI_CHAP_STEP_THREE; - break; - - case ISCSI_CHAP_STEP_THREE: - // - // one way CHAP authentication and the target would like to - // authenticate us. - // - Status =3D EFI_SUCCESS; - break; - - case ISCSI_CHAP_STEP_FOUR: - ASSERT (AuthData->AuthConfig.CHAPType =3D=3D ISCSI_CHAP_MUTUAL); - // - // The forth step, CHAP_N=3D CHAP_R=3D is received from Target. - // - Name =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_NAME= ); - if (Name =3D=3D NULL) { - goto ON_EXIT; - } - - Response =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_= RESPONSE); - if (Response =3D=3D NULL) { - goto ON_EXIT; - } - - RspLen =3D ISCSI_CHAP_RSP_LEN; - IScsiHexToBin (TargetRsp, &RspLen, Response); - - // - // Check the CHAP Response replied by Target. - // - Status =3D IScsiCHAPAuthTarget (AuthData, TargetRsp); - break; - - default: - break; - } - -ON_EXIT: - - IScsiFreeKeyValueList (KeyValueList); - - FreePool (Data); - - return Status; -} - -/** - This function fills the CHAP authentication information into the login P= DU - during the security negotiation stage in the iSCSI connection login. - - @param[in] Conn The iSCSI connection. - @param[in, out] Pdu The PDU to send out. - - @retval EFI_SUCCESS All check passed and the phase-related CHAP - authentication info is filled into the iSCS= I PDU. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_PROTOCOL_ERROR Some kind of protocol error happend. -**/ -EFI_STATUS -IScsiCHAPToSendReq ( - IN ISCSI_CONNECTION *Conn, - IN OUT NET_BUF *Pdu - ) -{ - EFI_STATUS Status; - ISCSI_SESSION *Session; - ISCSI_LOGIN_REQUEST *LoginReq; - ISCSI_CHAP_AUTH_DATA *AuthData; - CHAR8 *Value; - CHAR8 ValueStr[256]; - CHAR8 *Response; - UINT32 RspLen; - CHAR8 *Challenge; - UINT32 ChallengeLen; - - ASSERT (Conn->CurrentStage =3D=3D ISCSI_SECURITY_NEGOTIATION); - - Session =3D Conn->Session; - AuthData =3D &Session->AuthData; - LoginReq =3D (ISCSI_LOGIN_REQUEST *) NetbufGetByte (Pdu, 0, 0); - if (LoginReq =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - Status =3D EFI_SUCCESS; - - RspLen =3D 2 * ISCSI_CHAP_RSP_LEN + 3; - Response =3D AllocatePool (RspLen); - if (Response =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - ChallengeLen =3D 2 * ISCSI_CHAP_RSP_LEN + 3; - Challenge =3D AllocatePool (ChallengeLen); - if (Challenge =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - switch (Conn->CHAPStep) { - case ISCSI_CHAP_INITIAL: - // - // It's the initial Login Request. Fill in the key=3Dvalue pairs manda= tory - // for the initial Login Request. - // - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_INITIATOR_NAME, Session->Initiato= rName); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_SESSION_TYPE, "Normal"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_TARGET_NAME, Session->ConfigData.= NvData.TargetName); - - if (AuthData->AuthConfig.CHAPType =3D=3D ISCSI_CHAP_NONE) { - Value =3D ISCSI_KEY_VALUE_NONE; - ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT); - } else { - Value =3D ISCSI_AUTH_METHOD_CHAP; - } - - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_AUTH_METHOD, Value); - - break; - - case ISCSI_CHAP_STEP_ONE: - // - // First step, send the Login Request with CHAP_A=3D key-val= ue pair. - // - AsciiSPrint (ValueStr, sizeof (ValueStr), "%d", ISCSI_CHAP_ALGORITHM_M= D5); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_ALGORITHM, ValueStr); - - Conn->CHAPStep =3D ISCSI_CHAP_STEP_TWO; - break; - - case ISCSI_CHAP_STEP_THREE: - // - // Third step, send the Login Request with CHAP_N=3D CHAP_R=3D o= r - // CHAP_N=3D CHAP_R=3D CHAP_I=3D CHAP_C=3D if target ahten= tication is - // required too. - // - // CHAP_N=3D - // - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_NAME, (CHAR8 *) &AuthData->A= uthConfig.CHAPName); - // - // CHAP_R=3D - // - IScsiBinToHex ((UINT8 *) AuthData->CHAPResponse, ISCSI_CHAP_RSP_LEN, R= esponse, &RspLen); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_RESPONSE, Response); - - if (AuthData->AuthConfig.CHAPType =3D=3D ISCSI_CHAP_MUTUAL) { - // - // CHAP_I=3D - // - IScsiGenRandom ((UINT8 *) &AuthData->OutIdentifier, 1); - AsciiSPrint (ValueStr, sizeof (ValueStr), "%d", AuthData->OutIdentif= ier); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_IDENTIFIER, ValueStr); - // - // CHAP_C=3D - // - IScsiGenRandom ((UINT8 *) AuthData->OutChallenge, ISCSI_CHAP_RSP_LEN= ); - AuthData->OutChallengeLength =3D ISCSI_CHAP_RSP_LEN; - IScsiBinToHex ((UINT8 *) AuthData->OutChallenge, ISCSI_CHAP_RSP_LEN,= Challenge, &ChallengeLen); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_CHALLENGE, Challenge); - - Conn->CHAPStep =3D ISCSI_CHAP_STEP_FOUR; - } - // - // set the stage transition flag. - // - ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT); - break; - - default: - Status =3D EFI_PROTOCOL_ERROR; - break; - } - - FreePool (Response); - FreePool (Challenge); - - return Status; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiConfig.c deleted file mode 100644 index cb1eff1b690c..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c +++ /dev/null @@ -1,1264 +0,0 @@ -/** @file - Helper functions for configuring or getting the parameters relating to i= SCSI. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -CHAR16 mVendorStorageName[] =3D L"ISCSI_CONFIG_IFR_NVDATA"; -BOOLEAN mIScsiDeviceListUpdated =3D FALSE; -UINTN mNumberOfIScsiDevices =3D 0; -ISCSI_FORM_CALLBACK_INFO *mCallbackInfo =3D NULL; - -LIST_ENTRY mIScsiConfigFormList =3D { - &mIScsiConfigFormList, - &mIScsiConfigFormList -}; - -HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath =3D { - { - { - HARDWARE_DEVICE_PATH, - HW_VENDOR_DP, - { - (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) - } - }, - IP4_ISCSI_CONFIG_GUID - }, - { - END_DEVICE_PATH_TYPE, - END_ENTIRE_DEVICE_PATH_SUBTYPE, - { - (UINT8) (END_DEVICE_PATH_LENGTH), - (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) - } - } -}; - -/** - Convert the IPv4 address into a dotted string. - - @param[in] Ip The IPv4 address. - @param[out] Str The dotted IP string. -**/ -VOID -IScsiIpToStr ( - IN EFI_IPv4_ADDRESS *Ip, - OUT CHAR16 *Str - ) -{ - UnicodeSPrint ( Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], = Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]); -} - - -/** - Parse IsId in string format and convert it to binary. - - @param[in] String The buffer of the string to be parsed. - @param[in, out] IsId The buffer to store IsId. - - @retval EFI_SUCCESS The operation finished successfully. - @retval EFI_INVALID_PARAMETER Any input parameter is invalid. - -**/ -EFI_STATUS -IScsiParseIsIdFromString ( - IN CONST CHAR16 *String, - IN OUT UINT8 *IsId - ) -{ - UINT8 Index; - CHAR16 *IsIdStr; - CHAR16 TempStr[3]; - UINTN NodeVal; - CHAR16 PortString[ISCSI_NAME_IFR_MAX_SIZE]; - EFI_INPUT_KEY Key; - - if ((String =3D=3D NULL) || (IsId =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - IsIdStr =3D (CHAR16 *) String; - - if (StrLen (IsIdStr) !=3D 6) { - UnicodeSPrint ( - PortString, - (UINTN) sizeof (PortString), - L"Error! Input is incorrect, please input 6 hex numbers!\n" - ); - - CreatePopUp ( - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, - &Key, - PortString, - NULL - ); - - return EFI_INVALID_PARAMETER; - } - - for (Index =3D 3; Index < 6; Index++) { - CopyMem (TempStr, IsIdStr, sizeof (TempStr)); - TempStr[2] =3D L'\0'; - - // - // Convert the string to IsId. StrHexToUintn stops at the first charac= ter - // that is not a valid hex character, '\0' here. - // - NodeVal =3D StrHexToUintn (TempStr); - - IsId[Index] =3D (UINT8) NodeVal; - - IsIdStr =3D IsIdStr + 2; - } - - return EFI_SUCCESS; -} - -/** - Convert IsId from binary to string format. - - @param[out] String The buffer to store the converted string. - @param[in] IsId The buffer to store IsId. - - @retval EFI_SUCCESS The string converted successfully. - @retval EFI_INVALID_PARAMETER Any input parameter is invalid. - -**/ -EFI_STATUS -IScsiConvertIsIdToString ( - OUT CHAR16 *String, - IN UINT8 *IsId - ) -{ - UINT8 Index; - UINTN Number; - - if ((String =3D=3D NULL) || (IsId =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - for (Index =3D 0; Index < 6; Index++) { - if (IsId[Index] <=3D 0xF) { - Number =3D UnicodeSPrint ( - String, - 2 * ISID_CONFIGURABLE_STORAGE, - L"0%X", - (UINTN) IsId[Index] - ); - } else { - Number =3D UnicodeSPrint ( - String, - 2 * ISID_CONFIGURABLE_STORAGE, - L"%X", - (UINTN) IsId[Index] - ); - - } - - String =3D String + Number; - } - - *String =3D L'\0'; - - return EFI_SUCCESS; -} - - -/** - Update the list of iSCSI devices the iSCSI driver is controlling. - - @retval EFI_SUCCESS The callback successfully handled the act= ion. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiUpdateDeviceList ( - VOID - ) -{ - EFI_STATUS Status; - ISCSI_DEVICE_LIST *DeviceList; - UINTN DataSize; - UINTN NumHandles; - EFI_HANDLE *Handles; - UINTN HandleIndex; - UINTN Index; - UINTN LastDeviceIndex; - EFI_MAC_ADDRESS MacAddress; - UINTN HwAddressSize; - UINT16 VlanId; - ISCSI_MAC_INFO *CurMacInfo; - ISCSI_MAC_INFO TempMacInfo; - CHAR16 MacString[70]; - UINTN DeviceListSize; - - // - // Dump all the handles the Managed Network Service Binding Protocol is = installed on. - // - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiManagedNetworkServiceBindingProtocolGuid, - NULL, - &NumHandles, - &Handles - ); - if (EFI_ERROR (Status)) { - return Status; - } - - DataSize =3D 0; - Status =3D gRT->GetVariable ( - L"iSCSIDeviceList", - &gIp4IScsiConfigGuid, - NULL, - &DataSize, - NULL - ); - if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - DeviceList =3D (ISCSI_DEVICE_LIST *) AllocatePool (DataSize); - ASSERT (DeviceList !=3D NULL); - - gRT->GetVariable ( - L"iSCSIDeviceList", - &gIp4IScsiConfigGuid, - NULL, - &DataSize, - DeviceList - ); - - LastDeviceIndex =3D 0; - - for (HandleIndex =3D 0; HandleIndex < NumHandles; HandleIndex++) { - Status =3D NetLibGetMacAddress (Handles[HandleIndex], &MacAddress, &= HwAddressSize); - ASSERT (Status =3D=3D EFI_SUCCESS); - VlanId =3D NetLibGetVlanId (Handles[HandleIndex]); - - for (Index =3D LastDeviceIndex; Index < DeviceList->NumDevice; Index= ++) { - CurMacInfo =3D &DeviceList->MacInfo[Index]; - if ((CurMacInfo->Len =3D=3D HwAddressSize) && - (CurMacInfo->VlanId =3D=3D VlanId) && - (NET_MAC_EQUAL (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSi= ze)) - ) { - // - // The previous configured NIC is still here. - // - if (Index !=3D LastDeviceIndex) { - // - // Swap the current MAC address entry with the one indexed by - // LastDeviceIndex. - // - CopyMem (&TempMacInfo, CurMacInfo, sizeof (ISCSI_MAC_INFO)); - CopyMem (CurMacInfo, &DeviceList->MacInfo[LastDeviceIndex], si= zeof (ISCSI_MAC_INFO)); - CopyMem (&DeviceList->MacInfo[LastDeviceIndex], &TempMacInfo, = sizeof (ISCSI_MAC_INFO)); - } - - LastDeviceIndex++; - } - } - - if (LastDeviceIndex =3D=3D DeviceList->NumDevice) { - break; - } - } - - for (Index =3D LastDeviceIndex; Index < DeviceList->NumDevice; Index++= ) { - // - // delete the variables - // - CurMacInfo =3D &DeviceList->MacInfo[Index]; - IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, CurMacInfo->Vl= anId, MacString); - gRT->SetVariable (MacString, &gEfiIScsiInitiatorNameProtocolGuid, 0,= 0, NULL); - gRT->SetVariable (MacString, &gIScsiCHAPAuthInfoGuid, 0, 0, NULL); - } - - FreePool (DeviceList); - } else if (Status !=3D EFI_NOT_FOUND) { - FreePool (Handles); - return Status; - } - // - // Construct the new iSCSI device list. - // - DeviceListSize =3D sizeof (ISCSI_DEVICE_LIST) + (NumHandles - 1) = * sizeof (ISCSI_MAC_INFO); - DeviceList =3D (ISCSI_DEVICE_LIST *) AllocatePool (DeviceList= Size); - ASSERT (DeviceList !=3D NULL); - DeviceList->NumDevice =3D (UINT8) NumHandles; - - for (Index =3D 0; Index < NumHandles; Index++) { - NetLibGetMacAddress (Handles[Index], &MacAddress, &HwAddressSize); - - CurMacInfo =3D &DeviceList->MacInfo[Index]; - CopyMem (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize); - CurMacInfo->Len =3D (UINT8) HwAddressSize; - CurMacInfo->VlanId =3D NetLibGetVlanId (Handles[Index]); - } - - gRT->SetVariable ( - L"iSCSIDeviceList", - &gIp4IScsiConfigGuid, - ISCSI_CONFIG_VAR_ATTR, - DeviceListSize, - DeviceList - ); - - FreePool (DeviceList); - FreePool (Handles); - - return Status; -} - -/** - Get the iSCSI configuration form entry by the index of the goto opcode a= ctived. - - @param[in] Index The 0-based index of the goto opcode actived. - - @return The iSCSI configuration form entry found. -**/ -ISCSI_CONFIG_FORM_ENTRY * -IScsiGetConfigFormEntryByIndex ( - IN UINT32 Index - ) -{ - UINT32 CurrentIndex; - LIST_ENTRY *Entry; - ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry; - - CurrentIndex =3D 0; - ConfigFormEntry =3D NULL; - - NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) { - if (CurrentIndex =3D=3D Index) { - ConfigFormEntry =3D NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_E= NTRY, Link); - break; - } - - CurrentIndex++; - } - - return ConfigFormEntry; -} - -/** - Convert the iSCSI configuration data into the IFR data. - - @param[in] ConfigFormEntry The iSCSI configuration form entry. - @param[out] IfrNvData The IFR nv data. - -**/ -VOID -IScsiConvertDeviceConfigDataToIfrNvData ( - IN ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry, - OUT ISCSI_CONFIG_IFR_NVDATA *IfrNvData - ) -{ - ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData; - ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData; - - // - // Normal session configuration parameters. - // - SessionConfigData =3D &ConfigFormEntry->SessionConfigDat= a; - IfrNvData->Enabled =3D SessionConfigData->Enabled; - - IfrNvData->InitiatorInfoFromDhcp =3D SessionConfigData->InitiatorInfoFr= omDhcp; - IfrNvData->TargetInfoFromDhcp =3D SessionConfigData->TargetInfoFromD= hcp; - IfrNvData->TargetPort =3D SessionConfigData->TargetPort; - - IScsiIpToStr (&SessionConfigData->LocalIp, IfrNvData->LocalIp); - IScsiIpToStr (&SessionConfigData->SubnetMask, IfrNvData->SubnetMask); - IScsiIpToStr (&SessionConfigData->Gateway, IfrNvData->Gateway); - IScsiIpToStr (&SessionConfigData->TargetIp, IfrNvData->TargetIp); - - IScsiAsciiStrToUnicodeStr (SessionConfigData->TargetName, IfrNvData->Tar= getName); - - IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun); - - IScsiConvertIsIdToString (IfrNvData->IsId, SessionConfigData->IsId); - - // - // CHAP authentication parameters. - // - AuthConfigData =3D &ConfigFormEntry->AuthConfigData; - - IfrNvData->CHAPType =3D AuthConfigData->CHAPType; - - IScsiAsciiStrToUnicodeStr (AuthConfigData->CHAPName, IfrNvData->CHAPName= ); - IScsiAsciiStrToUnicodeStr (AuthConfigData->CHAPSecret, IfrNvData->CHAPSe= cret); - IScsiAsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPName, IfrNvData->R= everseCHAPName); - IScsiAsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPSecret, IfrNvData-= >ReverseCHAPSecret); -} - -/** - This function allows the caller to request the current - configuration for one or more named elements. The resulting - string is in format. Any and all alternative - configuration strings shall also be appended to the end of the - current configuration string. If they are, they must appear - after the current configuration. They must contain the same - routing (GUID, NAME, PATH) as the current configuration string. - They must have an additional description indicating the type of - alternative configuration the string represents, - "ALTCFG=3D". That (when - converted from Hex UNICODE to binary) is a reference to a - string in the associated string pack. - - @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. - @param[in] Request A null-terminated Unicode string in - format. Note that this - includes the routing information as well as - the configurable name / value pairs. It is - invalid for this string to be in - format. - @param[out] Progress On return, points to a character in the - Request string. Points to the string's null - terminator if request was successful. Points - to the most recent "&" before the first - failing name / value pair (or the beginning - of the string if the failure is in the first - name / value pair) if the request was not - successful. - @param[out] Results A null-terminated Unicode string in - format which has all values - filled in for the names in the Request string. - String to be allocated by the called function. - - @retval EFI_SUCCESS The Results string is filled with the - values corresponding to all requested - names. - @retval EFI_OUT_OF_RESOURCES Not enough memory to store the - parts of the results that must be - stored awaiting possible future - protocols. - @retval EFI_INVALID_PARAMETER For example, passing in a NULL - for the Request parameter - would result in this type of - error. In this case, the - Progress parameter would be - set to NULL. - @retval EFI_NOT_FOUND Routing data doesn't match any - known driver. Progress set to the - first character in the routing header. - Note: There is no requirement that the - driver validate the routing data. It - must skip the in order to - process the names. - @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set - to most recent & before the - error or the beginning of the - string. - @retval EFI_INVALID_PARAMETER Unknown name. Progress points - to the & before the name in - question.Currently not implemented. -**/ -EFI_STATUS -EFIAPI -IScsiFormExtractConfig ( - IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, - IN CONST EFI_STRING Request, - OUT EFI_STRING *Progress, - OUT EFI_STRING *Results - ) -{ - EFI_STATUS Status; - CHAR8 InitiatorName[ISCSI_NAME_MAX_SIZE]; - UINTN BufferSize; - ISCSI_CONFIG_IFR_NVDATA *IfrNvData; - ISCSI_FORM_CALLBACK_INFO *Private; - EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; - EFI_STRING ConfigRequestHdr; - EFI_STRING ConfigRequest; - BOOLEAN AllocatedRequest; - UINTN Size; - - if (Progress =3D=3D NULL || Results =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - *Progress =3D Request; - if ((Request !=3D NULL) && !HiiIsConfigHdrMatch (Request, &gIp4IScsiConf= igGuid, mVendorStorageName)) { - return EFI_NOT_FOUND; - } - - ConfigRequestHdr =3D NULL; - ConfigRequest =3D NULL; - AllocatedRequest =3D FALSE; - Size =3D 0; - - if (!mIScsiDeviceListUpdated) { - // - // Update the device list. - // - IScsiUpdateDeviceList (); - mIScsiDeviceListUpdated =3D TRUE; - } - - Private =3D ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); - IfrNvData =3D AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); - ASSERT (IfrNvData !=3D NULL); - if (Private->Current !=3D NULL) { - IScsiConvertDeviceConfigDataToIfrNvData (Private->Current, IfrNvData); - } - - BufferSize =3D ISCSI_NAME_MAX_SIZE; - Status =3D gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSi= ze, InitiatorName); - if (EFI_ERROR (Status)) { - IfrNvData->InitiatorName[0] =3D L'\0'; - } else { - IScsiAsciiStrToUnicodeStr (InitiatorName, IfrNvData->InitiatorName); - } - - // - // Convert buffer data to by helper function BlockToConfig(= ) - // - HiiConfigRouting =3D Private->ConfigRouting; - BufferSize =3D sizeof (ISCSI_CONFIG_IFR_NVDATA); - ConfigRequest =3D Request; - if ((Request =3D=3D NULL) || (StrStr (Request, L"OFFSET") =3D=3D NULL)) = { - // - // Request has no request element, construct full request string. - // Allocate and fill a buffer large enough to hold the tem= plate - // followed by "&OFFSET=3D0&WIDTH=3DWWWWWWWWWWWWWWWW" followed by a Nu= ll-terminator - // - ConfigRequestHdr =3D HiiConstructConfigHdr (&gIp4IScsiConfigGuid, mVen= dorStorageName, Private->DriverHandle); - Size =3D (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); - ConfigRequest =3D AllocateZeroPool (Size); - ASSERT (ConfigRequest !=3D NULL); - AllocatedRequest =3D TRUE; - UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=3D0&WIDTH=3D%016LX", C= onfigRequestHdr, (UINT64)BufferSize); - FreePool (ConfigRequestHdr); - } - Status =3D HiiConfigRouting->BlockToConfig ( - HiiConfigRouting, - ConfigRequest, - (UINT8 *) IfrNvData, - BufferSize, - Results, - Progress - ); - FreePool (IfrNvData); - // - // Free the allocated config request string. - // - if (AllocatedRequest) { - FreePool (ConfigRequest); - ConfigRequest =3D NULL; - } - - // - // Set Progress string to the original request string. - // - if (Request =3D=3D NULL) { - *Progress =3D NULL; - } else if (StrStr (Request, L"OFFSET") =3D=3D NULL) { - *Progress =3D Request + StrLen (Request); - } - - return Status; -} - -/** - This function applies changes in a driver's configuration. - Input is a Configuration, which has the routing data for this - driver followed by name / value configuration pairs. The driver - must apply those pairs to its configurable storage. If the - driver's configuration is stored in a linear block of data - and the driver's name / value pairs are in - format, it may use the ConfigToBlock helper function (above) to - simplify the job. Currently not implemented. - - @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. - @param[in] Configuration A null-terminated Unicode string in - format. - @param[out] Progress A pointer to a string filled in with the - offset of the most recent '&' before the - first failing name / value pair (or the - beginn ing of the string if the failure - is in the first name / value pair) or - the terminating NULL if all was - successful. - - @retval EFI_SUCCESS The results have been distributed or are - awaiting distribution. - @retval EFI_OUT_OF_RESOURCES Not enough memory to store the - parts of the results that must be - stored awaiting possible future - protocols. - @retval EFI_INVALID_PARAMETERS Passing in a NULL for the - Results parameter would result - in this type of error. - @retval EFI_NOT_FOUND Target for the specified routing data - was not found. -**/ -EFI_STATUS -EFIAPI -IScsiFormRouteConfig ( - IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, - IN CONST EFI_STRING Configuration, - OUT EFI_STRING *Progress - ) -{ - if (Configuration =3D=3D NULL || Progress =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check routing data in . - // Note: if only one Storage is used, then this checking could be skippe= d. - // - if (!HiiIsConfigHdrMatch (Configuration, &gIp4IScsiConfigGuid, mVendorSt= orageName)) { - *Progress =3D Configuration; - return EFI_NOT_FOUND; - } - - *Progress =3D Configuration + StrLen (Configuration); - return EFI_SUCCESS; -} - -/** - This function is called to provide results data to the driver. - This data consists of a unique key that is used to identify - which data is either being passed back or being asked for. - - @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTO= COL. - @param[in] Action Specifies the type of action taken by the= browser. - @param[in] QuestionId A unique value which is sent to the origi= nal - exporting driver so that it can identify = the type - of data to expect. The format of the data= tends to - vary based on the opcode that enerated th= e callback. - @param[in] Type The type of value for the question. - @param[in] Value A pointer to the data being sent to the o= riginal - exporting driver. - @param[out] ActionRequest On return, points to the action requested= by the - callback function. - - @retval EFI_SUCCESS The callback successfully handled the act= ion. - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold t= he - variable and its data. - @retval EFI_DEVICE_ERROR The variable could not be saved. - @retval EFI_UNSUPPORTED The specified Action is not supported by = the - callback.Currently not implemented. - @retval EFI_INVALID_PARAMETERS Passing in wrong parameter. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiFormCallback ( - IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, - IN EFI_BROWSER_ACTION Action, - IN EFI_QUESTION_ID QuestionId, - IN UINT8 Type, - IN EFI_IFR_TYPE_VALUE *Value, - OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest - ) -{ - ISCSI_FORM_CALLBACK_INFO *Private; - UINTN BufferSize; - CHAR8 IScsiName[ISCSI_NAME_MAX_SIZE]; - CHAR16 PortString[128]; - CHAR8 Ip4String[IP4_STR_MAX_SIZE]; - CHAR8 LunString[ISCSI_LUN_STR_MAX_LEN]; - UINT64 Lun; - EFI_STRING_ID DeviceFormTitleToken; - ISCSI_CONFIG_IFR_NVDATA *IfrNvData; - ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry; - EFI_IP_ADDRESS HostIp; - EFI_IP_ADDRESS SubnetMask; - EFI_IP_ADDRESS Gateway; - EFI_STATUS Status; - EFI_INPUT_KEY Key; - - if (Action !=3D EFI_BROWSER_ACTION_CHANGING && Action !=3D EFI_BROWSER_A= CTION_CHANGED) { - return EFI_UNSUPPORTED; - } - - Private =3D ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); - // - // Retrieve uncommitted data from Browser - // - IfrNvData =3D AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); - ASSERT (IfrNvData !=3D NULL); - if (!HiiGetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof= (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData)) { - FreePool (IfrNvData); - return EFI_NOT_FOUND; - } - Status =3D EFI_SUCCESS; - - if (Action =3D=3D EFI_BROWSER_ACTION_CHANGING) { - if ((QuestionId >=3D KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberO= fIScsiDevices + KEY_DEVICE_ENTRY_BASE))) { - // - // In case goto the device configuration form, update the device for= m title. - // - ConfigFormEntry =3D IScsiGetConfigFormEntryByIndex ((UINT32) (Questi= onId - KEY_DEVICE_ENTRY_BASE)); - ASSERT (ConfigFormEntry !=3D NULL); - - UnicodeSPrint (PortString, (UINTN) sizeof (PortString), L"Port %s", = ConfigFormEntry->MacString); - DeviceFormTitleToken =3D (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE= ; - HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortS= tring, NULL); - - IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData)= ; - - Private->Current =3D ConfigFormEntry; - } - } else if (Action =3D=3D EFI_BROWSER_ACTION_CHANGED) { - switch (QuestionId) { - case KEY_INITIATOR_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName); - BufferSize =3D AsciiStrSize (IScsiName); - - Status =3D gIScsiInitiatorName.Set (&gIScsiInitiatorName, &Buff= erSize, IScsiName); - if (EFI_ERROR (Status)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = iSCSI Name!", NULL); - } - - *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; - break; - - case KEY_LOCAL_IP: - IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String); - Status =3D IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || - ((Private->Current->SessionConfigData.SubnetMask.Addr[0] !=3D 0)= && - !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Priva= te->Current->SessionConfigData.SubnetMask.Addr)))) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = IP address!", NULL); - Status =3D EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4,= sizeof (HostIp.v4)); - } - - break; - - case KEY_SUBNET_MASK: - IScsiUnicodeStrToAsciiStr (IfrNvData->SubnetMask, Ip4String); - Status =3D IScsiAsciiStrToIp (Ip4String, &SubnetMask.v4); - if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] !=3D 0) && (IScsiGetS= ubnetMaskPrefixLength (&SubnetMask.v4) =3D=3D 0))) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = Subnet Mask!", NULL); - Status =3D EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetM= ask.v4, sizeof (SubnetMask.v4)); - } - - break; - - case KEY_GATE_WAY: - IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String); - Status =3D IScsiAsciiStrToIp (Ip4String, &Gateway.v4); - if (EFI_ERROR (Status) || - ((Gateway.Addr[0] !=3D 0) && - (Private->Current->SessionConfigData.SubnetMask.Addr[0] !=3D 0)= && - !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Priv= ate->Current->SessionConfigData.SubnetMask.Addr)))) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = Gateway!", NULL); - Status =3D EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4= , sizeof (Gateway.v4)); - } - - break; - - case KEY_TARGET_IP: - IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String); - Status =3D IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v= 4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = IP address!", NULL); - Status =3D EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp.v4= , sizeof (HostIp.v4)); - } - - break; - - case KEY_TARGET_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName); - Status =3D IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName)); - if (EFI_ERROR (Status)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = iSCSI Name!", NULL); - } else { - AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCS= I_NAME_MAX_SIZE, IScsiName); - } - - break; - - case KEY_DHCP_ENABLE: - if (IfrNvData->InitiatorInfoFromDhcp =3D=3D 0) { - IfrNvData->TargetInfoFromDhcp =3D 0; - } - - break; - - case KEY_BOOT_LUN: - IScsiUnicodeStrToAsciiStr (IfrNvData->BootLun, LunString); - Status =3D IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun); - if (EFI_ERROR (Status)) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid = LUN string!", NULL); - } else { - CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof= (Lun)); - } - - break; - - case KEY_CHAP_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPName, Private->Current->Au= thConfigData.CHAPName); - break; - - case KEY_CHAP_SECRET: - IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPSecret, Private->Current->= AuthConfigData.CHAPSecret); - break; - - case KEY_REVERSE_CHAP_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPName, Private->Curr= ent->AuthConfigData.ReverseCHAPName); - break; - - case KEY_REVERSE_CHAP_SECRET: - IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPSecret, Private->Cu= rrent->AuthConfigData.ReverseCHAPSecret); - break; - - case KEY_CONFIG_ISID: - IScsiParseIsIdFromString (IfrNvData->IsId, Private->Current->Session= ConfigData.IsId); - IScsiConvertIsIdToString (IfrNvData->IsId, Private->Current->Session= ConfigData.IsId); - - break; - - case KEY_SAVE_CHANGES: - // - // First, update those fields which don't have INTERACTIVE set. - // - Private->Current->SessionConfigData.Enabled =3D IfrNvD= ata->Enabled; - Private->Current->SessionConfigData.InitiatorInfoFromDhcp =3D IfrNvD= ata->InitiatorInfoFromDhcp; - Private->Current->SessionConfigData.TargetPort =3D IfrNvD= ata->TargetPort; - if (Private->Current->SessionConfigData.TargetPort =3D=3D 0) { - Private->Current->SessionConfigData.TargetPort =3D ISCSI_WELL_KNOW= N_PORT; - } - - Private->Current->SessionConfigData.TargetInfoFromDhcp =3D IfrNvDat= a->TargetInfoFromDhcp; - Private->Current->AuthConfigData.CHAPType =3D IfrNvDat= a->CHAPType; - - // - // Only do full parameter validation if iSCSI is enabled on this dev= ice. - // - if (Private->Current->SessionConfigData.Enabled) { - // - // Validate the address configuration of the Initiator if DHCP isn= 't - // deployed. - // - if (!Private->Current->SessionConfigData.InitiatorInfoFromDhcp) { - CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalI= p, sizeof (HostIp.v4)); - CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.Su= bnetMask, sizeof (SubnetMask.v4)); - CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gatew= ay, sizeof (Gateway.v4)); - - if ((Gateway.Addr[0] !=3D 0)) { - if (SubnetMask.Addr[0] =3D=3D 0) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Ga= teway address is set but subnet mask is zero.", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], Su= bnetMask.Addr[0])) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Lo= cal IP and Gateway are not in the same subnet.", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - } - } - } - // - // Validate target configuration if DHCP isn't deployed. - // - if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) { - CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.Target= Ip, sizeof (HostIp.v4)); - if (IP4_IS_UNSPECIFIED (NTOHL (HostIp.Addr[0])) || IP4_IS_LOCAL_= BROADCAST (NTOHL (HostIp.Addr[0]))) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Targ= et IP is invalid!", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - } - - // - // Validate iSCSI target name configuration again: - // The format of iSCSI target name is already verified when user= input the name; - // here we only check the case user does not input the name. - // - if (Private->Current->SessionConfigData.TargetName[0] =3D=3D '\0= ') { - CreatePopUp ( - EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, - &Key, - L"iSCSI target name is NULL!", - NULL - ); - Status =3D EFI_INVALID_PARAMETER; - break; - } - - } - - if (IfrNvData->CHAPType !=3D ISCSI_CHAP_NONE) { - if ((IfrNvData->CHAPName[0] =3D=3D '\0') || (IfrNvData->CHAPSecr= et[0] =3D=3D '\0')) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"CHAP= Name or CHAP Secret is invalid!", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - } - - if ((IfrNvData->CHAPType =3D=3D ISCSI_CHAP_MUTUAL) && - ((IfrNvData->ReverseCHAPName[0] =3D=3D '\0') || (IfrNvData->= ReverseCHAPSecret[0] =3D=3D '\0')) - ) { - CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Reve= rse CHAP Name or Reverse CHAP Secret is invalid!", NULL); - Status =3D EFI_INVALID_PARAMETER; - break; - } - } - } - - BufferSize =3D sizeof (Private->Current->SessionConfigData); - gRT->SetVariable ( - Private->Current->MacString, - &gEfiIScsiInitiatorNameProtocolGuid, - ISCSI_CONFIG_VAR_ATTR, - BufferSize, - &Private->Current->SessionConfigData - ); - - BufferSize =3D sizeof (Private->Current->AuthConfigData); - gRT->SetVariable ( - Private->Current->MacString, - &gIScsiCHAPAuthInfoGuid, - ISCSI_CONFIG_VAR_ATTR, - BufferSize, - &Private->Current->AuthConfigData - ); - *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; - break; - - default: - break; - } - } - - if (!EFI_ERROR (Status)) { - // - // Pass changed uncommitted data back to Form Browser - // - HiiSetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof (I= SCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL); - } - - FreePool (IfrNvData); - - return Status; -} - -/** - Updates the iSCSI configuration form to add/delete an entry for the iSCS= I - device specified by the Controller. - - @param[in] DriverBindingHandle The driverbinding handle. - @param[in] Controller The controller handle of the iSCSI devic= e. - @param[in] AddForm Whether to add or delete a form entry. - - @retval EFI_SUCCESS The iSCSI configuration form is updated. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiConfigUpdateForm ( - IN EFI_HANDLE DriverBindingHandle, - IN EFI_HANDLE Controller, - IN BOOLEAN AddForm - ) -{ - LIST_ENTRY *Entry; - ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry; - BOOLEAN EntryExisted; - EFI_STATUS Status; - EFI_MAC_ADDRESS MacAddress; - UINTN HwAddressSize; - UINT16 VlanId; - CHAR16 PortString[128]; - UINT16 FormIndex; - UINTN BufferSize; - VOID *StartOpCodeHandle; - VOID *EndOpCodeHandle; - EFI_IFR_GUID_LABEL *StartLabel; - EFI_IFR_GUID_LABEL *EndLabel; - - ConfigFormEntry =3D NULL; - EntryExisted =3D FALSE; - - NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) { - ConfigFormEntry =3D NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENT= RY, Link); - - if (ConfigFormEntry->Controller =3D=3D Controller) { - EntryExisted =3D TRUE; - break; - } - } - - if (AddForm) { - if (EntryExisted) { - return EFI_SUCCESS; - } else { - // - // Add a new form. - // - ConfigFormEntry =3D (ISCSI_CONFIG_FORM_ENTRY *) AllocateZeroPool (si= zeof (ISCSI_CONFIG_FORM_ENTRY)); - if (ConfigFormEntry =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - InitializeListHead (&ConfigFormEntry->Link); - ConfigFormEntry->Controller =3D Controller; - - // - // Get the MAC address and convert it into the formatted string. - // - Status =3D NetLibGetMacAddress (Controller, &MacAddress, &HwAddressS= ize); - ASSERT (Status =3D=3D EFI_SUCCESS); - VlanId =3D NetLibGetVlanId (Controller); - - IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, Conf= igFormEntry->MacString); - - // - // Get the normal session configuration data. - // - BufferSize =3D sizeof (ConfigFormEntry->SessionConfigData); - Status =3D gRT->GetVariable ( - ConfigFormEntry->MacString, - &gEfiIScsiInitiatorNameProtocolGuid, - NULL, - &BufferSize, - &ConfigFormEntry->SessionConfigData - ); - if (EFI_ERROR (Status)) { - ZeroMem (&ConfigFormEntry->SessionConfigData, sizeof (ConfigFormEn= try->SessionConfigData)); - - // - // Generate OUI-format ISID based on MAC address. - // - CopyMem (ConfigFormEntry->SessionConfigData.IsId, &MacAddress, 6); - ConfigFormEntry->SessionConfigData.IsId[0] =3D - (UINT8) (ConfigFormEntry->SessionConfigData.IsId[0] & 0x3F); - } - // - // Get the CHAP authentication configuration data. - // - BufferSize =3D sizeof (ConfigFormEntry->AuthConfigData); - Status =3D gRT->GetVariable ( - ConfigFormEntry->MacString, - &gIScsiCHAPAuthInfoGuid, - NULL, - &BufferSize, - &ConfigFormEntry->AuthConfigData - ); - if (EFI_ERROR (Status)) { - ZeroMem (&ConfigFormEntry->AuthConfigData, sizeof (ConfigFormEntry= ->AuthConfigData)); - } - // - // Compose the Port string and create a new EFI_STRING_ID. - // - UnicodeSPrint (PortString, sizeof (PortString), L"Port %s", ConfigFo= rmEntry->MacString); - ConfigFormEntry->PortTitleToken =3D HiiSetString (mCallbackInfo->Reg= isteredHandle, 0, PortString, NULL); - - // - // Compose the help string of this port and create a new EFI_STRING_= ID. - // - UnicodeSPrint (PortString, sizeof (PortString), L"Set the iSCSI para= meters on port %s", ConfigFormEntry->MacString); - ConfigFormEntry->PortTitleHelpToken =3D HiiSetString (mCallbackInfo-= >RegisteredHandle, 0, PortString, NULL); - - InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link); - mNumberOfIScsiDevices++; - } - } else { - ASSERT (EntryExisted); - - mNumberOfIScsiDevices--; - RemoveEntryList (&ConfigFormEntry->Link); - FreePool (ConfigFormEntry); - mCallbackInfo->Current =3D NULL; - } - // - // Allocate space for creation of Buffer - // - - // - // Init OpCode Handle - // - StartOpCodeHandle =3D HiiAllocateOpCodeHandle (); - ASSERT (StartOpCodeHandle !=3D NULL); - - EndOpCodeHandle =3D HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle !=3D NULL); - - // - // Create Hii Extend Label OpCode as the start opcode - // - StartLabel =3D (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHa= ndle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - StartLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; - StartLabel->Number =3D DEVICE_ENTRY_LABEL; - - // - // Create Hii Extend Label OpCode as the end opcode - // - EndLabel =3D (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle= , &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - EndLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; - EndLabel->Number =3D LABEL_END; - - FormIndex =3D 0; - NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) { - ConfigFormEntry =3D NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENT= RY, Link); - - HiiCreateGotoOpCode ( - StartOpCodeHandle, // Container for dynam= ic created opcodes - FORMID_DEVICE_FORM, // Target Form ID - ConfigFormEntry->PortTitleToken, // Prompt text - ConfigFormEntry->PortTitleHelpToken, // Help text - EFI_IFR_FLAG_CALLBACK, // Question flag - (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex) // Question ID - ); - - FormIndex++; - } - - HiiUpdateForm ( - mCallbackInfo->RegisteredHandle, - &gIp4IScsiConfigGuid, - FORMID_MAIN_FORM, - StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL - EndOpCodeHandle // LABEL_END - ); - - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); - - return EFI_SUCCESS; -} - -/** - Initialize the iSCSI configuration form. - - @param[in] DriverBindingHandle The iSCSI driverbinding handle. - - @retval EFI_SUCCESS The iSCSI configuration form is initial= ized. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiConfigFormInit ( - VOID - ) -{ - EFI_STATUS Status; - EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - ISCSI_FORM_CALLBACK_INFO *CallbackInfo; - - Status =3D gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOI= D **)&HiiDatabase); - if (EFI_ERROR (Status)) { - return Status; - } - - CallbackInfo =3D (ISCSI_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (= ISCSI_FORM_CALLBACK_INFO)); - if (CallbackInfo =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - CallbackInfo->Signature =3D ISCSI_FORM_CALLBACK_INFO_SIGNATURE; - CallbackInfo->HiiDatabase =3D HiiDatabase; - CallbackInfo->Current =3D NULL; - - CallbackInfo->ConfigAccess.ExtractConfig =3D IScsiFormExtractConfig; - CallbackInfo->ConfigAccess.RouteConfig =3D IScsiFormRouteConfig; - CallbackInfo->ConfigAccess.Callback =3D IScsiFormCallback; - - Status =3D gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL,= (VOID **)&CallbackInfo->ConfigRouting); - if (EFI_ERROR (Status)) { - FreePool(CallbackInfo); - return Status; - } - - // - // Install Device Path Protocol and Config Access protocol to driver han= dle - // - Status =3D gBS->InstallMultipleProtocolInterfaces ( - &CallbackInfo->DriverHandle, - &gEfiDevicePathProtocolGuid, - &mIScsiHiiVendorDevicePath, - &gEfiHiiConfigAccessProtocolGuid, - &CallbackInfo->ConfigAccess, - NULL - ); - ASSERT_EFI_ERROR (Status); - - // - // Publish our HII data - // - CallbackInfo->RegisteredHandle =3D HiiAddPackages ( - &gIp4IScsiConfigGuid, - CallbackInfo->DriverHandle, - IScsi4DxeStrings, - IScsiConfigDxeBin, - NULL - ); - if (CallbackInfo->RegisteredHandle =3D=3D NULL) { - FreePool(CallbackInfo); - return EFI_OUT_OF_RESOURCES; - } - - mCallbackInfo =3D CallbackInfo; - - return Status; -} - -/** - Unload the iSCSI configuration form, this includes: delete all the iSCSI - device configuration entries, uninstall the form callback protocol and - free the resources used. - - @param[in] DriverBindingHandle The iSCSI driverbinding handle. - - @retval EFI_SUCCESS The iSCSI configuration form is unloaded= . - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. -**/ -EFI_STATUS -IScsiConfigFormUnload ( - IN EFI_HANDLE DriverBindingHandle - ) -{ - ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry; - - while (!IsListEmpty (&mIScsiConfigFormList)) { - // - // Uninstall the device forms as the iSCSI driver instance may fail to - // control the controller but still install the device configuration f= orm. - // In such case, upon driver unloading, the driver instance's driverbi= nding. - // stop () won't be called, so we have to take this chance here to uni= nstall - // the device form. - // - ConfigFormEntry =3D NET_LIST_USER_STRUCT (mIScsiConfigFormList.Forward= Link, ISCSI_CONFIG_FORM_ENTRY, Link); - IScsiConfigUpdateForm (DriverBindingHandle, ConfigFormEntry->Controlle= r, FALSE); - } - - // - // Remove HII package list - // - mCallbackInfo->HiiDatabase->RemovePackageList ( - mCallbackInfo->HiiDatabase, - mCallbackInfo->RegisteredHandle - ); - - // - // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL - // - gBS->UninstallMultipleProtocolInterfaces ( - mCallbackInfo->DriverHandle, - &gEfiDevicePathProtocolGuid, - &mIScsiHiiVendorDevicePath, - &gEfiHiiConfigAccessProtocolGuid, - &mCallbackInfo->ConfigAccess, - NULL - ); - FreePool (mCallbackInfo); - - return EFI_SUCCESS; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDhcp.c b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiDhcp.c deleted file mode 100644 index 6a876c8b69dd..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDhcp.c +++ /dev/null @@ -1,472 +0,0 @@ -/** @file - iSCSI DHCP related configuration routines. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -/** - Extract the Root Path option and get the required target information. - - @param[in] RootPath The RootPath. - @param[in] Length Length of the RootPath option payload= . - @param[in, out] ConfigNvData The iSCSI session configuration data = read from nonvolatile device. - - @retval EFI_SUCCESS All required information is extracted from= the RootPath option. - @retval EFI_NOT_FOUND The RootPath is not an iSCSI RootPath. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_INVALID_PARAMETER The RootPath is mal-formatted. -**/ -EFI_STATUS -IScsiDhcpExtractRootPath ( - IN CHAR8 *RootPath, - IN UINT8 Length, - IN OUT ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData - ) -{ - EFI_STATUS Status; - UINT8 IScsiRootPathIdLen; - CHAR8 *TmpStr; - ISCSI_ROOT_PATH_FIELD Fields[RP_FIELD_IDX_MAX]; - ISCSI_ROOT_PATH_FIELD *Field; - UINT32 FieldIndex; - UINT8 Index; - - // - // "iscsi:"":"":"":"":" - // - IScsiRootPathIdLen =3D (UINT8) AsciiStrLen (ISCSI_ROOT_PATH_ID); - - if ((Length <=3D IScsiRootPathIdLen) || (CompareMem (RootPath, ISCSI_ROO= T_PATH_ID, IScsiRootPathIdLen) !=3D 0)) { - return EFI_NOT_FOUND; - } - // - // Skip the iSCSI RootPath ID "iscsi:". - // - RootPath +=3D IScsiRootPathIdLen; - Length =3D (UINT8) (Length - IScsiRootPathIdLen); - - TmpStr =3D (CHAR8 *) AllocatePool (Length + 1); - if (TmpStr =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - CopyMem (TmpStr, RootPath, Length); - TmpStr[Length] =3D '\0'; - - Index =3D 0; - FieldIndex =3D RP_FIELD_IDX_SERVERNAME; - ZeroMem (&Fields[0], sizeof (Fields)); - - // - // Extract the fields in the Root Path option string. - // - for (FieldIndex =3D RP_FIELD_IDX_SERVERNAME; (FieldIndex < RP_FIELD_IDX_= MAX) && (Index < Length); FieldIndex++) { - if (TmpStr[Index] !=3D ISCSI_ROOT_PATH_FIELD_DELIMITER) { - Fields[FieldIndex].Str =3D &TmpStr[Index]; - } - - while ((TmpStr[Index] !=3D ISCSI_ROOT_PATH_FIELD_DELIMITER) && (Index = < Length)) { - Index++; - } - - if (TmpStr[Index] =3D=3D ISCSI_ROOT_PATH_FIELD_DELIMITER) { - if (FieldIndex !=3D RP_FIELD_IDX_TARGETNAME) { - TmpStr[Index] =3D '\0'; - Index++; - } - - if (Fields[FieldIndex].Str !=3D NULL) { - Fields[FieldIndex].Len =3D (UINT8) AsciiStrLen (Fields[FieldIndex]= .Str); - } - } - } - - if (FieldIndex !=3D RP_FIELD_IDX_MAX) { - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - - if ((Fields[RP_FIELD_IDX_SERVERNAME].Str =3D=3D NULL) || - (Fields[RP_FIELD_IDX_TARGETNAME].Str =3D=3D NULL) || - (Fields[RP_FIELD_IDX_PROTOCOL].Len > 1) - ) { - - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - // - // Get the IP address of the target. - // - Field =3D &Fields[RP_FIELD_IDX_SERVERNAME]; - Status =3D IScsiAsciiStrToIp (Field->Str, &ConfigNvData->TargetIp); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - // - // Check the protocol type. - // - Field =3D &Fields[RP_FIELD_IDX_PROTOCOL]; - if ((Field->Str !=3D NULL) && ((*(Field->Str) - '0') !=3D EFI_IP_PROTO_T= CP)) { - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - // - // Get the port of the iSCSI target. - // - Field =3D &Fields[RP_FIELD_IDX_PORT]; - if (Field->Str !=3D NULL) { - ConfigNvData->TargetPort =3D (UINT16) AsciiStrDecimalToUintn (Field->S= tr); - } else { - ConfigNvData->TargetPort =3D ISCSI_WELL_KNOWN_PORT; - } - // - // Get the LUN. - // - Field =3D &Fields[RP_FIELD_IDX_LUN]; - if (Field->Str !=3D NULL) { - Status =3D IScsiAsciiStrToLun (Field->Str, ConfigNvData->BootLun); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } else { - ZeroMem (ConfigNvData->BootLun, sizeof (ConfigNvData->BootLun)); - } - // - // Get the target iSCSI Name. - // - Field =3D &Fields[RP_FIELD_IDX_TARGETNAME]; - - if (AsciiStrLen (Field->Str) > ISCSI_NAME_MAX_SIZE - 1) { - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - // - // Validate the iSCSI name. - // - Status =3D IScsiNormalizeName (Field->Str, AsciiStrLen (Field->Str)); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - AsciiStrCpyS (ConfigNvData->TargetName, ISCSI_NAME_MAX_SIZE, Field->Str)= ; - -ON_EXIT: - - FreePool (TmpStr); - - return Status; -} - -/** - The callback function registerd to the DHCP4 instance which is used to s= elect - the qualified DHCP OFFER. - - @param[in] This The DHCP4 protocol. - @param[in] Context The context set when configuring the DHCP4 prot= ocol. - @param[in] CurrentState The current state of the DHCP4 protocol. - @param[in] Dhcp4Event The event occurs in the current state. - @param[in] Packet The DHCP packet that is to be sent or already r= eceived. - @param[out] NewPacket The packet used to replace the above Packet. - - @retval EFI_SUCCESS Either the DHCP OFFER is qualified or we're not= intereseted - in the Dhcp4Event. - @retval EFI_NOT_READY The DHCP OFFER packet doesn't match our require= ments. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiDhcpSelectOffer ( - IN EFI_DHCP4_PROTOCOL * This, - IN VOID *Context, - IN EFI_DHCP4_STATE CurrentState, - IN EFI_DHCP4_EVENT Dhcp4Event, - IN EFI_DHCP4_PACKET * Packet, OPTIONAL - OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL - ) -{ - EFI_STATUS Status; - UINT32 OptionCount; - EFI_DHCP4_PACKET_OPTION **OptionList; - UINT32 Index; - - if ((Dhcp4Event !=3D Dhcp4RcvdOffer) && (Dhcp4Event !=3D Dhcp4SelectOffe= r)) { - return EFI_SUCCESS; - } - - OptionCount =3D 0; - - Status =3D This->Parse (This, Packet, &OptionCount, NULL); - if (Status !=3D EFI_BUFFER_TOO_SMALL) { - return EFI_NOT_READY; - } - - OptionList =3D AllocatePool (OptionCount * sizeof (EFI_DHCP4_PACKET_OPTI= ON *)); - if (OptionList =3D=3D NULL) { - return EFI_NOT_READY; - } - - Status =3D This->Parse (This, Packet, &OptionCount, OptionList); - if (EFI_ERROR (Status)) { - FreePool (OptionList); - return EFI_NOT_READY; - } - - for (Index =3D 0; Index < OptionCount; Index++) { - if (OptionList[Index]->OpCode !=3D DHCP4_TAG_ROOTPATH) { - continue; - } - - Status =3D IScsiDhcpExtractRootPath ( - (CHAR8 *) &OptionList[Index]->Data[0], - OptionList[Index]->Length, - (ISCSI_SESSION_CONFIG_NVDATA *) Context - ); - - break; - } - - if (Index =3D=3D OptionCount) { - Status =3D EFI_NOT_READY; - } - - FreePool (OptionList); - - return Status; -} - -/** - Parse the DHCP ACK to get the address configuration and DNS information. - - @param[in] Dhcp4 The DHCP4 protocol. - @param[in, out] ConfigData The session configuration data. - - @retval EFI_SUCCESS The DNS information is got from the DHCP A= CK. - @retval EFI_NO_MAPPING DHCP failed to acquire address and other i= nformation. - @retval EFI_INVALID_PARAMETER The DHCP ACK's DNS option is mal-formatted= . - @retval EFI_DEVICE_ERROR Other errors as indicated. -**/ -EFI_STATUS -IScsiParseDhcpAck ( - IN EFI_DHCP4_PROTOCOL *Dhcp4, - IN OUT ISCSI_SESSION_CONFIG_DATA *ConfigData - ) -{ - EFI_STATUS Status; - EFI_DHCP4_MODE_DATA Dhcp4ModeData; - UINT32 OptionCount; - EFI_DHCP4_PACKET_OPTION **OptionList; - UINT32 Index; - - Status =3D Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData); - if (EFI_ERROR (Status)) { - return Status; - } - - if (Dhcp4ModeData.State !=3D Dhcp4Bound) { - return EFI_NO_MAPPING; - } - - CopyMem (&ConfigData->NvData.LocalIp, &Dhcp4ModeData.ClientAddress, size= of (EFI_IPv4_ADDRESS)); - CopyMem (&ConfigData->NvData.SubnetMask, &Dhcp4ModeData.SubnetMask, size= of (EFI_IPv4_ADDRESS)); - CopyMem (&ConfigData->NvData.Gateway, &Dhcp4ModeData.RouterAddress, size= of (EFI_IPv4_ADDRESS)); - - OptionCount =3D 0; - OptionList =3D NULL; - - Status =3D Dhcp4->Parse (Dhcp4, Dhcp4ModeData.ReplyPacket, &OptionC= ount, OptionList); - if (Status !=3D EFI_BUFFER_TOO_SMALL) { - return EFI_DEVICE_ERROR; - } - - OptionList =3D AllocatePool (OptionCount * sizeof (EFI_DHCP4_PACKET_OPTI= ON *)); - if (OptionList =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status =3D Dhcp4->Parse (Dhcp4, Dhcp4ModeData.ReplyPacket, &OptionCount,= OptionList); - if (EFI_ERROR (Status)) { - FreePool (OptionList); - return EFI_DEVICE_ERROR; - } - - for (Index =3D 0; Index < OptionCount; Index++) { - // - // Get DNS server addresses and DHCP server address from this offer. - // - if (OptionList[Index]->OpCode =3D=3D DHCP4_TAG_DNS_SERVER) { - - if (((OptionList[Index]->Length & 0x3) !=3D 0) || (OptionList[Index]= ->Length =3D=3D 0)) { - Status =3D EFI_INVALID_PARAMETER; - break; - } - // - // Primary DNS server address. - // - CopyMem (&ConfigData->PrimaryDns, &OptionList[Index]->Data[0], sizeo= f (EFI_IPv4_ADDRESS)); - - if (OptionList[Index]->Length > 4) { - // - // Secondary DNS server address - // - CopyMem (&ConfigData->SecondaryDns, &OptionList[Index]->Data[4], s= izeof (EFI_IPv4_ADDRESS)); - } - } else if (OptionList[Index]->OpCode =3D=3D DHCP4_TAG_SERVER_ID) { - if (OptionList[Index]->Length !=3D 4) { - Status =3D EFI_INVALID_PARAMETER; - break; - } - - CopyMem (&ConfigData->DhcpServer, &OptionList[Index]->Data[0], sizeo= f (EFI_IPv4_ADDRESS)); - } - } - - FreePool (OptionList); - - return Status; -} - -/** - Parse the DHCP ACK to get the address configuration and DNS information. - - @param[in] Image The handle of the driver image. - @param[in] Controller The handle of the controller; - @param[in, out] ConfigData The session configuration data. - - @retval EFI_SUCCESS The DNS information is got from the DHCP A= CK. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NO_MEDIA There was a media error. - @retval Others Other errors as indicated. - -**/ -EFI_STATUS -IScsiDoDhcp ( - IN EFI_HANDLE Image, - IN EFI_HANDLE Controller, - IN OUT ISCSI_SESSION_CONFIG_DATA *ConfigData - ) -{ - EFI_HANDLE Dhcp4Handle; - EFI_DHCP4_PROTOCOL *Dhcp4; - EFI_STATUS Status; - EFI_DHCP4_PACKET_OPTION *ParaList; - EFI_DHCP4_CONFIG_DATA Dhcp4ConfigData; - EFI_STATUS MediaStatus; - UINT8 *Data; - - Dhcp4Handle =3D NULL; - Dhcp4 =3D NULL; - ParaList =3D NULL; - - // - // Check media status before do DHCP - // - MediaStatus =3D EFI_SUCCESS; - NetLibDetectMediaWaitTimeout (Controller, ISCSI_CHECK_MEDIA_GET_DHCP_WAI= TING_TIME, &MediaStatus); - if (MediaStatus !=3D EFI_SUCCESS) { - return EFI_NO_MEDIA; - } - - // - // Create a DHCP4 child instance and get the protocol. - // - Status =3D NetLibCreateServiceChild ( - Controller, - Image, - &gEfiDhcp4ServiceBindingProtocolGuid, - &Dhcp4Handle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->OpenProtocol ( - Dhcp4Handle, - &gEfiDhcp4ProtocolGuid, - (VOID **)&Dhcp4, - Image, - Controller, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - ParaList =3D AllocatePool (sizeof (EFI_DHCP4_PACKET_OPTION) + 3); - if (ParaList =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - // - // Ask the server to reply with Netmask, Router, DNS and RootPath option= s. - // - ParaList->OpCode =3D DHCP4_TAG_PARA_LIST; - ParaList->Length =3D (UINT8) (ConfigData->NvData.TargetInfoFromDhcp ? 4= : 3); - Data =3D &ParaList->Data[0]; - Data[0] =3D DHCP4_TAG_NETMASK; - Data[1] =3D DHCP4_TAG_ROUTER; - Data[2] =3D DHCP4_TAG_DNS_SERVER; - Data[3] =3D DHCP4_TAG_ROOTPATH; - - ZeroMem (&Dhcp4ConfigData, sizeof (EFI_DHCP4_CONFIG_DATA)); - Dhcp4ConfigData.OptionCount =3D 1; - Dhcp4ConfigData.OptionList =3D &ParaList; - - if (ConfigData->NvData.TargetInfoFromDhcp) { - // - // Use callback to select an offer which contains target information. - // - Dhcp4ConfigData.Dhcp4Callback =3D IScsiDhcpSelectOffer; - Dhcp4ConfigData.CallbackContext =3D &ConfigData->NvData; - } - - Status =3D Dhcp4->Configure (Dhcp4, &Dhcp4ConfigData); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Status =3D Dhcp4->Start (Dhcp4, NULL); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - // - // Parse the ACK to get required information. - // - Status =3D IScsiParseDhcpAck (Dhcp4, ConfigData); - -ON_EXIT: - - if (ParaList !=3D NULL) { - FreePool (ParaList); - } - - if (Dhcp4 !=3D NULL) { - Dhcp4->Stop (Dhcp4); - Dhcp4->Configure (Dhcp4, NULL); - - gBS->CloseProtocol ( - Dhcp4Handle, - &gEfiDhcp4ProtocolGuid, - Image, - Controller - ); - } - - NetLibDestroyServiceChild ( - Controller, - Image, - &gEfiDhcp4ServiceBindingProtocolGuid, - Dhcp4Handle - ); - - return Status; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiDriver.c deleted file mode 100644 index 730f3e506bbc..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c +++ /dev/null @@ -1,676 +0,0 @@ -/** @file - The entry point of IScsi driver. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -EFI_DRIVER_BINDING_PROTOCOL gIScsiDriverBinding =3D { - IScsiDriverBindingSupported, - IScsiDriverBindingStart, - IScsiDriverBindingStop, - 0xa, - NULL, - NULL -}; - -/** - Tests to see if this driver supports the RemainingDevicePath. - - @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. This - parameter is ignored by device drivers,= and is optional for bus - drivers. For bus drivers, if this param= eter is not NULL, then - the bus driver must determine if the bu= s controller specified - by ControllerHandle and the child contr= oller specified - by RemainingDevicePath are both support= ed by this - bus driver. - - @retval EFI_SUCCESS The RemainingDevicePath is supported or= NULL. - @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e and - RemainingDevicePath is not supported by= the driver specified by This. -**/ -EFI_STATUS -IScsiIsDevicePathSupported ( - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ) -{ - EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath; - - CurrentDevicePath =3D RemainingDevicePath; - if (CurrentDevicePath !=3D NULL) { - while (!IsDevicePathEnd (CurrentDevicePath)) { - if ((CurrentDevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && (Curre= ntDevicePath->SubType =3D=3D MSG_ISCSI_DP)) { - return EFI_SUCCESS; - } - - CurrentDevicePath =3D NextDevicePathNode (CurrentDevicePath); - } - - return EFI_UNSUPPORTED; - } - - return EFI_SUCCESS; -} - -/** - Tests to see if this driver supports a given controller. If a child devi= ce is provided, - it further tests to see if this driver supports creating a handle for th= e specified child device. - - @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. - @param[in] ControllerHandle The handle of the controller to test. T= his handle - must support a protocol interface that = supplies - an I/O abstraction to the driver. - @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. - This parameter is ignored by device dri= vers, and is optional for bus drivers. - - - @retval EFI_SUCCESS The device specified by ControllerHandl= e and - RemainingDevicePath is supported by the= driver specified by This. - @retval EFI_ALREADY_STARTED The device specified by ControllerHandl= e and - RemainingDevicePath is already being ma= naged by the driver - specified by This. - @retval EFI_ACCESS_DENIED The device specified by ControllerHandl= e and - RemainingDevicePath is already being ma= naged by a different - driver or an application that requires = exclusive acces. - Currently not implemented. - @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e and - RemainingDevicePath is not supported by= the driver specified by This. -**/ -EFI_STATUS -EFIAPI -IScsiDriverBindingSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ) -{ - EFI_STATUS Status; - - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiCallerIdGuid, - NULL, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL - ); - if (!EFI_ERROR (Status)) { - return EFI_ALREADY_STARTED; - } - - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiTcp4ServiceBindingProtocolGuid, - NULL, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - - Status =3D IScsiIsDevicePathSupported (RemainingDevicePath); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - - if (IScsiDhcpIsConfigured (ControllerHandle)) { - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiDhcp4ServiceBindingProtocolGuid, - NULL, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return EFI_UNSUPPORTED; - } - } - - return EFI_SUCCESS; -} - -/** - Start this driver on ControllerHandle. - - The Start() function is designed to be invoked from the EFI boot service= ConnectController(). - As a result, much of the error checking on the parameters to Start() has= been moved into this - common boot service. It is legal to call Start() from other locations, b= ut the following calling - restrictions must be followed or the system behavior will not be determi= nistic. - 1. ControllerHandle must be a valid EFI_HANDLE. - 2. If RemainingDevicePath is not NULL, then it must be a pointer to a na= turally aligned - EFI_DEVICE_PATH_PROTOCOL. - 3. Prior to calling Start(), the Supported() function for the driver spe= cified by This must - have been called with the same calling parameters, and Supported() mu= st have returned EFI_SUCCESS. - - @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. - @param[in] ControllerHandle The handle of the controller to start. = This handle - must support a protocol interface that = supplies - an I/O abstraction to the driver. - @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. - This parameter is ignored by device dri= vers, and is optional for bus drivers. - - @retval EFI_SUCCESS The device was started. - @retval EFI_DEVICE_ERROR The device could not be started due to = a device error. - Currently not implemented. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due = to a lack of resources. - @retval Others The driver failded to start the device. -**/ -EFI_STATUS -EFIAPI -IScsiDriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ) -{ - EFI_STATUS Status; - ISCSI_DRIVER_DATA *Private; - VOID *Interface; - - Private =3D IScsiCreateDriverData (This->DriverBindingHandle, Controller= Handle); - if (Private =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Create a underlayer child instance, but not need to configure it. Jus= t open ChildHandle - // via BY_DRIVER. That is, establishing the relationship between Control= lerHandle and ChildHandle. - // Therefore, when DisconnectController(), especially VLAN virtual contr= oller handle, - // IScsiDriverBindingStop() will be called. - // - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiTcp4ServiceBindingProtocolGuid, - &Private->ChildHandle - ); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->OpenProtocol ( - Private->ChildHandle, - &gEfiTcp4ProtocolGuid, - &Interface, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - // - // Always install private protocol no matter what happens later. We need= to - // keep the relationship between ControllerHandle and ChildHandle. - // - Status =3D gBS->InstallProtocolInterface ( - &ControllerHandle, - &gEfiCallerIdGuid, - EFI_NATIVE_INTERFACE, - &Private->IScsiIdentifier - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - // - // Try to add a port configuration page for this controller. - // - IScsiConfigUpdateForm (This->DriverBindingHandle, ControllerHandle, TRUE= ); - - // - // Get the iSCSI configuration data of this controller. - // - Status =3D IScsiGetConfigData (Private); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - // - // Try to login and create an iSCSI session according to the configurati= on. - // - Status =3D IScsiSessionLogin (Private); - if (Status =3D=3D EFI_MEDIA_CHANGED) { - // - // The specified target is not available and the redirection informati= on is - // got, login the session again with the updated target address. - // - Status =3D IScsiSessionLogin (Private); - } - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - // - // Duplicate the Session's tcp connection device path. The source port f= ield - // will be set to zero as one iSCSI session is comprised of several iSCS= I - // connections. - // - Private->DevicePath =3D IScsiGetTcpConnDevicePath (Private); - if (Private->DevicePath =3D=3D NULL) { - goto ON_ERROR; - } - // - // Install the updated device path onto the ExtScsiPassThruHandle. - // - Status =3D gBS->InstallProtocolInterface ( - &Private->ExtScsiPassThruHandle, - &gEfiDevicePathProtocolGuid, - EFI_NATIVE_INTERFACE, - Private->DevicePath - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - // - // ISCSI children should share the default Tcp child, just open the defa= ult Tcp child via BY_CHILD_CONTROLLER. - // - Status =3D gBS->OpenProtocol ( - Private->ChildHandle, /// Default Tcp child - &gEfiTcp4ProtocolGuid, - &Interface, - This->DriverBindingHandle, - Private->ExtScsiPassThruHandle, - EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER - ); - if (EFI_ERROR (Status)) { - gBS->UninstallMultipleProtocolInterfaces ( - Private->ExtScsiPassThruHandle, - &gEfiExtScsiPassThruProtocolGuid, - &Private->IScsiExtScsiPassThru, - &gEfiDevicePathProtocolGuid, - Private->DevicePath, - NULL - ); - - goto ON_ERROR; - } - - // - // Update/Publish the iSCSI Boot Firmware Table. - // - IScsiPublishIbft (); - - return EFI_SUCCESS; - -ON_ERROR: - - IScsiSessionAbort (&Private->Session); - - return Status; -} - -/** - Stop this driver on ControllerHandle. - - Release the control of this controller and remove the IScsi functions. T= he Stop() - function is designed to be invoked from the EFI boot service DisconnectC= ontroller(). - 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 loc= ations, - but the following calling restrictions must be followed or the system be= havior will not be deterministic. - 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previo= us 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 created = in this driver's - Start() function, and the Start() function must have called OpenProto= col() on - ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONT= ROLLER. - - @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOC= OL instance. - @param[in] ControllerHandle A handle to the device being stopped. The = handle must - support a bus specific I/O protocol for th= e driver - to use to stop the device. - @param[in] NumberOfChildren The number of child device handles in Chil= dHandleBuffer.Not used. - @param[in] ChildHandleBuffer An array of child handles to be freed. May= be NULL - if NumberOfChildren is 0.Not used. - - @retval EFI_SUCCESS The device was stopped. - @retval EFI_DEVICE_ERROR The device could not be stopped due to a d= evice error. - @retval EFI_INVALID_PARAMETER Child handle is NULL. - @retval EFI_ACCESS_DENIED The protocol could not be removed from the= Handle - because its interfaces are being used. - -**/ -EFI_STATUS -EFIAPI -IScsiDriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer OPTIONAL - ) -{ - EFI_HANDLE IScsiController; - EFI_STATUS Status; - ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier; - ISCSI_DRIVER_DATA *Private; - EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru; - ISCSI_CONNECTION *Conn; - - if (NumberOfChildren !=3D 0) { - // - // We should have only one child. - // - Status =3D gBS->OpenProtocol ( - ChildHandleBuffer[0], - &gEfiExtScsiPassThruProtocolGuid, - (VOID **) &PassThru, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru); - Conn =3D NET_LIST_HEAD (&Private->Session.Conns, ISCSI_CONNECTION, = Link); - - // - // Previously the TCP4 protocol is opened BY_CHILD_CONTROLLER. Just cl= ose - // the protocol here but not uninstall the device path protocol and - // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle. - // - gBS->CloseProtocol ( - Private->ChildHandle, - &gEfiTcp4ProtocolGuid, - Private->Image, - Private->ExtScsiPassThruHandle - ); - - gBS->CloseProtocol ( - Conn->Tcp4Io.Handle, - &gEfiTcp4ProtocolGuid, - Private->Image, - Private->ExtScsiPassThruHandle - ); - - return EFI_SUCCESS; - } - // - // Get the handle of the controller we are controling. - // - IScsiController =3D NetLibGetNicHandle (ControllerHandle, &gEfiTcp4Proto= colGuid); - - Status =3D gBS->OpenProtocol ( - IScsiController, - &gEfiCallerIdGuid, - (VOID **)&IScsiIdentifier, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - Private =3D ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier); - - if (Private->ChildHandle !=3D NULL) { - Status =3D gBS->CloseProtocol ( - Private->ChildHandle, - &gEfiTcp4ProtocolGuid, - This->DriverBindingHandle, - IScsiController - ); - - ASSERT (!EFI_ERROR (Status)); - - Status =3D NetLibDestroyServiceChild ( - IScsiController, - This->DriverBindingHandle, - &gEfiTcp4ServiceBindingProtocolGuid, - Private->ChildHandle - ); - ASSERT (!EFI_ERROR (Status)); - } - - IScsiConfigUpdateForm (This->DriverBindingHandle, IScsiController, FALSE= ); - - // - // Uninstall the private protocol. - // - gBS->UninstallProtocolInterface ( - IScsiController, - &gEfiCallerIdGuid, - &Private->IScsiIdentifier - ); - - // - // Update the iSCSI Boot Firware Table. - // - IScsiPublishIbft (); - - IScsiSessionAbort (&Private->Session); - Status =3D IScsiCleanDriverData (Private); - if (EFI_ERROR (Status)) { - return Status; - } - - return EFI_SUCCESS; -} - -/** - Unloads an image(the iSCSI driver). - - @param[in] ImageHandle Handle that identifies the image to be unl= oaded. - - @retval EFI_SUCCESS The image has been unloaded. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -EfiIScsiUnload ( - IN EFI_HANDLE ImageHandle - ) -{ - EFI_STATUS Status; - UINTN DeviceHandleCount; - EFI_HANDLE *DeviceHandleBuffer; - UINTN Index; - EFI_COMPONENT_NAME_PROTOCOL *ComponentName; - EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; - - // - // Try to disonnect the driver from the devices it's controlling. - // - Status =3D gBS->LocateHandleBuffer ( - AllHandles, - NULL, - NULL, - &DeviceHandleCount, - &DeviceHandleBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - - for (Index =3D 0; Index < DeviceHandleCount; Index++) { - Status =3D IScsiTestManagedDevice ( - DeviceHandleBuffer[Index], - gIScsiDriverBinding.DriverBindingHandle, - &gEfiTcp4ProtocolGuid - ); - if (EFI_ERROR (Status)) { - continue; - } - Status =3D gBS->DisconnectController ( - DeviceHandleBuffer[Index], - gIScsiDriverBinding.DriverBindingHandle, - NULL - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } - - // - // Unload the iSCSI configuration form. - // - Status =3D IScsiConfigFormUnload (gIScsiDriverBinding.DriverBindingHandl= e); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - // - // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 d= river binding handle - // if it has been installed. - // - Status =3D gBS->HandleProtocol ( - gIScsiDriverBinding.DriverBindingHandle, - &gEfiComponentNameProtocolGuid, - (VOID **) &ComponentName - ); - if (!EFI_ERROR (Status)) { - Status =3D gBS->UninstallMultipleProtocolInterfaces ( - gIScsiDriverBinding.DriverBindingHandle, - &gEfiComponentNameProtocolGuid, - ComponentName, - NULL - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } - - Status =3D gBS->HandleProtocol ( - gIScsiDriverBinding.DriverBindingHandle, - &gEfiComponentName2ProtocolGuid, - (VOID **) &ComponentName2 - ); - if (!EFI_ERROR (Status)) { - gBS->UninstallMultipleProtocolInterfaces ( - gIScsiDriverBinding.DriverBindingHandle, - &gEfiComponentName2ProtocolGuid, - ComponentName2, - NULL - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } - - Status =3D gBS->UninstallMultipleProtocolInterfaces ( - ImageHandle, - &gEfiDriverBindingProtocolGuid, - &gIScsiDriverBinding, - &gEfiIScsiInitiatorNameProtocolGuid, - &gIScsiInitiatorName, - NULL - ); -ON_EXIT: - - if (DeviceHandleBuffer !=3D NULL) { - FreePool (DeviceHandleBuffer); - } - - return Status; -} - -/** - This is the declaration of an EFI image entry point. This entry point is - the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers includ= ing - both device drivers and bus drivers. It initialize the global variables = and - publish the driver binding protocol. - - @param[in] ImageHandle The firmware allocated handle for the UEFI= image. - @param[in] SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was inst= alled unexpectedly. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiDriverEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - EFI_ISCSI_INITIATOR_NAME_PROTOCOL *IScsiInitiatorName; - - // - // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL. - // - Status =3D gBS->LocateProtocol ( - &gEfiIScsiInitiatorNameProtocolGuid, - NULL, - (VOID**) &IScsiInitiatorName - ); - - if (!EFI_ERROR (Status)) { - return EFI_ACCESS_DENIED; - } - - // - // Initialize the EFI Driver Library - // - Status =3D EfiLibInstallDriverBindingComponentName2 ( - ImageHandle, - SystemTable, - &gIScsiDriverBinding, - ImageHandle, - &gIScsiComponentName, - &gIScsiComponentName2 - ); - - if (!EFI_ERROR (Status)) { - // - // Install the iSCSI Initiator Name Protocol. - // - Status =3D gBS->InstallProtocolInterface ( - &ImageHandle, - &gEfiIScsiInitiatorNameProtocolGuid, - EFI_NATIVE_INTERFACE, - &gIScsiInitiatorName - ); - if (EFI_ERROR (Status)) { - gBS->UninstallMultipleProtocolInterfaces ( - ImageHandle, - &gEfiDriverBindingProtocolGuid, - &gIScsiDriverBinding, - &gEfiComponentName2ProtocolGuid, - &gIScsiComponentName2, - &gEfiComponentNameProtocolGuid, - &gIScsiComponentName, - NULL - ); - return Status; - } - - // - // Initialize the configuration form of iSCSI. - // - Status =3D IScsiConfigFormInit (); - if (EFI_ERROR (Status)) { - gBS->UninstallMultipleProtocolInterfaces ( - ImageHandle, - &gEfiDriverBindingProtocolGuid, - &gIScsiDriverBinding, - &gEfiComponentName2ProtocolGuid, - &gIScsiComponentName2, - &gEfiComponentNameProtocolGuid, - &gIScsiComponentName, - &gEfiIScsiInitiatorNameProtocolGuid, - &gIScsiInitiatorName, - NULL - ); - } - } - return Status; -} - diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c= b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c deleted file mode 100644 index db2d6d19366e..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c +++ /dev/null @@ -1,412 +0,0 @@ -/** @file - The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -/** - Sends a SCSI Request Packet to a SCSI device that is attached to the SCS= I channel. This function - supports both blocking I/O and nonblocking I/O. The blocking I/O functio= nality is required, and the - nonblocking I/O functionality is optional. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL= instance. - @param[in] Target The Target is an array of size TARGET_MAX_BYTES = and it represents - the id of the SCSI device to send the SCSI Reque= st Packet. Each - transport driver may chose to utilize a subset o= f this size to suit the needs - of transport target representation. For example,= a Fibre Channel driver - may use only 8 bytes (WWN) to represent an FC ta= rget. - @param[in] Lun The LUN of the SCSI device to send the SCSI Requ= est Packet. - @param[in, out] Packet A pointer to the SCSI Request Packet to send to = the SCSI device - specified by Target and Lun. - @param[in] Event If nonblocking I/O is not supported then Event i= s ignored, and blocking - I/O is performed. If Event is NULL, then blockin= g I/O is performed. If - Event is not NULL and non blocking I/O is suppor= ted, then - nonblocking I/O is performed, and Event will be = signaled when the - SCSI Request Packet completes. - - @retval EFI_SUCCESS The SCSI Request Packet was sent by the ho= st. For bi-directional - commands, InTransferLength bytes were tran= sferred from - InDataBuffer. For write and bi-directional= commands, - OutTransferLength bytes were transferred b= y - OutDataBuffer. - @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. = The number of bytes that - could be transferred is returned in InTran= sferLength. For write - and bi-directional commands, OutTransferLe= ngth bytes were - transferred by OutDataBuffer. Currently no= t implemeted. - @retval EFI_NOT_READY The SCSI Request Packet could not be sent = because there are too many - SCSI Request Packets already queued. The c= aller may retry again later. - @retval EFI_DEVICE_ERROR A device error occurred while attempting t= o send the SCSI Request - Packet. - @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiReques= tPacket are invalid. - @retval EFI_UNSUPPORTED The command described by the SCSI Request = Packet is not supported - by the host adapter. This includes the cas= e of Bi-directional SCSI - commands not supported by the implementati= on. The SCSI Request - Packet was not sent, so no additional stat= us information is available. - Currently not implemeted. - @retval EFI_TIMEOUT A timeout occurred while waiting for the S= CSI Request Packet to execute. -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruFunction ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, - IN UINT8 *Target, - IN UINT64 Lun, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, - IN EFI_EVENT Event OP= TIONAL - ) -{ - ISCSI_DRIVER_DATA *Private; - ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData; - EFI_STATUS Status; - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This); - ConfigNvData =3D &Private->Session.ConfigData.NvData; - - if (Target[0] !=3D 0 || (CompareMem (&Lun, ConfigNvData->BootLun, sizeof= (UINT64)) !=3D 0)) { - return EFI_INVALID_PARAMETER; - } - - if ((Packet =3D=3D NULL) || (Packet->Cdb =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Status =3D IScsiExecuteScsiCommand (This, Target, Lun, Packet); - if ((Status !=3D EFI_SUCCESS) && (Status !=3D EFI_NOT_READY)) { - // - // Try to reinstate the session and re-execute the Scsi command. - // - if (EFI_ERROR (IScsiSessionReinstatement (Private))) { - return EFI_DEVICE_ERROR; - } - - Status =3D IScsiExecuteScsiCommand (This, Target, Lun, Packet); - } - - return Status; -} - -/** - Used to retrieve the list of legal Target IDs and LUNs for SCSI devices = on a SCSI channel. These - can either be the list SCSI devices that are actually present on the SCS= I channel, or the list of legal - Target Ids and LUNs for the SCSI channel. Regardless, the caller of this= function must probe the - Target ID and LUN returned to see if a SCSI device is actually present a= t that location on the SCSI - channel. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCO= L instance. - @param[in, out] Target On input, a pointer to the Target ID (an array = of size - TARGET_MAX_BYTES) of a SCSI device present on t= he SCSI channel. - On output, a pointer to the Target ID (an array= of - TARGET_MAX_BYTES) of the next SCSI device prese= nt on a SCSI - channel. An input value of 0xF(all bytes in the= array are 0xF) in the - Target array retrieves the Target ID of the fir= st SCSI device present on a - SCSI channel. - @param[in, out] Lun On input, a pointer to the LUN of a SCSI device= present on the SCSI - channel. On output, a pointer to the LUN of the= next SCSI device present - on a SCSI channel. - - @retval EFI_SUCCESS The Target ID and LUN of the next SCSI dev= ice on the SCSI - channel was returned in Target and Lun. - @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target an= d Lun were - not returned on a previous call to GetNext= TargetLun(). - @retval EFI_NOT_FOUND There are no more SCSI devices on this SCS= I channel. -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruGetNextTargetLun ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, - IN OUT UINT8 **Target, - IN OUT UINT64 *Lun - ) -{ - ISCSI_DRIVER_DATA *Private; - ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData; - UINT8 TargetId[TARGET_MAX_BYTES]; - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This); - ConfigNvData =3D &Private->Session.ConfigData.NvData; - - if ((*Target)[0] =3D=3D 0 && (CompareMem (Lun, ConfigNvData->BootLun, si= zeof (UINT64)) =3D=3D 0)) { - // - // Only one pair per iSCSI Driver instance. - // - return EFI_NOT_FOUND; - } - - SetMem (TargetId, TARGET_MAX_BYTES, 0xFF); - if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) =3D=3D 0) { - (*Target)[0] =3D 0; - CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)); - - return EFI_SUCCESS; - } - - return EFI_INVALID_PARAMETER; -} - -/** - Used to allocate and build a device path node for a SCSI device on a SCS= I channel. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROT= OCOL instance. - @param[in] Target The Target is an array of size TARGET_MAX_BY= TES and it specifies the - Target ID of the SCSI device for which a dev= ice path node is to be - allocated and built. Transport drivers may c= hose to utilize a subset of - this size to suit the representation of targ= ets. For example, a Fibre - Channel driver may use only 8 bytes (WWN) in= the array to represent a - FC target. - @param[in] Lun The LUN of the SCSI device for which a devic= e path node is to be - allocated and built. - @param[in, out] DevicePath A pointer to a single device path node that = describes the SCSI device - specified by Target and Lun. This function i= s responsible for - allocating the buffer DevicePath with the bo= ot service - AllocatePool(). It is the caller's responsib= ility to free - DevicePath when the caller is finished with = DevicePath. - - @retval EFI_SUCCESS The device path node that describes the SC= SI device specified by - Target and Lun was allocated and returned = in - DevicePath. - @retval EFI_INVALID_PARAMETER DevicePath is NULL. - @retval EFI_NOT_FOUND The SCSI devices specified by Target and L= un does not exist - on the SCSI channel. - @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate= DevicePath. - -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruBuildDevicePath ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, - IN UINT8 *Target, - IN UINT64 Lun, - IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath - ) -{ - ISCSI_DRIVER_DATA *Private; - ISCSI_SESSION *Session; - ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData; - ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig; - EFI_DEV_PATH *Node; - UINTN DevPathNodeLen; - - if (DevicePath =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - if (Target[0] !=3D 0) { - return EFI_NOT_FOUND; - } - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This); - Session =3D &Private->Session; - ConfigNvData =3D &Session->ConfigData.NvData; - AuthConfig =3D &Session->AuthData.AuthConfig; - - if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) !=3D 0) { - return EFI_NOT_FOUND; - } - - DevPathNodeLen =3D sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvDa= ta->TargetName) + 1; - Node =3D AllocatePool (DevPathNodeLen); - if (Node =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Node->DevPath.Type =3D MESSAGING_DEVICE_PATH; - Node->DevPath.SubType =3D MSG_ISCSI_DP; - SetDevicePathNodeLength (&Node->DevPath, (UINT16)DevPathNodeLen); - - // - // 0 for TCP, others are reserved. - // - Node->Iscsi.NetworkProtocol =3D 0; - - Node->Iscsi.LoginOption =3D 0; - switch (AuthConfig->CHAPType) { - case ISCSI_CHAP_NONE: - Node->Iscsi.LoginOption |=3D 0x0800; - break; - - case ISCSI_CHAP_UNI: - Node->Iscsi.LoginOption |=3D 0x1000; - break; - - default: - break; - } - - CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64)); - Node->Iscsi.TargetPortalGroupTag =3D Session->TargetPortalGroupTag; - AsciiStrCpyS ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), AsciiStrLen (= ConfigNvData->TargetName) + 1, ConfigNvData->TargetName); - - *DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *) Node; - - return EFI_SUCCESS; -} - -/** - Used to translate a device path node to a Target ID and LUN. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL = instance. - @param[in] DevicePath A pointer to a single device path node that descr= ibes the SCSI device - on the SCSI channel. - @param[out] Target A pointer to the Target Array which represents th= e ID of a SCSI device - on the SCSI channel. - @param[out] Lun A pointer to the LUN of a SCSI device on the SCSI= channel. - - @retval EFI_SUCCESS DevicePath was successfully translated to = a Target ID and - LUN, and they were returned in Target and = Lun. - @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL. - @retval EFI_NOT_FOUND A valid translation from DevicePath to a T= arget ID and LUN - does not exist.Currently not implemented. - @retval EFI_UNSUPPORTED This driver does not support the device pa= th node type in - DevicePath. -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruGetTargetLun ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, - OUT UINT8 **Target, - OUT UINT64 *Lun - ) -{ - ISCSI_DRIVER_DATA *Private; - ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData; - - if ((DevicePath =3D=3D NULL) || (Target =3D=3D NULL) || (Lun =3D=3D NULL= )) { - return EFI_INVALID_PARAMETER; - } - - if ((DevicePath->Type !=3D MESSAGING_DEVICE_PATH) || - (DevicePath->SubType !=3D MSG_ISCSI_DP) || - (DevicePathNodeLength (DevicePath) <=3D sizeof (ISCSI_DEVICE_PATH)) - ) { - return EFI_UNSUPPORTED; - } - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This); - ConfigNvData =3D &Private->Session.ConfigData.NvData; - - SetMem (*Target, TARGET_MAX_BYTES, 0xFF); - (*Target)[0] =3D 0; - - if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *) DevicePath + sizeof= (ISCSI_DEVICE_PATH)) !=3D 0) { - return EFI_UNSUPPORTED; - } - - CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)); - - return EFI_SUCCESS; -} - -/** - Resets a SCSI channel. This operation resets all the SCSI devices connec= ted to the SCSI channel. - Currently not implemented. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instan= ce. - - @retval EFI_SUCCESS The SCSI channel was reset. - @retval EFI_DEVICE_ERROR A device error occurred while attempting to res= et the SCSI channel. - @retval EFI_TIMEOUT A timeout occurred while attempting to reset th= e SCSI channel. - @retval EFI_UNSUPPORTED The SCSI channel does not support a channel res= et operation. -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruResetChannel ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This - ) -{ - return EFI_UNSUPPORTED; -} - -/** - Resets a SCSI logical unit that is connected to a SCSI channel. Currentl= y not implemented. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL inst= ance. - @param[in] Target The Target is an array of size TARGET_MAX_BYTE and it= represents the - target port ID of the SCSI device containing the SCSI= logical unit to - reset. Transport drivers may chose to utilize a subse= t of this array to suit - the representation of their targets. - @param[in] Lun The LUN of the SCSI device to reset. - - @retval EFI_SUCCESS The SCSI device specified by Target and Lu= n was reset. - @retval EFI_INVALID_PARAMETER Target or Lun is NULL. - @retval EFI_TIMEOUT A timeout occurred while attempting to res= et the SCSI device - specified by Target and Lun. - @retval EFI_UNSUPPORTED The SCSI channel does not support a target= reset operation. - @retval EFI_DEVICE_ERROR A device error occurred while attempting t= o reset the SCSI device - specified by Target and Lun. - -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruResetTargetLun ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, - IN UINT8 *Target, - IN UINT64 Lun - ) -{ - return EFI_UNSUPPORTED; -} - -/** - Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI= channel. These can either - be the list SCSI devices that are actually present on the SCSI channel, = or the list of legal Target IDs - for the SCSI channel. Regardless, the caller of this function must probe= the Target ID returned to - see if a SCSI device is actually present at that location on the SCSI ch= annel. - - @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCO= L instance. - @param[in, out] Target (TARGET_MAX_BYTES) of a SCSI device present on = the SCSI channel. - On output, a pointer to the Target ID (an array= of - TARGET_MAX_BYTES) of the next SCSI device prese= nt on a SCSI - channel. An input value of 0xF(all bytes in the= array are 0xF) in the - Target array retrieves the Target ID of the fir= st SCSI device present on a - SCSI channel. - - @retval EFI_SUCCESS The Target ID of the next SCSI device on t= he SCSI - channel was returned in Target. - @retval EFI_INVALID_PARAMETER Target or Lun is NULL. - @retval EFI_TIMEOUT Target array is not all 0xF, and Target we= re not - returned on a previous call to GetNextTarg= et(). - Currently not implemented. - @retval EFI_NOT_FOUND There are no more SCSI devices on this SCS= I channel. -**/ -EFI_STATUS -EFIAPI -IScsiExtScsiPassThruGetNextTarget ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, - IN OUT UINT8 **Target - ) -{ - UINT8 TargetId[TARGET_MAX_BYTES]; - - SetMem (TargetId, TARGET_MAX_BYTES, 0xFF); - - if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) =3D=3D 0) { - (*Target)[0] =3D 0; - return EFI_SUCCESS; - } else if ((*Target)[0] =3D=3D 0) { - return EFI_NOT_FOUND; - } else { - return EFI_INVALID_PARAMETER; - } -} - -EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate =3D = { - NULL, - IScsiExtScsiPassThruFunction, - IScsiExtScsiPassThruGetNextTargetLun, - IScsiExtScsiPassThruBuildDevicePath, - IScsiExtScsiPassThruGetTargetLun, - IScsiExtScsiPassThruResetChannel, - IScsiExtScsiPassThruResetTargetLun, - IScsiExtScsiPassThruGetNextTarget -}; diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiIbft.c deleted file mode 100644 index 58c5447dcbd1..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c +++ /dev/null @@ -1,539 +0,0 @@ -/** @file - Implementation for iSCSI Boot Firmware Table publication. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -BOOLEAN mIbftInstalled =3D FALSE; -UINTN mTableKey; - -/** - Initialize the header of the iSCSI Boot Firmware Table. - - @param[out] Header The header of the iSCSI Boot Firmware Table. - @param[in] OemId The OEM ID. - @param[in] OemTableId The OEM table ID for the iBFT. -**/ -VOID -IScsiInitIbfTableHeader ( - OUT EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Header, - IN UINT8 *OemId, - IN UINT64 *OemTableId - ) -{ - ZeroMem (Header, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER)); - - Header->Signature =3D EFI_ACPI_3_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE; - Header->Length =3D IBFT_HEAP_OFFSET; - Header->Revision =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_REVISION; - Header->Checksum =3D 0; - - CopyMem (Header->OemId, OemId, sizeof (Header->OemId)); - CopyMem (&Header->OemTableId, OemTableId, sizeof (UINT64)); -} - -/** - Initialize the control section of the iSCSI Boot Firmware Table. - - @param[in] Table The ACPI table. - @param[in] HandleCount The number of the handles associated with iSCSI = sessions, it's - equal to the number of iSCSI sessions. -**/ -VOID -IScsiInitControlSection ( - IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table, - IN UINTN HandleCount - ) -{ - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control; - UINTN NumOffset; - - Control =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *) (Ta= ble + 1); - - ZeroMem (Control, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STR= UCTURE)); - - Control->Header.StructureId =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTR= OL_STRUCTURE_ID; - Control->Header.Version =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTR= OL_STRUCTURE_VERSION; - Control->Header.Length =3D (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIR= MWARE_TABLE_CONTROL_STRUCTURE); - - // - // Each session occupies two offsets, one for the NIC section, - // the other for the Target section. - // - NumOffset =3D 2 * HandleCount; - if (NumOffset > 4) { - // - // Need expand the control section if more than 2 NIC/Target sections - // exist. - // - Control->Header.Length =3D (UINT16) (Control->Header.Length + (NumOffs= et - 4) * sizeof (UINT16)); - } -} - -/** - Add one item into the heap. - - @param[in, out] Heap On input, the current address of the heap; On out= put, the address of - the heap after the item is added. - @param[in] Data The data to add into the heap. - @param[in] Len Length of the Data in byte. -**/ -VOID -IScsiAddHeapItem ( - IN OUT UINT8 **Heap, - IN VOID *Data, - IN UINTN Len - ) -{ - // - // Add one byte for the NULL delimiter. - // - *Heap -=3D Len + 1; - - CopyMem (*Heap, Data, Len); - *(*Heap + Len) =3D 0; -} - -/** - Fill the Initiator section of the iSCSI Boot Firmware Table. - - @param[in] Table The ACPI table. - @param[in, out] Heap The heap. - @param[in] Handle The handle associated with the iSCSI session. -**/ -VOID -IScsiFillInitiatorSection ( - IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table, - IN OUT UINT8 **Heap, - IN EFI_HANDLE Handle - ) -{ - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control; - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE *Initiator; - ISCSI_DRIVER_DATA *DriverData; - ISCSI_SESSION *Session; - ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier= ; - EFI_STATUS Status; - - Control =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *) (Ta= ble + 1); - - // - // Initiator section immediately follows the control section. - // - Initiator =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE *)= ((UINT8 *) Control + IBFT_ROUNDUP (Control->Header.Length)); - - Control->InitiatorOffset =3D (UINT16) ((UINTN) Initiator - (UINTN) Table= ); - - ZeroMem (Initiator, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR= _STRUCTURE)); - - Initiator->Header.StructureId =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INI= TIATOR_STRUCTURE_ID; - Initiator->Header.Version =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INI= TIATOR_STRUCTURE_VERSION; - Initiator->Header.Length =3D (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_F= IRMWARE_TABLE_INITIATOR_STRUCTURE); - Initiator->Header.Flags =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INI= TIATOR_STRUCTURE_FLAG_BLOCK_VALID | EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INIT= IATOR_STRUCTURE_FLAG_BOOT_SELECTED; - - // - // Get the identifier from the handle. - // - Status =3D gBS->HandleProtocol (Handle, &gEfiCallerIdGuid, (VOID **) &IS= csiIdentifier); - if (EFI_ERROR (Status)) { - ASSERT (FALSE); - return ; - } - - DriverData =3D ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier); - Session =3D &DriverData->Session; - - // - // Fill the iSCSI Initiator Name into the heap. - // - IScsiAddHeapItem (Heap, Session->InitiatorName, Session->InitiatorNameLe= ngth - 1); - - Initiator->IScsiNameLength =3D (UINT16) (Session->InitiatorNameLength -= 1); - Initiator->IScsiNameOffset =3D (UINT16) ((UINTN) *Heap - (UINTN) Table)= ; -} - -/** - Map the v4 IP address into v6 IP address. - - @param[in] V4 The v4 IP address. - @param[out] V6 The v6 IP address. -**/ -VOID -IScsiMapV4ToV6Addr ( - IN EFI_IPv4_ADDRESS *V4, - OUT EFI_IPv6_ADDRESS *V6 - ) -{ - UINTN Index; - - ZeroMem (V6, sizeof (EFI_IPv6_ADDRESS)); - - V6->Addr[10] =3D 0xff; - V6->Addr[11] =3D 0xff; - - for (Index =3D 0; Index < 4; Index++) { - V6->Addr[12 + Index] =3D V4->Addr[Index]; - } -} - -/** - Get the NIC's PCI location and return it according to the composited - format defined in iSCSI Boot Firmware Table. - - @param[in] Controller The handle of the controller. - - @return UINT16 The composited representation of the NIC PCI loc= ation. - @retval 0 Other errors as indicated. -**/ -UINT16 -IScsiGetNICPciLocation ( - IN EFI_HANDLE Controller - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_HANDLE PciIoHandle; - EFI_PCI_IO_PROTOCOL *PciIo; - UINTN Segment; - UINTN Bus; - UINTN Device; - UINTN Function; - - Status =3D gBS->HandleProtocol ( - Controller, - &gEfiDevicePathProtocolGuid, - (VOID **)&DevicePath - ); - if (EFI_ERROR (Status)) { - return 0; - } - - Status =3D gBS->LocateDevicePath ( - &gEfiPciIoProtocolGuid, - &DevicePath, - &PciIoHandle - ); - if (EFI_ERROR (Status)) { - return 0; - } - - Status =3D gBS->HandleProtocol (PciIoHandle, &gEfiPciIoProtocolGuid, (VO= ID **)&PciIo); - if (EFI_ERROR (Status)) { - return 0; - } - - Status =3D PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function= ); - if (EFI_ERROR (Status)) { - return 0; - } - - return (UINT16) ((Bus << 8) | (Device << 3) | Function); -} - -/** - Fill the NIC and target sections in iSCSI Boot Firmware Table. - - @param[in] Table The buffer of the ACPI table. - @param[in, out] Heap The heap buffer used to store the variable = length parameters such as iSCSI name. - @param[in] HandleCount Count The number of handles having iSCSI pr= ivate protocol installed. - @param[in] Handles The handle buffer. -**/ -VOID -IScsiFillNICAndTargetSections ( - IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table, - IN OUT UINT8 **Heap, - IN UINTN HandleCount, - IN EFI_HANDLE *Handles - ) -{ - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control; - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *Nic; - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE *Target; - ISCSI_DRIVER_DATA *DriverData; - ISCSI_SESSION_CONFIG_DATA *SessionConfigData= ; - ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig; - UINT16 *SectionOffset; - UINTN Index; - UINT16 Length; - EFI_MAC_ADDRESS MacAddress; - UINTN HwAddressSize; - ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier; - EFI_STATUS Status; - - // - // Get the offset of the first Nic and Target section. - // - Control =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *) (Ta= ble + 1); - Nic =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *) ((UINTN= ) Table + - Control->InitiatorOffset + IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_= BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE))); - Target =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE *) ((UI= NTN) Nic + - IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STR= UCTURE))); - - SectionOffset =3D &Control->NIC0Offset; - - for (Index =3D 0; Index < HandleCount; Index++) { - Status =3D gBS->HandleProtocol (Handles[Index], &gEfiCallerIdGuid, (VO= ID **)&IScsiIdentifier); - if (EFI_ERROR (Status)) { - ASSERT (FALSE); - return ; - } - - DriverData =3D ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifi= er); - SessionConfigData =3D &DriverData->Session.ConfigData; - AuthConfig =3D &DriverData->Session.AuthData.AuthConfig; - - // - // Fill the Nic section. - // - ZeroMem (Nic, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE= )); - - Nic->Header.StructureId =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STR= UCTURE_ID; - Nic->Header.Version =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STR= UCTURE_VERSION; - Nic->Header.Length =3D (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMW= ARE_TABLE_NIC_STRUCTURE); - Nic->Header.Index =3D (UINT8) Index; - Nic->Header.Flags =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STR= UCTURE_FLAG_BLOCK_VALID | - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTU= RE_FLAG_BOOT_SELECTED | - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTU= RE_FLAG_GLOBAL; - - // - // Get the subnet mask prefix length. - // - Nic->SubnetMaskPrefixLength =3D IScsiGetSubnetMaskPrefixLength (&Sessi= onConfigData->NvData.SubnetMask); - - if (SessionConfigData->NvData.InitiatorInfoFromDhcp) { - Nic->Origin =3D IpPrefixOriginDhcp; - } else { - Nic->Origin =3D IpPrefixOriginManual; - } - // - // Map the various v4 addresses into v6 addresses. - // - IScsiMapV4ToV6Addr (&SessionConfigData->NvData.LocalIp, &Nic->Ip); - IScsiMapV4ToV6Addr (&SessionConfigData->NvData.Gateway, &Nic->Gateway)= ; - IScsiMapV4ToV6Addr (&SessionConfigData->PrimaryDns, &Nic->PrimaryDns); - IScsiMapV4ToV6Addr (&SessionConfigData->SecondaryDns, &Nic->SecondaryD= ns); - IScsiMapV4ToV6Addr (&SessionConfigData->DhcpServer, &Nic->DhcpServer); - - Nic->VLanTag =3D NetLibGetVlanId (DriverData->Controller); - - Status =3D NetLibGetMacAddress (DriverData->Controller, &MacAddress, &= HwAddressSize); - ASSERT (Status =3D=3D EFI_SUCCESS); - CopyMem (Nic->Mac, MacAddress.Addr, sizeof (Nic->Mac)); - - // - // Get the PCI location of the Nic. - // - Nic->PciLocation =3D IScsiGetNICPciLocation (DriverData->Controller); - - *SectionOffset =3D (UINT16) ((UINTN) Nic - (UINTN) Table); - SectionOffset++; - - // - // Fill the Target section. - // - ZeroMem (Target, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STR= UCTURE)); - - Target->Header.StructureId =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TAR= GET_STRUCTURE_ID; - Target->Header.Version =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TAR= GET_STRUCTURE_VERSION; - Target->Header.Length =3D (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_F= IRMWARE_TABLE_TARGET_STRUCTURE); - Target->Header.Index =3D (UINT8) Index; - Target->Header.Flags =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TAR= GET_STRUCTURE_FLAG_BLOCK_VALID | EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_= STRUCTURE_FLAG_BOOT_SELECTED; - Target->Port =3D SessionConfigData->NvData.TargetPort; - Target->NicIndex =3D (UINT8) Index; - - if (AuthConfig->CHAPType =3D=3D ISCSI_CHAP_NONE) { - Target->CHAPType =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUC= TURE_CHAP_TYPE_NO_CHAP; - } if (AuthConfig->CHAPType =3D=3D ISCSI_CHAP_UNI) { - Target->CHAPType =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUC= TURE_CHAP_TYPE_CHAP; - } else if (AuthConfig->CHAPType =3D=3D ISCSI_CHAP_MUTUAL) { - Target->CHAPType =3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUC= TURE_CHAP_TYPE_MUTUAL_CHAP; - } - - IScsiMapV4ToV6Addr (&SessionConfigData->NvData.TargetIp, &Target->Ip); - CopyMem (Target->BootLun, SessionConfigData->NvData.BootLun, sizeof (T= arget->BootLun)); - - // - // Target iSCSI Name, CHAP name/secret, reverse CHAP name/secret. - // - Length =3D (UINT16) AsciiStrLen (SessionConfigData->NvData.TargetName)= ; - IScsiAddHeapItem (Heap, SessionConfigData->NvData.TargetName, Length); - - Target->IScsiNameLength =3D Length; - Target->IScsiNameOffset =3D (UINT16) ((UINTN) *Heap - (UINTN) Table); - - if (Target->CHAPType !=3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_ST= RUCTURE_CHAP_TYPE_NO_CHAP) { - // - // CHAP Name - // - Length =3D (UINT16) AsciiStrLen (AuthConfig->CHAPName); - IScsiAddHeapItem (Heap, AuthConfig->CHAPName, Length); - Target->CHAPNameLength =3D Length; - Target->CHAPNameOffset =3D (UINT16) ((UINTN) *Heap - (UINTN) Table)= ; - - // - // CHAP Secret - // - Length =3D (UINT16) AsciiStrLen (AuthConfig->CHAPSecret); - IScsiAddHeapItem (Heap, AuthConfig->CHAPSecret, Length); - Target->CHAPSecretLength =3D Length; - Target->CHAPSecretOffset =3D (UINT16) ((UINTN) *Heap - (UINTN) Tabl= e); - - if (Target->CHAPType =3D=3D EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGE= T_STRUCTURE_CHAP_TYPE_MUTUAL_CHAP) { - // - // Reverse CHAP Name - // - Length =3D (UINT16) AsciiStrLen (AuthConfig->ReverseCHAPName); - IScsiAddHeapItem (Heap, AuthConfig->ReverseCHAPName, Length); - Target->ReverseCHAPNameLength =3D Length; - Target->ReverseCHAPNameOffset =3D (UINT16) ((UINTN) *Heap - (UINTN= ) Table); - - // - // Reverse CHAP Secret - // - Length =3D (UINT16) AsciiStrLen (AuthConfig->ReverseCHAPSecret); - IScsiAddHeapItem (Heap, AuthConfig->ReverseCHAPSecret, Length); - Target->ReverseCHAPSecretLength =3D Length; - Target->ReverseCHAPSecretOffset =3D (UINT16) ((UINTN) *Heap - (UIN= TN) Table); - } - } - - *SectionOffset =3D (UINT16) ((UINTN) Target - (UINTN) Table); - SectionOffset++; - - // - // Advance to the next NIC/Target pair - // - Nic =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *) ((UINT= N) Target + - IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET= _STRUCTURE))); - Target =3D (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE *) ((U= INTN) Nic + - IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_ST= RUCTURE))); - } -} - -/** - Publish and remove the iSCSI Boot Firmware Table according to the iSCSI - session status. -**/ -VOID -IScsiPublishIbft ( - VOID - ) -{ - EFI_STATUS Status; - EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol; - EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINT8 *Heap; - UINT8 Checksum; - EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; - EFI_ACPI_DESCRIPTION_HEADER *Rsdt; - EFI_ACPI_DESCRIPTION_HEADER *Xsdt; - - Rsdt =3D NULL; - Xsdt =3D NULL; - - Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID = **)&AcpiTableProtocol); - if (EFI_ERROR (Status)) { - return ; - } - - - // - // Find ACPI table RSD_PTR from system table - // - Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)= &Rsdp); - if (EFI_ERROR (Status)) { - Status =3D EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID= **) &Rsdp); - } - - if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) { - return ; - } else if (Rsdp->Revision >=3D EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POIN= TER_REVISION && Rsdp->XsdtAddress !=3D 0) { - Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress; - } else if (Rsdp->RsdtAddress !=3D 0) { - Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress; - } - - if ((Xsdt =3D=3D NULL) && (Rsdt =3D=3D NULL)) { - return ; - } - - if (mIbftInstalled) { - Status =3D AcpiTableProtocol->UninstallAcpiTable ( - AcpiTableProtocol, - mTableKey - ); - if (EFI_ERROR (Status)) { - return ; - } - mIbftInstalled =3D FALSE; - } - - // - // Get all iSCSI private protocols. - // - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiCallerIdGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return ; - } - // - // Allocate 4k bytes to hold the ACPI table. - // - Table =3D AllocateZeroPool (IBFT_MAX_SIZE); - if (Table =3D=3D NULL) { - return ; - } - - Heap =3D (UINT8 *) Table + IBFT_HEAP_OFFSET; - - // - // Fill in the various section of the iSCSI Boot Firmware Table. - // - if (Rsdp->Revision >=3D EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REV= ISION) { - IScsiInitIbfTableHeader (Table, Xsdt->OemId, &Xsdt->OemTableId); - } else { - IScsiInitIbfTableHeader (Table, Rsdt->OemId, &Rsdt->OemTableId); - } - - IScsiInitControlSection (Table, HandleCount); - IScsiFillInitiatorSection (Table, &Heap, HandleBuffer[0]); - IScsiFillNICAndTargetSections (Table, &Heap, HandleCount, HandleBuffer); - - Checksum =3D CalculateCheckSum8((UINT8 *)Table, Table->Length); - Table->Checksum =3D Checksum; - - FreePool (HandleBuffer); - - // - // Install or update the iBFT table. - // - Status =3D AcpiTableProtocol->InstallAcpiTable ( - AcpiTableProtocol, - Table, - Table->Length, - &mTableKey - ); - if (EFI_ERROR(Status)) { - return; - } - - mIbftInstalled =3D TRUE; - FreePool (Table); -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.c b= /MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.c deleted file mode 100644 index e753d9eebdbe..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.c +++ /dev/null @@ -1,116 +0,0 @@ -/** @file - Implementation for EFI iSCSI Initiator Name Protocol. - -Copyright (c) 2004 - 2011, 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -EFI_ISCSI_INITIATOR_NAME_PROTOCOL gIScsiInitiatorName =3D { - IScsiGetInitiatorName, - IScsiSetInitiatorName -}; - -/** - Retrieves the current set value of iSCSI Initiator Name. - - @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROT= OCOL instance. - @param[in, out] BufferSize Size of the buffer in bytes pointed to by Bu= ffer / Actual size of the - variable data buffer. - @param[out] Buffer Pointer to the buffer for data to be read. T= he data is a null-terminated UTF-8 encoded string. - The maximum length is 223 characters, includ= ing the null-terminator. - - @retval EFI_SUCCESS Data was successfully retrieved into the p= rovided buffer and the - BufferSize was sufficient to handle the iS= CSI initiator name. - @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result. - @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL. - @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retr= ieved due to a hardware error. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiGetInitiatorName ( - IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - EFI_STATUS Status; - - if ((BufferSize =3D=3D NULL) || (Buffer =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Status =3D gRT->GetVariable ( - ISCSI_INITIATOR_NAME_VAR_NAME, - &gEfiIScsiInitiatorNameProtocolGuid, - NULL, - BufferSize, - Buffer - ); - - return Status; -} - -/** - Sets the iSCSI Initiator Name. - - @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROT= OCOL instance. - @param[in, out] BufferSize Size of the buffer in bytes pointed to by Bu= ffer. - @param[in] Buffer Pointer to the buffer for data to be written= . The data is a null-terminated UTF-8 encoded string. - The maximum length is 223 characters, includ= ing the null-terminator. - - @retval EFI_SUCCESS Data was successfully stored by the protoc= ol. - @retval EFI_UNSUPPORTED Platform policies do not allow for data to= be written. - Currently not implemented. - @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL, or BufferSiz= e exceeds the maximum allowed limit. - @retval EFI_DEVICE_ERROR The data could not be stored due to a hard= ware error. - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold th= e data. - @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere= to RFC 3720 - (and other related protocols). - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiSetInitiatorName ( - IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - - if ((BufferSize =3D=3D NULL) || (Buffer =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - if (*BufferSize > ISCSI_NAME_MAX_SIZE) { - *BufferSize =3D ISCSI_NAME_MAX_SIZE; - return EFI_INVALID_PARAMETER; - } - // - // only support iqn iSCSI names. - // - Status =3D IScsiNormalizeName ((CHAR8 *) Buffer, *BufferSize - 1); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gRT->SetVariable ( - ISCSI_INITIATOR_NAME_VAR_NAME, - &gEfiIScsiInitiatorNameProtocolGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACC= ESS, - *BufferSize, - Buffer - ); - - return Status; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiMisc.c deleted file mode 100644 index d924a8b82427..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c +++ /dev/null @@ -1,948 +0,0 @@ -/** @file - Miscellaneous routines for iSCSI driver. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 IScsiHexString[] =3D "012345678= 9ABCDEFabcdef"; - -/** - Removes (trims) specified leading and trailing characters from a string. - - @param[in, out] Str Pointer to the null-terminated string to be trimme= d. On return, - Str will hold the trimmed string. - - @param[in] CharC Character will be trimmed from str. -**/ -VOID -StrTrim ( - IN OUT CHAR16 *Str, - IN CHAR16 CharC - ) -{ - CHAR16 *Pointer1; - CHAR16 *Pointer2; - - if (*Str =3D=3D 0) { - return; - } - - // - // Trim off the leading and trailing characters c - // - for (Pointer1 =3D Str; (*Pointer1 !=3D 0) && (*Pointer1 =3D=3D CharC); P= ointer1++) { - ; - } - - Pointer2 =3D Str; - if (Pointer2 =3D=3D Pointer1) { - while (*Pointer1 !=3D 0) { - Pointer2++; - Pointer1++; - } - } else { - while (*Pointer1 !=3D 0) { - *Pointer2 =3D *Pointer1; - Pointer1++; - Pointer2++; - } - *Pointer2 =3D 0; - } - - - for (Pointer1 =3D Str + StrLen(Str) - 1; Pointer1 >=3D Str && *Pointer1 = =3D=3D CharC; Pointer1--) { - ; - } - if (Pointer1 !=3D Str + StrLen(Str) - 1) { - *(Pointer1 + 1) =3D 0; - } -} - -/** - Calculate the prefix length of the IPv4 subnet mask. - - @param[in] SubnetMask The IPv4 subnet mask. - - @return The prefix length of the subnet mask. - @retval 0 Other errors as indicated. -**/ -UINT8 -IScsiGetSubnetMaskPrefixLength ( - IN EFI_IPv4_ADDRESS *SubnetMask - ) -{ - UINT8 Len; - UINT32 ReverseMask; - - // - // The SubnetMask is in network byte order. - // - ReverseMask =3D (SubnetMask->Addr[0] << 24) | (SubnetMask->Addr[1] << 16= ) | (SubnetMask->Addr[2] << 8) | (SubnetMask->Addr[3]); - - // - // Reverse it. - // - ReverseMask =3D ~ReverseMask; - - if ((ReverseMask & (ReverseMask + 1)) !=3D 0) { - return 0; - } - - Len =3D 0; - - while (ReverseMask !=3D 0) { - ReverseMask =3D ReverseMask >> 1; - Len++; - } - - return (UINT8) (32 - Len); -} - -/** - Convert the hexadecimal encoded LUN string into the 64-bit LUN. - - @param[in] Str The hexadecimal encoded LUN string. - @param[out] Lun Storage to return the 64-bit LUN. - - @retval EFI_SUCCESS The 64-bit LUN is stored in Lun. - @retval EFI_INVALID_PARAMETER The string is malformatted. -**/ -EFI_STATUS -IScsiAsciiStrToLun ( - IN CHAR8 *Str, - OUT UINT8 *Lun - ) -{ - UINTN Index, IndexValue, IndexNum, SizeStr; - CHAR8 TemStr[2]; - UINT8 TemValue; - UINT16 Value[4]; - - ZeroMem (Lun, 8); - ZeroMem (TemStr, 2); - ZeroMem ((UINT8 *) Value, sizeof (Value)); - SizeStr =3D AsciiStrLen (Str); - IndexValue =3D 0; - IndexNum =3D 0; - - for (Index =3D 0; Index < SizeStr; Index ++) { - TemStr[0] =3D Str[Index]; - TemValue =3D (UINT8) AsciiStrHexToUint64 (TemStr); - if (TemValue =3D=3D 0 && TemStr[0] !=3D '0') { - if ((TemStr[0] !=3D '-') || (IndexNum =3D=3D 0)) { - // - // Invalid Lun Char - // - return EFI_INVALID_PARAMETER; - } - } - - if ((TemValue =3D=3D 0) && (TemStr[0] =3D=3D '-')) { - // - // Next Lun value - // - if (++IndexValue >=3D 4) { - // - // Max 4 Lun value - // - return EFI_INVALID_PARAMETER; - } - // - // Restart str index for the next lun value - // - IndexNum =3D 0; - continue; - } - - if (++IndexNum > 4) { - // - // Each Lun Str can't exceed size 4, because it will be as UINT16 va= lue - // - return EFI_INVALID_PARAMETER; - } - - // - // Combine UINT16 value - // - Value[IndexValue] =3D (UINT16) ((Value[IndexValue] << 4) + TemValue); - } - - for (Index =3D 0; Index <=3D IndexValue; Index ++) { - *((UINT16 *) &Lun[Index * 2]) =3D HTONS (Value[Index]); - } - - return EFI_SUCCESS; -} - -/** - Convert the 64-bit LUN into the hexadecimal encoded LUN string. - - @param[in] Lun The 64-bit LUN. - @param[out] Str The storage to return the hexadecimal encoded LUN strin= g. -**/ -VOID -IScsiLunToUnicodeStr ( - IN UINT8 *Lun, - OUT CHAR16 *Str - ) -{ - UINTN Index; - CHAR16 *TempStr; - - TempStr =3D Str; - - for (Index =3D 0; Index < 4; Index++) { - - if ((Lun[2 * Index] | Lun[2 * Index + 1]) =3D=3D 0) { - CopyMem(TempStr, L"0-", sizeof (L"0-")); - } else { - TempStr[0] =3D (CHAR16) IScsiHexString[Lun[2 * Index] >> 4]; - TempStr[1] =3D (CHAR16) IScsiHexString[Lun[2 * Index] & 0x0F]; - TempStr[2] =3D (CHAR16) IScsiHexString[Lun[2 * Index + 1] >> 4]; - TempStr[3] =3D (CHAR16) IScsiHexString[Lun[2 * Index + 1] & 0x0F]; - TempStr[4] =3D L'-'; - TempStr[5] =3D 0; - - StrTrim (TempStr, L'0'); - } - - TempStr +=3D StrLen (TempStr); - } - - ASSERT (StrLen(Str) >=3D 1); - Str[StrLen (Str) - 1] =3D 0; - - for (Index =3D StrLen (Str) - 1; Index > 1; Index =3D Index - 2) { - if ((Str[Index] =3D=3D L'0') && (Str[Index - 1] =3D=3D L'-')) { - Str[Index - 1] =3D 0; - } else { - break; - } - } -} - -/** - Convert the ASCII string into a UNICODE string. - - @param[in] Source The ASCII string. - @param[out] Destination The storage to return the UNICODE string. - - @return CHAR16 * Pointer to the UNICODE string. -**/ -CHAR16 * -IScsiAsciiStrToUnicodeStr ( - IN CHAR8 *Source, - OUT CHAR16 *Destination - ) -{ - ASSERT (Destination !=3D NULL); - ASSERT (Source !=3D NULL); - - while (*Source !=3D '\0') { - *(Destination++) =3D (CHAR16) *(Source++); - } - - *Destination =3D '\0'; - - return Destination; -} - -/** - Convert the UNICODE string into an ASCII string. - - @param[in] Source The UNICODE string. - @param[out] Destination The storage to return the ASCII string. - - @return CHAR8 * Pointer to the ASCII string. -**/ -CHAR8 * -IScsiUnicodeStrToAsciiStr ( - IN CHAR16 *Source, - OUT CHAR8 *Destination - ) -{ - ASSERT (Destination !=3D NULL); - ASSERT (Source !=3D NULL); - - while (*Source !=3D '\0') { - // - // If any Unicode characters in Source contain - // non-zero value in the upper 8 bits, then ASSERT(). - // - ASSERT (*Source < 0x100); - *(Destination++) =3D (CHAR8) *(Source++); - } - - *Destination =3D '\0'; - - return Destination; -} - -/** - Convert the decimal dotted IPv4 address into the binary IPv4 address. - - @param[in] Str The UNICODE string. - @param[out] Ip The storage to return the ASCII string. - - @retval EFI_SUCCESS The binary IP address is returned in Ip. - @retval EFI_INVALID_PARAMETER The IP string is malformatted. -**/ -EFI_STATUS -IScsiAsciiStrToIp ( - IN CHAR8 *Str, - OUT EFI_IPv4_ADDRESS *Ip - ) -{ - UINTN Index; - UINTN Number; - - Index =3D 0; - - while (*Str !=3D 0) { - - if (Index > 3) { - return EFI_INVALID_PARAMETER; - } - - Number =3D 0; - while (NET_IS_DIGIT (*Str)) { - Number =3D Number * 10 + (*Str - '0'); - Str++; - } - - if (Number > 0xFF) { - return EFI_INVALID_PARAMETER; - } - - Ip->Addr[Index] =3D (UINT8) Number; - - if ((*Str !=3D '\0') && (*Str !=3D '.')) { - // - // The current character should be either the NULL terminator or - // the dot delimiter. - // - return EFI_INVALID_PARAMETER; - } - - if (*Str =3D=3D '.') { - // - // Skip the delimiter. - // - Str++; - } - - Index++; - } - - if (Index !=3D 4) { - return EFI_INVALID_PARAMETER; - } - - return EFI_SUCCESS; -} - -/** - Convert the mac address into a hexadecimal encoded "-" seperated string. - - @param[in] Mac The mac address. - @param[in] Len Length in bytes of the mac address. - @param[in] VlanId VLAN ID of the network device. - @param[out] Str The storage to return the mac string. -**/ -VOID -IScsiMacAddrToStr ( - IN EFI_MAC_ADDRESS *Mac, - IN UINT32 Len, - IN UINT16 VlanId, - OUT CHAR16 *Str - ) -{ - UINT32 Index; - CHAR16 *String; - - for (Index =3D 0; Index < Len; Index++) { - Str[3 * Index] =3D (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4= ) & 0x0F]; - Str[3 * Index + 1] =3D (CHAR16) IScsiHexString[Mac->Addr[Index] & 0x0= F]; - Str[3 * Index + 2] =3D L'-'; - } - - String =3D &Str[3 * Index - 1] ; - if (VlanId !=3D 0) { - String +=3D UnicodeSPrint (String, 6 * sizeof (CHAR16), L"\\%04x", (UI= NTN) VlanId); - } - - *String =3D L'\0'; -} - -/** - Convert the binary encoded buffer into a hexadecimal encoded string. - - @param[in] BinBuffer The buffer containing the binary data. - @param[in] BinLength Length of the binary buffer. - @param[in, out] HexStr Pointer to the string. - @param[in, out] HexLength The length of the string. - - @retval EFI_SUCCESS The binary data is converted to the hexadec= imal string - and the length of the string is updated. - @retval EFI_BUFFER_TOO_SMALL The string is too small. - @retval EFI_INVALID_PARAMETER The IP string is malformatted. -**/ -EFI_STATUS -IScsiBinToHex ( - IN UINT8 *BinBuffer, - IN UINT32 BinLength, - IN OUT CHAR8 *HexStr, - IN OUT UINT32 *HexLength - ) -{ - UINTN Index; - - if ((HexStr =3D=3D NULL) || (BinBuffer =3D=3D NULL) || (BinLength =3D=3D= 0)) { - return EFI_INVALID_PARAMETER; - } - - if (((*HexLength) - 3) < BinLength * 2) { - *HexLength =3D BinLength * 2 + 3; - return EFI_BUFFER_TOO_SMALL; - } - - *HexLength =3D BinLength * 2 + 3; - // - // Prefix for Hex String - // - HexStr[0] =3D '0'; - HexStr[1] =3D 'x'; - - for (Index =3D 0; Index < BinLength; Index++) { - HexStr[Index * 2 + 2] =3D IScsiHexString[BinBuffer[Index] >> 4]; - HexStr[Index * 2 + 3] =3D IScsiHexString[BinBuffer[Index] & 0x0F]; - } - - HexStr[Index * 2 + 2] =3D '\0'; - - return EFI_SUCCESS; -} - -/** - Convert the hexadecimal string into a binary encoded buffer. - - @param[in, out] BinBuffer The binary buffer. - @param[in, out] BinLength Length of the binary buffer. - @param[in] HexStr The hexadecimal string. - - @retval EFI_SUCCESS The hexadecimal string is converted into a = binary - encoded buffer. - @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the = converted data. -**/ -EFI_STATUS -IScsiHexToBin ( - IN OUT UINT8 *BinBuffer, - IN OUT UINT32 *BinLength, - IN CHAR8 *HexStr - ) -{ - UINTN Index; - UINTN Length; - UINT8 Digit; - CHAR8 TemStr[2]; - - ZeroMem (TemStr, sizeof (TemStr)); - - // - // Find out how many hex characters the string has. - // - if ((HexStr[0] =3D=3D '0') && ((HexStr[1] =3D=3D 'x') || (HexStr[1] =3D= =3D 'X'))) { - HexStr +=3D 2; - } - - Length =3D AsciiStrLen (HexStr); - - for (Index =3D 0; Index < Length; Index ++) { - TemStr[0] =3D HexStr[Index]; - Digit =3D (UINT8) AsciiStrHexToUint64 (TemStr); - if (Digit =3D=3D 0 && TemStr[0] !=3D '0') { - // - // Invalid Lun Char - // - break; - } - if ((Index & 1) =3D=3D 0) { - BinBuffer [Index/2] =3D Digit; - } else { - BinBuffer [Index/2] =3D (UINT8) ((BinBuffer [Index/2] << 4) + Digit)= ; - } - } - - *BinLength =3D (UINT32) ((Index + 1)/2); - - return EFI_SUCCESS; -} - -/** - Generate random numbers. - - @param[in, out] Rand The buffer to contain random numbers. - @param[in] RandLength The length of the Rand buffer. -**/ -VOID -IScsiGenRandom ( - IN OUT UINT8 *Rand, - IN UINTN RandLength - ) -{ - UINT32 Random; - - while (RandLength > 0) { - Random =3D NET_RANDOM (NetRandomInitSeed ()); - *Rand++ =3D (UINT8) (Random); - RandLength--; - } -} - -/** - Create the iSCSI driver data.. - - @param[in] Image The handle of the driver image. - @param[in] Controller The handle of the controller. - - @return The iSCSI driver data created. - @retval NULL Other errors as indicated. -**/ -ISCSI_DRIVER_DATA * -IScsiCreateDriverData ( - IN EFI_HANDLE Image, - IN EFI_HANDLE Controller - ) -{ - ISCSI_DRIVER_DATA *Private; - EFI_STATUS Status; - - Private =3D AllocateZeroPool (sizeof (ISCSI_DRIVER_DATA)); - if (Private =3D=3D NULL) { - return NULL; - } - - Private->Signature =3D ISCSI_DRIVER_DATA_SIGNATURE; - Private->Image =3D Image; - Private->Controller =3D Controller; - - // - // Create an event to be signal when the BS to RT transition is triggerd= so - // as to abort the iSCSI session. - // - Status =3D gBS->CreateEventEx ( - EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - IScsiOnExitBootService, - Private, - &gEfiEventExitBootServicesGuid, - &Private->ExitBootServiceEvent - ); - if (EFI_ERROR (Status)) { - FreePool (Private); - return NULL; - } - - CopyMem(&Private->IScsiExtScsiPassThru, &gIScsiExtScsiPassThruProtocolTe= mplate, sizeof(EFI_EXT_SCSI_PASS_THRU_PROTOCOL)); - - // - // 0 is designated to the TargetId, so use another value for the Adapter= Id. - // - Private->ExtScsiPassThruMode.AdapterId =3D 2; - Private->ExtScsiPassThruMode.Attributes =3D EFI_EXT_SCSI_PASS_THRU_ATTRI= BUTES_PHYSICAL | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL; - Private->ExtScsiPassThruMode.IoAlign =3D 4; - Private->IScsiExtScsiPassThru.Mode =3D &Private->ExtScsiPassThruMode; - - // - // Install the Ext SCSI PASS THRU protocol. - // - Status =3D gBS->InstallProtocolInterface ( - &Private->ExtScsiPassThruHandle, - &gEfiExtScsiPassThruProtocolGuid, - EFI_NATIVE_INTERFACE, - &Private->IScsiExtScsiPassThru - ); - if (EFI_ERROR (Status)) { - gBS->CloseEvent (Private->ExitBootServiceEvent); - FreePool (Private); - - return NULL; - } - - IScsiSessionInit (&Private->Session, FALSE); - - return Private; -} - -/** - Clean the iSCSI driver data. - - @param[in] Private The iSCSI driver data. - - @retval EFI_SUCCESS The clean operation is successful. - @retval Others Other errors as indicated. - -**/ -EFI_STATUS -IScsiCleanDriverData ( - IN ISCSI_DRIVER_DATA *Private - ) -{ - EFI_STATUS Status; - - Status =3D EFI_SUCCESS; - - if (Private->DevicePath !=3D NULL) { - Status =3D gBS->UninstallProtocolInterface ( - Private->ExtScsiPassThruHandle, - &gEfiDevicePathProtocolGuid, - Private->DevicePath - ); - if (EFI_ERROR (Status)) { - goto EXIT; - } - - FreePool (Private->DevicePath); - } - - if (Private->ExtScsiPassThruHandle !=3D NULL) { - Status =3D gBS->UninstallProtocolInterface ( - Private->ExtScsiPassThruHandle, - &gEfiExtScsiPassThruProtocolGuid, - &Private->IScsiExtScsiPassThru - ); - } - -EXIT: - if (Private->ExitBootServiceEvent !=3D NULL) { - gBS->CloseEvent (Private->ExitBootServiceEvent); - } - - FreePool (Private); - return Status; -} - -/** - Check wheather the Controller is configured to use DHCP protocol. - - @param[in] Controller The handle of the controller. - - @retval TRUE The handle of the controller need the D= hcp protocol. - @retval FALSE The handle of the controller does not n= eed the Dhcp protocol. - -**/ -BOOLEAN -IScsiDhcpIsConfigured ( - IN EFI_HANDLE Controller - ) -{ - EFI_STATUS Status; - EFI_MAC_ADDRESS MacAddress; - UINTN HwAddressSize; - UINT16 VlanId; - CHAR16 MacString[70]; - ISCSI_SESSION_CONFIG_NVDATA *ConfigDataTmp; - - // - // Get the mac string, it's the name of various variable - // - Status =3D NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize)= ; - if (EFI_ERROR (Status)) { - return FALSE; - } - VlanId =3D NetLibGetVlanId (Controller); - IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacStrin= g); - - // - // Get the normal configuration. - // - Status =3D GetVariable2 ( - MacString, - &gEfiIScsiInitiatorNameProtocolGuid, - (VOID**)&ConfigDataTmp, - NULL - ); - if (ConfigDataTmp =3D=3D NULL || EFI_ERROR (Status)) { - return FALSE; - } - - if (ConfigDataTmp->Enabled && ConfigDataTmp->InitiatorInfoFromDhcp) { - FreePool (ConfigDataTmp); - return TRUE; - } - - FreePool (ConfigDataTmp); - return FALSE; -} - -/** - Get the various configuration data of this iSCSI instance. - - @param[in] Private The iSCSI driver data. - - @retval EFI_SUCCESS The configuration of this instance is got. - @retval EFI_ABORTED The operation was aborted. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiGetConfigData ( - IN ISCSI_DRIVER_DATA *Private - ) -{ - EFI_STATUS Status; - ISCSI_SESSION *Session; - UINTN BufferSize; - EFI_MAC_ADDRESS MacAddress; - UINTN HwAddressSize; - UINT16 VlanId; - CHAR16 MacString[70]; - - // - // get the iSCSI Initiator Name - // - Session =3D &Private->Session; - Session->InitiatorNameLength =3D ISCSI_NAME_MAX_SIZE; - Status =3D gIScsiInitiatorName.Get ( - &gIScsiInitiatorName, - &Session->InitiatorNameLength, - Session->InitiatorName - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Get the mac string, it's the name of various variable - // - Status =3D NetLibGetMacAddress (Private->Controller, &MacAddress, &HwAdd= ressSize); - ASSERT (Status =3D=3D EFI_SUCCESS); - VlanId =3D NetLibGetVlanId (Private->Controller); - IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacStrin= g); - - // - // Get the normal configuration. - // - BufferSize =3D sizeof (Session->ConfigData.NvData); - Status =3D gRT->GetVariable ( - MacString, - &gEfiIScsiInitiatorNameProtocolGuid, - NULL, - &BufferSize, - &Session->ConfigData.NvData - ); - if (EFI_ERROR (Status)) { - return Status; - } - - if (!Session->ConfigData.NvData.Enabled) { - return EFI_ABORTED; - } - // - // Get the CHAP Auth information. - // - BufferSize =3D sizeof (Session->AuthData.AuthConfig); - Status =3D gRT->GetVariable ( - MacString, - &gIScsiCHAPAuthInfoGuid, - NULL, - &BufferSize, - &Session->AuthData.AuthConfig - ); - - if (!EFI_ERROR (Status) && Session->ConfigData.NvData.InitiatorInfoFromD= hcp) { - // - // Start dhcp. - // - Status =3D IScsiDoDhcp (Private->Image, Private->Controller, &Session-= >ConfigData); - } - - return Status; -} - -/** - Get the device path of the iSCSI tcp connection and update it. - - @param[in] Private The iSCSI driver data. - - @return The updated device path. - @retval NULL Other errors as indicated. -**/ -EFI_DEVICE_PATH_PROTOCOL * -IScsiGetTcpConnDevicePath ( - IN ISCSI_DRIVER_DATA *Private - ) -{ - ISCSI_SESSION *Session; - ISCSI_CONNECTION *Conn; - TCP4_IO *Tcp4Io; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_STATUS Status; - EFI_DEV_PATH *DPathNode; - - Session =3D &Private->Session; - if (Session->State !=3D SESSION_STATE_LOGGED_IN) { - return NULL; - } - - Conn =3D NET_LIST_USER_STRUCT_S ( - Session->Conns.ForwardLink, - ISCSI_CONNECTION, - Link, - ISCSI_CONNECTION_SIGNATURE - ); - Tcp4Io =3D &Conn->Tcp4Io; - - Status =3D gBS->HandleProtocol ( - Tcp4Io->Handle, - &gEfiDevicePathProtocolGuid, - (VOID **)&DevicePath - ); - if (EFI_ERROR (Status)) { - return NULL; - } - // - // Duplicate it. - // - DevicePath =3D DuplicateDevicePath (DevicePath); - if (DevicePath =3D=3D NULL) { - return NULL; - } - - DPathNode =3D (EFI_DEV_PATH *) DevicePath; - - while (!IsDevicePathEnd (&DPathNode->DevPath)) { - if ((DevicePathType (&DPathNode->DevPath) =3D=3D MESSAGING_DEVICE_PATH= ) && - (DevicePathSubType (&DPathNode->DevPath) =3D=3D MSG_IPv4_DP) - ) { - - DPathNode->Ipv4.LocalPort =3D 0; - DPathNode->Ipv4.StaticIpAddress =3D - (BOOLEAN) (!Session->ConfigData.NvData.InitiatorInfoFromDhcp); - - // - // Add a judgement here to support previous versions of IPv4_DEVICE= _PATH. - // In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and S= ubnetMask - // do not exist. - // In new version of IPv4_DEVICE_PATH, structcure length is 27. - // - if (DevicePathNodeLength (&DPathNode->Ipv4) =3D=3D IP4_NODE_LEN_NEW_= VERSIONS) { - - IP4_COPY_ADDRESS ( - &DPathNode->Ipv4.GatewayIpAddress, - &Session->ConfigData.NvData.Gateway - ); - - IP4_COPY_ADDRESS ( - &DPathNode->Ipv4.SubnetMask, - &Session->ConfigData.NvData.SubnetMask - ); - } - - break; - } - - DPathNode =3D (EFI_DEV_PATH *) NextDevicePathNode (&DPathNode->DevPath= ); - } - - return DevicePath; -} - -/** - Abort the session when the transition from BS to RT is initiated. - - @param[in] Event The event signaled. - @param[in] Context The iSCSI driver data. -**/ -VOID -EFIAPI -IScsiOnExitBootService ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - ISCSI_DRIVER_DATA *Private; - - Private =3D (ISCSI_DRIVER_DATA *) Context; - - gBS->CloseEvent (Private->ExitBootServiceEvent); - Private->ExitBootServiceEvent =3D NULL; - - IScsiSessionAbort (&Private->Session); -} - -/** - Tests whether a controller handle is being managed by IScsi driver. - - This function tests whether the driver specified by DriverBindingHandle = is - currently managing the controller specified by ControllerHandle. This t= est - is performed by evaluating if the the protocol specified by ProtocolGuid= is - present on ControllerHandle and is was opened by DriverBindingHandle and= Nic - Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. - If ProtocolGuid is NULL, then ASSERT(). - - @param ControllerHandle A handle for a controller to test. - @param DriverBindingHandle Specifies the driver binding handle for the - driver. - @param ProtocolGuid Specifies the protocol that the driver spec= ified - by DriverBindingHandle opens in its Start() - function. - - @retval EFI_SUCCESS ControllerHandle is managed by the driver - specified by DriverBindingHandle. - @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driv= er - specified by DriverBindingHandle. - -**/ -EFI_STATUS -EFIAPI -IScsiTestManagedDevice ( - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE DriverBindingHandle, - IN EFI_GUID *ProtocolGuid - ) -{ - EFI_STATUS Status; - VOID *ManagedInterface; - EFI_HANDLE NicControllerHandle; - - ASSERT (ProtocolGuid !=3D NULL); - - NicControllerHandle =3D NetLibGetNicHandle (ControllerHandle, ProtocolGu= id); - if (NicControllerHandle =3D=3D NULL) { - return EFI_UNSUPPORTED; - } - - Status =3D gBS->OpenProtocol ( - ControllerHandle, - (EFI_GUID *) ProtocolGuid, - &ManagedInterface, - DriverBindingHandle, - NicControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (!EFI_ERROR (Status)) { - gBS->CloseProtocol ( - ControllerHandle, - (EFI_GUID *) ProtocolGuid, - DriverBindingHandle, - NicControllerHandle - ); - return EFI_UNSUPPORTED; - } - - if (Status !=3D EFI_ALREADY_STARTED) { - return EFI_UNSUPPORTED; - } - - return EFI_SUCCESS; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c b/MdeModu= lePkg/Universal/Network/IScsiDxe/IScsiProto.c deleted file mode 100644 index b4a5c2d02413..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.c +++ /dev/null @@ -1,2799 +0,0 @@ -/** @file - The implementation of iSCSI protocol based on RFC3720. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -UINT32 mDataSegPad =3D 0; - -/** - Attach the iSCSI connection to the iSCSI session. - - @param[in, out] Session The iSCSI session. - @param[in, out] Conn The iSCSI connection. -**/ -VOID -IScsiAttatchConnection ( - IN OUT ISCSI_SESSION *Session, - IN OUT ISCSI_CONNECTION *Conn - ) -{ - InsertTailList (&Session->Conns, &Conn->Link); - Conn->Session =3D Session; - Session->NumConns++; -} - -/** - Detach the iSCSI connection from the session it belongs to. - - @param[in, out] Conn The iSCSI connection. -**/ -VOID -IScsiDetatchConnection ( - IN OUT ISCSI_CONNECTION *Conn - ) -{ - RemoveEntryList (&Conn->Link); - Conn->Session->NumConns--; - Conn->Session =3D NULL; -} - -/** - Check the sequence number according to RFC3720. - - @param[in, out] ExpSN The currently expected sequence number. - @param[in] NewSN The sequence number to check. - - @retval EFI_SUCCESS The check passed and the ExpSN is increased. - @retval EFI_NOT_READY Response was sent due to a retransmission re= quest. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. -**/ -EFI_STATUS -IScsiCheckSN ( - IN OUT UINT32 *ExpSN, - IN UINT32 NewSN - ) -{ - if (!ISCSI_SEQ_EQ (NewSN, *ExpSN)) { - if (ISCSI_SEQ_LT (NewSN, *ExpSN)) { - // - // Duplicate - // - return EFI_NOT_READY; - } else { - return EFI_PROTOCOL_ERROR; - } - } else { - // - // Advance the ExpSN - // - (*ExpSN)++; - return EFI_SUCCESS; - } -} - -/** - Update the sequence numbers for the iSCSI command. - - @param[in, out] Session The iSCSI session. - @param[in] MaxCmdSN Maximum CmdSN from the target. - @param[in] ExpCmdSN Next expected CmdSN from the target. -**/ -VOID -IScsiUpdateCmdSN ( - IN OUT ISCSI_SESSION *Session, - IN UINT32 MaxCmdSN, - IN UINT32 ExpCmdSN - ) -{ - if (ISCSI_SEQ_LT (MaxCmdSN, ExpCmdSN - 1)) { - return ; - } - - if (ISCSI_SEQ_GT (MaxCmdSN, Session->MaxCmdSN)) { - Session->MaxCmdSN =3D MaxCmdSN; - } - - if (ISCSI_SEQ_GT (ExpCmdSN, Session->ExpCmdSN)) { - Session->ExpCmdSN =3D ExpCmdSN; - } -} - -/** - This function does the iSCSI connection login. - - @param[in, out] Conn The iSCSI connection to login. - - @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI= target. - @retval EFI_TIMEOUT Timeout happened during the login procedure. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiConnLogin ( - IN OUT ISCSI_CONNECTION *Conn - ) -{ - EFI_STATUS Status; - - // - // Start the timer, wait 16 seconds to establish the TCP connection. - // - Status =3D gBS->SetTimer (Conn->TimeoutEvent, TimerRelative, 16 * TICKS_= PER_SECOND); - if (EFI_ERROR (Status)) { - return Status; - } - // - // try to establish the tcp connection - // - Status =3D Tcp4IoConnect (&Conn->Tcp4Io, Conn->TimeoutEvent); - if (EFI_ERROR (Status)) { - return Status; - } - - gBS->SetTimer (Conn->TimeoutEvent, TimerCancel, 0); - Conn->State =3D CONN_STATE_IN_LOGIN; - - // - // connection is established, start the iSCSI Login - // - do { - Status =3D IScsiSendLoginReq (Conn); - if (EFI_ERROR (Status)) { - break; - } - - Status =3D IScsiReceiveLoginRsp (Conn); - if (EFI_ERROR (Status)) { - break; - } - } while (Conn->CurrentStage !=3D ISCSI_FULL_FEATURE_PHASE); - - return Status; -} - -/** - Reset the iSCSI connection. - - @param[in, out] Conn The iSCSI connection to reset. -**/ -VOID -IScsiConnReset ( - IN OUT ISCSI_CONNECTION *Conn - ) -{ - Tcp4IoReset (&Conn->Tcp4Io); -} - -/** - Create a TCP connection for the iSCSI session. - - @param[in] Private The iSCSI driver data. - @param[in] Session Maximum CmdSN from the target. - - @return The newly created iSCSI connection. -**/ -ISCSI_CONNECTION * -IScsiCreateConnection ( - IN ISCSI_DRIVER_DATA *Private, - IN ISCSI_SESSION *Session - ) -{ - ISCSI_CONNECTION *Conn; - TCP4_IO_CONFIG_DATA Tcp4IoConfig; - EFI_STATUS Status; - - Conn =3D AllocatePool (sizeof (ISCSI_CONNECTION)); - if (Conn =3D=3D NULL) { - return NULL; - } - - Conn->Signature =3D ISCSI_CONNECTION_SIGNATURE; - Conn->State =3D CONN_STATE_FREE; - Conn->CurrentStage =3D ISCSI_SECURITY_NEGOTIATION; - Conn->NextStage =3D ISCSI_LOGIN_OPERATIONAL_NEGOTIATION; - Conn->CHAPStep =3D ISCSI_CHAP_INITIAL; - Conn->ExpStatSN =3D 0; - Conn->PartialReqSent =3D FALSE; - Conn->PartialRspRcvd =3D FALSE; - Conn->Cid =3D Session->NextCid++; - - Status =3D gBS->CreateEvent ( - EVT_TIMER, - TPL_CALLBACK, - NULL, - NULL, - &Conn->TimeoutEvent - ); - if (EFI_ERROR (Status)) { - FreePool (Conn); - return NULL; - } - - NetbufQueInit (&Conn->RspQue); - - // - // set the default connection-only parameters - // - Conn->MaxRecvDataSegmentLength =3D DEFAULT_MAX_RECV_DATA_SEG_LEN; - Conn->HeaderDigest =3D IScsiDigestNone; - Conn->DataDigest =3D IScsiDigestNone; - - CopyMem (&Tcp4IoConfig.LocalIp, &Session->ConfigData.NvData.LocalIp, siz= eof (EFI_IPv4_ADDRESS)); - CopyMem (&Tcp4IoConfig.SubnetMask, &Session->ConfigData.NvData.SubnetMas= k, sizeof (EFI_IPv4_ADDRESS)); - CopyMem (&Tcp4IoConfig.Gateway, &Session->ConfigData.NvData.Gateway, siz= eof (EFI_IPv4_ADDRESS)); - CopyMem (&Tcp4IoConfig.RemoteIp, &Session->ConfigData.NvData.TargetIp, s= izeof (EFI_IPv4_ADDRESS)); - - Tcp4IoConfig.RemotePort =3D Session->ConfigData.NvData.TargetPort; - - // - // Create the tcp4 IO for this connection - // - Status =3D Tcp4IoCreateSocket ( - Private->Image, - Private->Controller, - &Tcp4IoConfig, - &Conn->Tcp4Io - ); - if (EFI_ERROR (Status)) { - gBS->CloseEvent (Conn->TimeoutEvent); - FreePool (Conn); - Conn =3D NULL; - } - - return Conn; -} - -/** - Destroy an iSCSI connection. - - @param[in] Conn The connection to destroy. -**/ -VOID -IScsiDestroyConnection ( - IN ISCSI_CONNECTION *Conn - ) -{ - Tcp4IoDestroySocket (&Conn->Tcp4Io); - NetbufQueFlush (&Conn->RspQue); - gBS->CloseEvent (Conn->TimeoutEvent); - FreePool (Conn); -} - -/** - Login the iSCSI session. - - @param[in] Private The iSCSI driver data. - - @retval EFI_SUCCESS The iSCSI session login procedure finished. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NO_MEDIA There was a media error. - @retval Others Other errors as indicated. - -**/ -EFI_STATUS -IScsiSessionLogin ( - IN ISCSI_DRIVER_DATA *Private - ) -{ - EFI_STATUS Status; - ISCSI_SESSION *Session; - ISCSI_CONNECTION *Conn; - EFI_TCP4_PROTOCOL *Tcp4; - EFI_STATUS MediaStatus; - - Session =3D &Private->Session; - - // - // Check media status before session login - // - MediaStatus =3D EFI_SUCCESS; - NetLibDetectMediaWaitTimeout (Private->Controller, ISCSI_CHECK_MEDIA_LOG= IN_WAITING_TIME, &MediaStatus); - if (MediaStatus !=3D EFI_SUCCESS) { - return EFI_NO_MEDIA; - } - - // - // Set session identifier - // - CopyMem (Session->Isid, Session->ConfigData.NvData.IsId, 6); - - // - // Create a connection for the session. - // - Conn =3D IScsiCreateConnection (Private, Session); - if (Conn =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - IScsiAttatchConnection (Session, Conn); - - // - // Login througth the newly created connection. - // - Status =3D IScsiConnLogin (Conn); - if (EFI_ERROR (Status)) { - IScsiConnReset (Conn); - IScsiDetatchConnection (Conn); - IScsiDestroyConnection (Conn); - } else { - Session->State =3D SESSION_STATE_LOGGED_IN; - - gBS->OpenProtocol ( - Conn->Tcp4Io.Handle, - &gEfiTcp4ProtocolGuid, - (VOID **)&Tcp4, - Private->Image, - Private->ExtScsiPassThruHandle, - EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER - ); - } - - return Status; -} - -/** - Build and send the iSCSI login request to the iSCSI target according to - the current login stage. - - @param[in] Conn The connection in the iSCSI login phase. - - @retval EFI_SUCCESS The iSCSI login request PDU is built and se= nt on this - connection. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_DEVICE_ERROR Some kind of device error happened. -**/ -EFI_STATUS -IScsiSendLoginReq ( - IN ISCSI_CONNECTION *Conn - ) -{ - NET_BUF *Pdu; - EFI_STATUS Status; - - // - // build the Login Request PDU - // - Pdu =3D IScsiPrepareLoginReq (Conn); - if (Pdu =3D=3D NULL) { - return EFI_DEVICE_ERROR; - } - // - // Send it to the iSCSI target. - // - Status =3D Tcp4IoTransmit (&Conn->Tcp4Io, Pdu); - - NetbufFree (Pdu); - - return Status; -} - -/** - Receive and process the iSCSI login response. - - @param[in] Conn The connection in the iSCSI login phase. - - @retval EFI_SUCCESS The iSCSI login response PDU is received an= d processed. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiReceiveLoginRsp ( - IN ISCSI_CONNECTION *Conn - ) -{ - EFI_STATUS Status; - NET_BUF *Pdu; - - Pdu =3D NULL; - - // - // Receive the iSCSI login response. - // - Status =3D IScsiReceivePdu (Conn, &Pdu, NULL, FALSE, FALSE, NULL); - if (EFI_ERROR (Status)) { - return Status; - } - // - // A Login Response is received, process it. - // - ASSERT (Pdu !=3D NULL); - Status =3D IScsiProcessLoginRsp (Conn, Pdu); - - NetbufFree (Pdu); - - return Status; -} - -/** - Add an iSCSI key-value pair as a string into the data segment of the Log= in Request PDU. - The DataSegmentLength and the actual size of the net buffer containing t= his PDU will be - updated. - - @param[in, out] Pdu The iSCSI PDU whose data segment the key-va= lue pair will - be added to. - @param[in] Key The key name string. - @param[in] Value The value string. - - @retval EFI_SUCCESS The key-valu pair is added to the PDU's dat= asegment and - the correspondence length fields are update= d. - @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to add= the key-value - pair. -**/ -EFI_STATUS -IScsiAddKeyValuePair ( - IN OUT NET_BUF *Pdu, - IN CHAR8 *Key, - IN CHAR8 *Value - ) -{ - UINT32 DataSegLen; - UINT32 KeyLen; - UINT32 ValueLen; - UINT32 TotalLen; - ISCSI_LOGIN_REQUEST *LoginReq; - CHAR8 *Data; - - LoginReq =3D (ISCSI_LOGIN_REQUEST *) NetbufGetByte (Pdu, 0, NULL); - if (LoginReq =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - DataSegLen =3D NTOH24 (LoginReq->DataSegmentLength); - - KeyLen =3D (UINT32) AsciiStrLen (Key); - ValueLen =3D (UINT32) AsciiStrLen (Value); - - // - // 1 byte for the key value separator '=3D' and 1 byte for the null - // delimiter after the value. - // - TotalLen =3D KeyLen + 1 + ValueLen + 1; - - // - // Allocate the space for the key-value pair. - // - Data =3D (CHAR8 *)NetbufAllocSpace (Pdu, TotalLen, NET_BUF_TAIL); - if (Data =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // Add the key. - // - CopyMem (Data, Key, KeyLen); - Data +=3D KeyLen; - - *Data =3D '=3D'; - Data++; - - // - // Add the value. - // - CopyMem (Data, Value, ValueLen); - Data +=3D ValueLen; - - *Data =3D '\0'; - - // - // update the DataSegmentLength - // - ISCSI_SET_DATASEG_LEN (LoginReq, DataSegLen + TotalLen); - - return EFI_SUCCESS; -} - -/** - Prepare the iSCSI login request to be sent according to the current logi= n status. - - @param[in, out] Conn The connection in the iSCSI login phase. - - @return The pointer to the net buffer containing the iSCSI login request= built. - @retval Others Other errors as indicated. -**/ -NET_BUF * -IScsiPrepareLoginReq ( - IN OUT ISCSI_CONNECTION *Conn - ) -{ - ISCSI_SESSION *Session; - NET_BUF *Nbuf; - ISCSI_LOGIN_REQUEST *LoginReq; - EFI_STATUS Status; - - Session =3D Conn->Session; - - Nbuf =3D NetbufAlloc (sizeof (ISCSI_LOGIN_REQUEST) + DEFAULT_MAX_RECV= _DATA_SEG_LEN); - if (Nbuf =3D=3D NULL) { - return NULL; - } - - LoginReq =3D (ISCSI_LOGIN_REQUEST *) NetbufAllocSpace (Nbuf, sizeof (ISC= SI_LOGIN_REQUEST), NET_BUF_TAIL); - ASSERT (LoginReq !=3D NULL); - ZeroMem (LoginReq, sizeof (ISCSI_LOGIN_REQUEST)); - - // - // Init the login request pdu - // - ISCSI_SET_OPCODE (LoginReq, ISCSI_OPCODE_LOGIN_REQ, ISCSI_REQ_IMMEDIATE)= ; - ISCSI_SET_STAGES (LoginReq, Conn->CurrentStage, Conn->NextStage); - LoginReq->VersionMax =3D ISCSI_VERSION_MAX; - LoginReq->VersionMin =3D ISCSI_VERSION_MIN; - LoginReq->Tsih =3D HTONS (Session->Tsih); - LoginReq->InitiatorTaskTag =3D HTONL (Session->InitiatorTaskTag); - LoginReq->Cid =3D HTONS (Conn->Cid); - LoginReq->CmdSN =3D HTONL (Session->CmdSN); - - // - // For the first Login Request on a coonection this is ExpStatSN for the - // old connection and this field is only valid if the Login Request rest= arts - // a connection. - // For subsequent Login Requests it is used to acknowledge the Login Res= ponses - // with their increasing StatSN values. - // - LoginReq->ExpStatSN =3D HTONL (Conn->ExpStatSN); - CopyMem (LoginReq->Isid, Session->Isid, sizeof (LoginReq->Isid)); - - if (Conn->PartialRspRcvd) { - // - // A partial response, initiator must send an empty Login Request. - // - return Nbuf; - } - - switch (Conn->CurrentStage) { - case ISCSI_SECURITY_NEGOTIATION: - Status =3D IScsiCHAPToSendReq (Conn, Nbuf); - break; - - case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION: - Status =3D IScsiFillOpParams (Conn, Nbuf); - ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT); - break; - - default: - // - // something error happens... - // - Status =3D EFI_DEVICE_ERROR; - break; - } - - if (EFI_ERROR (Status)) { - NetbufFree (Nbuf); - Nbuf =3D NULL; - } else { - // - // Pad the data segment if needed. - // - IScsiPadSegment (Nbuf, ISCSI_GET_DATASEG_LEN (LoginReq)); - // - // Check whether we will issue the stage transition signal? - // - Conn->TransitInitiated =3D (BOOLEAN) ISCSI_FLAG_ON (LoginReq, ISCSI_LO= GIN_REQ_PDU_FLAG_TRANSIT); - } - - return Nbuf; -} - -/** - Process the iSCSI Login Response. - - @param[in, out] Conn The connection on which the iSCSI login response i= s received. - @param[in, out] Pdu The iSCSI login response PDU. - - @retval EFI_SUCCESS The iSCSI login response PDU is processed and= all check are passed. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. - @retval EFI_MEDIA_CHANGED Target is redirected. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiProcessLoginRsp ( - IN OUT ISCSI_CONNECTION *Conn, - IN OUT NET_BUF *Pdu - ) -{ - EFI_STATUS Status; - ISCSI_SESSION *Session; - ISCSI_LOGIN_RESPONSE *LoginRsp; - BOOLEAN Transit; - BOOLEAN Continue; - UINT8 CurrentStage; - UINT8 NextStage; - UINT8 *DataSeg; - UINT32 DataSegLen; - - Session =3D Conn->Session; - - LoginRsp =3D (ISCSI_LOGIN_RESPONSE *) NetbufGetByte (Pdu, 0, NULL); - if (LoginRsp =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - if (!ISCSI_CHECK_OPCODE (LoginRsp, ISCSI_OPCODE_LOGIN_RSP)) { - // - // It's not a Login Response - // - return EFI_PROTOCOL_ERROR; - } - // - // Get the data segment if any. - // - DataSegLen =3D ISCSI_GET_DATASEG_LEN (LoginRsp); - if (DataSegLen !=3D 0) { - DataSeg =3D NetbufGetByte (Pdu, sizeof (ISCSI_LOGIN_RESPONSE), NULL); - } else { - DataSeg =3D NULL; - } - // - // Check the status class in the login response PDU. - // - switch (LoginRsp->StatusClass) { - case ISCSI_LOGIN_STATUS_SUCCESS: - // - // Just break here, the response and the data segment will be processe= d later. - // - break; - - case ISCSI_LOGIN_STATUS_REDIRECTION: - // - // The target may be moved to a different address - // - if (DataSeg =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - // - // Process the TargetAddress key-value strings in the data segment to = update the - // target address info. - // - Status =3D IScsiUpdateTargetAddress (Session, (CHAR8 *)DataSeg, DataSe= gLen); - if (EFI_ERROR (Status)) { - return Status; - } - // - // Session will be restarted on this error status because the Target i= s - // redirected by this Login Response. - // - return EFI_MEDIA_CHANGED; - - default: - // - // Initiator Error, Target Error, or any other undefined error code. - // - return EFI_PROTOCOL_ERROR; - } - // - // The status is sucess, extract the wanted fields from the header segme= nt. - // - Transit =3D (BOOLEAN) ISCSI_FLAG_ON (LoginRsp, ISCSI= _LOGIN_RSP_PDU_FLAG_TRANSIT); - Continue =3D (BOOLEAN) ISCSI_FLAG_ON (LoginRsp, ISCSI= _LOGIN_RSP_PDU_FLAG_CONTINUE); - - CurrentStage =3D (UINT8) ISCSI_GET_CURRENT_STAGE (LoginRs= p); - NextStage =3D (UINT8) ISCSI_GET_NEXT_STAGE (LoginRsp); - - LoginRsp->InitiatorTaskTag =3D NTOHL (LoginRsp->InitiatorTaskTag); - - if ((Transit && Continue) || - (CurrentStage !=3D Conn->CurrentStage) || - (!Conn->TransitInitiated && Transit) || - (Transit && (NextStage !=3D Conn->NextStage)) || - (CompareMem (Session->Isid, LoginRsp->Isid, sizeof (LoginRsp->Isid))= !=3D 0) || - (LoginRsp->InitiatorTaskTag !=3D Session->InitiatorTaskTag) - ) { - // - // A Login Response with the C bit set to 1 MUST have the T bit set to= 0; - // The CSG in the Login Response MUST be the same with the I-end of th= is connection; - // The T bit can't be 1 if the last Login Response sent by the initiat= or doesn't - // initiate the transistion; - // The NSG MUST be the same with the I-end of this connection if Trans= it is required. - // The ISID in the Login Response MUST be the same with this session. - // - return EFI_PROTOCOL_ERROR; - } - - LoginRsp->StatSN =3D NTOHL (LoginRsp->StatSN); - LoginRsp->ExpCmdSN =3D NTOHL (LoginRsp->ExpCmdSN); - LoginRsp->MaxCmdSN =3D NTOHL (LoginRsp->MaxCmdSN); - - if ((Conn->CurrentStage =3D=3D ISCSI_SECURITY_NEGOTIATION) && (Conn->CHA= PStep =3D=3D ISCSI_CHAP_INITIAL)) { - // - // If the Login Request is a leading Login Request, the target MUST us= e - // the value presented in CmdSN as the target value for ExpCmdSN. - // - if ((Session->State =3D=3D SESSION_STATE_FREE) && (Session->CmdSN !=3D= LoginRsp->ExpCmdSN)) { - return EFI_PROTOCOL_ERROR; - } - - // - // It's the initial Login Response, initialize the local ExpStatSN, Ma= xCmdSN - // and ExpCmdSN. - // - Conn->ExpStatSN =3D LoginRsp->StatSN + 1; - Session->MaxCmdSN =3D LoginRsp->MaxCmdSN; - Session->ExpCmdSN =3D LoginRsp->ExpCmdSN; - } else { - // - // Check the StatSN of this PDU - // - Status =3D IScsiCheckSN (&Conn->ExpStatSN, LoginRsp->StatSN); - if (!EFI_ERROR (Status)) { - // - // Update the MaxCmdSN and ExpCmdSN - // - IScsiUpdateCmdSN (Session, LoginRsp->MaxCmdSN, LoginRsp->ExpCmdSN); - } else { - return Status; - } - } - // - // Trim off the header segment. - // - NetbufTrim (Pdu, sizeof (ISCSI_LOGIN_RESPONSE), NET_BUF_HEAD); - - // - // Queue this login response first in case it's a partial response so th= at - // later when the full response list is received we can combine these sc= attered - // responses' data segment and then process it. - // - NET_GET_REF (Pdu); - NetbufQueAppend (&Conn->RspQue, Pdu); - - Conn->PartialRspRcvd =3D Continue; - if (Continue) { - // - // It's a partial response, have to wait for another or more Request/R= esponse - // conversations to get the full response. - // - return EFI_SUCCESS; - } - - switch (CurrentStage) { - case ISCSI_SECURITY_NEGOTIATION: - // - // In security negotiation stage, let CHAP module handle it. - // - Status =3D IScsiCHAPOnRspReceived (Conn); - break; - - case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION: - // - // Response received with negotiation resonse on iSCSI parameters, che= ck them. - // - Status =3D IScsiCheckOpParams (Conn); - break; - - default: - // - // Should never get here. - // - Status =3D EFI_PROTOCOL_ERROR; - break; - } - - if (Transit && (Status =3D=3D EFI_SUCCESS)) { - // - // Do the state transition. - // - Conn->CurrentStage =3D Conn->NextStage; - - if (Conn->CurrentStage =3D=3D ISCSI_LOGIN_OPERATIONAL_NEGOTIATION) { - Conn->NextStage =3D ISCSI_FULL_FEATURE_PHASE; - } else { - // - // CurrentStage is iSCSI Full Feature, it's the Login-Final Response= , - // get the TSIH from the Login Response. - // - Session->Tsih =3D NTOHS (LoginRsp->Tsih); - } - } - // - // Flush the response(s) received. - // - NetbufQueFlush (&Conn->RspQue); - - return Status; -} - -/** - Updated the target information according the data received in the iSCSI - login response with an target redirection status. - - @param[in, out] Session The iSCSI session. - @param[in] Data The data segment which should contain the - TargetAddress key-value list. - @param[in] Len Length of the data. - - @retval EFI_SUCCESS The target address is updated. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NOT_FOUND The TargetAddress key is not found. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiUpdateTargetAddress ( - IN OUT ISCSI_SESSION *Session, - IN CHAR8 *Data, - IN UINT32 Len - ) -{ - LIST_ENTRY *KeyValueList; - CHAR8 *TargetAddress; - CHAR8 *IpStr; - EFI_STATUS Status; - UINTN Number; - - KeyValueList =3D IScsiBuildKeyValueList (Data, Len); - if (KeyValueList =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status =3D EFI_NOT_FOUND; - - while (TRUE) { - TargetAddress =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_= TARGET_ADDRESS); - if (TargetAddress =3D=3D NULL) { - break; - } - - if (!NET_IS_DIGIT (TargetAddress[0])) { - // - // The domainname of the target may be presented in three formats: a= DNS host name, - // a dotted-decimal IPv4 address, or a bracketed IPv6 address. Only = accept dotted - // IPv4 address. - // - continue; - } - - IpStr =3D TargetAddress; - - while ((*TargetAddress !=3D 0) && (*TargetAddress !=3D ':') && (*Targe= tAddress !=3D ',')) { - // - // NULL, ':' or ',' ends the IPv4 string. - // - TargetAddress++; - } - - if (*TargetAddress =3D=3D ',') { - // - // Comma and the portal group tag MUST be ommitted if the TargetAddr= ess is sent - // as the result of a redirection. - // - continue; - } else if (*TargetAddress =3D=3D ':') { - *TargetAddress =3D '\0'; - - TargetAddress++; - - Number =3D AsciiStrDecimalToUintn (TargetAddress); - if (Number > 0xFFFF) { - continue; - } else { - Session->ConfigData.NvData.TargetPort =3D (UINT16) Number; - } - } else { - // - // The string only contains the IPv4 address. Use the well known por= t. - // - Session->ConfigData.NvData.TargetPort =3D ISCSI_WELL_KNOWN_PORT; - } - // - // Update the target IP address. - // - Status =3D IScsiAsciiStrToIp (IpStr, &Session->ConfigData.NvData.Targe= tIp); - if (EFI_ERROR (Status)) { - continue; - } else { - break; - } - } - - IScsiFreeKeyValueList (KeyValueList); - - return Status; -} - -/** - The callback function to free the net buffer list. - - @param[in] Arg The opaque parameter. -**/ -VOID -EFIAPI -IScsiFreeNbufList ( - VOID *Arg - ) -{ - ASSERT (Arg !=3D NULL); - - NetbufFreeList ((LIST_ENTRY *) Arg); - FreePool (Arg); -} - -/** - The callback function called in NetBufFree, it does nothing. - - @param[in] Arg The opaque parameter. -**/ -VOID -EFIAPI -IScsiNbufExtFree ( - VOID *Arg - ) -{ -} - -/** - Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI P= DU header and - an optional data segment. The two parts will be put into two blocks of b= uffers in the - net buffer. The digest check will be conducted in this function if neede= d and the digests - will be trimmed from the PDU buffer. - - @param[in] Conn The iSCSI connection to receive data from. - @param[out] Pdu The received iSCSI pdu. - @param[in] Context The context used to describe information on the= caller provided - buffer to receive data segment of the iSCSI pdu= , it's optional. - @param[in] HeaderDigest Whether there will be header digest received. - @param[in] DataDigest Whether there will be data digest. - @param[in] TimeoutEvent The timeout event, it's optional. - - @retval EFI_SUCCESS An iSCSI pdu is received. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiReceivePdu ( - IN ISCSI_CONNECTION *Conn, - OUT NET_BUF **Pdu, - IN ISCSI_IN_BUFFER_CONTEXT *Context, OPTIONAL - IN BOOLEAN HeaderDigest, - IN BOOLEAN DataDigest, - IN EFI_EVENT TimeoutEvent OPTIONAL - ) -{ - LIST_ENTRY *NbufList; - UINT32 Len; - NET_BUF *PduHdr; - UINT8 *Header; - EFI_STATUS Status; - UINT32 PadLen; - UINT32 InDataOffset; - NET_FRAGMENT Fragment[2]; - UINT32 FragmentCount; - NET_BUF *DataSeg; - UINT32 PadAndCRC32[2]; - - NbufList =3D AllocatePool (sizeof (LIST_ENTRY)); - if (NbufList =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - InitializeListHead (NbufList); - - // - // The header digest will be received together with the PDU header if ex= ists. - // - Len =3D sizeof (ISCSI_BASIC_HEADER) + (HeaderDigest ? sizeof (UINT32= ) : 0); - PduHdr =3D NetbufAlloc (Len); - if (PduHdr =3D=3D NULL) { - FreePool (NbufList); - return EFI_OUT_OF_RESOURCES; - } - - Header =3D NetbufAllocSpace (PduHdr, Len, NET_BUF_TAIL); - ASSERT (Header !=3D NULL); - InsertTailList (NbufList, &PduHdr->List); - - // - // First step, receive the BHS of the PDU. - // - Status =3D Tcp4IoReceive (&Conn->Tcp4Io, PduHdr, FALSE, TimeoutEvent); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - if (HeaderDigest) { - // - // TODO: check the header-digest. - // - // - // Trim off the digest. - // - NetbufTrim (PduHdr, sizeof (UINT32), NET_BUF_TAIL); - } - - Len =3D ISCSI_GET_DATASEG_LEN (Header); - if (Len =3D=3D 0) { - // - // No data segment.Form the pdu from a list of pdu segments. - // - *Pdu =3D NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufLis= t); - if (*Pdu =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - return Status; - } - // - // Get the length of the padding bytes of the data segment. - // - PadLen =3D ISCSI_GET_PAD_LEN (Len); - - switch (ISCSI_GET_OPCODE (Header)) { - case ISCSI_OPCODE_SCSI_DATA_IN: - // - // Try to use the buffer described by Context if the PDU is an - // iSCSI SCSI data in pdu so as to reduce memory copy overhead. - // - InDataOffset =3D ISCSI_GET_BUFFER_OFFSET (Header); - if ((Context =3D=3D NULL) || ((InDataOffset + Len) > Context->InDataLe= n)) { - Status =3D EFI_PROTOCOL_ERROR; - goto ON_EXIT; - } - - Fragment[0].Len =3D Len; - Fragment[0].Bulk =3D Context->InData + InDataOffset; - - if (DataDigest || (PadLen !=3D 0)) { - // - // The data segment is padded, use two fragments to receive it. - // The first to receive the useful data. The second to receive the p= adding. - // - Fragment[1].Len =3D PadLen + (DataDigest ? sizeof (UINT32) : 0); - Fragment[1].Bulk =3D (UINT8 *)PadAndCRC32 + (4 - PadLen); - FragmentCount =3D 2; - } else { - FragmentCount =3D 1; - } - - DataSeg =3D NetbufFromExt (&Fragment[0], FragmentCount, 0, 0, IScsiNbu= fExtFree, NULL); - if (DataSeg =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - break; - - case ISCSI_OPCODE_SCSI_RSP: - case ISCSI_OPCODE_NOP_IN: - case ISCSI_OPCODE_LOGIN_RSP: - case ISCSI_OPCODE_TEXT_RSP: - case ISCSI_OPCODE_ASYNC_MSG: - case ISCSI_OPCODE_REJECT: - case ISCSI_OPCODE_VENDOR_T0: - case ISCSI_OPCODE_VENDOR_T1: - case ISCSI_OPCODE_VENDOR_T2: - // - // Allocate buffer to receive the data segment. - // - Len +=3D PadLen + (DataDigest ? sizeof (UINT32) : 0); - DataSeg =3D NetbufAlloc (Len); - if (DataSeg =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - NetbufAllocSpace (DataSeg, Len, NET_BUF_TAIL); - break; - - default: - Status =3D EFI_PROTOCOL_ERROR; - goto ON_EXIT; - } - - InsertTailList (NbufList, &DataSeg->List); - - // - // Receive the data segment with the data digest if any. - // - Status =3D Tcp4IoReceive (&Conn->Tcp4Io, DataSeg, FALSE, TimeoutEvent); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - if (DataDigest) { - // - // TODO: Check the data digest. - // - NetbufTrim (DataSeg, sizeof (UINT32), NET_BUF_TAIL); - } - - if (PadLen !=3D 0) { - // - // Trim off the padding bytes in the data segment. - // - NetbufTrim (DataSeg, PadLen, NET_BUF_TAIL); - } - - // - // Form the pdu from a list of pdu segments. - // - *Pdu =3D NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufList)= ; - if (*Pdu =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - } - -ON_EXIT: - - if (EFI_ERROR (Status)) { - // - // Free the Nbufs in this NbufList and the NbufList itself. - // - IScsiFreeNbufList (NbufList); - } - - return Status; -} - -/** - Check and get the result of the prameter negotiation. - - @param[in, out] Conn The connection in iSCSI login. - - @retval EFI_SUCCESS The parmeter check is passed and negotiatio= n is finished. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. -**/ -EFI_STATUS -IScsiCheckOpParams ( - IN OUT ISCSI_CONNECTION *Conn - ) -{ - EFI_STATUS Status; - LIST_ENTRY *KeyValueList; - CHAR8 *Data; - UINT32 Len; - ISCSI_SESSION *Session; - CHAR8 *Value; - UINTN NumericValue; - - ASSERT (Conn->RspQue.BufNum !=3D 0); - - Session =3D Conn->Session; - - Len =3D Conn->RspQue.BufSize; - Data =3D AllocatePool (Len); - if (Data =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - NetbufQueCopy (&Conn->RspQue, 0, Len, (UINT8 *) Data); - - Status =3D EFI_PROTOCOL_ERROR; - - // - // Extract the Key-Value pairs into a list. - // - KeyValueList =3D IScsiBuildKeyValueList (Data, Len); - if (KeyValueList =3D=3D NULL) { - FreePool (Data); - return Status; - } - // - // HeaderDigest - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_HEADER_DIG= EST); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - if (AsciiStrCmp (Value, "CRC32") =3D=3D 0) { - if (Conn->HeaderDigest !=3D IScsiDigestCRC32) { - goto ON_ERROR; - } - } else if (AsciiStrCmp (Value, ISCSI_KEY_VALUE_NONE) =3D=3D 0) { - Conn->HeaderDigest =3D IScsiDigestNone; - } else { - goto ON_ERROR; - } - // - // DataDigest - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DATA_DIGES= T); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - if (AsciiStrCmp (Value, "CRC32") =3D=3D 0) { - if (Conn->DataDigest !=3D IScsiDigestCRC32) { - goto ON_ERROR; - } - } else if (AsciiStrCmp (Value, ISCSI_KEY_VALUE_NONE) =3D=3D 0) { - Conn->DataDigest =3D IScsiDigestNone; - } else { - goto ON_ERROR; - } - // - // ErrorRecoveryLevel, result fuction is Minimum. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_ERROR_RECO= VERY_LEVEL); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - if (NumericValue > 2) { - goto ON_ERROR; - } - - Session->ErrorRecoveryLevel =3D (UINT8) MIN (Session->ErrorRecoveryLevel= , NumericValue); - - // - // InitialR2T, result function is OR. - // - if (!Session->InitialR2T) { - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_INITIAL_= R2T); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - Session->InitialR2T =3D (BOOLEAN) (AsciiStrCmp (Value, "Yes") =3D=3D 0= ); - } - - // - // ImmediateData, result function is AND. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_IMMEDIATE_= DATA); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - Session->ImmediateData =3D (BOOLEAN) (Session->ImmediateData && (BOOLEAN= ) (AsciiStrCmp (Value, "Yes") =3D=3D 0)); - - // - // MaxRecvDataSegmentLength is declarative. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_MAX_RECV_D= ATA_SEGMENT_LENGTH); - if (Value !=3D NULL) { - Conn->MaxRecvDataSegmentLength =3D (UINT32) AsciiStrDecimalToUintn (Va= lue); - } - // - // MaxBurstLength, result funtion is Mininum. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_MAX_BURST_= LENGTH); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - Session->MaxBurstLength =3D (UINT32) MIN (Session->MaxBurstLength, Numer= icValue); - - // - // FirstBurstLength, result function is Minimum. Irrelevant when Initial= R2T=3DYes and - // ImmediateData=3DNo. - // This Key/Value is negotiation type. - // - if (!(Session->InitialR2T && !Session->ImmediateData)) { - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_FIRST_BU= RST_LENGTH); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - Session->FirstBurstLength =3D (UINT32) MIN (Session->FirstBurstLength,= NumericValue); - } - - // - // MaxConnections, result function is Minimum. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_MAX_CONNEC= TIONS); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - if ((NumericValue =3D=3D 0) || (NumericValue > 65535)) { - goto ON_ERROR; - } - - Session->MaxConnections =3D (UINT32) MIN (Session->MaxConnections, Numer= icValue); - - // - // DataPDUInOrder, result function is OR. - // - if (!Session->DataPDUInOrder) { - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DATA_PDU= _IN_ORDER); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - Session->DataPDUInOrder =3D (BOOLEAN) (AsciiStrCmp (Value, "Yes") =3D= =3D 0); - } - - // - // DataSequenceInorder, result function is OR. - // - if (!Session->DataSequenceInOrder) { - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DATA_SEQ= UENCE_IN_ORDER); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - Session->DataSequenceInOrder =3D (BOOLEAN) (AsciiStrCmp (Value, "Yes")= =3D=3D 0); - } - - // - // DefaultTime2Wait, result function is Maximum. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DEFAULT_TI= ME2WAIT); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - if (NumericValue =3D=3D 0) { - Session->DefaultTime2Wait =3D 0; - } else if (NumericValue > 3600) { - goto ON_ERROR; - } else { - Session->DefaultTime2Wait =3D (UINT32) MAX (Session->DefaultTime2Wait,= NumericValue); - } - // - // DefaultTime2Retain, result function is Minimum. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DEFAULT_TI= ME2RETAIN); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - if (NumericValue =3D=3D 0) { - Session->DefaultTime2Retain =3D 0; - } else if (NumericValue > 3600) { - goto ON_ERROR; - } else { - Session->DefaultTime2Retain =3D (UINT32) MIN (Session->DefaultTime2Ret= ain, NumericValue); - } - // - // MaxOutstandingR2T, result function is Minimum. - // - Value =3D IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_MAX_OUTSTA= NDING_R2T); - if (Value =3D=3D NULL) { - goto ON_ERROR; - } - - NumericValue =3D AsciiStrDecimalToUintn (Value); - if ((NumericValue =3D=3D 0) || (NumericValue > 65535)) { - goto ON_ERROR; - } - - Session->MaxOutstandingR2T =3D (UINT16) MIN (Session->MaxOutstandingR2T,= NumericValue); - - // - // Remove declarative key-value pairs, if any. - // - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_SESSION_TYPE); - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_ALIAS); - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_PORTAL_GROUP_= TAG); - // - // Remove the key-value that may not needed for result function is OR. - // - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_INITIAL_R2T); - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DATA_PDU_IN_ORDER); - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_DATA_SEQUENCE_IN_ORD= ER); - - // - // Remove irrelevant parameter, if any. - // - if (Session->InitialR2T && !Session->ImmediateData) { - IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_FIRST_BURST_LENGTH= ); - } - - if (IsListEmpty (KeyValueList)) { - // - // Succeed if no more keys in the list. - // - Status =3D EFI_SUCCESS; - } - -ON_ERROR: - - IScsiFreeKeyValueList (KeyValueList); - - FreePool (Data); - - return Status; -} - -/** - Fill the oprational prameters. - - @param[in] Conn The connection in iSCSI login. - @param[in, out] Pdu The iSCSI login request PDU to fill the par= ameters. - - @retval EFI_SUCCESS The parmeters are filled into the iSCSI log= in request PDU. -**/ -EFI_STATUS -IScsiFillOpParams ( - IN ISCSI_CONNECTION *Conn, - IN OUT NET_BUF *Pdu - ) -{ - ISCSI_SESSION *Session; - CHAR8 Value[256]; - - Session =3D Conn->Session; - - AsciiSPrint (Value, sizeof (Value), "%a", (Conn->HeaderDigest =3D=3D ISc= siDigestCRC32) ? "None,CRC32" : "None"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_HEADER_DIGEST, Value); - - AsciiSPrint (Value, sizeof (Value), "%a", (Conn->DataDigest =3D=3D IScsi= DigestCRC32) ? "None,CRC32" : "None"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_DATA_DIGEST, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->ErrorRecoveryLevel); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_ERROR_RECOVERY_LEVEL, Value); - - AsciiSPrint (Value, sizeof (Value), "%a", Session->InitialR2T ? "Yes" : = "No"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_INITIAL_R2T, Value); - - AsciiSPrint (Value, sizeof (Value), "%a", Session->ImmediateData ? "Yes"= : "No"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_IMMEDIATE_DATA, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", MAX_RECV_DATA_SEG_LEN_IN_FFP); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH, Value= ); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->MaxBurstLength); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_MAX_BURST_LENGTH, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->FirstBurstLength); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_FIRST_BURST_LENGTH, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->MaxConnections); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_MAX_CONNECTIONS, Value); - - AsciiSPrint (Value, sizeof (Value), "%a", Session->DataPDUInOrder ? "Yes= " : "No"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_DATA_PDU_IN_ORDER, Value); - - AsciiSPrint (Value, sizeof (Value), "%a", Session->DataSequenceInOrder ?= "Yes" : "No"); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->DefaultTime2Wait); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_DEFAULT_TIME2WAIT, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->DefaultTime2Retain); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_DEFAULT_TIME2RETAIN, Value); - - AsciiSPrint (Value, sizeof (Value), "%d", Session->MaxOutstandingR2T); - IScsiAddKeyValuePair (Pdu, ISCSI_KEY_MAX_OUTSTANDING_R2T, Value); - - return EFI_SUCCESS; -} - -/** - Pad the iSCSI AHS or data segment to an integer number of 4 byte words. - - @param[in, out] Pdu The iSCSI pdu which contains segments to pa= d. - @param[in] Len The length of the last semgnet in the PDU. - - @retval EFI_SUCCESS The segment is padded or no need to pad it. - @retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to= add the - padding bytes. -**/ -EFI_STATUS -IScsiPadSegment ( - IN OUT NET_BUF *Pdu, - IN UINT32 Len - ) -{ - UINT32 PadLen; - UINT8 *Data; - - PadLen =3D ISCSI_GET_PAD_LEN (Len); - - if (PadLen !=3D 0) { - Data =3D NetbufAllocSpace (Pdu, PadLen, NET_BUF_TAIL); - if (Data =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - ZeroMem (Data, PadLen); - } - - return EFI_SUCCESS; -} - -/** - Build a key-value list from the data segment. - - @param[in] Data The data segment containing the key-value pairs. - @param[in] Len Length of the data segment. - - @return The key-value list. - @retval NULL Other errors as indicated. -**/ -LIST_ENTRY * -IScsiBuildKeyValueList ( - IN CHAR8 *Data, - IN UINT32 Len - ) -{ - LIST_ENTRY *ListHead; - ISCSI_KEY_VALUE_PAIR *KeyValuePair; - - ListHead =3D AllocatePool (sizeof (LIST_ENTRY)); - if (ListHead =3D=3D NULL) { - return NULL; - } - - InitializeListHead (ListHead); - - while (Len > 0) { - KeyValuePair =3D AllocatePool (sizeof (ISCSI_KEY_VALUE_PAIR)); - if (KeyValuePair =3D=3D NULL) { - goto ON_ERROR; - } - - InitializeListHead (&KeyValuePair->List); - - KeyValuePair->Key =3D Data; - - while ((Len > 0) && (*Data !=3D '=3D')) { - Len--; - Data++; - } - - if (*Data =3D=3D '=3D') { - *Data =3D '\0'; - - Data++; - Len--; - } else { - FreePool (KeyValuePair); - goto ON_ERROR; - } - - KeyValuePair->Value =3D Data; - - InsertTailList (ListHead, &KeyValuePair->List);; - - Data +=3D AsciiStrLen (KeyValuePair->Value) + 1; - Len -=3D (UINT32) AsciiStrLen (KeyValuePair->Value) + 1; - } - - return ListHead; - -ON_ERROR: - - IScsiFreeKeyValueList (ListHead); - - return NULL; -} - -/** - Get the value string by the key name from the key-value list. If found, - the key-value entry will be removed from the list. - - @param[in, out] KeyValueList The key-value list. - @param[in] Key The key name to find. - - @return The value string. -**/ -CHAR8 * -IScsiGetValueByKeyFromList ( - IN OUT LIST_ENTRY *KeyValueList, - IN CHAR8 *Key - ) -{ - LIST_ENTRY *Entry; - ISCSI_KEY_VALUE_PAIR *KeyValuePair; - CHAR8 *Value; - - Value =3D NULL; - - NET_LIST_FOR_EACH (Entry, KeyValueList) { - KeyValuePair =3D NET_LIST_USER_STRUCT (Entry, ISCSI_KEY_VALUE_PAIR, Li= st); - - if (AsciiStrCmp (KeyValuePair->Key, Key) =3D=3D 0) { - Value =3D KeyValuePair->Value; - - RemoveEntryList (&KeyValuePair->List); - FreePool (KeyValuePair); - break; - } - } - - return Value; -} - -/** - Free the key-value list. - - @param[in] KeyValueList The key-value list. -**/ -VOID -IScsiFreeKeyValueList ( - IN LIST_ENTRY *KeyValueList - ) -{ - LIST_ENTRY *Entry; - ISCSI_KEY_VALUE_PAIR *KeyValuePair; - - while (!IsListEmpty (KeyValueList)) { - Entry =3D NetListRemoveHead (KeyValueList); - KeyValuePair =3D NET_LIST_USER_STRUCT (Entry, ISCSI_KEY_VALUE_PAIR, L= ist); - - FreePool (KeyValuePair); - } - - FreePool (KeyValueList); -} - -/** - Normalize the iSCSI name according to RFC. - - @param[in, out] Name The iSCSI name. - @param[in] Len length of the iSCSI name. - - @retval EFI_SUCCESS The iSCSI name is valid and normalized. - @retval EFI_PROTOCOL_ERROR The iSCSI name is mal-formatted or not in the= IQN format. -**/ -EFI_STATUS -IScsiNormalizeName ( - IN OUT CHAR8 *Name, - IN UINTN Len - ) -{ - UINTN Index; - - for (Index =3D 0; Index < Len; Index++) { - if (NET_IS_UPPER_CASE_CHAR (Name[Index])) { - // - // Convert the upper-case characters to lower-case ones - // - Name[Index] =3D (CHAR8) (Name[Index] - 'A' + 'a'); - } - - if (!NET_IS_LOWER_CASE_CHAR (Name[Index]) && - !NET_IS_DIGIT (Name[Index]) && - (Name[Index] !=3D '-') && - (Name[Index] !=3D '.') && - (Name[Index] !=3D ':') - ) { - // - // ASCII dash, dot, colon lower-case characters and digit characters - // are allowed. - // - return EFI_PROTOCOL_ERROR; - } - } - - if ((Len < 4) || (CompareMem (Name, "iqn.", 4) !=3D 0)) { - // - // Only IQN format is accepted now. - // - return EFI_PROTOCOL_ERROR; - } - - return EFI_SUCCESS; -} - -/** - Create an iSCSI task control block. - - @param[in] Conn The connection on which the task control blo= ck will be created. - @param[out] Tcb The newly created task control block. - - @retval EFI_SUCCESS The task control block is created. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NOT_READY The target can not accept new commands. -**/ -EFI_STATUS -IScsiNewTcb ( - IN ISCSI_CONNECTION *Conn, - OUT ISCSI_TCB **Tcb - ) -{ - ISCSI_SESSION *Session; - ISCSI_TCB *NewTcb; - - ASSERT (Tcb !=3D NULL); - - Session =3D Conn->Session; - - if (ISCSI_SEQ_GT (Session->CmdSN, Session->MaxCmdSN)) { - return EFI_NOT_READY; - } - - NewTcb =3D AllocateZeroPool (sizeof (ISCSI_TCB)); - if (NewTcb =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - InitializeListHead (&NewTcb->Link); - - NewTcb->SoFarInOrder =3D TRUE; - NewTcb->InitiatorTaskTag =3D Session->InitiatorTaskTag; - NewTcb->CmdSN =3D Session->CmdSN; - NewTcb->Conn =3D Conn; - - InsertTailList (&Session->TcbList, &NewTcb->Link); - - // - // Advance the initiator task tag. - // - Session->InitiatorTaskTag++; - Session->CmdSN++; - - *Tcb =3D NewTcb; - - return EFI_SUCCESS; -} - -/** - Delete the tcb from the connection and destroy it. - - @param[in] Tcb The tcb to delete. -**/ -VOID -IScsiDelTcb ( - IN ISCSI_TCB *Tcb - ) -{ - RemoveEntryList (&Tcb->Link); - - FreePool (Tcb); -} - - -/** - Create a data segment, pad it and calculate the CRC if needed. - - @param[in] Data The data to fill into the data segment. - @param[in] Len Length of the data. - @param[in] DataDigest Whether to calculate CRC for this data segment. - - @return The net buffer wrapping the data segment. -**/ -NET_BUF * -IScsiNewDataSegment ( - IN UINT8 *Data, - IN UINT32 Len, - IN BOOLEAN DataDigest - ) -{ - NET_FRAGMENT Fragment[2]; - UINT32 FragmentCount; - UINT32 PadLen; - NET_BUF *DataSeg; - - Fragment[0].Len =3D Len; - Fragment[0].Bulk =3D Data; - - PadLen =3D ISCSI_GET_PAD_LEN (Len); - if (PadLen !=3D 0) { - Fragment[1].Len =3D PadLen; - Fragment[1].Bulk =3D (UINT8 *) &mDataSegPad; - - FragmentCount =3D 2; - } else { - FragmentCount =3D 1; - } - - DataSeg =3D NetbufFromExt (&Fragment[0], FragmentCount, 0, 0, IScsiNbufE= xtFree, NULL); - - return DataSeg; -} - -/** - Create a iSCSI SCSI command PDU to encapsulate the command issued - by SCSI through the EXT SCSI PASS THRU Protocol. - - @param[in] Packet The EXT SCSI PASS THRU request packet containing the = SCSI command. - @param[in] Lun The LUN. - @param[in] Tcb The tcb associated with this SCSI command. - - @return The created iSCSI SCSI command PDU. - @retval NULL Other errors as indicated. -**/ -NET_BUF * -IScsiNewScsiCmdPdu ( - IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, - IN UINT64 Lun, - IN ISCSI_TCB *Tcb - ) -{ - LIST_ENTRY *NbufList; - NET_BUF *Pdu; - NET_BUF *PduHeader; - NET_BUF *DataSeg; - SCSI_COMMAND *ScsiCmd; - UINT8 AHSLength; - UINT32 Length; - ISCSI_ADDITIONAL_HEADER *Header; - ISCSI_BI_EXP_READ_DATA_LEN_AHS *BiExpReadDataLenAHS; - ISCSI_SESSION *Session; - UINT32 ImmediateDataLen; - - AHSLength =3D 0; - - if (Packet->DataDirection =3D=3D DataBi) { - // - // Bi directional Read/Write command, the bidirectional expected - // read data length AHS is required. - // - AHSLength +=3D sizeof (ISCSI_BI_EXP_READ_DATA_LEN_AHS); - } - - if (Packet->CdbLength > 16) { - // - // The CDB exceeds 16 bytes, an extended CDB AHS is required. - // - AHSLength =3D (UINT8) (AHSLength + (ISCSI_ROUNDUP (Packet->CdbLength -= 16) + sizeof (ISCSI_ADDITIONAL_HEADER))); - } - - Length =3D sizeof (SCSI_COMMAND) + AHSLength; - PduHeader =3D NetbufAlloc (Length); - if (PduHeader =3D=3D NULL) { - return NULL; - } - - ScsiCmd =3D (SCSI_COMMAND *) NetbufAllocSpace (PduHeader, Length, NET_BU= F_TAIL); - if (ScsiCmd =3D=3D NULL) { - NetbufFree (PduHeader); - return NULL; - } - Header =3D (ISCSI_ADDITIONAL_HEADER *) (ScsiCmd + 1); - - ZeroMem (ScsiCmd, Length); - - ISCSI_SET_OPCODE (ScsiCmd, ISCSI_OPCODE_SCSI_CMD, 0); - ISCSI_SET_FLAG (ScsiCmd, ISCSI_TASK_ATTR_SIMPLE); - - // - // Set the READ/WRITE flags according to the IO type of this request. - // - switch (Packet->DataDirection) { - case DataIn: - ISCSI_SET_FLAG (ScsiCmd, SCSI_CMD_PDU_FLAG_READ); - ScsiCmd->ExpDataXferLength =3D NTOHL (Packet->InTransferLength); - break; - - case DataOut: - ISCSI_SET_FLAG (ScsiCmd, SCSI_CMD_PDU_FLAG_WRITE); - ScsiCmd->ExpDataXferLength =3D NTOHL (Packet->OutTransferLength); - break; - - case DataBi: - ISCSI_SET_FLAG (ScsiCmd, SCSI_CMD_PDU_FLAG_READ | SCSI_CMD_PDU_FLAG_WR= ITE); - ScsiCmd->ExpDataXferLength =3D NTOHL (Packet->OutTransferLength); - - // - // Fill the bidirectional expected read data length AHS. - // - BiExpReadDataLenAHS =3D (ISCSI_BI_EXP_READ_DATA_LE= N_AHS *) Header; - Header =3D (ISCSI_ADDITIONAL_HEADER *) (BiExpReadDataLenAHS + 1); - - BiExpReadDataLenAHS->Length =3D NTOHS (5); - BiExpReadDataLenAHS->Type =3D ISCSI_AHS_TYPE_BI_EXP_READ_DATA_LEN; - BiExpReadDataLenAHS->ExpReadDataLength =3D NTOHL (Packet->InTransferLe= ngth); - - break; - } - - ScsiCmd->TotalAHSLength =3D AHSLength; - CopyMem (ScsiCmd->Lun, &Lun, sizeof (ScsiCmd->Lun)); - ScsiCmd->InitiatorTaskTag =3D NTOHL (Tcb->InitiatorTaskTag); - ScsiCmd->CmdSN =3D NTOHL (Tcb->CmdSN); - ScsiCmd->ExpStatSN =3D NTOHL (Tcb->Conn->ExpStatSN); - - CopyMem (ScsiCmd->Cdb, Packet->Cdb, sizeof (ScsiCmd->Cdb)); - - if (Packet->CdbLength > 16) { - Header->Length =3D NTOHS ((UINT16) (Packet->CdbLength - 15)); - Header->Type =3D ISCSI_AHS_TYPE_EXT_CDB; - - CopyMem (Header + 1, (UINT8 *) Packet->Cdb + 16, Packet->CdbLength - 1= 6); - } - - Pdu =3D PduHeader; - Session =3D Tcb->Conn->Session; - ImmediateDataLen =3D 0; - - if (Session->ImmediateData && (Packet->OutTransferLength !=3D 0)) { - // - // Send immediate data in this SCSI Command PDU. The length of the imm= eidate - // data is the minimum of FirstBurstLength, the data length to be xfer= ed and - // the MaxRecvdataSegmentLength on this connection. - // - ImmediateDataLen =3D MIN (Session->FirstBurstLength, Packet->OutTrans= ferLength); - ImmediateDataLen =3D MIN (ImmediateDataLen, Tcb->Conn->MaxRecvDataSeg= mentLength); - - // - // Update the data segment length in the PDU header. - // - ISCSI_SET_DATASEG_LEN (ScsiCmd, ImmediateDataLen); - - // - // Create the data segment. - // - DataSeg =3D IScsiNewDataSegment ((UINT8 *) Packet->OutDataBuffer, Imme= diateDataLen, FALSE); - if (DataSeg =3D=3D NULL) { - NetbufFree (PduHeader); - Pdu =3D NULL; - goto ON_EXIT; - } - - NbufList =3D AllocatePool (sizeof (LIST_ENTRY)); - if (NbufList =3D=3D NULL) { - NetbufFree (PduHeader); - NetbufFree (DataSeg); - - Pdu =3D NULL; - goto ON_EXIT; - } - - InitializeListHead (NbufList); - InsertTailList (NbufList, &PduHeader->List); - InsertTailList (NbufList, &DataSeg->List); - - Pdu =3D NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufList= ); - if (Pdu =3D=3D NULL) { - IScsiFreeNbufList (NbufList); - } - } - - if (Session->InitialR2T || - (ImmediateDataLen =3D=3D Session->FirstBurstLength) || - (ImmediateDataLen =3D=3D Packet->OutTransferLength) - ) { - // - // Unsolicited data out sequence is not allowed, - // or FirstBurstLength data is already sent out by immediate data - // or all the OUT data accompany this SCSI packet is sent as - // immediate data, the final flag should be set on this SCSI Command - // PDU. - // - ISCSI_SET_FLAG (ScsiCmd, ISCSI_BHS_FLAG_FINAL); - } - -ON_EXIT: - - return Pdu; -} - -/** - Create a new iSCSI SCSI Data Out PDU. - - @param[in] Data The data to put into the Data Out PDU. - @param[in] Len Length of the data. - @param[in] DataSN The DataSN of the Data Out PDU. - @param[in] Tcb The task control block of this Data Out PDU. - @param[in] Lun The LUN. - - @return The net buffer wrapping the Data Out PDU. - @retval NULL Other errors as indicated. -**/ -NET_BUF * -IScsiNewDataOutPdu ( - IN UINT8 *Data, - IN UINT32 Len, - IN UINT32 DataSN, - IN ISCSI_TCB *Tcb, - IN UINT64 Lun - ) -{ - LIST_ENTRY *NbufList; - NET_BUF *PduHdr; - NET_BUF *DataSeg; - NET_BUF *Pdu; - ISCSI_SCSI_DATA_OUT *DataOutHdr; - ISCSI_XFER_CONTEXT *XferContext; - - NbufList =3D AllocatePool (sizeof (LIST_ENTRY)); - if (NbufList =3D=3D NULL) { - return NULL; - } - - InitializeListHead (NbufList); - - // - // Allocate memory for the BHS. - // - PduHdr =3D NetbufAlloc (sizeof (ISCSI_SCSI_DATA_OUT)); - if (PduHdr =3D=3D NULL) { - FreePool (NbufList); - return NULL; - } - // - // Insert the BHS into the buffer list. - // - InsertTailList (NbufList, &PduHdr->List); - - DataOutHdr =3D (ISCSI_SCSI_DATA_OUT *) NetbufAllocSpace (PduHdr, sizeof= (ISCSI_SCSI_DATA_OUT), NET_BUF_TAIL); - ASSERT (DataOutHdr !=3D NULL); - XferContext =3D &Tcb->XferContext; - - ZeroMem (DataOutHdr, sizeof (ISCSI_SCSI_DATA_OUT)); - - // - // Set the flags and fields of the Data Out PDU BHS. - // - ISCSI_SET_OPCODE (DataOutHdr, ISCSI_OPCODE_SCSI_DATA_OUT, 0); - ISCSI_SET_DATASEG_LEN (DataOutHdr, Len); - - DataOutHdr->InitiatorTaskTag =3D HTONL (Tcb->InitiatorTaskTag); - DataOutHdr->TargetTransferTag =3D HTONL (XferContext->TargetTransferTag)= ; - DataOutHdr->ExpStatSN =3D HTONL (Tcb->Conn->ExpStatSN); - DataOutHdr->DataSN =3D HTONL (DataSN); - DataOutHdr->BufferOffset =3D HTONL (XferContext->Offset); - - if (XferContext->TargetTransferTag !=3D ISCSI_RESERVED_TAG) { - CopyMem (&DataOutHdr->Lun, &Lun, sizeof (DataOutHdr->Lun)); - } - // - // Build the data segment for this Data Out PDU. - // - DataSeg =3D IScsiNewDataSegment (Data, Len, FALSE); - if (DataSeg =3D=3D NULL) { - IScsiFreeNbufList (NbufList); - return NULL; - } - // - // Put the data segment into the buffer list and combine it with the BHS - // into a full Data Out PDU. - // - InsertTailList (NbufList, &DataSeg->List); - Pdu =3D NetbufFromBufList (NbufList, 0, 0, IScsiFreeNbufList, NbufList); - if (Pdu =3D=3D NULL) { - IScsiFreeNbufList (NbufList); - } - - return Pdu; -} - -/** - Generate a consecutive sequence of iSCSI SCSI Data Out PDUs. - - @param[in] Data The data which will be carried by the sequence of iSCS= I SCSI Data Out PDUs. - @param[in] Tcb The task control block of the data to send out. - @param[in] Lun The LUN the data will be sent to. - - @return A list of net buffers with each of them wraps an iSCSI SCSI Data= Out PDU. - @retval NULL Other errors as indicated. -**/ -LIST_ENTRY * -IScsiGenerateDataOutPduSequence ( - IN UINT8 *Data, - IN ISCSI_TCB *Tcb, - IN UINT64 Lun - ) -{ - LIST_ENTRY *PduList; - UINT32 DataSN; - UINT32 DataLen; - NET_BUF *DataOutPdu; - ISCSI_CONNECTION *Conn; - ISCSI_XFER_CONTEXT *XferContext; - UINT8 *DataOutPacket; - - PduList =3D AllocatePool (sizeof (LIST_ENTRY)); - if (PduList =3D=3D NULL) { - return NULL; - } - - InitializeListHead (PduList); - - DataSN =3D 0; - Conn =3D Tcb->Conn; - DataOutPdu =3D NULL; - XferContext =3D &Tcb->XferContext; - - while (XferContext->DesiredLength > 0) { - // - // Determine the length of data this Data Out PDU can carry. - // - DataLen =3D MIN (XferContext->DesiredLength, Conn->MaxRecvDataSegmentL= ength); - - // - // Create a Data Out PDU. - // - DataOutPdu =3D IScsiNewDataOutPdu (Data, DataLen, DataSN, Tcb, Lun); - if (DataOutPdu =3D=3D NULL) { - IScsiFreeNbufList (PduList); - PduList =3D NULL; - - goto ON_EXIT; - } - - InsertTailList (PduList, &DataOutPdu->List); - - // - // Update the context and DataSN. - // - XferContext->Offset +=3D DataLen; - XferContext->DesiredLength -=3D DataLen; - DataSN++; - Data +=3D DataLen; - } - // - // Set the F bit for the last data out PDU in this sequence. - // - DataOutPacket =3D NetbufGetByte (DataOutPdu, 0, NULL); - if (DataOutPacket =3D=3D NULL) { - IScsiFreeNbufList (PduList); - PduList =3D NULL; - goto ON_EXIT; - } - - ISCSI_SET_FLAG (DataOutPacket, ISCSI_BHS_FLAG_FINAL); - -ON_EXIT: - - return PduList; -} - -/** - Send the Data in a sequence of Data Out PDUs one by one. - - @param[in] Data The data to carry by Data Out PDUs. - @param[in] Lun The LUN the data will be sent to. - @param[in] Tcb The task control block. - - @retval EFI_SUCCES The data is sent out to the LUN. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiSendDataOutPduSequence ( - IN UINT8 *Data, - IN UINT64 Lun, - IN ISCSI_TCB *Tcb - ) -{ - LIST_ENTRY *DataOutPduList; - LIST_ENTRY *Entry; - NET_BUF *Pdu; - EFI_STATUS Status; - - // - // Generate the Data Out PDU sequence. - // - DataOutPduList =3D IScsiGenerateDataOutPduSequence (Data, Tcb, Lun); - if (DataOutPduList =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status =3D EFI_SUCCESS; - - // - // Send the Data Out PDU's one by one. - // - NET_LIST_FOR_EACH (Entry, DataOutPduList) { - Pdu =3D NET_LIST_USER_STRUCT (Entry, NET_BUF, List); - - Status =3D Tcp4IoTransmit (&Tcb->Conn->Tcp4Io, Pdu); - if (EFI_ERROR (Status)) { - break; - } - } - - IScsiFreeNbufList (DataOutPduList); - - return Status; -} - -/** - Process the received iSCSI SCSI Data In PDU. - - @param[in] Pdu The Data In PDU received. - @param[in] Tcb The task control block. - @param[in, out] Packet The EXT SCSI PASS THRU request packet. - - @retval EFI_SUCCES The check on the Data IN PDU is passed and = some update - actions are taken. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened= . - @retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the = request. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiOnDataInRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -{ - ISCSI_SCSI_DATA_IN *DataInHdr; - EFI_STATUS Status; - - DataInHdr =3D (ISCSI_SCSI_DATA_IN *) NetbufGetByte (Pd= u, 0, NULL); - if (DataInHdr =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - - DataInHdr->InitiatorTaskTag =3D NTOHL (DataInHdr->InitiatorTaskTag); - DataInHdr->ExpCmdSN =3D NTOHL (DataInHdr->ExpCmdSN); - DataInHdr->MaxCmdSN =3D NTOHL (DataInHdr->MaxCmdSN); - DataInHdr->DataSN =3D NTOHL (DataInHdr->DataSN); - - // - // Check the DataSN. - // - Status =3D IScsiCheckSN (&Tcb->ExpDataSN, DataInHdr->DataSN); - if (EFI_ERROR (Status)) { - return Status; - } - - if (DataInHdr->InitiatorTaskTag !=3D Tcb->InitiatorTaskTag) { - return EFI_PROTOCOL_ERROR; - } - // - // Update the command related sequence numbers. - // - IScsiUpdateCmdSN (Tcb->Conn->Session, DataInHdr->MaxCmdSN, DataInHdr->Ex= pCmdSN); - - if (ISCSI_FLAG_ON (DataInHdr, SCSI_DATA_IN_PDU_FLAG_STATUS_VALID)) { - if (!ISCSI_FLAG_ON (DataInHdr, ISCSI_BHS_FLAG_FINAL)) { - // - // The S bit is on but the F bit is off. - // - return EFI_PROTOCOL_ERROR; - } - - Tcb->StatusXferd =3D TRUE; - - if (ISCSI_FLAG_ON (DataInHdr, SCSI_DATA_IN_PDU_FLAG_OVERFLOW | SCSI_DA= TA_IN_PDU_FLAG_UNDERFLOW)) { - // - // Underflow and Overflow are mutual flags. - // - return EFI_PROTOCOL_ERROR; - } - // - // S bit is on, the StatSN is valid. - // - Status =3D IScsiCheckSN (&Tcb->Conn->ExpStatSN, NTOHL (DataInHdr->Stat= SN)); - if (EFI_ERROR (Status)) { - return Status; - } - - Packet->HostAdapterStatus =3D 0; - Packet->TargetStatus =3D DataInHdr->Status; - - if (ISCSI_FLAG_ON (DataInHdr, SCSI_RSP_PDU_FLAG_OVERFLOW)) { - Packet->InTransferLength +=3D NTOHL (DataInHdr->ResidualCount); - Status =3D EFI_BAD_BUFFER_SIZE; - } - - if (ISCSI_FLAG_ON (DataInHdr, SCSI_RSP_PDU_FLAG_UNDERFLOW)) { - Packet->InTransferLength -=3D NTOHL (DataInHdr->ResidualCount); - } - } - - return Status; -} - -/** - Process the received iSCSI R2T PDU. - - @param[in] Pdu The R2T PDU received. - @param[in] Tcb The task control block. - @param[in] Lun The Lun. - @param[in, out] Packet The EXT SCSI PASS THRU request packet. - - @retval EFI_SUCCES The R2T PDU is valid and the solicited data i= s sent out. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiOnR2TRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb, - IN UINT64 Lun, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -{ - ISCSI_READY_TO_TRANSFER *R2THdr; - EFI_STATUS Status; - ISCSI_XFER_CONTEXT *XferContext; - UINT8 *Data; - - R2THdr =3D (ISCSI_READY_TO_TRANSFER *) NetbufGetByte (Pdu, 0, NULL); - if (R2THdr =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - - R2THdr->InitiatorTaskTag =3D NTOHL (R2THdr->InitiatorTaskTag); - R2THdr->TargetTransferTag =3D NTOHL (R2THdr->TargetTransferTag); - R2THdr->StatSN =3D NTOHL (R2THdr->StatSN); - R2THdr->R2TSeqNum =3D NTOHL (R2THdr->R2TSeqNum); - R2THdr->BufferOffset =3D NTOHL (R2THdr->BufferOffset); - R2THdr->DesiredDataTransferLength =3D NTOHL (R2THdr->DesiredDataTransfer= Length); - - if ((R2THdr->InitiatorTaskTag !=3D Tcb->InitiatorTaskTag) || !ISCSI_SEQ_= EQ (R2THdr->StatSN, Tcb->Conn->ExpStatSN)) { - return EFI_PROTOCOL_ERROR;; - } - // - // Check the sequence number. - // - Status =3D IScsiCheckSN (&Tcb->ExpDataSN, R2THdr->R2TSeqNum); - if (EFI_ERROR (Status)) { - return Status; - } - - XferContext =3D &Tcb->XferContext; - XferContext->TargetTransferTag =3D R2THdr->TargetTransferTag; - XferContext->Offset =3D R2THdr->BufferOffset; - XferContext->DesiredLength =3D R2THdr->DesiredDataTransferLength; - - if (((XferContext->Offset + XferContext->DesiredLength) > Packet->OutTra= nsferLength) || - (XferContext->DesiredLength > Tcb->Conn->Session->MaxBurstLength) - ) { - return EFI_PROTOCOL_ERROR; - } - // - // Send the data solicited by this R2T. - // - Data =3D (UINT8 *) Packet->OutDataBuffer + XferContext->Offset; - Status =3D IScsiSendDataOutPduSequence (Data, Lun, Tcb); - - return Status; -} - -/** - Process the received iSCSI SCSI Response PDU. - - @param[in] Pdu The Response PDU received. - @param[in] Tcb The task control block. - @param[in, out] Packet The EXT SCSI PASS THRU request packet. - - @retval EFI_SUCCES The Response PDU is processed. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. - @retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the = request. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiOnScsiRspRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -{ - SCSI_RESPONSE *ScsiRspHdr; - ISCSI_SENSE_DATA *SenseData; - EFI_STATUS Status; - UINT32 DataSegLen; - - ScsiRspHdr =3D (SCSI_RESPONSE *) NetbufGetByte (Pdu, = 0, NULL); - if (ScsiRspHdr =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - - ScsiRspHdr->InitiatorTaskTag =3D NTOHL (ScsiRspHdr->InitiatorTaskTag); - if (ScsiRspHdr->InitiatorTaskTag !=3D Tcb->InitiatorTaskTag) { - return EFI_PROTOCOL_ERROR; - } - - ScsiRspHdr->StatSN =3D NTOHL (ScsiRspHdr->StatSN); - - Status =3D IScsiCheckSN (&Tcb->Conn->ExpStatSN, ScsiRspHdr-= >StatSN); - if (EFI_ERROR (Status)) { - return Status; - } - - ScsiRspHdr->MaxCmdSN =3D NTOHL (ScsiRspHdr->MaxCmdSN); - ScsiRspHdr->ExpCmdSN =3D NTOHL (ScsiRspHdr->ExpCmdSN); - IScsiUpdateCmdSN (Tcb->Conn->Session, ScsiRspHdr->MaxCmdSN, ScsiRspHdr->= ExpCmdSN); - - Tcb->StatusXferd =3D TRUE; - - Packet->HostAdapterStatus =3D ScsiRspHdr->Response; - if (Packet->HostAdapterStatus !=3D ISCSI_SERVICE_RSP_COMMAND_COMPLETE_AT= _TARGET) { - return EFI_SUCCESS; - } - - Packet->TargetStatus =3D ScsiRspHdr->Status; - - if (ISCSI_FLAG_ON (ScsiRspHdr, SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW | SCSI= _RSP_PDU_FLAG_BI_READ_UNDERFLOW) || - ISCSI_FLAG_ON (ScsiRspHdr, SCSI_RSP_PDU_FLAG_OVERFLOW | SCSI_RSP_PDU= _FLAG_UNDERFLOW) - ) { - return EFI_PROTOCOL_ERROR; - } - - if (ISCSI_FLAG_ON (ScsiRspHdr, SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW)) { - Packet->InTransferLength +=3D NTOHL (ScsiRspHdr->BiReadResidualCount); - Status =3D EFI_BAD_BUFFER_SIZE; - } - - if (ISCSI_FLAG_ON (ScsiRspHdr, SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW)) { - Packet->InTransferLength -=3D NTOHL (ScsiRspHdr->BiReadResidualCount); - } - - if (ISCSI_FLAG_ON (ScsiRspHdr, SCSI_RSP_PDU_FLAG_OVERFLOW)) { - if (Packet->DataDirection =3D=3D DataIn) { - Packet->InTransferLength +=3D NTOHL (ScsiRspHdr->ResidualCount); - } else { - Packet->OutTransferLength +=3D NTOHL (ScsiRspHdr->ResidualCount); - } - - Status =3D EFI_BAD_BUFFER_SIZE; - } - - if (ISCSI_FLAG_ON (ScsiRspHdr, SCSI_RSP_PDU_FLAG_UNDERFLOW)) { - if (Packet->DataDirection =3D=3D DataIn) { - Packet->InTransferLength -=3D NTOHL (ScsiRspHdr->ResidualCount); - } else { - Packet->OutTransferLength -=3D NTOHL (ScsiRspHdr->ResidualCount); - } - } - - DataSegLen =3D ISCSI_GET_DATASEG_LEN (ScsiRspHdr); - if (DataSegLen !=3D 0) { - SenseData =3D (ISCSI_SENSE_DATA *) NetbufGetByte (Pdu, s= izeof (SCSI_RESPONSE), NULL); - if (SenseData =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - - SenseData->Length =3D NTOHS (SenseData->Length); - - Packet->SenseDataLength =3D (UINT8) MIN (SenseData->Length, Packet->Se= nseDataLength); - if (Packet->SenseDataLength !=3D 0) { - CopyMem (Packet->SenseData, &SenseData->Data[0], Packet->SenseDataLe= ngth); - } - } else { - Packet->SenseDataLength =3D 0; - } - - return Status; -} - -/** - Process the received NOP In PDU. - - @param[in] Pdu The NOP In PDU received. - @param[in] Tcb The task control block. - - @retval EFI_SUCCES The NOP In PDU is processed and the related s= equence - numbers are updated. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol errror happened. -**/ -EFI_STATUS -IScsiOnNopInRcvd ( - IN NET_BUF *Pdu, - IN ISCSI_TCB *Tcb - ) -{ - ISCSI_NOP_IN *NopInHdr; - EFI_STATUS Status; - - NopInHdr =3D (ISCSI_NOP_IN *) NetbufGetByte (Pdu, 0, NULL); - if (NopInHdr =3D=3D NULL) { - return EFI_PROTOCOL_ERROR; - } - - NopInHdr->StatSN =3D NTOHL (NopInHdr->StatSN); - NopInHdr->ExpCmdSN =3D NTOHL (NopInHdr->ExpCmdSN); - NopInHdr->MaxCmdSN =3D NTOHL (NopInHdr->MaxCmdSN); - - if (NopInHdr->InitiatorTaskTag =3D=3D ISCSI_RESERVED_TAG) { - if (NopInHdr->StatSN !=3D Tcb->Conn->ExpStatSN) { - return EFI_PROTOCOL_ERROR; - } - } else { - Status =3D IScsiCheckSN (&Tcb->Conn->ExpStatSN, NopInHdr->StatSN); - if (EFI_ERROR (Status)) { - return Status; - } - } - - IScsiUpdateCmdSN (Tcb->Conn->Session, NopInHdr->MaxCmdSN, NopInHdr->ExpC= mdSN); - - return EFI_SUCCESS; -} - -/** - Execute the SCSI command issued through the EXT SCSI PASS THRU protocol. - - @param[in] PassThru The EXT SCSI PASS THRU protocol. - @param[in] Target The target ID. - @param[in] Lun The LUN. - @param[in, out] Packet The request packet containing IO request, SCS= I command - buffer and buffers to read/write. - - @retval EFI_SUCCES The SCSI command is executed and the result= is updated to - the Packet. - @retval EFI_DEVICE_ERROR Session state was not as required. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NOT_READY The target can not accept new commands. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiExecuteScsiCommand ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru, - IN UINT8 *Target, - IN UINT64 Lun, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ) -{ - EFI_STATUS Status; - ISCSI_DRIVER_DATA *Private; - ISCSI_SESSION *Session; - EFI_EVENT TimeoutEvent; - ISCSI_CONNECTION *Conn; - ISCSI_TCB *Tcb; - NET_BUF *Pdu; - ISCSI_XFER_CONTEXT *XferContext; - UINT8 *Data; - ISCSI_IN_BUFFER_CONTEXT InBufferContext; - UINT64 Timeout; - UINT8 *PduHdr; - - Private =3D ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru); - Session =3D &Private->Session; - Status =3D EFI_SUCCESS; - Tcb =3D NULL; - TimeoutEvent =3D NULL; - Timeout =3D 0; - - if (Session->State !=3D SESSION_STATE_LOGGED_IN) { - Status =3D EFI_DEVICE_ERROR; - goto ON_EXIT; - } - - Conn =3D NET_LIST_USER_STRUCT_S ( - Session->Conns.ForwardLink, - ISCSI_CONNECTION, - Link, - ISCSI_CONNECTION_SIGNATURE - ); - - if (Packet->Timeout !=3D 0) { - Timeout =3D MultU64x32 (Packet->Timeout, 2); - } - - Status =3D IScsiNewTcb (Conn, &Tcb); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - // - // Encapsulate the SCSI request packet into an iSCSI SCSI Command PDU. - // - Pdu =3D IScsiNewScsiCmdPdu (Packet, Lun, Tcb); - if (Pdu =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - XferContext =3D &Tcb->XferContext; - PduHdr =3D NetbufGetByte (Pdu, 0, NULL); - if (PduHdr =3D=3D NULL) { - Status =3D EFI_PROTOCOL_ERROR; - NetbufFree (Pdu); - goto ON_EXIT; - } - XferContext->Offset =3D ISCSI_GET_DATASEG_LEN (PduHdr); - - // - // Transmit the SCSI Command PDU. - // - Status =3D Tcp4IoTransmit (&Conn->Tcp4Io, Pdu); - - NetbufFree (Pdu); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - if (!Session->InitialR2T && - (XferContext->Offset < Session->FirstBurstLength) && - (XferContext->Offset < Packet->OutTransferLength) - ) { - // - // Unsolicited Data-Out sequence is allowed, there is remaining SCSI - // OUT data and the limit of FirstBurstLength is not reached. - // - XferContext->TargetTransferTag =3D ISCSI_RESERVED_TAG; - XferContext->DesiredLength =3D MIN ( - Session->FirstBurstLength, - Packet->OutTransferLength - XferContext-= >Offset - ); - - Data =3D (UINT8 *) Packet->OutDataBuffer + XferContext->Offset; - Status =3D IScsiSendDataOutPduSequence (Data, Lun, Tcb); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } - - InBufferContext.InData =3D (UINT8 *) Packet->InDataBuffer; - InBufferContext.InDataLen =3D Packet->InTransferLength; - - while (!Tcb->StatusXferd) { - // - // Start the timeout timer. - // - if (Timeout !=3D 0) { - Status =3D gBS->SetTimer (Conn->TimeoutEvent, TimerRelative, Timeout= ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - TimeoutEvent =3D Conn->TimeoutEvent; - } - // - // try to receive PDU from target. - // - Status =3D IScsiReceivePdu (Conn, &Pdu, &InBufferContext, FALSE, FALSE= , TimeoutEvent); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - PduHdr =3D NetbufGetByte (Pdu, 0, NULL); - if (PduHdr =3D=3D NULL) { - Status =3D EFI_PROTOCOL_ERROR; - NetbufFree (Pdu); - goto ON_EXIT; - } - switch (ISCSI_GET_OPCODE (PduHdr)) { - case ISCSI_OPCODE_SCSI_DATA_IN: - Status =3D IScsiOnDataInRcvd (Pdu, Tcb, Packet); - break; - - case ISCSI_OPCODE_R2T: - Status =3D IScsiOnR2TRcvd (Pdu, Tcb, Lun, Packet); - break; - - case ISCSI_OPCODE_SCSI_RSP: - Status =3D IScsiOnScsiRspRcvd (Pdu, Tcb, Packet); - break; - - case ISCSI_OPCODE_NOP_IN: - Status =3D IScsiOnNopInRcvd (Pdu, Tcb); - break; - - case ISCSI_OPCODE_VENDOR_T0: - case ISCSI_OPCODE_VENDOR_T1: - case ISCSI_OPCODE_VENDOR_T2: - // - // These messages are vendor specific, skip them. - // - break; - - default: - Status =3D EFI_PROTOCOL_ERROR; - break; - } - - NetbufFree (Pdu); - - if (EFI_ERROR (Status)) { - break; - } - } - -ON_EXIT: - - if (TimeoutEvent !=3D NULL) { - gBS->SetTimer (TimeoutEvent, TimerCancel, 0); - } - - if (Tcb !=3D NULL) { - IScsiDelTcb (Tcb); - } - - return Status; -} - -/** - Reinstate the session on some error. - - @param[in, out] Private The iSCSI driver data. - - @retval EFI_SUCCES The session is reinstated from some error. - @retval Other Reinstatement failed. -**/ -EFI_STATUS -IScsiSessionReinstatement ( - IN OUT ISCSI_DRIVER_DATA *Private - ) -{ - ISCSI_SESSION *Session; - EFI_STATUS Status; - - Session =3D &Private->Session; - ASSERT (Session->State !=3D SESSION_STATE_FREE); - - // - // Abort the session and re-init it. - // - IScsiSessionAbort (Session); - IScsiSessionInit (Session, TRUE); - - // - // Login again. - // - Status =3D IScsiSessionLogin (Private); - - return Status; -} - -/** - Initialize some session parameters before login. - - @param[in, out] Session The iSCSI session. - @param[in] Recovery Whether the request is from a fresh new start = or recovery. -**/ -VOID -IScsiSessionInit ( - IN OUT ISCSI_SESSION *Session, - IN BOOLEAN Recovery - ) -{ - if (!Recovery) { - Session->Signature =3D ISCSI_SESSION_SIGNATURE; - Session->State =3D SESSION_STATE_FREE; - - InitializeListHead (&Session->Conns); - InitializeListHead (&Session->TcbList); - } - - Session->Tsih =3D 0; - - Session->CmdSN =3D 1; - Session->InitiatorTaskTag =3D 1; - Session->NextCid =3D 1; - - Session->TargetPortalGroupTag =3D 0; - Session->MaxConnections =3D ISCSI_MAX_CONNS_PER_SESSION; - Session->InitialR2T =3D FALSE; - Session->ImmediateData =3D TRUE; - Session->MaxBurstLength =3D 262144; - Session->FirstBurstLength =3D MAX_RECV_DATA_SEG_LEN_IN_FFP; - Session->DefaultTime2Wait =3D 2; - Session->DefaultTime2Retain =3D 20; - Session->MaxOutstandingR2T =3D DEFAULT_MAX_OUTSTANDING_R2T; - Session->DataPDUInOrder =3D TRUE; - Session->DataSequenceInOrder =3D TRUE; - Session->ErrorRecoveryLevel =3D 0; -} - -/** - Abort the iSCSI session, that is, reset all the connection and free the - resources. - - @param[in, out] Session The iSCSI session. - - @retval EFI_SUCCES The session is aborted. -**/ -EFI_STATUS -IScsiSessionAbort ( - IN OUT ISCSI_SESSION *Session - ) -{ - ISCSI_DRIVER_DATA *Private; - ISCSI_CONNECTION *Conn; - - if (Session->State !=3D SESSION_STATE_LOGGED_IN) { - return EFI_SUCCESS; - } - - ASSERT (!IsListEmpty (&Session->Conns)); - - Private =3D ISCSI_DRIVER_DATA_FROM_SESSION (Session); - - while (!IsListEmpty (&Session->Conns)) { - Conn =3D NET_LIST_USER_STRUCT_S ( - Session->Conns.ForwardLink, - ISCSI_CONNECTION, - Link, - ISCSI_CONNECTION_SIGNATURE - ); - - gBS->CloseProtocol ( - Conn->Tcp4Io.Handle, - &gEfiTcp4ProtocolGuid, - Private->Image, - Private->ExtScsiPassThruHandle - ); - - IScsiConnReset (Conn); - - IScsiDetatchConnection (Conn); - IScsiDestroyConnection (Conn); - } - - Session->State =3D SESSION_STATE_FAILED; - - return EFI_SUCCESS; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.c b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.c deleted file mode 100644 index 901b38e92fc0..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.c +++ /dev/null @@ -1,487 +0,0 @@ -/** @file - The wrap of TCP/IP Socket interface. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "IScsiImpl.h" - -/** - The common notify function associated with various Tcp4Io events. - - @param[in] Event The event signaled. - @param[in] Context The context. -**/ -VOID -EFIAPI -Tcp4IoCommonNotify ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - *((BOOLEAN *) Context) =3D TRUE; -} - -/** - Create a TCP socket with the specified configuration data. - - @param[in] Image The handle of the driver image. - @param[in] Controller The handle of the controller. - @param[in] ConfigData The Tcp4 configuration data. - @param[in] Tcp4Io The Tcp4Io. - - @retval EFI_SUCCESS The TCP socket is created and configured. - @retval Others Failed to create the TCP socket or configure it. -**/ -EFI_STATUS -Tcp4IoCreateSocket ( - IN EFI_HANDLE Image, - IN EFI_HANDLE Controller, - IN TCP4_IO_CONFIG_DATA *ConfigData, - IN TCP4_IO *Tcp4Io - ) -{ - EFI_STATUS Status; - EFI_TCP4_PROTOCOL *Tcp4; - EFI_TCP4_CONFIG_DATA Tcp4ConfigData; - EFI_TCP4_OPTION ControlOption; - EFI_TCP4_ACCESS_POINT *AccessPoint; - - Tcp4Io->Handle =3D NULL; - Tcp4Io->ConnToken.CompletionToken.Event =3D NULL; - Tcp4Io->TxToken.CompletionToken.Event =3D NULL; - Tcp4Io->RxToken.CompletionToken.Event =3D NULL; - Tcp4Io->CloseToken.CompletionToken.Event =3D NULL; - Tcp4 =3D NULL; - - // - // Create the TCP4 child instance and get the TCP4 protocol. - // - Status =3D NetLibCreateServiceChild ( - Controller, - Image, - &gEfiTcp4ServiceBindingProtocolGuid, - &Tcp4Io->Handle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->OpenProtocol ( - Tcp4Io->Handle, - &gEfiTcp4ProtocolGuid, - (VOID **)&Tcp4Io->Tcp4, - Image, - Controller, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Tcp4Io->Image =3D Image; - Tcp4Io->Controller =3D Controller; - Tcp4 =3D Tcp4Io->Tcp4; - - // - // Set the configuration parameters. - // - ControlOption.ReceiveBufferSize =3D 0x200000; - ControlOption.SendBufferSize =3D 0x200000; - ControlOption.MaxSynBackLog =3D 0; - ControlOption.ConnectionTimeout =3D 0; - ControlOption.DataRetries =3D 6; - ControlOption.FinTimeout =3D 0; - ControlOption.TimeWaitTimeout =3D 0; - ControlOption.KeepAliveProbes =3D 4; - ControlOption.KeepAliveTime =3D 0; - ControlOption.KeepAliveInterval =3D 0; - ControlOption.EnableNagle =3D FALSE; - ControlOption.EnableTimeStamp =3D FALSE; - ControlOption.EnableWindowScaling =3D TRUE; - ControlOption.EnableSelectiveAck =3D FALSE; - ControlOption.EnablePathMtuDiscovery =3D FALSE; - - Tcp4ConfigData.TypeOfService =3D 8; - Tcp4ConfigData.TimeToLive =3D 255; - Tcp4ConfigData.ControlOption =3D &ControlOption; - - AccessPoint =3D &Tcp4ConfigData.AccessPoint; - - AccessPoint->UseDefaultAddress =3D FALSE; - AccessPoint->StationPort =3D 0; - AccessPoint->RemotePort =3D ConfigData->RemotePort; - AccessPoint->ActiveFlag =3D TRUE; - - CopyMem (&AccessPoint->StationAddress, &ConfigData->LocalIp, sizeof (EFI= _IPv4_ADDRESS)); - CopyMem (&AccessPoint->SubnetMask, &ConfigData->SubnetMask, sizeof (EFI_= IPv4_ADDRESS)); - CopyMem (&AccessPoint->RemoteAddress, &ConfigData->RemoteIp, sizeof (EFI= _IPv4_ADDRESS)); - - // - // Configure the TCP4 protocol. - // - Status =3D Tcp4->Configure (Tcp4, &Tcp4ConfigData); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - if (!EFI_IP4_EQUAL (&ConfigData->Gateway, &mZeroIp4Addr)) { - // - // the gateway is not zero, add the default route by hand - // - Status =3D Tcp4->Routes (Tcp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, &C= onfigData->Gateway); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - } - // - // Create events for variuos asynchronous operations. - // - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - Tcp4IoCommonNotify, - &Tcp4Io->IsConnDone, - &Tcp4Io->ConnToken.CompletionToken.Event - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - Tcp4IoCommonNotify, - &Tcp4Io->IsTxDone, - &Tcp4Io->TxToken.CompletionToken.Event - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - Tcp4IoCommonNotify, - &Tcp4Io->IsRxDone, - &Tcp4Io->RxToken.CompletionToken.Event - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - Tcp4IoCommonNotify, - &Tcp4Io->IsCloseDone, - &Tcp4Io->CloseToken.CompletionToken.Event - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Tcp4Io->IsTxDone =3D FALSE; - Tcp4Io->IsRxDone =3D FALSE; - - return EFI_SUCCESS; - -ON_ERROR: - - if (Tcp4Io->RxToken.CompletionToken.Event !=3D NULL) { - gBS->CloseEvent (Tcp4Io->RxToken.CompletionToken.Event); - } - - if (Tcp4Io->TxToken.CompletionToken.Event !=3D NULL) { - gBS->CloseEvent (Tcp4Io->TxToken.CompletionToken.Event); - } - - if (Tcp4Io->ConnToken.CompletionToken.Event !=3D NULL) { - gBS->CloseEvent (Tcp4Io->ConnToken.CompletionToken.Event); - } - - if (Tcp4 !=3D NULL) { - Tcp4->Configure (Tcp4, NULL); - - gBS->CloseProtocol ( - Tcp4Io->Handle, - &gEfiTcp4ProtocolGuid, - Image, - Controller - ); - } - - NetLibDestroyServiceChild ( - Controller, - Image, - &gEfiTcp4ServiceBindingProtocolGuid, - Tcp4Io->Handle - ); - - return Status; -} - -/** - Destroy the socket. - - @param[in] Tcp4Io The Tcp4Io which wraps the socket to be destroyeds. -**/ -VOID -Tcp4IoDestroySocket ( - IN TCP4_IO *Tcp4Io - ) -{ - EFI_TCP4_PROTOCOL *Tcp4; - - Tcp4 =3D Tcp4Io->Tcp4; - - Tcp4->Configure (Tcp4, NULL); - - gBS->CloseEvent (Tcp4Io->TxToken.CompletionToken.Event); - gBS->CloseEvent (Tcp4Io->RxToken.CompletionToken.Event); - gBS->CloseEvent (Tcp4Io->ConnToken.CompletionToken.Event); - - gBS->CloseProtocol ( - Tcp4Io->Handle, - &gEfiTcp4ProtocolGuid, - Tcp4Io->Image, - Tcp4Io->Controller - ); - - NetLibDestroyServiceChild ( - Tcp4Io->Controller, - Tcp4Io->Image, - &gEfiTcp4ServiceBindingProtocolGuid, - Tcp4Io->Handle - ); -} - -/** - Connect to the other endpoint of the TCP socket. - - @param[in, out] Tcp4Io The Tcp4Io wrapping the TCP socket. - @param[in] Timeout The time to wait for connection done. - - @retval EFI_SUCCESS Connect to the other endpoint of the TCP so= cket successfully. - @retval EFI_TIMEOUT Failed to connect to the other endpoint of = the TCP socket in the specified time period. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -Tcp4IoConnect ( - IN OUT TCP4_IO *Tcp4Io, - IN EFI_EVENT Timeout - ) -{ - EFI_TCP4_PROTOCOL *Tcp4; - EFI_STATUS Status; - - Tcp4Io->IsConnDone =3D FALSE; - Tcp4 =3D Tcp4Io->Tcp4; - Status =3D Tcp4->Connect (Tcp4, &Tcp4Io->ConnToken); - if (EFI_ERROR (Status)) { - return Status; - } - - while (!Tcp4Io->IsConnDone && EFI_ERROR (gBS->CheckEvent (Timeout))) { - Tcp4->Poll (Tcp4); - } - - if (!Tcp4Io->IsConnDone) { - Status =3D EFI_TIMEOUT; - } else { - Status =3D Tcp4Io->ConnToken.CompletionToken.Status; - } - - return Status; -} - -/** - Reset the socket. - - @param[in, out] Tcp4Io The Tcp4Io wrapping the TCP socket. -**/ -VOID -Tcp4IoReset ( - IN OUT TCP4_IO *Tcp4Io - ) -{ - EFI_STATUS Status; - EFI_TCP4_PROTOCOL *Tcp4; - - Tcp4Io->CloseToken.AbortOnClose =3D TRUE; - Tcp4Io->IsCloseDone =3D FALSE; - - Tcp4 =3D Tcp4Io->Tcp4; - Status =3D Tcp4->Close (Tcp4, &Tcp4Io->CloseToken); - if (EFI_ERROR (Status)) { - return ; - } - - while (!Tcp4Io->IsCloseDone) { - Tcp4->Poll (Tcp4); - } -} - -/** - Transmit the Packet to the other endpoint of the socket. - - @param[in] Tcp4Io The Tcp4Io wrapping the TCP socket. - @param[in] Packet The packet to transmit. - - @retval EFI_SUCCESS The packet is trasmitted. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -Tcp4IoTransmit ( - IN TCP4_IO *Tcp4Io, - IN NET_BUF *Packet - ) -{ - EFI_TCP4_TRANSMIT_DATA *TxData; - EFI_TCP4_PROTOCOL *Tcp4; - EFI_STATUS Status; - - TxData =3D AllocatePool (sizeof (EFI_TCP4_TRANSMIT_DATA) + (Packet->Bloc= kOpNum - 1) * sizeof (EFI_TCP4_FRAGMENT_DATA)); - if (TxData =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - TxData->Push =3D TRUE; - TxData->Urgent =3D FALSE; - TxData->DataLength =3D Packet->TotalSize; - - // - // Build the fragment table. - // - TxData->FragmentCount =3D Packet->BlockOpNum; - NetbufBuildExt (Packet, (NET_FRAGMENT *) &TxData->FragmentTable[0], &TxD= ata->FragmentCount); - - Tcp4Io->TxToken.Packet.TxData =3D TxData; - - // - // Trasnmit the packet. - // - Tcp4 =3D Tcp4Io->Tcp4; - Status =3D Tcp4->Transmit (Tcp4, &Tcp4Io->TxToken); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - while (!Tcp4Io->IsTxDone) { - Tcp4->Poll (Tcp4); - } - - Tcp4Io->IsTxDone =3D FALSE; - - Status =3D Tcp4Io->TxToken.CompletionToken.Status; - -ON_EXIT: - - FreePool (TxData); - - return Status; -} - -/** - Receive data from the socket. - - @param[in] Tcp4Io The Tcp4Io which wraps the socket to be des= troyed. - @param[in] Packet The buffer to hold the data copy from the s= oket rx buffer. - @param[in] AsyncMode Is this receive asyncronous or not. - @param[in] Timeout The time to wait for receiving the amount o= f data the Packet - can hold. - - @retval EFI_SUCCESS The required amount of data is received fro= m the socket. - @retval EFI_OUT_OF_RESOURCES Failed to allocate momery. - @retval EFI_TIMEOUT Failed to receive the required amount of da= ta in the - specified time period. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -Tcp4IoReceive ( - IN TCP4_IO *Tcp4Io, - IN NET_BUF *Packet, - IN BOOLEAN AsyncMode, - IN EFI_EVENT Timeout - ) -{ - EFI_TCP4_PROTOCOL *Tcp4; - EFI_TCP4_RECEIVE_DATA RxData; - EFI_STATUS Status; - NET_FRAGMENT *Fragment; - UINT32 FragmentCount; - UINT32 CurrentFragment; - - FragmentCount =3D Packet->BlockOpNum; - Fragment =3D AllocatePool (FragmentCount * sizeof (NET_FRAGMENT)); - if (Fragment =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // Build the fragment table. - // - NetbufBuildExt (Packet, Fragment, &FragmentCount); - - RxData.FragmentCount =3D 1; - Tcp4Io->RxToken.Packet.RxData =3D &RxData; - CurrentFragment =3D 0; - Tcp4 =3D Tcp4Io->Tcp4; - Status =3D EFI_SUCCESS; - - while (CurrentFragment < FragmentCount) { - RxData.DataLength =3D Fragment[CurrentFragment].= Len; - RxData.FragmentTable[0].FragmentLength =3D Fragment[CurrentFragment].= Len; - RxData.FragmentTable[0].FragmentBuffer =3D Fragment[CurrentFragment].= Bulk; - - Status =3D Tcp4->Receive (Tcp4, &Tcp4Io->RxToken); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - while (!Tcp4Io->IsRxDone && ((Timeout =3D=3D NULL) || EFI_ERROR (gBS->= CheckEvent (Timeout)))) { - // - // Poll until some data is received or something error happens. - // - Tcp4->Poll (Tcp4); - } - - if (!Tcp4Io->IsRxDone) { - // - // Timeout occurs, cancel the receive request. - // - Tcp4->Cancel (Tcp4, &Tcp4Io->RxToken.CompletionToken); - - Status =3D EFI_TIMEOUT; - goto ON_EXIT; - } else { - Tcp4Io->IsRxDone =3D FALSE; - } - - if (EFI_ERROR (Tcp4Io->RxToken.CompletionToken.Status)) { - Status =3D Tcp4Io->RxToken.CompletionToken.Status; - goto ON_EXIT; - } - - Fragment[CurrentFragment].Len -=3D RxData.FragmentTable[0].FragmentLen= gth; - if (Fragment[CurrentFragment].Len =3D=3D 0) { - CurrentFragment++; - } else { - Fragment[CurrentFragment].Bulk +=3D RxData.FragmentTable[0].Fragment= Length; - } - } - -ON_EXIT: - Tcp4Io->RxToken.Packet.RxData =3D NULL; - FreePool (Fragment); - - return Status; -} diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/Md5.c b/MdeModulePkg/U= niversal/Network/IScsiDxe/Md5.c deleted file mode 100644 index 3555f1a2ebe3..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/Md5.c +++ /dev/null @@ -1,350 +0,0 @@ -/** @file - Implementation of MD5 algorithm. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#include "Md5.h" - -CONST UINT32 Md5_Data[][2] =3D { - { 0, 1 }, - { 1, 5 }, - { 5, 3 }, - { 0, 7 } -}; - -CONST UINT32 Md5_S[][4] =3D { - { 7, 22, 17, 12 }, - { 5, 20, 14, 9 }, - { 4, 23, 16 ,11 }, - { 6, 21, 15, 10 }, -}; - -CONST UINT32 Md5_T[] =3D { - 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, - 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, - 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, - 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, - 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, - 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, - 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, - 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, - 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, - 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, - 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, - 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, - 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, - 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, - 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, - 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 -}; - -CONST UINT8 Md5HashPadding[] =3D -{ - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -// -// ROTATE_LEFT rotates x left n bits. -// -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - -#define SA MedStates[Index2 & 3] -#define SB MedStates[(Index2 + 1) & 3] -#define SC MedStates[(Index2 + 2) & 3] -#define SD MedStates[(Index2 + 3) & 3] - -/** - Tf1 is one basic MD5 transform function. - - @param[in] A A 32-bit quantity. - @param[in] B A 32-bit quantity. - @param[in] C A 32-bit quantity. - - @return Output was produced as a 32-bit quantity based on th= e - three 32-bit input quantity. -**/ -UINT32 -Tf1 ( - IN UINT32 A, - IN UINT32 B, - IN UINT32 C - ) -{ - return (A & B) | (~A & C); -} - -/** - Tf2 is one basic MD5 transform function. - - @param[in] A A 32-bit quantity. - @param[in] B A 32-bit quantity. - @param[in] C A 32-bit quantity. - - @return Output was produced as a 32-bit quantity based on th= e - three 32-bit input quantity. -**/ -UINT32 -Tf2 ( - IN UINT32 A, - IN UINT32 B, - IN UINT32 C - ) -{ - return (A & C) | (B & ~C); -} - -/** - Tf3 is one basic MD5 transform function. - - @param[in] A A 32-bit quantity. - @param[in] B A 32-bit quantity. - @param[in] C A 32-bit quantity. - - @return Output was produced as a 32-bit quantity based on th= e - three 32-bit input quantity. -**/ -UINT32 -Tf3 ( - IN UINT32 A, - IN UINT32 B, - IN UINT32 C - ) -{ - return A ^ B ^ C; -} - -/** - Tf4 is one basic MD5 transform function. - - @param[in] A A 32-bit quantity. - @param[in] B A 32-bit quantity. - @param[in] C A 32-bit quantity. - - @return Output was produced as a 32-bit quantity based on th= e - three 32-bit input quantity. -**/ -UINT32 -Tf4 ( - IN UINT32 A, - IN UINT32 B, - IN UINT32 C - ) -{ - return B ^ (A | ~C); -} - -typedef -UINT32 -(*MD5_TRANSFORM_FUNC) ( - IN UINT32 A, - IN UINT32 B, - IN UINT32 C - ); - -CONST MD5_TRANSFORM_FUNC Md5_F[] =3D { - Tf1, - Tf2, - Tf3, - Tf4 -}; - -/** - Perform the MD5 transform on 64 bytes data segment. - - @param[in, out] Md5Ctx It includes the data segment for Md5 transform. -**/ -VOID -MD5Transform ( - IN OUT MD5_CTX *Md5Ctx - ) -{ - UINT32 Index1; - UINT32 Index2; - UINT32 MedStates[MD5_HASHSIZE >> 2]; - UINT32 *Data; - UINT32 IndexD; - UINT32 IndexT; - - Data =3D (UINT32 *) Md5Ctx->M; - - // - // Copy MD5 states to MedStates - // - CopyMem (MedStates, Md5Ctx->States, MD5_HASHSIZE); - - IndexT =3D 0; - for (Index1 =3D 0; Index1 < 4; Index1++) { - IndexD =3D Md5_Data[Index1][0]; - for (Index2 =3D 16; Index2 > 0; Index2--) { - SA +=3D (*Md5_F[Index1]) (SB, SC, SD) + Data[IndexD] + Md5_T[IndexT]= ; - SA =3D ROTATE_LEFT (SA, Md5_S[Index1][Index2 & 3]); - SA +=3D SB; - - IndexD +=3D Md5_Data[Index1][1]; - IndexD &=3D 15; - - IndexT++; - } - } - - for (Index1 =3D 0; Index1 < 4; Index1++) { - Md5Ctx->States[Index1] +=3D MedStates[Index1]; - } -} - -/** - Copy data segment into the M field of MD5_CTX structure for later transf= orm. - If the length of data segment is larger than 64 bytes, then does the tra= nsform - immediately and the generated Md5 code is stored in the States field of = MD5_CTX - data struct for later accumulation. - All of Md5 code generated for the sequential 64-bytes data segaments are= be - accumulated in MD5Final() function. - - @param[in, out] Md5Ctx The data structure of storing the original data - segment and the final result. - @param[in] Data The data wanted to be transformed. - @param[in] DataLen The length of data. -**/ -VOID -MD5UpdateBlock ( - IN OUT MD5_CTX *Md5Ctx, - IN CONST UINT8 *Data, - IN UINTN DataLen - ) -{ - UINTN Limit; - - for (Limit =3D 64 - Md5Ctx->Count; DataLen >=3D 64 - Md5Ctx->Count; Limi= t =3D 64) { - CopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, Limit); - MD5Transform (Md5Ctx); - - Md5Ctx->Count =3D 0; - Data +=3D Limit; - DataLen -=3D Limit; - } - - CopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, DataLen); - Md5Ctx->Count +=3D DataLen; -} - -/** - Initialize four 32-bits chaining variables and use them to do the Md5 tr= ansform. - - @param[out] Md5Ctx The data structure of Md5. - - @retval EFI_SUCCESS Initialization is ok. -**/ -EFI_STATUS -MD5Init ( - OUT MD5_CTX *Md5Ctx - ) -{ - ZeroMem (Md5Ctx, sizeof (*Md5Ctx)); - - // - // Set magic initialization constants. - // - Md5Ctx->States[0] =3D 0x67452301; - Md5Ctx->States[1] =3D 0xefcdab89; - Md5Ctx->States[2] =3D 0x98badcfe; - Md5Ctx->States[3] =3D 0x10325476; - - return EFI_SUCCESS; -} - -/** - the external interface of Md5 algorithm - - @param[in, out] Md5Ctx The data structure of storing the original data - segment and the final result. - @param[in] Data The data wanted to be transformed. - @param[in] DataLen The length of data. - - @retval EFI_SUCCESS The transform is ok. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -MD5Update ( - IN OUT MD5_CTX *Md5Ctx, - IN VOID *Data, - IN UINTN DataLen - ) -{ - if (EFI_ERROR (Md5Ctx->Status)) { - return Md5Ctx->Status; - } - - MD5UpdateBlock (Md5Ctx, (CONST UINT8 *) Data, DataLen); - Md5Ctx->Length +=3D DataLen; - return EFI_SUCCESS; -} - -/** - Accumulate the MD5 value of every data segment and generate the finial - result according to MD5 algorithm. - - @param[in, out] Md5Ctx The data structure of storing the original dat= a - segment and the final result. - @param[out] HashVal The final 128-bits output. - - @retval EFI_SUCCESS The transform is ok. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -MD5Final ( - IN OUT MD5_CTX *Md5Ctx, - OUT UINT8 *HashVal - ) -{ - UINTN PadLength; - - if (Md5Ctx->Status =3D=3D EFI_ALREADY_STARTED) { - // - // Store Hashed value & Zeroize sensitive context information. - // - CopyMem (HashVal, (UINT8 *) Md5Ctx->States, MD5_HASHSIZE); - ZeroMem ((UINT8 *)Md5Ctx, sizeof (*Md5Ctx)); - - return EFI_SUCCESS; - } - - if (EFI_ERROR (Md5Ctx->Status)) { - return Md5Ctx->Status; - } - - PadLength =3D Md5Ctx->Count >=3D 56 ? 120 : 56; - PadLength -=3D Md5Ctx->Count; - MD5UpdateBlock (Md5Ctx, Md5HashPadding, PadLength); - Md5Ctx->Length =3D LShiftU64 (Md5Ctx->Length, 3); - MD5UpdateBlock (Md5Ctx, (CONST UINT8 *) &Md5Ctx->Length, 8); - - ZeroMem (Md5Ctx->M, sizeof (Md5Ctx->M)); - Md5Ctx->Length =3D 0; - Md5Ctx->Status =3D EFI_ALREADY_STARTED; - return MD5Final (Md5Ctx, HashVal); -} - diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/ComponentName.c b/MdeMo= dulePkg/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 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 IMPLI= ED. - -**/ - -#include "Tcp4Main.h" - -/** - Retrieves a Unicode string that is the user readable name of the driver. - - This function retrieves the user readable name of a driver in the form o= f a - Unicode string. If the driver specified by This has a user readable name= 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 speci= fied - 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_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is the - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d - in RFC 4646 or ISO 639-2 language code for= mat. - - @param[out] DriverName A pointer to the Unicode string to return. - 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 specifie= d by - This and the language specified by Languag= e 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 supp= ort - 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 control= ler - that is being managed by a driver. - - This function retrieves the user readable name of the controller specifi= ed by - ControllerHandle and ChildHandle in the form of a Unicode string. If the - driver specified by This has a user readable name in the language specif= ied by - Language, then a pointer to the controller name is returned in Controlle= rName, - and EFI_SUCCESS is returned. If the driver specified by This is not cur= rently - managing the controller specified by ControllerHandle and ChildHandle, - then EFI_UNSUPPORTED is returned. If the driver specified by This does = not - support the language specified by Language, then EFI_UNSUPPORTED is retu= rned. - - @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] ControllerHandle The handle of a controller that the driver - specified by This is managing. This handl= e - specifies the controller whose name is to = be - returned. - - @param[in] ChildHandle The handle of the child controller to retr= ieve - the name of. This is an optional paramete= r that - may be NULL. It will be NULL for device - drivers. It will also be NULL for a bus d= rivers - that wish to retrieve the name of the bus - controller. It will not be NULL for a bus - driver that wishes to retrieve the name of= a - child controller. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is th= e - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d in - RFC 4646 or ISO 639-2 language code format= . - - @param[out] ControllerName A pointer to the Unicode string to return. - This Unicode string is the name of the - controller specified by ControllerHandle a= nd - ChildHandle in the language specified by - Language from the point of view of the dri= ver - specified by This. - - @retval EFI_SUCCESS The Unicode string for the user readable n= ame in - the language specified by Language for the - 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 va= lid - 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 curren= tly - managing the controller specified by - ControllerHandle and ChildHandle. - - @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort - 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 gTcp4ComponentN= ame =3D { - TcpComponentNameGetDriverName, - TcpComponentNameGetControllerName, - "eng" -}; - -/// -/// EFI Component Name 2 Protocol -/// -GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTcp4ComponentN= ame2 =3D { - (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) TcpComponentNameGetDriverName, - (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) TcpComponentNameGetControllerN= ame, - "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 *gTcpControllerName= Table =3D NULL; - -/** - Retrieves a Unicode string that is the user readable name of the driver. - - This function retrieves the user readable name of a driver in the form o= f a - Unicode string. If the driver specified by This has a user readable name= 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 speci= fied - 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_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is the - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d - in RFC 4646 or ISO 639-2 language code for= mat. - - @param[out] DriverName A pointer to the Unicode string to return. - 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 specifie= d by - This and the language specified by Languag= e 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 supp= ort - 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 thi= s 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, N= ULL); - 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 control= ler - that is being managed by a driver. - - This function retrieves the user readable name of the controller specifi= ed by - ControllerHandle and ChildHandle in the form of a Unicode string. If the - driver specified by This has a user readable name in the language specif= ied by - Language, then a pointer to the controller name is returned in Controlle= rName, - and EFI_SUCCESS is returned. If the driver specified by This is not cur= rently - managing the controller specified by ControllerHandle and ChildHandle, - then EFI_UNSUPPORTED is returned. If the driver specified by This does = not - support the language specified by Language, then EFI_UNSUPPORTED is retu= rned. - - @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] ControllerHandle The handle of a controller that the driver - specified by This is managing. This handl= e - specifies the controller whose name is to = be - returned. - - @param[in] ChildHandle The handle of the child controller to ret= rieve - the name of. This is an optional paramete= r that - may be NULL. It will be NULL for device - drivers. It will also be NULL for a bus d= rivers - that wish to retrieve the name of the bus - controller. It will not be NULL for a bus - driver that wishes to retrieve the name of= a - child controller. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is th= e - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d in - RFC 4646 or ISO 639-2 language code format= . - - @param[out] ControllerName A pointer to the Unicode string to return. - This Unicode string is the name of the - controller specified by ControllerHandle a= nd - ChildHandle in the language specified by - Language from the point of view of the dri= ver - specified by This. - - @retval EFI_SUCCESS The Unicode string for the user readable n= ame in - the language specified by Language for the - 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 va= lid - 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 curren= tly - managing the controller specified by - ControllerHandle and ChildHandle. - - @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort - 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/MdeModuleP= kg/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 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 IMPLI= ED. - -**/ - -#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 the= data is - OOB. - @param BufLen The maximum length of the data buffer to s= tore 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, i= gnored. - -**/ -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 the= data is - OOB. - @param BufLen The maximum length of the data buffer to s= tore 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 receiv= e buffer. - @param RcvdBytes The maximum length of the data can be copi= ed. - @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); In= dex++) { - - 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 receiv= e 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 b= uffer. - - @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 establ= ished, - 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 successfull= y. - - @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_CONN= ECTED (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 conncnt = 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 socket. - - @return Pointer to the newly created socket, return NULL when exception = occured. - -**/ -SOCKET * -SockCreate ( - IN SOCK_INIT_DATA *SockInitData - ) -{ - SOCKET *Sock; - SOCKET *Parent; - EFI_STATUS Status; - - ASSERT ((SockInitData !=3D NULL) && (SockInitData->ProtoHandler !=3D NUL= L)); - 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->Dat= aSize); - - 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 occ= urred. - -**/ -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 is - 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 the - 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 signal= s - the close token. - - @param Sock Pointer to the socket associated with the = 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 proce= ssed. - - This function trims the sent data in the socket send buffer, signals the= 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 dat= a. - - @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 laye= r. - - This function will append the data to the socket receive buffer, set the= r - 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 re= ceived - data. - @param UrgLen The length of the urgent data in the recei= ved 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 ch= eck, - 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_BU= F =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 more = data - from the communication peer. - - This function set the socket's state to SO_NO_MORE_DATA and signal all q= ueued - 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 e= mpty. - -**/ -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 r= equired - one. - - @return Pointer to the buffer block next to SockEntry. NULL if SockEntry= 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, List)= ; -} diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c b/MdeMo= dulePkg/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 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 IMPLI= ED. - -**/ - - -#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 lists. - @retval FALSE The Event is not in related socket's lists. - -**/ -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 Even= t)) { - 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 in = Token. - - @return Pointer to the token that wraps Token. If NULL, error condition = 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 socket= . - -**/ -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 oc= cured. - -**/ -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 socket= 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 inita= te the - connection. - @param Token Pointer to the token used for the connectio= n - operation. - - @retval EFI_SUCCESS The connection is initialized successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not conf= igured to - be an active one, or the token is already i= n one of - this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - 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 connections= . - @param Token The token to accept a connection. - - @retval EFI_SUCCESS Either a connection is accpeted or the Toke= n is - buffered for further acception. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not conf= igured to - be a passive one, or the token is already i= n one of - this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - finished. - @retval EFI_NOT_STARTED The socket is not configured. - @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory li= mit. - -**/ -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 token = with - data. - @param Token The token with data that needs to send out. - - @retval EFI_SUCCESS The token is processed successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not in a - synchronized state , or the token is alread= y in one - of this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - finished. - @retval EFI_NOT_STARTED The socket is not configured. - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory li= mit. - -**/ -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 t= he - socket. - - @retval EFI_SUCCESS The token is processed successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not in a - synchronized state , or the token is alread= y in one - of this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - finished. - @retval EFI_NOT_STARTED The socket is not configured. - @retval EFI_CONNECTION_FIN The connection is closed and there is no mo= re data. - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory li= mit. - -**/ -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 socket= . - -**/ -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 to = close or - abort. - @param Token The token for close operation. - @param OnAbort TRUE for aborting the connection, FALSE to = close it. - - @retval EFI_SUCCESS The close or abort operation is initialized - successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not in a - synchronized state , or the token is alread= y in one - of this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - 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 from= . - @param Mode Pointer to the data to store the low layer = 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 I= P route - table to operate on. - @param RouteInfo Pointer to the route information to be proc= essed. - - @retval EFI_SUCCESS The route table is updated successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= . - @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/MdeM= odulePkg/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 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 IMPLI= ED. - -**/ - -#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 T= CP instance. - - @param Tcb Pointer to the TCP_CB of this TCP instance= . - @param RouteInfo Pointer to the route info to be processed. - - @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, configurat= ion(DHCP, - BOOTP, RARP, etc.) is not finished yet. - @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing tab= le. - @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 routin= g 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 instanc= e. - @param Mode Pointer to the buffer to store the operat= ional - settings. - - @retval EFI_SUCCESS The mode data is read. - @retval EFI_NOT_STARTED No configuration data is available becaus= e 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_LIS= TEN); - - 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_H= Z; - Option->DataRetries =3D Tcb->MaxRexmit; - Option->FinTimeout =3D Tcb->FinWait2Timeout / TCP_TICK_= HZ; - Option->TimeWaitTimeout =3D Tcb->TimeWaitTimeout / TCP_TICK_= HZ; - Option->KeepAliveProbes =3D Tcb->MaxKeepAlive; - Option->KeepAliveTime =3D Tcb->KeepAliveIdle / TCP_TICK_HZ= ; - Option->KeepAliveInterval =3D Tcb->KeepAlivePeriod / TCP_TICK_= HZ; - - Option->EnableNagle =3D (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFla= g, TCP_CTRL_NO_NAGLE)); - Option->EnableTimeStamp =3D (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFla= g, TCP_CTRL_NO_TS)); - Option->EnableWindowScaling =3D (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFla= g, 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 assign= ed. - @retval EFI_INVALID_PARAMETER The non-zero station port is already used= . - @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 instanc= e. - - @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 instanc= e. - -**/ -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 instanc= e. - @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 i= n - 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 NU= LL)); - - 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 def= ault 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, sizeof= (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, size= of (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_TIC= K_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_T= ICK_HZ) - ); - } - - Tcb->ConnectTimeout =3D TCP_COMP_VAL ( - TCP_CONNECT_TIME_MIN, - TCP_CONNECT_TIME, - TCP_CONNECT_TIME, - (UINT32) (Option->ConnectionTimeout * TCP_TICK= _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 instanc= e. - @param Request The code of this operation request. - @param Data Pointer to the operation specific data pa= ssed in - together with the operation request. - - @retval EFI_SUCCESS The socket request is completed successfu= lly. - @retval other The error status returned by the correspo= nding 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/MdeModul= ePkg/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 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 IMPLI= ED. - -**/ - -#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 sta= rted. - @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 NetDestro= yLinkList process. - - @param[in] Entry The entry to be removed. - @param[in] Context Pointer to the callback context correspond= s 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 *) Cont= ext)->ServiceBinding; - NumberOfChildren =3D ((TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Cont= ext)->NumberOfChildren; - ChildHandleBuffer =3D ((TCP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Cont= ext)->ChildHandleBuffer; - - if (!NetIsInHandleBuffer (Sock->SockHandle, NumberOfChildren, ChildHandl= eBuffer)) { - return EFI_SUCCESS; - } - - return ServiceBinding->DestroyChild (ServiceBinding, Sock->SockHandle); -} - -/** - The entry point for Tcp4 driver, used to install Tcp4 driver on the Imag= eHandle. - - @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 su= pports - creating a handle for the specified child device. - - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCO= L instance. - @param ControllerHandle The handle of the controller to test. This = handle - must support a protocol interface that supp= lies - an I/O abstraction to the driver. - @param RemainingDevicePath A pointer to the remaining portion of a dev= ice path. - This parameter is ignored by device drivers= , and is optional for bus drivers. - - - @retval EFI_SUCCESS The device specified by ControllerHandle an= d - RemainingDevicePath is supported by the dri= ver - specified by This. - @retval EFI_ALREADY_STARTED The device specified by ControllerHandle an= d - RemainingDevicePath is already being manage= d by - the driver specified by This. - @retval EFI_ACCESS_DENIED The device specified by ControllerHandle an= d - RemainingDevicePath is already being manage= d by a - different driver or an application that req= uires - exclusive access. - @retval EFI_UNSUPPORTED The device specified by ControllerHandle an= d - RemainingDevicePath is not supported by the= 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 service - ConnectController(). As a result, much of the error checking on the para= meters - to Start() has been moved into this common boot service. It is legal to = call - Start() from other locations, but the following calling restrictions mus= t 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 na= turally - aligned EFI_DEVICE_PATH_PROTOCOL. - 3. Prior to calling Start(), the Supported() function for the driver spe= cified - by This must have been called with the same calling parameters, and S= upported() - must have returned EFI_SUCCESS. - - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCO= L instance. - @param ControllerHandle The handle of the controller to start. This= handle - must support a protocol interface that supp= lies - an I/O abstraction to the driver. - @param RemainingDevicePath A pointer to the remaining portion of a dev= ice path. - This parameter is ignored by device drivers= , 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 de= vice 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 Bin= ding" - " 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 service - DisconnectController(). As a result, much of the error checking on the p= arameters - to Stop() has been moved into this common boot service. It is legal to c= all Stop() - from other locations, but the following calling restrictions must be fol= lowed - or the system behavior will not be deterministic. - 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previo= us 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 created = in this - driver's Start() function, and the Start() function must have called = OpenProtocol() - on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_C= ONTROLLER. - - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL i= nstance. - @param ControllerHandle A handle to the device being stopped. The hand= le must - support a bus specific I/O protocol for the dr= iver - to use to stop the device. - @param NumberOfChildren The number of child device handles in ChildHan= dleBuffer. - @param ChildHandleBuffer An array of child handles to be freed. May be = 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 devic= e 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, &gEfiIp4ProtocolGuid= ); - 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 i= n - 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)->TcpService= ; - - // - // 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 soc= ket 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)->TcpService= ; - - // - // 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 ChildH= andle - is a pointer to NULL, then a new handle is created and returned in Child= Handle. - If ChildHandle is not a pointer to NULL, then the protocol installs on t= he existing - ChildHandle. - - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance= . - @param ChildHandle Pointer to the handle of the child to create. If it = is NULL, then - a new handle is created. If it is a pointer to an ex= isting UEFI - handle, then the protocol is added to the existing U= EFI 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 t= o 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->DriverBindingHand= le; - - 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 remov= es a protocol - that was installed by CreateChild() from ChildHandle. If the removed pro= tocol is the - last protocol on ChildHandle, then ChildHandle is destroyed. - - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instanc= e. - @param ChildHandle Handle of the child to destroy - - @retval EFI_SUCCES The protocol was removed from ChildHandle. - @retval EFI_UNSUPPORTED ChildHandle does not support the protocol = that is - being removed. - @retval EFI_INVALID_PARAMETER Child handle is NULL. - @retval EFI_ACCESS_DENIED The protocol could not be removed from the= 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/MdeModule= Pkg/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 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 IMPLI= ED. - -**/ - - -#include "Tcp4Main.h" - - -/** - Check whether the sequence number of the incoming segment is acceptable. - - @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->SndMss)= ); - 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 Ri= ght. - - @param Nbuf Buffer that contains received TCP segment without IP he= ader. - @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 segm= ent. - -**/ -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 t= he - 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 queued. - -**/ -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 segment= . - -**/ -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 he= ader. - @param Src Source address of the segment, or the peer's IP address= . - @param Dst Destination address of the segment, or the local end's = IP - address. - - @retval 0 Segment is processed successfully. It is either accepte= d 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->Ack= ))) { - - 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 o= ut if TCP - // window scale is enabled, it will look like the peer is shrinkin= g the window. - // Check whether the SndNxt is out of the advertised receive windo= w 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 TCB= %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 f= or 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 packet. - @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 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 IMPLI= ED. - -**/ - -#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(), not= 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->De= st.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_ADDR= ESS)); - CopyMem (&Override.Ip4OverrideData.SourceAddress, &Src, sizeof (EFI_IPv4= _ADDRESS)); - - Status =3D IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, &Destination, &Ov= erride); - - 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/MdeModuleP= kg/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 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 IMPLI= ED. - -**/ - - -#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 tabl= e. - @param FragmentTable Pointer to the fragment table of the da= ta - 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 th= is - EFI TCPv4 Protocol instance into user-supplied buffers. This function ca= n - 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 instan= ce. - @param Tcp4State Pointer to the buffer to receive the cu= rrent TCP - state. - @param Tcp4ConfigData Pointer to the buffer to receive the cu= rrent TCP - configuration. - @param Ip4ModeData Pointer to the buffer to receive the cu= rrent IPv4 - configuration data used by the TCPv4 in= stance. - @param MnpConfigData Pointer to the buffer to receive the cu= rrent MNP - configuration data indirectly used by t= he TCPv4 - Instance. - @param SnpModeData Pointer to the buffer to receive the cu= rrent SNP - configuration data indirectly used by t= he TCPv4 - Instance. - - @retval EFI_SUCCESS The mode data was read. - @retval EFI_NOT_STARTED No configuration data is available beca= use 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 communication= end - setting, specify active open or passive open for an instance. - * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchron= ous - tokens, flush transmission and receiving buffer directly without informi= ng - 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 pr= oper - configuration it may call Connect() to initiates the three-way handshake= . - For a passive TCP4 instance, its state will transit to Tcp4StateListen a= fter - configuration, and Accept() may be called to listen the incoming TCP con= nection - request. If TcpConfigData is set to NULL, the instance is reset. Resetti= ng - process will be done brutally, the state machine will be set to Tcp4Stat= eClosed - directly, the receive queue and transmit queue will be flushed, and no t= raffic is - allowed through this instance. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param TcpConfigData Pointer to the configure data to config= ure the - instance. - - @retval EFI_SUCCESS The operational settings are set, chang= ed, or - reset successfully. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (through DHCP, BOOTP, RARP, etc.) is no= t - finished. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_ACCESS_DENIED Configuring TCP instance when it is alr= eady - configured. - @retval EFI_DEVICE_ERROR An unexpected network or system error o= ccurred. - @retval EFI_UNSUPPORTED One or more of the control options are = not - supported in the implementation. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resour= ces. - -**/ -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_A= DDR)); - 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 (IP= 4_ADDR)); - CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof= (IP4_ADDR)); - if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) || - (SubnetMask !=3D 0 && !NetIp4IsUnicast (NTOHL (Ip), NTOHL (Subne= tMask)))) { - 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 routin= g table. - The most specific route is selected by comparing the SubnetAddress with = 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 mo= re specific route. - Direct route is added with GatewayAddress set to 0.0.0.0. Packets are se= nt to - the destination host if its address can be found in the Address Resoluti= on Protocol (ARP) - cache or it is on the local subnet. If the instance is configured to use= default - address, a direct route to the local network will be added automatically= . - Each TCP instance has its own independent routing table. Instance that u= ses the - default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's rou= ting table. - The copy will be updated automatically whenever the IP driver reconfigur= es its - instance. As a result, the previous modification to the instance's local= copy - will be lost. The priority of checking the route table is specific with = IP - implementation and every IP implementation must comply with RFC 1122. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param DeleteRoute If TRUE, delete the specified route fro= m routing - table; if FALSE, add the specified rout= e to - routing table. - DestinationAddress and SubnetMask are u= sed as - the keywords to search route entry. - @param SubnetAddress The destination network. - @param SubnetMask The subnet mask for the destination net= work. - @param GatewayAddress The gateway address for this route. - It must be on the same subnet with the = station - address unless a direct route is specif= ied. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not = been - configured. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (through DHCP, BOOTP, RARP, etc.) is no= t - finished. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to = add the - entry to the routing table. - @retval EFI_NOT_FOUND This route is not in the routing table. - @retval EFI_ACCESS_DENIED This route is already in the routing ta= ble. - @retval EFI_UNSUPPORTED The TCP driver does not support this op= eration. - -**/ -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 instance= . - - The Connect() function will initiate an active open to the remote peer c= onfigured - in current TCP instance if it is configured active. If the connection su= cceeds - or fails due to any error, the ConnectionToken->CompletionToken.Event wi= ll be - signaled and ConnectionToken->CompletionToken.Status will be updated acc= ordingly. - This function can only be called for the TCP instance in Tcp4StateClosed= state. - The instance will transfer into Tcp4StateSynSent if the function returns= EFI_SUCCESS. - If TCP three way handshake succeeds, its state will become Tcp4StateEsta= blished, - otherwise, the state will return to Tcp4StateClosed. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce - @param ConnectionToken Pointer to the connection token to retu= rn when - the TCP three way handshake finishes. - - @retval EFI_SUCCESS The connection request is successfully = initiated - and the state of this TCPv4 instance ha= s - 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 ac= tive 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 resour= ce to - initiate the active open. - @retval EFI_DEVICE_ERROR An unexpected system or network error o= ccurred. - -**/ -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 request. - - The Accept() function initiates an asynchronous accept request to wait f= or an - incoming connection on the passive TCP instance. If a remote peer succes= sfully - establishes a connection with this instance, a new TCP instance will be = created - and its handle will be returned in ListenToken->NewChildHandle. The newl= y created - instance is configured by inheriting the passive instance's configuratio= n and is - ready for use upon return. The instance is in the Tcp4StateEstablished s= tate. - The ListenToken->CompletionToken.Event will be signaled when a new conne= ction - is accepted, user aborts the listen or connection is reset. This functio= n only - can be called when current TCP instance is in Tcp4StateListen state. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce - @param ListenToken Pointer to the listen token to return w= hen - operation finishes. - - @retval EFI_SUCCESS The listen token has been queued succes= sfully. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_ACCESS_DENIED The instatnce is not a passive one or i= t is not - in Tcp4StateListen state or a same list= en token - has already existed in the listen token= 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 to = finish - the operation. - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to abov= e 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 instance = along - with the user data. The status of the token is updated and the event in = the token - will be signaled once the data is sent out or some error occurs. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce - @param Token Pointer to the completion token to queu= e to the - transmit queue - - @retval EFI_SUCCESS The data has been queued for transmissi= on. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (DHCP, BOOTP, RARP, etc.) is not finish= ed yet. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_ACCESS_DENIED One or more of the following conditions= is TRUE: - * A transmit completion token with the = same - Token-> CompletionToken.Event was alr= eady in the - transmission queue. - * The current instance is in Tcp4StateC= losed state - * The current instance is a passive one= and - it is in Tcp4StateListen state. - * User has called Close() to disconnect= this - connection. - @retval EFI_NOT_READY The completion token could not be queue= d because - the transmit queue is full. - @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data becau= se of - resource shortage. - @retval EFI_NETWORK_UNREACHABLE There is no route to the destination ne= twork 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 packet= queue. - This function is always asynchronous. The caller must allocate the - Token->CompletionToken.Event and the FragmentBuffer used to receive data= . He also - must fill the DataLength which represents the whole length of all Fragme= ntBuffer. - When the receive operation completes, the EFI TCPv4 Protocol driver upda= tes the - Token->CompletionToken.Status and Token->Packet.RxData fields and the - Token->CompletionToken.Event is signaled. If got data the data and its l= ength - 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 notif= ication - function and context for the event will enable the user to receive the n= otification - and receiving status. That notification function is guaranteed to not be= re-entered. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param Token Pointer to a token that is associated w= ith the - receive data descriptor. - - @retval EFI_SUCCESS The receive completion token was cached= . - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (DHCP, BOOTP, RARP, etc.) is not finish= ed yet. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The receive completion token could not = be queued - due to a lack of system resources. - @retval EFI_DEVICE_ERROR An unexpected system or network error o= ccurred. - The EFI TCPv4 Protocol instance has bee= n reset - to startup defaults. - @retval EFI_ACCESS_DENIED One or more of the following conditions= is TRUE: - * A receive completion token with the s= ame - Token->CompletionToken.Event was alre= ady in - the receive queue. - * The current instance is in Tcp4StateC= losed state. - * The current instance is a passive one= and it - is in Tcp4StateListen state. - * User has called Close() to disconnect= this - connection. - @retval EFI_CONNECTION_FIN The communication peer has closed the c= onnection - and there is no any buffered data in th= e receive - buffer of this instance. - @retval EFI_NOT_READY The receive request could not be queued= 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 cal= led, - any buffered transmission data will be sent by TCP driver and the curren= t - 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 T= CP - driver to fast disconnect this connection. When the close operation comp= letes - successfully the TCP instance is in Tcp4StateClosed state, all pending - asynchronous operation is signaled and any buffers used for TCP network = traffic - is flushed. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param CloseToken Pointer to the close token to return wh= en - operation finishes. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_ACCESS_DENIED One or more of the following are TRUE: - * Configure() has been called with TcpC= onfigData - set to NULL and this function has not= returned. - * Previous Close() call on this instanc= e has not - finished. - @retval EFI_INVALID_PARAMETER One ore more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to f= inish the - operation. - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to abov= e - 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 reques= t. - - The Cancel() function aborts a pending connection, listen, transmit or r= eceive - request. If Token is not NULL and the token is in the connection, listen= , - transmission or receive queue when it is being cancelled, its Token->Sta= tus - will be set to EFI_ABORTED and then Token->Event will be signaled. If th= e token - is not in one of the queues, which usually means that the asynchronous o= peration - has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchron= ous 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 instan= ce. - @param Token Pointer to a token that has been issued= by - Connect(), Accept(), Transmit() or Rece= ive(). If - NULL, all pending tokens issued by abov= e four - functions will be aborted. - - @retval EFI_SUCCESS The asynchronous I/O request is aborted= 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, configu= ration - (DHCP, BOOTP,RARP, etc.) hasn's finishe= d yet. - @retval EFI_NOT_FOUND The asynchronous I/O request isn's foun= d in the - transmission or receive queue. It has e= ither - completed or wasn's issued by Transmit(= ) and Receive(). - @retval EFI_UNSUPPORTED The operation is not supported in curre= nt - 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 ne= twork - and application and can be called when the TCP instance is created succe= ssfully. - Its use is optional. In some implementations, the periodical timer in th= e MNP - driver may not poll the underlying communications device fast enough to = avoid - drop packets. Drivers and applications that are experiencing packet loss= should - try calling the Poll() function in a high frequency. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - - @retval EFI_SUCCESS Incoming or outgoing data was processed= . - @retval EFI_INVALID_PARAMETER This is NULL. - @retval EFI_DEVICE_ERROR An unexpected system or network error o= ccurred. - @retval EFI_NOT_READY No incoming or outgoing data was proces= sed. - @retval EFI_TIMEOUT Data was dropped out of the transmissio= n or - receive queue. Consider increasing the = 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/MdeModuleP= kg/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 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 IMPLI= ED. - -**/ - - -#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 instance= . - -**/ -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 instance= . - @param Seg Pointer to the segment that contains the p= eer's - intial info. - @param Opt Pointer to the options announced by the pe= er. - -**/ -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 T= RUE, 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 occur= red. - -**/ -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 instance= . - @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 TC= P - segment. - @param HeadSum The checksum value of the fixed part of ps= eudo - 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 instance= . - @param Nbuf Pointer to the buffer contains the TCP seg= ment. - - @return Pointer to the TCP_SEG that contains the translated TCP head in= formation. - -**/ -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 initia= te 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 instance= . - -**/ -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 instance= . - - @retval 0 Whether the data is sent out or is buffere= d for - further sending. - @retval -1 The Tcb is not in a state that data is per= mitted 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 instance= . - -**/ -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 instance. - -**/ -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 inst= ance. - - @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/MdeModul= ePkg/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 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 IMPLI= ED. - -**/ - -#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 successfully= 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/MdeModul= ePkg/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 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 IMPLI= ED. - -**/ - -#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 segme= nt. - - @param Tcb Pointer to the TCP_CB of this TCP instance. - @param Syn The flag to indicate whether the outgoing segment is a S= YN - segment. - - @return The value of the local receive window size used to fill the outi= ng 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 a= nd 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 sent = 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) && (TcpVerifySegment= (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 according= 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->SndWl= 2 + 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 window= 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 sma= ll 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 a= nd 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_L= ISTEN)); - - 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 p= robe. - - @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 NULL. - @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/MdeModule= Pkg/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 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 IMPLI= ED. - -**/ - -#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 timers - 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/Universal/Network/UefiPxeBcDxe/ComponentName.c b/= MdeModulePkg/Universal/Network/UefiPxeBcDxe/ComponentName.c deleted file mode 100644 index a085ef61f341..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/ComponentName.c +++ /dev/null @@ -1,365 +0,0 @@ -/** @file - -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - - -#include "PxeBcImpl.h" - -// -// EFI Component Name Functions -// -/** - Retrieves a Unicode string that is the user readable name of the driver. - - This function retrieves the user readable name of a driver in the form o= f a - Unicode string. If the driver specified by This has a user readable name= 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 speci= fied - 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_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is the - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d - in RFC 4646 or ISO 639-2 language code for= mat. - - @param[out] DriverName A pointer to the Unicode string to return. - 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 specifie= d by - This and the language specified by Languag= e 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 supp= ort - the language specified by Language. - -**/ -EFI_STATUS -EFIAPI -PxeBcComponentNameGetDriverName ( - IN EFI_COMPONENT_NAME_PROTOCOL * This, - IN CHAR8 *Language, - OUT CHAR16 **DriverName - ); - -/** - Retrieves a Unicode string that is the user readable name of the control= ler - that is being managed by a driver. - - This function retrieves the user readable name of the controller specifi= ed by - ControllerHandle and ChildHandle in the form of a Unicode string. If the - driver specified by This has a user readable name in the language specif= ied by - Language, then a pointer to the controller name is returned in Controlle= rName, - and EFI_SUCCESS is returned. If the driver specified by This is not cur= rently - managing the controller specified by ControllerHandle and ChildHandle, - then EFI_UNSUPPORTED is returned. If the driver specified by This does = not - support the language specified by Language, then EFI_UNSUPPORTED is retu= rned. - - @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] ControllerHandle The handle of a controller that the driver - specified by This is managing. This handl= e - specifies the controller whose name is to = be - returned. - - @param[in] ChildHandle The handle of the child controller to retr= ieve - the name of. This is an optional paramete= r that - may be NULL. It will be NULL for device - drivers. It will also be NULL for a bus d= rivers - that wish to retrieve the name of the bus - controller. It will not be NULL for a bus - driver that wishes to retrieve the name of= a - child controller. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is th= e - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d in - RFC 4646 or ISO 639-2 language code format= . - - @param[out] ControllerName A pointer to the Unicode string to return. - This Unicode string is the name of the - controller specified by ControllerHandle a= nd - ChildHandle in the language specified by - Language from the point of view of the dri= ver - specified by This. - - @retval EFI_SUCCESS The Unicode string for the user readable n= ame in - the language specified by Language for the - 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 va= lid - 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 curren= tly - managing the controller specified by - ControllerHandle and ChildHandle. - - @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort - the language specified by Language. - -**/ -EFI_STATUS -EFIAPI -PxeBcComponentNameGetControllerName ( - 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 gPxeBcCompon= entName =3D { - PxeBcComponentNameGetDriverName, - PxeBcComponentNameGetControllerName, - "eng" -}; - -GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPxeBcCompon= entName2 =3D { - (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PxeBcComponentNameGetDriverName, - (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PxeBcComponentNameGetControlle= rName, - "en" -}; - -GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcDriverNameTab= le[] =3D { - { - "eng;en", - L"UEFI PXE Base Code Driver" - }, - { - NULL, - NULL - } -}; - -GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPxeBcControllerNam= eTable[] =3D { - { - "eng;en", - L"PXE Controller" - }, - { - NULL, - NULL - } -}; - -/** - Retrieves a Unicode string that is the user readable name of the driver. - - This function retrieves the user readable name of a driver in the form o= f a - Unicode string. If the driver specified by This has a user readable name= 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 speci= fied - 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_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is the - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d - in RFC 4646 or ISO 639-2 language code for= mat. - - @param[out] DriverName A pointer to the Unicode string to return. - 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 specifie= d by - This and the language specified by Languag= e 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 supp= ort - the language specified by Language. - -**/ -EFI_STATUS -EFIAPI -PxeBcComponentNameGetDriverName ( - IN EFI_COMPONENT_NAME_PROTOCOL * This, - IN CHAR8 *Language, - OUT CHAR16 **DriverName - ) -{ - return LookupUnicodeString2 ( - Language, - This->SupportedLanguages, - mPxeBcDriverNameTable, - DriverName, - (BOOLEAN)(This =3D=3D &gPxeBcComponentName) - ); -} - -/** - Retrieves a Unicode string that is the user readable name of the control= ler - that is being managed by a driver. - - This function retrieves the user readable name of the controller specifi= ed by - ControllerHandle and ChildHandle in the form of a Unicode string. If the - driver specified by This has a user readable name in the language specif= ied by - Language, then a pointer to the controller name is returned in Controlle= rName, - and EFI_SUCCESS is returned. If the driver specified by This is not cur= rently - managing the controller specified by ControllerHandle and ChildHandle, - then EFI_UNSUPPORTED is returned. If the driver specified by This does = not - support the language specified by Language, then EFI_UNSUPPORTED is retu= rned. - - @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTO= COL or - EFI_COMPONENT_NAME_PROTOCOL instance. - - @param[in] ControllerHandle The handle of a controller that the driver - specified by This is managing. This handl= e - specifies the controller whose name is to = be - returned. - - @param[in] ChildHandle The handle of the child controller to retr= ieve - the name of. This is an optional paramete= r that - may be NULL. It will be NULL for device - drivers. It will also be NULL for a bus d= rivers - that wish to retrieve the name of the bus - controller. It will not be NULL for a bus - driver that wishes to retrieve the name of= a - child controller. - - @param[in] Language A pointer to a Null-terminated ASCII strin= g - array indicating the language. This is th= e - language of the driver name that the calle= r is - requesting, and it must match one of the - languages specified in SupportedLanguages.= The - number of languages supported by a driver = is up - to the driver writer. Language is specifie= d in - RFC 4646 or ISO 639-2 language code format= . - - @param[out] ControllerName A pointer to the Unicode string to return. - This Unicode string is the name of the - controller specified by ControllerHandle a= nd - ChildHandle in the language specified by - Language from the point of view of the dri= ver - specified by This. - - @retval EFI_SUCCESS The Unicode string for the user readable n= ame in - the language specified by Language for the - 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 va= lid - 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 curren= tly - managing the controller specified by - ControllerHandle and ChildHandle. - - @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort - the language specified by Language. - -**/ -EFI_STATUS -EFIAPI -PxeBcComponentNameGetControllerName ( - IN EFI_COMPONENT_NAME_PROTOCOL * This, - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE ChildHandle OPTIONAL, - IN CHAR8 *Language, - OUT CHAR16 **ControllerName - ) -{ - EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; - EFI_HANDLE NicHandle; - EFI_STATUS Status; - - if (ControllerHandle =3D=3D NULL || ChildHandle !=3D NULL) { - return EFI_UNSUPPORTED; - } - - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid= ); - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4Protocol= Guid); - - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiIp4Protocol= Guid); - - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiUdp4Proto= colGuid); - - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiMtftp4P= rotocolGuid); - - if (NicHandle =3D=3D NULL) { - return EFI_UNSUPPORTED; - } - } - } - } - } - - Status =3D gBS->OpenProtocol ( - NicHandle, - &gEfiPxeBaseCodeProtocolGuid, - (VOID **) &PxeBc, - NULL, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - return LookupUnicodeString2 ( - Language, - This->SupportedLanguages, - mPxeBcControllerNameTable, - ControllerName, - (BOOLEAN)(This =3D=3D &gPxeBcComponentName) - ); -} diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c b/MdeM= odulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c deleted file mode 100644 index f7b975f2997f..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c +++ /dev/null @@ -1,1999 +0,0 @@ -/** @file - Support for PxeBc dhcp functions. - -Copyright (c) 2013, Red Hat, Inc. -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - - -#include "PxeBcImpl.h" - -// -// This is a map from the interested DHCP4 option tags' index to the tag v= alue. -// -UINT8 mInterestedDhcp4Tags[PXEBC_DHCP4_TAG_INDEX_MAX] =3D { - DHCP4_TAG_BOOTFILE_LEN, - DHCP4_TAG_VENDOR, - DHCP4_TAG_OVERLOAD, - DHCP4_TAG_MSG_TYPE, - DHCP4_TAG_SERVER_ID, - DHCP4_TAG_VENDOR_CLASS_ID, - DHCP4_TAG_BOOTFILE -}; - - -/** - This function initialize the DHCP4 message instance. - - This function will pad each item of dhcp4 message packet. - - @param Seed Pointer to the message instance of the DHCP4 packet. - @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance. - -**/ -VOID -PxeBcInitSeedPacket ( - IN EFI_DHCP4_PACKET *Seed, - IN EFI_UDP4_PROTOCOL *Udp4 - ) -{ - EFI_SIMPLE_NETWORK_MODE Mode; - EFI_DHCP4_HEADER *Header; - - Udp4->GetModeData (Udp4, NULL, NULL, NULL, &Mode); - - Seed->Size =3D sizeof (EFI_DHCP4_PACKET); - Seed->Length =3D sizeof (Seed->Dhcp4); - - Header =3D &Seed->Dhcp4.Header; - - ZeroMem (Header, sizeof (EFI_DHCP4_HEADER)); - Header->OpCode =3D PXEBC_DHCP4_OPCODE_REQUEST; - Header->HwType =3D Mode.IfType; - Header->HwAddrLen =3D (UINT8) Mode.HwAddressSize; - CopyMem (Header->ClientHwAddr, &Mode.CurrentAddress, Header->HwAddrLen); - - Seed->Dhcp4.Magik =3D PXEBC_DHCP4_MAGIC; - Seed->Dhcp4.Option[0] =3D DHCP4_TAG_EOP; -} - - -/** - Copy the DCHP4 packet from srouce to destination. - - @param[in] Dst Pointer to the cache buffer for DHCPv4 packet. - @param[in] Src Pointer to the DHCPv4 packet to be cached. - - @retval EFI_SUCCESS Packet is copied. - @retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to= hold the packet. - -**/ -EFI_STATUS -PxeBcCopyEfiDhcp4Packet ( - IN EFI_DHCP4_PACKET *Dst, - IN EFI_DHCP4_PACKET *Src - ) -{ - if (Dst->Size < Src->Length) { - return EFI_BUFFER_TOO_SMALL; - } - - CopyMem (&Dst->Dhcp4, &Src->Dhcp4, Src->Length); - Dst->Length =3D Src->Length; - return EFI_SUCCESS; -} - - -/** - Copy the dhcp4 packet to the PxeBc private data and parse the dhcp4 pack= et. - - @param Private Pointer to PxeBc private data. - @param OfferIndex Index of cached packets as complements of pxe mode= data, - the index is maximum offer number. - - @retval EFI_SUCCESS Cache and parse the packet succes= sfully. - @retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to= hold the packet. - -**/ -EFI_STATUS -PxeBcCopyProxyOffer ( - IN PXEBC_PRIVATE_DATA *Private, - IN UINT32 OfferIndex - ) -{ - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_DHCP4_PACKET *Offer; - EFI_STATUS Status; - - ASSERT (OfferIndex < Private->NumOffers); - ASSERT (OfferIndex < PXEBC_MAX_OFFER_NUM); - - Mode =3D Private->PxeBc.Mode; - Offer =3D &Private->Dhcp4Offers[OfferIndex].Packet.Offer; - - Status =3D PxeBcCopyEfiDhcp4Packet (&Private->ProxyOffer.Packet.Offer, O= ffer); - if (EFI_ERROR(Status)) { - return Status; - } - CopyMem (&Mode->ProxyOffer, &Offer->Dhcp4, Offer->Length); - Mode->ProxyOfferReceived =3D TRUE; - - PxeBcParseCachedDhcpPacket (&Private->ProxyOffer); - return EFI_SUCCESS; -} - - -/** - Parse the cached dhcp packet. - - @param CachedPacket Pointer to cached dhcp packet. - - @retval TRUE Succeed to parse and validation. - @retval FALSE Fail to parse or validation. - -**/ -BOOLEAN -PxeBcParseCachedDhcpPacket ( - IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket - ) -{ - EFI_DHCP4_PACKET *Offer; - EFI_DHCP4_PACKET_OPTION **Options; - EFI_DHCP4_PACKET_OPTION *Option; - UINT8 OfferType; - UINTN Index; - UINT8 *Ptr8; - - CachedPacket->IsPxeOffer =3D FALSE; - ZeroMem (CachedPacket->Dhcp4Option, sizeof (CachedPacket->Dhcp4Option)); - ZeroMem (&CachedPacket->PxeVendorOption, sizeof (CachedPacket->PxeVendor= Option)); - - Offer =3D &CachedPacket->Packet.Offer; - Options =3D CachedPacket->Dhcp4Option; - - // - // Parse interested dhcp options and store their pointers in CachedPacke= t->Dhcp4Option. - // First, try to parse DHCPv4 options from the DHCP optional parameters = field. - // - for (Index =3D 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) { - Options[Index] =3D PxeBcParseExtendOptions ( - Offer->Dhcp4.Option, - GET_OPTION_BUFFER_LEN (Offer), - mInterestedDhcp4Tags[Index] - ); - } - // - // Second, Check if bootfilename and serverhostname is overloaded to car= ry DHCP options refers to rfc-2132. - // If yes, try to parse options from the BootFileName field, then Server= Name field. - // - Option =3D Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD]; - if (Option !=3D NULL) { - if ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) !=3D 0) { - for (Index =3D 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) { - if (Options[Index] =3D=3D NULL) { - Options[Index] =3D PxeBcParseExtendOptions ( - (UINT8 *) Offer->Dhcp4.Header.BootFileName, - sizeof (Offer->Dhcp4.Header.BootFileName), - mInterestedDhcp4Tags[Index] - ); - } - } - } - if ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_SERVER_NAME) !=3D 0) { - for (Index =3D 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) { - if (Options[Index] =3D=3D NULL) { - Options[Index] =3D PxeBcParseExtendOptions ( - (UINT8 *) Offer->Dhcp4.Header.ServerName, - sizeof (Offer->Dhcp4.Header.ServerName), - mInterestedDhcp4Tags[Index] - ); - } - } - } - } - - // - // Check whether is an offer with PXEClient or not. - // - Option =3D Options[PXEBC_DHCP4_TAG_INDEX_CLASS_ID]; - if ((Option !=3D NULL) && (Option->Length >=3D 9) && - (CompareMem (Option->Data, DEFAULT_CLASS_ID_DATA, 9) =3D=3D 0)) { - - CachedPacket->IsPxeOffer =3D TRUE; - } - - // - // Parse pxe vendor options and store their content/pointers in CachedPa= cket->PxeVendorOption. - // - Option =3D Options[PXEBC_DHCP4_TAG_INDEX_VENDOR]; - if (CachedPacket->IsPxeOffer && (Option !=3D NULL)) { - - if (!PxeBcParseVendorOptions (Option, &CachedPacket->PxeVendorOption))= { - return FALSE; - } - } - - - // - // Parse PXE boot file name: - // According to PXE spec, boot file name should be read from DHCP option= 67 (bootfile name) if present. - // Otherwise, read from boot file field in DHCP header. - // - if (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] !=3D NULL) { - // - // RFC 2132, Section 9.5 does not strictly state Bootfile name (option= 67) is null - // terminated string. So force to append null terminated character at = the end of string. - // - Ptr8 =3D (UINT8*)&Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data[0]; - Ptr8 +=3D Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Length; - if (*(Ptr8 - 1) !=3D '\0') { - *Ptr8 =3D '\0'; - } - } else if (Offer->Dhcp4.Header.BootFileName[0] !=3D 0) { - // - // If the bootfile is not present and bootfilename is present in dhcp = packet, just parse it. - // And do not count dhcp option header, or else will destroy the serve= rhostname. - // - // Make sure "BootFileName" is not overloaded. - // - if (Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD] =3D=3D NULL || - (Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD]->Data[0] & PXEBC_DHCP4_OV= ERLOAD_FILE) =3D=3D 0) { - Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] =3D (EFI_DHCP4_PACKET_OPTION= *) (&Offer->Dhcp4.Header.BootFileName[0] - - OFFSET_OF (EFI_DHCP4_PACKET_OP= TION, Data[0])); - } - } - - // - // Determine offer type of the dhcp packet. - // - Option =3D Options[PXEBC_DHCP4_TAG_INDEX_MSG_TYPE]; - if ((Option =3D=3D NULL) || (Option->Data[0] =3D=3D 0)) { - // - // It's a bootp offer - // - Option =3D CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]; - if (Option =3D=3D NULL) { - // - // bootp offer without bootfilename, discard it. - // - return FALSE; - } - - OfferType =3D DHCP4_PACKET_TYPE_BOOTP; - - } else { - - if (IS_VALID_DISCOVER_VENDOR_OPTION (CachedPacket->PxeVendorOption.Bit= Map)) { - // - // It's a pxe10 offer with PXEClient and discover vendor option. - // - OfferType =3D DHCP4_PACKET_TYPE_PXE10; - } else if (IS_VALID_MTFTP_VENDOR_OPTION (CachedPacket->PxeVendorOption= .BitMap)) { - // - // It's a wfm11a offer with PXEClient and mtftp vendor option, and - // return false since mtftp not supported currently. - // - return FALSE; - } else { - // - // If the binl offer with only PXEClient. - // - OfferType =3D (UINT8) ((CachedPacket->IsPxeOffer) ? DHCP4_PACKET_TYP= E_BINL : DHCP4_PACKET_TYPE_DHCP_ONLY); - } - } - - CachedPacket->OfferType =3D OfferType; - - return TRUE; -} - - -/** - Offer dhcp service with a BINL dhcp offer. - - @param Private Pointer to PxeBc private data. - @param Index Index of cached packets as complements of pxe mode dat= a, - the index is maximum offer number. - - @retval TRUE Offer the service successfully under priority BINL. - @retval FALSE Boot Service failed, parse cached dhcp packet failed o= r this - BINL ack cannot find options set or bootfile name spec= ified. - -**/ -BOOLEAN -PxeBcTryBinl ( - IN PXEBC_PRIVATE_DATA *Private, - IN UINT32 Index - ) -{ - EFI_DHCP4_PACKET *Offer; - EFI_IP_ADDRESS ServerIp; - EFI_STATUS Status; - PXEBC_CACHED_DHCP4_PACKET *CachedPacket; - EFI_DHCP4_PACKET *Reply; - - ASSERT (Index < PXEBC_MAX_OFFER_NUM); - ASSERT (Private->Dhcp4Offers[Index].OfferType =3D=3D DHCP4_PACKET_TYPE_B= INL); - - Offer =3D &Private->Dhcp4Offers[Index].Packet.Offer; - - // - // Use siaddr(next server) in DHCPOFFER packet header, if zero, use opti= on 54(server identifier) - // in DHCPOFFER packet. - // (It does not comply with PXE Spec, Ver2.1) - // - if (EFI_IP4_EQUAL (&Offer->Dhcp4.Header.ServerAddr.Addr, &mZeroIp4Addr))= { - CopyMem ( - &ServerIp.Addr[0], - Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER= _ID]->Data, - sizeof (EFI_IPv4_ADDRESS) - ); - } else { - CopyMem ( - &ServerIp.Addr[0], - &Offer->Dhcp4.Header.ServerAddr, - sizeof (EFI_IPv4_ADDRESS) - ); - } - if (ServerIp.Addr[0] =3D=3D 0) { - return FALSE; - } - - CachedPacket =3D &Private->ProxyOffer; - Reply =3D &CachedPacket->Packet.Offer; - - Status =3D PxeBcDiscvBootService ( - Private, - 0, - NULL, - FALSE, - &ServerIp, - 0, - NULL, - FALSE, - Reply - ); - if (EFI_ERROR (Status)) { - return FALSE; - } - - if (!PxeBcParseCachedDhcpPacket (CachedPacket)) { - return FALSE; - } - - if ((CachedPacket->OfferType !=3D DHCP4_PACKET_TYPE_PXE10) && - (CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] =3D=3D NU= LL)) { - // - // This BINL ack doesn't have discovery options set or bootfile name - // specified. - // - return FALSE; - } - - Private->PxeBc.Mode->ProxyOfferReceived =3D TRUE; - CopyMem (&Private->PxeBc.Mode->ProxyOffer, &Reply->Dhcp4, Reply->Length)= ; - - return TRUE; -} - - -/** - Offer dhcp service for each proxy with a BINL dhcp offer. - - @param Private Pointer to PxeBc private data - @param OfferIndex Pointer to the index of cached packets as complement= s of - pxe mode data, the index is maximum offer number. - - @return If there is no service needed offer return FALSE, otherwise TRUE= . - -**/ -BOOLEAN -PxeBcTryBinlProxy ( - IN PXEBC_PRIVATE_DATA *Private, - OUT UINT32 *OfferIndex - ) -{ - UINT32 Index; - - for (Index =3D 0; Index < Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]; I= ndex++) { - - *OfferIndex =3D Private->BinlIndex[Index]; - // - // Try this BINL proxy offer - // - if (PxeBcTryBinl (Private, *OfferIndex)) { - return TRUE; - } - } - - return FALSE; -} - - -/** - This function is to check the selected proxy offer (include BINL dhcp of= fer and - DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe = base code - mode structure. - - @param Private Pointer to PxeBc private data. - - @retval EFI_SUCCESS Operational successful. - @retval EFI_NO_RESPONSE Offer dhcp service failed. - @retval EFI_BUFFER_TOO_SMALL Failed to copy the packet to Pxe base= code mode. - -**/ -EFI_STATUS -PxeBcCheckSelectedOffer ( - IN PXEBC_PRIVATE_DATA *Private - ) -{ - PXEBC_CACHED_DHCP4_PACKET *SelectedOffer; - EFI_DHCP4_PACKET_OPTION **Options; - UINT32 Index; - EFI_DHCP4_PACKET *Offer; - UINT32 ProxyOfferIndex; - EFI_STATUS Status; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_DHCP4_PACKET *Ack; - - ASSERT (Private->SelectedOffer !=3D 0); - - Status =3D EFI_SUCCESS; - SelectedOffer =3D &Private->Dhcp4Offers[Private->SelectedOffer - 1]; - Options =3D SelectedOffer->Dhcp4Option; - - if (SelectedOffer->OfferType =3D=3D DHCP4_PACKET_TYPE_BINL) { - // - // The addresses are acquired from a BINL dhcp offer, try BINL to get - // the bootfile name - // - if (!PxeBcTryBinl (Private, Private->SelectedOffer - 1)) { - Status =3D EFI_NO_RESPONSE; - } - } else if (SelectedOffer->OfferType =3D=3D DHCP4_PACKET_TYPE_DHCP_ONLY) = { - // - // The selected offer to finish the D.O.R.A. is a DHCP only offer, we = need - // try proxy offers if there are some, othewise the bootfile name must= be - // set in this DHCP only offer. - // - if (Private->GotProxyOffer) { - // - // Get rid of the compiler warning. - // - ProxyOfferIndex =3D 0; - if (Private->SortOffers) { - // - // The offers are sorted before selecting, the proxy offer type mu= st be - // already determined. - // - ASSERT (Private->ProxyIndex[Private->ProxyOfferType] > 0); - - if (Private->ProxyOfferType =3D=3D DHCP4_PACKET_TYPE_BINL) { - // - // We buffer all received BINL proxy offers, try them all one by= one - // - if (!PxeBcTryBinlProxy (Private, &ProxyOfferIndex)) { - Status =3D EFI_NO_RESPONSE; - } - } else { - // - // For other types, only one proxy offer is buffered. - // - ProxyOfferIndex =3D Private->ProxyIndex[Private->ProxyOfferType]= - 1; - } - } else { - // - // The proxy offer type is not determined, choose proxy offer in t= he - // received order. - // - Status =3D EFI_NO_RESPONSE; - - ASSERT (Private->NumOffers < PXEBC_MAX_OFFER_NUM); - for (Index =3D 0; Index < Private->NumOffers; Index++) { - - Offer =3D &Private->Dhcp4Offers[Index].Packet.Offer; - if (!IS_PROXY_DHCP_OFFER (Offer)) { - // - // Skip non proxy dhcp offers. - // - continue; - } - - if (Private->Dhcp4Offers[Index].OfferType =3D=3D DHCP4_PACKET_TY= PE_BINL) { - // - // Try BINL - // - if (!PxeBcTryBinl (Private, Index)) { - // - // Failed, skip to the next offer - // - continue; - } - } - - Private->ProxyOfferType =3D Private->Dhcp4Offers[Index].OfferTyp= e; - ProxyOfferIndex =3D Index; - Status =3D EFI_SUCCESS; - break; - } - } - - if (!EFI_ERROR (Status) && (Private->ProxyOfferType !=3D DHCP4_PACKE= T_TYPE_BINL)) { - // - // Copy the proxy offer to Mode and set the flag - // - Status =3D PxeBcCopyProxyOffer (Private, ProxyOfferIndex); - } - } else { - // - // No proxy offer is received, the bootfile name MUST be set. - // - ASSERT (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] !=3D NULL); - } - } - - if (!EFI_ERROR (Status)) { - // - // Everything is OK, set the flag and copy the DHCP packets. - // - Mode =3D Private->PxeBc.Mode; - Offer =3D &SelectedOffer->Packet.Offer; - - // - // The discover packet is already copied, just set flag here. - // - Mode->DhcpDiscoverValid =3D TRUE; - - Ack =3D &Private->Dhcp4Ack.Packet.Ack; - if (SelectedOffer->OfferType =3D=3D DHCP4_PACKET_TYPE_BOOTP) { - // - // Other type of ACK is already cached. Bootp is special that we sho= uld - // use the bootp reply as the ACK and put it into the DHCP_ONLY buff= er. - // - Status =3D PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, O= ffer); - } - - PxeBcParseCachedDhcpPacket (&Private->Dhcp4Ack); - - Mode->DhcpAckReceived =3D TRUE; - - // - // Copy the dhcp ack. - // - CopyMem (&Mode->DhcpAck, &Ack->Dhcp4, Ack->Length); - } - - return Status; -} - - -/** - Cache the Dhcp4 packet offer, Parse and validate each option of the pack= et. - - @param Private Pointer to PxeBc private data. - @param RcvdOffer Pointer to the received Dhcp proxy offer packet. - - @retval EFI_SUCCESS Cache and parse the packet successfully. - @retval Others Operation failed. - -**/ -EFI_STATUS -PxeBcCacheDhcpOffer ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_DHCP4_PACKET *RcvdOffer - ) -{ - PXEBC_CACHED_DHCP4_PACKET *CachedOffer; - EFI_DHCP4_PACKET *Offer; - UINT8 OfferType; - EFI_STATUS Status; - - CachedOffer =3D &Private->Dhcp4Offers[Private->NumOffers]; - Offer =3D &CachedOffer->Packet.Offer; - - // - // Cache the orignal dhcp packet - // - Status =3D PxeBcCopyEfiDhcp4Packet (Offer, RcvdOffer); - if (EFI_ERROR(Status)) { - return Status; - } - - // - // Parse and validate the options (including dhcp option and vendor opti= on) - // - if (!PxeBcParseCachedDhcpPacket (CachedOffer)) { - return EFI_ABORTED; - } - - OfferType =3D CachedOffer->OfferType; - if (OfferType >=3D DHCP4_PACKET_TYPE_MAX) { - return EFI_ABORTED; - } - - if (OfferType =3D=3D DHCP4_PACKET_TYPE_BOOTP) { - - if (Private->BootpIndex !=3D 0) { - // - // Only cache the first bootp offer, discard others. - // - return EFI_ABORTED; - } else { - // - // Take as a dhcp only offer, but record index specifically. - // - Private->BootpIndex =3D Private->NumOffers + 1; - } - } else { - - if (IS_PROXY_DHCP_OFFER (Offer)) { - // - // It's a proxy dhcp offer with no your address, including pxe10, wf= m11a or binl offer. - // - Private->GotProxyOffer =3D TRUE; - - if (OfferType =3D=3D DHCP4_PACKET_TYPE_BINL) { - // - // Cache all binl offers. - // - Private->BinlIndex[Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]] = =3D Private->NumOffers; - Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]++; - } else if (Private->ProxyIndex[OfferType] !=3D 0) { - // - // Only cache the first pxe10/wfm11a offers each, discard the othe= rs. - // - return EFI_ABORTED; - } else { - // - // Record index of the proxy dhcp offer with type other than binl. - // - Private->ProxyIndex[OfferType] =3D Private->NumOffers + 1; - } - } else { - // - // It's a dhcp offer with your address. - // - ASSERT (Private->ServerCount[OfferType] < PXEBC_MAX_OFFER_NUM); - Private->OfferIndex[OfferType][Private->ServerCount[OfferType]] =3D = Private->NumOffers; - Private->ServerCount[OfferType]++; - } - } - - // - // Count the accepted offers. - // - Private->NumOffers++; - - return EFI_SUCCESS; -} - -/** - Switch the Ip4 policy to static. - - @param[in] Private The pointer to PXEBC_PRIVATE_DATA. - - @retval EFI_SUCCESS The policy is already configured to stat= ic. - @retval Others Other error as indicated.. - -**/ -EFI_STATUS -PxeBcSetIp4Policy ( - IN PXEBC_PRIVATE_DATA *Private - ) -{ - EFI_STATUS Status; - EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; - EFI_IP4_CONFIG2_POLICY Policy; - UINTN DataSize; - - Ip4Config2 =3D Private->Ip4Config2; - DataSize =3D sizeof (EFI_IP4_CONFIG2_POLICY); - Status =3D Ip4Config2->GetData ( - Ip4Config2, - Ip4Config2DataTypePolicy, - &DataSize, - &Policy - ); - if (EFI_ERROR (Status)) { - return Status; - } - - if (Policy !=3D Ip4Config2PolicyStatic) { - Policy =3D Ip4Config2PolicyStatic; - Status=3D Ip4Config2->SetData ( - Ip4Config2, - Ip4Config2DataTypePolicy, - sizeof (EFI_IP4_CONFIG2_POLICY), - &Policy - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - - return EFI_SUCCESS; -} - - -/** - Select the specified proxy offer, such as BINL, DHCP_ONLY and so on. - If the proxy does not exist, try offers with bootfile. - - @param Private Pointer to PxeBc private data. - -**/ -VOID -PxeBcSelectOffer ( - IN PXEBC_PRIVATE_DATA *Private - ) -{ - UINT32 Index; - UINT32 OfferIndex; - EFI_DHCP4_PACKET *Offer; - - Private->SelectedOffer =3D 0; - - if (Private->SortOffers) { - // - // Select offer according to the priority - // - if (Private->ServerCount[DHCP4_PACKET_TYPE_PXE10] > 0) { - // - // DHCP with PXE10 - // - Private->SelectedOffer =3D Private->OfferIndex[DHCP4_PACKET_TYPE_PXE= 10][0] + 1; - - } else if (Private->ServerCount[DHCP4_PACKET_TYPE_WFM11A] > 0) { - // - // DHCP with WfM - // - Private->SelectedOffer =3D Private->OfferIndex[DHCP4_PACKET_TYPE_WFM= 11A][0] + 1; - - } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_PXE10] > 0) && - (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0) - ) { - // - // DHCP only and proxy DHCP with PXE10 - // - Private->SelectedOffer =3D Private->OfferIndex[DHCP4_PACKET_TYPE_DHC= P_ONLY][0] + 1; - Private->ProxyOfferType =3D DHCP4_PACKET_TYPE_PXE10; - - } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_WFM11A] > 0) && - (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0) - ) { - // - // DHCP only and proxy DHCP with WfM - // - Private->SelectedOffer =3D Private->OfferIndex[DHCP4_PACKET_TYPE_DHC= P_ONLY][0] + 1; - Private->ProxyOfferType =3D DHCP4_PACKET_TYPE_WFM11A; - - } else if (Private->ServerCount[DHCP4_PACKET_TYPE_BINL] > 0) { - // - // DHCP with BINL - // - Private->SelectedOffer =3D Private->OfferIndex[DHCP4_PACKET_TYPE_BIN= L][0] + 1; - - } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL] > 0) && - (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0) - ) { - // - // DHCP only and proxy DHCP with BINL - // - Private->SelectedOffer =3D Private->OfferIndex[DHCP4_PACKET_TYPE_DHC= P_ONLY][0] + 1; - Private->ProxyOfferType =3D DHCP4_PACKET_TYPE_BINL; - - } else { - // - // Try offers with bootfile - // - for (Index =3D 0; Index < Private->ServerCount[DHCP4_PACKET_TYPE_DHC= P_ONLY]; Index++) { - // - // Select the first DHCP only offer with bootfile - // - OfferIndex =3D Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][In= dex]; - if (Private->Dhcp4Offers[OfferIndex].Dhcp4Option[PXEBC_DHCP4_TAG_I= NDEX_BOOTFILE] !=3D NULL) { - Private->SelectedOffer =3D OfferIndex + 1; - break; - } - } - - if (Private->SelectedOffer =3D=3D 0) { - // - // Select the Bootp reply with bootfile if any - // - Private->SelectedOffer =3D Private->BootpIndex; - } - } - } else { - // - // Try the offers in the received order. - // - for (Index =3D 0; Index < Private->NumOffers; Index++) { - - Offer =3D &Private->Dhcp4Offers[Index].Packet.Offer; - - if (IS_PROXY_DHCP_OFFER (Offer)) { - // - // Skip proxy offers - // - continue; - } - - if ((Private->Dhcp4Offers[Index].OfferType =3D=3D DHCP4_PACKET_TYPE_= DHCP_ONLY) && - ((!Private->GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4= Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] =3D=3D NULL))) { - // - // DHCP only offer but no proxy offer received and no bootfile opt= ion in this offer - // - continue; - } - - Private->SelectedOffer =3D Index + 1; - break; - } - } -} - - -/** - Callback routine. - - EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protoco= l driver - to intercept events that occurred in the configuration process. This str= ucture - provides advanced control of each state transition of the DHCP process. = The - returned status code determines the behavior of the EFI DHCPv4 Protocol = driver. - There are three possible returned values, which are described in the fol= lowing - table. - - @param This Pointer to the EFI DHCPv4 Protocol instanc= e that is used to - configure this callback function. - @param Context Pointer to the context that is initialized= by - EFI_DHCP4_PROTOCOL.Configure(). - @param CurrentState The current operational state of the EFI D= HCPv4 Protocol - driver. - @param Dhcp4Event The event that occurs in the current state= , which usually means a - state transition. - @param Packet The DHCP packet that is going to be sent o= r already received. - @param NewPacket The packet that is used to replace the abo= ve Packet. - - @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to co= ntinue the DHCP process. - @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The= EFI DHCPv4 Protocol - driver will continue to wait for more DHCP= OFFER packets until the retry - timeout expires. - @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to ab= ort the current process and - return to the Dhcp4Init or Dhcp4InitReboot= state. - -**/ -EFI_STATUS -EFIAPI -PxeBcDhcpCallBack ( - IN EFI_DHCP4_PROTOCOL * This, - IN VOID *Context, - IN EFI_DHCP4_STATE CurrentState, - IN EFI_DHCP4_EVENT Dhcp4Event, - IN EFI_DHCP4_PACKET * Packet OPTIONAL, - OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback; - EFI_DHCP4_PACKET_OPTION *MaxMsgSize; - UINT16 Value; - EFI_STATUS Status; - BOOLEAN Received; - EFI_DHCP4_HEADER *DhcpHeader; - - if ((Dhcp4Event !=3D Dhcp4RcvdOffer) && - (Dhcp4Event !=3D Dhcp4SelectOffer) && - (Dhcp4Event !=3D Dhcp4SendDiscover) && - (Dhcp4Event !=3D Dhcp4RcvdAck) && - (Dhcp4Event !=3D Dhcp4SendRequest)) { - return EFI_SUCCESS; - } - - Private =3D (PXEBC_PRIVATE_DATA *) Context; - Mode =3D Private->PxeBc.Mode; - Callback =3D Private->PxeBcCallback; - - // - // Override the Maximum DHCP Message Size. - // - MaxMsgSize =3D PxeBcParseExtendOptions ( - Packet->Dhcp4.Option, - GET_OPTION_BUFFER_LEN (Packet), - DHCP4_TAG_MAXMSG - ); - if (MaxMsgSize !=3D NULL) { - Value =3D HTONS (PXEBC_DHCP4_MAX_PACKET_SIZE); - CopyMem (MaxMsgSize->Data, &Value, sizeof (Value)); - } - - if ((Dhcp4Event !=3D Dhcp4SelectOffer) && (Callback !=3D NULL)) { - Received =3D (BOOLEAN) ((Dhcp4Event =3D=3D Dhcp4RcvdOffer) || (Dhcp4Ev= ent =3D=3D Dhcp4RcvdAck)); - Status =3D Callback->Callback ( - Callback, - Private->Function, - Received, - Packet->Length, - (EFI_PXE_BASE_CODE_PACKET *) &Packet->Dhcp4 - ); - if (Status !=3D EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) { - return EFI_ABORTED; - } - } - - Status =3D EFI_SUCCESS; - - switch (Dhcp4Event) { - - case Dhcp4SendDiscover: - case Dhcp4SendRequest: - if (Packet->Length > PXEBC_DHCP4_MAX_PACKET_SIZE) { - // - // If the to be sent packet exceeds the maximum length, abort the DH= CP process. - // - Status =3D EFI_ABORTED; - break; - } - - if (Mode->SendGUID) { - // - // send the system GUID instead of the MAC address as the hardware a= ddress - // in the DHCP packet header. - // - DhcpHeader =3D &Packet->Dhcp4.Header; - - if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientH= wAddr))) { - // - // GUID not yet set - send all 0xff's to show programable (via Set= Variable) - // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GU= ID), 0xff); - // GUID not yet set - send all 0's to show not programable - // - DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbi= os table!\n")); - ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID)); - } - - DhcpHeader->HwAddrLen =3D (UINT8) sizeof (EFI_GUID); - } - - if (Dhcp4Event =3D=3D Dhcp4SendDiscover) { - // - // Cache the dhcp discover packet, of which some information will be= used later. - // - CopyMem (Mode->DhcpDiscover.Raw, &Packet->Dhcp4, Packet->Length); - } - - break; - - case Dhcp4RcvdOffer: - Status =3D EFI_NOT_READY; - if (Packet->Length > PXEBC_DHCP4_MAX_PACKET_SIZE) { - // - // Ignore the incoming Offers which exceed the maximum length. - // - break; - } - - if (Private->NumOffers < PXEBC_MAX_OFFER_NUM) { - // - // Cache the dhcp offers in Private->Dhcp4Offers[] - // If error happens, just ignore this packet and continue to wait mo= re offer. - // - PxeBcCacheDhcpOffer (Private, Packet); - } - - break; - - case Dhcp4SelectOffer: - // - // Select an offer, if succeeded, Private->SelectedOffer points to - // the index of the selected one. - // - PxeBcSelectOffer (Private); - - if (Private->SelectedOffer =3D=3D 0) { - Status =3D EFI_ABORTED; - } else { - *NewPacket =3D &Private->Dhcp4Offers[Private->SelectedOffer - 1].Pac= ket.Offer; - } - - break; - - case Dhcp4RcvdAck: - // - // Cache Ack - // - ASSERT (Private->SelectedOffer !=3D 0); - - Status =3D PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Pac= ket); - if (EFI_ERROR (Status)) { - return EFI_ABORTED; - } - break; - - default: - break; - } - - return Status; -} - - -/** - Initialize the DHCP options and build the option list. - - @param Private Pointer to PxeBc private data. - @param OptList Pointer to a DHCP option list. - - @param IsDhcpDiscover Discover dhcp option or not. - - @return The index item number of the option list. - -**/ -UINT32 -PxeBcBuildDhcpOptions ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_DHCP4_PACKET_OPTION **OptList, - IN BOOLEAN IsDhcpDiscover - ) -{ - UINT32 Index; - PXEBC_DHCP4_OPTION_ENTRY OptEnt; - UINT16 Value; - - Index =3D 0; - OptList[0] =3D (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer; - - if (!IsDhcpDiscover) { - // - // Append message type. - // - OptList[Index]->OpCode =3D DHCP4_TAG_MSG_TYPE; - OptList[Index]->Length =3D 1; - OptEnt.Mesg =3D (PXEBC_DHCP4_OPTION_MESG *) OptList[Index]= ->Data; - OptEnt.Mesg->Type =3D PXEBC_DHCP4_MSG_TYPE_REQUEST; - Index++; - OptList[Index] =3D GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - - // - // Append max message size. - // - OptList[Index]->OpCode =3D DHCP4_TAG_MAXMSG; - OptList[Index]->Length =3D (UINT8) sizeof (PXEBC_DHCP4_OPTION_MAX_MES= G_SIZE); - OptEnt.MaxMesgSize =3D (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *) OptLi= st[Index]->Data; - Value =3D NTOHS (PXEBC_DHCP4_MAX_PACKET_SIZE); - CopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16)); - Index++; - OptList[Index] =3D GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - } - // - // Parameter request list option. - // - OptList[Index]->OpCode =3D DHCP4_TAG_PARA_LIST; - OptList[Index]->Length =3D 35; - OptEnt.Para =3D (PXEBC_DHCP4_OPTION_PARA *) OptList[Index]= ->Data; - OptEnt.Para->ParaList[0] =3D DHCP4_TAG_NETMASK; - OptEnt.Para->ParaList[1] =3D DHCP4_TAG_TIME_OFFSET; - OptEnt.Para->ParaList[2] =3D DHCP4_TAG_ROUTER; - OptEnt.Para->ParaList[3] =3D DHCP4_TAG_TIME_SERVER; - OptEnt.Para->ParaList[4] =3D DHCP4_TAG_NAME_SERVER; - OptEnt.Para->ParaList[5] =3D DHCP4_TAG_DNS_SERVER; - OptEnt.Para->ParaList[6] =3D DHCP4_TAG_HOSTNAME; - OptEnt.Para->ParaList[7] =3D DHCP4_TAG_BOOTFILE_LEN; - OptEnt.Para->ParaList[8] =3D DHCP4_TAG_DOMAINNAME; - OptEnt.Para->ParaList[9] =3D DHCP4_TAG_ROOTPATH; - OptEnt.Para->ParaList[10] =3D DHCP4_TAG_EXTEND_PATH; - OptEnt.Para->ParaList[11] =3D DHCP4_TAG_EMTU; - OptEnt.Para->ParaList[12] =3D DHCP4_TAG_TTL; - OptEnt.Para->ParaList[13] =3D DHCP4_TAG_BROADCAST; - OptEnt.Para->ParaList[14] =3D DHCP4_TAG_NIS_DOMAIN; - OptEnt.Para->ParaList[15] =3D DHCP4_TAG_NIS_SERVER; - OptEnt.Para->ParaList[16] =3D DHCP4_TAG_NTP_SERVER; - OptEnt.Para->ParaList[17] =3D DHCP4_TAG_VENDOR; - OptEnt.Para->ParaList[18] =3D DHCP4_TAG_REQUEST_IP; - OptEnt.Para->ParaList[19] =3D DHCP4_TAG_LEASE; - OptEnt.Para->ParaList[20] =3D DHCP4_TAG_SERVER_ID; - OptEnt.Para->ParaList[21] =3D DHCP4_TAG_T1; - OptEnt.Para->ParaList[22] =3D DHCP4_TAG_T2; - OptEnt.Para->ParaList[23] =3D DHCP4_TAG_VENDOR_CLASS_ID; - OptEnt.Para->ParaList[24] =3D DHCP4_TAG_TFTP; - OptEnt.Para->ParaList[25] =3D DHCP4_TAG_BOOTFILE; - OptEnt.Para->ParaList[26] =3D DHCP4_TAG_UUID; - OptEnt.Para->ParaList[27] =3D 0x80; - OptEnt.Para->ParaList[28] =3D 0x81; - OptEnt.Para->ParaList[29] =3D 0x82; - OptEnt.Para->ParaList[30] =3D 0x83; - OptEnt.Para->ParaList[31] =3D 0x84; - OptEnt.Para->ParaList[32] =3D 0x85; - OptEnt.Para->ParaList[33] =3D 0x86; - OptEnt.Para->ParaList[34] =3D 0x87; - Index++; - OptList[Index] =3D GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - - // - // Append UUID/Guid-based client identifier option - // - OptList[Index]->OpCode =3D DHCP4_TAG_UUID; - OptList[Index]->Length =3D (UINT8) sizeof (PXEBC_DHCP4_OPTION_UUID); - OptEnt.Uuid =3D (PXEBC_DHCP4_OPTION_UUID *) OptList[Index]->= Data; - OptEnt.Uuid->Type =3D 0; - Index++; - OptList[Index] =3D GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - - if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) { - // - // GUID not yet set - send all 0xff's to show programable (via SetVari= able) - // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID),= 0xff); - // GUID not yet set - send all 0's to show not programable - // - DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbios t= able!\n")); - ZeroMem (OptEnt.Uuid->Guid, sizeof (EFI_GUID)); - } - - // - // Append client network device interface option - // - OptList[Index]->OpCode =3D DHCP4_TAG_UNDI; - OptList[Index]->Length =3D (UINT8) sizeof (PXEBC_DHCP4_OPTION_UNDI); - OptEnt.Undi =3D (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->= Data; - if (Private->Nii !=3D NULL) { - OptEnt.Undi->Type =3D Private->Nii->Type; - OptEnt.Undi->MajorVer =3D Private->Nii->MajorVer; - OptEnt.Undi->MinorVer =3D Private->Nii->MinorVer; - } else { - OptEnt.Undi->Type =3D DEFAULT_UNDI_TYPE; - OptEnt.Undi->MajorVer =3D DEFAULT_UNDI_MAJOR; - OptEnt.Undi->MinorVer =3D DEFAULT_UNDI_MINOR; - } - - Index++; - OptList[Index] =3D GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - - // - // Append client system architecture option - // - OptList[Index]->OpCode =3D DHCP4_TAG_ARCH; - OptList[Index]->Length =3D (UINT8) sizeof (PXEBC_DHCP4_OPTION_ARCH); - OptEnt.Arch =3D (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->= Data; - Value =3D HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE); - CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16)); - Index++; - OptList[Index] =3D GET_NEXT_DHCP_OPTION (OptList[Index - 1]); - - // - // Append client system architecture option - // - OptList[Index]->OpCode =3D DHCP4_TAG_VENDOR_CLASS_ID; - OptList[Index]->Length =3D (UINT8) sizeof (PXEBC_DHCP4_OPTION_CLID); - OptEnt.Clid =3D (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->= Data; - CopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_= CLID)); - CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureTyp= e, sizeof (OptEnt.Clid->ArchitectureType)); - - if (Private->Nii !=3D NULL) { - // - // If NII protocol exists, update DHCP option data - // - CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (O= ptEnt.Clid->InterfaceName)); - CvtNum (Private->Nii->MajorVer, OptEnt.Clid->UndiMajor, sizeof (OptEnt= .Clid->UndiMajor)); - CvtNum (Private->Nii->MinorVer, OptEnt.Clid->UndiMinor, sizeof (OptEnt= .Clid->UndiMinor)); - } - - Index++; - - return Index; -} - - -/** - Discover the boot of service and initialize the vendor option if exists. - - @param Private Pointer to PxeBc private data. - @param Type PxeBc option boot item type - @param Layer PxeBc option boot item layer - @param UseBis Use BIS or not - @param DestIp Ip address for server - @param IpCount The total count of the server ip address - @param SrvList Server list - @param IsDiscv Discover the vendor or not - @param Reply The dhcp4 packet of Pxe reply - - @retval EFI_SUCCESS Operation succeeds. - @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed. - @retval EFI_NOT_FOUND There is no vendor option exists. - @retval EFI_TIMEOUT Send Pxe Discover time out. - -**/ -EFI_STATUS -PxeBcDiscvBootService ( - IN PXEBC_PRIVATE_DATA * Private, - IN UINT16 Type, - IN UINT16 *Layer, - IN BOOLEAN UseBis, - IN EFI_IP_ADDRESS * DestIp, - IN UINT16 IpCount, - IN EFI_PXE_BASE_CODE_SRVLIST * SrvList, - IN BOOLEAN IsDiscv, - OUT EFI_DHCP4_PACKET * Reply OPTIONAL - ) -{ - EFI_PXE_BASE_CODE_UDP_PORT Sport; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_DHCP4_PROTOCOL *Dhcp4; - EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN Token; - BOOLEAN IsBCast; - EFI_STATUS Status; - UINT16 RepIndex; - UINT16 SrvIndex; - UINT16 TryIndex; - EFI_DHCP4_LISTEN_POINT ListenPoint; - EFI_DHCP4_PACKET *Response; - EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM]= ; - UINT32 OptCount; - EFI_DHCP4_PACKET_OPTION *PxeOpt; - PXEBC_OPTION_BOOT_ITEM *PxeBootItem; - UINT8 VendorOptLen; - EFI_DHCP4_HEADER *DhcpHeader; - UINT32 Xid; - - Mode =3D Private->PxeBc.Mode; - Dhcp4 =3D Private->Dhcp4; - Status =3D EFI_SUCCESS; - - ZeroMem (&Token, sizeof (EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN)); - - if (DestIp =3D=3D NULL) { - Sport =3D PXEBC_DHCP4_S_PORT; - IsBCast =3D TRUE; - } else { - Sport =3D PXEBC_BS_DISCOVER_PORT; - IsBCast =3D FALSE; - } - - if (!UseBis && Layer !=3D NULL) { - *Layer &=3D EFI_PXE_BASE_CODE_BOOT_LAYER_MASK; - } - - OptCount =3D PxeBcBuildDhcpOptions (Private, OptList, FALSE); - - if (IsDiscv) { - ASSERT (Layer !=3D NULL); - // - // Add vendor option of PXE_BOOT_ITEM - // - VendorOptLen =3D (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 += sizeof (PXEBC_OPTION_BOOT_ITEM) + 1); - OptList[OptCount] =3D AllocatePool (VendorOptLen); - if (OptList[OptCount] =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - OptList[OptCount]->OpCode =3D DHCP4_TAG_VENDOR; - OptList[OptCount]->Length =3D (UINT8) (VendorOptLen - 2); - PxeOpt =3D (EFI_DHCP4_PACKET_OPTION *) OptList[= OptCount]->Data; - PxeOpt->OpCode =3D PXEBC_VENDOR_TAG_BOOT_ITEM; - PxeOpt->Length =3D (UINT8) sizeof (PXEBC_OPTION_BOOT_IT= EM); - PxeBootItem =3D (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->D= ata; - PxeBootItem->Type =3D HTONS (Type); - PxeBootItem->Layer =3D HTONS (*Layer); - PxeOpt->Data[PxeOpt->Length] =3D DHCP4_TAG_EOP; - - OptCount++; - } - - Status =3D Dhcp4->Build (Dhcp4, &Private->SeedPacket, 0, NULL, OptCount,= OptList, &Token.Packet); - - if (IsDiscv) { - FreePool (OptList[OptCount - 1]); - } - - if (EFI_ERROR (Status)) { - return Status; - } - - DhcpHeader =3D &Token.Packet->Dhcp4.Header; - if (Mode->SendGUID) { - if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwA= ddr))) { - // - // GUID not yet set - send all 0's to show not programable - // - DEBUG ((EFI_D_WARN, "PXE: Failed to read system GUID from the smbios= table!\n")); - ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID)); - } - - DhcpHeader->HwAddrLen =3D (UINT8) sizeof (EFI_GUID); - } - - Xid =3D NET_RANDOM (NetRandomInitSeed ()= ); - Token.Packet->Dhcp4.Header.Xid =3D HTONL(Xid); - Token.Packet->Dhcp4.Header.Reserved =3D HTONS((UINT16) ((IsBCast) ? 0x80= 00 : 0)); - CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, si= zeof (EFI_IPv4_ADDRESS)); - - Token.RemotePort =3D Sport; - - if (IsBCast) { - SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff); - } else { - CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS)); - } - - CopyMem (&Token.GatewayAddress, &Private->GatewayIp, sizeof (EFI_IPv4_AD= DRESS)); - - if (!IsBCast) { - Token.ListenPointCount =3D 1; - Token.ListenPoints =3D &ListenPoint; - Token.ListenPoints[0].ListenPort =3D PXEBC_BS_DISCOVER_PORT; - CopyMem (&Token.ListenPoints[0].ListenAddress, &Private->StationIp, si= zeof(EFI_IPv4_ADDRESS)); - CopyMem (&Token.ListenPoints[0].SubnetMask, &Private->SubnetMask, size= of(EFI_IPv4_ADDRESS)); - } - // - // Send Pxe Discover - // - for (TryIndex =3D 1; TryIndex <=3D PXEBC_BOOT_REQUEST_RETRIES; TryIndex+= +) { - - Token.TimeoutValue =3D (UINT16) (PXEBC_BOOT_REQUEST_T= IMEOUT * TryIndex); - Token.Packet->Dhcp4.Header.Seconds =3D (UINT16) (PXEBC_BOOT_REQUEST_T= IMEOUT * (TryIndex - 1)); - - Status =3D Dhcp4->TransmitReceive (Dhcp4, &Token); - - if (Token.Status !=3D EFI_TIMEOUT) { - break; - } - } - - if (TryIndex > PXEBC_BOOT_REQUEST_RETRIES) { - // - // No server response our PXE request - // - Status =3D EFI_TIMEOUT; - } - - if (!EFI_ERROR (Status)) { - // - // Find Pxe Reply - // - RepIndex =3D 0; - SrvIndex =3D 0; - Response =3D Token.ResponseList; - - while (RepIndex < Token.ResponseCount) { - if (Response->Length > PXEBC_DHCP4_MAX_PACKET_SIZE) { - SrvIndex =3D 0; - RepIndex++; - Response =3D (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->= Size); - continue; - } - - while (SrvIndex < IpCount) { - - if (SrvList[SrvIndex].AcceptAnyResponse) { - break; - } - - if ((SrvList[SrvIndex].Type =3D=3D Type) && EFI_IP4_EQUAL (&(Respo= nse->Dhcp4.Header.ServerAddr), &(Private->ServerIp))) { - break; - } - - SrvIndex++; - } - - if ((IpCount !=3D SrvIndex) || (IpCount =3D=3D 0)) { - break; - } - - SrvIndex =3D 0; - RepIndex++; - Response =3D (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->Si= ze); - } - - if (RepIndex < Token.ResponseCount) { - - if (Reply !=3D NULL) { - Status =3D PxeBcCopyEfiDhcp4Packet (Reply, Response); - if (EFI_ERROR(Status)) { - goto ON_EXIT; - } - } - - if (IsDiscv) { - CopyMem (&(Mode->PxeDiscover), &(Token.Packet->Dhcp4), Token.Packe= t->Length); - Mode->PxeDiscoverValid =3D TRUE; - - CopyMem (Mode->PxeReply.Raw, &Response->Dhcp4, Response->Length); - Mode->PxeReplyReceived =3D TRUE; - } - } else { - Status =3D EFI_NOT_FOUND; - } - } - -ON_EXIT: - // - // free the responselist - // - if (Token.ResponseList !=3D NULL) { - FreePool (Token.ResponseList); - } - // - // Free the dhcp packet - // - if (Token.Packet !=3D NULL) { - FreePool (Token.Packet); - } - - return Status; -} - - -/** - Parse interested dhcp options. - - @param Buffer Pointer to the dhcp options packet. - @param Length The length of the dhcp options. - @param OptTag The option OpCode. - - @return NULL if the buffer length is 0 and OpCode is not - DHCP4_TAG_EOP, or the pointer to the buffer. - -**/ -EFI_DHCP4_PACKET_OPTION * -PxeBcParseExtendOptions ( - IN UINT8 *Buffer, - IN UINT32 Length, - IN UINT8 OptTag - ) -{ - EFI_DHCP4_PACKET_OPTION *Option; - UINT32 Offset; - - Option =3D (EFI_DHCP4_PACKET_OPTION *) Buffer; - Offset =3D 0; - - while (Offset < Length && Option->OpCode !=3D DHCP4_TAG_EOP) { - - if (Option->OpCode =3D=3D OptTag) { - - return Option; - } - - if (Option->OpCode =3D=3D DHCP4_TAG_PAD) { - Offset++; - } else { - Offset +=3D Option->Length + 2; - } - - Option =3D (EFI_DHCP4_PACKET_OPTION *) (Buffer + Offset); - } - - return NULL; -} - - -/** - This function is to parse and check vendor options. - - @param Dhcp4Option Pointer to dhcp options - @param VendorOption Pointer to vendor options - - @return TRUE if valid for vendor options, or FALSE. - -**/ -BOOLEAN -PxeBcParseVendorOptions ( - IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option, - IN PXEBC_VENDOR_OPTION *VendorOption - ) -{ - UINT32 *BitMap; - UINT8 VendorOptionLen; - EFI_DHCP4_PACKET_OPTION *PxeOption; - UINT8 Offset; - - BitMap =3D VendorOption->BitMap; - VendorOptionLen =3D Dhcp4Option->Length; - PxeOption =3D (EFI_DHCP4_PACKET_OPTION *) &Dhcp4Option->Data[0]; - Offset =3D 0; - - while ((Offset < VendorOptionLen) && (PxeOption->OpCode !=3D DHCP4_TAG_E= OP)) { - // - // Parse every Vendor Option and set its BitMap - // - switch (PxeOption->OpCode) { - - case PXEBC_VENDOR_TAG_MTFTP_IP: - - CopyMem (&VendorOption->MtftpIp, PxeOption->Data, sizeof (EFI_IPv4_A= DDRESS)); - break; - - case PXEBC_VENDOR_TAG_MTFTP_CPORT: - - CopyMem (&VendorOption->MtftpCPort, PxeOption->Data, sizeof (VendorO= ption->MtftpCPort)); - break; - - case PXEBC_VENDOR_TAG_MTFTP_SPORT: - - CopyMem (&VendorOption->MtftpSPort, PxeOption->Data, sizeof (VendorO= ption->MtftpSPort)); - break; - - case PXEBC_VENDOR_TAG_MTFTP_TIMEOUT: - - VendorOption->MtftpTimeout =3D *PxeOption->Data; - break; - - case PXEBC_VENDOR_TAG_MTFTP_DELAY: - - VendorOption->MtftpDelay =3D *PxeOption->Data; - break; - - case PXEBC_VENDOR_TAG_DISCOVER_CTRL: - - VendorOption->DiscoverCtrl =3D *PxeOption->Data; - break; - - case PXEBC_VENDOR_TAG_DISCOVER_MCAST: - - CopyMem (&VendorOption->DiscoverMcastIp, PxeOption->Data, sizeof (EF= I_IPv4_ADDRESS)); - break; - - case PXEBC_VENDOR_TAG_BOOT_SERVERS: - - VendorOption->BootSvrLen =3D PxeOption->Length; - VendorOption->BootSvr =3D (PXEBC_BOOT_SVR_ENTRY *) PxeOption->Da= ta; - break; - - case PXEBC_VENDOR_TAG_BOOT_MENU: - - VendorOption->BootMenuLen =3D PxeOption->Length; - VendorOption->BootMenu =3D (PXEBC_BOOT_MENU_ENTRY *) PxeOption->D= ata; - break; - - case PXEBC_VENDOR_TAG_MENU_PROMPT: - - VendorOption->MenuPromptLen =3D PxeOption->Length; - VendorOption->MenuPrompt =3D (PXEBC_MENU_PROMPT *) PxeOption->Dat= a; - break; - - case PXEBC_VENDOR_TAG_MCAST_ALLOC: - - CopyMem (&VendorOption->McastIpBase, PxeOption->Data, sizeof (EFI_IP= v4_ADDRESS)); - CopyMem (&VendorOption->McastIpBlock, PxeOption->Data + 4, sizeof (V= endorOption->McastIpBlock)); - CopyMem (&VendorOption->McastIpRange, PxeOption->Data + 6, sizeof (V= endorOption->McastIpRange)); - break; - - case PXEBC_VENDOR_TAG_CREDENTIAL_TYPES: - - VendorOption->CredTypeLen =3D PxeOption->Length; - VendorOption->CredType =3D (UINT32 *) PxeOption->Data; - break; - - case PXEBC_VENDOR_TAG_BOOT_ITEM: - - CopyMem (&VendorOption->BootSrvType, PxeOption->Data, sizeof (Vendor= Option->BootSrvType)); - CopyMem (&VendorOption->BootSrvLayer, PxeOption->Data + 2, sizeof (V= endorOption->BootSrvLayer)); - break; - } - - SET_VENDOR_OPTION_BIT_MAP (BitMap, PxeOption->OpCode); - - if (PxeOption->OpCode =3D=3D DHCP4_TAG_PAD) { - Offset++; - } else { - Offset =3D (UINT8) (Offset + PxeOption->Length + 2); - } - - PxeOption =3D (EFI_DHCP4_PACKET_OPTION *) (Dhcp4Option->Data + Offset)= ; - } - - // - // FixMe, return falas if invalid of any vendor option - // - - return TRUE; -} - - -/** - This function display boot item detail. - - If the length of the boot item string over 70 Char, just display 70 Char= . - - @param Str Pointer to a string (boot item string). - @param Len The length of string. - -**/ -VOID -PxeBcDisplayBootItem ( - IN UINT8 *Str, - IN UINT8 Len - ) -{ - UINT8 Tmp; - - Len =3D (UINT8) MIN (70, Len); - Tmp =3D Str[Len]; - Str[Len] =3D 0; - AsciiPrint ("%a \n", Str); - Str[Len] =3D Tmp; -} - - -/** - Choose the boot prompt. - - @param Private Pointer to PxeBc private data. - - @retval EFI_SUCCESS Select boot prompt done. - @retval EFI_TIMEOUT Select boot prompt time out. - @retval EFI_NOT_FOUND The proxy offer is not Pxe10. - @retval EFI_ABORTED User cancel the operation. - @retval EFI_NOT_READY Read the input key from the keybroad has no= t finish. - -**/ -EFI_STATUS -PxeBcSelectBootPrompt ( - IN PXEBC_PRIVATE_DATA *Private - ) -{ - PXEBC_CACHED_DHCP4_PACKET *Packet; - PXEBC_VENDOR_OPTION *VendorOpt; - EFI_EVENT TimeoutEvent; - EFI_EVENT DescendEvent; - EFI_INPUT_KEY InputKey; - EFI_STATUS Status; - UINT8 Timeout; - UINT8 *Prompt; - UINT8 PromptLen; - INT32 SecCol; - INT32 SecRow; - - TimeoutEvent =3D NULL; - DescendEvent =3D NULL; - - if (Private->PxeBc.Mode->ProxyOfferReceived) { - - Packet =3D &Private->ProxyOffer; - } else { - - Packet =3D &Private->Dhcp4Ack; - } - - if (Packet->OfferType !=3D DHCP4_PACKET_TYPE_PXE10) { - return EFI_NOT_FOUND; - } - - VendorOpt =3D &Packet->PxeVendorOption; - // - // According to the PXE specification 2.1, Table 2-1 PXE DHCP Options (= Full - // List), we must not consider a boot prompt or boot menu if all of the - // following hold: - // - the PXE_DISCOVERY_CONTROL PXE tag is present inside the Vendor Opti= ons - // (=3D43) DHCP tag, and - // - the PXE_DISCOVERY_CONTROL PXE tag has bit 3 set, and - // - a boot file name has been presented with DHCP option 67. - // - if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) && - Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] !=3D NULL) { - return EFI_ABORTED; - } - - if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) { - return EFI_SUCCESS; - } - - Timeout =3D VendorOpt->MenuPrompt->Timeout; - Prompt =3D VendorOpt->MenuPrompt->Prompt; - PromptLen =3D (UINT8) (VendorOpt->MenuPromptLen - 1); - - if (Timeout =3D=3D 0) { - return EFI_SUCCESS; - } - - if (Timeout =3D=3D 255) { - return EFI_TIMEOUT; - } - - Status =3D gBS->CreateEvent ( - EVT_TIMER, - TPL_CALLBACK, - NULL, - NULL, - &TimeoutEvent - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->SetTimer ( - TimeoutEvent, - TimerRelative, - MultU64x32 (Timeout, TICKS_PER_SECOND) - ); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Status =3D gBS->CreateEvent ( - EVT_TIMER, - TPL_CALLBACK, - NULL, - NULL, - &DescendEvent - ); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Status =3D gBS->SetTimer ( - DescendEvent, - TimerPeriodic, - TICKS_PER_SECOND - ); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - SecCol =3D gST->ConOut->Mode->CursorColumn; - SecRow =3D gST->ConOut->Mode->CursorRow; - - PxeBcDisplayBootItem (Prompt, PromptLen); - - gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow)= ; - AsciiPrint ("(%d) ", Timeout--); - - while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) { - - if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) { - gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, Sec= Row); - AsciiPrint ("(%d) ", Timeout--); - } - - if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) =3D=3D EFI_NOT_R= EADY) { - - gBS->Stall (10 * TICKS_PER_MS); - continue; - } - - if (InputKey.ScanCode =3D=3D 0) { - - switch (InputKey.UnicodeChar) { - case CTRL ('c'): - Status =3D EFI_ABORTED; - break; - - case CTRL ('m'): - case 'm': - case 'M': - Status =3D EFI_TIMEOUT; - break; - - default: - continue; - } - } else { - - switch (InputKey.ScanCode) { - case SCAN_F8: - Status =3D EFI_TIMEOUT; - break; - - case SCAN_ESC: - Status =3D EFI_ABORTED; - break; - - default: - continue; - } - } - - break; - } - - gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1); - -ON_EXIT: - - if (DescendEvent !=3D NULL) { - gBS->CloseEvent (DescendEvent); - } - - if (TimeoutEvent !=3D NULL) { - gBS->CloseEvent (TimeoutEvent); - } - - return Status; -} - - -/** - Select the boot menu. - - @param Private Pointer to PxeBc private data. - @param Type The type of the menu. - @param UseDefaultItem Use default item or not. - - @retval EFI_ABORTED User cancel operation. - @retval EFI_SUCCESS Select the boot menu success. - @retval EFI_NOT_READY Read the input key from the keybroad has not fin= ish. - -**/ -EFI_STATUS -PxeBcSelectBootMenu ( - IN PXEBC_PRIVATE_DATA *Private, - OUT UINT16 *Type, - IN BOOLEAN UseDefaultItem - ) -{ - PXEBC_CACHED_DHCP4_PACKET *Packet; - PXEBC_VENDOR_OPTION *VendorOpt; - EFI_INPUT_KEY InputKey; - UINT8 MenuSize; - UINT8 MenuNum; - INT32 TopRow; - UINT16 Select; - UINT16 LastSelect; - UINT8 Index; - BOOLEAN Finish; - CHAR8 Blank[70]; - PXEBC_BOOT_MENU_ENTRY *MenuItem; - PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MAX_MENU_NUM]; - - Finish =3D FALSE; - Select =3D 0; - Index =3D 0; - *Type =3D 0; - - if (Private->PxeBc.Mode->ProxyOfferReceived) { - - Packet =3D &Private->ProxyOffer; - } else { - - Packet =3D &Private->Dhcp4Ack; - } - - ASSERT (Packet->OfferType =3D=3D DHCP4_PACKET_TYPE_PXE10); - - VendorOpt =3D &Packet->PxeVendorOption; - - if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) { - return EFI_SUCCESS; - } - - SetMem (Blank, sizeof(Blank), ' '); - - MenuSize =3D VendorOpt->BootMenuLen; - MenuItem =3D VendorOpt->BootMenu; - - if (MenuSize =3D=3D 0) { - return EFI_NOT_READY; - } - - while (MenuSize > 0) { - MenuArray[Index++] =3D MenuItem; - MenuSize =3D (UINT8) (MenuSize - (MenuItem->DescLen + 3)); - MenuItem =3D (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + = MenuItem->DescLen + 3); - if (Index >=3D PXEBC_MAX_MENU_NUM) { - break; - } - } - - if (UseDefaultItem) { - *Type =3D MenuArray[0]->Type; - *Type =3D NTOHS (*Type); - return EFI_SUCCESS; - } - - MenuNum =3D Index; - - for (Index =3D 0; Index < MenuNum; Index++) { - PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->Des= cLen); - } - - TopRow =3D gST->ConOut->Mode->CursorRow - MenuNum; - - do { - ASSERT (Select < PXEBC_MAX_MENU_NUM); - // - // highlight selected row - // - gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_= LIGHTGRAY)); - gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select); - Blank[MenuArray[Select]->DescLen] =3D 0; - AsciiPrint ("%a\r", Blank); - PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->D= escLen); - gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum); - LastSelect =3D Select; - - while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) =3D=3D EFI_NO= T_READY) { - gBS->Stall (10 * TICKS_PER_MS); - } - - if (InputKey.ScanCode =3D=3D 0) { - switch (InputKey.UnicodeChar) { - case CTRL ('c'): - InputKey.ScanCode =3D SCAN_ESC; - break; - - case CTRL ('j'): /* linefeed */ - case CTRL ('m'): /* return */ - Finish =3D TRUE; - break; - - case CTRL ('i'): /* tab */ - case ' ': - case 'd': - case 'D': - InputKey.ScanCode =3D SCAN_DOWN; - break; - - case CTRL ('h'): /* backspace */ - case 'u': - case 'U': - InputKey.ScanCode =3D SCAN_UP; - break; - - default: - InputKey.ScanCode =3D 0; - } - } - - switch (InputKey.ScanCode) { - case SCAN_LEFT: - case SCAN_UP: - if (Select > 0) { - --Select; - } - - break; - - case SCAN_DOWN: - case SCAN_RIGHT: - if (++Select =3D=3D MenuNum) { - --Select; - } - - break; - - case SCAN_PAGE_UP: - case SCAN_HOME: - Select =3D 0; - break; - - case SCAN_PAGE_DOWN: - case SCAN_END: - Select =3D (UINT16) (MenuNum - 1); - break; - - case SCAN_ESC: - return EFI_ABORTED; - } - - /* unhighlight last selected row */ - gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, = EFI_BLACK)); - gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect); - Blank[MenuArray[LastSelect]->DescLen] =3D 0; - AsciiPrint ("%a\r", Blank); - PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSe= lect]->DescLen); - gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum); - } while (!Finish); - - ASSERT (Select < PXEBC_MAX_MENU_NUM); - - // - // Swap the byte order - // - CopyMem (Type, &MenuArray[Select]->Type, sizeof (UINT16)); - *Type =3D NTOHS (*Type); - - return EFI_SUCCESS; -} - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c b/Md= eModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c deleted file mode 100644 index 76c140d8e3ff..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c +++ /dev/null @@ -1,665 +0,0 @@ -/** @file - The driver binding for UEFI PXEBC protocol. - -Copyright (c) 2007 - 2015, 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 IMPLI= ED. - -**/ - - -#include "PxeBcImpl.h" - -EFI_DRIVER_BINDING_PROTOCOL gPxeBcDriverBinding =3D { - PxeBcDriverBindingSupported, - PxeBcDriverBindingStart, - PxeBcDriverBindingStop, - 0xa, - NULL, - NULL -}; - -/** - This is the declaration of an EFI image entry point. This entry point is - the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers includ= ing - both device drivers and bus drivers. - - @param ImageHandle The firmware allocated handle for the UEFI= image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to = a lack of resources. - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - return EfiLibInstallDriverBindingComponentName2 ( - ImageHandle, - SystemTable, - &gPxeBcDriverBinding, - ImageHandle, - &gPxeBcComponentName, - &gPxeBcComponentName2 - ); -} - - -/** - Test to see if this driver supports ControllerHandle. This service - is called by the EFI boot service ConnectController(). In - order to make drivers as small as possible, there are a few calling - restrictions for this service. ConnectController() must - follow these calling restrictions. If any other agent wishes to call - Supported() it must also follow these calling restrictions. - PxeBc requires DHCP4 and MTFTP4 protocols. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to test - @param RemainingDevicePath Optional parameter use to pick a specific ch= ild - device to start. - - @retval EFI_SUCCESS This driver supports this device - @retval EFI_ALREADY_STARTED This driver is already running on this devic= e - @retval other This driver does not support this device - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverBindingSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL - ) -{ - EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; - EFI_STATUS Status; - - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiPxeBaseCodeProtocolGuid, - (VOID **) &PxeBc, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (!EFI_ERROR (Status)) { - return EFI_ALREADY_STARTED; - } - - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiDhcp4ServiceBindingProtocolGuid, - NULL, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL - ); - - if (!EFI_ERROR (Status)) { - - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiMtftp4ServiceBindingProtocolGuid, - NULL, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL - ); - - } - - return Status; -} - - -/** - Start this driver on ControllerHandle. This service is called by the - EFI boot service ConnectController(). In order to make - drivers as small as possible, there are a few calling restrictions for - this service. ConnectController() must follow these - calling restrictions. If any other agent wishes to call Start() it - must also follow these calling restrictions. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to bind driver to - @param RemainingDevicePath Optional parameter use to pick a specific c= hild - device to start. - - @retval EFI_SUCCESS This driver is added to ControllerHandle - @retval EFI_ALREADY_STARTED This driver is already running on Controlle= rHandle - @retval other This driver does not support this device - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - UINTN Index; - EFI_STATUS Status; - EFI_IP4_MODE_DATA Ip4ModeData; - - Private =3D AllocateZeroPool (sizeof (PXEBC_PRIVATE_DATA)); - if (Private =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Private->Signature =3D PXEBC_PRIVATE_DATA_SIGNATURE; - Private->Controller =3D ControllerHandle; - Private->Image =3D This->DriverBindingHandle; - CopyMem (&Private->PxeBc, &mPxeBcProtocolTemplate, sizeof (Private->PxeB= c)); - Private->PxeBc.Mode =3D &Private->Mode; - CopyMem (&Private->LoadFile, &mLoadFileProtocolTemplate, sizeof (Private= ->LoadFile)); - - Private->ProxyOffer.Packet.Offer.Size =3D PXEBC_CACHED_DHCP4_PACKET_MAX_= SIZE; - Private->Dhcp4Ack.Packet.Ack.Size =3D PXEBC_CACHED_DHCP4_PACKET_MAX_= SIZE; - Private->PxeReply.Packet.Ack.Size =3D PXEBC_CACHED_DHCP4_PACKET_MAX_= SIZE; - - for (Index =3D 0; Index < PXEBC_MAX_OFFER_NUM; Index++) { - Private->Dhcp4Offers[Index].Packet.Offer.Size =3D PXEBC_CACHED_DHCP4_P= ACKET_MAX_SIZE; - } - - // - // Get the NII interface if it exists. - // - Status =3D gBS->OpenProtocol ( - ControllerHandle, - &gEfiNetworkInterfaceIdentifierProtocolGuid_31, - (VOID **) &Private->Nii, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - Private->Nii =3D NULL; - } - - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiArpServiceBindingProtocolGuid, - &Private->ArpChild - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->OpenProtocol ( - Private->ArpChild, - &gEfiArpProtocolGuid, - (VOID **) &Private->Arp, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiDhcp4ServiceBindingProtocolGuid, - &Private->Dhcp4Child - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->OpenProtocol ( - Private->Dhcp4Child, - &gEfiDhcp4ProtocolGuid, - (VOID **) &Private->Dhcp4, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiIp4ServiceBindingProtocolGuid, - &Private->Ip4Child - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->OpenProtocol ( - Private->Ip4Child, - &gEfiIp4ProtocolGuid, - (VOID **) &Private->Ip4, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - // - // Get max packet size from Ip4 to calculate block size for Tftp later. - // - Status =3D Private->Ip4->GetModeData (Private->Ip4, &Ip4ModeData, NULL, = NULL); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Private->Ip4MaxPacketSize =3D Ip4ModeData.MaxPacketSize; - - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiMtftp4ServiceBindingProtocolGuid, - &Private->Mtftp4Child - ); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->OpenProtocol ( - Private->Mtftp4Child, - &gEfiMtftp4ProtocolGuid, - (VOID **) &Private->Mtftp4, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiUdp4ServiceBindingProtocolGuid, - &Private->Udp4ReadChild - ); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - // - // The UDP instance for EfiPxeBcUdpRead - // - Status =3D gBS->OpenProtocol ( - Private->Udp4ReadChild, - &gEfiUdp4ProtocolGuid, - (VOID **) &Private->Udp4Read, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - // - // The UDP instance for EfiPxeBcUdpWrite - // - Status =3D NetLibCreateServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiUdp4ServiceBindingProtocolGuid, - &Private->Udp4WriteChild - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - Status =3D gBS->OpenProtocol ( - Private->Udp4WriteChild, - &gEfiUdp4ProtocolGuid, - (VOID **) &Private->Udp4Write, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - ZeroMem (&Private->Udp4CfgData, sizeof (EFI_UDP4_CONFIG_DATA)); - Private->Udp4CfgData.AcceptBroadcast =3D FALSE; - Private->Udp4CfgData.AcceptPromiscuous =3D FALSE; - Private->Udp4CfgData.AcceptAnyPort =3D TRUE; - Private->Udp4CfgData.AllowDuplicatePort =3D TRUE; - Private->Udp4CfgData.TypeOfService =3D DEFAULT_ToS; - Private->Udp4CfgData.TimeToLive =3D DEFAULT_TTL; - Private->Udp4CfgData.DoNotFragment =3D FALSE; - Private->Udp4CfgData.ReceiveTimeout =3D PXEBC_DEFAULT_LIFETIME; - Private->Udp4CfgData.UseDefaultAddress =3D FALSE; - - PxeBcInitSeedPacket (&Private->SeedPacket, Private->Udp4Read); - Private->MacLen =3D Private->SeedPacket.Dhcp4.Header.HwAddrLen; - CopyMem (&Private->Mac, &Private->SeedPacket.Dhcp4.Header.ClientHwAddr[0= ], Private->MacLen); - - - ZeroMem (&Private->Ip4ConfigData, sizeof (EFI_IP4_CONFIG_DATA)); - Private->Ip4ConfigData.DefaultProtocol =3D EFI_IP_PROTO_ICMP; - Private->Ip4ConfigData.AcceptIcmpErrors =3D TRUE; - Private->Ip4ConfigData.TypeOfService =3D DEFAULT_ToS; - Private->Ip4ConfigData.TimeToLive =3D DEFAULT_TTL; - Private->Ip4ConfigData.DoNotFragment =3D FALSE; - Private->Ip4ConfigData.RawData =3D FALSE; - - Status =3D gBS->InstallMultipleProtocolInterfaces ( - &ControllerHandle, - &gEfiPxeBaseCodeProtocolGuid, - &Private->PxeBc, - &gEfiLoadFileProtocolGuid, - &Private->LoadFile, - NULL - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - // - // Locate Ip4->Ip4Config2 and store it for set IPv4 Policy. - // - Status =3D gBS->HandleProtocol ( - ControllerHandle, - &gEfiIp4Config2ProtocolGuid, - (VOID **) &Private->Ip4Config2 - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - return EFI_SUCCESS; - -ON_ERROR: - - if (Private->Udp4WriteChild !=3D NULL) { - gBS->CloseProtocol ( - Private->Udp4WriteChild, - &gEfiUdp4ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiUdp4ServiceBindingProtocolGuid, - Private->Udp4WriteChild - ); - } - - if (Private->Udp4ReadChild !=3D NULL) { - gBS->CloseProtocol ( - Private->Udp4ReadChild, - &gEfiUdp4ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiUdp4ServiceBindingProtocolGuid, - Private->Udp4ReadChild - ); - } - - if (Private->Mtftp4Child !=3D NULL) { - gBS->CloseProtocol ( - Private->Mtftp4Child, - &gEfiMtftp4ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiMtftp4ServiceBindingProtocolGuid, - Private->Mtftp4Child - ); - } - - if (Private->Ip4Child !=3D NULL) { - gBS->CloseProtocol ( - Private->Ip4Child, - &gEfiIp4ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiIp4ServiceBindingProtocolGuid, - Private->Ip4Child - ); - } - - if (Private->Dhcp4Child !=3D NULL) { - gBS->CloseProtocol ( - Private->Dhcp4Child, - &gEfiDhcp4ProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiDhcp4ServiceBindingProtocolGuid, - Private->Dhcp4Child - ); - } - - if (Private->ArpChild !=3D NULL) { - gBS->CloseProtocol ( - Private->ArpChild, - &gEfiArpProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); - - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiArpServiceBindingProtocolGuid, - Private->ArpChild - ); - } - - FreePool (Private); - - return Status; -} - - -/** - Stop this driver on ControllerHandle. This service is called by the - EFI boot service DisconnectController(). In order to - make drivers as small as possible, there are a few calling - restrictions for this service. DisconnectController() - must follow these calling restrictions. If any other agent wishes - to call Stop() it must also follow these calling restrictions. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to stop driver on - @param NumberOfChildren Number of Handles in ChildHandleBuffer. If num= ber of - children is zero stop the entire bus driver. - @param ChildHandleBuffer List of Child Handles to Stop. - - @retval EFI_SUCCESS This driver is removed ControllerHandle - @retval other This driver was not removed from this device - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; - EFI_HANDLE NicHandle; - EFI_STATUS Status; - - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid= ); - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiDhcp4Protocol= Guid); - - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiIp4Protocol= Guid); - - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiUdp4Proto= colGuid); - - if (NicHandle =3D=3D NULL) { - NicHandle =3D NetLibGetNicHandle (ControllerHandle, &gEfiMtftp4P= rotocolGuid); - - if (NicHandle =3D=3D NULL) { - return EFI_SUCCESS; - } - } - } - } - } - - Status =3D gBS->OpenProtocol ( - NicHandle, - &gEfiPxeBaseCodeProtocolGuid, - (VOID **) &PxeBc, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Stop functionality of PXE Base Code protocol - // - Status =3D PxeBc->Stop (PxeBc); - if (Status !=3D EFI_SUCCESS && Status !=3D EFI_NOT_STARTED) { - return Status; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (PxeBc); - - Status =3D gBS->UninstallMultipleProtocolInterfaces ( - NicHandle, - &gEfiPxeBaseCodeProtocolGuid, - &Private->PxeBc, - &gEfiLoadFileProtocolGuid, - &Private->LoadFile, - NULL - ); - - if (!EFI_ERROR (Status)) { - - gBS->CloseProtocol ( - Private->Udp4WriteChild, - &gEfiUdp4ProtocolGuid, - This->DriverBindingHandle, - NicHandle - ); - NetLibDestroyServiceChild ( - ControllerHandle, - This->DriverBindingHandle, - &gEfiUdp4ServiceBindingProtocolGuid, - Private->Udp4WriteChild - ); - - gBS->CloseProtocol ( - Private->Udp4ReadChild, - &gEfiUdp4ProtocolGuid, - This->DriverBindingHandle, - NicHandle - ); - NetLibDestroyServiceChild ( - NicHandle, - This->DriverBindingHandle, - &gEfiUdp4ServiceBindingProtocolGuid, - Private->Udp4ReadChild - ); - - gBS->CloseProtocol ( - Private->Dhcp4Child, - &gEfiDhcp4ProtocolGuid, - This->DriverBindingHandle, - NicHandle - ); - NetLibDestroyServiceChild ( - NicHandle, - This->DriverBindingHandle, - &gEfiDhcp4ServiceBindingProtocolGuid, - Private->Dhcp4Child - ); - - gBS->CloseProtocol ( - Private->Mtftp4Child, - &gEfiMtftp4ProtocolGuid, - This->DriverBindingHandle, - NicHandle - ); - NetLibDestroyServiceChild ( - NicHandle, - This->DriverBindingHandle, - &gEfiMtftp4ServiceBindingProtocolGuid, - Private->Mtftp4Child - ); - - gBS->CloseProtocol ( - Private->Ip4Child, - &gEfiIp4ProtocolGuid, - This->DriverBindingHandle, - NicHandle - ); - NetLibDestroyServiceChild ( - NicHandle, - This->DriverBindingHandle, - &gEfiIp4ServiceBindingProtocolGuid, - Private->Ip4Child - ); - - gBS->CloseProtocol ( - Private->ArpChild, - &gEfiArpProtocolGuid, - This->DriverBindingHandle, - NicHandle - ); - NetLibDestroyServiceChild ( - NicHandle, - This->DriverBindingHandle, - &gEfiArpServiceBindingProtocolGuid, - Private->ArpChild - ); - - FreePool (Private); - } - - return Status; -} - - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c b/MdeM= odulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c deleted file mode 100644 index 3fa3be99c178..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c +++ /dev/null @@ -1,2989 +0,0 @@ -/** @file - Interface routines for PxeBc. - -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - - -#include "PxeBcImpl.h" - -UINT32 mPxeDhcpTimeout[4] =3D { 4, 8, 16, 32 }; - -/** - Get and record the arp cache. - - @param This Pointer to EFI_PXE_BC_PROTOCOL - - @retval EFI_SUCCESS Arp cache updated successfully - @retval others If error occurs when getting arp cache - -**/ -EFI_STATUS -UpdateArpCache ( - IN EFI_PXE_BASE_CODE_PROTOCOL * This - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_STATUS Status; - UINT32 EntryLength; - UINT32 EntryCount; - EFI_ARP_FIND_DATA *Entries; - UINT32 Index; - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - Status =3D Private->Arp->Find ( - Private->Arp, - TRUE, - NULL, - &EntryLength, - &EntryCount, - &Entries, - TRUE - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Mode->ArpCacheEntries =3D MIN ( - EntryCount, - EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES - ); - for (Index =3D 0; Index < Mode->ArpCacheEntries; Index ++) { - CopyMem ( - &Mode->ArpCache[Index].IpAddr, - Entries + 1, - Entries->SwAddressLength - ); - CopyMem ( - &Mode->ArpCache[Index].MacAddr, - (UINT8 *) (Entries + 1) + Entries->SwAddressLength, - Entries->HwAddressLength - ); - // - // Slip to the next FindData. - // - Entries =3D (EFI_ARP_FIND_DATA *) ((UINT8 *) Entries + EntryLength); - } - - return EFI_SUCCESS; -} - -/** - Timeout routine to update arp cache. - - @param Event Pointer to EFI_PXE_BC_PROTOCOL - @param Context Context of the timer event - -**/ -VOID -EFIAPI -ArpCacheUpdateTimeout ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - UpdateArpCache ((EFI_PXE_BASE_CODE_PROTOCOL *) Context); -} - -/** - Do arp resolution from arp cache in PxeBcMode. - - @param PxeBcMode The PXE BC mode to look into. - @param Ip4Addr The Ip4 address for resolution. - @param MacAddress The resoluted MAC address if the resolution is su= ccessful. - The value is undefined if resolution fails. - - @retval TRUE The resolution is successful. - @retval FALSE Otherwise. - -**/ -BOOLEAN -FindInArpCache ( - IN EFI_PXE_BASE_CODE_MODE *PxeBcMode, - IN EFI_IPv4_ADDRESS *Ip4Addr, - OUT EFI_MAC_ADDRESS *MacAddress - ) -{ - UINT32 Index; - - for (Index =3D 0; Index < PxeBcMode->ArpCacheEntries; Index ++) { - if (EFI_IP4_EQUAL (&PxeBcMode->ArpCache[Index].IpAddr.v4, Ip4Addr)) { - CopyMem ( - MacAddress, - &PxeBcMode->ArpCache[Index].MacAddr, - sizeof (EFI_MAC_ADDRESS) - ); - return TRUE; - } - } - - return FALSE; -} - -/** - Notify function for the ICMP receive token, used to process - the received ICMP packets. - - @param Context The PXEBC private data. - -**/ -VOID -EFIAPI -IcmpErrorListenHandlerDpc ( - IN VOID *Context - ) -{ - EFI_STATUS Status; - EFI_IP4_RECEIVE_DATA *RxData; - EFI_IP4_PROTOCOL *Ip4; - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - UINTN Index; - UINT32 CopiedLen; - UINT8 *CopiedPointer; - - Private =3D (PXEBC_PRIVATE_DATA *) Context; - Mode =3D &Private->Mode; - Status =3D Private->IcmpErrorRcvToken.Status; - RxData =3D Private->IcmpErrorRcvToken.Packet.RxData; - Ip4 =3D Private->Ip4; - - if (Status =3D=3D EFI_ABORTED) { - // - // The reception is actively aborted by the consumer, directly return. - // - return; - } - - if (RxData =3D=3D NULL) { - goto Resume; - } - - if (Status !=3D EFI_ICMP_ERROR) { - // - // The return status should be recognized as EFI_ICMP_ERROR. - // - goto CleanUp; - } - - if (EFI_IP4 (RxData->Header->SourceAddress) !=3D 0 && - (NTOHL (Mode->SubnetMask.Addr[0]) !=3D 0) && - IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->He= ader->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) && - !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (= Mode->SubnetMask.Addr[0]))) { - // - // The source address is not zero and it's not a unicast IP address, d= iscard it. - // - goto CleanUp; - } - - if (!EFI_IP4_EQUAL (&RxData->Header->DestinationAddress, &Mode->StationI= p.v4)) { - // - // The dest address is not equal to Station Ip address, discard it. - // - goto CleanUp; - } - - // - // Constructor ICMP error packet - // - CopiedLen =3D 0; - CopiedPointer =3D (UINT8 *) &Mode->IcmpError; - - for (Index =3D 0; Index < RxData->FragmentCount; Index ++) { - CopiedLen +=3D RxData->FragmentTable[Index].FragmentLength; - if (CopiedLen <=3D sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)) { - CopyMem ( - CopiedPointer, - RxData->FragmentTable[Index].FragmentBuffer, - RxData->FragmentTable[Index].FragmentLength - ); - } else { - CopyMem ( - CopiedPointer, - RxData->FragmentTable[Index].FragmentBuffer, - CopiedLen - sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR) - ); - } - CopiedPointer +=3D CopiedLen; - } - -CleanUp: - gBS->SignalEvent (RxData->RecycleSignal); - -Resume: - Ip4->Receive (Ip4, &(Private->IcmpErrorRcvToken)); -} - -/** - Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK - - @param Event The event signaled. - @param Context The context passed in by the event notifie= r. - -**/ -VOID -EFIAPI -IcmpErrorListenHandler ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - // - // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK - // - QueueDpc (TPL_CALLBACK, IcmpErrorListenHandlerDpc, Context); -} - -/** - Enables the use of the PXE Base Code Protocol functions. - - This function enables the use of the PXE Base Code Protocol functions. I= f the - Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, t= hen - EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 form= atted - addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 f= ormatted - addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6= Supported - field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPO= RTED will - be returned. If there is not enough memory or other resources to start t= he PXE - Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwis= e, the - PXE Base Code Protocol will be started, and all of the fields of the EFI= _PXE_BASE_CODE_MODE - structure will be initialized as follows: - StartedSet to TRUE. - Ipv6SupportedUnchanged. - Ipv6AvailableUnchanged. - UsingIpv6Set to UseIpv6. - BisSupportedUnchanged. - BisDetectedUnchanged. - AutoArpSet to TRUE. - SendGUIDSet to FALSE. - TTLSet to DEFAULT_TTL. - ToSSet to DEFAULT_ToS. - DhcpCompletedSet to FALSE. - ProxyOfferReceivedSet to FALSE. - StationIpSet to an address of all zeros. - SubnetMaskSet to a subnet mask of all zeros. - DhcpDiscoverZero-filled. - DhcpAckZero-filled. - ProxyOfferZero-filled. - PxeDiscoverValidSet to FALSE. - PxeDiscoverZero-filled. - PxeReplyValidSet to FALSE. - PxeReplyZero-filled. - PxeBisReplyValidSet to FALSE. - PxeBisReplyZero-filled. - IpFilterSet the Filters field to 0 and the IpCnt field to 0. - ArpCacheEntriesSet to 0. - ArpCacheZero-filled. - RouteTableEntriesSet to 0. - RouteTableZero-filled. - IcmpErrorReceivedSet to FALSE. - IcmpErrorZero-filled. - TftpErroReceivedSet to FALSE. - TftpErrorZero-filled. - MakeCallbacksSet to TRUE if the PXE Base Code Callback Protocol is ava= ilable. - Set to FALSE if the PXE Base Code Callback Protocol is not available. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param UseIpv6 Specifies the type of IP addresses that ar= e to be used during the session - that is being started. Set to TRUE for IPv= 6 addresses, and FALSE for - IPv4 addresses. - - @retval EFI_SUCCESS The PXE Base Code Protocol was started. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this oper - @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported fie= ld of the - EFI_PXE_BASE_CODE_MODE structure is FALSE. - @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in t= he started state. - @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not poi= nt to a valid - EFI_PXE_BASE_CODE_PROTOCOL structure. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other = resources to start the - PXE Base Code Protocol. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcStart ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN BOOLEAN UseIpv6 - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_STATUS Status; - - if (This =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (Mode->Started) { - return EFI_ALREADY_STARTED; - } - - if (UseIpv6) { - // - // IPv6 is not supported now. - // - return EFI_UNSUPPORTED; - } - - AsciiPrint ("\n>>Start PXE over IPv4"); - - // - // Configure the udp4 instance to let it receive data - // - Status =3D Private->Udp4Read->Configure ( - Private->Udp4Read, - &Private->Udp4CfgData - ); - if (EFI_ERROR (Status)) { - return Status; - } - - - // - // Configure block size for TFTP as a default value to handle all link l= ayers. - // - Private->BlockSize =3D MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_P= ACKET_SIZE) - - PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT= _TFTP_OVERHEAD_SIZE; - // - // If PcdTftpBlockSize is set to non-zero, override the default value. - // - if (PcdGet64 (PcdTftpBlockSize) !=3D 0) { - Private->BlockSize =3D (UINTN) PcdGet64 (PcdTftpBlockSize); - } - - Private->AddressIsOk =3D FALSE; - - ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE)); - - Mode->Started =3D TRUE; - Mode->TTL =3D DEFAULT_TTL; - Mode->ToS =3D DEFAULT_ToS; - Mode->AutoArp =3D TRUE; - - // - // Create the event for Arp Cache checking. - // - Status =3D gBS->CreateEvent ( - EVT_TIMER | EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - ArpCacheUpdateTimeout, - This, - &Private->GetArpCacheEvent - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - // - // Start the timeout timer event. - // - Status =3D gBS->SetTimer ( - Private->GetArpCacheEvent, - TimerPeriodic, - TICKS_PER_SECOND - ); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - // - // Create ICMP error receiving event - // - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - IcmpErrorListenHandler, - Private, - &(Private->IcmpErrorRcvToken.Event) - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - // - //DHCP4 service allows only one of its children to be configured in - //the active state, If the DHCP4 D.O.R.A started by IP4 auto - //configuration and has not been completed, the Dhcp4 state machine - //will not be in the right state for the PXE to start a new round D.O.R.= A. - //so we need to switch it's policy to static. - // - Status =3D PxeBcSetIp4Policy (Private); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Status =3D Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigDat= a); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - // - // start to listen incoming packet - // - Status =3D Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvTo= ken); - if (!EFI_ERROR (Status)) { - return Status; - } - -ON_EXIT: - Private->Ip4->Configure (Private->Ip4, NULL); - - if (Private->IcmpErrorRcvToken.Event !=3D NULL) { - gBS->CloseEvent (Private->IcmpErrorRcvToken.Event); - } - - if (Private->GetArpCacheEvent !=3D NULL) { - gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0); - gBS->CloseEvent (Private->GetArpCacheEvent); - } - - Mode->Started =3D FALSE; - Mode->TTL =3D 0; - Mode->ToS =3D 0; - Mode->AutoArp =3D FALSE; - - return Status; -} - - -/** - Disables the use of the PXE Base Code Protocol functions. - - This function stops all activity on the network device. All the resource= s allocated - in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE= structure is - set to FALSE and EFI_SUCCESS is returned. If the Started field of the EF= I_PXE_BASE_CODE_MODE - structure is already FALSE, then EFI_NOT_STARTED will be returned. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - - @retval EFI_SUCCESS The PXE Base Code Protocol was stopped. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in t= he stopped state. - @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not poi= nt to a valid - EFI_PXE_BASE_CODE_PROTOCOL structure. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this operation. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcStop ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - - if (This =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - Private->Ip4->Cancel (Private->Ip4, NULL); - // - // Dispatch the DPCs queued by the NotifyFunction of the canceled rx tok= en's - // events. - // - DispatchDpc (); - - Private->Ip4->Configure (Private->Ip4, NULL); - - // - // Close the ICMP error receiving event. - // - gBS->CloseEvent (Private->IcmpErrorRcvToken.Event); - - // - // Cancel the TimeoutEvent timer. - // - gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0); - - // - // Close the TimeoutEvent event. - // - gBS->CloseEvent (Private->GetArpCacheEvent); - - Mode->Started =3D FALSE; - - Private->CurrentUdpSrcPort =3D 0; - Private->Udp4Write->Configure (Private->Udp4Write, NULL); - Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL); - Private->Udp4Read->Configure (Private->Udp4Read, NULL); - - Private->Dhcp4->Stop (Private->Dhcp4); - Private->Dhcp4->Configure (Private->Dhcp4, NULL); - - Private->FileSize =3D 0; - - return EFI_SUCCESS; -} - - -/** - Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / ack= nowledge) or DHCPv6 - S.A.R.R (solicit / advertise / request / reply) sequence. - - This function attempts to complete the DHCP sequence. If this sequence i= s completed, - then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived,= StationIp, - SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_= BASE_CODE_MODE - structure are filled in. - If SortOffers is TRUE, then the cached DHCP offer packets will be sorted= before - they are tried. If SortOffers is FALSE, then the cached DHCP offer packe= ts will - be tried in the order in which they are received. Please see the Preboot= Execution - Environment (PXE) Specification for additional details on the implementa= tion of DHCP. - This function can take at least 31 seconds to timeout and return control= to the - caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be= returned. - If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STAT= US_CONTINUE, - then the DHCP sequence will be stopped and EFI_ABORTED will be returned. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param SortOffers TRUE if the offers received should be sort= ed. Set to FALSE to try the - offers in the order that they are received= . - - @retval EFI_SUCCESS Valid DHCP has completed. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not poi= nt to a valid - EFI_PXE_BASE_CODE_PROTOCOL structure. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this operation. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to comple= te the DHCP Protocol. - @retval EFI_ABORTED The callback function aborted the DHCP Pro= tocol. - @retval EFI_TIMEOUT The DHCP Protocol timed out. - @retval EFI_ICMP_ERROR An ICMP error packet was received during t= he DHCP session. - @retval EFI_NO_RESPONSE Valid PXE offer was not received. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcDhcp ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN BOOLEAN SortOffers - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_DHCP4_PROTOCOL *Dhcp4; - EFI_DHCP4_CONFIG_DATA Dhcp4CfgData; - EFI_DHCP4_MODE_DATA Dhcp4Mode; - EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM]; - UINT32 OptCount; - EFI_STATUS Status; - EFI_ARP_CONFIG_DATA ArpConfigData; - EFI_PXE_BASE_CODE_IP_FILTER IpFilter; - - if (This =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Status =3D EFI_SUCCESS; - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - Dhcp4 =3D Private->Dhcp4; - Private->Function =3D EFI_PXE_BASE_CODE_FUNCTION_DHCP; - Private->SortOffers =3D SortOffers; - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - Mode->IcmpErrorReceived =3D FALSE; - - // - // Stop Udp4Read instance - // - Private->Udp4Read->Configure (Private->Udp4Read, NULL); - - // - // Initialize the DHCP options and build the option list - // - OptCount =3D PxeBcBuildDhcpOptions (Private, OptList, TRUE); - - // - // Set the DHCP4 config data. - // The four discovery timeouts are 4, 8, 16, 32 seconds respectively. - // - ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA)); - Dhcp4CfgData.OptionCount =3D OptCount; - Dhcp4CfgData.OptionList =3D OptList; - Dhcp4CfgData.Dhcp4Callback =3D PxeBcDhcpCallBack; - Dhcp4CfgData.CallbackContext =3D Private; - Dhcp4CfgData.DiscoverTryCount =3D 4; - Dhcp4CfgData.DiscoverTimeout =3D mPxeDhcpTimeout; - - Status =3D Dhcp4->Configure (Dhcp4, &Dhcp4CfgData); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - // - // Zero those arrays to record the varies numbers of DHCP OFFERS. - // - Private->GotProxyOffer =3D FALSE; - Private->NumOffers =3D 0; - Private->BootpIndex =3D 0; - ZeroMem (Private->ServerCount, sizeof (Private->ServerCount)); - ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex)); - - Status =3D Dhcp4->Start (Dhcp4, NULL); - if (EFI_ERROR (Status) && Status !=3D EFI_ALREADY_STARTED) { - if (Status =3D=3D EFI_ICMP_ERROR) { - Mode->IcmpErrorReceived =3D TRUE; - } - goto ON_EXIT; - } - - Status =3D Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - ASSERT (Dhcp4Mode.State =3D=3D Dhcp4Bound); - - CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4= _ADDRESS)); - CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_A= DDRESS)); - CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4= _ADDRESS)); - - CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS= )); - CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRE= SS)); - - // - // Check the selected offer to see whether BINL is required, if no or BI= NL is - // finished, set the various Mode members. - // - Status =3D PxeBcCheckSelectedOffer (Private); - - AsciiPrint ("\n Station IP address is "); - - PxeBcShowIp4Addr (&Private->StationIp.v4); - AsciiPrint ("\n"); - -ON_EXIT: - if (EFI_ERROR (Status)) { - Dhcp4->Stop (Dhcp4); - Dhcp4->Configure (Dhcp4, NULL); - } else { - // - // Remove the previously configured option list and callback function - // - ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA)); - Dhcp4->Configure (Dhcp4, &Dhcp4CfgData); - - Private->AddressIsOk =3D TRUE; - - if (!Mode->UsingIpv6) { - // - // If in IPv4 mode, configure the corresponding ARP with this new - // station IP address. - // - ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA)); - - ArpConfigData.SwAddressType =3D 0x0800; - ArpConfigData.SwAddressLength =3D (UINT8) sizeof (EFI_IPv4_ADDRESS); - ArpConfigData.StationAddress =3D &Private->StationIp.v4; - - Private->Arp->Configure (Private->Arp, NULL); - Private->Arp->Configure (Private->Arp, &ArpConfigData); - - // - // Updated the route table. Fill the first entry. - // - Mode->RouteTableEntries =3D 1; - Mode->RouteTable[0].IpAddr.Addr[0] =3D Private->StationIp.Addr[0= ] & Private->SubnetMask.Addr[0]; - Mode->RouteTable[0].SubnetMask.Addr[0] =3D Private->SubnetMask.Addr[= 0]; - Mode->RouteTable[0].GwAddr.Addr[0] =3D 0; - - // - // Create the default route entry if there is a default router. - // - if (Private->GatewayIp.Addr[0] !=3D 0) { - Mode->RouteTableEntries =3D 2; - Mode->RouteTable[1].IpAddr.Addr[0] =3D 0; - Mode->RouteTable[1].SubnetMask.Addr[0] =3D 0; - Mode->RouteTable[1].GwAddr.Addr[0] =3D Private->GatewayIp.Addr= [0]; - } - - // - // Flush new station IP address into Udp4CfgData and Ip4ConfigData - // - CopyMem (&Private->Udp4CfgData.StationAddress, &Private->StationIp, = sizeof (EFI_IPv4_ADDRESS)); - CopyMem (&Private->Udp4CfgData.SubnetMask, &Private->SubnetMask, siz= eof (EFI_IPv4_ADDRESS)); - CopyMem (&Private->Ip4ConfigData.StationAddress, &Private->StationIp= , sizeof (EFI_IPv4_ADDRESS)); - CopyMem (&Private->Ip4ConfigData.SubnetMask, &Private->SubnetMask, s= izeof (EFI_IPv4_ADDRESS)); - - // - // Reconfigure the Ip4 instance to capture background ICMP packets w= ith new station Ip address. - // - Private->Ip4->Cancel (Private->Ip4, &Private->IcmpErrorRcvToken); - Private->Ip4->Configure (Private->Ip4, NULL); - - Status =3D Private->Ip4->Configure (Private->Ip4, &Private->Ip4Confi= gData); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Status =3D Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorR= cvToken); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } - } - - Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData); - - // - // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with th= e IP - // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_I= P_FILTER_STATION_IP. - // - ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER)); - IpFilter.Filters =3D EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP; - This->SetIpFilter (This, &IpFilter); - - return Status; -} - - -/** - Attempts to complete the PXE Boot Server and/or boot image discovery seq= uence. - - This function attempts to complete the PXE Boot Server and/or boot image= discovery - sequence. If this sequence is completed, then EFI_SUCCESS is returned, a= nd the - PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of = the - EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then = the - PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE= structure - will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will b= e set to FALSE. - In the structure referenced by parameter Info, the PXE Boot Server list,= SrvList[], - has two uses: It is the Boot Server IP address list used for unicast dis= covery - (if the UseUCast field is TRUE), and it is the list used for Boot Server= verification - (if the MustUseList field is TRUE). Also, if the MustUseList field in th= at structure - is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, = any Boot - Server reply of that type will be accepted. If the AcceptAnyResponse fie= ld is - FALSE, only responses from Boot Servers with matching IP addresses will = be accepted. - This function can take at least 10 seconds to timeout and return control= to the - caller. If the Discovery sequence does not complete, then EFI_TIMEOUT wi= ll be - returned. Please see the Preboot Execution Environment (PXE) Specificati= on for - additional details on the implementation of the Discovery sequence. - If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STAT= US_CONTINUE, - then the Discovery sequence is stopped and EFI_ABORTED will be returned. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param Type The type of bootstrap to perform. - @param Layer Pointer to the boot server layer number to= discover, which must be - PXE_BOOT_LAYER_INITIAL when a new server t= ype is being - discovered. - @param UseBis TRUE if Boot Integrity Services are to be = used. FALSE otherwise. - @param Info Pointer to a data structure that contains = additional information on the - type of discovery operation that is to be = performed. - - @retval EFI_SUCCESS The Discovery sequence has been completed. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this operation. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to comple= te Discovery. - @retval EFI_ABORTED The callback function aborted the Discover= y sequence. - @retval EFI_TIMEOUT The Discovery sequence timed out. - @retval EFI_ICMP_ERROR An ICMP error packet was received during t= he PXE discovery - session. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcDiscover ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN UINT16 Type, - IN UINT16 *Layer, - IN BOOLEAN UseBis, - IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo; - EFI_PXE_BASE_CODE_DISCOVER_INFO *CreatedInfo; - EFI_PXE_BASE_CODE_SRVLIST *SrvList; - EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList; - PXEBC_CACHED_DHCP4_PACKET *Packet; - PXEBC_VENDOR_OPTION *VendorOpt; - UINT16 Index; - EFI_STATUS Status; - PXEBC_BOOT_SVR_ENTRY *BootSvrEntry; - EFI_PXE_BASE_CODE_IP_FILTER IpFilter; - - if (This =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - BootSvrEntry =3D NULL; - SrvList =3D NULL; - CreatedInfo =3D NULL; - Status =3D EFI_DEVICE_ERROR; - Private->Function =3D EFI_PXE_BASE_CODE_FUNCTION_DISCOVER; - - if (!Private->AddressIsOk) { - return EFI_INVALID_PARAMETER; - } - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - // - // Stop Udp4Read instance - // - Private->Udp4Read->Configure (Private->Udp4Read, NULL); - - Mode->IcmpErrorReceived =3D FALSE; - - // - // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL, - // use the previous setting; - // If info isn't offered, - // use the cached DhcpAck and ProxyOffer packets. - // - ZeroMem (&DefaultInfo, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO)); - if (*Layer !=3D EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) { - - if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeB= isReplyReceived && UseBis)) { - - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - - DefaultInfo.IpCnt =3D 1; - DefaultInfo.UseUCast =3D TRUE; - - DefaultSrvList.Type =3D Type; - DefaultSrvList.AcceptAnyResponse =3D FALSE; - DefaultSrvList.IpAddr.Addr[0] =3D Private->ServerIp.Addr[0]; - - SrvList =3D &DefaultSrvList; - Info =3D &DefaultInfo; - } else if (Info =3D=3D NULL) { - // - // Create info by the cached packet before - // - Packet =3D (Mode->ProxyOfferReceived) ? &Private->ProxyOffer : &Pri= vate->Dhcp4Ack; - VendorOpt =3D &Packet->PxeVendorOption; - - if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (Vendor= Opt->BitMap)) { - // - // Address is not acquired or no discovery options. - // - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - - DefaultInfo.UseMCast =3D (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (Vendo= rOpt->DiscoverCtrl); - DefaultInfo.UseBCast =3D (BOOLEAN)!IS_DISABLE_BCAST_DISCOVER (Vendo= rOpt->DiscoverCtrl); - DefaultInfo.MustUseList =3D (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (Vendo= rOpt->DiscoverCtrl); - DefaultInfo.UseUCast =3D DefaultInfo.MustUseList; - - if (DefaultInfo.UseMCast) { - // - // Get the multicast discover ip address from vendor option. - // - CopyMem ( - &DefaultInfo.ServerMCastIp.Addr, - &VendorOpt->DiscoverMcastIp, - sizeof (EFI_IPv4_ADDRESS) - ); - } - - DefaultInfo.IpCnt =3D 0; - Info =3D &DefaultInfo; - SrvList =3D Info->SrvList; - - if (DefaultInfo.MustUseList) { - BootSvrEntry =3D VendorOpt->BootSvr; - Status =3D EFI_INVALID_PARAMETER; - - while (((UINT8) (BootSvrEntry - VendorOpt->BootSvr)) < VendorOpt->Bo= otSvrLen) { - - if (BootSvrEntry->Type =3D=3D HTONS (Type)) { - Status =3D EFI_SUCCESS; - break; - } - - BootSvrEntry =3D GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry); - } - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - DefaultInfo.IpCnt =3D BootSvrEntry->IpCnt; - - if (DefaultInfo.IpCnt >=3D 1) { - CreatedInfo =3D AllocatePool (sizeof (DefaultInfo) + (DefaultInfo.= IpCnt - 1) * sizeof (*SrvList)); - if (CreatedInfo =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - - } - - CopyMem (CreatedInfo, &DefaultInfo, sizeof (DefaultInfo)); - Info =3D CreatedInfo; - SrvList =3D Info->SrvList; - } - - for (Index =3D 0; Index < DefaultInfo.IpCnt; Index++) { - CopyMem (&SrvList[Index].IpAddr, &BootSvrEntry->IpAddr[Index], siz= eof (EFI_IPv4_ADDRESS)); - SrvList[Index].AcceptAnyResponse =3D FALSE; - SrvList[Index].Type =3D BootSvrEntry->Type; - } - } - - } else { - - SrvList =3D Info->SrvList; - - if (!SrvList[0].AcceptAnyResponse) { - - for (Index =3D 1; Index < Info->IpCnt; Index++) { - if (SrvList[Index].AcceptAnyResponse) { - break; - } - } - - if (Index !=3D Info->IpCnt) { - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - } - } - - if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) || (Info->Mu= stUseList && Info->IpCnt =3D=3D 0)) { - - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - // - // Execute discover by UniCast/BroadCast/MultiCast - // - if (Info->UseUCast) { - - for (Index =3D 0; Index < Info->IpCnt; Index++) { - - if (BootSvrEntry =3D=3D NULL) { - Private->ServerIp.Addr[0] =3D SrvList[Index].IpAddr.Addr[0]; - } else { - CopyMem ( - &Private->ServerIp, - &BootSvrEntry->IpAddr[Index], - sizeof (EFI_IPv4_ADDRESS) - ); - } - - Status =3D PxeBcDiscvBootService ( - Private, - Type, - Layer, - UseBis, - &SrvList[Index].IpAddr, - 0, - NULL, - TRUE, - &Private->PxeReply.Packet.Ack - ); - if (!EFI_ERROR (Status)) { - break; - } - } - - } else if (Info->UseMCast) { - - Status =3D PxeBcDiscvBootService ( - Private, - Type, - Layer, - UseBis, - &Info->ServerMCastIp, - 0, - NULL, - TRUE, - &Private->PxeReply.Packet.Ack - ); - - } else if (Info->UseBCast) { - - Status =3D PxeBcDiscvBootService ( - Private, - Type, - Layer, - UseBis, - NULL, - Info->IpCnt, - SrvList, - TRUE, - &Private->PxeReply.Packet.Ack - ); - } - - if (EFI_ERROR (Status) || !Mode->PxeReplyReceived || (!Mode->PxeBisReply= Received && UseBis)) { - if (Status =3D=3D EFI_ICMP_ERROR) { - Mode->IcmpErrorReceived =3D TRUE; - } else { - Status =3D EFI_DEVICE_ERROR; - } - goto ON_EXIT; - } else { - PxeBcParseCachedDhcpPacket (&Private->PxeReply); - } - - if (Mode->PxeBisReplyReceived) { - CopyMem ( - &Private->ServerIp, - &Mode->PxeReply.Dhcpv4.BootpSiAddr, - sizeof (EFI_IPv4_ADDRESS) - ); - } - - if (CreatedInfo !=3D NULL) { - FreePool (CreatedInfo); - } - -ON_EXIT: - - Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData); - - // - // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with th= e IP - // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_I= P_FILTER_STATION_IP. - // - ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER)); - IpFilter.Filters =3D EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP; - This->SetIpFilter (This, &IpFilter); - - return Status; -} - - -/** - Used to perform TFTP and MTFTP services. - - This function is used to perform TFTP and MTFTP services. This includes = the - TFTP operations to get the size of a file, read a directory, read a file= , and - write a file. It also includes the MTFTP operations to get the size of a= file, - read a directory, and read a file. The type of operation is specified by= Operation. - If the callback function that is invoked during the TFTP/MTFTP operation= does - not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED = will - be returned. - For read operations, the return data will be placed in the buffer specif= ied by - BufferPtr. If BufferSize is too small to contain the entire downloaded f= ile, - then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to= zero - or the size of the requested file (the size of the requested file is onl= y returned - if the TFTP server supports TFTP options). If BufferSize is large enough= for the - read operation, then BufferSize will be set to the size of the downloade= d file, - and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() s= ervices - should use the get-file-size operations to determine the size of the dow= nloaded - file prior to using the read-file operations-especially when downloading= large - (greater than 64 MB) files-instead of making two calls to the read-file = operation. - Following this recommendation will save time if the file is larger than = expected - and the TFTP server does not support TFTP option extensions. Without TFT= P option - extension support, the client has to download the entire file, counting = and discarding - the received packets, to determine the file size. - For write operations, the data to be sent is in the buffer specified by = BufferPtr. - BufferSize specifies the number of bytes to send. If the write operation= completes - successfully, then EFI_SUCCESS will be returned. - For TFTP "get file size" operations, the size of the requested file or d= irectory - is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP= server - does not support options, the file will be downloaded into a bit bucket = and the - length of the downloaded file will be returned. For MTFTP "get file size= " operations, - if the MTFTP server does not support the "get file size" option, EFI_UNS= UPPORTED - will be returned. - This function can take up to 10 seconds to timeout and return control to= the caller. - If the TFTP sequence does not complete, EFI_TIMEOUT will be returned. - If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STAT= US_CONTINUE, - then the TFTP sequence is stopped and EFI_ABORTED will be returned. - The format of the data returned from a TFTP read directory operation is = a null-terminated - filename followed by a null-terminated information string, of the form - "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - no= te that - the seconds field can be a decimal number), where the date and time are = UTC. For - an MTFTP read directory command, there is additionally a null-terminated= multicast - IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The= final - entry is itself null-terminated, so that the final information string is= terminated - with two null octets. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param Operation The type of operation to perform. - @param BufferPtr A pointer to the data buffer. - @param Overwrite Only used on write file operations. TRUE i= f a file on a remote server can - be overwritten. - @param BufferSize For get-file-size operations, *BufferSize = returns the size of the - requested file. - @param BlockSize The requested block size to be used during= a TFTP transfer. - @param ServerIp The TFTP / MTFTP server IP address. - @param Filename A Null-terminated ASCII string that specif= ies a directory name or a file - name. - @param Info Pointer to the MTFTP information. - @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP rea= d file operation. - - @retval EFI_SUCCESS The TFTP/MTFTP operation was completed. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this operation. - @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete= the read operation. - @retval EFI_ABORTED The callback function aborted the TFTP/MTF= TP operation. - @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out. - @retval EFI_ICMP_ERROR An ICMP error packet was received during t= he MTFTP session. - @retval EFI_TFTP_ERROR A TFTP error packet was received during th= e MTFTP session. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcMtftp ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation, - IN OUT VOID *BufferPtr, - IN BOOLEAN Overwrite, - IN OUT UINT64 *BufferSize, - IN UINTN *BlockSize OPTIONAL, - IN EFI_IP_ADDRESS *ServerIp, - IN UINT8 *Filename, - IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL, - IN BOOLEAN DontUseBuffer - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_MTFTP4_CONFIG_DATA Mtftp4Config; - EFI_STATUS Status; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_MAC_ADDRESS TempMacAddr; - EFI_PXE_BASE_CODE_IP_FILTER IpFilter; - - if ((This =3D=3D NULL) = || - (Filename =3D=3D NULL) = || - (BufferSize =3D=3D NULL) = || - ((ServerIp =3D=3D NULL) || - (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || - IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0])))) = || - ((BufferPtr =3D=3D NULL) && DontUseBuffer) = || - ((BlockSize !=3D NULL) && (*BlockSize < 512))) { - - return EFI_INVALID_PARAMETER; - } - - Status =3D EFI_DEVICE_ERROR; - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D &Private->Mode; - - if (!Mode->AutoArp) { - // - // If AutoArp is set false, check arp cache - // - UpdateArpCache (This); - if (!FindInArpCache (Mode, &ServerIp->v4, &TempMacAddr)) { - return EFI_DEVICE_ERROR; - } - } - - // - // Stop Udp4Read instance - // - Private->Udp4Read->Configure (Private->Udp4Read, NULL); - - Mode->TftpErrorReceived =3D FALSE; - Mode->IcmpErrorReceived =3D FALSE; - - Mtftp4Config.UseDefaultSetting =3D FALSE; - Mtftp4Config.TimeoutValue =3D PXEBC_MTFTP_TIMEOUT; - Mtftp4Config.TryCount =3D PXEBC_MTFTP_RETRIES; - - CopyMem ( - &Mtftp4Config.StationIp, - &Private->StationIp, - sizeof (EFI_IPv4_ADDRESS) - ); - CopyMem ( - &Mtftp4Config.SubnetMask, - &Private->SubnetMask, - sizeof (EFI_IPv4_ADDRESS) - ); - CopyMem ( - &Mtftp4Config.GatewayIp, - &Private->GatewayIp, - sizeof (EFI_IPv4_ADDRESS) - ); - CopyMem ( - &Mtftp4Config.ServerIp, - ServerIp, - sizeof (EFI_IPv4_ADDRESS) - ); - - switch (Operation) { - - case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE: - - Status =3D PxeBcTftpGetFileSize ( - Private, - &Mtftp4Config, - Filename, - BlockSize, - BufferSize - ); - - break; - - case EFI_PXE_BASE_CODE_TFTP_READ_FILE: - - Status =3D PxeBcTftpReadFile ( - Private, - &Mtftp4Config, - Filename, - BlockSize, - BufferPtr, - BufferSize, - DontUseBuffer - ); - - break; - - case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE: - - Status =3D PxeBcTftpWriteFile ( - Private, - &Mtftp4Config, - Filename, - Overwrite, - BlockSize, - BufferPtr, - BufferSize - ); - - break; - - case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY: - - Status =3D PxeBcTftpReadDirectory ( - Private, - &Mtftp4Config, - Filename, - BlockSize, - BufferPtr, - BufferSize, - DontUseBuffer - ); - - break; - - case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE: - case EFI_PXE_BASE_CODE_MTFTP_READ_FILE: - case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY: - Status =3D EFI_UNSUPPORTED; - break; - - default: - - Status =3D EFI_INVALID_PARAMETER; - break; - } - - if (Status =3D=3D EFI_ICMP_ERROR) { - Mode->IcmpErrorReceived =3D TRUE; - } - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - -ON_EXIT: - Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData); - // - // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with th= e IP - // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_I= P_FILTER_STATION_IP. - // - ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER)); - IpFilter.Filters =3D EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP; - This->SetIpFilter (This, &IpFilter); - - return Status; -} - - -/** - Writes a UDP packet to the network interface. - - This function writes a UDP packet specified by the (optional HeaderPtr a= nd) - BufferPtr parameters to the network interface. The UDP header is automat= ically - built by this routine. It uses the parameters OpFlags, DestIp, DestPort,= GatewayIp, - SrcIp, and SrcPort to build this header. If the packet is successfully b= uilt and - transmitted through the network interface, then EFI_SUCCESS will be retu= rned. - If a timeout occurs during the transmission of the packet, then EFI_TIME= OUT will - be returned. If an ICMP error occurs during the transmission of the pack= et, then - the IcmpErrorReceived field is set to TRUE, the IcmpError field is fille= d in and - EFI_ICMP_ERROR will be returned. If the Callback Protocol does not retur= n - EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be ret= urned. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param OpFlags The UDP operation flags. - @param DestIp The destination IP address. - @param DestPort The destination UDP port number. - @param GatewayIp The gateway IP address. - @param SrcIp The source IP address. - @param SrcPort The source UDP port number. - @param HeaderSize An optional field which may be set to the = length of a header at - HeaderPtr to be prefixed to the data at Bu= fferPtr. - @param HeaderPtr If HeaderSize is not NULL, a pointer to a = header to be prefixed to the - data at BufferPtr. - @param BufferSize A pointer to the size of the data at Buffe= rPtr. - @param BufferPtr A pointer to the data to be written. - - @retval EFI_SUCCESS The UDP Write operation was completed. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted. - @retval EFI_ABORTED The callback function aborted the UDP Writ= e operation. - @retval EFI_TIMEOUT The UDP Write operation timed out. - @retval EFI_ICMP_ERROR An ICMP error packet was received during t= he UDP write session. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcUdpWrite ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN UINT16 OpFlags, - IN EFI_IP_ADDRESS *DestIp, - IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort, - IN EFI_IP_ADDRESS *GatewayIp OPTIONAL, - IN EFI_IP_ADDRESS *SrcIp OPTIONAL, - IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL, - IN UINTN *HeaderSize OPTIONAL, - IN VOID *HeaderPtr OPTIONAL, - IN UINTN *BufferSize, - IN VOID *BufferPtr - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_UDP4_PROTOCOL *Udp4; - EFI_UDP4_COMPLETION_TOKEN Token; - EFI_UDP4_TRANSMIT_DATA *Udp4TxData; - UINT32 FragCount; - UINT32 DataLength; - EFI_UDP4_SESSION_DATA Udp4Session; - EFI_STATUS Status; - BOOLEAN IsDone; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_MAC_ADDRESS TempMacAddr; - - IsDone =3D FALSE; - - if ((This =3D=3D NULL) || (DestIp =3D=3D NULL) || (DestPort =3D=3D NULL)= ) { - return EFI_INVALID_PARAMETER; - } - - if ((GatewayIp !=3D NULL) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp->Addr= [0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp->Addr[0])))) { - // - // Gateway is provided but it's not a unicast IP address. - // - return EFI_INVALID_PARAMETER; - } - - if ((HeaderSize !=3D NULL) && ((*HeaderSize =3D=3D 0) || (HeaderPtr =3D= =3D NULL))) { - // - // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the = HeaderPtr - // is NULL. - // - return EFI_INVALID_PARAMETER; - } - - if ((BufferSize =3D=3D NULL) || ((*BufferSize !=3D 0) && (BufferPtr =3D= =3D NULL))) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Udp4 =3D Private->Udp4Write; - Mode =3D &Private->Mode; - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - if (!Private->AddressIsOk && (SrcIp =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - if (!Mode->AutoArp) { - // - // If AutoArp is set false, check arp cache - // - UpdateArpCache (This); - if (!FindInArpCache (Mode, &DestIp->v4, &TempMacAddr)) { - return EFI_DEVICE_ERROR; - } - } - - Mode->IcmpErrorReceived =3D FALSE; - - if ((Private->CurrentUdpSrcPort =3D=3D 0) || - ((SrcPort !=3D NULL) && (*SrcPort !=3D Private->CurrentUdpSrcPort)))= { - // - // Port is changed, (re)configure the Udp4Write instance - // - if (SrcPort !=3D NULL) { - Private->CurrentUdpSrcPort =3D *SrcPort; - } - } - - Status =3D PxeBcConfigureUdpWriteInstance ( - Udp4, - &Private->StationIp.v4, - &Private->SubnetMask.v4, - &Private->GatewayIp.v4, - &Private->CurrentUdpSrcPort, - Private->Mode.TTL, - Private->Mode.ToS - ); - if (EFI_ERROR (Status)) { - Private->CurrentUdpSrcPort =3D 0; - return EFI_INVALID_PARAMETER; - } - - ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN)); - ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA)); - - CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRE= SS)); - Udp4Session.DestinationPort =3D *DestPort; - if (SrcIp !=3D NULL) { - CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS))= ; - } - if (SrcPort !=3D NULL) { - Udp4Session.SourcePort =3D *SrcPort; - } - - FragCount =3D (HeaderSize !=3D NULL) ? 2 : 1; - Udp4TxData =3D (EFI_UDP4_TRANSMIT_DATA *) AllocateZeroPool (sizeof (EFI_= UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA)); - if (Udp4TxData =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Udp4TxData->FragmentCount =3D FragCount; - Udp4TxData->FragmentTable[FragCount - 1].FragmentLength =3D (UINT32) *Bu= fferSize; - Udp4TxData->FragmentTable[FragCount - 1].FragmentBuffer =3D BufferPtr; - DataLength =3D (UINT32) *BufferSize; - - if (FragCount =3D=3D 2) { - - Udp4TxData->FragmentTable[0].FragmentLength =3D (UINT32) *HeaderSize; - Udp4TxData->FragmentTable[0].FragmentBuffer =3D HeaderPtr; - DataLength +=3D (UINT32) *HeaderSize; - } - - if (GatewayIp !=3D NULL) { - Udp4TxData->GatewayAddress =3D (EFI_IPv4_ADDRESS *) GatewayIp; - } - Udp4TxData->UdpSessionData =3D &Udp4Session; - Udp4TxData->DataLength =3D DataLength; - Token.Packet.TxData =3D Udp4TxData; - - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - PxeBcCommonNotify, - &IsDone, - &Token.Event - ); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - - Status =3D Udp4->Transmit (Udp4, &Token); - if (EFI_ERROR (Status)) { - if (Status =3D=3D EFI_ICMP_ERROR) { - Mode->IcmpErrorReceived =3D TRUE; - } - goto ON_EXIT; - } - - while (!IsDone) { - - Udp4->Poll (Udp4); - } - - Status =3D Token.Status; - -ON_EXIT: - - if (Token.Event !=3D NULL) { - gBS->CloseEvent (Token.Event); - } - - FreePool (Udp4TxData); - - // - // Reset the instance. - // - Udp4->Configure (Udp4, NULL); - return Status; -} - -/** - Decide whether the incoming UDP packet is acceptable per IP filter setti= ngs - in provided PxeBcMode. - - @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE. - @param Session Received UDP session. - - @retval TRUE The UDP package matches IP filters. - @retval FALSE The UDP package doesn't matches IP filters. - -**/ -BOOLEAN -CheckIpByFilter ( - IN EFI_PXE_BASE_CODE_MODE *PxeBcMode, - IN EFI_UDP4_SESSION_DATA *Session - ) -{ - UINTN Index; - EFI_IPv4_ADDRESS Ip4Address; - EFI_IPv4_ADDRESS DestIp4Address; - - if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUO= US) !=3D 0) { - return TRUE; - } - - CopyMem (&DestIp4Address, &Session->DestinationAddress, sizeof (DestIp4A= ddress)); - if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCU= OUS_MULTICAST) !=3D 0) && - IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address)) - ) { - return TRUE; - } - - if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAS= T) !=3D 0) && - IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address)) - ) { - return TRUE; - } - - CopyMem (&Ip4Address, &PxeBcMode->StationIp.v4, sizeof (Ip4Address)); - if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_= IP) !=3D 0) && - EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address) - ) { - return TRUE; - } - - ASSERT (PxeBcMode->IpFilter.IpCnt < EFI_PXE_BASE_CODE_MAX_IPCNT); - - for (Index =3D 0; Index < PxeBcMode->IpFilter.IpCnt; Index++) { - CopyMem ( - &Ip4Address, - &PxeBcMode->IpFilter.IpList[Index].v4, - sizeof (Ip4Address) - ); - if (EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)) { - return TRUE; - } - } - - return FALSE; -} - -/** - Reads a UDP packet from the network interface. - - This function reads a UDP packet from a network interface. The data cont= ents - are returned in (the optional HeaderPtr and) BufferPtr, and the size of = the - buffer received is returned in BufferSize . If the input BufferSize is s= maller - than the UDP packet received (less optional HeaderSize), it will be set = to the - required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, = the - contents of BufferPtr are undefined, and the packet is lost. If a UDP pa= cket is - successfully received, then EFI_SUCCESS will be returned, and the inform= ation - from the UDP header will be returned in DestIp, DestPort, SrcIp, and Src= Port if - they are not NULL. Depending on the values of OpFlags and the DestIp, De= stPort, - SrcIp, and SrcPort input values, different types of UDP packet receive f= iltering - will be performed. The following tables summarize these receive filter o= perations. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param OpFlags The UDP operation flags. - @param DestIp The destination IP address. - @param DestPort The destination UDP port number. - @param SrcIp The source IP address. - @param SrcPort The source UDP port number. - @param HeaderSize An optional field which may be set to the = length of a header at - HeaderPtr to be prefixed to the data at Bu= fferPtr. - @param HeaderPtr If HeaderSize is not NULL, a pointer to a = header to be prefixed to the - data at BufferPtr. - @param BufferSize A pointer to the size of the data at Buffe= rPtr. - @param BufferPtr A pointer to the data to be read. - - @retval EFI_SUCCESS The UDP Read operation was completed. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this operation. - @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold. - @retval EFI_ABORTED The callback function aborted the UDP Read= operation. - @retval EFI_TIMEOUT The UDP Read operation timed out. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcUdpRead ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN UINT16 OpFlags, - IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL, - IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL, - IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL, - IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL, - IN UINTN *HeaderSize OPTIONAL, - IN VOID *HeaderPtr OPTIONAL, - IN OUT UINTN *BufferSize, - IN VOID *BufferPtr - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_UDP4_PROTOCOL *Udp4; - EFI_UDP4_COMPLETION_TOKEN Token; - EFI_UDP4_RECEIVE_DATA *RxData; - EFI_UDP4_SESSION_DATA *Session; - EFI_STATUS Status; - BOOLEAN IsDone; - BOOLEAN Matched; - UINTN CopiedLen; - UINTN HeaderLen; - UINTN HeaderCopiedLen; - UINTN BufferCopiedLen; - UINT32 FragmentLength; - UINTN FragmentIndex; - UINT8 *FragmentBuffer; - - if (This =3D=3D NULL || DestIp =3D=3D NULL || DestPort =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) =3D=3D 0 &&= (DestPort =3D=3D NULL)) || - ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) =3D=3D 0 &&= (SrcIp =3D=3D NULL)) || - ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) =3D=3D 0 && = (SrcPort =3D=3D NULL))) { - return EFI_INVALID_PARAMETER; - } - - if (((HeaderSize !=3D NULL) && (*HeaderSize =3D=3D 0)) || ((HeaderSize != =3D NULL) && (HeaderPtr =3D=3D NULL))) { - return EFI_INVALID_PARAMETER; - } - - if ((BufferSize =3D=3D NULL) || (BufferPtr =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - Udp4 =3D Private->Udp4Read; - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - Mode->IcmpErrorReceived =3D FALSE; - - Status =3D gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - PxeBcCommonNotify, - &IsDone, - &Token.Event - ); - if (EFI_ERROR (Status)) { - return EFI_OUT_OF_RESOURCES; - } - -TRY_AGAIN: - - IsDone =3D FALSE; - Status =3D Udp4->Receive (Udp4, &Token); - if (EFI_ERROR (Status)) { - if (Status =3D=3D EFI_ICMP_ERROR) { - Mode->IcmpErrorReceived =3D TRUE; - } - goto ON_EXIT; - } - - Udp4->Poll (Udp4); - - if (!IsDone) { - Status =3D EFI_TIMEOUT; - } else { - - // - // check whether this packet matches the filters - // - if (EFI_ERROR (Token.Status)){ - goto ON_EXIT; - } - - RxData =3D Token.Packet.RxData; - Session =3D &RxData->UdpSession; - - Matched =3D TRUE; - - if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER) !=3D 0) { - Matched =3D FALSE; - // - // Check UDP package by IP filter settings - // - if (CheckIpByFilter (Mode, Session)) { - Matched =3D TRUE; - } - } - - if (Matched) { - Matched =3D FALSE; - - // - // Match the destination ip of the received udp dgram - // - if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP) !=3D 0) { - Matched =3D TRUE; - - if (DestIp !=3D NULL) { - CopyMem (DestIp, &Session->DestinationAddress, sizeof (EFI_IPv4_= ADDRESS)); - } - } else { - if (DestIp !=3D NULL) { - if (EFI_IP4_EQUAL (DestIp, &Session->DestinationAddress)) { - Matched =3D TRUE; - } - } else { - if (EFI_IP4_EQUAL (&Private->StationIp, &Session->DestinationAdd= ress)) { - Matched =3D TRUE; - } - } - } - } - - if (Matched) { - // - // Match the destination port of the received udp dgram - // - if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) !=3D 0) = { - - if (DestPort !=3D NULL) { - *DestPort =3D Session->DestinationPort; - } - } else { - - if (*DestPort !=3D Session->DestinationPort) { - Matched =3D FALSE; - } - } - } - - if (Matched) { - // - // Match the source ip of the received udp dgram - // - if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) !=3D 0) { - - if (SrcIp !=3D NULL) { - CopyMem (SrcIp, &Session->SourceAddress, sizeof (EFI_IPv4_ADDRES= S)); - } - } else { - - if (!EFI_IP4_EQUAL (SrcIp, &Session->SourceAddress)) { - Matched =3D FALSE; - } - } - } - - if (Matched) { - // - // Match the source port of the received udp dgram - // - if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) !=3D 0) { - - if (SrcPort !=3D NULL) { - *SrcPort =3D Session->SourcePort; - } - } else { - - if (*SrcPort !=3D Session->SourcePort) { - Matched =3D FALSE; - } - } - } - - if (Matched) { - ASSERT (RxData !=3D NULL); - - HeaderLen =3D 0; - if (HeaderSize !=3D NULL) { - HeaderLen =3D MIN (*HeaderSize, RxData->DataLength); - } - - if (RxData->DataLength - HeaderLen > *BufferSize) { - Status =3D EFI_BUFFER_TOO_SMALL; - } else { - *HeaderSize =3D HeaderLen; - *BufferSize =3D RxData->DataLength - HeaderLen; - - HeaderCopiedLen =3D 0; - BufferCopiedLen =3D 0; - for (FragmentIndex =3D 0; FragmentIndex < RxData->FragmentCount; F= ragmentIndex++) { - FragmentLength =3D RxData->FragmentTable[FragmentIndex].Fragment= Length; - FragmentBuffer =3D RxData->FragmentTable[FragmentIndex].Fragment= Buffer; - if (HeaderCopiedLen + FragmentLength < HeaderLen) { - // - // Copy the header part of received data. - // - CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer= , FragmentLength); - HeaderCopiedLen +=3D FragmentLength; - } else if (HeaderCopiedLen < HeaderLen) { - // - // Copy the header part of received data. - // - CopiedLen =3D HeaderLen - HeaderCopiedLen; - CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer= , CopiedLen); - HeaderCopiedLen +=3D CopiedLen; - - // - // Copy the other part of received data. - // - CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer= + CopiedLen, FragmentLength - CopiedLen); - BufferCopiedLen +=3D (FragmentLength - CopiedLen); - } else { - // - // Copy the other part of received data. - // - CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer= , FragmentLength); - BufferCopiedLen +=3D FragmentLength; - } - } - } - } else { - - Status =3D EFI_TIMEOUT; - } - - // - // Recycle the RxData - // - gBS->SignalEvent (RxData->RecycleSignal); - - if (!Matched) { - goto TRY_AGAIN; - } - } - -ON_EXIT: - - Udp4->Cancel (Udp4, &Token); - - gBS->CloseEvent (Token.Event); - - return Status; -} - -/** - Updates the IP receive filters of a network device and enables software = filtering. - - The NewFilter field is used to modify the network device's current IP re= ceive - filter settings and to enable a software filter. This function updates t= he IpFilter - field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIp= Filter. - The software filter is used when the USE_FILTER in OpFlags is set to Udp= Read(). - The current hardware filter remains in effect no matter what the setting= s of OpFlags - are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is f= rom those - packets whose reception is enabled in hardware-physical NIC address (uni= cast), - broadcast address, logical address or addresses (multicast), or all (pro= miscuous). - UdpRead() does not modify the IP filter settings. - Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the I= P receive - filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_ST= ATION_IP. - If an application or driver wishes to preserve the IP receive filter set= tings, - it will have to preserve the IP receive filter settings before these cal= ls, and - use SetIpFilter() to restore them after the calls. If incompatible filte= ring is - requested (for example, PROMISCUOUS with anything else) or if the device= does not - support a requested filter setting and it cannot be accommodated in soft= ware - (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be = returned. - The IPlist field is used to enable IPs other than the StationIP. They ma= y be - multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FI= LTER_STATION_IP, - then both the StationIP and the IPs from the IPlist will be used. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param NewFilter Pointer to the new set of IP receive filte= rs. - - @retval EFI_SUCCESS The IP receive filter settings were update= d. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcSetIpFilter ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter - ) -{ - EFI_STATUS Status; - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - UINTN Index; - EFI_UDP4_CONFIG_DATA *Udp4Cfg; - BOOLEAN PromiscuousNeed; - BOOLEAN AcceptPromiscuous; - BOOLEAN AcceptBroadcast; - BOOLEAN MultiCastUpdate; - - if (This =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "This =3D=3D NULL.\n")); - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (NewFilter =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "NewFilter =3D=3D NULL.\n")); - return EFI_INVALID_PARAMETER; - } - - if (NewFilter->IpCnt > EFI_PXE_BASE_CODE_MAX_IPCNT) { - DEBUG ((EFI_D_ERROR, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX= _IPCNT)); - return EFI_INVALID_PARAMETER; - } - - if (!Mode->Started) { - DEBUG ((EFI_D_ERROR, "BC was not started.\n")); - return EFI_NOT_STARTED; - } - - if (Mode->UsingIpv6) { - DEBUG ((EFI_D_ERROR, "This driver is PXE for IPv4 Only.\n")); - return EFI_INVALID_PARAMETER; - } - - PromiscuousNeed =3D FALSE; - - for (Index =3D 0; Index < NewFilter->IpCnt; ++Index) { - if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter->IpList[Index].v4))) { - // - // The IP is a broadcast address. - // - DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n")); - return EFI_INVALID_PARAMETER; - } - if ((EFI_NTOHL(Mode->StationIp) !=3D 0) && - (EFI_NTOHL(Mode->SubnetMask) !=3D 0) && - IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpL= ist[Index].v4), EFI_NTOHL(Mode->SubnetMask)) && - NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(= Mode->SubnetMask)) && - ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != =3D 0)) { - // - // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address = is in IpList, - // promiscuous mode is needed. - // - PromiscuousNeed =3D TRUE; - } - } - - AcceptPromiscuous =3D FALSE; - AcceptBroadcast =3D FALSE; - MultiCastUpdate =3D FALSE; - - if (PromiscuousNeed || - ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) !=3D= 0) || - ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTI= CAST) !=3D 0) - ) { - // - // Configure the udp4 filter to receive all packages. - // - AcceptPromiscuous =3D TRUE; - } else if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) = !=3D 0) { - // - // Configure the udp4 filter to receive all broadcast packages. - // - AcceptBroadcast =3D TRUE; - } - - // - // In multicast condition when Promiscuous FALSE and IpCnt no-zero. - // Here check if there is any update of the multicast ip address. If yes= , - // we need leave the old multicast group (by Config UDP instance to NULL= ), - // and join the new multicast group. - // - if (!AcceptPromiscuous) { - if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) !=3D= 0) { - if (Mode->IpFilter.IpCnt !=3D NewFilter->IpCnt) { - MultiCastUpdate =3D TRUE; - } else if (CompareMem (Mode->IpFilter.IpList, NewFilter->IpList, New= Filter->IpCnt * sizeof (EFI_IP_ADDRESS)) !=3D 0 ) { - MultiCastUpdate =3D TRUE; - } - } - } - - // - // Check whether we need reconfigure the UDP instance. - // - Udp4Cfg =3D &Private->Udp4CfgData; - if ((AcceptPromiscuous !=3D Udp4Cfg->AcceptPromiscuous) || - (AcceptBroadcast !=3D Udp4Cfg->AcceptBroadcast) || MultiCastUpda= te) { - // - // Clear the UDP instance configuration, all joined groups will be lef= t - // during the operation. - // - Private->Udp4Read->Configure (Private->Udp4Read, NULL); - - // - // Configure the UDP instance with the new configuration. - // - Udp4Cfg->AcceptPromiscuous =3D AcceptPromiscuous; - Udp4Cfg->AcceptBroadcast =3D AcceptBroadcast; - Status =3D Private->Udp4Read->Configure (Private->Udp4Read, Udp4Cfg); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // In not Promiscuous mode, need to join the new multicast group. - // - if (!AcceptPromiscuous) { - for (Index =3D 0; Index < NewFilter->IpCnt; ++Index) { - if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter->IpList[Index].v4))) { - // - // Join the mutilcast group. - // - Status =3D Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &= NewFilter->IpList[Index].v4); - if (EFI_ERROR (Status)) { - return Status; - } - } - } - } - } - - - // - // Save the new filter. - // - CopyMem (&Mode->IpFilter, NewFilter, sizeof (Mode->IpFilter)); - - return EFI_SUCCESS; -} - - -/** - Uses the ARP protocol to resolve a MAC address. - - This function uses the ARP protocol to resolve a MAC address. The UsingI= pv6 field - of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or = IPv6 - addresses are being used. The IP address specified by IpAddr is used to = resolve - a MAC address. If the ARP protocol succeeds in resolving the specified a= ddress, - then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MO= DE structure - are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the re= solved - MAC address is placed there as well. If the PXE Base Code protocol is i= n the - stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol enc= ounters - a timeout condition while attempting to resolve an address, then EFI_TIM= EOUT is - returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CAL= LBACK_STATUS_CONTINUE, - then EFI_ABORTED is returned. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param IpAddr Pointer to the IP address that is used to = resolve a MAC address. - @param MacAddr If not NULL, a pointer to the MAC address = that was resolved with the - ARP protocol. - - @retval EFI_SUCCESS The IP or MAC address was resolved. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_DEVICE_ERROR The network device encountered an error du= ring this operation. - @retval EFI_ICMP_ERROR Something error occur with the ICMP packet= message. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcArp ( - IN EFI_PXE_BASE_CODE_PROTOCOL * This, - IN EFI_IP_ADDRESS * IpAddr, - IN EFI_MAC_ADDRESS * MacAddr OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_STATUS Status; - EFI_MAC_ADDRESS TempMacAddr; - - if (This =3D=3D NULL || IpAddr =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - if (!Private->AddressIsOk || Mode->UsingIpv6) { - // - // We can't resolve the IP address if we don't have a local address no= w. - // Don't have ARP for IPv6. - // - return EFI_INVALID_PARAMETER; - } - - Mode->IcmpErrorReceived =3D FALSE; - - if (!Mode->AutoArp) { - // - // If AutoArp is set false, check arp cache - // - UpdateArpCache (This); - if (!FindInArpCache (Mode, &IpAddr->v4, &TempMacAddr)) { - return EFI_DEVICE_ERROR; - } - } else { - Status =3D Private->Arp->Request (Private->Arp, &IpAddr->v4, NULL, &Te= mpMacAddr); - if (EFI_ERROR (Status)) { - if (Status =3D=3D EFI_ICMP_ERROR) { - Mode->IcmpErrorReceived =3D TRUE; - } - return Status; - } - } - - if (MacAddr !=3D NULL) { - CopyMem (MacAddr, &TempMacAddr, sizeof (EFI_MAC_ADDRESS)); - } - - return EFI_SUCCESS; -} - -/** - Updates the parameters that affect the operation of the PXE Base Code Pr= otocol. - - This function sets parameters that affect the operation of the PXE Base = Code Protocol. - The parameter specified by NewAutoArp is used to control the generation = of ARP - protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will = be generated - as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then = no ARP - Protocol packets will be generated. In this case, the only mappings that= are - available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE= structure. - If there are not enough mappings in the ArpCache to perform a PXE Base C= ode Protocol - service, then the service will fail. This function updates the AutoArp f= ield of - the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp. - The SetParameters() call must be invoked after a Callback Protocol is in= stalled - to enable the use of callbacks. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param NewAutoArp If not NULL, a pointer to a value that spe= cifies whether to replace the - current value of AutoARP. - @param NewSendGUID If not NULL, a pointer to a value that spe= cifies whether to replace the - current value of SendGUID. - @param NewTTL If not NULL, a pointer to be used in place= of the current value of TTL, - the "time to live" field of the IP header. - @param NewToS If not NULL, a pointer to be used in place= of the current value of ToS, - the "type of service" field of the IP head= er. - @param NewMakeCallback If not NULL, a pointer to a value that spe= cifies whether to replace the - current value of the MakeCallback field of= the Mode structure. - - @retval EFI_SUCCESS The new parameters values were updated. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcSetParameters ( - IN EFI_PXE_BASE_CODE_PROTOCOL *This, - IN BOOLEAN *NewAutoArp OPTIONAL, - IN BOOLEAN *NewSendGUID OPTIONAL, - IN UINT8 *NewTTL OPTIONAL, - IN UINT8 *NewToS OPTIONAL, - IN BOOLEAN *NewMakeCallback // OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_STATUS Status; - - Status =3D EFI_SUCCESS; - - if (This =3D=3D NULL) { - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (NewSendGUID !=3D NULL && *NewSendGUID) { - // - // FixMe, cann't locate SendGuid - // - } - - if (NewMakeCallback !=3D NULL && *NewMakeCallback) { - - Status =3D gBS->HandleProtocol ( - Private->Controller, - &gEfiPxeBaseCodeCallbackProtocolGuid, - (VOID **) &Private->PxeBcCallback - ); - if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback =3D=3D NUL= L)) { - - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - } - - if (!Mode->Started) { - Status =3D EFI_NOT_STARTED; - goto ON_EXIT; - } - - if (NewMakeCallback !=3D NULL) { - - if (*NewMakeCallback) { - // - // Update the Callback protocol. - // - Status =3D gBS->HandleProtocol ( - Private->Controller, - &gEfiPxeBaseCodeCallbackProtocolGuid, - (VOID **) &Private->PxeBcCallback - ); - - if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback =3D=3D N= ULL)) { - Status =3D EFI_INVALID_PARAMETER; - goto ON_EXIT; - } - } else { - Private->PxeBcCallback =3D NULL; - } - - Mode->MakeCallbacks =3D *NewMakeCallback; - } - - if (NewAutoArp !=3D NULL) { - Mode->AutoArp =3D *NewAutoArp; - } - - if (NewSendGUID !=3D NULL) { - Mode->SendGUID =3D *NewSendGUID; - } - - if (NewTTL !=3D NULL) { - Mode->TTL =3D *NewTTL; - } - - if (NewToS !=3D NULL) { - Mode->ToS =3D *NewToS; - } - -ON_EXIT: - return Status; -} - -/** - Updates the station IP address and/or subnet mask values of a network de= vice. - - This function updates the station IP address and/or subnet mask values o= f a network - device. The NewStationIp field is used to modify the network device's cu= rrent IP address. - If NewStationIP is NULL, then the current IP address will not be modifie= d. Otherwise, - this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE = structure - with NewStationIp. The NewSubnetMask field is used to modify the network= device's current subnet - mask. If NewSubnetMask is NULL, then the current subnet mask will not be= modified. - Otherwise, this function updates the SubnetMask field of the EFI_PXE_BAS= E_CODE_MODE - structure with NewSubnetMask. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL = instance. - @param NewStationIp Pointer to the new IP address to be used b= y the network device. - @param NewSubnetMask Pointer to the new subnet mask to be used = by the network device. - - @retval EFI_SUCCESS The new station IP address and/or subnet m= ask were updated. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopp= ed state. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcSetStationIP ( - IN EFI_PXE_BASE_CODE_PROTOCOL * This, - IN EFI_IP_ADDRESS * NewStationIp OPTIONAL, - IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_ARP_CONFIG_DATA ArpConfigData; - - if (This =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - if (NewSubnetMask !=3D NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMa= sk->Addr[0]))) { - return EFI_INVALID_PARAMETER; - } - - if (NewStationIp !=3D NULL) { - if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) || - IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp->Addr[0])) || - (NewSubnetMask !=3D NULL && NewSubnetMask->Addr[0] !=3D 0 && !NetI= p4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0]))= )) { - return EFI_INVALID_PARAMETER; - } - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - if (NewStationIp !=3D NULL) { - CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS)); - CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS)); - } - - if (NewSubnetMask !=3D NULL) { - CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS)); - CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS))= ; - } - - Private->AddressIsOk =3D TRUE; - - if (!Mode->UsingIpv6) { - // - // If in IPv4 mode, configure the corresponding ARP with this new - // station IP address. - // - ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA)); - - ArpConfigData.SwAddressType =3D 0x0800; - ArpConfigData.SwAddressLength =3D (UINT8) sizeof (EFI_IPv4_ADDRESS); - ArpConfigData.StationAddress =3D &Private->StationIp.v4; - - Private->Arp->Configure (Private->Arp, NULL); - Private->Arp->Configure (Private->Arp, &ArpConfigData); - - // - // Update the route table. - // - Mode->RouteTableEntries =3D 1; - Mode->RouteTable[0].IpAddr.Addr[0] =3D Private->StationIp.Addr[0] = & Private->SubnetMask.Addr[0]; - Mode->RouteTable[0].SubnetMask.Addr[0] =3D Private->SubnetMask.Addr[0]= ; - Mode->RouteTable[0].GwAddr.Addr[0] =3D 0; - } - - return EFI_SUCCESS; -} - -/** - Updates the contents of the cached DHCP and Discover packets. - - The pointers to the new packets are used to update the contents of the c= ached - packets in the EFI_PXE_BASE_CODE_MODE structure. - - @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL= instance. - @param NewDhcpDiscoverValid Pointer to a value that will replace the = current - DhcpDiscoverValid field. - @param NewDhcpAckReceived Pointer to a value that will replace the = current - DhcpAckReceived field. - @param NewProxyOfferReceived Pointer to a value that will replace the = current - ProxyOfferReceived field. - @param NewPxeDiscoverValid Pointer to a value that will replace the = current - ProxyOfferReceived field. - @param NewPxeReplyReceived Pointer to a value that will replace the = current - PxeReplyReceived field. - @param NewPxeBisReplyReceived Pointer to a value that will replace the = current - PxeBisReplyReceived field. - @param NewDhcpDiscover Pointer to the new cached DHCP Discover p= acket contents. - @param NewDhcpAck Pointer to the new cached DHCP Ack packet= contents. - @param NewProxyOffer Pointer to the new cached Proxy Offer pac= ket contents. - @param NewPxeDiscover Pointer to the new cached PXE Discover pa= cket contents. - @param NewPxeReply Pointer to the new cached PXE Reply packe= t contents. - @param NewPxeBisReply Pointer to the new cached PXE BIS Reply p= acket contents. - - @retval EFI_SUCCESS The cached packet contents were updated. - @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stop= ped state. - @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_= PXE_BASE_CODE_PROTOCOL structure. - -**/ -EFI_STATUS -EFIAPI -EfiPxeBcSetPackets ( - IN EFI_PXE_BASE_CODE_PROTOCOL * This, - IN BOOLEAN * NewDhcpDiscoverValid OPTIONAL, - IN BOOLEAN * NewDhcpAckReceived OPTIONAL, - IN BOOLEAN * NewProxyOfferReceived OPTIONAL, - IN BOOLEAN * NewPxeDiscoverValid OPTIONAL, - IN BOOLEAN * NewPxeReplyReceived OPTIONAL, - IN BOOLEAN * NewPxeBisReplyReceived OPTIONAL, - IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover OPTIONAL, - IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck OPTIONAL, - IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer OPTIONAL, - IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover OPTIONAL, - IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply OPTIONAL, - IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_MODE *Mode; - - if (This =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_PXEBC (This); - Mode =3D Private->PxeBc.Mode; - - if (!Mode->Started) { - return EFI_NOT_STARTED; - } - - if (NewDhcpDiscoverValid !=3D NULL) { - Mode->DhcpDiscoverValid =3D *NewDhcpDiscoverValid; - } - - if (NewDhcpAckReceived !=3D NULL) { - Mode->DhcpAckReceived =3D *NewDhcpAckReceived; - } - - if (NewProxyOfferReceived !=3D NULL) { - Mode->ProxyOfferReceived =3D *NewProxyOfferReceived; - } - - if (NewPxeDiscoverValid !=3D NULL) { - Mode->PxeDiscoverValid =3D *NewPxeDiscoverValid; - } - - if (NewPxeReplyReceived !=3D NULL) { - Mode->PxeReplyReceived =3D *NewPxeReplyReceived; - } - - if (NewPxeBisReplyReceived !=3D NULL) { - Mode->PxeBisReplyReceived =3D *NewPxeBisReplyReceived; - } - - if (NewDhcpDiscover !=3D NULL) { - CopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CO= DE_PACKET)); - } - - if (NewDhcpAck !=3D NULL) { - CopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET)= ); - } - - if (NewProxyOffer !=3D NULL) { - CopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_P= ACKET)); - } - - if (NewPxeDiscover !=3D NULL) { - CopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE= _PACKET)); - } - - if (NewPxeReply !=3D NULL) { - CopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKE= T)); - } - - if (NewPxeBisReply !=3D NULL) { - CopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE= _PACKET)); - } - - return EFI_SUCCESS; -} - -EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate =3D { - EFI_PXE_BASE_CODE_PROTOCOL_REVISION, - EfiPxeBcStart, - EfiPxeBcStop, - EfiPxeBcDhcp, - EfiPxeBcDiscover, - EfiPxeBcMtftp, - EfiPxeBcUdpWrite, - EfiPxeBcUdpRead, - EfiPxeBcSetIpFilter, - EfiPxeBcArp, - EfiPxeBcSetParameters, - EfiPxeBcSetStationIP, - EfiPxeBcSetPackets, - NULL -}; - -/** - Callback function that is invoked when the PXE Base Code Protocol is abo= ut to transmit, has - received, or is waiting to receive a packet. - - This function is invoked when the PXE Base Code Protocol is about to tra= nsmit, has received, - or is waiting to receive a packet. Parameters Function and Received spec= ify the type of event. - Parameters PacketLen and Packet specify the packet that generated the ev= ent. If these fields - are zero and NULL respectively, then this is a status update callback. I= f the operation specified - by Function is to continue, then CALLBACK_STATUS_CONTINUE should be retu= rned. If the operation - specified by Function should be aborted, then CALLBACK_STATUS_ABORT shou= ld be returned. Due to - the polling nature of UEFI device drivers, a callback function should no= t execute for more than 5 ms. - The SetParameters() function must be called after a Callback Protocol is= installed to enable the - use of callbacks. - - @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_= PROTOCOL instance. - @param Function The PXE Base Code Protocol function that i= s waiting for an event. - @param Received TRUE if the callback is being invoked due = to a receive event. FALSE if - the callback is being invoked due to a tra= nsmit event. - @param PacketLength The length, in bytes, of Packet. This fiel= d will have a value of zero if - this is a wait for receive event. - @param PacketPtr If Received is TRUE, a pointer to the pack= et that was just received; - otherwise a pointer to the packet that is = about to be transmitted. - - @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies= a continue operation - @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies= an abort operation - -**/ -EFI_PXE_BASE_CODE_CALLBACK_STATUS -EFIAPI -EfiPxeLoadFileCallback ( - IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL * This, - IN EFI_PXE_BASE_CODE_FUNCTION Function, - IN BOOLEAN Received, - IN UINT32 PacketLength, - IN EFI_PXE_BASE_CODE_PACKET * PacketPtr OPTIONAL - ) -{ - EFI_INPUT_KEY Key; - EFI_STATUS Status; - - // - // Catch Ctrl-C or ESC to abort. - // - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - - if (!EFI_ERROR (Status)) { - - if (Key.ScanCode =3D=3D SCAN_ESC || Key.UnicodeChar =3D=3D (0x1F & 'c'= )) { - - return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT; - } - } - // - // No print if receive packet - // - if (Received) { - return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE; - } - // - // Print only for three functions - // - switch (Function) { - - case EFI_PXE_BASE_CODE_FUNCTION_MTFTP: - // - // Print only for open MTFTP packets, not every MTFTP packets - // - if (PacketLength !=3D 0 && PacketPtr !=3D NULL) { - if (PacketPtr->Raw[0x1C] !=3D 0x00 || PacketPtr->Raw[0x1D] !=3D 0x01= ) { - return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE; - } - } - break; - - case EFI_PXE_BASE_CODE_FUNCTION_DHCP: - case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER: - break; - - default: - return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE; - } - - if (PacketLength !=3D 0 && PacketPtr !=3D NULL) { - // - // Print '.' when transmit a packet - // - AsciiPrint ("."); - - } - - return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE; -} - -EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate =3D { - EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION, - EfiPxeLoadFileCallback -}; - - -/** - Find the boot file. - - @param Private Pointer to PxeBc private data. - @param BufferSize Pointer to buffer size. - @param Buffer Pointer to buffer. - - @retval EFI_SUCCESS Discover the boot file successfully. - @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out. - @retval EFI_ABORTED PXE bootstrap server, so local boot need ab= ort. - @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot fi= le. - -**/ -EFI_STATUS -DiscoverBootFile ( - IN PXEBC_PRIVATE_DATA *Private, - IN OUT UINT64 *BufferSize, - IN VOID *Buffer - ) -{ - EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; - EFI_PXE_BASE_CODE_MODE *Mode; - EFI_STATUS Status; - UINT16 Type; - UINT16 Layer; - BOOLEAN UseBis; - PXEBC_CACHED_DHCP4_PACKET *Packet; - UINT16 Value; - - PxeBc =3D &Private->PxeBc; - Mode =3D PxeBc->Mode; - Type =3D EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP; - Layer =3D EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL; - - // - // do DHCP. - // - Status =3D PxeBc->Dhcp (PxeBc, TRUE); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Select a boot server - // - Status =3D PxeBcSelectBootPrompt (Private); - - if (Status =3D=3D EFI_SUCCESS) { - Status =3D PxeBcSelectBootMenu (Private, &Type, TRUE); - } else if (Status =3D=3D EFI_TIMEOUT) { - Status =3D PxeBcSelectBootMenu (Private, &Type, FALSE); - } - - if (!EFI_ERROR (Status)) { - - if (Type =3D=3D EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) { - // - // Local boot(PXE bootstrap server) need abort - // - return EFI_ABORTED; - } - - UseBis =3D (BOOLEAN) (Mode->BisSupported && Mode->BisDetected); - Status =3D PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL); - if (EFI_ERROR (Status)) { - return Status; - } - } - - *BufferSize =3D 0; - - // - // Get bootfile name and (m)tftp server ip addresss - // - if (Mode->PxeReplyReceived) { - Packet =3D &Private->PxeReply; - } else if (Mode->ProxyOfferReceived) { - Packet =3D &Private->ProxyOffer; - } else { - Packet =3D &Private->Dhcp4Ack; - } - - // - // Use siaddr(next server) in DHCPOFFER packet header, if zero, use opti= on 54(server identifier) - // in DHCPOFFER packet. - // (It does not comply with PXE Spec, Ver2.1) - // - if (EFI_IP4_EQUAL (&Packet->Packet.Offer.Dhcp4.Header.ServerAddr, &mZero= Ip4Addr)) { - CopyMem ( - &Private->ServerIp, - Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data, - sizeof (EFI_IPv4_ADDRESS) - ); - } else { - CopyMem ( - &Private->ServerIp, - &Packet->Packet.Offer.Dhcp4.Header.ServerAddr, - sizeof (EFI_IPv4_ADDRESS) - ); - } - if (Private->ServerIp.Addr[0] =3D=3D 0) { - return EFI_DEVICE_ERROR; - } - - ASSERT (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] !=3D NULL); - - // - // bootlfile name - // - Private->BootFileName =3D (CHAR8 *) (Packet->Dhcp4Option[PXEBC_DHCP4_TAG= _INDEX_BOOTFILE]->Data); - - if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] !=3D NULL) { - // - // Already have the bootfile length option, compute the file size - // - CopyMem (&Value, Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LE= N]->Data, sizeof (Value)); - Value =3D NTOHS (Value); - *BufferSize =3D 512 * Value; - Status =3D EFI_BUFFER_TOO_SMALL; - } else { - // - // Get the bootfile size from tftp - // - Status =3D PxeBc->Mtftp ( - PxeBc, - EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, - Buffer, - FALSE, - BufferSize, - &Private->BlockSize, - &Private->ServerIp, - (UINT8 *) Private->BootFileName, - NULL, - FALSE - ); - } - - Private->FileSize =3D (UINTN) *BufferSize; - - // - // Display all the information: boot server address, boot file name and = boot file size. - // - AsciiPrint ("\n Server IP address is "); - PxeBcShowIp4Addr (&Private->ServerIp.v4); - AsciiPrint ("\n NBP filename is %a", Private->BootFileName); - AsciiPrint ("\n NBP filesize is %d Bytes", Private->FileSize); - - return Status; -} - -/** - Causes the driver to load a specified file. - - @param This Protocol instance pointer. - @param FilePath The device specific path of the file to lo= ad. - @param BootPolicy If TRUE, indicates that the request origin= ates from the - boot manager is attempting to load FilePat= h as a boot - selection. If FALSE, then FilePath must ma= tch as exact file - to be loaded. - @param BufferSize On input the size of Buffer in bytes. On o= utput with a return - code of EFI_SUCCESS, the amount of data tr= ansferred to - Buffer. On output with a return code of EF= I_BUFFER_TOO_SMALL, - the size of Buffer required to retrieve th= e requested file. - @param Buffer The memory buffer to transfer the file to.= IF Buffer is NULL, - then no the size of the requested file is = returned in - BufferSize. - - @retval EFI_SUCCESS The file was loaded. - @retval EFI_UNSUPPORTED The device does not support the prov= ided BootPolicy - @retval EFI_INVALID_PARAMETER FilePath is not a valid device path,= or - BufferSize is NULL. - @retval EFI_NO_MEDIA No medium was present to load the fi= le. - @retval EFI_DEVICE_ERROR The file was not loaded due to a dev= ice error. - @retval EFI_NO_RESPONSE The remote system did not respond. - @retval EFI_NOT_FOUND The file was not found. - @retval EFI_ABORTED The file load process was manually c= ancelled. - -**/ -EFI_STATUS -EFIAPI -EfiPxeLoadFile ( - IN EFI_LOAD_FILE_PROTOCOL * This, - IN EFI_DEVICE_PATH_PROTOCOL * FilePath, - IN BOOLEAN BootPolicy, - IN OUT UINTN *BufferSize, - IN VOID *Buffer OPTIONAL - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; - BOOLEAN NewMakeCallback; - EFI_STATUS Status; - UINT64 TmpBufSize; - EFI_STATUS MediaStatus; - - if (FilePath =3D=3D NULL || !IsDevicePathEnd (FilePath)) { - return EFI_INVALID_PARAMETER; - } - - Private =3D PXEBC_PRIVATE_DATA_FROM_LOADFILE (This); - PxeBc =3D &Private->PxeBc; - NewMakeCallback =3D FALSE; - Status =3D EFI_DEVICE_ERROR; - - if (This =3D=3D NULL || BufferSize =3D=3D NULL) { - - return EFI_INVALID_PARAMETER; - } - - // - // Only support BootPolicy - // - if (!BootPolicy) { - return EFI_UNSUPPORTED; - } - - // - // Check media status before PXE start - // - MediaStatus =3D EFI_SUCCESS; - NetLibDetectMediaWaitTimeout (Private->Controller, PXEBC_CHECK_MEDIA_WAI= TING_TIME, &MediaStatus); - if (MediaStatus !=3D EFI_SUCCESS) { - return EFI_NO_MEDIA; - } - - Status =3D PxeBc->Start (PxeBc, FALSE); - if (EFI_ERROR (Status) && (Status !=3D EFI_ALREADY_STARTED)) { - return Status; - } - - Status =3D gBS->HandleProtocol ( - Private->Controller, - &gEfiPxeBaseCodeCallbackProtocolGuid, - (VOID **) &Private->PxeBcCallback - ); - if (Status =3D=3D EFI_UNSUPPORTED) { - - CopyMem (&Private->LoadFileCallback, &mPxeBcCallBackTemplate, sizeof (= Private->LoadFileCallback)); - - Status =3D gBS->InstallProtocolInterface ( - &Private->Controller, - &gEfiPxeBaseCodeCallbackProtocolGuid, - EFI_NATIVE_INTERFACE, - &Private->LoadFileCallback - ); - - NewMakeCallback =3D (BOOLEAN) (Status =3D=3D EFI_SUCCESS); - - Status =3D PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NUL= L, &NewMakeCallback); - if (EFI_ERROR (Status)) { - PxeBc->Stop (PxeBc); - return Status; - } - } - - if (Private->FileSize =3D=3D 0) { - TmpBufSize =3D 0; - Status =3D DiscoverBootFile (Private, &TmpBufSize, Buffer); - - if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) { - Status =3D EFI_DEVICE_ERROR; - } else if (TmpBufSize > 0 && *BufferSize >=3D (UINTN) TmpBufSize && Bu= ffer !=3D NULL) { - AsciiPrint ("\n Downloading NBP file...\n"); - *BufferSize =3D (UINTN) TmpBufSize; - Status =3D PxeBc->Mtftp ( - PxeBc, - EFI_PXE_BASE_CODE_TFTP_READ_FILE, - Buffer, - FALSE, - &TmpBufSize, - &Private->BlockSize, - &Private->ServerIp, - (UINT8 *) Private->BootFileName, - NULL, - FALSE - ); - } else if (TmpBufSize > 0) { - *BufferSize =3D (UINTN) TmpBufSize; - Status =3D EFI_BUFFER_TOO_SMALL; - } - } else if (Buffer =3D=3D NULL || Private->FileSize > *BufferSize) { - *BufferSize =3D Private->FileSize; - Status =3D EFI_BUFFER_TOO_SMALL; - } else { - // - // Download the file. - // - AsciiPrint ("\n Downloading NBP file...\n"); - TmpBufSize =3D (UINT64) (*BufferSize); - Status =3D PxeBc->Mtftp ( - PxeBc, - EFI_PXE_BASE_CODE_TFTP_READ_FILE, - Buffer, - FALSE, - &TmpBufSize, - &Private->BlockSize, - &Private->ServerIp, - (UINT8 *) Private->BootFileName, - NULL, - FALSE - ); - } - // - // If we added a callback protocol, now is the time to remove it. - // - if (NewMakeCallback) { - - NewMakeCallback =3D FALSE; - - PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback)= ; - - gBS->UninstallProtocolInterface ( - Private->Controller, - &gEfiPxeBaseCodeCallbackProtocolGuid, - &Private->LoadFileCallback - ); - } - - // - // Check download status - // - if (Status =3D=3D EFI_SUCCESS) { - AsciiPrint ("\n NBP file downloaded successfully.\n"); - // - // The DHCP4 can have only one configured child instance so we need to= stop - // reset the DHCP4 child before we return. Otherwise the other program= s which - // also need to use DHCP4 will be impacted. - // The functionality of PXE Base Code protocol will not be stopped, - // when downloading is successfully. - // - Private->Dhcp4->Stop (Private->Dhcp4); - Private->Dhcp4->Configure (Private->Dhcp4, NULL); - return EFI_SUCCESS; - - } else if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - if (Buffer !=3D NULL) { - AsciiPrint ("PXE-E05: Download buffer is smaller than requested file= .\n"); - } else { - // - // The functionality of PXE Base Code protocol will not be stopped. - // - return Status; - } - - } else if (Status =3D=3D EFI_DEVICE_ERROR) { - AsciiPrint ("PXE-E07: Network device error.\n"); - - } else if (Status =3D=3D EFI_OUT_OF_RESOURCES) { - AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n"); - - } else if (Status =3D=3D EFI_NO_MEDIA) { - AsciiPrint ("PXE-E12: Could not detect network connection.\n"); - - } else if (Status =3D=3D EFI_NO_RESPONSE) { - AsciiPrint ("PXE-E16: No offer received.\n"); - - } else if (Status =3D=3D EFI_TIMEOUT) { - AsciiPrint ("PXE-E18: Server response timeout.\n"); - - } else if (Status =3D=3D EFI_ABORTED) { - AsciiPrint ("PXE-E21: Remote boot cancelled.\n"); - - } else if (Status =3D=3D EFI_ICMP_ERROR) { - AsciiPrint ("PXE-E22: Client received ICMP error from server.\n"); - - } else if (Status =3D=3D EFI_TFTP_ERROR) { - AsciiPrint ("PXE-E23: Client received TFTP error from server.\n"); - - } else { - AsciiPrint ("PXE-E99: Unexpected network error.\n"); - } - - PxeBc->Stop (PxeBc); - - return Status; -} - -EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate =3D { EfiPxeLoadFile }; - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c b/Mde= ModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c deleted file mode 100644 index 88767c8394ab..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.c +++ /dev/null @@ -1,454 +0,0 @@ -/** @file - PxeBc MTFTP functions. - -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - -#include "PxeBcImpl.h" - -CHAR8 *mMtftpOptions[PXE_MTFTP_OPTION_MAXIMUM_INDEX] =3D { - "blksize", - "timeout", - "tsize", - "multicast" -}; - - -/** - This is a callback function when packets received/transmitted in Mtftp d= river. - - A callback function that is provided by the caller to intercept - the EFI_MTFTP4_OPCODE_DATA or EFI_MTFTP4_OPCODE_DATA8 packets processed = in the - EFI_MTFTP4_PROTOCOL.ReadFile() function, and alternatively to intercept - EFI_MTFTP4_OPCODE_OACK or EFI_MTFTP4_OPCODE_ERROR packets during a call = to - EFI_MTFTP4_PROTOCOL.ReadFile(), WriteFile() or ReadDirectory(). - - @param This Pointer to Mtftp protocol instance - @param Token Pointer to Mtftp token - @param PacketLen Length of Mtftp packet - @param Packet Pointer to Mtftp packet - - @retval EFI_SUCCESS Operation sucess - @retval EFI_ABORTED Abort transfer process - -**/ -EFI_STATUS -EFIAPI -PxeBcCheckPacket ( - IN EFI_MTFTP4_PROTOCOL *This, - IN EFI_MTFTP4_TOKEN *Token, - IN UINT16 PacketLen, - IN EFI_MTFTP4_PACKET *Packet - ) -{ - PXEBC_PRIVATE_DATA *Private; - EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback; - EFI_STATUS Status; - - Private =3D (PXEBC_PRIVATE_DATA *) Token->Context; - Callback =3D Private->PxeBcCallback; - Status =3D EFI_SUCCESS; - - if (Packet->OpCode =3D=3D EFI_MTFTP4_OPCODE_ERROR) { - Private->Mode.TftpErrorReceived =3D TRUE; - Private->Mode.TftpError.ErrorCode =3D (UINT8) Packet->Error.ErrorCode; - AsciiStrnCpyS (Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_ST= RING_LENGTH, (CHAR8 *) Packet->Error.ErrorMessage, PXE_MTFTP_ERROR_STRING_L= ENGTH - 1); - Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - 1]= =3D '\0'; - } - - if (Callback !=3D NULL) { - - Status =3D Callback->Callback ( - Callback, - Private->Function, - TRUE, - PacketLen, - (EFI_PXE_BASE_CODE_PACKET *) Packet - ); - if (Status !=3D EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) { - - Status =3D EFI_ABORTED; - } else { - - Status =3D EFI_SUCCESS; - } - } - - return Status; -} - - -/** - This function is to get size of a file by Tftp. - - @param Private Pointer to PxeBc private data - @param Config Pointer to Mtftp configuration data - @param Filename Pointer to file name - @param BlockSize Pointer to block size - @param BufferSize Pointer to buffer size - - @retval EFI_SUCCESS Get the size of file success - @retval EFI_NOT_FOUND Parse the tftp ptions failed. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval Other Has not get the size of the file. - -**/ -EFI_STATUS -PxeBcTftpGetFileSize ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN UINTN *BlockSize, - IN OUT UINT64 *BufferSize - ) -{ - EFI_MTFTP4_PROTOCOL *Mtftp4; - EFI_MTFTP4_OPTION ReqOpt[2]; - EFI_MTFTP4_PACKET *Packet; - EFI_MTFTP4_OPTION *Option; - UINT32 PktLen; - UINT8 OptBuf[128]; - UINT32 OptCnt; - EFI_STATUS Status; - - *BufferSize =3D 0; - Status =3D EFI_DEVICE_ERROR; - Mtftp4 =3D Private->Mtftp4; - Packet =3D NULL; - Option =3D NULL; - PktLen =3D 0; - OptCnt =3D 1; - Config->InitialServerPort =3D PXEBC_BS_DOWNLOAD_PORT; - - Status =3D Mtftp4->Configure (Mtftp4, Config); - if (EFI_ERROR (Status)) { - - return Status; - } - - ReqOpt[0].OptionStr =3D (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_TSIZE_IND= EX]; - UtoA10 (0, (CHAR8 *) OptBuf, PXE_MTFTP_OPTBUF_MAXNUM_INDEX); - ReqOpt[0].ValueStr =3D OptBuf; - - if (BlockSize !=3D NULL) { - ReqOpt[1].OptionStr =3D (UINT8*)mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZE= _INDEX]; - ReqOpt[1].ValueStr =3D ReqOpt[0].ValueStr + AsciiStrLen ((CHAR8 *) Re= qOpt[0].ValueStr) + 1; - UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[1].ValueStr, PXE_MTFTP_OPTBUF_MAX= NUM_INDEX - (AsciiStrLen ((CHAR8 *) ReqOpt[0].ValueStr) + 1)); - OptCnt++; - } - - Status =3D Mtftp4->GetInfo ( - Mtftp4, - NULL, - Filename, - NULL, - (UINT8) OptCnt, - ReqOpt, - &PktLen, - &Packet - ); - - if (EFI_ERROR (Status)) { - if (Status =3D=3D EFI_TFTP_ERROR) { - Private->Mode.TftpErrorReceived =3D TRUE; - Private->Mode.TftpError.ErrorCode =3D (UINT8) Packet->Error.ErrorCod= e; - AsciiStrnCpyS ( - Private->Mode.TftpError.ErrorString, - PXE_MTFTP_ERROR_STRING_LENGTH, - (CHAR8 *) Packet->Error.ErrorMessage, - PXE_MTFTP_ERROR_STRING_LENGTH - 1 - ); - Private->Mode.TftpError.ErrorString[PXE_MTFTP_ERROR_STRING_LENGTH - = 1] =3D '\0'; - } - goto ON_ERROR; - } - - OptCnt =3D 0; - - Status =3D Mtftp4->ParseOptions ( - Mtftp4, - PktLen, - Packet, - (UINT32 *) &OptCnt, - &Option - ); - - if (EFI_ERROR (Status)) { - - goto ON_ERROR; - } - - Status =3D EFI_NOT_FOUND; - - while (OptCnt !=3D 0) { - - if (AsciiStrnCmp ((CHAR8 *) Option[OptCnt - 1].OptionStr, "tsize", 5) = =3D=3D 0) { - - *BufferSize =3D AtoU64 (Option[OptCnt - 1].ValueStr); - Status =3D EFI_SUCCESS; - } - - OptCnt--; - } - - FreePool (Option); - -ON_ERROR: - - if (Packet !=3D NULL) { - FreePool (Packet); - } - - Mtftp4->Configure (Mtftp4, NULL); - - return Status; -} - - -/** - This function is to get data of a file by Tftp. - - @param Private Pointer to PxeBc private data - @param Config Pointer to Mtftp configuration data - @param Filename Pointer to file name - @param BlockSize Pointer to block size - @param BufferPtr Pointer to buffer - @param BufferSize Pointer to buffer size - @param DontUseBuffer Indicate whether with a receive buffer - - @retval EFI_SUCCESS Read the data success from the special file. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval other Read data from file failed. - -**/ -EFI_STATUS -PxeBcTftpReadFile ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN UINTN *BlockSize, - IN UINT8 *BufferPtr, - IN OUT UINT64 *BufferSize, - IN BOOLEAN DontUseBuffer - ) -{ - EFI_MTFTP4_PROTOCOL *Mtftp4; - EFI_MTFTP4_TOKEN Token; - EFI_MTFTP4_OPTION ReqOpt[1]; - UINT32 OptCnt; - UINT8 OptBuf[128]; - EFI_STATUS Status; - - Status =3D EFI_DEVICE_ERROR; - Mtftp4 =3D Private->Mtftp4; - OptCnt =3D 0; - Config->InitialServerPort =3D PXEBC_BS_DOWNLOAD_PORT; - - Status =3D Mtftp4->Configure (Mtftp4, Config); - if (EFI_ERROR (Status)) { - - return Status; - } - - if (BlockSize !=3D NULL) { - - ReqOpt[0].OptionStr =3D (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZ= E_INDEX]; - ReqOpt[0].ValueStr =3D OptBuf; - UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAX= NUM_INDEX); - OptCnt++; - } - - Token.Event =3D NULL; - Token.OverrideData =3D NULL; - Token.Filename =3D Filename; - Token.ModeStr =3D NULL; - Token.OptionCount =3D OptCnt; - Token.OptionList =3D ReqOpt; - Token.Context =3D Private; - - if (DontUseBuffer) { - Token.BufferSize =3D 0; - Token.Buffer =3D NULL; - } else { - Token.BufferSize =3D *BufferSize; - Token.Buffer =3D BufferPtr; - } - - Token.CheckPacket =3D PxeBcCheckPacket; - Token.TimeoutCallback =3D NULL; - Token.PacketNeeded =3D NULL; - - Status =3D Mtftp4->ReadFile (Mtftp4, &Token); - - *BufferSize =3D Token.BufferSize; - - Mtftp4->Configure (Mtftp4, NULL); - - return Status; -} - - -/** - This function is put data of a file by Tftp. - - @param Private Pointer to PxeBc private data - @param Config Pointer to Mtftp configuration data - @param Filename Pointer to file name - @param Overwrite Indicate whether with overwrite attribute - @param BlockSize Pointer to block size - @param BufferPtr Pointer to buffer - @param BufferSize Pointer to buffer size - - @retval EFI_SUCCESS Write the data success into the special file. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval other Write data into file failed. - -**/ -EFI_STATUS -PxeBcTftpWriteFile ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN BOOLEAN Overwrite, - IN UINTN *BlockSize, - IN UINT8 *BufferPtr, - IN OUT UINT64 *BufferSize - ) -{ - EFI_MTFTP4_PROTOCOL *Mtftp4; - EFI_MTFTP4_TOKEN Token; - EFI_MTFTP4_OPTION ReqOpt[1]; - UINT32 OptCnt; - UINT8 OptBuf[128]; - EFI_STATUS Status; - - Status =3D EFI_DEVICE_ERROR; - Mtftp4 =3D Private->Mtftp4; - OptCnt =3D 0; - Config->InitialServerPort =3D PXEBC_BS_DOWNLOAD_PORT; - - Status =3D Mtftp4->Configure (Mtftp4, Config); - if (EFI_ERROR (Status)) { - - return Status; - } - - if (BlockSize !=3D NULL) { - - ReqOpt[0].OptionStr =3D (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZ= E_INDEX]; - ReqOpt[0].ValueStr =3D OptBuf; - UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAX= NUM_INDEX); - OptCnt++; - } - - Token.Event =3D NULL; - Token.OverrideData =3D NULL; - Token.Filename =3D Filename; - Token.ModeStr =3D NULL; - Token.OptionCount =3D OptCnt; - Token.OptionList =3D ReqOpt; - Token.BufferSize =3D *BufferSize; - Token.Buffer =3D BufferPtr; - Token.CheckPacket =3D PxeBcCheckPacket; - Token.TimeoutCallback =3D NULL; - Token.PacketNeeded =3D NULL; - - Status =3D Mtftp4->WriteFile (Mtftp4, &Token); - *BufferSize =3D Token.BufferSize; - - Mtftp4->Configure (Mtftp4, NULL); - - return Status; -} - - -/** - This function is to get data(file) from a directory(may be a server) by = Tftp. - - @param Private Pointer to PxeBc private data. - @param Config Pointer to Mtftp configuration data. - @param Filename Pointer to file name. - @param BlockSize Pointer to block size. - @param BufferPtr Pointer to buffer. - @param BufferSize Pointer to buffer size. - @param DontUseBuffer Indicate whether with a receive buffer. - - @retval EFI_SUCCES Get the data from the file included in direct= ory success. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval other Operation failed. - -**/ -EFI_STATUS -PxeBcTftpReadDirectory ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN UINTN *BlockSize, - IN UINT8 *BufferPtr, - IN OUT UINT64 *BufferSize, - IN BOOLEAN DontUseBuffer - ) -{ - EFI_MTFTP4_PROTOCOL *Mtftp4; - EFI_MTFTP4_TOKEN Token; - EFI_MTFTP4_OPTION ReqOpt[1]; - UINT32 OptCnt; - UINT8 OptBuf[128]; - EFI_STATUS Status; - - Status =3D EFI_DEVICE_ERROR; - Mtftp4 =3D Private->Mtftp4; - OptCnt =3D 0; - Config->InitialServerPort =3D PXEBC_BS_DOWNLOAD_PORT; - - Status =3D Mtftp4->Configure (Mtftp4, Config); - if (EFI_ERROR (Status)) { - - return Status; - } - - if (BlockSize !=3D NULL) { - - ReqOpt[0].OptionStr =3D (UINT8*) mMtftpOptions[PXE_MTFTP_OPTION_BLKSIZ= E_INDEX]; - ReqOpt[0].ValueStr =3D OptBuf; - UtoA10 (*BlockSize, (CHAR8 *) ReqOpt[0].ValueStr, PXE_MTFTP_OPTBUF_MAX= NUM_INDEX); - OptCnt++; - } - - Token.Event =3D NULL; - Token.OverrideData =3D NULL; - Token.Filename =3D Filename; - Token.ModeStr =3D NULL; - Token.OptionCount =3D OptCnt; - Token.OptionList =3D ReqOpt; - Token.Context =3D Private; - - if (DontUseBuffer) { - Token.BufferSize =3D 0; - Token.Buffer =3D NULL; - } else { - Token.BufferSize =3D *BufferSize; - Token.Buffer =3D BufferPtr; - } - - Token.CheckPacket =3D PxeBcCheckPacket; - Token.TimeoutCallback =3D NULL; - Token.PacketNeeded =3D NULL; - - Status =3D Mtftp4->ReadDirectory (Mtftp4, &Token); - - *BufferSize =3D Token.BufferSize; - - Mtftp4->Configure (Mtftp4, NULL); - - return Status; -} - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c b/M= deModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c deleted file mode 100644 index 1401ca5ec2fd..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c +++ /dev/null @@ -1,221 +0,0 @@ -/** @file - Support routines for PxeBc. - -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - - -#include "PxeBcImpl.h" - - -/** - The common notify function associated with various PxeBc events. - - @param Event The event signaled. - @param Context The context. - -**/ -VOID -EFIAPI -PxeBcCommonNotify ( - IN EFI_EVENT Event, - IN VOID *Context - ) -{ - *((BOOLEAN *) Context) =3D TRUE; -} - - -/** - This function initialize(or configure) the Udp4Write instance. - - @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance. - @param StationIp Pointer to the station ip address. - @param SubnetMask Pointer to the subnetmask of the station ip address. - @param Gateway Pointer to the gateway ip address. - @param SrcPort Pointer to the srouce port of the station. - @param Ttl The time to live field of the IP header. - @param ToS The type of service field of the IP header. - - @retval EFI_SUCCESS The configuration settings were set, chang= ed, or reset successfully. - @retval EFI_NO_MAPPING When using a default address, configuratio= n (DHCP, BOOTP, - RARP, etc.) is not finished yet. - @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE: - @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already= started/configured - and must be stopped/reset before it can be= reconfigured. - @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE - and UdpConfigData.StationPort is already u= sed by - other instance. - @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot alloc= ate memory for this - EFI UDPv4 Protocol instance. - @retval EFI_DEVICE_ERROR An unexpected network or system error occu= rred and this instance - was not opened. - @retval Others Please examine the function Udp4->Routes(U= dp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns. - -**/ -EFI_STATUS -PxeBcConfigureUdpWriteInstance ( - IN EFI_UDP4_PROTOCOL *Udp4, - IN EFI_IPv4_ADDRESS *StationIp, - IN EFI_IPv4_ADDRESS *SubnetMask, - IN EFI_IPv4_ADDRESS *Gateway, - IN OUT UINT16 *SrcPort, - IN UINT8 Ttl, - IN UINT8 ToS - ) -{ - EFI_UDP4_CONFIG_DATA Udp4CfgData; - EFI_STATUS Status; - - ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData)); - - Udp4CfgData.ReceiveTimeout =3D PXEBC_DEFAULT_LIFETIME; - Udp4CfgData.TypeOfService =3D ToS; - Udp4CfgData.TimeToLive =3D Ttl; - Udp4CfgData.AllowDuplicatePort =3D TRUE; - - CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp)); - CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask)); - - Udp4CfgData.StationPort =3D *SrcPort; - - // - // Reset the instance. - // - Udp4->Configure (Udp4, NULL); - - Status =3D Udp4->Configure (Udp4, &Udp4CfgData); - if (!EFI_ERROR (Status) && (Gateway->Addr[0] !=3D 0)) { - // - // basic configuration OK, need to add the default route entry - // - Status =3D Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Ga= teway); - if (EFI_ERROR (Status)) { - // - // roll back - // - Udp4->Configure (Udp4, NULL); - } - } - - if (!EFI_ERROR (Status) && (*SrcPort =3D=3D 0)) { - Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL); - *SrcPort =3D Udp4CfgData.StationPort; - } - - return Status; -} - -/** - This function is to display the IPv4 address. - - @param[in] Ip The pointer to the IPv4 address. - -**/ -VOID -PxeBcShowIp4Addr ( - IN EFI_IPv4_ADDRESS *Ip - ) -{ - UINTN Index; - - for (Index =3D 0; Index < 4; Index++) { - AsciiPrint ("%d", Ip->Addr[Index]); - if (Index < 3) { - AsciiPrint ("."); - } - } -} - -/** - Convert number to ASCII value. - - @param Number Numeric value to convert to decimal ASCII va= lue. - @param Buffer Buffer to place ASCII version of the Number. - @param Length Length of Buffer. - -**/ -VOID -CvtNum ( - IN UINTN Number, - IN UINT8 *Buffer, - IN UINTN Length - ) -{ - UINTN Remainder; - - for (; Length > 0; Length--) { - Remainder =3D Number % 10; - Number /=3D 10; - Buffer[Length - 1] =3D (UINT8) ('0' + Remainder); - } -} - - -/** - Convert unsigned int number to decimal number. - - @param Number The unsigned int number will be converted. - @param Buffer Pointer to the buffer to store the decimal nu= mber after transform. - @param[in] BufferSize The maxsize of the buffer. - - @return the length of the number after transform. - -**/ -UINTN -UtoA10 ( - IN UINTN Number, - IN CHAR8 *Buffer, - IN UINTN BufferSize - ) -{ - UINTN Index; - CHAR8 TempStr[64]; - - Index =3D 63; - TempStr[Index] =3D 0; - - do { - Index--; - TempStr[Index] =3D (CHAR8) ('0' + (Number % 10)); - Number =3D Number / 10; - } while (Number !=3D 0); - - AsciiStrCpyS (Buffer, BufferSize, &TempStr[Index]); - - return AsciiStrLen (Buffer); -} - - -/** - Convert ASCII numeric string to a UINTN value. - - @param Buffer Pointer to the 8-byte unsigned int value. - - @return UINTN value of the ASCII string. - -**/ -UINT64 -AtoU64 ( - IN UINT8 *Buffer - ) -{ - UINT64 Value; - UINT8 Character; - - Value =3D 0; - while ((Character =3D *Buffer++) !=3D '\0') { - Value =3D MultU64x32 (Value, 10) + (Character - '0'); - } - - return Value; -} - diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 2465d39fd744..5d042be3a862 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -354,12 +354,10 @@ [Components] MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf - MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf 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 MdeModulePkg/Universal/PcatSingleSegmentPciCfg2Pei/PcatSingleSegmentPciC= fg2Pei.inf @@ -422,7 +420,6 @@ [Components] MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf =20 [Components.IA32, Components.X64, Components.AARCH64] - MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf MdeModulePkg/Universal/EbcDxe/EbcDxe.inf MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.h b/MdeM= odulePkg/Universal/Network/IScsiDxe/ComponentName.h deleted file mode 100644 index ee371d26744c..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.h +++ /dev/null @@ -1,165 +0,0 @@ -/** @file - The header file of UEFI Component Name(2) protocol. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _COMPONENT_NAME_H_ -#define _COMPONENT_NAME_H_ - -#include -#include - -extern EFI_COMPONENT_NAME2_PROTOCOL gIScsiComponentName2; -extern EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName; - -// -// EFI Component Name Protocol for iSCSI driver. -// - -/** - Retrieves a Unicode string that is the user readable name of the EFI Dri= ver. - - This function retrieves the user readable name of a driver in the form o= f a - Unicode string. If the driver specified by This has a user readable name= 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 speci= fied - by This does not support the language specified by Language, - then EFI_UNSUPPORTED is returned. - - @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCOL ins= tance. - @param[in] Language A pointer to a three characters ISO 639-2 langua= ge identifier. - This is the language of the driver name that tha= t the caller - is requesting, and it must match one of the lang= uages specified - in SupportedLanguages. The number of languages = supported by a - driver is up to the driver writer. - @param[out] DriverName A pointer to the Unicode string to return. This= Unicode string - is the name of the driver specified by This in t= he language - specified by Language. - - @retval EFI_SUCCESS The Unicode string for the Driver specifie= d by This - and the language specified by Language 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 supp= ort the - language specified by Language. -**/ -EFI_STATUS -EFIAPI -IScsiComponentNameGetDriverName ( - IN EFI_COMPONENT_NAME_PROTOCOL *This, - IN CHAR8 *Language, - OUT CHAR16 **DriverName - ); - -/** - Retrieves a Unicode string that is the user readable name of the control= ler - that is being managed by an EFI Driver. Currently not implemented. - - @param[in] This A pointer to the EFI_COMPONENT_NAME_PROTOCO= L instance. - @param[in] ControllerHandle The handle of a controller that the driver = specified by - This is managing. This handle specifies th= e controller - whose name is to be returned. - @param[in] ChildHandle The handle of the child controller to retri= eve the name - of. This is an optional parameter that may= be NULL. It - will be NULL for device drivers. It will a= lso be NULL - for a bus drivers that wish to retrieve the= name of the - bus controller. It will not be NULL for a = bus driver - that wishes to retrieve the name of a child= controller. - @param[in] Language A pointer to a three characters ISO 639-2 l= anguage - identifier. This is the language of the co= ntroller name - that that the caller is requesting, and it = must match one - of the languages specified in SupportedLang= uages. The - number of languages supported by a driver i= s up to the - driver writer. - @param[out] ControllerName A pointer to the Unicode string to return. = This Unicode - string is the name of the controller specif= ied by - ControllerHandle and ChildHandle in the lan= guage 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 n= ame in the - language specified by Language for the dri= ver - specified by This was returned in DriverNa= me. - @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. - @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a va= lid 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 curren= tly managing - the controller specified by ControllerHand= le and - ChildHandle. - @retval EFI_UNSUPPORTED The driver specified by This does not supp= ort the - language specified by Language. -**/ -EFI_STATUS -EFIAPI -IScsiComponentNameGetControllerName ( - IN EFI_COMPONENT_NAME_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE ChildHandle OPTIONAL, - IN CHAR8 *Language, - OUT CHAR16 **ControllerName - ); - -// -// EFI iSCSI Initiator Name Protocol for IScsi driver. -// - -/** - Retrieves the current set value of iSCSI Initiator Name. - - @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROT= OCOL instance. - @param[in, out] BufferSize Size of the buffer in bytes pointed to by Bu= ffer / Actual size of the - variable data buffer. - @param[out] Buffer Pointer to the buffer for data to be read. - - @retval EFI_SUCCESS Data was successfully retrieved into the p= rovided buffer and the - BufferSize was sufficient to handle the iS= CSI initiator name - @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result. - @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL. - @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retr= ieved due to a hardware error. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiGetInitiatorName ( - IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ); - -/** - Sets the iSCSI Initiator Name. - - @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROT= OCOL instance. - @param[in, out] BufferSize Size of the buffer in bytes pointed to by Bu= ffer. - @param[in] Buffer Pointer to the buffer for data to be written= . - - @retval EFI_SUCCESS Data was successfully stored by the protoc= ol. - @retval EFI_UNSUPPORTED Platform policies do not allow for data to= be written. - Currently not implemented. - @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL, or BufferSiz= e exceeds the maximum allowed limit. - @retval EFI_DEVICE_ERROR The data could not be stored due to a hard= ware error. - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold th= e data. - @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere= to RFC 3720 - (and other related protocols) - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiSetInitiatorName ( - IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsi4Dxe.uni b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsi4Dxe.uni deleted file mode 100644 index d3c020e45d3b..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsi4Dxe.uni +++ /dev/null @@ -1,25 +0,0 @@ -// /** @file -// This module produces EFI iSCSI Initiator Name Protocol. -// -// This module produces EFI iSCSI Initiator Name Protocol upon EFI TCPv4 P= rotocol -// and EFI DHCPv4 Protocol, to provide the capability to do the transport = for SCSI -// data over TCP/IP. It installs EFI HII Configuration Access Protocol to = provide -// one way to configurate the iSCSI setting. -// -// Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials -// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "Produces EFI iSCS= I Initiator Name Protocol" - -#string STR_MODULE_DESCRIPTION #language en-US "This module produ= ces EFI iSCSI Initiator Name Protocol upon EFI TCPv4 Protocol and EFI DHCPv= 4 Protocol, to provide the capability to do the transport for SCSI data ove= r TCP/IP. It installs EFI HII Configuration Access Protocol to provide a wa= y to configure the iSCSI setting." - diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsi4DxeExtra.uni b/M= deModulePkg/Universal/Network/IScsiDxe/IScsi4DxeExtra.uni deleted file mode 100644 index 5ec75820a605..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsi4DxeExtra.uni +++ /dev/null @@ -1,20 +0,0 @@ -// /** @file -// IScsi4Dxe 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 B= SD 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 IM= PLIED. -// -// **/ - -#string STR_PROPERTIES_MODULE_NAME -#language en-US -"iSCSI DXE Driver" - - diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.h b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiCHAP.h deleted file mode 100644 index 14a5658f754b..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiCHAP.h +++ /dev/null @@ -1,106 +0,0 @@ -/** @file - The header file of CHAP configuration. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_CHAP_H_ -#define _ISCSI_CHAP_H_ - -#define ISCSI_AUTH_METHOD_CHAP "CHAP" - -#define ISCSI_KEY_CHAP_ALGORITHM "CHAP_A" -#define ISCSI_KEY_CHAP_IDENTIFIER "CHAP_I" -#define ISCSI_KEY_CHAP_CHALLENGE "CHAP_C" -#define ISCSI_KEY_CHAP_NAME "CHAP_N" -#define ISCSI_KEY_CHAP_RESPONSE "CHAP_R" - -#define ISCSI_CHAP_ALGORITHM_MD5 5 - -#define ISCSI_CHAP_AUTH_MAX_LEN 1024 -/// -/// MD5_HASHSIZE -/// -#define ISCSI_CHAP_RSP_LEN 16 - -#define ISCSI_CHAP_INITIAL 0 -#define ISCSI_CHAP_STEP_ONE 1 -#define ISCSI_CHAP_STEP_TWO 2 -#define ISCSI_CHAP_STEP_THREE 3 -#define ISCSI_CHAP_STEP_FOUR 4 - -#pragma pack(1) - -typedef struct _ISCSI_CHAP_AUTH_CONFIG_NVDATA { - UINT8 CHAPType; - CHAR8 CHAPName[ISCSI_CHAP_NAME_STORAGE]; - CHAR8 CHAPSecret[ISCSI_CHAP_SECRET_STORAGE]; - CHAR8 ReverseCHAPName[ISCSI_CHAP_NAME_STORAGE]; - CHAR8 ReverseCHAPSecret[ISCSI_CHAP_SECRET_STORAGE]; -} ISCSI_CHAP_AUTH_CONFIG_NVDATA; - -#pragma pack() - -/// -/// ISCSI CHAP Authentication Data -/// -typedef struct _ISCSI_CHAP_AUTH_DATA { - ISCSI_CHAP_AUTH_CONFIG_NVDATA AuthConfig; - UINT32 InIdentifier; - UINT8 InChallenge[ISCSI_CHAP_AUTH_MAX_LEN]; - UINT32 InChallengeLength; - // - // Calculated CHAP Response (CHAP_R) value - // - UINT8 CHAPResponse[ISCSI_CHAP_RSP_LEN]; - - // - // Auth-data to be sent out for mutual authentication - // - UINT32 OutIdentifier; - UINT8 OutChallenge[ISCSI_CHAP_AUTH_MAX_LEN]; - UINT32 OutChallengeLength; -} ISCSI_CHAP_AUTH_DATA; - -/** - This function checks the received iSCSI Login Response during the securi= ty - negotiation stage. - - @param[in] Conn The iSCSI connection. - - @retval EFI_SUCCESS The Login Response passed the CHAP validati= on. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_PROTOCOL_ERROR Some kind of protocol error happend. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiCHAPOnRspReceived ( - IN ISCSI_CONNECTION *Conn - ); -/** - This function fills the CHAP authentication information into the login P= DU - during the security negotiation stage in the iSCSI connection login. - - @param[in] Conn The iSCSI connection. - @param[in, out] Pdu The PDU to send out. - - @retval EFI_SUCCESS All check passed and the phase-related CHAP - authentication info is filled into the iSCS= I PDU. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_PROTOCOL_ERROR Some kind of protocol error happend. -**/ -EFI_STATUS -IScsiCHAPToSendReq ( - IN ISCSI_CONNECTION *Conn, - IN OUT NET_BUF *Pdu - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiCommon.h b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiCommon.h deleted file mode 100644 index 650c68d53bab..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiCommon.h +++ /dev/null @@ -1,22 +0,0 @@ -/** @file - The common header file of Iscsi. - -Copyright (c) 2004 - 2008, 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_COMMON_H_ -#define _ISCSI_COMMON_H_ - -typedef struct _ISCSI_SESSION ISCSI_SESSION; -typedef struct _ISCSI_CONNECTION ISCSI_CONNECTION; -typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA; - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiConfig.h deleted file mode 100644 index c3d07f6f4859..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h +++ /dev/null @@ -1,166 +0,0 @@ -/** @file - The header file of IScsiConfig.c. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_CONFIG_H_ -#define _ISCSI_CONFIG_H_ - -#include -#include -#include -#include -#include -#include -#include - -extern UINT8 IScsiConfigDxeBin[]; -extern UINT8 IScsi4DxeStrings[]; - -#define ISCSI_INITATOR_NAME_VAR_NAME L"I_NAME" - -#define ISCSI_CONFIG_VAR_ATTR (EFI_VARIABLE_BOOTSERVICE_ACCE= SS | EFI_VARIABLE_NON_VOLATILE) - -#define ISCSI_FORM_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('I', 'f', 'c', '= i') - - - -/** - If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is= clear, - then this macro return a pointer to a data structure ISCSI_FORM_CALLBACK= _INFO. - - If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is= set, - The Signature field of the data structure ISCSI_FORM_CALLBACK_INFO - is compared to TestSignature. If the signatures match, then a pointer - to the pointer to a data structure ISCSI_FORM_CALLBACK_INFO is returned. - If the signatures do not match, then DebugAssert() is called with a desc= ription - of "CR has a bad signature" and Callback is returned. - - If the data type ISCSI_FORM_CALLBACK_INFO_SIGNATURE does not contain the= field - specified by Callback, then the module will not compile. - - If ISCSI_FORM_CALLBACK_INFO_SIGNATURE does not contain a field called Si= gnature, - then the module will not compile. - - @param Callback Pointer to the specified field within the data - structure ISCSI_FORM_CALLBACK_INFO. - @return A pointer to the pointer to a data structure ISCSI_FORM_CALLBAC= K_INFO. - @retval Others Some unexpected error happened. -**/ - -#define ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK(Callback) \ - CR ( \ - Callback, \ - ISCSI_FORM_CALLBACK_INFO, \ - ConfigAccess, \ - ISCSI_FORM_CALLBACK_INFO_SIGNATURE \ - ) - -#pragma pack(1) - -typedef struct _ISCSI_MAC_INFO { - EFI_MAC_ADDRESS Mac; - UINT8 Len; - UINT16 VlanId; -} ISCSI_MAC_INFO; - -typedef struct _ISCSI_DEVICE_LIST { - UINT8 NumDevice; - ISCSI_MAC_INFO MacInfo[1]; -} ISCSI_DEVICE_LIST; - -#pragma pack() - -typedef struct _ISCSI_CONFIG_FORM_ENTRY { - LIST_ENTRY Link; - EFI_HANDLE Controller; - CHAR16 MacString[95]; - EFI_STRING_ID PortTitleToken; - EFI_STRING_ID PortTitleHelpToken; - - ISCSI_SESSION_CONFIG_NVDATA SessionConfigData; - ISCSI_CHAP_AUTH_CONFIG_NVDATA AuthConfigData; -} ISCSI_CONFIG_FORM_ENTRY; - -typedef struct _ISCSI_FORM_CALLBACK_INFO { - UINTN Signature; - EFI_HANDLE DriverHandle; - EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess; - EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_CONFIG_ROUTING_PROTOCOL *ConfigRouting; - UINT16 *KeyList; - VOID *FormBuffer; - EFI_HII_HANDLE RegisteredHandle; - ISCSI_CONFIG_FORM_ENTRY *Current; -} ISCSI_FORM_CALLBACK_INFO; - -#pragma pack(1) - -/// -/// HII specific Vendor Device Path definition. -/// -typedef struct { - VENDOR_DEVICE_PATH VendorDevicePath; - EFI_DEVICE_PATH_PROTOCOL End; -} HII_VENDOR_DEVICE_PATH; - -#pragma pack() - -/** - Updates the iSCSI configuration form to add/delete an entry for the iSCS= I - device specified by the Controller. - - @param[in] DriverBindingHandle The driverbinding handle. - @param[in] Controller The controller handle of the iSCSI devic= e. - @param[in] AddForm Whether to add or delete a form entry. - - @retval EFI_SUCCESS The iSCSI configuration form is updated. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiConfigUpdateForm ( - IN EFI_HANDLE DriverBindingHandle, - IN EFI_HANDLE Controller, - IN BOOLEAN AddForm - ); - -/** - Initialize the iSCSI configuration form. - - @param[in] DriverBindingHandle The iSCSI driverbinding handle. - - @retval EFI_SUCCESS The iSCSI configuration form is initial= ized. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiConfigFormInit ( - VOID - ); - -/** - Unload the iSCSI configuration form, this includes: delete all the iSCSI - device configuration entries, uninstall the form callback protocol and - free the resources used. - - @param[in] DriverBindingHandle The iSCSI driverbinding handle. - - @retval EFI_SUCCESS The iSCSI configuration form is unloaded= . - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. -**/ -EFI_STATUS -IScsiConfigFormUnload ( - IN EFI_HANDLE DriverBindingHandle - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxe.vfr b/M= deModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxe.vfr deleted file mode 100644 index 9e28d81fb40d..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxe.vfr +++ /dev/null @@ -1,219 +0,0 @@ -/** @file - Vfr file for iSCSI config. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - - -#include "IScsiConfigNVDataStruc.h" -#define EFI_NETWORK_DEVICE_CLASS 0x04 - -formset - guid =3D IP4_ISCSI_CONFIG_GUID, - title =3D STRING_TOKEN(STR_ISCSI_CONFIG_FORM_TITLE), - help =3D STRING_TOKEN(STR_ISCSI_CONFIG_FORM_HELP), - - varstore ISCSI_CONFIG_IFR_NVDATA, - name =3D ISCSI_CONFIG_IFR_NVDATA, - guid =3D IP4_ISCSI_CONFIG_GUID; - form formid =3D FORMID_MAIN_FORM, - title =3D STRING_TOKEN(STR_ISCSI_MAIN_FORM_TITLE); - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.InitiatorName, - prompt =3D STRING_TOKEN(STR_ISCSI_CONFIG_INIT_NAME), - help =3D STRING_TOKEN(STR_ISCSI_CONFIG_INIT_NAME_HELP), - flags =3D INTERACTIVE, - key =3D KEY_INITIATOR_NAME, - minsize =3D ISCSI_NAME_IFR_MIN_SIZE, - maxsize =3D ISCSI_NAME_IFR_MAX_SIZE, - endstring; - - label DEVICE_ENTRY_LABEL; - label LABEL_END; - - endform; - - form formid =3D FORMID_DEVICE_FORM, - title =3D STRING_TOKEN(STR_ISCSI_DEVICE_FORM_TITLE); - - checkbox varid =3D ISCSI_CONFIG_IFR_NVDATA.Enabled, - prompt =3D STRING_TOKEN(STR_ISCSI_DEVICE_ENABLE), - help =3D STRING_TOKEN(STR_NULL), - flags =3D 0, - endcheckbox; - - checkbox varid =3D ISCSI_CONFIG_IFR_NVDATA.InitiatorInfoFromDhcp, - prompt =3D STRING_TOKEN(STR_ISCSI_ENABLE_DHCP), - help =3D STRING_TOKEN(STR_ISCSI_ENABLE_DHCP), - flags =3D INTERACTIVE, - key =3D KEY_DHCP_ENABLE, - endcheckbox; - - suppressif ideqval ISCSI_CONFIG_IFR_NVDATA.InitiatorInfoFromDhcp =3D= =3D 0x01; - string varid =3D ISCSI_CONFIG_IFR_NVDATA.LocalIp, - prompt =3D STRING_TOKEN(STR_ISCSI_LOCAL_IP_ADDRESS), - help =3D STRING_TOKEN(STR_ISCSI_IP_ADDRESS_HELP), - flags =3D INTERACTIVE, - key =3D KEY_LOCAL_IP, - minsize =3D IP_MIN_SIZE, - maxsize =3D IP_MAX_SIZE, - endstring; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.SubnetMask, - prompt =3D STRING_TOKEN(STR_ISCSI_LOCAL_MASK), - help =3D STRING_TOKEN(STR_ISCSI_IP_ADDRESS_HELP), - flags =3D INTERACTIVE, - key =3D KEY_SUBNET_MASK, - minsize =3D IP_MIN_SIZE, - maxsize =3D IP_MAX_SIZE, - endstring; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.Gateway, - prompt =3D STRING_TOKEN(STR_ISCSI_LOCAL_GATEWAY), - help =3D STRING_TOKEN(STR_ISCSI_IP_ADDRESS_HELP), - flags =3D INTERACTIVE, - key =3D KEY_GATE_WAY, - minsize =3D IP_MIN_SIZE, - maxsize =3D IP_MAX_SIZE, - endstring; - endif; - - subtitle text =3D STRING_TOKEN(STR_NULL); - - suppressif ideqval ISCSI_CONFIG_IFR_NVDATA.InitiatorInfoFromDhcp =3D= =3D 0x00; - checkbox varid =3D ISCSI_CONFIG_IFR_NVDATA.TargetInfoFromDhcp, - prompt =3D STRING_TOKEN(STR_ISCSI_ENABLE_DHCP_ON_TARGET), - help =3D STRING_TOKEN(STR_ISCSI_ENABLE_DHCP_ON_TARGET), - flags =3D 0, - endcheckbox; - endif; - - suppressif ideqval ISCSI_CONFIG_IFR_NVDATA.TargetInfoFromDhcp =3D=3D 0= x01; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.TargetName, - prompt =3D STRING_TOKEN(STR_ISCSI_TARGET_NAME), - help =3D STRING_TOKEN(STR_ISCSI_TARGET_NAME), - flags =3D INTERACTIVE, - key =3D KEY_TARGET_NAME, - minsize =3D ISCSI_NAME_IFR_MIN_SIZE, - maxsize =3D ISCSI_NAME_IFR_MAX_SIZE, - endstring; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.TargetIp, - prompt =3D STRING_TOKEN(STR_ISCSI_TARGET_IP_ADDRESS), - help =3D STRING_TOKEN(STR_ISCSI_IP_ADDRESS_HELP), - flags =3D INTERACTIVE, - key =3D KEY_TARGET_IP, - minsize =3D IP_MIN_SIZE, - maxsize =3D IP_MAX_SIZE, - endstring; - - numeric varid =3D ISCSI_CONFIG_IFR_NVDATA.TargetPort, - prompt =3D STRING_TOKEN(STR_ISCSI_TARGET_PORT), - help =3D STRING_TOKEN(STR_ISCSI_TARGET_PORT), - flags =3D 0, - minimum =3D TARGET_PORT_MIN_NUM, - maximum =3D TARGET_PORT_MAX_NUM, - step =3D 0, - endnumeric; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.BootLun, - prompt =3D STRING_TOKEN(STR_ISCSI_BOOT_LUN), - help =3D STRING_TOKEN(STR_ISCSI_BOOT_LUN_HELP), - flags =3D INTERACTIVE, - key =3D KEY_BOOT_LUN, - minsize =3D LUN_MIN_SIZE, - maxsize =3D LUN_MAX_SIZE, - endstring; - endif; - - subtitle text =3D STRING_TOKEN(STR_NULL); - - oneof varid =3D ISCSI_CONFIG_IFR_NVDATA.CHAPType, - prompt =3D STRING_TOKEN(STR_CHAP_TYPE_PROMPT), - help =3D STRING_TOKEN(STR_CHAP_TYPE_HELP), - option text =3D STRING_TOKEN(STR_CHAP_TYPE_NONE), value =3D IS= CSI_CHAP_NONE, flags =3D DEFAULT; - option text =3D STRING_TOKEN(STR_CHAP_TYPE_UNI), value =3D IS= CSI_CHAP_UNI, flags =3D 0; - option text =3D STRING_TOKEN(STR_CHAP_TYPE_MUTUAL), value =3D IS= CSI_CHAP_MUTUAL, flags =3D 0; - endoneof; - - suppressif ideqval ISCSI_CONFIG_IFR_NVDATA.CHAPType =3D=3D ISCSI_CHAP_= NONE; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.CHAPName, - prompt =3D STRING_TOKEN(STR_ISCSI_CHAP_NAME), - help =3D STRING_TOKEN(STR_ISCSI_CHAP_NAME), - flags =3D INTERACTIVE, - key =3D KEY_CHAP_NAME, - minsize =3D 0, - maxsize =3D ISCSI_CHAP_NAME_MAX_LEN, - endstring; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.CHAPSecret, - prompt =3D STRING_TOKEN(STR_ISCSI_CHAP_SECRET), - help =3D STRING_TOKEN(STR_ISCSI_CHAP_SECRET_HELP), - flags =3D INTERACTIVE, - key =3D KEY_CHAP_SECRET, - minsize =3D ISCSI_CHAP_SECRET_MIN_LEN, - maxsize =3D ISCSI_CHAP_SECRET_MAX_LEN, - endstring; - - endif; - - suppressif NOT ideqval ISCSI_CONFIG_IFR_NVDATA.CHAPType =3D=3D ISCSI_C= HAP_MUTUAL; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.ReverseCHAPName, - prompt =3D STRING_TOKEN(STR_ISCSI_REVERSE_CHAP_NAME), - help =3D STRING_TOKEN(STR_ISCSI_REVERSE_CHAP_NAME), - flags =3D INTERACTIVE, - key =3D KEY_REVERSE_CHAP_NAME, - minsize =3D 0, - maxsize =3D ISCSI_CHAP_NAME_MAX_LEN, - endstring; - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.ReverseCHAPSecret, - prompt =3D STRING_TOKEN(STR_ISCSI_REVERSE_CHAP_SECRET), - help =3D STRING_TOKEN(STR_ISCSI_CHAP_SECRET_HELP), - flags =3D INTERACTIVE, - key =3D KEY_REVERSE_CHAP_SECRET, - minsize =3D ISCSI_CHAP_SECRET_MIN_LEN, - maxsize =3D ISCSI_CHAP_SECRET_MAX_LEN, - endstring; - - endif; - - subtitle text =3D STRING_TOKEN(STR_NULL); - - string varid =3D ISCSI_CONFIG_IFR_NVDATA.IsId, - prompt =3D STRING_TOKEN(STR_ISCSI_CONFIG_ISID), - help =3D STRING_TOKEN(STR_ISCSI_CONFIG_ISID_HELP), - flags =3D INTERACTIVE, - key =3D KEY_CONFIG_ISID, - minsize =3D ISID_CONFIGURABLE_MIN_LEN, - maxsize =3D ISID_CONFIGURABLE_MAX_LEN, - endstring; - - subtitle text =3D STRING_TOKEN(STR_NULL); - - text - help =3D STRING_TOKEN (STR_SAVE_CHANGES), - text =3D STRING_TOKEN (STR_SAVE_CHANGES), - flags =3D INTERACTIVE, - key =3D KEY_SAVE_CHANGES; - - goto FORMID_MAIN_FORM, - prompt =3D STRING_TOKEN (STR_RETURN_MAIN_FORM), - help =3D STRING_TOKEN (STR_RETURN_MAIN_FORM), - flags =3D 0; - - endform; - -endformset; - diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxeStrings.= uni b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxeStrings.uni deleted file mode 100644 index 729c74ebfc1b..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigDxeStrings.uni +++ /dev/null @@ -1,62 +0,0 @@ -// *++ -// -// Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
-// This program and the accompanying materials -// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. -// -// Module Name: -// -// IScsiConfigStrings.uni -// -// Abstract: -// -// String definitions for iSCSI configuration. -// -// Revision History: -// -// --*/ - - -/=3D# - -#langdef en-US "English" - -#string STR_ISCSI_CONFIG_FORM_TITLE #language en-US "iSCSI Configurati= on" -#string STR_ISCSI_CONFIG_FORM_HELP #language en-US "Configure the iSC= SI parameters." -#string STR_ISCSI_MAIN_FORM_TITLE #language en-US "iSCSI Configurati= on" -#string STR_ISCSI_CONFIG_INIT_NAME #language en-US "iSCSI Initiator N= ame" -#string STR_ISCSI_CONFIG_INIT_NAME_HELP #language en-US "The worldwide uni= que name of the initiator. Only iqn. format is accepted." -#string STR_ISCSI_DEVICE_FORM_TITLE #language en-US "" -#string STR_ISCSI_DEVICE_ENABLE #language en-US "Enable iSCSI" -#string STR_ISCSI_LOCAL_IP_ADDRESS #language en-US " Initiator IP Ad= dress" -#string STR_ISCSI_LOCAL_MASK #language en-US " Initiator Subne= t Mask" -#string STR_ISCSI_LOCAL_GATEWAY #language en-US " Gateway" -#string STR_ISCSI_IP_ADDRESS_HELP #language en-US "Enter IP address = in dotted-decimal notation." -#string STR_ISCSI_TARGET_NAME #language en-US " Target Name" -#string STR_ISCSI_TARGET_IP_ADDRESS #language en-US " Target IP Addre= ss" -#string STR_ISCSI_TARGET_PORT #language en-US " Target Port" -#string STR_ISCSI_BOOT_LUN #language en-US " Boot LUN" -#string STR_ISCSI_BOOT_LUN_HELP #language en-US "Hexadecimal repre= sentation of the LU number. Examples are: 4752-3A4F-6b7e-2F99, 6734-9-156f-= 127, 4186-9" -#string STR_ISCSI_ENABLE_DHCP #language en-US "Enable DHCP" -#string STR_ISCSI_ENABLE_DHCP_ON_TARGET #language en-US "Get target info v= ia DHCP" -#string STR_CHAP_TYPE_PROMPT #language en-US "CHAP Type" -#string STR_CHAP_TYPE_HELP #language en-US "None, One way CHA= P or mutual CHAP" -#string STR_CHAP_TYPE_NONE #language en-US "None" -#string STR_CHAP_TYPE_UNI #language en-US "One way" -#string STR_CHAP_TYPE_MUTUAL #language en-US "Mutual" -#string STR_ISCSI_CHAP_NAME #language en-US " CHAP Name" -#string STR_ISCSI_CHAP_SECRET #language en-US " CHAP Secret" -#string STR_ISCSI_CHAP_SECRET_HELP #language en-US "The minimum lengt= h is 12 bytes and the maximum length is 16 bytes." -#string STR_ISCSI_REVERSE_CHAP_NAME #language en-US " Reverse CHAP Na= me" -#string STR_ISCSI_REVERSE_CHAP_SECRET #language en-US " Reverse CHAP Se= cret" -#string STR_ISCSI_CONFIG_ISID #language en-US "ISID" -#string STR_ISCSI_CONFIG_ISID_HELP #language en-US "OUI-format ISID i= n 6 bytes, default value are derived from MAC address. Only last 3 bytes ar= e configurable. Example: update 0ABBCCDDEEFF to 0ABBCCF07901 by input F0790= 1." -#string STR_RETURN_MAIN_FORM #language en-US "Back to Previous = Page" -#string STR_SAVE_CHANGES #language en-US "Save Changes" -#string STR_NULL #language en-US "" - diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigNVDataStruc= .h b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigNVDataStruc.h deleted file mode 100644 index 7c2e4e65fa8e..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfigNVDataStruc.h +++ /dev/null @@ -1,109 +0,0 @@ -/** @file - Define NVData structures used by the iSCSI configuration component - -Copyright (c) 2004 - 2011, 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_NVDATASTRUC_H_ -#define _ISCSI_NVDATASTRUC_H_ - -#include - -#define VAR_EQ_TEST_NAME 0x100 - -#define FORMID_MAIN_FORM 1 -#define FORMID_DEVICE_FORM 2 - -#define ISCSI_NAME_MAX_SIZE 224 - -// -// Vfr has a limit on the size, it's 255 bytes. -// -#define ISCSI_NAME_IFR_MIN_SIZE 4 -#define ISCSI_NAME_IFR_MAX_SIZE 223 - -#define IP_MIN_SIZE 7 -#define IP_MAX_SIZE 15 -#define IP4_STR_MAX_SIZE 16 - -#define LUN_MIN_SIZE 1 -#define LUN_MAX_SIZE 20 - -#define ISCSI_CHAP_NONE 0 -#define ISCSI_CHAP_UNI 1 -#define ISCSI_CHAP_MUTUAL 2 - -#define TARGET_PORT_MIN_NUM 0 -#define TARGET_PORT_MAX_NUM 65535 - -#define DEVICE_ENTRY_LABEL 0x1234 -#define LABEL_END 0xffff - -#define KEY_INITIATOR_NAME 0x101 -#define KEY_DHCP_ENABLE 0x102 -#define KEY_LOCAL_IP 0x103 -#define KEY_SUBNET_MASK 0x104 -#define KEY_GATE_WAY 0x105 -#define KEY_TARGET_IP 0x106 -#define KEY_CHAP_NAME 0x107 -#define KEY_CHAP_SECRET 0x108 -#define KEY_REVERSE_CHAP_NAME 0x109 -#define KEY_REVERSE_CHAP_SECRET 0x10a -#define KEY_SAVE_CHANGES 0x10b -#define KEY_TARGET_NAME 0x10c -#define KEY_BOOT_LUN 0x10d -#define KEY_CONFIG_ISID 0x10e - -#define KEY_DEVICE_ENTRY_BASE 0x1000 - -#define ISCSI_LUN_STR_MAX_LEN 21 -#define ISCSI_CHAP_SECRET_MIN_LEN 12 -#define ISCSI_CHAP_SECRET_MAX_LEN 16 -// -// ISCSI_CHAP_SECRET_STORAGE =3D ISCSI_CHAP_SECRET_MAX_LEN + sizeof (NULL= -Terminator) -// -#define ISCSI_CHAP_SECRET_STORAGE 17 - -#define ISCSI_CHAP_NAME_MAX_LEN 126 -#define ISCSI_CHAP_NAME_STORAGE 127 - -#define ISID_CONFIGURABLE_MIN_LEN 6 -#define ISID_CONFIGURABLE_MAX_LEN 12 -#define ISID_CONFIGURABLE_STORAGE 13 - -#pragma pack(1) -typedef struct { - CHAR16 InitiatorName[ISCSI_NAME_MAX_SIZE]; - - UINT8 Enabled; - - UINT8 InitiatorInfoFromDhcp; - CHAR16 LocalIp[IP4_STR_MAX_SIZE]; - CHAR16 SubnetMask[IP4_STR_MAX_SIZE]; - CHAR16 Gateway[IP4_STR_MAX_SIZE]; - - CHAR16 TargetName[ISCSI_NAME_MAX_SIZE]; - CHAR16 TargetIp[IP4_STR_MAX_SIZE]; - UINT16 TargetPort; - CHAR16 BootLun[ISCSI_LUN_STR_MAX_LEN]; - UINT8 TargetInfoFromDhcp; - - UINT8 CHAPType; - CHAR16 CHAPName[ISCSI_CHAP_NAME_STORAGE]; - CHAR16 CHAPSecret[ISCSI_CHAP_SECRET_STORAGE]; - CHAR16 ReverseCHAPName[ISCSI_CHAP_NAME_STORAGE]; - CHAR16 ReverseCHAPSecret[ISCSI_CHAP_SECRET_STORAGE]; - - CHAR16 IsId[ISID_CONFIGURABLE_STORAGE]; -} ISCSI_CONFIG_IFR_NVDATA; -#pragma pack() - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDhcp.h b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiDhcp.h deleted file mode 100644 index 4c4dcaa8f68d..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDhcp.h +++ /dev/null @@ -1,55 +0,0 @@ -/** @file - The header file of IScsiDhcp. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_DHCP_H_ -#define _ISCSI_DHCP_H_ - -#include - -#define ISCSI_ROOT_PATH_ID "iscsi:" -#define ISCSI_ROOT_PATH_FIELD_DELIMITER ':' - -#define RP_FIELD_IDX_SERVERNAME 0 -#define RP_FIELD_IDX_PROTOCOL 1 -#define RP_FIELD_IDX_PORT 2 -#define RP_FIELD_IDX_LUN 3 -#define RP_FIELD_IDX_TARGETNAME 4 -#define RP_FIELD_IDX_MAX 5 - -typedef struct _ISCSI_ROOT_PATH_FIELD { - CHAR8 *Str; - UINT8 Len; -} ISCSI_ROOT_PATH_FIELD; - -/** - Parse the DHCP ACK to get the address configuration and DNS information. - - @param[in] Image The handle of the driver image. - @param[in] Controller The handle of the controller; - @param[in, out] ConfigData The session configuration data. - - @retval EFI_SUCCESS The DNS information is got from the DHCP A= CK. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NO_MEDIA There was a media error. - @retval Others Other errors as indicated. - -**/ -EFI_STATUS -IScsiDoDhcp ( - IN EFI_HANDLE Image, - IN EFI_HANDLE Controller, - IN OUT ISCSI_SESSION_CONFIG_DATA *ConfigData - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.h b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiDriver.h deleted file mode 100644 index d6a619f00fc0..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.h +++ /dev/null @@ -1,140 +0,0 @@ -/** @file - The header file of IScsiDriver.c. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_DRIVER_H_ -#define _ISCSI_DRIVER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ISCSI_INITIATOR_NAME_VAR_NAME L"I_NAME" - -typedef struct _ISCSI_PRIVATE_PROTOCOL { - UINT32 Reserved; -} ISCSI_PRIVATE_PROTOCOL; - -// -// EFI Driver Binding Protocol for iSCSI driver. -// - -/** - Tests to see if this driver supports a given controller. If a child devi= ce is provided, - it further tests to see if this driver supports creating a handle for th= e specified child device. - - @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. - @param[in] ControllerHandle The handle of the controller to test. T= his handle - must support a protocol interface that = supplies - an I/O abstraction to the driver. - @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. - This parameter is ignored by device dri= vers, and is optional for bus drivers. - - - @retval EFI_SUCCESS The device specified by ControllerHandl= e and - RemainingDevicePath is supported by the= driver specified by This. - @retval EFI_ALREADY_STARTED The device specified by ControllerHandl= e and - RemainingDevicePath is already being ma= naged by the driver - specified by This. - @retval EFI_ACCESS_DENIED The device specified by ControllerHandl= e and - RemainingDevicePath is already being ma= naged by a different - driver or an application that requires = exclusive acces. - Currently not implemented. - @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e and - RemainingDevicePath is not supported by= the driver specified by This. -**/ -EFI_STATUS -EFIAPI -IScsiDriverBindingSupported ( - 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 service ConnectController(). As a result, much= of - the error checking on the parameters to Start() has been moved into this - common boot service. It is legal to call Start() from other locations, - but the following calling restrictions must be followed or the system be= havior 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 na= turally aligned - EFI_DEVICE_PATH_PROTOCOL. - 3. Prior to calling Start(), the Supported() function for the driver spe= cified by This must - have been called with the same calling parameters, and Supported() mu= st have returned EFI_SUCCESS. - - @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. - @param[in] ControllerHandle The handle of the controller to start. = This handle - must support a protocol interface that = supplies - an I/O abstraction to the driver. - @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. - This parameter is ignored by device dri= vers, and is optional for bus drivers. - - @retval EFI_SUCCESS The device was started. - @retval EFI_DEVICE_ERROR The device could not be started due to = a device error. - Currently not implemented. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due = to a lack of resources. - @retval Others The driver failded to start the device. -**/ -EFI_STATUS -EFIAPI -IScsiDriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL - ); - -/** - Stop this driver on ControllerHandle. - - Release the control of this controller and remove the IScsi functions. T= he Stop() - function is designed to be invoked from the EFI boot service DisconnectC= ontroller(). - 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 loc= ations, - but the following calling restrictions must be followed or the system be= havior will not be deterministic. - 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previo= us 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 created = in this driver's - Start() function, and the Start() function must have called OpenProto= col() on - ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONT= ROLLER. - - @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOC= OL instance. - @param[in] ControllerHandle A handle to the device being stopped. The = handle must - support a bus specific I/O protocol for th= e driver - to use to stop the device. - @param[in] NumberOfChildren The number of child device handles in Chil= dHandleBuffer.Not used. - @param[in] ChildHandleBuffer An array of child handles to be freed. May= be NULL - if NumberOfChildren is 0.Not used. - - @retval EFI_SUCCESS The device was stopped. - @retval EFI_DEVICE_ERROR The device could not be stopped due to a d= evice error. -**/ -EFI_STATUS -EFIAPI -IScsiDriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer OPTIONAL - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf b/MdeModu= lePkg/Universal/Network/IScsiDxe/IScsiDxe.inf deleted file mode 100644 index 48729e3029f7..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf +++ /dev/null @@ -1,134 +0,0 @@ -## @file -# This module produces EFI iSCSI Initiator Name Protocol. -# -# This module produces EFI iSCSI Initiator Name Protocol upon EFI TCPv4 P= rotocol -# and EFI DHCPv4 Protocol, to provide the capability to do the transport = for SCSI -# data over TCP/IP. It installs EFI HII Configuration Access Protocol to = provide -# one way to configurate the iSCSI setting. This driver only supports IPv= 4 network -# stack. -# -# Notes: -# 1) This driver can't co-work with the IScsiDxe driver in NetworkPkg. -# 2) This driver might have some issues that have been fixed in the IScsi= Dxe driver -# in NetworkPkg. -# 3) This driver supports fewer features than the IScsiDxe driver in Netw= orkPkg -# (e.g. IPv6, Dns support for target URL configuration, iSCSI keyword = support). -# 4) IScsiDxe driver in NetworkPkg is recommended for use instead of this= one even -# though both of them can be used. -# -# Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D IScsi4Dxe - MODULE_UNI_FILE =3D IScsi4Dxe.uni - FILE_GUID =3D 4579B72D-7EC4-4dd4-8486-083C86B182A7 - MODULE_TYPE =3D UEFI_DRIVER - VERSION_STRING =3D 1.0 - ENTRY_POINT =3D IScsiDriverEntryPoint - UNLOAD_IMAGE =3D EfiIScsiUnload - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# -# DRIVER_BINDING =3D gIScsiDriverBinding -# COMPONENT_NAME =3D gIScsiComponentName -# COMPONENT_NAME2 =3D gIScsiComponentName2 -# - -[Sources] - IScsiTcp4Io.h - IScsiProto.h - IScsiMisc.h - IScsiIbft.h - IScsiExtScsiPassThru.h - IScsiDriver.h - IScsiDhcp.h - IScsiCommon.h - IScsiCHAP.h - IScsiInitiatorName.h - ComponentName.h - Md5.h - IScsiTcp4Io.c - IScsiProto.c - IScsiMisc.c - IScsiInitiatorName.c - IScsiIbft.c - IScsiExtScsiPassThru.c - IScsiDriver.c - IScsiDhcp.c - IScsiCHAP.c - ComponentName.c - Md5.c - IScsiConfigDxeStrings.uni - IScsiConfigDxe.vfr - IScsiConfig.c - IScsiConfig.h - IScsiImpl.h - IScsiConfigNVDataStruc.h - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - -[LibraryClasses] - UefiDriverEntryPoint - UefiLib - BaseLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - BaseMemoryLib - MemoryAllocationLib - DevicePathLib - DebugLib - PrintLib - HiiLib - NetLib - -[Protocols] - ## PRODUCES - ## UNDEFINED # Variable - gEfiIScsiInitiatorNameProtocolGuid - gEfiExtScsiPassThruProtocolGuid ## BY_START - gEfiTcp4ProtocolGuid ## TO_START - gEfiTcp4ServiceBindingProtocolGuid ## TO_START - gEfiDhcp4ProtocolGuid ## TO_START - gEfiDhcp4ServiceBindingProtocolGuid ## TO_START - ## TO_START - ## PRODUCES - gEfiDevicePathProtocolGuid - gEfiHiiConfigAccessProtocolGuid ## PRODUCES - gEfiHiiDatabaseProtocolGuid ## CONSUMES - gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES - gEfiAcpiTableProtocolGuid ## SOMETIMES_CONSUMES - -[Guids] - gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES ## E= vent - gEfiIfrTianoGuid ## SOMETIMES_PRODUCES ## U= NDEFINED - gEfiAcpiTableGuid ## SOMETIMES_CONSUMES ## S= ystemTable - gEfiAcpi10TableGuid ## SOMETIMES_CONSUMES ## S= ystemTable - ## SOMETIMES_PRODUCES ## Variable:L"iSCSIDeviceList" - ## SOMETIMES_CONSUMES ## Variable:L"iSCSIDeviceList" - ## SOMETIMES_CONSUMES ## UNDEFINED # HiiIsConfigHdrMatch mVendorStorag= eName - ## SOMETIMES_PRODUCES ## UNDEFINED # HiiConstructConfigHdr mVendorStorag= eName - ## SOMETIMES_PRODUCES ## UNDEFINED # HiiGetBrowserData mVendorStorag= eName - ## SOMETIMES_CONSUMES ## UNDEFINED # HiiSetBrowserData mVendorStorag= eName - ## SOMETIMES_CONSUMES ## HII - gIp4IScsiConfigGuid - ## SOMETIMES_PRODUCES ## Variable - ## SOMETIMES_CONSUMES ## Variable - gIScsiCHAPAuthInfoGuid - -[UserExtensions.TianoCore."ExtraFiles"] - IScsi4DxeExtra.uni diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.h= b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.h deleted file mode 100644 index e635e47b9292..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.h +++ /dev/null @@ -1,22 +0,0 @@ -/** @file - The header file of IScsiExtScsiPassThru.c. - -Copyright (c) 2004 - 2008, 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_EXT_SCSI_PASS_THRU_H_ -#define _ISCSI_EXT_SCSI_PASS_THRU_H_ - -#include - -extern EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTempl= ate; - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.h b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiIbft.h deleted file mode 100644 index 4f3828db63c6..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.h +++ /dev/null @@ -1,38 +0,0 @@ -/** @file - Some extra definitions for iBFT. - -Copyright (c) 2004 - 2009, 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_IBFT_H_ -#define _ISCSI_IBFT_H_ - -#include -#include -#include -#include - -#define IBFT_TABLE_VAR_NAME L"iBFT" -#define IBFT_MAX_SIZE 4096 -#define IBFT_HEAP_OFFSET 2048 - -#define IBFT_ROUNDUP(size) NET_ROUNDUP ((size), EFI_ACPI_ISCSI_BOOT_FIRMW= ARE_TABLE_STRUCTURE_ALIGNMENT) - -/** - Publish and remove the iSCSI Boot Firmware Table according to the iSCSI - session status. -**/ -VOID -IScsiPublishIbft ( - VOID - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiImpl.h b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiImpl.h deleted file mode 100644 index 8a5ee2149eb2..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiImpl.h +++ /dev/null @@ -1,168 +0,0 @@ -/** @file - The header file of IScsiImpl.c. - -Copyright (c) 2004 - 2016, 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_IMPL_H_ -#define _ISCSI_IMPL_H_ - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include "IScsiCommon.h" -#include "IScsiDriver.h" -#include "IScsiInitiatorName.h" -#include "ComponentName.h" -#include "IScsiConfigNVDataStruc.h" -#include "IScsiExtScsiPassThru.h" -#include "IScsiProto.h" -#include "IScsiMisc.h" -#include "IScsiCHAP.h" -#include "IScsiConfig.h" -#include "IScsiDhcp.h" -#include "IScsiTcp4Io.h" -#include "IScsiIbft.h" - - -#define ISCSI_SESSION_SIGNATURE SIGNATURE_32 ('I', 'S', 'S', 'N') - -struct _ISCSI_SESSION { - UINT32 Signature; - - ISCSI_SESSION_CONFIG_DATA ConfigData; - ISCSI_CHAP_AUTH_DATA AuthData; - - CHAR8 InitiatorName[ISCSI_NAME_MAX_SIZE]; - UINTN InitiatorNameLength; - UINT8 State; - - UINT8 Isid[6]; - UINT16 Tsih; - - UINT32 CmdSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - - UINT32 InitiatorTaskTag; - UINT16 NextCid; - - LIST_ENTRY Conns; - UINT32 NumConns; - - LIST_ENTRY TcbList; - - // - // session-wide parameters - // - UINT16 TargetPortalGroupTag; - UINT32 MaxConnections; - BOOLEAN InitialR2T; - BOOLEAN ImmediateData; - UINT32 MaxBurstLength; - UINT32 FirstBurstLength; - UINT32 DefaultTime2Wait; - UINT32 DefaultTime2Retain; - UINT16 MaxOutstandingR2T; - BOOLEAN DataPDUInOrder; - BOOLEAN DataSequenceInOrder; - UINT8 ErrorRecoveryLevel; -}; - -#define ISCSI_CONNECTION_SIGNATURE SIGNATURE_32 ('I', 'S', 'C', 'N') - -struct _ISCSI_CONNECTION { - UINT32 Signature; - LIST_ENTRY Link; - - EFI_EVENT TimeoutEvent; - - ISCSI_SESSION *Session; - - UINT8 State; - UINT8 CurrentStage; - UINT8 NextStage; - - UINT8 CHAPStep; - - BOOLEAN PartialReqSent; - BOOLEAN PartialRspRcvd; - - BOOLEAN TransitInitiated; - - UINT16 Cid; - UINT32 ExpStatSN; - - // - // queues... - // - NET_BUF_QUEUE RspQue; - - TCP4_IO Tcp4Io; - - // - // connection-only parameters - // - UINT32 MaxRecvDataSegmentLength; - ISCSI_DIGEST_TYPE HeaderDigest; - ISCSI_DIGEST_TYPE DataDigest; -}; - -#define ISCSI_DRIVER_DATA_SIGNATURE SIGNATURE_32 ('I', 'S', 'D', 'A') - -#define ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU(PassThru) \ - CR ( \ - PassThru, \ - ISCSI_DRIVER_DATA, \ - IScsiExtScsiPassThru, \ - ISCSI_DRIVER_DATA_SIGNATURE \ - ) -#define ISCSI_DRIVER_DATA_FROM_IDENTIFIER(Identifier) \ - CR ( \ - Identifier, \ - ISCSI_DRIVER_DATA, \ - IScsiIdentifier, \ - ISCSI_DRIVER_DATA_SIGNATURE \ - ) -#define ISCSI_DRIVER_DATA_FROM_SESSION(s) \ - CR ( \ - s, \ - ISCSI_DRIVER_DATA, \ - Session, \ - ISCSI_DRIVER_DATA_SIGNATURE \ - ) - -struct _ISCSI_DRIVER_DATA { - UINT32 Signature; - EFI_HANDLE Image; - EFI_HANDLE Controller; - ISCSI_PRIVATE_PROTOCOL IScsiIdentifier; - EFI_HANDLE ChildHandle; - EFI_EVENT ExitBootServiceEvent; - - EFI_EXT_SCSI_PASS_THRU_PROTOCOL IScsiExtScsiPassThru; - EFI_EXT_SCSI_PASS_THRU_MODE ExtScsiPassThruMode; - EFI_HANDLE ExtScsiPassThruHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - - ISCSI_SESSION Session; -}; - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.h b= /MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.h deleted file mode 100644 index f967fb383095..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiInitiatorName.h +++ /dev/null @@ -1,74 +0,0 @@ -/** @file - The header file for EFI iSCSI Initiator Name Protocol. - -Copyright (c) 2004 - 2008, 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_INITIATOR_NAME_H_ -#define _ISCSI_INITIATOR_NAME_H_ - -#include - -extern EFI_ISCSI_INITIATOR_NAME_PROTOCOL gIScsiInitiatorName; - -// -// EFI iSCSI Initiator Name Protocol for IScsi driver. -// - -/** - Retrieves the current set value of iSCSI Initiator Name. - - @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROT= OCOL instance. - @param[in, out] BufferSize Size of the buffer in bytes pointed to by Bu= ffer / Actual size of the - variable data buffer. - @param[out] Buffer Pointer to the buffer for data to be read. - - @retval EFI_SUCCESS Data was successfully retrieved into the p= rovided buffer and the - BufferSize was sufficient to handle the iS= CSI initiator name. - @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the result. - @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL. - @retval EFI_DEVICE_ERROR The iSCSI initiator name could not be retr= ieved due to a hardware error. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiGetInitiatorName ( - IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ); - -/** - Sets the iSCSI Initiator Name. - - @param[in] This Pointer to the EFI_ISCSI_INITIATOR_NAME_PROT= OCOL instance. - @param[in, out] BufferSize Size of the buffer in bytes pointed to by Bu= ffer. - @param[in] Buffer Pointer to the buffer for data to be written= . - - @retval EFI_SUCCESS Data was successfully stored by the protoc= ol. - @retval EFI_UNSUPPORTED Platform policies do not allow for data to= be written. - Currently not implemented. - @retval EFI_INVALID_PARAMETER BufferSize or Buffer is NULL, or BufferSiz= e exceeds the maximum allowed limit. - @retval EFI_DEVICE_ERROR The data could not be stored due to a hard= ware error. - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold th= e data. - @retval EFI_PROTOCOL_ERROR Input iSCSI initiator name does not adhere= to RFC 3720 - (and other related protocols). - @retval Others Other errors as indicated. -**/ -EFI_STATUS -EFIAPI -IScsiSetInitiatorName ( - IN EFI_ISCSI_INITIATOR_NAME_PROTOCOL *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h b/MdeModul= ePkg/Universal/Network/IScsiDxe/IScsiMisc.h deleted file mode 100644 index 500e00373b25..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h +++ /dev/null @@ -1,317 +0,0 @@ -/** @file - Miscellaneous definitions for iSCSI driver. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_MISC_H_ -#define _ISCSI_MISC_H_ - -#include - -typedef struct _ISCSI_SESSION_CONFIG_DATA ISCSI_SESSION_CONFIG_DATA; - -/// -/// IPv4 Device Path Node Length -/// -#define IP4_NODE_LEN_NEW_VERSIONS 27 - -#pragma pack(1) -typedef struct { - BOOLEAN Enabled; - - BOOLEAN InitiatorInfoFromDhcp; - EFI_IPv4_ADDRESS LocalIp; - EFI_IPv4_ADDRESS SubnetMask; - EFI_IPv4_ADDRESS Gateway; - - BOOLEAN TargetInfoFromDhcp; - CHAR8 TargetName[ISCSI_NAME_MAX_SIZE]; - EFI_IPv4_ADDRESS TargetIp; - UINT16 TargetPort; - UINT8 BootLun[8]; - - UINT8 IsId[6]; -} ISCSI_SESSION_CONFIG_NVDATA; -#pragma pack() - -struct _ISCSI_SESSION_CONFIG_DATA { - ISCSI_SESSION_CONFIG_NVDATA NvData; - - EFI_IPv4_ADDRESS PrimaryDns; - EFI_IPv4_ADDRESS SecondaryDns; - EFI_IPv4_ADDRESS DhcpServer; -}; - -/** - Calculate the prefix length of the IPv4 subnet mask. - - @param[in] SubnetMask The IPv4 subnet mask. - - @return The prefix length of the subnet mask. - @retval 0 Other errors as indicated. -**/ -UINT8 -IScsiGetSubnetMaskPrefixLength ( - IN EFI_IPv4_ADDRESS *SubnetMask - ); - -/** - Convert the hexadecimal encoded LUN string into the 64-bit LUN. - - @param[in] Str The hexadecimal encoded LUN string. - @param[out] Lun Storage to return the 64-bit LUN. - - @retval EFI_SUCCESS The 64-bit LUN is stored in Lun. - @retval EFI_INVALID_PARAMETER The string is malformatted. -**/ -EFI_STATUS -IScsiAsciiStrToLun ( - IN CHAR8 *Str, - OUT UINT8 *Lun - ); - -/** - Convert the 64-bit LUN into the hexadecimal encoded LUN string. - - @param[in] Lun The 64-bit LUN. - @param[out] Str The storage to return the hexadecimal encoded LUN strin= g. -**/ -VOID -IScsiLunToUnicodeStr ( - IN UINT8 *Lun, - OUT CHAR16 *Str - ); - -/** - Convert the ASCII string into a UNICODE string. - - @param[in] Source The ASCII string. - @param[out] Destination The storage to return the UNICODE string. - - @return CHAR16 * Pointer to the UNICODE string. -**/ -CHAR16 * -IScsiAsciiStrToUnicodeStr ( - IN CHAR8 *Source, - OUT CHAR16 *Destination - ); - -/** - Convert the UNICODE string into an ASCII string. - - @param[in] Source The UNICODE string. - @param[out] Destination The storage to return the ASCII string. - - @return CHAR8 * Pointer to the ASCII string. -**/ -CHAR8 * -IScsiUnicodeStrToAsciiStr ( - IN CHAR16 *Source, - OUT CHAR8 *Destination - ); - -/** - Convert the mac address into a hexadecimal encoded "-" seperated string. - - @param[in] Mac The mac address. - @param[in] Len Length in bytes of the mac address. - @param[in] VlanId VLAN ID of the network device. - @param[out] Str The storage to return the mac string. -**/ -VOID -IScsiMacAddrToStr ( - IN EFI_MAC_ADDRESS *Mac, - IN UINT32 Len, - IN UINT16 VlanId, - OUT CHAR16 *Str - ); - -/** - Convert the decimal dotted IPv4 address into the binary IPv4 address. - - @param[in] Str The UNICODE string. - @param[out] Ip The storage to return the ASCII string. - - @retval EFI_SUCCESS The binary IP address is returned in Ip. - @retval EFI_INVALID_PARAMETER The IP string is malformatted. -**/ -EFI_STATUS -IScsiAsciiStrToIp ( - IN CHAR8 *Str, - OUT EFI_IPv4_ADDRESS *Ip - ); - -/** - Convert the binary encoded buffer into a hexadecimal encoded string. - - @param[in] BinBuffer The buffer containing the binary data. - @param[in] BinLength Length of the binary buffer. - @param[in, out] HexStr Pointer to the string. - @param[in, out] HexLength The length of the string. - - @retval EFI_SUCCESS The binary data is converted to the hexadec= imal string - and the length of the string is updated. - @retval EFI_BUFFER_TOO_SMALL The string is too small. - @retval EFI_INVALID_PARAMETER The IP string is malformatted. -**/ -EFI_STATUS -IScsiBinToHex ( - IN UINT8 *BinBuffer, - IN UINT32 BinLength, - IN OUT CHAR8 *HexStr, - IN OUT UINT32 *HexLength - ); - -/** - Convert the hexadecimal string into a binary encoded buffer. - - @param[in, out] BinBuffer The binary buffer. - @param[in, out] BinLength Length of the binary buffer. - @param[in] HexStr The hexadecimal string. - - @retval EFI_SUCCESS The hexadecimal string is converted into a = binary - encoded buffer. - @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the = converted data. -**/ -EFI_STATUS -IScsiHexToBin ( - IN OUT UINT8 *BinBuffer, - IN OUT UINT32 *BinLength, - IN CHAR8 *HexStr - ); - -/** - Generate random numbers. - - @param[in, out] Rand The buffer to contain random numbers. - @param[in] RandLength The length of the Rand buffer. -**/ -VOID -IScsiGenRandom ( - IN OUT UINT8 *Rand, - IN UINTN RandLength - ); - -/** - Create the iSCSI driver data.. - - @param[in] Image The handle of the driver image. - @param[in] Controller The handle of the controller. - - @return The iSCSI driver data created. - @retval NULL Other errors as indicated. -**/ -ISCSI_DRIVER_DATA * -IScsiCreateDriverData ( - IN EFI_HANDLE Image, - IN EFI_HANDLE Controller - ); - -/** - Clean the iSCSI driver data. - - @param[in] Private The iSCSI driver data. - - @retval EFI_SUCCES The clean operation is successful. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiCleanDriverData ( - IN ISCSI_DRIVER_DATA *Private - ); - -/** - Check wheather the Controller is configured to use DHCP protocol. - - @param[in] Controller The handle of the controller. - - @retval TRUE The handle of the controller need the D= hcp protocol. - @retval FALSE The handle of the controller does not n= eed the Dhcp protocol. - -**/ -BOOLEAN -IScsiDhcpIsConfigured ( - IN EFI_HANDLE Controller - ); - -/** - Get the various configuration data of this iSCSI instance. - - @param[in] Private The iSCSI driver data. - - @retval EFI_SUCCESS The configuration of this instance is got. - @retval EFI_ABORTED The operation was aborted. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiGetConfigData ( - IN ISCSI_DRIVER_DATA *Private - ); - -/** - Get the device path of the iSCSI tcp connection and update it. - - @param[in] Private The iSCSI driver data. - - @return The updated device path. - @retval NULL Other errors as indicated. -**/ -EFI_DEVICE_PATH_PROTOCOL * -IScsiGetTcpConnDevicePath ( - IN ISCSI_DRIVER_DATA *Private - ); - -/** - Abort the session when the transition from BS to RT is initiated. - - @param[in] Event The event signaled. - @param[in] Context The iSCSI driver data. -**/ -VOID -EFIAPI -IScsiOnExitBootService ( - IN EFI_EVENT Event, - IN VOID *Context - ); - -/** - Tests whether a controller handle is being managed by IScsi driver. - - This function tests whether the driver specified by DriverBindingHandle = is - currently managing the controller specified by ControllerHandle. This t= est - is performed by evaluating if the the protocol specified by ProtocolGuid= is - present on ControllerHandle and is was opened by DriverBindingHandle and= Nic - Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. - If ProtocolGuid is NULL, then ASSERT(). - - @param ControllerHandle A handle for a controller to test. - @param DriverBindingHandle Specifies the driver binding handle for the - driver. - @param ProtocolGuid Specifies the protocol that the driver spec= ified - by DriverBindingHandle opens in its Start() - function. - - @retval EFI_SUCCESS ControllerHandle is managed by the driver - specified by DriverBindingHandle. - @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driv= er - specified by DriverBindingHandle. - -**/ -EFI_STATUS -EFIAPI -IScsiTestManagedDevice ( - IN EFI_HANDLE ControllerHandle, - IN EFI_HANDLE DriverBindingHandle, - IN EFI_GUID *ProtocolGuid - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.h b/MdeModu= lePkg/Universal/Network/IScsiDxe/IScsiProto.h deleted file mode 100644 index 6469df0434a1..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.h +++ /dev/null @@ -1,1005 +0,0 @@ -/** @file - The header file of iSCSI Protocol that defines many specific data struct= ures. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_PROTO_H_ -#define _ISCSI_PROTO_H_ - -#include - -// -// RFC 1982 Serial Number Arithmetic, SERIAL_BITS =3D 32 -// -#define ISCSI_SEQ_EQ(s1, s2) ((s1) =3D=3D (s2)) -#define ISCSI_SEQ_LT(s1, s2) \ - ( \ - (((INT32) (s1) < (INT32) (s2)) && (s2 - s1) < ((UINT32) 1 << 31)) ||= \ - (((INT32) (s1) > (INT32) (s2)) && (s1 - s2) > ((UINT32) 1 << 31)) \ - ) -#define ISCSI_SEQ_GT(s1, s2) \ - ( \ - (((INT32) (s1) < (INT32) (s2)) && (s2 - s1) > ((UINT32) 1 << 31)) ||= \ - (((INT32) (s1) > (INT32) (s2)) && (s1 - s2) < ((UINT32) 1 << 31)) \ - ) - -#define ISCSI_WELL_KNOWN_PORT 3260 -#define ISCSI_MAX_CONNS_PER_SESSION 1 - -#define DEFAULT_MAX_RECV_DATA_SEG_LEN 8192 -#define MAX_RECV_DATA_SEG_LEN_IN_FFP 65536 -#define DEFAULT_MAX_OUTSTANDING_R2T 1 - -#define ISCSI_VERSION_MAX 0x00 -#define ISCSI_VERSION_MIN 0x00 - -#define ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME EFI_TIMER_PERIOD_SEC= ONDS(20) -#define ISCSI_CHECK_MEDIA_GET_DHCP_WAITING_TIME EFI_TIMER_PERIOD_SEC= ONDS(20) - -#define ISCSI_KEY_AUTH_METHOD "AuthMethod" -#define ISCSI_KEY_HEADER_DIGEST "HeaderDigest" -#define ISCSI_KEY_DATA_DIGEST "DataDigest" -#define ISCSI_KEY_MAX_CONNECTIONS "MaxConnections" -#define ISCSI_KEY_TARGET_NAME "TargetName" -#define ISCSI_KEY_INITIATOR_NAME "InitiatorName" -#define ISCSI_KEY_TARGET_ALIAS "TargetAlias" -#define ISCSI_KEY_INITIATOR_ALIAS "InitiatorAlias" -#define ISCSI_KEY_TARGET_ADDRESS "TargetAddress" -#define ISCSI_KEY_INITIAL_R2T "InitialR2T" -#define ISCSI_KEY_IMMEDIATE_DATA "ImmediateData" -#define ISCSI_KEY_TARGET_PORTAL_GROUP_TAG "TargetPortalGroupTag" -#define ISCSI_KEY_MAX_BURST_LENGTH "MaxBurstLength" -#define ISCSI_KEY_FIRST_BURST_LENGTH "FirstBurstLength" -#define ISCSI_KEY_DEFAULT_TIME2WAIT "DefaultTime2Wait" -#define ISCSI_KEY_DEFAULT_TIME2RETAIN "DefaultTime2Retain" -#define ISCSI_KEY_MAX_OUTSTANDING_R2T "MaxOutstandingR2T" -#define ISCSI_KEY_DATA_PDU_IN_ORDER "DataPDUInOrder" -#define ISCSI_KEY_DATA_SEQUENCE_IN_ORDER "DataSequenceInOrder" -#define ISCSI_KEY_ERROR_RECOVERY_LEVEL "ErrorRecoveryLevel" -#define ISCSI_KEY_SESSION_TYPE "SessionType" -#define ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH "MaxRecvDataSegmentLength" - -#define ISCSI_KEY_VALUE_NONE "None" - -/// -/// connection state for initiator -/// - -#define CONN_STATE_FREE 0 -#define CONN_STATE_XPT_WAIT 1 -#define CONN_STATE_IN_LOGIN 2 -#define CONN_STATE_LOGGED_IN 3 -#define CONN_STATE_IN_LOGOUT 4 -#define CONN_STATE_LOGOUT_REQUESTED 5 -#define CONN_STATE_CLEANUP_WAIT 6 -#define CONN_STATE_IN_CLEANUP 7 - -/// -/// session state for initiator -/// -#define SESSION_STATE_FREE 0 -#define SESSION_STATE_LOGGED_IN 1 -#define SESSION_STATE_FAILED 2 - -typedef enum { - DataIn =3D 0, - DataOut =3D 1, - DataBi =3D 2 -} DATA_DIRECTION; - -#define ISCSI_RESERVED_TAG 0xffffffff - -#define ISCSI_REQ_IMMEDIATE 0x40 -#define ISCSI_OPCODE_MASK 0x3F - -#define ISCSI_SET_OPCODE(PduHdr, Op, Flgs) ((((ISCSI_BASIC_HEADER *) (Pdu= Hdr))->OpCode) =3D ((Op) | (Flgs))) -#define ISCSI_GET_OPCODE(PduHdr) ((((ISCSI_BASIC_HEADER *) (Pdu= Hdr))->OpCode) & ISCSI_OPCODE_MASK) -#define ISCSI_CHECK_OPCODE(PduHdr, Op) ((((PduHdr)->OpCode) & ISCSI_O= PCODE_MASK) =3D=3D (Op)) -#define ISCSI_IMMEDIATE_ON(PduHdr) ((PduHdr)->OpCode & ISCSI_REQ_= IMMEDIATE) -#define ISCSI_SET_FLAG(PduHdr, Flag) (((ISCSI_BASIC_HEADER *) (PduH= dr))->Flags |=3D (BOOLEAN)(Flag)) -#define ISCSI_CLEAR_FLAG(PduHdr, Flag) (((ISCSI_BASIC_HEADER *) (PduH= dr))->Flags &=3D ~(Flag)) -#define ISCSI_FLAG_ON(PduHdr, Flag) ((((ISCSI_BASIC_HEADER *) (Pdu= Hdr))->Flags & (Flag)) =3D=3D (Flag)) -#define ISCSI_SET_STAGES(PduHdr, Cur, Nxt) ((PduHdr)->Flags =3D (UINT8) (= (PduHdr)->Flags | ((Cur) << 2 | (Nxt)))) -#define ISCSI_GET_CURRENT_STAGE(PduHdr) (((PduHdr)->Flags >> 2) & 0x3) -#define ISCSI_GET_NEXT_STAGE(PduHdr) (((PduHdr)->Flags) & 0x3) - -#define ISCSI_GET_PAD_LEN(DataLen) ((~(DataLen) + 1) & 0x3) -#define ISCSI_ROUNDUP(DataLen) (((DataLen) + 3) &~(0x3)) - -#define HTON24(Dst, Src) \ - do { \ - (Dst)[0] =3D (UINT8) (((Src) >> 16) & 0xFF); \ - (Dst)[1] =3D (UINT8) (((Src) >> 8) & 0xFF); \ - (Dst)[2] =3D (UINT8) ((Src) & 0xFF); \ - } while (0); - -#define NTOH24(src) (((src)[0] << 16) | ((src)[1] = << 8) | ((src)[2])) - -#define ISCSI_GET_DATASEG_LEN(PduHdr) NTOH24 (((ISCSI_BASIC_HEADER *= ) (PduHdr))->DataSegmentLength) -#define ISCSI_SET_DATASEG_LEN(PduHdr, Len) HTON24 (((ISCSI_BASIC_HEADER *= ) (PduHdr))->DataSegmentLength, (Len)) - -// -// initiator opcodes -// -#define ISCSI_OPCODE_NOP_OUT 0x00 -#define ISCSI_OPCODE_SCSI_CMD 0x01 -#define ISCSI_OPCODE_SCSI_TMF_REQ 0x02 -#define ISCSI_OPCODE_LOGIN_REQ 0x03 -#define ISCSI_OPCODE_TEXT_REQ 0x04 -#define ISCSI_OPCODE_SCSI_DATA_OUT 0x05 -#define ISCSI_OPCODE_LOGOUT_REQ 0x06 -#define ISCSI_OPCODE_SNACK_REQ 0x10 -#define ISCSI_OPCODE_VENDOR_I0 0x1c -#define ISCSI_OPCODE_VENDOR_I1 0x1d -#define ISCSI_OPCODE_VENDOR_I2 0x1e - -// -// target opcodes -// -#define ISCSI_OPCODE_NOP_IN 0x20 -#define ISCSI_OPCODE_SCSI_RSP 0x21 -#define ISCSI_OPCODE_SCSI_TMF_RSP 0x22 -#define ISCSI_OPCODE_LOGIN_RSP 0x23 -#define ISCSI_OPCODE_TEXT_RSP 0x24 -#define ISCSI_OPCODE_SCSI_DATA_IN 0x25 -#define ISCSI_OPCODE_LOGOUT_RSP 0x26 -#define ISCSI_OPCODE_R2T 0x31 -#define ISCSI_OPCODE_ASYNC_MSG 0x32 -#define ISCSI_OPCODE_VENDOR_T0 0x3c -#define ISCSI_OPCODE_VENDOR_T1 0x3d -#define ISCSI_OPCODE_VENDOR_T2 0x3e -#define ISCSI_OPCODE_REJECT 0x3f - -#define ISCSI_BHS_FLAG_FINAL 0x80 - -/// -/// iSCSI Basic Header Segment -/// -typedef struct _ISCSI_BASIC_HEADER { - UINT8 OpCode; - UINT8 Flags; - UINT16 OpCodeSpecific1; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 OpCodeSpecific2[7]; -} ISCSI_BASIC_HEADER; - -// -// Defined AHS types, others are reserved. -// -#define ISCSI_AHS_TYPE_EXT_CDB 0x1 -#define ISCSI_AHS_TYPE_BI_EXP_READ_DATA_LEN 0x2 - -typedef struct _ISCSI_ADDTIONAL_HEADER { - UINT16 Length; - UINT8 Type; - UINT8 TypeSpecific[1]; -} ISCSI_ADDITIONAL_HEADER; - -typedef struct _ISCSI_BI_EXP_READ_DATA_LEN_AHS { - UINT16 Length; - UINT8 Type; - UINT8 Reserved; - UINT32 ExpReadDataLength; -} ISCSI_BI_EXP_READ_DATA_LEN_AHS; - -#define SCSI_CMD_PDU_FLAG_READ 0x40 -#define SCSI_CMD_PDU_FLAG_WRITE 0x20 - -#define ISCSI_CMD_PDU_TASK_ATTR_MASK 0x07 - -// -// task attributes -// -#define ISCSI_TASK_ATTR_UNTAGGED 0x00 -#define ISCSI_TASK_ATTR_SIMPLE 0x01 -#define ISCSI_TASK_ATTR_ORDERD 0x02 -#define ISCSI_TASK_ATTR_HOQ 0x03 -#define ISCSI_TASK_ATTR_ACA 0x04 - -/// -/// SCSI Command -/// -typedef struct _SCSI_COMMAND { - UINT8 OpCode; - UINT8 Flags; - UINT16 Reserved; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 ExpDataXferLength; - UINT32 CmdSN; - UINT32 ExpStatSN; - UINT8 Cdb[16]; -} SCSI_COMMAND; - -// -// flag bit definitions in SCSI response -// -#define SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW 0x10 -#define SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW 0x08 -#define SCSI_RSP_PDU_FLAG_OVERFLOW 0x04 -#define SCSI_RSP_PDU_FLAG_UNDERFLOW 0x02 - -// -// iSCSI service response codes -// -#define ISCSI_SERVICE_RSP_COMMAND_COMPLETE_AT_TARGET 0x00 -#define ISCSI_SERVICE_RSP_TARGET_FAILURE 0x01 - -/// -/// SCSI Response -/// -typedef struct _SCSI_RESPONSE { - UINT8 OpCode; - UINT8 Flags; - UINT8 Response; - UINT8 Status; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Reserved[8]; - UINT32 InitiatorTaskTag; - UINT32 SNACKTag; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 ExpDataSN; - UINT32 BiReadResidualCount; - UINT32 ResidualCount; -} SCSI_RESPONSE; - -typedef struct _ISCSI_SENSE_DATA { - UINT16 Length; - UINT8 Data[2]; -} ISCSI_SENSE_DATA; - -/// -/// iSCSI Task Managment Function Request -/// -typedef struct _ISCSI_TMF_REQUEST { - UINT8 OpCode; - UINT8 Fuction; - UINT16 Reserved1; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 ReferencedTaskTag; - UINT32 CmdSN; - UINT32 ExpStatSN; - UINT32 RefCmdSN; - UINT32 ExpDataSN; - UINT32 Reserved2[2]; -} ISCSI_TMF_REQUEST; - -#define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_COMPLETE 0 -#define ISCSI_TMF_RSP_PDU_RSP_TASK_NOT_EXIST 1 -#define ISCSI_TMF_RSP_PDU_RSP_LUN_NOT_EXIST 2 -#define ISCSI_TMF_RSP_PDU_RSP_TASK_STILL_ALLEGIANT 3 -#define ISCSI_TMF_RSP_PDU_RSP_TASK_REASSGIN_NOT_SUPPORTED 4 -#define ISCSI_TMF_RSP_PDU_RSP_NOT_SUPPORTED 5 -#define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_AHTH_FAILED 6 -#define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_REJECTED 255 - -/// -/// iSCSI Task Management Function Response -/// -typedef struct _ISCSI_TMF_RESPONSE { - UINT8 OpCode; - UINT8 Reserved1; - UINT8 Response; - UINT8 Reserved2; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT32 Reserver3[2]; - UINT32 InitiatorTaskTag; - UINT32 Reserved4; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 Reserved[3]; -} ISCSI_TMF_RESPONSE; - -/// -/// SCSI Data-Out -/// -typedef struct _ISCSI_SCSI_DATA_OUT { - UINT8 OpCode; - UINT8 Reserved1[3]; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 TargetTransferTag; - UINT32 Reserved2; - UINT32 ExpStatSN; - UINT32 Reserved3; - UINT32 DataSN; - UINT32 BufferOffset; - UINT32 Reserved4; -} ISCSI_SCSI_DATA_OUT; - -#define SCSI_DATA_IN_PDU_FLAG_ACKKNOWLEDGE 0x40 -#define SCSI_DATA_IN_PDU_FLAG_OVERFLOW SCSI_RSP_PDU_FLAG_OVERFLOW -#define SCSI_DATA_IN_PDU_FLAG_UNDERFLOW SCSI_RSP_PDU_FLAG_UNDERFLOW -#define SCSI_DATA_IN_PDU_FLAG_STATUS_VALID 0x01 - -/// -/// SCSI Data-In -/// -typedef struct _ISCSI_SCSI_DATA_IN { - UINT8 OpCode; - UINT8 Flags; - UINT8 Reserved1; - UINT8 Status; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 TargetTransferTag; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 DataSN; - UINT32 BufferOffset; - UINT32 ResidualCount; -} ISCSI_SCSI_DATA_IN; - -#define ISCSI_GET_BUFFER_OFFSET(PduHdr) NTOHL (((ISCSI_SCSI_DATA_IN *) (Pd= uHdr))->BufferOffset) - -/// -/// Ready To Transfer -/// -typedef struct _ISCSI_READY_TO_TRANSFER { - UINT8 OpCode; - UINT8 Reserved1[3]; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 TargetTransferTag; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 R2TSeqNum; - UINT32 BufferOffset; - UINT32 DesiredDataTransferLength; -} ISCSI_READY_TO_TRANSFER; - -typedef struct _ISCSI_ASYNC_MESSAGE { - UINT8 OpCode; - UINT8 Reserved1[8]; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 Reserved2; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT8 AsyncEvent; - UINT8 AsyncVCode; - UINT16 Parameter1; - UINT16 Parameter2; - UINT16 Parameter3; - UINT32 Reserved3; -} ISCSI_ASYNC_MESSAGE; - -#define ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT 0x80 -#define ISCSI_LOGIN_REQ_PDU_FLAG_CONTINUE 0x40 - -/// -/// Login Request -/// -typedef struct _ISCSI_LOGIN_REQUEST { - UINT8 OpCode; - UINT8 Flags; - UINT8 VersionMax; - UINT8 VersionMin; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Isid[6]; - UINT16 Tsih; - UINT32 InitiatorTaskTag; - UINT16 Cid; - UINT16 Reserved1; - UINT32 CmdSN; - UINT32 ExpStatSN; - UINT32 Reserved2[4]; -} ISCSI_LOGIN_REQUEST; - -#define ISCSI_LOGIN_RSP_PDU_FLAG_TRANSIT ISCSI_LOGIN_REQ_PDU_FLAG_TRANS= IT -#define ISCSI_LOGIN_RSP_PDU_FLAG_CONTINUE ISCSI_LOGIN_REQ_PDU_FLAG_CONTI= NUE - -#define ISCSI_LOGIN_STATUS_SUCCESS 0 -#define ISCSI_LOGIN_STATUS_REDIRECTION 1 -#define ISCSI_LOGIN_STATUS_INITIATOR_ERROR 2 -#define ISCSI_LOGIN_STATUS_TARGET_ERROR 3 - -/// -/// Login Response -/// -typedef struct _ISCSI_LOGIN_RESPONSE { - UINT8 OpCode; - UINT8 Flags; - UINT8 VersionMax; - UINT8 VersionActive; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Isid[6]; - UINT16 Tsih; - UINT32 InitiatorTaskTag; - UINT32 Reserved1; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT8 StatusClass; - UINT8 StatusDetail; - UINT8 Reserved2[10]; -} ISCSI_LOGIN_RESPONSE; - -#define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0 -#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1 -#define ISCSI_LOGOUT_REASON_REMOVE_CONNECTION_FOR_RECOVERY 2 - -/// -/// Logout Request -/// -typedef struct _ISCSI_LOGOUT_REQUEST { - UINT8 OpCode; - UINT8 ReasonCode; - UINT16 Reserved1; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT32 Reserved2[2]; - UINT32 InitiatorTaskTag; - UINT16 Cid; - UINT16 Reserved3; - UINT32 CmdSN; - UINT32 ExpStatSN; - UINT32 Reserved4[4]; -} ISCSI_LOGOUT_REQUEST; - -#define ISCSI_LOGOUT_RESPONSE_SESSION_CLOSED_SUCCESS 0 -#define ISCSI_LOGOUT_RESPONSE_CID_NOT_FOUND 1 -#define ISCSI_LOGOUT_RESPONSE_RECOVERY_NOT_SUPPORTED 2 -#define ISCSI_LOGOUT_RESPONSE_CLEANUP_FAILED 3 - -/// -/// Logout Response -/// -typedef struct _ISCSI_LOGOUT_RESPONSE { - UINT8 OpCode; - UINT8 Reserved1; - UINT8 Response; - UINT8 Reserved2; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT32 Reserved3[2]; - UINT32 InitiatorTaskTag; - UINT32 Reserved4; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 Reserved5; - UINT16 Time2Wait; - UINT16 Time2Retain; - UINT32 Reserved6; -} ISCSI_LOGOUT_RESPONSE; - -#define ISCSI_SNACK_REQUEST_TYPE_DATA_OR_R2T 0 -#define ISCSI_SNACK_REQUEST_TYPE_STATUS 1 -#define ISCSI_SNACK_REQUEST_TYPE_DATA_ACK 2 -#define ISCSI_SNACK_REQUEST_TYPE_RDATA 3 - -/// -/// SNACK Request -/// -typedef struct _ISCSI_SNACK_REQUEST { - UINT8 OpCode; - UINT8 Type; - UINT16 Reserved1; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 TargetTransferTag; - UINT32 Reserved2; - UINT32 ExpStatSN; - UINT32 Reserved[2]; - UINT32 BegRun; - UINT32 RunLength; -} ISCSI_SNACK_REQUEST; - -/// -/// Reject -/// -typedef struct _ISCSI_REJECT { - UINT8 OpCode; - UINT8 Reserved1; - UINT8 Reason; - UINT8 Reserved2; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT32 Reserved3[2]; - UINT32 InitiatorTaskTag; - UINT32 Reserved4; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 DataSN; - UINT32 Reserved5[2]; -} ISCSI_REJECT; - -/// -/// NOP-Out -/// -typedef struct _ISCSI_NOP_OUT { - UINT8 OpCode; - UINT8 Reserved1[3]; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 TargetTransferTag; - UINT32 CmdSN; - UINT32 ExpStatSN; - UINT32 Reserved2[4]; -} ISCSI_NOP_OUT; - -/// -/// NOP-In -/// -typedef struct _ISCSI_NOP_IN { - UINT8 OpCode; - UINT8 Reserved1[3]; - UINT8 TotalAHSLength; - UINT8 DataSegmentLength[3]; - UINT8 Lun[8]; - UINT32 InitiatorTaskTag; - UINT32 TargetTransferTag; - UINT32 StatSN; - UINT32 ExpCmdSN; - UINT32 MaxCmdSN; - UINT32 Reserved2[3]; -} ISCSI_NOP_IN; - -#define ISCSI_SECURITY_NEGOTIATION 0 -#define ISCSI_LOGIN_OPERATIONAL_NEGOTIATION 1 -#define ISCSI_FULL_FEATURE_PHASE 3 - -typedef enum { - IScsiDigestNone, - IScsiDigestCRC32 -} ISCSI_DIGEST_TYPE; - -typedef struct _ISCSI_XFER_CONTEXT { - UINT32 TargetTransferTag; - UINT32 Offset; - UINT32 DesiredLength; - UINT32 ExpDataSN; -} ISCSI_XFER_CONTEXT; - -typedef struct _ISCSI_IN_BUFFER_CONTEXT { - UINT8 *InData; - UINT32 InDataLen; -} ISCSI_IN_BUFFER_CONTEXT; - -typedef struct _ISCSI_TCB { - LIST_ENTRY Link; - - BOOLEAN SoFarInOrder; - UINT32 ExpDataSN; - BOOLEAN FbitReceived; - BOOLEAN StatusXferd; - UINT32 ActiveR2Ts; - UINT32 Response; - CHAR8 *Reason; - UINT32 InitiatorTaskTag; - UINT32 CmdSN; - UINT32 SNACKTag; - - ISCSI_XFER_CONTEXT XferContext; - - ISCSI_CONNECTION *Conn; -} ISCSI_TCB; - -typedef struct _ISCSI_KEY_VALUE_PAIR { - LIST_ENTRY List; - - CHAR8 *Key; - CHAR8 *Value; -} ISCSI_KEY_VALUE_PAIR; - -/** - Attach the iSCSI connection to the iSCSI session. - - @param[in, out] Session The iSCSI session. - @param[in, out] Conn The iSCSI connection. -**/ -VOID -IScsiAttatchConnection ( - IN OUT ISCSI_SESSION *Session, - IN OUT ISCSI_CONNECTION *Conn - ); - -/** - Detach the iSCSI connection from the session it belongs to. - - @param[in, out] Conn The iSCSI connection. -**/ -VOID -IScsiDetatchConnection ( - IN OUT ISCSI_CONNECTION *Conn - ); - -/** - This function does the iSCSI connection login. - - @param[in, out] Conn The iSCSI connection to login. - - @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI= target. - @retval EFI_TIMEOUT Timeout happened during the login procedure. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiConnLogin ( - IN OUT ISCSI_CONNECTION *Conn - ); - -/** - Create a TCP connection for the iSCSI session. - - @param[in] Private The iSCSI driver data. - @param[in] Session Maximum CmdSN from the target. - - @return The newly created iSCSI connection. -**/ -ISCSI_CONNECTION * -IScsiCreateConnection ( - IN ISCSI_DRIVER_DATA *Private, - IN ISCSI_SESSION *Session - ); - -/** - Destroy an iSCSI connection. - - @param[in] Conn The connection to destroy. -**/ -VOID -IScsiDestroyConnection ( - IN ISCSI_CONNECTION *Conn - ); - -/** - Login the iSCSI session. - - @param[in] Private The iSCSI driver data. - - @retval EFI_SUCCESS The iSCSI session login procedure finished. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NO_MEDIA There was a media error. - @retval Others Other errors as indicated. - -**/ -EFI_STATUS -IScsiSessionLogin ( - IN ISCSI_DRIVER_DATA *Private - ); - -/** - Build and send the iSCSI login request to the iSCSI target according to - the current login stage. - - @param[in] Conn The connection in the iSCSI login phase. - - @retval EFI_SUCCESS The iSCSI login request PDU is built and se= nt on this - connection. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_DEVICE_ERROR Some kind of device error happened. -**/ -EFI_STATUS -IScsiSendLoginReq ( - IN ISCSI_CONNECTION *Conn - ); - -/** - Receive and process the iSCSI login response. - - @param[in] Conn The connection in the iSCSI login phase. - - @retval EFI_SUCCESS The iSCSI login response PDU is received an= d processed. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiReceiveLoginRsp ( - IN ISCSI_CONNECTION *Conn - ); - -/** - Add an iSCSI key-value pair as a string into the data segment of the Log= in Request PDU. - The DataSegmentLength and the actual size of the net buffer containing t= his PDU will be - updated. - - @param[in, out] Pdu The iSCSI PDU whose data segment the key-va= lue pair will - be added to. - @param[in] Key The key name string. - @param[in] Value The value string. - - @retval EFI_SUCCESS The key-valu pair is added to the PDU's dat= asegment and - the correspondence length fields are update= d. - @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to add= the key-value - pair. -**/ -EFI_STATUS -IScsiAddKeyValuePair ( - IN OUT NET_BUF *Pdu, - IN CHAR8 *Key, - IN CHAR8 *Value - ); - -/** - Prepare the iSCSI login request to be sent according to the current logi= n status. - - @param[in, out] Conn The connection in the iSCSI login phase. - - @return The pointer to the net buffer containing the iSCSI login request= built. - @retval Others Other errors as indicated. -**/ -NET_BUF * -IScsiPrepareLoginReq ( - IN OUT ISCSI_CONNECTION *Conn - ); - -/** - Process the iSCSI Login Response. - - @param[in, out] Conn The connection on which the iSCSI login response i= s received. - @param[in, out] Pdu The iSCSI login response PDU. - - @retval EFI_SUCCESS The iSCSI login response PDU is processed and= all check are passed. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. - @retval EFI_MEDIA_CHANGED Target is redirected. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiProcessLoginRsp ( - IN OUT ISCSI_CONNECTION *Conn, - IN OUT NET_BUF *Pdu - ); - -/** - Updated the target information according the data received in the iSCSI - login response with an target redirection status. - - @param[in, out] Session The iSCSI session. - @param[in] Data The data segment which should contain the - TargetAddress key-value list. - @param[in] Len Length of the data. - - @retval EFI_SUCCESS The target address is updated. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NOT_FOUND The TargetAddress key is not found. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiUpdateTargetAddress ( - IN OUT ISCSI_SESSION *Session, - IN CHAR8 *Data, - IN UINT32 Len - ); - -/** - The callback function to free the net buffer list. - - @param[in] Arg The opaque parameter. -**/ -VOID -EFIAPI -IScsiFreeNbufList ( - VOID *Arg - ); - -/** - Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI P= DU header and - an optional data segment. The two parts will be put into two blocks of b= uffers in the - net buffer. The digest check will be conducted in this function if neede= d and the digests - will be trimmed from the PDU buffer. - - @param[in] Conn The iSCSI connection to receive data from. - @param[out] Pdu The received iSCSI pdu. - @param[in] Context The context used to describe information on the= caller provided - buffer to receive data segment of the iSCSI pdu= , it's optional. - @param[in] HeaderDigest Whether there will be header digest received. - @param[in] DataDigest Whether there will be data digest. - @param[in] TimeoutEvent The timeout event, it's optional. - - @retval EFI_SUCCESS An iSCSI pdu is received. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiReceivePdu ( - IN ISCSI_CONNECTION *Conn, - OUT NET_BUF **Pdu, - IN ISCSI_IN_BUFFER_CONTEXT *Context, OPTIONAL - IN BOOLEAN HeaderDigest, - IN BOOLEAN DataDigest, - IN EFI_EVENT TimeoutEvent OPTIONAL - ); - -/** - Check and get the result of the prameter negotiation. - - @param[in, out] Conn The connection in iSCSI login. - - @retval EFI_SUCCESS The parmeter check is passed and negotiatio= n is finished. - @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. -**/ -EFI_STATUS -IScsiCheckOpParams ( - IN OUT ISCSI_CONNECTION *Conn - ); - -/** - Fill the oprational prameters. - - @param[in] Conn The connection in iSCSI login. - @param[in, out] Pdu The iSCSI login request PDU to fill the par= ameters. - - @retval EFI_SUCCESS The parmeters are filled into the iSCSI log= in request PDU. -**/ -EFI_STATUS -IScsiFillOpParams ( - IN ISCSI_CONNECTION *Conn, - IN OUT NET_BUF *Pdu - ); - -/** - Pad the iSCSI AHS or data segment to an integer number of 4 byte words. - - @param[in, out] Pdu The iSCSI pdu which contains segments to pa= d. - @param[in] Len The length of the last semgnet in the PDU. - - @retval EFI_SUCCESS The segment is padded or no need to pad it. - @retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to= add the - padding bytes. -**/ -EFI_STATUS -IScsiPadSegment ( - IN OUT NET_BUF *Pdu, - IN UINT32 Len - ); - -/** - Build a key-value list from the data segment. - - @param[in] Data The data segment containing the key-value pairs. - @param[in] Len Length of the data segment. - - @return The key-value list. - @retval NULL Other errors as indicated. -**/ -LIST_ENTRY * -IScsiBuildKeyValueList ( - IN CHAR8 *Data, - IN UINT32 Len - ); - -/** - Get the value string by the key name from the key-value list. If found, - the key-value entry will be removed from the list. - - @param[in, out] KeyValueList The key-value list. - @param[in] Key The key name to find. - - @return The value string. -**/ -CHAR8 * -IScsiGetValueByKeyFromList ( - IN OUT LIST_ENTRY *KeyValueList, - IN CHAR8 *Key - ); - -/** - Free the key-value list. - - @param[in] KeyValueList The key-value list. -**/ -VOID -IScsiFreeKeyValueList ( - IN LIST_ENTRY *KeyValueList - ); - -/** - Normalize the iSCSI name according to RFC. - - @param[in, out] Name The iSCSI name. - @param[in] Len length of the iSCSI name. - - @retval EFI_SUCCESS The iSCSI name is valid and normalized. - @retval EFI_PROTOCOL_ERROR The iSCSI name is mal-formatted or not in the= IQN format. -**/ -EFI_STATUS -IScsiNormalizeName ( - IN OUT CHAR8 *Name, - IN UINTN Len - ); - -/** - Execute the SCSI command issued through the EXT SCSI PASS THRU protocol. - - @param[in] PassThru The EXT SCSI PASS THRU protocol. - @param[in] Target The target ID. - @param[in] Lun The LUN. - @param[in, out] Packet The request packet containing IO request, SCS= I command - buffer and buffers to read/write. - - @retval EFI_SUCCES The SCSI command is executed and the result= is updated to - the Packet. - @retval EFI_DEVICE_ERROR Session state was not as required. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval EFI_NOT_READY The target can not accept new commands. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -IScsiExecuteScsiCommand ( - IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru, - IN UINT8 *Target, - IN UINT64 Lun, - IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet - ); - -/** - Reinstate the session on some error. - - @param[in, out] Private The iSCSI driver data. - - @retval EFI_SUCCES The session is reinstated from some error. - @retval Other Reinstatement failed. -**/ -EFI_STATUS -IScsiSessionReinstatement ( - IN OUT ISCSI_DRIVER_DATA *Private - ); - -/** - Initialize some session parameters before login. - - @param[in, out] Session The iSCSI session. - @param[in] Recovery Whether the request is from a fresh new start = or recovery. -**/ -VOID -IScsiSessionInit ( - IN OUT ISCSI_SESSION *Session, - IN BOOLEAN Recovery - ); - -/** - Abort the iSCSI session, that is, reset all the connection and free the - resources. - - @param[in, out] Session The iSCSI session. - - @retval EFI_SUCCES The session is aborted. -**/ -EFI_STATUS -IScsiSessionAbort ( - IN OUT ISCSI_SESSION *Session - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.h b/MdeMod= ulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.h deleted file mode 100644 index 9e0f1e0f02c2..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiTcp4Io.h +++ /dev/null @@ -1,142 +0,0 @@ -/** @file - iSCSI Tcp4 IO related definitions. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _ISCSI_TCP4_IO_H_ -#define _ISCSI_TCP4_IO_H_ - -#include -#include - -typedef struct _TCP4_IO_CONFIG_DATA { - EFI_IPv4_ADDRESS LocalIp; - EFI_IPv4_ADDRESS SubnetMask; - EFI_IPv4_ADDRESS Gateway; - - EFI_IPv4_ADDRESS RemoteIp; - UINT16 RemotePort; -} TCP4_IO_CONFIG_DATA; - -typedef struct _TCP4_IO { - EFI_HANDLE Image; - EFI_HANDLE Controller; - - EFI_HANDLE Handle; - EFI_TCP4_PROTOCOL *Tcp4; - - EFI_TCP4_CONNECTION_TOKEN ConnToken; - EFI_TCP4_IO_TOKEN TxToken; - EFI_TCP4_IO_TOKEN RxToken; - EFI_TCP4_CLOSE_TOKEN CloseToken; - - BOOLEAN IsConnDone; - BOOLEAN IsTxDone; - BOOLEAN IsRxDone; - BOOLEAN IsCloseDone; -} TCP4_IO; - -/** - Create a TCP socket with the specified configuration data. - - @param[in] Image The handle of the driver image. - @param[in] Controller The handle of the controller. - @param[in] ConfigData The Tcp4 configuration data. - @param[in] Tcp4Io The Tcp4Io. - - @retval EFI_SUCCESS The TCP socket is created and configured. - @retval Others Failed to create the TCP socket or configure it. -**/ -EFI_STATUS -Tcp4IoCreateSocket ( - IN EFI_HANDLE Image, - IN EFI_HANDLE Controller, - IN TCP4_IO_CONFIG_DATA *ConfigData, - IN TCP4_IO *Tcp4Io - ); - -/** - Destroy the socket. - - @param[in] Tcp4Io The Tcp4Io which wraps the socket to be destroyeds. -**/ -VOID -Tcp4IoDestroySocket ( - IN TCP4_IO *Tcp4Io - ); - -/** - Connect to the other endpoint of the TCP socket. - - @param[in, out] Tcp4Io The Tcp4Io wrapping the TCP socket. - @param[in] Timeout The time to wait for connection done. - - @retval EFI_SUCCESS Connect to the other endpoint of the TCP so= cket successfully. - @retval EFI_TIMEOUT Failed to connect to the other endpoint of = the TCP socket in the specified time period. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -Tcp4IoConnect ( - IN OUT TCP4_IO *Tcp4Io, - IN EFI_EVENT Timeout - ); - -/** - Reset the socket. - - @param[in, out] Tcp4Io The Tcp4Io wrapping the TCP socket. -**/ -VOID -Tcp4IoReset ( - IN OUT TCP4_IO *Tcp4Io - ); - -/** - Transmit the Packet to the other endpoint of the socket. - - @param[in] Tcp4Io The Tcp4Io wrapping the TCP socket. - @param[in] Packet The packet to transmit. - - @retval EFI_SUCCESS The packet is trasmitted. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -Tcp4IoTransmit ( - IN TCP4_IO *Tcp4Io, - IN NET_BUF *Packet - ); - -/** - Receive data from the socket. - - @param[in] Tcp4Io The Tcp4Io which wraps the socket to be des= troyed. - @param[in] Packet The buffer to hold the data copy from the s= oket rx buffer. - @param[in] AsyncMode Is this receive asyncronous or not. - @param[in] Timeout The time to wait for receiving the amount o= f data the Packet - can hold. - - @retval EFI_SUCCESS The required amount of data is received fro= m the socket. - @retval EFI_OUT_OF_RESOURCES Failed to allocate momery. - @retval EFI_TIMEOUT Failed to receive the required amount of da= ta in the - specified time period. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -Tcp4IoReceive ( - IN TCP4_IO *Tcp4Io, - IN NET_BUF *Packet, - IN BOOLEAN AsyncMode, - IN EFI_EVENT Timeout - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/Md5.h b/MdeModulePkg/U= niversal/Network/IScsiDxe/Md5.h deleted file mode 100644 index 1541b2d8ece1..000000000000 --- a/MdeModulePkg/Universal/Network/IScsiDxe/Md5.h +++ /dev/null @@ -1,80 +0,0 @@ -/** @file - Header file for Md5. - -Copyright (c) 2004 - 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 IMPLI= ED. - -**/ - -#ifndef _MD5_H_ -#define _MD5_H_ - -#include -#include -#include -#include - -#define MD5_HASHSIZE 16 - -typedef struct _MD5_CTX { - EFI_STATUS Status; - UINT64 Length; - UINT32 States[MD5_HASHSIZE / sizeof (UINT32)]; - UINT8 M[64]; - UINTN Count; -} MD5_CTX; - -/** - Initialize four 32-bits chaining variables and use them to do the Md5 tr= ansform. - - @param[out] Md5Ctx The data structure of Md5. - - @retval EFI_SUCCESS Initialization is ok. -**/ -EFI_STATUS -MD5Init ( - OUT MD5_CTX *Md5Ctx - ); - -/** - the external interface of Md5 algorithm - - @param[in, out] Md5Ctx The data structure of storing the original data - segment and the final result. - @param[in] Data The data wanted to be transformed. - @param[in] DataLen The length of data. - - @retval EFI_SUCCESS The transform is ok. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -MD5Update ( - IN OUT MD5_CTX *Md5Ctx, - IN VOID *Data, - IN UINTN DataLen - ); - -/** - Accumulate the MD5 value of every data segment and generate the finial - result according to MD5 algorithm. - - @param[in, out] Md5Ctx The data structure of storing the original dat= a - segment and the final result. - @param[out] HashVal The final 128-bits output. - - @retval EFI_SUCCESS The transform is ok. - @retval Others Other errors as indicated. -**/ -EFI_STATUS -MD5Final ( - IN OUT MD5_CTX *Md5Ctx, - OUT UINT8 *HashVal - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h b/MdeModuleP= kg/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 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 IMPLI= ED. - -**/ - -#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 receiv= e buffer. - @param RcvdBytes The maximum length of the data can be copi= ed. - @param IsOOB If TRUE the data is OOB, else the data is = 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 receiv= e 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 socket. - - @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 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 IMPLI= ED. - -**/ - -#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_UNCO= NFIGURED) - -/** - 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_CONNECTING) - -/** - 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_DISCONNECTI= NG) - -/** - 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_D= ATA)) - -/** - 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 (Si= ze)) - -/** - 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)->BufS= ize) - -/** - 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 (Si= ze)) - -/** - 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)->BufS= ize) - -/** - 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_S= IGNATURE) - -#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 sock= et -#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 protoco= l -#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_buffer - 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 successfully. - @retval other The error status returned by the correspondin= g 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 is - 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 the - 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 signal= s - the close token. - - @param Sock Pointer to the socket associated with the = closed - connection. - -**/ -VOID -SockConnClosed ( - IN OUT SOCKET *Sock - ); - -/** - Called by low layer protocol to indicate that some data is sent or proce= ssed. - - This function trims the sent data in the socket send buffer, signals the= 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 dat= a. - - @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 laye= r. - - This function will append the data to the socket receive buffer, set the= r - 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 re= ceived - data. - @param UrgLen The length of the urgent data in the recei= ved 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 ch= eck, - 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 occ= urred. - -**/ -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 sock= et - 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 templa= te - ///< wanted to install on socket - - // - // Callbacks after socket is created and before socket is to be destroye= d. - // - SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created - SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied - VOID *Context; ///< The context of the callback - - // - // Opaque protocol data. - // - VOID *ProtoData; - UINT32 DataSize; - - SOCK_PROTO_HANDLER ProtoHandler; ///< The handler of protocol for s= ocket 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 soc= ket - EFI_HANDLE DriverBinding; ///< Socket's driver binding proto= col - 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 data - SOCK_BUFFER RcvBuffer; ///< Receive buffer of received data - EFI_STATUS SockError; ///< The error returned by low layer p= rotocol - BOOLEAN InDestroy; - - // - // Fields used to manage the connection request - // - UINT32 BackLog; ///< the limit of connection to this soc= ket - UINT32 ConnCnt; ///< the current count of connections to= it - SOCKET *Parent; ///< listening parent that accept the co= nnection - LIST_ENTRY ConnectionList; ///< the connections maintained by this = 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 co= nnected - SOCK_COMPLETION_TOKEN *CloseToken; ///< app's token to signal if cl= osed - - // - // Interface for low level protocol - // - SOCK_PROTO_HANDLER ProtoHandler; ///< The request handler of pr= otocol - UINT8 ProtoReserved[PROTO_RESERVED_LEN]; ///< Data fields reserved for = protocol - NET_PROTOCOL NetProtocol; ///< TCP or UDP protocol socke= t used - - // - // Callbacks after socket is created and before socket is to be destroye= d. - // - SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created - SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied - VOID *Context; ///< The context of the callba= ck -}; - -/// -/// The token structure buffered in socket layer. -/// -typedef struct _SOCK_TOKEN { - LIST_ENTRY TokenList; ///< The entry to add in the token= list - SOCK_COMPLETION_TOKEN *Token; ///< The application's token - UINT32 RemainDataLen; ///< Unprocessed data length - SOCKET *Sock; ///< The poninter to the socket th= is 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 oc= cured. - -**/ -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 socket= . - -**/ -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 socket= 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 inita= te the - connection. - @param Token Pointer to the token used for the connectio= n - operation. - - @retval EFI_SUCCESS The connection is initialized successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not conf= igured to - be an active one, or the token is already i= n one of - this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - 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 connections= . - @param Token The token to accept a connection. - - @retval EFI_SUCCESS Either a connection is accpeted or the Toke= n is - buffered for further acception. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not conf= igured to - be a passive one, or the token is already i= n one of - this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - finished. - @retval EFI_NOT_STARTED The socket is not configured. - @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory li= mit. - -**/ -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 token = with - data. - @param Token The token with data that needs to send out. - - @retval EFI_SUCCESS The token is processed successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not in a - synchronized state , or the token is alread= y in one - of this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - finished. - @retval EFI_NOT_STARTED The socket is not configured. - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory li= mit. - -**/ -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 t= he - socket. - - @retval EFI_SUCCESS The token is processed successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not in a - synchronized state , or the token is alread= y in one - of this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - finished. - @retval EFI_NOT_STARTED The socket is not configured. - @retval EFI_CONNECTION_FIN The connection is closed and there is no mo= re data. - @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory li= mit. - -**/ -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 socket= . - -**/ -EFI_STATUS -SockFlush ( - IN SOCKET *Sock - ); - -/** - Close or abort the socket associated connection. - - @param Sock Pointer to the socket of the connection to = close or - abort. - @param Token The token for close operation. - @param OnAbort TRUE for aborting the connection, FALSE to = close it. - - @retval EFI_SUCCESS The close or abort operation is initialized - successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= , or the - socket is closed, or the socket is not in a - synchronized state , or the token is alread= y in one - of this socket's lists. - @retval EFI_NO_MAPPING The IP address configuration operation is n= ot - 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 from= . - @param Mode Pointer to the data to store the low layer = 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 I= P route - table to operate on. - @param RouteInfo Pointer to the route information to be proc= essed. - - @retval EFI_SUCCESS The route table is updated successfully. - @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket= . - @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 e= mpty. - -**/ -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 r= equired - one. - - @return Pointer to the buffer block next to SockEntry. NULL if SockEntry= 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/MdeModul= ePkg/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 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 IMPLI= ED. - -**/ - -#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(), not= 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 instanc= e. - @param Request The code of this operation request. - @param Data Pointer to the operation specific data pa= ssed in - together with the operation request. - - @retval EFI_SUCCESS The socket request is completed successfu= lly. - @retval other The error status returned by the correspo= nding 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 Imag= eHandle. - - @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 su= pports - creating a handle for the specified child device. - - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCO= L instance. - @param ControllerHandle The handle of the controller to test. This = handle - must support a protocol interface that supp= lies - an I/O abstraction to the driver. - @param RemainingDevicePath A pointer to the remaining portion of a dev= ice path. - This parameter is ignored by device drivers= , and is optional for bus drivers. - - - @retval EFI_SUCCESS The device specified by ControllerHandle an= d - RemainingDevicePath is supported by the dri= ver - specified by This. - @retval EFI_ALREADY_STARTED The device specified by ControllerHandle an= d - RemainingDevicePath is already being manage= d by - the driver specified by This. - @retval EFI_ACCESS_DENIED The device specified by ControllerHandle an= d - RemainingDevicePath is already being manage= d by a - different driver or an application that req= uires - exclusive access. - @retval EFI_UNSUPPORTED The device specified by ControllerHandle an= d - RemainingDevicePath is not supported by the= 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 service - ConnectController(). As a result, much of the error checking on the para= meters - to Start() has been moved into this common boot service. It is legal to = call - Start() from other locations, but the following calling restrictions mus= t 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 na= turally - aligned EFI_DEVICE_PATH_PROTOCOL. - 3. Prior to calling Start(), the Supported() function for the driver spe= cified - by This must have been called with the same calling parameters, and S= upported() - must have returned EFI_SUCCESS. - - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCO= L instance. - @param ControllerHandle The handle of the controller to start. This= handle - must support a protocol interface that supp= lies - an I/O abstraction to the driver. - @param RemainingDevicePath A pointer to the remaining portion of a dev= ice path. - This parameter is ignored by device drivers= , 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 de= vice 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 service - DisconnectController(). As a result, much of the error checking on the p= arameters - to Stop() has been moved into this common boot service. It is legal to c= all Stop() - from other locations, but the following calling restrictions must be fol= lowed - or the system behavior will not be deterministic. - 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previo= us 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 created = in this - driver's Start() function, and the Start() function must have called = OpenProtocol() - on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_C= ONTROLLER. - - @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL i= nstance. - @param ControllerHandle A handle to the device being stopped. The hand= le must - support a bus specific I/O protocol for the dr= iver - to use to stop the device. - @param NumberOfChildren The number of child device handles in ChildHan= dleBuffer. - @param ChildHandleBuffer An array of child handles to be freed. May be = 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 devic= e 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 i= n - 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 soc= ket 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 ChildH= andle - is a pointer to NULL, then a new handle is created and returned in Child= Handle. - If ChildHandle is not a pointer to NULL, then the protocol installs on t= he existing - ChildHandle. - - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance= . - @param ChildHandle Pointer to the handle of the child to create. If it = is NULL, then - a new handle is created. If it is a pointer to an ex= isting UEFI - handle, then the protocol is added to the existing U= EFI 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 t= o 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 remov= es a protocol - that was installed by CreateChild() from ChildHandle. If the removed pro= tocol is the - last protocol on ChildHandle, then ChildHandle is destroyed. - - @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instanc= e. - @param ChildHandle Handle of the child to destroy - - @retval EFI_SUCCES The protocol was removed from ChildHandle. - @retval EFI_UNSUPPORTED ChildHandle does not support the protocol = that is - being removed. - @retval EFI_INVALID_PARAMETER Child handle is NULL. - @retval EFI_ACCESS_DENIED The protocol could not be removed from the= 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/MdeModule= Pkg/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 P= rotocol. -# -# This module produces EFI TCPv4(Transmission Control Protocol version 4)= Protocol -# upon EFI IPv4 Protocol, to provide basic TCPv4 I/O services. This drive= r 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 TcpDx= e driver -# in NetworkPkg. -# 3) This driver supports fewer features than the TcpDxe driver in Networ= kPkg (e.g. IPv6, -# TCP Cancel function). -# 4) TcpDxe driver in NetworkPkg is recommended for use instead of this o= ne 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 B= SD 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 IM= PLIED. -# -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D Tcp4Dxe - MODULE_UNI_FILE =3D Tcp4Dxe.uni - FILE_GUID =3D 6d6963ab-906d-4a65-a7ca-bd40e5d6af4d - 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 the = 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/MdeModule= Pkg/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 P= rotocol. -// -// 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 B= SD 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 IM= PLIED. -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "Produces EFI TCPv= 4 Protocol and EFI TCPv4 Service Binding Protocol" - -#string STR_MODULE_DESCRIPTION #language en-US "This module produ= ces EFI TCPv4(Transmission Control Protocol version 4) Protocol upon EFI IP= v4 Protocol to provide basic TCPv4 I/O services." - diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4DxeExtra.uni b/MdeM= odulePkg/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 B= SD 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 IM= PLIED. -// -// **/ - -#string STR_PROPERTIES_MODULE_NAME -#language en-US -"TCP v4 DXE Driver" - - diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h b/MdeModuleP= kg/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 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 IMPLI= ED. - -**/ - -#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 T= RUE, 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 occur= red. - -**/ -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 instance= . - -**/ -VOID -TcpInitTcbLocal ( - IN OUT TCP_CB *Tcb - ); - -/** - Initialize the peer related members. - - @param Tcb Pointer to the TCP_CB of this TCP instance= . - @param Seg Pointer to the segment that contains the p= eer's - intial info. - @param Opt Pointer to the options announced by the pe= er. - -**/ -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 instance= . - @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 a= nd 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 p= robe. - - @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 t= he - 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 NULL. - @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 a= nd 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 packet. - @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 he= ader. - @param Src Source address of the segment, or the peer's IP address= . - @param Dst Destination address of the segment, or the local end's = IP - address. - - @retval 0 Segment is processed successfully. It is either accepte= d 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 acceptable. - - @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 segm= ent. - -**/ -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 queued. - -**/ -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 segment= . - -**/ -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 TC= P - segment. - @param HeadSum The checksum value of the fixed part of ps= eudo - 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 instance= . - @param Nbuf Pointer to the buffer contains the TCP seg= ment. - - @return Pointer to the TCP_SEG that contains the translated TCP head in= formation. - -**/ -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 initia= te 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 instance= . - -**/ -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 instance= . - -**/ -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 instance= . - - @retval 0 Whether the data is sent out or is buffere= d for - further sending. - @retval -1 The Tcb is not in a state that data is per= mitted 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 instance. - -**/ -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 inst= ance. - - @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/MdeModuleP= kg/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 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 IMPLI= ED. - -**/ - -#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 instanc= e. - @param Request The code of this operation request. - @param Data Pointer to the operation specific data pa= ssed in - together with the operation request. - - @retval EFI_SUCCESS The socket request is completed successfu= lly. - @retval other The error status returned by the correspo= nding 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 th= is - EFI TCPv4 Protocol instance into user-supplied buffers. This function ca= n - 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 instan= ce. - @param Tcp4State Pointer to the buffer to receive the cu= rrent TCP - state. - @param Tcp4ConfigData Pointer to the buffer to receive the cu= rrent TCP - configuration. - @param Ip4ModeData Pointer to the buffer to receive the cu= rrent IPv4 - configuration data used by the TCPv4 in= stance. - @param MnpConfigData Pointer to the buffer to receive the cu= rrent MNP - configuration data indirectly used by t= he TCPv4 - Instance. - @param SnpModeData Pointer to the buffer to receive the cu= rrent SNP - configuration data indirectly used by t= he TCPv4 - Instance. - - @retval EFI_SUCCESS The mode data was read. - @retval EFI_NOT_STARTED No configuration data is available beca= use 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 communication= end - setting, specify active open or passive open for an instance. - * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchron= ous - tokens, flush transmission and receiving buffer directly without informi= ng - 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 pr= oper - configuration it may call Connect() to initiates the three-way handshake= . - For a passive TCP4 instance, its state will transit to Tcp4StateListen a= fter - configuration, and Accept() may be called to listen the incoming TCP con= nection - request. If TcpConfigData is set to NULL, the instance is reset. Resetti= ng - process will be done brutally, the state machine will be set to Tcp4Stat= eClosed - directly, the receive queue and transmit queue will be flushed, and no t= raffic is - allowed through this instance. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param TcpConfigData Pointer to the configure data to config= ure the - instance. - - @retval EFI_SUCCESS The operational settings are set, chang= ed, or - reset successfully. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (through DHCP, BOOTP, RARP, etc.) is no= t - finished. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_ACCESS_DENIED Configuring TCP instance when it is alr= eady - configured. - @retval EFI_DEVICE_ERROR An unexpected network or system error o= ccurred. - @retval EFI_UNSUPPORTED One or more of the control options are = not - supported in the implementation. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resour= ces. - -**/ -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 routin= g table. - The most specific route is selected by comparing the SubnetAddress with = 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 mo= re specific route. - Direct route is added with GatewayAddress set to 0.0.0.0. Packets are se= nt to - the destination host if its address can be found in the Address Resoluti= on Protocol (ARP) - cache or it is on the local subnet. If the instance is configured to use= default - address, a direct route to the local network will be added automatically= . - Each TCP instance has its own independent routing table. Instance that u= ses the - default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's rou= ting table. - The copy will be updated automatically whenever the IP driver reconfigur= es its - instance. As a result, the previous modification to the instance's local= copy - will be lost. The priority of checking the route table is specific with = IP - implementation and every IP implementation must comply with RFC 1122. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param DeleteRoute If TRUE, delete the specified route fro= m routing - table; if FALSE, add the specified rout= e to - routing table. - DestinationAddress and SubnetMask are u= sed as - the keywords to search route entry. - @param SubnetAddress The destination network. - @param SubnetMask The subnet mask for the destination net= work. - @param GatewayAddress The gateway address for this route. - It must be on the same subnet with the = station - address unless a direct route is specif= ied. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not = been - configured. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (through DHCP, BOOTP, RARP, etc.) is no= t - finished. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to = add the - entry to the routing table. - @retval EFI_NOT_FOUND This route is not in the routing table. - @retval EFI_ACCESS_DENIED This route is already in the routing ta= ble. - @retval EFI_UNSUPPORTED The TCP driver does not support this op= eration. - -**/ -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 instance= . - - The Connect() function will initiate an active open to the remote peer c= onfigured - in current TCP instance if it is configured active. If the connection su= cceeds - or fails due to any error, the ConnectionToken->CompletionToken.Event wi= ll be - signaled and ConnectionToken->CompletionToken.Status will be updated acc= ordingly. - This function can only be called for the TCP instance in Tcp4StateClosed= state. - The instance will transfer into Tcp4StateSynSent if the function returns= EFI_SUCCESS. - If TCP three way handshake succeeds, its state will become Tcp4StateEsta= blished, - otherwise, the state will return to Tcp4StateClosed. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce - @param ConnectionToken Pointer to the connection token to retu= rn when - the TCP three way handshake finishes. - - @retval EFI_SUCCESS The connection request is successfully = initiated - and the state of this TCPv4 instance ha= s - 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 ac= tive 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 resour= ce to - initiate the active open. - @retval EFI_DEVICE_ERROR An unexpected system or network error o= ccurred. - -**/ -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 request. - - The Accept() function initiates an asynchronous accept request to wait f= or an - incoming connection on the passive TCP instance. If a remote peer succes= sfully - establishes a connection with this instance, a new TCP instance will be = created - and its handle will be returned in ListenToken->NewChildHandle. The newl= y created - instance is configured by inheriting the passive instance's configuratio= n and is - ready for use upon return. The instance is in the Tcp4StateEstablished s= tate. - The ListenToken->CompletionToken.Event will be signaled when a new conne= ction - is accepted, user aborts the listen or connection is reset. This functio= n only - can be called when current TCP instance is in Tcp4StateListen state. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce - @param ListenToken Pointer to the listen token to return w= hen - operation finishes. - - @retval EFI_SUCCESS The listen token has been queued succes= sfully. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_ACCESS_DENIED The instatnce is not a passive one or i= t is not - in Tcp4StateListen state or a same list= en token - has already existed in the listen token= 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 to = finish - the operation. - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to abov= e 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 instance = along - with the user data. The status of the token is updated and the event in = the token - will be signaled once the data is sent out or some error occurs. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce - @param Token Pointer to the completion token to queu= e to the - transmit queue - - @retval EFI_SUCCESS The data has been queued for transmissi= on. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (DHCP, BOOTP, RARP, etc.) is not finish= ed yet. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_ACCESS_DENIED One or more of the following conditions= is TRUE: - * A transmit completion token with the = same - Token-> CompletionToken.Event was alr= eady in the - transmission queue. - * The current instance is in Tcp4StateC= losed state - * The current instance is a passive one= and - it is in Tcp4StateListen state. - * User has called Close() to disconnect= this - connection. - @retval EFI_NOT_READY The completion token could not be queue= d because - the transmit queue is full. - @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data becau= se of - resource shortage. - @retval EFI_NETWORK_UNREACHABLE There is no route to the destination ne= twork 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 packet= queue. - This function is always asynchronous. The caller must allocate the - Token->CompletionToken.Event and the FragmentBuffer used to receive data= . He also - must fill the DataLength which represents the whole length of all Fragme= ntBuffer. - When the receive operation completes, the EFI TCPv4 Protocol driver upda= tes the - Token->CompletionToken.Status and Token->Packet.RxData fields and the - Token->CompletionToken.Event is signaled. If got data the data and its l= ength - 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 notif= ication - function and context for the event will enable the user to receive the n= otification - and receiving status. That notification function is guaranteed to not be= re-entered. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param Token Pointer to a token that is associated w= ith the - receive data descriptor. - - @retval EFI_SUCCESS The receive completion token was cached= . - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_NO_MAPPING When using a default address, configura= tion - (DHCP, BOOTP, RARP, etc.) is not finish= ed yet. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The receive completion token could not = be queued - due to a lack of system resources. - @retval EFI_DEVICE_ERROR An unexpected system or network error o= ccurred. - The EFI TCPv4 Protocol instance has bee= n reset - to startup defaults. - @retval EFI_ACCESS_DENIED One or more of the following conditions= is TRUE: - * A receive completion token with the s= ame - Token->CompletionToken.Event was alre= ady in - the receive queue. - * The current instance is in Tcp4StateC= losed state. - * The current instance is a passive one= and it - is in Tcp4StateListen state. - * User has called Close() to disconnect= this - connection. - @retval EFI_CONNECTION_FIN The communication peer has closed the c= onnection - and there is no any buffered data in th= e receive - buffer of this instance. - @retval EFI_NOT_READY The receive request could not be queued= 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 cal= led, - any buffered transmission data will be sent by TCP driver and the curren= t - 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 T= CP - driver to fast disconnect this connection. When the close operation comp= letes - successfully the TCP instance is in Tcp4StateClosed state, all pending - asynchronous operation is signaled and any buffers used for TCP network = traffic - is flushed. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - @param CloseToken Pointer to the close token to return wh= en - operation finishes. - - @retval EFI_SUCCESS The operation completed successfully. - @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't b= een - configured. - @retval EFI_ACCESS_DENIED One or more of the following are TRUE: - * Configure() has been called with TcpC= onfigData - set to NULL and this function has not= returned. - * Previous Close() call on this instanc= e has not - finished. - @retval EFI_INVALID_PARAMETER One ore more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to f= inish the - operation. - @retval EFI_DEVICE_ERROR Any unexpected and not belonged to abov= e - 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 reques= t. - - The Cancel() function aborts a pending connection, listen, transmit or r= eceive - request. If Token is not NULL and the token is in the connection, listen= , - transmission or receive queue when it is being cancelled, its Token->Sta= tus - will be set to EFI_ABORTED and then Token->Event will be signaled. If th= e token - is not in one of the queues, which usually means that the asynchronous o= peration - has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchron= ous 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 instan= ce. - @param Token Pointer to a token that has been issued= by - Connect(), Accept(), Transmit() or Rece= ive(). If - NULL, all pending tokens issued by abov= e four - functions will be aborted. - - @retval EFI_SUCCESS The asynchronous I/O request is aborted= 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, configu= ration - (DHCP, BOOTP,RARP, etc.) hasn's finishe= d yet. - @retval EFI_NOT_FOUND The asynchronous I/O request isn's foun= d in the - transmission or receive queue. It has e= ither - completed or wasn's issued by Transmit(= ) and Receive(). - @retval EFI_UNSUPPORTED The operation is not supported in curre= nt - 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 ne= twork - and application and can be called when the TCP instance is created succe= ssfully. - Its use is optional. In some implementations, the periodical timer in th= e MNP - driver may not poll the underlying communications device fast enough to = avoid - drop packets. Drivers and applications that are experiencing packet loss= should - try calling the Poll() function in a high frequency. - - @param This Pointer to the EFI_TCP4_PROTOCOL instan= ce. - - @retval EFI_SUCCESS Incoming or outgoing data was processed= . - @retval EFI_INVALID_PARAMETER This is NULL. - @retval EFI_DEVICE_ERROR An unexpected system or network error o= ccurred. - @retval EFI_NOT_READY No incoming or outgoing data was proces= sed. - @retval EFI_TIMEOUT Data was dropped out of the transmissio= n or - receive queue. Consider increasing the = polling - rate. - -**/ -EFI_STATUS -EFIAPI -Tcp4Poll ( - IN EFI_TCP4_PROTOCOL *This - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Option.h b/MdeModul= ePkg/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 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 IMPLI= ED. - -**/ - -#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, ali= gned - -// -// 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 value -#define TCP_OPTION_MAX_WIN 0xffff ///< Max window size in TCP hea= der - - -/** - 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 successfully= 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/MdeModule= Pkg/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 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 IMPLI= ED. - -**/ - -#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 recovery -#define TCP_CONGEST_LOSS 2 ///< Retxmit because of retxmit time o= ut -#define TCP_CONGEST_OPEN 3 ///< TCP is opening its congestion win= dow - -// -// 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 i= n syn -#define TCP_CTRL_NO_TS 0x0010 ///< Disable Timestamp option -#define TCP_CTRL_RCVD_TS 0x0020 ///< Received a Timestamp option i= n syn -#define TCP_CTRL_SND_TS 0x0040 ///< Send Timestamp option to remo= te -#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 is = on -#define TCP_CTRL_RTT_ON 0x2000 ///< The RTT measurement is on -#define TCP_CTRL_ACK_NOW 0x4000 ///< Send the ACK now, don't delay - -// -// Timer related values -// -#define TCP_TIMER_CONNECT 0 ///< Connection establ= ishment timer -#define TCP_TIMER_REXMIT 1 ///< Retransmit timer -#define TCP_TIMER_PROBE 2 ///< Window probe time= r -#define TCP_TIMER_KEEPALIVE 3 ///< Keepalive timer -#define TCP_TIMER_FINWAIT2 4 ///< FIN_WAIT_2 timer -#define TCP_TIMER_2MSL 5 ///< TIME_WAIT tiemr -#define TCP_TIMER_NUMBER 6 ///< The total number = of TCP timer. -#define TCP_TICK 200 ///< Every TCP tick is= 200ms -#define TCP_TICK_HZ 5 ///< The frequence of = TCP tick -#define TCP_RTT_SHIFT 3 ///< SRTT & RTTVAR sca= led by 8 -#define TCP_RTO_MIN TCP_TICK_HZ ///< The minium value = of RTO -#define TCP_RTO_MAX (TCP_TICK_HZ * 60) ///< The maxium value = of RTO -#define TCP_FOLD_RTT 4 ///< Timeout threshod = to fold RTT - -// -// Default values for some timers -// -#define TCP_MAX_LOSS 12 ///< Default = max times to retxmit -#define TCP_KEEPALIVE_IDLE_MIN (TCP_TICK_HZ * 60 * 60 * 2) ///< First ke= ep 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/FIN.= 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_CONNECT_= 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 pesudo - ///< 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 peer - UINT32 SndWndMax; ///< Max send window advertised by the pee= r - TCP_SEQNO SndWl1; ///< Seq number used for last window updat= e - 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 up= date. - ///< It is necessary because of delayed AC= K - - TCP_SEQNO RcvUp; ///< Urgent point; - TCP_SEQNO Irs; ///< Initial Receiving Sequen= ce - UINT16 RcvMss; ///< Max receive segment size - UINT16 EnabledTimer; ///< Which timer is currently= enabled - UINT32 Timer[TCP_TIMER_NUMBER]; ///< When the timer will expi= re - INT32 NextExpire; ///< Count down offset for the nearest ti= mer - UINT32 Idle; ///< How long the connection is in idle - UINT32 ProbeTime; ///< The time out value for current windo= w 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 buffer - UINT32 TsRecent; ///< TsRecent to echo to the remote peer - 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 beats - 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(RFC378= 2) - UINT8 LossTimes; ///< Number of retxmit timeouts in a row - TCP_SEQNO LossRecover; ///< Recover point for retxmit - - // - // configuration parameters, for EFI_TCP4_PROTOCOL specification - // - UINT32 KeepAliveIdle; ///< Idle time before sending first p= robe - UINT32 KeepAlivePeriod; ///< Interval for subsequent keep ali= ve probe - UINT8 MaxKeepAlive; ///< Maxium keep alive probe times. - UINT8 KeepAliveProbes; ///< The number of keep alive probe. - UINT16 MaxRexmit; ///< The maxium number of retxmit bef= ore abort - UINT32 FinWait2Timeout; ///< The FIN_WAIT_2 time out - UINT32 TimeWaitTimeout; ///< The TIME_WAIT time out - UINT32 ConnectTimeout; ///< The connect establishment time o= ut - - // - // RFC7323 - // Addressing Window Retraction for TCP Window Scale Option. - // - TCP_SEQNO RetxmitSeqMax; ///< Max Seq number in previous r= etransmission. - - // - // configuration for tcp provided by user - // - BOOLEAN UseDefaultAddr; - UINT8 Tos; - UINT8 Ttl; - EFI_IPv4_ADDRESS SubnetMask; - - IP_IO_IP_INFO *IpInfo; /// 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 diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h b/MdeM= odulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h deleted file mode 100644 index d8336c5e82e9..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.h +++ /dev/null @@ -1,502 +0,0 @@ -/** @file - Dhcp and Discover routines for PxeBc. - -Copyright (c) 2013, Red Hat, Inc. -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - -#ifndef __EFI_PXEBC_DHCP_H__ -#define __EFI_PXEBC_DHCP_H__ - -#define PXEBC_DHCP4_MAX_OPTION_NUM 16 -#define PXEBC_DHCP4_MAX_OPTION_SIZE 312 -#define PXEBC_DHCP4_MAX_PACKET_SIZE (sizeof (EFI_PXE_BASE_CODE_PACK= ET)) - -#define PXEBC_DHCP4_S_PORT 67 -#define PXEBC_DHCP4_C_PORT 68 -#define PXEBC_BS_DOWNLOAD_PORT 69 -#define PXEBC_BS_DISCOVER_PORT 4011 - -#define PXEBC_DHCP4_OPCODE_REQUEST 1 -#define PXEBC_DHCP4_OPCODE_REPLY 2 -#define PXEBC_DHCP4_MSG_TYPE_REQUEST 3 -#define PXEBC_DHCP4_MAGIC 0x63538263 // network byte orde= r - -// -// Sub-Options in Dhcp Vendor Option -// -#define PXEBC_VENDOR_TAG_MTFTP_IP 1 -#define PXEBC_VENDOR_TAG_MTFTP_CPORT 2 -#define PXEBC_VENDOR_TAG_MTFTP_SPORT 3 -#define PXEBC_VENDOR_TAG_MTFTP_TIMEOUT 4 -#define PXEBC_VENDOR_TAG_MTFTP_DELAY 5 -#define PXEBC_VENDOR_TAG_DISCOVER_CTRL 6 -#define PXEBC_VENDOR_TAG_DISCOVER_MCAST 7 -#define PXEBC_VENDOR_TAG_BOOT_SERVERS 8 -#define PXEBC_VENDOR_TAG_BOOT_MENU 9 -#define PXEBC_VENDOR_TAG_MENU_PROMPT 10 -#define PXEBC_VENDOR_TAG_MCAST_ALLOC 11 -#define PXEBC_VENDOR_TAG_CREDENTIAL_TYPES 12 -#define PXEBC_VENDOR_TAG_BOOT_ITEM 71 - -#define PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT 4 -#define PXEBC_DHCP4_DISCOVER_RETRIES 4 - -#define PXEBC_MAX_MENU_NUM 24 -#define PXEBC_MAX_OFFER_NUM 16 - -#define PXEBC_BOOT_REQUEST_TIMEOUT 1 -#define PXEBC_BOOT_REQUEST_RETRIES 4 - -#define PXEBC_DHCP4_OVERLOAD_FILE 1 -#define PXEBC_DHCP4_OVERLOAD_SERVER_NAME 2 - -// -// The array index of the DHCP4 option tag interested -// -#define PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN 0 -#define PXEBC_DHCP4_TAG_INDEX_VENDOR 1 -#define PXEBC_DHCP4_TAG_INDEX_OVERLOAD 2 -#define PXEBC_DHCP4_TAG_INDEX_MSG_TYPE 3 -#define PXEBC_DHCP4_TAG_INDEX_SERVER_ID 4 -#define PXEBC_DHCP4_TAG_INDEX_CLASS_ID 5 -#define PXEBC_DHCP4_TAG_INDEX_BOOTFILE 6 -#define PXEBC_DHCP4_TAG_INDEX_MAX 7 - -// -// The type of DHCP OFFER, arranged by priority, PXE10 has the highest pri= ority. -// -#define DHCP4_PACKET_TYPE_PXE10 0 -#define DHCP4_PACKET_TYPE_WFM11A 1 -#define DHCP4_PACKET_TYPE_BINL 2 -#define DHCP4_PACKET_TYPE_DHCP_ONLY 3 -#define DHCP4_PACKET_TYPE_BOOTP 4 -#define DHCP4_PACKET_TYPE_MAX 5 - -#define BIT(x) (1 << x) -#define CTRL(x) (0x1F & (x)) - -// -// WfM11a options -// -#define MTFTP_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_MTFTP_IP) | \ - BIT (PXEBC_VENDOR_TAG_MTFTP_CPORT) | = \ - BIT (PXEBC_VENDOR_TAG_MTFTP_SPORT) | = \ - BIT (PXEBC_VENDOR_TAG_MTFTP_TIMEOUT) = | \ - BIT (PXEBC_VENDOR_TAG_MTFTP_DELAY)) -// -// Discoverty options -// -#define DISCOVER_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_DISCOVER_CT= RL) | \ - BIT (PXEBC_VENDOR_TAG_DISCOVER_MC= AST) | \ - BIT (PXEBC_VENDOR_TAG_BOOT_SERVER= S) | \ - BIT (PXEBC_VENDOR_TAG_BOOT_MENU) = | \ - BIT (PXEBC_VENDOR_TAG_MENU_PROMPT= )) - -#define IS_VALID_BOOT_PROMPT(x) \ - ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_MENU_PROMPT)) =3D=3D BIT (PXEBC_VENDO= R_TAG_MENU_PROMPT)) - -#define IS_VALID_BOOT_MENU(x) \ - ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_MENU)) =3D=3D BIT (PXEBC_VENDOR_= TAG_BOOT_MENU)) - -#define IS_VALID_MTFTP_VENDOR_OPTION(x) \ - (((UINT32) ((x)[0]) & MTFTP_VENDOR_OPTION_BIT_MAP) =3D=3D MTFTP_VENDOR= _OPTION_BIT_MAP) - -#define IS_VALID_DISCOVER_VENDOR_OPTION(x) (((UINT32) ((x)[0]) & DISCOVER= _VENDOR_OPTION_BIT_MAP) !=3D 0) - -#define IS_VALID_CREDENTIAL_VENDOR_OPTION(x) \ - (((UINT32) ((x)[0]) & BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) =3D=3D = BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) - -#define IS_VALID_BOOTITEM_VENDOR_OPTION(x) \ - (((UINT32) ((x)[PXEBC_VENDOR_TAG_BOOT_ITEM / 32]) & BIT (PXEBC_VENDOR_= TAG_BOOT_ITEM % 32)) \ - =3D=3D BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32)) - -#define IS_DISABLE_BCAST_DISCOVER(x) (((x) & BIT (0)) =3D=3D BIT (0)) -#define IS_DISABLE_MCAST_DISCOVER(x) (((x) & BIT (1)) =3D=3D BIT (1)) -#define IS_ENABLE_USE_SERVER_LIST(x) (((x) & BIT (2)) =3D=3D BIT (2)) -#define IS_DISABLE_PROMPT_MENU(x) (((x) & BIT (3)) =3D=3D BIT (3)) - -#define SET_VENDOR_OPTION_BIT_MAP(x, y) (((x)[(y) / 32]) =3D (UINT32) ((x)= [(y) / 32]) | BIT ((y) % 32)) - -#pragma pack(1) -typedef struct { - UINT8 ParaList[135]; -} PXEBC_DHCP4_OPTION_PARA; - -typedef struct { - UINT16 Size; -} PXEBC_DHCP4_OPTION_MAX_MESG_SIZE; - -typedef struct { - UINT8 Type; - UINT8 MajorVer; - UINT8 MinorVer; -} PXEBC_DHCP4_OPTION_UNDI; - -typedef struct { - UINT8 Type; -} PXEBC_DHCP4_OPTION_MESG; - -typedef struct { - UINT16 Type; -} PXEBC_DHCP4_OPTION_ARCH; - -#define DEFAULT_CLASS_ID_DATA "PXEClient:Arch:xxxxx:UNDI:003000" -#define DEFAULT_UNDI_TYPE 1 -#define DEFAULT_UNDI_MAJOR 3 -#define DEFAULT_UNDI_MINOR 0 - -typedef struct { - UINT8 ClassIdentifier[10]; - UINT8 ArchitecturePrefix[5]; - UINT8 ArchitectureType[5]; - UINT8 Lit3[1]; - UINT8 InterfaceName[4]; - UINT8 Lit4[1]; - UINT8 UndiMajor[3]; - UINT8 UndiMinor[3]; -} PXEBC_DHCP4_OPTION_CLID; - -typedef struct { - UINT8 Type; - UINT8 Guid[16]; -} PXEBC_DHCP4_OPTION_UUID; - -typedef struct { - UINT16 Type; - UINT16 Layer; -} PXEBC_OPTION_BOOT_ITEM; - -#pragma pack() - -typedef union { - PXEBC_DHCP4_OPTION_PARA *Para; - PXEBC_DHCP4_OPTION_UNDI *Undi; - PXEBC_DHCP4_OPTION_ARCH *Arch; - PXEBC_DHCP4_OPTION_CLID *Clid; - PXEBC_DHCP4_OPTION_UUID *Uuid; - PXEBC_DHCP4_OPTION_MESG *Mesg; - PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize; -} PXEBC_DHCP4_OPTION_ENTRY; - -typedef struct { - UINT16 Type; - UINT8 IpCnt; - EFI_IPv4_ADDRESS IpAddr[1]; -} PXEBC_BOOT_SVR_ENTRY; - -typedef struct { - UINT16 Type; - UINT8 DescLen; - UINT8 DescStr[1]; -} PXEBC_BOOT_MENU_ENTRY; - -typedef struct { - UINT8 Timeout; - UINT8 Prompt[1]; -} PXEBC_MENU_PROMPT; - -typedef struct { - UINT32 BitMap[8]; - EFI_IPv4_ADDRESS MtftpIp; - UINT16 MtftpCPort; - UINT16 MtftpSPort; - UINT8 MtftpTimeout; - UINT8 MtftpDelay; - UINT8 DiscoverCtrl; - EFI_IPv4_ADDRESS DiscoverMcastIp; - EFI_IPv4_ADDRESS McastIpBase; - UINT16 McastIpBlock; - UINT16 McastIpRange; - UINT16 BootSrvType; - UINT16 BootSrvLayer; - PXEBC_BOOT_SVR_ENTRY *BootSvr; - UINT8 BootSvrLen; - PXEBC_BOOT_MENU_ENTRY *BootMenu; - UINT8 BootMenuLen; - PXEBC_MENU_PROMPT *MenuPrompt; - UINT8 MenuPromptLen; - UINT32 *CredType; - UINT8 CredTypeLen; -} PXEBC_VENDOR_OPTION; - -#define PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE (OFFSET_OF (EFI_DHCP4_PACKET, = Dhcp4) + PXEBC_DHCP4_MAX_PACKET_SIZE) - -typedef union { - EFI_DHCP4_PACKET Offer; - EFI_DHCP4_PACKET Ack; - UINT8 Buffer[PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE]; -} PXEBC_DHCP4_PACKET; - -typedef struct { - PXEBC_DHCP4_PACKET Packet; - BOOLEAN IsPxeOffer; - UINT8 OfferType; - EFI_DHCP4_PACKET_OPTION *Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_MAX]; - PXEBC_VENDOR_OPTION PxeVendorOption; -} PXEBC_CACHED_DHCP4_PACKET; - -#define GET_NEXT_DHCP_OPTION(Opt) \ - (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + sizeof (EFI_DHCP4_PACKET_= OPTION) + (Opt)->Length - 1) - -#define GET_OPTION_BUFFER_LEN(Pkt) ((Pkt)->Length - sizeof (EFI_DHCP4_HEA= DER) - 4) -#define IS_PROXY_DHCP_OFFER(Offer) EFI_IP4_EQUAL (&((Offer)->Dhcp4.Header= .YourAddr), &mZeroIp4Addr) - -#define GET_NEXT_BOOT_SVR_ENTRY(Ent) \ - (PXEBC_BOOT_SVR_ENTRY *) ((UINT8 *) Ent + sizeof (*(Ent)) + ((Ent)->IpCn= t - 1) * sizeof (EFI_IPv4_ADDRESS)) - - -/** - This function initialize the DHCP4 message instance. - - This function will pad each item of dhcp4 message packet. - - @param Seed Pointer to the message instance of the DHCP4 packet. - @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance. - -**/ -VOID -PxeBcInitSeedPacket ( - IN EFI_DHCP4_PACKET *Seed, - IN EFI_UDP4_PROTOCOL *Udp4 - ); - - -/** - Parse the cached dhcp packet. - - @param CachedPacket Pointer to cached dhcp packet. - - @retval TRUE Succeed to parse and validation. - @retval FALSE Fail to parse or validation. - -**/ -BOOLEAN -PxeBcParseCachedDhcpPacket ( - IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket - ); - -/** - This function is to check the selected proxy offer (include BINL dhcp of= fer and - DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe = base code - mode structure. - - @param Private Pointer to PxeBc private data. - - @retval EFI_SUCCESS Operational successful. - @retval EFI_NO_RESPONSE Offer dhcp service failed. - @retval EFI_BUFFER_TOO_SMALL Failed to copy the packet to Pxe base= code mode. - -**/ -EFI_STATUS -PxeBcCheckSelectedOffer ( - IN PXEBC_PRIVATE_DATA *Private - ); - - -/** - Callback routine. - - EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protoco= l driver - to intercept events that occurred in the configuration process. This str= ucture - provides advanced control of each state transition of the DHCP process. = The - returned status code determines the behavior of the EFI DHCPv4 Protocol = driver. - There are three possible returned values, which are described in the fol= lowing - table. - - @param This Pointer to the EFI DHCPv4 Protocol instanc= e that is used to - configure this callback function. - @param Context Pointer to the context that is initialized= by - EFI_DHCP4_PROTOCOL.Configure(). - @param CurrentState The current operational state of the EFI D= HCPv4 Protocol - driver. - @param Dhcp4Event The event that occurs in the current state= , which usually means a - state transition. - @param Packet The DHCP packet that is going to be sent o= r already received. - @param NewPacket The packet that is used to replace the abo= ve Packet. - - @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to co= ntinue the DHCP process. - @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The= EFI DHCPv4 Protocol - driver will continue to wait for more DHCP= OFFER packets until the retry - timeout expires. - @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to ab= ort the current process and - return to the Dhcp4Init or Dhcp4InitReboot= state. - -**/ -EFI_STATUS -EFIAPI -PxeBcDhcpCallBack ( - IN EFI_DHCP4_PROTOCOL * This, - IN VOID *Context, - IN EFI_DHCP4_STATE CurrentState, - IN EFI_DHCP4_EVENT Dhcp4Event, - IN EFI_DHCP4_PACKET * Packet OPTIONAL, - OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL - ); - -/** - Switch the Ip4 policy to static. - - @param[in] Private The pointer to PXEBC_PRIVATE_DATA. - - @retval EFI_SUCCESS The policy is already configured to stat= ic. - @retval Others Other error as indicated.. - -**/ -EFI_STATUS -PxeBcSetIp4Policy ( - IN PXEBC_PRIVATE_DATA *Private - ); - -/** - Discover the boot of service and initialize the vendor option if exists. - - @param Private Pointer to PxeBc private data. - @param Type PxeBc option boot item type - @param Layer PxeBc option boot item layer - @param UseBis Use BIS or not - @param DestIp Ip address for server - @param IpCount The total count of the server ip address - @param SrvList Server list - @param IsDiscv Discover the vendor or not - @param Reply The dhcp4 packet of Pxe reply - - @retval EFI_SUCCESS Operation succeeds. - @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed. - @retval EFI_NOT_FOUND There is no vendor option exists. - @retval EFI_TIMEOUT Send Pxe Discover time out. - -**/ -EFI_STATUS -PxeBcDiscvBootService ( - IN PXEBC_PRIVATE_DATA * Private, - IN UINT16 Type, - IN UINT16 *Layer, - IN BOOLEAN UseBis, - IN EFI_IP_ADDRESS * DestIp, - IN UINT16 IpCount, - IN EFI_PXE_BASE_CODE_SRVLIST * SrvList, - IN BOOLEAN IsDiscv, - OUT EFI_DHCP4_PACKET * Reply OPTIONAL - ); - - -/** - Initialize the DHCP options and build the option list. - - @param Private Pointer to PxeBc private data. - @param OptList Pointer to a DHCP option list. - - @param IsDhcpDiscover Discover dhcp option or not. - - @return The index item number of the option list. - -**/ -UINT32 -PxeBcBuildDhcpOptions ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_DHCP4_PACKET_OPTION **OptList, - IN BOOLEAN IsDhcpDiscover - ); - - -/** - Create the boot options. - - @param OptList Pointer to the list of the options - @param Type the type of option - @param Layer the layer of the boot options - @param OptLen length of opotion - -**/ -VOID -PxeBcCreateBootOptions ( - IN EFI_DHCP4_PACKET_OPTION *OptList, - IN UINT16 Type, - IN UINT16 *Layer, - OUT UINT32 *OptLen - ); - - -/** - Parse interested dhcp options. - - @param Buffer Pointer to the dhcp options packet. - @param Length The length of the dhcp options. - @param OptTag The option OpCode. - - @return NULL if the buffer length is 0 and OpCode is not - DHCP4_TAG_EOP, or the pointer to the buffer. - -**/ -EFI_DHCP4_PACKET_OPTION * -PxeBcParseExtendOptions ( - IN UINT8 *Buffer, - IN UINT32 Length, - IN UINT8 OptTag - ); - - -/** - This function is to parse and check vendor options. - - @param Dhcp4Option Pointer to dhcp options - @param VendorOption Pointer to vendor options - - @return TRUE if valid for vendor options, or FALSE. - -**/ -BOOLEAN -PxeBcParseVendorOptions ( - IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option, - IN PXEBC_VENDOR_OPTION *VendorOption - ); - - -/** - Choose the boot prompt. - - @param Private Pointer to PxeBc private data. - - @retval EFI_SUCCESS Select boot prompt done. - @retval EFI_TIMEOUT Select boot prompt time out. - @retval EFI_NOT_FOUND The proxy offer is not Pxe10. - @retval EFI_ABORTED User cancel the operation. - @retval EFI_NOT_READY Read the input key from the keybroad has no= t finish. - -**/ -EFI_STATUS -PxeBcSelectBootPrompt ( - IN PXEBC_PRIVATE_DATA *Private - ); - - -/** - Select the boot menu. - - @param Private Pointer to PxeBc private data. - @param Type The type of the menu. - @param UseDefaultItem Use default item or not. - - @retval EFI_ABORTED User cancel operation. - @retval EFI_SUCCESS Select the boot menu success. - @retval EFI_NOT_READY Read the input key from the keybroad has not fin= ish. - -**/ -EFI_STATUS -PxeBcSelectBootMenu ( - IN PXEBC_PRIVATE_DATA *Private, - OUT UINT16 *Type, - IN BOOLEAN UseDefaultItem - ); - -#endif - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h b/Md= eModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h deleted file mode 100644 index b7bf069dd637..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.h +++ /dev/null @@ -1,102 +0,0 @@ -/** @file - -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - -#ifndef __EFI_PXEBC_DRIVER_H__ -#define __EFI_PXEBC_DRIVER_H__ - -/** - Test to see if this driver supports ControllerHandle. This service - is called by the EFI boot service ConnectController(). In - order to make drivers as small as possible, there are a few calling - restrictions for this service. ConnectController() must - follow these calling restrictions. If any other agent wishes to call - Supported() it must also follow these calling restrictions. - PxeBc requires DHCP4 and MTFTP4 protocols. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to test - @param RemainingDevicePath Optional parameter use to pick a specific ch= ild - device to start. - - @retval EFI_SUCCESS This driver supports this device - @retval EFI_ALREADY_STARTED This driver is already running on this devic= e - @retval other This driver does not support this device - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverBindingSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL - ); - -/** - Start this driver on ControllerHandle. This service is called by the - EFI boot service ConnectController(). In order to make - drivers as small as possible, there are a few calling restrictions for - this service. ConnectController() must follow these - calling restrictions. If any other agent wishes to call Start() it - must also follow these calling restrictions. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to bind driver to - @param RemainingDevicePath Optional parameter use to pick a specific c= hild - device to start. - - @retval EFI_SUCCESS This driver is added to ControllerHandle - @retval EFI_ALREADY_STARTED This driver is already running on Controlle= rHandle - @retval other This driver does not support this device - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, - IN EFI_HANDLE ControllerHandle, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL - ); - -/** - Stop this driver on ControllerHandle. This service is called by the - EFI boot service DisconnectController(). In order to - make drivers as small as possible, there are a few calling - restrictions for this service. DisconnectController() - must follow these calling restrictions. If any other agent wishes - to call Stop() it must also follow these calling restrictions. - - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to stop driver on - @param NumberOfChildren Number of Handles in ChildHandleBuffer. If num= ber of - children is zero stop the entire bus driver. - @param ChildHandleBuffer List of Child Handles to Stop. - - @retval EFI_SUCCESS This driver is removed ControllerHandle - @retval other This driver was not removed from this device - -**/ -EFI_STATUS -EFIAPI -PxeBcDriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE ControllerHandle, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer - ); - -extern EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2; -extern EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName; -extern EFI_DRIVER_BINDING_PROTOCOL gPxeBcDriverBinding; - -#endif - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h b/MdeM= odulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h deleted file mode 100644 index e96b6f2c5d14..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.h +++ /dev/null @@ -1,189 +0,0 @@ -/** @file - -Copyright (c) 2007 - 2016, 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 IMPLI= ED. - -**/ - -#ifndef __EFI_PXEBC_IMPL_H__ -#define __EFI_PXEBC_IMPL_H__ - - -typedef struct _PXEBC_PRIVATE_DATA PXEBC_PRIVATE_DATA; - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PxeBcDriver.h" -#include "PxeBcDhcp.h" -#include "PxeBcMtftp.h" -#include "PxeBcSupport.h" - -#define PXEBC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'X', 'E', 'P') -#define PXEBC_MTFTP_TIMEOUT 4 -#define PXEBC_MTFTP_RETRIES 6 -#define PXEBC_DEFAULT_UDP_OVERHEAD_SIZE 8 -#define PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE 4 -#define PXEBC_DEFAULT_PACKET_SIZE 1480 -#define PXEBC_DEFAULT_LIFETIME 50000 // 50ms, unit is microse= cond -#define PXEBC_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20) - -struct _PXEBC_PRIVATE_DATA { - UINT32 Signature; - EFI_HANDLE Controller; - EFI_HANDLE Image; - EFI_HANDLE ArpChild; - EFI_HANDLE Dhcp4Child; - EFI_HANDLE Ip4Child; - EFI_HANDLE Mtftp4Child; - EFI_HANDLE Udp4ReadChild; - EFI_HANDLE Udp4WriteChild; - - EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii; - - EFI_PXE_BASE_CODE_PROTOCOL PxeBc; - EFI_LOAD_FILE_PROTOCOL LoadFile; - EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL LoadFileCallback; - EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *PxeBcCallback; - EFI_ARP_PROTOCOL *Arp; - EFI_DHCP4_PROTOCOL *Dhcp4; - EFI_IP4_PROTOCOL *Ip4; - EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; - EFI_IP4_CONFIG_DATA Ip4ConfigData; - EFI_MTFTP4_PROTOCOL *Mtftp4; - EFI_UDP4_PROTOCOL *Udp4Read; - EFI_UDP4_PROTOCOL *Udp4Write; - UINT16 CurrentUdpSrcPort; - EFI_UDP4_CONFIG_DATA Udp4CfgData; - - - EFI_PXE_BASE_CODE_MODE Mode; - EFI_PXE_BASE_CODE_FUNCTION Function; - - CHAR8 *BootFileName; - - EFI_IP_ADDRESS StationIp; - EFI_IP_ADDRESS SubnetMask; - EFI_IP_ADDRESS GatewayIp; - EFI_IP_ADDRESS ServerIp; - BOOLEAN AddressIsOk; - UINT32 Ip4MaxPacketSize; - UINTN BlockSize; - UINTN FileSize; - - UINT8 OptionBuffer[PXEBC_DHCP4_MAX_O= PTION_SIZE]; - EFI_DHCP4_PACKET SeedPacket; - EFI_MAC_ADDRESS Mac; - UINT8 MacLen; - - BOOLEAN SortOffers; - BOOLEAN GotProxyOffer; - UINT32 NumOffers; - UINT32 SelectedOffer; - UINT32 ProxyOfferType; - - // - // Cached packets as complements of pxe mode data - // - PXEBC_CACHED_DHCP4_PACKET ProxyOffer; - PXEBC_CACHED_DHCP4_PACKET Dhcp4Ack; - PXEBC_CACHED_DHCP4_PACKET PxeReply; - PXEBC_CACHED_DHCP4_PACKET Dhcp4Offers[PXEBC_MAX_OFFER_NU= M]; - - // - // Arrays for different types of offers: - // ServerCount records the count of the servers we got the offers, - // OfferIndex records the index of the offer sent by the server indexe= d by ServerCount. - // - UINT32 ServerCount[DHCP4_PACKET_TYPE_= MAX]; - UINT32 OfferIndex[DHCP4_PACKET_TYPE_M= AX][PXEBC_MAX_OFFER_NUM]; - UINT32 BootpIndex; - UINT32 ProxyIndex[DHCP4_PACKET_TYPE_M= AX]; - UINT32 BinlIndex[PXEBC_MAX_OFFER_NUM]= ; - - EFI_EVENT GetArpCacheEvent; - // - // token and event used to get ICMP error data from IP - // - EFI_IP4_COMPLETION_TOKEN IcmpErrorRcvToken; -}; - -#define PXEBC_PRIVATE_DATA_FROM_PXEBC(a) CR (a, PXEBC_PRIVATE_DAT= A, PxeBc, PXEBC_PRIVATE_DATA_SIGNATURE) - -#define PXEBC_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, PXEBC_PRIVATE_DAT= A, LoadFile, PXEBC_PRIVATE_DATA_SIGNATURE) - -#define PXEBC_PRIVATE_DATA_FROM_PXEBCCALLBACK(a) CR (a, PXEBC_PRIVATE_DAT= A, PxeBcCallback, PXEBC_PRIVATE_DATA_SIGNATURE) - -extern EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate; -extern EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate; - -/** - Causes the driver to load a specified file. - - @param This Protocol instance pointer. - @param FilePath The device specific path of the file to lo= ad. - @param BootPolicy If TRUE, indicates that the request origin= ates from the - boot manager is attempting to load FilePat= h as a boot - selection. If FALSE, then FilePath must ma= tch as exact file - to be loaded. - @param BufferSize On input the size of Buffer in bytes. On o= utput with a return - code of EFI_SUCCESS, the amount of data tr= ansferred to - Buffer. On output with a return code of EF= I_BUFFER_TOO_SMALL, - the size of Buffer required to retrieve th= e requested file. - @param Buffer The memory buffer to transfer the file to.= IF Buffer is NULL, - then no the size of the requested file is = returned in - BufferSize. - - @retval EFI_SUCCESS The file was loaded. - @retval EFI_UNSUPPORTED The device does not support the prov= ided BootPolicy - @retval EFI_INVALID_PARAMETER FilePath is not a valid device path,= or - BufferSize is NULL. - @retval EFI_NO_MEDIA No medium was present to load the fi= le. - @retval EFI_DEVICE_ERROR The file was not loaded due to a dev= ice error. - @retval EFI_NO_RESPONSE The remote system did not respond. - @retval EFI_NOT_FOUND The file was not found. - @retval EFI_ABORTED The file load process was manually c= ancelled. - -**/ -EFI_STATUS -EFIAPI -EfiPxeLoadFile ( - IN EFI_LOAD_FILE_PROTOCOL * This, - IN EFI_DEVICE_PATH_PROTOCOL * FilePath, - IN BOOLEAN BootPolicy, - IN OUT UINTN *BufferSize, - IN VOID *Buffer OPTIONAL - ); - -#endif diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h b/Mde= ModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h deleted file mode 100644 index 903dd4fbb69a..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcMtftp.h +++ /dev/null @@ -1,137 +0,0 @@ -/** @file - Mtftp routines for PxeBc. - -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - -#ifndef __EFI_PXEBC_MTFTP_H__ -#define __EFI_PXEBC_MTFTP_H__ - -#define PXE_MTFTP_OPTION_BLKSIZE_INDEX 0 -#define PXE_MTFTP_OPTION_TIMEOUT_INDEX 1 -#define PXE_MTFTP_OPTION_TSIZE_INDEX 2 -#define PXE_MTFTP_OPTION_MULTICAST_INDEX 3 -#define PXE_MTFTP_OPTION_MAXIMUM_INDEX 4 - -#define PXE_MTFTP_ERROR_STRING_LENGTH 127 -#define PXE_MTFTP_OPTBUF_MAXNUM_INDEX 128 - - -/** - This function is to get size of a file by Tftp. - - @param Private Pointer to PxeBc private data - @param Config Pointer to Mtftp configuration data - @param Filename Pointer to file name - @param BlockSize Pointer to block size - @param BufferSize Pointer to buffer size - - @retval EFI_SUCCESS Get the size of file success - @retval EFI_NOT_FOUND Parse the tftp ptions failed. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval Other Has not get the size of the file. - -**/ -EFI_STATUS -PxeBcTftpGetFileSize ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN UINTN *BlockSize, - IN OUT UINT64 *BufferSize - ); - - -/** - This function is to get data of a file by Tftp. - - @param Private Pointer to PxeBc private data - @param Config Pointer to Mtftp configuration data - @param Filename Pointer to file name - @param BlockSize Pointer to block size - @param BufferPtr Pointer to buffer - @param BufferSize Pointer to buffer size - @param DontUseBuffer Indicate whether with a receive buffer - - @retval EFI_SUCCESS Read the data success from the special file. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval other Read data from file failed. - -**/ -EFI_STATUS -PxeBcTftpReadFile ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN UINTN *BlockSize, - IN UINT8 *BufferPtr, - IN OUT UINT64 *BufferSize, - IN BOOLEAN DontUseBuffer - ); - - -/** - This function is put data of a file by Tftp. - - @param Private Pointer to PxeBc private data - @param Config Pointer to Mtftp configuration data - @param Filename Pointer to file name - @param Overwrite Indicate whether with overwrite attribute - @param BlockSize Pointer to block size - @param BufferPtr Pointer to buffer - @param BufferSize Pointer to buffer size - - @retval EFI_SUCCESS Write the data success into the special file. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval other Write data into file failed. - -**/ -EFI_STATUS -PxeBcTftpWriteFile ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN BOOLEAN Overwrite, - IN UINTN *BlockSize, - IN UINT8 *BufferPtr, - IN OUT UINT64 *BufferSize - ); - - -/** - This function is to get data(file) from a directory(may be a server) by = Tftp. - - @param Private Pointer to PxeBc private data. - @param Config Pointer to Mtftp configuration data. - @param Filename Pointer to file name. - @param BlockSize Pointer to block size. - @param BufferPtr Pointer to buffer. - @param BufferSize Pointer to buffer size. - @param DontUseBuffer Indicate whether with a receive buffer. - - @retval EFI_SUCCES Get the data from the file included in direct= ory success. - @retval EFI_DEVICE_ERROR The network device encountered an error durin= g this operation. - @retval other Operation failed. - -**/ -EFI_STATUS -PxeBcTftpReadDirectory ( - IN PXEBC_PRIVATE_DATA *Private, - IN EFI_MTFTP4_CONFIG_DATA *Config, - IN UINT8 *Filename, - IN UINTN *BlockSize, - IN UINT8 *BufferPtr, - IN OUT UINT64 *BufferSize, - IN BOOLEAN DontUseBuffer - ); - -#endif - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h b/M= deModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h deleted file mode 100644 index a28c9740c171..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.h +++ /dev/null @@ -1,134 +0,0 @@ -/** @file - Support routines for PxeBc. -Copyright (c) 2007 - 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 IMPLI= ED. - -**/ - -#ifndef __EFI_PXEBC_SUPPORT_H__ -#define __EFI_PXEBC_SUPPORT_H__ - - -/** - The common notify function associated with various PxeBc events. - - @param Event The event signaled. - @param Context The context. - -**/ -VOID -EFIAPI -PxeBcCommonNotify ( - IN EFI_EVENT Event, - IN VOID *Context - ); - - -/** - This function initialize(or configure) the Udp4Write instance. - - @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance. - @param StationIp Pointer to the station ip address. - @param SubnetMask Pointer to the subnetmask of the station ip address. - @param Gateway Pointer to the gateway ip address. - @param SrcPort Pointer to the srouce port of the station. - @param Ttl The time to live field of the IP header. - @param ToS The type of service field of the IP header. - - @retval EFI_SUCCESS The configuration settings were set, chang= ed, or reset successfully. - @retval EFI_NO_MAPPING When using a default address, configuratio= n (DHCP, BOOTP, - RARP, etc.) is not finished yet. - @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE: - @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already= started/configured - and must be stopped/reset before it can be= reconfigured. - @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE - and UdpConfigData.StationPort is already u= sed by - other instance. - @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot alloc= ate memory for this - EFI UDPv4 Protocol instance. - @retval EFI_DEVICE_ERROR An unexpected network or system error occu= rred and this instance - was not opened. - @retval Others Please examine the function Udp4->Routes(U= dp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns. - -**/ -EFI_STATUS -PxeBcConfigureUdpWriteInstance ( - IN EFI_UDP4_PROTOCOL *Udp4, - IN EFI_IPv4_ADDRESS *StationIp, - IN EFI_IPv4_ADDRESS *SubnetMask, - IN EFI_IPv4_ADDRESS *Gateway, - IN OUT UINT16 *SrcPort, - IN UINT8 Ttl, - IN UINT8 ToS - ); - - -/** - This function is to display the IPv4 address. - - @param[in] Ip The pointer to the IPv4 address. - -**/ -VOID -PxeBcShowIp4Addr ( - IN EFI_IPv4_ADDRESS *Ip - ); - - -/** - Convert number to ASCII value. - - @param Number Numeric value to convert to decimal ASCII va= lue. - @param Buffer Buffer to place ASCII version of the Number. - @param Length Length of Buffer. - -**/ -VOID -CvtNum ( - IN UINTN Number, - IN UINT8 *Buffer, - IN UINTN Length - ); - - -/** - Convert unsigned int number to decimal number. - - @param Number The unsigned int number will be converted. - @param Buffer Pointer to the buffer to store the decimal nu= mber after transform. - @param[in] BufferSize The maxsize of the buffer. - - @return the length of the number after transform. - -**/ -UINTN -UtoA10 ( - IN UINTN Number, - IN CHAR8 *Buffer, - IN UINTN BufferSize - - ); - - -/** - Convert ASCII numeric string to a UINTN value. - - @param Buffer Pointer to the 8-byte unsigned int value. - - @return UINTN value of the ASCII string. - -**/ -UINT64 -AtoU64 ( - IN UINT8 *Buffer - ); - - -#endif - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxe.uni = b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxe.uni deleted file mode 100644 index e97c3cadd973..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxe.uni +++ /dev/null @@ -1,25 +0,0 @@ -// /** @file -// This module produces EFI Preboot Execution Environment (PXE) Base Code = Protocol. -// -// This module produces EFI PXE Base Code Protocol upon EFI MMP Protocl an= d IPv4 -// network stack, used to control PXE-compatible devices. It produces EFI = Load File -// Protocol to provide one clean way to otain control from the boot manage= r if the -// boot patch is from the remote device. -// -// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials -// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "Produces EFI Preb= oot Execution Environment (PXE) Base Code Protocol" - -#string STR_MODULE_DESCRIPTION #language en-US "This module produ= ces EFI PXE Base Code Protocol upon the EFI MMP Protocol and the IPv4 netwo= rk stack, and is used to control PXE-compatible devices. It produces the EF= I Load File Protocol to provide a clean method to obtain control from the b= oot manager if the boot patch is from the remote device." - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxeExtra= .uni b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxeExtra.uni deleted file mode 100644 index 2c1bda1a8bd2..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxe4BcDxeExtra.uni +++ /dev/null @@ -1,20 +0,0 @@ -// /** @file -// UefiPxe4BcDxe 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 B= SD 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 IM= PLIED. -// -// **/ - -#string STR_PROPERTIES_MODULE_NAME -#language en-US -"UEFI PXE Base Code DXE Driver" - - diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf b= /MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf deleted file mode 100644 index 042401992945..000000000000 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf +++ /dev/null @@ -1,102 +0,0 @@ -## @file -# This module produces EFI Preboot Execution Environment (PXE) Base Code = Protocol. -# -# This module produces EFI PXE Base Code Protocol upon EFI MMP Protocl an= d IPv4 -# network stack, used to control PXE-compatible devices. It produces EFI = Load File -# Protocol to provide one clean way to otain control from the boot manage= r if the -# boot patch is from the remote device. This driver only supports IPv4 ne= twork stack. -# -# Notes: -# 1) This driver can't co-work with the UefiPxeBcDxe driver in NetworkPkg= . -# 2) This driver might have some issues that have been fixed in the UefiP= xeBcDxe -# driver in NetworkPkg. -# 3) This driver supports fewer features than the UefiPxeBcDxe driver in = NetworkPkg -# (e.g. IPv6, MTFTP windowsize). -# 4) UefiPxeBcDxe driver in NetworkPkg is recommended for use instead of = this one even -# though both of them can be used. -# -# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. -# -# -## - - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D UefiPxe4BcDxe - MODULE_UNI_FILE =3D UefiPxe4BcDxe.uni - FILE_GUID =3D 3B1DEAB5-C75D-442e-9238-8E2FFB62B0BB - MODULE_TYPE =3D UEFI_DRIVER - VERSION_STRING =3D 1.0 - ENTRY_POINT =3D PxeBcDriverEntryPoint - UNLOAD_IMAGE =3D NetLibDefaultUnload - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 -# -# DRIVER_BINDING =3D gPxeBcDriverBinding -# COMPONENT_NAME =3D gPxeBcComponentName -# COMPONENT_NAME2 =3D gPxeBcComponentName2 -# - -[Sources] - PxeBcMtftp.c - PxeBcSupport.h - PxeBcSupport.c - PxeBcDriver.c - PxeBcDhcp.h - ComponentName.c - PxeBcImpl.c - PxeBcImpl.h - PxeBcDhcp.c - PxeBcMtftp.h - PxeBcDriver.h - - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - -[LibraryClasses] - BaseLib - UefiLib - UefiBootServicesTableLib - UefiDriverEntryPoint - BaseMemoryLib - MemoryAllocationLib - DebugLib - NetLib - DpcLib - PcdLib - -[Protocols] - gEfiPxeBaseCodeCallbackProtocolGuid ## SOMETIMES_PRODUCES - gEfiPxeBaseCodeProtocolGuid ## BY_START - gEfiLoadFileProtocolGuid ## BY_START - gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## SOMETIMES_CONSUMES - gEfiArpServiceBindingProtocolGuid ## TO_START - gEfiArpProtocolGuid ## TO_START - gEfiMtftp4ServiceBindingProtocolGuid ## TO_START - gEfiMtftp4ProtocolGuid ## TO_START - gEfiUdp4ServiceBindingProtocolGuid ## TO_START - gEfiUdp4ProtocolGuid ## TO_START - gEfiDhcp4ServiceBindingProtocolGuid ## TO_START - gEfiDhcp4ProtocolGuid ## TO_START - gEfiIp4ServiceBindingProtocolGuid ## TO_START - gEfiIp4ProtocolGuid ## TO_START - gEfiIp4Config2ProtocolGuid ## TO_START - -[Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdTftpBlockSize ## SOMETIMES_CONSUMES - -[UserExtensions.TianoCore."ExtraFiles"] - UefiPxe4BcDxeExtra.uni --=20 2.18.0.windows.1