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