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