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