]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Impl.h
CommitLineData
83cbd279 1/** @file\r
3e8c18da 2 EFI DHCP protocol implementation.\r
3 RFCs supported are:\r
4 RFC 2131: Dynamic Host Configuration Protocol\r
5 RFC 2132: DHCP Options and BOOTP Vendor Extensions\r
6 RFC 1534: Interoperation Between DHCP and BOOTP\r
7 RFC 3396: Encoding Long Options in DHCP.\r
d1102dba 8\r
479a3b60 9Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 10SPDX-License-Identifier: BSD-2-Clause-Patent\r
83cbd279 11\r
83cbd279 12**/\r
13\r
14#ifndef __EFI_DHCP4_IMPL_H__\r
15#define __EFI_DHCP4_IMPL_H__\r
16\r
17\r
772db4bb 18\r
2517435c 19#include <Uefi.h>\r
772db4bb 20\r
21#include <Protocol/Dhcp4.h>\r
22#include <Protocol/Udp4.h>\r
ac6c3d90 23#include <IndustryStandard/Dhcp.h>\r
772db4bb 24#include <Library/DebugLib.h>\r
25#include <Library/UefiDriverEntryPoint.h>\r
26#include <Library/UefiBootServicesTableLib.h>\r
27#include <Library/UefiLib.h>\r
83cbd279 28#include <Library/BaseLib.h>\r
29#include <Library/NetLib.h>\r
30\r
31typedef struct _DHCP_SERVICE DHCP_SERVICE;\r
32typedef struct _DHCP_PROTOCOL DHCP_PROTOCOL;\r
33\r
34#include "Dhcp4Option.h"\r
35#include "Dhcp4Io.h"\r
36\r
f3f2e05d 37#define DHCP_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', 'C', 'P')\r
38#define DHCP_PROTOCOL_SIGNATURE SIGNATURE_32 ('d', 'h', 'c', 'p')\r
83cbd279 39\r
8ce6b650 40#define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)\r
f6b7393c 41\r
42//\r
43// The state of the DHCP service. It starts as UNCONFIGED. If\r
44// and active child configures the service successfully, it\r
45// goes to CONFIGED. If the active child configures NULL, it\r
75dce340 46// goes back to UNCONFIGED. It becomes DESTROY if it is (partly)\r
47// destroyed.\r
f6b7393c 48//\r
49#define DHCP_UNCONFIGED 0\r
50#define DHCP_CONFIGED 1\r
75dce340 51#define DHCP_DESTROY 2\r
f6b7393c 52\r
83cbd279 53\r
54struct _DHCP_PROTOCOL {\r
55 UINT32 Signature;\r
56 EFI_DHCP4_PROTOCOL Dhcp4Protocol;\r
e48e37fc 57 LIST_ENTRY Link;\r
83cbd279 58 EFI_HANDLE Handle;\r
59 DHCP_SERVICE *Service;\r
60\r
75dce340 61 BOOLEAN InDestroy;\r
83cbd279 62\r
63 EFI_EVENT CompletionEvent;\r
64 EFI_EVENT RenewRebindEvent;\r
65\r
66 EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;\r
b45b45b2 67 UDP_IO *UdpIo; // The UDP IO used for TransmitReceive.\r
c4a62a12 68 UINT32 Timeout;\r
842d83d6 69 UINT16 ElaspedTime;\r
c4a62a12 70 NET_BUF_QUEUE ResponseQueue;\r
83cbd279 71};\r
72\r
73//\r
74// DHCP driver is specical in that it is a singleton. Although it\r
75// has a service binding, there can be only one active child.\r
76//\r
77struct _DHCP_SERVICE {\r
78 UINT32 Signature;\r
79 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
80\r
75dce340 81 INTN ServiceState; // CONFIGED, UNCONFIGED, and DESTROY\r
83cbd279 82\r
83 EFI_HANDLE Controller;\r
84 EFI_HANDLE Image;\r
85\r
e48e37fc 86 LIST_ENTRY Children;\r
83cbd279 87 UINTN NumChildren;\r
88\r
89 INTN DhcpState;\r
90 EFI_STATUS IoStatus; // the result of last user operation\r
91 UINT32 Xid;\r
92\r
93 IP4_ADDR ClientAddr; // lease IP or configured client address\r
94 IP4_ADDR Netmask;\r
95 IP4_ADDR ServerAddr;\r
96\r
97 EFI_DHCP4_PACKET *LastOffer; // The last received offer\r
98 EFI_DHCP4_PACKET *Selected;\r
99 DHCP_PARAMETER *Para;\r
100\r
101 UINT32 Lease;\r
102 UINT32 T1;\r
103 UINT32 T2;\r
104 INTN ExtraRefresh; // This refresh is reqested by user\r
105\r
b45b45b2 106 UDP_IO *UdpIo; // Udp child receiving all DHCP message\r
107 UDP_IO *LeaseIoPort; // Udp child with lease IP\r
434ce3fe 108 EFI_DHCP4_PACKET *LastPacket; // The last sent packet for retransmission\r
83cbd279 109 EFI_MAC_ADDRESS Mac;\r
110 UINT8 HwType;\r
111 UINT8 HwLen;\r
982a9eae 112 UINT8 ClientAddressSendOut[16];\r
83cbd279 113\r
114 DHCP_PROTOCOL *ActiveChild;\r
115 EFI_DHCP4_CONFIG_DATA ActiveConfig;\r
116 UINT32 UserOptionLen;\r
117\r
118 //\r
119 // Timer event and various timer\r
120 //\r
121 EFI_EVENT Timer;\r
122\r
123 UINT32 PacketToLive; // Retransmission timer for our packets\r
434ce3fe 124 UINT32 LastTimeout; // Record the init value of PacketToLive every time\r
83cbd279 125 INTN CurRetry;\r
126 INTN MaxRetries;\r
83cbd279 127 UINT32 LeaseLife;\r
128};\r
129\r
130typedef struct {\r
131 EFI_DHCP4_PACKET_OPTION **Option;\r
132 UINT32 OptionCount;\r
133 UINT32 Index;\r
134} DHCP_PARSE_CONTEXT;\r
135\r
136#define DHCP_INSTANCE_FROM_THIS(Proto) \\r
137 CR ((Proto), DHCP_PROTOCOL, Dhcp4Protocol, DHCP_PROTOCOL_SIGNATURE)\r
138\r
139#define DHCP_SERVICE_FROM_THIS(Sb) \\r
140 CR ((Sb), DHCP_SERVICE, ServiceBinding, DHCP_SERVICE_SIGNATURE)\r
141\r
142extern EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate;\r
143\r
7bce0c5a 144/**\r
145 Give up the control of the DHCP service to let other child\r
146 resume. Don't change the service's DHCP state and the Client\r
147 address and option list configure as required by RFC2131.\r
148\r
149 @param DhcpSb The DHCP service instance.\r
150\r
7bce0c5a 151**/\r
83cbd279 152VOID\r
153DhcpYieldControl (\r
ed729a0c 154 IN DHCP_SERVICE *DhcpSb\r
83cbd279 155 );\r
156\r
ed729a0c 157/**\r
158 Complete a Dhcp4 transaction and signal the upper layer.\r
235eaa63 159\r
ed729a0c 160 @param Instance Dhcp4 instance.\r
ed729a0c 161\r
162**/\r
c4a62a12 163VOID\r
164PxeDhcpDone (\r
165 IN DHCP_PROTOCOL *Instance\r
166 );\r
167\r
235eaa63 168/**\r
169 Free the resource related to the configure parameters.\r
170 DHCP driver will make a copy of the user's configure\r
171 such as the time out value.\r
172\r
173 @param Config The DHCP configure data\r
174\r
175**/\r
176VOID\r
177DhcpCleanConfigure (\r
178 IN OUT EFI_DHCP4_CONFIG_DATA *Config\r
179 );\r
180\r
479a3b60
WF
181/**\r
182 Callback of Dhcp packet. Does nothing.\r
183\r
184 @param Arg The context.\r
185\r
186**/\r
187VOID\r
188EFIAPI\r
189DhcpDummyExtFree (\r
190 IN VOID *Arg\r
191 );\r
192\r
842d83d6 193/**\r
194 Set the elapsed time based on the given instance and the pointer to the\r
195 elapsed time option.\r
196\r
197 @param[in] Elapsed The pointer to the position to append.\r
198 @param[in] Instance The pointer to the Dhcp4 instance.\r
199**/\r
200VOID\r
201SetElapsedTime (\r
202 IN UINT16 *Elapsed,\r
203 IN DHCP_PROTOCOL *Instance\r
204 );\r
205\r
83cbd279 206#endif\r