Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
Is it an android phone? If not, adb will not work, anyway. –  Keith Dec 31 '10 at 3:05
    
I'm guessing that adb doesn't actually get this info from udev. Probably from sysfs instead, or directly from the device. Consider patching adb, probably the easiest approach. –  derobert Jan 2 '13 at 16:05
add comment

3 Answers 3

up vote 1 down vote accepted

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.
share|improve this answer
    
Thanks - this explains it. In my case fixing the broken hardware was the easier (buying better hardware). –  Ralf Jan 2 '13 at 19:27
add comment

If you know the device node of the specific device (e.g. /dev/sdb), you can look it up with the following command: udevadm info -a -p $(udevadm info -q path -n /dev/sdb)

Usually, if you're trying to create a custom rule in /etc/udev/rules.d/51-android.rules for android devices, writing lsusb in your terminal will display something like Bus 002 Device 004: ID 062a:3270 Creative Labs . The four characters after "ID"--in this case it would be 062a--are used to indicate the specific idVendor within that file.

share|improve this answer
    
That helps with writing udev rules, but is there any way to write a rule that changes the serial number? –  Ralf Jan 2 '13 at 15:38
    
Don't know for your particular phone, but in my experience once the udev rules are set (and you run adb start-server as root or using sudo), adb will be able to read the serial number on its own. –  Drake Clarris Jan 2 '13 at 19:27
add comment

Probably it's not serial but FTDI, so you can try this way:

1) Get the serial

sudo udevadm info --attribute-walk -n /dev/ttyUSB0  | sed -n '/FTDI/,/serial/p'

2) Create the rule and substitute the XXXXXXXX with the serial you found or a FAKE serial

sudo echo 'SUBSYSTEM=="tty", ATTRS{serial}=="XXXXXXXX", GROUP="users", MODE="0660", SYMLINK+="myusbphone"' | sudo tee /etc/udev/rules.d/99-myusbphone.rules

3) Reload the rules

sudo udevadm control --reload-rules

Hope it helps...

In the case try to contact the author of this article.

share|improve this answer
    
I don't think OP is talking about serial protocol but the serial number of the USB device. That's a little used field in the device descriptor along with vendor and product IDs. It's supposed to be unique to each device but isn't mandatory in the USB spec. No answer for how to fake it, sorry. I'd probably patch the kernel... –  ali1234 Apr 25 '11 at 22:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.