Debian Codegraph @

xpp/twinstar_setup

raw
1 #! /usr/bin/perl -w
2 #
3 # Written by Oron Peled <[email protected]>
4 # Copyright (C) 2009, Xorcom
5 # This program is free software; you can redistribute and/or
6 # modify it under the same terms as Perl itself.
7 #
8 # $Id$
9 #
10 use strict;
11 use File::Basename;
12 BEGIN {
13 my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules");
14 $ENV{PATH} = "$dir:$ENV{PATH}";
15 }
16
17 use Dahdi::Config::Gen qw(is_true);
18 use Dahdi::Hardware;
19 use Dahdi::Xpp::Mpp;
20 use Dahdi::Xpp::Xbus;
21
22 my $xpporder_file = $ENV{XPPORDER_CONF} || "/etc/dahdi/xpp_order";
23
24 my @devices = Dahdi::Hardware->device_list;
25 my @xbuses = Dahdi::Xpp::xbuses;
26
27 my $format = "%-20s %-10s # %s\n";
28
29 sub bad_xpds($) {
30 my $xbus = shift || die;
31 my $bad_xpds = 0;
32
33 foreach my $xpd ($xbus->xpds) {
34 if(! $xpd->spanno) {
35 my $fqn = $xpd->fqn;
36 warn "\t$fqn -- Not registered with DAHDI\n";
37 $bad_xpds++;
38 }
39 }
40 return $bad_xpds;
41 }
42
43 sub twinstar_checks() {
44 my @twinstar_good;
45 my $first_port;
46 if(! -d "/sys/bus/astribanks") {
47 die "CANNOT generate TwinStar setup -- xpp drivers are not loaded\n";
48 }
49 foreach my $dev (@devices) {
50 my $hwname = $dev->hardware_name;
51 my $xbus;
52 my $loaded;
53 my $tws_port;
54 my $tws_power;
55 my $tws_watchdog;
56 my $mppinfo;
57 if(! $dev->is_astribank) {
58 warn "SKIP $hwname -- Only Astribanks can be used for TwinStar\n";
59 next;
60 }
61 Dahdi::Xpp::Mpp->mpp_addinfo($dev);
62 $mppinfo = $dev->mppinfo;
63 if(! defined $mppinfo) {
64 warn "SKIP $hwname -- is not TwinStar ready\n";
65 next;
66 }
67 if(! defined $mppinfo->{MPP_TALK}) {
68 warn "SKIP $hwname -- USB firmware is not loaded\n";
69 next;
70 }
71 if(! $mppinfo->{TWINSTAR_CAPABLE}) {
72 warn "SKIP $hwname -- is not TwinStar capable\n";
73 next;
74 }
75 $xbus = $dev->xbus;
76 if(! defined $xbus) {
77 warn "SKIP $hwname -- No XBUS for this device (FPGA firmware? Initialization?)\n";
78 next;
79 }
80 my $dev = $xbus->transport;
81 my $connector = $xbus->connector;
82 my $label = $xbus->label;
83 my $xbusstr = sprintf "%s (%s) [%s]", $xbus->name, $connector, $label;
84 if(bad_xpds($xbus)) {
85 warn "SKIP $xbusstr -- Not registered with DAHDI\n";
86 next;
87 }
88 my $port = $mppinfo->{TWINSTAR_PORT};
89 if(! defined $port) {
90 warn "SKIP $xbusstr -- Cannot read USB port info\n";
91 next;
92 }
93 my $power = $mppinfo->{TWINSTAR_POWER};
94 if(! defined $power) {
95 warn "SKIP $xbusstr -- Cannot read USB power info\n";
96 next;
97 }
98 if(!$power->[0] || !$power->[1]) {
99 warn "WARNING: Only one cable: $xbusstr\n";
100 }
101 $first_port = $port unless defined $first_port;
102 printf "GOOD: %-15s port=%d %s\n", $label, $port, $connector;
103 push(@twinstar_good, $xbus);
104 if($first_port != $port) {
105 die
106 "$0: ",
107 "XBUS($connector, $label) ",
108 "connected to PORT $port ",
109 "(others to $first_port)\n";
110 }
111 }
112 return @twinstar_good;
113 }
114
115 my @twinstar_good = twinstar_checks;
116 if(!@twinstar_good) {
117 print STDERR "Abort. No Twinstar capable Astribanks found\n";
118 exit 1;
119 }
120 print "Generating Configuration\n";
121 system("dahdi_genconf -v xpporder");
122 die "Failed: $?\n" if $?;
123
124 1;
125
126 __END__
127
128 =head1 NAME
129
130 twinstar_setup - Prepares a server for Astribank TwinStar operation.
131
132 =head1 DESCRIPTION
133
134 This script prepares a server for Astribank TwinStar operation.
135 The stages are:
136
137 =over
138
139 =item Preliminary checks
140
141 Check that we have only TwinStar capable Astribanks, that the drivers are already loaded.
142
143 =item Configuration Generation
144
145 Indirectly generate the F</etc/dahdi/xpp_order> file that describes the current configuration.
146 This is done by running C<dahdi_genconf xpporder>
147
148 This configuration file is used by twinstar_hook(8) to know when all Astribanks has reconnected
149 to the backup server.
150
151 =item Deployment to Backup Server
152
153 Not implemented yet. Should be done manualy.
154
155 =back