Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame] | 1 | /** @file
|
| 2 | Main file for Disconnect shell Driver1 function.
|
| 3 |
|
| 4 | (C) Copyright 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
|
| 10 |
|
| 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.
|
| 13 |
|
| 14 | **/
|
| 15 |
|
| 16 | #include "UefiShellDriver1CommandsLib.h"
|
| 17 |
|
| 18 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
| 19 | {L"-r", TypeFlag},
|
| 20 | {NULL, TypeMax}
|
| 21 | };
|
| 22 |
|
| 23 | /**
|
| 24 | Disconnect everything.
|
| 25 |
|
| 26 | @retval EFI_SUCCESS The operation was successful.
|
| 27 | **/
|
| 28 | EFI_STATUS
|
| 29 | EFIAPI
|
| 30 | DisconnectAll(
|
| 31 | VOID
|
| 32 | )
|
| 33 | {
|
| 34 | //
|
| 35 | // Stolen from UEFI 2.3 spec (May 2009 version)
|
| 36 | // Pages 171/172
|
| 37 | // Removed gBS local definition
|
| 38 | //
|
| 39 |
|
| 40 | //
|
| 41 | // Disconnect All Handles Example
|
| 42 | // The following example recusively disconnects all drivers from all
|
| 43 | // controllers in a platform.
|
| 44 | //
|
| 45 | EFI_STATUS Status;
|
| 46 | // EFI_BOOT_SERVICES *gBS;
|
| 47 | UINTN HandleCount;
|
| 48 | EFI_HANDLE *HandleBuffer;
|
| 49 | UINTN HandleIndex;
|
| 50 | //
|
| 51 | // Retrieve the list of all handles from the handle database
|
| 52 | //
|
| 53 | Status = gBS->LocateHandleBuffer (
|
| 54 | AllHandles,
|
| 55 | NULL,
|
| 56 | NULL,
|
| 57 | &HandleCount,
|
| 58 | &HandleBuffer
|
| 59 | );
|
| 60 | if (!EFI_ERROR (Status)) {
|
| 61 | for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
| 62 | Status = gBS->DisconnectController (
|
| 63 | HandleBuffer[HandleIndex],
|
| 64 | NULL,
|
| 65 | NULL
|
| 66 | );
|
| 67 | }
|
| 68 | gBS->FreePool(HandleBuffer);
|
| 69 | //
|
| 70 | // end of stealing
|
| 71 | //
|
| 72 | }
|
| 73 | return (EFI_SUCCESS);
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | Function for 'disconnect' command.
|
| 78 |
|
| 79 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
| 80 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
| 81 | **/
|
| 82 | SHELL_STATUS
|
| 83 | EFIAPI
|
| 84 | ShellCommandRunDisconnect (
|
| 85 | IN EFI_HANDLE ImageHandle,
|
| 86 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 87 | )
|
| 88 | {
|
| 89 | EFI_STATUS Status;
|
| 90 | LIST_ENTRY *Package;
|
| 91 | CHAR16 *ProblemParam;
|
| 92 | SHELL_STATUS ShellStatus;
|
| 93 | CONST CHAR16 *Param1;
|
| 94 | CONST CHAR16 *Param2;
|
| 95 | CONST CHAR16 *Param3;
|
| 96 | EFI_HANDLE Handle1;
|
| 97 | EFI_HANDLE Handle2;
|
| 98 | EFI_HANDLE Handle3;
|
| 99 | UINT64 Intermediate1;
|
| 100 | UINT64 Intermediate2;
|
| 101 | UINT64 Intermediate3;
|
| 102 |
|
| 103 | ShellStatus = SHELL_SUCCESS;
|
| 104 |
|
| 105 | //
|
| 106 | // initialize the shell lib (we must be in non-auto-init...)
|
| 107 | //
|
| 108 | Status = ShellInitialize();
|
| 109 | ASSERT_EFI_ERROR(Status);
|
| 110 |
|
| 111 | Status = CommandInit();
|
| 112 | ASSERT_EFI_ERROR(Status);
|
| 113 |
|
| 114 | //
|
| 115 | // parse the command line
|
| 116 | //
|
| 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;
|
| 123 | } else {
|
| 124 | ASSERT(FALSE);
|
| 125 | }
|
| 126 | } else {
|
| 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;
|
| 134 | } else {
|
| 135 | Status = DisconnectAll();
|
| 136 | }
|
| 137 | } else {
|
| 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;
|
| 144 | } else {
|
| 145 | //
|
| 146 | // must have between 1 and 3 handles passed in ...
|
| 147 | //
|
| 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;
|
| 157 |
|
| 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;
|
| 171 | } else {
|
| 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);
|
| 175 | }
|
| 176 | }
|
| 177 | }
|
| 178 | }
|
| 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;
|
| 186 | }
|
| 187 | }
|
| 188 | return (ShellStatus);
|
| 189 | }
|