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

Sept/Oct 2019 Issue of The NT Insider available


Download PDF here: http://insider.osr.com/2019/ntinsider_2019_01.pdf

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

PNP device dev in a VM

AvalonAvalon Member Posts: 15
edited August 28 in NTDEV

Hey. Regarding PnP devices, when plugged in they load a .INF file associated with them. Can I emulate this behavior in VMWare for example, even though all it's PnP devices are virtual and supported, i.e. you plug in a USB and you're asked if you want to use host/guest connection, or a mouse, etc, but some devices I plug in can't be passed through.

So I want to create a basic PNP device where I can emulate and trigger the "h/w eject" and "h/w insert" functionality to test my .INF/driver that will be loaded/unloaded when Windows processes the PNP action. Any ddk samples/ideas to create this fake PNP device.

Comments

  • MichaelKMichaelK Member Posts: 6
    Toaster project should help:

    https://github.com/microsoft/Windows-driver-samples/tree/master/general/toaster/toastDrv

    It creates a bus driver that simulates device insertions, ejections, etc.
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,411

    So I want to create a basic PNP device where I can emulate and trigger the "h/w eject" and "h/w insert" functionality to test my .INF/driver

    Hmmmmm... what KIND of device do you want to emulate? In general, VMWare doesn’t provide the ability to pass, for example, PCIe devices through to the VM.

    Tell us more about your device and what you want to do.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • AvalonAvalon Member Posts: 15

    @Peter_Viscarola_(OSR) said:

    So I want to create a basic PNP device where I can emulate and trigger the "h/w eject" and "h/w insert" functionality to test my .INF/driver

    Hmmmmm... what KIND of device do you want to emulate? In general, VMWare doesn’t provide the ability to pass, for example, PCIe devices through to the VM.

    Tell us more about your device and what you want to do.

    Peter

    A PCI device. Yes VMWare doesn't, hence I want to emulate this behavior of IRP_MN_SURPRISE_REMOVAL and the driver being removed, then rescan (or add device trigger) to load the driver again. So I can test the INF/driver associated with multiple load/unload/remove events based on the device being ejected/inserted.

    Yes @MichaelK that toastDrv looked interesting, seems I need to create a Bus driver. Any sample code in WDM instead of KMDF? I've been reading how PNP works and seems I could use IoInvalidateDeviceState, which I did not see in that KMDF project.

  • MichaelKMichaelK Member Posts: 6

    The first rule of OSR is:
    You do write drivers in KMDF.
    The second rule of OSR is:
    You do write drivers in KMDF.

    KMDF is just a wrapper over WDM that makes your life and life of your customers easier. Also, it's open source and avail at github: https://github.com/microsoft/Windows-Driver-Frameworks/tree/master/src/framework/kmdf

    If, after all, you still want WDM Toaster, do search older WDK.
    IIRC, Toaster of WDK 7 still was a WDM driver.

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

    Simulating a hardware device, including arrival and departure, is a rather difficult undertaking. It could be that you only want to emulate a small subset of stuff, but still... a big job. Unless you have a lot of free time and absolutely no money, you’d be way better off just buying a bunch of systems to test on.

    Bus drivers in WDM are exceptionally annoying and complex to write. In KMDF, they’re almost a joy. “The first rule of OSR is...”

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • Pavel_APavel_A Member Posts: 2,687

    “The first rule of OSR is...”

    Never miss opportunity to have some joy at work? :)

    Simulation of PCI(e) devices is quite common for hardware developers, but if the OP wants pure software - he can use VirtualBox
    instead of VMware (opensource), he can look at Qemu...
    The real question is - why? Just for joy?

    -- pa

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
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE