]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c
Fix a missing doxygen parameter entry.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Dispatcher.c
index 536a01a1d5391a59c376c1205e68a8d5206f6a6a..009ae582a505927ba761c6a28cc73b278253f220 100644 (file)
@@ -23,43 +23,33 @@ Abstract:
 #define TCP_COMP_VAL(Min, Max, Default, Val) \\r
   ((((Val) <= (Max)) && ((Val) >= (Min))) ? (Val) : (Default))\r
 \r
-STATIC\r
+/**\r
+  Add or remove a route entry in the IP route table associated with this TCP instance.\r
+\r
+  @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
+  @param  RouteInfo             Pointer to the route info to be processed.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_NOT_STARTED       The driver instance has not been started.\r
+  @retval EFI_NO_MAPPING        When using the default address, configuration(DHCP,\r
+                                BOOTP, RARP, etc.) is not finished yet.\r
+  @retval EFI_OUT_OF_RESOURCES  Could not add the entry to the routing table.\r
+  @retval EFI_NOT_FOUND         This route is not in the routing table\r
+                                (when RouteInfo->DeleteRoute is TRUE).\r
+  @retval EFI_ACCESS_DENIED     The route is already defined in the routing table\r
+                                (when RouteInfo->DeleteRoute is FALSE).\r
+**/\r
 EFI_STATUS\r
 Tcp4Route (\r
   IN TCP_CB           *Tcb,\r
   IN TCP4_ROUTE_INFO  *RouteInfo\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Add or remove a route entry in the IP route table associated\r
-  with this TCP instance.\r
-\r
-Arguments:\r
-\r
-  Tcb       - Pointer to the TCP_CB of this TCP instance.\r
-  RouteInfo - Pointer to the route info to be processed.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS          - The operation completed successfully.\r
-  EFI_NOT_STARTED      - The driver instance has not been started.\r
-  EFI_NO_MAPPING       - When using the default address, configuration(DHCP,\r
-                         BOOTP, RARP, etc.) is not finished yet.\r
-  EFI_OUT_OF_RESOURCES - Could not add the entry to the routing table.\r
-  EFI_NOT_FOUND        - This route is not in the routing table\r
-                         (when RouteInfo->DeleteRoute is TRUE).\r
-  EFI_ACCESS_DENIED    - The route is already defined in the routing table\r
-                         (when RouteInfo->DeleteRoute is FALSE).\r
-\r
---*/\r
 {\r
   EFI_IP4_PROTOCOL  *Ip;\r
 \r
   Ip = Tcb->IpInfo->Ip;\r
 \r
-  ASSERT (Ip);\r
+  ASSERT (Ip != NULL);\r
 \r
   return Ip->Routes (\r
               Ip,\r
@@ -68,7 +58,7 @@ Returns:
               RouteInfo->SubnetMask,\r
               RouteInfo->GatewayAddress\r
               );\r
-\r
+              \r
 }\r
 \r
 \r
@@ -84,7 +74,6 @@ Returns:
                                  instance hasn't been started.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Tcp4GetMode (\r
   IN TCP_CB         *Tcb,\r
@@ -103,11 +92,11 @@ Tcp4GetMode (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  if (Mode->Tcp4State) {\r
+  if (Mode->Tcp4State != NULL) {\r
     *(Mode->Tcp4State) = (EFI_TCP4_CONNECTION_STATE) Tcb->State;\r
   }\r
 \r
-  if (Mode->Tcp4ConfigData) {\r
+  if (Mode->Tcp4ConfigData != NULL) {\r
 \r
     ConfigData                      = Mode->Tcp4ConfigData;\r
     AccessPoint                     = &(ConfigData->AccessPoint);\r
@@ -118,11 +107,11 @@ Tcp4GetMode (
 \r
     AccessPoint->UseDefaultAddress  = Tcb->UseDefaultAddr;\r
 \r
-    NetCopyMem (&AccessPoint->StationAddress, &Tcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
+    CopyMem (&AccessPoint->StationAddress, &Tcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
     AccessPoint->SubnetMask         = Tcb->SubnetMask;\r
     AccessPoint->StationPort        = NTOHS (Tcb->LocalEnd.Port);\r
 \r
-    NetCopyMem (&AccessPoint->RemoteAddress, &Tcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
+    CopyMem (&AccessPoint->RemoteAddress, &Tcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS));\r
     AccessPoint->RemotePort         = NTOHS (Tcb->RemoteEnd.Port);\r
     AccessPoint->ActiveFlag         = (BOOLEAN) (Tcb->State != TCP_LISTEN);\r
 \r
@@ -141,8 +130,7 @@ Tcp4GetMode (
 \r
       Option->EnableNagle         = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_NAGLE));\r
       Option->EnableTimeStamp     = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_TS));\r
-      Option->EnableWindowScaling = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_WS))\r
-;\r
+      Option->EnableWindowScaling = (BOOLEAN) (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_WS));\r
 \r
       Option->EnableSelectiveAck      = FALSE;\r
       Option->EnablePathMtuDiscovery  = FALSE;\r
@@ -150,7 +138,7 @@ Tcp4GetMode (
   }\r
 \r
   Ip = Tcb->IpInfo->Ip;\r
-  ASSERT (Ip);\r
+  ASSERT (Ip != NULL);\r
 \r
   return Ip->GetModeData (Ip, Mode->Ip4ModeData, Mode->MnpConfigData, Mode->SnpModeData);\r
 }\r
@@ -168,7 +156,6 @@ Tcp4GetMode (
   @retval EFI_OUT_OF_RESOURCES   No port can be allocated.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Tcp4Bind (\r
   IN EFI_TCP4_ACCESS_POINT *AP\r
@@ -203,7 +190,7 @@ Tcp4Bind (
       if (mTcp4RandomPort <= TCP4_PORT_KNOWN) {\r
 \r
         if (Cycle) {\r
-          TCP4_DEBUG_ERROR (("Tcp4Bind: no port can be allocated "\r
+          DEBUG ((EFI_D_ERROR, "Tcp4Bind: no port can be allocated "\r
             "for this pcb\n"));\r
 \r
           return EFI_OUT_OF_RESOURCES;\r
@@ -224,14 +211,11 @@ Tcp4Bind (
 \r
 \r
 /**\r
-  Flush the Tcb add its associated protocols..\r
+  Flush the Tcb add its associated protocols.\r
 \r
   @param  Tcb                    Pointer to the TCP_CB to be flushed.\r
 \r
-  @retval EFI_SUCCESS            The operation is completed successfully.\r
-\r
 **/\r
-STATIC\r
 VOID\r
 Tcp4FlushPcb (\r
   IN TCP_CB *Tcb\r
@@ -246,7 +230,17 @@ Tcp4FlushPcb (
   TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
 \r
   if (SOCK_IS_CONFIGURED (Sock)) {\r
-    NetListRemoveEntry (&Tcb->List);\r
+    RemoveEntryList (&Tcb->List);\r
+\r
+    //\r
+    // Uninstall the device path protocl.\r
+    //\r
+    gBS->UninstallProtocolInterface (\r
+           Sock->SockHandle,\r
+           &gEfiDevicePathProtocolGuid,\r
+           Sock->DevicePath\r
+           );\r
+    gBS->FreePool (Sock->DevicePath);\r
 \r
     TcpSetVariableData (TcpProto->TcpService);\r
   }\r
@@ -255,7 +249,15 @@ Tcp4FlushPcb (
   NetbufFreeList (&Tcb->RcvQue);\r
 }\r
 \r
-STATIC\r
+/**\r
+  Attach a Tcb to the socket.\r
+\r
+  @param  Sk                     Pointer to the socket of this TCP instance.\r
+  \r
+  @retval EFI_SUCCESS            The operation is completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed due to resource limit.\r
+\r
+**/\r
 EFI_STATUS\r
 Tcp4AttachPcb (\r
   IN SOCKET  *Sk\r
@@ -265,11 +267,11 @@ Tcp4AttachPcb (
   TCP4_PROTO_DATA   *ProtoData;\r
   IP_IO             *IpIo;\r
 \r
-  Tcb = NetAllocateZeroPool (sizeof (TCP_CB));\r
+  Tcb = AllocateZeroPool (sizeof (TCP_CB));\r
 \r
   if (Tcb == NULL) {\r
 \r
-    TCP4_DEBUG_ERROR (("Tcp4ConfigurePcb: failed to allocate a TCB\n"));\r
+    DEBUG ((EFI_D_ERROR, "Tcp4ConfigurePcb: failed to allocate a TCB\n"));\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -283,13 +285,13 @@ Tcp4AttachPcb (
   Tcb->IpInfo = IpIoAddIp (IpIo);\r
   if (Tcb->IpInfo == NULL) {\r
 \r
-    NetFreePool (Tcb);\r
+    gBS->FreePool (Tcb);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  NetListInit (&Tcb->List);\r
-  NetListInit (&Tcb->SndQue);\r
-  NetListInit (&Tcb->RcvQue);\r
+  InitializeListHead (&Tcb->List);\r
+  InitializeListHead (&Tcb->SndQue);\r
+  InitializeListHead (&Tcb->RcvQue);\r
 \r
   Tcb->State        = TCP_CLOSED;\r
   Tcb->Sk           = Sk;\r
@@ -298,7 +300,12 @@ Tcp4AttachPcb (
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+/**\r
+  Detach the Tcb of the socket.\r
+\r
+  @param  Sk                     Pointer to the socket of this TCP instance.\r
+  \r
+**/\r
 VOID\r
 Tcp4DetachPcb (\r
   IN SOCKET  *Sk\r
@@ -316,7 +323,7 @@ Tcp4DetachPcb (
 \r
   IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);\r
 \r
-  NetFreePool (Tcb);\r
+  gBS->FreePool (Tcb);\r
 \r
   ProtoData->TcpPcb = NULL;\r
 }\r
@@ -326,7 +333,6 @@ Tcp4DetachPcb (
   Configure the Tcb using CfgData.\r
 \r
   @param  Sk                     Pointer to the socket of this TCP instance.\r
-  @param  SkTcb                  Pointer to the TCP_CB of this TCP instance.\r
   @param  CfgData                Pointer to the TCP configuration data.\r
 \r
   @retval EFI_SUCCESS            The operation is completed successfully.\r
@@ -335,7 +341,6 @@ Tcp4DetachPcb (
   @retval EFI_OUT_OF_RESOURCES   Failed due to resource limit.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 Tcp4ConfigurePcb (\r
   IN SOCKET               *Sk,\r
@@ -348,7 +353,7 @@ Tcp4ConfigurePcb (
   TCP4_PROTO_DATA     *TcpProto;\r
   TCP_CB              *Tcb;\r
 \r
-  ASSERT (CfgData && Sk && Sk->SockHandle);\r
+  ASSERT ((CfgData != NULL) && (Sk != NULL) && (Sk->SockHandle != NULL));\r
 \r
   TcpProto = (TCP4_PROTO_DATA *) Sk->ProtoReserved;\r
   Tcb      = TcpProto->TcpPcb;\r
@@ -358,7 +363,7 @@ Tcp4ConfigurePcb (
   //\r
   // Add Ip for send pkt to the peer\r
   //\r
-  CopyMem (&IpCfgData, &mIpIoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
+  CopyMem (&IpCfgData, &mIpIoDefaultIpConfigData, sizeof (IpCfgData));\r
   IpCfgData.DefaultProtocol   = EFI_IP_PROTO_TCP;\r
   IpCfgData.UseDefaultAddress = CfgData->AccessPoint.UseDefaultAddress;\r
   IpCfgData.StationAddress    = CfgData->AccessPoint.StationAddress;\r
@@ -387,7 +392,7 @@ Tcp4ConfigurePcb (
   Status = Tcp4Bind (&(CfgData->AccessPoint));\r
 \r
   if (EFI_ERROR (Status)) {\r
-    TCP4_DEBUG_ERROR (("Tcp4ConfigurePcb: Bind endpoint failed "\r
+    DEBUG ((EFI_D_ERROR, "Tcp4ConfigurePcb: Bind endpoint failed "\r
       "with %r\n", Status));\r
 \r
     goto OnExit;\r
@@ -397,8 +402,8 @@ Tcp4ConfigurePcb (
   // Initalize the operating information in this Tcb\r
   //\r
   ASSERT (Tcb->State == TCP_CLOSED &&\r
-    NetListIsEmpty (&Tcb->SndQue) &&\r
-    NetListIsEmpty (&Tcb->RcvQue));\r
+    IsListEmpty (&Tcb->SndQue) &&\r
+    IsListEmpty (&Tcb->RcvQue));\r
 \r
   TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE);\r
   Tcb->State            = TCP_CLOSED;\r
@@ -428,12 +433,19 @@ Tcp4ConfigurePcb (
   Tcb->TTL            = CfgData->TimeToLive;\r
   Tcb->TOS            = CfgData->TypeOfService;\r
 \r
-  NetCopyMem (&Tcb->LocalEnd.Ip, &CfgData->AccessPoint.StationAddress, sizeof (IP4_ADDR));\r
+  Tcb->UseDefaultAddr = CfgData->AccessPoint.UseDefaultAddress;\r
+\r
+  CopyMem (&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
+    CopyMem (&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
@@ -537,6 +549,15 @@ Tcp4ConfigurePcb (
     }\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
@@ -600,13 +621,13 @@ Tcp4Dispatcher (
     // notify TCP using this message to give it a chance to send out\r
     // window update information\r
     //\r
-    ASSERT (Tcb);\r
+    ASSERT (Tcb != NULL);\r
     TcpOnAppConsume (Tcb);\r
     break;\r
 \r
   case SOCK_SND:\r
 \r
-    ASSERT (Tcb);\r
+    ASSERT (Tcb != NULL);\r
     TcpOnAppSend (Tcb);\r
     break;\r
 \r
@@ -669,7 +690,7 @@ Tcp4Dispatcher (
 \r
   case SOCK_MODE:\r
 \r
-    ASSERT (Data && Tcb);\r
+    ASSERT ((Data != NULL) && (Tcb != NULL));\r
 \r
     return Tcp4GetMode (Tcb, (TCP4_MODE_DATA *) Data);\r
 \r
@@ -677,10 +698,12 @@ Tcp4Dispatcher (
 \r
   case SOCK_ROUTE:\r
 \r
-    ASSERT (Data && Tcb);\r
+    ASSERT ((Data != NULL) && (Tcb != NULL));\r
 \r
     return Tcp4Route (Tcb, (TCP4_ROUTE_INFO *) Data);\r
 \r
+  default:\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
   return EFI_SUCCESS;\r