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