]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 27 Aug 2007 09:17:26 +0000 (09:17 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 27 Aug 2007 09:17:26 +0000 (09:17 +0000)
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

MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Driver.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c

index 8787f6cf7addedfea8b99b26f517df7ae18359d0..279c10698d5f1530aa2aafc9323722eba8e752ad 100644 (file)
@@ -457,6 +457,18 @@ NetLibGetMacString (
   IN OUT       CHAR16      **MacString
   );
 
   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,
 EFI_HANDLE
 NetLibGetNicHandle (
   IN EFI_HANDLE             Controller,
index 0dff772b7ae73ec916f0a98baa901d0cb9f319de..ddcd6c93ece608dbfdddede09c66a3fbe4ce6a49 100644 (file)
@@ -24,6 +24,7 @@ Abstract:
 #include <Protocol/ServiceBinding.h>
 #include <Protocol/SimpleNetwork.h>
 #include <Protocol/LoadedImage.h>
 #include <Protocol/ServiceBinding.h>
 #include <Protocol/SimpleNetwork.h>
 #include <Protocol/LoadedImage.h>
+#include <Protocol/NicIp4Config.h>
 
 #include <Library/NetLib.h>
 #include <Library/BaseLib.h>
 
 #include <Library/NetLib.h>
 #include <Library/BaseLib.h>
@@ -838,11 +839,7 @@ NetLibDefaultUnload (
   UINTN                             DeviceHandleCount;
   UINTN                             Index;
   EFI_DRIVER_BINDING_PROTOCOL       *DriverBinding;
   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;
   EFI_COMPONENT_NAME_PROTOCOL       *ComponentName;
-#endif
   EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration;
   EFI_DRIVER_DIAGNOSTICS_PROTOCOL   *DriverDiagnostics;
 
   EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration;
   EFI_DRIVER_DIAGNOSTICS_PROTOCOL   *DriverDiagnostics;
 
@@ -1123,6 +1120,109 @@ NetLibGetMacString (
   return EFI_SUCCESS;
 }
 
   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.
 
 /**
   Find the UNDI/SNP handle from controller and protocol GUID.
index f247e610836006956f46bd5ac3673d029e53e6c9..2bd876e9a04d5a4bd1dd00311813ed3b700d4146 100644 (file)
@@ -54,4 +54,4 @@
 \r
 [Protocols]\r
   gEfiSimpleNetworkProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r
 \r
 [Protocols]\r
   gEfiSimpleNetworkProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r
-\r
+  gEfiNicIp4ConfigProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
index 7c219e3b9b67db23bb5037ae21e94396c8f4e7be..75efa045b1b5e6a1a0406d24e46804e4cf0e540c 100644 (file)
@@ -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
   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;
   SOCK_CONFIGURE_STATE  ConfigureState;
   SOCK_TYPE             Type;
   SOCK_STATE            State;
index c714dd3dae9c197dfa12a1dc559ea4c7f720616c..0b845ee9adf996f726b7565e6389af083e3b8297 100644 (file)
@@ -248,6 +248,16 @@ Tcp4FlushPcb (
   if (SOCK_IS_CONFIGURED (Sock)) {\r
     NetListRemoveEntry (&Tcb->List);\r
 \r
   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
     TcpSetVariableData (TcpProto->TcpService);\r
   }\r
 \r
@@ -428,12 +438,19 @@ Tcp4ConfigurePcb (
   Tcb->TTL            = CfgData->TimeToLive;\r
   Tcb->TOS            = CfgData->TypeOfService;\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->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
   Option              = CfgData->ControlOption;\r
 \r
@@ -537,6 +554,15 @@ Tcp4ConfigurePcb (
     }\r
   }\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
   // update state of Tcb and socket\r
   //\r
@@ -681,8 +707,6 @@ Tcp4Dispatcher (
 \r
     return Tcp4Route (Tcb, (TCP4_ROUTE_INFO *) Data);\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
 \r
   return EFI_SUCCESS;\r
index 3ae8a2091cb9f4cff48941d411856002719f59fc..1eefb38f915309e29b5ca723f56a0be26e9c425b 100644 (file)
@@ -586,6 +586,28 @@ Tcp4ServiceBindingCreateChild (
                   );\r
   if (EFI_ERROR (Status)) {\r
     SockDestroyChild (Sock);\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
 \r
 ON_EXIT:\r
@@ -652,6 +674,16 @@ Tcp4ServiceBindingDestroyChild (
 \r
   Status = SockDestroyChild (Sock);\r
 \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
   //\r
   // Close the Ip4 protocol.\r
   //\r
index 44f3623695d5ffc7d5910a002848d825dbe097ed..86c88a950686a199afeaae12a6b0708b113a423e 100644 (file)
@@ -2,7 +2,7 @@
 # Component name for module Tcp4\r
 #\r
 # FIX ME!\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
 #\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
@@ -68,6 +68,7 @@
   DebugLib\r
   NetLib\r
   IpIoLib\r
   DebugLib\r
   NetLib\r
   IpIoLib\r
+  DevicePathLib\r
 \r
 [Protocols]\r
   gEfiIp4ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
 \r
 [Protocols]\r
   gEfiIp4ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
index 6441c13c643e792cd2374375a09ca0225126440c..be99f3bf470060c5af7323694f3e2345c05de510 100644 (file)
@@ -350,4 +350,9 @@ TcpClearVariableData (
   IN TCP4_SERVICE_DATA  *Tcp4Service
   );
 
   IN TCP4_SERVICE_DATA  *Tcp4Service
   );
 
+EFI_STATUS
+TcpInstallDevicePath (
+  IN SOCKET  *Sock
+  );
+
 #endif
 #endif
index fdd64ef9f46c0d23f353e8ec659129c8222496b5..2eaf0ccec51ee8886893a931aa2102b63d59df8d 100644 (file)
@@ -23,6 +23,8 @@ Abstract:
 \r
 #include "Tcp4Main.h"\r
 \r
 \r
 #include "Tcp4Main.h"\r
 \r
+#include <Library/DevicePathLib.h>\r
+\r
 NET_LIST_ENTRY  mTcpRunQue = {\r
   &mTcpRunQue,\r
   &mTcpRunQue\r
 NET_LIST_ENTRY  mTcpRunQue = {\r
   &mTcpRunQue,\r
   &mTcpRunQue\r
@@ -423,6 +425,7 @@ TcpCloneTcb (
   )\r
 {\r
   TCP_CB               *Clone;\r
   )\r
 {\r
   TCP_CB               *Clone;\r
+  TCP4_SERVICE_DATA  *TcpService;\r
 \r
   Clone = NetAllocatePool (sizeof (TCP_CB));\r
 \r
 \r
   Clone = NetAllocatePool (sizeof (TCP_CB));\r
 \r
@@ -451,6 +454,19 @@ TcpCloneTcb (
 \r
   ((TCP4_PROTO_DATA *) (Clone->Sk->ProtoReserved))->TcpPcb = Clone;\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
   return Clone;\r
 }\r
 \r
@@ -530,6 +546,15 @@ TcpSetState (
   case TCP_ESTABLISHED:\r
 \r
     SockConnEstablished (Tcb->Sk);\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
     break;\r
 \r
   case TCP_CLOSED:\r
@@ -1091,3 +1116,65 @@ TcpClearVariableData (
   Tcp4Service->MacString = NULL;\r
 }\r
 \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
index 5cf87c7921d6e32015c009199608ea75a1528fb6..dd4ed1bf3241ad8e5d8d47e68ba30dec93d78224 100644 (file)
@@ -1349,7 +1349,7 @@ Udp4EnqueueDgram (
       //\r
       // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.\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
       if (Wrap == NULL) {\r
         continue;\r
       }\r