]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Library/NetLib.h
c843b6ce79a0789f9957fec71da6f5fb1ca5d30d
[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 //
217 // Wrap functions to ease the impact of EFI library changes.
218 //
219 #define NetAllocateZeroPool AllocateZeroPool
220 #define NetAllocatePool AllocatePool
221 #define NetFreePool gBS->FreePool
222 #define NetCopyMem CopyMem
223 #define NetSetMem SetMem
224 #define NetZeroMem(Dest, Len) SetMem ((Dest), (Len), 0)
225 #define NetCompareMem CompareMem
226
227 //
228 // Lock primitives: the stack implements its lock primitives according
229 // to the standard EFI enviornment. It will NOT consider multiprocessor.
230 //
231 #define NET_TPL_LOCK TPL_CALLBACK
232 #define NET_TPL_EVENT TPL_NOTIFY
233 #define NET_TPL_RECYCLE TPL_NOTIFY
234 #define NET_TPL_TIMER NET_TPL_LOCK
235
236 #define NET_LOCK EFI_LOCK
237 #define NET_LOCK_INIT(x) EfiInitializeLock (x, NET_TPL_LOCK)
238 #define NET_RECYCLE_LOCK_INIT(x) EfiInitializeLock (x, NET_TPL_RECYCLE)
239 #define NET_TRYLOCK(x) EfiAcquireLockOrFail (x)
240 #define NET_UNLOCK(x) EfiReleaseLock (x)
241
242 #define NET_RAISE_TPL(x) (gBS->RaiseTPL (x))
243 #define NET_RESTORE_TPL(x) (gBS->RestoreTPL (x))
244
245 #define TICKS_PER_MS 10000U
246 #define TICKS_PER_SECOND 10000000U
247
248 #define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)
249
250
251 UINT32
252 NetGetUint32 (
253 IN UINT8 *Buf
254 );
255
256 VOID
257 NetPutUint32 (
258 IN UINT8 *Buf,
259 IN UINT32 Data
260 );
261
262 UINT32
263 NetRandomInitSeed (
264 VOID
265 );
266
267
268 //
269 // Double linked list entry functions, this extends the
270 // EFI list functions.
271 //
272 typedef LIST_ENTRY NET_LIST_ENTRY;
273
274 #define NetListInit(Head) InitializeListHead(Head)
275 #define NetListInsertHead(Head, Entry) InsertHeadList((Head), (Entry))
276 #define NetListInsertTail(Head, Entry) InsertTailList((Head), (Entry))
277 #define NetListIsEmpty(List) IsListEmpty(List)
278
279 #define NET_LIST_USER_STRUCT(Entry, Type, Field) \
280 _CR(Entry, Type, Field)
281
282 #define NET_LIST_USER_STRUCT_S(Entry, Type, Field, Sig) \
283 CR(Entry, Type, Field, Sig)
284
285 //
286 // Iterate through the doule linked list. It is NOT delete safe
287 //
288 #define NET_LIST_FOR_EACH(Entry, ListHead) \
289 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
290
291 //
292 // Iterate through the doule linked list. This is delete-safe.
293 // Don't touch NextEntry. Also, don't use this macro if list
294 // entries other than the Entry may be deleted when processing
295 // the current Entry.
296 //
297 #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
298 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
299 Entry != (ListHead); \
300 Entry = NextEntry, NextEntry = Entry->ForwardLink \
301 )
302
303 //
304 // Make sure the list isn't empty before get the frist/last record.
305 //
306 #define NET_LIST_HEAD(ListHead, Type, Field) \
307 NET_LIST_USER_STRUCT((ListHead)->ForwardLink, Type, Field)
308
309 #define NET_LIST_TAIL(ListHead, Type, Field) \
310 NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)
311
312 #define NetListRemoveEntry(Entry) RemoveEntryList (Entry)
313
314 NET_LIST_ENTRY*
315 NetListRemoveHead (
316 NET_LIST_ENTRY *Head
317 );
318
319 NET_LIST_ENTRY*
320 NetListRemoveTail (
321 NET_LIST_ENTRY *Head
322 );
323
324 VOID
325 NetListInsertAfter (
326 IN NET_LIST_ENTRY *PrevEntry,
327 IN NET_LIST_ENTRY *NewEntry
328 );
329
330 VOID
331 NetListInsertBefore (
332 IN NET_LIST_ENTRY *PostEntry,
333 IN NET_LIST_ENTRY *NewEntry
334 );
335
336
337 //
338 // Object container: EFI network stack spec defines various kinds of
339 // tokens. The drivers can share code to manage those objects.
340 //
341 typedef struct {
342 NET_LIST_ENTRY Link;
343 VOID *Key;
344 VOID *Value;
345 } NET_MAP_ITEM;
346
347 typedef struct {
348 NET_LIST_ENTRY Used;
349 NET_LIST_ENTRY Recycled;
350 UINTN Count;
351 } NET_MAP;
352
353 #define NET_MAP_INCREAMENT 64
354
355 VOID
356 NetMapInit (
357 IN NET_MAP *Map
358 );
359
360 VOID
361 NetMapClean (
362 IN NET_MAP *Map
363 );
364
365 BOOLEAN
366 NetMapIsEmpty (
367 IN NET_MAP *Map
368 );
369
370 UINTN
371 NetMapGetCount (
372 IN NET_MAP *Map
373 );
374
375 EFI_STATUS
376 NetMapInsertHead (
377 IN NET_MAP *Map,
378 IN VOID *Key,
379 IN VOID *Value OPTIONAL
380 );
381
382 EFI_STATUS
383 NetMapInsertTail (
384 IN NET_MAP *Map,
385 IN VOID *Key,
386 IN VOID *Value OPTIONAL
387 );
388
389 NET_MAP_ITEM *
390 NetMapFindKey (
391 IN NET_MAP *Map,
392 IN VOID *Key
393 );
394
395 VOID *
396 NetMapRemoveItem (
397 IN NET_MAP *Map,
398 IN NET_MAP_ITEM *Item,
399 OUT VOID **Value OPTIONAL
400 );
401
402 VOID *
403 NetMapRemoveHead (
404 IN NET_MAP *Map,
405 OUT VOID **Value OPTIONAL
406 );
407
408 VOID *
409 NetMapRemoveTail (
410 IN NET_MAP *Map,
411 OUT VOID **Value OPTIONAL
412 );
413
414 typedef
415 EFI_STATUS
416 (*NET_MAP_CALLBACK) (
417 IN NET_MAP *Map,
418 IN NET_MAP_ITEM *Item,
419 IN VOID *Arg
420 );
421
422 EFI_STATUS
423 NetMapIterate (
424 IN NET_MAP *Map,
425 IN NET_MAP_CALLBACK CallBack,
426 IN VOID *Arg OPTIONAL
427 );
428
429
430 //
431 // Helper functions to implement driver binding and service binding protocols.
432 //
433 EFI_STATUS
434 NetLibCreateServiceChild (
435 IN EFI_HANDLE ControllerHandle,
436 IN EFI_HANDLE ImageHandle,
437 IN EFI_GUID *ServiceBindingGuid,
438 OUT EFI_HANDLE *ChildHandle
439 );
440
441 EFI_STATUS
442 NetLibDestroyServiceChild (
443 IN EFI_HANDLE ControllerHandle,
444 IN EFI_HANDLE ImageHandle,
445 IN EFI_GUID *ServiceBindingGuid,
446 IN EFI_HANDLE ChildHandle
447 );
448
449 EFI_STATUS
450 NetLibGetMacString (
451 IN EFI_HANDLE SnpHandle,
452 IN EFI_HANDLE ImageHandle,
453 IN OUT CHAR16 **MacString
454 );
455
456 VOID
457 NetLibCreateIPv4DPathNode (
458 IN OUT IPv4_DEVICE_PATH *Node,
459 IN EFI_HANDLE Controller,
460 IN IP4_ADDR LocalIp,
461 IN UINT16 LocalPort,
462 IN IP4_ADDR RemoteIp,
463 IN UINT16 RemotePort,
464 IN UINT16 Protocol,
465 IN BOOLEAN UseDefaultAddress
466 );
467
468 EFI_HANDLE
469 NetLibGetNicHandle (
470 IN EFI_HANDLE Controller,
471 IN EFI_GUID *ProtocolGuid
472 );
473
474 EFI_STATUS
475 NetLibQueueDpc (
476 IN EFI_TPL DpcTpl,
477 IN EFI_DPC_PROCEDURE DpcProcedure,
478 IN VOID *DpcContext OPTIONAL
479 );
480
481 EFI_STATUS
482 NetLibDispatchDpc (
483 VOID
484 );
485
486 EFI_STATUS
487 EFIAPI
488 NetLibDefaultUnload (
489 IN EFI_HANDLE ImageHandle
490 );
491
492 enum {
493 //
494 //Various signatures
495 //
496 NET_BUF_SIGNATURE = EFI_SIGNATURE_32 ('n', 'b', 'u', 'f'),
497 NET_VECTOR_SIGNATURE = EFI_SIGNATURE_32 ('n', 'v', 'e', 'c'),
498 NET_QUE_SIGNATURE = EFI_SIGNATURE_32 ('n', 'b', 'q', 'u'),
499
500
501 NET_PROTO_DATA = 64, // Opaque buffer for protocols
502 NET_BUF_HEAD = 1, // Trim or allocate space from head
503 NET_BUF_TAIL = 0, // Trim or allocate space from tail
504 NET_VECTOR_OWN_FIRST = 0x01, // We allocated the 1st block in the vector
505 };
506
507 #define NET_CHECK_SIGNATURE(PData, SIGNATURE) \
508 ASSERT (((PData) != NULL) && ((PData)->Signature == (SIGNATURE)))
509
510 #define NET_SWAP_SHORT(Value) \
511 ((((Value) & 0xff) << 8) | (((Value) >> 8) & 0xff))
512
513 //
514 // Single memory block in the vector.
515 //
516 typedef struct {
517 UINT32 Len; // The block's length
518 UINT8 *Bulk; // The block's Data
519 } NET_BLOCK;
520
521 typedef VOID (*NET_VECTOR_EXT_FREE) (VOID *Arg);
522
523 //
524 //NET_VECTOR contains several blocks to hold all packet's
525 //fragments and other house-keeping stuff for sharing. It
526 //doesn't specify the where actual packet fragment begins.
527 //
528 typedef struct {
529 UINT32 Signature;
530 INTN RefCnt; // Reference count to share NET_VECTOR.
531 NET_VECTOR_EXT_FREE Free; // external function to free NET_VECTOR
532 VOID *Arg; // opeque argument to Free
533 UINT32 Flag; // Flags, NET_VECTOR_OWN_FIRST
534 UINT32 Len; // Total length of the assocated BLOCKs
535
536 UINT32 BlockNum;
537 NET_BLOCK Block[1];
538 } NET_VECTOR;
539
540 //
541 //NET_BLOCK_OP operate on the NET_BLOCK, It specifies
542 //where the actual fragment begins and where it ends
543 //
544 typedef struct {
545 UINT8 *BlockHead; // Block's head, or the smallest valid Head
546 UINT8 *BlockTail; // Block's tail. BlockTail-BlockHead=block length
547 UINT8 *Head; // 1st byte of the data in the block
548 UINT8 *Tail; // Tail of the data in the block, Tail-Head=Size
549 UINT32 Size; // The size of the data
550 } NET_BLOCK_OP;
551
552
553 //
554 //NET_BUF is the buffer manage structure used by the
555 //network stack. Every network packet may be fragmented,
556 //and contains multiple fragments. The Vector points to
557 //memory blocks used by the each fragment, and BlockOp
558 //specifies where each fragment begins and ends.
559 //
560 //It also contains a opaque area for protocol to store
561 //per-packet informations. Protocol must be caution not
562 //to overwrite the members after that.
563 //
564 typedef struct {
565 UINT32 Signature;
566 INTN RefCnt;
567 NET_LIST_ENTRY List; // The List this NET_BUF is on
568
569 IP4_HEAD *Ip; // Network layer header, for fast access
570 TCP_HEAD *Tcp; // Transport layer header, for fast access
571 UINT8 ProtoData [NET_PROTO_DATA]; //Protocol specific data
572
573 NET_VECTOR *Vector; // The vector containing the packet
574
575 UINT32 BlockOpNum; // Total number of BlockOp in the buffer
576 UINT32 TotalSize; // Total size of the actual packet
577 NET_BLOCK_OP BlockOp[1]; // Specify the position of actual packet
578 } NET_BUF;
579
580
581 //
582 //A queue of NET_BUFs, It is just a thin extension of
583 //NET_BUF functions.
584 //
585 typedef struct {
586 UINT32 Signature;
587 INTN RefCnt;
588 NET_LIST_ENTRY List; // The List this buffer queue is on
589
590 NET_LIST_ENTRY BufList; // list of queued buffers
591 UINT32 BufSize; // total length of DATA in the buffers
592 UINT32 BufNum; // total number of buffers on the chain
593 } NET_BUF_QUEUE;
594
595 //
596 // Pseudo header for TCP and UDP checksum
597 //
598 #pragma pack(1)
599 typedef struct {
600 IP4_ADDR SrcIp;
601 IP4_ADDR DstIp;
602 UINT8 Reserved;
603 UINT8 Protocol;
604 UINT16 Len;
605 } NET_PSEUDO_HDR;
606 #pragma pack()
607
608 //
609 // The fragment entry table used in network interfaces. This is
610 // the same as NET_BLOCK now. Use two different to distinguish
611 // the two in case that NET_BLOCK be enhanced later.
612 //
613 typedef struct {
614 UINT32 Len;
615 UINT8 *Bulk;
616 } NET_FRAGMENT;
617
618 #define NET_GET_REF(PData) ((PData)->RefCnt++)
619 #define NET_PUT_REF(PData) ((PData)->RefCnt--)
620 #define NETBUF_FROM_PROTODATA(Info) _CR((Info), NET_BUF, ProtoData)
621
622 #define NET_BUF_SHARED(Buf) \
623 (((Buf)->RefCnt > 1) || ((Buf)->Vector->RefCnt > 1))
624
625 #define NET_VECTOR_SIZE(BlockNum) \
626 (sizeof (NET_VECTOR) + ((BlockNum) - 1) * sizeof (NET_BLOCK))
627
628 #define NET_BUF_SIZE(BlockOpNum) \
629 (sizeof (NET_BUF) + ((BlockOpNum) - 1) * sizeof (NET_BLOCK_OP))
630
631 #define NET_HEADSPACE(BlockOp) \
632 (UINTN)((BlockOp)->Head - (BlockOp)->BlockHead)
633
634 #define NET_TAILSPACE(BlockOp) \
635 (UINTN)((BlockOp)->BlockTail - (BlockOp)->Tail)
636
637 NET_BUF *
638 NetbufAlloc (
639 IN UINT32 Len
640 );
641
642 VOID
643 NetbufFree (
644 IN NET_BUF *Nbuf
645 );
646
647
648 UINT8 *
649 NetbufGetByte (
650 IN NET_BUF *Nbuf,
651 IN UINT32 Offset,
652 OUT UINT32 *Index OPTIONAL
653 );
654
655 NET_BUF *
656 NetbufClone (
657 IN NET_BUF *Nbuf
658 );
659
660 NET_BUF *
661 NetbufDuplicate (
662 IN NET_BUF *Nbuf,
663 IN NET_BUF *Duplicate OPTIONAL,
664 IN UINT32 HeadSpace
665 );
666
667 NET_BUF *
668 NetbufGetFragment (
669 IN NET_BUF *Nbuf,
670 IN UINT32 Offset,
671 IN UINT32 Len,
672 IN UINT32 HeadSpace
673 );
674
675 VOID
676 NetbufReserve (
677 IN NET_BUF *Nbuf,
678 IN UINT32 Len
679 );
680
681 UINT8 *
682 NetbufAllocSpace (
683 IN NET_BUF *Nbuf,
684 IN UINT32 Len,
685 IN BOOLEAN FromHead
686 );
687
688 UINT32
689 NetbufTrim (
690 IN NET_BUF *Nbuf,
691 IN UINT32 Len,
692 IN BOOLEAN FromHead
693 );
694
695 UINT32
696 NetbufCopy (
697 IN NET_BUF *Nbuf,
698 IN UINT32 Offset,
699 IN UINT32 Len,
700 IN UINT8 *Dest
701 );
702
703 NET_BUF *
704 NetbufFromExt (
705 IN NET_FRAGMENT *ExtFragment,
706 IN UINT32 ExtNum,
707 IN UINT32 HeadSpace,
708 IN UINT32 HeadLen,
709 IN NET_VECTOR_EXT_FREE ExtFree,
710 IN VOID *Arg OPTIONAL
711 );
712
713 EFI_STATUS
714 NetbufBuildExt (
715 IN NET_BUF *Nbuf,
716 IN NET_FRAGMENT *ExtFragment,
717 IN UINT32 *ExtNum
718 );
719
720 NET_BUF *
721 NetbufFromBufList (
722 IN NET_LIST_ENTRY *BufList,
723 IN UINT32 HeadSpace,
724 IN UINT32 HeaderLen,
725 IN NET_VECTOR_EXT_FREE ExtFree,
726 IN VOID *Arg OPTIONAL
727 );
728
729 VOID
730 NetbufFreeList (
731 IN NET_LIST_ENTRY *Head
732 );
733
734 VOID
735 NetbufQueInit (
736 IN NET_BUF_QUEUE *NbufQue
737 );
738
739 NET_BUF_QUEUE *
740 NetbufQueAlloc (
741 VOID
742 );
743
744 VOID
745 NetbufQueFree (
746 IN NET_BUF_QUEUE *NbufQue
747 );
748
749 NET_BUF *
750 NetbufQueRemove (
751 IN NET_BUF_QUEUE *NbufQue
752 );
753
754 VOID
755 NetbufQueAppend (
756 IN NET_BUF_QUEUE *NbufQue,
757 IN NET_BUF *Nbuf
758 );
759
760 UINT32
761 NetbufQueCopy (
762 IN NET_BUF_QUEUE *NbufQue,
763 IN UINT32 Offset,
764 IN UINT32 Len,
765 IN UINT8 *Dest
766 );
767
768 UINT32
769 NetbufQueTrim (
770 IN NET_BUF_QUEUE *NbufQue,
771 IN UINT32 Len
772 );
773
774 VOID
775 NetbufQueFlush (
776 IN NET_BUF_QUEUE *NbufQue
777 );
778
779 UINT16
780 NetblockChecksum (
781 IN UINT8 *Bulk,
782 IN UINT32 Len
783 );
784
785 UINT16
786 NetAddChecksum (
787 IN UINT16 Checksum1,
788 IN UINT16 Checksum2
789 );
790
791 UINT16
792 NetbufChecksum (
793 IN NET_BUF *Nbuf
794 );
795
796 UINT16
797 NetPseudoHeadChecksum (
798 IN IP4_ADDR Src,
799 IN IP4_ADDR Dst,
800 IN UINT8 Proto,
801 IN UINT16 Len
802 );
803
804 //
805 // The debug level definition. This value is also used as the
806 // syslog's servity level. Don't change it.
807 //
808 enum {
809 NETDEBUG_LEVEL_TRACE = 5,
810 NETDEBUG_LEVEL_WARNING = 4,
811 NETDEBUG_LEVEL_ERROR = 3,
812 };
813
814 #ifdef EFI_NETWORK_STACK_DEBUG
815
816 //
817 // The debug output expects the ASCII format string, Use %a to print ASCII
818 // string, and %s to print UNICODE string. PrintArg must be enclosed in ().
819 // For example: NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name));
820 //
821 #define NET_DEBUG_TRACE(Module, PrintArg) \
822 NetDebugOutput ( \
823 NETDEBUG_LEVEL_TRACE, \
824 Module, \
825 __FILE__, \
826 __LINE__, \
827 NetDebugASPrint PrintArg \
828 )
829
830 #define NET_DEBUG_WARNING(Module, PrintArg) \
831 NetDebugOutput ( \
832 NETDEBUG_LEVEL_WARNING, \
833 Module, \
834 __FILE__, \
835 __LINE__, \
836 NetDebugASPrint PrintArg \
837 )
838
839 #define NET_DEBUG_ERROR(Module, PrintArg) \
840 NetDebugOutput ( \
841 NETDEBUG_LEVEL_ERROR, \
842 Module, \
843 __FILE__, \
844 __LINE__, \
845 NetDebugASPrint PrintArg \
846 )
847
848 #else
849 #define NET_DEBUG_TRACE(Module, PrintString)
850 #define NET_DEBUG_WARNING(Module, PrintString)
851 #define NET_DEBUG_ERROR(Module, PrintString)
852 #endif
853
854 UINT8 *
855 NetDebugASPrint (
856 UINT8 *Format,
857 ...
858 );
859
860 EFI_STATUS
861 NetDebugOutput (
862 UINT32 Level,
863 UINT8 *Module,
864 UINT8 *File,
865 UINT32 Line,
866 UINT8 *Message
867 );
868
869 //
870 // Network debug message is sent out as syslog.
871 //
872 enum {
873 NET_SYSLOG_FACILITY = 16, // Syslog local facility local use
874 NET_SYSLOG_PACKET_LEN = 512,
875 NET_DEBUG_MSG_LEN = 470, // 512 - (ether+ip+udp head length)
876 NET_SYSLOG_TX_TIMEOUT = 500 *1000 *10, // 500ms
877 };
878 #endif