Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

KMDF virtual driver - how to create device object on demand?

nb3mnb3m Member Posts: 12
edited May 6 in NTDEV

I am developing KMDF virtual com driver (in WDF) working with user mode manager that install/remove driver using devcon commands. Currently my driver runs as pnp driver without power management. However I have problem installing multiple instances of my driver. When I am loading second or further driver instance I can see that system removes previous driver instance and then loads 2 or more drivers. At the end I have multiple driver working instances however I am loosing all data stored in previous device.

Is there a good way to add new virtual PnP device? Or should I rework driver to non-PnP and try to handle it in different way?

Post edited by nb3m on

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,035
    via Email
    nb3m wrote:
    > Is there a good way to add new virtual PnP device? Or should I rework driver to non-PnP and try to handle it in different way?

    PnP is clearly the right way to do this.  Exactly what devcon commands
    are you using?

    One alternative would be to write a very simple bus driver to control
    your instances.  When it's time to add or remove an instance, you could
    send an ioctl to the bus driver, have it create a new PDO or surprise
    remove an old one, and then invalidate the device relations.   KMDF
    makes a bus driver like that almost trivial.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • nb3mnb3m Member Posts: 12

    Thanks Tim for your replay. I think, what i was looking for was SetupDiRegisterDeviceInfo function. According to msdn documentation it will inform PnP manager that my device has been "plugged in" and it will install device automatically. I will check if it works. Creating bus driver seems to me like an use a sledgehammer to crack a nut.

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,035
    via Email
    nb3m wrote:
    > Thanks Tim for your replay. I think, what i was looking for was SetupDiRegisterDeviceInfo function. According to msdn documentation it will inform PnP manager that my device has been "plugged in" and it will install device automatically.

    Well, the doc says that function is designed for non-PnP devices only. 
    I suppose it's worth a try.


    > I will check if it works. Creating bus driver seems to me like an use a sledgehammer to crack a nut.

    Not like it used to be.  Thanks to KMDF, bus drivers are easy-peasy. 
    It's well under 100 lines of code to do what you're asking.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • nb3mnb3m Member Posts: 12

    I have managed to create and register device in Device Manager. However I have problems loading driver for that device. I am trying to use DiInstallDevice function to load driver for new device. My driver is test signed and I am wondering if it's possible to load it. In theory I can chose SP_DRVINFO_DATA structure but it's not working. Do you think it might be due to test-signature?

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,380

    I don't understand, like at all, what you're trying to do.

    Can you please start from the beginning and give us all a nice, clear, description of what you're trying to accomplish. NOT how you're presently doing it, please. But, rather, what it is your end goal is.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • nb3mnb3m Member Posts: 12
    edited May 10

    I have virtual PnP kernel driver, lets call it Virtual Serial. My driver setup device using EvtDriverDeviceAdd event callback. I have user application (manager) that installs driver like a devcon. Each time when I install driver it creates additional Virtual Serial device. At this point I start having problems. Each time I install driver it will create Virtual Serial but as well it will refresh all previous devices. I need my application to add single Virtual Serial and load driver for that device without refreshing other devices.

    Normal devices, like usb stick, after plugging in are recognized individually and PnP manager loads driver. Because my driver is virtual I need to manually add device into PnP manager and load driver for it.

    Hopefully it was clear enough.

    Regards.

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,035
    via Email
    nb3m wrote:
    > I have virtual PnP kernel driver, lets call it Virtual Serial. My driver loads device using EvtDriverDeviceAdd event callback. I have user application that installs driver like a devcon. Each time when I install driver it creates additional Virtual Serial device.

    Right, because "devcon install" is the wrong way to do this.


    > Normal devices, like usb stick, after plugging in are recognized individually and PnP manager loads driver. Because my driver is virtual I need to manually add device into PnP manager.

    I already told you the answer to this.  The USB stick works because the
    usbhub bus driver creates a new PDO, for which PnP will load a new
    function driver.  You can do this in exactly the same way.  Create a
    simple bus driver.  Have your application send a request to that bus
    driver to create or remove PDOs.

    Look, go to the Windows driver samples and look up the
    general/toaster/toastDrv sample.  That sample does exactly what you want
    to do.  There is a virtual bus driver (kmdf/bus/dynamic) that listens to
    ioctl requests to plug in a new device, unplug an existing device, and
    even eject a device.  There is even a set of applications that show how
    to trigger it (exe/enum and exe/notify).

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,380

    Hopefully it was clear enough.

    Not really. Once again, you described "how you're presently doing it" -- which is exactly what I asked you not to do.

    But, it SOUNDS to me like you need a bus driver. Which is what Mr. Roberts is telling you.

    If you want to try again, and describe what your overall goal is, without resorting to telling me how you've implemented it so far, that still might be helpful. Maybe not. :o

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • nb3mnb3m Member Posts: 12

    @Tim_Roberts Thank you for your replay. I will take a look at toaster example.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA