dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / tip / aculib / df.c
blobf7cfad2bbe3199207f07be45e03e2e7161e5c909
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
12 #pragma ident "%Z%%M% %I% %E% SMI"
15 * Dial the DF02-AC or DF03-AC
18 #include "tip.h"
20 static sigjmp_buf Sjbuf;
21 static void timeout(void);
23 void df_disconnect(void);
24 int df_dialer(char *, char *, int);
26 int
27 df02_dialer(char *num, char *acu)
30 return (df_dialer(num, acu, 0));
33 int
34 df03_dialer(char *num, char *acu)
37 return (df_dialer(num, acu, 1));
40 /* ARGSUSED */
41 int
42 df_dialer(char *num, char *acu, int df03)
44 int f = FD;
45 struct termios buf;
46 int speed = 0;
47 char c = '\0';
49 (void) ioctl(f, TCGETS, &buf);
50 buf.c_cflag |= HUPCL;
51 (void) ioctl(f, TCSETS, &buf);
52 if (sigsetjmp(Sjbuf, 1)) {
53 (void) printf("connection timed out\r\n");
54 df_disconnect();
55 return (0);
57 if (boolean(value(VERBOSE)))
58 (void) printf("\ndialing...");
59 (void) fflush(stdout);
60 #ifdef TIOCMSET
61 if (df03) {
62 int st = TIOCM_ST; /* secondary Transmit flag */
64 (void) ioctl(f, TCGETS, &buf);
65 if (cfgetospeed(&buf) != B1200) { /* must dial at 1200 baud */
66 speed = cfgetospeed(&buf);
67 (void) cfsetospeed(&buf, B0);
68 (void) cfsetispeed(&buf, B0);
69 (void) cfsetospeed(&buf, B1200);
70 (void) ioctl(f, TCSETSW, &buf);
71 /* clear ST for 300 baud */
72 (void) ioctl(f, TIOCMBIC, &st);
73 } else
74 /* set ST for 1200 baud */
75 (void) ioctl(f, TIOCMBIS, &st);
77 #endif
78 (void) signal(SIGALRM, (sig_handler_t)timeout);
79 (void) alarm(5 * strlen(num) + 10);
80 (void) ioctl(f, TCFLSH, TCOFLUSH);
81 (void) write(f, "\001", 1);
82 (void) sleep(1);
83 (void) write(f, "\002", 1);
84 (void) write(f, num, strlen(num));
85 (void) read(f, &c, 1);
86 #ifdef TIOCMSET
87 if (df03 && speed) {
88 (void) cfsetospeed(&buf, B0);
89 (void) cfsetispeed(&buf, B0);
90 (void) cfsetospeed(&buf, speed);
91 (void) ioctl(f, TCSETSW, &buf);
93 #endif
94 return (c == 'A');
97 void
98 df_disconnect(void)
101 (void) write(FD, "\001", 1);
102 (void) sleep(1);
103 (void) ioctl(FD, TCFLSH, TCOFLUSH);
106 void
107 df_abort(void)
110 df_disconnect();
114 static void
115 timeout(void)
118 siglongjmp(Sjbuf, 1);