TftpDynamicCommand.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /** @file
  2. Produce "tftp" shell dynamic command.
  3. Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
  4. Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "Tftp.h"
  8. #include <Protocol/ShellDynamicCommand.h>
  9. /**
  10. This is the shell command handler function pointer callback type. This
  11. function handles the command when it is invoked in the shell.
  12. @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
  13. @param[in] SystemTable The pointer to the system table.
  14. @param[in] ShellParameters The parameters associated with the command.
  15. @param[in] Shell The instance of the shell protocol used in the context
  16. of processing this command.
  17. @return EFI_SUCCESS the operation was successful
  18. @return other the operation failed.
  19. **/
  20. SHELL_STATUS
  21. EFIAPI
  22. TftpCommandHandler (
  23. IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
  24. IN EFI_SYSTEM_TABLE *SystemTable,
  25. IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  26. IN EFI_SHELL_PROTOCOL *Shell
  27. )
  28. {
  29. gEfiShellParametersProtocol = ShellParameters;
  30. gEfiShellProtocol = Shell;
  31. return RunTftp (gImageHandle, SystemTable);
  32. }
  33. /**
  34. This is the command help handler function pointer callback type. This
  35. function is responsible for displaying help information for the associated
  36. command.
  37. @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
  38. @param[in] Language The pointer to the language string to use.
  39. @return string Pool allocated help string, must be freed by caller
  40. **/
  41. CHAR16 *
  42. EFIAPI
  43. TftpCommandGetHelp (
  44. IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
  45. IN CONST CHAR8 *Language
  46. )
  47. {
  48. return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), Language);
  49. }
  50. EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {
  51. L"tftp",
  52. TftpCommandHandler,
  53. TftpCommandGetHelp
  54. };
  55. /**
  56. Entry point of Tftp Dynamic Command.
  57. Produce the DynamicCommand protocol to handle "tftp" command.
  58. @param ImageHandle The image handle of the process.
  59. @param SystemTable The EFI System Table pointer.
  60. @retval EFI_SUCCESS Tftp command is executed successfully.
  61. @retval EFI_ABORTED HII package was failed to initialize.
  62. @retval others Other errors when executing tftp command.
  63. **/
  64. EFI_STATUS
  65. EFIAPI
  66. TftpCommandInitialize (
  67. IN EFI_HANDLE ImageHandle,
  68. IN EFI_SYSTEM_TABLE *SystemTable
  69. )
  70. {
  71. EFI_STATUS Status;
  72. mTftpHiiHandle = InitializeHiiPackage (ImageHandle);
  73. if (mTftpHiiHandle == NULL) {
  74. return EFI_ABORTED;
  75. }
  76. Status = gBS->InstallProtocolInterface (
  77. &ImageHandle,
  78. &gEfiShellDynamicCommandProtocolGuid,
  79. EFI_NATIVE_INTERFACE,
  80. &mTftpDynamicCommand
  81. );
  82. ASSERT_EFI_ERROR (Status);
  83. return Status;
  84. }
  85. /**
  86. Tftp driver unload handler.
  87. @param ImageHandle The image handle of the process.
  88. @retval EFI_SUCCESS The image is unloaded.
  89. @retval Others Failed to unload the image.
  90. **/
  91. EFI_STATUS
  92. EFIAPI
  93. TftpUnload (
  94. IN EFI_HANDLE ImageHandle
  95. )
  96. {
  97. EFI_STATUS Status;
  98. Status = gBS->UninstallProtocolInterface (
  99. ImageHandle,
  100. &gEfiShellDynamicCommandProtocolGuid,
  101. &mTftpDynamicCommand
  102. );
  103. if (EFI_ERROR (Status)) {
  104. return Status;
  105. }
  106. HiiRemovePackages (mTftpHiiHandle);
  107. return EFI_SUCCESS;
  108. }