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