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