#!/sbin/runscript # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/net-dialup/capi4k-utils/files/capi.initd,v 1.7 2005/09/03 20:25:17 sbriesen Exp $ opts="info showconfig" depend() { after isapnp pcmcia bluetooth hotplug } # possible firmware locations (list and order taken from 'capiinit') FWDIRS=(/lib/firmware/isdn /lib/firmware /usr/share/isdn /usr/lib/isdn /lib/isdn) # Firmware search findfw() { # local DIR for DIR in ${FWDIRS[*]}; do if [ -f "${DIR}/${1}" ]; then echo "${DIR}/${1}"; return 0 fi done return 1 } # looking for 'detected' cards (currently only 'sedlfax') detected() { # # /proc/capi/controller: /bin/sed -n "s:^\([1-9][0-9]*\) \+${1} \+detected \+.*:\1:p" \ /proc/capi/controller 2>/dev/null } # detecting loaded mISDN modules misdn_modules() { /bin/sed -n "s:^mISDN_core \+[0-9]\+ \+[0-9]\+ \+\([^ ]\+\).*\$:\1:p" \ /proc/modules 2>/dev/null | /bin/tr "," " " } # detecting loaded CAPI drivers capi_drivers() { local DRV MISDN=0 while read DRV; do case "${DRV}" in mISDN) MISDN=1;; ?*) echo "${DRV}";; esac done < <(/bin/sed 2>/dev/null -n "s:^[0-9]\+ \+\([^ ]\+\).*\$:\1:p" /proc/capi/controller) if [ ${MISDN} -gt 0 ]; then # dirty hack to find loaded mISDN modules for DRV in $(misdn_modules); do case "${DRV}" in mISDN_*|l3udss1|faxl3) continue;; ?*) echo "${DRV}";; esac done fi } # detecting bluetooth CIP connections bluez_cip() { [ -x /usr/bin/ciptool ] && \ /bin/sed -n "s:[0-9]\+ \+cmtp \+[^ ]\+ \+\([0-9A-F:]\+\) \+.*\$:\1:p" \ /proc/capi/controller 2>/dev/null } start() { if [ ! -e /etc/capi.conf ] ; then eerror "You're missing /etc/capi.conf (comes with a capi-driver)." eerror "Emerge net-dialup/fritzcapi if you're having an AVM Fritz!Card" return 1 fi ebegin "Loading CAPI" [ -f /proc/capi/capi20 ] || /sbin/modprobe -s capi eend $? || return 1 local CNT=0 # wait for udev (max 10s) while [ ! -c /dev/capi20 -a ${CNT} -lt 40 ]; do sleep 0.25; : $((CNT++)) done ebegin "Starting CAPI" /usr/sbin/capiinit 2>/dev/null activate if eend $?; then local CIP MSG INFO FW CARD MISDN # HACK: loading ISAR.BIN onto 'sedlfax' cards # shouldn't be necessary, but mISDN is crappy MISDN=$(detected "mISDN") if [ -n "${MISDN}" ]; then FW=$(findfw "ISAR.BIN") if [ -n "${FW}" ]; then for CARD in ${MISDN}; do ebegin "Loading firmware '${FW##*/}' onto controller ${CARD}" /usr/sbin/avmcapictrl &>/dev/null load "${FW}" "${CARD}" eend $? done else eerror "Firmware 'ISAR.BIN' not found in ${FWDIRS[0]}" fi fi # connect to CIP devices if [ -n "${CAPI_CIP_DEVICES}" -a -x /usr/bin/ciptool ]; then for CIP in ${CAPI_CIP_DEVICES}; do ebegin "CIP connect to ${CIP}" INFO=$(/usr/bin/ciptool 2>&1 connect "${CIP}") if ! eend $?; then [ -n "${INFO}" ] && \ while read line MSG; do eerror " ${MSG}"; done < <(echo "${INFO}") fi done sleep 0.3 # give subsystems time to initialize fi # load 'capidrv' [ -f /proc/capi/capidrv -o "${CAPI_LOAD_CAPIDRV}" != "yes" ] || /sbin/modprobe -s capidrv # show controllers INFO=$(/dev/null -s /dev/capi20; then ebegin "Stopping CAPI applications" /bin/fuser -ks /dev/capi20; RET=$? while [ ${RET} -eq 0 -a ${FCNT} -lt 10 ]; do : $((FCNT++)); sleep 0.5; /bin/fuser -s /dev/capi20; RET=$? done [ $RET -ne 0 ] eend $? fi # release bluetooth CIP connections for CIP in $(bluez_cip); do ebegin "Release CIP connection to ${CIP}" /usr/bin/ciptool release "${CIP}" eend done ebegin "Stopping CAPI" [ "${CAPI_LOAD_CAPIDRV}" = "yes" ] && /sbin/modprobe -sqr capidrv [ "${CAPI_UNLOAD_CARDS}" = "yes" ] && /usr/sbin/capiinit &>/dev/null stop for DRV in ${DRIVERS}; do /sbin/modprobe -sqr "${DRV}"; done /sbin/modprobe -sqr capi eend 0 # ignore errors } info() { if [ -f /proc/capi/controller ]; then local MSG while read MSG; do einfo "${MSG}"; done < /proc/capi/controller else eerror "ERROR: CAPI not loaded" return 1 fi } showconfig() { local MSG INFO if INFO=$(/usr/sbin/capiinit 2>&1 show); then while read MSG; do einfo "${MSG}"; done < <(echo "${INFO}") return 0 fi while read MSG; do eerror "${MSG}"; done < <(echo "${INFO}") return 1 }