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 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #ifndef __EFI_DHCP4_IMPL_H__
21 #define __EFI_DHCP4_IMPL_H__
27 #include <Protocol/Dhcp4.h>
28 #include <Protocol/Udp4.h>
29 #include <IndustryStandard/Dhcp.h>
30 #include <Library/DebugLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/NetLib.h>
37 typedef struct _DHCP_SERVICE DHCP_SERVICE
;
38 typedef struct _DHCP_PROTOCOL DHCP_PROTOCOL
;
40 #include "Dhcp4Option.h"
43 #define DHCP_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', 'C', 'P')
44 #define DHCP_PROTOCOL_SIGNATURE SIGNATURE_32 ('d', 'h', 'c', 'p')
46 #define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
49 // The state of the DHCP service. It starts as UNCONFIGED. If
50 // and active child configures the service successfully, it
51 // goes to CONFIGED. If the active child configures NULL, it
52 // goes back to UNCONFIGED. It becomes DESTROY if it is (partly)
55 #define DHCP_UNCONFIGED 0
56 #define DHCP_CONFIGED 1
57 #define DHCP_DESTROY 2
60 struct _DHCP_PROTOCOL
{
62 EFI_DHCP4_PROTOCOL Dhcp4Protocol
;
65 DHCP_SERVICE
*Service
;
69 EFI_EVENT CompletionEvent
;
70 EFI_EVENT RenewRebindEvent
;
72 EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN
*Token
;
73 UDP_IO
*UdpIo
; // The UDP IO used for TransmitReceive.
76 NET_BUF_QUEUE ResponseQueue
;
80 // DHCP driver is specical in that it is a singleton. Although it
81 // has a service binding, there can be only one active child.
83 struct _DHCP_SERVICE
{
85 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
87 INTN ServiceState
; // CONFIGED, UNCONFIGED, and DESTROY
89 EFI_HANDLE Controller
;
96 EFI_STATUS IoStatus
; // the result of last user operation
99 IP4_ADDR ClientAddr
; // lease IP or configured client address
103 EFI_DHCP4_PACKET
*LastOffer
; // The last received offer
104 EFI_DHCP4_PACKET
*Selected
;
105 DHCP_PARAMETER
*Para
;
110 INTN ExtraRefresh
; // This refresh is reqested by user
112 UDP_IO
*UdpIo
; // Udp child receiving all DHCP message
113 UDP_IO
*LeaseIoPort
; // Udp child with lease IP
114 EFI_DHCP4_PACKET
*LastPacket
; // The last sent packet for retransmission
118 UINT8 ClientAddressSendOut
[16];
120 DHCP_PROTOCOL
*ActiveChild
;
121 EFI_DHCP4_CONFIG_DATA ActiveConfig
;
122 UINT32 UserOptionLen
;
125 // Timer event and various timer
129 UINT32 PacketToLive
; // Retransmission timer for our packets
130 UINT32 LastTimeout
; // Record the init value of PacketToLive every time
137 EFI_DHCP4_PACKET_OPTION
**Option
;
140 } DHCP_PARSE_CONTEXT
;
142 #define DHCP_INSTANCE_FROM_THIS(Proto) \
143 CR ((Proto), DHCP_PROTOCOL, Dhcp4Protocol, DHCP_PROTOCOL_SIGNATURE)
145 #define DHCP_SERVICE_FROM_THIS(Sb) \
146 CR ((Sb), DHCP_SERVICE, ServiceBinding, DHCP_SERVICE_SIGNATURE)
148 extern EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate
;
151 Give up the control of the DHCP service to let other child
152 resume. Don't change the service's DHCP state and the Client
153 address and option list configure as required by RFC2131.
155 @param DhcpSb The DHCP service instance.
160 IN DHCP_SERVICE
*DhcpSb
164 Complete a Dhcp4 transaction and signal the upper layer.
166 @param Instance Dhcp4 instance.
171 IN DHCP_PROTOCOL
*Instance
175 Free the resource related to the configure parameters.
176 DHCP driver will make a copy of the user's configure
177 such as the time out value.
179 @param Config The DHCP configure data
184 IN OUT EFI_DHCP4_CONFIG_DATA
*Config
188 Callback of Dhcp packet. Does nothing.
190 @param Arg The context.
200 Set the elapsed time based on the given instance and the pointer to the
203 @param[in] Elapsed The pointer to the position to append.
204 @param[in] Instance The pointer to the Dhcp4 instance.
209 IN DHCP_PROTOCOL
*Instance