Apr 28 2023
We generally know that when we buy a piece of technology that it will not last forever, connectors wear out and/or go out of fashion. But I think the most frustrating reason to have to get rid of something is that drivers stop being made for devices.
USB has been a remarkable success. It has been with us for a long time and has kept a (mostly, ignoring USB-C) consistent connector. Meaning that very old devices made for USB 1 are still usable in systems that are being sold today. At least this would be the case if the older devices still had drivers for currently relevant operating systems.
The USB universal video, audio and storage classes have provided a standard for devices to implement to ensure that they can work with little custom work on drivers or no extra drivers at all, but they still have to have been made in a time where those standards existed.
A good friend of mine this week was clearing out stuff and handed me an old logitech QuickCam Express webcam, this was actually a pretty serious nostalgic moment as it happened to also be the same model as my first webcam, so thinking it could be funny at some work meetings to have an “early 2000s” vibe I took it home.
However the QuickCam Express has not had drivers since Windows XP it seems. I attached it to my Linux machine, and no module was loaded, and when I then attached it to my Windows 10 VM I was presented with an unknown device. Meaning I was out of luck for official support for this thing.
This was especially annoying since I had already taken this thing home. Not wanting to give up so quickly I decided to go and actually verify if this webcam still worked by installing a copy of Windows XP to see if it would correctly function on a period correct operating system.
(As a side note I believe it should be on record that installing Windows XP on reasonably fast modern systems is very amusing, the setup wizard will say that it has 30 minutes remaining and then proceed to blow through the entire installation in less than 15 seconds)
After installation, I loaded up Windows Movie Maker to see if the webcam would correctly work and was delighted to see that it does. (I must say the quality of webcams has definitely improved since 1999)
So the question was, how are we going to make this webcam that only has drivers up to Windows XP work on a modern day operating system?
In one of my previous blog posts I bought a number of “VGA2USB” video capture devices for very cheap and I later understood that these were very cheap because they also had no modern-day drivers, so I decided to correct it by writing a user space driver (and I now use those devices at least once a month!).
A user space driver is a driver that is embedded inside a program rather than a module of code inside the operating system. This means that the driver can run often on different versions of operating systems and often on different platforms with minimal code changes.
To get an idea of what the Windows XP driver was doing I loaded usbmon into my desktop that was running the Windows XP VM and then recorded the USB traffic going between the virtual machine and the webcam. This is invaluable in reverse engineering since it allows us to see a real time “known good communication” transcript that we can then build our own driver from.
Reassuringly it seemed that the communication was pretty basic, involving what looked like some basic settings bootstrapping and then isochronous data transfer of a pretty basic looking data stream.
I then began to look around to see if anybody had previously written a Linux driver for this webcam, and it turned out someone had in the form of qc-usb. So using that as a base I worked towards getting a very basic setup where I could stream image data.
To start with I used the same libusb wrapper go-usb and set it up to look for the QuickCam’s usb VID and PID:
ctx := gousb.NewContext()
defer ctx.Close()
// idVendor=046d, idProduct=0870,
dev, err := ctx.OpenDeviceWithVIDPID(0x046d