]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
a29b6bc434b66c8a687e1dc1b140774631fa6179
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Driver.c
1 /** @file
2 Tcp driver function.
3
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php<BR>
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "Tcp4Main.h"
16
17
18 UINT16 mTcp4RandomPort;
19 extern EFI_COMPONENT_NAME_PROTOCOL gTcp4ComponentName;
20 extern EFI_COMPONENT_NAME2_PROTOCOL gTcp4ComponentName2;
21
22 TCP4_HEARTBEAT_TIMER mTcp4Timer = {
23 NULL,
24 0
25 };
26
27 EFI_TCP4_PROTOCOL mTcp4ProtocolTemplate = {
28 Tcp4GetModeData,
29 Tcp4Configure,
30 Tcp4Routes,
31 Tcp4Connect,
32 Tcp4Accept,
33 Tcp4Transmit,
34 Tcp4Receive,
35 Tcp4Close,
36 Tcp4Cancel,
37 Tcp4Poll
38 };
39
40 SOCK_INIT_DATA mTcp4DefaultSockData = {
41 SockStream,
42 0,
43 NULL,
44 TCP_BACKLOG,
45 TCP_SND_BUF_SIZE,
46 TCP_RCV_BUF_SIZE,
47 &mTcp4ProtocolTemplate,
48 Tcp4CreateSocketCallback,
49 Tcp4DestroySocketCallback,
50 NULL,
51 NULL,
52 0,
53 Tcp4Dispatcher,
54 NULL,
55 };
56
57 EFI_DRIVER_BINDING_PROTOCOL mTcp4DriverBinding = {
58 Tcp4DriverBindingSupported,
59 Tcp4DriverBindingStart,
60 Tcp4DriverBindingStop,
61 0xa,
62 NULL,
63 NULL
64 };
65
66 EFI_SERVICE_BINDING_PROTOCOL mTcp4ServiceBinding = {
67 Tcp4ServiceBindingCreateChild,
68 Tcp4ServiceBindingDestroyChild
69 };
70
71
72 /**
73 Create and start the heartbeat timer for TCP driver.
74
75 @retval EFI_SUCCESS The timer is successfully created and started.
76 @retval other The timer is not created.
77
78 **/
79 EFI_STATUS
80 Tcp4CreateTimer (
81 VOID
82 )
83 {
84 EFI_STATUS Status;
85
86 Status = EFI_SUCCESS;
87
88 if (mTcp4Timer.RefCnt == 0) {
89
90 Status = gBS->CreateEvent (
91 EVT_TIMER | EVT_NOTIFY_SIGNAL,
92 TPL_NOTIFY,
93 TcpTicking,
94 NULL,
95 &mTcp4Timer.TimerEvent
96 );
97 if (!EFI_ERROR (Status)) {
98
99 Status = gBS->SetTimer (
100 mTcp4Timer.TimerEvent,
101 TimerPeriodic,
102 (UINT64) (TICKS_PER_SECOND / TCP_TICK_HZ)
103 );
104 }
105 }
106
107 if (!EFI_ERROR (Status)) {
108
109 mTcp4Timer.RefCnt++;
110 }
111
112 return Status;
113 }
114
115
116 /**
117 Stop and destroy the heartbeat timer for TCP driver.
118
119 **/
120 VOID
121 Tcp4DestroyTimer (
122 VOID
123 )
124 {
125 ASSERT (mTcp4Timer.RefCnt > 0);
126
127 mTcp4Timer.RefCnt--;
128
129 if (mTcp4Timer.RefCnt > 0) {
130 return;
131 }
132
133 gBS->SetTimer (mTcp4Timer.TimerEvent, TimerCancel, 0);
134 gBS->CloseEvent (mTcp4Timer.TimerEvent);
135 mTcp4Timer.TimerEvent = NULL;
136 }
137
138 /**
139 The entry point for Tcp4 driver, used to install Tcp4 driver on the ImageHandle.
140
141 @param ImageHandle The firmware allocated handle for this
142 driver image.
143 @param SystemTable Pointer to the EFI system table.
144
145 @retval EFI_SUCCESS Driver loaded.
146 @retval other Driver not loaded.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 Tcp4DriverEntryPoint (
152 IN EFI_HANDLE ImageHandle,
153 IN EFI_SYSTEM_TABLE *SystemTable
154 )
155 {
156 EFI_STATUS Status;
157 UINT32 Seed;
158
159 //
160 // Install the TCP4 Driver Binding Protocol
161 //
162 Status = EfiLibInstallDriverBindingComponentName2 (
163 ImageHandle,
164 SystemTable,
165 &mTcp4DriverBinding,
166 ImageHandle,
167 &gTcp4ComponentName,
168 &gTcp4ComponentName2
169 );
170 ASSERT_EFI_ERROR (Status);
171 //
172 // Initialize ISS and random port.
173 //
174 Seed = NetRandomInitSeed ();
175 mTcpGlobalIss = NET_RANDOM (Seed) % mTcpGlobalIss;
176 mTcp4RandomPort = (UINT16) (TCP4_PORT_KNOWN +
177 (UINT16) (NET_RANDOM(Seed) % TCP4_PORT_KNOWN));
178
179 return Status;
180 }
181
182
183 /**
184 Tests to see if this driver supports a given controller.
185
186 If a child device is provided, it further tests to see if this driver supports
187 creating a handle for the specified child device.
188
189 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
190 @param ControllerHandle The handle of the controller to test. This handle
191 must support a protocol interface that supplies
192 an I/O abstraction to the driver.
193 @param RemainingDevicePath A pointer to the remaining portion of a device path.
194 This parameter is ignored by device drivers, and is optional for bus drivers.
195
196
197 @retval EFI_SUCCESS The device specified by ControllerHandle and
198 RemainingDevicePath is supported by the driver
199 specified by This.
200 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
201 RemainingDevicePath is already being managed by
202 the driver specified by This.
203 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
204 RemainingDevicePath is already being managed by a
205 different driver or an application that requires
206 exclusive access.
207 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
208 RemainingDevicePath is not supported by the driver
209 specified by This.
210
211 **/
212 EFI_STATUS
213 EFIAPI
214 Tcp4DriverBindingSupported (
215 IN EFI_DRIVER_BINDING_PROTOCOL *This,
216 IN EFI_HANDLE ControllerHandle,
217 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
218 )
219 {
220 EFI_STATUS Status;
221
222 //
223 // Test for the Tcp4ServiceBinding Protocol
224 //
225 Status = gBS->OpenProtocol (
226 ControllerHandle,
227 &gEfiTcp4ServiceBindingProtocolGuid,
228 NULL,
229 This->DriverBindingHandle,
230 ControllerHandle,
231 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
232 );
233 if (!EFI_ERROR (Status)) {
234 return EFI_ALREADY_STARTED;
235 }
236
237 //
238 // Test for the Ip4 Protocol
239 //
240 Status = gBS->OpenProtocol (
241 ControllerHandle,
242 &gEfiIp4ServiceBindingProtocolGuid,
243 NULL,
244 This->DriverBindingHandle,
245 ControllerHandle,
246 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
247 );
248
249 return Status;
250 }
251
252
253 /**
254 Start this driver on ControllerHandle.
255
256 The Start() function is designed to be invoked from the EFI boot service
257 ConnectController(). As a result, much of the error checking on the parameters
258 to Start() has been moved into this common boot service. It is legal to call
259 Start() from other locations, but the following calling restrictions must be
260 followed or the system behavior will not be deterministic.
261 1. ControllerHandle must be a valid EFI_HANDLE.
262 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally
263 aligned EFI_DEVICE_PATH_PROTOCOL.
264 3. Prior to calling Start(), the Supported() function for the driver specified
265 by This must have been called with the same calling parameters, and Supported()
266 must have returned EFI_SUCCESS.
267
268 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
269 @param ControllerHandle The handle of the controller to start. This handle
270 must support a protocol interface that supplies
271 an I/O abstraction to the driver.
272 @param RemainingDevicePath A pointer to the remaining portion of a device path.
273 This parameter is ignored by device drivers, and is
274 optional for bus drivers.
275
276 @retval EFI_SUCCESS The device was started.
277 @retval EFI_ALREADY_STARTED The device could not be started due to a device error.
278 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
279 of resources.
280
281 **/
282 EFI_STATUS
283 EFIAPI
284 Tcp4DriverBindingStart (
285 IN EFI_DRIVER_BINDING_PROTOCOL *This,
286 IN EFI_HANDLE ControllerHandle,
287 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
288 )
289 {
290 EFI_STATUS Status;
291 TCP4_SERVICE_DATA *TcpServiceData;
292 IP_IO_OPEN_DATA OpenData;
293
294 TcpServiceData = AllocateZeroPool (sizeof (TCP4_SERVICE_DATA));
295
296 if (NULL == TcpServiceData) {
297 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough"
298 " resource to create a Tcp Servcie Data\n"));
299
300 return EFI_OUT_OF_RESOURCES;
301 }
302
303 //
304 // Create a new IP IO to Consume it
305 //
306 TcpServiceData->IpIo = IpIoCreate (
307 This->DriverBindingHandle,
308 ControllerHandle,
309 IP_VERSION_4
310 );
311 if (NULL == TcpServiceData->IpIo) {
312
313 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough"
314 " resource to create an Ip Io\n"));
315
316 Status = EFI_OUT_OF_RESOURCES;
317 goto ON_ERROR;
318 }
319
320 //
321 // Configure and start IpIo.
322 //
323 ZeroMem (&OpenData, sizeof (IP_IO_OPEN_DATA));
324
325 CopyMem (
326 &OpenData.IpConfigData.Ip4CfgData,
327 &mIp4IoDefaultIpConfigData,
328 sizeof (EFI_IP4_CONFIG_DATA)
329 );
330
331 OpenData.IpConfigData.Ip4CfgData.DefaultProtocol = EFI_IP_PROTO_TCP;
332
333 OpenData.PktRcvdNotify = Tcp4RxCallback;
334 Status = IpIoOpen (TcpServiceData->IpIo, &OpenData);
335
336 if (EFI_ERROR (Status)) {
337 goto ON_ERROR;
338 }
339
340 //
341 // Create the timer event used by TCP driver
342 //
343 Status = Tcp4CreateTimer ();
344 if (EFI_ERROR (Status)) {
345
346 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Create TcpTimer"
347 " Event failed with %r\n", Status));
348
349 goto ON_ERROR;
350 }
351
352 //
353 // Install the Tcp4ServiceBinding Protocol on the
354 // controller handle
355 //
356 TcpServiceData->Tcp4ServiceBinding = mTcp4ServiceBinding;
357
358 Status = gBS->InstallMultipleProtocolInterfaces (
359 &ControllerHandle,
360 &gEfiTcp4ServiceBindingProtocolGuid,
361 &TcpServiceData->Tcp4ServiceBinding,
362 NULL
363 );
364 if (EFI_ERROR (Status)) {
365
366 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Install Tcp4 Service Binding"
367 " Protocol failed for %r\n", Status));
368
369 Tcp4DestroyTimer ();
370 goto ON_ERROR;
371 }
372
373 //
374 // Initialize member in TcpServiceData
375 //
376 TcpServiceData->ControllerHandle = ControllerHandle;
377 TcpServiceData->Signature = TCP4_DRIVER_SIGNATURE;
378 TcpServiceData->DriverBindingHandle = This->DriverBindingHandle;
379
380 InitializeListHead (&TcpServiceData->SocketList);
381
382 TcpSetVariableData (TcpServiceData);
383
384 return EFI_SUCCESS;
385
386 ON_ERROR:
387
388 if (TcpServiceData->IpIo != NULL) {
389 IpIoDestroy (TcpServiceData->IpIo);
390 }
391
392 FreePool (TcpServiceData);
393
394 return Status;
395 }
396
397
398 /**
399 Stop this driver on ControllerHandle.
400
401 The Stop() function is designed to be invoked from the EFI boot service
402 DisconnectController(). As a result, much of the error checking on the parameters
403 to Stop() has been moved into this common boot service. It is legal to call Stop()
404 from other locations, but the following calling restrictions must be followed
405 or the system behavior will not be deterministic.
406 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call
407 to this same driver's Start() function.
408 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
409 EFI_HANDLE. In addition, all of these handles must have been created in this
410 driver's Start() function, and the Start() function must have called OpenProtocol()
411 on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
412
413 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
414 @param ControllerHandle A handle to the device being stopped. The handle must
415 support a bus specific I/O protocol for the driver
416 to use to stop the device.
417 @param NumberOfChildren The number of child device handles in ChildHandleBuffer.
418 @param ChildHandleBuffer An array of child handles to be freed. May be NULL if
419 NumberOfChildren is 0.
420
421 @retval EFI_SUCCESS The device was stopped.
422 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
423
424 **/
425 EFI_STATUS
426 EFIAPI
427 Tcp4DriverBindingStop (
428 IN EFI_DRIVER_BINDING_PROTOCOL *This,
429 IN EFI_HANDLE ControllerHandle,
430 IN UINTN NumberOfChildren,
431 IN EFI_HANDLE *ChildHandleBuffer
432 )
433 {
434 EFI_STATUS Status;
435 EFI_HANDLE NicHandle;
436 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
437 TCP4_SERVICE_DATA *TcpServiceData;
438 SOCKET *Sock;
439
440 // Find the NicHandle where Tcp4 ServiceBinding Protocol is installed.
441 //
442 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);
443 if (NicHandle == NULL) {
444 return EFI_DEVICE_ERROR;
445 }
446
447 //
448 // Retrieve the TCP driver Data Structure
449 //
450 Status = gBS->OpenProtocol (
451 NicHandle,
452 &gEfiTcp4ServiceBindingProtocolGuid,
453 (VOID **) &ServiceBinding,
454 This->DriverBindingHandle,
455 ControllerHandle,
456 EFI_OPEN_PROTOCOL_GET_PROTOCOL
457 );
458 if (EFI_ERROR (Status)) {
459
460 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStop: Locate Tcp4 Service "
461 " Binding Protocol failed with %r\n", Status));
462
463 return EFI_DEVICE_ERROR;
464 }
465
466 TcpServiceData = TCP4_FROM_THIS (ServiceBinding);
467
468 if (NumberOfChildren == 0) {
469 //
470 // Uninstall TCP servicebinding protocol
471 //
472 gBS->UninstallMultipleProtocolInterfaces (
473 NicHandle,
474 &gEfiTcp4ServiceBindingProtocolGuid,
475 ServiceBinding,
476 NULL
477 );
478
479 //
480 // Destroy the IpIO consumed by TCP driver
481 //
482 IpIoDestroy (TcpServiceData->IpIo);
483
484 //
485 // Destroy the heartbeat timer.
486 //
487 Tcp4DestroyTimer ();
488
489 //
490 // Clear the variable.
491 //
492 TcpClearVariableData (TcpServiceData);
493
494 //
495 // Release the TCP service data
496 //
497 FreePool (TcpServiceData);
498 } else {
499
500 while (!IsListEmpty (&TcpServiceData->SocketList)) {
501 Sock = NET_LIST_HEAD (&TcpServiceData->SocketList, SOCKET, Link);
502
503 ServiceBinding->DestroyChild (ServiceBinding, Sock->SockHandle);
504 }
505 }
506
507 return Status;
508 }
509
510 /**
511 Open Ip4 and device path protocols for a created socket, and insert it in
512 socket list.
513
514 @param This Pointer to the socket just created
515 @param Context Context of the socket
516
517 @retval EFI_SUCCESS This protocol is installed successfully.
518 @retval other Some error occured.
519
520 **/
521 EFI_STATUS
522 Tcp4CreateSocketCallback (
523 IN SOCKET *This,
524 IN VOID *Context
525 )
526 {
527 EFI_STATUS Status;
528 TCP4_SERVICE_DATA *TcpServiceData;
529 EFI_IP4_PROTOCOL *Ip4;
530
531 TcpServiceData = ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpService;
532
533 //
534 // Open the default Ip4 protocol of IP_IO BY_DRIVER.
535 //
536 Status = gBS->OpenProtocol (
537 TcpServiceData->IpIo->ChildHandle,
538 &gEfiIp4ProtocolGuid,
539 (VOID **) &Ip4,
540 TcpServiceData->DriverBindingHandle,
541 This->SockHandle,
542 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
543 );
544 if (EFI_ERROR (Status)) {
545 return Status;
546 }
547
548 //
549 // Open the device path on the handle where service binding resides on.
550 //
551 Status = gBS->OpenProtocol (
552 TcpServiceData->ControllerHandle,
553 &gEfiDevicePathProtocolGuid,
554 (VOID **) &This->ParentDevicePath,
555 TcpServiceData->DriverBindingHandle,
556 This->SockHandle,
557 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
558 );
559 if (EFI_ERROR (Status)) {
560 gBS->CloseProtocol (
561 TcpServiceData->IpIo->ChildHandle,
562 &gEfiIp4ProtocolGuid,
563 TcpServiceData->DriverBindingHandle,
564 This->SockHandle
565 );
566 } else {
567 //
568 // Insert this socket into the SocketList.
569 //
570 InsertTailList (&TcpServiceData->SocketList, &This->Link);
571 }
572
573 return Status;
574 }
575
576 /**
577 Close Ip4 and device path protocols for a socket, and remove it from socket list.
578
579 @param This Pointer to the socket to be removed
580 @param Context Context of the socket
581
582 **/
583 VOID
584 Tcp4DestroySocketCallback (
585 IN SOCKET *This,
586 IN VOID *Context
587 )
588 {
589 TCP4_SERVICE_DATA *TcpServiceData;
590
591 TcpServiceData = ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpService;
592
593 //
594 // Remove this node from the list.
595 //
596 RemoveEntryList (&This->Link);
597
598 //
599 // Close the device path protocol
600 //
601 gBS->CloseProtocol (
602 TcpServiceData->ControllerHandle,
603 &gEfiDevicePathProtocolGuid,
604 TcpServiceData->DriverBindingHandle,
605 This->SockHandle
606 );
607
608 //
609 // Close the Ip4 protocol.
610 //
611 gBS->CloseProtocol (
612 TcpServiceData->IpIo->ChildHandle,
613 &gEfiIp4ProtocolGuid,
614 TcpServiceData->DriverBindingHandle,
615 This->SockHandle
616 );
617 }
618
619 /**
620 Creates a child handle and installs a protocol.
621
622 The CreateChild() function installs a protocol on ChildHandle. If ChildHandle
623 is a pointer to NULL, then a new handle is created and returned in ChildHandle.
624 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing
625 ChildHandle.
626
627 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
628 @param ChildHandle Pointer to the handle of the child to create. If it is NULL, then
629 a new handle is created. If it is a pointer to an existing UEFI
630 handle, then the protocol is added to the existing UEFI handle.
631
632 @retval EFI_SUCCES The protocol was added to ChildHandle.
633 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
634 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
635 the child.
636 @retval other The child handle was not created.
637
638 **/
639 EFI_STATUS
640 EFIAPI
641 Tcp4ServiceBindingCreateChild (
642 IN EFI_SERVICE_BINDING_PROTOCOL *This,
643 IN OUT EFI_HANDLE *ChildHandle
644 )
645 {
646 SOCKET *Sock;
647 TCP4_SERVICE_DATA *TcpServiceData;
648 TCP4_PROTO_DATA TcpProto;
649 EFI_STATUS Status;
650 EFI_TPL OldTpl;
651
652 if (NULL == This || NULL == ChildHandle) {
653 return EFI_INVALID_PARAMETER;
654 }
655
656 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
657 Status = EFI_SUCCESS;
658 TcpServiceData = TCP4_FROM_THIS (This);
659 TcpProto.TcpService = TcpServiceData;
660 TcpProto.TcpPcb = NULL;
661
662 //
663 // Create a tcp instance with defualt Tcp default
664 // sock init data and TcpProto
665 //
666 mTcp4DefaultSockData.ProtoData = &TcpProto;
667 mTcp4DefaultSockData.DataSize = sizeof (TCP4_PROTO_DATA);
668 mTcp4DefaultSockData.DriverBinding = TcpServiceData->DriverBindingHandle;
669
670 Sock = SockCreateChild (&mTcp4DefaultSockData);
671 if (NULL == Sock) {
672 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingCreateChild: "
673 "No resource to create a Tcp Child\n"));
674
675 Status = EFI_OUT_OF_RESOURCES;
676 } else {
677 *ChildHandle = Sock->SockHandle;
678 }
679
680 mTcp4DefaultSockData.ProtoData = NULL;
681
682 gBS->RestoreTPL (OldTpl);
683 return Status;
684 }
685
686
687 /**
688 Destroys a child handle with a protocol installed on it.
689
690 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
691 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
692 last protocol on ChildHandle, then ChildHandle is destroyed.
693
694 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
695 @param ChildHandle Handle of the child to destroy
696
697 @retval EFI_SUCCES The protocol was removed from ChildHandle.
698 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is
699 being removed.
700 @retval EFI_INVALID_PARAMETER Child handle is NULL.
701 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
702 because its services are being used.
703 @retval other The child handle was not destroyed.
704
705 **/
706 EFI_STATUS
707 EFIAPI
708 Tcp4ServiceBindingDestroyChild (
709 IN EFI_SERVICE_BINDING_PROTOCOL *This,
710 IN EFI_HANDLE ChildHandle
711 )
712 {
713 EFI_STATUS Status;
714 EFI_TCP4_PROTOCOL *Tcp4;
715 SOCKET *Sock;
716 EFI_TPL OldTpl;
717
718 if (NULL == This || NULL == ChildHandle) {
719 return EFI_INVALID_PARAMETER;
720 }
721
722 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
723
724 //
725 // retrieve the Tcp4 protocol from ChildHandle
726 //
727 Status = gBS->OpenProtocol (
728 ChildHandle,
729 &gEfiTcp4ProtocolGuid,
730 (VOID **) &Tcp4,
731 mTcp4DriverBinding.DriverBindingHandle,
732 ChildHandle,
733 EFI_OPEN_PROTOCOL_GET_PROTOCOL
734 );
735 if (EFI_ERROR (Status)) {
736 Status = EFI_UNSUPPORTED;
737 } else {
738 //
739 // destroy this sock and related Tcp protocol control
740 // block
741 //
742 Sock = SOCK_FROM_THIS (Tcp4);
743
744 SockDestroyChild (Sock);
745 }
746
747 gBS->RestoreTPL (OldTpl);
748 return Status;
749 }
750