summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-11-04 17:25:21 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-11-04 17:25:21 +0000
commit91dfb30679d4412323565cb8ea61795c2d78264a (patch)
tree74b97f6bf9415994418ff5133504eeeca8f9e835
parentd366f60c4269c6918bc0e40393e0593629f69278 (diff)
dahdi-perl fixes, mostly xpp-specific.
* Fix pattern for PCI BRI cards * Fix recognizing xpp devices by @connector in xpp_order * Print more helpful comments in xpp_order * Remove most (if not all) need of /proc/bus/usb * Handle other similar "is_twinstar" errors. Merged revisions 6975,7000,7223,7401,7462 via svnmerge from http://svn.digium.com/svn/dahdi/tools/trunk ........ r6975 | tzafrir | 2009-08-12 22:02:00 +0300 (Wed, 12 Aug 2009) | 2 lines dahdi-perl: Remove a pointless whitespace in BRI strings list ........ r7000 | tzafrir | 2009-08-14 00:40:01 +0300 (Fri, 14 Aug 2009) | 4 lines dahdi-perl: don't re-append '@' when testing the Astribank connector string xpp rev: 7291 ........ r7223 | tzafrir | 2009-09-27 16:38:50 +0200 (Sun, 27 Sep 2009) | 7 lines dahdi_genconf: xpp_order generator: Extra '#' after connector comment Add an extra '#' right after the connector string to make it simpler to use the connector string from the generated xpp_order. xpp rev: 7292 ........ r7401 | tzafrir | 2009-10-13 20:21:17 +0200 (Tue, 13 Oct 2009) | 12 lines 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. ........ r7462 | tzafrir | 2009-11-04 13:48:43 +0200 (Wed, 04 Nov 2009) | 6 lines dahdi-perl: Avoid '"is_twinstar" on unblessed reference' Dpn't panic if a device is not found in the list of hardware. This is not only indication of a bug, but can also happen if a device appeared after the script was started. ........ git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/branches/2.2@7473 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rw-r--r--xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm2
-rw-r--r--xpp/perl_modules/Dahdi/Hardware/USB.pm61
-rw-r--r--xpp/perl_modules/Dahdi/Span.pm2
-rw-r--r--xpp/perl_modules/Dahdi/Xpp.pm3
4 files changed, 55 insertions, 13 deletions
diff --git a/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm b/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm
index a98f912..e7bfb72 100644
--- a/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm
+++ b/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm
@@ -111,7 +111,7 @@ HEAD
my $label = $xbus->label;
my $connector = $xbus->connector;
my $name = $xbus->name;
- printf "%s\t# %s (%s)\n", $label, $connector, $name;
+ printf "%s\t# %s #(%s)\n", $label, $connector, $name;
}
close F;
select $old;
diff --git a/xpp/perl_modules/Dahdi/Hardware/USB.pm b/xpp/perl_modules/Dahdi/Hardware/USB.pm
index af0274f..722b87b 100644
--- a/xpp/perl_modules/Dahdi/Hardware/USB.pm
+++ b/xpp/perl_modules/Dahdi/Hardware/USB.pm
@@ -77,7 +77,6 @@ sub set_transport($$) {
my $xbus = shift || die;
my $xbus_dir = shift;
my $transportdir = "$xbus_dir/transport";
- my $hwdev;
if(! -e "$transportdir/ep_00") {
warn "A trasnport in '$transportdir' is not USB";
return undef;
@@ -94,25 +93,69 @@ 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);
#printf STDERR "DEBUG: %03d/%03d\n", $busnum, $devnum;
$xbus->{USB_DEVNAME} = $usbname;
- $hwdev = Dahdi::Hardware->device_by_hwname("usb:$usbname");
- #print "set_transport: ", $hwdev, "\n";
- $xbus->{TRANSPORT} = $hwdev;
- $hwdev->{XBUS} = $xbus;
- $hwdev->{LOADED} = 'xpp_usb';
- $xbus->{IS_TWINSTAR} = $hwdev->is_twinstar;
+ my $hwdev = Dahdi::Hardware->device_by_hwname("usb:$usbname");
+ if(defined $hwdev) {
+ #print "set_transport: ", $hwdev, "\n";
+ $xbus->{TRANSPORT} = $hwdev;
+ $hwdev->{XBUS} = $xbus;
+ $hwdev->{LOADED} = 'xpp_usb';
+ $xbus->{IS_TWINSTAR} = $hwdev->is_twinstar;
+ }
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: $!";
diff --git a/xpp/perl_modules/Dahdi/Span.pm b/xpp/perl_modules/Dahdi/Span.pm
index bd5eeee..b7987e1 100644
--- a/xpp/perl_modules/Dahdi/Span.pm
+++ b/xpp/perl_modules/Dahdi/Span.pm
@@ -131,7 +131,7 @@ sub by_number($) {
my @bri_strings = (
'BRI_(NT|TE)',
- '(?:quad|octo)BRI PCI ISDN Card.* \[(NT|TE)\]\ ',
+ '(?:quad|octo)BRI PCI ISDN Card.* \[(NT|TE)\]',
'octoBRI \[(NT|TE)\] ',
'HFC-S PCI A ISDN.* \[(NT|TE)\] ',
'(B4XXP) \(PCI\) Card', # Does not expose NT/TE type
diff --git a/xpp/perl_modules/Dahdi/Xpp.pm b/xpp/perl_modules/Dahdi/Xpp.pm
index f9e62a5..7ac574b 100644
--- a/xpp/perl_modules/Dahdi/Xpp.pm
+++ b/xpp/perl_modules/Dahdi/Xpp.pm
@@ -206,10 +206,9 @@ sub add_xpporder(@) {
# Overrides from config file
foreach my $xbus (@xbuses) {
my $label = $xbus->label;
- my $connector = '@' . $xbus->connector;
my $val;
$val = $order{$label};
- $val = $order{$connector} unless defined $val;
+ $val = $order{$xbus->connector} unless defined $val;
$xbus->{XPPORDER} = $val if defined $val;
}
}