2 * Copyright (c) 1986, 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 * @(#)courier.c 8.1 (Berkeley) 6/6/93
34 * $DragonFly: src/usr.bin/tip/libacu/courier.c,v 1.3 2005/05/07 23:20:43 corecode Exp $
38 * Routines for calling up on a Courier modem.
39 * Derived from Hayes driver.
43 #include "acucommon.h"
48 static void sigALRM();
49 static int cour_connect(void);
50 static int cour_swallow(char *);
51 static int timeout
= 0;
52 static int connected
= 0;
53 static jmp_buf timeoutbuf
, intbuf
;
54 static int coursync();
65 if (boolean(value(VERBOSE
)))
66 printf("Using \"%s\"\n", acu
);
75 printf("can't synchronize with courier\n");
77 logent(value(HOST
), num
, "courier", "can't synch up");
81 cour_write(FD
, "AT E0\r", 6); /* turn off echoing */
84 if (boolean(value(VERBOSE
)))
87 ioctl(FD
, TIOCFLUSH
, 0); /* flush any clutter */
88 cour_write(FD
, "AT C1 E0 H0 Q0 X6 V1\r", 21);
89 if (!cour_swallow("\r\nOK\r\n"))
92 cour_write(FD
, "AT D", 4);
93 for (cp
= num
; *cp
; cp
++)
96 cour_write(FD
, num
, strlen(num
));
97 cour_write(FD
, "\r", 1);
98 connected
= cour_connect();
101 sprintf(line
, "%d second dial timeout",
102 number(value(DIALTIMEOUT
)));
103 logent(value(HOST
), num
, "cour", line
);
113 /* first hang up the modem*/
114 ioctl(FD
, TIOCCDTR
, 0);
116 ioctl(FD
, TIOCSDTR
, 0);
117 coursync(); /* reset */
123 cour_write(FD
, "\r", 1); /* send anything to abort the call */
130 printf("\07timeout waiting for reply\n");
132 longjmp(timeoutbuf
, 1);
137 register char *match
;
142 f
= signal(SIGALRM
, sigALRM
);
149 if (setjmp(timeoutbuf
)) {
153 alarm(number(value(DIALTIMEOUT
)));
158 if (boolean(value(VERBOSE
)))
161 } while (c
== *match
++);
163 if (boolean(value(VERBOSE
)))
166 signal(SIGALRM
, SIG_DFL
);
191 if (cour_swallow("\r\n") == 0)
193 f
= signal(SIGALRM
, sigALRM
);
195 nc
= 0; nl
= sizeof(dialer_buf
)-1;
196 bzero(dialer_buf
, sizeof(dialer_buf
));
198 for (nc
= 0, nl
= sizeof(dialer_buf
)-1 ; nl
> 0 ; nc
++, nl
--) {
199 if (setjmp(timeoutbuf
))
201 alarm(number(value(DIALTIMEOUT
)));
208 if (cour_swallow("\n") == 0)
212 if (strcmp(dialer_buf
, "RINGING") == 0 &&
213 boolean(value(VERBOSE
))) {
215 printf("%s\r\n", dialer_buf
);
219 if (strncmp(dialer_buf
, "CONNECT",
220 sizeof("CONNECT")-1) != 0)
222 for (bm
= baud_msg
; bm
->msg
; bm
++)
224 dialer_buf
+sizeof("CONNECT")-1) == 0) {
225 if (!acu_setspeed(bm
->baud
))
229 if (boolean(value(VERBOSE
)))
230 printf("%s\r\n", dialer_buf
);
238 if (boolean(value(VERBOSE
)))
243 printf("%s\r\n", dialer_buf
);
250 * This convoluted piece of code attempts to get
251 * the courier in sync.
260 while (already
++ < MAXRETRY
) {
261 ioctl(FD
, TIOCFLUSH
, 0); /* flush any clutter */
262 cour_write(FD
, "\rAT Z\r", 6); /* reset modem */
263 bzero(buf
, sizeof(buf
));
265 ioctl(FD
, FIONREAD
, &len
);
267 len
= read(FD
, buf
, sizeof(buf
));
270 printf("coursync: (\"%s\")\n\r", buf
);
272 if (index(buf
, '0') ||
273 (index(buf
, 'O') && index(buf
, 'K')))
277 * If not strapped for DTR control,
278 * try to get command mode.
281 cour_write(FD
, "+++", 3);
284 * Toggle DTR to force anyone off that might have left
285 * the modem connected.
287 ioctl(FD
, TIOCCDTR
, 0);
289 ioctl(FD
, TIOCSDTR
, 0);
291 cour_write(FD
, "\rAT Z\r", 6);
295 cour_write(fd
, cp
, n
)
301 if (boolean(value(VERBOSE
)))
306 for ( ; n
-- ; cp
++) {
319 if (ioctl(FD
, FIONREAD
, &n
) < 0)
323 if (read(FD
, buf
, n
) != n
)
334 /* end of courier.c */