diff options
author | tzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2007-04-29 22:12:49 +0000 |
---|---|---|
committer | tzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2007-04-29 22:12:49 +0000 |
commit | 507a085a24b4f58585b632b17117cbe6451754f7 (patch) | |
tree | d84cca85bf06634a1db1abb185110c379bc925fc /xpp/utils/genzaptelconf | |
parent | 0aa20f6afb511e417dd28974a275262c9c867b63 (diff) |
xpp rev. 3814:
* Protocol no. 2.6: syncing improvements.
* Support for 8-port Astribank BRI.
* Firmware unloading now works:
rmmod xpp_usb; /etc/hotplug/usb/xpp_fxloader reset
* Defaults of kernel parameters are now part of parameter description.
* World-readable kernel parameters.
* No need for extra patch beyond bristuff for Astribank BRI.
* Default poll intervals changed: 500 in BRI and FXO.
* Allow changing FXS polls interval at run time.
* BRI initalization fixed on SUSE (path to logger).
* When using the SUSE zaptel rpm package, set modules_var=ZAPTEL_MODULES in
/etc/sysconfig/zaptel .
* zt_registration not verbose by default.
* xpp_sync warns if FXO is sync slave.
* Fixed genzaptelconf -z (zapscan output emulation).
* PCM fixes.
* Solves "multiple ticks" bug. No need for pcm_tasklets workaround.
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@2477 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'xpp/utils/genzaptelconf')
-rwxr-xr-x | xpp/utils/genzaptelconf | 604 |
1 files changed, 345 insertions, 259 deletions
diff --git a/xpp/utils/genzaptelconf b/xpp/utils/genzaptelconf index c5dedd4..4bf8a38 100755 --- a/xpp/utils/genzaptelconf +++ b/xpp/utils/genzaptelconf @@ -34,7 +34,7 @@ # (redhat/centos) # /etc/default/zaptel may override the following variables -VERSION=0.5.8 +VERSION=0.5.10 rcsid='$Id$' lc_country=us # set to: ls, ks or gs for (Loopstart, Kewlstart and GroundStart) @@ -59,15 +59,25 @@ fxs_immediate=no ZAPCONF_FILE=${ZAPCONF_FILE:-/etc/zaptel.conf} ZAPCONF_FILE_SYSTEM=$ZAPCONF_FILE ZAPATA_FILE=${ZAPATA_FILE:-/etc/asterisk/zapata-channels.conf} +ZAPSCAN_FILE=${ZAPSCAN_FILE:-/etc/asterisk/zapscan.conf} ZAPTEL_BOOT_DEBIAN=${ZAPTEL_BOOT_DEBIAN:-/etc/default/zaptel} ZAPTEL_BOOT_FEDORA=${ZAPTEL_BOOT_FEDORA:-/etc/sysconfig/zaptel} MODLIST_FILE=/etc/modules MODLIST_FILE_FEDORA=/etc/sysconfig/zaptel exten_base_dir=/etc/asterisk/extensions-phones.d exten_defs_file=/etc/asterisk/extensions-defs.conf +# perl utilities: +xpp_sync=/usr/sbin/xpp_sync +zt_registration=/usr/sbin/zt_registration # how long to wait for /dev/zap/ctl to appear? (seconds) DEVZAP_TIMEOUT=${DEVZAP_TIMEOUT:-20} ZTCFG=${ZTCFG:-/sbin/ztcfg} +# BRI/PRI spans will be in an additional per-span group whose number +# is SPAN_GROUP_BASE + span-number +SPAN_GROUP_BASE=10 +# set to "yes" to make BRI NT spans set overlapdial (handy for ISDN phones +# and other devices). +brint_overlap=no # a temporary directory to store whatever we need to remember. # @@ -77,14 +87,20 @@ tmp_dir= # A list of all modules: # - the list of modules which will be probed (in this order) if -d is used # - The module that will be deleted from /etc/modules , if -d -M is used -ALL_MODULES="zaphfc qozap ztgsm wctdm wctdm24xxp wcfxo wcfxs pciradio tor2 torisa wct1xxp wct4xxp wcte11xp wanpipe wcusb xpp_usb" +ALL_MODULES="vzaphfc zaphfc qozap ztgsm wctdm wctdm24xxp wcfxo wcfxs pciradio tor2 torisa wcte12xp wct1xxp wct4xxp wcte11xp wanpipe wcusb xpp_usb" + +# The name of the variable in /etc/sysconfig/zaptel into which to set +# the list of detected modules. +modules_var=MODULES +# On SuSE with the rpm package: +#modules_var=ZAPTEL_MODULES # What signalling to give to ZapBRI channels? # bri: bri_net; bri_cpe (Bristuffed Asterisk. No multi- support) # bri_ptmpi: bri_net_ptmp; bri_cpe_ptmp (Bristuffed Asterisk, multi- support) # pri: pri_net; pri_cpe (Recent Asterisk. Experimental) -ZAPBRI_SIGNALLING=bri -#ZAPBRI_SIGNALLING=bri_ptmp +#ZAPBRI_SIGNALLING=bri +ZAPBRI_SIGNALLING=bri_ptmp #ZAPBRI_SIGNALLING=pri # read default configuration from /etc/default/zaptel @@ -102,6 +118,8 @@ if [ ! -x "$ZTCFG" ]; then fi fi +XPP_SYNC=auto # sync mode. can be set to '0' or '1' or HOST explicitly. + # it is safe to use -c twice: the last one will be used. ztcfg_cmd="$ZTCFG -c $ZAPCONF_FILE" @@ -115,6 +133,7 @@ do_module_list=no verbose=no do_restart=yes fxsdisable=no +do_gen_zapscan=no span_te_timing_counter=1 @@ -123,7 +142,7 @@ bri) ZAPBRI_NET=bri_net; ZAPBRI_CPE=bri_cpe ;; pri) ZAPBRI_NET=pri_net; ZAPBRI_CPE=pri_cpe ;; bri_ptmp) ZAPBRI_NET=bri_net_ptmp; ZAPBRI_CPE=bri_cpe_ptmp ;; *) - echo >&2 "Incorrect value for ZAPBRI_SIGNALLING ($ZAPBRI_SIGNALLING). Abortring" + echo >&2 "Incorrect value for ZAPBRI_SIGNALLING ($ZAPBRI_SIGNALLING). Abortring" exit 1 ;; esac @@ -146,10 +165,10 @@ wait_for_zapctl() { # no point waiting. if [ -c /dev/zap/ctl ] || ! grep -q zaptel /proc/modules ; then return - fi - say "Waiting for /dev/zap/ctl to be generated" - devzap_found=0 - for i in `seq $DEVZAP_TIMEOUT`; do + fi + say "Waiting for /dev/zap/ctl to be generated" + devzap_found=0 + for i in `seq $DEVZAP_TIMEOUT`; do sleep 1 if [ -c /dev/zap/ctl ]; then devzap_found=1 @@ -157,8 +176,8 @@ wait_for_zapctl() { fi done if [ "$devzap_found" != 1 ]; then - say "Still no /dev/zap/ctl after $devzap_timeout seconds." - echo >&2 "No /dev/zap/ctl: cannot run ztcfg. Aborting." + say "Still no /dev/zap/ctl after $devzap_timeout seconds." + echo >&2 "No /dev/zap/ctl: cannot run ztcfg. Aborting." fi } @@ -192,15 +211,15 @@ update_module_list_debian() { update_module_list_fedora() { say "Updating modules list in zaptel init config $MODLIST_FILE_FEDORA." - sed -i.bak -e '/^MODULES=/d' "$MODLIST_FILE_FEDORA" - echo "MODULES=\"$*\"" >> "$MODLIST_FILE_FEDORA" + sed -i.bak -e "/^$modules_var=/d" "$MODLIST_FILE_FEDORA" + echo "$modules_var=\"$*\"" >> "$MODLIST_FILE_FEDORA" } update_module_list() { if [ -f "$MODLIST_FILE" ]; then - update_module_list_debian "$@" + update_module_list_debian "$@" elif [ -f "$MODLIST_FILE_FEDORA" ]; then - update_module_list_fedora "$@" + update_module_list_fedora "$@" else die "Can't find a modules list to update. Tried: $MODLIST_FILE, $MODLIST_FILE_FEDORA. Aborting" fi @@ -229,6 +248,26 @@ zap_reg_xpp() { done } +# Initialize the Xorcom Astribank (xpp/) +xpp_startup() { + # do nothing if the module xpp was not loaded, or if no + # Astribanks connected: + if [ ! -d /proc/xpp ]; then return 0; fi + if ! grep -q 'STATUS=connected' /proc/xpp/xbuses; then return 0; fi + + echo "Waiting for Astribank devices to initialize:" + cat /proc/xpp/XBUS-[0-9]*/waitfor_xpds 2>/dev/null || true + + # overriding locales for the above two, as perl can be noisy + # when locales are missing. + # No register all the devices if they didn't auto-register: + LC_ALL=C $zt_registration on + + # this one could actually be run after ztcfg: + LC_ALL=C $xpp_sync "$XPP_SYNC" +} + + usage() { program=`basename $0` @@ -251,6 +290,20 @@ usage() { 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." + echo >&2 " -z: also generate zapscan.conf for the asterisk GUI." +} + +# print /etc/asterisk/zapscan.conf for the Asterisk-GUI +# $1: port type. Currently only fxs/fxo . Note that this is the type, and +# not the signalling (which would be the fxo fir an fxs port. +# $2: port number. Probably a range of ports is also allowed. +print_zapscan_port () { + if [ "$do_gen_zapscan" != 'yes' ]; then return 0; fi + + echo " +[$2] +port=$1 +" >>$zapscan_file } # $1: channel number @@ -286,12 +339,12 @@ print_pattern() { else method="$fxs_default_start" fi + case "$sig" in + fxs) sig_name=FXO;; + fxo) sig_name=FXS;; + esac case "$mode" in list) - case "$sig" in - fxs) sig_name=FXO;; - fxo) sig_name=FXS;; - esac echo $chan $sig_name $astbank_type;; files) # sadly, both input ports and output ports go into the same span as @@ -400,18 +453,7 @@ print_pattern() { reset_zapata_entry $zapata_file $reset_values echo "" >> $zapata_file - # Keep a note of what channels we have identified - say "DEBUG: adding to channels list: channel: $chan, sig: $sig" - case "$sig" in - fxs) - echo $chan >$tmp_dir/fxo_$chan - say "DEBUG: FXO list now contains: `cat $tmp_dir/fxo_* |xargs`" - ;; - fxo) - echo $chan >$tmp_dir/fxs_$chan - say "DEBUG: FXS list now contains: `cat $tmp_dir/fxs_* |xargs`" - ;; - esac + print_zapscan_port "$sig" "$chan" ;; esac @@ -539,7 +581,7 @@ temporary_zapconf() { case "$1" in save) say "Temporarily moving zaptel.conf aside to work around broken modprobe.conf" - ZAPCONF_FILE_TMP=`mktemp -t zaptel.conf-XXXXXX` || die "Error creating temporary zaptel.conf" + ZAPCONF_FILE_TMP=`mktemp /tmp/genzaptelconf-zaptel.conf-XXXXXX` || die "Error creating temporary zaptel.conf" cp -a $ZAPCONF_FILE_SYSTEM $ZAPCONF_FILE_TMP echo -n >$ZAPCONF_FILE_SYSTEM ;; @@ -552,55 +594,244 @@ temporary_zapconf() { esac } -# TODO: kill this function. It is now unreferenced from anywhere. -check_tdm_sigtype() { - chan_num=$1 - sig_type=$2 - mode=$3 - - case "$sig_type" in - fxs)chan_sig_type=fxo;; - fxo)chan_sig_type=fxs;; - esac - -# print_pattern $chan_num $chan_sig_type $mode - - # if you get syntax error from this line, make sure you use 'bash' - # rather than 'sh' - $ztcfg_cmd -c <(print_pattern $chan_num $chan_sig_type zaptel) 2>/dev/null \ - || return 1 - if head -c1 /dev/zap/$chan_num >/dev/null 2>/dev/null - then - print_pattern $chan_num $chan_sig_type $mode - return 0 - else - return 1 - fi -} - # run after the channel's entry. Used to reset all the values reset_zapata_entry() { conf_file="$1"; shift for arg in "$@"; do case "$arg" in - busydetect) echo "busydetect=no" >>$conf_file;; - context) echo "context=default" >>$conf_file;; - immediate) echo "immediate=no" >>$conf_file;; - rxgain) echo "rxgain=0" >>$conf_file;; - txgain) echo "txgain=0" >>$conf_file;; - *) echo "$arg=" >>$conf_file;; + busydetect) echo "$arg=no" >>$conf_file;; + context) echo "$arg=default" >>$conf_file;; + immediate) echo "$arg=no" >>$conf_file;; + overlapdial) echo "$arg=no" >>$conf_file;; + rxgain) echo "$arg=0" >>$conf_file;; + txgain) echo "$arg=0" >>$conf_file;; + *) echo "$arg=" >>$conf_file;; esac done } +# we need to preserve the permissions of existing configurations files. +# However we also don't want to be left with incomplete configurations in +# case we are stopped in the middle. Thus we create a temporary file and +# mv it to the original file only when done. +# +# This function gives the temporary file the permissions of the original, +# or some sane defaults. +# +# The temporary file is generated here, and ths its name is passed through +# a variable whose name is passed as a parameter (new_var). +# +# $1: orig_cfg_file +# $2: new_var +gen_tmp_conf() { + orig_cfg_file=$1 + new_var=$2 + + # assign to new_var by reference: + eval $new_var=`mktemp /tmp/genzaptelconf-conf-XXXXXX` \ + || die "Unable to create temporary config file for $orig_cfg_file" + if [ -r "$orig_cfg_file" ]; then + chown --reference="$orig_cfg_file" ${!new_var} 2>/dev/null + chmod --reference="$orig_cfg_file" ${!new_var} 2>/dev/null + else + chmod 644 ${!new_var} + fi +} + +# Extract information from one digital channel (one line in a /proc/zaptel +# file). Information is saved to $tmp_dir/span_foo variables. +detect_digital_channel() { + line="$1" + chan_num="$2" + span_num="$3" + + # 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 + # we have a E1 span, a T1 span or a BRI span. + 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 + *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 $ZAPBRI_NET >$tmp_dir/span_signalling + else + echo $ZAPBRI_CPE >$tmp_dir/span_signalling + fi + ;; + *ztgsm*/*) + # Junghanns's GSM cards. + echo 'ccs' >$tmp_dir/span_framing + #Does this mean anything? + echo 'gsm' >$tmp_dir/span_signalling + ;; + *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 + echo 'pri_cpe' >$tmp_dir/span_signalling + # an example of country-specific setup. This is probably not accurate + # Contributions are welcome + case "$lc_country" in + nl) + # (Just an example for per-country info) + echo 'ccs' >$tmp_dir/span_framing + echo 'ami' >$tmp_dir/span_coding + #echo 'crc4' >$tmp_dir/span_yellow + #echo 'euroisdn' >$tmp_dir/span_switchtype + #echo 'pri_cpe' >$tmp_dir/span_signalling + ;; + il|de|au) + echo 'ccs' >$tmp_dir/span_framing + echo 'hdb3' >$tmp_dir/span_coding + echo 'crc4' >$tmp_dir/span_yellow + echo 'euroisdn' >$tmp_dir/span_switchtype + ;; + cl) + echo 'ccs' >$tmp_dir/span_framing + echo 'hdb3' >$tmp_dir/span_coding + #echo 'crc4' >$tmp_dir/span_yellow + echo 'national' >$tmp_dir/span_switchtype + ;; + esac + ;; + esac + fi + # span_lastd is always the one before last + # channel. span_bchan is the last: + echo $chan_num >$tmp_dir/span_end +} + +# read information from the $tmp_dir/span_foo files and generate +# configuration for the span and its channels. +write_digital_config() { + # if the current file we checked was not of a digital span, we have + # nothing to do: + if [ "`cat $tmp_dir/span_begin`" = -1 ]; then return; fi + + # read files to variables: + for suffix in num begin end timing lbo framing \ + coding switchtype signalling yellow termtype + do + eval span_$suffix=`cat $tmp_dir/span_$suffix 2>/dev/null` + done + + if [ "$span_yellow" != '' ]; then span_yellow=",$span_yellow"; fi + # exactly the same logic is used in asterisk's chan_zap.c. + # also not that $(( )) is bash-specific + case "$((1+ $span_end - $span_begin))" in + 2|3|24) #ztgsm, BRI or T1 + dchan=$span_end + bchans="$span_begin-$(($span_end-1))" + ;; + 31) #E1 + dchan="$(($span_begin+15))" + bchans="$span_begin-$(($span_begin+14)),$(($span_begin+16))-$span_end" + if [ "$span_switchtype" = 'national' ]; then + # don't leave an E1 span with defective defaults: + 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 + 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 + # this span is TE or NT: + if [ "$span_termtype" != '' ] + then echo "# termtype: $span_termtype" >>$zaptel_file + fi + + echo bchan=$bchans >>$zaptel_file + echo dchan=$dchan >>$zaptel_file + if [ "$fxsdisable" = 'yes' ] && [ "$span_termtype" = 'nt' ]; then return; fi + # You should not send content to zapata.conf below this line + + span_group=$(($SPAN_GROUP_BASE + $span_num)) + + 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>" >> $zapata_file + reset_values="$reset_values callerid" + #echo "mailbox=$exten" + if [ "$brint_overlap" = 'yes' ] + then + echo "overlapdial=yes" >> $zapata_file + reset_values="$reset_values overlapdial" + fi + if [ "$group_manual" != "yes" ] + then + echo "group=$group_phones,$span_group" >> $zapata_file + reset_values="$reset_values group" + fi + if [ "$context_manual" != "yes" ] + then + echo "context=$context_phones" >> $zapata_file + fi + else + #echo "mailbox=" + if [ "$group_manual" != "yes" ] + then + echo "group=$group_lines,$span_group" >> $zapata_file + reset_values="$reset_values group" + fi + if [ "$context_manual" != "yes" ] + then + echo "context=$context_lines" >> $zapata_file + reset_values="$reset_values context" + fi + fi + fi + echo "switchtype = $span_switchtype" >> $zapata_file + echo "signalling = $span_signalling" >> $zapata_file + echo "channel => $bchans" >> $zapata_file + reset_zapata_entry $zapata_file $reset_values + reset_values= + ;; + list) + echo "### BRI/PRI: $span_termtype" + echo "$bchans Data" + echo "$dchan Control" + #echo BRI/PRI: chans: $bchans, control: $dchan + ;; + esac +} + +# This is where the actual detection configuration detection work happens. genconf() { local mode=$1 local reset_values="" - # reset FXO list (global) - #say "DEBUG: resetting channels lists" - rm -f $tmp_dir/fx{s,o}_* # 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) @@ -613,22 +844,20 @@ genconf() { case "$mode" in - files) - local zaptel_file=`mktemp -t genzaptelconf-zaptel-XXXXXX` - local zapata_file=`mktemp -t genzaptelconf-zapata-XXXXXX` - if [ -r "${ZAPCONF_FILE}" ]; then - chown --reference="${ZAPCONF_FILE}" $zaptel_file || true - chmod --reference="${ZAPCONF_FILE}" $zaptel_file - else - chmod 644 $zaptel_file - fi - if [ -r "${ZAPATA_FILE}" ]; then - chown --reference="${ZAPATA_FILE}" $zapata_file || true - chmod --reference="${ZAPATA_FILE}" $zapata_file - else - chmod 644 $zapata_file - fi - cat <<EOF >$zaptel_file + files) + if [ "$do_gen_zapscan" = 'yes' ]; then + gen_tmp_conf "$ZAPSCAN_FILE" zapscan_file + cat <<EOF >$zapscan_file +; zapscan.conf: information about detected zaptel channels +; (currently: analog only) +; +; Automatically generated by $0 -- Please do not edit. + +EOF + fi + gen_tmp_conf "$ZAPTEL_FILE" zaptel_file + gen_tmp_conf "$ZAPATA_FILE" zapata_file + cat <<EOF >$zaptel_file # Autogenerated by $0 -- do not hand edit # Zaptel Configuration File # @@ -638,7 +867,7 @@ genconf() { # It must be in the module loading order EOF - cat <<EOF >$zapata_file + cat <<EOF >$zapata_file ; Autogenerated by $0 -- do not hand edit ; Zaptel Channels Configurations (zapata.conf) ; @@ -672,10 +901,10 @@ EOF case "$mode" in list) echo "### $title";; files) - echo "" >>$zaptel_file - echo "# $title" >>$zaptel_file - echo "" >>$zapata_file - echo "; $title" >>$zapata_file + echo "" >>$zaptel_file + echo "# $title" >>$zaptel_file + echo "" >>$zapata_file + echo "; $title" >>$zapata_file ;; esac echo '-1' >$tmp_dir/span_begin @@ -749,74 +978,7 @@ EOF print_pattern -a input $chan_num fxo $mode ;; *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 - *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 $ZAPBRI_NET >$tmp_dir/span_signalling - else - echo $ZAPBRI_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 - ;; - *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 - echo 'pri_cpe' >$tmp_dir/span_signalling - # an example of country-specific setup. This is probably not accurate - # Contributions are welcome - case "$lc_country" in - nl) - # (Just an example for per-country info) - echo 'ccs' >$tmp_dir/span_framing - echo 'ami' >$tmp_dir/span_coding - #echo 'crc4' >$tmp_dir/span_yellow - #echo 'euroisdn' >$tmp_dir/span_switchtype - #echo 'pri_cpe' >$tmp_dir/span_signalling - ;; - il|de|au) - echo 'ccs' >$tmp_dir/span_framing - echo 'hdb3' >$tmp_dir/span_coding - echo 'crc4' >$tmp_dir/span_yellow - echo 'euroisdn' >$tmp_dir/span_switchtype - ;; - cl) - echo 'ccs' >$tmp_dir/span_framing - echo 'hdb3' >$tmp_dir/span_coding - #echo 'crc4' >$tmp_dir/span_yellow - echo 'national' >$tmp_dir/span_switchtype - ;; - esac - ;; - esac - fi - # span_lastd is always the one before last - # channel. span_bchan is the last: - echo $chan_num >$tmp_dir/span_end + detect_digital_channel "$line" "$chan_num" "$span_num" ;; '') ;; # Empty line (after span header) *) @@ -831,97 +993,7 @@ EOF done # end of part in sub-process. - if [ "`cat $tmp_dir/span_begin`" != -1 ] - then # write PRI span ocnfig: - # read files to variables: - for suffix in num begin end timing lbo framing \ - coding switchtype signalling yellow termtype - do - eval span_$suffix=`cat $tmp_dir/span_$suffix 2>/dev/null` - done - if [ "$span_yellow" != '' ]; then span_yellow=",$span_yellow"; fi - # exactly the same logic is used in asterisk's chan_zap.c. - # also not that $(( )) is bash-specific - case "$((1+ $span_end - $span_begin))" in - 2|3|24) #ztgsm, BRI or T1 - dchan=$span_end - bchans="$span_begin-$(($span_end-1))" - ;; - 31) #E1 - 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 - 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" >>$zaptel_file - fi - 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>" >> $zapata_file - reset_values="$reset_values callerid" - #echo "mailbox=$exten" - if [ "$group_manual" != "yes" ] - then - echo "group=$group_phones" >> $zapata_file - reset_values="$reset_values group" - fi - if [ "$context_manual" != "yes" ] - then - echo "context=$context_phones" >> $zapata_file - fi - else # we have may have set it. So reset it: - echo "callerid=asreceived" >> $zapata_file - reset_values="$reset_values callerid" - #echo "mailbox=" - if [ "$group_manual" != "yes" ] - then - echo "group=$group_lines" >> $zapata_file - reset_values="$reset_values group" - fi - if [ "$context_manual" != "yes" ] - then - echo "context=$context_lines" >> $zapata_file - reset_values="$reset_values context" - fi - fi - fi - echo "switchtype = $span_switchtype" >> $zapata_file - echo "signalling = $span_signalling" >> $zapata_file - echo "channel => $bchans" >> $zapata_file - reset_zapata_entry $zapata_file $reset_values - ;; - list) - echo "### BRI/PRI: $span_termtype" - echo "$bchans Data" - echo "$dchan Control" - #echo BRI/PRI: chans: $bchans, control: $dchan - ;; - esac - fi + write_digital_config done if [ "$mode" = 'files' ] @@ -936,14 +1008,26 @@ EOF fi if [ "$mode" = 'files' ]; then - mv ${ZAPCONF_FILE} ${ZAPCONF_FILE}.bak + mv ${ZAPCONF_FILE} ${ZAPCONF_FILE}.bak 2>/dev/null mv $zaptel_file ${ZAPCONF_FILE} - mv ${ZAPATA_FILE} ${ZAPATA_FILE}.bak + mv ${ZAPATA_FILE} ${ZAPATA_FILE}.bak 2>/dev/nullk mv $zapata_file ${ZAPATA_FILE} + if [ "$do_gen_zapscan" = 'yes' ]; then + mv $ZAPSCAN_FILE $ZAPSCAN_FILE.bak 2>/dev/null + mv $zapscan_file $ZAPSCAN_FILE + fi + + zapata_file_name=`basename $ZAPATA_FILE` + if ! grep -q "^#include.*$zapata_file_name" \ + /etc/asterisk/zapata.conf + then + say "Note: generated $ZAPATA_FILE not included in zapata.conf" + say "To fix: echo '#include $zapata_file_name' >>/etc/asterisk/zapata.conf" + fi fi } -while getopts 'c:de:Fhlm:MRsuv' arg +while getopts 'c:de:Fhlm:MRsuvz' arg do case "$arg" in e) # guarantee that it is a number: @@ -959,6 +1043,7 @@ do M) do_module_list=yes; do_detect=yes ;; s) force_stop_ast=yes ;; R) do_restart=no ;; + z) do_gen_zapscan=yes ;; h) usage; exit 0;; *) echo >&2 "unknown parameter -$arg, Aborting"; usage; exit 1;; esac @@ -970,7 +1055,7 @@ if [ $# != 0 ]; then exit 1 fi -tmp_dir=`mktemp -d -t` || \ +tmp_dir=`mktemp -d /tmp/genzaptelconf-dir-XXXXXX` || \ die "$0: failed to create temporary directory. Aborting" @@ -991,14 +1076,14 @@ defaultzone=$loadzone # make sure asterisk is not in our way if [ "$force_stop_ast" = 'yes' ] then - /etc/init.d/asterisk 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. if ( [ "$do_unload" = yes ] || [ "$do_detect" = yes ] ) && \ - pidof asterisk >/dev/null + pidof asterisk >/dev/null then - echo >&2 "Asterisk is already running. Configuration left untouched" + echo >&2 "Asterisk is already running. Configuration left untouched" echo >&2 "You can use the option -s to shut down Asterisk for the" echo >&2 "duration of the detection." exit 1 @@ -1019,7 +1104,8 @@ fi if [ "$mode" = list ]; then genconf list else - zap_reg_xpp + #zap_reg_xpp + xpp_startup wait_for_zapctl say "Generating '${ZAPCONF_FILE} and ${ZAPATA_FILE}'" genconf files @@ -1028,17 +1114,17 @@ fi if [ "$tmp_dir" != '' ] then - rm -rf "$tmp_dir" + rm -rf "$tmp_dir" fi if [ "$force_stop_ast" != 'yes' ] || [ "$do_restart" != 'yes' ] then - exit 0 + exit 0 fi if [ -x /etc/init.d/asterisk ] then - /etc/init.d/asterisk start 1>&2 + /etc/init.d/asterisk start 1>&2 fi # if in verbose mode: verify that asterisk is running @@ -1054,4 +1140,4 @@ if [ "$verbose" != 'no' ] fi fi -# vim:ts=2: +# vim:ts=8: |