]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
2da4a513495e138512d5f7c440ca73279edb593b
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Config2Impl.c
1 /** @file
2 The implementation of EFI IPv4 Configuration II Protocol.
3
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "Ip4Impl.h"
17
18 LIST_ENTRY mIp4Config2InstanceList = {&mIp4Config2InstanceList, &mIp4Config2InstanceList};
19
20 /**
21 The event process routine when the DHCPv4 service binding protocol is installed
22 in the system.
23
24 @param[in] Event Not used.
25 @param[in] Context Pointer to the IP4 config2 instance data.
26
27 **/
28 VOID
29 EFIAPI
30 Ip4Config2OnDhcp4SbInstalled (
31 IN EFI_EVENT Event,
32 IN VOID *Context
33 );
34
35 /**
36 Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.
37
38 @param[in, out] Instance The buffer of IP4 config2 instance to be freed.
39
40 @retval EFI_SUCCESS The child was successfully destroyed.
41 @retval Others Failed to destroy the child.
42
43 **/
44 EFI_STATUS
45 Ip4Config2DestroyDhcp4 (
46 IN OUT IP4_CONFIG2_INSTANCE *Instance
47 )
48 {
49 IP4_SERVICE *IpSb;
50 EFI_STATUS Status;
51 EFI_DHCP4_PROTOCOL *Dhcp4;
52
53 Dhcp4 = Instance->Dhcp4;
54 ASSERT (Dhcp4 != NULL);
55
56 Dhcp4->Stop (Dhcp4);
57 Dhcp4->Configure (Dhcp4, NULL);
58 Instance->Dhcp4 = NULL;
59
60 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
61
62 //
63 // Close DHCPv4 protocol and destroy the child.
64 //
65 Status = gBS->CloseProtocol (
66 Instance->Dhcp4Handle,
67 &gEfiDhcp4ProtocolGuid,
68 IpSb->Image,
69 IpSb->Controller
70 );
71 if (EFI_ERROR (Status)) {
72 return Status;
73 }
74
75 Status = NetLibDestroyServiceChild (
76 IpSb->Controller,
77 IpSb->Image,
78 &gEfiDhcp4ServiceBindingProtocolGuid,
79 Instance->Dhcp4Handle
80 );
81
82 Instance->Dhcp4Handle = NULL;
83
84 return Status;
85 }
86
87 /**
88 Start the DHCP configuration for this IP service instance.
89 It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
90 DHCP configuration.
91
92 @param[in] Instance The IP4 config2 instance to configure.
93
94 @retval EFI_SUCCESS The auto configuration is successfull started.
95 @retval Others Failed to start auto configuration.
96
97 **/
98 EFI_STATUS
99 Ip4StartAutoConfig (
100 IN IP4_CONFIG2_INSTANCE *Instance
101 );
102
103 /**
104 Update the current policy to NewPolicy. During the transition
105 period, the default router list
106 and address list in all interfaces will be released.
107
108 @param[in] IpSb The IP4 service binding instance.
109 @param[in] NewPolicy The new policy to be updated to.
110
111 **/
112 VOID
113 Ip4Config2OnPolicyChanged (
114 IN IP4_SERVICE *IpSb,
115 IN EFI_IP4_CONFIG2_POLICY NewPolicy
116 )
117 {
118 IP4_INTERFACE *IpIf;
119 IP4_ROUTE_TABLE *RouteTable;
120
121 //
122 // Currently there are only two policies: static and dhcp. Regardless of
123 // what transition is going on, i.e., static -> dhcp and dhcp ->
124 // static, we have to free default router table and all addresses.
125 //
126
127 if (IpSb->DefaultInterface != NULL) {
128 if (IpSb->DefaultRouteTable != NULL) {
129 Ip4FreeRouteTable (IpSb->DefaultRouteTable);
130 IpSb->DefaultRouteTable = NULL;
131 }
132
133 Ip4CancelReceive (IpSb->DefaultInterface);
134
135 Ip4FreeInterface (IpSb->DefaultInterface, NULL);
136 IpSb->DefaultInterface = NULL;
137 }
138
139 Ip4CleanAssembleTable (&IpSb->Assemble);
140
141 //
142 // Create new default interface and route table.
143 //
144 IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);
145 if (IpIf == NULL) {
146 return ;
147 }
148
149 RouteTable = Ip4CreateRouteTable ();
150 if (RouteTable == NULL) {
151 Ip4FreeInterface (IpIf, NULL);
152 return ;
153 }
154
155 IpSb->DefaultInterface = IpIf;
156 InsertHeadList (&IpSb->Interfaces, &IpIf->Link);
157 IpSb->DefaultRouteTable = RouteTable;
158 Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb);
159
160 if (IpSb->State == IP4_SERVICE_CONFIGED) {
161 IpSb->State = IP4_SERVICE_UNSTARTED;
162 }
163
164 //
165 // Start the dhcp configuration.
166 //
167 if (NewPolicy == Ip4Config2PolicyDhcp) {
168 Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);
169 }
170
171 }
172
173 /**
174 Signal the registered event. It is the callback routine for NetMapIterate.
175
176 @param[in] Map Points to the list of registered event.
177 @param[in] Item The registered event.
178 @param[in] Arg Not used.
179
180 @retval EFI_SUCCESS The event was signaled successfully.
181 **/
182 EFI_STATUS
183 EFIAPI
184 Ip4Config2SignalEvent (
185 IN NET_MAP *Map,
186 IN NET_MAP_ITEM *Item,
187 IN VOID *Arg
188 )
189 {
190 gBS->SignalEvent ((EFI_EVENT) Item->Key);
191
192 return EFI_SUCCESS;
193 }
194
195 /**
196 Read the configuration data from variable storage according to the VarName and
197 gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the
198 data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
199 configuration data to IP4_CONFIG2_INSTANCE.
200
201 @param[in] VarName The pointer to the variable name
202 @param[in, out] Instance The pointer to the IP4 config2 instance data.
203
204 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
205 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
206 @retval EFI_SUCCESS The configuration data was retrieved successfully.
207
208 **/
209 EFI_STATUS
210 Ip4Config2ReadConfigData (
211 IN CHAR16 *VarName,
212 IN OUT IP4_CONFIG2_INSTANCE *Instance
213 )
214 {
215 EFI_STATUS Status;
216 UINTN VarSize;
217 IP4_CONFIG2_VARIABLE *Variable;
218 IP4_CONFIG2_DATA_ITEM *DataItem;
219 UINTN Index;
220 IP4_CONFIG2_DATA_RECORD DataRecord;
221 CHAR8 *Data;
222
223 //
224 // Try to read the configuration variable.
225 //
226 VarSize = 0;
227 Status = gRT->GetVariable (
228 VarName,
229 &gEfiIp4Config2ProtocolGuid,
230 NULL,
231 &VarSize,
232 NULL
233 );
234
235 if (Status == EFI_BUFFER_TOO_SMALL) {
236 //
237 // Allocate buffer and read the config variable.
238 //
239 Variable = AllocatePool (VarSize);
240 if (Variable == NULL) {
241 return EFI_OUT_OF_RESOURCES;
242 }
243
244 Status = gRT->GetVariable (
245 VarName,
246 &gEfiIp4Config2ProtocolGuid,
247 NULL,
248 &VarSize,
249 Variable
250 );
251 if (EFI_ERROR (Status) || (UINT16) (~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize)) != 0) {
252 //
253 // GetVariable still error or the variable is corrupted.
254 // Fall back to the default value.
255 //
256 FreePool (Variable);
257
258 //
259 // Remove the problematic variable and return EFI_NOT_FOUND, a new
260 // variable will be set again.
261 //
262 gRT->SetVariable (
263 VarName,
264 &gEfiIp4Config2ProtocolGuid,
265 IP4_CONFIG2_VARIABLE_ATTRIBUTE,
266 0,
267 NULL
268 );
269
270 return EFI_NOT_FOUND;
271 }
272
273
274 for (Index = 0; Index < Variable->DataRecordCount; Index++) {
275
276 CopyMem (&DataRecord, &Variable->DataRecord[Index], sizeof (DataRecord));
277
278 DataItem = &Instance->DataItem[DataRecord.DataType];
279 if (DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED) &&
280 (DataItem->DataSize != DataRecord.DataSize)
281 ) {
282 //
283 // Perhaps a corrupted data record...
284 //
285 continue;
286 }
287
288 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {
289 //
290 // This data item has variable length data.
291 //
292 DataItem->Data.Ptr = AllocatePool (DataRecord.DataSize);
293 if (DataItem->Data.Ptr == NULL) {
294 //
295 // no memory resource
296 //
297 continue;
298 }
299 }
300
301 Data = (CHAR8 *) Variable + DataRecord.Offset;
302 CopyMem (DataItem->Data.Ptr, Data, DataRecord.DataSize);
303
304 DataItem->DataSize = DataRecord.DataSize;
305 DataItem->Status = EFI_SUCCESS;
306 }
307
308 FreePool (Variable);
309 return EFI_SUCCESS;
310 }
311
312 return Status;
313 }
314
315 /**
316 Write the configuration data from IP4_CONFIG2_INSTANCE to variable storage.
317
318 @param[in] VarName The pointer to the variable name.
319 @param[in] Instance The pointer to the IP4 config2 instance data.
320
321 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
322 @retval EFI_SUCCESS The configuration data is written successfully.
323
324 **/
325 EFI_STATUS
326 Ip4Config2WriteConfigData (
327 IN CHAR16 *VarName,
328 IN IP4_CONFIG2_INSTANCE *Instance
329 )
330 {
331 UINTN Index;
332 UINTN VarSize;
333 IP4_CONFIG2_DATA_ITEM *DataItem;
334 IP4_CONFIG2_VARIABLE *Variable;
335 IP4_CONFIG2_DATA_RECORD *DataRecord;
336 CHAR8 *Heap;
337 EFI_STATUS Status;
338
339 VarSize = sizeof (IP4_CONFIG2_VARIABLE) - sizeof (IP4_CONFIG2_DATA_RECORD);
340
341 for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {
342
343 DataItem = &Instance->DataItem[Index];
344 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {
345
346 VarSize += sizeof (IP4_CONFIG2_DATA_RECORD) + DataItem->DataSize;
347 }
348 }
349
350 Variable = AllocatePool (VarSize);
351 if (Variable == NULL) {
352 return EFI_OUT_OF_RESOURCES;
353 }
354
355 Heap = (CHAR8 *) Variable + VarSize;
356 Variable->DataRecordCount = 0;
357
358 for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {
359
360 DataItem = &Instance->DataItem[Index];
361 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {
362
363 Heap -= DataItem->DataSize;
364 CopyMem (Heap, DataItem->Data.Ptr, DataItem->DataSize);
365
366 DataRecord = &Variable->DataRecord[Variable->DataRecordCount];
367 DataRecord->DataType = (EFI_IP4_CONFIG2_DATA_TYPE) Index;
368 DataRecord->DataSize = (UINT32) DataItem->DataSize;
369 DataRecord->Offset = (UINT16) (Heap - (CHAR8 *) Variable);
370
371 Variable->DataRecordCount++;
372 }
373 }
374
375 Variable->Checksum = 0;
376 Variable->Checksum = (UINT16) ~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize);
377
378 Status = gRT->SetVariable (
379 VarName,
380 &gEfiIp4Config2ProtocolGuid,
381 IP4_CONFIG2_VARIABLE_ATTRIBUTE,
382 VarSize,
383 Variable
384 );
385
386 FreePool (Variable);
387
388 return Status;
389 }
390
391
392 /**
393 Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of GetModeData.
394 The EFI_IP4_ROUTE_TABLE is clumsy to use in the internal operation of the
395 IP4 driver.
396
397 @param[in] IpSb The IP4 service binding instance.
398 @param[out] Table The built IP4 route table.
399
400 @retval EFI_SUCCESS The route table is successfully build
401 @retval EFI_NOT_FOUND Failed to allocate the memory for the rotue table.
402
403 **/
404 EFI_STATUS
405 Ip4Config2BuildDefaultRouteTable (
406 IN IP4_SERVICE *IpSb,
407 OUT EFI_IP4_ROUTE_TABLE *Table
408 )
409 {
410 LIST_ENTRY *Entry;
411 IP4_ROUTE_ENTRY *RtEntry;
412 UINT32 Count;
413 INT32 Index;
414
415 if (IpSb->DefaultRouteTable == NULL) {
416 return EFI_NOT_FOUND;
417 }
418
419 Count = IpSb->DefaultRouteTable->TotalNum;
420
421 if (Count == 0) {
422 return EFI_NOT_FOUND;
423 }
424
425 //
426 // Copy the route entry to EFI route table. Keep the order of
427 // route entry copied from most specific to default route. That
428 // is, interlevel the route entry from the instance's route area
429 // and those from the default route table's route area.
430 //
431 Count = 0;
432
433 for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {
434
435 NET_LIST_FOR_EACH (Entry, &(IpSb->DefaultRouteTable->RouteArea[Index])) {
436 RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
437
438 EFI_IP4 (Table[Count].SubnetAddress) = HTONL (RtEntry->Dest & RtEntry->Netmask);
439 EFI_IP4 (Table[Count].SubnetMask) = HTONL (RtEntry->Netmask);
440 EFI_IP4 (Table[Count].GatewayAddress) = HTONL (RtEntry->NextHop);
441
442 Count++;
443 }
444
445 }
446
447 return EFI_SUCCESS;
448 }
449
450 /**
451 The event process routine when the DHCPv4 service binding protocol is installed
452 in the system.
453
454 @param[in] Event Not used.
455 @param[in] Context The pointer to the IP4 config2 instance data.
456
457 **/
458 VOID
459 EFIAPI
460 Ip4Config2OnDhcp4SbInstalled (
461 IN EFI_EVENT Event,
462 IN VOID *Context
463 )
464 {
465 IP4_CONFIG2_INSTANCE *Instance;
466
467 Instance = (IP4_CONFIG2_INSTANCE *) Context;
468
469 if ((Instance->Dhcp4Handle != NULL) || (Instance->Policy != Ip4Config2PolicyDhcp)) {
470 //
471 // The DHCP4 child is already created or the policy is no longer DHCP.
472 //
473 return ;
474 }
475
476 Ip4StartAutoConfig (Instance);
477 }
478
479 /**
480 Set the station address and subnetmask for the default interface.
481
482 @param[in] Instance The pointer to the IP4 config2 instance data.
483 @param[in] StationAddress Ip address to be set.
484 @param[in] SubnetMask Subnet to be set.
485
486 @retval EFI_SUCCESS Set default address successful.
487 @retval Others Some errors occur in setting.
488
489 **/
490 EFI_STATUS
491 Ip4Config2SetDefaultAddr (
492 IN IP4_CONFIG2_INSTANCE *Instance,
493 IN IP4_ADDR StationAddress,
494 IN IP4_ADDR SubnetMask
495 )
496 {
497 EFI_STATUS Status;
498 IP4_SERVICE *IpSb;
499 IP4_INTERFACE *IpIf;
500 IP4_PROTOCOL *Ip4Instance;
501 EFI_ARP_PROTOCOL *Arp;
502 LIST_ENTRY *Entry;
503 IP4_ADDR Subnet;
504 IP4_ROUTE_TABLE *RouteTable;
505
506 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
507 IpIf = IpSb->DefaultInterface;
508 ASSERT (IpIf != NULL);
509
510 if ((IpIf->Ip == StationAddress) && (IpIf->SubnetMask == SubnetMask)) {
511 return EFI_SUCCESS;
512 }
513
514 //
515 // The default address is changed, free the previous interface first.
516 //
517 if (IpSb->DefaultRouteTable != NULL) {
518 Ip4FreeRouteTable (IpSb->DefaultRouteTable);
519 IpSb->DefaultRouteTable = NULL;
520 }
521
522 Ip4CancelReceive (IpSb->DefaultInterface);
523 Ip4FreeInterface (IpSb->DefaultInterface, NULL);
524 IpSb->DefaultInterface = NULL;
525 //
526 // Create new default interface and route table.
527 //
528 IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);
529 if (IpIf == NULL) {
530 return EFI_OUT_OF_RESOURCES;
531 }
532
533 RouteTable = Ip4CreateRouteTable ();
534 if (RouteTable == NULL) {
535 Ip4FreeInterface (IpIf, NULL);
536 return EFI_OUT_OF_RESOURCES;
537 }
538
539 IpSb->DefaultInterface = IpIf;
540 InsertHeadList (&IpSb->Interfaces, &IpIf->Link);
541 IpSb->DefaultRouteTable = RouteTable;
542 Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb);
543
544 if (IpSb->State == IP4_SERVICE_CONFIGED) {
545 IpSb->State = IP4_SERVICE_UNSTARTED;
546 }
547
548 Status = Ip4SetAddress (IpIf, StationAddress, SubnetMask);
549 if (EFI_ERROR (Status)) {
550 return Status;
551 }
552
553 if (IpIf->Arp != NULL) {
554 //
555 // A non-NULL IpIf->Arp here means a new ARP child is created when setting default address,
556 // but some IP children may have referenced the default interface before it is configured,
557 // these IP instances also consume this ARP protocol so they need to open it BY_CHILD_CONTROLLER.
558 //
559 Arp = NULL;
560 NET_LIST_FOR_EACH (Entry, &IpIf->IpInstances) {
561 Ip4Instance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, AddrLink, IP4_PROTOCOL_SIGNATURE);
562 Status = gBS->OpenProtocol (
563 IpIf->ArpHandle,
564 &gEfiArpProtocolGuid,
565 (VOID **) &Arp,
566 gIp4DriverBinding.DriverBindingHandle,
567 Ip4Instance->Handle,
568 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
569 );
570 if (EFI_ERROR (Status)) {
571 return Status;
572 }
573 }
574 }
575
576 Ip4AddRoute (
577 IpSb->DefaultRouteTable,
578 StationAddress,
579 SubnetMask,
580 IP4_ALLZERO_ADDRESS
581 );
582
583 //
584 // Add a route for the connected network.
585 //
586 Subnet = StationAddress & SubnetMask;
587
588 Ip4AddRoute (
589 IpSb->DefaultRouteTable,
590 Subnet,
591 SubnetMask,
592 IP4_ALLZERO_ADDRESS
593 );
594
595 IpSb->State = IP4_SERVICE_CONFIGED;
596 return EFI_SUCCESS;
597 }
598
599 /**
600 Set the station address, subnetmask and gateway address for the default interface.
601
602 @param[in] Instance The pointer to the IP4 config2 instance data.
603 @param[in] StationAddress Ip address to be set.
604 @param[in] SubnetMask Subnet to be set.
605 @param[in] GatewayAddress Gateway to be set.
606
607 @retval EFI_SUCCESS Set default If successful.
608 @retval Others Errors occur as indicated.
609
610 **/
611 EFI_STATUS
612 Ip4Config2SetDefaultIf (
613 IN IP4_CONFIG2_INSTANCE *Instance,
614 IN IP4_ADDR StationAddress,
615 IN IP4_ADDR SubnetMask,
616 IN IP4_ADDR GatewayAddress
617 )
618 {
619 EFI_STATUS Status;
620 IP4_SERVICE *IpSb;
621
622 Status = Ip4Config2SetDefaultAddr (Instance, StationAddress, SubnetMask);
623 if (EFI_ERROR (Status)) {
624 return Status;
625 }
626
627 //
628 // Create a route if there is a default router.
629 //
630 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
631 if (GatewayAddress != IP4_ALLZERO_ADDRESS) {
632 Ip4AddRoute (
633 IpSb->DefaultRouteTable,
634 IP4_ALLZERO_ADDRESS,
635 IP4_ALLZERO_ADDRESS,
636 GatewayAddress
637 );
638 }
639
640 return EFI_SUCCESS;
641 }
642
643
644 /**
645 Release all the DHCP related resources.
646
647 @param Instance The IP4 config2 instance.
648
649 @return None
650
651 **/
652 VOID
653 Ip4Config2CleanDhcp4 (
654 IN IP4_CONFIG2_INSTANCE *Instance
655 )
656 {
657 IP4_SERVICE *IpSb;
658
659 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
660
661 if (Instance->Dhcp4 != NULL) {
662 Instance->Dhcp4->Stop (Instance->Dhcp4);
663
664 gBS->CloseProtocol (
665 Instance->Dhcp4Handle,
666 &gEfiDhcp4ProtocolGuid,
667 IpSb->Image,
668 IpSb->Controller
669 );
670
671 Instance->Dhcp4 = NULL;
672 }
673
674 if (Instance->Dhcp4Handle != NULL) {
675 NetLibDestroyServiceChild (
676 IpSb->Controller,
677 IpSb->Image,
678 &gEfiDhcp4ServiceBindingProtocolGuid,
679 Instance->Dhcp4Handle
680 );
681
682 Instance->Dhcp4Handle = NULL;
683 }
684
685 if (Instance->Dhcp4Event != NULL) {
686 gBS->CloseEvent (Instance->Dhcp4Event);
687 Instance->Dhcp4Event = NULL;
688 }
689 }
690
691
692 /**
693 Callback function when DHCP process finished. It will save the
694 retrieved IP configure parameter from DHCP to the NVRam.
695
696 @param Event The callback event
697 @param Context Opaque context to the callback
698
699 @return None
700
701 **/
702 VOID
703 EFIAPI
704 Ip4Config2OnDhcp4Complete (
705 IN EFI_EVENT Event,
706 IN VOID *Context
707 )
708 {
709 IP4_CONFIG2_INSTANCE *Instance;
710 EFI_DHCP4_MODE_DATA Dhcp4Mode;
711 EFI_STATUS Status;
712 IP4_ADDR StationAddress;
713 IP4_ADDR SubnetMask;
714 IP4_ADDR GatewayAddress;
715
716 Instance = (IP4_CONFIG2_INSTANCE *) Context;
717 ASSERT (Instance->Dhcp4 != NULL);
718
719 //
720 // Get the DHCP retrieved parameters
721 //
722 Status = Instance->Dhcp4->GetModeData (Instance->Dhcp4, &Dhcp4Mode);
723
724 if (EFI_ERROR (Status)) {
725 goto Exit;
726 }
727
728 if (Dhcp4Mode.State == Dhcp4Bound) {
729 StationAddress = EFI_NTOHL (Dhcp4Mode.ClientAddress);
730 SubnetMask = EFI_NTOHL (Dhcp4Mode.SubnetMask);
731 GatewayAddress = EFI_NTOHL (Dhcp4Mode.RouterAddress);
732
733 Status = Ip4Config2SetDefaultIf (Instance, StationAddress, SubnetMask, GatewayAddress);
734 if (EFI_ERROR (Status)) {
735 goto Exit;
736 }
737
738 Instance->DhcpSuccess = TRUE;
739 }
740
741 Exit:
742 Ip4Config2CleanDhcp4 (Instance);
743 DispatchDpc ();
744 }
745
746
747 /**
748 Start the DHCP configuration for this IP service instance.
749 It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
750 DHCP configuration.
751
752 @param[in] Instance The IP4 config2 instance to configure
753
754 @retval EFI_SUCCESS The auto configuration is successfull started
755 @retval Others Failed to start auto configuration.
756
757 **/
758 EFI_STATUS
759 Ip4StartAutoConfig (
760 IN IP4_CONFIG2_INSTANCE *Instance
761 )
762 {
763 IP4_SERVICE *IpSb;
764 EFI_DHCP4_PROTOCOL *Dhcp4;
765 EFI_DHCP4_MODE_DATA Dhcp4Mode;
766 EFI_DHCP4_PACKET_OPTION *OptionList[1];
767 IP4_CONFIG2_DHCP4_OPTION ParaList;
768 EFI_STATUS Status;
769
770
771 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
772
773 if (IpSb->State > IP4_SERVICE_UNSTARTED) {
774 return EFI_SUCCESS;
775 }
776
777 //
778 // A host must not invoke DHCP configuration if it is already
779 // participating in the DHCP configuraiton process.
780 //
781 if (Instance->Dhcp4Handle != NULL) {
782 return EFI_SUCCESS;
783 }
784
785 Status = NetLibCreateServiceChild (
786 IpSb->Controller,
787 IpSb->Image,
788 &gEfiDhcp4ServiceBindingProtocolGuid,
789 &Instance->Dhcp4Handle
790 );
791
792 if (Status == EFI_UNSUPPORTED) {
793 //
794 // No DHCPv4 Service Binding protocol, register a notify.
795 //
796 if (Instance->Dhcp4SbNotifyEvent == NULL) {
797 Instance->Dhcp4SbNotifyEvent = EfiCreateProtocolNotifyEvent (
798 &gEfiDhcp4ServiceBindingProtocolGuid,
799 TPL_CALLBACK,
800 Ip4Config2OnDhcp4SbInstalled,
801 (VOID *) Instance,
802 &Instance->Registration
803 );
804 }
805 }
806
807 if (EFI_ERROR (Status)) {
808 return Status;
809 }
810
811 if (Instance->Dhcp4SbNotifyEvent != NULL) {
812 gBS->CloseEvent (Instance->Dhcp4SbNotifyEvent);
813 }
814
815 Status = gBS->OpenProtocol (
816 Instance->Dhcp4Handle,
817 &gEfiDhcp4ProtocolGuid,
818 (VOID **) &Instance->Dhcp4,
819 IpSb->Image,
820 IpSb->Controller,
821 EFI_OPEN_PROTOCOL_BY_DRIVER
822 );
823 ASSERT_EFI_ERROR (Status);
824
825
826 //
827 // Check the current DHCP status, if the DHCP process has
828 // already finished, return now.
829 //
830 Dhcp4 = Instance->Dhcp4;
831 Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);
832
833 if (Dhcp4Mode.State == Dhcp4Bound) {
834 Ip4Config2OnDhcp4Complete (NULL, Instance);
835 return EFI_SUCCESS;
836
837 }
838
839 //
840 // Try to start the DHCP process. Use most of the current
841 // DHCP configuration to avoid problems if some DHCP client
842 // yields the control of this DHCP service to us.
843 //
844 ParaList.Head.OpCode = DHCP_TAG_PARA_LIST;
845 ParaList.Head.Length = 2;
846 ParaList.Head.Data[0] = DHCP_TAG_NETMASK;
847 ParaList.Route = DHCP_TAG_ROUTER;
848 OptionList[0] = &ParaList.Head;
849 Dhcp4Mode.ConfigData.OptionCount = 1;
850 Dhcp4Mode.ConfigData.OptionList = OptionList;
851
852 Status = Dhcp4->Configure (Dhcp4, &Dhcp4Mode.ConfigData);
853
854 if (EFI_ERROR (Status)) {
855 return Status;
856 }
857
858 //
859 // Start the DHCP process
860 //
861 Status = gBS->CreateEvent (
862 EVT_NOTIFY_SIGNAL,
863 TPL_CALLBACK,
864 Ip4Config2OnDhcp4Complete,
865 Instance,
866 &Instance->Dhcp4Event
867 );
868
869 if (EFI_ERROR (Status)) {
870 return Status;
871 }
872
873 Status = Dhcp4->Start (Dhcp4, Instance->Dhcp4Event);
874
875 if (EFI_ERROR (Status)) {
876 return Status;
877 }
878
879 IpSb->State = IP4_SERVICE_STARTED;
880 DispatchDpc ();
881 return EFI_SUCCESS;
882
883 }
884
885
886
887 /**
888 The work function is to get the interface information of the communication
889 device this IP4_CONFIG2_INSTANCE manages.
890
891 @param[in] Instance Pointer to the IP4 config2 instance data.
892 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
893 bytes, the size of buffer required to store the specified
894 configuration data.
895 @param[in] Data The data buffer in which the configuration data is returned.
896 Ignored if DataSize is ZERO.
897
898 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
899 configuration data, and the required size is
900 returned in DataSize.
901 @retval EFI_SUCCESS The specified configuration data was obtained.
902
903 **/
904 EFI_STATUS
905 Ip4Config2GetIfInfo (
906 IN IP4_CONFIG2_INSTANCE *Instance,
907 IN OUT UINTN *DataSize,
908 IN VOID *Data OPTIONAL
909 )
910 {
911
912 IP4_SERVICE *IpSb;
913 UINTN Length;
914 IP4_CONFIG2_DATA_ITEM *Item;
915 EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
916 IP4_ADDR Address;
917
918 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
919 Length = sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO);
920
921 if (IpSb->DefaultRouteTable != NULL) {
922 Length += IpSb->DefaultRouteTable->TotalNum * sizeof (EFI_IP4_ROUTE_TABLE);
923 }
924
925 if (*DataSize < Length) {
926 *DataSize = Length;
927 return EFI_BUFFER_TOO_SMALL;
928 }
929
930 //
931 // Copy the fixed size part of the interface info.
932 //
933 Item = &Instance->DataItem[Ip4Config2DataTypeInterfaceInfo];
934 IfInfo = (EFI_IP4_CONFIG2_INTERFACE_INFO *) Data;
935 CopyMem (IfInfo, Item->Data.Ptr, sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO));
936
937 //
938 // Update the address info.
939 //
940 if (IpSb->DefaultInterface != NULL) {
941 Address = HTONL (IpSb->DefaultInterface->Ip);
942 CopyMem (&IfInfo->StationAddress, &Address, sizeof (EFI_IPv4_ADDRESS));
943 Address = HTONL (IpSb->DefaultInterface->SubnetMask);
944 CopyMem (&IfInfo->SubnetMask, &Address, sizeof (EFI_IPv4_ADDRESS));
945 }
946
947 if (IpSb->DefaultRouteTable != NULL) {
948 IfInfo->RouteTableSize = IpSb->DefaultRouteTable->TotalNum;
949 IfInfo->RouteTable = (EFI_IP4_ROUTE_TABLE *) ((UINT8 *) Data + sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO));
950
951 Ip4Config2BuildDefaultRouteTable (IpSb, IfInfo->RouteTable);
952 }
953
954 return EFI_SUCCESS;
955 }
956
957 /**
958 The work function is to set the general configuration policy for the EFI IPv4 network
959 stack that is running on the communication device managed by this IP4_CONFIG2_INSTANCE.
960 The policy will affect other configuration settings.
961
962 @param[in] Instance Pointer to the IP4 config2 instance data.
963 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
964 @param[in] Data The data buffer to set.
965
966 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
967 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
968 @retval EFI_ABORTED The new policy equals the current policy.
969 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
970 network stack was set.
971
972 **/
973 EFI_STATUS
974 Ip4Config2SetPolicy (
975 IN IP4_CONFIG2_INSTANCE *Instance,
976 IN UINTN DataSize,
977 IN VOID *Data
978 )
979 {
980 EFI_IP4_CONFIG2_POLICY NewPolicy;
981 IP4_CONFIG2_DATA_ITEM *DataItem;
982 IP4_SERVICE *IpSb;
983
984 if (DataSize != sizeof (EFI_IP4_CONFIG2_POLICY)) {
985 return EFI_BAD_BUFFER_SIZE;
986 }
987
988 NewPolicy = *((EFI_IP4_CONFIG2_POLICY *) Data);
989
990 if (NewPolicy >= Ip4Config2PolicyMax) {
991 return EFI_INVALID_PARAMETER;
992 }
993
994 if (NewPolicy == Instance->Policy) {
995 if (NewPolicy != Ip4Config2PolicyDhcp || Instance->DhcpSuccess) {
996 return EFI_ABORTED;
997 }
998
999 } else {
1000 if (NewPolicy == Ip4Config2PolicyDhcp) {
1001 //
1002 // The policy is changed from static to dhcp:
1003 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
1004 // data size, and fire up all the related events.
1005 //
1006 DataItem = &Instance->DataItem[Ip4Config2DataTypeManualAddress];
1007 if (DataItem->Data.Ptr != NULL) {
1008 FreePool (DataItem->Data.Ptr);
1009 }
1010 DataItem->Data.Ptr = NULL;
1011 DataItem->DataSize = 0;
1012 DataItem->Status = EFI_NOT_FOUND;
1013 NetMapIterate (&DataItem->EventMap, Ip4Config2SignalEvent, NULL);
1014
1015 DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];
1016 if (DataItem->Data.Ptr != NULL) {
1017 FreePool (DataItem->Data.Ptr);
1018 }
1019 DataItem->Data.Ptr = NULL;
1020 DataItem->DataSize = 0;
1021 DataItem->Status = EFI_NOT_FOUND;
1022 NetMapIterate (&DataItem->EventMap, Ip4Config2SignalEvent, NULL);
1023
1024 DataItem = &Instance->DataItem[Ip4Config2DataTypeDnsServer];
1025 if (DataItem->Data.Ptr != NULL) {
1026 FreePool (DataItem->Data.Ptr);
1027 }
1028 DataItem->Data.Ptr = NULL;
1029 DataItem->DataSize = 0;
1030 DataItem->Status = EFI_NOT_FOUND;
1031 NetMapIterate (&DataItem->EventMap, Ip4Config2SignalEvent, NULL);
1032 } else {
1033 //
1034 // The policy is changed from dhcp to static. Stop the DHCPv4 process
1035 // and destroy the DHCPv4 child.
1036 //
1037 if (Instance->Dhcp4Handle != NULL) {
1038 Ip4Config2DestroyDhcp4 (Instance);
1039 }
1040
1041 //
1042 // Close the event.
1043 //
1044 if (Instance->Dhcp4Event != NULL) {
1045 gBS->CloseEvent (Instance->Dhcp4Event);
1046 }
1047 }
1048 }
1049
1050 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
1051 Ip4Config2OnPolicyChanged (IpSb, NewPolicy);
1052
1053 Instance->Policy = NewPolicy;
1054
1055 return EFI_SUCCESS;
1056 }
1057
1058 /**
1059 The work function is to set the station addresses manually for the EFI IPv4
1060 network stack. It is only configurable when the policy is Ip4Config2PolicyStatic.
1061
1062 @param[in] Instance Pointer to the IP4 config2 instance data.
1063 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1064 @param[in] Data The data buffer to set.
1065
1066 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1067 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1068 under the current policy.
1069 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1070 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
1071 @retval EFI_NOT_READY An asynchrous process is invoked to set the specified
1072 configuration data, and the process is not finished.
1073 @retval EFI_ABORTED The manual addresses to be set equal current
1074 configuration.
1075 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1076 network stack was set.
1077
1078 **/
1079 EFI_STATUS
1080 Ip4Config2SetMaunualAddress (
1081 IN IP4_CONFIG2_INSTANCE *Instance,
1082 IN UINTN DataSize,
1083 IN VOID *Data
1084 )
1085 {
1086 EFI_IP4_CONFIG2_MANUAL_ADDRESS NewAddress;
1087 IP4_CONFIG2_DATA_ITEM *DataItem;
1088 EFI_STATUS Status;
1089 IP4_ADDR StationAddress;
1090 IP4_ADDR SubnetMask;
1091 VOID *Ptr;
1092
1093 ASSERT (Instance->DataItem[Ip4Config2DataTypeManualAddress].Status != EFI_NOT_READY);
1094
1095 if (((DataSize % sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS)) != 0) || (DataSize == 0)) {
1096 return EFI_BAD_BUFFER_SIZE;
1097 }
1098
1099 if (Instance->Policy != Ip4Config2PolicyStatic) {
1100 return EFI_WRITE_PROTECTED;
1101 }
1102
1103 NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);
1104
1105 //
1106 // Store the new data, and init the DataItem status to EFI_NOT_READY because
1107 // we may have an asynchronous configuration process.
1108 //
1109 Ptr = AllocateCopyPool (DataSize, Data);
1110 if (Ptr == NULL) {
1111 return EFI_OUT_OF_RESOURCES;
1112 }
1113
1114 DataItem = &Instance->DataItem[Ip4Config2DataTypeManualAddress];
1115 if (DataItem->Data.Ptr != NULL) {
1116 FreePool (DataItem->Data.Ptr);
1117 }
1118
1119 DataItem->Data.Ptr = Ptr;
1120 DataItem->DataSize = DataSize;
1121 DataItem->Status = EFI_NOT_READY;
1122
1123 StationAddress = EFI_NTOHL (NewAddress.Address);
1124 SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
1125
1126 Status = Ip4Config2SetDefaultAddr (Instance, StationAddress, SubnetMask);
1127 if (EFI_ERROR (Status)) {
1128 goto ON_EXIT;
1129 }
1130
1131 DataItem->Status = EFI_SUCCESS;
1132
1133 ON_EXIT:
1134 if (EFI_ERROR (DataItem->Status)) {
1135 if (Ptr != NULL) {
1136 FreePool (Ptr);
1137 }
1138 DataItem->Data.Ptr = NULL;
1139 }
1140
1141 return EFI_SUCCESS;
1142 }
1143
1144 /**
1145 The work function is to set the gateway addresses manually for the EFI IPv4
1146 network stack that is running on the communication device that this EFI IPv4
1147 Configuration Protocol manages. It is not configurable when the policy is
1148 Ip4Config2PolicyDhcp. The gateway addresses must be unicast IPv4 addresses.
1149
1150 @param[in] Instance The pointer to the IP4 config2 instance data.
1151 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1152 @param[in] Data The data buffer to set. This points to an array of
1153 EFI_IPv6_ADDRESS instances.
1154
1155 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1156 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1157 under the current policy.
1158 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1159 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1160 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1161 current configuration.
1162 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1163 network stack was set.
1164
1165 **/
1166 EFI_STATUS
1167 Ip4Config2SetGateway (
1168 IN IP4_CONFIG2_INSTANCE *Instance,
1169 IN UINTN DataSize,
1170 IN VOID *Data
1171 )
1172 {
1173 IP4_SERVICE *IpSb;
1174 IP4_CONFIG2_DATA_ITEM *DataItem;
1175 IP4_ADDR Gateway;
1176
1177 UINTN Index1;
1178 UINTN Index2;
1179 EFI_IPv4_ADDRESS *OldGateway;
1180 EFI_IPv4_ADDRESS *NewGateway;
1181 UINTN OldGatewayCount;
1182 UINTN NewGatewayCount;
1183 BOOLEAN OneRemoved;
1184 BOOLEAN OneAdded;
1185 VOID *Tmp;
1186
1187 if ((DataSize % sizeof (EFI_IPv4_ADDRESS) != 0) || (DataSize == 0)) {
1188 return EFI_BAD_BUFFER_SIZE;
1189 }
1190
1191 if (Instance->Policy != Ip4Config2PolicyStatic) {
1192 return EFI_WRITE_PROTECTED;
1193 }
1194
1195
1196 NewGateway = (EFI_IPv4_ADDRESS *) Data;
1197 NewGatewayCount = DataSize / sizeof (EFI_IPv4_ADDRESS);
1198 for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {
1199 CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR));
1200
1201 if (!NetIp4IsUnicast (NTOHL (Gateway), 0)) {
1202
1203 return EFI_INVALID_PARAMETER;
1204 }
1205
1206 for (Index2 = Index1 + 1; Index2 < NewGatewayCount; Index2++) {
1207 if (EFI_IP4_EQUAL (NewGateway + Index1, NewGateway + Index2)) {
1208 return EFI_INVALID_PARAMETER;
1209 }
1210 }
1211 }
1212
1213 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
1214 DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];
1215 OldGateway = DataItem->Data.Gateway;
1216 OldGatewayCount = DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS);
1217 OneRemoved = FALSE;
1218 OneAdded = FALSE;
1219
1220 if (NewGatewayCount != OldGatewayCount) {
1221 Tmp = AllocatePool (DataSize);
1222 if (Tmp == NULL) {
1223 return EFI_OUT_OF_RESOURCES;
1224 }
1225 } else {
1226 Tmp = NULL;
1227 }
1228
1229 for (Index1 = 0; Index1 < OldGatewayCount; Index1++) {
1230 //
1231 // Remove this route entry.
1232 //
1233 CopyMem (&Gateway, OldGateway + Index1, sizeof (IP4_ADDR));
1234 Ip4DelRoute (
1235 IpSb->DefaultRouteTable,
1236 IP4_ALLZERO_ADDRESS,
1237 IP4_ALLZERO_ADDRESS,
1238 NTOHL (Gateway)
1239 );
1240 OneRemoved = TRUE;
1241
1242 }
1243
1244 for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {
1245 CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR));
1246 Ip4AddRoute (
1247 IpSb->DefaultRouteTable,
1248 IP4_ALLZERO_ADDRESS,
1249 IP4_ALLZERO_ADDRESS,
1250 NTOHL (Gateway)
1251 );
1252
1253 OneAdded = TRUE;
1254 }
1255
1256
1257 if (!OneRemoved && !OneAdded) {
1258 DataItem->Status = EFI_SUCCESS;
1259 return EFI_ABORTED;
1260 } else {
1261
1262 if (Tmp != NULL) {
1263 if (DataItem->Data.Ptr != NULL) {
1264 FreePool (DataItem->Data.Ptr);
1265 }
1266 DataItem->Data.Ptr = Tmp;
1267 }
1268
1269 CopyMem (DataItem->Data.Ptr, Data, DataSize);
1270 DataItem->DataSize = DataSize;
1271 DataItem->Status = EFI_SUCCESS;
1272 return EFI_SUCCESS;
1273 }
1274
1275 }
1276
1277 /**
1278 The work function is to set the DNS server list for the EFI IPv4 network
1279 stack running on the communication device that this EFI_IP4_CONFIG2_PROTOCOL
1280 manages. It is not configurable when the policy is Ip4Config2PolicyDhcp.
1281 The DNS server addresses must be unicast IPv4 addresses.
1282
1283 @param[in] Instance The pointer to the IP4 config2 instance data.
1284 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1285 @param[in] Data The data buffer to set, points to an array of
1286 EFI_IPv4_ADDRESS instances.
1287
1288 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1289 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1290 under the current policy.
1291 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1292 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1293 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1294 configuration.
1295 @retval EFI_SUCCESS The specified configuration data for the EFI IPv4
1296 network stack was set.
1297
1298 **/
1299 EFI_STATUS
1300 Ip4Config2SetDnsServer (
1301 IN IP4_CONFIG2_INSTANCE *Instance,
1302 IN UINTN DataSize,
1303 IN VOID *Data
1304 )
1305 {
1306 UINTN OldIndex;
1307 UINTN NewIndex;
1308 UINTN Index1;
1309 EFI_IPv4_ADDRESS *OldDns;
1310 EFI_IPv4_ADDRESS *NewDns;
1311 UINTN OldDnsCount;
1312 UINTN NewDnsCount;
1313 IP4_CONFIG2_DATA_ITEM *Item;
1314 BOOLEAN OneAdded;
1315 VOID *Tmp;
1316 IP4_ADDR DnsAddress;
1317
1318 if ((DataSize % sizeof (EFI_IPv4_ADDRESS) != 0) || (DataSize == 0)) {
1319 return EFI_BAD_BUFFER_SIZE;
1320 }
1321
1322 if (Instance->Policy != Ip4Config2PolicyStatic) {
1323 return EFI_WRITE_PROTECTED;
1324 }
1325
1326 Item = &Instance->DataItem[Ip4Config2DataTypeDnsServer];
1327 NewDns = (EFI_IPv4_ADDRESS *) Data;
1328 OldDns = Item->Data.DnsServers;
1329 NewDnsCount = DataSize / sizeof (EFI_IPv4_ADDRESS);
1330 OldDnsCount = Item->DataSize / sizeof (EFI_IPv4_ADDRESS);
1331 OneAdded = FALSE;
1332
1333 if (NewDnsCount != OldDnsCount) {
1334 Tmp = AllocatePool (DataSize);
1335 if (Tmp == NULL) {
1336 return EFI_OUT_OF_RESOURCES;
1337 }
1338 } else {
1339 Tmp = NULL;
1340 }
1341
1342 for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {
1343 CopyMem (&DnsAddress, NewDns + NewIndex, sizeof (IP4_ADDR));
1344
1345 if (!NetIp4IsUnicast (NTOHL (DnsAddress), 0)) {
1346 //
1347 // The dns server address must be unicast.
1348 //
1349 FreePool (Tmp);
1350 return EFI_INVALID_PARAMETER;
1351 }
1352
1353 for (Index1 = NewIndex + 1; Index1 < NewDnsCount; Index1++) {
1354 if (EFI_IP4_EQUAL (NewDns + NewIndex, NewDns + Index1)) {
1355 FreePool (Tmp);
1356 return EFI_INVALID_PARAMETER;
1357 }
1358 }
1359
1360 if (OneAdded) {
1361 //
1362 // If any address in the new setting is not in the old settings, skip the
1363 // comparision below.
1364 //
1365 continue;
1366 }
1367
1368 for (OldIndex = 0; OldIndex < OldDnsCount; OldIndex++) {
1369 if (EFI_IP4_EQUAL (NewDns + NewIndex, OldDns + OldIndex)) {
1370 //
1371 // If found break out.
1372 //
1373 break;
1374 }
1375 }
1376
1377 if (OldIndex == OldDnsCount) {
1378 OneAdded = TRUE;
1379 }
1380 }
1381
1382 if (!OneAdded && (DataSize == Item->DataSize)) {
1383 //
1384 // No new item is added and the size is the same.
1385 //
1386 Item->Status = EFI_SUCCESS;
1387 return EFI_ABORTED;
1388 } else {
1389 if (Tmp != NULL) {
1390 if (Item->Data.Ptr != NULL) {
1391 FreePool (Item->Data.Ptr);
1392 }
1393 Item->Data.Ptr = Tmp;
1394 }
1395
1396 CopyMem (Item->Data.Ptr, Data, DataSize);
1397 Item->DataSize = DataSize;
1398 Item->Status = EFI_SUCCESS;
1399 return EFI_SUCCESS;
1400 }
1401
1402 }
1403
1404 /**
1405 Generate the operational state of the interface this IP4 config2 instance manages
1406 and output in EFI_IP4_CONFIG2_INTERFACE_INFO.
1407
1408 @param[in] IpSb The pointer to the IP4 service binding instance.
1409 @param[out] IfInfo The pointer to the IP4 config2 interface information structure.
1410
1411 **/
1412 VOID
1413 Ip4Config2InitIfInfo (
1414 IN IP4_SERVICE *IpSb,
1415 OUT EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo
1416 )
1417 {
1418 IfInfo->Name[0] = L'e';
1419 IfInfo->Name[1] = L't';
1420 IfInfo->Name[2] = L'h';
1421 IfInfo->Name[3] = (CHAR16) (L'0' + IpSb->Ip4Config2Instance.IfIndex);
1422 IfInfo->Name[4] = 0;
1423
1424 IfInfo->IfType = IpSb->SnpMode.IfType;
1425 IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;
1426 CopyMem (&IfInfo->HwAddress, &IpSb->SnpMode.CurrentAddress, IfInfo->HwAddressSize);
1427 }
1428
1429 /**
1430 The event handle routine when DHCPv4 process is finished or is updated.
1431
1432 @param[in] Event Not used.
1433 @param[in] Context The pointer to the IP4 configuration instance data.
1434
1435 **/
1436 VOID
1437 EFIAPI
1438 Ip4Config2OnDhcp4Event (
1439 IN EFI_EVENT Event,
1440 IN VOID *Context
1441 )
1442 {
1443 return ;
1444 }
1445
1446
1447 /**
1448 Set the configuration for the EFI IPv4 network stack running on the communication
1449 device this EFI_IP4_CONFIG2_PROTOCOL instance manages.
1450
1451 This function is used to set the configuration data of type DataType for the EFI
1452 IPv4 network stack that is running on the communication device that this EFI IPv4
1453 Configuration Protocol instance manages.
1454
1455 DataSize is used to calculate the count of structure instances in the Data for
1456 a DataType in which multiple structure instances are allowed.
1457
1458 This function is always non-blocking. When setting some type of configuration data,
1459 an asynchronous process is invoked to check the correctness of the data, such as
1460 performing Duplicate Address Detection on the manually set local IPv4 addresses.
1461 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1462 is invoked, and the process is not finished yet. The caller wanting to get the result
1463 of the asynchronous process is required to call RegisterDataNotify() to register an
1464 event on the specified configuration data. Once the event is signaled, the caller
1465 can call GetData() to obtain the configuration data and know the result.
1466 For other types of configuration data that do not require an asynchronous configuration
1467 process, the result of the operation is immediately returned.
1468
1469 @param[in] This The pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1470 @param[in] DataType The type of data to set.
1471 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1472 @param[in] Data The data buffer to set. The type of the data buffer is
1473 associated with the DataType.
1474
1475 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1476 network stack was set successfully.
1477 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1478 - This is NULL.
1479 - Data is NULL.
1480 - One or more fields in Data do not match the requirement of the
1481 data type indicated by DataType.
1482 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1483 configuration data cannot be set under the current policy.
1484 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1485 data is already in process.
1486 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1487 configuration data, and the process is not finished yet.
1488 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1489 indicated by DataType.
1490 @retval EFI_UNSUPPORTED This DataType is not supported.
1491 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1492 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1493
1494 **/
1495 EFI_STATUS
1496 EFIAPI
1497 EfiIp4Config2SetData (
1498 IN EFI_IP4_CONFIG2_PROTOCOL *This,
1499 IN EFI_IP4_CONFIG2_DATA_TYPE DataType,
1500 IN UINTN DataSize,
1501 IN VOID *Data
1502 )
1503 {
1504 EFI_TPL OldTpl;
1505 EFI_STATUS Status;
1506 IP4_CONFIG2_INSTANCE *Instance;
1507 IP4_SERVICE *IpSb;
1508
1509 if ((This == NULL) || (Data == NULL)) {
1510 return EFI_INVALID_PARAMETER;
1511 }
1512
1513 if (DataType >= Ip4Config2DataTypeMaximum) {
1514 return EFI_UNSUPPORTED;
1515 }
1516
1517 Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);
1518 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
1519 NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);
1520
1521
1522 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1523
1524 Status = Instance->DataItem[DataType].Status;
1525 if (Status != EFI_NOT_READY) {
1526
1527 if (Instance->DataItem[DataType].SetData == NULL) {
1528 //
1529 // This type of data is readonly.
1530 //
1531 Status = EFI_WRITE_PROTECTED;
1532 } else {
1533
1534 Status = Instance->DataItem[DataType].SetData (Instance, DataSize, Data);
1535 if (!EFI_ERROR (Status)) {
1536 //
1537 // Fire up the events registered with this type of data.
1538 //
1539 NetMapIterate (&Instance->DataItem[DataType].EventMap, Ip4Config2SignalEvent, NULL);
1540 Ip4Config2WriteConfigData (IpSb->MacString, Instance);
1541 } else if (Status == EFI_ABORTED) {
1542 //
1543 // The SetData is aborted because the data to set is the same with
1544 // the one maintained.
1545 //
1546 Status = EFI_SUCCESS;
1547 NetMapIterate (&Instance->DataItem[DataType].EventMap, Ip4Config2SignalEvent, NULL);
1548 }
1549 }
1550 } else {
1551 //
1552 // Another asynchornous process is on the way.
1553 //
1554 Status = EFI_ACCESS_DENIED;
1555 }
1556
1557 gBS->RestoreTPL (OldTpl);
1558
1559 return Status;
1560 }
1561
1562 /**
1563 Get the configuration data for the EFI IPv4 network stack running on the communication
1564 device that this EFI_IP4_CONFIG2_PROTOCOL instance manages.
1565
1566 This function returns the configuration data of type DataType for the EFI IPv4 network
1567 stack running on the communication device that this EFI IPv4 Configuration Protocol instance
1568 manages.
1569
1570 The caller is responsible for allocating the buffer used to return the specified
1571 configuration data. The required size will be returned to the caller if the size of
1572 the buffer is too small.
1573
1574 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
1575 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
1576 to register an event on the specified configuration data. Once the asynchronous configuration
1577 process is finished, the event will be signaled, and a subsequent GetData() call will return
1578 the specified configuration data.
1579
1580 @param[in] This Pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1581 @param[in] DataType The type of data to get.
1582 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
1583 size of buffer required to store the specified configuration data.
1584 @param[in] Data The data buffer in which the configuration data is returned. The
1585 type of the data buffer is associated with the DataType.
1586 This is an optional parameter that may be NULL.
1587
1588 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1589 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
1590 - This is NULL.
1591 - DataSize is NULL.
1592 - Data is NULL if *DataSize is not zero.
1593 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
1594 and the required size is returned in DataSize.
1595 @retval EFI_NOT_READY The specified configuration data is not ready due to an
1596 asynchronous configuration process already in progress.
1597 @retval EFI_NOT_FOUND The specified configuration data is not found.
1598
1599 **/
1600 EFI_STATUS
1601 EFIAPI
1602 EfiIp4Config2GetData (
1603 IN EFI_IP4_CONFIG2_PROTOCOL *This,
1604 IN EFI_IP4_CONFIG2_DATA_TYPE DataType,
1605 IN OUT UINTN *DataSize,
1606 IN VOID *Data OPTIONAL
1607 )
1608 {
1609 EFI_TPL OldTpl;
1610 EFI_STATUS Status;
1611 IP4_CONFIG2_INSTANCE *Instance;
1612 IP4_CONFIG2_DATA_ITEM *DataItem;
1613
1614 if ((This == NULL) || (DataSize == NULL) || ((*DataSize != 0) && (Data == NULL))) {
1615 return EFI_INVALID_PARAMETER;
1616 }
1617
1618 if (DataType >= Ip4Config2DataTypeMaximum) {
1619 return EFI_NOT_FOUND;
1620 }
1621
1622 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1623
1624 Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);
1625 DataItem = &Instance->DataItem[DataType];
1626
1627 Status = Instance->DataItem[DataType].Status;
1628 if (!EFI_ERROR (Status)) {
1629
1630 if (DataItem->GetData != NULL) {
1631
1632 Status = DataItem->GetData (Instance, DataSize, Data);
1633 } else if (*DataSize < Instance->DataItem[DataType].DataSize) {
1634 //
1635 // Update the buffer length.
1636 //
1637 *DataSize = Instance->DataItem[DataType].DataSize;
1638 Status = EFI_BUFFER_TOO_SMALL;
1639 } else {
1640
1641 *DataSize = Instance->DataItem[DataType].DataSize;
1642 CopyMem (Data, Instance->DataItem[DataType].Data.Ptr, *DataSize);
1643 }
1644 }
1645
1646 gBS->RestoreTPL (OldTpl);
1647
1648 return Status;
1649 }
1650
1651 /**
1652 Register an event that is signaled whenever a configuration process on the specified
1653 configuration data is done.
1654
1655 This function registers an event that is to be signaled whenever a configuration
1656 process on the specified configuration data is performed. An event can be registered
1657 for a different DataType simultaneously. The caller is responsible for determining
1658 which type of configuration data causes the signaling of the event in such an event.
1659
1660 @param[in] This Pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1661 @param[in] DataType The type of data to unregister the event for.
1662 @param[in] Event The event to register.
1663
1664 @retval EFI_SUCCESS The notification event for the specified configuration data is
1665 registered.
1666 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
1667 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
1668 supported.
1669 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1670 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
1671
1672 **/
1673 EFI_STATUS
1674 EFIAPI
1675 EfiIp4Config2RegisterDataNotify (
1676 IN EFI_IP4_CONFIG2_PROTOCOL *This,
1677 IN EFI_IP4_CONFIG2_DATA_TYPE DataType,
1678 IN EFI_EVENT Event
1679 )
1680 {
1681 EFI_TPL OldTpl;
1682 EFI_STATUS Status;
1683 IP4_CONFIG2_INSTANCE *Instance;
1684 NET_MAP *EventMap;
1685 NET_MAP_ITEM *Item;
1686
1687 if ((This == NULL) || (Event == NULL)) {
1688 return EFI_INVALID_PARAMETER;
1689 }
1690
1691 if (DataType >= Ip4Config2DataTypeMaximum) {
1692 return EFI_UNSUPPORTED;
1693 }
1694
1695 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1696
1697 Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);
1698 EventMap = &Instance->DataItem[DataType].EventMap;
1699
1700 //
1701 // Check whether this event is already registered for this DataType.
1702 //
1703 Item = NetMapFindKey (EventMap, Event);
1704 if (Item == NULL) {
1705
1706 Status = NetMapInsertTail (EventMap, Event, NULL);
1707
1708 if (EFI_ERROR (Status)) {
1709
1710 Status = EFI_OUT_OF_RESOURCES;
1711 }
1712
1713 } else {
1714
1715 Status = EFI_ACCESS_DENIED;
1716 }
1717
1718 gBS->RestoreTPL (OldTpl);
1719
1720 return Status;
1721 }
1722
1723 /**
1724 Remove a previously registered event for the specified configuration data.
1725
1726 @param This The pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.
1727 @param DataType The type of data to remove from the previously
1728 registered event.
1729 @param Event The event to be unregistered.
1730
1731 @retval EFI_SUCCESS The event registered for the specified
1732 configuration data was removed.
1733 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
1734 @retval EFI_NOT_FOUND The Event has not been registered for the
1735 specified DataType.
1736
1737 **/
1738 EFI_STATUS
1739 EFIAPI
1740 EfiIp4Config2UnregisterDataNotify (
1741 IN EFI_IP4_CONFIG2_PROTOCOL *This,
1742 IN EFI_IP4_CONFIG2_DATA_TYPE DataType,
1743 IN EFI_EVENT Event
1744 )
1745 {
1746 EFI_TPL OldTpl;
1747 EFI_STATUS Status;
1748 IP4_CONFIG2_INSTANCE *Instance;
1749 NET_MAP_ITEM *Item;
1750
1751 if ((This == NULL) || (Event == NULL)) {
1752 return EFI_INVALID_PARAMETER;
1753 }
1754
1755 if (DataType >= Ip4Config2DataTypeMaximum) {
1756 return EFI_NOT_FOUND;
1757 }
1758
1759 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1760
1761 Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);
1762
1763 Item = NetMapFindKey (&Instance->DataItem[DataType].EventMap, Event);
1764 if (Item != NULL) {
1765
1766 NetMapRemoveItem (&Instance->DataItem[DataType].EventMap, Item, NULL);
1767 Status = EFI_SUCCESS;
1768 } else {
1769
1770 Status = EFI_NOT_FOUND;
1771 }
1772
1773 gBS->RestoreTPL (OldTpl);
1774
1775 return Status;
1776 }
1777
1778 /**
1779 Initialize an IP4_CONFIG2_INSTANCE.
1780
1781 @param[out] Instance The buffer of IP4_CONFIG2_INSTANCE to be initialized.
1782
1783 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1784 @retval EFI_SUCCESS The IP4_CONFIG2_INSTANCE initialized successfully.
1785
1786 **/
1787 EFI_STATUS
1788 Ip4Config2InitInstance (
1789 OUT IP4_CONFIG2_INSTANCE *Instance
1790 )
1791 {
1792 IP4_SERVICE *IpSb;
1793 IP4_CONFIG2_INSTANCE *TmpInstance;
1794 LIST_ENTRY *Entry;
1795 EFI_STATUS Status;
1796 UINTN Index;
1797 UINT16 IfIndex;
1798 IP4_CONFIG2_DATA_ITEM *DataItem;
1799
1800
1801 IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);
1802
1803 Instance->Signature = IP4_CONFIG2_INSTANCE_SIGNATURE;
1804
1805
1806 //
1807 // Determine the index of this interface.
1808 //
1809 IfIndex = 0;
1810 NET_LIST_FOR_EACH (Entry, &mIp4Config2InstanceList) {
1811 TmpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_CONFIG2_INSTANCE, Link, IP4_CONFIG2_INSTANCE_SIGNATURE);
1812
1813 if (TmpInstance->IfIndex > IfIndex) {
1814 //
1815 // There is a sequence hole because some interface is down.
1816 //
1817 break;
1818 }
1819
1820 IfIndex++;
1821 }
1822
1823 Instance->IfIndex = IfIndex;
1824 NetListInsertBefore (Entry, &Instance->Link);
1825
1826 for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {
1827 //
1828 // Initialize the event map for each data item.
1829 //
1830 NetMapInit (&Instance->DataItem[Index].EventMap);
1831 }
1832
1833
1834 //
1835 // Initialize each data type: associate storage and set data size for the
1836 // fixed size data types, hook the SetData function, set the data attribute.
1837 //
1838 DataItem = &Instance->DataItem[Ip4Config2DataTypeInterfaceInfo];
1839 DataItem->GetData = Ip4Config2GetIfInfo;
1840 DataItem->Data.Ptr = &Instance->InterfaceInfo;
1841 DataItem->DataSize = sizeof (Instance->InterfaceInfo);
1842 SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED | DATA_ATTRIB_VOLATILE);
1843 Ip4Config2InitIfInfo (IpSb, &Instance->InterfaceInfo);
1844
1845 DataItem = &Instance->DataItem[Ip4Config2DataTypePolicy];
1846 DataItem->SetData = Ip4Config2SetPolicy;
1847 DataItem->Data.Ptr = &Instance->Policy;
1848 DataItem->DataSize = sizeof (Instance->Policy);
1849 Instance->Policy = Ip4Config2PolicyDhcp;
1850 SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);
1851
1852 DataItem = &Instance->DataItem[Ip4Config2DataTypeManualAddress];
1853 DataItem->SetData = Ip4Config2SetMaunualAddress;
1854 DataItem->Status = EFI_NOT_FOUND;
1855
1856 DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];
1857 DataItem->SetData = Ip4Config2SetGateway;
1858 DataItem->Status = EFI_NOT_FOUND;
1859
1860 DataItem = &Instance->DataItem[Ip4Config2DataTypeDnsServer];
1861 DataItem->SetData = Ip4Config2SetDnsServer;
1862 DataItem->Status = EFI_NOT_FOUND;
1863
1864 //
1865 // Create the event used for DHCP.
1866 //
1867 Status = gBS->CreateEvent (
1868 EVT_NOTIFY_SIGNAL,
1869 TPL_CALLBACK,
1870 Ip4Config2OnDhcp4Event,
1871 Instance,
1872 &Instance->Dhcp4Event
1873 );
1874 ASSERT_EFI_ERROR (Status);
1875
1876 Instance->Configured = TRUE;
1877
1878 //
1879 // Try to read the config data from NV variable.
1880 //
1881 Status = Ip4Config2ReadConfigData (IpSb->MacString, Instance);
1882 if (Status == EFI_NOT_FOUND) {
1883 Status = Ip4Config2WriteConfigData (IpSb->MacString, Instance);
1884 }
1885
1886 if (EFI_ERROR (Status)) {
1887 return Status;
1888 }
1889
1890 //
1891 // Try to set the configured parameter.
1892 //
1893 for (Index = Ip4Config2DataTypePolicy; Index < Ip4Config2DataTypeMaximum; Index++) {
1894 DataItem = &IpSb->Ip4Config2Instance.DataItem[Index];
1895 if (DataItem->Data.Ptr != NULL) {
1896 DataItem->SetData (
1897 &IpSb->Ip4Config2Instance,
1898 DataItem->DataSize,
1899 DataItem->Data.Ptr
1900 );
1901 }
1902 }
1903
1904 Instance->Ip4Config2.SetData = EfiIp4Config2SetData;
1905 Instance->Ip4Config2.GetData = EfiIp4Config2GetData;
1906 Instance->Ip4Config2.RegisterDataNotify = EfiIp4Config2RegisterDataNotify;
1907 Instance->Ip4Config2.UnregisterDataNotify = EfiIp4Config2UnregisterDataNotify;
1908
1909 //
1910 // Publish the IP4 configuration form
1911 //
1912 return Ip4Config2FormInit (Instance);
1913 }
1914
1915
1916 /**
1917 Release an IP4_CONFIG2_INSTANCE.
1918
1919 @param[in, out] Instance The buffer of IP4_CONFIG2_INSTANCE to be freed.
1920
1921 **/
1922 VOID
1923 Ip4Config2CleanInstance (
1924 IN OUT IP4_CONFIG2_INSTANCE *Instance
1925 )
1926 {
1927 UINTN Index;
1928 IP4_CONFIG2_DATA_ITEM *DataItem;
1929
1930 if (Instance->DeclineAddress != NULL) {
1931 FreePool (Instance->DeclineAddress);
1932 }
1933
1934 if (!Instance->Configured) {
1935 return ;
1936 }
1937
1938 if (Instance->Dhcp4Handle != NULL) {
1939
1940 Ip4Config2DestroyDhcp4 (Instance);
1941 }
1942
1943 //
1944 // Close the event.
1945 //
1946 if (Instance->Dhcp4Event != NULL) {
1947 gBS->CloseEvent (Instance->Dhcp4Event);
1948 }
1949
1950 for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {
1951
1952 DataItem = &Instance->DataItem[Index];
1953
1954 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {
1955 if (DataItem->Data.Ptr != NULL) {
1956 FreePool (DataItem->Data.Ptr);
1957 }
1958 DataItem->Data.Ptr = NULL;
1959 DataItem->DataSize = 0;
1960 }
1961
1962 NetMapClean (&Instance->DataItem[Index].EventMap);
1963 }
1964
1965 Ip4Config2FormUnload (Instance);
1966
1967 RemoveEntryList (&Instance->Link);
1968 }
1969