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