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