2 EFI DHCP protocol implementation.
4 RFC 2131: Dynamic Host Configuration Protocol
5 RFC 2132: DHCP Options and BOOTP Vendor Extensions
6 RFC 1534: Interoperation Between DHCP and BOOTP
7 RFC 3396: Encoding Long Options in DHCP.
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #ifndef __EFI_DHCP4_IMPL_H__
15 #define __EFI_DHCP4_IMPL_H__
19 #include <Protocol/Dhcp4.h>
20 #include <Protocol/Udp4.h>
21 #include <IndustryStandard/Dhcp.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/NetLib.h>
29 typedef struct _DHCP_SERVICE DHCP_SERVICE
;
30 typedef struct _DHCP_PROTOCOL DHCP_PROTOCOL
;
32 #include "Dhcp4Option.h"
35 #define DHCP_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', 'C', 'P')
36 #define DHCP_PROTOCOL_SIGNATURE SIGNATURE_32 ('d', 'h', 'c', 'p')
38 #define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
41 // The state of the DHCP service. It starts as UNCONFIGED. If
42 // and active child configures the service successfully, it
43 // goes to CONFIGED. If the active child configures NULL, it
44 // goes back to UNCONFIGED. It becomes DESTROY if it is (partly)
47 #define DHCP_UNCONFIGED 0
48 #define DHCP_CONFIGED 1
49 #define DHCP_DESTROY 2
51 struct _DHCP_PROTOCOL
{
53 EFI_DHCP4_PROTOCOL Dhcp4Protocol
;
56 DHCP_SERVICE
*Service
;
60 EFI_EVENT CompletionEvent
;
61 EFI_EVENT RenewRebindEvent
;
63 EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN
*Token
;
64 UDP_IO
*UdpIo
; // The UDP IO used for TransmitReceive.
67 NET_BUF_QUEUE ResponseQueue
;
71 // DHCP driver is specical in that it is a singleton. Although it
72 // has a service binding, there can be only one active child.
74 struct _DHCP_SERVICE
{
76 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
78 INTN ServiceState
; // CONFIGED, UNCONFIGED, and DESTROY
80 EFI_HANDLE Controller
;
87 EFI_STATUS IoStatus
; // the result of last user operation
90 IP4_ADDR ClientAddr
; // lease IP or configured client address
94 EFI_DHCP4_PACKET
*LastOffer
; // The last received offer
95 EFI_DHCP4_PACKET
*Selected
;
101 INTN ExtraRefresh
; // This refresh is reqested by user
103 UDP_IO
*UdpIo
; // Udp child receiving all DHCP message
104 UDP_IO
*LeaseIoPort
; // Udp child with lease IP
105 EFI_DHCP4_PACKET
*LastPacket
; // The last sent packet for retransmission
109 UINT8 ClientAddressSendOut
[16];
111 DHCP_PROTOCOL
*ActiveChild
;
112 EFI_DHCP4_CONFIG_DATA ActiveConfig
;
113 UINT32 UserOptionLen
;
116 // Timer event and various timer
120 UINT32 PacketToLive
; // Retransmission timer for our packets
121 UINT32 LastTimeout
; // Record the init value of PacketToLive every time
128 EFI_DHCP4_PACKET_OPTION
**Option
;
131 } DHCP_PARSE_CONTEXT
;
133 #define DHCP_INSTANCE_FROM_THIS(Proto) \
134 CR ((Proto), DHCP_PROTOCOL, Dhcp4Protocol, DHCP_PROTOCOL_SIGNATURE)
136 #define DHCP_SERVICE_FROM_THIS(Sb) \
137 CR ((Sb), DHCP_SERVICE, ServiceBinding, DHCP_SERVICE_SIGNATURE)
139 extern EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate
;
142 Give up the control of the DHCP service to let other child
143 resume. Don't change the service's DHCP state and the Client
144 address and option list configure as required by RFC2131.
146 @param DhcpSb The DHCP service instance.
151 IN DHCP_SERVICE
*DhcpSb
155 Complete a Dhcp4 transaction and signal the upper layer.
157 @param Instance Dhcp4 instance.
162 IN DHCP_PROTOCOL
*Instance
166 Free the resource related to the configure parameters.
167 DHCP driver will make a copy of the user's configure
168 such as the time out value.
170 @param Config The DHCP configure data
175 IN OUT EFI_DHCP4_CONFIG_DATA
*Config
179 Callback of Dhcp packet. Does nothing.
181 @param Arg The context.
191 Set the elapsed time based on the given instance and the pointer to the
194 @param[in] Elapsed The pointer to the position to append.
195 @param[in] Instance The pointer to the Dhcp4 instance.
200 IN DHCP_PROTOCOL
*Instance