VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c@ 105670

Last change on this file since 105670 was 101291, checked in by vboxsync, 15 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 7.2 KB
Line 
1/** @file
2 Main file for Disconnect shell Driver1 function.
3
4 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
6 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include "UefiShellDriver1CommandsLib.h"
12
13STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
14 { L"-r", TypeFlag },
15 { L"-nc", TypeFlag },
16 { NULL, TypeMax }
17};
18
19/**
20 Disconnect everything.
21
22 @retval EFI_SUCCESS The operation was successful.
23**/
24EFI_STATUS
25DisconnectAll (
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 (
50 AllHandles,
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
74/**
75 Function for 'disconnect' command.
76
77 @param[in] ImageHandle Handle to the Image (NULL if Internal).
78 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
79**/
80SHELL_STATUS
81EFIAPI
82ShellCommandRunDisconnect (
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 ShellStatus = SHELL_SUCCESS;
102
103 //
104 // initialize the shell lib (we must be in non-auto-init...)
105 //
106 Status = ShellInitialize ();
107 ASSERT_EFI_ERROR (Status);
108
109 Status = CommandInit ();
110 ASSERT_EFI_ERROR (Status);
111
112 //
113 // parse the command line
114 //
115 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
116 if (EFI_ERROR (Status)) {
117 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
118 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"disconnect", ProblemParam);
119 FreePool (ProblemParam);
120 ShellStatus = SHELL_INVALID_PARAMETER;
121 } else {
122 ASSERT (FALSE);
123 }
124 } else {
125 if (ShellCommandLineGetFlag (Package, L"-r")) {
126 if (ShellCommandLineGetCount (Package) > 1) {
127 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"disconnect");
128 ShellStatus = SHELL_INVALID_PARAMETER;
129 } else if (ShellCommandLineGetCount (Package) < 1) {
130 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect");
131 ShellStatus = SHELL_INVALID_PARAMETER;
132 } else {
133 Status = DisconnectAll ();
134 //
135 // Reconnect all consoles if -nc is not provided
136 //
137 if (!ShellCommandLineGetFlag (Package, L"-nc")) {
138 ShellConnectFromDevPaths (L"ConInDev");
139 ShellConnectFromDevPaths (L"ConOutDev");
140 ShellConnectFromDevPaths (L"ErrOutDev");
141 ShellConnectFromDevPaths (L"ErrOut");
142 ShellConnectFromDevPaths (L"ConIn");
143 ShellConnectFromDevPaths (L"ConOut");
144 }
145 }
146 } else if (ShellCommandLineGetFlag (Package, L"-nc")) {
147 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect");
148 ShellStatus = SHELL_INVALID_PARAMETER;
149 } else {
150 if (ShellCommandLineGetCount (Package) > 4) {
151 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"disconnect");
152 ShellStatus = SHELL_INVALID_PARAMETER;
153 } else if (ShellCommandLineGetCount (Package) < 2) {
154 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"disconnect");
155 ShellStatus = SHELL_INVALID_PARAMETER;
156 } else {
157 //
158 // must have between 1 and 3 handles passed in ...
159 //
160 Param1 = ShellCommandLineGetRawValue (Package, 1);
161 Param2 = ShellCommandLineGetRawValue (Package, 2);
162 Param3 = ShellCommandLineGetRawValue (Package, 3);
163
164 if (Param1 && !EFI_ERROR (ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE))) {
165 Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate1);
166 } else {
167 Handle1 = NULL;
168 }
169
170 if (Param2 && !EFI_ERROR (ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE))) {
171 Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate2);
172 } else {
173 Handle2 = NULL;
174 }
175
176 if (Param3 && !EFI_ERROR (ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE))) {
177 Handle3 = ConvertHandleIndexToHandle ((UINTN)Intermediate3);
178 } else {
179 Handle3 = NULL;
180 }
181
182 if ((Param1 != NULL) && (Handle1 == NULL)) {
183 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param1);
184 ShellStatus = SHELL_INVALID_PARAMETER;
185 } else if ((Param2 != NULL) && (Handle2 == NULL)) {
186 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param2);
187 ShellStatus = SHELL_INVALID_PARAMETER;
188 } else if ((Param3 != NULL) && (Handle3 == NULL)) {
189 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param3);
190 ShellStatus = SHELL_INVALID_PARAMETER;
191 } else if ((Handle2 != NULL) && EFI_ERROR (gBS->OpenProtocol (Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
192 ASSERT (Param2 != NULL);
193 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, L"disconnect", ShellStrToUintn (Param2), L"driver handle");
194 ShellStatus = SHELL_INVALID_PARAMETER;
195 } else {
196 ASSERT (Param1 != NULL);
197 Status = gBS->DisconnectController (Handle1, Handle2, Handle3);
198 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", (UINTN)Intermediate1, (UINTN)Intermediate2, (UINTN)Intermediate3, Status);
199 }
200 }
201 }
202 }
203
204 if (ShellStatus == SHELL_SUCCESS) {
205 if (Status == EFI_SECURITY_VIOLATION) {
206 ShellStatus = SHELL_SECURITY_VIOLATION;
207 } else if (Status == EFI_INVALID_PARAMETER) {
208 ShellStatus = SHELL_INVALID_PARAMETER;
209 } else if (EFI_ERROR (Status)) {
210 ShellStatus = SHELL_NOT_FOUND;
211 }
212 }
213
214 return (ShellStatus);
215}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette