TianoCore EDK2 master
Loading...
Searching...
No Matches
TcpDriver.c
Go to the documentation of this file.
1
10#include "TcpMain.h"
11
12UINT16 mTcp4RandomPort;
13UINT16 mTcp6RandomPort;
14
15TCP_HEARTBEAT_TIMER mTcpTimer = {
16 NULL,
17 0
18};
19
20EFI_TCP4_PROTOCOL gTcp4ProtocolTemplate = {
31};
32
33EFI_TCP6_PROTOCOL gTcp6ProtocolTemplate = {
43};
44
45SOCK_INIT_DATA mTcpDefaultSockData = {
48 NULL,
49 TCP_BACKLOG,
50 TCP_SND_BUF_SIZE,
51 TCP_RCV_BUF_SIZE,
52 IP_VERSION_4,
53 NULL,
56 NULL,
57 NULL,
58 0,
60 NULL,
61};
62
63EFI_DRIVER_BINDING_PROTOCOL gTcp4DriverBinding = {
67 0xa,
68 NULL,
69 NULL
70};
71
72EFI_DRIVER_BINDING_PROTOCOL gTcp6DriverBinding = {
76 0xa,
77 NULL,
78 NULL
79};
80
81EFI_SERVICE_BINDING_PROTOCOL gTcpServiceBinding = {
84};
85
86//
87// This is the handle for the Hash2ServiceBinding Protocol instance this driver produces
88// if the platform does not provide one.
89//
90EFI_HANDLE mHash2ServiceHandle = NULL;
91
101 VOID
102 )
103{
104 EFI_STATUS Status;
105
106 Status = EFI_SUCCESS;
107
108 if (mTcpTimer.RefCnt == 0) {
109 Status = gBS->CreateEvent (
110 EVT_TIMER | EVT_NOTIFY_SIGNAL,
111 TPL_NOTIFY,
113 NULL,
114 &mTcpTimer.TimerEvent
115 );
116 if (!EFI_ERROR (Status)) {
117 Status = gBS->SetTimer (
118 mTcpTimer.TimerEvent,
120 (UINT64)(TICKS_PER_SECOND / TCP_TICK_HZ)
121 );
122 }
123 }
124
125 if (!EFI_ERROR (Status)) {
126 mTcpTimer.RefCnt++;
127 }
128
129 return Status;
130}
131
136VOID
138 VOID
139 )
140{
141 ASSERT (mTcpTimer.RefCnt > 0);
142
143 mTcpTimer.RefCnt--;
144
145 if (mTcpTimer.RefCnt > 0) {
146 return;
147 }
148
149 gBS->SetTimer (mTcpTimer.TimerEvent, TimerCancel, 0);
150 gBS->CloseEvent (mTcpTimer.TimerEvent);
151 mTcpTimer.TimerEvent = NULL;
152}
153
165EFIAPI
167 IN EFI_HANDLE ImageHandle,
168 IN EFI_SYSTEM_TABLE *SystemTable
169 )
170{
171 EFI_STATUS Status;
172 UINT32 Random;
173
174 //
175 // Initialize the Secret used for hashing TCP sequence numbers
176 //
177 // Normally this should be regenerated periodically, but since
178 // this is only used for UEFI networking and not a general purpose
179 // operating system, it is not necessary to regenerate it.
180 //
181 Status = PseudoRandomU32 (&mTcpGlobalSecret);
182 if (EFI_ERROR (Status)) {
183 DEBUG ((DEBUG_ERROR, "%a failed to generate random number: %r\n", __func__, Status));
184 return Status;
185 }
186
187 //
188 // Get a random number used to generate a random port number
189 // Intentionally not linking this to mTcpGlobalSecret to avoid leaking information about the secret
190 //
191 Status = PseudoRandomU32 (&Random);
192 if (EFI_ERROR (Status)) {
193 DEBUG ((DEBUG_ERROR, "%a Failed to generate random number: %r\n", __func__, Status));
194 return Status;
195 }
196
197 //
198 // Install the TCP Driver Binding Protocol
199 //
201 ImageHandle,
202 SystemTable,
203 &gTcp4DriverBinding,
204 ImageHandle,
207 );
208 if (EFI_ERROR (Status)) {
209 return Status;
210 }
211
212 //
213 // Install the TCP Driver Binding Protocol
214 //
216 ImageHandle,
217 SystemTable,
218 &gTcp6DriverBinding,
219 NULL,
222 );
223 if (EFI_ERROR (Status)) {
225 &gTcp4DriverBinding,
228 );
229 return Status;
230 }
231
232 //
233 // Initialize the random port.
234 //
235 mTcp4RandomPort = (UINT16)(TCP_PORT_KNOWN + (Random % TCP_PORT_KNOWN));
236 mTcp6RandomPort = mTcp4RandomPort;
237
238 return EFI_SUCCESS;
239}
240
256 IN EFI_HANDLE Controller,
257 IN EFI_HANDLE Image,
258 IN UINT8 IpVersion
259 )
260{
261 EFI_STATUS Status;
262 EFI_GUID *IpServiceBindingGuid;
263 EFI_GUID *TcpServiceBindingGuid;
264 TCP_SERVICE_DATA *TcpServiceData;
265 IP_IO_OPEN_DATA OpenData;
266 EFI_SERVICE_BINDING_PROTOCOL *Hash2ServiceBinding;
267 EFI_HASH2_PROTOCOL *Hash2Protocol;
268
269 if (IpVersion == IP_VERSION_4) {
270 IpServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;
271 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
272 } else {
273 IpServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;
274 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
275 }
276
277 Status = gBS->OpenProtocol (
278 Controller,
279 TcpServiceBindingGuid,
280 NULL,
281 Image,
282 Controller,
283 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
284 );
285 if (!EFI_ERROR (Status)) {
286 return EFI_ALREADY_STARTED;
287 }
288
289 Status = gBS->OpenProtocol (
290 Controller,
291 IpServiceBindingGuid,
292 NULL,
293 Image,
294 Controller,
295 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
296 );
297 if (EFI_ERROR (Status)) {
298 return EFI_UNSUPPORTED;
299 }
300
301 Status = gBS->LocateProtocol (&gEfiHash2ProtocolGuid, NULL, (VOID **)&Hash2Protocol);
302 if (EFI_ERROR (Status)) {
303 //
304 // If we can't find the Hashing protocol, then we need to create one.
305 //
306
307 //
308 // Platform is expected to publish the hash service binding protocol to support TCP.
309 //
310 Status = gBS->LocateProtocol (
311 &gEfiHash2ServiceBindingProtocolGuid,
312 NULL,
313 (VOID **)&Hash2ServiceBinding
314 );
315 if (EFI_ERROR (Status) || (Hash2ServiceBinding == NULL) || (Hash2ServiceBinding->CreateChild == NULL)) {
316 return EFI_UNSUPPORTED;
317 }
318
319 //
320 // Create an instance of the hash protocol for this controller.
321 //
322 Status = Hash2ServiceBinding->CreateChild (Hash2ServiceBinding, &mHash2ServiceHandle);
323 if (EFI_ERROR (Status)) {
324 return EFI_UNSUPPORTED;
325 }
326 }
327
328 //
329 // Create the TCP service data.
330 //
331 TcpServiceData = AllocateZeroPool (sizeof (TCP_SERVICE_DATA));
332 if (TcpServiceData == NULL) {
333 return EFI_OUT_OF_RESOURCES;
334 }
335
336 TcpServiceData->Signature = TCP_DRIVER_SIGNATURE;
337 TcpServiceData->ControllerHandle = Controller;
338 TcpServiceData->DriverBindingHandle = Image;
339 TcpServiceData->IpVersion = IpVersion;
340 CopyMem (
341 &TcpServiceData->ServiceBinding,
342 &gTcpServiceBinding,
344 );
345
346 TcpServiceData->IpIo = IpIoCreate (Image, Controller, IpVersion);
347 if (TcpServiceData->IpIo == NULL) {
348 Status = EFI_OUT_OF_RESOURCES;
349 goto ON_ERROR;
350 }
351
352 InitializeListHead (&TcpServiceData->SocketList);
353 ZeroMem (&OpenData, sizeof (IP_IO_OPEN_DATA));
354
355 if (IpVersion == IP_VERSION_4) {
356 CopyMem (
357 &OpenData.IpConfigData.Ip4CfgData,
358 &mIp4IoDefaultIpConfigData,
359 sizeof (EFI_IP4_CONFIG_DATA)
360 );
361 OpenData.IpConfigData.Ip4CfgData.DefaultProtocol = EFI_IP_PROTO_TCP;
362 } else {
363 CopyMem (
364 &OpenData.IpConfigData.Ip6CfgData,
365 &mIp6IoDefaultIpConfigData,
366 sizeof (EFI_IP6_CONFIG_DATA)
367 );
368 OpenData.IpConfigData.Ip6CfgData.DefaultProtocol = EFI_IP_PROTO_TCP;
369 }
370
371 OpenData.PktRcvdNotify = TcpRxCallback;
372 Status = IpIoOpen (TcpServiceData->IpIo, &OpenData);
373 if (EFI_ERROR (Status)) {
374 goto ON_ERROR;
375 }
376
377 Status = TcpCreateTimer ();
378 if (EFI_ERROR (Status)) {
379 goto ON_ERROR;
380 }
381
382 Status = gBS->InstallMultipleProtocolInterfaces (
383 &Controller,
384 TcpServiceBindingGuid,
385 &TcpServiceData->ServiceBinding,
386 NULL
387 );
388 if (EFI_ERROR (Status)) {
390
391 goto ON_ERROR;
392 }
393
394 return EFI_SUCCESS;
395
396ON_ERROR:
397
398 if (TcpServiceData->IpIo != NULL) {
399 IpIoDestroy (TcpServiceData->IpIo);
400 TcpServiceData->IpIo = NULL;
401 }
402
403 FreePool (TcpServiceData);
404
405 return Status;
406}
407
419EFIAPI
421 IN LIST_ENTRY *Entry,
422 IN VOID *Context
423 )
424{
425 SOCKET *Sock;
426 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
427 UINTN NumberOfChildren;
428 EFI_HANDLE *ChildHandleBuffer;
429
430 if ((Entry == NULL) || (Context == NULL)) {
431 return EFI_INVALID_PARAMETER;
432 }
433
434 Sock = NET_LIST_USER_STRUCT_S (Entry, SOCKET, Link, SOCK_SIGNATURE);
435 ServiceBinding = ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ServiceBinding;
436 NumberOfChildren = ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->NumberOfChildren;
437 ChildHandleBuffer = ((TCP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ChildHandleBuffer;
438
439 if (!NetIsInHandleBuffer (Sock->SockHandle, NumberOfChildren, ChildHandleBuffer)) {
440 return EFI_SUCCESS;
441 }
442
443 return ServiceBinding->DestroyChild (ServiceBinding, Sock->SockHandle);
444}
445
464 IN EFI_HANDLE Controller,
465 IN EFI_HANDLE ImageHandle,
466 IN UINTN NumberOfChildren,
467 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL,
468 IN UINT8 IpVersion
469 )
470{
471 EFI_HANDLE NicHandle;
472 EFI_GUID *IpProtocolGuid;
473 EFI_GUID *ServiceBindingGuid;
474 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
475 TCP_SERVICE_DATA *TcpServiceData;
476 EFI_STATUS Status;
477 LIST_ENTRY *List;
479 EFI_SERVICE_BINDING_PROTOCOL *Hash2ServiceBinding;
480
481 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
482
483 if (IpVersion == IP_VERSION_4) {
484 IpProtocolGuid = &gEfiIp4ProtocolGuid;
485 ServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
486 } else {
487 IpProtocolGuid = &gEfiIp6ProtocolGuid;
488 ServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
489 }
490
491 NicHandle = NetLibGetNicHandle (Controller, IpProtocolGuid);
492 if (NicHandle == NULL) {
493 return EFI_SUCCESS;
494 }
495
496 //
497 // Destroy the Hash2ServiceBinding instance if it is created by Tcp driver.
498 //
499 if (mHash2ServiceHandle != NULL) {
500 Status = gBS->LocateProtocol (
501 &gEfiHash2ServiceBindingProtocolGuid,
502 NULL,
503 (VOID **)&Hash2ServiceBinding
504 );
505 if (EFI_ERROR (Status) || (Hash2ServiceBinding == NULL) || (Hash2ServiceBinding->DestroyChild == NULL)) {
506 return EFI_UNSUPPORTED;
507 }
508
509 //
510 // Destroy the instance of the hashing protocol for this controller.
511 //
512 Status = Hash2ServiceBinding->DestroyChild (Hash2ServiceBinding, mHash2ServiceHandle);
513 if (EFI_ERROR (Status)) {
514 return EFI_UNSUPPORTED;
515 }
516
517 mHash2ServiceHandle = NULL;
518 }
519
520 Status = gBS->OpenProtocol (
521 NicHandle,
522 ServiceBindingGuid,
523 (VOID **)&ServiceBinding,
524 ImageHandle,
525 Controller,
526 EFI_OPEN_PROTOCOL_GET_PROTOCOL
527 );
528 if (EFI_ERROR (Status)) {
529 return EFI_DEVICE_ERROR;
530 }
531
532 TcpServiceData = TCP_SERVICE_FROM_THIS (ServiceBinding);
533
534 if (NumberOfChildren != 0) {
535 List = &TcpServiceData->SocketList;
536 Context.ServiceBinding = ServiceBinding;
537 Context.NumberOfChildren = NumberOfChildren;
538 Context.ChildHandleBuffer = ChildHandleBuffer;
539 Status = NetDestroyLinkList (
540 List,
542 &Context,
543 NULL
544 );
545 } else if (IsListEmpty (&TcpServiceData->SocketList)) {
546 //
547 // Uninstall TCP servicebinding protocol
548 //
549 gBS->UninstallMultipleProtocolInterfaces (
550 NicHandle,
551 ServiceBindingGuid,
552 ServiceBinding,
553 NULL
554 );
555
556 //
557 // Destroy the IpIO consumed by TCP driver
558 //
559 IpIoDestroy (TcpServiceData->IpIo);
560 TcpServiceData->IpIo = NULL;
561
562 //
563 // Destroy the heartbeat timer.
564 //
566
567 //
568 // Release the TCP service data
569 //
570 FreePool (TcpServiceData);
571
572 Status = EFI_SUCCESS;
573 }
574
575 return Status;
576}
577
592EFIAPI
595 IN EFI_HANDLE ControllerHandle,
596 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
597 )
598{
599 EFI_STATUS Status;
600
601 //
602 // Test for the Tcp4ServiceBinding Protocol
603 //
604 Status = gBS->OpenProtocol (
605 ControllerHandle,
606 &gEfiTcp4ServiceBindingProtocolGuid,
607 NULL,
608 This->DriverBindingHandle,
609 ControllerHandle,
610 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
611 );
612 if (!EFI_ERROR (Status)) {
613 return EFI_ALREADY_STARTED;
614 }
615
616 //
617 // Test for the Ip4ServiceBinding Protocol
618 //
619 Status = gBS->OpenProtocol (
620 ControllerHandle,
621 &gEfiIp4ServiceBindingProtocolGuid,
622 NULL,
623 This->DriverBindingHandle,
624 ControllerHandle,
625 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
626 );
627 return Status;
628}
629
645EFIAPI
648 IN EFI_HANDLE ControllerHandle,
649 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
650 )
651{
652 EFI_STATUS Status;
653
654 Status = TcpCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_4);
655 if ((Status == EFI_ALREADY_STARTED) || (Status == EFI_UNSUPPORTED)) {
656 Status = EFI_SUCCESS;
657 }
658
659 return Status;
660}
661
678EFIAPI
681 IN EFI_HANDLE ControllerHandle,
682 IN UINTN NumberOfChildren,
683 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
684 )
685{
686 return TcpDestroyService (
687 ControllerHandle,
688 This->DriverBindingHandle,
689 NumberOfChildren,
690 ChildHandleBuffer,
691 IP_VERSION_4
692 );
693}
694
709EFIAPI
712 IN EFI_HANDLE ControllerHandle,
713 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
714 )
715{
716 EFI_STATUS Status;
717
718 //
719 // Test for the Tcp6ServiceBinding Protocol
720 //
721 Status = gBS->OpenProtocol (
722 ControllerHandle,
723 &gEfiTcp6ServiceBindingProtocolGuid,
724 NULL,
725 This->DriverBindingHandle,
726 ControllerHandle,
727 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
728 );
729 if (!EFI_ERROR (Status)) {
730 return EFI_ALREADY_STARTED;
731 }
732
733 //
734 // Test for the Ip6ServiceBinding Protocol
735 //
736 Status = gBS->OpenProtocol (
737 ControllerHandle,
738 &gEfiIp6ServiceBindingProtocolGuid,
739 NULL,
740 This->DriverBindingHandle,
741 ControllerHandle,
742 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
743 );
744 return Status;
745}
746
762EFIAPI
765 IN EFI_HANDLE ControllerHandle,
766 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
767 )
768{
769 EFI_STATUS Status;
770
771 Status = TcpCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_6);
772 if ((Status == EFI_ALREADY_STARTED) || (Status == EFI_UNSUPPORTED)) {
773 Status = EFI_SUCCESS;
774 }
775
776 return Status;
777}
778
795EFIAPI
798 IN EFI_HANDLE ControllerHandle,
799 IN UINTN NumberOfChildren,
800 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
801 )
802{
803 return TcpDestroyService (
804 ControllerHandle,
805 This->DriverBindingHandle,
806 NumberOfChildren,
807 ChildHandleBuffer,
808 IP_VERSION_6
809 );
810}
811
824 IN SOCKET *This,
825 IN VOID *Context
826 )
827{
828 EFI_STATUS Status;
829 TCP_SERVICE_DATA *TcpServiceData;
830 EFI_GUID *IpProtocolGuid;
831 VOID *Ip;
832
833 if (This->IpVersion == IP_VERSION_4) {
834 IpProtocolGuid = &gEfiIp4ProtocolGuid;
835 } else {
836 IpProtocolGuid = &gEfiIp6ProtocolGuid;
837 }
838
839 TcpServiceData = ((TCP_PROTO_DATA *)This->ProtoReserved)->TcpService;
840
841 //
842 // Open the default IP protocol of IP_IO BY_DRIVER.
843 //
844 Status = gBS->OpenProtocol (
845 TcpServiceData->IpIo->ChildHandle,
846 IpProtocolGuid,
847 &Ip,
848 TcpServiceData->DriverBindingHandle,
849 This->SockHandle,
850 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
851 );
852 if (EFI_ERROR (Status)) {
853 return Status;
854 }
855
856 //
857 // Open the device path on the handle where service binding resides on.
858 //
859 Status = gBS->OpenProtocol (
860 TcpServiceData->ControllerHandle,
861 &gEfiDevicePathProtocolGuid,
862 (VOID **)&This->ParentDevicePath,
863 TcpServiceData->DriverBindingHandle,
864 This->SockHandle,
865 EFI_OPEN_PROTOCOL_GET_PROTOCOL
866 );
867 if (EFI_ERROR (Status)) {
868 gBS->CloseProtocol (
869 TcpServiceData->IpIo->ChildHandle,
870 IpProtocolGuid,
871 TcpServiceData->DriverBindingHandle,
872 This->SockHandle
873 );
874 } else {
875 //
876 // Insert this socket into the SocketList.
877 //
878 InsertTailList (&TcpServiceData->SocketList, &This->Link);
879 }
880
881 return Status;
882}
883
891VOID
893 IN SOCKET *This,
894 IN VOID *Context
895 )
896{
897 TCP_SERVICE_DATA *TcpServiceData;
898 EFI_GUID *IpProtocolGuid;
899
900 if (This->IpVersion == IP_VERSION_4) {
901 IpProtocolGuid = &gEfiIp4ProtocolGuid;
902 } else {
903 IpProtocolGuid = &gEfiIp6ProtocolGuid;
904 }
905
906 TcpServiceData = ((TCP_PROTO_DATA *)This->ProtoReserved)->TcpService;
907
908 //
909 // Remove this node from the list.
910 //
911 RemoveEntryList (&This->Link);
912
913 //
914 // Close the IP protocol.
915 //
916 gBS->CloseProtocol (
917 TcpServiceData->IpIo->ChildHandle,
918 IpProtocolGuid,
919 TcpServiceData->DriverBindingHandle,
920 This->SockHandle
921 );
922}
923
945EFIAPI
948 IN OUT EFI_HANDLE *ChildHandle
949 )
950{
951 SOCKET *Sock;
952 TCP_SERVICE_DATA *TcpServiceData;
953 TCP_PROTO_DATA TcpProto;
954 EFI_STATUS Status;
955 EFI_TPL OldTpl;
956
957 if ((NULL == This) || (NULL == ChildHandle)) {
958 return EFI_INVALID_PARAMETER;
959 }
960
961 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
962
963 Status = EFI_SUCCESS;
964 TcpServiceData = TCP_SERVICE_FROM_THIS (This);
965 TcpProto.TcpService = TcpServiceData;
966 TcpProto.TcpPcb = NULL;
967
968 //
969 // Create a tcp instance with default Tcp default
970 // sock init data and TcpProto
971 //
972 mTcpDefaultSockData.ProtoData = &TcpProto;
973 mTcpDefaultSockData.DataSize = sizeof (TCP_PROTO_DATA);
974 mTcpDefaultSockData.DriverBinding = TcpServiceData->DriverBindingHandle;
975 mTcpDefaultSockData.IpVersion = TcpServiceData->IpVersion;
976
977 if (TcpServiceData->IpVersion == IP_VERSION_4) {
978 mTcpDefaultSockData.Protocol = &gTcp4ProtocolTemplate;
979 } else {
980 mTcpDefaultSockData.Protocol = &gTcp6ProtocolTemplate;
981 }
982
983 Sock = SockCreateChild (&mTcpDefaultSockData);
984 if (NULL == Sock) {
985 DEBUG (
986 (DEBUG_ERROR,
987 "TcpDriverBindingCreateChild: No resource to create a Tcp Child\n")
988 );
989
990 Status = EFI_OUT_OF_RESOURCES;
991 } else {
992 *ChildHandle = Sock->SockHandle;
993 }
994
995 mTcpDefaultSockData.ProtoData = NULL;
996
997 gBS->RestoreTPL (OldTpl);
998 return Status;
999}
1000
1020EFIAPI
1023 IN EFI_HANDLE ChildHandle
1024 )
1025{
1026 EFI_STATUS Status;
1027 VOID *Tcp;
1028 SOCKET *Sock;
1029
1030 if ((NULL == This) || (NULL == ChildHandle)) {
1031 return EFI_INVALID_PARAMETER;
1032 }
1033
1034 //
1035 // retrieve the Tcp4 protocol from ChildHandle
1036 //
1037 Status = gBS->OpenProtocol (
1038 ChildHandle,
1039 &gEfiTcp4ProtocolGuid,
1040 &Tcp,
1041 gTcp4DriverBinding.DriverBindingHandle,
1042 ChildHandle,
1043 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1044 );
1045 if (EFI_ERROR (Status)) {
1046 //
1047 // No Tcp4, try the Tcp6 protocol
1048 //
1049 Status = gBS->OpenProtocol (
1050 ChildHandle,
1051 &gEfiTcp6ProtocolGuid,
1052 &Tcp,
1053 gTcp6DriverBinding.DriverBindingHandle,
1054 ChildHandle,
1055 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1056 );
1057 if (EFI_ERROR (Status)) {
1058 Status = EFI_UNSUPPORTED;
1059 }
1060 }
1061
1062 if (!EFI_ERROR (Status)) {
1063 //
1064 // destroy this sock and related Tcp protocol control
1065 // block
1066 //
1067 Sock = SOCK_FROM_THIS (Tcp);
1068
1069 SockDestroyChild (Sock);
1070 }
1071
1072 return Status;
1073}
UINT64 UINTN
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI IpIoDestroy(IN OUT IP_IO *IpIo)
Definition: DxeIpIoLib.c:1518
IP_IO *EFIAPI IpIoCreate(IN EFI_HANDLE Image, IN EFI_HANDLE Controller, IN UINT8 IpVersion)
Definition: DxeIpIoLib.c:1217
EFI_STATUS EFIAPI IpIoOpen(IN OUT IP_IO *IpIo, IN IP_IO_OPEN_DATA *OpenData)
Definition: DxeIpIoLib.c:1310
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
BOOLEAN EFIAPI NetIsInHandleBuffer(IN EFI_HANDLE Handle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: DxeNetLib.c:1306
EFI_STATUS EFIAPI PseudoRandomU32(OUT UINT32 *Output)
Definition: DxeNetLib.c:1011
EFI_HANDLE EFIAPI NetLibGetNicHandle(IN EFI_HANDLE Controller, IN EFI_GUID *ProtocolGuid)
Definition: DxeNetLib.c:3019
EFI_STATUS EFIAPI NetDestroyLinkList(IN LIST_ENTRY *List, IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, IN VOID *Context OPTIONAL, OUT UINTN *ListLength OPTIONAL)
Definition: DxeNetLib.c:1236
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTcpComponentName2
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gTcpComponentName
SOCKET * SockCreateChild(IN SOCK_INIT_DATA *SockInitData)
@ SockStream
This socket providing stream service.
Definition: Socket.h:350
#define SO_CLOSED
Definition: Socket.h:64
EFI_STATUS SockDestroyChild(IN OUT SOCKET *Sock)
EFI_STATUS TcpDispatcher(IN SOCKET *Sock, IN UINT8 Request, IN VOID *Data OPTIONAL)
EFI_STATUS TcpCreateSocketCallback(IN SOCKET *This, IN VOID *Context)
Definition: TcpDriver.c:823
VOID TcpDestroyTimer(VOID)
Definition: TcpDriver.c:137
EFI_STATUS EFIAPI Tcp4DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: TcpDriver.c:679
EFI_STATUS EFIAPI TcpDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TcpDriver.c:166
EFI_STATUS EFIAPI TcpDestroyChildEntryInHandleBuffer(IN LIST_ENTRY *Entry, IN VOID *Context)
Definition: TcpDriver.c:420
EFI_STATUS TcpDestroyService(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL, IN UINT8 IpVersion)
Definition: TcpDriver.c:463
EFI_STATUS TcpCreateService(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN UINT8 IpVersion)
Definition: TcpDriver.c:255
EFI_STATUS EFIAPI Tcp6DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: TcpDriver.c:763
EFI_STATUS EFIAPI Tcp4DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: TcpDriver.c:593
VOID TcpDestroySocketCallback(IN SOCKET *This, IN VOID *Context)
Definition: TcpDriver.c:892
EFI_STATUS EFIAPI TcpServiceBindingDestroyChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle)
Definition: TcpDriver.c:1021
EFI_STATUS EFIAPI Tcp6DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: TcpDriver.c:710
EFI_STATUS TcpCreateTimer(VOID)
Definition: TcpDriver.c:100
EFI_STATUS EFIAPI TcpServiceBindingCreateChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN OUT EFI_HANDLE *ChildHandle)
Definition: TcpDriver.c:946
EFI_STATUS EFIAPI Tcp6DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: TcpDriver.c:796
EFI_STATUS EFIAPI Tcp4DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: TcpDriver.c:646
VOID EFIAPI TcpTicking(IN EFI_EVENT Event, IN VOID *Context)
Definition: TcpTimer.c:563
VOID EFIAPI TcpRxCallback(IN EFI_STATUS Status, IN UINT8 IcmpErr, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Pkt, IN VOID *Context OPTIONAL)
Definition: TcpIo.c:27
EFI_STATUS EFIAPI Tcp4GetModeData(IN EFI_TCP4_PROTOCOL *This, OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL, OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL, OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL, OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL)
Definition: TcpMain.c:76
EFI_STATUS EFIAPI Tcp4Accept(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_LISTEN_TOKEN *ListenToken)
Definition: TcpMain.c:297
EFI_STATUS EFIAPI Tcp4Cancel(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL)
Definition: TcpMain.c:509
EFI_STATUS EFIAPI Tcp4Receive(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_IO_TOKEN *Token)
Definition: TcpMain.c:410
EFI_STATUS EFIAPI Tcp6Close(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CLOSE_TOKEN *CloseToken)
Definition: TcpMain.c:1004
EFI_STATUS EFIAPI Tcp6Connect(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CONNECTION_TOKEN *ConnectionToken)
Definition: TcpMain.c:753
EFI_STATUS EFIAPI Tcp6GetModeData(IN EFI_TCP6_PROTOCOL *This, OUT EFI_TCP6_CONNECTION_STATE *Tcp6State OPTIONAL, OUT EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL, OUT EFI_IP6_MODE_DATA *Ip6ModeData OPTIONAL, OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL)
Definition: TcpMain.c:589
EFI_STATUS EFIAPI Tcp6Configure(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL)
Definition: TcpMain.c:665
EFI_STATUS EFIAPI Tcp6Receive(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_IO_TOKEN *Token)
Definition: TcpMain.c:942
EFI_STATUS EFIAPI Tcp4Transmit(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_IO_TOKEN *Token)
Definition: TcpMain.c:344
EFI_STATUS EFIAPI Tcp4Close(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CLOSE_TOKEN *CloseToken)
Definition: TcpMain.c:467
EFI_STATUS EFIAPI Tcp6Poll(IN EFI_TCP6_PROTOCOL *This)
Definition: TcpMain.c:1092
EFI_STATUS EFIAPI Tcp4Poll(IN EFI_TCP4_PROTOCOL *This)
Definition: TcpMain.c:541
EFI_STATUS EFIAPI Tcp6Transmit(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_IO_TOKEN *Token)
Definition: TcpMain.c:861
EFI_STATUS EFIAPI Tcp6Cancel(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_COMPLETION_TOKEN *Token OPTIONAL)
Definition: TcpMain.c:1057
EFI_STATUS EFIAPI Tcp4Routes(IN EFI_TCP4_PROTOCOL *This, IN BOOLEAN DeleteRoute, IN EFI_IPv4_ADDRESS *SubnetAddress, IN EFI_IPv4_ADDRESS *SubnetMask, IN EFI_IPv4_ADDRESS *GatewayAddress)
Definition: TcpMain.c:213
EFI_STATUS EFIAPI Tcp6Accept(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_LISTEN_TOKEN *ListenToken)
Definition: TcpMain.c:806
EFI_STATUS EFIAPI Tcp4Connect(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken)
Definition: TcpMain.c:259
EFI_STATUS EFIAPI Tcp4Configure(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL)
Definition: TcpMain.c:127
#define TCP_TICK_HZ
The frequence of TCP tick.
Definition: TcpProto.h:85
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiLibUninstallDriverBindingComponentName2(IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
@ TimerCancel
Definition: UefiSpec.h:531
@ TimerPeriodic
Definition: UefiSpec.h:535
PKT_RCVD_NOTIFY PktRcvdNotify
Receive callback.
Definition: IpIoLib.h:268
IP_IO_IP_CONFIG_DATA IpConfigData
Configuration of the IP instance.
Definition: IpIoLib.h:265
VOID * Protocol
Definition: Socket.h:425
EFI_HANDLE DriverBinding
The driver binding handle.
Definition: Socket.h:443
EFI_HANDLE SockHandle
The virtual handle of the socket.
Definition: Socket.h:461
UINT8 DefaultProtocol
Definition: Ip4.h:63
UINT8 DefaultProtocol
Definition: Ip6.h:144
Definition: Base.h:213