TianoCore EDK2 master
Loading...
Searching...
No Matches
Disconnect.c
Go to the documentation of this file.
1
12
13STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
14 { L"-r", TypeFlag },
15 { L"-nc", TypeFlag },
16 { NULL, TypeMax }
17};
18
26 VOID
27 )
28{
29 //
30 // Stolen from UEFI 2.3 spec (May 2009 version)
31 // Pages 171/172
32 // Removed gBS local definition
33 //
34
35 //
36 // Disconnect All Handles Example
37 // The following example recusively disconnects all drivers from all
38 // controllers in a platform.
39 //
40 EFI_STATUS Status;
41 // EFI_BOOT_SERVICES *gBS;
42 UINTN HandleCount;
43 EFI_HANDLE *HandleBuffer;
44 UINTN HandleIndex;
45
46 //
47 // Retrieve the list of all handles from the handle database
48 //
49 Status = gBS->LocateHandleBuffer (
51 NULL,
52 NULL,
53 &HandleCount,
54 &HandleBuffer
55 );
56 if (!EFI_ERROR (Status)) {
57 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
58 Status = gBS->DisconnectController (
59 HandleBuffer[HandleIndex],
60 NULL,
61 NULL
62 );
63 }
64
65 gBS->FreePool (HandleBuffer);
66 //
67 // end of stealing
68 //
69 }
70
71 return (EFI_SUCCESS);
72}
73
81EFIAPI
83 IN EFI_HANDLE ImageHandle,
84 IN EFI_SYSTEM_TABLE *SystemTable
85 )
86{
87 EFI_STATUS Status;
88 LIST_ENTRY *Package;
89 CHAR16 *ProblemParam;
90 SHELL_STATUS ShellStatus;
91 CONST CHAR16 *Param1;
92 CONST CHAR16 *Param2;
93 CONST CHAR16 *Param3;
94 EFI_HANDLE Handle1;
95 EFI_HANDLE Handle2;
96 EFI_HANDLE Handle3;
97 UINT64 Intermediate1;
98 UINT64 Intermediate2;
99 UINT64 Intermediate3;
100
101 Intermediate1 = 0;
102 Intermediate2 = 0;
103 Intermediate3 = 0;
104 ShellStatus = SHELL_SUCCESS;
105
106 //
107 // initialize the shell lib (we must be in non-auto-init...)
108 //
109 Status = ShellInitialize ();
110 ASSERT_EFI_ERROR (Status);
111
112 Status = CommandInit ();
113 ASSERT_EFI_ERROR (Status);
114
115 //
116 // parse the command line
117 //
118 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
119 if (EFI_ERROR (Status)) {
120 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
121 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"disconnect", ProblemParam);
122 FreePool (ProblemParam);
123 ShellStatus = SHELL_INVALID_PARAMETER;
124 } else {
125 ASSERT (FALSE);
126 }
127 } else {
128 if (ShellCommandLineGetFlag (Package, L"-r")) {
129 if (ShellCommandLineGetCount (Package) > 1) {
130 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"disconnect");
131 ShellStatus = SHELL_INVALID_PARAMETER;
132 } else if (ShellCommandLineGetCount (Package) < 1) {
133 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect");
134 ShellStatus = SHELL_INVALID_PARAMETER;
135 } else {
136 Status = DisconnectAll ();
137 //
138 // Reconnect all consoles if -nc is not provided
139 //
140 if (!ShellCommandLineGetFlag (Package, L"-nc")) {
141 ShellConnectFromDevPaths (L"ConInDev");
142 ShellConnectFromDevPaths (L"ConOutDev");
143 ShellConnectFromDevPaths (L"ErrOutDev");
144 ShellConnectFromDevPaths (L"ErrOut");
145 ShellConnectFromDevPaths (L"ConIn");
146 ShellConnectFromDevPaths (L"ConOut");
147 }
148 }
149 } else if (ShellCommandLineGetFlag (Package, L"-nc")) {
150 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect");
151 ShellStatus = SHELL_INVALID_PARAMETER;
152 } else {
153 if (ShellCommandLineGetCount (Package) > 4) {
154 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"disconnect");
155 ShellStatus = SHELL_INVALID_PARAMETER;
156 } else if (ShellCommandLineGetCount (Package) < 2) {
157 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect");
158 ShellStatus = SHELL_INVALID_PARAMETER;
159 } else {
160 //
161 // must have between 1 and 3 handles passed in ...
162 //
163 Param1 = ShellCommandLineGetRawValue (Package, 1);
164 Param2 = ShellCommandLineGetRawValue (Package, 2);
165 Param3 = ShellCommandLineGetRawValue (Package, 3);
166
167 if (Param1 && !EFI_ERROR (ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE))) {
168 Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate1);
169 } else {
170 Handle1 = NULL;
171 }
172
173 if (Param2 && !EFI_ERROR (ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE))) {
174 Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate2);
175 } else {
176 Handle2 = NULL;
177 }
178
179 if (Param3 && !EFI_ERROR (ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE))) {
180 Handle3 = ConvertHandleIndexToHandle ((UINTN)Intermediate3);
181 } else {
182 Handle3 = NULL;
183 }
184
185 if ((Param1 != NULL) && (Handle1 == NULL)) {
186 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param1);
187 ShellStatus = SHELL_INVALID_PARAMETER;
188 } else if ((Param2 != NULL) && (Handle2 == NULL)) {
189 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param2);
190 ShellStatus = SHELL_INVALID_PARAMETER;
191 } else if ((Param3 != NULL) && (Handle3 == NULL)) {
192 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param3);
193 ShellStatus = SHELL_INVALID_PARAMETER;
194 } else if ((Handle2 != NULL) && EFI_ERROR (gBS->OpenProtocol (Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
195 ASSERT (Param2 != NULL);
196 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, L"disconnect", ShellStrToUintn (Param2), L"driver handle");
197 ShellStatus = SHELL_INVALID_PARAMETER;
198 } else {
199 ASSERT (Param1 != NULL);
200 Status = gBS->DisconnectController (Handle1, Handle2, Handle3);
201 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", (UINTN)Intermediate1, (UINTN)Intermediate2, (UINTN)Intermediate3, Status);
202 }
203 }
204 }
205 }
206
207 if (ShellStatus == SHELL_SUCCESS) {
208 if (Status == EFI_SECURITY_VIOLATION) {
209 ShellStatus = SHELL_SECURITY_VIOLATION;
210 } else if (Status == EFI_INVALID_PARAMETER) {
211 ShellStatus = SHELL_INVALID_PARAMETER;
212 } else if (EFI_ERROR (Status)) {
213 ShellStatus = SHELL_NOT_FOUND;
214 }
215 }
216
217 return (ShellStatus);
218}
UINT64 UINTN
EFI_STATUS ShellConnectFromDevPaths(IN CONST CHAR16 *Key)
Definition: Connect.c:193
EFI_STATUS DisconnectAll(VOID)
Definition: Disconnect.c:25
SHELL_STATUS EFIAPI ShellCommandRunDisconnect(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Disconnect.c:82
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_HANDLE EFIAPI ConvertHandleIndexToHandle(IN CONST UINTN TheIndex)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_SECURITY_VIOLATION
Definition: Shell.h:141
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI CommandInit(VOID)
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
@ AllHandles
Definition: UefiSpec.h:1509