summaryrefslogtreecommitdiff
blob: 4c6124a25dfbadce6c138b963acec80594861d7d (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
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dialup/isdn4k-utils/files/isdn.initd,v 1.4 2006/02/04 21:14:17 sbriesen Exp $

opts="${opts} save reload makedev info"

depend() {
	use hisax
	[ "$DEPEND_ON_CAPI" = "yes" ] && need capi
}

# gets list of installed cards
card_list() {  # output: <contr> <chan> <card>
	local IDMAP=() IDX=1 CONTR=0 LAST='-' CARD=''
	read -a IDMAP < <(/bin/head 2>/dev/null -n1 /dev/isdninfo) || return 1
	while [ ${IDX} -lt ${#IDMAP[*]} ]; do
		CARD=${IDMAP[$IDX]}
		if [ "${CARD}" != "-" -a "${CARD}" != "${LAST}" ]; then
			echo "${CONTR} $((IDX-1)) ${CARD}"; : $((CONTR++))
		fi
		LAST="${CARD}"; : $((IDX++))
	done
}

# gets CAPI controller name
capi_name() {  # <contr>
	/bin/sed -n "s:^${1} \+[^ ]\+ \+[^ ]\+ \+\([^ ]\+\) \+.\+\$:\1:p" \
		/proc/capi/controller 2>/dev/null
}

# displays installed ISDN cards
show_cards() {  # < $(card_list)
	local CONTR CHAN CARD CAPI
	while read CONTR CHAN CARD; do
		case "${CARD}" in
			capidrv-[1-9]*)
				CAPI=$(capi_name ${CARD/capidrv-})
				einfo "${1}${CONTR} ${CARD} (${CAPI})"
				;;
			*)
				einfo "${1}${CONTR} ${CARD}"
				;;
		esac
	done
}

# creates ISDN devices for static /dev and udev
makedev() {
	if [ ! -e /dev/.devfsd ]; then
		local CHAN
		pushd /dev >/dev/null || return 1
		ebegin "Creating ISDN devices"
		/bin/rm -f isdninfo isdnctrl* ippp[0-9]* isdn[0-9]* ttyI[0-9]*
		for ((CHAN = 0; CHAN < ISDN_MAX_CHANNELS; CHAN++)); do
			/bin/mknod -m "${ISDNDEV_MODE}" isdn${CHAN}     c 45 $((CHAN))       # b
			/bin/mknod -m "${ISDNDEV_MODE}" isdnctrl${CHAN} c 45 $((CHAN + 64))  # ctrl
			/bin/mknod -m "${ISDNDEV_MODE}" ippp${CHAN}     c 45 $((CHAN + 128)) # ppp
			/bin/mknod -m "${ISDNDEV_MODE}" ttyI${CHAN}     c 43 $((CHAN))       # tty
		done
		/bin/chgrp "${ISDNDEV_GROUP}" isdnctrl* ippp[0-9]* isdn[0-9]* ttyI[0-9]*
		/bin/mknod -m 444 isdninfo c 45 255
		/bin/ln -snf isdnctrl0 isdnctrl
		popd >/dev/null
		eend 0
	fi
}


start() {
	# create ISDN devices if necessary
	[ -c /dev/isdninfo -a -c /dev/isdnctrl0 ] || makedev

	local LIST="$(card_list)"

	if [ -z "${LIST}" ]; then
		eerror "ERROR: no ISDN cards available"
		return 1
	fi

	ebegin "Loading isdnctrl configuration"
	[ ! -f "${ISDNCTRL_CONFIG}" ] || /usr/sbin/isdnctrl readconf "${ISDNCTRL_CONFIG}" >/dev/null
	eend $?
	
	if [ -n "${IPROFD_SETTINGS}" ]; then
		ebegin "Starting modem-register daemon"
		start-stop-daemon 2>/dev/null --start --quiet --exec /usr/sbin/iprofd -- "${IPROFD_SETTINGS}"
		eend $?
	fi

	einfo "Available ISDN cards:"
	show_cards "  " < <(echo "${LIST}")
	return 0
}

stop() {
	local RET FCNT=0

        # if some other monitoring processes are running, kill 'em
	if /bin/fuser 2>/dev/null -s /dev/isdninfo; then
		ebegin "Stopping monitoring processes"
		/bin/fuser -ks /dev/isdninfo; RET=$?
		while [ ${RET} -eq 0 -a ${FCNT} -lt 10 ]; do
			: $((FCNT++)); sleep 0.5; /bin/fuser -s /dev/isdninfo; RET=$?
		done
		[ $RET -ne 0 ]
		eend $?
	fi

	if [ -n "${IPROFD_SETTINGS}" ]; then
		ebegin "Stopping modem-register daemon"
		start-stop-daemon 2>/dev/null --stop --quiet --retry 5 --exec /usr/sbin/iprofd
		eend $?
	fi

	ebegin "Unloading isdnctrl configuration"
	/usr/sbin/isdnctrl reset force &>/dev/null
	eend $?

	return 0  # ignore errors
}

save() {
	ebegin "Saving isdnctrl configuration"
	/usr/sbin/isdnctrl writeconf "${ISDNCTRL_CONFIG}" >/dev/null
	eend $?
}

reload() {
	ebegin "Reloading isdnctrl configuration"
	/usr/sbin/isdnctrl reset >/dev/null
	[ ! -f "${ISDNCTRL_CONFIG}" ] || \
	/usr/sbin/isdnctrl readconf "${ISDNCTRL_CONFIG}" >/dev/null
	eend $?
}

info() {
	local LIST="$(card_list)"
	if [ -z "${LIST}" ]; then
		eerror "ERROR: no ISDN cards available"
		return 1
	fi
	show_cards < <(echo "${LIST}")
}