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