1 | /** @file
|
---|
2 | Main file for Disconnect shell Driver1 function.
|
---|
3 |
|
---|
4 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials
|
---|
6 | are licensed and made available under the terms and conditions of the BSD License
|
---|
7 | which accompanies this distribution. The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include "UefiShellDriver1CommandsLib.h"
|
---|
16 |
|
---|
17 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
---|
18 | {L"-r", TypeFlag},
|
---|
19 | {NULL, TypeMax}
|
---|
20 | };
|
---|
21 |
|
---|
22 | /**
|
---|
23 | Disconnect everything.
|
---|
24 |
|
---|
25 | @retval EFI_SUCCESS The operation was successful.
|
---|
26 | **/
|
---|
27 | EFI_STATUS
|
---|
28 | EFIAPI
|
---|
29 | DisconnectAll(
|
---|
30 | VOID
|
---|
31 | )
|
---|
32 | {
|
---|
33 | //
|
---|
34 | // Stolen from UEFI 2.3 spec (May 2009 version)
|
---|
35 | // Pages 171/172
|
---|
36 | // Removed gBS local definition
|
---|
37 | //
|
---|
38 |
|
---|
39 | //
|
---|
40 | // Disconnect All Handles Example
|
---|
41 | // The following example recusively disconnects all drivers from all
|
---|
42 | // controllers in a platform.
|
---|
43 | //
|
---|
44 | EFI_STATUS Status;
|
---|
45 | // EFI_BOOT_SERVICES *gBS;
|
---|
46 | UINTN HandleCount;
|
---|
47 | EFI_HANDLE *HandleBuffer;
|
---|
48 | UINTN HandleIndex;
|
---|
49 | //
|
---|
50 | // Retrieve the list of all handles from the handle database
|
---|
51 | //
|
---|
52 | Status = gBS->LocateHandleBuffer (
|
---|
53 | AllHandles,
|
---|
54 | NULL,
|
---|
55 | NULL,
|
---|
56 | &HandleCount,
|
---|
57 | &HandleBuffer
|
---|
58 | );
|
---|
59 | if (!EFI_ERROR (Status)) {
|
---|
60 | for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
---|
61 | Status = gBS->DisconnectController (
|
---|
62 | HandleBuffer[HandleIndex],
|
---|
63 | NULL,
|
---|
64 | NULL
|
---|
65 | );
|
---|
66 | }
|
---|
67 | gBS->FreePool(HandleBuffer);
|
---|
68 | //
|
---|
69 | // end of stealing
|
---|
70 | //
|
---|
71 | }
|
---|
72 | return (EFI_SUCCESS);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | Function for 'disconnect' command.
|
---|
77 |
|
---|
78 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
---|
79 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
---|
80 | **/
|
---|
81 | SHELL_STATUS
|
---|
82 | EFIAPI
|
---|
83 | ShellCommandRunDisconnect (
|
---|
84 | IN EFI_HANDLE ImageHandle,
|
---|
85 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
86 | )
|
---|
87 | {
|
---|
88 | EFI_STATUS Status;
|
---|
89 | LIST_ENTRY *Package;
|
---|
90 | CHAR16 *ProblemParam;
|
---|
91 | SHELL_STATUS ShellStatus;
|
---|
92 | CONST CHAR16 *Param1;
|
---|
93 | CONST CHAR16 *Param2;
|
---|
94 | CONST CHAR16 *Param3;
|
---|
95 | EFI_HANDLE Handle1;
|
---|
96 | EFI_HANDLE Handle2;
|
---|
97 | EFI_HANDLE Handle3;
|
---|
98 | UINT64 Intermediate1;
|
---|
99 | UINT64 Intermediate2;
|
---|
100 | UINT64 Intermediate3;
|
---|
101 |
|
---|
102 | ShellStatus = SHELL_SUCCESS;
|
---|
103 |
|
---|
104 | //
|
---|
105 | // initialize the shell lib (we must be in non-auto-init...)
|
---|
106 | //
|
---|
107 | Status = ShellInitialize();
|
---|
108 | ASSERT_EFI_ERROR(Status);
|
---|
109 |
|
---|
110 | Status = CommandInit();
|
---|
111 | ASSERT_EFI_ERROR(Status);
|
---|
112 |
|
---|
113 | //
|
---|
114 | // parse the command line
|
---|
115 | //
|
---|
116 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
---|
117 | if (EFI_ERROR(Status)) {
|
---|
118 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
---|
119 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
|
---|
120 | FreePool(ProblemParam);
|
---|
121 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
122 | } else {
|
---|
123 | ASSERT(FALSE);
|
---|
124 | }
|
---|
125 | } else {
|
---|
126 | if (ShellCommandLineGetFlag(Package, L"-r")){
|
---|
127 | if (ShellCommandLineGetCount(Package) > 1){
|
---|
128 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
|
---|
129 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
130 | } else if (ShellCommandLineGetCount(Package) < 1) {
|
---|
131 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle);
|
---|
132 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
133 | } else {
|
---|
134 | Status = DisconnectAll();
|
---|
135 | }
|
---|
136 | } else {
|
---|
137 | if (ShellCommandLineGetCount(Package) > 4){
|
---|
138 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
|
---|
139 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
140 | } else if (ShellCommandLineGetCount(Package) < 2) {
|
---|
141 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle);
|
---|
142 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
143 | } else {
|
---|
144 | //
|
---|
145 | // must have between 1 and 3 handles passed in ...
|
---|
146 | //
|
---|
147 | Param1 = ShellCommandLineGetRawValue(Package, 1);
|
---|
148 | Param2 = ShellCommandLineGetRawValue(Package, 2);
|
---|
149 | Param3 = ShellCommandLineGetRawValue(Package, 3);
|
---|
150 | ShellConvertStringToUint64(Param1, &Intermediate1, TRUE, FALSE);
|
---|
151 | Handle1 = Param1!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate1):NULL;
|
---|
152 | ShellConvertStringToUint64(Param2, &Intermediate2, TRUE, FALSE);
|
---|
153 | Handle2 = Param2!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate2):NULL;
|
---|
154 | ShellConvertStringToUint64(Param3, &Intermediate3, TRUE, FALSE);
|
---|
155 | Handle3 = Param3!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate3):NULL;
|
---|
156 |
|
---|
157 | if (Param1 != NULL && Handle1 == NULL) {
|
---|
158 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1);
|
---|
159 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
160 | } else if (Param2 != NULL && Handle2 == NULL) {
|
---|
161 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2);
|
---|
162 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
163 | } else if (Param3 != NULL && Handle3 == NULL) {
|
---|
164 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param3);
|
---|
165 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
166 | } else if (Handle2 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
|
---|
167 | ASSERT(Param2 != NULL);
|
---|
168 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, ShellStrToUintn(Param2), L"driver handle");
|
---|
169 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
170 | } else {
|
---|
171 | ASSERT(Param1 != NULL);
|
---|
172 | Status = gBS->DisconnectController(Handle1, Handle2, Handle3);
|
---|
173 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", (UINTN)Intermediate1, (UINTN)Intermediate2, (UINTN)Intermediate3, Status);
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 | if (ShellStatus == SHELL_SUCCESS) {
|
---|
179 | if (Status == EFI_SECURITY_VIOLATION) {
|
---|
180 | ShellStatus = SHELL_SECURITY_VIOLATION;
|
---|
181 | } else if (Status == EFI_INVALID_PARAMETER) {
|
---|
182 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
183 | } else if (EFI_ERROR(Status)) {
|
---|
184 | ShellStatus = SHELL_NOT_FOUND;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | return (ShellStatus);
|
---|
188 | }
|
---|