From nobody Sat Nov 2 12:19:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489653359400247.01419961291504; Thu, 16 Mar 2017 01:35:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CEB1A80407; Thu, 16 Mar 2017 01:35:57 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 D07A980406 for ; Thu, 16 Mar 2017 01:35:55 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2017 01:35:55 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.130]) by fmsmga005.fm.intel.com with ESMTP; 16 Mar 2017 01:35:53 -0700 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489653355; x=1521189355; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=efyGg0RNrJnIOReVOYN7/odvRAdy9DVjR4MKc1w1Tk4=; b=PQ+LuIWzLPSHcJ551ZRczBupHuTSEjbTHzAHf69pCZWaJKlCixtv3Ggv LUXJR9gDmxEqcz63wq5QThihItz0tQ==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,170,1486454400"; d="scan'208";a="76907085" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Thu, 16 Mar 2017 16:35:48 +0800 Message-Id: <1489653350-62316-2-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1489653350-62316-1-git-send-email-jiaxin.wu@intel.com> References: <1489653350-62316-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 1/2] MdeModulePke/Mtftp4Dxe: Add windowsize option support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch is to support the tftp windowsize option that allows the client and server to negotiate a window size of consecutive blocks to send as an alternative for replacing the single-block lockstep schema. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 5 ++- .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h | 11 +++++- .../Universal/Network/Mtftp4Dxe/Mtftp4Option.c | 12 +++++- .../Universal/Network/Mtftp4Dxe/Mtftp4Option.h | 6 ++- .../Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c | 44 ++++++++++++++++--= ---- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c | 14 +++---- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h | 16 +------- .../Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c | 41 +++++++++++++++++-= -- 8 files changed, 104 insertions(+), 45 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c b/MdeMod= ulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c index a2583a4..9d4de42 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c @@ -1,10 +1,10 @@ /** @file Interface routine for Mtftp4. =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -78,10 +78,12 @@ Mtftp4CleanOperation ( ZeroMem (&Instance->RequestOption, sizeof (MTFTP4_OPTION)); =20 Instance->Operation =3D 0; =20 Instance->BlkSize =3D MTFTP4_DEFAULT_BLKSIZE; + Instance->SentAckNo =3D 0; + Instance->WindowSize =3D 1; Instance->LastBlock =3D 0; Instance->ServerIp =3D 0; Instance->ListeningPort =3D 0; Instance->ConnectedPort =3D 0; Instance->Gateway =3D 0; @@ -438,10 +440,11 @@ Mtftp4Start ( // Set the operation parameters from the configuration or override data. // Config =3D &Instance->Config; Instance->Token =3D Token; Instance->BlkSize =3D MTFTP4_DEFAULT_BLKSIZE; + Instance->WindowSize =3D MTFTP4_DEFAULT_WINDOWSIZE; =20 CopyMem (&Instance->ServerIp, &Config->ServerIp, sizeof (IP4_ADDR)); Instance->ServerIp =3D NTOHL (Instance->ServerIp); =20 Instance->ListeningPort =3D Config->InitialServerPort; diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h b/MdeMod= ulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h index 527fd1d..733bc5d 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h @@ -6,12 +6,13 @@ RFC1350 - THE TFTP PROTOCOL (REVISION 2) RFC2090 - TFTP Multicast Option RFC2347 - TFTP Option Extension RFC2348 - TFTP Blocksize Option RFC2349 - TFTP Timeout Interval and Transfer Size Options + RFC7440 - TFTP Windowsize Option =20 -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -54,10 +55,11 @@ typedef struct _MTFTP4_PROTOCOL MTFTP4_PROTOCOL; =20 #define MTFTP4_DEFAULT_SERVER_PORT 69 #define MTFTP4_DEFAULT_TIMEOUT 3 #define MTFTP4_DEFAULT_RETRY 5 #define MTFTP4_DEFAULT_BLKSIZE 512 +#define MTFTP4_DEFAULT_WINDOWSIZE 1 #define MTFTP4_TIME_TO_GETMAP 5 =20 #define MTFTP4_STATE_UNCONFIGED 0 #define MTFTP4_STATE_CONFIGED 1 #define MTFTP4_STATE_DESTROY 2 @@ -119,10 +121,17 @@ struct _MTFTP4_PROTOCOL { UINT16 BlkSize; UINT16 LastBlock; LIST_ENTRY Blocks; =20 // + // The last sent ack number.=20 + // + UINT16 SentAckNo; + + UINT16 WindowSize; + + // // The server's communication end point: IP and two ports. one for // initial request, one for its selected port. // IP4_ADDR ServerIp; UINT16 ListeningPort; diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c b/MdeM= odulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c index e40561a..da6aee0 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.c @@ -1,9 +1,9 @@ /** @file Routines to process MTFTP4 options. =20 -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -14,10 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. =20 #include "Mtftp4Impl.h" =20 CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] =3D { "blksize", + "windowsize", "timeout", "tsize", "multicast" }; =20 @@ -479,10 +480,19 @@ Mtftp4ParseOption ( } } =20 MtftpOption->Exist |=3D MTFTP4_MCAST_EXIST; =20 + } else if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "windowsiz= e")) { + Value =3D NetStringToU32 (This->ValueStr); + + if (Value < 1) { + return EFI_INVALID_PARAMETER; + } + + MtftpOption->WindowSize =3D (UINT16) Value; + MtftpOption->Exist |=3D MTFTP4_WINDOWSIZE_EXIST; } else if (Request) { // // Ignore the unsupported option if it is a reply, and return // EFI_UNSUPPORTED if it's a request according to the UEFI spec. // diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.h b/MdeM= odulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.h index b7fdbf2..b86d77d 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.h +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Option.h @@ -1,9 +1,9 @@ /** @file Routines to process MTFTP4 options. =20 -Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -14,23 +14,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. =20 =20 #ifndef __EFI_MTFTP4_OPTION_H__ #define __EFI_MTFTP4_OPTION_H__ =20 -#define MTFTP4_SUPPORTED_OPTIONS 4 +#define MTFTP4_SUPPORTED_OPTIONS 5 #define MTFTP4_OPCODE_LEN 2 #define MTFTP4_ERRCODE_LEN 2 #define MTFTP4_BLKNO_LEN 2 #define MTFTP4_DATA_HEAD_LEN 4 =20 #define MTFTP4_BLKSIZE_EXIST 0x01 #define MTFTP4_TIMEOUT_EXIST 0x02 #define MTFTP4_TSIZE_EXIST 0x04 #define MTFTP4_MCAST_EXIST 0x08 +#define MTFTP4_WINDOWSIZE_EXIST 0x10 =20 typedef struct { UINT16 BlkSize; + UINT16 WindowSize; UINT8 Timeout; UINT32 Tsize; IP4_ADDR McastIp; UINT16 McastPort; BOOLEAN Master; diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c b/MdeModu= lePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c index e983d79..5454d6c 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c @@ -1,10 +1,10 @@ /** @file Routines to process Rrq (download). =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -97,10 +97,13 @@ Mtftp4RrqSendAck ( IN UINT16 BlkNo ) { EFI_MTFTP4_PACKET *Ack; NET_BUF *Packet; + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; =20 Packet =3D NetbufAlloc (sizeof (EFI_MTFTP4_ACK_HEADER)); if (Packet =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } @@ -113,11 +116,16 @@ Mtftp4RrqSendAck ( ASSERT (Ack !=3D NULL); =20 Ack->Ack.OpCode =3D HTONS (EFI_MTFTP4_OPCODE_ACK); Ack->Ack.Block[0] =3D HTONS (BlkNo); =20 - return Mtftp4SendPacket (Instance, Packet); + Status =3D Mtftp4SendPacket (Instance, Packet); + if (!EFI_ERROR (Status)) { + Instance->SentAckNo =3D BlkNo; + } + + return Status; } =20 =20 /** Deliver the received data block to the user, which can be saved @@ -156,11 +164,11 @@ Mtftp4RrqSaveBlock ( =20 // // This is the last block, save the block no // if (DataLen < Instance->BlkSize) { - Completed =3D TRUE; + Completed =3D TRUE; Instance->LastBlock =3D Block; Mtftp4SetLastBlockNum (&Instance->Blocks, Block); } =20 // @@ -255,23 +263,23 @@ Mtftp4RrqHandleData ( EFI_STATUS Status; UINT16 BlockNum; INTN Expected; =20 *Completed =3D FALSE; + Status =3D EFI_SUCCESS; BlockNum =3D NTOHS (Packet->Data.Block); Expected =3D Mtftp4GetNextBlockNum (&Instance->Blocks); =20 ASSERT (Expected >=3D 0); =20 // - // If we are active and received an unexpected packet, retransmit - // the last ACK then restart receiving. If we are passive, save - // the block. + // If we are active and received an unexpected packet, transmit + // the ACK for the block we received, then restart receiving the=20 + // expected one. If we are passive, save the block. // if (Instance->Master && (Expected !=3D BlockNum)) { - Mtftp4Retransmit (Instance); - return EFI_SUCCESS; + return Mtftp4RrqSendAck (Instance, (UINT16) (Expected - 1)); } =20 Status =3D Mtftp4RrqSaveBlock (Instance, Packet, Len); =20 if (EFI_ERROR (Status)) { @@ -307,14 +315,17 @@ Mtftp4RrqHandleData ( =20 } else { BlockNum =3D (UINT16) (Expected - 1); } =20 - Mtftp4RrqSendAck (Instance, BlockNum); + if (Instance->WindowSize =3D=3D (BlockNum - Instance->SentAckNo) || Ex= pected < 0) { + Status =3D Mtftp4RrqSendAck (Instance, BlockNum); + } + =20 } =20 - return EFI_SUCCESS; + return Status; } =20 =20 /** Validate whether the options received in the server's OACK packet is val= id. @@ -347,14 +358,15 @@ Mtftp4RrqOackValid ( if ((Reply->Exist &~Request->Exist) !=3D 0) { return FALSE; } =20 // - // Server can only specify a smaller block size to be used and + // Server can only specify a smaller block size and window size to be us= ed and // return the timeout matches that requested. // if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) !=3D 0)&& (Reply->BlkSize > = Request->BlkSize)) || + (((Reply->Exist & MTFTP4_WINDOWSIZE_EXIST) !=3D 0)&& (Reply->WindowSi= ze > Request->WindowSize)) || (((Reply->Exist & MTFTP4_TIMEOUT_EXIST) !=3D 0) && (Reply->Timeout != =3D Request->Timeout))) { return FALSE; } =20 // @@ -527,11 +539,11 @@ Mtftp4RrqHandleOack ( =20 if ((Reply.Exist & MTFTP4_MCAST_EXIST) !=3D 0) { =20 // // Save the multicast info. Always update the Master, only update the - // multicast IP address, block size, timeoute at the first time. If IP + // multicast IP address, block size, window size, timeoute at the firs= t time. If IP // address is updated, create a UDP child to receive the multicast. // Instance->Master =3D Reply.Master; =20 if (Instance->McastIp =3D=3D 0) { @@ -596,10 +608,14 @@ Mtftp4RrqHandleOack ( // Update the parameters used. // if (Reply.BlkSize !=3D 0) { Instance->BlkSize =3D Reply.BlkSize; } + + if (Reply.WindowSize !=3D 0) { + Instance->WindowSize =3D Reply.WindowSize; + } =20 if (Reply.Timeout !=3D 0) { Instance->Timeout =3D Reply.Timeout; } =20 } =20 @@ -609,10 +625,14 @@ Mtftp4RrqHandleOack ( =20 if (Reply.BlkSize !=3D 0) { Instance->BlkSize =3D Reply.BlkSize; } =20 + if (Reply.WindowSize !=3D 0) { + Instance->WindowSize =3D Reply.WindowSize; + } + if (Reply.Timeout !=3D 0) { Instance->Timeout =3D Reply.Timeout; } } =20 diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c b/Mde= ModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c index c625fda..83e6837 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c @@ -1,9 +1,9 @@ /** @file Support routines for Mtftp. =20 -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -218,19 +218,19 @@ Mtftp4RemoveBlockNum ( // transfers of unlimited size. There is no consensus, however, whet= her=20 // the counter should wrap around to zero or to one. Many implementa= tions=20 // wrap to zero, because this is the simplest to implement. Here we = choose=20 // this solution. // - *TotalBlock =3D Num; - =20 + *TotalBlock =3D Num; + if (Range->Round > 0) { - *TotalBlock +=3D Range->Bound + MultU64x32 ((UINTN) (Range->Round -1= ), (UINT32) (Range->Bound + 1)) + 1; - } + *TotalBlock +=3D Range->Bound + MultU64x32 ((UINTN) (Range->Round= -1), (UINT32) (Range->Bound + 1)) + 1; + } =20 if (Range->Start > Range->Bound) { - Range->Start =3D 0; - Range->Round ++; + Range->Start =3D 0; + Range->Round ++; } =20 if ((Range->Start > Range->End) || Completed) { RemoveEntryList (&Range->Link); FreePool (Range); diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h b/Mde= ModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h index 802e386..4b7e2b0 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h @@ -1,9 +1,9 @@ /** @file Support routines for MTFTP. =20 -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -172,24 +172,10 @@ Mtftp4SendError ( IN UINT16 ErrCode, IN UINT8 *ErrInfo ); =20 /** - Retransmit the last packet for the instance. - - @param Instance The Mtftp instance - - @retval EFI_SUCCESS The last packet is retransmitted. - @retval Others Failed to retransmit. - -**/ -EFI_STATUS -Mtftp4Retransmit ( - IN MTFTP4_PROTOCOL *Instance - ); - -/** The timer ticking function for the Mtftp service instance. =20 @param Event The ticking event @param Context The Mtftp service instance =20 diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c b/MdeModu= lePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c index e825714..ea4de93 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c @@ -1,9 +1,9 @@ /** @file Routines to process Wrq (upload). =20 -Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 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
=20 @@ -19,21 +19,23 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. /** Build then send a MTFTP data packet for the MTFTP upload session. =20 @param Instance The MTFTP upload session. @param BlockNum The block number to send. + @param Completed Return whether the upload has finished. =20 @retval EFI_OUT_OF_RESOURCES Failed to build the packet. @retval EFI_ABORTED The consumer of this child directs to abor= t the transmission by return an error through Pa= cketNeeded. @retval EFI_SUCCESS The data is sent. =20 **/ EFI_STATUS Mtftp4WrqSendBlock ( IN OUT MTFTP4_PROTOCOL *Instance, - IN UINT16 BlockNum + IN UINT16 BlockNum, + OUT BOOLEAN *Completed ) { EFI_MTFTP4_PACKET *Packet; EFI_MTFTP4_TOKEN *Token; NET_BUF *UdpPacket; @@ -66,19 +68,23 @@ Mtftp4WrqSendBlock ( if (Token->Buffer !=3D NULL) { Start =3D MultU64x32 (BlockNum - 1, Instance->BlkSize); =20 if (Token->BufferSize < Start + Instance->BlkSize) { DataLen =3D (UINT16) (Token->BufferSize - Start); + if (DataLen =3D=3D 0) { + *Completed =3D TRUE; + return EFI_SUCCESS; + } + =20 Instance->LastBlock =3D BlockNum; Mtftp4SetLastBlockNum (&Instance->Blocks, BlockNum); } =20 if (DataLen > 0) { NetbufAllocSpace (UdpPacket, DataLen, FALSE); CopyMem (Packet->Data.Data, (UINT8 *) Token->Buffer + Start, DataLen= ); - } - + }=20 } else { // // Get data from PacketNeeded // DataBuf =3D NULL; @@ -101,10 +107,15 @@ Mtftp4WrqSendBlock ( ); =20 return EFI_ABORTED; } =20 + if (DataLen =3D=3D 0) { + *Completed =3D TRUE; + return EFI_SUCCESS; + } + if (DataLen < Instance->BlkSize) { Instance->LastBlock =3D BlockNum; Mtftp4SetLastBlockNum (&Instance->Blocks, BlockNum); } =20 @@ -144,10 +155,15 @@ Mtftp4WrqHandleAck ( ) { UINT16 AckNum; INTN Expected; UINT64 TotalBlock; + + INTN Index; + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; =20 *Completed =3D FALSE; AckNum =3D NTOHS (Packet->Ack.Block[0]); Expected =3D Mtftp4GetNextBlockNum (&Instance->Blocks); =20 @@ -191,11 +207,19 @@ Mtftp4WrqHandleAck ( =20 return EFI_TFTP_ERROR; } } =20 - return Mtftp4WrqSendBlock (Instance, (UINT16) Expected); + for (Index =3D 0; Index < Instance->WindowSize; Index++) { + if (!EFI_ERROR (Status) && !(*Completed)) { + Status =3D Mtftp4WrqSendBlock (Instance, (UINT16) (Expected + Index)= , Completed); + } else { + break; + } + } + + return Status; } =20 =20 /** Check whether the received OACK is valid.=20 @@ -225,14 +249,15 @@ Mtftp4WrqOackValid ( if ((Reply->Exist & ~Request->Exist) !=3D 0) { return FALSE; } =20 // - // Server can only specify a smaller block size to be used and + // Server can only specify a smaller block size and window size to be us= ed and // return the timeout matches that requested. // if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) !=3D 0) && (Reply->BlkSize >= Request->BlkSize)) || + (((Reply->Exist & MTFTP4_WINDOWSIZE_EXIST) !=3D 0)&& (Reply->WindowSi= ze > Request->WindowSize)) || (((Reply->Exist & MTFTP4_TIMEOUT_EXIST) !=3D 0) && (Reply->Timeout != =3D Request->Timeout))) { return FALSE; } =20 return TRUE; @@ -302,10 +327,14 @@ Mtftp4WrqHandleOack ( =20 if (Reply.BlkSize !=3D 0) { Instance->BlkSize =3D Reply.BlkSize; } =20 + if (Reply.WindowSize !=3D 0) { + Instance->WindowSize =3D Reply.WindowSize; + } + if (Reply.Timeout !=3D 0) { Instance->Timeout =3D Reply.Timeout; } =20 // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:19:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489653362145789.7153913348646; Thu, 16 Mar 2017 01:36:02 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1717F8040A; Thu, 16 Mar 2017 01:36:00 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 A6B568036C for ; Thu, 16 Mar 2017 01:35:57 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2017 01:35:57 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.130]) by fmsmga005.fm.intel.com with ESMTP; 16 Mar 2017 01:35:55 -0700 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489653357; x=1521189357; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Ffsos+rr1MjEMCZdBtewVTXJq7kIhBi2FGKXw2645VA=; b=WEIaUBIhgfYjC69dxsFeYbeI9D2sUYFrTlrBbRfZUk1bWd2JpigFv1xR r1k5M7SkIX+ELHV3YV53zSnOLu8szQ==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,170,1486454400"; d="scan'208";a="76907103" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Thu, 16 Mar 2017 16:35:49 +0800 Message-Id: <1489653350-62316-3-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1489653350-62316-1-git-send-email-jiaxin.wu@intel.com> References: <1489653350-62316-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 2/2] ShellPkg/tftp: Add one option for tftp command to specify windowsize X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Carsey Jaben , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Define -w option for tftp shell command to specify the TFTP windowsize option. That will benefit the big file download for tftp server. Cc: Ye Ting Cc: Fu Siyuan Cc: Carsey Jaben Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c | 60 ++++++++++++++++++= ---- .../UefiShellTftpCommandLib.uni | 6 ++- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c b/ShellPkg/Lib= rary/UefiShellTftpCommandLib/Tftp.c index 5c50797..26f73ea 100755 --- a/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c +++ b/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c @@ -1,10 +1,10 @@ /** @file The implementation for the 'tftp' Shell command. =20 Copyright (c) 2015, ARM Ltd. All rights reserved.
- Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
=20 This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -180,10 +180,11 @@ DownloadFile ( IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR16 *FilePath, IN CONST CHAR8 *AsciiFilePath, IN UINTN FileSize, IN UINT16 BlockSize, + IN UINT16 WindowSize, OUT VOID **Data ); =20 /** Update the progress of a file download @@ -224,10 +225,11 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { {L"-l", TypeValue}, {L"-r", TypeValue}, {L"-c", TypeValue}, {L"-t", TypeValue}, {L"-s", TypeValue}, + {L"-w", TypeValue}, {NULL , TypeMax} }; =20 /// /// The default block size (512) of tftp is defined in the RFC1350. @@ -236,11 +238,16 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { /// /// The valid range of block size option is defined in the RFC2348. /// #define MTFTP_MIN_BLKSIZE 8 #define MTFTP_MAX_BLKSIZE 65464 +/// +/// The The default windowsize. +/// +#define MTFTP_DEFAULT_WINDOWSIZE 1 =20 +#define MTFTP_MAX_WINDOWSIZE 64 =20 /** Function for 'tftp' command. =20 @param[in] ImageHandle Handle to the Image (NULL if Internal). @@ -285,18 +292,20 @@ ShellCommandRunTftp ( EFI_MTFTP4_PROTOCOL *Mtftp4; UINTN FileSize; VOID *Data; SHELL_FILE_HANDLE FileHandle; UINT16 BlockSize; + UINT16 WindowSize; =20 ShellStatus =3D SHELL_INVALID_PARAMETER; ProblemParam =3D NULL; NicFound =3D FALSE; AsciiRemoteFilePath =3D NULL; Handles =3D NULL; FileSize =3D 0; BlockSize =3D MTFTP_DEFAULT_BLKSIZE; + WindowSize =3D 1; =20 // // Initialize the Shell library (we must be in non-auto-init...) // Status =3D ShellInitialize (); @@ -432,10 +441,24 @@ ShellCommandRunTftp ( ); goto Error; } } =20 + ValueStr =3D ShellCommandLineGetValue (CheckPackage, L"-w"); + if (ValueStr !=3D NULL) { + if (!StringToUint16 (ValueStr, &WindowSize)) { + goto Error; + } + if (WindowSize < MTFTP_DEFAULT_WINDOWSIZE || WindowSize > MTFTP_MAX_WI= NDOWSIZE) { + ShellPrintHiiEx ( + -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), + gShellTftpHiiHandle, L"tftp", ValueStr + ); + goto Error; + } + } + // // Locate all MTFTP4 Service Binding protocols // ShellStatus =3D SHELL_NOT_FOUND; Status =3D gBS->LocateHandleBuffer ( @@ -506,11 +529,11 @@ ShellCommandRunTftp ( gShellTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } =20 - Status =3D DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, = FileSize, BlockSize, &Data); + Status =3D DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, = FileSize, BlockSize, WindowSize, &Data); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD), gShellTftpHiiHandle, RemoteFilePath, NicName, Status ); @@ -890,20 +913,21 @@ DownloadFile ( IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR16 *FilePath, IN CONST CHAR8 *AsciiFilePath, IN UINTN FileSize, IN UINT16 BlockSize, + IN UINT16 WindowSize, OUT VOID **Data ) { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS PagesAddress; VOID *Buffer; DOWNLOAD_CONTEXT *TftpContext; EFI_MTFTP4_TOKEN Mtftp4Token; - EFI_MTFTP4_OPTION ReqOpt; - UINT8 OptBuf[10]; + UINT8 BlksizeBuf[10]; + UINT8 WindowsizeBuf[10]; =20 // Downloaded file can be large. BS.AllocatePages() is more faster // than AllocatePool() and avoid fragmentation. // The downloaded file could be an EFI application. Marking the // allocated page as EfiBootServicesCode would allow to execute a @@ -932,17 +956,29 @@ DownloadFile ( Mtftp4Token.Filename =3D (UINT8*)AsciiFilePath; Mtftp4Token.BufferSize =3D FileSize; Mtftp4Token.Buffer =3D Buffer; Mtftp4Token.CheckPacket =3D CheckPacket; Mtftp4Token.Context =3D (VOID*)TftpContext; + Mtftp4Token.OptionCount =3D 0; + Mtftp4Token.OptionList =3D AllocatePool (sizeof (EFI_MTFTP4_OPTION) * 2= ); + if (Mtftp4Token.OptionList =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Error; + } + if (BlockSize !=3D MTFTP_DEFAULT_BLKSIZE) { - ReqOpt.OptionStr =3D (UINT8 *) "blksize"; - AsciiSPrint ((CHAR8 *)OptBuf, sizeof (OptBuf), "%d", BlockSize); - ReqOpt.ValueStr =3D OptBuf; + Mtftp4Token.OptionList[Mtftp4Token.OptionCount].OptionStr =3D (UINT8 *= ) "blksize"; + AsciiSPrint ((CHAR8 *) BlksizeBuf, sizeof (BlksizeBuf), "%d", BlockSiz= e); + Mtftp4Token.OptionList[Mtftp4Token.OptionCount].ValueStr =3D BlksizeB= uf; + Mtftp4Token.OptionCount ++; + } =20 - Mtftp4Token.OptionCount =3D 1; - Mtftp4Token.OptionList =3D &ReqOpt; + if (WindowSize !=3D MTFTP_DEFAULT_WINDOWSIZE) { + Mtftp4Token.OptionList[Mtftp4Token.OptionCount].OptionStr =3D (UINT8 *= ) "windowsize"; + AsciiSPrint ((CHAR8 *) WindowsizeBuf, sizeof (WindowsizeBuf), "%d", Wi= ndowSize); + Mtftp4Token.OptionList[Mtftp4Token.OptionCount].ValueStr =3D Windowsi= zeBuf; + Mtftp4Token.OptionCount ++; } =20 ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING), gShellTftpHiiHandle, FilePath @@ -954,14 +990,18 @@ DownloadFile ( gShellTftpHiiHandle ); =20 Error : =20 - if (TftpContext =3D=3D NULL) { + if (TftpContext !=3D NULL) { FreePool (TftpContext); } =20 + if (Mtftp4Token.OptionList !=3D NULL) { + FreePool (Mtftp4Token.OptionList); + } + if (EFI_ERROR (Status)) { gBS->FreePages (PagesAddress, EFI_SIZE_TO_PAGES (FileSize)); return Status; } =20 diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandL= ib.uni b/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.u= ni index 4f4447d..ca6fa44 100644 --- a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.uni +++ b/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.uni @@ -1,9 +1,9 @@ // /** // // (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
-// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+// Copyright (c) 2010 - 2017, 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 // @@ -48,11 +48,11 @@ ".SH NAME\r\n" "Download a file from TFTP server.\r\n" ".SH SYNOPSIS\r\n" " \r\n" "TFTP [-i interface] [-l ] [-r ] [-c ] [-t ]\r\n" -" [-s ] host remotefilepath [localfilepath]\r\n" +" [-s ] [-w ] host remotefilepath [localfilep= ath]\r\n" ".SH OPTIONS\r\n" " \r\n" " -i interface - Specifies an adapter name, i.e., eth0.\r\n" " -l port - Specifies the local port number. Default value is 0\= r\n" " and the port number is automatically assigned.\r\n" @@ -61,10 +61,12 @@ " wait for a response. The default value is 6.\r\n" " -t - The number of seconds to wait for a response after\r= \n" " sending a request packet. Default value is 4s.\r\n" " -s - Specifies the TFTP blksize option as defined in RFC = 2348.\r\n" " Valid range is between 8 and 65464, default value is= 512.\r\n" +" -w - Specifies the TFTP windowsize option as defined in R= FC 7440.\r\n" +" Valid range is between 1 and 64, default value is 1.= \r\n" " host - Specify TFTP Server IPv4 address.\r\n" " remotefilepath - TFTP server file path to download the file.\r\n" " localfilepath - Local destination file path.\r\n" ".SH DESCRIPTION\r\n" " \r\n" --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel