]>
Commit | Line | Data |
---|---|---|
4684b66f | 1 | /*++ |
2 | This file contains an 'Intel UEFI Application' and is | |
3 | licensed for Intel CPUs and chipsets under the terms of your | |
4 | license agreement with Intel or your vendor. This file may | |
5 | be modified by the user, subject to additional terms of the | |
6 | license agreement | |
7 | --*/ | |
8 | /*++ | |
9 | ||
10 | Copyright (c) 2011 Intel Corporation. All rights reserved | |
11 | This software and associated documentation (if any) is furnished | |
12 | under a license and may only be used or copied in accordance | |
13 | with the terms of the license. Except as permitted by such | |
14 | license, no part of this software or documentation may be | |
15 | reproduced, stored in a retrieval system, or transmitted in any | |
16 | form or by any means without the express written consent of | |
17 | Intel Corporation. | |
18 | ||
19 | --*/ | |
20 | ||
21 | /** @file | |
22 | Display the handles in the system | |
23 | ||
24 | **/ | |
25 | ||
26 | #include <WebServer.h> | |
27 | ||
28 | ||
29 | /** | |
30 | Respond with the handles in the system | |
31 | ||
32 | @param [in] SocketFD The socket's file descriptor to add to the list. | |
33 | @param [in] pPort The WSDT_PORT structure address | |
34 | @param [out] pbDone Address to receive the request completion status | |
35 | ||
36 | @retval EFI_SUCCESS The request was successfully processed | |
37 | ||
38 | **/ | |
39 | EFI_STATUS | |
40 | HandlePage ( | |
41 | IN int SocketFD, | |
42 | IN WSDT_PORT * pPort, | |
43 | OUT BOOLEAN * pbDone | |
44 | ) | |
45 | { | |
46 | INTN Digit; | |
47 | INTN Entries; | |
48 | INTN Index; | |
49 | UINTN GuidCount; | |
50 | UINTN LengthInBytes; | |
51 | UINT8 * pDigit; | |
52 | EFI_HANDLE * pHandleArray; | |
53 | EFI_HANDLE * pHandle; | |
54 | EFI_HANDLE * pHandleEnd; | |
55 | EFI_GUID ** ppGuidArray; | |
56 | EFI_GUID ** ppGuid; | |
57 | EFI_GUID ** ppGuidEnd; | |
58 | INTN Shift; | |
59 | EFI_STATUS Status; | |
60 | UINTN Value; | |
61 | CONST UINTN cDigit [] = { | |
62 | 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15 }; | |
63 | ||
64 | DBG_ENTER ( ); | |
65 | ||
66 | // | |
67 | // Send the handles page | |
68 | // | |
69 | for ( ; ; ) { | |
70 | // | |
71 | // Send the page header | |
72 | // | |
73 | Status = HttpPageHeader ( SocketFD, pPort, L"Handle Database" ); | |
74 | if ( EFI_ERROR ( Status )) { | |
75 | break; | |
76 | } | |
77 | ||
78 | // | |
79 | // Build the table header | |
80 | // | |
81 | Status = HttpSendAnsiString ( SocketFD, | |
82 | pPort, | |
83 | "<h1>Handle Database</h1>\r\n" | |
84 | "<table border=\"1\">\r\n" | |
85 | " <tr bgcolor=\"c0c0ff\"><th>Handle</th><th>Protocol Guids</th></tr>\r\n" ); | |
86 | if ( EFI_ERROR ( Status )) { | |
87 | break; | |
88 | } | |
89 | ||
90 | // | |
91 | // Determine the number of handles in the database | |
92 | // | |
93 | LengthInBytes = 0; | |
94 | Status = gBS->LocateHandle ( AllHandles, | |
95 | NULL, | |
96 | NULL, | |
97 | &LengthInBytes, | |
98 | NULL ); | |
99 | if ( EFI_BUFFER_TOO_SMALL == Status ) { | |
100 | // | |
101 | // Allocate space for the handles | |
102 | // | |
103 | Status = gBS->AllocatePool ( EfiRuntimeServicesData, | |
104 | LengthInBytes, | |
105 | (VOID **) &pHandleArray ); | |
106 | if ( !EFI_ERROR ( Status )) { | |
107 | // | |
108 | // Get the list of handles | |
109 | // | |
110 | Status = gBS->LocateHandle ( AllHandles, | |
111 | NULL, | |
112 | NULL, | |
113 | &LengthInBytes, | |
114 | pHandleArray ); | |
115 | if ( !EFI_ERROR ( Status )) { | |
116 | Entries = LengthInBytes / sizeof ( *pHandleArray ); | |
117 | pHandle = pHandleArray; | |
118 | pHandleEnd = &pHandle [ Entries ]; | |
119 | while ( pHandleEnd > pHandle ) { | |
120 | // | |
121 | // Build the table entry for this page | |
122 | // | |
123 | Status = HttpSendAnsiString ( SocketFD, | |
124 | pPort, | |
125 | "<tr><td><code>0x" ); | |
126 | if ( EFI_ERROR ( Status )) { | |
127 | break; | |
128 | } | |
129 | Value = (UINTN) *pHandle; | |
130 | for ( Shift = ( sizeof ( Shift ) << 3 ) - 4; 0 <= Shift; Shift -= 4 ) { | |
131 | // | |
132 | // Convert the next address nibble to ANSI hex | |
133 | // | |
134 | Digit = (( Value >> Shift ) & 0xf ) | '0'; | |
135 | if ( '9' < Digit ) { | |
136 | Digit += 'a' - '0' - 10; | |
137 | } | |
138 | ||
139 | // | |
140 | // Display the address digit | |
141 | // | |
142 | Status = HttpSendByte ( SocketFD, | |
143 | pPort, | |
144 | (UINT8) Digit ); | |
145 | if ( EFI_ERROR ( Status )) { | |
146 | break; | |
147 | } | |
148 | } | |
149 | if ( EFI_ERROR ( Status )) { | |
150 | break; | |
151 | } | |
152 | ||
153 | // | |
154 | // Start the second column | |
155 | // | |
156 | Status = HttpSendAnsiString ( SocketFD, | |
157 | pPort, | |
158 | "</code></td><td><code>\r\n" ); | |
159 | if ( EFI_ERROR ( Status )) { | |
160 | break; | |
161 | } | |
162 | ||
163 | // | |
164 | // Determine the number of protocols connected to this handle | |
165 | // | |
166 | Status = gBS->ProtocolsPerHandle ( *pHandle, | |
167 | &ppGuidArray, | |
168 | &GuidCount ); | |
169 | if ( EFI_ERROR ( Status )) { | |
170 | break; | |
171 | } | |
172 | ppGuid = ppGuidArray; | |
173 | ppGuidEnd = &ppGuid [ GuidCount ]; | |
174 | while ( ppGuidEnd > ppGuid ) { | |
175 | // | |
176 | // Display the guid | |
177 | // | |
178 | pDigit = (UINT8 *) *ppGuid; | |
179 | for ( Index = 0; 16 > Index; Index++ ) { | |
180 | // | |
181 | // Separate the portions of the GUID | |
182 | // 99E87DCF-6162-40c5-9FA1-32111F5197F7 | |
183 | // | |
184 | if (( 4 == Index ) | |
185 | || ( 6 == Index ) | |
186 | || ( 8 == Index ) | |
187 | || ( 10 == Index )) { | |
188 | Status = HttpSendByte ( SocketFD, | |
189 | pPort, | |
190 | '-' ); | |
191 | if ( EFI_ERROR ( Status )) { | |
192 | break; | |
193 | } | |
194 | } | |
195 | ||
196 | // | |
197 | // Display the GUID digits | |
198 | // | |
199 | Value = pDigit [ cDigit [ Index ]]; | |
200 | for ( Shift = 4; 0 <= Shift; Shift -= 4 ) { | |
201 | // | |
202 | // Convert the next address nibble to ANSI hex | |
203 | // | |
204 | Digit = (( Value >> Shift ) & 0xf ) | '0'; | |
205 | if ( '9' < Digit ) { | |
206 | Digit += 'a' - '0' - 10; | |
207 | } | |
208 | ||
209 | // | |
210 | // Display the address digit | |
211 | // | |
212 | Status = HttpSendByte ( SocketFD, | |
213 | pPort, | |
214 | (UINT8) Digit ); | |
215 | if ( EFI_ERROR ( Status )) { | |
216 | break; | |
217 | } | |
218 | } | |
219 | if ( EFI_ERROR ( Status )) { | |
220 | break; | |
221 | } | |
222 | } | |
223 | ||
224 | // | |
225 | // Separate each GUID | |
226 | // | |
227 | Status = HttpSendAnsiString ( SocketFD, | |
228 | pPort, | |
229 | "<br/>\r\n" ); | |
230 | if ( EFI_ERROR ( Status )) { | |
231 | break; | |
232 | } | |
233 | ||
234 | // | |
235 | // Set the next protocol | |
236 | // | |
237 | ppGuid+= 1; | |
238 | } | |
239 | ||
240 | // | |
241 | // Free the GUID array | |
242 | // | |
243 | gBS->FreePool ( ppGuidArray ); | |
244 | if ( EFI_ERROR ( Status )) { | |
245 | break; | |
246 | } | |
247 | ||
248 | // | |
249 | // End the row | |
250 | // | |
251 | Status = HttpSendAnsiString ( SocketFD, | |
252 | pPort, | |
253 | "</code></td></tr>\r\n" ); | |
254 | if ( EFI_ERROR ( Status )) { | |
255 | break; | |
256 | } | |
257 | ||
258 | // | |
259 | // Set the next handle | |
260 | // | |
261 | pHandle += 1; | |
262 | } | |
263 | } | |
264 | ||
265 | // | |
266 | // Done with the handle array | |
267 | // | |
268 | gBS->FreePool ( pHandleArray ); | |
269 | } | |
270 | } | |
271 | ||
272 | // | |
273 | // Build the table trailer | |
274 | // | |
275 | Status = HttpSendAnsiString ( SocketFD, | |
276 | pPort, | |
277 | "</table>\r\n" ); | |
278 | if ( EFI_ERROR ( Status )) { | |
279 | break; | |
280 | } | |
281 | ||
282 | // | |
283 | // Send the page trailer | |
284 | // | |
285 | Status = HttpPageTrailer ( SocketFD, pPort, pbDone ); | |
286 | break; | |
287 | } | |
288 | ||
289 | // | |
290 | // Return the operation status | |
291 | // | |
292 | DBG_EXIT_STATUS ( Status ); | |
293 | return Status; | |
294 | } |