]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Include/Library/NetLib.h
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / Include / Library / NetLib.h
CommitLineData
97b38d4e 1/** @file\r
1204fe83 2 This library is only intended to be used by UEFI network stack modules.\r
e9b67286 3 It provides basic functions for the UEFI network stack.\r
97b38d4e 4\r
e0e26f9c 5Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
97b38d4e 7\r
8**/\r
9\r
10#ifndef _NET_LIB_H_\r
11#define _NET_LIB_H_\r
12\r
fb115c61 13#include <Protocol/Ip6.h>\r
14\r
1204fe83 15#include <Library/BaseLib.h>\r
7b126c2e 16#include <Library/BaseMemoryLib.h>\r
1204fe83 17\r
d1050b9d
MK
18typedef UINT32 IP4_ADDR;\r
19typedef UINT32 TCP_SEQNO;\r
20typedef UINT16 TCP_PORTNO;\r
97b38d4e 21\r
d1050b9d
MK
22#define NET_ETHER_ADDR_LEN 6\r
23#define NET_IFTYPE_ETHERNET 0x01\r
b45b45b2 24\r
d1050b9d
MK
25#define NET_VLAN_TAG_LEN 4\r
26#define ETHER_TYPE_VLAN 0x8100\r
779ae357 27\r
b45b45b2 28#define EFI_IP_PROTO_UDP 0x11\r
29#define EFI_IP_PROTO_TCP 0x06\r
30#define EFI_IP_PROTO_ICMP 0x01\r
f6b7393c 31#define IP4_PROTO_IGMP 0x02\r
32#define IP6_ICMP 58\r
dba6e9a9
JW
33#define DNS_MAX_NAME_SIZE 255\r
34#define DNS_MAX_MESSAGE_SIZE 512\r
b45b45b2 35\r
36//\r
37// The address classification\r
38//\r
d1050b9d
MK
39#define IP4_ADDR_CLASSA 1 // Deprecated\r
40#define IP4_ADDR_CLASSB 2 // Deprecated\r
41#define IP4_ADDR_CLASSC 3 // Deprecated\r
42#define IP4_ADDR_CLASSD 4\r
43#define IP4_ADDR_CLASSE 5\r
b45b45b2 44\r
d1050b9d
MK
45#define IP4_MASK_NUM 33\r
46#define IP6_PREFIX_NUM 129\r
b45b45b2 47\r
d1050b9d
MK
48#define IP4_MASK_MAX 32\r
49#define IP6_PREFIX_MAX 128\r
364f4efa 50\r
d1050b9d
MK
51#define IP6_HOP_BY_HOP 0\r
52#define IP6_DESTINATION 60\r
53#define IP6_ROUTING 43\r
54#define IP6_FRAGMENT 44\r
55#define IP6_AH 51\r
56#define IP6_ESP 50\r
57#define IP6_NO_NEXT_HEADER 59\r
b45b45b2 58\r
d1050b9d
MK
59#define IP_VERSION_4 4\r
60#define IP_VERSION_6 6\r
fb115c61 61\r
d1050b9d 62#define IP6_PREFIX_LENGTH 64\r
501793fa 63\r
a57cdf33
JW
64//\r
65// DNS QTYPE values\r
66//\r
d1050b9d
MK
67#define DNS_TYPE_A 1\r
68#define DNS_TYPE_NS 2\r
69#define DNS_TYPE_CNAME 5\r
70#define DNS_TYPE_SOA 6\r
71#define DNS_TYPE_WKS 11\r
72#define DNS_TYPE_PTR 12\r
73#define DNS_TYPE_HINFO 13\r
74#define DNS_TYPE_MINFO 14\r
75#define DNS_TYPE_MX 15\r
76#define DNS_TYPE_TXT 16\r
77#define DNS_TYPE_AAAA 28\r
78#define DNS_TYPE_SRV_RR 33\r
79#define DNS_TYPE_AXFR 252\r
80#define DNS_TYPE_MAILB 253\r
81#define DNS_TYPE_ANY 255\r
a57cdf33
JW
82\r
83//\r
84// DNS QCLASS values\r
85//\r
d1050b9d
MK
86#define DNS_CLASS_INET 1\r
87#define DNS_CLASS_CH 3\r
88#define DNS_CLASS_HS 4\r
89#define DNS_CLASS_ANY 255\r
a57cdf33 90\r
ca4e4323 91//\r
92// Number of 100ns units time Interval for network media state detect\r
93//\r
94#define MEDIA_STATE_DETECT_TIME_INTERVAL 1000000U\r
95\r
97b38d4e 96#pragma pack(1)\r
97\r
98//\r
99// Ethernet head definition\r
100//\r
101typedef struct {\r
d1050b9d
MK
102 UINT8 DstMac[NET_ETHER_ADDR_LEN];\r
103 UINT8 SrcMac[NET_ETHER_ADDR_LEN];\r
104 UINT16 EtherType;\r
97b38d4e 105} ETHER_HEAD;\r
106\r
779ae357 107//\r
108// 802.1Q VLAN Tag Control Information\r
109//\r
110typedef union {\r
111 struct {\r
d1050b9d
MK
112 UINT16 Vid : 12; // Unique VLAN identifier (0 to 4094)\r
113 UINT16 Cfi : 1; // Canonical Format Indicator\r
114 UINT16 Priority : 3; // 802.1Q priority level (0 to 7)\r
779ae357 115 } Bits;\r
d1050b9d 116 UINT16 Uint16;\r
779ae357 117} VLAN_TCI;\r
118\r
119#define VLAN_TCI_CFI_CANONICAL_MAC 0\r
120#define VLAN_TCI_CFI_NON_CANONICAL_MAC 1\r
97b38d4e 121\r
122//\r
123// The EFI_IP4_HEADER is hard to use because the source and\r
124// destination address are defined as EFI_IPv4_ADDRESS, which\r
125// is a structure. Two structures can't be compared or masked\r
126// directly. This is why there is an internal representation.\r
127//\r
128typedef struct {\r
d1050b9d
MK
129 UINT8 HeadLen : 4;\r
130 UINT8 Ver : 4;\r
131 UINT8 Tos;\r
132 UINT16 TotalLen;\r
133 UINT16 Id;\r
134 UINT16 Fragment;\r
135 UINT8 Ttl;\r
136 UINT8 Protocol;\r
137 UINT16 Checksum;\r
138 IP4_ADDR Src;\r
139 IP4_ADDR Dst;\r
97b38d4e 140} IP4_HEAD;\r
141\r
97b38d4e 142//\r
e9b67286 143// ICMP head definition. Each ICMP message is categorized as either an error\r
97b38d4e 144// message or query message. Two message types have their own head format.\r
145//\r
146typedef struct {\r
d1050b9d
MK
147 UINT8 Type;\r
148 UINT8 Code;\r
149 UINT16 Checksum;\r
97b38d4e 150} IP4_ICMP_HEAD;\r
151\r
152typedef struct {\r
d1050b9d
MK
153 IP4_ICMP_HEAD Head;\r
154 UINT32 Fourth; // 4th filed of the head, it depends on Type.\r
155 IP4_HEAD IpHead;\r
97b38d4e 156} IP4_ICMP_ERROR_HEAD;\r
157\r
158typedef struct {\r
d1050b9d
MK
159 IP4_ICMP_HEAD Head;\r
160 UINT16 Id;\r
161 UINT16 Seq;\r
97b38d4e 162} IP4_ICMP_QUERY_HEAD;\r
163\r
fb115c61 164typedef struct {\r
d1050b9d
MK
165 UINT8 Type;\r
166 UINT8 Code;\r
167 UINT16 Checksum;\r
fb115c61 168} IP6_ICMP_HEAD;\r
169\r
170typedef struct {\r
d1050b9d
MK
171 IP6_ICMP_HEAD Head;\r
172 UINT32 Fourth;\r
173 EFI_IP6_HEADER IpHead;\r
fb115c61 174} IP6_ICMP_ERROR_HEAD;\r
175\r
176typedef struct {\r
d1050b9d
MK
177 IP6_ICMP_HEAD Head;\r
178 UINT32 Fourth;\r
fb115c61 179} IP6_ICMP_INFORMATION_HEAD;\r
97b38d4e 180\r
181//\r
182// UDP header definition\r
183//\r
184typedef struct {\r
d1050b9d
MK
185 UINT16 SrcPort;\r
186 UINT16 DstPort;\r
187 UINT16 Length;\r
188 UINT16 Checksum;\r
fb115c61 189} EFI_UDP_HEADER;\r
97b38d4e 190\r
191//\r
192// TCP header definition\r
193//\r
194typedef struct {\r
d1050b9d
MK
195 TCP_PORTNO SrcPort;\r
196 TCP_PORTNO DstPort;\r
197 TCP_SEQNO Seq;\r
198 TCP_SEQNO Ack;\r
199 UINT8 Res : 4;\r
200 UINT8 HeadLen : 4;\r
201 UINT8 Flag;\r
202 UINT16 Wnd;\r
203 UINT16 Checksum;\r
204 UINT16 Urg;\r
97b38d4e 205} TCP_HEAD;\r
206\r
207#pragma pack()\r
208\r
209#define NET_MAC_EQUAL(pMac1, pMac2, Len) \\r
210 (CompareMem ((pMac1), (pMac2), Len) == 0)\r
211\r
212#define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \\r
213 (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))\r
214\r
1204fe83 215#define NTOHL(x) SwapBytes32 (x)\r
97b38d4e 216\r
217#define HTONL(x) NTOHL(x)\r
218\r
1204fe83 219#define NTOHS(x) SwapBytes16 (x)\r
97b38d4e 220\r
d1050b9d
MK
221#define HTONS(x) NTOHS(x)\r
222#define NTOHLL(x) SwapBytes64 (x)\r
223#define HTONLL(x) NTOHLL(x)\r
224#define NTOHLLL(x) Ip6Swap128 (x)\r
225#define HTONLLL(x) NTOHLLL(x)\r
97b38d4e 226\r
227//\r
228// Test the IP's attribute, All the IPs are in host byte order.\r
229//\r
230#define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)\r
3289dcba 231#define IP4_IS_UNSPECIFIED(Ip) ((Ip) == 0)\r
97b38d4e 232#define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)\r
233#define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))\r
364f4efa 234#define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != (IP4_MASK_MAX + 1))\r
97b38d4e 235\r
d1050b9d 236#define IP6_IS_MULTICAST(Ip6) (((Ip6)->Addr[0]) == 0xFF)\r
3a15fd52 237\r
97b38d4e 238//\r
239// Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.\r
240//\r
241#define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))\r
242#define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))\r
243#define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)\r
244\r
fb115c61 245#define EFI_IP6_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv6_ADDRESS)) == 0)\r
246\r
d1050b9d
MK
247#define IP4_COPY_ADDRESS(Dest, Src) (CopyMem ((Dest), (Src), sizeof (EFI_IPv4_ADDRESS)))\r
248#define IP6_COPY_ADDRESS(Dest, Src) (CopyMem ((Dest), (Src), sizeof (EFI_IPv6_ADDRESS)))\r
249#define IP6_COPY_LINK_ADDRESS(Mac1, Mac2) (CopyMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)))\r
f6b7393c 250\r
251//\r
1204fe83 252// The debug level definition. This value is also used as the\r
86ac8fb2 253// syslog's severity level. Don't change it.\r
f6b7393c 254//\r
d1050b9d
MK
255#define NETDEBUG_LEVEL_TRACE 5\r
256#define NETDEBUG_LEVEL_WARNING 4\r
257#define NETDEBUG_LEVEL_ERROR 3\r
f6b7393c 258\r
259//\r
1204fe83 260// Network debug message is sent out as syslog packet.\r
f6b7393c 261//\r
1204fe83 262#define NET_SYSLOG_FACILITY 16 // Syslog local facility local use\r
263#define NET_SYSLOG_PACKET_LEN 512\r
264#define NET_SYSLOG_TX_TIMEOUT (500 * 1000 * 10) // 500ms\r
265#define NET_DEBUG_MSG_LEN 470 // 512 - (ether+ip4+udp4 head length)\r
f6b7393c 266\r
267//\r
1204fe83 268// The debug output expects the ASCII format string, Use %a to print ASCII\r
269// string, and %s to print UNICODE string. PrintArg must be enclosed in ().\r
f6b7393c 270// For example: NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name));\r
271//\r
272#define NET_DEBUG_TRACE(Module, PrintArg) \\r
273 NetDebugOutput ( \\r
274 NETDEBUG_LEVEL_TRACE, \\r
275 Module, \\r
276 __FILE__, \\r
45137bca 277 DEBUG_LINE_NUMBER, \\r
f6b7393c 278 NetDebugASPrint PrintArg \\r
279 )\r
280\r
281#define NET_DEBUG_WARNING(Module, PrintArg) \\r
282 NetDebugOutput ( \\r
283 NETDEBUG_LEVEL_WARNING, \\r
284 Module, \\r
285 __FILE__, \\r
45137bca 286 DEBUG_LINE_NUMBER, \\r
f6b7393c 287 NetDebugASPrint PrintArg \\r
288 )\r
289\r
290#define NET_DEBUG_ERROR(Module, PrintArg) \\r
291 NetDebugOutput ( \\r
292 NETDEBUG_LEVEL_ERROR, \\r
293 Module, \\r
294 __FILE__, \\r
45137bca 295 DEBUG_LINE_NUMBER, \\r
f6b7393c 296 NetDebugASPrint PrintArg \\r
297 )\r
298\r
299/**\r
1204fe83 300 Allocate a buffer, then format the message to it. This is a\r
301 help function for the NET_DEBUG_XXX macros. The PrintArg of\r
302 these macros treats the variable length print parameters as a\r
f6b7393c 303 single parameter, and pass it to the NetDebugASPrint. For\r
304 example, NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name))\r
1204fe83 305 if extracted to:\r
306\r
f6b7393c 307 NetDebugOutput (\r
1204fe83 308 NETDEBUG_LEVEL_TRACE,\r
309 "Tcp",\r
f6b7393c 310 __FILE__,\r
45137bca 311 DEBUG_LINE_NUMBER,\r
1204fe83 312 NetDebugASPrint ("State transit to %a\n", Name)\r
313 )\r
314\r
f6b7393c 315 @param Format The ASCII format string.\r
1204fe83 316 @param ... The variable length parameter whose format is determined\r
f6b7393c 317 by the Format string.\r
318\r
319 @return The buffer containing the formatted message,\r
64a80549 320 or NULL if memory allocation failed.\r
f6b7393c 321\r
322**/\r
323CHAR8 *\r
e798cd87 324EFIAPI\r
f6b7393c 325NetDebugASPrint (\r
d1050b9d 326 IN CHAR8 *Format,\r
f6b7393c 327 ...\r
328 );\r
329\r
330/**\r
331 Builds an UDP4 syslog packet and send it using SNP.\r
332\r
333 This function will locate a instance of SNP then send the message through it.\r
334 Because it isn't open the SNP BY_DRIVER, apply caution when using it.\r
335\r
86ac8fb2
GL
336 @param Level The severity level of the message.\r
337 @param Module The Module that generates the log.\r
f6b7393c 338 @param File The file that contains the log.\r
339 @param Line The exact line that contains the log.\r
340 @param Message The user message to log.\r
341\r
342 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
343 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet\r
1204fe83 344 @retval EFI_SUCCESS The log is discard because that it is more verbose\r
f6b7393c 345 than the mNetDebugLevelMax. Or, it has been sent out.\r
1204fe83 346**/\r
f6b7393c 347EFI_STATUS\r
e798cd87 348EFIAPI\r
f6b7393c 349NetDebugOutput (\r
d1050b9d
MK
350 IN UINT32 Level,\r
351 IN UINT8 *Module,\r
352 IN UINT8 *File,\r
353 IN UINT32 Line,\r
354 IN UINT8 *Message\r
f6b7393c 355 );\r
356\r
97b38d4e 357/**\r
1204fe83 358 Return the length of the mask.\r
359\r
e9b67286 360 Return the length of the mask. Valid values are 0 to 32.\r
3a1ab4bc 361 If the mask is invalid, return the invalid length 33, which is IP4_MASK_NUM.\r
97b38d4e 362 NetMask is in the host byte order.\r
363\r
ae213b7d 364 @param[in] NetMask The netmask to get the length from.\r
97b38d4e 365\r
e9b67286 366 @return The length of the netmask, or IP4_MASK_NUM (33) if the mask is invalid.\r
1204fe83 367\r
97b38d4e 368**/\r
369INTN\r
370EFIAPI\r
371NetGetMaskLength (\r
d1050b9d 372 IN IP4_ADDR NetMask\r
97b38d4e 373 );\r
374\r
375/**\r
3a1ab4bc 376 Return the class of the IP address, such as class A, B, C.\r
97b38d4e 377 Addr is in host byte order.\r
1204fe83 378\r
3289dcba
FS
379 [ATTENTION]\r
380 Classful addressing (IP class A/B/C) has been deprecated according to RFC4632.\r
381 Caller of this function could only check the returned value against\r
382 IP4_ADDR_CLASSD (multicast) or IP4_ADDR_CLASSE (reserved) now.\r
383\r
3a1ab4bc 384 The address of class A starts with 0.\r
385 If the address belong to class A, return IP4_ADDR_CLASSA.\r
1204fe83 386 The address of class B starts with 10.\r
3a1ab4bc 387 If the address belong to class B, return IP4_ADDR_CLASSB.\r
1204fe83 388 The address of class C starts with 110.\r
3a1ab4bc 389 If the address belong to class C, return IP4_ADDR_CLASSC.\r
1204fe83 390 The address of class D starts with 1110.\r
3a1ab4bc 391 If the address belong to class D, return IP4_ADDR_CLASSD.\r
392 The address of class E starts with 1111.\r
393 If the address belong to class E, return IP4_ADDR_CLASSE.\r
97b38d4e 394\r
1204fe83 395\r
ae213b7d 396 @param[in] Addr The address to get the class from.\r
97b38d4e 397\r
ae213b7d 398 @return IP address class, such as IP4_ADDR_CLASSA.\r
97b38d4e 399\r
400**/\r
401INTN\r
402EFIAPI\r
403NetGetIpClass (\r
d1050b9d 404 IN IP4_ADDR Addr\r
97b38d4e 405 );\r
406\r
407/**\r
408 Check whether the IP is a valid unicast address according to\r
d1102dba 409 the netmask.\r
1204fe83 410\r
3289dcba 411 ASSERT if NetMask is zero.\r
d1102dba 412\r
29788f17
FS
413 If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r
414 except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r
12ae56cf
FS
415 mask (RFC3021), or a 32bit NetMask (all 0xFF) is used for special network environment (e.g.\r
416 PPP link).\r
4a76d9b9 417\r
ae213b7d 418 @param[in] Ip The IP to check against.\r
419 @param[in] NetMask The mask of the IP.\r
97b38d4e 420\r
3289dcba 421 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE.\r
97b38d4e 422\r
423**/\r
424BOOLEAN\r
ae213b7d 425EFIAPI\r
f6b7393c 426NetIp4IsUnicast (\r
d1050b9d
MK
427 IN IP4_ADDR Ip,\r
428 IN IP4_ADDR NetMask\r
97b38d4e 429 );\r
430\r
fb115c61 431/**\r
432 Check whether the incoming IPv6 address is a valid unicast address.\r
433\r
e0e26f9c
WF
434 ASSERT if Ip6 is NULL.\r
435\r
fb115c61 436 If the address is a multicast address has binary 0xFF at the start, it is not\r
437 a valid unicast address. If the address is unspecified ::, it is not a valid\r
438 unicast address to be assigned to any node. If the address is loopback address\r
439 ::1, it is also not a valid unicast address to be assigned to any physical\r
1204fe83 440 interface.\r
fb115c61 441\r
442 @param[in] Ip6 The IPv6 address to check against.\r
443\r
444 @return TRUE if Ip6 is a valid unicast address on the network, otherwise FALSE.\r
445\r
1204fe83 446**/\r
fb115c61 447BOOLEAN\r
e798cd87 448EFIAPI\r
f6b7393c 449NetIp6IsValidUnicast (\r
d1050b9d 450 IN EFI_IPv6_ADDRESS *Ip6\r
f6b7393c 451 );\r
452\r
f6b7393c 453/**\r
454 Check whether the incoming Ipv6 address is the unspecified address or not.\r
455\r
e0e26f9c
WF
456 ASSERT if Ip6 is NULL.\r
457\r
f6b7393c 458 @param[in] Ip6 - Ip6 address, in network order.\r
459\r
64a80549 460 @retval TRUE - Yes, incoming Ipv6 address is the unspecified address.\r
461 @retval FALSE - The incoming Ipv6 address is not the unspecified address\r
1204fe83 462\r
f6b7393c 463**/\r
464BOOLEAN\r
e798cd87 465EFIAPI\r
f6b7393c 466NetIp6IsUnspecifiedAddr (\r
d1050b9d 467 IN EFI_IPv6_ADDRESS *Ip6\r
fb115c61 468 );\r
469\r
f6b7393c 470/**\r
471 Check whether the incoming Ipv6 address is a link-local address.\r
472\r
e0e26f9c
WF
473 ASSERT if Ip6 is NULL.\r
474\r
f6b7393c 475 @param[in] Ip6 - Ip6 address, in network order.\r
476\r
64a80549 477 @retval TRUE - The incoming Ipv6 address is a link-local address.\r
478 @retval FALSE - The incoming Ipv6 address is not a link-local address.\r
1204fe83 479\r
f6b7393c 480**/\r
481BOOLEAN\r
e798cd87 482EFIAPI\r
f6b7393c 483NetIp6IsLinkLocalAddr (\r
d1050b9d 484 IN EFI_IPv6_ADDRESS *Ip6\r
f6b7393c 485 );\r
486\r
487/**\r
488 Check whether the Ipv6 address1 and address2 are on the connected network.\r
489\r
e0e26f9c
WF
490 ASSERT if Ip1 or Ip2 is NULL.\r
491 ASSERT if PrefixLength exceeds or equals to IP6_PREFIX_MAX.\r
492\r
f6b7393c 493 @param[in] Ip1 - Ip6 address1, in network order.\r
494 @param[in] Ip2 - Ip6 address2, in network order.\r
495 @param[in] PrefixLength - The prefix length of the checking net.\r
496\r
64a80549 497 @retval TRUE - Yes, the Ipv6 address1 and address2 are connected.\r
498 @retval FALSE - No the Ipv6 address1 and address2 are not connected.\r
1204fe83 499\r
f6b7393c 500**/\r
501BOOLEAN\r
e798cd87 502EFIAPI\r
f6b7393c 503NetIp6IsNetEqual (\r
d1050b9d
MK
504 EFI_IPv6_ADDRESS *Ip1,\r
505 EFI_IPv6_ADDRESS *Ip2,\r
506 UINT8 PrefixLength\r
f6b7393c 507 );\r
508\r
b45b45b2 509/**\r
64a80549 510 Switches the endianess of an IPv6 address.\r
b45b45b2 511\r
e0e26f9c
WF
512 ASSERT if Ip6 is NULL.\r
513\r
b45b45b2 514 This function swaps the bytes in a 128-bit IPv6 address to switch the value\r
515 from little endian to big endian or vice versa. The byte swapped value is\r
516 returned.\r
517\r
64a80549 518 @param Ip6 Points to an IPv6 address.\r
b45b45b2 519\r
520 @return The byte swapped IPv6 address.\r
521\r
522**/\r
523EFI_IPv6_ADDRESS *\r
e798cd87 524EFIAPI\r
b45b45b2 525Ip6Swap128 (\r
d1050b9d 526 EFI_IPv6_ADDRESS *Ip6\r
b45b45b2 527 );\r
528\r
d1050b9d 529extern IP4_ADDR gIp4AllMasks[IP4_MASK_NUM];\r
97b38d4e 530\r
531extern EFI_IPv4_ADDRESS mZeroIp4Addr;\r
532\r
533#define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))\r
418373a1 534#define NET_IS_HEX(Ch) ((('0' <= (Ch)) && ((Ch) <= '9')) || (('A' <= (Ch)) && ((Ch) <= 'F')) || (('a' <= (Ch)) && ((Ch) <= 'f')))\r
97b38d4e 535#define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))\r
536#define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))\r
537#define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))\r
538\r
d1050b9d
MK
539#define TICKS_PER_MS 10000U\r
540#define TICKS_PER_SECOND 10000000U\r
97b38d4e 541\r
d1050b9d 542#define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)\r
97b38d4e 543\r
544/**\r
3a1ab4bc 545 Extract a UINT32 from a byte stream.\r
1204fe83 546\r
e0e26f9c
WF
547 ASSERT if Buf is NULL.\r
548\r
1204fe83 549 This function copies a UINT32 from a byte stream, and then converts it from Network\r
3a1ab4bc 550 byte order to host byte order. Use this function to avoid alignment error.\r
97b38d4e 551\r
ae213b7d 552 @param[in] Buf The buffer to extract the UINT32.\r
97b38d4e 553\r
554 @return The UINT32 extracted.\r
555\r
556**/\r
557UINT32\r
558EFIAPI\r
559NetGetUint32 (\r
d1050b9d 560 IN UINT8 *Buf\r
97b38d4e 561 );\r
562\r
563/**\r
1204fe83 564 Puts a UINT32 into the byte stream in network byte order.\r
565\r
e0e26f9c
WF
566 ASSERT if Buf is NULL.\r
567\r
64a80549 568 Converts a UINT32 from host byte order to network byte order, then copies it to the\r
3a1ab4bc 569 byte stream.\r
97b38d4e 570\r
64a80549 571 @param[in, out] Buf The buffer in which to put the UINT32.\r
3b1464d5 572 @param[in] Data The data to be converted and put into the byte stream.\r
1204fe83 573\r
97b38d4e 574**/\r
575VOID\r
576EFIAPI\r
577NetPutUint32 (\r
d1050b9d
MK
578 IN OUT UINT8 *Buf,\r
579 IN UINT32 Data\r
97b38d4e 580 );\r
581\r
582/**\r
2bd25290 583 Initialize a random seed using current time and monotonic count.\r
1204fe83 584\r
d1102dba 585 Get current time and monotonic count first. Then initialize a random seed\r
2bd25290
FS
586 based on some basic mathematics operation on the hour, day, minute, second,\r
587 nanosecond and year of the current time and the monotonic count value.\r
1204fe83 588\r
2bd25290 589 @return The random seed initialized with current time.\r
97b38d4e 590\r
591**/\r
592UINT32\r
593EFIAPI\r
594NetRandomInitSeed (\r
595 VOID\r
596 );\r
597\r
97b38d4e 598#define NET_LIST_USER_STRUCT(Entry, Type, Field) \\r
50d7ebad 599 BASE_CR(Entry, Type, Field)\r
97b38d4e 600\r
601#define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \\r
602 CR(Entry, Type, Field, Sig)\r
603\r
604//\r
e9b67286 605// Iterate through the double linked list. It is NOT delete safe\r
97b38d4e 606//\r
607#define NET_LIST_FOR_EACH(Entry, ListHead) \\r
608 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)\r
609\r
610//\r
e9b67286 611// Iterate through the double linked list. This is delete-safe.\r
97b38d4e 612// Don't touch NextEntry. Also, don't use this macro if list\r
613// entries other than the Entry may be deleted when processing\r
614// the current Entry.\r
615//\r
616#define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \\r
617 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \\r
618 Entry != (ListHead); \\r
619 Entry = NextEntry, NextEntry = Entry->ForwardLink \\r
620 )\r
621\r
622//\r
e9b67286 623// Make sure the list isn't empty before getting the first/last record.\r
97b38d4e 624//\r
625#define NET_LIST_HEAD(ListHead, Type, Field) \\r
626 NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)\r
627\r
628#define NET_LIST_TAIL(ListHead, Type, Field) \\r
629 NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)\r
630\r
97b38d4e 631/**\r
3a1ab4bc 632 Remove the first node entry on the list, and return the removed node entry.\r
1204fe83 633\r
e9b67286 634 Removes the first node entry from a doubly linked list. It is up to the caller of\r
635 this function to release the memory used by the first node, if that is required. On\r
1204fe83 636 exit, the removed node is returned.\r
3a1ab4bc 637\r
638 If Head is NULL, then ASSERT().\r
639 If Head was not initialized, then ASSERT().\r
640 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
641 linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,\r
1204fe83 642 then ASSERT().\r
97b38d4e 643\r
ae213b7d 644 @param[in, out] Head The list header.\r
97b38d4e 645\r
3a1ab4bc 646 @return The first node entry that is removed from the list, NULL if the list is empty.\r
97b38d4e 647\r
648**/\r
649LIST_ENTRY *\r
650EFIAPI\r
651NetListRemoveHead (\r
d1050b9d 652 IN OUT LIST_ENTRY *Head\r
97b38d4e 653 );\r
654\r
655/**\r
e9b67286 656 Remove the last node entry on the list and return the removed node entry.\r
3a1ab4bc 657\r
658 Removes the last node entry from a doubly linked list. It is up to the caller of\r
e9b67286 659 this function to release the memory used by the first node, if that is required. On\r
1204fe83 660 exit, the removed node is returned.\r
97b38d4e 661\r
3a1ab4bc 662 If Head is NULL, then ASSERT().\r
663 If Head was not initialized, then ASSERT().\r
664 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
665 linked list including the head node is greater than or equal to PcdMaximumLinkedListLength,\r
1204fe83 666 then ASSERT().\r
667\r
ae213b7d 668 @param[in, out] Head The list head.\r
97b38d4e 669\r
3a1ab4bc 670 @return The last node entry that is removed from the list, NULL if the list is empty.\r
97b38d4e 671\r
672**/\r
673LIST_ENTRY *\r
674EFIAPI\r
675NetListRemoveTail (\r
d1050b9d 676 IN OUT LIST_ENTRY *Head\r
97b38d4e 677 );\r
678\r
679/**\r
3a1ab4bc 680 Insert a new node entry after a designated node entry of a doubly linked list.\r
1204fe83 681\r
e0e26f9c
WF
682 ASSERT if PrevEntry or NewEntry is NULL.\r
683\r
e9b67286 684 Inserts a new node entry designated by NewEntry after the node entry designated by PrevEntry\r
3a1ab4bc 685 of the doubly linked list.\r
1204fe83 686\r
687 @param[in, out] PrevEntry The entry after which to insert.\r
ae213b7d 688 @param[in, out] NewEntry The new entry to insert.\r
97b38d4e 689\r
690**/\r
691VOID\r
692EFIAPI\r
693NetListInsertAfter (\r
d1050b9d
MK
694 IN OUT LIST_ENTRY *PrevEntry,\r
695 IN OUT LIST_ENTRY *NewEntry\r
97b38d4e 696 );\r
697\r
698/**\r
3a1ab4bc 699 Insert a new node entry before a designated node entry of a doubly linked list.\r
1204fe83 700\r
e0e26f9c
WF
701 ASSERT if PostEntry or NewEntry is NULL.\r
702\r
e9b67286 703 Inserts a new node entry designated by NewEntry before the node entry designated by PostEntry\r
3a1ab4bc 704 of the doubly linked list.\r
1204fe83 705\r
ae213b7d 706 @param[in, out] PostEntry The entry to insert before.\r
707 @param[in, out] NewEntry The new entry to insert.\r
97b38d4e 708\r
709**/\r
710VOID\r
711EFIAPI\r
712NetListInsertBefore (\r
d1050b9d
MK
713 IN OUT LIST_ENTRY *PostEntry,\r
714 IN OUT LIST_ENTRY *NewEntry\r
97b38d4e 715 );\r
716\r
216f7970 717/**\r
718 Callback function which provided by user to remove one node in NetDestroyLinkList process.\r
d1102dba 719\r
216f7970 720 @param[in] Entry The entry to be removed.\r
721 @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r
722\r
723 @retval EFI_SUCCESS The entry has been removed successfully.\r
724 @retval Others Fail to remove the entry.\r
725\r
726**/\r
727typedef\r
728EFI_STATUS\r
d1050b9d 729(EFIAPI *NET_DESTROY_LINK_LIST_CALLBACK)(\r
216f7970 730 IN LIST_ENTRY *Entry,\r
731 IN VOID *Context OPTIONAL\r
1f7eb561 732 );\r
216f7970 733\r
734/**\r
735 Safe destroy nodes in a linked list, and return the length of the list after all possible operations finished.\r
736\r
737 Destroy network children list by list traversals is not safe due to graph dependencies between nodes.\r
738 This function performs a safe traversal to destroy these nodes by checking to see if the node being destroyed\r
739 has been removed from the list or not.\r
740 If it has been removed, then restart the traversal from the head.\r
741 If it hasn't been removed, then continue with the next node directly.\r
742 This function will end the iterate and return the CallBack's last return value if error happens,\r
6deb4baa 743 or return EFI_SUCCESS if 2 complete passes are made with no changes in the number of children in the list.\r
216f7970 744\r
745 @param[in] List The head of the list.\r
746 @param[in] CallBack Pointer to the callback function to destroy one node in the list.\r
747 @param[in] Context Pointer to the callback function's context: corresponds to the\r
748 parameter Context in NET_DESTROY_LINK_LIST_CALLBACK.\r
749 @param[out] ListLength The length of the link list if the function returns successfully.\r
750\r
751 @retval EFI_SUCCESS Two complete passes are made with no changes in the number of children.\r
752 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
753 @retval Others Return the CallBack's last return value.\r
754\r
755**/\r
756EFI_STATUS\r
757EFIAPI\r
758NetDestroyLinkList (\r
d1050b9d
MK
759 IN LIST_ENTRY *List,\r
760 IN NET_DESTROY_LINK_LIST_CALLBACK CallBack,\r
761 IN VOID *Context OPTIONAL,\r
762 OUT UINTN *ListLength OPTIONAL\r
1f7eb561 763 );\r
216f7970 764\r
765/**\r
766 This function checks the input Handle to see if it's one of these handles in ChildHandleBuffer.\r
767\r
768 @param[in] Handle Handle to be checked.\r
769 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer.\r
770 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
771 if NumberOfChildren is 0.\r
772\r
86ac8fb2 773 @retval TRUE Found the input Handle in ChildHandleBuffer.\r
216f7970 774 @retval FALSE Can't find the input Handle in ChildHandleBuffer.\r
775\r
776**/\r
777BOOLEAN\r
1f7eb561 778EFIAPI\r
216f7970 779NetIsInHandleBuffer (\r
d1050b9d
MK
780 IN EFI_HANDLE Handle,\r
781 IN UINTN NumberOfChildren,\r
782 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
1f7eb561 783 );\r
97b38d4e 784\r
785//\r
786// Object container: EFI network stack spec defines various kinds of\r
787// tokens. The drivers can share code to manage those objects.\r
788//\r
789typedef struct {\r
d1050b9d
MK
790 LIST_ENTRY Link;\r
791 VOID *Key;\r
792 VOID *Value;\r
97b38d4e 793} NET_MAP_ITEM;\r
794\r
795typedef struct {\r
d1050b9d
MK
796 LIST_ENTRY Used;\r
797 LIST_ENTRY Recycled;\r
798 UINTN Count;\r
97b38d4e 799} NET_MAP;\r
800\r
801#define NET_MAP_INCREAMENT 64\r
802\r
803/**\r
804 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.\r
1204fe83 805\r
806 Initialize the forward and backward links of two head nodes donated by Map->Used\r
3a1ab4bc 807 and Map->Recycled of two doubly linked lists.\r
808 Initializes the count of the <Key, Value> pairs in the netmap to zero.\r
1204fe83 809\r
3a1ab4bc 810 If Map is NULL, then ASSERT().\r
811 If the address of Map->Used is NULL, then ASSERT().\r
812 If the address of Map->Recycled is NULl, then ASSERT().\r
1204fe83 813\r
ae213b7d 814 @param[in, out] Map The netmap to initialize.\r
97b38d4e 815\r
816**/\r
817VOID\r
818EFIAPI\r
819NetMapInit (\r
d1050b9d 820 IN OUT NET_MAP *Map\r
97b38d4e 821 );\r
822\r
823/**\r
824 To clean up the netmap, that is, release allocated memories.\r
1204fe83 825\r
e9b67286 826 Removes all nodes of the Used doubly linked list and frees memory of all related netmap items.\r
3a1ab4bc 827 Removes all nodes of the Recycled doubly linked list and free memory of all related netmap items.\r
e9b67286 828 The number of the <Key, Value> pairs in the netmap is set to zero.\r
1204fe83 829\r
3a1ab4bc 830 If Map is NULL, then ASSERT().\r
1204fe83 831\r
ae213b7d 832 @param[in, out] Map The netmap to clean up.\r
97b38d4e 833\r
834**/\r
835VOID\r
836EFIAPI\r
837NetMapClean (\r
d1050b9d 838 IN OUT NET_MAP *Map\r
97b38d4e 839 );\r
840\r
841/**\r
3a1ab4bc 842 Test whether the netmap is empty and return true if it is.\r
1204fe83 843\r
3a1ab4bc 844 If the number of the <Key, Value> pairs in the netmap is zero, return TRUE.\r
1204fe83 845\r
3a1ab4bc 846 If Map is NULL, then ASSERT().\r
1204fe83 847\r
ae213b7d 848 @param[in] Map The net map to test.\r
97b38d4e 849\r
850 @return TRUE if the netmap is empty, otherwise FALSE.\r
851\r
852**/\r
853BOOLEAN\r
854EFIAPI\r
855NetMapIsEmpty (\r
d1050b9d 856 IN NET_MAP *Map\r
97b38d4e 857 );\r
858\r
859/**\r
860 Return the number of the <Key, Value> pairs in the netmap.\r
861\r
e0e26f9c
WF
862 If Map is NULL, then ASSERT().\r
863\r
ae213b7d 864 @param[in] Map The netmap to get the entry number.\r
97b38d4e 865\r
866 @return The entry number in the netmap.\r
867\r
868**/\r
869UINTN\r
870EFIAPI\r
871NetMapGetCount (\r
d1050b9d 872 IN NET_MAP *Map\r
97b38d4e 873 );\r
874\r
875/**\r
876 Allocate an item to save the <Key, Value> pair to the head of the netmap.\r
1204fe83 877\r
3a1ab4bc 878 Allocate an item to save the <Key, Value> pair and add corresponding node entry\r
1204fe83 879 to the beginning of the Used doubly linked list. The number of the <Key, Value>\r
3a1ab4bc 880 pairs in the netmap increase by 1.\r
97b38d4e 881\r
3a1ab4bc 882 If Map is NULL, then ASSERT().\r
e0e26f9c 883 If Key is NULL, then ASSERT().\r
1204fe83 884\r
ae213b7d 885 @param[in, out] Map The netmap to insert into.\r
886 @param[in] Key The user's key.\r
887 @param[in] Value The user's value for the key.\r
97b38d4e 888\r
ae213b7d 889 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.\r
890 @retval EFI_SUCCESS The item is inserted to the head.\r
97b38d4e 891\r
892**/\r
893EFI_STATUS\r
894EFIAPI\r
895NetMapInsertHead (\r
d1050b9d
MK
896 IN OUT NET_MAP *Map,\r
897 IN VOID *Key,\r
898 IN VOID *Value OPTIONAL\r
97b38d4e 899 );\r
900\r
901/**\r
902 Allocate an item to save the <Key, Value> pair to the tail of the netmap.\r
903\r
3a1ab4bc 904 Allocate an item to save the <Key, Value> pair and add corresponding node entry\r
1204fe83 905 to the tail of the Used doubly linked list. The number of the <Key, Value>\r
3a1ab4bc 906 pairs in the netmap increase by 1.\r
907\r
908 If Map is NULL, then ASSERT().\r
e0e26f9c 909 If Key is NULL, then ASSERT().\r
1204fe83 910\r
ae213b7d 911 @param[in, out] Map The netmap to insert into.\r
912 @param[in] Key The user's key.\r
913 @param[in] Value The user's value for the key.\r
97b38d4e 914\r
ae213b7d 915 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item.\r
916 @retval EFI_SUCCESS The item is inserted to the tail.\r
97b38d4e 917\r
918**/\r
919EFI_STATUS\r
920EFIAPI\r
921NetMapInsertTail (\r
d1050b9d
MK
922 IN OUT NET_MAP *Map,\r
923 IN VOID *Key,\r
924 IN VOID *Value OPTIONAL\r
97b38d4e 925 );\r
926\r
927/**\r
e9b67286 928 Finds the key in the netmap and returns the point to the item containing the Key.\r
1204fe83 929\r
930 Iterate the Used doubly linked list of the netmap to get every item. Compare the key of every\r
3a1ab4bc 931 item with the key to search. It returns the point to the item contains the Key if found.\r
97b38d4e 932\r
3a1ab4bc 933 If Map is NULL, then ASSERT().\r
e0e26f9c 934 If Key is NULL, then ASSERT().\r
1204fe83 935\r
ae213b7d 936 @param[in] Map The netmap to search within.\r
937 @param[in] Key The key to search.\r
97b38d4e 938\r
939 @return The point to the item contains the Key, or NULL if Key isn't in the map.\r
940\r
941**/\r
ae213b7d 942NET_MAP_ITEM *\r
97b38d4e 943EFIAPI\r
944NetMapFindKey (\r
d1050b9d
MK
945 IN NET_MAP *Map,\r
946 IN VOID *Key\r
97b38d4e 947 );\r
948\r
949/**\r
3a1ab4bc 950 Remove the node entry of the item from the netmap and return the key of the removed item.\r
1204fe83 951\r
952 Remove the node entry of the item from the Used doubly linked list of the netmap.\r
953 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node\r
3a1ab4bc 954 entry of the item to the Recycled doubly linked list of the netmap. If Value is not NULL,\r
955 Value will point to the value of the item. It returns the key of the removed item.\r
1204fe83 956\r
3a1ab4bc 957 If Map is NULL, then ASSERT().\r
958 If Item is NULL, then ASSERT().\r
959 if item in not in the netmap, then ASSERT().\r
1204fe83 960\r
ae213b7d 961 @param[in, out] Map The netmap to remove the item from.\r
962 @param[in, out] Item The item to remove.\r
963 @param[out] Value The variable to receive the value if not NULL.\r
97b38d4e 964\r
ae213b7d 965 @return The key of the removed item.\r
97b38d4e 966\r
967**/\r
968VOID *\r
969EFIAPI\r
970NetMapRemoveItem (\r
d1050b9d
MK
971 IN OUT NET_MAP *Map,\r
972 IN OUT NET_MAP_ITEM *Item,\r
973 OUT VOID **Value OPTIONAL\r
97b38d4e 974 );\r
975\r
976/**\r
3a1ab4bc 977 Remove the first node entry on the netmap and return the key of the removed item.\r
97b38d4e 978\r
1204fe83 979 Remove the first node entry from the Used doubly linked list of the netmap.\r
980 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node\r
3a1ab4bc 981 entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,\r
982 parameter Value will point to the value of the item. It returns the key of the removed item.\r
1204fe83 983\r
3a1ab4bc 984 If Map is NULL, then ASSERT().\r
985 If the Used doubly linked list is empty, then ASSERT().\r
1204fe83 986\r
ae213b7d 987 @param[in, out] Map The netmap to remove the head from.\r
988 @param[out] Value The variable to receive the value if not NULL.\r
97b38d4e 989\r
ae213b7d 990 @return The key of the item removed.\r
97b38d4e 991\r
992**/\r
993VOID *\r
994EFIAPI\r
995NetMapRemoveHead (\r
d1050b9d
MK
996 IN OUT NET_MAP *Map,\r
997 OUT VOID **Value OPTIONAL\r
97b38d4e 998 );\r
999\r
1000/**\r
3a1ab4bc 1001 Remove the last node entry on the netmap and return the key of the removed item.\r
97b38d4e 1002\r
1204fe83 1003 Remove the last node entry from the Used doubly linked list of the netmap.\r
1004 The number of the <Key, Value> pairs in the netmap decrease by 1. Then add the node\r
3a1ab4bc 1005 entry to the Recycled doubly linked list of the netmap. If parameter Value is not NULL,\r
1006 parameter Value will point to the value of the item. It returns the key of the removed item.\r
1204fe83 1007\r
3a1ab4bc 1008 If Map is NULL, then ASSERT().\r
1009 If the Used doubly linked list is empty, then ASSERT().\r
1204fe83 1010\r
ae213b7d 1011 @param[in, out] Map The netmap to remove the tail from.\r
1012 @param[out] Value The variable to receive the value if not NULL.\r
97b38d4e 1013\r
ae213b7d 1014 @return The key of the item removed.\r
97b38d4e 1015\r
1016**/\r
1017VOID *\r
1018EFIAPI\r
1019NetMapRemoveTail (\r
d1050b9d
MK
1020 IN OUT NET_MAP *Map,\r
1021 OUT VOID **Value OPTIONAL\r
97b38d4e 1022 );\r
1023\r
1024typedef\r
1025EFI_STATUS\r
d1050b9d 1026(EFIAPI *NET_MAP_CALLBACK)(\r
97b38d4e 1027 IN NET_MAP *Map,\r
1028 IN NET_MAP_ITEM *Item,\r
1029 IN VOID *Arg\r
1030 );\r
1031\r
1032/**\r
3a1ab4bc 1033 Iterate through the netmap and call CallBack for each item.\r
1204fe83 1034\r
86ac8fb2 1035 It will continue the traverse if CallBack returns EFI_SUCCESS, otherwise, break\r
1204fe83 1036 from the loop. It returns the CallBack's last return value. This function is\r
3a1ab4bc 1037 delete safe for the current item.\r
97b38d4e 1038\r
3a1ab4bc 1039 If Map is NULL, then ASSERT().\r
1040 If CallBack is NULL, then ASSERT().\r
1204fe83 1041\r
ae213b7d 1042 @param[in] Map The Map to iterate through.\r
1043 @param[in] CallBack The callback function to call for each item.\r
1044 @param[in] Arg The opaque parameter to the callback.\r
97b38d4e 1045\r
64a80549 1046 @retval EFI_SUCCESS There is no item in the netmap, or CallBack for each item\r
1047 returns EFI_SUCCESS.\r
ae213b7d 1048 @retval Others It returns the CallBack's last return value.\r
97b38d4e 1049\r
1050**/\r
1051EFI_STATUS\r
1052EFIAPI\r
1053NetMapIterate (\r
d1050b9d
MK
1054 IN NET_MAP *Map,\r
1055 IN NET_MAP_CALLBACK CallBack,\r
1056 IN VOID *Arg OPTIONAL\r
97b38d4e 1057 );\r
1058\r
97b38d4e 1059//\r
1060// Helper functions to implement driver binding and service binding protocols.\r
1061//\r
d1050b9d 1062\r
97b38d4e 1063/**\r
1064 Create a child of the service that is identified by ServiceBindingGuid.\r
1204fe83 1065\r
3a1ab4bc 1066 Get the ServiceBinding Protocol first, then use it to create a child.\r
97b38d4e 1067\r
3a1ab4bc 1068 If ServiceBindingGuid is NULL, then ASSERT().\r
1069 If ChildHandle is NULL, then ASSERT().\r
1204fe83 1070\r
ae213b7d 1071 @param[in] Controller The controller which has the service installed.\r
1072 @param[in] Image The image handle used to open service.\r
1073 @param[in] ServiceBindingGuid The service's Guid.\r
e9b67286 1074 @param[in, out] ChildHandle The handle to receive the created child.\r
97b38d4e 1075\r
e9b67286 1076 @retval EFI_SUCCESS The child was successfully created.\r
97b38d4e 1077 @retval Others Failed to create the child.\r
1078\r
1079**/\r
1080EFI_STATUS\r
1081EFIAPI\r
1082NetLibCreateServiceChild (\r
d1050b9d
MK
1083 IN EFI_HANDLE Controller,\r
1084 IN EFI_HANDLE Image,\r
1085 IN EFI_GUID *ServiceBindingGuid,\r
1086 IN OUT EFI_HANDLE *ChildHandle\r
97b38d4e 1087 );\r
1088\r
1089/**\r
e9b67286 1090 Destroy a child of the service that is identified by ServiceBindingGuid.\r
1204fe83 1091\r
3a1ab4bc 1092 Get the ServiceBinding Protocol first, then use it to destroy a child.\r
1204fe83 1093\r
3a1ab4bc 1094 If ServiceBindingGuid is NULL, then ASSERT().\r
1204fe83 1095\r
ae213b7d 1096 @param[in] Controller The controller which has the service installed.\r
1097 @param[in] Image The image handle used to open service.\r
1098 @param[in] ServiceBindingGuid The service's Guid.\r
e9b67286 1099 @param[in] ChildHandle The child to destroy.\r
97b38d4e 1100\r
64a80549 1101 @retval EFI_SUCCESS The child was destroyed.\r
e9b67286 1102 @retval Others Failed to destroy the child.\r
97b38d4e 1103\r
1104**/\r
1105EFI_STATUS\r
1106EFIAPI\r
1107NetLibDestroyServiceChild (\r
d1050b9d
MK
1108 IN EFI_HANDLE Controller,\r
1109 IN EFI_HANDLE Image,\r
1110 IN EFI_GUID *ServiceBindingGuid,\r
1111 IN EFI_HANDLE ChildHandle\r
97b38d4e 1112 );\r
1113\r
1114/**\r
779ae357 1115 Get handle with Simple Network Protocol installed on it.\r
1116\r
1117 There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r
1118 If Simple Network Protocol is already installed on the ServiceHandle, the\r
1119 ServiceHandle will be returned. If SNP is not installed on the ServiceHandle,\r
1120 try to find its parent handle with SNP installed.\r
1121\r
1122 @param[in] ServiceHandle The handle where network service binding protocols are\r
1123 installed on.\r
1124 @param[out] Snp The pointer to store the address of the SNP instance.\r
1125 This is an optional parameter that may be NULL.\r
1126\r
1127 @return The SNP handle, or NULL if not found.\r
1128\r
1129**/\r
1130EFI_HANDLE\r
1131EFIAPI\r
1132NetLibGetSnpHandle (\r
d1050b9d
MK
1133 IN EFI_HANDLE ServiceHandle,\r
1134 OUT EFI_SIMPLE_NETWORK_PROTOCOL **Snp OPTIONAL\r
779ae357 1135 );\r
1136\r
1137/**\r
1138 Retrieve VLAN ID of a VLAN device handle.\r
1139\r
1140 Search VLAN device path node in Device Path of specified ServiceHandle and\r
1141 return its VLAN ID. If no VLAN device path node found, then this ServiceHandle\r
1142 is not a VLAN device handle, and 0 will be returned.\r
1143\r
1144 @param[in] ServiceHandle The handle where network service binding protocols are\r
1145 installed on.\r
1146\r
1147 @return VLAN ID of the device handle, or 0 if not a VLAN device.\r
97b38d4e 1148\r
779ae357 1149**/\r
1150UINT16\r
1151EFIAPI\r
1152NetLibGetVlanId (\r
d1050b9d 1153 IN EFI_HANDLE ServiceHandle\r
779ae357 1154 );\r
1155\r
1156/**\r
1157 Find VLAN device handle with specified VLAN ID.\r
1158\r
1159 The VLAN child device handle is created by VLAN Config Protocol on ControllerHandle.\r
1160 This function will append VLAN device path node to the parent device path,\r
1161 and then use LocateDevicePath() to find the correct VLAN device handle.\r
1162\r
e2851998 1163 @param[in] ControllerHandle The handle where network service binding protocols are\r
779ae357 1164 installed on.\r
e2851998 1165 @param[in] VlanId The configured VLAN ID for the VLAN device.\r
779ae357 1166\r
1167 @return The VLAN device handle, or NULL if not found.\r
1168\r
1169**/\r
1170EFI_HANDLE\r
1171EFIAPI\r
1172NetLibGetVlanHandle (\r
d1050b9d
MK
1173 IN EFI_HANDLE ControllerHandle,\r
1174 IN UINT16 VlanId\r
779ae357 1175 );\r
1176\r
1177/**\r
1178 Get MAC address associated with the network service handle.\r
1179\r
e0e26f9c
WF
1180 If MacAddress is NULL, then ASSERT().\r
1181 If AddressSize is NULL, then ASSERT().\r
1182\r
779ae357 1183 There should be MNP Service Binding Protocol installed on the input ServiceHandle.\r
1184 If SNP is installed on the ServiceHandle or its parent handle, MAC address will\r
1185 be retrieved from SNP. If no SNP found, try to get SNP mode data use MNP.\r
1186\r
1187 @param[in] ServiceHandle The handle where network service binding protocols are\r
1188 installed on.\r
1189 @param[out] MacAddress The pointer to store the returned MAC address.\r
1190 @param[out] AddressSize The length of returned MAC address.\r
1191\r
64a80549 1192 @retval EFI_SUCCESS MAC address was returned successfully.\r
779ae357 1193 @retval Others Failed to get SNP mode data.\r
1194\r
1195**/\r
1196EFI_STATUS\r
1197EFIAPI\r
1198NetLibGetMacAddress (\r
d1050b9d
MK
1199 IN EFI_HANDLE ServiceHandle,\r
1200 OUT EFI_MAC_ADDRESS *MacAddress,\r
1201 OUT UINTN *AddressSize\r
779ae357 1202 );\r
1203\r
1204/**\r
1205 Convert MAC address of the NIC associated with specified Service Binding Handle\r
1206 to a unicode string. Callers are responsible for freeing the string storage.\r
3a1ab4bc 1207\r
e0e26f9c
WF
1208 If MacString is NULL, then ASSERT().\r
1209\r
779ae357 1210 Locate simple network protocol associated with the Service Binding Handle and\r
1211 get the mac address from SNP. Then convert the mac address into a unicode\r
1212 string. It takes 2 unicode characters to represent a 1 byte binary buffer.\r
1213 Plus one unicode character for the null-terminator.\r
3a1ab4bc 1214\r
779ae357 1215 @param[in] ServiceHandle The handle where network service binding protocol is\r
64a80549 1216 installed.\r
779ae357 1217 @param[in] ImageHandle The image handle used to act as the agent handle to\r
b00ed21a 1218 get the simple network protocol. This parameter is\r
1219 optional and may be NULL.\r
ae213b7d 1220 @param[out] MacString The pointer to store the address of the string\r
1221 representation of the mac address.\r
1204fe83 1222\r
64a80549 1223 @retval EFI_SUCCESS Converted the mac address a unicode string successfully.\r
1224 @retval EFI_OUT_OF_RESOURCES There are not enough memory resources.\r
ae213b7d 1225 @retval Others Failed to open the simple network protocol.\r
97b38d4e 1226\r
1227**/\r
1228EFI_STATUS\r
1229EFIAPI\r
1230NetLibGetMacString (\r
d1050b9d
MK
1231 IN EFI_HANDLE ServiceHandle,\r
1232 IN EFI_HANDLE ImageHandle OPTIONAL,\r
1233 OUT CHAR16 **MacString\r
97b38d4e 1234 );\r
1235\r
dd29f3ed 1236/**\r
1237 Detect media status for specified network device.\r
1238\r
e0e26f9c
WF
1239 If MediaPresent is NULL, then ASSERT().\r
1240\r
dd29f3ed 1241 The underlying UNDI driver may or may not support reporting media status from\r
1242 GET_STATUS command (PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED). This routine\r
3b1464d5 1243 will try to invoke Snp->GetStatus() to get the media status. If media is already\r
1244 present, it returns directly. If media is not present, it will stop SNP and then\r
d1102dba
LG
1245 restart SNP to get the latest media status. This provides an opportunity to get\r
1246 the correct media status for old UNDI driver, which doesn't support reporting\r
64a80549 1247 media status from GET_STATUS command.\r
1248 Note: there are two limitations for the current algorithm:\r
1249 1) For UNDI with this capability, when the cable is not attached, there will\r
1250 be an redundant Stop/Start() process.\r
3b1464d5 1251 2) for UNDI without this capability, in case that network cable is attached when\r
1252 Snp->Initialize() is invoked while network cable is unattached later,\r
1253 NetLibDetectMedia() will report MediaPresent as TRUE, causing upper layer\r
1254 apps to wait for timeout time.\r
dd29f3ed 1255\r
1256 @param[in] ServiceHandle The handle where network service binding protocols are\r
64a80549 1257 installed.\r
dd29f3ed 1258 @param[out] MediaPresent The pointer to store the media status.\r
1259\r
1260 @retval EFI_SUCCESS Media detection success.\r
64a80549 1261 @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device handle.\r
1262 @retval EFI_UNSUPPORTED The network device does not support media detection.\r
1263 @retval EFI_DEVICE_ERROR SNP is in an unknown state.\r
dd29f3ed 1264\r
1265**/\r
1266EFI_STATUS\r
1267EFIAPI\r
1268NetLibDetectMedia (\r
d1050b9d
MK
1269 IN EFI_HANDLE ServiceHandle,\r
1270 OUT BOOLEAN *MediaPresent\r
dd29f3ed 1271 );\r
1272\r
ca4e4323 1273/**\r
d1102dba
LG
1274 Detect media state for a network device. This routine will wait for a period of time at\r
1275 a specified checking interval when a certain network is under connecting until connection\r
ca4e4323 1276 process finishes or timeout. If Aip protocol is supported by low layer drivers, three kinds\r
1277 of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and EFI_NO_MEDIA, represents\r
d1102dba
LG
1278 connected state, connecting state and no media state respectively. When function detects\r
1279 the current state is EFI_NOT_READY, it will loop to wait for next time's check until state\r
1280 turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supported, function will\r
ca4e4323 1281 call NetLibDetectMedia() and return state directly.\r
1282\r
1283 @param[in] ServiceHandle The handle where network service binding protocols are\r
1284 installed on.\r
1285 @param[in] Timeout The maximum number of 100ns units to wait when network\r
1286 is connecting. Zero value means detect once and return\r
1287 immediately.\r
1288 @param[out] MediaState The pointer to the detected media state.\r
1289\r
1290 @retval EFI_SUCCESS Media detection success.\r
d1102dba 1291 @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device handle or\r
ca4e4323 1292 MediaState pointer is NULL.\r
1293 @retval EFI_DEVICE_ERROR A device error occurred.\r
1294 @retval EFI_TIMEOUT Network is connecting but timeout.\r
1295\r
1296**/\r
1297EFI_STATUS\r
1298EFIAPI\r
1299NetLibDetectMediaWaitTimeout (\r
d1050b9d
MK
1300 IN EFI_HANDLE ServiceHandle,\r
1301 IN UINT64 Timeout,\r
1302 OUT EFI_STATUS *MediaState\r
ca4e4323 1303 );\r
1304\r
97b38d4e 1305/**\r
1306 Create an IPv4 device path node.\r
1204fe83 1307\r
e0e26f9c
WF
1308 If Node is NULL, then ASSERT().\r
1309\r
3a1ab4bc 1310 The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.\r
1311 The header subtype of IPv4 device path node is MSG_IPv4_DP.\r
1312 The length of the IPv4 device path node in bytes is 19.\r
64a80549 1313 Get other information from parameters to make up the whole IPv4 device path node.\r
97b38d4e 1314\r
64a80549 1315 @param[in, out] Node The pointer to the IPv4 device path node.\r
f6b7393c 1316 @param[in] Controller The controller handle.\r
ae213b7d 1317 @param[in] LocalIp The local IPv4 address.\r
1318 @param[in] LocalPort The local port.\r
1319 @param[in] RemoteIp The remote IPv4 address.\r
1320 @param[in] RemotePort The remote port.\r
1321 @param[in] Protocol The protocol type in the IP header.\r
1322 @param[in] UseDefaultAddress Whether this instance is using default address or not.\r
97b38d4e 1323\r
97b38d4e 1324**/\r
1325VOID\r
1326EFIAPI\r
1327NetLibCreateIPv4DPathNode (\r
1328 IN OUT IPv4_DEVICE_PATH *Node,\r
1329 IN EFI_HANDLE Controller,\r
1330 IN IP4_ADDR LocalIp,\r
1331 IN UINT16 LocalPort,\r
1332 IN IP4_ADDR RemoteIp,\r
1333 IN UINT16 RemotePort,\r
1334 IN UINT16 Protocol,\r
1335 IN BOOLEAN UseDefaultAddress\r
1336 );\r
1337\r
f6b7393c 1338/**\r
1339 Create an IPv6 device path node.\r
1204fe83 1340\r
e0e26f9c
WF
1341 If Node is NULL, then ASSERT().\r
1342 If LocalIp is NULL, then ASSERT().\r
1343 If RemoteIp is NULL, then ASSERT().\r
1344\r
f6b7393c 1345 The header type of IPv6 device path node is MESSAGING_DEVICE_PATH.\r
1346 The header subtype of IPv6 device path node is MSG_IPv6_DP.\r
1347 The length of the IPv6 device path node in bytes is 43.\r
64a80549 1348 Get other information from parameters to make up the whole IPv6 device path node.\r
f6b7393c 1349\r
64a80549 1350 @param[in, out] Node The pointer to the IPv6 device path node.\r
f6b7393c 1351 @param[in] Controller The controller handle.\r
1352 @param[in] LocalIp The local IPv6 address.\r
1353 @param[in] LocalPort The local port.\r
1354 @param[in] RemoteIp The remote IPv6 address.\r
1355 @param[in] RemotePort The remote port.\r
1356 @param[in] Protocol The protocol type in the IP header.\r
1357\r
1358**/\r
1359VOID\r
1360EFIAPI\r
1361NetLibCreateIPv6DPathNode (\r
1362 IN OUT IPv6_DEVICE_PATH *Node,\r
1363 IN EFI_HANDLE Controller,\r
1364 IN EFI_IPv6_ADDRESS *LocalIp,\r
1365 IN UINT16 LocalPort,\r
1366 IN EFI_IPv6_ADDRESS *RemoteIp,\r
1367 IN UINT16 RemotePort,\r
1368 IN UINT16 Protocol\r
1369 );\r
1370\r
97b38d4e 1371/**\r
1372 Find the UNDI/SNP handle from controller and protocol GUID.\r
1204fe83 1373\r
e0e26f9c
WF
1374 If ProtocolGuid is NULL, then ASSERT().\r
1375\r
e9b67286 1376 For example, IP will open an MNP child to transmit/receive\r
1377 packets. When MNP is stopped, IP should also be stopped. IP\r
64a80549 1378 needs to find its own private data that is related the IP's\r
1379 service binding instance that is installed on the UNDI/SNP handle.\r
1380 The controller is then either an MNP or an ARP child handle. Note that\r
86ac8fb2 1381 IP opens these handles using BY_DRIVER. Use that information to get the\r
97b38d4e 1382 UNDI/SNP handle.\r
1383\r
64a80549 1384 @param[in] Controller The protocol handle to check.\r
ae213b7d 1385 @param[in] ProtocolGuid The protocol that is related with the handle.\r
97b38d4e 1386\r
ae213b7d 1387 @return The UNDI/SNP handle or NULL for errors.\r
97b38d4e 1388\r
1389**/\r
1390EFI_HANDLE\r
1391EFIAPI\r
1392NetLibGetNicHandle (\r
d1050b9d
MK
1393 IN EFI_HANDLE Controller,\r
1394 IN EFI_GUID *ProtocolGuid\r
97b38d4e 1395 );\r
1396\r
97b38d4e 1397/**\r
1398 This is the default unload handle for all the network drivers.\r
1399\r
3a1ab4bc 1400 Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
1401 Uninstall all the protocols installed in the driver entry point.\r
1204fe83 1402\r
ae213b7d 1403 @param[in] ImageHandle The drivers' driver image.\r
97b38d4e 1404\r
1405 @retval EFI_SUCCESS The image is unloaded.\r
1406 @retval Others Failed to unload the image.\r
1407\r
1408**/\r
1409EFI_STATUS\r
1410EFIAPI\r
1411NetLibDefaultUnload (\r
d1050b9d 1412 IN EFI_HANDLE ImageHandle\r
97b38d4e 1413 );\r
1414\r
e4ef0031 1415/**\r
1416 Convert one Null-terminated ASCII string (decimal dotted) to EFI_IPv4_ADDRESS.\r
1417\r
1418 @param[in] String The pointer to the Ascii string.\r
1419 @param[out] Ip4Address The pointer to the converted IPv4 address.\r
1420\r
64a80549 1421 @retval EFI_SUCCESS Converted to an IPv4 address successfully.\r
86ac8fb2 1422 @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip4Address is NULL.\r
e4ef0031 1423\r
1424**/\r
1425EFI_STATUS\r
e798cd87 1426EFIAPI\r
e4ef0031 1427NetLibAsciiStrToIp4 (\r
d1050b9d
MK
1428 IN CONST CHAR8 *String,\r
1429 OUT EFI_IPv4_ADDRESS *Ip4Address\r
e4ef0031 1430 );\r
1431\r
1432/**\r
1433 Convert one Null-terminated ASCII string to EFI_IPv6_ADDRESS. The format of the\r
86ac8fb2 1434 string is defined in RFC 4291 - Text Representation of Addresses.\r
e4ef0031 1435\r
1436 @param[in] String The pointer to the Ascii string.\r
1437 @param[out] Ip6Address The pointer to the converted IPv6 address.\r
1438\r
64a80549 1439 @retval EFI_SUCCESS Converted to an IPv6 address successfully.\r
86ac8fb2 1440 @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip6Address is NULL.\r
e4ef0031 1441\r
1442**/\r
1443EFI_STATUS\r
e798cd87 1444EFIAPI\r
e4ef0031 1445NetLibAsciiStrToIp6 (\r
d1050b9d
MK
1446 IN CONST CHAR8 *String,\r
1447 OUT EFI_IPv6_ADDRESS *Ip6Address\r
e4ef0031 1448 );\r
1449\r
1450/**\r
1451 Convert one Null-terminated Unicode string (decimal dotted) to EFI_IPv4_ADDRESS.\r
1452\r
1453 @param[in] String The pointer to the Ascii string.\r
1454 @param[out] Ip4Address The pointer to the converted IPv4 address.\r
1455\r
64a80549 1456 @retval EFI_SUCCESS Converted to an IPv4 address successfully.\r
86ac8fb2 1457 @retval EFI_INVALID_PARAMETER The string is mal-formatted or Ip4Address is NULL.\r
e4ef0031 1458\r
1459**/\r
1460EFI_STATUS\r
e798cd87 1461EFIAPI\r
e4ef0031 1462NetLibStrToIp4 (\r
d1050b9d
MK
1463 IN CONST CHAR16 *String,\r
1464 OUT EFI_IPv4_ADDRESS *Ip4Address\r
e4ef0031 1465 );\r
1466\r
1467/**\r
1468 Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS. The format of\r
86ac8fb2 1469 the string is defined in RFC 4291 - Text Representation of Addresses.\r
e4ef0031 1470\r
1471 @param[in] String The pointer to the Ascii string.\r
1472 @param[out] Ip6Address The pointer to the converted IPv6 address.\r
1473\r
64a80549 1474 @retval EFI_SUCCESS Converted to an IPv6 address successfully.\r
86ac8fb2 1475 @retval EFI_INVALID_PARAMETER The string is malformatted or Ip6Address is NULL.\r
e4ef0031 1476\r
1477**/\r
1478EFI_STATUS\r
e798cd87 1479EFIAPI\r
e4ef0031 1480NetLibStrToIp6 (\r
d1050b9d
MK
1481 IN CONST CHAR16 *String,\r
1482 OUT EFI_IPv6_ADDRESS *Ip6Address\r
e4ef0031 1483 );\r
1484\r
1485/**\r
1486 Convert one Null-terminated Unicode string to EFI_IPv6_ADDRESS and prefix length.\r
86ac8fb2 1487 The format of the string is defined in RFC 4291 - Text Representation of Addresses\r
e4ef0031 1488 Prefixes: ipv6-address/prefix-length.\r
1489\r
1490 @param[in] String The pointer to the Ascii string.\r
1491 @param[out] Ip6Address The pointer to the converted IPv6 address.\r
1492 @param[out] PrefixLength The pointer to the converted prefix length.\r
1493\r
64a80549 1494 @retval EFI_SUCCESS Converted to an IPv6 address successfully.\r
86ac8fb2 1495 @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip6Address is NULL.\r
e4ef0031 1496\r
1497**/\r
1498EFI_STATUS\r
e798cd87 1499EFIAPI\r
e4ef0031 1500NetLibStrToIp6andPrefix (\r
d1050b9d
MK
1501 IN CONST CHAR16 *String,\r
1502 OUT EFI_IPv6_ADDRESS *Ip6Address,\r
1503 OUT UINT8 *PrefixLength\r
e4ef0031 1504 );\r
b45b45b2 1505\r
216f7970 1506/**\r
1507\r
1508 Convert one EFI_IPv6_ADDRESS to Null-terminated Unicode string.\r
1509 The text representation of address is defined in RFC 4291.\r
d1102dba 1510\r
216f7970 1511 @param[in] Ip6Address The pointer to the IPv6 address.\r
1512 @param[out] String The buffer to return the converted string.\r
1513 @param[in] StringSize The length in bytes of the input String.\r
d1102dba 1514\r
216f7970 1515 @retval EFI_SUCCESS Convert to string successfully.\r
1516 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
d1102dba 1517 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small for the result. BufferSize has been\r
216f7970 1518 updated with the size needed to complete the request.\r
1519**/\r
1520EFI_STATUS\r
1521EFIAPI\r
1522NetLibIp6ToStr (\r
d1050b9d
MK
1523 IN EFI_IPv6_ADDRESS *Ip6Address,\r
1524 OUT CHAR16 *String,\r
1525 IN UINTN StringSize\r
216f7970 1526 );\r
1527\r
b45b45b2 1528//\r
e4ef0031 1529// Various signatures\r
b45b45b2 1530//\r
d1050b9d
MK
1531#define NET_BUF_SIGNATURE SIGNATURE_32 ('n', 'b', 'u', 'f')\r
1532#define NET_VECTOR_SIGNATURE SIGNATURE_32 ('n', 'v', 'e', 'c')\r
1533#define NET_QUE_SIGNATURE SIGNATURE_32 ('n', 'b', 'q', 'u')\r
97b38d4e 1534\r
d1050b9d
MK
1535#define NET_PROTO_DATA 64 // Opaque buffer for protocols\r
1536#define NET_BUF_HEAD 1 // Trim or allocate space from head\r
1537#define NET_BUF_TAIL 0 // Trim or allocate space from tail\r
1538#define NET_VECTOR_OWN_FIRST 0x01 // We allocated the 1st block in the vector\r
97b38d4e 1539\r
1540#define NET_CHECK_SIGNATURE(PData, SIGNATURE) \\r
1541 ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))\r
1542\r
97b38d4e 1543//\r
1544// Single memory block in the vector.\r
1545//\r
1546typedef struct {\r
d1050b9d
MK
1547 UINT32 Len; // The block's length\r
1548 UINT8 *Bulk; // The block's Data\r
97b38d4e 1549} NET_BLOCK;\r
1550\r
d1050b9d 1551typedef VOID (EFIAPI *NET_VECTOR_EXT_FREE)(VOID *Arg);\r
97b38d4e 1552\r
1553//\r
d1050b9d
MK
1554// NET_VECTOR contains several blocks to hold all packet's\r
1555// fragments and other house-keeping stuff for sharing. It\r
1556// doesn't specify the where actual packet fragment begins.\r
97b38d4e 1557//\r
1558typedef struct {\r
d1050b9d
MK
1559 UINT32 Signature;\r
1560 INTN RefCnt; // Reference count to share NET_VECTOR.\r
1561 NET_VECTOR_EXT_FREE Free; // external function to free NET_VECTOR\r
1562 VOID *Arg; // opaque argument to Free\r
1563 UINT32 Flag; // Flags, NET_VECTOR_OWN_FIRST\r
1564 UINT32 Len; // Total length of the associated BLOCKs\r
1565\r
1566 UINT32 BlockNum;\r
1567 NET_BLOCK Block[1];\r
97b38d4e 1568} NET_VECTOR;\r
1569\r
1570//\r
d1050b9d
MK
1571// NET_BLOCK_OP operates on the NET_BLOCK. It specifies\r
1572// where the actual fragment begins and ends\r
97b38d4e 1573//\r
1574typedef struct {\r
d1050b9d
MK
1575 UINT8 *BlockHead; // Block's head, or the smallest valid Head\r
1576 UINT8 *BlockTail; // Block's tail. BlockTail-BlockHead=block length\r
1577 UINT8 *Head; // 1st byte of the data in the block\r
1578 UINT8 *Tail; // Tail of the data in the block, Tail-Head=Size\r
1579 UINT32 Size; // The size of the data\r
97b38d4e 1580} NET_BLOCK_OP;\r
1581\r
f6b7393c 1582typedef union {\r
1583 IP4_HEAD *Ip4;\r
1584 EFI_IP6_HEADER *Ip6;\r
1585} NET_IP_HEAD;\r
97b38d4e 1586\r
1587//\r
d1050b9d
MK
1588// NET_BUF is the buffer manage structure used by the\r
1589// network stack. Every network packet may be fragmented. The Vector points to\r
1590// memory blocks used by each fragment, and BlockOp\r
1591// specifies where each fragment begins and ends.\r
97b38d4e 1592//\r
d1050b9d
MK
1593// It also contains an opaque area for the protocol to store\r
1594// per-packet information. Protocol must be careful not\r
1595// to overwrite the members after that.\r
97b38d4e 1596//\r
1597typedef struct {\r
d1050b9d
MK
1598 UINT32 Signature;\r
1599 INTN RefCnt;\r
1600 LIST_ENTRY List; // The List this NET_BUF is on\r
97b38d4e 1601\r
d1050b9d
MK
1602 NET_IP_HEAD Ip; // Network layer header, for fast access\r
1603 TCP_HEAD *Tcp; // Transport layer header, for fast access\r
1604 EFI_UDP_HEADER *Udp; // User Datagram Protocol header\r
1605 UINT8 ProtoData[NET_PROTO_DATA]; // Protocol specific data\r
97b38d4e 1606\r
d1050b9d 1607 NET_VECTOR *Vector; // The vector containing the packet\r
97b38d4e 1608\r
d1050b9d
MK
1609 UINT32 BlockOpNum; // Total number of BlockOp in the buffer\r
1610 UINT32 TotalSize; // Total size of the actual packet\r
1611 NET_BLOCK_OP BlockOp[1]; // Specify the position of actual packet\r
97b38d4e 1612} NET_BUF;\r
1613\r
97b38d4e 1614//\r
d1050b9d
MK
1615// A queue of NET_BUFs. It is a thin extension of\r
1616// NET_BUF functions.\r
97b38d4e 1617//\r
1618typedef struct {\r
d1050b9d
MK
1619 UINT32 Signature;\r
1620 INTN RefCnt;\r
1621 LIST_ENTRY List; // The List this buffer queue is on\r
97b38d4e 1622\r
d1050b9d
MK
1623 LIST_ENTRY BufList; // list of queued buffers\r
1624 UINT32 BufSize; // total length of DATA in the buffers\r
1625 UINT32 BufNum; // total number of buffers on the chain\r
97b38d4e 1626} NET_BUF_QUEUE;\r
1627\r
1628//\r
1629// Pseudo header for TCP and UDP checksum\r
1630//\r
1631#pragma pack(1)\r
1632typedef struct {\r
d1050b9d
MK
1633 IP4_ADDR SrcIp;\r
1634 IP4_ADDR DstIp;\r
1635 UINT8 Reserved;\r
1636 UINT8 Protocol;\r
1637 UINT16 Len;\r
97b38d4e 1638} NET_PSEUDO_HDR;\r
f6b7393c 1639\r
1640typedef struct {\r
1641 EFI_IPv6_ADDRESS SrcIp;\r
1642 EFI_IPv6_ADDRESS DstIp;\r
1643 UINT32 Len;\r
d1050b9d
MK
1644 UINT32 Reserved : 24;\r
1645 UINT32 NextHeader : 8;\r
f6b7393c 1646} NET_IP6_PSEUDO_HDR;\r
97b38d4e 1647#pragma pack()\r
1648\r
1649//\r
1650// The fragment entry table used in network interfaces. This is\r
1651// the same as NET_BLOCK now. Use two different to distinguish\r
1652// the two in case that NET_BLOCK be enhanced later.\r
1653//\r
1654typedef struct {\r
d1050b9d
MK
1655 UINT32 Len;\r
1656 UINT8 *Bulk;\r
97b38d4e 1657} NET_FRAGMENT;\r
1658\r
d1050b9d
MK
1659#define NET_GET_REF(PData) ((PData)->RefCnt++)\r
1660#define NET_PUT_REF(PData) ((PData)->RefCnt--)\r
1661#define NETBUF_FROM_PROTODATA(Info) BASE_CR((Info), NET_BUF, ProtoData)\r
97b38d4e 1662\r
1663#define NET_BUF_SHARED(Buf) \\r
1664 (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))\r
1665\r
1666#define NET_VECTOR_SIZE(BlockNum) \\r
1667 (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))\r
1668\r
1669#define NET_BUF_SIZE(BlockOpNum) \\r
1670 (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))\r
1671\r
1672#define NET_HEADSPACE(BlockOp) \\r
809e2bbf 1673 ((UINTN)((BlockOp)->Head) - (UINTN)((BlockOp)->BlockHead))\r
97b38d4e 1674\r
1675#define NET_TAILSPACE(BlockOp) \\r
809e2bbf 1676 ((UINTN)((BlockOp)->BlockTail) - (UINTN)((BlockOp)->Tail))\r
97b38d4e 1677\r
1678/**\r
1679 Allocate a single block NET_BUF. Upon allocation, all the\r
1680 free space is in the tail room.\r
1681\r
ae213b7d 1682 @param[in] Len The length of the block.\r
97b38d4e 1683\r
64a80549 1684 @return The pointer to the allocated NET_BUF, or NULL if the\r
1685 allocation failed due to resource limitations.\r
97b38d4e 1686\r
1687**/\r
1688NET_BUF *\r
1689EFIAPI\r
1690NetbufAlloc (\r
d1050b9d 1691 IN UINT32 Len\r
97b38d4e 1692 );\r
1693\r
1694/**\r
7557df4d 1695 Free the net buffer and its associated NET_VECTOR.\r
1204fe83 1696\r
7557df4d 1697 Decrease the reference count of the net buffer by one. Free the associated net\r
1204fe83 1698 vector and itself if the reference count of the net buffer is decreased to 0.\r
1699 The net vector free operation decreases the reference count of the net\r
e9b67286 1700 vector by one, and performs the resource free operation when the reference count\r
1204fe83 1701 of the net vector is 0.\r
1702\r
64a80549 1703 @param[in] Nbuf The pointer to the NET_BUF to be freed.\r
97b38d4e 1704\r
1705**/\r
1706VOID\r
1707EFIAPI\r
1708NetbufFree (\r
d1050b9d 1709 IN NET_BUF *Nbuf\r
97b38d4e 1710 );\r
1711\r
1712/**\r
1204fe83 1713 Get the index of NET_BLOCK_OP that contains the byte at Offset in the net\r
1714 buffer.\r
1715\r
1716 For example, this function can be used to retrieve the IP header in the packet. It\r
1717 also can be used to get the fragment that contains the byte used\r
1718 mainly by the library implementation itself.\r
97b38d4e 1719\r
64a80549 1720 @param[in] Nbuf The pointer to the net buffer.\r
7557df4d 1721 @param[in] Offset The offset of the byte.\r
1204fe83 1722 @param[out] Index Index of the NET_BLOCK_OP that contains the byte at\r
7557df4d 1723 Offset.\r
97b38d4e 1724\r
64a80549 1725 @return The pointer to the Offset'th byte of data in the net buffer, or NULL\r
7557df4d 1726 if there is no such data in the net buffer.\r
97b38d4e 1727\r
1728**/\r
1729UINT8 *\r
1730EFIAPI\r
1731NetbufGetByte (\r
d1050b9d
MK
1732 IN NET_BUF *Nbuf,\r
1733 IN UINT32 Offset,\r
1734 OUT UINT32 *Index OPTIONAL\r
97b38d4e 1735 );\r
1736\r
1737/**\r
1204fe83 1738 Create a copy of the net buffer that shares the associated net vector.\r
1739\r
1740 The reference count of the newly created net buffer is set to 1. The reference\r
1741 count of the associated net vector is increased by one.\r
97b38d4e 1742\r
64a80549 1743 @param[in] Nbuf The pointer to the net buffer to be cloned.\r
97b38d4e 1744\r
64a80549 1745 @return The pointer to the cloned net buffer, or NULL if the\r
1746 allocation failed due to resource limitations.\r
97b38d4e 1747\r
1748**/\r
7557df4d 1749NET_BUF *\r
97b38d4e 1750EFIAPI\r
1751NetbufClone (\r
d1050b9d 1752 IN NET_BUF *Nbuf\r
97b38d4e 1753 );\r
1754\r
1755/**\r
7557df4d 1756 Create a duplicated copy of the net buffer with data copied and HeadSpace\r
1757 bytes of head space reserved.\r
1204fe83 1758\r
7557df4d 1759 The duplicated net buffer will allocate its own memory to hold the data of the\r
1760 source net buffer.\r
1204fe83 1761\r
64a80549 1762 @param[in] Nbuf The pointer to the net buffer to be duplicated from.\r
1763 @param[in, out] Duplicate The pointer to the net buffer to duplicate to. If\r
1764 NULL, a new net buffer is allocated.\r
1765 @param[in] HeadSpace The length of the head space to reserve.\r
7557df4d 1766\r
64a80549 1767 @return The pointer to the duplicated net buffer, or NULL if\r
1768 the allocation failed due to resource limitations.\r
97b38d4e 1769\r
1770**/\r
1771NET_BUF *\r
1772EFIAPI\r
1773NetbufDuplicate (\r
d1050b9d
MK
1774 IN NET_BUF *Nbuf,\r
1775 IN OUT NET_BUF *Duplicate OPTIONAL,\r
1776 IN UINT32 HeadSpace\r
97b38d4e 1777 );\r
1778\r
1779/**\r
1204fe83 1780 Create a NET_BUF structure which contains Len byte data of Nbuf starting from\r
1781 Offset.\r
1782\r
1783 A new NET_BUF structure will be created but the associated data in NET_VECTOR\r
64a80549 1784 is shared. This function exists to perform IP packet fragmentation.\r
7557df4d 1785\r
64a80549 1786 @param[in] Nbuf The pointer to the net buffer to be extracted.\r
1204fe83 1787 @param[in] Offset Starting point of the data to be included in the new\r
7557df4d 1788 net buffer.\r
64a80549 1789 @param[in] Len The bytes of data to be included in the new net buffer.\r
1790 @param[in] HeadSpace The bytes of the head space to reserve for the protocol header.\r
7557df4d 1791\r
64a80549 1792 @return The pointer to the cloned net buffer, or NULL if the\r
1793 allocation failed due to resource limitations.\r
97b38d4e 1794\r
1795**/\r
1796NET_BUF *\r
1797EFIAPI\r
1798NetbufGetFragment (\r
d1050b9d
MK
1799 IN NET_BUF *Nbuf,\r
1800 IN UINT32 Offset,\r
1801 IN UINT32 Len,\r
1802 IN UINT32 HeadSpace\r
97b38d4e 1803 );\r
1804\r
1805/**\r
7557df4d 1806 Reserve some space in the header room of the net buffer.\r
1807\r
1204fe83 1808 Upon allocation, all the space is in the tail room of the buffer. Call this\r
64a80549 1809 function to move space to the header room. This function is quite limited\r
1204fe83 1810 in that it can only reserve space from the first block of an empty NET_BUF not\r
64a80549 1811 built from the external. However, it should be enough for the network stack.\r
97b38d4e 1812\r
64a80549 1813 @param[in, out] Nbuf The pointer to the net buffer.\r
7557df4d 1814 @param[in] Len The length of buffer to be reserved from the header.\r
97b38d4e 1815\r
1816**/\r
1817VOID\r
1818EFIAPI\r
1819NetbufReserve (\r
d1050b9d
MK
1820 IN OUT NET_BUF *Nbuf,\r
1821 IN UINT32 Len\r
97b38d4e 1822 );\r
1823\r
1824/**\r
1204fe83 1825 Allocate Len bytes of space from the header or tail of the buffer.\r
97b38d4e 1826\r
64a80549 1827 @param[in, out] Nbuf The pointer to the net buffer.\r
7557df4d 1828 @param[in] Len The length of the buffer to be allocated.\r
64a80549 1829 @param[in] FromHead The flag to indicate whether to reserve the data\r
7557df4d 1830 from head (TRUE) or tail (FALSE).\r
97b38d4e 1831\r
64a80549 1832 @return The pointer to the first byte of the allocated buffer,\r
1833 or NULL, if there is no sufficient space.\r
97b38d4e 1834\r
1835**/\r
d1050b9d 1836UINT8 *\r
97b38d4e 1837EFIAPI\r
1838NetbufAllocSpace (\r
d1050b9d
MK
1839 IN OUT NET_BUF *Nbuf,\r
1840 IN UINT32 Len,\r
1841 IN BOOLEAN FromHead\r
97b38d4e 1842 );\r
1843\r
1844/**\r
64a80549 1845 Trim Len bytes from the header or the tail of the net buffer.\r
97b38d4e 1846\r
64a80549 1847 @param[in, out] Nbuf The pointer to the net buffer.\r
7557df4d 1848 @param[in] Len The length of the data to be trimmed.\r
d1102dba 1849 @param[in] FromHead The flag to indicate whether trim data is from the\r
64a80549 1850 head (TRUE) or the tail (FALSE).\r
97b38d4e 1851\r
64a80549 1852 @return The length of the actual trimmed data, which may be less\r
e9b67286 1853 than Len if the TotalSize of Nbuf is less than Len.\r
97b38d4e 1854\r
1855**/\r
1856UINT32\r
1857EFIAPI\r
1858NetbufTrim (\r
d1050b9d
MK
1859 IN OUT NET_BUF *Nbuf,\r
1860 IN UINT32 Len,\r
1861 IN BOOLEAN FromHead\r
97b38d4e 1862 );\r
1863\r
1864/**\r
1204fe83 1865 Copy Len bytes of data from the specific offset of the net buffer to the\r
7557df4d 1866 destination memory.\r
1204fe83 1867\r
e9b67286 1868 The Len bytes of data may cross several fragments of the net buffer.\r
1204fe83 1869\r
64a80549 1870 @param[in] Nbuf The pointer to the net buffer.\r
7557df4d 1871 @param[in] Offset The sequence number of the first byte to copy.\r
64a80549 1872 @param[in] Len The length of the data to copy.\r
7557df4d 1873 @param[in] Dest The destination of the data to copy to.\r
1874\r
1875 @return The length of the actual copied data, or 0 if the offset\r
361468ed 1876 specified exceeds the total size of net buffer.\r
97b38d4e 1877\r
1878**/\r
1879UINT32\r
1880EFIAPI\r
1881NetbufCopy (\r
d1050b9d
MK
1882 IN NET_BUF *Nbuf,\r
1883 IN UINT32 Offset,\r
1884 IN UINT32 Len,\r
1885 IN UINT8 *Dest\r
97b38d4e 1886 );\r
1887\r
1888/**\r
1204fe83 1889 Build a NET_BUF from external blocks.\r
1890\r
e9b67286 1891 A new NET_BUF structure will be created from external blocks. An additional block\r
7557df4d 1892 of memory will be allocated to hold reserved HeadSpace bytes of header room\r
e9b67286 1893 and existing HeadLen bytes of header, but the external blocks are shared by the\r
7557df4d 1894 net buffer to avoid data copying.\r
97b38d4e 1895\r
64a80549 1896 @param[in] ExtFragment The pointer to the data block.\r
7557df4d 1897 @param[in] ExtNum The number of the data blocks.\r
ae213b7d 1898 @param[in] HeadSpace The head space to be reserved.\r
e9b67286 1899 @param[in] HeadLen The length of the protocol header. The function\r
1900 pulls this amount of data into a linear block.\r
64a80549 1901 @param[in] ExtFree The pointer to the caller-provided free function.\r
ae213b7d 1902 @param[in] Arg The argument passed to ExtFree when ExtFree is\r
1903 called.\r
97b38d4e 1904\r
64a80549 1905 @return The pointer to the net buffer built from the data blocks,\r
7557df4d 1906 or NULL if the allocation failed due to resource\r
1907 limit.\r
97b38d4e 1908\r
1909**/\r
1910NET_BUF *\r
1911EFIAPI\r
1912NetbufFromExt (\r
d1050b9d
MK
1913 IN NET_FRAGMENT *ExtFragment,\r
1914 IN UINT32 ExtNum,\r
1915 IN UINT32 HeadSpace,\r
1916 IN UINT32 HeadLen,\r
1917 IN NET_VECTOR_EXT_FREE ExtFree,\r
1918 IN VOID *Arg OPTIONAL\r
97b38d4e 1919 );\r
1920\r
1921/**\r
7557df4d 1922 Build a fragment table to contain the fragments in the net buffer. This is the\r
1204fe83 1923 opposite operation of the NetbufFromExt.\r
1924\r
64a80549 1925 @param[in] Nbuf Points to the net buffer.\r
1926 @param[in, out] ExtFragment The pointer to the data block.\r
7557df4d 1927 @param[in, out] ExtNum The number of the data blocks.\r
97b38d4e 1928\r
1204fe83 1929 @retval EFI_BUFFER_TOO_SMALL The number of non-empty blocks is bigger than\r
7557df4d 1930 ExtNum.\r
64a80549 1931 @retval EFI_SUCCESS The fragment table was built successfully.\r
97b38d4e 1932\r
1933**/\r
1934EFI_STATUS\r
1935EFIAPI\r
1936NetbufBuildExt (\r
d1050b9d
MK
1937 IN NET_BUF *Nbuf,\r
1938 IN OUT NET_FRAGMENT *ExtFragment,\r
1939 IN OUT UINT32 *ExtNum\r
97b38d4e 1940 );\r
1941\r
1942/**\r
7557df4d 1943 Build a net buffer from a list of net buffers.\r
1204fe83 1944\r
64a80549 1945 All the fragments will be collected from the list of NEW_BUF, and then a new\r
1204fe83 1946 net buffer will be created through NetbufFromExt.\r
1947\r
7557df4d 1948 @param[in] BufList A List of the net buffer.\r
1949 @param[in] HeadSpace The head space to be reserved.\r
e9b67286 1950 @param[in] HeaderLen The length of the protocol header. The function\r
1951 pulls this amount of data into a linear block.\r
64a80549 1952 @param[in] ExtFree The pointer to the caller provided free function.\r
7557df4d 1953 @param[in] Arg The argument passed to ExtFree when ExtFree is called.\r
1954\r
64a80549 1955 @return The pointer to the net buffer built from the list of net\r
7557df4d 1956 buffers.\r
97b38d4e 1957\r
1958**/\r
1959NET_BUF *\r
1960EFIAPI\r
1961NetbufFromBufList (\r
d1050b9d
MK
1962 IN LIST_ENTRY *BufList,\r
1963 IN UINT32 HeadSpace,\r
1964 IN UINT32 HeaderLen,\r
1965 IN NET_VECTOR_EXT_FREE ExtFree,\r
1966 IN VOID *Arg OPTIONAL\r
97b38d4e 1967 );\r
1968\r
1969/**\r
1970 Free a list of net buffers.\r
1971\r
64a80549 1972 @param[in, out] Head The pointer to the head of linked net buffers.\r
97b38d4e 1973\r
1974**/\r
1975VOID\r
1976EFIAPI\r
1977NetbufFreeList (\r
d1050b9d 1978 IN OUT LIST_ENTRY *Head\r
97b38d4e 1979 );\r
1980\r
1981/**\r
1982 Initiate the net buffer queue.\r
1983\r
64a80549 1984 @param[in, out] NbufQue The pointer to the net buffer queue to be initialized.\r
97b38d4e 1985\r
1986**/\r
1987VOID\r
1988EFIAPI\r
1989NetbufQueInit (\r
d1050b9d 1990 IN OUT NET_BUF_QUEUE *NbufQue\r
97b38d4e 1991 );\r
1992\r
1993/**\r
7557df4d 1994 Allocate and initialize a net buffer queue.\r
97b38d4e 1995\r
64a80549 1996 @return The pointer to the allocated net buffer queue, or NULL if the\r
7557df4d 1997 allocation failed due to resource limit.\r
97b38d4e 1998\r
1999**/\r
2000NET_BUF_QUEUE *\r
2001EFIAPI\r
2002NetbufQueAlloc (\r
2003 VOID\r
2004 );\r
2005\r
2006/**\r
1204fe83 2007 Free a net buffer queue.\r
2008\r
7557df4d 2009 Decrease the reference count of the net buffer queue by one. The real resource\r
1204fe83 2010 free operation isn't performed until the reference count of the net buffer\r
7557df4d 2011 queue is decreased to 0.\r
97b38d4e 2012\r
64a80549 2013 @param[in] NbufQue The pointer to the net buffer queue to be freed.\r
97b38d4e 2014\r
2015**/\r
2016VOID\r
2017EFIAPI\r
2018NetbufQueFree (\r
d1050b9d 2019 IN NET_BUF_QUEUE *NbufQue\r
97b38d4e 2020 );\r
2021\r
2022/**\r
7557df4d 2023 Remove a net buffer from the head in the specific queue and return it.\r
97b38d4e 2024\r
64a80549 2025 @param[in, out] NbufQue The pointer to the net buffer queue.\r
97b38d4e 2026\r
64a80549 2027 @return The pointer to the net buffer removed from the specific queue,\r
7557df4d 2028 or NULL if there is no net buffer in the specific queue.\r
97b38d4e 2029\r
2030**/\r
2031NET_BUF *\r
2032EFIAPI\r
2033NetbufQueRemove (\r
d1050b9d 2034 IN OUT NET_BUF_QUEUE *NbufQue\r
97b38d4e 2035 );\r
2036\r
2037/**\r
7557df4d 2038 Append a net buffer to the net buffer queue.\r
97b38d4e 2039\r
64a80549 2040 @param[in, out] NbufQue The pointer to the net buffer queue.\r
2041 @param[in, out] Nbuf The pointer to the net buffer to be appended.\r
97b38d4e 2042\r
2043**/\r
2044VOID\r
2045EFIAPI\r
2046NetbufQueAppend (\r
d1050b9d
MK
2047 IN OUT NET_BUF_QUEUE *NbufQue,\r
2048 IN OUT NET_BUF *Nbuf\r
97b38d4e 2049 );\r
2050\r
2051/**\r
7557df4d 2052 Copy Len bytes of data from the net buffer queue at the specific offset to the\r
2053 destination memory.\r
1204fe83 2054\r
64a80549 2055 The copying operation is the same as NetbufCopy, but applies to the net buffer\r
7557df4d 2056 queue instead of the net buffer.\r
1204fe83 2057\r
64a80549 2058 @param[in] NbufQue The pointer to the net buffer queue.\r
7557df4d 2059 @param[in] Offset The sequence number of the first byte to copy.\r
64a80549 2060 @param[in] Len The length of the data to copy.\r
7557df4d 2061 @param[out] Dest The destination of the data to copy to.\r
2062\r
1204fe83 2063 @return The length of the actual copied data, or 0 if the offset\r
7557df4d 2064 specified exceeds the total size of net buffer queue.\r
97b38d4e 2065\r
2066**/\r
2067UINT32\r
2068EFIAPI\r
2069NetbufQueCopy (\r
d1050b9d
MK
2070 IN NET_BUF_QUEUE *NbufQue,\r
2071 IN UINT32 Offset,\r
2072 IN UINT32 Len,\r
2073 OUT UINT8 *Dest\r
97b38d4e 2074 );\r
2075\r
2076/**\r
3b1464d5 2077 Trim Len bytes of data from the buffer queue and free any net buffer\r
2078 that is completely trimmed.\r
1204fe83 2079\r
7557df4d 2080 The trimming operation is the same as NetbufTrim but applies to the net buffer\r
2081 queue instead of the net buffer.\r
97b38d4e 2082\r
64a80549 2083 @param[in, out] NbufQue The pointer to the net buffer queue.\r
2084 @param[in] Len The length of the data to trim.\r
97b38d4e 2085\r
7557df4d 2086 @return The actual length of the data trimmed.\r
97b38d4e 2087\r
2088**/\r
2089UINT32\r
2090EFIAPI\r
2091NetbufQueTrim (\r
d1050b9d
MK
2092 IN OUT NET_BUF_QUEUE *NbufQue,\r
2093 IN UINT32 Len\r
97b38d4e 2094 );\r
2095\r
97b38d4e 2096/**\r
2097 Flush the net buffer queue.\r
2098\r
64a80549 2099 @param[in, out] NbufQue The pointer to the queue to be flushed.\r
97b38d4e 2100\r
2101**/\r
2102VOID\r
2103EFIAPI\r
2104NetbufQueFlush (\r
d1050b9d 2105 IN OUT NET_BUF_QUEUE *NbufQue\r
97b38d4e 2106 );\r
2107\r
2108/**\r
7557df4d 2109 Compute the checksum for a bulk of data.\r
97b38d4e 2110\r
64a80549 2111 @param[in] Bulk The pointer to the data.\r
2112 @param[in] Len The length of the data, in bytes.\r
97b38d4e 2113\r
ae213b7d 2114 @return The computed checksum.\r
97b38d4e 2115\r
2116**/\r
2117UINT16\r
2118EFIAPI\r
2119NetblockChecksum (\r
d1050b9d
MK
2120 IN UINT8 *Bulk,\r
2121 IN UINT32 Len\r
97b38d4e 2122 );\r
2123\r
2124/**\r
2125 Add two checksums.\r
2126\r
ae213b7d 2127 @param[in] Checksum1 The first checksum to be added.\r
2128 @param[in] Checksum2 The second checksum to be added.\r
97b38d4e 2129\r
ae213b7d 2130 @return The new checksum.\r
97b38d4e 2131\r
2132**/\r
2133UINT16\r
2134EFIAPI\r
2135NetAddChecksum (\r
d1050b9d
MK
2136 IN UINT16 Checksum1,\r
2137 IN UINT16 Checksum2\r
97b38d4e 2138 );\r
2139\r
2140/**\r
2141 Compute the checksum for a NET_BUF.\r
2142\r
64a80549 2143 @param[in] Nbuf The pointer to the net buffer.\r
97b38d4e 2144\r
ae213b7d 2145 @return The computed checksum.\r
97b38d4e 2146\r
2147**/\r
2148UINT16\r
2149EFIAPI\r
2150NetbufChecksum (\r
d1050b9d 2151 IN NET_BUF *Nbuf\r
97b38d4e 2152 );\r
2153\r
2154/**\r
1204fe83 2155 Compute the checksum for TCP/UDP pseudo header.\r
2156\r
7557df4d 2157 Src and Dst are in network byte order, and Len is in host byte order.\r
97b38d4e 2158\r
ae213b7d 2159 @param[in] Src The source address of the packet.\r
2160 @param[in] Dst The destination address of the packet.\r
2161 @param[in] Proto The protocol type of the packet.\r
2162 @param[in] Len The length of the packet.\r
97b38d4e 2163\r
ae213b7d 2164 @return The computed checksum.\r
97b38d4e 2165\r
2166**/\r
2167UINT16\r
2168EFIAPI\r
2169NetPseudoHeadChecksum (\r
d1050b9d
MK
2170 IN IP4_ADDR Src,\r
2171 IN IP4_ADDR Dst,\r
2172 IN UINT8 Proto,\r
2173 IN UINT16 Len\r
97b38d4e 2174 );\r
2175\r
f6b7393c 2176/**\r
64a80549 2177 Compute the checksum for the TCP6/UDP6 pseudo header.\r
1204fe83 2178\r
f6b7393c 2179 Src and Dst are in network byte order, and Len is in host byte order.\r
2180\r
2181 @param[in] Src The source address of the packet.\r
2182 @param[in] Dst The destination address of the packet.\r
2183 @param[in] NextHeader The protocol type of the packet.\r
2184 @param[in] Len The length of the packet.\r
2185\r
2186 @return The computed checksum.\r
2187\r
2188**/\r
2189UINT16\r
e798cd87 2190EFIAPI\r
f6b7393c 2191NetIp6PseudoHeadChecksum (\r
d1050b9d
MK
2192 IN EFI_IPv6_ADDRESS *Src,\r
2193 IN EFI_IPv6_ADDRESS *Dst,\r
2194 IN UINT8 NextHeader,\r
2195 IN UINT32 Len\r
f6b7393c 2196 );\r
705f53a9 2197\r
2198/**\r
d1102dba
LG
2199 The function frees the net buffer which allocated by the IP protocol. It releases\r
2200 only the net buffer and doesn't call the external free function.\r
705f53a9 2201\r
d1102dba
LG
2202 This function should be called after finishing the process of mIpSec->ProcessExt()\r
2203 for outbound traffic. The (EFI_IPSEC2_PROTOCOL)->ProcessExt() allocates a new\r
705f53a9 2204 buffer for the ESP, so there needs a function to free the old net buffer.\r
2205\r
2206 @param[in] Nbuf The network buffer to be freed.\r
2207\r
2208**/\r
2209VOID\r
2210NetIpSecNetbufFree (\r
d1050b9d 2211 NET_BUF *Nbuf\r
705f53a9 2212 );\r
57b301b5 2213\r
2214/**\r
2215 This function obtains the system guid from the smbios table.\r
2216\r
e0e26f9c
WF
2217 If SystemGuid is NULL, then ASSERT().\r
2218\r
57b301b5 2219 @param[out] SystemGuid The pointer of the returned system guid.\r
2220\r
2221 @retval EFI_SUCCESS Successfully obtained the system guid.\r
2222 @retval EFI_NOT_FOUND Did not find the SMBIOS table.\r
2223\r
2224**/\r
2225EFI_STATUS\r
2226EFIAPI\r
2227NetLibGetSystemGuid (\r
d1050b9d 2228 OUT EFI_GUID *SystemGuid\r
57b301b5 2229 );\r
2230\r
dba6e9a9 2231/**\r
e0e26f9c
WF
2232 Create Dns QName according the queried domain name.\r
2233\r
2234 If DomainName is NULL, then ASSERT().\r
2235\r
d1102dba
LG
2236 QName is a domain name represented as a sequence of labels,\r
2237 where each label consists of a length octet followed by that\r
2238 number of octets. The QName terminates with the zero\r
2239 length octet for the null label of the root. Caller should\r
dba6e9a9
JW
2240 take responsibility to free the buffer in returned pointer.\r
2241\r
d1102dba 2242 @param DomainName The pointer to the queried domain name string.\r
dba6e9a9
JW
2243\r
2244 @retval NULL Failed to fill QName.\r
2245 @return QName filled successfully.\r
d1102dba
LG
2246\r
2247**/\r
dba6e9a9
JW
2248CHAR8 *\r
2249EFIAPI\r
2250NetLibCreateDnsQName (\r
d1050b9d 2251 IN CHAR16 *DomainName\r
dba6e9a9
JW
2252 );\r
2253\r
97b38d4e 2254#endif\r