]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c
ShellPkg/tftp: Convert from NULL class library to Dynamic Command
[mirror_edk2.git] / ShellPkg / DynamicCommand / TftpDynamicCommand / TftpDynamicCommand.c
diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c
new file mode 100644 (file)
index 0000000..928ef08
--- /dev/null
@@ -0,0 +1,131 @@
+/** @file\r
+  Produce "tftp" shell dynamic command.\r
+\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2015, ARM Ltd. All rights reserved.<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
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include "Tftp.h"\r
+#include <Protocol/ShellDynamicCommand.h>\r
+\r
+/**\r
+  This is the shell command handler function pointer callback type.  This\r
+  function handles the command when it is invoked in the shell.\r
+\r
+  @param[in] This                   The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.\r
+  @param[in] SystemTable            The pointer to the system table.\r
+  @param[in] ShellParameters        The parameters associated with the command.\r
+  @param[in] Shell                  The instance of the shell protocol used in the context\r
+                                    of processing this command.\r
+\r
+  @return EFI_SUCCESS               the operation was sucessful\r
+  @return other                     the operation failed.\r
+**/\r
+SHELL_STATUS\r
+EFIAPI\r
+TftpCommandHandler (\r
+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable,\r
+  IN EFI_SHELL_PARAMETERS_PROTOCOL         *ShellParameters,\r
+  IN EFI_SHELL_PROTOCOL                    *Shell\r
+  )\r
+{\r
+  gEfiShellParametersProtocol = ShellParameters;\r
+  return RunTftp (gImageHandle, SystemTable);\r
+}\r
+\r
+/**\r
+  This is the command help handler function pointer callback type.  This\r
+  function is responsible for displaying help information for the associated\r
+  command.\r
+\r
+  @param[in] This                   The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.\r
+  @param[in] Language               The pointer to the language string to use.\r
+\r
+  @return string                    Pool allocated help string, must be freed by caller\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+TftpCommandGetHelp (\r
+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,\r
+  IN CONST CHAR8                           *Language\r
+  )\r
+{\r
+  return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), Language);\r
+}\r
+\r
+EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {\r
+  L"tftp",\r
+  TftpCommandHandler,\r
+  TftpCommandGetHelp\r
+};\r
+\r
+/**\r
+  Entry point of Tftp Dynamic Command.\r
+\r
+  Produce the DynamicCommand protocol to handle "tftp" command.\r
+\r
+  @param ImageHandle            The image handle of the process.\r
+  @param SystemTable            The EFI System Table pointer.\r
+\r
+  @retval EFI_SUCCESS           Tftp command is executed sucessfully.\r
+  @retval EFI_ABORTED           HII package was failed to initialize.\r
+  @retval others                Other errors when executing tftp command.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TftpCommandInitialize (\r
+  IN EFI_HANDLE               ImageHandle,\r
+  IN EFI_SYSTEM_TABLE         *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  mTftpHiiHandle = InitializeHiiPackage (ImageHandle);\r
+  if (mTftpHiiHandle == NULL) {\r
+    return EFI_ABORTED;\r
+  }\r
+\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &ImageHandle,\r
+                  &gEfiShellDynamicCommandProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mTftpDynamicCommand\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Tftp driver unload handler.\r
+\r
+  @param ImageHandle            The image handle of the process.\r
+\r
+  @retval EFI_SUCCESS           The image is unloaded.\r
+  @retval Others                Failed to unload the image.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TftpUnload (\r
+  IN EFI_HANDLE               ImageHandle\r
+)\r
+{\r
+  EFI_STATUS                  Status;\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  ImageHandle,\r
+                  &gEfiShellDynamicCommandProtocolGuid,\r
+                  &mTftpDynamicCommand\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  HiiRemovePackages (mTftpHiiHandle);\r
+  return EFI_SUCCESS;\r
+}\r