diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-03-01 14:29:03 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-03-01 14:29:03 +0000 |
commit | 908c836a2f65d2410800f01518a6039e49028902 (patch) | |
tree | 3e08a9e28315b4d70f5beff8033c07b369f909f8 /xpp/perl_modules/Dahdi/Xpp | |
parent | 0746ac5aa96958870d2dbf8cb13f603fd1d8600a (diff) |
xpp-dahdi: freepbx code generation; better procfs compatibility
* dahdi_genconf -F will generate chan_dahdi.conf for freepbx
(like genzaptelconf -F)
* Better procfs compatibility for xpp modules.
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6057 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/perl_modules/Dahdi/Xpp')
-rw-r--r-- | xpp/perl_modules/Dahdi/Xpp/Xbus.pm | 63 | ||||
-rw-r--r-- | xpp/perl_modules/Dahdi/Xpp/Xpd.pm | 70 |
2 files changed, 103 insertions, 30 deletions
diff --git a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm index 2cae6f8..b7994f8 100644 --- a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm +++ b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm @@ -46,13 +46,16 @@ sub get_xpd_by_number($$) { return $wanted; } +my %file_warned; # Prevent duplicate warnings about same file. + sub xbus_attr_path($$) { my ($busnum, @attr) = @_; foreach my $attr (@attr) { my $file = sprintf "$Dahdi::Xpp::sysfs_astribanks/xbus-%02d/$attr", $busnum; unless(-f $file) { my $procfile = sprintf "/proc/xpp/XBUS-%02d/$attr", $busnum; - warn "$0: OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"; + warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to '$procfile'\n" + unless $file_warned{$attr}++; $file = $procfile; } next unless -f $file; @@ -92,6 +95,40 @@ sub read_attrs() { } } +sub read_xpdnames_old($) { + my $xbus_num = shift || die; + my $pat = sprintf "/proc/xpp/XBUS-%02d/XPD-[0-9][0-9]", $xbus_num; + my @xpdnames; + + #print STDERR "read_xpdnames_old($xbus_num): $pat\n"; + foreach (glob $pat) { + die "Bad /proc entry: '$_'" unless /^.*XPD-([0-9])([0-9])$/; + my $name = sprintf("%02d:%1d:%1d", $xbus_num, $1, $2); + #print STDERR "\t> $_ ($name)\n"; + push(@xpdnames, $name); + } + return @xpdnames; +} + +sub read_xpdnames($) { + my $xbus_num = shift || die; + my $xbus_dir = "$Dahdi::Xpp::sysfs_astribanks/xbus-$xbus_num"; + my $pat = sprintf "%s/xbus-%02d/[0-9][0-9]:[0-9]:[0-9]", $Dahdi::Xpp::sysfs_astribanks, $xbus_num; + my @xpdnames; + + #print STDERR "read_xpdnames($xbus_num): $pat\n"; + foreach (glob $pat) { + die "Bad /sys entry: '$_'" unless m/^.*\/([0-9][0-9]):([0-9]):([0-9])$/; + my ($busnum, $unit, $subunit) = ($1, $2, $3); + my $name = sprintf("%02d:%1d:%1d", $1, $2, $3); + #print STDERR "\t> $_ ($name)\n"; + push(@xpdnames, $name); + } + return @xpdnames; +} + +my $warned_notransport = 0; + sub new($$) { my $pack = shift or die "Wasn't called as a class method\n"; my $num = shift; @@ -116,18 +153,22 @@ sub new($$) { warn "Bad USB transport='$transport' usbdev='$usbdev'\n"; } } - @{$self->{XPDS}} = (); - opendir(D, $xbus_dir) || die "Failed opendir($xbus_dir): $!"; - while(my $entry = readdir D) { - $entry =~ /^([0-9]+):([0-9]+):([0-9]+)$/ or next; - my ($busnum, $unit, $subunit) = ($1, $2, $3); + my @xpdnames; + my @xpds; + if(-e $transport) { + @xpdnames = read_xpdnames($num); + } else { + @xpdnames = read_xpdnames_old($num); + warn "$0: warning - OLD DRIVER: missing '$transport'. Fall back to /proc\n" + unless $warned_notransport++; + } + foreach my $xpdstr (@xpdnames) { + my ($busnum, $unit, $subunit) = split(/:/, $xpdstr); my $procdir = "/proc/xpp/XBUS-$busnum/XPD-$unit$subunit"; - #print STDERR "busnum=$busnum, unit=$unit, subunit=$subunit procdir=$procdir\n"; - my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, $procdir, "$xbus_dir/$entry"); - push(@{$self->{XPDS}}, $xpd); + my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, $procdir, "$xbus_dir/$xpdstr"); + push(@xpds, $xpd); } - closedir D; - @{$self->{XPDS}} = sort { $a->id <=> $b->id } @{$self->{XPDS}}; + @{$self->{XPDS}} = sort { $a->id <=> $b->id } @xpds; return $self; } diff --git a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm index 297a1d5..e5aed5d 100644 --- a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm +++ b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm @@ -12,6 +12,8 @@ use Dahdi::Utils; use Dahdi::Xpp; use Dahdi::Xpp::Line; +my %file_warned; # Prevent duplicate warnings about same file. + sub xpd_attr_path($@) { my $self = shift || die; my ($busnum, $unitnum, $subunitnum, @attr) = ( @@ -25,7 +27,8 @@ sub xpd_attr_path($@) { unless(-f $file) { my $procfile = sprintf "/proc/xpp/XBUS-%02d/XPD-%1d%1d/$attr", $busnum, $unitnum, $subunitnum; - warn "$0: OLD DRIVER: missing '$file'. Fall back to /proc\n"; + warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to /proc\n" + unless $file_warned{$attr}++; $file = $procfile; } next unless -f $file; @@ -47,13 +50,56 @@ sub xpd_old_gettype($) { return $head; } +sub xpd_old_getspan($) { + my $xpd = shift || die; + my $dahdi_registration = "/proc/xpp/" . $xpd->fqn . "/dahdi_registration"; + open(F, $dahdi_registration) or die "Failed to open '$dahdi_registration': $!"; + my $head = <F>; + close F; + chomp $head; + return $head; +} + +sub xpd_old_getoffhook($) { + my $xpd = shift || die; + my $summary = "/proc/xpp/" . $xpd->fqn . "/summary"; + my $channels; + + local $/ = "\n"; + open(F, "$summary") || die "Failed opening $summary: $!\n"; + my $head = <F>; + chomp $head; # "XPD-00 (BRI_TE ,card present, span 3)" + my $offhook; + while(<F>) { + chomp; + if(s/^\s*offhook\s*:\s*//) { + s/\s*$//; + $offhook = $_; + $offhook || die "No channels in '$summary'"; + last; + } + } + close F; + return $offhook; +} + +my %attr_missing_warned; # Prevent duplicate warnings + sub xpd_getattr($$) { my $xpd = shift || die; my $attr = shift || die; $attr = lc($attr); - my $file = xpd_attr_path($xpd, lc($attr)); + my $file = $xpd->xpd_attr_path(lc($attr)); + # Handle special cases for backward compat return xpd_old_gettype($xpd) if $attr eq 'type' and !defined $file; + return xpd_old_getspan($xpd) if $attr eq 'span' and !defined $file; + return xpd_old_getoffhook($xpd) if $attr eq 'offhook' and !defined $file; + if(!defined($file)) { + warn "$0: xpd_getattr($attr) -- Missing attribute.\n" if + $attr_missing_warned{$attr}; + return undef; + } open(F, $file) || return undef; my $val = <F>; close F; @@ -136,29 +182,15 @@ sub new($$$$$) { my $self = { XBUS => $xbus, ID => "$unit$subunit", + FQN => $xbus->name . "/" . "XPD-$unit$subunit", UNIT => $unit, SUBUNIT => $subunit, DIR => $procdir, SYSFS_DIR => $sysfsdir, }; bless $self, $pack; - local $/ = "\n"; - open(F, "$procdir/summary") || die "Missing summary file in $procdir"; - my $head = <F>; - chomp $head; # "XPD-00 (BRI_TE ,card present, span 3)" - # The driver does not export the number of channels... - # Let's find it indirectly - while(<F>) { - chomp; - if(s/^\s*offhook\s*:\s*//) { - my @offhook = split; - @offhook || die "No channels in '$procdir/summary'"; - $self->{CHANNELS} = @offhook; - last; - } - } - close F; - $self->{FQN} = $xbus->name . "/" . "XPD-$unit$subunit"; + my @offhook = split / /, ($self->xpd_getattr('offhook')); + $self->{CHANNELS} = @offhook; my $type = $self->xpd_getattr('type'); my $span = $self->xpd_getattr('span'); $self->{SPANNO} = $span; |