Fake serial number of USB device

udevusb

I have a mobile phone connected to my PC via USB.

When viewing the device info using

sudo udevadm info --attribute-walk

the product and vendor id's show up fine, but there is no ATTR{serial}. An application I'm using (Android adb) needs the device to report a serial number to work properly.

Is there any way I can fake the serial number of the device, for example by using a udev rule?

Clarification: The question is not on how to get the serial number of the USB device, but on how to set the serial number.

I had an Android phone that does not report a serial number over USB, and the adb tool did not like this too much. So far there does not seem to be any simple solution for this. However, there days it is very easy to just buy a proper Android phone for development.

Best Answer

First, make sure that the device not reporting a serial number is really the problem. adb devices will list the serial number as all question marks if it doesn't have permission to access the corresponding device under /dev/bus/usb/. Also remember the adb starts up a server, you may need to kill that to get it to re-probe.

Assuming it really is a problem with the device, I quickly checked the adb source code. It appears register_device in core/adb/usb_linux.c reads the serial number straight from the device. core/adb/usb_libusb.c calls libusb_get_device_descriptor to do it, which (checking the libusb source code) grabs it from sysfs or directly from the device. So no udev trickery is going to help, unfortunately.

Your choices would seem to be:

  • figure out how to make adb work without a serial number. Possibly, patch adb (it is open source). This is a question more for Stack Overflow, I think.
  • patch to kernel usbfs driver to fake a response to adb's request. This sounds much harder than patching adb to me.
  • patch the kernel to allow faking the serial # in syfs, assuming adb is using libusb.
  • fix the broken hardware.
Related Question