[dahdi-commits] tzafrir: tools/trunk r4484 - in /tools/trunk/xpp: ./ perl_modules/Dahdi/ perl...

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Sun Jun 29 11:57:49 CDT 2008


Author: tzafrir
Date: Sun Jun 29 11:57:48 2008
New Revision: 4484

URL: http://svn.digium.com/view/dahdi?view=rev&rev=4484
Log:
dahdi_genconf configuration separated from the kernel config.
* Using /etc/dahdi/genconf_parameters.
* A shiny new format (sample file included).
* xpp_fxloader is configured from /etc/dahdi/init.conf (like the init.d
  script).
* Yet some more string cleanups.

Modified:
    tools/trunk/xpp/dahdi_genconf
    tools/trunk/xpp/dahdi_hardware
    tools/trunk/xpp/genconf_parameters
    tools/trunk/xpp/perl_modules/Dahdi/Config/GenconfDefaults.pm
    tools/trunk/xpp/perl_modules/Dahdi/Span.pm
    tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
    tools/trunk/xpp/xpp_fxloader
    tools/trunk/xpp/xpp_sync

Modified: tools/trunk/xpp/dahdi_genconf
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/dahdi_genconf?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/dahdi_genconf (original)
+++ tools/trunk/xpp/dahdi_genconf Sun Jun 29 11:57:48 2008
@@ -14,6 +14,8 @@
 use Dahdi;
 use Dahdi::Xpp;
 use Dahdi::Config::GenconfDefaults;
+
+my $genconf_defaults;
 
 my %default_context = (
 	FXO	=> 'from-pstn',
@@ -61,6 +63,7 @@
 	OUT	=> "fxo_{fxs_default_start}",
 	);
 
+my $file = '';
 my $base_exten = 4000;
 my $fxs_immediate = 'no';
 my $lc_country = 'us';
@@ -68,8 +71,10 @@
 my $defaultzone = $lc_country;
 my $bri_sig_style = 'bri_ptmp';
 my $brint_overlap = 'no';
+my $pri_termtype = 'SPAN/* TE';
 
 my %dahdi_default_vars = (
+		GENCONF_FILE		=> \$file,
 		base_exten		=> \$base_exten,
 		fxs_immediate		=> \$fxs_immediate,
 		fxs_default_start	=> \$fxs_default_start,
@@ -87,8 +92,9 @@
 						\$default_group{OUT},
 					],
 		group_lines		=> \$default_group{FXO},
-		DAHDI_BRI_SIGNALLING	=> \$bri_sig_style,
+		bri_sig_style		=> \$bri_sig_style,
 		brint_overlap		=> \$brint_overlap,
+		pri_termtype		=> \$pri_termtype,
 		);
 
 sub map_dahdi_defaults {
@@ -110,6 +116,7 @@
 		}
 		foreach my $v (@vars) {
 			$$v = $val;
+			#printf STDERR "%-20s %s\n", $v, $val;
 		}
 	}
 }
@@ -217,7 +224,7 @@
 	print <<"HEAD";
 # Dahdi Configuration File
 #
