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