3 Display the DHCP options
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
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.
16 #include <WebServer.h>
17 #include <Guid/DxeServices.h>
18 #include <pi/PiDxeCis.h>
20 #include <protocol/Dhcp4.h>
21 #include <protocol/ServiceBinding.h>
24 Respond with the DHCP options
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
30 @retval EFI_SUCCESS The request was successfully processed
40 // EFI_HANDLE Dhcp4Handle;
41 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
43 EFI_DHCP4_PROTOCOL
* pDhcp4
;
44 EFI_DHCP4_PACKET
* pDhcp4Packet
;
47 // EFI_SERVICE_BINDING_PROTOCOL * pService;
53 // Send the DHCP options
57 // Send the page header
59 Status
= HttpPageHeader ( SocketFD
, pPort
, L
"DHCP Options" );
60 if ( EFI_ERROR ( Status
)) {
67 Status
= HttpSendAnsiString ( SocketFD
,
70 if ( EFI_ERROR ( Status
)) {
73 Status
= HttpSendUnicodeString ( SocketFD
,
76 if ( EFI_ERROR ( Status
)) {
79 Status
= HttpSendAnsiString ( SocketFD
,
82 if ( EFI_ERROR ( Status
)) {
87 // Attempt to locate DHCP clients
89 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
90 // &gEfiDhcp4ServiceBindingProtocolGuid,
91 &gEfiDhcp4ProtocolGuid
,
95 if ( EFI_ERROR ( Status
)) {
96 Status
= HttpSendAnsiString ( SocketFD
,
99 if ( EFI_ERROR ( Status
)) {
105 // Walk the list of handles
107 pEnd
= &pHandle
[ HandleCount
];
108 while ( pEnd
> pHandle
) {
111 // Get the DHCP service binding
113 Status = gBS->OpenProtocol ( *pHandle,
114 &gEfiDhcp4ServiceBindingProtocolGuid,
118 EFI_OPEN_PROTOCOL_GET_PROTOCOL );
119 if ( EFI_ERROR ( Status )) {
120 Status = HttpSendAnsiString ( SocketFD,
122 "Failed to open gEfiDhcp4ServiceBindingProtocolGuid" );
127 // Get the DHCP handle
129 Status = pService->CreateChild ( pService,
131 if ( EFI_ERROR ( Status )) {
132 Status = HttpSendAnsiString ( SocketFD,
134 "Failed to create DHCP4 child" );
139 // Get the DHCP protocol
141 Status
= gBS
->OpenProtocol ( *pHandle
,
143 &gEfiDhcp4ProtocolGuid
,
147 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
148 if ( EFI_ERROR ( Status
)) {
149 Status
= HttpSendAnsiString ( SocketFD
,
151 "Failed to open gEfiDhcp4ProtocolGuid" );
155 // Get the DHCP packet
157 Status
= pDhcp4
->GetModeData ( pDhcp4
,
159 if ( EFI_ERROR ( Status
)) {
160 Status
= HttpSendAnsiString ( SocketFD
,
162 "Failed to get DHCP4 mode" );
166 // Get the last packet
168 pDhcp4Packet
= Dhcp4Mode
.ReplyPacket
;
169 if ( NULL
== pDhcp4Packet
) {
170 Status
= HttpSendAnsiString ( SocketFD
,
172 "No DHCP reply received!<br/>DHCP Mode:<br/>" );
173 if ( EFI_ERROR ( Status
)) {
178 // Display the DHCP mode data
180 Status
= HttpSendDump ( SocketFD
,
182 sizeof ( Dhcp4Mode
),
183 (UINT8
*)&Dhcp4Mode
);
187 // Display the DHCP packet
189 Status
= HttpSendDump ( SocketFD
,
191 pDhcp4Packet
->Length
,
192 (UINT8
*)&pDhcp4Packet
->Dhcp4
);
199 // Done with the DHCP protocol
201 pService->DestroyChild ( pService,
207 // Set the next service binding
214 // Send the page trailer
216 Status
= HttpPageTrailer ( SocketFD
, pPort
, pbDone
);
221 // Return the operation status
223 DBG_EXIT_STATUS ( Status
);