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