]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Library/NetLib.h
Sync the latest version from R8.
[mirror_edk2.git] / MdeModulePkg / Include / Library / NetLib.h
1 /** @file
2
3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 NetLib.h
15
16 Abstract:
17
18 Library for the UEFI network stack.
19
20
21 **/
22
23 #ifndef _NET_LIB_H_
24 #define _NET_LIB_H_
25
26 #include <PiDxe.h>
27 #include <Protocol/DriverBinding.h>
28 #include <Protocol/ComponentName.h>
29 #include <Protocol/DriverConfiguration.h>
30 #include <Protocol/DriverDiagnostics.h>
31 #include <Protocol/Dpc.h>
32
33 #define EFI_NET_LITTLE_ENDIAN
34
35 typedef UINT32 IP4_ADDR;
36 typedef UINT32 TCP_SEQNO;
37 typedef UINT16 TCP_PORTNO;
38
39 enum {
40 NET_ETHER_ADDR_LEN = 6,
41 NET_IFTYPE_ETHERNET = 0x01,
42
43 EFI_IP_PROTO_UDP = 0x11,
44 EFI_IP_PROTO_TCP = 0x06,
45 EFI_IP_PROTO_ICMP = 0x01,
46
47 //
48 // The address classfication
49 //
50 IP4_ADDR_CLASSA = 1,
51 IP4_ADDR_CLASSB,
52 IP4_ADDR_CLASSC,
53 IP4_ADDR_CLASSD,
54 IP4_ADDR_CLASSE,
55
56 IP4_MASK_NUM = 33,
57 };
58
59 #pragma pack(1)
60
61 //
62 // Ethernet head definition
63 //
64 typedef struct {
65 UINT8 DstMac [NET_ETHER_ADDR_LEN];
66 UINT8 SrcMac [NET_ETHER_ADDR_LEN];
67 UINT16 EtherType;
68 } ETHER_HEAD;
69
70
71 //
72 // The EFI_IP4_HEADER is hard to use because the source and
73 // destination address are defined as EFI_IPv4_ADDRESS, which
74 // is a structure. Two structures can't be compared or masked
75 // directly. This is why there is an internal representation.
76 //
77 typedef struct {
78 #ifdef EFI_NET_LITTLE_ENDIAN
79 UINT8 HeadLen : 4;
80 UINT8 Ver : 4;
81 #else
82 UINT8 Ver : 4;
83 UINT8 HeadLen : 4;
84 #endif
85 UINT8 Tos;
86 UINT16 TotalLen;
87 UINT16 Id;
88 UINT16 Fragment;
89 UINT8 Ttl;
90 UINT8 Protocol;
91 UINT16 Checksum;
92 IP4_ADDR Src;
93 IP4_ADDR Dst;
94 } IP4_HEAD;
95
96
97 //
98 // ICMP head definition. ICMP message is categoried as either an error
99 // message or query message. Two message types have their own head format.
100 //
101 typedef struct {
102 UINT8 Type;
103 UINT8 Code;
104 UINT16 Checksum;
105 } IP4_ICMP_HEAD;
106
107 typedef struct {
108 IP4_ICMP_HEAD Head;
109 UINT32 Fourth; // 4th filed of the head, it depends on Type.
110 IP4_HEAD IpHead;
111 } IP4_ICMP_ERROR_HEAD;
112
113 typedef struct {
114 IP4_ICMP_HEAD Head;
115 UINT16 Id;
116 UINT16 Seq;
117 } IP4_ICMP_QUERY_HEAD;
118
119
120 //
121 // UDP header definition
122 //
123 typedef struct {
124 UINT16 SrcPort;
125 UINT16 DstPort;
126 UINT16 Length;
127 UINT16 Checksum;
128 } EFI_UDP4_HEADER;
129
130
131 //
132 // TCP header definition
133 //
134 typedef struct {
135 TCP_PORTNO SrcPort;
136 TCP_PORTNO DstPort;
137 TCP_SEQNO Seq;
138 TCP_SEQNO Ack;
139 #ifdef EFI_NET_LITTLE_ENDIAN
140 UINT8 Res : 4;
141 UINT8 HeadLen : 4;
142 #else
143 UINT8 HeadLen : 4;
144 UINT8 Res : 4;
145 #endif
146 UINT8 Flag;
147 UINT16 Wnd;
148 UINT16 Checksum;
149 UINT16 Urg;
150 } TCP_HEAD;
151
152 #pragma pack()
153
154 #define NET_MAC_EQUAL(pMac1, pMac2, Len) \
155 (NetCompareMem ((pMac1), (pMac2), Len) == 0)
156
157 #define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \
158 (((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))
159
160 #ifdef EFI_NET_LITTLE_ENDIAN
161 #define NTOHL(x) (UINT32)((((UINT32) (x) & 0xff) << 24) | \
162 (((UINT32) (x) & 0xff00) << 8) | \
163 (((UINT32) (x) & 0xff0000) >> 8) | \
164 (((UINT32) (x) & 0xff000000) >> 24))
165
166 #define HTONL(x) NTOHL(x)
167
168 #define NTOHS(x) (UINT16)((((UINT16) (x) & 0xff) << 8) | \
169 (((UINT16) (x) & 0xff00) >> 8))
170
171 #define HTONS(x) NTOHS(x)
172 #else
173 #define NTOHL(x) (UINT32)(x)
174 #define HTONL(x) (UINT32)(x)
175 #define NTOHS(x) (UINT16)(x)
176 #define HTONS(x) (UINT16)(x)
177 #endif
178
179 //
180 // Test the IP's attribute, All the IPs are in host byte order.
181 //
182 #define IP4_IS_MULTICAST(Ip) (((Ip) & 0xF0000000) == 0xE0000000)
183 #define IP4_IS_LOCAL_BROADCAST(Ip) ((Ip) == 0xFFFFFFFF)
184 #define IP4_NET_EQUAL(Ip1, Ip2, NetMask) (((Ip1) & (NetMask)) == ((Ip2) & (NetMask)))
185 #define IP4_IS_VALID_NETMASK(Ip) (NetGetMaskLength (Ip) != IP4_MASK_NUM)
186
187 //
188 // Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.
189 //
190 #define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))
191 #define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))
192 #define EFI_IP4_EQUAL(Ip1, Ip2) (NetCompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)
193
194 INTN
195 NetGetMaskLength (
196 IN IP4_ADDR Mask
197 );
198
199 INTN
200 NetGetIpClass (
201 IN IP4_ADDR Addr
202 );
203
204 BOOLEAN
205 Ip4IsUnicast (
206 IN IP4_ADDR Ip,
207 IN IP4_ADDR NetMask
208 );
209
210 extern IP4_ADDR mIp4AllMasks [IP4_MASK_NUM];
211
212
213 extern EFI_IPv4_ADDRESS mZeroIp4Addr;
214
215 #define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))
216 #define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))
217
218 //
219 // Wrap functions to ease the impact of EFI library changes.
220 //
221 #define NetAllocateZeroPool AllocateZeroPool
222 #define NetAllocatePool AllocatePool
223 #define NetFreePool gBS->FreePool
224 #define NetCopyMem CopyMem
225 #define NetSetMem SetMem
226 #define NetZeroMem(Dest, Len) SetMem ((Dest), (Len), 0)
227 #define NetCompareMem CompareMem
228
229 //
230 // Lock primitives: the stack implements its lock primitives according
231 // to the standard EFI enviornment. It will NOT consider multiprocessor.
232 //
233 #define NET_TPL_LOCK TPL_CALLBACK
234 #define NET_TPL_EVENT TPL_NOTIFY
235 #define NET_TPL_RECYCLE TPL_NOTIFY
236 #define NET_TPL_TIMER NET_TPL_LOCK
237
238 #define NET_LOCK EFI_LOCK
239 #define NET_LOCK_INIT(x) EfiInitializeLock (x, NET_TPL_LOCK)
240 #define NET_RECYCLE_LOCK_INIT(x) EfiInitializeLock (x, NET_TPL_RECYCLE)
241 #define NET_TRYLOCK(x) EfiAcquireLockOrFail (x)
242 #define NET_UNLOCK(x) EfiReleaseLock (x)
243
244 #define NET_RAISE_TPL(x) (gBS->RaiseTPL (x))
245 #define NET_RESTORE_TPL(x) (gBS->RestoreTPL (x))
246
247 #define TICKS_PER_MS 10000U
248 #define TICKS_PER_SECOND 10000000U
249
250 #define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)
251
252
253 UINT32
254 NetGetUint32 (
255 IN UINT8 *Buf
256 );
257
258 VOID
259 NetPutUint32 (
260 IN UINT8 *Buf,
261 IN UINT32 Data
262 );
263
264 UINT32
265 NetRandomInitSeed (
266 VOID
267 );
268
269
270 //
271 // Double linked list entry functions, this extends the
272 // EFI list functions.
273 //
274 typedef LIST_ENTRY NET_LIST_ENTRY;
275
276 #define NetListInit(Head) InitializeListHead(Head)
277 #define NetListInsertHead(Head, Entry) InsertHeadList((Head), (Entry))
278 #define NetListInsertTail(Head, Entry) InsertTailList((Head), (Entry))
279 #define NetListIsEmpty(List) IsListEmpty(List)
280
281 #define NET_LIST_USER_STRUCT(Entry, Type, Field) \
282 _CR(Entry, Type, Field)
283
284 #define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \
285 CR(Entry, Type, Field, Sig)
286
287 //
288 // Iterate through the doule linked list. It is NOT delete safe
289 //
290 #define NET_LIST_FOR_EACH(Entry, ListHead) \
291 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
292
293 //
294 // Iterate through the doule linked list. This is delete-safe.
295 // Don't touch NextEntry. Also, don't use this macro if list
296 // entries other than the Entry may be deleted when processing
297 // the current Entry.
298 //
299 #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
300 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
301 Entry != (ListHead); \
302 Entry = NextEntry, NextEntry = Entry->ForwardLink \
303 )
304
305 //
306 // Make sure the list isn't empty before get the frist/last record.
307 //
308 #define NET_LIST_HEAD(ListHead, Type, Field) \
309 NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)
310
311 #define NET_LIST_TAIL(ListHead, Type, Field) \
312 NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)
313
314 #define NetListRemoveEntry(Entry) RemoveEntryList (Entry)
315
316 NET_LIST_ENTRY*
317 NetListRemoveHead (
318 NET_LIST_ENTRY *Head
319 );
320
321 NET_LIST_ENTRY*
322 NetListRemoveTail (
323 NET_LIST_ENTRY *Head
324 );
325
326 VOID
327 NetListInsertAfter (
328 IN NET_LIST_ENTRY *PrevEntry,
329 IN NET_LIST_ENTRY *NewEntry
330 );
331
332 VOID
333 NetListInsertBefore (
334 IN NET_LIST_ENTRY *PostEntry,
335 IN NET_LIST_ENTRY *NewEntry
336 );
337
338
339 //
340 // Object container: EFI network stack spec defines various kinds of
341 // tokens. The drivers can share code to manage those objects.
342 //
343 typedef struct {
344 NET_LIST_ENTRY Link;
345 VOID *Key;
346 VOID *Value;
347 } NET_MAP_ITEM;
348
349 typedef struct {
350 NET_LIST_ENTRY Used;
351 NET_LIST_ENTRY Recycled;
352 UINTN Count;
353 } NET_MAP;
354
355 #define NET_MAP_INCREAMENT 64
356
357 VOID
358 NetMapInit (
359 IN NET_MAP *Map
360 );
361
362 VOID
363 NetMapClean (
364 IN NET_MAP *Map
365 );
366
367 BOOLEAN
368 NetMapIsEmpty (
369 IN NET_MAP *Map
370 );
371
372 UINTN
373 NetMapGetCount (
374 IN NET_MAP *Map
375 );
376
377 EFI_STATUS
378 NetMapInsertHead (
379 IN NET_MAP *Map,
380 IN VOID *Key,
381 IN VOID *Value OPTIONAL
382 );
383
384 EFI_STATUS
385 NetMapInsertTail (
386 IN NET_MAP *Map,
387 IN VOID *Key,
388 IN VOID *Value OPTIONAL
389 );
390
391 NET_MAP_ITEM *
392 NetMapFindKey (
393 IN NET_MAP *Map,
394 IN VOID *Key
395 );
396
397 VOID *
398 NetMapRemoveItem (
399 IN NET_MAP *Map,
400 IN NET_MAP_ITEM *Item,
401 OUT VOID **Value OPTIONAL
402 );
403
404 VOID *
405 NetMapRemoveHead (
406 IN NET_MAP *Map,
407 OUT VOID **Value OPTIONAL
408 );
409
410 VOID *
411 NetMapRemoveTail (
412 IN NET_MAP *Map,
413 OUT VOID **Value OPTIONAL
414 );
415
416 typedef
417 EFI_STATUS
418 (*NET_MAP_CALLBACK) (
419 IN NET_MAP *Map,
420 IN NET_MAP_ITEM *Item,
421 IN VOID *Arg
422 );
423
424 EFI_STATUS
425 NetMapIterate (
426 IN NET_MAP *Map,
427 IN NET_MAP_CALLBACK CallBack,
428 IN VOID *Arg OPTIONAL
429 );
430
431
432 //
433 // Helper functions to implement driver binding and service binding protocols.
434 //
435 EFI_STATUS
436 NetLibCreateServiceChild (
437 IN EFI_HANDLE ControllerHandle,
438 IN EFI_HANDLE ImageHandle,
439 IN EFI_GUID *ServiceBindingGuid,
440 OUT EFI_HANDLE *ChildHandle
441 );
442
443 EFI_STATUS
444 NetLibDestroyServiceChild (
445 IN EFI_HANDLE ControllerHandle,
446 IN EFI_HANDLE ImageHandle,
447 IN EFI_GUID *ServiceBindingGuid,
448 IN EFI_HANDLE ChildHandle
449 );
450
451 EFI_STATUS
452 NetLibGetMacString (
453 IN EFI_HANDLE SnpHandle,
454 IN EFI_HANDLE ImageHandle,
455 IN OUT CHAR16 **MacString
456 );
457
458 VOID
459 NetLibCreateIPv4DPathNode (
460 IN OUT IPv4_DEVICE_PATH *Node,
461 IN EFI_HANDLE Controller,
462 IN IP4_ADDR LocalIp,
463 IN UINT16 LocalPort,
464 IN IP4_ADDR RemoteIp,
465 IN UINT16 RemotePort,
466 IN UINT16 Protocol,
467 IN BOOLEAN UseDefaultAddress
468 );
469
470 EFI_HANDLE
471 NetLibGetNicHandle (
472 IN EFI_HANDLE Controller,
473 IN EFI_GUID *ProtocolGuid
474 );
475
476 EFI_STATUS
477 NetLibQueueDpc (
478 IN EFI_TPL DpcTpl,
479 IN EFI_DPC_PROCEDURE DpcProcedure,
480 IN VOID *DpcContext OPTIONAL
481 );
482
483 EFI_STATUS
484 NetLibDispatchDpc (
485 VOID
486 );
487
488 EFI_STATUS
489 EFIAPI
490 NetLibDefaultUnload (
491 IN EFI_HANDLE ImageHandle
492 );
493
494 enum {
495 //
496 //Various signatures
497 //
498 NET_BUF_SIGNATURE = EFI_SIGNATURE_32 ('n', 'b', 'u', 'f'),
499 NET_VECTOR_SIGNATURE = EFI_SIGNATURE_32 ('n', 'v', 'e', 'c'),
500 NET_QUE_SIGNATURE = EFI_SIGNATURE_32 ('n', 'b', 'q', 'u'),
501
502
503 NET_PROTO_DATA = 64, // Opaque buffer for protocols
504 NET_BUF_HEAD = 1, // Trim or allocate space from head
505 NET_BUF_TAIL = 0, // Trim or allocate space from tail
506 NET_VECTOR_OWN_FIRST = 0x01, // We allocated the 1st block in the vector
507 };
508
509 #define NET_CHECK_SIGNATURE(PData, SIGNATURE) \
510 ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))
511
512 #define NET_SWAP_SHORT(Value) \
513 ((((Value) & 0xff) << 8) | (((Value) >> 8) & 0xff))
514
515 //
516 // Single memory block in the vector.
517 //
518 typedef struct {
519 UINT32 Len; // The block's length
520 UINT8 *Bulk; // The block's Data
521 } NET_BLOCK;
522
523 typedef VOID (*NET_VECTOR_EXT_FREE) (VOID *Arg);
524
525 //
526 //NET_VECTOR contains several blocks to hold all packet's
527 //fragments and other house-keeping stuff for sharing. It
528 //doesn't specify the where actual packet fragment begins.
529 //
530 typedef struct {
531 UINT32 Signature;
532 INTN RefCnt; // Reference count to share NET_VECTOR.
533 NET_VECTOR_EXT_FREE Free; // external function to free NET_VECTOR
534 VOID *Arg; // opeque argument to Free
535 UINT32 Flag; // Flags, NET_VECTOR_OWN_FIRST
536 UINT32 Len; // Total length of the assocated BLOCKs
537
538 UINT32 BlockNum;
539 NET_BLOCK Block[1];
540 } NET_VECTOR;
541
542 //
543 //NET_BLOCK_OP operate on the NET_BLOCK, It specifies
544 //where the actual fragment begins and where it ends
545 //
546 typedef struct {
547 UINT8 *BlockHead; // Block's head, or the smallest valid Head
548 UINT8 *BlockTail; // Block's tail. BlockTail-BlockHead=block length
549 UINT8 *Head; // 1st byte of the data in the block
550 UINT8 *Tail; // Tail of the data in the block, Tail-Head=Size
551 UINT32 Size; // The size of the data
552 } NET_BLOCK_OP;
553
554
555 //
556 //NET_BUF is the buffer manage structure used by the
557 //network stack. Every network packet may be fragmented,
558 //and contains multiple fragments. The Vector points to
559 //memory blocks used by the each fragment, and BlockOp
560 //specifies where each fragment begins and ends.
561 //
562 //It also contains a opaque area for protocol to store
563 //per-packet informations. Protocol must be caution not
564 //to overwrite the members after that.
565 //
566 typedef struct {
567 UINT32 Signature;
568 INTN RefCnt;
569 NET_LIST_ENTRY List; // The List this NET_BUF is on
570
571 IP4_HEAD *Ip; // Network layer header, for fast access
572 TCP_HEAD *Tcp; // Transport layer header, for fast access
573 UINT8 ProtoData [NET_PROTO_DATA]; //Protocol specific data
574
575 NET_VECTOR *Vector; // The vector containing the packet
576
577 UINT32 BlockOpNum; // Total number of BlockOp in the buffer
578 UINT32 TotalSize; // Total size of the actual packet
579 NET_BLOCK_OP BlockOp[1]; // Specify the position of actual packet
580 } NET_BUF;
581
582
583 //
584 //A queue of NET_BUFs, It is just a thin extension of
585 //NET_BUF functions.
586 //
587 typedef struct {
588 UINT32 Signature;
589 INTN RefCnt;
590 NET_LIST_ENTRY List; // The List this buffer queue is on
591
592 NET_LIST_ENTRY BufList; // list of queued buffers
593 UINT32 BufSize; // total length of DATA in the buffers
594 UINT32 BufNum; // total number of buffers on the chain
595 } NET_BUF_QUEUE;
596
597 //
598 // Pseudo header for TCP and UDP checksum
599 //
600 #pragma pack(1)
601 typedef struct {
602 IP4_ADDR SrcIp;
603 IP4_ADDR DstIp;
604 UINT8 Reserved;
605 UINT8 Protocol;
606 UINT16 Len;
607 } NET_PSEUDO_HDR;
608 #pragma pack()
609
610 //
611 // The fragment entry table used in network interfaces. This is
612 // the same as NET_BLOCK now. Use two different to distinguish
613 // the two in case that NET_BLOCK be enhanced later.
614 //
615 typedef struct {
616 UINT32 Len;
617 UINT8 *Bulk;
618 } NET_FRAGMENT;
619
620 #define NET_GET_REF(PData) ((PData)->RefCnt++)
621 #define NET_PUT_REF(PData) ((PData)->RefCnt--)
622 #define NETBUF_FROM_PROTODATA(Info) _CR((Info), NET_BUF, ProtoData)
623
624 #define NET_BUF_SHARED(Buf) \
625 (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))
626
627 #define NET_VECTOR_SIZE(BlockNum) \
628 (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))
629
630 #define NET_BUF_SIZE(BlockOpNum) \
631 (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))
632
633 #define NET_HEADSPACE(BlockOp) \
634 (UINTN)((BlockOp)->Head - (BlockOp)->BlockHead)
635
636 #define NET_TAILSPACE(BlockOp) \
637 (UINTN)((BlockOp)->BlockTail - (BlockOp)->Tail)
638
639 NET_BUF *
640 NetbufAlloc (
641 IN UINT32 Len
642 );
643
644 VOID
645 NetbufFree (
646 IN NET_BUF *Nbuf
647 );
648
649
650 UINT8 *
651 NetbufGetByte (
652 IN NET_BUF *Nbuf,
653 IN UINT32 Offset,
654 OUT UINT32 *Index OPTIONAL
655 );
656
657 NET_BUF *
658 NetbufClone (
659 IN NET_BUF *Nbuf
660 );
661
662 NET_BUF *
663 NetbufDuplicate (
664 IN NET_BUF *Nbuf,
665 IN NET_BUF *Duplicate OPTIONAL,
666 IN UINT32 HeadSpace
667 );
668
669 NET_BUF *
670 NetbufGetFragment (
671 IN NET_BUF *Nbuf,
672 IN UINT32 Offset,
673 IN UINT32 Len,
674 IN UINT32 HeadSpace
675 );
676
677 VOID
678 NetbufReserve (
679 IN NET_BUF *Nbuf,
680 IN UINT32 Len
681 );
682
683 UINT8 *
684 NetbufAllocSpace (
685 IN NET_BUF *Nbuf,
686 IN UINT32 Len,
687 IN BOOLEAN FromHead
688 );
689
690 UINT32
691 NetbufTrim (
692 IN NET_BUF *Nbuf,
693 IN UINT32 Len,
694 IN BOOLEAN FromHead
695 );
696
697 UINT32
698 NetbufCopy (
699 IN NET_BUF *Nbuf,
700 IN UINT32 Offset,
701 IN UINT32 Len,
702 IN UINT8 *Dest
703 );
704
705 NET_BUF *
706 NetbufFromExt (
707 IN NET_FRAGMENT *ExtFragment,
708 IN UINT32 ExtNum,
709 IN UINT32 HeadSpace,
710 IN UINT32 HeadLen,
711 IN NET_VECTOR_EXT_FREE ExtFree,
712 IN VOID *Arg OPTIONAL
713 );
714
715 EFI_STATUS
716 NetbufBuildExt (
717 IN NET_BUF *Nbuf,
718 IN NET_FRAGMENT *ExtFragment,
719 IN UINT32 *ExtNum
720 );
721
722 NET_BUF *
723 NetbufFromBufList (
724 IN NET_LIST_ENTRY *BufList,
725 IN UINT32 HeadSpace,
726 IN UINT32 HeaderLen,
727 IN NET_VECTOR_EXT_FREE ExtFree,
728 IN VOID *Arg OPTIONAL
729 );
730
731 VOID
732 NetbufFreeList (
733 IN NET_LIST_ENTRY *Head
734 );
735
736 VOID
737 NetbufQueInit (
738 IN NET_BUF_QUEUE *NbufQue
739 );
740
741 NET_BUF_QUEUE *
742 NetbufQueAlloc (
743 VOID
744 );
745
746 VOID
747 NetbufQueFree (
748 IN NET_BUF_QUEUE *NbufQue
749 );
750
751 NET_BUF *
752 NetbufQueRemove (
753 IN NET_BUF_QUEUE *NbufQue
754 );
755
756 VOID
757 NetbufQueAppend (
758 IN NET_BUF_QUEUE *NbufQue,
759 IN NET_BUF *Nbuf
760 );
761
762 UINT32
763 NetbufQueCopy (
764 IN NET_BUF_QUEUE *NbufQue,
765 IN UINT32 Offset,
766 IN UINT32 Len,
767 IN UINT8 *Dest
768 );
769
770 UINT32
771 NetbufQueTrim (
772 IN NET_BUF_QUEUE *NbufQue,
773 IN UINT32 Len
774 );
775
776 VOID
777 NetbufQueFlush (
778 IN NET_BUF_QUEUE *NbufQue
779 );
780
781 UINT16
782 NetblockChecksum (
783 IN UINT8 *Bulk,
784 IN UINT32 Len
785 );
786
787 UINT16
788 NetAddChecksum (
789 IN UINT16 Checksum1,
790 IN UINT16 Checksum2
791 );
792
793 UINT16
794 NetbufChecksum (
795 IN NET_BUF *Nbuf
796 );
797
798 UINT16
799 NetPseudoHeadChecksum (
800 IN IP4_ADDR Src,
801 IN IP4_ADDR Dst,
802 IN UINT8 Proto,
803 IN UINT16 Len
804 );
805
806 //
807 // The debug level definition. This value is also used as the
808 // syslog's servity level. Don't change it.
809 //
810 enum {
811 NETDEBUG_LEVEL_TRACE = 5,
812 NETDEBUG_LEVEL_WARNING = 4,
813 NETDEBUG_LEVEL_ERROR = 3,
814 };
815
816 #ifdef EFI_NETWORK_STACK_DEBUG
817
818 //
819 // The debug output expects the ASCII format string, Use %a to print ASCII
820 // string, and %s to print UNICODE string. PrintArg must be enclosed in ().
821 // For example: NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name));
822 //
823 #define NET_DEBUG_TRACE(Module, PrintArg) \
824 NetDebugOutput ( \
825 NETDEBUG_LEVEL_TRACE, \
826 Module, \
827 __FILE__, \
828 __LINE__, \
829 NetDebugASPrint PrintArg \
830 )
831
832 #define NET_DEBUG_WARNING(Module, PrintArg) \
833 NetDebugOutput ( \
834 NETDEBUG_LEVEL_WARNING, \
835 Module, \
836 __FILE__, \
837 __LINE__, \
838 NetDebugASPrint PrintArg \
839 )
840
841 #define NET_DEBUG_ERROR(Module, PrintArg) \
842 NetDebugOutput ( \
843 NETDEBUG_LEVEL_ERROR, \
844 Module, \
845 __FILE__, \
846 __LINE__, \
847 NetDebugASPrint PrintArg \
848 )
849
850 #else
851 #define NET_DEBUG_TRACE(Module, PrintString)
852 #define NET_DEBUG_WARNING(Module, PrintString)
853 #define NET_DEBUG_ERROR(Module, PrintString)
854 #endif
855
856 UINT8 *
857 NetDebugASPrint (
858 UINT8 *Format,
859 ...
860 );
861
862 EFI_STATUS
863 NetDebugOutput (
864 UINT32 Level,
865 UINT8 *Module,
866 UINT8 *File,
867 UINT32 Line,
868 UINT8 *Message
869 );
870
871 //
872 // Network debug message is sent out as syslog.
873 //
874 enum {
875 NET_SYSLOG_FACILITY = 16, // Syslog local facility local use
876 NET_SYSLOG_PACKET_LEN = 512,
877 NET_DEBUG_MSG_LEN = 470, // 512 - (ether+ip+udp head length)
878 NET_SYSLOG_TX_TIMEOUT = 500 *1000 *10, // 500ms
879 };
880 #endif