]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/WebServer/DhcpOptions.c
AppPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / AppPkg / Applications / Sockets / WebServer / DhcpOptions.c
1 /** @file
2 Display the DHCP options
3
4 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 **/
7 #include <WebServer.h>
8 #include <Guid/DxeServices.h>
9 #include <Pi/PiDxeCis.h>
10
11 #include <Protocol/Dhcp4.h>
12 #include <Protocol/ServiceBinding.h>
13
14 /**
15 Respond with the DHCP options
16
17 @param[in] SocketFD The socket's file descriptor to add to the list.
18 @param[in] pPort The WSDT_PORT structure address
19 @param[out] pbDone Address to receive the request completion status
20
21 @retval EFI_SUCCESS The request was successfully processed
22
23 **/
24 EFI_STATUS
25 DhcpOptionsPage (
26 IN int SocketFD,
27 IN WSDT_PORT * pPort,
28 OUT BOOLEAN * pbDone
29 )
30 {
31 // EFI_HANDLE Dhcp4Handle;
32 EFI_DHCP4_MODE_DATA Dhcp4Mode;
33 UINTN HandleCount;
34 EFI_DHCP4_PROTOCOL * pDhcp4;
35 EFI_DHCP4_PACKET * pDhcp4Packet;
36 EFI_HANDLE * pEnd;
37 EFI_HANDLE * pHandle;
38 // EFI_SERVICE_BINDING_PROTOCOL * pService;
39 EFI_STATUS Status;
40
41 DBG_ENTER ( );
42
43 //
44 // Send the DHCP options
45 //
46 for ( ; ; ) {
47 //
48 // Send the page header
49 //
50 Status = HttpPageHeader ( SocketFD, pPort, L"DHCP Options" );
51 if ( EFI_ERROR ( Status )) {
52 break;
53 }
54
55 //
56 // Build the header
57 //
58 Status = HttpSendAnsiString ( SocketFD,
59 pPort,
60 "<h1>" );
61 if ( EFI_ERROR ( Status )) {
62 break;
63 }
64 Status = HttpSendUnicodeString ( SocketFD,
65 pPort,
66 L"DHCP Options" );
67 if ( EFI_ERROR ( Status )) {
68 break;
69 }
70 Status = HttpSendAnsiString ( SocketFD,
71 pPort,
72 "</h1>\r\n" );
73 if ( EFI_ERROR ( Status )) {
74 break;
75 }
76
77 //
78 // Attempt to locate DHCP clients
79 //
80 Status = gBS->LocateHandleBuffer ( ByProtocol,
81 // &gEfiDhcp4ServiceBindingProtocolGuid,
82 &gEfiDhcp4ProtocolGuid,
83 NULL,
84 &HandleCount,
85 &pHandle );
86 if ( EFI_ERROR ( Status )) {
87 Status = HttpSendAnsiString ( SocketFD,
88 pPort,
89 "DHCP not in use" );
90 if ( EFI_ERROR ( Status )) {
91 break;
92 }
93 }
94 else {
95 //
96 // Walk the list of handles
97 //
98 pEnd = &pHandle [ HandleCount ];
99 while ( pEnd > pHandle ) {
100 /*
101 //
102 // Get the DHCP service binding
103 //
104 Status = gBS->OpenProtocol ( *pHandle,
105 &gEfiDhcp4ServiceBindingProtocolGuid,
106 &pService,
107 NULL,
108 gImageHandle,
109 EFI_OPEN_PROTOCOL_GET_PROTOCOL );
110 if ( EFI_ERROR ( Status )) {
111 Status = HttpSendAnsiString ( SocketFD,
112 pPort,
113 "Failed to open gEfiDhcp4ServiceBindingProtocolGuid" );
114 break;
115 }
116
117 //
118 // Get the DHCP handle
119 //
120 Status = pService->CreateChild ( pService,
121 &Dhcp4Handle );
122 if ( EFI_ERROR ( Status )) {
123 Status = HttpSendAnsiString ( SocketFD,
124 pPort,
125 "Failed to create DHCP4 child" );
126 }
127 else {
128 */
129 //
130 // Get the DHCP protocol
131 //
132 Status = gBS->OpenProtocol ( *pHandle,
133 // Dhcp4Handle,
134 &gEfiDhcp4ProtocolGuid,
135 (VOID **)&pDhcp4,
136 NULL,
137 gImageHandle,
138 EFI_OPEN_PROTOCOL_GET_PROTOCOL );
139 if ( EFI_ERROR ( Status )) {
140 Status = HttpSendAnsiString ( SocketFD,
141 pPort,
142 "Failed to open gEfiDhcp4ProtocolGuid" );
143 }
144 else {
145 //
146 // Get the DHCP packet
147 //
148 Status = pDhcp4->GetModeData ( pDhcp4,
149 &Dhcp4Mode );
150 if ( EFI_ERROR ( Status )) {
151 Status = HttpSendAnsiString ( SocketFD,
152 pPort,
153 "Failed to get DHCP4 mode" );
154 }
155 else {
156 //
157 // Get the last packet
158 //
159 pDhcp4Packet = Dhcp4Mode.ReplyPacket;
160 if ( NULL == pDhcp4Packet ) {
161 Status = HttpSendAnsiString ( SocketFD,
162 pPort,
163 "No DHCP reply received!<br/>DHCP Mode:<br/>" );
164 if ( EFI_ERROR ( Status )) {
165 break;
166 }
167
168 //
169 // Display the DHCP mode data
170 //
171 Status = HttpSendDump ( SocketFD,
172 pPort,
173 sizeof ( Dhcp4Mode ),
174 (UINT8 *)&Dhcp4Mode );
175 }
176 else {
177 //
178 // Display the DHCP packet
179 //
180 Status = HttpSendDump ( SocketFD,
181 pPort,
182 pDhcp4Packet->Length,
183 (UINT8 *)&pDhcp4Packet->Dhcp4 );
184 }
185 }
186 /*
187 }
188
189 //
190 // Done with the DHCP protocol
191 //
192 pService->DestroyChild ( pService,
193 Dhcp4Handle );
194 */
195 }
196
197 //
198 // Set the next service binding
199 //
200 pHandle += 1;
201 }
202 }
203
204 //
205 // Send the page trailer
206 //
207 Status = HttpPageTrailer ( SocketFD, pPort, pbDone );
208 break;
209 }
210
211 //
212 // Return the operation status
213 //
214 DBG_EXIT_STATUS ( Status );
215 return Status;
216 }