* Copyright (c) 1983 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)hayes.c 5.2 (Berkeley) %G%";
* 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
, "ATv0\r", 5); /* tell modem to use short status codes */
write(FD
, "ATTD", 4); /* send dial command */
write(FD
, num
, strlen(num
));
if ((dummy
= gobble("01234")) != '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");
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
++)
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");