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