Multiple Handles to USB Device

Hi,
I would like to use my Usb device by several processes.
Unfortunately, there is nothing written about any limitation to do that.
But in fact, it is impossible. The CreateFile fails on ACCESS_DENIED.
Indeed, this limitation makes things more safe for most cases.
But for my device (in embedded lab environment and not for production) I would like to be able to do it.
I admit, I will need to care the context and sync R/W operations .

Can you explain , where the limitation is ?
Is it on EvtDeviceIoCreate that intentionally fails ?

How can i get it over, by writing Filter driver ?
What filter model is better/easier/faster Umdf or Kmdf ?

I know, there is always a way to write a client-service and centralize access to USB , but because of some reasons I prefer to do it by filter driver if possible.

Thanks you in advance
E.H

Do you own the driver? Which device driver does the device use ?

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@hotmail.com
Sent: Tuesday, April 4, 2017 6:53:47 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Multiple Handles to USB Device

Hi,
I would like to use my Usb device by several processes.
Unfortunately, there is nothing written about any limitation to do that.
But in fact, it is impossible. The CreateFile fails on ACCESS_DENIED.
Indeed, this limitation makes things more safe for most cases.
But for my device (in embedded lab environment and not for production) I would like to be able to do it.
I admit, I will need to care the context and sync R/W operations .

Can you explain , where the limitation is ?
Is it on EvtDeviceIoCreate that intentionally fails ?

How can i get it over, by writing Filter driver ?
What filter model is better/easier/faster Umdf or Kmdf ?

I know, there is always a way to write a client-service and centralize access to USB , but because of some reasons I prefer to do it by filter driver if possible.

Thanks you in advance
E.H


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

I’m not an owner. I use the MCU (microchip device).
It uses the win usb driver and winusb, but it has modified inf.

Thanks

“The CreateFile fails on ACCESS_DENIED”

This might simply be an application error; check the arguments to CreateFile(), especially the dwDesiredAccess and dwShareMode values.

Otherwise, please show us the code - including the arguments to CreateFile() - which you are using to access the device.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-628798-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: 04 April 2017 14:54
To: Windows System Software Devs Interest List
Subject: [ntdev] Multiple Handles to USB Device

Hi,
I would like to use my Usb device by several processes.
Unfortunately, there is nothing written about any limitation to do
that.
But in fact, it is impossible. The CreateFile fails on ACCESS_DENIED.
Indeed, this limitation makes things more safe for most cases.
But for my device (in embedded lab environment and not for production)
I would like to be able to do it.
I admit, I will need to care the context and sync R/W operations .

Can you explain , where the limitation is ?
Is it on EvtDeviceIoCreate that intentionally fails ?

How can i get it over, by writing Filter driver ?
What filter model is better/easier/faster Umdf or Kmdf ?

I know, there is always a way to write a client-service and centralize
access to USB , but because of some reasons I prefer to do it by filter
driver if possible.

Thanks you in advance
E.H


NTDEV is sponsored by OSR

Visit the list online at:
http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at
> http:</http:></http:></http:>

Winusb requires exclusive access. If you want to have multiple applications access the device, abandon winusb and write a umdf 2.0 driver which gives you the multiple app access you need. You will have to stop using the winusb driver and API dll and move to straight custom ioctls

Bent from my phone


From: xxxxx@lists.osr.com on behalf of David Boyce
Sent: Tuesday, April 4, 2017 8:44:40 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Multiple Handles to USB Device

“The CreateFile fails on ACCESS_DENIED”

This might simply be an application error; check the arguments to CreateFile(), especially the dwDesiredAccess and dwShareMode values.

Otherwise, please show us the code - including the arguments to CreateFile() - which you are using to access the device.

