LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 06-20-2014, 08:28 AM   #1
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Rep: Reputation: 17
Question Getting a device recognized: custom udev rule?


Dear udev experts,

we have a little smart-phone (Huawei Ideos) bearing a SD card, which used to be recognized as mass storage in a trouble-free way when attached to a Linux PC (running debian/testing and KDE 4.13.1) via usb cable.

Some months ago it wasn't detected automatically anymore, but we found some easy clue (albeit unhandsome, because it requires root privileges) to workaround that: starting gparted manually triggered something that caused the system to recognize the partition.

Meanwhile even this little trick doesn't work anymore.

After the device is connected, "tail -f /var/log/messages" shows:
Code:
Jun 20 15:17:22 mybox kernel: [...] usb 1-1.2: new high-speed USB device number 27 using ehci-pci
Jun 20 15:17:22 mybox kernel: [...] usb 1-1.2: New USB device found, idVendor=12d1, idProduct=1037
Jun 20 15:17:22 mybox kernel: [...] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 20 15:17:22 mybox kernel: [...] usb 1-1.2: Product: Android Adapter
Jun 20 15:17:22 mybox kernel: [...] usb 1-1.2: Manufacturer: Huawei Incorporated
Jun 20 15:17:22 mybox kernel: [...] usb 1-1.2: SerialNumber: (...)
Jun 20 15:17:22 mybox kernel: [...] usb-storage 1-1.2:1.0: USB Mass Storage device detected
Jun 20 15:17:22 mybox kernel: [...] scsi41 : usb-storage 1-1.2:1.0
Jun 20 15:17:23 mybox usb_modeswitch: switch device 12d1:1037 on 001/027
That seems okay, but there is no additional block device on the linux side. After enabling USB usage on the Android side, nothing more happens.

However, we found the following (reloading the usb_storage driver) to be sufficient:
Code:
/sbin/modprobe -r usb_storage
/sbin/modprobe usb_storage
Hence, all we miss is a sensible way to automate this. We thought, /etc/udev/rules.d/ should be the right place to deposit a small script, but nothing worked.

After some hours of unavailingly searching for inspiring examples, I dare to ask whether someone with deeper expertise has any suggestion...?

Last edited by devdol; 06-25-2014 at 03:26 AM. Reason: found a wokraround
 
Old 06-21-2014, 11:50 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Here is an article from android.com on how to create a udev rule to automate the connection. You will have to edit the command which is given to change the vendor id number from a list at the bottom of the article.
http://developer.android.com/tools/device.html
 
Old 06-21-2014, 01:52 PM   #3
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Original Poster
Rep: Reputation: 17
Hello bigrigdriver,

