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 * Dial the DF02-AC or DF03-AC
160Sstevel@tonic-gate */
170Sstevel@tonic-gate
180Sstevel@tonic-gate #include "tip.h"
190Sstevel@tonic-gate
20*549Smuffin static sigjmp_buf Sjbuf;
21*549Smuffin static void timeout(void);
220Sstevel@tonic-gate
23*549Smuffin void df_disconnect(void);
24*549Smuffin int df_dialer(char *, char *, int);
25*549Smuffin
26*549Smuffin int
df02_dialer(char * num,char * acu)27*549Smuffin df02_dialer(char *num, char *acu)
280Sstevel@tonic-gate {
290Sstevel@tonic-gate
300Sstevel@tonic-gate return (df_dialer(num, acu, 0));
310Sstevel@tonic-gate }
320Sstevel@tonic-gate
33*549Smuffin int
df03_dialer(char * num,char * acu)34*549Smuffin df03_dialer(char *num, char *acu)
350Sstevel@tonic-gate {
360Sstevel@tonic-gate
370Sstevel@tonic-gate return (df_dialer(num, acu, 1));
380Sstevel@tonic-gate }
390Sstevel@tonic-gate
40*549Smuffin /* ARGSUSED */
41*549Smuffin int
df_dialer(char * num,char * acu,int df03)42*549Smuffin df_dialer(char *num, char *acu, int df03)
430Sstevel@tonic-gate {
44*549Smuffin int f = FD;
450Sstevel@tonic-gate struct termios buf;
460Sstevel@tonic-gate int speed = 0;
470Sstevel@tonic-gate char c = '\0';
480Sstevel@tonic-gate
49*549Smuffin (void) ioctl(f, TCGETS, &buf);
500Sstevel@tonic-gate buf.c_cflag |= HUPCL;
51*549Smuffin (void) ioctl(f, TCSETS, &buf);
520Sstevel@tonic-gate if (sigsetjmp(Sjbuf, 1)) {
53*549Smuffin (void) printf("connection timed out\r\n");
540Sstevel@tonic-gate df_disconnect();
550Sstevel@tonic-gate return (0);
560Sstevel@tonic-gate }
570Sstevel@tonic-gate if (boolean(value(VERBOSE)))
58*549Smuffin (void) printf("\ndialing...");
59*549Smuffin (void) fflush(stdout);
600Sstevel@tonic-gate #ifdef TIOCMSET
610Sstevel@tonic-gate if (df03) {
620Sstevel@tonic-gate int st = TIOCM_ST; /* secondary Transmit flag */
630Sstevel@tonic-gate
64*549Smuffin (void) ioctl(f, TCGETS, &buf);
650Sstevel@tonic-gate if (cfgetospeed(&buf) != B1200) { /* must dial at 1200 baud */
660Sstevel@tonic-gate speed = cfgetospeed(&buf);
67*549Smuffin (void) cfsetospeed(&buf, B0);
68*549Smuffin (void) cfsetispeed(&buf, B0);
69*549Smuffin (void) cfsetospeed(&buf, B1200);
70*549Smuffin (void) ioctl(f, TCSETSW, &buf);
71*549Smuffin /* clear ST for 300 baud */
72*549Smuffin (void) ioctl(f, TIOCMBIC, &st);
730Sstevel@tonic-gate } else
74*549Smuffin /* set ST for 1200 baud */
75*549Smuffin (void) ioctl(f, TIOCMBIS, &st);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate #endif
78*549Smuffin (void) signal(SIGALRM, (sig_handler_t)timeout);
79*549Smuffin (void) alarm(5 * strlen(num) + 10);
80*549Smuffin (void) ioctl(f, TCFLSH, TCOFLUSH);
81*549Smuffin (void) write(f, "\001", 1);
82*549Smuffin (void) sleep(1);
83*549Smuffin (void) write(f, "\002", 1);
84*549Smuffin (void) write(f, num, strlen(num));
85*549Smuffin (void) read(f, &c, 1);
860Sstevel@tonic-gate #ifdef TIOCMSET
870Sstevel@tonic-gate if (df03 && speed) {
88*549Smuffin (void) cfsetospeed(&buf, B0);
89*549Smuffin (void) cfsetispeed(&buf, B0);
90*549Smuffin (void) cfsetospeed(&buf, speed);
91*549Smuffin (void) ioctl(f, TCSETSW, &buf);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate #endif
940Sstevel@tonic-gate return (c == 'A');
950Sstevel@tonic-gate }
960Sstevel@tonic-gate
97*549Smuffin void
df_disconnect(void)98*549Smuffin df_disconnect(void)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate
101*549Smuffin (void) write(FD, "\001", 1);
102*549Smuffin (void) sleep(1);
103*549Smuffin (void) ioctl(FD, TCFLSH, TCOFLUSH);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate
106*549Smuffin void
df_abort(void)107*549Smuffin df_abort(void)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate df_disconnect();
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate static void
timeout(void)115*549Smuffin timeout(void)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate siglongjmp(Sjbuf, 1);
1190Sstevel@tonic-gate }
120