]>
Commit | Line | Data |
---|---|---|
b2570da8 | 1 | /** @file\r |
402fa70f | 2 | This code implements the IP4Config and NicIp4Config protocols.\r |
b2570da8 | 3 | \r |
d80ea739 | 4 | Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r |
b2570da8 | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
402fa70f | 7 | which accompanies this distribution. The full text of the license may be found at<BR>\r |
b2570da8 | 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 | |
b2570da8 | 13 | **/\r |
14 | \r | |
15 | #include "Ip4Config.h"\r | |
16 | \r | |
17 | IP4_CONFIG_INSTANCE *mIp4ConfigNicList[MAX_IP4_CONFIG_IN_VARIABLE];\r | |
18 | \r | |
b2570da8 | 19 | \r |
20 | /**\r | |
c8d8f1e3 | 21 | Get the NIC's configure information from the IP4 configure variable.\r |
b2570da8 | 22 | It will remove the invalid variable.\r |
23 | \r | |
24 | @param NicAddr The NIC to check\r | |
25 | \r | |
26 | @return NULL if no configure for the NIC in the variable, or it is invalid.\r | |
c8d8f1e3 | 27 | Otherwise the pointer to the NIC's IP configure parameter will be returned.\r |
b2570da8 | 28 | \r |
29 | **/\r | |
30 | NIC_IP4_CONFIG_INFO *\r | |
31 | Ip4ConfigGetNicInfo (\r | |
32 | IN NIC_ADDR *NicAddr\r | |
33 | )\r | |
34 | {\r | |
35 | IP4_CONFIG_VARIABLE *Variable;\r | |
36 | IP4_CONFIG_VARIABLE *NewVariable;\r | |
37 | NIC_IP4_CONFIG_INFO *Config;\r | |
38 | \r | |
39 | //\r | |
40 | // Read the configuration parameter for this NicAddr from\r | |
41 | // the EFI variable\r | |
42 | //\r | |
43 | Variable = Ip4ConfigReadVariable ();\r | |
44 | \r | |
45 | if (Variable == NULL) {\r | |
46 | return NULL;\r | |
47 | }\r | |
48 | \r | |
49 | Config = Ip4ConfigFindNicVariable (Variable, NicAddr);\r | |
50 | \r | |
51 | if (Config == NULL) {\r | |
766c7483 | 52 | FreePool (Variable);\r |
b2570da8 | 53 | return NULL;\r |
54 | }\r | |
55 | \r | |
56 | //\r | |
57 | // Validate the configuration, if the configuration is invalid,\r | |
58 | // remove it from the variable.\r | |
59 | //\r | |
60 | if (!Ip4ConfigIsValid (Config)) {\r | |
61 | NewVariable = Ip4ConfigModifyVariable (Variable, &Config->NicAddr, NULL);\r | |
62 | Ip4ConfigWriteVariable (NewVariable);\r | |
63 | \r | |
64 | if (NewVariable != NULL) {\r | |
766c7483 | 65 | FreePool (NewVariable);\r |
b2570da8 | 66 | };\r |
67 | \r | |
766c7483 | 68 | FreePool (Config);\r |
b2570da8 | 69 | Config = NULL;\r |
70 | }\r | |
71 | \r | |
766c7483 | 72 | FreePool (Variable);\r |
b2570da8 | 73 | return Config;\r |
74 | }\r | |
75 | \r | |
76 | \r | |
77 | /**\r | |
78 | Get the configure parameter for this NIC.\r | |
79 | \r | |
63886849 | 80 | @param Instance The IP4 CONFIG Instance.\r |
b2570da8 | 81 | @param ConfigLen The length of the NicConfig buffer.\r |
82 | @param NicConfig The buffer to receive the NIC's configure\r | |
83 | parameter.\r | |
84 | \r | |
d80ea739 | 85 | @retval EFI_SUCCESS The configure parameter for this NIC was\r |
c8d8f1e3 | 86 | obtained successfully .\r |
87 | @retval EFI_INVALID_PARAMETER This or ConfigLen is NULL.\r | |
b2570da8 | 88 | @retval EFI_NOT_FOUND There is no configure parameter for the NIC in\r |
89 | NVRam.\r | |
d80ea739 | 90 | @retval EFI_BUFFER_TOO_SMALL The ConfigLen is too small or the NicConfig is\r |
c8d8f1e3 | 91 | NULL.\r |
b2570da8 | 92 | \r |
93 | **/\r | |
94 | EFI_STATUS\r | |
95 | EFIAPI\r | |
96 | EfiNicIp4ConfigGetInfo (\r | |
63886849 | 97 | IN IP4_CONFIG_INSTANCE *Instance,\r |
b2570da8 | 98 | IN OUT UINTN *ConfigLen,\r |
99 | OUT NIC_IP4_CONFIG_INFO *NicConfig\r | |
100 | )\r | |
101 | {\r | |
b2570da8 | 102 | NIC_IP4_CONFIG_INFO *Config;\r |
103 | EFI_STATUS Status;\r | |
104 | UINTN Len;\r | |
105 | \r | |
63886849 | 106 | if ((Instance == NULL) || (ConfigLen == NULL)) {\r |
b2570da8 | 107 | return EFI_INVALID_PARAMETER;\r |
108 | }\r | |
109 | \r | |
110 | //\r | |
111 | // Read the Nic's configuration parameter from variable\r | |
112 | //\r | |
b2570da8 | 113 | Config = Ip4ConfigGetNicInfo (&Instance->NicAddr);\r |
114 | \r | |
115 | if (Config == NULL) {\r | |
116 | return EFI_NOT_FOUND;\r | |
117 | }\r | |
118 | \r | |
119 | //\r | |
120 | // Copy the data to user's buffer\r | |
121 | //\r | |
122 | Len = SIZEOF_NIC_IP4_CONFIG_INFO (Config);\r | |
123 | \r | |
124 | if ((*ConfigLen < Len) || (NicConfig == NULL)) {\r | |
125 | Status = EFI_BUFFER_TOO_SMALL;\r | |
126 | } else {\r | |
127 | Status = EFI_SUCCESS;\r | |
e48e37fc | 128 | CopyMem (NicConfig, Config, Len);\r |
7659d0c9 | 129 | Ip4ConfigFixRouteTablePointer (&NicConfig->Ip4Info);\r |
b2570da8 | 130 | }\r |
131 | \r | |
132 | *ConfigLen = Len;\r | |
133 | \r | |
766c7483 | 134 | FreePool (Config);\r |
b2570da8 | 135 | return Status;\r |
136 | }\r | |
137 | \r | |
138 | \r | |
139 | /**\r | |
d80ea739 | 140 | Set the IP configure parameters for this NIC.\r |
c8d8f1e3 | 141 | \r |
d80ea739 | 142 | If Reconfig is TRUE, the IP driver will be informed to discard current\r |
143 | auto configure parameter and restart the auto configuration process.\r | |
c8d8f1e3 | 144 | If current there is a pending auto configuration, EFI_ALREADY_STARTED is\r |
b2570da8 | 145 | returned. You can only change the configure setting when either\r |
146 | the configure has finished or not started yet. If NicConfig, the\r | |
147 | NIC's configure parameter is removed from the variable.\r | |
148 | \r | |
63886849 | 149 | @param Instance The IP4 CONFIG instance.\r |
d80ea739 | 150 | @param NicConfig The new NIC IP4 configure parameter.\r |
b2570da8 | 151 | @param Reconfig Inform the IP4 driver to restart the auto\r |
d80ea739 | 152 | configuration.\r |
153 | \r | |
154 | @retval EFI_SUCCESS The configure parameter for this NIC was\r | |
155 | set successfully.\r | |
b2570da8 | 156 | @retval EFI_INVALID_PARAMETER This is NULL or the configure parameter is\r |
157 | invalid.\r | |
158 | @retval EFI_ALREADY_STARTED There is a pending auto configuration.\r | |
d80ea739 | 159 | @retval EFI_NOT_FOUND No auto configure parameter is found.\r |
b2570da8 | 160 | \r |
161 | **/\r | |
162 | EFI_STATUS\r | |
163 | EFIAPI\r | |
164 | EfiNicIp4ConfigSetInfo (\r | |
63886849 | 165 | IN IP4_CONFIG_INSTANCE *Instance,\r |
3e8c18da | 166 | IN NIC_IP4_CONFIG_INFO *NicConfig OPTIONAL,\r |
b2570da8 | 167 | IN BOOLEAN Reconfig\r |
168 | )\r | |
169 | {\r | |
b2570da8 | 170 | IP4_CONFIG_VARIABLE *Variable;\r |
171 | IP4_CONFIG_VARIABLE *NewVariable;\r | |
172 | EFI_STATUS Status;\r | |
173 | \r | |
174 | //\r | |
175 | // Validate the parameters\r | |
176 | //\r | |
63886849 | 177 | if (Instance == NULL) {\r |
b2570da8 | 178 | return EFI_INVALID_PARAMETER;\r |
179 | }\r | |
180 | \r | |
b2570da8 | 181 | if ((NicConfig != NULL) && (!Ip4ConfigIsValid (NicConfig) ||\r |
182 | !NIC_ADDR_EQUAL (&NicConfig->NicAddr, &Instance->NicAddr))) {\r | |
183 | return EFI_INVALID_PARAMETER;\r | |
184 | }\r | |
185 | \r | |
186 | if (Instance->State == IP4_CONFIG_STATE_STARTED) {\r | |
187 | return EFI_ALREADY_STARTED;\r | |
188 | }\r | |
189 | \r | |
190 | //\r | |
191 | // Update the parameter in the configure variable\r | |
192 | //\r | |
193 | Variable = Ip4ConfigReadVariable ();\r | |
194 | \r | |
195 | if ((Variable == NULL) && (NicConfig == NULL)) {\r | |
196 | return EFI_NOT_FOUND;\r | |
197 | }\r | |
198 | \r | |
199 | NewVariable = Ip4ConfigModifyVariable (Variable, &Instance->NicAddr, NicConfig);\r | |
200 | Status = Ip4ConfigWriteVariable (NewVariable);\r | |
201 | \r | |
202 | if (NewVariable != NULL) {\r | |
766c7483 | 203 | FreePool (NewVariable);\r |
b2570da8 | 204 | }\r |
205 | \r | |
206 | //\r | |
207 | // Variable is NULL when saving the first configure parameter\r | |
208 | //\r | |
209 | if (Variable != NULL) {\r | |
766c7483 | 210 | FreePool (Variable);\r |
b2570da8 | 211 | }\r |
212 | \r | |
213 | if (EFI_ERROR (Status)) {\r | |
214 | return Status;\r | |
215 | }\r | |
216 | \r | |
217 | //\r | |
218 | // Signal the IP4 to run the auto configuration again\r | |
219 | //\r | |
220 | if (Reconfig && (Instance->ReconfigEvent != NULL)) {\r | |
221 | Status = gBS->SignalEvent (Instance->ReconfigEvent);\r | |
d8d26fb2 | 222 | DispatchDpc ();\r |
b2570da8 | 223 | }\r |
224 | \r | |
225 | return Status;\r | |
226 | }\r | |
227 | \r | |
c8d8f1e3 | 228 | /**\r |
229 | Callback function when DHCP process finished. It will save the\r | |
230 | retrieved IP configure parameter from DHCP to the NVRam.\r | |
231 | \r | |
232 | @param Event The callback event\r | |
233 | @param Context Opaque context to the callback\r | |
234 | \r | |
235 | @return None\r | |
236 | \r | |
237 | **/\r | |
238 | VOID\r | |
239 | EFIAPI\r | |
240 | Ip4ConfigOnDhcp4Complete (\r | |
241 | IN EFI_EVENT Event,\r | |
242 | IN VOID *Context\r | |
243 | )\r | |
244 | {\r | |
245 | IP4_CONFIG_INSTANCE *Instance;\r | |
246 | EFI_DHCP4_MODE_DATA Dhcp4Mode;\r | |
247 | EFI_IP4_IPCONFIG_DATA *Ip4Config;\r | |
248 | EFI_STATUS Status;\r | |
249 | BOOLEAN Perment;\r | |
250 | IP4_ADDR Subnet;\r | |
251 | IP4_ADDR Ip1;\r | |
252 | IP4_ADDR Ip2;\r | |
253 | \r | |
254 | Instance = (IP4_CONFIG_INSTANCE *) Context;\r | |
255 | ASSERT (Instance->Dhcp4 != NULL);\r | |
256 | \r | |
257 | Instance->State = IP4_CONFIG_STATE_CONFIGURED;\r | |
258 | Instance->Result = EFI_TIMEOUT;\r | |
259 | \r | |
260 | //\r | |
261 | // Get the DHCP retrieved parameters\r | |
262 | //\r | |
263 | Status = Instance->Dhcp4->GetModeData (Instance->Dhcp4, &Dhcp4Mode);\r | |
264 | \r | |
265 | if (EFI_ERROR (Status)) {\r | |
266 | goto ON_EXIT;\r | |
267 | }\r | |
268 | \r | |
269 | if (Dhcp4Mode.State == Dhcp4Bound) {\r | |
270 | //\r | |
271 | // Save the new configuration retrieved by DHCP both in\r | |
272 | // the instance and to NVRam. So, both the IP4 driver and\r | |
273 | // other user can get that address.\r | |
274 | //\r | |
275 | Perment = FALSE;\r | |
276 | \r | |
277 | if (Instance->NicConfig != NULL) {\r | |
278 | ASSERT (Instance->NicConfig->Source == IP4_CONFIG_SOURCE_DHCP);\r | |
279 | Perment = Instance->NicConfig->Perment;\r | |
766c7483 | 280 | FreePool (Instance->NicConfig);\r |
c8d8f1e3 | 281 | }\r |
282 | \r | |
283 | Instance->NicConfig = AllocatePool (sizeof (NIC_IP4_CONFIG_INFO) + 2* sizeof (EFI_IP4_ROUTE_TABLE));\r | |
284 | \r | |
285 | if (Instance->NicConfig == NULL) {\r | |
286 | Instance->Result = EFI_OUT_OF_RESOURCES;\r | |
287 | goto ON_EXIT;\r | |
288 | }\r | |
289 | \r | |
290 | Instance->NicConfig->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (Instance->NicConfig + 1);\r | |
291 | \r | |
292 | CopyMem (&Instance->NicConfig->NicAddr, &Instance->NicAddr, sizeof (Instance->NicConfig->NicAddr));\r | |
293 | Instance->NicConfig->Source = IP4_CONFIG_SOURCE_DHCP;\r | |
294 | Instance->NicConfig->Perment = Perment;\r | |
295 | \r | |
296 | Ip4Config = &Instance->NicConfig->Ip4Info;\r | |
297 | Ip4Config->StationAddress = Dhcp4Mode.ClientAddress;\r | |
298 | Ip4Config->SubnetMask = Dhcp4Mode.SubnetMask;\r | |
299 | \r | |
300 | //\r | |
301 | // Create a route for the connected network\r | |
302 | //\r | |
303 | Ip4Config->RouteTableSize = 1;\r | |
304 | \r | |
305 | CopyMem (&Ip1, &Dhcp4Mode.ClientAddress, sizeof (IP4_ADDR));\r | |
306 | CopyMem (&Ip2, &Dhcp4Mode.SubnetMask, sizeof (IP4_ADDR));\r | |
307 | \r | |
308 | Subnet = Ip1 & Ip2;\r | |
309 | \r | |
310 | CopyMem (&Ip4Config->RouteTable[0].SubnetAddress, &Subnet, sizeof (EFI_IPv4_ADDRESS));\r | |
311 | CopyMem (&Ip4Config->RouteTable[0].SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
312 | ZeroMem (&Ip4Config->RouteTable[0].GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
313 | \r | |
314 | //\r | |
315 | // Create a route if there is a default router.\r | |
316 | //\r | |
317 | if (!EFI_IP4_EQUAL (&Dhcp4Mode.RouterAddress, &mZeroIp4Addr)) {\r | |
318 | Ip4Config->RouteTableSize = 2;\r | |
319 | \r | |
320 | ZeroMem (&Ip4Config->RouteTable[1].SubnetAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
321 | ZeroMem (&Ip4Config->RouteTable[1].SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
322 | CopyMem (&Ip4Config->RouteTable[1].GatewayAddress, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
323 | }\r | |
324 | \r | |
325 | Instance->Result = EFI_SUCCESS;\r | |
326 | \r | |
327 | //\r | |
328 | // ignore the return status of EfiNicIp4ConfigSetInfo. Network\r | |
329 | // stack can operate even that failed.\r | |
330 | //\r | |
63886849 | 331 | EfiNicIp4ConfigSetInfo (Instance, Instance->NicConfig, FALSE);\r |
c8d8f1e3 | 332 | }\r |
333 | \r | |
334 | ON_EXIT:\r | |
335 | gBS->SignalEvent (Instance->DoneEvent);\r | |
336 | Ip4ConfigCleanDhcp4 (Instance);\r | |
337 | \r | |
d8d26fb2 | 338 | DispatchDpc ();\r |
c8d8f1e3 | 339 | \r |
340 | return ;\r | |
341 | }\r | |
b2570da8 | 342 | \r |
343 | /**\r | |
402fa70f | 344 | Starts running the configuration policy for the EFI IPv4 Protocol driver.\r |
d80ea739 | 345 | \r |
346 | The Start() function is called to determine and to begin the platform\r | |
347 | configuration policy by the EFI IPv4 Protocol driver. This determination may\r | |
348 | be as simple as returning EFI_UNSUPPORTED if there is no EFI IPv4 Protocol\r | |
349 | driver configuration policy. It may be as involved as loading some defaults\r | |
350 | from nonvolatile storage, downloading dynamic data from a DHCP server, and\r | |
402fa70f | 351 | checking permissions with a site policy server.\r |
d80ea739 | 352 | Starting the configuration policy is just the beginning. It may finish almost\r |
353 | instantly or it may take several minutes before it fails to retrieve configuration\r | |
354 | information from one or more servers. Once the policy is started, drivers\r | |
355 | should use the DoneEvent parameter to determine when the configuration policy\r | |
356 | has completed. EFI_IP4_CONFIG_PROTOCOL.GetData() must then be called to\r | |
402fa70f | 357 | determine if the configuration succeeded or failed.\r |
d80ea739 | 358 | Until the configuration completes successfully, EFI IPv4 Protocol driver instances\r |
402fa70f | 359 | that are attempting to use default configurations must return EFI_NO_MAPPING.\r |
d80ea739 | 360 | Once the configuration is complete, the EFI IPv4 Configuration Protocol driver\r |
361 | signals DoneEvent. The configuration may need to be updated in the future,\r | |
362 | however; in this case, the EFI IPv4 Configuration Protocol driver must signal\r | |
363 | ReconfigEvent, and all EFI IPv4 Protocol driver instances that are using default\r | |
364 | configurations must return EFI_NO_MAPPING until the configuration policy has\r | |
402fa70f | 365 | been rerun.\r |
366 | \r | |
367 | @param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.\r | |
d80ea739 | 368 | @param DoneEvent Event that will be signaled when the EFI IPv4\r |
369 | Protocol driver configuration policy completes\r | |
402fa70f | 370 | execution. This event must be of type EVT_NOTIFY_SIGNAL.\r |
d80ea739 | 371 | @param ReconfigEvent Event that will be signaled when the EFI IPv4\r |
372 | Protocol driver configuration needs to be updated.\r | |
402fa70f | 373 | This event must be of type EVT_NOTIFY_SIGNAL.\r |
d80ea739 | 374 | \r |
375 | @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol\r | |
402fa70f | 376 | driver is now running.\r |
377 | @retval EFI_INVALID_PARAMETER One or more of the following parameters is NULL:\r | |
378 | This\r | |
379 | DoneEvent\r | |
380 | ReconfigEvent\r | |
381 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
d80ea739 | 382 | @retval EFI_ALREADY_STARTED The configuration policy for the EFI IPv4 Protocol\r |
402fa70f | 383 | driver was already started.\r |
384 | @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.\r | |
d80ea739 | 385 | @retval EFI_UNSUPPORTED This interface does not support the EFI IPv4 Protocol\r |
402fa70f | 386 | driver configuration.\r |
b2570da8 | 387 | \r |
388 | **/\r | |
389 | EFI_STATUS\r | |
390 | EFIAPI\r | |
391 | EfiIp4ConfigStart (\r | |
392 | IN EFI_IP4_CONFIG_PROTOCOL *This,\r | |
393 | IN EFI_EVENT DoneEvent,\r | |
394 | IN EFI_EVENT ReconfigEvent\r | |
395 | )\r | |
396 | {\r | |
397 | IP4_CONFIG_INSTANCE *Instance;\r | |
398 | EFI_DHCP4_PROTOCOL *Dhcp4;\r | |
399 | EFI_DHCP4_MODE_DATA Dhcp4Mode;\r | |
400 | EFI_DHCP4_PACKET_OPTION *OptionList[1];\r | |
401 | IP4_CONFIG_DHCP4_OPTION ParaList;\r | |
402 | EFI_STATUS Status;\r | |
403 | UINT32 Source;\r | |
404 | EFI_TPL OldTpl;\r | |
405 | \r | |
406 | if ((This == NULL) || (DoneEvent == NULL) || (ReconfigEvent == NULL)) {\r | |
407 | return EFI_INVALID_PARAMETER;\r | |
408 | }\r | |
409 | \r | |
410 | Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (This);\r | |
411 | \r | |
e48e37fc | 412 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
b2570da8 | 413 | \r |
414 | if (Instance->State != IP4_CONFIG_STATE_IDLE) {\r | |
415 | Status = EFI_ALREADY_STARTED;\r | |
416 | \r | |
417 | goto ON_EXIT;\r | |
418 | }\r | |
419 | \r | |
420 | Instance->DoneEvent = DoneEvent;\r | |
421 | Instance->ReconfigEvent = ReconfigEvent;\r | |
422 | \r | |
423 | Instance->NicConfig = Ip4ConfigGetNicInfo (&Instance->NicAddr);\r | |
424 | \r | |
425 | if (Instance->NicConfig == NULL) {\r | |
426 | Source = IP4_CONFIG_SOURCE_DHCP;\r | |
427 | } else {\r | |
428 | Source = Instance->NicConfig->Source;\r | |
429 | }\r | |
430 | \r | |
431 | //\r | |
432 | // If the source is static, the auto configuration is done.\r | |
433 | // return now.\r | |
434 | //\r | |
435 | if (Source == IP4_CONFIG_SOURCE_STATIC) {\r | |
436 | Instance->State = IP4_CONFIG_STATE_CONFIGURED;\r | |
437 | Instance->Result = EFI_SUCCESS;\r | |
438 | \r | |
439 | gBS->SignalEvent (Instance->DoneEvent);\r | |
440 | Status = EFI_SUCCESS;\r | |
441 | goto ON_EXIT;\r | |
442 | }\r | |
443 | \r | |
444 | //\r | |
445 | // Start the dhcp process\r | |
446 | //\r | |
447 | ASSERT ((Source == IP4_CONFIG_SOURCE_DHCP) && (Instance->Dhcp4 == NULL));\r | |
448 | \r | |
449 | Status = NetLibCreateServiceChild (\r | |
450 | Instance->Controller,\r | |
451 | Instance->Image,\r | |
452 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
453 | &Instance->Dhcp4Handle\r | |
454 | );\r | |
455 | \r | |
456 | if (EFI_ERROR (Status)) {\r | |
457 | goto ON_ERROR;\r | |
458 | }\r | |
459 | \r | |
460 | Status = gBS->OpenProtocol (\r | |
461 | Instance->Dhcp4Handle,\r | |
462 | &gEfiDhcp4ProtocolGuid,\r | |
463 | (VOID **) &Instance->Dhcp4,\r | |
464 | Instance->Image,\r | |
465 | Instance->Controller,\r | |
466 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
467 | );\r | |
468 | \r | |
469 | if (EFI_ERROR (Status)) {\r | |
470 | goto ON_ERROR;\r | |
471 | }\r | |
472 | \r | |
473 | //\r | |
474 | // Check the current DHCP status, if the DHCP process has\r | |
475 | // already finished, return now.\r | |
476 | //\r | |
477 | Dhcp4 = Instance->Dhcp4;\r | |
478 | Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r | |
479 | \r | |
480 | if (EFI_ERROR (Status)) {\r | |
481 | goto ON_ERROR;\r | |
482 | }\r | |
483 | \r | |
484 | if (Dhcp4Mode.State == Dhcp4Bound) {\r | |
485 | Ip4ConfigOnDhcp4Complete (NULL, Instance);\r | |
486 | \r | |
487 | goto ON_EXIT;\r | |
488 | }\r | |
489 | \r | |
490 | //\r | |
491 | // Try to start the DHCP process. Use most of the current\r | |
492 | // DHCP configuration to avoid problems if some DHCP client\r | |
493 | // yields the control of this DHCP service to us.\r | |
494 | //\r | |
495 | ParaList.Head.OpCode = DHCP_TAG_PARA_LIST;\r | |
496 | ParaList.Head.Length = 2;\r | |
497 | ParaList.Head.Data[0] = DHCP_TAG_NETMASK;\r | |
498 | ParaList.Route = DHCP_TAG_ROUTER;\r | |
499 | OptionList[0] = &ParaList.Head;\r | |
500 | Dhcp4Mode.ConfigData.OptionCount = 1;\r | |
501 | Dhcp4Mode.ConfigData.OptionList = OptionList;\r | |
502 | \r | |
503 | Status = Dhcp4->Configure (Dhcp4, &Dhcp4Mode.ConfigData);\r | |
504 | \r | |
505 | if (EFI_ERROR (Status)) {\r | |
506 | goto ON_ERROR;\r | |
507 | }\r | |
508 | \r | |
509 | //\r | |
510 | // Start the DHCP process\r | |
511 | //\r | |
512 | Status = gBS->CreateEvent (\r | |
513 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 514 | TPL_CALLBACK,\r |
b2570da8 | 515 | Ip4ConfigOnDhcp4Complete,\r |
516 | Instance,\r | |
517 | &Instance->Dhcp4Event\r | |
518 | );\r | |
519 | \r | |
520 | if (EFI_ERROR (Status)) {\r | |
521 | goto ON_ERROR;\r | |
522 | }\r | |
523 | \r | |
524 | Status = Dhcp4->Start (Dhcp4, Instance->Dhcp4Event);\r | |
525 | \r | |
526 | if (EFI_ERROR (Status)) {\r | |
527 | goto ON_ERROR;\r | |
528 | }\r | |
529 | \r | |
530 | Instance->State = IP4_CONFIG_STATE_STARTED;\r | |
531 | Instance->Result = EFI_NOT_READY;\r | |
532 | \r | |
533 | ON_ERROR:\r | |
534 | if (EFI_ERROR (Status)) {\r | |
535 | Ip4ConfigCleanConfig (Instance);\r | |
536 | }\r | |
537 | \r | |
538 | ON_EXIT:\r | |
e48e37fc | 539 | gBS->RestoreTPL (OldTpl);\r |
b2570da8 | 540 | \r |
d8d26fb2 | 541 | DispatchDpc ();\r |
7659d0c9 | 542 | \r |
b2570da8 | 543 | return Status;\r |
544 | }\r | |
545 | \r | |
546 | \r | |
547 | /**\r | |
402fa70f | 548 | Stops running the configuration policy for the EFI IPv4 Protocol driver.\r |
d80ea739 | 549 | \r |
550 | The Stop() function stops the configuration policy for the EFI IPv4 Protocol driver.\r | |
402fa70f | 551 | All configuration data will be lost after calling Stop().\r |
b2570da8 | 552 | \r |
402fa70f | 553 | @param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.\r |
b2570da8 | 554 | \r |
d80ea739 | 555 | @retval EFI_SUCCESS The configuration policy for the EFI IPv4 Protocol\r |
402fa70f | 556 | driver has been stopped.\r |
b2570da8 | 557 | @retval EFI_INVALID_PARAMETER This is NULL.\r |
d80ea739 | 558 | @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol\r |
402fa70f | 559 | driver was not started.\r |
d80ea739 | 560 | \r |
b2570da8 | 561 | **/\r |
562 | EFI_STATUS\r | |
563 | EFIAPI\r | |
564 | EfiIp4ConfigStop (\r | |
565 | IN EFI_IP4_CONFIG_PROTOCOL *This\r | |
566 | )\r | |
567 | {\r | |
568 | IP4_CONFIG_INSTANCE *Instance;\r | |
569 | EFI_STATUS Status;\r | |
570 | EFI_TPL OldTpl;\r | |
571 | \r | |
572 | if (This == NULL) {\r | |
573 | return EFI_INVALID_PARAMETER;\r | |
574 | }\r | |
575 | \r | |
576 | Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (This);\r | |
577 | \r | |
578 | Status = EFI_SUCCESS;\r | |
e48e37fc | 579 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
b2570da8 | 580 | \r |
581 | if (Instance->State == IP4_CONFIG_STATE_IDLE) {\r | |
582 | Status = EFI_NOT_STARTED;\r | |
583 | goto ON_EXIT;\r | |
584 | }\r | |
585 | \r | |
586 | //\r | |
587 | // Release all the configure parameters. Don't signal the user\r | |
588 | // event. The user wants to abort the configuration, this isn't\r | |
589 | // the configuration done or reconfiguration.\r | |
590 | //\r | |
591 | Ip4ConfigCleanConfig (Instance);\r | |
592 | \r | |
593 | ON_EXIT:\r | |
e48e37fc | 594 | gBS->RestoreTPL (OldTpl);\r |
b2570da8 | 595 | \r |
596 | return Status;\r | |
597 | }\r | |
598 | \r | |
599 | \r | |
600 | /**\r | |
402fa70f | 601 | Returns the default configuration data (if any) for the EFI IPv4 Protocol driver.\r |
602 | \r | |
d80ea739 | 603 | The GetData() function returns the current configuration data for the EFI IPv4\r |
402fa70f | 604 | Protocol driver after the configuration policy has completed.\r |
d80ea739 | 605 | \r |
402fa70f | 606 | @param This Pointer to the EFI_IP4_CONFIG_PROTOCOL instance.\r |
d80ea739 | 607 | @param ConfigDataSize On input, the size of the ConfigData buffer.\r |
608 | On output, the count of bytes that were written\r | |
402fa70f | 609 | into the ConfigData buffer.\r |
d80ea739 | 610 | @param ConfigData Pointer to the EFI IPv4 Configuration Protocol\r |
611 | driver configuration data structure.\r | |
612 | Type EFI_IP4_IPCONFIG_DATA is defined in\r | |
402fa70f | 613 | "Related Definitions" below.\r |
614 | \r | |
615 | @retval EFI_SUCCESS The EFI IPv4 Protocol driver configuration has been returned.\r | |
616 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
d80ea739 | 617 | @retval EFI_NOT_STARTED The configuration policy for the EFI IPv4 Protocol\r |
402fa70f | 618 | driver is not running.\r |
c8d8f1e3 | 619 | @retval EFI_NOT_READY EFI IPv4 Protocol driver configuration is still running.\r |
620 | @retval EFI_ABORTED EFI IPv4 Protocol driver configuration could not complete.\r | |
621 | Currently not implemented.\r | |
d80ea739 | 622 | @retval EFI_BUFFER_TOO_SMALL *ConfigDataSize is smaller than the configuration\r |
402fa70f | 623 | data buffer or ConfigData is NULL.\r |
b2570da8 | 624 | \r |
625 | **/\r | |
626 | EFI_STATUS\r | |
627 | EFIAPI\r | |
628 | EfiIp4ConfigGetData (\r | |
629 | IN EFI_IP4_CONFIG_PROTOCOL *This,\r | |
630 | IN OUT UINTN *ConfigDataSize,\r | |
631 | OUT EFI_IP4_IPCONFIG_DATA *ConfigData OPTIONAL\r | |
632 | )\r | |
633 | {\r | |
634 | IP4_CONFIG_INSTANCE *Instance;\r | |
635 | NIC_IP4_CONFIG_INFO *NicConfig;\r | |
636 | EFI_STATUS Status;\r | |
637 | EFI_TPL OldTpl;\r | |
638 | UINTN Len;\r | |
639 | \r | |
640 | if ((This == NULL) || (ConfigDataSize == NULL)) {\r | |
641 | return EFI_INVALID_PARAMETER;\r | |
642 | }\r | |
643 | \r | |
644 | Instance = IP4_CONFIG_INSTANCE_FROM_IP4CONFIG (This);\r | |
645 | \r | |
646 | Status = EFI_SUCCESS;\r | |
e48e37fc | 647 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
b2570da8 | 648 | \r |
649 | if (Instance->State == IP4_CONFIG_STATE_IDLE) {\r | |
650 | Status = EFI_NOT_STARTED;\r | |
651 | } else if (Instance->State == IP4_CONFIG_STATE_STARTED) {\r | |
652 | Status = EFI_NOT_READY;\r | |
653 | }\r | |
654 | \r | |
655 | if (EFI_ERROR (Status)) {\r | |
656 | goto ON_EXIT;\r | |
657 | }\r | |
658 | \r | |
659 | //\r | |
660 | // Copy the configure data if auto configuration succeeds.\r | |
661 | //\r | |
662 | Status = Instance->Result;\r | |
663 | \r | |
664 | if (Status == EFI_SUCCESS) {\r | |
665 | ASSERT (Instance->NicConfig != NULL);\r | |
666 | \r | |
667 | NicConfig = Instance->NicConfig;\r | |
668 | Len = SIZEOF_IP4_CONFIG_INFO (&NicConfig->Ip4Info);\r | |
669 | \r | |
670 | if ((*ConfigDataSize < Len) || (ConfigData == NULL)) {\r | |
671 | Status = EFI_BUFFER_TOO_SMALL;\r | |
672 | } else {\r | |
e48e37fc | 673 | CopyMem (ConfigData, &NicConfig->Ip4Info, Len);\r |
7659d0c9 | 674 | Ip4ConfigFixRouteTablePointer (ConfigData);\r |
b2570da8 | 675 | }\r |
676 | \r | |
677 | *ConfigDataSize = Len;\r | |
678 | }\r | |
679 | \r | |
680 | ON_EXIT:\r | |
e48e37fc | 681 | gBS->RestoreTPL (OldTpl);\r |
b2570da8 | 682 | \r |
683 | return Status;\r | |
684 | }\r | |
685 | \r | |
b2570da8 | 686 | /**\r |
687 | Release all the DHCP related resources.\r | |
688 | \r | |
689 | @param This The IP4 configure instance\r | |
690 | \r | |
691 | @return None\r | |
692 | \r | |
693 | **/\r | |
694 | VOID\r | |
695 | Ip4ConfigCleanDhcp4 (\r | |
696 | IN IP4_CONFIG_INSTANCE *This\r | |
697 | )\r | |
698 | {\r | |
699 | if (This->Dhcp4 != NULL) {\r | |
700 | This->Dhcp4->Stop (This->Dhcp4);\r | |
701 | \r | |
702 | gBS->CloseProtocol (\r | |
703 | This->Dhcp4Handle,\r | |
704 | &gEfiDhcp4ProtocolGuid,\r | |
705 | This->Image,\r | |
706 | This->Controller\r | |
707 | );\r | |
708 | \r | |
709 | This->Dhcp4 = NULL;\r | |
710 | }\r | |
711 | \r | |
712 | if (This->Dhcp4Handle != NULL) {\r | |
713 | NetLibDestroyServiceChild (\r | |
714 | This->Controller,\r | |
715 | This->Image,\r | |
716 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
717 | This->Dhcp4Handle\r | |
718 | );\r | |
719 | \r | |
720 | This->Dhcp4Handle = NULL;\r | |
721 | }\r | |
722 | \r | |
723 | if (This->Dhcp4Event == NULL) {\r | |
724 | gBS->CloseEvent (This->Dhcp4Event);\r | |
725 | This->Dhcp4Event = NULL;\r | |
726 | }\r | |
727 | }\r | |
728 | \r | |
729 | \r | |
730 | /**\r | |
7bce0c5a | 731 | Clean up all the configuration parameters.\r |
b2570da8 | 732 | \r |
733 | @param Instance The IP4 configure instance\r | |
734 | \r | |
735 | @return None\r | |
736 | \r | |
737 | **/\r | |
738 | VOID\r | |
739 | Ip4ConfigCleanConfig (\r | |
740 | IN IP4_CONFIG_INSTANCE *Instance\r | |
741 | )\r | |
742 | {\r | |
743 | if (Instance->NicConfig != NULL) {\r | |
766c7483 | 744 | FreePool (Instance->NicConfig);\r |
b2570da8 | 745 | Instance->NicConfig = NULL;\r |
746 | }\r | |
747 | \r | |
748 | Instance->State = IP4_CONFIG_STATE_IDLE;\r | |
749 | Instance->DoneEvent = NULL;\r | |
750 | Instance->ReconfigEvent = NULL;\r | |
751 | \r | |
752 | Ip4ConfigCleanDhcp4 (Instance);\r | |
753 | }\r | |
754 | \r | |
755 | EFI_IP4_CONFIG_PROTOCOL mIp4ConfigProtocolTemplate = {\r | |
756 | EfiIp4ConfigStart,\r | |
757 | EfiIp4ConfigStop,\r | |
758 | EfiIp4ConfigGetData\r | |
759 | };\r | |
760 | \r |