ReactOS  0.4.15-dev-1397-g19779b3
protocol.c File Reference
#include "ndisuio.h"
#include <debug.h>
Include dependency graph for protocol.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

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)
 
static NDIS_STATUS UnbindAdapterByContext (PNDISUIO_ADAPTER_CONTEXT AdapterContext)
 
static NDIS_STATUS BindAdapterByName (PNDIS_STRING DeviceName)
 
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)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file protocol.c.

Function Documentation

◆ BindAdapterByName()

static NDIS_STATUS BindAdapterByName ( PNDIS_STRING  DeviceName)
static

Definition at line 383 of file protocol.c.

384 {
386  PNDISUIO_ADAPTER_CONTEXT AdapterContext;
387  NDIS_MEDIUM SupportedMedia[1] = {NdisMedium802_3};
388  UINT SelectedMedium;
391 
392  /* Allocate the adapter context */
393  AdapterContext = ExAllocatePool(NonPagedPool, sizeof(*AdapterContext));
394  if (!AdapterContext)
395  {
396  return NDIS_STATUS_RESOURCES;
397  }
398 
399  /* Set up the adapter context */
400  RtlZeroMemory(AdapterContext, sizeof(*AdapterContext));
403  KeInitializeSpinLock(&AdapterContext->Spinlock);
404  InitializeListHead(&AdapterContext->PacketList);
405  InitializeListHead(&AdapterContext->OpenEntryList);
406  AdapterContext->OpenCount = 0;
407 
408  AdapterContext->DeviceName.Length =
409  AdapterContext->DeviceName.MaximumLength = DeviceName->Length;
410  AdapterContext->DeviceName.Buffer = ExAllocatePool(NonPagedPool, DeviceName->Length);
411  if (!AdapterContext->DeviceName.Buffer)
412  {
413  ExFreePool(AdapterContext);
414  return NDIS_STATUS_RESOURCES;
415  }
416 
417  /* Copy the device name into the adapter context */
418  RtlCopyMemory(AdapterContext->DeviceName.Buffer, DeviceName->Buffer, DeviceName->Length);
419 
420  DPRINT("Binding adapter %wZ\n", &AdapterContext->DeviceName);
421 
422  /* Create the buffer pool */
424  &AdapterContext->BufferPoolHandle,
425  50);
427  {
428  DPRINT1("Failed to allocate buffer pool with status 0x%x\n", Status);
429  RtlFreeUnicodeString(&AdapterContext->DeviceName);
430  ExFreePool(AdapterContext);
431  return Status;
432  }
433 
434  /* Create the packet pool */
436  &AdapterContext->PacketPoolHandle,
437  25,
440  {
441  DPRINT1("Failed to allocate packet pool with status 0x%x\n", Status);
442  NdisFreeBufferPool(AdapterContext->BufferPoolHandle);
443  RtlFreeUnicodeString(&AdapterContext->DeviceName);
444  ExFreePool(AdapterContext);
445  return Status;
446  }
447 
448  /* Send the open request */
451  &AdapterContext->BindingHandle,
452  &SelectedMedium,
453  SupportedMedia,
454  1,
456  AdapterContext,
457  DeviceName,
458  0,
459  NULL);
460 
461  /* Wait for a pending open */
463  {
464  KeWaitForSingleObject(&AdapterContext->AsyncEvent,
465  Executive,
466  KernelMode,
467  FALSE,
468  NULL);
469  Status = AdapterContext->AsyncStatus;
470  }
471 
472  /* Check the final status */
474  {
475  DPRINT1("Failed to open adapter for bind with status 0x%x\n", Status);
476  NdisFreePacketPool(AdapterContext->PacketPoolHandle);
477  NdisFreeBufferPool(AdapterContext->BufferPoolHandle);
478  RtlFreeUnicodeString(&AdapterContext->DeviceName);
479  ExFreePool(AdapterContext);
480  return Status;
481  }
482 
483  /* Get the MAC options */
484  Request.RequestType = NdisRequestQueryInformation;
485  Request.DATA.QUERY_INFORMATION.Oid = OID_GEN_MAC_OPTIONS;
486  Request.DATA.QUERY_INFORMATION.InformationBuffer = &AdapterContext->MacOptions;
487  Request.DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(ULONG);
489  AdapterContext->BindingHandle,
490  &Request);
491 
492  /* Wait for a pending request */
494  {
495  KeWaitForSingleObject(&AdapterContext->AsyncEvent,
496  Executive,
497  KernelMode,
498  FALSE,
499  NULL);
500  Status = AdapterContext->AsyncStatus;
501  }
502 
503  /* Check the final status */
505  {
506  NDIS_STATUS CloseStatus;
507 
508  DPRINT1("Failed to get MAC options with status 0x%x\n", Status);
509 
510  NdisCloseAdapter(&CloseStatus,
511  AdapterContext->BindingHandle);
512  if (CloseStatus == NDIS_STATUS_PENDING)
513  {
514  KeWaitForSingleObject(&AdapterContext->AsyncEvent,
515  Executive,
516  KernelMode,
517  FALSE,
518  NULL);
519  }
520 
521  NdisFreePacketPool(AdapterContext->PacketPoolHandle);
522  NdisFreeBufferPool(AdapterContext->BufferPoolHandle);
523  RtlFreeUnicodeString(&AdapterContext->DeviceName);
524  ExFreePool(AdapterContext);
525  return Status;
526  }
527 
528  /* Add the adapter context to the global list */
530  &AdapterContext->ListEntry,
532 
533  return STATUS_SUCCESS;
534 }
VOID EXPORT NdisAllocatePacketPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:421
NDIS_HANDLE BufferPoolHandle
Definition: ndisuio.h:34
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6008
enum _NDIS_MEDIUM NDIS_MEDIUM
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define OID_GEN_MAC_OPTIONS
Definition: ntddndis.h:251
KSPIN_LOCK Spinlock
Definition: ndisuio.h:50
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
int NDIS_STATUS
Definition: ntddndis.h:471
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
VOID EXPORT NdisRequest(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_REQUEST NdisRequest)
Definition: protocol.c:1239
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
void DPRINT(...)
Definition: polytest.cpp:61
NDIS_HANDLE PacketPoolHandle
Definition: ndisuio.h:33
KSPIN_LOCK GlobalAdapterListLock
Definition: main.c:16
Status
Definition: gdiplustypes.h:24
#define PROTOCOL_RESERVED_SIZE_IN_PACKET
Definition: ndis.h:1540
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
UNICODE_STRING DeviceName
Definition: ndisuio.h:44
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
NDIS_HANDLE BindingHandle
Definition: ndisuio.h:26
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
LIST_ENTRY ListEntry
Definition: ndisuio.h:47
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID EXPORT 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 OPTIONAL)
Definition: protocol.c:764
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:777
LIST_ENTRY GlobalAdapterList
Definition: main.c:17
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:793
#define DPRINT1
Definition: precomp.h:8
VOID EXPORT NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:703
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
LIST_ENTRY OpenEntryList
Definition: ndisuio.h:30
#define STATUS_SUCCESS
Definition: shellext.h:65
NDIS_HANDLE GlobalProtocolHandle
Definition: main.c:15
VOID EXPORT NdisAllocateBufferPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
Definition: buffer.c:372
LIST_ENTRY PacketList
Definition: ndisuio.h:37
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by NduBindAdapter().

