]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/mISDN
3 ################################################################################
5 # misdn-init init script
7 # Copyright (C) 2005, Nadi Sarrar
9 # Nadi Sarrar <nadi@beronet.com>
11 # This program is free software, distributed under the terms of
12 # the GNU General Public License
18 # /usr/sbin/misdn-init start|stop|restart|config|scan|help
21 # chkconfig: 2345 35 60
22 # description: mISDN Kernel Modules
27 # Path to your misdn-init.conf:
29 misdn_init_conf
= "/etc/misdn-init.conf"
31 ################################################################################
34 # change this to modify the user/group settings of /dev/mISDN
39 # HFC 8/4 (S0) Options
53 ignore_pcm_frameclock
= 13
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."
75 echo "[!!] FATAL: $1 not in path, please install."
77 if [ " ${2} " != "notfatal" ] ; then
81 var
= $
( echo ${1} |
tr a-z A-Z
)
82 eval " $var =`which ${1} `"
90 check_cmd lsusb notfatal
98 function check_asterisk
{
99 if ps ax |
grep -v grep |
grep asterisk
> / dev
/ null
; then asterisk
-rx "stop now" ; fi
102 function create_card_db
112 cardline
= " ${cardline}${cardcount},${1}${NL} "
113 let "cardcount = ${cardcount} + 1"
117 let "portcount = ${portcount} + ${1} "
120 for line
in $
( ${LSPCI} -n -d 0xd161 : b410
); do
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
136 if [ $( ${LSPCI} -n -s ${line:5:3} -d 0x1397:30b1 | ${WC} -l) -eq 2 ]; then
150 if ${LSPCI} -n -v -s " ${line:5} " | grep "Subsystem" | grep "1397:b567" > /dev/null ; then
152 elif ${LSPCI} -n -v -s " ${line:5} " | grep "Subsystem" | grep "1397:b566\|1397:b569" > /dev/null ; then
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
163 for line in $( ${LSPCI} -n | grep "1244:\(0a00\|0e00\)"); do
166 for line in $( ${LSPCI} -n -d 1050:6692); do
170 if [ -e ${LSUSB} ]; then
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
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
')
191 function load_card_modules {
193 carddb=$(create_card_db)
195 function find_carddb_line {
197 for l in ${carddb} ; do
198 if [ $i -eq $1 ] ; then
206 if [ ! -z " $1 " ] ; then
207 echo "Loading only $1 "
213 for line in $( ${SED} -n -e ' / ^
[ ^
#]/p' ${misdn_init_conf});
215 var
= $
( echo " ${line} " |
${CUT} -d "=" -f1 )
216 val
= $
( echo " ${line} " |
${CUT} -d "=" -f2 )
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- )
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"
233 hfcmulti
[ $
(( ${nr} + 1 ))]= 1
234 let "hfcports = ${hfcports} + ${ports} "
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} )
243 hfcmulti
[ $
(( ${nr} + 1))]=$(echo "obase=10;2^(${pcm_slave}-1)+${hfcmulti[$((${nr}+1))]} " | ${BC} )
244 let " skipnr
= ${skipnr} + 1 "
247 hfcmulti[ ${nr}]=$(echo ${mod} | ${SED} -e " s
/ ^
0 x\
([ 0 -9 ]* \
)/ \
1 / ")
248 let " hfcports
= ${hfcports} + ${ports} "
250 for li in ${opns} ; do
251 hfcmulti[ ${nr}]=$(echo "obase=10;2^(${!li}-1)+${hfcmulti[${nr}]} " |
${BC} )
256 other_card
[ ${nr} ]= ${mod}
261 for li
in $
( expand " ${val} " ); do
262 layermask
[ ${li} ]= "0xf"
263 protocol
[ ${li} ]= 34 # 0x22 == 34
267 for li
in $
( expand " ${val} " ); do
268 layermask
[ ${li} ]= "0xf"
269 protocol
[ ${li} ]= 2 # 0x2 == 2
273 for li
in $
( expand " ${val} " ); do
274 layermask
[ ${li} ]= "0x3"
275 protocol
[ ${li} ]= 18 # 0x12 == 18
279 for li
in $
( expand " ${val} " ); do
280 layermask
[ ${li} ]= "0x0"
281 protocol
[ ${li} ]= 34 # 0x22 == 34
287 for li
in $
( expand " ${val} " ); do
288 layermask
[ ${li} ]= "0x0"
289 protocol
[ ${li} ]= 2 # 0x2 == 2
296 port
= `echo " ${val} " | ${SED} -e "s/^\([0-9]*\),.*/\1/"`
297 opt
= `echo " ${val} " | ${SED} -e "s/^[0-9]*,\(.*\)/\1/"`
299 if [ -z ${protocol[${port}]} ]; then
300 protocol
[ ${port} ]= "0"
305 protocol
[ ${port}]=$(echo "obase=10;2^(${!li}-1)+${protocol[${port}]} " | ${BC} )
311 poll_option=poll= ${val}
314 dsp_poll_option=poll= ${val}
320 export dsp_options= ${val}
323 export dtmfthreshold_option=" dtmfthreshold
= ${val} "
332 echo " unknown variable
: ${var} "
338 echo " ----------------------------------------- "
339 echo " Loading module
( s
) for your misdn-cards
: "
340 echo " ----------------------------------------- "
344 while [ ! -z ${hfcmulti[${card_index}]} ] || [ ! -z ${other_card[${card_index}]} ];
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}]} ];
353 hfcmulti_type=" ${hfcmulti_type}$(echo "obase=16;\"0x\";${hfcmulti[${card_index}]} " | ${BC} ),"
354 let "card_index = ${card_index} + 1"
356 while [ ${hfcports} -gt 0 ];
358 if [ ! -z ${protocol[${port_index}]} ]; then
359 hfcmulti_prot
= " ${hfcmulti_prot}$(echo "obase=16;\"0x\";${protocol[${port_index}]} " |
${BC} ), "
361 hfcmulti_prot=" ${hfcmulti_prot} 0x2 , "
363 if [ ! -z ${layermask[${port_index}]} ]; then
364 hfcmulti_layer=" ${hfcmulti_layer}${layermask[${port_index}]} , "
366 hfcmulti_layer=" ${hfcmulti_layer} 0xf , "
368 let " port_index
= ${port_index} + 1 "
369 let " hfcports
= ${hfcports} - 1 "
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} "
378 if [ ! -z ${pcm} ]; then
379 hfcmulti_cmd=" ${hfcmulti_cmd} pcm
= ${pcm} "
381 if [ ! -z ${debug} ]; then
382 hfcmulti_cmd=" ${hfcmulti_cmd} debug
= ${debug} "
385 if [ ! -z ${timer} ]; then
386 hfcmulti_cmd=" ${hfcmulti_cmd} timer
= ${timer} "
389 if [ -z " $1 " ] ; then
393 if [ " $1 " = " hfcmulti
" ] ; then
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} ), "
405 other_prot=" protocol
= 0x2 , "
407 if [ ! -z ${layermask[${port_index}]} ]; then
408 other_layer=" layermask
= ${layermask[${port_index}]} , "
410 other_layer=" layermask
= 0xf , "
413 modinfo $other_mod | egrep -q 'parm: *poll' && other_extra=" $other_extra ${poll_option} "
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}]} " ];
420 if [ ! -z ${protocol[${port_index}]} ]; then
421 other_prot=" ${other_prot}$(echo "obase=16;\"0x\";${protocol[${port_index}]} " | ${BC} ),"
423 other_prot
= " ${other_prot} 0x2,"
425 if [ ! -z ${layermask[${port_index}]} ]; then
426 other_layer
= " ${other_layer}${layermask[${port_index}]} ,"
428 other_layer
= " ${other_layer} 0xf,"
430 let "prev = ${card_index} "
431 let "card_index = ${card_index} + 1"
432 let "port_index = ${port_index} + 1"
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} "
439 if [ -z " $1 " ] ; then
443 if [ " $1 " = " ${other_card[${prev}]} " ] ; then
454 function unload_card_modules
{
458 for line
in $
( ${SED} -ne '/^[^#]/p' ${misdn_init_conf} );
460 var
= $
( echo " ${line} " |
${CUT} -d "=" -f 1 )
461 val
= $
( echo " ${line} " |
${CUT} -d "=" -f 2 )
465 nr
= $
( echo " ${val} " |
${CUT} -d "," -f 1 )
466 mod
= $
( echo " ${val} " |
${CUT} -d "," -f 2 )
469 modulelist
[ ${nr} ]= hfcmulti
472 modulelist
[ ${nr} ]= hfcmulti
475 modulelist
[ ${nr} ]= ${mod}
483 echo "-------------------------------------------"
484 echo " Unloading module(s) for your misdn-cards:"
485 echo "-------------------------------------------"
487 rmmod_cmd
= " ${RMMOD} ${modulelist[1]} "
493 while [ ! -z ${modulelist[${index}]} ];
495 if [ ${modulelist[${index}]} != ${modulelist[${prev}]} ]; then
496 rmmod_cmd
= " ${RMMOD} ${modulelist[${index}]} "
500 let "prev = ${index} "
501 let "index = ${index} + 1"
505 function create_misdn_init_conf
{
513 carddb
= $
( create_card_db
)
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} "
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} "
533 while [ ${index} -le ${portcount} ]; do
534 portline
= " ${portline} ${index} ,"
535 let "index = ${index} + 1"
537 portline
= "$(echo ${portline} | ${SED} -e 's/^\(.*\),$/\1/')"
540 # Configuration file for your misdn hardware
542 # Usage: /usr/sbin/misdn-init start|stop|restart|config|scan|help
548 # Syntax: card=<number>,<type>[,<option>...]
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
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.
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.
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
577 # Syntax: <port_type>=<port_number>[,<port_number>...]
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
590 # Syntax: option=<port_number>,<option>[,<option>...]
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
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.
606 #option=1,master_clock
608 #option=3,optical,los,ais,slip
612 # General Options for your hfcmulti hardware
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.
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
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.
642 # Enable debugging (see hfc_multi.h for debug options).
644 # dsp_options=<number>
646 # set this to 2 and you'll have software bridging instead of
650 # dtmfthreshold=<milliseconds>
652 # Here you can tune the sensitivity of the dtmf tone recognizer.
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.
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"
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
! "
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 \" "
684 function check_cfg_file {
685 if [ ! -f ${misdn_init_conf} ]; then
687 if [ ! -z " $1 " ] ; then
688 /usr/sbin/misdn-init config
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."
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
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
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
721 echo "[i] creating device node: /dev/mISDN"
732 for mod in $(lsmod | ${SED} -ne ' / Module
/!{ s
/ \
([ ^
]* \
) .
*/ \
1 /; p
} ');
735 mISDN_capi | mISDN_dsp | l3udss1 | mISDN_l2 | mISDN_l1 | mISDN_isac )
736 eval " ${RMMOD} ${mod} "
752 sleep 2 # some phones will release tei when layer 1 is down
758 create_misdn_init_conf
764 create_misdn_init_conf scan
769 echo "Usage: $0 {start|stop|restart|config|scan|help}"
774 echo "Usage: $0 {start|stop|restart|config|scan|help}"