#define _NET_LIB_H_
#include <PiDxe.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/ComponentName.h>
#include <Protocol/DriverConfiguration.h>
#include <Protocol/DriverDiagnostics.h>
-
-#define EFI_NET_LITTLE_ENDIAN
+#include <Protocol/Dpc.h>
typedef UINT32 IP4_ADDR;
typedef UINT32 TCP_SEQNO;
// directly. This is why there is an internal representation.
//
typedef struct {
-#ifdef EFI_NET_LITTLE_ENDIAN
UINT8 HeadLen : 4;
UINT8 Ver : 4;
-#else
- UINT8 Ver : 4;
- UINT8 HeadLen : 4;
-#endif
UINT8 Tos;
UINT16 TotalLen;
UINT16 Id;
TCP_PORTNO DstPort;
TCP_SEQNO Seq;
TCP_SEQNO Ack;
-#ifdef EFI_NET_LITTLE_ENDIAN
UINT8 Res : 4;
UINT8 HeadLen : 4;
-#else
- UINT8 HeadLen : 4;
- UINT8 Res : 4;
-#endif
UINT8 Flag;
UINT16 Wnd;
UINT16 Checksum;
#pragma pack()
#define NET_MAC_EQUAL(pMac1, pMac2, Len) \
- (NetCompareMem ((pMac1), (pMac2), Len) == 0)
+ (CompareMem ((pMac1), (pMac2), Len) == 0)
#define NET_MAC_IS_MULTICAST(Mac, BMac, Len) \
(((*((UINT8 *) Mac) & 0x01) == 0x01) && (!NET_MAC_EQUAL (Mac, BMac, Len)))
-#ifdef EFI_NET_LITTLE_ENDIAN
#define NTOHL(x) (UINT32)((((UINT32) (x) & 0xff) << 24) | \
(((UINT32) (x) & 0xff00) << 8) | \
(((UINT32) (x) & 0xff0000) >> 8) | \
(((UINT16) (x) & 0xff00) >> 8))
#define HTONS(x) NTOHS(x)
-#else
-#define NTOHL(x) (UINT32)(x)
-#define HTONL(x) (UINT32)(x)
-#define NTOHS(x) (UINT16)(x)
-#define HTONS(x) (UINT16)(x)
-#endif
//
// Test the IP's attribute, All the IPs are in host byte order.
//
// Convert the EFI_IP4_ADDRESS to plain UINT32 IP4 address.
//
-#define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))
-#define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))
-#define EFI_IP_EQUAL(Ip1, Ip2) (EFI_IP4 (Ip1) == EFI_IP4 (Ip2))
+#define EFI_IP4(EfiIpAddr) (*(IP4_ADDR *) ((EfiIpAddr).Addr))
+#define EFI_NTOHL(EfiIp) (NTOHL (EFI_IP4 ((EfiIp))))
+#define EFI_IP4_EQUAL(Ip1, Ip2) (CompareMem ((Ip1), (Ip2), sizeof (EFI_IPv4_ADDRESS)) == 0)
INTN
NetGetMaskLength (
extern IP4_ADDR mIp4AllMasks [IP4_MASK_NUM];
-//@MT:#include EFI_PROTOCOL_CONSUMER (LoadedImage)
-//@MT:#include EFI_PROTOCOL_CONSUMER (ServiceBinding)
-//@MT:#include EFI_PROTOCOL_CONSUMER (SimpleNetwork)
-//
-// Wrap functions to ease the impact of EFI library changes.
-//
-#define NetAllocateZeroPool AllocateZeroPool
-#define NetAllocatePool AllocatePool
-#define NetFreePool gBS->FreePool
-#define NetCopyMem CopyMem
-#define NetSetMem SetMem
-#define NetZeroMem(Dest, Len) SetMem ((Dest), (Len), 0)
-#define NetCompareMem CompareMem
-
-//
-// Lock primitives: the stack implements its lock primitives according
-// to the standard EFI enviornment. It will NOT consider multiprocessor.
-//
-#define NET_TPL_LOCK TPL_CALLBACK
-#define NET_TPL_RECYCLE_LOCK (NET_TPL_LOCK + 1)
-#define NET_TPL_EVENT TPL_CALLBACK
-#define NET_TPL_RECYCLE (NET_TPL_LOCK + 1)
-#define NET_TPL_SLOW_TIMER (TPL_CALLBACK - 1)
-#define NET_TPL_FAST_TIMER NET_TPL_RECYCLE
-#define NET_TPL_TIMER TPL_CALLBACK
-
-#define NET_LOCK EFI_LOCK
-#define NET_LOCK_INIT(x) EfiInitializeLock (x, NET_TPL_LOCK)
-#define NET_RECYCLE_LOCK_INIT(x) EfiInitializeLock (x, NET_TPL_RECYCLE_LOCK)
-#define NET_TRYLOCK(x) EfiAcquireLockOrFail (x)
-#define NET_UNLOCK(x) EfiReleaseLock (x)
+extern EFI_IPv4_ADDRESS mZeroIp4Addr;
-#define NET_RAISE_TPL(x) (gBS->RaiseTPL (x))
-#define NET_RESTORE_TPL(x) (gBS->RestoreTPL (x))
+#define NET_IS_DIGIT(Ch) (('0' <= (Ch)) && ((Ch) <= '9'))
+#define NET_ROUNDUP(size, unit) (((size) + (unit) - 1) & (~((unit) - 1)))
+#define NET_IS_LOWER_CASE_CHAR(Ch) (('a' <= (Ch)) && ((Ch) <= 'z'))
+#define NET_IS_UPPER_CASE_CHAR(Ch) (('A' <= (Ch)) && ((Ch) <= 'Z'))
#define TICKS_PER_MS 10000U
#define TICKS_PER_SECOND 10000000U
-#define NET_MIN(a, b) ((a) < (b) ? (a) : (b))
-#define NET_MAX(a, b) ((a) > (b) ? (a) : (b))
-#define NET_RANDOM(Seed) (((Seed) * 1103515245L + 12345) % 4294967295L)
+#define NET_RANDOM(Seed) ((UINT32) ((UINT32) (Seed) * 1103515245UL + 12345) % 4294967295UL)
UINT32
);
-//
-// Double linked list entry functions, this extends the
-// EFI list functions.
-//
-typedef LIST_ENTRY NET_LIST_ENTRY;
-
-#define NetListInit(Head) InitializeListHead(Head)
-#define NetListInsertHead(Head, Entry) InsertHeadList((Head), (Entry))
-#define NetListInsertTail(Head, Entry) InsertTailList((Head), (Entry))
-#define NetListIsEmpty(List) IsListEmpty(List)
-
#define NET_LIST_USER_STRUCT(Entry, Type, Field) \
_CR(Entry, Type, Field)
#define NET_LIST_TAIL(ListHead, Type, Field) \
NET_LIST_USER_STRUCT((ListHead)->BackLink, Type, Field)
-#define NetListRemoveEntry(Entry) RemoveEntryList (Entry)
-NET_LIST_ENTRY*
+LIST_ENTRY *
NetListRemoveHead (
- NET_LIST_ENTRY *Head
+ LIST_ENTRY *Head
);
-NET_LIST_ENTRY*
+LIST_ENTRY *
NetListRemoveTail (
- NET_LIST_ENTRY *Head
+ LIST_ENTRY *Head
);
VOID
NetListInsertAfter (
- IN NET_LIST_ENTRY *PrevEntry,
- IN NET_LIST_ENTRY *NewEntry
+ IN LIST_ENTRY *PrevEntry,
+ IN LIST_ENTRY *NewEntry
);
VOID
NetListInsertBefore (
- IN NET_LIST_ENTRY *PostEntry,
- IN NET_LIST_ENTRY *NewEntry
+ IN LIST_ENTRY *PostEntry,
+ IN LIST_ENTRY *NewEntry
);
// tokens. The drivers can share code to manage those objects.
//
typedef struct {
- NET_LIST_ENTRY Link;
+ LIST_ENTRY Link;
VOID *Key;
VOID *Value;
} NET_MAP_ITEM;
typedef struct {
- NET_LIST_ENTRY Used;
- NET_LIST_ENTRY Recycled;
+ LIST_ENTRY Used;
+ LIST_ENTRY Recycled;
UINTN Count;
} NET_MAP;
NetLibGetMacString (
IN EFI_HANDLE SnpHandle,
IN EFI_HANDLE ImageHandle,
- IN OUT CONST CHAR16 **MacString
+ IN OUT CHAR16 **MacString
+ );
+
+VOID
+NetLibCreateIPv4DPathNode (
+ IN OUT IPv4_DEVICE_PATH *Node,
+ IN EFI_HANDLE Controller,
+ IN IP4_ADDR LocalIp,
+ IN UINT16 LocalPort,
+ IN IP4_ADDR RemoteIp,
+ IN UINT16 RemotePort,
+ IN UINT16 Protocol,
+ IN BOOLEAN UseDefaultAddress
);
EFI_HANDLE
IN EFI_GUID *ProtocolGuid
);
-typedef
EFI_STATUS
-(EFIAPI *NET_LIB_DRIVER_UNLOAD) (
- IN EFI_HANDLE ImageHandle
+NetLibQueueDpc (
+ IN EFI_TPL DpcTpl,
+ IN EFI_DPC_PROCEDURE DpcProcedure,
+ IN VOID *DpcContext OPTIONAL
);
EFI_STATUS
-EFIAPI
-NetLibDefaultUnload (
- IN EFI_HANDLE ImageHandle
+NetLibDispatchDpc (
+ VOID
);
EFI_STATUS
-NetLibInstallAllDriverProtocolsWithUnload (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable,
- IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,
- IN EFI_HANDLE DriverBindingHandle,
- IN EFI_COMPONENT_NAME_PROTOCOL *ComponentName, OPTIONAL
- IN EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, OPTIONAL
- IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics, OPTIONAL
- IN NET_LIB_DRIVER_UNLOAD CustomizedUnload
+EFIAPI
+NetLibDefaultUnload (
+ IN EFI_HANDLE ImageHandle
);
-EFI_STATUS
-NetLibInstallAllDriverProtocols (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable,
- IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,
- IN EFI_HANDLE DriverBindingHandle,
- IN EFI_COMPONENT_NAME_PROTOCOL *ComponentName, OPTIONAL
- IN EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, OPTIONAL
- IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics OPTIONAL
- );
-\r
enum {
//
//Various signatures
typedef struct {
UINT32 Signature;
INTN RefCnt;
- NET_LIST_ENTRY List; // The List this NET_BUF is on
+ LIST_ENTRY List; // The List this NET_BUF is on
IP4_HEAD *Ip; // Network layer header, for fast access
TCP_HEAD *Tcp; // Transport layer header, for fast access
typedef struct {
UINT32 Signature;
INTN RefCnt;
- NET_LIST_ENTRY List; // The List this buffer queue is on
+ LIST_ENTRY List; // The List this buffer queue is on
- NET_LIST_ENTRY BufList; // list of queued buffers
+ LIST_ENTRY BufList; // list of queued buffers
UINT32 BufSize; // total length of DATA in the buffers
UINT32 BufNum; // total number of buffers on the chain
} NET_BUF_QUEUE;
NET_BUF *
NetbufFromBufList (
- IN NET_LIST_ENTRY *BufList,
+ IN LIST_ENTRY *BufList,
IN UINT32 HeadSpace,
IN UINT32 HeaderLen,
IN NET_VECTOR_EXT_FREE ExtFree,
VOID
NetbufFreeList (
- IN NET_LIST_ENTRY *Head
+ IN LIST_ENTRY *Head
);
VOID
IN UINT16 Len
);
-//\r
-// The debug level definition. This value is also used as the\r
-// syslog's servity level. Don't change it.\r
-//\r
-enum {\r
- NETDEBUG_LEVEL_TRACE = 5,\r
- NETDEBUG_LEVEL_WARNING = 4,\r
- NETDEBUG_LEVEL_ERROR = 3,\r
-};\r
-\r
-#ifdef EFI_NETWORK_STACK_DEBUG\r
-\r
-//\r
-// The debug output expects the ASCII format string, Use %a to print ASCII\r
-// string, and %s to print UNICODE string. PrintArg must be enclosed in ().\r
-// For example: NET_DEBUG_TRACE ("Tcp", ("State transit to %a\n", Name));\r
-//\r
-#define NET_DEBUG_TRACE(Module, PrintArg) \\r
- NetDebugOutput ( \\r
- NETDEBUG_LEVEL_TRACE, \\r
- Module, \\r
- __FILE__, \\r
- __LINE__, \\r
- NetDebugASPrint PrintArg \\r
- )\r
-\r
-#define NET_DEBUG_WARNING(Module, PrintArg) \\r
- NetDebugOutput ( \\r
- NETDEBUG_LEVEL_WARNING, \\r
- Module, \\r
- __FILE__, \\r
- __LINE__, \\r
- NetDebugASPrint PrintArg \\r
- )\r
-\r
-#define NET_DEBUG_ERROR(Module, PrintArg) \\r
- NetDebugOutput ( \\r
- NETDEBUG_LEVEL_ERROR, \\r
- Module, \\r
- __FILE__, \\r
- __LINE__, \\r
- NetDebugASPrint PrintArg \\r
- )\r
-\r
-#else\r
-#define NET_DEBUG_TRACE(Module, PrintString)\r
-#define NET_DEBUG_WARNING(Module, PrintString)\r
-#define NET_DEBUG_ERROR(Module, PrintString)\r
-#endif\r
-\r
-UINT8 *\r
-NetDebugASPrint (\r
- UINT8 *Format,\r
- ...\r
- );\r
-\r
-EFI_STATUS\r
-NetDebugOutput (\r
- UINT32 Level,\r
- UINT8 *Module,\r
- UINT8 *File,\r
- UINT32 Line,\r
- UINT8 *Message\r
- );\r
-\r
-//\r
-// Network debug message is sent out as syslog.\r
-//\r
-enum {\r
- NET_SYSLOG_FACILITY = 16, // Syslog local facility local use\r
- NET_SYSLOG_PACKET_LEN = 512,\r
- NET_DEBUG_MSG_LEN = 470, // 512 - (ether+ip+udp head length)\r
- NET_SYSLOG_TX_TIMEOUT = 500 *1000 *10, // 500ms\r
-};
#endif