Basic NDIS 3.0 support
authorCasper Hornstrup <chorns@users.sourceforge.net>
Sun, 27 Aug 2000 16:31:41 +0000 (16:31 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Sun, 27 Aug 2000 16:31:41 +0000 (16:31 +0000)
svn path=/trunk/; revision=1318

13 files changed:
reactos/drivers/net/ndis/include/buffer.h
reactos/drivers/net/ndis/include/debug.h
reactos/drivers/net/ndis/include/miniport.h
reactos/drivers/net/ndis/include/ndissys.h
reactos/drivers/net/ndis/include/protocol.h
reactos/drivers/net/ndis/ndis/buffer.c
reactos/drivers/net/ndis/ndis/io.c
reactos/drivers/net/ndis/ndis/main.c
reactos/drivers/net/ndis/ndis/miniport.c
reactos/drivers/net/ndis/ndis/protocol.c
reactos/drivers/net/ndis/ndis/stubs.c
reactos/include/net/ndis.h
reactos/include/net/ntddndis.h [new file with mode: 0644]

index eaa2a1e..7beaa66 100644 (file)
@@ -25,6 +25,32 @@ typedef struct _NDIS_BUFFER_POOL
     NETWORK_HEADER Buffers[0];
 } NDIS_BUFFER_POOL, *PNDIS_BUFFER_POOL;
 
+
+UINT CopyBufferToBufferChain(
+    PNDIS_BUFFER DstBuffer,
+    UINT DstOffset,
+    PUCHAR SrcData,
+    UINT Length);
+
+UINT CopyBufferChainToBuffer(
+    PUCHAR DstData,
+    PNDIS_BUFFER SrcBuffer,
+    UINT SrcOffset,
+    UINT Length);
+
+UINT CopyPacketToBuffer(
+    PUCHAR DstData,
+    PNDIS_PACKET SrcPacket,
+    UINT SrcOffset,
+    UINT Length);
+
+UINT CopyPacketToBufferChain(
+    PNDIS_BUFFER DstBuffer,
+    UINT DstOffset,
+    PNDIS_PACKET SrcPacket,
+    UINT SrcOffset,
+    UINT Length);
+
 #endif /* __BUFFER_H */
 
 /* EOF */
index 35c0aef..74d540c 100644 (file)
@@ -18,6 +18,7 @@
 #define DEBUG_REFCOUNT 0x00000100
 #define DEBUG_MINIPORT 0x00000200
 #define DEBUG_PROTOCOL 0x00000400
+#define DEBUG_PACKET   0x00000800
 #define DEBUG_ULTRA    0xFFFFFFFF
 
 #ifdef DBG
@@ -74,7 +75,7 @@ extern DWORD DebugTraceLevel;
 #ifdef _MSC_VER
 
 #define UNIMPLEMENTED \
-    NDIS_DbgPrint(MIN_TRACE, ("The function at %s:%d is unimplemented.\n", __FILE__, __LINE__));
+    NDIS_DbgPrint(MIN_TRACE, ("The function at (%s:%d) is unimplemented.\n", __FILE__, __LINE__));
 
 #else /* _MSC_VER */
 
@@ -85,7 +86,7 @@ extern DWORD DebugTraceLevel;
 
 
 #define CHECKPOINT \
-    do { NDIS_DbgPrint(MIN_TRACE, ("%s:%d\n", __FILE__, __LINE__)); } while(0);
+    do { NDIS_DbgPrint(MIN_TRACE, ("(%s:%d)\n", __FILE__, __LINE__)); } while(0);
 
 #endif /* __DEBUG_H */
 
index 27ce3f6..9c4009c 100644 (file)
 #include <ndissys.h>
 
 