-# This file is parsed by the Dahdi Configurator, ztcfg
+# This file is parsed by the Dahdi Configurator, dahdi_cfg
 #
 HEAD
 	foreach my $span (@spans) {
@@ -530,9 +537,15 @@
 
 sub set_defaults {
 	# Source default files
-	my ($default_file, %source_defaults) =
-		Dahdi::Config::GenconfDefaults::source_vars(keys(%dahdi_default_vars));
-	map_dahdi_defaults(%source_defaults);
+	my $default_file = $ENV{GENCONF_PARAMETERS} || "/etc/dahdi/genconf_parameters";
+	$genconf_defaults = Dahdi::Config::GenconfDefaults->new($default_file);
+	#$genconf_defaults->dump;
+	map_dahdi_defaults(%$genconf_defaults);
+	foreach my $span (@spans) {
+		if($span->is_pri) {
+			$span->pri_set_fromconfig($genconf_defaults);
+		}
+	}
 	# Fixups
 	foreach my $val (values %default_dahdi_signalling, values %default_chan_dahdi_signalling) {
 		$val =~ s/{fxs_default_start}/$fxs_default_start/g;
@@ -581,7 +594,7 @@
 
 =item dahdi - /etc/dahdi/system.conf
 
-Configuration for ztcfg(1). It's location may be overriden by the
+Configuration for dahdi_cfg(1). It's location may be overriden by the
 environment variable DAHDI_CONF_FILE.
 
 =item chan_dahdi - /etc/asterisk/dahdi-channels.conf

Modified: tools/trunk/xpp/dahdi_hardware
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/dahdi_hardware?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/dahdi_hardware (original)
+++ tools/trunk/xpp/dahdi_hardware Sun Jun 29 11:57:48 2008
@@ -36,7 +36,7 @@
 	my $connector = ($xbus->status eq 'CONNECTED') ? $xbus->connector : "MISSING";
 	printf " LABEL=%-20s CONNECTOR=%-20s\n", $label, $connector;
 	foreach my $xpd (@xpds) {
-		my $reg = $xpd->zt_registration;
+		my $reg = $xpd->dahdi_registration;
 		my $span;
 		my $spanstr;
 		if($reg && @spans) {

Modified: tools/trunk/xpp/genconf_parameters
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/genconf_parameters?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/genconf_parameters (original)
+++ tools/trunk/xpp/genconf_parameters Sun Jun 29 11:57:48 2008
@@ -4,18 +4,38 @@
 # This file contains parameters that affect the
 # dahdi_genconf configurator generator.
 #
-base_exten=4000
-fxs_immediate=no
-fxs_default_start=ks
-lc_country=il
+# Syntax:
+# 	* A comment from '#' to end of line
+# 	* Blank lines ignored
+# 	* Whitespace at end of line trimmed
+# 	* Single valued items:
+# 	     key <whitespaces...> value
+# 	* List valued items:
+# 	     key
+# 	     <whitespaces...>value1
+# 	     <whitespaces...>value2
+# 	     ...
+#
 
-#context_lines=
-#context_phones=
-#context_input=
-#context_output=
+#base_exten		4000
+#fxs_immediate		no
+#fxs_default_start	ks
+#lc_country		il
 
-#group_phones=
-#group_lines=
+#context_lines		from-pstn
+#context_phones		from-internal
+#context_input		astbank-input
+#context_output		astbank-output
 
-#brint_overlap=
-bri_sig_style=bri_ptmp
+#group_phones		0
+#group_lines		5
+
+#brint_overlap
+#bri_sig_style		bri_ptmp
+
+# pri_types contains a list of settings:
+# Currently the only setting is for TE or NT (the default is TE)
+#
+#pri_termtype
+#	SPAN/2		NT
+#	SPAN/4		NT

Modified: tools/trunk/xpp/perl_modules/Dahdi/Config/GenconfDefaults.pm
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Config/GenconfDefaults.pm?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Config/GenconfDefaults.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Config/GenconfDefaults.pm Sun Jun 29 11:57:48 2008
@@ -9,31 +9,54 @@
 #
 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;
+sub new($$) {
+	my $pack = shift || die;
+	my $cfg_file = shift || die;
+	my $self = { GENCONF_FILE => $cfg_file };
+	bless $self, $pack;
+	open(F, $cfg_file) || die "$0: Cannot read '$cfg_file': $!\n";
+	my $array_key;
+	while(<F>) {
+		my ($key, $val);
+		chomp;
+		s/#.*$//;
+		s/\s+$//;	# trim tail whitespace
+		next unless /\S/;
+		if(defined $array_key && /^\s+/) {
+			s/^\s+//;	# trim beginning whitespace
+			push(@{$self->{$array_key}}, $_);
+			next; 
+		}
+		undef $array_key;
+		($key, $val) = split(/\s+/, $_, 2);
+		$key = lc($key);
+		if(! defined $val) {
+			$array_key = $key;
+			next;
+		}
+		die "$cfg_file:$.: Duplicate key '$key'\n", if exists $self->{$key};
+		$self->{$key} = $val;
 	}
-	return %vars;
+	close F;
+	return $self;
 }
 
-sub source_vars {
-	my @vars = @_;
-	my $default_file = $ENV{GENCONF_PARAMETERS} || "/etc/dahdi/genconf_parameters";
-	if (! -r $default_file) {
-		return ("", ());
+sub dump($) {
+	my $self = shift || die;
+	foreach my $k (sort keys %$self) {
+		my $val = $self->{$k};
+		my $ref = ref $val;
+		if($ref eq '') {
+			printf STDERR "%-20s %s\n", $k, $val;
+		} elsif($ref eq 'ARRAY') {
+			printf STDERR "%s\n", $k;
+			foreach my $v (@{$val}) {
+				printf STDERR "\t%s\n", $v;
+			}
+		} else {
+			printf STDERR "%-20s (%s) %s\n", $k, $ref, $val;
+		}
 	}
-	my %vars = do_source($default_file, @vars);
-	return ($default_file, %vars);
 }
 
 1;

Modified: tools/trunk/xpp/perl_modules/Dahdi/Span.pm
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Span.pm?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Span.pm Sun Jun 29 11:57:48 2008
@@ -137,7 +137,7 @@
 		);
 
 my @pri_strings = (
-		'(E1|T1|J1)_(NT|TE)',
+		'(E1|T1|J1)',
 		'Tormenta 2 .*Quad (E1|T1)',       # tor2.
 		'Digium Wildcard .100P (T1|E1)/', # wct1xxp
 		'ISA Tormenta Span 1',	           # torisa
@@ -166,7 +166,6 @@
 		$self->{DCHAN_IDX} = 23;
 		$self->{BCHAN_LIST} = [ 0 .. 22 ];
 	}
-	$self->{TYPE} = "${proto}_$self->{TERMTYPE}";
 }
 
 sub new($$) {
@@ -207,7 +206,7 @@
 			my ($proto) = grep(/(E1|T1|J1)/, @info);
 			$proto = 'UNKNOWN' unless defined $proto;
 			my ($termtype) = grep(/(NT|TE)/, @info);
-			$termtype = 'TE' unless defined $termtype;
+			$termtype = 'UNKNOWN' unless defined $termtype;
 
 			$self->{IS_DIGITAL} = 1;
 			$self->{IS_PRI} = 1;
@@ -216,8 +215,6 @@
 			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;
@@ -286,7 +283,6 @@
 		} else {
 			die "'$self->{PROTO}' unsupported yet";
 		}
-		$self->{SIGNALLING} = ($self->{TERMTYPE} eq 'NT') ? $DAHDI_PRI_NET : $DAHDI_PRI_CPE ;
 	}
 	return $self;
 }
@@ -297,4 +293,57 @@
 	return @{$self->{BCHANS}};
 }
 
+sub set_termtype($$) {
+	my $span = shift || die;
+	my $termtype = shift || die;
+	$span->{TERMTYPE} = $termtype;
+	$span->{SIGNALLING} = ($termtype eq 'NT') ? $DAHDI_PRI_NET : $DAHDI_PRI_CPE ;
+	$span->{TYPE} = $span->proto . "_$termtype";
+}
+
+sub pri_set_fromconfig($$) {
+	my $span = shift || die;
+	my $genconf = shift || die;
+	my $name = $span->name;
+#	if(defined $termtype) {
+#		die "Termtype for $name already defined as $termtype\n";
+#	}
+	my $pri_termtype = $genconf->{pri_termtype};
+	my @pri_specs;
+	if(defined $pri_termtype) {
+		@pri_specs = @{$pri_termtype};
+	}
+	push(@pri_specs , 'SPAN/* TE');		# Default
+	my @patlist = ( "SPAN/" . $span->num );
+	my ($xbus_name, $xpd_name) = ($name =~ m|(XBUS-\d+)/(XPD-\d+)|);
+	if(defined $xbus_name) {
+		push(@patlist, "NUM/$xbus_name/$xpd_name");
+#		push(@patlist, "CONNECTOR/$ENV{XBUS_CONNECTOR}/$xpd_name");
+	}
+	#print STDERR "PATLIST=@patlist\n";
+	my $match_termtype;
+SPEC:
+	for(my $i = 0; $i < @pri_specs; $i++) {
+		my $spec = $pri_specs[$i];
+		#print STDERR "spec: $spec\n";
+		my ($match, $termtype) = split(/\s+/, $spec);
+		next unless defined $match and defined $termtype;
+		# Convert "globs" to regex
+		$match =~ s/\*/.*/g;
+		$match =~ s/\?/./g;
+		#print STDERR "match: $match\n";
+		foreach my $pattern (@patlist) {
+			#print STDERR "testmatch: $pattern =~ $match\n";
+			if($pattern =~ $match) {
+				#print STDERR "$xpd_name: MATCH '$pattern' ~ '$match' termtype=$termtype\n";
+				$match_termtype = $termtype;
+				last SPEC;
+			}
+		}
+	}
+	die "Unknown pri_termtype" unless defined $match_termtype;
+	$span->set_termtype($match_termtype);
+}
+
+
 1;

Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm Sun Jun 29 11:57:48 2008
@@ -114,7 +114,7 @@
 	}
 	$self->{TYPE} = $type;
 	$self->{IS_BRI} = ($type =~ /BRI_(NT|TE)/);
-	$self->{IS_PRI} = ($type =~ /[ETJ]1_(NT|TE)/);
+	$self->{IS_PRI} = ($type =~ /[ETJ]1/);
 	$self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} );
 	Dahdi::Xpp::Line->create_all($self, $procdir);
 	return $self;

