ReactOS 0.4.15-dev-7842-g558ab78
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
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 {
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 {
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
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}
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define FUNCTION_SEND
Definition: afd.h:86
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
NTSTATUS NTAPI AfdSetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:102
NTSTATUS NTAPI AfdGetSockName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:232
NTSTATUS NTAPI AfdGetInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:14
NTSTATUS NTAPI AfdGetPeerName(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: info.c:281
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS TdiQueryInformation(PFILE_OBJECT FileObject, LONG QueryType, PMDL MdlBuffer)
Definition: tdi.c:668
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define AFD_INFO_SEND_WINDOW_SIZE
Definition: shared.h:186
#define AFD_INFO_RECEIVE_WINDOW_SIZE
Definition: shared.h:185
#define AFD_INFO_RECEIVE_CONTENT_SIZE
Definition: shared.h:188
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
#define AFD_INFO_SENDS_IN_PROGRESS
Definition: shared.h:184
#define AFD_INFO_INLINING_MODE
Definition: shared.h:182
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
#define AFD_INFO_GROUP_ID_TYPE
Definition: shared.h:187
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
Definition: afd.h:159
ULONG InformationClass
Definition: shared.h:29
ULONG Ulong
Definition: shared.h:31
union _AFD_INFO::@3381 Information
BOOLEAN Boolean
Definition: shared.h:33
LARGE_INTEGER LargeInteger
Definition: shared.h:32
Definition: cdstruc.h:902
ULONG Flags
Definition: ntfs.h:536
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TDI_QUERY_ADDRESS_INFO
Definition: tdi.h:181
UINT TaLengthOfTransportAddress(PTRANSPORT_ADDRESS Addr)
Definition: tdiconn.c:46
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _LARGE_INTEGER::@2290 u
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
* PFILE_OBJECT
Definition: iotypes.h:1998
@ IoModifyAccess
Definition: ketypes.h:865