17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
37c478bd9Sstevel@tonic-gate * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate */
5*8d489c7aSmuffin
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
87c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
97c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
107c478bd9Sstevel@tonic-gate */
11*8d489c7aSmuffin
12*8d489c7aSmuffin #pragma ident "%Z%%M% %I% %E% SMI"
137c478bd9Sstevel@tonic-gate
147c478bd9Sstevel@tonic-gate /*
157c478bd9Sstevel@tonic-gate * Routines for dialing up on DN-11
167c478bd9Sstevel@tonic-gate */
177c478bd9Sstevel@tonic-gate #include "tip.h"
187c478bd9Sstevel@tonic-gate
19*8d489c7aSmuffin void alarmtr(void);
20*8d489c7aSmuffin
217c478bd9Sstevel@tonic-gate static sigjmp_buf jmpbuf;
227c478bd9Sstevel@tonic-gate static int child = -1, dn;
237c478bd9Sstevel@tonic-gate
24*8d489c7aSmuffin int
dn_dialer(char * num,char * acu)25*8d489c7aSmuffin dn_dialer(char *num, char *acu)
267c478bd9Sstevel@tonic-gate {
27*8d489c7aSmuffin int lt, nw;
28*8d489c7aSmuffin int timelim;
297c478bd9Sstevel@tonic-gate struct termios buf;
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate if (boolean(value(VERBOSE)))
32*8d489c7aSmuffin (void) printf("\nstarting call...");
337c478bd9Sstevel@tonic-gate if ((dn = open(acu, 1)) < 0) {
347c478bd9Sstevel@tonic-gate if (errno == EBUSY)
35*8d489c7aSmuffin (void) printf("line busy...");
367c478bd9Sstevel@tonic-gate else
37*8d489c7aSmuffin (void) printf("acu open error...");
387c478bd9Sstevel@tonic-gate return (0);
397c478bd9Sstevel@tonic-gate }
407c478bd9Sstevel@tonic-gate if (sigsetjmp(jmpbuf, 1)) {
41*8d489c7aSmuffin (void) kill(child, SIGKILL);
42*8d489c7aSmuffin (void) close(dn);
437c478bd9Sstevel@tonic-gate return (0);
447c478bd9Sstevel@tonic-gate }
45*8d489c7aSmuffin (void) signal(SIGALRM, (sig_handler_t)alarmtr);
467c478bd9Sstevel@tonic-gate timelim = 5 * strlen(num);
47*8d489c7aSmuffin (void) alarm(timelim < 30 ? 30 : timelim);
487c478bd9Sstevel@tonic-gate if ((child = fork()) == 0) {
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate * ignore this stuff for aborts
517c478bd9Sstevel@tonic-gate */
52*8d489c7aSmuffin (void) signal(SIGALRM, SIG_IGN);
53*8d489c7aSmuffin (void) signal(SIGINT, SIG_IGN);
54*8d489c7aSmuffin (void) signal(SIGQUIT, SIG_IGN);
55*8d489c7aSmuffin (void) sleep(2);
567c478bd9Sstevel@tonic-gate nw = write(dn, num, lt = strlen(num));
577c478bd9Sstevel@tonic-gate exit(nw != lt);
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate * open line - will return on carrier
617c478bd9Sstevel@tonic-gate */
627c478bd9Sstevel@tonic-gate if ((FD = open(DV, 2)) < 0) {
637c478bd9Sstevel@tonic-gate if (errno == EIO)
64*8d489c7aSmuffin (void) printf("lost carrier...");
657c478bd9Sstevel@tonic-gate else
66*8d489c7aSmuffin (void) printf("dialup line open failed...");
67*8d489c7aSmuffin (void) alarm(0);
68*8d489c7aSmuffin (void) kill(child, SIGKILL);
69*8d489c7aSmuffin (void) close(dn);
707c478bd9Sstevel@tonic-gate return (0);
717c478bd9Sstevel@tonic-gate }
72*8d489c7aSmuffin (void) alarm(0);
73*8d489c7aSmuffin (void) ioctl(dn, TCGETS, &buf);
747c478bd9Sstevel@tonic-gate buf.c_cflag |= HUPCL;
75*8d489c7aSmuffin (void) ioctl(dn, TCSETSF, &buf);
76*8d489c7aSmuffin (void) signal(SIGALRM, SIG_DFL);
777c478bd9Sstevel@tonic-gate while ((nw = wait(<)) != child && nw != -1)
787c478bd9Sstevel@tonic-gate ;
79*8d489c7aSmuffin (void) fflush(stdout);
80*8d489c7aSmuffin (void) close(dn);
817c478bd9Sstevel@tonic-gate if (lt != 0) {
82*8d489c7aSmuffin (void) close(FD);
837c478bd9Sstevel@tonic-gate return (0);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate return (1);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate void
alarmtr(void)89*8d489c7aSmuffin alarmtr(void)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate
92*8d489c7aSmuffin (void) alarm(0);
937c478bd9Sstevel@tonic-gate siglongjmp(jmpbuf, 1);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate * Insurance, for some reason we don't seem to be
987c478bd9Sstevel@tonic-gate * hanging up...
997c478bd9Sstevel@tonic-gate */
100*8d489c7aSmuffin void
dn_disconnect(void)101*8d489c7aSmuffin dn_disconnect(void)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate int dtr = TIOCM_DTR;
1047c478bd9Sstevel@tonic-gate
105*8d489c7aSmuffin (void) sleep(2);
1067c478bd9Sstevel@tonic-gate if (FD > 0)
107*8d489c7aSmuffin (void) ioctl(FD, TIOCMBIC, &dtr);
108*8d489c7aSmuffin (void) close(FD);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
111*8d489c7aSmuffin void
dn_abort(void)112*8d489c7aSmuffin dn_abort(void)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate int dtr = TIOCM_DTR;
1157c478bd9Sstevel@tonic-gate
116*8d489c7aSmuffin (void) sleep(2);
1177c478bd9Sstevel@tonic-gate if (child > 0)
118*8d489c7aSmuffin (void) kill(child, SIGKILL);
1197c478bd9Sstevel@tonic-gate if (dn > 0)
120*8d489c7aSmuffin (void) close(dn);
1217c478bd9Sstevel@tonic-gate if (FD > 0)
122*8d489c7aSmuffin (void) ioctl(FD, TIOCMBIC, &dtr);
123*8d489c7aSmuffin (void) close(FD);
1247c478bd9Sstevel@tonic-gate }
125