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