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