]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
Insert comments for functions/macros and add the file headers.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Driver.c
1 /** @file
2 Tcp driver function.
3
4 Copyright (c) 2005 - 2007, Intel Corporation<BR>
5 All rights reserved. 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 SOCK_STREAM,
42 (SOCK_STATE) 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 (This->DriverBindingHandle, ControllerHandle);
307 if (NULL == TcpServiceData->IpIo) {
308
309 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough"
310 " resource to create an Ip Io\n"));
311
312 Status = EFI_OUT_OF_RESOURCES;
313 goto ON_ERROR;
314 }
315
316 //
317 // Configure and start IpIo.
318 //
319 ZeroMem (&OpenData, sizeof (IP_IO_OPEN_DATA));
320
321 CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData));
322 OpenData.IpConfigData.DefaultProtocol = EFI_IP_PROTO_TCP;
323
324 OpenData.PktRcvdNotify = Tcp4RxCallback;
325 Status = IpIoOpen (TcpServiceData->IpIo, &OpenData);
326
327 if (EFI_ERROR (Status)) {
328 goto ON_ERROR;
329 }
330
331 //
332 // Create the timer event used by TCP driver
333 //
334 Status = Tcp4CreateTimer ();
335 if (EFI_ERROR (Status)) {
336
337 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Create TcpTimer"
338 " Event failed with %r\n", Status));
339
340 goto ON_ERROR;
341 }
342
343 //
344 // Install the Tcp4ServiceBinding Protocol on the
345 // controller handle
346 //
347 TcpServiceData->Tcp4ServiceBinding = mTcp4ServiceBinding;
348
349 Status = gBS->InstallMultipleProtocolInterfaces (
350 &ControllerHandle,
351 &gEfiTcp4ServiceBindingProtocolGuid,
352 &TcpServiceData->Tcp4ServiceBinding,
353 NULL
354 );
355 if (EFI_ERROR (Status)) {
356
357 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Install Tcp4 Service Binding"
358 " Protocol failed for %r\n", Status));
359
360 Tcp4DestroyTimer ();
361 goto ON_ERROR;
362 }
363
364 //
365 // Initialize member in TcpServiceData
366 //
367 TcpServiceData->ControllerHandle = ControllerHandle;
368 TcpServiceData->Signature = TCP4_DRIVER_SIGNATURE;
369 TcpServiceData->DriverBindingHandle = This->DriverBindingHandle;
370
371 InitializeListHead (&TcpServiceData->SocketList);
372
373 TcpSetVariableData (TcpServiceData);
374
375 return EFI_SUCCESS;
376
377 ON_ERROR:
378
379 if (TcpServiceData->IpIo != NULL) {
380 IpIoDestroy (TcpServiceData->IpIo);
381 }
382
383 gBS->FreePool (TcpServiceData);
384
385 return Status;
386 }
387
388
389 /**
390 Stop this driver on ControllerHandle.
391
392 The Stop() function is designed to be invoked from the EFI boot service
393 DisconnectController(). As a result, much of the error checking on the parameters
394 to Stop() has been moved into this common boot service. It is legal to call Stop()
395 from other locations, but the following calling restrictions must be followed
396 or the system behavior will not be deterministic.
397 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call
398 to this same driver's Start() function.
399 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
400 EFI_HANDLE. In addition, all of these handles must have been created in this
401 driver's Start() function, and the Start() function must have called OpenProtocol()
402 on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
403
404 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
405 @param ControllerHandle A handle to the device being stopped. The handle must
406 support a bus specific I/O protocol for the driver
407 to use to stop the device.
408 @param NumberOfChildren The number of child device handles in ChildHandleBuffer.
409 @param ChildHandleBuffer An array of child handles to be freed. May be NULL if
410 NumberOfChildren is 0.
411
412 @retval EFI_SUCCESS The device was stopped.
413 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
414
415 **/
416 EFI_STATUS
417 EFIAPI
418 Tcp4DriverBindingStop (
419 IN EFI_DRIVER_BINDING_PROTOCOL *This,
420 IN EFI_HANDLE ControllerHandle,
421 IN UINTN NumberOfChildren,
422 IN EFI_HANDLE *ChildHandleBuffer
423 )
424 {
425 EFI_STATUS Status;
426 EFI_HANDLE NicHandle;
427 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
428 TCP4_SERVICE_DATA *TcpServiceData;
429 SOCKET *Sock;
430
431 // Find the NicHandle where Tcp4 ServiceBinding Protocol is installed.
432 //
433 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);
434 if (NicHandle == NULL) {
435 return EFI_DEVICE_ERROR;
436 }
437
438 //
439 // Retrieve the TCP driver Data Structure
440 //
441 Status = gBS->OpenProtocol (
442 NicHandle,
443 &gEfiTcp4ServiceBindingProtocolGuid,
444 (VOID **) &ServiceBinding,
445 This->DriverBindingHandle,
446 ControllerHandle,
447 EFI_OPEN_PROTOCOL_GET_PROTOCOL
448 );
449 if (EFI_ERROR (Status)) {
450
451 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStop: Locate Tcp4 Service "
452 " Binding Protocol failed with %r\n", Status));
453
454 return EFI_DEVICE_ERROR;
455 }
456
457 TcpServiceData = TCP4_FROM_THIS (ServiceBinding);
458
459 if (NumberOfChildren == 0) {
460 //
461 // Uninstall TCP servicebinding protocol
462 //
463 gBS->UninstallMultipleProtocolInterfaces (
464 NicHandle,
465 &gEfiTcp4ServiceBindingProtocolGuid,
466 ServiceBinding,
467 NULL
468 );
469
470 //
471 // Destroy the IpIO consumed by TCP driver
472 //
473 IpIoDestroy (TcpServiceData->IpIo);
474
475 //
476 // Destroy the heartbeat timer.
477 //
478 Tcp4DestroyTimer ();
479
480 //
481 // Clear the variable.
482 //
483 TcpClearVariableData (TcpServiceData);
484
485 //
486 // Release the TCP service data
487 //
488 gBS->FreePool (TcpServiceData);
489 } else {
490
491 while (!IsListEmpty (&TcpServiceData->SocketList)) {
492 Sock = NET_LIST_HEAD (&TcpServiceData->SocketList, SOCKET, Link);
493
494 ServiceBinding->DestroyChild (ServiceBinding, Sock->SockHandle);
495 }
496 }
497
498 return Status;
499 }
500
501 /**
502 Open Ip4 and device path protocols for a created socket, and insert it in
503 socket list.
504
505 @param This Pointer to the socket just created
506 @param Context Context of the socket
507
508 @retval EFI_SUCCESS This protocol is installed successfully.
509 @retval other Some error occured.
510
511 **/
512 EFI_STATUS
513 Tcp4CreateSocketCallback (
514 IN SOCKET *This,
515 IN VOID *Context
516 )
517 {
518 EFI_STATUS Status;
519 TCP4_SERVICE_DATA *TcpServiceData;
520 EFI_IP4_PROTOCOL *Ip4;
521
522 TcpServiceData = ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpService;
523
524 //
525 // Open the default Ip4 protocol of IP_IO BY_DRIVER.
526 //
527 Status = gBS->OpenProtocol (
528 TcpServiceData->IpIo->ChildHandle,
529 &gEfiIp4ProtocolGuid,
530 (VOID **) &Ip4,
531 TcpServiceData->DriverBindingHandle,
532 This->SockHandle,
533 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
534 );
535 if (EFI_ERROR (Status)) {
536 return Status;
537 }
538
539 //
540 // Open the device path on the handle where service binding resides on.
541 //
542 Status = gBS->OpenProtocol (
543 TcpServiceData->ControllerHandle,
544 &gEfiDevicePathProtocolGuid,
545 (VOID **) &This->ParentDevicePath,
546 TcpServiceData->DriverBindingHandle,
547 This->SockHandle,
548 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
549 );
550 if (EFI_ERROR (Status)) {
551 gBS->CloseProtocol (
552 TcpServiceData->IpIo->ChildHandle,
553 &gEfiIp4ProtocolGuid,
554 TcpServiceData->DriverBindingHandle,
555 This->SockHandle
556 );
557 } else {
558 //
559 // Insert this socket into the SocketList.
560 //
561 InsertTailList (&TcpServiceData->SocketList, &This->Link);
562 }
563
564 return Status;
565 }
566
567 /**
568 Close Ip4 and device path protocols for a socket, and remove it from socket list.
569
570 @param This Pointer to the socket to be removed
571 @param Context Context of the socket
572
573 **/
574 VOID
575 Tcp4DestroySocketCallback (
576 IN SOCKET *This,
577 IN VOID *Context
578 )
579 {
580 TCP4_SERVICE_DATA *TcpServiceData;
581
582 TcpServiceData = ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpService;
583
584 //
585 // Remove this node from the list.
586 //
587 RemoveEntryList (&This->Link);
588
589 //
590 // Close the device path protocol
591 //
592 gBS->CloseProtocol (
593 TcpServiceData->ControllerHandle,
594 &gEfiDevicePathProtocolGuid,
595 TcpServiceData->DriverBindingHandle,
596 This->SockHandle
597 );
598
599 //
600 // Close the Ip4 protocol.
601 //
602 gBS->CloseProtocol (
603 TcpServiceData->IpIo->ChildHandle,
604 &gEfiIp4ProtocolGuid,
605 TcpServiceData->DriverBindingHandle,
606 This->SockHandle
607 );
608 }
609
610 /**
611 Creates a child handle and installs a protocol.
612
613 The CreateChild() function installs a protocol on ChildHandle. If ChildHandle
614 is a pointer to NULL, then a new handle is created and returned in ChildHandle.
615 If ChildHandle is not a pointer to NULL, then the protocol installs on the existing
616 ChildHandle.
617
618 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
619 @param ChildHandle Pointer to the handle of the child to create. If it is NULL, then
620 a new handle is created. If it is a pointer to an existing UEFI
621 handle, then the protocol is added to the existing UEFI handle.
622
623 @retval EFI_SUCCES The protocol was added to ChildHandle.
624 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
625 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
626 the child.
627 @retval other The child handle was not created.
628
629 **/
630 EFI_STATUS
631 EFIAPI
632 Tcp4ServiceBindingCreateChild (
633 IN EFI_SERVICE_BINDING_PROTOCOL *This,
634 IN OUT EFI_HANDLE *ChildHandle
635 )
636 {
637 SOCKET *Sock;
638 TCP4_SERVICE_DATA *TcpServiceData;
639 TCP4_PROTO_DATA TcpProto;
640 EFI_STATUS Status;
641 EFI_TPL OldTpl;
642
643 if (NULL == This || NULL == ChildHandle) {
644 return EFI_INVALID_PARAMETER;
645 }
646
647 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
648 Status = EFI_SUCCESS;
649 TcpServiceData = TCP4_FROM_THIS (This);
650 TcpProto.TcpService = TcpServiceData;
651 TcpProto.TcpPcb = NULL;
652
653 //
654 // Create a tcp instance with defualt Tcp default
655 // sock init data and TcpProto
656 //
657 mTcp4DefaultSockData.ProtoData = &TcpProto;
658 mTcp4DefaultSockData.DataSize = sizeof (TCP4_PROTO_DATA);
659 mTcp4DefaultSockData.DriverBinding = TcpServiceData->DriverBindingHandle;
660
661 Sock = SockCreateChild (&mTcp4DefaultSockData);
662 if (NULL == Sock) {
663 DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingCreateChild: "
664 "No resource to create a Tcp Child\n"));
665
666 Status = EFI_OUT_OF_RESOURCES;
667 } else {
668 *ChildHandle = Sock->SockHandle;
669 }
670
671 gBS->RestoreTPL (OldTpl);
672 return Status;
673 }
674
675
676 /**
677 Destroys a child handle with a protocol installed on it.
678
679 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
680 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
681 last protocol on ChildHandle, then ChildHandle is destroyed.
682
683 @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
684 @param ChildHandle Handle of the child to destroy
685
686 @retval EFI_SUCCES The protocol was removed from ChildHandle.
687 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is
688 being removed.
689 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
690 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
691 because its services are being used.
692 @retval other The child handle was not destroyed.
693
694 **/
695 EFI_STATUS
696 EFIAPI
697 Tcp4ServiceBindingDestroyChild (
698 IN EFI_SERVICE_BINDING_PROTOCOL *This,
699 IN EFI_HANDLE ChildHandle
700 )
701 {
702 EFI_STATUS Status;
703 EFI_TCP4_PROTOCOL *Tcp4;
704 SOCKET *Sock;
705 EFI_TPL OldTpl;
706
707 if (NULL == This || NULL == ChildHandle) {
708 return EFI_INVALID_PARAMETER;
709 }
710
711 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
712
713 //
714 // retrieve the Tcp4 protocol from ChildHandle
715 //
716 Status = gBS->OpenProtocol (
717 ChildHandle,
718 &gEfiTcp4ProtocolGuid,
719 (VOID **) &Tcp4,
720 mTcp4DriverBinding.DriverBindingHandle,
721 ChildHandle,
722 EFI_OPEN_PROTOCOL_GET_PROTOCOL
723 );
724 if (EFI_ERROR (Status)) {
725 Status = EFI_UNSUPPORTED;
726 } else {
727 //
728 // destroy this sock and related Tcp protocol control
729 // block
730 //
731 Sock = SOCK_FROM_THIS (Tcp4);
732
733 SockDestroyChild (Sock);
734 }
735
736 gBS->RestoreTPL (OldTpl);
737 return Status;
738 }
739