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