4
# Provides: softmodem sl-modem-daemon
5
# Default-Start: 2 3 4 5
7
# Required-Start: $local_fs $remote_fs
8
# Required-Stop: $local_fs $remote_fs
9
# Short-Description: Setup the SmartLink modem daemon
10
# Description: Starts the modem daemon emulating a serial device and
11
# links the result to /dev/modem.
15
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
16
DAEMON=/usr/sbin/slmodemd
18
PIDFILE=/var/run/$NAME.pid
19
DESC="SmartLink modem daemon"
20
modprobe="$(cat /proc/sys/kernel/modprobe 2>/dev/null || echo modprobe)"
22
. /lib/lsb/init-functions
24
test -x $DAEMON || exit 0
26
# there may be old options there...
27
test -r /etc/default/slmodemd && . /etc/default/slmodemd
29
# but most likely they are here
30
test -r /etc/default/sl-modem-daemon && . /etc/default/sl-modem-daemon
33
driverlist="snd-intel8x0m snd-via82xx-modem snd-atiixp-modem"
35
# must match the names in /proc/modules with the underscores etc., includes slamr too
36
unloadllist="snd_intel8x0m snd_via82xx_modem snd_atiixp_modem slamr"
40
unset aplay_grep_line;
43
# first check for situation when there is modem subdevice (aplay -l output have "(M|m)odem" string, and /proc/asound/cards doesn't).
44
# this one doesn't need modprobe (modem is part of sound card chip)
46
if ! proc_grep=$(grep -i "\[Modem " /proc/asound/cards) ; then
47
# if there is aplay output, get card and device numbers and form SLMODEMD_DEVICE as hw:a,b
48
if aplay_grep=$(LC_ALL=C aplay -l | egrep '^card [0-9].*(M|m)odem') ; then
49
aplay_grep_line=$(echo "$aplay_grep" | sed -r 's/^card ([[:digit:]]+).*device ([[:digit:]]+).*$/\1 \2/')
51
# Let's configure subdevice
52
if [ -n "$aplay_grep_line" ] ; then
54
# This one needs hw as prefix
56
SLMODEMD_DEVICE="$ALSADEVPREFIX:$1,$2"
60
# if there is no aplay and proc output, try to modprobe and then check for modem cards again
62
# first check to not do unneccessary modprobe calls. Some people even put
63
# it into the kernel image
65
for x in $driverlist ; do $modprobe $x 2>/dev/null ; done
67
for start_reps in `seq 100` ; do
68
test -e /proc/asound/cards && proc_grep=$(grep -i "\[Modem " -i /proc/asound/cards) && (LC_ALL=C aplay -l | egrep '^card [0-9]*\: Modem ' >/dev/null) && break
75
# if we got proc_grep (already existed or from previous if), let's use it to form SLMODEMD_DEVICE as modem:a
76
if [ -n "$proc_grep" ] ; then
77
# ALSA driver is loaded, use it
79
SLMODEMD_DEVICE=$ALSADEVPREFIX:$1
88
if test "$DONTSTART" = 1 ; then
89
test "$BEQUIET" = 1 || echo "Not starting $DESC (options not set in /etc/default/slmodemd)"
93
if test "$SLMODEMD_COUNTRY" ; then
94
OPTS="$OPTS -c $SLMODEMD_COUNTRY"
97
ALSA=`echo $SLMODEMD_DEVICE | grep :`
99
if [ "`echo $SLMODEMD_DEVICE | grep auto`" ] ; then
101
# carefully look for signs of loaded drivers
102
if grep -i "\[Modem " -i /proc/asound/cards ; then
103
# already loaded, just pick up the device there
106
# ALSA not loaded yet, try the smartlink driver first, then try ALSA
107
# though (forced loading)
108
if grep -q 'slamr\..*o' /lib/modules/`uname -r`/modules.dep ;
110
if $modprobe slamr 2>&1 | grep -q not.found ; then
113
SLMODEMD_DEVICE=slamr0
121
if [ "$ALSA" ] ; then
122
# either detected or choosed by user, the driver must already be loaded
123
# and the device name be picked up before
125
OPTS=" --alsa $OPTS $SLMODEMD_DEVICE"
129
if test "$SLMODEMD_DEVICE" ; then
130
OPTS="$OPTS /dev/$SLMODEMD_DEVICE"
133
if uname -a | grep -q x86_64 ; then
134
echo "Only access through ALSA is available on amd64 but slamr driver was chosen!"
135
echo "Make sure that an ALSA driver for your chipset is available and is loaded"
136
echo "and that access to SmartLink modem components is supported by it."
140
# installed as module so just load it or bail out
141
if MODPROBE_OPTIONS="" $modprobe slamr 2>&1 | grep -q not.found ; then
142
echo "SmartLink modem driver not available for this Kernel. Please read README.Debian"
143
echo "or try to install the package sl-modem-dkms. Exiting..."
151
echo -n "Starting SmartLink Modem driver for: $SLMODEMD_DEVICE"
152
ulimit -Hl unlimited; ulimit -Sl unlimited
153
start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --make-pidfile --background --quiet -- $OPTS
155
if [ "$RETVAL" = 0 ] && [ "$NOSYMLINK" != 1 ] ; then
157
echo "Creating /dev/modem symlink, pointing to: /dev/ttySL0."
158
ln -sf ttySL0 /dev/modem
163
echo -n "Shutting down SmartLink Modem driver normally"
165
if [ "`pidof $NAME`" ] ; then
166
if start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry 1 ; then
169
echo " probably failed."
170
echo "Trying it the hard way (send SIGKILL all $NAME processes): "
171
killall -KILL $NAME || RETVAL=1
174
echo " ... no $NAME daemon running."
176
test "$RETVAL" -ne 0 || rm -f "$PIDFILE"
177
echo -n "Unloading modem driver from kernel ... "
179
for x in $unloadllist ; do
180
if grep -l -q "^$x " /proc/modules ; then
181
$modprobe -r $x 2>/dev/null && msg="$x." || msg="failed."
188
echo -n "Status of $DESC: "
189
if [ ! -r "$PIDFILE" ]; then
190
echo "$NAME is not running."
193
if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
194
echo "$NAME is running."
197
echo "$NAME is not running but $PIDFILE exists."
202
# See how we were called. Consider udev action too.
212
# slusb via udev part
213
if [ "$DEVICE" ] ; then
214
SLMODEMD_DEVICE="$DEVICE"
216
SLMODEMD_DEVICE="$DEVNAME"
219
if [ -r "$SLMODEMD_DEVICE" ]
221
# check if $GROUP really exists
222
if getent group $GROUP > /dev/null; then
223
chmod 660 "$SLMODEMD_DEVICE"
224
chown root:$GROUP "$SLMODEMD_DEVICE"
236
restart|reload|force-reload)
247
echo "Usage: /etc/init.d/sl-modem-daemon {start|stop|restart|status}"