[zaptel-commits] tzafrir: branch 1.2 r1495 -
/branches/1.2/xpp/utils/genzaptelconf
zaptel-commits at lists.digium.com
zaptel-commits at lists.digium.com
Mon Oct 2 21:49:20 MST 2006
Author: tzafrir
Date: Mon Oct 2 23:49:19 2006
New Revision: 1495
URL: http://svn.digium.com/view/zaptel?rev=1495&view=rev
Log:
* run config function (genconf) in a single pass. Bumped version to 0.5.6 .
* E1 spans should not be configured as "national". TODO: find a better default
* Add support for Sangoma A102 (Hopefully also all A10x) PRI cards:
-d won't work, but will configure existing spans.
* Better comments in genconf()
* Removing update_extensions_defs: cleaning temporary files is only done once.
Modified:
branches/1.2/xpp/utils/genzaptelconf
Modified: branches/1.2/xpp/utils/genzaptelconf
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/utils/genzaptelconf?rev=1495&r1=1494&r2=1495&view=diff
==============================================================================
--- branches/1.2/xpp/utils/genzaptelconf (original)
+++ branches/1.2/xpp/utils/genzaptelconf Mon Oct 2 23:49:19 2006
@@ -34,7 +34,7 @@
# (redhat/centos)
# /etc/default/zaptel may override the following variables
-VERSION=0.5.5
+VERSION=0.5.6
rcsid='$Id$'
lc_country=us
base_exten=6000
@@ -67,10 +67,10 @@
# how long to wait for /dev/zap/ctl to appear? (seconds)
DEVZAP_TIMEOUT=${DEVZAP_TIMEOUT:-20}
ZTCFG=${ZTCFG:-/sbin/ztcfg}
-ASTERISK_INIT_SCRIPT=${ASTERISK_INIT_SCRIPT:-/etc/init.d/asterisk}
-
-# a temporary directory. Created when the switch -r is parsed on getopts
-# and deleted in the end on update_extensions_defs
+
+# a temporary directory to store whatever we need to remember.
+#
+# The main loop of genconf is run in a sub-process.
tmp_dir=
# A list of all modules:
@@ -88,7 +88,7 @@
if [ -x /usr/sbin/ztcfg ]; then
ZTCFG=/usr/sbin/ztcfg
else
- echo "ztcfg is not on found, do you have zaptel properly installed?"
+ echo >&2 "ztcfg is not on found, do you have zaptel properly installed?"
exit 1;
fi
fi
@@ -106,6 +106,8 @@
verbose=no
do_restart=yes
fxsdisable=no
+
+span_te_timing_counter=1
die() {
echo "$@" >&2
@@ -185,11 +187,6 @@
fi
}
-update_extensions_defs() {
- # cleaning up the temp dir
- if [ -d "$tmp_dir" ]; then rm -rf "$tmp_dir"; fi
-}
-
zap_reg_xpp() {
@@ -265,19 +262,19 @@
then method=ls
fi
case "$mode" in
- zaptel)
+ list) echo $chan $sig $astbanktype;;
+ files)
# sadly, both input ports and output ports go into the same span as
# the FXS ports. Thus we need to separate between them. See also
# the zapata.conf section:
- if [ "$astbank_type" != '' ]; then echo "# astbanktype: $astbank_type"; fi
- echo "${sig}$method=$chan"
- ;;
- list) echo $chan $sig $astbanktype;;
- zapata)
+ if [ "$astbank_type" != '' ];
+ then echo "# astbanktype: $astbank_type" >>$zaptel_file;
+ fi
+ echo "${sig}$method=$chan" >>$zaptel_file
# zap2amp will rewrite those from zaptel.conf and hints there
- if [ "$fxsdisable" = 'yes' ] && [ $sig = 'fxo' ]; then return; fi
+ if [ "$fxsdisable" = 'yes' ] && [ "$sig" = 'fxo' ]; then return; fi
- echo "signalling=${sig}_$method"
+ echo "signalling=${sig}_$method" >>$zapata_file
if [ "$sig" = 'fxo' ]
then
# to preconfigure channel 1's extension to 550, set
@@ -303,59 +300,59 @@
else # use the pre-configured extension number
vmbox=$cfg_vmbox
fi
- echo "callerid=\"Channel $chan\" <$exten>"
- echo "mailbox=$exten"
+ echo "callerid=\"Channel $chan\" <$exten>" >> $zapata_file
+ echo "mailbox=$exten" >> $zapata_file
if [ "$group_manual" != "yes" ]
then
- echo "group=$group_phones"
+ echo "group=$group_phones" >> $zapata_file
fi
if [ "$context_manual" != "yes" ]
then
if [ "$astbank_type" != '' ];
then
context_var_name=context_$astbank_type
- echo context=${!context_var_name}
+ echo context=${!context_var_name} >> $zapata_file
else
- echo "context=$context_phones"
+ echo "context=$context_phones" >> $zapata_file
fi
fi
else # this is an FXO (trunk/phone: FXO signalling)
# we have may have set it. So reset it:
- echo "callerid=asreceived"
- echo "mailbox="
+ echo "callerid=asreceived" >> $zapata_file
+ echo "mailbox=" >> $zapata_file
if [ "$group_manual" != "yes" ]
then
- echo "group=$group_lines"
+ echo "group=$group_lines" >> $zapata_file
fi
if [ "$context_manual" != "yes" ]
then
- echo "context=$context_lines"
+ echo "context=$context_lines" >> $zapata_file
fi
if [ "$lc_country" = 'uk' ]
then
- echo "cidsignalling=v23"
+ echo "cidsignalling=v23" >> $zapata_file
case $line in
- *WCFXO*) echo "cidstart=history";;
- *) echo "cidstart=polarity";; #a TDM400
+ *WCFXO*) echo "cidstart=history" >> $zapata_file;;
+ *) echo "cidstart=polarity" >> $zapata_file;;
esac
fi
- echo ";;; line=\"$line\""
+ echo ";;; line=\"$line\"" >> $zapata_file
# if kewlstart is not used, busydetect has to be employed:
if [ "$method" = 'ls' ]
- then echo 'busydetect=yes'
- else echo 'busydetect=no'
+ then echo 'busydetect=yes' >> $zapata_file
+ else echo 'busydetect=no' >> $zapata_file
fi
fi
if [ "$set_immediate" = 'yes' ]
then
if [ "$astbank_type" = 'input' ]
- then echo 'immediate=yes'
- else echo 'immediate=no'
+ then echo 'immediate=yes' >> $zapata_file
+ else echo 'immediate=no' >> $zapata_file
fi
fi
- echo "channel => $chan"
- echo ""
+ echo "channel => $chan" >> $zapata_file
+ echo "" >> $zapata_file
# Keep a note of what channels we have identified
say "DEBUG: adding to channels list: channel: $chan, sig: $sig"
@@ -565,8 +562,10 @@
case "$mode" in
- zaptel)
- cat <<EOF
+ files)
+ local zaptel_file=`mktemp -t genzaptelconf-zaptel-XXXXXX`
+ local zapata_file=`mktemp -t genzaptelconf-zapata-XXXXXX`
+ cat <<EOF >$zaptel_file
# Autogenerated by $0 -- do not hand edit
# Zaptel Configuration File
#
@@ -576,9 +575,7 @@
# It must be in the module loading order
EOF
- ;;
- zapata)
- cat <<EOF
+ cat <<EOF >$zapata_file
; Autogenerated by $0 -- do not hand edit
; Zaptel Channels Configurations (zapata.conf)
;
@@ -596,9 +593,6 @@
#
# The '<(command)' syntax creates a temporary file whose content is is the
# output of 'command'.
- #
- # This approach failed with the T1 card we have: the read operation simply
- # hung.
#
# Another problem with such an approach is how to include an existing
# configuration file. For instance: how to include some default settings.
@@ -611,18 +605,21 @@
# the first line is the title line. It states the model name
# the second line is empty
title=`head -n 1 $procfile`
- echo ""
- # stuff that needs to be remembered accross lines (for PRI support)
- echo "$rem_char $title"
+ # stuff that needs to be remembered accross lines (for PRI/BRI support)
+ echo "" >>$zaptel_file
+ echo "# $title" >>$zaptel_file
+ echo "" >>$zapata_file
+ echo "; $title" >>$zapata_file
echo '-1' >$tmp_dir/span_begin
echo '-1' >$tmp_dir/span_end
- echo '1' >$tmp_dir/span_timing
+ echo '0' >$tmp_dir/span_timing
echo '1' >$tmp_dir/span_lbo
echo '' >$tmp_dir/span_framing
echo 'ami' >$tmp_dir/span_coding
echo '' >$tmp_dir/span_switchtype
echo '' >$tmp_dir/span_signalling
+ # Check if ZapBRI cards are in TE or NT mode
if echo $title | egrep -q '((quad|octo)BRI PCI ISDN Card.* \[NT\]\ |octoBRI \[NT\] |HFC-S PCI A ISDN.* \[NT\] )'
then
echo 'nt' >$tmp_dir/span_termtype
@@ -640,6 +637,7 @@
chan_num=`echo $line |awk '{print $1}'`
case "$line" in
*WCTDM/*|*/WRTDM/*|*OPVXA1200/*)
+ # TDM400P/2400P and similar cards (Sangoma A200, OpenVox A1200)
# this can be either FXS or FXO
maybe_fxs=0
maybe_fxo=0
@@ -659,6 +657,7 @@
if [ $maybe_fxo = 1 ]; then print_pattern $chan_num fxs $mode; fi
;;
*WCFXO/*)
+ # X100P
print_pattern $chan_num fxs $mode || \
echo "$rem_char channel $chan_num, WCFXO, inactive."
;;
@@ -666,39 +665,56 @@
print_pattern $chan_num fxo $mode
;;
*XPP_FXO/*)
+ # Astribank FXO span
print_pattern $chan_num fxs $mode
;;
*XPP_FXS/*)
+ # Astribank FXS span (regular port)
print_pattern $chan_num fxo $mode
;;
*XPP_OUT/*)
+ # Astribank FXS span (output port)
print_pattern -a output $chan_num fxo $mode
;;
*XPP_IN/*)
+ # Astribank FXS span (input port)
print_pattern -a input $chan_num fxo $mode
;;
- *ZTHFC*/*|*ztqoz*/*|*ztgsm/*|*TE4/*|*TE2/*|*WCT1/*|*Tor2/*|*TorISA/*) # should also be used for other PRI channels
+ *ZTHFC*/*|*ztqoz*/*|*ztgsm/*|*TE[24]/*|*WCT1/*|*Tor2/*|*TorISA/*|*XPP_BRI_*/*|*WP[TE]1/*)
+ # PRI/BRI channel
+ # Rather than identifying cards by the header line, we identify them by the channel names
+ # This is shorter. This also allows us to count the channel numbers and check if a PRI
+ # card is E1 or T1.
if [ "`cat $tmp_dir/span_begin`" = "-1" ]
then
echo $chan_num >$tmp_dir/span_begin
echo $span_num >$tmp_dir/span_num
+ # The Astribank channels provide the information of TE/NT in the channel name. So
+ # why not use it?
case "$line" in
- *ZTHFC*/*|*ztqoz*/*)
+ *XPP_BRI_TE/*) echo 'te' >$tmp_dir/span_termtype;;
+ *XPP_BRI_NT/*) echo 'nt' >$tmp_dir/span_termtype;;
+ esac
+ case "$line" in
+ *ZTHFC*/*|*ztqoz*/*|*XPP_BRI_*/*)
+ # BRI channel
echo 'ccs' >$tmp_dir/span_framing
echo 'euroisdn' >$tmp_dir/span_switchtype
if [ "`cat $tmp_dir/span_termtype`" = 'nt' 2>/dev/null ]
then
- echo 'bri_net' >$tmp_dir/span_signalling
+ echo 'bri_net' >$tmp_dir/span_signalling
else
echo 'bri_cpe' >$tmp_dir/span_signalling
fi
;;
*ztgsm*/*)
+ # Junghanns's GSM cards.
echo 'ccs' >$tmp_dir/span_framing
# what switch type? Any meaning to it?
echo 'gsm' >$tmp_dir/span_signalling
;;
- *TE4/*|*TE2/*|*WCT1/*|*Tor2/*|*TorISA/*)
+ *TE[24]/*|*WCT1/*|*Tor2/*|*TorISA/*|*WP[TE]1/*)
+ # PRI span (E1/T1)
echo 'esf' >$tmp_dir/span_framing
echo 'b8zs' >$tmp_dir/span_coding
echo 'national' >$tmp_dir/span_switchtype
@@ -735,9 +751,18 @@
echo $chan_num >$tmp_dir/span_end
;;
'') ;; # Empty line (after span header)
- *) echo "$rem_char ??: $line";;
+ *)
+ case "$mode" in
+ list) echo "# ??: $line";;
+ files)
+ echo "# ??: $line" >>$zaptel_file
+ echo "; ??: $line" >>$zaptel_file
+ esac
+ ;;
esac
done
+ # end of part in sub-process.
+
if [ "`cat $tmp_dir/span_begin`" != -1 ]
then # write PRI span ocnfig:
# read files to variables:
@@ -755,52 +780,65 @@
bchans="$span_begin-$(($span_end-1))"
;;
31) #E1
- dchan="$(($span_begin+15))"
+ dchan="$(($span_begin+15))"
bchans="$span_begin-$(($span_begin+14)),$(($span_begin+16))-$span_end"
+ if [ "$span_switchtype" = 'national' ]; then
+ span_framing=ccs
+ span_coding=hdb3
+ span_switchtype=euroisdn
+ fi
+ ;;
+ esac
+ # Let's assume that a TE span should get the clock from the remote unit,
+ # and NT spans should provide timing. Just as a sane default.
+ # If we have several TE spans, the first will have priority 1,
+ # second: 2, etc.
+ case "$span_signalling" in *_cpe*)
+ span_timing=$span_te_timing_counter
+ span_te_timing_counter=$(($span_te_timing_counter + 1))
;;
esac
case "$mode" in
- zaptel)
- echo span=$span_num,$span_timing,$span_lbo,$span_framing,$span_coding$span_yellow
+ files)
+ echo span=$span_num,$span_timing,$span_lbo,$span_framing,$span_coding$span_yellow >> $zaptel_file
if [ "$span_termtype" != '' ]
- then echo "# termtype: $span_termtype"
+ then echo "# termtype: $span_termtype" >>$zaptel_file
fi
- echo bchan=$bchans
- echo dchan=$dchan
- ;;
- zapata)
+ echo bchan=$bchans >>$zaptel_file
+ echo dchan=$dchan >>$zaptel_file
+
if [ "$span_termtype" != '' ]
then
# an ISDN card's span that we know if it is in NT mode or TE mode.
# NT is the same as FXS for us and TE is the same as FXO
if [ "$span_termtype" = 'nt' ]
then
- echo "callerid=\"Channels $span_begin - $span_end\" <$span_begin>"
+ echo "callerid=\"Channels $span_begin - $span_end\" <$span_begin>" >> $zapata_file
#echo "mailbox=$exten"
if [ "$group_manual" != "yes" ]
then
- echo "group=$group_phones"
+ echo "group=$group_phones" >> $zapata_file
fi
if [ "$context_manual" != "yes" ]
then
- echo "context=$context_phones"
+ echo "context=$context_phones" >> $zapata_file
fi
else # we have may have set it. So reset it:
echo "callerid=asreceived"
#echo "mailbox="
if [ "$group_manual" != "yes" ]
then
- echo "group=$group_lines"
+ echo "group=$group_lines" >> $zapata_file
fi
if [ "$context_manual" != "yes" ]
then
- echo "context=$context_lines"
+ echo "context=$context_lines" >> $zapata_file
fi
fi
fi
- echo "switchtype = $span_switchtype"
- echo "signalling = $span_signalling"
- echo "channel => $bchans"
+ echo "switchtype = $span_switchtype" >> $zapata_file
+ echo "signalling = $span_signalling" >> $zapata_file
+ echo "channel => $bchans" >> $zapata_file
;;
list)
echo BRI/PRI: chans: $bchans, control: $dchan
@@ -809,21 +847,23 @@
fi
done
- if [ "$mode" = 'zaptel' ]
+ if [ "$mode" = 'files' ]
then
- cat <<EOF
+ cat <<EOF >> ${zaptel_file}
# Global data
+loadzone = $loadzone
+defaultzone = $defaultzone
EOF
- echo "loadzone = $loadzone"
- echo "defaultzone = $defaultzone"
fi
- if [ "$mode" = 'zapata' ] || [ "$mode" = 'list' ]
- then
- update_extensions_defs
- fi
+ mv ${ZAPCONF_FILE} ${ZAPCONF_FILE}.bak
+ mv $zaptel_file ${ZAPCONF_FILE}
+ mv ${ZAPATA_FILE} ${ZAPATA_FILE}.bak
+ mv $zapata_file ${ZAPATA_FILE}
+ # cleaning up the temp dir
+ if [ -d "$tmp_dir" ]; then rm -rf "$tmp_dir"; fi
}
while getopts 'c:de:Fhlm:MRsuv' arg
@@ -874,7 +914,7 @@
# make sure asterisk is not in our way
if [ "$force_stop_ast" = 'yes' ]
then
- $ASTERISK_INIT_SCRIPT stop 1>&2
+ /etc/init.d/asterisk stop 1>&2
else
# if asterisk is running and we wanted to detect modules
# or simply to unload modules, asterisk needs to go away.
@@ -904,13 +944,9 @@
else
zap_reg_xpp
check_for_astribank
- say "Generating '${ZAPCONF_FILE}'"
- mv "${ZAPCONF_FILE}" "${ZAPCONF_FILE}.bak"
wait_for_zapctl
- genconf zaptel > "${ZAPCONF_FILE}"
- say "Generating '${ZAPATA_FILE}'"
- mv "${ZAPATA_FILE}" "${ZAPATA_FILE}.bak"
- genconf zapata > "${ZAPATA_FILE}"
+ say "Generating '${ZAPCONF_FILE} and ${ZAPATA_FILE}'"
+ genconf files
if [ "$set_immediate" = 'yes' ] && [ -x /etc/init.d/zaptel ]
then /etc/init.d/zaptel start
else run_ztcfg
@@ -927,9 +963,9 @@
exit 0
fi
-if [ -x $ASTERISK_INIT_SCRIPT ]
+if [ -x /etc/init.d/asterisk ]
then
- $ASTERISK_INIT_SCRIPT start 1>&2
+ /etc/init.d/asterisk start 1>&2
fi
# if in verbose mode: verify that asterisk is running
More information about the zaptel-commits
mailing list