VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip6Dxe/Ip6Driver.c@ 48674

Last change on this file since 48674 was 48674, checked in by vboxsync, 11 years ago

EFI: Export newly imported tinaocore UEFI sources to OSE.

  • Property svn:eol-style set to native
File size: 25.6 KB
Line 
1/** @file
2 The driver binding and service binding protocol for IP6 driver.
3
4 Copyright (c) 2009 - 2011, 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 "Ip6Impl.h"
17
18EFI_DRIVER_BINDING_PROTOCOL gIp6DriverBinding = {
19 Ip6DriverBindingSupported,
20 Ip6DriverBindingStart,
21 Ip6DriverBindingStop,
22 0xa,
23 NULL,
24 NULL
25};
26
27/**
28 This is the declaration of an EFI image entry point. This entry point is
29 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
30 both device drivers and bus drivers.
31
32 The entry point for IP6 driver which installs the driver
33 binding and component name protocol on its image.
34
35 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
36 @param[in] SystemTable A pointer to the EFI System Table.
37
38 @retval EFI_SUCCESS The operation completed successfully.
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
40
41**/
42EFI_STATUS
43EFIAPI
44Ip6DriverEntryPoint (
45 IN EFI_HANDLE ImageHandle,
46 IN EFI_SYSTEM_TABLE *SystemTable
47 )
48{
49 return EfiLibInstallDriverBindingComponentName2 (
50 ImageHandle,
51 SystemTable,
52 &gIp6DriverBinding,
53 ImageHandle,
54 &gIp6ComponentName,
55 &gIp6ComponentName2
56 );
57}
58
59/**
60 Test to see if this driver supports ControllerHandle.
61
62 @param[in] This Protocol instance pointer.
63 @param[in] ControllerHandle Handle of device to test.
64 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
65 device to start.
66
67 @retval EFI_SUCCESS This driver supports this device.
68 @retval EFI_ALREADY_STARTED This driver is already running on this device.
69 @retval other This driver does not support this device.
70
71**/
72EFI_STATUS
73EFIAPI
74Ip6DriverBindingSupported (
75 IN EFI_DRIVER_BINDING_PROTOCOL *This,
76 IN EFI_HANDLE ControllerHandle,
77 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
78 )
79{
80 //
81 // Test for the MNP service binding Protocol
82 //
83 return gBS->OpenProtocol (
84 ControllerHandle,
85 &gEfiManagedNetworkServiceBindingProtocolGuid,
86 NULL,
87 This->DriverBindingHandle,
88 ControllerHandle,
89 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
90 );
91}
92
93/**
94 Clean up an IP6 service binding instance. It releases all
95 the resource allocated by the instance. The instance may be
96 partly initialized, or partly destroyed. If a resource is
97 destroyed, it is marked as that in case the destory failed and
98 being called again later.
99
100 @param[in] IpSb The IP6 service binding instance to clean up.
101
102 @retval EFI_SUCCESS The resource used by the instance are cleaned up.
103 @retval Others Failed to clean up some of the resources.
104
105**/
106EFI_STATUS
107Ip6CleanService (
108 IN IP6_SERVICE *IpSb
109 )
110{
111 EFI_STATUS Status;
112 EFI_IPv6_ADDRESS AllNodes;
113 IP6_NEIGHBOR_ENTRY *NeighborCache;
114
115 Ip6ConfigCleanInstance (&IpSb->Ip6ConfigInstance);
116
117 //
118 // Leave link-scope all-nodes multicast address (FF02::1)
119 //
120 Ip6SetToAllNodeMulticast (FALSE, IP6_LINK_LOCAL_SCOPE, &AllNodes);
121
122 Status = Ip6LeaveGroup (IpSb, &AllNodes);
123 if (EFI_ERROR (Status)) {
124 return Status;
125 }
126
127 if (IpSb->DefaultInterface != NULL) {
128 Ip6CleanInterface (IpSb->DefaultInterface, NULL);
129 IpSb->DefaultInterface = NULL;
130 }
131
132 Ip6CleanDefaultRouterList (IpSb);
133
134 Ip6CleanPrefixListTable (IpSb, &IpSb->OnlinkPrefix);
135 Ip6CleanPrefixListTable (IpSb, &IpSb->AutonomousPrefix);
136
137 if (IpSb->RouteTable != NULL) {
138 Ip6CleanRouteTable (IpSb->RouteTable);
139 IpSb->RouteTable = NULL;
140 }
141
142 if (IpSb->InterfaceId != NULL) {
143 FreePool (IpSb->InterfaceId);
144 }
145
146 IpSb->InterfaceId = NULL;
147
148 Ip6CleanAssembleTable (&IpSb->Assemble);
149
150 if (IpSb->MnpChildHandle != NULL) {
151 if (IpSb->Mnp != NULL) {
152 IpSb->Mnp->Cancel (IpSb->Mnp, NULL);
153 IpSb->Mnp->Configure (IpSb->Mnp, NULL);
154 gBS->CloseProtocol (
155 IpSb->MnpChildHandle,
156 &gEfiManagedNetworkProtocolGuid,
157 IpSb->Image,
158 IpSb->Controller
159 );
160
161 IpSb->Mnp = NULL;
162 }
163
164 NetLibDestroyServiceChild (
165 IpSb->Controller,
166 IpSb->Image,
167 &gEfiManagedNetworkServiceBindingProtocolGuid,
168 IpSb->MnpChildHandle
169 );
170
171 IpSb->MnpChildHandle = NULL;
172 }
173
174 if (IpSb->RecvRequest.MnpToken.Event != NULL) {
175 gBS->CloseEvent (IpSb->RecvRequest.MnpToken.Event);
176 }
177
178 if (IpSb->Timer != NULL) {
179 gBS->SetTimer (IpSb->Timer, TimerCancel, 0);
180 gBS->CloseEvent (IpSb->Timer);
181
182 IpSb->Timer = NULL;
183 }
184
185 if (IpSb->FasterTimer != NULL) {
186 gBS->SetTimer (IpSb->FasterTimer, TimerCancel, 0);
187 gBS->CloseEvent (IpSb->FasterTimer);
188
189 IpSb->FasterTimer = NULL;
190 }
191 //
192 // Free the Neighbor Discovery resources
193 //
194 while (!IsListEmpty (&IpSb->NeighborTable)) {
195 NeighborCache = NET_LIST_HEAD (&IpSb->NeighborTable, IP6_NEIGHBOR_ENTRY, Link);
196 Ip6FreeNeighborEntry (IpSb, NeighborCache, FALSE, TRUE, EFI_SUCCESS, NULL, NULL);
197 }
198
199 return EFI_SUCCESS;
200}
201
202/**
203 Create a new IP6 driver service binding protocol.
204
205 @param[in] Controller The controller that has MNP service binding
206 installed.
207 @param[in] ImageHandle The IP6 driver's image handle.
208 @param[out] Service The variable to receive the newly created IP6
209 service.
210
211 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
212 @retval EFI_SUCCESS A new IP6 service binding private is created.
213
214**/
215EFI_STATUS
216Ip6CreateService (
217 IN EFI_HANDLE Controller,
218 IN EFI_HANDLE ImageHandle,
219 OUT IP6_SERVICE **Service
220 )
221{
222 IP6_SERVICE *IpSb;
223 EFI_STATUS Status;
224 EFI_MANAGED_NETWORK_COMPLETION_TOKEN *MnpToken;
225 EFI_MANAGED_NETWORK_CONFIG_DATA *Config;
226 IP6_CONFIG_DATA_ITEM *DataItem;
227
228 ASSERT (Service != NULL);
229
230 *Service = NULL;
231
232 //
233 // allocate a service private data then initialize all the filed to
234 // empty resources, so if any thing goes wrong when allocating
235 // resources, Ip6CleanService can be called to clean it up.
236 //
237 IpSb = AllocateZeroPool (sizeof (IP6_SERVICE));
238
239 if (IpSb == NULL) {
240 return EFI_OUT_OF_RESOURCES;
241 }
242
243 IpSb->Signature = IP6_SERVICE_SIGNATURE;
244 IpSb->ServiceBinding.CreateChild = Ip6ServiceBindingCreateChild;
245 IpSb->ServiceBinding.DestroyChild = Ip6ServiceBindingDestroyChild;
246 IpSb->State = IP6_SERVICE_UNSTARTED;
247 IpSb->InDestroy = FALSE;
248
249 IpSb->NumChildren = 0;
250 InitializeListHead (&IpSb->Children);
251
252 InitializeListHead (&IpSb->Interfaces);
253 IpSb->DefaultInterface = NULL;
254 IpSb->RouteTable = NULL;
255
256 IpSb->RecvRequest.Signature = IP6_LINK_RX_SIGNATURE;
257 IpSb->RecvRequest.CallBack = NULL;
258 IpSb->RecvRequest.Context = NULL;
259 MnpToken = &IpSb->RecvRequest.MnpToken;
260 MnpToken->Event = NULL;
261 MnpToken->Status = EFI_NOT_READY;
262 MnpToken->Packet.RxData = NULL;
263
264 Ip6CreateAssembleTable (&IpSb->Assemble);
265
266 IpSb->MldCtrl.Mldv1QuerySeen = 0;
267 InitializeListHead (&IpSb->MldCtrl.Groups);
268
269 ZeroMem (&IpSb->LinkLocalAddr, sizeof (EFI_IPv6_ADDRESS));
270 IpSb->LinkLocalOk = FALSE;
271 IpSb->LinkLocalDadFail = FALSE;
272 IpSb->Dhcp6NeedStart = FALSE;
273 IpSb->Dhcp6NeedInfoRequest = FALSE;
274
275 IpSb->CurHopLimit = IP6_HOP_LIMIT;
276 IpSb->LinkMTU = IP6_MIN_LINK_MTU;
277 IpSb->BaseReachableTime = IP6_REACHABLE_TIME;
278 Ip6UpdateReachableTime (IpSb);
279 //
280 // RFC4861 RETRANS_TIMER: 1,000 milliseconds
281 //
282 IpSb->RetransTimer = IP6_RETRANS_TIMER;
283
284 IpSb->RoundRobin = 0;
285
286 InitializeListHead (&IpSb->NeighborTable);
287 InitializeListHead (&IpSb->DefaultRouterList);
288 InitializeListHead (&IpSb->OnlinkPrefix);
289 InitializeListHead (&IpSb->AutonomousPrefix);
290
291 IpSb->InterfaceIdLen = IP6_IF_ID_LEN;
292 IpSb->InterfaceId = NULL;
293
294 IpSb->RouterAdvertiseReceived = FALSE;
295 IpSb->SolicitTimer = IP6_MAX_RTR_SOLICITATIONS;
296 IpSb->Ticks = 0;
297
298 IpSb->Image = ImageHandle;
299 IpSb->Controller = Controller;
300
301 IpSb->MnpChildHandle = NULL;
302 IpSb->Mnp = NULL;
303
304 Config = &IpSb->MnpConfigData;
305 Config->ReceivedQueueTimeoutValue = 0;
306 Config->TransmitQueueTimeoutValue = 0;
307 Config->ProtocolTypeFilter = IP6_ETHER_PROTO;
308 Config->EnableUnicastReceive = TRUE;
309 Config->EnableMulticastReceive = TRUE;
310 Config->EnableBroadcastReceive = TRUE;
311 Config->EnablePromiscuousReceive = FALSE;
312 Config->FlushQueuesOnReset = TRUE;
313 Config->EnableReceiveTimestamps = FALSE;
314 Config->DisableBackgroundPolling = FALSE;
315
316 ZeroMem (&IpSb->SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE));
317
318 IpSb->Timer = NULL;
319 IpSb->FasterTimer = NULL;
320
321 ZeroMem (&IpSb->Ip6ConfigInstance, sizeof (IP6_CONFIG_INSTANCE));
322
323 IpSb->MacString = NULL;
324
325 //
326 // Create various resources. First create the route table, timer
327 // event, MNP token event and MNP child.
328 //
329
330 IpSb->RouteTable = Ip6CreateRouteTable ();
331 if (IpSb->RouteTable == NULL) {
332 Status = EFI_OUT_OF_RESOURCES;
333 goto ON_ERROR;
334 }
335
336 Status = gBS->CreateEvent (
337 EVT_NOTIFY_SIGNAL | EVT_TIMER,
338 TPL_CALLBACK,
339 Ip6TimerTicking,
340 IpSb,
341 &IpSb->Timer
342 );
343 if (EFI_ERROR (Status)) {
344 goto ON_ERROR;
345 }
346
347 Status = gBS->CreateEvent (
348 EVT_NOTIFY_SIGNAL | EVT_TIMER,
349 TPL_CALLBACK,
350 Ip6NdFasterTimerTicking,
351 IpSb,
352 &IpSb->FasterTimer
353 );
354 if (EFI_ERROR (Status)) {
355 goto ON_ERROR;
356 }
357
358 Status = NetLibCreateServiceChild (
359 Controller,
360 ImageHandle,
361 &gEfiManagedNetworkServiceBindingProtocolGuid,
362 &IpSb->MnpChildHandle
363 );
364 if (EFI_ERROR (Status)) {
365 goto ON_ERROR;
366 }
367
368 Status = gBS->OpenProtocol (
369 IpSb->MnpChildHandle,
370 &gEfiManagedNetworkProtocolGuid,
371 (VOID **) (&IpSb->Mnp),
372 ImageHandle,
373 Controller,
374 EFI_OPEN_PROTOCOL_BY_DRIVER
375 );
376 if (EFI_ERROR (Status)) {
377 goto ON_ERROR;
378 }
379
380 Status = Ip6ServiceConfigMnp (IpSb, TRUE);
381 if (EFI_ERROR (Status)) {
382 goto ON_ERROR;
383 }
384
385 Status = IpSb->Mnp->GetModeData (IpSb->Mnp, NULL, &IpSb->SnpMode);
386 if (EFI_ERROR (Status)) {
387 goto ON_ERROR;
388 }
389
390 IpSb->MaxPacketSize = IP6_MIN_LINK_MTU - sizeof (EFI_IP6_HEADER);
391 if (NetLibGetVlanId (IpSb->Controller) != 0) {
392 //
393 // This is a VLAN device, reduce MTU by VLAN tag length
394 //
395 IpSb->MaxPacketSize -= NET_VLAN_TAG_LEN;
396 }
397 IpSb->OldMaxPacketSize = IpSb->MaxPacketSize;
398
399 //
400 // Currently only ETHERNET is supported in IPv6 stack, since
401 // link local address requires an IEEE 802 48-bit MACs for
402 // EUI-64 format interface identifier mapping.
403 //
404 if (IpSb->SnpMode.IfType != NET_IFTYPE_ETHERNET) {
405 Status = EFI_UNSUPPORTED;
406 goto ON_ERROR;
407 }
408
409 Status = Ip6InitMld (IpSb);
410 if (EFI_ERROR (Status)) {
411 goto ON_ERROR;
412 }
413
414 //
415 // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds.
416 //
417 Status = gBS->SetTimer (IpSb->FasterTimer, TimerPeriodic, TICKS_PER_MS * IP6_TIMER_INTERVAL_IN_MS);
418 if (EFI_ERROR (Status)) {
419 goto ON_ERROR;
420 }
421
422 //
423 // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds.
424 //
425 Status = gBS->SetTimer (IpSb->Timer, TimerPeriodic, TICKS_PER_MS * IP6_ONE_SECOND_IN_MS);
426 if (EFI_ERROR (Status)) {
427 goto ON_ERROR;
428 }
429
430
431 Status = gBS->CreateEvent (
432 EVT_NOTIFY_SIGNAL,
433 TPL_NOTIFY,
434 Ip6OnFrameReceived,
435 &IpSb->RecvRequest,
436 &MnpToken->Event
437 );
438 if (EFI_ERROR (Status)) {
439 goto ON_ERROR;
440 }
441
442 Status = Ip6ReceiveFrame (Ip6AcceptFrame, IpSb);
443 if (EFI_ERROR (Status)) {
444 goto ON_ERROR;
445 }
446
447 Status = NetLibGetMacString (IpSb->Controller, IpSb->Image, &IpSb->MacString);
448 if (EFI_ERROR (Status)) {
449 goto ON_ERROR;
450 }
451
452 Status = Ip6ConfigInitInstance (&IpSb->Ip6ConfigInstance);
453 if (EFI_ERROR (Status)) {
454 goto ON_ERROR;
455 }
456
457 IpSb->DefaultInterface = Ip6CreateInterface (IpSb, TRUE);
458 if (IpSb->DefaultInterface == NULL) {
459 Status = EFI_DEVICE_ERROR;
460 goto ON_ERROR;
461 }
462
463 //
464 // If there is any manual address, set it.
465 //
466 DataItem = &IpSb->Ip6ConfigInstance.DataItem[Ip6ConfigDataTypeManualAddress];
467 if (DataItem->Data.Ptr != NULL) {
468 DataItem->SetData (
469 &IpSb->Ip6ConfigInstance,
470 DataItem->DataSize,
471 DataItem->Data.Ptr
472 );
473 }
474
475 InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link);
476
477 *Service = IpSb;
478 return EFI_SUCCESS;
479
480ON_ERROR:
481 Ip6CleanService (IpSb);
482 FreePool (IpSb);
483 return Status;
484}
485
486
487/**
488 Start this driver on ControllerHandle.
489
490 @param[in] This Protocol instance pointer.
491 @param[in] ControllerHandle Handle of device to bind driver to.
492 @param[in] RemainingDevicePath Optional parameter used to pick a specific child
493 device to start.
494
495 @retval EFI_SUCCES This driver is added to ControllerHandle.
496 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
497 @retval other This driver does not support this device.
498
499**/
500EFI_STATUS
501EFIAPI
502Ip6DriverBindingStart (
503 IN EFI_DRIVER_BINDING_PROTOCOL *This,
504 IN EFI_HANDLE ControllerHandle,
505 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
506 )
507{
508 IP6_SERVICE *IpSb;
509 EFI_STATUS Status;
510
511 //
512 // Test for the Ip6 service binding protocol
513 //
514 Status = gBS->OpenProtocol (
515 ControllerHandle,
516 &gEfiIp6ServiceBindingProtocolGuid,
517 NULL,
518 This->DriverBindingHandle,
519 ControllerHandle,
520 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
521 );
522
523 if (Status == EFI_SUCCESS) {
524 return EFI_ALREADY_STARTED;
525 }
526
527 Status = Ip6CreateService (ControllerHandle, This->DriverBindingHandle, &IpSb);
528
529 if (EFI_ERROR (Status)) {
530 return Status;
531 }
532
533 ASSERT (IpSb != NULL);
534
535 //
536 // Install the Ip6ServiceBinding Protocol onto ControlerHandle
537 //
538 Status = gBS->InstallMultipleProtocolInterfaces (
539 &ControllerHandle,
540 &gEfiIp6ServiceBindingProtocolGuid,
541 &IpSb->ServiceBinding,
542 &gEfiIp6ConfigProtocolGuid,
543 &IpSb->Ip6ConfigInstance.Ip6Config,
544 NULL
545 );
546
547 if (EFI_ERROR (Status)) {
548
549 Ip6CleanService (IpSb);
550 FreePool (IpSb);
551 } else {
552 //
553 // Initialize the IP6 ID
554 //
555 mIp6Id = NET_RANDOM (NetRandomInitSeed ());
556
557 Ip6SetVariableData (IpSb);
558 }
559
560 return Status;
561}
562
563/**
564 Stop this driver on ControllerHandle.
565
566 @param[in] This Protocol instance pointer.
567 @param[in] ControllerHandle Handle of device to stop driver on.
568 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
569 of children is zero, stop the entire bus driver.
570 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
571 if NumberOfChildren is 0.
572
573 @retval EFI_SUCCESS The device was stopped.
574 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
575
576**/
577EFI_STATUS
578EFIAPI
579Ip6DriverBindingStop (
580 IN EFI_DRIVER_BINDING_PROTOCOL *This,
581 IN EFI_HANDLE ControllerHandle,
582 IN UINTN NumberOfChildren,
583 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
584 )
585{
586 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
587 IP6_SERVICE *IpSb;
588 IP6_PROTOCOL *IpInstance;
589 EFI_HANDLE NicHandle;
590 EFI_STATUS Status;
591 BOOLEAN IsDhcp6;
592 EFI_TPL OldTpl;
593 INTN State;
594
595 IsDhcp6 = FALSE;
596 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiDhcp6ProtocolGuid);
597
598 if (NicHandle != NULL) {
599 //
600 // DriverBindingStop is triggered by the uninstallation of the EFI DHCPv6
601 // Protocol used by Ip6Config.
602 //
603 IsDhcp6 = TRUE;
604 } else {
605
606 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiManagedNetworkProtocolGuid);
607
608 if (NicHandle == NULL) {
609 return EFI_DEVICE_ERROR;
610 }
611 }
612
613 Status = gBS->OpenProtocol (
614 NicHandle,
615 &gEfiIp6ServiceBindingProtocolGuid,
616 (VOID **) &ServiceBinding,
617 This->DriverBindingHandle,
618 NicHandle,
619 EFI_OPEN_PROTOCOL_GET_PROTOCOL
620 );
621 if (EFI_ERROR (Status)) {
622 return EFI_DEVICE_ERROR;
623 }
624
625 IpSb = IP6_SERVICE_FROM_PROTOCOL (ServiceBinding);
626
627 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
628
629 if (IpSb->InDestroy) {
630 Status = EFI_SUCCESS;
631 goto Exit;
632 }
633
634 if (IsDhcp6) {
635
636 Status = Ip6ConfigDestroyDhcp6 (&IpSb->Ip6ConfigInstance);
637 gBS->CloseEvent (IpSb->Ip6ConfigInstance.Dhcp6Event);
638 IpSb->Ip6ConfigInstance.Dhcp6Event = NULL;
639 } else if (NumberOfChildren == 0) {
640
641 IpSb->InDestroy = TRUE;
642 State = IpSb->State;
643 IpSb->State = IP6_SERVICE_DESTROY;
644
645 //
646 // Clear the variable data.
647 //
648 Ip6ClearVariableData (IpSb);
649
650 Status = Ip6CleanService (IpSb);
651 if (EFI_ERROR (Status)) {
652 IpSb->State = State;
653 goto Exit;
654 }
655
656 Status = gBS->UninstallMultipleProtocolInterfaces (
657 NicHandle,
658 &gEfiIp6ServiceBindingProtocolGuid,
659 ServiceBinding,
660 &gEfiIp6ConfigProtocolGuid,
661 &IpSb->Ip6ConfigInstance.Ip6Config,
662 NULL
663 );
664 ASSERT_EFI_ERROR (Status);
665 FreePool (IpSb);
666 } else {
667 //
668 // NumberOfChildren is not zero, destroy all IP6 children instances.
669 //
670 while (!IsListEmpty (&IpSb->Children)) {
671 IpInstance = NET_LIST_HEAD (&IpSb->Children, IP6_PROTOCOL, Link);
672 ServiceBinding->DestroyChild (ServiceBinding, IpInstance->Handle);
673 }
674
675 if (IpSb->NumChildren != 0) {
676 Status = EFI_DEVICE_ERROR;
677 }
678 }
679
680Exit:
681
682 gBS->RestoreTPL (OldTpl);
683
684 return Status;
685}
686
687
688/**
689 Creates a child handle with a set of I/O services.
690
691 @param[in] This Protocol instance pointer.
692 @param[in] ChildHandle Pointer to the handle of the child to create. If
693 it is NULL, then a new handle is created. If it
694 is not NULL, then the I/O services are added to
695 the existing child handle.
696
697 @retval EFI_SUCCES The child handle was created with the I/O services.
698 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
699 the child.
700 @retval other The child handle was not created.
701
702**/
703EFI_STATUS
704EFIAPI
705Ip6ServiceBindingCreateChild (
706 IN EFI_SERVICE_BINDING_PROTOCOL *This,
707 IN EFI_HANDLE *ChildHandle
708 )
709{
710 IP6_SERVICE *IpSb;
711 IP6_PROTOCOL *IpInstance;
712 EFI_TPL OldTpl;
713 EFI_STATUS Status;
714 VOID *Mnp;
715
716 if ((This == NULL) || (ChildHandle == NULL)) {
717 return EFI_INVALID_PARAMETER;
718 }
719
720 IpSb = IP6_SERVICE_FROM_PROTOCOL (This);
721
722 if (IpSb->LinkLocalDadFail) {
723 return EFI_DEVICE_ERROR;
724 }
725
726 IpInstance = AllocatePool (sizeof (IP6_PROTOCOL));
727
728 if (IpInstance == NULL) {
729 return EFI_OUT_OF_RESOURCES;
730 }
731
732 Ip6InitProtocol (IpSb, IpInstance);
733
734 //
735 // Install Ip6 onto ChildHandle
736 //
737 Status = gBS->InstallMultipleProtocolInterfaces (
738 ChildHandle,
739 &gEfiIp6ProtocolGuid,
740 &IpInstance->Ip6Proto,
741 NULL
742 );
743 if (EFI_ERROR (Status)) {
744 goto ON_ERROR;
745 }
746
747 IpInstance->Handle = *ChildHandle;
748
749 //
750 // Open the Managed Network protocol BY_CHILD.
751 //
752 Status = gBS->OpenProtocol (
753 IpSb->MnpChildHandle,
754 &gEfiManagedNetworkProtocolGuid,
755 (VOID **) &Mnp,
756 gIp6DriverBinding.DriverBindingHandle,
757 IpInstance->Handle,
758 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
759 );
760 if (EFI_ERROR (Status)) {
761 gBS->UninstallMultipleProtocolInterfaces (
762 ChildHandle,
763 &gEfiIp6ProtocolGuid,
764 &IpInstance->Ip6Proto,
765 NULL
766 );
767
768 goto ON_ERROR;
769 }
770
771 //
772 // Insert it into the service binding instance.
773 //
774 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
775
776 InsertTailList (&IpSb->Children, &IpInstance->Link);
777 IpSb->NumChildren++;
778
779 gBS->RestoreTPL (OldTpl);
780
781ON_ERROR:
782
783 if (EFI_ERROR (Status)) {
784
785 Ip6CleanProtocol (IpInstance);
786
787 FreePool (IpInstance);
788 }
789
790 return Status;
791}
792
793/**
794 Destroys a child handle with a set of I/O services.
795
796 @param[in] This Protocol instance pointer.
797 @param[in] ChildHandle Handle of the child to destroy.
798
799 @retval EFI_SUCCES The I/O services were removed from the child
800 handle.
801 @retval EFI_UNSUPPORTED The child handle does not support the I/O services
802 that are being removed.
803 @retval EFI_INVALID_PARAMETER Child handle is NULL.
804 @retval EFI_ACCESS_DENIED The child handle could not be destroyed because
805 its I/O services are being used.
806 @retval other The child handle was not destroyed.
807
808**/
809EFI_STATUS
810EFIAPI
811Ip6ServiceBindingDestroyChild (
812 IN EFI_SERVICE_BINDING_PROTOCOL *This,
813 IN EFI_HANDLE ChildHandle
814 )
815{
816 EFI_STATUS Status;
817 IP6_SERVICE *IpSb;
818 IP6_PROTOCOL *IpInstance;
819 EFI_IP6_PROTOCOL *Ip6;
820 EFI_TPL OldTpl;
821 INTN State;
822
823 if ((This == NULL) || (ChildHandle == NULL)) {
824 return EFI_INVALID_PARAMETER;
825 }
826
827 //
828 // Retrieve the private context data structures
829 //
830 IpSb = IP6_SERVICE_FROM_PROTOCOL (This);
831
832 Status = gBS->OpenProtocol (
833 ChildHandle,
834 &gEfiIp6ProtocolGuid,
835 (VOID **) &Ip6,
836 gIp6DriverBinding.DriverBindingHandle,
837 ChildHandle,
838 EFI_OPEN_PROTOCOL_GET_PROTOCOL
839 );
840
841 if (EFI_ERROR (Status)) {
842 return EFI_UNSUPPORTED;
843 }
844
845 IpInstance = IP6_INSTANCE_FROM_PROTOCOL (Ip6);
846
847 if (IpInstance->Service != IpSb) {
848 return EFI_INVALID_PARAMETER;
849 }
850
851 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
852
853 //
854 // A child can be destroyed more than once. For example,
855 // Ip6DriverBindingStop will destory all of its children.
856 // when UDP driver is being stopped, it will destory all
857 // the IP child it opens.
858 //
859 if (IpInstance->State == IP6_STATE_DESTROY) {
860 gBS->RestoreTPL (OldTpl);
861 return EFI_SUCCESS;
862 }
863
864 State = IpInstance->State;
865 IpInstance->State = IP6_STATE_DESTROY;
866
867 //
868 // Close the Managed Network protocol.
869 //
870 gBS->CloseProtocol (
871 IpSb->MnpChildHandle,
872 &gEfiManagedNetworkProtocolGuid,
873 gIp6DriverBinding.DriverBindingHandle,
874 ChildHandle
875 );
876
877 //
878 // Uninstall the IP6 protocol first. Many thing happens during
879 // this:
880 // 1. The consumer of the IP6 protocol will be stopped if it
881 // opens the protocol BY_DRIVER. For eaxmple, if MNP driver is
882 // stopped, IP driver's stop function will be called, and uninstall
883 // EFI_IP6_PROTOCOL will trigger the UDP's stop function. This
884 // makes it possible to create the network stack bottom up, and
885 // stop it top down.
886 // 2. the upper layer will recycle the received packet. The recycle
887 // event's TPL is higher than this function. The recycle events
888 // will be called back before preceeding. If any packets not recycled,
889 // that means there is a resource leak.
890 //
891 Status = gBS->UninstallProtocolInterface (
892 ChildHandle,
893 &gEfiIp6ProtocolGuid,
894 &IpInstance->Ip6Proto
895 );
896
897 if (EFI_ERROR (Status)) {
898 goto ON_ERROR;
899 }
900
901 Status = Ip6CleanProtocol (IpInstance);
902
903 Ip6SetVariableData (IpSb);
904
905 if (EFI_ERROR (Status)) {
906 gBS->InstallMultipleProtocolInterfaces (
907 &ChildHandle,
908 &gEfiIp6ProtocolGuid,
909 Ip6,
910 NULL
911 );
912
913 goto ON_ERROR;
914 }
915
916 RemoveEntryList (&IpInstance->Link);
917 ASSERT (IpSb->NumChildren > 0);
918 IpSb->NumChildren--;
919
920 gBS->RestoreTPL (OldTpl);
921
922 FreePool (IpInstance);
923 return EFI_SUCCESS;
924
925ON_ERROR:
926 IpInstance->State = State;
927 gBS->RestoreTPL (OldTpl);
928
929 return Status;
930}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette