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