#!/bin/sh # # zaptel This shell script takes care of loading and unloading \ # Zapata Telephony interfaces # chkconfig: - 9 92 # description: The zapata telephony drivers allow you to use your linux \ # computer to accept incoming data and voice interfaces # # config: /etc/sysconfig/zaptel initdir=/etc/rc.d/init.d # Source function library. . $initdir/functions || exit 0 # Source zaptel configuration. [ -f /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel if [ -z "${MODULES}" ]; then # Populate defaults if not present # MODULES="tor2 wct4xxp wct1xxp wcte11xp wcfxo wctdm ztdummypll" MODULES="ztdummypll" fi RMODULES="" # Reverse list for un-loading; don't change for x in $MODULES; do RMODULES="$x $RMODULES" done # register any xpp device found, and not registered. # you can setup the xpp drivers not to register themselves on boot, # and then you need to register them manually, this is done by the # module option zap_autoreg=0 in /etc/modprobe.conf zap_reg_xpp() { if [ ! -d /proc/xpp ]; then return; fi # Get a list of connected Astribank devices, sorted by the name of # the USB connector. That order is rather arbitrary, but will not # change without changes to the cabling. xbusses=`sort -k 2 /proc/xpp/xbuses | awk -F: '/STATUS=connected/ {print $1}'` # get a list of XPDs that were not yet registered as zaptel 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. xbusses_pattern=`echo $xbusses| sed -e 's|XBUS-[0-9]*|/proc/xpp/&/XPD-*/zt_registration|g'`' /dev/null' echo "Checking file ($xbusses_pattern): " $xbusses_pattern xpds_to_register=`grep -l 0 $xbusses_pattern 2>/dev/null` || true for file in $xpds_to_register; do echo 1 >$file done } # Wait for udev to generate /dev/zap/ctl, if needed: wait_for_zap_ctl(){ if [ ! -c /dev/zap/ctl ] && grep -q zaptel /proc/modules ; then echo "Waiting for /dev/zap/ctl to be generated" devzap_found=0 devzap_timeout=20 for i in `seq $devzap_timeout`; do sleep 1 if [ -a /dev/zap/ctl ]; then devzap_found=1 break 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." fi fi } # sleep a while until the xpp modules fully register wait_for_xpp() { if [ -d /proc/xpp ] then # wait for the XPDs to register: # TODO: improve error reporting and produce a message here cat /proc/xpp/XBUS-*/waitfor_xpds 2>/dev/null >/dev/null || true fi } # astribank drivers come with device synchronization by default # fix this to host synchronization, unless it's an FXO. # FXO will be the sync masters on our setup fix_asterisbank_sync() { # do nothing if module not present if [ ! -d /proc/xpp ]; then return; fi #if ! grep -q '^HOST' /proc/xpp/sync 2>/dev/null; then return; fi case "$XPP_SYNC" in n*|N*) return;; host|HOST) sync_value="HOST";; [0-9]*)sync_value="$XPP_SYNC";; *) # find the number of the first bus, and sync from it: bus=`awk -F: '/STATUS=connected/{print $1}' /proc/xpp/xbuses | head -n 1 | cut -d- -f2` # do nothing if there is no bus: case "$bus" in [0-9]*):;; *) return;; esac sync_value="$bus 0" ;; esac # the built-in echo of bash fails to print a proper error on failure if ! /bin/echo "$sync_value" >/proc/xpp/sync then echo >&2 "Updating XPP sync source failed (used XPP_SYNC='$XPP_SYNC')" fi } # check if /etc/sysconfig/zaptel exists. If not exit if [ ! -f /etc/sysconfig/zaptel ]; then echo "Cannot start: /etc/sysconfig/zaptel is missing." exit 0 fi # Check that telephony is "yes". If not exit if [ ${TELEPHONY} = "no" ]; then echo "Cannot start: TELEPHONY=no in /etc/sysconfig/zaptel." exit 0 fi # check of /usr/sbin/ztcfg exists. If not exit if [ ! -f /usr/sbin/ztcfg ]; then echo "Cannot start: /usr/sbin/ztcfg is missing." exit 0 fi # check of /etc/zaptel.conf exits. If not exit if [ ! -f /etc/zaptel.conf ]; then echo "Cannot start: /etc/zaptel.conf is missing." exit 0 fi if [ "${DEBUG}" = "yes" ]; then ARGS="debug=1" fi RETVAL=0 # See how we were called. case "$1" in start) # Load drivers rmmod wcusb >& /dev/null rmmod wcfxsusb >& /dev/null rmmod audio >& /dev/null action "Loading zaptel framework: " modprobe zaptel rc=$? if [ "$rc" = "1" ]; then exit 1 fi STRING="Waiting for zap to come online:" echo -n "$STRING " if [ "${RHGB_STARTED}" != "" -a -w /etc/rhgb/temp/rhgb-console ]; then echo -n "$STRING " > /etc/rhgb/temp/rhgb-console fi TMOUT=10 # max secs to wait while [ ! -d /dev/zap ] ; do sleep 1 TMOUT=`expr $TMOUT - 1` if [ $TMOUT -eq 0 ] ; then failure $"$STRING" if [ "${RHGB_STARTED}" != "" -a -w /etc/rhgb/tmp/rhgb-console ]; then echo_failure > /etc/rhgb/temp/rhgb-console [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --details=yes fi echo exit 1 fi done success $"$STRING" if [ "${RHGB_STARTED}" != "" -a -w /etc/rhgb/tmp/rhgb-console ]; then echo_success > /etc/rhgb/temp/rhgb-console fi echo echo "Loading zaptel hardware modules:" for x in $MODULES; do eval localARGS="\$${x}_ARGS" action "Loading ${x}:" modprobe ${x} ${ARGS} ${localARGS} done # wait for udev system to create the needed device files wait_for_zap_ctl # wait for xpp drivers to be ready wait_for_xpp # xpp drivers do not register with zaptel by default zap_reg_xpp # fix astribank sync -> host fix_asterisbank_sync if [ ! -e /proc/zaptel/1 ]; then echo "No functioning zap hardware found in /proc/zaptel, loading ztdummypll" action "Loading ztdummypll:" modprobe ztdummypll fi action "Running ztcfg: " /usr/sbin/ztcfg RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zaptel ;; stop) # Unload drivers action "Removing zaptel modules:" /usr/sbin/genzaptelconf -us RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zaptel ;; restart) $0 stop $0 start ;; reload) action "Reloading ztcfg: " /usr/sbin/ztcfg RETVAL=$? ;; *) echo "Usage: zaptel {start|stop|restart|reload}" exit 1 esac exit $RETVAL