]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeNetLib/NetBuffer.c
Code clean up in NetLib:
[mirror_edk2.git] / MdeModulePkg / Library / DxeNetLib / NetBuffer.c
index 42e308a5a32ae9175a5d02d926585ca2290ed9d5..eadffbb45d6ae88c0e3d1a4567bb63d54ead4bdd 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
   Network library functions providing net buffer operation support.\r
-  \r
+\r
 Copyright (c) 2005 - 2009, 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
@@ -22,16 +22,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 \r
 /**\r
-  Allocate and build up the sketch for a NET_BUF. \r
-   \r
-  The net buffer allocated has the BlockOpNum's NET_BLOCK_OP, and its associated \r
+  Allocate and build up the sketch for a NET_BUF.\r
+\r
+  The net buffer allocated has the BlockOpNum's NET_BLOCK_OP, and its associated\r
   NET_VECTOR has the BlockNum's NET_BLOCK. But all the NET_BLOCK_OP and\r
   NET_BLOCK remain un-initialized.\r
 \r
   @param[in]  BlockNum       The number of NET_BLOCK in the vector of net buffer\r
   @param[in]  BlockOpNum     The number of NET_BLOCK_OP in the net buffer\r
 \r
-  @return                    Pointer to the allocated NET_BUF, or NULL if the \r
+  @return                    Pointer to the allocated NET_BUF, or NULL if the\r
                              allocation failed due to resource limit.\r
 \r
 **/\r
@@ -88,7 +88,7 @@ FreeNbuf:
 \r
   @param[in]  Len              The length of the block.\r
 \r
-  @return                      Pointer to the allocated NET_BUF, or NULL if the \r
+  @return                      Pointer to the allocated NET_BUF, or NULL if the\r
                                allocation failed due to resource limit.\r
 \r
 **/\r
@@ -137,11 +137,11 @@ FreeNBuf:
 }\r
 \r
 /**\r
-  Free the net vector. \r
-   \r
-  Decrease the reference count of the net vector by one. The real resource free \r
-  operation isn't performed until the reference count of the net vector is \r
-  decreased to 0. \r
+  Free the net vector.\r
+\r
+  Decrease the reference count of the net vector by one. The real resource free\r
+  operation isn't performed until the reference count of the net vector is\r
+  decreased to 0.\r
 \r
   @param[in]  Vector                Pointer to the NET_VECTOR to be freed.\r
 \r
@@ -190,13 +190,13 @@ NetbufFreeVector (
 \r
 /**\r
   Free the net buffer and its associated NET_VECTOR.\r
\r
+\r
   Decrease the reference count of the net buffer by one. Free the associated net\r
-  vector and itself if the reference count of the net buffer is decreased to 0. \r
-  The net vector free operation just decrease the reference count of the net \r
+  vector and itself if the reference count of the net buffer is decreased to 0.\r
+  The net vector free operation just decrease the reference count of the net\r
   vector by one and do the real resource free operation when the reference count\r
-  of the net vector is 0. \r
\r
+  of the net vector is 0.\r
+\r
   @param[in]  Nbuf                  Pointer to the NET_BUF to be freed.\r
 \r
 **/\r