Modified: tools/trunk/xpp/xpp_fxloader
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/xpp_fxloader?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/xpp_fxloader (original)
+++ tools/trunk/xpp/xpp_fxloader Sun Jun 29 11:57:48 2008
@@ -4,17 +4,17 @@
 #
 # This script can be run manually or from hotplug/udev.
 #
-# Firmware files should be located in $FIRMWARE_DIR which defaults:
+# Firmware files should be located in $XPP_FIRMWARE_DIR which defaults:
 # 	1. /usr/share/dahdi
-#	2. Can be overidden by setting $FIRMWARE_DIR in the environment
-#	3. Can be overidden by setting $FIRMWARE_DIR in /etc/default/zaptel
+#	2. Can be overidden by setting $XPP_FIRMWARE_DIR in the environment
+#	3. Can be overidden by setting $XPP_FIRMWARE_DIR in /etc/dahdi/init.conf
 #
 # Manual Run
 # ##########
 #
 #   path/to/xpp_fxloader load
 #
-# Make sure the firmware files are in $FIRMWARE_DIR
+# Make sure the firmware files are in $XPP_FIRMWARE_DIR
 #
 # UDEV Installation
 # #################
@@ -53,19 +53,8 @@
 export PATH
 
 me=`basename $0`
-DEBIAN_DEFAULTS="/etc/default/zaptel"
-REDHAT_DEFAULTS="/etc/sysconfig/zaptel"
-
+DEFAULTS="/etc/dahdi/init.conf"
 status_fd=3
