How to access COM port from a driver

Hi,

I have a composite device which exposes COM port driver and another NDIS driver. COM port driver is an existing driver which responds to AT commands. I need to access this COM port from NDIS driver how can I use it.

Can I use

  1. ZwCreateFile to communicate with COM port.

  2. IoGetDeviceObjectPointer to find handle to device object opened and then use IoCallDriver to send the read and write IRP requests to driver.

  3. Is there any other recommended way of doing

Advantage/ Disadvantage of one over another ?

Regards,

Anurag Choudhary wrote:

  1. ZwCreateFile to communicate with COM port.
  2. IoGetDeviceObjectPointer to find handle to device object opened
    and then use IoCallDriver to send the read and write IRP requests
    to driver.
  3. Is there any other recommended way of doing

Use a WDFIOTARGET when opening the other device. I think you get some benefits from what KMDF will manage for you.

IoGetDeviceObjectPointer uses ZwOpenFile underneath the covers so #1 and #2 are nearly identical, the only difference is that IoGetDeviceObjectPointer closes the handle it opened before returning. This means that the driver behind the handle will see an IRP_MJ_CLEANUP. Most serial drivers treat this as a purge and will no longer respond to requests after the MJ_CLEANUP has been processed. As such, ZwOpenFile will be a better alternative for you.

As Chris rightly pointed out, you can use KMDF (in miniport mode) to create a remote WDFIOTARGET and open the com port with it. This buys you i/o tracking as well state tracking notifications (for instance you must close the handle if the com port is being gracefully removed/disabled). Since this is a USB NIC, you can also use the KMDF WDFUSBDEVICE and WDFUSBPIPE io targets to configure and communicate with your device instead of rolling your own PIRPs and URBs

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, June 19, 2008 11:41 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to access COM port from a driver

Anurag Choudhary wrote:

  1. ZwCreateFile to communicate with COM port.
  2. IoGetDeviceObjectPointer to find handle to device object opened
    and then use IoCallDriver to send the read and write IRP requests
    to driver.
  3. Is there any other recommended way of doing

Use a WDFIOTARGET when opening the other device. I think you get some benefits from what KMDF will manage for 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

Thanks for your response Doron/ Chris.

Can I use ZwReadFile and ZwWriteFile to write AT Commands and receive
response from COM port ? or should I use IoCallDriver to send IRP for send
or receive ? Which one is preferred and why ?

Regards,
Anurag

On Fri, Jun 20, 2008 at 12:52 AM, Doron Holan
wrote:

> IoGetDeviceObjectPointer uses ZwOpenFile underneath the covers so #1 and #2
> are nearly identical, the only difference is that IoGetDeviceObjectPointer
> closes the handle it opened before returning. This means that the driver
> behind the handle will see an IRP_MJ_CLEANUP. Most serial drivers treat
> this as a purge and will no longer respond to requests after the MJ_CLEANUP
> has been processed. As such, ZwOpenFile will be a better alternative for
> you.
>
> As Chris rightly pointed out, you can use KMDF (in miniport mode) to create
> a remote WDFIOTARGET and open the com port with it. This buys you i/o
> tracking as well state tracking notifications (for instance you must close
> the handle if the com port is being gracefully removed/disabled). Since
> this is a USB NIC, you can also use the KMDF WDFUSBDEVICE and WDFUSBPIPE io
> targets to configure and communicate with your device instead of rolling
> your own PIRPs and URBs
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
> Sent: Thursday, June 19, 2008 11:41 AM
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] How to access COM port from a driver
>
> Anurag Choudhary wrote:
>
> > 1. ZwCreateFile to communicate with COM port.
> > 2. IoGetDeviceObjectPointer to find handle to device object opened
> > and then use IoCallDriver to send the read and write IRP requests
> > to driver.
> > 3. Is there any other recommended way of doing
>
> Use a WDFIOTARGET when opening the other device. I think you get some
> benefits from what KMDF will manage for 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
>
>
> —
> 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
>

It really depends on the context in which you want to send reads and writes. The Zw APIs require you to be at passive with APCs enabled. If you are writing to the com port in response to NDIS packet flow, you will most likely be at IRQL > PASSIVE_LEVEL. If you roll your own read/write PIRPs, these restrictions go away and you can send these at IRQL <= dispatch.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of anurag choudhary
Sent: Thursday, June 19, 2008 10:53 PM
To: Windows System Software Devs Interest List
Subject: Re: RE:[ntdev] How to access COM port from a driver

Thanks for your response Doron/ Chris.

Can I use ZwReadFile and ZwWriteFile to write AT Commands and receive response from COM port ? or should I use IoCallDriver to send IRP for send or receive ? Which one is preferred and why ?

Regards,
Anurag
On Fri, Jun 20, 2008 at 12:52 AM, Doron Holan > wrote:
IoGetDeviceObjectPointer uses ZwOpenFile underneath the covers so #1 and #2 are nearly identical, the only difference is that IoGetDeviceObjectPointer closes the handle it opened before returning. This means that the driver behind the handle will see an IRP_MJ_CLEANUP. Most serial drivers treat this as a purge and will no longer respond to requests after the MJ_CLEANUP has been processed. As such, ZwOpenFile will be a better alternative for you.

As Chris rightly pointed out, you can use KMDF (in miniport mode) to create a remote WDFIOTARGET and open the com port with it. This buys you i/o tracking as well state tracking notifications (for instance you must close the handle if the com port is being gracefully removed/disabled). Since this is a USB NIC, you can also use the KMDF WDFUSBDEVICE and WDFUSBPIPE io targets to configure and communicate with your device instead of rolling your own PIRPs and URBs

d

-----Original Message-----
From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of xxxxx@gmail.commailto:xxxxx
Sent: Thursday, June 19, 2008 11:41 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to access COM port from a driver

Anurag Choudhary wrote:

> 1. ZwCreateFile to communicate with COM port.
> 2. IoGetDeviceObjectPointer to find handle to device object opened
> and then use IoCallDriver to send the read and write IRP requests
> to driver.
> 3. Is there any other recommended way of doing

Use a WDFIOTARGET when opening the other device. I think you get some benefits from what KMDF will manage for 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


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

— 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</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>