Dropping DTR?

Chuck Sites chuck at laffu.UUCP
Sat Jan 28 11:17:03 AEST 1989


In article <362 at cocktrice.UUCP>, mdm at cocktrice.UUCP (Mike Mitchell) writes:
> Does anyone have a fancy trick for lowering DTR going to a modem attached
> to tty0? I have my modem set up to auto answer, however there are times
> that I do not want the modem to answer the phone.
This is what I've been doing to toggle between an auto answer, and
dial-in on Hayes type modems with uPORT. There is no Makefile with
this program, but It should be pretty easy to set up.  Look at the
shell scripts dismdm & enamdm for the directories to place
the programs modemctl, tty.on & tty.off.  To compile modemctl.c
a simple:

cc -O modemctl.c -o modemctl

will do.  You may need to change some of the parameters in
modemctl.c when setting up the ioctl call. Look at the program
if you need baud rates other than 2400.  The shell scripts I'm
using here are pretty laim, so you may want to beef these up.
At work, we are using the same modemctl.c program, but with some
much improved shell scripts to control seven different modems.
With the addition of a cron job or two, it's pretty easy to have
one of these Hayes type modems doing all kinds of wierd things
in the middle of the night :-)
----------------------- CUT HERE-----------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	dismdm
#	enamdm
#	modemctl.c
#	tty.off
#	tty.on
# This archive created: Fri Jan 27 19:17:30 1989
export PATH; PATH=/bin:$PATH
if test -f 'dismdm'
then
       echo shar: will not over-write existing file "'dismdm'"
else
cat << \SHAR_EOF > 'dismdm'
#Disable modem port from logins
/etc/tty.off t0
/usr/lib/uucp/modemctl "AT,ATE1,ATS0=0"
chown uucp /dev/tty0
chgrp bin /dev/tty0
echo "** Disable Modem at `date '+%r on %D'` **" >> /usr/spool/uucp/LOGFILE
SHAR_EOF
chmod +x 'dismdm'
fi # end of overwriting check
if test -f 'enamdm'
then
       echo shar: will not over-write existing file "'enamdm'"
else
cat << \SHAR_EOF > 'enamdm'
#Enable modem for logins
/usr/lib/uucp/modemctl -c "ATE0,ATS0=1"
/etc/tty.on t0
echo "** Enable Modem at `date '+%r on %D'` **" >> /usr/spool/uucp/LOGFILE
SHAR_EOF
chmod +x 'enamdm'
fi # end of overwriting check
if test -f 'modemctl.c'
then
       echo shar: will not over-write existing file "'modemctl.c'"
else
cat << \SHAR_EOF > 'modemctl.c'
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <termio.h>
extern int errno;

/* #define DEBUG  /* envoke debug outbut */

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

typedef int bool;

char device[40]="/dev/tty0";
char wakeup[]="\r\rAT\r\rAT\r\r";
char command[132];
char cm[40];