thanks, that made some progress! In summary, we created /etc/udev/rules.d/51-android.rules as root, readably by all, and containing
Code:
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666", GROUP="plugdev"
Code:
After that, in fact two block devices (representing the smartphone's built in memory an its SD card) show up when plugged...
UDEV  [501.038346] add      /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:0/block/sdd (block)
UDEV  [501.038382] add      /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:2/block/sde (block)
UDEV  [501.043141] change   /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:0/block/sdd (block)
UDEV  [501.044182] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:0/block/sdd (block)
UDEV  [501.044965] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:0 (scsi)
UDEV  [501.051113] change   /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:2/block/sde (block)
UDEV  [501.051862] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/host11/target11:0:0/11:0:0:2/block/sde (block)
... but are "changed" and "removed" immediately after. So, we suppose, to clear up the sequence of events, one should be able to monitor not only the results (by udevadm monitor) but also the sequence of rules that control them. Because maybe we don't have to add additional rules but comment out (or modify) existing ones?

(Our system does not know an udevtrigger command, nor udevtest nor udevcontrol reload_rules. We suppose udevadm trigger, udevadm test are the successors of the first ones.)

But at the moment, we are dazed puzzled about the whole confusing scenario.



UPDATE

Amongst many others, we found a rule in /lib/udev/rules.d/40-usb_modeswitch.rules that is without counterpart on an Ubuntu system (12.04), where mass storage is detected and enabled as expected:

Code:
# Generic entry for all Huawei devices
ATTRS{idVendor}=="12d1", ATTR{bInterfaceNumber}=="00", ATTR{bInterfaceClass}=="08", RUN+="usb_modeswitch '%b/%k'"
If we comment this line out on our Debian System, block devices do appear:
Code:
...
UDEV  [1050015.057403] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/scsi_disk/56:0:0:0 (scsi_disk)
UDEV  [1050015.057693] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/scsi_generic/sg4 (scsi_generic)
UDEV  [1050015.058741] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/bsg/56:0:0:0 (bsg)
UDEV  [1050015.060412] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:1/scsi_generic/sg5 (scsi_generic)
KERNEL[1050015.061783] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/block/sdd (block)
UDEV  [1050015.063166] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2 (scsi)
UDEV  [1050015.064851] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/scsi_disk/56:0:0:2 (scsi_disk)
UDEV  [1050015.065901] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/scsi_device/56:0:0:2 (scsi_device)
UDEV  [1050015.066008] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/bsg/56:0:0:2 (bsg)
UDEV  [1050015.066108] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/scsi_generic/sg6 (scsi_generic)
KERNEL[1050015.070671] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/block/sde (block)
UDEV  [1050015.073846] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/block/sdd (block)
UDEV  [1050015.074457] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:1/block/sr1 (block)
"/org/freedesktop/UDisks2/drives/Huawei_Incorporated_Android_Adapter_CC96A0C3FBD3" has new interfaces: ("org.freedesktop.UDisks2.Drive") 
UDEV  [1050015.094046] add      /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/block/sde (block)
UDEV  [1050015.100281] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:1/block/sr1 (block)
UDEV  [1050015.102456] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/block/sde (block)
UDEV  [1050015.102585] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:2/block/sde (block)
UDEV  [1050015.129124] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/block/sdd (block)
"/org/freedesktop/UDisks2/block_devices/sdd" has new interfaces: ("org.freedesktop.UDisks2.Block") 
UDEV  [1050015.158534] change   /devices/pci0000:00/0000:00:1a.7/usb9/9-1/9-1:1.0/host56/target56:0:0/56:0:0:0/block/sdd (block)
"/org/freedesktop/UDisks2/drives/Huawei_Incorporated_Android_Adapter_CC96A0C3FBD3_1" has new interfaces: ("org.freedesktop.UDisks2.Drive") 
"/org/freedesktop/UDisks2/block_devices/sr1" has new interfaces: ("org.freedesktop.UDisks2.Block") 
"/org/freedesktop/UDisks2/drives/Huawei_Incorporated_Android_Adapter_CC96A0C3FBD3_2" has new interfaces: ("org.freedesktop.UDisks2.Drive") 
"/org/freedesktop/UDisks2/block_devices/sde" has new interfaces: ("org.freedesktop.UDisks2.Block")
Now, it is still necessary to make them available the usual way.

Last edited by devdol; 06-24-2014 at 02:54 AM.
 
Old 06-25-2014, 03:05 AM   #4
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Original Poster
Rep: Reputation: 17
Smile

Thanks to nopes from ther german forum, who pointed me to a relevant posting from thatguychuck (read that for details), I tried
to enable kernel polling for the current uptime by:
Code:
# cat          /sys/module/block/parameters/events_dfl_poll_msecs
0
# echo 2000 >  /sys/module/block/parameters/events_dfl_poll_msecs
After that, it worked!

Even when 40-usb_modeswitch.rules (see above) is reverted to its original state (that is, "Generic entry for all Huawei devices" re-enabled), so kernel polling seems to be the only thing to change.

To make kernel polling permanent:
Code:
/etc/rc.local: echo 2000 > /sys/module/block/parameters/events_dfl_poll_msecs
Just enabling kernel polling triggers the usual automatism, e.g. updating KDE's device notifier.

While I feel like happily declaring this problem as solved, I am quite sure, that this is just one of different solutions and certainly not the most elegant one (the fact that the ubuntu reference system mentioned above has 0 kernel polling, too, lends colour to this hypothesis).
However, at least within a couple of hours, I have not experienced side-effects.

So, if you can propose an even better approach, please post it here!

Last edited by devdol; 06-25-2014 at 04:33 AM. Reason: clarification
 
  


Reply

Tags
block device, recognition, rule, udev



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom udev rule not creating device node. DVB related vdemuth Slackware 5 01-24-2012 12:53 PM
udev rule executes command, wont add device node DigiLogik Linux - General 0 05-21-2009 05:19 PM
UDEV - Camera custom rule syntax Toods Slackware 1 11-20-2007 06:03 AM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 03:43 AM
Wrong group with custom udev rule enragedchip Linux - Hardware 1 12-11-2005 02:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 02:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration