Creating own IRP

Dear Experts,

I am writing USB functional driver for WinXP.
My driver is working fine when the application terminates after completely
reading data from the device.
I am using direct IO as data transfer mechanism.
Device buffers will be filled with data, if the application terminates
before driver reads the data completely from the device.

In this scenario, I want to read out the data from the device buffers from
Dispatch clean.
For this I am creating my own IRP in dispatch clean and creating my own MDL,
which will be passed to the lower driver to read the data.
Lower level driver was not responding to my IRP. Please find the code I am
using to create my own IRP.

PIRP CancelIrp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

if(!CancelIrp) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for CancelIrp\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;

}

deviceExtension->Irp = CancelIrp;

virtualAddress = (ULONG_PTR)ExAllocatePool(NonPagedPool,
sizeof(deviceExtension->LengthRemain)); //Allocate the buffer for the data
to be read from Token.

if(!virtualAddress) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for virtualAddress\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}

mdl = IoAllocateMdl((PVOID) virtualAddress,
deviceExtension->LengthRemain,
FALSE,
FALSE,
NULL);

if(mdl == NULL) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for mdl\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto BulkUsb_ReadBufferCleanExit;
}

Is any thing wrong with my IRP/MDL creation ?
Is there any alternate method to read out the device buffers (not driver
buffers) from driver ?

Regards,
Saradhi

There’s lots wrong with it. Your error handling clauses are broken – they
flow to the “non-error” path, so your code will dereference NULL pointers if
allocation fails.

Second, it’s not clear what you’re trying to achieve here. Describe what
you are trying to do, not how you are doing it.

Also, if you want to pass a pointer to non-paged pool within a URB, just set
Urb->UrbXxx.TransferBuffer to your buffer. Don’t create the MDL yourself.
The USB stack will do that for you. Make sure you set
Urb->UrbXxx.TransferBufferMDL to NULL.

– arlie


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ramya Desai
Sent: Thursday, February 02, 2006 1:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Creating own IRP

Dear Experts,

I am writing USB functional driver for WinXP.
My driver is working fine when the application terminates after completely
reading data from the device.
I am using direct IO as data transfer mechanism.
Device buffers will be filled with data, if the application terminates
before driver reads the data completely from the device.

In this scenario, I want to read out the data from the device buffers from
Dispatch clean.
For this I am creating my own IRP in dispatch clean and creating my own MDL,
which will be passed to the lower driver to read the data.
Lower level driver was not responding to my IRP. Please find the code I am
using to create my own IRP.

PIRP CancelIrp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

if(!CancelIrp) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for CancelIrp\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;

}

deviceExtension->Irp = CancelIrp;

virtualAddress = (ULONG_PTR)ExAllocatePool(NonPagedPool,
sizeof(deviceExtension->LengthRemain)); //Allocate the buffer for the data
to be read from Token.

if(!virtualAddress) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for virtualAddress\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}

mdl = IoAllocateMdl((PVOID) virtualAddress,
deviceExtension->LengthRemain,
FALSE,
FALSE,
NULL);

if(mdl == NULL) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for mdl\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto BulkUsb_ReadBufferCleanExit;
}

Is any thing wrong with my IRP/MDL creation ?
Is there any alternate method to read out the device buffers (not driver
buffers) from driver ?

Regards,
Saradhi
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email
to xxxxx@lists.osr.com

Ramya Desai wrote:

I am writing USB functional driver for WinXP.
My driver is working fine when the application terminates after
completely reading data from the device.
I am using direct IO as data transfer mechanism.
Device buffers will be filled with data, if the application terminates
before driver reads the data completely from the device.

So, the device has more buffers than can be sent in a single transfer?
Do you have to send a command to the device to turn the data collection
off and on? Are you sending that command? Is it possible the device
will not respond to data requests after you have stopped data collection?

In this scenario, I want to read out the data from the device buffers
from Dispatch clean.
For this I am creating my own IRP in dispatch clean and creating my
own MDL, which will be passed to the lower driver to read the data.

