Strange behavior when trying to send IRP to a serial device from kernel

Hi,

I’m trying to develop a driver thats, among other things, has a IOCTL that
writes data to a com port from the kernel itself.

In order to accomplish that, when receiving a certain IOCTL from user mode,
I’m creating an IRP using IoBuildAsynchronousFsdRequest and sending it to
the device below me using IoCallDriver.

After the IoCallDriver, I tried two things:

1.) Return STATUS_PENDING and register a completion routine on the new IRP.
In the completion routine I called IoCompleteRequest.

2.) Use IoBuildSynchronousFsdRequest and wait on the event(as documented in
MSDN: Event [in]

Supplies a pointer to a caller-allocated and initialized event object. The
I/O manager sets the event to the Signaled state when a lower-level driver
completes the requested operation. After calling IoCallDriver, the driver
can wait for the event object.)

Both of the methods didn’t work as I expected and I’m not quite sure why…
The user-mode application that sent the IOCTL hanged. After few hours of
debugging, I’ve discovered the the completion routine was never called(when
I used STATUS_PENDING) and nothing ever has set the event to be
signaled(when I tried to wait on the event to become signaled). I tried to
find the answer in the Serial driver(sources avaiable in the DDK), but other
than discvoering that the ISR routine is not called for some reason, I found
no answer.

Any suggestions?

Thank you!

Post your send code

d

debt from my phone


From: Liran Elkayam
Sent: 5/25/2012 12:22 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Strange behavior when trying to send IRP to a serial device from kernel

Hi,
I’m trying to develop a driver thats, among other things, has a IOCTL that writes data to a com port from the kernel itself.
In order to accomplish that, when receiving a certain IOCTL from user mode, I’m creating an IRP using IoBuildAsynchronousFsdRequest and sending it to the device below me using IoCallDriver.
After the IoCallDriver, I tried two things:

1.) Return STATUS_PENDING and register a completion routine on the new IRP. In the completion routine I called IoCompleteRequest.
2.) Use IoBuildSynchronousFsdRequest and wait on the event(as documented in MSDN: Event [in]
Supplies a pointer to a caller-allocated and initialized event object. The I/O manager sets the event to the Signaled state when a lower-level driver completes the requested operation. After calling IoCallDriver, the driver can wait for the event object.)

Both of the methods didn’t work as I expected and I’m not quite sure why… The user-mode application that sent the IOCTL hanged. After few hours of debugging, I’ve discovered the the completion routine was never called(when I used STATUS_PENDING) and nothing ever has set the event to be signaled(when I tried to wait on the event to become signaled). I tried to find the answer in the Serial driver(sources avaiable in the DDK), but other than discvoering that the ISR routine is not called for some reason, I found no answer.

Any suggestions?
Thank you!


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

So you suspect that the serial port does not get its interrupt?
(so it does not send, receive or whatever)
Try to test it separately from the rest of your driver; verify that it works
well.
Only when all parts works, debug the whole.
– pa

“Liran Elkayam” wrote in message news:xxxxx@ntdev…
> Hi,
>
> I’m trying to develop a driver thats, among other things, has a IOCTL that
> writes data to a com port from the kernel itself.
>
> In order to accomplish that, when receiving a certain IOCTL from user
> mode,
> I’m creating an IRP using IoBuildAsynchronousFsdRequest and sending it to
> the device below me using IoCallDriver.
>
> After the IoCallDriver, I tried two things:
>
>
>
> 1.) Return STATUS_PENDING and register a completion routine on the new
> IRP.
> In the completion routine I called IoCompleteRequest.
>
> 2.) Use IoBuildSynchronousFsdRequest and wait on the event(as documented
> in
> MSDN: Event [in]
>
> Supplies a pointer to a caller-allocated and initialized event object. The
> I/O manager sets the event to the Signaled state when a lower-level driver
> completes the requested operation. After calling IoCallDriver, the driver
> can wait for the event object.)
>
>
>
> Both of the methods didn’t work as I expected and I’m not quite sure
> why…
> The user-mode application that sent the IOCTL hanged. After few hours of
> debugging, I’ve discovered the the completion routine was never
> called(when
> I used STATUS_PENDING) and nothing ever has set the event to be
> signaled(when I tried to wait on the event to become signaled). I tried to
> find the answer in the Serial driver(sources avaiable in the DDK), but
> other
> than discvoering that the ISR routine is not called for some reason, I
> found
> no answer.
>
>
>
> Any suggestions?
>
> Thank you!
>
>

