]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c
IntelFsp2WrapperPkg/FspmWrapperPeim: Update debug message match code.
[mirror_edk2.git] / ShellPkg / Library / UefiShellTftpCommandLib / Tftp.c
index d2f7046de037cdcaacce7a7265f4cbd2ca4e3e0d..831b9c3d0250c342a4c19ee0073d5be65fe90981 100644 (file)
@@ -2,6 +2,8 @@
   The implementation for the 'tftp' Shell command.\r
 \r
   Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2015, Intel Corporation. All rights reserved. <BR>\r
+  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -14,6 +16,8 @@
 \r
 #include "UefiShellTftpCommandLib.h"\r
 \r
+#define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32\r
+\r
 /*\r
    Constant strings and definitions related to the message indicating the amount of\r
    progress in the dowloading of a TFTP file.\r
@@ -59,7 +63,8 @@ StringToUint16 (
   @param[in]   NicNumber         The network physical device number.\r
   @param[out]  NicName           Address where to store the NIC name.\r
                                  The memory area has to be at least\r
-                                 IP4_NIC_NAME_LENGTH bytes wide.\r
+                                 IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH \r
+                                 double byte wide.\r
 \r
   @return  EFI_SUCCESS  The name of the NIC was returned.\r
   @return  Others       The creation of the child for the Managed\r
@@ -192,6 +197,7 @@ DownloadFile (
 **/\r
 STATIC \r
 EFI_STATUS \r
+EFIAPI\r
 CheckPacket (\r
   IN EFI_MTFTP4_PROTOCOL  *This,\r
   IN EFI_MTFTP4_TOKEN     *Token,\r
@@ -258,7 +264,7 @@ ShellCommandRunTftp (
   EFI_HANDLE              *Handles;\r
   UINTN                   HandleCount;\r
   UINTN                   NicNumber;\r
-  CHAR16                  NicName[IP4_NIC_NAME_LENGTH];\r
+  CHAR16                  NicName[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH];\r
   EFI_HANDLE              ControllerHandle;\r
   EFI_HANDLE              Mtftp4ChildHandle;\r
   EFI_MTFTP4_PROTOCOL     *Mtftp4;\r
@@ -271,6 +277,7 @@ ShellCommandRunTftp (
   NicFound            = FALSE;\r
   AsciiRemoteFilePath = NULL;\r
   Handles             = NULL;\r
+  FileSize            = 0;\r
 \r
   //\r
   // Initialize the Shell library (we must be in non-auto-init...)\r
@@ -334,6 +341,7 @@ ShellCommandRunTftp (
   }\r
 \r
   RemoteFilePath = ShellCommandLineGetRawValue (CheckPackage, 2);\r
+  ASSERT(RemoteFilePath != NULL);\r
   AsciiRemoteFilePath = AllocatePool (\r
                           (StrLen (RemoteFilePath) + 1) * sizeof (CHAR8)\r
                           );\r
@@ -571,7 +579,7 @@ StringToUint16 (
     return FALSE;\r
   }\r
 \r
-  *Value = Val;\r
+  *Value = (UINT16)Val;\r
   return TRUE;\r
 }\r
 \r
@@ -582,7 +590,8 @@ StringToUint16 (
   @param[in]   NicNumber         The network physical device number.\r
   @param[out]  NicName           Address where to store the NIC name.\r
                                  The memory area has to be at least\r
-                                 IP4_NIC_NAME_LENGTH bytes wide.\r
+                                 IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH \r
+                                 double byte wide.\r
 \r
   @return  EFI_SUCCESS  The name of the NIC was returned.\r
   @return  Others       The creation of the child for the Managed\r
@@ -623,7 +632,7 @@ GetNicName (
 \r
   UnicodeSPrint (\r
     NicName,\r
-    IP4_NIC_NAME_LENGTH,\r
+    IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH,\r
     SnpMode.IfType == NET_IFTYPE_ETHERNET ?\r
     L"eth%d" :\r
     L"unk%d" ,\r
@@ -933,6 +942,7 @@ Error :
 **/\r
 STATIC\r
 EFI_STATUS\r
+EFIAPI\r
 CheckPacket (\r
   IN EFI_MTFTP4_PROTOCOL  *This,\r
   IN EFI_MTFTP4_TOKEN     *Token,\r
@@ -942,10 +952,11 @@ CheckPacket (
 {\r
   DOWNLOAD_CONTEXT  *Context;\r
   CHAR16            Progress[TFTP_PROGRESS_MESSAGE_SIZE];\r
-  UINT64            NbOfKb;\r
+  UINT            NbOfKb;\r
   UINTN             Index;\r
   UINTN             LastStep;\r
   UINTN             Step;\r
+  EFI_STATUS        Status;\r
 \r
   if ((NTOHS (Packet->OpCode)) != EFI_MTFTP4_OPCODE_DATA) {\r
     return EFI_SUCCESS;\r
@@ -966,17 +977,19 @@ CheckPacket (
   NbOfKb = Context->DownloadedNbOfBytes / 1024;\r
 \r
   Progress[0] = L'\0';\r
-  LastStep  = (Context->LastReportedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) /\r
-              Context->FileSize;\r
-  Step      = (Context->DownloadedNbOfBytes   * TFTP_PROGRESS_SLIDER_STEPS) /\r
-              Context->FileSize;\r
+  LastStep  = (Context->LastReportedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
+  Step      = (Context->DownloadedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
+\r
   if (Step <= LastStep) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   ShellPrintEx (-1, -1, L"%s", mTftpProgressDelete);\r
 \r
-  StrCpy (Progress, mTftpProgressFrame);\r
+  Status = StrCpyS (Progress, TFTP_PROGRESS_MESSAGE_SIZE, mTftpProgressFrame);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
   for (Index = 1; Index < Step; Index++) {\r
     Progress[Index] = L'=';\r
   }\r