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
33 * @(#)hayes.c 8.1 (Berkeley) 6/6/93
37 * Routines for calling up on a Hayes Modem
38 * (based on the old VenTel driver).
39 * The modem is expected to be strapped for "echo".
40 * Also, the switches enabling the DTR and CD lines
41 * must be set correctly.
43 * The easy way to hang up a modem is always simply to
44 * clear the DTR signal. However, if the +++ sequence
45 * (which switches the modem back to local mode) is sent
46 * before modem is hung up, removal of the DTR signal
47 * has no effect (except that it prevents the modem from
48 * recognizing commands).
49 * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984)
53 * It is probably not a good idea to switch the modem
54 * state between 'verbose' and terse (status messages).
55 * This should be kicked out and we should use verbose
56 * mode only. This would make it consistent with normal
57 * interactive use thru the command 'tip dialer'.
62 #define min(a,b) ((a < b) ? a : b)
64 static void sigALRM();
65 static int timeout = 0;
66 static jmp_buf timeoutbuf;
69 static char dumbuf[DUMBUFLEN];
75 static int state = IDLE;
82 register int connected = 0;
87 if (hay_sync() == 0) /* make sure we can talk to the modem */
89 if (boolean(value(VERBOSE)))
90 printf("\ndialing...");
94 write(FD, "ATv0\r", 5); /* tell modem to use short status codes */
97 write(FD, "ATTD", 4); /* send dial command */
98 write(FD, num, strlen(num));
103 if ((dummy = gobble("01234")) != '1')
112 return (connected); /* lets get out of here.. */
114 ioctl(FD, TIOCFLUSH, 0);
117 sprintf(line, "%d second dial timeout",
118 number(value(DIALTIMEOUT)));
119 logent(value(HOST), num, "hayes", line);
123 hay_disconnect(); /* insurance */
133 /* first hang up the modem*/
135 printf("\rdisconnecting modem....\n\r");
137 ioctl(FD, TIOCCDTR, 0);
139 ioctl(FD, TIOCSDTR, 0);
148 write(FD, "\r", 1); /* send anything to abort the call */
156 printf("\07timeout waiting for reply\n\r");
158 longjmp(timeoutbuf, 1);
163 register char *match;
169 f = signal(SIGALRM, sigALRM);
172 printf("\ngobble: waiting for %s\n", match);
175 if (setjmp(timeoutbuf)) {
179 alarm(number(value(DIALTIMEOUT)));
184 printf("%c 0x%x ", c, c);
186 for (i = 0; i < strlen(match); i++)
189 } while (status == 0);
190 signal(SIGALRM, SIG_DFL);
216 printf("NO CARRIER");
220 printf("ERROR in input");
224 printf("CONNECT 1200");
228 printf("Unknown Modem error: %c (0x%x)", c, c);
235 * set modem back to normal verbose status codes.
242 ioctl(FD, TIOCFLUSH, &len); /* get rid of trash */
246 ioctl(FD, TIOCFLUSH, 0);
248 write(FD, "ATH0\r", 5); /* insurance */
251 if (c != '0' && c != '3') {
252 printf("cannot hang up modem\n\r");
253 printf("please use 'tip dialer' to make sure the line is hung up\n\r");
257 ioctl(FD, FIONREAD, &len);
259 printf("goodbye1: len=%d -- ", len);
260 rlen = read(FD, dumbuf, min(len, DUMBUFLEN));
262 printf("read (%d): %s\r\n", rlen, dumbuf);
264 write(FD, "ATv1\r", 5);
267 ioctl(FD, FIONREAD, &len);
268 printf("goodbye2: len=%d -- ", len);
269 rlen = read(FD, dumbuf, min(len, DUMBUFLEN));
271 printf("read (%d): %s\r\n", rlen, dumbuf);
274 ioctl(FD, TIOCFLUSH, 0); /* clear the input buffer */
275 ioctl(FD, TIOCCDTR, 0); /* clear DTR (insurance) */
285 while (retry++ <= MAXRETRY) {
286 write(FD, "AT\r", 3);
288 ioctl(FD, FIONREAD, &len);
290 len = read(FD, dumbuf, min(len, DUMBUFLEN));
291 if (index(dumbuf, '0') ||
292 (index(dumbuf, 'O') && index(dumbuf, 'K')))
296 printf("hay_sync: (\"%s\") %d\n\r", dumbuf, retry);
299 ioctl(FD, TIOCCDTR, 0);
300 ioctl(FD, TIOCSDTR, 0);
302 printf("Cannot synchronize with hayes...\n\r");