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