]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/TftpDynamicCommand: Add one option for tftp command to specify windowsize.
authorJiaxin Wu <Jiaxin.wu@intel.com>
Fri, 14 Sep 2018 07:48:17 +0000 (15:48 +0800)
committerJiaxin Wu <Jiaxin.wu@intel.com>
Thu, 27 Sep 2018 01:00:01 +0000 (09:00 +0800)
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>
ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c
ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.uni

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