summaryrefslogtreecommitdiff
path: root/xpp/twinstar_setup
diff options
context:
space:
mode:
Diffstat (limited to 'xpp/twinstar_setup')
-rwxr-xr-xxpp/twinstar_setup144
1 files changed, 144 insertions, 0 deletions
diff --git a/xpp/twinstar_setup b/xpp/twinstar_setup
new file mode 100755
index 0000000..da76dca
--- /dev/null
+++ b/xpp/twinstar_setup
@@ -0,0 +1,144 @@
+#! /usr/bin/perl -w
+#
+# Written by Oron Peled <oron@actcom.co.il>
+# Copyright (C) 2009, Xorcom
+# This program is free software; you can redistribute and/or
+# modify it under the same terms as Perl itself.
+#
+# $Id$
+#
+use strict;
+use File::Basename;
+BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }
+
+use Dahdi::Config::Gen qw(is_true);
+use Dahdi::Hardware;
+use Dahdi::Xpp::Mpp;
+use Dahdi::Xpp::Xbus;
+
+my $tws_file = $ENV{DAHDI_TWINSTAR_SETUP} || "/etc/dahdi/twinstar_setup.conf";
+my $xpporder_file = $ENV{XPPORDER_CONF} || "/etc/dahdi/xpp_order";
+
+my @xbuses = Dahdi::Xpp::xbuses;
+
+my $format = "%-20s %-10s # %s\n";
+
+sub prep_lines() {
+ my @twinstar_out;
+ my $first_port;
+ if(! -d "/sys/bus/astribanks") {
+ die "CANNOT generate TwinStar setup -- xpp drivers are not loaded\n";
+ }
+ foreach my $xbus (@xbuses) {
+ my $dev = $xbus->transport;
+ my $connector = $xbus->connector;
+ my $label = $xbus->label;
+ my $xbusstr = sprintf "%s (%s) [%s]", $xbus->name, $connector, $label;
+ Dahdi::Xpp::Mpp->mpp_addinfo($dev);
+ my $mppinfo = $dev->mppinfo;
+ if(! defined $mppinfo) {
+ warn "SKIP $xbusstr -- is not Twinstar capable\n";
+ next;
+ }
+ if(! defined $mppinfo->{MPP_TALK}) {
+ warn "SKIP $xbusstr -- USB firmware is not loaded\n";
+ next;
+ }
+ my $port = $mppinfo->{TWINSTAR_PORT};
+ if(! defined $port) {
+ warn "SKIP $xbusstr -- Cannot read USB port info\n";
+ next;
+ }
+ my $power = $mppinfo->{TWINSTAR_POWER};
+ if(! defined $power) {
+ warn "SKIP $xbusstr -- Cannot read USB power info\n";
+ next;
+ }
+ if(!$power->[0] || !$power->[1]) {
+ warn "Only one cable: $xbusstr\n";
+ }
+ $first_port = $port unless defined $first_port;
+ my $line = sprintf $format,
+ $label, $port, $connector;
+ push(@twinstar_out, $line);
+ if($first_port != $port) {
+ die
+ "$0: ",
+ "XBUS($connector, $label) ",
+ "connected to PORT $port ",
+ "(others to $first_port)\n";
+ }
+ }
+ return @twinstar_out;
+}
+
+sub gen_twinstar_setup($) {
+ my $file = shift || die;
+ my @twinstar_out = prep_lines;
+ if(!@twinstar_out) {
+ print STDERR "No Twinstar capable Astribanks found\n";
+ return;
+ }
+ rename "$file", "$file.bak"
+ or $! == 2 # ENOENT (No dependency on Errno.pm)
+ or die "Failed to backup old config: $!\n";
+ print "Generating $file\n";
+ open(F, ">$file") || die "$0: Failed to open $file: $!\n";
+ my $old = select F;
+ printf "# Autogenerated by %s on %s -- Next run will overwrite contents.\n",
+ $0, scalar(localtime);
+ print <<"HEAD";
+#
+# This file is parsed by twinstar_hook
+#
+HEAD
+ printf $format, "# LABEL", "PORT", "CONNECTOR";
+ foreach (@twinstar_out) {
+ print;
+ }
+ close F;
+ select $old;
+}
+
+sub gen_xpporder($) {
+ my $file = shift || die;
+
+ rename "$file", "$file.bak"
+ or $! == 2 # ENOENT (No dependency on Errno.pm)
+ or die "Failed to backup old config: $!\n";
+ print "Generating $file\n";
+ open(F, ">$file") || die "$0: Failed to open $file: $!\n";
+ my $old = select F;
+ printf "# Autogenerated by %s on %s -- Next run will overwrite contents.\n",
+ $0, scalar(localtime);
+ print <<"HEAD";
+#
+# This file is parsed by Dahdi::Xpp
+#
+HEAD
+ foreach my $xbus (@xbuses) {
+ my $label = $xbus->label;
+ printf "%s\t# @%s (%s)\n",
+ $label, $xbus->connector, $xbus->name;
+ }
+ close F;
+ select $old;
+}
+
+gen_twinstar_setup($tws_file);
+gen_xpporder($xpporder_file);
+
+1;
+
+__END__
+
+=head1 NAME
+
+twinstar - Generate configuration for dahdi drivers.
+
+=head1 DESCRIPTION
+
+Generate the F</etc/dahdi/twinstar_setup.conf>.
+This is the configuration for twinstar_hook(8).
+
+Its location may be overriden via the environment variable F<DAHDI_TWINSTAR_SETUP>.