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