summaryrefslogtreecommitdiff
blob: c866e229a8fca43dd8991bfcc601eb660eecc7e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# 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.hotplug,v 1.6 2005/05/16 08:49:33 genstef Exp $

. /etc/conf.d/capi

[ "$CAPI_HOTPLUG_USB" = "yes" ] || exit 0

# syslog output
syslog() {  # <msg>
	/usr/bin/logger -t "capi-usb" "$1"
}

beep_ok() {
	[ "$CAPI_HOTPLUG_BEEP" = "yes" ] && echo -en "\033[10;1200]\a\033[10;262]" > /dev/console
}

beep_error() {
	[ "$CAPI_HOTPLUG_BEEP" = "yes" ] && echo -en "\033[10;300]\a\033[10;262]" > /dev/console
}

# driver lookup
cardinfo() {  # <driver>
	# /proc/capi/controller: <controller> <drivername> <state> <cardname> <controllerinfo>
	/bin/sed 2>/dev/null -n "s:^\([1-9][0-9]*\) \+${1} \+\([^ ]\+\) \+\([^ ]\+\) \+\([^ ]\+\):\1 \3 \2 \4:p" /proc/capi/controller
}

# AVM firmware loader
avmusb() {  # <driver> <usbdev> <firmware>
	local CARD NAME STATUS TYPE VER DEV FIRMWARE
	while read CARD NAME STATUS TYPE VER DEV; do  # AVM cardinfo
		if [ "${STATUS}" = "detected" -a ${DEV} -eq ${2} ]; then
			syslog "loading firmware '${3}' into controller ${CARD} (${NAME})"
			/usr/sbin/avmcapictrl load "/lib/firmware/${3}" "${CARD}"
			break
		fi
	done < <(cardinfo "${1}")
}

# normalize and split product code
# only needed, because coldplug gives other results than hotplug :-/
IFS="/" read _A _B _C < <(echo "${PRODUCT}")
read VENDOR DEVID PCLASS < <(/usr/bin/printf "%04x %04x %04x" "0x${_A}" "0x${_B}" "0x${_C}")
VENDID="${VENDOR}/${DEVID}"
DEVTMP="${DEVICE##/proc/bus/usb/}"
USBBUS="${DEVTMP%%/*}"
USBDEV="${DEVTMP##*/}"

# create/check lockfile
LOCK="/tmp/.capi-usb-${USBBUS}-${USBDEV}"
/bin/ln 2>/dev/null -sn $$ ${LOCK} || exit 0
trap "/bin/rm -f ${LOCK}" 0 1 2 3 15

# select driver and firmware
LOADER=""
DRIVER=""
FIRMWARE=""
case "${VENDID}" in
	"057c/0c00") # FRITZCARD!USB
		DRIVER="fcusb";;
	"057c/1000") # FRITZCARD!USB v2.0
		DRIVER="fcusb2"; LOADER="avmusb"; FIRMWARE="fus2base.frm";;
	"057c/1900") # FRITZCARD!USB v2.1
		DRIVER="fcusb2"; LOADER="avmusb"; FIRMWARE="fus3base.frm";;
	"057c/2000") # FRITZX!USB
		DRIVER="fxusb";;
	"057c/2200") # BlueFRITZ!USB
		DRIVER="bfusb"; LOADER="avmusb"; FIRMWARE="bfubase.frm";;
	"057c/2300") # FRITZDSL!USB
		DRIVER="fcdslusb"; LOADER="avmusb"; FIRMWARE="fdsubase.frm";;
	"057c/2800") # FRITZX!USB OEM
		DRIVER="fxusb_CZ";;
	"057c/3500") # FRITZDSL!USB SL
		DRIVER="fcdslslusb"; LOADER="avmusb"; FIRMWARE="fdlubase.frm";;
	"0959/2bd0") # ISDN USB TA (Cologne Chip HFC-S USB based)
		DRIVER="hfcsusb";;
	"0675/1688") # DrayTek miniVigor 128 USB ISDN TA
		DRIVER="hfcsusb";;
	"07b0/0007") # Billion tiny USB ISDN TA 128
		DRIVER="hfcsusb";;
	"0742/2008") # Stollmann USB TA
		DRIVER="hfcsusb";;
	"0742/2009") # Aceex USB ISDN TA
		DRIVER="hfcsusb";;
	"0742/200a") # OEM USB ISDN TA
		DRIVER="hfcsusb";;
	"08e3/0301") # Olitec USB RNIS
		DRIVER="hfcsusb";;
	"07fa/0846") # Bewan Modem RNIS USB
		DRIVER="hfcsusb";;
	"07fa/0847") # Djinn Numeris USB
		DRIVER="hfcsusb";;
	"07b0/0006") # Twister ISDN TA
		DRIVER="hfcsusb";;
	*) # unknown card
		syslog "unknown USB product: ${VENDID}"
		exit 1;;
esac

if [ "$DRIVER" = "hfcsusb" -a "$CAPI_HOTPLUG_MISDN" != "yes" ]; then
	syslog "ignore mISDN card: ${DRIVER} (${VENDID})"
	exit 0
fi

case "$ACTION" in
	add)
		# loading capi
		if ! ( [ -f /proc/capi/capi20 ] || /sbin/modprobe -sq capi ); then
			syslog "could not load CAPI!"
			beep_error; exit 1
		fi
	
		# loading driver
		if ! /sbin/modprobe -sq ${DRIVER}; then
			syslog "could not load driver ${DRIVER}!"
			beep_error; exit 1
		fi
	
		# loading firmware	
		if [ -n "${LOADER}" -a -n "${FIRMWARE}" ]; then
			CNT=0  # wait for udev
			while [ ! -e /dev/capi20 -a $CNT -lt 20 ]; do
				sleep 0.5; : $((CNT++))
			done
			if [ -f "/lib/firmware/${FIRMWARE}" ]; then
				$LOADER $DRIVER $USBDEV $FIRMWARE
			else
				syslog "firmware ${FIRMWARE} not found!"
				beep_error; exit 1
			fi
		fi

		# loading capidrv (should be loaded *after* card driver)
		if ! ( [ -f /proc/capi/capidrv -o "$CAPI_LOAD_CAPIDRV" != "yes" ] || /sbin/modprobe -sq capidrv ); then
			syslog "could not load CAPIDRV!"
		fi
		
		beep_ok
		;;

	remove)
		/sbin/modprobe -sqr ${DRIVER}
		;;
esac
exit 0