[svn-commits] tzafrir: tools/trunk r7401 - /tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Oct 13 13:21:21 CDT 2009


Author: tzafrir
Date: Tue Oct 13 13:21:17 2009
New Revision: 7401

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=7401
Log:
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.


Modified:
    tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm

Modified: tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm?view=diff&rev=7401&r1=7400&r2=7401
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm Tue Oct 13 13:21:17 2009
@@ -94,7 +94,8 @@
 			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 @@
 	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: $!";




More information about the svn-commits mailing list