2 Main file for Disconnect shell Driver1 function.
4 Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellDriver1CommandsLib.h"
18 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
24 Disconnect everything.
26 @retval EFI_SUCCESS The operation was successful.
35 // Stolen from UEFI 2.3 spec (May 2009 version)
37 // Removed gBS local definition
41 // Disconnect All Handles Example
42 // The following example recusively disconnects all drivers from all
43 // controllers in a platform.
46 // EFI_BOOT_SERVICES *gBS;
48 EFI_HANDLE
*HandleBuffer
;
51 // Retrieve the list of all handles from the handle database
53 Status
= gBS
->LocateHandleBuffer (
60 if (!EFI_ERROR (Status
)) {
61 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
62 Status
= gBS
->DisconnectController (
63 HandleBuffer
[HandleIndex
],
68 gBS
->FreePool(HandleBuffer
);
77 Function for 'disconnect' command.
79 @param[in] ImageHandle Handle to the Image (NULL if Internal).
80 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
84 ShellCommandRunDisconnect (
85 IN EFI_HANDLE ImageHandle
,
86 IN EFI_SYSTEM_TABLE
*SystemTable
92 SHELL_STATUS ShellStatus
;
100 UINT64 Intermediate2
;
101 UINT64 Intermediate3
;
103 ShellStatus
= SHELL_SUCCESS
;
106 // initialize the shell lib (we must be in non-auto-init...)
108 Status
= ShellInitialize();
109 ASSERT_EFI_ERROR(Status
);
111 Status
= CommandInit();
112 ASSERT_EFI_ERROR(Status
);
115 // parse the command line
117 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
118 if (EFI_ERROR(Status
)) {
119 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
120 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"disconnect", ProblemParam
);
121 FreePool(ProblemParam
);
122 ShellStatus
= SHELL_INVALID_PARAMETER
;
127 if (ShellCommandLineGetFlag(Package
, L
"-r")){
128 if (ShellCommandLineGetCount(Package
) > 1){
129 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"disconnect");
130 ShellStatus
= SHELL_INVALID_PARAMETER
;
131 } else if (ShellCommandLineGetCount(Package
) < 1) {
132 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
, L
"disconnect");
133 ShellStatus
= SHELL_INVALID_PARAMETER
;
135 Status
= DisconnectAll();
138 if (ShellCommandLineGetCount(Package
) > 4){
139 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"disconnect");
140 ShellStatus
= SHELL_INVALID_PARAMETER
;
141 } else if (ShellCommandLineGetCount(Package
) < 2) {
142 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
, L
"disconnect");
143 ShellStatus
= SHELL_INVALID_PARAMETER
;
146 // must have between 1 and 3 handles passed in ...
148 Param1
= ShellCommandLineGetRawValue(Package
, 1);
149 Param2
= ShellCommandLineGetRawValue(Package
, 2);
150 Param3
= ShellCommandLineGetRawValue(Package
, 3);
151 ShellConvertStringToUint64(Param1
, &Intermediate1
, TRUE
, FALSE
);
152 Handle1
= Param1
!=NULL
?ConvertHandleIndexToHandle((UINTN
)Intermediate1
):NULL
;
153 ShellConvertStringToUint64(Param2
, &Intermediate2
, TRUE
, FALSE
);
154 Handle2
= Param2
!=NULL
?ConvertHandleIndexToHandle((UINTN
)Intermediate2
):NULL
;
155 ShellConvertStringToUint64(Param3
, &Intermediate3
, TRUE
, FALSE
);
156 Handle3
= Param3
!=NULL
?ConvertHandleIndexToHandle((UINTN
)Intermediate3
):NULL
;
158 if (Param1
!= NULL
&& Handle1
== NULL
) {
159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"disconnect", Param1
);
160 ShellStatus
= SHELL_INVALID_PARAMETER
;
161 } else if (Param2
!= NULL
&& Handle2
== NULL
) {
162 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"disconnect", Param2
);
163 ShellStatus
= SHELL_INVALID_PARAMETER
;
164 } else if (Param3
!= NULL
&& Handle3
== NULL
) {
165 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"disconnect", Param3
);
166 ShellStatus
= SHELL_INVALID_PARAMETER
;
167 } else if (Handle2
!= NULL
&& EFI_ERROR(gBS
->OpenProtocol(Handle2
, &gEfiDriverBindingProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
168 ASSERT(Param2
!= NULL
);
169 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_HANDLE_NOT
), gShellDriver1HiiHandle
, L
"disconnect", ShellStrToUintn(Param2
), L
"driver handle");
170 ShellStatus
= SHELL_INVALID_PARAMETER
;
172 ASSERT(Param1
!= NULL
);
173 Status
= gBS
->DisconnectController(Handle1
, Handle2
, Handle3
);
174 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_3P_RESULT
), gShellDriver1HiiHandle
, L
"Disconnect", (UINTN
)Intermediate1
, (UINTN
)Intermediate2
, (UINTN
)Intermediate3
, Status
);
179 if (ShellStatus
== SHELL_SUCCESS
) {
180 if (Status
== EFI_SECURITY_VIOLATION
) {
181 ShellStatus
= SHELL_SECURITY_VIOLATION
;
182 } else if (Status
== EFI_INVALID_PARAMETER
) {
183 ShellStatus
= SHELL_INVALID_PARAMETER
;
184 } else if (EFI_ERROR(Status
)) {
185 ShellStatus
= SHELL_NOT_FOUND
;
188 return (ShellStatus
);