Thanks for the responses.
Doron - I don’t have the code right now in this computer, but I can rewrite
it if you think It’s necessary.
Pavel - The serial driver writes the string to the com port! It just doesn’t
completes the request, which makes my driver(or the user mode application)
to hang :frowning:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Pavel A.
Sent: Friday, May 25, 2012 10:34 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Strange behavior when trying to send IRP to a serial
device from kernel

So you suspect that the serial port does not get its interrupt?
(so it does not send, receive or whatever) Try to test it separately from
the rest of your driver; verify that it works well.
Only when all parts works, debug the whole.
– pa

“Liran Elkayam” wrote in message news:xxxxx@ntdev…
> Hi,
>
> I’m trying to develop a driver thats, among other things, has a IOCTL
> that writes data to a com port from the kernel itself.
>
> In order to accomplish that, when receiving a certain IOCTL from user
> mode, I’m creating an IRP using IoBuildAsynchronousFsdRequest and
> sending it to the device below me using IoCallDriver.
>
> After the IoCallDriver, I tried two things:
>
>
>
> 1.) Return STATUS_PENDING and register a completion routine on the new
> IRP.
> In the completion routine I called IoCompleteRequest.
>
> 2.) Use IoBuildSynchronousFsdRequest and wait on the event(as
> documented in
> MSDN: Event [in]
>
> Supplies a pointer to a caller-allocated and initialized event object.
> The I/O manager sets the event to the Signaled state when a
> lower-level driver completes the requested operation. After calling
> IoCallDriver, the driver can wait for the event object.)
>
>
>
> Both of the methods didn’t work as I expected and I’m not quite sure
> why…
> The user-mode application that sent the IOCTL hanged. After few hours
> of debugging, I’ve discovered the the completion routine was never
> called(when I used STATUS_PENDING) and nothing ever has set the event
> to be signaled(when I tried to wait on the event to become signaled).
> I tried to find the answer in the Serial driver(sources avaiable in
> the DDK), but other than discvoering that the ISR routine is not
> called for some reason, I found no answer.
>
>
>
> Any suggestions?
>
> Thank you!
>
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

This is just a guess, but it sounds like interrupts are not enabled for
the device. This is not too surprising, because I suspect that interrupts
are not enabled until IRP_MJ_CREATE is processed, and are not disabled
until IRP_MJ_CLOSE is processed. Furthermore, by just sending down an
IRP, you could interfere with someone else using the device. You must
first open the device properly, which reserves it from others, and if my
guess is right will enable the interrupts. Since I am nowhere near my
desktop and the various driver sources, I can’t verify my guess.
joe

Hi,

I’m trying to develop a driver thats, among other things, has a IOCTL that
writes data to a com port from the kernel itself.

In order to accomplish that, when receiving a certain IOCTL from user
mode,
I’m creating an IRP using IoBuildAsynchronousFsdRequest and sending it to
the device below me using IoCallDriver.

After the IoCallDriver, I tried two things:

1.) Return STATUS_PENDING and register a completion routine on the new
IRP.
In the completion routine I called IoCompleteRequest.

2.) Use IoBuildSynchronousFsdRequest and wait on the event(as documented
in
MSDN: Event [in]

Supplies a pointer to a caller-allocated and initialized event object. The
I/O manager sets the event to the Signaled state when a lower-level driver
completes the requested operation. After calling IoCallDriver, the driver
can wait for the event object.)

Both of the methods didn’t work as I expected and I’m not quite sure
why…
The user-mode application that sent the IOCTL hanged. After few hours of
debugging, I’ve discovered the the completion routine was never
called(when
I used STATUS_PENDING) and nothing ever has set the event to be
signaled(when I tried to wait on the event to become signaled). I tried to
find the answer in the Serial driver(sources avaiable in the DDK), but
other
than discvoering that the ISR routine is not called for some reason, I
found
no answer.

Any suggestions?

Thank you!


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>1.) Return STATUS_PENDING and register a completion routine on the new IRP. In the completion

routine I called IoCompleteRequest.

This seems to be correct. You’ve forgot IoMarkIrpPending probably.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com