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 #define MAXRETRY 3 /* sync up retry count */
17 #define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */
19 static int detect(char *);
20 static int bizsync(int);
21 static void echo(char *);
22 static void flush(char *);
23 static void sigALRM(void);
24 static int timeout
= 0;
25 static sigjmp_buf timeoutbuf
;
27 void biz31_disconnect(void);
30 * Dial up on a BIZCOMP Model 1031 with either
31 * tone dialing (mod = "f")
32 * pulse dialing (mod = "w")
35 biz_dialer(char *num
, char *mod
)
40 logent(value(HOST
), "", "biz", "out of sync");
41 (void) printf("bizcomp out of sync\n");
45 if (boolean(value(VERBOSE
)))
46 (void) printf("\nstarting call...");
47 echo("#\rk$\r$\n"); /* disable auto-answer */
48 echo("$>$.$ #\r"); /* tone/pulse dialing */
51 echo("$>$.$ #\re$ "); /* disconnection sequence */
54 echo("$>$.$ #\rr$ "); /* repeat dial */
57 if (boolean(value(VERBOSE
)))
58 (void) printf("ringing...");
60 * The reply from the BIZCOMP should be:
61 * `^G NO CONNECTION\r\n^G\r\n' failure
62 * ` CONNECTION\r\n^G' success
64 connected
= detect(" ");
69 (void) sprintf(line
, "%d second dial timeout",
70 number(value(DIALTIMEOUT
)));
71 logent(value(HOST
), num
, "biz", line
);
75 flush(" NO CONNECTION\r\n\07\r\n");
77 flush("CONNECTION\r\n\07");
79 biz31_disconnect(); /* insurance */
85 biz31w_dialer(char *num
, char *acu
)
88 return (biz_dialer(num
, "w"));
93 biz31f_dialer(char *num
, char *acu
)
96 return (biz_dialer(num
, "f"));
100 biz31_disconnect(void)
103 (void) write(FD
, DISCONNECT_CMD
, 4);
105 (void) ioctl(FD
, TCFLSH
, TCOFLUSH
);
112 (void) write(FD
, "\33", 1);
123 (void) read(FD
, &c
, 1);
129 (void) write(FD
, &c
, 1);
133 (void) write(FD
, &c
, 1);
134 (void) read(FD
, &c
, 1);
144 siglongjmp(timeoutbuf
, 1);
153 f
= signal(SIGALRM
, (sig_handler_t
)sigALRM
);
156 if (sigsetjmp(timeoutbuf
, 1)) {
157 (void) printf("\07timeout waiting for reply\n");
161 (void) alarm(number(value(DIALTIMEOUT
)));
162 (void) read(FD
, &c
, 1);
167 (void) signal(SIGALRM
, f
);
168 return (timeout
== 0);
177 f
= signal(SIGALRM
, (sig_handler_t
)sigALRM
);
179 if (sigsetjmp(timeoutbuf
, 1))
182 (void) read(FD
, &c
, 1);
185 (void) signal(SIGALRM
, f
);
186 timeout
= 0; /* guard against disconnection */
190 * This convoluted piece of code attempts to get
191 * the bizcomp in sync. If you don't have the capacity or nread
192 * call there are gory ways to simulate this.
199 #define chars(b) ((b).cp_nbytes)
200 #define IOCTL FIOCAPACITY
205 #define IOCTL FIONREAD
211 if (ioctl(fd
, IOCTL
, (caddr_t
)&b
) >= 0 && chars(b
) > 0)
212 (void) ioctl(fd
, TCFLSH
, TCIOFLUSH
);
213 (void) write(fd
, "\rp>\r", 4);
215 if (ioctl(fd
, IOCTL
, (caddr_t
)&b
) >= 0) {
216 if (chars(b
) != 10) {
218 if (already
> MAXRETRY
)
220 (void) write(fd
, DISCONNECT_CMD
, 4);
225 (void) read(fd
, buf
, 10);
226 if (strncmp(buf
, "p >\r\n\r\n>", 8))