getty replacement wanted for Ultrx/BSD4.x
Jur van der Burg
vdburg at utrtsc.dec.com
Tue Oct 16 01:01:04 AEST 1990
In article <195 at ncmicro.lonestar.org>, ltf at ncmicro.lonestar.org (Lance Franklin) writes...
>Let's try this again...never got any response to earlier requests.
>
>I'm looking for sources for getty (or a getty replacement) that will
>allow a better interface to hayes-style modems that can notify the
>computer of the baud-rate of the caller. Yes, I know that the present
.....
This hack may do what you want. I use this on a microvax 2000 with
a quattro modem, Ultrix is V3.1. (Unsupported, etc...)
Jur.
/*
* aa.c (AutoAnswer)
*
* for dc hayes smart modem.
* Listens for a modem reponse, sets the badurate accordingly,
* turns off verbose mode and speaker(always off) and turns on
* extended result codes. exec()'s '/etc/getty' on exit.
*
* Use the following in /etc/gettytab:
*
* #
* # Setup terminal with full 8-bit support for dialin connections
* #
* M8bit.300|300-baud-8bit-modem:\
* :sp#300:p8:f0#01000000000:to#20:
* M8bit.1200|1200-baud-8bit-modem:\
* :sp#1200:p8:f0#01000000000:to#20:
* M8bit.2400|2400-baud-8bit-modem:\
* :sp#2400:p8:f0#01000000000:to#20:
*
* And the following in /etc/ttys:
*
* tty02 "/etc/aa M8bit.2400" dialup on modem # modem port
*
* Jur van der Burg - 14 apr 1990
*/
#include <ctype.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#define LOGFILE "/usr/adm/aa_log"
FILE *logfp;
int modem_fp;
char *gettim(),
*make_result();
main(argc,argv)
int argc;
char *argv[];
{
char devname[20];
sprintf(devname,"/dev/%s",argv[2]); /* assemble modem line name */
sleep(1); /* give modem time to hang up from previous call */
modem_fp = open(devname,O_RDWR|O_NDELAY,0); /* open line without wait */
ioctl(modem_fp,TIOCNMODEM,(int *)1); /* ignore modem signals */
logfp = fopen(LOGFILE,"a"); /* open the log file */
setbuf(logfp,0); /* make sure we can see contents */
init_modem(); /* prepare the modem */
for(;;) /* do this until valid response */
switch(get_result()) /* get the response */
{
case 1:
connect("300",argv);
break;
case 5:
connect("1200",argv);
break;
case 10:
connect("2400",argv);
break;
default:
break;
}
}
init_modem()
{
struct sgttyb ttybuf;
ioctl(modem_fp,TIOCGETP,&ttybuf);
ttybuf.sg_ispeed = ttybuf.sg_ospeed = B2400;
ttybuf.sg_flags |= RAW;
ttybuf.sg_flags &= ~ECHO;
ioctl(modem_fp,TIOCSETP,&ttybuf);
write(modem_fp,"\rATZ\r",5);
sleep(3);
write(modem_fp,"AT Q0 V0 M0 X3 E0 S0=1 &D2 &C1 &R1\r",35);
sleep(1);
ioctl(modem_fp, TIOCFLUSH, 0);
}
get_result()
{
int result;
char tmp;
result = -1;
while (result < 0)
{
read(modem_fp,&tmp,1);
switch(tmp)
{
case '1':
read(modem_fp,&tmp,1);
if (tmp == '\r')
result = 1;
else if (isdigit(tmp))
result = 10 + (tmp - '0');
break;
default:
if (isdigit(tmp))
result = tmp - '0';
break;
}
}
ioctl(modem_fp, TIOCFLUSH, 0);
fprintf(logfp,"%s> %s\n",gettim(),make_result(result));
return(result);
}
connect(baudrate,argv)
char *baudrate;
char *argv[];
{
static char *args[] = {
"+", /* getty will accept our open line */
"M8bit.xxxxx",
0,
0 };
char *envp[1];
strcpy(&args[1][6],baudrate);
args[2] = argv[2];
envp[0] = 0;
sigsetmask(0);
fprintf(logfp,"%s> calling getty: %s %s %s\n",gettim(),args[0],args[1],args[2]);
fclose(logfp);
ioctl(modem_fp,TIOCMODEM,(int *) 1); /* set modem type line */
ioctl(modem_fp,TIOCHPCL,0); /* set hangup on close */
dup2(0,1);
dup2(0,2);
execve("/etc/getty", args, envp);
exit(255);
}
char *gettim()
{
char *ctime();
time_t tim;
char *str;
tim = time((long *)0);
str = ctime(&tim);
str[24] = '\0'; /* zap trailing newline */
return (str);
}
char *make_result(code)
int code;
{
switch(code)
{
case 0:
return("OK");
case 1:
return("CONNECT");
case 2:
return("RING");
case 3:
return("NO CARRIER");
case 4:
return("ERROR");
case 5:
return("CONNECT 1200");
case 6:
return("NO DIALTONE");
case 7:
return("BUSY");
case 8:
return("NO ANSWER");
case 10:
return("CONNECT 2400");
default:
return("UNKNOWN");
}
}
Jur van der Burg DEC Easynet: utrtsc::vdburg
Digital Equipment bv UUCP: {decvax,ucbvax,allegra}!
Utrecht Internet: decwrl!utrtsc.dec.com!vdburg
The Netherlands vdburg at utrtsc.dec.com
vdburg%utrtsc.dec at decwrl.dec.com
******************** EH? *********************
More information about the Comp.unix.ultrix
mailing list