◆ 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 }
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
Status
Definition: gdiplustypes.h:24
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 }
_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:6013
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:581

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");
57  return NDIS_STATUS_SUCCESS;
58 
59  case NetEventSetPower:
60  ASSERT(NetPnPEvent->BufferLength >= sizeof(*PowerState));
61 
62  PowerState = NetPnPEvent->Buffer;
63  switch (*PowerState)
64  {
65  case NdisDeviceStateD0:
66  DPRINT1("NetPnPEvent: SetPower D0\n");
67  return NDIS_STATUS_SUCCESS;
68 
69  default:
70  DPRINT1("NetPnPEvent: SetPower state %d not supported\n", *PowerState);
71  return NDIS_STATUS_FAILURE;
72  }
73 
74  case NetEventQueryPower:
75  DPRINT1("NetPnPEvent: QueryPower\n");
76  return NDIS_STATUS_SUCCESS;
77 
79  DPRINT1("NetPnPEvent: CancelRemoveDevice\n");
80  return NDIS_STATUS_SUCCESS;
81 
83  DPRINT1("NetPnPEvent: Reconfigure\n");
84  return NDIS_STATUS_SUCCESS;
85 
86  case NetEventBindList:
87  DPRINT1("NetPnPEvent: BindList\n");
88  return NDIS_STATUS_SUCCESS;
89 
91  DPRINT("NetPnPEvent: BindsComplete\n");
92  return NDIS_STATUS_SUCCESS;
93 
95  DPRINT1("NetPnPEvent: PnPCapabilities\n");
96  return NDIS_STATUS_SUCCESS;
97 
98  default:
99  DPRINT1("NetPnPEvent unimplemented for net event 0x%x\n", NetPnPEvent->NetEvent);
100  return NDIS_STATUS_FAILURE;
101  }
102 }
enum _NDIS_DEVICE_POWER_STATE * PNDIS_DEVICE_POWER_STATE
_In_ NDIS_HANDLE _In_ PNET_PNP_EVENT NetPnPEvent
Definition: ndis.h:6081
void DPRINT(...)
Definition: polytest.cpp:61
#define ASSERT(a)
Definition: mode.c:45
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3032
#define DPRINT1
Definition: precomp.h:8
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

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 }
_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:6013
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:581

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,
207  PacketSize,
208  AdapterContext->MacOptions);
210  }
211  else
212  {
214  AdapterContext->BindingHandle,
215  MacReceiveContext,
216  0,
217  PacketSize,
218  Packet,
221  {
222  KeWaitForSingleObject(&AdapterContext->AsyncEvent,
223  Executive,
224  KernelMode,
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);
250  return NDIS_STATUS_RESOURCES;
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 */
261  ExInterlockedInsertTailList(&AdapterContext->PacketList,
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 }
_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:6013
Definition: ndisuio.h:65
_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:1331
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
unsigned char * PUCHAR
Definition: retypes.h:3
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
KSPIN_LOCK Spinlock
Definition: ndisuio.h:50
VOID CleanupAndFreePacket(PNDIS_PACKET Packet, BOOLEAN FreePool)
Definition: misc.c:83
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
int NDIS_STATUS
Definition: ntddndis.h:471
#define FALSE
Definition: types.h:117
UCHAR PacketData[1]
Definition: ndisuio.h:74
void DPRINT(...)
Definition: polytest.cpp:61
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
Status
Definition: gdiplustypes.h:24
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define NdisCopyLookaheadData(Destination, Source, Length, MacOptions)
Definition: ndis.h:3289
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
PNDIS_PACKET CreatePacketFromPoolBuffer(PNDISUIO_ADAPTER_CONTEXT AdapterContext, PVOID Buffer, ULONG BufferSize)
Definition: misc.c:52
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
NDIS_HANDLE BindingHandle
Definition: ndisuio.h:26
_In_ USHORT PacketSize
Definition: iofuncs.h:1056
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
ULONG PacketLength
Definition: ndisuio.h:68
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
LIST_ENTRY PacketList
Definition: ndisuio.h:37
LIST_ENTRY ListEntry
Definition: ndisuio.h:71
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

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 }
_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:6013
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:581

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 }
_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:6013
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:581

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 }
_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:6013
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:581

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 }
_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:6013
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
#define IO_NO_INCREMENT
Definition: iotypes.h:581

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 }
_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:6013
static NDIS_STATUS UnbindAdapterByContext(PNDISUIO_ADAPTER_CONTEXT AdapterContext)
Definition: protocol.c:299
Status
Definition: gdiplustypes.h:24

