33 if ((Event ==
NULL) || (Context ==
NULL)) {
37 *((BOOLEAN *)Context) =
TRUE;
61 if ((Tcp6 ==
NULL) || (Tcp6ConfigData ==
NULL)) {
62 return EFI_INVALID_PARAMETER;
66 Status =
gBS->CreateEvent (
73 if (EFI_ERROR (Status)) {
77 Status =
gBS->SetTimer (
83 if (EFI_ERROR (Status)) {
87 while (EFI_ERROR (
gBS->CheckEvent (Event))) {
90 Status = Tcp6->Configure (Tcp6, Tcp6ConfigData);
92 if (!EFI_ERROR (Status)) {
100 gBS->CloseEvent (Event);
147 if ((Image ==
NULL) || (Controller ==
NULL) || (ConfigData ==
NULL) || (TcpIo ==
NULL)) {
148 return EFI_INVALID_PARAMETER;
156 if (TcpVersion == TCP_VERSION_4) {
157 ServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
158 ProtocolGuid = &gEfiTcp4ProtocolGuid;
159 Interface = (VOID **)(&TcpIo->Tcp.Tcp4);
160 }
else if (TcpVersion == TCP_VERSION_6) {
161 ServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
162 ProtocolGuid = &gEfiTcp6ProtocolGuid;
163 Interface = (VOID **)(&TcpIo->Tcp.Tcp6);
165 return EFI_UNSUPPORTED;
168 TcpIo->TcpVersion = TcpVersion;
179 if (EFI_ERROR (Status)) {
183 Status =
gBS->OpenProtocol (
189 EFI_OPEN_PROTOCOL_BY_DRIVER
191 if (EFI_ERROR (Status) || (*Interface ==
NULL)) {
195 if (TcpVersion == TCP_VERSION_4) {
196 Tcp4 = TcpIo->Tcp.Tcp4;
198 Tcp6 = TcpIo->Tcp.Tcp6;
201 TcpIo->Image = Image;
202 TcpIo->Controller = Controller;
207 ControlOption.ReceiveBufferSize = 0x200000;
208 ControlOption.SendBufferSize = 0x200000;
209 ControlOption.MaxSynBackLog = 0;
210 ControlOption.ConnectionTimeout = 0;
211 ControlOption.DataRetries = 6;
212 ControlOption.FinTimeout = 0;
213 ControlOption.TimeWaitTimeout = 0;
214 ControlOption.KeepAliveProbes = 4;
215 ControlOption.KeepAliveTime = 0;
216 ControlOption.KeepAliveInterval = 0;
217 ControlOption.EnableNagle =
FALSE;
218 ControlOption.EnableTimeStamp =
FALSE;
219 ControlOption.EnableWindowScaling =
TRUE;
220 ControlOption.EnableSelectiveAck =
FALSE;
221 ControlOption.EnablePathMtuDiscovery =
FALSE;
223 if (TcpVersion == TCP_VERSION_4) {
224 Tcp4ConfigData.TypeOfService = 8;
225 Tcp4ConfigData.TimeToLive = 255;
226 Tcp4ConfigData.ControlOption = &ControlOption;
228 AccessPoint4 = &Tcp4ConfigData.AccessPoint;
231 AccessPoint4->StationPort = ConfigData->Tcp4IoConfigData.StationPort;
232 AccessPoint4->RemotePort = ConfigData->Tcp4IoConfigData.RemotePort;
233 AccessPoint4->ActiveFlag = ConfigData->Tcp4IoConfigData.ActiveFlag;
236 &AccessPoint4->StationAddress,
237 &ConfigData->Tcp4IoConfigData.LocalIp,
241 &AccessPoint4->SubnetMask,
242 &ConfigData->Tcp4IoConfigData.SubnetMask,
246 &AccessPoint4->RemoteAddress,
247 &ConfigData->Tcp4IoConfigData.RemoteIp,
251 ASSERT (Tcp4 !=
NULL);
256 Status = Tcp4->Configure (Tcp4, &Tcp4ConfigData);
257 if (EFI_ERROR (Status)) {
261 if (!EFI_IP4_EQUAL (&ConfigData->Tcp4IoConfigData.Gateway, &mZeroIp4Addr)) {
265 Status = Tcp4->Routes (
270 &ConfigData->Tcp4IoConfigData.Gateway
272 if (EFI_ERROR (Status)) {
284 AccessPoint6->
StationPort = ConfigData->Tcp6IoConfigData.StationPort;
285 AccessPoint6->
RemotePort = ConfigData->Tcp6IoConfigData.RemotePort;
286 AccessPoint6->
ActiveFlag = ConfigData->Tcp6IoConfigData.ActiveFlag;
288 IP6_COPY_ADDRESS (&AccessPoint6->
RemoteAddress, &ConfigData->Tcp6IoConfigData.RemoteIp);
290 ASSERT (Tcp6 !=
NULL);
294 Status = Tcp6->Configure (Tcp6, &Tcp6ConfigData);
295 if (Status == EFI_NO_MAPPING) {
299 if (EFI_ERROR (Status)) {
307 Status =
gBS->CreateEvent (
314 if (EFI_ERROR (Status)) {
318 TcpIo->ConnToken.Tcp4Token.CompletionToken.Event = Event;
320 Status =
gBS->CreateEvent (
324 &TcpIo->IsListenDone,
327 if (EFI_ERROR (Status)) {
331 TcpIo->ListenToken.Tcp4Token.CompletionToken.Event = Event;
333 Status =
gBS->CreateEvent (
340 if (EFI_ERROR (Status)) {
344 TcpIo->TxToken.Tcp4Token.CompletionToken.Event = Event;
346 Status =
gBS->CreateEvent (
353 if (EFI_ERROR (Status)) {
357 TcpIo->RxToken.Tcp4Token.CompletionToken.Event = Event;
360 if (RxData ==
NULL) {
361 Status = EFI_OUT_OF_RESOURCES;
365 TcpIo->RxToken.Tcp4Token.Packet.RxData = RxData;
367 Status =
gBS->CreateEvent (
374 if (EFI_ERROR (Status)) {
378 TcpIo->CloseToken.Tcp4Token.CompletionToken.Event = Event;
413 TcpVersion = TcpIo->TcpVersion;
415 if ((TcpVersion != TCP_VERSION_4) && (TcpVersion != TCP_VERSION_6)) {
419 Event = TcpIo->ConnToken.Tcp4Token.CompletionToken.Event;
422 gBS->CloseEvent (Event);
425 Event = TcpIo->ListenToken.Tcp4Token.CompletionToken.Event;
428 gBS->CloseEvent (Event);
431 Event = TcpIo->TxToken.Tcp4Token.CompletionToken.Event;
434 gBS->CloseEvent (Event);
437 Event = TcpIo->RxToken.Tcp4Token.CompletionToken.Event;
440 gBS->CloseEvent (Event);
443 Event = TcpIo->CloseToken.Tcp4Token.CompletionToken.Event;
446 gBS->CloseEvent (Event);
449 if (TcpIo->RxToken.Tcp4Token.Packet.RxData !=
NULL) {
450 FreePool (TcpIo->RxToken.Tcp4Token.Packet.RxData);
456 if (TcpVersion == TCP_VERSION_4) {
457 ServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
458 ProtocolGuid = &gEfiTcp4ProtocolGuid;
459 Tcp4 = TcpIo->Tcp.Tcp4;
461 Tcp4->Configure (Tcp4,
NULL);
464 ServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
465 ProtocolGuid = &gEfiTcp6ProtocolGuid;
466 Tcp6 = TcpIo->Tcp.Tcp6;
468 Tcp6->Configure (Tcp6,
NULL);
472 if ((Tcp4 !=
NULL) || (Tcp6 !=
NULL)) {
483 if (TcpIo->IsListenDone) {
484 if (TcpVersion == TCP_VERSION_4) {
485 Tcp4 = TcpIo->NewTcp.Tcp4;
487 Tcp4->Configure (Tcp4,
NULL);
488 ChildHandle = TcpIo->ListenToken.Tcp4Token.NewChildHandle;
491 Tcp6 = TcpIo->NewTcp.Tcp6;
493 Tcp6->Configure (Tcp6,
NULL);
494 ChildHandle = TcpIo->ListenToken.Tcp6Token.NewChildHandle;
498 if (ChildHandle !=
NULL) {
543 if ((TcpIo ==
NULL) || (TcpIo->Tcp.Tcp4 ==
NULL)) {
544 return EFI_INVALID_PARAMETER;
547 TcpIo->IsConnDone =
FALSE;
552 if (TcpIo->TcpVersion == TCP_VERSION_4) {
553 Tcp4 = TcpIo->Tcp.Tcp4;
554 Status = Tcp4->Connect (Tcp4, &TcpIo->ConnToken.Tcp4Token);
555 }
else if (TcpIo->TcpVersion == TCP_VERSION_6) {
556 Tcp6 = TcpIo->Tcp.Tcp6;
557 Status = Tcp6->Connect (Tcp6, &TcpIo->ConnToken.Tcp6Token);
559 return EFI_UNSUPPORTED;
562 if (EFI_ERROR (Status)) {
566 while (!TcpIo->IsConnDone && ((Timeout ==
NULL) || EFI_ERROR (
gBS->CheckEvent (Timeout)))) {
567 if (TcpIo->TcpVersion == TCP_VERSION_4) {
574 if (!TcpIo->IsConnDone) {
575 if (TcpIo->TcpVersion == TCP_VERSION_4) {
576 Tcp4->Cancel (Tcp4, &TcpIo->ConnToken.Tcp4Token.CompletionToken);
578 Tcp6->Cancel (Tcp6, &TcpIo->ConnToken.Tcp6Token.CompletionToken);
581 Status = EFI_TIMEOUT;
583 Status = TcpIo->ConnToken.Tcp4Token.CompletionToken.Status;
619 if ((TcpIo ==
NULL) || (TcpIo->Tcp.Tcp4 ==
NULL)) {
620 return EFI_INVALID_PARAMETER;
623 TcpIo->IsListenDone =
FALSE;
628 if (TcpIo->TcpVersion == TCP_VERSION_4) {
629 Tcp4 = TcpIo->Tcp.Tcp4;
630 Status = Tcp4->Accept (Tcp4, &TcpIo->ListenToken.Tcp4Token);
631 }
else if (TcpIo->TcpVersion == TCP_VERSION_6) {
632 Tcp6 = TcpIo->Tcp.Tcp6;
633 Status = Tcp6->Accept (Tcp6, &TcpIo->ListenToken.Tcp6Token);
635 return EFI_UNSUPPORTED;
638 if (EFI_ERROR (Status)) {
642 while (!TcpIo->IsListenDone && ((Timeout ==
NULL) || EFI_ERROR (
gBS->CheckEvent (Timeout)))) {
643 if (TcpIo->TcpVersion == TCP_VERSION_4) {
650 if (!TcpIo->IsListenDone) {
651 if (TcpIo->TcpVersion == TCP_VERSION_4) {
652 Tcp4->Cancel (Tcp4, &TcpIo->ListenToken.Tcp4Token.CompletionToken);
654 Tcp6->Cancel (Tcp6, &TcpIo->ListenToken.Tcp6Token.CompletionToken);
657 Status = EFI_TIMEOUT;
659 Status = TcpIo->ListenToken.Tcp4Token.CompletionToken.Status;
666 if (!EFI_ERROR (Status)) {
667 if (TcpIo->TcpVersion == TCP_VERSION_4) {
668 ProtocolGuid = &gEfiTcp4ProtocolGuid;
670 ProtocolGuid = &gEfiTcp6ProtocolGuid;
673 Status =
gBS->OpenProtocol (
674 TcpIo->ListenToken.Tcp4Token.NewChildHandle,
676 (VOID **)(&TcpIo->NewTcp.Tcp4),
679 EFI_OPEN_PROTOCOL_BY_DRIVER
702 if ((TcpIo ==
NULL) || (TcpIo->Tcp.Tcp4 ==
NULL)) {
706 TcpIo->IsCloseDone =
FALSE;
710 if (TcpIo->TcpVersion == TCP_VERSION_4) {
711 TcpIo->CloseToken.Tcp4Token.AbortOnClose =
TRUE;
712 Tcp4 = TcpIo->Tcp.Tcp4;
713 Status = Tcp4->Close (Tcp4, &TcpIo->CloseToken.Tcp4Token);
714 }
else if (TcpIo->TcpVersion == TCP_VERSION_6) {
715 TcpIo->CloseToken.Tcp6Token.AbortOnClose =
TRUE;
716 Tcp6 = TcpIo->Tcp.Tcp6;
717 Status = Tcp6->Close (Tcp6, &TcpIo->CloseToken.Tcp6Token);
722 if (EFI_ERROR (Status)) {
726 while (!TcpIo->IsCloseDone) {
727 if (TcpIo->TcpVersion == TCP_VERSION_4) {
763 if ((TcpIo ==
NULL) || (TcpIo->Tcp.Tcp4 ==
NULL) || (Packet ==
NULL)) {
764 return EFI_INVALID_PARAMETER;
767 if (TcpIo->TcpVersion == TCP_VERSION_4) {
770 }
else if (TcpIo->TcpVersion == TCP_VERSION_6) {
774 return EFI_UNSUPPORTED;
779 return EFI_OUT_OF_RESOURCES;
799 Status = EFI_DEVICE_ERROR;
804 if (TcpIo->TcpVersion == TCP_VERSION_4) {
806 Tcp4 = TcpIo->Tcp.Tcp4;
807 if (TcpIo->IsListenDone) {
808 Tcp4 = TcpIo->NewTcp.Tcp4;
815 Status = Tcp4->Transmit (Tcp4, &TcpIo->TxToken.Tcp4Token);
818 Tcp6 = TcpIo->Tcp.Tcp6;
819 if (TcpIo->IsListenDone) {
820 Tcp6 = TcpIo->NewTcp.Tcp6;
827 Status = Tcp6->Transmit (Tcp6, &TcpIo->TxToken.Tcp6Token);
830 if (EFI_ERROR (Status)) {
834 while (!TcpIo->IsTxDone) {
835 if (TcpIo->TcpVersion == TCP_VERSION_4) {
842 TcpIo->IsTxDone =
FALSE;
843 Status = TcpIo->TxToken.Tcp4Token.CompletionToken.Status;
875 IN BOOLEAN AsyncMode,
884 UINT32 FragmentCount;
885 UINT32 CurrentFragment;
887 if ((TcpIo ==
NULL) || (TcpIo->Tcp.Tcp4 ==
NULL) || (Packet ==
NULL)) {
888 return EFI_INVALID_PARAMETER;
891 RxData = TcpIo->RxToken.Tcp4Token.Packet.RxData;
892 if (RxData ==
NULL) {
893 return EFI_INVALID_PARAMETER;
899 if (TcpIo->TcpVersion == TCP_VERSION_4) {
900 Tcp4 = TcpIo->Tcp.Tcp4;
902 if (TcpIo->IsListenDone) {
903 Tcp4 = TcpIo->NewTcp.Tcp4;
907 return EFI_DEVICE_ERROR;
909 }
else if (TcpIo->TcpVersion == TCP_VERSION_6) {
910 Tcp6 = TcpIo->Tcp.Tcp6;
912 if (TcpIo->IsListenDone) {
913 Tcp6 = TcpIo->NewTcp.Tcp6;
917 return EFI_DEVICE_ERROR;
920 return EFI_UNSUPPORTED;
923 FragmentCount = Packet->BlockOpNum;
925 if (Fragment ==
NULL) {
926 Status = EFI_OUT_OF_RESOURCES;
935 RxData->FragmentCount = 1;
939 while (CurrentFragment < FragmentCount) {
940 RxData->DataLength = Fragment[CurrentFragment].Len;
941 RxData->FragmentTable[0].FragmentLength = Fragment[CurrentFragment].Len;
942 RxData->FragmentTable[0].FragmentBuffer = Fragment[CurrentFragment].Bulk;
944 if (TcpIo->TcpVersion == TCP_VERSION_4) {
945 Status = Tcp4->Receive (Tcp4, &TcpIo->RxToken.Tcp4Token);
947 Status = Tcp6->Receive (Tcp6, &TcpIo->RxToken.Tcp6Token);
950 if (EFI_ERROR (Status)) {
954 while (!TcpIo->IsRxDone && ((Timeout ==
NULL) || EFI_ERROR (
gBS->CheckEvent (Timeout)))) {
958 if (TcpIo->TcpVersion == TCP_VERSION_4) {
965 if (!TcpIo->IsRxDone) {
969 if (TcpIo->TcpVersion == TCP_VERSION_4) {
970 Tcp4->Cancel (Tcp4, &TcpIo->RxToken.Tcp4Token.CompletionToken);
972 Tcp6->Cancel (Tcp6, &TcpIo->RxToken.Tcp6Token.CompletionToken);
975 Status = EFI_TIMEOUT;
978 TcpIo->IsRxDone =
FALSE;
981 Status = TcpIo->RxToken.Tcp4Token.CompletionToken.Status;
983 if (EFI_ERROR (Status)) {
987 Fragment[CurrentFragment].Len -= RxData->FragmentTable[0].FragmentLength;
988 if (Fragment[CurrentFragment].Len == 0) {
991 Fragment[CurrentFragment].Bulk += RxData->FragmentTable[0].FragmentLength;
997 if (Fragment !=
NULL) {
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI TcpIoCreateSocket(IN EFI_HANDLE Image, IN EFI_HANDLE Controller, IN UINT8 TcpVersion, IN TCP_IO_CONFIG_DATA *ConfigData, OUT TCP_IO *TcpIo)
EFI_STATUS EFIAPI TcpIoAccept(IN OUT TCP_IO *TcpIo, IN EFI_EVENT Timeout OPTIONAL)
EFI_STATUS EFIAPI TcpIoReceive(IN OUT TCP_IO *TcpIo, IN NET_BUF *Packet, IN BOOLEAN AsyncMode, IN EFI_EVENT Timeout OPTIONAL)
EFI_STATUS EFIAPI TcpIoConnect(IN OUT TCP_IO *TcpIo, IN EFI_EVENT Timeout OPTIONAL)
EFI_STATUS TcpIoGetMapping(IN EFI_TCP6_PROTOCOL *Tcp6, IN EFI_TCP6_CONFIG_DATA *Tcp6ConfigData)
EFI_STATUS EFIAPI TcpIoTransmit(IN TCP_IO *TcpIo, IN NET_BUF *Packet)
VOID EFIAPI TcpIoDestroySocket(IN TCP_IO *TcpIo)
VOID EFIAPI TcpIoReset(IN OUT TCP_IO *TcpIo)
VOID EFIAPI TcpIoCommonNotify(IN EFI_EVENT Event, IN VOID *Context)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI NetbufBuildExt(IN NET_BUF *Nbuf, IN OUT NET_FRAGMENT *ExtFragment, IN OUT UINT32 *ExtNum)
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define TCP_GET_MAPPING_TIMEOUT
EFI_IPv6_ADDRESS RemoteAddress
EFI_TCP6_ACCESS_POINT AccessPoint
EFI_TCP6_OPTION * ControlOption