1 /** @file
2   Definitions for the web server.
3 
4   Copyright (c) 2011-2012, Intel Corporation
5   All rights reserved. This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #ifndef _WEB_SERVER_H_
16 #define _WEB_SERVER_H_
17 
18 #include <errno.h>
19 #include <Uefi.h>
20 
21 #include <Guid/EventGroup.h>
22 
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/UefiApplicationEntryPoint.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiLib.h>
30 #include <Protocol/BlockIo.h>
31 
32 #include <netinet/in.h>
33 
34 #include <sys/EfiSysCall.h>
35 #include <sys/poll.h>
36 #include <sys/socket.h>
37 
38 #if defined(_MSC_VER)   //  Handle Microsoft VC++ compiler specifics.
39 #pragma warning ( disable : 4054 )
40 #pragma warning ( disable : 4152 )
41 #endif  //  defined(_MSC_VER)
42 
43 //------------------------------------------------------------------------------
44 //  Pages
45 //------------------------------------------------------------------------------
46 
47 #define PAGE_ACPI_APIC                  L"/APIC"
48 #define PAGE_ACPI_BGRT                  L"/BGRT"
49 #define PAGE_ACPI_DSDT                  L"/DSDT"
50 #define PAGE_ACPI_FADT                  L"/FADT"
51 #define PAGE_ACPI_HPET                  L"/HPET"
52 #define PAGE_ACPI_MCFG                  L"/MCFG"
53 #define PAGE_ACPI_RSDP_10B              L"/RSDP1.0b"
54 #define PAGE_ACPI_RSDP_30               L"/RSDP3.0"
55 #define PAGE_ACPI_RSDT                  L"/RSDT"
56 #define PAGE_ACPI_SSDT                  L"/SSDT"
57 #define PAGE_ACPI_TCPA                  L"/TCPA"
58 #define PAGE_ACPI_UEFI                  L"/UEFI"
59 #define PAGE_BOOT_SERVICES_TABLE        L"/BootServicesTable"
60 #define PAGE_CONFIGURATION_TABLE        L"/ConfigurationTable"
61 #define PAGE_DXE_SERVICES_TABLE         L"/DxeServicesTable"
62 #define PAGE_RUNTIME_SERVICES_TABLE     L"/RuntimeServicesTable"
63 
64 //------------------------------------------------------------------------------
65 //  Signatures
66 //------------------------------------------------------------------------------
67 
68 #define APIC_SIGNATURE        0x43495041
69 #define BGRT_SIGNATURE        0x54524742
70 #define DSDT_SIGNATURE        0x54445344
71 #define FADT_SIGNATURE        0x50434146
72 #define HPET_SIGNATURE        0x54455048
73 #define MCFG_SIGNATURE        0x4746434d
74 #define SSDT_SIGNATURE        0x54445353
75 #define TCPA_SIGNATURE        0x41504354
76 #define UEFI_SIGNATURE        0x49464555
77 
78 //------------------------------------------------------------------------------
79 //  Macros
80 //------------------------------------------------------------------------------
81 
82 #if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */
83 #define DBG_ENTER()             DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///<  Display routine entry
84 #define DBG_EXIT()              DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" ))  ///<  Display routine exit
85 #define DBG_EXIT_DEC(Status)    DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status ))      ///<  Display routine exit with decimal value
86 #define DBG_EXIT_HEX(Status)    DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status ))  ///<  Display routine exit with hex value
87 #define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status ))      ///<  Display routine exit with status value
88 #define DBG_EXIT_TF(Status)     DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" ))  ///<  Display routine with TRUE/FALSE value
89 #else   //  _MSC_VER
90 #define DBG_ENTER()
91 #define DBG_EXIT()
92 #define DBG_EXIT_DEC(Status)
93 #define DBG_EXIT_HEX(Status)
94 #define DBG_EXIT_STATUS(Status)
95 #define DBG_EXIT_TF(Status)
96 #endif  //  _MSC_VER
97 
98 #define DIM(x)    ( sizeof ( x ) / sizeof ( x[0] ))   ///<  Compute the number of entries in an array
99 
100 //------------------------------------------------------------------------------
101 //  Constants
102 //------------------------------------------------------------------------------
103 
104 #define DEBUG_SOCKET_POLL       0x00080000  ///<  Display the socket poll messages
105 #define DEBUG_PORT_WORK         0x00040000  ///<  Display the port work messages
106 #define DEBUG_SERVER_LISTEN     0x00020000  ///<  Display the socket poll messages
107 #define DEBUG_HTTP_PORT         0x00010000  ///<  Display HTTP port related messages
108 #define DEBUG_REQUEST           0x00008000  ///<  Display the HTTP request messages
109 
110 #define HTTP_PORT_POLL_DELAY  ( 2 * 1000 )  ///<  Delay in milliseconds for attempts to open the HTTP port
111 #define CLIENT_POLL_DELAY     50            ///<  Delay in milliseconds between client polls
112 
113 #define TPL_WEB_SERVER        TPL_CALLBACK  ///<  TPL for routine synchronization
114 
115 /**
116   Verify new TPL value
117 
118   This macro which is enabled when debug is enabled verifies that
119   the new TPL value is >= the current TPL value.
120 **/
121 #ifdef VERIFY_TPL
122 #undef VERIFY_TPL
123 #endif  //  VERIFY_TPL
124 
125 #if !defined(MDEPKG_NDEBUG)
126 
127 #define VERIFY_TPL(tpl)                           \
128 {                                                 \
129   EFI_TPL PreviousTpl;                            \
130                                                   \
131   PreviousTpl = gBS->RaiseTPL ( TPL_HIGH_LEVEL ); \
132   gBS->RestoreTPL ( PreviousTpl );                \
133   if ( PreviousTpl > tpl ) {                      \
134     DEBUG (( DEBUG_ERROR, "Current TPL: %d, New TPL: %d\r\n", PreviousTpl, tpl ));  \
135     ASSERT ( PreviousTpl <= tpl );                \
136   }                                               \
137 }
138 
139 #else   //  MDEPKG_NDEBUG
140 
141 #define VERIFY_TPL(tpl)
142 
143 #endif  //  MDEPKG_NDEBUG
144 
145 #define WEB_SERVER_SIGNATURE        SIGNATURE_32 ('W','e','b','S')  ///<  DT_WEB_SERVER memory signature
146 
147 #define SPACES_ADDRESS_TO_DATA      2
148 #define BYTES_ON_A_LINE             16
149 #define SPACES_BETWEEN_BYTES        1
150 #define SPACES_DATA_TO_ASCII        2
151 
152 
153 //------------------------------------------------------------------------------
154 // Protocol Declarations
155 //------------------------------------------------------------------------------
156 
157 extern EFI_COMPONENT_NAME_PROTOCOL gComponentName;    ///<  Component name protocol declaration
158 extern EFI_COMPONENT_NAME2_PROTOCOL gComponentName2;  ///<  Component name 2 protocol declaration
159 extern EFI_DRIVER_BINDING_PROTOCOL gDriverBinding;    ///<  Driver binding protocol declaration
160 
161 //------------------------------------------------------------------------------
162 //  Data Types
163 //------------------------------------------------------------------------------
164 
165 /**
166   Port control structure
167 **/
168 typedef struct {
169   //
170   //  Buffer management
171   //
172   size_t    RequestLength;      ///<  Request length in bytes
173   size_t    TxBytes;            ///<  Bytes in the TX buffer
174   UINT8     Request[ 65536 ];   ///<  Page request
175   UINT8     RxBuffer[ 65536 ];  ///<  Receive buffer
176   UINT8     TxBuffer[ 65536 ];  ///<  Transmit buffer
177 } WSDT_PORT;
178 
179 /**
180   Web server control structure
181 **/
182 typedef struct {
183   UINTN Signature;              ///<  Structure identification
184 
185   //
186   //  Image attributes
187   //
188   EFI_HANDLE ImageHandle;       ///<  Image handle
189 
190   //
191   //  HTTP port management
192   //
193   BOOLEAN   bRunning;           ///<  Web server running
194   EFI_EVENT TimerEvent;         ///<  Timer to open HTTP port
195   int       HttpListenPort;     ///<  File descriptor for the HTTP listen port over TCP4
196   int       HttpListenPort6;    ///<  File descriptor for the HTTP listen port over TCP6
197 
198   //
199   //  Client port management
200   //
201   nfds_t    MaxEntries;         ///<  Maximum entries in the PortList array
202   nfds_t    Entries;            ///<  The current number of entries in the PortList array
203   struct pollfd * pFdList;      ///<  List of socket file descriptors
204   WSDT_PORT ** ppPortList;      ///<  List of port management structures
205 } DT_WEB_SERVER;
206 
207 //#define SERVER_FROM_SERVICE(a) CR (a, DT_WEB_SERVER, ServiceBinding, WEB_SERVER_SIGNATURE)  ///< Locate DT_LAYER from service binding
208 
209 extern DT_WEB_SERVER mWebServer;
210 
211 /**
212   Process an HTTP request
213 
214   @param [in] SocketFD      The socket's file descriptor to add to the list.
215   @param [in] pPort         The WSDT_PORT structure address
216   @param [out] pbDone       Address to receive the request completion status
217 
218   @retval EFI_SUCCESS       The request was successfully processed
219 
220 **/
221 typedef
222 EFI_STATUS
223 (* PFN_RESPONSE) (
224   IN int SocketFD,
225   IN WSDT_PORT * pPort,
226   IN BOOLEAN * pbDone
227   );
228 
229 /**
230   Data structure to delcare page support routines
231 **/
232 typedef struct {
233   UINT16 * pPageName;         ///<  Name of the page
234   PFN_RESPONSE pfnResponse;   ///<  Routine to generate the response
235   UINT16 * pDescription;      ///<  Description of the page
236 } DT_PAGE;
237 
238 extern CONST DT_PAGE mPageList[];   ///<  List of pages
239 extern CONST UINTN mPageCount;      ///<  Number of pages
240 
241 //------------------------------------------------------------------------------
242 // Web Pages
243 //------------------------------------------------------------------------------
244 
245 /**
246   Respond with the APIC table
247 
248   @param [in] SocketFD      The socket's file descriptor to add to the list.
249   @param [in] pPort         The WSDT_PORT structure address
250   @param [out] pbDone       Address to receive the request completion status
251 
252   @retval EFI_SUCCESS       The request was successfully processed
253 
254 **/
255 EFI_STATUS
256 AcpiApicPage (
257   IN int SocketFD,
258   IN WSDT_PORT * pPort,
259   OUT BOOLEAN * pbDone
260   );
261 
262 /**
263   Respond with the BGRT table
264 
265   @param [in] SocketFD      The socket's file descriptor to add to the list.
266   @param [in] pPort         The WSDT_PORT structure address
267   @param [out] pbDone       Address to receive the request completion status
268 
269   @retval EFI_SUCCESS       The request was successfully processed
270 
271 **/
272 EFI_STATUS
273 AcpiBgrtPage (
274   IN int SocketFD,
275   IN WSDT_PORT * pPort,
276   OUT BOOLEAN * pbDone
277   );
278 
279 /**
280   Respond with the ACPI DSDT table
281 
282   @param [in] SocketFD      The socket's file descriptor to add to the list.
283   @param [in] pPort         The WSDT_PORT structure address
284   @param [out] pbDone       Address to receive the request completion status
285 
286   @retval EFI_SUCCESS       The request was successfully processed
287 
288 **/
289 EFI_STATUS
290 AcpiDsdtPage (
291   IN int SocketFD,
292   IN WSDT_PORT * pPort,
293   OUT BOOLEAN * pbDone
294   );
295 
296 /**
297   Respond with the ACPI FADT table
298 
299   @param [in] SocketFD      The socket's file descriptor to add to the list.
300   @param [in] pPort         The WSDT_PORT structure address
301   @param [out] pbDone       Address to receive the request completion status
302 
303   @retval EFI_SUCCESS       The request was successfully processed
304 
305 **/
306 EFI_STATUS
307 AcpiFadtPage (
308   IN int SocketFD,
309   IN WSDT_PORT * pPort,
310   OUT BOOLEAN * pbDone
311   );
312 
313 /**
314   Respond with the HPET table
315 
316   @param [in] SocketFD      The socket's file descriptor to add to the list.
317   @param [in] pPort         The WSDT_PORT structure address
318   @param [out] pbDone       Address to receive the request completion status
319 
320   @retval EFI_SUCCESS       The request was successfully processed
321 
322 **/
323 EFI_STATUS
324 AcpiHpetPage (
325   IN int SocketFD,
326   IN WSDT_PORT * pPort,
327   OUT BOOLEAN * pbDone
328   );
329 
330 /**
331   Respond with the MCFG table
332 
333   @param [in] SocketFD      The socket's file descriptor to add to the list.
334   @param [in] pPort         The WSDT_PORT structure address
335   @param [out] pbDone       Address to receive the request completion status
336 
337   @retval EFI_SUCCESS       The request was successfully processed
338 
339 **/
340 EFI_STATUS
341 AcpiMcfgPage (
342   IN int SocketFD,
343   IN WSDT_PORT * pPort,
344   OUT BOOLEAN * pbDone
345   );
346 
347 /**
348   Respond with the ACPI RSDP 1.0b table
349 
350   @param [in] SocketFD      The socket's file descriptor to add to the list.
351   @param [in] pPort         The WSDT_PORT structure address
352   @param [out] pbDone       Address to receive the request completion status
353 
354   @retval EFI_SUCCESS       The request was successfully processed
355 
356 **/
357 EFI_STATUS
358 AcpiRsdp10Page (
359   IN int SocketFD,
360   IN WSDT_PORT * pPort,
361   OUT BOOLEAN * pbDone
362   );
363 
364 /**
365   Respond with the ACPI RSDP 3.0 table
366 
367   @param [in] SocketFD      The socket's file descriptor to add to the list.
368   @param [in] pPort         The WSDT_PORT structure address
369   @param [out] pbDone       Address to receive the request completion status
370 
371   @retval EFI_SUCCESS       The request was successfully processed
372 
373 **/
374 EFI_STATUS
375 AcpiRsdp30Page (
376   IN int SocketFD,
377   IN WSDT_PORT * pPort,
378   OUT BOOLEAN * pbDone
379   );
380 
381 /**
382   Respond with the ACPI RSDT table
383 
384   @param [in] SocketFD      The socket's file descriptor to add to the list.
385   @param [in] pPort         The WSDT_PORT structure address
386   @param [out] pbDone       Address to receive the request completion status
387 
388   @retval EFI_SUCCESS       The request was successfully processed
389 
390 **/
391 EFI_STATUS
392 AcpiRsdtPage (
393   IN int SocketFD,
394   IN WSDT_PORT * pPort,
395   OUT BOOLEAN * pbDone
396   );
397 
398 /**
399   Respond with the SSDT table
400 
401   @param [in] SocketFD      The socket's file descriptor to add to the list.
402   @param [in] pPort         The WSDT_PORT structure address
403   @param [out] pbDone       Address to receive the request completion status
404 
405   @retval EFI_SUCCESS       The request was successfully processed
406 
407 **/
408 EFI_STATUS
409 AcpiSsdtPage (
410   IN int SocketFD,
411   IN WSDT_PORT * pPort,
412   OUT BOOLEAN * pbDone
413   );
414 
415 /**
416   Respond with the TCPA table
417 
418   @param [in] SocketFD      The socket's file descriptor to add to the list.
419   @param [in] pPort         The WSDT_PORT structure address
420   @param [out] pbDone       Address to receive the request completion status
421 
422   @retval EFI_SUCCESS       The request was successfully processed
423 
424 **/
425 EFI_STATUS
426 AcpiTcpaPage (
427   IN int SocketFD,
428   IN WSDT_PORT * pPort,
429   OUT BOOLEAN * pbDone
430   );
431 
432 /**
433   Respond with the UEFI table
434 
435   @param [in] SocketFD      The socket's file descriptor to add to the list.
436   @param [in] pPort         The WSDT_PORT structure address
437   @param [out] pbDone       Address to receive the request completion status
438 
439   @retval EFI_SUCCESS       The request was successfully processed
440 
441 **/
442 EFI_STATUS
443 AcpiUefiPage (
444   IN int SocketFD,
445   IN WSDT_PORT * pPort,
446   OUT BOOLEAN * pbDone
447   );
448 
449 /**
450   Respond with the boot services table
451 
452   @param [in] SocketFD      The socket's file descriptor to add to the list.
453   @param [in] pPort         The WSDT_PORT structure address
454   @param [out] pbDone       Address to receive the request completion status
455 
456   @retval EFI_SUCCESS       The request was successfully processed
457 
458 **/
459 EFI_STATUS
460 BootServicesTablePage (
461   IN int SocketFD,
462   IN WSDT_PORT * pPort,
463   OUT BOOLEAN * pbDone
464   );
465 
466 /**
467   Respond with the configuration tables
468 
469   @param [in] SocketFD      The socket's file descriptor to add to the list.
470   @param [in] pPort         The WSDT_PORT structure address
471   @param [out] pbDone       Address to receive the request completion status
472 
473   @retval EFI_SUCCESS       The request was successfully processed
474 
475 **/
476 EFI_STATUS
477 ConfigurationTablePage (
478   IN int SocketFD,
479   IN WSDT_PORT * pPort,
480   OUT BOOLEAN * pbDone
481   );
482 
483 /**
484   Respond with the DHCP options
485 
486   @param [in] SocketFD      The socket's file descriptor to add to the list.
487   @param [in] pPort         The WSDT_PORT structure address
488   @param [out] pbDone       Address to receive the request completion status
489 
490   @retval EFI_SUCCESS       The request was successfully processed
491 
492 **/
493 EFI_STATUS
494 DhcpOptionsPage (
495   IN int SocketFD,
496   IN WSDT_PORT * pPort,
497   OUT BOOLEAN * pbDone
498   );
499 
500 /**
501   Respond with the DXE services table
502 
503   @param [in] SocketFD      The socket's file descriptor to add to the list.
504   @param [in] pPort         The WSDT_PORT structure address
505   @param [out] pbDone       Address to receive the request completion status
506 
507   @retval EFI_SUCCESS       The request was successfully processed
508 
509 **/
510 EFI_STATUS
511 DxeServicesTablePage (
512   IN int SocketFD,
513   IN WSDT_PORT * pPort,
514   OUT BOOLEAN * pbDone
515   );
516 
517 /**
518   Respond with the Exit page
519 
520   @param [in] SocketFD      The socket's file descriptor to add to the list.
521   @param [in] pPort         The WSDT_PORT structure address
522   @param [out] pbDone       Address to receive the request completion status
523 
524   @retval EFI_SUCCESS       The request was successfully processed
525 
526 **/
527 EFI_STATUS
528 ExitPage (
529   IN int SocketFD,
530   IN WSDT_PORT * pPort,
531   OUT BOOLEAN * pbDone
532   );
533 
534 /**
535   Respond with the firmware status
536 
537   @param [in] SocketFD      The socket's file descriptor to add to the list.
538   @param [in] pPort         The WSDT_PORT structure address
539   @param [out] pbDone       Address to receive the request completion status
540 
541   @retval EFI_SUCCESS       The request was successfully processed
542 
543 **/
544 EFI_STATUS
545 FirmwarePage (
546   IN int SocketFD,
547   IN WSDT_PORT * pPort,
548   OUT BOOLEAN * pbDone
549   );
550 
551 /**
552   Respond with the handles in the system
553 
554   @param [in] SocketFD      The socket's file descriptor to add to the list.
555   @param [in] pPort         The WSDT_PORT structure address
556   @param [out] pbDone       Address to receive the request completion status
557 
558   @retval EFI_SUCCESS       The request was successfully processed
559 
560 **/
561 EFI_STATUS
562 HandlePage (
563   IN int SocketFD,
564   IN WSDT_PORT * pPort,
565   OUT BOOLEAN * pbDone
566   );
567 
568 /**
569   Respond with the Hello World page
570 
571   @param [in] SocketFD      The socket's file descriptor to add to the list.
572   @param [in] pPort         The WSDT_PORT structure address
573   @param [out] pbDone       Address to receive the request completion status
574 
575   @retval EFI_SUCCESS       The request was successfully processed
576 
577 **/
578 EFI_STATUS
579 HelloPage (
580   IN int SocketFD,
581   IN WSDT_PORT * pPort,
582   OUT BOOLEAN * pbDone
583   );
584 
585 /**
586   Respond with the list of known pages
587 
588   @param [in] SocketFD      The socket's file descriptor to add to the list.
589   @param [in] pPort         The WSDT_PORT structure address
590   @param [out] pbDone       Address to receive the request completion status
591 
592   @retval EFI_SUCCESS       The request was successfully processed
593 
594 **/
595 EFI_STATUS
596 IndexPage (
597   IN int SocketFD,
598   IN WSDT_PORT * pPort,
599   OUT BOOLEAN * pbDone
600   );
601 
602 /**
603   Page to display the memory map
604 
605   @param [in] SocketFD      The socket's file descriptor to add to the list.
606   @param [in] pPort         The WSDT_PORT structure address
607   @param [out] pbDone       Address to receive the request completion status
608 
609   @retval EFI_SUCCESS       The request was successfully processed
610 
611 **/
612 EFI_STATUS
613 MemoryMapPage (
614   IN int SocketFD,
615   IN WSDT_PORT * pPort,
616   OUT BOOLEAN * pbDone
617   );
618 
619 /**
620   Display the memory type registers
621 
622   @param [in] SocketFD      The socket's file descriptor to add to the list.
623   @param [in] pPort         The WSDT_PORT structure address
624   @param [out] pbDone       Address to receive the request completion status
625 
626   @retval EFI_SUCCESS       The request was successfully processed
627 
628 **/
629 EFI_STATUS
630 MemoryTypeRegistersPage (
631   IN int SocketFD,
632   IN WSDT_PORT * pPort,
633   OUT BOOLEAN * pbDone
634   );
635 
636 /**
637   Respond with the Ports page
638 
639   @param [in] SocketFD      The socket's file descriptor to add to the list.
640   @param [in] pPort         The WSDT_PORT structure address
641   @param [out] pbDone       Address to receive the request completion status
642 
643   @retval EFI_SUCCESS       The request was successfully processed
644 
645 **/
646 EFI_STATUS
647 PortsPage (
648   IN int SocketFD,
649   IN WSDT_PORT * pPort,
650   OUT BOOLEAN * pbDone
651   );
652 
653 /**
654   Page to reboot the system
655 
656   @param [in] SocketFD      The socket's file descriptor to add to the list.
657   @param [in] pPort         The WSDT_PORT structure address
658   @param [out] pbDone       Address to receive the request completion status
659 
660   @retval EFI_SUCCESS       The request was successfully processed
661 
662 **/
663 EFI_STATUS
664 RebootPage (
665   IN int SocketFD,
666   IN WSDT_PORT * pPort,
667   OUT BOOLEAN * pbDone
668   );
669 
670 /**
671   Respond with the runtime services table
672 
673   @param [in] SocketFD      The socket's file descriptor to add to the list.
674   @param [in] pPort         The WSDT_PORT structure address
675   @param [out] pbDone       Address to receive the request completion status
676 
677   @retval EFI_SUCCESS       The request was successfully processed
678 
679 **/
680 EFI_STATUS
681 RuntimeSservicesTablePage (
682   IN int SocketFD,
683   IN WSDT_PORT * pPort,
684   OUT BOOLEAN * pbDone
685   );
686 
687 /**
688   Respond with the system table
689 
690   @param [in] SocketFD      The socket's file descriptor to add to the list.
691   @param [in] pPort         The WSDT_PORT structure address
692   @param [out] pbDone       Address to receive the request completion status
693 
694   @retval EFI_SUCCESS       The request was successfully processed
695 
696 **/
697 EFI_STATUS
698 SystemTablePage (
699   IN int SocketFD,
700   IN WSDT_PORT * pPort,
701   OUT BOOLEAN * pbDone
702   );
703 
704 //------------------------------------------------------------------------------
705 // Support routines
706 //------------------------------------------------------------------------------
707 
708 /**
709   Display the EFI Table Header
710 
711   @param [in] SocketFD      The socket's file descriptor to add to the list.
712   @param [in] pPort         The WSDT_PORT structure address
713   @param [in] pHeader       Address of the EFI_TABLE_HEADER structure
714 
715   @retval EFI_SUCCESS       The request was successfully processed
716 
717 **/
718 EFI_STATUS
719 EfiTableHeader (
720   IN int SocketFD,
721   IN WSDT_PORT * pPort,
722   IN EFI_TABLE_HEADER * pHeader
723   );
724 
725 /**
726   Buffer the HTTP page header
727 
728   @param [in] SocketFD      The socket's file descriptor to add to the list.
729   @param [in] pPort         The WSDT_PORT structure address
730   @param [in] pTitle        A zero terminated Unicode title string
731 
732   @retval EFI_SUCCESS       The request was successfully processed
733 
734 **/
735 EFI_STATUS
736 HttpPageHeader (
737   IN int SocketFD,
738   IN WSDT_PORT * pPort,
739   IN CONST CHAR16 * pTitle
740   );
741 
742 /**
743   Buffer and send the HTTP page trailer
744 
745   @param [in] SocketFD      The socket's file descriptor to add to the list.
746   @param [in] pPort         The WSDT_PORT structure address
747   @param [out] pbDone       Address to receive the request completion status
748 
749   @retval EFI_SUCCESS       The request was successfully processed
750 
751 **/
752 EFI_STATUS
753 HttpPageTrailer (
754   IN int SocketFD,
755   IN WSDT_PORT * pPort,
756   IN BOOLEAN * pbDone
757   );
758 
759 /**
760   Process an HTTP request
761 
762   @param [in] SocketFD      The socket's file descriptor to add to the list.
763   @param [in] pPort         The WSDT_PORT structure address
764   @param [out] pbDone       Address to receive the request completion status
765 
766   @retval EFI_SUCCESS       The request was successfully processed
767 
768 **/
769 EFI_STATUS
770 HttpRequest (
771   IN int SocketFD,
772   IN WSDT_PORT * pPort,
773   IN BOOLEAN * pbDone
774   );
775 
776 /**
777   Buffer data for sending
778 
779   @param [in] SocketFD      The socket's file descriptor to add to the list.
780   @param [in] pPort         The WSDT_PORT structure address
781   @param [in] LengthInBytes Length of valid data in the buffer
782   @param [in] pBuffer       Buffer of data to send
783 
784   @retval EFI_SUCCESS       The request was successfully processed
785 
786 **/
787 EFI_STATUS
788 HttpSend (
789   IN int SocketFD,
790   IN WSDT_PORT * pPort,
791   IN size_t LengthInBytes,
792   IN CONST UINT8 * pBuffer
793   );
794 
795 /**
796   Send an ANSI string
797 
798   @param [in] SocketFD      The socket's file descriptor to add to the list.
799   @param [in] pPort         The WSDT_PORT structure address
800   @param [in] pString       A zero terminated Unicode string
801 
802   @retval EFI_SUCCESS       The request was successfully processed
803 
804 **/
805 EFI_STATUS
806 HttpSendAnsiString (
807   IN int SocketFD,
808   IN WSDT_PORT * pPort,
809   IN CONST char * pString
810   );
811 
812 /**
813   Buffer a single byte
814 
815   @param [in] SocketFD      The socket's file descriptor to add to the list.
816   @param [in] pPort         The WSDT_PORT structure address
817   @param [in] Data          The data byte to send
818 
819   @retval EFI_SUCCESS       The request was successfully processed
820 
821 **/
822 EFI_STATUS
823 HttpSendByte (
824   IN int SocketFD,
825   IN WSDT_PORT * pPort,
826   IN UINT8 Data
827   );
828 
829 /**
830   Display a character
831 
832   @param [in] SocketFD      The socket's file descriptor to add to the list.
833   @param [in] pPort         The WSDT_PORT structure address
834   @param [in] Character     Character to display
835   @param [in] pReplacement  Replacement character string
836 
837   @retval EFI_SUCCESS       The request was successfully processed
838 
839 **/
840 EFI_STATUS
841 HttpSendCharacter (
842   IN int SocketFD,
843   IN WSDT_PORT * pPort,
844   IN CHAR8 Character,
845   IN CHAR8 * pReplacement
846   );
847 
848 /**
849   Send a buffer dump
850 
851   @param [in] SocketFD      The socket's file descriptor to add to the list.
852   @param [in] pPort         The WSDT_PORT structure address
853   @param [in] ByteCount     The number of bytes to display
854   @param [in] pData         Address of the byte array
855 
856   @retval EFI_SUCCESS       The request was successfully processed
857 
858 **/
859 EFI_STATUS
860 HttpSendDump (
861   IN int SocketFD,
862   IN WSDT_PORT * pPort,
863   IN UINTN ByteCount,
864   IN CONST UINT8 * pData
865   );
866 
867 /**
868   Display a row containing a GUID value
869 
870   @param [in] SocketFD      The socket's file descriptor to add to the list.
871   @param [in] pPort         The WSDT_PORT structure address
872   @param [in] pGuid         Address of the GUID to display
873 
874   @retval EFI_SUCCESS       The request was successfully processed
875 
876 **/
877 EFI_STATUS
878 HttpSendGuid (
879   IN int SocketFD,
880   IN WSDT_PORT * pPort,
881   IN CONST EFI_GUID * pGuid
882   );
883 
884 /**
885   Output a hex value to the HTML page
886 
887   @param [in] SocketFD    Socket file descriptor
888   @param [in] pPort       The WSDT_PORT structure address
889   @param [in] Bits        Number of bits to display
890   @param [in] Value       Value to display
891 
892   @retval EFI_SUCCESS Successfully displayed the address
893 **/
894 EFI_STATUS
895 HttpSendHexBits (
896   IN int SocketFD,
897   IN WSDT_PORT * pPort,
898   IN INT32 Bits,
899   IN UINT64 Value
900   );
901 
902 /**
903   Output a hex value to the HTML page
904 
905   @param [in] SocketFD    Socket file descriptor
906   @param [in] pPort       The WSDT_PORT structure address
907   @param [in] Value       Value to display
908 
909   @retval EFI_SUCCESS Successfully displayed the address
910 **/
911 EFI_STATUS
912 HttpSendHexValue (
913   IN int SocketFD,
914   IN WSDT_PORT * pPort,
915   IN UINT64 Value
916   );
917 
918 /**
919   Output an IP address to the HTML page
920 
921   @param [in] SocketFD    Socket file descriptor
922   @param [in] pPort       The WSDT_PORT structure address
923   @param [in] pAddress    Address of the socket address
924 
925   @retval EFI_SUCCESS Successfully displayed the address
926 **/
927 EFI_STATUS
928 HttpSendIpAddress (
929   IN int SocketFD,
930   IN WSDT_PORT * pPort,
931   IN struct sockaddr_in6 * pAddress
932   );
933 
934 /**
935   Send a Unicode string
936 
937   @param [in] SocketFD      The socket's file descriptor to add to the list.
938   @param [in] pPort         The WSDT_PORT structure address
939   @param [in] pString       A zero terminated Unicode string
940 
941   @retval EFI_SUCCESS       The request was successfully processed
942 
943 **/
944 EFI_STATUS
945 HttpSendUnicodeString (
946   IN int SocketFD,
947   IN WSDT_PORT * pPort,
948   IN CONST UINT16 * pString
949   );
950 
951 /**
952   Output a value to the HTML page
953 
954   @param [in] SocketFD    Socket file descriptor
955   @param [in] pPort       The WSDT_PORT structure address
956   @param [in] Value       Value to display
957 
958   @retval EFI_SUCCESS Successfully displayed the address
959 **/
960 EFI_STATUS
961 HttpSendValue (
962   IN int SocketFD,
963   IN WSDT_PORT * pPort,
964   IN UINT64 Value
965   );
966 
967 /**
968   Display a row containing a decimal value
969 
970   @param [in] SocketFD      The socket's file descriptor to add to the list.
971   @param [in] pPort         The WSDT_PORT structure address
972   @param [in] pName         Address of a zero terminated name string
973   @param [in] Value         The value to display
974 
975   @retval EFI_SUCCESS       The request was successfully processed
976 
977 **/
978 EFI_STATUS
979 RowDecimalValue (
980   IN int SocketFD,
981   IN WSDT_PORT * pPort,
982   IN CONST CHAR8 * pName,
983   IN UINT64 Value
984   );
985 
986 /**
987   Display a row containing a GUID value
988 
989   @param [in] SocketFD      The socket's file descriptor to add to the list.
990   @param [in] pPort         The WSDT_PORT structure address
991   @param [in] pName         Address of a zero terminated name string
992   @param [in] pGuid         Address of the GUID to display
993 
994   @retval EFI_SUCCESS       The request was successfully processed
995 
996 **/
997 EFI_STATUS
998 RowGuid (
999   IN int SocketFD,
1000   IN WSDT_PORT * pPort,
1001   IN CONST CHAR8 * pName,
1002   IN CONST EFI_GUID * pGuid
1003   );
1004 
1005 /**
1006   Display a row containing a hex value
1007 
1008   @param [in] SocketFD      The socket's file descriptor to add to the list.
1009   @param [in] pPort         The WSDT_PORT structure address
1010   @param [in] pName         Address of a zero terminated name string
1011   @param [in] Value         The value to display
1012   @param [in] pWebPage      Address of a zero terminated web page name
1013 
1014   @retval EFI_SUCCESS       The request was successfully processed
1015 
1016 **/
1017 EFI_STATUS
1018 RowHexValue (
1019   IN int SocketFD,
1020   IN WSDT_PORT * pPort,
1021   IN CONST CHAR8 * pName,
1022   IN UINT64 Value,
1023   IN CONST CHAR16 * pWebPage
1024   );
1025 
1026 /**
1027   Display a row containing a pointer
1028 
1029   @param [in] SocketFD      The socket's file descriptor to add to the list.
1030   @param [in] pPort         The WSDT_PORT structure address
1031   @param [in] pName         Address of a zero terminated name string
1032   @param [in] pAddress      The address to display
1033   @param [in] pWebPage      Address of a zero terminated web page name
1034 
1035   @retval EFI_SUCCESS       The request was successfully processed
1036 
1037 **/
1038 EFI_STATUS
1039 RowPointer (
1040   IN int SocketFD,
1041   IN WSDT_PORT * pPort,
1042   IN CONST CHAR8 * pName,
1043   IN CONST VOID * pAddress,
1044   IN CONST CHAR16 * pWebPage
1045   );
1046 
1047 /**
1048   Display a row containing a revision
1049 
1050   @param [in] SocketFD      The socket's file descriptor to add to the list.
1051   @param [in] pPort         The WSDT_PORT structure address
1052   @param [in] pName         Address of a zero terminated name string
1053   @param [in] Revision      The revision to display
1054 
1055   @retval EFI_SUCCESS       The request was successfully processed
1056 
1057 **/
1058 EFI_STATUS
1059 RowRevision (
1060   IN int SocketFD,
1061   IN WSDT_PORT * pPort,
1062   IN CONST CHAR8 * pName,
1063   IN UINT32 Revision
1064   );
1065 
1066 /**
1067   Display a row containing a unicode string
1068 
1069   @param [in] SocketFD      The socket's file descriptor to add to the list.
1070   @param [in] pPort         The WSDT_PORT structure address
1071   @param [in] pName         Address of a zero terminated name string
1072   @param [in] pString       Address of a zero terminated unicode string
1073 
1074   @retval EFI_SUCCESS       The request was successfully processed
1075 
1076 **/
1077 EFI_STATUS
1078 RowUnicodeString (
1079   IN int SocketFD,
1080   IN WSDT_PORT * pPort,
1081   IN CONST CHAR8 * pName,
1082   IN CONST CHAR16 * pString
1083   );
1084 
1085 /**
1086   Start the table page
1087 
1088   @param [in] SocketFD      The socket's file descriptor to add to the list.
1089   @param [in] pPort         The WSDT_PORT structure address
1090   @param [in] pName         Address of a zero terminated name string
1091   @param [in] pTable        Address of the table
1092 
1093   @retval EFI_SUCCESS       The request was successfully processed
1094 
1095 **/
1096 EFI_STATUS
1097 TableHeader (
1098   IN int SocketFD,
1099   IN WSDT_PORT * pPort,
1100   IN CONST CHAR16 * pName,
1101   IN CONST VOID * pTable
1102   );
1103 
1104 /**
1105   End the table page
1106 
1107   @param [in] SocketFD      The socket's file descriptor to add to the list.
1108   @param [in] pPort         The WSDT_PORT structure address
1109   @param [out] pbDone       Address to receive the request completion status
1110 
1111   @retval EFI_SUCCESS       The request was successfully processed
1112 
1113 **/
1114 EFI_STATUS
1115 TableTrailer (
1116   IN int SocketFD,
1117   IN WSDT_PORT * pPort,
1118   OUT BOOLEAN *pbDone
1119   );
1120 
1121 /**
1122   HTTP port creation timer routine
1123 
1124   This routine polls the socket layer waiting for the initial network connection
1125   which will enable the creation of the HTTP port.  The socket layer will manage
1126   the coming and going of the network connections after that until the last network
1127   connection is broken.
1128 
1129   @param [in] pWebServer  The web server control structure address.
1130 
1131 **/
1132 VOID
1133 WebServerTimer (
1134   IN DT_WEB_SERVER * pWebServer
1135   );
1136 
1137 /**
1138   Start the web server port creation timer
1139 
1140   @param [in] pWebServer  The web server control structure address.
1141 
1142   @retval EFI_SUCCESS         The timer was successfully started.
1143   @retval EFI_ALREADY_STARTED The timer is already running.
1144   @retval Other               The timer failed to start.
1145 
1146 **/
1147 EFI_STATUS
1148 WebServerTimerStart (
1149   IN DT_WEB_SERVER * pWebServer
1150   );
1151 
1152 /**
1153   Stop the web server port creation timer
1154 
1155   @param [in] pWebServer  The web server control structure address.
1156 
1157   @retval EFI_SUCCESS   The HTTP port timer is stopped
1158   @retval Other         Failed to stop the HTTP port timer
1159 
1160 **/
1161 EFI_STATUS
1162 WebServerTimerStop (
1163   IN DT_WEB_SERVER * pWebServer
1164   );
1165 
1166 //------------------------------------------------------------------------------
1167 // Driver Binding Protocol Support
1168 //------------------------------------------------------------------------------
1169 
1170 /**
1171   Stop this driver on Controller by removing NetworkInterfaceIdentifier protocol and
1172   closing the DevicePath and PciIo protocols on Controller.
1173 
1174   @param [in] pThis                Protocol instance pointer.
1175   @param [in] Controller           Handle of device to stop driver on.
1176   @param [in] NumberOfChildren     How many children need to be stopped.
1177   @param [in] pChildHandleBuffer   Not used.
1178 
1179   @retval EFI_SUCCESS          This driver is removed Controller.
1180   @retval EFI_DEVICE_ERROR     The device could not be stopped due to a device error.
1181   @retval other                This driver was not removed from this device.
1182 
1183 **/
1184 EFI_STATUS
1185 EFIAPI
1186 DriverStop (
1187   IN  EFI_DRIVER_BINDING_PROTOCOL * pThis,
1188   IN  EFI_HANDLE Controller,
1189   IN  UINTN NumberOfChildren,
1190   IN  EFI_HANDLE * pChildHandleBuffer
1191   );
1192 
1193 //------------------------------------------------------------------------------
1194 // EFI Component Name Protocol Support
1195 //------------------------------------------------------------------------------
1196 
1197 /**
1198   Retrieves a Unicode string that is the user readable name of the driver.
1199 
1200   This function retrieves the user readable name of a driver in the form of a
1201   Unicode string. If the driver specified by This has a user readable name in
1202   the language specified by Language, then a pointer to the driver name is
1203   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
1204   by This does not support the language specified by Language,
1205   then EFI_UNSUPPORTED is returned.
1206 
1207   @param [in] pThis             A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
1208                                 EFI_COMPONENT_NAME_PROTOCOL instance.
1209   @param [in] pLanguage         A pointer to a Null-terminated ASCII string
1210                                 array indicating the language. This is the
1211                                 language of the driver name that the caller is
1212                                 requesting, and it must match one of the
1213                                 languages specified in SupportedLanguages. The
1214                                 number of languages supported by a driver is up
1215                                 to the driver writer. Language is specified
1216                                 in RFC 3066 or ISO 639-2 language code format.
1217   @param [out] ppDriverName     A pointer to the Unicode string to return.
1218                                 This Unicode string is the name of the
1219                                 driver specified by This in the language
1220                                 specified by Language.
1221 
1222   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
1223                                 This and the language specified by Language was
1224                                 returned in DriverName.
1225   @retval EFI_INVALID_PARAMETER Language is NULL.
1226   @retval EFI_INVALID_PARAMETER DriverName is NULL.
1227   @retval EFI_UNSUPPORTED       The driver specified by This does not support
1228                                 the language specified by Language.
1229 
1230 **/
1231 EFI_STATUS
1232 EFIAPI
1233 GetDriverName (
1234   IN  EFI_COMPONENT_NAME_PROTOCOL * pThis,
1235   IN  CHAR8 * pLanguage,
1236   OUT CHAR16 ** ppDriverName
1237   );
1238 
1239 
1240 /**
1241   Retrieves a Unicode string that is the user readable name of the controller
1242   that is being managed by a driver.
1243 
1244   This function retrieves the user readable name of the controller specified by
1245   ControllerHandle and ChildHandle in the form of a Unicode string. If the
1246   driver specified by This has a user readable name in the language specified by
1247   Language, then a pointer to the controller name is returned in ControllerName,
1248   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
1249   managing the controller specified by ControllerHandle and ChildHandle,
1250   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
1251   support the language specified by Language, then EFI_UNSUPPORTED is returned.
1252 
1253   @param [in] pThis             A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
1254                                 EFI_COMPONENT_NAME_PROTOCOL instance.
1255   @param [in] ControllerHandle  The handle of a controller that the driver
1256                                 specified by This is managing.  This handle
1257                                 specifies the controller whose name is to be
1258                                 returned.
1259   @param [in] ChildHandle       The handle of the child controller to retrieve
1260                                 the name of.  This is an optional parameter that
1261                                 may be NULL.  It will be NULL for device
1262                                 drivers.  It will also be NULL for a bus drivers
1263                                 that wish to retrieve the name of the bus
1264                                 controller.  It will not be NULL for a bus
1265                                 driver that wishes to retrieve the name of a
1266                                 child controller.
1267   @param [in] pLanguage         A pointer to a Null-terminated ASCII string
1268                                 array indicating the language.  This is the
1269                                 language of the driver name that the caller is
1270                                 requesting, and it must match one of the
1271                                 languages specified in SupportedLanguages. The
1272                                 number of languages supported by a driver is up
1273                                 to the driver writer. Language is specified in
1274                                 RFC 3066 or ISO 639-2 language code format.
1275   @param [out] ppControllerName A pointer to the Unicode string to return.
1276                                 This Unicode string is the name of the
1277                                 controller specified by ControllerHandle and
1278                                 ChildHandle in the language specified by
1279                                 Language from the point of view of the driver
1280                                 specified by This.
1281 
1282   @retval EFI_SUCCESS           The Unicode string for the user readable name in
1283                                 the language specified by Language for the
1284                                 driver specified by This was returned in
1285                                 DriverName.
1286   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
1287   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
1288                                 EFI_HANDLE.
1289   @retval EFI_INVALID_PARAMETER Language is NULL.
1290   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
1291   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
1292                                 managing the controller specified by
1293                                 ControllerHandle and ChildHandle.
1294   @retval EFI_UNSUPPORTED       The driver specified by This does not support
1295                                 the language specified by Language.
1296 
1297 **/
1298 EFI_STATUS
1299 EFIAPI
1300 GetControllerName (
1301   IN  EFI_COMPONENT_NAME_PROTOCOL * pThis,
1302   IN  EFI_HANDLE ControllerHandle,
1303   IN OPTIONAL EFI_HANDLE ChildHandle,
1304   IN  CHAR8 * pLanguage,
1305   OUT CHAR16 ** ppControllerName
1306   );
1307 
1308 //------------------------------------------------------------------------------
1309 
1310 #endif  //  _WEB_SERVER_H_
1311