Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
6.5 KiB

  1. /***************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Dot4Usb.sys - Lower Filter Driver for Dot4.sys for USB connected
  5. IEEE 1284.4 devices.
  6. File Name:
  7. ReadWrit.c
  8. Abstract:
  9. Dispatch routines for IRP_MJ_READ and IRP_MJ_WRITE
  10. Environment:
  11. Kernel mode only
  12. Notes:
  13. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  14. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  16. PURPOSE.
  17. Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  18. Revision History:
  19. 01/18/2000 : created
  20. ToDo in this file:
  21. - IoReleaseRemoveLock() calls need to be moved to USB completion routine
  22. - code review w/Joby
  23. Author(s):
  24. Doug Fritz (DFritz)
  25. Joby Lafky (JobyL)
  26. ****************************************************************************/
  27. #include "pch.h"
  28. /************************************************************************/
  29. /* DispatchRead */
  30. /************************************************************************/
  31. //
  32. // Routine Description:
  33. //
  34. // Dispatch routine for IRP_MJ_READ - Validate parameters and forward
  35. // valid requests to USB handler.
  36. //
  37. // Arguments:
  38. //
  39. // DevObj - pointer to Device Object that is the target of the request
  40. // Irp - pointer to read request
  41. //
  42. // Return Value:
  43. //
  44. // NTSTATUS
  45. //
  46. /************************************************************************/
  47. NTSTATUS
  48. DispatchRead(
  49. IN PDEVICE_OBJECT DevObj,
  50. IN PIRP Irp
  51. )
  52. {
  53. PDEVICE_EXTENSION devExt = DevObj->DeviceExtension;
  54. NTSTATUS status;
  55. PUSBD_PIPE_INFORMATION pipe;
  56. BOOLEAN bReleaseRemLockOnFail = FALSE;
  57. TR_VERBOSE(("DispatchRead - enter"));
  58. status = IoAcquireRemoveLock( &devExt->RemoveLock, Irp );
  59. if( STATUS_SUCCESS != status ) {
  60. // couldn't aquire RemoveLock - FAIL request
  61. bReleaseRemLockOnFail = FALSE;
  62. goto targetFail;
  63. }
  64. bReleaseRemLockOnFail = TRUE; // We now have the RemoveLock
  65. if( !Irp->MdlAddress ) {
  66. // no MDL - FAIL request
  67. status = STATUS_INVALID_PARAMETER;
  68. goto targetFail;
  69. }
  70. if( !MmGetMdlByteCount(Irp->MdlAddress) ) {
  71. // zero length MDL - FAIL request
  72. status = STATUS_INVALID_PARAMETER;
  73. goto targetFail;
  74. }
  75. pipe = devExt->ReadPipe;
  76. if( !pipe ) {
  77. // we don't have a read pipe? - something is seriously wrong
  78. D4UAssert(FALSE);
  79. status = STATUS_UNSUCCESSFUL;
  80. goto targetFail;
  81. }
  82. if( UsbdPipeTypeBulk != pipe->PipeType ) {
  83. // our read pipe is not a bulk pipe?
  84. D4UAssert(FALSE);
  85. status = STATUS_UNSUCCESSFUL;
  86. goto targetFail;
  87. }
  88. //
  89. // If we got here we survived the sanity checks - continue processing
  90. //
  91. status = UsbReadWrite( DevObj, Irp, pipe, UsbReadRequest );
  92. //IoReleaseRemoveLock( &devExt->RemoveLock, Irp ); // Moved this to completion routine
  93. goto targetExit;
  94. targetFail:
  95. Irp->IoStatus.Status = status;
  96. IoCompleteRequest( Irp, IO_NO_INCREMENT );
  97. if( bReleaseRemLockOnFail ) {
  98. IoReleaseRemoveLock( &devExt->RemoveLock, Irp );
  99. }
  100. targetExit:
  101. return status;
  102. }
  103. /************************************************************************/
  104. /* DispatchWrite */
  105. /************************************************************************/
  106. //
  107. // Routine Description:
  108. //
  109. // Dispatch routine for IRP_MJ_WRITE - Validate parameters and forward
  110. // valid requests to USB handler.
  111. //
  112. // Arguments:
  113. //
  114. // DevObj - pointer to Device Object that is the target of the request
  115. // Irp - pointer to write request
  116. //
  117. // Return Value:
  118. //
  119. // NTSTATUS
  120. //
  121. /************************************************************************/
  122. NTSTATUS
  123. DispatchWrite(
  124. IN PDEVICE_OBJECT DevObj,
  125. IN PIRP Irp
  126. )
  127. {
  128. PDEVICE_EXTENSION devExt = DevObj->DeviceExtension;
  129. NTSTATUS status;
  130. PUSBD_PIPE_INFORMATION pipe;
  131. BOOLEAN bReleaseRemLockOnFail;
  132. TR_VERBOSE(("DispatchWrite - enter"));
  133. status = IoAcquireRemoveLock( &devExt->RemoveLock, Irp );
  134. if( STATUS_SUCCESS != status ) {
  135. // couldn't aquire RemoveLock - FAIL request
  136. bReleaseRemLockOnFail = FALSE;
  137. goto targetFail;
  138. }
  139. bReleaseRemLockOnFail = TRUE; // We now have the RemoveLock
  140. if( !Irp->MdlAddress ) {
  141. // no MDL - FAIL request
  142. status = STATUS_INVALID_PARAMETER;
  143. goto targetFail;
  144. }
  145. if( !MmGetMdlByteCount(Irp->MdlAddress) ) {
  146. // zero length MDL - FAIL request
  147. status = STATUS_INVALID_PARAMETER;
  148. goto targetFail;
  149. }
  150. pipe = devExt->WritePipe;
  151. if( !pipe ) {
  152. // we don't have a write pipe? - something is seriously wrong - FAIL request
  153. D4UAssert(FALSE);
  154. status = STATUS_UNSUCCESSFUL;
  155. goto targetFail;
  156. }
  157. if( UsbdPipeTypeBulk != pipe->PipeType ) {
  158. // our write pipe is not a bulk pipe? - FAIL request
  159. D4UAssert(FALSE);
  160. status = STATUS_UNSUCCESSFUL;
  161. goto targetFail;
  162. }
  163. //
  164. // If we got here we survived the sanity checks - continue processing
  165. //
  166. status = UsbReadWrite( DevObj, Irp, pipe, UsbWriteRequest );
  167. // IoReleaseRemoveLock( &devExt->RemoveLock, Irp ); // moved this to completion routine
  168. goto targetExit;
  169. targetFail:
  170. Irp->IoStatus.Status = status;
  171. IoCompleteRequest( Irp, IO_NO_INCREMENT );
  172. if( bReleaseRemLockOnFail ) {
  173. IoReleaseRemoveLock( &devExt->RemoveLock, Irp );
  174. }
  175. targetExit:
  176. return status;
  177. }