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