10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
5*549Smuffin
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate */
11*549Smuffin
12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
130Sstevel@tonic-gate
140Sstevel@tonic-gate /*
150Sstevel@tonic-gate * Routines for dialing up on DN-11
160Sstevel@tonic-gate */
170Sstevel@tonic-gate #include "tip.h"
180Sstevel@tonic-gate
19*549Smuffin void alarmtr(void);
20*549Smuffin
21*549Smuffin static sigjmp_buf jmpbuf;
22*549Smuffin static int child = -1, dn;
230Sstevel@tonic-gate
24*549Smuffin int
dn_dialer(char * num,char * acu)25*549Smuffin dn_dialer(char *num, char *acu)
260Sstevel@tonic-gate {
27*549Smuffin int lt, nw;
28*549Smuffin int timelim;
290Sstevel@tonic-gate struct termios buf;
300Sstevel@tonic-gate
310Sstevel@tonic-gate if (boolean(value(VERBOSE)))
32*549Smuffin (void) printf("\nstarting call...");
330Sstevel@tonic-gate if ((dn = open(acu, 1)) < 0) {
340Sstevel@tonic-gate if (errno == EBUSY)
35*549Smuffin (void) printf("line busy...");
360Sstevel@tonic-gate else
37*549Smuffin (void) printf("acu open error...");
380Sstevel@tonic-gate return (0);
390Sstevel@tonic-gate }
400Sstevel@tonic-gate if (sigsetjmp(jmpbuf, 1)) {
41*549Smuffin (void) kill(child, SIGKILL);
42*549Smuffin (void) close(dn);
430Sstevel@tonic-gate return (0);
440Sstevel@tonic-gate }
45*549Smuffin (void) signal(SIGALRM, (sig_handler_t)alarmtr);
460Sstevel@tonic-gate timelim = 5 * strlen(num);
47*549Smuffin (void) alarm(timelim < 30 ? 30 : timelim);
480Sstevel@tonic-gate if ((child = fork()) == 0) {
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate * ignore this stuff for aborts
510Sstevel@tonic-gate */
52*549Smuffin (void) signal(SIGALRM, SIG_IGN);
53*549Smuffin (void) signal(SIGINT, SIG_IGN);
54*549Smuffin (void) signal(SIGQUIT, SIG_IGN);
55*549Smuffin (void) sleep(2);
560Sstevel@tonic-gate nw = write(dn, num, lt = strlen(num));
570Sstevel@tonic-gate exit(nw != lt);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate * open line - will return on carrier
610Sstevel@tonic-gate */
620Sstevel@tonic-gate if ((FD = open(DV, 2)) < 0) {
630Sstevel@tonic-gate if (errno == EIO)
64*549Smuffin (void) printf("lost carrier...");
650Sstevel@tonic-gate else
66*549Smuffin (void) printf("dialup line open failed...");
67*549Smuffin (void) alarm(0);
68*549Smuffin (void) kill(child, SIGKILL);
69*549Smuffin (void) close(dn);
700Sstevel@tonic-gate return (0);
710Sstevel@tonic-gate }
72*549Smuffin (void) alarm(0);
73*549Smuffin (void) ioctl(dn, TCGETS, &buf);
740Sstevel@tonic-gate buf.c_cflag |= HUPCL;
75*549Smuffin (void) ioctl(dn, TCSETSF, &buf);
76*549Smuffin (void) signal(SIGALRM, SIG_DFL);
770Sstevel@tonic-gate while ((nw = wait(<)) != child && nw != -1)
780Sstevel@tonic-gate ;
79*549Smuffin (void) fflush(stdout);
80*549Smuffin (void) close(dn);
810Sstevel@tonic-gate if (lt != 0) {
82*549Smuffin (void) close(FD);
830Sstevel@tonic-gate return (0);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate return (1);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate
880Sstevel@tonic-gate void
alarmtr(void)89*549Smuffin alarmtr(void)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate
92*549Smuffin (void) alarm(0);
930Sstevel@tonic-gate siglongjmp(jmpbuf, 1);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate * Insurance, for some reason we don't seem to be
980Sstevel@tonic-gate * hanging up...
990Sstevel@tonic-gate */
100*549Smuffin void
dn_disconnect(void)101*549Smuffin dn_disconnect(void)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate int dtr = TIOCM_DTR;
1040Sstevel@tonic-gate
105*549Smuffin (void) sleep(2);
1060Sstevel@tonic-gate if (FD > 0)
107*549Smuffin (void) ioctl(FD, TIOCMBIC, &dtr);
108*549Smuffin (void) close(FD);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate
111*549Smuffin void
dn_abort(void)112*549Smuffin dn_abort(void)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate int dtr = TIOCM_DTR;
1150Sstevel@tonic-gate
116*549Smuffin (void) sleep(2);
1170Sstevel@tonic-gate if (child > 0)
118*549Smuffin (void) kill(child, SIGKILL);
1190Sstevel@tonic-gate if (dn > 0)
120*549Smuffin (void) close(dn);
1210Sstevel@tonic-gate if (FD > 0)
122*549Smuffin (void) ioctl(FD, TIOCMBIC, &dtr);
123*549Smuffin (void) close(FD);
1240Sstevel@tonic-gate }
125