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