@@ -224,10 +224,10 @@ NetbufFree (
 \r
 \r
 /**\r
-  Create a copy of the net buffer that shares the associated net vector. \r
-   \r
-  The reference count of the newly created net buffer is set to 1. The reference \r
-  count of the associated net vector is increased by one. \r
+  Create a copy of the net buffer that shares the associated net vector.\r
+\r
+  The reference count of the newly created net buffer is set to 1. The reference\r
+  count of the associated net vector is increased by one.\r
 \r
   @param[in]  Nbuf              Pointer to the net buffer to be cloned.\r
 \r
@@ -274,12 +274,12 @@ NetbufClone (
 /**\r
   Create a duplicated copy of the net buffer with data copied and HeadSpace\r
   bytes of head space reserved.\r
-   \r
+\r
   The duplicated net buffer will allocate its own memory to hold the data of the\r
   source net buffer.\r
-   \r
+\r
   @param[in]       Nbuf         Pointer to the net buffer to be duplicated from.\r
-  @param[in, out]  Duplicate    Pointer to the net buffer to duplicate to, if \r
+  @param[in, out]  Duplicate    Pointer to the net buffer to duplicate to, if\r
                                 NULL a new net buffer is allocated.\r
   @param[in]      HeadSpace     Length of the head space to reserve.\r
 \r
@@ -352,16 +352,16 @@ NetbufFreeList (
 \r
 \r
 /**\r
-  Get the index of NET_BLOCK_OP that contains the byte at Offset in the net \r
-  buffer. \r
-  \r
-  This can be used to, for example, retrieve the IP header in the packet. It \r
-  also can be used to get the fragment that contains the byte which is used \r
-  mainly by the library implementation itself. \r
+  Get the index of NET_BLOCK_OP that contains the byte at Offset in the net\r
+  buffer.\r
+\r
+  This can be used to, for example, retrieve the IP header in the packet. It\r
+  also can be used to get the fragment that contains the byte which is used\r
+  mainly by the library implementation itself.\r
 \r
   @param[in]   Nbuf      Pointer to the net buffer.\r
   @param[in]   Offset    The offset of the byte.\r
-  @param[out]  Index     Index of the NET_BLOCK_OP that contains the byte at \r
+  @param[out]  Index     Index of the NET_BLOCK_OP that contains the byte at\r
                          Offset.\r
 \r
   @return       Pointer to the Offset'th byte of data in the net buffer, or NULL\r
@@ -409,12 +409,12 @@ NetbufGetByte (
 \r
 \r
 /**\r
-  Set the NET_BLOCK and corresponding NET_BLOCK_OP in the net buffer and \r
+  Set the NET_BLOCK and corresponding NET_BLOCK_OP in the net buffer and\r
   corresponding net vector according to the bulk pointer and bulk length.\r
-   \r
-  All the pointers in the Index'th NET_BLOCK and NET_BLOCK_OP are set to the \r
-  bulk's head and tail respectively. So, this function alone can't be used by \r
-  NetbufAlloc. \r
+\r
+  All the pointers in the Index'th NET_BLOCK and NET_BLOCK_OP are set to the\r
+  bulk's head and tail respectively. So, this function alone can't be used by\r
+  NetbufAlloc.\r
 \r
   @param[in, out]  Nbuf       Pointer to the net buffer.\r
   @param[in]       Bulk       Pointer to the data.\r
@@ -453,15 +453,15 @@ NetbufSetBlock (
 \r
 /**\r
   Set the NET_BLOCK_OP in the net buffer. The corresponding NET_BLOCK\r
-  structure is left untouched. \r
-   \r
-  Some times, there is no 1:1 relationship between NET_BLOCK and NET_BLOCK_OP. \r
-  For example, that in NetbufGetFragment. \r
+  structure is left untouched.\r
+\r
+  Some times, there is no 1:1 relationship between NET_BLOCK and NET_BLOCK_OP.\r
+  For example, that in NetbufGetFragment.\r
 \r
   @param[in, out]  Nbuf       Pointer to the net buffer.\r
   @param[in]       Bulk       Pointer to the data.\r
   @param[in]       Len        Length of the bulk data.\r
-  @param[in]       Index      The data block index in the net buffer the bulk \r
+  @param[in]       Index      The data block index in the net buffer the bulk\r
                               data should belong to.\r
 \r
 **/\r
@@ -488,10 +488,10 @@ NetbufSetBlockOp (
 \r
 \r
 /**\r
-  Helper function for NetbufGetFragment. NetbufGetFragment may allocate the \r
-  first block to reserve HeadSpace bytes header space. So it needs to create a \r
-  new net vector for the first block and can avoid copy for the remaining data \r
-  by sharing the old net vector. \r
+  Helper function for NetbufGetFragment. NetbufGetFragment may allocate the\r
+  first block to reserve HeadSpace bytes header space. So it needs to create a\r
+  new net vector for the first block and can avoid copy for the remaining data\r
+  by sharing the old net vector.\r
 \r
   @param[in]  Arg                   Point to the old NET_VECTOR.\r
 \r
@@ -510,19 +510,19 @@ NetbufGetFragmentFree (
 \r
 \r
 /**\r
-  Create a NET_BUF structure which contains Len byte data of Nbuf starting from \r
-  Offset. \r
-   \r
-  A new NET_BUF structure will be created but the associated data in NET_VECTOR \r
-  is shared. This function exists to do IP packet fragmentation. \r
+  Create a NET_BUF structure which contains Len byte data of Nbuf starting from\r
+  Offset.\r
+\r
+  A new NET_BUF structure will be created but the associated data in NET_VECTOR\r
+  is shared. This function exists to do IP packet fragmentation.\r
 \r
   @param[in]  Nbuf         Pointer to the net buffer to be extracted.\r
-  @param[in]  Offset       Starting point of the data to be included in the new \r
+  @param[in]  Offset       Starting point of the data to be included in the new\r
                            net buffer.\r
-  @param[in]  Len          Bytes of data to be included in the new net buffer. \r
-  @param[in]  HeadSpace    Bytes of head space to reserve for protocol header. \r
+  @param[in]  Len          Bytes of data to be included in the new net buffer.\r
+  @param[in]  HeadSpace    Bytes of head space to reserve for protocol header.\r
 \r
-  @return                  Pointer to the cloned net buffer, or NULL if the \r
+  @return                  Pointer to the cloned net buffer, or NULL if the\r
                            allocation failed due to resource limit.\r
 \r
 **/\r
@@ -694,8 +694,8 @@ FreeChild:
 \r
 \r
 /**\r
-  Build a NET_BUF from external blocks. \r
-   \r
+  Build a NET_BUF from external blocks.\r
+\r
   A new NET_BUF structure will be created from external blocks. Additional block\r
   of memory will be allocated to hold reserved HeadSpace bytes of header room\r
   and existing HeadLen bytes of header but the external blocks are shared by the\r
@@ -710,7 +710,7 @@ FreeChild:
   @param[in]  Arg                   The argument passed to ExtFree when ExtFree is\r
                                     called.\r
 \r
-  @return                  Pointer to the net buffer built from the data blocks, \r
+  @return                  Pointer to the net buffer built from the data blocks,\r
                            or NULL if the allocation failed due to resource\r
                            limit.\r
 \r
@@ -878,13 +878,13 @@ FreeFirstBlock:
 \r
 /**\r
   Build a fragment table to contain the fragments in the net buffer. This is the\r
-  opposite operation of the NetbufFromExt. \r
-   \r
+  opposite operation of the NetbufFromExt.\r
+\r
   @param[in]       Nbuf                  Point to the net buffer.\r
   @param[in, out]  ExtFragment           Pointer to the data block.\r
   @param[in, out]  ExtNum                The number of the data blocks.\r
 \r
-  @retval EFI_BUFFER_TOO_SMALL  The number of non-empty block is bigger than \r
+  @retval EFI_BUFFER_TOO_SMALL  The number of non-empty block is bigger than\r
                                 ExtNum.\r
   @retval EFI_SUCCESS           Fragment table is built successfully.\r
 \r
@@ -923,10 +923,10 @@ NetbufBuildExt (
 \r
 /**\r
   Build a net buffer from a list of net buffers.\r
-   \r
-  All the fragments will be collected from the list of NEW_BUF and then a new \r
-  net buffer will be created through NetbufFromExt. \r
-   \r
+\r
+  All the fragments will be collected from the list of NEW_BUF and then a new\r
+  net buffer will be created through NetbufFromExt.\r
+\r
   @param[in]   BufList    A List of the net buffer.\r
   @param[in]   HeadSpace  The head space to be reserved.\r
   @param[in]   HeaderLen  The length of the protocol header, This function\r
@@ -934,7 +934,7 @@ NetbufBuildExt (
   @param[in]   ExtFree    Pointer to the caller provided free function.\r
   @param[in]   Arg        The argument passed to ExtFree when ExtFree is called.\r
 \r
-  @return                 Pointer to the net buffer built from the list of net \r
+  @return                 Pointer to the net buffer built from the list of net\r
                           buffers.\r
 \r
 **/\r
@@ -1000,10 +1000,10 @@ NetbufFromBufList (
 /**\r
   Reserve some space in the header room of the net buffer.\r
 \r
-  Upon allocation, all the space are in the tail room of the buffer. Call this \r
+  Upon allocation, all the space are in the tail room of the buffer. Call this\r
   function to move some space to the header room. This function is quite limited\r
-  in that it can only reserve space from the first block of an empty NET_BUF not \r
-  built from the external. But it should be enough for the network stack. \r
+  in that it can only reserve space from the first block of an empty NET_BUF not\r
+  built from the external. But it should be enough for the network stack.\r
 \r
   @param[in, out]  Nbuf     Pointer to the net buffer.\r
   @param[in]       Len      The length of buffer to be reserved from the header.\r
@@ -1030,14 +1030,14 @@ NetbufReserve (
 \r
 \r
 /**\r
-  Allocate Len bytes of space from the header or tail of the buffer. \r
+  Allocate Len bytes of space from the header or tail of the buffer.\r
 \r
   @param[in, out]  Nbuf       Pointer to the net buffer.\r
   @param[in]       Len        The length of the buffer to be allocated.\r
-  @param[in]       FromHead   The flag to indicate whether reserve the data \r
+  @param[in]       FromHead   The flag to indicate whether reserve the data\r
                               from head (TRUE) or tail (FALSE).\r
 \r
-  @return                     Pointer to the first byte of the allocated buffer, \r
+  @return                     Pointer to the first byte of the allocated buffer,\r
                               or NULL if there is no sufficient space.\r
 \r
 **/\r
@@ -1126,7 +1126,7 @@ NetbufAllocSpace (
 \r
   @param[in, out]  BlockOp      Pointer to the NET_BLOCK.\r
   @param[in]       Len          The length of the data to be trimmed.\r
-  @param[in]       FromHead     The flag to indicate whether trim data from head \r
+  @param[in]       FromHead     The flag to indicate whether trim data from head\r
                                 (TRUE) or tail (FALSE).\r
 \r
 **/\r
@@ -1150,14 +1150,14 @@ NetblockTrim (
 \r
 \r
 /**\r
-  Trim Len bytes from the header or tail of the net buffer. \r
+  Trim Len bytes from the header or tail of the net buffer.\r
 \r
   @param[in, out]  Nbuf         Pointer to the net buffer.\r
   @param[in]       Len          The length of the data to be trimmed.\r
-  @param[in]      FromHead      The flag to indicate whether trim data from head \r
+  @param[in]      FromHead      The flag to indicate whether trim data from head\r
                                 (TRUE) or tail (FALSE).\r
 \r
-  @return    Length of the actually trimmed data, which is possible to be less \r
+  @return    Length of the actually trimmed data, which is possible to be less\r
              than Len because the TotalSize of Nbuf is less than Len.\r
 \r
 **/\r
@@ -1216,11 +1216,11 @@ NetbufTrim (
 \r
 \r
 /**\r
-  Copy Len bytes of data from the specific offset of the net buffer to the \r
+  Copy Len bytes of data from the specific offset of the net buffer to the\r
   destination memory.\r
\r
+\r
   The Len bytes of data may cross the several fragments of the net buffer.\r
\r
+\r
   @param[in]   Nbuf         Pointer to the net buffer.\r
   @param[in]   Offset       The sequence number of the first byte to copy.\r
   @param[in]   Len          Length of the data to copy.\r
@@ -1368,10 +1368,10 @@ NetbufQueAlloc (
 \r
 \r
 /**\r
-  Free a net buffer queue. \r
-   \r
+  Free a net buffer queue.\r
+\r
   Decrease the reference count of the net buffer queue by one. The real resource\r
-  free operation isn't performed until the reference count of the net buffer \r
+  free operation isn't performed until the reference count of the net buffer\r
   queue is decreased to 0.\r
 \r
   @param[in]  NbufQue               Pointer to the net buffer queue to be freed.\r
@@ -1424,7 +1424,7 @@ NetbufQueAppend (
 \r
   @param[in, out]  NbufQue               Pointer to the net buffer queue.\r
 \r
-  @return           Pointer to the net buffer removed from the specific queue, \r
+  @return           Pointer to the net buffer removed from the specific queue,\r
                     or NULL if there is no net buffer in the specific queue.\r
 \r
 **/\r
@@ -1455,16 +1455,16 @@ NetbufQueRemove (
 /**\r
   Copy Len bytes of data from the net buffer queue at the specific offset to the\r
   destination memory.\r
\r
+\r
   The copying operation is the same as NetbufCopy but applies to the net buffer\r
   queue instead of the net buffer.\r
\r
+\r
   @param[in]   NbufQue         Pointer to the net buffer queue.\r
   @param[in]   Offset          The sequence number of the first byte to copy.\r
   @param[in]   Len             Length of the data to copy.\r
   @param[out]  Dest            The destination of the data to copy to.\r
 \r
-  @return       The length of the actual copied data, or 0 if the offset \r
+  @return       The length of the actual copied data, or 0 if the offset\r
                 specified exceeds the total size of net buffer queue.\r
 \r
 **/\r
@@ -1557,9 +1557,9 @@ NetbufQueCopy (
 \r
 \r
 /**\r
-  Trim Len bytes of data from the queue header, release any of the net buffer \r
+  Trim Len bytes of data from the queue header, release any of the net buffer\r
   whom is trimmed wholely.\r
-   \r
+\r
   The trimming operation is the same as NetbufTrim but applies to the net buffer\r
   queue instead of the net buffer.\r
 \r
@@ -1756,7 +1756,7 @@ NetbufChecksum (
       // The checksum starts with an odd byte, swap\r
       // the checksum before added to total checksum\r
       //\r
-      BlockSum = (UINT16) NET_SWAP_SHORT (BlockSum);\r
+      BlockSum = SwapBytes16 (BlockSum);\r
     }\r
 \r
     TotalSum = NetAddChecksum (BlockSum, TotalSum);\r
@@ -1768,8 +1768,8 @@ NetbufChecksum (
 \r
 \r
 /**\r
-  Compute the checksum for TCP/UDP pseudo header. \r
-   \r
+  Compute the checksum for TCP/UDP pseudo header.\r
+\r
   Src and Dst are in network byte order, and Len is in host byte order.\r
 \r
   @param[in]   Src                   The source address of the packet.\r
@@ -1805,8 +1805,8 @@ NetPseudoHeadChecksum (
 }\r
 \r
 /**\r
-  Compute the checksum for TCP6/UDP6 pseudo header. \r
-   \r
+  Compute the checksum for TCP6/UDP6 pseudo header.\r
+\r
   Src and Dst are in network byte order, and Len is in host byte order.\r
 \r
   @param[in]   Src                   The source address of the packet.\r
@@ -1836,7 +1836,7 @@ NetIp6PseudoHeadChecksum (
   IP6_COPY_ADDRESS (&Hdr.DstIp, Dst);\r
 \r
   Hdr.NextHeader = NextHeader;\r
-  Hdr.Len        = HTONL (Len); \r
+  Hdr.Len        = HTONL (Len);\r
 \r
   return NetblockChecksum ((UINT8 *) &Hdr, sizeof (Hdr));\r
 }\r