Hi All,
I am working on writing functional and upper filter WDM drivers for a
particular device on Windows 2k. The stack of drivers is used to connect
to the device and upload a file from it (beside other things).
A snapshot of code in the upper filter driver, which interacts with the
functional driver….
While (ReadMoreData == TRUE)
{
.
.
pIrp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
MyUSBDriverDevice, MyBuffer, MY_USB_BUFFER_SIZE, &MyStartingOffset,
&MyReadEvent, &MyIoStatusBlock);
PIO_STACK_LOCATION nextStack;
nextStack = IoGetNextIrpStackLocation(pIrp);
nextStack->MajorFunction = IRP_MJ_READ;
nextStack->FileObject = pMyFileObject;
nextStack->FileObject->FsContext =MyUsbPipeInformation[1];
status = IoCallDriver(MyUSBDriverDevice, pIrp);
ResetEvent(MyReadEvent);
KeWaitForSingleObject(&MyReadEvent, &status, Executive, KernelMode,
FALSE, &MyDelay);
// note that theres is no completion routine as the Irp is synchjronous
if((pIrp->IoStatus->Status==0)
{
// success… hence read the data from Irp and send it to the application
}else
{
// continue the next iteraion
}
.
.
}
The problem scenario
It is observed by the application using this driver stack that sometimes
a packet of data is missing randomly.
On further investigation we found that the functional driver receives an
IRP with status (pIrp->IoStatus->Status) ‘successful’ for each and every
packet read from the device. This was verified with the help of the
sequence number carried by each packet. So we can conclude that the
functional driver receives all the packets read from the device.
For some packets ( which are reported missing by the application), the
IRP containing that packet has status ‘successful’ in the functional
driver, but the status of the same IRP is seen as ‘pending’ in the upper
filter driver.
As the upper filter driver sees the status of the Irp pending even after
waiting on the event associated with the IRP, it assumes that there is
nothing to be read and goes on to the next iteration to try and read from
the device, loosing a packet in the process.
This happens roughly 2 out of 5 times the application asks to upload a
file form the device. Sometimes up to 2-3 packets (out of about 400
packets) are reported missing.
HELP!!
Could somebody explain why the pIrp->IoStatus->Status differs for the
same Irp in two immediate drivers (even after using an event for
serialization)?