Faking the presence of a USB device in order to test driver installation on Windows - windows

I've been asked to help with some problems that a company are having with an Windows installer they have that includes some custom driver installation for some hardware they make.
I've got access to the source code to build the software and installer (which is an WIX/MSI one), but don't have access to the hardware, so can't actually test it properly.
Is it possible (either with a toolkit, or without) to trick windows into thinking that a specific device USB device has been attached to the computer in order to trigger Windows into trying to install the drivers? . I've got access to all the Vendoer Id, DeviceID, etc information.
Thanks
Tom

That should be possible. Take a look at WDK USBSamp and NDIS Virtual miniport (or virtual serial driver) samples. The first one is a USB driver sample and second one demonstrates how to build virtual driver. You should be able to combine the two to create a virtual USB driver.

Related

How can I create a Bulk USB Gadget WinUSB Device

I created an small embedded WinUSB device which offers 2 bulk endpoints. This device can communicate with Linux and with Windows10 without installing driver, or a .inf file.
Now we want to use the same API with a embedded Linux. The USB-Gadget mode offers Serial CDC/ACM and RNDIS-Ethernet and many more.
I was able to create a USB-Gadget with the gadgetfs which had only bulk ep. I could communicate with Linux and Windows host. The USB-Device had /dev/ttyGS0 to communicate. But in Windows I had to install WinUSB driver manually.
I work with yocto to create embedded kernel.
I added some line of code here: /linux-imx/drivers/usb/gadget/legacy/serial.c , f_serial.c, u_serial.h to add additional variable os_desc and parameter use_winusb. But the resulting g_serial still creates a COM-Port in Windows10 or a no WinUSB device. For our device we need WinUSB-Device only.
The RNDIS Gadget does has WinUSB support. So I tried to create a own USB-Gadget device with https://github.com/libusbgx/libusbgx. But if I use the USBG_F_SERIAL function type then it can't create WinUSB. See error:
Error setting function OS desc
Error: USBG_ERROR_NOT_FOUND : Not found (file or directory removed)
If I use USBG_F_RNDIS, it works, and with manipulated USB descriptor it'll recognized by Windows as WinUSB device. But Linux implement's it as USB-ETH ethernet device. The USB-Device get's no /dev/ttyGS0 serial connection to communicate.
I'm reading the Linux kernel driver source now, to find the position, where I can simply ann this WinUSB os-descriptor stuff into the USBG_F_SERIAL type. But I think it'll take month to get through.
Any solution would be ok. Patch for the Linux driver sources g_serial or how to configure a USB-Gadgetfs would be great. Any hint, where to put additional code would also be fine.
I wanted to change the kernel, but fortunately found this:
https://blog.soutade.fr/post/2016/07/create-your-own-usb-gadget-with-gadgetfs.html
This code made it easy to add WinUSB features.
Source of modified Version for WinUSB: https://github.com/rundekugel/gadgetfsd/tree/WinUSB

Pre-install driver on Windows

I am trying to create an installer (using Inno Setup) that will pre-install a USB driver for an LCD HMI. I have the drivers from the manufacturer (they appear to be signed). However, no matter what I do, Windows will first detect the driver as a "Gadget Serial v2.4" device, then immediately go to "Windows Update" and downloads a "PNX Bulk Device" driver.
This driver does not work with the HMI. I have to then manually open up Device Manager, find the "PNX Bulk Device", go to "Update Driver Software"..."Browse My Computer", "Have Disk", etc.
This is a very arduous process and may be overwhelming for an inexperienced user.
Is there anyway to automate the process, such that if the package is installed before the USB device is plugged in, then the driver will be in place, and Windows will use the correct driver rather than the Generic ones it is finding?
Note: I have tried the DPInst utility, the SetupCopyOEMInf function and pnputil.exe. All methods "appear" to work (ie: no error messages), but Windows still grabs the generic driver first, no matter what.
I realize my understanding of drivers may be flawed. I'm trying this on a Windows 7 x64 architecture, but I would like it to work universally.

Writing a UMDF virtual device driver (or software device) like Virtual DVD

I have an "off the shelf" commercial software using an ANT USB dongle to communicate with a cycling trainer.
My trainer is not compatible with the software because the protocol is slightly different (not a lot).
My goal is to write a protocol translator. The only thing I can think of is to write a UMDF virtual device driver (like Magic ISO Virtual DVD) looking like an ANT USB Device in the device manager (same PID\VID) while connecting itself to the physical ANT device. The virtual device driver will perform the protocol translation.
I looked at several examples from Microsoft here https://github.com/Microsoft/Windows-driver-samples but I was unable to find anything relevant. I thought this example would be a good start https://github.com/Microsoft/Windows-driver-samples-master/Sensors/CustomSensors but it is impossible to load the driver using the given procedure from the inf file.
BTW I am familiar with the content of INF files and the basics of KMDF & UMDF device drivers programming. My problem is to write something that will load in the device manager and present itself as a real USB device even if it is not enumerated by the USB bus subsystem.
Can anybody with driver development experience point me to some relevant code sample or documentation?
Best regards !
I am currently developing a UMDF CCID (smartcard reader) driver. This project helped me at the beginning because it compiles out of the box and creates virtual device nodes (smartcard readers) visible in the device manager.

Remove incorrect binding of composite device to custom driver

Our latest WHQL'ed custom driver has an incorrect entry for one of our upcoming product. The upcoming product is composite device and our WHQL'ed driver has an entry which matches the device ID for the composite device instead of the individual interfaces.
When the new device is connected to machines which have the WHQL'ed driver, the device gets binded to our driver and not to Windows Generic Parent Driver (usbccgp.sys). This prevents the interfaces in the device from being listed.
We could manually fix this by uninstalling the driver for the device and making it to bind to usbccgp.sys driver. In Vista and higher versions, we could delete the driver binaries at the time of uninstall. But there is no direct way to completely delete the driver binaries in XP. This makes it very difficult to cleanly uninstall the driver
Can this be fixed using an uninstaller? What is the best way to fix the affected machine in an automated way?
Download the Windows Driver Development Kit (Win DDK) and locate the devcon.exe executable for your architecture. Then, from an elevated command prompt:
devcon.exe find =usb
To list all of your current devices.
devcon.exe -r remove =usb *YOUR_HARDWARE_ID*
Will complete disassociate the device and driver from the target machine. If you have trouble getting the hardware id you can blow away all your USB drivers and let Windows auto-detect them after reboot.
devcon.exe -r remove =usb *
Extreme, yes. Effective, yes. We work with virtual comm ports all day and our test machines often experience your same issue. This technique has yet to fail.

Programmatically Add Fake Hardware in Windows

I have created a fake usb flash driver driver in Windows that will fake Windows into thinking that a new hardware device is attached. I have also found the APIs that allow me to enumerate the hardware attached (so I know which device is my fake driver).
The problem is I only want to attach the hardware when my program is running, and I don't want it to be accessible when my program is not running.
How can I programmatically add this hardware or enable/disable this driver? Someone suggested the right nomenclature is "load/unload".
Using VC++ with Windows APIs on Windows 7 and higher.
Try the C++ class wrapper to load/unload device drivers from code project.

Resources