/[gentoo-x86]/net-dialup/capi4k-utils/files/capi.initd
Gentoo

Contents of /net-dialup/capi4k-utils/files/capi.initd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Sun Apr 20 23:00:46 2008 UTC (12 years, 2 months ago) by sbriesen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +32 -29 lines
made init-script posix-shell compatible
(Portage version: 2.1.5_rc5)

1 #!/sbin/runscript
2 # Copyright 1999-2008 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/net-dialup/capi4k-utils/files/capi.initd,v 1.7 2005/09/03 20:25:17 sbriesen Exp $
5
6 opts="info showconfig"
7
8 depend() {
9 after isapnp pcmcia bluetooth
10 }
11
12 # possible firmware locations (list and order taken from 'capiinit')
13 FWDIRS="/lib/firmware/isdn /lib/firmware /usr/share/isdn /usr/lib/isdn /lib/isdn"
14
15 # Firmware search
16 findfw() { # <fw_name>
17 local DIR
18 for DIR in ${FWDIRS}; do
19 if [ -f "${DIR}/${1}" ]; then
20 echo "${DIR}/${1}"; return 0
21 fi
22 done
23 return 1
24 }
25
26 # looking for 'detected' cards (currently only 'sedlfax')
27 detected() { # <driver>
28 # /proc/capi/controller: <controller> <drivername> <state> <cardname> <controllerinfo>
29 sed -n "s:^\([1-9][0-9]*\) \+${1} \+detected \+.*:\1:p" \
30 /proc/capi/controller 2>/dev/null
31 }
32
33 # detecting loaded mISDN modules
34 misdn_modules() {
35 sed -n "s:^mISDN_core \+[0-9]\+ \+[0-9]\+ \+\([^ ]\+\).*\$:\1:p" \
36 /proc/modules 2>/dev/null | tr "," " "
37 }
38
39 # detecting loaded CAPI drivers
40 capi_drivers() {
41 local DRV MISDN=0
42 for DRV in $(sed -n "s:^[0-9]\+ \+\([^ ]\+\).*\$:\1:p" /proc/capi/controller 2>/dev/null); do
43 case "${DRV}" in
44 mISDN) MISDN=1;;
45 ?*) echo "${DRV}";;
46 esac
47 done
48 # dirty hack to find loaded mISDN modules
49 if [ ${MISDN} -gt 0 ]; then
50 for DRV in $(misdn_modules); do
51 case "${DRV}" in
52 mISDN_*|l3udss1|faxl3) continue;;
53 ?*) echo "${DRV}";;
54 esac
55 done
56 fi
57 }
58
59 # detecting bluetooth CIP connections
60 bluez_cip() {
61 [ -x /usr/bin/ciptool ] && \
62 sed -n "s:[0-9]\+ \+cmtp \+[^ ]\+ \+\([0-9A-F:]\+\) \+.*\$:\1:p" \
63 /proc/capi/controller 2>/dev/null
64 }
65
66
67
68 start() {
69 if [ ! -e /etc/capi.conf ] ; then
70 eerror "You're missing /etc/capi.conf (comes with a capi-driver)."
71 eerror "Emerge net-dialup/fritzcapi if you're having an AVM Fritz!Card"
72 return 1
73 fi
74
75 ebegin "Loading CAPI"
76 [ -f /proc/capi/capi20 ] || /sbin/modprobe -s capi
77 eend $? || return 1
78
79 local CNT=0 # wait for udev (max 10s)
80 while [ ! -c /dev/capi20 -a ${CNT} -lt 40 ]; do
81 sleep 0.25; : $((CNT++))
82 done
83
84 ebegin "Starting CAPI"
85 /usr/sbin/capiinit activate 2>/dev/null
86 if eend $?; then
87 local CIP MSG INFO FW CARD MISDN
88
89 # HACK: loading ISAR.BIN onto 'sedlfax' cards
90 # shouldn't be necessary, but mISDN is crappy
91 MISDN=$(detected "mISDN")
92 if [ -n "${MISDN}" ]; then
93 FW=$(findfw "ISAR.BIN")
94 if [ -n "${FW}" ]; then
95 for CARD in ${MISDN}; do
96 ebegin "Loading firmware '${FW##*/}' onto controller ${CARD}"
97 /usr/sbin/avmcapictrl load "${FW}" "${CARD}" 2>&1 >/dev/null
98 eend $?
99 done
100 else
101 eerror "Firmware 'ISAR.BIN' not found in ${FWDIRS%% *}"
102 fi
103 fi
104
105 # connect to CIP devices
106 if [ -n "${CAPI_CIP_DEVICES}" -a -x /usr/bin/ciptool ]; then
107 for CIP in ${CAPI_CIP_DEVICES}; do
108 ebegin "CIP connect to ${CIP}"
109 INFO=$(/usr/bin/ciptool connect "${CIP}" 2>&1)
110 if ! eend $?; then
111 [ -n "${INFO}" ] && \
112 echo "${INFO}" | while read line MSG; do eerror " ${MSG}"; done
113 fi
114 done
115 sleep 0.3 # give subsystems time to initialize
116 fi
117
118 # load 'capidrv'
119 [ -f /proc/capi/capidrv -o "${CAPI_LOAD_CAPIDRV}" != "yes" ] || /sbin/modprobe -s capidrv
120
121 # show controllers
122 INFO=$(cat /proc/capi/controller)
123 if [ -n "${INFO}" ]; then
124 einfo "Available CAPI controllers:"
125 echo "${INFO}" | while read MSG; do einfo " ${MSG}"; done
126 fi
127 fi
128 return 0 # never fail
129 }
130
131 stop() {
132 local DRV CIP RET FCNT=0 DRIVERS=$(capi_drivers | sort -u)
133
134 # if some CAPI applications are still running, kill 'em
135 if fuser -s /dev/capi20 2>/dev/null; then
136 ebegin "Stopping CAPI applications"
137 fuser -ks /dev/capi20; RET=$?
138 while [ ${RET} -eq 0 -a ${FCNT} -lt 10 ]; do
139 : $((FCNT++)); sleep 0.5; fuser -s /dev/capi20; RET=$?
140 done
141 [ ${RET} -ne 0 ]
142 eend $?
143 fi
144
145 # release bluetooth CIP connections
146 for CIP in $(bluez_cip); do
147 ebegin "Release CIP connection to ${CIP}"
148 /usr/bin/ciptool release "${CIP}"
149 eend
150 done
151
152 ebegin "Stopping CAPI"
153 [ "${CAPI_LOAD_CAPIDRV}" = "yes" ] && /sbin/modprobe -sqr capidrv
154 [ "${CAPI_UNLOAD_CARDS}" = "yes" ] && /usr/sbin/capiinit stop &>/dev/null
155 for DRV in ${DRIVERS}; do
156 /sbin/modprobe -sqr "${DRV}"
157 done
158 /sbin/modprobe -sqr capi
159 eend 0 # ignore errors
160 }
161
162 info() {
163 if [ -f /proc/capi/controller ]; then
164 local MSG
165 while read MSG; do einfo "${MSG}"; done < /proc/capi/controller
166 else
167 eerror "ERROR: CAPI not loaded"
168 return 1
169 fi
170 }
171
172 showconfig() {
173 local MSG INFO
174 if INFO=$(/usr/sbin/capiinit show 2>&1); then
175 echo "${INFO}" | while read MSG; do einfo "${MSG}"; done
176 return 0
177 fi
178 echo "${INFO}" | while read MSG; do eerror "${MSG}"; done
179 return 1
180 }

  ViewVC Help
Powered by ViewVC 1.1.20