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