24{
36
37
41 totalLength = 0;
45
47
48 if (deviceExtension->DeviceState !=
Working)
49 {
50 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: Invalid device state\n"));
52 goto FreeBT_DispatchRead_Exit;
53
54 }
55
56
57 if (deviceExtension->SSEnable)
58 {
59 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_DispatchRead: Waiting on the IdleReqPendEvent\n"));
65
66 }
67
69 if (rwContext ==
NULL)
70 {
71 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: Failed to alloc mem for rwContext\n"));
73 goto FreeBT_DispatchRead_Exit;
74
75 }
76
78 {
80
81 }
82
83 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: Transfer data length = %d\n", totalLength));
84 if (totalLength == 0)
85 {
88 goto FreeBT_DispatchRead_Exit;
89
90 }
91
93 if (totalLength > deviceExtension->DataInPipe.MaximumPacketSize)
94 {
95 stageLength = deviceExtension->DataInPipe.MaximumPacketSize;
96
97 }
98
99 else
100 {
101 stageLength = totalLength;
102
103 }
104
107 {
108 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: Failed to alloc mem for mdl\n"));
111 goto FreeBT_DispatchRead_Exit;
112
113 }
114
115
119 {
120 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: Failed to alloc mem for urb\n"));
124 goto FreeBT_DispatchRead_Exit;
125
126 }
127
129 urb,
131 deviceExtension->DataInPipe.PipeHandle,
134 stageLength,
137
138
139 rwContext->
Urb = urb;
141 rwContext->
Length = totalLength - stageLength;
144
145
152 rwContext,
156
157
159
162 {
163 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: IoCallDriver fails with status %X\n", ntStatus));
164
165
166
167
168
170 {
173 {
174 FreeBT_DbgPrint(1, (
"FBTUSB: FreeBT_DispatchRead: FreeBT_ResetPipe failed\n"));
176
177 }
178
179 }
180
181 else
182 {
183 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_DispatchRead: ntStatus is STATUS_CANCELLED or STATUS_DEVICE_NOT_CONNECTED\n"));
184
185 }
186
187 }
188
191
192 FreeBT_DbgPrint(3, (
"FBTUSB: FreeBT_DispatchRead: URB sent to lower driver, IRP is pending\n"));
193
194
196
197FreeBT_DispatchRead_Exit:
198 Irp->IoStatus.Status = ntStatus;
199 Irp->IoStatus.Information = 0;
202
203 return ntStatus;
204
205}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define NT_SUCCESS(StatCode)
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
NTSTATUS NTAPI FreeBT_ResetPipe(IN PDEVICE_OBJECT DeviceObject, IN USBD_PIPE_HANDLE PipeHandle)
NTSTATUS NTAPI FreeBT_ResetDevice(IN PDEVICE_OBJECT DeviceObject)
LONG NTAPI FreeBT_IoIncrement(IN OUT PDEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI FreeBT_ReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
struct _FREEBT_RW_CONTEXT * PFREEBT_RW_CONTEXT
#define FreeBT_DbgPrint(level, _x_)
#define ExAllocatePool(type, size)
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
#define IoCompleteRequest
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
struct _IO_STACK_LOCATION::@3974::@4013 Others
#define STATUS_DEVICE_NOT_CONNECTED
#define STATUS_INVALID_DEVICE_STATE
#define STATUS_INSUFFICIENT_RESOURCES
#define USBD_TRANSFER_DIRECTION_IN
#define USBD_SHORT_TRANSFER_OK
#define UsbBuildInterruptOrBulkTransferRequest(urb, length, pipeHandle, transferBuffer, transferBufferMDL, transferBufferLength, transferFlags, link)
#define IOCTL_INTERNAL_USB_SUBMIT_URB
_In_ PDEVICE_OBJECT DeviceObject
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
IO_COMPLETION_ROUTINE * PIO_COMPLETION_ROUTINE
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define MmGetMdlByteCount(_Mdl)
#define MmGetMdlVirtualAddress(_Mdl)