]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
Add comments for functions.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Misc.c
index 12f5e4354e8cef2ad1d197bfb80b2f0b996d0a93..1c269929e34d5fa376bacd3c0397b2b0a5dc5ff1 100644 (file)
@@ -1,23 +1,15 @@
 /** @file\r
+  Misc support routines for tcp.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation\r
+Copyright (c) 2005 - 2006, Intel Corporation<BR>\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
 which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
+http://opensource.org/licenses/bsd-license.php<BR>\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  Tcp4Misc.c\r
-\r
-Abstract:\r
-\r
-  Misc support routines for tcp.\r
-\r
-\r
 **/\r
 \r
 \r
@@ -57,8 +49,6 @@ CHAR16   *mTcpStateName[] = {
 \r
   @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 TcpInitTcbLocal (\r
@@ -85,7 +75,7 @@ TcpInitTcbLocal (
   Tcb->RcvWnd = GET_RCV_BUFFSIZE (Tcb->Sk);\r
 \r
   //\r
-  // Fisrt window size is never scaled\r
+  // First window size is never scaled\r
   //\r
   Tcb->RcvWndScale = 0;\r
 }\r
@@ -99,8 +89,6 @@ TcpInitTcbLocal (
                                 intial info.\r
   @param  Opt                   Pointer to the options announced by the peer.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 TcpInitTcbPeer (\r
@@ -183,7 +171,8 @@ TcpInitTcbPeer (
   @param  Local                 Pointer to the local (IP, Port).\r
   @param  Remote                Pointer to the remote (IP, Port).\r
 \r
-  @return Pointer to the TCP_CB with the least number of wildcard, if NULL no match is found.\r
+  @return  Pointer to the TCP_CB with the least number of wildcard, \r
+           if NULL no match is found.\r
 \r
 **/\r
 TCP_CB *\r
@@ -206,8 +195,7 @@ TcpLocateListenTcb (
 \r
     if ((Local->Port != Node->LocalEnd.Port) ||\r
         !TCP_PEER_MATCH (Remote, &Node->RemoteEnd) ||\r
-        !TCP_PEER_MATCH (Local, &Node->LocalEnd)\r
-          ) {\r
+        !TCP_PEER_MATCH (Local, &Node->LocalEnd)) {\r
 \r
       continue;\r
     }\r
@@ -248,7 +236,7 @@ TcpLocateListenTcb (
   @param  Addr                  Pointer to the IP address needs to match.\r
   @param  Port                  The port number needs to match.\r
 \r
-  @return The Tcb which matches the <Addr Port> paire exists or not.\r
+  @return  The Tcb which matches the <Addr Port> paire exists or not.\r
 \r
 **/\r
 BOOLEAN\r
@@ -299,7 +287,7 @@ TcpFindTcbByPeer (
   @param  Syn                   Whether to search the listen sockets, if TRUE, the\r
                                 listen sockets are searched.\r
 \r
-  @return Pointer to the related TCP_CB, if NULL no match is found.\r
+  @return  Pointer to the related TCP_CB, if NULL no match is found.\r
 \r
 **/\r
 TCP_CB *\r
@@ -369,13 +357,11 @@ TcpInsertTcb (
   TCP4_PROTO_DATA  *TcpProto;\r
 \r
   ASSERT (\r
-    Tcb &&\r
-    (\r
-    (Tcb->State == TCP_LISTEN) ||\r
-    (Tcb->State == TCP_SYN_SENT) ||\r
-    (Tcb->State == TCP_SYN_RCVD) ||\r
-    (Tcb->State == TCP_CLOSED)\r
-    )\r
+    (Tcb != NULL) &&\r
+    ((Tcb->State == TCP_LISTEN) ||\r
+     (Tcb->State == TCP_SYN_SENT) ||\r
+     (Tcb->State == TCP_SYN_RCVD) ||\r
+     (Tcb->State == TCP_CLOSED))\r
     );\r
 \r
   if (Tcb->LocalEnd.Port == 0) {\r
@@ -411,11 +397,11 @@ TcpInsertTcb (
 \r
 \r
 /**\r
-  Clone a TCP_CB from Tcb.\r
+  Clone a TCB_CB from Tcb.\r
 \r
   @param  Tcb                   Pointer to the TCP_CB to be cloned.\r
 \r
-  @return Pointer to the new cloned TCP_CB, if NULL error condition occurred.\r
+  @return  Pointer to the new cloned TCP_CB, if NULL error condition occurred.\r
 \r
 **/\r
 TCP_CB *\r
@@ -459,9 +445,7 @@ TcpCloneTcb (
 /**\r
   Compute an ISS to be used by a new connection.\r
 \r
-  None\r
-\r
-  @return The result ISS.\r
+  @return  The result ISS.\r
 \r
 **/\r
 TCP_SEQNO\r
@@ -477,9 +461,9 @@ TcpGetIss (
 /**\r
   Get the local mss.\r
 \r
-  None\r
+  @param  Sock        Pointer to the socket to get mss\r
 \r
-  @return The mss size.\r
+  @return  The mss size.\r
 \r
 **/\r
 UINT16\r
@@ -491,11 +475,11 @@ TcpGetRcvMss (
   TCP4_PROTO_DATA         *TcpProto;\r
   EFI_IP4_PROTOCOL        *Ip;\r
 \r
-  ASSERT (Sock);\r
+  ASSERT (Sock != NULL);\r
 \r
   TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
   Ip       = TcpProto->TcpService->IpIo->Ip;\r
-  ASSERT (Ip);\r
+  ASSERT (Ip != NULL);\r
 \r
   Ip->GetModeData (Ip, NULL, NULL, &SnpMode);\r
 \r
@@ -509,13 +493,11 @@ TcpGetRcvMss (
   @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
   @param  State                 The state to be set.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 TcpSetState (\r
-  IN TCP_CB *Tcb,\r
-  IN UINT8  State\r
+  IN TCP_CB      *Tcb,\r
+  IN TCP_STATES  State\r
   )\r
 {\r
   DEBUG (\r
@@ -526,7 +508,7 @@ TcpSetState (
     mTcpStateName[State])\r
     );\r
 \r
-  Tcb->State = State;\r
+  Tcb->State = (TCP_STATES)State;\r
 \r
   switch (State) {\r
   case TCP_ESTABLISHED:\r
@@ -547,6 +529,8 @@ TcpSetState (
 \r
     SockConnClosed (Tcb->Sk);\r
 \r
+    break;\r
+  case default:\r
     break;\r
   }\r
 }\r
@@ -560,7 +544,7 @@ TcpSetState (
   @param  HeadSum               The checksum value of the fixed part of pseudo\r
                                 header.\r
 \r
-  @return The checksum value.\r
+  @return  The checksum value.\r
 \r
 **/\r
 UINT16\r
@@ -574,15 +558,14 @@ TcpChecksum (
   Checksum  = NetbufChecksum (Nbuf);\r
   Checksum  = NetAddChecksum (Checksum, HeadSum);\r
 \r
-  Checksum = NetAddChecksum (\r
-              Checksum,\r
-              HTONS ((UINT16) Nbuf->TotalSize)\r
-              );\r
+  Checksum  = NetAddChecksum (\r
+                Checksum,\r
+                HTONS ((UINT16) Nbuf->TotalSize)\r
+                );\r
 \r
   return (UINT16) ~Checksum;\r
 }\r
 \r
-\r
 /**\r
   Translate the information from the head of the received TCP\r
   segment Nbuf contains and fill it into a TCP_SEG structure.\r
@@ -590,7 +573,7 @@ TcpChecksum (
   @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
   @param  Nbuf                  Pointer to the buffer contains the TCP segment.\r
 \r
-  @return Pointer to the TCP_SEG that contains the translated TCP head information.\r
+  @return  Pointer to the TCP_SEG that contains the translated TCP head information.\r
 \r
 **/\r
 TCP_SEG *\r
@@ -639,8 +622,6 @@ TcpFormatNetbuf (
   @param  Tcb                   Pointer to the TCP_CB of the connection to be\r
                                 reset.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 TcpResetConnection (\r
@@ -685,13 +666,11 @@ TcpResetConnection (
 \r
 \r
 /**\r
-  Initialize an active connection,\r
+  Initialize an active connection.\r
 \r
   @param  Tcb                   Pointer to the TCP_CB that wants to initiate a\r
                                 connection.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 TcpOnAppConnect (\r
@@ -712,17 +691,15 @@ TcpOnAppConnect (
 \r
   @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpOnAppClose (\r
   IN TCP_CB *Tcb\r
   )\r
 {\r
-  ASSERT (Tcb);\r
+  ASSERT (Tcb != NULL);\r
 \r
-  if (!IsListEmpty (&Tcb->RcvQue) || GET_RCV_DATASIZE (Tcb->Sk)) {\r
+  if (!IsListEmpty (&Tcb->RcvQue) || GET_RCV_DATASIZE (Tcb->Sk) != 0) {\r
 \r
     DEBUG ((EFI_D_WARN, "TcpOnAppClose: connection reset "\r
       "because data is lost for TCB %p\n", Tcb));\r
@@ -747,6 +724,8 @@ TcpOnAppClose (
   case TCP_CLOSE_WAIT:\r
     TcpSetState (Tcb, TCP_LAST_ACK);\r
     break;\r
+  case default:\r
+    break;\r
   }\r
 \r
   TcpToSendData (Tcb, 1);\r
@@ -754,8 +733,7 @@ TcpOnAppClose (
 \r
 \r
 /**\r
-  Check whether the application's newly delivered data\r
-  can be sent out.\r
+  Check whether the application's newly delivered data can be sent out.\r
 \r
   @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
 \r
@@ -798,6 +776,8 @@ TcpOnAppSend (
   case TCP_TIME_WAIT:\r
     return -1;\r
     break;\r
+  case default:\r
+    break;\r
   }\r
 \r
   return 0;\r
@@ -810,7 +790,6 @@ TcpOnAppSend (
 \r
   @param  Tcb                   Pointer to the TCP_CB of this TCP instance.\r
 \r
-\r
 **/\r
 INTN\r
 TcpOnAppConsume (\r
@@ -840,13 +819,13 @@ TcpOnAppConsume (
       if (TcpOld < Tcb->RcvMss) {\r
 \r
         DEBUG ((EFI_D_INFO, "TcpOnAppConsume: send a window"\r
-          " update for a window closed Tcb(%p)\n", Tcb));\r
+          " update for a window closed Tcb %p\n", Tcb));\r
 \r
         TcpSendAck (Tcb);\r
       } else if (Tcb->DelayedAck == 0) {\r
 \r
         DEBUG ((EFI_D_INFO, "TcpOnAppConsume: scheduled a delayed"\r
-          " ACK to update window for Tcb(%p)\n", Tcb));\r
+          " ACK to update window for Tcb %p\n", Tcb));\r
 \r
         Tcb->DelayedAck = 1;\r
       }\r
@@ -877,8 +856,6 @@ TcpOnAppConsume (
 \r
   @param  Tcb                   Pointer to the TCP_CB of the TCP instance.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 TcpOnAppAbort (\r
@@ -905,7 +882,7 @@ TcpOnAppAbort (
 /**\r
   Set the Tdp4 variable data.\r
 \r
-  @param  Tcp4Service           Tcp4 service data.\r
+  @param  Tcp4Service           Pointer to Tcp4 service data.\r
 \r
   @retval EFI_OUT_OF_RESOURCES  There are not enough resources to set the variable.\r
   @retval other                 Set variable failed.\r
@@ -1078,9 +1055,7 @@ ON_ERROR:
 /**\r
   Clear the variable and free the resource.\r
 \r
-  @param  Tcp4Service           Tcp4 service data.\r
-\r
-  @return None.\r
+  @param  Tcp4Service           Pointer to Tcp4 service data.\r
 \r
 **/\r
 VOID\r
@@ -1102,26 +1077,19 @@ TcpClearVariableData (
   Tcp4Service->MacString = NULL;\r
 }\r
 \r
-EFI_STATUS\r
-TcpInstallDevicePath (\r
-  IN SOCKET *Sock\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\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
+  @param  Sock             Pointer to the socket representing the TCP instance.\r
 \r
-Returns:\r
+  @retval  EFI_SUCCESS     The device path protocol is installed.\r
+  @retval  other           Failed to install the device path protocol.\r
 \r
-  EFI_SUCCESS - The device path protocol is installed.\r
-  other       - Failed to install the device path protocol.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+TcpInstallDevicePath (\r
+  IN SOCKET *Sock\r
+  )\r
 {\r
   TCP4_PROTO_DATA    *TcpProto;\r
   TCP4_SERVICE_DATA  *TcpService;\r
@@ -1145,9 +1113,9 @@ Returns:
     );\r
 \r
   Sock->DevicePath = AppendDevicePathNode (\r
-                     Sock->ParentDevicePath,\r
-                     (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode\r
-                     );\r
+                       Sock->ParentDevicePath,\r
+                       (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode\r
+                       );\r
   if (Sock->DevicePath == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r