]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.h
21bbf194bff216a0f9c047d3df4793b91d22d96e
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.h
1 /** @file
2
3 Copyright (c) 2006 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 Dhcp4Io.h
16
17 Abstract:
18
19 The DHCP4 protocol implementation.
20
21
22 **/
23
24 #ifndef __EFI_DHCP4_IO_H__
25 #define __EFI_DHCP4_IO_H__
26
27 #include <PiDxe.h>
28
29 #include <Protocol/ServiceBinding.h>
30
31 #include <Library/NetLib.h>
32 #include <Library/UdpIoLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/MemoryAllocationLib.h>
35
36
37
38 #define DHCP_WAIT_OFFER 3 // Time to wait the offers
39 #define DHCP_DEFAULT_LEASE 7 * 24 * 60 * 60 // Seven days as default.
40 #define DHCP_SERVER_PORT 67
41 #define DHCP_CLIENT_PORT 68
42
43 typedef enum {
44 //
45 // BOOTP header "op" field
46 //
47 BOOTP_REQUEST = 1,
48 BOOTP_REPLY = 2
49 } DHCP_OP_TYPE;
50
51 typedef enum {
52 //
53 // DHCP message types
54 //
55 DHCP_MSG_DISCOVER = 1,
56 DHCP_MSG_OFFER = 2,
57 DHCP_MSG_REQUEST = 3,
58 DHCP_MSG_DECLINE = 4,
59 DHCP_MSG_ACK = 5,
60 DHCP_MSG_NAK = 6,
61 DHCP_MSG_RELEASE = 7,
62 DHCP_MSG_INFORM = 8
63 } DHCP_MSG_TYPE;
64
65 typedef enum {
66 //
67 // DHCP notify user type
68 //
69 DHCP_NOTIFY_COMPLETION = 1,
70 DHCP_NOTIFY_RENEWREBIND,
71 DHCP_NOTIFY_ALL
72 } DHCP_NOTIFY_TYPE;
73
74 #define DHCP_IS_BOOTP(Parameter) (((Parameter) == NULL) || ((Parameter)->DhcpType == 0))
75
76 #define DHCP_CONNECTED(State) \
77 (((State) == Dhcp4Bound) || ((State) == (Dhcp4Renewing)) || ((State) == Dhcp4Rebinding))
78
79 /**
80 Set the DHCP state. If CallUser is true, it will try to notify
81 the user before change the state by DhcpNotifyUser. It returns
82 EFI_ABORTED if the user return EFI_ABORTED, otherwise, it returns
83 EFI_SUCCESS. If CallUser is FALSE, it isn't necessary to test
84 the return value of this function.
85
86 @param DhcpSb The DHCP service instance
87 @param State The new DHCP state to change to
88 @param CallUser Whether we need to call user
89
90 @retval EFI_SUCCESS The state is changed
91 @retval EFI_ABORTED The user asks to abort the DHCP process.
92
93 **/
94 EFI_STATUS
95 DhcpSetState (
96 IN OUT DHCP_SERVICE *DhcpSb,
97 IN INTN State,
98 IN BOOLEAN CallUser
99 );
100
101 /**
102 Build and transmit a DHCP message according to the current states.
103 This function implement the Table 5. of RFC 2131. Always transits
104 the state (as defined in Figure 5. of the same RFC) before sending
105 a DHCP message. The table is adjusted accordingly.
106
107 @param DhcpSb The DHCP service instance
108 @param Seed The seed packet which the new packet is based on
109 @param Para The DHCP parameter of the Seed packet
110 @param Type The message type to send
111 @param Msg The human readable message to include in the packet
112 sent.
113
114 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet
115 @retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP
116 @retval EFI_SUCCESS The message is sent
117 @retval other Other error occurs
118
119 **/
120 EFI_STATUS
121 DhcpSendMessage (
122 IN DHCP_SERVICE *DhcpSb,
123 IN EFI_DHCP4_PACKET *Seed,
124 IN DHCP_PARAMETER *Para,
125 IN UINT8 Type,
126 IN UINT8 *Msg
127 );
128
129 /**
130 Each DHCP service has three timer. Two of them are count down timer.
131 One for the packet retransmission. The other is to collect the offers.
132 The third timer increaments the lease life which is compared to T1, T2,
133 and lease to determine the time to renew and rebind the lease.
134 DhcpOnTimerTick will be called once every second.
135
136 @param Event The timer event
137 @param Context The context, which is the DHCP service instance.
138
139 @return None
140
141 **/
142 VOID
143 EFIAPI
144 DhcpOnTimerTick (
145 IN EFI_EVENT Event,
146 IN VOID *Context
147 );
148
149 /**
150 Handle the received DHCP packets. This function drives the DHCP
151 state machine.
152
153 @param UdpPacket The UDP packets received.
154 @param Points The local/remote UDP access points
155 @param IoStatus The status of the UDP receive
156 @param Context The opaque parameter to the function.
157
158 @return None
159
160 **/
161 VOID
162 DhcpInput (
163 NET_BUF *UdpPacket,
164 UDP_POINTS *Points,
165 EFI_STATUS IoStatus,
166 VOID *Context
167 );
168
169 /**
170 Send an initial DISCOVER or REQUEST message according to the
171 DHCP service's current state.
172
173 @param DhcpSb The DHCP service instance
174
175 @retval EFI_SUCCESS The request has been sent
176 @retval other Some error occurs when sending the request.
177
178 **/
179 EFI_STATUS
180 DhcpInitRequest (
181 IN DHCP_SERVICE *DhcpSb
182 );
183
184 /**
185 Clean up the DHCP related states, IoStatus isn't reset.
186
187 @param DhcpSb The DHCP instance service.
188
189 @return None
190
191 **/
192 VOID
193 DhcpCleanLease (
194 IN DHCP_SERVICE *DhcpSb
195 );
196
197 /**
198 Release the net buffer when packet is sent.
199
200 @param UdpPacket The UDP packets received.
201 @param Points The local/remote UDP access points
202 @param IoStatus The status of the UDP receive
203 @param Context The opaque parameter to the function.
204
205 @return None
206
207 **/
208 VOID
209 DhcpOnPacketSent (
210 NET_BUF *Packet,
211 UDP_POINTS *Points,
212 EFI_STATUS IoStatus,
213 VOID *Context
214 );
215
216 #endif