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 <ting.ye@intel.com> Cc: Fu Siyuan <siyuan.fu@intel.com> Cc: Carsey Jaben <jaben.carsey@intel.com> Cc: Shao Ming <ming.shao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com>
This commit is contained in:
@@ -183,6 +183,7 @@ DownloadFile (
|
|||||||
IN CONST CHAR8 *AsciiFilePath,
|
IN CONST CHAR8 *AsciiFilePath,
|
||||||
IN UINTN FileSize,
|
IN UINTN FileSize,
|
||||||
IN UINT16 BlockSize,
|
IN UINT16 BlockSize,
|
||||||
|
IN UINT16 WindowSize,
|
||||||
OUT VOID **Data
|
OUT VOID **Data
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -227,6 +228,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
|||||||
{L"-c", TypeValue},
|
{L"-c", TypeValue},
|
||||||
{L"-t", TypeValue},
|
{L"-t", TypeValue},
|
||||||
{L"-s", TypeValue},
|
{L"-s", TypeValue},
|
||||||
|
{L"-w", TypeValue},
|
||||||
{NULL , TypeMax}
|
{NULL , TypeMax}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -239,7 +241,17 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
|||||||
///
|
///
|
||||||
#define MTFTP_MIN_BLKSIZE 8
|
#define MTFTP_MIN_BLKSIZE 8
|
||||||
#define MTFTP_MAX_BLKSIZE 65464
|
#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.
|
Function for 'tftp' command.
|
||||||
@@ -288,6 +300,7 @@ RunTftp (
|
|||||||
VOID *Data;
|
VOID *Data;
|
||||||
SHELL_FILE_HANDLE FileHandle;
|
SHELL_FILE_HANDLE FileHandle;
|
||||||
UINT16 BlockSize;
|
UINT16 BlockSize;
|
||||||
|
UINT16 WindowSize;
|
||||||
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
ProblemParam = NULL;
|
ProblemParam = NULL;
|
||||||
@@ -297,6 +310,7 @@ RunTftp (
|
|||||||
FileSize = 0;
|
FileSize = 0;
|
||||||
DataSize = 0;
|
DataSize = 0;
|
||||||
BlockSize = MTFTP_DEFAULT_BLKSIZE;
|
BlockSize = MTFTP_DEFAULT_BLKSIZE;
|
||||||
|
WindowSize = MTFTP_DEFAULT_WINDOWSIZE;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize the Shell library (we must be in non-auto-init...)
|
// Initialize the Shell library (we must be in non-auto-init...)
|
||||||
@@ -436,6 +450,20 @@ RunTftp (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValueStr = ShellCommandLineGetValue (CheckPackage, L"-w");
|
||||||
|
if (ValueStr != NULL) {
|
||||||
|
if (!StringToUint16 (ValueStr, &WindowSize)) {
|
||||||
|
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
|
// Locate all MTFTP4 Service Binding protocols
|
||||||
//
|
//
|
||||||
@@ -510,7 +538,7 @@ RunTftp (
|
|||||||
goto NextHandle;
|
goto NextHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, &Data);
|
Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, WindowSize, &Data);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
ShellPrintHiiEx (
|
ShellPrintHiiEx (
|
||||||
-1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD),
|
-1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD),
|
||||||
@@ -896,6 +924,7 @@ DownloadFile (
|
|||||||
IN CONST CHAR8 *AsciiFilePath,
|
IN CONST CHAR8 *AsciiFilePath,
|
||||||
IN UINTN FileSize,
|
IN UINTN FileSize,
|
||||||
IN UINT16 BlockSize,
|
IN UINT16 BlockSize,
|
||||||
|
IN UINT16 WindowSize,
|
||||||
OUT VOID **Data
|
OUT VOID **Data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -904,8 +933,8 @@ DownloadFile (
|
|||||||
VOID *Buffer;
|
VOID *Buffer;
|
||||||
DOWNLOAD_CONTEXT *TftpContext;
|
DOWNLOAD_CONTEXT *TftpContext;
|
||||||
EFI_MTFTP4_TOKEN Mtftp4Token;
|
EFI_MTFTP4_TOKEN Mtftp4Token;
|
||||||
EFI_MTFTP4_OPTION ReqOpt;
|
UINT8 BlksizeBuf[10];
|
||||||
UINT8 OptBuf[10];
|
UINT8 WindowsizeBuf[10];
|
||||||
|
|
||||||
// Downloaded file can be large. BS.AllocatePages() is more faster
|
// Downloaded file can be large. BS.AllocatePages() is more faster
|
||||||
// than AllocatePool() and avoid fragmentation.
|
// than AllocatePool() and avoid fragmentation.
|
||||||
@@ -938,13 +967,25 @@ DownloadFile (
|
|||||||
Mtftp4Token.Buffer = Buffer;
|
Mtftp4Token.Buffer = Buffer;
|
||||||
Mtftp4Token.CheckPacket = CheckPacket;
|
Mtftp4Token.CheckPacket = CheckPacket;
|
||||||
Mtftp4Token.Context = (VOID*)TftpContext;
|
Mtftp4Token.Context = (VOID*)TftpContext;
|
||||||
if (BlockSize != MTFTP_DEFAULT_BLKSIZE) {
|
Mtftp4Token.OptionCount = 0;
|
||||||
ReqOpt.OptionStr = (UINT8 *) "blksize";
|
Mtftp4Token.OptionList = AllocatePool (sizeof (EFI_MTFTP4_OPTION) * 2);
|
||||||
AsciiSPrint ((CHAR8 *)OptBuf, sizeof (OptBuf), "%d", BlockSize);
|
if (Mtftp4Token.OptionList == NULL) {
|
||||||
ReqOpt.ValueStr = OptBuf;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
|
|
||||||
Mtftp4Token.OptionCount = 1;
|
if (BlockSize != MTFTP_DEFAULT_BLKSIZE) {
|
||||||
Mtftp4Token.OptionList = &ReqOpt;
|
Mtftp4Token.OptionList[Mtftp4Token.OptionCount].OptionStr = (UINT8 *) "blksize";
|
||||||
|
AsciiSPrint ((CHAR8 *) BlksizeBuf, sizeof (BlksizeBuf), "%d", BlockSize);
|
||||||
|
Mtftp4Token.OptionList[Mtftp4Token.OptionCount].ValueStr = BlksizeBuf;
|
||||||
|
Mtftp4Token.OptionCount ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WindowSize != MTFTP_DEFAULT_WINDOWSIZE) {
|
||||||
|
Mtftp4Token.OptionList[Mtftp4Token.OptionCount].OptionStr = (UINT8 *) "windowsize";
|
||||||
|
AsciiSPrint ((CHAR8 *) WindowsizeBuf, sizeof (WindowsizeBuf), "%d", WindowSize);
|
||||||
|
Mtftp4Token.OptionList[Mtftp4Token.OptionCount].ValueStr = WindowsizeBuf;
|
||||||
|
Mtftp4Token.OptionCount ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShellPrintHiiEx (
|
ShellPrintHiiEx (
|
||||||
@@ -960,10 +1001,14 @@ DownloadFile (
|
|||||||
|
|
||||||
Error :
|
Error :
|
||||||
|
|
||||||
if (TftpContext == NULL) {
|
if (TftpContext != NULL) {
|
||||||
FreePool (TftpContext);
|
FreePool (TftpContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Mtftp4Token.OptionList != NULL) {
|
||||||
|
FreePool (Mtftp4Token.OptionList);
|
||||||
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
gBS->FreePages (PagesAddress, EFI_SIZE_TO_PAGES (FileSize));
|
gBS->FreePages (PagesAddress, EFI_SIZE_TO_PAGES (FileSize));
|
||||||
return Status;
|
return Status;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
// /**
|
// /**
|
||||||
//
|
//
|
||||||
// (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
|
// (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
|
||||||
// Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
|
// Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
|
||||||
// This program and the accompanying materials
|
// This program and the accompanying materials
|
||||||
// are licensed and made available under the terms and conditions of the BSD License
|
// 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
|
// which accompanies this distribution. The full text of the license may be found at
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
".SH SYNOPSIS\r\n"
|
".SH SYNOPSIS\r\n"
|
||||||
" \r\n"
|
" \r\n"
|
||||||
"TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"
|
"TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"
|
||||||
" [-s <block size>] host remotefilepath [localfilepath]\r\n"
|
" [-s <block size>] [-w <window size>] host remotefilepath [localfilepath]\r\n"
|
||||||
".SH OPTIONS\r\n"
|
".SH OPTIONS\r\n"
|
||||||
" \r\n"
|
" \r\n"
|
||||||
" -i interface - Specifies an adapter name, i.e., eth0.\r\n"
|
" -i interface - Specifies an adapter name, i.e., eth0.\r\n"
|
||||||
@@ -63,6 +63,8 @@
|
|||||||
" sending a request packet. Default value is 4s.\r\n"
|
" sending a request packet. Default value is 4s.\r\n"
|
||||||
" -s <block size> - Specifies the TFTP blksize option as defined in RFC 2348.\r\n"
|
" -s <block size> - 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"
|
" Valid range is between 8 and 65464, default value is 512.\r\n"
|
||||||
|
" -w <window size> - Specifies the TFTP windowsize option as defined in RFC 7440.\r\n"
|
||||||
|
" Valid range is between 1 and 64, default value is 1.\r\n"
|
||||||
" host - Specify TFTP Server IPv4 address.\r\n"
|
" host - Specify TFTP Server IPv4 address.\r\n"
|
||||||
" remotefilepath - TFTP server file path to download the file.\r\n"
|
" remotefilepath - TFTP server file path to download the file.\r\n"
|
||||||
" localfilepath - Local destination file path.\r\n"
|
" localfilepath - Local destination file path.\r\n"
|
||||||
|
Reference in New Issue
Block a user