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"
16 static int hayes_sync(int);
17 static void sigALRM(void);
18 static sigjmp_buf timeoutbuf
;
20 void hayes_disconnect(void);
23 * Dial up on a Hayes Smart Modem 1200 or 2400
27 hayes_dialer(char *num
, char *acu
)
29 char code
= 0, cr
= 0;
33 f
= signal(SIGALRM
, (sig_handler_t
)sigALRM
);
35 if (!hayes_sync(FD
)) {
36 (void) printf("can't synchronize with hayes\n");
38 logent(value(HOST
), num
, "hayes", "can't synch up");
40 (void) signal(SIGALRM
, f
);
43 if (boolean(value(VERBOSE
)))
44 (void) printf("\ndialing...");
45 (void) fflush(stdout
);
46 (void) ioctl(FD
, TCGETS
, &buf
);
48 (void) ioctl(FD
, TCSETS
, &buf
);
49 (void) ioctl(FD
, TCFLSH
, TCIOFLUSH
);
51 if (sigsetjmp(timeoutbuf
, 1)) {
55 (void) sprintf(line
, "%d second dial timeout",
56 number(value(DIALTIMEOUT
)));
57 logent(value(HOST
), num
, "hayes", line
);
60 (void) signal(SIGALRM
, f
);
63 (void) alarm(number(value(DIALTIMEOUT
)));
64 (void) ioctl(FD
, TCFLSH
, TCIOFLUSH
);
66 (void) write(FD
, "AT", 2);
68 (void) write(FD
, "ATDT", 4); /* use tone dialing */
69 (void) write(FD
, num
, strlen(num
));
70 (void) write(FD
, "\r", 1);
71 (void) read(FD
, &code
, 1);
72 (void) read(FD
, &cr
, 1);
73 if (code
== '1' && cr
== '0')
74 (void) read(FD
, &cr
, 1);
76 (void) signal(SIGALRM
, f
);
77 if ((code
== '1' || code
== '5') && cr
== '\r')
83 hayes_disconnect(void)
94 (void) ioctl(FD
, TIOCMBIC
, &dtr
);
96 (void) ioctl(FD
, TCFLSH
, TCIOFLUSH
);
103 siglongjmp(timeoutbuf
, 1);
107 * This piece of code attempts to get the hayes in sync.
113 char code
= 0, cr
= 0;
117 * Toggle DTR to force anyone off that might have left
118 * the modem connected, and insure a consistent state
121 (void) ioctl(fd
, TIOCMBIC
, &dtr
);
123 (void) ioctl(fd
, TIOCMBIS
, &dtr
);
124 for (tries
= 0; tries
< 3; tries
++) {
126 * After reseting the modem, initialize all
127 * parameters to required vaules:
129 * V0 - result codes are single digits
130 * Q0 - result codes ARE sent
132 * S0=1 - automatically answer phone
133 * S2=255 - disable escape character
134 * S12=255 - longest possible escape guard time
136 (void) write(fd
, "ATV0Q0E0S0=1S2=255S12=255\r", 26);
138 /* flush any echoes or return codes */
139 (void) ioctl(fd
, TCFLSH
, TCIOFLUSH
);
140 /* now see if the modem is talking to us properly */
141 (void) write(fd
, "AT\r", 3);
142 if (sigsetjmp(timeoutbuf
, 1) == 0) {
144 (void) read(FD
, &code
, 1);
145 (void) read(FD
, &cr
, 1);
146 if (code
== '0' && cr
== '\r')