2 Display the DHCP options
4 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 #include <Guid/DxeServices.h>
9 #include <Pi/PiDxeCis.h>
11 #include <Protocol/Dhcp4.h>
12 #include <Protocol/ServiceBinding.h>
15 Respond with the DHCP options
17 @param[in] SocketFD The socket's file descriptor to add to the list.
18 @param[in] pPort The WSDT_PORT structure address
19 @param[out] pbDone Address to receive the request completion status
21 @retval EFI_SUCCESS The request was successfully processed
31 // EFI_HANDLE Dhcp4Handle;
32 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
34 EFI_DHCP4_PROTOCOL
* pDhcp4
;
35 EFI_DHCP4_PACKET
* pDhcp4Packet
;
38 // EFI_SERVICE_BINDING_PROTOCOL * pService;
44 // Send the DHCP options
48 // Send the page header
50 Status
= HttpPageHeader ( SocketFD
, pPort
, L
"DHCP Options" );
51 if ( EFI_ERROR ( Status
)) {
58 Status
= HttpSendAnsiString ( SocketFD
,
61 if ( EFI_ERROR ( Status
)) {
64 Status
= HttpSendUnicodeString ( SocketFD
,
67 if ( EFI_ERROR ( Status
)) {
70 Status
= HttpSendAnsiString ( SocketFD
,
73 if ( EFI_ERROR ( Status
)) {
78 // Attempt to locate DHCP clients
80 Status
= gBS
->LocateHandleBuffer ( ByProtocol
,
81 // &gEfiDhcp4ServiceBindingProtocolGuid,
82 &gEfiDhcp4ProtocolGuid
,
86 if ( EFI_ERROR ( Status
)) {
87 Status
= HttpSendAnsiString ( SocketFD
,
90 if ( EFI_ERROR ( Status
)) {
96 // Walk the list of handles
98 pEnd
= &pHandle
[ HandleCount
];
99 while ( pEnd
> pHandle
) {
102 // Get the DHCP service binding
104 Status = gBS->OpenProtocol ( *pHandle,
105 &gEfiDhcp4ServiceBindingProtocolGuid,
109 EFI_OPEN_PROTOCOL_GET_PROTOCOL );
110 if ( EFI_ERROR ( Status )) {
111 Status = HttpSendAnsiString ( SocketFD,
113 "Failed to open gEfiDhcp4ServiceBindingProtocolGuid" );
118 // Get the DHCP handle
120 Status = pService->CreateChild ( pService,
122 if ( EFI_ERROR ( Status )) {
123 Status = HttpSendAnsiString ( SocketFD,
125 "Failed to create DHCP4 child" );
130 // Get the DHCP protocol
132 Status
= gBS
->OpenProtocol ( *pHandle
,
134 &gEfiDhcp4ProtocolGuid
,
138 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
139 if ( EFI_ERROR ( Status
)) {
140 Status
= HttpSendAnsiString ( SocketFD
,
142 "Failed to open gEfiDhcp4ProtocolGuid" );
146 // Get the DHCP packet
148 Status
= pDhcp4
->GetModeData ( pDhcp4
,
150 if ( EFI_ERROR ( Status
)) {
151 Status
= HttpSendAnsiString ( SocketFD
,
153 "Failed to get DHCP4 mode" );
157 // Get the last packet
159 pDhcp4Packet
= Dhcp4Mode
.ReplyPacket
;
160 if ( NULL
== pDhcp4Packet
) {
161 Status
= HttpSendAnsiString ( SocketFD
,
163 "No DHCP reply received!<br/>DHCP Mode:<br/>" );
164 if ( EFI_ERROR ( Status
)) {
169 // Display the DHCP mode data
171 Status
= HttpSendDump ( SocketFD
,
173 sizeof ( Dhcp4Mode
),
174 (UINT8
*)&Dhcp4Mode
);
178 // Display the DHCP packet
180 Status
= HttpSendDump ( SocketFD
,
182 pDhcp4Packet
->Length
,
183 (UINT8
*)&pDhcp4Packet
->Dhcp4
);
190 // Done with the DHCP protocol
192 pService->DestroyChild ( pService,
198 // Set the next service binding
205 // Send the page trailer
207 Status
= HttpPageTrailer ( SocketFD
, pPort
, pbDone
);
212 // Return the operation status
214 DBG_EXIT_STATUS ( Status
);