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 <linux/delay.h>
17 #include "isdn_common.h"
19 #ifdef CONFIG_ISDN_AUDIO
20 #include "isdn_audio.h"
22 #define VBUFX (VBUF/16)
25 #define FIX_FILE_TRANSFER
26 #define DUMMY_HAYES_AT
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);
40 /* Leave this unchanged unless you know what you do! */
41 #define MODEM_PARANOIA_CHECK
42 #define MODEM_DO_RESTART
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};
49 char *isdn_tty_revision = "$Revision: 1.1.2.3 $";
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.
58 * 0 = Failure, data has to be buffered and later processed by
59 * isdn_tty_readmodem().
62 isdn_tty_try_read(modem_info * info, struct sk_buff *skb)
66 struct tty_struct *tty;
70 if ((tty = info->tty)) {
71 if (info->mcr & UART_MCR_RTS) {
73 #ifdef CONFIG_ISDN_AUDIO
74 + ISDN_AUDIO_SKB_DLECOUNT(skb)
78 c = tty_buffer_request_room(tty, len);
80 #ifdef CONFIG_ISDN_AUDIO
81 if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
83 unsigned char *dp = skb->data;
85 if (*skb->data == DLE)
86 tty_insert_flip_char(tty, DLE, 0);
87 tty_insert_flip_char(tty, *dp++, 0);
93 tty_insert_flip_string(tty, skb->data, len - 1);
94 last = skb->data[len - 1];
95 #ifdef CONFIG_ISDN_AUDIO
98 if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
99 tty_insert_flip_char(tty, last, 0xFF);
101 tty_insert_flip_char(tty, last, TTY_NORMAL);
102 tty_flip_buffer_push(tty);
112 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
113 * It tries getting received data from the receive queue an stuff it into
114 * the tty's flip-buffer.
117 isdn_tty_readmodem(void)
123 struct tty_struct *tty;
126 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
127 if ((midx = dev->m_idx[i]) >= 0) {
128 info = &dev->mdm.info[midx];
131 #ifdef CONFIG_ISDN_AUDIO
132 isdn_audio_eval_dtmf(info);
133 if ((info->vonline & 1) && (info->emu.vpar[1]))
134 isdn_audio_eval_silence(info);
136 if ((tty = info->tty)) {
137 if (info->mcr & UART_MCR_RTS) {
138 /* CISCO AsyncPPP Hack */
139 if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
140 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0);
142 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1);
144 tty_flip_buffer_push(tty);
158 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
162 isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb)
166 #ifdef CONFIG_ISDN_AUDIO
171 if ((midx = dev->m_idx[i]) < 0) {
172 /* if midx is invalid, packet is not for tty */
175 info = &dev->mdm.info[midx];
176 #ifdef CONFIG_ISDN_AUDIO
179 if ((info->vonline) && (!info->emu.vpar[4]))
180 isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt);
181 if ((info->vonline & 1) && (info->emu.vpar[1]))
182 isdn_audio_calc_silence(info, skb->data, skb->len, ifmt);
184 if ((info->online < 2)
185 #ifdef CONFIG_ISDN_AUDIO
186 && (!(info->vonline & 1))
189 /* If Modem not listening, drop data */
193 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
194 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) {
195 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
196 if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */
199 if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */
202 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
203 if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1)))
206 #ifdef CONFIG_ISDN_AUDIO
207 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
208 ISDN_AUDIO_SKB_LOCK(skb) = 0;
209 if (info->vonline & 1) {
210 /* voice conversion/compression */
211 switch (info->emu.vpar[3]) {
216 * Since compressed data takes less
217 * space, we can overwrite the buffer.
219 skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr,
228 isdn_audio_ulaw2alaw(skb->data, skb->len);
233 isdn_audio_alaw2ulaw(skb->data, skb->len);
236 ISDN_AUDIO_SKB_DLECOUNT(skb) =
237 isdn_tty_countDLE(skb->data, skb->len);
239 #ifdef CONFIG_ISDN_TTY_FAX
241 if (info->faxonline & 2) {
242 isdn_tty_fax_bitorder(info, skb);
243 ISDN_AUDIO_SKB_DLECOUNT(skb) =
244 isdn_tty_countDLE(skb->data, skb->len);
249 /* Try to deliver directly via tty-buf if queue is empty */
250 spin_lock_irqsave(&info->readlock, flags);
251 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
252 if (isdn_tty_try_read(info, skb)) {
253 spin_unlock_irqrestore(&info->readlock, flags);
256 /* Direct deliver failed or queue wasn't empty.
257 * Queue up for later dequeueing via timer-irq.
259 __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb);
260 dev->drv[di]->rcvcount[channel] +=
262 #ifdef CONFIG_ISDN_AUDIO
263 + ISDN_AUDIO_SKB_DLECOUNT(skb)
266 spin_unlock_irqrestore(&info->readlock, flags);
267 /* Schedule dequeuing */
268 if ((dev->modempoll) && (info->rcvsched))
269 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
274 isdn_tty_cleanup_xmit(modem_info * info)
276 skb_queue_purge(&info->xmit_queue);
277 #ifdef CONFIG_ISDN_AUDIO
278 skb_queue_purge(&info->dtmf_queue);
283 isdn_tty_tint(modem_info * info)
285 struct sk_buff *skb = skb_dequeue(&info->xmit_queue);
291 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
292 info->isdn_channel, 1, skb)) == len) {
293 struct tty_struct *tty = info->tty;
294 info->send_outstanding++;
295 info->msr &= ~UART_MSR_CTS;
296 info->lsr &= ~UART_LSR_TEMT;
301 /* Error: no channel, already shutdown, or wrong parameter */
305 skb_queue_head(&info->xmit_queue, skb);
308 #ifdef CONFIG_ISDN_AUDIO
310 isdn_tty_countDLE(unsigned char *buf, int len)
320 /* This routine is called from within isdn_tty_write() to perform
321 * DLE-decoding when sending audio-data.
324 isdn_tty_handleDLEdown(modem_info * info, atemu * m, int len)
326 unsigned char *p = &info->xmit_buf[info->xmit_count];
336 memmove(p, p + 1, len - 1);
347 #ifdef ISDN_DEBUG_MODEM_VOICE
349 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
352 isdn_tty_at_cout("\020\003", info);
353 if (!info->vonline) {
354 #ifdef ISDN_DEBUG_MODEM_VOICE
356 "DLEdown: send VCON on ttyI%d\n",
359 isdn_tty_at_cout("\r\nVCON\r\n", info);
366 memmove(p, p + 1, len - 1);
380 printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n");
386 /* This routine is called from within isdn_tty_write() when receiving
387 * audio-data. It interrupts receiving, if an character other than
391 isdn_tty_end_vrx(const char *buf, int c)
397 if ((ch != 0x11) && (ch != 0x13))
404 static int voice_cf[7] =
405 {0, 0, 4, 3, 2, 0, 0};
407 #endif /* CONFIG_ISDN_AUDIO */
409 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
410 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
411 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
412 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
415 isdn_tty_senddown(modem_info * info)
419 #ifdef CONFIG_ISDN_AUDIO
424 #ifdef CONFIG_ISDN_AUDIO
425 if (info->vonline & 4) {
427 if (!info->vonline) {
428 #ifdef ISDN_DEBUG_MODEM_VOICE
430 "senddown: send VCON on ttyI%d\n",
433 isdn_tty_at_cout("\r\nVCON\r\n", info);
437 if (!(buflen = info->xmit_count))
439 if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0)
440 info->msr &= ~UART_MSR_CTS;
441 info->lsr &= ~UART_LSR_TEMT;
442 /* info->xmit_count is modified here and in isdn_tty_write().
443 * So we return here if isdn_tty_write() is in the
446 atomic_inc(&info->xmit_lock);
447 if (!(atomic_dec_and_test(&info->xmit_lock)))
449 if (info->isdn_driver < 0) {
450 info->xmit_count = 0;
453 skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4;
454 #ifdef CONFIG_ISDN_AUDIO
455 if (info->vonline & 2)
456 audio_len = buflen * voice_cf[info->emu.vpar[3]];
459 skb = dev_alloc_skb(skb_res + buflen + audio_len);
461 skb = dev_alloc_skb(skb_res + buflen);
465 "isdn_tty: Out of memory in ttyI%d senddown\n",
469 skb_reserve(skb, skb_res);
470 memcpy(skb_put(skb, buflen), info->xmit_buf, buflen);
471 info->xmit_count = 0;
472 #ifdef CONFIG_ISDN_AUDIO
473 if (info->vonline & 2) {
474 /* For now, ifmt is fixed to 1 (alaw), since this
475 * is used with ISDN everywhere in the world, except
476 * US, Canada and Japan.
477 * Later, when US-ISDN protocols are implemented,
478 * this setting will depend on the D-channel protocol.
482 /* voice conversion/decompression */
483 switch (info->emu.vpar[3]) {
487 /* adpcm, compatible to ZyXel 1496 modem
488 * with ROM revision 6.01
490 audio_len = isdn_audio_adpcm2xlaw(info->adpcms,
493 skb_put(skb, audio_len),
495 skb_pull(skb, buflen);
496 skb_trim(skb, audio_len);
501 isdn_audio_alaw2ulaw(skb->data,
507 isdn_audio_ulaw2alaw(skb->data,
512 #endif /* CONFIG_ISDN_AUDIO */
513 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
514 /* Add T.70 simplified header */
515 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT)
516 memcpy(skb_push(skb, 2), "\1\0", 2);
518 memcpy(skb_push(skb, 4), "\1\0\1\0", 4);
520 skb_queue_tail(&info->xmit_queue, skb);
523 /************************************************************
527 * mostly "stolen" from original Linux-serial.c and friends.
529 ************************************************************/
531 /* The next routine is called once from within timer-interrupt
532 * triggered within isdn_tty_modem_ncarrier(). It calls
533 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
534 * into the tty's buffer.
537 isdn_tty_modem_do_ncarrier(unsigned long data)
539 modem_info *info = (modem_info *) data;
540 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
543 /* Next routine is called, whenever the DTR-signal is raised.
544 * It checks the ncarrier-flag, and triggers the above routine
545 * when necessary. The ncarrier-flag is set, whenever DTR goes
549 isdn_tty_modem_ncarrier(modem_info * info)
551 if (info->ncarrier) {
552 info->nc_timer.expires = jiffies + HZ;
553 add_timer(&info->nc_timer);
558 * return the usage calculated by si and layer 2 protocol
561 isdn_calc_usage(int si, int l2)
563 int usg = ISDN_USAGE_MODEM;
565 #ifdef CONFIG_ISDN_AUDIO
568 case ISDN_PROTO_L2_MODEM:
569 usg = ISDN_USAGE_MODEM;
571 #ifdef CONFIG_ISDN_TTY_FAX
572 case ISDN_PROTO_L2_FAX:
573 usg = ISDN_USAGE_FAX;
576 case ISDN_PROTO_L2_TRANS:
578 usg = ISDN_USAGE_VOICE;
586 /* isdn_tty_dial() performs dialing of a tty an the necessary
587 * setup of the lower levels before that.
590 isdn_tty_dial(char *n, modem_info * info, atemu * m)
592 int usg = ISDN_USAGE_MODEM;
594 int l2 = m->mdmreg[REG_L2PROT];
600 for (j = 7; j >= 0; j--)
601 if (m->mdmreg[REG_SI1] & (1 << j)) {
605 usg = isdn_calc_usage(si, l2);
606 #ifdef CONFIG_ISDN_AUDIO
608 (l2 != ISDN_PROTO_L2_MODEM)
609 #ifdef CONFIG_ISDN_TTY_FAX
610 && (l2 != ISDN_PROTO_L2_FAX)
613 l2 = ISDN_PROTO_L2_TRANS;
614 usg = ISDN_USAGE_VOICE;
617 m->mdmreg[REG_SI1I] = si2bit[si];
618 spin_lock_irqsave(&dev->lock, flags);
619 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
621 spin_unlock_irqrestore(&dev->lock, flags);
622 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
624 info->isdn_driver = dev->drvmap[i];
625 info->isdn_channel = dev->chanmap[i];
627 dev->m_idx[i] = info->line;
628 dev->usage[i] |= ISDN_USAGE_OUTGOING;
630 strcpy(info->last_num, n);
632 spin_unlock_irqrestore(&dev->lock, flags);
633 cmd.driver = info->isdn_driver;
634 cmd.arg = info->isdn_channel;
635 cmd.command = ISDN_CMD_CLREAZ;
637 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
638 cmd.driver = info->isdn_driver;
639 cmd.command = ISDN_CMD_SETEAZ;
641 cmd.driver = info->isdn_driver;
642 cmd.command = ISDN_CMD_SETL2;
644 cmd.arg = info->isdn_channel + (l2 << 8);
646 cmd.driver = info->isdn_driver;
647 cmd.command = ISDN_CMD_SETL3;
648 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
649 #ifdef CONFIG_ISDN_TTY_FAX
650 if (l2 == ISDN_PROTO_L2_FAX) {
651 cmd.parm.fax = info->fax;
652 info->fax->direction = ISDN_TTY_FAX_CONN_OUT;
656 cmd.driver = info->isdn_driver;
657 cmd.arg = info->isdn_channel;
658 sprintf(cmd.parm.setup.phone, "%s", n);
659 sprintf(cmd.parm.setup.eazmsn, "%s",
660 isdn_map_eaz2msn(m->msn, info->isdn_driver));
661 cmd.parm.setup.si1 = si;
662 cmd.parm.setup.si2 = m->mdmreg[REG_SI2];
663 cmd.command = ISDN_CMD_DIAL;
665 info->emu.carrierwait = 0;
666 strcpy(dev->num[i], n);
669 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
673 /* isdn_tty_hangup() disassociates a tty from the real
674 * ISDN-line (hangup). The usage-status is cleared
675 * and some cleanup is done also.
678 isdn_tty_modem_hup(modem_info * info, int local)
686 di = info->isdn_driver;
687 ch = info->isdn_channel;
688 if (di < 0 || ch < 0)
691 info->isdn_driver = -1;
692 info->isdn_channel = -1;
694 #ifdef ISDN_DEBUG_MODEM_HUP
695 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
698 isdn_tty_flush_buffer(info->tty);
700 info->last_lhup = local;
702 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
704 #ifdef CONFIG_ISDN_AUDIO
706 #ifdef CONFIG_ISDN_TTY_FAX
708 info->fax->phase = ISDN_FAX_PHASE_IDLE;
710 info->emu.vpar[4] = 0;
711 info->emu.vpar[5] = 8;
712 kfree(info->dtmf_state);
713 info->dtmf_state = NULL;
714 kfree(info->silence_state);
715 info->silence_state = NULL;
721 if ((info->msr & UART_MSR_RI) &&
722 (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
723 isdn_tty_modem_result(RESULT_RUNG, info);
724 info->msr &= ~(UART_MSR_DCD | UART_MSR_RI);
725 info->lsr |= UART_LSR_TEMT;
729 cmd.command = ISDN_CMD_HANGUP;
734 isdn_all_eaz(di, ch);
735 info->emu.mdmreg[REG_RINGCNT] = 0;
736 isdn_free_channel(di, ch, 0);
738 if (info->drv_index >= 0) {
739 dev->m_idx[info->drv_index] = -1;
740 info->drv_index = -1;
745 * Begin of a CAPI like interface, currently used only for
746 * supplementary service (CAPI 2.0 part III)
748 #include <linux/isdn/capicmd.h>
751 isdn_tty_capi_facility(capi_msg *cm) {
752 return(-1); /* dummy */
755 /* isdn_tty_suspend() tries to suspend the current tty connection
758 isdn_tty_suspend(char *id, modem_info * info, atemu * m)
767 #ifdef ISDN_DEBUG_MODEM_SERVICES
768 printk(KERN_DEBUG "Msusp ttyI%d\n", info->line);
771 if ((info->isdn_driver >= 0)) {
772 cmd.parm.cmsg.Length = l+18;
773 cmd.parm.cmsg.Command = CAPI_FACILITY;
774 cmd.parm.cmsg.Subcommand = CAPI_REQ;
775 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
776 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
777 cmd.parm.cmsg.para[1] = 0;
778 cmd.parm.cmsg.para[2] = l + 3;
779 cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
780 cmd.parm.cmsg.para[4] = 0;
781 cmd.parm.cmsg.para[5] = l;
782 strncpy(&cmd.parm.cmsg.para[6], id, l);
783 cmd.command = CAPI_PUT_MESSAGE;
784 cmd.driver = info->isdn_driver;
785 cmd.arg = info->isdn_channel;
790 /* isdn_tty_resume() tries to resume a suspended call
791 * setup of the lower levels before that. unfortunatly here is no
792 * checking for compatibility of used protocols implemented by Q931
793 * It does the same things like isdn_tty_dial, the last command
794 * is different, may be we can merge it.
798 isdn_tty_resume(char *id, modem_info * info, atemu * m)
800 int usg = ISDN_USAGE_MODEM;
802 int l2 = m->mdmreg[REG_L2PROT];
810 for (j = 7; j >= 0; j--)
811 if (m->mdmreg[REG_SI1] & (1 << j)) {
815 usg = isdn_calc_usage(si, l2);
816 #ifdef CONFIG_ISDN_AUDIO
818 (l2 != ISDN_PROTO_L2_MODEM)
819 #ifdef CONFIG_ISDN_TTY_FAX
820 && (l2 != ISDN_PROTO_L2_FAX)
823 l2 = ISDN_PROTO_L2_TRANS;
824 usg = ISDN_USAGE_VOICE;
827 m->mdmreg[REG_SI1I] = si2bit[si];
828 spin_lock_irqsave(&dev->lock, flags);
829 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
831 spin_unlock_irqrestore(&dev->lock, flags);
832 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
834 info->isdn_driver = dev->drvmap[i];
835 info->isdn_channel = dev->chanmap[i];
837 dev->m_idx[i] = info->line;
838 dev->usage[i] |= ISDN_USAGE_OUTGOING;
840 // strcpy(info->last_num, n);
842 spin_unlock_irqrestore(&dev->lock, flags);
843 cmd.driver = info->isdn_driver;
844 cmd.arg = info->isdn_channel;
845 cmd.command = ISDN_CMD_CLREAZ;
847 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
848 cmd.driver = info->isdn_driver;
849 cmd.command = ISDN_CMD_SETEAZ;
851 cmd.driver = info->isdn_driver;
852 cmd.command = ISDN_CMD_SETL2;
854 cmd.arg = info->isdn_channel + (l2 << 8);
856 cmd.driver = info->isdn_driver;
857 cmd.command = ISDN_CMD_SETL3;
858 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
860 cmd.driver = info->isdn_driver;
861 cmd.arg = info->isdn_channel;
862 cmd.parm.cmsg.Length = l+18;
863 cmd.parm.cmsg.Command = CAPI_FACILITY;
864 cmd.parm.cmsg.Subcommand = CAPI_REQ;
865 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
866 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
867 cmd.parm.cmsg.para[1] = 0;
868 cmd.parm.cmsg.para[2] = l+3;
869 cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
870 cmd.parm.cmsg.para[4] = 0;
871 cmd.parm.cmsg.para[5] = l;
872 strncpy(&cmd.parm.cmsg.para[6], id, l);
873 cmd.command =CAPI_PUT_MESSAGE;
875 // strcpy(dev->num[i], n);
878 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
882 /* isdn_tty_send_msg() sends a message to a HL driver
883 * This is used for hybrid modem cards to send AT commands to it
887 isdn_tty_send_msg(modem_info * info, atemu * m, char *msg)
889 int usg = ISDN_USAGE_MODEM;
891 int l2 = m->mdmreg[REG_L2PROT];
900 isdn_tty_modem_result(RESULT_ERROR, info);
903 for (j = 7; j >= 0; j--)
904 if (m->mdmreg[REG_SI1] & (1 << j)) {
908 usg = isdn_calc_usage(si, l2);
909 #ifdef CONFIG_ISDN_AUDIO
911 (l2 != ISDN_PROTO_L2_MODEM)
912 #ifdef CONFIG_ISDN_TTY_FAX
913 && (l2 != ISDN_PROTO_L2_FAX)
916 l2 = ISDN_PROTO_L2_TRANS;
917 usg = ISDN_USAGE_VOICE;
920 m->mdmreg[REG_SI1I] = si2bit[si];
921 spin_lock_irqsave(&dev->lock, flags);
922 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
924 spin_unlock_irqrestore(&dev->lock, flags);
925 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
927 info->isdn_driver = dev->drvmap[i];
928 info->isdn_channel = dev->chanmap[i];
930 dev->m_idx[i] = info->line;
931 dev->usage[i] |= ISDN_USAGE_OUTGOING;
934 spin_unlock_irqrestore(&dev->lock, flags);
935 cmd.driver = info->isdn_driver;
936 cmd.arg = info->isdn_channel;
937 cmd.command = ISDN_CMD_CLREAZ;
939 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
940 cmd.driver = info->isdn_driver;
941 cmd.command = ISDN_CMD_SETEAZ;
943 cmd.driver = info->isdn_driver;
944 cmd.command = ISDN_CMD_SETL2;
946 cmd.arg = info->isdn_channel + (l2 << 8);
948 cmd.driver = info->isdn_driver;
949 cmd.command = ISDN_CMD_SETL3;
950 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
952 cmd.driver = info->isdn_driver;
953 cmd.arg = info->isdn_channel;
954 cmd.parm.cmsg.Length = l+14;
955 cmd.parm.cmsg.Command = CAPI_MANUFACTURER;
956 cmd.parm.cmsg.Subcommand = CAPI_REQ;
957 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
958 cmd.parm.cmsg.para[0] = l+1;
959 strncpy(&cmd.parm.cmsg.para[1], msg, l);
960 cmd.parm.cmsg.para[l+1] = 0xd;
961 cmd.command =CAPI_PUT_MESSAGE;
962 /* info->dialing = 1;
963 strcpy(dev->num[i], n);
971 isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine)
973 #ifdef MODEM_PARANOIA_CHECK
975 printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n",
979 if (info->magic != ISDN_ASYNC_MAGIC) {
980 printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n",
989 * This routine is called to set the UART divisor registers to match
990 * the specified baud rate for a serial port.
993 isdn_tty_change_speed(modem_info * info)
1001 if (!info->tty || !info->tty->termios)
1003 cflag = info->tty->termios->c_cflag;
1005 quot = i = cflag & CBAUD;
1009 info->tty->termios->c_cflag &= ~CBAUDEX;
1014 info->mcr |= UART_MCR_DTR;
1015 isdn_tty_modem_ncarrier(info);
1017 info->mcr &= ~UART_MCR_DTR;
1018 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1019 #ifdef ISDN_DEBUG_MODEM_HUP
1020 printk(KERN_DEBUG "Mhup in changespeed\n");
1024 isdn_tty_modem_reset_regs(info, 0);
1025 isdn_tty_modem_hup(info, 1);
1029 /* byte size and parity */
1030 cval = cflag & (CSIZE | CSTOPB);
1033 cval |= UART_LCR_PARITY;
1034 if (!(cflag & PARODD))
1035 cval |= UART_LCR_EPAR;
1038 /* CTS flow control flag and modem status interrupts */
1039 if (cflag & CRTSCTS) {
1040 info->flags |= ISDN_ASYNC_CTS_FLOW;
1042 info->flags &= ~ISDN_ASYNC_CTS_FLOW;
1044 info->flags &= ~ISDN_ASYNC_CHECK_CD;
1046 info->flags |= ISDN_ASYNC_CHECK_CD;
1051 isdn_tty_startup(modem_info * info)
1053 if (info->flags & ISDN_ASYNC_INITIALIZED)
1055 isdn_lock_drivers();
1056 #ifdef ISDN_DEBUG_MODEM_OPEN
1057 printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line);
1060 * Now, initialize the UART
1062 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
1064 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1066 * and set the speed of the serial port
1068 isdn_tty_change_speed(info);
1070 info->flags |= ISDN_ASYNC_INITIALIZED;
1071 info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
1072 info->send_outstanding = 0;
1077 * This routine will shutdown a serial port; interrupts are disabled, and
1078 * DTR is dropped if the hangup on close termio flag is on.
1081 isdn_tty_shutdown(modem_info * info)
1083 if (!(info->flags & ISDN_ASYNC_INITIALIZED))
1085 #ifdef ISDN_DEBUG_MODEM_OPEN
1086 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
1088 isdn_unlock_drivers();
1089 info->msr &= ~UART_MSR_RI;
1090 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1091 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
1092 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1093 isdn_tty_modem_reset_regs(info, 0);
1094 #ifdef ISDN_DEBUG_MODEM_HUP
1095 printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n");
1097 isdn_tty_modem_hup(info, 1);
1101 set_bit(TTY_IO_ERROR, &info->tty->flags);
1103 info->flags &= ~ISDN_ASYNC_INITIALIZED;
1106 /* isdn_tty_write() is the main send-routine. It is called from the upper
1107 * levels within the kernel to perform sending data. Depending on the
1108 * online-flag it either directs output to the at-command-interpreter or
1109 * to the lower level. Additional tasks done here:
1110 * - If online, check for escape-sequence (+++)
1111 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1112 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1113 * - If dialing, abort dial.
1116 isdn_tty_write(struct tty_struct *tty, const u_char * buf, int count)
1120 modem_info *info = (modem_info *) tty->driver_data;
1121 atemu *m = &info->emu;
1123 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write"))
1125 /* See isdn_tty_senddown() */
1126 atomic_inc(&info->xmit_lock);
1129 if (c > info->xmit_size - info->xmit_count)
1130 c = info->xmit_size - info->xmit_count;
1131 if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize)
1132 c = dev->drv[info->isdn_driver]->maxbufsize;
1135 if ((info->online > 1)
1136 #ifdef CONFIG_ISDN_AUDIO
1137 || (info->vonline & 3)
1140 #ifdef CONFIG_ISDN_AUDIO
1143 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
1146 memcpy(&(info->xmit_buf[info->xmit_count]), buf, c);
1147 #ifdef CONFIG_ISDN_AUDIO
1148 if (info->vonline) {
1149 int cc = isdn_tty_handleDLEdown(info, m, c);
1150 if (info->vonline & 2) {
1152 /* If DLE decoding results in zero-transmit, but
1153 * c originally was non-zero, do a wakeup.
1156 info->msr |= UART_MSR_CTS;
1157 info->lsr |= UART_LSR_TEMT;
1159 info->xmit_count += cc;
1161 if ((info->vonline & 3) == 1) {
1162 /* Do NOT handle Ctrl-Q or Ctrl-S
1163 * when in full-duplex audio mode.
1165 if (isdn_tty_end_vrx(buf, c)) {
1166 info->vonline &= ~1;
1167 #ifdef ISDN_DEBUG_MODEM_VOICE
1169 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1172 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
1176 if (TTY_IS_FCLASS1(info)) {
1177 int cc = isdn_tty_handleDLEdown(info, m, c);
1179 if (info->vonline & 4) { /* ETX seen */
1182 c.command = ISDN_CMD_FAXCMD;
1183 c.driver = info->isdn_driver;
1184 c.arg = info->isdn_channel;
1185 c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
1186 c.parm.aux.subcmd = ETX;
1190 #ifdef ISDN_DEBUG_MODEM_VOICE
1191 printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c);
1193 info->xmit_count += cc;
1196 info->xmit_count += c;
1198 info->msr |= UART_MSR_CTS;
1199 info->lsr |= UART_LSR_TEMT;
1200 if (info->dialing) {
1202 #ifdef ISDN_DEBUG_MODEM_HUP
1203 printk(KERN_DEBUG "Mhup in isdn_tty_write\n");
1205 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
1206 isdn_tty_modem_hup(info, 1);
1208 c = isdn_tty_edit_at(buf, c, info);
1214 atomic_dec(&info->xmit_lock);
1215 if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) {
1216 if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
1217 isdn_tty_senddown(info);
1218 isdn_tty_tint(info);
1220 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1226 isdn_tty_write_room(struct tty_struct *tty)
1228 modem_info *info = (modem_info *) tty->driver_data;
1231 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room"))
1234 return info->xmit_size;
1235 ret = info->xmit_size - info->xmit_count;
1236 return (ret < 0) ? 0 : ret;
1240 isdn_tty_chars_in_buffer(struct tty_struct *tty)
1242 modem_info *info = (modem_info *) tty->driver_data;
1244 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer"))
1248 return (info->xmit_count);
1252 isdn_tty_flush_buffer(struct tty_struct *tty)
1259 info = (modem_info *) tty->driver_data;
1260 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) {
1263 isdn_tty_cleanup_xmit(info);
1264 info->xmit_count = 0;
1265 wake_up_interruptible(&tty->write_wait);
1270 isdn_tty_flush_chars(struct tty_struct *tty)
1272 modem_info *info = (modem_info *) tty->driver_data;
1274 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars"))
1276 if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue))
1277 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1281 * ------------------------------------------------------------
1282 * isdn_tty_throttle()
1284 * This routine is called by the upper-layer tty layer to signal that
1285 * incoming characters should be throttled.
1286 * ------------------------------------------------------------
1289 isdn_tty_throttle(struct tty_struct *tty)
1291 modem_info *info = (modem_info *) tty->driver_data;
1293 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle"))
1296 info->x_char = STOP_CHAR(tty);
1297 info->mcr &= ~UART_MCR_RTS;
1301 isdn_tty_unthrottle(struct tty_struct *tty)
1303 modem_info *info = (modem_info *) tty->driver_data;
1305 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle"))
1311 info->x_char = START_CHAR(tty);
1313 info->mcr |= UART_MCR_RTS;
1317 * ------------------------------------------------------------
1318 * isdn_tty_ioctl() and friends
1319 * ------------------------------------------------------------
1323 * isdn_tty_get_lsr_info - get line status register info
1325 * Purpose: Let user call ioctl() to get info when the UART physically
1326 * is emptied. On bus types like RS485, the transmitter must
1327 * release the bus after transmitting. This must be done when
1328 * the transmit shift register is empty, not be done when the
1329 * transmit holding register is empty. This functionality
1330 * allows RS485 driver to be written in user space.
1333 isdn_tty_get_lsr_info(modem_info * info, uint __user * value)
1339 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1340 return put_user(result, value);
1345 isdn_tty_tiocmget(struct tty_struct *tty, struct file *file)
1347 modem_info *info = (modem_info *) tty->driver_data;
1348 u_char control, status;
1350 if (isdn_tty_paranoia_check(info, tty->name, __FUNCTION__))
1352 if (tty->flags & (1 << TTY_IO_ERROR))
1355 #ifdef ISDN_DEBUG_MODEM_IOCTL
1356 printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
1359 control = info->mcr;
1361 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1362 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1363 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1364 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1365 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1366 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1370 isdn_tty_tiocmset(struct tty_struct *tty, struct file *file,
1371 unsigned int set, unsigned int clear)
1373 modem_info *info = (modem_info *) tty->driver_data;
1375 if (isdn_tty_paranoia_check(info, tty->name, __FUNCTION__))
1377 if (tty->flags & (1 << TTY_IO_ERROR))
1380 #ifdef ISDN_DEBUG_MODEM_IOCTL
1381 printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear);
1384 if (set & TIOCM_RTS)
1385 info->mcr |= UART_MCR_RTS;
1386 if (set & TIOCM_DTR) {
1387 info->mcr |= UART_MCR_DTR;
1388 isdn_tty_modem_ncarrier(info);
1391 if (clear & TIOCM_RTS)
1392 info->mcr &= ~UART_MCR_RTS;
1393 if (clear & TIOCM_DTR) {
1394 info->mcr &= ~UART_MCR_DTR;
1395 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1396 isdn_tty_modem_reset_regs(info, 0);
1397 #ifdef ISDN_DEBUG_MODEM_HUP
1398 printk(KERN_DEBUG "Mhup in TIOCMSET\n");
1402 isdn_tty_modem_hup(info, 1);
1409 isdn_tty_ioctl(struct tty_struct *tty, struct file *file,
1410 uint cmd, ulong arg)
1412 modem_info *info = (modem_info *) tty->driver_data;
1415 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl"))
1417 if (tty->flags & (1 << TTY_IO_ERROR))
1420 case TCSBRK: /* SVID version: non-zero arg --> no break */
1421 #ifdef ISDN_DEBUG_MODEM_IOCTL
1422 printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line);
1424 retval = tty_check_change(tty);
1427 tty_wait_until_sent(tty, 0);
1429 case TCSBRKP: /* support for POSIX tcsendbreak() */
1430 #ifdef ISDN_DEBUG_MODEM_IOCTL
1431 printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line);
1433 retval = tty_check_change(tty);
1436 tty_wait_until_sent(tty, 0);
1439 #ifdef ISDN_DEBUG_MODEM_IOCTL
1440 printk(KERN_DEBUG "ttyI%d ioctl TIOCGSOFTCAR\n", info->line);
1442 return put_user(C_CLOCAL(tty) ? 1 : 0, (ulong __user *) arg);
1444 #ifdef ISDN_DEBUG_MODEM_IOCTL
1445 printk(KERN_DEBUG "ttyI%d ioctl TIOCSSOFTCAR\n", info->line);
1447 if (get_user(arg, (ulong __user *) arg))
1449 tty->termios->c_cflag =
1450 ((tty->termios->c_cflag & ~CLOCAL) |
1451 (arg ? CLOCAL : 0));
1453 case TIOCSERGETLSR: /* Get line status register */
1454 #ifdef ISDN_DEBUG_MODEM_IOCTL
1455 printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);
1457 return isdn_tty_get_lsr_info(info, (uint __user *) arg);
1459 #ifdef ISDN_DEBUG_MODEM_IOCTL
1460 printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line);
1462 return -ENOIOCTLCMD;
1468 isdn_tty_set_termios(struct tty_struct *tty, struct termios *old_termios)
1470 modem_info *info = (modem_info *) tty->driver_data;
1473 isdn_tty_change_speed(info);
1475 if (tty->termios->c_cflag == old_termios->c_cflag)
1477 isdn_tty_change_speed(info);
1478 if ((old_termios->c_cflag & CRTSCTS) &&
1479 !(tty->termios->c_cflag & CRTSCTS)) {
1480 tty->hw_stopped = 0;
1486 * ------------------------------------------------------------
1487 * isdn_tty_open() and friends
1488 * ------------------------------------------------------------
1491 isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info * info)
1493 DECLARE_WAITQUEUE(wait, NULL);
1498 * If the device is in the middle of being closed, then block
1499 * until it's done, and then try again.
1501 if (tty_hung_up_p(filp) ||
1502 (info->flags & ISDN_ASYNC_CLOSING)) {
1503 if (info->flags & ISDN_ASYNC_CLOSING)
1504 interruptible_sleep_on(&info->close_wait);
1505 #ifdef MODEM_DO_RESTART
1506 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1509 return -ERESTARTSYS;
1515 * If non-blocking mode is set, then make the check up front
1518 if ((filp->f_flags & O_NONBLOCK) ||
1519 (tty->flags & (1 << TTY_IO_ERROR))) {
1520 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1522 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1525 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) {
1526 if (info->normal_termios.c_cflag & CLOCAL)
1529 if (tty->termios->c_cflag & CLOCAL)
1533 * Block waiting for the carrier detect and the line to become
1534 * free (i.e., not in use by the callout). While we are in
1535 * this loop, info->count is dropped by one, so that
1536 * isdn_tty_close() knows when to free things. We restore it upon
1537 * exit, either normal or abnormal.
1540 add_wait_queue(&info->open_wait, &wait);
1541 #ifdef ISDN_DEBUG_MODEM_OPEN
1542 printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1543 info->line, info->count);
1545 if (!(tty_hung_up_p(filp)))
1547 info->blocked_open++;
1549 set_current_state(TASK_INTERRUPTIBLE);
1550 if (tty_hung_up_p(filp) ||
1551 !(info->flags & ISDN_ASYNC_INITIALIZED)) {
1552 #ifdef MODEM_DO_RESTART
1553 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1556 retval = -ERESTARTSYS;
1562 if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
1563 !(info->flags & ISDN_ASYNC_CLOSING) &&
1564 (do_clocal || (info->msr & UART_MSR_DCD))) {
1567 if (signal_pending(current)) {
1568 retval = -ERESTARTSYS;
1571 #ifdef ISDN_DEBUG_MODEM_OPEN
1572 printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1573 info->line, info->count);
1577 current->state = TASK_RUNNING;
1578 remove_wait_queue(&info->open_wait, &wait);
1579 if (!tty_hung_up_p(filp))
1581 info->blocked_open--;
1582 #ifdef ISDN_DEBUG_MODEM_OPEN
1583 printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1584 info->line, info->count);
1588 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1593 * This routine is called whenever a serial port is opened. It
1594 * enables interrupts for a serial port, linking in its async structure into
1595 * the IRQ chain. It also performs the serial-specific
1596 * initialization for the tty structure.
1599 isdn_tty_open(struct tty_struct *tty, struct file *filp)
1605 if (line < 0 || line > ISDN_MAX_CHANNELS)
1607 info = &dev->mdm.info[line];
1608 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))
1610 if (!try_module_get(info->owner)) {
1611 printk(KERN_WARNING "%s: cannot reserve module\n", __FUNCTION__);
1614 #ifdef ISDN_DEBUG_MODEM_OPEN
1615 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
1619 tty->driver_data = info;
1622 * Start up serial port
1624 retval = isdn_tty_startup(info);
1626 #ifdef ISDN_DEBUG_MODEM_OPEN
1627 printk(KERN_DEBUG "isdn_tty_open return after startup\n");
1629 module_put(info->owner);
1632 retval = isdn_tty_block_til_ready(tty, filp, info);
1634 #ifdef ISDN_DEBUG_MODEM_OPEN
1635 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");
1637 module_put(info->owner);
1640 #ifdef ISDN_DEBUG_MODEM_OPEN
1641 printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line);
1644 #ifdef ISDN_DEBUG_MODEM_OPEN
1645 printk(KERN_DEBUG "isdn_tty_open normal exit\n");
1651 isdn_tty_close(struct tty_struct *tty, struct file *filp)
1653 modem_info *info = (modem_info *) tty->driver_data;
1656 if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close"))
1658 if (tty_hung_up_p(filp)) {
1659 #ifdef ISDN_DEBUG_MODEM_OPEN
1660 printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n");
1664 if ((tty->count == 1) && (info->count != 1)) {
1666 * Uh, oh. tty->count is 1, which means that the tty
1667 * structure will be freed. Info->count should always
1668 * be one in these conditions. If it's greater than
1669 * one, we've got real problems, since it means the
1670 * serial port won't be shutdown.
1672 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
1673 "info->count is %d\n", info->count);
1676 if (--info->count < 0) {
1677 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
1678 info->line, info->count);
1682 #ifdef ISDN_DEBUG_MODEM_OPEN
1683 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
1685 module_put(info->owner);
1688 info->flags |= ISDN_ASYNC_CLOSING;
1690 * Save the termios structure, since this port may have
1691 * separate termios for callout and dialin.
1693 if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)
1694 info->normal_termios = *tty->termios;
1695 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1696 info->callout_termios = *tty->termios;
1700 * At this point we stop accepting input. To do this, we
1701 * disable the receive line status interrupts, and tell the
1702 * interrupt driver to stop checking the data ready bit in the
1703 * line status register.
1705 if (info->flags & ISDN_ASYNC_INITIALIZED) {
1706 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1708 * Before we drop DTR, make sure the UART transmitter
1709 * has completely drained; this is especially
1710 * important if there is a transmit FIFO!
1712 timeout = jiffies + HZ;
1713 while (!(info->lsr & UART_LSR_TEMT)) {
1714 schedule_timeout_interruptible(20);
1715 if (time_after(jiffies,timeout))
1720 isdn_tty_shutdown(info);
1722 if (tty->driver->flush_buffer)
1723 tty->driver->flush_buffer(tty);
1724 tty_ldisc_flush(tty);
1728 module_put(info->owner);
1729 if (info->blocked_open) {
1730 msleep_interruptible(500);
1731 wake_up_interruptible(&info->open_wait);
1733 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CLOSING);
1734 wake_up_interruptible(&info->close_wait);
1735 #ifdef ISDN_DEBUG_MODEM_OPEN
1736 printk(KERN_DEBUG "isdn_tty_close normal exit\n");
1741 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1744 isdn_tty_hangup(struct tty_struct *tty)
1746 modem_info *info = (modem_info *) tty->driver_data;
1748 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
1750 isdn_tty_shutdown(info);
1752 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE);
1754 wake_up_interruptible(&info->open_wait);
1757 /* This routine initializes all emulator-data.
1760 isdn_tty_reset_profile(atemu * m)
1773 m->profile[11] = 70;
1774 m->profile[12] = 0x45;
1776 m->profile[14] = ISDN_PROTO_L2_X75I;
1777 m->profile[15] = ISDN_PROTO_L3_TRANS;
1778 m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16;
1779 m->profile[17] = ISDN_MODEM_WINSIZE;
1788 #ifdef CONFIG_ISDN_AUDIO
1790 isdn_tty_modem_reset_vpar(atemu * m)
1792 m->vpar[0] = 2; /* Voice-device (2 = phone line) */
1793 m->vpar[1] = 0; /* Silence detection level (0 = none ) */
1794 m->vpar[2] = 70; /* Silence interval (7 sec. ) */
1795 m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1796 m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */
1797 m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1801 #ifdef CONFIG_ISDN_TTY_FAX
1803 isdn_tty_modem_reset_faxpar(modem_info * info)
1805 T30_s *f = info->fax;
1808 f->phase = ISDN_FAX_PHASE_IDLE;
1810 f->resolution = 1; /* fine */
1811 f->rate = 5; /* 14400 bit/s */
1818 memset(&f->id[0], 32, FAXIDLEN - 1);
1819 f->id[FAXIDLEN - 1] = 0;
1830 memset(&f->pollid[0], 32, FAXIDLEN - 1);
1831 f->pollid[FAXIDLEN - 1] = 0;
1836 isdn_tty_modem_reset_regs(modem_info * info, int force)
1838 atemu *m = &info->emu;
1839 if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {
1840 memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);
1841 memcpy(m->msn, m->pmsn, ISDN_MSNLEN);
1842 memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);
1843 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
1845 #ifdef CONFIG_ISDN_AUDIO
1846 isdn_tty_modem_reset_vpar(m);
1848 #ifdef CONFIG_ISDN_TTY_FAX
1849 isdn_tty_modem_reset_faxpar(info);
1855 modem_write_profile(atemu * m)
1857 memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG);
1858 memcpy(m->pmsn, m->msn, ISDN_MSNLEN);
1859 memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN);
1861 send_sig(SIGIO, dev->profd, 1);
1864 static struct tty_operations modem_ops = {
1865 .open = isdn_tty_open,
1866 .close = isdn_tty_close,
1867 .write = isdn_tty_write,
1868 .flush_chars = isdn_tty_flush_chars,
1869 .write_room = isdn_tty_write_room,
1870 .chars_in_buffer = isdn_tty_chars_in_buffer,
1871 .flush_buffer = isdn_tty_flush_buffer,
1872 .ioctl = isdn_tty_ioctl,
1873 .throttle = isdn_tty_throttle,
1874 .unthrottle = isdn_tty_unthrottle,
1875 .set_termios = isdn_tty_set_termios,
1876 .hangup = isdn_tty_hangup,
1877 .tiocmget = isdn_tty_tiocmget,
1878 .tiocmset = isdn_tty_tiocmset,
1882 isdn_tty_modem_init(void)
1889 m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS);
1892 m->tty_modem->name = "ttyI";
1893 m->tty_modem->devfs_name = "isdn/ttyI";
1894 m->tty_modem->major = ISDN_TTY_MAJOR;
1895 m->tty_modem->minor_start = 0;
1896 m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL;
1897 m->tty_modem->subtype = SERIAL_TYPE_NORMAL;
1898 m->tty_modem->init_termios = tty_std_termios;
1899 m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1900 m->tty_modem->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
1901 m->tty_modem->driver_name = "isdn_tty";
1902 tty_set_operations(m->tty_modem, &modem_ops);
1903 retval = tty_register_driver(m->tty_modem);
1905 printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n");
1908 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1910 #ifdef CONFIG_ISDN_TTY_FAX
1911 if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) {
1912 printk(KERN_ERR "Could not allocate fax t30-buffer\n");
1914 goto err_unregister;
1918 info->owner = THIS_MODULE;
1920 spin_lock_init(&info->readlock);
1921 init_MUTEX(&info->write_sem);
1922 sprintf(info->last_cause, "0000");
1923 sprintf(info->last_num, "none");
1925 info->last_lhup = 1;
1928 isdn_tty_reset_profile(&info->emu);
1929 isdn_tty_modem_reset_regs(info, 1);
1930 info->magic = ISDN_ASYNC_MAGIC;
1935 info->blocked_open = 0;
1936 init_waitqueue_head(&info->open_wait);
1937 init_waitqueue_head(&info->close_wait);
1938 info->isdn_driver = -1;
1939 info->isdn_channel = -1;
1940 info->drv_index = -1;
1941 info->xmit_size = ISDN_SERIAL_XMIT_SIZE;
1942 init_timer(&info->nc_timer);
1943 info->nc_timer.function = isdn_tty_modem_do_ncarrier;
1944 info->nc_timer.data = (unsigned long) info;
1945 skb_queue_head_init(&info->xmit_queue);
1946 #ifdef CONFIG_ISDN_AUDIO
1947 skb_queue_head_init(&info->dtmf_queue);
1949 if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) {
1950 printk(KERN_ERR "Could not allocate modem xmit-buffer\n");
1952 goto err_unregister;
1954 /* Make room for T.70 header */
1955 info->xmit_buf += 4;
1959 for (i--; i >= 0; i--) {
1961 #ifdef CONFIG_ISDN_TTY_FAX
1964 kfree(info->xmit_buf - 4);
1966 tty_unregister_driver(m->tty_modem);
1968 put_tty_driver(m->tty_modem);
1969 m->tty_modem = NULL;
1979 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1980 info = &dev->mdm.info[i];
1981 isdn_tty_cleanup_xmit(info);
1982 #ifdef CONFIG_ISDN_TTY_FAX
1985 kfree(info->xmit_buf - 4);
1987 tty_unregister_driver(dev->mdm.tty_modem);
1988 put_tty_driver(dev->mdm.tty_modem);
1989 dev->mdm.tty_modem = NULL;
1994 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
1995 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
1996 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
2000 isdn_tty_match_icall(char *cid, atemu *emu, int di)
2002 #ifdef ISDN_DEBUG_MODEM_ICALL
2003 printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
2004 emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di),
2005 emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]);
2007 if (strlen(emu->lmsn)) {
2008 char *p = emu->lmsn;
2014 if ((q = strchr(p, ';')))
2016 if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret)
2018 #ifdef ISDN_DEBUG_MODEM_ICALL
2019 printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2020 p, isdn_map_eaz2msn(emu->msn, di), tmp);
2035 tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di));
2036 #ifdef ISDN_DEBUG_MODEM_ICALL
2037 printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n",
2038 isdn_map_eaz2msn(emu->msn, di), tmp);
2045 * An incoming call-request has arrived.
2046 * Search the tty-devices for an appropriate device and bind
2047 * it to the ISDN-Channel.
2050 * 0 = No matching device found.
2051 * 1 = A matching device found.
2052 * 3 = No match found, but eventually would match, if
2056 isdn_tty_find_icall(int di, int ch, setup_parm *setup)
2067 if (!setup->phone[0]) {
2069 printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n");
2072 si1 = (int) setup->si1;
2073 si2 = (int) setup->si2;
2074 if (!setup->eazmsn[0]) {
2075 printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n");
2078 eaz = setup->eazmsn;
2079 #ifdef ISDN_DEBUG_MODEM_ICALL
2080 printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2);
2083 spin_lock_irqsave(&dev->lock, flags);
2084 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2085 modem_info *info = &dev->mdm.info[i];
2087 if (info->count == 0)
2089 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
2090 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
2091 idx = isdn_dc2minor(di, ch);
2092 #ifdef ISDN_DEBUG_MODEM_ICALL
2093 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret);
2094 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx,
2095 info->flags, info->isdn_driver, info->isdn_channel,
2099 #ifndef FIX_FILE_TRANSFER
2100 (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) &&
2102 (info->isdn_driver == -1) &&
2103 (info->isdn_channel == -1) &&
2104 (USG_NONE(dev->usage[idx]))) {
2107 if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret)
2109 if (!matchret) { /* EAZ is matching */
2110 info->isdn_driver = di;
2111 info->isdn_channel = ch;
2112 info->drv_index = idx;
2113 dev->m_idx[idx] = info->line;
2114 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2115 dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]);
2116 strcpy(dev->num[idx], nr);
2117 strcpy(info->emu.cpn, eaz);
2118 info->emu.mdmreg[REG_SI1I] = si2bit[si1];
2119 info->emu.mdmreg[REG_PLAN] = setup->plan;
2120 info->emu.mdmreg[REG_SCREEN] = setup->screen;
2122 spin_unlock_irqrestore(&dev->lock, flags);
2123 printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr,
2125 info->msr |= UART_MSR_RI;
2126 isdn_tty_modem_result(RESULT_RING, info);
2127 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1);
2133 spin_unlock_irqrestore(&dev->lock, flags);
2134 printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz,
2135 ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2))? "rejected" : "ignored");
2136 return (wret == 2)?3:0;
2139 #define TTY_IS_ACTIVE(info) \
2140 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2143 isdn_tty_stat_callback(int i, isdn_ctrl *c)
2151 if ((mi = dev->m_idx[i]) >= 0) {
2152 info = &dev->mdm.info[mi];
2153 switch (c->command) {
2154 case ISDN_STAT_CINF:
2155 printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num);
2156 info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10);
2157 if (e == (char *)c->parm.num)
2158 info->emu.charge = 0;
2161 case ISDN_STAT_BSENT:
2162 #ifdef ISDN_TTY_STAT_DEBUG
2163 printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line);
2165 if ((info->isdn_driver == c->driver) &&
2166 (info->isdn_channel == c->arg)) {
2167 info->msr |= UART_MSR_CTS;
2168 if (info->send_outstanding)
2169 if (!(--info->send_outstanding))
2170 info->lsr |= UART_LSR_TEMT;
2171 isdn_tty_tint(info);
2175 case ISDN_STAT_CAUSE:
2176 #ifdef ISDN_TTY_STAT_DEBUG
2177 printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line);
2179 /* Signal cause to tty-device */
2180 strncpy(info->last_cause, c->parm.num, 5);
2182 case ISDN_STAT_DISPLAY:
2183 #ifdef ISDN_TTY_STAT_DEBUG
2184 printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line);
2186 /* Signal display to tty-device */
2187 if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) &&
2188 !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) {
2189 isdn_tty_at_cout("\r\n", info);
2190 isdn_tty_at_cout("DISPLAY: ", info);
2191 isdn_tty_at_cout(c->parm.display, info);
2192 isdn_tty_at_cout("\r\n", info);
2195 case ISDN_STAT_DCONN:
2196 #ifdef ISDN_TTY_STAT_DEBUG
2197 printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line);
2199 if (TTY_IS_ACTIVE(info)) {
2200 if (info->dialing == 1) {
2206 case ISDN_STAT_DHUP:
2207 #ifdef ISDN_TTY_STAT_DEBUG
2208 printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
2210 if (TTY_IS_ACTIVE(info)) {
2211 if (info->dialing == 1)
2212 isdn_tty_modem_result(RESULT_BUSY, info);
2213 if (info->dialing > 1)
2214 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
2216 #ifdef ISDN_DEBUG_MODEM_HUP
2217 printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n");
2219 isdn_tty_modem_hup(info, 0);
2223 case ISDN_STAT_BCONN:
2224 #ifdef ISDN_TTY_STAT_DEBUG
2225 printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line);
2227 /* Wake up any processes waiting
2228 * for incoming call of this device when
2229 * DCD follow the state of incoming carrier
2231 if (info->blocked_open &&
2232 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) {
2233 wake_up_interruptible(&info->open_wait);
2236 /* Schedule CONNECT-Message to any tty
2237 * waiting for it and
2238 * set DCD-bit of its modem-status.
2240 if (TTY_IS_ACTIVE(info) ||
2241 (info->blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
2242 info->msr |= UART_MSR_DCD;
2243 info->emu.charge = 0;
2244 if (info->dialing & 0xf)
2250 if (USG_MODEM(dev->usage[i])) {
2251 if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) {
2252 strcpy(info->emu.connmsg, c->parm.num);
2253 isdn_tty_modem_result(RESULT_CONNECT, info);
2255 isdn_tty_modem_result(RESULT_CONNECT64000, info);
2257 if (USG_VOICE(dev->usage[i]))
2258 isdn_tty_modem_result(RESULT_VCON, info);
2262 case ISDN_STAT_BHUP:
2263 #ifdef ISDN_TTY_STAT_DEBUG
2264 printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
2266 if (TTY_IS_ACTIVE(info)) {
2267 #ifdef ISDN_DEBUG_MODEM_HUP
2268 printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
2270 isdn_tty_modem_hup(info, 0);
2274 case ISDN_STAT_NODCH:
2275 #ifdef ISDN_TTY_STAT_DEBUG
2276 printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line);
2278 if (TTY_IS_ACTIVE(info)) {
2279 if (info->dialing) {
2283 sprintf(info->last_cause, "0000");
2284 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
2286 isdn_tty_modem_hup(info, 0);
2290 case ISDN_STAT_UNLOAD:
2291 #ifdef ISDN_TTY_STAT_DEBUG
2292 printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line);
2294 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2295 info = &dev->mdm.info[i];
2296 if (info->isdn_driver == c->driver) {
2298 isdn_tty_modem_hup(info, 1);
2302 #ifdef CONFIG_ISDN_TTY_FAX
2303 case ISDN_STAT_FAXIND:
2304 if (TTY_IS_ACTIVE(info)) {
2305 isdn_tty_fax_command(info, c);
2309 #ifdef CONFIG_ISDN_AUDIO
2310 case ISDN_STAT_AUDIO:
2311 if (TTY_IS_ACTIVE(info)) {
2312 switch(c->parm.num[0]) {
2313 case ISDN_AUDIO_DTMF:
2314 if (info->vonline) {
2315 isdn_audio_put_dle_code(info,
2328 /*********************************************************************
2329 Modem-Emulator-Routines
2330 *********************************************************************/
2332 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2335 * Put a message from the AT-emulator into receive-buffer of tty,
2336 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2339 isdn_tty_at_cout(char *msg, modem_info * info)
2341 struct tty_struct *tty;
2342 atemu *m = &info->emu;
2346 struct sk_buff *skb = NULL;
2348 int l = strlen(msg);
2351 printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
2354 spin_lock_irqsave(&info->readlock, flags);
2356 if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) {
2357 spin_unlock_irqrestore(&info->readlock, flags);
2361 /* use queue instead of direct, if online and */
2362 /* data is in queue or buffer is full */
2363 if (info->online && ((tty_buffer_request_room(tty, l) < l) ||
2364 !skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) {
2365 skb = alloc_skb(l, GFP_ATOMIC);
2367 spin_unlock_irqrestore(&info->readlock, flags);
2370 sp = skb_put(skb, l);
2371 #ifdef CONFIG_ISDN_AUDIO
2372 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
2373 ISDN_AUDIO_SKB_LOCK(skb) = 0;
2377 for (p = msg; *p; p++) {
2380 c = m->mdmreg[REG_CR];
2383 c = m->mdmreg[REG_LF];
2386 c = m->mdmreg[REG_BS];
2394 if(tty_insert_flip_char(tty, c, TTY_NORMAL) == 0)
2399 __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb);
2400 dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len;
2401 spin_unlock_irqrestore(&info->readlock, flags);
2402 /* Schedule dequeuing */
2403 if (dev->modempoll && info->rcvsched)
2404 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
2407 spin_unlock_irqrestore(&info->readlock, flags);
2408 tty_flip_buffer_push(tty);
2413 * Perform ATH Hangup
2416 isdn_tty_on_hook(modem_info * info)
2418 if (info->isdn_channel >= 0) {
2419 #ifdef ISDN_DEBUG_MODEM_HUP
2420 printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n");
2422 isdn_tty_modem_hup(info, 1);
2427 isdn_tty_off_hook(void)
2429 printk(KERN_DEBUG "isdn_tty_off_hook\n");
2432 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2433 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2436 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2437 * isdn_tty_modem_escape() if sequence found.
2440 * p pointer to databuffer
2441 * plus escape-character
2442 * count length of buffer
2443 * pluscount count of valid escape-characters so far
2444 * lastplus timestamp of last character
2447 isdn_tty_check_esc(const u_char * p, u_char plus, int count, int *pluscount,
2458 if (*(p++) == plus) {
2459 if ((*pluscount)++) {
2460 /* Time since last '+' > 0.5 sec. ? */
2461 if (time_after(jiffies, *lastplus + PLUSWAIT1))
2464 /* Time since last non-'+' < 1.5 sec. ? */
2465 if (time_before(jiffies, *lastplus + PLUSWAIT2))
2468 if ((*pluscount == 3) && (count == 1))
2469 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1);
2474 *lastplus = jiffies;
2480 * Return result of AT-emulator to tty-receive-buffer, depending on
2481 * modem-register 12, bit 0 and 1.
2482 * For CONNECT-messages also switch to online-mode.
2483 * For RING-message handle auto-ATA if register 0 != 0
2487 isdn_tty_modem_result(int code, modem_info * info)
2489 atemu *m = &info->emu;
2490 static char *msg[] =
2491 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2492 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2493 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2494 char s[ISDN_MSNLEN+10];
2498 m->mdmreg[REG_RINGCNT]++;
2499 if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA])
2500 /* Automatically accept incoming call */
2501 isdn_tty_cmd_ATA(info);
2503 case RESULT_NO_CARRIER:
2504 #ifdef ISDN_DEBUG_MODEM_HUP
2505 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n",
2506 (info->flags & ISDN_ASYNC_CLOSING),
2509 m->mdmreg[REG_RINGCNT] = 0;
2510 del_timer(&info->nc_timer);
2512 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) {
2515 #ifdef CONFIG_ISDN_AUDIO
2516 if (info->vonline & 1) {
2517 #ifdef ISDN_DEBUG_MODEM_VOICE
2518 printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n",
2521 /* voice-recording, add DLE-ETX */
2522 isdn_tty_at_cout("\020\003", info);
2524 if (info->vonline & 2) {
2525 #ifdef ISDN_DEBUG_MODEM_VOICE
2526 printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n",
2529 /* voice-playing, add DLE-DC4 */
2530 isdn_tty_at_cout("\020\024", info);
2534 case RESULT_CONNECT:
2535 case RESULT_CONNECT64000:
2536 sprintf(info->last_cause, "0000");
2541 #ifdef ISDN_DEBUG_MODEM_VOICE
2542 printk(KERN_DEBUG "res3: send VCON on ttyI%d\n",
2545 sprintf(info->last_cause, "0000");
2549 } /* switch(code) */
2551 if (m->mdmreg[REG_RESP] & BIT_RESP) {
2553 if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) {
2554 /* Show numeric results only */
2555 sprintf(s, "\r\n%d\r\n", code);
2556 isdn_tty_at_cout(s, info);
2558 if (code == RESULT_RING) {
2559 /* return if "show RUNG" and ringcounter>1 */
2560 if ((m->mdmreg[REG_RUNG] & BIT_RUNG) &&
2561 (m->mdmreg[REG_RINGCNT] > 1))
2563 /* print CID, _before_ _every_ ring */
2564 if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) {
2565 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info);
2566 isdn_tty_at_cout(dev->num[info->drv_index], info);
2567 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2568 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2569 isdn_tty_at_cout(info->emu.cpn, info);
2573 isdn_tty_at_cout("\r\n", info);
2574 isdn_tty_at_cout(msg[code], info);
2576 case RESULT_CONNECT:
2577 switch (m->mdmreg[REG_L2PROT]) {
2578 case ISDN_PROTO_L2_MODEM:
2579 isdn_tty_at_cout(" ", info);
2580 isdn_tty_at_cout(m->connmsg, info);
2585 /* Append CPN, if enabled */
2586 if ((m->mdmreg[REG_CPN] & BIT_CPN)) {
2587 sprintf(s, "/%s", m->cpn);
2588 isdn_tty_at_cout(s, info);
2590 /* Print CID only once, _after_ 1st RING */
2591 if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) &&
2592 (m->mdmreg[REG_RINGCNT] == 1)) {
2593 isdn_tty_at_cout("\r\n", info);
2594 isdn_tty_at_cout("CALLER NUMBER: ", info);
2595 isdn_tty_at_cout(dev->num[info->drv_index], info);
2596 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2597 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2598 isdn_tty_at_cout(info->emu.cpn, info);
2602 case RESULT_NO_CARRIER:
2603 case RESULT_NO_DIALTONE:
2605 case RESULT_NO_ANSWER:
2606 m->mdmreg[REG_RINGCNT] = 0;
2607 /* Append Cause-Message if enabled */
2608 if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) {
2609 sprintf(s, "/%s", info->last_cause);
2610 isdn_tty_at_cout(s, info);
2613 case RESULT_CONNECT64000:
2614 /* Append Protocol to CONNECT message */
2615 switch (m->mdmreg[REG_L2PROT]) {
2616 case ISDN_PROTO_L2_X75I:
2617 case ISDN_PROTO_L2_X75UI:
2618 case ISDN_PROTO_L2_X75BUI:
2619 isdn_tty_at_cout("/X.75", info);
2621 case ISDN_PROTO_L2_HDLC:
2622 isdn_tty_at_cout("/HDLC", info);
2624 case ISDN_PROTO_L2_V11096:
2625 isdn_tty_at_cout("/V110/9600", info);
2627 case ISDN_PROTO_L2_V11019:
2628 isdn_tty_at_cout("/V110/19200", info);
2630 case ISDN_PROTO_L2_V11038:
2631 isdn_tty_at_cout("/V110/38400", info);
2634 if (m->mdmreg[REG_T70] & BIT_T70) {
2635 isdn_tty_at_cout("/T.70", info);
2636 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2637 isdn_tty_at_cout("+", info);
2641 isdn_tty_at_cout("\r\n", info);
2644 if (code == RESULT_NO_CARRIER) {
2645 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) {
2648 tty_ldisc_flush(info->tty);
2649 if ((info->flags & ISDN_ASYNC_CHECK_CD) &&
2650 (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
2651 (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) {
2652 tty_hangup(info->tty);
2659 * Display a modem-register-value.
2662 isdn_tty_show_profile(int ridx, modem_info * info)
2666 sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]);
2667 isdn_tty_at_cout(v, info);
2671 * Get MSN-string from char-pointer, set pointer to end of number
2674 isdn_tty_get_msnstr(char *n, char **p)
2676 int limit = ISDN_MSNLEN - 1;
2678 while (((*p[0] >= '0' && *p[0] <= '9') ||
2679 /* Why a comma ??? */
2680 (*p[0] == ',') || (*p[0] == ':')) &&
2687 * Get phone-number from modem-commandbuffer
2690 isdn_tty_getdial(char *p, char *q,int cnt)
2693 int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
2696 while (strchr(" 0123456789,#.*WPTS-", *p) && *p && --cnt>0) {
2697 if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
2698 (*p == '*') || (*p == '#')) {
2710 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2711 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2714 isdn_tty_report(modem_info * info)
2716 atemu *m = &info->emu;
2719 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info);
2720 sprintf(s, " Remote Number: %s\r\n", info->last_num);
2721 isdn_tty_at_cout(s, info);
2722 sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming");
2723 isdn_tty_at_cout(s, info);
2724 isdn_tty_at_cout(" Layer-2 Protocol: ", info);
2725 switch (info->last_l2) {
2726 case ISDN_PROTO_L2_X75I:
2727 isdn_tty_at_cout("X.75i", info);
2729 case ISDN_PROTO_L2_X75UI:
2730 isdn_tty_at_cout("X.75ui", info);
2732 case ISDN_PROTO_L2_X75BUI:
2733 isdn_tty_at_cout("X.75bui", info);
2735 case ISDN_PROTO_L2_HDLC:
2736 isdn_tty_at_cout("HDLC", info);
2738 case ISDN_PROTO_L2_V11096:
2739 isdn_tty_at_cout("V.110 9600 Baud", info);
2741 case ISDN_PROTO_L2_V11019:
2742 isdn_tty_at_cout("V.110 19200 Baud", info);
2744 case ISDN_PROTO_L2_V11038:
2745 isdn_tty_at_cout("V.110 38400 Baud", info);
2747 case ISDN_PROTO_L2_TRANS:
2748 isdn_tty_at_cout("transparent", info);
2750 case ISDN_PROTO_L2_MODEM:
2751 isdn_tty_at_cout("modem", info);
2753 case ISDN_PROTO_L2_FAX:
2754 isdn_tty_at_cout("fax", info);
2757 isdn_tty_at_cout("unknown", info);
2760 if (m->mdmreg[REG_T70] & BIT_T70) {
2761 isdn_tty_at_cout("/T.70", info);
2762 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2763 isdn_tty_at_cout("+", info);
2765 isdn_tty_at_cout("\r\n", info);
2766 isdn_tty_at_cout(" Service: ", info);
2767 switch (info->last_si) {
2769 isdn_tty_at_cout("audio\r\n", info);
2772 isdn_tty_at_cout("btx\r\n", info);
2775 isdn_tty_at_cout("data\r\n", info);
2778 sprintf(s, "%d\r\n", info->last_si);
2779 isdn_tty_at_cout(s, info);
2782 sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote");
2783 isdn_tty_at_cout(s, info);
2784 sprintf(s, " Last cause: %s\r\n", info->last_cause);
2785 isdn_tty_at_cout(s, info);
2789 * Parse AT&.. commands.
2792 isdn_tty_cmd_ATand(char **p, modem_info * info)
2794 atemu *m = &info->emu;
2798 #define MAXRB (sizeof(rb) - 1)
2802 /* &B - Set Buffersize */
2805 if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX))
2807 #ifdef CONFIG_ISDN_AUDIO
2808 if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF))
2811 m->mdmreg[REG_PSIZE] = i / 16;
2812 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2813 switch (m->mdmreg[REG_L2PROT]) {
2814 case ISDN_PROTO_L2_V11096:
2815 case ISDN_PROTO_L2_V11019:
2816 case ISDN_PROTO_L2_V11038:
2817 info->xmit_size /= 10;
2821 /* &C - DCD Status */
2823 switch (isdn_getnum(p)) {
2825 m->mdmreg[REG_DCD] &= ~BIT_DCD;
2828 m->mdmreg[REG_DCD] |= BIT_DCD;
2835 /* &D - Set DTR-Low-behavior */
2837 switch (isdn_getnum(p)) {
2839 m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP;
2840 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2843 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2844 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2847 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2848 m->mdmreg[REG_DTRR] |= BIT_DTRR;
2855 /* &E -Set EAZ/MSN */
2857 isdn_tty_get_msnstr(m->msn, p);
2860 /* &F -Set Factory-Defaults */
2862 if (info->msr & UART_MSR_DCD)
2864 isdn_tty_reset_profile(m);
2865 isdn_tty_modem_reset_regs(info, 1);
2867 #ifdef DUMMY_HAYES_AT
2869 /* only for be compilant with common scripts */
2870 /* &K Flowcontrol - no function */
2876 /* &L -Set Numbers to listen on */
2879 while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) &&
2881 m->lmsn[i++] = *p[0]++;
2885 /* &R - Set V.110 bitrate adaption */
2890 /* Switch off V.110, back to X.75 */
2891 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2892 m->mdmreg[REG_SI2] = 0;
2893 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2896 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096;
2897 m->mdmreg[REG_SI2] = 197;
2898 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2901 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019;
2902 m->mdmreg[REG_SI2] = 199;
2903 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2906 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038;
2907 m->mdmreg[REG_SI2] = 198; /* no existing standard for this */
2908 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2913 /* Switch off T.70 */
2914 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
2916 m->mdmreg[REG_SI1] |= 4;
2919 /* &S - Set Windowsize */
2922 if ((i > 0) && (i < 9))
2923 m->mdmreg[REG_WSIZE] = i;
2928 /* &V - Show registers */
2930 isdn_tty_at_cout("\r\n", info);
2931 for (i = 0; i < ISDN_MODEM_NUMREG; i++) {
2932 sprintf(rb, "S%02d=%03d%s", i,
2933 m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n");
2934 isdn_tty_at_cout(rb, info);
2936 sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n",
2937 strlen(m->msn) ? m->msn : "None");
2938 isdn_tty_at_cout(rb, info);
2939 if (strlen(m->lmsn)) {
2940 isdn_tty_at_cout("\r\nListen: ", info);
2941 isdn_tty_at_cout(m->lmsn, info);
2942 isdn_tty_at_cout("\r\n", info);
2946 /* &W - Write Profile */
2951 modem_write_profile(m);
2958 /* &X - Switch to BTX-Mode and T.70 */
2960 switch (isdn_getnum(p)) {
2962 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
2963 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2966 m->mdmreg[REG_T70] |= BIT_T70;
2967 m->mdmreg[REG_T70] &= ~BIT_T70_EXT;
2968 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2969 info->xmit_size = 112;
2970 m->mdmreg[REG_SI1] = 4;
2971 m->mdmreg[REG_SI2] = 0;
2974 m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT);
2975 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2976 info->xmit_size = 112;
2977 m->mdmreg[REG_SI1] = 4;
2978 m->mdmreg[REG_SI2] = 0;
2991 isdn_tty_check_ats(int mreg, int mval, modem_info * info, atemu * m)
2993 /* Some plausibility checks */
2996 if (mval > ISDN_PROTO_L2_MAX)
3000 if ((mval * 16) > ISDN_SERIAL_XMIT_MAX)
3002 #ifdef CONFIG_ISDN_AUDIO
3003 if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX))
3006 info->xmit_size = mval * 16;
3007 switch (m->mdmreg[REG_L2PROT]) {
3008 case ISDN_PROTO_L2_V11096:
3009 case ISDN_PROTO_L2_V11019:
3010 case ISDN_PROTO_L2_V11038:
3011 info->xmit_size /= 10;
3017 /* readonly registers */
3024 * Perform ATS command
3027 isdn_tty_cmd_ATS(char **p, modem_info * info)
3029 atemu *m = &info->emu;
3035 mreg = isdn_getnum(p);
3036 if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG)
3041 mval = isdn_getnum(p);
3042 if (mval < 0 || mval > 255)
3044 if (isdn_tty_check_ats(mreg, mval, info, m))
3046 m->mdmreg[mreg] = mval;
3049 /* Set/Clear a single bit */
3051 bitpos = isdn_getnum(p);
3052 if ((bitpos < 0) || (bitpos > 7))
3057 bval = isdn_getnum(p);
3058 if (bval < 0 || bval > 1)
3061 mval = m->mdmreg[mreg] | (1 << bitpos);
3063 mval = m->mdmreg[mreg] & ~(1 << bitpos);
3064 if (isdn_tty_check_ats(mreg, mval, info, m))
3066 m->mdmreg[mreg] = mval;
3070 isdn_tty_at_cout("\r\n", info);
3071 isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0",
3080 isdn_tty_show_profile(mreg, info);
3090 * Perform ATA command
3093 isdn_tty_cmd_ATA(modem_info * info)
3095 atemu *m = &info->emu;
3099 if (info->msr & UART_MSR_RI) {
3100 /* Accept incoming call */
3102 strcpy(info->last_num, dev->num[info->drv_index]);
3103 m->mdmreg[REG_RINGCNT] = 0;
3104 info->msr &= ~UART_MSR_RI;
3105 l2 = m->mdmreg[REG_L2PROT];
3106 #ifdef CONFIG_ISDN_AUDIO
3107 /* If more than one bit set in reg18, autoselect Layer2 */
3108 if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) {
3109 if (m->mdmreg[REG_SI1I] == 1) {
3110 if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX))
3111 l2 = ISDN_PROTO_L2_TRANS;
3113 l2 = ISDN_PROTO_L2_X75I;
3116 cmd.driver = info->isdn_driver;
3117 cmd.command = ISDN_CMD_SETL2;
3118 cmd.arg = info->isdn_channel + (l2 << 8);
3121 cmd.driver = info->isdn_driver;
3122 cmd.command = ISDN_CMD_SETL3;
3123 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
3124 #ifdef CONFIG_ISDN_TTY_FAX
3125 if (l2 == ISDN_PROTO_L2_FAX) {
3126 cmd.parm.fax = info->fax;
3127 info->fax->direction = ISDN_TTY_FAX_CONN_IN;
3131 cmd.driver = info->isdn_driver;
3132 cmd.arg = info->isdn_channel;
3133 cmd.command = ISDN_CMD_ACCEPTD;
3135 info->emu.carrierwait = 0;
3137 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
3139 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3142 #ifdef CONFIG_ISDN_AUDIO
3144 * Parse AT+F.. commands
3147 isdn_tty_cmd_PLUSF(char **p, modem_info * info)
3149 atemu *m = &info->emu;
3152 if (!strncmp(p[0], "CLASS", 5)) {
3157 sprintf(rs, "\r\n%d",
3158 (m->mdmreg[REG_SI1] & 1) ? 8 : 0);
3159 #ifdef CONFIG_ISDN_TTY_FAX
3160 if (TTY_IS_FCLASS2(info))
3161 sprintf(rs, "\r\n2");
3162 else if (TTY_IS_FCLASS1(info))
3163 sprintf(rs, "\r\n1");
3165 isdn_tty_at_cout(rs, info);
3172 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3173 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3174 m->mdmreg[REG_SI1] = 4;
3176 m->mdmreg[REG_PSIZE] * 16;
3178 #ifdef CONFIG_ISDN_TTY_FAX
3181 if (!(dev->global_features &
3182 ISDN_FEATURE_L3_FCLASS1))
3184 m->mdmreg[REG_SI1] = 1;
3185 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3186 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1;
3188 m->mdmreg[REG_PSIZE] * 16;
3192 if (!(dev->global_features &
3193 ISDN_FEATURE_L3_FCLASS2))
3195 m->mdmreg[REG_SI1] = 1;
3196 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3197 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2;
3199 m->mdmreg[REG_PSIZE] * 16;
3204 /* L2 will change on dialout with si=1 */
3205 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3206 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3207 m->mdmreg[REG_SI1] = 5;
3208 info->xmit_size = VBUF;
3212 strcpy(rs, "\r\n0,");
3213 #ifdef CONFIG_ISDN_TTY_FAX
3214 if (dev->global_features &
3215 ISDN_FEATURE_L3_FCLASS1)
3217 if (dev->global_features &
3218 ISDN_FEATURE_L3_FCLASS2)
3222 isdn_tty_at_cout(rs, info);
3233 #ifdef CONFIG_ISDN_TTY_FAX
3234 return (isdn_tty_cmd_PLUSF_FAX(p, info));
3241 * Parse AT+V.. commands
3244 isdn_tty_cmd_PLUSV(char **p, modem_info * info)
3246 atemu *m = &info->emu;
3248 static char *vcmd[] =
3249 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL};
3257 if (!strncmp(vcmd[i], p[0], 2)) {
3265 /* AT+VNH - Auto hangup feature */
3269 isdn_tty_at_cout("\r\n1", info);
3279 isdn_tty_at_cout("\r\n1", info);
3290 /* AT+VIP - Reset all voice parameters */
3291 isdn_tty_modem_reset_vpar(m);
3294 /* AT+VLS - Select device, accept incoming call */
3298 sprintf(rs, "\r\n%d", m->vpar[0]);
3299 isdn_tty_at_cout(rs, info);
3314 isdn_tty_at_cout("\r\n0,2", info);
3325 /* AT+VRX - Start recording */
3328 if (info->online != 1) {
3329 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3332 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3333 if (!info->dtmf_state) {
3334 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3337 info->silence_state = isdn_audio_silence_init(info->silence_state);
3338 if (!info->silence_state) {
3339 printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n");
3342 if (m->vpar[3] < 5) {
3343 info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]);
3344 if (!info->adpcmr) {
3345 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3349 #ifdef ISDN_DEBUG_AT
3350 printk(KERN_DEBUG "AT: +VRX\n");
3353 isdn_tty_modem_result(RESULT_CONNECT, info);
3357 /* AT+VSD - Silence detection */
3361 sprintf(rs, "\r\n<%d>,<%d>",
3364 isdn_tty_at_cout(rs, info);
3368 if ((*p[0]>='0') && (*p[0]<='9')) {
3369 par1 = isdn_getnum(p);
3370 if ((par1 < 0) || (par1 > 31))
3375 par2 = isdn_getnum(p);
3376 if ((par2 < 0) || (par2 > 255))
3384 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3395 /* AT+VSM - Select compression */
3399 sprintf(rs, "\r\n<%d>,<%d><8000>",
3402 isdn_tty_at_cout(rs, info);
3412 par1 = isdn_getnum(p);
3413 if ((par1 < 2) || (par1 > 6))
3419 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3421 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3423 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3425 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3427 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3439 /* AT+VTX - Start sending */
3442 if (info->online != 1) {
3443 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3446 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3447 if (!info->dtmf_state) {
3448 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3451 if (m->vpar[3] < 5) {
3452 info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]);
3453 if (!info->adpcms) {
3454 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3458 #ifdef ISDN_DEBUG_AT
3459 printk(KERN_DEBUG "AT: +VTX\n");
3463 isdn_tty_modem_result(RESULT_CONNECT, info);
3467 /* AT+VDD - DTMF detection */
3471 sprintf(rs, "\r\n<%d>,<%d>",
3474 isdn_tty_at_cout(rs, info);
3478 if ((*p[0]>='0') && (*p[0]<='9')) {
3479 if (info->online != 1)
3481 par1 = isdn_getnum(p);
3482 if ((par1 < 0) || (par1 > 15))
3487 par2 = isdn_getnum(p);
3488 if ((par2 < 0) || (par2 > 255))
3492 cmd.driver = info->isdn_driver;
3493 cmd.command = ISDN_CMD_AUDIO;
3494 cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8);
3495 cmd.parm.num[0] = par1;
3496 cmd.parm.num[1] = par2;
3502 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3517 #endif /* CONFIG_ISDN_AUDIO */
3520 * Parse and perform an AT-command-line.
3523 isdn_tty_parse_at(modem_info * info)
3525 atemu *m = &info->emu;
3529 #ifdef ISDN_DEBUG_AT
3530 printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd);
3532 for (p = &m->mdmcmd[2]; *p;) {
3538 /* A - Accept incoming call */
3540 isdn_tty_cmd_ATA(info);
3545 if (info->msr & UART_MSR_DCD)
3547 if (info->msr & UART_MSR_RI) {
3548 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3551 isdn_tty_getdial(++p, ds, sizeof ds);
3553 if (!strlen(m->msn))
3554 isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info);
3555 else if (strlen(ds))
3556 isdn_tty_dial(ds, info, m);
3561 /* E - Turn Echo on/off */
3563 switch (isdn_getnum(&p)) {
3565 m->mdmreg[REG_ECHO] &= ~BIT_ECHO;
3568 m->mdmreg[REG_ECHO] |= BIT_ECHO;
3575 /* H - On/Off-hook */
3580 isdn_tty_on_hook(info);
3584 isdn_tty_off_hook();
3587 isdn_tty_on_hook(info);
3592 /* I - Information */
3594 isdn_tty_at_cout("\r\nLinux ISDN", info);
3602 isdn_tty_report(info);
3606 sprintf(ds, "\r\n%d", info->emu.charge);
3607 isdn_tty_at_cout(ds, info);
3612 #ifdef DUMMY_HAYES_AT
3615 /* only for be compilant with common scripts */
3624 if (info->msr & UART_MSR_DCD)
3625 /* if B-Channel is up */
3626 isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT:RESULT_CONNECT64000, info);
3628 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3631 /* Q - Turn Emulator messages on/off */
3633 switch (isdn_getnum(&p)) {
3635 m->mdmreg[REG_RESP] |= BIT_RESP;
3638 m->mdmreg[REG_RESP] &= ~BIT_RESP;
3645 /* S - Set/Get Register */
3647 if (isdn_tty_cmd_ATS(&p, info))
3651 /* V - Numeric or ASCII Emulator-messages */
3653 switch (isdn_getnum(&p)) {
3655 m->mdmreg[REG_RESP] |= BIT_RESPNUM;
3658 m->mdmreg[REG_RESP] &= ~BIT_RESPNUM;
3665 /* Z - Load Registers from Profile */
3667 if (info->msr & UART_MSR_DCD) {
3669 isdn_tty_on_hook(info);
3671 isdn_tty_modem_reset_regs(info, 1);
3676 #ifdef CONFIG_ISDN_AUDIO
3679 if (isdn_tty_cmd_PLUSF(&p, info))
3683 if ((!(m->mdmreg[REG_SI1] & 1)) ||
3684 (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM))
3687 if (isdn_tty_cmd_PLUSV(&p, info))
3690 #endif /* CONFIG_ISDN_AUDIO */
3691 case 'S': /* SUSPEND */
3693 isdn_tty_get_msnstr(ds, &p);
3694 isdn_tty_suspend(ds, info, m);
3696 case 'R': /* RESUME */
3698 isdn_tty_get_msnstr(ds, &p);
3699 isdn_tty_resume(ds, info, m);
3701 case 'M': /* MESSAGE */
3703 isdn_tty_send_msg(info, m, p);
3711 if (isdn_tty_cmd_ATand(&p, info))
3718 #ifdef CONFIG_ISDN_AUDIO
3721 isdn_tty_modem_result(RESULT_OK, info);
3724 /* Need own toupper() because standard-toupper is not available
3727 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
3730 * Perform line-editing of AT-commands
3734 * count length of buffer
3735 * channel index to line (minor-device)
3738 isdn_tty_edit_at(const char *p, int count, modem_info * info)
3740 atemu *m = &info->emu;
3746 for (cnt = count; cnt > 0; p++, cnt--) {
3749 if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) {
3750 /* Separator (CR or LF) */
3751 m->mdmcmd[m->mdmcmdl] = 0;
3752 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3755 isdn_tty_at_cout(eb, info);
3757 if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2))))
3758 isdn_tty_parse_at(info);
3762 if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) {
3763 /* Backspace-Function */
3764 if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) {
3767 if (m->mdmreg[REG_ECHO] & BIT_ECHO)
3768 isdn_tty_at_cout("\b", info);
3773 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3776 isdn_tty_at_cout(eb, info);
3778 if (m->mdmcmdl < 255) {
3780 switch (m->mdmcmdl) {
3783 m->mdmcmd[m->mdmcmdl] = c;
3784 m->mdmcmd[++m->mdmcmdl] = 0;
3788 /* Fall through, check for 'A' */
3791 m->mdmcmd[m->mdmcmdl] = c;
3792 m->mdmcmd[++m->mdmcmdl] = 0;
3796 m->mdmcmd[m->mdmcmdl] = c;
3797 m->mdmcmd[++m->mdmcmdl] = 0;
3806 * Switch all modem-channels who are online and got a valid
3807 * escape-sequence 1.5 seconds ago, to command-mode.
3808 * This function is called every second via timer-interrupt from within
3809 * timer-dispatcher isdn_timer_function()
3812 isdn_tty_modem_escape(void)
3818 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
3819 if (USG_MODEM(dev->usage[i]))
3820 if ((midx = dev->m_idx[i]) >= 0) {
3821 modem_info *info = &dev->mdm.info[midx];
3824 if ((info->emu.pluscount == 3) &&
3825 time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) {
3826 info->emu.pluscount = 0;
3828 isdn_tty_modem_result(RESULT_OK, info);
3832 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
3836 * Put a RING-message to all modem-channels who have the RI-bit set.
3837 * This function is called every second via timer-interrupt from within
3838 * timer-dispatcher isdn_timer_function()
3841 isdn_tty_modem_ring(void)
3846 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3847 modem_info *info = &dev->mdm.info[i];
3848 if (info->msr & UART_MSR_RI) {
3850 isdn_tty_modem_result(RESULT_RING, info);
3853 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton);
3857 * For all online tty's, try sending data to
3861 isdn_tty_modem_xmit(void)
3866 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3867 modem_info *info = &dev->mdm.info[i];
3870 isdn_tty_senddown(info);
3871 isdn_tty_tint(info);
3874 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton);
3878 * Check all channels if we have a 'no carrier' timeout.
3879 * Timeout value is set by Register S7.
3882 isdn_tty_carrier_timeout(void)
3887 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3888 modem_info *info = &dev->mdm.info[i];
3889 if (info->dialing) {
3890 if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
3892 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3893 isdn_tty_modem_hup(info, 1);
3899 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);