1 | /** @file
|
---|
2 | EFI DHCP protocol implementation.
|
---|
3 | RFCs supported are:
|
---|
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.
|
---|
8 |
|
---|
9 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
10 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
11 |
|
---|
12 | **/
|
---|
13 |
|
---|
14 | #ifndef __EFI_DHCP4_IMPL_H__
|
---|
15 | #define __EFI_DHCP4_IMPL_H__
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 | #include <Uefi.h>
|
---|
20 |
|
---|
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>
|
---|
30 |
|
---|
31 | typedef struct _DHCP_SERVICE DHCP_SERVICE;
|
---|
32 | typedef struct _DHCP_PROTOCOL DHCP_PROTOCOL;
|
---|
33 |
|
---|
34 | #include "Dhcp4Option.h"
|
---|
35 | #include "Dhcp4Io.h"
|
---|
36 |
|
---|
37 | #define DHCP_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', 'C', 'P')
|
---|
38 | #define DHCP_PROTOCOL_SIGNATURE SIGNATURE_32 ('d', 'h', 'c', 'p')
|
---|
39 |
|
---|
40 | #define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
|
---|
41 |
|
---|
42 | //
|
---|
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)
|
---|
47 | // destroyed.
|
---|
48 | //
|
---|
49 | #define DHCP_UNCONFIGED 0
|
---|
50 | #define DHCP_CONFIGED 1
|
---|
51 | #define DHCP_DESTROY 2
|
---|
52 |
|
---|
53 |
|
---|
54 | struct _DHCP_PROTOCOL {
|
---|
55 | UINT32 Signature;
|
---|
56 | EFI_DHCP4_PROTOCOL Dhcp4Protocol;
|
---|
57 | LIST_ENTRY Link;
|
---|
58 | EFI_HANDLE Handle;
|
---|
59 | DHCP_SERVICE *Service;
|
---|
60 |
|
---|
61 | BOOLEAN InDestroy;
|
---|
62 |
|
---|
63 | EFI_EVENT CompletionEvent;
|
---|
64 | EFI_EVENT RenewRebindEvent;
|
---|
65 |
|
---|
66 | EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;
|
---|
67 | UDP_IO *UdpIo; // The UDP IO used for TransmitReceive.
|
---|
68 | UINT32 Timeout;
|
---|
69 | UINT16 ElaspedTime;
|
---|
70 | NET_BUF_QUEUE ResponseQueue;
|
---|
71 | };
|
---|
72 |
|
---|
73 | //
|
---|
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.
|
---|
76 | //
|
---|
77 | struct _DHCP_SERVICE {
|
---|
78 | UINT32 Signature;
|
---|
79 | EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
|
---|
80 |
|
---|
81 | INTN ServiceState; // CONFIGED, UNCONFIGED, and DESTROY
|
---|
82 |
|
---|
83 | EFI_HANDLE Controller;
|
---|
84 | EFI_HANDLE Image;
|
---|
85 |
|
---|
86 | LIST_ENTRY Children;
|
---|
87 | UINTN NumChildren;
|
---|
88 |
|
---|
89 | INTN DhcpState;
|
---|
90 | EFI_STATUS IoStatus; // the result of last user operation
|
---|
91 | UINT32 Xid;
|
---|
92 |
|
---|
93 | IP4_ADDR ClientAddr; // lease IP or configured client address
|
---|
94 | IP4_ADDR Netmask;
|
---|
95 | IP4_ADDR ServerAddr;
|
---|
96 |
|
---|
97 | EFI_DHCP4_PACKET *LastOffer; // The last received offer
|
---|
98 | EFI_DHCP4_PACKET *Selected;
|
---|
99 | DHCP_PARAMETER *Para;
|
---|
100 |
|
---|
101 | UINT32 Lease;
|
---|
102 | UINT32 T1;
|
---|
103 | UINT32 T2;
|
---|
104 | INTN ExtraRefresh; // This refresh is reqested by user
|
---|
105 |
|
---|
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
|
---|
109 | EFI_MAC_ADDRESS Mac;
|
---|
110 | UINT8 HwType;
|
---|
111 | UINT8 HwLen;
|
---|
112 | UINT8 ClientAddressSendOut[16];
|
---|
113 |
|
---|
114 | DHCP_PROTOCOL *ActiveChild;
|
---|
115 | EFI_DHCP4_CONFIG_DATA ActiveConfig;
|
---|
116 | UINT32 UserOptionLen;
|
---|
117 |
|
---|
118 | //
|
---|
119 | // Timer event and various timer
|
---|
120 | //
|
---|
121 | EFI_EVENT Timer;
|
---|
122 |
|
---|
123 | UINT32 PacketToLive; // Retransmission timer for our packets
|
---|
124 | UINT32 LastTimeout; // Record the init value of PacketToLive every time
|
---|
125 | INTN CurRetry;
|
---|
126 | INTN MaxRetries;
|
---|
127 | UINT32 LeaseLife;
|
---|
128 | };
|
---|
129 |
|
---|
130 | typedef struct {
|
---|
131 | EFI_DHCP4_PACKET_OPTION **Option;
|
---|
132 | UINT32 OptionCount;
|
---|
133 | UINT32 Index;
|
---|
134 | } DHCP_PARSE_CONTEXT;
|
---|
135 |
|
---|
136 | #define DHCP_INSTANCE_FROM_THIS(Proto) \
|
---|
137 | CR ((Proto), DHCP_PROTOCOL, Dhcp4Protocol, DHCP_PROTOCOL_SIGNATURE)
|
---|
138 |
|
---|
139 | #define DHCP_SERVICE_FROM_THIS(Sb) \
|
---|
140 | CR ((Sb), DHCP_SERVICE, ServiceBinding, DHCP_SERVICE_SIGNATURE)
|
---|
141 |
|
---|
142 | extern EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate;
|
---|
143 |
|
---|
144 | /**
|
---|
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.
|
---|
148 |
|
---|
149 | @param DhcpSb The DHCP service instance.
|
---|
150 |
|
---|
151 | **/
|
---|
152 | VOID
|
---|
153 | DhcpYieldControl (
|
---|
154 | IN DHCP_SERVICE *DhcpSb
|
---|
155 | );
|
---|
156 |
|
---|
157 | /**
|
---|
158 | Complete a Dhcp4 transaction and signal the upper layer.
|
---|
159 |
|
---|
160 | @param Instance Dhcp4 instance.
|
---|
161 |
|
---|
162 | **/
|
---|
163 | VOID
|
---|
164 | PxeDhcpDone (
|
---|
165 | IN DHCP_PROTOCOL *Instance
|
---|
166 | );
|
---|
167 |
|
---|
168 | /**
|
---|
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.
|
---|
172 |
|
---|
173 | @param Config The DHCP configure data
|
---|
174 |
|
---|
175 | **/
|
---|
176 | VOID
|
---|
177 | DhcpCleanConfigure (
|
---|
178 | IN OUT EFI_DHCP4_CONFIG_DATA *Config
|
---|
179 | );
|
---|
180 |
|
---|
181 | /**
|
---|
182 | Callback of Dhcp packet. Does nothing.
|
---|
183 |
|
---|
184 | @param Arg The context.
|
---|
185 |
|
---|
186 | **/
|
---|
187 | VOID
|
---|
188 | EFIAPI
|
---|
189 | DhcpDummyExtFree (
|
---|
190 | IN VOID *Arg
|
---|
191 | );
|
---|
192 |
|
---|
193 | /**
|
---|
194 | Set the elapsed time based on the given instance and the pointer to the
|
---|
195 | elapsed time option.
|
---|
196 |
|
---|
197 | @param[in] Elapsed The pointer to the position to append.
|
---|
198 | @param[in] Instance The pointer to the Dhcp4 instance.
|
---|
199 | **/
|
---|
200 | VOID
|
---|
201 | SetElapsedTime (
|
---|
202 | IN UINT16 *Elapsed,
|
---|
203 | IN DHCP_PROTOCOL *Instance
|
---|
204 | );
|
---|
205 |
|
---|
206 | #endif
|
---|