2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
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 * Routines for calling up on a Ventel Modem
16 * Define VENNOECHO if the Ventel is strapped for "no echo".
22 static int vensync(int);
23 static int gobble(char);
24 static void echo(char *);
25 static void sigALRM(void);
26 static int timeout
= 0;
27 static sigjmp_buf timeoutbuf
;
29 void ven_disconnect(void);
33 ven_dialer(char *num
, char *acu
)
42 * Get in synch with a couple of carriage returns
45 (void) printf("can't synchronize with ventel\n");
47 logent(value(HOST
), num
, "ventel", "can't synch up");
51 if (boolean(value(VERBOSE
)))
52 (void) printf("\ndialing...");
53 (void) fflush(stdout
);
54 (void) ioctl(FD
, TCGETS
, &buf
);
56 (void) ioctl(FD
, TCSETSF
, &buf
);
58 echo("#k$\r$\n$D$I$A$L$:$ ");
59 for (cp
= num
; *cp
; cp
++) {
61 (void) write(FD
, cp
, 1);
65 echo("k$\r$\n$D$I$A$L$:$ <");
66 for (cp
= num
; *cp
; cp
++) {
70 (void) write(FD
, cp
, 1);
71 (void) read(FD
, &c
, 1);
76 connected
= gobble('!');
77 (void) ioctl(FD
, TCFLSH
, TCIOFLUSH
);
80 (void) sprintf(line
, "%d second dial timeout",
81 number(value(DIALTIMEOUT
)));
82 logent(value(HOST
), num
, "ventel", line
);
86 ven_disconnect(); /* insurance */
101 (void) write(FD
, "\03", 1);
113 (void) read(FD
, &c
, 1);
119 (void) write(FD
, &c
, 1);
123 (void) write(FD
, &c
, 1);
124 (void) read(FD
, &c
, 1);
133 (void) printf("\07timeout waiting for reply\n");
135 siglongjmp(timeoutbuf
, 1);
144 f
= signal(SIGALRM
, (sig_handler_t
)sigALRM
);
147 if (sigsetjmp(timeoutbuf
, 1)) {
148 (void) signal(SIGALRM
, f
);
151 (void) alarm(number(value(DIALTIMEOUT
)));
152 (void) read(FD
, &c
, 1);
156 if (boolean(value(VERBOSE
)))
159 } while (c
!= '\n' && c
!= match
);
160 (void) signal(SIGALRM
, SIG_DFL
);
164 #define min(a, b) (((a) > (b)) ? (b) : (a))
166 * This convoluted piece of code attempts to get
167 * the ventel in sync. If you don't have FIONREAD
168 * there are gory ways to simulate this.
173 int already
= 0, nread
;
178 * Toggle DTR to force anyone off that might have left
179 * the modem connected, and insure a consistent state
182 * If you don't have the ioctl calls to diddle directly
183 * with DTR, you can always try setting the baud rate to 0.
185 (void) ioctl(FD
, TIOCMBIC
, &dtr
);
187 (void) ioctl(FD
, TIOCMBIS
, &dtr
);
188 while (already
< MAXRETRY
) {
190 * After reseting the modem, send it two \r's to
191 * autobaud on. Make sure to delay between them
192 * so the modem can frame the incoming characters.
194 (void) write(fd
, "\r", 1);
197 #include <sys/time.h>
198 struct timeval tv
= {0, 500000};
200 (void) select(0, 0, 0, 0, &tv
);
205 (void) write(fd
, "\r", 1);
207 if (ioctl(fd
, FIONREAD
, (caddr_t
)&nread
) < 0) {
208 perror("tip: ioctl");
212 (void) read(fd
, buf
, min(nread
, 60));
213 if ((buf
[nread
- 1] & 0177) == '$')
215 nread
-= min(nread
, 60);