12.07.2015 Views

Udev unplugged - Sarath Lakshman

Udev unplugged - Sarath Lakshman

Udev unplugged - Sarath Lakshman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

IntroducingTable 1: Operations for udev keysOperatorprogram additionally may be matched with theRESULT key.• ATTR: different attributes for the device like size,product ID, vendor, etc.• RESULT: matches the returned string of the lastPROGRAM call. This key may be used in any rulefollowing a PROGRAM call.• RUN: it can be set to some external program that canbe executed when a device is detected.• SYMLINK: for creating symlinks for the matchingdevice.• ACTION: permits two match conditions ‘add’ and‘remove’ when a new device is added or removed.In addition to this, Table 1 lists different operators youcan use with each of the keys.Now the question is: how do we collect informationabout devices?Writing a rule is, in turn, matching the device byspecifying unique bytes about the device. The uniqueinformation about the device can be grabbed from sysfs:[slynux@gnubox tmp]$ cat /sys/block/sda/sda1/size14336000Meaning== For matching. Eg: KERNEL==”ttyUSB0”= Setting a parameter. Eg: NAME=”my_disk”+= Adding to list. Eg: SYMLINK+=”cd1 cd2”Here I have retrieved an attribute size for the devicesda1. Now I can use ATTR{size}==”14336000” to matchthe device /dev/sda1.To make the job easier, we have a udev utility calledudevinfo, which can be used to collect details aboutdevices and write rules in a very handy way. The followingis the udevinfo output for the same /dev/sda1:Now the match is ready! You can even create a symlinkfor the device as /dev/musicdrive:KERNEL==”sda1” , SUBSYSTEM==”block” , ATTR{dev}==”8:1”, 2048” ,SYMLINK+=”musicdrive”Alternatively, you can use the following to obtaininformation about any device name:# udevinfo -a -p `udevinfo -q path -n /dev/devicename`Setting up an automatic Internet connectionI depend on BSNL EVDO/CDMA for Internet access. I haveconfigured the dialling by using the wvdial PPP utility,and I issue the wvdial command to connect under Fedora9. I found it interesting to write udev rules to auto connectInternet whenever I plug in the EVDO USB modem.Here’s how to get started: first, plug in the EVDOdevice in the USB port; second, run the dmesg commandat a terminal prompt. I received the following dmesgoutput:usb 6-2: New USB device found, idVendor=05c6, idProduct=6000usb 6-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0usb 6-2: Product: ZTE CDMA Techusb 6-2: Manufacturer: ZTE, IncorporatedBut there was no suitable kernel module loaded tocreate /dev/ttyUSB0, which is the device node for thecorresponding device. You might try manually loading theUSB serial module specifying the Product ID and vendorID parameters—that is, idVendor=05c6, idProduct=6000.Run the following command as the root user:/sbin/modprobe usbserial product=0x6000 vendor=0x05c6Executing the dmesg command again brings up thefollowing:# udevinfo -a -p /sys/block/sda/sda1looking at device ‘/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1’:KERNEL==”sda1”SUBSYSTEM==”block”DRIVER==””ATTR{dev}==”8:1”ATTR{start}==”2048”ATTR{size}==”14336000”ATTR{stat}==” 190 59 2162 1655 30 31 488 8360 1652 2491”As you can see, it returned a lot of information aboutthe device. We will take some of the above lines to make audev rule:KERNEL==”sda1” , SUBSYSTEM==”block” , ATTR{dev}==”8:1”, 2048”usb 6-2: configuration #1 chosen from 1 choiceusbserial_generic 6-2:1.0: generic converter detectedusb 6-2: generic converter now attached to ttyUSB0As you can see, this time /dev/ttyUSB0 is created andmade available. [Actually when the module usbserial isloaded using the modprobe command, it is required tomanually create /dev/ttyUSB0 using the mknod command.But there is a default udev rule that creates the device.]Now we have to dial wvdial as the root in orderto connect. How do we transform this manual processto a udev rule? Run the following command to collectappropriate parameters to match the device:udevinfo -a -p $(udevinfo -q path -n /dev/ttyUSB0)Now, create a file called /etc/udev/rules.d/100-bsnl.80December 2008 | LINUX For You | www.openITis.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!