2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93";
39 * Routines for calling up on a Hayes Modem
40 * (based on the old VenTel driver).
41 * The modem is expected to be strapped for "echo".
42 * Also, the switches enabling the DTR and CD lines
43 * must be set correctly.
45 * The easy way to hang up a modem is always simply to
46 * clear the DTR signal. However, if the +++ sequence
47 * (which switches the modem back to local mode) is sent
48 * before modem is hung up, removal of the DTR signal
49 * has no effect (except that it prevents the modem from
50 * recognizing commands).
51 * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984)
55 * It is probably not a good idea to switch the modem
56 * state between 'verbose' and terse (status messages).
57 * This should be kicked out and we should use verbose
58 * mode only. This would make it consistent with normal
59 * interactive use thru the command 'tip dialer'.
64 #define min(a,b) ((a < b) ? a : b)
66 static void sigALRM();
67 static int timeout = 0;
68 static jmp_buf timeoutbuf;
71 static char dumbuf[DUMBUFLEN];
77 static int state = IDLE;
84 register int connected = 0;
89 if (hay_sync() == 0) /* make sure we can talk to the modem */
91 if (boolean(value(VERBOSE)))
92 printf("\ndialing...");
96 write(FD, "ATv0\r", 5); /* tell modem to use short status codes */
99 write(FD, "ATTD", 4); /* send dial command */
100 write(FD, num, strlen(num));
105 if ((dummy = gobble("01234")) != '1')
114 return (connected); /* lets get out of here.. */
116 ioctl(FD, TIOCFLUSH, 0);
119 sprintf(line, "%d second dial timeout",
120 number(value(DIALTIMEOUT)));
121 logent(value(HOST), num, "hayes", line);
125 hay_disconnect(); /* insurance */
135 /* first hang up the modem*/
137 printf("\rdisconnecting modem....\n\r");
139 ioctl(FD, TIOCCDTR, 0);
141 ioctl(FD, TIOCSDTR, 0);
150 write(FD, "\r", 1); /* send anything to abort the call */
158 printf("\07timeout waiting for reply\n\r");
160 longjmp(timeoutbuf, 1);
165 register char *match;
171 f = signal(SIGALRM, sigALRM);
174 printf("\ngobble: waiting for %s\n", match);
177 if (setjmp(timeoutbuf)) {
181 alarm(number(value(DIALTIMEOUT)));
186 printf("%c 0x%x ", c, c);
188 for (i = 0; i < strlen(match); i++)
191 } while (status == 0);
192 signal(SIGALRM, SIG_DFL);
218 printf("NO CARRIER");
222 printf("ERROR in input");
226 printf("CONNECT 1200");
230 printf("Unknown Modem error: %c (0x%x)", c, c);
237 * set modem back to normal verbose status codes.
244 ioctl(FD, TIOCFLUSH, &len); /* get rid of trash */
248 ioctl(FD, TIOCFLUSH, 0);
250 write(FD, "ATH0\r", 5); /* insurance */
253 if (c != '0' && c != '3') {
254 printf("cannot hang up modem\n\r");
255 printf("please use 'tip dialer' to make sure the line is hung up\n\r");
259 ioctl(FD, FIONREAD, &len);
261 printf("goodbye1: len=%d -- ", len);
262 rlen = read(FD, dumbuf, min(len, DUMBUFLEN));
264 printf("read (%d): %s\r\n", rlen, dumbuf);
266 write(FD, "ATv1\r", 5);
269 ioctl(FD, FIONREAD, &len);
270 printf("goodbye2: len=%d -- ", len);
271 rlen = read(FD, dumbuf, min(len, DUMBUFLEN));
273 printf("read (%d): %s\r\n", rlen, dumbuf);
276 ioctl(FD, TIOCFLUSH, 0); /* clear the input buffer */
277 ioctl(FD, TIOCCDTR, 0); /* clear DTR (insurance) */
287 while (retry++ <= MAXRETRY) {
288 write(FD, "AT\r", 3);
290 ioctl(FD, FIONREAD, &len);
292 len = read(FD, dumbuf, min(len, DUMBUFLEN));
293 if (index(dumbuf, '0') ||
294 (index(dumbuf, 'O') && index(dumbuf, 'K')))
298 printf("hay_sync: (\"%s\") %d\n\r", dumbuf, retry);
301 ioctl(FD, TIOCCDTR, 0);
302 ioctl(FD, TIOCSDTR, 0);
304 printf("Cannot synchronize with hayes...\n\r");