Commit | Line | Data |
---|---|---|
05862919 | 1 | #ifndef lint |
a9910fe5 | 2 | static char sccsid[] = "@(#)biz22.c 4.4 (Berkeley) %G%"; |
05862919 SL |
3 | #endif |
4 | ||
cabb8583 SL |
5 | #include "tip.h" |
6 | ||
05862919 | 7 | #define DISCONNECT_CMD "\20\04" /* disconnection string */ |
cabb8583 | 8 | |
05862919 SL |
9 | static int sigALRM(); |
10 | static int timeout = 0; | |
11 | static jmp_buf timeoutbuf; | |
cabb8583 SL |
12 | |
13 | /* | |
14 | * Dial up on a BIZCOMP Model 1022 with either | |
15 | * tone dialing (mod = "V") | |
16 | * pulse dialing (mod = "W") | |
17 | */ | |
18 | static int | |
19 | biz_dialer(num, mod) | |
20 | char *num, *mod; | |
21 | { | |
22 | register int connected = 0; | |
23 | char cbuf[40]; | |
24 | ||
25 | if (boolean(value(VERBOSE))) | |
26 | printf("\nstarting call..."); | |
27 | /* | |
28 | * Disable auto-answer and configure for tone/pulse | |
29 | * dialing | |
30 | */ | |
31 | if (cmd("\02K\r")) { | |
32 | printf("can't initialize bizcomp..."); | |
33 | return (0); | |
34 | } | |
35 | strcpy(cbuf, "\02.\r"); | |
36 | cbuf[1] = *mod; | |
37 | if (cmd(cbuf)) { | |
38 | printf("can't set dialing mode..."); | |
39 | return (0); | |
40 | } | |
41 | strcpy(cbuf, "\02D"); | |
42 | strcat(cbuf, num); | |
43 | strcat(cbuf, "\r"); | |
44 | write(FD, cbuf, strlen(cbuf)); | |
45 | if (!detect("7\r")) { | |
46 | printf("can't get dial tone..."); | |
47 | return (0); | |
48 | } | |
49 | if (boolean(value(VERBOSE))) | |
50 | printf("ringing..."); | |
51 | /* | |
52 | * The reply from the BIZCOMP should be: | |
53 | * 2 \r or 7 \r failure | |
54 | * 1 \r success | |
55 | */ | |
56 | connected = detect("1\r"); | |
57 | #ifdef ACULOG | |
58 | if (timeout) { | |
59 | char line[80]; | |
60 | ||
61 | sprintf(line, "%d second dial timeout", | |
62 | number(value(DIALTIMEOUT))); | |
63 | logent(value(HOST), num, "biz1022", line); | |
64 | } | |
65 | #endif | |
66 | if (timeout) | |
67 | biz22_disconnect(); /* insurance */ | |
68 | return (connected); | |
69 | } | |
70 | ||
71 | biz22w_dialer(num, acu) | |
72 | char *num, *acu; | |
73 | { | |
05862919 | 74 | |
cabb8583 SL |
75 | return (biz_dialer(num, "W")); |
76 | } | |
77 | ||
78 | biz22f_dialer(num, acu) | |
79 | char *num, *acu; | |
80 | { | |
05862919 | 81 | |
cabb8583 SL |
82 | return (biz_dialer(num, "V")); |
83 | } | |
84 | ||
85 | biz22_disconnect() | |
86 | { | |
05862919 SL |
87 | int rw = 2; |
88 | ||
89 | write(FD, DISCONNECT_CMD, 4); | |
cabb8583 | 90 | sleep(2); |
05862919 | 91 | ioctl(FD, TIOCFLUSH, &rw); |
cabb8583 SL |
92 | } |
93 | ||
94 | biz22_abort() | |
95 | { | |
05862919 | 96 | |
cabb8583 | 97 | write(FD, "\02", 1); |
cabb8583 SL |
98 | } |
99 | ||
100 | static int | |
101 | sigALRM() | |
102 | { | |
05862919 | 103 | |
cabb8583 | 104 | timeout = 1; |
05862919 | 105 | longjmp(timeoutbuf, 1); |
cabb8583 SL |
106 | } |
107 | ||
108 | static int | |
109 | cmd(s) | |
110 | register char *s; | |
111 | { | |
112 | char c; | |
05862919 | 113 | int (*f)(); |
cabb8583 SL |
114 | |
115 | write(FD, s, strlen(s)); | |
05862919 SL |
116 | f = signal(SIGALRM, sigALRM); |
117 | if (setjmp(timeoutbuf)) { | |
118 | biz22_abort(); | |
119 | signal(SIGALRM, f); | |
120 | return (1); | |
121 | } | |
cabb8583 SL |
122 | alarm(number(value(DIALTIMEOUT))); |
123 | read(FD, &c, 1); | |
124 | alarm(0); | |
05862919 | 125 | signal(SIGALRM, f); |
cabb8583 SL |
126 | c &= 0177; |
127 | return (c != '\r'); | |
128 | } | |
129 | ||
130 | static int | |
131 | detect(s) | |
132 | register char *s; | |
133 | { | |
134 | char c; | |
05862919 | 135 | int (*f)(); |
cabb8583 | 136 | |
05862919 | 137 | f = signal(SIGALRM, sigALRM); |
cabb8583 SL |
138 | timeout = 0; |
139 | while (*s) { | |
05862919 SL |
140 | if (setjmp(timeoutbuf)) { |
141 | biz22_abort(); | |
142 | break; | |
143 | } | |
cabb8583 SL |
144 | alarm(number(value(DIALTIMEOUT))); |
145 | read(FD, &c, 1); | |
146 | alarm(0); | |
cabb8583 SL |
147 | c &= 0177; |
148 | if (c != *s++) | |
149 | return (0); | |
150 | } | |
05862919 SL |
151 | signal(SIGALRM, f); |
152 | return (timeout == 0); | |
cabb8583 | 153 | } |