summaryrefslogtreecommitdiff
path: root/kernel/xpp/utils/zconf/Zaptel/Config/Gen
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/xpp/utils/zconf/Zaptel/Config/Gen')
-rw-r--r--kernel/xpp/utils/zconf/Zaptel/Config/Gen/Unicall.pm4
-rw-r--r--kernel/xpp/utils/zconf/Zaptel/Config/Gen/Users.pm2
-rw-r--r--kernel/xpp/utils/zconf/Zaptel/Config/Gen/Xpporder.pm142
-rw-r--r--kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zapata.pm4
-rw-r--r--kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zaptel.pm47
5 files changed, 186 insertions, 13 deletions
diff --git a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Unicall.pm b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Unicall.pm
index 3e1048d..6d9552f 100644
--- a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Unicall.pm
+++ b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Unicall.pm
@@ -32,7 +32,9 @@ sub generate($) {
print "Generating $file\n" if $genopts->{verbose};
open(F, ">$file") || die "$0: Failed to open $file: $!\n";
my $old = select F;
- printf "; Autogenerated by %s on %s -- do not hand edit\n", $0, scalar(localtime);
+ printf "; Autogenerated by $0 on %s\n", scalar(localtime);
+ print "; If you edit this file and execute $0 again,\n";
+ print "; your manual changes will be LOST.\n";
print "; This file should be #included in unicall.conf\n\n";
foreach my $span (@spans) {
next unless $span->is_digital();
diff --git a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Users.pm b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Users.pm
index 7c9e937..dbbf9d2 100644
--- a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Users.pm
+++ b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Users.pm
@@ -88,6 +88,8 @@ sub generate($) {
;! Filename: @{[basename($file)]} ($file)
;! Generator: $0
;! Creation Date: @{[scalar(localtime)]}
+;! If you edit this file and execute $0 again,\n";
+;! your manual changes will be LOST.\n";
;!
[general]
;
diff --git a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Xpporder.pm b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Xpporder.pm
new file mode 100644
index 0000000..0d34d93
--- /dev/null
+++ b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Xpporder.pm
@@ -0,0 +1,142 @@
+package Zaptel::Config::Gen::Xpporder;
+use strict;
+
+use Zaptel::Config::Gen qw(is_true);
+use Zaptel::Xpp;
+
+sub new($$$) {
+ my $pack = shift || die;
+ my $gconfig = shift || die;
+ my $genopts = shift || die;
+ my $file = $ENV{XPPORDER_CONF} || "/etc/xpp_order";
+ my $self = {
+ FILE => $file,
+ GCONFIG => $gconfig,
+ GENOPTS => $genopts,
+ };
+ bless $self, $pack;
+ return $self;
+}
+
+#
+# Returns list of xbuses sorted by the span numbers assigned
+# to their XPD's. Also checks that each XBUS span numbers are sequential.
+sub get_sorted_xbuses(@) {
+ my @spans = @_; # Verify our spans
+ my @xbuses = Zaptel::Xpp::xbuses;
+ my %xbus_of_span;
+ my %xbus_beginning;
+ my %seen_spans;
+ my @sorted_xbuses;
+ foreach my $xbus (@xbuses) {
+ my $last_spanno;
+ foreach my $xpd ($xbus->xpds) {
+ my $spanno = $xpd->spanno;
+ if(!$spanno) {
+ printf STDERR "%s: Is not registered. Skipping.\n", $xpd->fqn;
+ next;
+ }
+ $seen_spans{$spanno}++;
+ if($xbus_of_span{$spanno}) {
+ printf STDERR "%s: Span %d already seen on %s\n",
+ $xpd->fqn, $spanno, $xbus_of_span{$spanno}->name;
+ die;
+ }
+ $xbus_of_span{$spanno} = $xbus;
+ # Check XPD's sequential numbering
+ if(defined $last_spanno) {
+ if($last_spanno + 1 != $spanno) {
+ printf STDERR "%s: Bad span numbers (%d, %d)\n",
+ $xpd->fqn, $last_spanno, $spanno;
+ die;
+ }
+ } else {
+ $xbus_beginning{$xbus} = $spanno;
+ }
+ $last_spanno = $spanno;
+ }
+ }
+ foreach my $span (@spans) {
+ my $spanno = $span->num;
+ if(!defined($seen_spans{$spanno})) {
+ warn "Span $spanno: Ignored: Does not belong to any XPD\n";
+ }
+ }
+ @sorted_xbuses = sort { $xbus_beginning{$a} <=> $xbus_beginning{$b} } @xbuses;
+ return @sorted_xbuses;
+}
+
+sub generate($$$) {
+ my $self = shift || die;
+ my $file = $self->{FILE};
+ my $gconfig = $self->{GCONFIG};
+ my $genopts = $self->{GENOPTS};
+ my @spans = @_; # Verify it's all our spans
+ my @xbuses = get_sorted_xbuses(@spans);
+ warn "Empty configuration -- no xbuses\n" unless @xbuses;
+ rename "$file", "$file.bak"
+ or $! == 2 # ENOENT (No dependency on Errno.pm)
+ or die "Failed to backup old config: $!\n";
+ #$gconfig->dump;
+ print "Generating $file\n" if $genopts->{verbose};
+ open(F, ">$file") || die "$0: Failed to open $file: $!\n";
+ my $old = select F;
+ printf "# Autogenerated by $0 on %s\n", scalar(localtime);
+ print "# If you edit this file and execute $0 again,\n";
+ print "# your manual changes will be LOST.\n";
+ print <<'HEAD';
+#
+# This is an optional configuration file for ordering
+# Zaptel registration.
+#
+# It is read from /etc/xpp_order. This location
+# may be overridden via the environment variable XPPORDER_CONF
+#
+# Lines may contain:
+# - The Astribank label (verbatim)
+# - The Astribank connector string (prefixed with @)
+# Ordering number of each listed Astribank is determined
+# by its position in this file.
+# Astribanks not listed in this file, get an ordering
+# number of 99 (last).
+#
+# Astribanks with same ordering number are sorted by their
+# connectors (to preserve legacy behavior).
+#
+# Examples:
+#usb:1234
+#@usb-0000:06:02.2-2
+HEAD
+ foreach my $xbus (@xbuses) {
+ my $label = $xbus->label;
+ my $connector = $xbus->connector;
+ my $name = $xbus->name;
+ printf "%s\t# %s (%s)\n", $label, $connector, $name;
+ }
+ close F;
+ select $old;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Xpporder - Generate Astribank ordering information for zt_registration.
+
+=head1 SYNOPSIS
+
+ use Zaptel::Config::Gen::Xpporder;
+
+ my $cfg = new Zaptel::Config::Gen::Xpporder(\%global_config, \%genopts);
+ $cfg->generate;
+
+=head1 DESCRIPTION
+
+Generate the F</etc/xpp_order>.
+This is the configuration for zt_registration(1).
+The order is determined according to current Zaptel registration
+order.
+
+Its location may be overriden via the environment variable F<XPPORDER_CONF>.
diff --git a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zapata.pm b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zapata.pm
index e8fd733..8e0ebce 100644
--- a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zapata.pm
+++ b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zapata.pm
@@ -140,7 +140,9 @@ sub generate($) {
print "Generating $file\n" if $genopts->{verbose};
open(F, ">$file") || die "$0: Failed to open $file: $!\n";
my $old = select F;
- printf "; Autogenerated by %s on %s -- do not hand edit\n", $0, scalar(localtime);
+ printf "; Autogenerated by $0 on %s\n", scalar(localtime);
+ print "; If you edit this file and execute $0 again,\n";
+ print "; your manual changes will be LOST.\n";
print <<"HEAD";
; Zaptel Channels Configurations (zapata.conf)
;
diff --git a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zaptel.pm b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zaptel.pm
index 2c30c33..892442f 100644
--- a/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zaptel.pm
+++ b/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Zaptel.pm
@@ -39,11 +39,6 @@ sub gen_digital($$) {
$span_crc4 = '';
$framing = 'cas';
}
- my $dchan_type = 'dchan';
- if ($span->is_bri() && is_true($gconfig->{'bri_hardhdlc'})) {
- $dchan_type = 'hardhdlc';
- }
-
$timing = ($termtype eq 'NT') ? 0 : $bri_te_last_timing++;
printf "span=%d,%d,%d,%s,%s%s%s\n",
$num,
@@ -54,14 +49,42 @@ sub gen_digital($$) {
$span_crc4,
$span_yellow;
printf "# termtype: %s\n", lc($termtype);
- if ($gconfig->{'pri_connection_type'} eq 'PRI') {
+ my $dchan_type;
+ if ($span->is_bri()) {
+ my $use_bristuff = 0;
+ my $cfg_hardhdlc = $gconfig->{'bri_hardhdlc'};
+ my $xpd = $span->xpd();
+ if(!defined($cfg_hardhdlc) || $cfg_hardhdlc =~ /AUTO/i) {
+ # Autodetect
+ if(defined($xpd)) {
+ # Bristuff?
+ if(defined($xpd->dchan_hardhdlc) && !is_true($xpd->dchan_hardhdlc)) {
+ $use_bristuff = 1;
+ }
+ }
+ } elsif(!is_true($cfg_hardhdlc)) {
+ $use_bristuff = 1;
+ }
+ if($use_bristuff) {
+ $dchan_type = 'dchan';
+ } else {
+ $dchan_type = 'hardhdlc';
+ }
printf "bchan=%s\n", Zaptel::Config::Gen::bchan_range($span);
my $dchan = $span->dchan();
printf "$dchan_type=%d\n", $dchan->num();
- } elsif ($gconfig->{'pri_connection_type'} eq 'R2' ) {
- my $idle_bits = $gconfig->{'r2_idle_bits'};
- printf "cas=%s:$idle_bits\n", Zaptel::Config::Gen::bchan_range($span);
- printf "dchan=%d\n", $span->dchan()->num();
+ } elsif($span->is_pri()) {
+ if ($gconfig->{'pri_connection_type'} eq 'PRI') {
+ printf "bchan=%s\n", Zaptel::Config::Gen::bchan_range($span);
+ my $dchan = $span->dchan();
+ printf "dchan=%d\n", $dchan->num();
+ } elsif ($gconfig->{'pri_connection_type'} eq 'R2' ) {
+ my $idle_bits = $gconfig->{'r2_idle_bits'};
+ printf "cas=%s:$idle_bits\n", Zaptel::Config::Gen::bchan_range($span);
+ printf "dchan=%d\n", $span->dchan()->num();
+ }
+ } else {
+ die "Digital span $num is not BRI, nor PRI?";
}
}
@@ -100,7 +123,9 @@ sub generate($$$) {
print "Generating $file\n" if $genopts->{verbose};
open(F, ">$file") || die "$0: Failed to open $file: $!\n";
my $old = select F;
- printf "# Autogenerated by %s on %s -- do not hand edit\n", $0, scalar(localtime);
+ printf "# Autogenerated by $0 on %s\n", scalar(localtime);
+ print "# If you edit this file and execute $0 again,\n";
+ print "# your manual changes will be LOST.\n";
print <<"HEAD";
# Zaptel Configuration File
#