Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeninfo.c
Go to the documentation of this file.
00001 /* $Id: info.c 56389 2012-04-22 13:11:54Z tfaber $ 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: drivers/net/afd/afd/info.c 00005 * PURPOSE: Ancillary functions driver 00006 * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net) 00007 * UPDATE HISTORY: 00008 * 20040708 Created 00009 */ 00010 #include "afd.h" 00011 00012 NTSTATUS NTAPI 00013 AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp, 00014 PIO_STACK_LOCATION IrpSp ) { 00015 NTSTATUS Status = STATUS_SUCCESS; 00016 PAFD_INFO InfoReq = LockRequest(Irp, IrpSp); 00017 PFILE_OBJECT FileObject = IrpSp->FileObject; 00018 PAFD_FCB FCB = FileObject->FsContext; 00019 PLIST_ENTRY CurrentEntry; 00020 00021 AFD_DbgPrint(MID_TRACE,("Called %x %x\n", InfoReq, 00022 InfoReq ? InfoReq->InformationClass : 0)); 00023 00024 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp ); 00025 00026 if (!InfoReq) 00027 return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0); 00028 00029 _SEH2_TRY { 00030 switch( InfoReq->InformationClass ) { 00031 case AFD_INFO_RECEIVE_WINDOW_SIZE: 00032 InfoReq->Information.Ulong = FCB->Recv.Size; 00033 break; 00034 00035 case AFD_INFO_SEND_WINDOW_SIZE: 00036 InfoReq->Information.Ulong = FCB->Send.Size; 00037 AFD_DbgPrint(MID_TRACE,("Send window size %d\n", FCB->Send.Size)); 00038 break; 00039 00040 case AFD_INFO_GROUP_ID_TYPE: 00041 InfoReq->Information.LargeInteger.u.HighPart = FCB->GroupType; 00042 InfoReq->Information.LargeInteger.u.LowPart = FCB->GroupID; 00043 AFD_DbgPrint(MID_TRACE, ("Group ID: %d Group Type: %d\n", FCB->GroupID, FCB->GroupType)); 00044 break; 00045 00046 case AFD_INFO_BLOCKING_MODE: 00047 InfoReq->Information.Boolean = FCB->NonBlocking; 00048 break; 00049 00050 case AFD_INFO_INLINING_MODE: 00051 InfoReq->Information.Boolean = FCB->OobInline; 00052 break; 00053 00054 case AFD_INFO_RECEIVE_CONTENT_SIZE: 00055 /* Only touch InfoReq if a socket has been set up. 00056 Behaviour was verified under WinXP SP2. */ 00057 if(FCB->AddressFile.Object || FCB->Connection.Object) 00058 InfoReq->Information.Ulong = FCB->Recv.Content - FCB->Recv.BytesUsed; 00059 00060 break; 00061 00062 case AFD_INFO_SENDS_IN_PROGRESS: 00063 InfoReq->Information.Ulong = 0; 00064 00065 /* Count the queued sends */ 00066 CurrentEntry = FCB->PendingIrpList[FUNCTION_SEND].Flink; 00067 while (CurrentEntry != &FCB->PendingIrpList[FUNCTION_SEND]) 00068 { 00069 InfoReq->Information.Ulong++; 00070 CurrentEntry = CurrentEntry->Flink; 00071 } 00072 00073 /* This needs to count too because when this is dispatched 00074 * the user-mode IRP has already been completed and therefore 00075 * will NOT be in our pending IRP list. We count this as one send 00076 * outstanding although it could be multiple since we batch sends 00077 * when waiting for the in flight request to return, so this number 00078 * may not be accurate but it really doesn't matter that much since 00079 * it's more or less a zero/non-zero comparison to determine whether 00080 * we can shutdown the socket 00081 */ 00082 if (FCB->SendIrp.InFlightRequest) 00083 InfoReq->Information.Ulong++; 00084 break; 00085 00086 default: 00087 AFD_DbgPrint(MIN_TRACE,("Unknown info id %x\n", 00088 InfoReq->InformationClass)); 00089 Status = STATUS_INVALID_PARAMETER; 00090 break; 00091 } 00092 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { 00093 AFD_DbgPrint(MIN_TRACE,("Exception executing GetInfo\n")); 00094 Status = STATUS_INVALID_PARAMETER; 00095 } _SEH2_END; 00096 00097 AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status)); 00098 00099 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 ); 00100 } 00101 00102 NTSTATUS NTAPI 00103 AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp, 00104 PIO_STACK_LOCATION IrpSp ) { 00105 NTSTATUS Status = STATUS_SUCCESS; 00106 PAFD_INFO InfoReq = LockRequest(Irp, IrpSp); 00107 PFILE_OBJECT FileObject = IrpSp->FileObject; 00108 PAFD_FCB FCB = FileObject->FsContext; 00109 PCHAR NewBuffer; 00110 00111 if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp); 00112 00113 if (!InfoReq) 00114 return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0); 00115 00116 _SEH2_TRY { 00117 switch (InfoReq->InformationClass) { 00118 case AFD_INFO_BLOCKING_MODE: 00119 AFD_DbgPrint(MID_TRACE,("Blocking mode set to %d\n", InfoReq->Information.Boolean)); 00120 FCB->NonBlocking = InfoReq->Information.Boolean; 00121 break; 00122 case AFD_INFO_INLINING_MODE: 00123 FCB->OobInline = InfoReq->Information.Boolean; 00124 break; 00125 case AFD_INFO_RECEIVE_WINDOW_SIZE: 00126 NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong); 00127 if (NewBuffer) 00128 { 00129 if (FCB->Recv.Content > InfoReq->Information.Ulong) 00130 FCB->Recv.Content = InfoReq->Information.Ulong; 00131 00132 if (FCB->Recv.Window) 00133 { 00134 RtlCopyMemory(NewBuffer, 00135 FCB->Recv.Window, 00136 FCB->Recv.Content); 00137 00138 ExFreePool(FCB->Recv.Window); 00139 } 00140 00141 FCB->Recv.Size = InfoReq->Information.Ulong; 00142 FCB->Recv.Window = NewBuffer; 00143 00144 Status = STATUS_SUCCESS; 00145 } 00146 else 00147 { 00148 Status = STATUS_NO_MEMORY; 00149 } 00150 break; 00151 case AFD_INFO_SEND_WINDOW_SIZE: 00152 NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong); 00153 if (NewBuffer) 00154 { 00155 if (FCB->Send.BytesUsed > InfoReq->Information.Ulong) 00156 FCB->Send.BytesUsed = InfoReq->Information.Ulong; 00157 00158 if (FCB->Send.Window) 00159 { 00160 RtlCopyMemory(NewBuffer, 00161 FCB->Send.Window, 00162 FCB->Send.BytesUsed); 00163 00164 ExFreePool(FCB->Send.Window); 00165 } 00166 00167 FCB->Send.Size = InfoReq->Information.Ulong; 00168 FCB->Send.Window = NewBuffer; 00169 00170 Status = STATUS_SUCCESS; 00171 } 00172 else 00173 { 00174 Status = STATUS_NO_MEMORY; 00175 } 00176 break; 00177 default: 00178 AFD_DbgPrint(MIN_TRACE,("Unknown request %d\n", InfoReq->InformationClass)); 00179 break; 00180 } 00181 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { 00182 AFD_DbgPrint(MIN_TRACE,("Exception executing SetInfo\n")); 00183 Status = STATUS_INVALID_PARAMETER; 00184 } _SEH2_END; 00185 00186 AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status)); 00187 00188 return UnlockAndMaybeComplete(FCB, Status, Irp, 0); 00189 } 00190 00191 NTSTATUS NTAPI 00192 AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp, 00193 PIO_STACK_LOCATION IrpSp ) { 00194 NTSTATUS Status = STATUS_SUCCESS; 00195 PFILE_OBJECT FileObject = IrpSp->FileObject; 00196 PAFD_FCB FCB = FileObject->FsContext; 00197 PMDL Mdl = NULL; 00198 00199 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp ); 00200 00201 if( FCB->AddressFile.Object == NULL && FCB->Connection.Object == NULL ) { 00202 return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0 ); 00203 } 00204 00205 Mdl = IoAllocateMdl( Irp->UserBuffer, 00206 IrpSp->Parameters.DeviceIoControl.OutputBufferLength, 00207 FALSE, 00208 FALSE, 00209 NULL ); 00210 00211 if( Mdl != NULL ) { 00212 _SEH2_TRY { 00213 MmProbeAndLockPages( Mdl, Irp->RequestorMode, IoModifyAccess ); 00214 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { 00215 AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n")); 00216 Status = _SEH2_GetExceptionCode(); 00217 } _SEH2_END; 00218 00219 if( NT_SUCCESS(Status) ) { 00220 Status = TdiQueryInformation( FCB->Connection.Object 00221 ? FCB->Connection.Object 00222 : FCB->AddressFile.Object, 00223 TDI_QUERY_ADDRESS_INFO, 00224 Mdl ); 00225 } 00226 } else 00227 Status = STATUS_INSUFFICIENT_RESOURCES; 00228 00229 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 ); 00230 } 00231 00232 NTSTATUS NTAPI 00233 AfdGetPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp, 00234 PIO_STACK_LOCATION IrpSp ) { 00235 NTSTATUS Status; 00236 PFILE_OBJECT FileObject = IrpSp->FileObject; 00237 PAFD_FCB FCB = FileObject->FsContext; 00238 00239 00240 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp ); 00241 00242 if (FCB->RemoteAddress == NULL) { 00243 AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n")); 00244 return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0 ); 00245 } 00246 00247 if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= TaLengthOfTransportAddress(FCB->RemoteAddress)) 00248 { 00249 RtlCopyMemory(Irp->UserBuffer, FCB->RemoteAddress, TaLengthOfTransportAddress(FCB->RemoteAddress)); 00250 Status = STATUS_SUCCESS; 00251 } 00252 else 00253 { 00254 AFD_DbgPrint(MIN_TRACE,("Buffer too small\n")); 00255 Status = STATUS_BUFFER_TOO_SMALL; 00256 } 00257 00258 return UnlockAndMaybeComplete( FCB, Status, Irp, 0 ); 00259 } Generated on Sat May 26 2012 04:23:13 for ReactOS by
1.7.6.1
|