Updated mISDN to current socket trunk
[ipfire-2.x.git] / src / initscripts / init.d / mISDN
CommitLineData
c6c9630e
MT
1#!/bin/bash
2
0ca06802 3################################################################################
c6c9630e 4#
0ca06802
MT
5# misdn-init init script
6#
7# Copyright (C) 2005, Nadi Sarrar
c6c9630e 8#
0ca06802
MT
9# Nadi Sarrar <nadi@beronet.com>
10#
11# This program is free software, distributed under the terms of
12# the GNU General Public License
c6c9630e 13#
c6c9630e 14
0ca06802
MT
15#
16# USAGE:
17#
18# /usr/sbin/misdn-init start|stop|restart|config|scan|help
19#
c6c9630e 20
0ca06802
MT
21# chkconfig: 2345 35 60
22# description: mISDN Kernel Modules
c6c9630e 23
0ca06802
MT
24#
25# CONFIGURATION:
26#
27# Path to your misdn-init.conf:
28#
29misdn_init_conf="/etc/misdn-init.conf"
30#
31################################################################################
c6c9630e 32
0ca06802
MT
33#
34# change this to modify the user/group settings of /dev/mISDN
35#
36USER=asterisk
37GROUP=asterisk
c6c9630e 38
0ca06802
MT
39# HFC 8/4 (S0) Options
40master_clock=17
c6c9630e 41
0ca06802
MT
42# HFC-E1 Options
43optical=17
44los=19
45ais=20
46slip=21
47nocrc4=24
c6c9630e 48
0ca06802
MT
49# Card Settings
50ulaw=9
51dtmf=10
52pcm_slave=12
53ignore_pcm_frameclock=13
c6c9630e 54
0ca06802
MT
55rxclock=14
56crystalclock=19
c6c9630e 57
0ca06802 58watchdog=20
c6c9630e 59
c6c9630e 60
0ca06802
MT
61#dsp defaults
62dsp_options=0
c6c9630e 63
0ca06802 64poll_option=
c6c9630e 65
0ca06802 66dsp_poll_option=
c6c9630e 67
0ca06802 68dtmfthreshold_option=
c6c9630e 69
0ca06802
MT
70function check_cmd {
71 if ! which "${1}" > /dev/null; then
72 if [ "$(id -u)" != "0" ]; then
73 echo "[!!] FATAL: $1 not in path, please install and/or be root."
74 else
75 echo "[!!] FATAL: $1 not in path, please install."
76 fi
77 if [ "${2}" != "notfatal" ] ; then
78 exit 1
79 fi
80 else
81 var=$(echo ${1} | tr a-z A-Z)
82 eval "$var=`which ${1}`"
83 fi
84}
c6c9630e 85
0ca06802
MT
86check_cmd modprobe
87check_cmd rmmod
88check_cmd insmod
89check_cmd lspci
90check_cmd lsusb notfatal
91check_cmd mknod
92check_cmd bc
93check_cmd cut
94check_cmd wc
95check_cmd seq
96check_cmd sed
97
98function check_asterisk {
99 if ps ax | grep -v grep | grep asterisk > /dev/null ; then asterisk -rx "stop now" ; fi
c6c9630e
MT
100}
101
0ca06802 102function create_card_db
c6c9630e 103{
0ca06802
MT
104 cardline=""
105 cardcount=1
106 skipnext=0
107
108 IFS=$'\n'
109 NL="
c6c9630e 110"
c6c9630e 111 function addcard {
0ca06802
MT
112 cardline="${cardline}${cardcount},${1}${NL}"
113 let "cardcount = ${cardcount} + 1"
114 }
115
116 function addport {
117 let "portcount = ${portcount} + ${1}"
c6c9630e
MT
118 }
119
120 for line in $(${LSPCI} -n -d 0xd161:b410); do
0ca06802 121 addcard "4,0x4"
c6c9630e
MT
122 done
123
124 for line in $(${LSPCI} -n | ${SED} -n 's/^\(0000:\|\)\([0-9a-f]\{2\}:[0-9a-f]\{2\}.[0-9a-f]\{1\}\)\( Class \| \)[0-9a-f]\{4\}: 1397:\([0-9a-f]\{4\}\).*$/\4 \2/p'); do
125 if [ ${skipnext} -eq 1 ]; then
126 skipnext=0
127 continue
128 fi
129 case "${line}" in
130 30b1*)
131 case "${line:5}" in
132 00*)
0ca06802 133 addcard "1,0x1"
c6c9630e
MT
134 ;;
135 *)
0ca06802
MT
136 if [ $(${LSPCI} -n -s ${line:5:3} -d 0x1397:30b1 | ${WC} -l) -eq 2 ]; then
137 addcard "2,2E1"
c6c9630e
MT
138 skipnext=1
139 else
0ca06802 140 addcard "1,0x1"
c6c9630e
MT
141 fi
142 ;;
143 esac
144 ;;
145 16b8*)
0ca06802 146 addcard "8,0x8"
c6c9630e
MT
147 ;;
148 08b4*)
0ca06802
MT
149
150 if ${LSPCI} -n -v -s "${line:5}" | grep "Subsystem" | grep "1397:b567" > /dev/null ; then
151 addcard "1,0x4"
152 elif ${LSPCI} -n -v -s "${line:5}" | grep "Subsystem" | grep "1397:b566\|1397:b569" > /dev/null ; then
153 addcard "2,0x4"
c6c9630e 154 else
0ca06802 155 addcard "4,0x4"
c6c9630e
MT
156 fi
157 ;;
158 esac
159 done
0ca06802
MT
160 for line in $(${LSPCI} -n | grep "1397:\(2bd\(0\|6\|7\|8\|9\|a\|b\|c\)\|b100\)\|1043:0675\|0871:ffa\(1\|2\)\|1051:0100\|15b0:2bd0\|114f:007\(0\|1\|2\|3\)\|13d1:2bd1\|182d:3069"); do
161 addcard "1,hfcpci"
c6c9630e 162 done
0ca06802
MT
163 for line in $(${LSPCI} -n | grep "1244:\(0a00\|0e00\)"); do
164 addcard "1,avmfritz"
c6c9630e
MT
165 done
166 for line in $(${LSPCI} -n -d 1050:6692); do
0ca06802 167 addcard "1,w6692pci"
c6c9630e 168 done
0ca06802 169
c6c9630e 170 if [ -e ${LSUSB} ]; then
0ca06802
MT
171 for line in $(${LSUSB} | grep "0959:2bd0\|0675:1688\|07b0:000\(6\|7\)\|0742:200\(7\|8\|9\|A\)\|08e3:0301\|07fa:084\(7\|8\)\|07ba:0006"); do
172 addcard "1,hfcsusb"
c6c9630e
MT
173 done
174 fi
0ca06802
MT
175
176 echo "${cardline}"
c6c9630e
MT
177}
178
0ca06802 179function expand
c6c9630e 180{
0ca06802
MT
181 local IFS=$','
182 for tok in $1; do
183 if [ "$(echo $tok | ${SED} -ne 's/\([0-9]*\)-\([0-9]*\)/\1 \2/p')" != "" ]; then
184 ${SEQ} $(echo $tok | ${SED} -ne 's/\([0-9]*\)-[0-9]*/\1/p') $(echo $tok | ${SED} -ne 's/[0-9]*-\([0-9]*\)/\1/p')
185 else
186 echo $tok
187 fi
c6c9630e 188 done
0ca06802
MT
189}
190
191function load_card_modules {
192
193 carddb=$(create_card_db)
194
195 function find_carddb_line {
196 i=1
197 for l in ${carddb} ; do
198 if [ $i -eq $1 ] ; then
199 echo $l
200 return
201 fi
202 let "i=$i+1"
203 done
204 }
c6c9630e 205
0ca06802
MT
206 if [ ! -z "$1" ] ; then
207 echo "Loading only $1"
c6c9630e 208 fi
0ca06802
MT
209
210 IFS=$'\n'
211 skipnr=0
212
213 for line in $(${SED} -n -e '/^[^#]/p' ${misdn_init_conf});
214 do
215 var=$(echo "${line}" | ${CUT} -d "=" -f1)
216 val=$(echo "${line}" | ${CUT} -d "=" -f2)
217
218 case "${var}" in
219 card)
220 #echo "processing line: $val"
221 nr=$(echo "${val}" | ${CUT} -d "," -f1)
222 mod=$(echo "${val}" | ${CUT} -d "," -f2)
223 opns=$(echo "${val}" | ${CUT} -d "," -f3-)
224
225 #getting portcount from carddb
226 ports=$(find_carddb_line $nr | ${CUT} -d "," -f2)
227 let "nr = ${nr} + ${skipnr}"
228 #echo "nr $nr ports $ports mod $mod opns: $opns"
229
230 case "${mod}" in
231 2E1)
232 hfcmulti[${nr}]=1
233 hfcmulti[$((${nr} + 1))]=1
234 let "hfcports = ${hfcports} + ${ports}"
235 IFS=$','
236 for li in ${opns}; do
237 hfcmulti[${nr}]=$(echo "obase=10;2^(${!li}-1)+${hfcmulti[${nr}]}" | ${BC})
238 if [ "${li}" != "pcm_slave" ]; then
239 hfcmulti[$((${nr} + 1))]=$(echo "obase=10;2^(${!li}-1)+${hfcmulti[$((${nr}+1))]}" | ${BC})
240 fi
241 done
242 IFS=$'\n'
243 hfcmulti[$((${nr} + 1))]=$(echo "obase=10;2^(${pcm_slave}-1)+${hfcmulti[$((${nr}+1))]}" | ${BC})
244 let "skipnr = ${skipnr} + 1"
245 ;;
246 0x*)
247 hfcmulti[${nr}]=$(echo ${mod} | ${SED} -e "s/^0x\([0-9]*\)/\1/")
248 let "hfcports = ${hfcports} + ${ports}"
249 IFS=$','
250 for li in ${opns}; do
251 hfcmulti[${nr}]=$(echo "obase=10;2^(${!li}-1)+${hfcmulti[${nr}]}" | ${BC})
252 done
253 IFS=$'\n'
254 ;;
255 *)
256 other_card[${nr}]=${mod}
257 ;;
258 esac
259 ;;
260 te_ptp)
261 for li in $(expand "${val}"); do
262 layermask[${li}]="0xf"
263 protocol[${li}]=34 # 0x22 == 34
264 done
265 ;;
266 te_ptmp)
267 for li in $(expand "${val}"); do
268 layermask[${li}]="0xf"
269 protocol[${li}]=2 # 0x2 == 2
270 done
271 ;;
272 nt_*)
273 for li in $(expand "${val}"); do
274 layermask[${li}]="0x3"
275 protocol[${li}]=18 # 0x12 == 18
276 done
277 ;;
278 te_capi_ptp)
279 for li in $(expand "${val}"); do
280 layermask[${li}]="0x0"
281 protocol[${li}]=34 # 0x22 == 34
282 done
283
284 export addcapi=1
285 ;;
286 te_capi_ptmp)
287 for li in $(expand "${val}"); do
288 layermask[${li}]="0x0"
289 protocol[${li}]=2 # 0x2 == 2
290 done
291
292 export addcapi=1
293 ;;
294
295 option)
296 port=`echo "${val}" | ${SED} -e "s/^\([0-9]*\),.*/\1/"`
297 opt=`echo "${val}" | ${SED} -e "s/^[0-9]*,\(.*\)/\1/"`
298
299 if [ -z ${protocol[${port}]} ]; then
300 protocol[${port}]="0"
301 fi
302
303 IFS=$','
304 for li in ${opt}; do
305 protocol[${port}]=$(echo "obase=10;2^(${!li}-1)+${protocol[${port}]}" | ${BC})
306 done
307 IFS=$'\n'
308 ;;
309 poll)
310 poll=${val}
311 poll_option=poll=${val}
312 ;;
313 dsp_poll)
314 dsp_poll_option=poll=${val}
315 ;;
316 pcm)
317 pcm=${val}
318 ;;
319 dsp_options)
320 export dsp_options=${val}
321 ;;
322 dtmfthreshold)
323 export dtmfthreshold_option="dtmfthreshold=${val}"
324 ;;
325 debug)
326 debug=${val}
327 ;;
328 timer)
329 timer=${val}
330 ;;
331 *)
332 echo "unknown variable: ${var}"
333 ;;
334 esac
335
336 done
337
338 echo "-----------------------------------------"
339 echo " Loading module(s) for your misdn-cards:"
340 echo "-----------------------------------------"
341
342 card_index=1
343 port_index=1
344 while [ ! -z ${hfcmulti[${card_index}]} ] || [ ! -z ${other_card[${card_index}]} ];
345 do
346 if [ ! -z ${hfcmulti[${card_index}]} ]; then
347 # MODPROBE COMMAND FOR hfcmulti CARD
348 hfcmulti_type="type="
349 hfcmulti_prot="protocol="
350 hfcmulti_layer="layermask="
351 while [ ! -z ${hfcmulti[${card_index}]} ];
352 do
353 hfcmulti_type="${hfcmulti_type}$(echo "obase=16;\"0x\";${hfcmulti[${card_index}]}" | ${BC} ),"
354 let "card_index = ${card_index} + 1"
355 done
356 while [ ${hfcports} -gt 0 ];
357 do
358 if [ ! -z ${protocol[${port_index}]} ]; then
359 hfcmulti_prot="${hfcmulti_prot}$(echo "obase=16;\"0x\";${protocol[${port_index}]}" | ${BC}),"
360 else
361 hfcmulti_prot="${hfcmulti_prot}0x2,"
362 fi
363 if [ ! -z ${layermask[${port_index}]} ]; then
364 hfcmulti_layer="${hfcmulti_layer}${layermask[${port_index}]},"
365 else
366 hfcmulti_layer="${hfcmulti_layer}0xf,"
367 fi
368 let "port_index = ${port_index} + 1"
369 let "hfcports = ${hfcports} - 1"
370 done
371 hfcmulti_type="$(echo ${hfcmulti_type} | ${SED} -e 's/^\(.*\),$/\1/')"
372 hfcmulti_prot="$(echo ${hfcmulti_prot} | ${SED} -e 's/^\(.*\),$/\1/')"
373 hfcmulti_layer="$(echo ${hfcmulti_layer} | ${SED} -e 's/^\(.*\),$/\1/')"
374 hfcmulti_cmd="${MODPROBE} --ignore-install hfcmulti ${hfcmulti_type} ${hfcmulti_prot} ${hfcmulti_layer}"
375 if [ ! -z ${poll} ]; then
376 hfcmulti_cmd="${hfcmulti_cmd} poll=${poll}"
377 fi
378 if [ ! -z ${pcm} ]; then
379 hfcmulti_cmd="${hfcmulti_cmd} pcm=${pcm}"
380 fi
381 if [ ! -z ${debug} ]; then
382 hfcmulti_cmd="${hfcmulti_cmd} debug=${debug}"
383 fi
384
385 if [ ! -z ${timer} ]; then
386 hfcmulti_cmd="${hfcmulti_cmd} timer=${timer}"
387 fi
388
389 if [ -z "$1" ] ; then
390 echo ${hfcmulti_cmd}
391 eval ${hfcmulti_cmd}
392 else
393 if [ "$1" = "hfcmulti" ] ; then
394 echo ${hfcmulti_cmd}
395 eval ${hfcmulti_cmd}
396 fi
397 fi
398 else
399 # MODPROBE COMMAND FOR _NON_ hfcmulti CARD
400 other_mod="${other_card[${card_index}]}"
401 other_cmd="${MODPROBE} --ignore-install ${other_mod}"
402 if [ ! -z ${protocol[${port_index}]} ]; then
403 other_prot="protocol=$(echo "obase=16;\"0x\";${protocol[${port_index}]}" | ${BC}),"
404 else
405 other_prot="protocol=0x2,"
406 fi
407 if [ ! -z ${layermask[${port_index}]} ]; then
408 other_layer="layermask=${layermask[${port_index}]},"
409 else
410 other_layer="layermask=0xf,"
411 fi
412 other_extra=""
413 modinfo $other_mod | egrep -q 'parm: *poll' && other_extra="$other_extra ${poll_option}"
414
415 let "prev = ${card_index}"
416 let "card_index = ${card_index} + 1"
417 let "port_index = ${port_index} + 1"
418 while [ "${other_card[${card_index}]}" == "${other_card[${prev}]}" ];
419 do
420 if [ ! -z ${protocol[${port_index}]} ]; then
421 other_prot="${other_prot}$(echo "obase=16;\"0x\";${protocol[${port_index}]}" | ${BC}),"
422 else
423 other_prot="${other_prot}0x2,"
424 fi
425 if [ ! -z ${layermask[${port_index}]} ]; then
426 other_layer="${other_layer}${layermask[${port_index}]},"
427 else
428 other_layer="${other_layer}0xf,"
429 fi
430 let "prev = ${card_index}"
431 let "card_index = ${card_index} + 1"
432 let "port_index = ${port_index} + 1"
433 done
434
435 other_prot="$(echo ${other_prot} | ${SED} -e 's/^\(.*\),$/\1/')"
436 other_layer="$(echo ${other_layer} | ${SED} -e 's/^\(.*\),$/\1/')"
437 other_cmd="${other_cmd} ${other_prot} ${other_layer} ${other_extra}"
438
439 if [ -z "$1" ] ; then
440 echo "${other_cmd}"
441 eval ${other_cmd}
442 else
443 if [ "$1" = "${other_card[${prev}]}" ] ; then
444 echo ${other_cmd}
445 eval ${other_cmd}
446 fi
447 fi
448
449
450 fi
451 done
c6c9630e
MT
452}
453
0ca06802
MT
454function unload_card_modules {
455
456 IFS=$'\n'
457
458 for line in $(${SED} -ne '/^[^#]/p' ${misdn_init_conf});
459 do
460 var=$(echo "${line}" | ${CUT} -d "=" -f 1)
461 val=$(echo "${line}" | ${CUT} -d "=" -f 2)
462
463 case "${var}" in
464 card)
465 nr=$(echo "${val}" | ${CUT} -d "," -f 1)
466 mod=$(echo "${val}" | ${CUT} -d "," -f 2)
467 case "${mod}" in
468 2E1)
469 modulelist[${nr}]=hfcmulti
470 ;;
471 0x*)
472 modulelist[${nr}]=hfcmulti
473 ;;
474 *)
475 modulelist[${nr}]=${mod}
476 ;;
477 esac
478 ;;
479 esac
480
481 done
482
483 echo "-------------------------------------------"
484 echo " Unloading module(s) for your misdn-cards:"
485 echo "-------------------------------------------"
486
487 rmmod_cmd="${RMMOD} ${modulelist[1]}"
488 echo "${rmmod_cmd}"
489 eval ${rmmod_cmd}
c6c9630e 490
0ca06802
MT
491 index=2
492 prev=1
493 while [ ! -z ${modulelist[${index}]} ];
494 do
495 if [ ${modulelist[${index}]} != ${modulelist[${prev}]} ]; then
496 rmmod_cmd="${RMMOD} ${modulelist[${index}]}"
497 echo "${rmmod_cmd}"
498 eval ${rmmod_cmd}
499 fi
500 let "prev = ${index}"
501 let "index = ${index} + 1"
c6c9630e
MT
502 done
503}
504
0ca06802
MT
505function create_misdn_init_conf {
506 cardline=""
507 cardcount=1
508 portcount=0
509 cardconf=""
510 IFS=$'\n'
511 NL="
512"
513 carddb=$(create_card_db)
514
515 for line in $carddb ; do
516 tmp="card=$(echo $line | ${CUT} -d, -f1,3)"
517 let "portcount = ${portcount} + $(echo $line | ${CUT} -d, -f2)"
518 cardline="${cardline}${tmp}${NL}"
519 done
c6c9630e 520
0ca06802
MT
521 function die {
522 echo "[!!] ${1}"
523 exit 1
524 }
525
526 if [ "${1}" == "scan" ]; then
527 echo "[OK] found the following devices:"
528 echo "${cardline}[ii] run \"/usr/sbin/misdn-init config\" to store this information to ${misdn_init_conf}"
529 else
530
531 index=1
532 portline="te_ptmp="
533 while [ ${index} -le ${portcount} ]; do
534 portline="${portline}${index},"
535 let "index = ${index} + 1"
536 done
537 portline="$(echo ${portline} | ${SED} -e 's/^\(.*\),$/\1/')"
538
539 misdn_cfg_pt1="#
540# Configuration file for your misdn hardware
c6c9630e 541#
0ca06802 542# Usage: /usr/sbin/misdn-init start|stop|restart|config|scan|help
c6c9630e
MT
543#
544
0ca06802
MT
545#
546# Card Settings
547#
548# Syntax: card=<number>,<type>[,<option>...]
549#
550# <number> count your cards beginning with 1
551# <type> either 0x1,0x4 or 0x8 for your hfcmulti hardware,
552# or the name of your card driver module.
553# <option> ulaw - uLaw (instead of aLaw)
554# dtmf - enable DTMF detection on all B-channels
555#
556# pcm_slave - set PCM bus into slave mode
557# If you have a set of cards, all wired via PCM. Set
558# all cards into pcm_slave mode and leave one out.
559# The left card will automatically be Master.
560#
561# ignore_pcm_frameclock - this can be set in conjunction with
562# pcm_slave. If this card has a
563# PCI Bus Position before the Position
564# of the Master, then this port cannot
565# yet receive a frameclock, so it must
566# ignore the pcm frameclock.
567#
568# rxclock - use clocking for pcm from ST Port
569# crystalclock - use clocking for pcm from PLL (genrated on board)
570# watchdog - This dual E1 Board has a Watchdog for
571# transparent mode
572#
573#"
574 misdn_cfg_pt2="#
575# Port settings
576#
577# Syntax: <port_type>=<port_number>[,<port_number>...]
578#
579# <port_type> te_ptp - TE-Mode, PTP
580# te_ptmp - TE-Mode, PTMP
581# te_capi_ptp - TE-Mode (capi), PTP
582# te_capi_ptmp - TE-Mode (capi), PTMP
583# nt_ptp - NT-Mode, PTP
584# nt_ptmp - NT-Mode, PTMP
585# <port_number> port that should be considered
586#"
587 misdn_cfg_pt3="#
588# Port Options
589#
590# Syntax: option=<port_number>,<option>[,<option>...]
591#
592# <option> master_clock - use master clock for this S/T interface
593# (only once per chip, only for HFC 8/4)
594# optical - optical (only HFC-E1)
595# los - report LOS (only HFC-E1)
596# ais - report AIS (only HFC-E1)
597# slip - report SLIP (only HFC-E1)
598# nocrc4 - turn off crc4 mode use double frame instead
599# (only HFC-E1)
600#
601# The master_clock option is essential for retrieving and transmitting
602# faxes to avoid failures during transmission. It tells the driver to
603# synchronize the Card with the given Port which should be a TE Port and
604# connected to the PSTN in general.
605#
606#option=1,master_clock
607#option=2,ais,nocrc4
608#option=3,optical,los,ais,slip
c6c9630e 609
c6c9630e 610
0ca06802
MT
611#
612# General Options for your hfcmulti hardware
613#
614# poll=<number>
615#
616# Only one poll value must be given for all cards.
617# Give the number of samples for each fifo process.
618# By default 128 is used. Decrease to reduce delay, increase to
619# reduce cpu load. If unsure, don't mess with it!!!
620# Valid is 32, 64, 128, 256.
621#
622# dsp_poll=<number>
623# This is the poll option which is used by mISDN_dsp, this might
624# differ from the one given by poll= for the hfc based cards, since
625# they can only use multiples of 32, the dsp_poll is dependant on
626# the kernel timer setting which can be found in the CPU section
627# in the kernel config. Defaults are there either 100Hz, 250Hz
628# or 1000Hz. If your setting is either 1000 or 250 it is compatible
629# with the poll option for the hfc chips, if you have 100 it is
630# different and you need here a multiple of 80.
631# The default is to have no dsp_poll option, then the dsp itself
632# finds out which option is the best to use by itself
633#
634# pcm=<number>
635#
636# Give the id of the PCM bus. All PCM busses with the same ID
637# are expected to be connected and have equal slots.
638# Only one chip of the PCM bus must be master, the others slave.
639#
640# debug=<number>
641#
642# Enable debugging (see hfc_multi.h for debug options).
643#
644# dsp_options=<number>
645#
646# set this to 2 and you'll have software bridging instead of
647# hardware bridging.
648#
649#
650# dtmfthreshold=<milliseconds>
651#
652# Here you can tune the sensitivity of the dtmf tone recognizer.
653#
654# timer=<1|0>
655#
656# set this to 1 if you want hfcmulti to register at ztdummy (zaptel)
657# and provide a 1khz timing source for it. This makes it possible
658# to have an accurate timing source for asterisk through zaptel from
659# hfcmulti to make applications like Meetme and faxing between wctdm
660# and hfcmulti work properly.
661#
662poll=128
adf8eb98 663dsp_poll=80
0ca06802
MT
664dsp_options=0
665dtmfthreshold=100
666debug=0"
667
668 if [ -f ${misdn_init_conf} ]; then
669 cp "${misdn_init_conf}" "${misdn_init_conf}.save" || die "could not backup your existing ${misdn_init_conf}!"
670 echo "[OK] ${misdn_init_conf} already present. backing it up to ${misdn_init_conf}.save"
671 fi
672 echo "${misdn_cfg_pt1}${NL}${cardline}${NL}${misdn_cfg_pt2}${NL}${portline}${NL}${NL}${misdn_cfg_pt3}" > ${misdn_init_conf} || die "could not write to /etc/misdn-init.conf!"
673#echo "${misdn_cfg_pt1}${NL}${cardline}${NL}${misdn_cfg_pt2}${NL}${portline}${NL}${NL}${misdn_cfg_pt3}" > testconf || die "could not write to /etc/misdn-init.conf!"
674
675 echo "[OK] ${misdn_init_conf} created. It's now safe to run \"/usr/sbin/misdn-init start\""
676 if [ ${portcount} -gt 1 ]; then
677 echo "[ii] make your ports (1-${portcount}) available in asterisk by editing \"/etc/asterisk/misdn.conf\""
678 elif [ ${portcount} -eq 1 ]; then
679 echo "[ii] make your port (1) available in asterisk by editing \"/etc/asterisk/misdn.conf\""
680 fi
681 fi
682}
683
684function check_cfg_file {
685 if [ ! -f ${misdn_init_conf} ]; then
686
687 if [ ! -z "$1" ] ; then
688 /usr/sbin/misdn-init config
689 else
690 echo "[!!] failed to load: ${misdn_init_conf}"
691 echo "run \"/usr/sbin/misdn-init config\" to scan your devices and generate a basic config file."
692 exit 1
693 fi
694 fi
695}
696
697# MAIN #############
698
699case "$1" in
700 start|--start)
701 check_cfg_file $2
702
703 ${MODPROBE} capi
704 ${MODPROBE} mISDN_core debug=0
705 ${MODPROBE} mISDN_l1 debug=0
706 ${MODPROBE} mISDN_l2 debug=0
707 ${MODPROBE} l3udss1 debug=0
708 ${MODPROBE} mISDN_capi
709
710 load_card_modules $2
711
712 echo "${MODPROBE} mISDN_dsp debug=0x0 options=$dsp_options $dsp_poll_option $dtmfthreshold_option"
713 ${MODPROBE} mISDN_dsp debug=0x0 options=$dsp_options $dsp_poll_option $dtmfthreshold_option
714 sleep 1
715
716 if [ ! -e /dev/mISDN ]; then
717 $MKNOD /dev/mISDN c 46 0
718 if grep asterisk /etc/passwd > /dev/null; then
719 chown $USER:$GROUP /dev/mISDN
720 fi
721 echo "[i] creating device node: /dev/mISDN"
722 fi
c6c9630e
MT
723 ;;
724
725 stop|--stop)
0ca06802
MT
726
727 check_cfg_file
728
729 check_asterisk
730
731
732 for mod in $(lsmod | ${SED} -ne '/Module/!{s/\([^ ]*\).*/\1/;p}');
733 do
734 case "${mod}" in
735 mISDN_capi | mISDN_dsp | l3udss1 | mISDN_l2 | mISDN_l1 | mISDN_isac )
736 eval "${RMMOD} ${mod}"
737 ;;
738 esac
739 done
740
741 unload_card_modules
742
743 ${RMMOD} mISDN_core
c6c9630e 744
c6c9630e
MT
745 ;;
746
747 restart|--restart)
0ca06802
MT
748
749 check_cfg_file
c6c9630e 750
0ca06802
MT
751 sh $0 stop
752 sleep 2 # some phones will release tei when layer 1 is down
753 sh $0 start
c6c9630e
MT
754 ;;
755
756 config|--config)
0ca06802
MT
757
758 create_misdn_init_conf
759
c6c9630e
MT
760 ;;
761
762 scan|--scan)
763
0ca06802
MT
764 create_misdn_init_conf scan
765
c6c9630e
MT
766 ;;
767
768 help|--help)
0ca06802 769 echo "Usage: $0 {start|stop|restart|config|scan|help}"
c6c9630e
MT
770 exit 0
771 ;;
772
773 *)
0ca06802 774 echo "Usage: $0 {start|stop|restart|config|scan|help}"
c6c9630e
MT
775 exit 2
776 ;;
777
778esac
779
0ca06802 780