]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/WebServer/SystemTable.c
Fix some errors detected by the GCC 4.4 compiler.
[mirror_edk2.git] / AppPkg / Applications / Sockets / WebServer / SystemTable.c
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 system table
23
24 **/
25
26 #include <WebServer.h>
27
28
29 /**
30 Display the EFI Table Header
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 [in] pHeader Address of the EFI_TABLE_HEADER structure
35
36 @retval EFI_SUCCESS The request was successfully processed
37
38 **/
39 EFI_STATUS
40 EfiTableHeader (
41 IN int SocketFD,
42 IN WSDT_PORT * pPort,
43 IN EFI_TABLE_HEADER * pHeader
44 )
45 {
46 EFI_STATUS Status;
47
48 DBG_ENTER ( );
49
50 //
51 // Send the handles page
52 //
53 for ( ; ; ) {
54 ///
55 /// A 64-bit signature that identifies the type of table that follows.
56 /// Unique signatures have been generated for the EFI System Table,
57 /// the EFI Boot Services Table, and the EFI Runtime Services Table.
58 ///
59 Status = RowHexValue ( SocketFD,
60 pPort,
61 "Hdr.Signature",
62 pHeader->Signature,
63 NULL );
64 if ( EFI_ERROR ( Status )) {
65 break;
66 }
67
68 ///
69 /// The revision of the EFI Specification to which this table
70 /// conforms. The upper 16 bits of this field contain the major
71 /// revision value, and the lower 16 bits contain the minor revision
72 /// value. The minor revision values are limited to the range of 00..99.
73 ///
74 Status = RowRevision ( SocketFD,
75 pPort,
76 "Hdr.Revision",
77 pHeader->Revision );
78 if ( EFI_ERROR ( Status )) {
79 break;
80 }
81
82 ///
83 /// The size, in bytes, of the entire table including the EFI_TABLE_HEADER.
84 ///
85 Status = RowDecimalValue ( SocketFD,
86 pPort,
87 "Hdr.HeaderSize",
88 pHeader->HeaderSize );
89 if ( EFI_ERROR ( Status )) {
90 break;
91 }
92
93 ///
94 /// The 32-bit CRC for the entire table. This value is computed by
95 /// setting this field to 0, and computing the 32-bit CRC for HeaderSize bytes.
96 ///
97 Status = RowHexValue ( SocketFD,
98 pPort,
99 "Hdr.CRC",
100 pHeader->CRC32,
101 NULL );
102 if ( EFI_ERROR ( Status )) {
103 break;
104 }
105
106 ///
107 /// Reserved field that must be set to 0.
108 ///
109 Status = RowHexValue ( SocketFD,
110 pPort,
111 "Hdr.Reserved",
112 pHeader->Reserved,
113 NULL );
114 break;
115 }
116
117 //
118 // Return the operation status
119 //
120 DBG_EXIT_STATUS ( Status );
121 return Status;
122 }
123
124
125 /**
126 Display a row containing a decimal value
127
128 @param [in] SocketFD The socket's file descriptor to add to the list.
129 @param [in] pPort The WSDT_PORT structure address
130 @param [in] pName Address of a zero terminated name string
131 @param [in] Value The value to display
132
133 @retval EFI_SUCCESS The request was successfully processed
134
135 **/
136 EFI_STATUS
137 RowDecimalValue (
138 IN int SocketFD,
139 IN WSDT_PORT * pPort,
140 IN CONST CHAR8 * pName,
141 IN UINT64 Value
142 )
143 {
144 EFI_STATUS Status;
145
146 DBG_ENTER ( );
147
148 //
149 // Use for/break instead of goto
150 //
151 for ( ; ; ) {
152 Status = HttpSendAnsiString ( SocketFD,
153 pPort,
154 "<tr><td>" );
155 if ( EFI_ERROR ( Status )) {
156 break;
157 }
158 Status = HttpSendAnsiString ( SocketFD,
159 pPort,
160 pName );
161 if ( EFI_ERROR ( Status )) {
162 break;
163 }
164 Status = HttpSendAnsiString ( SocketFD,
165 pPort,
166 "</td><td><code>" );
167 if ( EFI_ERROR ( Status )) {
168 break;
169 }
170 Status = HttpSendValue ( SocketFD,
171 pPort,
172 Value );
173 if ( EFI_ERROR ( Status )) {
174 break;
175 }
176 Status = HttpSendAnsiString ( SocketFD,
177 pPort,
178 "</code></td></tr>\r\n" );
179 break;
180 }
181
182 //
183 // Return the operation status
184 //
185 DBG_EXIT_STATUS ( Status );
186 return Status;
187 }
188
189
190 /**
191 Display a row containing a hex value
192
193 @param [in] SocketFD The socket's file descriptor to add to the list.
194 @param [in] pPort The WSDT_PORT structure address
195 @param [in] pName Address of a zero terminated name string
196 @param [in] Value The value to display
197 @param [in] pWebPage Address of a zero terminated web page name
198
199 @retval EFI_SUCCESS The request was successfully processed
200
201 **/
202 EFI_STATUS
203 RowHexValue (
204 IN int SocketFD,
205 IN WSDT_PORT * pPort,
206 IN CONST CHAR8 * pName,
207 IN UINT64 Value,
208 IN CONST CHAR16 * pWebPage
209 )
210 {
211 EFI_STATUS Status;
212
213 DBG_ENTER ( );
214
215 //
216 // Use for/break instead of goto
217 //
218 for ( ; ; ) {
219 Status = HttpSendAnsiString ( SocketFD,
220 pPort,
221 "<tr><td>" );
222 if ( EFI_ERROR ( Status )) {
223 break;
224 }
225 Status = HttpSendAnsiString ( SocketFD,
226 pPort,
227 pName );
228 if ( EFI_ERROR ( Status )) {
229 break;
230 }
231 Status = HttpSendAnsiString ( SocketFD,
232 pPort,
233 "</td><td><code>0x" );
234 if ( EFI_ERROR ( Status )) {
235 break;
236 }
237 if ( NULL != pWebPage ) {
238 Status = HttpSendAnsiString ( SocketFD,
239 pPort,
240 "<a target=\"_blank\" href=\"" );
241 if ( EFI_ERROR ( Status )) {
242 break;
243 }
244 Status = HttpSendUnicodeString ( SocketFD,
245 pPort,
246 pWebPage );
247 if ( EFI_ERROR ( Status )) {
248 break;
249 }
250 Status = HttpSendAnsiString ( SocketFD,
251 pPort,
252 "\">" );
253 if ( EFI_ERROR ( Status )) {
254 break;
255 }
256 }
257 Status = HttpSendHexValue ( SocketFD,
258 pPort,
259 Value );
260 if ( EFI_ERROR ( Status )) {
261 break;
262 }
263 if ( NULL != pWebPage ) {
264 Status = HttpSendAnsiString ( SocketFD,
265 pPort,
266 "</a>" );
267 if ( EFI_ERROR ( Status )) {
268 break;
269 }
270 }
271 Status = HttpSendAnsiString ( SocketFD,
272 pPort,
273 "</code></td></tr>\r\n" );
274 break;
275 }
276
277 //
278 // Return the operation status
279 //
280 DBG_EXIT_STATUS ( Status );
281 return Status;
282 }
283
284
285 /**
286 Display a row containing a pointer
287
288 @param [in] SocketFD The socket's file descriptor to add to the list.
289 @param [in] pPort The WSDT_PORT structure address
290 @param [in] pName Address of a zero terminated name string
291 @param [in] pAddress The address to display
292 @param [in] pWebPage Address of a zero terminated web page name
293
294 @retval EFI_SUCCESS The request was successfully processed
295
296 **/
297 EFI_STATUS
298 RowPointer (
299 IN int SocketFD,
300 IN WSDT_PORT * pPort,
301 IN CONST CHAR8 * pName,
302 IN CONST VOID * pAddress,
303 IN CONST CHAR16 * pWebPage
304 )
305 {
306 EFI_STATUS Status;
307
308 DBG_ENTER ( );
309
310 //
311 // Use for/break instead of goto
312 //
313 for ( ; ; ) {
314 Status = HttpSendAnsiString ( SocketFD,
315 pPort,
316 "<tr><td>" );
317 if ( EFI_ERROR ( Status )) {
318 break;
319 }
320 Status = HttpSendAnsiString ( SocketFD,
321 pPort,
322 pName );
323 if ( EFI_ERROR ( Status )) {
324 break;
325 }
326 Status = HttpSendAnsiString ( SocketFD,
327 pPort,
328 "</td><td><code>" );
329 if ( EFI_ERROR ( Status )) {
330 break;
331 }
332 if ( NULL != pWebPage ) {
333 Status = HttpSendAnsiString ( SocketFD,
334 pPort,
335 "<a target=\"_blank\" href=\"" );
336 if ( EFI_ERROR ( Status )) {
337 break;
338 }
339 Status = HttpSendUnicodeString ( SocketFD,
340 pPort,
341 pWebPage );
342 if ( EFI_ERROR ( Status )) {
343 break;
344 }
345 Status = HttpSendAnsiString ( SocketFD,
346 pPort,
347 "\">" );
348 if ( EFI_ERROR ( Status )) {
349 break;
350 }
351 }
352 Status = HttpSendAnsiString ( SocketFD,
353 pPort,
354 "0x" );
355 if ( EFI_ERROR ( Status )) {
356 break;
357 }
358 Status = HttpSendHexBits ( SocketFD,
359 pPort,
360 sizeof ( pAddress ) * 8,
361 (UINT64)(UINTN)pAddress );
362 if ( EFI_ERROR ( Status )) {
363 break;
364 }
365 if ( NULL != pWebPage ) {
366 Status = HttpSendAnsiString ( SocketFD,
367 pPort,
368 "</a>" );
369 if ( EFI_ERROR ( Status )) {
370 break;
371 }
372 }
373 Status = HttpSendAnsiString ( SocketFD,
374 pPort,
375 "</code></td></tr>\r\n" );
376 break;
377 }
378
379 //
380 // Return the operation status
381 //
382 DBG_EXIT_STATUS ( Status );
383 return Status;
384 }
385
386
387 /**
388 Display a row containing a revision
389
390 @param [in] SocketFD The socket's file descriptor to add to the list.
391 @param [in] pPort The WSDT_PORT structure address
392 @param [in] pName Address of a zero terminated name string
393 @param [in] Revision The revision to display
394
395 @retval EFI_SUCCESS The request was successfully processed
396
397 **/
398 EFI_STATUS
399 RowRevision (
400 IN int SocketFD,
401 IN WSDT_PORT * pPort,
402 IN CONST CHAR8 * pName,
403 IN UINT32 Revision
404 )
405 {
406 EFI_STATUS Status;
407
408 DBG_ENTER ( );
409
410 //
411 // Use for/break instead of goto
412 //
413 for ( ; ; ) {
414 Status = HttpSendAnsiString ( SocketFD,
415 pPort,
416 "<tr><td>" );
417 if ( EFI_ERROR ( Status )) {
418 break;
419 }
420 Status = HttpSendAnsiString ( SocketFD,
421 pPort,
422 pName );
423 if ( EFI_ERROR ( Status )) {
424 break;
425 }
426 Status = HttpSendAnsiString ( SocketFD,
427 pPort,
428 "</td><td><code>" );
429 if ( EFI_ERROR ( Status )) {
430 break;
431 }
432 Status = HttpSendValue ( SocketFD,
433 pPort,
434 Revision >> 16 );
435 if ( EFI_ERROR ( Status )) {
436 break;
437 }
438 Status = HttpSendByte ( SocketFD,
439 pPort,
440 '.' );
441 if ( EFI_ERROR ( Status )) {
442 break;
443 }
444 Status = HttpSendValue ( SocketFD,
445 pPort,
446 Revision & 0xFFFF );
447 if ( EFI_ERROR ( Status )) {
448 break;
449 }
450 Status = HttpSendAnsiString ( SocketFD,
451 pPort,
452 "</code></td></tr>\r\n" );
453 break;
454 }
455
456 //
457 // Return the operation status
458 //
459 DBG_EXIT_STATUS ( Status );
460 return Status;
461 }
462
463
464 /**
465 Display a row containing a unicode string
466
467 @param [in] SocketFD The socket's file descriptor to add to the list.
468 @param [in] pPort The WSDT_PORT structure address
469 @param [in] pName Address of a zero terminated name string
470 @param [in] pString Address of a zero terminated unicode string
471
472 @retval EFI_SUCCESS The request was successfully processed
473
474 **/
475 EFI_STATUS
476 RowUnicodeString (
477 IN int SocketFD,
478 IN WSDT_PORT * pPort,
479 IN CONST CHAR8 * pName,
480 IN CONST CHAR16 * pString
481 )
482 {
483 EFI_STATUS Status;
484
485 DBG_ENTER ( );
486
487 //
488 // Use for/break instead of goto
489 //
490 for ( ; ; ) {
491 Status = HttpSendAnsiString ( SocketFD,
492 pPort,
493 "<tr><td>" );
494 if ( EFI_ERROR ( Status )) {
495 break;
496 }
497 Status = HttpSendAnsiString ( SocketFD,
498 pPort,
499 pName );
500 if ( EFI_ERROR ( Status )) {
501 break;
502 }
503 Status = HttpSendAnsiString ( SocketFD,
504 pPort,
505 "</td><td>" );
506 if ( EFI_ERROR ( Status )) {
507 break;
508 }
509 Status = HttpSendUnicodeString ( SocketFD,
510 pPort,
511 pString );
512 if ( EFI_ERROR ( Status )) {
513 break;
514 }
515 Status = HttpSendAnsiString ( SocketFD,
516 pPort,
517 "</td></tr>\r\n" );
518 break;
519 }
520
521 //
522 // Return the operation status
523 //
524 DBG_EXIT_STATUS ( Status );
525 return Status;
526 }
527
528
529 /**
530 Start the table page
531
532 @param [in] SocketFD The socket's file descriptor to add to the list.
533 @param [in] pPort The WSDT_PORT structure address
534 @param [in] pName Address of a zero terminated name string
535 @param [in] pTable Address of the table
536
537 @retval EFI_SUCCESS The request was successfully processed
538
539 **/
540 EFI_STATUS
541 TableHeader (
542 IN int SocketFD,
543 IN WSDT_PORT * pPort,
544 IN CONST CHAR16 * pName,
545 IN CONST VOID * pTable
546 )
547 {
548 EFI_STATUS Status;
549
550 DBG_ENTER ( );
551
552 //
553 // Use for/break instead of goto
554 //
555 for ( ; ; ) {
556 //
557 // Send the page header
558 //
559 Status = HttpPageHeader ( SocketFD, pPort, pName );
560 if ( EFI_ERROR ( Status )) {
561 break;
562 }
563
564 //
565 // Build the table header
566 //
567 Status = HttpSendAnsiString ( SocketFD,
568 pPort,
569 "<h1>" );
570 if ( EFI_ERROR ( Status )) {
571 break;
572 }
573 Status = HttpSendUnicodeString ( SocketFD,
574 pPort,
575 pName );
576 if ( EFI_ERROR ( Status )) {
577 break;
578 }
579 if ( NULL != pTable ) {
580 Status = HttpSendAnsiString ( SocketFD,
581 pPort,
582 ": 0x" );
583 if ( EFI_ERROR ( Status )) {
584 break;
585 }
586 Status = HttpSendHexBits ( SocketFD,
587 pPort,
588 sizeof ( pTable ) * 8,
589 (UINT64)(UINTN)pTable );
590 if ( EFI_ERROR ( Status )) {
591 break;
592 }
593 }
594 Status = HttpSendAnsiString ( SocketFD,
595 pPort,
596 "</h1>\r\n"
597 "<table border=\"1\">\r\n"
598 " <tr bgcolor=\"c0c0ff\"><th>Field Name</th><th>Value</th></tr>\r\n" );
599 break;
600 }
601
602 //
603 // Return the operation status
604 //
605 DBG_EXIT_STATUS ( Status );
606 return Status;
607 }
608
609
610 /**
611 End the table page
612
613 @param [in] SocketFD The socket's file descriptor to add to the list.
614 @param [in] pPort The WSDT_PORT structure address
615 @param [out] pbDone Address to receive the request completion status
616
617 @retval EFI_SUCCESS The request was successfully processed
618
619 **/
620 EFI_STATUS
621 TableTrailer (
622 IN int SocketFD,
623 IN WSDT_PORT * pPort,
624 OUT BOOLEAN *pbDone
625 )
626 {
627 EFI_STATUS Status;
628
629 DBG_ENTER ( );
630
631 //
632 // Use for/break instead of goto
633 //
634 for ( ; ; ) {
635 //
636 // Build the table trailer
637 //
638 Status = HttpSendAnsiString ( SocketFD,
639 pPort,
640 "</table>\r\n" );
641 if ( EFI_ERROR ( Status )) {
642 break;
643 }
644
645 //
646 // Send the page trailer
647 //
648 Status = HttpPageTrailer ( SocketFD, pPort, pbDone );
649 break;
650 }
651
652 //
653 // Return the operation status
654 //
655 DBG_EXIT_STATUS ( Status );
656 return Status;
657 }
658
659
660 /**
661 Respond with the system table
662
663 @param [in] SocketFD The socket's file descriptor to add to the list.
664 @param [in] pPort The WSDT_PORT structure address
665 @param [out] pbDone Address to receive the request completion status
666
667 @retval EFI_SUCCESS The request was successfully processed
668
669 **/
670 EFI_STATUS
671 SystemTablePage (
672 IN int SocketFD,
673 IN WSDT_PORT * pPort,
674 OUT BOOLEAN * pbDone
675 )
676 {
677 EFI_STATUS Status;
678
679 DBG_ENTER ( );
680
681 //
682 // Send the system table page
683 //
684 for ( ; ; ) {
685 //
686 // Send the page and table header
687 //
688 Status = TableHeader ( SocketFD, pPort, L"System Table", gST );
689 if ( EFI_ERROR ( Status )) {
690 break;
691 }
692
693 ///
694 /// The table header for the EFI System Table.
695 ///
696 Status = EfiTableHeader ( SocketFD,
697 pPort,
698 &gST->Hdr );
699 if ( EFI_ERROR ( Status )) {
700 break;
701 }
702
703 ///
704 /// A pointer to a null terminated string that identifies the vendor
705 /// that produces the system firmware for the platform.
706 ///
707 Status = RowUnicodeString ( SocketFD,
708 pPort,
709 "FirmwareVendor",
710 gST->FirmwareVendor );
711 if ( EFI_ERROR ( Status )) {
712 break;
713 }
714
715 ///
716 /// A firmware vendor specific value that identifies the revision
717 /// of the system firmware for the platform.
718 ///
719 Status = RowRevision ( SocketFD,
720 pPort,
721 "FirmwareRevision",
722 gST->FirmwareRevision );
723 if ( EFI_ERROR ( Status )) {
724 break;
725 }
726
727 ///
728 /// The handle for the active console input device. This handle must support
729 /// EFI_SIMPLE_TEXT_INPUT_PROTOCOL and EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
730 ///
731 Status = RowPointer ( SocketFD,
732 pPort,
733 "ConsoleInHandle",
734 (VOID *)gST->ConsoleInHandle,
735 NULL );
736 if ( EFI_ERROR ( Status )) {
737 break;
738 }
739
740 ///
741 /// A pointer to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL interface that is
742 /// associated with ConsoleInHandle.
743 ///
744 Status = RowPointer ( SocketFD,
745 pPort,
746 "ConIn",
747 (VOID *)gST->ConIn,
748 NULL );
749 if ( EFI_ERROR ( Status )) {
750 break;
751 }
752
753 ///
754 /// The handle for the active console output device.
755 ///
756 Status = RowPointer ( SocketFD,
757 pPort,
758 "ConsoleOutHandle",
759 (VOID *)gST->ConsoleOutHandle,
760 NULL );
761 if ( EFI_ERROR ( Status )) {
762 break;
763 }
764
765 ///
766 /// A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface
767 /// that is associated with ConsoleOutHandle.
768 ///
769 Status = RowPointer ( SocketFD,
770 pPort,
771 "ConOut",
772 (VOID *)gST->ConOut,
773 NULL );
774 if ( EFI_ERROR ( Status )) {
775 break;
776 }
777
778 ///
779 /// The handle for the active standard error console device.
780 /// This handle must support the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.
781 ///
782 Status = RowPointer ( SocketFD,
783 pPort,
784 "StandardErrorHandle",
785 (VOID *)gST->StandardErrorHandle,
786 NULL );
787 if ( EFI_ERROR ( Status )) {
788 break;
789 }
790
791 ///
792 /// A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface
793 /// that is associated with StandardErrorHandle.
794 ///
795 Status = RowPointer ( SocketFD,
796 pPort,
797 "StdErr",
798 (VOID *)gST->StdErr,
799 NULL );
800 if ( EFI_ERROR ( Status )) {
801 break;
802 }
803
804 ///
805 /// A pointer to the EFI Runtime Services Table.
806 ///
807 Status = RowPointer ( SocketFD,
808 pPort,
809 "RuntimeServices",
810 (VOID *)gST->RuntimeServices,
811 PAGE_RUNTIME_SERVICES_TABLE );
812
813 ///
814 /// A pointer to the EFI Boot Services Table.
815 ///
816 Status = RowPointer ( SocketFD,
817 pPort,
818 "BootServices",
819 (VOID *)gST->BootServices,
820 PAGE_BOOT_SERVICES_TABLE );
821 if ( EFI_ERROR ( Status )) {
822 break;
823 }
824
825 ///
826 /// The number of system configuration tables in the buffer ConfigurationTable.
827 ///
828 Status = RowDecimalValue ( SocketFD,
829 pPort,
830 "NumberOfTableEntries",
831 gST->NumberOfTableEntries );
832 if ( EFI_ERROR ( Status )) {
833 break;
834 }
835
836 ///
837 /// A pointer to the system configuration tables.
838 /// The number of entries in the table is NumberOfTableEntries.
839 ///
840 Status = RowPointer ( SocketFD,
841 pPort,
842 "ConfigurationTable",
843 (VOID *)gST->ConfigurationTable,
844 PAGE_CONFIGURATION_TABLE );
845 if ( EFI_ERROR ( Status )) {
846 break;
847 }
848
849 //
850 // Build the table trailer
851 //
852 Status = TableTrailer ( SocketFD,
853 pPort,
854 pbDone );
855 break;
856 }
857
858 //
859 // Return the operation status
860 //
861 DBG_EXIT_STATUS ( Status );
862 return Status;
863 }