-
-if [ -r "$DEBIAN_DEFAULTS" -a -r "$REDHAT_DEFAULTS" ]; then
-	echo 1>&2 "$0: Both '$DEBIAN_DEFAULTS' and '$REDHAT_DEFAULTS' exist"
-	exit 1
-elif [ -r "$DEBIAN_DEFAULTS" ]; then
-	DEFAULTS="$DEBIAN_DEFAULTS"
-elif [ -r "$REDHAT_DEFAULTS" ]; then
-	DEFAULTS="$REDHAT_DEFAULTS"
-fi
 
 if [ -t 2 ]; then
 	LOGGER="logger -i -t '$me' -s"
@@ -77,9 +66,9 @@
 DEVUSB_PREFIX=/dev/bus/usb
 USB_PREFIX=
 
-FIRMWARE_DIR="${FIRMWARE_DIR:-/usr/share/dahdi}"
-
-FIRM_FXS=$FIRMWARE_DIR/FPGA_FXS.hex
+XPP_FIRMWARE_DIR="${XPP_FIRMWARE_DIR:-/usr/share/dahdi}"
+
+FIRM_FXS=$XPP_FIRMWARE_DIR/FPGA_FXS.hex
 
 FPGA_LOAD=${FPGA_LOAD:-/usr/sbin/fpga_load}
 USB_FW="${USB_FW:-USB_FW.hex}"
