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