From da10e87bd6c69c4374de470b7b286c36c823fdc2 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Thu, 19 Jun 2008 17:34:36 +0000 Subject: XPP tools rename: part 2. Removed obsolete astribank_hook (not needed) and print_modes (moved to kernel). git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@4416 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- xpp/Makefile | 47 ++--- xpp/astribank_hook | 57 ------ xpp/dahdi_drivers | 6 +- xpp/dahdi_genconf | 124 ++++++------ xpp/dahdi_hardware | 32 +-- xpp/dahdi_registration | 24 +-- xpp/genzaptelconf | 108 +++++------ xpp/genzaptelconf.8 | 40 ++-- xpp/lsdahdi | 22 +-- xpp/perl_modules/Dahdi.pm | 68 +++++++ xpp/perl_modules/Dahdi/Chans.pm | 202 +++++++++++++++++++ xpp/perl_modules/Dahdi/Config/Defaults.pm | 57 ++++++ xpp/perl_modules/Dahdi/Hardware.pm | 168 ++++++++++++++++ xpp/perl_modules/Dahdi/Hardware/PCI.pm | 208 ++++++++++++++++++++ xpp/perl_modules/Dahdi/Hardware/USB.pm | 116 +++++++++++ xpp/perl_modules/Dahdi/Span.pm | 300 +++++++++++++++++++++++++++++ xpp/perl_modules/Dahdi/Utils.pm | 52 +++++ xpp/perl_modules/Dahdi/Xpp.pm | 199 +++++++++++++++++++ xpp/perl_modules/Dahdi/Xpp/Line.pm | 95 +++++++++ xpp/perl_modules/Dahdi/Xpp/Xbus.pm | 118 ++++++++++++ xpp/perl_modules/Dahdi/Xpp/Xpd.pm | 123 ++++++++++++ xpp/perl_modules/Zaptel.pm | 68 ------- xpp/perl_modules/Zaptel/Chans.pm | 202 ------------------- xpp/perl_modules/Zaptel/Config/Defaults.pm | 56 ------ xpp/perl_modules/Zaptel/Hardware.pm | 168 ---------------- xpp/perl_modules/Zaptel/Hardware/PCI.pm | 208 -------------------- xpp/perl_modules/Zaptel/Hardware/USB.pm | 116 ----------- xpp/perl_modules/Zaptel/Span.pm | 300 ----------------------------- xpp/perl_modules/Zaptel/Utils.pm | 52 ----- xpp/perl_modules/Zaptel/Xpp.pm | 199 ------------------- xpp/perl_modules/Zaptel/Xpp/Line.pm | 95 --------- xpp/perl_modules/Zaptel/Xpp/Xbus.pm | 118 ------------ xpp/perl_modules/Zaptel/Xpp/Xpd.pm | 123 ------------ xpp/print_modes.c | 33 ---- xpp/xpp.rules | 4 +- xpp/xpp_blink | 26 +-- xpp/xpp_fxloader | 4 +- xpp/xpp_modprobe | 2 +- xpp/xpp_sync | 36 ++-- 39 files changed, 1935 insertions(+), 2041 deletions(-) delete mode 100755 xpp/astribank_hook create mode 100644 xpp/perl_modules/Dahdi.pm create mode 100644 xpp/perl_modules/Dahdi/Chans.pm create mode 100644 xpp/perl_modules/Dahdi/Config/Defaults.pm create mode 100644 xpp/perl_modules/Dahdi/Hardware.pm create mode 100644 xpp/perl_modules/Dahdi/Hardware/PCI.pm create mode 100644 xpp/perl_modules/Dahdi/Hardware/USB.pm create mode 100644 xpp/perl_modules/Dahdi/Span.pm create mode 100644 xpp/perl_modules/Dahdi/Utils.pm create mode 100644 xpp/perl_modules/Dahdi/Xpp.pm create mode 100644 xpp/perl_modules/Dahdi/Xpp/Line.pm create mode 100644 xpp/perl_modules/Dahdi/Xpp/Xbus.pm create mode 100644 xpp/perl_modules/Dahdi/Xpp/Xpd.pm delete mode 100644 xpp/perl_modules/Zaptel.pm delete mode 100644 xpp/perl_modules/Zaptel/Chans.pm delete mode 100644 xpp/perl_modules/Zaptel/Config/Defaults.pm delete mode 100644 xpp/perl_modules/Zaptel/Hardware.pm delete mode 100644 xpp/perl_modules/Zaptel/Hardware/PCI.pm delete mode 100644 xpp/perl_modules/Zaptel/Hardware/USB.pm delete mode 100644 xpp/perl_modules/Zaptel/Span.pm delete mode 100644 xpp/perl_modules/Zaptel/Utils.pm delete mode 100644 xpp/perl_modules/Zaptel/Xpp.pm delete mode 100644 xpp/perl_modules/Zaptel/Xpp/Line.pm delete mode 100644 xpp/perl_modules/Zaptel/Xpp/Xbus.pm delete mode 100644 xpp/perl_modules/Zaptel/Xpp/Xpd.pm delete mode 100644 xpp/print_modes.c diff --git a/xpp/Makefile b/xpp/Makefile index 2e3624c..81a14c0 100644 --- a/xpp/Makefile +++ b/xpp/Makefile @@ -10,10 +10,10 @@ INSTALL_DATA = install -m 644 # # These variables should be passed to us. But until then... # -ZAPTEL_DIR ?= $(shell if [ -f "../../zaptel.h" ]; then echo "../.."; else echo "../../.."; fi) -ZAP_KERNEL ?= $(shell if [ -d "$(ZAPTEL_DIR)/kernel" ]; then echo "$(ZAPTEL_DIR)/kernel"; else echo "$(ZAPTEL_DIR)"; fi) +DAHDI_TOOLSDIR ?= .. +DAHDI_KERNELDIR = --include $(ZAPTEL_DIR)/makeopts +include $(DAHDI_TOOLSDIR)/makeopts INSTALL_DATA = $(INSTALL) -m 644 @@ -26,50 +26,43 @@ INSTALL ?= install INSTALL_DATA = $(INSTALL) -m 644 SBINDIR = $(prefix)/sbin -DATADIR = $(datadir)/zaptel +DATADIR = $(datadir)/dahdi MANDIR = $(mandir)/man8 HOTPLUG_USB_DIR = /etc/hotplug/usb UDEV_RULES_DIR = /etc/udev/rules.d PERLLIBDIR := $(shell eval `perl -V:sitelib`; echo "$$sitelib") -PERL_DIRS := $(shell cd zconf; find * -name '[A-Z]*' -type d| xargs) +PERL_DIRS := $(shell cd perl_modules; find * -name '[A-Z]*' -type d| xargs) PERL_MODS_PAT := *.pm $(PERL_DIRS:%=%/*.pm) -PERL_MODS := $(shell cd zconf; echo $(PERL_MODS_PAT)) +PERL_MODS := $(shell cd perl_modules; echo $(PERL_MODS_PAT)) XPD_FIRMWARE = $(wildcard ../firmwares/*.hex) -XPD_INIT_DATA = $(XPD_FIRMWARE) init_fxo_modes +XPD_INIT_DATA = $(XPD_FIRMWARE) XPD_INIT = $(wildcard ../init_card_?_*) xpp_fxloader # Variables that should be defined above, but need sane defaults: # FIXME: Are those values really sane? HOSTCC ?= $(CC) -ifeq (,$(PBX_LIBUSB)) -# No PBX_LIBUSB? Maybe we compile against zaptel-1.2 -# Let's make a poor man detection of libusb -PBX_LIBUSB = $(shell if [ -r /usr/include/usb.h ]; then echo 1; else echo 0; fi) -endif - -WCTDM=$(shell for i in $(ZAP_KERNEL)/wctdm.c $(ZAP_KERNEL)/fxo_modes.h; do [ -f "$$i" ] && echo "$$i"; done) CFLAGS = -g -Wall $(EXTRA_CFLAGS) %.8: % pod2man --section 8 $^ > $@ || $(RM) $@ PERL_SCRIPTS = \ - zt_registration \ + dahdi_registration \ xpp_sync \ - lszaptel \ + lsdahdi \ xpp_blink \ - zapconf \ - zaptel_hardware \ + dahdi_genconf \ + dahdi_hardware \ # PERL_MANS = $(PERL_SCRIPTS:%=%.8) -TARGETS = init_fxo_modes print_modes perlcheck +TARGETS = perlcheck PROG_INSTALL = genzaptelconf MAN_INSTALL = $(PROG_INSTALL:%=%.8) -ifeq (1,$(PBX_LIBUSB)) +ifeq (1,$(PBX_USB)) TARGETS += libhexfile.a fpga_load test_parse PROG_INSTALL += fpga_load endif @@ -104,7 +97,7 @@ ifneq (,$(PERLLIBDIR)) done for i in $(PERL_MODS); \ do \ - $(INSTALL_DATA) "zconf/$$i" "$(DESTDIR)$(PERLLIBDIR)/$$i"; \ + $(INSTALL_DATA) "perl_modules/$$i" "$(DESTDIR)$(PERLLIBDIR)/$$i"; \ done endif @@ -126,18 +119,8 @@ test_parse.o: test_parse.c hexfile.h test_parse: test_parse.o libhexfile.a $(CC) -L. -o $@ $@.o $(EXTRA_LIBS) -lhexfile -lusb -print_modes: print_modes.c wctdm_fxomodes.h - $(HOSTCC) -o $@ $(CFLAGS) $< - -wctdm_fxomodes.h: $(WCTDM) - @echo Building FXO modes from: $(WCTDM) - perl -n -e 'print if (/^static struct fxo_mode {$$/ .. /};$$/)' $(WCTDM) >$@ || rm -f $@ - -init_fxo_modes: print_modes - ./$< >$@ - perlcheck: $(PERL_SCRIPTS) - for i in $^; do perl -I./zconf -c $$i || exit 1; done + for i in $^; do perl -I./perl_modules -c $$i || exit 1; done touch $@ clean: diff --git a/xpp/astribank_hook b/xpp/astribank_hook deleted file mode 100755 index 8dd13c9..0000000 --- a/xpp/astribank_hook +++ /dev/null @@ -1,57 +0,0 @@ -#! /bin/sh - -# This is an example of an Astribank device hook. The xpp.rules file -# calls /usr/share/zaptel/astribank_hook after a new Astribank is ready -# and after and old Astribank device has been destroyed. -# - -set -e - -me=`basename $0` -INIT_DIR=`dirname $0` -XPP_BASE=/proc/xpp -export XPP_BASE -LOGGER="logger -s -t $me" - -ZAPTEL_BOOT_DEBIAN=${ZAPTEL_BOOT_DEBIAN:-/etc/default/zaptel} -ZAPTEL_BOOT_FEDORA=${ZAPTEL_BOOT_FEDORA:-/etc/sysconfig/zaptel} - -# read default configuration from /etc/default/zaptel -if [ -r $ZAPTEL_BOOT_DEBIAN ]; then . $ZAPTEL_BOOT_DEBIAN; fi -if [ -r $ZAPTEL_BOOT_FEDORA ]; then . $ZAPTEL_BOOT_FEDORA; fi - -if [ "$ASTRIBANK_HOOK_DISABLED" != '' ]; then - $LOGGER -p kern.info "Exiting... ASTRIBANK_HOOK_DISABLED" - exit 0 -fi - -# Always redirect stderr somewhere, otherwise the shell script will die -# when it tries to do I/O related stuff on closed file descriptor. -# Our default is to throw it down the bit-bucket. -#exec 2> /dev/console -## If you wish to trace this script: -#exec 2> "/tmp/astribank_hook_$XBUS_NAME" - -# Maybe add some logging -#$LOGGER -p kern.info "$0: $ACTION: $*." - -case "$ACTION" in -add) - # An Astribank was added and is initialized and ready. - # Put your shell commands bellow - : - ;; -remove) - # An Astribank was Removed. - # Put your shell commands bellow - # You should not access /proc/xpp/... or run related utilities - # like xpp_sync, since this is likely to cause very bad race - # conditions during driver removal. - : - ;; -*) - ;; -esac - -# Maybe add some logging -#$LOGGER -p kern.info "$0: Done: $ACTION: $*." diff --git a/xpp/dahdi_drivers b/xpp/dahdi_drivers index d7904c0..add8374 100755 --- a/xpp/dahdi_drivers +++ b/xpp/dahdi_drivers @@ -1,9 +1,9 @@ #! /usr/bin/perl -w use strict; use File::Basename; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); } +BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } -use Zaptel::Hardware; +use Dahdi::Hardware; -my $hardware = Zaptel::Hardware->scan; +my $hardware = Dahdi::Hardware->scan; print join("\n", $hardware->drivers),"\n"; diff --git a/xpp/dahdi_genconf b/xpp/dahdi_genconf index 7f94f6b..83fd0d4 100755 --- a/xpp/dahdi_genconf +++ b/xpp/dahdi_genconf @@ -9,11 +9,11 @@ # use strict; use File::Basename; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); } +BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } -use Zaptel; -use Zaptel::Xpp; -use Zaptel::Config::Defaults; +use Dahdi; +use Dahdi::Xpp; +use Dahdi::Config::Defaults; my %default_context = ( FXO => 'from-pstn', @@ -47,14 +47,14 @@ my %default_group = ( my $fxs_default_start = 'ls'; -my %default_zaptel_signalling = ( +my %default_dahdi_signalling = ( FXO => 'fxsks', FXS => "fxo{fxs_default_start}", IN => "fxo{fxs_default_start}", OUT => "fxo{fxs_default_start}", ); -my %default_zapata_signalling = ( +my %default_chan_dahdi_signalling = ( FXO => 'fxs_ks', FXS => "fxo_{fxs_default_start}", IN => "fxo_{fxs_default_start}", @@ -69,7 +69,7 @@ my $defaultzone = $lc_country; my $bri_sig_style = 'bri_ptmp'; my $brint_overlap = 'no'; -my %zaptel_default_vars = ( +my %dahdi_default_vars = ( base_exten => \$base_exten, fxs_immediate => \$fxs_immediate, fxs_default_start => \$fxs_default_start, @@ -87,15 +87,15 @@ my %zaptel_default_vars = ( \$default_group{OUT}, ], group_lines => \$default_group{FXO}, - ZAPBRI_SIGNALLING => \$bri_sig_style, + DAHDI_BRI_SIGNALLING => \$bri_sig_style, brint_overlap => \$brint_overlap, ); -sub map_zaptel_defaults { +sub map_dahdi_defaults { my %defaults = @_; foreach my $name (keys %defaults) { my $val = $defaults{$name}; - my $ref = $zaptel_default_vars{$name}; + my $ref = $dahdi_default_vars{$name}; my $type = ref $ref; my @vars = (); # Some broken shells (msh) export even variables @@ -115,21 +115,21 @@ sub map_zaptel_defaults { } -my $zapconf_file; -my $zapatachannels_file; +my $dahdiconf_file; +my $chan_dahdi_channels_file; my $users_file; -my $zapataconf_file; +my $chan_dahdi_conf_file; my %files = ( - zaptel => { file => \$zapconf_file, func => \&gen_zaptelconf }, - zapata => { file => \$zapatachannels_file, func => \&gen_zapatachannelsconf }, + dahdi => { file => \$dahdiconf_file, func => \&gen_dahdiconf }, + chan_dahdi => { file => \$chan_dahdi_channels_file, func => \&gen_chan_dahdi_channelsconf }, users => { file => \$users_file, func => \&gen_usersconf }, - zapataconf => { file => \$zapataconf_file, func => \&gen_zapataconf }, + chan_dahdi_full => { file => \$chan_dahdi_conf_file, func => \&gen_chan_dahdi_conf }, ); -my @default_files = ("zaptel", "zapata"); +my @default_files = ("dahdi", "chan_dahdi"); -my @spans = Zaptel::spans(); +my @spans = Dahdi::spans(); sub bchan_range($) { my $span = shift || die; @@ -156,7 +156,7 @@ sub bchan_range($) { return join(',', @range); } -sub gen_zaptel_signalling($) { +sub gen_dahdi_signalling($) { my $chan = shift || die; my $type = $chan->type; my $num = $chan->num; @@ -166,7 +166,7 @@ sub gen_zaptel_signalling($) { printf "# channel %d, %s, no module.\n", $num, $chan->fqn; return; } - my $sig = $default_zaptel_signalling{$type} || die "unknown default zaptel signalling for chan $chan type $type"; + my $sig = $default_dahdi_signalling{$type} || die "unknown default dahdi signalling for chan $chan type $type"; if ($type eq 'IN') { printf "# astbanktype: input\n"; } elsif ($type eq 'OUT') { @@ -177,7 +177,7 @@ sub gen_zaptel_signalling($) { my $bri_te_last_timing = 1; -sub gen_zaptel_digital($) { +sub gen_dahdi_digital($) { my $span = shift || die; my $num = $span->num() || die; die "Span #$num is analog" unless $span->is_digital(); @@ -206,7 +206,7 @@ sub gen_zaptel_digital($) { printf "dchan=%d\n", $dchan->num(); } -sub gen_zaptelconf($) { +sub gen_dahdiconf($) { my $file = shift || die; rename "$file", "$file.bak" or $! == 2 # ENOENT (No dependency on Errno.pm) @@ -215,15 +215,15 @@ sub gen_zaptelconf($) { my $old = select F; printf "# Autogenerated by %s on %s -- do not hand edit\n", $0, scalar(localtime); print <<"HEAD"; -# Zaptel Configuration File +# Dahdi Configuration File # -# This file is parsed by the Zaptel Configurator, ztcfg +# This file is parsed by the Dahdi Configurator, ztcfg # HEAD foreach my $span (@spans) { printf "# Span %d: %s %s\n", $span->num, $span->name, $span->description; if($span->is_digital()) { - gen_zaptel_digital($span); + gen_dahdi_digital($span); } else { foreach my $chan ($span->chans()) { if(1 || !defined $chan->type) { @@ -233,7 +233,7 @@ HEAD unless defined $type; $chan->type($type); } - gen_zaptel_signalling($chan); + gen_dahdi_signalling($chan); } } print "\n"; @@ -257,7 +257,7 @@ my %DefaultConfigs = ( txgain => 0, ); -sub reset_zapata_values { +sub reset_chan_dahdi_values { foreach my $arg (@_) { if (exists $DefaultConfigs{$arg}) { print "$arg = $DefaultConfigs{$arg}\n"; @@ -267,7 +267,7 @@ sub reset_zapata_values { } } -sub gen_zapata_digital($) { +sub gen_chan_dahdi_digital($) { my $span = shift || die; my $num = $span->num() || die; die "Span #$num is analog" unless $span->is_digital(); @@ -296,23 +296,23 @@ sub gen_zapata_digital($) { printf "switchtype = %s\n", $span->switchtype; printf "signalling = %s\n", $sig; printf "channel => %s\n", bchan_range($span); - reset_zapata_values(@to_reset); + reset_chan_dahdi_values(@to_reset); } -sub gen_zapata_channel($) { +sub gen_chan_dahdi_channel($) { my $chan = shift || die; my $type = $chan->type; my $num = $chan->num; die "channel $num type $type is not an analog channel\n" if $chan->span->is_digital(); my $exten = $base_exten + $num; - my $sig = $default_zapata_signalling{$type}; + my $sig = $default_chan_dahdi_signalling{$type}; my $context = $default_context{$type}; my $group = $default_group{$type}; my $callerid; my $immediate; return if $type eq 'EMPTY'; - die "missing default_zapata_signalling for chan #$num type $type" unless $sig; + die "missing default_chan_dahdi_signalling for chan #$num type $type" unless $sig; $callerid = ($type eq 'FXO') ? 'asreceived' : sprintf "\"Channel %d\" <%04d>", $num, $exten; @@ -347,7 +347,7 @@ sub gen_zapata_channel($) { print "\n"; } -sub gen_zapatachannelsconf($) { +sub gen_chan_dahdi_channelsconf($) { my $file = shift || die; rename "$file", "$file.bak" or $! == 2 # ENOENT (No dependency on Errno.pm) @@ -356,20 +356,20 @@ sub gen_zapatachannelsconf($) { my $old = select F; printf "; Autogenerated by %s on %s -- do not hand edit\n", $0, scalar(localtime); print <<"HEAD"; -; Zaptel Channels Configurations (zapata.conf) +; Dahdi Channels Configurations (chan_dahdi.conf) ; -; This is not intended to be a complete zapata.conf. Rather, it is intended -; to be #include-d by /etc/zapata.conf that will include the global settings +; This is not intended to be a complete chan_dahdi.conf. Rather, it is intended +; to be #include-d by /etc/asterisk/chan_dahdi.conf that will include the global settings ; HEAD foreach my $span (@spans) { printf "; Span %d: %s %s\n", $span->num, $span->name, $span->description; if($span->is_digital()) { - gen_zapata_digital($span); + gen_chan_dahdi_digital($span); } else { foreach my $chan ($span->chans()) { - gen_zapata_channel($chan); + gen_chan_dahdi_channel($chan); } } print "\n"; @@ -384,10 +384,10 @@ sub gen_users_channel($) { my $num = $chan->num; die "channel $num type $type is not an analog channel\n" if $chan->span->is_digital(); my $exten = $base_exten + $num; - my $sig = $default_zapata_signalling{$type}; + my $sig = $default_chan_dahdi_signalling{$type}; my $full_name = "$type $num"; - die "missing default_zapata_signalling for chan #$num type $type" unless $sig; + die "missing default_chan_dahdi_signalling for chan #$num type $type" unless $sig; print << "EOF"; [$exten] callwaiting = yes @@ -406,7 +406,7 @@ threewaycalling = yes vmsecret = 1234 secret = 1234 signalling = $sig -zapchan = $num +dahdichan = $num registeriax = no registersip = no canreinvite = no @@ -505,7 +505,7 @@ HEAD select $old; } -sub gen_zapataconf($) { +sub gen_chan_dahdi_conf($) { my $file = shift || die; open(F, ">>$file") || die "$0: Failed to open $file: $!\n"; my $old = select F; @@ -514,8 +514,8 @@ sub gen_zapataconf($) { my $current_sig = ""; for my $chan ($span->chans()) { my $chan_num = $chan->num; - if ($default_zapata_signalling{$chan->type} ne $current_sig) { - $current_sig = $default_zapata_signalling{$chan->type}; + if ($default_chan_dahdi_signalling{$chan->type} ne $current_sig) { + $current_sig = $default_chan_dahdi_signalling{$chan->type}; print "\nsignalling = $current_sig"; print "\nchannel => $chan_num"; } else { @@ -531,16 +531,16 @@ sub gen_zapataconf($) { sub set_defaults { # Source default files my ($default_file, %source_defaults) = - Zaptel::Config::Defaults::source_vars(keys(%zaptel_default_vars)); - map_zaptel_defaults(%source_defaults); + Dahdi::Config::Defaults::source_vars(keys(%dahdi_default_vars)); + map_dahdi_defaults(%source_defaults); # Fixups - foreach my $val (values %default_zaptel_signalling, values %default_zapata_signalling) { + foreach my $val (values %default_dahdi_signalling, values %default_chan_dahdi_signalling) { $val =~ s/{fxs_default_start}/$fxs_default_start/g; } - $zapconf_file = $ENV{ZAPCONF_FILE} || "/etc/zaptel.conf"; - $zapatachannels_file = $ENV{ZAPATA_FILE} || "/etc/asterisk/zapata-channels.conf"; + $dahdiconf_file = $ENV{DAHDI_CONF_FILE} || "/etc/dahdi.conf"; + $chan_dahdi_channels_file = $ENV{CHAN_DAHDI_CHANNELS_FILE} || "/etc/asterisk/dahdi-channels.conf"; $users_file = $ENV{USERS_FILE} || "/etc/asterisk/users.conf"; - $zapataconf_file = $ENV{ZAPATACONF_FILE} || "/etc/asterisk/zapata.conf"; + $chan_dahdi_conf_file = $ENV{CHAN_DAHDI_CONF_FILE} || "/etc/asterisk/chan_dahdi.conf"; } sub parse_args { @@ -565,39 +565,39 @@ __END__ =head1 NAME -zapconf - Generate configuration for zaptel channels. +dahdi_genconf - Generate configuration for dahdi channels. =head1 SYNOPSIS -zapconf [FILES...] +dahdi_genconf [FILES...] =head1 DESCRIPTION -This script generate configuration files for Zaptel hardware. -Currently it can generate three files: zaptel, zapata, users and zapataconf (see below). -Without arguments, it generates only zaptel and zapata. +This script generate configuration files for Dahdi hardware. +Currently it can generate three files: dahdi, chan_dahdi, users and chan_dahdi_full (see below). +Without arguments, it generates only dahdi and chan_dahdi. =over 4 -=item zaptel - /etc/zaptel.conf +=item dahdi - /etc/dahdi.conf Configuration for ztcfg(1). It's location may be overriden by the -environment variable ZAPCONF_FILE. +environment variable DAHDI_CONF_FILE. -=item zapata - /etc/asterisk/zapata-channels.conf +=item chan_dahdi - /etc/asterisk/dahdi-channels.conf -Configuration for asterisk(1). It should be included in the main /etc/asterisk/zapata.conf. -It's location may be overriden by the environment variable ZAPATA_FILE. +Configuration for asterisk(1). It should be included in the main /etc/asterisk/chan_dahdi.conf. +It's location may be overriden by the environment variable CHAN_DAHDI_CHANNELS_FILE. =item users - /etc/asterisk/users.conf Configuration for asterisk(1) and AsteriskGUI. It's location may be overriden by the environment variable USERS_FILE. -=item zapataconf - /etc/asterisk/zapata.conf +=item chan_dahdi_full - /etc/asterisk/chan_dahdi.conf Configuration for asterisk(1) and AsteriskGUI. -It's location may be overriden by the environment variable ZAPATACONF_FILE. +It's location may be overriden by the environment variable CHAN_DAHDI_CONF_FILE. =back diff --git a/xpp/dahdi_hardware b/xpp/dahdi_hardware index 004a44b..d869f32 100755 --- a/xpp/dahdi_hardware +++ b/xpp/dahdi_hardware @@ -10,13 +10,13 @@ use strict; use File::Basename; use Getopt::Std; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); } +BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } -use Zaptel; -use Zaptel::Span; -use Zaptel::Xpp; -use Zaptel::Xpp::Xbus; -use Zaptel::Hardware; +use Dahdi; +use Dahdi::Span; +use Dahdi::Xpp; +use Dahdi::Xpp::Xbus; +use Dahdi::Hardware; sub usage { die "Usage: $0 [-v][-x]\n"; @@ -26,8 +26,8 @@ our ($opt_v, $opt_x); getopts('vx') || usage; @ARGV == 0 or usage; -my $hardware = Zaptel::Hardware->scan; -my @spans = Zaptel::spans; +my $hardware = Dahdi::Hardware->scan; +my @spans = Dahdi::spans; sub show_xbus($) { my $xbus = shift or die; @@ -47,7 +47,7 @@ sub show_xbus($) { } my $master = ''; #$master = "XPP-SYNC" if $xpd->is_sync_master; - $master .= " ZAPTEL-SYNC" if defined($span) && $span->is_zaptel_sync_master; + $master .= " DAHDI-SYNC" if defined($span) && $span->is_dahdi_sync_master; printf "\t%-10s: %-8s %s %s\n", $xpd->fqn, $xpd->type, $spanstr, $master; } } @@ -59,7 +59,7 @@ sub show_disconnected(%) { my %seen = @_; my $notified_lost = 0; - foreach my $xbus (Zaptel::Xpp::xbuses('SORT_CONNECTOR')) { + foreach my $xbus (Dahdi::Xpp::xbuses('SORT_CONNECTOR')) { if(!$seen{$xbus->name}) { print "----------- XPP Spans with disconnected hardware -----------\n" unless $notified_lost++; @@ -95,11 +95,11 @@ __END__ =head1 NAME -zaptel_hardware - Shows Zaptel hardware devices. +dahdi_hardware - Shows Dahdi hardware devices. =head1 SYNOPSIS -zaptel_hardware [-v][-x] +dahdi_hardware [-v][-x] =head1 OPTIONS @@ -118,9 +118,9 @@ Show disconnected Astribank unit, if any. =head1 DESCRIPTION -Show all zaptel hardware devices. Devices are recognized according to -lists of PCI and USB IDs in Zaptel::Hardware::PCI.pm and -Zaptel::Hardware::USB.pm . For PCI it is possible to detect by +Show all dahdi hardware devices. Devices are recognized according to +lists of PCI and USB IDs in Dahdi::Hardware::PCI.pm and +Dahdi::Hardware::USB.pm . For PCI it is possible to detect by sub-vendor and sub-product ID as well. The first output column is the connector: a bus specific field that @@ -130,7 +130,7 @@ The second field shows which driver should handle the device. a "-" sign marks that the device is not yet handled by this driver. A "+" sign means that the device is handled by the driver. -For the Xorcom Astribank (and in the future: for other Zaptel devices) +For the Xorcom Astribank (and in the future: for other Dahdi devices) some further information is provided from the driver. Those extra lines always begin with spaces. diff --git a/xpp/dahdi_registration b/xpp/dahdi_registration index 831f048..44352ab 100755 --- a/xpp/dahdi_registration +++ b/xpp/dahdi_registration @@ -9,12 +9,12 @@ # use strict; use File::Basename; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); } +BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } -use Zaptel; -use Zaptel::Span; -use Zaptel::Xpp; -use Zaptel::Xpp::Xbus; +use Dahdi; +use Dahdi::Span; +use Dahdi::Xpp; +use Dahdi::Xpp::Xbus; sub usage { die "Usage: $0 [on|off|1|0]\n"; @@ -40,9 +40,9 @@ sub myprintf { printf @_ if $should_output; } -my @spans = Zaptel::spans; +my @spans = Dahdi::spans; -foreach my $xbus (Zaptel::Xpp::xbuses('SORT_CONNECTOR')) { +foreach my $xbus (Dahdi::Xpp::xbuses('SORT_CONNECTOR')) { myprintf "%-10s\t%s\t%s\n", $xbus->name, $xbus->label, $xbus->connector; next unless $xbus->status eq 'CONNECTED'; foreach my $xpd ($xbus->xpds()) { @@ -66,7 +66,7 @@ __END__ =head1 NAME -dahdi_registration - Handle registration of Xorcom XPD modules in zaptel. +dahdi_registration - Handle registration of Xorcom XPD modules in dahdi. =head1 SYNOPSIS @@ -75,20 +75,20 @@ dahdi_registration [on|off] =head1 DESCRIPTION Without parameters, show all connected XPDs sorted by physical connector order. -Each one is show to be unregistered (off), or registered to a specific zaptel +Each one is show to be unregistered (off), or registered to a specific dahdi span (the span number is shown). All registerations/deregisterations are sorted by physical connector string. Span registration should generally always succeed. Span unregistration may fail if channels from the span are in use by e.g. asterisk. In such a case -you'll also see those channels as '(In use)' in the output of lszaptel(8). +you'll also see those channels as '(In use)' in the output of lsdahdi(8). =head2 Parameters -off -- deregisters all XPD's from zaptel. +off -- deregisters all XPD's from dahdi. -on -- registers all XPD's to zaptel. +on -- registers all XPD's to dahdi. =head2 Sample Output diff --git a/xpp/genzaptelconf b/xpp/genzaptelconf index 163f595..023bd73 100755 --- a/xpp/genzaptelconf +++ b/xpp/genzaptelconf @@ -1,7 +1,7 @@ #! /bin/bash # genzaptelconf: generate as smartly as you can: -# /etc/zaptel.conf +# /etc/dahdi.conf # /etc/asterisk/zapata-channels.conf (to be #include-d into zapata.conf) # update: # With '-M' /etc/modules (list of modules to load) @@ -56,7 +56,7 @@ group_lines=0 # group for lines # Set fxs_immediate to 'yes' to make all FXS lines answer immediately. fxs_immediate=no -ZAPCONF_FILE=${ZAPCONF_FILE:-/etc/zaptel.conf} +ZAPCONF_FILE=${ZAPCONF_FILE:-/etc/dahdi.conf} ZAPCONF_FILE_SYSTEM=$ZAPCONF_FILE ZAPATA_FILE=${ZAPATA_FILE:-/etc/asterisk/zapata-channels.conf} ZAPSCAN_FILE=${ZAPSCAN_FILE:-/etc/asterisk/zapscan.conf} @@ -121,7 +121,7 @@ if [ ! -x "$ZTCFG" ]; then if [ -x /usr/sbin/ztcfg ]; then ZTCFG=/usr/sbin/ztcfg else - echo >&2 "ztcfg is not on found, do you have zaptel properly installed?" + echo >&2 "ztcfg is not on found, do you have dahdi properly installed?" exit_cleanup 1 fi fi @@ -178,9 +178,9 @@ exit_cleanup() { # Wait for udev to generate /dev/zap/ctl, if needed: wait_for_zapctl() { - # if device file already exists, or if zaptel has failed to load: + # if device file already exists, or if dahdi has failed to load: # no point waiting. - if [ -c /dev/zap/ctl ] || ! grep -q zaptel /proc/modules ; then + if [ -c /dev/zap/ctl ] || ! grep -q dahdi /proc/modules ; then return fi say "Waiting for /dev/zap/ctl to be generated" @@ -227,7 +227,7 @@ update_module_list_debian() { } update_module_list_fedora() { - say "Updating modules list in zaptel init config $MODLIST_FILE_FEDORA." + say "Updating modules list in dahdi init config $MODLIST_FILE_FEDORA." sed -i.bak -e "/^$modules_var=/d" "$MODLIST_FILE_FEDORA" echo "$modules_var=\"$*\"" >> "$MODLIST_FILE_FEDORA" } @@ -251,10 +251,10 @@ zap_reg_xpp() { # the USB connector. That order is rather arbitrary, but will not # change without changes to the cabling. xbusses=`sed -e '/STATUS=connected/!d' -e 's/ *STATUS=.*//' -e 's/ *CONNECTOR=//' /proc/xpp/xbuses | sort -t: -k 2 | cut -d: -f1` - say "Zaptel registration order:" + say "Dahdi registration order:" say "$xbusses" - # get a list of XPDs that were not yet registered as zaptel spans. + # get a list of XPDs that were not yet registered as dahdi spans. # this will be the case if you set the parameter zap_autoreg=0 to # the module xpp # Append /dev/null to provide a valid file name in case of an empty pattern. @@ -289,7 +289,7 @@ xpp_startup() { usage() { program=`basename $0` - echo >&2 "$program: generate zaptel.conf and zapata.conf" + echo >&2 "$program: generate dahdi.conf and zapata.conf" echo >&2 "(version $VERSION, $rcsid)" echo >&2 "usage:" echo >&2 " $program [-sRdv] [-m k|l|g] [-c ] [-e ] [-F]" @@ -301,9 +301,9 @@ usage() { echo >&2 " -c CODE: set the country code (default: $lc_country)" echo >&2 " -e NUM: set the base extension number (default: $base_exten)" echo >&2 " -F: Don't print FXSs in zapata.conf" - echo >&2 " -l: output a list of detected channels instead of zaptel.conf" + echo >&2 " -l: output a list of detected channels instead of dahdi.conf" echo >&2 " -d: Perform hardware detection" - echo >&2 " -u: Unload zaptel modules (will not restart Asterisk)." + echo >&2 " -u: Unload dahdi modules (will not restart Asterisk)." echo >&2 " -v: verbose" echo >&2 " -s: Stop Asterisk before running, and start it at the end." echo >&2 " -R: Don't restart asterisk in the end." @@ -371,10 +371,10 @@ print_pattern() { echo ";;; line=\"$line\"" >> $zapata_file if [ "$astbank_type" != '' ]; - then echo "# astbanktype: $astbank_type" >>$zaptel_file; + then echo "# astbanktype: $astbank_type" >>$dahdi_file; fi - echo "${sig}$method=$chan" >>$zaptel_file - # zap2amp will rewrite those from zaptel.conf and hints there + echo "${sig}$method=$chan" >>$dahdi_file + # zap2amp will rewrite those from dahdi.conf and hints there if [ "$fxsdisable" = 'yes' ] && [ "$sig" = 'fxo' ]; then return; fi echo "signalling=${sig}_$method" >>$zapata_file @@ -476,14 +476,14 @@ print_pattern() { } -# the number of channels from /proc/zaptel +# the number of channels from /proc/dahdi # must always print a number as its output. count_proc_zap_lines() { - # if zaptel is not loaded there are 0 channels: - if [ ! -d /proc/zaptel ]; then echo '0'; return; fi + # if dahdi is not loaded there are 0 channels: + if [ ! -d /proc/dahdi ]; then echo '0'; return; fi ( - for file in `echo /proc/zaptel/* |grep -v '\*'` + for file in `echo /proc/dahdi/* |grep -v '\*'` do sed -e 1,2d $file # remove the two header lines done ) | wc -l # the total number of lines @@ -498,7 +498,7 @@ load_modules() { eval "args=\$$args" # a module is worth listing if it: # a. loaded successfully, and - # b. added channels lines under /proc/zaptel/* + # b. added channels lines under /proc/dahdi/* if /sbin/modprobe $i $args 2> /dev/null then check=0 @@ -545,8 +545,8 @@ unload_module() { } unload_modules() { - say "Unloading zaptel modules:" - unload_module zaptel + say "Unloading dahdi modules:" + unload_module dahdi say '' } @@ -574,11 +574,11 @@ detect() { if echo $modlist | grep -q xpp_usb; then wait_for_xpp; fi } -# The module configuration generated by zaptel includes a totally useless +# The module configuration generated by dahdi includes a totally useless # automatic run of ztcfg after modules loading. As a workaround for that, -# we provide an empty zaptel.conf temporarily. +# we provide an empty dahdi.conf temporarily. # -# At hardware detection time we shouldn't really touch zaptel.conf . So we +# At hardware detection time we shouldn't really touch dahdi.conf . So we # must keep a copy of it somewhere. # # I use ZAPCONF_FILE_SYSTEM rather than ZAPCONF_FILE, as the bogus modprobe @@ -590,15 +590,15 @@ ZAPCONF_FILE_TMP= temporary_zapconf() { case "$1" in save) - say "Temporarily moving zaptel.conf aside to work around broken modprobe.conf" - ZAPCONF_FILE_TMP=`mktemp /tmp/genzaptelconf-zaptel.conf-XXXXXX` || die "Error creating temporary zaptel.conf" + say "Temporarily moving dahdi.conf aside to work around broken modprobe.conf" + ZAPCONF_FILE_TMP=`mktemp /tmp/genzaptelconf-dahdi.conf-XXXXXX` || die "Error creating temporary dahdi.conf" if [ -f $ZAPCONF_FILE_SYSTEM ]; then cp -a $ZAPCONF_FILE_SYSTEM $ZAPCONF_FILE_TMP fi echo -n >$ZAPCONF_FILE_SYSTEM ;; restore) - # restore original zaptel.conf: + # restore original dahdi.conf: if [ "$ZAPCONF_FILE_TMP" = '' ]; then return; fi mv $ZAPCONF_FILE_TMP $ZAPCONF_FILE_SYSTEM ZAPCONF_FILE_TMP='' @@ -652,7 +652,7 @@ gen_tmp_conf() { fi } -# Extract information from one digital channel (one line in a /proc/zaptel +# Extract information from one digital channel (one line in a /proc/dahdi # file). Information is saved to $tmp_dir/span_foo variables. # FIXME: detection should move to when we know the number of channels # and hence can tell between an E1 and a T1. @@ -786,15 +786,15 @@ write_digital_config() { esac case "$mode" in files) - echo span=$span_num,$span_timing,$span_lbo,$span_framing,$span_coding$span_yellow >> $zaptel_file - # leave a comment in zaptel.conf that allows to tell if + echo span=$span_num,$span_timing,$span_lbo,$span_framing,$span_coding$span_yellow >> $dahdi_file + # leave a comment in dahdi.conf that allows to tell if # this span is TE or NT: if [ "$span_termtype" != '' ] - then echo "# termtype: $span_termtype" >>$zaptel_file + then echo "# termtype: $span_termtype" >>$dahdi_file fi - echo bchan=$bchans >>$zaptel_file - echo dchan=$dchan >>$zaptel_file + echo bchan=$bchans >>$dahdi_file + echo dchan=$dchan >>$dahdi_file if [ "$fxsdisable" = 'yes' ] && [ "$span_termtype" = 'nt' ]; then return; fi # You should not send content to zapata.conf below this line @@ -857,13 +857,13 @@ genconf() { local mode=$1 local reset_values="" -# spanlist=`echo /proc/zaptel/* | grep -v '\*'` -# spanlist=$(for i in `for i in /proc/zaptel/*; do if [ -f $i ]; then echo $i | cut -f 4 -d / ; fi; done | sort -n`; do echo -n "/proc/zaptel/$i "; done) -# spanlist=(cd /proc/zaptel; ls | sort -n | sed 's|^|/proc/zaptel/|') - spanlist=`ls /proc/zaptel/ 2>/dev/null | sort -n | sed 's|^|/proc/zaptel/|'` +# spanlist=`echo /proc/dahdi/* | grep -v '\*'` +# spanlist=$(for i in `for i in /proc/dahdi/*; do if [ -f $i ]; then echo $i | cut -f 4 -d / ; fi; done | sort -n`; do echo -n "/proc/dahdi/$i "; done) +# spanlist=(cd /proc/dahdi; ls | sort -n | sed 's|^|/proc/dahdi/|') + spanlist=`ls /proc/dahdi/ 2>/dev/null | sort -n | sed 's|^|/proc/dahdi/|'` #if [ "$spanlist" == "" ]; then - # die "No zapata interfaces in /proc/zaptel" + # die "No zapata interfaces in /proc/dahdi" #fi @@ -872,20 +872,20 @@ genconf() { if [ "$do_gen_zapscan" = 'yes' ]; then gen_tmp_conf "$ZAPSCAN_FILE" zapscan_file cat <$zapscan_file -; zapscan.conf: information about detected zaptel channels +; zapscan.conf: information about detected dahdi channels ; (currently: analog only) ; ; Automatically generated by $0 -- Please do not edit. EOF fi - gen_tmp_conf "$ZAPTEL_FILE" zaptel_file + gen_tmp_conf "$ZAPTEL_FILE" dahdi_file gen_tmp_conf "$ZAPATA_FILE" zapata_file - cat <$zaptel_file + cat <$dahdi_file # Autogenerated by $0 -- do not hand edit -# Zaptel Configuration File +# Dahdi Configuration File # -# This file is parsed by the Zaptel Configurator, ztcfg +# This file is parsed by the Dahdi Configurator, ztcfg # # It must be in the module loading order @@ -893,7 +893,7 @@ EOF EOF cat <$zapata_file ; Autogenerated by $0 -- do not hand edit -; Zaptel Channels Configurations (zapata.conf) +; Dahdi Channels Configurations (zapata.conf) ; ; This is not intended to be a complete zapata.conf. Rather, it is intended ; to be #include-d by /etc/zapata.conf that will include the global settings @@ -913,7 +913,7 @@ EOF # Another problem with such an approach is how to include an existing # configuration file. For instance: how to include some default settings. # - # Maybe an 'include' directive should be added to zaptel.conf ? + # Maybe an 'include' directive should be added to dahdi.conf ? #cat $spanlist | for procfile in $spanlist do @@ -925,8 +925,8 @@ EOF case "$mode" in list) echo "### $title";; files) - echo "" >>$zaptel_file - echo "# $title" >>$zaptel_file + echo "" >>$dahdi_file + echo "# $title" >>$dahdi_file echo "" >>$zapata_file echo "; $title" >>$zapata_file ;; @@ -975,7 +975,7 @@ EOF # print nothing here. case "$mode" in list) echo "# channel $chan_num, WCTDM, no module.";; - files) echo "# channel $chan_num, WCTDM, no module." >> $zaptel_file;; + files) echo "# channel $chan_num, WCTDM, no module." >> $dahdi_file;; esac continue fi @@ -986,7 +986,7 @@ EOF *WCFXO/*) # X100P print_pattern $chan_num fxs $mode || \ - echo "# channel $chan_num, WCFXO, inactive." >>$zaptel_file + echo "# channel $chan_num, WCFXO, inactive." >>$dahdi_file ;; *WCUSB/*) print_pattern $chan_num fxo $mode @@ -1030,7 +1030,7 @@ EOF case "$mode" in list) echo "# ??: $line";; files) - echo "# ??: $line" >>$zaptel_file + echo "# ??: $line" >>$dahdi_file echo "; ??: $line" >>$zapata_file esac ;; @@ -1043,7 +1043,7 @@ EOF if [ "$mode" = 'files' ] then - cat <> ${zaptel_file} + cat <> ${dahdi_file} # Global data @@ -1054,7 +1054,7 @@ EOF if [ "$mode" = 'files' ]; then mv ${ZAPCONF_FILE} ${ZAPCONF_FILE}.bak 2>/dev/null - mv $zaptel_file ${ZAPCONF_FILE} + mv $dahdi_file ${ZAPCONF_FILE} mv ${ZAPATA_FILE} ${ZAPATA_FILE}.bak 2>/dev/nullk mv $zapata_file ${ZAPATA_FILE} if [ "$do_gen_zapscan" = 'yes' ]; then @@ -1105,7 +1105,7 @@ tmp_dir=`mktemp -d /tmp/genzaptelconf-dir-XXXXXX` || \ case "$lc_country" in - # the list was generated from the source of zaptel: + # the list was generated from the source of dahdi: #grep '{.*[0-9]\+,.*"[a-z][a-z]"' zonedata.c | cut -d'"' -f 2 | xargs |tr ' ' '|' us|au|fr|nl|uk|fi|es|jp|no|at|nz|it|gr|tw|cl|se|be|sg|il|br|hu|lt|pl|za|pt|ee|mx|in|de|ch|dk|cz|cn):;; *) @@ -1150,7 +1150,7 @@ if [ "$zapconf_use_perl" = yes ]; then #redefine genconf to use perl utilities: genconf() { case "$1" in - list) zaptel_hardware ;; + list) dahdi_hardware ;; files) zapconf ;; esac } diff --git a/xpp/genzaptelconf.8 b/xpp/genzaptelconf.8 index c3f6f73..0725b6a 100644 --- a/xpp/genzaptelconf.8 +++ b/xpp/genzaptelconf.8 @@ -1,7 +1,7 @@ .TH GENZAPTELCONF 8 "July 18th, 2005" "Xorcom Rapid Asterisk" "Linux Programmer's Manual" .SH "NAME" .B genzaptelconf --- generates zaptel configuration (TDM adaptors) +-- generates dahdi configuration (TDM adaptors) .SH SYNOPSIS .PP .B genzaptelconf @@ -11,16 +11,16 @@ [-sRdv] -l -- only list to standard output .B genzaptelconf --su -- only unload zaptel modules +-su -- only unload dahdi modules .B genzaptelconf -h -- Help screen .SH DESCRIPTION .B genzaptelconf -is a script to detect zaptel devices (currently mostly TDM cards are +is a script to detect dahdi devices (currently mostly TDM cards are supported). It generates both -.I /etc/zaptel.conf +.I /etc/dahdi.conf and .I /etc/asterisk/zapata-channels.conf @@ -36,7 +36,7 @@ configiration is a default that I only hope is sane. Looking for feedback .RS A two-letter country code. Sets the country-code for the zonezone entries in -.I zaptel.conf +.I dahdi.conf , The default is the value of .I lc_country from @@ -46,7 +46,7 @@ and failing that, "us". .B -d .RS -Also try to detect modules. Unloads all zaptel modules and loads them +Also try to detect modules. Unloads all dahdi modules and loads them one by one. Considers a module useful if it loaded successfully and if loading it has generated at least one zapata channel. @@ -109,7 +109,7 @@ Don't restart asterisk even if it was stopped using .B -s .RS Stop asterisk for the duration of the test. The detection will only -work if nobody uses the zaptel channels: +work if nobody uses the dahdi channels: * To allow unloading of modules @@ -124,7 +124,7 @@ try to start it after the end of the test. Be verbose. lists the detected modules if .I -d is used. Lists detected channls. In the end tries to connect to asterisk -to get a list of configured zaptel channels. +to get a list of configured dahdi channels. .RE .B -z @@ -174,12 +174,12 @@ If set to 'yes', no context changes are made in zapata-channels.conf .I context_lines .RS -The context into which calls will go from zaptel trunks. +The context into which calls will go from dahdi trunks. .RE .I context_phones .RS -The context into which calls will go from zaptel phones. +The context into which calls will go from dahdi phones. .RE .I context_manual @@ -189,12 +189,12 @@ If set to 'yes', no group settings are made in zapata-channels.conf .I group_lines .RS -The group number for zaptel trunks. +The group number for dahdi trunks. .RE .I group_phones .RS -The group number for zaptel phones. +The group number for dahdi phones. .RE .I ALL_MODULES @@ -205,7 +205,7 @@ is the same for both. .I ZAPCONF_FILE .RS -ztcfg's configuration file. The sane default is /etc/zaptel.conf . +ztcfg's configuration file. The sane default is /etc/dahdi.conf . .RE .I ZAPATA_FILE @@ -216,7 +216,7 @@ The generated partial zapata.conf snippet. Default: .I ZAPTEL_BOOT_DEBIAN .RS -The Debian Zaptel defaults file. Normally +The Debian Dahdi defaults file. Normally .I /etc/default/zaptel . .RE @@ -224,7 +224,7 @@ The Debian Zaptel defaults file. Normally .I ZAPTEL_BOOT_FEDORA .RS -The Zaptel defaults file on various other distributions. Normally +The Dahdi defaults file on various other distributions. Normally .I /etc/sysconfig/zaptel . .RE @@ -246,14 +246,14 @@ as a last resort. .RE .SH FILES -.I /etc/zaptel.conf +.I /etc/dahdi.conf .RS The configuration file used by .I ztcfg -to configure zaptel devices. re-written by +to configure dahdi devices. re-written by .I genzaptelconf . A backup copy is saved to -.I /etc/zaptel.conf.bak +.I /etc/dahdi.conf.bak . .RE @@ -287,7 +287,7 @@ configuration file that This file holds configuration for both .I genzaptelconf and -.I /etc/init.d/zaptel . +.I /etc/init.d/dahdi . It is sourced by both scripts and can thus be used to override settings of variables from those scripts. .RE @@ -297,7 +297,7 @@ of variables from those scripts. A debian-specific list of kernel modules to be loaded by modprobe at boot time. When the option .I -d -(detect) is used, genzaptelconf will write in this file zaptel modules +(detect) is used, genzaptelconf will write in this file dahdi modules to be loaded. If you want to use a different file, set .I MOD_FILELIST . If it is rewritten, a backup copy is saved to diff --git a/xpp/lsdahdi b/xpp/lsdahdi index a836d98..5611ddd 100755 --- a/xpp/lsdahdi +++ b/xpp/lsdahdi @@ -9,18 +9,18 @@ # use strict; use File::Basename; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); } +BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } -use Zaptel; -use Zaptel::Span; -use Zaptel::Xpp; -use Zaptel::Xpp::Xbus; -use Zaptel::Xpp::Xpd; +use Dahdi; +use Dahdi::Span; +use Dahdi::Xpp; +use Dahdi::Xpp::Xbus; +use Dahdi::Xpp::Xpd; -my @xbuses = Zaptel::Xpp::xbuses("SORT_CONNECTOR"); +my @xbuses = Dahdi::Xpp::xbuses("SORT_CONNECTOR"); my @xpds = map { $_->xpds } @xbuses; -foreach my $span (Zaptel::spans()) { +foreach my $span (Dahdi::spans()) { my $spanno = $span->num; my $xpd = $span->xpd; my @lines; @@ -46,11 +46,11 @@ __END__ =head1 NAME -lszaptel - List all zaptel channels with their types and spans. +lsdahdi - List all dahdi channels with their types and spans. =head1 SYNOPSIS -lszaptel +lsdahdi =head1 DESCRIPTION @@ -103,6 +103,6 @@ and the second one is the signalling (if set). =head1 FILES -lszaptel is a somewhat glorified 'cat /proc/zaptel/*' . Unlike that +lsdahdi is a somewhat glorified 'cat /proc/dahdi/*' . Unlike that command, it sorts the spans with the proper order. It also formats the output slightly differently. diff --git a/xpp/perl_modules/Dahdi.pm b/xpp/perl_modules/Dahdi.pm new file mode 100644 index 0000000..a191556 --- /dev/null +++ b/xpp/perl_modules/Dahdi.pm @@ -0,0 +1,68 @@ +package Dahdi; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Span; + +=head1 NAME + +Dahdi - Perl interface to Dahdi information + +This package allows access from Perl to information about Dahdi +hardware and loaded Dahdi devices. + +=head1 SYNOPSIS + + # Listing channels in analog spans: + use Dahdi; + # scans system: + my @xbuses = Dahdi::spans(); + for my $span (@spans) { + next if ($span->is_digital); + $span->num. " - [". $span->type ."] ". $span->name. "\n"; + for my $chan ($span->chans) { + print " - ".$chan->num . " - [". $chan->type. "] ". $chan->fqn". \n"; + } + } +=cut + +my $proc_base = "/proc/dahdi"; + +=head1 spans() + +Returns a list of span objects, ordered by span number. + +=cut + +sub spans() { + my @spans; + + -d $proc_base or return (); + foreach my $zfile (glob "$proc_base/*") { + $zfile =~ s:$proc_base/::; + my $span = Dahdi::Span->new($zfile); + push(@spans, $span); + } + @spans = sort { $a->num <=> $b->num } @spans; + return @spans; +} + +=head1 SEE ALSO + +Span objects: L. + +Dahdi channels objects: L. + +Dahdi hardware devices information: L. + +Xorcom Astribank -specific information: L. + +=cut + +1; diff --git a/xpp/perl_modules/Dahdi/Chans.pm b/xpp/perl_modules/Dahdi/Chans.pm new file mode 100644 index 0000000..adb7975 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Chans.pm @@ -0,0 +1,202 @@ +package Dahdi::Chans; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; + +=head1 NAME + +Dahdi::Chans - Perl interface to a Dahdi channel information + +This package allows access from perl to information about a Dahdi +channel. It is part of the Dahdi Perl package. + +=head1 battery() + +Returns 1 if channel reports to have battery (A remote PBX connected to +an FXO port), 0 if channel reports to not have battery and C +otherwise. + +Currently only wcfxo and Astribank FXO modules report battery. For the +rest of the channels + +=head1 fqn() + +(Fully Qualified Name) Returns the full "name" of the channel. + +=head1 index() + +Returns the number of this channel (in the span). + +=head1 num() + +Returns the number of this channel as a Dahdi channel. + +=head signalling() + +Returns the signalling set for this channel through /etc/dahdi.conf . +This is always empty before dahdi_cfg was run. And shows the "other" type +for FXS and for FXO. + +=head1 span() + +Returns a reference to the span to which this channel belongs. + +=head1 type() + +Returns the type of the channel: 'FXS', 'FXO', 'EMPTY', etc. + +=cut + +sub new($$$$$$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $span = shift or die "Missing a span parameter\n"; + my $index = shift; + my $line = shift or die "Missing an input line\n"; + defined $index or die "Missing an index parameter\n"; + my $self = { + 'SPAN' => $span, + 'INDEX' => $index, + }; + bless $self, $pack; + my ($num, $fqn, $rest) = split(/\s+/, $line, 3); + $num or die "Missing a channel number parameter\n"; + $fqn or die "Missing a channel fqn parameter\n"; + my $signalling = ''; + my $info = ''; + if(defined $rest) { + if($rest =~ s/^\s*(\w+)\s*//) { + $signalling = $1; + } + if($rest =~ s/(.*)//) { + $info = $1; + } + } + $self->{NUM} = $num; + $self->{FQN} = $fqn; + $self->{SIGNALLING} = $signalling; + $self->{INFO} = $info; + my $type; + if($fqn =~ m|\bXPP_(\w+)/.*$|) { + $type = $1; # An Astribank + } elsif ($fqn =~ m{\bWCFXO/.*}) { + $type = "FXO"; # wcfxo - x100p and relatives. + # A single port card. The driver issue RED alarm when + # There's no better + $self->{BATTERY} = !($span->description =~ /\bRED\b/); + } elsif ($fqn =~ m{\bFXS/.*}) { + $type = "FXS"; # likely Rhino + } elsif ($fqn =~ m{\bFXO/.*}) { + $type = "FXO"; # likely Rhino + } elsif ($fqn =~ m{\b---/.*}) { + $type = "EMPTY"; # likely Rhino, empty slot. + } elsif ($fqn =~ m{\b(TE[24]|WCT1|Tor2|TorISA|WP[TE]1|cwain[12])/.*}) { + # TE[24]: Digium wct4xxp + # WCT1: Digium single span card drivers? + # Tor2: Tor PCI cards + # TorISA: ISA ones (still used?) + # WP[TE]1: Sangoma. TODO: this one tells us if it is TE or NT. + # cwain: Junghanns E1 card. + $type = "PRI"; + } elsif ($fqn =~ m{\b(ZTHFC%d*|ztqoz\d*)/.*}) { + # ZTHFC: HFC-s single-port card (zaphfc/vzaphfc) + # ztqoz: qozap (Junghanns) multi-port HFC card + $type = "BRI"; + } elsif ($fqn =~ m{\bztgsm/.*}) { + # Junghanns GSM card + $type = "GSM"; + } elsif(defined $signalling) { + $type = 'FXS' if $signalling =~ /^FXS/; + $type = 'FXO' if $signalling =~ /^FXO/; + } else { + $type = undef; + } + $self->type($type); + $self->span()->type($type) + if ! defined($self->span()->type()) || + $self->span()->type() eq 'UNKNOWN'; + return $self; +} + +=head1 probe_type() + +In the case of some cards, the information in /proc/dahdi is not good +enough to tell the type of each channel. In this case an extra explicit +probe is needed. + +Currently this is implemented by using some invocations of dahdi_cfg(8). + +It may later be replaced by dahdi_scan(8). + +=cut + +my $dahdi_cfg = $ENV{DAHDI_CFG} || '/sbin/dahdi_cfg'; +sub probe_type($) { + my $self = shift; + my $fqn = $self->fqn; + my $num = $self->num; + my $type; + + if($fqn =~ m:WCTDM/| WRTDM/|OPVXA1200/:) { + my %maybe; + + undef %maybe; + foreach my $sig (qw(fxo fxs)) { + my $cmd = "echo ${sig}ks=$num | $dahdi_cfg -c /dev/fd/0"; + + $maybe{$sig} = system("$cmd >/dev/null 2>&1") == 0; + } + if($maybe{fxo} and $maybe{fxs}) { + $type = 'EMPTY'; + } elsif($maybe{fxo}) { + $type = 'FXS'; + } elsif($maybe{fxs}) { + $type = 'FXO'; + } else { + $type = 'EMPTY'; + } + } else { + $type = $self->type; + } + return $type; +} + +sub battery($) { + my $self = shift or die; + my $span = $self->span or die; + + return undef unless $self->type eq 'FXO'; + return $self->{BATTERY} if defined $self->{BATTERY}; + + my $xpd = $span->xpd; + my $index = $self->index; + return undef if !$xpd; + + # It's an XPD (FXO) + my @lines = @{$xpd->lines}; + my $line = $lines[$index]; + return $line->battery; +} + +sub blink($$) { + my $self = shift or die; + my $on = shift; + my $span = $self->span or die; + + my $xpd = $span->xpd; + my $index = $self->index; + return undef if !$xpd; + + my @lines = @{$xpd->lines}; + my $line = $lines[$index]; + return $line->blink($on); +} + + +1; diff --git a/xpp/perl_modules/Dahdi/Config/Defaults.pm b/xpp/perl_modules/Dahdi/Config/Defaults.pm new file mode 100644 index 0000000..e720568 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Config/Defaults.pm @@ -0,0 +1,57 @@ +package Dahdi::Config::Defaults; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; + +# Use the shell to source a file and expand a given list +# of variables. +sub do_source($@) { + my $file = shift; + my @vars = @_; + my @output = `env -i sh -ec '. $file; export @vars; for i in @vars; do eval echo \$i=\\\$\$i; done'`; + die "$0: Sourcing '$file' exited with $?" if $?; + my %vars; + + foreach my $line (@output) { + chomp $line; + my ($k, $v) = split(/=/, $line, 2); + $vars{$k} = $v if grep /^$k$/, @vars; + } + return %vars; +} + +sub source_vars { + my @vars = @_; + my $default_file; + my %system_files = ( + "/etc/default/zaptel" => 'Debian and friends', + "/etc/sysconfig/zaptel" => 'Red Hat and friends', + "/etc/dahdi/defaults" => 'Dahdi generic', + ); + + if(defined $ENV{DAHDI_DEFAULTS}) { + $default_file = $ENV{DAHDI_DEFAULTS}; + } else { + foreach my $f (keys %system_files) { + if(-r $f) { + if(defined $default_file) { + die "An '$f' collides with '$default_file'"; + } + $default_file = $f; + } + } + } + if (! $default_file) { + return ("", ()); + } + my %vars = Dahdi::Config::Defaults::do_source($default_file, @vars); + return ($default_file, %vars); +} + +1; diff --git a/xpp/perl_modules/Dahdi/Hardware.pm b/xpp/perl_modules/Dahdi/Hardware.pm new file mode 100644 index 0000000..6407760 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Hardware.pm @@ -0,0 +1,168 @@ +package Dahdi::Hardware; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Hardware::USB; +use Dahdi::Hardware::PCI; + +=head1 NAME + +Dahdi::Hardware - Perl interface to a Dahdi devices listing + + + use Dahdi::Hardware; + + my $hardware = Dahdi::Hardware->scan; + + # mini dahdi_hardware: + foreach my $device ($hardware->device_list) { + print "Vendor: device->{VENDOR}, Product: $device->{PRODUCT}\n" + } + + # let's see if there are devices without loaded drivers, and sugggest + # drivers to load: + my @to_load = (); + foreach my $device ($hardware->device_list) { + if (! $device->{LOADED} ) { + push @to_load, ($device->${DRIVER}); + } + } + if (@to_load) { + print "To support the extra devices you probably need to run:\n" + print " modprobe ". (join ' ', @to_load). "\n"; + } + + +This module provides information about available Dahdi devices on the +system. It identifies devices by (USB/PCI) bus IDs. + + +=head1 Device Attributes +As usual, object attributes can be used in either upp-case or +lower-case, or lower-case functions. + +=head2 bus_type + +'PCI' or 'USB'. + + +=head2 description + +A one-line description of the device. + + +=head2 driver + +Name of a Dahdi device driver that should handle this device. This is +based on a pre-made list. + + +=head2 vendor, product, subvendor, subproduct + +The PCI and USB vendor ID, product ID, sub-vendor ID and sub-product ID. +(The standard short lspci and lsusb listings show only vendor and +product IDs). + + +=head2 loaded + +If the device is handled by a module - the name of the module. Else - +undef. + + +=head2 priv_device_name + +A string that shows the "location" of that device on the bus. + + +=head2 is_astribank + +True if the device is a Xorcom Astribank (which may provide some extra +attributes). + +=head2 serial + +(Astribank-specific attrribute) - the serial number string of the +Astribank. + +=cut + +sub device_detected($$) { + my $dev = shift || die; + my $name = shift || die; + die unless defined $dev->{'BUS_TYPE'}; + $dev->{IS_ASTRIBANK} = 0 unless defined $dev->{'IS_ASTRIBANK'}; + $dev->{'HARDWARE_NAME'} = $name; +} + +sub device_removed($) { + my $dev = shift || die; + my $name = $dev->hardware_name; + die "Missing dahdi device hardware name" unless $name; +} + + +=head1 device_list() + +Returns a list of the hardware devices on the system. + +You must run scan() first for this function to run meaningful output. + +=cut + +sub device_list($) { + my $self = shift || die; + my @types = @_; + my @list; + + @types = qw(USB PCI) unless @types; + foreach my $t (@types) { + @list = ( @list, @{$self->{$t}} ); + } + return @list; +} + + +=head1 drivers() + +Returns a list of drivers (currently sorted by name) that are used by +the devices in the current system (regardless to whether or not they are +loaded. + +=cut + +sub drivers($) { + my $self = shift || die; + my @devs = $self->device_list; + my @drvs = map { $_->{DRIVER} } @devs; + # Make unique + my %drivers; + @drivers{@drvs} = 1; + return sort keys %drivers; +} + + +=head1 scan() + +Scan the system for Dahdi devices (PCI and USB). Returns nothing but +must be run to initialize the module. + +=cut + +sub scan($) { + my $pack = shift || die; + my $self = {}; + bless $self, $pack; + + $self->{USB} = [ Dahdi::Hardware::USB->devices ]; + $self->{PCI} = [ Dahdi::Hardware::PCI->scan_devices ]; + return $self; +} + +1; diff --git a/xpp/perl_modules/Dahdi/Hardware/PCI.pm b/xpp/perl_modules/Dahdi/Hardware/PCI.pm new file mode 100644 index 0000000..f3d9360 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Hardware/PCI.pm @@ -0,0 +1,208 @@ +package Dahdi::Hardware::PCI; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; +use Dahdi::Hardware; + +our @ISA = qw(Dahdi::Hardware); + +# Lookup algorithm: +# First match 'vendor:product/subvendor:subproduct' key +# Else match 'vendor:product/subvendor' key +# Else match 'vendor:product' key +# Else not a dahdi hardware. +my %pci_ids = ( + # from wct4xxp + '10ee:0314' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P/TE405P (1st Gen)' }, + 'd161:0420/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE420 (4th Gen)' }, + 'd161:0410/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P (4th Gen)' }, + 'd161:0405/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE405P (4th Gen)' }, + 'd161:0410/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P (3rd Gen)' }, + 'd161:0405/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE405P (3rd Gen)' }, + 'd161:0410' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P (2nd Gen)' }, + 'd161:0405' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE405P (2nd Gen)' }, + 'd161:0220/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE220 (4th Gen)' }, + 'd161:0205/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE205P (4th Gen)' }, + 'd161:0210/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE210P (4th Gen)' }, + 'd161:0205/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE205P (3rd Gen)' }, + 'd161:0210/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE210P (3rd Gen)' }, + 'd161:0205' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE205P ' }, + 'd161:0210' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE210P ' }, + + # from wctdm24xxp + 'd161:2400' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard TDM2400P' }, + 'd161:0800' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard TDM800P' }, + 'd161:8002' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard AEX800' }, + 'd161:8003' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard AEX2400' }, + 'd161:8005' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard TDM410P' }, + 'd161:8006' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard AEX410P' }, + + # from pciradio + 'e159:0001/e16b' => { DRIVER => 'pciradio', DESCRIPTION => 'PCIRADIO' }, + + # from wcfxo + 'e159:0001/8084' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P clone' }, + 'e159:0001/8085' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P' }, + 'e159:0001/8086' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P clone' }, + 'e159:0001/8087' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P clone' }, + '1057:5608' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X100P' }, + + # from wct1xxp + 'e159:0001/6159' => { DRIVER => 'wct1xxp', DESCRIPTION => 'Digium Wildcard T100P T1/PRI or E100P E1/PRA Board' }, + + # from wctdm + 'e159:0001/a159' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard S400P Prototype' }, + 'e159:0001/e159' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard S400P Prototype' }, + 'e159:0001/b100' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV E/F' }, + 'e159:0001/b1d9' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV I' }, + 'e159:0001/b118' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV I' }, + 'e159:0001/b119' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV I' }, + 'e159:0001/a9fd' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + 'e159:0001/a8fd' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + 'e159:0001/a800' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + 'e159:0001/a801' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + 'e159:0001/a908' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + 'e159:0001/a901' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + #'e159:0001' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, + + # from wcte11xp + 'e159:0001/71fe' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, + 'e159:0001/79fe' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, + 'e159:0001/795e' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, + 'e159:0001/79de' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, + 'e159:0001/797e' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, + + # from wcte12xp + 'd161:0120' => { DRIVER => 'wcte12xp', DESCRIPTION => 'Wildcard TE12xP' }, + 'd161:8000' => { DRIVER => 'wcte12xp', DESCRIPTION => 'Wildcard TE121' }, + 'd161:8001' => { DRIVER => 'wcte12xp', DESCRIPTION => 'Wildcard TE122' }, + + # from tor2 + '10b5:9030' => { DRIVER => 'tor2', DESCRIPTION => 'PLX 9030' }, + '10b5:3001' => { DRIVER => 'tor2', DESCRIPTION => 'PLX Development Board' }, + '10b5:D00D' => { DRIVER => 'tor2', DESCRIPTION => 'Tormenta 2 Quad T1/PRI or E1/PRA' }, + '10b5:4000' => { DRIVER => 'tor2', DESCRIPTION => 'Tormenta 2 Quad T1/E1 (non-Digium clone)' }, + + # Cologne Chips: + # (Still a partial list) + '1397:08b4/b556' => { DRIVER => 'qozap', DESCRIPTION => 'Junghanns DuoBRI ISDN card' }, + '1397:08b4' => { DRIVER => 'qozap', DESCRIPTION => 'Junghanns QuadBRI ISDN card' }, + '1397:16b8' => { DRIVER => 'qozap', DESCRIPTION => 'Junghanns OctoBRI ISDN card' }, + '1397:30b1' => { DRIVER => 'cwain', DESCRIPTION => 'HFC-E1 ISDN E1 card' }, + '1397:2bd0' => { DRIVER => 'zaphfc', DESCRIPTION => 'HFC-S ISDN BRI card' }, + '1397:f001' => { DRIVER => 'ztgsm', DESCRIPTION => 'HFC-GSM Cologne Chips GSM' }, + + # Rhino cards (based on pci.ids) + '0b0b:0105' => { DRIVER => 'r1t1', DESCRIPTION => 'Rhino R1T1' }, + '0b0b:0205' => { DRIVER => 'r4fxo', DESCRIPTION => 'Rhino R14FXO' }, + '0b0b:0206' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB4FXO 4-channel FXO analog telphony card' }, + '0b0b:0305' => { DRIVER => 'r1t1', DESCRIPTION => 'Rhino R1T1' }, + '0b0b:0405' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino R8FXX' }, + '0b0b:0406' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB8FXX 8-channel modular analog telphony card' }, + '0b0b:0505' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino R24FXX' }, + '0b0b:0506' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB24FXS 24-Channel FXS analog telphony card' }, + '0b0b:0605' => { DRIVER => 'rxt1', DESCRIPTION => 'Rhino R2T1' }, + '0b0b:0705' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino R24FXS' }, + '0b0b:0706' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB24FXO 24-Channel FXO analog telphony card' }, + '0b0b:0906' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB24FXX 24-channel modular analog telphony card' }, + + # Sangoma cards (based on pci.ids) + '1923:0040' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A200/Remora FXO/FXS Analog AFT card' }, + '1923:0100' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A104d QUAD T1/E1 AFT card' }, + '1923:0300' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A101 single-port T1/E1' }, + '1923:0400' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A104u Quad T1/E1 AFT' }, + ); + +$ENV{PATH} .= ":/usr/sbin:/sbin:/usr/bin:/bin"; + +sub pci_sorter { + return $a->priv_device_name() cmp $b->priv_device_name(); +} + +sub new($$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $self = { @_ }; + bless $self, $pack; + Dahdi::Hardware::device_detected($self, + sprintf("pci:%s", $self->{PRIV_DEVICE_NAME})); + return $self; +} + +my %pci_devs; + +sub readfile($) { + my $name = shift || die; + open(F, $name) || die "Failed to open '$name': $!"; + my $str = ; + close F; + chomp($str); + return $str; +} + +sub scan_devices($) { + my @devices; + + while() { + m,([^/]+)$,,; + my $name = $1; + my $l = readlink $_ || die; + $pci_devs{$name}{PRIV_DEVICE_NAME} = $name; + $pci_devs{$name}{DEVICE} = $l; + $pci_devs{$name}{VENDOR} = readfile "$_/vendor"; + $pci_devs{$name}{PRODUCT} = readfile "$_/device"; + $pci_devs{$name}{SUBVENDOR} = readfile "$_/subsystem_vendor"; + $pci_devs{$name}{SUBPRODUCT} = readfile "$_/subsystem_device"; + my $dev = $pci_devs{$name}; + grep(s/0x//, $dev->{VENDOR}, $dev->{PRODUCT}, $dev->{SUBVENDOR}, $dev->{SUBPRODUCT}); + $pci_devs{$name}{DRIVER} = ''; + } + + while() { + m,^(.*?)/([^/]+)/([^/]+)$,; + my $prefix = $1; + my $drvname = $2; + my $id = $3; + my $l = readlink "$prefix/$drvname/module"; + # Find the real module name (if we can). + if(defined $l) { + my $moduledir = "$prefix/$drvname/$l"; + my $modname = $moduledir; + $modname =~ s:^.*/::; + $drvname = $modname; + } + $pci_devs{$id}{LOADED} = $drvname; + } + foreach (sort keys %pci_devs) { + my $dev = $pci_devs{$_}; + my $key; + # Try to match + $key = "$dev->{VENDOR}:$dev->{PRODUCT}/$dev->{SUBVENDOR}:$dev->{SUBPRODUCT}"; + $key = "$dev->{VENDOR}:$dev->{PRODUCT}/$dev->{SUBVENDOR}" if !defined($pci_ids{$key}); + $key = "$dev->{VENDOR}:$dev->{PRODUCT}" if !defined($pci_ids{$key}); + next unless defined $pci_ids{$key}; + + my $d = Dahdi::Hardware::PCI->new( + BUS_TYPE => 'PCI', + PRIV_DEVICE_NAME => $dev->{PRIV_DEVICE_NAME}, + VENDOR => $dev->{VENDOR}, + PRODUCT => $dev->{PRODUCT}, + SUBVENDOR => $dev->{SUBVENDOR}, + SUBPRODUCT => $dev->{SUBPRODUCT}, + LOADED => $dev->{LOADED}, + DRIVER => $pci_ids{$key}{DRIVER}, + DESCRIPTION => $pci_ids{$key}{DESCRIPTION}, + ); + push(@devices, $d); + } + @devices = sort pci_sorter @devices; + return @devices; +} + +1; diff --git a/xpp/perl_modules/Dahdi/Hardware/USB.pm b/xpp/perl_modules/Dahdi/Hardware/USB.pm new file mode 100644 index 0000000..fed7c29 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Hardware/USB.pm @@ -0,0 +1,116 @@ +package Dahdi::Hardware::USB; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; +use Dahdi::Hardware; +use Dahdi::Xpp; +use Dahdi::Xpp::Xbus; + +our @ISA = qw(Dahdi::Hardware); + +my %usb_ids = ( + # from wcusb + '06e6:831c' => { DRIVER => 'wcusb', DESCRIPTION => 'Wildcard S100U USB FXS Interface' }, + '06e6:831e' => { DRIVER => 'wcusb2', DESCRIPTION => 'Wildcard S110U USB FXS Interface' }, + '06e6:b210' => { DRIVER => 'wc_usb_phone', DESCRIPTION => 'Wildcard Phone Test driver' }, + + # from xpp_usb + 'e4e4:1130' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-8/16 no-firmware' }, + 'e4e4:1131' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-8/16 USB-firmware' }, + 'e4e4:1132' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-8/16 FPGA-firmware' }, + 'e4e4:1140' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-BRI no-firmware' }, + 'e4e4:1141' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-BRI USB-firmware' }, + 'e4e4:1142' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-BRI FPGA-firmware' }, + 'e4e4:1150' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-multi no-firmware' }, + 'e4e4:1151' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-multi USB-firmware' }, + 'e4e4:1152' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-multi FPGA-firmware' }, + 'e4e4:1160' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-modular no-firmware' }, + 'e4e4:1161' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-modular USB-firmware' }, + 'e4e4:1162' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-modular FPGA-firmware' }, + ); + + +$ENV{PATH} .= ":/usr/sbin:/sbin:/usr/bin:/bin"; + +my @xbuses = Dahdi::Xpp::xbuses('SORT_CONNECTOR'); + +sub usb_sorter() { + return $a->hardware_name cmp $b->hardware_name; +} + +sub xbus_of_usb($) { + my $priv_device_name = shift; + my $dev = shift; + + my ($wanted) = grep { + defined($_->usb_devname) && + $priv_device_name eq $_->usb_devname + } @xbuses; + return $wanted; +} + +sub new($$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $self = { @_ }; + bless $self, $pack; + my $xbus = xbus_of_usb($self->priv_device_name); + if(defined $xbus) { + $self->{XBUS} = $xbus; + $self->{LOADED} = 'xpp_usb'; + } else { + $self->{XBUS} = undef; + $self->{LOADED} = undef; + } + Dahdi::Hardware::device_detected($self, + sprintf("usb:%s", $self->{PRIV_DEVICE_NAME})); + return $self; +} + +sub devices($) { + my $pack = shift || die; + my $usb_device_list = "/proc/bus/usb/devices"; + return unless (-r $usb_device_list); + + my @devices; + open(F, $usb_device_list) || die "Failed to open $usb_device_list: $!"; + local $/ = ''; + while() { + my @lines = split(/\n/); + my ($tline) = grep(/^T/, @lines); + my ($pline) = grep(/^P/, @lines); + my ($sline) = grep(/^S:.*SerialNumber=/, @lines); + my ($busnum,$devnum) = ($tline =~ /Bus=(\w+)\W.*Dev#=\s*(\w+)\W/); + my $devname = sprintf("%03d/%03d", $busnum, $devnum); + my ($vendor,$product) = ($pline =~ /Vendor=(\w+)\W.*ProdID=(\w+)\W/); + my $serial; + if(defined $sline) { + $sline =~ /SerialNumber=(.*)/; + $serial = $1; + #$serial =~ s/[[:^print:]]/_/g; + } + my $model = $usb_ids{"$vendor:$product"}; + next unless defined $model; + my $d = Dahdi::Hardware::USB->new( + IS_ASTRIBANK => ($model->{DRIVER} eq 'xpp_usb')?1:0, + BUS_TYPE => 'USB', + PRIV_DEVICE_NAME => $devname, + VENDOR => $vendor, + PRODUCT => $product, + SERIAL => $serial, + DESCRIPTION => $model->{DESCRIPTION}, + DRIVER => $model->{DRIVER}, + ); + push(@devices, $d); + } + close F; + @devices = sort usb_sorter @devices; +} + +1; diff --git a/xpp/perl_modules/Dahdi/Span.pm b/xpp/perl_modules/Dahdi/Span.pm new file mode 100644 index 0000000..e8faa9b --- /dev/null +++ b/xpp/perl_modules/Dahdi/Span.pm @@ -0,0 +1,300 @@ +package Dahdi::Span; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; +use Dahdi::Chans; +use Dahdi::Xpp::Xpd; + +=head1 NAME + +Dahdi::Spans - Perl interface to a Dahdi span information + +This package allows access from perl to information about a Dahdi +channel. It is part of the Dahdi Perl package. + +A span is a logical unit of Dahdi channels. Normally a port in a +digital card or a whole analog card. + +See documentation of module L for usage example. Specifically +C must be run initially. + +=head1 by_number() + +Get a span by its Dahdi span number. + +=head1 Span Properties + +=head2 num() + +The span number. + +=head2 name() + +The name field of a Dahdi span. E.g.: + + TE2/0/1 + +=head2 description() + +The description field of the span. e.g: + + "T2XXP (PCI) Card 0 Span 1" HDB3/CCS/CRC4 RED + +=head2 chans() + +The list of the channels (L objects) of this span. +In a scalar context returns the number of channels this span has. + +=head2 bchans() + +Likewise a list of bchannels (or a count in a scalar context). + +=head2 is_sync_master() + +Is this span the source of timing for Dahdi? + +=head2 type() + +Type of span, or "UNKNOWN" if could not be detected. Current known +types: + +BRI_TE, BRI_NT, E1_TE, E1_NT, J1_TE, J1_NT, T1_TE, T1_NT, FXS, FXO + +=head2 is_pri() + +Is this an E1/J1/T1 span? + +=head2 is_bri() + +Is this a BRI span? + +=head2 is_digital() + +Is this a digital (as opposed to analog) span? + +=head2 termtype() + +Set for digital spans. "TE" or "NT". Will probably be assumed to be "TE" +if there's no information pointing either way. + +=head2 coding() + +Suggested sane coding type (e.g.: "hdb3", "b8zs") for this type of span. + +=head2 framing() + +Suggested sane framing type (e.g.: "ccs", "esf") for this type of span. + +=head2 yellow(), crc4() + +Likewise, suggestions ofr the respective fields in the span= line in +dahdi.conf for this span. + +=head2 signalling() + +Suggested chan_dahdi.conf signalling for channels of this span. + +=head2 switchtype() + +Suggested chan_dahdi.conf switchtype for channels of this span. + +=head1 Note + +Most of those properties are normally used as lower-case functions, but +actually set in the module as capital-letter propeties. To look at e.g. +"signalling" is set, look for "SIGNALLING". + +=cut + +my $proc_base = "/proc/dahdi"; + +sub chans($) { + my $span = shift; + return @{$span->{CHANS}}; +} + +sub by_number($) { + my $span_number = shift; + die "Missing span number" unless defined $span_number; + my @spans = Dahdi::spans(); + + my ($span) = grep { $_->num == $span_number } @spans; + return $span; +} + +my @bri_strings = ( + 'BRI_(NT|TE)', + '(?:quad|octo)BRI PCI ISDN Card.* \[(NT|TE)\]\ ', + 'octoBRI \[(NT|TE)\] ', + 'HFC-S PCI A ISDN.* \[(NT|TE)\] ' + ); + +my @pri_strings = ( + '(E1|T1|J1)_(NT|TE)', + 'Tormenta 2 .*Quad (E1|T1)', # tor2. + 'Digium Wildcard .100P (T1|E1)/', # wct1xxp + 'ISA Tormenta Span 1', # torisa + 'TE110P T1/E1', # wcte11xp + 'Wildcard TE120P', # wcte12xp + 'Wildcard TE121', # wcte12xp + 'Wildcard TE122', # wcte12xp + 'T[24]XXP \(PCI\) Card ', # wct4xxp + ); + +our $DAHDI_BRI_NET = 'bri_net'; +our $DAHDI_BRI_CPE = 'bri_cpe'; + +our $DAHDI_PRI_NET = 'pri_net'; +our $DAHDI_PRI_CPE = 'pri_cpe'; + +sub init_proto($$) { + my $self = shift; + my $proto = shift; + + $self->{PROTO} = $proto; + if($proto eq 'E1') { + $self->{DCHAN_IDX} = 15; + $self->{BCHAN_LIST} = [ 0 .. 14, 16 .. 30 ]; + } elsif($proto eq 'T1') { + $self->{DCHAN_IDX} = 23; + $self->{BCHAN_LIST} = [ 0 .. 22 ]; + } + $self->{TYPE} = "${proto}_$self->{TERMTYPE}"; +} + +sub new($$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $num = shift or die "Missing a span number parameter\n"; + my $self = { NUM => $num }; + bless $self, $pack; + $self->{TYPE} = "UNKNOWN"; + my @xpds = Dahdi::Xpp::Xpd::xpds_by_spanno; + my $xpd = $xpds[$num]; + if(defined $xpd) { + die "Spanno mismatch: $xpd->spanno, $num" unless $xpd->spanno == $num; + $self->{XPD} = $xpd; + } + open(F, "$proc_base/$num") or die "Failed to open '$proc_base/$num\n"; + my $head = ; + chomp $head; + $self->{IS_DIGITAL} = 0; + $self->{IS_BRI} = 0; + $self->{IS_PRI} = 0; + foreach my $cardtype (@bri_strings) { + if($head =~ m/$cardtype/) { + $self->{IS_DIGITAL} = 1; + $self->{IS_BRI} = 1; + $self->{TERMTYPE} = $1; + $self->{TYPE} = "BRI_$1"; + $self->{DCHAN_IDX} = 2; + $self->{BCHAN_LIST} = [ 0, 1 ]; + last; + } + } + foreach my $cardtype (@pri_strings) { + if($head =~ m/$cardtype/) { + my @info; + + push(@info, $1) if defined $1; + push(@info, $2) if defined $2; + my ($proto) = grep(/(E1|T1|J1)/, @info); + $proto = 'UNKNOWN' unless defined $proto; + my ($termtype) = grep(/(NT|TE)/, @info); + $termtype = 'TE' unless defined $termtype; + + $self->{IS_DIGITAL} = 1; + $self->{IS_PRI} = 1; + $self->{TERMTYPE} = $termtype; + $self->init_proto($proto); + last; + } + } + die "$0: Unkown TERMTYPE [NT/TE]\n" + if $self->is_digital and !defined $self->{TERMTYPE}; + ($self->{NAME}, $self->{DESCRIPTION}) = (split(/\s+/, $head, 4))[2, 3]; + $self->{IS_DAHDI_SYNC_MASTER} = + ($self->{DESCRIPTION} =~ /\(MASTER\)/) ? 1 : 0; + $self->{CHANS} = []; + my @channels; + my $index = 0; + while() { + chomp; + s/^\s*//; + s/\s*$//; + next unless /\S/; + next unless /^\s*\d+/; # must be a real channel string. + my $c = Dahdi::Chans->new($self, $index, $_); + push(@channels, $c); + $index++; + } + close F; + if($self->is_pri()) { + # Check for PRI with unknown type strings + if($index == 31) { + if($self->{PROTO} eq 'UNKNOWN') { + $self->init_proto('E1'); + } elsif($self->{PROTO} ne 'E1') { + die "$index channels in a $self->{PROTO} span"; + } + } elsif($index == 24) { + if($self->{PROTO} eq 'UNKNOWN') { + $self->init_proto('T1'); # FIXME: J1? + } elsif($self->{PROTO} ne 'T1') { + die "$index channels in a $self->{PROTO} span"; + } + } + } + @channels = sort { $a->num <=> $b->num } @channels; + $self->{CHANS} = \@channels; + $self->{YELLOW} = undef; + $self->{CRC4} = undef; + if($self->is_bri()) { + $self->{CODING} = 'ami'; + $self->{DCHAN} = ($self->chans())[$self->{DCHAN_IDX}]; + $self->{BCHANS} = [ ($self->chans())[@{$self->{BCHAN_LIST}}] ]; + # Infer some info from channel name: + my $first_chan = ($self->chans())[0] || die "$0: No channels in span #$num\n"; + my $chan_fqn = $first_chan->fqn(); + if($chan_fqn =~ m(ZTHFC.*/|ztqoz.*/|XPP_BRI_.*/)) { # BRI + $self->{FRAMING} = 'ccs'; + $self->{SWITCHTYPE} = 'euroisdn'; + $self->{SIGNALLING} = ($self->{TERMTYPE} eq 'NT') ? $DAHDI_BRI_NET : $DAHDI_BRI_CPE ; + } elsif($chan_fqn =~ m(ztgsm.*/)) { # Junghanns's GSM cards. + $self->{FRAMING} = 'ccs'; + $self->{SIGNALLING} = 'gsm'; + } + } + if($self->is_pri()) { + $self->{DCHAN} = ($self->chans())[$self->{DCHAN_IDX}]; + $self->{BCHANS} = [ ($self->chans())[@{$self->{BCHAN_LIST}}] ]; + if($self->{PROTO} eq 'E1') { + $self->{CODING} = 'hdb3'; + $self->{FRAMING} = 'ccs'; + $self->{SWITCHTYPE} = 'euroisdn'; + $self->{CRC4} = 'crc4'; + } elsif($self->{PROTO} eq 'T1') { + $self->{CODING} = 'b8zs'; + $self->{FRAMING} = 'esf'; + $self->{SWITCHTYPE} = 'national'; + } else { + die "'$self->{PROTO}' unsupported yet"; + } + $self->{SIGNALLING} = ($self->{TERMTYPE} eq 'NT') ? $DAHDI_PRI_NET : $DAHDI_PRI_CPE ; + } + return $self; +} + +sub bchans($) { + my $self = shift || die; + + return @{$self->{BCHANS}}; +} + +1; diff --git a/xpp/perl_modules/Dahdi/Utils.pm b/xpp/perl_modules/Dahdi/Utils.pm new file mode 100644 index 0000000..dcb7441 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Utils.pm @@ -0,0 +1,52 @@ +package Dahdi::Utils; + +# Accessors (miniperl does not have Class:Accessor) +our $AUTOLOAD; +sub AUTOLOAD { + my $self = shift; + my $name = $AUTOLOAD; + $name =~ s/.*://; # strip fully-qualified portion + return if $name =~ /^[A-Z_]+$/; # ignore special methods (DESTROY) + my $key = uc($name); + my $val = shift; + if (defined $val) { + #print STDERR "set: $key = $val\n"; + return $self->{$key} = $val; + } else { + if(!exists $self->{$key}) { + #$self->xpp_dump; + #die "Trying to get uninitialized '$key'"; + } + my $val = $self->{$key}; + #print STDERR "get: $key ($val)\n"; + return $val; + } +} + +sub xpp_dump($) { + my $self = shift || die; + printf STDERR "Dump a %s\n", ref($self); + foreach my $k (sort keys %{$self}) { + my $val = $self->{$k}; + $val = '**UNDEF**' if !defined $val; + printf STDERR " %-20s %s\n", $k, $val; + } +} + +# Based on Autoloader + +sub import { + my $pkg = shift; + my $callpkg = caller; + + #print STDERR "import: $pkg, $callpkg\n"; + # + # Export symbols, but not by accident of inheritance. + # + die "Sombody inherited Dahdi::Utils" if $pkg ne 'Dahdi::Utils'; + no strict 'refs'; + *{ $callpkg . '::AUTOLOAD' } = \&AUTOLOAD; + *{ $callpkg . '::xpp_dump' } = \&xpp_dump; +} + +1; diff --git a/xpp/perl_modules/Dahdi/Xpp.pm b/xpp/perl_modules/Dahdi/Xpp.pm new file mode 100644 index 0000000..08757e9 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Xpp.pm @@ -0,0 +1,199 @@ +package Dahdi::Xpp; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Xpp::Xbus; + +=head1 NAME + +Dahdi::Xpp - Perl interface to the Xorcom Astribank drivers. + +=head1 SYNOPSIS + + # Listing all Astribanks: + use Dahdi::Xpp; + # scans hardware: + my @xbuses = Dahdi::Xpp::xbuses("SORT_CONNECTOR"); + for my $xbus (@xbuses) { + print $xbus->name." (".$xbus->label .", ". $xbus->connector .")\n"; + for my $xpd ($xbus->xpds) { + print " - ".$xpd->fqn,"\n"; + } + } +=cut + + +my $proc_base = "/proc/xpp"; + +# Nominal sorters for xbuses +sub by_name { + return $a->name cmp $b->name; +} + +sub by_connector { + return $a->connector cmp $b->connector; +} + +sub by_label { + my $cmp = $a->label cmp $b->label; + return $cmp if $cmp != 0; + return $a->connector cmp $b->connector; +} + +=head1 xbuses([sort_order]) + +Scans system (/proc and /sys) and returns a list of Astribank (Xbus) +objects. The optional parameter sort_order is the order in which +the Astribanks will be returns: + +=over + +=item SORT_CONNECTOR + +Sort by the connector string. For USB this defines the "path" to get to +the device through controllers, hubs etc. + +=item SORT_LABEL + +Sorts by the label of the Astribank. The label field is unique to the +Astribank. It can also be viewed through 'lsusb -v' without the drivers +loaded (the iSerial field in the Device Descriptor). + +=item SORT_NAME + +Sort by the "name". e.g: "XBUS-00". The order of Astribank names depends +on the load order, and hence may change between different runs. + +=item custom function + +Instead of using a predefined sorter, you can pass your own sorting +function. See the example sorters in the code of this module. + +=back + +=cut + +sub xbuses { + my $optsort = shift || 'SORT_CONNECTOR'; + my @xbuses; + + -d "$proc_base" or return (); + my @lines; + local $/ = "\n"; + open(F, "$proc_base/xbuses") || + die "$0: Failed to open $proc_base/xbuses: $!\n"; + @lines = ; + close F; + foreach my $line (@lines) { + chomp $line; + my ($name, @attr) = split(/\s+/, $line); + $name =~ s/://; + $name =~ /XBUS-(\d\d)/ or die "Bad XBUS number: $name"; + my $num = $1; + @attr = map { split(/=/); } @attr; + my $xbus = Dahdi::Xpp::Xbus->new(NAME => $name, NUM => $num, @attr); + push(@xbuses, $xbus); + } + my $sorter; + if($optsort eq "SORT_CONNECTOR") { + $sorter = \&by_connector; + } elsif($optsort eq "SORT_NAME") { + $sorter = \&by_name; + } elsif($optsort eq "SORT_LABEL") { + $sorter = \&by_label; + } elsif(ref($optsort) eq 'CODE') { + $sorter = $optsort; + } else { + die "Unknown optional sorter '$optsort'"; + } + @xbuses = sort $sorter @xbuses; + return @xbuses; +} + +sub xpd_of_span($) { + my $span = shift or die "Missing span parameter"; + return undef unless defined $span; + foreach my $xbus (Dahdi::Xpp::xbuses('SORT_CONNECTOR')) { + foreach my $xpd ($xbus->xpds()) { + return $xpd if $xpd->fqn eq $span->name; + } + } + return undef; +} + +=head1 sync([new_sync_source]) + +Gets (and optionally sets) the internal Astribanks synchronization +source. When used to set sync source, returns the original sync source. + +A synchronization source is a value valid writing into /proc/xpp/sync . +For more information read that file and see README.Astribank . + +=cut + +sub sync { + my $newsync = shift; + my $result; + my $newapi = 0; + + my $file = "$proc_base/sync"; + return '' unless -f $file; + # First query + open(F, "$file") or die "Failed to open $file for reading: $!"; + while() { + chomp; + /SYNC=/ and $newapi = 1; + s/#.*//; + if(/\S/) { # First non-comment line + s/^SYNC=\D*// if $newapi; + $result = $_; + last; + } + } + close F; + if(defined($newsync)) { # Now change + $newsync =~ s/.*/\U$&/; + if($newsync =~ /^(\d+)$/) { + $newsync = ($newapi)? "SYNC=$1" : "$1 0"; + } elsif($newsync ne 'DAHDI') { + die "Bad sync parameter '$newsync'"; + } + open(F, ">$file") or die "Failed to open $file for writing: $!"; + print F $newsync; + close(F) or die "Failed in closing $file: $!"; + } + return $result; +} + +=head1 SEE ALSO + +=over + +=item L + +Xbus (Astribank) object. + +=item L + +XPD (the rough equivalent of a Dahdi span) object. + +=item L + +Object for a line: an analog port or a time-slot in a adapter. +Equivalent of a channel in Dahdi. + +=item L + +General documentation in the master package. + +=back + +=cut + +1; diff --git a/xpp/perl_modules/Dahdi/Xpp/Line.pm b/xpp/perl_modules/Dahdi/Xpp/Line.pm new file mode 100644 index 0000000..d627ea4 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Xpp/Line.pm @@ -0,0 +1,95 @@ +package Dahdi::Xpp::Line; +# +# Written by Oron Peled +# Copyright (C) 2008, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; + +my $proc_base = "/proc/xpp"; + +sub new($$$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $xpd = shift or die; + my $index = shift; + defined $index or die; + my $self = {}; + bless $self, $pack; + $self->{XPD} = $xpd; + $self->{INDEX} = $index; + return $self; +} + +sub blink($$) { + my $self = shift; + my $on = shift; + my $xpd = $self->xpd; + my $result; + + my $file = "$proc_base/" . $xpd->fqn . "/blink"; + die "$file is missing" unless -f $file; + # First query + open(F, "$file") or die "Failed to open $file for reading: $!"; + $result = ; + chomp $result; + close F; + if(defined($on)) { # Now change + my $onbitmask = 1 << $self->index; + my $offbitmask = $result & ~$onbitmask; + + $result = $offbitmask; + $result |= $onbitmask if $on; + open(F, ">$file") or die "Failed to open $file for writing: $!"; + print F "$result"; + if(!close(F)) { + if($! == 17) { # EEXISTS + # good + } else { + undef $result; + } + } + } + return $result; +} + +sub create_all($$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $xpd = shift || die; + my $procdir = shift || die; + local $/ = "\n"; + my @lines; + for(my $i = 0; $i < $xpd->{CHANNELS}; $i++) { + my $line = Dahdi::Xpp::Line->new($xpd, $i); + push(@lines, $line); + } + $xpd->{LINES} = \@lines; + my ($infofile) = glob "$procdir/*_info"; + die "Failed globbing '$procdir/*_info'" unless defined $infofile; + my $type = $xpd->type; + open(F, "$infofile") || die "Failed opening '$infofile': $!"; + my $battery_info = 0; + while () { + chomp; + if($type eq 'FXO') { + $battery_info = 1 if /^Battery:/; + if($battery_info && s/^\s*on\s*:\s*//) { + my @batt = split; + foreach my $l (@lines) { + die unless @batt; + my $state = shift @batt; + $l->{BATTERY} = ($state eq '+') ? 1 : 0; + } + $battery_info = 0; + die if @batt; + } + } + } + close F; +} + + +1; diff --git a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm new file mode 100644 index 0000000..4e6b2b3 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm @@ -0,0 +1,118 @@ +package Dahdi::Xpp::Xbus; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; +use Dahdi::Xpp::Xpd; + +my $proc_base = "/proc/xpp"; + +sub xpds($) { + my $xbus = shift; + return @{$xbus->{XPDS}}; +} + +sub by_number($) { + my $busnumber = shift; + die "Missing xbus number parameter" unless defined $busnumber; + my @xbuses = Dahdi::Xpp::xbuses(); + + my ($xbus) = grep { $_->num == $busnumber } @xbuses; + return $xbus; +} + +sub by_label($) { + my $label = shift; + die "Missing xbus label parameter" unless defined $label; + my @xbuses = Dahdi::Xpp::xbuses(); + + my ($xbus) = grep { $_->label eq $label } @xbuses; + return $xbus; +} + +sub get_xpd_by_number($$) { + my $xbus = shift; + my $xpdid = shift; + die "Missing XPD id parameter" unless defined $xpdid; + my @xpds = $xbus->xpds; + my ($wanted) = grep { $_->id eq $xpdid } @xpds; + return $wanted; +} + +sub new($$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $self = {}; + bless $self, $pack; + while(@_) { + my ($k, $v) = @_; + shift; shift; + # Keys in all caps + $k = uc($k); + # Some values are in all caps as well + if($k =~ /^(STATUS)$/) { + $v = uc($v); + } + $self->{$k} = $v; + } + # backward compat for drivers without labels. + if(!defined $self->{LABEL}) { + $self->{LABEL} = '[]'; + } + $self->{LABEL} =~ s/^\[(.*)\]$/$1/ or die "$self->{NAME}: Bad label"; + # Fix badly burned labels. + $self->{LABEL} =~ s/[[:^print:]]/_/g; + $self->{NAME} or die "Missing xbus name"; + my $prefix = "$proc_base/" . $self->{NAME}; + my $usbfile = "$prefix/xpp_usb"; + if(open(F, "$usbfile")) { + my $head = ; + chomp $head; + close F; + $head =~ s/^device: +([^, ]+)/$1/i or die; + $self->{USB_DEVNAME} = $head; + } + @{$self->{XPDS}} = (); + foreach my $dir (glob "$prefix/XPD-??") { + my $xpd = Dahdi::Xpp::Xpd->new($self, $dir); + push(@{$self->{XPDS}}, $xpd); + } + @{$self->{XPDS}} = sort { $a->id <=> $b->id } @{$self->{XPDS}}; + return $self; +} + +sub pretty_xpds($) { + my $xbus = shift; + my @xpds = sort { $a->id <=> $b->id } $xbus->xpds(); + my @xpd_types = map { $_->type } @xpds; + my $last_type = ''; + my $mult = 0; + my $xpdstr = ''; + foreach my $curr (@xpd_types) { + if(!$last_type || ($curr eq $last_type)) { + $mult++; + } else { + if($mult == 1) { + $xpdstr .= "$last_type "; + } elsif($mult) { + $xpdstr .= "$last_type*$mult "; + } + $mult = 1; + } + $last_type = $curr; + } + if($mult == 1) { + $xpdstr .= "$last_type "; + } elsif($mult) { + $xpdstr .= "$last_type*$mult "; + } + $xpdstr =~ s/\s*$//; # trim trailing space + return $xpdstr; +} + +1; diff --git a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm new file mode 100644 index 0000000..9e22ed2 --- /dev/null +++ b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm @@ -0,0 +1,123 @@ +package Dahdi::Xpp::Xpd; +# +# Written by Oron Peled +# Copyright (C) 2007, Xorcom +# This program is free software; you can redistribute and/or +# modify it under the same terms as Perl itself. +# +# $Id$ +# +use strict; +use Dahdi::Utils; +use Dahdi::Xpp; +use Dahdi::Xpp::Line; + +my $proc_base = "/proc/xpp"; + +sub blink($$) { + my $self = shift; + my $on = shift; + my $result; + + my $file = "$proc_base/" . $self->fqn . "/blink"; + die "$file is missing" unless -f $file; + # First query + open(F, "$file") or die "Failed to open $file for reading: $!"; + $result = ; + 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)?"0xFFFF":"0"; + if(!close(F)) { + if($! == 17) { # EEXISTS + # good + } else { + undef $result; + } + } + } + return $result; +} + +sub dahdi_registration($$) { + my $self = shift; + my $on = shift; + my $result; + + my $file = "$proc_base/" . $self->fqn . "/dahdi_registration"; + die "$file is missing" unless -f $file; + # First query + open(F, "$file") or die "Failed to open $file for reading: $!"; + $result = ; + 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 xpds_by_spanno() { + my @xbuses = Dahdi::Xpp::xbuses("SORT_CONNECTOR"); + my @xpds = map { $_->xpds } @xbuses; + @xpds = grep { $_->spanno } @xpds; + @xpds = sort { $a->spanno <=> $b->spanno } @xpds; + my @spanno = map { $_->spanno } @xpds; + my @idx; + @idx[@spanno] = @xpds; # The spanno is the index now + return @idx; +} + +sub new($$) { + my $pack = shift or die "Wasn't called as a class method\n"; + my $xbus = shift || die; + my $procdir = shift || die; + my $self = {}; + bless $self, $pack; + $self->{XBUS} = $xbus; + $self->{DIR} = $procdir; + local $/ = "\n"; + open(F, "$procdir/summary") || die "Missing summary file in $procdir"; + my $head = ; + 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() { + chomp; + if(s/^\s*offhook\s*:\s*//) { + my @offhook = split; + @offhook || die "No channels in '$procdir/summary'"; + $self->{CHANNELS} = @offhook; + last; + } + } + close F; + $head =~ s/^(XPD-(\d\d))\s+// || die; + $self->{ID} = $2; + $self->{FQN} = $xbus->name . "/" . $1; + $head =~ s/^.*\(// || die; + $head =~ s/\) */, / || die; + $head =~ s/\s*,\s*/,/g || die; + my ($type,$present,$span,$rest) = split(/,/, $head); + #warn "Garbage in '$procdir/summary': rest='$rest'\n" if $rest; + if($span =~ s/span\s+(\d+)//) { # since changeset:5119 + $self->{SPANNO} = $1; + } + $self->{TYPE} = $type; + $self->{IS_BRI} = ($type =~ /BRI_(NT|TE)/); + $self->{IS_PRI} = ($type =~ /[ETJ]1_(NT|TE)/); + $self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} ); + Dahdi::Xpp::Line->create_all($self, $procdir); + return $self; +} + +1; diff --git a/xpp/perl_modules/Zaptel.pm b/xpp/perl_modules/Zaptel.pm deleted file mode 100644 index ef36bae..0000000 --- a/xpp/perl_modules/Zaptel.pm +++ /dev/null @@ -1,68 +0,0 @@ -package Zaptel; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Span; - -=head1 NAME - -Zaptel - Perl interface to Zaptel information - -This package allows access from Perl to information about Zaptel -hardware and loaded Zaptel devices. - -=head1 SYNOPSIS - - # Listing channels in analog spans: - use Zaptel; - # scans system: - my @xbuses = Zaptel::spans(); - for my $span (@spans) { - next if ($span->is_digital); - $span->num. " - [". $span->type ."] ". $span->name. "\n"; - for my $chan ($span->chans) { - print " - ".$chan->num . " - [". $chan->type. "] ". $chan->fqn". \n"; - } - } -=cut - -my $proc_base = "/proc/dahdi"; - -=head1 spans() - -Returns a list of span objects, ordered by span number. - -=cut - -sub spans() { - my @spans; - - -d $proc_base or return (); - foreach my $zfile (glob "$proc_base/*") { - $zfile =~ s:$proc_base/::; - my $span = Zaptel::Span->new($zfile); - push(@spans, $span); - } - @spans = sort { $a->num <=> $b->num } @spans; - return @spans; -} - -=head1 SEE ALSO - -Span objects: L. - -Zaptel channels objects: L. - -Zaptel hardware devices information: L. - -Xorcom Astribank -specific information: L. - -=cut - -1; diff --git a/xpp/perl_modules/Zaptel/Chans.pm b/xpp/perl_modules/Zaptel/Chans.pm deleted file mode 100644 index 6f83f77..0000000 --- a/xpp/perl_modules/Zaptel/Chans.pm +++ /dev/null @@ -1,202 +0,0 @@ -package Zaptel::Chans; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; - -=head1 NAME - -Zaptel::Chans - Perl interface to a Zaptel channel information - -This package allows access from perl to information about a Zaptel -channel. It is part of the Zaptel Perl package. - -=head1 battery() - -Returns 1 if channel reports to have battery (A remote PBX connected to -an FXO port), 0 if channel reports to not have battery and C -otherwise. - -Currently only wcfxo and Astribank FXO modules report battery. For the -rest of the channels - -=head1 fqn() - -(Fully Qualified Name) Returns the full "name" of the channel. - -=head1 index() - -Returns the number of this channel (in the span). - -=head1 num() - -Returns the number of this channel as a Zaptel channel. - -=head signalling() - -Returns the signalling set for this channel through /etc/zaptel.conf . -This is always empty before ztcfg was run. And shows the "other" type -for FXS and for FXO. - -=head1 span() - -Returns a reference to the span to which this channel belongs. - -=head1 type() - -Returns the type of the channel: 'FXS', 'FXO', 'EMPTY', etc. - -=cut - -sub new($$$$$$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $span = shift or die "Missing a span parameter\n"; - my $index = shift; - my $line = shift or die "Missing an input line\n"; - defined $index or die "Missing an index parameter\n"; - my $self = { - 'SPAN' => $span, - 'INDEX' => $index, - }; - bless $self, $pack; - my ($num, $fqn, $rest) = split(/\s+/, $line, 3); - $num or die "Missing a channel number parameter\n"; - $fqn or die "Missing a channel fqn parameter\n"; - my $signalling = ''; - my $info = ''; - if(defined $rest) { - if($rest =~ s/^\s*(\w+)\s*//) { - $signalling = $1; - } - if($rest =~ s/(.*)//) { - $info = $1; - } - } - $self->{NUM} = $num; - $self->{FQN} = $fqn; - $self->{SIGNALLING} = $signalling; - $self->{INFO} = $info; - my $type; - if($fqn =~ m|\bXPP_(\w+)/.*$|) { - $type = $1; # An Astribank - } elsif ($fqn =~ m{\bWCFXO/.*}) { - $type = "FXO"; # wcfxo - x100p and relatives. - # A single port card. The driver issue RED alarm when - # There's no better - $self->{BATTERY} = !($span->description =~ /\bRED\b/); - } elsif ($fqn =~ m{\bFXS/.*}) { - $type = "FXS"; # likely Rhino - } elsif ($fqn =~ m{\bFXO/.*}) { - $type = "FXO"; # likely Rhino - } elsif ($fqn =~ m{\b---/.*}) { - $type = "EMPTY"; # likely Rhino, empty slot. - } elsif ($fqn =~ m{\b(TE[24]|WCT1|Tor2|TorISA|WP[TE]1|cwain[12])/.*}) { - # TE[24]: Digium wct4xxp - # WCT1: Digium single span card drivers? - # Tor2: Tor PCI cards - # TorISA: ISA ones (still used?) - # WP[TE]1: Sangoma. TODO: this one tells us if it is TE or NT. - # cwain: Junghanns E1 card. - $type = "PRI"; - } elsif ($fqn =~ m{\b(ZTHFC%d*|ztqoz\d*)/.*}) { - # ZTHFC: HFC-s single-port card (zaphfc/vzaphfc) - # ztqoz: qozap (Junghanns) multi-port HFC card - $type = "BRI"; - } elsif ($fqn =~ m{\bztgsm/.*}) { - # Junghanns GSM card - $type = "GSM"; - } elsif(defined $signalling) { - $type = 'FXS' if $signalling =~ /^FXS/; - $type = 'FXO' if $signalling =~ /^FXO/; - } else { - $type = undef; - } - $self->type($type); - $self->span()->type($type) - if ! defined($self->span()->type()) || - $self->span()->type() eq 'UNKNOWN'; - return $self; -} - -=head1 probe_type() - -In the case of some cards, the information in /proc/zaptel is not good -enough to tell the type of each channel. In this case an extra explicit -probe is needed. - -Currently this is implemented by using some invocations of ztcfg(8). - -It may later be replaced by ztscan(8). - -=cut - -my $ztcfg = $ENV{ZTCFG} || '/sbin/ztcfg'; -sub probe_type($) { - my $self = shift; - my $fqn = $self->fqn; - my $num = $self->num; - my $type; - - if($fqn =~ m:WCTDM/| WRTDM/|OPVXA1200/:) { - my %maybe; - - undef %maybe; - foreach my $sig (qw(fxo fxs)) { - my $cmd = "echo ${sig}ks=$num | $ztcfg -c /dev/fd/0"; - - $maybe{$sig} = system("$cmd >/dev/null 2>&1") == 0; - } - if($maybe{fxo} and $maybe{fxs}) { - $type = 'EMPTY'; - } elsif($maybe{fxo}) { - $type = 'FXS'; - } elsif($maybe{fxs}) { - $type = 'FXO'; - } else { - $type = 'EMPTY'; - } - } else { - $type = $self->type; - } - return $type; -} - -sub battery($) { - my $self = shift or die; - my $span = $self->span or die; - - return undef unless $self->type eq 'FXO'; - return $self->{BATTERY} if defined $self->{BATTERY}; - - my $xpd = $span->xpd; - my $index = $self->index; - return undef if !$xpd; - - # It's an XPD (FXO) - my @lines = @{$xpd->lines}; - my $line = $lines[$index]; - return $line->battery; -} - -sub blink($$) { - my $self = shift or die; - my $on = shift; - my $span = $self->span or die; - - my $xpd = $span->xpd; - my $index = $self->index; - return undef if !$xpd; - - my @lines = @{$xpd->lines}; - my $line = $lines[$index]; - return $line->blink($on); -} - - -1; diff --git a/xpp/perl_modules/Zaptel/Config/Defaults.pm b/xpp/perl_modules/Zaptel/Config/Defaults.pm deleted file mode 100644 index 360ca0a..0000000 --- a/xpp/perl_modules/Zaptel/Config/Defaults.pm +++ /dev/null @@ -1,56 +0,0 @@ -package Zaptel::Config::Defaults; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; - -# Use the shell to source a file and expand a given list -# of variables. -sub do_source($@) { - my $file = shift; - my @vars = @_; - my @output = `env -i sh -ec '. $file; export @vars; for i in @vars; do eval echo \$i=\\\$\$i; done'`; - die "$0: Sourcing '$file' exited with $?" if $?; - my %vars; - - foreach my $line (@output) { - chomp $line; - my ($k, $v) = split(/=/, $line, 2); - $vars{$k} = $v if grep /^$k$/, @vars; - } - return %vars; -} - -sub source_vars { - my @vars = @_; - my $default_file; - my %system_files = ( - "/etc/default/zaptel" => 'Debian and friends', - "/etc/sysconfig/zaptel" => 'Red Hat and friends', - ); - - if(defined $ENV{ZAPTEL_DEFAULTS}) { - $default_file = $ENV{ZAPTEL_DEFAULTS}; - } else { - foreach my $f (keys %system_files) { - if(-r $f) { - if(defined $default_file) { - die "An '$f' collides with '$default_file'"; - } - $default_file = $f; - } - } - } - if (! $default_file) { - return ("", ()); - } - my %vars = Zaptel::Config::Defaults::do_source($default_file, @vars); - return ($default_file, %vars); -} - -1; diff --git a/xpp/perl_modules/Zaptel/Hardware.pm b/xpp/perl_modules/Zaptel/Hardware.pm deleted file mode 100644 index ff7aeea..0000000 --- a/xpp/perl_modules/Zaptel/Hardware.pm +++ /dev/null @@ -1,168 +0,0 @@ -package Zaptel::Hardware; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Hardware::USB; -use Zaptel::Hardware::PCI; - -=head1 NAME - -Zaptel::Hardware - Perl interface to a Zaptel devices listing - - - use Zaptel::Hardware; - - my $hardware = Zaptel::Hardware->scan; - - # mini zaptel_hardware: - foreach my $device ($hardware->device_list) { - print "Vendor: device->{VENDOR}, Product: $device->{PRODUCT}\n" - } - - # let's see if there are devices without loaded drivers, and sugggest - # drivers to load: - my @to_load = (); - foreach my $device ($hardware->device_list) { - if (! $device->{LOADED} ) { - push @to_load, ($device->${DRIVER}); - } - } - if (@to_load) { - print "To support the extra devices you probably need to run:\n" - print " modprobe ". (join ' ', @to_load). "\n"; - } - - -This module provides information about available Zaptel devices on the -system. It identifies devices by (USB/PCI) bus IDs. - - -=head1 Device Attributes -As usual, object attributes can be used in either upp-case or -lower-case, or lower-case functions. - -=head2 bus_type - -'PCI' or 'USB'. - - -=head2 description - -A one-line description of the device. - - -=head2 driver - -Name of a Zaptel device driver that should handle this device. This is -based on a pre-made list. - - -=head2 vendor, product, subvendor, subproduct - -The PCI and USB vendor ID, product ID, sub-vendor ID and sub-product ID. -(The standard short lspci and lsusb listings show only vendor and -product IDs). - - -=head2 loaded - -If the device is handled by a module - the name of the module. Else - -undef. - - -=head2 priv_device_name - -A string that shows the "location" of that device on the bus. - - -=head2 is_astribank - -True if the device is a Xorcom Astribank (which may provide some extra -attributes). - -=head2 serial - -(Astribank-specific attrribute) - the serial number string of the -Astribank. - -=cut - -sub device_detected($$) { - my $dev = shift || die; - my $name = shift || die; - die unless defined $dev->{'BUS_TYPE'}; - $dev->{IS_ASTRIBANK} = 0 unless defined $dev->{'IS_ASTRIBANK'}; - $dev->{'HARDWARE_NAME'} = $name; -} - -sub device_removed($) { - my $dev = shift || die; - my $name = $dev->hardware_name; - die "Missing zaptel device hardware name" unless $name; -} - - -=head1 device_list() - -Returns a list of the hardware devices on the system. - -You must run scan() first for this function to run meaningful output. - -=cut - -sub device_list($) { - my $self = shift || die; - my @types = @_; - my @list; - - @types = qw(USB PCI) unless @types; - foreach my $t (@types) { - @list = ( @list, @{$self->{$t}} ); - } - return @list; -} - - -=head1 drivers() - -Returns a list of drivers (currently sorted by name) that are used by -the devices in the current system (regardless to whether or not they are -loaded. - -=cut - -sub drivers($) { - my $self = shift || die; - my @devs = $self->device_list; - my @drvs = map { $_->{DRIVER} } @devs; - # Make unique - my %drivers; - @drivers{@drvs} = 1; - return sort keys %drivers; -} - - -=head1 scan() - -Scan the system for Zaptel devices (PCI and USB). Returns nothing but -must be run to initialize the module. - -=cut - -sub scan($) { - my $pack = shift || die; - my $self = {}; - bless $self, $pack; - - $self->{USB} = [ Zaptel::Hardware::USB->devices ]; - $self->{PCI} = [ Zaptel::Hardware::PCI->scan_devices ]; - return $self; -} - -1; diff --git a/xpp/perl_modules/Zaptel/Hardware/PCI.pm b/xpp/perl_modules/Zaptel/Hardware/PCI.pm deleted file mode 100644 index a63b09f..0000000 --- a/xpp/perl_modules/Zaptel/Hardware/PCI.pm +++ /dev/null @@ -1,208 +0,0 @@ -package Zaptel::Hardware::PCI; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; -use Zaptel::Hardware; - -our @ISA = qw(Zaptel::Hardware); - -# Lookup algorithm: -# First match 'vendor:product/subvendor:subproduct' key -# Else match 'vendor:product/subvendor' key -# Else match 'vendor:product' key -# Else not a zaptel hardware. -my %pci_ids = ( - # from wct4xxp - '10ee:0314' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P/TE405P (1st Gen)' }, - 'd161:0420/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE420 (4th Gen)' }, - 'd161:0410/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P (4th Gen)' }, - 'd161:0405/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE405P (4th Gen)' }, - 'd161:0410/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P (3rd Gen)' }, - 'd161:0405/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE405P (3rd Gen)' }, - 'd161:0410' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE410P (2nd Gen)' }, - 'd161:0405' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE405P (2nd Gen)' }, - 'd161:0220/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE220 (4th Gen)' }, - 'd161:0205/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE205P (4th Gen)' }, - 'd161:0210/0004' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE210P (4th Gen)' }, - 'd161:0205/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE205P (3rd Gen)' }, - 'd161:0210/0003' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE210P (3rd Gen)' }, - 'd161:0205' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE205P ' }, - 'd161:0210' => { DRIVER => 'wct4xxp', DESCRIPTION => 'Wildcard TE210P ' }, - - # from wctdm24xxp - 'd161:2400' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard TDM2400P' }, - 'd161:0800' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard TDM800P' }, - 'd161:8002' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard AEX800' }, - 'd161:8003' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard AEX2400' }, - 'd161:8005' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard TDM410P' }, - 'd161:8006' => { DRIVER => 'wctdm24xxp', DESCRIPTION => 'Wildcard AEX410P' }, - - # from pciradio - 'e159:0001/e16b' => { DRIVER => 'pciradio', DESCRIPTION => 'PCIRADIO' }, - - # from wcfxo - 'e159:0001/8084' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P clone' }, - 'e159:0001/8085' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P' }, - 'e159:0001/8086' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P clone' }, - 'e159:0001/8087' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X101P clone' }, - '1057:5608' => { DRIVER => 'wcfxo', DESCRIPTION => 'Wildcard X100P' }, - - # from wct1xxp - 'e159:0001/6159' => { DRIVER => 'wct1xxp', DESCRIPTION => 'Digium Wildcard T100P T1/PRI or E100P E1/PRA Board' }, - - # from wctdm - 'e159:0001/a159' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard S400P Prototype' }, - 'e159:0001/e159' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard S400P Prototype' }, - 'e159:0001/b100' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV E/F' }, - 'e159:0001/b1d9' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV I' }, - 'e159:0001/b118' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV I' }, - 'e159:0001/b119' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV I' }, - 'e159:0001/a9fd' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - 'e159:0001/a8fd' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - 'e159:0001/a800' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - 'e159:0001/a801' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - 'e159:0001/a908' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - 'e159:0001/a901' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - #'e159:0001' => { DRIVER => 'wctdm', DESCRIPTION => 'Wildcard TDM400P REV H' }, - - # from wcte11xp - 'e159:0001/71fe' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, - 'e159:0001/79fe' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, - 'e159:0001/795e' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, - 'e159:0001/79de' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, - 'e159:0001/797e' => { DRIVER => 'wcte11xp', DESCRIPTION => 'Digium Wildcard TE110P T1/E1 Board' }, - - # from wcte12xp - 'd161:0120' => { DRIVER => 'wcte12xp', DESCRIPTION => 'Wildcard TE12xP' }, - 'd161:8000' => { DRIVER => 'wcte12xp', DESCRIPTION => 'Wildcard TE121' }, - 'd161:8001' => { DRIVER => 'wcte12xp', DESCRIPTION => 'Wildcard TE122' }, - - # from tor2 - '10b5:9030' => { DRIVER => 'tor2', DESCRIPTION => 'PLX 9030' }, - '10b5:3001' => { DRIVER => 'tor2', DESCRIPTION => 'PLX Development Board' }, - '10b5:D00D' => { DRIVER => 'tor2', DESCRIPTION => 'Tormenta 2 Quad T1/PRI or E1/PRA' }, - '10b5:4000' => { DRIVER => 'tor2', DESCRIPTION => 'Tormenta 2 Quad T1/E1 (non-Digium clone)' }, - - # Cologne Chips: - # (Still a partial list) - '1397:08b4/b556' => { DRIVER => 'qozap', DESCRIPTION => 'Junghanns DuoBRI ISDN card' }, - '1397:08b4' => { DRIVER => 'qozap', DESCRIPTION => 'Junghanns QuadBRI ISDN card' }, - '1397:16b8' => { DRIVER => 'qozap', DESCRIPTION => 'Junghanns OctoBRI ISDN card' }, - '1397:30b1' => { DRIVER => 'cwain', DESCRIPTION => 'HFC-E1 ISDN E1 card' }, - '1397:2bd0' => { DRIVER => 'zaphfc', DESCRIPTION => 'HFC-S ISDN BRI card' }, - '1397:f001' => { DRIVER => 'ztgsm', DESCRIPTION => 'HFC-GSM Cologne Chips GSM' }, - - # Rhino cards (based on pci.ids) - '0b0b:0105' => { DRIVER => 'r1t1', DESCRIPTION => 'Rhino R1T1' }, - '0b0b:0205' => { DRIVER => 'r4fxo', DESCRIPTION => 'Rhino R14FXO' }, - '0b0b:0206' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB4FXO 4-channel FXO analog telphony card' }, - '0b0b:0305' => { DRIVER => 'r1t1', DESCRIPTION => 'Rhino R1T1' }, - '0b0b:0405' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino R8FXX' }, - '0b0b:0406' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB8FXX 8-channel modular analog telphony card' }, - '0b0b:0505' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino R24FXX' }, - '0b0b:0506' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB24FXS 24-Channel FXS analog telphony card' }, - '0b0b:0605' => { DRIVER => 'rxt1', DESCRIPTION => 'Rhino R2T1' }, - '0b0b:0705' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino R24FXS' }, - '0b0b:0706' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB24FXO 24-Channel FXO analog telphony card' }, - '0b0b:0906' => { DRIVER => 'rcbfx', DESCRIPTION => 'Rhino RCB24FXX 24-channel modular analog telphony card' }, - - # Sangoma cards (based on pci.ids) - '1923:0040' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A200/Remora FXO/FXS Analog AFT card' }, - '1923:0100' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A104d QUAD T1/E1 AFT card' }, - '1923:0300' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A101 single-port T1/E1' }, - '1923:0400' => { DRIVER => 'wanpipe', DESCRIPTION => 'Sangoma Technologies Corp. A104u Quad T1/E1 AFT' }, - ); - -$ENV{PATH} .= ":/usr/sbin:/sbin:/usr/bin:/bin"; - -sub pci_sorter { - return $a->priv_device_name() cmp $b->priv_device_name(); -} - -sub new($$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $self = { @_ }; - bless $self, $pack; - Zaptel::Hardware::device_detected($self, - sprintf("pci:%s", $self->{PRIV_DEVICE_NAME})); - return $self; -} - -my %pci_devs; - -sub readfile($) { - my $name = shift || die; - open(F, $name) || die "Failed to open '$name': $!"; - my $str = ; - close F; - chomp($str); - return $str; -} - -sub scan_devices($) { - my @devices; - - while() { - m,([^/]+)$,,; - my $name = $1; - my $l = readlink $_ || die; - $pci_devs{$name}{PRIV_DEVICE_NAME} = $name; - $pci_devs{$name}{DEVICE} = $l; - $pci_devs{$name}{VENDOR} = readfile "$_/vendor"; - $pci_devs{$name}{PRODUCT} = readfile "$_/device"; - $pci_devs{$name}{SUBVENDOR} = readfile "$_/subsystem_vendor"; - $pci_devs{$name}{SUBPRODUCT} = readfile "$_/subsystem_device"; - my $dev = $pci_devs{$name}; - grep(s/0x//, $dev->{VENDOR}, $dev->{PRODUCT}, $dev->{SUBVENDOR}, $dev->{SUBPRODUCT}); - $pci_devs{$name}{DRIVER} = ''; - } - - while() { - m,^(.*?)/([^/]+)/([^/]+)$,; - my $prefix = $1; - my $drvname = $2; - my $id = $3; - my $l = readlink "$prefix/$drvname/module"; - # Find the real module name (if we can). - if(defined $l) { - my $moduledir = "$prefix/$drvname/$l"; - my $modname = $moduledir; - $modname =~ s:^.*/::; - $drvname = $modname; - } - $pci_devs{$id}{LOADED} = $drvname; - } - foreach (sort keys %pci_devs) { - my $dev = $pci_devs{$_}; - my $key; - # Try to match - $key = "$dev->{VENDOR}:$dev->{PRODUCT}/$dev->{SUBVENDOR}:$dev->{SUBPRODUCT}"; - $key = "$dev->{VENDOR}:$dev->{PRODUCT}/$dev->{SUBVENDOR}" if !defined($pci_ids{$key}); - $key = "$dev->{VENDOR}:$dev->{PRODUCT}" if !defined($pci_ids{$key}); - next unless defined $pci_ids{$key}; - - my $d = Zaptel::Hardware::PCI->new( - BUS_TYPE => 'PCI', - PRIV_DEVICE_NAME => $dev->{PRIV_DEVICE_NAME}, - VENDOR => $dev->{VENDOR}, - PRODUCT => $dev->{PRODUCT}, - SUBVENDOR => $dev->{SUBVENDOR}, - SUBPRODUCT => $dev->{SUBPRODUCT}, - LOADED => $dev->{LOADED}, - DRIVER => $pci_ids{$key}{DRIVER}, - DESCRIPTION => $pci_ids{$key}{DESCRIPTION}, - ); - push(@devices, $d); - } - @devices = sort pci_sorter @devices; - return @devices; -} - -1; diff --git a/xpp/perl_modules/Zaptel/Hardware/USB.pm b/xpp/perl_modules/Zaptel/Hardware/USB.pm deleted file mode 100644 index a2dc08f..0000000 --- a/xpp/perl_modules/Zaptel/Hardware/USB.pm +++ /dev/null @@ -1,116 +0,0 @@ -package Zaptel::Hardware::USB; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; -use Zaptel::Hardware; -use Zaptel::Xpp; -use Zaptel::Xpp::Xbus; - -our @ISA = qw(Zaptel::Hardware); - -my %usb_ids = ( - # from wcusb - '06e6:831c' => { DRIVER => 'wcusb', DESCRIPTION => 'Wildcard S100U USB FXS Interface' }, - '06e6:831e' => { DRIVER => 'wcusb2', DESCRIPTION => 'Wildcard S110U USB FXS Interface' }, - '06e6:b210' => { DRIVER => 'wc_usb_phone', DESCRIPTION => 'Wildcard Phone Test driver' }, - - # from xpp_usb - 'e4e4:1130' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-8/16 no-firmware' }, - 'e4e4:1131' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-8/16 USB-firmware' }, - 'e4e4:1132' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-8/16 FPGA-firmware' }, - 'e4e4:1140' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-BRI no-firmware' }, - 'e4e4:1141' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-BRI USB-firmware' }, - 'e4e4:1142' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-BRI FPGA-firmware' }, - 'e4e4:1150' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-multi no-firmware' }, - 'e4e4:1151' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-multi USB-firmware' }, - 'e4e4:1152' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-multi FPGA-firmware' }, - 'e4e4:1160' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-modular no-firmware' }, - 'e4e4:1161' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-modular USB-firmware' }, - 'e4e4:1162' => { DRIVER => 'xpp_usb', DESCRIPTION => 'Astribank-modular FPGA-firmware' }, - ); - - -$ENV{PATH} .= ":/usr/sbin:/sbin:/usr/bin:/bin"; - -my @xbuses = Zaptel::Xpp::xbuses('SORT_CONNECTOR'); - -sub usb_sorter() { - return $a->hardware_name cmp $b->hardware_name; -} - -sub xbus_of_usb($) { - my $priv_device_name = shift; - my $dev = shift; - - my ($wanted) = grep { - defined($_->usb_devname) && - $priv_device_name eq $_->usb_devname - } @xbuses; - return $wanted; -} - -sub new($$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $self = { @_ }; - bless $self, $pack; - my $xbus = xbus_of_usb($self->priv_device_name); - if(defined $xbus) { - $self->{XBUS} = $xbus; - $self->{LOADED} = 'xpp_usb'; - } else { - $self->{XBUS} = undef; - $self->{LOADED} = undef; - } - Zaptel::Hardware::device_detected($self, - sprintf("usb:%s", $self->{PRIV_DEVICE_NAME})); - return $self; -} - -sub devices($) { - my $pack = shift || die; - my $usb_device_list = "/proc/bus/usb/devices"; - return unless (-r $usb_device_list); - - my @devices; - open(F, $usb_device_list) || die "Failed to open $usb_device_list: $!"; - local $/ = ''; - while() { - my @lines = split(/\n/); - my ($tline) = grep(/^T/, @lines); - my ($pline) = grep(/^P/, @lines); - my ($sline) = grep(/^S:.*SerialNumber=/, @lines); - my ($busnum,$devnum) = ($tline =~ /Bus=(\w+)\W.*Dev#=\s*(\w+)\W/); - my $devname = sprintf("%03d/%03d", $busnum, $devnum); - my ($vendor,$product) = ($pline =~ /Vendor=(\w+)\W.*ProdID=(\w+)\W/); - my $serial; - if(defined $sline) { - $sline =~ /SerialNumber=(.*)/; - $serial = $1; - #$serial =~ s/[[:^print:]]/_/g; - } - my $model = $usb_ids{"$vendor:$product"}; - next unless defined $model; - my $d = Zaptel::Hardware::USB->new( - IS_ASTRIBANK => ($model->{DRIVER} eq 'xpp_usb')?1:0, - BUS_TYPE => 'USB', - PRIV_DEVICE_NAME => $devname, - VENDOR => $vendor, - PRODUCT => $product, - SERIAL => $serial, - DESCRIPTION => $model->{DESCRIPTION}, - DRIVER => $model->{DRIVER}, - ); - push(@devices, $d); - } - close F; - @devices = sort usb_sorter @devices; -} - -1; diff --git a/xpp/perl_modules/Zaptel/Span.pm b/xpp/perl_modules/Zaptel/Span.pm deleted file mode 100644 index 9aceb78..0000000 --- a/xpp/perl_modules/Zaptel/Span.pm +++ /dev/null @@ -1,300 +0,0 @@ -package Zaptel::Span; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; -use Zaptel::Chans; -use Zaptel::Xpp::Xpd; - -=head1 NAME - -Zaptel::Spans - Perl interface to a Zaptel span information - -This package allows access from perl to information about a Zaptel -channel. It is part of the Zaptel Perl package. - -A span is a logical unit of Zaptel channels. Normally a port in a -digital card or a whole analog card. - -See documentation of module L for usage example. Specifically -C must be run initially. - -=head1 by_number() - -Get a span by its Zaptel span number. - -=head1 Span Properties - -=head2 num() - -The span number. - -=head2 name() - -The name field of a Zaptel span. E.g.: - - TE2/0/1 - -=head2 description() - -The description field of the span. e.g: - - "T2XXP (PCI) Card 0 Span 1" HDB3/CCS/CRC4 RED - -=head2 chans() - -The list of the channels (L objects) of this span. -In a scalar context returns the number of channels this span has. - -=head2 bchans() - -Likewise a list of bchannels (or a count in a scalar context). - -=head2 is_sync_master() - -Is this span the source of timing for Zaptel? - -=head2 type() - -Type of span, or "UNKNOWN" if could not be detected. Current known -types: - -BRI_TE, BRI_NT, E1_TE, E1_NT, J1_TE, J1_NT, T1_TE, T1_NT, FXS, FXO - -=head2 is_pri() - -Is this an E1/J1/T1 span? - -=head2 is_bri() - -Is this a BRI span? - -=head2 is_digital() - -Is this a digital (as opposed to analog) span? - -=head2 termtype() - -Set for digital spans. "TE" or "NT". Will probably be assumed to be "TE" -if there's no information pointing either way. - -=head2 coding() - -Suggested sane coding type (e.g.: "hdb3", "b8zs") for this type of span. - -=head2 framing() - -Suggested sane framing type (e.g.: "ccs", "esf") for this type of span. - -=head2 yellow(), crc4() - -Likewise, suggestions ofr the respective fields in the span= line in -zaptel.conf for this span. - -=head2 signalling() - -Suggested zapata.conf signalling for channels of this span. - -=head2 switchtype() - -Suggested zapata.conf switchtype for channels of this span. - -=head1 Note - -Most of those properties are normally used as lower-case functions, but -actually set in the module as capital-letter propeties. To look at e.g. -"signalling" is set, look for "SIGNALLING". - -=cut - -my $proc_base = "/proc/dahdi"; - -sub chans($) { - my $span = shift; - return @{$span->{CHANS}}; -} - -sub by_number($) { - my $span_number = shift; - die "Missing span number" unless defined $span_number; - my @spans = Zaptel::spans(); - - my ($span) = grep { $_->num == $span_number } @spans; - return $span; -} - -my @bri_strings = ( - 'BRI_(NT|TE)', - '(?:quad|octo)BRI PCI ISDN Card.* \[(NT|TE)\]\ ', - 'octoBRI \[(NT|TE)\] ', - 'HFC-S PCI A ISDN.* \[(NT|TE)\] ' - ); - -my @pri_strings = ( - '(E1|T1|J1)_(NT|TE)', - 'Tormenta 2 .*Quad (E1|T1)', # tor2. - 'Digium Wildcard .100P (T1|E1)/', # wct1xxp - 'ISA Tormenta Span 1', # torisa - 'TE110P T1/E1', # wcte11xp - 'Wildcard TE120P', # wcte12xp - 'Wildcard TE121', # wcte12xp - 'Wildcard TE122', # wcte12xp - 'T[24]XXP \(PCI\) Card ', # wct4xxp - ); - -our $ZAPBRI_NET = 'bri_net'; -our $ZAPBRI_CPE = 'bri_cpe'; - -our $ZAPPRI_NET = 'pri_net'; -our $ZAPPRI_CPE = 'pri_cpe'; - -sub init_proto($$) { - my $self = shift; - my $proto = shift; - - $self->{PROTO} = $proto; - if($proto eq 'E1') { - $self->{DCHAN_IDX} = 15; - $self->{BCHAN_LIST} = [ 0 .. 14, 16 .. 30 ]; - } elsif($proto eq 'T1') { - $self->{DCHAN_IDX} = 23; - $self->{BCHAN_LIST} = [ 0 .. 22 ]; - } - $self->{TYPE} = "${proto}_$self->{TERMTYPE}"; -} - -sub new($$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $num = shift or die "Missing a span number parameter\n"; - my $self = { NUM => $num }; - bless $self, $pack; - $self->{TYPE} = "UNKNOWN"; - my @xpds = Zaptel::Xpp::Xpd::xpds_by_spanno; - my $xpd = $xpds[$num]; - if(defined $xpd) { - die "Spanno mismatch: $xpd->spanno, $num" unless $xpd->spanno == $num; - $self->{XPD} = $xpd; - } - open(F, "$proc_base/$num") or die "Failed to open '$proc_base/$num\n"; - my $head = ; - chomp $head; - $self->{IS_DIGITAL} = 0; - $self->{IS_BRI} = 0; - $self->{IS_PRI} = 0; - foreach my $cardtype (@bri_strings) { - if($head =~ m/$cardtype/) { - $self->{IS_DIGITAL} = 1; - $self->{IS_BRI} = 1; - $self->{TERMTYPE} = $1; - $self->{TYPE} = "BRI_$1"; - $self->{DCHAN_IDX} = 2; - $self->{BCHAN_LIST} = [ 0, 1 ]; - last; - } - } - foreach my $cardtype (@pri_strings) { - if($head =~ m/$cardtype/) { - my @info; - - push(@info, $1) if defined $1; - push(@info, $2) if defined $2; - my ($proto) = grep(/(E1|T1|J1)/, @info); - $proto = 'UNKNOWN' unless defined $proto; - my ($termtype) = grep(/(NT|TE)/, @info); - $termtype = 'TE' unless defined $termtype; - - $self->{IS_DIGITAL} = 1; - $self->{IS_PRI} = 1; - $self->{TERMTYPE} = $termtype; - $self->init_proto($proto); - last; - } - } - die "$0: Unkown TERMTYPE [NT/TE]\n" - if $self->is_digital and !defined $self->{TERMTYPE}; - ($self->{NAME}, $self->{DESCRIPTION}) = (split(/\s+/, $head, 4))[2, 3]; - $self->{IS_ZAPTEL_SYNC_MASTER} = - ($self->{DESCRIPTION} =~ /\(MASTER\)/) ? 1 : 0; - $self->{CHANS} = []; - my @channels; - my $index = 0; - while() { - chomp; - s/^\s*//; - s/\s*$//; - next unless /\S/; - next unless /^\s*\d+/; # must be a real channel string. - my $c = Zaptel::Chans->new($self, $index, $_); - push(@channels, $c); - $index++; - } - close F; - if($self->is_pri()) { - # Check for PRI with unknown type strings - if($index == 31) { - if($self->{PROTO} eq 'UNKNOWN') { - $self->init_proto('E1'); - } elsif($self->{PROTO} ne 'E1') { - die "$index channels in a $self->{PROTO} span"; - } - } elsif($index == 24) { - if($self->{PROTO} eq 'UNKNOWN') { - $self->init_proto('T1'); # FIXME: J1? - } elsif($self->{PROTO} ne 'T1') { - die "$index channels in a $self->{PROTO} span"; - } - } - } - @channels = sort { $a->num <=> $b->num } @channels; - $self->{CHANS} = \@channels; - $self->{YELLOW} = undef; - $self->{CRC4} = undef; - if($self->is_bri()) { - $self->{CODING} = 'ami'; - $self->{DCHAN} = ($self->chans())[$self->{DCHAN_IDX}]; - $self->{BCHANS} = [ ($self->chans())[@{$self->{BCHAN_LIST}}] ]; - # Infer some info from channel name: - my $first_chan = ($self->chans())[0] || die "$0: No channels in span #$num\n"; - my $chan_fqn = $first_chan->fqn(); - if($chan_fqn =~ m(ZTHFC.*/|ztqoz.*/|XPP_BRI_.*/)) { # BRI - $self->{FRAMING} = 'ccs'; - $self->{SWITCHTYPE} = 'euroisdn'; - $self->{SIGNALLING} = ($self->{TERMTYPE} eq 'NT') ? $ZAPBRI_NET : $ZAPBRI_CPE ; - } elsif($chan_fqn =~ m(ztgsm.*/)) { # Junghanns's GSM cards. - $self->{FRAMING} = 'ccs'; - $self->{SIGNALLING} = 'gsm'; - } - } - if($self->is_pri()) { - $self->{DCHAN} = ($self->chans())[$self->{DCHAN_IDX}]; - $self->{BCHANS} = [ ($self->chans())[@{$self->{BCHAN_LIST}}] ]; - if($self->{PROTO} eq 'E1') { - $self->{CODING} = 'hdb3'; - $self->{FRAMING} = 'ccs'; - $self->{SWITCHTYPE} = 'euroisdn'; - $self->{CRC4} = 'crc4'; - } elsif($self->{PROTO} eq 'T1') { - $self->{CODING} = 'b8zs'; - $self->{FRAMING} = 'esf'; - $self->{SWITCHTYPE} = 'national'; - } else { - die "'$self->{PROTO}' unsupported yet"; - } - $self->{SIGNALLING} = ($self->{TERMTYPE} eq 'NT') ? $ZAPPRI_NET : $ZAPPRI_CPE ; - } - return $self; -} - -sub bchans($) { - my $self = shift || die; - - return @{$self->{BCHANS}}; -} - -1; diff --git a/xpp/perl_modules/Zaptel/Utils.pm b/xpp/perl_modules/Zaptel/Utils.pm deleted file mode 100644 index 8d13ad7..0000000 --- a/xpp/perl_modules/Zaptel/Utils.pm +++ /dev/null @@ -1,52 +0,0 @@ -package Zaptel::Utils; - -# Accessors (miniperl does not have Class:Accessor) -our $AUTOLOAD; -sub AUTOLOAD { - my $self = shift; - my $name = $AUTOLOAD; - $name =~ s/.*://; # strip fully-qualified portion - return if $name =~ /^[A-Z_]+$/; # ignore special methods (DESTROY) - my $key = uc($name); - my $val = shift; - if (defined $val) { - #print STDERR "set: $key = $val\n"; - return $self->{$key} = $val; - } else { - if(!exists $self->{$key}) { - #$self->xpp_dump; - #die "Trying to get uninitialized '$key'"; - } - my $val = $self->{$key}; - #print STDERR "get: $key ($val)\n"; - return $val; - } -} - -sub xpp_dump($) { - my $self = shift || die; - printf STDERR "Dump a %s\n", ref($self); - foreach my $k (sort keys %{$self}) { - my $val = $self->{$k}; - $val = '**UNDEF**' if !defined $val; - printf STDERR " %-20s %s\n", $k, $val; - } -} - -# Based on Autoloader - -sub import { - my $pkg = shift; - my $callpkg = caller; - - #print STDERR "import: $pkg, $callpkg\n"; - # - # Export symbols, but not by accident of inheritance. - # - die "Sombody inherited Zaptel::Utils" if $pkg ne 'Zaptel::Utils'; - no strict 'refs'; - *{ $callpkg . '::AUTOLOAD' } = \&AUTOLOAD; - *{ $callpkg . '::xpp_dump' } = \&xpp_dump; -} - -1; diff --git a/xpp/perl_modules/Zaptel/Xpp.pm b/xpp/perl_modules/Zaptel/Xpp.pm deleted file mode 100644 index 8b7458f..0000000 --- a/xpp/perl_modules/Zaptel/Xpp.pm +++ /dev/null @@ -1,199 +0,0 @@ -package Zaptel::Xpp; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Xpp::Xbus; - -=head1 NAME - -Zaptel::Xpp - Perl interface to the Xorcom Astribank drivers. - -=head1 SYNOPSIS - - # Listing all Astribanks: - use Zaptel::Xpp; - # scans hardware: - my @xbuses = Zaptel::Xpp::xbuses("SORT_CONNECTOR"); - for my $xbus (@xbuses) { - print $xbus->name." (".$xbus->label .", ". $xbus->connector .")\n"; - for my $xpd ($xbus->xpds) { - print " - ".$xpd->fqn,"\n"; - } - } -=cut - - -my $proc_base = "/proc/xpp"; - -# Nominal sorters for xbuses -sub by_name { - return $a->name cmp $b->name; -} - -sub by_connector { - return $a->connector cmp $b->connector; -} - -sub by_label { - my $cmp = $a->label cmp $b->label; - return $cmp if $cmp != 0; - return $a->connector cmp $b->connector; -} - -=head1 xbuses([sort_order]) - -Scans system (/proc and /sys) and returns a list of Astribank (Xbus) -objects. The optional parameter sort_order is the order in which -the Astribanks will be returns: - -=over - -=item SORT_CONNECTOR - -Sort by the connector string. For USB this defines the "path" to get to -the device through controllers, hubs etc. - -=item SORT_LABEL - -Sorts by the label of the Astribank. The label field is unique to the -Astribank. It can also be viewed through 'lsusb -v' without the drivers -loaded (the iSerial field in the Device Descriptor). - -=item SORT_NAME - -Sort by the "name". e.g: "XBUS-00". The order of Astribank names depends -on the load order, and hence may change between different runs. - -=item custom function - -Instead of using a predefined sorter, you can pass your own sorting -function. See the example sorters in the code of this module. - -=back - -=cut - -sub xbuses { - my $optsort = shift || 'SORT_CONNECTOR'; - my @xbuses; - - -d "$proc_base" or return (); - my @lines; - local $/ = "\n"; - open(F, "$proc_base/xbuses") || - die "$0: Failed to open $proc_base/xbuses: $!\n"; - @lines = ; - close F; - foreach my $line (@lines) { - chomp $line; - my ($name, @attr) = split(/\s+/, $line); - $name =~ s/://; - $name =~ /XBUS-(\d\d)/ or die "Bad XBUS number: $name"; - my $num = $1; - @attr = map { split(/=/); } @attr; - my $xbus = Zaptel::Xpp::Xbus->new(NAME => $name, NUM => $num, @attr); - push(@xbuses, $xbus); - } - my $sorter; - if($optsort eq "SORT_CONNECTOR") { - $sorter = \&by_connector; - } elsif($optsort eq "SORT_NAME") { - $sorter = \&by_name; - } elsif($optsort eq "SORT_LABEL") { - $sorter = \&by_label; - } elsif(ref($optsort) eq 'CODE') { - $sorter = $optsort; - } else { - die "Unknown optional sorter '$optsort'"; - } - @xbuses = sort $sorter @xbuses; - return @xbuses; -} - -sub xpd_of_span($) { - my $span = shift or die "Missing span parameter"; - return undef unless defined $span; - foreach my $xbus (Zaptel::Xpp::xbuses('SORT_CONNECTOR')) { - foreach my $xpd ($xbus->xpds()) { - return $xpd if $xpd->fqn eq $span->name; - } - } - return undef; -} - -=head1 sync([new_sync_source]) - -Gets (and optionally sets) the internal Astribanks synchronization -source. When used to set sync source, returns the original sync source. - -A synchronization source is a value valid writing into /proc/xpp/sync . -For more information read that file and see README.Astribank . - -=cut - -sub sync { - my $newsync = shift; - my $result; - my $newapi = 0; - - my $file = "$proc_base/sync"; - return '' unless -f $file; - # First query - open(F, "$file") or die "Failed to open $file for reading: $!"; - while() { - chomp; - /SYNC=/ and $newapi = 1; - s/#.*//; - if(/\S/) { # First non-comment line - s/^SYNC=\D*// if $newapi; - $result = $_; - last; - } - } - close F; - if(defined($newsync)) { # Now change - $newsync =~ s/.*/\U$&/; - if($newsync =~ /^(\d+)$/) { - $newsync = ($newapi)? "SYNC=$1" : "$1 0"; - } elsif($newsync ne 'ZAPTEL') { - die "Bad sync parameter '$newsync'"; - } - open(F, ">$file") or die "Failed to open $file for writing: $!"; - print F $newsync; - close(F) or die "Failed in closing $file: $!"; - } - return $result; -} - -=head1 SEE ALSO - -=over - -=item L - -Xbus (Astribank) object. - -=item L - -XPD (the rough equivalent of a Zaptel span) object. - -=item L - -Object for a line: an analog port or a time-slot in a adapter. -Equivalent of a channel in Zaptel. - -=item L - -General documentation in the master package. - -=back - -=cut - -1; diff --git a/xpp/perl_modules/Zaptel/Xpp/Line.pm b/xpp/perl_modules/Zaptel/Xpp/Line.pm deleted file mode 100644 index 2472c3b..0000000 --- a/xpp/perl_modules/Zaptel/Xpp/Line.pm +++ /dev/null @@ -1,95 +0,0 @@ -package Zaptel::Xpp::Line; -# -# Written by Oron Peled -# Copyright (C) 2008, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; - -my $proc_base = "/proc/xpp"; - -sub new($$$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $xpd = shift or die; - my $index = shift; - defined $index or die; - my $self = {}; - bless $self, $pack; - $self->{XPD} = $xpd; - $self->{INDEX} = $index; - return $self; -} - -sub blink($$) { - my $self = shift; - my $on = shift; - my $xpd = $self->xpd; - my $result; - - my $file = "$proc_base/" . $xpd->fqn . "/blink"; - die "$file is missing" unless -f $file; - # First query - open(F, "$file") or die "Failed to open $file for reading: $!"; - $result = ; - chomp $result; - close F; - if(defined($on)) { # Now change - my $onbitmask = 1 << $self->index; - my $offbitmask = $result & ~$onbitmask; - - $result = $offbitmask; - $result |= $onbitmask if $on; - open(F, ">$file") or die "Failed to open $file for writing: $!"; - print F "$result"; - if(!close(F)) { - if($! == 17) { # EEXISTS - # good - } else { - undef $result; - } - } - } - return $result; -} - -sub create_all($$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $xpd = shift || die; - my $procdir = shift || die; - local $/ = "\n"; - my @lines; - for(my $i = 0; $i < $xpd->{CHANNELS}; $i++) { - my $line = Zaptel::Xpp::Line->new($xpd, $i); - push(@lines, $line); - } - $xpd->{LINES} = \@lines; - my ($infofile) = glob "$procdir/*_info"; - die "Failed globbing '$procdir/*_info'" unless defined $infofile; - my $type = $xpd->type; - open(F, "$infofile") || die "Failed opening '$infofile': $!"; - my $battery_info = 0; - while () { - chomp; - if($type eq 'FXO') { - $battery_info = 1 if /^Battery:/; - if($battery_info && s/^\s*on\s*:\s*//) { - my @batt = split; - foreach my $l (@lines) { - die unless @batt; - my $state = shift @batt; - $l->{BATTERY} = ($state eq '+') ? 1 : 0; - } - $battery_info = 0; - die if @batt; - } - } - } - close F; -} - - -1; diff --git a/xpp/perl_modules/Zaptel/Xpp/Xbus.pm b/xpp/perl_modules/Zaptel/Xpp/Xbus.pm deleted file mode 100644 index e840f14..0000000 --- a/xpp/perl_modules/Zaptel/Xpp/Xbus.pm +++ /dev/null @@ -1,118 +0,0 @@ -package Zaptel::Xpp::Xbus; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; -use Zaptel::Xpp::Xpd; - -my $proc_base = "/proc/xpp"; - -sub xpds($) { - my $xbus = shift; - return @{$xbus->{XPDS}}; -} - -sub by_number($) { - my $busnumber = shift; - die "Missing xbus number parameter" unless defined $busnumber; - my @xbuses = Zaptel::Xpp::xbuses(); - - my ($xbus) = grep { $_->num == $busnumber } @xbuses; - return $xbus; -} - -sub by_label($) { - my $label = shift; - die "Missing xbus label parameter" unless defined $label; - my @xbuses = Zaptel::Xpp::xbuses(); - - my ($xbus) = grep { $_->label eq $label } @xbuses; - return $xbus; -} - -sub get_xpd_by_number($$) { - my $xbus = shift; - my $xpdid = shift; - die "Missing XPD id parameter" unless defined $xpdid; - my @xpds = $xbus->xpds; - my ($wanted) = grep { $_->id eq $xpdid } @xpds; - return $wanted; -} - -sub new($$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $self = {}; - bless $self, $pack; - while(@_) { - my ($k, $v) = @_; - shift; shift; - # Keys in all caps - $k = uc($k); - # Some values are in all caps as well - if($k =~ /^(STATUS)$/) { - $v = uc($v); - } - $self->{$k} = $v; - } - # backward compat for drivers without labels. - if(!defined $self->{LABEL}) { - $self->{LABEL} = '[]'; - } - $self->{LABEL} =~ s/^\[(.*)\]$/$1/ or die "$self->{NAME}: Bad label"; - # Fix badly burned labels. - $self->{LABEL} =~ s/[[:^print:]]/_/g; - $self->{NAME} or die "Missing xbus name"; - my $prefix = "$proc_base/" . $self->{NAME}; - my $usbfile = "$prefix/xpp_usb"; - if(open(F, "$usbfile")) { - my $head = ; - chomp $head; - close F; - $head =~ s/^device: +([^, ]+)/$1/i or die; - $self->{USB_DEVNAME} = $head; - } - @{$self->{XPDS}} = (); - foreach my $dir (glob "$prefix/XPD-??") { - my $xpd = Zaptel::Xpp::Xpd->new($self, $dir); - push(@{$self->{XPDS}}, $xpd); - } - @{$self->{XPDS}} = sort { $a->id <=> $b->id } @{$self->{XPDS}}; - return $self; -} - -sub pretty_xpds($) { - my $xbus = shift; - my @xpds = sort { $a->id <=> $b->id } $xbus->xpds(); - my @xpd_types = map { $_->type } @xpds; - my $last_type = ''; - my $mult = 0; - my $xpdstr = ''; - foreach my $curr (@xpd_types) { - if(!$last_type || ($curr eq $last_type)) { - $mult++; - } else { - if($mult == 1) { - $xpdstr .= "$last_type "; - } elsif($mult) { - $xpdstr .= "$last_type*$mult "; - } - $mult = 1; - } - $last_type = $curr; - } - if($mult == 1) { - $xpdstr .= "$last_type "; - } elsif($mult) { - $xpdstr .= "$last_type*$mult "; - } - $xpdstr =~ s/\s*$//; # trim trailing space - return $xpdstr; -} - -1; diff --git a/xpp/perl_modules/Zaptel/Xpp/Xpd.pm b/xpp/perl_modules/Zaptel/Xpp/Xpd.pm deleted file mode 100644 index 5087f1f..0000000 --- a/xpp/perl_modules/Zaptel/Xpp/Xpd.pm +++ /dev/null @@ -1,123 +0,0 @@ -package Zaptel::Xpp::Xpd; -# -# Written by Oron Peled -# Copyright (C) 2007, Xorcom -# This program is free software; you can redistribute and/or -# modify it under the same terms as Perl itself. -# -# $Id$ -# -use strict; -use Zaptel::Utils; -use Zaptel::Xpp; -use Zaptel::Xpp::Line; - -my $proc_base = "/proc/xpp"; - -sub blink($$) { - my $self = shift; - my $on = shift; - my $result; - - my $file = "$proc_base/" . $self->fqn . "/blink"; - die "$file is missing" unless -f $file; - # First query - open(F, "$file") or die "Failed to open $file for reading: $!"; - $result = ; - 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)?"0xFFFF":"0"; - if(!close(F)) { - if($! == 17) { # EEXISTS - # good - } else { - undef $result; - } - } - } - return $result; -} - -sub dahdi_registration($$) { - my $self = shift; - my $on = shift; - my $result; - - my $file = "$proc_base/" . $self->fqn . "/dahdi_registration"; - die "$file is missing" unless -f $file; - # First query - open(F, "$file") or die "Failed to open $file for reading: $!"; - $result = ; - 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 xpds_by_spanno() { - my @xbuses = Zaptel::Xpp::xbuses("SORT_CONNECTOR"); - my @xpds = map { $_->xpds } @xbuses; - @xpds = grep { $_->spanno } @xpds; - @xpds = sort { $a->spanno <=> $b->spanno } @xpds; - my @spanno = map { $_->spanno } @xpds; - my @idx; - @idx[@spanno] = @xpds; # The spanno is the index now - return @idx; -} - -sub new($$) { - my $pack = shift or die "Wasn't called as a class method\n"; - my $xbus = shift || die; - my $procdir = shift || die; - my $self = {}; - bless $self, $pack; - $self->{XBUS} = $xbus; - $self->{DIR} = $procdir; - local $/ = "\n"; - open(F, "$procdir/summary") || die "Missing summary file in $procdir"; - my $head = ; - 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() { - chomp; - if(s/^\s*offhook\s*:\s*//) { - my @offhook = split; - @offhook || die "No channels in '$procdir/summary'"; - $self->{CHANNELS} = @offhook; - last; - } - } - close F; - $head =~ s/^(XPD-(\d\d))\s+// || die; - $self->{ID} = $2; - $self->{FQN} = $xbus->name . "/" . $1; - $head =~ s/^.*\(// || die; - $head =~ s/\) */, / || die; - $head =~ s/\s*,\s*/,/g || die; - my ($type,$present,$span,$rest) = split(/,/, $head); - #warn "Garbage in '$procdir/summary': rest='$rest'\n" if $rest; - if($span =~ s/span\s+(\d+)//) { # since changeset:5119 - $self->{SPANNO} = $1; - } - $self->{TYPE} = $type; - $self->{IS_BRI} = ($type =~ /BRI_(NT|TE)/); - $self->{IS_PRI} = ($type =~ /[ETJ]1_(NT|TE)/); - $self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} ); - Zaptel::Xpp::Line->create_all($self, $procdir); - return $self; -} - -1; diff --git a/xpp/print_modes.c b/xpp/print_modes.c deleted file mode 100644 index 77e0e33..0000000 --- a/xpp/print_modes.c +++ /dev/null @@ -1,33 +0,0 @@ -#include - -#include "wctdm_fxomodes.h" - -int main() { - size_t i; - - for (i=0; i<(sizeof(fxo_modes)/sizeof(struct fxo_mode)); i++) { - if (fxo_modes[i].name == NULL) break; - int reg16=0, reg26=0, reg30=0, reg31=0x20; - char ring_osc[BUFSIZ]="", ring_x[BUFSIZ] = ""; - - reg16 |= (fxo_modes[i].ohs << 6); - reg16 |= (fxo_modes[i].rz << 1); - reg16 |= (fxo_modes[i].rt); - - reg26 |= (fxo_modes[i].dcv << 6); - reg26 |= (fxo_modes[i].mini << 4); - reg26 |= (fxo_modes[i].ilim << 1); - - reg30 = (fxo_modes[i].acim); - - reg31 |= (fxo_modes[i].ohs2 << 3); - - if (fxo_modes[i].ring_osc) - snprintf(ring_osc, BUFSIZ, "ring_osc=%04X", fxo_modes[i].ring_osc); - if (fxo_modes[i].ring_x) - snprintf(ring_x, BUFSIZ, "ring_x=%04X", fxo_modes[i].ring_x); - printf("%-15s\treg16=%02X\treg26=%02X\treg30=%02X\treg31=%02X\t%s\t%s\n", - fxo_modes[i].name, reg16, reg26, reg30, reg31, ring_osc, ring_x); - } - return 0; -} diff --git a/xpp/xpp.rules b/xpp/xpp.rules index d3cc226..907e08a 100644 --- a/xpp/xpp.rules +++ b/xpp/xpp.rules @@ -4,11 +4,11 @@ KERNEL=="[0-9]*", GOTO="xpp_usb_add_end" # Load firmware into the Xorcom Astribank device: SYSFS{idVendor}=="e4e4", SYSFS{idProduct}=="11[345][01]", \ - RUN+="/usr/share/zaptel/xpp_fxloader udev $sysfs{idVendor}/$sysfs{idProduct}/$sysfs{bcdDevice}" + RUN+="/usr/share/dahdi/xpp_fxloader udev $sysfs{idVendor}/$sysfs{idProduct}/$sysfs{bcdDevice}" LABEL="xpp_usb_add_end" # Hotplug hook for Astribank up/down -# By default XPP_INIT_DIR="/usr/share/zaptel" +# By default XPP_INIT_DIR="/usr/share/dahdi" KERNEL=="xbus*" RUN+="%E{XPP_INIT_DIR}/astribank_hook udev $kernel $sysfs{status} $sysfs{connector}" diff --git a/xpp/xpp_blink b/xpp/xpp_blink index 7d0d845..ff63ae7 100755 --- a/xpp/xpp_blink +++ b/xpp/xpp_blink @@ -9,12 +9,12 @@ # use strict; use File::Basename; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); } +BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } -use Zaptel; -use Zaptel::Span; -use Zaptel::Xpp; -use Zaptel::Xpp::Xbus; +use Dahdi; +use Dahdi::Span; +use Dahdi::Xpp; +use Dahdi::Xpp::Xbus; sub usage { die "Usage: $0 {on|off|bzzt} {span | chan | xpd [] | label