2 Main file for OpenInfo shell Driver1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDriver1CommandsLib.h"
12 STATIC CONST CHAR16 StringHandProt
[] = L
"HandProt ";
13 STATIC CONST CHAR16 StringGetProt
[] = L
"GetProt ";
14 STATIC CONST CHAR16 StringTestProt
[] = L
"TestProt ";
15 STATIC CONST CHAR16 StringChild
[] = L
"Child ";
16 STATIC CONST CHAR16 StringDriver
[] = L
"Driver ";
17 STATIC CONST CHAR16 StringExclusive
[] = L
"Exclusive";
18 STATIC CONST CHAR16 StringDriverEx
[] = L
"DriverEx ";
19 STATIC CONST CHAR16 StringUnknown
[] = L
"Unknown ";
22 Open the database and print out all the info about TheHandle.
24 @param[in] TheHandle The handle to print info on.
26 @retval EFI_SUCCESS The operation was successful.
27 @retval EFI_INVALID_PARAMETER TheHandle was NULL.
30 TraverseHandleDatabase (
31 IN CONST EFI_HANDLE TheHandle
35 EFI_GUID
**ProtocolGuidArray
;
38 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
41 CONST CHAR16
*OpenTypeString
;
45 UINTN ControllerIndex
;
47 if (TheHandle
== NULL
) {
48 return (EFI_INVALID_PARAMETER
);
52 // Retrieve the list of all the protocols on the handle
54 Status
= gBS
->ProtocolsPerHandle (
59 ASSERT_EFI_ERROR (Status
);
60 if (!EFI_ERROR (Status
)) {
61 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
63 // print out the human readable name for this one.
65 TempString
= GetStringNameFromGuid (ProtocolGuidArray
[ProtocolIndex
], NULL
);
66 if (TempString
== NULL
) {
70 ShellPrintEx (-1, -1, L
"%H%s%N\r\n", TempString
);
71 FreePool (TempString
);
74 // Retrieve the list of agents that have opened each protocol
76 Status
= gBS
->OpenProtocolInformation (
78 ProtocolGuidArray
[ProtocolIndex
],
82 ASSERT_EFI_ERROR (Status
);
83 if (!EFI_ERROR (Status
)) {
84 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
85 switch (OpenInfo
[OpenInfoIndex
].Attributes
) {
86 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
: OpenTypeString
= StringHandProt
;
88 case EFI_OPEN_PROTOCOL_GET_PROTOCOL
: OpenTypeString
= StringGetProt
;
90 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL
: OpenTypeString
= StringTestProt
;
92 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
: OpenTypeString
= StringChild
;
94 case EFI_OPEN_PROTOCOL_BY_DRIVER
: OpenTypeString
= StringDriver
;
96 case EFI_OPEN_PROTOCOL_EXCLUSIVE
: OpenTypeString
= StringExclusive
;
98 case EFI_OPEN_PROTOCOL_BY_DRIVER
|EFI_OPEN_PROTOCOL_EXCLUSIVE
:
99 OpenTypeString
= StringDriverEx
;
101 default: OpenTypeString
= StringUnknown
;
105 HandleIndex
= ConvertHandleToHandleIndex (OpenInfo
[OpenInfoIndex
].AgentHandle
);
106 Name
= GetStringNameFromHandle (OpenInfo
[OpenInfoIndex
].AgentHandle
, NULL
);
107 ControllerIndex
= ConvertHandleToHandleIndex (OpenInfo
[OpenInfoIndex
].ControllerHandle
);
108 if (ControllerIndex
!= 0) {
113 STRING_TOKEN (STR_OPENINFO_LINE
),
114 gShellDriver1HiiHandle
,
117 OpenInfo
[OpenInfoIndex
].OpenCount
,
126 STRING_TOKEN (STR_OPENINFO_MIN_LINE
),
127 gShellDriver1HiiHandle
,
129 OpenInfo
[OpenInfoIndex
].OpenCount
,
140 FreePool (ProtocolGuidArray
);
147 Function for 'openinfo' command.
149 @param[in] ImageHandle Handle to the Image (NULL if Internal).
150 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
154 ShellCommandRunOpenInfo (
155 IN EFI_HANDLE ImageHandle
,
156 IN EFI_SYSTEM_TABLE
*SystemTable
161 CHAR16
*ProblemParam
;
162 SHELL_STATUS ShellStatus
;
163 EFI_HANDLE TheHandle
;
164 CONST CHAR16
*Param1
;
167 ShellStatus
= SHELL_SUCCESS
;
170 // initialize the shell lib (we must be in non-auto-init...)
172 Status
= ShellInitialize ();
173 ASSERT_EFI_ERROR (Status
);
175 Status
= CommandInit ();
176 ASSERT_EFI_ERROR (Status
);
179 // parse the command line
181 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
182 if (EFI_ERROR (Status
)) {
183 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
184 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"openinfo", ProblemParam
);
185 FreePool (ProblemParam
);
186 ShellStatus
= SHELL_INVALID_PARAMETER
;
191 if (ShellCommandLineGetCount (Package
) > 2) {
193 // error for too many parameters
195 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"openinfo");
196 ShellStatus
= SHELL_INVALID_PARAMETER
;
197 } else if (ShellCommandLineGetCount (Package
) == 0) {
198 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
, L
"openinfo");
199 ShellStatus
= SHELL_INVALID_PARAMETER
;
201 Param1
= ShellCommandLineGetRawValue (Package
, 1);
202 Status
= ShellConvertStringToUint64 (Param1
, &Intermediate
, TRUE
, FALSE
);
203 if (EFI_ERROR (Status
) || (Param1
== NULL
) || (ConvertHandleIndexToHandle ((UINTN
)Intermediate
) == NULL
)) {
204 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"openinfo", Param1
);
205 ShellStatus
= SHELL_INVALID_PARAMETER
;
207 TheHandle
= ConvertHandleIndexToHandle ((UINTN
)Intermediate
);
208 ASSERT (TheHandle
!= NULL
);
209 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_OPENINFO_HEADER_LINE
), gShellDriver1HiiHandle
, (UINTN
)Intermediate
, TheHandle
);
211 Status
= TraverseHandleDatabase (TheHandle
);
212 if (!EFI_ERROR (Status
)) {
214 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"openinfo", Param1
);
215 ShellStatus
= SHELL_NOT_FOUND
;
221 return (ShellStatus
);