> -----Original Message-----
> From: xxxxx@lists.osr.commailto:xxxxx [mailto:bounce-628798-
> xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.commailto:xxxxx
> Sent: 04 April 2017 14:54
> To: Windows System Software Devs Interest List
> Subject: [ntdev] Multiple Handles to USB Device
>
> Hi,
> I would like to use my Usb device by several processes.
> Unfortunately, there is nothing written about any limitation to do
> that.
> But in fact, it is impossible. The CreateFile fails on ACCESS_DENIED.
> Indeed, this limitation makes things more safe for most cases.
> But for my device (in embedded lab environment and not for production)
> I would like to be able to do it.
> I admit, I will need to care the context and sync R/W operations .
>
> Can you explain , where the limitation is ?
> Is it on EvtDeviceIoCreate that intentionally fails ?
>
> How can i get it over, by writing Filter driver ?
> What filter model is better/easier/faster Umdf or Kmdf ?
>
> I know, there is always a way to write a client-service and centralize
> access to USB , but because of some reasons I prefer to do it by filter
> driver if possible.
>
> Thanks you in advance
> E.H
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at:
> http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at
> http:


This email message has been delivered safely and archived online by Mimecast.
For more information please visit http://www.mimecast.com



NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></http:></http:></http:></mailto:xxxxx></mailto:xxxxx>

>> " You will have to stop using the winusb driver and API dll and move to straight custom ioctls"

Why, writing User/Kernel Driver upper filter will not solve this problem ?

Thanks
E.H

Because when you are done, I think the complexity of the filter is going to be high, all to work around winusb’s policy. I think the complexity in the filter is going to be about equal as writing a functional driver on your own. The value of winusb is that you don’t write a driver, the actual winusb API surface is simple. So if you are already going down the path of writing a driver, writing a driver in WDF (user or KM) that is equivalent to winusb is super simple and then it is a matter of applying the right policy and logic on top of it

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, April 4, 2017 10:14 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Multiple Handles to USB Device

>> " You will have to stop using the winusb driver and API dll and move to straight custom ioctls"

Why, writing User/Kernel Driver upper filter will not solve this problem ?

Thanks
E.H


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

Currently, I use the FX3 kmdf as basis , it seems me ± OK, but I see also other examples in Windows-driver-samples->USB. like usbsamp (kmdf) or umdf_fx2 (umdf).
Is UMDF makes life easier ?
Or maybe you can direct to another example that match & covers better the winusb API surface?

Thank you for any suggestion.

xxxxx@hotmail.com wrote:

Currently, I use the FX3 kmdf as basis , it seems me ± OK, but I see also other examples in Windows-driver-samples->USB. like usbsamp (kmdf) or umdf_fx2 (umdf).
Is UMDF makes life easier ?
Or maybe you can direct to another example that match & covers better the winusb API surface?

It doesn’t much matter. UMDF is easier to debug, because a bug in a
UMDF driver doesn’t crash the whole system.

I would also point out that there are other solutions to your problem.
You can, for example, write a Windows service to own the driver
connection, and have that service offer APIs to multiple client
applications. Thus, the service acts as a traffic cop to distribute
services. That allows you to use WinUSB and avoid the driver world.
Whether that’s simpler in the long term than a custom driver is a matter
for debate over distilled beverages.


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

I think the OP wants to not touch the apps, have the apps continue to use winusb.dll and underneath the covers, make it work. Neither the service as arbiter or UMDF driver allow the apps to continue to use winusb. The OP has to be willing to change the apps to make this work.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Wednesday, April 5, 2017 9:54 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Multiple Handles to USB Device

xxxxx@hotmail.com wrote:
> Currently, I use the FX3 kmdf as basis , it seems me ± OK, but I see also other examples in Windows-driver-samples->USB. like usbsamp (kmdf) or umdf_fx2 (umdf).
> Is UMDF makes life easier ?
> Or maybe you can direct to another example that match & covers better the winusb API surface?

It doesn’t much matter. UMDF is easier to debug, because a bug in a UMDF driver doesn’t crash the whole system.

I would also point out that there are other solutions to your problem.
You can, for example, write a Windows service to own the driver connection, and have that service offer APIs to multiple client applications. Thus, the service acts as a traffic cop to distribute services. That allows you to use WinUSB and avoid the driver world.
Whether that’s simpler in the long term than a custom driver is a matter for debate over distilled beverages.


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


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

It depends on the application, but in principle one can write a 'wrapper" winusb.dll (assuming the app is not hardened against DLL preload attack :)) From this wrapper (or ‘virtualizer’) call the service that owns the winusb device, as Mr. Roberts advises.

–pa

Thank you for your advice, I will be thankful, if you can answer my questions regarding the best example to start with (better umdf) that covers the USB interface.

Regarding the nice idea to use winusb wrapper that redirects to centralized service, I prefer not to use the service at all , because at our “lab” case , the performance is critical . we don’t want to pay additional even small overhead.

I will be glad if you can point me to the best example . I just afaid the the umdf_fx2 example is full of unrelated stuff and , i’m not sure it covers the full USB spec like winusb.sys.

Thank you in advance

You are not going to find a USB sample that is functionally equivalent to winusb. The umdf 2.0 fx2 sample is a great place to start

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@hotmail.com
Sent: Thursday, April 6, 2017 3:47:05 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Multiple Handles to USB Device

Thank you for your advice, I will be thankful, if you can answer my questions regarding the best example to start with (better umdf) that covers the USB interface.

Regarding the nice idea to use winusb wrapper that redirects to centralized service, I prefer not to use the service at all , because at our “lab” case , the performance is critical . we don’t want to pay additional even small overhead.

I will be glad if you can point me to the best example . I just afaid the the umdf_fx2 example is full of unrelated stuff and , i’m not sure it covers the full USB spec like winusb.sys.

Thank you in advance


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

xxxxx@hotmail.com wrote:

Thank you for your advice, I will be thankful, if you can answer my questions regarding the best example to start with (better umdf) that covers the USB interface.

Regarding the nice idea to use winusb wrapper that redirects to centralized service, I prefer not to use the service at all , because at our “lab” case , the performance is critical . we don’t want to pay additional even small overhead.

What does that mean? With USB, you spend an awful lot of time waiting
for the bus anyway. Very few USB applications are truly CPU bound.

If you do actually have a real CPU problem (as opposed to a theoretical
one), then you don’t want UMDF. It is, essentially, the exact same
concept I described. UMDF drivers run in a centralized service, and
your ioctls ship over to that service before getting send to kernel mode
for handling.

I will be glad if you can point me to the best example . I just afaid the the umdf_fx2 example is full of unrelated stuff and , i’m not sure it covers the full USB spec like winusb.sys.

You don’t need the full USB spec, unless you happen to be developing a
host controller. You need to fetch descriptors, you need to send
control pipe requests, and you need to read and write from your data
pipes. That’s all WinUSB provides, and for a fixed device you can do
that with a few hundred lines of KMDF.


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

Just one important note. my statement about performance was not accurate. I mean that it is important to us the r/w requests will come to the HW and back as soon as possible.

Tim, thanks, probably kernel will be more correct way and much easier :). just because I’ve not experienced umdf yet.

by the opportunity, I would like to appreciate your all for your responses . it is a great forum, people altruistically share knowledge. honestly,It is not quite common nowadays, especially from such a great experts like you guys.
Thank you

xxxxx@hotmail.com wrote:

Tim, thanks, probably kernel will be more correct way and much easier :). just because I’ve not experienced umdf yet.

Assuming you use UMDF 2.0, the concepts, APIs, and callbacks are
identical to KMDF. You just use Win32 APIs for non-framework stuff
instead of kernel APIs.


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