]>
Commit | Line | Data |
---|---|---|
1ca6711e | 1 | /* |
1da177e4 LT |
2 | * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). |
3 | * | |
4 | * Copyright 1994-1999 by Fritz Elfert ([email protected]) | |
5 | * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg | |
6 | * | |
7 | * This software may be used and distributed according to the terms | |
8 | * of the GNU General Public License, incorporated herein by reference. | |
9 | * | |
10 | */ | |
11 | #undef ISDN_TTY_STAT_DEBUG | |
12 | ||
1da177e4 | 13 | #include <linux/isdn.h> |
6776a2f0 | 14 | #include <linux/serial.h> /* ASYNC_* flags */ |
5a0e3ad6 | 15 | #include <linux/slab.h> |
1da177e4 | 16 | #include <linux/delay.h> |
72250d44 | 17 | #include <linux/mutex.h> |
1da177e4 LT |
18 | #include "isdn_common.h" |
19 | #include "isdn_tty.h" | |
20 | #ifdef CONFIG_ISDN_AUDIO | |
21 | #include "isdn_audio.h" | |
22 | #define VBUF 0x3e0 | |
23 | #define VBUFX (VBUF/16) | |
24 | #endif | |
25 | ||
26 | #define FIX_FILE_TRANSFER | |
27 | #define DUMMY_HAYES_AT | |
28 | ||
29 | /* Prototypes */ | |
30 | ||
72250d44 | 31 | static DEFINE_MUTEX(modem_info_mutex); |
1da177e4 LT |
32 | static int isdn_tty_edit_at(const char *, int, modem_info *); |
33 | static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *); | |
34 | static void isdn_tty_modem_reset_regs(modem_info *, int); | |
35 | static void isdn_tty_cmd_ATA(modem_info *); | |
36 | static void isdn_tty_flush_buffer(struct tty_struct *); | |
37 | static void isdn_tty_modem_result(int, modem_info *); | |
38 | #ifdef CONFIG_ISDN_AUDIO | |
39 | static int isdn_tty_countDLE(unsigned char *, int); | |
40 | #endif | |
41 | ||
42 | /* Leave this unchanged unless you know what you do! */ | |
43 | #define MODEM_PARANOIA_CHECK | |
44 | #define MODEM_DO_RESTART | |
45 | ||
46 | static int bit2si[8] = | |
47 | {1, 5, 7, 7, 7, 7, 7, 7}; | |
48 | static int si2bit[8] = | |
49 | {4, 1, 4, 4, 4, 4, 4, 4}; | |
50 | ||
1da177e4 LT |
51 | /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() |
52 | * to stuff incoming data directly into a tty's flip-buffer. This | |
53 | * is done to speed up tty-receiving if the receive-queue is empty. | |
54 | * This routine MUST be called with interrupts off. | |
55 | * Return: | |
56 | * 1 = Success | |
57 | * 0 = Failure, data has to be buffered and later processed by | |
58 | * isdn_tty_readmodem(). | |
59 | */ | |
60 | static int | |
475be4d8 | 61 | isdn_tty_try_read(modem_info *info, struct sk_buff *skb) |
1da177e4 LT |
62 | { |
63 | int c; | |
64 | int len; | |
65 | struct tty_struct *tty; | |
33f0f88f | 66 | char last; |
1da177e4 | 67 | |
37630f40 JS |
68 | if (!info->online) |
69 | return 0; | |
70 | ||
ba43294d | 71 | tty = info->port.tty; |
37630f40 JS |
72 | if (!tty) |
73 | return 0; | |
74 | ||
75 | if (!(info->mcr & UART_MCR_RTS)) | |
76 | return 0; | |
77 | ||
78 | len = skb->len | |
1da177e4 | 79 | #ifdef CONFIG_ISDN_AUDIO |
37630f40 | 80 | + ISDN_AUDIO_SKB_DLECOUNT(skb) |
1da177e4 | 81 | #endif |
37630f40 JS |
82 | ; |
83 | ||
84 | c = tty_buffer_request_room(tty, len); | |
85 | if (c < len) | |
86 | return 0; | |
33f0f88f | 87 | |
1da177e4 | 88 | #ifdef CONFIG_ISDN_AUDIO |
37630f40 JS |
89 | if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { |
90 | int l = skb->len; | |
91 | unsigned char *dp = skb->data; | |
92 | while (--l) { | |
93 | if (*dp == DLE) | |
94 | tty_insert_flip_char(tty, DLE, 0); | |
95 | tty_insert_flip_char(tty, *dp++, 0); | |
96 | } | |
97 | if (*dp == DLE) | |
98 | tty_insert_flip_char(tty, DLE, 0); | |
99 | last = *dp; | |
100 | } else { | |
1da177e4 | 101 | #endif |
37630f40 JS |
102 | if (len > 1) |
103 | tty_insert_flip_string(tty, skb->data, len - 1); | |
104 | last = skb->data[len - 1]; | |
105 | #ifdef CONFIG_ISDN_AUDIO | |
1da177e4 | 106 | } |
37630f40 JS |
107 | #endif |
108 | if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) | |
109 | tty_insert_flip_char(tty, last, 0xFF); | |
110 | else | |
111 | tty_insert_flip_char(tty, last, TTY_NORMAL); | |
112 | tty_flip_buffer_push(tty); | |
113 | kfree_skb(skb); | |
114 | ||
115 | return 1; | |
1da177e4 LT |
116 | } |
117 | ||
118 | /* isdn_tty_readmodem() is called periodically from within timer-interrupt. | |
119 | * It tries getting received data from the receive queue an stuff it into | |
120 | * the tty's flip-buffer. | |
121 | */ | |
122 | void | |
123 | isdn_tty_readmodem(void) | |
124 | { | |
125 | int resched = 0; | |
126 | int midx; | |
127 | int i; | |
1da177e4 LT |
128 | int r; |
129 | struct tty_struct *tty; | |
130 | modem_info *info; | |
131 | ||
132 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
37630f40 JS |
133 | midx = dev->m_idx[i]; |
134 | if (midx < 0) | |
135 | continue; | |
136 | ||
137 | info = &dev->mdm.info[midx]; | |
138 | if (!info->online) | |
139 | continue; | |
140 | ||
141 | r = 0; | |
1da177e4 | 142 | #ifdef CONFIG_ISDN_AUDIO |
37630f40 JS |
143 | isdn_audio_eval_dtmf(info); |
144 | if ((info->vonline & 1) && (info->emu.vpar[1])) | |
145 | isdn_audio_eval_silence(info); | |
146 | #endif | |
ba43294d | 147 | tty = info->port.tty; |
37630f40 JS |
148 | if (tty) { |
149 | if (info->mcr & UART_MCR_RTS) { | |
150 | /* CISCO AsyncPPP Hack */ | |
151 | if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) | |
152 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); | |
153 | else | |
154 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); | |
155 | if (r) | |
156 | tty_flip_buffer_push(tty); | |
157 | } else | |
158 | r = 1; | |
159 | } else | |
160 | r = 1; | |
161 | if (r) { | |
162 | info->rcvsched = 0; | |
163 | resched = 1; | |
164 | } else | |
165 | info->rcvsched = 1; | |
1da177e4 LT |
166 | } |
167 | if (!resched) | |
168 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); | |
169 | } | |
170 | ||
171 | int | |
172 | isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb) | |
173 | { | |
174 | ulong flags; | |
175 | int midx; | |
176 | #ifdef CONFIG_ISDN_AUDIO | |
177 | int ifmt; | |
178 | #endif | |
179 | modem_info *info; | |
180 | ||
181 | if ((midx = dev->m_idx[i]) < 0) { | |
182 | /* if midx is invalid, packet is not for tty */ | |
183 | return 0; | |
184 | } | |
185 | info = &dev->mdm.info[midx]; | |
186 | #ifdef CONFIG_ISDN_AUDIO | |
187 | ifmt = 1; | |
475be4d8 | 188 | |
1da177e4 LT |
189 | if ((info->vonline) && (!info->emu.vpar[4])) |
190 | isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt); | |
191 | if ((info->vonline & 1) && (info->emu.vpar[1])) | |
192 | isdn_audio_calc_silence(info, skb->data, skb->len, ifmt); | |
193 | #endif | |
194 | if ((info->online < 2) | |
195 | #ifdef CONFIG_ISDN_AUDIO | |
196 | && (!(info->vonline & 1)) | |
197 | #endif | |
198 | ) { | |
199 | /* If Modem not listening, drop data */ | |
200 | kfree_skb(skb); | |
201 | return 1; | |
202 | } | |
203 | if (info->emu.mdmreg[REG_T70] & BIT_T70) { | |
204 | if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) { | |
205 | /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */ | |
206 | if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */ | |
207 | skb_pull(skb, 4); | |
208 | else | |
209 | if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */ | |
210 | skb_pull(skb, 2); | |
211 | } else | |
212 | /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */ | |
213 | if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1))) | |
214 | skb_pull(skb, 4); | |
215 | } | |
216 | #ifdef CONFIG_ISDN_AUDIO | |
217 | ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; | |
218 | ISDN_AUDIO_SKB_LOCK(skb) = 0; | |
219 | if (info->vonline & 1) { | |
220 | /* voice conversion/compression */ | |
221 | switch (info->emu.vpar[3]) { | |
475be4d8 JP |
222 | case 2: |
223 | case 3: | |
224 | case 4: | |
225 | /* adpcm | |
226 | * Since compressed data takes less | |
227 | * space, we can overwrite the buffer. | |
228 | */ | |
229 | skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr, | |
230 | ifmt, | |
231 | skb->data, | |
232 | skb->data, | |
233 | skb->len)); | |
234 | break; | |
235 | case 5: | |
236 | /* a-law */ | |
237 | if (!ifmt) | |
238 | isdn_audio_ulaw2alaw(skb->data, skb->len); | |
239 | break; | |
240 | case 6: | |
241 | /* u-law */ | |
242 | if (ifmt) | |
243 | isdn_audio_alaw2ulaw(skb->data, skb->len); | |
244 | break; | |
1da177e4 LT |
245 | } |
246 | ISDN_AUDIO_SKB_DLECOUNT(skb) = | |
247 | isdn_tty_countDLE(skb->data, skb->len); | |
248 | } | |
249 | #ifdef CONFIG_ISDN_TTY_FAX | |
250 | else { | |
251 | if (info->faxonline & 2) { | |
252 | isdn_tty_fax_bitorder(info, skb); | |
253 | ISDN_AUDIO_SKB_DLECOUNT(skb) = | |
254 | isdn_tty_countDLE(skb->data, skb->len); | |
255 | } | |
256 | } | |
257 | #endif | |
258 | #endif | |
33f0f88f | 259 | /* Try to deliver directly via tty-buf if queue is empty */ |
1da177e4 LT |
260 | spin_lock_irqsave(&info->readlock, flags); |
261 | if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) | |
262 | if (isdn_tty_try_read(info, skb)) { | |
263 | spin_unlock_irqrestore(&info->readlock, flags); | |
264 | return 1; | |
265 | } | |
266 | /* Direct deliver failed or queue wasn't empty. | |
267 | * Queue up for later dequeueing via timer-irq. | |
268 | */ | |
269 | __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb); | |
270 | dev->drv[di]->rcvcount[channel] += | |
271 | (skb->len | |
272 | #ifdef CONFIG_ISDN_AUDIO | |
273 | + ISDN_AUDIO_SKB_DLECOUNT(skb) | |
274 | #endif | |
275 | ); | |
276 | spin_unlock_irqrestore(&info->readlock, flags); | |
277 | /* Schedule dequeuing */ | |
278 | if ((dev->modempoll) && (info->rcvsched)) | |
279 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); | |
280 | return 1; | |
281 | } | |
282 | ||
3e206b0a | 283 | static void |
475be4d8 | 284 | isdn_tty_cleanup_xmit(modem_info *info) |
1da177e4 LT |
285 | { |
286 | skb_queue_purge(&info->xmit_queue); | |
287 | #ifdef CONFIG_ISDN_AUDIO | |
288 | skb_queue_purge(&info->dtmf_queue); | |
289 | #endif | |
290 | } | |
291 | ||
292 | static void | |
475be4d8 | 293 | isdn_tty_tint(modem_info *info) |
1da177e4 LT |
294 | { |
295 | struct sk_buff *skb = skb_dequeue(&info->xmit_queue); | |
296 | int len, slen; | |
297 | ||
298 | if (!skb) | |
299 | return; | |
300 | len = skb->len; | |
301 | if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, | |
302 | info->isdn_channel, 1, skb)) == len) { | |
ba43294d | 303 | struct tty_struct *tty = info->port.tty; |
1da177e4 LT |
304 | info->send_outstanding++; |
305 | info->msr &= ~UART_MSR_CTS; | |
306 | info->lsr &= ~UART_LSR_TEMT; | |
307 | tty_wakeup(tty); | |
308 | return; | |
309 | } | |
310 | if (slen < 0) { | |
311 | /* Error: no channel, already shutdown, or wrong parameter */ | |
312 | dev_kfree_skb(skb); | |
313 | return; | |
314 | } | |
315 | skb_queue_head(&info->xmit_queue, skb); | |
316 | } | |
317 | ||
318 | #ifdef CONFIG_ISDN_AUDIO | |
319 | static int | |
320 | isdn_tty_countDLE(unsigned char *buf, int len) | |
321 | { | |
322 | int count = 0; | |
323 | ||
324 | while (len--) | |
325 | if (*buf++ == DLE) | |
326 | count++; | |
327 | return count; | |
328 | } | |
329 | ||
330 | /* This routine is called from within isdn_tty_write() to perform | |
331 | * DLE-decoding when sending audio-data. | |
332 | */ | |
333 | static int | |
475be4d8 | 334 | isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) |
1da177e4 | 335 | { |
82e46b31 | 336 | unsigned char *p = &info->port.xmit_buf[info->xmit_count]; |
1da177e4 LT |
337 | int count = 0; |
338 | ||
339 | while (len > 0) { | |
340 | if (m->lastDLE) { | |
341 | m->lastDLE = 0; | |
342 | switch (*p) { | |
475be4d8 JP |
343 | case DLE: |
344 | /* Escape code */ | |
345 | if (len > 1) | |
346 | memmove(p, p + 1, len - 1); | |
347 | p--; | |
348 | count++; | |
349 | break; | |
350 | case ETX: | |
351 | /* End of data */ | |
352 | info->vonline |= 4; | |
353 | return count; | |
354 | case DC4: | |
355 | /* Abort RX */ | |
356 | info->vonline &= ~1; | |
1da177e4 | 357 | #ifdef ISDN_DEBUG_MODEM_VOICE |
475be4d8 JP |
358 | printk(KERN_DEBUG |
359 | "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n", | |
360 | info->line); | |
1da177e4 | 361 | #endif |
475be4d8 JP |
362 | isdn_tty_at_cout("\020\003", info); |
363 | if (!info->vonline) { | |
1da177e4 | 364 | #ifdef ISDN_DEBUG_MODEM_VOICE |
475be4d8 JP |
365 | printk(KERN_DEBUG |
366 | "DLEdown: send VCON on ttyI%d\n", | |
367 | info->line); | |
1da177e4 | 368 | #endif |
475be4d8 JP |
369 | isdn_tty_at_cout("\r\nVCON\r\n", info); |
370 | } | |
371 | /* Fall through */ | |
372 | case 'q': | |
373 | case 's': | |
374 | /* Silence */ | |
375 | if (len > 1) | |
376 | memmove(p, p + 1, len - 1); | |
377 | p--; | |
378 | break; | |
1da177e4 LT |
379 | } |
380 | } else { | |
381 | if (*p == DLE) | |
382 | m->lastDLE = 1; | |
383 | else | |
384 | count++; | |
385 | } | |
386 | p++; | |
387 | len--; | |
388 | } | |
389 | if (len < 0) { | |
390 | printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n"); | |
391 | return 0; | |
392 | } | |
393 | return count; | |
394 | } | |
395 | ||
396 | /* This routine is called from within isdn_tty_write() when receiving | |
397 | * audio-data. It interrupts receiving, if an character other than | |
398 | * ^S or ^Q is sent. | |
399 | */ | |
400 | static int | |
401 | isdn_tty_end_vrx(const char *buf, int c) | |
402 | { | |
403 | char ch; | |
404 | ||
405 | while (c--) { | |
406 | ch = *buf; | |
407 | if ((ch != 0x11) && (ch != 0x13)) | |
408 | return 1; | |
409 | buf++; | |
410 | } | |
411 | return 0; | |
412 | } | |
413 | ||
414 | static int voice_cf[7] = | |
415 | {0, 0, 4, 3, 2, 0, 0}; | |
416 | ||
417 | #endif /* CONFIG_ISDN_AUDIO */ | |
418 | ||
419 | /* isdn_tty_senddown() is called either directly from within isdn_tty_write() | |
420 | * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls | |
421 | * outgoing data from the tty's xmit-buffer, handles voice-decompression or | |
422 | * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint. | |
423 | */ | |
424 | static void | |
475be4d8 | 425 | isdn_tty_senddown(modem_info *info) |
1da177e4 LT |
426 | { |
427 | int buflen; | |
428 | int skb_res; | |
429 | #ifdef CONFIG_ISDN_AUDIO | |
430 | int audio_len; | |
431 | #endif | |
432 | struct sk_buff *skb; | |
433 | ||
434 | #ifdef CONFIG_ISDN_AUDIO | |
435 | if (info->vonline & 4) { | |
436 | info->vonline &= ~6; | |
437 | if (!info->vonline) { | |
438 | #ifdef ISDN_DEBUG_MODEM_VOICE | |
439 | printk(KERN_DEBUG | |
440 | "senddown: send VCON on ttyI%d\n", | |
441 | info->line); | |
442 | #endif | |
443 | isdn_tty_at_cout("\r\nVCON\r\n", info); | |
444 | } | |
445 | } | |
446 | #endif | |
447 | if (!(buflen = info->xmit_count)) | |
448 | return; | |
475be4d8 | 449 | if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0) |
1da177e4 | 450 | info->msr &= ~UART_MSR_CTS; |
475be4d8 | 451 | info->lsr &= ~UART_LSR_TEMT; |
1da177e4 LT |
452 | /* info->xmit_count is modified here and in isdn_tty_write(). |
453 | * So we return here if isdn_tty_write() is in the | |
454 | * critical section. | |
455 | */ | |
456 | atomic_inc(&info->xmit_lock); | |
457 | if (!(atomic_dec_and_test(&info->xmit_lock))) | |
458 | return; | |
459 | if (info->isdn_driver < 0) { | |
460 | info->xmit_count = 0; | |
461 | return; | |
462 | } | |
463 | skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4; | |
464 | #ifdef CONFIG_ISDN_AUDIO | |
465 | if (info->vonline & 2) | |
466 | audio_len = buflen * voice_cf[info->emu.vpar[3]]; | |
467 | else | |
468 | audio_len = 0; | |
469 | skb = dev_alloc_skb(skb_res + buflen + audio_len); | |
470 | #else | |
471 | skb = dev_alloc_skb(skb_res + buflen); | |
472 | #endif | |
473 | if (!skb) { | |
474 | printk(KERN_WARNING | |
475 | "isdn_tty: Out of memory in ttyI%d senddown\n", | |
476 | info->line); | |
477 | return; | |
478 | } | |
479 | skb_reserve(skb, skb_res); | |
82e46b31 | 480 | memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen); |
1da177e4 LT |
481 | info->xmit_count = 0; |
482 | #ifdef CONFIG_ISDN_AUDIO | |
483 | if (info->vonline & 2) { | |
484 | /* For now, ifmt is fixed to 1 (alaw), since this | |
485 | * is used with ISDN everywhere in the world, except | |
486 | * US, Canada and Japan. | |
487 | * Later, when US-ISDN protocols are implemented, | |
488 | * this setting will depend on the D-channel protocol. | |
489 | */ | |
490 | int ifmt = 1; | |
491 | ||
492 | /* voice conversion/decompression */ | |
493 | switch (info->emu.vpar[3]) { | |
475be4d8 JP |
494 | case 2: |
495 | case 3: | |
496 | case 4: | |
497 | /* adpcm, compatible to ZyXel 1496 modem | |
498 | * with ROM revision 6.01 | |
499 | */ | |
500 | audio_len = isdn_audio_adpcm2xlaw(info->adpcms, | |
501 | ifmt, | |
502 | skb->data, | |
503 | skb_put(skb, audio_len), | |
504 | buflen); | |
505 | skb_pull(skb, buflen); | |
506 | skb_trim(skb, audio_len); | |
507 | break; | |
508 | case 5: | |
509 | /* a-law */ | |
510 | if (!ifmt) | |
511 | isdn_audio_alaw2ulaw(skb->data, | |
512 | buflen); | |
513 | break; | |
514 | case 6: | |
515 | /* u-law */ | |
516 | if (ifmt) | |
517 | isdn_audio_ulaw2alaw(skb->data, | |
518 | buflen); | |
519 | break; | |
1da177e4 LT |
520 | } |
521 | } | |
522 | #endif /* CONFIG_ISDN_AUDIO */ | |
523 | if (info->emu.mdmreg[REG_T70] & BIT_T70) { | |
524 | /* Add T.70 simplified header */ | |
525 | if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) | |
526 | memcpy(skb_push(skb, 2), "\1\0", 2); | |
527 | else | |
528 | memcpy(skb_push(skb, 4), "\1\0\1\0", 4); | |
529 | } | |
530 | skb_queue_tail(&info->xmit_queue, skb); | |
531 | } | |
532 | ||
533 | /************************************************************ | |
534 | * | |
535 | * Modem-functions | |
536 | * | |
537 | * mostly "stolen" from original Linux-serial.c and friends. | |
538 | * | |
539 | ************************************************************/ | |
540 | ||
541 | /* The next routine is called once from within timer-interrupt | |
542 | * triggered within isdn_tty_modem_ncarrier(). It calls | |
543 | * isdn_tty_modem_result() to stuff a "NO CARRIER" Message | |
33f0f88f | 544 | * into the tty's buffer. |
1da177e4 LT |
545 | */ |
546 | static void | |
547 | isdn_tty_modem_do_ncarrier(unsigned long data) | |
548 | { | |
549 | modem_info *info = (modem_info *) data; | |
550 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
551 | } | |
552 | ||
553 | /* Next routine is called, whenever the DTR-signal is raised. | |
554 | * It checks the ncarrier-flag, and triggers the above routine | |
555 | * when necessary. The ncarrier-flag is set, whenever DTR goes | |
556 | * low. | |
557 | */ | |
558 | static void | |
475be4d8 | 559 | isdn_tty_modem_ncarrier(modem_info *info) |
1da177e4 LT |
560 | { |
561 | if (info->ncarrier) { | |
562 | info->nc_timer.expires = jiffies + HZ; | |
563 | add_timer(&info->nc_timer); | |
564 | } | |
565 | } | |
566 | ||
567 | /* | |
568 | * return the usage calculated by si and layer 2 protocol | |
569 | */ | |
3e206b0a | 570 | static int |
1da177e4 LT |
571 | isdn_calc_usage(int si, int l2) |
572 | { | |
573 | int usg = ISDN_USAGE_MODEM; | |
574 | ||
575 | #ifdef CONFIG_ISDN_AUDIO | |
576 | if (si == 1) { | |
475be4d8 JP |
577 | switch (l2) { |
578 | case ISDN_PROTO_L2_MODEM: | |
579 | usg = ISDN_USAGE_MODEM; | |
580 | break; | |
1da177e4 | 581 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 JP |
582 | case ISDN_PROTO_L2_FAX: |
583 | usg = ISDN_USAGE_FAX; | |
584 | break; | |
1da177e4 | 585 | #endif |
475be4d8 JP |
586 | case ISDN_PROTO_L2_TRANS: |
587 | default: | |
588 | usg = ISDN_USAGE_VOICE; | |
589 | break; | |
1da177e4 LT |
590 | } |
591 | } | |
592 | #endif | |
475be4d8 | 593 | return (usg); |
1da177e4 LT |
594 | } |
595 | ||
596 | /* isdn_tty_dial() performs dialing of a tty an the necessary | |
597 | * setup of the lower levels before that. | |
598 | */ | |
599 | static void | |
475be4d8 | 600 | isdn_tty_dial(char *n, modem_info *info, atemu *m) |
1da177e4 LT |
601 | { |
602 | int usg = ISDN_USAGE_MODEM; | |
603 | int si = 7; | |
604 | int l2 = m->mdmreg[REG_L2PROT]; | |
605 | u_long flags; | |
606 | isdn_ctrl cmd; | |
607 | int i; | |
608 | int j; | |
609 | ||
610 | for (j = 7; j >= 0; j--) | |
611 | if (m->mdmreg[REG_SI1] & (1 << j)) { | |
612 | si = bit2si[j]; | |
613 | break; | |
614 | } | |
615 | usg = isdn_calc_usage(si, l2); | |
616 | #ifdef CONFIG_ISDN_AUDIO | |
475be4d8 JP |
617 | if ((si == 1) && |
618 | (l2 != ISDN_PROTO_L2_MODEM) | |
1da177e4 | 619 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 | 620 | && (l2 != ISDN_PROTO_L2_FAX) |
1da177e4 LT |
621 | #endif |
622 | ) { | |
623 | l2 = ISDN_PROTO_L2_TRANS; | |
624 | usg = ISDN_USAGE_VOICE; | |
625 | } | |
626 | #endif | |
627 | m->mdmreg[REG_SI1I] = si2bit[si]; | |
628 | spin_lock_irqsave(&dev->lock, flags); | |
629 | i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); | |
630 | if (i < 0) { | |
631 | spin_unlock_irqrestore(&dev->lock, flags); | |
632 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); | |
633 | } else { | |
634 | info->isdn_driver = dev->drvmap[i]; | |
635 | info->isdn_channel = dev->chanmap[i]; | |
636 | info->drv_index = i; | |
637 | dev->m_idx[i] = info->line; | |
638 | dev->usage[i] |= ISDN_USAGE_OUTGOING; | |
639 | info->last_dir = 1; | |
640 | strcpy(info->last_num, n); | |
641 | isdn_info_update(); | |
642 | spin_unlock_irqrestore(&dev->lock, flags); | |
643 | cmd.driver = info->isdn_driver; | |
644 | cmd.arg = info->isdn_channel; | |
645 | cmd.command = ISDN_CMD_CLREAZ; | |
646 | isdn_command(&cmd); | |
647 | strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); | |
648 | cmd.driver = info->isdn_driver; | |
649 | cmd.command = ISDN_CMD_SETEAZ; | |
650 | isdn_command(&cmd); | |
651 | cmd.driver = info->isdn_driver; | |
652 | cmd.command = ISDN_CMD_SETL2; | |
653 | info->last_l2 = l2; | |
654 | cmd.arg = info->isdn_channel + (l2 << 8); | |
655 | isdn_command(&cmd); | |
656 | cmd.driver = info->isdn_driver; | |
657 | cmd.command = ISDN_CMD_SETL3; | |
658 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); | |
659 | #ifdef CONFIG_ISDN_TTY_FAX | |
660 | if (l2 == ISDN_PROTO_L2_FAX) { | |
661 | cmd.parm.fax = info->fax; | |
662 | info->fax->direction = ISDN_TTY_FAX_CONN_OUT; | |
663 | } | |
664 | #endif | |
665 | isdn_command(&cmd); | |
666 | cmd.driver = info->isdn_driver; | |
667 | cmd.arg = info->isdn_channel; | |
668 | sprintf(cmd.parm.setup.phone, "%s", n); | |
669 | sprintf(cmd.parm.setup.eazmsn, "%s", | |
670 | isdn_map_eaz2msn(m->msn, info->isdn_driver)); | |
671 | cmd.parm.setup.si1 = si; | |
672 | cmd.parm.setup.si2 = m->mdmreg[REG_SI2]; | |
673 | cmd.command = ISDN_CMD_DIAL; | |
674 | info->dialing = 1; | |
675 | info->emu.carrierwait = 0; | |
676 | strcpy(dev->num[i], n); | |
677 | isdn_info_update(); | |
678 | isdn_command(&cmd); | |
679 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); | |
680 | } | |
681 | } | |
682 | ||
683 | /* isdn_tty_hangup() disassociates a tty from the real | |
684 | * ISDN-line (hangup). The usage-status is cleared | |
685 | * and some cleanup is done also. | |
686 | */ | |
687 | void | |
475be4d8 | 688 | isdn_tty_modem_hup(modem_info *info, int local) |
1da177e4 LT |
689 | { |
690 | isdn_ctrl cmd; | |
691 | int di, ch; | |
692 | ||
693 | if (!info) | |
694 | return; | |
695 | ||
696 | di = info->isdn_driver; | |
697 | ch = info->isdn_channel; | |
698 | if (di < 0 || ch < 0) | |
699 | return; | |
700 | ||
701 | info->isdn_driver = -1; | |
702 | info->isdn_channel = -1; | |
703 | ||
704 | #ifdef ISDN_DEBUG_MODEM_HUP | |
705 | printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); | |
706 | #endif | |
707 | info->rcvsched = 0; | |
ba43294d | 708 | isdn_tty_flush_buffer(info->port.tty); |
1da177e4 LT |
709 | if (info->online) { |
710 | info->last_lhup = local; | |
711 | info->online = 0; | |
712 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
713 | } | |
714 | #ifdef CONFIG_ISDN_AUDIO | |
715 | info->vonline = 0; | |
716 | #ifdef CONFIG_ISDN_TTY_FAX | |
717 | info->faxonline = 0; | |
718 | info->fax->phase = ISDN_FAX_PHASE_IDLE; | |
719 | #endif | |
720 | info->emu.vpar[4] = 0; | |
721 | info->emu.vpar[5] = 8; | |
3c7208f2 JJ |
722 | kfree(info->dtmf_state); |
723 | info->dtmf_state = NULL; | |
724 | kfree(info->silence_state); | |
725 | info->silence_state = NULL; | |
726 | kfree(info->adpcms); | |
727 | info->adpcms = NULL; | |
728 | kfree(info->adpcmr); | |
729 | info->adpcmr = NULL; | |
1da177e4 LT |
730 | #endif |
731 | if ((info->msr & UART_MSR_RI) && | |
475be4d8 | 732 | (info->emu.mdmreg[REG_RUNG] & BIT_RUNG)) |
1da177e4 LT |
733 | isdn_tty_modem_result(RESULT_RUNG, info); |
734 | info->msr &= ~(UART_MSR_DCD | UART_MSR_RI); | |
735 | info->lsr |= UART_LSR_TEMT; | |
736 | ||
737 | if (local) { | |
738 | cmd.driver = di; | |
739 | cmd.command = ISDN_CMD_HANGUP; | |
740 | cmd.arg = ch; | |
741 | isdn_command(&cmd); | |
742 | } | |
743 | ||
744 | isdn_all_eaz(di, ch); | |
745 | info->emu.mdmreg[REG_RINGCNT] = 0; | |
746 | isdn_free_channel(di, ch, 0); | |
747 | ||
748 | if (info->drv_index >= 0) { | |
749 | dev->m_idx[info->drv_index] = -1; | |
750 | info->drv_index = -1; | |
751 | } | |
752 | } | |
753 | ||
754 | /* | |
475be4d8 | 755 | * Begin of a CAPI like interface, currently used only for |
1da177e4 LT |
756 | * supplementary service (CAPI 2.0 part III) |
757 | */ | |
758 | #include <linux/isdn/capicmd.h> | |
07a97fe8 | 759 | #include <linux/module.h> |
1da177e4 LT |
760 | |
761 | int | |
762 | isdn_tty_capi_facility(capi_msg *cm) { | |
475be4d8 | 763 | return (-1); /* dummy */ |
1da177e4 LT |
764 | } |
765 | ||
766 | /* isdn_tty_suspend() tries to suspend the current tty connection | |
767 | */ | |
768 | static void | |
475be4d8 | 769 | isdn_tty_suspend(char *id, modem_info *info, atemu *m) |
1da177e4 LT |
770 | { |
771 | isdn_ctrl cmd; | |
475be4d8 | 772 | |
1da177e4 LT |
773 | int l; |
774 | ||
775 | if (!info) | |
776 | return; | |
777 | ||
778 | #ifdef ISDN_DEBUG_MODEM_SERVICES | |
779 | printk(KERN_DEBUG "Msusp ttyI%d\n", info->line); | |
780 | #endif | |
781 | l = strlen(id); | |
782 | if ((info->isdn_driver >= 0)) { | |
475be4d8 | 783 | cmd.parm.cmsg.Length = l + 18; |
1da177e4 LT |
784 | cmd.parm.cmsg.Command = CAPI_FACILITY; |
785 | cmd.parm.cmsg.Subcommand = CAPI_REQ; | |
786 | cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; | |
787 | cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */ | |
788 | cmd.parm.cmsg.para[1] = 0; | |
789 | cmd.parm.cmsg.para[2] = l + 3; | |
790 | cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */ | |
791 | cmd.parm.cmsg.para[4] = 0; | |
792 | cmd.parm.cmsg.para[5] = l; | |
793 | strncpy(&cmd.parm.cmsg.para[6], id, l); | |
794 | cmd.command = CAPI_PUT_MESSAGE; | |
795 | cmd.driver = info->isdn_driver; | |
796 | cmd.arg = info->isdn_channel; | |
797 | isdn_command(&cmd); | |
798 | } | |
799 | } | |
800 | ||
801 | /* isdn_tty_resume() tries to resume a suspended call | |
25985edc | 802 | * setup of the lower levels before that. unfortunately here is no |
1da177e4 LT |
803 | * checking for compatibility of used protocols implemented by Q931 |
804 | * It does the same things like isdn_tty_dial, the last command | |
805 | * is different, may be we can merge it. | |
806 | */ | |
807 | ||
808 | static void | |
475be4d8 | 809 | isdn_tty_resume(char *id, modem_info *info, atemu *m) |
1da177e4 LT |
810 | { |
811 | int usg = ISDN_USAGE_MODEM; | |
812 | int si = 7; | |
813 | int l2 = m->mdmreg[REG_L2PROT]; | |
814 | isdn_ctrl cmd; | |
815 | ulong flags; | |
816 | int i; | |
817 | int j; | |
818 | int l; | |
819 | ||
820 | l = strlen(id); | |
821 | for (j = 7; j >= 0; j--) | |
822 | if (m->mdmreg[REG_SI1] & (1 << j)) { | |
823 | si = bit2si[j]; | |
824 | break; | |
825 | } | |
826 | usg = isdn_calc_usage(si, l2); | |
827 | #ifdef CONFIG_ISDN_AUDIO | |
475be4d8 JP |
828 | if ((si == 1) && |
829 | (l2 != ISDN_PROTO_L2_MODEM) | |
1da177e4 | 830 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 | 831 | && (l2 != ISDN_PROTO_L2_FAX) |
1da177e4 LT |
832 | #endif |
833 | ) { | |
834 | l2 = ISDN_PROTO_L2_TRANS; | |
835 | usg = ISDN_USAGE_VOICE; | |
836 | } | |
837 | #endif | |
838 | m->mdmreg[REG_SI1I] = si2bit[si]; | |
839 | spin_lock_irqsave(&dev->lock, flags); | |
840 | i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); | |
841 | if (i < 0) { | |
842 | spin_unlock_irqrestore(&dev->lock, flags); | |
843 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); | |
844 | } else { | |
845 | info->isdn_driver = dev->drvmap[i]; | |
846 | info->isdn_channel = dev->chanmap[i]; | |
847 | info->drv_index = i; | |
848 | dev->m_idx[i] = info->line; | |
849 | dev->usage[i] |= ISDN_USAGE_OUTGOING; | |
850 | info->last_dir = 1; | |
851 | // strcpy(info->last_num, n); | |
852 | isdn_info_update(); | |
853 | spin_unlock_irqrestore(&dev->lock, flags); | |
854 | cmd.driver = info->isdn_driver; | |
855 | cmd.arg = info->isdn_channel; | |
856 | cmd.command = ISDN_CMD_CLREAZ; | |
857 | isdn_command(&cmd); | |
858 | strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); | |
859 | cmd.driver = info->isdn_driver; | |
860 | cmd.command = ISDN_CMD_SETEAZ; | |
861 | isdn_command(&cmd); | |
862 | cmd.driver = info->isdn_driver; | |
863 | cmd.command = ISDN_CMD_SETL2; | |
864 | info->last_l2 = l2; | |
865 | cmd.arg = info->isdn_channel + (l2 << 8); | |
866 | isdn_command(&cmd); | |
867 | cmd.driver = info->isdn_driver; | |
868 | cmd.command = ISDN_CMD_SETL3; | |
869 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); | |
870 | isdn_command(&cmd); | |
871 | cmd.driver = info->isdn_driver; | |
872 | cmd.arg = info->isdn_channel; | |
475be4d8 | 873 | cmd.parm.cmsg.Length = l + 18; |
1da177e4 LT |
874 | cmd.parm.cmsg.Command = CAPI_FACILITY; |
875 | cmd.parm.cmsg.Subcommand = CAPI_REQ; | |
876 | cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; | |
877 | cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */ | |
878 | cmd.parm.cmsg.para[1] = 0; | |
475be4d8 | 879 | cmd.parm.cmsg.para[2] = l + 3; |
1da177e4 LT |
880 | cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */ |
881 | cmd.parm.cmsg.para[4] = 0; | |
882 | cmd.parm.cmsg.para[5] = l; | |
883 | strncpy(&cmd.parm.cmsg.para[6], id, l); | |
475be4d8 | 884 | cmd.command = CAPI_PUT_MESSAGE; |
1da177e4 LT |
885 | info->dialing = 1; |
886 | // strcpy(dev->num[i], n); | |
887 | isdn_info_update(); | |
888 | isdn_command(&cmd); | |
889 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); | |
890 | } | |
891 | } | |
892 | ||
893 | /* isdn_tty_send_msg() sends a message to a HL driver | |
894 | * This is used for hybrid modem cards to send AT commands to it | |
895 | */ | |
896 | ||
897 | static void | |
475be4d8 | 898 | isdn_tty_send_msg(modem_info *info, atemu *m, char *msg) |
1da177e4 LT |
899 | { |
900 | int usg = ISDN_USAGE_MODEM; | |
901 | int si = 7; | |
902 | int l2 = m->mdmreg[REG_L2PROT]; | |
903 | isdn_ctrl cmd; | |
904 | ulong flags; | |
905 | int i; | |
906 | int j; | |
907 | int l; | |
908 | ||
909 | l = strlen(msg); | |
910 | if (!l) { | |
911 | isdn_tty_modem_result(RESULT_ERROR, info); | |
912 | return; | |
913 | } | |
914 | for (j = 7; j >= 0; j--) | |
915 | if (m->mdmreg[REG_SI1] & (1 << j)) { | |
916 | si = bit2si[j]; | |
917 | break; | |
918 | } | |
919 | usg = isdn_calc_usage(si, l2); | |
920 | #ifdef CONFIG_ISDN_AUDIO | |
475be4d8 JP |
921 | if ((si == 1) && |
922 | (l2 != ISDN_PROTO_L2_MODEM) | |
1da177e4 | 923 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 | 924 | && (l2 != ISDN_PROTO_L2_FAX) |
1da177e4 LT |
925 | #endif |
926 | ) { | |
927 | l2 = ISDN_PROTO_L2_TRANS; | |
928 | usg = ISDN_USAGE_VOICE; | |
929 | } | |
930 | #endif | |
931 | m->mdmreg[REG_SI1I] = si2bit[si]; | |
932 | spin_lock_irqsave(&dev->lock, flags); | |
933 | i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); | |
934 | if (i < 0) { | |
935 | spin_unlock_irqrestore(&dev->lock, flags); | |
936 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); | |
937 | } else { | |
938 | info->isdn_driver = dev->drvmap[i]; | |
939 | info->isdn_channel = dev->chanmap[i]; | |
940 | info->drv_index = i; | |
941 | dev->m_idx[i] = info->line; | |
942 | dev->usage[i] |= ISDN_USAGE_OUTGOING; | |
943 | info->last_dir = 1; | |
944 | isdn_info_update(); | |
945 | spin_unlock_irqrestore(&dev->lock, flags); | |
946 | cmd.driver = info->isdn_driver; | |
947 | cmd.arg = info->isdn_channel; | |
948 | cmd.command = ISDN_CMD_CLREAZ; | |
949 | isdn_command(&cmd); | |
950 | strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); | |
951 | cmd.driver = info->isdn_driver; | |
952 | cmd.command = ISDN_CMD_SETEAZ; | |
953 | isdn_command(&cmd); | |
954 | cmd.driver = info->isdn_driver; | |
955 | cmd.command = ISDN_CMD_SETL2; | |
956 | info->last_l2 = l2; | |
957 | cmd.arg = info->isdn_channel + (l2 << 8); | |
958 | isdn_command(&cmd); | |
959 | cmd.driver = info->isdn_driver; | |
960 | cmd.command = ISDN_CMD_SETL3; | |
961 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); | |
962 | isdn_command(&cmd); | |
963 | cmd.driver = info->isdn_driver; | |
964 | cmd.arg = info->isdn_channel; | |
475be4d8 | 965 | cmd.parm.cmsg.Length = l + 14; |
1da177e4 LT |
966 | cmd.parm.cmsg.Command = CAPI_MANUFACTURER; |
967 | cmd.parm.cmsg.Subcommand = CAPI_REQ; | |
968 | cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; | |
475be4d8 | 969 | cmd.parm.cmsg.para[0] = l + 1; |
1da177e4 | 970 | strncpy(&cmd.parm.cmsg.para[1], msg, l); |
475be4d8 JP |
971 | cmd.parm.cmsg.para[l + 1] = 0xd; |
972 | cmd.command = CAPI_PUT_MESSAGE; | |
1da177e4 LT |
973 | /* info->dialing = 1; |
974 | strcpy(dev->num[i], n); | |
975 | isdn_info_update(); | |
976 | */ | |
977 | isdn_command(&cmd); | |
978 | } | |
979 | } | |
980 | ||
981 | static inline int | |
982 | isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine) | |
983 | { | |
984 | #ifdef MODEM_PARANOIA_CHECK | |
985 | if (!info) { | |
986 | printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n", | |
475be4d8 | 987 | name, routine); |
1da177e4 LT |
988 | return 1; |
989 | } | |
990 | if (info->magic != ISDN_ASYNC_MAGIC) { | |
991 | printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n", | |
992 | name, routine); | |
993 | return 1; | |
994 | } | |
995 | #endif | |
996 | return 0; | |
997 | } | |
998 | ||
999 | /* | |
1000 | * This routine is called to set the UART divisor registers to match | |
1001 | * the specified baud rate for a serial port. | |
1002 | */ | |
1003 | static void | |
475be4d8 | 1004 | isdn_tty_change_speed(modem_info *info) |
1da177e4 | 1005 | { |
265d6f00 | 1006 | struct tty_port *port = &info->port; |
1da177e4 | 1007 | uint cflag, |
475be4d8 JP |
1008 | cval, |
1009 | quot; | |
1da177e4 LT |
1010 | int i; |
1011 | ||
265d6f00 | 1012 | if (!port->tty || !port->tty->termios) |
1da177e4 | 1013 | return; |
265d6f00 | 1014 | cflag = port->tty->termios->c_cflag; |
1da177e4 LT |
1015 | |
1016 | quot = i = cflag & CBAUD; | |
1017 | if (i & CBAUDEX) { | |
1018 | i &= ~CBAUDEX; | |
1019 | if (i < 1 || i > 2) | |
265d6f00 | 1020 | port->tty->termios->c_cflag &= ~CBAUDEX; |
1da177e4 LT |
1021 | else |
1022 | i += 15; | |
1023 | } | |
1024 | if (quot) { | |
1025 | info->mcr |= UART_MCR_DTR; | |
1026 | isdn_tty_modem_ncarrier(info); | |
1027 | } else { | |
1028 | info->mcr &= ~UART_MCR_DTR; | |
1029 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { | |
1030 | #ifdef ISDN_DEBUG_MODEM_HUP | |
1031 | printk(KERN_DEBUG "Mhup in changespeed\n"); | |
1032 | #endif | |
1033 | if (info->online) | |
1034 | info->ncarrier = 1; | |
1035 | isdn_tty_modem_reset_regs(info, 0); | |
1036 | isdn_tty_modem_hup(info, 1); | |
1037 | } | |
1038 | return; | |
1039 | } | |
1040 | /* byte size and parity */ | |
1041 | cval = cflag & (CSIZE | CSTOPB); | |
1042 | cval >>= 4; | |
1043 | if (cflag & PARENB) | |
1044 | cval |= UART_LCR_PARITY; | |
1045 | if (!(cflag & PARODD)) | |
1046 | cval |= UART_LCR_EPAR; | |
1da177e4 LT |
1047 | |
1048 | /* CTS flow control flag and modem status interrupts */ | |
1049 | if (cflag & CRTSCTS) { | |
265d6f00 | 1050 | port->flags |= ASYNC_CTS_FLOW; |
1da177e4 | 1051 | } else |
265d6f00 | 1052 | port->flags &= ~ASYNC_CTS_FLOW; |
1da177e4 | 1053 | if (cflag & CLOCAL) |
265d6f00 | 1054 | port->flags &= ~ASYNC_CHECK_CD; |
1da177e4 | 1055 | else { |
265d6f00 | 1056 | port->flags |= ASYNC_CHECK_CD; |
1da177e4 LT |
1057 | } |
1058 | } | |
1059 | ||
1060 | static int | |
475be4d8 | 1061 | isdn_tty_startup(modem_info *info) |
1da177e4 | 1062 | { |
48decc1c | 1063 | if (info->port.flags & ASYNC_INITIALIZED) |
1da177e4 LT |
1064 | return 0; |
1065 | isdn_lock_drivers(); | |
1066 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1067 | printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line); | |
1068 | #endif | |
1069 | /* | |
1070 | * Now, initialize the UART | |
1071 | */ | |
1072 | info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; | |
ba43294d JS |
1073 | if (info->port.tty) |
1074 | clear_bit(TTY_IO_ERROR, &info->port.tty->flags); | |
1da177e4 LT |
1075 | /* |
1076 | * and set the speed of the serial port | |
1077 | */ | |
1078 | isdn_tty_change_speed(info); | |
1079 | ||
48decc1c | 1080 | info->port.flags |= ASYNC_INITIALIZED; |
1da177e4 LT |
1081 | info->msr |= (UART_MSR_DSR | UART_MSR_CTS); |
1082 | info->send_outstanding = 0; | |
1083 | return 0; | |
1084 | } | |
1085 | ||
1086 | /* | |
1087 | * This routine will shutdown a serial port; interrupts are disabled, and | |
1088 | * DTR is dropped if the hangup on close termio flag is on. | |
1089 | */ | |
1090 | static void | |
475be4d8 | 1091 | isdn_tty_shutdown(modem_info *info) |
1da177e4 | 1092 | { |
48decc1c | 1093 | if (!(info->port.flags & ASYNC_INITIALIZED)) |
1da177e4 LT |
1094 | return; |
1095 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1096 | printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); | |
1097 | #endif | |
1098 | isdn_unlock_drivers(); | |
1099 | info->msr &= ~UART_MSR_RI; | |
ba43294d | 1100 | if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) { |
1da177e4 LT |
1101 | info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); |
1102 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { | |
1103 | isdn_tty_modem_reset_regs(info, 0); | |
1104 | #ifdef ISDN_DEBUG_MODEM_HUP | |
1105 | printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n"); | |
1106 | #endif | |
1107 | isdn_tty_modem_hup(info, 1); | |
1108 | } | |
1109 | } | |
ba43294d JS |
1110 | if (info->port.tty) |
1111 | set_bit(TTY_IO_ERROR, &info->port.tty->flags); | |
1da177e4 | 1112 | |
48decc1c | 1113 | info->port.flags &= ~ASYNC_INITIALIZED; |
1da177e4 LT |
1114 | } |
1115 | ||
1116 | /* isdn_tty_write() is the main send-routine. It is called from the upper | |
1117 | * levels within the kernel to perform sending data. Depending on the | |
1118 | * online-flag it either directs output to the at-command-interpreter or | |
1119 | * to the lower level. Additional tasks done here: | |
1120 | * - If online, check for escape-sequence (+++) | |
1121 | * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes. | |
1122 | * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed. | |
1123 | * - If dialing, abort dial. | |
1124 | */ | |
1125 | static int | |
475be4d8 | 1126 | isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count) |
1da177e4 LT |
1127 | { |
1128 | int c; | |
1129 | int total = 0; | |
1130 | modem_info *info = (modem_info *) tty->driver_data; | |
1131 | atemu *m = &info->emu; | |
1132 | ||
1133 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write")) | |
1134 | return 0; | |
1135 | /* See isdn_tty_senddown() */ | |
1136 | atomic_inc(&info->xmit_lock); | |
1137 | while (1) { | |
1138 | c = count; | |
1139 | if (c > info->xmit_size - info->xmit_count) | |
1140 | c = info->xmit_size - info->xmit_count; | |
1141 | if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize) | |
1142 | c = dev->drv[info->isdn_driver]->maxbufsize; | |
1143 | if (c <= 0) | |
1144 | break; | |
1145 | if ((info->online > 1) | |
1146 | #ifdef CONFIG_ISDN_AUDIO | |
1147 | || (info->vonline & 3) | |
1148 | #endif | |
1149 | ) { | |
1150 | #ifdef CONFIG_ISDN_AUDIO | |
1151 | if (!info->vonline) | |
1152 | #endif | |
1153 | isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, | |
1154 | &(m->pluscount), | |
1155 | &(m->lastplus)); | |
82e46b31 | 1156 | memcpy(&info->port.xmit_buf[info->xmit_count], buf, c); |
1da177e4 LT |
1157 | #ifdef CONFIG_ISDN_AUDIO |
1158 | if (info->vonline) { | |
1159 | int cc = isdn_tty_handleDLEdown(info, m, c); | |
1160 | if (info->vonline & 2) { | |
1161 | if (!cc) { | |
1162 | /* If DLE decoding results in zero-transmit, but | |
1163 | * c originally was non-zero, do a wakeup. | |
1164 | */ | |
1165 | tty_wakeup(tty); | |
1166 | info->msr |= UART_MSR_CTS; | |
1167 | info->lsr |= UART_LSR_TEMT; | |
1168 | } | |
1169 | info->xmit_count += cc; | |
1170 | } | |
1171 | if ((info->vonline & 3) == 1) { | |
1172 | /* Do NOT handle Ctrl-Q or Ctrl-S | |
1173 | * when in full-duplex audio mode. | |
1174 | */ | |
1175 | if (isdn_tty_end_vrx(buf, c)) { | |
1176 | info->vonline &= ~1; | |
1177 | #ifdef ISDN_DEBUG_MODEM_VOICE | |
1178 | printk(KERN_DEBUG | |
1179 | "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n", | |
1180 | info->line); | |
1181 | #endif | |
1182 | isdn_tty_at_cout("\020\003\r\nVCON\r\n", info); | |
1183 | } | |
1184 | } | |
1185 | } else | |
475be4d8 JP |
1186 | if (TTY_IS_FCLASS1(info)) { |
1187 | int cc = isdn_tty_handleDLEdown(info, m, c); | |
1188 | ||
1189 | if (info->vonline & 4) { /* ETX seen */ | |
1190 | isdn_ctrl c; | |
1191 | ||
1192 | c.command = ISDN_CMD_FAXCMD; | |
1193 | c.driver = info->isdn_driver; | |
1194 | c.arg = info->isdn_channel; | |
1195 | c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL; | |
1196 | c.parm.aux.subcmd = ETX; | |
1197 | isdn_command(&c); | |
1198 | } | |
1199 | info->vonline = 0; | |
1da177e4 | 1200 | #ifdef ISDN_DEBUG_MODEM_VOICE |
475be4d8 | 1201 | printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c); |
1da177e4 | 1202 | #endif |
475be4d8 JP |
1203 | info->xmit_count += cc; |
1204 | } else | |
1da177e4 | 1205 | #endif |
475be4d8 | 1206 | info->xmit_count += c; |
1da177e4 LT |
1207 | } else { |
1208 | info->msr |= UART_MSR_CTS; | |
1209 | info->lsr |= UART_LSR_TEMT; | |
1210 | if (info->dialing) { | |
1211 | info->dialing = 0; | |
1212 | #ifdef ISDN_DEBUG_MODEM_HUP | |
1213 | printk(KERN_DEBUG "Mhup in isdn_tty_write\n"); | |
1214 | #endif | |
1215 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
1216 | isdn_tty_modem_hup(info, 1); | |
1217 | } else | |
1218 | c = isdn_tty_edit_at(buf, c, info); | |
1219 | } | |
1220 | buf += c; | |
1221 | count -= c; | |
1222 | total += c; | |
1223 | } | |
1224 | atomic_dec(&info->xmit_lock); | |
b03efcfb | 1225 | if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) { |
1da177e4 LT |
1226 | if (m->mdmreg[REG_DXMT] & BIT_DXMT) { |
1227 | isdn_tty_senddown(info); | |
1228 | isdn_tty_tint(info); | |
1229 | } | |
1230 | isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); | |
1231 | } | |
1232 | return total; | |
1233 | } | |
1234 | ||
1235 | static int | |
1236 | isdn_tty_write_room(struct tty_struct *tty) | |
1237 | { | |
1238 | modem_info *info = (modem_info *) tty->driver_data; | |
1239 | int ret; | |
1240 | ||
1241 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room")) | |
1242 | return 0; | |
1243 | if (!info->online) | |
1244 | return info->xmit_size; | |
1245 | ret = info->xmit_size - info->xmit_count; | |
1246 | return (ret < 0) ? 0 : ret; | |
1247 | } | |
1248 | ||
1249 | static int | |
1250 | isdn_tty_chars_in_buffer(struct tty_struct *tty) | |
1251 | { | |
1252 | modem_info *info = (modem_info *) tty->driver_data; | |
1253 | ||
1254 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer")) | |
1255 | return 0; | |
1256 | if (!info->online) | |
1257 | return 0; | |
1258 | return (info->xmit_count); | |
1259 | } | |
1260 | ||
1261 | static void | |
1262 | isdn_tty_flush_buffer(struct tty_struct *tty) | |
1263 | { | |
1264 | modem_info *info; | |
1265 | ||
1266 | if (!tty) { | |
1267 | return; | |
1268 | } | |
1269 | info = (modem_info *) tty->driver_data; | |
1270 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) { | |
1271 | return; | |
1272 | } | |
1273 | isdn_tty_cleanup_xmit(info); | |
1274 | info->xmit_count = 0; | |
1da177e4 LT |
1275 | tty_wakeup(tty); |
1276 | } | |
1277 | ||
1278 | static void | |
1279 | isdn_tty_flush_chars(struct tty_struct *tty) | |
1280 | { | |
1281 | modem_info *info = (modem_info *) tty->driver_data; | |
1282 | ||
1283 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars")) | |
1284 | return; | |
b03efcfb | 1285 | if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) |
1da177e4 LT |
1286 | isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); |
1287 | } | |
1288 | ||
1289 | /* | |
1290 | * ------------------------------------------------------------ | |
1291 | * isdn_tty_throttle() | |
1292 | * | |
1293 | * This routine is called by the upper-layer tty layer to signal that | |
1294 | * incoming characters should be throttled. | |
1295 | * ------------------------------------------------------------ | |
1296 | */ | |
1297 | static void | |
1298 | isdn_tty_throttle(struct tty_struct *tty) | |
1299 | { | |
1300 | modem_info *info = (modem_info *) tty->driver_data; | |
1301 | ||
1302 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle")) | |
1303 | return; | |
1304 | if (I_IXOFF(tty)) | |
1305 | info->x_char = STOP_CHAR(tty); | |
1306 | info->mcr &= ~UART_MCR_RTS; | |
1307 | } | |
1308 | ||
1309 | static void | |
1310 | isdn_tty_unthrottle(struct tty_struct *tty) | |
1311 | { | |
1312 | modem_info *info = (modem_info *) tty->driver_data; | |
1313 | ||
1314 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle")) | |
1315 | return; | |
1316 | if (I_IXOFF(tty)) { | |
1317 | if (info->x_char) | |
1318 | info->x_char = 0; | |
1319 | else | |
1320 | info->x_char = START_CHAR(tty); | |
1321 | } | |
1322 | info->mcr |= UART_MCR_RTS; | |
1323 | } | |
1324 | ||
1325 | /* | |
1326 | * ------------------------------------------------------------ | |
1327 | * isdn_tty_ioctl() and friends | |
1328 | * ------------------------------------------------------------ | |
1329 | */ | |
1330 | ||
1331 | /* | |
1332 | * isdn_tty_get_lsr_info - get line status register info | |
1333 | * | |
1334 | * Purpose: Let user call ioctl() to get info when the UART physically | |
1335 | * is emptied. On bus types like RS485, the transmitter must | |
1336 | * release the bus after transmitting. This must be done when | |
1337 | * the transmit shift register is empty, not be done when the | |
1338 | * transmit holding register is empty. This functionality | |
1339 | * allows RS485 driver to be written in user space. | |
1340 | */ | |
1341 | static int | |
475be4d8 | 1342 | isdn_tty_get_lsr_info(modem_info *info, uint __user *value) |
1da177e4 LT |
1343 | { |
1344 | u_char status; | |
1345 | uint result; | |
1346 | ||
1347 | status = info->lsr; | |
1348 | result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); | |
1349 | return put_user(result, value); | |
1350 | } | |
1351 | ||
1352 | ||
1353 | static int | |
60b33c13 | 1354 | isdn_tty_tiocmget(struct tty_struct *tty) |
1da177e4 LT |
1355 | { |
1356 | modem_info *info = (modem_info *) tty->driver_data; | |
1357 | u_char control, status; | |
1358 | ||
156f1ed6 | 1359 | if (isdn_tty_paranoia_check(info, tty->name, __func__)) |
1da177e4 LT |
1360 | return -ENODEV; |
1361 | if (tty->flags & (1 << TTY_IO_ERROR)) | |
1362 | return -EIO; | |
1363 | ||
72250d44 | 1364 | mutex_lock(&modem_info_mutex); |
1da177e4 LT |
1365 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
1366 | printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line); | |
1367 | #endif | |
1368 | ||
1369 | control = info->mcr; | |
1370 | status = info->msr; | |
72250d44 | 1371 | mutex_unlock(&modem_info_mutex); |
1da177e4 | 1372 | return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
475be4d8 JP |
1373 | | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
1374 | | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) | |
1375 | | ((status & UART_MSR_RI) ? TIOCM_RNG : 0) | |
1376 | | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) | |
1377 | | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0); | |
1da177e4 LT |
1378 | } |
1379 | ||
1380 | static int | |
20b9d177 | 1381 | isdn_tty_tiocmset(struct tty_struct *tty, |
475be4d8 | 1382 | unsigned int set, unsigned int clear) |
1da177e4 LT |
1383 | { |
1384 | modem_info *info = (modem_info *) tty->driver_data; | |
1385 | ||
156f1ed6 | 1386 | if (isdn_tty_paranoia_check(info, tty->name, __func__)) |
1da177e4 LT |
1387 | return -ENODEV; |
1388 | if (tty->flags & (1 << TTY_IO_ERROR)) | |
1389 | return -EIO; | |
1390 | ||
1391 | #ifdef ISDN_DEBUG_MODEM_IOCTL | |
1392 | printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear); | |
1393 | #endif | |
1394 | ||
72250d44 | 1395 | mutex_lock(&modem_info_mutex); |
1da177e4 LT |
1396 | if (set & TIOCM_RTS) |
1397 | info->mcr |= UART_MCR_RTS; | |
1398 | if (set & TIOCM_DTR) { | |
1399 | info->mcr |= UART_MCR_DTR; | |
1400 | isdn_tty_modem_ncarrier(info); | |
1401 | } | |
1402 | ||
1403 | if (clear & TIOCM_RTS) | |
1404 | info->mcr &= ~UART_MCR_RTS; | |
1405 | if (clear & TIOCM_DTR) { | |
1406 | info->mcr &= ~UART_MCR_DTR; | |
1407 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { | |
1408 | isdn_tty_modem_reset_regs(info, 0); | |
1409 | #ifdef ISDN_DEBUG_MODEM_HUP | |
1410 | printk(KERN_DEBUG "Mhup in TIOCMSET\n"); | |
1411 | #endif | |
1412 | if (info->online) | |
1413 | info->ncarrier = 1; | |
1414 | isdn_tty_modem_hup(info, 1); | |
1415 | } | |
1416 | } | |
72250d44 | 1417 | mutex_unlock(&modem_info_mutex); |
1da177e4 LT |
1418 | return 0; |
1419 | } | |
1420 | ||
1421 | static int | |
6caa76b7 | 1422 | isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong arg) |
1da177e4 LT |
1423 | { |
1424 | modem_info *info = (modem_info *) tty->driver_data; | |
1425 | int retval; | |
1426 | ||
1427 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl")) | |
1428 | return -ENODEV; | |
1429 | if (tty->flags & (1 << TTY_IO_ERROR)) | |
1430 | return -EIO; | |
1431 | switch (cmd) { | |
475be4d8 | 1432 | case TCSBRK: /* SVID version: non-zero arg --> no break */ |
1da177e4 | 1433 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
475be4d8 JP |
1434 | printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line); |
1435 | #endif | |
1436 | retval = tty_check_change(tty); | |
1437 | if (retval) | |
1438 | return retval; | |
1439 | tty_wait_until_sent(tty, 0); | |
1440 | return 0; | |
1441 | case TCSBRKP: /* support for POSIX tcsendbreak() */ | |
1da177e4 | 1442 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
475be4d8 JP |
1443 | printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line); |
1444 | #endif | |
1445 | retval = tty_check_change(tty); | |
1446 | if (retval) | |
1447 | return retval; | |
1448 | tty_wait_until_sent(tty, 0); | |
1449 | return 0; | |
1450 | case TIOCSERGETLSR: /* Get line status register */ | |
1da177e4 | 1451 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
475be4d8 | 1452 | printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line); |
1da177e4 | 1453 | #endif |
475be4d8 JP |
1454 | return isdn_tty_get_lsr_info(info, (uint __user *) arg); |
1455 | default: | |
1da177e4 | 1456 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
475be4d8 | 1457 | printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line); |
1da177e4 | 1458 | #endif |
475be4d8 | 1459 | return -ENOIOCTLCMD; |
1da177e4 LT |
1460 | } |
1461 | return 0; | |
1462 | } | |
1463 | ||
1464 | static void | |
606d099c | 1465 | isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) |
1da177e4 LT |
1466 | { |
1467 | modem_info *info = (modem_info *) tty->driver_data; | |
1468 | ||
1469 | if (!old_termios) | |
1470 | isdn_tty_change_speed(info); | |
1471 | else { | |
6e4d376c AC |
1472 | if (tty->termios->c_cflag == old_termios->c_cflag && |
1473 | tty->termios->c_ispeed == old_termios->c_ispeed && | |
1474 | tty->termios->c_ospeed == old_termios->c_ospeed) | |
1da177e4 LT |
1475 | return; |
1476 | isdn_tty_change_speed(info); | |
1477 | if ((old_termios->c_cflag & CRTSCTS) && | |
6e4d376c | 1478 | !(tty->termios->c_cflag & CRTSCTS)) |
1da177e4 | 1479 | tty->hw_stopped = 0; |
1da177e4 LT |
1480 | } |
1481 | } | |
1482 | ||
1483 | /* | |
1484 | * ------------------------------------------------------------ | |
1485 | * isdn_tty_open() and friends | |
1486 | * ------------------------------------------------------------ | |
1487 | */ | |
042b9e7c | 1488 | |
1da177e4 | 1489 | static int |
475be4d8 | 1490 | isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info *info) |
1da177e4 | 1491 | { |
265d6f00 | 1492 | struct tty_port *port = &info->port; |
1da177e4 LT |
1493 | DECLARE_WAITQUEUE(wait, NULL); |
1494 | int do_clocal = 0; | |
1495 | int retval; | |
1496 | ||
1497 | /* | |
1498 | * If the device is in the middle of being closed, then block | |
1499 | * until it's done, and then try again. | |
1500 | */ | |
1501 | if (tty_hung_up_p(filp) || | |
265d6f00 JS |
1502 | (port->flags & ASYNC_CLOSING)) { |
1503 | if (port->flags & ASYNC_CLOSING) | |
1504 | interruptible_sleep_on(&port->close_wait); | |
1da177e4 | 1505 | #ifdef MODEM_DO_RESTART |
265d6f00 | 1506 | if (port->flags & ASYNC_HUP_NOTIFY) |
1da177e4 LT |
1507 | return -EAGAIN; |
1508 | else | |
1509 | return -ERESTARTSYS; | |
1510 | #else | |
1511 | return -EAGAIN; | |
1512 | #endif | |
1513 | } | |
1514 | /* | |
1515 | * If non-blocking mode is set, then make the check up front | |
1516 | * and then exit. | |
1517 | */ | |
1518 | if ((filp->f_flags & O_NONBLOCK) || | |
1519 | (tty->flags & (1 << TTY_IO_ERROR))) { | |
265d6f00 | 1520 | port->flags |= ASYNC_NORMAL_ACTIVE; |
1da177e4 LT |
1521 | return 0; |
1522 | } | |
05eb48be JS |
1523 | if (tty->termios->c_cflag & CLOCAL) |
1524 | do_clocal = 1; | |
1da177e4 LT |
1525 | /* |
1526 | * Block waiting for the carrier detect and the line to become | |
1527 | * free (i.e., not in use by the callout). While we are in | |
1528 | * this loop, info->count is dropped by one, so that | |
1529 | * isdn_tty_close() knows when to free things. We restore it upon | |
1530 | * exit, either normal or abnormal. | |
1531 | */ | |
1532 | retval = 0; | |
265d6f00 | 1533 | add_wait_queue(&port->open_wait, &wait); |
1da177e4 LT |
1534 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1535 | printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n", | |
1536 | info->line, info->count); | |
1537 | #endif | |
1538 | if (!(tty_hung_up_p(filp))) | |
265d6f00 JS |
1539 | port->count--; |
1540 | port->blocked_open++; | |
1da177e4 LT |
1541 | while (1) { |
1542 | set_current_state(TASK_INTERRUPTIBLE); | |
1543 | if (tty_hung_up_p(filp) || | |
265d6f00 | 1544 | !(port->flags & ASYNC_INITIALIZED)) { |
1da177e4 | 1545 | #ifdef MODEM_DO_RESTART |
265d6f00 | 1546 | if (port->flags & ASYNC_HUP_NOTIFY) |
1da177e4 LT |
1547 | retval = -EAGAIN; |
1548 | else | |
1549 | retval = -ERESTARTSYS; | |
1550 | #else | |
1551 | retval = -EAGAIN; | |
1552 | #endif | |
1553 | break; | |
1554 | } | |
265d6f00 | 1555 | if (!(port->flags & ASYNC_CLOSING) && |
042b9e7c | 1556 | (do_clocal || tty_port_carrier_raised(port))) { |
1da177e4 LT |
1557 | break; |
1558 | } | |
1559 | if (signal_pending(current)) { | |
1560 | retval = -ERESTARTSYS; | |
1561 | break; | |
1562 | } | |
1563 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1564 | printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n", | |
265d6f00 | 1565 | info->line, port->count); |
1da177e4 LT |
1566 | #endif |
1567 | schedule(); | |
1568 | } | |
1569 | current->state = TASK_RUNNING; | |
265d6f00 | 1570 | remove_wait_queue(&port->open_wait, &wait); |
1da177e4 | 1571 | if (!tty_hung_up_p(filp)) |
265d6f00 JS |
1572 | port->count++; |
1573 | port->blocked_open--; | |
1da177e4 LT |
1574 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1575 | printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n", | |
265d6f00 | 1576 | info->line, port->count); |
1da177e4 LT |
1577 | #endif |
1578 | if (retval) | |
1579 | return retval; | |
265d6f00 | 1580 | port->flags |= ASYNC_NORMAL_ACTIVE; |
1da177e4 LT |
1581 | return 0; |
1582 | } | |
1583 | ||
1584 | /* | |
1585 | * This routine is called whenever a serial port is opened. It | |
1586 | * enables interrupts for a serial port, linking in its async structure into | |
1587 | * the IRQ chain. It also performs the serial-specific | |
1588 | * initialization for the tty structure. | |
1589 | */ | |
1590 | static int | |
1591 | isdn_tty_open(struct tty_struct *tty, struct file *filp) | |
1592 | { | |
265d6f00 | 1593 | struct tty_port *port; |
1da177e4 | 1594 | modem_info *info; |
410235fd | 1595 | int retval; |
1da177e4 | 1596 | |
410235fd | 1597 | info = &dev->mdm.info[tty->index]; |
1da177e4 LT |
1598 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) |
1599 | return -ENODEV; | |
265d6f00 | 1600 | port = &info->port; |
1da177e4 | 1601 | #ifdef ISDN_DEBUG_MODEM_OPEN |
475be4d8 | 1602 | printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, |
265d6f00 | 1603 | port->count); |
1da177e4 | 1604 | #endif |
265d6f00 | 1605 | port->count++; |
1da177e4 | 1606 | tty->driver_data = info; |
265d6f00 JS |
1607 | port->tty = tty; |
1608 | tty->port = port; | |
1da177e4 LT |
1609 | /* |
1610 | * Start up serial port | |
1611 | */ | |
1612 | retval = isdn_tty_startup(info); | |
1613 | if (retval) { | |
1614 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1615 | printk(KERN_DEBUG "isdn_tty_open return after startup\n"); | |
1616 | #endif | |
1da177e4 LT |
1617 | return retval; |
1618 | } | |
1619 | retval = isdn_tty_block_til_ready(tty, filp, info); | |
1620 | if (retval) { | |
1621 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1622 | printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); | |
1623 | #endif | |
1da177e4 LT |
1624 | return retval; |
1625 | } | |
1626 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1627 | printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line); | |
1628 | #endif | |
1629 | dev->modempoll++; | |
1630 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1631 | printk(KERN_DEBUG "isdn_tty_open normal exit\n"); | |
1632 | #endif | |
1633 | return 0; | |
1634 | } | |
1635 | ||
1636 | static void | |
1637 | isdn_tty_close(struct tty_struct *tty, struct file *filp) | |
1638 | { | |
1639 | modem_info *info = (modem_info *) tty->driver_data; | |
265d6f00 | 1640 | struct tty_port *port = &info->port; |
1da177e4 LT |
1641 | ulong timeout; |
1642 | ||
1643 | if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) | |
1644 | return; | |
1645 | if (tty_hung_up_p(filp)) { | |
1646 | #ifdef ISDN_DEBUG_MODEM_OPEN | |
1647 | printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n"); | |
1648 | #endif | |
1649 | return; | |
1650 | } | |
265d6f00 | 1651 | if ((tty->count == 1) && (port->count != 1)) { |
1da177e4 LT |
1652 | /* |
1653 | * Uh, oh. tty->count is 1, which means that the tty | |
1654 | * structure will be freed. Info->count should always | |
1655 | * be one in these conditions. If it's greater than | |
1656 | * one, we've got real problems, since it means the | |
1657 | * serial port won't be shutdown. | |
1658 | */ | |
1659 | printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " | |
265d6f00 JS |
1660 | "info->count is %d\n", port->count); |
1661 | port->count = 1; | |
1da177e4 | 1662 | } |
265d6f00 | 1663 | if (--port->count < 0) { |
1da177e4 | 1664 | printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", |
265d6f00 JS |
1665 | info->line, port->count); |
1666 | port->count = 0; | |
1da177e4 | 1667 | } |
265d6f00 | 1668 | if (port->count) { |
1da177e4 LT |
1669 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1670 | printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); | |
1671 | #endif | |
1672 | return; | |
1673 | } | |
265d6f00 | 1674 | port->flags |= ASYNC_CLOSING; |
1da177e4 LT |
1675 | |
1676 | tty->closing = 1; | |
1677 | /* | |
1678 | * At this point we stop accepting input. To do this, we | |
1679 | * disable the receive line status interrupts, and tell the | |
1680 | * interrupt driver to stop checking the data ready bit in the | |
1681 | * line status register. | |
1682 | */ | |
265d6f00 | 1683 | if (port->flags & ASYNC_INITIALIZED) { |
0b058353 | 1684 | tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ |
1da177e4 LT |
1685 | /* |
1686 | * Before we drop DTR, make sure the UART transmitter | |
1687 | * has completely drained; this is especially | |
1688 | * important if there is a transmit FIFO! | |
1689 | */ | |
1690 | timeout = jiffies + HZ; | |
1691 | while (!(info->lsr & UART_LSR_TEMT)) { | |
24763c48 | 1692 | schedule_timeout_interruptible(20); |
475be4d8 | 1693 | if (time_after(jiffies, timeout)) |
1da177e4 LT |
1694 | break; |
1695 | } | |
1696 | } | |
1697 | dev->modempoll--; | |
1698 | isdn_tty_shutdown(info); | |
978e595f | 1699 | isdn_tty_flush_buffer(tty); |
1da177e4 | 1700 | tty_ldisc_flush(tty); |
265d6f00 | 1701 | port->tty = NULL; |
1da177e4 | 1702 | info->ncarrier = 0; |
4330d663 JS |
1703 | |
1704 | tty_port_close_end(port, tty); | |
1da177e4 LT |
1705 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1706 | printk(KERN_DEBUG "isdn_tty_close normal exit\n"); | |
1707 | #endif | |
1708 | } | |
1709 | ||
1710 | /* | |
1711 | * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled. | |
1712 | */ | |
1713 | static void | |
1714 | isdn_tty_hangup(struct tty_struct *tty) | |
1715 | { | |
1716 | modem_info *info = (modem_info *) tty->driver_data; | |
265d6f00 | 1717 | struct tty_port *port = &info->port; |
1da177e4 LT |
1718 | |
1719 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) | |
1720 | return; | |
1721 | isdn_tty_shutdown(info); | |
265d6f00 JS |
1722 | port->count = 0; |
1723 | port->flags &= ~ASYNC_NORMAL_ACTIVE; | |
1724 | port->tty = NULL; | |
1725 | wake_up_interruptible(&port->open_wait); | |
1da177e4 LT |
1726 | } |
1727 | ||
1728 | /* This routine initializes all emulator-data. | |
1729 | */ | |
1730 | static void | |
475be4d8 | 1731 | isdn_tty_reset_profile(atemu *m) |
1da177e4 LT |
1732 | { |
1733 | m->profile[0] = 0; | |
1734 | m->profile[1] = 0; | |
1735 | m->profile[2] = 43; | |
1736 | m->profile[3] = 13; | |
1737 | m->profile[4] = 10; | |
1738 | m->profile[5] = 8; | |
1739 | m->profile[6] = 3; | |
1740 | m->profile[7] = 60; | |
1741 | m->profile[8] = 2; | |
1742 | m->profile[9] = 6; | |
1743 | m->profile[10] = 7; | |
1744 | m->profile[11] = 70; | |
1745 | m->profile[12] = 0x45; | |
1746 | m->profile[13] = 4; | |
1747 | m->profile[14] = ISDN_PROTO_L2_X75I; | |
1748 | m->profile[15] = ISDN_PROTO_L3_TRANS; | |
1749 | m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16; | |
1750 | m->profile[17] = ISDN_MODEM_WINSIZE; | |
1751 | m->profile[18] = 4; | |
1752 | m->profile[19] = 0; | |
1753 | m->profile[20] = 0; | |
1754 | m->profile[23] = 0; | |
1755 | m->pmsn[0] = '\0'; | |
1756 | m->plmsn[0] = '\0'; | |
1757 | } | |
1758 | ||
1759 | #ifdef CONFIG_ISDN_AUDIO | |
1760 | static void | |
475be4d8 | 1761 | isdn_tty_modem_reset_vpar(atemu *m) |
1da177e4 LT |
1762 | { |
1763 | m->vpar[0] = 2; /* Voice-device (2 = phone line) */ | |
1764 | m->vpar[1] = 0; /* Silence detection level (0 = none ) */ | |
1765 | m->vpar[2] = 70; /* Silence interval (7 sec. ) */ | |
1766 | m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */ | |
1767 | m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */ | |
1768 | m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */ | |
1769 | } | |
1770 | #endif | |
1771 | ||
1772 | #ifdef CONFIG_ISDN_TTY_FAX | |
1773 | static void | |
475be4d8 | 1774 | isdn_tty_modem_reset_faxpar(modem_info *info) |
1da177e4 LT |
1775 | { |
1776 | T30_s *f = info->fax; | |
1777 | ||
1778 | f->code = 0; | |
1779 | f->phase = ISDN_FAX_PHASE_IDLE; | |
1780 | f->direction = 0; | |
1781 | f->resolution = 1; /* fine */ | |
1782 | f->rate = 5; /* 14400 bit/s */ | |
1783 | f->width = 0; | |
1784 | f->length = 0; | |
1785 | f->compression = 0; | |
1786 | f->ecm = 0; | |
1787 | f->binary = 0; | |
1788 | f->scantime = 0; | |
1789 | memset(&f->id[0], 32, FAXIDLEN - 1); | |
1790 | f->id[FAXIDLEN - 1] = 0; | |
1791 | f->badlin = 0; | |
1792 | f->badmul = 0; | |
1793 | f->bor = 0; | |
1794 | f->nbc = 0; | |
1795 | f->cq = 0; | |
1796 | f->cr = 0; | |
1797 | f->ctcrty = 0; | |
1798 | f->minsp = 0; | |
1799 | f->phcto = 30; | |
1800 | f->rel = 0; | |
1801 | memset(&f->pollid[0], 32, FAXIDLEN - 1); | |
1802 | f->pollid[FAXIDLEN - 1] = 0; | |
1803 | } | |
1804 | #endif | |
1805 | ||
1806 | static void | |
475be4d8 | 1807 | isdn_tty_modem_reset_regs(modem_info *info, int force) |
1da177e4 LT |
1808 | { |
1809 | atemu *m = &info->emu; | |
1810 | if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) { | |
1811 | memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG); | |
1812 | memcpy(m->msn, m->pmsn, ISDN_MSNLEN); | |
1813 | memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN); | |
1814 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; | |
1815 | } | |
1816 | #ifdef CONFIG_ISDN_AUDIO | |
1817 | isdn_tty_modem_reset_vpar(m); | |
1818 | #endif | |
1819 | #ifdef CONFIG_ISDN_TTY_FAX | |
1820 | isdn_tty_modem_reset_faxpar(info); | |
1821 | #endif | |
1822 | m->mdmcmdl = 0; | |
1823 | } | |
1824 | ||
1825 | static void | |
475be4d8 | 1826 | modem_write_profile(atemu *m) |
1da177e4 LT |
1827 | { |
1828 | memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG); | |
1829 | memcpy(m->pmsn, m->msn, ISDN_MSNLEN); | |
1830 | memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN); | |
1831 | if (dev->profd) | |
1832 | send_sig(SIGIO, dev->profd, 1); | |
1833 | } | |
1834 | ||
b68e31d0 | 1835 | static const struct tty_operations modem_ops = { |
475be4d8 | 1836 | .open = isdn_tty_open, |
1da177e4 LT |
1837 | .close = isdn_tty_close, |
1838 | .write = isdn_tty_write, | |
1839 | .flush_chars = isdn_tty_flush_chars, | |
1840 | .write_room = isdn_tty_write_room, | |
1841 | .chars_in_buffer = isdn_tty_chars_in_buffer, | |
1842 | .flush_buffer = isdn_tty_flush_buffer, | |
1843 | .ioctl = isdn_tty_ioctl, | |
1844 | .throttle = isdn_tty_throttle, | |
1845 | .unthrottle = isdn_tty_unthrottle, | |
1846 | .set_termios = isdn_tty_set_termios, | |
1847 | .hangup = isdn_tty_hangup, | |
1848 | .tiocmget = isdn_tty_tiocmget, | |
1849 | .tiocmset = isdn_tty_tiocmset, | |
1850 | }; | |
1851 | ||
042b9e7c JS |
1852 | static int isdn_tty_carrier_raised(struct tty_port *port) |
1853 | { | |
1854 | modem_info *info = container_of(port, modem_info, port); | |
1855 | return info->msr & UART_MSR_DCD; | |
1856 | } | |
1857 | ||
1858 | static const struct tty_port_operations isdn_tty_port_ops = { | |
1859 | .carrier_raised = isdn_tty_carrier_raised, | |
1860 | }; | |
1861 | ||
1da177e4 LT |
1862 | int |
1863 | isdn_tty_modem_init(void) | |
1864 | { | |
1865 | isdn_modem_t *m; | |
1866 | int i, retval; | |
1867 | modem_info *info; | |
1868 | ||
1869 | m = &dev->mdm; | |
1870 | m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS); | |
1871 | if (!m->tty_modem) | |
1872 | return -ENOMEM; | |
1873 | m->tty_modem->name = "ttyI"; | |
1da177e4 LT |
1874 | m->tty_modem->major = ISDN_TTY_MAJOR; |
1875 | m->tty_modem->minor_start = 0; | |
1876 | m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL; | |
1877 | m->tty_modem->subtype = SERIAL_TYPE_NORMAL; | |
1878 | m->tty_modem->init_termios = tty_std_termios; | |
1879 | m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | |
331b8319 | 1880 | m->tty_modem->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1da177e4 LT |
1881 | m->tty_modem->driver_name = "isdn_tty"; |
1882 | tty_set_operations(m->tty_modem, &modem_ops); | |
1883 | retval = tty_register_driver(m->tty_modem); | |
1884 | if (retval) { | |
1885 | printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n"); | |
1886 | goto err; | |
1887 | } | |
1888 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
1889 | info = &m->info[i]; | |
1890 | #ifdef CONFIG_ISDN_TTY_FAX | |
1891 | if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) { | |
1892 | printk(KERN_ERR "Could not allocate fax t30-buffer\n"); | |
1893 | retval = -ENOMEM; | |
1894 | goto err_unregister; | |
1895 | } | |
1da177e4 | 1896 | #endif |
48decc1c | 1897 | tty_port_init(&info->port); |
042b9e7c | 1898 | info->port.ops = &isdn_tty_port_ops; |
1da177e4 | 1899 | spin_lock_init(&info->readlock); |
1da177e4 LT |
1900 | sprintf(info->last_cause, "0000"); |
1901 | sprintf(info->last_num, "none"); | |
1902 | info->last_dir = 0; | |
1903 | info->last_lhup = 1; | |
1904 | info->last_l2 = -1; | |
1905 | info->last_si = 0; | |
1906 | isdn_tty_reset_profile(&info->emu); | |
1907 | isdn_tty_modem_reset_regs(info, 1); | |
1908 | info->magic = ISDN_ASYNC_MAGIC; | |
1909 | info->line = i; | |
1da177e4 | 1910 | info->x_char = 0; |
1da177e4 LT |
1911 | info->isdn_driver = -1; |
1912 | info->isdn_channel = -1; | |
1913 | info->drv_index = -1; | |
1914 | info->xmit_size = ISDN_SERIAL_XMIT_SIZE; | |
1915 | init_timer(&info->nc_timer); | |
1916 | info->nc_timer.function = isdn_tty_modem_do_ncarrier; | |
1917 | info->nc_timer.data = (unsigned long) info; | |
1918 | skb_queue_head_init(&info->xmit_queue); | |
1919 | #ifdef CONFIG_ISDN_AUDIO | |
1920 | skb_queue_head_init(&info->dtmf_queue); | |
1921 | #endif | |
82e46b31 JS |
1922 | info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, |
1923 | GFP_KERNEL); | |
1924 | if (!info->port.xmit_buf) { | |
1da177e4 LT |
1925 | printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); |
1926 | retval = -ENOMEM; | |
1927 | goto err_unregister; | |
1928 | } | |
1929 | /* Make room for T.70 header */ | |
82e46b31 | 1930 | info->port.xmit_buf += 4; |
1da177e4 LT |
1931 | } |
1932 | return 0; | |
1933 | err_unregister: | |
1934 | for (i--; i >= 0; i--) { | |
1935 | info = &m->info[i]; | |
1936 | #ifdef CONFIG_ISDN_TTY_FAX | |
1937 | kfree(info->fax); | |
1938 | #endif | |
82e46b31 | 1939 | kfree(info->port.xmit_buf - 4); |
1da177e4 LT |
1940 | } |
1941 | tty_unregister_driver(m->tty_modem); | |
475be4d8 | 1942 | err: |
1da177e4 LT |
1943 | put_tty_driver(m->tty_modem); |
1944 | m->tty_modem = NULL; | |
1945 | return retval; | |
1946 | } | |
1947 | ||
1948 | void | |
1949 | isdn_tty_exit(void) | |
1950 | { | |
1951 | modem_info *info; | |
1952 | int i; | |
1953 | ||
1954 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
1955 | info = &dev->mdm.info[i]; | |
1956 | isdn_tty_cleanup_xmit(info); | |
1957 | #ifdef CONFIG_ISDN_TTY_FAX | |
1958 | kfree(info->fax); | |
1959 | #endif | |
82e46b31 | 1960 | kfree(info->port.xmit_buf - 4); |
1da177e4 LT |
1961 | } |
1962 | tty_unregister_driver(dev->mdm.tty_modem); | |
1963 | put_tty_driver(dev->mdm.tty_modem); | |
1964 | dev->mdm.tty_modem = NULL; | |
1965 | } | |
1966 | ||
1967 | ||
1968 | /* | |
1969 | * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx) | |
1970 | * match the MSN against the MSNs (glob patterns) defined for tty_emulator, | |
1971 | * and return 0 for match, 1 for no match, 2 if MSN could match if longer. | |
1972 | */ | |
1973 | ||
1974 | static int | |
1975 | isdn_tty_match_icall(char *cid, atemu *emu, int di) | |
1976 | { | |
1977 | #ifdef ISDN_DEBUG_MODEM_ICALL | |
1978 | printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n", | |
1979 | emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di), | |
1980 | emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]); | |
1981 | #endif | |
1982 | if (strlen(emu->lmsn)) { | |
1983 | char *p = emu->lmsn; | |
1984 | char *q; | |
1985 | int tmp; | |
1986 | int ret = 0; | |
1987 | ||
1988 | while (1) { | |
1989 | if ((q = strchr(p, ';'))) | |
1990 | *q = '\0'; | |
1991 | if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret) | |
1992 | ret = tmp; | |
1993 | #ifdef ISDN_DEBUG_MODEM_ICALL | |
1994 | printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n", | |
1995 | p, isdn_map_eaz2msn(emu->msn, di), tmp); | |
1996 | #endif | |
1997 | if (q) { | |
1998 | *q = ';'; | |
1999 | p = q; | |
2000 | p++; | |
2001 | } | |
2002 | if (!tmp) | |
2003 | return 0; | |
2004 | if (!q) | |
2005 | break; | |
2006 | } | |
2007 | return ret; | |
2008 | } else { | |
2009 | int tmp; | |
2010 | tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di)); | |
2011 | #ifdef ISDN_DEBUG_MODEM_ICALL | |
475be4d8 JP |
2012 | printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n", |
2013 | isdn_map_eaz2msn(emu->msn, di), tmp); | |
1da177e4 LT |
2014 | #endif |
2015 | return tmp; | |
2016 | } | |
2017 | } | |
2018 | ||
2019 | /* | |
2020 | * An incoming call-request has arrived. | |
2021 | * Search the tty-devices for an appropriate device and bind | |
2022 | * it to the ISDN-Channel. | |
2023 | * Return: | |
2024 | * | |
2025 | * 0 = No matching device found. | |
2026 | * 1 = A matching device found. | |
2027 | * 3 = No match found, but eventually would match, if | |
2028 | * CID is longer. | |
2029 | */ | |
2030 | int | |
2031 | isdn_tty_find_icall(int di, int ch, setup_parm *setup) | |
2032 | { | |
2033 | char *eaz; | |
2034 | int i; | |
2035 | int wret; | |
2036 | int idx; | |
2037 | int si1; | |
2038 | int si2; | |
2039 | char *nr; | |
2040 | ulong flags; | |
2041 | ||
2042 | if (!setup->phone[0]) { | |
2043 | nr = "0"; | |
2044 | printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n"); | |
2045 | } else | |
2046 | nr = setup->phone; | |
2047 | si1 = (int) setup->si1; | |
2048 | si2 = (int) setup->si2; | |
2049 | if (!setup->eazmsn[0]) { | |
2050 | printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n"); | |
2051 | eaz = "0"; | |
2052 | } else | |
2053 | eaz = setup->eazmsn; | |
2054 | #ifdef ISDN_DEBUG_MODEM_ICALL | |
2055 | printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2); | |
2056 | #endif | |
2057 | wret = 0; | |
2058 | spin_lock_irqsave(&dev->lock, flags); | |
2059 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
2060 | modem_info *info = &dev->mdm.info[i]; | |
2061 | ||
1b05f030 | 2062 | if (info->port.count == 0) |
475be4d8 | 2063 | continue; |
1da177e4 LT |
2064 | if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ |
2065 | (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ | |
2066 | idx = isdn_dc2minor(di, ch); | |
2067 | #ifdef ISDN_DEBUG_MODEM_ICALL | |
2068 | printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); | |
2069 | printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, | |
48decc1c JS |
2070 | info->port.flags, info->isdn_driver, |
2071 | info->isdn_channel, dev->usage[idx]); | |
1da177e4 LT |
2072 | #endif |
2073 | if ( | |
2074 | #ifndef FIX_FILE_TRANSFER | |
48decc1c | 2075 | (info->port.flags & ASYNC_NORMAL_ACTIVE) && |
1da177e4 LT |
2076 | #endif |
2077 | (info->isdn_driver == -1) && | |
2078 | (info->isdn_channel == -1) && | |
2079 | (USG_NONE(dev->usage[idx]))) { | |
2080 | int matchret; | |
2081 | ||
2082 | if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret) | |
2083 | wret = matchret; | |
2084 | if (!matchret) { /* EAZ is matching */ | |
2085 | info->isdn_driver = di; | |
2086 | info->isdn_channel = ch; | |
2087 | info->drv_index = idx; | |
2088 | dev->m_idx[idx] = info->line; | |
2089 | dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE; | |
475be4d8 | 2090 | dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]); |
1da177e4 LT |
2091 | strcpy(dev->num[idx], nr); |
2092 | strcpy(info->emu.cpn, eaz); | |
2093 | info->emu.mdmreg[REG_SI1I] = si2bit[si1]; | |
2094 | info->emu.mdmreg[REG_PLAN] = setup->plan; | |
2095 | info->emu.mdmreg[REG_SCREEN] = setup->screen; | |
2096 | isdn_info_update(); | |
2097 | spin_unlock_irqrestore(&dev->lock, flags); | |
2098 | printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr, | |
2099 | info->line); | |
2100 | info->msr |= UART_MSR_RI; | |
2101 | isdn_tty_modem_result(RESULT_RING, info); | |
2102 | isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1); | |
2103 | return 1; | |
2104 | } | |
2105 | } | |
2106 | } | |
2107 | } | |
2108 | spin_unlock_irqrestore(&dev->lock, flags); | |
2109 | printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz, | |
475be4d8 JP |
2110 | ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2)) ? "rejected" : "ignored"); |
2111 | return (wret == 2) ? 3 : 0; | |
1da177e4 LT |
2112 | } |
2113 | ||
48decc1c | 2114 | #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE) |
1da177e4 LT |
2115 | |
2116 | int | |
2117 | isdn_tty_stat_callback(int i, isdn_ctrl *c) | |
2118 | { | |
2119 | int mi; | |
2120 | modem_info *info; | |
2121 | char *e; | |
2122 | ||
2123 | if (i < 0) | |
2124 | return 0; | |
2125 | if ((mi = dev->m_idx[i]) >= 0) { | |
2126 | info = &dev->mdm.info[mi]; | |
2127 | switch (c->command) { | |
475be4d8 JP |
2128 | case ISDN_STAT_CINF: |
2129 | printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num); | |
2130 | info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10); | |
2131 | if (e == (char *)c->parm.num) | |
2132 | info->emu.charge = 0; | |
2133 | ||
2134 | break; | |
2135 | case ISDN_STAT_BSENT: | |
1da177e4 | 2136 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 | 2137 | printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line); |
1da177e4 | 2138 | #endif |
475be4d8 JP |
2139 | if ((info->isdn_driver == c->driver) && |
2140 | (info->isdn_channel == c->arg)) { | |
2141 | info->msr |= UART_MSR_CTS; | |
2142 | if (info->send_outstanding) | |
2143 | if (!(--info->send_outstanding)) | |
2144 | info->lsr |= UART_LSR_TEMT; | |
2145 | isdn_tty_tint(info); | |
1da177e4 | 2146 | return 1; |
475be4d8 JP |
2147 | } |
2148 | break; | |
2149 | case ISDN_STAT_CAUSE: | |
1da177e4 | 2150 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 JP |
2151 | printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line); |
2152 | #endif | |
2153 | /* Signal cause to tty-device */ | |
2154 | strncpy(info->last_cause, c->parm.num, 5); | |
2155 | return 1; | |
2156 | case ISDN_STAT_DISPLAY: | |
1da177e4 | 2157 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 | 2158 | printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line); |
1da177e4 | 2159 | #endif |
475be4d8 JP |
2160 | /* Signal display to tty-device */ |
2161 | if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) && | |
2162 | !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) { | |
2163 | isdn_tty_at_cout("\r\n", info); | |
2164 | isdn_tty_at_cout("DISPLAY: ", info); | |
2165 | isdn_tty_at_cout(c->parm.display, info); | |
2166 | isdn_tty_at_cout("\r\n", info); | |
2167 | } | |
2168 | return 1; | |
2169 | case ISDN_STAT_DCONN: | |
2170 | #ifdef ISDN_TTY_STAT_DEBUG | |
2171 | printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line); | |
2172 | #endif | |
2173 | if (TTY_IS_ACTIVE(info)) { | |
2174 | if (info->dialing == 1) { | |
2175 | info->dialing = 2; | |
2176 | return 1; | |
1da177e4 | 2177 | } |
475be4d8 JP |
2178 | } |
2179 | break; | |
2180 | case ISDN_STAT_DHUP: | |
1da177e4 | 2181 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 | 2182 | printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line); |
1da177e4 | 2183 | #endif |
475be4d8 JP |
2184 | if (TTY_IS_ACTIVE(info)) { |
2185 | if (info->dialing == 1) | |
2186 | isdn_tty_modem_result(RESULT_BUSY, info); | |
2187 | if (info->dialing > 1) | |
2188 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
2189 | info->dialing = 0; | |
1da177e4 | 2190 | #ifdef ISDN_DEBUG_MODEM_HUP |
475be4d8 | 2191 | printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n"); |
1da177e4 | 2192 | #endif |
475be4d8 JP |
2193 | isdn_tty_modem_hup(info, 0); |
2194 | return 1; | |
2195 | } | |
2196 | break; | |
2197 | case ISDN_STAT_BCONN: | |
1da177e4 | 2198 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 JP |
2199 | printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line); |
2200 | #endif | |
2201 | /* Wake up any processes waiting | |
2202 | * for incoming call of this device when | |
2203 | * DCD follow the state of incoming carrier | |
2204 | */ | |
1b05f030 | 2205 | if (info->port.blocked_open && |
475be4d8 | 2206 | (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { |
c6e92b63 | 2207 | wake_up_interruptible(&info->port.open_wait); |
475be4d8 | 2208 | } |
1da177e4 | 2209 | |
475be4d8 JP |
2210 | /* Schedule CONNECT-Message to any tty |
2211 | * waiting for it and | |
2212 | * set DCD-bit of its modem-status. | |
2213 | */ | |
2214 | if (TTY_IS_ACTIVE(info) || | |
1b05f030 JS |
2215 | (info->port.blocked_open && |
2216 | (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { | |
475be4d8 JP |
2217 | info->msr |= UART_MSR_DCD; |
2218 | info->emu.charge = 0; | |
2219 | if (info->dialing & 0xf) | |
2220 | info->last_dir = 1; | |
2221 | else | |
2222 | info->last_dir = 0; | |
2223 | info->dialing = 0; | |
2224 | info->rcvsched = 1; | |
2225 | if (USG_MODEM(dev->usage[i])) { | |
2226 | if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) { | |
2227 | strcpy(info->emu.connmsg, c->parm.num); | |
2228 | isdn_tty_modem_result(RESULT_CONNECT, info); | |
2229 | } else | |
2230 | isdn_tty_modem_result(RESULT_CONNECT64000, info); | |
1da177e4 | 2231 | } |
475be4d8 JP |
2232 | if (USG_VOICE(dev->usage[i])) |
2233 | isdn_tty_modem_result(RESULT_VCON, info); | |
2234 | return 1; | |
2235 | } | |
2236 | break; | |
2237 | case ISDN_STAT_BHUP: | |
1da177e4 | 2238 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 | 2239 | printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line); |
1da177e4 | 2240 | #endif |
475be4d8 | 2241 | if (TTY_IS_ACTIVE(info)) { |
1da177e4 | 2242 | #ifdef ISDN_DEBUG_MODEM_HUP |
475be4d8 | 2243 | printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n"); |
1da177e4 | 2244 | #endif |
475be4d8 JP |
2245 | isdn_tty_modem_hup(info, 0); |
2246 | return 1; | |
2247 | } | |
2248 | break; | |
2249 | case ISDN_STAT_NODCH: | |
1da177e4 | 2250 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 JP |
2251 | printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line); |
2252 | #endif | |
2253 | if (TTY_IS_ACTIVE(info)) { | |
2254 | if (info->dialing) { | |
2255 | info->dialing = 0; | |
2256 | info->last_l2 = -1; | |
2257 | info->last_si = 0; | |
2258 | sprintf(info->last_cause, "0000"); | |
2259 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); | |
1da177e4 | 2260 | } |
475be4d8 JP |
2261 | isdn_tty_modem_hup(info, 0); |
2262 | return 1; | |
2263 | } | |
2264 | break; | |
2265 | case ISDN_STAT_UNLOAD: | |
1da177e4 | 2266 | #ifdef ISDN_TTY_STAT_DEBUG |
475be4d8 | 2267 | printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line); |
1da177e4 | 2268 | #endif |
475be4d8 JP |
2269 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
2270 | info = &dev->mdm.info[i]; | |
2271 | if (info->isdn_driver == c->driver) { | |
2272 | if (info->online) | |
2273 | isdn_tty_modem_hup(info, 1); | |
1da177e4 | 2274 | } |
475be4d8 JP |
2275 | } |
2276 | return 1; | |
1da177e4 | 2277 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 JP |
2278 | case ISDN_STAT_FAXIND: |
2279 | if (TTY_IS_ACTIVE(info)) { | |
2280 | isdn_tty_fax_command(info, c); | |
2281 | } | |
2282 | break; | |
1da177e4 LT |
2283 | #endif |
2284 | #ifdef CONFIG_ISDN_AUDIO | |
475be4d8 JP |
2285 | case ISDN_STAT_AUDIO: |
2286 | if (TTY_IS_ACTIVE(info)) { | |
2287 | switch (c->parm.num[0]) { | |
2288 | case ISDN_AUDIO_DTMF: | |
2289 | if (info->vonline) { | |
2290 | isdn_audio_put_dle_code(info, | |
1da177e4 | 2291 | c->parm.num[1]); |
1da177e4 | 2292 | } |
475be4d8 | 2293 | break; |
1da177e4 | 2294 | } |
475be4d8 JP |
2295 | } |
2296 | break; | |
1da177e4 LT |
2297 | #endif |
2298 | } | |
2299 | } | |
2300 | return 0; | |
2301 | } | |
2302 | ||
2303 | /********************************************************************* | |
2304 | Modem-Emulator-Routines | |
475be4d8 | 2305 | *********************************************************************/ |
1da177e4 | 2306 | |
475be4d8 | 2307 | #define cmdchar(c) ((c >= ' ') && (c <= 0x7f)) |
1da177e4 LT |
2308 | |
2309 | /* | |
2310 | * Put a message from the AT-emulator into receive-buffer of tty, | |
2311 | * convert CR, LF, and BS to values in modem-registers 3, 4 and 5. | |
2312 | */ | |
2313 | void | |
475be4d8 | 2314 | isdn_tty_at_cout(char *msg, modem_info *info) |
1da177e4 LT |
2315 | { |
2316 | struct tty_struct *tty; | |
2317 | atemu *m = &info->emu; | |
2318 | char *p; | |
2319 | char c; | |
2320 | u_long flags; | |
2321 | struct sk_buff *skb = NULL; | |
2322 | char *sp = NULL; | |
1f4d4a80 | 2323 | int l; |
1da177e4 LT |
2324 | |
2325 | if (!msg) { | |
2326 | printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n"); | |
2327 | return; | |
2328 | } | |
1f4d4a80 AB |
2329 | |
2330 | l = strlen(msg); | |
2331 | ||
1da177e4 | 2332 | spin_lock_irqsave(&info->readlock, flags); |
ba43294d | 2333 | tty = info->port.tty; |
48decc1c | 2334 | if ((info->port.flags & ASYNC_CLOSING) || (!tty)) { |
1da177e4 LT |
2335 | spin_unlock_irqrestore(&info->readlock, flags); |
2336 | return; | |
2337 | } | |
2338 | ||
33f0f88f AC |
2339 | /* use queue instead of direct, if online and */ |
2340 | /* data is in queue or buffer is full */ | |
61b9a26a | 2341 | if (info->online && ((tty_buffer_request_room(tty, l) < l) || |
475be4d8 | 2342 | !skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) { |
33f0f88f | 2343 | skb = alloc_skb(l, GFP_ATOMIC); |
1da177e4 LT |
2344 | if (!skb) { |
2345 | spin_unlock_irqrestore(&info->readlock, flags); | |
2346 | return; | |
2347 | } | |
33f0f88f | 2348 | sp = skb_put(skb, l); |
1da177e4 LT |
2349 | #ifdef CONFIG_ISDN_AUDIO |
2350 | ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; | |
2351 | ISDN_AUDIO_SKB_LOCK(skb) = 0; | |
2352 | #endif | |
2353 | } | |
2354 | ||
2355 | for (p = msg; *p; p++) { | |
2356 | switch (*p) { | |
475be4d8 JP |
2357 | case '\r': |
2358 | c = m->mdmreg[REG_CR]; | |
2359 | break; | |
2360 | case '\n': | |
2361 | c = m->mdmreg[REG_LF]; | |
2362 | break; | |
2363 | case '\b': | |
2364 | c = m->mdmreg[REG_BS]; | |
2365 | break; | |
2366 | default: | |
2367 | c = *p; | |
1da177e4 LT |
2368 | } |
2369 | if (skb) { | |
2370 | *sp++ = c; | |
2371 | } else { | |
475be4d8 | 2372 | if (tty_insert_flip_char(tty, c, TTY_NORMAL) == 0) |
1da177e4 | 2373 | break; |
1da177e4 LT |
2374 | } |
2375 | } | |
2376 | if (skb) { | |
2377 | __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb); | |
2378 | dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len; | |
2379 | spin_unlock_irqrestore(&info->readlock, flags); | |
2380 | /* Schedule dequeuing */ | |
33f0f88f | 2381 | if (dev->modempoll && info->rcvsched) |
1da177e4 LT |
2382 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); |
2383 | ||
2384 | } else { | |
2385 | spin_unlock_irqrestore(&info->readlock, flags); | |
33f0f88f | 2386 | tty_flip_buffer_push(tty); |
1da177e4 LT |
2387 | } |
2388 | } | |
2389 | ||
2390 | /* | |
2391 | * Perform ATH Hangup | |
2392 | */ | |
2393 | static void | |
475be4d8 | 2394 | isdn_tty_on_hook(modem_info *info) |
1da177e4 LT |
2395 | { |
2396 | if (info->isdn_channel >= 0) { | |
2397 | #ifdef ISDN_DEBUG_MODEM_HUP | |
2398 | printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n"); | |
2399 | #endif | |
2400 | isdn_tty_modem_hup(info, 1); | |
2401 | } | |
2402 | } | |
2403 | ||
2404 | static void | |
2405 | isdn_tty_off_hook(void) | |
2406 | { | |
2407 | printk(KERN_DEBUG "isdn_tty_off_hook\n"); | |
2408 | } | |
2409 | ||
475be4d8 JP |
2410 | #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */ |
2411 | #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */ | |
1da177e4 LT |
2412 | |
2413 | /* | |
2414 | * Check Buffer for Modem-escape-sequence, activate timer-callback to | |
2415 | * isdn_tty_modem_escape() if sequence found. | |
2416 | * | |
2417 | * Parameters: | |
2418 | * p pointer to databuffer | |
2419 | * plus escape-character | |
2420 | * count length of buffer | |
2421 | * pluscount count of valid escape-characters so far | |
2422 | * lastplus timestamp of last character | |
2423 | */ | |
2424 | static void | |
475be4d8 | 2425 | isdn_tty_check_esc(const u_char *p, u_char plus, int count, int *pluscount, |
1da177e4 LT |
2426 | u_long *lastplus) |
2427 | { | |
2428 | if (plus > 127) | |
2429 | return; | |
2430 | if (count > 3) { | |
2431 | p += count - 3; | |
2432 | count = 3; | |
2433 | *pluscount = 0; | |
2434 | } | |
2435 | while (count > 0) { | |
2436 | if (*(p++) == plus) { | |
2437 | if ((*pluscount)++) { | |
2438 | /* Time since last '+' > 0.5 sec. ? */ | |
2439 | if (time_after(jiffies, *lastplus + PLUSWAIT1)) | |
2440 | *pluscount = 1; | |
2441 | } else { | |
2442 | /* Time since last non-'+' < 1.5 sec. ? */ | |
2443 | if (time_before(jiffies, *lastplus + PLUSWAIT2)) | |
2444 | *pluscount = 0; | |
2445 | } | |
2446 | if ((*pluscount == 3) && (count == 1)) | |
2447 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1); | |
2448 | if (*pluscount > 3) | |
2449 | *pluscount = 1; | |
2450 | } else | |
2451 | *pluscount = 0; | |
2452 | *lastplus = jiffies; | |
2453 | count--; | |
2454 | } | |
2455 | } | |
2456 | ||
2457 | /* | |
2458 | * Return result of AT-emulator to tty-receive-buffer, depending on | |
2459 | * modem-register 12, bit 0 and 1. | |
2460 | * For CONNECT-messages also switch to online-mode. | |
2461 | * For RING-message handle auto-ATA if register 0 != 0 | |
2462 | */ | |
2463 | ||
2464 | static void | |
475be4d8 | 2465 | isdn_tty_modem_result(int code, modem_info *info) |
1da177e4 LT |
2466 | { |
2467 | atemu *m = &info->emu; | |
2468 | static char *msg[] = | |
475be4d8 JP |
2469 | {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR", |
2470 | "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER", | |
2471 | "RINGING", "NO MSN/EAZ", "VCON", "RUNG"}; | |
2472 | char s[ISDN_MSNLEN + 10]; | |
1da177e4 LT |
2473 | |
2474 | switch (code) { | |
475be4d8 JP |
2475 | case RESULT_RING: |
2476 | m->mdmreg[REG_RINGCNT]++; | |
2477 | if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA]) | |
2478 | /* Automatically accept incoming call */ | |
2479 | isdn_tty_cmd_ATA(info); | |
2480 | break; | |
2481 | case RESULT_NO_CARRIER: | |
1da177e4 | 2482 | #ifdef ISDN_DEBUG_MODEM_HUP |
475be4d8 | 2483 | printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", |
48decc1c | 2484 | (info->port.flags & ASYNC_CLOSING), |
ba43294d | 2485 | (!info->port.tty)); |
475be4d8 JP |
2486 | #endif |
2487 | m->mdmreg[REG_RINGCNT] = 0; | |
2488 | del_timer(&info->nc_timer); | |
2489 | info->ncarrier = 0; | |
ba43294d | 2490 | if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) |
475be4d8 | 2491 | return; |
6776a2f0 | 2492 | |
1da177e4 | 2493 | #ifdef CONFIG_ISDN_AUDIO |
475be4d8 | 2494 | if (info->vonline & 1) { |
1da177e4 | 2495 | #ifdef ISDN_DEBUG_MODEM_VOICE |
475be4d8 JP |
2496 | printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n", |
2497 | info->line); | |
1da177e4 | 2498 | #endif |
475be4d8 JP |
2499 | /* voice-recording, add DLE-ETX */ |
2500 | isdn_tty_at_cout("\020\003", info); | |
2501 | } | |
2502 | if (info->vonline & 2) { | |
1da177e4 | 2503 | #ifdef ISDN_DEBUG_MODEM_VOICE |
475be4d8 JP |
2504 | printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n", |
2505 | info->line); | |
1da177e4 | 2506 | #endif |
475be4d8 JP |
2507 | /* voice-playing, add DLE-DC4 */ |
2508 | isdn_tty_at_cout("\020\024", info); | |
2509 | } | |
1da177e4 | 2510 | #endif |
475be4d8 JP |
2511 | break; |
2512 | case RESULT_CONNECT: | |
2513 | case RESULT_CONNECT64000: | |
2514 | sprintf(info->last_cause, "0000"); | |
2515 | if (!info->online) | |
2516 | info->online = 2; | |
2517 | break; | |
2518 | case RESULT_VCON: | |
1da177e4 | 2519 | #ifdef ISDN_DEBUG_MODEM_VOICE |
475be4d8 JP |
2520 | printk(KERN_DEBUG "res3: send VCON on ttyI%d\n", |
2521 | info->line); | |
1da177e4 | 2522 | #endif |
475be4d8 JP |
2523 | sprintf(info->last_cause, "0000"); |
2524 | if (!info->online) | |
2525 | info->online = 1; | |
2526 | break; | |
2527 | } /* switch (code) */ | |
1da177e4 LT |
2528 | |
2529 | if (m->mdmreg[REG_RESP] & BIT_RESP) { | |
2530 | /* Show results */ | |
2531 | if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) { | |
2532 | /* Show numeric results only */ | |
2533 | sprintf(s, "\r\n%d\r\n", code); | |
2534 | isdn_tty_at_cout(s, info); | |
2535 | } else { | |
2536 | if (code == RESULT_RING) { | |
475be4d8 JP |
2537 | /* return if "show RUNG" and ringcounter>1 */ |
2538 | if ((m->mdmreg[REG_RUNG] & BIT_RUNG) && | |
1da177e4 | 2539 | (m->mdmreg[REG_RINGCNT] > 1)) |
475be4d8 JP |
2540 | return; |
2541 | /* print CID, _before_ _every_ ring */ | |
2542 | if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) { | |
2543 | isdn_tty_at_cout("\r\nCALLER NUMBER: ", info); | |
2544 | isdn_tty_at_cout(dev->num[info->drv_index], info); | |
2545 | if (m->mdmreg[REG_CDN] & BIT_CDN) { | |
2546 | isdn_tty_at_cout("\r\nCALLED NUMBER: ", info); | |
2547 | isdn_tty_at_cout(info->emu.cpn, info); | |
2548 | } | |
2549 | } | |
1da177e4 LT |
2550 | } |
2551 | isdn_tty_at_cout("\r\n", info); | |
2552 | isdn_tty_at_cout(msg[code], info); | |
2553 | switch (code) { | |
475be4d8 JP |
2554 | case RESULT_CONNECT: |
2555 | switch (m->mdmreg[REG_L2PROT]) { | |
2556 | case ISDN_PROTO_L2_MODEM: | |
2557 | isdn_tty_at_cout(" ", info); | |
2558 | isdn_tty_at_cout(m->connmsg, info); | |
1da177e4 | 2559 | break; |
475be4d8 JP |
2560 | } |
2561 | break; | |
2562 | case RESULT_RING: | |
2563 | /* Append CPN, if enabled */ | |
2564 | if ((m->mdmreg[REG_CPN] & BIT_CPN)) { | |
2565 | sprintf(s, "/%s", m->cpn); | |
2566 | isdn_tty_at_cout(s, info); | |
2567 | } | |
2568 | /* Print CID only once, _after_ 1st RING */ | |
2569 | if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) && | |
2570 | (m->mdmreg[REG_RINGCNT] == 1)) { | |
2571 | isdn_tty_at_cout("\r\n", info); | |
2572 | isdn_tty_at_cout("CALLER NUMBER: ", info); | |
2573 | isdn_tty_at_cout(dev->num[info->drv_index], info); | |
2574 | if (m->mdmreg[REG_CDN] & BIT_CDN) { | |
2575 | isdn_tty_at_cout("\r\nCALLED NUMBER: ", info); | |
2576 | isdn_tty_at_cout(info->emu.cpn, info); | |
1da177e4 | 2577 | } |
475be4d8 JP |
2578 | } |
2579 | break; | |
2580 | case RESULT_NO_CARRIER: | |
2581 | case RESULT_NO_DIALTONE: | |
2582 | case RESULT_BUSY: | |
2583 | case RESULT_NO_ANSWER: | |
2584 | m->mdmreg[REG_RINGCNT] = 0; | |
2585 | /* Append Cause-Message if enabled */ | |
2586 | if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) { | |
2587 | sprintf(s, "/%s", info->last_cause); | |
2588 | isdn_tty_at_cout(s, info); | |
2589 | } | |
2590 | break; | |
2591 | case RESULT_CONNECT64000: | |
2592 | /* Append Protocol to CONNECT message */ | |
2593 | switch (m->mdmreg[REG_L2PROT]) { | |
2594 | case ISDN_PROTO_L2_X75I: | |
2595 | case ISDN_PROTO_L2_X75UI: | |
2596 | case ISDN_PROTO_L2_X75BUI: | |
2597 | isdn_tty_at_cout("/X.75", info); | |
1da177e4 | 2598 | break; |
475be4d8 JP |
2599 | case ISDN_PROTO_L2_HDLC: |
2600 | isdn_tty_at_cout("/HDLC", info); | |
1da177e4 | 2601 | break; |
475be4d8 JP |
2602 | case ISDN_PROTO_L2_V11096: |
2603 | isdn_tty_at_cout("/V110/9600", info); | |
2604 | break; | |
2605 | case ISDN_PROTO_L2_V11019: | |
2606 | isdn_tty_at_cout("/V110/19200", info); | |
2607 | break; | |
2608 | case ISDN_PROTO_L2_V11038: | |
2609 | isdn_tty_at_cout("/V110/38400", info); | |
1da177e4 | 2610 | break; |
475be4d8 JP |
2611 | } |
2612 | if (m->mdmreg[REG_T70] & BIT_T70) { | |
2613 | isdn_tty_at_cout("/T.70", info); | |
2614 | if (m->mdmreg[REG_T70] & BIT_T70_EXT) | |
2615 | isdn_tty_at_cout("+", info); | |
2616 | } | |
2617 | break; | |
1da177e4 LT |
2618 | } |
2619 | isdn_tty_at_cout("\r\n", info); | |
2620 | } | |
2621 | } | |
2622 | if (code == RESULT_NO_CARRIER) { | |
ba43294d | 2623 | if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) |
1da177e4 | 2624 | return; |
6776a2f0 | 2625 | |
48decc1c | 2626 | if (info->port.flags & ASYNC_CHECK_CD) |
ba43294d | 2627 | tty_hangup(info->port.tty); |
1da177e4 LT |
2628 | } |
2629 | } | |
2630 | ||
2631 | ||
2632 | /* | |
2633 | * Display a modem-register-value. | |
2634 | */ | |
2635 | static void | |
475be4d8 | 2636 | isdn_tty_show_profile(int ridx, modem_info *info) |
1da177e4 LT |
2637 | { |
2638 | char v[6]; | |
2639 | ||
2640 | sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]); | |
2641 | isdn_tty_at_cout(v, info); | |
2642 | } | |
2643 | ||
2644 | /* | |
2645 | * Get MSN-string from char-pointer, set pointer to end of number | |
2646 | */ | |
2647 | static void | |
2648 | isdn_tty_get_msnstr(char *n, char **p) | |
2649 | { | |
2650 | int limit = ISDN_MSNLEN - 1; | |
2651 | ||
2652 | while (((*p[0] >= '0' && *p[0] <= '9') || | |
2653 | /* Why a comma ??? */ | |
2654 | (*p[0] == ',') || (*p[0] == ':')) && | |
475be4d8 | 2655 | (limit--)) |
1da177e4 LT |
2656 | *n++ = *p[0]++; |
2657 | *n = '\0'; | |
2658 | } | |
2659 | ||
2660 | /* | |
2661 | * Get phone-number from modem-commandbuffer | |
2662 | */ | |
2663 | static void | |
475be4d8 | 2664 | isdn_tty_getdial(char *p, char *q, int cnt) |
1da177e4 LT |
2665 | { |
2666 | int first = 1; | |
2667 | int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid | |
475be4d8 | 2668 | buffer overflow */ |
1da177e4 | 2669 | |
475be4d8 | 2670 | while (strchr(" 0123456789,#.*WPTSR-", *p) && *p && --cnt > 0) { |
1da177e4 | 2671 | if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) || |
924ad158 | 2672 | ((*p == 'R') && first) || |
1da177e4 LT |
2673 | (*p == '*') || (*p == '#')) { |
2674 | *q++ = *p; | |
2675 | limit--; | |
2676 | } | |
475be4d8 | 2677 | if (!limit) |
1da177e4 LT |
2678 | break; |
2679 | p++; | |
2680 | first = 0; | |
2681 | } | |
2682 | *q = 0; | |
2683 | } | |
2684 | ||
2685 | #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; } | |
2686 | #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; } | |
2687 | ||
2688 | static void | |
475be4d8 | 2689 | isdn_tty_report(modem_info *info) |
1da177e4 LT |
2690 | { |
2691 | atemu *m = &info->emu; | |
2692 | char s[80]; | |
2693 | ||
2694 | isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info); | |
2695 | sprintf(s, " Remote Number: %s\r\n", info->last_num); | |
2696 | isdn_tty_at_cout(s, info); | |
2697 | sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming"); | |
2698 | isdn_tty_at_cout(s, info); | |
2699 | isdn_tty_at_cout(" Layer-2 Protocol: ", info); | |
2700 | switch (info->last_l2) { | |
475be4d8 JP |
2701 | case ISDN_PROTO_L2_X75I: |
2702 | isdn_tty_at_cout("X.75i", info); | |
2703 | break; | |
2704 | case ISDN_PROTO_L2_X75UI: | |
2705 | isdn_tty_at_cout("X.75ui", info); | |
2706 | break; | |
2707 | case ISDN_PROTO_L2_X75BUI: | |
2708 | isdn_tty_at_cout("X.75bui", info); | |
2709 | break; | |
2710 | case ISDN_PROTO_L2_HDLC: | |
2711 | isdn_tty_at_cout("HDLC", info); | |
2712 | break; | |
2713 | case ISDN_PROTO_L2_V11096: | |
2714 | isdn_tty_at_cout("V.110 9600 Baud", info); | |
2715 | break; | |
2716 | case ISDN_PROTO_L2_V11019: | |
2717 | isdn_tty_at_cout("V.110 19200 Baud", info); | |
2718 | break; | |
2719 | case ISDN_PROTO_L2_V11038: | |
2720 | isdn_tty_at_cout("V.110 38400 Baud", info); | |
2721 | break; | |
2722 | case ISDN_PROTO_L2_TRANS: | |
2723 | isdn_tty_at_cout("transparent", info); | |
2724 | break; | |
2725 | case ISDN_PROTO_L2_MODEM: | |
2726 | isdn_tty_at_cout("modem", info); | |
2727 | break; | |
2728 | case ISDN_PROTO_L2_FAX: | |
2729 | isdn_tty_at_cout("fax", info); | |
2730 | break; | |
2731 | default: | |
2732 | isdn_tty_at_cout("unknown", info); | |
2733 | break; | |
1da177e4 LT |
2734 | } |
2735 | if (m->mdmreg[REG_T70] & BIT_T70) { | |
2736 | isdn_tty_at_cout("/T.70", info); | |
2737 | if (m->mdmreg[REG_T70] & BIT_T70_EXT) | |
2738 | isdn_tty_at_cout("+", info); | |
2739 | } | |
2740 | isdn_tty_at_cout("\r\n", info); | |
2741 | isdn_tty_at_cout(" Service: ", info); | |
2742 | switch (info->last_si) { | |
475be4d8 JP |
2743 | case 1: |
2744 | isdn_tty_at_cout("audio\r\n", info); | |
2745 | break; | |
2746 | case 5: | |
2747 | isdn_tty_at_cout("btx\r\n", info); | |
2748 | break; | |
2749 | case 7: | |
2750 | isdn_tty_at_cout("data\r\n", info); | |
2751 | break; | |
2752 | default: | |
2753 | sprintf(s, "%d\r\n", info->last_si); | |
2754 | isdn_tty_at_cout(s, info); | |
2755 | break; | |
1da177e4 LT |
2756 | } |
2757 | sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote"); | |
2758 | isdn_tty_at_cout(s, info); | |
2759 | sprintf(s, " Last cause: %s\r\n", info->last_cause); | |
2760 | isdn_tty_at_cout(s, info); | |
2761 | } | |
2762 | ||
2763 | /* | |
2764 | * Parse AT&.. commands. | |
2765 | */ | |
2766 | static int | |
475be4d8 | 2767 | isdn_tty_cmd_ATand(char **p, modem_info *info) |
1da177e4 LT |
2768 | { |
2769 | atemu *m = &info->emu; | |
2770 | int i; | |
2771 | char rb[100]; | |
2772 | ||
2773 | #define MAXRB (sizeof(rb) - 1) | |
2774 | ||
2775 | switch (*p[0]) { | |
475be4d8 JP |
2776 | case 'B': |
2777 | /* &B - Set Buffersize */ | |
2778 | p[0]++; | |
2779 | i = isdn_getnum(p); | |
2780 | if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX)) | |
2781 | PARSE_ERROR1; | |
1da177e4 | 2782 | #ifdef CONFIG_ISDN_AUDIO |
475be4d8 JP |
2783 | if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF)) |
2784 | PARSE_ERROR1; | |
1da177e4 | 2785 | #endif |
475be4d8 JP |
2786 | m->mdmreg[REG_PSIZE] = i / 16; |
2787 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; | |
2788 | switch (m->mdmreg[REG_L2PROT]) { | |
2789 | case ISDN_PROTO_L2_V11096: | |
2790 | case ISDN_PROTO_L2_V11019: | |
2791 | case ISDN_PROTO_L2_V11038: | |
2792 | info->xmit_size /= 10; | |
2793 | } | |
2794 | break; | |
2795 | case 'C': | |
2796 | /* &C - DCD Status */ | |
2797 | p[0]++; | |
2798 | switch (isdn_getnum(p)) { | |
2799 | case 0: | |
2800 | m->mdmreg[REG_DCD] &= ~BIT_DCD; | |
1da177e4 | 2801 | break; |
475be4d8 JP |
2802 | case 1: |
2803 | m->mdmreg[REG_DCD] |= BIT_DCD; | |
1da177e4 | 2804 | break; |
475be4d8 JP |
2805 | default: |
2806 | PARSE_ERROR1 | |
2807 | } | |
2808 | break; | |
2809 | case 'D': | |
2810 | /* &D - Set DTR-Low-behavior */ | |
2811 | p[0]++; | |
2812 | switch (isdn_getnum(p)) { | |
2813 | case 0: | |
2814 | m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP; | |
2815 | m->mdmreg[REG_DTRR] &= ~BIT_DTRR; | |
1da177e4 | 2816 | break; |
475be4d8 JP |
2817 | case 2: |
2818 | m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP; | |
2819 | m->mdmreg[REG_DTRR] &= ~BIT_DTRR; | |
2820 | break; | |
2821 | case 3: | |
2822 | m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP; | |
2823 | m->mdmreg[REG_DTRR] |= BIT_DTRR; | |
1da177e4 | 2824 | break; |
475be4d8 JP |
2825 | default: |
2826 | PARSE_ERROR1 | |
2827 | } | |
2828 | break; | |
2829 | case 'E': | |
2830 | /* &E -Set EAZ/MSN */ | |
2831 | p[0]++; | |
2832 | isdn_tty_get_msnstr(m->msn, p); | |
2833 | break; | |
2834 | case 'F': | |
2835 | /* &F -Set Factory-Defaults */ | |
2836 | p[0]++; | |
2837 | if (info->msr & UART_MSR_DCD) | |
2838 | PARSE_ERROR1; | |
2839 | isdn_tty_reset_profile(m); | |
2840 | isdn_tty_modem_reset_regs(info, 1); | |
2841 | break; | |
1da177e4 | 2842 | #ifdef DUMMY_HAYES_AT |
475be4d8 JP |
2843 | case 'K': |
2844 | /* only for be compilant with common scripts */ | |
2845 | /* &K Flowcontrol - no function */ | |
2846 | p[0]++; | |
2847 | isdn_getnum(p); | |
2848 | break; | |
2849 | #endif | |
2850 | case 'L': | |
2851 | /* &L -Set Numbers to listen on */ | |
2852 | p[0]++; | |
2853 | i = 0; | |
2854 | while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) && | |
2855 | (i < ISDN_LMSNLEN - 1)) | |
2856 | m->lmsn[i++] = *p[0]++; | |
2857 | m->lmsn[i] = '\0'; | |
2858 | break; | |
2859 | case 'R': | |
2860 | /* &R - Set V.110 bitrate adaption */ | |
2861 | p[0]++; | |
2862 | i = isdn_getnum(p); | |
2863 | switch (i) { | |
2864 | case 0: | |
2865 | /* Switch off V.110, back to X.75 */ | |
2866 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; | |
2867 | m->mdmreg[REG_SI2] = 0; | |
2868 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; | |
1da177e4 | 2869 | break; |
475be4d8 JP |
2870 | case 9600: |
2871 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096; | |
2872 | m->mdmreg[REG_SI2] = 197; | |
2873 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; | |
1da177e4 | 2874 | break; |
475be4d8 JP |
2875 | case 19200: |
2876 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019; | |
2877 | m->mdmreg[REG_SI2] = 199; | |
2878 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; | |
1da177e4 | 2879 | break; |
475be4d8 JP |
2880 | case 38400: |
2881 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038; | |
2882 | m->mdmreg[REG_SI2] = 198; /* no existing standard for this */ | |
2883 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; | |
1da177e4 | 2884 | break; |
475be4d8 JP |
2885 | default: |
2886 | PARSE_ERROR1; | |
2887 | } | |
2888 | /* Switch off T.70 */ | |
2889 | m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT); | |
2890 | /* Set Service 7 */ | |
2891 | m->mdmreg[REG_SI1] |= 4; | |
2892 | break; | |
2893 | case 'S': | |
2894 | /* &S - Set Windowsize */ | |
2895 | p[0]++; | |
2896 | i = isdn_getnum(p); | |
2897 | if ((i > 0) && (i < 9)) | |
2898 | m->mdmreg[REG_WSIZE] = i; | |
2899 | else | |
2900 | PARSE_ERROR1; | |
2901 | break; | |
2902 | case 'V': | |
2903 | /* &V - Show registers */ | |
2904 | p[0]++; | |
2905 | isdn_tty_at_cout("\r\n", info); | |
2906 | for (i = 0; i < ISDN_MODEM_NUMREG; i++) { | |
2907 | sprintf(rb, "S%02d=%03d%s", i, | |
2908 | m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n"); | |
2909 | isdn_tty_at_cout(rb, info); | |
2910 | } | |
2911 | sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n", | |
2912 | strlen(m->msn) ? m->msn : "None"); | |
2913 | isdn_tty_at_cout(rb, info); | |
2914 | if (strlen(m->lmsn)) { | |
2915 | isdn_tty_at_cout("\r\nListen: ", info); | |
2916 | isdn_tty_at_cout(m->lmsn, info); | |
2917 | isdn_tty_at_cout("\r\n", info); | |
2918 | } | |
2919 | break; | |
2920 | case 'W': | |
2921 | /* &W - Write Profile */ | |
2922 | p[0]++; | |
2923 | switch (*p[0]) { | |
2924 | case '0': | |
1da177e4 | 2925 | p[0]++; |
475be4d8 | 2926 | modem_write_profile(m); |
1da177e4 | 2927 | break; |
475be4d8 JP |
2928 | default: |
2929 | PARSE_ERROR1; | |
2930 | } | |
2931 | break; | |
2932 | case 'X': | |
2933 | /* &X - Switch to BTX-Mode and T.70 */ | |
2934 | p[0]++; | |
2935 | switch (isdn_getnum(p)) { | |
2936 | case 0: | |
2937 | m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT); | |
2938 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; | |
2939 | break; | |
2940 | case 1: | |
2941 | m->mdmreg[REG_T70] |= BIT_T70; | |
2942 | m->mdmreg[REG_T70] &= ~BIT_T70_EXT; | |
2943 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; | |
2944 | info->xmit_size = 112; | |
2945 | m->mdmreg[REG_SI1] = 4; | |
2946 | m->mdmreg[REG_SI2] = 0; | |
2947 | break; | |
2948 | case 2: | |
2949 | m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT); | |
2950 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; | |
2951 | info->xmit_size = 112; | |
2952 | m->mdmreg[REG_SI1] = 4; | |
2953 | m->mdmreg[REG_SI2] = 0; | |
1da177e4 LT |
2954 | break; |
2955 | default: | |
2956 | PARSE_ERROR1; | |
475be4d8 JP |
2957 | } |
2958 | break; | |
2959 | default: | |
2960 | PARSE_ERROR1; | |
1da177e4 LT |
2961 | } |
2962 | return 0; | |
2963 | } | |
2964 | ||
2965 | static int | |
475be4d8 | 2966 | isdn_tty_check_ats(int mreg, int mval, modem_info *info, atemu *m) |
1da177e4 LT |
2967 | { |
2968 | /* Some plausibility checks */ | |
2969 | switch (mreg) { | |
475be4d8 JP |
2970 | case REG_L2PROT: |
2971 | if (mval > ISDN_PROTO_L2_MAX) | |
2972 | return 1; | |
2973 | break; | |
2974 | case REG_PSIZE: | |
2975 | if ((mval * 16) > ISDN_SERIAL_XMIT_MAX) | |
2976 | return 1; | |
1da177e4 | 2977 | #ifdef CONFIG_ISDN_AUDIO |
475be4d8 | 2978 | if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX)) |
1da177e4 | 2979 | return 1; |
475be4d8 JP |
2980 | #endif |
2981 | info->xmit_size = mval * 16; | |
2982 | switch (m->mdmreg[REG_L2PROT]) { | |
2983 | case ISDN_PROTO_L2_V11096: | |
2984 | case ISDN_PROTO_L2_V11019: | |
2985 | case ISDN_PROTO_L2_V11038: | |
2986 | info->xmit_size /= 10; | |
2987 | } | |
2988 | break; | |
2989 | case REG_SI1I: | |
2990 | case REG_PLAN: | |
2991 | case REG_SCREEN: | |
2992 | /* readonly registers */ | |
2993 | return 1; | |
1da177e4 LT |
2994 | } |
2995 | return 0; | |
2996 | } | |
2997 | ||
2998 | /* | |
2999 | * Perform ATS command | |
3000 | */ | |
3001 | static int | |
475be4d8 | 3002 | isdn_tty_cmd_ATS(char **p, modem_info *info) |
1da177e4 LT |
3003 | { |
3004 | atemu *m = &info->emu; | |
3005 | int bitpos; | |
3006 | int mreg; | |
3007 | int mval; | |
3008 | int bval; | |
3009 | ||
3010 | mreg = isdn_getnum(p); | |
3011 | if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG) | |
3012 | PARSE_ERROR1; | |
3013 | switch (*p[0]) { | |
475be4d8 JP |
3014 | case '=': |
3015 | p[0]++; | |
3016 | mval = isdn_getnum(p); | |
3017 | if (mval < 0 || mval > 255) | |
3018 | PARSE_ERROR1; | |
3019 | if (isdn_tty_check_ats(mreg, mval, info, m)) | |
3020 | PARSE_ERROR1; | |
3021 | m->mdmreg[mreg] = mval; | |
3022 | break; | |
3023 | case '.': | |
3024 | /* Set/Clear a single bit */ | |
3025 | p[0]++; | |
3026 | bitpos = isdn_getnum(p); | |
3027 | if ((bitpos < 0) || (bitpos > 7)) | |
3028 | PARSE_ERROR1; | |
3029 | switch (*p[0]) { | |
1da177e4 LT |
3030 | case '=': |
3031 | p[0]++; | |
475be4d8 JP |
3032 | bval = isdn_getnum(p); |
3033 | if (bval < 0 || bval > 1) | |
1da177e4 | 3034 | PARSE_ERROR1; |
475be4d8 JP |
3035 | if (bval) |
3036 | mval = m->mdmreg[mreg] | (1 << bitpos); | |
3037 | else | |
3038 | mval = m->mdmreg[mreg] & ~(1 << bitpos); | |
1da177e4 LT |
3039 | if (isdn_tty_check_ats(mreg, mval, info, m)) |
3040 | PARSE_ERROR1; | |
3041 | m->mdmreg[mreg] = mval; | |
3042 | break; | |
1da177e4 LT |
3043 | case '?': |
3044 | p[0]++; | |
475be4d8 JP |
3045 | isdn_tty_at_cout("\r\n", info); |
3046 | isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0", | |
3047 | info); | |
1da177e4 LT |
3048 | break; |
3049 | default: | |
3050 | PARSE_ERROR1; | |
475be4d8 JP |
3051 | } |
3052 | break; | |
3053 | case '?': | |
3054 | p[0]++; | |
3055 | isdn_tty_show_profile(mreg, info); | |
3056 | break; | |
3057 | default: | |
3058 | PARSE_ERROR1; | |
3059 | break; | |
1da177e4 LT |
3060 | } |
3061 | return 0; | |
3062 | } | |
3063 | ||
3064 | /* | |
3065 | * Perform ATA command | |
3066 | */ | |
3067 | static void | |
475be4d8 | 3068 | isdn_tty_cmd_ATA(modem_info *info) |
1da177e4 LT |
3069 | { |
3070 | atemu *m = &info->emu; | |
3071 | isdn_ctrl cmd; | |
3072 | int l2; | |
3073 | ||
3074 | if (info->msr & UART_MSR_RI) { | |
3075 | /* Accept incoming call */ | |
3076 | info->last_dir = 0; | |
3077 | strcpy(info->last_num, dev->num[info->drv_index]); | |
3078 | m->mdmreg[REG_RINGCNT] = 0; | |
3079 | info->msr &= ~UART_MSR_RI; | |
3080 | l2 = m->mdmreg[REG_L2PROT]; | |
3081 | #ifdef CONFIG_ISDN_AUDIO | |
3082 | /* If more than one bit set in reg18, autoselect Layer2 */ | |
3083 | if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) { | |
3084 | if (m->mdmreg[REG_SI1I] == 1) { | |
3085 | if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX)) | |
3086 | l2 = ISDN_PROTO_L2_TRANS; | |
3087 | } else | |
3088 | l2 = ISDN_PROTO_L2_X75I; | |
3089 | } | |
3090 | #endif | |
3091 | cmd.driver = info->isdn_driver; | |
3092 | cmd.command = ISDN_CMD_SETL2; | |
3093 | cmd.arg = info->isdn_channel + (l2 << 8); | |
3094 | info->last_l2 = l2; | |
3095 | isdn_command(&cmd); | |
3096 | cmd.driver = info->isdn_driver; | |
3097 | cmd.command = ISDN_CMD_SETL3; | |
3098 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); | |
3099 | #ifdef CONFIG_ISDN_TTY_FAX | |
3100 | if (l2 == ISDN_PROTO_L2_FAX) { | |
3101 | cmd.parm.fax = info->fax; | |
3102 | info->fax->direction = ISDN_TTY_FAX_CONN_IN; | |
3103 | } | |
3104 | #endif | |
3105 | isdn_command(&cmd); | |
3106 | cmd.driver = info->isdn_driver; | |
3107 | cmd.arg = info->isdn_channel; | |
3108 | cmd.command = ISDN_CMD_ACCEPTD; | |
3109 | info->dialing = 16; | |
3110 | info->emu.carrierwait = 0; | |
3111 | isdn_command(&cmd); | |
3112 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); | |
3113 | } else | |
3114 | isdn_tty_modem_result(RESULT_NO_ANSWER, info); | |
3115 | } | |
3116 | ||
3117 | #ifdef CONFIG_ISDN_AUDIO | |
3118 | /* | |
3119 | * Parse AT+F.. commands | |
3120 | */ | |
3121 | static int | |
475be4d8 | 3122 | isdn_tty_cmd_PLUSF(char **p, modem_info *info) |
1da177e4 LT |
3123 | { |
3124 | atemu *m = &info->emu; | |
3125 | char rs[20]; | |
3126 | ||
3127 | if (!strncmp(p[0], "CLASS", 5)) { | |
3128 | p[0] += 5; | |
3129 | switch (*p[0]) { | |
475be4d8 JP |
3130 | case '?': |
3131 | p[0]++; | |
3132 | sprintf(rs, "\r\n%d", | |
3133 | (m->mdmreg[REG_SI1] & 1) ? 8 : 0); | |
1da177e4 | 3134 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 JP |
3135 | if (TTY_IS_FCLASS2(info)) |
3136 | sprintf(rs, "\r\n2"); | |
3137 | else if (TTY_IS_FCLASS1(info)) | |
3138 | sprintf(rs, "\r\n1"); | |
1da177e4 | 3139 | #endif |
475be4d8 JP |
3140 | isdn_tty_at_cout(rs, info); |
3141 | break; | |
3142 | case '=': | |
3143 | p[0]++; | |
3144 | switch (*p[0]) { | |
3145 | case '0': | |
1da177e4 | 3146 | p[0]++; |
475be4d8 JP |
3147 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; |
3148 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS; | |
3149 | m->mdmreg[REG_SI1] = 4; | |
3150 | info->xmit_size = | |
3151 | m->mdmreg[REG_PSIZE] * 16; | |
3152 | break; | |
1da177e4 | 3153 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 JP |
3154 | case '1': |
3155 | p[0]++; | |
3156 | if (!(dev->global_features & | |
3157 | ISDN_FEATURE_L3_FCLASS1)) | |
3158 | PARSE_ERROR1; | |
3159 | m->mdmreg[REG_SI1] = 1; | |
3160 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX; | |
3161 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1; | |
3162 | info->xmit_size = | |
3163 | m->mdmreg[REG_PSIZE] * 16; | |
3164 | break; | |
3165 | case '2': | |
3166 | p[0]++; | |
3167 | if (!(dev->global_features & | |
3168 | ISDN_FEATURE_L3_FCLASS2)) | |
3169 | PARSE_ERROR1; | |
3170 | m->mdmreg[REG_SI1] = 1; | |
3171 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX; | |
3172 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2; | |
3173 | info->xmit_size = | |
3174 | m->mdmreg[REG_PSIZE] * 16; | |
3175 | break; | |
1da177e4 | 3176 | #endif |
475be4d8 JP |
3177 | case '8': |
3178 | p[0]++; | |
3179 | /* L2 will change on dialout with si=1 */ | |
3180 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; | |
3181 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS; | |
3182 | m->mdmreg[REG_SI1] = 5; | |
3183 | info->xmit_size = VBUF; | |
3184 | break; | |
3185 | case '?': | |
3186 | p[0]++; | |
3187 | strcpy(rs, "\r\n0,"); | |
1da177e4 | 3188 | #ifdef CONFIG_ISDN_TTY_FAX |
475be4d8 JP |
3189 | if (dev->global_features & |
3190 | ISDN_FEATURE_L3_FCLASS1) | |
3191 | strcat(rs, "1,"); | |
3192 | if (dev->global_features & | |
3193 | ISDN_FEATURE_L3_FCLASS2) | |
3194 | strcat(rs, "2,"); | |
3195 | #endif | |
3196 | strcat(rs, "8"); | |
3197 | isdn_tty_at_cout(rs, info); | |
1da177e4 LT |
3198 | break; |
3199 | default: | |
3200 | PARSE_ERROR1; | |
475be4d8 JP |
3201 | } |
3202 | break; | |
3203 | default: | |
3204 | PARSE_ERROR1; | |
1da177e4 LT |
3205 | } |
3206 | return 0; | |
3207 | } | |
3208 | #ifdef CONFIG_ISDN_TTY_FAX | |
3209 | return (isdn_tty_cmd_PLUSF_FAX(p, info)); | |
3210 | #else | |
3211 | PARSE_ERROR1; | |
3212 | #endif | |
3213 | } | |
3214 | ||
3215 | /* | |
3216 | * Parse AT+V.. commands | |
3217 | */ | |
3218 | static int | |
475be4d8 | 3219 | isdn_tty_cmd_PLUSV(char **p, modem_info *info) |
1da177e4 LT |
3220 | { |
3221 | atemu *m = &info->emu; | |
3222 | isdn_ctrl cmd; | |
3223 | static char *vcmd[] = | |
475be4d8 | 3224 | {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL}; |
1da177e4 LT |
3225 | int i; |
3226 | int par1; | |
3227 | int par2; | |
3228 | char rs[20]; | |
3229 | ||
3230 | i = 0; | |
3231 | while (vcmd[i]) { | |
3232 | if (!strncmp(vcmd[i], p[0], 2)) { | |
3233 | p[0] += 2; | |
3234 | break; | |
3235 | } | |
3236 | i++; | |
3237 | } | |
3238 | switch (i) { | |
475be4d8 JP |
3239 | case 0: |
3240 | /* AT+VNH - Auto hangup feature */ | |
3241 | switch (*p[0]) { | |
3242 | case '?': | |
3243 | p[0]++; | |
3244 | isdn_tty_at_cout("\r\n1", info); | |
3245 | break; | |
3246 | case '=': | |
3247 | p[0]++; | |
1da177e4 | 3248 | switch (*p[0]) { |
475be4d8 JP |
3249 | case '1': |
3250 | p[0]++; | |
3251 | break; | |
3252 | case '?': | |
3253 | p[0]++; | |
3254 | isdn_tty_at_cout("\r\n1", info); | |
3255 | break; | |
3256 | default: | |
3257 | PARSE_ERROR1; | |
1da177e4 LT |
3258 | } |
3259 | break; | |
475be4d8 JP |
3260 | default: |
3261 | PARSE_ERROR1; | |
3262 | } | |
3263 | break; | |
3264 | case 1: | |
3265 | /* AT+VIP - Reset all voice parameters */ | |
3266 | isdn_tty_modem_reset_vpar(m); | |
3267 | break; | |
3268 | case 2: | |
3269 | /* AT+VLS - Select device, accept incoming call */ | |
3270 | switch (*p[0]) { | |
3271 | case '?': | |
3272 | p[0]++; | |
3273 | sprintf(rs, "\r\n%d", m->vpar[0]); | |
3274 | isdn_tty_at_cout(rs, info); | |
1da177e4 | 3275 | break; |
475be4d8 JP |
3276 | case '=': |
3277 | p[0]++; | |
1da177e4 | 3278 | switch (*p[0]) { |
475be4d8 JP |
3279 | case '0': |
3280 | p[0]++; | |
3281 | m->vpar[0] = 0; | |
3282 | break; | |
3283 | case '2': | |
3284 | p[0]++; | |
3285 | m->vpar[0] = 2; | |
3286 | break; | |
3287 | case '?': | |
3288 | p[0]++; | |
3289 | isdn_tty_at_cout("\r\n0,2", info); | |
3290 | break; | |
3291 | default: | |
1da177e4 LT |
3292 | PARSE_ERROR1; |
3293 | } | |
475be4d8 JP |
3294 | break; |
3295 | default: | |
3296 | PARSE_ERROR1; | |
3297 | } | |
3298 | break; | |
3299 | case 3: | |
3300 | /* AT+VRX - Start recording */ | |
3301 | if (!m->vpar[0]) | |
3302 | PARSE_ERROR1; | |
3303 | if (info->online != 1) { | |
3304 | isdn_tty_modem_result(RESULT_NO_ANSWER, info); | |
3305 | return 1; | |
3306 | } | |
3307 | info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state); | |
3308 | if (!info->dtmf_state) { | |
3309 | printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n"); | |
3310 | PARSE_ERROR1; | |
3311 | } | |
3312 | info->silence_state = isdn_audio_silence_init(info->silence_state); | |
3313 | if (!info->silence_state) { | |
3314 | printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n"); | |
3315 | PARSE_ERROR1; | |
3316 | } | |
3317 | if (m->vpar[3] < 5) { | |
3318 | info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]); | |
3319 | if (!info->adpcmr) { | |
3320 | printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n"); | |
1da177e4 LT |
3321 | PARSE_ERROR1; |
3322 | } | |
475be4d8 | 3323 | } |
1da177e4 | 3324 | #ifdef ISDN_DEBUG_AT |
475be4d8 | 3325 | printk(KERN_DEBUG "AT: +VRX\n"); |
1da177e4 | 3326 | #endif |
475be4d8 JP |
3327 | info->vonline |= 1; |
3328 | isdn_tty_modem_result(RESULT_CONNECT, info); | |
3329 | return 0; | |
3330 | break; | |
3331 | case 4: | |
3332 | /* AT+VSD - Silence detection */ | |
3333 | switch (*p[0]) { | |
3334 | case '?': | |
3335 | p[0]++; | |
3336 | sprintf(rs, "\r\n<%d>,<%d>", | |
3337 | m->vpar[1], | |
3338 | m->vpar[2]); | |
3339 | isdn_tty_at_cout(rs, info); | |
1da177e4 | 3340 | break; |
475be4d8 JP |
3341 | case '=': |
3342 | p[0]++; | |
3343 | if ((*p[0] >= '0') && (*p[0] <= '9')) { | |
3344 | par1 = isdn_getnum(p); | |
3345 | if ((par1 < 0) || (par1 > 31)) | |
1da177e4 | 3346 | PARSE_ERROR1; |
475be4d8 | 3347 | if (*p[0] != ',') |
1da177e4 | 3348 | PARSE_ERROR1; |
475be4d8 JP |
3349 | p[0]++; |
3350 | par2 = isdn_getnum(p); | |
3351 | if ((par2 < 0) || (par2 > 255)) | |
3352 | PARSE_ERROR1; | |
3353 | m->vpar[1] = par1; | |
3354 | m->vpar[2] = par2; | |
3355 | break; | |
3356 | } else | |
3357 | if (*p[0] == '?') { | |
1da177e4 | 3358 | p[0]++; |
475be4d8 JP |
3359 | isdn_tty_at_cout("\r\n<0-31>,<0-255>", |
3360 | info); | |
1da177e4 | 3361 | break; |
475be4d8 | 3362 | } else |
1da177e4 | 3363 | PARSE_ERROR1; |
1da177e4 | 3364 | break; |
475be4d8 JP |
3365 | default: |
3366 | PARSE_ERROR1; | |
3367 | } | |
3368 | break; | |
3369 | case 5: | |
3370 | /* AT+VSM - Select compression */ | |
3371 | switch (*p[0]) { | |
3372 | case '?': | |
3373 | p[0]++; | |
3374 | sprintf(rs, "\r\n<%d>,<%d><8000>", | |
3375 | m->vpar[3], | |
3376 | m->vpar[1]); | |
3377 | isdn_tty_at_cout(rs, info); | |
3378 | break; | |
3379 | case '=': | |
3380 | p[0]++; | |
3381 | switch (*p[0]) { | |
3382 | case '2': | |
3383 | case '3': | |
3384 | case '4': | |
3385 | case '5': | |
3386 | case '6': | |
3387 | par1 = isdn_getnum(p); | |
3388 | if ((par1 < 2) || (par1 > 6)) | |
3389 | PARSE_ERROR1; | |
3390 | m->vpar[3] = par1; | |
3391 | break; | |
3392 | case '?': | |
3393 | p[0]++; | |
3394 | isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n", | |
3395 | info); | |
3396 | isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n", | |
3397 | info); | |
3398 | isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n", | |
3399 | info); | |
3400 | isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n", | |
3401 | info); | |
3402 | isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n", | |
3403 | info); | |
3404 | break; | |
3405 | default: | |
1da177e4 | 3406 | PARSE_ERROR1; |
1da177e4 | 3407 | } |
475be4d8 JP |
3408 | break; |
3409 | default: | |
3410 | PARSE_ERROR1; | |
3411 | } | |
3412 | break; | |
3413 | case 6: | |
3414 | /* AT+VTX - Start sending */ | |
3415 | if (!m->vpar[0]) | |
3416 | PARSE_ERROR1; | |
3417 | if (info->online != 1) { | |
3418 | isdn_tty_modem_result(RESULT_NO_ANSWER, info); | |
3419 | return 1; | |
3420 | } | |
3421 | info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state); | |
3422 | if (!info->dtmf_state) { | |
3423 | printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n"); | |
3424 | PARSE_ERROR1; | |
3425 | } | |
3426 | if (m->vpar[3] < 5) { | |
3427 | info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]); | |
3428 | if (!info->adpcms) { | |
3429 | printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n"); | |
1da177e4 LT |
3430 | PARSE_ERROR1; |
3431 | } | |
475be4d8 | 3432 | } |
1da177e4 | 3433 | #ifdef ISDN_DEBUG_AT |
475be4d8 | 3434 | printk(KERN_DEBUG "AT: +VTX\n"); |
1da177e4 | 3435 | #endif |
475be4d8 JP |
3436 | m->lastDLE = 0; |
3437 | info->vonline |= 2; | |
3438 | isdn_tty_modem_result(RESULT_CONNECT, info); | |
3439 | return 0; | |
3440 | break; | |
3441 | case 7: | |
3442 | /* AT+VDD - DTMF detection */ | |
3443 | switch (*p[0]) { | |
3444 | case '?': | |
3445 | p[0]++; | |
3446 | sprintf(rs, "\r\n<%d>,<%d>", | |
3447 | m->vpar[4], | |
3448 | m->vpar[5]); | |
3449 | isdn_tty_at_cout(rs, info); | |
1da177e4 | 3450 | break; |
475be4d8 JP |
3451 | case '=': |
3452 | p[0]++; | |
3453 | if ((*p[0] >= '0') && (*p[0] <= '9')) { | |
3454 | if (info->online != 1) | |
3455 | PARSE_ERROR1; | |
3456 | par1 = isdn_getnum(p); | |
3457 | if ((par1 < 0) || (par1 > 15)) | |
3458 | PARSE_ERROR1; | |
3459 | if (*p[0] != ',') | |
1da177e4 | 3460 | PARSE_ERROR1; |
475be4d8 JP |
3461 | p[0]++; |
3462 | par2 = isdn_getnum(p); | |
3463 | if ((par2 < 0) || (par2 > 255)) | |
3464 | PARSE_ERROR1; | |
3465 | m->vpar[4] = par1; | |
3466 | m->vpar[5] = par2; | |
3467 | cmd.driver = info->isdn_driver; | |
3468 | cmd.command = ISDN_CMD_AUDIO; | |
3469 | cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8); | |
3470 | cmd.parm.num[0] = par1; | |
3471 | cmd.parm.num[1] = par2; | |
3472 | isdn_command(&cmd); | |
3473 | break; | |
3474 | } else | |
3475 | if (*p[0] == '?') { | |
3476 | p[0]++; | |
3477 | isdn_tty_at_cout("\r\n<0-15>,<0-255>", | |
3478 | info); | |
1da177e4 | 3479 | break; |
475be4d8 | 3480 | } else |
1da177e4 | 3481 | PARSE_ERROR1; |
1da177e4 LT |
3482 | break; |
3483 | default: | |
3484 | PARSE_ERROR1; | |
475be4d8 JP |
3485 | } |
3486 | break; | |
3487 | default: | |
3488 | PARSE_ERROR1; | |
1da177e4 LT |
3489 | } |
3490 | return 0; | |
3491 | } | |
3492 | #endif /* CONFIG_ISDN_AUDIO */ | |
3493 | ||
3494 | /* | |
3495 | * Parse and perform an AT-command-line. | |
3496 | */ | |
3497 | static void | |
475be4d8 | 3498 | isdn_tty_parse_at(modem_info *info) |
1da177e4 LT |
3499 | { |
3500 | atemu *m = &info->emu; | |
3501 | char *p; | |
f417f5e4 | 3502 | char ds[ISDN_MSNLEN]; |
1da177e4 LT |
3503 | |
3504 | #ifdef ISDN_DEBUG_AT | |
3505 | printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd); | |
3506 | #endif | |
3507 | for (p = &m->mdmcmd[2]; *p;) { | |
3508 | switch (*p) { | |
475be4d8 JP |
3509 | case ' ': |
3510 | p++; | |
3511 | break; | |
3512 | case 'A': | |
3513 | /* A - Accept incoming call */ | |
3514 | p++; | |
3515 | isdn_tty_cmd_ATA(info); | |
3516 | return; | |
3517 | break; | |
3518 | case 'D': | |
3519 | /* D - Dial */ | |
3520 | if (info->msr & UART_MSR_DCD) | |
3521 | PARSE_ERROR; | |
3522 | if (info->msr & UART_MSR_RI) { | |
3523 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
3524 | return; | |
3525 | } | |
3526 | isdn_tty_getdial(++p, ds, sizeof ds); | |
3527 | p += strlen(p); | |
3528 | if (!strlen(m->msn)) | |
3529 | isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info); | |
3530 | else if (strlen(ds)) | |
3531 | isdn_tty_dial(ds, info, m); | |
3532 | else | |
3533 | PARSE_ERROR; | |
3534 | return; | |
3535 | case 'E': | |
3536 | /* E - Turn Echo on/off */ | |
3537 | p++; | |
3538 | switch (isdn_getnum(&p)) { | |
3539 | case 0: | |
3540 | m->mdmreg[REG_ECHO] &= ~BIT_ECHO; | |
1da177e4 | 3541 | break; |
475be4d8 JP |
3542 | case 1: |
3543 | m->mdmreg[REG_ECHO] |= BIT_ECHO; | |
3544 | break; | |
3545 | default: | |
3546 | PARSE_ERROR; | |
3547 | } | |
3548 | break; | |
3549 | case 'H': | |
3550 | /* H - On/Off-hook */ | |
3551 | p++; | |
3552 | switch (*p) { | |
3553 | case '0': | |
1da177e4 | 3554 | p++; |
475be4d8 | 3555 | isdn_tty_on_hook(info); |
1da177e4 | 3556 | break; |
475be4d8 | 3557 | case '1': |
1da177e4 | 3558 | p++; |
475be4d8 | 3559 | isdn_tty_off_hook(); |
1da177e4 | 3560 | break; |
475be4d8 JP |
3561 | default: |
3562 | isdn_tty_on_hook(info); | |
3563 | break; | |
3564 | } | |
3565 | break; | |
3566 | case 'I': | |
3567 | /* I - Information */ | |
3568 | p++; | |
3569 | isdn_tty_at_cout("\r\nLinux ISDN", info); | |
3570 | switch (*p) { | |
3571 | case '0': | |
3572 | case '1': | |
1da177e4 | 3573 | p++; |
1da177e4 | 3574 | break; |
475be4d8 | 3575 | case '2': |
1da177e4 | 3576 | p++; |
475be4d8 | 3577 | isdn_tty_report(info); |
1da177e4 | 3578 | break; |
475be4d8 | 3579 | case '3': |
1da177e4 | 3580 | p++; |
475be4d8 JP |
3581 | snprintf(ds, sizeof(ds), "\r\n%d", info->emu.charge); |
3582 | isdn_tty_at_cout(ds, info); | |
1da177e4 | 3583 | break; |
475be4d8 JP |
3584 | default:; |
3585 | } | |
3586 | break; | |
3587 | #ifdef DUMMY_HAYES_AT | |
3588 | case 'L': | |
3589 | case 'M': | |
3590 | /* only for be compilant with common scripts */ | |
3591 | /* no function */ | |
3592 | p++; | |
3593 | isdn_getnum(&p); | |
3594 | break; | |
1da177e4 | 3595 | #endif |
475be4d8 JP |
3596 | case 'O': |
3597 | /* O - Go online */ | |
3598 | p++; | |
3599 | if (info->msr & UART_MSR_DCD) | |
3600 | /* if B-Channel is up */ | |
3601 | isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT : RESULT_CONNECT64000, info); | |
3602 | else | |
3603 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
3604 | return; | |
3605 | case 'Q': | |
3606 | /* Q - Turn Emulator messages on/off */ | |
3607 | p++; | |
3608 | switch (isdn_getnum(&p)) { | |
3609 | case 0: | |
3610 | m->mdmreg[REG_RESP] |= BIT_RESP; | |
3611 | break; | |
3612 | case 1: | |
3613 | m->mdmreg[REG_RESP] &= ~BIT_RESP; | |
3614 | break; | |
3615 | default: | |
3616 | PARSE_ERROR; | |
3617 | } | |
3618 | break; | |
3619 | case 'S': | |
3620 | /* S - Set/Get Register */ | |
3621 | p++; | |
3622 | if (isdn_tty_cmd_ATS(&p, info)) | |
1da177e4 | 3623 | return; |
475be4d8 JP |
3624 | break; |
3625 | case 'V': | |
3626 | /* V - Numeric or ASCII Emulator-messages */ | |
3627 | p++; | |
3628 | switch (isdn_getnum(&p)) { | |
3629 | case 0: | |
3630 | m->mdmreg[REG_RESP] |= BIT_RESPNUM; | |
3631 | break; | |
3632 | case 1: | |
3633 | m->mdmreg[REG_RESP] &= ~BIT_RESPNUM; | |
1da177e4 | 3634 | break; |
475be4d8 JP |
3635 | default: |
3636 | PARSE_ERROR; | |
3637 | } | |
3638 | break; | |
3639 | case 'Z': | |
3640 | /* Z - Load Registers from Profile */ | |
3641 | p++; | |
3642 | if (info->msr & UART_MSR_DCD) { | |
3643 | info->online = 0; | |
3644 | isdn_tty_on_hook(info); | |
3645 | } | |
3646 | isdn_tty_modem_reset_regs(info, 1); | |
3647 | break; | |
3648 | case '+': | |
3649 | p++; | |
3650 | switch (*p) { | |
3651 | #ifdef CONFIG_ISDN_AUDIO | |
3652 | case 'F': | |
1da177e4 | 3653 | p++; |
475be4d8 | 3654 | if (isdn_tty_cmd_PLUSF(&p, info)) |
1da177e4 LT |
3655 | return; |
3656 | break; | |
3657 | case 'V': | |
475be4d8 JP |
3658 | if ((!(m->mdmreg[REG_SI1] & 1)) || |
3659 | (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM)) | |
3660 | PARSE_ERROR; | |
1da177e4 | 3661 | p++; |
475be4d8 JP |
3662 | if (isdn_tty_cmd_PLUSV(&p, info)) |
3663 | return; | |
1da177e4 | 3664 | break; |
475be4d8 JP |
3665 | #endif /* CONFIG_ISDN_AUDIO */ |
3666 | case 'S': /* SUSPEND */ | |
1da177e4 | 3667 | p++; |
475be4d8 JP |
3668 | isdn_tty_get_msnstr(ds, &p); |
3669 | isdn_tty_suspend(ds, info, m); | |
1da177e4 | 3670 | break; |
475be4d8 | 3671 | case 'R': /* RESUME */ |
1da177e4 | 3672 | p++; |
475be4d8 JP |
3673 | isdn_tty_get_msnstr(ds, &p); |
3674 | isdn_tty_resume(ds, info, m); | |
1da177e4 | 3675 | break; |
475be4d8 | 3676 | case 'M': /* MESSAGE */ |
1da177e4 | 3677 | p++; |
475be4d8 | 3678 | isdn_tty_send_msg(info, m, p); |
1da177e4 LT |
3679 | break; |
3680 | default: | |
3681 | PARSE_ERROR; | |
475be4d8 JP |
3682 | } |
3683 | break; | |
3684 | case '&': | |
3685 | p++; | |
3686 | if (isdn_tty_cmd_ATand(&p, info)) | |
3687 | return; | |
3688 | break; | |
3689 | default: | |
3690 | PARSE_ERROR; | |
1da177e4 LT |
3691 | } |
3692 | } | |
3693 | #ifdef CONFIG_ISDN_AUDIO | |
3694 | if (!info->vonline) | |
3695 | #endif | |
3696 | isdn_tty_modem_result(RESULT_OK, info); | |
3697 | } | |
3698 | ||
3699 | /* Need own toupper() because standard-toupper is not available | |
3700 | * within modules. | |
3701 | */ | |
475be4d8 | 3702 | #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c) |
1da177e4 LT |
3703 | |
3704 | /* | |
3705 | * Perform line-editing of AT-commands | |
3706 | * | |
3707 | * Parameters: | |
3708 | * p inputbuffer | |
3709 | * count length of buffer | |
3710 | * channel index to line (minor-device) | |
3711 | */ | |
3712 | static int | |
475be4d8 | 3713 | isdn_tty_edit_at(const char *p, int count, modem_info *info) |
1da177e4 LT |
3714 | { |
3715 | atemu *m = &info->emu; | |
3716 | int total = 0; | |
3717 | u_char c; | |
3718 | char eb[2]; | |
3719 | int cnt; | |
3720 | ||
3721 | for (cnt = count; cnt > 0; p++, cnt--) { | |
3722 | c = *p; | |
3723 | total++; | |
3724 | if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) { | |
3725 | /* Separator (CR or LF) */ | |
3726 | m->mdmcmd[m->mdmcmdl] = 0; | |
3727 | if (m->mdmreg[REG_ECHO] & BIT_ECHO) { | |
3728 | eb[0] = c; | |
3729 | eb[1] = 0; | |
3730 | isdn_tty_at_cout(eb, info); | |
3731 | } | |
3732 | if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2)))) | |
3733 | isdn_tty_parse_at(info); | |
3734 | m->mdmcmdl = 0; | |
3735 | continue; | |
3736 | } | |
3737 | if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) { | |
3738 | /* Backspace-Function */ | |
3739 | if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) { | |
3740 | if (m->mdmcmdl) | |
3741 | m->mdmcmdl--; | |
3742 | if (m->mdmreg[REG_ECHO] & BIT_ECHO) | |
3743 | isdn_tty_at_cout("\b", info); | |
3744 | } | |
3745 | continue; | |
3746 | } | |
3747 | if (cmdchar(c)) { | |
3748 | if (m->mdmreg[REG_ECHO] & BIT_ECHO) { | |
3749 | eb[0] = c; | |
3750 | eb[1] = 0; | |
3751 | isdn_tty_at_cout(eb, info); | |
3752 | } | |
3753 | if (m->mdmcmdl < 255) { | |
3754 | c = my_toupper(c); | |
3755 | switch (m->mdmcmdl) { | |
475be4d8 JP |
3756 | case 1: |
3757 | if (c == 'T') { | |
3758 | m->mdmcmd[m->mdmcmdl] = c; | |
3759 | m->mdmcmd[++m->mdmcmdl] = 0; | |
1da177e4 | 3760 | break; |
475be4d8 JP |
3761 | } else |
3762 | m->mdmcmdl = 0; | |
3763 | /* Fall through, check for 'A' */ | |
3764 | case 0: | |
3765 | if (c == 'A') { | |
1da177e4 LT |
3766 | m->mdmcmd[m->mdmcmdl] = c; |
3767 | m->mdmcmd[++m->mdmcmdl] = 0; | |
475be4d8 JP |
3768 | } |
3769 | break; | |
3770 | default: | |
3771 | m->mdmcmd[m->mdmcmdl] = c; | |
3772 | m->mdmcmd[++m->mdmcmdl] = 0; | |
1da177e4 LT |
3773 | } |
3774 | } | |
3775 | } | |
3776 | } | |
3777 | return total; | |
3778 | } | |
3779 | ||
3780 | /* | |
3781 | * Switch all modem-channels who are online and got a valid | |
3782 | * escape-sequence 1.5 seconds ago, to command-mode. | |
3783 | * This function is called every second via timer-interrupt from within | |
3784 | * timer-dispatcher isdn_timer_function() | |
3785 | */ | |
3786 | void | |
3787 | isdn_tty_modem_escape(void) | |
3788 | { | |
3789 | int ton = 0; | |
3790 | int i; | |
3791 | int midx; | |
3792 | ||
3793 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) | |
37630f40 JS |
3794 | if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) { |
3795 | modem_info *info = &dev->mdm.info[midx]; | |
3796 | if (info->online) { | |
3797 | ton = 1; | |
3798 | if ((info->emu.pluscount == 3) && | |
3799 | time_after(jiffies, | |
3800 | info->emu.lastplus + PLUSWAIT2)) { | |
3801 | info->emu.pluscount = 0; | |
3802 | info->online = 0; | |
3803 | isdn_tty_modem_result(RESULT_OK, info); | |
1da177e4 LT |
3804 | } |
3805 | } | |
37630f40 | 3806 | } |
1da177e4 LT |
3807 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); |
3808 | } | |
3809 | ||
3810 | /* | |
3811 | * Put a RING-message to all modem-channels who have the RI-bit set. | |
3812 | * This function is called every second via timer-interrupt from within | |
3813 | * timer-dispatcher isdn_timer_function() | |
3814 | */ | |
3815 | void | |
3816 | isdn_tty_modem_ring(void) | |
3817 | { | |
3818 | int ton = 0; | |
3819 | int i; | |
3820 | ||
3821 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
3822 | modem_info *info = &dev->mdm.info[i]; | |
3823 | if (info->msr & UART_MSR_RI) { | |
3824 | ton = 1; | |
3825 | isdn_tty_modem_result(RESULT_RING, info); | |
3826 | } | |
3827 | } | |
3828 | isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton); | |
3829 | } | |
3830 | ||
3831 | /* | |
3832 | * For all online tty's, try sending data to | |
3833 | * the lower levels. | |
3834 | */ | |
3835 | void | |
3836 | isdn_tty_modem_xmit(void) | |
3837 | { | |
3838 | int ton = 1; | |
3839 | int i; | |
3840 | ||
3841 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
3842 | modem_info *info = &dev->mdm.info[i]; | |
3843 | if (info->online) { | |
3844 | ton = 1; | |
3845 | isdn_tty_senddown(info); | |
3846 | isdn_tty_tint(info); | |
3847 | } | |
3848 | } | |
3849 | isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton); | |
3850 | } | |
3851 | ||
3852 | /* | |
3853 | * Check all channels if we have a 'no carrier' timeout. | |
3854 | * Timeout value is set by Register S7. | |
3855 | */ | |
3856 | void | |
3857 | isdn_tty_carrier_timeout(void) | |
3858 | { | |
3859 | int ton = 0; | |
3860 | int i; | |
3861 | ||
3862 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | |
3863 | modem_info *info = &dev->mdm.info[i]; | |
37630f40 JS |
3864 | if (!info->dialing) |
3865 | continue; | |
3866 | if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { | |
3867 | info->dialing = 0; | |
3868 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | |
3869 | isdn_tty_modem_hup(info, 1); | |
3870 | } else | |
3871 | ton = 1; | |
1da177e4 LT |
3872 | } |
3873 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); | |
3874 | } |