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