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__
21 #include <Protocol/Dhcp4.h>
22 #include <Protocol/Udp4.h>
23 #include <IndustryStandard/Dhcp.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiDriverEntryPoint.h>
26 #include <Library/UefiBootServicesTableLib.h>
27 #include <Library/UefiLib.h>
28 #include <Library/BaseLib.h>
29 #include <Library/NetLib.h>
31 typedef struct _DHCP_SERVICE DHCP_SERVICE
;
32 typedef struct _DHCP_PROTOCOL DHCP_PROTOCOL
;
34 #include "Dhcp4Option.h"
37 #define DHCP_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', 'C', 'P')
38 #define DHCP_PROTOCOL_SIGNATURE SIGNATURE_32 ('d', 'h', 'c', 'p')
40 #define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
43 // The state of the DHCP service. It starts as UNCONFIGED. If
44 // and active child configures the service successfully, it
45 // goes to CONFIGED. If the active child configures NULL, it
46 // goes back to UNCONFIGED. It becomes DESTROY if it is (partly)
49 #define DHCP_UNCONFIGED 0
50 #define DHCP_CONFIGED 1
51 #define DHCP_DESTROY 2
54 struct _DHCP_PROTOCOL
{
56 EFI_DHCP4_PROTOCOL Dhcp4Protocol
;
59 DHCP_SERVICE
*Service
;
63 EFI_EVENT CompletionEvent
;
64 EFI_EVENT RenewRebindEvent
;
66 EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN
*Token
;
67 UDP_IO
*UdpIo
; // The UDP IO used for TransmitReceive.
70 NET_BUF_QUEUE ResponseQueue
;
74 // DHCP driver is specical in that it is a singleton. Although it
75 // has a service binding, there can be only one active child.
77 struct _DHCP_SERVICE
{
79 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
81 INTN ServiceState
; // CONFIGED, UNCONFIGED, and DESTROY
83 EFI_HANDLE Controller
;
90 EFI_STATUS IoStatus
; // the result of last user operation
93 IP4_ADDR ClientAddr
; // lease IP or configured client address
97 EFI_DHCP4_PACKET
*LastOffer
; // The last received offer
98 EFI_DHCP4_PACKET
*Selected
;
104 INTN ExtraRefresh
; // This refresh is reqested by user
106 UDP_IO
*UdpIo
; // Udp child receiving all DHCP message
107 UDP_IO
*LeaseIoPort
; // Udp child with lease IP
108 EFI_DHCP4_PACKET
*LastPacket
; // The last sent packet for retransmission
112 UINT8 ClientAddressSendOut
[16];
114 DHCP_PROTOCOL
*ActiveChild
;
115 EFI_DHCP4_CONFIG_DATA ActiveConfig
;
116 UINT32 UserOptionLen
;
119 // Timer event and various timer
123 UINT32 PacketToLive
; // Retransmission timer for our packets
124 UINT32 LastTimeout
; // Record the init value of PacketToLive every time
131 EFI_DHCP4_PACKET_OPTION
**Option
;
134 } DHCP_PARSE_CONTEXT
;
136 #define DHCP_INSTANCE_FROM_THIS(Proto) \
137 CR ((Proto), DHCP_PROTOCOL, Dhcp4Protocol, DHCP_PROTOCOL_SIGNATURE)
139 #define DHCP_SERVICE_FROM_THIS(Sb) \
140 CR ((Sb), DHCP_SERVICE, ServiceBinding, DHCP_SERVICE_SIGNATURE)
142 extern EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate
;
145 Give up the control of the DHCP service to let other child
146 resume. Don't change the service's DHCP state and the Client
147 address and option list configure as required by RFC2131.
149 @param DhcpSb The DHCP service instance.
154 IN DHCP_SERVICE
*DhcpSb
158 Complete a Dhcp4 transaction and signal the upper layer.
160 @param Instance Dhcp4 instance.
165 IN DHCP_PROTOCOL
*Instance
169 Free the resource related to the configure parameters.
170 DHCP driver will make a copy of the user's configure
171 such as the time out value.
173 @param Config The DHCP configure data
178 IN OUT EFI_DHCP4_CONFIG_DATA
*Config
182 Callback of Dhcp packet. Does nothing.
184 @param Arg The context.
194 Set the elapsed time based on the given instance and the pointer to the
197 @param[in] Elapsed The pointer to the position to append.
198 @param[in] Instance The pointer to the Dhcp4 instance.
203 IN DHCP_PROTOCOL
*Instance