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