* Copyright (c) 1983 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)hayes.c 5.4 (Berkeley) 3/2/91";
* Routines for calling up on a Hayes Modem
* (based on the old VenTel driver).
* The modem is expected to be strapped for "echo".
* Also, the switches enabling the DTR and CD lines
* The easy way to hang up a modem is always simply to
* clear the DTR signal. However, if the +++ sequence
* (which switches the modem back to local mode) is sent
* before modem is hung up, removal of the DTR signal
* has no effect (except that it prevents the modem from
* (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984)
* It is probably not a good idea to switch the modem
* state between 'verbose' and terse (status messages).
* This should be kicked out and we should use verbose
* mode only. This would make it consistent with normal
* interactive use thru the command 'tip dialer'.
#define min(a,b) ((a < b) ? a : b)
static jmp_buf timeoutbuf
;
static char dumbuf
[DUMBUFLEN
];
register int connected
= 0;
if (hay_sync() == 0) /* make sure we can talk to the modem */
if (boolean(value(VERBOSE
)))
ioctl(FD
, TIOCFLUSH
, 0); /* get rid of garbage */
write(FD
, "ATm0x5v0\r", 9); /* mute speaker; short status codes */
write(FD
, "ATx0v0\r", 7); /* short status codes */
write(FD
, "ATD", 3); /* send dial command */
write(FD
, "ATDT", 4); /* send dial command */
write(FD
, num
, strlen(num
));
if ((dummy
= gobble("012345678")) != '1')
return (connected
); /* lets get out of here.. */
sprintf(line
, "%d second dial timeout",
number(value(DIALTIMEOUT
)));
logent(value(HOST
), num
, "hayes", line
);
hay_disconnect(); /* insurance */
/* first hang up the modem*/
printf("\rdisconnecting modem....\n\r");
write(FD
, "\r", 1); /* send anything to abort the call */
printf("\07timeout waiting for reply\n\r");
f
= signal(SIGALRM
, sigALRM
);
printf("\ngobble: waiting for %s\n", match
);
if (setjmp(timeoutbuf
)) {
alarm(number(value(DIALTIMEOUT
)));
printf("%c 0x%x ", c
, c
);
for (i
= 0; i
< strlen(match
); i
++)
status
= *match
; /* a hack to make some things work */
signal(SIGALRM
, SIG_DFL
);
printf("ERROR in input");
printf("Unknown Modem error: %c (0x%x)", c
, c
);
* set modem back to normal verbose status codes.
ioctl(FD
, TIOCFLUSH
, &len
); /* get rid of trash */
write(FD
, "ATH0\r", 5); /* insurance */
if (c
!= '0' && c
!= '3') {
printf("cannot hang up modem\n\r");
printf("please use 'tip dialer' to make sure the line is hung up\n\r");
ioctl(FD
, FIONREAD
, &len
);
printf("goodbye1: len=%d -- ", len
);
rlen
= read(FD
, dumbuf
, min(len
, DUMBUFLEN
));
printf("read (%d): %s\r\n", rlen
, dumbuf
);
ioctl(FD
, FIONREAD
, &len
);
printf("goodbye2: len=%d -- ", len
);
rlen
= read(FD
, dumbuf
, min(len
, DUMBUFLEN
));
printf("read (%d): %s\r\n", rlen
, dumbuf
);
ioctl(FD
, TIOCFLUSH
, 0); /* clear the input buffer */
ioctl(FD
, TIOCCDTR
, 0); /* clear DTR (insurance) */
while (retry
++ <= MAXRETRY
) {
ioctl(FD
, FIONREAD
, &len
);
len
= read(FD
, dumbuf
, min(len
, DUMBUFLEN
));
if (index(dumbuf
, '0') ||
(index(dumbuf
, 'O') && index(dumbuf
, 'K')))
printf("hay_sync: (\"%s\") %d\n\r", dumbuf
, retry
);
printf("Cannot synchronize with hayes...\n\r");