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

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?

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.

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.

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.

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?

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

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.

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).

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

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