@@ -127,8 +116,8 @@
   devices=`find_dev $v_id $p_id`
   for dev in $devices
   do
-    $LOGGER "USB Firmware $FIRMWARE_DIR/$fw into $dev"
-    do_fxload -D $dev -I $FIRMWARE_DIR/$fw || exit 1
+    $LOGGER "USB Firmware $XPP_FIRMWARE_DIR/$fw into $dev"
+    do_fxload -D $dev -I $XPP_FIRMWARE_DIR/$fw || exit 1
   done
 }
 
@@ -146,9 +135,9 @@
 	$LOGGER "FPGA Firmware into $dev"
 	sleep_if_race
 	(
-		$FPGA_LOAD -D "$dev" -I "$FIRMWARE_DIR/$fw" -i
+		$FPGA_LOAD -D "$dev" -I "$XPP_FIRMWARE_DIR/$fw" -i
 		echo $? >$status_fd
-	)>| $LOGGER
+	) | $LOGGER
 	status=`cat <$status_fd`
 	if [ "$status" != 0 ]; then
 		echo "fpga_load failed with status $status" | $LOGGER
@@ -280,15 +269,15 @@
 	prod_id=`echo "$PRODUCT" | cut -d/ -f2`
 	case "$PRODUCT" in
 	e4e4/11[345]0/*)
-		FIRM_USB="$FIRMWARE_DIR/$USB_FW"
+		FIRM_USB="$XPP_FIRMWARE_DIR/$USB_FW"
 		$LOGGER "Loading firmware '$FIRM_USB' into '$DEVICE'"
 		do_fxload -D "$DEVICE" -I "$FIRM_USB"
 		;;
 	e4e4/11[345]1/*)
 		if [ "$prod_id" = 1131 ]; then
-			FIRM_FPGA="$FIRMWARE_DIR/FPGA_FXS.hex"	# Legacy
+			FIRM_FPGA="$XPP_FIRMWARE_DIR/FPGA_FXS.hex"	# Legacy
 		else
-			FIRM_FPGA="$FIRMWARE_DIR/FPGA_$prod_id.hex"
+			FIRM_FPGA="$XPP_FIRMWARE_DIR/FPGA_$prod_id.hex"
 		fi
 		sleep_if_race
 		$FPGA_LOAD -D "$DEVICE" -I "$FIRM_FPGA" 2>&1 >/dev/null | $LOGGER

Modified: tools/trunk/xpp/xpp_sync
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/xpp_sync?view=diff&rev=4484&r1=4483&r2=4484
==============================================================================
--- tools/trunk/xpp/xpp_sync (original)
+++ tools/trunk/xpp/xpp_sync Sun Jun 29 11:57:48 2008
@@ -207,11 +207,10 @@
 it is the first on the list. It is also the actual syncer, as we can see
 from the '+' beside it.
 
-xpp_sync is normally called from both the dahdi init.d script and the 
-the Astribank udev script. The parameter it is called with defaults to 
+xpp_sync is normally called from the dahdi init.d script.
+The parameter it is called with defaults to 
 I<auto>, but it is possible to override that parameter (e.g: set it to
-I<dahdi>) through the value of XPP_SYNC in either /etc/defualt/zaptel
-or /etc/sysconfig/zaptel .
+I<dahdi>) through the value of XPP_SYNC in /etc/dahdi/init.conf .
 
 =head1 FILES
 




More information about the dahdi-commits mailing list