From a0c21c7b22a022a05fc1f5bf887185532961fbcd Mon Sep 17 00:00:00 2001 From: CSRG Date: Sat, 6 Nov 1982 11:08:32 -0800 Subject: [PATCH] BSD 4_1c_2 development Work on file usr/src/usr.bin/tip/README Work on file usr/src/usr.bin/tip/remote-file Work on file usr/src/usr.bin/tip/TODO Work on file usr/src/usr.bin/tip/phones-file Work on file usr/src/usr.bin/tip/biz31.c Work on file usr/src/usr.bin/tip/biz22.c Work on file usr/src/usr.bin/tip/df.c Work on file usr/src/usr.bin/tip/lock.c Work on file usr/src/usr.bin/tip/dn11.c Work on file usr/src/usr.bin/tip/ventel.c Work on file usr/src/usr.bin/tip/aculog.c Synthesized-from: CSRG/cd1/4.1c.2 --- usr/src/usr.bin/tip/README | 69 +++++++++++ usr/src/usr.bin/tip/TODO | 23 ++++ usr/src/usr.bin/tip/aculog.c | 27 +++++ usr/src/usr.bin/tip/biz22.c | 140 +++++++++++++++++++++ usr/src/usr.bin/tip/biz31.c | 207 ++++++++++++++++++++++++++++++++ usr/src/usr.bin/tip/df.c | 100 +++++++++++++++ usr/src/usr.bin/tip/dn11.c | 114 ++++++++++++++++++ usr/src/usr.bin/tip/lock.c | 34 ++++++ usr/src/usr.bin/tip/phones-file | 17 +++ usr/src/usr.bin/tip/remote-file | 107 +++++++++++++++++ usr/src/usr.bin/tip/ventel.c | 178 +++++++++++++++++++++++++++ 11 files changed, 1016 insertions(+) create mode 100644 usr/src/usr.bin/tip/README create mode 100644 usr/src/usr.bin/tip/TODO create mode 100644 usr/src/usr.bin/tip/aculog.c create mode 100644 usr/src/usr.bin/tip/biz22.c create mode 100644 usr/src/usr.bin/tip/biz31.c create mode 100644 usr/src/usr.bin/tip/df.c create mode 100644 usr/src/usr.bin/tip/dn11.c create mode 100644 usr/src/usr.bin/tip/lock.c create mode 100644 usr/src/usr.bin/tip/phones-file create mode 100644 usr/src/usr.bin/tip/remote-file create mode 100644 usr/src/usr.bin/tip/ventel.c diff --git a/usr/src/usr.bin/tip/README b/usr/src/usr.bin/tip/README new file mode 100644 index 0000000000..f2e7b3a78a --- /dev/null +++ b/usr/src/usr.bin/tip/README @@ -0,0 +1,69 @@ +Tip can be configured in a number of ways: + +ACU's: +----- + +ACU Define in makefile +-------------------- --------------- +BIZCOMP 1022, 1031 BIZ1022, BIZ1031 +DEC DF02-AC, DF03-AC DF02, DF03 +DEC DN-11/Able Quadracall DN11 +Ventel VENTEL + +New ACU's may be added by editing the ACU description table +in acutab.c and writing a ``driver''. + +ACU usage can be monitored by defining ACULOG in the makefile. +If this is done and no phone numbers should appear in the +log file, define PRISTINE in the makefile. + +Variables: +--------- + +Tip's internal workings revolve around a set of (possibly) +user defined variables. These are statically initialized +in vars.c, and from the remote file. + +Note that adding or deleting variables requires tip to be completedly +recompiled, as indexes into the variable table are used to avoid +expensive lookups. These defines are set in tip.h. + +Commands: +-------- + +The command dispatch table is defined in cmdtab.c. Commands +may have attributes such as EXPerimental and PRIVileged (only +root may execute). + + + +-------------------------------------------------------------------------- + +Recent changes about Jan 82 (documentation still needs +to be updated): + + +A new, improved version of tip is now available. The most important +addition is the capacility to specify a phone number with tip. The +default baud rate is 1200. To use it do: + + tip phone-number +or + tip -300 phone-number + +for 300 baud. + +A ~^Z command has been added to tip as well. + +A new cu program is available that interfaces to the tip program. +It attempts to give the same user interface as cu but it is really +the tip program so you have all the advantages of tip. This allows +cu (actually tip) to search for a free ACU instead of having the +user specify which one he wants. + +If you have any trouble with either of these programs, please let +me know as soon as possible so that I may fix them. + + Bill Shannon + + diff --git a/usr/src/usr.bin/tip/TODO b/usr/src/usr.bin/tip/TODO new file mode 100644 index 0000000000..39d5f96aa0 --- /dev/null +++ b/usr/src/usr.bin/tip/TODO @@ -0,0 +1,23 @@ +1. Rethink protection glitches on REMOTE & PHONES + files (setuid/setgid??). + +2. Make clean fix for scripting being set in .tiprc + +3. get phone numbers and cu interface to work. DONE + +4. change EOFREAD to recognize more general strings. + +5. add an option that returns an exit status based on + whether resources for the requested operation are available. + +6. write a program to list known systems (a quick shell script + should do it); people keep forgetting the names. + +7. change remote file descriptions so that acu attributes are + are attached to a device so that several different devices + can be used to get to the same system (perhaps hardwired + and phone line). got any ideas here? I'm looking at something + like dv=cua1,cul1,dn11;cua2,,df03. + +8. make a user's personal remote file supplement the system one. + diff --git a/usr/src/usr.bin/tip/aculog.c b/usr/src/usr.bin/tip/aculog.c new file mode 100644 index 0000000000..d7b7b447d7 --- /dev/null +++ b/usr/src/usr.bin/tip/aculog.c @@ -0,0 +1,27 @@ +#include + +#define ACULOG "/usr/adm/aculog" + +main(argc, argv) +char *argv[]; +{ + register FILE *fd; + register int i; + register char *p; + char line[256]; + extern char *index(); + + if ((fd = fopen(ACULOG, "r")) == NULL) { + fprintf(stderr, "can't open %s\n", ACULOG); + exit(1); + } + while (fgets(line, sizeof(line), fd) != NULL) + if (p = index(line, ' ')) { + for (i = 1; i < argc; i++) + if (strncmp(argv[i], line, p-line) == 0) + break; + if (i == argc && argc > 1) + continue; + printf("%s", line); + } +} diff --git a/usr/src/usr.bin/tip/biz22.c b/usr/src/usr.bin/tip/biz22.c new file mode 100644 index 0000000000..a591388675 --- /dev/null +++ b/usr/src/usr.bin/tip/biz22.c @@ -0,0 +1,140 @@ +/* biz22.c 4.1 81/11/29 */ +#include "tip.h" + +#if BIZ1022 +#define DISCONNECT "\20\04" /* disconnection string */ + +static int sigALRM(); +static int timeout = 0; + +/* + * Dial up on a BIZCOMP Model 1022 with either + * tone dialing (mod = "V") + * pulse dialing (mod = "W") + */ +static int +biz_dialer(num, mod) + char *num, *mod; +{ + register int connected = 0; + char cbuf[40]; + + if (boolean(value(VERBOSE))) + printf("\nstarting call..."); + /* + * Disable auto-answer and configure for tone/pulse + * dialing + */ + if (cmd("\02K\r")) { + printf("can't initialize bizcomp..."); + return (0); + } + strcpy(cbuf, "\02.\r"); + cbuf[1] = *mod; + if (cmd(cbuf)) { + printf("can't set dialing mode..."); + return (0); + } + strcpy(cbuf, "\02D"); + strcat(cbuf, num); + strcat(cbuf, "\r"); + write(FD, cbuf, strlen(cbuf)); + if (!detect("7\r")) { + printf("can't get dial tone..."); + return (0); + } + if (boolean(value(VERBOSE))) + printf("ringing..."); + /* + * The reply from the BIZCOMP should be: + * 2 \r or 7 \r failure + * 1 \r success + */ + connected = detect("1\r"); +#ifdef ACULOG + if (timeout) { + char line[80]; + + sprintf(line, "%d second dial timeout", + number(value(DIALTIMEOUT))); + logent(value(HOST), num, "biz1022", line); + } +#endif + if (timeout) + biz22_disconnect(); /* insurance */ + return (connected); +} + +biz22w_dialer(num, acu) + char *num, *acu; +{ + return (biz_dialer(num, "W")); +} + +biz22f_dialer(num, acu) + char *num, *acu; +{ + return (biz_dialer(num, "V")); +} + +biz22_disconnect() +{ + write(FD, DISCONNECT, 4); + sleep(2); + ioctl(FD, TIOCFLUSH); +} + +biz22_abort() +{ + write(FD, "\02", 1); + timeout = 1; +} + +static int +sigALRM() +{ + signal(SIGALRM, SIG_IGN); + printf("\07timeout waiting for reply\n"); + timeout = 1; +} + +static int +cmd(s) + register char *s; +{ + char c; + + write(FD, s, strlen(s)); + timeout = 0; + signal(SIGALRM, biz22_abort); + alarm(number(value(DIALTIMEOUT))); + read(FD, &c, 1); + alarm(0); + signal(SIGALRM, SIG_DFL); + if (timeout) + return (1); + c &= 0177; + return (c != '\r'); +} + +static int +detect(s) + register char *s; +{ + char c; + + signal(SIGALRM, biz22_abort); + timeout = 0; + while (*s) { + alarm(number(value(DIALTIMEOUT))); + read(FD, &c, 1); + alarm(0); + if (timeout) + return (0); + c &= 0177; + if (c != *s++) + return (0); + } + signal(SIGALRM, SIG_DFL); + return (1); +} diff --git a/usr/src/usr.bin/tip/biz31.c b/usr/src/usr.bin/tip/biz31.c new file mode 100644 index 0000000000..1c76e0b4cc --- /dev/null +++ b/usr/src/usr.bin/tip/biz31.c @@ -0,0 +1,207 @@ +/* biz31.c 4.4 81/11/29 */ +#include "tip.h" + +#if BIZ1031 +#define MAXRETRY 3 /* sync up retry count */ +#define DISCONNECT "\21\25\11\24" /* disconnection string */ + +static int sigALRM(); +static int timeout = 0; + +/* + * Dial up on a BIZCOMP Model 1031 with either + * tone dialing (mod = "f") + * pulse dialing (mod = "w") + */ +static int +biz_dialer(num, mod) + char *num, *mod; +{ + register int connected = 0; + + if (!bizsync(FD)) { + logent(value(HOST), "", "biz", "out of sync"); + printf("bizcomp out of sync\n"); + delock(uucplock); + exit(0); + } + if (boolean(value(VERBOSE))) + printf("\nstarting call..."); + echo("#\rk$\r$\n"); /* disable auto-answer */ + echo("$>$.$ #\r"); /* tone/pulse dialing */ + echo(mod); + echo("$\r$\n"); + echo("$>$.$ #\re$ "); /* disconnection sequence */ + echo(DISCONNECT); + echo("\r$\n$\r$\n"); + echo("$>$.$ #\rr$ "); /* repeat dial */ + echo(num); + echo("\r$\n"); + if (boolean(value(VERBOSE))) + printf("ringing..."); + /* + * The reply from the BIZCOMP should be: + * `^G NO CONNECTION\r\n^G\r\n' failure + * ` CONNECTION\r\n^G' success + */ + connected = detect(" "); +#ifdef ACULOG + if (timeout) { + char line[80]; + + sprintf(line, "%d second dial timeout", + number(value(DIALTIMEOUT))); + logent(value(HOST), num, "biz", line); + } +#endif + if (!connected) + flush(" NO CONNECTION\r\n\07\r\n"); + else + flush("CONNECTION\r\n\07"); + if (timeout) + biz31_disconnect(); /* insurance */ + return (connected); +} + +biz31w_dialer(num, acu) + char *num, *acu; +{ + return (biz_dialer(num, "w")); +} + +biz31f_dialer(num, acu) + char *num, *acu; +{ + return (biz_dialer(num, "f")); +} + +biz31_disconnect() +{ + write(FD, DISCONNECT, 4); + sleep(2); + ioctl(FD, TIOCFLUSH); +} + +biz31_abort() +{ + write(FD, "\33", 1); + timeout = 1; +} + +static int +echo(s) + register char *s; +{ + char c; + + while (c = *s++) switch (c) { + + case '$': + read(FD, &c, 1); + s++; + break; + + case '#': + c = *s++; + write(FD, &c, 1); + break; + + default: + write(FD, &c, 1); + read(FD, &c, 1); + } +} + +static int +sigALRM() +{ + signal(SIGALRM, SIG_IGN); + printf("\07timeout waiting for reply\n"); + timeout = 1; +} + +static int +detect(s) + register char *s; +{ + char c; + + signal(SIGALRM, biz31_abort); + timeout = 0; + while (*s) { + alarm(number(value(DIALTIMEOUT))); + read(FD, &c, 1); + alarm(0); + if (timeout) + return (0); + if (c != *s++) + return (0); + } + signal(SIGALRM, SIG_DFL); + return (1); +} + +static int +flush(s) + register char *s; +{ + char c; + + signal(SIGALRM, sigALRM); + timeout = 0; + while (*s++) { + alarm(10); + read(FD, &c, 1); + alarm(0); + if (timeout) + break; + } + signal(SIGALRM, SIG_DFL); + timeout = 0; /* guard against disconnection */ + return (1); +} + +/* + * This convoluted piece of code attempts to get + * the bizcomp in sync. If you don't have the capacity or nread + * call there are gory ways to simulate this. + */ +static int +bizsync(fd) +{ +#ifdef FIOCAPACITY + struct capacity b; +# define chars(b) ((b).cp_nbytes) +# define IOCTL FIOCAPACITY +#endif +#ifdef FIONREAD + long b; +# define chars(b) (b) +# define IOCTL FIONREAD +#endif + register int already = 0; + char buf[10]; + +retry: + if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0) + ioctl(fd, TIOCFLUSH); + write(fd, "\rp>\r", 4); + sleep(1); + if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) { + if (chars(b) != 10) { + nono: + if (already > MAXRETRY) + return (0); + write(fd, DISCONNECT, 4); + sleep(2); + already++; + goto retry; + } else { + read(fd, buf, 10); + if (strncmp(buf, "p >\r\n\r\n>", 8)) + goto nono; + } + } + return (1); +} +#endif diff --git a/usr/src/usr.bin/tip/df.c b/usr/src/usr.bin/tip/df.c new file mode 100644 index 0000000000..24759f26bf --- /dev/null +++ b/usr/src/usr.bin/tip/df.c @@ -0,0 +1,100 @@ +/* df.c 4.5 81/11/29 */ +/* + * Dial the DF02-AC or DF03-AC + */ + +#if defined(DF02) || defined(DF03) +#include "tip.h" +#include + +static jmp_buf Sjbuf; +static timeout(); + +#if DF02 +df02_dialer(num, acu) + char *num, *acu; +{ + return (df_dialer(num, acu, 0)); +} +#endif + +#if DF03 +df03_dialer(num, acu) + char *num, *acu; +{ + return (df_dialer(num, acu, 1)); +} +#endif + +df_dialer(num, acu, df03) + char *num, *acu; + int df03; +{ + register int f = FD; + struct sgttyb buf; + int speed = 0, c = 0; +#ifdef TIOCMSET + int st = MST; /* Secondary Transmit flag, for speed select */ +#endif + + ioctl(f, TIOCHPCL, 0); /* make sure it hangs up when done */ + if (setjmp(Sjbuf)) { + printf("connection timed out\r\n"); + df_disconnect(); + return (0); + } + if (boolean(value(VERBOSE))) + printf("\ndialing..."); + fflush(stdout); +#ifdef TIOCMSET + if (df03) { + ioctl(f, TIOCGETP, &buf); + if (buf.sg_ospeed != B1200) { /* must dial at 1200 baud */ + speed = buf.sg_ospeed; + buf.sg_ospeed = buf.sg_ispeed = B1200; + ioctl(f, TIOCSETP, &buf); + ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */ + } else + ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */ + } +#endif + signal(SIGALRM, timeout); + alarm(5 * strlen(num) + 10); + ioctl(f, TIOCFLUSH, 0); + write(f, "\001", 1); + sleep(1); + write(f, "\002", 1); + write(f, num, strlen(num)); + read(f, (char *)&c, 1); +#ifdef TIOCMSET + if (df03 && speed) { + buf.sg_ispeed = buf.sg_ospeed = speed; + ioctl(f, TIOCSETP, &buf); + } +#endif + return (c == 'A'); +} + + +df_disconnect() +{ + write(FD, "\001", 1); + sleep(1); + ioctl(FD, TIOCFLUSH, 0); +} + + +df_abort() +{ + write(FD, "\001", 1); + sleep(1); + ioctl(FD, TIOCFLUSH, 0); +} + + +static +timeout() +{ + longjmp(Sjbuf, 1); +} +#endif diff --git a/usr/src/usr.bin/tip/dn11.c b/usr/src/usr.bin/tip/dn11.c new file mode 100644 index 0000000000..8f7dcc751d --- /dev/null +++ b/usr/src/usr.bin/tip/dn11.c @@ -0,0 +1,114 @@ +/* dn11.c 4.11 81/11/29 */ + +#if DN11 +/* + * Routines for dialing up on DN-11 + */ +#include "tip.h" +#include +#include + +int dn_abort(); + +int alarmtr(); + +static jmp_buf jmpbuf; +static int child = -1, dn; + +dn_dialer(num, acu) + char *num, *acu; +{ + extern errno; + char *p, *q, phone[40]; + int lt, nw, connected = 1; + register int timelim; + + if (boolean(value(VERBOSE))) + printf("\nstarting call..."); + if ((dn = open(acu, 1)) < 0) { + if (errno == EBUSY) + printf("line busy..."); + else + printf("acu open error..."); + return (0); + } + if (setjmp(jmpbuf)) { + kill(child, SIGKILL); + close(dn); + return (0); + } + signal(SIGALRM, alarmtr); + timelim = 5 * strlen(num); + alarm(timelim < 30 ? 30 : timelim); + if ((child = fork()) == 0) { + /* + * ignore this stuff for aborts + */ + signal(SIGALRM, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + sleep(2); + nw = write(dn, num, lt = strlen(num)); + exit(nw != lt); + } + /* + * open line - will return on carrier + */ + if ((FD = open(DV, 2)) < 0) { + if (errno == EIO) + printf("lost carrier..."); + else + printf("dialup line open failed..."); + alarm(0); + kill(child, SIGKILL); + close(dn); + return (0); + } + alarm(0); + ioctl(dn, TIOCHPCL, 0); + signal(SIGALRM, SIG_DFL); + while ((nw = wait(<)) != child && nw != -1) + ; + fflush(stdout); + close(dn); + if (lt != 0) { + close(FD); + return (0); + } + return (1); +} + +alarmtr() +{ + alarm(0); + longjmp(jmpbuf, 1); +} + +/* + * Insurance, for some reason we don't seem to be + * hanging up... + */ +dn_disconnect() +{ + sleep(2); +#ifdef VMUNIX + if (FD > 0) + ioctl(FD, TIOCCDTR, 0); +#endif + close(FD); +} + +dn_abort() +{ + sleep(2); + if (child > 0) + kill(child, SIGKILL); + if (dn > 0) + close(dn); +#ifdef VMUNIX + if (FD > 0) + ioctl(FD, TIOCCDTR, 0); +#endif + close(FD); +} +#endif diff --git a/usr/src/usr.bin/tip/lock.c b/usr/src/usr.bin/tip/lock.c new file mode 100644 index 0000000000..a652d98de5 --- /dev/null +++ b/usr/src/usr.bin/tip/lock.c @@ -0,0 +1,34 @@ +/* lock.c 4.3 81/11/29 */ +#include "tip.h" + +#ifdef ACULOG +/* + * Locking mechanism for files + */ + +static int fd = -1; + +lock(f) + char *f; +{ + int timeout = 0; + + while ((fd = creat(f, 0444)) < 0) { + if (++timeout == 6) + break; + sleep(5); + } + if (timeout == 6 && fd >= 0) + unlock(); + else + unlink(f); + return (fd >= 0); +} + +unlock() +{ + if (fd != -1) + close(fd); + fd = -1; +} +#endif diff --git a/usr/src/usr.bin/tip/phones-file b/usr/src/usr.bin/tip/phones-file new file mode 100644 index 0000000000..96d4961e87 --- /dev/null +++ b/usr/src/usr.bin/tip/phones-file @@ -0,0 +1,17 @@ +bert 004156427750-< +ernie 004156427652 +lbl 004154864979-< +ames 009699129 +decvax 00603-884-1241 +decvax 006038841230 +case 002163683923 +casevax 002163683240 +cwrunix 002163683240 +cwruecmp 002163683906 +ecmp 002163683906 +navy 423012273700 +gi 006028997900 +gi750 008015823032 +texas 512-474-5511 +sri 415-326-7005 +texas-20 512-477-6542 diff --git a/usr/src/usr.bin/tip/remote-file b/usr/src/usr.bin/tip/remote-file new file mode 100644 index 0000000000..1f1c3ce9fd --- /dev/null +++ b/usr/src/usr.bin/tip/remote-file @@ -0,0 +1,107 @@ +This file contains two sample remote files, +each using a different style. Pick one you +like but don't use both! + + +First example: + +# +# General dialer definitions used below +# +dial1200|1200 Baud Able Quadracall attributes:\ + :dv=/dev/cul1:br#1200:cu=/dev/cua1:at=dn11:du: +dial300|300 Bizcomp 1022 attributes:\ + :dv=/dev/cul0:br#300:cu=/dev/cua0:at=dn11:du: +# +# UNIX system definitions +# +unix1200|1200 Baud dial-out to another UNIX system:\ + :el=^U^C^R^O^D^S^Q:ie=%$:oe=^D:tc=dial1200: +unix300|300 Baud dial-out to another UNIX system:\ + :el=^U^C^R^O^D^S^Q:ie=%$:oe=^D:tc=dial300: +# +# System descriptions +# +45|Sytek PDP-11/45:dv=/dev/ttyh1:br#9600:hw:el=^U^C^R^O^D^S^Q:ie=%$:oe=^D: + +bert|CSRG ARPA VAX-11/780:pn=@:tc=unix1200: +ernie|UCB VAX-11/780:pn=@:tc=unix1200: +lbl|LBL VAX-11/780:pn=@:tc=unix1200: +decvax|DEC VAX-11/780:pn=@:tc=unix1200: + +casevax|cwrunix|CWRU VAX-11/750:pn=@:tc=unix1200: +cwruecmp|ecmp|CWRU VAX-11/780:pn=@:tc=unix1200: +case|CWRU DEC-20:pn=@:tc=unix1200: + +ames|Ames TIP:pn=@:tc=unix1200: +navy|navy PWB 11/70:pn=@:tc=unix300: + +gi750|General Instruments VAX-11/750, Arizona:pn=@:tc=unix1200: +gi|General Instruments VAX-11/780, Utah:pn=@:tc=unix1200: + +video:dv=/dev/tty04:br#4800: + + + + +Second example: + +45z|PDP-11/45Z system:\ + :dv=/dev/tty32:br#9600:el=^U^C^S^Q^D:ie=%$:oe=^D: +decvax|DEC VAX-11/780:\ + :pn=41148:tc=UNIX-300: +decvax-1200|DEC VAX-11/780:\ + :pn=41230:tc=UNIX-1200: +decmail:\ + :pn=42311:tc=VMS-1200: +ems:\ + :pn=41991:tc=VMS-1200: +vms750|nymph|NPG 750:\ + :dv=/dev/tty36,/dev/tty37:br#9600:el=^Z^U^C^S^Q^O:ie=$@:oe=^Z: +spa|SPA VAX-11/780:\ + :pn=8=2270513:tc=UNIX-300: +vax4|DECnet hub:\ + :pn=41662:tc=VMS-1200: +star|VMS development system:\ + :pn=41701:tc=VMS-1200: +sultan|Software Tools:\ + :pn=41701:tc=UNIX-1200: +cghub|demo room timesharing VAX:\ + :pn=41023,41024:tc=VMS-300 +phenix|phenix-300|Distributed systems:\ + :pn=8=2472765,8=2472766,8=2472767,8=2472768:tc=VMS-300 +market|arpanet:\ + :pn=8=2317437,8=2317438,8=2317447,8=2317447,8=2317448,8=2317449,\ + :8=2317450,8=2317451:tc=TOPS20-1200 +market300|arpanet300:\ + :pn=8=2311120,8=2311125,8=2311128:tc=TOPS20-300 +tip0|tip1200:tc=UNIX-1200: +tip300:tc=UNIX-300: +cu0|cu300:tc=UNIX-300: +cu1200:tc=UNIX-1200: +UNIX-300:\ + :dv=/dev/cua0:el=^D^U^C^S^Q^O@:du:at=df02:ie=#$%:oe=^D:br#300: +UNIX-1200:\ + :dv=/dev/cua1,/dev/cua2,/dev/cua4:el=^D^U^C^S^Q^O@:du:at=df03:\ + :ie=#$%:oe=^D:br#1200: +VMS-300|TOPS20-300:\ + :dv=/dev/cua0:el=^Z^U^C^S^Q^O:du:at=df02:ie=$@:oe=^Z:br#300: +VMS-1200|TOPS20-1200:\ + :dv=/dev/cua1,/dev/cua2,/dev/cua4:el=^Z^U^C^S^Q^O:du:at=df03:\ + :ie=$@:oe=^Z:br#1200: +-------------------------------------------------------------------- +The attributes are: + +dv device to use for the tty +el EOL marks (default is NULL) +du make a call flag (dial up) +pn phone numbers (@ =>'s search phones file; possibly taken from + PHONES environment variable) +at ACU type +ie input EOF marks (default is NULL) +oe output EOF string (default is NULL) +cu call unit (default is dv) +br baud rate (defaults to 300) +fs frame size (default is BUFSIZ) -- used in buffering writes + on receive operations +tc to continue a capability diff --git a/usr/src/usr.bin/tip/ventel.c b/usr/src/usr.bin/tip/ventel.c new file mode 100644 index 0000000000..9a84930b0d --- /dev/null +++ b/usr/src/usr.bin/tip/ventel.c @@ -0,0 +1,178 @@ +/* ventel.c 1.2 82/07/29 */ + +#if VENTEL +/* + * Routines for calling up on a Ventel Modem + */ +#include "tip.h" +#include +#include + +#define MAXRETRY 5 +#define DISCONNECT "\03" /* ^C */ + +static int sigALRM(); +static int timeout = 0; + +ven_dialer(num, acu) + register char *num; + char *acu; +{ + register char *cp; + register int connected = 0; + char c; +#ifdef ACULOG + char line[80]; +#endif + /* + * Get in synch with a couple of carriage returns + */ + if (!vensync(FD)) { + printf("can't synchronize with ventel\n"); +#ifdef ACULOG + logent(value(HOST), num, "ventel", "can't synch up"); +#endif + return (0); + } + if (boolean(value(VERBOSE))) + printf("\ndialing..."); + fflush(stdout); + ioctl(FD, TIOCHPCL, 0); + echo("k$\r$\n$D$I$A$L$:$ <"); + for (cp = num; *cp; cp++) { + sleep(1); + write(FD, cp, 1); + read(FD, &c, 1); + } + echo(">\r$\n"); + if (gobble('\n')) + connected = gobble('!'); + ioctl(FD, TIOCFLUSH); +#ifdef ACULOG + if (timeout) { + sprintf(line, "%d second dial timeout", + number(value(DIALTIMEOUT))); + logent(value(HOST), num, "ventel", line); + } +#endif + if (timeout) + ven_disconnect(); /* insurance */ + return (connected); +} + +ven_disconnect() +{ + close(FD); +} + +ven_abort() +{ + write(FD, "\03", 1); + close(FD); +} + +static int +echo(s) + register char *s; +{ + char c; + + while (c = *s++) switch (c) { + + case '$': + read(FD, &c, 1); + s++; + break; + + case '#': + c = *s++; + write(FD, &c, 1); + break; + + default: + write(FD, &c, 1); + read(FD, &c, 1); + } +} + +static int +sigALRM() +{ + signal(SIGALRM, SIG_IGN); + printf("\07timeout waiting for reply\n"); + timeout = 1; +} + +static int +gobble(s) + register char s; +{ + char c; + + signal(SIGALRM, sigALRM); + timeout = 0; + do { + alarm(number(value(DIALTIMEOUT))); + read(FD, &c, 1); + c &= 0177; + alarm(0); +#ifdef notdef + if (boolean(value(VERBOSE))) + putchar(c); +#endif + if (timeout) + return (0); + } while (c != '\n' && c != s); + signal(SIGALRM, SIG_DFL); + return (c == s); +} + +#define min(a,b) ((a)>(b)?(b):(a)) +/* + * This convoluted piece of code attempts to get + * the ventel in sync. If you don't have the capacity or nread + * call there are gory ways to simulate this. + */ +static int +vensync(fd) +{ + long nread; + register int already = 0, nbytes; + char buf[60]; + + /* + * Toggle DTR to force anyone off that might have left + * the modem connected, and insure a consistent state + * to start from. + * + * If you don't have the ioctl calls to diddle directly + * with DTR, you can always try setting the baud rate to 0. + */ + ioctl(FD, TIOCCDTR, 0); + sleep(2); + ioctl(FD, TIOCSDTR, 0); + while (already < MAXRETRY) { + /* + * After reseting the modem, send it two \r's to + * autobaud on. Make sure to delay between them + * so the modem can frame the incoming characters. + */ + write(fd, "\r", 1); + sleep(1); + write(fd, "\r", 1); + sleep(3); + if (ioctl(fd, FIONREAD, (caddr_t)&nread) >= 0) { + nbytes = nread; + while (nbytes > 0) { + read(fd, buf, min(nbytes, 60)); + if ((buf[nbytes-1]&0177) == '$') + return (1); + nbytes -= min(nbytes, 60); + } + sleep(1); + already++; + } + } + return (0); +} +#endif -- 2.20.1