2 This library provides basic functiosn for UEFI network stack.
4 Copyright (c) 2005 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Protocol/DriverBinding.h>
22 #include <Protocol/ComponentName.h>
23 #include <Protocol/DriverConfiguration.h>
24 #include <Protocol/DriverDiagnostics.h>
25 #include <Protocol/Dpc.h>
27 typedef UINT32 IP4_ADDR
;
28 typedef UINT32 TCP_SEQNO
;
29 typedef UINT16 TCP_PORTNO
;
32 NET_ETHER_ADDR_LEN
= 6,
33 NET_IFTYPE_ETHERNET
= 0x01,
35 EFI_IP_PROTO_UDP
= 0x11,
36 EFI_IP_PROTO_TCP
= 0x06,
37 EFI_IP_PROTO_ICMP
= 0x01,
40 // The address classfication
54 // Ethernet head definition
57 UINT8 DstMac
[NET_ETHER_ADDR_LEN
];
58 UINT8 SrcMac
[NET_ETHER_ADDR_LEN
];
64 // The EFI_IP4_HEADER is hard to use because the source and
65 // destination address are defined as EFI_IPv4_ADDRESS, which
66 // is a structure. Two structures can't be compared or masked
67 // directly. This is why there is an internal representation.
85 // ICMP head definition. ICMP message is categoried as either an error
86 // message or query message. Two message types have their own head format.
96 UINT32 Fourth
; // 4th filed of the head, it depends on Type.
98 } IP4_ICMP_ERROR_HEAD
;
104 } IP4_ICMP_QUERY_HEAD
;
108 // UDP header definition
119 // TCP header definition
136 #define NET_MAC_EQUAL(pMac1, pMac2, Len) \
137 (CompareMem ((pMac1), (pMac2), Len) == 0)
139 #define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \
140 (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))
142 #define NTOHL(x) (UINT32)((((UINT32) (x) & 0xff) << 24) | \
143 (((UINT32) (x) & 0xff00) << 8) | \
144 (((UINT32) (x) & 0xff0000) >> 8) | \
145 (((UINT32) (x) & 0xff000000) >> 24))
147 #define HTONL(x) NTOHL(x)
149 #define NTOHS(x) (UINT16)((((UINT16) (x) & 0xff) << 8) | \
150 (((UINT16) (x) & 0xff00) >> 8))
152 #define HTONS(x) NTOHS(x)
155 // Test the IP's attribute, All the IPs are in host byte order.
157 #define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)
158 #define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)
159 #define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))
160 #define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != IP4_MASK_NUM)
163 // Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.
165 #define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))
166 #define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))
167 #define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)
170 Return the length of the mask. If the mask is invalid,
171 return the invalid length 33, which is IP4_MASK_NUM.
172 NetMask is in the host byte order.
174 @param NetMask The netmask to get the length from
176 @return The length of the netmask, IP4_MASK_NUM if the mask isn't
187 Return the class of the address, such as class a, b, c.
188 Addr is in host byte order.
190 @param Addr The address to get the class from
192 @return IP address class, such as IP4_ADDR_CLASSA
202 Check whether the IP is a valid unicast address according to
203 the netmask. If NetMask is zero, use the IP address's class to
204 get the default mask.
206 @param Ip The IP to check againist
207 @param NetMask The mask of the IP
209 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE
218 extern IP4_ADDR mIp4AllMasks
[IP4_MASK_NUM
];
221 extern EFI_IPv4_ADDRESS mZeroIp4Addr
;
223 #define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))
224 #define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))
225 #define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))
226 #define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))
228 #define TICKS_PER_MS 10000U
229 #define TICKS_PER_SECOND 10000000U
231 #define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)
234 Extract a UINT32 from a byte stream, then convert it to host
235 byte order. Use this function to avoid alignment error.
237 @param Buf The buffer to extract the UINT32.
239 @return The UINT32 extracted.
249 Put a UINT32 to the byte stream. Convert it from host byte order
250 to network byte order before putting.
252 @param Buf The buffer to put the UINT32
253 @param Data The data to put
266 Initialize a random seed using current time.
270 @return The random seed initialized with current time.
280 #define NET_LIST_USER_STRUCT(Entry, Type, Field) \
281 _CR(Entry, Type, Field)
283 #define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \
284 CR(Entry, Type, Field, Sig)
287 // Iterate through the doule linked list. It is NOT delete safe
289 #define NET_LIST_FOR_EACH(Entry, ListHead) \
290 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
293 // Iterate through the doule linked list. This is delete-safe.
294 // Don't touch NextEntry. Also, don't use this macro if list
295 // entries other than the Entry may be deleted when processing
296 // the current Entry.
298 #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
299 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
300 Entry != (ListHead); \
301 Entry = NextEntry, NextEntry = Entry->ForwardLink \
305 // Make sure the list isn't empty before get the frist/last record.
307 #define NET_LIST_HEAD(ListHead, Type, Field) \
308 NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)
310 #define NET_LIST_TAIL(ListHead, Type, Field) \
311 NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)
315 Remove the first entry on the list
317 @param Head The list header
319 @return The entry that is removed from the list, NULL if the list is empty.
329 Remove the last entry on the list
331 @param Head The list head
333 @return The entry that is removed from the list, NULL if the list is empty.
343 Insert the NewEntry after the PrevEntry
345 @param PrevEntry The previous entry to insert after
346 @param NewEntry The new entry to insert
354 IN LIST_ENTRY
*PrevEntry
,
355 IN LIST_ENTRY
*NewEntry
359 Insert the NewEntry before the PostEntry
361 @param PostEntry The entry to insert before
362 @param NewEntry The new entry to insert
369 NetListInsertBefore (
370 IN LIST_ENTRY
*PostEntry
,
371 IN LIST_ENTRY
*NewEntry
376 // Object container: EFI network stack spec defines various kinds of
377 // tokens. The drivers can share code to manage those objects.
391 #define NET_MAP_INCREAMENT 64
394 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.
396 @param Map The netmap to initialize
408 To clean up the netmap, that is, release allocated memories.
410 @param Map The netmap to clean up.
422 Test whether the netmap is empty
424 @param Map The net map to test
426 @return TRUE if the netmap is empty, otherwise FALSE.
436 Return the number of the <Key, Value> pairs in the netmap.
438 @param Map The netmap to get the entry number
440 @return The entry number in the netmap.
450 Allocate an item to save the <Key, Value> pair to the head of the netmap.
452 @param Map The netmap to insert into
453 @param Key The user's key
454 @param Value The user's value for the key
456 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
457 @retval EFI_SUCCESS The item is inserted to the head
465 IN VOID
*Value OPTIONAL
469 Allocate an item to save the <Key, Value> pair to the tail of the netmap.
471 @param Map The netmap to insert into
472 @param Key The user's key
473 @param Value The user's value for the key
475 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
476 @retval EFI_SUCCESS The item is inserted to the tail
484 IN VOID
*Value OPTIONAL
488 Find the key in the netmap
490 @param Map The netmap to search within
491 @param Key The key to search
493 @return The point to the item contains the Key, or NULL if Key isn't in the map.
504 Remove the item from the netmap
506 @param Map The netmap to remove the item from
507 @param Item The item to remove
508 @param Value The variable to receive the value if not NULL
510 @return The key of the removed item.
517 IN NET_MAP_ITEM
*Item
,
518 OUT VOID
**Value OPTIONAL
522 Remove the first entry on the netmap
524 @param Map The netmap to remove the head from
525 @param Value The variable to receive the value if not NULL
527 @return The key of the item removed
534 OUT VOID
**Value OPTIONAL
538 Remove the last entry on the netmap
540 @param Map The netmap to remove the tail from
541 @param Value The variable to receive the value if not NULL
543 @return The key of the item removed
550 OUT VOID
**Value OPTIONAL
555 (*NET_MAP_CALLBACK
) (
557 IN NET_MAP_ITEM
*Item
,
562 Iterate through the netmap and call CallBack for each item. It will
563 contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break
564 from the loop. It returns the CallBack's last return value. This
565 function is delete safe for the current item.
567 @param Map The Map to iterate through
568 @param CallBack The callback function to call for each item.
569 @param Arg The opaque parameter to the callback
571 @return It returns the CallBack's last return value.
578 IN NET_MAP_CALLBACK CallBack
,
579 IN VOID
*Arg OPTIONAL
584 // Helper functions to implement driver binding and service binding protocols.
587 Create a child of the service that is identified by ServiceBindingGuid.
589 @param Controller The controller which has the service installed.
590 @param Image The image handle used to open service.
591 @param ServiceBindingGuid The service's Guid.
592 @param ChildHandle The handle to receive the create child
594 @retval EFI_SUCCESS The child is successfully created.
595 @retval Others Failed to create the child.
600 NetLibCreateServiceChild (
601 IN EFI_HANDLE ControllerHandle
,
602 IN EFI_HANDLE ImageHandle
,
603 IN EFI_GUID
*ServiceBindingGuid
,
604 OUT EFI_HANDLE
*ChildHandle
608 Destory a child of the service that is identified by ServiceBindingGuid.
610 @param Controller The controller which has the service installed.
611 @param Image The image handle used to open service.
612 @param ServiceBindingGuid The service's Guid.
613 @param ChildHandle The child to destory
615 @retval EFI_SUCCESS The child is successfully destoried.
616 @retval Others Failed to destory the child.
621 NetLibDestroyServiceChild (
622 IN EFI_HANDLE ControllerHandle
,
623 IN EFI_HANDLE ImageHandle
,
624 IN EFI_GUID
*ServiceBindingGuid
,
625 IN EFI_HANDLE ChildHandle
629 Convert the mac address of the simple network protocol installed on
630 SnpHandle to a unicode string. Callers are responsible for freeing the
633 @param SnpHandle The handle where the simple network protocol is
635 @param ImageHandle The image handle used to act as the agent handle to
636 get the simple network protocol.
637 @param MacString The pointer to store the address of the string
638 representation of the mac address.
640 @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.
641 @retval other Failed to open the simple network protocol.
647 IN EFI_HANDLE SnpHandle
,
648 IN EFI_HANDLE ImageHandle
,
649 IN OUT CHAR16
**MacString
653 Create an IPv4 device path node.
655 @param Node Pointer to the IPv4 device path node.
656 @param Controller The handle where the NIC IP4 config protocol resides.
657 @param LocalIp The local IPv4 address.
658 @param LocalPort The local port.
659 @param RemoteIp The remote IPv4 address.
660 @param RemotePort The remote port.
661 @param Protocol The protocol type in the IP header.
662 @param UseDefaultAddress Whether this instance is using default address or not.
668 NetLibCreateIPv4DPathNode (
669 IN OUT IPv4_DEVICE_PATH
*Node
,
670 IN EFI_HANDLE Controller
,
673 IN IP4_ADDR RemoteIp
,
674 IN UINT16 RemotePort
,
676 IN BOOLEAN UseDefaultAddress
680 Find the UNDI/SNP handle from controller and protocol GUID.
681 For example, IP will open a MNP child to transmit/receive
682 packets, when MNP is stopped, IP should also be stopped. IP
683 needs to find its own private data which is related the IP's
684 service binding instance that is install on UNDI/SNP handle.
685 Now, the controller is either a MNP or ARP child handle. But
686 IP opens these handle BY_DRIVER, use that info, we can get the
689 @param Controller Then protocol handle to check
690 @param ProtocolGuid The protocol that is related with the handle.
692 @return The UNDI/SNP handle or NULL.
698 IN EFI_HANDLE Controller
,
699 IN EFI_GUID
*ProtocolGuid
703 Add a Deferred Procedure Call to the end of the DPC queue.
705 @DpcTpl The EFI_TPL that the DPC should be invoked.
706 @DpcProcedure Pointer to the DPC's function.
707 @DpcContext Pointer to the DPC's context. Passed to DpcProcedure
708 when DpcProcedure is invoked.
710 @retval EFI_SUCCESS The DPC was queued.
711 @retval EFI_INVALID_PARAMETER DpcTpl is not a valid EFI_TPL.
712 DpcProcedure is NULL.
713 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
714 add the DPC to the queue.
721 IN EFI_DPC_PROCEDURE DpcProcedure
,
722 IN VOID
*DpcContext OPTIONAL
726 Add a Deferred Procedure Call to the end of the DPC queue.
728 @retval EFI_SUCCESS One or more DPCs were invoked.
729 @retval EFI_NOT_FOUND No DPCs were invoked.
739 The constructor function caches the pointer to DPC protocol.
741 The constructor function locates DPC protocol from protocol database.
742 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
744 @param ImageHandle The firmware allocated handle for the EFI image.
745 @param SystemTable A pointer to the EFI System Table.
747 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
752 NetLibDefaultUnload (
753 IN EFI_HANDLE ImageHandle
760 NET_BUF_SIGNATURE
= EFI_SIGNATURE_32 ('n', 'b', 'u', 'f'),
761 NET_VECTOR_SIGNATURE
= EFI_SIGNATURE_32 ('n', 'v', 'e', 'c'),
762 NET_QUE_SIGNATURE
= EFI_SIGNATURE_32 ('n', 'b', 'q', 'u'),
765 NET_PROTO_DATA
= 64, // Opaque buffer for protocols
766 NET_BUF_HEAD
= 1, // Trim or allocate space from head
767 NET_BUF_TAIL
= 0, // Trim or allocate space from tail
768 NET_VECTOR_OWN_FIRST
= 0x01 // We allocated the 1st block in the vector
771 #define NET_CHECK_SIGNATURE(PData, SIGNATURE) \
772 ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))
774 #define NET_SWAP_SHORT(Value) \
775 ((((Value) & 0xff) << 8) | (((Value) >> 8) & 0xff))
778 // Single memory block in the vector.
781 UINT32 Len
; // The block's length
782 UINT8
*Bulk
; // The block's Data
785 typedef VOID (*NET_VECTOR_EXT_FREE
) (VOID
*Arg
);
788 //NET_VECTOR contains several blocks to hold all packet's
789 //fragments and other house-keeping stuff for sharing. It
790 //doesn't specify the where actual packet fragment begins.
794 INTN RefCnt
; // Reference count to share NET_VECTOR.
795 NET_VECTOR_EXT_FREE Free
; // external function to free NET_VECTOR
796 VOID
*Arg
; // opeque argument to Free
797 UINT32 Flag
; // Flags, NET_VECTOR_OWN_FIRST
798 UINT32 Len
; // Total length of the assocated BLOCKs
805 //NET_BLOCK_OP operate on the NET_BLOCK, It specifies
806 //where the actual fragment begins and where it ends
809 UINT8
*BlockHead
; // Block's head, or the smallest valid Head
810 UINT8
*BlockTail
; // Block's tail. BlockTail-BlockHead=block length
811 UINT8
*Head
; // 1st byte of the data in the block
812 UINT8
*Tail
; // Tail of the data in the block, Tail-Head=Size
813 UINT32 Size
; // The size of the data
818 //NET_BUF is the buffer manage structure used by the
819 //network stack. Every network packet may be fragmented,
820 //and contains multiple fragments. The Vector points to
821 //memory blocks used by the each fragment, and BlockOp
822 //specifies where each fragment begins and ends.
824 //It also contains a opaque area for protocol to store
825 //per-packet informations. Protocol must be caution not
826 //to overwrite the members after that.
831 LIST_ENTRY List
; // The List this NET_BUF is on
833 IP4_HEAD
*Ip
; // Network layer header, for fast access
834 TCP_HEAD
*Tcp
; // Transport layer header, for fast access
835 UINT8 ProtoData
[NET_PROTO_DATA
]; //Protocol specific data
837 NET_VECTOR
*Vector
; // The vector containing the packet
839 UINT32 BlockOpNum
; // Total number of BlockOp in the buffer
840 UINT32 TotalSize
; // Total size of the actual packet
841 NET_BLOCK_OP BlockOp
[1]; // Specify the position of actual packet
846 //A queue of NET_BUFs, It is just a thin extension of
852 LIST_ENTRY List
; // The List this buffer queue is on
854 LIST_ENTRY BufList
; // list of queued buffers
855 UINT32 BufSize
; // total length of DATA in the buffers
856 UINT32 BufNum
; // total number of buffers on the chain
860 // Pseudo header for TCP and UDP checksum
873 // The fragment entry table used in network interfaces. This is
874 // the same as NET_BLOCK now. Use two different to distinguish
875 // the two in case that NET_BLOCK be enhanced later.
882 #define NET_GET_REF(PData) ((PData)->RefCnt++)
883 #define NET_PUT_REF(PData) ((PData)->RefCnt--)
884 #define NETBUF_FROM_PROTODATA(Info) _CR((Info), NET_BUF, ProtoData)
886 #define NET_BUF_SHARED(Buf) \
887 (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))
889 #define NET_VECTOR_SIZE(BlockNum) \
890 (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))
892 #define NET_BUF_SIZE(BlockOpNum) \
893 (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))
895 #define NET_HEADSPACE(BlockOp) \
896 (UINTN)((BlockOp)->Head - (BlockOp)->BlockHead)
898 #define NET_TAILSPACE(BlockOp) \
899 (UINTN)((BlockOp)->BlockTail - (BlockOp)->Tail)
902 Allocate a single block NET_BUF. Upon allocation, all the
903 free space is in the tail room.
905 @param Len The length of the block.
907 @retval * Pointer to the allocated NET_BUF. If NULL the
908 allocation failed due to resource limit.
918 Free the buffer and its associated NET_VECTOR.
920 @param Nbuf Pointer to the NET_BUF to be freed.
932 Get the position of some byte in the net buffer. This can be used
933 to, for example, retrieve the IP header in the packet. It also
934 returns the fragment that contains the byte which is used mainly by
935 the buffer implementation itself.
937 @param Nbuf Pointer to the net buffer.
938 @param Offset The index or offset of the byte
939 @param Index Index of the fragment that contains the block
941 @retval * Pointer to the nth byte of data in the net buffer.
942 If NULL, there is no such data in the net buffer.
950 OUT UINT32
*Index OPTIONAL
954 Create a copy of NET_BUF that share the associated NET_DATA.
956 @param Nbuf Pointer to the net buffer to be cloned.
958 @retval * Pointer to the cloned net buffer.
968 Create a duplicated copy of Nbuf, data is copied. Also leave some
969 head space before the data.
971 @param Nbuf Pointer to the net buffer to be cloned.
972 @param Duplicate Pointer to the net buffer to duplicate to, if NULL
973 a new net buffer is allocated.
974 @param HeadSpace Length of the head space to reserve
976 @retval * Pointer to the duplicated net buffer.
983 IN NET_BUF
*Duplicate OPTIONAL
,
988 Create a NET_BUF structure which contains Len byte data of
989 Nbuf starting from Offset. A new NET_BUF structure will be
990 created but the associated data in NET_VECTOR is shared.
991 This function exists to do IP packet fragmentation.
993 @param Nbuf Pointer to the net buffer to be cloned.
994 @param Offset Starting point of the data to be included in new
996 @param Len How many data to include in new data
997 @param HeadSpace How many bytes of head space to reserve for
1000 @retval * Pointer to the cloned net buffer.
1013 Reserve some space in the header room of the buffer.
1014 Upon allocation, all the space are in the tail room
1015 of the buffer. Call this function to move some space
1016 to the header room. This function is quite limited in
1017 that it can only reserver space from the first block
1018 of an empty NET_BUF not built from the external. But
1019 it should be enough for the network stack.
1021 @param Nbuf Pointer to the net buffer.
1022 @param Len The length of buffer to be reserverd.
1035 Allocate some space from the header or tail of the buffer.
1037 @param Nbuf Pointer to the net buffer.
1038 @param Len The length of the buffer to be allocated.
1039 @param FromHead The flag to indicate whether reserve the data from
1040 head or tail. TRUE for from head, and FALSE for
1043 @retval * Pointer to the first byte of the allocated buffer.
1055 Trim some data from the header or tail of the buffer.
1057 @param Nbuf Pointer to the net buffer.
1058 @param Len The length of the data to be trimmed.
1059 @param FromHead The flag to indicate whether trim data from head or
1060 tail. TRUE for from head, and FALSE for from tail.
1062 @retval UINTN Length of the actually trimmed data.
1074 Copy the data from the specific offset to the destination.
1076 @param Nbuf Pointer to the net buffer.
1077 @param Offset The sequence number of the first byte to copy.
1078 @param Len Length of the data to copy.
1079 @param Dest The destination of the data to copy to.
1081 @retval UINTN The length of the copied data.
1094 Build a NET_BUF from external blocks.
1096 @param ExtFragment Pointer to the data block.
1097 @param ExtNum The number of the data block.
1098 @param HeadSpace The head space to be reserved.
1099 @param HeadLen The length of the protocol header, This function
1100 will pull that number of data into a linear block.
1101 @param ExtFree Pointer to the caller provided free function.
1102 @param Arg The argument passed to ExtFree when ExtFree is
1105 @retval * Pointer to the net buffer built from the data
1112 IN NET_FRAGMENT
*ExtFragment
,
1114 IN UINT32 HeadSpace
,
1116 IN NET_VECTOR_EXT_FREE ExtFree
,
1117 IN VOID
*Arg OPTIONAL
1121 Build a fragment table to contain the fragments in the
1122 buffer. This is the opposite of the NetbufFromExt.
1124 @param Nbuf Point to the net buffer
1125 @param ExtFragment Pointer to the data block.
1126 @param ExtNum The number of the data block.
1128 @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than ExtNum
1129 @retval EFI_SUCCESS Fragment table built.
1136 IN NET_FRAGMENT
*ExtFragment
,
1141 Build a NET_BUF from a list of NET_BUF.
1143 @param BufList A List of NET_BUF.
1144 @param HeadSpace The head space to be reserved.
1145 @param HeaderLen The length of the protocol header, This function
1146 will pull that number of data into a linear block.
1147 @param ExtFree Pointer to the caller provided free function.
1148 @param Arg The argument passed to ExtFree when ExtFree is
1151 @retval * Pointer to the net buffer built from the data
1158 IN LIST_ENTRY
*BufList
,
1159 IN UINT32 HeadSpace
,
1160 IN UINT32 HeaderLen
,
1161 IN NET_VECTOR_EXT_FREE ExtFree
,
1162 IN VOID
*Arg OPTIONAL
1166 Free a list of net buffers.
1168 @param Head Pointer to the head of linked net buffers.
1180 Initiate the net buffer queue.
1182 @param NbufQue Pointer to the net buffer queue to be initiated.
1190 IN NET_BUF_QUEUE
*NbufQue
1194 Allocate an initialized net buffer queue.
1198 @retval * Pointer to the allocated net buffer queue.
1208 Free a net buffer queue.
1210 @param NbufQue Poitner to the net buffer queue to be freed.
1218 IN NET_BUF_QUEUE
*NbufQue
1222 Remove a net buffer from head in the specific queue.
1224 @param NbufQue Pointer to the net buffer queue.
1226 @retval * Pointer to the net buffer removed from the specific
1233 IN NET_BUF_QUEUE
*NbufQue
1237 Append a buffer to the end of the queue.
1239 @param NbufQue Pointer to the net buffer queue.
1240 @param Nbuf Pointer to the net buffer to be appended.
1248 IN NET_BUF_QUEUE
*NbufQue
,
1253 Copy some data from the buffer queue to the destination.
1255 @param NbufQue Pointer to the net buffer queue.
1256 @param Offset The sequence number of the first byte to copy.
1257 @param Len Length of the data to copy.
1258 @param Dest The destination of the data to copy to.
1260 @retval UINTN The length of the copied data.
1266 IN NET_BUF_QUEUE
*NbufQue
,
1273 Copy some data from the buffer queue to the destination.
1275 @param NbufQue Pointer to the net buffer queue.
1276 @param Offset The sequence number of the first byte to copy.
1277 @param Len Length of the data to copy.
1278 @param Dest The destination of the data to copy to.
1280 @retval UINTN The length of the copied data.
1286 IN NET_BUF_QUEUE
*NbufQue
,
1292 Flush the net buffer queue.
1294 @param NbufQue Pointer to the queue to be flushed.
1302 IN NET_BUF_QUEUE
*NbufQue
1306 Compute checksum for a bulk of data.
1308 @param Bulk Pointer to the data.
1309 @param Len Length of the data, in bytes.
1311 @retval UINT16 The computed checksum.
1324 @param Checksum1 The first checksum to be added.
1325 @param Checksum2 The second checksum to be added.
1327 @retval UINT16 The new checksum.
1333 IN UINT16 Checksum1
,
1338 Compute the checksum for a NET_BUF.
1340 @param Nbuf Pointer to the net buffer.
1342 @retval UINT16 The computed checksum.
1352 Compute the checksum for TCP/UDP pseudo header.
1353 Src, Dst are in network byte order. and Len is
1356 @param Src The source address of the packet.
1357 @param Dst The destination address of the packet.
1358 @param Proto The protocol type of the packet.
1359 @param Len The length of the packet.
1361 @retval UINT16 The computed checksum.
1366 NetPseudoHeadChecksum (