summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2007-08-27 09:17:26 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2007-08-27 09:17:26 +0000
commite5e12de7d0a67111060c77723df39885c91a8ea5 (patch)
tree4a16a8e5a4b7c32a2c6bacfb71f065f86389dd3c
parent98376cc51df0c0bd92a3436ec3309401d98c84e3 (diff)
downloadedk2-e5e12de7d0a67111060c77723df39885c91a8ea5.zip
edk2-e5e12de7d0a67111060c77723df39885c91a8ea5.tar.gz
edk2-e5e12de7d0a67111060c77723df39885c91a8ea5.tar.bz2
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
2. Fixed one porting bug in Udp4Impl.c git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3717 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/Include/Library/NetLib.h12
-rw-r--r--MdeModulePkg/Library/DxeNetLib/DxeNetLib.c108
-rw-r--r--MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf2
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h2
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c32
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c32
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf3
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h5
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c87
-rw-r--r--MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c2
10 files changed, 274 insertions, 11 deletions
diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h
index 8787f6c..279c106 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -457,6 +457,18 @@ NetLibGetMacString (
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,
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index 0dff772..ddcd6c9 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -24,6 +24,7 @@ Abstract:
#include <Protocol/ServiceBinding.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/LoadedImage.h>
+#include <Protocol/NicIp4Config.h>
#include <Library/NetLib.h>
#include <Library/BaseLib.h>
@@ -838,11 +839,7 @@ NetLibDefaultUnload (
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;
@@ -1123,6 +1120,109 @@ NetLibGetMacString (
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.
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
index f247e61..2bd876e 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
@@ -54,4 +54,4 @@
[Protocols]
gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
-
+ gEfiNicIp4ConfigProtocolGuid # PROTOCOL ALWAYS_CONSUMED
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h b/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
index 7c219e3..75efa04 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
@@ -328,6 +328,8 @@ struct _SOCKET {
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;
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
index c714dd3..0b845ee 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
@@ -248,6 +248,16 @@ Tcp4FlushPcb (
if (SOCK_IS_CONFIGURED (Sock)) {
NetListRemoveEntry (&Tcb->List);
+ //
+ // Uninstall the device path protocl.
+ //
+ gBS->UninstallProtocolInterface (
+ Sock->SockHandle,
+ &gEfiDevicePathProtocolGuid,
+ Sock->DevicePath
+ );
+ NetFreePool (Sock->DevicePath);
+
TcpSetVariableData (TcpProto->TcpService);
}
@@ -428,12 +438,19 @@ Tcp4ConfigurePcb (
Tcb->TTL = CfgData->TimeToLive;
Tcb->TOS = CfgData->TypeOfService;
+ Tcb->UseDefaultAddr = CfgData->AccessPoint.UseDefaultAddress;
+
NetCopyMem (&Tcb->LocalEnd.Ip, &CfgData->AccessPoint.StationAddress, sizeof (IP4_ADDR));
Tcb->LocalEnd.Port = HTONS (CfgData->AccessPoint.StationPort);
Tcb->SubnetMask = CfgData->AccessPoint.SubnetMask;
- NetCopyMem (&Tcb->RemoteEnd.Ip, &CfgData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));
- Tcb->RemoteEnd.Port = HTONS (CfgData->AccessPoint.RemotePort);
+ if (CfgData->AccessPoint.ActiveFlag) {
+ NetCopyMem (&Tcb->RemoteEnd.Ip, &CfgData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));
+ Tcb->RemoteEnd.Port = HTONS (CfgData->AccessPoint.RemotePort);
+ } else {
+ Tcb->RemoteEnd.Ip = 0;
+ Tcb->RemoteEnd.Port = 0;
+ }
Option = CfgData->ControlOption;
@@ -538,6 +555,15 @@ Tcp4ConfigurePcb (
}
//
+ // The socket is bound, the <SrcIp, SrcPort, DstIp, DstPort> is
+ // determined, construct the IP device path and install it.
+ //
+ Status = TcpInstallDevicePath (Sk);
+ if (EFI_ERROR (Status)) {
+ goto OnExit;
+ }
+
+ //
// update state of Tcb and socket
//
if (CfgData->AccessPoint.ActiveFlag == FALSE) {
@@ -681,8 +707,6 @@ Tcp4Dispatcher (
return Tcp4Route (Tcb, (TCP4_ROUTE_INFO *) Data);
- default:
- return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
index 3ae8a20..1eefb38 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
@@ -586,6 +586,28 @@ Tcp4ServiceBindingCreateChild (
);
if (EFI_ERROR (Status)) {
SockDestroyChild (Sock);
+ goto ON_EXIT;
+ }
+
+ //
+ // Open the device path on the handle where service binding resides on.
+ //
+ Status = gBS->OpenProtocol (
+ TcpServiceData->ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID **) &Sock->ParentDevicePath,
+ TcpServiceData->DriverBindingHandle,
+ Sock->SockHandle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ TcpServiceData->IpIo->ChildHandle,
+ &gEfiIp4ProtocolGuid,
+ TcpServiceData->DriverBindingHandle,
+ Sock->SockHandle
+ );
+ SockDestroyChild (Sock);
}
ON_EXIT:
@@ -653,6 +675,16 @@ Tcp4ServiceBindingDestroyChild (
Status = SockDestroyChild (Sock);
//
+ // Close the device path protocol
+ //
+ gBS->CloseProtocol (
+ TcpServiceData->ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ TcpServiceData->DriverBindingHandle,
+ ChildHandle
+ );
+
+ //
// Close the Ip4 protocol.
//
gBS->CloseProtocol (
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
index 44f3623..86c88a9 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
@@ -2,7 +2,7 @@
# Component name for module Tcp4
#
# FIX ME!
-# Copyright (c) 2006, Intel Corporation.
+# Copyright (c) 2006, Intel Corporation.
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -68,6 +68,7 @@
DebugLib
NetLib
IpIoLib
+ DevicePathLib
[Protocols]
gEfiIp4ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h
index 6441c13..be99f3b 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h
@@ -350,4 +350,9 @@ TcpClearVariableData (
IN TCP4_SERVICE_DATA *Tcp4Service
);
+EFI_STATUS
+TcpInstallDevicePath (
+ IN SOCKET *Sock
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
index fdd64ef..2eaf0cc 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
@@ -23,6 +23,8 @@ Abstract:
#include "Tcp4Main.h"
+#include <Library/DevicePathLib.h>
+
NET_LIST_ENTRY mTcpRunQue = {
&mTcpRunQue,
&mTcpRunQue
@@ -423,6 +425,7 @@ TcpCloneTcb (
)
{
TCP_CB *Clone;
+ TCP4_SERVICE_DATA *TcpService;
Clone = NetAllocatePool (sizeof (TCP_CB));
@@ -451,6 +454,19 @@ TcpCloneTcb (
((TCP4_PROTO_DATA *) (Clone->Sk->ProtoReserved))->TcpPcb = Clone;
+ //
+ // Open the device path on the handle where service binding resides on.
+ //
+ TcpService = ((TCP4_PROTO_DATA *) (Clone->Sk->ProtoReserved))->TcpService;
+ gBS->OpenProtocol (
+ TcpService->ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID **) &Clone->Sk->ParentDevicePath,
+ TcpService->DriverBindingHandle,
+ Clone->Sk->SockHandle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+
return Clone;
}
@@ -530,6 +546,15 @@ TcpSetState (
case TCP_ESTABLISHED:
SockConnEstablished (Tcb->Sk);
+
+ if (Tcb->Parent != NULL) {
+ //
+ // A new connection is accepted by a listening socket, install
+ // the device path.
+ //
+ TcpInstallDevicePath (Tcb->Sk);
+ }
+
break;
case TCP_CLOSED:
@@ -1091,3 +1116,65 @@ TcpClearVariableData (
Tcp4Service->MacString = NULL;
}
+EFI_STATUS
+TcpInstallDevicePath (
+ IN SOCKET *Sock
+ )
+/*++
+
+Routine Description:
+
+ Install the device path protocol on the TCP instance.
+
+Arguments:
+
+ Sock - Pointer to the socket representing the TCP instance.
+
+Returns:
+
+ EFI_SUCCESS - The device path protocol is installed.
+ other - Failed to install the device path protocol.
+
+--*/
+{
+ TCP4_PROTO_DATA *TcpProto;
+ TCP4_SERVICE_DATA *TcpService;
+ TCP_CB *Tcb;
+ IPv4_DEVICE_PATH Ip4DPathNode;
+ EFI_STATUS Status;
+
+ TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;
+ TcpService = TcpProto->TcpService;
+ Tcb = TcpProto->TcpPcb;
+
+ NetLibCreateIPv4DPathNode (
+ &Ip4DPathNode,
+ TcpService->ControllerHandle,
+ Tcb->LocalEnd.Ip,
+ NTOHS (Tcb->LocalEnd.Port),
+ Tcb->RemoteEnd.Ip,
+ NTOHS (Tcb->RemoteEnd.Port),
+ EFI_IP_PROTO_TCP,
+ Tcb->UseDefaultAddr
+ );
+
+ Sock->DevicePath = AppendDevicePathNode (
+ Sock->ParentDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode
+ );
+ if (Sock->DevicePath == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = gBS->InstallProtocolInterface (
+ &Sock->SockHandle,
+ &gEfiDevicePathProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ Sock->DevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ NetFreePool (Sock->DevicePath);
+ }
+
+ return Status;
+}
diff --git a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
index 5cf87c7..dd4ed1b 100644
--- a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
+++ b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
@@ -1349,7 +1349,7 @@ Udp4EnqueueDgram (
//
// Wrap the RxData and put this Wrap into the instances RcvdDgramQue.
//
- CopyMem (&Wrap, Udp4WrapRxData (Instance, Packet, RxData), sizeof (Wrap));
+ Wrap = Udp4WrapRxData (Instance, Packet, RxData);
if (Wrap == NULL) {
continue;
}