Do you control the firmware on the device? A better solution is to use
a vendor command to send some kind of a “cancel” request to the device,
to let it clear out the buffers without wasting a bunch of USB bandwidth
on data that will be discarded.

Lower level driver was not responding to my IRP. Please find the code
I am using to create my own IRP.

Of course, that’s only half the code. You didn’t include the creation
and transmission of the URB.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Dear Arlie Davis,

If the driver was doing read operation, the Device buffers will be filled
with data. If the application is closed at this moment, the Device buffers
will still hold the data to be read. If these buffers are not cleared,
Device will not respond to any further commands issued by driver.

To avoid this situation I wanted to clear read out the data from device
buffers (not Driver buffers) as just we do in Dispatch Read function. I want
do this from Dispatch clean.

I tried with both MDL and virtual address to the URB, but still facing the
same problem
Please found the bellow code.

UsbBuildInterruptOrBulkTransferRequest(
urb,
sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
pipeHandle,
(PVOID)&virtualAddress2,
NULL,
stageLength,
urbFlags,
NULL);

Is there any method to read out the data from device buffers other than what
I am planning to do ? The limitation is, I can not control device firmware
from my driver.

Regards,
Ramya

On 2/2/06, Arlie Davis wrote:
>
> There’s lots wrong with it. Your error handling clauses are broken –
> they
> flow to the “non-error” path, so your code will dereference NULL pointers
> if
> allocation fails.
>
> Second, it’s not clear what you’re trying to achieve here. Describe what
> you are trying to do, not how you are doing it.
>
> Also, if you want to pass a pointer to non-paged pool within a URB, just
> set
> Urb->UrbXxx.TransferBuffer to your buffer. Don’t create the MDL yourself.
> The USB stack will do that for you. Make sure you set
> Urb->UrbXxx.TransferBufferMDL to NULL.
>
> – arlie
>
>
> ________________________________
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Ramya Desai
> Sent: Thursday, February 02, 2006 1:30 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] Creating own IRP
>
>
> Dear Experts,
>
> I am writing USB functional driver for WinXP.
> My driver is working fine when the application terminates after completely
> reading data from the device.
> I am using direct IO as data transfer mechanism.
> Device buffers will be filled with data, if the application terminates
> before driver reads the data completely from the device.
>
> In this scenario, I want to read out the data from the device buffers from
> Dispatch clean.
> For this I am creating my own IRP in dispatch clean and creating my own
> MDL,
> which will be passed to the lower driver to read the data.
> Lower level driver was not responding to my IRP. Please find the code I am
> using to create my own IRP.
>
>
> PIRP CancelIrp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
>
> if(!CancelIrp) {
>
> BulkUsb_DbgPrint(1, (“Failed to alloc mem for CancelIrp\n”));
>
> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
>
> }
>
> deviceExtension->Irp = CancelIrp;
>
>
> virtualAddress = (ULONG_PTR)ExAllocatePool(NonPagedPool,
> sizeof(deviceExtension->LengthRemain)); //Allocate the buffer for the
> data
> to be read from Token.
>
> if(!virtualAddress) {
>
> BulkUsb_DbgPrint(1, (“Failed to alloc mem for virtualAddress\n”));
>
> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
> }
>
> mdl = IoAllocateMdl((PVOID) virtualAddress,
> deviceExtension->LengthRemain,
> FALSE,
> FALSE,
> NULL);
>
> if(mdl == NULL) {
>
> BulkUsb_DbgPrint(1, (“Failed to alloc mem for mdl\n”));
>
> ntStatus = STATUS_INSUFFICIENT_RESOURCES;
> goto BulkUsb_ReadBufferCleanExit;
> }
>
>
> Is any thing wrong with my IRP/MDL creation ?
> Is there any alternate method to read out the device buffers (not driver
> buffers) from driver ?
>
>
> Regards,
> Saradhi
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 You are currently subscribed
> to
> ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank
> email
> to xxxxx@lists.osr.com
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

