TianoCore EDK2 master
Loading...
Searching...
No Matches
NetLib.h
Go to the documentation of this file.
1
11#ifndef _NET_LIB_H_
12#define _NET_LIB_H_
13
14#include <Protocol/Ip6.h>
15
16#include <Library/BaseLib.h>
18
19typedef UINT32 IP4_ADDR;
20typedef UINT32 TCP_SEQNO;
21typedef UINT16 TCP_PORTNO;
22
23#define NET_ETHER_ADDR_LEN 6
24#define NET_IFTYPE_ETHERNET 0x01
25
26#define NET_VLAN_TAG_LEN 4
27#define ETHER_TYPE_VLAN 0x8100
28
29#define EFI_IP_PROTO_UDP 0x11
30#define EFI_IP_PROTO_TCP 0x06
31#define EFI_IP_PROTO_ICMP 0x01
32#define IP4_PROTO_IGMP 0x02
33#define IP6_ICMP 58
34#define DNS_MAX_NAME_SIZE 255
35#define DNS_MAX_MESSAGE_SIZE 512
36
37//
38// The address classification
39//
40#define IP4_ADDR_CLASSA 1 // Deprecated
41#define IP4_ADDR_CLASSB 2 // Deprecated
42#define IP4_ADDR_CLASSC 3 // Deprecated
43#define IP4_ADDR_CLASSD 4
44#define IP4_ADDR_CLASSE 5
45
46#define IP4_MASK_NUM 33
47#define IP6_PREFIX_NUM 129
48
49#define IP4_MASK_MAX 32
50#define IP6_PREFIX_MAX 128
51
52#define IP6_HOP_BY_HOP 0
53#define IP6_DESTINATION 60
54#define IP6_ROUTING 43
55#define IP6_FRAGMENT 44
56#define IP6_AH 51
57#define IP6_ESP 50
58#define IP6_NO_NEXT_HEADER 59
59
60#define IP_VERSION_4 4
61#define IP_VERSION_6 6
62
63#define IP6_PREFIX_LENGTH 64
64
65//
66// DNS QTYPE values
67//
68#define DNS_TYPE_A 1
69#define DNS_TYPE_NS 2
70#define DNS_TYPE_CNAME 5
71#define DNS_TYPE_SOA 6
72#define DNS_TYPE_WKS 11
73#define DNS_TYPE_PTR 12
74#define DNS_TYPE_HINFO 13
75#define DNS_TYPE_MINFO 14
76#define DNS_TYPE_MX 15
77#define DNS_TYPE_TXT 16
78#define DNS_TYPE_AAAA 28
79#define DNS_TYPE_SRV_RR 33
80#define DNS_TYPE_AXFR 252
81#define DNS_TYPE_MAILB 253
82#define DNS_TYPE_ANY 255
83
84//
85// DNS QCLASS values
86//
87#define DNS_CLASS_INET 1
88#define DNS_CLASS_CH 3
89#define DNS_CLASS_HS 4
90#define DNS_CLASS_ANY 255
91
92//
93// Number of 100ns units time Interval for network media state detect
94//
95#define MEDIA_STATE_DETECT_TIME_INTERVAL 1000000U
96
97#pragma pack(1)
98
99//
100// Ethernet head definition
101//
102typedef struct {
103 UINT8 DstMac[NET_ETHER_ADDR_LEN];
104 UINT8 SrcMac[NET_ETHER_ADDR_LEN];
105 UINT16 EtherType;
106} ETHER_HEAD;
107
108//
109// 802.1Q VLAN Tag Control Information
110//
111typedef union {
112 struct {
113 UINT16 Vid : 12; // Unique VLAN identifier (0 to 4094)
114 UINT16 Cfi : 1; // Canonical Format Indicator
115 UINT16 Priority : 3; // 802.1Q priority level (0 to 7)
116 } Bits;
117 UINT16 Uint16;
118} VLAN_TCI;
119
120#define VLAN_TCI_CFI_CANONICAL_MAC 0
121#define VLAN_TCI_CFI_NON_CANONICAL_MAC 1
122
123//
124// The EFI_IP4_HEADER is hard to use because the source and
125// destination address are defined as EFI_IPv4_ADDRESS, which
126// is a structure. Two structures can't be compared or masked
127// directly. This is why there is an internal representation.
128//
129typedef struct {
130 UINT8 HeadLen : 4;
131 UINT8 Ver : 4;
132 UINT8 Tos;
133 UINT16 TotalLen;
134 UINT16 Id;
135 UINT16 Fragment;
136 UINT8 Ttl;
137 UINT8 Protocol;
138 UINT16 Checksum;
139 IP4_ADDR Src;
140 IP4_ADDR Dst;
141} IP4_HEAD;
142
143//
144// ICMP head definition. Each ICMP message is categorized as either an error
145// message or query message. Two message types have their own head format.
146//
147typedef struct {
148 UINT8 Type;
149 UINT8 Code;
150 UINT16 Checksum;
152
153typedef struct {
154 IP4_ICMP_HEAD Head;
155 UINT32 Fourth; // 4th filed of the head, it depends on Type.
156 IP4_HEAD IpHead;
158
159typedef struct {
160 IP4_ICMP_HEAD Head;
161 UINT16 Id;
162 UINT16 Seq;
164
165typedef struct {
166 UINT8 Type;
167 UINT8 Code;
168 UINT16 Checksum;
170
171typedef struct {
172 IP6_ICMP_HEAD Head;
173 UINT32 Fourth;
174 EFI_IP6_HEADER IpHead;
176
177typedef struct {
178 IP6_ICMP_HEAD Head;
179 UINT32 Fourth;
181
182//
183// UDP header definition
184//
185typedef struct {
186 UINT16 SrcPort;
187 UINT16 DstPort;
188 UINT16 Length;
189 UINT16 Checksum;
191
192//
193// TCP header definition
194//
195typedef struct {
196 TCP_PORTNO SrcPort;
197 TCP_PORTNO DstPort;
198 TCP_SEQNO Seq;
199 TCP_SEQNO Ack;
200 UINT8 Res : 4;
201 UINT8 HeadLen : 4;
202 UINT8 Flag;
203 UINT16 Wnd;
204 UINT16 Checksum;
205 UINT16 Urg;
206} TCP_HEAD;
207
208#pragma pack()
209
210#define NET_MAC_EQUAL(pMac1, pMac2, Len) \
211 (CompareMem ((pMac1), (pMac2), Len) == 0)
212
213#define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \
214 (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))
215
216#define NTOHL(x) SwapBytes32 (x)
217
218#define HTONL(x) NTOHL(x)
219
220#define NTOHS(x) SwapBytes16 (x)
221
222#define HTONS(x) NTOHS(x)
223#define NTOHLL(x) SwapBytes64 (x)
224#define HTONLL(x) NTOHLL(x)
225#define NTOHLLL(x) Ip6Swap128 (x)
226#define HTONLLL(x) NTOHLLL(x)
227
228//
229// Test the IP's attribute, All the IPs are in host byte order.
230//
231#define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)
232#define IP4_IS_UNSPECIFIED(Ip) ((Ip) == 0)
233#define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)
234#define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))
235#define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != (IP4_MASK_MAX + 1))
236
237#define IP6_IS_MULTICAST(Ip6) (((Ip6)->Addr[0]) == 0xFF)
238
239//
240// Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.
241//
242#define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))
243#define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))
244#define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)
245
246#define EFI_IP6_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv6_ADDRESS)) == 0)
247
248#define IP4_COPY_ADDRESS(Dest, Src) (CopyMem ((Dest), (Src), sizeof (EFI_IPv4_ADDRESS)))
249#define IP6_COPY_ADDRESS(Dest, Src) (CopyMem ((Dest), (Src), sizeof (EFI_IPv6_ADDRESS)))
250#define IP6_COPY_LINK_ADDRESS(Mac1, Mac2) (CopyMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)))
251
252//
253// The debug level definition. This value is also used as the
254// syslog's severity level. Don't change it.
255//
256#define NETDEBUG_LEVEL_TRACE 5
257#define NETDEBUG_LEVEL_WARNING 4
258#define NETDEBUG_LEVEL_ERROR 3
259
260//
261// Network debug message is sent out as syslog packet.
262//
263#define NET_SYSLOG_FACILITY 16 // Syslog local facility local use
264#define NET_SYSLOG_PACKET_LEN 512
265#define NET_SYSLOG_TX_TIMEOUT (500 * 1000 * 10) // 500ms
266#define NET_DEBUG_MSG_LEN 470 // 512 - (ether+ip4+udp4 head length)
267
268//
269// The debug output expects the ASCII format string, Use %a to print ASCII
270// string, and %s to print UNICODE string. PrintArg must be enclosed in ().
271// For example: NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name));
272//
273#define NET_DEBUG_TRACE(Module, PrintArg) \
274 NetDebugOutput ( \
275 NETDEBUG_LEVEL_TRACE, \
276 Module, \
277 __FILE__, \
278 DEBUG_LINE_NUMBER, \
279 NetDebugASPrint PrintArg \
280 )
281
282#define NET_DEBUG_WARNING(Module, PrintArg) \
283 NetDebugOutput ( \
284 NETDEBUG_LEVEL_WARNING, \
285 Module, \
286 __FILE__, \
287 DEBUG_LINE_NUMBER, \
288 NetDebugASPrint PrintArg \
289 )
290
291#define NET_DEBUG_ERROR(Module, PrintArg) \
292 NetDebugOutput ( \
293 NETDEBUG_LEVEL_ERROR, \
294 Module, \
295 __FILE__, \
296 DEBUG_LINE_NUMBER, \
297 NetDebugASPrint PrintArg \
298 )
299
324CHAR8 *
325EFIAPI
327 IN CHAR8 *Format,
328 ...
329 );
330
349EFIAPI
351 IN UINT32 Level,
352 IN UINT8 *Module,
353 IN UINT8 *File,
354 IN UINT32 Line,
355 IN UINT8 *Message
356 );
357
370INTN
371EFIAPI
373 IN IP4_ADDR NetMask
374 );
375
402INTN
403EFIAPI
405 IN IP4_ADDR Addr
406 );
407
425BOOLEAN
426EFIAPI
428 IN IP4_ADDR Ip,
429 IN IP4_ADDR NetMask
430 );
431
448BOOLEAN
449EFIAPI
452 );
453
465BOOLEAN
466EFIAPI
469 );
470
482BOOLEAN
483EFIAPI
486 );
487
502BOOLEAN
503EFIAPI
505 EFI_IPv6_ADDRESS *Ip1,
506 EFI_IPv6_ADDRESS *Ip2,
507 UINT8 PrefixLength
508 );
509
525EFIAPI
528 );
529
530extern IP4_ADDR gIp4AllMasks[IP4_MASK_NUM];
531
532extern EFI_IPv4_ADDRESS mZeroIp4Addr;
533
534#define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))
535#define NET_IS_HEX(Ch) ((('0' <= (Ch)) && ((Ch) <= '9')) || (('A' <= (Ch)) && ((Ch) <= 'F')) || (('a' <= (Ch)) && ((Ch) <= 'f')))
536#define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))
537#define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))
538#define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))
539
540#define TICKS_PER_MS 10000U
541#define TICKS_PER_SECOND 10000000U
542
556UINT32
557EFIAPI
559 IN UINT8 *Buf
560 );
561
574VOID
575EFIAPI
577 IN OUT UINT8 *Buf,
578 IN UINT32 Data
579 );
580
595EFIAPI
597 OUT VOID *Output,
598 IN UINTN OutputLength
599 );
600
613EFIAPI
615 OUT UINT32 *Output
616 );
617
618#define NET_LIST_USER_STRUCT(Entry, Type, Field) \
619 BASE_CR(Entry, Type, Field)
620
621#define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \
622 CR(Entry, Type, Field, Sig)
623
624//
625// Iterate through the double linked list. It is NOT delete safe
626//
627#define NET_LIST_FOR_EACH(Entry, ListHead) \
628 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
629
630//
631// Iterate through the double linked list. This is delete-safe.
632// Don't touch NextEntry. Also, don't use this macro if list
633// entries other than the Entry may be deleted when processing
634// the current Entry.
635//
636#define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
637 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
638 Entry != (ListHead); \
639 Entry = NextEntry, NextEntry = Entry->ForwardLink \
640 )
641
642//
643// Make sure the list isn't empty before getting the first/last record.
644//
645#define NET_LIST_HEAD(ListHead, Type, Field) \
646 NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)
647
648#define NET_LIST_TAIL(ListHead, Type, Field) \
649 NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)
650
670EFIAPI
672 IN OUT LIST_ENTRY *Head
673 );
674
694EFIAPI
696 IN OUT LIST_ENTRY *Head
697 );
698
711VOID
712EFIAPI
714 IN OUT LIST_ENTRY *PrevEntry,
715 IN OUT LIST_ENTRY *NewEntry
716 );
717
730VOID
731EFIAPI
733 IN OUT LIST_ENTRY *PostEntry,
734 IN OUT LIST_ENTRY *NewEntry
735 );
736
747typedef
750 IN LIST_ENTRY *Entry,
751 IN VOID *Context OPTIONAL
752 );
753
777EFIAPI
779 IN LIST_ENTRY *List,
781 IN VOID *Context OPTIONAL,
782 OUT UINTN *ListLength OPTIONAL
783 );
784
797BOOLEAN
798EFIAPI
800 IN EFI_HANDLE Handle,
801 IN UINTN NumberOfChildren,
802 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
803 );
804
805//
806// Object container: EFI network stack spec defines various kinds of
807// tokens. The drivers can share code to manage those objects.
808//
809typedef struct {
810 LIST_ENTRY Link;
811 VOID *Key;
812 VOID *Value;
814
815typedef struct {
816 LIST_ENTRY Used;
817 LIST_ENTRY Recycled;
818 UINTN Count;
819} NET_MAP;
820
821#define NET_MAP_INCREAMENT 64
822
837VOID
838EFIAPI
840 IN OUT NET_MAP *Map
841 );
842
855VOID
856EFIAPI
858 IN OUT NET_MAP *Map
859 );
860
873BOOLEAN
874EFIAPI
876 IN NET_MAP *Map
877 );
878
889UINTN
890EFIAPI
892 IN NET_MAP *Map
893 );
894
914EFIAPI
916 IN OUT NET_MAP *Map,
917 IN VOID *Key,
918 IN VOID *Value OPTIONAL
919 );
920
940EFIAPI
942 IN OUT NET_MAP *Map,
943 IN VOID *Key,
944 IN VOID *Value OPTIONAL
945 );
946
963EFIAPI
965 IN NET_MAP *Map,
966 IN VOID *Key
967 );
968
988VOID *
989EFIAPI
991 IN OUT NET_MAP *Map,
992 IN OUT NET_MAP_ITEM *Item,
993 OUT VOID **Value OPTIONAL
994 );
995
1013VOID *
1014EFIAPI
1016 IN OUT NET_MAP *Map,
1017 OUT VOID **Value OPTIONAL
1018 );
1019
1037VOID *
1038EFIAPI
1040 IN OUT NET_MAP *Map,
1041 OUT VOID **Value OPTIONAL
1042 );
1043
1044typedef
1046(EFIAPI *NET_MAP_CALLBACK)(
1047 IN NET_MAP *Map,
1048 IN NET_MAP_ITEM *Item,
1049 IN VOID *Arg
1050 );
1051
1072EFIAPI
1074 IN NET_MAP *Map,
1075 IN NET_MAP_CALLBACK CallBack,
1076 IN VOID *Arg OPTIONAL
1077 );
1078
1079//
1080// Helper functions to implement driver binding and service binding protocols.
1081//
1082
1101EFIAPI
1103 IN EFI_HANDLE Controller,
1104 IN EFI_HANDLE Image,
1105 IN EFI_GUID *ServiceBindingGuid,
1106 IN OUT EFI_HANDLE *ChildHandle
1107 );
1108
1126EFIAPI
1128 IN EFI_HANDLE Controller,
1129 IN EFI_HANDLE Image,
1130 IN EFI_GUID *ServiceBindingGuid,
1131 IN EFI_HANDLE ChildHandle
1132 );
1133
1151EFIAPI
1153 IN EFI_HANDLE ServiceHandle,
1154 OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL
1155 );
1156
1170UINT16
1171EFIAPI
1173 IN EFI_HANDLE ServiceHandle
1174 );
1175
1191EFIAPI
1193 IN EFI_HANDLE ControllerHandle,
1194 IN UINT16 VlanId
1195 );
1196
1217EFIAPI
1219 IN EFI_HANDLE ServiceHandle,
1220 OUT EFI_MAC_ADDRESS *MacAddress,
1221 OUT UINTN *AddressSize
1222 );
1223
1249EFIAPI
1251 IN EFI_HANDLE ServiceHandle,
1252 IN EFI_HANDLE ImageHandle OPTIONAL,
1253 OUT CHAR16 **MacString
1254 );
1255
1287EFIAPI
1289 IN EFI_HANDLE ServiceHandle,
1290 OUT BOOLEAN *MediaPresent
1291 );
1292
1318EFIAPI
1320 IN EFI_HANDLE ServiceHandle,
1321 IN UINT64 Timeout,
1322 OUT EFI_STATUS *MediaState
1323 );
1324
1345VOID
1346EFIAPI
1348 IN OUT IPv4_DEVICE_PATH *Node,
1349 IN EFI_HANDLE Controller,
1350 IN IP4_ADDR LocalIp,
1351 IN UINT16 LocalPort,
1352 IN IP4_ADDR RemoteIp,
1353 IN UINT16 RemotePort,
1354 IN UINT16 Protocol,
1355 IN BOOLEAN UseDefaultAddress
1356 );
1357
1379VOID
1380EFIAPI
1382 IN OUT IPv6_DEVICE_PATH *Node,
1383 IN EFI_HANDLE Controller,
1384 IN EFI_IPv6_ADDRESS *LocalIp,
1385 IN UINT16 LocalPort,
1386 IN EFI_IPv6_ADDRESS *RemoteIp,
1387 IN UINT16 RemotePort,
1388 IN UINT16 Protocol
1389 );
1390
1411EFIAPI
1413 IN EFI_HANDLE Controller,
1414 IN EFI_GUID *ProtocolGuid
1415 );
1416
1430EFIAPI
1432 IN EFI_HANDLE ImageHandle
1433 );
1434
1446EFIAPI
1448 IN CONST CHAR8 *String,
1449 OUT EFI_IPv4_ADDRESS *Ip4Address
1450 );
1451
1464EFIAPI
1466 IN CONST CHAR8 *String,
1467 OUT EFI_IPv6_ADDRESS *Ip6Address
1468 );
1469
1481EFIAPI
1483 IN CONST CHAR16 *String,
1484 OUT EFI_IPv4_ADDRESS *Ip4Address
1485 );
1486
1499EFIAPI
1501 IN CONST CHAR16 *String,
1502 OUT EFI_IPv6_ADDRESS *Ip6Address
1503 );
1504
1519EFIAPI
1521 IN CONST CHAR16 *String,
1522 OUT EFI_IPv6_ADDRESS *Ip6Address,
1523 OUT UINT8 *PrefixLength
1524 );
1525
1541EFIAPI
1543 IN EFI_IPv6_ADDRESS *Ip6Address,
1544 OUT CHAR16 *String,
1545 IN UINTN StringSize
1546 );
1547
1548//
1549// Various signatures
1550//
1551#define NET_BUF_SIGNATURE SIGNATURE_32 ('n', 'b', 'u', 'f')
1552#define NET_VECTOR_SIGNATURE SIGNATURE_32 ('n', 'v', 'e', 'c')
1553#define NET_QUE_SIGNATURE SIGNATURE_32 ('n', 'b', 'q', 'u')
1554
1555#define NET_PROTO_DATA 64 // Opaque buffer for protocols
1556#define NET_BUF_HEAD 1 // Trim or allocate space from head
1557#define NET_BUF_TAIL 0 // Trim or allocate space from tail
1558#define NET_VECTOR_OWN_FIRST 0x01 // We allocated the 1st block in the vector
1559
1560#define NET_CHECK_SIGNATURE(PData, SIGNATURE) \
1561 ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))
1562
1563//
1564// Single memory block in the vector.
1565//
1566typedef struct {
1567 UINT32 Len; // The block's length
1568 UINT8 *Bulk; // The block's Data
1569} NET_BLOCK;
1570
1571typedef VOID (EFIAPI *NET_VECTOR_EXT_FREE)(VOID *Arg);
1572
1573//
1574// NET_VECTOR contains several blocks to hold all packet's
1575// fragments and other house-keeping stuff for sharing. It
1576// doesn't specify the where actual packet fragment begins.
1577//
1578typedef struct {
1579 UINT32 Signature;
1580 INTN RefCnt; // Reference count to share NET_VECTOR.
1581 NET_VECTOR_EXT_FREE Free; // external function to free NET_VECTOR
1582 VOID *Arg; // opaque argument to Free
1583 UINT32 Flag; // Flags, NET_VECTOR_OWN_FIRST
1584 UINT32 Len; // Total length of the associated BLOCKs
1585
1586 UINT32 BlockNum;
1587 NET_BLOCK Block[1];
1588} NET_VECTOR;
1589
1590//
1591// NET_BLOCK_OP operates on the NET_BLOCK. It specifies
1592// where the actual fragment begins and ends
1593//
1594typedef struct {
1595 UINT8 *BlockHead; // Block's head, or the smallest valid Head
1596 UINT8 *BlockTail; // Block's tail. BlockTail-BlockHead=block length
1597 UINT8 *Head; // 1st byte of the data in the block
1598 UINT8 *Tail; // Tail of the data in the block, Tail-Head=Size
1599 UINT32 Size; // The size of the data
1600} NET_BLOCK_OP;
1601
1602typedef union {
1603 IP4_HEAD *Ip4;
1604 EFI_IP6_HEADER *Ip6;
1605} NET_IP_HEAD;
1606
1607//
1608// NET_BUF is the buffer manage structure used by the
1609// network stack. Every network packet may be fragmented. The Vector points to
1610// memory blocks used by each fragment, and BlockOp
1611// specifies where each fragment begins and ends.
1612//
1613// It also contains an opaque area for the protocol to store
1614// per-packet information. Protocol must be careful not
1615// to overwrite the members after that.
1616//
1617typedef struct {
1618 UINT32 Signature;
1619 INTN RefCnt;
1620 LIST_ENTRY List; // The List this NET_BUF is on
1621
1622 NET_IP_HEAD Ip; // Network layer header, for fast access
1623 TCP_HEAD *Tcp; // Transport layer header, for fast access
1624 EFI_UDP_HEADER *Udp; // User Datagram Protocol header
1625 UINT8 ProtoData[NET_PROTO_DATA]; // Protocol specific data
1626
1627 NET_VECTOR *Vector; // The vector containing the packet
1628
1629 UINT32 BlockOpNum; // Total number of BlockOp in the buffer
1630 UINT32 TotalSize; // Total size of the actual packet
1631 NET_BLOCK_OP BlockOp[1]; // Specify the position of actual packet
1632} NET_BUF;
1633
1634//
1635// A queue of NET_BUFs. It is a thin extension of
1636// NET_BUF functions.
1637//
1638typedef struct {
1639 UINT32 Signature;
1640 INTN RefCnt;
1641 LIST_ENTRY List; // The List this buffer queue is on
1642
1643 LIST_ENTRY BufList; // list of queued buffers
1644 UINT32 BufSize; // total length of DATA in the buffers
1645 UINT32 BufNum; // total number of buffers on the chain
1647
1648//
1649// Pseudo header for TCP and UDP checksum
1650//
1651#pragma pack(1)
1652typedef struct {
1653 IP4_ADDR SrcIp;
1654 IP4_ADDR DstIp;
1655 UINT8 Reserved;
1656 UINT8 Protocol;
1657 UINT16 Len;
1659
1660typedef struct {
1661 EFI_IPv6_ADDRESS SrcIp;
1662 EFI_IPv6_ADDRESS DstIp;
1663 UINT32 Len;
1664 UINT32 Reserved : 24;
1665 UINT32 NextHeader : 8;
1667#pragma pack()
1668
1669//
1670// The fragment entry table used in network interfaces. This is
1671// the same as NET_BLOCK now. Use two different to distinguish
1672// the two in case that NET_BLOCK be enhanced later.
1673//
1674typedef struct {
1675 UINT32 Len;
1676 UINT8 *Bulk;
1677} NET_FRAGMENT;
1678
1679#define NET_GET_REF(PData) ((PData)->RefCnt++)
1680#define NET_PUT_REF(PData) ((PData)->RefCnt--)
1681#define NETBUF_FROM_PROTODATA(Info) BASE_CR((Info), NET_BUF, ProtoData)
1682
1683#define NET_BUF_SHARED(Buf) \
1684 (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))
1685
1686#define NET_VECTOR_SIZE(BlockNum) \
1687 (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))
1688
1689#define NET_BUF_SIZE(BlockOpNum) \
1690 (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))
1691
1692#define NET_HEADSPACE(BlockOp) \
1693 ((UINTN)((BlockOp)->Head) - (UINTN)((BlockOp)->BlockHead))
1694
1695#define NET_TAILSPACE(BlockOp) \
1696 ((UINTN)((BlockOp)->BlockTail) - (UINTN)((BlockOp)->Tail))
1697
1708NET_BUF *
1709EFIAPI
1711 IN UINT32 Len
1712 );
1713
1726VOID
1727EFIAPI
1728NetbufFree (
1729 IN NET_BUF *Nbuf
1730 );
1731
1749UINT8 *
1750EFIAPI
1752 IN NET_BUF *Nbuf,
1753 IN UINT32 Offset,
1754 OUT UINT32 *Index OPTIONAL
1755 );
1756
1769NET_BUF *
1770EFIAPI
1772 IN NET_BUF *Nbuf
1773 );
1774
1791NET_BUF *
1792EFIAPI
1794 IN NET_BUF *Nbuf,
1795 IN OUT NET_BUF *Duplicate OPTIONAL,
1796 IN UINT32 HeadSpace
1797 );
1798
1816NET_BUF *
1817EFIAPI
1819 IN NET_BUF *Nbuf,
1820 IN UINT32 Offset,
1821 IN UINT32 Len,
1822 IN UINT32 HeadSpace
1823 );
1824
1837VOID
1838EFIAPI
1840 IN OUT NET_BUF *Nbuf,
1841 IN UINT32 Len
1842 );
1843
1856UINT8 *
1857EFIAPI
1859 IN OUT NET_BUF *Nbuf,
1860 IN UINT32 Len,
1861 IN BOOLEAN FromHead
1862 );
1863
1876UINT32
1877EFIAPI
1878NetbufTrim (
1879 IN OUT NET_BUF *Nbuf,
1880 IN UINT32 Len,
1881 IN BOOLEAN FromHead
1882 );
1883
1899UINT32
1900EFIAPI
1901NetbufCopy (
1902 IN NET_BUF *Nbuf,
1903 IN UINT32 Offset,
1904 IN UINT32 Len,
1905 IN UINT8 *Dest
1906 );
1907
1930NET_BUF *
1931EFIAPI
1933 IN NET_FRAGMENT *ExtFragment,
1934 IN UINT32 ExtNum,
1935 IN UINT32 HeadSpace,
1936 IN UINT32 HeadLen,
1937 IN NET_VECTOR_EXT_FREE ExtFree,
1938 IN VOID *Arg OPTIONAL
1939 );
1940
1955EFIAPI
1957 IN NET_BUF *Nbuf,
1958 IN OUT NET_FRAGMENT *ExtFragment,
1959 IN OUT UINT32 *ExtNum
1960 );
1961
1979NET_BUF *
1980EFIAPI
1982 IN LIST_ENTRY *BufList,
1983 IN UINT32 HeadSpace,
1984 IN UINT32 HeaderLen,
1985 IN NET_VECTOR_EXT_FREE ExtFree,
1986 IN VOID *Arg OPTIONAL
1987 );
1988
1995VOID
1996EFIAPI
1998 IN OUT LIST_ENTRY *Head
1999 );
2000
2007VOID
2008EFIAPI
2010 IN OUT NET_BUF_QUEUE *NbufQue
2011 );
2012
2021EFIAPI
2023 VOID
2024 );
2025
2036VOID
2037EFIAPI
2039 IN NET_BUF_QUEUE *NbufQue
2040 );
2041
2051NET_BUF *
2052EFIAPI
2054 IN OUT NET_BUF_QUEUE *NbufQue
2055 );
2056
2064VOID
2065EFIAPI
2067 IN OUT NET_BUF_QUEUE *NbufQue,
2068 IN OUT NET_BUF *Nbuf
2069 );
2070
2087UINT32
2088EFIAPI
2090 IN NET_BUF_QUEUE *NbufQue,
2091 IN UINT32 Offset,
2092 IN UINT32 Len,
2093 OUT UINT8 *Dest
2094 );
2095
2109UINT32
2110EFIAPI
2112 IN OUT NET_BUF_QUEUE *NbufQue,
2113 IN UINT32 Len
2114 );
2115
2122VOID
2123EFIAPI
2125 IN OUT NET_BUF_QUEUE *NbufQue
2126 );
2127
2137UINT16
2138EFIAPI
2140 IN UINT8 *Bulk,
2141 IN UINT32 Len
2142 );
2143
2153UINT16
2154EFIAPI
2156 IN UINT16 Checksum1,
2157 IN UINT16 Checksum2
2158 );
2159
2168UINT16
2169EFIAPI
2171 IN NET_BUF *Nbuf
2172 );
2173
2187UINT16
2188EFIAPI
2190 IN IP4_ADDR Src,
2191 IN IP4_ADDR Dst,
2192 IN UINT8 Proto,
2193 IN UINT16 Len
2194 );
2195
2209UINT16
2210EFIAPI
2212 IN EFI_IPv6_ADDRESS *Src,
2213 IN EFI_IPv6_ADDRESS *Dst,
2214 IN UINT8 NextHeader,
2215 IN UINT32 Len
2216 );
2217
2229VOID
2231 NET_BUF *Nbuf
2232 );
2233
2246EFIAPI
2248 OUT EFI_GUID *SystemGuid
2249 );
2250
2268CHAR8 *
2269EFIAPI
2271 IN CHAR16 *DomainName
2272 );
2273
2274#endif
UINT64 UINTN
INT64 INTN
#define CONST
Definition: Base.h:259
#define OPTIONAL
Definition: Base.h:290
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
Definition: NetBuffer.c:195
VOID EFIAPI NetbufQueInit(IN OUT NET_BUF_QUEUE *NbufQue)
Definition: NetBuffer.c:1300
VOID *EFIAPI NetMapRemoveTail(IN OUT NET_MAP *Map, OUT VOID **Value OPTIONAL)
Definition: DxeNetLib.c:1754
VOID EFIAPI NetbufReserve(IN OUT NET_BUF *Nbuf, IN UINT32 Len)
Definition: NetBuffer.c:984
LIST_ENTRY *EFIAPI NetListRemoveHead(IN OUT LIST_ENTRY *Head)
Definition: DxeNetLib.c:1090
UINT16 EFIAPI NetIp6PseudoHeadChecksum(IN EFI_IPv6_ADDRESS *Src, IN EFI_IPv6_ADDRESS *Dst, IN UINT8 NextHeader, IN UINT32 Len)
Definition: NetBuffer.c:1777
LIST_ENTRY *EFIAPI NetListRemoveTail(IN OUT LIST_ENTRY *Head)
Definition: DxeNetLib.c:1134
NET_BUF *EFIAPI NetbufClone(IN NET_BUF *Nbuf)
Definition: NetBuffer.c:229
UINT32 EFIAPI NetbufTrim(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
Definition: NetBuffer.c:1134
UINT16 EFIAPI NetbufChecksum(IN NET_BUF *Nbuf)
Definition: NetBuffer.c:1687
EFI_STATUS EFIAPI NetLibGetMacAddress(IN EFI_HANDLE ServiceHandle, OUT EFI_MAC_ADDRESS *MacAddress, OUT UINTN *AddressSize)
Definition: DxeNetLib.c:2251
EFI_STATUS EFIAPI NetbufBuildExt(IN NET_BUF *Nbuf, IN OUT NET_FRAGMENT *ExtFragment, IN OUT UINT32 *ExtNum)
Definition: NetBuffer.c:866
UINT32 EFIAPI NetbufQueTrim(IN OUT NET_BUF_QUEUE *NbufQue, IN UINT32 Len)
Definition: NetBuffer.c:1537
EFI_STATUS EFIAPI NetLibGetMacString(IN EFI_HANDLE ServiceHandle, IN EFI_HANDLE ImageHandle OPTIONAL, OUT CHAR16 **MacString)
Definition: DxeNetLib.c:2363
UINT16 EFIAPI NetblockChecksum(IN UINT8 *Bulk, IN UINT32 Len)
Definition: NetBuffer.c:1615
UINT32 EFIAPI NetbufQueCopy(IN NET_BUF_QUEUE *NbufQue, IN UINT32 Offset, IN UINT32 Len, OUT UINT8 *Dest)
Definition: NetBuffer.c:1438
BOOLEAN EFIAPI NetIp4IsUnicast(IN IP4_ADDR Ip, IN IP4_ADDR NetMask)
Definition: DxeNetLib.c:683
BOOLEAN EFIAPI NetIp6IsValidUnicast(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:725
VOID EFIAPI NetMapClean(IN OUT NET_MAP *Map)
Definition: DxeNetLib.c:1368
VOID EFIAPI NetbufQueFlush(IN OUT NET_BUF_QUEUE *NbufQue)
Definition: NetBuffer.c:1592
EFI_HANDLE EFIAPI NetLibGetVlanHandle(IN EFI_HANDLE ControllerHandle, IN UINT16 VlanId)
Definition: DxeNetLib.c:2180
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
Definition: DxeNetLib.c:1967
UINT32 EFIAPI NetbufCopy(IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT8 *Dest)
Definition: NetBuffer.c:1206
VOID EFIAPI NetLibCreateIPv6DPathNode(IN OUT IPv6_DEVICE_PATH *Node, IN EFI_HANDLE Controller, IN EFI_IPv6_ADDRESS *LocalIp, IN UINT16 LocalPort, IN EFI_IPv6_ADDRESS *RemoteIp, IN UINT16 RemotePort, IN UINT16 Protocol)
Definition: DxeNetLib.c:2965
EFI_STATUS EFIAPI NetLibAsciiStrToIp4(IN CONST CHAR8 *String, OUT EFI_IPv4_ADDRESS *Ip4Address)
Definition: DxeNetLib.c:3068
CHAR8 *EFIAPI NetLibCreateDnsQName(IN CHAR16 *DomainName)
Definition: DxeNetLib.c:3424
BOOLEAN EFIAPI NetIp6IsNetEqual(EFI_IPv6_ADDRESS *Ip1, EFI_IPv6_ADDRESS *Ip2, UINT8 PrefixLength)
Definition: DxeNetLib.c:837
NET_MAP_ITEM *EFIAPI NetMapFindKey(IN NET_MAP *Map, IN VOID *Key)
Definition: DxeNetLib.c:1629
EFI_STATUS EFIAPI NetMapInsertHead(IN OUT NET_MAP *Map, IN VOID *Key, IN VOID *Value OPTIONAL)
Definition: DxeNetLib.c:1512
BOOLEAN EFIAPI NetIp6IsLinkLocalAddr(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:796
EFI_IPv6_ADDRESS *EFIAPI Ip6Swap128(EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:892
UINT16 EFIAPI NetAddChecksum(IN UINT16 Checksum1, IN UINT16 Checksum2)
Definition: NetBuffer.c:1658
NET_BUF_QUEUE *EFIAPI NetbufQueAlloc(VOID)
Definition: NetBuffer.c:1322
VOID EFIAPI NetListInsertAfter(IN OUT LIST_ENTRY *PrevEntry, IN OUT LIST_ENTRY *NewEntry)
Definition: DxeNetLib.c:1172
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
Definition: DxeNetLib.c:2020
NET_BUF *EFIAPI NetbufAlloc(IN UINT32 Len)
Definition: NetBuffer.c:89
VOID EFIAPI NetMapInit(IN OUT NET_MAP *Map)
Definition: DxeNetLib.c:1343
NET_BUF *EFIAPI NetbufGetFragment(IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT32 HeadSpace)
Definition: NetBuffer.c:510
NET_BUF *EFIAPI NetbufFromExt(IN NET_FRAGMENT *ExtFragment, IN UINT32 ExtNum, IN UINT32 HeadSpace, IN UINT32 HeadLen, IN NET_VECTOR_EXT_FREE ExtFree, IN VOID *Arg OPTIONAL)
Definition: NetBuffer.c:693
EFI_STATUS EFIAPI NetLibDetectMedia(IN EFI_HANDLE ServiceHandle, OUT BOOLEAN *MediaPresent)
Definition: DxeNetLib.c:2472
UINT32 EFIAPI NetGetUint32(IN UINT8 *Buf)
Definition: DxeNetLib.c:1033
CHAR8 *EFIAPI NetDebugASPrint(IN CHAR8 *Format,...)
Definition: DxeNetLib.c:481
VOID EFIAPI NetLibCreateIPv4DPathNode(IN OUT IPv4_DEVICE_PATH *Node, IN EFI_HANDLE Controller, IN IP4_ADDR LocalIp, IN UINT16 LocalPort, IN IP4_ADDR RemoteIp, IN UINT16 RemotePort, IN UINT16 Protocol, IN BOOLEAN UseDefaultAddress)
Definition: DxeNetLib.c:2903
EFI_STATUS EFIAPI NetLibDefaultUnload(IN EFI_HANDLE ImageHandle)
Definition: DxeNetLib.c:1846
NET_BUF *EFIAPI NetbufFromBufList(IN LIST_ENTRY *BufList, IN UINT32 HeadSpace, IN UINT32 HeaderLen, IN NET_VECTOR_EXT_FREE ExtFree, IN VOID *Arg OPTIONAL)
Definition: NetBuffer.c:914
BOOLEAN EFIAPI NetIsInHandleBuffer(IN EFI_HANDLE Handle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: DxeNetLib.c:1306
BOOLEAN EFIAPI NetIp6IsUnspecifiedAddr(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:766
VOID EFIAPI NetPutUint32(IN OUT UINT8 *Buf, IN UINT32 Data)
Definition: DxeNetLib.c:1059
EFI_STATUS EFIAPI NetLibDetectMediaWaitTimeout(IN EFI_HANDLE ServiceHandle, IN UINT64 Timeout, OUT EFI_STATUS *MediaState)
Definition: DxeNetLib.c:2683
EFI_STATUS EFIAPI NetLibGetSystemGuid(OUT EFI_GUID *SystemGuid)
Definition: DxeNetLib.c:3325
EFI_STATUS EFIAPI NetLibStrToIp4(IN CONST CHAR16 *String, OUT EFI_IPv4_ADDRESS *Ip4Address)
Definition: DxeNetLib.c:3125
VOID NetIpSecNetbufFree(NET_BUF *Nbuf)
Definition: NetBuffer.c:1812
INTN EFIAPI NetGetIpClass(IN IP4_ADDR Addr)
Definition: DxeNetLib.c:643
UINT8 *EFIAPI NetbufAllocSpace(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
Definition: NetBuffer.c:1015
EFI_HANDLE EFIAPI NetLibGetSnpHandle(IN EFI_HANDLE ServiceHandle, OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL)
Definition: DxeNetLib.c:2073
NET_BUF *EFIAPI NetbufDuplicate(IN NET_BUF *Nbuf, IN OUT NET_BUF *Duplicate OPTIONAL, IN UINT32 HeadSpace)
Definition: NetBuffer.c:280
EFI_STATUS EFIAPI NetLibStrToIp6andPrefix(IN CONST CHAR16 *String, OUT EFI_IPv6_ADDRESS *Ip6Address, OUT UINT8 *PrefixLength)
Definition: DxeNetLib.c:3185
VOID EFIAPI NetbufFreeList(IN OUT LIST_ENTRY *Head)
Definition: NetBuffer.c:319
BOOLEAN EFIAPI NetMapIsEmpty(IN NET_MAP *Map)
Definition: DxeNetLib.c:1413
EFI_STATUS EFIAPI NetLibAsciiStrToIp6(IN CONST CHAR8 *String, OUT EFI_IPv6_ADDRESS *Ip6Address)
Definition: DxeNetLib.c:3097
INTN EFIAPI NetGetMaskLength(IN IP4_ADDR NetMask)
Definition: DxeNetLib.c:600
VOID EFIAPI NetbufQueFree(IN NET_BUF_QUEUE *NbufQue)
Definition: NetBuffer.c:1350
EFI_STATUS EFIAPI NetLibStrToIp6(IN CONST CHAR16 *String, OUT EFI_IPv6_ADDRESS *Ip6Address)
Definition: DxeNetLib.c:3154
EFI_STATUS EFIAPI PseudoRandomU32(OUT UINT32 *Output)
Definition: DxeNetLib.c:1011
UINT16 EFIAPI NetPseudoHeadChecksum(IN IP4_ADDR Src, IN IP4_ADDR Dst, IN UINT8 Proto, IN UINT16 Len)
Definition: NetBuffer.c:1740
UINT8 *EFIAPI NetbufGetByte(IN NET_BUF *Nbuf, IN UINT32 Offset, OUT UINT32 *Index OPTIONAL)
Definition: NetBuffer.c:359
EFI_STATUS EFIAPI NetLibIp6ToStr(IN EFI_IPv6_ADDRESS *Ip6Address, OUT CHAR16 *String, IN UINTN StringSize)
Definition: DxeNetLib.c:3218
VOID *EFIAPI NetMapRemoveItem(IN OUT NET_MAP *Map, IN OUT NET_MAP_ITEM *Item, OUT VOID **Value OPTIONAL)
Definition: DxeNetLib.c:1671
VOID *EFIAPI NetMapRemoveHead(IN OUT NET_MAP *Map, OUT VOID **Value OPTIONAL)
Definition: DxeNetLib.c:1710
EFI_HANDLE EFIAPI NetLibGetNicHandle(IN EFI_HANDLE Controller, IN EFI_GUID *ProtocolGuid)
Definition: DxeNetLib.c:3019
EFI_STATUS EFIAPI NetMapInsertTail(IN OUT NET_MAP *Map, IN VOID *Key, IN VOID *Value OPTIONAL)
Definition: DxeNetLib.c:1556
EFI_STATUS EFIAPI NetDestroyLinkList(IN LIST_ENTRY *List, IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, IN VOID *Context OPTIONAL, OUT UINTN *ListLength OPTIONAL)
Definition: DxeNetLib.c:1236
VOID EFIAPI NetbufQueAppend(IN OUT NET_BUF_QUEUE *NbufQue, IN OUT NET_BUF *Nbuf)
Definition: NetBuffer.c:1374
EFI_STATUS(EFIAPI * NET_DESTROY_LINK_LIST_CALLBACK)(IN LIST_ENTRY *Entry, IN VOID *Context OPTIONAL)
Definition: NetLib.h:749
EFI_STATUS EFIAPI NetMapIterate(IN NET_MAP *Map, IN NET_MAP_CALLBACK CallBack, IN VOID *Arg OPTIONAL)
Definition: DxeNetLib.c:1800
VOID EFIAPI NetListInsertBefore(IN OUT LIST_ENTRY *PostEntry, IN OUT LIST_ENTRY *NewEntry)
Definition: DxeNetLib.c:1199
EFI_STATUS EFIAPI PseudoRandom(OUT VOID *Output, IN UINTN OutputLength)
Definition: DxeNetLib.c:928
UINT16 EFIAPI NetLibGetVlanId(IN EFI_HANDLE ServiceHandle)
Definition: DxeNetLib.c:2140
NET_BUF *EFIAPI NetbufQueRemove(IN OUT NET_BUF_QUEUE *NbufQue)
Definition: NetBuffer.c:1399
EFI_STATUS EFIAPI NetDebugOutput(IN UINT32 Level, IN UINT8 *Module, IN UINT8 *File, IN UINT32 Line, IN UINT8 *Message)
Definition: DxeNetLib.c:524
UINTN EFIAPI NetMapGetCount(IN NET_MAP *Map)
Definition: DxeNetLib.c:1433
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
Definition: Base.h:213