main(argc,argv) int argc; char *argv[]; {

        struct termio buf,obuf;
        int fd,argcnt;
        int i,j,issue;
        bool clocal;

        char c;
        
        if (argc<2) {
                fprintf(stderr,"USAGE: modemctl [-c] [-T/dev/tty##] \"Hayse AT command string\"\n");
                exit(1);
        }
        argcnt=1;
        if(*(argv[1]+0)=='-' && *(argv[1]+1)=='c') {
                ++argcnt; 
                clocal=TRUE;
        } else
                clocal=FALSE;

                
        if(*(argv[argcnt]+0)=='-' && *(argv[argcnt]+1)=='T') {
                strncpy(device,argv[argcnt]+2,40);
                ++argcnt;
        }               
#ifdef DEBUG
        printf("%s\n%s\n%s\n",argv[1],device,argv[2]);
#endif  
        fd=open(device,O_NDELAY);
        sleep(2);                       /* Toggle DTR line ON/OFF */
        close(fd);                      /* to wakeup modem.       */
        sleep(1);

        if ((fd=open(device,O_NDELAY|O_RDWR))<0) {
                perror("Modemctl error");
                exit(1);
        }
        ioctl(fd,TCGETA,&buf);
        ioctl(fd,TCGETA,&obuf);
#ifdef DEBUG
        printf("iflag=%o\noflag=%o\ncflag=%o\nlflag=%o\n\n",buf.c_iflag,buf.c_oflag,buf.c_cflag,buf.c_lflag);
#endif

        buf.c_iflag = (IGNBRK | IGNPAR | IXON | IXOFF);
        buf.c_oflag = 0;
        buf.c_cflag = (B2400 | CS8 | CREAD | CLOCAL | HUPCL);
        buf.c_lflag = 0;
        ioctl(fd,TCSETA,&buf);
        ioctl(fd,TCFLSH,2);
        close(fd);
        sleep(1);

/* second pass at opening file */ 

        if ((fd=open(device,O_NDELAY|O_RDWR))<0) {
                perror("Modemctl error");
                exit(1);
        }
        ioctl(fd,TCGETA,&buf);
        ioctl(fd,TCGETA,&obuf);

#ifdef DEBUG
        printf("iflag=%o\noflag=%o\ncflag=%o\nlflag=%o\n\n",buf.c_iflag,buf.c_oflag,buf.c_cflag,buf.c_lflag);
#endif

        buf.c_iflag = (IGNBRK | IGNPAR | IXON | IXOFF);
        buf.c_oflag = 0;
        buf.c_cflag = (B2400 | CS8 | CREAD | CLOCAL | HUPCL);
        buf.c_lflag = 0;

        ioctl(fd,TCSETA,&buf);
        ioctl(fd,TCGETA,&buf);

#ifdef DEBUG
        printf("iflag=%o\noflag=%o\ncflag=%o\nlflag=%o\n\n",buf.c_iflag,buf.c_oflag,buf.c_cflag,buf.c_lflag);
#endif
        sleep(1);
        /* issue command to modem */
        write(fd,wakeup,strlen(wakeup));
        ioctl(fd,TCFLSH,0);

        sleep(3);
        strcpy(command,argv[argcnt]);
#ifdef DEBUG
        printf("command=%s\n",command);
#endif
        i=0,j=0;
        issue=0;
        
        while (command[i] != 0) {
                cm[j]=command[i];
                if (cm[j]==',') {
                        cm[j]='\r';
                        cm[++j]=0;
                        write(fd,cm,j);
                        sleep(2);
                        ioctl(fd,TCFLSH,0);
#ifdef DEBUG
                        sleep(1);
                        printf("issue(%d)=%s\n",++issue,cm);
#endif
                        j=0;
                } else 
                        ++j;

                ++i;
        }
        cm[j]='\r';
        cm[++j] = 0;
        write(fd,cm,j);
        sleep(2);
        ioctl(fd,TCFLSH,0);
#ifdef DEBUG
        printf("issue(%d)=%s\n",++issue,cm);
#endif

        buf.c_iflag = ( BRKINT | IGNPAR | IXON | ICRNL | ISTRIP);       /* make the tty sane */
        buf.c_oflag = (OPOST | TAB3 | ONLCR );
        buf.c_lflag = (ISIG | ICANON | ECHO | ECHOE | ECHOK );
        if (clocal != TRUE) buf.c_cflag &= ~CLOCAL;

        ioctl(fd,TCSETA,&buf); 
        sleep(1);
        close(fd);
        sleep(2);
        
        fd=open(device,O_NDELAY);
        sleep(2);                       /* Toggle DTR line ON/OFF */
        close(fd);                      /* to wake up modem.      */
        sleep(1);
        
}       
SHAR_EOF
chmod +x 'modemctl.c'
fi # end of overwriting check
if test -f 'tty.off'
then
       echo shar: will not over-write existing file "'tty.off'"
else
cat << \SHAR_EOF > 'tty.off'
# TTY.OFF turns respawn of terminal line off.
# 1.1(1987) Copper Electronics Inc.
#

if [ $# -eq 0 ]
then
   echo "Usage: $0 tty#"
   echo "Example: 09=tty9, mo=modem, ect."
   exit 1
fi

trap "" 1 2 3 15
/bin/sed /$1:/s/respawn/off/g /etc/inittab > /etc/inittab.old
mv /etc/inittab.old /etc/inittab
chmod +r /etc/inittab
/bin/telinit q
trap 1 2 3 15
SHAR_EOF
chmod +x 'tty.off'
fi # end of overwriting check
if test -f 'tty.on'
then
       echo shar: will not over-write existing file "'tty.on'"
else
cat << \SHAR_EOF > 'tty.on'
# TTY.ON turns respawn of terminal line on.
# 1.1(1987) Copper Electronics Inc.
#

if [ $# -eq 0 ]
then
   echo "Usage: $0 tty#"
   echo "Example: 09=tty9, mo=modem, ect."
   exit 1
fi

trap "" 1 2 3 15
/bin/sed /$1:/s/off/respawn/g /etc/inittab > /etc/inittab.old
mv /etc/inittab.old /etc/inittab
chmod +r /etc/inittab
/bin/telinit q
trap 1 2 3 15

SHAR_EOF
chmod +x 'tty.on'
fi # end of overwriting check
#	End of shell archive
exit 0

-- 
   "Nothing can be made fool proof because fools are just too damned clever"  
______________________________________________________________________________
  . . . .  AUTHOR: Chuck Sites @ The Louisville Area Forum For Unix  . . . .  
 o o o o o   UUCP: {mit-eddie}!bloom-beacon!coplex!chuck            o o o o o 
O O O O O O   ATT: (502)454-7218               \laffu!chuck        O O O O O O
______________________________________________________________________________



More information about the Comp.unix.microport mailing list