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