ReactOS 0.4.16-dev-197-g92996da
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 {
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);
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,
458 0,
459 NULL);
460
461 /* Wait for a pending open */
463 {
464 KeWaitForSingleObject(&AdapterContext->AsyncEvent,
465 Executive,
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 */
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,
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,
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}
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
VOID EXPORT NdisAllocateBufferPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
Definition: buffer.c:372
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:777
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:793
VOID EXPORT NdisAllocatePacketPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:421
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 NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:703
NDIS_HANDLE GlobalProtocolHandle
Definition: main.c:15
LIST_ENTRY GlobalAdapterList
Definition: main.c:17
KSPIN_LOCK GlobalAdapterListLock
Definition: main.c:16
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
unsigned int UINT
Definition: ndis.h:50
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define PROTOCOL_RESERVED_SIZE_IN_PACKET
Definition: ndis.h:1540
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6009
_In_opt_ NDIS_HANDLE _In_opt_ NDIS_HANDLE _Inout_ PNDIS_REQUEST NdisRequest
Definition: ndis.h:1573
@ NdisRequestQueryInformation
Definition: ndis.h:790
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define KernelMode
Definition: asm.h:34
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
enum _NDIS_MEDIUM NDIS_MEDIUM
@ NdisMedium802_3
Definition: ntddndis.h:188
int NDIS_STATUS
Definition: ntddndis.h:475
#define OID_GEN_MAC_OPTIONS
Definition: ntddndis.h:251
@ SynchronizationEvent
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
LIST_ENTRY OpenEntryList
Definition: ndisuio.h:30
NDIS_STATUS AsyncStatus
Definition: ndisuio.h:22
LIST_ENTRY PacketList
Definition: ndisuio.h:37
NDIS_HANDLE PacketPoolHandle
Definition: ndisuio.h:33
KSPIN_LOCK Spinlock
Definition: ndisuio.h:50
LIST_ENTRY ListEntry
Definition: ndisuio.h:47
NDIS_HANDLE BufferPoolHandle
Definition: ndisuio.h:34
UNICODE_STRING DeviceName
Definition: ndisuio.h:44
NDIS_HANDLE BindingHandle
Definition: ndisuio.h:26
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
@ Executive
Definition: ketypes.h:415

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}
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 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 IO_NO_INCREMENT
Definition: iotypes.h:598

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 ASSERT(a)
Definition: mode.c:44
#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
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 IO_NETWORK_INCREMENT
Definition: tcpip.h:43
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NdisCopyLookaheadData(Destination, Source, Length, MacOptions)
Definition: ndis.h:3289
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
Definition: ndisuio.h:66
UCHAR PacketData[1]
Definition: ndisuio.h:74
LIST_ENTRY ListEntry
Definition: ndisuio.h:71
ULONG PacketLength
Definition: ndisuio.h:68
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().

◆ UnbindAdapterByContext()

static NDIS_STATUS UnbindAdapterByContext ( PNDISUIO_ADAPTER_CONTEXT  AdapterContext)
static

Definition at line 299 of file protocol.c.

300{
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,
370 FALSE,
371 NULL);
372 Status = AdapterContext->AsyncStatus;
373 }
374
375 /* Free the context */
376 ExFreePool(AdapterContext);
377
378 return Status;
379}
#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
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: ndisuio.h:54
PFILE_OBJECT FileObject
Definition: ndisuio.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by NduUnbindAdapter().