/** @file\r
-\r
-Copyright (c) 2005 - 2006, Intel Corporation\r
+ Network library.\r
+ \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
\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
- NetBuffer.c\r
-\r
-Abstract:\r
-\r
-\r
-\r
**/\r
\r
-#include <PiDxe.h>\r
+#include <Uefi.h>\r
\r
#include <Library/NetLib.h>\r
#include <Library/BaseLib.h>\r
has the BlockOpNum's NET_BLOCK_OP, and its associated NET_VECTOR has the\r
BlockNum's NET_BLOCK.\r
\r
- @param BlockNum The number of NET_BLOCK in the Vector of net buffer\r
- @param BlockOpNum The number of NET_BLOCK_OP in the net buffer\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
- @retval * Pointer to the allocated NET_BUF. If NULL the\r
+ @return Pointer to the allocated NET_BUF. If NULL, the\r
allocation failed due to resource limit.\r
\r
**/\r
Allocate a single block NET_BUF. Upon allocation, all the\r
free space is in the tail room.\r
\r
- @param Len The length of the block.\r
+ @param[in] Len The length of the block.\r
\r
- @retval * Pointer to the allocated NET_BUF. If NULL the\r
+ @return Pointer to the allocated NET_BUF. If NULL the\r
allocation failed due to resource limit.\r
\r
**/\r
\r
\r
/**\r
- Free the vector\r
-\r
- @param Vector Pointer to the NET_VECTOR to be freed.\r
+ Free the vector.\r
\r
- @return None.\r
+ @param[in] Vector Pointer to the NET_VECTOR to be freed.\r
\r
**/\r
VOID\r
/**\r
Free the buffer and its associated NET_VECTOR.\r
\r
- @param Nbuf Pointer to the NET_BUF to be freed.\r
-\r
- @return None.\r
+ @param[in] Nbuf Pointer to the NET_BUF to be freed.\r
\r
**/\r
VOID\r
/**\r
Create a copy of NET_BUF that share the associated NET_DATA.\r
\r
- @param Nbuf Pointer to the net buffer to be cloned.\r
+ @param[in] Nbuf Pointer to the net buffer to be cloned.\r
\r
- @retval * Pointer to the cloned net buffer.\r
+ @return Pointer to the cloned net buffer.If NULL, the\r
+ allocation failed due to resource limit.\r
\r
**/\r
NET_BUF *\r
Create a duplicated copy of Nbuf, data is copied. Also leave some\r
head space before the data.\r
\r
- @param Nbuf Pointer to the net buffer to be cloned.\r
- @param Duplicate Pointer to the net buffer to duplicate to, if NULL\r
- a new net buffer is allocated.\r
- @param HeadSpace Length of the head space to reserve\r
+ @param[in] Nbuf Pointer to the net buffer to be cloned.\r
+ @param[in, out] Duplicate Pointer to the net buffer to duplicate to, if NULL\r
+ a new net buffer is allocated.\r
+ @param[in] HeadSpace Length of the head space to reserve.\r
\r
- @retval * Pointer to the duplicated net buffer.\r
+ @return Pointer to the duplicated net buffer.If NULL, the\r
+ allocation failed due to resource limit.\r
\r
**/\r
NET_BUF *\r
EFIAPI\r
NetbufDuplicate (\r
IN NET_BUF *Nbuf,\r
- IN NET_BUF *Duplicate OPTIONAL,\r
+ IN OUT NET_BUF *Duplicate OPTIONAL,\r
IN UINT32 HeadSpace\r
)\r
{\r
/**\r
Free a list of net buffers.\r
\r
- @param Head Pointer to the head of linked net buffers.\r
-\r
- @return None.\r
+ @param[in, out] Head Pointer to the head of linked net buffers.\r
\r
**/\r
VOID\r
EFIAPI\r
NetbufFreeList (\r
- IN LIST_ENTRY *Head\r
+ IN OUT LIST_ENTRY *Head\r
)\r
{\r
LIST_ENTRY *Entry;\r
returns the fragment that contains the byte which is used mainly by\r
the buffer implementation itself.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Offset The index or offset of the byte\r
- @param Index Index of the fragment that contains the block\r
+ @param[in] Nbuf Pointer to the net buffer.\r
+ @param[in] Offset The index or offset of the byte.\r
+ @param[out] Index Index of the fragment that contains the block.\r
\r
- @retval * Pointer to the nth byte of data in the net buffer.\r
+ @return * Pointer to the nth byte of data in the net buffer.\r
If NULL, there is no such data in the net buffer.\r
\r
**/\r
are set to the bulk's head and tail respectively. So, this\r
function alone can't be used by NetbufAlloc.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Bulk Pointer to the data.\r
- @param Len Length of the bulk data.\r
- @param Index The data block index in the net buffer the bulk\r
- data should belong to.\r
-\r
- @return None.\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
+ data should belong to.\r
+ \r
**/\r
VOID\r
NetbufSetBlock (\r
- IN NET_BUF *Nbuf,\r
+ IN OUT NET_BUF *Nbuf,\r
IN UINT8 *Bulk,\r
IN UINT32 Len,\r
IN UINT32 Index\r
structure is left untouched. Some times, there is no 1:1 relationship\r
between NET_BLOCK and NET_BLOCK_OP. For example, that in NetbufGetFragment.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Bulk Pointer to the data.\r
- @param Len Length of the bulk data.\r
- @param Index The data block index in the net buffer the bulk\r
- data should belong to.\r
-\r
- @return None.\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
+ data should belong to.\r
\r
**/\r
VOID\r
NetbufSetBlockOp (\r
- IN NET_BUF *Nbuf,\r
+ IN OUT NET_BUF *Nbuf,\r
IN UINT8 *Bulk,\r
IN UINT32 Len,\r
IN UINT32 Index\r
need to create a new NET_VECTOR. But, we want to avoid data copy by sharing\r
the old NET_VECTOR.\r
\r
- @param Arg Point to the old NET_VECTOR\r
-\r
- @return NONE\r
+ @param[in] Arg Point to the old NET_VECTOR.\r
\r
**/\r
VOID\r
created but the associated data in NET_VECTOR is shared.\r
This function exists to do IP packet fragmentation.\r
\r
- @param Nbuf Pointer to the net buffer to be cloned.\r
- @param Offset Starting point of the data to be included in new\r
- buffer.\r
- @param Len How many data to include in new data\r
- @param HeadSpace How many bytes of head space to reserve for\r
- protocol header\r
+ @param[in] Nbuf Pointer to the net buffer to be cloned.\r
+ @param[in] Offset Starting point of the data to be included in new\r
+ buffer.\r
+ @param[in] Len How many data to include in new data.\r
+ @param[in] HeadSpace How many bytes of head space to reserve for\r
+ protocol header.\r
\r
- @retval * Pointer to the cloned net buffer.\r
+ @return Pointer to the cloned net buffer.If NULL, the\r
+ allocation failed due to resource limit.\r
\r
**/\r
NET_BUF *\r
/**\r
Build a NET_BUF from external blocks.\r
\r
- @param ExtFragment Pointer to the data block.\r
- @param ExtNum The number of the data block.\r
- @param HeadSpace The head space to be reserved.\r
- @param HeadLen The length of the protocol header, This function\r
- will pull that number of data into a linear block.\r
- @param ExtFree Pointer to the caller provided free function.\r
- @param Arg The argument passed to ExtFree when ExtFree is\r
- called.\r
+ @param[in] ExtFragment Pointer to the data block.\r
+ @param[in] ExtNum The number of the data block.\r
+ @param[in] HeadSpace The head space to be reserved.\r
+ @param[in] HeadLen The length of the protocol header, This function\r
+ will pull that number of data into a linear block.\r
+ @param[in] ExtFree Pointer to the caller provided free function.\r
+ @param[in] Arg The argument passed to ExtFree when ExtFree is\r
+ called.\r
\r
- @retval * Pointer to the net buffer built from the data\r
- blocks.\r
+ @return Pointer to the net buffer built from the data blocks.\r
+ If NULL, the allocation failed due to resource limit.\r
\r
**/\r
NET_BUF *\r
Vector = Nbuf->Vector;\r
Vector->Free = ExtFree;\r
Vector->Arg = Arg;\r
- Vector->Flag = (FirstBlockLen ? NET_VECTOR_OWN_FIRST : 0);\r
+ Vector->Flag = ((FirstBlockLen != 0) ? NET_VECTOR_OWN_FIRST : 0);\r
\r
//\r
// Set the first block up which may contain\r
Vector->Len = TotalLen + HeadSpace;\r
Nbuf->TotalSize = TotalLen;\r
\r
- if (SavedIndex) {\r
+ if (SavedIndex != 0) {\r
ExtFragment[SavedIndex] = SavedFragment;\r
}\r
\r
Build a fragment table to contain the fragments in the\r
buffer. This is the opposite of the NetbufFromExt.\r
\r
- @param Nbuf Point to the net buffer\r
- @param ExtFragment Pointer to the data block.\r
- @param ExtNum The number of the data block.\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 block.\r
\r
- @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than ExtNum\r
+ @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than ExtNum.\r
@retval EFI_SUCCESS Fragment table built.\r
\r
**/\r
EFIAPI\r
NetbufBuildExt (\r
IN NET_BUF *Nbuf,\r
- IN NET_FRAGMENT *ExtFragment,\r
- IN UINT32 *ExtNum\r
+ IN OUT NET_FRAGMENT *ExtFragment,\r
+ IN OUT UINT32 *ExtNum\r
)\r
{\r
UINT32 Index;\r
/**\r
Build a NET_BUF from a list of NET_BUF.\r
\r
- @param BufList A List of NET_BUF.\r
- @param HeadSpace The head space to be reserved.\r
- @param HeaderLen The length of the protocol header, This function\r
- will pull that number of data into a linear block.\r
- @param ExtFree Pointer to the caller provided free function.\r
- @param Arg The argument passed to ExtFree when ExtFree is\r
- called.\r
+ @param[in] BufList A List of NET_BUF.\r
+ @param[in] HeadSpace The head space to be reserved.\r
+ @param[in] HeaderLen The length of the protocol header, This function\r
+ will pull that number of data into a linear block.\r
+ @param[in] ExtFree Pointer to the caller provided free function.\r
+ @param[in] Arg The argument passed to ExtFree when ExtFree is\r
+ called.\r
\r
- @retval * Pointer to the net buffer built from the data\r
+ @return Pointer to the net buffer built from the data\r
blocks.\r
\r
**/\r
of an empty NET_BUF not built from the external. But\r
it should be enough for the network stack.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Len The length of buffer to be reserverd.\r
-\r
- @return None.\r
+ @param[in, out] Nbuf Pointer to the net buffer.\r
+ @param[in] Len The length of buffer to be reserverd.\r
\r
**/\r
VOID\r
EFIAPI\r
NetbufReserve (\r
- IN NET_BUF *Nbuf,\r
+ IN OUT NET_BUF *Nbuf,\r
IN UINT32 Len\r
)\r
{\r
/**\r
Allocate some space from the header or tail of the buffer.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Len The length of the buffer to be allocated.\r
- @param FromHead The flag to indicate whether reserve the data from\r
- head or tail. TRUE for from head, and FALSE for\r
- from tail.\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 from\r
+ head or tail. TRUE for from head, and FALSE for\r
+ from tail.\r
\r
- @retval * Pointer to the first byte of the allocated buffer.\r
+ @return Pointer to the first byte of the allocated buffer.\r
\r
**/\r
UINT8 *\r
EFIAPI\r
NetbufAllocSpace (\r
- IN NET_BUF *Nbuf,\r
+ IN OUT NET_BUF *Nbuf,\r
IN UINT32 Len,\r
IN BOOLEAN FromHead\r
)\r
/**\r
Trim a single NET_BLOCK.\r
\r
- @param BlockOp Pointer to the NET_BLOCK.\r
- @param Len The length of the data to be trimmed.\r
- @param FromHead The flag to indicate whether trim data from head or\r
- tail. TRUE for from head, and FALSE for from tail.\r
-\r
- @return None.\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 or\r
+ tail. TRUE for from head, and FALSE for from tail.\r
\r
**/\r
VOID\r
NetblockTrim (\r
- IN NET_BLOCK_OP *BlockOp,\r
+ IN OUT NET_BLOCK_OP *BlockOp,\r
IN UINT32 Len,\r
IN BOOLEAN FromHead\r
)\r
/**\r
Trim some data from the header or tail of the buffer.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Len The length of the data to be trimmed.\r
- @param FromHead The flag to indicate whether trim data from head or\r
- tail. TRUE for from head, and FALSE for from tail.\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 or\r
+ tail. TRUE for from head, and FALSE for from tail.\r
\r
- @retval UINTN Length of the actually trimmed data.\r
+ @return Length of the actually trimmed data.\r
\r
**/\r
UINT32\r
EFIAPI\r
NetbufTrim (\r
- IN NET_BUF *Nbuf,\r
+ IN OUT NET_BUF *Nbuf,\r
IN UINT32 Len,\r
IN BOOLEAN FromHead\r
)\r
/**\r
Copy the data from the specific offset to the destination.\r
\r
- @param Nbuf Pointer to the net buffer.\r
- @param Offset The sequence number of the first byte to copy.\r
- @param Len Length of the data to copy.\r
- @param Dest The destination of the data to copy to.\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
+ @param[in] Dest The destination of the data to copy to.\r
\r
@retval UINTN The length of the copied data.\r
\r
/**\r
Initiate the net buffer queue.\r
\r
- @param NbufQue Pointer to the net buffer queue to be initiated.\r
-\r
- @return None.\r
+ @param[in, out] NbufQue Pointer to the net buffer queue to be initiated.\r
\r
**/\r
VOID\r
EFIAPI\r
NetbufQueInit (\r
- IN NET_BUF_QUEUE *NbufQue\r
+ IN OUT NET_BUF_QUEUE *NbufQue\r
)\r
{\r
NbufQue->Signature = NET_QUE_SIGNATURE;\r
/**\r
Allocate an initialized net buffer queue.\r
\r
- None.\r
-\r
- @retval * Pointer to the allocated net buffer queue.\r
+ @return Pointer to the allocated net buffer queue.If NULL, the\r
+ allocation failed due to resource limit.\r
\r
**/\r
NET_BUF_QUEUE *\r
/**\r
Free a net buffer queue.\r
\r
- @param NbufQue Poitner to the net buffer queue to be freed.\r
-\r
- @return None.\r
+ @param[in] NbufQue Poitner to the net buffer queue to be freed.\r
\r
**/\r
VOID\r
/**\r
Append a buffer to the end of the queue.\r
\r
- @param NbufQue Pointer to the net buffer queue.\r
- @param Nbuf Pointer to the net buffer to be appended.\r
-\r
- @return None.\r
+ @param[in, out] NbufQue Pointer to the net buffer queue.\r
+ @param[in, out] Nbuf Pointer to the net buffer to be appended.\r
\r
**/\r
VOID\r
EFIAPI\r
NetbufQueAppend (\r
- IN NET_BUF_QUEUE *NbufQue,\r
- IN NET_BUF *Nbuf\r
+ IN OUT NET_BUF_QUEUE *NbufQue,\r
+ IN OUT NET_BUF *Nbuf\r
)\r
{\r
NET_CHECK_SIGNATURE (NbufQue, NET_QUE_SIGNATURE);\r
/**\r
Remove a net buffer from head in the specific queue.\r
\r
- @param NbufQue Pointer to the net buffer queue.\r
+ @param[in, out] NbufQue Pointer to the net buffer queue.\r
\r
- @retval * Pointer to the net buffer removed from the specific\r
+ @return Pointer to the net buffer removed from the specific\r
+ queue. If NULL, there is no net buffer in the specific\r
queue.\r
\r
**/\r
NET_BUF *\r
EFIAPI\r
NetbufQueRemove (\r
- IN NET_BUF_QUEUE *NbufQue\r
+ IN OUT NET_BUF_QUEUE *NbufQue\r
)\r
{\r
NET_BUF *First;\r
/**\r
Copy some data from the buffer queue to the destination.\r
\r
- @param NbufQue Pointer to the net buffer queue.\r
- @param Offset The sequence number of the first byte to copy.\r
- @param Len Length of the data to copy.\r
- @param Dest The destination of the data to copy to.\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
- @retval UINTN The length of the copied data.\r
+ @return The length of the copied data. If 0, then the length is zero or offset \r
+ suppress the total size of net buffer.\r
\r
**/\r
UINT32\r
+EFIAPI\r
NetbufQueCopy (\r
IN NET_BUF_QUEUE *NbufQue,\r
IN UINT32 Offset,\r
IN UINT32 Len,\r
- IN UINT8 *Dest\r
+ OUT UINT8 *Dest\r
)\r
{\r
LIST_ENTRY *Entry;\r
Trim some data from the queue header, release the buffer if\r
whole buffer is trimmed.\r
\r
- @param NbufQue Pointer to the net buffer queue.\r
- @param Len Length of the data to trim.\r
+ @param[in, out] NbufQue Pointer to the net buffer queue.\r
+ @param[in] Len Length of the data to trim.\r
\r
- @retval UINTN The length of the data trimmed.\r
+ @return The length of the data trimmed, or 0 if length of the data to trim is zero.\r
\r
**/\r
UINT32\r
EFIAPI\r
NetbufQueTrim (\r
- IN NET_BUF_QUEUE *NbufQue,\r
+ IN OUT NET_BUF_QUEUE *NbufQue,\r
IN UINT32 Len\r
)\r
{\r
/**\r
Flush the net buffer queue.\r
\r
- @param NbufQue Pointer to the queue to be flushed.\r
-\r
- @return None.\r
+ @param[in, out] NbufQue Pointer to the queue to be flushed.\r
\r
**/\r
VOID\r
EFIAPI\r
NetbufQueFlush (\r
- IN NET_BUF_QUEUE *NbufQue\r
+ IN OUT NET_BUF_QUEUE *NbufQue\r
)\r
{\r
NET_CHECK_SIGNATURE (NbufQue, NET_QUE_SIGNATURE);\r
/**\r
Compute checksum for a bulk of data.\r
\r
- @param Bulk Pointer to the data.\r
- @param Len Length of the data, in bytes.\r
+ @param[in] Bulk Pointer to the data.\r
+ @param[in] Len Length of the data, in bytes.\r
\r
- @retval UINT16 The computed checksum.\r
+ @return The computed checksum.\r
\r
**/\r
UINT16\r
//\r
// Fold 32-bit sum to 16 bits\r
//\r
- while (Sum >> 16) {\r
+ while ((Sum >> 16) != 0) {\r
Sum = (Sum & 0xffff) + (Sum >> 16);\r
\r
}\r
/**\r
Add two checksums.\r
\r
- @param Checksum1 The first checksum to be added.\r
- @param Checksum2 The second checksum to be added.\r
+ @param[in] Checksum1 The first checksum to be added.\r
+ @param[in] Checksum2 The second checksum to be added.\r
\r
- @retval UINT16 The new checksum.\r
+ @return The new checksum.\r
\r
**/\r
UINT16\r
//\r
// two UINT16 can only add up to a carry of 1.\r
//\r
- if (Sum >> 16) {\r
+ if ((Sum >> 16) != 0) {\r
Sum = (Sum & 0xffff) + 1;\r
\r
}\r
/**\r
Compute the checksum for a NET_BUF.\r
\r
- @param Nbuf Pointer to the net buffer.\r
+ @param[in] Nbuf Pointer to the net buffer.\r
\r
- @retval UINT16 The computed checksum.\r
+ @return The computed checksum.\r
\r
**/\r
UINT16\r
\r
BlockSum = NetblockChecksum (BlockOp[Index].Head, BlockOp[Index].Size);\r
\r
- if (Offset & 0x01) {\r
+ if ((Offset & 0x01) != 0) {\r
//\r
// The checksum starts with an odd byte, swap\r
// the checksum before added to total checksum\r
Src, Dst are in network byte order. and Len is\r
in host byte order.\r
\r
- @param Src The source address of the packet.\r
- @param Dst The destination address of the packet.\r
- @param Proto The protocol type of the packet.\r
- @param Len The length of the packet.\r
+ @param[in] Src The source address of the packet.\r
+ @param[in] Dst The destination address of the packet.\r
+ @param[in] Proto The protocol type of the packet.\r
+ @param[in] Len The length of the packet.\r
\r
- @retval UINT16 The computed checksum.\r
+ @return The computed checksum.\r
\r
**/\r
UINT16\r