ReactOS  0.4.10-dev-348-gbcec1fd
event.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Ancillary Function Driver
4  * FILE: afd/event.c
5  * PURPOSE: TDI event handlers
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * REVISIONS:
8  * CSH 01/09-2000 Created
9  */
10 
11 #include <afd.h>
12 
14  IN PVOID TdiEventContext,
16 {
17  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
18 
19  return STATUS_SUCCESS;
20 }
21 
22 
24  IN PVOID TdiEventContext,
25  IN CONNECTION_CONTEXT ConnectionContext,
26  IN LONG DisconnectDataLength,
27  IN PVOID DisconnectData,
28  IN LONG DisconnectInformationLength,
29  IN PVOID DisconnectInformation,
30  IN ULONG DisconnectFlags)
31 {
32  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
33 
34  return STATUS_SUCCESS;
35 }
36 
37 
39  IN PVOID TdiEventContext,
40  IN CONNECTION_CONTEXT ConnectionContext,
41  IN ULONG ReceiveFlags,
42  IN ULONG BytesIndicated,
43  IN ULONG BytesAvailable,
44  OUT ULONG *BytesTaken,
45  IN PVOID Tsdu,
46  OUT PIRP *IoRequestPacket)
47 {
48  PAFDFCB FCB = (PAFDFCB)TdiEventContext;
49  PVOID ReceiveBuffer;
50  PAFD_BUFFER Buffer;
51  KIRQL OldIrql;
52 
53  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
54 
55  AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes on socket\n",
56  BytesAvailable));
57 
58  ReceiveBuffer = ExAllocatePoolWithTag(NonPagedPool,
59  BytesAvailable,
61 
62  if (!ReceiveBuffer)
64 
65  /*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
66  &BufferLookasideList);*/
67  Buffer = (PAFD_BUFFER)ExAllocatePoolWithTag(NonPagedPool,
68  sizeof(AFD_BUFFER),
70 
71  if (!Buffer) {
72  ExFreePoolWithTag(ReceiveBuffer, TAG_AFD_DATA_BUFFER);
74  }
75 
76  /* Copy the data to a local buffer */
77  RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
78 
79  Buffer->Buffer.len = BytesAvailable;
80  Buffer->Buffer.buf = ReceiveBuffer;
81  Buffer->Offset = 0;
82 
83  KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
84 
85  InsertTailList( &FCB->ReceiveQueue, &Buffer->ListEntry );
86 
87  TryToSatisfyRecvRequest( FCB, TRUE );
88 
89  KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
90 
91  *BytesTaken = BytesAvailable;
92 
93  AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
94 
95  return STATUS_SUCCESS;
96 }
97 
98 
100  IN PVOID TdiEventContext,
101  IN CONNECTION_CONTEXT ConnectionContext,
102  IN ULONG ReceiveFlags,
103  IN ULONG BytesIndicated,
104  IN ULONG BytesAvailable,
105  OUT ULONG *BytesTaken,
106  IN PVOID Tsdu,
107  OUT PIRP *IoRequestPacket)
108 {
109  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
110 
111  return STATUS_SUCCESS;
112 }
113 
114 
116  IN PVOID TdiEventContext,
117  IN CONNECTION_CONTEXT ConnectionContext,
118  IN ULONG ReceiveFlags,
119  IN ULONG ReceiveLength,
121  IN PMDL Tsdu,
122  IN PVOID TsduDescriptor)
123 {
124  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
125 
126  return STATUS_SUCCESS;
127 }
128 
129 
131  IN PVOID TdiEventContext,
132  IN LONG SourceAddressLength,
134  IN LONG OptionsLength,
135  IN PVOID Options,
136  IN ULONG ReceiveDatagramFlags,
137  IN ULONG BytesIndicated,
138  IN ULONG BytesAvailable,
139  OUT ULONG *BytesTaken,
140  IN PVOID Tsdu,
141  OUT PIRP *IoRequestPacket)
142 {
143  PAFDFCB FCB = (PAFDFCB)TdiEventContext;
144  PAFD_READ_REQUEST ReadRequest;
145  PVOID ReceiveBuffer;
146  PAFD_BUFFER Buffer;
149  KIRQL OldIrql;
150  ULONG Count;
152 
153  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
154 
155  AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes from (0x%X).\n",
156  BytesAvailable, *(PULONG)SourceAddress));
157 
158  ReceiveBuffer = ExAllocatePoolWithTag(NonPagedPool,
159  BytesAvailable,
161 
162  if (!ReceiveBuffer)
164 
165  /*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
166  &BufferLookasideList);*/
167  Buffer = (PAFD_BUFFER)ExAllocatePoolWithTag(NonPagedPool,
168  sizeof(AFD_BUFFER),
170 
171  if (!Buffer) {
172  ExFreePoolWithTag(ReceiveBuffer, TAG_AFD_DATA_BUFFER);
174  }
175 
176  /* Copy the data to a local buffer */
177  RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
178 
179  Buffer->Buffer.len = BytesAvailable;
180  Buffer->Buffer.buf = ReceiveBuffer;
181  Buffer->Offset = 0;
182 
183  ExInterlockedInsertTailList(&FCB->ReceiveQueue,
184  &Buffer->ListEntry,
185  &FCB->ReceiveQueueLock);
186 
187  KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
188 
189  if (CompleteIrp = !IsListEmpty(&FCB->ReadRequestQueue)) {
190  AFD_DbgPrint(MAX_TRACE, ("Satisfying read request.\n"));
191 
192  Entry = RemoveHeadList(&FCB->ReceiveQueue);
193  ReadRequest = CONTAINING_RECORD(Entry, AFD_READ_REQUEST, ListEntry);
194 
195  Status = FillWSABuffers(FCB,
196  ReadRequest->RecvFromRequest->Buffers,
197  ReadRequest->RecvFromRequest->BufferCount,
198  &Count,
199  FALSE); /* Packet oriented */
200  ReadRequest->RecvFromReply->NumberOfBytesRecvd = Count;
201  ReadRequest->RecvFromReply->Status = NO_ERROR;
202 
203  ReadRequest->Irp->IoStatus.Information = 0;
204  ReadRequest->Irp->IoStatus.Status = Status;
205  }
206 
207  KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
208 
209  if (CompleteIrp) {
210  AFD_DbgPrint(MAX_TRACE, ("Completing IRP at (0x%X).\n", ReadRequest->Irp));
211  IoCompleteRequest(ReadRequest->Irp, IO_NETWORK_INCREMENT);
212  *BytesTaken = BytesAvailable;
213  }
214 
215  AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
216 
217  return STATUS_SUCCESS;
218 }
219 
220 
222  PAFDFCB FCB)
223 {
225 
226  assert(FCB->TdiAddressObject);
227 
228  /* Report errors for all types of sockets */
229  Status = TdiSetEventHandler(FCB->TdiAddressObject,
232  (PVOID)FCB);
233  if (!NT_SUCCESS(Status)) { return Status; }
234 
235  switch (FCB->SocketType) {
236  case SOCK_STREAM:
237  Status = TdiSetEventHandler(FCB->TdiAddressObject,
240  (PVOID)FCB);
241  if (!NT_SUCCESS(Status)) { return Status; }
242 
243  Status = TdiSetEventHandler(FCB->TdiAddressObject,
246  (PVOID)FCB);
247  if (!NT_SUCCESS(Status)) { return Status; }
248 
249  Status = TdiSetEventHandler(FCB->TdiAddressObject,
252  (PVOID)FCB);
253  if (!NT_SUCCESS(Status)) { return Status; }
254 
255  Status = TdiSetEventHandler(FCB->TdiAddressObject,
258  (PVOID)FCB);
259  if (!NT_SUCCESS(Status)) { return Status; }
260  break;
261 
262  case SOCK_DGRAM:
263  case SOCK_RAW:
264  Status = TdiSetEventHandler(FCB->TdiAddressObject,
267  (PVOID)FCB);
268  if (!NT_SUCCESS(Status)) { return Status; }
269  }
270  return STATUS_SUCCESS;
271 }
272 
273 
275  PAFDFCB FCB)
276 {
278 
279  Status = TdiSetEventHandler(FCB->TdiAddressObject,
281  NULL,
282  NULL);
283  if (!NT_SUCCESS(Status)) { return Status; }
284 
285  switch (FCB->SocketType) {
286  case SOCK_STREAM:
287  Status = TdiSetEventHandler(FCB->TdiAddressObject,
289  NULL,
290  NULL);
291  if (!NT_SUCCESS(Status)) { return Status; }
292 
293  Status = TdiSetEventHandler(FCB->TdiAddressObject,
295  NULL,
296  NULL);
297  if (!NT_SUCCESS(Status)) { return Status; }
298 
299  Status = TdiSetEventHandler(FCB->TdiAddressObject,
301  NULL,
302  NULL);
303  if (!NT_SUCCESS(Status)) { return Status; }
304 
305  Status = TdiSetEventHandler(FCB->TdiAddressObject,
307  NULL,
308  NULL);
309  if (!NT_SUCCESS(Status)) { return Status; }
310  break;
311 
312  case SOCK_DGRAM:
313  case SOCK_RAW:
314  Status = TdiSetEventHandler(FCB->TdiAddressObject,
316  NULL,
317  NULL);
318  if (!NT_SUCCESS(Status)) { return Status; }
319  }
320  return STATUS_SUCCESS;
321 }
322 
323 /* EOF */
DWORD *typedef PVOID
Definition: winlogon.h:52
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS AfdRegisterEventHandlers(PAFDFCB FCB)
Definition: event.c:221
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
struct _Entry Entry
Definition: kefuncs.h:640
Definition: cdfs.h:197
return STATUS_SUCCESS
Definition: btrfs.c:2690
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define TDI_EVENT_RECEIVE_EXPEDITED
Definition: tdikrnl.h:151
#define TDI_EVENT_DISCONNECT
Definition: tdikrnl.h:147
#define assert(x)
Definition: debug.h:53
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
LONG TDI_STATUS
Definition: tdi.h:36
NTSTATUS AfdEventDisconnect(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN LONG DisconnectDataLength, IN PVOID DisconnectData, IN LONG DisconnectInformationLength, IN PVOID DisconnectInformation, IN ULONG DisconnectFlags)
Definition: event.c:23
#define InsertTailList(ListHead, Entry)
#define NO_ERROR
Definition: dderror.h:5
PVOID PMDL
Definition: usb.h:39
enum OPTION_FLAGS Options
Definition: stats.c:44
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
TDI_STATUS ClientEventReceiveExpedited(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
Definition: event.c:99
VOID CompleteIrp(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: pnp.c:12
#define SOCK_RAW
Definition: winsock.h:337
NTSTATUS AfdEventReceive(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
Definition: event.c:38
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define TDI_EVENT_RECEIVE
Definition: tdikrnl.h:149
NTSTATUS TdiSetEventHandler(PFILE_OBJECT FileObject, LONG EventType, PVOID Handler, PVOID Context)
Definition: tdi.c:546
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
PVOID CONNECTION_CONTEXT
Definition: tdi.h:37
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
NTSTATUS AfdEventError(IN PVOID TdiEventContext, IN NTSTATUS Status)
Definition: event.c:13
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
#define TDI_EVENT_CHAINED_RECEIVE
Definition: tdikrnl.h:153
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
NTSTATUS AfdDeregisterEventHandlers(PAFDFCB FCB)
Definition: event.c:274
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
UINTN VOID * Buffer
Definition: acefiex.h:370
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
#define TDI_EVENT_RECEIVE_DATAGRAM
Definition: tdikrnl.h:150
Status
Definition: gdiplustypes.h:24
NTSTATUS AfdEventReceiveDatagramHandler(IN PVOID TdiEventContext, IN LONG SourceAddressLength, IN PVOID SourceAddress, IN LONG OptionsLength, IN PVOID Options, IN ULONG ReceiveDatagramFlags, IN ULONG BytesIndicated, IN ULONG BytesAvailable, OUT ULONG *BytesTaken, IN PVOID Tsdu, OUT PIRP *IoRequestPacket)
Definition: event.c:130
#define MAX_TRACE
Definition: debug.h:16
unsigned int * PULONG
Definition: retypes.h:1
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
NTSTATUS ClientEventChainedReceive(IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG ReceiveLength, IN ULONG StartingOffset, IN PMDL Tsdu, IN PVOID TsduDescriptor)
Definition: event.c:115
#define OUT
Definition: typedefs.h:39
PVOID PIRP
Definition: usb.h:38
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define SOCK_STREAM
Definition: tcpip.h:118
#define SOCK_DGRAM
Definition: winsock.h:336
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS SourceAddress
Definition: iotypes.h:1089
#define TDI_EVENT_ERROR
Definition: tdikrnl.h:148