With so little information, it’s impossible to help you. What is
virtualAddress2? Is it a pointer? If so, you’re passing the address of the
pointer, not the address of the memory to which the pointer points. Are you
then calling IoCallDriver? UsbBuildInterruptOrBulkTransferRequest only
fills in fields in a URB structure; it does not actually submit the URB to
the USB stack. Are you setting an I/O completion routine (with
IoSetCompletionRoutine), and if so, what are you doing in that routine? How
are you synchronizing the actions of the completion routine with the thread
that is processing IRP_MJ_CLEANUP?

You need to provide more specific information on what you’re doing. What
happens when your driver runs? Does it crash, stop responding, lose data,
etc.? If it crashes, what is the output of !analyze -v? Do you have a
kernel debugger attached?

– arlie


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ramya Desai
Sent: Friday, February 03, 2006 10:19 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Creating own IRP

Dear Arlie Davis,

If the driver was doing read operation, the Device buffers will be filled
with data. If the application is closed at this moment, the Device buffers
will still hold the data to be read. If these buffers are not cleared,
Device will not respond to any further commands issued by driver.

To avoid this situation I wanted to clear read out the data from device
buffers (not Driver buffers) as just we do in Dispatch Read function. I want
do this from Dispatch clean.

I tried with both MDL and virtual address to the URB, but still facing the
same problem
Please found the bellow code.

UsbBuildInterruptOrBulkTransferRequest(
urb,
sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
pipeHandle,
(PVOID)&virtualAddress2,
NULL,
stageLength,
urbFlags,
NULL);

Is there any method to read out the data from device buffers other than what
I am planning to do ? The limitation is, I can not control device firmware
from my driver.

Regards,
Ramya

On 2/2/06, Arlie Davis wrote:

There’s lots wrong with it. Your error handling clauses are broken
– they
flow to the “non-error” path, so your code will dereference NULL
pointers if
allocation fails.

Second, it’s not clear what you’re trying to achieve here. Describe
what
you are trying to do, not how you are doing it.

Also, if you want to pass a pointer to non-paged pool within a URB,
just set
Urb->UrbXxx.TransferBuffer to your buffer. Don’t create the MDL
yourself.
The USB stack will do that for you. Make sure you set
Urb->UrbXxx.TransferBufferMDL to NULL.

– arlie

________________________________

From: xxxxx@lists.osr.com
[mailto: xxxxx@lists.osr.com
mailto:xxxxx] On Behalf Of Ramya Desai
Sent: Thursday, February 02, 2006 1:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Creating own IRP

Dear Experts,

I am writing USB functional driver for WinXP.
My driver is working fine when the application terminates after
completely
reading data from the device.
I am using direct IO as data transfer mechanism.
Device buffers will be filled with data, if the application
terminates
before driver reads the data completely from the device.

In this scenario, I want to read out the data from the device
buffers from
Dispatch clean.
For this I am creating my own IRP in dispatch clean and creating my
own MDL,
which will be passed to the lower driver to read the data.
Lower level driver was not responding to my IRP. Please find the
code I am
using to create my own IRP.

PIRP CancelIrp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

if(!CancelIrp) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for
CancelIrp\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;

}

deviceExtension->Irp = CancelIrp;

virtualAddress = (ULONG_PTR)ExAllocatePool(NonPagedPool,
sizeof(deviceExtension->LengthRemain)); //Allocate the buffer for
the data
to be read from Token.

if(!virtualAddress) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for
virtualAddress\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}

mdl = IoAllocateMdl((PVOID) virtualAddress,
deviceExtension->LengthRemain,
FALSE,
FALSE,
NULL);

if(mdl == NULL) {

BulkUsb_DbgPrint(1, (“Failed to alloc mem for mdl\n”));

ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto BulkUsb_ReadBufferCleanExit;
}

Is any thing wrong with my IRP/MDL creation ?
Is there any alternate method to read out the device buffers (not
driver
buffers) from driver ?

Regards,
Saradhi
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently
subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a
blank email
to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
http:

You are currently subscribed to ntdev as: xxxxx@gmail.com
To unsubscribe send a blank email to
xxxxx@lists.osr.com mailto:xxxxx

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email
to xxxxx@lists.osr.com</mailto:xxxxx></http:></mailto:xxxxx>