]>
Commit | Line | Data |
---|---|---|
772db4bb | 1 | /** @file\r |
3e8c18da | 2 | This file implement the EFI_DHCP4_PROTOCOL interface.\r |
e2851998 | 3 | \r |
8c5f78a2 | 4 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
772db4bb | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
772db4bb | 13 | **/\r |
14 | \r | |
15 | \r | |
16 | #include "Dhcp4Impl.h"\r | |
17 | \r | |
f9204641 | 18 | /**\r |
19 | Returns the current operating mode and cached data packet for the EFI DHCPv4 Protocol driver.\r | |
e2851998 | 20 | \r |
f9204641 | 21 | The GetModeData() function returns the current operating mode and cached data\r |
22 | packet for the EFI DHCPv4 Protocol driver.\r | |
23 | \r | |
3e8c18da | 24 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
25 | @param[out] Dhcp4ModeData Pointer to storage for the EFI_DHCP4_MODE_DATA structure.\r | |
f9204641 | 26 | \r |
27 | @retval EFI_SUCCESS The mode data was returned.\r | |
28 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
29 | \r | |
30 | **/\r | |
31 | EFI_STATUS\r | |
32 | EFIAPI\r | |
33 | EfiDhcp4GetModeData (\r | |
34 | IN EFI_DHCP4_PROTOCOL *This,\r | |
35 | OUT EFI_DHCP4_MODE_DATA *Dhcp4ModeData\r | |
36 | );\r | |
37 | \r | |
38 | /**\r | |
39 | Initializes, changes, or resets the operational settings for the EFI DHCPv4 Protocol driver.\r | |
40 | \r | |
41 | The Configure() function is used to initialize, change, or reset the operational\r | |
42 | settings of the EFI DHCPv4 Protocol driver for the communication device on which\r | |
43 | the EFI DHCPv4 Service Binding Protocol is installed. This function can be\r | |
44 | successfully called only if both of the following are true:\r | |
45 | * This instance of the EFI DHCPv4 Protocol driver is in the Dhcp4Stopped, Dhcp4Init,\r | |
46 | Dhcp4InitReboot, or Dhcp4Bound states.\r | |
47 | * No other EFI DHCPv4 Protocol driver instance that is controlled by this EFI\r | |
48 | DHCPv4 Service Binding Protocol driver instance has configured this EFI DHCPv4\r | |
49 | Protocol driver.\r | |
50 | When this driver is in the Dhcp4Stopped state, it can transfer into one of the\r | |
51 | following two possible initial states:\r | |
52 | * Dhcp4Init\r | |
53 | * Dhcp4InitReboot\r | |
54 | The driver can transfer into these states by calling Configure() with a non-NULL\r | |
55 | Dhcp4CfgData. The driver will transfer into the appropriate state based on the\r | |
56 | supplied client network address in the ClientAddress parameter and DHCP options\r | |
57 | in the OptionList parameter as described in RFC 2131.\r | |
58 | When Configure() is called successfully while Dhcp4CfgData is set to NULL, the\r | |
59 | default configuring data will be reset in the EFI DHCPv4 Protocol driver and\r | |
60 | the state of the EFI DHCPv4 Protocol driver will not be changed. If one instance\r | |
61 | wants to make it possible for another instance to configure the EFI DHCPv4 Protocol\r | |
62 | driver, it must call this function with Dhcp4CfgData set to NULL.\r | |
63 | \r | |
3e8c18da | 64 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
65 | @param[in] Dhcp4CfgData Pointer to the EFI_DHCP4_CONFIG_DATA.\r | |
f9204641 | 66 | \r |
67 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the Dhcp4Init or\r | |
68 | Dhcp4InitReboot state, if the original state of this driver\r | |
69 | was Dhcp4Stopped and the value of Dhcp4CfgData was\r | |
70 | not NULL. Otherwise, the state was left unchanged.\r | |
71 | @retval EFI_ACCESS_DENIED This instance of the EFI DHCPv4 Protocol driver was not in the\r | |
72 | Dhcp4Stopped, Dhcp4Init, Dhcp4InitReboot, or Dhcp4Bound state;\r | |
73 | Or onother instance of this EFI DHCPv4 Protocol driver is already\r | |
74 | in a valid configured state.\r | |
75 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
76 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
77 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
78 | \r | |
79 | **/\r | |
80 | EFI_STATUS\r | |
81 | EFIAPI\r | |
82 | EfiDhcp4Configure (\r | |
83 | IN EFI_DHCP4_PROTOCOL *This,\r | |
84 | IN EFI_DHCP4_CONFIG_DATA *Dhcp4CfgData OPTIONAL\r | |
e2851998 | 85 | );\r |
f9204641 | 86 | \r |
87 | /**\r | |
88 | Starts the DHCP configuration process.\r | |
89 | \r | |
90 | The Start() function starts the DHCP configuration process. This function can\r | |
91 | be called only when the EFI DHCPv4 Protocol driver is in the Dhcp4Init or\r | |
92 | Dhcp4InitReboot state.\r | |
93 | If the DHCP process completes successfully, the state of the EFI DHCPv4 Protocol\r | |
94 | driver will be transferred through Dhcp4Selecting and Dhcp4Requesting to the\r | |
95 | Dhcp4Bound state. The CompletionEvent will then be signaled if it is not NULL.\r | |
96 | If the process aborts, either by the user or by some unexpected network error,\r | |
97 | the state is restored to the Dhcp4Init state. The Start() function can be called\r | |
98 | again to restart the process.\r | |
99 | Refer to RFC 2131 for precise state transitions during this process. At the\r | |
100 | time when each event occurs in this process, the callback function that was set\r | |
101 | by EFI_DHCP4_PROTOCOL.Configure() will be called and the user can take this\r | |
102 | opportunity to control the process.\r | |
e2851998 | 103 | \r |
3e8c18da | 104 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
105 | @param[in] CompletionEvent If not NULL, indicates the event that will be signaled when the\r | |
106 | EFI DHCPv4 Protocol driver is transferred into the\r | |
107 | Dhcp4Bound state or when the DHCP process is aborted.\r | |
108 | EFI_DHCP4_PROTOCOL.GetModeData() can be called to\r | |
109 | check the completion status. If NULL,\r | |
110 | EFI_DHCP4_PROTOCOL.Start() will wait until the driver\r | |
111 | is transferred into the Dhcp4Bound state or the process fails.\r | |
f9204641 | 112 | \r |
113 | @retval EFI_SUCCESS The DHCP configuration process has started, or it has completed\r | |
114 | when CompletionEvent is NULL.\r | |
115 | @retval EFI_NOT_STARTED The EFI DHCPv4 Protocol driver is in the Dhcp4Stopped\r | |
116 | state. EFI_DHCP4_PROTOCOL. Configure() needs to be called.\r | |
117 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
118 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
119 | @retval EFI_TIMEOUT The DHCP configuration process failed because no response was\r | |
120 | received from the server within the specified timeout value.\r | |
121 | @retval EFI_ABORTED The user aborted the DHCP process.\r | |
122 | @retval EFI_ALREADY_STARTED Some other EFI DHCPv4 Protocol instance already started the\r | |
123 | DHCP process.\r | |
124 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
125 | \r | |
126 | **/\r | |
127 | EFI_STATUS\r | |
128 | EFIAPI\r | |
129 | EfiDhcp4Start (\r | |
130 | IN EFI_DHCP4_PROTOCOL *This,\r | |
131 | IN EFI_EVENT CompletionEvent OPTIONAL\r | |
132 | );\r | |
133 | \r | |
134 | /**\r | |
135 | Extends the lease time by sending a request packet.\r | |
e2851998 | 136 | \r |
f9204641 | 137 | The RenewRebind() function is used to manually extend the lease time when the\r |
138 | EFI DHCPv4 Protocol driver is in the Dhcp4Bound state and the lease time has\r | |
139 | not expired yet. This function will send a request packet to the previously\r | |
140 | found server (or to any server when RebindRequest is TRUE) and transfer the\r | |
141 | state into the Dhcp4Renewing state (or Dhcp4Rebinding when RebindingRequest is\r | |
142 | TRUE). When a response is received, the state is returned to Dhcp4Bound.\r | |
143 | If no response is received before the try count is exceeded (the RequestTryCount\r | |
144 | field that is specified in EFI_DHCP4_CONFIG_DATA) but before the lease time that\r | |
145 | was issued by the previous server expires, the driver will return to the Dhcp4Bound\r | |
146 | state and the previous configuration is restored. The outgoing and incoming packets\r | |
147 | can be captured by the EFI_DHCP4_CALLBACK function.\r | |
148 | \r | |
3e8c18da | 149 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
150 | @param[in] RebindRequest If TRUE, this function broadcasts the request packets and enters\r | |
151 | the Dhcp4Rebinding state. Otherwise, it sends a unicast\r | |
152 | request packet and enters the Dhcp4Renewing state.\r | |
153 | @param[in] CompletionEvent If not NULL, this event is signaled when the renew/rebind phase\r | |
154 | completes or some error occurs.\r | |
155 | EFI_DHCP4_PROTOCOL.GetModeData() can be called to\r | |
156 | check the completion status. If NULL,\r | |
157 | EFI_DHCP4_PROTOCOL.RenewRebind() will busy-wait\r | |
158 | until the DHCP process finishes.\r | |
f9204641 | 159 | \r |
160 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the\r | |
161 | Dhcp4Renewing state or is back to the Dhcp4Bound state.\r | |
162 | @retval EFI_NOT_STARTED The EFI DHCPv4 Protocol driver is in the Dhcp4Stopped\r | |
163 | state. EFI_DHCP4_PROTOCOL.Configure() needs to\r | |
164 | be called.\r | |
165 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
166 | @retval EFI_TIMEOUT There was no response from the server when the try count was\r | |
167 | exceeded.\r | |
168 | @retval EFI_ACCESS_DENIED The driver is not in the Dhcp4Bound state.\r | |
169 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
170 | \r | |
171 | **/\r | |
172 | EFI_STATUS\r | |
173 | EFIAPI\r | |
174 | EfiDhcp4RenewRebind (\r | |
175 | IN EFI_DHCP4_PROTOCOL *This,\r | |
176 | IN BOOLEAN RebindRequest,\r | |
177 | IN EFI_EVENT CompletionEvent OPTIONAL\r | |
178 | );\r | |
179 | \r | |
180 | /**\r | |
181 | Releases the current address configuration.\r | |
182 | \r | |
183 | The Release() function releases the current configured IP address by doing either\r | |
184 | of the following:\r | |
185 | * Sending a DHCPRELEASE packet when the EFI DHCPv4 Protocol driver is in the\r | |
186 | Dhcp4Bound state\r | |
187 | * Setting the previously assigned IP address that was provided with the\r | |
188 | EFI_DHCP4_PROTOCOL.Configure() function to 0.0.0.0 when the driver is in\r | |
189 | Dhcp4InitReboot state\r | |
190 | After a successful call to this function, the EFI DHCPv4 Protocol driver returns\r | |
191 | to the Dhcp4Init state and any subsequent incoming packets will be discarded silently.\r | |
192 | \r | |
3e8c18da | 193 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
f9204641 | 194 | \r |
195 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the Dhcp4Init phase.\r | |
196 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
197 | @retval EFI_ACCESS_DENIED The EFI DHCPv4 Protocol driver is not Dhcp4InitReboot state.\r | |
198 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
199 | \r | |
200 | **/\r | |
201 | EFI_STATUS\r | |
202 | EFIAPI\r | |
203 | EfiDhcp4Release (\r | |
204 | IN EFI_DHCP4_PROTOCOL *This\r | |
205 | );\r | |
206 | \r | |
207 | /**\r | |
208 | Stops the current address configuration.\r | |
e2851998 | 209 | \r |
f9204641 | 210 | The Stop() function is used to stop the DHCP configuration process. After this\r |
211 | function is called successfully, the EFI DHCPv4 Protocol driver is transferred\r | |
212 | into the Dhcp4Stopped state. EFI_DHCP4_PROTOCOL.Configure() needs to be called\r | |
213 | before DHCP configuration process can be started again. This function can be\r | |
214 | called when the EFI DHCPv4 Protocol driver is in any state.\r | |
215 | \r | |
3e8c18da | 216 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
f9204641 | 217 | \r |
218 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the Dhcp4Stopped phase.\r | |
219 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
220 | \r | |
221 | **/\r | |
222 | EFI_STATUS\r | |
223 | EFIAPI\r | |
224 | EfiDhcp4Stop (\r | |
225 | IN EFI_DHCP4_PROTOCOL *This\r | |
226 | );\r | |
227 | \r | |
228 | /**\r | |
229 | Builds a DHCP packet, given the options to be appended or deleted or replaced.\r | |
230 | \r | |
231 | The Build() function is used to assemble a new packet from the original packet\r | |
232 | by replacing or deleting existing options or appending new options. This function\r | |
233 | does not change any state of the EFI DHCPv4 Protocol driver and can be used at\r | |
234 | any time.\r | |
235 | \r | |
3e8c18da | 236 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
237 | @param[in] SeedPacket Initial packet to be used as a base for building new packet.\r | |
238 | @param[in] DeleteCount Number of opcodes in the DeleteList.\r | |
239 | @param[in] DeleteList List of opcodes to be deleted from the seed packet.\r | |
240 | Ignored if DeleteCount is zero.\r | |
241 | @param[in] AppendCount Number of entries in the OptionList.\r | |
242 | @param[in] AppendList Pointer to a DHCP option list to be appended to SeedPacket.\r | |
243 | If SeedPacket also contains options in this list, they are\r | |
244 | replaced by new options (except pad option). Ignored if\r | |
245 | AppendCount is zero. Type EFI_DHCP4_PACKET_OPTION\r | |
246 | @param[out] NewPacket Pointer to storage for the pointer to the new allocated packet.\r | |
247 | Use the EFI Boot Service FreePool() on the resulting pointer\r | |
248 | when done with the packet.\r | |
f9204641 | 249 | \r |
250 | @retval EFI_SUCCESS The new packet was built.\r | |
251 | @retval EFI_OUT_OF_RESOURCES Storage for the new packet could not be allocated.\r | |
252 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
253 | \r | |
254 | **/\r | |
255 | EFI_STATUS\r | |
256 | EFIAPI\r | |
257 | EfiDhcp4Build (\r | |
258 | IN EFI_DHCP4_PROTOCOL *This,\r | |
259 | IN EFI_DHCP4_PACKET *SeedPacket,\r | |
260 | IN UINT32 DeleteCount,\r | |
261 | IN UINT8 *DeleteList OPTIONAL,\r | |
262 | IN UINT32 AppendCount,\r | |
263 | IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL,\r | |
264 | OUT EFI_DHCP4_PACKET **NewPacket\r | |
265 | );\r | |
e2851998 | 266 | \r |
3e8c18da | 267 | /**\r |
f9204641 | 268 | Transmits a DHCP formatted packet and optionally waits for responses.\r |
e2851998 | 269 | \r |
f9204641 | 270 | The TransmitReceive() function is used to transmit a DHCP packet and optionally\r |
271 | wait for the response from servers. This function does not change the state of\r | |
272 | the EFI DHCPv4 Protocol driver and thus can be used at any time.\r | |
273 | \r | |
3e8c18da | 274 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
275 | @param[in] Token Pointer to the EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN structure.\r | |
f9204641 | 276 | \r |
277 | @retval EFI_SUCCESS The packet was successfully queued for transmission.\r | |
278 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
279 | @retval EFI_NOT_READY The previous call to this function has not finished yet. Try to call\r | |
280 | this function after collection process completes.\r | |
281 | @retval EFI_NO_MAPPING The default station address is not available yet.\r | |
282 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
283 | @retval Others Some other unexpected error occurred.\r | |
284 | \r | |
285 | **/\r | |
286 | EFI_STATUS\r | |
287 | EFIAPI\r | |
288 | EfiDhcp4TransmitReceive (\r | |
289 | IN EFI_DHCP4_PROTOCOL *This,\r | |
290 | IN EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token\r | |
291 | );\r | |
292 | \r | |
293 | /**\r | |
294 | Parses the packed DHCP option data.\r | |
e2851998 | 295 | \r |
f9204641 | 296 | The Parse() function is used to retrieve the option list from a DHCP packet.\r |
51195fbe | 297 | If *OptionCount isn't zero, and there is enough space for all the DHCP options\r |
f9204641 | 298 | in the Packet, each element of PacketOptionList is set to point to somewhere in\r |
299 | the Packet->Dhcp4.Option where a new DHCP option begins. If RFC3396 is supported,\r | |
300 | the caller should reassemble the parsed DHCP options to get the finial result.\r | |
51195fbe | 301 | If *OptionCount is zero or there isn't enough space for all of them, the number\r |
f9204641 | 302 | of DHCP options in the Packet is returned in OptionCount.\r |
303 | \r | |
304 | @param This Pointer to the EFI_DHCP4_PROTOCOL instance.\r | |
305 | @param Packet Pointer to packet to be parsed.\r | |
306 | @param OptionCount On input, the number of entries in the PacketOptionList.\r | |
307 | On output, the number of entries that were written into the\r | |
308 | PacketOptionList.\r | |
309 | @param PacketOptionList List of packet option entries to be filled in. End option or pad\r | |
310 | options are not included.\r | |
311 | \r | |
312 | @retval EFI_SUCCESS The packet was successfully parsed.\r | |
313 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
314 | @retval EFI_BUFFER_TOO_SMALL One or more of the following conditions is TRUE:\r | |
315 | 1) *OptionCount is smaller than the number of options that\r | |
316 | were found in the Packet.\r | |
317 | 2) PacketOptionList is NULL.\r | |
318 | \r | |
319 | **/\r | |
320 | EFI_STATUS\r | |
321 | EFIAPI\r | |
322 | EfiDhcp4Parse (\r | |
323 | IN EFI_DHCP4_PROTOCOL *This,\r | |
324 | IN EFI_DHCP4_PACKET *Packet,\r | |
325 | IN OUT UINT32 *OptionCount,\r | |
326 | OUT EFI_DHCP4_PACKET_OPTION *PacketOptionList[] OPTIONAL\r | |
327 | );\r | |
328 | \r | |
329 | EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate = {\r | |
330 | EfiDhcp4GetModeData,\r | |
331 | EfiDhcp4Configure,\r | |
332 | EfiDhcp4Start,\r | |
333 | EfiDhcp4RenewRebind,\r | |
334 | EfiDhcp4Release,\r | |
335 | EfiDhcp4Stop,\r | |
336 | EfiDhcp4Build,\r | |
337 | EfiDhcp4TransmitReceive,\r | |
338 | EfiDhcp4Parse\r | |
339 | };\r | |
772db4bb | 340 | \r |
341 | /**\r | |
f9204641 | 342 | Returns the current operating mode and cached data packet for the EFI DHCPv4 Protocol driver.\r |
e2851998 | 343 | \r |
f9204641 | 344 | The GetModeData() function returns the current operating mode and cached data\r |
345 | packet for the EFI DHCPv4 Protocol driver.\r | |
772db4bb | 346 | \r |
3e8c18da | 347 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
348 | @param[out] Dhcp4ModeData Pointer to storage for the EFI_DHCP4_MODE_DATA structure.\r | |
772db4bb | 349 | \r |
f9204641 | 350 | @retval EFI_SUCCESS The mode data was returned.\r |
351 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
772db4bb | 352 | \r |
353 | **/\r | |
772db4bb | 354 | EFI_STATUS\r |
355 | EFIAPI\r | |
356 | EfiDhcp4GetModeData (\r | |
357 | IN EFI_DHCP4_PROTOCOL *This,\r | |
358 | OUT EFI_DHCP4_MODE_DATA *Dhcp4ModeData\r | |
359 | )\r | |
360 | {\r | |
361 | DHCP_PROTOCOL *Instance;\r | |
362 | DHCP_SERVICE *DhcpSb;\r | |
363 | DHCP_PARAMETER *Para;\r | |
364 | EFI_TPL OldTpl;\r | |
365 | IP4_ADDR Ip;\r | |
366 | \r | |
367 | //\r | |
368 | // First validate the parameters.\r | |
369 | //\r | |
370 | if ((This == NULL) || (Dhcp4ModeData == NULL)) {\r | |
371 | return EFI_INVALID_PARAMETER;\r | |
372 | }\r | |
373 | \r | |
374 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
982a9eae | 375 | \r |
e48e37fc | 376 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 377 | DhcpSb = Instance->Service;\r |
378 | \r | |
379 | //\r | |
380 | // Caller can use GetModeData to retrieve current DHCP states\r | |
381 | // no matter whether it is the active child or not.\r | |
382 | //\r | |
f9204641 | 383 | Dhcp4ModeData->State = (EFI_DHCP4_STATE) DhcpSb->DhcpState;\r |
687a2e5f | 384 | CopyMem (&Dhcp4ModeData->ConfigData, &DhcpSb->ActiveConfig, sizeof (Dhcp4ModeData->ConfigData));\r |
385 | CopyMem (&Dhcp4ModeData->ClientMacAddress, &DhcpSb->Mac, sizeof (Dhcp4ModeData->ClientMacAddress));\r | |
772db4bb | 386 | \r |
387 | Ip = HTONL (DhcpSb->ClientAddr);\r | |
e48e37fc | 388 | CopyMem (&Dhcp4ModeData->ClientAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
772db4bb | 389 | \r |
390 | Ip = HTONL (DhcpSb->Netmask);\r | |
e48e37fc | 391 | CopyMem (&Dhcp4ModeData->SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
772db4bb | 392 | \r |
393 | Ip = HTONL (DhcpSb->ServerAddr);\r | |
e48e37fc | 394 | CopyMem (&Dhcp4ModeData->ServerAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
772db4bb | 395 | \r |
396 | Para = DhcpSb->Para;\r | |
397 | \r | |
398 | if (Para != NULL) {\r | |
399 | Ip = HTONL (Para->Router);\r | |
e48e37fc | 400 | CopyMem (&Dhcp4ModeData->RouterAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
f9204641 | 401 | Dhcp4ModeData->LeaseTime = Para->Lease;\r |
772db4bb | 402 | } else {\r |
e48e37fc | 403 | ZeroMem (&Dhcp4ModeData->RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r |
f9204641 | 404 | Dhcp4ModeData->LeaseTime = 0xffffffff;\r |
772db4bb | 405 | }\r |
406 | \r | |
407 | Dhcp4ModeData->ReplyPacket = DhcpSb->Selected;\r | |
408 | \r | |
e48e37fc | 409 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 410 | return EFI_SUCCESS;\r |
411 | }\r | |
412 | \r | |
413 | \r | |
414 | /**\r | |
415 | Free the resource related to the configure parameters.\r | |
416 | DHCP driver will make a copy of the user's configure\r | |
417 | such as the time out value.\r | |
418 | \r | |
419 | @param Config The DHCP configure data\r | |
420 | \r | |
772db4bb | 421 | **/\r |
422 | VOID\r | |
423 | DhcpCleanConfigure (\r | |
f9204641 | 424 | IN OUT EFI_DHCP4_CONFIG_DATA *Config\r |
772db4bb | 425 | )\r |
426 | {\r | |
427 | UINT32 Index;\r | |
428 | \r | |
429 | if (Config->DiscoverTimeout != NULL) {\r | |
a4df47f1 | 430 | FreePool (Config->DiscoverTimeout);\r |
772db4bb | 431 | }\r |
432 | \r | |
433 | if (Config->RequestTimeout != NULL) {\r | |
a4df47f1 | 434 | FreePool (Config->RequestTimeout);\r |
772db4bb | 435 | }\r |
436 | \r | |
437 | if (Config->OptionList != NULL) {\r | |
438 | for (Index = 0; Index < Config->OptionCount; Index++) {\r | |
439 | if (Config->OptionList[Index] != NULL) {\r | |
a4df47f1 | 440 | FreePool (Config->OptionList[Index]);\r |
772db4bb | 441 | }\r |
442 | }\r | |
443 | \r | |
a4df47f1 | 444 | FreePool (Config->OptionList);\r |
772db4bb | 445 | }\r |
446 | \r | |
e48e37fc | 447 | ZeroMem (Config, sizeof (EFI_DHCP4_CONFIG_DATA));\r |
772db4bb | 448 | }\r |
449 | \r | |
450 | \r | |
451 | /**\r | |
452 | Allocate memory for configure parameter such as timeout value for Dst,\r | |
453 | then copy the configure parameter from Src to Dst.\r | |
454 | \r | |
3e8c18da | 455 | @param[out] Dst The destination DHCP configure data.\r |
456 | @param[in] Src The source DHCP configure data.\r | |
772db4bb | 457 | \r |
458 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r | |
459 | @retval EFI_SUCCESS The configure is copied.\r | |
460 | \r | |
461 | **/\r | |
462 | EFI_STATUS\r | |
463 | DhcpCopyConfigure (\r | |
f9204641 | 464 | OUT EFI_DHCP4_CONFIG_DATA *Dst,\r |
465 | IN EFI_DHCP4_CONFIG_DATA *Src\r | |
772db4bb | 466 | )\r |
467 | {\r | |
468 | EFI_DHCP4_PACKET_OPTION **DstOptions;\r | |
469 | EFI_DHCP4_PACKET_OPTION **SrcOptions;\r | |
cd7bfc2c | 470 | UINTN Len;\r |
772db4bb | 471 | UINT32 Index;\r |
472 | \r | |
72030458 | 473 | CopyMem (Dst, Src, sizeof (*Dst));\r |
772db4bb | 474 | Dst->DiscoverTimeout = NULL;\r |
475 | Dst->RequestTimeout = NULL;\r | |
476 | Dst->OptionList = NULL;\r | |
477 | \r | |
478 | //\r | |
479 | // Allocate a memory then copy DiscoverTimeout to it\r | |
480 | //\r | |
481 | if (Src->DiscoverTimeout != NULL) {\r | |
482 | Len = Src->DiscoverTryCount * sizeof (UINT32);\r | |
e48e37fc | 483 | Dst->DiscoverTimeout = AllocatePool (Len);\r |
772db4bb | 484 | \r |
485 | if (Dst->DiscoverTimeout == NULL) {\r | |
486 | return EFI_OUT_OF_RESOURCES;\r | |
487 | }\r | |
488 | \r | |
489 | for (Index = 0; Index < Src->DiscoverTryCount; Index++) {\r | |
36ee91ca | 490 | Dst->DiscoverTimeout[Index] = MAX (Src->DiscoverTimeout[Index], 1);\r |
772db4bb | 491 | }\r |
492 | }\r | |
493 | \r | |
494 | //\r | |
495 | // Allocate a memory then copy RequestTimeout to it\r | |
496 | //\r | |
497 | if (Src->RequestTimeout != NULL) {\r | |
498 | Len = Src->RequestTryCount * sizeof (UINT32);\r | |
e48e37fc | 499 | Dst->RequestTimeout = AllocatePool (Len);\r |
772db4bb | 500 | \r |
501 | if (Dst->RequestTimeout == NULL) {\r | |
502 | goto ON_ERROR;\r | |
503 | }\r | |
504 | \r | |
505 | for (Index = 0; Index < Src->RequestTryCount; Index++) {\r | |
36ee91ca | 506 | Dst->RequestTimeout[Index] = MAX (Src->RequestTimeout[Index], 1);\r |
772db4bb | 507 | }\r |
508 | }\r | |
509 | \r | |
510 | //\r | |
511 | // Allocate an array of dhcp option point, then allocate memory\r | |
512 | // for each option and copy the source option to it\r | |
513 | //\r | |
514 | if (Src->OptionList != NULL) {\r | |
515 | Len = Src->OptionCount * sizeof (EFI_DHCP4_PACKET_OPTION *);\r | |
e48e37fc | 516 | Dst->OptionList = AllocateZeroPool (Len);\r |
772db4bb | 517 | \r |
518 | if (Dst->OptionList == NULL) {\r | |
519 | goto ON_ERROR;\r | |
520 | }\r | |
521 | \r | |
522 | DstOptions = Dst->OptionList;\r | |
523 | SrcOptions = Src->OptionList;\r | |
524 | \r | |
525 | for (Index = 0; Index < Src->OptionCount; Index++) {\r | |
36ee91ca | 526 | Len = sizeof (EFI_DHCP4_PACKET_OPTION) + MAX (SrcOptions[Index]->Length - 1, 0);\r |
772db4bb | 527 | \r |
e48e37fc | 528 | DstOptions[Index] = AllocatePool (Len);\r |
772db4bb | 529 | \r |
530 | if (DstOptions[Index] == NULL) {\r | |
531 | goto ON_ERROR;\r | |
532 | }\r | |
533 | \r | |
e48e37fc | 534 | CopyMem (DstOptions[Index], SrcOptions[Index], Len);\r |
772db4bb | 535 | }\r |
536 | }\r | |
537 | \r | |
538 | return EFI_SUCCESS;\r | |
539 | \r | |
540 | ON_ERROR:\r | |
541 | DhcpCleanConfigure (Dst);\r | |
542 | return EFI_OUT_OF_RESOURCES;\r | |
543 | }\r | |
544 | \r | |
545 | \r | |
546 | /**\r | |
547 | Give up the control of the DHCP service to let other child\r | |
548 | resume. Don't change the service's DHCP state and the Client\r | |
549 | address and option list configure as required by RFC2131.\r | |
550 | \r | |
551 | @param DhcpSb The DHCP service instance.\r | |
552 | \r | |
772db4bb | 553 | **/\r |
554 | VOID\r | |
555 | DhcpYieldControl (\r | |
556 | IN DHCP_SERVICE *DhcpSb\r | |
557 | )\r | |
558 | {\r | |
559 | EFI_DHCP4_CONFIG_DATA *Config;\r | |
772db4bb | 560 | \r |
772db4bb | 561 | Config = &DhcpSb->ActiveConfig;\r |
562 | \r | |
563 | DhcpSb->ServiceState = DHCP_UNCONFIGED;\r | |
564 | DhcpSb->ActiveChild = NULL;\r | |
565 | \r | |
566 | if (Config->DiscoverTimeout != NULL) {\r | |
a4df47f1 | 567 | FreePool (Config->DiscoverTimeout);\r |
772db4bb | 568 | \r |
569 | Config->DiscoverTryCount = 0;\r | |
570 | Config->DiscoverTimeout = NULL;\r | |
571 | }\r | |
572 | \r | |
573 | if (Config->RequestTimeout != NULL) {\r | |
a4df47f1 | 574 | FreePool (Config->RequestTimeout);\r |
772db4bb | 575 | \r |
576 | Config->RequestTryCount = 0;\r | |
577 | Config->RequestTimeout = NULL;\r | |
578 | }\r | |
579 | \r | |
580 | Config->Dhcp4Callback = NULL;\r | |
581 | Config->CallbackContext = NULL;\r | |
582 | }\r | |
583 | \r | |
584 | \r | |
585 | /**\r | |
f9204641 | 586 | Initializes, changes, or resets the operational settings for the EFI DHCPv4 Protocol driver.\r |
587 | \r | |
588 | The Configure() function is used to initialize, change, or reset the operational\r | |
589 | settings of the EFI DHCPv4 Protocol driver for the communication device on which\r | |
590 | the EFI DHCPv4 Service Binding Protocol is installed. This function can be\r | |
591 | successfully called only if both of the following are true:\r | |
592 | * This instance of the EFI DHCPv4 Protocol driver is in the Dhcp4Stopped, Dhcp4Init,\r | |
593 | Dhcp4InitReboot, or Dhcp4Bound states.\r | |
594 | * No other EFI DHCPv4 Protocol driver instance that is controlled by this EFI\r | |
595 | DHCPv4 Service Binding Protocol driver instance has configured this EFI DHCPv4\r | |
596 | Protocol driver.\r | |
597 | When this driver is in the Dhcp4Stopped state, it can transfer into one of the\r | |
598 | following two possible initial states:\r | |
599 | * Dhcp4Init\r | |
600 | * Dhcp4InitReboot\r | |
601 | The driver can transfer into these states by calling Configure() with a non-NULL\r | |
602 | Dhcp4CfgData. The driver will transfer into the appropriate state based on the\r | |
603 | supplied client network address in the ClientAddress parameter and DHCP options\r | |
604 | in the OptionList parameter as described in RFC 2131.\r | |
605 | When Configure() is called successfully while Dhcp4CfgData is set to NULL, the\r | |
606 | default configuring data will be reset in the EFI DHCPv4 Protocol driver and\r | |
607 | the state of the EFI DHCPv4 Protocol driver will not be changed. If one instance\r | |
608 | wants to make it possible for another instance to configure the EFI DHCPv4 Protocol\r | |
609 | driver, it must call this function with Dhcp4CfgData set to NULL.\r | |
610 | \r | |
3e8c18da | 611 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
612 | @param[in] Dhcp4CfgData Pointer to the EFI_DHCP4_CONFIG_DATA.\r | |
f9204641 | 613 | \r |
614 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the Dhcp4Init or\r | |
615 | Dhcp4InitReboot state, if the original state of this driver\r | |
616 | was Dhcp4Stopped and the value of Dhcp4CfgData was\r | |
617 | not NULL. Otherwise, the state was left unchanged.\r | |
618 | @retval EFI_ACCESS_DENIED This instance of the EFI DHCPv4 Protocol driver was not in the\r | |
619 | Dhcp4Stopped, Dhcp4Init, Dhcp4InitReboot, or Dhcp4Bound state;\r | |
620 | Or onother instance of this EFI DHCPv4 Protocol driver is already\r | |
621 | in a valid configured state.\r | |
622 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
623 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
624 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
772db4bb | 625 | \r |
626 | **/\r | |
772db4bb | 627 | EFI_STATUS\r |
628 | EFIAPI\r | |
629 | EfiDhcp4Configure (\r | |
630 | IN EFI_DHCP4_PROTOCOL *This,\r | |
631 | IN EFI_DHCP4_CONFIG_DATA *Dhcp4CfgData OPTIONAL\r | |
632 | )\r | |
633 | {\r | |
634 | EFI_DHCP4_CONFIG_DATA *Config;\r | |
635 | DHCP_PROTOCOL *Instance;\r | |
636 | DHCP_SERVICE *DhcpSb;\r | |
637 | EFI_STATUS Status;\r | |
638 | EFI_TPL OldTpl;\r | |
639 | UINT32 Index;\r | |
640 | IP4_ADDR Ip;\r | |
641 | \r | |
642 | //\r | |
643 | // First validate the parameters\r | |
644 | //\r | |
645 | if (This == NULL) {\r | |
646 | return EFI_INVALID_PARAMETER;\r | |
647 | }\r | |
648 | \r | |
649 | if (Dhcp4CfgData != NULL) {\r | |
e2851998 | 650 | if ((Dhcp4CfgData->DiscoverTryCount != 0) && (Dhcp4CfgData->DiscoverTimeout == NULL)) {\r |
772db4bb | 651 | return EFI_INVALID_PARAMETER;\r |
652 | }\r | |
653 | \r | |
e2851998 | 654 | if ((Dhcp4CfgData->RequestTryCount != 0) && (Dhcp4CfgData->RequestTimeout == NULL)) {\r |
772db4bb | 655 | return EFI_INVALID_PARAMETER;\r |
656 | }\r | |
657 | \r | |
e2851998 | 658 | if ((Dhcp4CfgData->OptionCount != 0) && (Dhcp4CfgData->OptionList == NULL)) {\r |
772db4bb | 659 | return EFI_INVALID_PARAMETER;\r |
660 | }\r | |
661 | \r | |
e48e37fc | 662 | CopyMem (&Ip, &Dhcp4CfgData->ClientAddress, sizeof (IP4_ADDR));\r |
772db4bb | 663 | \r |
f6b7393c | 664 | if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {\r |
772db4bb | 665 | \r |
666 | return EFI_INVALID_PARAMETER;\r | |
667 | }\r | |
668 | }\r | |
669 | \r | |
670 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
671 | \r | |
672 | if (Instance->Signature != DHCP_PROTOCOL_SIGNATURE) {\r | |
673 | return EFI_INVALID_PARAMETER;\r | |
674 | }\r | |
675 | \r | |
e48e37fc | 676 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 677 | \r |
678 | DhcpSb = Instance->Service;\r | |
679 | Config = &DhcpSb->ActiveConfig;\r | |
680 | \r | |
681 | Status = EFI_ACCESS_DENIED;\r | |
682 | \r | |
683 | if ((DhcpSb->DhcpState != Dhcp4Stopped) &&\r | |
684 | (DhcpSb->DhcpState != Dhcp4Init) &&\r | |
685 | (DhcpSb->DhcpState != Dhcp4InitReboot) &&\r | |
686 | (DhcpSb->DhcpState != Dhcp4Bound)) {\r | |
687 | \r | |
688 | goto ON_EXIT;\r | |
689 | }\r | |
690 | \r | |
691 | if ((DhcpSb->ActiveChild != NULL) && (DhcpSb->ActiveChild != Instance)) {\r | |
692 | goto ON_EXIT;\r | |
693 | }\r | |
694 | \r | |
695 | if (Dhcp4CfgData != NULL) {\r | |
696 | Status = EFI_OUT_OF_RESOURCES;\r | |
697 | DhcpCleanConfigure (Config);\r | |
698 | \r | |
699 | if (EFI_ERROR (DhcpCopyConfigure (Config, Dhcp4CfgData))) {\r | |
700 | goto ON_EXIT;\r | |
701 | }\r | |
702 | \r | |
703 | DhcpSb->UserOptionLen = 0;\r | |
704 | \r | |
705 | for (Index = 0; Index < Dhcp4CfgData->OptionCount; Index++) {\r | |
706 | DhcpSb->UserOptionLen += Dhcp4CfgData->OptionList[Index]->Length + 2;\r | |
707 | }\r | |
708 | \r | |
709 | DhcpSb->ActiveChild = Instance;\r | |
710 | \r | |
711 | if (DhcpSb->DhcpState == Dhcp4Stopped) {\r | |
712 | DhcpSb->ClientAddr = EFI_NTOHL (Dhcp4CfgData->ClientAddress);\r | |
713 | \r | |
714 | if (DhcpSb->ClientAddr != 0) {\r | |
715 | DhcpSb->DhcpState = Dhcp4InitReboot;\r | |
716 | } else {\r | |
717 | DhcpSb->DhcpState = Dhcp4Init;\r | |
718 | }\r | |
719 | }\r | |
720 | \r | |
721 | DhcpSb->ServiceState = DHCP_CONFIGED;\r | |
722 | Status = EFI_SUCCESS;\r | |
723 | \r | |
724 | } else if (DhcpSb->ActiveChild == Instance) {\r | |
725 | Status = EFI_SUCCESS;\r | |
726 | DhcpYieldControl (DhcpSb);\r | |
727 | }\r | |
728 | \r | |
729 | ON_EXIT:\r | |
e48e37fc | 730 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 731 | return Status;\r |
732 | }\r | |
733 | \r | |
734 | \r | |
735 | /**\r | |
f9204641 | 736 | Starts the DHCP configuration process.\r |
737 | \r | |
738 | The Start() function starts the DHCP configuration process. This function can\r | |
739 | be called only when the EFI DHCPv4 Protocol driver is in the Dhcp4Init or\r | |
740 | Dhcp4InitReboot state.\r | |
741 | If the DHCP process completes successfully, the state of the EFI DHCPv4 Protocol\r | |
742 | driver will be transferred through Dhcp4Selecting and Dhcp4Requesting to the\r | |
743 | Dhcp4Bound state. The CompletionEvent will then be signaled if it is not NULL.\r | |
744 | If the process aborts, either by the user or by some unexpected network error,\r | |
745 | the state is restored to the Dhcp4Init state. The Start() function can be called\r | |
746 | again to restart the process.\r | |
747 | Refer to RFC 2131 for precise state transitions during this process. At the\r | |
748 | time when each event occurs in this process, the callback function that was set\r | |
749 | by EFI_DHCP4_PROTOCOL.Configure() will be called and the user can take this\r | |
750 | opportunity to control the process.\r | |
e2851998 | 751 | \r |
3e8c18da | 752 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
753 | @param[in] CompletionEvent If not NULL, indicates the event that will be signaled when the\r | |
754 | EFI DHCPv4 Protocol driver is transferred into the\r | |
755 | Dhcp4Bound state or when the DHCP process is aborted.\r | |
756 | EFI_DHCP4_PROTOCOL.GetModeData() can be called to\r | |
757 | check the completion status. If NULL,\r | |
758 | EFI_DHCP4_PROTOCOL.Start() will wait until the driver\r | |
759 | is transferred into the Dhcp4Bound state or the process fails.\r | |
f9204641 | 760 | \r |
761 | @retval EFI_SUCCESS The DHCP configuration process has started, or it has completed\r | |
762 | when CompletionEvent is NULL.\r | |
763 | @retval EFI_NOT_STARTED The EFI DHCPv4 Protocol driver is in the Dhcp4Stopped\r | |
764 | state. EFI_DHCP4_PROTOCOL. Configure() needs to be called.\r | |
765 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
766 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
767 | @retval EFI_TIMEOUT The DHCP configuration process failed because no response was\r | |
768 | received from the server within the specified timeout value.\r | |
769 | @retval EFI_ABORTED The user aborted the DHCP process.\r | |
770 | @retval EFI_ALREADY_STARTED Some other EFI DHCPv4 Protocol instance already started the\r | |
771 | DHCP process.\r | |
772 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
dd29f3ed | 773 | @retval EFI_NO_MEDIA There was a media error.\r |
772db4bb | 774 | \r |
775 | **/\r | |
772db4bb | 776 | EFI_STATUS\r |
777 | EFIAPI\r | |
778 | EfiDhcp4Start (\r | |
779 | IN EFI_DHCP4_PROTOCOL *This,\r | |
780 | IN EFI_EVENT CompletionEvent OPTIONAL\r | |
781 | )\r | |
782 | {\r | |
783 | DHCP_PROTOCOL *Instance;\r | |
784 | DHCP_SERVICE *DhcpSb;\r | |
785 | EFI_STATUS Status;\r | |
786 | EFI_TPL OldTpl;\r | |
787 | \r | |
788 | //\r | |
789 | // First validate the parameters\r | |
790 | //\r | |
791 | if (This == NULL) {\r | |
792 | return EFI_INVALID_PARAMETER;\r | |
793 | }\r | |
794 | \r | |
795 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
796 | \r | |
797 | if (Instance->Signature != DHCP_PROTOCOL_SIGNATURE) {\r | |
798 | return EFI_INVALID_PARAMETER;\r | |
799 | }\r | |
800 | \r | |
e48e37fc | 801 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 802 | DhcpSb = Instance->Service;\r |
803 | \r | |
804 | if (DhcpSb->DhcpState == Dhcp4Stopped) {\r | |
805 | Status = EFI_NOT_STARTED;\r | |
806 | goto ON_ERROR;\r | |
807 | }\r | |
808 | \r | |
809 | if ((DhcpSb->DhcpState != Dhcp4Init) && (DhcpSb->DhcpState != Dhcp4InitReboot)) {\r | |
810 | Status = EFI_ALREADY_STARTED;\r | |
811 | goto ON_ERROR;\r | |
812 | }\r | |
813 | \r | |
814 | DhcpSb->IoStatus = EFI_ALREADY_STARTED;\r | |
815 | \r | |
816 | if (EFI_ERROR (Status = DhcpInitRequest (DhcpSb))) {\r | |
817 | goto ON_ERROR;\r | |
818 | }\r | |
819 | \r | |
772db4bb | 820 | \r |
821 | Instance->CompletionEvent = CompletionEvent;\r | |
822 | \r | |
823 | //\r | |
e48e37fc | 824 | // Restore the TPL now, don't call poll function at TPL_CALLBACK.\r |
772db4bb | 825 | //\r |
e48e37fc | 826 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 827 | \r |
828 | if (CompletionEvent == NULL) {\r | |
829 | while (DhcpSb->IoStatus == EFI_ALREADY_STARTED) {\r | |
b45b45b2 | 830 | DhcpSb->UdpIo->Protocol.Udp4->Poll (DhcpSb->UdpIo->Protocol.Udp4);\r |
772db4bb | 831 | }\r |
832 | \r | |
833 | return DhcpSb->IoStatus;\r | |
834 | }\r | |
835 | \r | |
836 | return EFI_SUCCESS;\r | |
837 | \r | |
838 | ON_ERROR:\r | |
e48e37fc | 839 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 840 | return Status;\r |
841 | }\r | |
842 | \r | |
843 | \r | |
844 | /**\r | |
f9204641 | 845 | Extends the lease time by sending a request packet.\r |
e2851998 | 846 | \r |
f9204641 | 847 | The RenewRebind() function is used to manually extend the lease time when the\r |
848 | EFI DHCPv4 Protocol driver is in the Dhcp4Bound state and the lease time has\r | |
849 | not expired yet. This function will send a request packet to the previously\r | |
850 | found server (or to any server when RebindRequest is TRUE) and transfer the\r | |
851 | state into the Dhcp4Renewing state (or Dhcp4Rebinding when RebindingRequest is\r | |
852 | TRUE). When a response is received, the state is returned to Dhcp4Bound.\r | |
853 | If no response is received before the try count is exceeded (the RequestTryCount\r | |
854 | field that is specified in EFI_DHCP4_CONFIG_DATA) but before the lease time that\r | |
855 | was issued by the previous server expires, the driver will return to the Dhcp4Bound\r | |
856 | state and the previous configuration is restored. The outgoing and incoming packets\r | |
857 | can be captured by the EFI_DHCP4_CALLBACK function.\r | |
858 | \r | |
3e8c18da | 859 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
860 | @param[in] RebindRequest If TRUE, this function broadcasts the request packets and enters\r | |
861 | the Dhcp4Rebinding state. Otherwise, it sends a unicast\r | |
862 | request packet and enters the Dhcp4Renewing state.\r | |
863 | @param[in] CompletionEvent If not NULL, this event is signaled when the renew/rebind phase\r | |
864 | completes or some error occurs.\r | |
865 | EFI_DHCP4_PROTOCOL.GetModeData() can be called to\r | |
866 | check the completion status. If NULL,\r | |
867 | EFI_DHCP4_PROTOCOL.RenewRebind() will busy-wait\r | |
868 | until the DHCP process finishes.\r | |
f9204641 | 869 | \r |
870 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the\r | |
871 | Dhcp4Renewing state or is back to the Dhcp4Bound state.\r | |
872 | @retval EFI_NOT_STARTED The EFI DHCPv4 Protocol driver is in the Dhcp4Stopped\r | |
873 | state. EFI_DHCP4_PROTOCOL.Configure() needs to\r | |
874 | be called.\r | |
875 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
876 | @retval EFI_TIMEOUT There was no response from the server when the try count was\r | |
877 | exceeded.\r | |
878 | @retval EFI_ACCESS_DENIED The driver is not in the Dhcp4Bound state.\r | |
879 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
772db4bb | 880 | \r |
881 | **/\r | |
772db4bb | 882 | EFI_STATUS\r |
883 | EFIAPI\r | |
884 | EfiDhcp4RenewRebind (\r | |
885 | IN EFI_DHCP4_PROTOCOL *This,\r | |
886 | IN BOOLEAN RebindRequest,\r | |
887 | IN EFI_EVENT CompletionEvent OPTIONAL\r | |
888 | )\r | |
889 | {\r | |
890 | DHCP_PROTOCOL *Instance;\r | |
891 | DHCP_SERVICE *DhcpSb;\r | |
892 | EFI_STATUS Status;\r | |
893 | EFI_TPL OldTpl;\r | |
894 | \r | |
895 | //\r | |
896 | // First validate the parameters\r | |
897 | //\r | |
898 | if (This == NULL) {\r | |
899 | return EFI_INVALID_PARAMETER;\r | |
900 | }\r | |
901 | \r | |
902 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
903 | \r | |
904 | if (Instance->Signature != DHCP_PROTOCOL_SIGNATURE) {\r | |
905 | return EFI_INVALID_PARAMETER;\r | |
906 | }\r | |
907 | \r | |
e48e37fc | 908 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 909 | DhcpSb = Instance->Service;\r |
910 | \r | |
911 | if (DhcpSb->DhcpState == Dhcp4Stopped) {\r | |
912 | Status = EFI_NOT_STARTED;\r | |
ae0a0b06 | 913 | goto ON_EXIT;\r |
772db4bb | 914 | }\r |
915 | \r | |
916 | if (DhcpSb->DhcpState != Dhcp4Bound) {\r | |
917 | Status = EFI_ACCESS_DENIED;\r | |
ae0a0b06 | 918 | goto ON_EXIT;\r |
772db4bb | 919 | }\r |
920 | \r | |
921 | if (DHCP_IS_BOOTP (DhcpSb->Para)) {\r | |
ae0a0b06 | 922 | Status = EFI_SUCCESS;\r |
923 | goto ON_EXIT;\r | |
772db4bb | 924 | }\r |
925 | \r | |
926 | //\r | |
927 | // Transit the states then send a extra DHCP request\r | |
928 | //\r | |
929 | if (!RebindRequest) {\r | |
930 | DhcpSetState (DhcpSb, Dhcp4Renewing, FALSE);\r | |
931 | } else {\r | |
932 | DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE);\r | |
933 | }\r | |
934 | \r | |
842d83d6 | 935 | //\r |
936 | // Clear initial time to make sure that elapsed-time\r | |
937 | // is set to 0 for first REQUEST in renewal process.\r | |
938 | //\r | |
939 | Instance->ElaspedTime = 0;\r | |
940 | \r | |
772db4bb | 941 | Status = DhcpSendMessage (\r |
942 | DhcpSb,\r | |
943 | DhcpSb->Selected,\r | |
944 | DhcpSb->Para,\r | |
945 | DHCP_MSG_REQUEST,\r | |
67a58d0f | 946 | (UINT8 *) "Extra renew/rebind by the application"\r |
772db4bb | 947 | );\r |
948 | \r | |
949 | if (EFI_ERROR (Status)) {\r | |
950 | DhcpSetState (DhcpSb, Dhcp4Bound, FALSE);\r | |
ae0a0b06 | 951 | goto ON_EXIT;\r |
772db4bb | 952 | }\r |
953 | \r | |
954 | DhcpSb->ExtraRefresh = TRUE;\r | |
955 | DhcpSb->IoStatus = EFI_ALREADY_STARTED;\r | |
956 | Instance->RenewRebindEvent = CompletionEvent;\r | |
957 | \r | |
e48e37fc | 958 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 959 | \r |
960 | if (CompletionEvent == NULL) {\r | |
961 | while (DhcpSb->IoStatus == EFI_ALREADY_STARTED) {\r | |
b45b45b2 | 962 | DhcpSb->UdpIo->Protocol.Udp4->Poll (DhcpSb->UdpIo->Protocol.Udp4);\r |
963 | \r | |
772db4bb | 964 | }\r |
965 | \r | |
966 | return DhcpSb->IoStatus;\r | |
967 | }\r | |
968 | \r | |
969 | return EFI_SUCCESS;\r | |
970 | \r | |
ae0a0b06 | 971 | ON_EXIT:\r |
e48e37fc | 972 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 973 | return Status;\r |
974 | }\r | |
975 | \r | |
976 | \r | |
977 | /**\r | |
f9204641 | 978 | Releases the current address configuration.\r |
979 | \r | |
980 | The Release() function releases the current configured IP address by doing either\r | |
981 | of the following:\r | |
982 | * Sending a DHCPRELEASE packet when the EFI DHCPv4 Protocol driver is in the\r | |
983 | Dhcp4Bound state\r | |
984 | * Setting the previously assigned IP address that was provided with the\r | |
985 | EFI_DHCP4_PROTOCOL.Configure() function to 0.0.0.0 when the driver is in\r | |
986 | Dhcp4InitReboot state\r | |
987 | After a successful call to this function, the EFI DHCPv4 Protocol driver returns\r | |
988 | to the Dhcp4Init state and any subsequent incoming packets will be discarded silently.\r | |
772db4bb | 989 | \r |
3e8c18da | 990 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
772db4bb | 991 | \r |
f9204641 | 992 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the Dhcp4Init phase.\r |
993 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
994 | @retval EFI_ACCESS_DENIED The EFI DHCPv4 Protocol driver is not Dhcp4InitReboot state.\r | |
995 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
772db4bb | 996 | \r |
997 | **/\r | |
772db4bb | 998 | EFI_STATUS\r |
999 | EFIAPI\r | |
1000 | EfiDhcp4Release (\r | |
1001 | IN EFI_DHCP4_PROTOCOL *This\r | |
1002 | )\r | |
1003 | {\r | |
1004 | DHCP_PROTOCOL *Instance;\r | |
1005 | DHCP_SERVICE *DhcpSb;\r | |
1006 | EFI_STATUS Status;\r | |
1007 | EFI_TPL OldTpl;\r | |
1008 | \r | |
1009 | //\r | |
1010 | // First validate the parameters\r | |
1011 | //\r | |
1012 | if (This == NULL) {\r | |
1013 | return EFI_INVALID_PARAMETER;\r | |
1014 | }\r | |
1015 | \r | |
1016 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
1017 | \r | |
1018 | if (Instance->Signature != DHCP_PROTOCOL_SIGNATURE) {\r | |
1019 | return EFI_INVALID_PARAMETER;\r | |
1020 | }\r | |
1021 | \r | |
1022 | Status = EFI_SUCCESS;\r | |
e48e37fc | 1023 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 1024 | DhcpSb = Instance->Service;\r |
1025 | \r | |
1026 | if ((DhcpSb->DhcpState != Dhcp4InitReboot) && (DhcpSb->DhcpState != Dhcp4Bound)) {\r | |
1027 | Status = EFI_ACCESS_DENIED;\r | |
1028 | goto ON_EXIT;\r | |
1029 | }\r | |
1030 | \r | |
1031 | if (!DHCP_IS_BOOTP (DhcpSb->Para) && (DhcpSb->DhcpState == Dhcp4Bound)) {\r | |
1032 | Status = DhcpSendMessage (\r | |
1033 | DhcpSb,\r | |
1034 | DhcpSb->Selected,\r | |
1035 | DhcpSb->Para,\r | |
1036 | DHCP_MSG_RELEASE,\r | |
1037 | NULL\r | |
1038 | );\r | |
1039 | \r | |
1040 | if (EFI_ERROR (Status)) {\r | |
1041 | Status = EFI_DEVICE_ERROR;\r | |
1042 | goto ON_EXIT;\r | |
1043 | }\r | |
1044 | }\r | |
1045 | \r | |
1046 | DhcpCleanLease (DhcpSb);\r | |
1047 | \r | |
1048 | ON_EXIT:\r | |
e48e37fc | 1049 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 1050 | return Status;\r |
1051 | }\r | |
1052 | \r | |
1053 | \r | |
1054 | /**\r | |
f9204641 | 1055 | Stops the current address configuration.\r |
e2851998 | 1056 | \r |
f9204641 | 1057 | The Stop() function is used to stop the DHCP configuration process. After this\r |
1058 | function is called successfully, the EFI DHCPv4 Protocol driver is transferred\r | |
1059 | into the Dhcp4Stopped state. EFI_DHCP4_PROTOCOL.Configure() needs to be called\r | |
1060 | before DHCP configuration process can be started again. This function can be\r | |
1061 | called when the EFI DHCPv4 Protocol driver is in any state.\r | |
772db4bb | 1062 | \r |
3e8c18da | 1063 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
772db4bb | 1064 | \r |
f9204641 | 1065 | @retval EFI_SUCCESS The EFI DHCPv4 Protocol driver is now in the Dhcp4Stopped phase.\r |
1066 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
772db4bb | 1067 | \r |
1068 | **/\r | |
772db4bb | 1069 | EFI_STATUS\r |
1070 | EFIAPI\r | |
1071 | EfiDhcp4Stop (\r | |
1072 | IN EFI_DHCP4_PROTOCOL *This\r | |
1073 | )\r | |
1074 | {\r | |
1075 | DHCP_PROTOCOL *Instance;\r | |
1076 | DHCP_SERVICE *DhcpSb;\r | |
1077 | EFI_TPL OldTpl;\r | |
1078 | \r | |
1079 | //\r | |
1080 | // First validate the parameters\r | |
1081 | //\r | |
1082 | if (This == NULL) {\r | |
1083 | return EFI_INVALID_PARAMETER;\r | |
1084 | }\r | |
1085 | \r | |
1086 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
1087 | \r | |
1088 | if (Instance->Signature != DHCP_PROTOCOL_SIGNATURE) {\r | |
1089 | return EFI_INVALID_PARAMETER;\r | |
1090 | }\r | |
1091 | \r | |
e48e37fc | 1092 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 1093 | DhcpSb = Instance->Service;\r |
1094 | \r | |
1095 | DhcpCleanLease (DhcpSb);\r | |
1096 | \r | |
1097 | DhcpSb->DhcpState = Dhcp4Stopped;\r | |
1098 | DhcpSb->ServiceState = DHCP_UNCONFIGED;\r | |
1099 | \r | |
e48e37fc | 1100 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 1101 | return EFI_SUCCESS;\r |
1102 | }\r | |
1103 | \r | |
1104 | \r | |
1105 | /**\r | |
f9204641 | 1106 | Builds a DHCP packet, given the options to be appended or deleted or replaced.\r |
1107 | \r | |
1108 | The Build() function is used to assemble a new packet from the original packet\r | |
1109 | by replacing or deleting existing options or appending new options. This function\r | |
1110 | does not change any state of the EFI DHCPv4 Protocol driver and can be used at\r | |
1111 | any time.\r | |
1112 | \r | |
3e8c18da | 1113 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
1114 | @param[in] SeedPacket Initial packet to be used as a base for building new packet.\r | |
1115 | @param[in] DeleteCount Number of opcodes in the DeleteList.\r | |
1116 | @param[in] DeleteList List of opcodes to be deleted from the seed packet.\r | |
1117 | Ignored if DeleteCount is zero.\r | |
1118 | @param[in] AppendCount Number of entries in the OptionList.\r | |
1119 | @param[in] AppendList Pointer to a DHCP option list to be appended to SeedPacket.\r | |
1120 | If SeedPacket also contains options in this list, they are\r | |
1121 | replaced by new options (except pad option). Ignored if\r | |
1122 | AppendCount is zero. Type EFI_DHCP4_PACKET_OPTION\r | |
1123 | @param[out] NewPacket Pointer to storage for the pointer to the new allocated packet.\r | |
1124 | Use the EFI Boot Service FreePool() on the resulting pointer\r | |
1125 | when done with the packet.\r | |
f9204641 | 1126 | \r |
1127 | @retval EFI_SUCCESS The new packet was built.\r | |
1128 | @retval EFI_OUT_OF_RESOURCES Storage for the new packet could not be allocated.\r | |
1129 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
772db4bb | 1130 | \r |
1131 | **/\r | |
772db4bb | 1132 | EFI_STATUS\r |
1133 | EFIAPI\r | |
1134 | EfiDhcp4Build (\r | |
1135 | IN EFI_DHCP4_PROTOCOL *This,\r | |
1136 | IN EFI_DHCP4_PACKET *SeedPacket,\r | |
1137 | IN UINT32 DeleteCount,\r | |
1138 | IN UINT8 *DeleteList OPTIONAL,\r | |
1139 | IN UINT32 AppendCount,\r | |
1140 | IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL,\r | |
1141 | OUT EFI_DHCP4_PACKET **NewPacket\r | |
1142 | )\r | |
1143 | {\r | |
1144 | //\r | |
1145 | // First validate the parameters\r | |
1146 | //\r | |
1147 | if ((This == NULL) || (NewPacket == NULL)) {\r | |
1148 | return EFI_INVALID_PARAMETER;\r | |
1149 | }\r | |
1150 | \r | |
1151 | if ((SeedPacket == NULL) || (SeedPacket->Dhcp4.Magik != DHCP_OPTION_MAGIC) ||\r | |
1152 | EFI_ERROR (DhcpValidateOptions (SeedPacket, NULL))) {\r | |
1153 | \r | |
1154 | return EFI_INVALID_PARAMETER;\r | |
1155 | }\r | |
1156 | \r | |
1157 | if (((DeleteCount == 0) && (AppendCount == 0)) ||\r | |
1158 | ((DeleteCount != 0) && (DeleteList == NULL)) ||\r | |
1159 | ((AppendCount != 0) && (AppendList == NULL))) {\r | |
1160 | \r | |
1161 | return EFI_INVALID_PARAMETER;\r | |
1162 | }\r | |
1163 | \r | |
1164 | return DhcpBuild (\r | |
1165 | SeedPacket,\r | |
1166 | DeleteCount,\r | |
1167 | DeleteList,\r | |
1168 | AppendCount,\r | |
1169 | AppendList,\r | |
1170 | NewPacket\r | |
1171 | );\r | |
1172 | }\r | |
1173 | \r | |
f9204641 | 1174 | /**\r |
1175 | Callback by UdpIoCreatePort() when creating UdpIo for this Dhcp4 instance.\r | |
e2851998 | 1176 | \r |
3e8c18da | 1177 | @param[in] UdpIo The UdpIo being created.\r |
1178 | @param[in] Context Dhcp4 instance.\r | |
e2851998 | 1179 | \r |
f9204641 | 1180 | @retval EFI_SUCCESS UdpIo is configured successfully.\r |
1181 | @retval other Other error occurs.\r | |
1182 | **/\r | |
c4a62a12 | 1183 | EFI_STATUS\r |
e798cd87 | 1184 | EFIAPI\r |
c4a62a12 | 1185 | Dhcp4InstanceConfigUdpIo (\r |
b45b45b2 | 1186 | IN UDP_IO *UdpIo,\r |
c4a62a12 | 1187 | IN VOID *Context\r |
1188 | )\r | |
1189 | {\r | |
1190 | DHCP_PROTOCOL *Instance;\r | |
8c5f78a2 | 1191 | DHCP_SERVICE *DhcpSb;\r |
c4a62a12 | 1192 | EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;\r |
1193 | EFI_UDP4_CONFIG_DATA UdpConfigData;\r | |
ce964733 WJ |
1194 | IP4_ADDR ClientAddr;\r |
1195 | IP4_ADDR Ip; \r | |
1196 | INTN Class; \r | |
1197 | IP4_ADDR SubnetMask;\r | |
c4a62a12 | 1198 | \r |
1199 | Instance = (DHCP_PROTOCOL *) Context;\r | |
8c5f78a2 | 1200 | DhcpSb = Instance->Service;\r |
c4a62a12 | 1201 | Token = Instance->Token;\r |
1202 | \r | |
e48e37fc | 1203 | ZeroMem (&UdpConfigData, sizeof (EFI_UDP4_CONFIG_DATA));\r |
c4a62a12 | 1204 | \r |
1205 | UdpConfigData.AcceptBroadcast = TRUE;\r | |
1206 | UdpConfigData.AllowDuplicatePort = TRUE;\r | |
1207 | UdpConfigData.TimeToLive = 64;\r | |
1208 | UdpConfigData.DoNotFragment = TRUE;\r | |
1209 | \r | |
ce964733 WJ |
1210 | ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr);\r |
1211 | Ip = HTONL (ClientAddr);\r | |
e48e37fc | 1212 | CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
8c5f78a2 JW |
1213 | \r |
1214 | if (DhcpSb->Netmask == 0) {\r | |
1215 | Class = NetGetIpClass (ClientAddr);\r | |
1216 | ASSERT (Class < IP4_ADDR_CLASSE);\r | |
1217 | SubnetMask = gIp4AllMasks[Class << 3];\r | |
1218 | } else {\r | |
1219 | SubnetMask = DhcpSb->Netmask;\r | |
1220 | }\r | |
1221 | \r | |
ce964733 | 1222 | Ip = HTONL (SubnetMask);\r |
e48e37fc | 1223 | CopyMem (&UdpConfigData.SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
c4a62a12 | 1224 | \r |
1225 | if ((Token->ListenPointCount == 0) || (Token->ListenPoints[0].ListenPort == 0)) {\r | |
1226 | UdpConfigData.StationPort = DHCP_CLIENT_PORT;\r | |
1227 | } else {\r | |
1228 | UdpConfigData.StationPort = Token->ListenPoints[0].ListenPort;\r | |
1229 | }\r | |
1230 | \r | |
b45b45b2 | 1231 | return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);\r |
c4a62a12 | 1232 | }\r |
1233 | \r | |
f9204641 | 1234 | /**\r |
1235 | Create UdpIo for this Dhcp4 instance.\r | |
e2851998 | 1236 | \r |
f9204641 | 1237 | @param Instance The Dhcp4 instance.\r |
e2851998 | 1238 | \r |
f9204641 | 1239 | @retval EFI_SUCCESS UdpIo is created successfully.\r |
1240 | @retval EFI_OUT_OF_RESOURCES Fails to create UdpIo because of limited\r | |
1241 | resources or configuration failure.\r | |
1242 | **/\r | |
c4a62a12 | 1243 | EFI_STATUS\r |
1244 | Dhcp4InstanceCreateUdpIo (\r | |
f9204641 | 1245 | IN OUT DHCP_PROTOCOL *Instance\r |
c4a62a12 | 1246 | )\r |
1247 | {\r | |
1248 | DHCP_SERVICE *DhcpSb;\r | |
216f7970 | 1249 | EFI_STATUS Status;\r |
1250 | VOID *Udp4;\r | |
c4a62a12 | 1251 | \r |
1252 | ASSERT (Instance->Token != NULL);\r | |
1253 | \r | |
1254 | DhcpSb = Instance->Service;\r | |
b45b45b2 | 1255 | Instance->UdpIo = UdpIoCreateIo (\r |
1256 | DhcpSb->Controller,\r | |
1257 | DhcpSb->Image,\r | |
1258 | Dhcp4InstanceConfigUdpIo,\r | |
1259 | UDP_IO_UDP4_VERSION,\r | |
1260 | Instance\r | |
1261 | );\r | |
c4a62a12 | 1262 | if (Instance->UdpIo == NULL) {\r |
1263 | return EFI_OUT_OF_RESOURCES;\r | |
1264 | } else {\r | |
216f7970 | 1265 | Status = gBS->OpenProtocol (\r |
1266 | Instance->UdpIo->UdpHandle,\r | |
1267 | &gEfiUdp4ProtocolGuid,\r | |
1268 | (VOID **) &Udp4,\r | |
1269 | Instance->Service->Image,\r | |
1270 | Instance->Handle,\r | |
1271 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
1272 | );\r | |
1273 | if (EFI_ERROR (Status)) {\r | |
1274 | UdpIoFreeIo (Instance->UdpIo);\r | |
1275 | Instance->UdpIo = NULL;\r | |
1276 | }\r | |
1277 | return Status;\r | |
c4a62a12 | 1278 | }\r |
1279 | }\r | |
1280 | \r | |
f9204641 | 1281 | /**\r |
1282 | Callback of Dhcp packet. Does nothing.\r | |
e2851998 | 1283 | \r |
f9204641 | 1284 | @param Arg The context.\r |
3e8c18da | 1285 | \r |
f9204641 | 1286 | **/\r |
c4a62a12 | 1287 | VOID\r |
e798cd87 | 1288 | EFIAPI\r |
c4a62a12 | 1289 | DhcpDummyExtFree (\r |
1290 | IN VOID *Arg\r | |
1291 | )\r | |
982a9eae | 1292 | {\r |
c4a62a12 | 1293 | }\r |
1294 | \r | |
f9204641 | 1295 | /**\r |
1296 | Callback of UdpIoRecvDatagram() that handles a Dhcp4 packet.\r | |
e2851998 | 1297 | \r |
f9204641 | 1298 | Only BOOTP responses will be handled that correspond to the Xid of the request\r |
1299 | sent out. The packet will be queued to the response queue.\r | |
e2851998 | 1300 | \r |
f9204641 | 1301 | @param UdpPacket The Dhcp4 packet.\r |
b45b45b2 | 1302 | @param EndPoint Udp4 address pair.\r |
f9204641 | 1303 | @param IoStatus Status of the input.\r |
1304 | @param Context Extra info for the input.\r | |
e2851998 | 1305 | \r |
f9204641 | 1306 | **/\r |
c4a62a12 | 1307 | VOID\r |
e798cd87 | 1308 | EFIAPI\r |
c4a62a12 | 1309 | PxeDhcpInput (\r |
1310 | NET_BUF *UdpPacket,\r | |
b45b45b2 | 1311 | UDP_END_POINT *EndPoint,\r |
c4a62a12 | 1312 | EFI_STATUS IoStatus,\r |
1313 | VOID *Context\r | |
1314 | )\r | |
1315 | {\r | |
1316 | DHCP_PROTOCOL *Instance;\r | |
c4a62a12 | 1317 | EFI_DHCP4_HEADER *Head;\r |
1318 | NET_BUF *Wrap;\r | |
1319 | EFI_DHCP4_PACKET *Packet;\r | |
1320 | EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;\r | |
1321 | UINT32 Len;\r | |
1322 | EFI_STATUS Status;\r | |
1323 | \r | |
1324 | Wrap = NULL;\r | |
1325 | Instance = (DHCP_PROTOCOL *) Context;\r | |
1326 | Token = Instance->Token;\r | |
c4a62a12 | 1327 | \r |
1328 | //\r | |
f9204641 | 1329 | // Don't restart receive if error occurs or DHCP is destroyed.\r |
c4a62a12 | 1330 | //\r |
1331 | if (EFI_ERROR (IoStatus)) {\r | |
1332 | return ;\r | |
1333 | }\r | |
1334 | \r | |
1335 | ASSERT (UdpPacket != NULL);\r | |
982a9eae | 1336 | \r |
c4a62a12 | 1337 | //\r |
1338 | // Validate the packet received\r | |
1339 | //\r | |
1340 | if (UdpPacket->TotalSize < sizeof (EFI_DHCP4_HEADER)) {\r | |
1341 | goto RESTART;\r | |
1342 | }\r | |
982a9eae | 1343 | \r |
c4a62a12 | 1344 | //\r |
1345 | // Copy the DHCP message to a continuous memory block, make the buffer size\r | |
1346 | // of the EFI_DHCP4_PACKET a multiple of 4-byte.\r | |
1347 | //\r | |
1348 | Len = NET_ROUNDUP (sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER), 4);\r | |
1349 | Wrap = NetbufAlloc (Len);\r | |
c4a62a12 | 1350 | if (Wrap == NULL) {\r |
1351 | goto RESTART;\r | |
1352 | }\r | |
1353 | \r | |
1354 | Packet = (EFI_DHCP4_PACKET *) NetbufAllocSpace (Wrap, Len, NET_BUF_TAIL);\r | |
894d038a | 1355 | ASSERT (Packet != NULL);\r |
1356 | \r | |
c4a62a12 | 1357 | Packet->Size = Len;\r |
1358 | Head = &Packet->Dhcp4.Header;\r | |
1359 | Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *) Head);\r | |
1360 | \r | |
1361 | if (Packet->Length != UdpPacket->TotalSize) {\r | |
1362 | goto RESTART;\r | |
1363 | }\r | |
982a9eae | 1364 | \r |
c4a62a12 | 1365 | //\r |
1366 | // Is this packet the answer to our packet?\r | |
1367 | //\r | |
1368 | if ((Head->OpCode != BOOTP_REPLY) ||\r | |
1369 | (Head->Xid != Token->Packet->Dhcp4.Header.Xid) ||\r | |
ce964733 | 1370 | (CompareMem (&Token->Packet->Dhcp4.Header.ClientHwAddr[0], Head->ClientHwAddr, Head->HwAddrLen) != 0)) {\r |
c4a62a12 | 1371 | goto RESTART;\r |
1372 | }\r | |
982a9eae | 1373 | \r |
c4a62a12 | 1374 | //\r |
1375 | // Validate the options and retrieve the interested options\r | |
1376 | //\r | |
1377 | if ((Packet->Length > sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32)) &&\r | |
1378 | (Packet->Dhcp4.Magik == DHCP_OPTION_MAGIC) &&\r | |
1379 | EFI_ERROR (DhcpValidateOptions (Packet, NULL))) {\r | |
1380 | \r | |
1381 | goto RESTART;\r | |
1382 | }\r | |
1383 | \r | |
1384 | //\r | |
1385 | // Keep this packet in the ResponseQueue.\r | |
1386 | //\r | |
1387 | NET_GET_REF (Wrap);\r | |
1388 | NetbufQueAppend (&Instance->ResponseQueue, Wrap);\r | |
1389 | \r | |
1390 | RESTART:\r | |
1391 | \r | |
1392 | NetbufFree (UdpPacket);\r | |
1393 | \r | |
1394 | if (Wrap != NULL) {\r | |
1395 | NetbufFree (Wrap);\r | |
1396 | }\r | |
1397 | \r | |
1398 | Status = UdpIoRecvDatagram (Instance->UdpIo, PxeDhcpInput, Instance, 0);\r | |
1399 | if (EFI_ERROR (Status)) {\r | |
1400 | PxeDhcpDone (Instance);\r | |
1401 | }\r | |
1402 | }\r | |
1403 | \r | |
f9204641 | 1404 | /**\r |
1405 | Complete a Dhcp4 transaction and signal the upper layer.\r | |
e2851998 | 1406 | \r |
f9204641 | 1407 | @param Instance Dhcp4 instance.\r |
f9204641 | 1408 | \r |
1409 | **/\r | |
c4a62a12 | 1410 | VOID\r |
1411 | PxeDhcpDone (\r | |
1412 | IN DHCP_PROTOCOL *Instance\r | |
1413 | )\r | |
1414 | {\r | |
1415 | EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;\r | |
1416 | \r | |
1417 | Token = Instance->Token;\r | |
1418 | \r | |
1419 | Token->ResponseCount = Instance->ResponseQueue.BufNum;\r | |
1420 | if (Token->ResponseCount != 0) {\r | |
e48e37fc | 1421 | Token->ResponseList = (EFI_DHCP4_PACKET *) AllocatePool (Instance->ResponseQueue.BufSize);\r |
c4a62a12 | 1422 | if (Token->ResponseList == NULL) {\r |
1423 | Token->Status = EFI_OUT_OF_RESOURCES;\r | |
1424 | goto SIGNAL_USER;\r | |
1425 | }\r | |
1426 | \r | |
1427 | //\r | |
f9204641 | 1428 | // Copy the received DHCP responses.\r |
c4a62a12 | 1429 | //\r |
1430 | NetbufQueCopy (&Instance->ResponseQueue, 0, Instance->ResponseQueue.BufSize, (UINT8 *) Token->ResponseList);\r | |
1431 | Token->Status = EFI_SUCCESS;\r | |
1432 | } else {\r | |
1433 | Token->ResponseList = NULL;\r | |
1434 | Token->Status = EFI_TIMEOUT;\r | |
1435 | }\r | |
1436 | \r | |
1437 | SIGNAL_USER:\r | |
1438 | //\r | |
f9204641 | 1439 | // Clean up the resources dedicated for this transmit receive transaction.\r |
c4a62a12 | 1440 | //\r |
1441 | NetbufQueFlush (&Instance->ResponseQueue);\r | |
b45b45b2 | 1442 | UdpIoCleanIo (Instance->UdpIo);\r |
216f7970 | 1443 | gBS->CloseProtocol (\r |
1444 | Instance->UdpIo->UdpHandle,\r | |
1445 | &gEfiUdp4ProtocolGuid,\r | |
1446 | Instance->Service->Image,\r | |
1447 | Instance->Handle\r | |
1448 | );\r | |
b45b45b2 | 1449 | UdpIoFreeIo (Instance->UdpIo);\r |
c4a62a12 | 1450 | Instance->UdpIo = NULL;\r |
1451 | Instance->Token = NULL;\r | |
1452 | \r | |
1453 | if (Token->CompletionEvent != NULL) {\r | |
1454 | gBS->SignalEvent (Token->CompletionEvent);\r | |
982a9eae | 1455 | }\r |
c4a62a12 | 1456 | }\r |
1457 | \r | |
772db4bb | 1458 | \r |
1459 | /**\r | |
ba39e316 | 1460 | Transmits a DHCP formatted packet and optionally waits for responses.\r |
e2851998 | 1461 | \r |
f9204641 | 1462 | The TransmitReceive() function is used to transmit a DHCP packet and optionally\r |
1463 | wait for the response from servers. This function does not change the state of\r | |
1464 | the EFI DHCPv4 Protocol driver and thus can be used at any time.\r | |
ba39e316 | 1465 | \r |
3e8c18da | 1466 | @param[in] This Pointer to the EFI_DHCP4_PROTOCOL instance.\r |
1467 | @param[in] Token Pointer to the EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN structure.\r | |
ba39e316 | 1468 | \r |
1469 | @retval EFI_SUCCESS The packet was successfully queued for transmission.\r | |
1470 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
1471 | @retval EFI_NOT_READY The previous call to this function has not finished yet. Try to call\r | |
1472 | this function after collection process completes.\r | |
1473 | @retval EFI_NO_MAPPING The default station address is not available yet.\r | |
1474 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
1475 | @retval Others Some other unexpected error occurred.\r | |
772db4bb | 1476 | \r |
1477 | **/\r | |
772db4bb | 1478 | EFI_STATUS\r |
1479 | EFIAPI\r | |
1480 | EfiDhcp4TransmitReceive (\r | |
1481 | IN EFI_DHCP4_PROTOCOL *This,\r | |
1482 | IN EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token\r | |
1483 | )\r | |
1484 | {\r | |
c4a62a12 | 1485 | DHCP_PROTOCOL *Instance;\r |
1486 | EFI_TPL OldTpl;\r | |
1487 | EFI_STATUS Status;\r | |
1488 | NET_FRAGMENT Frag;\r | |
1489 | NET_BUF *Wrap;\r | |
b45b45b2 | 1490 | UDP_END_POINT EndPoint;\r |
c4a62a12 | 1491 | IP4_ADDR Ip;\r |
1492 | DHCP_SERVICE *DhcpSb;\r | |
b45b45b2 | 1493 | EFI_IP_ADDRESS Gateway;\r |
ce964733 WJ |
1494 | IP4_ADDR ClientAddr;\r |
1495 | INTN Class;\r | |
c4a62a12 | 1496 | IP4_ADDR SubnetMask;\r |
1497 | \r | |
1498 | if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) {\r | |
1499 | return EFI_INVALID_PARAMETER;\r | |
1500 | }\r | |
1501 | \r | |
1502 | Instance = DHCP_INSTANCE_FROM_THIS (This);\r | |
1503 | DhcpSb = Instance->Service;\r | |
1504 | \r | |
1505 | if (Instance->Token != NULL) {\r | |
1506 | //\r | |
1507 | // The previous call to TransmitReceive is not finished.\r | |
1508 | //\r | |
1509 | return EFI_NOT_READY;\r | |
1510 | }\r | |
1511 | \r | |
f9204641 | 1512 | if ((Token->Packet->Dhcp4.Magik != DHCP_OPTION_MAGIC) ||\r |
1513 | (NTOHL (Token->Packet->Dhcp4.Header.Xid) == Instance->Service->Xid) ||\r | |
1514 | (Token->TimeoutValue == 0) ||\r | |
1515 | ((Token->ListenPointCount != 0) && (Token->ListenPoints == NULL)) ||\r | |
1516 | EFI_ERROR (DhcpValidateOptions (Token->Packet, NULL)) ||\r | |
1517 | EFI_IP4_EQUAL (&Token->RemoteAddress, &mZeroIp4Addr)\r | |
1518 | ) {\r | |
c4a62a12 | 1519 | //\r |
f9204641 | 1520 | // The DHCP packet isn't well-formed, the Transaction ID is already used,\r |
1521 | // the timeout value is zero, the ListenPoint is invalid, or the\r | |
1522 | // RemoteAddress is zero.\r | |
c4a62a12 | 1523 | //\r |
1524 | return EFI_INVALID_PARAMETER;\r | |
1525 | }\r | |
1526 | \r | |
ce964733 WJ |
1527 | ClientAddr = EFI_NTOHL (Token->Packet->Dhcp4.Header.ClientAddr);\r |
1528 | \r | |
1529 | if (ClientAddr == 0) {\r | |
c4a62a12 | 1530 | return EFI_NO_MAPPING;\r |
1531 | }\r | |
1532 | \r | |
e48e37fc | 1533 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
c4a62a12 | 1534 | \r |
1535 | //\r | |
1536 | // Save the token and the timeout value.\r | |
1537 | //\r | |
1538 | Instance->Token = Token;\r | |
1539 | Instance->Timeout = Token->TimeoutValue;\r | |
1540 | \r | |
1541 | //\r | |
1542 | // Create a UDP IO for this transmit receive transaction.\r | |
1543 | //\r | |
1544 | Status = Dhcp4InstanceCreateUdpIo (Instance);\r | |
1545 | if (EFI_ERROR (Status)) {\r | |
1546 | goto ON_ERROR;\r | |
1547 | }\r | |
1548 | \r | |
982a9eae | 1549 | //\r |
1550 | // Save the Client Address is sent out\r | |
1551 | //\r | |
f9204641 | 1552 | CopyMem (\r |
1553 | &DhcpSb->ClientAddressSendOut[0],\r | |
1554 | &Token->Packet->Dhcp4.Header.ClientHwAddr[0],\r | |
1555 | Token->Packet->Dhcp4.Header.HwAddrLen\r | |
1556 | );\r | |
982a9eae | 1557 | \r |
772db4bb | 1558 | //\r |
c4a62a12 | 1559 | // Wrap the DHCP packet into a net buffer.\r |
772db4bb | 1560 | //\r |
c4a62a12 | 1561 | Frag.Bulk = (UINT8 *) &Token->Packet->Dhcp4;\r |
1562 | Frag.Len = Token->Packet->Length;\r | |
1563 | Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r | |
1564 | if (Wrap == NULL) {\r | |
1565 | Status = EFI_OUT_OF_RESOURCES;\r | |
1566 | goto ON_ERROR;\r | |
1567 | }\r | |
1568 | \r | |
1569 | //\r | |
b45b45b2 | 1570 | // Set the local address and local port to ZERO.\r |
c4a62a12 | 1571 | //\r |
b45b45b2 | 1572 | ZeroMem (&EndPoint, sizeof (UDP_END_POINT));\r |
c4a62a12 | 1573 | \r |
1574 | //\r | |
1575 | // Set the destination address and destination port.\r | |
1576 | //\r | |
e48e37fc | 1577 | CopyMem (&Ip, &Token->RemoteAddress, sizeof (EFI_IPv4_ADDRESS));\r |
b45b45b2 | 1578 | EndPoint.RemoteAddr.Addr[0] = NTOHL (Ip);\r |
c4a62a12 | 1579 | \r |
1580 | if (Token->RemotePort == 0) {\r | |
1581 | EndPoint.RemotePort = DHCP_SERVER_PORT;\r | |
1582 | } else {\r | |
1583 | EndPoint.RemotePort = Token->RemotePort;\r | |
1584 | }\r | |
1585 | \r | |
8c5f78a2 JW |
1586 | if (DhcpSb->Netmask == 0) {\r |
1587 | Class = NetGetIpClass (ClientAddr);\r | |
1588 | ASSERT (Class < IP4_ADDR_CLASSE);\r | |
1589 | SubnetMask = gIp4AllMasks[Class << 3];\r | |
1590 | } else {\r | |
1591 | SubnetMask = DhcpSb->Netmask;\r | |
1592 | }\r | |
1593 | \r | |
c4a62a12 | 1594 | //\r |
1595 | // Get the gateway.\r | |
1596 | //\r | |
b45b45b2 | 1597 | ZeroMem (&Gateway, sizeof (Gateway));\r |
ce964733 | 1598 | if (!IP4_NET_EQUAL (ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) {\r |
b45b45b2 | 1599 | CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r |
1600 | Gateway.Addr[0] = NTOHL (Gateway.Addr[0]);\r | |
c4a62a12 | 1601 | }\r |
1602 | \r | |
1603 | //\r | |
1604 | // Transmit the DHCP packet.\r | |
1605 | //\r | |
b45b45b2 | 1606 | Status = UdpIoSendDatagram (Instance->UdpIo, Wrap, &EndPoint, &Gateway, DhcpOnPacketSent, NULL);\r |
c4a62a12 | 1607 | if (EFI_ERROR (Status)) {\r |
1608 | NetbufFree (Wrap);\r | |
1609 | goto ON_ERROR;\r | |
1610 | }\r | |
1611 | \r | |
1612 | //\r | |
1613 | // Start to receive the DHCP response.\r | |
1614 | //\r | |
1615 | Status = UdpIoRecvDatagram (Instance->UdpIo, PxeDhcpInput, Instance, 0);\r | |
1616 | if (EFI_ERROR (Status)) {\r | |
1617 | goto ON_ERROR;\r | |
1618 | }\r | |
1619 | \r | |
1620 | ON_ERROR:\r | |
1621 | \r | |
1622 | if (EFI_ERROR (Status) && (Instance->UdpIo != NULL)) {\r | |
b45b45b2 | 1623 | UdpIoCleanIo (Instance->UdpIo);\r |
216f7970 | 1624 | gBS->CloseProtocol (\r |
1625 | Instance->UdpIo->UdpHandle,\r | |
1626 | &gEfiUdp4ProtocolGuid,\r | |
1627 | Instance->Service->Image,\r | |
1628 | Instance->Handle\r | |
1629 | );\r | |
b45b45b2 | 1630 | UdpIoFreeIo (Instance->UdpIo);\r |
c4a62a12 | 1631 | Instance->UdpIo = NULL;\r |
1632 | Instance->Token = NULL;\r | |
1633 | }\r | |
1634 | \r | |
e48e37fc | 1635 | gBS->RestoreTPL (OldTpl);\r |
c4a62a12 | 1636 | \r |
1637 | if (!EFI_ERROR (Status) && (Token->CompletionEvent == NULL)) {\r | |
1638 | //\r | |
1639 | // Keep polling until timeout if no error happens and the CompletionEvent\r | |
1640 | // is NULL.\r | |
1641 | //\r | |
c5bcc2e2 | 1642 | while (TRUE) {\r |
1643 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1644 | //\r | |
1645 | // Raise TPL to protect the UDPIO in instance, in case that DhcpOnTimerTick\r | |
1646 | // free it when timeout.\r | |
1647 | //\r | |
1648 | if (Instance->Timeout > 0) {\r | |
b45b45b2 | 1649 | Instance->UdpIo->Protocol.Udp4->Poll (Instance->UdpIo->Protocol.Udp4);\r |
c5bcc2e2 | 1650 | gBS->RestoreTPL (OldTpl);\r |
1651 | } else {\r | |
1652 | gBS->RestoreTPL (OldTpl);\r | |
1653 | break;\r | |
1654 | }\r | |
c4a62a12 | 1655 | }\r |
1656 | }\r | |
1657 | \r | |
1658 | return Status;\r | |
772db4bb | 1659 | }\r |
1660 | \r | |
1661 | \r | |
1662 | /**\r | |
1663 | Callback function for DhcpIterateOptions. This callback sets the\r | |
1664 | EFI_DHCP4_PACKET_OPTION array in the DHCP_PARSE_CONTEXT to point\r | |
1665 | the individual DHCP option in the packet.\r | |
1666 | \r | |
3e8c18da | 1667 | @param[in] Tag The DHCP option type\r |
1668 | @param[in] Len Length of the DHCP option data\r | |
1669 | @param[in] Data The DHCP option data\r | |
1670 | @param[in] Context The context, to pass several parameters in.\r | |
772db4bb | 1671 | \r |
1672 | @retval EFI_SUCCESS It always returns EFI_SUCCESS\r | |
1673 | \r | |
1674 | **/\r | |
772db4bb | 1675 | EFI_STATUS\r |
1676 | Dhcp4ParseCheckOption (\r | |
1677 | IN UINT8 Tag,\r | |
1678 | IN UINT8 Len,\r | |
1679 | IN UINT8 *Data,\r | |
1680 | IN VOID *Context\r | |
1681 | )\r | |
1682 | {\r | |
1683 | DHCP_PARSE_CONTEXT *Parse;\r | |
1684 | \r | |
1685 | Parse = (DHCP_PARSE_CONTEXT *) Context;\r | |
1686 | Parse->Index++;\r | |
1687 | \r | |
36ee91ca | 1688 | if (Parse->Index <= Parse->OptionCount) {\r |
772db4bb | 1689 | //\r |
50d7ebad | 1690 | // Use BASE_CR to get the memory position of EFI_DHCP4_PACKET_OPTION for\r |
772db4bb | 1691 | // the EFI_DHCP4_PACKET_OPTION->Data because DhcpIterateOptions only\r |
1692 | // pass in the point to option data.\r | |
1693 | //\r | |
50d7ebad | 1694 | Parse->Option[Parse->Index - 1] = BASE_CR (Data, EFI_DHCP4_PACKET_OPTION, Data);\r |
772db4bb | 1695 | }\r |
1696 | \r | |
1697 | return EFI_SUCCESS;\r | |
1698 | }\r | |
1699 | \r | |
1700 | \r | |
1701 | /**\r | |
f9204641 | 1702 | Parses the packed DHCP option data.\r |
e2851998 | 1703 | \r |
f9204641 | 1704 | The Parse() function is used to retrieve the option list from a DHCP packet.\r |
51195fbe | 1705 | If *OptionCount isn't zero, and there is enough space for all the DHCP options\r |
f9204641 | 1706 | in the Packet, each element of PacketOptionList is set to point to somewhere in\r |
1707 | the Packet->Dhcp4.Option where a new DHCP option begins. If RFC3396 is supported,\r | |
1708 | the caller should reassemble the parsed DHCP options to get the finial result.\r | |
51195fbe | 1709 | If *OptionCount is zero or there isn't enough space for all of them, the number\r |
f9204641 | 1710 | of DHCP options in the Packet is returned in OptionCount.\r |
1711 | \r | |
1712 | @param This Pointer to the EFI_DHCP4_PROTOCOL instance.\r | |
1713 | @param Packet Pointer to packet to be parsed.\r | |
1714 | @param OptionCount On input, the number of entries in the PacketOptionList.\r | |
1715 | On output, the number of entries that were written into the\r | |
1716 | PacketOptionList.\r | |
1717 | @param PacketOptionList List of packet option entries to be filled in. End option or pad\r | |
1718 | options are not included.\r | |
1719 | \r | |
1720 | @retval EFI_SUCCESS The packet was successfully parsed.\r | |
1721 | @retval EFI_INVALID_PARAMETER Some parameter is NULL.\r | |
1722 | @retval EFI_BUFFER_TOO_SMALL One or more of the following conditions is TRUE:\r | |
1723 | 1) *OptionCount is smaller than the number of options that\r | |
1724 | were found in the Packet.\r | |
1725 | 2) PacketOptionList is NULL.\r | |
772db4bb | 1726 | \r |
1727 | **/\r | |
772db4bb | 1728 | EFI_STATUS\r |
1729 | EFIAPI\r | |
1730 | EfiDhcp4Parse (\r | |
1731 | IN EFI_DHCP4_PROTOCOL *This,\r | |
1732 | IN EFI_DHCP4_PACKET *Packet,\r | |
1733 | IN OUT UINT32 *OptionCount,\r | |
1734 | OUT EFI_DHCP4_PACKET_OPTION *PacketOptionList[] OPTIONAL\r | |
1735 | )\r | |
1736 | {\r | |
1737 | DHCP_PARSE_CONTEXT Context;\r | |
1738 | EFI_STATUS Status;\r | |
1739 | \r | |
1740 | //\r | |
1741 | // First validate the parameters\r | |
1742 | //\r | |
1743 | if ((This == NULL) || (Packet == NULL) || (OptionCount == NULL)) {\r | |
1744 | return EFI_INVALID_PARAMETER;\r | |
1745 | }\r | |
1746 | \r | |
1747 | if ((Packet->Size < Packet->Length + 2 * sizeof (UINT32)) ||\r | |
1748 | (Packet->Dhcp4.Magik != DHCP_OPTION_MAGIC) ||\r | |
1749 | EFI_ERROR (DhcpValidateOptions (Packet, NULL))) {\r | |
1750 | \r | |
1751 | return EFI_INVALID_PARAMETER;\r | |
1752 | }\r | |
1753 | \r | |
1754 | if ((*OptionCount != 0) && (PacketOptionList == NULL)) {\r | |
1755 | return EFI_BUFFER_TOO_SMALL;\r | |
1756 | }\r | |
1757 | \r | |
e48e37fc | 1758 | ZeroMem (PacketOptionList, *OptionCount * sizeof (EFI_DHCP4_PACKET_OPTION *));\r |
772db4bb | 1759 | \r |
1760 | Context.Option = PacketOptionList;\r | |
1761 | Context.OptionCount = *OptionCount;\r | |
1762 | Context.Index = 0;\r | |
1763 | \r | |
1764 | Status = DhcpIterateOptions (Packet, Dhcp4ParseCheckOption, &Context);\r | |
1765 | \r | |
1766 | if (EFI_ERROR (Status)) {\r | |
1767 | return Status;\r | |
1768 | }\r | |
1769 | \r | |
1770 | *OptionCount = Context.Index;\r | |
1771 | \r | |
1772 | if (Context.Index > Context.OptionCount) {\r | |
1773 | return EFI_BUFFER_TOO_SMALL;\r | |
1774 | }\r | |
1775 | \r | |
1776 | return EFI_SUCCESS;\r | |
1777 | }\r | |
842d83d6 | 1778 | \r |
1779 | /**\r | |
1780 | Set the elapsed time based on the given instance and the pointer to the\r | |
1781 | elapsed time option.\r | |
1782 | \r | |
1783 | @param[in] Elapsed The pointer to the position to append.\r | |
1784 | @param[in] Instance The pointer to the Dhcp4 instance.\r | |
1785 | **/\r | |
1786 | VOID\r | |
1787 | SetElapsedTime (\r | |
1788 | IN UINT16 *Elapsed,\r | |
1789 | IN DHCP_PROTOCOL *Instance\r | |
1790 | )\r | |
1791 | {\r | |
1792 | WriteUnaligned16 (Elapsed, HTONS(Instance->ElaspedTime));\r | |
1793 | }\r |