]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c
ShellPkg/tftp: Convert from NULL class library to Dynamic Command
[mirror_edk2.git] / ShellPkg / DynamicCommand / TftpDynamicCommand / TftpDynamicCommand.c
CommitLineData
09610023
RN
1/** @file\r
2 Produce "tftp" shell dynamic command.\r
3\r
4 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
5 Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16#include "Tftp.h"\r
17#include <Protocol/ShellDynamicCommand.h>\r
18\r
19/**\r
20 This is the shell command handler function pointer callback type. This\r
21 function handles the command when it is invoked in the shell.\r
22\r
23 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.\r
24 @param[in] SystemTable The pointer to the system table.\r
25 @param[in] ShellParameters The parameters associated with the command.\r
26 @param[in] Shell The instance of the shell protocol used in the context\r
27 of processing this command.\r
28\r
29 @return EFI_SUCCESS the operation was sucessful\r
30 @return other the operation failed.\r
31**/\r
32SHELL_STATUS\r
33EFIAPI\r
34TftpCommandHandler (\r
35 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,\r
36 IN EFI_SYSTEM_TABLE *SystemTable,\r
37 IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
38 IN EFI_SHELL_PROTOCOL *Shell\r
39 )\r
40{\r
41 gEfiShellParametersProtocol = ShellParameters;\r
42 return RunTftp (gImageHandle, SystemTable);\r
43}\r
44\r
45/**\r
46 This is the command help handler function pointer callback type. This\r
47 function is responsible for displaying help information for the associated\r
48 command.\r
49\r
50 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.\r
51 @param[in] Language The pointer to the language string to use.\r
52\r
53 @return string Pool allocated help string, must be freed by caller\r
54**/\r
55CHAR16 *\r
56EFIAPI\r
57TftpCommandGetHelp (\r
58 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,\r
59 IN CONST CHAR8 *Language\r
60 )\r
61{\r
62 return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), Language);\r
63}\r
64\r
65EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {\r
66 L"tftp",\r
67 TftpCommandHandler,\r
68 TftpCommandGetHelp\r
69};\r
70\r
71/**\r
72 Entry point of Tftp Dynamic Command.\r
73\r
74 Produce the DynamicCommand protocol to handle "tftp" command.\r
75\r
76 @param ImageHandle The image handle of the process.\r
77 @param SystemTable The EFI System Table pointer.\r
78\r
79 @retval EFI_SUCCESS Tftp command is executed sucessfully.\r
80 @retval EFI_ABORTED HII package was failed to initialize.\r
81 @retval others Other errors when executing tftp command.\r
82**/\r
83EFI_STATUS\r
84EFIAPI\r
85TftpCommandInitialize (\r
86 IN EFI_HANDLE ImageHandle,\r
87 IN EFI_SYSTEM_TABLE *SystemTable\r
88 )\r
89{\r
90 EFI_STATUS Status;\r
91 mTftpHiiHandle = InitializeHiiPackage (ImageHandle);\r
92 if (mTftpHiiHandle == NULL) {\r
93 return EFI_ABORTED;\r
94 }\r
95\r
96 Status = gBS->InstallProtocolInterface (\r
97 &ImageHandle,\r
98 &gEfiShellDynamicCommandProtocolGuid,\r
99 EFI_NATIVE_INTERFACE,\r
100 &mTftpDynamicCommand\r
101 );\r
102 ASSERT_EFI_ERROR (Status);\r
103 return Status;\r
104}\r
105\r
106/**\r
107 Tftp driver unload handler.\r
108\r
109 @param ImageHandle The image handle of the process.\r
110\r
111 @retval EFI_SUCCESS The image is unloaded.\r
112 @retval Others Failed to unload the image.\r
113**/\r
114EFI_STATUS\r
115EFIAPI\r
116TftpUnload (\r
117 IN EFI_HANDLE ImageHandle\r
118)\r
119{\r
120 EFI_STATUS Status;\r
121 Status = gBS->UninstallProtocolInterface (\r
122 ImageHandle,\r
123 &gEfiShellDynamicCommandProtocolGuid,\r
124 &mTftpDynamicCommand\r
125 );\r
126 if (EFI_ERROR (Status)) {\r
127 return Status;\r
128 }\r
129 HiiRemovePackages (mTftpHiiHandle);\r
130 return EFI_SUCCESS;\r
131}\r