2 Main file for OpenInfo shell Driver1 function.
4 Copyright (c) 2010, 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
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.
15 #include "UefiShellDriver1CommandsLib.h"
17 STATIC CONST CHAR16 StringHandProt
[] = L
"HandProt ";
18 STATIC CONST CHAR16 StringGetProt
[] = L
"GetProt ";
19 STATIC CONST CHAR16 StringTestProt
[] = L
"TestProt ";
20 STATIC CONST CHAR16 StringChild
[] = L
"Child ";
21 STATIC CONST CHAR16 StringDriver
[] = L
"Driver ";
22 STATIC CONST CHAR16 StringExclusive
[] = L
"Exclusive";
23 STATIC CONST CHAR16 StringDriverEx
[] = L
"DriverEx ";
24 STATIC CONST CHAR16 StringUnknown
[] = L
"Unknown ";
28 TraverseHandleDatabase (
29 IN CONST EFI_HANDLE TheHandle
33 EFI_GUID
**ProtocolGuidArray
;
36 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
39 CONST CHAR16
*OpenTypeString
;
44 ASSERT(TheHandle
!= NULL
);
47 // Retrieve the list of all the protocols on the handle
49 Status
= gBS
->ProtocolsPerHandle (
54 ASSERT_EFI_ERROR(Status
);
55 if (!EFI_ERROR (Status
)) {
57 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
59 // print out the human readable name for this one.
61 TempString
= GetStringNameFromGuid(ProtocolGuidArray
[ProtocolIndex
], NULL
);
62 if (TempString
== NULL
) {
65 ShellPrintEx(-1, -1, L
"%H%s%N\r\n", TempString
);
69 // Retrieve the list of agents that have opened each protocol
71 Status
= gBS
->OpenProtocolInformation (
73 ProtocolGuidArray
[ProtocolIndex
],
77 ASSERT_EFI_ERROR(Status
);
78 if (!EFI_ERROR (Status
)) {
79 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
80 switch (OpenInfo
[OpenInfoIndex
].Attributes
) {
81 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
: OpenTypeString
= StringHandProt
; break;
82 case EFI_OPEN_PROTOCOL_GET_PROTOCOL
: OpenTypeString
= StringGetProt
; break;
83 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL
: OpenTypeString
= StringTestProt
; break;
84 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
: OpenTypeString
= StringChild
; break;
85 case EFI_OPEN_PROTOCOL_BY_DRIVER
: OpenTypeString
= StringDriver
; break;
86 case EFI_OPEN_PROTOCOL_EXCLUSIVE
: OpenTypeString
= StringExclusive
; break;
87 case EFI_OPEN_PROTOCOL_BY_DRIVER
|EFI_OPEN_PROTOCOL_EXCLUSIVE
:
88 OpenTypeString
= StringDriverEx
; break;
89 default: OpenTypeString
= StringUnknown
; break;
91 HandleIndex
= ConvertHandleToHandleIndex(OpenInfo
[OpenInfoIndex
].AgentHandle
);
92 Name
= GetStringNameFromHandle(OpenInfo
[OpenInfoIndex
].AgentHandle
, "en");
93 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
!=NULL
) {
98 STRING_TOKEN(STR_OPENINFO_LINE
),
99 gShellDriver1HiiHandle
,
101 ConvertHandleToHandleIndex(OpenInfo
[OpenInfoIndex
].ControllerHandle
),
102 OpenInfo
[OpenInfoIndex
].OpenCount
,
111 STRING_TOKEN(STR_OPENINFO_MIN_LINE
),
112 gShellDriver1HiiHandle
,
114 OpenInfo
[OpenInfoIndex
].OpenCount
,
123 FreePool (ProtocolGuidArray
);
130 Function for 'openinfo' command.
132 @param[in] ImageHandle Handle to the Image (NULL if Internal).
133 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
137 ShellCommandRunOpenInfo (
138 IN EFI_HANDLE ImageHandle
,
139 IN EFI_SYSTEM_TABLE
*SystemTable
144 CHAR16
*ProblemParam
;
145 SHELL_STATUS ShellStatus
;
146 EFI_HANDLE TheHandle
;
147 CONST CHAR16
*Param1
;
149 ShellStatus
= SHELL_SUCCESS
;
152 // initialize the shell lib (we must be in non-auto-init...)
154 Status
= ShellInitialize();
155 ASSERT_EFI_ERROR(Status
);
157 Status
= CommandInit();
158 ASSERT_EFI_ERROR(Status
);
161 // parse the command line
163 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
164 if (EFI_ERROR(Status
)) {
165 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
166 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
167 FreePool(ProblemParam
);
168 ShellStatus
= SHELL_INVALID_PARAMETER
;
173 if (ShellCommandLineGetCount(Package
) > 2){
175 // error for too many parameters
177 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
178 ShellStatus
= SHELL_INVALID_PARAMETER
;
179 } else if (ShellCommandLineGetCount(Package
) == 0) {
180 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
);
181 ShellStatus
= SHELL_INVALID_PARAMETER
;
183 Param1
= ShellCommandLineGetRawValue(Package
, 1);
184 if (Param1
== NULL
|| ConvertHandleIndexToHandle(StrHexToUintn(Param1
)) == NULL
){
185 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Param1
);
186 ShellStatus
= SHELL_INVALID_PARAMETER
;
188 TheHandle
= ConvertHandleIndexToHandle(StrHexToUintn(Param1
));
189 ASSERT(TheHandle
!= NULL
);
190 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_OPENINFO_HEADER_LINE
), gShellDriver1HiiHandle
, StrHexToUintn(Param1
), TheHandle
);
192 Status
= TraverseHandleDatabase (TheHandle
);
193 if (!EFI_ERROR(Status
)) {
195 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Param1
);
196 ShellStatus
= SHELL_NOT_FOUND
;
201 return (ShellStatus
);