diff options
Diffstat (limited to 'xpp/utils/genzaptelconf')
-rwxr-xr-x | xpp/utils/genzaptelconf | 268 |
1 files changed, 157 insertions, 111 deletions
diff --git a/xpp/utils/genzaptelconf b/xpp/utils/genzaptelconf index d69b710..053bf1c 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.5 +VERSION=0.5.7 rcsid='$Id$' lc_country=us base_exten=6000 @@ -54,6 +54,8 @@ group_lines=0 # group for lines # for others. Note that if an Astribank is not detected, the script # will set this to "no", so you can safely leave it as "yes". set_immediate=yes +# Set fxs_immediate to 'yes' to make all FXS lines answer immediately. +fxs_immediate=no ZAPCONF_FILE=${ZAPCONF_FILE:-/etc/zaptel.conf} ZAPCONF_FILE_SYSTEM=$ZAPCONF_FILE @@ -68,8 +70,9 @@ exten_defs_file=/etc/asterisk/extensions-defs.conf DEVZAP_TIMEOUT=${DEVZAP_TIMEOUT:-20} ZTCFG=${ZTCFG:-/sbin/ztcfg} -# 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: @@ -87,7 +90,7 @@ if [ ! -x "$ZTCFG" ]; then 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 +109,8 @@ verbose=no do_restart=yes fxsdisable=no +span_te_timing_counter=1 + die() { echo "$@" >&2 exit 1 @@ -184,11 +189,6 @@ update_module_list() { fi } -update_extensions_defs() { - # cleaning up the temp dir - if [ -d "$tmp_dir" ]; then rm -rf "$tmp_dir"; fi -} - zap_reg_xpp() { @@ -226,8 +226,8 @@ usage() { echo >&2 "$program: generate zaptel.conf and zapata.conf" echo >&2 "(version $VERSION, $rcsid)" echo >&2 "usage:" - echo >&2 " $program [-sdv] [-m k|l|g] [-c <country_code>] [-r |-e <base_exten>] " - echo >&2 " $program [-sdv] -l" + echo >&2 " $program [-sRdv] [-m k|l|g] [-c <country_code>] [-e <base_exten>] [-F]" + echo >&2 " $program [-sRdv] -l" echo >&2 " $program -su" echo >&2 " $program -h (this screen)" echo >&2 "" @@ -237,9 +237,9 @@ usage() { 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 " -d: Perform hardware detection" - echo >&2 " -u: Unload zaptel modules" + echo >&2 " -u: Unload zaptel modules (will not restart Asterisk)." echo >&2 " -v: verbose" - echo >&2 " -s: Don't fail if asterisk is running. Stop it" + echo >&2 " -s: Stop Asterisk before running, and start it at the end." echo >&2 " -R: Don't restart asterisk in the end." } @@ -264,19 +264,19 @@ print_pattern() { 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 @@ -302,59 +302,60 @@ print_pattern() { 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' + if [ "$astbank_type" = 'input' ] || \ + ( [ "$fxs_immediate" = 'yes' ] && [ "$sig" = "fxo" ] ) + 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" @@ -456,16 +457,7 @@ unload_modules() { # sleep a while until the xpp modules fully register wait_for_xpp() { - case "`uname -r`" in - 2.6.8*) - autoreg="/sys/module/xpp/zap_autoreg" - ;; - *) - autoreg="/sys/module/xpp/parameters/zap_autoreg" - ;; - esac - if [ -d /proc/xpp ] && \ - [ "`cat $autoreg`" = 'Y' ] + if [ -d /proc/xpp ] then # wait for the XPDs to register: # TODO: improve error reporting and produce a messagee here @@ -549,14 +541,10 @@ genconf() { #say "DEBUG: resetting channels lists" rm -f $tmp_dir/fx{s,o}_* - if [ "$mode" = 'zapata' ] - then - rem_char=';' - else - rem_char='#' - fi - - spanlist=`echo /proc/zaptel/* | grep -v '\*'` +# 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/|'` #if [ "$spanlist" == "" ]; then # die "No zapata interfaces in /proc/zaptel" @@ -564,8 +552,22 @@ genconf() { case "$mode" in - zaptel) - cat <<EOF + 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 # Autogenerated by $0 -- do not hand edit # Zaptel Configuration File # @@ -575,9 +577,7 @@ genconf() { # 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 +596,6 @@ EOF # 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. # @@ -610,18 +607,21 @@ EOF # 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 @@ -639,18 +639,19 @@ EOF 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 - $ztcfg_cmd -c <(print_pattern $chan_num fxo zaptel) &>/dev/null && maybe_fxs=1 - $ztcfg_cmd -c <(print_pattern $chan_num fxs zaptel) &>/dev/null && maybe_fxo=1 + $ztcfg_cmd -c <(echo fxoks=$chan_num) &>/dev/null && maybe_fxs=1 + $ztcfg_cmd -c <(echo fxsks=$chan_num) &>/dev/null && maybe_fxo=1 if [ $maybe_fxs = 1 ] && [ $maybe_fxo = 1 ] then # An installed module won't accept both FXS and FXO signalling types: # this is an empty slot. # TODO: I believe that the Sangoma A20x will reject both and thus # print nothing here. - echo "$rem_char channel $chan_num, WCTDM, no module." + echo "# channel $chan_num, WCTDM, no module." >> $zaptel_file continue fi @@ -658,46 +659,64 @@ EOF 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." + echo "# channel $chan_num, WCFXO, inactive." >>$zaptel_file ;; *WCUSB/*) 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 @@ -713,11 +732,18 @@ EOF #echo 'euroisdn' >$tmp_dir/span_switchtype #echo 'pri_cpe' >$tmp_dir/span_signalling ;; - il) + 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 @@ -727,9 +753,18 @@ EOF 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: @@ -747,52 +782,65 @@ EOF 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 @@ -801,21 +849,23 @@ EOF 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 @@ -896,13 +946,9 @@ if [ "$mode" = list ]; then 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 |