Re: [edk2] [Patch 3/5] ShellPkg/TftpDynamicCommand: Add one option for tftp command to specify windowsize.
Reviewed-by: Jaben Carsey > -Original Message- > From: Wu, Jiaxin > Sent: Sunday, September 16, 2018 10:44 PM > To: edk2-devel@lists.01.org > Cc: Ye, Ting ; Fu, Siyuan ; Carsey, > Jaben ; Shao, Ming ; Wu, > Jiaxin > Subject: [Patch 3/5] ShellPkg/TftpDynamicCommand: Add one option for tftp > command to specify windowsize. > Importance: High > > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=886 > > This patch is to define one new option for TFTP shell command to specify the > windowsize option as defined in RFC 7440. Valid range is between 1 and 64, > default value is 1. > > Note that: RFC 7440 does not mention max window size value, but for the > stability reason, the value is limited to 64. > > Cc: Ye Ting > Cc: Fu Siyuan > Cc: Carsey Jaben > Cc: Shao Ming > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Wu Jiaxin > --- > .../DynamicCommand/TftpDynamicCommand/Tftp.c | 65 > --- > .../TftpDynamicCommand/Tftp.uni | 6 +- > 2 files changed, 59 insertions(+), 12 deletions(-) > > diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c > b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c > index 44be6d4e76..c66be6b9d9 100644 > --- a/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c > +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c > @@ -181,10 +181,11 @@ DownloadFile ( >IN EFI_MTFTP4_PROTOCOL *Mtftp4, >IN CONST CHAR16 *FilePath, >IN CONST CHAR8 *AsciiFilePath, >IN UINTNFileSize, >IN UINT16 BlockSize, > + IN UINT16 WindowSize, >OUT VOID **Data >); > > /** >Update the progress of a file download > @@ -225,10 +226,11 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { >{L"-l", TypeValue}, >{L"-r", TypeValue}, >{L"-c", TypeValue}, >{L"-t", TypeValue}, >{L"-s", TypeValue}, > + {L"-w", TypeValue}, >{NULL , TypeMax} >}; > > /// > /// The default block size (512) of tftp is defined in the RFC1350. > @@ -237,11 +239,21 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { > /// > /// The valid range of block size option is defined in the RFC2348. > /// > #define MTFTP_MIN_BLKSIZE 8 > #define MTFTP_MAX_BLKSIZE 65464 > - > +/// > +/// The default windowsize (1) of tftp. > +/// > +#define MTFTP_DEFAULT_WINDOWSIZE 1 > +/// > +/// The valid range of window size option. > +/// Note that: RFC 7440 does not mention max window size value, but for > the > +/// stability reason, the value is limited to 64. > +/// > +#define MTFTP_MIN_WINDOWSIZE 1 > +#define MTFTP_MAX_WINDOWSIZE 64 > > /** >Function for 'tftp' command. > >@param[in] ImageHandle Handle to the Image (NULL if Internal). > @@ -286,19 +298,21 @@ RunTftp ( >UINTN FileSize; >UINTN DataSize; >VOID*Data; >SHELL_FILE_HANDLE FileHandle; >UINT16 BlockSize; > + UINT16 WindowSize; > >ShellStatus = SHELL_INVALID_PARAMETER; >ProblemParam= NULL; >NicFound= FALSE; >AsciiRemoteFilePath = NULL; >Handles = NULL; >FileSize= 0; >DataSize= 0; >BlockSize = MTFTP_DEFAULT_BLKSIZE; > + WindowSize = MTFTP_DEFAULT_WINDOWSIZE; > >// >// Initialize the Shell library (we must be in non-auto-init...) >// >Status = ShellInitialize (); > @@ -434,10 +448,24 @@ RunTftp ( >); >goto Error; > } >} > > + ValueStr = ShellCommandLineGetValue (CheckPackage, L"-w"); > + if (ValueStr != NULL) { > +if (!StringToUint16 (ValueStr, )) { > + goto Error; > +} > +if (WindowSize < MTFTP_MIN_WINDOWSIZE || WindowSize > > MTFTP_MAX_WINDOWSIZE) { > + ShellPrintHiiEx ( > +-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), > +mTftpHiiHandle, L"tftp", ValueStr > + ); > + goto Error; > +} > + } > + >// >// Locate all MTFTP4 Service Binding protocols >// >ShellStatus = SHELL_NOT_FOUND; >Status = gBS->LocateHandleBuffer ( > @@ -508,11 +536,11 @@ RunTftp ( > mTftpHiiHandle, RemoteFilePath, NicName, Status >); >goto NextHandle; > } > > -Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, > FileSize, BlockSize, ); > +Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, > FileSize, BlockSize, WindowSize, ); > if (EFI_ERROR (Status)) { >ShellPrintHiiEx ( > -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD), > mTftpHiiHandle, RemoteFilePath, NicName, Status >); > @@ -894,20 +922,21 @@ DownloadFile ( >IN EFI_MTFTP4_PROTOCOL *Mtftp4, >IN CONST CHAR16 *FilePath, >IN CONST CHAR8 *AsciiFilePath, >IN UINTNFileSize, >IN UINT16
[edk2] [Patch 3/5] ShellPkg/TftpDynamicCommand: Add one option for tftp command to specify windowsize.
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=886 This patch is to define one new option for TFTP shell command to specify the windowsize option as defined in RFC 7440. Valid range is between 1 and 64, default value is 1. Note that: RFC 7440 does not mention max window size value, but for the stability reason, the value is limited to 64. Cc: Ye Ting Cc: Fu Siyuan Cc: Carsey Jaben Cc: Shao Ming Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin --- .../DynamicCommand/TftpDynamicCommand/Tftp.c | 65 --- .../TftpDynamicCommand/Tftp.uni | 6 +- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c index 44be6d4e76..c66be6b9d9 100644 --- a/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c @@ -181,10 +181,11 @@ DownloadFile ( IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR16 *FilePath, IN CONST CHAR8 *AsciiFilePath, IN UINTNFileSize, IN UINT16 BlockSize, + IN UINT16 WindowSize, OUT VOID **Data ); /** Update the progress of a file download @@ -225,10 +226,11 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { {L"-l", TypeValue}, {L"-r", TypeValue}, {L"-c", TypeValue}, {L"-t", TypeValue}, {L"-s", TypeValue}, + {L"-w", TypeValue}, {NULL , TypeMax} }; /// /// The default block size (512) of tftp is defined in the RFC1350. @@ -237,11 +239,21 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { /// /// The valid range of block size option is defined in the RFC2348. /// #define MTFTP_MIN_BLKSIZE 8 #define MTFTP_MAX_BLKSIZE 65464 - +/// +/// The default windowsize (1) of tftp. +/// +#define MTFTP_DEFAULT_WINDOWSIZE 1 +/// +/// The valid range of window size option. +/// Note that: RFC 7440 does not mention max window size value, but for the +/// stability reason, the value is limited to 64. +/// +#define MTFTP_MIN_WINDOWSIZE 1 +#define MTFTP_MAX_WINDOWSIZE 64 /** Function for 'tftp' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @@ -286,19 +298,21 @@ RunTftp ( UINTN FileSize; UINTN DataSize; VOID*Data; SHELL_FILE_HANDLE FileHandle; UINT16 BlockSize; + UINT16 WindowSize; ShellStatus = SHELL_INVALID_PARAMETER; ProblemParam= NULL; NicFound= FALSE; AsciiRemoteFilePath = NULL; Handles = NULL; FileSize= 0; DataSize= 0; BlockSize = MTFTP_DEFAULT_BLKSIZE; + WindowSize = MTFTP_DEFAULT_WINDOWSIZE; // // Initialize the Shell library (we must be in non-auto-init...) // Status = ShellInitialize (); @@ -434,10 +448,24 @@ RunTftp ( ); goto Error; } } + ValueStr = ShellCommandLineGetValue (CheckPackage, L"-w"); + if (ValueStr != NULL) { +if (!StringToUint16 (ValueStr, )) { + goto Error; +} +if (WindowSize < MTFTP_MIN_WINDOWSIZE || WindowSize > MTFTP_MAX_WINDOWSIZE) { + ShellPrintHiiEx ( +-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), +mTftpHiiHandle, L"tftp", ValueStr + ); + goto Error; +} + } + // // Locate all MTFTP4 Service Binding protocols // ShellStatus = SHELL_NOT_FOUND; Status = gBS->LocateHandleBuffer ( @@ -508,11 +536,11 @@ RunTftp ( mTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } -Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, ); +Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, WindowSize, ); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD), mTftpHiiHandle, RemoteFilePath, NicName, Status ); @@ -894,20 +922,21 @@ DownloadFile ( IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR16 *FilePath, IN CONST CHAR8 *AsciiFilePath, IN UINTNFileSize, IN UINT16 BlockSize, + IN UINT16 WindowSize, OUT VOID **Data ) { EFI_STATUSStatus; 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]; // 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