1 /* $Id: isdn_tty.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
3 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
12 #undef ISDN_TTY_STAT_DEBUG
14 #include <linux/config.h>
15 #include <linux/isdn.h>
16 #include "isdn_common.h"
18 #ifdef CONFIG_ISDN_AUDIO
19 #include "isdn_audio.h"
21 #define VBUFX (VBUF/16)
24 #define FIX_FILE_TRANSFER
25 #define DUMMY_HAYES_AT
29 static int isdn_tty_edit_at(const char *, int, modem_info *, int);
30 static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *, int);
31 static void isdn_tty_modem_reset_regs(modem_info *, int);
32 static void isdn_tty_cmd_ATA(modem_info *);
33 static void isdn_tty_flush_buffer(struct tty_struct *);
34 static void isdn_tty_modem_result(int, modem_info *);
35 #ifdef CONFIG_ISDN_AUDIO
36 static int isdn_tty_countDLE(unsigned char *, int);
39 /* Leave this unchanged unless you know what you do! */
40 #define MODEM_PARANOIA_CHECK
41 #define MODEM_DO_RESTART
43 static int bit2si[8] =
44 {1, 5, 7, 7, 7, 7, 7, 7};
45 static int si2bit[8] =
46 {4, 1, 4, 4, 4, 4, 4, 4};
48 char *isdn_tty_revision = "$Revision: 1.1.2.3 $";
51 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
52 * to stuff incoming data directly into a tty's flip-buffer. This
53 * is done to speed up tty-receiving if the receive-queue is empty.
54 * This routine MUST be called with interrupts off.
57 * 0 = Failure, data has to be buffered and later processed by
58 * isdn_tty_readmodem().
61 isdn_tty_try_read(modem_info * info, struct sk_buff *skb)
65 struct tty_struct *tty;
68 if ((tty = info->tty)) {
69 if (info->mcr & UART_MCR_RTS) {
70 c = TTY_FLIPBUF_SIZE - tty->flip.count;
72 #ifdef CONFIG_ISDN_AUDIO
73 + ISDN_AUDIO_SKB_DLECOUNT(skb)
77 #ifdef CONFIG_ISDN_AUDIO
78 if (ISDN_AUDIO_SKB_DLECOUNT(skb))
80 if (*skb->data == DLE)
81 tty_insert_flip_char(tty, DLE, 0);
82 tty_insert_flip_char(tty, *skb->data++, 0);
85 memcpy(tty->flip.char_buf_ptr,
87 tty->flip.count += len;
88 tty->flip.char_buf_ptr += len;
89 memset(tty->flip.flag_buf_ptr, 0, len);
90 tty->flip.flag_buf_ptr += len;
91 #ifdef CONFIG_ISDN_AUDIO
94 if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
95 tty->flip.flag_buf_ptr[len - 1] = 0xff;
96 schedule_delayed_work(&tty->flip.work, 1);
106 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
107 * It tries getting received data from the receive queue an stuff it into
108 * the tty's flip-buffer.
111 isdn_tty_readmodem(void)
118 struct tty_struct *tty;
121 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
122 if ((midx = dev->m_idx[i]) >= 0) {
123 info = &dev->mdm.info[midx];
126 #ifdef CONFIG_ISDN_AUDIO
127 isdn_audio_eval_dtmf(info);
128 if ((info->vonline & 1) && (info->emu.vpar[1]))
129 isdn_audio_eval_silence(info);
131 if ((tty = info->tty)) {
132 if (info->mcr & UART_MCR_RTS) {
133 c = TTY_FLIPBUF_SIZE - tty->flip.count;
135 r = isdn_readbchan(info->isdn_driver, info->isdn_channel,
136 tty->flip.char_buf_ptr,
137 tty->flip.flag_buf_ptr, c, NULL);
138 /* CISCO AsyncPPP Hack */
139 if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
140 memset(tty->flip.flag_buf_ptr, 0, r);
141 tty->flip.count += r;
142 tty->flip.flag_buf_ptr += r;
143 tty->flip.char_buf_ptr += r;
145 schedule_delayed_work(&tty->flip.work, 1);
160 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
164 isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb)
168 #ifdef CONFIG_ISDN_AUDIO
173 if ((midx = dev->m_idx[i]) < 0) {
174 /* if midx is invalid, packet is not for tty */
177 info = &dev->mdm.info[midx];
178 #ifdef CONFIG_ISDN_AUDIO
181 if ((info->vonline) && (!info->emu.vpar[4]))
182 isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt);
183 if ((info->vonline & 1) && (info->emu.vpar[1]))
184 isdn_audio_calc_silence(info, skb->data, skb->len, ifmt);
186 if ((info->online < 2)
187 #ifdef CONFIG_ISDN_AUDIO
188 && (!(info->vonline & 1))
191 /* If Modem not listening, drop data */
195 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
196 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) {
197 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
198 if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */
201 if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */
204 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
205 if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1)))
208 #ifdef CONFIG_ISDN_AUDIO
209 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
210 ISDN_AUDIO_SKB_LOCK(skb) = 0;
211 if (info->vonline & 1) {
212 /* voice conversion/compression */
213 switch (info->emu.vpar[3]) {
218 * Since compressed data takes less
219 * space, we can overwrite the buffer.
221 skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr,
230 isdn_audio_ulaw2alaw(skb->data, skb->len);
235 isdn_audio_alaw2ulaw(skb->data, skb->len);
238 ISDN_AUDIO_SKB_DLECOUNT(skb) =
239 isdn_tty_countDLE(skb->data, skb->len);
241 #ifdef CONFIG_ISDN_TTY_FAX
243 if (info->faxonline & 2) {
244 isdn_tty_fax_bitorder(info, skb);
245 ISDN_AUDIO_SKB_DLECOUNT(skb) =
246 isdn_tty_countDLE(skb->data, skb->len);
251 /* Try to deliver directly via tty-flip-buf if queue is empty */
252 spin_lock_irqsave(&info->readlock, flags);
253 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
254 if (isdn_tty_try_read(info, skb)) {
255 spin_unlock_irqrestore(&info->readlock, flags);
258 /* Direct deliver failed or queue wasn't empty.
259 * Queue up for later dequeueing via timer-irq.
261 __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb);
262 dev->drv[di]->rcvcount[channel] +=
264 #ifdef CONFIG_ISDN_AUDIO
265 + ISDN_AUDIO_SKB_DLECOUNT(skb)
268 spin_unlock_irqrestore(&info->readlock, flags);
269 /* Schedule dequeuing */
270 if ((dev->modempoll) && (info->rcvsched))
271 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
276 isdn_tty_cleanup_xmit(modem_info * info)
278 skb_queue_purge(&info->xmit_queue);
279 #ifdef CONFIG_ISDN_AUDIO
280 skb_queue_purge(&info->dtmf_queue);
285 isdn_tty_tint(modem_info * info)
287 struct sk_buff *skb = skb_dequeue(&info->xmit_queue);
293 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
294 info->isdn_channel, 1, skb)) == len) {
295 struct tty_struct *tty = info->tty;
296 info->send_outstanding++;
297 info->msr &= ~UART_MSR_CTS;
298 info->lsr &= ~UART_LSR_TEMT;
299 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
300 tty->ldisc.write_wakeup)
301 (tty->ldisc.write_wakeup) (tty);
302 wake_up_interruptible(&tty->write_wait);
306 /* Error: no channel, already shutdown, or wrong parameter */
310 skb_queue_head(&info->xmit_queue, skb);
313 #ifdef CONFIG_ISDN_AUDIO
315 isdn_tty_countDLE(unsigned char *buf, int len)
325 /* This routine is called from within isdn_tty_write() to perform
326 * DLE-decoding when sending audio-data.
329 isdn_tty_handleDLEdown(modem_info * info, atemu * m, int len)
331 unsigned char *p = &info->xmit_buf[info->xmit_count];
341 memmove(p, p + 1, len - 1);
352 #ifdef ISDN_DEBUG_MODEM_VOICE
354 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
357 isdn_tty_at_cout("\020\003", info);
358 if (!info->vonline) {
359 #ifdef ISDN_DEBUG_MODEM_VOICE
361 "DLEdown: send VCON on ttyI%d\n",
364 isdn_tty_at_cout("\r\nVCON\r\n", info);
371 memmove(p, p + 1, len - 1);
385 printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n");
391 /* This routine is called from within isdn_tty_write() when receiving
392 * audio-data. It interrupts receiving, if an character other than
396 isdn_tty_end_vrx(const char *buf, int c, int from_user)
405 if ((ch != 0x11) && (ch != 0x13))
412 static int voice_cf[7] =
413 {0, 0, 4, 3, 2, 0, 0};
415 #endif /* CONFIG_ISDN_AUDIO */
417 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
418 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
419 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
420 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
423 isdn_tty_senddown(modem_info * info)
427 #ifdef CONFIG_ISDN_AUDIO
432 #ifdef CONFIG_ISDN_AUDIO
433 if (info->vonline & 4) {
435 if (!info->vonline) {
436 #ifdef ISDN_DEBUG_MODEM_VOICE
438 "senddown: send VCON on ttyI%d\n",
441 isdn_tty_at_cout("\r\nVCON\r\n", info);
445 if (!(buflen = info->xmit_count))
447 if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0)
448 info->msr &= ~UART_MSR_CTS;
449 info->lsr &= ~UART_LSR_TEMT;
450 /* info->xmit_count is modified here and in isdn_tty_write().
451 * So we return here if isdn_tty_write() is in the
454 atomic_inc(&info->xmit_lock);
455 if (!(atomic_dec_and_test(&info->xmit_lock)))
457 if (info->isdn_driver < 0) {
458 info->xmit_count = 0;
461 skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4;
462 #ifdef CONFIG_ISDN_AUDIO
463 if (info->vonline & 2)
464 audio_len = buflen * voice_cf[info->emu.vpar[3]];
467 skb = dev_alloc_skb(skb_res + buflen + audio_len);
469 skb = dev_alloc_skb(skb_res + buflen);
473 "isdn_tty: Out of memory in ttyI%d senddown\n",
477 skb_reserve(skb, skb_res);
478 memcpy(skb_put(skb, buflen), info->xmit_buf, buflen);
479 info->xmit_count = 0;
480 #ifdef CONFIG_ISDN_AUDIO
481 if (info->vonline & 2) {
482 /* For now, ifmt is fixed to 1 (alaw), since this
483 * is used with ISDN everywhere in the world, except
484 * US, Canada and Japan.
485 * Later, when US-ISDN protocols are implemented,
486 * this setting will depend on the D-channel protocol.
490 /* voice conversion/decompression */
491 switch (info->emu.vpar[3]) {
495 /* adpcm, compatible to ZyXel 1496 modem
496 * with ROM revision 6.01
498 audio_len = isdn_audio_adpcm2xlaw(info->adpcms,
501 skb_put(skb, audio_len),
503 skb_pull(skb, buflen);
504 skb_trim(skb, audio_len);
509 isdn_audio_alaw2ulaw(skb->data,
515 isdn_audio_ulaw2alaw(skb->data,
520 #endif /* CONFIG_ISDN_AUDIO */
521 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
522 /* Add T.70 simplified header */
523 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT)
524 memcpy(skb_push(skb, 2), "\1\0", 2);
526 memcpy(skb_push(skb, 4), "\1\0\1\0", 4);
528 skb_queue_tail(&info->xmit_queue, skb);
531 /************************************************************
535 * mostly "stolen" from original Linux-serial.c and friends.
537 ************************************************************/
539 /* The next routine is called once from within timer-interrupt
540 * triggered within isdn_tty_modem_ncarrier(). It calls
541 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
542 * into the tty's flip-buffer.
545 isdn_tty_modem_do_ncarrier(unsigned long data)
547 modem_info *info = (modem_info *) data;
548 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
551 /* Next routine is called, whenever the DTR-signal is raised.
552 * It checks the ncarrier-flag, and triggers the above routine
553 * when necessary. The ncarrier-flag is set, whenever DTR goes
557 isdn_tty_modem_ncarrier(modem_info * info)
559 if (info->ncarrier) {
560 info->nc_timer.expires = jiffies + HZ;
561 add_timer(&info->nc_timer);
566 * return the usage calculated by si and layer 2 protocol
569 isdn_calc_usage(int si, int l2)
571 int usg = ISDN_USAGE_MODEM;
573 #ifdef CONFIG_ISDN_AUDIO
576 case ISDN_PROTO_L2_MODEM:
577 usg = ISDN_USAGE_MODEM;
579 #ifdef CONFIG_ISDN_TTY_FAX
580 case ISDN_PROTO_L2_FAX:
581 usg = ISDN_USAGE_FAX;
584 case ISDN_PROTO_L2_TRANS:
586 usg = ISDN_USAGE_VOICE;
594 /* isdn_tty_dial() performs dialing of a tty an the necessary
595 * setup of the lower levels before that.
598 isdn_tty_dial(char *n, modem_info * info, atemu * m)
600 int usg = ISDN_USAGE_MODEM;
602 int l2 = m->mdmreg[REG_L2PROT];
608 for (j = 7; j >= 0; j--)
609 if (m->mdmreg[REG_SI1] & (1 << j)) {
613 usg = isdn_calc_usage(si, l2);
614 #ifdef CONFIG_ISDN_AUDIO
616 (l2 != ISDN_PROTO_L2_MODEM)
617 #ifdef CONFIG_ISDN_TTY_FAX
618 && (l2 != ISDN_PROTO_L2_FAX)
621 l2 = ISDN_PROTO_L2_TRANS;
622 usg = ISDN_USAGE_VOICE;
625 m->mdmreg[REG_SI1I] = si2bit[si];
626 spin_lock_irqsave(&dev->lock, flags);
627 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
629 spin_unlock_irqrestore(&dev->lock, flags);
630 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
632 info->isdn_driver = dev->drvmap[i];
633 info->isdn_channel = dev->chanmap[i];
635 dev->m_idx[i] = info->line;
636 dev->usage[i] |= ISDN_USAGE_OUTGOING;
638 strcpy(info->last_num, n);
640 spin_unlock_irqrestore(&dev->lock, flags);
641 cmd.driver = info->isdn_driver;
642 cmd.arg = info->isdn_channel;
643 cmd.command = ISDN_CMD_CLREAZ;
645 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
646 cmd.driver = info->isdn_driver;
647 cmd.command = ISDN_CMD_SETEAZ;
649 cmd.driver = info->isdn_driver;
650 cmd.command = ISDN_CMD_SETL2;
652 cmd.arg = info->isdn_channel + (l2 << 8);
654 cmd.driver = info->isdn_driver;
655 cmd.command = ISDN_CMD_SETL3;
656 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
657 #ifdef CONFIG_ISDN_TTY_FAX
658 if (l2 == ISDN_PROTO_L2_FAX) {
659 cmd.parm.fax = info->fax;
660 info->fax->direction = ISDN_TTY_FAX_CONN_OUT;
664 cmd.driver = info->isdn_driver;
665 cmd.arg = info->isdn_channel;
666 sprintf(cmd.parm.setup.phone, "%s", n);
667 sprintf(cmd.parm.setup.eazmsn, "%s",
668 isdn_map_eaz2msn(m->msn, info->isdn_driver));
669 cmd.parm.setup.si1 = si;
670 cmd.parm.setup.si2 = m->mdmreg[REG_SI2];
671 cmd.command = ISDN_CMD_DIAL;
673 info->emu.carrierwait = 0;
674 strcpy(dev->num[i], n);
677 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
681 /* isdn_tty_hangup() disassociates a tty from the real
682 * ISDN-line (hangup). The usage-status is cleared
683 * and some cleanup is done also.
686 isdn_tty_modem_hup(modem_info * info, int local)
694 di = info->isdn_driver;
695 ch = info->isdn_channel;
696 if (di < 0 || ch < 0)
699 info->isdn_driver = -1;
700 info->isdn_channel = -1;
702 #ifdef ISDN_DEBUG_MODEM_HUP
703 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
706 isdn_tty_flush_buffer(info->tty);
708 info->last_lhup = local;
710 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
712 #ifdef CONFIG_ISDN_AUDIO
714 #ifdef CONFIG_ISDN_TTY_FAX
716 info->fax->phase = ISDN_FAX_PHASE_IDLE;
718 info->emu.vpar[4] = 0;
719 info->emu.vpar[5] = 8;
720 if (info->dtmf_state) {
721 kfree(info->dtmf_state);
722 info->dtmf_state = NULL;
724 if (info->silence_state) {
725 kfree(info->silence_state);
726 info->silence_state = NULL;
737 if ((info->msr & UART_MSR_RI) &&
738 (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
739 isdn_tty_modem_result(RESULT_RUNG, info);
740 info->msr &= ~(UART_MSR_DCD | UART_MSR_RI);
741 info->lsr |= UART_LSR_TEMT;
745 cmd.command = ISDN_CMD_HANGUP;
750 isdn_all_eaz(di, ch);
751 info->emu.mdmreg[REG_RINGCNT] = 0;
752 isdn_free_channel(di, ch, 0);
754 if (info->drv_index >= 0) {
755 dev->m_idx[info->drv_index] = -1;
756 info->drv_index = -1;
761 * Begin of a CAPI like interface, currently used only for
762 * supplementary service (CAPI 2.0 part III)
764 #include <linux/isdn/capicmd.h>
767 isdn_tty_capi_facility(capi_msg *cm) {
768 return(-1); /* dummy */
771 /* isdn_tty_suspend() tries to suspend the current tty connection
774 isdn_tty_suspend(char *id, modem_info * info, atemu * m)
783 #ifdef ISDN_DEBUG_MODEM_SERVICES
784 printk(KERN_DEBUG "Msusp ttyI%d\n", info->line);
787 if ((info->isdn_driver >= 0)) {
788 cmd.parm.cmsg.Length = l+18;
789 cmd.parm.cmsg.Command = CAPI_FACILITY;
790 cmd.parm.cmsg.Subcommand = CAPI_REQ;
791 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
792 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
793 cmd.parm.cmsg.para[1] = 0;
794 cmd.parm.cmsg.para[2] = l + 3;
795 cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
796 cmd.parm.cmsg.para[4] = 0;
797 cmd.parm.cmsg.para[5] = l;
798 strncpy(&cmd.parm.cmsg.para[6], id, l);
799 cmd.command = CAPI_PUT_MESSAGE;
800 cmd.driver = info->isdn_driver;
801 cmd.arg = info->isdn_channel;
806 /* isdn_tty_resume() tries to resume a suspended call
807 * setup of the lower levels before that. unfortunatly here is no
808 * checking for compatibility of used protocols implemented by Q931
809 * It does the same things like isdn_tty_dial, the last command
810 * is different, may be we can merge it.
814 isdn_tty_resume(char *id, modem_info * info, atemu * m)
816 int usg = ISDN_USAGE_MODEM;
818 int l2 = m->mdmreg[REG_L2PROT];
826 for (j = 7; j >= 0; j--)
827 if (m->mdmreg[REG_SI1] & (1 << j)) {
831 usg = isdn_calc_usage(si, l2);
832 #ifdef CONFIG_ISDN_AUDIO
834 (l2 != ISDN_PROTO_L2_MODEM)
835 #ifdef CONFIG_ISDN_TTY_FAX
836 && (l2 != ISDN_PROTO_L2_FAX)
839 l2 = ISDN_PROTO_L2_TRANS;
840 usg = ISDN_USAGE_VOICE;
843 m->mdmreg[REG_SI1I] = si2bit[si];
844 spin_lock_irqsave(&dev->lock, flags);
845 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
847 spin_unlock_irqrestore(&dev->lock, flags);
848 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
850 info->isdn_driver = dev->drvmap[i];
851 info->isdn_channel = dev->chanmap[i];
853 dev->m_idx[i] = info->line;
854 dev->usage[i] |= ISDN_USAGE_OUTGOING;
856 // strcpy(info->last_num, n);
858 spin_unlock_irqrestore(&dev->lock, flags);
859 cmd.driver = info->isdn_driver;
860 cmd.arg = info->isdn_channel;
861 cmd.command = ISDN_CMD_CLREAZ;
863 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
864 cmd.driver = info->isdn_driver;
865 cmd.command = ISDN_CMD_SETEAZ;
867 cmd.driver = info->isdn_driver;
868 cmd.command = ISDN_CMD_SETL2;
870 cmd.arg = info->isdn_channel + (l2 << 8);
872 cmd.driver = info->isdn_driver;
873 cmd.command = ISDN_CMD_SETL3;
874 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
876 cmd.driver = info->isdn_driver;
877 cmd.arg = info->isdn_channel;
878 cmd.parm.cmsg.Length = l+18;
879 cmd.parm.cmsg.Command = CAPI_FACILITY;
880 cmd.parm.cmsg.Subcommand = CAPI_REQ;
881 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
882 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
883 cmd.parm.cmsg.para[1] = 0;
884 cmd.parm.cmsg.para[2] = l+3;
885 cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
886 cmd.parm.cmsg.para[4] = 0;
887 cmd.parm.cmsg.para[5] = l;
888 strncpy(&cmd.parm.cmsg.para[6], id, l);
889 cmd.command =CAPI_PUT_MESSAGE;
891 // strcpy(dev->num[i], n);
894 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
898 /* isdn_tty_send_msg() sends a message to a HL driver
899 * This is used for hybrid modem cards to send AT commands to it
903 isdn_tty_send_msg(modem_info * info, atemu * m, char *msg)
905 int usg = ISDN_USAGE_MODEM;
907 int l2 = m->mdmreg[REG_L2PROT];
916 isdn_tty_modem_result(RESULT_ERROR, info);
919 for (j = 7; j >= 0; j--)
920 if (m->mdmreg[REG_SI1] & (1 << j)) {
924 usg = isdn_calc_usage(si, l2);
925 #ifdef CONFIG_ISDN_AUDIO
927 (l2 != ISDN_PROTO_L2_MODEM)
928 #ifdef CONFIG_ISDN_TTY_FAX
929 && (l2 != ISDN_PROTO_L2_FAX)
932 l2 = ISDN_PROTO_L2_TRANS;
933 usg = ISDN_USAGE_VOICE;
936 m->mdmreg[REG_SI1I] = si2bit[si];
937 spin_lock_irqsave(&dev->lock, flags);
938 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
940 spin_unlock_irqrestore(&dev->lock, flags);
941 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
943 info->isdn_driver = dev->drvmap[i];
944 info->isdn_channel = dev->chanmap[i];
946 dev->m_idx[i] = info->line;
947 dev->usage[i] |= ISDN_USAGE_OUTGOING;
950 spin_unlock_irqrestore(&dev->lock, flags);
951 cmd.driver = info->isdn_driver;
952 cmd.arg = info->isdn_channel;
953 cmd.command = ISDN_CMD_CLREAZ;
955 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
956 cmd.driver = info->isdn_driver;
957 cmd.command = ISDN_CMD_SETEAZ;
959 cmd.driver = info->isdn_driver;
960 cmd.command = ISDN_CMD_SETL2;
962 cmd.arg = info->isdn_channel + (l2 << 8);
964 cmd.driver = info->isdn_driver;
965 cmd.command = ISDN_CMD_SETL3;
966 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
968 cmd.driver = info->isdn_driver;
969 cmd.arg = info->isdn_channel;
970 cmd.parm.cmsg.Length = l+14;
971 cmd.parm.cmsg.Command = CAPI_MANUFACTURER;
972 cmd.parm.cmsg.Subcommand = CAPI_REQ;
973 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
974 cmd.parm.cmsg.para[0] = l+1;
975 strncpy(&cmd.parm.cmsg.para[1], msg, l);
976 cmd.parm.cmsg.para[l+1] = 0xd;
977 cmd.command =CAPI_PUT_MESSAGE;
978 /* info->dialing = 1;
979 strcpy(dev->num[i], n);
987 isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine)
989 #ifdef MODEM_PARANOIA_CHECK
991 printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n",
995 if (info->magic != ISDN_ASYNC_MAGIC) {
996 printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n",
1005 * This routine is called to set the UART divisor registers to match
1006 * the specified baud rate for a serial port.
1009 isdn_tty_change_speed(modem_info * info)
1017 if (!info->tty || !info->tty->termios)
1019 cflag = info->tty->termios->c_cflag;
1021 quot = i = cflag & CBAUD;
1025 info->tty->termios->c_cflag &= ~CBAUDEX;
1030 info->mcr |= UART_MCR_DTR;
1031 isdn_tty_modem_ncarrier(info);
1033 info->mcr &= ~UART_MCR_DTR;
1034 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1035 #ifdef ISDN_DEBUG_MODEM_HUP
1036 printk(KERN_DEBUG "Mhup in changespeed\n");
1040 isdn_tty_modem_reset_regs(info, 0);
1041 isdn_tty_modem_hup(info, 1);
1045 /* byte size and parity */
1046 cval = cflag & (CSIZE | CSTOPB);
1049 cval |= UART_LCR_PARITY;
1050 if (!(cflag & PARODD))
1051 cval |= UART_LCR_EPAR;
1054 /* CTS flow control flag and modem status interrupts */
1055 if (cflag & CRTSCTS) {
1056 info->flags |= ISDN_ASYNC_CTS_FLOW;
1058 info->flags &= ~ISDN_ASYNC_CTS_FLOW;
1060 info->flags &= ~ISDN_ASYNC_CHECK_CD;
1062 info->flags |= ISDN_ASYNC_CHECK_CD;
1067 isdn_tty_startup(modem_info * info)
1069 if (info->flags & ISDN_ASYNC_INITIALIZED)
1071 isdn_lock_drivers();
1072 #ifdef ISDN_DEBUG_MODEM_OPEN
1073 printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line);
1076 * Now, initialize the UART
1078 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
1080 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1082 * and set the speed of the serial port
1084 isdn_tty_change_speed(info);
1086 info->flags |= ISDN_ASYNC_INITIALIZED;
1087 info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
1088 info->send_outstanding = 0;
1093 * This routine will shutdown a serial port; interrupts are disabled, and
1094 * DTR is dropped if the hangup on close termio flag is on.
1097 isdn_tty_shutdown(modem_info * info)
1099 if (!(info->flags & ISDN_ASYNC_INITIALIZED))
1101 #ifdef ISDN_DEBUG_MODEM_OPEN
1102 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
1104 isdn_unlock_drivers();
1105 info->msr &= ~UART_MSR_RI;
1106 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1107 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
1108 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1109 isdn_tty_modem_reset_regs(info, 0);
1110 #ifdef ISDN_DEBUG_MODEM_HUP
1111 printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n");
1113 isdn_tty_modem_hup(info, 1);
1117 set_bit(TTY_IO_ERROR, &info->tty->flags);
1119 info->flags &= ~ISDN_ASYNC_INITIALIZED;
1122 /* isdn_tty_write() is the main send-routine. It is called from the upper
1123 * levels within the kernel to perform sending data. Depending on the
1124 * online-flag it either directs output to the at-command-interpreter or
1125 * to the lower level. Additional tasks done here:
1126 * - If online, check for escape-sequence (+++)
1127 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1128 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1129 * - If dialing, abort dial.
1132 isdn_tty_write(struct tty_struct *tty, int from_user, const u_char * buf, int count)
1136 modem_info *info = (modem_info *) tty->driver_data;
1137 atemu *m = &info->emu;
1139 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write"))
1142 down(&info->write_sem);
1143 /* See isdn_tty_senddown() */
1144 atomic_inc(&info->xmit_lock);
1147 if (c > info->xmit_size - info->xmit_count)
1148 c = info->xmit_size - info->xmit_count;
1149 if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize)
1150 c = dev->drv[info->isdn_driver]->maxbufsize;
1153 if ((info->online > 1)
1154 #ifdef CONFIG_ISDN_AUDIO
1155 || (info->vonline & 3)
1158 #ifdef CONFIG_ISDN_AUDIO
1161 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
1166 copy_from_user(&(info->xmit_buf[info->xmit_count]), buf, c);
1168 memcpy(&(info->xmit_buf[info->xmit_count]), buf, c);
1169 #ifdef CONFIG_ISDN_AUDIO
1170 if (info->vonline) {
1171 int cc = isdn_tty_handleDLEdown(info, m, c);
1172 if (info->vonline & 2) {
1174 /* If DLE decoding results in zero-transmit, but
1175 * c originally was non-zero, do a wakeup.
1177 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1178 tty->ldisc.write_wakeup)
1179 (tty->ldisc.write_wakeup) (tty);
1180 wake_up_interruptible(&tty->write_wait);
1181 info->msr |= UART_MSR_CTS;
1182 info->lsr |= UART_LSR_TEMT;
1184 info->xmit_count += cc;
1186 if ((info->vonline & 3) == 1) {
1187 /* Do NOT handle Ctrl-Q or Ctrl-S
1188 * when in full-duplex audio mode.
1190 if (isdn_tty_end_vrx(buf, c, from_user)) {
1191 info->vonline &= ~1;
1192 #ifdef ISDN_DEBUG_MODEM_VOICE
1194 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1197 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
1201 if (TTY_IS_FCLASS1(info)) {
1202 int cc = isdn_tty_handleDLEdown(info, m, c);
1204 if (info->vonline & 4) { /* ETX seen */
1207 c.command = ISDN_CMD_FAXCMD;
1208 c.driver = info->isdn_driver;
1209 c.arg = info->isdn_channel;
1210 c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
1211 c.parm.aux.subcmd = ETX;
1215 #ifdef ISDN_DEBUG_MODEM_VOICE
1216 printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c);
1218 info->xmit_count += cc;
1221 info->xmit_count += c;
1223 info->msr |= UART_MSR_CTS;
1224 info->lsr |= UART_LSR_TEMT;
1225 if (info->dialing) {
1227 #ifdef ISDN_DEBUG_MODEM_HUP
1228 printk(KERN_DEBUG "Mhup in isdn_tty_write\n");
1230 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
1231 isdn_tty_modem_hup(info, 1);
1233 c = isdn_tty_edit_at(buf, c, info, from_user);
1239 atomic_dec(&info->xmit_lock);
1240 if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue))) {
1241 if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
1242 isdn_tty_senddown(info);
1243 isdn_tty_tint(info);
1245 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1248 up(&info->write_sem);
1253 isdn_tty_write_room(struct tty_struct *tty)
1255 modem_info *info = (modem_info *) tty->driver_data;
1258 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room"))
1261 return info->xmit_size;
1262 ret = info->xmit_size - info->xmit_count;
1263 return (ret < 0) ? 0 : ret;
1267 isdn_tty_chars_in_buffer(struct tty_struct *tty)
1269 modem_info *info = (modem_info *) tty->driver_data;
1271 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer"))
1275 return (info->xmit_count);
1279 isdn_tty_flush_buffer(struct tty_struct *tty)
1286 info = (modem_info *) tty->driver_data;
1287 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) {
1290 isdn_tty_cleanup_xmit(info);
1291 info->xmit_count = 0;
1292 wake_up_interruptible(&tty->write_wait);
1293 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1294 tty->ldisc.write_wakeup)
1295 (tty->ldisc.write_wakeup) (tty);
1299 isdn_tty_flush_chars(struct tty_struct *tty)
1301 modem_info *info = (modem_info *) tty->driver_data;
1303 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars"))
1305 if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue)))
1306 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1310 * ------------------------------------------------------------
1311 * isdn_tty_throttle()
1313 * This routine is called by the upper-layer tty layer to signal that
1314 * incoming characters should be throttled.
1315 * ------------------------------------------------------------
1318 isdn_tty_throttle(struct tty_struct *tty)
1320 modem_info *info = (modem_info *) tty->driver_data;
1322 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle"))
1325 info->x_char = STOP_CHAR(tty);
1326 info->mcr &= ~UART_MCR_RTS;
1330 isdn_tty_unthrottle(struct tty_struct *tty)
1332 modem_info *info = (modem_info *) tty->driver_data;
1334 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle"))
1340 info->x_char = START_CHAR(tty);
1342 info->mcr |= UART_MCR_RTS;
1346 * ------------------------------------------------------------
1347 * isdn_tty_ioctl() and friends
1348 * ------------------------------------------------------------
1352 * isdn_tty_get_lsr_info - get line status register info
1354 * Purpose: Let user call ioctl() to get info when the UART physically
1355 * is emptied. On bus types like RS485, the transmitter must
1356 * release the bus after transmitting. This must be done when
1357 * the transmit shift register is empty, not be done when the
1358 * transmit holding register is empty. This functionality
1359 * allows RS485 driver to be written in user space.
1362 isdn_tty_get_lsr_info(modem_info * info, uint __user * value)
1368 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1369 return put_user(result, value);
1374 isdn_tty_tiocmget(struct tty_struct *tty, struct file *file)
1376 modem_info *info = (modem_info *) tty->driver_data;
1377 u_char control, status;
1379 if (isdn_tty_paranoia_check(info, tty->name, __FUNCTION__))
1381 if (tty->flags & (1 << TTY_IO_ERROR))
1384 #ifdef ISDN_DEBUG_MODEM_IOCTL
1385 printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
1388 control = info->mcr;
1390 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1391 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1392 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1393 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1394 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1395 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1399 isdn_tty_tiocmset(struct tty_struct *tty, struct file *file,
1400 unsigned int set, unsigned int clear)
1402 modem_info *info = (modem_info *) tty->driver_data;
1404 if (isdn_tty_paranoia_check(info, tty->name, __FUNCTION__))
1406 if (tty->flags & (1 << TTY_IO_ERROR))
1409 #ifdef ISDN_DEBUG_MODEM_IOCTL
1410 printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear);
1413 if (set & TIOCM_RTS)
1414 info->mcr |= UART_MCR_RTS;
1415 if (set & TIOCM_DTR) {
1416 info->mcr |= UART_MCR_DTR;
1417 isdn_tty_modem_ncarrier(info);
1420 if (clear & TIOCM_RTS)
1421 info->mcr &= ~UART_MCR_RTS;
1422 if (clear & TIOCM_DTR) {
1423 info->mcr &= ~UART_MCR_DTR;
1424 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1425 isdn_tty_modem_reset_regs(info, 0);
1426 #ifdef ISDN_DEBUG_MODEM_HUP
1427 printk(KERN_DEBUG "Mhup in TIOCMSET\n");
1431 isdn_tty_modem_hup(info, 1);
1438 isdn_tty_ioctl(struct tty_struct *tty, struct file *file,
1439 uint cmd, ulong arg)
1441 modem_info *info = (modem_info *) tty->driver_data;
1444 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl"))
1446 if (tty->flags & (1 << TTY_IO_ERROR))
1449 case TCSBRK: /* SVID version: non-zero arg --> no break */
1450 #ifdef ISDN_DEBUG_MODEM_IOCTL
1451 printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line);
1453 retval = tty_check_change(tty);
1456 tty_wait_until_sent(tty, 0);
1458 case TCSBRKP: /* support for POSIX tcsendbreak() */
1459 #ifdef ISDN_DEBUG_MODEM_IOCTL
1460 printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line);
1462 retval = tty_check_change(tty);
1465 tty_wait_until_sent(tty, 0);
1468 #ifdef ISDN_DEBUG_MODEM_IOCTL
1469 printk(KERN_DEBUG "ttyI%d ioctl TIOCGSOFTCAR\n", info->line);
1471 return put_user(C_CLOCAL(tty) ? 1 : 0, (ulong __user *) arg);
1473 #ifdef ISDN_DEBUG_MODEM_IOCTL
1474 printk(KERN_DEBUG "ttyI%d ioctl TIOCSSOFTCAR\n", info->line);
1476 if (get_user(arg, (ulong __user *) arg))
1478 tty->termios->c_cflag =
1479 ((tty->termios->c_cflag & ~CLOCAL) |
1480 (arg ? CLOCAL : 0));
1482 case TIOCSERGETLSR: /* Get line status register */
1483 #ifdef ISDN_DEBUG_MODEM_IOCTL
1484 printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);
1486 return isdn_tty_get_lsr_info(info, (uint __user *) arg);
1488 #ifdef ISDN_DEBUG_MODEM_IOCTL
1489 printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line);
1491 return -ENOIOCTLCMD;
1497 isdn_tty_set_termios(struct tty_struct *tty, struct termios *old_termios)
1499 modem_info *info = (modem_info *) tty->driver_data;
1502 isdn_tty_change_speed(info);
1504 if (tty->termios->c_cflag == old_termios->c_cflag)
1506 isdn_tty_change_speed(info);
1507 if ((old_termios->c_cflag & CRTSCTS) &&
1508 !(tty->termios->c_cflag & CRTSCTS)) {
1509 tty->hw_stopped = 0;
1515 * ------------------------------------------------------------
1516 * isdn_tty_open() and friends
1517 * ------------------------------------------------------------
1520 isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info * info)
1522 DECLARE_WAITQUEUE(wait, NULL);
1527 * If the device is in the middle of being closed, then block
1528 * until it's done, and then try again.
1530 if (tty_hung_up_p(filp) ||
1531 (info->flags & ISDN_ASYNC_CLOSING)) {
1532 if (info->flags & ISDN_ASYNC_CLOSING)
1533 interruptible_sleep_on(&info->close_wait);
1534 #ifdef MODEM_DO_RESTART
1535 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1538 return -ERESTARTSYS;
1544 * If non-blocking mode is set, then make the check up front
1547 if ((filp->f_flags & O_NONBLOCK) ||
1548 (tty->flags & (1 << TTY_IO_ERROR))) {
1549 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1551 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1554 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) {
1555 if (info->normal_termios.c_cflag & CLOCAL)
1558 if (tty->termios->c_cflag & CLOCAL)
1562 * Block waiting for the carrier detect and the line to become
1563 * free (i.e., not in use by the callout). While we are in
1564 * this loop, info->count is dropped by one, so that
1565 * isdn_tty_close() knows when to free things. We restore it upon
1566 * exit, either normal or abnormal.
1569 add_wait_queue(&info->open_wait, &wait);
1570 #ifdef ISDN_DEBUG_MODEM_OPEN
1571 printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1572 info->line, info->count);
1574 if (!(tty_hung_up_p(filp)))
1576 info->blocked_open++;
1578 set_current_state(TASK_INTERRUPTIBLE);
1579 if (tty_hung_up_p(filp) ||
1580 !(info->flags & ISDN_ASYNC_INITIALIZED)) {
1581 #ifdef MODEM_DO_RESTART
1582 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1585 retval = -ERESTARTSYS;
1591 if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
1592 !(info->flags & ISDN_ASYNC_CLOSING) &&
1593 (do_clocal || (info->msr & UART_MSR_DCD))) {
1596 if (signal_pending(current)) {
1597 retval = -ERESTARTSYS;
1600 #ifdef ISDN_DEBUG_MODEM_OPEN
1601 printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1602 info->line, info->count);
1606 current->state = TASK_RUNNING;
1607 remove_wait_queue(&info->open_wait, &wait);
1608 if (!tty_hung_up_p(filp))
1610 info->blocked_open--;
1611 #ifdef ISDN_DEBUG_MODEM_OPEN
1612 printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1613 info->line, info->count);
1617 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1622 * This routine is called whenever a serial port is opened. It
1623 * enables interrupts for a serial port, linking in its async structure into
1624 * the IRQ chain. It also performs the serial-specific
1625 * initialization for the tty structure.
1628 isdn_tty_open(struct tty_struct *tty, struct file *filp)
1634 if (line < 0 || line > ISDN_MAX_CHANNELS)
1636 info = &dev->mdm.info[line];
1637 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))
1639 if (!try_module_get(info->owner)) {
1640 printk(KERN_WARNING "%s: cannot reserve module\n", __FUNCTION__);
1643 #ifdef ISDN_DEBUG_MODEM_OPEN
1644 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
1648 tty->driver_data = info;
1651 * Start up serial port
1653 retval = isdn_tty_startup(info);
1655 #ifdef ISDN_DEBUG_MODEM_OPEN
1656 printk(KERN_DEBUG "isdn_tty_open return after startup\n");
1658 module_put(info->owner);
1661 retval = isdn_tty_block_til_ready(tty, filp, info);
1663 #ifdef ISDN_DEBUG_MODEM_OPEN
1664 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");
1666 module_put(info->owner);
1669 #ifdef ISDN_DEBUG_MODEM_OPEN
1670 printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line);
1673 #ifdef ISDN_DEBUG_MODEM_OPEN
1674 printk(KERN_DEBUG "isdn_tty_open normal exit\n");
1680 isdn_tty_close(struct tty_struct *tty, struct file *filp)
1682 modem_info *info = (modem_info *) tty->driver_data;
1685 if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close"))
1687 if (tty_hung_up_p(filp)) {
1688 #ifdef ISDN_DEBUG_MODEM_OPEN
1689 printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n");
1693 if ((tty->count == 1) && (info->count != 1)) {
1695 * Uh, oh. tty->count is 1, which means that the tty
1696 * structure will be freed. Info->count should always
1697 * be one in these conditions. If it's greater than
1698 * one, we've got real problems, since it means the
1699 * serial port won't be shutdown.
1701 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
1702 "info->count is %d\n", info->count);
1705 if (--info->count < 0) {
1706 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
1707 info->line, info->count);
1711 #ifdef ISDN_DEBUG_MODEM_OPEN
1712 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
1716 info->flags |= ISDN_ASYNC_CLOSING;
1718 * Save the termios structure, since this port may have
1719 * separate termios for callout and dialin.
1721 if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)
1722 info->normal_termios = *tty->termios;
1723 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1724 info->callout_termios = *tty->termios;
1728 * At this point we stop accepting input. To do this, we
1729 * disable the receive line status interrupts, and tell the
1730 * interrupt driver to stop checking the data ready bit in the
1731 * line status register.
1733 if (info->flags & ISDN_ASYNC_INITIALIZED) {
1734 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1736 * Before we drop DTR, make sure the UART transmitter
1737 * has completely drained; this is especially
1738 * important if there is a transmit FIFO!
1740 timeout = jiffies + HZ;
1741 while (!(info->lsr & UART_LSR_TEMT)) {
1742 set_current_state(TASK_INTERRUPTIBLE);
1743 schedule_timeout(20);
1744 if (time_after(jiffies,timeout))
1749 isdn_tty_shutdown(info);
1750 if (tty->driver->flush_buffer)
1751 tty->driver->flush_buffer(tty);
1752 if (tty->ldisc.flush_buffer)
1753 tty->ldisc.flush_buffer(tty);
1757 module_put(info->owner);
1758 if (info->blocked_open) {
1759 set_current_state(TASK_INTERRUPTIBLE);
1760 schedule_timeout(HZ/2);
1761 wake_up_interruptible(&info->open_wait);
1763 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CLOSING);
1764 wake_up_interruptible(&info->close_wait);
1765 #ifdef ISDN_DEBUG_MODEM_OPEN
1766 printk(KERN_DEBUG "isdn_tty_close normal exit\n");
1771 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1774 isdn_tty_hangup(struct tty_struct *tty)
1776 modem_info *info = (modem_info *) tty->driver_data;
1778 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
1780 isdn_tty_shutdown(info);
1782 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE);
1784 wake_up_interruptible(&info->open_wait);
1787 /* This routine initializes all emulator-data.
1790 isdn_tty_reset_profile(atemu * m)
1803 m->profile[11] = 70;
1804 m->profile[12] = 0x45;
1806 m->profile[14] = ISDN_PROTO_L2_X75I;
1807 m->profile[15] = ISDN_PROTO_L3_TRANS;
1808 m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16;
1809 m->profile[17] = ISDN_MODEM_WINSIZE;
1818 #ifdef CONFIG_ISDN_AUDIO
1820 isdn_tty_modem_reset_vpar(atemu * m)
1822 m->vpar[0] = 2; /* Voice-device (2 = phone line) */
1823 m->vpar[1] = 0; /* Silence detection level (0 = none ) */
1824 m->vpar[2] = 70; /* Silence interval (7 sec. ) */
1825 m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1826 m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */
1827 m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1831 #ifdef CONFIG_ISDN_TTY_FAX
1833 isdn_tty_modem_reset_faxpar(modem_info * info)
1835 T30_s *f = info->fax;
1838 f->phase = ISDN_FAX_PHASE_IDLE;
1840 f->resolution = 1; /* fine */
1841 f->rate = 5; /* 14400 bit/s */
1848 memset(&f->id[0], 32, FAXIDLEN - 1);
1849 f->id[FAXIDLEN - 1] = 0;
1860 memset(&f->pollid[0], 32, FAXIDLEN - 1);
1861 f->pollid[FAXIDLEN - 1] = 0;
1866 isdn_tty_modem_reset_regs(modem_info * info, int force)
1868 atemu *m = &info->emu;
1869 if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {
1870 memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);
1871 memcpy(m->msn, m->pmsn, ISDN_MSNLEN);
1872 memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);
1873 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
1875 #ifdef CONFIG_ISDN_AUDIO
1876 isdn_tty_modem_reset_vpar(m);
1878 #ifdef CONFIG_ISDN_TTY_FAX
1879 isdn_tty_modem_reset_faxpar(info);
1885 modem_write_profile(atemu * m)
1887 memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG);
1888 memcpy(m->pmsn, m->msn, ISDN_MSNLEN);
1889 memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN);
1891 send_sig(SIGIO, dev->profd, 1);
1894 static struct tty_operations modem_ops = {
1895 .open = isdn_tty_open,
1896 .close = isdn_tty_close,
1897 .write = isdn_tty_write,
1898 .flush_chars = isdn_tty_flush_chars,
1899 .write_room = isdn_tty_write_room,
1900 .chars_in_buffer = isdn_tty_chars_in_buffer,
1901 .flush_buffer = isdn_tty_flush_buffer,
1902 .ioctl = isdn_tty_ioctl,
1903 .throttle = isdn_tty_throttle,
1904 .unthrottle = isdn_tty_unthrottle,
1905 .set_termios = isdn_tty_set_termios,
1906 .hangup = isdn_tty_hangup,
1907 .tiocmget = isdn_tty_tiocmget,
1908 .tiocmset = isdn_tty_tiocmset,
1912 isdn_tty_modem_init(void)
1919 m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS);
1922 m->tty_modem->name = "ttyI";
1923 m->tty_modem->devfs_name = "isdn/ttyI";
1924 m->tty_modem->major = ISDN_TTY_MAJOR;
1925 m->tty_modem->minor_start = 0;
1926 m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL;
1927 m->tty_modem->subtype = SERIAL_TYPE_NORMAL;
1928 m->tty_modem->init_termios = tty_std_termios;
1929 m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1930 m->tty_modem->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
1931 m->tty_modem->driver_name = "isdn_tty";
1932 tty_set_operations(m->tty_modem, &modem_ops);
1933 retval = tty_register_driver(m->tty_modem);
1935 printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n");
1938 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1940 #ifdef CONFIG_ISDN_TTY_FAX
1941 if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) {
1942 printk(KERN_ERR "Could not allocate fax t30-buffer\n");
1944 goto err_unregister;
1948 info->owner = THIS_MODULE;
1950 spin_lock_init(&info->readlock);
1951 init_MUTEX(&info->write_sem);
1952 sprintf(info->last_cause, "0000");
1953 sprintf(info->last_num, "none");
1955 info->last_lhup = 1;
1958 isdn_tty_reset_profile(&info->emu);
1959 isdn_tty_modem_reset_regs(info, 1);
1960 info->magic = ISDN_ASYNC_MAGIC;
1965 info->blocked_open = 0;
1966 init_waitqueue_head(&info->open_wait);
1967 init_waitqueue_head(&info->close_wait);
1968 info->isdn_driver = -1;
1969 info->isdn_channel = -1;
1970 info->drv_index = -1;
1971 info->xmit_size = ISDN_SERIAL_XMIT_SIZE;
1972 init_timer(&info->nc_timer);
1973 info->nc_timer.function = isdn_tty_modem_do_ncarrier;
1974 info->nc_timer.data = (unsigned long) info;
1975 skb_queue_head_init(&info->xmit_queue);
1976 #ifdef CONFIG_ISDN_AUDIO
1977 skb_queue_head_init(&info->dtmf_queue);
1979 if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) {
1980 printk(KERN_ERR "Could not allocate modem xmit-buffer\n");
1982 goto err_unregister;
1984 /* Make room for T.70 header */
1985 info->xmit_buf += 4;
1989 for (i--; i >= 0; i--) {
1991 #ifdef CONFIG_ISDN_TTY_FAX
1994 kfree(info->xmit_buf - 4);
1996 tty_unregister_driver(m->tty_modem);
1998 put_tty_driver(m->tty_modem);
1999 m->tty_modem = NULL;
2009 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2010 info = &dev->mdm.info[i];
2011 isdn_tty_cleanup_xmit(info);
2012 #ifdef CONFIG_ISDN_TTY_FAX
2015 kfree(info->xmit_buf - 4);
2017 tty_unregister_driver(dev->mdm.tty_modem);
2018 put_tty_driver(dev->mdm.tty_modem);
2019 dev->mdm.tty_modem = NULL;
2024 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
2025 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
2026 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
2030 isdn_tty_match_icall(char *cid, atemu *emu, int di)
2032 #ifdef ISDN_DEBUG_MODEM_ICALL
2033 printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
2034 emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di),
2035 emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]);
2037 if (strlen(emu->lmsn)) {
2038 char *p = emu->lmsn;
2044 if ((q = strchr(p, ';')))
2046 if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret)
2048 #ifdef ISDN_DEBUG_MODEM_ICALL
2049 printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2050 p, isdn_map_eaz2msn(emu->msn, di), tmp);
2065 tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di));
2066 #ifdef ISDN_DEBUG_MODEM_ICALL
2067 printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n",
2068 isdn_map_eaz2msn(emu->msn, di), tmp);
2075 * An incoming call-request has arrived.
2076 * Search the tty-devices for an appropriate device and bind
2077 * it to the ISDN-Channel.
2080 * 0 = No matching device found.
2081 * 1 = A matching device found.
2082 * 3 = No match found, but eventually would match, if
2086 isdn_tty_find_icall(int di, int ch, setup_parm *setup)
2097 if (!setup->phone[0]) {
2099 printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n");
2102 si1 = (int) setup->si1;
2103 si2 = (int) setup->si2;
2104 if (!setup->eazmsn[0]) {
2105 printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n");
2108 eaz = setup->eazmsn;
2109 #ifdef ISDN_DEBUG_MODEM_ICALL
2110 printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2);
2113 spin_lock_irqsave(&dev->lock, flags);
2114 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2115 modem_info *info = &dev->mdm.info[i];
2117 if (info->count == 0)
2119 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
2120 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
2121 idx = isdn_dc2minor(di, ch);
2122 #ifdef ISDN_DEBUG_MODEM_ICALL
2123 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret);
2124 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx,
2125 info->flags, info->isdn_driver, info->isdn_channel,
2129 #ifndef FIX_FILE_TRANSFER
2130 (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) &&
2132 (info->isdn_driver == -1) &&
2133 (info->isdn_channel == -1) &&
2134 (USG_NONE(dev->usage[idx]))) {
2137 if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret)
2139 if (!matchret) { /* EAZ is matching */
2140 info->isdn_driver = di;
2141 info->isdn_channel = ch;
2142 info->drv_index = idx;
2143 dev->m_idx[idx] = info->line;
2144 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2145 dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]);
2146 strcpy(dev->num[idx], nr);
2147 strcpy(info->emu.cpn, eaz);
2148 info->emu.mdmreg[REG_SI1I] = si2bit[si1];
2149 info->emu.mdmreg[REG_PLAN] = setup->plan;
2150 info->emu.mdmreg[REG_SCREEN] = setup->screen;
2152 spin_unlock_irqrestore(&dev->lock, flags);
2153 printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr,
2155 info->msr |= UART_MSR_RI;
2156 isdn_tty_modem_result(RESULT_RING, info);
2157 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1);
2163 spin_unlock_irqrestore(&dev->lock, flags);
2164 printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz,
2165 ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2))? "rejected" : "ignored");
2166 return (wret == 2)?3:0;
2169 #define TTY_IS_ACTIVE(info) \
2170 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2173 isdn_tty_stat_callback(int i, isdn_ctrl *c)
2181 if ((mi = dev->m_idx[i]) >= 0) {
2182 info = &dev->mdm.info[mi];
2183 switch (c->command) {
2184 case ISDN_STAT_CINF:
2185 printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num);
2186 info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10);
2187 if (e == (char *)c->parm.num)
2188 info->emu.charge = 0;
2191 case ISDN_STAT_BSENT:
2192 #ifdef ISDN_TTY_STAT_DEBUG
2193 printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line);
2195 if ((info->isdn_driver == c->driver) &&
2196 (info->isdn_channel == c->arg)) {
2197 info->msr |= UART_MSR_CTS;
2198 if (info->send_outstanding)
2199 if (!(--info->send_outstanding))
2200 info->lsr |= UART_LSR_TEMT;
2201 isdn_tty_tint(info);
2205 case ISDN_STAT_CAUSE:
2206 #ifdef ISDN_TTY_STAT_DEBUG
2207 printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line);
2209 /* Signal cause to tty-device */
2210 strncpy(info->last_cause, c->parm.num, 5);
2212 case ISDN_STAT_DISPLAY:
2213 #ifdef ISDN_TTY_STAT_DEBUG
2214 printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line);
2216 /* Signal display to tty-device */
2217 if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) &&
2218 !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) {
2219 isdn_tty_at_cout("\r\n", info);
2220 isdn_tty_at_cout("DISPLAY: ", info);
2221 isdn_tty_at_cout(c->parm.display, info);
2222 isdn_tty_at_cout("\r\n", info);
2225 case ISDN_STAT_DCONN:
2226 #ifdef ISDN_TTY_STAT_DEBUG
2227 printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line);
2229 if (TTY_IS_ACTIVE(info)) {
2230 if (info->dialing == 1) {
2236 case ISDN_STAT_DHUP:
2237 #ifdef ISDN_TTY_STAT_DEBUG
2238 printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
2240 if (TTY_IS_ACTIVE(info)) {
2241 if (info->dialing == 1)
2242 isdn_tty_modem_result(RESULT_BUSY, info);
2243 if (info->dialing > 1)
2244 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
2246 #ifdef ISDN_DEBUG_MODEM_HUP
2247 printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n");
2249 isdn_tty_modem_hup(info, 0);
2253 case ISDN_STAT_BCONN:
2254 #ifdef ISDN_TTY_STAT_DEBUG
2255 printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line);
2257 /* Wake up any processes waiting
2258 * for incoming call of this device when
2259 * DCD follow the state of incoming carrier
2261 if (info->blocked_open &&
2262 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) {
2263 wake_up_interruptible(&info->open_wait);
2266 /* Schedule CONNECT-Message to any tty
2267 * waiting for it and
2268 * set DCD-bit of its modem-status.
2270 if (TTY_IS_ACTIVE(info) ||
2271 (info->blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
2272 info->msr |= UART_MSR_DCD;
2273 info->emu.charge = 0;
2274 if (info->dialing & 0xf)
2280 if (USG_MODEM(dev->usage[i])) {
2281 if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) {
2282 strcpy(info->emu.connmsg, c->parm.num);
2283 isdn_tty_modem_result(RESULT_CONNECT, info);
2285 isdn_tty_modem_result(RESULT_CONNECT64000, info);
2287 if (USG_VOICE(dev->usage[i]))
2288 isdn_tty_modem_result(RESULT_VCON, info);
2292 case ISDN_STAT_BHUP:
2293 #ifdef ISDN_TTY_STAT_DEBUG
2294 printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
2296 if (TTY_IS_ACTIVE(info)) {
2297 #ifdef ISDN_DEBUG_MODEM_HUP
2298 printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
2300 isdn_tty_modem_hup(info, 0);
2304 case ISDN_STAT_NODCH:
2305 #ifdef ISDN_TTY_STAT_DEBUG
2306 printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line);
2308 if (TTY_IS_ACTIVE(info)) {
2309 if (info->dialing) {
2313 sprintf(info->last_cause, "0000");
2314 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
2316 isdn_tty_modem_hup(info, 0);
2320 case ISDN_STAT_UNLOAD:
2321 #ifdef ISDN_TTY_STAT_DEBUG
2322 printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line);
2324 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2325 info = &dev->mdm.info[i];
2326 if (info->isdn_driver == c->driver) {
2328 isdn_tty_modem_hup(info, 1);
2332 #ifdef CONFIG_ISDN_TTY_FAX
2333 case ISDN_STAT_FAXIND:
2334 if (TTY_IS_ACTIVE(info)) {
2335 isdn_tty_fax_command(info, c);
2339 #ifdef CONFIG_ISDN_AUDIO
2340 case ISDN_STAT_AUDIO:
2341 if (TTY_IS_ACTIVE(info)) {
2342 switch(c->parm.num[0]) {
2343 case ISDN_AUDIO_DTMF:
2344 if (info->vonline) {
2345 isdn_audio_put_dle_code(info,
2358 /*********************************************************************
2359 Modem-Emulator-Routines
2360 *********************************************************************/
2362 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2365 * Put a message from the AT-emulator into receive-buffer of tty,
2366 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2369 isdn_tty_at_cout(char *msg, modem_info * info)
2371 struct tty_struct *tty;
2372 atemu *m = &info->emu;
2376 struct sk_buff *skb = NULL;
2380 printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
2383 spin_lock_irqsave(&info->readlock, flags);
2385 if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) {
2386 spin_unlock_irqrestore(&info->readlock, flags);
2390 /* use queue instead of direct flip, if online and */
2391 /* data is in queue or flip buffer is full */
2392 if ((info->online) && (((tty->flip.count + strlen(msg)) >= TTY_FLIPBUF_SIZE) ||
2393 (!skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel])))) {
2394 skb = alloc_skb(strlen(msg), GFP_ATOMIC);
2396 spin_unlock_irqrestore(&info->readlock, flags);
2399 sp = skb_put(skb, strlen(msg));
2400 #ifdef CONFIG_ISDN_AUDIO
2401 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
2402 ISDN_AUDIO_SKB_LOCK(skb) = 0;
2406 for (p = msg; *p; p++) {
2409 c = m->mdmreg[REG_CR];
2412 c = m->mdmreg[REG_LF];
2415 c = m->mdmreg[REG_BS];
2423 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
2425 tty_insert_flip_char(tty, c, 0);
2429 __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb);
2430 dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len;
2431 spin_unlock_irqrestore(&info->readlock, flags);
2432 /* Schedule dequeuing */
2433 if ((dev->modempoll) && (info->rcvsched))
2434 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
2437 spin_unlock_irqrestore(&info->readlock, flags);
2438 schedule_delayed_work(&tty->flip.work, 1);
2443 * Perform ATH Hangup
2446 isdn_tty_on_hook(modem_info * info)
2448 if (info->isdn_channel >= 0) {
2449 #ifdef ISDN_DEBUG_MODEM_HUP
2450 printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n");
2452 isdn_tty_modem_hup(info, 1);
2457 isdn_tty_off_hook(void)
2459 printk(KERN_DEBUG "isdn_tty_off_hook\n");
2462 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2463 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2466 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2467 * isdn_tty_modem_escape() if sequence found.
2470 * p pointer to databuffer
2471 * plus escape-character
2472 * count length of buffer
2473 * pluscount count of valid escape-characters so far
2474 * lastplus timestamp of last character
2477 isdn_tty_check_esc(const u_char * p, u_char plus, int count, int *pluscount,
2478 u_long *lastplus, int from_user)
2490 copy_from_user(cbuf, p, count);
2494 if (*(p++) == plus) {
2495 if ((*pluscount)++) {
2496 /* Time since last '+' > 0.5 sec. ? */
2497 if (time_after(jiffies, *lastplus + PLUSWAIT1))
2500 /* Time since last non-'+' < 1.5 sec. ? */
2501 if (time_before(jiffies, *lastplus + PLUSWAIT2))
2504 if ((*pluscount == 3) && (count == 1))
2505 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1);
2510 *lastplus = jiffies;
2516 * Return result of AT-emulator to tty-receive-buffer, depending on
2517 * modem-register 12, bit 0 and 1.
2518 * For CONNECT-messages also switch to online-mode.
2519 * For RING-message handle auto-ATA if register 0 != 0
2523 isdn_tty_modem_result(int code, modem_info * info)
2525 atemu *m = &info->emu;
2526 static char *msg[] =
2527 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2528 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2529 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2530 char s[ISDN_MSNLEN+10];
2534 m->mdmreg[REG_RINGCNT]++;
2535 if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA])
2536 /* Automatically accept incoming call */
2537 isdn_tty_cmd_ATA(info);
2539 case RESULT_NO_CARRIER:
2540 #ifdef ISDN_DEBUG_MODEM_HUP
2541 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n",
2542 (info->flags & ISDN_ASYNC_CLOSING),
2545 m->mdmreg[REG_RINGCNT] = 0;
2546 del_timer(&info->nc_timer);
2548 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) {
2551 #ifdef CONFIG_ISDN_AUDIO
2552 if (info->vonline & 1) {
2553 #ifdef ISDN_DEBUG_MODEM_VOICE
2554 printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n",
2557 /* voice-recording, add DLE-ETX */
2558 isdn_tty_at_cout("\020\003", info);
2560 if (info->vonline & 2) {
2561 #ifdef ISDN_DEBUG_MODEM_VOICE
2562 printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n",
2565 /* voice-playing, add DLE-DC4 */
2566 isdn_tty_at_cout("\020\024", info);
2570 case RESULT_CONNECT:
2571 case RESULT_CONNECT64000:
2572 sprintf(info->last_cause, "0000");
2577 #ifdef ISDN_DEBUG_MODEM_VOICE
2578 printk(KERN_DEBUG "res3: send VCON on ttyI%d\n",
2581 sprintf(info->last_cause, "0000");
2585 } /* switch(code) */
2587 if (m->mdmreg[REG_RESP] & BIT_RESP) {
2589 if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) {
2590 /* Show numeric results only */
2591 sprintf(s, "\r\n%d\r\n", code);
2592 isdn_tty_at_cout(s, info);
2594 if (code == RESULT_RING) {
2595 /* return if "show RUNG" and ringcounter>1 */
2596 if ((m->mdmreg[REG_RUNG] & BIT_RUNG) &&
2597 (m->mdmreg[REG_RINGCNT] > 1))
2599 /* print CID, _before_ _every_ ring */
2600 if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) {
2601 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info);
2602 isdn_tty_at_cout(dev->num[info->drv_index], info);
2603 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2604 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2605 isdn_tty_at_cout(info->emu.cpn, info);
2609 isdn_tty_at_cout("\r\n", info);
2610 isdn_tty_at_cout(msg[code], info);
2612 case RESULT_CONNECT:
2613 switch (m->mdmreg[REG_L2PROT]) {
2614 case ISDN_PROTO_L2_MODEM:
2615 isdn_tty_at_cout(" ", info);
2616 isdn_tty_at_cout(m->connmsg, info);
2621 /* Append CPN, if enabled */
2622 if ((m->mdmreg[REG_CPN] & BIT_CPN)) {
2623 sprintf(s, "/%s", m->cpn);
2624 isdn_tty_at_cout(s, info);
2626 /* Print CID only once, _after_ 1st RING */
2627 if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) &&
2628 (m->mdmreg[REG_RINGCNT] == 1)) {
2629 isdn_tty_at_cout("\r\n", info);
2630 isdn_tty_at_cout("CALLER NUMBER: ", info);
2631 isdn_tty_at_cout(dev->num[info->drv_index], info);
2632 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2633 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2634 isdn_tty_at_cout(info->emu.cpn, info);
2638 case RESULT_NO_CARRIER:
2639 case RESULT_NO_DIALTONE:
2641 case RESULT_NO_ANSWER:
2642 m->mdmreg[REG_RINGCNT] = 0;
2643 /* Append Cause-Message if enabled */
2644 if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) {
2645 sprintf(s, "/%s", info->last_cause);
2646 isdn_tty_at_cout(s, info);
2649 case RESULT_CONNECT64000:
2650 /* Append Protocol to CONNECT message */
2651 switch (m->mdmreg[REG_L2PROT]) {
2652 case ISDN_PROTO_L2_X75I:
2653 case ISDN_PROTO_L2_X75UI:
2654 case ISDN_PROTO_L2_X75BUI:
2655 isdn_tty_at_cout("/X.75", info);
2657 case ISDN_PROTO_L2_HDLC:
2658 isdn_tty_at_cout("/HDLC", info);
2660 case ISDN_PROTO_L2_V11096:
2661 isdn_tty_at_cout("/V110/9600", info);
2663 case ISDN_PROTO_L2_V11019:
2664 isdn_tty_at_cout("/V110/19200", info);
2666 case ISDN_PROTO_L2_V11038:
2667 isdn_tty_at_cout("/V110/38400", info);
2670 if (m->mdmreg[REG_T70] & BIT_T70) {
2671 isdn_tty_at_cout("/T.70", info);
2672 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2673 isdn_tty_at_cout("+", info);
2677 isdn_tty_at_cout("\r\n", info);
2680 if (code == RESULT_NO_CARRIER) {
2681 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) {
2684 if (info->tty->ldisc.flush_buffer)
2685 info->tty->ldisc.flush_buffer(info->tty);
2686 if ((info->flags & ISDN_ASYNC_CHECK_CD) &&
2687 (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
2688 (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) {
2689 tty_hangup(info->tty);
2696 * Display a modem-register-value.
2699 isdn_tty_show_profile(int ridx, modem_info * info)
2703 sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]);
2704 isdn_tty_at_cout(v, info);
2708 * Get MSN-string from char-pointer, set pointer to end of number
2711 isdn_tty_get_msnstr(char *n, char **p)
2713 int limit = ISDN_MSNLEN - 1;
2715 while (((*p[0] >= '0' && *p[0] <= '9') ||
2716 /* Why a comma ??? */
2717 (*p[0] == ',') || (*p[0] == ':')) &&
2724 * Get phone-number from modem-commandbuffer
2727 isdn_tty_getdial(char *p, char *q,int cnt)
2730 int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
2733 while (strchr(" 0123456789,#.*WPTS-", *p) && *p && --cnt>0) {
2734 if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
2735 (*p == '*') || (*p == '#')) {
2747 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2748 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2751 isdn_tty_report(modem_info * info)
2753 atemu *m = &info->emu;
2756 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info);
2757 sprintf(s, " Remote Number: %s\r\n", info->last_num);
2758 isdn_tty_at_cout(s, info);
2759 sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming");
2760 isdn_tty_at_cout(s, info);
2761 isdn_tty_at_cout(" Layer-2 Protocol: ", info);
2762 switch (info->last_l2) {
2763 case ISDN_PROTO_L2_X75I:
2764 isdn_tty_at_cout("X.75i", info);
2766 case ISDN_PROTO_L2_X75UI:
2767 isdn_tty_at_cout("X.75ui", info);
2769 case ISDN_PROTO_L2_X75BUI:
2770 isdn_tty_at_cout("X.75bui", info);
2772 case ISDN_PROTO_L2_HDLC:
2773 isdn_tty_at_cout("HDLC", info);
2775 case ISDN_PROTO_L2_V11096:
2776 isdn_tty_at_cout("V.110 9600 Baud", info);
2778 case ISDN_PROTO_L2_V11019:
2779 isdn_tty_at_cout("V.110 19200 Baud", info);
2781 case ISDN_PROTO_L2_V11038:
2782 isdn_tty_at_cout("V.110 38400 Baud", info);
2784 case ISDN_PROTO_L2_TRANS:
2785 isdn_tty_at_cout("transparent", info);
2787 case ISDN_PROTO_L2_MODEM:
2788 isdn_tty_at_cout("modem", info);
2790 case ISDN_PROTO_L2_FAX:
2791 isdn_tty_at_cout("fax", info);
2794 isdn_tty_at_cout("unknown", info);
2797 if (m->mdmreg[REG_T70] & BIT_T70) {
2798 isdn_tty_at_cout("/T.70", info);
2799 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2800 isdn_tty_at_cout("+", info);
2802 isdn_tty_at_cout("\r\n", info);
2803 isdn_tty_at_cout(" Service: ", info);
2804 switch (info->last_si) {
2806 isdn_tty_at_cout("audio\r\n", info);
2809 isdn_tty_at_cout("btx\r\n", info);
2812 isdn_tty_at_cout("data\r\n", info);
2815 sprintf(s, "%d\r\n", info->last_si);
2816 isdn_tty_at_cout(s, info);
2819 sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote");
2820 isdn_tty_at_cout(s, info);
2821 sprintf(s, " Last cause: %s\r\n", info->last_cause);
2822 isdn_tty_at_cout(s, info);
2826 * Parse AT&.. commands.
2829 isdn_tty_cmd_ATand(char **p, modem_info * info)
2831 atemu *m = &info->emu;
2835 #define MAXRB (sizeof(rb) - 1)
2839 /* &B - Set Buffersize */
2842 if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX))
2844 #ifdef CONFIG_ISDN_AUDIO
2845 if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF))
2848 m->mdmreg[REG_PSIZE] = i / 16;
2849 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2850 switch (m->mdmreg[REG_L2PROT]) {
2851 case ISDN_PROTO_L2_V11096:
2852 case ISDN_PROTO_L2_V11019:
2853 case ISDN_PROTO_L2_V11038:
2854 info->xmit_size /= 10;
2858 /* &C - DCD Status */
2860 switch (isdn_getnum(p)) {
2862 m->mdmreg[REG_DCD] &= ~BIT_DCD;
2865 m->mdmreg[REG_DCD] |= BIT_DCD;
2872 /* &D - Set DTR-Low-behavior */
2874 switch (isdn_getnum(p)) {
2876 m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP;
2877 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2880 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2881 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2884 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2885 m->mdmreg[REG_DTRR] |= BIT_DTRR;
2892 /* &E -Set EAZ/MSN */
2894 isdn_tty_get_msnstr(m->msn, p);
2897 /* &F -Set Factory-Defaults */
2899 if (info->msr & UART_MSR_DCD)
2901 isdn_tty_reset_profile(m);
2902 isdn_tty_modem_reset_regs(info, 1);
2904 #ifdef DUMMY_HAYES_AT
2906 /* only for be compilant with common scripts */
2907 /* &K Flowcontrol - no function */
2913 /* &L -Set Numbers to listen on */
2916 while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) &&
2918 m->lmsn[i++] = *p[0]++;
2922 /* &R - Set V.110 bitrate adaption */
2927 /* Switch off V.110, back to X.75 */
2928 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2929 m->mdmreg[REG_SI2] = 0;
2930 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2933 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096;
2934 m->mdmreg[REG_SI2] = 197;
2935 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2938 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019;
2939 m->mdmreg[REG_SI2] = 199;
2940 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2943 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038;
2944 m->mdmreg[REG_SI2] = 198; /* no existing standard for this */
2945 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2950 /* Switch off T.70 */
2951 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
2953 m->mdmreg[REG_SI1] |= 4;
2956 /* &S - Set Windowsize */
2959 if ((i > 0) && (i < 9))
2960 m->mdmreg[REG_WSIZE] = i;
2965 /* &V - Show registers */
2967 isdn_tty_at_cout("\r\n", info);
2968 for (i = 0; i < ISDN_MODEM_NUMREG; i++) {
2969 sprintf(rb, "S%02d=%03d%s", i,
2970 m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n");
2971 isdn_tty_at_cout(rb, info);
2973 sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n",
2974 strlen(m->msn) ? m->msn : "None");
2975 isdn_tty_at_cout(rb, info);
2976 if (strlen(m->lmsn)) {
2977 isdn_tty_at_cout("\r\nListen: ", info);
2978 isdn_tty_at_cout(m->lmsn, info);
2979 isdn_tty_at_cout("\r\n", info);
2983 /* &W - Write Profile */
2988 modem_write_profile(m);
2995 /* &X - Switch to BTX-Mode and T.70 */
2997 switch (isdn_getnum(p)) {
2999 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
3000 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
3003 m->mdmreg[REG_T70] |= BIT_T70;
3004 m->mdmreg[REG_T70] &= ~BIT_T70_EXT;
3005 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3006 info->xmit_size = 112;
3007 m->mdmreg[REG_SI1] = 4;
3008 m->mdmreg[REG_SI2] = 0;
3011 m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT);
3012 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3013 info->xmit_size = 112;
3014 m->mdmreg[REG_SI1] = 4;
3015 m->mdmreg[REG_SI2] = 0;
3028 isdn_tty_check_ats(int mreg, int mval, modem_info * info, atemu * m)
3030 /* Some plausibility checks */
3033 if (mval > ISDN_PROTO_L2_MAX)
3037 if ((mval * 16) > ISDN_SERIAL_XMIT_MAX)
3039 #ifdef CONFIG_ISDN_AUDIO
3040 if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX))
3043 info->xmit_size = mval * 16;
3044 switch (m->mdmreg[REG_L2PROT]) {
3045 case ISDN_PROTO_L2_V11096:
3046 case ISDN_PROTO_L2_V11019:
3047 case ISDN_PROTO_L2_V11038:
3048 info->xmit_size /= 10;
3054 /* readonly registers */
3061 * Perform ATS command
3064 isdn_tty_cmd_ATS(char **p, modem_info * info)
3066 atemu *m = &info->emu;
3072 mreg = isdn_getnum(p);
3073 if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG)
3078 mval = isdn_getnum(p);
3079 if (mval < 0 || mval > 255)
3081 if (isdn_tty_check_ats(mreg, mval, info, m))
3083 m->mdmreg[mreg] = mval;
3086 /* Set/Clear a single bit */
3088 bitpos = isdn_getnum(p);
3089 if ((bitpos < 0) || (bitpos > 7))
3094 bval = isdn_getnum(p);
3095 if (bval < 0 || bval > 1)
3098 mval = m->mdmreg[mreg] | (1 << bitpos);
3100 mval = m->mdmreg[mreg] & ~(1 << bitpos);
3101 if (isdn_tty_check_ats(mreg, mval, info, m))
3103 m->mdmreg[mreg] = mval;
3107 isdn_tty_at_cout("\r\n", info);
3108 isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0",
3117 isdn_tty_show_profile(mreg, info);
3127 * Perform ATA command
3130 isdn_tty_cmd_ATA(modem_info * info)
3132 atemu *m = &info->emu;
3136 if (info->msr & UART_MSR_RI) {
3137 /* Accept incoming call */
3139 strcpy(info->last_num, dev->num[info->drv_index]);
3140 m->mdmreg[REG_RINGCNT] = 0;
3141 info->msr &= ~UART_MSR_RI;
3142 l2 = m->mdmreg[REG_L2PROT];
3143 #ifdef CONFIG_ISDN_AUDIO
3144 /* If more than one bit set in reg18, autoselect Layer2 */
3145 if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) {
3146 if (m->mdmreg[REG_SI1I] == 1) {
3147 if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX))
3148 l2 = ISDN_PROTO_L2_TRANS;
3150 l2 = ISDN_PROTO_L2_X75I;
3153 cmd.driver = info->isdn_driver;
3154 cmd.command = ISDN_CMD_SETL2;
3155 cmd.arg = info->isdn_channel + (l2 << 8);
3158 cmd.driver = info->isdn_driver;
3159 cmd.command = ISDN_CMD_SETL3;
3160 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
3161 #ifdef CONFIG_ISDN_TTY_FAX
3162 if (l2 == ISDN_PROTO_L2_FAX) {
3163 cmd.parm.fax = info->fax;
3164 info->fax->direction = ISDN_TTY_FAX_CONN_IN;
3168 cmd.driver = info->isdn_driver;
3169 cmd.arg = info->isdn_channel;
3170 cmd.command = ISDN_CMD_ACCEPTD;
3172 info->emu.carrierwait = 0;
3174 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
3176 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3179 #ifdef CONFIG_ISDN_AUDIO
3181 * Parse AT+F.. commands
3184 isdn_tty_cmd_PLUSF(char **p, modem_info * info)
3186 atemu *m = &info->emu;
3189 if (!strncmp(p[0], "CLASS", 5)) {
3194 sprintf(rs, "\r\n%d",
3195 (m->mdmreg[REG_SI1] & 1) ? 8 : 0);
3196 #ifdef CONFIG_ISDN_TTY_FAX
3197 if (TTY_IS_FCLASS2(info))
3198 sprintf(rs, "\r\n2");
3199 else if (TTY_IS_FCLASS1(info))
3200 sprintf(rs, "\r\n1");
3202 isdn_tty_at_cout(rs, info);
3209 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3210 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3211 m->mdmreg[REG_SI1] = 4;
3213 m->mdmreg[REG_PSIZE] * 16;
3215 #ifdef CONFIG_ISDN_TTY_FAX
3218 if (!(dev->global_features &
3219 ISDN_FEATURE_L3_FCLASS1))
3221 m->mdmreg[REG_SI1] = 1;
3222 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3223 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1;
3225 m->mdmreg[REG_PSIZE] * 16;
3229 if (!(dev->global_features &
3230 ISDN_FEATURE_L3_FCLASS2))
3232 m->mdmreg[REG_SI1] = 1;
3233 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3234 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2;
3236 m->mdmreg[REG_PSIZE] * 16;
3241 /* L2 will change on dialout with si=1 */
3242 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3243 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3244 m->mdmreg[REG_SI1] = 5;
3245 info->xmit_size = VBUF;
3249 strcpy(rs, "\r\n0,");
3250 #ifdef CONFIG_ISDN_TTY_FAX
3251 if (dev->global_features &
3252 ISDN_FEATURE_L3_FCLASS1)
3254 if (dev->global_features &
3255 ISDN_FEATURE_L3_FCLASS2)
3259 isdn_tty_at_cout(rs, info);
3270 #ifdef CONFIG_ISDN_TTY_FAX
3271 return (isdn_tty_cmd_PLUSF_FAX(p, info));
3278 * Parse AT+V.. commands
3281 isdn_tty_cmd_PLUSV(char **p, modem_info * info)
3283 atemu *m = &info->emu;
3285 static char *vcmd[] =
3286 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL};
3294 if (!strncmp(vcmd[i], p[0], 2)) {
3302 /* AT+VNH - Auto hangup feature */
3306 isdn_tty_at_cout("\r\n1", info);
3316 isdn_tty_at_cout("\r\n1", info);
3327 /* AT+VIP - Reset all voice parameters */
3328 isdn_tty_modem_reset_vpar(m);
3331 /* AT+VLS - Select device, accept incoming call */
3335 sprintf(rs, "\r\n%d", m->vpar[0]);
3336 isdn_tty_at_cout(rs, info);
3351 isdn_tty_at_cout("\r\n0,2", info);
3362 /* AT+VRX - Start recording */
3365 if (info->online != 1) {
3366 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3369 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3370 if (!info->dtmf_state) {
3371 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3374 info->silence_state = isdn_audio_silence_init(info->silence_state);
3375 if (!info->silence_state) {
3376 printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n");
3379 if (m->vpar[3] < 5) {
3380 info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]);
3381 if (!info->adpcmr) {
3382 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3386 #ifdef ISDN_DEBUG_AT
3387 printk(KERN_DEBUG "AT: +VRX\n");
3390 isdn_tty_modem_result(RESULT_CONNECT, info);
3394 /* AT+VSD - Silence detection */
3398 sprintf(rs, "\r\n<%d>,<%d>",
3401 isdn_tty_at_cout(rs, info);
3405 if ((*p[0]>='0') && (*p[0]<='9')) {
3406 par1 = isdn_getnum(p);
3407 if ((par1 < 0) || (par1 > 31))
3412 par2 = isdn_getnum(p);
3413 if ((par2 < 0) || (par2 > 255))
3421 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3432 /* AT+VSM - Select compression */
3436 sprintf(rs, "\r\n<%d>,<%d><8000>",
3439 isdn_tty_at_cout(rs, info);
3449 par1 = isdn_getnum(p);
3450 if ((par1 < 2) || (par1 > 6))
3456 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3458 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3460 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3462 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3464 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3476 /* AT+VTX - Start sending */
3479 if (info->online != 1) {
3480 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3483 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3484 if (!info->dtmf_state) {
3485 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3488 if (m->vpar[3] < 5) {
3489 info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]);
3490 if (!info->adpcms) {
3491 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3495 #ifdef ISDN_DEBUG_AT
3496 printk(KERN_DEBUG "AT: +VTX\n");
3500 isdn_tty_modem_result(RESULT_CONNECT, info);
3504 /* AT+VDD - DTMF detection */
3508 sprintf(rs, "\r\n<%d>,<%d>",
3511 isdn_tty_at_cout(rs, info);
3515 if ((*p[0]>='0') && (*p[0]<='9')) {
3516 if (info->online != 1)
3518 par1 = isdn_getnum(p);
3519 if ((par1 < 0) || (par1 > 15))
3524 par2 = isdn_getnum(p);
3525 if ((par2 < 0) || (par2 > 255))
3529 cmd.driver = info->isdn_driver;
3530 cmd.command = ISDN_CMD_AUDIO;
3531 cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8);
3532 cmd.parm.num[0] = par1;
3533 cmd.parm.num[1] = par2;
3539 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3554 #endif /* CONFIG_ISDN_AUDIO */
3557 * Parse and perform an AT-command-line.
3560 isdn_tty_parse_at(modem_info * info)
3562 atemu *m = &info->emu;
3566 #ifdef ISDN_DEBUG_AT
3567 printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd);
3569 for (p = &m->mdmcmd[2]; *p;) {
3575 /* A - Accept incoming call */
3577 isdn_tty_cmd_ATA(info);
3582 if (info->msr & UART_MSR_DCD)
3584 if (info->msr & UART_MSR_RI) {
3585 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3588 isdn_tty_getdial(++p, ds, sizeof ds);
3590 if (!strlen(m->msn))
3591 isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info);
3592 else if (strlen(ds))
3593 isdn_tty_dial(ds, info, m);
3598 /* E - Turn Echo on/off */
3600 switch (isdn_getnum(&p)) {
3602 m->mdmreg[REG_ECHO] &= ~BIT_ECHO;
3605 m->mdmreg[REG_ECHO] |= BIT_ECHO;
3612 /* H - On/Off-hook */
3617 isdn_tty_on_hook(info);
3621 isdn_tty_off_hook();
3624 isdn_tty_on_hook(info);
3629 /* I - Information */
3631 isdn_tty_at_cout("\r\nLinux ISDN", info);
3639 isdn_tty_report(info);
3643 sprintf(ds, "\r\n%d", info->emu.charge);
3644 isdn_tty_at_cout(ds, info);
3649 #ifdef DUMMY_HAYES_AT
3652 /* only for be compilant with common scripts */
3661 if (info->msr & UART_MSR_DCD)
3662 /* if B-Channel is up */
3663 isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT:RESULT_CONNECT64000, info);
3665 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3668 /* Q - Turn Emulator messages on/off */
3670 switch (isdn_getnum(&p)) {
3672 m->mdmreg[REG_RESP] |= BIT_RESP;
3675 m->mdmreg[REG_RESP] &= ~BIT_RESP;
3682 /* S - Set/Get Register */
3684 if (isdn_tty_cmd_ATS(&p, info))
3688 /* V - Numeric or ASCII Emulator-messages */
3690 switch (isdn_getnum(&p)) {
3692 m->mdmreg[REG_RESP] |= BIT_RESPNUM;
3695 m->mdmreg[REG_RESP] &= ~BIT_RESPNUM;
3702 /* Z - Load Registers from Profile */
3704 if (info->msr & UART_MSR_DCD) {
3706 isdn_tty_on_hook(info);
3708 isdn_tty_modem_reset_regs(info, 1);
3713 #ifdef CONFIG_ISDN_AUDIO
3716 if (isdn_tty_cmd_PLUSF(&p, info))
3720 if ((!(m->mdmreg[REG_SI1] & 1)) ||
3721 (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM))
3724 if (isdn_tty_cmd_PLUSV(&p, info))
3727 #endif /* CONFIG_ISDN_AUDIO */
3728 case 'S': /* SUSPEND */
3730 isdn_tty_get_msnstr(ds, &p);
3731 isdn_tty_suspend(ds, info, m);
3733 case 'R': /* RESUME */
3735 isdn_tty_get_msnstr(ds, &p);
3736 isdn_tty_resume(ds, info, m);
3738 case 'M': /* MESSAGE */
3740 isdn_tty_send_msg(info, m, p);
3748 if (isdn_tty_cmd_ATand(&p, info))
3755 #ifdef CONFIG_ISDN_AUDIO
3758 isdn_tty_modem_result(RESULT_OK, info);
3761 /* Need own toupper() because standard-toupper is not available
3764 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
3767 * Perform line-editing of AT-commands
3771 * count length of buffer
3772 * channel index to line (minor-device)
3773 * user flag: buffer is in userspace
3776 isdn_tty_edit_at(const char *p, int count, modem_info * info, int user)
3778 atemu *m = &info->emu;
3784 for (cnt = count; cnt > 0; p++, cnt--) {
3790 if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) {
3791 /* Separator (CR or LF) */
3792 m->mdmcmd[m->mdmcmdl] = 0;
3793 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3796 isdn_tty_at_cout(eb, info);
3798 if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2))))
3799 isdn_tty_parse_at(info);
3803 if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) {
3804 /* Backspace-Function */
3805 if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) {
3808 if (m->mdmreg[REG_ECHO] & BIT_ECHO)
3809 isdn_tty_at_cout("\b", info);
3814 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3817 isdn_tty_at_cout(eb, info);
3819 if (m->mdmcmdl < 255) {
3821 switch (m->mdmcmdl) {
3824 m->mdmcmd[m->mdmcmdl] = c;
3825 m->mdmcmd[++m->mdmcmdl] = 0;
3829 /* Fall through, check for 'A' */
3832 m->mdmcmd[m->mdmcmdl] = c;
3833 m->mdmcmd[++m->mdmcmdl] = 0;
3837 m->mdmcmd[m->mdmcmdl] = c;
3838 m->mdmcmd[++m->mdmcmdl] = 0;
3847 * Switch all modem-channels who are online and got a valid
3848 * escape-sequence 1.5 seconds ago, to command-mode.
3849 * This function is called every second via timer-interrupt from within
3850 * timer-dispatcher isdn_timer_function()
3853 isdn_tty_modem_escape(void)
3859 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
3860 if (USG_MODEM(dev->usage[i]))
3861 if ((midx = dev->m_idx[i]) >= 0) {
3862 modem_info *info = &dev->mdm.info[midx];
3865 if ((info->emu.pluscount == 3) &&
3866 time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) {
3867 info->emu.pluscount = 0;
3869 isdn_tty_modem_result(RESULT_OK, info);
3873 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
3877 * Put a RING-message to all modem-channels who have the RI-bit set.
3878 * This function is called every second via timer-interrupt from within
3879 * timer-dispatcher isdn_timer_function()
3882 isdn_tty_modem_ring(void)
3887 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3888 modem_info *info = &dev->mdm.info[i];
3889 if (info->msr & UART_MSR_RI) {
3891 isdn_tty_modem_result(RESULT_RING, info);
3894 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton);
3898 * For all online tty's, try sending data to
3902 isdn_tty_modem_xmit(void)
3907 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3908 modem_info *info = &dev->mdm.info[i];
3911 isdn_tty_senddown(info);
3912 isdn_tty_tint(info);
3915 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton);
3919 * Check all channels if we have a 'no carrier' timeout.
3920 * Timeout value is set by Register S7.
3923 isdn_tty_carrier_timeout(void)
3928 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3929 modem_info *info = &dev->mdm.info[i];
3930 if (info->dialing) {
3931 if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
3933 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3934 isdn_tty_modem_hup(info, 1);
3940 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);