Referenced by DriverEntry().

◆ UnbindAdapterByContext()

static NDIS_STATUS UnbindAdapterByContext ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext)
static

Definition at line 299 of file protocol.c.

300 {
301  KIRQL OldIrql;
302  PLIST_ENTRY CurrentEntry;
303  PNDISUIO_OPEN_ENTRY OpenEntry;
304  PNDISUIO_PACKET_ENTRY PacketEntry;
306 
307  DPRINT("Unbinding adapter %wZ\n", &AdapterContext->DeviceName);
308 
309  /* FIXME: We don't do anything with outstanding reads */
310 
311  /* Remove the adapter context from the global list */
313  RemoveEntryList(&AdapterContext->ListEntry);
315 
316  /* Free the device name string */
317  RtlFreeUnicodeString(&AdapterContext->DeviceName);
318 
319  /* Invalidate all handles to this adapter */
320  CurrentEntry = AdapterContext->OpenEntryList.Flink;
321  while (CurrentEntry != &AdapterContext->OpenEntryList)
322  {
323  OpenEntry = CONTAINING_RECORD(CurrentEntry, NDISUIO_OPEN_ENTRY, ListEntry);
324 
325  /* Make sure the entry is sane */
326  ASSERT(OpenEntry->FileObject);
327 
328  /* Remove the adapter context pointer */
329  ASSERT(AdapterContext == OpenEntry->FileObject->FsContext);
330  OpenEntry->FileObject->FsContext = NULL;
331  AdapterContext->OpenCount--;
332 
333  /* Remove the open entry pointer */
334  ASSERT(OpenEntry == OpenEntry->FileObject->FsContext2);
335  OpenEntry->FileObject->FsContext2 = NULL;
336 
337  /* Move to the next entry */
338  CurrentEntry = CurrentEntry->Flink;
339 
340  /* Free the open entry */
341  ExFreePool(OpenEntry);
342  }
343 
344  /* If this fails, we have a refcount mismatch somewhere */
345  ASSERT(AdapterContext->OpenCount == 0);
346 
347  /* Free all pending packet entries */
348  CurrentEntry = AdapterContext->PacketList.Flink;
349  while (CurrentEntry != &AdapterContext->PacketList)
350  {
351  PacketEntry = CONTAINING_RECORD(CurrentEntry, NDISUIO_PACKET_ENTRY, ListEntry);
352 
353  /* Move to the next entry */
354  CurrentEntry = CurrentEntry->Flink;
355 
356  /* Free the packet entry */
357  ExFreePool(PacketEntry);
358  }
359 
360  /* Send the close request */
362  AdapterContext->BindingHandle);
363 
364  /* Wait for a pending close */
366  {
367  KeWaitForSingleObject(&AdapterContext->AsyncEvent,
368  Executive,
369  KernelMode,
370  FALSE,
371  NULL);
372  Status = AdapterContext->AsyncStatus;
373  }
374 
375  /* Free the context */
376  ExFreePool(AdapterContext);
377 
378  return Status;
379 }
Definition: ndisuio.h:65
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
int NDIS_STATUS
Definition: ntddndis.h:471
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
Definition: ndisuio.h:53
void DPRINT(...)
Definition: polytest.cpp:61
KSPIN_LOCK GlobalAdapterListLock
Definition: main.c:16
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
PFILE_OBJECT FileObject
Definition: ndisuio.h:56
UNICODE_STRING DeviceName
Definition: ndisuio.h:44
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: typedefs.h:119
NDIS_HANDLE BindingHandle
Definition: ndisuio.h:26
LIST_ENTRY ListEntry
Definition: ndisuio.h:47
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
VOID EXPORT NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:703
LIST_ENTRY OpenEntryList
Definition: ndisuio.h:30
LIST_ENTRY PacketList
Definition: ndisuio.h:37
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by NduUnbindAdapter().