ReactOS 0.4.15-dev-8245-gd24675b
ndisuio.h File Reference
#include <ndis.h>
#include <nuiouser.h>
Include dependency graph for ndisuio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _NDISUIO_ADAPTER_CONTEXT
 
struct  _NDISUIO_OPEN_ENTRY
 
struct  _NDISUIO_PACKET_ENTRY
 

Macros

#define NDIS_MAJOR_VERSION   5
 
#define NDIS_MINOR_VERSION   0
 

Typedefs

typedef struct _NDISUIO_ADAPTER_CONTEXT NDISUIO_ADAPTER_CONTEXT
 
typedef struct _NDISUIO_ADAPTER_CONTEXTPNDISUIO_ADAPTER_CONTEXT
 
typedef struct _NDISUIO_OPEN_ENTRY NDISUIO_OPEN_ENTRY
 
typedef struct _NDISUIO_OPEN_ENTRYPNDISUIO_OPEN_ENTRY
 
typedef struct _NDISUIO_PACKET_ENTRY NDISUIO_PACKET_ENTRY
 
typedef struct _NDISUIO_PACKET_ENTRYPNDISUIO_PACKET_ENTRY
 

Functions

NTSTATUS NTAPI NduDispatchCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI NduDispatchClose (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI NduDispatchDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NDIS_STATUS AllocateAndChainBuffer (PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDIS_PACKET Packet, PVOID Buffer, ULONG BufferSize, BOOLEAN Front)
 
PNDIS_PACKET CreatePacketFromPoolBuffer (PNDISUIO_ADAPTER_CONTEXT AdapterContext, PVOID Buffer, ULONG BufferSize)
 
VOID CleanupAndFreePacket (PNDIS_PACKET Packet, BOOLEAN FreePool)
 
PNDISUIO_ADAPTER_CONTEXT FindAdapterContextByName (PNDIS_STRING DeviceName)
 
VOID ReferenceAdapterContext (PNDISUIO_ADAPTER_CONTEXT AdapterContext)
 
VOID DereferenceAdapterContextWithOpenEntry (PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDISUIO_OPEN_ENTRY OpenEntry)
 
VOID NTAPI NduOpenAdapterComplete (NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS Status, NDIS_STATUS OpenStatus)
 
VOID NTAPI NduCloseAdapterComplete (NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS Status)
 
NDIS_STATUS NTAPI NduNetPnPEvent (NDIS_HANDLE ProtocolBindingContext, PNET_PNP_EVENT NetPnPEvent)
 
VOID NTAPI NduSendComplete (NDIS_HANDLE ProtocolBindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
 
VOID NTAPI NduTransferDataComplete (NDIS_HANDLE ProtocolBindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred)
 
VOID NTAPI NduResetComplete (NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS Status)
 
VOID NTAPI NduRequestComplete (NDIS_HANDLE ProtocolBindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
 
NDIS_STATUS NTAPI NduReceive (NDIS_HANDLE ProtocolBindingContext, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, UINT HeaderBufferSize, PVOID LookAheadBuffer, UINT LookaheadBufferSize, UINT PacketSize)
 
VOID NTAPI NduReceiveComplete (NDIS_HANDLE ProtocolBindingContext)
 
VOID NTAPI NduStatus (NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS GeneralStatus, PVOID StatusBuffer, UINT StatusBufferSize)
 
VOID NTAPI NduStatusComplete (NDIS_HANDLE ProtocolBindingContext)
 
VOID NTAPI NduBindAdapter (PNDIS_STATUS Status, NDIS_HANDLE BindContext, PNDIS_STRING DeviceName, PVOID SystemSpecific1, PVOID SystemSpecific2)
 
VOID NTAPI NduUnbindAdapter (PNDIS_STATUS Status, NDIS_HANDLE ProtocolBindingContext, NDIS_HANDLE UnbindContext)
 
NTSTATUS NTAPI NduDispatchRead (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI NduDispatchWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 

Variables

PDEVICE_OBJECT GlobalDeviceObject
 
NDIS_HANDLE GlobalProtocolHandle
 
LIST_ENTRY GlobalAdapterList
 
KSPIN_LOCK GlobalAdapterListLock
 

Macro Definition Documentation

◆ NDIS_MAJOR_VERSION

#define NDIS_MAJOR_VERSION   5

Definition at line 78 of file ndisuio.h.

◆ NDIS_MINOR_VERSION

#define NDIS_MINOR_VERSION   0

Definition at line 79 of file ndisuio.h.

Typedef Documentation

◆ NDISUIO_ADAPTER_CONTEXT

◆ NDISUIO_OPEN_ENTRY

◆ NDISUIO_PACKET_ENTRY

◆ PNDISUIO_ADAPTER_CONTEXT

◆ PNDISUIO_OPEN_ENTRY

◆ PNDISUIO_PACKET_ENTRY

Function Documentation

◆ AllocateAndChainBuffer()

NDIS_STATUS AllocateAndChainBuffer ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext,
PNDIS_PACKET  Packet,
PVOID  Buffer,
ULONG  BufferSize,
BOOLEAN  Front 
)

Definition at line 15 of file misc.c.

20{
22 PNDIS_BUFFER NdisBuffer;
23
24 /* Allocate the NDIS buffer mapping the pool */
26 &NdisBuffer,
27 AdapterContext->BufferPoolHandle,
28 Buffer,
31 {
32 DPRINT1("No free buffer descriptors\n");
33 return Status;
34 }
35
36 if (Front)
37 {
38 /* Chain the buffer to front */
39 NdisChainBufferAtFront(Packet, NdisBuffer);
40 }
41 else
42 {
43 /* Chain the buffer to back */
44 NdisChainBufferAtBack(Packet, NdisBuffer);
45 }
46
47 /* Return success */
49}
#define DPRINT1
Definition: precomp.h:8
Definition: bufpool.h:45
VOID EXPORT NdisAllocateBuffer(OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID VirtualAddress, IN UINT Length)
Definition: buffer.c:336
Status
Definition: gdiplustypes.h:25
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NdisChainBufferAtBack(Packet, Buffer)
Definition: ndis.h:3128
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
int NDIS_STATUS
Definition: ntddndis.h:475
NDIS_HANDLE BufferPoolHandle
Definition: ndisuio.h:34
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by CreatePacketFromPoolBuffer().

◆ CleanupAndFreePacket()

VOID CleanupAndFreePacket ( PNDIS_PACKET  Packet,
BOOLEAN  FreePool 
)

Definition at line 83 of file misc.c.

84{
86 PVOID Data;
88
89 /* Free each buffer and its backing pool memory */
90 while (TRUE)
91 {
92 /* Unchain each buffer */
94 if (!Buffer)
95 break;
96
97 /* Get the backing memory */
99
100 /* Free the buffer */
102
103 if (FreePool)
104 {
105 /* Free the backing memory */
107 }
108 }
109
110 /* Free the packet descriptor */
112}
#define TRUE
Definition: types.h:120
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:828
VOID EXPORT NdisUnchainBufferAtFront(IN OUT PNDIS_PACKET Packet, OUT PNDIS_BUFFER *Buffer)
Definition: buffer.c:1069
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define FreePool(P)
Definition: mntmgr.h:154
#define NdisFreeBuffer
Definition: ndis.h:2895
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint32_t ULONG
Definition: typedefs.h:59

Referenced by NduDispatchWrite(), and NduReceive().

◆ CreatePacketFromPoolBuffer()

PNDIS_PACKET CreatePacketFromPoolBuffer ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext,
PVOID  Buffer,
ULONG  BufferSize 
)

Definition at line 52 of file misc.c.

55{
58
59 /* Allocate a packet descriptor */
61 &Packet,
62 AdapterContext->PacketPoolHandle);
64 {
65 DPRINT1("No free packet descriptors\n");
66 return NULL;
67 }
68
69 /* Use the helper to chain the buffer */
70 Status = AllocateAndChainBuffer(AdapterContext, Packet,
73 {
75 return NULL;
76 }
77
78 /* Return the packet */
79 return Packet;
80}
#define NULL
Definition: types.h:112
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:394
NDIS_STATUS AllocateAndChainBuffer(PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDIS_PACKET Packet, PVOID Buffer, ULONG BufferSize, BOOLEAN Front)
Definition: misc.c:15
NDIS_HANDLE PacketPoolHandle
Definition: ndisuio.h:33

Referenced by NduDispatchWrite(), and NduReceive().

◆ DereferenceAdapterContextWithOpenEntry()

VOID DereferenceAdapterContextWithOpenEntry ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext,
PNDISUIO_OPEN_ENTRY  OpenEntry 
)

Definition at line 149 of file misc.c.

151{
153
154 /* Lock the adapter context */
155 KeAcquireSpinLock(&AdapterContext->Spinlock, &OldIrql);
156
157 /* Decrement the open count */
158 AdapterContext->OpenCount--;
159
160 /* Cleanup the open entry if we were given one */
161 if (OpenEntry != NULL)
162 {
163 /* Remove the open entry */
164 RemoveEntryList(&OpenEntry->ListEntry);
165
166 /* Invalidate the FO */
167 OpenEntry->FileObject->FsContext = NULL;
168 OpenEntry->FileObject->FsContext2 = NULL;
169
170 /* Free the open entry */
171 ExFreePool(OpenEntry);
172 }
173
174 /* Release the adapter context lock */
175 KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
176}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KSPIN_LOCK Spinlock
Definition: ndisuio.h:50
LIST_ENTRY ListEntry
Definition: ndisuio.h:62
PFILE_OBJECT FileObject
Definition: ndisuio.h:56
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by NduDispatchClose(), and OpenDeviceReadWrite().

◆ FindAdapterContextByName()

PNDISUIO_ADAPTER_CONTEXT FindAdapterContextByName ( PNDIS_STRING  DeviceName)

Definition at line 115 of file misc.c.

116{
118 PLIST_ENTRY CurrentEntry;
119 PNDISUIO_ADAPTER_CONTEXT AdapterContext;
120
122 CurrentEntry = GlobalAdapterList.Flink;
123 while (CurrentEntry != &GlobalAdapterList)
124 {
125 AdapterContext = CONTAINING_RECORD(CurrentEntry, NDISUIO_ADAPTER_CONTEXT, ListEntry);
126
127 /* Check if the device name matches */
128 if (RtlEqualUnicodeString(&AdapterContext->DeviceName, DeviceName, TRUE))
129 {
131 return AdapterContext;
132 }
133
134 CurrentEntry = CurrentEntry->Flink;
135 }
137
138 return NULL;
139}
LIST_ENTRY GlobalAdapterList
Definition: main.c:17
KSPIN_LOCK GlobalAdapterListLock
Definition: main.c:16
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
UNICODE_STRING DeviceName
Definition: ndisuio.h:44
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

Referenced by OpenDeviceReadWrite().

◆ NduBindAdapter()

VOID NTAPI NduBindAdapter ( PNDIS_STATUS  Status,
NDIS_HANDLE  BindContext,
PNDIS_STRING  DeviceName,
PVOID  SystemSpecific1,
PVOID  SystemSpecific2 
)

Definition at line 538 of file protocol.c.

543{
544 /* Use our helper function to create a context for this adapter */
546}
static NDIS_STATUS BindAdapterByName(PNDIS_STRING DeviceName)
Definition: protocol.c:383

Referenced by DriverEntry().

◆ NduCloseAdapterComplete()

VOID NTAPI NduCloseAdapterComplete ( NDIS_HANDLE  ProtocolBindingContext,
NDIS_STATUS  Status 
)

Definition at line 31 of file protocol.c.

33{
35
36 DPRINT("Asynchronous adapter close completed\n");
37
38 /* Store the final status and signal the event */
39 AdapterContext->AsyncStatus = Status;
40 KeSetEvent(&AdapterContext->AsyncEvent, IO_NO_INCREMENT, FALSE);
41}
#define FALSE
Definition: types.h:117
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE ProtocolBindingContext
Definition: ndis.h:6015
#define DPRINT
Definition: sndvol32.h:73
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ NduDispatchClose()

NTSTATUS NTAPI NduDispatchClose ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 40 of file createclose.c.

42{
44 PNDISUIO_ADAPTER_CONTEXT AdapterContext = IrpSp->FileObject->FsContext;
45 PNDISUIO_OPEN_ENTRY OpenEntry = IrpSp->FileObject->FsContext2;
46
48
49 DPRINT("Closing file object 0x%x\n", IrpSp->FileObject);
50
51 /* Check if this handle was ever associated with an adapter */
52 if (AdapterContext != NULL)
53 {
54 ASSERT(OpenEntry != NULL);
55
56 DPRINT("Removing binding to adapter %wZ\n", &AdapterContext->DeviceName);
57
58 /* Call the our helper */
59 DereferenceAdapterContextWithOpenEntry(AdapterContext, OpenEntry);
60 }
61
62 /* Completed */
63 Irp->IoStatus.Status = STATUS_SUCCESS;
64 Irp->IoStatus.Information = 0;
66
67 /* Return success */
68 return STATUS_SUCCESS;
69}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
PDEVICE_OBJECT GlobalDeviceObject
Definition: main.c:14
VOID DereferenceAdapterContextWithOpenEntry(PNDISUIO_ADAPTER_CONTEXT AdapterContext, PNDISUIO_OPEN_ENTRY OpenEntry)
Definition: misc.c:149
#define ASSERT(a)
Definition: mode.c:44
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_SUCCESS
Definition: shellext.h:65
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
Definition: ndisuio.h:54
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by DriverEntry().

◆ NduDispatchCreate()

NTSTATUS NTAPI NduDispatchCreate ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 16 of file createclose.c.

18{
20
22
23 DPRINT("Created file object 0x%x\n", IrpSp->FileObject);
24
25 /* This is associated with an adapter during IOCTL_NDISUIO_OPEN_(WRITE_)DEVICE */
26 IrpSp->FileObject->FsContext = NULL;
27 IrpSp->FileObject->FsContext2 = NULL;
28
29 /* Completed successfully */
30 Irp->IoStatus.Status = STATUS_SUCCESS;
31 Irp->IoStatus.Information = FILE_OPENED;
33
34 /* Return success */
35 return STATUS_SUCCESS;
36}
#define FILE_OPENED
Definition: nt_native.h:769

Referenced by DriverEntry().

◆ NduDispatchDeviceControl()

NTSTATUS NTAPI NduDispatchDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 469 of file ioctl.c.

471{
473 PNDISUIO_OPEN_ENTRY OpenEntry;
474
476
477 /* Handle open IOCTLs first */
478 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
479 {
482#if 0
483 case IOCTL_NDISUIO_OPEN_WRITE_DEVICE:
484 return OpenDeviceWrite(Irp, IrpSp);
485#endif
487 return WaitForBind(Irp, IrpSp);
488
490 return QueryBinding(Irp, IrpSp);
491
492 default:
493 /* Fail if this file object has no adapter associated */
494 if (IrpSp->FileObject->FsContext == NULL)
495 {
496 Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
497 Irp->IoStatus.Information = 0;
499
501 }
502
503 /* Now handle write IOCTLs */
504 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
505 {
507 return SetAdapterOid(Irp, IrpSp);
508
509 default:
510 /* Check that we have read permissions */
511 OpenEntry = IrpSp->FileObject->FsContext2;
512 if (OpenEntry->WriteOnly)
513 {
514 Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
515 Irp->IoStatus.Information = 0;
517
519 }
520
521 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
522 {
523#if 0
524 case IOCTL_CANCEL_READ:
525 return CancelPacketRead(Irp, IrpSp);
526#endif
527
529 return QueryAdapterOid(Irp, IrpSp);
530
531 default:
532 DPRINT1("Unimplemented\n");
533 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
534 Irp->IoStatus.Information = 0;
537 }
538 }
539 break;
540 }
541}
static NTSTATUS QueryAdapterOid(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:220
static NTSTATUS SetAdapterOid(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:146
static NTSTATUS QueryBinding(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:34
static NTSTATUS OpenDeviceReadWrite(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:294
static NTSTATUS WaitForBind(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:16
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define IOCTL_NDISUIO_QUERY_OID_VALUE
Definition: nuiouser.h:16
#define IOCTL_NDISUIO_BIND_WAIT
Definition: nuiouser.h:27
#define IOCTL_NDISUIO_OPEN_DEVICE
Definition: nuiouser.h:12
#define IOCTL_NDISUIO_QUERY_BINDING
Definition: nuiouser.h:23
#define IOCTL_NDISUIO_SET_OID_VALUE
Definition: nuiouser.h:31
struct _IO_STACK_LOCATION::@1574::@1575 DeviceIoControl
union _IO_STACK_LOCATION::@1574 Parameters
BOOLEAN WriteOnly
Definition: ndisuio.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by DriverEntry().

◆ NduDispatchRead()

NTSTATUS NTAPI NduDispatchRead ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 42 of file readwrite.c.

44{
46 PNDISUIO_ADAPTER_CONTEXT AdapterContext = IrpSp->FileObject->FsContext;
47 PNDISUIO_OPEN_ENTRY OpenEntry = IrpSp->FileObject->FsContext2;
48 KIRQL OldIrql, OldCancelIrql;
50 PLIST_ENTRY ListEntry;
51 PNDISUIO_PACKET_ENTRY PacketEntry = NULL;
53
55
56 if (OpenEntry->WriteOnly)
57 {
58 Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
59 Irp->IoStatus.Information = 0;
61
63 }
64
65 /* Make the read cancellable */
66 IoAcquireCancelSpinLock(&OldCancelIrql);
68 if (Irp->Cancel)
69 {
70 IoReleaseCancelSpinLock(OldCancelIrql);
71
72 /* Indicate a 0 byte read */
73 Irp->IoStatus.Status = STATUS_SUCCESS;
74 Irp->IoStatus.Information = 0;
76
77 return STATUS_SUCCESS;
78 }
79 IoReleaseCancelSpinLock(OldCancelIrql);
80
81 while (TRUE)
82 {
83 KeAcquireSpinLock(&AdapterContext->Spinlock, &OldIrql);
84
85 /* Check if we have a packet */
86 if (IsListEmpty(&AdapterContext->PacketList))
87 {
88 KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
89
90 /* Wait for a packet (in the context of the calling user thread) */
94 TRUE,
95 NULL);
97 {
98 /* Remove the cancel routine */
99 IoAcquireCancelSpinLock(&OldCancelIrql);
101 IoReleaseCancelSpinLock(OldCancelIrql);
102
103 break;
104 }
105 }
106 else
107 {
108 /* Remove the cancel routine */
109 IoAcquireCancelSpinLock(&OldCancelIrql);
111 IoReleaseCancelSpinLock(OldCancelIrql);
112
113 /* Remove the first packet in the list */
114 ListEntry = RemoveHeadList(&AdapterContext->PacketList);
115 PacketEntry = CONTAINING_RECORD(ListEntry, NDISUIO_PACKET_ENTRY, ListEntry);
116
117 /* Release the adapter lock */
118 KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
119
120 /* And we're done with this loop */
122 break;
123 }
124 }
125
126 /* Check if we got a packet */
127 if (PacketEntry != NULL)
128 {
129 /* Find the right amount of bytes to copy */
130 BytesCopied = PacketEntry->PacketLength;
131 if (BytesCopied > IrpSp->Parameters.Read.Length)
133
134 /* Copy the packet */
135 RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
136 &PacketEntry->PacketData[0],
138
139 /* Free the packet entry */
140 ExFreePool(PacketEntry);
141 }
142 else
143 {
144 /* Something failed */
145 BytesCopied = 0;
146 }
147
148 /* Complete the IRP */
149 Irp->IoStatus.Status = Status;
150 Irp->IoStatus.Information = BytesCopied;
152
153 return Status;
154}
LONG NTSTATUS
Definition: precomp.h:26
static VOID NTAPI ReadIrpCancel(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: readwrite.c:17
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
IoSetCancelRoutine(Irp, CancelRoutine)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3171
#define UserMode
Definition: asm.h:35
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
struct _IO_STACK_LOCATION::@3992::@3996 Read
LIST_ENTRY PacketList
Definition: ndisuio.h:37
Definition: ndisuio.h:66
UCHAR PacketData[1]
Definition: ndisuio.h:74
ULONG PacketLength
Definition: ndisuio.h:68
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
@ UserRequest
Definition: ketypes.h:421

Referenced by DriverEntry().

◆ NduDispatchWrite()

NTSTATUS NTAPI NduDispatchWrite ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 158 of file readwrite.c.

160{
162 PNDISUIO_ADAPTER_CONTEXT AdapterContext = IrpSp->FileObject->FsContext;
165 ULONG BytesCopied = 0;
166
168
169 /* Create a packet and buffer descriptor for this user buffer */
170 Packet = CreatePacketFromPoolBuffer(AdapterContext,
171 Irp->AssociatedIrp.SystemBuffer,
172 IrpSp->Parameters.Write.Length);
173 if (Packet)
174 {
175 /* Send it via NDIS */
177 AdapterContext->BindingHandle,
178 Packet);
179
180 /* Wait for the send */
182 {
183 KeWaitForSingleObject(&AdapterContext->AsyncEvent,
184 Executive,
186 FALSE,
187 NULL);
188 Status = AdapterContext->AsyncStatus;
189 }
190
191 /* Check if it succeeded */
194
196 }
197 else
198 {
199 /* No memory */
201 }
202
203 /* Complete the IRP */
204 Irp->IoStatus.Status = Status;
205 Irp->IoStatus.Information = BytesCopied;
207
208 return Status;
209}
VOID EXPORT NdisSend(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_PACKET Packet)
Definition: protocol.c:1272
PNDIS_PACKET CreatePacketFromPoolBuffer(PNDISUIO_ADAPTER_CONTEXT AdapterContext, PVOID Buffer, ULONG BufferSize)
Definition: misc.c:52
VOID CleanupAndFreePacket(PNDIS_PACKET Packet, BOOLEAN FreePool)
Definition: misc.c:83
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
#define KernelMode
Definition: asm.h:34
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
struct _IO_STACK_LOCATION::@3992::@3997 Write
NDIS_HANDLE BindingHandle
Definition: ndisuio.h:26
@ Executive
Definition: ketypes.h:415

Referenced by DriverEntry().

◆ NduNetPnPEvent()

NDIS_STATUS NTAPI NduNetPnPEvent ( NDIS_HANDLE  ProtocolBindingContext,
PNET_PNP_EVENT  NetPnPEvent 
)

Definition at line 45 of file protocol.c.

47{
49
50 DPRINT("NetPnPEvent\n");
51
52 switch (NetPnPEvent->NetEvent)
53 {
55 /* Nothing to do */
56 DPRINT1("NetPnPEvent: QueryRemoveDevice\n");
58
60 ASSERT(NetPnPEvent->BufferLength >= sizeof(*PowerState));
61
62 PowerState = NetPnPEvent->Buffer;
63 switch (*PowerState)
64 {
66 DPRINT1("NetPnPEvent: SetPower D0\n");
68
69 default:
70 DPRINT1("NetPnPEvent: SetPower state %d not supported\n", *PowerState);
72 }
73
75 DPRINT1("NetPnPEvent: QueryPower\n");
77
79 DPRINT1("NetPnPEvent: CancelRemoveDevice\n");
81
83 DPRINT1("NetPnPEvent: Reconfigure\n");
85
87 DPRINT1("NetPnPEvent: BindList\n");
89
91 DPRINT("NetPnPEvent: BindsComplete\n");
93
95 DPRINT1("NetPnPEvent: PnPCapabilities\n");
97
98 default:
99 DPRINT1("NetPnPEvent unimplemented for net event 0x%x\n", NetPnPEvent->NetEvent);
100 return NDIS_STATUS_FAILURE;
101 }
102}
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
_In_ NDIS_HANDLE _In_ PNET_PNP_EVENT NetPnPEvent
Definition: ndis.h:6082
@ NetEventBindList
Definition: netpnp.h:20
@ NetEventSetPower
Definition: netpnp.h:15
@ NetEventPnPCapabilities
Definition: netpnp.h:22
@ NetEventQueryRemoveDevice
Definition: netpnp.h:17
@ NetEventReconfigure
Definition: netpnp.h:19
@ NetEventBindsComplete
Definition: netpnp.h:21
@ NetEventCancelRemoveDevice
Definition: netpnp.h:18
@ NetEventQueryPower
Definition: netpnp.h:16
@ NdisDeviceStateD0
Definition: ntddndis.h:38
enum _NDIS_DEVICE_POWER_STATE * PNDIS_DEVICE_POWER_STATE
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034

Referenced by DriverEntry().

◆ NduOpenAdapterComplete()

VOID NTAPI NduOpenAdapterComplete ( NDIS_HANDLE  ProtocolBindingContext,
NDIS_STATUS  Status,
NDIS_STATUS  OpenStatus 
)

Definition at line 16 of file protocol.c.

19{
21
22 DPRINT("Asynchronous adapter open completed\n");
23
24 /* Store the final status and signal the event */
25 AdapterContext->AsyncStatus = Status;
26 KeSetEvent(&AdapterContext->AsyncEvent, IO_NO_INCREMENT, FALSE);
27}

Referenced by DriverEntry().

◆ NduReceive()

NDIS_STATUS NTAPI NduReceive ( NDIS_HANDLE  ProtocolBindingContext,
NDIS_HANDLE  MacReceiveContext,
PVOID  HeaderBuffer,
UINT  HeaderBufferSize,
PVOID  LookAheadBuffer,
UINT  LookaheadBufferSize,
UINT  PacketSize 
)

Definition at line 166 of file protocol.c.

173{
175 PNDISUIO_PACKET_ENTRY PacketEntry;
176 PVOID PacketBuffer;
180
181 DPRINT("Received a %d byte packet\n", PacketSize);
182
183 /* Discard if nobody is waiting for it */
184 if (AdapterContext->OpenCount == 0)
186
187 /* Allocate a buffer to hold the packet data and header */
188 PacketBuffer = ExAllocatePool(NonPagedPool, PacketSize + HeaderBufferSize);
189 if (!PacketBuffer)
191
192 /* Allocate the packet descriptor and buffer */
193 Packet = CreatePacketFromPoolBuffer(AdapterContext,
194 (PUCHAR)PacketBuffer + HeaderBufferSize,
195 PacketSize);
196 if (!Packet)
197 {
198 ExFreePool(PacketBuffer);
200 }
201
202 /* Transfer the packet data into our data buffer */
203 if (LookaheadBufferSize == PacketSize)
204 {
205 NdisCopyLookaheadData((PVOID)((PUCHAR)PacketBuffer + HeaderBufferSize),
206 LookAheadBuffer,
208 AdapterContext->MacOptions);
210 }
211 else
212 {
214 AdapterContext->BindingHandle,
215 MacReceiveContext,
216 0,
218 Packet,
221 {
222 KeWaitForSingleObject(&AdapterContext->AsyncEvent,
223 Executive,
225 FALSE,
226 NULL);
227 Status = AdapterContext->AsyncStatus;
228 }
230 {
231 DPRINT1("Failed to transfer data with status 0x%x\n", Status);
233 ExFreePool(PacketBuffer);
235 }
236 }
237
238 /* Copy the header data */
239 RtlCopyMemory(PacketBuffer, HeaderBuffer, HeaderBufferSize);
240
241 /* Free the packet descriptor and buffers
242 but not the pool because we still need it */
244
245 /* Allocate a packet entry from pool */
246 PacketEntry = ExAllocatePool(NonPagedPool, sizeof(NDISUIO_PACKET_ENTRY) + BytesTransferred + HeaderBufferSize - 1);
247 if (!PacketEntry)
248 {
249 ExFreePool(PacketBuffer);
251 }
252
253 /* Initialize the packet entry and copy in packet data */
254 PacketEntry->PacketLength = BytesTransferred + HeaderBufferSize;
255 RtlCopyMemory(PacketEntry->PacketData, PacketBuffer, PacketEntry->PacketLength);
256
257 /* Free the old buffer */
258 ExFreePool(PacketBuffer);
259
260 /* Insert the packet on the adapter's packet list */
262 &PacketEntry->ListEntry,
263 &AdapterContext->Spinlock);
264
265 /* Signal the read event */
266 KeSetEvent(&AdapterContext->PacketReadEvent,
268 FALSE);
269
270 return NDIS_STATUS_SUCCESS;
271}
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)
Definition: protocol.c:1307
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
unsigned int UINT
Definition: ndis.h:50
#define NdisCopyLookaheadData(Destination, Source, Length, MacOptions)
Definition: ndis.h:3289
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
LIST_ENTRY ListEntry
Definition: ndisuio.h:71
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342
_In_ USHORT PacketSize
Definition: iofuncs.h:1058

Referenced by DriverEntry().

◆ NduReceiveComplete()

VOID NTAPI NduReceiveComplete ( NDIS_HANDLE  ProtocolBindingContext)

Definition at line 275 of file protocol.c.

276{
277 /* No op */
278}

Referenced by DriverEntry().

◆ NduRequestComplete()

VOID NTAPI NduRequestComplete ( NDIS_HANDLE  ProtocolBindingContext,
PNDIS_REQUEST  NdisRequest,
NDIS_STATUS  Status 
)

Definition at line 151 of file protocol.c.

154{
156
157 DPRINT("Asynchronous adapter request completed\n");
158
159 /* Store the final status and signal the event */
160 AdapterContext->AsyncStatus = Status;
161 KeSetEvent(&AdapterContext->AsyncEvent, IO_NO_INCREMENT, FALSE);
162}

Referenced by DriverEntry().

◆ NduResetComplete()

VOID NTAPI NduResetComplete ( NDIS_HANDLE  ProtocolBindingContext,
NDIS_STATUS  Status 
)

Definition at line 137 of file protocol.c.

139{
141
142 DPRINT("Asynchronous adapter reset completed\n");
143
144 /* Store the final status and signal the event */
145 AdapterContext->AsyncStatus = Status;
146 KeSetEvent(&AdapterContext->AsyncEvent, IO_NO_INCREMENT, FALSE);
147}

Referenced by DriverEntry().

◆ NduSendComplete()

VOID NTAPI NduSendComplete ( NDIS_HANDLE  ProtocolBindingContext,
PNDIS_PACKET  Packet,
NDIS_STATUS  Status 
)

Definition at line 106 of file protocol.c.

109{
111
112 DPRINT("Asynchronous adapter send completed\n");
113
114 /* Store the final status and signal the event */
115 AdapterContext->AsyncStatus = Status;
116 KeSetEvent(&AdapterContext->AsyncEvent, IO_NO_INCREMENT, FALSE);
117}

Referenced by DriverEntry().

◆ NduStatus()

VOID NTAPI NduStatus ( NDIS_HANDLE  ProtocolBindingContext,
NDIS_STATUS  GeneralStatus,
PVOID  StatusBuffer,
UINT  StatusBufferSize 
)

Definition at line 282 of file protocol.c.

286{
287 /* FIXME: Implement status tracking */
288}

Referenced by DriverEntry().

◆ NduStatusComplete()

VOID NTAPI NduStatusComplete ( NDIS_HANDLE  ProtocolBindingContext)

Definition at line 292 of file protocol.c.

293{
294 /* FIXME: Implement status tracking */
295}

Referenced by DriverEntry().

◆ NduTransferDataComplete()

VOID NTAPI NduTransferDataComplete ( NDIS_HANDLE  ProtocolBindingContext,
PNDIS_PACKET  Packet,
NDIS_STATUS  Status,
UINT  BytesTransferred 
)

Definition at line 121 of file protocol.c.

125{
127
128 DPRINT("Asynchronous adapter transfer completed\n");
129
130 /* Store the final status and signal the event */
131 AdapterContext->AsyncStatus = Status;
132 KeSetEvent(&AdapterContext->AsyncEvent, IO_NO_INCREMENT, FALSE);
133}

Referenced by DriverEntry().

◆ NduUnbindAdapter()

VOID NTAPI NduUnbindAdapter ( PNDIS_STATUS  Status,
NDIS_HANDLE  ProtocolBindingContext,
NDIS_HANDLE  UnbindContext 
)

Definition at line 550 of file protocol.c.

553{
554 /* This is forced unbind. UnbindAdapterByContext() will take care of
555 * invalidating file handles pointer to this adapter for us */
557}
static NDIS_STATUS UnbindAdapterByContext(PNDISUIO_ADAPTER_CONTEXT AdapterContext)
Definition: protocol.c:299

Referenced by DriverEntry().

◆ ReferenceAdapterContext()

VOID ReferenceAdapterContext ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext)

Definition at line 142 of file misc.c.

143{
144 /* Increment the open count */
145 AdapterContext->OpenCount++;
146}

Referenced by OpenDeviceReadWrite().

Variable Documentation

◆ GlobalAdapterList

LIST_ENTRY GlobalAdapterList
extern

Definition at line 17 of file main.c.

Referenced by BindAdapterByName(), DriverEntry(), FindAdapterContextByName(), and QueryBinding().

◆ GlobalAdapterListLock

KSPIN_LOCK GlobalAdapterListLock
extern

◆ GlobalDeviceObject

◆ GlobalProtocolHandle

NDIS_HANDLE GlobalProtocolHandle
extern

Definition at line 15 of file main.c.

Referenced by BindAdapterByName(), and DriverEntry().