2007-05-06 13:54:52 +00:00
/*****************************************************************************\
* * * *
2007-07-07 15:13:20 +00:00
* * LCR * *
2007-05-06 13:54:52 +00:00
* * * *
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * *
* * Copyright : Andreas Eversberg * *
* * * *
* * generate start / stop script * *
* * * *
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <stdarg.h>
2007-07-15 10:01:27 +00:00
# include "macro.h"
2007-05-06 13:54:52 +00:00
int type [ 256 ] ;
2008-07-12 17:07:52 +00:00
int coredebug = 0 , carddebug = 0 , dspdebug = 0 ;
2007-05-06 13:54:52 +00:00
int lawopt = 0 ;
2008-07-12 17:07:52 +00:00
struct cards {
2008-09-02 00:02:11 +00:00
const char * name ;
const char * module ;
2007-05-06 13:54:52 +00:00
} cards [ ] = {
2008-07-12 17:07:52 +00:00
// { "AVM Fritz PCI (PNP)", "avmfritz"},
{ " HFC PCI (Cologne Chip) " , " hfcpci " } ,
{ " HFC-4S / HFC-8S / HFC-E1 (Cologne Chip) " , " hfcmulti " } ,
{ " HFC-S USB (Cologne Chip) " , " hfcsusb " } ,
// { "HFC-S MINI (Cologne Chip)", "hfcsmini"},
// { "XHFC (Cologne Chip)", "xhfc"},
// { "Sedlbaur FAX", "sedlfax"},
// { "Winbond 6692 PCI", "w6692pci"},
{ NULL , NULL }
2007-05-06 13:54:52 +00:00
} ;
int main ( void )
{
FILE * fp ;
2008-07-12 17:07:52 +00:00
int i = 0 , j , jj , n ;
char input [ 256 ] , file [ 256 ] ;
2015-11-26 17:39:48 +00:00
int __attribute__ ( ( __unused__ ) ) ret ;
2008-06-01 16:52:10 +00:00
2007-05-06 13:54:52 +00:00
printf ( " \n \n This program generates a script, which is used to start/stop/restart mISDN \n " ) ;
2008-07-12 17:07:52 +00:00
printf ( " driver. Please select card only once. Mode and options are given by LCR. \n " ) ;
2007-05-06 13:54:52 +00:00
2009-07-05 20:14:21 +00:00
while ( 1 ) {
2008-07-12 17:07:52 +00:00
printf ( " \n Select %sdriver for cards: \n \n " , i ? " another " : " " ) ;
jj = 0 ;
2009-07-05 20:14:21 +00:00
while ( cards [ jj ] . name ) {
2008-07-12 17:07:52 +00:00
printf ( " (%d) %s \n " , jj + 1 , cards [ jj ] . name ) ;
jj + + ;
}
2009-07-05 20:14:21 +00:00
do {
2008-07-12 17:07:52 +00:00
printf ( " \n Select driver number[1-n] (or enter 'done'): " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , input ) ;
2008-07-12 17:07:52 +00:00
} while ( atoi ( input ) < = 0 & & ! ! strcmp ( input , " done " ) ) ;
type [ i ] = atoi ( input ) ;
2007-05-06 13:54:52 +00:00
i + + ;
2008-07-12 17:07:52 +00:00
if ( ! strcmp ( input , " done " ) )
break ;
2007-05-06 13:54:52 +00:00
}
2009-07-05 20:14:21 +00:00
if ( ! i ) {
2008-07-12 17:07:52 +00:00
printf ( " \n No cards defined! \n " ) ;
2007-05-06 13:54:52 +00:00
return ( - 1 ) ;
}
printf ( " \n Enter LAW audio mode. For a-LAW (default), just enter 0. For u-LAW enter 1. \n [0..n | 0xn]: " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , input ) ;
2007-05-06 13:54:52 +00:00
lawopt = strtoul ( input , NULL , 0 ) ;
printf ( " \n Enter debugging flags of mISDN core. For no debug, just enter 0. \n [0..n | 0xn]: " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , input ) ;
2007-05-06 13:54:52 +00:00
coredebug = strtoul ( input , NULL , 0 ) ;
printf ( " \n Enter debugging flags of cards. For no debug, just enter 0. \n [0..n | 0xn]: " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , input ) ;
2007-05-06 13:54:52 +00:00
carddebug = strtoul ( input , NULL , 0 ) ;
printf ( " \n Enter dsp debugging flags of driver. For no debug, just enter 0. \n [0..n | 0xn]: " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , input ) ;
2007-05-06 13:54:52 +00:00
dspdebug = strtoul ( input , NULL , 0 ) ;
n = i ;
2007-07-07 15:13:20 +00:00
printf ( " \n Where do you like to load the modules from, enter 0 for default, 1 for \n '/usr/local/lcr/modules/' or the full path. \n [0 | 1 | <path>]: " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , input ) ;
2007-05-06 13:54:52 +00:00
if ( ! strcmp ( input , " 0 " ) )
SCPY ( input , " " ) ;
if ( ! strcmp ( input , " 1 " ) )
2007-07-07 15:13:20 +00:00
SCPY ( input , " /usr/local/lcr/modules " ) ;
2007-05-06 13:54:52 +00:00
if ( input [ 0 ] ) if ( input [ strlen ( input ) - 1 ] ! = ' / ' )
SCAT ( input , " / " ) ;
2008-07-12 17:07:52 +00:00
printf ( " \n \n Finally tell me where to write the mISDN rc file. \n Enter the name 'mISDN' for current directory. \n You may want to say '/usr/local/lcr/mISDN' or '/etc/rc.d/mISDN' \n : " ) ; fflush ( stdout ) ;
2010-03-11 13:07:20 +00:00
ret = scanf ( " %s " , file ) ;
2009-07-05 20:14:21 +00:00
if ( ! ( fp = fopen ( file , " w " ) ) ) {
2008-07-12 17:07:52 +00:00
fprintf ( stderr , " \n Error: Failed to open '%s', try again. \n " , file ) ;
2007-07-15 10:01:27 +00:00
exit ( EXIT_FAILURE ) ;
2007-05-06 13:54:52 +00:00
}
fprintf ( fp , " # rc script for mISDN driver \n \n " ) ;
fprintf ( fp , " case \" $1 \" in \n " ) ;
fprintf ( fp , " \t start|--start) \n " ) ;
2008-02-03 12:47:33 +00:00
fprintf ( fp , " \t \t %s %smISDN_core%s debug=0x%x \n " , input [ 0 ] ? " insmod -f " : " modprobe --ignore-install " , input , input [ 0 ] ? " .ko " : " " , coredebug ) ;
fprintf ( fp , " \t \t %s %smISDN_dsp%s debug=0x%x options=0x%x \n " , input [ 0 ] ? " insmod -f " : " modprobe --ignore-install " , input , input [ 0 ] ? " .ko " : " " , dspdebug , lawopt ) ;
2007-05-06 13:54:52 +00:00
j = 0 ;
2009-07-05 20:14:21 +00:00
while ( cards [ j ] . name ) {
2008-07-12 17:07:52 +00:00
jj = 0 ;
2009-07-05 20:14:21 +00:00
while ( jj < n ) {
2008-07-12 17:07:52 +00:00
if ( type [ jj ] = = j + 1 )
fprintf ( fp , " \t \t %s %s%s%s debug=0x%x \n " , input [ 0 ] ? " insmod -f " : " modprobe --ignore-install " , input , cards [ j ] . module , input [ 0 ] ? " .ko " : " " , carddebug ) ;
jj + + ;
2007-05-06 13:54:52 +00:00
}
j + + ;
}
fprintf ( fp , " \t \t sleep 1 \n " ) ;
fprintf ( fp , " \t \t ;; \n \n " ) ;
fprintf ( fp , " \t stop|--stop) \n " ) ;
2009-07-05 20:14:21 +00:00
while ( j ) {
2008-07-12 17:07:52 +00:00
j - - ;
jj = 0 ;
2009-07-05 20:14:21 +00:00
while ( jj < n ) {
2008-07-12 17:07:52 +00:00
if ( type [ jj ] = = j + 1 )
fprintf ( fp , " \t \t rmmod %s \n " , cards [ j ] . module ) ;
jj + + ;
2007-05-06 13:54:52 +00:00
}
}
fprintf ( fp , " \t \t rmmod mISDN_dsp \n " ) ;
fprintf ( fp , " \t \t rmmod mISDN_core \n " ) ;
fprintf ( fp , " \t \t ;; \n \n " ) ;
fprintf ( fp , " \t restart|--restart) \n " ) ;
fprintf ( fp , " \t \t sh $0 stop \n " ) ;
fprintf ( fp , " \t \t sleep 2 # some phones will release tei when layer 1 is down \n " ) ;
fprintf ( fp , " \t \t sh $0 start \n " ) ;
fprintf ( fp , " \t \t ;; \n \n " ) ;
fprintf ( fp , " \t help|--help) \n " ) ;
fprintf ( fp , " \t \t echo \" Usage: $0 {start|stop|restart|help} \" \n " ) ;
fprintf ( fp , " \t \t exit 0 \n " ) ;
fprintf ( fp , " \t \t ;; \n \n " ) ;
fprintf ( fp , " \t *) \n " ) ;
fprintf ( fp , " \t \t echo \" Usage: $0 {start|stop|restart|help} \" \n " ) ;
fprintf ( fp , " \t \t exit 2 \n " ) ;
fprintf ( fp , " \t \t ;; \n \n " ) ;
fprintf ( fp , " esac \n " ) ;
fclose ( fp ) ;
2008-07-12 17:07:52 +00:00
printf ( " \n File '%s' is written to the current directory. \n " , file ) ;
2007-05-06 13:54:52 +00:00
}