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