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