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