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