+typedef struct _HARDWARE_ADDRESS {
+    union {
+        UCHAR Medium802_3[ETH_LENGTH_OF_ADDRESS];
+    } Type;
+} HARDWARE_ADDRESS, *PHARDWARE_ADDRESS;
+
 /* Information about a miniport */
 typedef struct _MINIPORT_DRIVER {
     LIST_ENTRY                      ListEntry;          /* Entry on global list */
@@ -19,7 +25,6 @@ typedef struct _MINIPORT_DRIVER {
     NDIS_MINIPORT_CHARACTERISTICS   Chars;              /* Miniport characteristics */
     WORK_QUEUE_ITEM                 WorkItem;           /* Work item */
     PDRIVER_OBJECT                  DriverObject;       /* Driver object of miniport */
-    NDIS_STRING                     RegistryPath;       /* Registry path of miniport */
     LIST_ENTRY                      AdapterListHead;    /* Adapters created by miniport */
 } MINIPORT_DRIVER, *PMINIPORT_DRIVER;
 
@@ -27,40 +32,102 @@ typedef struct _MINIPORT_DRIVER {
 
 /* Information about a logical adapter */
 typedef struct _LOGICAL_ADAPTER {
+    NDIS_MINIPORT_BLOCK;                                /* NDIS defined fields */
+
+    KDPC                        MiniportDpc;            /* DPC routine for adapter */
+    BOOLEAN                     MiniportBusy;           /* A MiniportXxx routine is executing */
+    NDIS_HANDLE                 MiniportAdapterBinding; /* Binding handle for current caller */
+    ULONG                       WorkQueueLevel;         /* Number of used work item buffers */
+    NDIS_MINIPORT_WORK_ITEM     WorkQueue[NDIS_MINIPORT_WORK_QUEUE_SIZE];
+    PNDIS_MINIPORT_WORK_ITEM    WorkQueueHead;          /* Head of work queue */
+    PNDIS_MINIPORT_WORK_ITEM    WorkQueueTail;          /* Tail of work queue */
+
     LIST_ENTRY                  ListEntry;              /* Entry on global list */
     LIST_ENTRY                  MiniportListEntry;      /* Entry on miniport driver list */
-    KSPIN_LOCK                  Lock;                   /* Protecting spin lock */
+    LIST_ENTRY                  ProtocolListHead;       /* List of bound protocols */
     ULONG                       RefCount;               /* Reference count */
     PMINIPORT_DRIVER            Miniport;               /* Miniport owning this adapter */
     UNICODE_STRING              DeviceName;             /* Device name of this adapter */
-    PDEVICE_OBJECT              DeviceObject;           /* Device object of adapter */
-    PVOID                       MiniportAdapterContext; /* Adapter context for miniport */
     ULONG                       Attributes;             /* Attributes of adapter */
-    NDIS_INTERFACE_TYPE         AdapterType;            /* Type of adapter interface */
     /* TRUE if the miniport has called NdisSetAttributes(Ex) for this adapter */
     BOOLEAN                     AttributesSet;
-    PNDIS_MINIPORT_INTERRUPT    InterruptObject;        /* Interrupt object for adapter */
     PVOID                       QueryBuffer;            /* Buffer to use for queries */
     ULONG                       QueryBufferLength;      /* Length of QueryBuffer */
+    ULONG                       MediumHeaderSize;       /* Size of medium header */
+    HARDWARE_ADDRESS            Address;                /* Hardware address of adapter */
+    ULONG                       AddressLength;          /* Length of hardware address */
+    PUCHAR                      LookaheadBuffer;        /* Pointer to lookahead buffer */
+    ULONG                       LookaheadLength;        /* Length of lookahead buffer */
+    ULONG                       CurLookaheadLength;     /* Current (selected) length of lookahead buffer */
+    ULONG                       MaxLookaheadLength;     /* Maximum length of lookahead buffer */
+
+    PNDIS_PACKET                PacketQueueHead;        /* Head of packet queue */
+    PNDIS_PACKET                PacketQueueTail;        /* Head of packet queue */
+
+    PNDIS_PACKET                LoopPacket;             /* Current packet beeing looped */
 } LOGICAL_ADAPTER, *PLOGICAL_ADAPTER;
 
 #define GET_LOGICAL_ADAPTER(Handle)((PLOGICAL_ADAPTER)Handle)
 
-
 extern LIST_ENTRY MiniportListHead;
 extern KSPIN_LOCK MiniportListLock;
 extern LIST_ENTRY AdapterListHead;
 extern KSPIN_LOCK AdapterListLock;
 
-PLOGICAL_ADAPTER MiniLocateDevice(
+
+#ifdef DBG
+VOID
+MiniDisplayPacket(
+    PNDIS_PACKET Packet);
+#endif /* DBG */
+
+VOID
+MiniIndicateData(
+    PLOGICAL_ADAPTER    Adapter,
+    NDIS_HANDLE         MacReceiveContext,
+    PVOID               HeaderBuffer,
+    UINT                HeaderBufferSize,
+    PVOID               LookaheadBuffer,
+    UINT                LookaheadBufferSize,
+    UINT                PacketSize);
+
+BOOLEAN
+MiniAdapterHasAddress(
+    PLOGICAL_ADAPTER Adapter,
+    PNDIS_PACKET Packet);
+
+PLOGICAL_ADAPTER
+MiniLocateDevice(
     PNDIS_STRING AdapterName);
 
-NDIS_STATUS MiniQueryInformation(
+NDIS_STATUS
+MiniQueryInformation(
     PLOGICAL_ADAPTER    Adapter,
     NDIS_OID            Oid,
     ULONG               Size,
     PULONG              BytesWritten);
 
+NDIS_STATUS
+FASTCALL
+MiniQueueWorkItem(
+    PLOGICAL_ADAPTER    Adapter,
+    NDIS_WORK_ITEM_TYPE WorkItemType,
+    PVOID               WorkItemContext,
+    NDIS_HANDLE         Initiator);
+
+NDIS_STATUS
+FASTCALL
+MiniDequeueWorkItem(
+    PLOGICAL_ADAPTER    Adapter,
+    NDIS_WORK_ITEM_TYPE *WorkItemType,
+    PVOID               *WorkItemContext,
+    NDIS_HANDLE         *Initiator);
+
+NDIS_STATUS
+MiniDoRequest(
+    PLOGICAL_ADAPTER Adapter,
+    PNDIS_REQUEST NdisRequest);
+
 #endif /* __MINIPORT_H */
 
 /* EOF */
index bed6df7..8c3bdee 100644 (file)
         PoolFreeBuffer(Object);                           \
 }
 
+
+#define MIN(value1, value2) \
+    ((value1 < value2)? value1 : value2)
+
+#define MAX(value1, value2) \
+    ((value1 > value2)? value1 : value2)
+
 #endif /* __NDISSYS_H */
 
 /* EOF */
index ba4c025..4711d98 100644 (file)
@@ -25,11 +25,15 @@ typedef struct _PROTOCOL_BINDING {
 
 
 typedef struct _ADAPTER_BINDING {
-    LIST_ENTRY       ListEntry;         /* Entry on global list */
-    LIST_ENTRY       ProtocolListEntry; /* Entry on protocol binding adapter list */
-    KSPIN_LOCK       Lock;              /* Protecting spin lock */
-    ULONG            RefCount;          /* Reference count */
-    PLOGICAL_ADAPTER Adapter;           /* Adapter opened by protocol */
+    NDIS_OPEN_BLOCK;                            /* NDIS defined fields */
+
+    LIST_ENTRY        ListEntry;                /* Entry on global list */
+    LIST_ENTRY        ProtocolListEntry;        /* Entry on protocol binding adapter list */
+    LIST_ENTRY        AdapterListEntry;         /* Entry on logical adapter list */
+    KSPIN_LOCK        Lock;                     /* Protecting spin lock */
+    ULONG             RefCount;                 /* Reference count */
+    PPROTOCOL_BINDING ProtocolBinding;          /* Protocol that opened adapter */
+    PLOGICAL_ADAPTER  Adapter;                  /* Adapter opened by protocol */
 } ADAPTER_BINDING, *PADAPTER_BINDING;
 
 #define GET_ADAPTER_BINDING(Handle)((PADAPTER_BINDING)Handle)
@@ -38,6 +42,12 @@ typedef struct _ADAPTER_BINDING {
 extern LIST_ENTRY ProtocolListHead;
 extern KSPIN_LOCK ProtocolListLock;
 
+
+NDIS_STATUS
+ProIndicatePacket(
+    PLOGICAL_ADAPTER Adapter,
+    PNDIS_PACKET Packet);
+
 #endif /* __PROTOCOL_H */
 
 /* EOF */
index b989ab8..fdaf4b2 100644 (file)
 #include <buffer.h>
 
 
+
+__inline ULONG SkipToOffset(
+    PNDIS_BUFFER Buffer,
+    UINT Offset,
+    PUCHAR *Data,
+    PUINT Size)
+/*
+ * FUNCTION: Skips Offset bytes into a buffer chain
+ * ARGUMENTS:
+ *     Buffer = Pointer to NDIS buffer
+ *     Offset = Number of bytes to skip
+ *     Data   = Address of a pointer that on return will contain the
+ *              address of the offset in the buffer
+ *     Size   = Address of a pointer that on return will contain the
+ *              size of the destination buffer
+ * RETURNS:
+ *     Offset into buffer, -1 if buffer chain was smaller than Offset bytes
+ * NOTES:
+ *     Buffer may be NULL
+ */
+{
+    for (;;) {
+
+        if (!Buffer)
+            return -1;
+
+        NdisQueryBuffer(Buffer, (PVOID)Data, Size);
+
+        if (Offset < *Size) {
+            ((ULONG_PTR)*Data) += Offset;
+            *Size              -= Offset;
+            break;
+        }
+
+        Offset -= *Size;
+
+        NdisGetNextBuffer(Buffer, &Buffer);
+    }
+
+    return Offset;
+}
+
+
+UINT CopyBufferToBufferChain(
+    PNDIS_BUFFER DstBuffer,
+    UINT DstOffset,
+    PUCHAR SrcData,
+    UINT Length)
+/*
+ * FUNCTION: Copies data from a buffer to an NDIS buffer chain
+ * ARGUMENTS:
+ *     DstBuffer = Pointer to destination NDIS buffer 
+ *     DstOffset = Destination start offset
+ *     SrcData   = Pointer to source buffer
+ *     Length    = Number of bytes to copy
+ * RETURNS:
+ *     Number of bytes copied to destination buffer
+ * NOTES:
+ *     The number of bytes copied may be limited by the destination
+ *     buffer size
+ */
+{
+    UINT BytesCopied, BytesToCopy, DstSize;
+    PUCHAR DstData;
+
+    NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X)  DstOffset (0x%X)  SrcData (0x%X)  Length (%d)\n", DstBuffer, DstOffset, SrcData, Length));
+
+    /* Skip DstOffset bytes in the destination buffer chain */
+    if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == -1)
+        return 0;
+
+    /* Start copying the data */
+    BytesCopied = 0;
+    for (;;) {
+        BytesToCopy = MIN(DstSize, Length);
+
+        RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
+        BytesCopied        += BytesToCopy;
+        (ULONG_PTR)SrcData += BytesToCopy;
+
+        Length -= BytesToCopy;
+        if (Length == 0)
+            break;
+
+        DstSize -= BytesToCopy;
+        if (DstSize == 0) {
+            /* No more bytes in desination buffer. Proceed to
+               the next buffer in the destination buffer chain */
+            NdisGetNextBuffer(DstBuffer, &DstBuffer);
+            if (!DstBuffer)
+                break;
+
+            NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
+        }
+    }
+
+    return BytesCopied;
+}
+
+
+UINT CopyBufferChainToBuffer(
+    PUCHAR DstData,
+    PNDIS_BUFFER SrcBuffer,
+    UINT SrcOffset,
+    UINT Length)
+/*
+ * FUNCTION: Copies data from an NDIS buffer chain to a buffer
+ * ARGUMENTS:
+ *     DstData   = Pointer to destination buffer
+ *     SrcBuffer = Pointer to source NDIS buffer
+ *     SrcOffset = Source start offset
+ *     Length    = Number of bytes to copy
+ * RETURNS:
+ *     Number of bytes copied to destination buffer
+ * NOTES:
+ *     The number of bytes copied may be limited by the source
+ *     buffer size
+ */
+{
+    UINT BytesCopied, BytesToCopy, SrcSize;
+    PUCHAR SrcData;
+
+    NDIS_DbgPrint(MAX_TRACE, ("DstData 0x%X  SrcBuffer 0x%X  SrcOffset 0x%X  Length %d\n",DstData,SrcBuffer, SrcOffset, Length));
+    
+    /* Skip SrcOffset bytes in the source buffer chain */
+    if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == -1)
+        return 0;
+
+    /* Start copying the data */
+    BytesCopied = 0;
+    for (;;) {
+        BytesToCopy = MIN(SrcSize, Length);
+
+        NDIS_DbgPrint(MAX_TRACE, ("Copying (%d) bytes from 0x%X to 0x%X\n", BytesToCopy, SrcData, DstData));
+
+        RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
+        BytesCopied        += BytesToCopy;
+        (ULONG_PTR)DstData += BytesToCopy;
+
+        Length -= BytesToCopy;
+        if (Length == 0)
+            break;
+
+        SrcSize -= BytesToCopy;
+        if (SrcSize == 0) {
+            /* No more bytes in source buffer. Proceed to
+               the next buffer in the source buffer chain */
+            NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
+            if (!SrcBuffer)
+                break;
+
+            NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
+        }
+    }
+
+    return BytesCopied;
+}
+
+
+UINT CopyPacketToBuffer(
+    PUCHAR DstData,
+    PNDIS_PACKET SrcPacket,
+    UINT SrcOffset,
+    UINT Length)
+/*
+ * FUNCTION: Copies data from an NDIS packet to a buffer
+ * ARGUMENTS:
+ *     DstData   = Pointer to destination buffer
+ *     SrcPacket = Pointer to source NDIS packet
+ *     SrcOffset = Source start offset
+ *     Length    = Number of bytes to copy
+ * RETURNS:
+ *     Number of bytes copied to destination buffer
+ * NOTES:
+ *     The number of bytes copied may be limited by the source
+ *     buffer size
+ */
+{
+    PNDIS_BUFFER FirstBuffer;
+    PVOID Address;
+    UINT FirstLength;
+    UINT TotalLength;
+
+    NDIS_DbgPrint(MAX_TRACE, ("DstData (0x%X)  SrcPacket (0x%X)  SrcOffset (0x%X)  Length (%d)\n", DstData, SrcPacket, SrcOffset, Length));
+
+    NdisGetFirstBufferFromPacket(SrcPacket,
+                                 &FirstBuffer,
+                                 &Address,
+                                 &FirstLength,
+                                 &TotalLength);
+
+    return CopyBufferChainToBuffer(DstData, FirstBuffer, SrcOffset, Length);
+}
+
+
+UINT CopyPacketToBufferChain(
+    PNDIS_BUFFER DstBuffer,
+    UINT DstOffset,
+    PNDIS_PACKET SrcPacket,
+    UINT SrcOffset,
+    UINT Length)
+/*
+ * FUNCTION: Copies data from an NDIS packet to an NDIS buffer chain
+ * ARGUMENTS:
+ *     DstBuffer = Pointer to destination NDIS buffer
+ *     DstOffset = Destination start offset
+ *     SrcPacket = Pointer to source NDIS packet
+ *     SrcOffset = Source start offset
+ *     Length    = Number of bytes to copy
+ * RETURNS:
+ *     Number of bytes copied to destination buffer
+ * NOTES:
+ *     The number of bytes copied may be limited by the source and
+ *     destination buffer sizes
+ */
+{
+    PNDIS_BUFFER SrcBuffer;
+    PUCHAR DstData, SrcData;
+    UINT DstSize, SrcSize;
+    UINT Count, Total;
+
+    NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X)  DstOffset (0x%X)  SrcPacket (0x%X)  SrcOffset (0x%X)  Length (%d)\n", DstBuffer, DstOffset, SrcPacket, SrcOffset, Length));
+
+    /* Skip DstOffset bytes in the destination buffer chain */
+    NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
+    if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == -1)
+        return 0;
+
+    /* Skip SrcOffset bytes in the source packet */
+    NdisGetFirstBufferFromPacket(SrcPacket, &SrcBuffer, (PVOID)&SrcData, &SrcSize, &Total);
+    if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == -1)
+        return 0;
+
+    /* Copy the data */
+    for (Total = 0;;) {
+        /* Find out how many bytes we can copy at one time */
+        if (Length < SrcSize)
+            Count = Length;
+        else
+            Count = SrcSize;
+        if (DstSize < Count)
+            Count = DstSize;
+
+        RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
+
+        Total  += Count;
+        Length -= Count;
+        if (Length == 0)
+            break;
+
+        DstSize -= Count;
+        if (DstSize == 0) {
+            /* No more bytes in destination buffer. Proceed to
+               the next buffer in the destination buffer chain */
+            NdisGetNextBuffer(DstBuffer, &DstBuffer);
+            if (!DstBuffer)
+                break;
+
+            NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
+        }
+
+        SrcSize -= Count;
+        if (SrcSize == 0) {
+            /* No more bytes in source buffer. Proceed to
+               the next buffer in the source buffer chain */
+            NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
+            if (!SrcBuffer)
+                break;
+
+            NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
+        }
+    }
+
+    return Total;
+}
+
+
+
 VOID
 EXPORT
 NdisAdjustBufferLength(
@@ -276,15 +554,17 @@ EXPORT
 NdisBufferLength(
     IN  PNDIS_BUFFER    Buffer)
 /*
- * FUNCTION:
+ * FUNCTION: Modifies the length of an NDIS buffer
  * ARGUMENTS:
+ *     Buffer = Pointer to NDIS buffer descriptor
+ *     Length = New size of buffer
  * NOTES:
  *    NDIS 5.0
+ * RETURNS:
+ *     Length of NDIS buffer
  */
 {
-    UNIMPLEMENTED
-
-    return 0;
+    return Buffer->ByteCount;
 }
 
 
@@ -329,52 +609,6 @@ NdisCopyBuffer(
 }
 
 
-__inline ULONG SkipToOffset(
-    PNDIS_BUFFER Buffer,
-    UINT Offset,
-    PVOID *Data,
-    PUINT Size)
-/*
- * FUNCTION: Skips Offset bytes into a buffer chain
- * ARGUMENTS:
- *     Buffer = Pointer to NDIS buffer
- *     Offset = Number of bytes to skip
- *     Data   = Address of a pointer that on return will contain the
- *              address of the offset in the buffer
- *     Size   = Address of a pointer that on return will contain the
- *              size of the destination buffer
- * RETURNS:
- *     Offset into buffer, -1 if buffer chain was smaller than Offset bytes
- * NOTES:
- *     Buffer may be NULL
- */
-{
-    ULONG Address = 0;
-
-    for (;;) {
-
-        if (!Buffer)
-            return -1;
-
-        NdisQueryBuffer(Buffer, Data, Size);
-
-        if (Offset < *Size) {
-            Address += Offset;
-            *Size   -= Offset;
-            break;
-        }
-
-        Offset -= *Size;
-
-        NdisGetNextBuffer(Buffer, &Buffer);
-    }
-
-    *Data = (PVOID)Address;
-
-    return Offset;
-}
-
-
 VOID
 EXPORT
 NdisCopyFromPacketToPacket(
@@ -397,19 +631,19 @@ NdisCopyFromPacketToPacket(
 {
     PNDIS_BUFFER SrcBuffer;
     PNDIS_BUFFER DstBuffer;
-    PVOID DstData, SrcData;
+    PUCHAR DstData, SrcData;
     UINT DstSize, SrcSize;
     UINT Count, Total;
 
     *BytesCopied = 0;
 
     /* Skip DestinationOffset bytes in the destination packet */
-    NdisGetFirstBufferFromPacket(Destination, &DstBuffer, &DstData, &DstSize, &Total);
+    NdisGetFirstBufferFromPacket(Destination, &DstBuffer, (PVOID)&DstData, &DstSize, &Total);
     if (SkipToOffset(DstBuffer, DestinationOffset, &DstData, &DstSize) == -1)
         return;
 
     /* Skip SourceOffset bytes in the source packet */
-    NdisGetFirstBufferFromPacket(Source, &SrcBuffer, &SrcData, &SrcSize, &Total);
+    NdisGetFirstBufferFromPacket(Source, &SrcBuffer, (PVOID)&SrcData, &SrcSize, &Total);
     if (SkipToOffset(SrcBuffer, SourceOffset, &SrcData, &SrcSize) == -1)
         return;
 
@@ -438,7 +672,7 @@ NdisCopyFromPacketToPacket(
             if (!DstBuffer)
                 break;
 
-            NdisQueryBuffer(DstBuffer, &DstData, &DstSize);
+            NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
         }
 
         SrcSize -= Count;
@@ -449,7 +683,7 @@ NdisCopyFromPacketToPacket(
             if (!SrcBuffer)
                 break;
 
-            NdisQueryBuffer(SrcBuffer, &SrcData, &SrcSize);
+            NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
         }
     }
 
@@ -616,8 +850,34 @@ NdisGetFirstBufferFromPacket(
     OUT PVOID           *_FirstBufferVA,
     OUT PUINT           _FirstBufferLength,
     OUT PUINT           _TotalBufferLength)
+/*
+ * FUNCTION: Retrieves information about an NDIS packet
+ * ARGUMENTS:
+ *     _Packet            = Pointer to NDIS packet
+ *     _FirstBuffer       = Address of buffer for pointer to first NDIS buffer
+ *     _FirstBufferVA     = Address of buffer for address of first NDIS buffer
+ *     _FirstBufferLength = Address of buffer for length of first buffer
+ *     _TotalBufferLength = Address of buffer for total length of packet
+ */
 {
-    UNIMPLEMENTED
+    PNDIS_BUFFER Buffer;
+
+    Buffer          = _Packet->Private.Head;
+    *_FirstBuffer   = Buffer;
+    *_FirstBufferVA = MmGetMdlVirtualAddress(Buffer);
+
+    if (Buffer != NULL) {
+        *_FirstBufferLength = MmGetMdlByteCount(Buffer);
+        Buffer = Buffer->Next;
+    } else
+        *_FirstBufferLength = 0;
+
+    *_TotalBufferLength = *_FirstBufferLength;
+
+    while (Buffer != NULL) {
+        *_TotalBufferLength += MmGetMdlByteCount(Buffer);
+        Buffer = Buffer->Next;
+    }
 }
 
 
@@ -683,7 +943,8 @@ NdisQueryBufferOffset(
     OUT PUINT           Offset,
     OUT PUINT           Length)
 {
-    UNIMPLEMENTED
+    *((PUINT)Offset) = MmGetMdlByteOffset(Buffer);
+    *((PUINT)Length) = MmGetMdlByteCount(Buffer);
 }
 
 
index dcdc154..b72279d 100644 (file)
@@ -25,10 +25,33 @@ VOID HandleDeferredProcessing(
  *     SystemArgument2 = Unused
  */
 {
+    BOOLEAN WasBusy;
     PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(DeferredContext);
 
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    KeAcquireSpinLockAtDpcLevel(&Adapter->Lock);
+    WasBusy = Adapter->MiniportBusy;
+    Adapter->MiniportBusy = TRUE;
+    KeReleaseSpinLockFromDpcLevel(&Adapter->Lock);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Before HandleInterruptHandler.\n"));
+
     /* Call the deferred interrupt service handler for this adapter */
-    (*Adapter->Miniport->Chars.HandleInterruptHandler)(Adapter);
+    (*Adapter->Miniport->Chars.HandleInterruptHandler)(
+        Adapter->MiniportAdapterContext);
+
+    NDIS_DbgPrint(MAX_TRACE, ("After HandleInterruptHandler.\n"));
+
+    KeAcquireSpinLockAtDpcLevel(&Adapter->Lock);
+    if ((!WasBusy) && (Adapter->WorkQueueHead)) {
+        KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);
+    } else {
+        Adapter->MiniportBusy = WasBusy;
+    }
+    KeReleaseSpinLockFromDpcLevel(&Adapter->Lock);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
 }
 
 
@@ -41,23 +64,27 @@ BOOLEAN ServiceRoutine(
  *     Interrupt      = Pointer to interrupt object
  *     ServiceContext = Pointer to context information (LOGICAL_ADAPTER)
  * RETURNS
- *     TRUE if our device generated the interrupt
+ *     TRUE if a miniport controlled device generated the interrupt
  */
 {
     BOOLEAN InterruptRecognized;
     BOOLEAN QueueMiniportHandleInterrupt;
     PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(ServiceContext);
 
-    /* FIXME: Support shared interrupts */
+    NDIS_DbgPrint(MAX_TRACE, ("Called. Adapter (0x%X)\n", Adapter));
 
     (*Adapter->Miniport->Chars.ISRHandler)(&InterruptRecognized,
-        &QueueMiniportHandleInterrupt, Adapter);
+                                           &QueueMiniportHandleInterrupt,
+                                           Adapter->MiniportAdapterContext);
 
     if (QueueMiniportHandleInterrupt) {
-        KeInsertQueueDpc(&Adapter->InterruptObject->InterruptDpc, NULL, NULL);
+        NDIS_DbgPrint(MAX_TRACE, ("Queueing DPC.\n"));
+        KeInsertQueueDpc(&Adapter->Interrupt->InterruptDpc, NULL, NULL);
     }
 
-    return TRUE;
+    NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
+
+    return InterruptRecognized;
 }
 
 
@@ -230,7 +257,9 @@ NdisMDeregisterIoPortRange(
  *     PortOffset            = Pointer to mapped base port address
  */
 {
-    UNIMPLEMENTED
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    /* Thank you */
 }
 
 
@@ -257,16 +286,6 @@ NdisMMapIoSpace(
 }
 
 
-VOID
-EXPORT
-NdisMQueryInformationComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_STATUS Status)
-{
-    UNIMPLEMENTED
-}
-
-
 ULONG
 EXPORT
 NdisMReadDmaCounter(
@@ -312,39 +331,70 @@ NdisMRegisterInterrupt(
  *     InterruptVector       = Specifies bus-relative vector to register
  *     InterruptLevel        = Specifies bus-relative DIRQL vector for interrupt
  *     RequestIsr            = TRUE if MiniportISR should always be called
- *     SharedInterrupt       = TRUE if other devices may use tha same interrupt
+ *     SharedInterrupt       = TRUE if other devices may use the same interrupt
  *     InterruptMode         = Specifies type of interrupt
  * RETURNS:
  *     Status of operation
  */
 {
-    NTSTATUS NtStatus;
+    NTSTATUS Status;
     ULONG MappedIRQ;
     KIRQL DIrql;
-    KAFFINITY Affinity = 0xFFFFFFFF;
-    PLOGICAL_ADAPTER Adapter  = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
+    KAFFINITY Affinity;
+    PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called. InterruptVector (0x%X)  InterruptLevel (0x%X)  "
+        "SharedInterrupt (%d)  InterruptMode (0x%X)\n",
+        InterruptVector, InterruptLevel, SharedInterrupt, InterruptMode));
 
     RtlZeroMemory(Interrupt, sizeof(NDIS_MINIPORT_INTERRUPT));
 
     KeInitializeSpinLock(&Interrupt->DpcCountLock);
 
-    KeInitializeDpc(&Interrupt->InterruptDpc, HandleDeferredProcessing, Adapter);
+    KeInitializeDpc(&Interrupt->InterruptDpc,
+                    HandleDeferredProcessing,
+                    Adapter);
 
     KeInitializeEvent(&Interrupt->DpcsCompletedEvent,
-        NotificationEvent, FALSE);
+                      NotificationEvent,
+                      FALSE);
 
     Interrupt->SharedInterrupt = SharedInterrupt;
 
-    Adapter->InterruptObject = Interrupt;
-
-    MappedIRQ = HalGetInterruptVector(Adapter->AdapterType, 0,
-        InterruptLevel, InterruptVector, &DIrql, &Affinity);
-
-    NtStatus = IoConnectInterrupt(&Interrupt->InterruptObject, ServiceRoutine, Adapter,
-        &Interrupt->DpcCountLock, MappedIRQ, DIrql, DIrql, InterruptMode,
-        SharedInterrupt, Affinity, FALSE);
+    Adapter->Interrupt = Interrupt;
+
+    MappedIRQ = HalGetInterruptVector(Internal, /* Adapter->AdapterType, */
+                                      0,
+                                      InterruptLevel,
+                                      InterruptVector,
+                                      &DIrql,
+                                      &Affinity);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Connecting to interrupt vector (0x%X)  Affinity (0x%X).\n", MappedIRQ, Affinity));
+
+    Status = IoConnectInterrupt(&Interrupt->InterruptObject,
+                                ServiceRoutine,
+                                Adapter,
+                                &Interrupt->DpcCountLock,
+                                MappedIRQ,
+                                DIrql,
+                                DIrql,
+                                InterruptMode,
+                                SharedInterrupt,
+                                Affinity,
+                                FALSE);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
+
+    if (NT_SUCCESS(Status))
+        return NDIS_STATUS_SUCCESS;
+
+    if (Status == STATUS_INSUFFICIENT_RESOURCES) {
+        /* FIXME: Log error */
+        return NDIS_STATUS_RESOURCE_CONFLICT;
+    }
 
-       return NDIS_STATUS_SUCCESS;
+    return NDIS_STATUS_FAILURE;
 }
 
 
@@ -367,22 +417,25 @@ NdisMRegisterIoPortRange(
  */
 {
 #if 0
-    NTSTATUS NtStatus;
+    NTSTATUS Status;
     BOOLEAN ConflictDetected;
     PLOGICAL_ADAPTER Adapter  = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
     PMINIPORT_DRIVER Miniport = Adapter->Miniport;
 
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
     /* Non-PnP hardware. NT5 function */
-    NtStatus = IoReportResourceForDetection(
-        Miniport->DriverObject,
-        NULL,
-        0,
-        NULL,
-        NULL,
-        0,
-        &ConflictDetected);
+    Status = IoReportResourceForDetection(Miniport->DriverObject,
+                                          NULL,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          0,
+                                          &ConflictDetected);
     return NDIS_STATUS_FAILURE;
 #else
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
     /* It's yours! */
     *PortOffset = (PVOID)InitialPort;
 
@@ -391,16 +444,6 @@ NdisMRegisterIoPortRange(
 }
 
 
-VOID
-EXPORT
-NdisMSetInformationComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_STATUS Status)
-{
-    UNIMPLEMENTED
-}
-
-
 VOID
 EXPORT
 NdisMSetupDmaTransfer(
@@ -415,18 +458,6 @@ NdisMSetupDmaTransfer(
 }
 
 
-VOID
-EXPORT
-NdisMTransferDataComplete(
-    IN  NDIS_HANDLE     MiniportAdapterHandle,
-    IN  PNDIS_PACKET    Packet,
-    IN  NDIS_STATUS     Status,
-    IN  UINT            BytesTransferred)
-{
-    UNIMPLEMENTED
-}
-
-
 VOID
 EXPORT
 NdisMUnmapIoSpace(
index 11bbf05..4188cf7 100644 (file)
@@ -8,10 +8,15 @@
  *   CSH 01/08-2000 Created
  */
 #include <ndissys.h>
+#include <protocol.h>
+#include <miniport.h>
+
 
 #ifdef DBG
+
 /* See debug.h for debug/trace constants */
 DWORD DebugTraceLevel = MIN_TRACE;
+
 #endif /* DBG */
 
 
@@ -45,6 +50,15 @@ DriverEntry(
 {
     NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 
+    InitializeListHead(&ProtocolListHead);
+    KeInitializeSpinLock(&ProtocolListLock);
+
+    InitializeListHead(&MiniportListHead);
+    KeInitializeSpinLock(&MiniportListLock);
+
+    InitializeListHead(&AdapterListHead);
+    KeInitializeSpinLock(&AdapterListLock);
+
 #ifdef _MSC_VER
     DriverObject->DriverUnload = MainUnload;
 #else
index 6def0ba..6df7d76 100644 (file)
@@ -8,9 +8,13 @@
  *   CSH 01/08-2000 Created
  */
 #include <miniport.h>
+#include <protocol.h>
+#ifdef DBG
+#include <buffer.h>
+#endif /* DBG */
 
 
-/* Number of medias we know */
+/* Number of media we know */
 #define MEDIA_ARRAY_SIZE    15
 
 static NDIS_MEDIUM MediaArray[MEDIA_ARRAY_SIZE] = {
@@ -38,18 +42,306 @@ LIST_ENTRY AdapterListHead;
 KSPIN_LOCK AdapterListLock;
 
 
-VOID MiniportWorker(
-    PVOID Context)
+#ifdef DBG
+VOID
+MiniDisplayPacket(
+    PNDIS_PACKET Packet)
+{
+    ULONG i, Length;
+    UCHAR Buffer[64];
+
+    Length = CopyPacketToBuffer(
+        (PUCHAR)&Buffer,
+        Packet,
+        0,
+        64);
+
+    NDIS_DbgPrint(DEBUG_PACKET, ("*** PACKET START ***"));
+
+    for (i = 0; i < Length; i++) {
+        if (i % 12 == 0)
+            DbgPrint("\n%04X ", i);
+        DbgPrint("%02X ", Buffer[i]);
+    }
+
+    NDIS_DbgPrint(DEBUG_PACKET, ("*** PACKET STOP ***\n"));
+}
+#endif /* DBG */
+
+
+VOID
+MiniIndicateData(
+    PLOGICAL_ADAPTER    Adapter,
+    NDIS_HANDLE         MacReceiveContext,
+    PVOID               HeaderBuffer,
+    UINT                HeaderBufferSize,
+    PVOID               LookaheadBuffer,
+    UINT                LookaheadBufferSize,
+    UINT                PacketSize)
+/*
+ * FUNCTION: Indicate received data to bound protocols
+ * ARGUMENTS:
+ *     Adapter             = Pointer to logical adapter
+ *     MacReceiveContext   = MAC receive context handle
+ *     HeaderBuffer        = Pointer to header buffer
+ *     HeaderBufferSize    = Size of header buffer
+ *     LookaheadBuffer     = Pointer to lookahead buffer
+ *     LookaheadBufferSize = Size of lookahead buffer
+ *     PacketSize          = Total size of received packet
+ */
+{
+    KIRQL OldIrql;
+    PLIST_ENTRY CurrentEntry;
+    PADAPTER_BINDING AdapterBinding;
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called. Adapter (0x%X)  HeaderBuffer (0x%X)  "
+        "HeaderBufferSize (0x%X)  LookaheadBuffer (0x%X)  LookaheadBufferSize (0x%X).\n",
+        Adapter, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize));
+
+#ifdef DBG
+    if (DebugTraceLevel | DEBUG_PACKET) {
+        ULONG i, Length;
+        PUCHAR p;
+
+        NDIS_DbgPrint(DEBUG_PACKET, ("*** RECEIVE PACKET START ***\n"));
+        NDIS_DbgPrint(DEBUG_PACKET, ("HEADER:"));
+        p = HeaderBuffer;
+        for (i = 0; i < HeaderBufferSize; i++) {
+            if (i % 12 == 0)
+                DbgPrint("\n%04X ", i);
+            DbgPrint("%02X ", *p);
+            (ULONG_PTR)p += 1;
+        }
+
+        NDIS_DbgPrint(DEBUG_PACKET, ("\nFRAME:"));
+
+        p = LookaheadBuffer;
+        Length = (LookaheadBufferSize < 64)? LookaheadBufferSize : 64;
+        for (i = 0; i < Length; i++) {
+            if (i % 12 == 0)
+                DbgPrint("\n%04X ", i);
+            DbgPrint("%02X ", *p);
+            (ULONG_PTR)p += 1;
+        }
+
+        NDIS_DbgPrint(DEBUG_PACKET, ("*** RECEIVE PACKET STOP ***\n"));
+    }
+#endif /* DBG */
+
+    KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+    CurrentEntry = Adapter->ProtocolListHead.Flink;
+    while (CurrentEntry != &Adapter->ProtocolListHead) {
+           AdapterBinding = CONTAINING_RECORD(CurrentEntry,
+                                           ADAPTER_BINDING,
+                                           AdapterListEntry);
+
+        KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+        (*AdapterBinding->ProtocolBinding->Chars.u4.ReceiveHandler)(
+            AdapterBinding->ProtocolBindingContext,
+            MacReceiveContext,
+            HeaderBuffer,
+            HeaderBufferSize,
+            LookaheadBuffer,
+            LookaheadBufferSize,
+            PacketSize);
+
+        KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+
+        CurrentEntry = CurrentEntry->Flink;
+    }
+    KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+}
+
+
+VOID
+MiniEthReceiveComplete(
+    IN  PETH_FILTER Filter)
+/*
+ * FUNCTION: Receive indication complete function for Ethernet devices
+ * ARGUMENTS:
+ *     Filter = Pointer to Ethernet filter
+ */
+{
+    KIRQL OldIrql;
+    PLIST_ENTRY CurrentEntry;
+    PLOGICAL_ADAPTER Adapter;
+    PADAPTER_BINDING AdapterBinding;
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
+
+    Adapter = (PLOGICAL_ADAPTER)Filter->Miniport;
+
+    KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+    CurrentEntry = Adapter->ProtocolListHead.Flink;
+    while (CurrentEntry != &Adapter->ProtocolListHead) {
+           AdapterBinding = CONTAINING_RECORD(CurrentEntry,
+                                           ADAPTER_BINDING,
+                                           AdapterListEntry);
+
+        KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+        (*AdapterBinding->ProtocolBinding->Chars.ReceiveCompleteHandler)(
+            AdapterBinding->ProtocolBindingContext);
+
+        KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+
+        CurrentEntry = CurrentEntry->Flink;
+    }
+    KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+}
+
+
+VOID
+MiniEthReceiveIndication(
+    IN  PETH_FILTER Filter,
+    IN  NDIS_HANDLE MacReceiveContext,
+    IN  PCHAR       Address,
+    IN  PVOID       HeaderBuffer,
+    IN  UINT        HeaderBufferSize,
+    IN  PVOID       LookaheadBuffer,
+    IN  UINT        LookaheadBufferSize,
+    IN  UINT        PacketSize)
+/*
+ * FUNCTION: Receive indication function for Ethernet devices
+ * ARGUMENTS:
+ *     Filter              = Pointer to Ethernet filter
+ *     MacReceiveContext   = MAC receive context handle
+ *     Address             = Pointer to destination Ethernet address
+ *     HeaderBuffer        = Pointer to Ethernet header buffer
+ *     HeaderBufferSize    = Size of Ethernet header buffer
+ *     LookaheadBuffer     = Pointer to lookahead buffer
+ *     LookaheadBufferSize = Size of lookahead buffer
+ *     PacketSize          = Total size of received packet
+ */
+{
+    MiniIndicateData((PLOGICAL_ADAPTER)Filter->Miniport,
+                     MacReceiveContext,
+                     HeaderBuffer,
+                     HeaderBufferSize,
+                     LookaheadBuffer,
+                     LookaheadBufferSize,
+                     PacketSize);
+}
+
+
+VOID
+MiniResetComplete(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status,
+    IN  BOOLEAN     AddressingReset)
+{
+    UNIMPLEMENTED
+}
+
+
+VOID
+MiniSendComplete(
+    IN  NDIS_HANDLE     MiniportAdapterHandle,
+    IN  PNDIS_PACKET    Packet,
+    IN  NDIS_STATUS     Status)
+/*
+ * FUNCTION: Forwards a message to the initiating protocol saying
+ *           that a packet was handled
+ * ARGUMENTS:
+ *     NdisAdapterHandle = Handle input to MiniportInitialize
+ *     Packet            = Pointer to NDIS packet that was sent
+ *     Status            = Status of send operation
+ */
+{
+    PADAPTER_BINDING AdapterBinding;
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
+
+    AdapterBinding = (PADAPTER_BINDING)Packet->Reserved[0];
+
+    (*AdapterBinding->ProtocolBinding->Chars.u2.SendCompleteHandler)(
+        AdapterBinding->ProtocolBindingContext,
+        Packet,
+        Status);
+}
+
+
+VOID
+MiniSendResourcesAvailable(
+    IN  NDIS_HANDLE MiniportAdapterHandle)
+{
+    UNIMPLEMENTED
+}
+
+
+VOID
+MiniTransferDataComplete(
+    IN  NDIS_HANDLE     MiniportAdapterHandle,
+    IN  PNDIS_PACKET    Packet,
+    IN  NDIS_STATUS     Status,
+    IN  UINT            BytesTransferred)
+{
+    PLOGICAL_ADAPTER Adapter        = (PLOGICAL_ADAPTER)MiniportAdapterHandle;
+    PADAPTER_BINDING AdapterBinding = Adapter->MiniportAdapterBinding;
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
+
+    (*AdapterBinding->ProtocolBinding->Chars.u3.TransferDataCompleteHandler)(
+        AdapterBinding->ProtocolBindingContext,
+        Packet,
+        Status,
+        BytesTransferred);
+}
+
+
+BOOLEAN
+MiniAdapterHasAddress(
+    PLOGICAL_ADAPTER Adapter,
+    PNDIS_PACKET Packet)
 /*
- * FUNCTION: Worker function for MiniportXxx functions
+ * FUNCTION: Determines wether a packet has the same destination address as an adapter
  * ARGUMENTS:
- *     Context = Pointer to context information (MINIPORT_DRIVER)
+ *     Adapter = Pointer to logical adapter object
+ *     Packet  = Pointer to NDIS packet
+ * RETURNS:
+ *     TRUE if the destination address is that of the adapter, FALSE if not
  */
 {
+    UINT Length;
+    PUCHAR Start1;
+    PUCHAR Start2;
+    PNDIS_BUFFER NdisBuffer;
+    UINT BufferLength;
+
+    Start1 = (PUCHAR)&Adapter->Address;
+    NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, NULL);
+    if (!NdisBuffer) {
+        NDIS_DbgPrint(MID_TRACE, ("Packet contains no buffers.\n"));
+        return FALSE;
+    }
+
+    NdisQueryBuffer(NdisBuffer, (PVOID)&Start2, &BufferLength);
+
+    /* FIXME: Should handle fragmented packets */
+
+    switch (Adapter->MediaType) {
+    case NdisMedium802_3:
+        Length = ETH_LENGTH_OF_ADDRESS;
+        /* Destination address is the first field */
+        break;
+
+    default:
+        NDIS_DbgPrint(MIN_TRACE, ("Adapter has unsupported media type (0x%X).\n", Adapter->MediaType));
+        return FALSE;
+    }
+
+    if (BufferLength < Length) {
+        NDIS_DbgPrint(MID_TRACE, ("Buffer is too small.\n"));
+        return FALSE;
+    }
+
+    return (RtlCompareMemory((PVOID)Start1, (PVOID)Start2, Length) == Length);
 }
 
 
-PLOGICAL_ADAPTER MiniLocateDevice(
+PLOGICAL_ADAPTER
+MiniLocateDevice(
     PNDIS_STRING AdapterName)
 /*
  * FUNCTION: Returns the logical adapter object for a specific adapter
@@ -61,39 +353,31 @@ PLOGICAL_ADAPTER MiniLocateDevice(
  *     is responsible for dereferencing after use
  */
 {
-    KIRQL OldIrql1;
-    KIRQL OldIrql2;
-    PLIST_ENTRY CurrentMEntry;
-    PLIST_ENTRY CurrentAEntry;
-    PMINIPORT_DRIVER Miniport;
+    KIRQL OldIrql;
+    PLIST_ENTRY CurrentEntry;
     PLOGICAL_ADAPTER Adapter;
 
-    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called. AdapterName (0x%X).\n", AdapterName));
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
 
-    KeAcquireSpinLock(&MiniportListLock, &OldIrql1);
-    CurrentMEntry = MiniportListHead.Flink;
-    while (CurrentMEntry != &MiniportListHead) {
-           Miniport = CONTAINING_RECORD(CurrentMEntry, MINIPORT_DRIVER, ListEntry);
+    KeAcquireSpinLock(&AdapterListLock, &OldIrql);
+    CurrentEntry = AdapterListHead.Flink;
+    while (CurrentEntry != &AdapterListHead) {
+           Adapter = CONTAINING_RECORD(CurrentEntry, LOGICAL_ADAPTER, ListEntry);
 
-        KeAcquireSpinLock(&AdapterListLock, &OldIrql2);
-        CurrentAEntry = AdapterListHead.Flink;
-        while (CurrentAEntry != &AdapterListHead) {
-               Adapter = CONTAINING_RECORD(CurrentAEntry, LOGICAL_ADAPTER, ListEntry);
+        if (RtlCompareUnicodeString(AdapterName, &Adapter->DeviceName, TRUE) == 0) {
+            ReferenceObject(Adapter);
+            KeReleaseSpinLock(&AdapterListLock, OldIrql);
 
-            if (RtlCompareUnicodeString(AdapterName, &Adapter->DeviceName, TRUE) == 0) {
-                ReferenceObject(Adapter);
-                KeReleaseSpinLock(&AdapterListLock, OldIrql2);
-                KeReleaseSpinLock(&MiniportListLock, OldIrql1);
-                return Adapter;
-            }
+            NDIS_DbgPrint(DEBUG_MINIPORT, ("Leaving. Adapter found at (0x%X).\n", Adapter));
 
-            CurrentAEntry = CurrentAEntry->Flink;
+            return Adapter;
         }
-        KeReleaseSpinLock(&AdapterListLock, OldIrql2);
 
-        CurrentMEntry = CurrentMEntry->Flink;
+        CurrentEntry = CurrentEntry->Flink;
     }
-    KeReleaseSpinLock(&MiniportListLock, OldIrql1);
+    KeReleaseSpinLock(&AdapterListLock, OldIrql);
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Leaving (adapter not found).\n"));
 
     return NULL;
 }
@@ -109,36 +393,39 @@ MiniQueryInformation(
  * FUNCTION: Queries a logical adapter for properties
  * ARGUMENTS:
  *     Adapter      = Pointer to the logical adapter object to query
- *     Oid          = Specifies the oid to query for
+ *     Oid          = Specifies the Object ID to query for
  *     Size         = If non-zero overrides the length in the adapter object
  *     BytesWritten = Address of buffer to place number of bytes written
- * RETURNS:
- *     Status of operation
  * NOTES:
  *     If the specified buffer is too small, a new buffer is allocated,
  *     and the query is attempted again
+ * RETURNS:
+ *     Status of operation
  */
 {
     NDIS_STATUS NdisStatus;
     ULONG BytesNeeded;
 
     if (Adapter->QueryBufferLength == 0) {
-        Adapter->QueryBuffer = ExAllocatePool(NonPagedPool, 32);
+        Adapter->QueryBuffer = ExAllocatePool(NonPagedPool, (Size == 0)? 32 : Size);
 
         if (!Adapter->QueryBuffer) {
             NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
             return NDIS_STATUS_RESOURCES;
         }
 
-        Adapter->QueryBufferLength = 32;
+        Adapter->QueryBufferLength = (Size == 0)? 32 : Size;
     }
 
-    BytesNeeded = (Size = 0)? Adapter->QueryBufferLength : Size;
+    BytesNeeded = (Size == 0)? Adapter->QueryBufferLength : Size;
 
     NdisStatus = (*Adapter->Miniport->Chars.QueryInformationHandler)(
-        Adapter, Oid, &BytesNeeded,
-        Adapter->QueryBufferLength,
-        BytesWritten, &BytesNeeded);
+        Adapter->MiniportAdapterContext,
+        Oid,
+        Adapter->QueryBuffer,
+        BytesNeeded,
+        BytesWritten,
+        &BytesNeeded);
 
     if ((NT_SUCCESS(NdisStatus)) || (NdisStatus == NDIS_STATUS_PENDING)) {
         NDIS_DbgPrint(DEBUG_MINIPORT, ("Miniport returned status (0x%X).\n", NdisStatus));
@@ -149,8 +436,8 @@ MiniQueryInformation(
         ExFreePool(Adapter->QueryBuffer);
 
         Adapter->QueryBufferLength += BytesNeeded;
-        Adapter->QueryBuffer = ExAllocatePool(
-            NonPagedPool, Adapter->QueryBufferLength);
+        Adapter->QueryBuffer = ExAllocatePool(NonPagedPool,
+                                              Adapter->QueryBufferLength);
 
         if (!Adapter->QueryBuffer) {
             NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
@@ -158,13 +445,264 @@ MiniQueryInformation(
         }
 
         NdisStatus = (*Adapter->Miniport->Chars.QueryInformationHandler)(
-            Adapter, Oid, Adapter->QueryBuffer, Size, BytesWritten, &BytesNeeded);
+            Adapter->MiniportAdapterContext,
+            Oid,
+            Adapter->QueryBuffer,
+            Size,
+            BytesWritten,
+            &BytesNeeded);
     }
 
     return NdisStatus;
 }
 
 
+NDIS_STATUS
+FASTCALL
+MiniQueueWorkItem(
+    PLOGICAL_ADAPTER    Adapter,
+    NDIS_WORK_ITEM_TYPE WorkItemType,
+    PVOID               WorkItemContext,
+    NDIS_HANDLE         Initiator)
+/*
+ * FUNCTION: Queues a work item for execution at a later time
+ * ARGUMENTS:
+ *     Adapter         = Pointer to the logical adapter object to queue work item on
+ *     WorkItemType    = Type of work item to queue
+ *     WorkItemContext = Pointer to context information for work item
+ *     Initiator       = Pointer to ADAPTER_BINDING structure of initiating protocol
+ * NOTES:
+ *     Adapter lock must be held when called
+ * RETURNS:
+ *     Status of operation
+ */
+{
+    PNDIS_MINIPORT_WORK_ITEM Item;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    if (Adapter->WorkQueueLevel < NDIS_MINIPORT_WORK_QUEUE_SIZE - 1) {
+        Item = &Adapter->WorkQueue[Adapter->WorkQueueLevel];
+        Adapter->WorkQueueLevel++;
+    } else {
+        Item = ExAllocatePool(NonPagedPool, sizeof(NDIS_MINIPORT_WORK_ITEM));
+        if (Item) {
+            /* Set flag so we know that the buffer should be freed
+               when work item is dequeued */
+            Item->Allocated = TRUE;
+        } else {
+            NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+            return NDIS_STATUS_RESOURCES;
+        }
+    }
+
+    Item->WorkItemType    = WorkItemType;
+    Item->WorkItemContext = WorkItemContext;
+    Item->Initiator       = Initiator;
+
+    Item->Link.Next = NULL;
+    if (!Adapter->WorkQueueHead) {
+        Adapter->WorkQueueHead = Item;
+    } else {
+        Adapter->WorkQueueTail->Link.Next = (PSINGLE_LIST_ENTRY)Item;
+    }
+
+    KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);
+
+    return NDIS_STATUS_SUCCESS;
+}
+
+
+NDIS_STATUS
+FASTCALL
+MiniDequeueWorkItem(
+    PLOGICAL_ADAPTER    Adapter,
+    NDIS_WORK_ITEM_TYPE *WorkItemType,
+    PVOID               *WorkItemContext,
+    NDIS_HANDLE         *Initiator)
+/*
+ * FUNCTION: Dequeues a work item from the work queue of a logical adapter
+ * ARGUMENTS:
+ *     Adapter         = Pointer to the logical adapter object to dequeue work item from
+ *     WorkItemType    = Address of buffer for work item type
+ *     WorkItemContext = Address of buffer for pointer to context information
+ *     Initiator       = Address of buffer for initiator of the work (ADAPTER_BINDING)
+ * NOTES:
+ *     Adapter lock must be held when called
+ * RETURNS:
+ *     Status of operation
+ */
+{
+    PNDIS_MINIPORT_WORK_ITEM Item;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    Item = Adapter->WorkQueueHead;
+    if (Item) {
+        Adapter->WorkQueueHead = (PNDIS_MINIPORT_WORK_ITEM)Item->Link.Next;
+        if (Item == Adapter->WorkQueueTail)
+            Adapter->WorkQueueTail = NULL;
+
+        *WorkItemType    = Item->WorkItemType;
+        *WorkItemContext = Item->WorkItemContext;
+        *Initiator       = Item->Initiator;
+
+        if (Item->Allocated) {
+            ExFreePool(Item);
+        } else {
+            Adapter->WorkQueueLevel--;
+#ifdef DBG
+            if (Adapter->WorkQueueLevel < 0) {
+                NDIS_DbgPrint(MIN_TRACE, ("Adapter->WorkQueueLevel is < 0 (should be >= 0).\n"));
+            }
+#endif
+        }
+
+        return NDIS_STATUS_SUCCESS;
+    }
+
+    return NDIS_STATUS_FAILURE;
+}
+
+
+NDIS_STATUS
+MiniDoRequest(
+    PLOGICAL_ADAPTER Adapter,
+    PNDIS_REQUEST NdisRequest)
+/*
+ * FUNCTION: Sends a request to a miniport
+ * ARGUMENTS:
+ *     Adapter     = Pointer to logical adapter object
+ *     NdisRequest = Pointer to NDIS request structure describing request
+ * RETURNS:
+ *     Status of operation
+ */
+{
+    Adapter->MediaRequest = NdisRequest;
+
+    switch (NdisRequest->RequestType) {
+    case NdisRequestQueryInformation:
+        return (*Adapter->Miniport->Chars.QueryInformationHandler)(
+            Adapter->MiniportAdapterContext,
+            NdisRequest->DATA.QUERY_INFORMATION.Oid,
+            NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer,
+            NdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength,
+            (PULONG)&NdisRequest->DATA.QUERY_INFORMATION.BytesWritten,
+            (PULONG)&NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded);
+        break;
+
+    case NdisRequestSetInformation:
+        return (*Adapter->Miniport->Chars.SetInformationHandler)(
+            Adapter->MiniportAdapterContext,
+            NdisRequest->DATA.SET_INFORMATION.Oid,
+            NdisRequest->DATA.SET_INFORMATION.InformationBuffer,
+            NdisRequest->DATA.SET_INFORMATION.InformationBufferLength,
+            (PULONG)&NdisRequest->DATA.SET_INFORMATION.BytesRead,
+            (PULONG)&NdisRequest->DATA.SET_INFORMATION.BytesNeeded);
+        break;
+
+    default:
+        return NDIS_STATUS_FAILURE;
+    }
+}
+
+
+VOID MiniportDpc(
+    IN PKDPC Dpc,
+    IN PVOID DeferredContext,
+    IN PVOID SystemArgument1,
+    IN PVOID SystemArgument2)
+/*
+ * FUNCTION: Deferred routine to handle serialization
+ * ARGUMENTS:
+ *     Dpc             = Pointer to DPC object
+ *     DeferredContext = Pointer to context information (LOGICAL_ADAPTER)
+ *     SystemArgument1 = Unused
+ *     SystemArgument2 = Unused
+ */
+{
+    NDIS_STATUS NdisStatus;
+    PVOID WorkItemContext;
+    NDIS_WORK_ITEM_TYPE WorkItemType;
+    PADAPTER_BINDING AdapterBinding;
+    PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(DeferredContext);
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
+
+    NdisStatus = MiniDequeueWorkItem(Adapter,
+                                     &WorkItemType,
+                                     &WorkItemContext,
+                                     (PNDIS_HANDLE)&AdapterBinding);
+    if (NdisStatus == NDIS_STATUS_SUCCESS) {
+        Adapter->MiniportAdapterBinding = AdapterBinding;
+        switch (WorkItemType) {
+        case NdisWorkItemSend:
+#ifdef DBG
+            MiniDisplayPacket((PNDIS_PACKET)WorkItemContext);
+#endif
+            NdisStatus = (*Adapter->Miniport->Chars.u1.SendHandler)(
+                Adapter->MiniportAdapterContext,
+                (PNDIS_PACKET)WorkItemContext,
+                0);
+            if (NdisStatus != NDIS_STATUS_PENDING) {
+                MiniSendComplete((NDIS_HANDLE)Adapter,
+                                 (PNDIS_PACKET)WorkItemContext,
+                                 NdisStatus);
+            }
+            break;
+
+        case NdisWorkItemSendLoopback:
+            NdisStatus = ProIndicatePacket(Adapter,
+                                           (PNDIS_PACKET)WorkItemContext);
+            MiniSendComplete((NDIS_HANDLE)Adapter,
+                             (PNDIS_PACKET)WorkItemContext,
+                             NdisStatus);
+            break;
+
+        case NdisWorkItemReturnPackets:
+            break;
+
+        case NdisWorkItemResetRequested:
+            break;
+
+        case NdisWorkItemResetInProgress:
+            break;
+
+        case NdisWorkItemHalt:
+            break;
+
+        case NdisWorkItemMiniportCallback:
+            break;
+
+        case NdisWorkItemRequest:
+            NdisStatus = MiniDoRequest(Adapter, (PNDIS_REQUEST)WorkItemContext);
+
+            if (NdisStatus == NDIS_STATUS_PENDING)
+                break;
+
+            switch (((PNDIS_REQUEST)WorkItemContext)->RequestType) {
+            case NdisRequestQueryInformation:
+                NdisMQueryInformationComplete((NDIS_HANDLE)Adapter, NdisStatus);
+                break;
+
+            case NdisRequestSetInformation:
+                NdisMSetInformationComplete((NDIS_HANDLE)Adapter, NdisStatus);
+                break;
+
+            default:
+                NDIS_DbgPrint(MIN_TRACE, ("Unknown NDIS request type.\n"));
+                break;
+            }
+            break;
+
+        default:
+            NDIS_DbgPrint(MIN_TRACE, ("Unknown NDIS work item type (%d).\n", WorkItemType));
+            break;
+        }
+    }
+}
+
+
 VOID
 EXPORT
 NdisMCloseLog(
@@ -244,6 +782,8 @@ NdisInitializeWrapper(
 {
     PMINIPORT_DRIVER Miniport;
 
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
     Miniport = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_DRIVER));
     if (!Miniport) {
         NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
@@ -257,11 +797,9 @@ NdisInitializeWrapper(
 
     Miniport->RefCount = 1;
 
-    ExInitializeWorkItem(&Miniport->WorkItem, MiniportWorker, Miniport);
-
     Miniport->DriverObject = (PDRIVER_OBJECT)SystemSpecific1;
-    /* FIXME: Copy RegistryPath */
-    //Miniport->RegistryPath = SystemSpecific2;
+
+    InitializeListHead(&Miniport->AdapterListHead);
 
     /* Put miniport in global miniport list */
     ExInterlockedInsertTailList(&MiniportListHead,
@@ -272,6 +810,24 @@ NdisInitializeWrapper(
 }
 
 
+VOID
+EXPORT
+NdisMQueryInformationComplete(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status)
+{
+    PLOGICAL_ADAPTER Adapter        = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
+    PADAPTER_BINDING AdapterBinding = (PADAPTER_BINDING)Adapter->MiniportAdapterBinding;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    (*AdapterBinding->ProtocolBinding->Chars.RequestCompleteHandler)(
+        AdapterBinding->ProtocolBindingContext,
+        Adapter->MediaRequest,
+        Status);
+}
+
+
 VOID
 EXPORT
 NdisMRegisterAdapterShutdownHandler(
@@ -283,6 +839,102 @@ NdisMRegisterAdapterShutdownHandler(
 }
 
 
+NDIS_STATUS
+DoQueries(
+    PLOGICAL_ADAPTER Adapter,
+    NDIS_OID AddressOID)
+/*
+ * FUNCTION: Queries miniport for information
+ * ARGUMENTS:
+ *     Adapter    = Pointer to logical adapter
+ *     AddressOID = OID to use to query for current address
+ * RETURNS:
+ *     Status of operation
+ */
+{
+    ULONG BytesWritten;
+    NDIS_STATUS NdisStatus;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    /* Get MAC options for adapter */
+    NdisStatus = MiniQueryInformation(Adapter,
+                                      OID_GEN_MAC_OPTIONS,
+                                      0,
+                                      &BytesWritten);
+    if (NdisStatus != NDIS_STATUS_SUCCESS) {
+        NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_MAC_OPTIONS failed. NdisStatus (0x%X).\n", NdisStatus));
+        return NdisStatus;
+    }
+
+    RtlCopyMemory(&Adapter->MacOptions, Adapter->QueryBuffer, sizeof(UINT));
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("MacOptions (0x%X).\n", Adapter->MacOptions));
+
+    /* Get current hardware address of adapter */
+    NdisStatus = MiniQueryInformation(Adapter,
+                                      AddressOID,
+                                      0,
+                                      &BytesWritten);
+    if (NdisStatus != NDIS_STATUS_SUCCESS) {
+        NDIS_DbgPrint(MIN_TRACE, ("Address OID (0x%X) failed. NdisStatus (0x%X).\n",
+            AddressOID, NdisStatus));
+        return NdisStatus;
+    }
+
+    RtlCopyMemory(&Adapter->Address, Adapter->QueryBuffer, Adapter->AddressLength);
+#ifdef DBG
+    {
+        /* 802.3 only */
+
+        PUCHAR A = (PUCHAR)&Adapter->Address.Type.Medium802_3;
+
+        NDIS_DbgPrint(MAX_TRACE, ("Adapter address is (%02X %02X %02X %02X %02X %02X).\n",
+            A[0], A[1], A[2], A[3], A[4], A[5]));
+    }
+#endif /* DBG */
+
+    /* Get maximum lookahead buffer size of adapter */
+    NdisStatus = MiniQueryInformation(Adapter,
+                                      OID_GEN_MAXIMUM_LOOKAHEAD,
+                                      0,
+                                      &BytesWritten);
+    if (NdisStatus != NDIS_STATUS_SUCCESS) {
+        NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_MAXIMUM_LOOKAHEAD failed. NdisStatus (0x%X).\n", NdisStatus));
+        return NdisStatus;
+    }
+
+    Adapter->MaxLookaheadLength = *((PULONG)Adapter->QueryBuffer);
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("MaxLookaheadLength (0x%X).\n", Adapter->MaxLookaheadLength));
+
+    /* Get current lookahead buffer size of adapter */
+    NdisStatus = MiniQueryInformation(Adapter,
+                                      OID_GEN_CURRENT_LOOKAHEAD,
+                                      0,
+                                      &BytesWritten);
+    if (NdisStatus != NDIS_STATUS_SUCCESS) {
+        NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_CURRENT_LOOKAHEAD failed. NdisStatus (0x%X).\n", NdisStatus));
+        return NdisStatus;
+    }
+
+    Adapter->CurLookaheadLength = *((PULONG)Adapter->QueryBuffer);
+
+    NDIS_DbgPrint(DEBUG_MINIPORT, ("CurLookaheadLength (0x%X).\n", Adapter->CurLookaheadLength));
+
+    if (Adapter->MaxLookaheadLength != 0) {
+        Adapter->LookaheadLength = Adapter->MaxLookaheadLength +
+                                   Adapter->MediumHeaderSize;
+        Adapter->LookaheadBuffer = ExAllocatePool(NonPagedPool,
+                                                  Adapter->LookaheadLength);
+        if (!Adapter->LookaheadBuffer)
+            return NDIS_STATUS_RESOURCES;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+
 NDIS_STATUS
 EXPORT
 NdisMRegisterMiniport(
@@ -300,12 +952,18 @@ NdisMRegisterMiniport(
  */
 {
     UINT MinSize;
+    KIRQL OldIrql;
     NTSTATUS Status;
     NDIS_STATUS NdisStatus;
+    NDIS_STATUS OpenErrorStatus;
     UINT SelectedMediumIndex;
     PLOGICAL_ADAPTER Adapter;
+    NDIS_OID AddressOID;
+    BOOLEAN MemError          = FALSE;
     PMINIPORT_DRIVER Miniport = GET_MINIPORT_DRIVER(NdisWrapperHandle);
 
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
     switch (MiniportCharacteristics->MajorNdisVersion) {
     case 0x03:
         MinSize = sizeof(NDIS30_MINIPORT_CHARACTERISTICS_S);
@@ -361,22 +1019,48 @@ NdisMRegisterMiniport(
         return NDIS_STATUS_RESOURCES;
     }
 
+    /* This is very important */
     RtlZeroMemory(Adapter, sizeof(LOGICAL_ADAPTER));
-    KeInitializeSpinLock(&Adapter->Lock);
-    Adapter->RefCount = 1;
-    Adapter->Miniport = Miniport;
 
     /* Create the device object for this adapter */
     /* FIXME: Use GUIDs */
     RtlInitUnicodeString(&Adapter->DeviceName, L"\\Device\\ne2000");
-    Status = IoCreateDevice(Miniport->DriverObject, 0, &Adapter->DeviceName,
-        FILE_DEVICE_PHYSICAL_NETCARD, 0, FALSE, &Adapter->DeviceObject);
+    Status = IoCreateDevice(Miniport->DriverObject,
+                            0,
+                            &Adapter->DeviceName,
+                            FILE_DEVICE_PHYSICAL_NETCARD,
+                            0,
+                            FALSE,
+                            &Adapter->DeviceObject);
     if (!NT_SUCCESS(Status)) {
         NDIS_DbgPrint(MIN_TRACE, ("Could not create device object.\n"));
         ExFreePool(Adapter);
         return NDIS_STATUS_FAILURE;
     }
 
+    /* Initialize adapter object */
+
+    KeInitializeSpinLock(&Adapter->Lock);
+
+    InitializeListHead(&Adapter->ProtocolListHead);
+
+    Adapter->RefCount = 1;
+
+    Adapter->Miniport = Miniport;
+
+    /* Set handlers (some NDIS macros require these) */
+
+    Adapter->EthRxCompleteHandler = MiniEthReceiveComplete;
+    Adapter->EthRxIndicateHandler = MiniEthReceiveIndication;
+
+    Adapter->SendCompleteHandler  = MiniSendComplete;
+    Adapter->SendResourcesHandler = MiniSendResourcesAvailable;
+    Adapter->ResetCompleteHandler = MiniResetComplete;
+    Adapter->TDCompleteHandler    = MiniTransferDataComplete;
+
+
+    KeInitializeDpc(&Adapter->MiniportDpc, MiniportDpc, (PVOID)Adapter);
+
     /* Put adapter in adapter list for this miniport */
     ExInterlockedInsertTailList(&Miniport->AdapterListHead,
                                 &Adapter->MiniportListEntry,
@@ -388,14 +1072,65 @@ NdisMRegisterMiniport(
                                 &AdapterListLock);
 
     /* Call MiniportInitialize */
-    (*Miniport->Chars.InitializeHandler)(
-        &NdisStatus,
+    NdisStatus = (*Miniport->Chars.InitializeHandler)(
+        &OpenErrorStatus,
         &SelectedMediumIndex,
         &MediaArray[0],
         MEDIA_ARRAY_SIZE,
         Adapter,
         NULL /* FIXME: WrapperConfigurationContext */);
 
+    if ((NdisStatus == NDIS_STATUS_SUCCESS) &&
+        (SelectedMediumIndex < MEDIA_ARRAY_SIZE)) {
+        
+        Adapter->MediaType = MediaArray[SelectedMediumIndex];
+
+        switch (Adapter->MediaType) {
+        case NdisMedium802_3:
+            Adapter->MediumHeaderSize = 14;
+            AddressOID = OID_802_3_CURRENT_ADDRESS;
+            Adapter->AddressLength = ETH_LENGTH_OF_ADDRESS;
+
+            Adapter->FilterDbs.u.EthDB = ExAllocatePool(NonPagedPool,
+                                                        sizeof(ETH_FILTER));
+            if (Adapter->FilterDbs.u.EthDB) {
+                RtlZeroMemory(Adapter->FilterDbs.u.EthDB, sizeof(ETH_FILTER));
+                Adapter->FilterDbs.u.EthDB->Miniport = (PNDIS_MINIPORT_BLOCK)Adapter;
+            } else
+                MemError = TRUE;
+            break;
+
+        default:
+            /* FIXME: Support other types of medias */
+            ASSERT(FALSE);
+            return NDIS_STATUS_FAILURE;
+        }
+
+        NdisStatus = DoQueries(Adapter, AddressOID);
+    }
+
+    if ((MemError) ||
+        (NdisStatus != NDIS_STATUS_SUCCESS) ||
+        (SelectedMediumIndex >= MEDIA_ARRAY_SIZE)) {
+
+        /* Remove adapter from adapter list for this miniport */
+        KeAcquireSpinLock(&Miniport->Lock, &OldIrql);
+        RemoveEntryList(&Adapter->MiniportListEntry);
+        KeReleaseSpinLock(&Miniport->Lock, OldIrql);
+
+        /* Remove adapter from global adapter list */
+        KeAcquireSpinLock(&AdapterListLock, &OldIrql);
+        RemoveEntryList(&Adapter->ListEntry);
+        KeReleaseSpinLock(&AdapterListLock, OldIrql);
+
+        if (Adapter->LookaheadBuffer)
+            ExFreePool(Adapter->LookaheadBuffer);
+
+        IoDeleteDevice(Adapter->DeviceObject);
+        ExFreePool(Adapter);
+        return NDIS_STATUS_FAILURE;
+    }
+
     return NDIS_STATUS_SUCCESS;
 }
 
@@ -403,11 +1138,13 @@ NdisMRegisterMiniport(
 VOID
 EXPORT
 NdisMResetComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_STATUS Status,
-    IN  BOOLEAN     AddressingReset)
+    IN NDIS_HANDLE MiniportAdapterHandle,
+    IN NDIS_STATUS Status,
+    IN BOOLEAN     AddressingReset)
 {
-    UNIMPLEMENTED
+    MiniResetComplete(MiniportAdapterHandle,
+                      Status,
+                      AddressingReset);
 }
 
 
@@ -417,8 +1154,18 @@ NdisMSendComplete(
     IN  NDIS_HANDLE     MiniportAdapterHandle,
     IN  PNDIS_PACKET    Packet,
     IN  NDIS_STATUS     Status)
+/*
+ * FUNCTION: Forwards a message to the initiating protocol saying
+ *           that a packet was handled
+ * ARGUMENTS:
+ *     NdisAdapterHandle = Handle input to MiniportInitialize
+ *     Packet            = Pointer to NDIS packet that was sent
+ *     Status            = Status of send operation
+ */
 {
-    UNIMPLEMENTED
+    MiniSendComplete(MiniportAdapterHandle,
+                     Packet,
+                     Status);
 }
 
 
@@ -427,7 +1174,40 @@ EXPORT
 NdisMSendResourcesAvailable(
     IN  NDIS_HANDLE MiniportAdapterHandle)
 {
-    UNIMPLEMENTED
+    MiniSendResourcesAvailable(MiniportAdapterHandle);
+}
+
+
+VOID
+EXPORT
+NdisMTransferDataComplete(
+    IN  NDIS_HANDLE     MiniportAdapterHandle,
+    IN  PNDIS_PACKET    Packet,
+    IN  NDIS_STATUS     Status,
+    IN  UINT            BytesTransferred)
+{
+    MiniTransferDataComplete(MiniportAdapterHandle,
+                             Packet,
+                             Status,
+                             BytesTransferred);
+}
+
+
+VOID
+EXPORT
+NdisMSetInformationComplete(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status)
+{
+    PLOGICAL_ADAPTER Adapter        = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
+    PADAPTER_BINDING AdapterBinding = (PADAPTER_BINDING)Adapter->MiniportAdapterBinding;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    (*AdapterBinding->ProtocolBinding->Chars.RequestCompleteHandler)(
+        AdapterBinding->ProtocolBindingContext,
+        Adapter->MediaRequest,
+        Status);
 }
 
 
@@ -449,7 +1229,9 @@ NdisMSetAttributes(
 {
     PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
 
-    Adapter->MiniportAdapterContext = MiniportAdapterHandle;
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    Adapter->MiniportAdapterContext = MiniportAdapterContext;
     Adapter->Attributes    = BusMaster? NDIS_ATTRIBUTE_BUS_MASTER : 0;
     Adapter->AdapterType   = AdapterType;
     Adapter->AttributesSet = TRUE;
@@ -520,13 +1302,17 @@ NdisTerminateWrapper(
     IN  NDIS_HANDLE NdisWrapperHandle,
     IN  PVOID       SystemSpecific)
 /*
- * FUNCTION: Releases resources allocated by a call to NdisMInitializeWrapper
+ * FUNCTION: Releases resources allocated by a call to NdisInitializeWrapper
  * ARGUMENTS:
- *     NdisWrapperHandle = Handle returned by NdisMInitializeWrapper
+ *     NdisWrapperHandle = Handle returned by NdisInitializeWrapper (MINIPORT_DRIVER)
  *     SystemSpecific    = Always NULL
  */
 {
-    ExFreePool(NdisWrapperHandle);
+    PMINIPORT_DRIVER Miniport = GET_MINIPORT_DRIVER(NdisWrapperHandle);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    ExFreePool(Miniport);
 }
 
 /* EOF */
index 39a3b16..299ba51 100644 (file)
 #include <ndissys.h>
 #include <miniport.h>
 #include <protocol.h>
+#include <buffer.h>
+
 
 LIST_ENTRY ProtocolListHead;
 KSPIN_LOCK ProtocolListLock;
 
 
-VOID ProtocolWorker(
-    PVOID Context)
+NDIS_STATUS
+ProIndicatePacket(
+    PLOGICAL_ADAPTER Adapter,
+    PNDIS_PACKET Packet)
+/*
+ * FUNCTION: Indicates a packet to bound protocols
+ * ARGUMENTS:
+ *     Adapter = Pointer to logical adapter
+ *     Packet  = Pointer to packet to indicate
+ * RETURNS:
+ *     Status of operation
+ */
+{
+    KIRQL OldIrql;
+    UINT Length;
+    UINT Total;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+#ifdef DBG
+    MiniDisplayPacket(Packet);
+#endif
+
+    NdisQueryPacket(Packet, NULL, NULL, NULL, &Total);
+
+    KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+
+    Adapter->LoopPacket = Packet;
+
+    Length = CopyPacketToBuffer(
+        Adapter->LookaheadBuffer,
+        Packet,
+        0,
+        Adapter->CurLookaheadLength);
+
+    KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+    if (Length > Adapter->MediumHeaderSize) {
+        MiniIndicateData(Adapter,
+                         NULL,
+                         Adapter->LookaheadBuffer,
+                         Adapter->MediumHeaderSize,
+                         &Adapter->LookaheadBuffer[Adapter->MediumHeaderSize],
+                         Length - Adapter->MediumHeaderSize,
+                         Total - Adapter->MediumHeaderSize);
+    } else {
+        MiniIndicateData(Adapter,
+                         NULL,
+                         Adapter->LookaheadBuffer,
+                         Adapter->MediumHeaderSize,
+                         NULL,
+                         0,
+                         0);
+    }
+
+    KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+
+    Adapter->LoopPacket = NULL;
+
+    KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+    return STATUS_SUCCESS;
+}
+
+
+NDIS_STATUS
+ProRequest(
+    IN  NDIS_HANDLE     MacBindingHandle,
+    IN  PNDIS_REQUEST   NdisRequest)
+/*
+ * FUNCTION: Forwards a request to an NDIS miniport
+ * ARGUMENTS:
+ *     MacBindingHandle = Adapter binding handle
+ *     NdisRequest      = Pointer to request to perform
+ * RETURNS:
+ *     Status of operation
+ */
+{
+    KIRQL OldIrql;
+    BOOLEAN Queue;
+    NDIS_STATUS NdisStatus;
+    PADAPTER_BINDING AdapterBinding = GET_ADAPTER_BINDING(MacBindingHandle);
+    PLOGICAL_ADAPTER Adapter        = AdapterBinding->Adapter;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+    Queue = Adapter->MiniportBusy;
+    if (Queue) {
+        MiniQueueWorkItem(Adapter,
+                          NdisWorkItemRequest,
+                          (PVOID)NdisRequest,
+                          (NDIS_HANDLE)AdapterBinding);
+    } else {
+        Adapter->MiniportBusy = TRUE;
+    }
+    KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+    if (!Queue) {
+        KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+        NdisStatus = MiniDoRequest(Adapter, NdisRequest);
+        KeAcquireSpinLockAtDpcLevel(&Adapter->Lock);
+        Adapter->MiniportBusy = FALSE;
+        if (Adapter->WorkQueueHead)
+            KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);
+        KeReleaseSpinLockFromDpcLevel(&Adapter->Lock);
+        KeLowerIrql(OldIrql);
+    } else {
+        NdisStatus = NDIS_STATUS_PENDING;
+    }
+    return NdisStatus;
+}
+
+
+NDIS_STATUS
+ProReset(
+    IN  NDIS_HANDLE MacBindingHandle)
+{
+    UNIMPLEMENTED
+
+    return NDIS_STATUS_FAILURE;
+}
+
+
+NDIS_STATUS
+ProSend(
+    IN  NDIS_HANDLE     MacBindingHandle,
+    IN  PNDIS_PACKET    Packet)
+/*
+ * FUNCTION: Forwards a request to send a packet to an NDIS miniport
+ * ARGUMENTS:
+ *     MacBindingHandle = Adapter binding handle
+ *     Packet           = Pointer to NDIS packet descriptor
+ */
+{
+    KIRQL OldIrql;
+    BOOLEAN Queue;
+    NDIS_STATUS NdisStatus;
+    PADAPTER_BINDING AdapterBinding  = GET_ADAPTER_BINDING(MacBindingHandle);
+    PLOGICAL_ADAPTER Adapter         = AdapterBinding->Adapter;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    /* FIXME: Should queue packet if miniport returns NDIS_STATUS_RESOURCES */
+
+    Packet->Reserved[0] = (ULONG_PTR)MacBindingHandle;
+
+    KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
+    Queue = Adapter->MiniportBusy;
+
+    /* We may have to loop this packet if miniport cannot */
+    if (Adapter->MacOptions & NDIS_MAC_OPTION_NO_LOOPBACK) {
+        if (MiniAdapterHasAddress(Adapter, Packet)) {
+            /* Do software loopback because miniport does not support it */
+
+            NDIS_DbgPrint(MIN_TRACE, ("Looping packet.\n"));
+
+            if (Queue) {
+
+                /* FIXME: Packets should properbly be queued directly on the adapter instead */
+
+                MiniQueueWorkItem(Adapter,
+                                  NdisWorkItemSendLoopback,
+                                  (PVOID)Packet,
+                                  (NDIS_HANDLE)AdapterBinding);
+            } else {
+                Adapter->MiniportBusy = TRUE;
+            }
+            KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+            if (!Queue) {
+                KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+                NdisStatus = ProIndicatePacket(Adapter, Packet);
+                KeAcquireSpinLockAtDpcLevel(&Adapter->Lock);
+                Adapter->MiniportBusy = FALSE;
+                if (Adapter->WorkQueueHead)
+                    KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);
+                KeReleaseSpinLockFromDpcLevel(&Adapter->Lock);
+                KeLowerIrql(OldIrql);
+                return NdisStatus;
+            } else {
+                return NDIS_STATUS_PENDING;
+            }
+        }
+    }
+
+    if (Queue) {
+
+        /* FIXME: Packets should properbly be queued directly on the adapter instead */
+
+        MiniQueueWorkItem(Adapter,
+                          NdisWorkItemSend,
+                          (PVOID)Packet,
+                          (NDIS_HANDLE)AdapterBinding);
+    } else {
+        Adapter->MiniportBusy = TRUE;
+    }
+    KeReleaseSpinLock(&Adapter->Lock, OldIrql);
+
+    if (!Queue) {
+        KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+        NdisStatus = (*Adapter->Miniport->Chars.u1.SendHandler)(
+            Adapter->MiniportAdapterContext,
+            Packet,
+            0);
+        KeAcquireSpinLockAtDpcLevel(&Adapter->Lock);
+        Adapter->MiniportBusy = FALSE;
+        if (Adapter->WorkQueueHead)
+            KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);
+        KeReleaseSpinLockFromDpcLevel(&Adapter->Lock);
+        KeLowerIrql(OldIrql);
+    } else {
+        NdisStatus = NDIS_STATUS_PENDING;
+    }
+    return NdisStatus;
+}
+
+
+VOID
+ProSendPackets(
+    IN  NDIS_HANDLE     NdisBindingHandle,
+    IN  PPNDIS_PACKET   PacketArray,
+    IN  UINT            NumberOfPackets)
+{
+    UNIMPLEMENTED
+}
+
+
+NDIS_STATUS
+ProTransferData(
+    IN  NDIS_HANDLE         MacBindingHandle,
+    IN  NDIS_HANDLE         MacReceiveContext,
+    IN  UINT                ByteOffset,
+    IN  UINT                BytesToTransfer,
+    IN  OUT    PNDIS_PACKET    Packet,
+    OUT PUINT               BytesTransferred)
 /*
- * FUNCTION: Worker function for ProtocolXxx functions
+ * FUNCTION: Forwards a request to copy received data into a protocol-supplied packet
  * ARGUMENTS:
- *     Context = Pointer to context information (PROTOCOL_BINDING)
+ *     MacBindingHandle  = Adapter binding handle
+ *     MacReceiveContext = MAC receive context
+ *     ByteOffset        = Offset in packet to place data
+ *     BytesToTransfer   = Number of bytes to copy into packet
+ *     Packet            = Pointer to NDIS packet descriptor
+ *     BytesTransferred  = Address of buffer to place number of bytes copied
  */
 {
+    PADAPTER_BINDING AdapterBinding = GET_ADAPTER_BINDING(MacBindingHandle);
+    PLOGICAL_ADAPTER Adapter        = AdapterBinding->Adapter;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    /* FIXME: Interrupts must be disabled for adapter */
+
+    if (Packet == Adapter->LoopPacket) {
+        /* NDIS is responsible for looping this packet */
+        NdisCopyFromPacketToPacket(Packet,
+                                   ByteOffset,
+                                   BytesToTransfer,
+                                   Adapter->LoopPacket,
+                                   0,
+                                   BytesTransferred);
+        return NDIS_STATUS_SUCCESS;
+    }
+
+    return (*Adapter->Miniport->Chars.u2.TransferDataHandler)(
+        Packet,
+        BytesTransferred,
+        Adapter->MiniportAdapterContext,
+        MacReceiveContext,
+        ByteOffset,
+        BytesToTransfer);
 }
 
 
+
 VOID
 EXPORT
-STDCALL
 NdisCloseAdapter(
     OUT PNDIS_STATUS    Status,
     IN  NDIS_HANDLE     NdisBindingHandle)
@@ -39,8 +305,21 @@ NdisCloseAdapter(
  *     NdisBindingHandle = Handle returned by NdisOpenAdapter
  */
 {
+    KIRQL OldIrql;
     PADAPTER_BINDING AdapterBinding = GET_ADAPTER_BINDING(NdisBindingHandle);
 
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    /* Remove from protocol's bound adapters list */
+    KeAcquireSpinLock(&AdapterBinding->ProtocolBinding->Lock, &OldIrql);
+    RemoveEntryList(&AdapterBinding->ProtocolListEntry);
+    KeReleaseSpinLock(&AdapterBinding->ProtocolBinding->Lock, OldIrql);
+
+    /* Remove protocol from adapter's bound protocols list */
+    KeAcquireSpinLock(&AdapterBinding->Adapter->Lock, &OldIrql);
+    RemoveEntryList(&AdapterBinding->AdapterListEntry);
+    KeReleaseSpinLock(&AdapterBinding->Adapter->Lock, OldIrql);
+
     ExFreePool(AdapterBinding);
 
     *Status = NDIS_STATUS_SUCCESS;
@@ -59,7 +338,20 @@ NdisDeregisterProtocol(
  *     NdisProtocolHandle = Handle returned by NdisRegisterProtocol
  */
 {
-    ExFreePool(NdisProtocolHandle);
+    KIRQL OldIrql;
+    PPROTOCOL_BINDING Protocol = GET_PROTOCOL_BINDING(NdisProtocolHandle);
+
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
+    /* FIXME: Make sure no adapter bindings exist */
+
+    /* Remove protocol from global list */
+    KeAcquireSpinLock(&ProtocolListLock, &OldIrql);
+    RemoveEntryList(&Protocol->ListEntry);
+    KeReleaseSpinLock(&ProtocolListLock, OldIrql);
+
+    ExFreePool(Protocol);
+
     *Status = NDIS_STATUS_SUCCESS;
 }
 
@@ -94,60 +386,38 @@ NdisOpenAdapter(
  *     AddressingInformation  = Optional pointer to buffer with NIC specific information
  */
 {
-    PADAPTER_BINDING AdapterBinding;
-    PLOGICAL_ADAPTER Adapter;
-    NDIS_STATUS NdisStatus;
-    PNDIS_MEDIUM Medium1;
-    PNDIS_MEDIUM Medium2;
-    ULONG BytesWritten;
+    UINT i;
     BOOLEAN Found;
-    UINT i, j;
-    PPROTOCOL_BINDING Protocol = GET_PROTOCOL_BINDING(ProtocolBindingContext);
+    PLOGICAL_ADAPTER Adapter;
+    PADAPTER_BINDING AdapterBinding;
+    PPROTOCOL_BINDING Protocol = GET_PROTOCOL_BINDING(NdisProtocolHandle);
 
-    Adapter = MiniLocateDevice(AdapterName);
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 
+    Adapter = MiniLocateDevice(AdapterName);
     if (!Adapter) {
         NDIS_DbgPrint(MIN_TRACE, ("Adapter not found.\n"));
         *Status = NDIS_STATUS_ADAPTER_NOT_FOUND;
         return;
     }
 
-    /* Query the miniport driver for it's supported medias and search the list
-       to find the first medium also supported by the protocol driver */
-
-    NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MEDIA_SUPPORTED, 0, &BytesWritten);
-
-    /* FIXME: Handle this */
-    if (NdisStatus == NDIS_STATUS_PENDING) {
-        NDIS_DbgPrint(MIN_TRACE, ("NDIS_STATUS_PENDING returned!\n"));
-    }
-
-    if (!NT_SUCCESS(NdisStatus))
-        *Status = NdisStatus;
-
-    Medium1 = Adapter->QueryBuffer;
-    Medium2 = MediumArray;
-    Found   = FALSE;
-    for (i = 0; i < BytesWritten / sizeof(NDIS_MEDIUM); i++) {
-        for (j = 0; j < MediumArraySize; j++) {
-            if (Medium2[j] == Medium1[i]) {
-                *SelectedMediumIndex = j;
-                Found = TRUE;
-                break;
-            }
-        }
-        if (Found)
+    /* Find the media type in the list provided by the protocol driver */
+    Found = FALSE;
+    for (i = 0; i < MediumArraySize; i++) {
+        if (Adapter->MediaType == MediumArray[i]) {
+            *SelectedMediumIndex = i;
+            Found = TRUE;
             break;
+        }
     }
 
     if (!Found) {
-        NDIS_DbgPrint(MIN_TRACE, ("Media is not supported.\n"));
+        NDIS_DbgPrint(MIN_TRACE, ("Medium is not supported.\n"));
         *Status = NDIS_STATUS_UNSUPPORTED_MEDIA;
         return;
     }
 
     AdapterBinding = ExAllocatePool(NonPagedPool, sizeof(ADAPTER_BINDING));
-
     if (!AdapterBinding) {
         NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
         *Status = NDIS_STATUS_RESOURCES;
@@ -156,12 +426,32 @@ NdisOpenAdapter(
 
     RtlZeroMemory(AdapterBinding, sizeof(ADAPTER_BINDING));
 
-    /* Put on protocol binding adapter list */
+    AdapterBinding->ProtocolBinding        = Protocol;
+    AdapterBinding->Adapter                = Adapter;
+    AdapterBinding->ProtocolBindingContext = ProtocolBindingContext;
+
+    /* Set fields required by some NDIS macros */
+    AdapterBinding->MacBindingHandle = (NDIS_HANDLE)AdapterBinding;
+    
+    /* Set handlers (some NDIS macros require these) */
+
+    AdapterBinding->RequestHandler      = ProRequest;
+    AdapterBinding->ResetHandler        = ProReset;
+    AdapterBinding->u1.SendHandler      = ProSend;
+    AdapterBinding->SendPacketsHandler  = ProSendPackets;
+    AdapterBinding->TransferDataHandler = ProTransferData;
+
+    /* Put on protocol's bound adapters list */
     ExInterlockedInsertTailList(&Protocol->AdapterListHead,
                                 &AdapterBinding->ProtocolListEntry,
                                 &Protocol->Lock);
 
-    *NdisBindingHandle = AdapterBinding;
+    /* Put protocol on adapter's bound protocols list */
+    ExInterlockedInsertTailList(&Adapter->ProtocolListHead,
+                                &AdapterBinding->AdapterListEntry,
+                                &Adapter->Lock);
+
+    *NdisBindingHandle = (NDIS_HANDLE)AdapterBinding;
 
     *Status = NDIS_STATUS_SUCCESS;
 }
@@ -187,6 +477,8 @@ NdisRegisterProtocol(
     NTSTATUS NtStatus;
     UINT MinSize;
 
+    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
+
     switch (ProtocolCharacteristics->MajorNdisVersion) {
     case 0x03:
         MinSize = sizeof(NDIS30_PROTOCOL_CHARACTERISTICS_S);
@@ -221,10 +513,9 @@ NdisRegisterProtocol(
     RtlZeroMemory(Protocol, sizeof(PROTOCOL_BINDING));
     RtlCopyMemory(&Protocol->Chars, ProtocolCharacteristics, MinSize);
 
-    NtStatus = RtlUpcaseUnicodeString(
-        &Protocol->Chars.Name,
-        &ProtocolCharacteristics->Name,
-        TRUE);
+    NtStatus = RtlUpcaseUnicodeString(&Protocol->Chars.Name,
+                                      &ProtocolCharacteristics->Name,
+                                      TRUE);
     if (!NT_SUCCESS(NtStatus)) {
         NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
         ExFreePool(Protocol);
@@ -236,10 +527,13 @@ NdisRegisterProtocol(
 
     Protocol->RefCount = 1;
 
-    ExInitializeWorkItem(&Protocol->WorkItem, ProtocolWorker, Protocol);
-
     InitializeListHead(&Protocol->AdapterListHead);
 
+    /* Put protocol binding on global list */
+    ExInterlockedInsertTailList(&ProtocolListHead,
+                                &Protocol->ListEntry,
+                                &ProtocolListLock);
+
     *NdisProtocolHandle = Protocol;
     *Status             = NDIS_STATUS_SUCCESS;
 }
@@ -251,8 +545,15 @@ NdisRequest(
     OUT PNDIS_STATUS    Status,
     IN  NDIS_HANDLE     NdisBindingHandle,
     IN  PNDIS_REQUEST   NdisRequest)
+/*
+ * FUNCTION: Forwards a request to an NDIS driver
+ * ARGUMENTS:
+ *     Status            = Address of buffer for status information
+ *     NdisBindingHandle = Adapter binding handle
+ *     NdisRequest       = Pointer to request to perform
+ */
 {
-    UNIMPLEMENTED
+    *Status = ProRequest(NdisBindingHandle, NdisRequest);
 }
 
 
@@ -262,7 +563,7 @@ NdisReset(
     OUT PNDIS_STATUS    Status,
     IN  NDIS_HANDLE     NdisBindingHandle)
 {
-    UNIMPLEMENTED
+    *Status = ProReset(NdisBindingHandle);
 }
 
 
@@ -272,8 +573,15 @@ NdisSend(
     OUT PNDIS_STATUS    Status,
     IN  NDIS_HANDLE     NdisBindingHandle,
     IN  PNDIS_PACKET    Packet)
+/*
+ * FUNCTION: Forwards a request to send a packet
+ * ARGUMENTS:
+ *     Status             = Address of buffer for status information
+ *     NdisBindingHandle  = Adapter binding handle
+ *     Packet             = Pointer to NDIS packet descriptor
+ */
 {
-    UNIMPLEMENTED
+    *Status = ProSend(NdisBindingHandle, Packet);
 }
 
 
@@ -284,22 +592,38 @@ NdisSendPackets(
     IN  PPNDIS_PACKET   PacketArray,
     IN  UINT            NumberOfPackets)
 {
-    UNIMPLEMENTED
+    ProSendPackets(NdisBindingHandle, PacketArray, NumberOfPackets);
 }
 
 
 VOID
 EXPORT
 NdisTransferData(
-    OUT PNDIS_STATUS        Status,
-    IN  NDIS_HANDLE         NdisBindingHandle,
-    IN  NDIS_HANDLE         MacReceiveContext,
-    IN  UINT                ByteOffset,
-    IN  UINT                BytesToTransfer,
-    IN  OUT    PNDIS_PACKET    Packet,
-    OUT PUINT               BytesTransferred)
+    OUT     PNDIS_STATUS    Status,
+    IN      NDIS_HANDLE     NdisBindingHandle,
+    IN      NDIS_HANDLE     MacReceiveContext,
+    IN      UINT            ByteOffset,
+    IN      UINT            BytesToTransfer,
+    IN OUT     PNDIS_PACKET    Packet,
+    OUT     PUINT           BytesTransferred)
+/*
+ * FUNCTION: Forwards a request to copy received data into a protocol-supplied packet
+ * ARGUMENTS:
+ *     Status            = Address of buffer for status information
+ *     NdisBindingHandle = Adapter binding handle
+ *     MacReceiveContext = MAC receive context
+ *     ByteOffset        = Offset in packet to place data
+ *     BytesToTransfer   = Number of bytes to copy into packet
+ *     Packet            = Pointer to NDIS packet descriptor
+ *     BytesTransferred  = Address of buffer to place number of bytes copied
+ */
 {
-    UNIMPLEMENTED
+    *Status = ProTransferData(NdisBindingHandle,
+                              MacReceiveContext,
+                              ByteOffset,
+                              BytesToTransfer,
+                              Packet,
+                              BytesTransferred);
 }
 
 /* EOF */
index 8a56921..76c2eb2 100644 (file)
@@ -100,27 +100,6 @@ NdisInterlockedRemoveHeadList(
 }
 
 
-VOID
-EXPORT
-NdisMArcIndicateReceive(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  PUCHAR      HeaderBuffer,
-    IN  PUCHAR      DataBuffer,
-    IN  UINT        Length)
-{
-    UNIMPLEMENTED
-}
-
-
-VOID
-EXPORT
-NdisMArcIndicateReceiveComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle)
-{
-    UNIMPLEMENTED
-}
-
-
 VOID
 EXPORT
 NdisMCompleteBufferPhysicalMapping(
@@ -131,54 +110,6 @@ NdisMCompleteBufferPhysicalMapping(
 }
 
 
-VOID
-EXPORT
-NdisMEthIndicateReceive (
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_HANDLE MiniportReceiveContext,
-    IN  PVOID       HeaderBuffer,
-    IN  UINT        HeaderBufferSize,
-    IN  PVOID       LookaheadBuffer,
-    IN  UINT        LookaheadBufferSize,
-    IN  UINT        PacketSize)
-{
-    UNIMPLEMENTED
-}
-
-
-VOID
-EXPORT
-NdisMEthIndicateReceiveComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle)
-{
-    UNIMPLEMENTED
-}
-
-
-VOID
-EXPORT
-NdisMFddiIndicateReceive(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_HANDLE MiniportReceiveContext,
-    IN  PVOID       HeaderBuffer,
-    IN  UINT        HeaderBufferSize,
-    IN  PVOID       LookaheadBuffer,
-    IN  UINT        LookaheadBufferSize,
-    IN  UINT        PacketSize)
-{
-    UNIMPLEMENTED
-}
-
-
-VOID
-EXPORT
-NdisMFddiIndicateReceiveComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle)
-{
-    UNIMPLEMENTED
-}
-
-
 VOID
 EXPORT
 NdisMStartBufferPhysicalMapping(
@@ -193,30 +124,6 @@ NdisMStartBufferPhysicalMapping(
 }
 
 
-VOID
-EXPORT
-NdisMTrIndicateReceive(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_HANDLE MiniportReceiveContext,
-    IN  PVOID       HeaderBuffer,
-    IN  UINT        HeaderBufferSize,
-    IN  PVOID       LookaheadBuffer,
-    IN  UINT        LookaheadBufferSize,
-    IN  UINT        PacketSize)
-{
-    UNIMPLEMENTED
-}
-
-
-VOID
-EXPORT
-NdisMTrIndicateReceiveComplete(
-    IN  NDIS_HANDLE  MiniportAdapterHandle)
-{
-    UNIMPLEMENTED
-}
-
-
 VOID
 EXPORT
 NdisMapFile(
index 811d9f3..dd42439 100644 (file)
@@ -34,8 +34,13 @@ extern "C"
 #endif
 #endif
 
+#ifndef UNALIGNED
 #define UNALIGNED
+#endif
 
+#ifndef FASTCALL
+#define FASTCALL STDCALL
+#endif
 
 /* The NDIS library export functions. NDIS miniport drivers import functions */
 #ifdef NDIS_WRAPPER
@@ -201,7 +206,7 @@ typedef signed int INT, *PINT;
 
 #include "netevent.h"
 #include "ndisoid.h"
-
+#include "ntddndis.h"
 
 
 /* More types */
@@ -683,8 +688,8 @@ typedef enum _NDIS_INTERFACE_TYPE
        NdisInterfacePcMcia         = PCMCIABus
 } NDIS_INTERFACE_TYPE, *PNDIS_INTERFACE_TYPE;
 
-#define NdisInterruptLatched        Latched
 #define NdisInterruptLevelSensitive LevelSensitive
+#define NdisInterruptLatched        Latched
 typedef KINTERRUPT_MODE NDIS_INTERRUPT_MODE, *PNDIS_INTERRUPT_MODE;
 
 
@@ -721,248 +726,31 @@ typedef VOID (*ADAPTER_SHUTDOWN_HANDLER)(
 
 
 
-#if defined(NDIS_WRAPPER) || !defined(NDIS_MINIPORT_DRIVER)
-
-/* Structures available only to full MAC drivers */
-
-typedef BOOLEAN (*PNDIS_INTERRUPT_SERVICE)(
-    IN  PVOID   InterruptContext);
-
-typedef VOID (*PNDIS_DEFERRED_PROCESSING)(
-    IN  PVOID   SystemSpecific1,
-    IN  PVOID   InterruptContext,
-    IN  PVOID   SystemSpecific2,
-    IN  PVOID   SystemSpecific3);
-
-
-typedef struct _NDIS_INTERRUPT
-{
-    PKINTERRUPT                 InterruptObject;
-    KSPIN_LOCK                  DpcCountLock;
-    PNDIS_INTERRUPT_SERVICE     MacIsr;
-    PNDIS_DEFERRED_PROCESSING   MacDpc;
-    KDPC                        InterruptDpc;
-    PVOID                       InterruptContext;
-    UCHAR                       DpcCount;
-    BOOLEAN                     Removing;
-    /* Used to tell when all DPCs for the adapter are completed */
-    KEVENT                                             DpcsCompletedEvent;
-} NDIS_INTERRUPT, *PNDIS_INTERRUPT;
-
-
-/* NDIS adapter information */
-
-typedef NDIS_STATUS (*PNDIS_ACTIVATE_CALLBACK)(
-    IN  NDIS_HANDLE NdisAdatperHandle,
-    IN  NDIS_HANDLE MacAdapterContext,
-    IN  ULONG       DmaChannel);
-
-typedef struct _NDIS_PORT_DESCRIPTOR
-{
-    ULONG   InitialPort;
-    ULONG   NumberOfPorts;
-    PVOID * PortOffset;
-} NDIS_PORT_DESCRIPTOR, *PNDIS_PORT_DESCRIPTOR;
-
-typedef struct _NDIS_ADAPTER_INFORMATION
-{
-    ULONG                   DmaChannel;
-    BOOLEAN                    Master;
-    BOOLEAN                    Dma32BitAddresses;
-    PNDIS_ACTIVATE_CALLBACK ActivateCallback;
-    NDIS_INTERFACE_TYPE     AdapterType;
-    ULONG                   PhysicalMapRegistersNeeded;
-    ULONG                   MaximumPhysicalMapping;
-    ULONG                   NumberOfPortDescriptors;
-    NDIS_PORT_DESCRIPTOR    PortDescriptors[1];
-} NDIS_ADAPTER_INFORMATION, *PNDIS_ADAPTER_INFORMATION;
-
-
-/* Prototypes for NDIS_MAC_CHARACTERISTICS */
-
-typedef NDIS_STATUS (*OPEN_ADAPTER_HANDLER)(
-    OUT PNDIS_STATUS    OpenErrorStatus,
-    OUT NDIS_HANDLE *   MacBindingHandle,
-    OUT PUINT           SelectedMediumIndex,
-    IN  PNDIS_MEDIUM    MediumArray,
-    IN  UINT            MediumArraySize,
-    IN  NDIS_HANDLE     NdisBindingContext,
-    IN  NDIS_HANDLE     MacAdapterContext,
-    IN  UINT            OpenOptions,
-    IN  PSTRING         AddressingInformation OPTIONAL);
-
-typedef NDIS_STATUS (*CLOSE_ADAPTER_HANDLER)(
-    IN  NDIS_HANDLE MacBindingHandle);
-
-typedef NDIS_STATUS (*SEND_HANDLER)(
-    IN  NDIS_HANDLE     MacBindingHandle,
-    IN  PNDIS_PACKET    Packet);
-
-typedef NDIS_STATUS (*WAN_SEND_HANDLER)(
-    IN  NDIS_HANDLE         MacBindingHandle,
-    IN  PNDIS_WAN_PACKET    Packet);
-
-typedef NDIS_STATUS (*TRANSFER_DATA_HANDLER)(
-    IN  NDIS_HANDLE     MacBindingHandle,
-    IN  NDIS_HANDLE     MacReceiveContext,
-    IN  UINT            ByteOffset,
-    IN  UINT            BytesToTransfer,
-    OUT PNDIS_PACKET    Packet,
-    OUT PUINT           BytesTransferred);
-
-typedef NDIS_STATUS (*WAN_TRANSFER_DATA_HANDLER)(
-    VOID);
-
-typedef NDIS_STATUS (*RESET_HANDLER)(
-    IN  NDIS_HANDLE MacBindingHandle);
-
-typedef NDIS_STATUS (*REQUEST_HANDLER)(
-    IN  NDIS_HANDLE     MacBindingHandle,
-    IN  PNDIS_REQUEST   NdisRequest);
-
-typedef NDIS_STATUS (*QUERY_GLOBAL_STATISTICS_HANDLER)(
-    IN  NDIS_HANDLE     MacAdapterContext,
-    IN  PNDIS_REQUEST   NdisRequest);
-
-typedef VOID (*UNLOAD_MAC_HANDLER)(
-    IN  NDIS_HANDLE MacMacContext);
+#ifdef NDIS_WRAPPER
 
-typedef NDIS_STATUS (*ADD_ADAPTER_HANDLER)(
-    IN  NDIS_HANDLE     MacMacContext,
-    IN  NDIS_HANDLE     WrapperConfigurationContext,
-    IN  PNDIS_STRING    AdapterName);
+typedef struct _OID_LIST    OID_LIST, *POID_LIST;
 
-typedef VOID (*REMOVE_ADAPTER_HANDLER)(
-    IN  NDIS_HANDLE MacAdapterContext);
+/* PnP state */
 
-typedef struct _NDIS_MAC_CHARACTERISTICS
+typedef enum _NDIS_PNP_DEVICE_STATE
 {
-    UCHAR                           MajorNdisVersion;
-    UCHAR                           MinorNdisVersion;
-    UINT                            Reserved;
-    OPEN_ADAPTER_HANDLER            OpenAdapterHandler;
-    CLOSE_ADAPTER_HANDLER           CloseAdapterHandler;
-    SEND_HANDLER                    SendHandler;
-    TRANSFER_DATA_HANDLER           TransferDataHandler;
-    RESET_HANDLER                   ResetHandler;
-    REQUEST_HANDLER                 RequestHandler;
-    QUERY_GLOBAL_STATISTICS_HANDLER QueryGlobalStatisticsHandler;
-    UNLOAD_MAC_HANDLER              UnloadMacHandler;
-    ADD_ADAPTER_HANDLER             AddAdapterHandler;
-    REMOVE_ADAPTER_HANDLER          RemoveAdapterHandler;
-    NDIS_STRING                     Name;
-} NDIS_MAC_CHARACTERISTICS, *PNDIS_MAC_CHARACTERISTICS;
-
-typedef        NDIS_MAC_CHARACTERISTICS        NDIS_WAN_MAC_CHARACTERISTICS;
-typedef        NDIS_WAN_MAC_CHARACTERISTICS    *PNDIS_WAN_MAC_CHARACTERISTICS;
-
-
-
-/* Functions available only to full MAC drivers */
-
-VOID
-EXPIMP
-NdisAllocateSharedMemory(
-    IN  NDIS_HANDLE             NdisAdapterHandle,
-    IN  ULONG                   Length,
-    IN  BOOLEAN                 Cached,
-    OUT PVOID                   *VirtualAddress,
-    OUT PNDIS_PHYSICAL_ADDRESS  PhysicalAddress);
-
-VOID
-EXPIMP
-NdisCompleteCloseAdapter(
-    IN  NDIS_HANDLE NdisBindingContext,
-    IN  NDIS_STATUS Status);
-
-VOID
-EXPIMP
-NdisCompleteOpenAdapter(
-    IN  NDIS_HANDLE NdisBindingContext,
-    IN  NDIS_STATUS Status,
-    IN  NDIS_STATUS OpenErrorStatus);
-
-NDIS_STATUS
-EXPIMP
-NdisDeregisterAdapter(
-    IN  NDIS_HANDLE NdisAdapterHandle);
-
-VOID
-EXPIMP
-NdisDeregisterAdapterShutdownHandler(
-    IN  NDIS_HANDLE NdisAdapterHandle);
-
-VOID
-EXPIMP
-NdisFreeSharedMemory(
-    IN  NDIS_HANDLE             NdisAdapterHandle,
-    IN  ULONG                   Length,
-    IN  BOOLEAN                 Cached,
-    IN  PVOID                   VirtualAddress,
-    IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress);
-
-VOID
-EXPIMP
-NdisInitializeInterrupt(
-    OUT     PNDIS_STATUS                Status,
-    IN OUT  PNDIS_INTERRUPT             Interrupt,
-    IN      NDIS_HANDLE                 NdisAdapterHandle,
-    IN      PNDIS_INTERRUPT_SERVICE     InterruptServiceRoutine,
-    IN      PVOID                       InterruptContext,
-    IN      PNDIS_DEFERRED_PROCESSING   DeferredProcessingRoutine,
-    IN      UINT                        InterruptVector,
-    IN      UINT                        InterruptLevel,
-    IN      BOOLEAN                     SharedInterrupt,
-    IN      NDIS_INTERRUPT_MODE         InterruptMode);
-
-VOID
-EXPIMP
-NdisMapIoSpace(
-    OUT PNDIS_STATUS            Status,
-    OUT PVOID                   *VirtualAddress,
-    IN  NDIS_HANDLE             NdisAdapterHandle,
-    IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress,
-    IN  UINT                    Length);
-
-NDIS_STATUS
-EXPIMP
-NdisRegisterAdapter(
-    OUT PNDIS_HANDLE    NdisAdapterHandle,
-    IN  NDIS_HANDLE     NdisMacHandle,
-    IN  NDIS_HANDLE     MacAdapterContext,
-    IN  NDIS_HANDLE     WrapperConfigurationContext,
-    IN  PNDIS_STRING    AdapterName,
-    IN  PVOID           AdapterInformation);
-
-VOID
-EXPIMP
-NdisRegisterAdapterShutdownHandler(
-    IN  NDIS_HANDLE                 NdisAdapterHandle,
-    IN  PVOID                       ShutdownContext,
-    IN  ADAPTER_SHUTDOWN_HANDLER    ShutdownHandler);
-
-VOID
-EXPIMP
-NdisRegisterMac(
-    OUT PNDIS_STATUS                Status,
-    OUT PNDIS_HANDLE                NdisMacHandle,
-    IN  NDIS_HANDLE                 NdisWrapperHandle,
-    IN  NDIS_HANDLE                 MacMacContext,
-    IN  PNDIS_MAC_CHARACTERISTICS   MacCharacteristics,
-    IN  UINT                        CharacteristicsLength);
-
-VOID
-EXPIMP
-NdisReleaseAdapterResources(
-    IN  NDIS_HANDLE NdisAdapterHandle);
-
-VOID
-EXPIMP
-NdisRemoveInterrupt(
-    IN  PNDIS_INTERRUPT Interrupt);
-
-#endif /* NDIS_WRAPPER || !NDIS_MINIPORT_DRIVER */
+    NdisPnPDeviceAdded,
+    NdisPnPDeviceStarted,
+    NdisPnPDeviceQueryStopped,
+    NdisPnPDeviceStopped,
+    NdisPnPDeviceQueryRemoved,
+    NdisPnPDeviceRemoved,
+    NdisPnPDeviceSurpriseRemoved
+} NDIS_PNP_DEVICE_STATE;
+
+#define        NDIS_DEVICE_NOT_STOPPABLE               0x00000001
+#define        NDIS_DEVICE_NOT_REMOVEABLE              0x00000002
+#define        NDIS_DEVICE_NOT_SUSPENDABLE                 0x00000004
+#define NDIS_DEVICE_DISABLE_PM                  0x00000008
+#define NDIS_DEVICE_DISABLE_WAKE_UP             0x00000010
+#define NDIS_DEVICE_DISABLE_WAKE_ON_RECONNECT   0x00000020
 
+#endif /* NDIS_WRAPPER */
 
 
 #ifdef NDIS50
@@ -1473,7 +1261,7 @@ typedef VOID (*RECEIVE_COMPLETE_HANDLER)(
 
 
 /* Protocol characteristics for NDIS 3.0 protocols */
-#if 0
+#ifdef _MSC_VER
 typedef struct _NDIS30_PROTOCOL_CHARACTERISTICS
 {
     UCHAR                           MajorNdisVersion;
@@ -1508,6 +1296,7 @@ typedef struct _NDIS30_PROTOCOL_CHARACTERISTICS
     STATUS_COMPLETE_HANDLER            StatusCompleteHandler;
     NDIS_STRING                            Name;
 } NDIS30_PROTOCOL_CHARACTERISTICS;
+typedef NDIS30_PROTOCOL_CHARACTERISTICS NDIS30_PROTOCOL_CHARACTERISTICS_S;
 #else
 #define NDIS30_PROTOCOL_CHARACTERISTICS \
     UCHAR                           MajorNdisVersion; \
@@ -1576,7 +1365,7 @@ typedef VOID (*UNLOAD_PROTOCOL_HANDLER)(
 
 
 /* Protocol characteristics for NDIS 4.0 protocols */
-#if 0
+#ifdef _MSC_VER
 typedef struct _NDIS40_PROTOCOL_CHARACTERISTICS
 {
     NDIS30_PROTOCOL_CHARACTERISTICS;
@@ -1587,6 +1376,7 @@ typedef struct _NDIS40_PROTOCOL_CHARACTERISTICS
     TRANSLATE_HANDLER       TranslateHandler;
     UNLOAD_PROTOCOL_HANDLER UnloadHandler;
 } NDIS40_PROTOCOL_CHARACTERISTICS;
+typedef NDIS40_PROTOCOL_CHARACTERISTICS NDIS40_PROTOCOL_CHARACTERISTICS_S;
 #else
 #define NDIS40_PROTOCOL_CHARACTERISTICS \
     NDIS30_PROTOCOL_CHARACTERISTICS; \
@@ -1627,7 +1417,7 @@ typedef VOID (*CO_AF_REGISTER_NOTIFY_HANDLER)(
     IN  NDIS_HANDLE         ProtocolBindingContext,
     IN  PCO_ADDRESS_FAMILY  AddressFamily);
 
-#if 0
+#ifdef _MSC_VER
 typedef struct _NDIS50_PROTOCOL_CHARACTERISTICS
 {
     NDIS40_PROTOCOL_CHARACTERISTICS;
@@ -1639,6 +1429,7 @@ typedef struct _NDIS50_PROTOCOL_CHARACTERISTICS
     CO_RECEIVE_PACKET_HANDLER       CoReceivePacketHandler;
     CO_AF_REGISTER_NOTIFY_HANDLER   CoAfRegisterNotifyHandler;
 } NDIS50_PROTOCOL_CHARACTERISTICS;
+typedef NDIS50_PROTOCOL_CHARACTERISTICS NDIS50_PROTOCOL_CHARACTERISTICS_S;
 #else
 #define NDIS50_PROTOCOL_CHARACTERISTICS \
     NDIS40_PROTOCOL_CHARACTERISTICS; \
@@ -1932,14 +1723,14 @@ NdisFreeBuffer(
  *     OUT PVOID           *VirtualAddress OPTIONAL,
  *     OUT PUINT           Length)
  */
-#define NdisQueryBuffer(Buffer,                                         \
-                        VirtualAddress,                                 \
-                        Length)                                         \
-{                                                                       \
-       if (VirtualAddress != NULL)                                         \
-               *(PVOID*)(VirtualAddress) = MmGetSystemAddressForMdl(Buffer);   \
-                                                                        \
-       *(Length) = MmGetMdlByteCount(Buffer);                              \
+#define NdisQueryBuffer(Buffer,                                       \
+                        VirtualAddress,                               \
+                        Length)                                       \
+{                                                                     \
+       if (VirtualAddress)                                               \
+               *((PVOID*)VirtualAddress) = MmGetSystemAddressForMdl(Buffer); \
+                                                                      \
+       *((PUINT)Length) = MmGetMdlByteCount(Buffer);                     \
 }
 
 
@@ -1953,8 +1744,8 @@ NdisFreeBuffer(
                               Offset,               \
                               Length)               \
 {                                                   \
-    *(PUINT)(Offset) = MmGetMdlByteOffset(Buffer);  \
-    *(PUINT)(Length) = MmGetMdlByteCount(Buffer);   \
+    *((PUINT)Offset) = MmGetMdlByteOffset(Buffer);  \
+    *((PUINT)Length) = MmGetMdlByteCount(Buffer);   \
 }
 
 #endif /* BINARY_COMPATIBLE */
@@ -2120,8 +1911,8 @@ NdisFreeBuffer(
                         FirstBuffer,                                            \
                         TotalPacketLength)                                      \
 {                                                                               \
-    if ((FirstBuffer) != NULL)                                                  \
-        *(FirstBuffer) = (Packet)->Private.Head;                                \
+    if (FirstBuffer)                                                            \
+        *((PNDIS_BUFFER*)FirstBuffer) = (Packet)->Private.Head;                 \
     if ((TotalPacketLength) || (BufferCount) || (PhysicalBufferCount)) {        \
         if (!(Packet)->Private.ValidCounts) {                                   \
             UINT _Offset;                                                       \
@@ -2146,16 +1937,17 @@ NdisFreeBuffer(
                }                                                                       \
                                                                                 \
         if (PhysicalBufferCount)                                                \
-            *(PUINT)(PhysicalBufferCount) = (Packet)->Private.PhysicalCount;    \
+            *((PUINT)PhysicalBufferCount) = (Packet)->Private.PhysicalCount;    \
                                                                                 \
         if (BufferCount)                                                        \
-            *(PUINT)(BufferCount) = (Packet)->Private.Count;                    \
+            *((PUINT)BufferCount) = (Packet)->Private.Count;                    \
                                                                                 \
         if (TotalPacketLength)                                                  \
-            *(PUINT)(TotalPacketLength) = (Packet)->Private.TotalLength;        \
+            *((PUINT)TotalPacketLength) = (Packet)->Private.TotalLength;        \
     }                                                                           \
 }
 
+
 /*
  * VOID NdisRecalculatePacketCounts(
  *     IN OUT  PNDIS_PACKET    Packet);
@@ -2698,41 +2490,12 @@ NdisUnicodeStringToAnsiString(
     WRITE_REGISTER_USHORT((Register), (Data))
 
 
+/* Linked lists */
 
 VOID
 EXPIMP
-NdisCloseAdapter(
-    OUT PNDIS_STATUS    Status,
-    IN  NDIS_HANDLE     NdisBindingHandle);
-
-VOID
-EXPIMP
-NdisCloseConfiguration(
-    IN  NDIS_HANDLE ConfigurationHandle);
-
-VOID
-EXPIMP
-NdisCompleteBindAdapter(
-    IN  NDIS_HANDLE BindAdapterContext,
-    IN  NDIS_STATUS Status,
-    IN  NDIS_STATUS OpenStatus);
-
-VOID
-EXPIMP
-NdisCompleteUnbindAdapter(
-    IN  NDIS_HANDLE UnbindAdapterContext,
-    IN  NDIS_STATUS Status);
-
-VOID
-EXPIMP
-NdisDeregisterProtocol(
-    OUT PNDIS_STATUS    Status,
-    IN  NDIS_HANDLE     NdisProtocolHandle);
-
-VOID
-EXPIMP
-NdisInitializeListHead(
-    IN  PLIST_ENTRY ListHead);
+NdisInitializeListHead(
+    IN  PLIST_ENTRY ListHead);
 
 VOID
 EXPIMP
@@ -2761,38 +2524,11 @@ NdisInterlockedRemoveHeadList(
     IN  PLIST_ENTRY     ListHead,
     IN  PNDIS_SPIN_LOCK SpinLock); 
 
-VOID
-EXPIMP
-NdisOpenAdapter(
-    OUT PNDIS_STATUS    Status,
-    OUT PNDIS_STATUS    OpenErrorStatus,
-    OUT PNDIS_HANDLE    NdisBindingHandle,
-    OUT PUINT           SelectedMediumIndex,
-    IN  PNDIS_MEDIUM    MediumArray,
-    IN  UINT            MediumArraySize,
-    IN  NDIS_HANDLE     NdisProtocolHandle,
-    IN  NDIS_HANDLE     ProtocolBindingContext,
-    IN  PNDIS_STRING    AdapterName,
-    IN  UINT            OpenOptions,
-    IN  PSTRING         AddressingInformation);
 
 VOID
 EXPIMP
-NdisOpenProtocolConfiguration(
-    OUT PNDIS_STATUS    Status,
-    OUT PNDIS_HANDLE    ConfigurationHandle,
-    IN  PNDIS_STRING    ProtocolSection);
-
-NDIS_STATUS
-EXPIMP
-NdisQueryReceiveInformation(
-    IN  NDIS_HANDLE NdisBindingHandle,
-    IN  NDIS_HANDLE MacContext,
-    OUT PLONGLONG   TimeSent            OPTIONAL,
-    OUT PLONGLONG   TimeReceived        OPTIONAL,
-    IN  PUCHAR      Buffer,
-    IN  UINT        BufferSize,
-    OUT PUINT       SizeNeeded);
+NdisCloseConfiguration(
+    IN  NDIS_HANDLE ConfigurationHandle);
 
 VOID
 EXPIMP
@@ -2803,58 +2539,6 @@ NdisReadConfiguration(
     IN  PNDIS_STRING                    Keyword,
     IN  NDIS_PARAMETER_TYPE             ParameterType);
 
-VOID
-EXPIMP
-NdisRegisterProtocol(
-    OUT PNDIS_STATUS                    Status,
-    OUT PNDIS_HANDLE                    NdisProtocolHandle,
-    IN  PNDIS_PROTOCOL_CHARACTERISTICS  ProtocolCharacteristics,
-    IN  UINT                            CharacteristicsLength);
-
-VOID
-EXPIMP
-NdisRequest(
-    OUT PNDIS_STATUS    Status,
-    IN  NDIS_HANDLE     NdisBindingHandle,
-    IN  PNDIS_REQUEST   NdisRequest);
-
-VOID
-EXPIMP
-NdisReset(
-    OUT PNDIS_STATUS    Status,
-    IN  NDIS_HANDLE     NdisBindingHandle);
-
-VOID
-EXPIMP
-NdisReturnPackets(
-    IN  PNDIS_PACKET    *PacketsToReturn,
-    IN  UINT            NumberOfPackets);
-
-VOID
-EXPIMP
-NdisSend(
-    OUT PNDIS_STATUS    Status,
-    IN  NDIS_HANDLE     NdisBindingHandle,
-    IN  PNDIS_PACKET    Packet);
-
-VOID
-EXPIMP
-NdisSendPackets(
-    IN  NDIS_HANDLE     NdisBindingHandle,
-    IN  PPNDIS_PACKET   PacketArray,
-    IN  UINT            NumberOfPackets);
-
-VOID
-EXPIMP
-NdisTransferData(
-    OUT PNDIS_STATUS        Status,
-    IN  NDIS_HANDLE         NdisBindingHandle,
-    IN  NDIS_HANDLE         MacReceiveContext,
-    IN  UINT                ByteOffset,
-    IN  UINT                BytesToTransfer,
-    IN  OUT PNDIS_PACKET    Packet,
-    OUT PUINT               BytesTransferred);
-
 VOID
 EXPIMP
 NdisWriteConfiguration(
@@ -3577,11 +3261,87 @@ NdisIMInitializeDeviceInstanceEx(
 
 
 
-/* NDIS structures available only to miniport drivers */
+/* Prototypes for NDIS_MINIPORT_CHARACTERISTICS */
+
+typedef BOOLEAN (*W_CHECK_FOR_HANG_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext);
+
+typedef VOID (*W_DISABLE_INTERRUPT_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext);
+
+typedef VOID (*W_ENABLE_INTERRUPT_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext);
+
+typedef VOID (*W_HALT_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext);
+
+typedef VOID (*W_HANDLE_INTERRUPT_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext);
+
+typedef NDIS_STATUS (*W_INITIALIZE_HANDLER)(
+    OUT PNDIS_STATUS    OpenErrorStatus,
+    OUT PUINT           SelectedMediumIndex,
+    IN  PNDIS_MEDIUM    MediumArray,
+    IN  UINT            MediumArraySize,
+    IN  NDIS_HANDLE     MiniportAdapterContext,
+    IN  NDIS_HANDLE     WrapperConfigurationContext);
+
+typedef VOID (*W_ISR_HANDLER)(
+    OUT PBOOLEAN                               InterruptRecognized,
+    OUT PBOOLEAN                               QueueMiniportHandleInterrupt,
+    IN NDIS_HANDLE                             MiniportAdapterContext);
+
+typedef NDIS_STATUS (*W_QUERY_INFORMATION_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext,
+    IN  NDIS_OID    Oid,
+    IN  PVOID       InformationBuffer,
+    IN  ULONG       InformationBufferLength,
+    OUT PULONG      BytesWritten,
+    OUT PULONG      BytesNeeded);
+
+typedef NDIS_STATUS (*W_RECONFIGURE_HANDLER)(
+    OUT PNDIS_STATUS    OpenErrorStatus,
+    IN  NDIS_HANDLE     MiniportAdapterContext,
+    IN  NDIS_HANDLE        WrapperConfigurationContext);
+
+typedef NDIS_STATUS (*W_RESET_HANDLER)(
+    OUT PBOOLEAN    AddressingReset,
+    IN  NDIS_HANDLE MiniportAdapterContext);
+
+typedef NDIS_STATUS (*W_SEND_HANDLER)(
+    IN  NDIS_HANDLE     MiniportAdapterContext,
+    IN  PNDIS_PACKET    Packet,
+    IN  UINT            Flags);
+
+typedef NDIS_STATUS (*WM_SEND_HANDLER)(
+    IN  NDIS_HANDLE         MiniportAdapterContext,
+    IN  NDIS_HANDLE         NdisLinkHandle,
+    IN  PNDIS_WAN_PACKET    Packet);
+
+typedef NDIS_STATUS (*W_SET_INFORMATION_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterContext,
+    IN  NDIS_OID    Oid,
+    IN  PVOID       InformationBuffer,
+    IN  ULONG       InformationBufferLength,
+    OUT PULONG      BytesRead,
+    OUT PULONG      BytesNeeded);
+
+typedef NDIS_STATUS (*W_TRANSFER_DATA_HANDLER)(
+    OUT PNDIS_PACKET    Packet,
+    OUT PUINT           BytesTransferred,
+    IN  NDIS_HANDLE     MiniportAdapterContext,
+    IN  NDIS_HANDLE     MiniportReceiveContext,
+    IN  UINT            ByteOffset,
+    IN  UINT            BytesToTransfer);
+
+typedef NDIS_STATUS (*WM_TRANSFER_DATA_HANDLER)(
+    VOID);
 
-#if defined(NDIS_WRAPPER) || defined(NDIS_MINIPORT_DRIVER)
 
-/* Obsolete technology specific defines */
+
+/* NDIS structures available only to miniport drivers */
+
+/* Technology specific defines */
 
 #define DECLARE_UNKNOWN_STRUCT(BaseName) \
     typedef struct _##BaseName BaseName, *P##BaseName;
@@ -3592,6 +3352,14 @@ NdisIMInitializeDeviceInstanceEx(
 
 /* ARCnet */
 
+typedef struct _ARC_BUFFER_LIST
+{
+    PVOID                   Buffer;
+    UINT                    Size;
+    UINT                    BytesLeft;
+    struct _ARC_BUFFER_LIST *Next;
+} ARC_BUFFER_LIST, *PARC_BUFFER_LIST;
+
 DECLARE_UNKNOWN_STRUCT(ARC_FILTER)
 
 
@@ -3613,12 +3381,39 @@ ArcFilterDprIndicateReceiveComplete(
 
 #define ETH_LENGTH_OF_ADDRESS   6
 
-DECLARE_UNKNOWN_STRUCT(ETH_FILTER)
+DECLARE_UNKNOWN_STRUCT(ETH_BINDING_INFO);
 
 DECLARE_UNKNOWN_PROTOTYPE(ETH_ADDRESS_CHANGE)
 DECLARE_UNKNOWN_PROTOTYPE(ETH_FILTER_CHANGE)
 DECLARE_UNKNOWN_PROTOTYPE(ETH_DEFERRED_CLOSE)
 
+typedef struct _ETH_FILTER
+{
+    PNDIS_SPIN_LOCK             Lock;
+    CHAR                        (*MCastAddressBuf)[ETH_LENGTH_OF_ADDRESS];
+    struct _NDIS_MINIPORT_BLOCK *Miniport;
+    UINT                        CombinedPacketFilter;
+    PETH_BINDING_INFO           OpenList;
+    ETH_ADDRESS_CHANGE          AddressChangeAction;
+    ETH_FILTER_CHANGE           FilterChangeAction;
+    ETH_DEFERRED_CLOSE          CloseAction;
+    UINT                        MaxMulticastAddresses;
+    UINT                        NumAddresses;
+    UCHAR                       AdapterAddress[ETH_LENGTH_OF_ADDRESS];
+    UINT                        OldCombinedPacketFilter;
+    CHAR                        (*OldMCastAddressBuf)[ETH_LENGTH_OF_ADDRESS];
+    UINT                        OldNumAddresses;
+    PETH_BINDING_INFO           DirectedList;
+    PETH_BINDING_INFO           BMList;
+    PETH_BINDING_INFO           MCastSet;
+#if 0
+#ifdef NDIS_WRAPPER
+       UINT                        NumOpens;
+       NDIS_RW_LOCK                BindListLock;
+#endif
+#endif
+} ETH_FILTER, *PETH_FILTER;
+
 
 NDIS_STATUS
 EXPIMP
@@ -3965,154 +3760,80 @@ TrShouldAddressLoopBack(
 
 
 
-/* Prototypes for NDIS_MINIPORT_CHARACTERISTICS */
+#ifdef _MSC_VER
+typedef struct _NDIS30_MINIPORT_CHARACTERISTICS
+{
+    UCHAR                           MajorNdisVersion;
+    UCHAR                           MinorNdisVersion;
+    UINT                            Reserved;
+    W_CHECK_FOR_HANG_HANDLER        CheckForHangHandler;
+    W_DISABLE_INTERRUPT_HANDLER     DisableInterruptHandler;
+    W_ENABLE_INTERRUPT_HANDLER      EnableInterruptHandler;
+    W_HALT_HANDLER                  HaltHandler;
+    W_HANDLE_INTERRUPT_HANDLER      HandleInterruptHandler;
+    W_INITIALIZE_HANDLER            InitializeHandler;
+    W_ISR_HANDLER                   ISRHandler;
+    W_QUERY_INFORMATION_HANDLER     QueryInformationHandler;
+    W_RECONFIGURE_HANDLER           ReconfigureHandler;
+    W_RESET_HANDLER                 ResetHandler;
+    union
+    {
+        W_SEND_HANDLER              SendHandler;
+        WM_SEND_HANDLER             WanSendHandler;
+    } u1;
+    W_SET_INFORMATION_HANDLER       SetInformationHandler;
+    union
+    {
+        W_TRANSFER_DATA_HANDLER     TransferDataHandler;
+        WM_TRANSFER_DATA_HANDLER    WanTransferDataHandler;
+    } u2;
+} NDIS30_MINIPORT_CHARACTERISTICS;
+typedef NDIS30_MINIPORT_CHARACTERISTICS NDIS30_MINIPORT_CHARACTERISTICS_S;
+#else
+#define NDIS30_MINIPORT_CHARACTERISTICS \
+    UCHAR                           MajorNdisVersion; \
+    UCHAR                           MinorNdisVersion; \
+    UINT                            Reserved; \
+    W_CHECK_FOR_HANG_HANDLER        CheckForHangHandler; \
+    W_DISABLE_INTERRUPT_HANDLER     DisableInterruptHandler; \
+    W_ENABLE_INTERRUPT_HANDLER      EnableInterruptHandler; \
+    W_HALT_HANDLER                  HaltHandler; \
+    W_HANDLE_INTERRUPT_HANDLER      HandleInterruptHandler; \
+    W_INITIALIZE_HANDLER            InitializeHandler; \
+    W_ISR_HANDLER                   ISRHandler; \
+    W_QUERY_INFORMATION_HANDLER     QueryInformationHandler; \
+    W_RECONFIGURE_HANDLER           ReconfigureHandler; \
+    W_RESET_HANDLER                 ResetHandler; \
+    union \
+    { \
+        W_SEND_HANDLER              SendHandler; \
+        WM_SEND_HANDLER             WanSendHandler; \
+    } u1; \
+    W_SET_INFORMATION_HANDLER       SetInformationHandler; \
+    union \
+    { \
+        W_TRANSFER_DATA_HANDLER     TransferDataHandler; \
+        WM_TRANSFER_DATA_HANDLER    WanTransferDataHandler; \
+    } u2; 
+typedef struct _NDIS30_MINIPORT_CHARACTERISTICS_S
+{
+   NDIS30_MINIPORT_CHARACTERISTICS;
+} NDIS30_MINIPORT_CHARACTERISTICS_S, *PSNDIS30_MINIPORT_CHARACTERISTICS_S;
+#endif
 
-typedef BOOLEAN (*W_CHECK_FOR_HANG_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext);
-
-typedef VOID (*W_DISABLE_INTERRUPT_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext);
-
-typedef VOID (*W_ENABLE_INTERRUPT_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext);
-
-typedef VOID (*W_HALT_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext);
-
-typedef VOID (*W_HANDLE_INTERRUPT_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext);
-
-typedef NDIS_STATUS (*W_INITIALIZE_HANDLER)(
-    OUT PNDIS_STATUS    OpenErrorStatus,
-    OUT PUINT           SelectedMediumIndex,
-    IN  PNDIS_MEDIUM    MediumArray,
-    IN  UINT            MediumArraySize,
-    IN  NDIS_HANDLE     MiniportAdapterContext,
-    IN  NDIS_HANDLE     WrapperConfigurationContext);
-
-typedef VOID (*W_ISR_HANDLER)(
-    OUT PBOOLEAN                               InterruptRecognized,
-    OUT PBOOLEAN                               QueueMiniportHandleInterrupt,
-    IN NDIS_HANDLE                             MiniportAdapterContext);
-
-typedef NDIS_STATUS (*W_QUERY_INFORMATION_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext,
-    IN  NDIS_OID    Oid,
-    IN  PVOID       InformationBuffer,
-    IN  ULONG       InformationBufferLength,
-    OUT PULONG      BytesWritten,
-    OUT PULONG      BytesNeeded);
-
-typedef NDIS_STATUS (*W_RECONFIGURE_HANDLER)(
-    OUT PNDIS_STATUS    OpenErrorStatus,
-    IN  NDIS_HANDLE     MiniportAdapterContext,
-    IN  NDIS_HANDLE        WrapperConfigurationContext);
-
-typedef NDIS_STATUS (*W_RESET_HANDLER)(
-    OUT PBOOLEAN    AddressingReset,
-    IN  NDIS_HANDLE MiniportAdapterContext);
-
-typedef NDIS_STATUS (*W_SEND_HANDLER)(
-    IN  NDIS_HANDLE     MiniportAdapterContext,
-    IN  PNDIS_PACKET    Packet,
-    IN  UINT            Flags);
-
-typedef NDIS_STATUS (*WM_SEND_HANDLER)(
-    IN  NDIS_HANDLE         MiniportAdapterContext,
-    IN  NDIS_HANDLE         NdisLinkHandle,
-    IN  PNDIS_WAN_PACKET    Packet);
-
-typedef NDIS_STATUS (*W_SET_INFORMATION_HANDLER)(
-    IN  NDIS_HANDLE MiniportAdapterContext,
-    IN  NDIS_OID    Oid,
-    IN  PVOID       InformationBuffer,
-    IN  ULONG       InformationBufferLength,
-    OUT PULONG      BytesRead,
-    OUT PULONG      BytesNeeded);
+/* Extensions for NDIS 4.0 miniports */
 
-typedef NDIS_STATUS (*W_TRANSFER_DATA_HANDLER)(
-    OUT PNDIS_PACKET    Packet,
-    OUT PUINT           BytesTransferred,
+typedef VOID (*W_SEND_PACKETS_HANDLER)(
     IN  NDIS_HANDLE     MiniportAdapterContext,
-    IN  NDIS_HANDLE     MiniportReceiveContext,
-    IN  UINT            ByteOffset,
-    IN  UINT            BytesToTransfer);
-
-typedef NDIS_STATUS (*WM_TRANSFER_DATA_HANDLER)(
-    VOID);
-
-#if 0
-typedef struct _NDIS30_MINIPORT_CHARACTERISTICS
-{
-    UCHAR                           MajorNdisVersion;
-    UCHAR                           MinorNdisVersion;
-    UINT                            Reserved;
-    W_CHECK_FOR_HANG_HANDLER        CheckForHangHandler;
-    W_DISABLE_INTERRUPT_HANDLER     DisableInterruptHandler;
-    W_ENABLE_INTERRUPT_HANDLER      EnableInterruptHandler;
-    W_HALT_HANDLER                  HaltHandler;
-    W_HANDLE_INTERRUPT_HANDLER      HandleInterruptHandler;
-    W_INITIALIZE_HANDLER            InitializeHandler;
-    W_ISR_HANDLER                   ISRHandler;
-    W_QUERY_INFORMATION_HANDLER     QueryInformationHandler;
-    W_RECONFIGURE_HANDLER           ReconfigureHandler;
-    W_RESET_HANDLER                 ResetHandler;
-    union
-    {
-        W_SEND_HANDLER              SendHandler;
-        WM_SEND_HANDLER             WanSendHandler;
-    } u1;
-    W_SET_INFORMATION_HANDLER       SetInformationHandler;
-    union
-    {
-        W_TRANSFER_DATA_HANDLER     TransferDataHandler;
-        WM_TRANSFER_DATA_HANDLER    WanTransferDataHandler;
-    } u2;
-} NDIS30_MINIPORT_CHARACTERISTICS;
-#else
-#define NDIS30_MINIPORT_CHARACTERISTICS \
-    UCHAR                           MajorNdisVersion; \
-    UCHAR                           MinorNdisVersion; \
-    UINT                            Reserved; \
-    W_CHECK_FOR_HANG_HANDLER        CheckForHangHandler; \
-    W_DISABLE_INTERRUPT_HANDLER     DisableInterruptHandler; \
-    W_ENABLE_INTERRUPT_HANDLER      EnableInterruptHandler; \
-    W_HALT_HANDLER                  HaltHandler; \
-    W_HANDLE_INTERRUPT_HANDLER      HandleInterruptHandler; \
-    W_INITIALIZE_HANDLER            InitializeHandler; \
-    W_ISR_HANDLER                   ISRHandler; \
-    W_QUERY_INFORMATION_HANDLER     QueryInformationHandler; \
-    W_RECONFIGURE_HANDLER           ReconfigureHandler; \
-    W_RESET_HANDLER                 ResetHandler; \
-    union \
-    { \
-        W_SEND_HANDLER              SendHandler; \
-        WM_SEND_HANDLER             WanSendHandler; \
-    } u1; \
-    W_SET_INFORMATION_HANDLER       SetInformationHandler; \
-    union \
-    { \
-        W_TRANSFER_DATA_HANDLER     TransferDataHandler; \
-        WM_TRANSFER_DATA_HANDLER    WanTransferDataHandler; \
-    } u2; 
-typedef struct _NDIS30_MINIPORT_CHARACTERISTICS_S
-{
-   NDIS30_MINIPORT_CHARACTERISTICS;
-} NDIS30_MINIPORT_CHARACTERISTICS_S, *PSNDIS30_MINIPORT_CHARACTERISTICS_S;
-#endif
+    IN  PPNDIS_PACKET   PacketArray,
+    IN  UINT            NumberOfPackets);
 
-/* Extensions for NDIS 4.0 miniports */
 #ifdef NDIS40
 
 typedef VOID (*W_RETURN_PACKET_HANDLER)(
     IN  NDIS_HANDLE     MiniportAdapterContext,
     IN  PNDIS_PACKET    Packet);
 
-typedef VOID (*W_SEND_PACKETS_HANDLER)(
-    IN  NDIS_HANDLE     MiniportAdapterContext,
-    IN  PPNDIS_PACKET   PacketArray,
-    IN  UINT            NumberOfPackets);
-
 typedef VOID (*W_ALLOCATE_COMPLETE_HANDLER)(
     IN  NDIS_HANDLE             MiniportAdapterContext,
     IN  PVOID                   VirtualAddress,
@@ -4120,7 +3841,7 @@ typedef VOID (*W_ALLOCATE_COMPLETE_HANDLER)(
     IN  ULONG                   Length,
     IN  PVOID                   Context);
 
-#if 0
+#ifdef _MSC_VER
 typedef struct _NDIS40_MINIPORT_CHARACTERISTICS
 {
     NDIS30_MINIPORT_CHARACTERISTICS;
@@ -4129,6 +3850,7 @@ typedef struct _NDIS40_MINIPORT_CHARACTERISTICS
     W_SEND_PACKETS_HANDLER      SendPacketsHandler;
     W_ALLOCATE_COMPLETE_HANDLER AllocateCompleteHandler;
 } NDIS40_MINIPORT_CHARACTERISTICS;
+typedef NDIS40_MINIPORT_CHARACTERISTICS NDIS40_MINIPORT_CHARACTERISTICS_S;
 #else
 #define NDIS40_MINIPORT_CHARACTERISTICS \
     NDIS30_MINIPORT_CHARACTERISTICS; \
@@ -4172,7 +3894,7 @@ typedef NDIS_STATUS (*W_CO_REQUEST_HANDLER)(
     IN      NDIS_HANDLE     MiniportVcContext   OPTIONAL,
     IN OUT  PNDIS_REQUEST   NdisRequest);
 
-#if 0
+#ifdef _MSC_VER
 typedef struct _NDIS50_MINIPORT_CHARACTERISTICS
 {
     NDIS40_MINIPORT_CHARACTERISTICS;
@@ -4184,6 +3906,7 @@ typedef struct _NDIS50_MINIPORT_CHARACTERISTICS
     W_CO_SEND_PACKETS_HANDLER   CoSendPacketsHandler;
     W_CO_REQUEST_HANDLER        CoRequestHandler;
 } NDIS50_MINIPORT_CHARACTERISTICS;
+typedef NDIS50_MINIPORT_CHARACTERISTICS NDIS50_MINIPORT_CHARACTERISTICS_S;
 #else
 #define NDIS50_MINIPORT_CHARACTERISTICS \
     NDIS40_MINIPORT_CHARACTERISTICS; \
@@ -4224,58 +3947,842 @@ typedef struct _NDIS_MINIPORT_CHARACTERISTICS
 typedef        NDIS_MINIPORT_CHARACTERISTICS *PNDIS_MINIPORT_CHARACTERISTICS;
 
 
-typedef struct _NDIS_MINIPORT_BLOCK NDIS_MINIPORT_BLOCK, *PNDIS_MINIPORT_BLOCK;
 
+typedef NDIS_STATUS (*SEND_HANDLER)(
+    IN  NDIS_HANDLE     MacBindingHandle,
+    IN  PNDIS_PACKET    Packet);
 
-typedef struct _NDIS_MINIPORT_INTERRUPT
+typedef NDIS_STATUS (*TRANSFER_DATA_HANDLER)(
+    IN  NDIS_HANDLE     MacBindingHandle,
+    IN  NDIS_HANDLE     MacReceiveContext,
+    IN  UINT            ByteOffset,
+    IN  UINT            BytesToTransfer,
+    OUT PNDIS_PACKET    Packet,
+    OUT PUINT           BytesTransferred);
+
+typedef NDIS_STATUS (*RESET_HANDLER)(
+    IN  NDIS_HANDLE MacBindingHandle);
+
+typedef NDIS_STATUS (*REQUEST_HANDLER)(
+    IN  NDIS_HANDLE     MacBindingHandle,
+    IN  PNDIS_REQUEST   NdisRequest);
+
+
+
+/* Structures available only to full MAC drivers */
+
+typedef BOOLEAN (*PNDIS_INTERRUPT_SERVICE)(
+    IN  PVOID   InterruptContext);
+
+typedef VOID (*PNDIS_DEFERRED_PROCESSING)(
+    IN  PVOID   SystemSpecific1,
+    IN  PVOID   InterruptContext,
+    IN  PVOID   SystemSpecific2,
+    IN  PVOID   SystemSpecific3);
+
+
+typedef struct _NDIS_INTERRUPT
 {
     PKINTERRUPT                 InterruptObject;
     KSPIN_LOCK                  DpcCountLock;
-    PVOID                       MiniportIdField;
-    W_ISR_HANDLER               MiniportIsr;
-    W_HANDLE_INTERRUPT_HANDLER  MiniportDpc;
+    PNDIS_INTERRUPT_SERVICE     MacIsr;
+    PNDIS_DEFERRED_PROCESSING   MacDpc;
     KDPC                        InterruptDpc;
-    PNDIS_MINIPORT_BLOCK        Miniport;
-
+    PVOID                       InterruptContext;
     UCHAR                       DpcCount;
-    BOOLEAN                     Filler1;
+    BOOLEAN                     Removing;
+    /* Used to tell when all DPCs for the adapter are completed */
+    KEVENT                                             DpcsCompletedEvent;
+} NDIS_INTERRUPT, *PNDIS_INTERRUPT;
 
-    KEVENT                      DpcsCompletedEvent;
 
-    BOOLEAN                     SharedInterrupt;
-    BOOLEAN                        IsrRequested;
-} NDIS_MINIPORT_INTERRUPT, *PNDIS_MINIPORT_INTERRUPT;
+/* NDIS adapter information */
 
+typedef NDIS_STATUS (*PNDIS_ACTIVATE_CALLBACK)(
+    IN  NDIS_HANDLE NdisAdatperHandle,
+    IN  NDIS_HANDLE MacAdapterContext,
+    IN  ULONG       DmaChannel);
 
-typedef struct _NDIS_MINIPORT_TIMER
+typedef struct _NDIS_PORT_DESCRIPTOR
 {
-    KTIMER                      Timer;
-    KDPC                        Dpc;
-    PNDIS_TIMER_FUNCTION        MiniportTimerFunction;
-    PVOID                       MiniportTimerContext;
-    PNDIS_MINIPORT_BLOCK        Miniport;
-    struct _NDIS_MINIPORT_TIMER *NextDeferredTimer;
-} NDIS_MINIPORT_TIMER, *PNDIS_MINIPORT_TIMER;
+    ULONG   InitialPort;
+    ULONG   NumberOfPorts;
+    PVOID * PortOffset;
+} NDIS_PORT_DESCRIPTOR, *PNDIS_PORT_DESCRIPTOR;
 
+typedef struct _NDIS_ADAPTER_INFORMATION
+{
+    ULONG                   DmaChannel;
+    BOOLEAN                    Master;
+    BOOLEAN                    Dma32BitAddresses;
+    PNDIS_ACTIVATE_CALLBACK ActivateCallback;
+    NDIS_INTERFACE_TYPE     AdapterType;
+    ULONG                   PhysicalMapRegistersNeeded;
+    ULONG                   MaximumPhysicalMapping;
+    ULONG                   NumberOfPortDescriptors;
+    NDIS_PORT_DESCRIPTOR    PortDescriptors[1];
+} NDIS_ADAPTER_INFORMATION, *PNDIS_ADAPTER_INFORMATION;
 
 
-/* NDIS intermediate miniport structures */
+/* Prototypes for NDIS_MAC_CHARACTERISTICS */
 
-typedef VOID (*W_MINIPORT_CALLBACK)(
-    IN  NDIS_HANDLE MiniportAdapterContext,
-    IN  PVOID       CallbackContext);
+typedef NDIS_STATUS (*OPEN_ADAPTER_HANDLER)(
+    OUT PNDIS_STATUS    OpenErrorStatus,
+    OUT NDIS_HANDLE *   MacBindingHandle,
+    OUT PUINT           SelectedMediumIndex,
+    IN  PNDIS_MEDIUM    MediumArray,
+    IN  UINT            MediumArraySize,
+    IN  NDIS_HANDLE     NdisBindingContext,
+    IN  NDIS_HANDLE     MacAdapterContext,
+    IN  UINT            OpenOptions,
+    IN  PSTRING         AddressingInformation OPTIONAL);
 
+typedef NDIS_STATUS (*CLOSE_ADAPTER_HANDLER)(
+    IN  NDIS_HANDLE MacBindingHandle);
 
-/* Routines for NDIS miniport drivers */
+typedef NDIS_STATUS (*WAN_TRANSFER_DATA_HANDLER)(
+    VOID);
 
-VOID
-EXPIMP
-NdisMCloseLog(
-    IN  NDIS_HANDLE LogHandle);
+typedef NDIS_STATUS (*QUERY_GLOBAL_STATISTICS_HANDLER)(
+    IN  NDIS_HANDLE     MacAdapterContext,
+    IN  PNDIS_REQUEST   NdisRequest);
 
-NDIS_STATUS
-EXPIMP
-NdisMCreateLog(
+typedef VOID (*UNLOAD_MAC_HANDLER)(
+    IN  NDIS_HANDLE MacMacContext);
+
+typedef NDIS_STATUS (*ADD_ADAPTER_HANDLER)(
+    IN  NDIS_HANDLE     MacMacContext,
+    IN  NDIS_HANDLE     WrapperConfigurationContext,
+    IN  PNDIS_STRING    AdapterName);
+
+typedef VOID (*REMOVE_ADAPTER_HANDLER)(
+    IN  NDIS_HANDLE MacAdapterContext);
+
+typedef struct _NDIS_MAC_CHARACTERISTICS
+{
+    UCHAR                           MajorNdisVersion;
+    UCHAR                           MinorNdisVersion;
+    UINT                            Reserved;
+    OPEN_ADAPTER_HANDLER            OpenAdapterHandler;
+    CLOSE_ADAPTER_HANDLER           CloseAdapterHandler;
+    SEND_HANDLER                    SendHandler;
+    TRANSFER_DATA_HANDLER           TransferDataHandler;
+    RESET_HANDLER                   ResetHandler;
+    REQUEST_HANDLER                 RequestHandler;
+    QUERY_GLOBAL_STATISTICS_HANDLER QueryGlobalStatisticsHandler;
+    UNLOAD_MAC_HANDLER              UnloadMacHandler;
+    ADD_ADAPTER_HANDLER             AddAdapterHandler;
+    REMOVE_ADAPTER_HANDLER          RemoveAdapterHandler;
+    NDIS_STRING                     Name;
+} NDIS_MAC_CHARACTERISTICS, *PNDIS_MAC_CHARACTERISTICS;
+
+typedef        NDIS_MAC_CHARACTERISTICS        NDIS_WAN_MAC_CHARACTERISTICS;
+typedef        NDIS_WAN_MAC_CHARACTERISTICS    *PNDIS_WAN_MAC_CHARACTERISTICS;
+
+
+
+VOID
+EXPIMP
+NdisAllocateSharedMemory(
+    IN  NDIS_HANDLE             NdisAdapterHandle,
+    IN  ULONG                   Length,
+    IN  BOOLEAN                 Cached,
+    OUT PVOID                   *VirtualAddress,
+    OUT PNDIS_PHYSICAL_ADDRESS  PhysicalAddress);
+
+VOID
+EXPIMP
+NdisCompleteCloseAdapter(
+    IN  NDIS_HANDLE NdisBindingContext,
+    IN  NDIS_STATUS Status);
+
+VOID
+EXPIMP
+NdisCompleteOpenAdapter(
+    IN  NDIS_HANDLE NdisBindingContext,
+    IN  NDIS_STATUS Status,
+    IN  NDIS_STATUS OpenErrorStatus);
+
+NDIS_STATUS
+EXPIMP
+NdisDeregisterAdapter(
+    IN  NDIS_HANDLE NdisAdapterHandle);
+
+VOID
+EXPIMP
+NdisDeregisterAdapterShutdownHandler(
+    IN  NDIS_HANDLE NdisAdapterHandle);
+
+VOID
+EXPIMP
+NdisFreeSharedMemory(
+    IN  NDIS_HANDLE             NdisAdapterHandle,
+    IN  ULONG                   Length,
+    IN  BOOLEAN                 Cached,
+    IN  PVOID                   VirtualAddress,
+    IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress);
+
+VOID
+EXPIMP
+NdisInitializeInterrupt(
+    OUT     PNDIS_STATUS                Status,
+    IN OUT  PNDIS_INTERRUPT             Interrupt,
+    IN      NDIS_HANDLE                 NdisAdapterHandle,
+    IN      PNDIS_INTERRUPT_SERVICE     InterruptServiceRoutine,
+    IN      PVOID                       InterruptContext,
+    IN      PNDIS_DEFERRED_PROCESSING   DeferredProcessingRoutine,
+    IN      UINT                        InterruptVector,
+    IN      UINT                        InterruptLevel,
+    IN      BOOLEAN                     SharedInterrupt,
+    IN      NDIS_INTERRUPT_MODE         InterruptMode);
+
+VOID
+EXPIMP
+NdisMapIoSpace(
+    OUT PNDIS_STATUS            Status,
+    OUT PVOID                   *VirtualAddress,
+    IN  NDIS_HANDLE             NdisAdapterHandle,
+    IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress,
+    IN  UINT                    Length);
+
+NDIS_STATUS
+EXPIMP
+NdisRegisterAdapter(
+    OUT PNDIS_HANDLE    NdisAdapterHandle,
+    IN  NDIS_HANDLE     NdisMacHandle,
+    IN  NDIS_HANDLE     MacAdapterContext,
+    IN  NDIS_HANDLE     WrapperConfigurationContext,
+    IN  PNDIS_STRING    AdapterName,
+    IN  PVOID           AdapterInformation);
+
+VOID
+EXPIMP
+NdisRegisterAdapterShutdownHandler(
+    IN  NDIS_HANDLE                 NdisAdapterHandle,
+    IN  PVOID                       ShutdownContext,
+    IN  ADAPTER_SHUTDOWN_HANDLER    ShutdownHandler);
+
+VOID
+EXPIMP
+NdisRegisterMac(
+    OUT PNDIS_STATUS                Status,
+    OUT PNDIS_HANDLE                NdisMacHandle,
+    IN  NDIS_HANDLE                 NdisWrapperHandle,
+    IN  NDIS_HANDLE                 MacMacContext,
+    IN  PNDIS_MAC_CHARACTERISTICS   MacCharacteristics,
+    IN  UINT                        CharacteristicsLength);
+
+VOID
+EXPIMP
+NdisReleaseAdapterResources(
+    IN  NDIS_HANDLE NdisAdapterHandle);
+
+VOID
+EXPIMP
+NdisRemoveInterrupt(
+    IN  PNDIS_INTERRUPT Interrupt);
+
+
+
+typedef struct _NDIS_MAC_BLOCK      NDIS_MAC_BLOCK,      *PNDIS_MAC_BLOCK;
+typedef struct _NDIS_ADAPTER_BLOCK     NDIS_ADAPTER_BLOCK,  *PNDIS_ADAPTER_BLOCK;
+typedef struct _NDIS_MINIPORT_BLOCK NDIS_MINIPORT_BLOCK, *PNDIS_MINIPORT_BLOCK;
+typedef struct _NDIS_PROTOCOL_BLOCK NDIS_PROTOCOL_BLOCK, *PNDIS_PROTOCOL_BLOCK;
+typedef struct _NDIS_OPEN_BLOCK                NDIS_OPEN_BLOCK,     *PNDIS_OPEN_BLOCK;
+typedef struct _NDIS_M_DRIVER_BLOCK NDIS_M_DRIVER_BLOCK, *PNDIS_M_DRIVER_BLOCK;
+typedef        struct _NDIS_AF_LIST        NDIS_AF_LIST,        *PNDIS_AF_LIST;
+typedef        struct _NULL_FILTER         NULL_FILTER,         *PNULL_FILTER;
+
+
+typedef struct _REFERENCE
+{
+    KSPIN_LOCK  SpinLock;
+    USHORT      ReferenceCount;
+    BOOLEAN     Closing;
+} REFERENCE, *PREFERENCE;
+
+typedef struct _NDIS_MINIPORT_INTERRUPT
+{
+    PKINTERRUPT                 InterruptObject;
+    KSPIN_LOCK                  DpcCountLock;
+    PVOID                       MiniportIdField;
+    W_ISR_HANDLER               MiniportIsr;
+    W_HANDLE_INTERRUPT_HANDLER  MiniportDpc;
+    KDPC                        InterruptDpc;
+    PNDIS_MINIPORT_BLOCK        Miniport;
+
+    UCHAR                       DpcCount;
+    BOOLEAN                     Filler1;
+
+    KEVENT                      DpcsCompletedEvent;
+
+    BOOLEAN                     SharedInterrupt;
+    BOOLEAN                        IsrRequested;
+} NDIS_MINIPORT_INTERRUPT, *PNDIS_MINIPORT_INTERRUPT;
+
+typedef struct _NDIS_MINIPORT_TIMER
+{
+    KTIMER                      Timer;
+    KDPC                        Dpc;
+    PNDIS_TIMER_FUNCTION        MiniportTimerFunction;
+    PVOID                       MiniportTimerContext;
+    PNDIS_MINIPORT_BLOCK        Miniport;
+    struct _NDIS_MINIPORT_TIMER *NextDeferredTimer;
+} NDIS_MINIPORT_TIMER, *PNDIS_MINIPORT_TIMER;
+
+
+typedef struct _MAP_REGISTER_ENTRY
+{
+    PVOID   MapRegister;
+    BOOLEAN WriteToDevice;
+} MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
+
+
+typedef enum _NDIS_WORK_ITEM_TYPE
+{
+    NdisWorkItemRequest,
+    NdisWorkItemSend,
+    NdisWorkItemReturnPackets,
+    NdisWorkItemResetRequested,
+    NdisWorkItemResetInProgress,
+    NdisWorkItemHalt,
+    NdisWorkItemSendLoopback,
+    NdisWorkItemMiniportCallback,
+    NdisMaxWorkItems
+} NDIS_WORK_ITEM_TYPE, *PNDIS_WORK_ITEM_TYPE;
+
+#define        NUMBER_OF_WORK_ITEM_TYPES   NdisMaxWorkItems
+#define        NUMBER_OF_SINGLE_WORK_ITEMS 6
+
+typedef struct _NDIS_MINIPORT_WORK_ITEM
+{
+    SINGLE_LIST_ENTRY   Link;
+    NDIS_WORK_ITEM_TYPE WorkItemType;
+    PVOID               WorkItemContext;
+    BOOLEAN             Allocated;
+    NDIS_HANDLE         Initiator;
+} NDIS_MINIPORT_WORK_ITEM, *PNDIS_MINIPORT_WORK_ITEM;
+
+
+typedef struct _NDIS_BIND_PATHS
+{
+    UINT        Number;
+    NDIS_STRING Paths[1];
+} NDIS_BIND_PATHS, *PNDIS_BIND_PATHS;
+
+typedef struct _FILTERDBS
+{
+    union
+    {
+        PETH_FILTER     EthDB;
+        PNULL_FILTER    NullDB;
+    } u;
+    PTR_FILTER          TrDB;
+    PFDDI_FILTER        FddiDB;
+    PARC_FILTER         ArcDB;
+} FILTERDBS, *PFILTERDBS;
+
+
+typedef VOID (*ETH_RCV_COMPLETE_HANDLER)(
+    IN  PETH_FILTER Filter);
+
+typedef VOID (*ETH_RCV_INDICATE_HANDLER)(
+    IN  PETH_FILTER Filter,
+    IN  NDIS_HANDLE MacReceiveContext,
+    IN  PCHAR       Address,
+    IN  PVOID       HeaderBuffer,
+    IN  UINT        HeaderBufferSize,
+    IN  PVOID       LookaheadBuffer,
+    IN  UINT        LookaheadBufferSize,
+    IN  UINT        PacketSize);
+
+typedef VOID (*FDDI_RCV_COMPLETE_HANDLER)(
+    IN  PFDDI_FILTER    Filter);
+
+typedef VOID (*FDDI_RCV_INDICATE_HANDLER)(
+    IN  PFDDI_FILTER    Filter,
+    IN  NDIS_HANDLE     MacReceiveContext,
+    IN  PCHAR           Address,
+    IN  UINT            AddressLength,
+    IN  PVOID           HeaderBuffer,
+    IN  UINT            HeaderBufferSize,
+    IN  PVOID           LookaheadBuffer,
+    IN  UINT            LookaheadBufferSize,
+    IN  UINT            PacketSize);
+
+typedef VOID (*FILTER_PACKET_INDICATION_HANDLER)(
+    IN  NDIS_HANDLE     Miniport,
+    IN  PPNDIS_PACKET   PacketArray,
+    IN  UINT            NumberOfPackets);
+
+typedef VOID (*TR_RCV_COMPLETE_HANDLER)(
+    IN  PTR_FILTER  Filter);
+
+typedef VOID (*TR_RCV_INDICATE_HANDLER)(
+    IN  PTR_FILTER  Filter,
+    IN  NDIS_HANDLE MacReceiveContext,
+    IN  PVOID       HeaderBuffer,
+    IN  UINT        HeaderBufferSize,
+    IN  PVOID       LookaheadBuffer,
+    IN  UINT        LookaheadBufferSize,
+    IN  UINT        PacketSize);
+
+typedef VOID (*WAN_RCV_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_HANDLE NdisLinkContext);
+
+typedef VOID (*WAN_RCV_HANDLER)(
+    OUT PNDIS_STATUS    Status,
+    IN  NDIS_HANDLE     MiniportAdapterHandle,
+    IN  NDIS_HANDLE     NdisLinkContext,
+    IN  PUCHAR          Packet,
+    IN  ULONG           PacketSize);
+
+typedef VOID (FASTCALL *NDIS_M_DEQUEUE_WORK_ITEM)(
+    IN  PNDIS_MINIPORT_BLOCK    Miniport,
+    IN  NDIS_WORK_ITEM_TYPE     WorkItemType,
+    OUT PVOID                   *WorkItemContext);
+
+typedef VOID (FASTCALL *NDIS_M_PROCESS_DEFERRED)(
+    IN  PNDIS_MINIPORT_BLOCK    Miniport);
+
+typedef NDIS_STATUS (FASTCALL *NDIS_M_QUEUE_NEW_WORK_ITEM)(
+    IN  PNDIS_MINIPORT_BLOCK    Miniport,
+    IN  NDIS_WORK_ITEM_TYPE     WorkItemType,
+    IN  PVOID                   WorkItemContext);
+
+typedef NDIS_STATUS (FASTCALL *NDIS_M_QUEUE_WORK_ITEM)(
+    IN  PNDIS_MINIPORT_BLOCK    Miniport,
+    IN  NDIS_WORK_ITEM_TYPE     WorkItemType,
+    IN  PVOID                   WorkItemContext);
+
+typedef VOID (*NDIS_M_REQ_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status);
+
+typedef VOID (*NDIS_M_RESET_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status,
+    IN  BOOLEAN AddressingReset);
+
+typedef VOID (*NDIS_M_SEND_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE     MiniportAdapterHandle,
+    IN  PNDIS_PACKET    Packet,
+    IN  NDIS_STATUS     Status);
+
+typedef VOID (*NDIS_M_SEND_RESOURCES_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterHandle);
+
+typedef BOOLEAN (FASTCALL *NDIS_M_START_SENDS)(
+    IN  PNDIS_MINIPORT_BLOCK    Miniport);
+
+typedef VOID (*NDIS_M_STATUS_HANDLER)(
+    IN  NDIS_HANDLE MiniportHandle,
+    IN  NDIS_STATUS GeneralStatus,
+    IN  PVOID       StatusBuffer,
+    IN  UINT        StatusBufferSize);
+
+typedef VOID (*NDIS_M_STS_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterHandle);
+
+typedef VOID (*NDIS_M_TD_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE     MiniportAdapterHandle,
+    IN  PNDIS_PACKET    Packet,
+    IN  NDIS_STATUS     Status,
+    IN  UINT            BytesTransferred);
+
+typedef VOID (*NDIS_WM_SEND_COMPLETE_HANDLER)(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  PVOID       Packet,
+    IN  NDIS_STATUS Status);
+
+
+#ifdef NDIS_WRAPPER
+
+#define ARC_SEND_BUFFERS    8
+#define ARC_HEADER_SIZE     4
+
+typedef struct _NDIS_ARC_BUF
+{
+    NDIS_HANDLE ArcnetBufferPool;
+    PUCHAR      ArcnetLookaheadBuffer;
+    UINT        NumFree;
+    ARC_BUFFER_LIST ArcnetBuffers[ARC_SEND_BUFFERS];
+} NDIS_ARC_BUF, *PNDIS_ARC_BUF;
+
+#define NDIS_MINIPORT_WORK_QUEUE_SIZE 10
+
+typedef struct _NDIS_LOG
+{
+    PNDIS_MINIPORT_BLOCK    Miniport;
+    KSPIN_LOCK              LogLock;
+    PIRP                    Irp;
+    UINT                    TotalSize;
+    UINT                    CurrentSize;
+    UINT                    InPtr;
+    UINT                    OutPtr;
+    UCHAR                   LogBuf[1];
+} NDIS_LOG, *PNDIS_LOG;
+
+#endif /* NDIS_WRAPPER */
+
+
+struct _NDIS_ADAPTER_BLOCK
+{
+    PDEVICE_OBJECT          DeviceObject;
+    PNDIS_MAC_BLOCK         MacHandle;
+    NDIS_HANDLE             MacAdapterContext;
+    NDIS_STRING             AdapterName;
+    PNDIS_OPEN_BLOCK        OpenQueue;
+    PNDIS_ADAPTER_BLOCK     NextAdapter;
+    REFERENCE               Ref;
+    PVOID                   BusDataContext;
+    BOOLEAN                 BeingRemoved;
+    UCHAR                   Flags;
+    PCM_RESOURCE_LIST       Resources;
+    PNDIS_STRING            pAdapterInstanceName;
+    PVOID                   WrapperContext;
+
+    ULONG                   BusNumber;
+    NDIS_INTERFACE_TYPE     BusType;
+    ULONG                   ChannelNumber;
+    NDIS_INTERFACE_TYPE     AdapterType;
+    BOOLEAN                 Master;
+    UCHAR                   AssignedProcessor;
+    ULONG                   PhysicalMapRegistersNeeded;
+    ULONG                   MaximumPhysicalMapping;
+    ULONG                   InitialPort;
+    ULONG                   NumberOfPorts;
+    PUCHAR                  InitialPortMapping;
+    BOOLEAN                 InitialPortMapped;
+    PUCHAR                  PortOffset;
+    PMAP_REGISTER_ENTRY     MapRegisters;
+
+    KEVENT                  AllocationEvent;
+    UINT                    CurrentMapRegister;
+    PADAPTER_OBJECT         SystemAdapterObject;
+#if 0
+#ifdef NDIS_WRAPPER
+    ULONG                   BusId;
+    ULONG                   SlotNumber;
+    NDIS_STRING             BaseName;
+    PDEVICE_OBJECT          PhysicalDeviceObject;
+    PDEVICE_OBJECT          NextDeviceObject;
+    PCM_RESOURCE_LIST       AllocatedResources;
+    PCM_RESOURCE_LIST       AllocatedResourcesTranslated;
+    NDIS_EVENT              OpenReadyEvent;
+    NDIS_PNP_DEVICE_STATE   PnPDeviceState;
+    PGET_SET_DEVICE_DATA    SetBusData;
+    PGET_SET_DEVICE_DATA    GetBusData;
+    POID_LIST               OidList;
+    ULONG                   PnPCapabilities;
+#endif /* NDIS_WRAPPER */
+#endif
+};
+
+
+struct _NDIS_MINIPORT_BLOCK
+{
+    ULONG                       NullValue;
+    PNDIS_MINIPORT_BLOCK        NextMiniport;
+    PNDIS_M_DRIVER_BLOCK        DriverHandle;
+    NDIS_HANDLE                        MiniportAdapterContext;
+    UNICODE_STRING              MiniportName;
+    PNDIS_BIND_PATHS            BindPaths;
+    NDIS_HANDLE                        OpenQueue;
+    REFERENCE                   Ref;
+    NDIS_HANDLE                        DeviceContext;
+    UCHAR                       Padding1;
+
+    UCHAR                       LockAcquired;
+    UCHAR                       PmodeOpens;
+    UCHAR                       AssignedProcessor;
+    KSPIN_LOCK                  Lock;
+    PNDIS_REQUEST               MediaRequest;
+    PNDIS_MINIPORT_INTERRUPT    Interrupt;
+    ULONG                       Flags;
+    ULONG                       PnPFlags;
+
+    LIST_ENTRY                 PacketList;
+    PNDIS_PACKET                FirstPendingPacket;
+    PNDIS_PACKET                ReturnPacketsQueue;
+    ULONG                       RequestBuffer;
+    PVOID                       SetMCastBuffer;
+    PNDIS_MINIPORT_BLOCK        PrimaryMiniport;
+    PVOID                       WrapperContext;
+
+    PVOID                       BusDataContext;
+    ULONG                       PnPCapabilities;
+    PCM_RESOURCE_LIST           Resources;
+    NDIS_TIMER                  WakeUpDpcTimer;
+    UNICODE_STRING              BaseName;
+    UNICODE_STRING              SymbolicLinkName;
+
+    ULONG                       CheckForHangSeconds;
+    USHORT                      CFHangTicks;
+    USHORT                      CFHangCurrentTick;
+    NDIS_STATUS                        ResetStatus;
+    NDIS_HANDLE                        ResetOpen;
+    FILTERDBS                   FilterDbs;
+
+    FILTER_PACKET_INDICATION_HANDLER    PacketIndicateHandler;
+    NDIS_M_SEND_COMPLETE_HANDLER        SendCompleteHandler;
+    NDIS_M_SEND_RESOURCES_HANDLER       SendResourcesHandler;
+    NDIS_M_RESET_COMPLETE_HANDLER       ResetCompleteHandler;
+
+    NDIS_MEDIUM                        MediaType;
+    ULONG                       BusNumber;
+    NDIS_INTERFACE_TYPE         BusType;
+    NDIS_INTERFACE_TYPE                AdapterType;
+    PDEVICE_OBJECT              DeviceObject;
+    PDEVICE_OBJECT              PhysicalDeviceObject;
+    PDEVICE_OBJECT              NextDeviceObject;
+
+    PMAP_REGISTER_ENTRY         MapRegisters;
+    PNDIS_AF_LIST               CallMgrAfList;
+    PVOID                       MiniportThread;
+    PVOID                       SetInfoBuf;
+    USHORT                      SetInfoBufLen;
+    USHORT                      MaxSendPackets;
+    NDIS_STATUS                        FakeStatus;
+    PVOID                       LockHandler;
+    PUNICODE_STRING                pAdapterInstanceName;
+    PADAPTER_OBJECT             SystemAdapterObject;
+    UINT                        MacOptions;
+    PNDIS_REQUEST               PendingRequest;
+    UINT                        MaximumLongAddresses;
+    UINT                        MaximumShortAddresses;
+    UINT                        CurrentLookahead;
+    UINT                        MaximumLookahead;
+
+    W_HANDLE_INTERRUPT_HANDLER  HandleInterruptHandler;
+    W_DISABLE_INTERRUPT_HANDLER DisableInterruptHandler;
+    W_ENABLE_INTERRUPT_HANDLER  EnableInterruptHandler;
+    W_SEND_PACKETS_HANDLER      SendPacketsHandler;
+    NDIS_M_START_SENDS          DeferredSendHandler;
+
+    ETH_RCV_INDICATE_HANDLER    EthRxIndicateHandler;
+    TR_RCV_INDICATE_HANDLER        TrRxIndicateHandler;
+    FDDI_RCV_INDICATE_HANDLER   FddiRxIndicateHandler;
+
+    ETH_RCV_COMPLETE_HANDLER    EthRxCompleteHandler;
+    TR_RCV_COMPLETE_HANDLER        TrRxCompleteHandler;
+    FDDI_RCV_COMPLETE_HANDLER   FddiRxCompleteHandler;
+
+    NDIS_M_STATUS_HANDLER       StatusHandler;
+    NDIS_M_STS_COMPLETE_HANDLER StatusCompleteHandler;
+    NDIS_M_TD_COMPLETE_HANDLER  TDCompleteHandler;
+    NDIS_M_REQ_COMPLETE_HANDLER QueryCompleteHandler;
+    NDIS_M_REQ_COMPLETE_HANDLER SetCompleteHandler;
+
+    NDIS_WM_SEND_COMPLETE_HANDLER   WanSendCompleteHandler;
+    WAN_RCV_HANDLER                 WanRcvHandler;
+    WAN_RCV_COMPLETE_HANDLER        WanRcvCompleteHandler;
+#if 0
+#ifdef NDIS_WRAPPER
+    SINGLE_LIST_ENTRY           WorkQueue[NUMBER_OF_WORK_ITEM_TYPES];
+    SINGLE_LIST_ENTRY           SingleWorkItems[NUMBER_OF_SINGLE_WORK_ITEMS];
+    PNDIS_MAC_BLOCK                FakeMac;
+    UCHAR                       SendFlags;
+    UCHAR                       TrResetRing;
+    UCHAR                       ArcnetAddress;
+
+    union
+    {
+        PNDIS_ARC_BUF           ArcBuf;
+        PVOID                   BusInterface;
+    } u1;
+
+    ULONG                       ChannelNumber;
+    PNDIS_LOG                   Log;
+    ULONG                       BusId;
+    ULONG                       SlotNumber;
+    PCM_RESOURCE_LIST           AllocatedResources;
+    PCM_RESOURCE_LIST           AllocatedResourcesTranslated;
+    SINGLE_LIST_ENTRY           PatternList;
+    NDIS_PNP_CAPABILITIES       PMCapabilities;
+#if 0
+    DEVICE_CAPABILITIES                DeviceCaps;
+#endif
+    ULONG                       WakeUpEnable;
+#if 0
+    DEVICE_POWER_STATE          CurrentDeviceState;
+#endif
+    PIRP                        pIrpWaitWake;
+#if 0
+    SYSTEM_POWER_STATE          WaitWakeSystemState;
+#endif
+    LARGE_INTEGER               VcIndex;
+    KSPIN_LOCK                 VcCountLock;
+    LIST_ENTRY                  WmiEnabledVcs;
+    PNDIS_GUID                  pNdisGuidMap;
+    PNDIS_GUID                  pCustomGuidMap;
+    USHORT                      VcCount;
+    USHORT                      cNdisGuidMap;
+    USHORT                      cCustomGuidMap;
+    USHORT                      CurrentMapRegister;
+    PKEVENT                     AllocationEvent;
+    USHORT                      PhysicalMapRegistersNeeded;
+    USHORT                      SGMapRegistersNeeded;
+    ULONG                       MaximumPhysicalMapping;
+
+    NDIS_TIMER                  MediaDisconnectTimer;
+    USHORT                      MediaDisconnectTimeOut;
+    USHORT                      InstanceNumber;
+    NDIS_EVENT                  OpenReadyEvent;
+    NDIS_PNP_DEVICE_STATE       PnPDeviceState;
+    NDIS_PNP_DEVICE_STATE       OldPnPDeviceState;
+#if 0
+    PGET_SET_DEVICE_DATA        SetBusData;
+    PGET_SET_DEVICE_DATA        GetBusData;
+#endif
+    POID_LIST                   OidList;
+    KDPC                        DeferredDpc;
+#if 0
+    NDIS_STATS                  NdisStats;
+#endif
+    PNDIS_PACKET                IndicatedPacket[MAXIMUM_PROCESSORS];
+    PKEVENT                        RemoveReadyEvent;
+    PKEVENT                        AllOpensClosedEvent;
+    PKEVENT                     AllRequestsCompletedEvent;
+    ULONG                       InitTimeMs;
+    NDIS_MINIPORT_WORK_ITEM     WorkItemBuffer[NUMBER_OF_SINGLE_WORK_ITEMS];
+    PNDIS_MINIPORT_TIMER        TimerQueue;
+       ULONG                       DriverVerifyFlags;
+
+    PNDIS_MINIPORT_BLOCK        NextGlobalMiniport;
+       USHORT                      InternalResetCount;
+    USHORT                      MiniportResetCount;
+    USHORT                      MediaSenseConnectCount;
+    USHORT                      MediaSenseDisconnectCount;
+    PNDIS_PACKET                *xPackets;
+    ULONG                       UserModeOpenReferences;
+#endif /* NDIS_WRAPPER */
+#endif
+};
+
+
+/* Handler prototypes for NDIS_OPEN_BLOCK */
+
+typedef NDIS_STATUS (*WAN_SEND_HANDLER)(
+    IN  NDIS_HANDLE MacBindingHandle,
+    IN  NDIS_HANDLE LinkHandle,
+    IN  PVOID       Packet);
+
+/* NDIS 4.0 extension */
+
+typedef VOID (*SEND_PACKETS_HANDLER)(
+    IN  NDIS_HANDLE     MiniportAdapterContext,
+    IN  PPNDIS_PACKET   PacketArray,
+    IN  UINT            NumberOfPackets);
+
+
+struct _NDIS_OPEN_BLOCK
+{
+    PNDIS_MAC_BLOCK             MacHandle;
+    NDIS_HANDLE                 MacBindingHandle;
+    PNDIS_ADAPTER_BLOCK         AdapterHandle;
+    PNDIS_PROTOCOL_BLOCK        ProtocolHandle;
+    NDIS_HANDLE                        ProtocolBindingContext;
+    PNDIS_OPEN_BLOCK            AdapterNextOpen;
+    PNDIS_OPEN_BLOCK            ProtocolNextOpen;
+    PNDIS_OPEN_BLOCK            NextGlobalOpen;
+    BOOLEAN                     Closing;
+    BOOLEAN                        Unbinding;
+    BOOLEAN                     NoProtRsvdOnRcvPkt;
+    BOOLEAN                     ProcessingOpens;
+    PNDIS_STRING                BindDeviceName;
+    KSPIN_LOCK                  SpinLock;
+    PNDIS_STRING                RootDeviceName;
+
+    union
+    {
+        SEND_HANDLER            SendHandler;
+        WAN_SEND_HANDLER        WanSendHandler;
+    } u1;
+    TRANSFER_DATA_HANDLER       TransferDataHandler;
+
+    SEND_COMPLETE_HANDLER       SendCompleteHandler;
+    TRANSFER_DATA_COMPLETE_HANDLER  TransferDataCompleteHandler;
+    RECEIVE_HANDLER             ReceiveHandler;
+    RECEIVE_COMPLETE_HANDLER    ReceiveCompleteHandler;
+
+    union
+    {
+        RECEIVE_HANDLER                PostNt31ReceiveHandler;
+        WAN_RECEIVE_HANDLER     WanReceiveHandler;
+    } u2;
+    RECEIVE_COMPLETE_HANDLER    PostNt31ReceiveCompleteHandler;
+
+    RECEIVE_PACKET_HANDLER      ReceivePacketHandler;
+    SEND_PACKETS_HANDLER        SendPacketsHandler;
+
+    RESET_HANDLER               ResetHandler;
+    REQUEST_HANDLER                RequestHandler;
+    RESET_COMPLETE_HANDLER      ResetCompleteHandler;
+    STATUS_HANDLER              StatusHandler;
+    STATUS_COMPLETE_HANDLER     StatusCompleteHandler;
+    REQUEST_COMPLETE_HANDLER    RequestCompleteHandler;
+};
+
+
+
+/* Routines for NDIS miniport drivers */
+
+VOID
+EXPIMP
+NdisInitializeWrapper(
+    OUT PNDIS_HANDLE    NdisWrapperHandle,
+    IN  PVOID           SystemSpecific1,
+    IN  PVOID           SystemSpecific2,
+    IN  PVOID           SystemSpecific3);
+
+NDIS_STATUS
+EXPIMP
+NdisMAllocateMapRegisters(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  UINT        DmaChannel,
+    IN  BOOLEAN     Dma32BitAddresses,
+    IN  ULONG       PhysicalMapRegistersNeeded,
+    IN  ULONG       MaximumPhysicalMapping);
+
+/*
+ * VOID NdisMArcIndicateReceive(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle,
+ *     IN  PUCHAR      HeaderBuffer,
+ *     IN  PUCHAR      DataBuffer,
+ *     IN  UINT        Length);
+ */
+#define NdisMArcIndicateReceive(MiniportAdapterHandle, \
+                                HeaderBuffer,          \
+                                DataBuffer,            \
+                                Length)                \
+{                                                      \
+    ArcFilterDprIndicateReceive(                       \
+        (((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->FilterDbs.ArcDB), \
+        (HeaderBuffer), \
+        (DataBuffer),   \
+        (Length));      \
+}
+
+/*
+ * VOID NdisMArcIndicateReceiveComplete(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle);
+ */
+#define NdisMArcIndicateReceiveComplete(MiniportAdapterHandle) \
+{                                                              \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->ArcRxCompleteHandler)( \
+        ((PNDIS_MINIPORT_BLOCK)MiniportAdapterHandle)->FilterDbs.ArcDB);      \
+}
+
+VOID
+EXPIMP
+NdisMCloseLog(
+    IN  NDIS_HANDLE LogHandle);
+
+NDIS_STATUS
+EXPIMP
+NdisMCreateLog(
     IN  NDIS_HANDLE     MiniportAdapterHandle,
     IN  UINT            Size,
     OUT PNDIS_HANDLE    LogHandle);
@@ -4285,11 +4792,110 @@ EXPIMP
 NdisMDeregisterAdapterShutdownHandler(
     IN  NDIS_HANDLE MiniportHandle);
 
+VOID
+EXPIMP
+NdisMDeregisterInterrupt(
+    IN  PNDIS_MINIPORT_INTERRUPT    Interrupt);
+
+VOID
+EXPIMP
+NdisMDeregisterIoPortRange(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  UINT        InitialPort,
+    IN  UINT        NumberOfPorts,
+    IN  PVOID       PortOffset);
+
+/*
+ * VOID NdisMEthIndicateReceive(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle,
+ *     IN  NDIS_HANDLE MiniportReceiveContext,
+ *     IN  PVOID       HeaderBuffer,
+ *     IN  UINT        HeaderBufferSize,
+ *     IN  PVOID       LookaheadBuffer,
+ *     IN  UINT        LookaheadBufferSize,
+ *     IN  UINT        PacketSize);
+ */
+#define NdisMEthIndicateReceive(MiniportAdapterHandle,  \
+                                MiniportReceiveContext, \
+                                HeaderBuffer,           \
+                                HeaderBufferSize,       \
+                                LookaheadBuffer,        \
+                                LookaheadBufferSize,    \
+                                PacketSize)             \
+{                                                       \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->EthRxIndicateHandler)( \
+        (((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->FilterDbs.u.EthDB), \
+               (MiniportReceiveContext), \
+               (HeaderBuffer),           \
+               (HeaderBuffer),           \
+               (HeaderBufferSize),       \
+               (LookaheadBuffer),        \
+               (LookaheadBufferSize),    \
+               (PacketSize));            \
+}
+
+/*
+ * VOID NdisMEthIndicateReceiveComplete(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle);
+ */
+#define NdisMEthIndicateReceiveComplete(MiniportAdapterHandle) \
+{                                                              \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->EthRxCompleteHandler)( \
+        ((PNDIS_MINIPORT_BLOCK)MiniportAdapterHandle)->FilterDbs.u.EthDB);    \
+}
+
+/*
+ * VOID NdisMFddiIndicateReceive(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle,
+ *     IN  NDIS_HANDLE MiniportReceiveContext,
+ *     IN  PVOID       HeaderBuffer,
+ *     IN  UINT        HeaderBufferSize,
+ *     IN  PVOID       LookaheadBuffer,
+ *     IN  UINT        LookaheadBufferSize,
+ *     IN  UINT        PacketSize);
+ */
+#define NdisMFddiIndicateReceive(MiniportAdapterHandle,  \
+                                 MiniportReceiveContext, \
+                                 HeaderBuffer,           \
+                                 HeaderBufferSize,       \
+                                 LookaheadBuffer,        \
+                                 LookaheadBufferSize,    \
+                                 PacketSize)             \
+{                                                        \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->FddiRxIndicateHandler)( \
+        (((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->FilterDbs.FddiDB),   \
+        (MiniportReceiveContext),              \
+        (PUCHAR)(HeaderBuffer) + 1,            \
+        (((*(PUCHAR*)(HeaderBuffer)) & 0x40) ? \
+            FDDI_LENGTH_OF_LONG_ADDRESS :      \
+                   FDDI_LENGTH_OF_SHORT_ADDRESS),     \
+        (HeaderBuffer),                        \
+        (HeaderBufferSize),                    \
+        (LookaheadBuffer),                     \
+        (LookaheadBufferSize),                 \
+        (PacketSize));                         \
+}
+
+/*
+ * VOID NdisMFddiIndicateReceiveComplete(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle);
+ */
+#define NdisMFddiIndicateReceiveComplete(MiniportAdapterHandle) \
+{                                                               \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->FddiRxCompleteHandler)( \
+        ((PNDIS_MINIPORT_BLOCK)MiniportAdapterHandle)->FilterDbs.FddiDB);      \
+}
+
 VOID
 EXPIMP
 NdisMFlushLog(
     IN  NDIS_HANDLE LogHandle);
 
+VOID
+EXPIMP
+NdisMFreeMapRegisters(
+    IN  NDIS_HANDLE MiniportAdapterHandle);
+
 VOID
 EXPIMP
 NdisMIndicateStatus(
@@ -4303,23 +4909,35 @@ EXPIMP
 NdisMIndicateStatusComplete(
     IN  NDIS_HANDLE MiniportAdapterHandle);
 
-VOID
-EXPIMP
-NdisInitializeWrapper(
-    OUT PNDIS_HANDLE    NdisWrapperHandle,
-    IN  PVOID           SystemSpecific1,
-    IN  PVOID           SystemSpecific2,
-    IN  PVOID           SystemSpecific3);
-
 /*
  * VOID NdisMInitializeWrapper(
- *    OUT PNDIS_HANDLE    NdisWrapperHandle,
- *    IN  PVOID           SystemSpecific1,
- *    IN  PVOID           SystemSpecific2,
- *    IN  PVOID           SystemSpecific3);
+ *     OUT PNDIS_HANDLE    NdisWrapperHandle,
+ *     IN  PVOID           SystemSpecific1,
+ *     IN  PVOID           SystemSpecific2,
+ *     IN  PVOID           SystemSpecific3);
  */
-#define NdisMInitializeWrapper(n, s1, s2, s3) \
-    NdisInitializeWrapper((n),(s1),(s2),(s3))
+#define NdisMInitializeWrapper(NdisWrapperHandle, \
+                               SystemSpecific1,   \
+                               SystemSpecific2,   \
+                               SystemSpecific3)   \
+    NdisInitializeWrapper((NdisWrapperHandle),    \
+                          (SystemSpecific1),      \
+                          (SystemSpecific2),      \
+                          (SystemSpecific3))
+
+NDIS_STATUS
+EXPIMP
+NdisMMapIoSpace(
+    OUT PVOID *                 VirtualAddress,
+    IN  NDIS_HANDLE             MiniportAdapterHandle,
+    IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress,
+    IN  UINT                    Length);
+
+VOID
+EXPIMP
+NdisMQueryInformationComplete(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status);
 
 VOID
 EXPIMP
@@ -4328,6 +4946,25 @@ NdisMRegisterAdapterShutdownHandler(
     IN  PVOID                       ShutdownContext,
     IN  ADAPTER_SHUTDOWN_HANDLER    ShutdownHandler);
 
+NDIS_STATUS
+EXPIMP
+NdisMRegisterInterrupt(
+    OUT PNDIS_MINIPORT_INTERRUPT    Interrupt,
+    IN  NDIS_HANDLE                 MiniportAdapterHandle,
+    IN  UINT                        InterruptVector,
+    IN  UINT                        InterruptLevel,
+    IN  BOOLEAN                            RequestIsr,
+    IN  BOOLEAN                     SharedInterrupt,
+    IN  NDIS_INTERRUPT_MODE         InterruptMode);
+
+NDIS_STATUS
+EXPIMP
+NdisMRegisterIoPortRange(
+    OUT PVOID *     PortOffset,
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  UINT        InitialPort,
+    IN  UINT        NumberOfPorts);
+
 NDIS_STATUS
 EXPIMP
 NdisMRegisterMiniport(
@@ -4335,24 +4972,65 @@ NdisMRegisterMiniport(
     IN  PNDIS_MINIPORT_CHARACTERISTICS  MiniportCharacteristics,
     IN  UINT                            CharacteristicsLength);
 
-VOID
-EXPIMP
-NdisMResetComplete(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  NDIS_STATUS Status,
-    IN  BOOLEAN     AddressingReset);
 
-VOID
-EXPIMP
-NdisMSendComplete(
-    IN  NDIS_HANDLE     MiniportAdapterHandle,
-    IN  PNDIS_PACKET    Packet,
-    IN  NDIS_STATUS     Status);
+#ifndef NDIS_WRAPPER
+
+/*
+ * VOID NdisMResetComplete(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle,
+ *     IN  NDIS_STATUS Status,
+ *     IN  BOOLEAN     AddressingReset);
+ */
+#define        NdisMResetComplete(MiniportAdapterHandle, \
+                           Status,                \
+                           AddressingReset)       \
+{                                                 \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->ResetCompleteHandler)( \
+        MiniportAdapterHandle, Status, AddressingReset); \
+}
+
+/*
+ * VOID NdisMSendComplete(
+ *     IN  NDIS_HANDLE     MiniportAdapterHandle,
+ *     IN  PNDIS_PACKET    Packet,
+ *     IN  NDIS_STATUS     Status);
+ */
+#define        NdisMSendComplete(MiniportAdapterHandle, \
+                          Packet,                \
+                          Status)                \
+{                                                \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->SendCompleteHandler)( \
+        MiniportAdapterHandle, Packet, Status);  \
+}
+
+/*
+ * VOID NdisMSendResourcesAvailable(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle);
+ */
+#define        NdisMSendResourcesAvailable(MiniportAdapterHandle) \
+{                                                \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->SendResourcesHandler)( \
+        MiniportAdapterHandle); \
+}
+
+/*
+ * VOID NdisMTransferDataComplete(
+ *     IN  NDIS_HANDLE     MiniportAdapterHandle,
+ *     IN  PNDIS_PACKET    Packet,
+ *     IN  NDIS_STATUS     Status,
+ *     IN  UINT            BytesTransferred);
+ */
+#define        NdisMTransferDataComplete(MiniportAdapterHandle, \
+                                  Packet,                \
+                                  Status,                \
+                                  BytesTransferred)      \
+{                                                        \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->TDCompleteHandler)( \
+        MiniportAdapterHandle, Packet, Status, BytesTransferred)           \
+}
+
+#endif /* NDIS_WRAPPER */
 
-VOID
-EXPIMP
-NdisMSendResourcesAvailable(
-    IN  NDIS_HANDLE MiniportAdapterHandle);
 
 VOID
 EXPIMP
@@ -4371,6 +5049,12 @@ NdisMSetAttributesEx(
     IN  ULONG               AttributeFlags,
     IN  NDIS_INTERFACE_TYPE AdapterType); 
 
+VOID
+EXPIMP
+NdisMSetInformationComplete(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  NDIS_STATUS Status);
+
 VOID
 EXPIMP
 NdisMSleep(
@@ -4383,6 +5067,45 @@ NdisMSynchronizeWithInterrupt(
     IN  PVOID                       SynchronizeFunction,
     IN  PVOID                       SynchronizeContext);
 
+/*
+ * VOID NdisMTrIndicateReceive(
+ *     IN  NDIS_HANDLE MiniportAdapterHandle,
+ *     IN  NDIS_HANDLE MiniportReceiveContext,
+ *     IN  PVOID       HeaderBuffer,
+ *     IN  UINT        HeaderBufferSize,
+ *     IN  PVOID       LookaheadBuffer,
+ *     IN  UINT        LookaheadBufferSize,
+ *     IN  UINT        PacketSize);
+ */
+#define NdisMTrIndicateReceive(MiniportAdapterHandle,  \
+                               MiniportReceiveContext, \
+                               HeaderBuffer,           \
+                               HeaderBufferSize,       \
+                               LookaheadBuffer,        \
+                               LookaheadBufferSize,    \
+                               PacketSize)             \
+{                                                      \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->TrRxIndicateHandler)( \
+        (((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->FilterDbs.TrDB),   \
+               (MiniportReceiveContext), \
+               (HeaderBuffer),           \
+               (HeaderBuffer),           \
+               (HeaderBufferSize),       \
+               (LookaheadBuffer),        \
+               (LookaheadBufferSize),    \
+               (PacketSize));            \
+}
+
+/*
+ * VOID NdisMTrIndicateReceiveComplete(
+ *     IN  NDIS_HANDLE  MiniportAdapterHandle);
+ */
+#define NdisMTrIndicateReceiveComplete(MiniportAdapterHandle) \
+{                                                             \
+    (*((PNDIS_MINIPORT_BLOCK)(MiniportAdapterHandle))->TrRxCompleteHandler)( \
+        ((PNDIS_MINIPORT_BLOCK)MiniportAdapterHandle)->FilterDbs.TrDB);      \
+}
+
 NDIS_STATUS
 EXPIMP
 NdisMWriteLogData(
@@ -4390,12 +5113,35 @@ NdisMWriteLogData(
     IN  PVOID       LogBuffer,
     IN  UINT        LogBufferSize);
 
+VOID
+EXPIMP
+NdisMQueryAdapterResources(
+    OUT PNDIS_STATUS        Status,
+    IN  NDIS_HANDLE         WrapperConfigurationContext,
+    OUT PNDIS_RESOURCE_LIST ResourceList,
+    IN  OUT PUINT           BufferSize);
+
 VOID
 EXPIMP
 NdisTerminateWrapper(
     IN  NDIS_HANDLE NdisWrapperHandle,
     IN  PVOID       SystemSpecific);
 
+VOID
+EXPIMP
+NdisMUnmapIoSpace(
+    IN  NDIS_HANDLE MiniportAdapterHandle,
+    IN  PVOID       VirtualAddress,
+    IN  UINT        Length);
+
+
+
+/* NDIS intermediate miniport structures */
+
+typedef VOID (*W_MINIPORT_CALLBACK)(
+    IN  NDIS_HANDLE MiniportAdapterContext,
+    IN  PVOID       CallbackContext);
+
 
 
 /* Routines for intermediate miniport drivers */
@@ -4439,89 +5185,6 @@ NdisIMSwitchToMiniport(
     OUT PNDIS_HANDLE    SwitchHandle);
 
 
-VOID
-EXPIMP
-NdisMSetResetTimeout(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  UINT        TimeInSeconds);
-
-NDIS_STATUS
-EXPIMP
-NdisMAllocateMapRegisters(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  UINT        DmaChannel,
-    IN  BOOLEAN     Dma32BitAddresses,
-    IN  ULONG       PhysicalMapRegistersNeeded,
-    IN  ULONG       MaximumPhysicalMapping);
-
-VOID
-EXPIMP
-NdisMFreeMapRegisters(
-    IN  NDIS_HANDLE MiniportAdapterHandle);
-
-NDIS_STATUS
-EXPIMP
-NdisMRegisterIoPortRange(
-    OUT PVOID *     PortOffset,
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  UINT        InitialPort,
-    IN  UINT        NumberOfPorts);
-
-VOID
-EXPIMP
-NdisMDeregisterIoPortRange(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  UINT        InitialPort,
-    IN  UINT        NumberOfPorts,
-    IN  PVOID       PortOffset);
-
-NDIS_STATUS
-EXPIMP
-NdisMMapIoSpace(
-    OUT PVOID *                 VirtualAddress,
-    IN  NDIS_HANDLE             MiniportAdapterHandle,
-    IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress,
-    IN  UINT                    Length);
-
-VOID
-EXPIMP
-NdisMUnmapIoSpace(
-    IN  NDIS_HANDLE MiniportAdapterHandle,
-    IN  PVOID       VirtualAddress,
-    IN  UINT        Length);
-
-NDIS_STATUS
-EXPIMP
-NdisMRegisterInterrupt(
-    OUT PNDIS_MINIPORT_INTERRUPT    Interrupt,
-    IN  NDIS_HANDLE                 MiniportAdapterHandle,
-    IN  UINT                        InterruptVector,
-    IN  UINT                        InterruptLevel,
-    IN  BOOLEAN                            RequestIsr,
-    IN  BOOLEAN                     SharedInterrupt,
-    IN  NDIS_INTERRUPT_MODE         InterruptMode);
-
-VOID
-EXPIMP
-NdisMDeregisterInterrupt(
-    IN  PNDIS_MINIPORT_INTERRUPT    Interrupt);
-
-BOOLEAN
-EXPIMP
-NdisMSynchronizeWithInterrupt(
-    IN  PNDIS_MINIPORT_INTERRUPT    Interrupt,
-    IN  PVOID                       SynchronizeFunction,
-    IN  PVOID                       SynchronizeContext);
-
-VOID
-EXPIMP
-NdisMQueryAdapterResources(
-    OUT PNDIS_STATUS        Status,
-    IN  NDIS_HANDLE         WrapperConfigurationContext,
-    OUT PNDIS_RESOURCE_LIST ResourceList,
-    IN  OUT PUINT           BufferSize);
-
-
 /* Functions obsoleted by NDIS 5.0 */
 
 VOID
@@ -4581,7 +5244,173 @@ NdisUpdateSharedMemory(
     IN  PVOID                   VirtualAddress,
     IN  NDIS_PHYSICAL_ADDRESS   PhysicalAddress);
 
-#endif /* NDIS_WRAPPER || NDIS_MINIPORT_DRIVER */
+
+/* Routines for NDIS protocol drivers */
+
+#if BINARY_COMPATIBLE
+
+VOID
+EXPIMP
+NdisRequest(
+    OUT PNDIS_STATUS    Status,
+    IN  NDIS_HANDLE     NdisBindingHandle,
+    IN  PNDIS_REQUEST   NdisRequest);
+
+VOID
+EXPIMP
+NdisReset(
+    OUT PNDIS_STATUS    Status,
+    IN  NDIS_HANDLE     NdisBindingHandle);
+
+VOID
+EXPIMP
+NdisSend(
+    OUT PNDIS_STATUS    Status,
+    IN  NDIS_HANDLE     NdisBindingHandle,
+    IN  PNDIS_PACKET    Packet);
+
+VOID
+EXPIMP
+NdisSendPackets(
+    IN  NDIS_HANDLE     NdisBindingHandle,
+    IN  PPNDIS_PACKET   PacketArray,
+    IN  UINT            NumberOfPackets);
+
+VOID
+EXPIMP
+NdisTransferData(
+    OUT PNDIS_STATUS        Status,
+    IN  NDIS_HANDLE         NdisBindingHandle,
+    IN  NDIS_HANDLE         MacReceiveContext,
+    IN  UINT                ByteOffset,
+    IN  UINT                BytesToTransfer,
+    IN  OUT PNDIS_PACKET    Packet,
+    OUT PUINT               BytesTransferred);
+
+#else /* BINARY_COMPATIBLE */
+
+#define NdisRequest(Status,            \
+                    NdisBindingHandle, \
+                    NdisRequest)       \
+{                                      \
+    *(Status) = (((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->RequestHandler)(         \
+        ((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->MacBindingHandle, (NdisRequest)); \
+}
+
+#define NdisReset(Status,            \
+                  NdisBindingHandle) \
+{                                    \
+    *(Status) = (((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->ResetHandler)( \
+        ((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->MacBindingHandle);      \
+}
+
+#define NdisSend(Status,            \
+                 NdisBindingHandle, \
+                 Packet)            \
+{                                   \
+    *(Status) = (((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->u1.SendHandler)(    \
+        ((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->MacBindingHandle, (Packet)); \
+}
+
+#define NdisSendPackets(NdisBindingHandle, \
+                        PacketArray,       \
+                        NumberOfPackets)   \
+{                                          \
+    (((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->SendPacketsHandler)( \
+        (PNDIS_OPEN_BLOCK)(NdisBindingHandle), (PacketArray), (NumberOfPackets)); \
+}
+
+#define NdisTransferData(Status,           \
+                        NdisBindingHandle, \
+                        MacReceiveContext, \
+                        ByteOffset,        \
+                        BytesToTransfer,   \
+                        Packet,            \
+                        BytesTransferred)  \
+{                                          \
+    *(Status) =        (((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->TransferDataHandler)( \
+        ((PNDIS_OPEN_BLOCK)(NdisBindingHandle))->MacBindingHandle,              \
+        (MacReceiveContext), \
+        (ByteOffset),        \
+        (BytesToTransfer),   \
+        (Packet),            \
+        (BytesTransferred)); \
+}
+
+#endif /* BINARY_COMPATIBLE */
+
+
+VOID
+EXPIMP
+NdisCloseAdapter(
+    OUT PNDIS_STATUS    Status,
+    IN  NDIS_HANDLE     NdisBindingHandle);
+
+VOID
+EXPIMP
+NdisCompleteBindAdapter(
+    IN  NDIS_HANDLE BindAdapterContext,
+    IN  NDIS_STATUS Status,
+    IN  NDIS_STATUS OpenStatus);
+
+VOID
+EXPIMP
+NdisCompleteUnbindAdapter(
+    IN  NDIS_HANDLE UnbindAdapterContext,
+    IN  NDIS_STATUS Status);
+
+VOID
+EXPIMP
+NdisDeregisterProtocol(
+    OUT PNDIS_STATUS    Status,
+    IN  NDIS_HANDLE     NdisProtocolHandle);
+
+VOID
+EXPIMP
+NdisOpenAdapter(
+    OUT PNDIS_STATUS    Status,
+    OUT PNDIS_STATUS    OpenErrorStatus,
+    OUT PNDIS_HANDLE    NdisBindingHandle,
+    OUT PUINT           SelectedMediumIndex,
+    IN  PNDIS_MEDIUM    MediumArray,
+    IN  UINT            MediumArraySize,
+    IN  NDIS_HANDLE     NdisProtocolHandle,
+    IN  NDIS_HANDLE     ProtocolBindingContext,
+    IN  PNDIS_STRING    AdapterName,
+    IN  UINT            OpenOptions,
+    IN  PSTRING         AddressingInformation);
+
+VOID
+EXPIMP
+NdisOpenProtocolConfiguration(
+    OUT PNDIS_STATUS    Status,
+    OUT PNDIS_HANDLE    ConfigurationHandle,
+    IN  PNDIS_STRING    ProtocolSection);
+
+NDIS_STATUS
+EXPIMP
+NdisQueryReceiveInformation(
+    IN  NDIS_HANDLE NdisBindingHandle,
+    IN  NDIS_HANDLE MacContext,
+    OUT PLONGLONG   TimeSent            OPTIONAL,
+    OUT PLONGLONG   TimeReceived        OPTIONAL,
+    IN  PUCHAR      Buffer,
+    IN  UINT        BufferSize,
+    OUT PUINT       SizeNeeded);
+
+VOID
+EXPIMP
+NdisRegisterProtocol(
+    OUT PNDIS_STATUS                    Status,
+    OUT PNDIS_HANDLE                    NdisProtocolHandle,
+    IN  PNDIS_PROTOCOL_CHARACTERISTICS  ProtocolCharacteristics,
+    IN  UINT                            CharacteristicsLength);
+
+VOID
+EXPIMP
+NdisReturnPackets(
+    IN  PNDIS_PACKET    *PacketsToReturn,
+    IN  UINT            NumberOfPackets);
 
 #ifdef __cplusplus
 };
diff --git a/reactos/include/net/ntddndis.h b/reactos/include/net/ntddndis.h
new file mode 100644 (file)
index 0000000..e3d6a82
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * COPYRIGHT:   See COPYING in the top level directory
+ * PROJECT:     ReactOS NDIS library
+ * FILE:        include/net/ntddndis.h
+ * PURPOSE:     Structures for accessing NDIS devices
+ */
+#ifndef __NTDDNDIS_H
+#define __NIDDNDIS_H
+
+typedef enum _NDIS_DEVICE_POWER_STATE
+{
+    NdisDeviceStateUnspecified = 0,
+    NdisDeviceStateD0,
+    NdisDeviceStateD1,
+    NdisDeviceStateD2,
+    NdisDeviceStateD3,
+    NdisDeviceStateMaximum
+} NDIS_DEVICE_POWER_STATE, *PNDIS_DEVICE_POWER_STATE;
+
+typedef struct _NDIS_PM_WAKE_UP_CAPABILITIES
+{
+    NDIS_DEVICE_POWER_STATE MinMagicPacketWakeUp;
+    NDIS_DEVICE_POWER_STATE MinPatternWakeUp;
+    NDIS_DEVICE_POWER_STATE MinLinkChangeWakeUp;
+} NDIS_PM_WAKE_UP_CAPABILITIES, *PNDIS_PM_WAKE_UP_CAPABILITIES;
+
+typedef struct _NDIS_PNP_CAPABILITIES
+{
+    ULONG                           Flags;
+    NDIS_PM_WAKE_UP_CAPABILITIES    WakeUpCapabilities;
+} NDIS_PNP_CAPABILITIES, *PNDIS_PNP_CAPABILITIES;
+
+#endif /* __NTDDNDIS_H */
+
+/* EOF */