ReactOS  0.4.14-dev-583-g2a1ba2c
info.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/net/afd/afd/info.c
5  * PURPOSE: Ancillary functions driver
6  * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
7  * UPDATE HISTORY:
8  * 20040708 Created
9  */
10 
11 #include "afd.h"
12 
17  PAFD_INFO InfoReq = LockRequest(Irp, IrpSp, TRUE, NULL);
19  PAFD_FCB FCB = FileObject->FsContext;
20  PLIST_ENTRY CurrentEntry;
21 
23 
24  AFD_DbgPrint(MID_TRACE,("Called %p %x\n", InfoReq,
25  InfoReq ? InfoReq->InformationClass : 0));
26 
27  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
28 
29  if (!InfoReq)
31 
32  _SEH2_TRY {
33  switch( InfoReq->InformationClass ) {
35  InfoReq->Information.Ulong = FCB->Recv.Size;
36  break;
37 
39  InfoReq->Information.Ulong = FCB->Send.Size;
40  AFD_DbgPrint(MID_TRACE,("Send window size %u\n", FCB->Send.Size));
41  break;
42 
44  InfoReq->Information.LargeInteger.u.HighPart = FCB->GroupType;
45  InfoReq->Information.LargeInteger.u.LowPart = FCB->GroupID;
46  AFD_DbgPrint(MID_TRACE, ("Group ID: %u Group Type: %u\n", FCB->GroupID, FCB->GroupType));
47  break;
48 
50  InfoReq->Information.Boolean = FCB->NonBlocking;
51  break;
52 
54  InfoReq->Information.Boolean = FCB->OobInline;
55  break;
56 
58  InfoReq->Information.Ulong = FCB->Recv.Content - FCB->Recv.BytesUsed;
59  break;
60 
62  InfoReq->Information.Ulong = 0;
63 
64  /* Count the queued sends */
65  CurrentEntry = FCB->PendingIrpList[FUNCTION_SEND].Flink;
66  while (CurrentEntry != &FCB->PendingIrpList[FUNCTION_SEND])
67  {
68  InfoReq->Information.Ulong++;
69  CurrentEntry = CurrentEntry->Flink;
70  }
71 
72  /* This needs to count too because when this is dispatched
73  * the user-mode IRP has already been completed and therefore
74  * will NOT be in our pending IRP list. We count this as one send
75  * outstanding although it could be multiple since we batch sends
76  * when waiting for the in flight request to return, so this number
77  * may not be accurate but it really doesn't matter that much since
78  * it's more or less a zero/non-zero comparison to determine whether
79  * we can shutdown the socket
80  */
81  if (FCB->SendIrp.InFlightRequest)
82  InfoReq->Information.Ulong++;
83  break;
84 
85  default:
86  AFD_DbgPrint(MIN_TRACE,("Unknown info id %x\n",
87  InfoReq->InformationClass));
89  break;
90  }
92  AFD_DbgPrint(MIN_TRACE,("Exception executing GetInfo\n"));
94  } _SEH2_END;
95 
96  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
97 
98  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
99 }
100 
105  PAFD_INFO InfoReq = LockRequest(Irp, IrpSp, FALSE, NULL);
107  PAFD_FCB FCB = FileObject->FsContext;
108  PCHAR NewBuffer;
109 
111 
112  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
113 
114  if (!InfoReq)
116 
117  _SEH2_TRY {
118  switch (InfoReq->InformationClass) {
120  AFD_DbgPrint(MID_TRACE,("Blocking mode set to %u\n", InfoReq->Information.Boolean));
121  FCB->NonBlocking = InfoReq->Information.Boolean;
122  break;
124  FCB->OobInline = InfoReq->Information.Boolean;
125  break;
127  if (FCB->State == SOCKET_STATE_CONNECTED ||
129  {
130  /* FIXME: likely not right, check tcpip.sys for TDI_QUERY_MAX_DATAGRAM_INFO */
131  if (InfoReq->Information.Ulong > 0 && InfoReq->Information.Ulong < 0xFFFF &&
132  InfoReq->Information.Ulong != FCB->Recv.Size)
133  {
134  NewBuffer = ExAllocatePoolWithTag(PagedPool,
135  InfoReq->Information.Ulong,
137 
138  if (NewBuffer)
139  {
140  if (FCB->Recv.Content > InfoReq->Information.Ulong)
141  FCB->Recv.Content = InfoReq->Information.Ulong;
142 
143  if (FCB->Recv.Window)
144  {
145  RtlCopyMemory(NewBuffer,
146  FCB->Recv.Window,
147  FCB->Recv.Content);
148 
150  }
151 
152  FCB->Recv.Size = InfoReq->Information.Ulong;
153  FCB->Recv.Window = NewBuffer;
154 
156  }
157  else
158  {
160  }
161  }
162  else
163  {
165  }
166  }
167  else
168  {
170  }
171  break;
173  if (FCB->State == SOCKET_STATE_CONNECTED ||
175  {
176  if (InfoReq->Information.Ulong > 0 && InfoReq->Information.Ulong < 0xFFFF &&
177  InfoReq->Information.Ulong != FCB->Send.Size)
178  {
179  NewBuffer = ExAllocatePoolWithTag(PagedPool,
180  InfoReq->Information.Ulong,
182 
183  if (NewBuffer)
184  {
185  if (FCB->Send.BytesUsed > InfoReq->Information.Ulong)
186  FCB->Send.BytesUsed = InfoReq->Information.Ulong;
187 
188  if (FCB->Send.Window)
189  {
190  RtlCopyMemory(NewBuffer,
191  FCB->Send.Window,
192  FCB->Send.BytesUsed);
193 
195  }
196 
197  FCB->Send.Size = InfoReq->Information.Ulong;
198  FCB->Send.Window = NewBuffer;
199 
201  }
202  else
203  {
205  }
206  }
207  else
208  {
210  }
211  }
212  else
213  {
215  }
216  break;
217  default:
218  AFD_DbgPrint(MIN_TRACE,("Unknown request %u\n", InfoReq->InformationClass));
219  break;
220  }
222  AFD_DbgPrint(MIN_TRACE,("Exception executing SetInfo\n"));
224  } _SEH2_END;
225 
226  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
227 
228  return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
229 }
230 
236  PAFD_FCB FCB = FileObject->FsContext;
237  PMDL Mdl = NULL;
238 
240  ASSERT(Irp->MdlAddress == NULL);
241 
242  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
243 
244  if( FCB->AddressFile.Object == NULL && FCB->Connection.Object == NULL ) {
246  }
247 
248  Mdl = IoAllocateMdl( Irp->UserBuffer,
249  IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
250  FALSE,
251  FALSE,
252  NULL );
253 
254  if( Mdl != NULL ) {
255  _SEH2_TRY {
256  MmProbeAndLockPages( Mdl, Irp->RequestorMode, IoModifyAccess );
258  AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
260  } _SEH2_END;
261 
262  if( NT_SUCCESS(Status) ) {
263  Status = TdiQueryInformation( FCB->Connection.Object
264  ? FCB->Connection.Object
265  : FCB->AddressFile.Object,
267  Mdl );
268  }
269 
270  /* Check if MmProbeAndLockPages or TdiQueryInformation failed and
271  * clean up Mdl */
272  if (!NT_SUCCESS(Status) && Irp->MdlAddress != Mdl)
273  IoFreeMdl(Mdl);
274  } else
276 
277  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
278 }
279 
285  PAFD_FCB FCB = FileObject->FsContext;
286 
288 
289  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
290 
291  if (FCB->RemoteAddress == NULL) {
292  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
294  }
295 
296  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= TaLengthOfTransportAddress(FCB->RemoteAddress))
297  {
298  RtlCopyMemory(Irp->UserBuffer, FCB->RemoteAddress, TaLengthOfTransportAddress(FCB->RemoteAddress));
300  }
301  else
302  {
303  AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
305  }
306 
307  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
308 }
struct _LARGE_INTEGER::@2220 u
signed char * PCHAR
Definition: retypes.h:7
UINT TaLengthOfTransportAddress(PTRANSPORT_ADDRESS Addr)
Definition: tdiconn.c:46
#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
BOOLEAN Boolean
Definition: shared.h:33
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
NTSTATUS TdiQueryInformation(PFILE_OBJECT FileObject, LONG QueryType, PMDL MdlBuffer)
Definition: tdi.c:668
NTSTATUS NTAPI AfdSetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:102
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4250
#define TDI_QUERY_ADDRESS_INFO
Definition: tdi.h:181
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
LARGE_INTEGER LargeInteger
Definition: shared.h:32
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define AFD_INFO_SEND_WINDOW_SIZE
Definition: shared.h:186
Definition: afd.h:161
#define AFD_INFO_RECEIVE_CONTENT_SIZE
Definition: shared.h:188
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define FUNCTION_SEND
Definition: afd.h:86
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG InformationClass
Definition: shared.h:29
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
* PFILE_OBJECT
Definition: iotypes.h:1955
union _AFD_INFO::@3282 Information
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:532
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS NTAPI AfdGetSockName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:232
#define AFD_INFO_GROUP_ID_TYPE
Definition: shared.h:187
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define AFD_INFO_SENDS_IN_PROGRESS
Definition: shared.h:184
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#define AFD_INFO_INLINING_MODE
Definition: shared.h:182
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define AFD_INFO_RECEIVE_WINDOW_SIZE
Definition: shared.h:185
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI AfdGetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:14
ULONG Ulong
Definition: shared.h:31
NTSTATUS NTAPI AfdGetPeerName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:281