2 Display the DHCP options
4 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #include <WebServer.h>
14 #include <Guid/DxeServices.h>
15 #include <Pi/PiDxeCis.h>
17 #include <Protocol/Dhcp4.h>
18 #include <Protocol/ServiceBinding.h>
21 Respond with the DHCP options
23 @param[in] SocketFD The socket's file descriptor to add to the list.
24 @param[in] pPort The WSDT_PORT structure address
25 @param[out] pbDone Address to receive the request completion status
27 @retval EFI_SUCCESS The request was successfully processed
37 // EFI_HANDLE Dhcp4Handle;
38 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
40 EFI_DHCP4_PROTOCOL
* pDhcp4
;
41 EFI_DHCP4_PACKET
* pDhcp4Packet
;
44 // EFI_SERVICE_BINDING_PROTOCOL * pService;
50 // Send the DHCP options
54 // Send the page header
56 Status
= HttpPageHeader ( SocketFD
, pPort
, L
"DHCP Options" );
57 if ( EFI_ERROR ( Status
)) {
64 Status
= HttpSendAnsiString ( SocketFD
,
67 if ( EFI_ERROR ( Status
)) {
70 Status
= HttpSendUnicodeString ( SocketFD
,
73 if ( EFI_ERROR ( Status
)) {
76 Status
= HttpSendAnsiString ( SocketFD
,
79 if ( EFI_ERROR ( Status
)) {
84 // Attempt to locate DHCP clients
86 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
87 // &gEfiDhcp4ServiceBindingProtocolGuid,
88 &gEfiDhcp4ProtocolGuid
,
92 if ( EFI_ERROR ( Status
)) {
93 Status
= HttpSendAnsiString ( SocketFD
,
96 if ( EFI_ERROR ( Status
)) {
102 // Walk the list of handles
104 pEnd
= &pHandle
[ HandleCount
];
105 while ( pEnd
> pHandle
) {
108 // Get the DHCP service binding
110 Status = gBS->OpenProtocol ( *pHandle,
111 &gEfiDhcp4ServiceBindingProtocolGuid,
115 EFI_OPEN_PROTOCOL_GET_PROTOCOL );
116 if ( EFI_ERROR ( Status )) {
117 Status = HttpSendAnsiString ( SocketFD,
119 "Failed to open gEfiDhcp4ServiceBindingProtocolGuid" );
124 // Get the DHCP handle
126 Status = pService->CreateChild ( pService,
128 if ( EFI_ERROR ( Status )) {
129 Status = HttpSendAnsiString ( SocketFD,
131 "Failed to create DHCP4 child" );
136 // Get the DHCP protocol
138 Status
= gBS
->OpenProtocol ( *pHandle
,
140 &gEfiDhcp4ProtocolGuid
,
144 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
145 if ( EFI_ERROR ( Status
)) {
146 Status
= HttpSendAnsiString ( SocketFD
,
148 "Failed to open gEfiDhcp4ProtocolGuid" );
152 // Get the DHCP packet
154 Status
= pDhcp4
->GetModeData ( pDhcp4
,
156 if ( EFI_ERROR ( Status
)) {
157 Status
= HttpSendAnsiString ( SocketFD
,
159 "Failed to get DHCP4 mode" );
163 // Get the last packet
165 pDhcp4Packet
= Dhcp4Mode
.ReplyPacket
;
166 if ( NULL
== pDhcp4Packet
) {
167 Status
= HttpSendAnsiString ( SocketFD
,
169 "No DHCP reply received!<br/>DHCP Mode:<br/>" );
170 if ( EFI_ERROR ( Status
)) {
175 // Display the DHCP mode data
177 Status
= HttpSendDump ( SocketFD
,
179 sizeof ( Dhcp4Mode
),
180 (UINT8
*)&Dhcp4Mode
);
184 // Display the DHCP packet
186 Status
= HttpSendDump ( SocketFD
,
188 pDhcp4Packet
->Length
,
189 (UINT8
*)&pDhcp4Packet
->Dhcp4
);
196 // Done with the DHCP protocol
198 pService->DestroyChild ( pService,
204 // Set the next service binding
211 // Send the page trailer
213 Status
= HttpPageTrailer ( SocketFD
, pPort
, pbDone
);
218 // Return the operation status
220 DBG_EXIT_STATUS ( Status
);