IN OUT CHAR16 **MacString
);
+VOID
+NetLibCreateIPv4DPathNode (
+ IN OUT IPv4_DEVICE_PATH *Node,
+ IN EFI_HANDLE Controller,
+ IN IP4_ADDR LocalIp,
+ IN UINT16 LocalPort,
+ IN IP4_ADDR RemoteIp,
+ IN UINT16 RemotePort,
+ IN UINT16 Protocol,
+ IN BOOLEAN UseDefaultAddress
+ );
+
EFI_HANDLE
NetLibGetNicHandle (
IN EFI_HANDLE Controller,
#include <Protocol/ServiceBinding.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/LoadedImage.h>
+#include <Protocol/NicIp4Config.h>
#include <Library/NetLib.h>
#include <Library/BaseLib.h>
UINTN DeviceHandleCount;
UINTN Index;
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
- EFI_COMPONENT_NAME2_PROTOCOL *ComponentName;
-#else
EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
-#endif
EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration;
EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics;
return EFI_SUCCESS;
}
+/**
+ Check the default address used by the IPv4 driver is static or dynamic (acquired
+ from DHCP).
+
+ @param Controller The controller handle which has the NIC Ip4 Config Protocol
+ relative with the default address to judge.
+
+ @retval TRUE If the default address is static.
+ @retval FALSE If the default address is acquired from DHCP.
+
+**/
+STATIC
+BOOLEAN
+NetLibDefaultAddressIsStatic (
+ IN EFI_HANDLE Controller
+ )
+{
+ EFI_STATUS Status;
+ EFI_NIC_IP4_CONFIG_PROTOCOL *NicIp4;
+ UINTN Len;
+ NIC_IP4_CONFIG_INFO *ConfigInfo;
+ BOOLEAN IsStatic;
+
+ Status = gBS->HandleProtocol (
+ Controller,
+ &gEfiNicIp4ConfigProtocolGuid,
+ (VOID **) &NicIp4
+ );
+ if (EFI_ERROR (Status)) {
+ return TRUE;
+ }
+
+ Len = 0;
+ Status = NicIp4->GetInfo (NicIp4, &Len, NULL);
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ return TRUE;
+ }
+
+ ConfigInfo = NetAllocatePool (Len);
+ if (ConfigInfo == NULL) {
+ return TRUE;
+ }
+
+ IsStatic = TRUE;
+ Status = NicIp4->GetInfo (NicIp4, &Len, ConfigInfo);
+ if (EFI_ERROR (Status)) {
+ goto ON_EXIT;
+ }
+
+ IsStatic = (BOOLEAN) (ConfigInfo->Source == IP4_CONFIG_SOURCE_STATIC);
+
+ON_EXIT:
+
+ NetFreePool (ConfigInfo);
+
+ return IsStatic;
+}
+
+/**
+ Create an IPv4 device path node.
+
+ @param Node Pointer to the IPv4 device path node.
+ @param Controller The handle where the NIC IP4 config protocol resides.
+ @param LocalIp The local IPv4 address.
+ @param LocalPort The local port.
+ @param RemoteIp The remote IPv4 address.
+ @param RemotePort The remote port.
+ @param Protocol The protocol type in the IP header.
+ @param UseDefaultAddress Whether this instance is using default address or not.
+
+ @retval None
+**/
+VOID
+NetLibCreateIPv4DPathNode (
+ IN OUT IPv4_DEVICE_PATH *Node,
+ IN EFI_HANDLE Controller,
+ IN IP4_ADDR LocalIp,
+ IN UINT16 LocalPort,
+ IN IP4_ADDR RemoteIp,
+ IN UINT16 RemotePort,
+ IN UINT16 Protocol,
+ IN BOOLEAN UseDefaultAddress
+ )
+{
+ Node->Header.Type = MESSAGING_DEVICE_PATH;
+ Node->Header.SubType = MSG_IPv4_DP;
+ SetDevicePathNodeLength (&Node->Header, 19);
+
+ NetCopyMem (&Node->LocalIpAddress, &LocalIp, sizeof (EFI_IPv4_ADDRESS));
+ NetCopyMem (&Node->RemoteIpAddress, &RemoteIp, sizeof (EFI_IPv4_ADDRESS));
+
+ Node->LocalPort = LocalPort;
+ Node->RemotePort = RemotePort;
+
+ Node->Protocol = Protocol;
+
+ if (!UseDefaultAddress) {
+ Node->StaticIpAddress = TRUE;
+ } else {
+ Node->StaticIpAddress = NetLibDefaultAddressIsStatic (Controller);
+ }
+}
+
/**
Find the UNDI/SNP handle from controller and protocol GUID.
\r
[Protocols]\r
gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
-\r
+ gEfiNicIp4ConfigProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
UINT32 Signature;
EFI_HANDLE SockHandle; // the virtual handle of the socket
EFI_HANDLE DriverBinding; // socket't driver binding protocol
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
SOCK_CONFIGURE_STATE ConfigureState;
SOCK_TYPE Type;
SOCK_STATE State;
if (SOCK_IS_CONFIGURED (Sock)) {\r
NetListRemoveEntry (&Tcb->List);\r
\r
+ //\r
+ // Uninstall the device path protocl.\r
+ //\r
+ gBS->UninstallProtocolInterface (\r
+ Sock->SockHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ Sock->DevicePath\r
+ );\r
+ NetFreePool (Sock->DevicePath);\r
+\r
TcpSetVariableData (TcpProto->TcpService);\r
}\r
\r
Tcb->TTL = CfgData->TimeToLive;\r
Tcb->TOS = CfgData->TypeOfService;\r
\r
+ Tcb->UseDefaultAddr = CfgData->AccessPoint.UseDefaultAddress;\r
+\r
NetCopyMem (&Tcb->LocalEnd.Ip, &CfgData->AccessPoint.StationAddress, sizeof (IP4_ADDR));\r
Tcb->LocalEnd.Port = HTONS (CfgData->AccessPoint.StationPort);\r
Tcb->SubnetMask = CfgData->AccessPoint.SubnetMask;\r
\r
- NetCopyMem (&Tcb->RemoteEnd.Ip, &CfgData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));\r
- Tcb->RemoteEnd.Port = HTONS (CfgData->AccessPoint.RemotePort);\r
+ if (CfgData->AccessPoint.ActiveFlag) {\r
+ NetCopyMem (&Tcb->RemoteEnd.Ip, &CfgData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));\r
+ Tcb->RemoteEnd.Port = HTONS (CfgData->AccessPoint.RemotePort);\r
+ } else {\r
+ Tcb->RemoteEnd.Ip = 0;\r
+ Tcb->RemoteEnd.Port = 0;\r
+ }\r
\r
Option = CfgData->ControlOption;\r
\r
}\r
}\r
\r
+ //\r
+ // The socket is bound, the <SrcIp, SrcPort, DstIp, DstPort> is\r
+ // determined, construct the IP device path and install it.\r
+ //\r
+ Status = TcpInstallDevicePath (Sk);\r
+ if (EFI_ERROR (Status)) {\r
+ goto OnExit;\r
+ }\r
+\r
//\r
// update state of Tcb and socket\r
//\r
\r
return Tcp4Route (Tcb, (TCP4_ROUTE_INFO *) Data);\r
\r
- default:\r
- return EFI_UNSUPPORTED;\r
}\r
\r
return EFI_SUCCESS;\r
);\r
if (EFI_ERROR (Status)) {\r
SockDestroyChild (Sock);\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ //\r
+ // Open the device path on the handle where service binding resides on.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ TcpServiceData->ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &Sock->ParentDevicePath,\r
+ TcpServiceData->DriverBindingHandle,\r
+ Sock->SockHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ TcpServiceData->IpIo->ChildHandle,\r
+ &gEfiIp4ProtocolGuid,\r
+ TcpServiceData->DriverBindingHandle,\r
+ Sock->SockHandle\r
+ );\r
+ SockDestroyChild (Sock);\r
}\r
\r
ON_EXIT:\r
\r
Status = SockDestroyChild (Sock);\r
\r
+ //\r
+ // Close the device path protocol\r
+ //\r
+ gBS->CloseProtocol (\r
+ TcpServiceData->ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ TcpServiceData->DriverBindingHandle,\r
+ ChildHandle\r
+ );\r
+\r
//\r
// Close the Ip4 protocol.\r
//\r
# Component name for module Tcp4\r
#\r
# FIX ME!\r
-# Copyright (c) 2006, Intel Corporation. \r
+# Copyright (c) 2006, Intel Corporation.\r
#\r
# All rights reserved. This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
DebugLib\r
NetLib\r
IpIoLib\r
+ DevicePathLib\r
\r
[Protocols]\r
gEfiIp4ProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
IN TCP4_SERVICE_DATA *Tcp4Service
);
+EFI_STATUS
+TcpInstallDevicePath (
+ IN SOCKET *Sock
+ );
+
#endif
\r
#include "Tcp4Main.h"\r
\r
+#include <Library/DevicePathLib.h>\r
+\r
NET_LIST_ENTRY mTcpRunQue = {\r
&mTcpRunQue,\r
&mTcpRunQue\r
)\r
{\r
TCP_CB *Clone;\r
+ TCP4_SERVICE_DATA *TcpService;\r
\r
Clone = NetAllocatePool (sizeof (TCP_CB));\r
\r
\r
((TCP4_PROTO_DATA *) (Clone->Sk->ProtoReserved))->TcpPcb = Clone;\r
\r
+ //\r
+ // Open the device path on the handle where service binding resides on.\r
+ //\r
+ TcpService = ((TCP4_PROTO_DATA *) (Clone->Sk->ProtoReserved))->TcpService;\r
+ gBS->OpenProtocol (\r
+ TcpService->ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &Clone->Sk->ParentDevicePath,\r
+ TcpService->DriverBindingHandle,\r
+ Clone->Sk->SockHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+\r
return Clone;\r
}\r
\r
case TCP_ESTABLISHED:\r
\r
SockConnEstablished (Tcb->Sk);\r
+\r
+ if (Tcb->Parent != NULL) {\r
+ //\r
+ // A new connection is accepted by a listening socket, install\r
+ // the device path.\r
+ //\r
+ TcpInstallDevicePath (Tcb->Sk);\r
+ }\r
+\r
break;\r
\r
case TCP_CLOSED:\r
Tcp4Service->MacString = NULL;\r
}\r
\r
+EFI_STATUS\r
+TcpInstallDevicePath (\r
+ IN SOCKET *Sock\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Install the device path protocol on the TCP instance.\r
+\r
+Arguments:\r
+\r
+ Sock - Pointer to the socket representing the TCP instance.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The device path protocol is installed.\r
+ other - Failed to install the device path protocol.\r
+\r
+--*/\r
+{\r
+ TCP4_PROTO_DATA *TcpProto;\r
+ TCP4_SERVICE_DATA *TcpService;\r
+ TCP_CB *Tcb;\r
+ IPv4_DEVICE_PATH Ip4DPathNode;\r
+ EFI_STATUS Status;\r
+\r
+ TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
+ TcpService = TcpProto->TcpService;\r
+ Tcb = TcpProto->TcpPcb;\r
+\r
+ NetLibCreateIPv4DPathNode (\r
+ &Ip4DPathNode,\r
+ TcpService->ControllerHandle,\r
+ Tcb->LocalEnd.Ip,\r
+ NTOHS (Tcb->LocalEnd.Port),\r
+ Tcb->RemoteEnd.Ip,\r
+ NTOHS (Tcb->RemoteEnd.Port),\r
+ EFI_IP_PROTO_TCP,\r
+ Tcb->UseDefaultAddr\r
+ );\r
+\r
+ Sock->DevicePath = AppendDevicePathNode (\r
+ Sock->ParentDevicePath,\r
+ (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode\r
+ );\r
+ if (Sock->DevicePath == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Sock->SockHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ Sock->DevicePath\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ NetFreePool (Sock->DevicePath);\r
+ }\r
+\r
+ return Status;\r
+}\r
//\r
// Wrap the RxData and put this Wrap into the instances RcvdDgramQue.\r
//\r
- CopyMem (&Wrap, Udp4WrapRxData (Instance, Packet, RxData), sizeof (Wrap));\r
+ Wrap = Udp4WrapRxData (Instance, Packet, RxData);\r
if (Wrap == NULL) {\r
continue;\r
}\r