]>
Commit | Line | Data |
---|---|---|
4ba49616 | 1 | /** @file\r |
2 | Main file for OpenInfo shell Driver1 function.\r | |
3 | \r | |
c011b6c9 | 4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r |
361a8267 | 5 | Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r |
4ba49616 | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "UefiShellDriver1CommandsLib.h"\r | |
17 | \r | |
18 | STATIC CONST CHAR16 StringHandProt[] = L"HandProt ";\r | |
19 | STATIC CONST CHAR16 StringGetProt[] = L"GetProt ";\r | |
20 | STATIC CONST CHAR16 StringTestProt[] = L"TestProt ";\r | |
21 | STATIC CONST CHAR16 StringChild[] = L"Child ";\r | |
22 | STATIC CONST CHAR16 StringDriver[] = L"Driver ";\r | |
23 | STATIC CONST CHAR16 StringExclusive[] = L"Exclusive";\r | |
24 | STATIC CONST CHAR16 StringDriverEx[] = L"DriverEx ";\r | |
25 | STATIC CONST CHAR16 StringUnknown[] = L"Unknown ";\r | |
26 | \r | |
361a8267 | 27 | /**\r |
28 | Open the database and print out all the info about TheHandle.\r | |
29 | \r | |
30 | @param[in] TheHandle The handle to print info on.\r | |
31 | \r | |
32 | @retval EFI_SUCCESS The operation was successful.\r | |
33 | @retval EFI_INVALID_PARAMETER TheHandle was NULL.\r | |
34 | **/\r | |
4ba49616 | 35 | EFI_STATUS\r |
36 | EFIAPI\r | |
37 | TraverseHandleDatabase (\r | |
38 | IN CONST EFI_HANDLE TheHandle\r | |
39 | )\r | |
40 | {\r | |
41 | EFI_STATUS Status;\r | |
42 | EFI_GUID **ProtocolGuidArray;\r | |
43 | UINTN ArrayCount;\r | |
44 | UINTN ProtocolIndex;\r | |
45 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r | |
46 | UINTN OpenInfoCount;\r | |
47 | UINTN OpenInfoIndex;\r | |
48 | CONST CHAR16 *OpenTypeString;\r | |
49 | CHAR16 *TempString;\r | |
50 | UINTN HandleIndex;\r | |
51 | CONST CHAR16 *Name;\r | |
f330ff35 | 52 | UINTN ControllerIndex;\r |
4ba49616 | 53 | \r |
361a8267 | 54 | if (TheHandle == NULL) {\r |
55 | return (EFI_INVALID_PARAMETER);\r | |
56 | }\r | |
4ba49616 | 57 | \r |
58 | //\r | |
59 | // Retrieve the list of all the protocols on the handle\r | |
60 | //\r | |
61 | Status = gBS->ProtocolsPerHandle (\r | |
62 | TheHandle,\r | |
63 | &ProtocolGuidArray,\r | |
64 | &ArrayCount\r | |
65 | );\r | |
66 | ASSERT_EFI_ERROR(Status);\r | |
67 | if (!EFI_ERROR (Status)) {\r | |
68 | \r | |
69 | for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r | |
70 | //\r | |
71 | // print out the human readable name for this one.\r | |
72 | //\r | |
73 | TempString = GetStringNameFromGuid(ProtocolGuidArray[ProtocolIndex], NULL);\r | |
74 | if (TempString == NULL) {\r | |
75 | continue;\r | |
76 | }\r | |
77 | ShellPrintEx(-1, -1, L"%H%s%N\r\n", TempString);\r | |
78 | FreePool(TempString);\r | |
79 | \r | |
80 | //\r | |
81 | // Retrieve the list of agents that have opened each protocol\r | |
82 | //\r | |
83 | Status = gBS->OpenProtocolInformation (\r | |
84 | TheHandle,\r | |
85 | ProtocolGuidArray[ProtocolIndex],\r | |
86 | &OpenInfo,\r | |
87 | &OpenInfoCount\r | |
88 | );\r | |
89 | ASSERT_EFI_ERROR(Status);\r | |
90 | if (!EFI_ERROR (Status)) {\r | |
91 | for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r | |
92 | switch (OpenInfo[OpenInfoIndex].Attributes) {\r | |
93 | case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: OpenTypeString = StringHandProt; break;\r | |
94 | case EFI_OPEN_PROTOCOL_GET_PROTOCOL: OpenTypeString = StringGetProt; break;\r | |
95 | case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: OpenTypeString = StringTestProt; break;\r | |
96 | case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: OpenTypeString = StringChild; break;\r | |
97 | case EFI_OPEN_PROTOCOL_BY_DRIVER: OpenTypeString = StringDriver; break;\r | |
98 | case EFI_OPEN_PROTOCOL_EXCLUSIVE: OpenTypeString = StringExclusive; break;\r | |
99 | case EFI_OPEN_PROTOCOL_BY_DRIVER|EFI_OPEN_PROTOCOL_EXCLUSIVE:\r | |
100 | OpenTypeString = StringDriverEx; break;\r | |
101 | default: OpenTypeString = StringUnknown; break;\r | |
102 | }\r | |
f330ff35 | 103 | HandleIndex = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].AgentHandle);\r |
104 | Name = GetStringNameFromHandle(OpenInfo[OpenInfoIndex].AgentHandle, NULL);\r | |
105 | ControllerIndex = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].ControllerHandle);\r | |
106 | if (ControllerIndex != 0) {\r | |
4ba49616 | 107 | ShellPrintHiiEx(\r |
108 | -1,\r | |
109 | -1,\r | |
110 | NULL,\r | |
111 | STRING_TOKEN(STR_OPENINFO_LINE),\r | |
112 | gShellDriver1HiiHandle,\r | |
113 | HandleIndex,\r | |
f330ff35 | 114 | ControllerIndex,\r |
4ba49616 | 115 | OpenInfo[OpenInfoIndex].OpenCount,\r |
116 | OpenTypeString,\r | |
117 | Name\r | |
118 | );\r | |
119 | } else {\r | |
120 | ShellPrintHiiEx(\r | |
121 | -1,\r | |
122 | -1,\r | |
123 | NULL,\r | |
124 | STRING_TOKEN(STR_OPENINFO_MIN_LINE),\r | |
125 | gShellDriver1HiiHandle,\r | |
126 | HandleIndex,\r | |
127 | OpenInfo[OpenInfoIndex].OpenCount,\r | |
128 | OpenTypeString,\r | |
129 | Name\r | |
130 | ); \r | |
131 | }\r | |
132 | }\r | |
133 | FreePool (OpenInfo);\r | |
134 | }\r | |
135 | }\r | |
136 | FreePool (ProtocolGuidArray);\r | |
137 | }\r | |
138 | \r | |
139 | return Status;\r | |
140 | }\r | |
141 | \r | |
142 | /**\r | |
143 | Function for 'openinfo' command.\r | |
144 | \r | |
145 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
146 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
147 | **/\r | |
148 | SHELL_STATUS\r | |
149 | EFIAPI\r | |
150 | ShellCommandRunOpenInfo (\r | |
151 | IN EFI_HANDLE ImageHandle,\r | |
152 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
153 | )\r | |
154 | {\r | |
155 | EFI_STATUS Status;\r | |
156 | LIST_ENTRY *Package;\r | |
157 | CHAR16 *ProblemParam;\r | |
158 | SHELL_STATUS ShellStatus;\r | |
159 | EFI_HANDLE TheHandle;\r | |
160 | CONST CHAR16 *Param1;\r | |
361a8267 | 161 | UINT64 Intermediate;\r |
4ba49616 | 162 | \r |
163 | ShellStatus = SHELL_SUCCESS;\r | |
164 | \r | |
165 | //\r | |
166 | // initialize the shell lib (we must be in non-auto-init...)\r | |
167 | //\r | |
168 | Status = ShellInitialize();\r | |
169 | ASSERT_EFI_ERROR(Status);\r | |
170 | \r | |
171 | Status = CommandInit();\r | |
172 | ASSERT_EFI_ERROR(Status);\r | |
173 | \r | |
174 | //\r | |
175 | // parse the command line\r | |
176 | //\r | |
177 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r | |
178 | if (EFI_ERROR(Status)) {\r | |
179 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
bc280720 | 180 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"openinfo", ProblemParam); \r |
4ba49616 | 181 | FreePool(ProblemParam);\r |
182 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
183 | } else {\r | |
184 | ASSERT(FALSE);\r | |
185 | }\r | |
186 | } else {\r | |
187 | if (ShellCommandLineGetCount(Package) > 2){\r | |
188 | //\r | |
189 | // error for too many parameters\r | |
190 | //\r | |
bc280720 | 191 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"openinfo"); \r |
4ba49616 | 192 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
193 | } else if (ShellCommandLineGetCount(Package) == 0) {\r | |
bc280720 | 194 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"openinfo"); \r |
4ba49616 | 195 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
196 | } else {\r | |
197 | Param1 = ShellCommandLineGetRawValue(Package, 1);\r | |
361a8267 | 198 | Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE);\r |
199 | if (EFI_ERROR(Status) || Param1 == NULL || ConvertHandleIndexToHandle((UINTN)Intermediate) == NULL){\r | |
bc280720 | 200 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1); \r |
4ba49616 | 201 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
202 | } else {\r | |
361a8267 | 203 | TheHandle = ConvertHandleIndexToHandle((UINTN)Intermediate);\r |
4ba49616 | 204 | ASSERT(TheHandle != NULL);\r |
361a8267 | 205 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, (UINTN)Intermediate, TheHandle);\r |
4ba49616 | 206 | \r |
207 | Status = TraverseHandleDatabase (TheHandle);\r | |
208 | if (!EFI_ERROR(Status)) {\r | |
209 | } else {\r | |
bc280720 | 210 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1); \r |
4ba49616 | 211 | ShellStatus = SHELL_NOT_FOUND;\r |
212 | }\r | |
213 | }\r | |
214 | }\r | |
215 | }\r | |
216 | return (ShellStatus);\r | |
217 | }\r |