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