2 This library provides basic function 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.
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Protocol/DriverBinding.h>
21 #include <Protocol/ComponentName.h>
22 #include <Protocol/DriverConfiguration.h>
23 #include <Protocol/DriverDiagnostics.h>
24 #include <Protocol/Dpc.h>
26 typedef UINT32 IP4_ADDR
;
27 typedef UINT32 TCP_SEQNO
;
28 typedef UINT16 TCP_PORTNO
;
31 NET_ETHER_ADDR_LEN
= 6,
32 NET_IFTYPE_ETHERNET
= 0x01,
34 EFI_IP_PROTO_UDP
= 0x11,
35 EFI_IP_PROTO_TCP
= 0x06,
36 EFI_IP_PROTO_ICMP
= 0x01,
39 // The address classification
53 // Ethernet head definition
56 UINT8 DstMac
[NET_ETHER_ADDR_LEN
];
57 UINT8 SrcMac
[NET_ETHER_ADDR_LEN
];
63 // The EFI_IP4_HEADER is hard to use because the source and
64 // destination address are defined as EFI_IPv4_ADDRESS, which
65 // is a structure. Two structures can't be compared or masked
66 // directly. This is why there is an internal representation.
84 // ICMP head definition. ICMP message is categoried as either an error
85 // message or query message. Two message types have their own head format.
95 UINT32 Fourth
; // 4th filed of the head, it depends on Type.
97 } IP4_ICMP_ERROR_HEAD
;
103 } IP4_ICMP_QUERY_HEAD
;
107 // UDP header definition
118 // TCP header definition
135 #define NET_MAC_EQUAL(pMac1, pMac2, Len) \
136 (CompareMem ((pMac1), (pMac2), Len) == 0)
138 #define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \
139 (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))
141 #define NTOHL(x) (UINT32)((((UINT32) (x) & 0xff) << 24) | \
142 (((UINT32) (x) & 0xff00) << 8) | \
143 (((UINT32) (x) & 0xff0000) >> 8) | \
144 (((UINT32) (x) & 0xff000000) >> 24))
146 #define HTONL(x) NTOHL(x)
148 #define NTOHS(x) (UINT16)((((UINT16) (x) & 0xff) << 8) | \
149 (((UINT16) (x) & 0xff00) >> 8))
151 #define HTONS(x) NTOHS(x)
154 // Test the IP's attribute, All the IPs are in host byte order.
156 #define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)
157 #define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)
158 #define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))
159 #define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != IP4_MASK_NUM)
162 // Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.
164 #define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))
165 #define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))
166 #define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)
169 Return the length of the mask. If the mask is invalid,
170 return the invalid length 33, which is IP4_MASK_NUM.
171 NetMask is in the host byte order.
173 @param NetMask The netmask to get the length from
175 @return The length of the netmask, IP4_MASK_NUM if the mask isn't
186 Return the class of the address, such as class a, b, c.
187 Addr is in host byte order.
189 @param Addr The address to get the class from
191 @return IP address class, such as IP4_ADDR_CLASSA
201 Check whether the IP is a valid unicast address according to
202 the netmask. If NetMask is zero, use the IP address's class to
203 get the default mask.
205 @param Ip The IP to check againist
206 @param NetMask The mask of the IP
208 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE
217 extern IP4_ADDR gIp4AllMasks
[IP4_MASK_NUM
];
220 extern EFI_IPv4_ADDRESS mZeroIp4Addr
;
222 #define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))
223 #define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))
224 #define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))
225 #define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))
227 #define TICKS_PER_MS 10000U
228 #define TICKS_PER_SECOND 10000000U
230 #define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)
233 Extract a UINT32 from a byte stream, then convert it to host
234 byte order. Use this function to avoid alignment error.
236 @param Buf The buffer to extract the UINT32.
238 @return The UINT32 extracted.
248 Put a UINT32 to the byte stream. Convert it from host byte order
249 to network byte order before putting.
251 @param Buf The buffer to put the UINT32
252 @param Data The data to put
265 Initialize a random seed using current time.
269 @return The random seed initialized with current time.
279 #define NET_LIST_USER_STRUCT(Entry, Type, Field) \
280 BASE_CR(Entry, Type, Field)
282 #define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \
283 CR(Entry, Type, Field, Sig)
286 // Iterate through the doule linked list. It is NOT delete safe
288 #define NET_LIST_FOR_EACH(Entry, ListHead) \
289 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
292 // Iterate through the doule linked list. This is delete-safe.
293 // Don't touch NextEntry. Also, don't use this macro if list
294 // entries other than the Entry may be deleted when processing
295 // the current Entry.
297 #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
298 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
299 Entry != (ListHead); \
300 Entry = NextEntry, NextEntry = Entry->ForwardLink \
304 // Make sure the list isn't empty before get the frist/last record.
306 #define NET_LIST_HEAD(ListHead, Type, Field) \
307 NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)
309 #define NET_LIST_TAIL(ListHead, Type, Field) \
310 NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)
314 Remove the first entry on the list
316 @param Head The list header
318 @return The entry that is removed from the list, NULL if the list is empty.
328 Remove the last entry on the list
330 @param Head The list head
332 @return The entry that is removed from the list, NULL if the list is empty.
342 Insert the NewEntry after the PrevEntry.
344 @param PrevEntry The previous entry to insert after
345 @param NewEntry The new entry to insert
353 IN LIST_ENTRY
*PrevEntry
,
354 IN LIST_ENTRY
*NewEntry
358 Insert the NewEntry before the PostEntry.
360 @param PostEntry The entry to insert before
361 @param NewEntry The new entry to insert
368 NetListInsertBefore (
369 IN LIST_ENTRY
*PostEntry
,
370 IN LIST_ENTRY
*NewEntry
375 // Object container: EFI network stack spec defines various kinds of
376 // tokens. The drivers can share code to manage those objects.
390 #define NET_MAP_INCREAMENT 64
393 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.
395 @param Map The netmap to initialize
407 To clean up the netmap, that is, release allocated memories.
409 @param Map The netmap to clean up.
421 Test whether the netmap is empty
423 @param Map The net map to test
425 @return TRUE if the netmap is empty, otherwise FALSE.
435 Return the number of the <Key, Value> pairs in the netmap.
437 @param Map The netmap to get the entry number
439 @return The entry number in the netmap.
449 Allocate an item to save the <Key, Value> pair to the head of the netmap.
451 @param Map The netmap to insert into
452 @param Key The user's key
453 @param Value The user's value for the key
455 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
456 @retval EFI_SUCCESS The item is inserted to the head
464 IN VOID
*Value OPTIONAL
468 Allocate an item to save the <Key, Value> pair to the tail of the netmap.
470 @param Map The netmap to insert into
471 @param Key The user's key
472 @param Value The user's value for the key
474 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
475 @retval EFI_SUCCESS The item is inserted to the tail
483 IN VOID
*Value OPTIONAL
487 Find the key in the netmap
489 @param Map The netmap to search within
490 @param Key The key to search
492 @return The point to the item contains the Key, or NULL if Key isn't in the map.
503 Remove the item from the netmap
505 @param Map The netmap to remove the item from
506 @param Item The item to remove
507 @param Value The variable to receive the value if not NULL
509 @return The key of the removed item.
516 IN NET_MAP_ITEM
*Item
,
517 OUT VOID
**Value OPTIONAL
521 Remove the first entry on the netmap.
523 @param Map The netmap to remove the head from
524 @param Value The variable to receive the value if not NULL
526 @return The key of the item removed
533 OUT VOID
**Value OPTIONAL
537 Remove the last entry on the netmap.
539 @param Map The netmap to remove the tail from
540 @param Value The variable to receive the value if not NULL
542 @return The key of the item removed
549 OUT VOID
**Value OPTIONAL
554 (*NET_MAP_CALLBACK
) (
556 IN NET_MAP_ITEM
*Item
,
561 Iterate through the netmap and call CallBack for each item. It will
562 contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break
563 from the loop. It returns the CallBack's last return value. This
564 function is delete safe for the current item.
566 @param Map The Map to iterate through
567 @param CallBack The callback function to call for each item.
568 @param Arg The opaque parameter to the callback
570 @return It returns the CallBack's last return value.
577 IN NET_MAP_CALLBACK CallBack
,
578 IN VOID
*Arg OPTIONAL
583 // Helper functions to implement driver binding and service binding protocols.
586 Create a child of the service that is identified by ServiceBindingGuid.
588 @param ControllerHandle The controller which has the service installed.
589 @param ImageHandle The image handle used to open service.
590 @param ServiceBindingGuid The service's Guid.
591 @param ChildHandle The handle to receive the create child
593 @retval EFI_SUCCESS The child is successfully created.
594 @retval Others Failed to create the child.
599 NetLibCreateServiceChild (
600 IN EFI_HANDLE ControllerHandle
,
601 IN EFI_HANDLE ImageHandle
,
602 IN EFI_GUID
*ServiceBindingGuid
,
603 OUT EFI_HANDLE
*ChildHandle
607 Destory a child of the service that is identified by ServiceBindingGuid.
609 @param ControllerHandle The controller which has the service installed.
610 @param ImageHandle The image handle used to open service.
611 @param ServiceBindingGuid The service's Guid.
612 @param ChildHandle The child to destory
614 @retval EFI_SUCCESS The child is successfully destoried.
615 @retval Others Failed to destory the child.
620 NetLibDestroyServiceChild (
621 IN EFI_HANDLE ControllerHandle
,
622 IN EFI_HANDLE ImageHandle
,
623 IN EFI_GUID
*ServiceBindingGuid
,
624 IN EFI_HANDLE ChildHandle
628 Convert the mac address of the simple network protocol installed on
629 SnpHandle to a unicode string. Callers are responsible for freeing the
632 @param SnpHandle The handle where the simple network protocol is
634 @param ImageHandle The image handle used to act as the agent handle to
635 get the simple network protocol.
636 @param MacString The pointer to store the address of the string
637 representation of the mac address.
639 @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.
640 @retval other Failed to open the simple network protocol.
646 IN EFI_HANDLE SnpHandle
,
647 IN EFI_HANDLE ImageHandle
,
648 IN OUT CHAR16
**MacString
652 Create an IPv4 device path node.
654 @param Node Pointer to the IPv4 device path node.
655 @param Controller The handle where the NIC IP4 config protocol resides.
656 @param LocalIp The local IPv4 address.
657 @param LocalPort The local port.
658 @param RemoteIp The remote IPv4 address.
659 @param RemotePort The remote port.
660 @param Protocol The protocol type in the IP header.
661 @param UseDefaultAddress Whether this instance is using default address or not.
666 NetLibCreateIPv4DPathNode (
667 IN OUT IPv4_DEVICE_PATH
*Node
,
668 IN EFI_HANDLE Controller
,
671 IN IP4_ADDR RemoteIp
,
672 IN UINT16 RemotePort
,
674 IN BOOLEAN UseDefaultAddress
678 Find the UNDI/SNP handle from controller and protocol GUID.
679 For example, IP will open a MNP child to transmit/receive
680 packets, when MNP is stopped, IP should also be stopped. IP
681 needs to find its own private data which is related the IP's
682 service binding instance that is install on UNDI/SNP handle.
683 Now, the controller is either a MNP or ARP child handle. But
684 IP opens these handle BY_DRIVER, use that info, we can get the
687 @param Controller Then protocol handle to check
688 @param ProtocolGuid The protocol that is related with the handle.
690 @return The UNDI/SNP handle or NULL.
696 IN EFI_HANDLE Controller
,
697 IN EFI_GUID
*ProtocolGuid
701 Add a Deferred Procedure Call to the end of the DPC queue.
703 @param DpcTpl The EFI_TPL that the DPC should be invoked.
704 @param DpcProcedure Pointer to the DPC's function.
705 @param DpcContext Pointer to the DPC's context. Passed to DpcProcedure
706 when DpcProcedure is invoked.
708 @retval EFI_SUCCESS The DPC was queued.
709 @retval EFI_INVALID_PARAMETER DpcTpl is not a valid EFI_TPL.
710 DpcProcedure is NULL.
711 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
712 add the DPC to the queue.
719 IN EFI_DPC_PROCEDURE DpcProcedure
,
720 IN VOID
*DpcContext OPTIONAL
724 Add a Deferred Procedure Call to the end of the DPC queue.
726 @retval EFI_SUCCESS One or more DPCs were invoked.
727 @retval EFI_NOT_FOUND No DPCs were invoked.
737 This is the default unload handle for all the network drivers.
739 @param ImageHandle The drivers' driver image.
741 @retval EFI_SUCCESS The image is unloaded.
742 @retval Others Failed to unload the image.
747 NetLibDefaultUnload (
748 IN EFI_HANDLE ImageHandle
755 NET_BUF_SIGNATURE
= EFI_SIGNATURE_32 ('n', 'b', 'u', 'f'),
756 NET_VECTOR_SIGNATURE
= EFI_SIGNATURE_32 ('n', 'v', 'e', 'c'),
757 NET_QUE_SIGNATURE
= EFI_SIGNATURE_32 ('n', 'b', 'q', 'u'),
760 NET_PROTO_DATA
= 64, // Opaque buffer for protocols
761 NET_BUF_HEAD
= 1, // Trim or allocate space from head
762 NET_BUF_TAIL
= 0, // Trim or allocate space from tail
763 NET_VECTOR_OWN_FIRST
= 0x01 // We allocated the 1st block in the vector
764 } NET_SIGNATURE_TYPE
;
766 #define NET_CHECK_SIGNATURE(PData, SIGNATURE) \
767 ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))
769 #define NET_SWAP_SHORT(Value) \
770 ((((Value) & 0xff) << 8) | (((Value) >> 8) & 0xff))
773 // Single memory block in the vector.
776 UINT32 Len
; // The block's length
777 UINT8
*Bulk
; // The block's Data
780 typedef VOID (*NET_VECTOR_EXT_FREE
) (VOID
*Arg
);
783 //NET_VECTOR contains several blocks to hold all packet's
784 //fragments and other house-keeping stuff for sharing. It
785 //doesn't specify the where actual packet fragment begins.
789 INTN RefCnt
; // Reference count to share NET_VECTOR.
790 NET_VECTOR_EXT_FREE Free
; // external function to free NET_VECTOR
791 VOID
*Arg
; // opeque argument to Free
792 UINT32 Flag
; // Flags, NET_VECTOR_OWN_FIRST
793 UINT32 Len
; // Total length of the assocated BLOCKs
800 //NET_BLOCK_OP operate on the NET_BLOCK, It specifies
801 //where the actual fragment begins and where it ends
804 UINT8
*BlockHead
; // Block's head, or the smallest valid Head
805 UINT8
*BlockTail
; // Block's tail. BlockTail-BlockHead=block length
806 UINT8
*Head
; // 1st byte of the data in the block
807 UINT8
*Tail
; // Tail of the data in the block, Tail-Head=Size
808 UINT32 Size
; // The size of the data
813 //NET_BUF is the buffer manage structure used by the
814 //network stack. Every network packet may be fragmented,
815 //and contains multiple fragments. The Vector points to
816 //memory blocks used by the each fragment, and BlockOp
817 //specifies where each fragment begins and ends.
819 //It also contains a opaque area for protocol to store
820 //per-packet informations. Protocol must be caution not
821 //to overwrite the members after that.
826 LIST_ENTRY List
; // The List this NET_BUF is on
828 IP4_HEAD
*Ip
; // Network layer header, for fast access
829 TCP_HEAD
*Tcp
; // Transport layer header, for fast access
830 UINT8 ProtoData
[NET_PROTO_DATA
]; //Protocol specific data
832 NET_VECTOR
*Vector
; // The vector containing the packet
834 UINT32 BlockOpNum
; // Total number of BlockOp in the buffer
835 UINT32 TotalSize
; // Total size of the actual packet
836 NET_BLOCK_OP BlockOp
[1]; // Specify the position of actual packet
841 //A queue of NET_BUFs, It is just a thin extension of
847 LIST_ENTRY List
; // The List this buffer queue is on
849 LIST_ENTRY BufList
; // list of queued buffers
850 UINT32 BufSize
; // total length of DATA in the buffers
851 UINT32 BufNum
; // total number of buffers on the chain
855 // Pseudo header for TCP and UDP checksum
868 // The fragment entry table used in network interfaces. This is
869 // the same as NET_BLOCK now. Use two different to distinguish
870 // the two in case that NET_BLOCK be enhanced later.
877 #define NET_GET_REF(PData) ((PData)->RefCnt++)
878 #define NET_PUT_REF(PData) ((PData)->RefCnt--)
879 #define NETBUF_FROM_PROTODATA(Info) BASE_CR((Info), NET_BUF, ProtoData)
881 #define NET_BUF_SHARED(Buf) \
882 (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))
884 #define NET_VECTOR_SIZE(BlockNum) \
885 (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))
887 #define NET_BUF_SIZE(BlockOpNum) \
888 (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))
890 #define NET_HEADSPACE(BlockOp) \
891 (UINTN)((BlockOp)->Head - (BlockOp)->BlockHead)
893 #define NET_TAILSPACE(BlockOp) \
894 (UINTN)((BlockOp)->BlockTail - (BlockOp)->Tail)
897 Allocate a single block NET_BUF. Upon allocation, all the
898 free space is in the tail room.
900 @param Len The length of the block.
902 @retval * Pointer to the allocated NET_BUF. If NULL the
903 allocation failed due to resource limit.
913 Free the buffer and its associated NET_VECTOR.
915 @param Nbuf Pointer to the NET_BUF to be freed.
927 Get the position of some byte in the net buffer. This can be used
928 to, for example, retrieve the IP header in the packet. It also
929 returns the fragment that contains the byte which is used mainly by
930 the buffer implementation itself.
932 @param Nbuf Pointer to the net buffer.
933 @param Offset The index or offset of the byte
934 @param Index Index of the fragment that contains the block
936 @retval * Pointer to the nth byte of data in the net buffer.
937 If NULL, there is no such data in the net buffer.
945 OUT UINT32
*Index OPTIONAL
949 Create a copy of NET_BUF that share the associated NET_DATA.
951 @param Nbuf Pointer to the net buffer to be cloned.
953 @retval * Pointer to the cloned net buffer.
963 Create a duplicated copy of Nbuf, data is copied. Also leave some
964 head space before the data.
966 @param Nbuf Pointer to the net buffer to be cloned.
967 @param Duplicate Pointer to the net buffer to duplicate to, if NULL
968 a new net buffer is allocated.
969 @param HeadSpace Length of the head space to reserve
971 @retval * Pointer to the duplicated net buffer.
978 IN NET_BUF
*Duplicate OPTIONAL
,
983 Create a NET_BUF structure which contains Len byte data of
984 Nbuf starting from Offset. A new NET_BUF structure will be
985 created but the associated data in NET_VECTOR is shared.
986 This function exists to do IP packet fragmentation.
988 @param Nbuf Pointer to the net buffer to be cloned.
989 @param Offset Starting point of the data to be included in new
991 @param Len How many data to include in new data
992 @param HeadSpace How many bytes of head space to reserve for
995 @retval * Pointer to the cloned net buffer.
1008 Reserve some space in the header room of the buffer.
1009 Upon allocation, all the space are in the tail room
1010 of the buffer. Call this function to move some space
1011 to the header room. This function is quite limited in
1012 that it can only reserver space from the first block
1013 of an empty NET_BUF not built from the external. But
1014 it should be enough for the network stack.
1016 @param Nbuf Pointer to the net buffer.
1017 @param Len The length of buffer to be reserverd.
1030 Allocate some space from the header or tail of the buffer.
1032 @param Nbuf Pointer to the net buffer.
1033 @param Len The length of the buffer to be allocated.
1034 @param FromHead The flag to indicate whether reserve the data from
1035 head or tail. TRUE for from head, and FALSE for
1038 @retval * Pointer to the first byte of the allocated buffer.
1050 Trim some data from the header or tail of the buffer.
1052 @param Nbuf Pointer to the net buffer.
1053 @param Len The length of the data to be trimmed.
1054 @param FromHead The flag to indicate whether trim data from head or
1055 tail. TRUE for from head, and FALSE for from tail.
1057 @retval UINTN Length of the actually trimmed data.
1069 Copy the data from the specific offset to the destination.
1071 @param Nbuf Pointer to the net buffer.
1072 @param Offset The sequence number of the first byte to copy.
1073 @param Len Length of the data to copy.
1074 @param Dest The destination of the data to copy to.
1076 @retval UINTN The length of the copied data.
1089 Build a NET_BUF from external blocks.
1091 @param ExtFragment Pointer to the data block.
1092 @param ExtNum The number of the data block.
1093 @param HeadSpace The head space to be reserved.
1094 @param HeadLen The length of the protocol header, This function
1095 will pull that number of data into a linear block.
1096 @param ExtFree Pointer to the caller provided free function.
1097 @param Arg The argument passed to ExtFree when ExtFree is
1100 @retval * Pointer to the net buffer built from the data
1107 IN NET_FRAGMENT
*ExtFragment
,
1109 IN UINT32 HeadSpace
,
1111 IN NET_VECTOR_EXT_FREE ExtFree
,
1112 IN VOID
*Arg OPTIONAL
1116 Build a fragment table to contain the fragments in the
1117 buffer. This is the opposite of the NetbufFromExt.
1119 @param Nbuf Point to the net buffer
1120 @param ExtFragment Pointer to the data block.
1121 @param ExtNum The number of the data block.
1123 @retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than ExtNum
1124 @retval EFI_SUCCESS Fragment table built.
1131 IN NET_FRAGMENT
*ExtFragment
,
1136 Build a NET_BUF from a list of NET_BUF.
1138 @param BufList A List of NET_BUF.
1139 @param HeadSpace The head space to be reserved.
1140 @param HeaderLen The length of the protocol header, This function
1141 will pull that number of data into a linear block.
1142 @param ExtFree Pointer to the caller provided free function.
1143 @param Arg The argument passed to ExtFree when ExtFree is
1146 @retval * Pointer to the net buffer built from the data
1153 IN LIST_ENTRY
*BufList
,
1154 IN UINT32 HeadSpace
,
1155 IN UINT32 HeaderLen
,
1156 IN NET_VECTOR_EXT_FREE ExtFree
,
1157 IN VOID
*Arg OPTIONAL
1161 Free a list of net buffers.
1163 @param Head Pointer to the head of linked net buffers.
1175 Initiate the net buffer queue.
1177 @param NbufQue Pointer to the net buffer queue to be initiated.
1185 IN NET_BUF_QUEUE
*NbufQue
1189 Allocate an initialized net buffer queue.
1193 @retval * Pointer to the allocated net buffer queue.
1203 Free a net buffer queue.
1205 @param NbufQue Poitner to the net buffer queue to be freed.
1213 IN NET_BUF_QUEUE
*NbufQue
1217 Remove a net buffer from head in the specific queue.
1219 @param NbufQue Pointer to the net buffer queue.
1221 @retval * Pointer to the net buffer removed from the specific
1228 IN NET_BUF_QUEUE
*NbufQue
1232 Append a buffer to the end of the queue.
1234 @param NbufQue Pointer to the net buffer queue.
1235 @param Nbuf Pointer to the net buffer to be appended.
1243 IN NET_BUF_QUEUE
*NbufQue
,
1248 Copy some data from the buffer queue to the destination.
1250 @param NbufQue Pointer to the net buffer queue.
1251 @param Offset The sequence number of the first byte to copy.
1252 @param Len Length of the data to copy.
1253 @param Dest The destination of the data to copy to.
1255 @retval UINTN The length of the copied data.
1261 IN NET_BUF_QUEUE
*NbufQue
,
1268 Trim some data from the queue header, release the buffer if
1269 whole buffer is trimmed.
1271 @param NbufQue Pointer to the net buffer queue.
1272 @param Len Length of the data to trim.
1274 @retval UINTN The length of the data trimmed.
1280 IN NET_BUF_QUEUE
*NbufQue
,
1286 Flush the net buffer queue.
1288 @param NbufQue Pointer to the queue to be flushed.
1296 IN NET_BUF_QUEUE
*NbufQue
1300 Compute checksum for a bulk of data.
1302 @param Bulk Pointer to the data.
1303 @param Len Length of the data, in bytes.
1305 @retval UINT16 The computed checksum.
1318 @param Checksum1 The first checksum to be added.
1319 @param Checksum2 The second checksum to be added.
1321 @retval UINT16 The new checksum.
1327 IN UINT16 Checksum1
,
1332 Compute the checksum for a NET_BUF.
1334 @param Nbuf Pointer to the net buffer.
1336 @retval UINT16 The computed checksum.
1346 Compute the checksum for TCP/UDP pseudo header.
1347 Src, Dst are in network byte order. and Len is
1350 @param Src The source address of the packet.
1351 @param Dst The destination address of the packet.
1352 @param Proto The protocol type of the packet.
1353 @param Len The length of the packet.
1355 @retval UINT16 The computed checksum.
1360 NetPseudoHeadChecksum (