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