xpp: better dahdi_registration
Improvements to the xpp tool dahdi_registration: * Use the new xpp driver with support for dahdi_registration sysfs attribute in each device. * Wait for UDEV to finish handling span assignments (via dahdi_waitfor_span_assignments). * Still supports legacy drivers without this, by falling back to old style iterative "registration" on each xpd. Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
This commit is contained in:
parent
b1d55683ae
commit
ca09f327ed
@ -74,8 +74,6 @@ if(defined($on)) { # Translate to booleans
|
|||||||
$should_output = 0 unless $verbose;
|
$should_output = 0 unless $verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
undef $on if $dahdi_autoreg and not $opts{'R'};
|
|
||||||
|
|
||||||
sub state2str($) {
|
sub state2str($) {
|
||||||
return (shift)?"on":"off";
|
return (shift)?"on":"off";
|
||||||
}
|
}
|
||||||
@ -84,39 +82,42 @@ sub myprintf {
|
|||||||
printf @_ if $should_output;
|
printf @_ if $should_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
my @spans = Dahdi::spans;
|
|
||||||
|
|
||||||
foreach my $xbus (Dahdi::Xpp::xbuses($sorter)) {
|
foreach my $xbus (Dahdi::Xpp::xbuses($sorter)) {
|
||||||
myprintf "%-10s\t%3s-%s\t%s\n",
|
my $prev = $xbus->dahdi_registration($on);
|
||||||
$xbus->name, $xbus->xpporder, $xbus->label, $xbus->connector;
|
|
||||||
next unless $xbus->status eq 'CONNECTED';
|
|
||||||
foreach my $xpd (Dahdi::Xpp::Xpd::telephony_devs($xbus->xpds())) {
|
|
||||||
my $prev = $xpd->dahdi_registration($on);
|
|
||||||
if(!defined($prev)) { # Failure
|
if(!defined($prev)) { # Failure
|
||||||
printf "%s: Failed %s\n", $xpd->fqn, $!;
|
printf STDERR "%s: Failed %s\n", $xbus->name, $!;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
myprintf "\t%-10s: ", $xpd->fqn;
|
my $reg_str;
|
||||||
if(!defined($on)) { # Query only
|
if (defined $on) {
|
||||||
my ($span) = grep { $_->name eq $xpd->fqn } @spans;
|
$reg_str = ($on) ? "registering" : "unregistering";
|
||||||
my $spanstr = ($span) ? ("Span " . $span->num) : "";
|
} else {
|
||||||
myprintf "%s %s\n", state2str($prev), $spanstr ;
|
$reg_str = ($prev) ? "registered" : "unregistered";
|
||||||
next;
|
|
||||||
}
|
}
|
||||||
myprintf "%3s ==> %3s\n", state2str($prev), state2str($on);
|
myprintf "%-10s\t%3s-%s\t%s (%s)\n",
|
||||||
}
|
$xbus->name, $xbus->xpporder, $xbus->label, $xbus->connector,
|
||||||
next unless defined($on) && $on;
|
$reg_str;
|
||||||
|
next unless $xbus->status eq 'CONNECTED';
|
||||||
# Only assign if no default assignment, or forced by '-R' option
|
# Only assign if no default assignment, or forced by '-R' option
|
||||||
|
if (defined($on) && $on) {
|
||||||
if ($opts{'R'} || ! $default_auto_assign) {
|
if ($opts{'R'} || ! $default_auto_assign) {
|
||||||
# Emulate /etc/dahdi/assigned-spans.conf:
|
# Emulate /etc/dahdi/assigned-spans.conf:
|
||||||
# - We iterate over $xbus according to /etc/dahdi/xpp_order
|
# - We iterate over $xbus according to /etc/dahdi/xpp_order
|
||||||
# - We "auto" assign all spans of current $xbus
|
# - We "auto" assign all spans of current $xbus
|
||||||
my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
|
my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
|
||||||
myprintf "auto-assign $devpath\n";
|
|
||||||
my @cmd = ('dahdi_span_assignments', 'auto', $devpath);
|
my @cmd = ('dahdi_span_assignments', 'auto', $devpath);
|
||||||
system @cmd;
|
system @cmd;
|
||||||
warn "Failed '@cmd' (status=$?)\n" if $?;
|
warn "Failed '@cmd' (status=$?)\n" if $?;
|
||||||
}
|
}
|
||||||
|
# wait for UDEV to do its stuff
|
||||||
|
system "dahdi_waitfor_span_assignments assigned";
|
||||||
|
}
|
||||||
|
foreach my $xpd (Dahdi::Xpp::Xpd::telephony_devs($xbus->xpds())) {
|
||||||
|
my $spanno = $xpd->xpd_getattr('span');
|
||||||
|
myprintf "\t%-10s: ", $xpd->fqn;
|
||||||
|
my $spanstr = ($spanno) ? ("Span " . $spanno) : "unassigned";
|
||||||
|
myprintf "%s\n", $spanstr ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
myprintf "# Sorted: $sort_order\n" if defined $sort_order;
|
myprintf "# Sorted: $sort_order\n" if defined $sort_order;
|
||||||
|
|
||||||
|
@ -146,6 +146,40 @@ sub new($$) {
|
|||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub dahdi_registration($$) {
|
||||||
|
my $xbus = shift;
|
||||||
|
my $on = shift;
|
||||||
|
my $result;
|
||||||
|
my $file = sprintf("%s/dahdi_registration", $xbus->sysfs_dir);
|
||||||
|
# Handle old drivers without dahdi_registration xbus attribute
|
||||||
|
if (! -f $file) {
|
||||||
|
warn "Old xpp driver without dahdi_registration support. Emulating it using xpd/span support\n";
|
||||||
|
my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();
|
||||||
|
my $prev;
|
||||||
|
foreach my $xpd (@xpds) {
|
||||||
|
$prev = $xpd->dahdi_registration($on);
|
||||||
|
}
|
||||||
|
return $prev;
|
||||||
|
}
|
||||||
|
# First query
|
||||||
|
open(F, "$file") or die "Failed to open $file for reading: $!";
|
||||||
|
$result = <F>;
|
||||||
|
chomp $result;
|
||||||
|
close F;
|
||||||
|
if(defined($on) and $on ne $result) { # Now change
|
||||||
|
open(F, ">$file") or die "Failed to open $file for writing: $!";
|
||||||
|
print F ($on)?"1":"0";
|
||||||
|
if(!close(F)) {
|
||||||
|
if($! == 17) { # EEXISTS
|
||||||
|
# good
|
||||||
|
} else {
|
||||||
|
undef $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
sub pretty_xpds($) {
|
sub pretty_xpds($) {
|
||||||
my $xbus = shift;
|
my $xbus = shift;
|
||||||
my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();
|
my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();
|
||||||
|
Loading…
Reference in New Issue
Block a user