12UINT16 mTcp4RandomPort;
13UINT16 mTcp6RandomPort;
108 if (mTcpTimer.RefCnt == 0) {
109 Status =
gBS->CreateEvent (
110 EVT_TIMER | EVT_NOTIFY_SIGNAL,
114 &mTcpTimer.TimerEvent
116 if (!EFI_ERROR (Status)) {
117 Status =
gBS->SetTimer (
118 mTcpTimer.TimerEvent,
125 if (!EFI_ERROR (Status)) {
141 ASSERT (mTcpTimer.RefCnt > 0);
145 if (mTcpTimer.RefCnt > 0) {
150 gBS->CloseEvent (mTcpTimer.TimerEvent);
151 mTcpTimer.TimerEvent =
NULL;
182 if (EFI_ERROR (Status)) {
183 DEBUG ((DEBUG_ERROR,
"%a failed to generate random number: %r\n", __func__, Status));
192 if (EFI_ERROR (Status)) {
193 DEBUG ((DEBUG_ERROR,
"%a Failed to generate random number: %r\n", __func__, Status));
208 if (EFI_ERROR (Status)) {
223 if (EFI_ERROR (Status)) {
235 mTcp4RandomPort = (UINT16)(TCP_PORT_KNOWN + (Random % TCP_PORT_KNOWN));
236 mTcp6RandomPort = mTcp4RandomPort;
269 if (IpVersion == IP_VERSION_4) {
270 IpServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;
271 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
273 IpServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;
274 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
277 Status =
gBS->OpenProtocol (
279 TcpServiceBindingGuid,
283 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
285 if (!EFI_ERROR (Status)) {
286 return EFI_ALREADY_STARTED;
289 Status =
gBS->OpenProtocol (
291 IpServiceBindingGuid,
295 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
297 if (EFI_ERROR (Status)) {
298 return EFI_UNSUPPORTED;
301 Status =
gBS->LocateProtocol (&gEfiHash2ProtocolGuid,
NULL, (VOID **)&Hash2Protocol);
302 if (EFI_ERROR (Status)) {
310 Status =
gBS->LocateProtocol (
311 &gEfiHash2ServiceBindingProtocolGuid,
313 (VOID **)&Hash2ServiceBinding
315 if (EFI_ERROR (Status) || (Hash2ServiceBinding ==
NULL) || (Hash2ServiceBinding->CreateChild ==
NULL)) {
316 return EFI_UNSUPPORTED;
322 Status = Hash2ServiceBinding->CreateChild (Hash2ServiceBinding, &mHash2ServiceHandle);
323 if (EFI_ERROR (Status)) {
324 return EFI_UNSUPPORTED;
332 if (TcpServiceData ==
NULL) {
333 return EFI_OUT_OF_RESOURCES;
336 TcpServiceData->Signature = TCP_DRIVER_SIGNATURE;
337 TcpServiceData->ControllerHandle = Controller;
338 TcpServiceData->DriverBindingHandle = Image;
339 TcpServiceData->IpVersion = IpVersion;
341 &TcpServiceData->ServiceBinding,
346 TcpServiceData->IpIo =
IpIoCreate (Image, Controller, IpVersion);
347 if (TcpServiceData->IpIo ==
NULL) {
348 Status = EFI_OUT_OF_RESOURCES;
355 if (IpVersion == IP_VERSION_4) {
358 &mIp4IoDefaultIpConfigData,
365 &mIp6IoDefaultIpConfigData,
372 Status =
IpIoOpen (TcpServiceData->IpIo, &OpenData);
373 if (EFI_ERROR (Status)) {
378 if (EFI_ERROR (Status)) {
382 Status =
gBS->InstallMultipleProtocolInterfaces (
384 TcpServiceBindingGuid,
385 &TcpServiceData->ServiceBinding,
388 if (EFI_ERROR (Status)) {
398 if (TcpServiceData->IpIo !=
NULL) {
400 TcpServiceData->IpIo =
NULL;
427 UINTN NumberOfChildren;
430 if ((Entry ==
NULL) || (Context ==
NULL)) {
431 return EFI_INVALID_PARAMETER;
434 Sock = NET_LIST_USER_STRUCT_S (Entry,
SOCKET, Link, SOCK_SIGNATURE);
443 return ServiceBinding->DestroyChild (ServiceBinding, Sock->
SockHandle);
481 ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));
483 if (IpVersion == IP_VERSION_4) {
484 IpProtocolGuid = &gEfiIp4ProtocolGuid;
485 ServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
487 IpProtocolGuid = &gEfiIp6ProtocolGuid;
488 ServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
492 if (NicHandle ==
NULL) {
499 if (mHash2ServiceHandle !=
NULL) {
500 Status =
gBS->LocateProtocol (
501 &gEfiHash2ServiceBindingProtocolGuid,
503 (VOID **)&Hash2ServiceBinding
505 if (EFI_ERROR (Status) || (Hash2ServiceBinding ==
NULL) || (Hash2ServiceBinding->DestroyChild ==
NULL)) {
506 return EFI_UNSUPPORTED;
512 Status = Hash2ServiceBinding->DestroyChild (Hash2ServiceBinding, mHash2ServiceHandle);
513 if (EFI_ERROR (Status)) {
514 return EFI_UNSUPPORTED;
517 mHash2ServiceHandle =
NULL;
520 Status =
gBS->OpenProtocol (
523 (VOID **)&ServiceBinding,
526 EFI_OPEN_PROTOCOL_GET_PROTOCOL
528 if (EFI_ERROR (Status)) {
529 return EFI_DEVICE_ERROR;
532 TcpServiceData = TCP_SERVICE_FROM_THIS (ServiceBinding);
534 if (NumberOfChildren != 0) {
535 List = &TcpServiceData->SocketList;
536 Context.ServiceBinding = ServiceBinding;
537 Context.NumberOfChildren = NumberOfChildren;
538 Context.ChildHandleBuffer = ChildHandleBuffer;
545 }
else if (
IsListEmpty (&TcpServiceData->SocketList)) {
549 gBS->UninstallMultipleProtocolInterfaces (
560 TcpServiceData->IpIo =
NULL;
604 Status =
gBS->OpenProtocol (
606 &gEfiTcp4ServiceBindingProtocolGuid,
608 This->DriverBindingHandle,
610 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
612 if (!EFI_ERROR (Status)) {
613 return EFI_ALREADY_STARTED;
619 Status =
gBS->OpenProtocol (
621 &gEfiIp4ServiceBindingProtocolGuid,
623 This->DriverBindingHandle,
625 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
654 Status =
TcpCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_4);
655 if ((Status == EFI_ALREADY_STARTED) || (Status == EFI_UNSUPPORTED)) {
688 This->DriverBindingHandle,
721 Status =
gBS->OpenProtocol (
723 &gEfiTcp6ServiceBindingProtocolGuid,
725 This->DriverBindingHandle,
727 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
729 if (!EFI_ERROR (Status)) {
730 return EFI_ALREADY_STARTED;
736 Status =
gBS->OpenProtocol (
738 &gEfiIp6ServiceBindingProtocolGuid,
740 This->DriverBindingHandle,
742 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
771 Status =
TcpCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_6);
772 if ((Status == EFI_ALREADY_STARTED) || (Status == EFI_UNSUPPORTED)) {
805 This->DriverBindingHandle,
833 if (This->IpVersion == IP_VERSION_4) {
834 IpProtocolGuid = &gEfiIp4ProtocolGuid;
836 IpProtocolGuid = &gEfiIp6ProtocolGuid;
839 TcpServiceData = ((
TCP_PROTO_DATA *)This->ProtoReserved)->TcpService;
844 Status =
gBS->OpenProtocol (
845 TcpServiceData->IpIo->ChildHandle,
848 TcpServiceData->DriverBindingHandle,
850 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
852 if (EFI_ERROR (Status)) {
859 Status =
gBS->OpenProtocol (
860 TcpServiceData->ControllerHandle,
861 &gEfiDevicePathProtocolGuid,
862 (VOID **)&This->ParentDevicePath,
863 TcpServiceData->DriverBindingHandle,
865 EFI_OPEN_PROTOCOL_GET_PROTOCOL
867 if (EFI_ERROR (Status)) {
869 TcpServiceData->IpIo->ChildHandle,
871 TcpServiceData->DriverBindingHandle,
900 if (This->IpVersion == IP_VERSION_4) {
901 IpProtocolGuid = &gEfiIp4ProtocolGuid;
903 IpProtocolGuid = &gEfiIp6ProtocolGuid;
906 TcpServiceData = ((
TCP_PROTO_DATA *)This->ProtoReserved)->TcpService;
917 TcpServiceData->IpIo->ChildHandle,
919 TcpServiceData->DriverBindingHandle,
957 if ((
NULL == This) || (
NULL == ChildHandle)) {
958 return EFI_INVALID_PARAMETER;
961 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
964 TcpServiceData = TCP_SERVICE_FROM_THIS (This);
965 TcpProto.TcpService = TcpServiceData;
966 TcpProto.TcpPcb =
NULL;
972 mTcpDefaultSockData.ProtoData = &TcpProto;
974 mTcpDefaultSockData.
DriverBinding = TcpServiceData->DriverBindingHandle;
975 mTcpDefaultSockData.IpVersion = TcpServiceData->IpVersion;
977 if (TcpServiceData->IpVersion == IP_VERSION_4) {
978 mTcpDefaultSockData.
Protocol = &gTcp4ProtocolTemplate;
980 mTcpDefaultSockData.
Protocol = &gTcp6ProtocolTemplate;
987 "TcpDriverBindingCreateChild: No resource to create a Tcp Child\n")
990 Status = EFI_OUT_OF_RESOURCES;
995 mTcpDefaultSockData.ProtoData =
NULL;
997 gBS->RestoreTPL (OldTpl);
1030 if ((
NULL == This) || (
NULL == ChildHandle)) {
1031 return EFI_INVALID_PARAMETER;
1037 Status =
gBS->OpenProtocol (
1039 &gEfiTcp4ProtocolGuid,
1043 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1045 if (EFI_ERROR (Status)) {
1049 Status =
gBS->OpenProtocol (
1051 &gEfiTcp6ProtocolGuid,
1055 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1057 if (EFI_ERROR (Status)) {
1058 Status = EFI_UNSUPPORTED;
1062 if (!EFI_ERROR (Status)) {
1067 Sock = SOCK_FROM_THIS (Tcp);
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
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)
IP_IO *EFIAPI IpIoCreate(IN EFI_HANDLE Image, IN EFI_HANDLE Controller, IN UINT8 IpVersion)
EFI_STATUS EFIAPI IpIoOpen(IN OUT IP_IO *IpIo, IN IP_IO_OPEN_DATA *OpenData)
#define DEBUG(Expression)
BOOLEAN EFIAPI NetIsInHandleBuffer(IN EFI_HANDLE Handle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
EFI_STATUS EFIAPI PseudoRandomU32(OUT UINT32 *Output)
EFI_HANDLE EFIAPI NetLibGetNicHandle(IN EFI_HANDLE Controller, IN EFI_GUID *ProtocolGuid)
EFI_STATUS EFIAPI NetDestroyLinkList(IN LIST_ENTRY *List, IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, IN VOID *Context OPTIONAL, OUT UINTN *ListLength OPTIONAL)
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.
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)
VOID TcpDestroyTimer(VOID)
EFI_STATUS EFIAPI Tcp4DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
EFI_STATUS EFIAPI TcpDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI TcpDestroyChildEntryInHandleBuffer(IN LIST_ENTRY *Entry, IN VOID *Context)
EFI_STATUS TcpDestroyService(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL, IN UINT8 IpVersion)
EFI_STATUS TcpCreateService(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN UINT8 IpVersion)
EFI_STATUS EFIAPI Tcp6DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS EFIAPI Tcp4DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
VOID TcpDestroySocketCallback(IN SOCKET *This, IN VOID *Context)
EFI_STATUS EFIAPI TcpServiceBindingDestroyChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle)
EFI_STATUS EFIAPI Tcp6DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS TcpCreateTimer(VOID)
EFI_STATUS EFIAPI TcpServiceBindingCreateChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN OUT EFI_HANDLE *ChildHandle)
EFI_STATUS EFIAPI Tcp6DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
EFI_STATUS EFIAPI Tcp4DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
VOID EFIAPI TcpTicking(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI TcpRxCallback(IN EFI_STATUS Status, IN UINT8 IcmpErr, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Pkt, IN VOID *Context OPTIONAL)
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)
EFI_STATUS EFIAPI Tcp4Accept(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_LISTEN_TOKEN *ListenToken)
EFI_STATUS EFIAPI Tcp4Cancel(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL)
EFI_STATUS EFIAPI Tcp4Receive(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_IO_TOKEN *Token)
EFI_STATUS EFIAPI Tcp6Close(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CLOSE_TOKEN *CloseToken)
EFI_STATUS EFIAPI Tcp6Connect(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CONNECTION_TOKEN *ConnectionToken)
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)
EFI_STATUS EFIAPI Tcp6Configure(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_CONFIG_DATA *Tcp6ConfigData OPTIONAL)
EFI_STATUS EFIAPI Tcp6Receive(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_IO_TOKEN *Token)
EFI_STATUS EFIAPI Tcp4Transmit(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_IO_TOKEN *Token)
EFI_STATUS EFIAPI Tcp4Close(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CLOSE_TOKEN *CloseToken)
EFI_STATUS EFIAPI Tcp6Poll(IN EFI_TCP6_PROTOCOL *This)
EFI_STATUS EFIAPI Tcp4Poll(IN EFI_TCP4_PROTOCOL *This)
EFI_STATUS EFIAPI Tcp6Transmit(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_IO_TOKEN *Token)
EFI_STATUS EFIAPI Tcp6Cancel(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_COMPLETION_TOKEN *Token OPTIONAL)
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)
EFI_STATUS EFIAPI Tcp6Accept(IN EFI_TCP6_PROTOCOL *This, IN EFI_TCP6_LISTEN_TOKEN *ListenToken)
EFI_STATUS EFIAPI Tcp4Connect(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken)
EFI_STATUS EFIAPI Tcp4Configure(IN EFI_TCP4_PROTOCOL *This, IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL)
#define TCP_TICK_HZ
The frequence of TCP tick.
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)
EFI_HANDLE DriverBindingHandle
PKT_RCVD_NOTIFY PktRcvdNotify
Receive callback.
IP_IO_IP_CONFIG_DATA IpConfigData
Configuration of the IP instance.
EFI_HANDLE DriverBinding
The driver binding handle.
EFI_HANDLE SockHandle
The virtual handle of the socket.