diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-10-13 18:21:17 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-10-13 18:21:17 +0000 |
commit | ee453cb6ce6863f1b3f87888bf4572d1f6455cb3 (patch) | |
tree | 18d6a3c3af7d01144c362f73f86e6f8f81662422 /xpp/perl_modules/Dahdi | |
parent | 55b5a9cc5ea6f7f634a3b6b667c39b7c5cb02a8f (diff) |
xpp: make /proc/bus/usb/devices optional
Get the information we read from /proc/bus/usb/devices from
/sys/bus/usb/devices . Tested on my Debian Unstable with 2.6.30 kernel.
The default is still /proc/bus/usb and sysfs is only used if the procfs
file is not found.
Also fixes a case of using the sysfs attribute busnum, that does not
exist in kernel 2.6.9 . Devise the bus number from the name of the node.
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@7401 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/perl_modules/Dahdi')
-rw-r--r-- | xpp/perl_modules/Dahdi/Hardware/USB.pm | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/xpp/perl_modules/Dahdi/Hardware/USB.pm b/xpp/perl_modules/Dahdi/Hardware/USB.pm index af0274f..56ac23a 100644 --- a/xpp/perl_modules/Dahdi/Hardware/USB.pm +++ b/xpp/perl_modules/Dahdi/Hardware/USB.pm @@ -94,7 +94,8 @@ sub set_transport($$) { warn "Bad USB transportdir='$transportdir' usbdev='$usbdev'\n"; } } elsif(-d "$transportdir/usb_endpoint") { - $busnum = readval("$transportdir/busnum"); + $transportdir =~ m|/(\d+)-\d+$|; + $busnum = $1; $devnum = readval("$transportdir/devnum"); } my $usbname = sprintf("%03d/%03d", $busnum, $devnum); @@ -109,10 +110,51 @@ sub set_transport($$) { return $hwdev; } +sub _get_attr($) { + my $attr_file = shift; + + open(ATTR, $attr_file) or die "Failed to read SysFS attribute $attr_file\n"; + my $value = <ATTR>; + chomp $value; + return $value; +} + +sub scan_devices_sysfs($) { + my $pack = shift || die; + my @devices = (); + + while (</sys/bus/usb/devices/*-*>) { + next unless -r "$_/idVendor"; # endpoints + + # Older kernels, e.g. 2.6.9, don't have the attribute + # busnum: + m|/(\d+)-\d+$|; + my $busnum = $1 || next; + my $devnum = _get_attr("$_/devnum"); + my $vendor = _get_attr("$_/idVendor"); + my $product = _get_attr("$_/idProduct"); + my $serial = _get_attr("$_/serial"); + my $devname = sprintf("%03d/%03d", $busnum, $devnum); + my $model = $usb_ids{"$vendor:$product"}; + next unless defined $model; + my $d = Dahdi::Hardware::USB->new( + IS_ASTRIBANK => ($model->{DRIVER} eq 'xpp_usb')?1:0, + PRIV_DEVICE_NAME => $devname, + VENDOR => $vendor, + PRODUCT => $product, + SERIAL => $serial, + DESCRIPTION => $model->{DESCRIPTION}, + DRIVER => $model->{DRIVER}, + ); + push(@devices, $d); + } + return @devices; +} + sub scan_devices($) { my $pack = shift || die; my $usb_device_list = "/proc/bus/usb/devices"; - return unless (-r $usb_device_list); + return $pack->scan_devices_sysfs() unless (-r $usb_device_list); my @devices; open(F, $usb_device_list) || die "Failed to open $usb_device_list: $!"; |