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