2 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
4 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
5 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
11 #undef ISDN_TTY_STAT_DEBUG
13 #include <linux/isdn.h>
14 #include <linux/serial.h> /* ASYNC_* flags */
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/mutex.h>
18 #include "isdn_common.h"
20 #ifdef CONFIG_ISDN_AUDIO
21 #include "isdn_audio.h"
23 #define VBUFX (VBUF/16)
26 #define FIX_FILE_TRANSFER
27 #define DUMMY_HAYES_AT
31 static DEFINE_MUTEX(modem_info_mutex);
32 static int isdn_tty_edit_at(const char *, int, modem_info *);
33 static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *);
34 static void isdn_tty_modem_reset_regs(modem_info *, int);
35 static void isdn_tty_cmd_ATA(modem_info *);
36 static void isdn_tty_flush_buffer(struct tty_struct *);
37 static void isdn_tty_modem_result(int, modem_info *);
38 #ifdef CONFIG_ISDN_AUDIO
39 static int isdn_tty_countDLE(unsigned char *, int);
42 /* Leave this unchanged unless you know what you do! */
43 #define MODEM_PARANOIA_CHECK
44 #define MODEM_DO_RESTART
46 static int bit2si[8] =
47 {1, 5, 7, 7, 7, 7, 7, 7};
48 static int si2bit[8] =
49 {4, 1, 4, 4, 4, 4, 4, 4};
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)
63 struct tty_port *port = &info->port;
66 struct tty_struct *tty;
76 if (!(info->mcr & UART_MCR_RTS))
80 #ifdef CONFIG_ISDN_AUDIO
81 + ISDN_AUDIO_SKB_DLECOUNT(skb)
85 c = tty_buffer_request_room(port, len);
89 #ifdef CONFIG_ISDN_AUDIO
90 if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
92 unsigned char *dp = skb->data;
95 tty_insert_flip_char(port, DLE, 0);
96 tty_insert_flip_char(port, *dp++, 0);
99 tty_insert_flip_char(port, DLE, 0);
104 tty_insert_flip_string(port, skb->data, len - 1);
105 last = skb->data[len - 1];
106 #ifdef CONFIG_ISDN_AUDIO
109 if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
110 tty_insert_flip_char(port, last, 0xFF);
112 tty_insert_flip_char(port, last, TTY_NORMAL);
113 tty_flip_buffer_push(tty);
119 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
120 * It tries getting received data from the receive queue an stuff it into
121 * the tty's flip-buffer.
124 isdn_tty_readmodem(void)
130 struct tty_struct *tty;
133 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
134 midx = dev->m_idx[i];
138 info = &dev->mdm.info[midx];
143 #ifdef CONFIG_ISDN_AUDIO
144 isdn_audio_eval_dtmf(info);
145 if ((info->vonline & 1) && (info->emu.vpar[1]))
146 isdn_audio_eval_silence(info);
148 tty = info->port.tty;
150 if (info->mcr & UART_MCR_RTS) {
151 /* CISCO AsyncPPP Hack */
152 if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
153 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, &info->port, 0);
155 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, &info->port, 1);
157 tty_flip_buffer_push(tty);
169 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
173 isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb)
177 #ifdef CONFIG_ISDN_AUDIO
182 if ((midx = dev->m_idx[i]) < 0) {
183 /* if midx is invalid, packet is not for tty */
186 info = &dev->mdm.info[midx];
187 #ifdef CONFIG_ISDN_AUDIO
190 if ((info->vonline) && (!info->emu.vpar[4]))
191 isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt);
192 if ((info->vonline & 1) && (info->emu.vpar[1]))
193 isdn_audio_calc_silence(info, skb->data, skb->len, ifmt);
195 if ((info->online < 2)
196 #ifdef CONFIG_ISDN_AUDIO
197 && (!(info->vonline & 1))
200 /* If Modem not listening, drop data */
204 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
205 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) {
206 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
207 if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */
210 if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */
213 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
214 if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1)))
217 #ifdef CONFIG_ISDN_AUDIO
218 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
219 ISDN_AUDIO_SKB_LOCK(skb) = 0;
220 if (info->vonline & 1) {
221 /* voice conversion/compression */
222 switch (info->emu.vpar[3]) {
227 * Since compressed data takes less
228 * space, we can overwrite the buffer.
230 skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr,
239 isdn_audio_ulaw2alaw(skb->data, skb->len);
244 isdn_audio_alaw2ulaw(skb->data, skb->len);
247 ISDN_AUDIO_SKB_DLECOUNT(skb) =
248 isdn_tty_countDLE(skb->data, skb->len);
250 #ifdef CONFIG_ISDN_TTY_FAX
252 if (info->faxonline & 2) {
253 isdn_tty_fax_bitorder(info, skb);
254 ISDN_AUDIO_SKB_DLECOUNT(skb) =
255 isdn_tty_countDLE(skb->data, skb->len);
260 /* Try to deliver directly via tty-buf if queue is empty */
261 spin_lock_irqsave(&info->readlock, flags);
262 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
263 if (isdn_tty_try_read(info, skb)) {
264 spin_unlock_irqrestore(&info->readlock, flags);
267 /* Direct deliver failed or queue wasn't empty.
268 * Queue up for later dequeueing via timer-irq.
270 __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb);
271 dev->drv[di]->rcvcount[channel] +=
273 #ifdef CONFIG_ISDN_AUDIO
274 + ISDN_AUDIO_SKB_DLECOUNT(skb)
277 spin_unlock_irqrestore(&info->readlock, flags);
278 /* Schedule dequeuing */
279 if ((dev->modempoll) && (info->rcvsched))
280 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
285 isdn_tty_cleanup_xmit(modem_info *info)
287 skb_queue_purge(&info->xmit_queue);
288 #ifdef CONFIG_ISDN_AUDIO
289 skb_queue_purge(&info->dtmf_queue);
294 isdn_tty_tint(modem_info *info)
296 struct sk_buff *skb = skb_dequeue(&info->xmit_queue);
302 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
303 info->isdn_channel, 1, skb)) == len) {
304 struct tty_struct *tty = info->port.tty;
305 info->send_outstanding++;
306 info->msr &= ~UART_MSR_CTS;
307 info->lsr &= ~UART_LSR_TEMT;
312 /* Error: no channel, already shutdown, or wrong parameter */
316 skb_queue_head(&info->xmit_queue, skb);
319 #ifdef CONFIG_ISDN_AUDIO
321 isdn_tty_countDLE(unsigned char *buf, int len)
331 /* This routine is called from within isdn_tty_write() to perform
332 * DLE-decoding when sending audio-data.
335 isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len)
337 unsigned char *p = &info->port.xmit_buf[info->xmit_count];
347 memmove(p, p + 1, len - 1);
358 #ifdef ISDN_DEBUG_MODEM_VOICE
360 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
363 isdn_tty_at_cout("\020\003", info);
364 if (!info->vonline) {
365 #ifdef ISDN_DEBUG_MODEM_VOICE
367 "DLEdown: send VCON on ttyI%d\n",
370 isdn_tty_at_cout("\r\nVCON\r\n", info);
377 memmove(p, p + 1, len - 1);
391 printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n");
397 /* This routine is called from within isdn_tty_write() when receiving
398 * audio-data. It interrupts receiving, if an character other than
402 isdn_tty_end_vrx(const char *buf, int c)
408 if ((ch != 0x11) && (ch != 0x13))
415 static int voice_cf[7] =
416 {0, 0, 4, 3, 2, 0, 0};
418 #endif /* CONFIG_ISDN_AUDIO */
420 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
421 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
422 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
423 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
426 isdn_tty_senddown(modem_info *info)
430 #ifdef CONFIG_ISDN_AUDIO
435 #ifdef CONFIG_ISDN_AUDIO
436 if (info->vonline & 4) {
438 if (!info->vonline) {
439 #ifdef ISDN_DEBUG_MODEM_VOICE
441 "senddown: send VCON on ttyI%d\n",
444 isdn_tty_at_cout("\r\nVCON\r\n", info);
448 if (!(buflen = info->xmit_count))
450 if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0)
451 info->msr &= ~UART_MSR_CTS;
452 info->lsr &= ~UART_LSR_TEMT;
453 /* info->xmit_count is modified here and in isdn_tty_write().
454 * So we return here if isdn_tty_write() is in the
457 atomic_inc(&info->xmit_lock);
458 if (!(atomic_dec_and_test(&info->xmit_lock)))
460 if (info->isdn_driver < 0) {
461 info->xmit_count = 0;
464 skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4;
465 #ifdef CONFIG_ISDN_AUDIO
466 if (info->vonline & 2)
467 audio_len = buflen * voice_cf[info->emu.vpar[3]];
470 skb = dev_alloc_skb(skb_res + buflen + audio_len);
472 skb = dev_alloc_skb(skb_res + buflen);
476 "isdn_tty: Out of memory in ttyI%d senddown\n",
480 skb_reserve(skb, skb_res);
481 memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen);
482 info->xmit_count = 0;
483 #ifdef CONFIG_ISDN_AUDIO
484 if (info->vonline & 2) {
485 /* For now, ifmt is fixed to 1 (alaw), since this
486 * is used with ISDN everywhere in the world, except
487 * US, Canada and Japan.
488 * Later, when US-ISDN protocols are implemented,
489 * this setting will depend on the D-channel protocol.
493 /* voice conversion/decompression */
494 switch (info->emu.vpar[3]) {
498 /* adpcm, compatible to ZyXel 1496 modem
499 * with ROM revision 6.01
501 audio_len = isdn_audio_adpcm2xlaw(info->adpcms,
504 skb_put(skb, audio_len),
506 skb_pull(skb, buflen);
507 skb_trim(skb, audio_len);
512 isdn_audio_alaw2ulaw(skb->data,
518 isdn_audio_ulaw2alaw(skb->data,
523 #endif /* CONFIG_ISDN_AUDIO */
524 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
525 /* Add T.70 simplified header */
526 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT)
527 memcpy(skb_push(skb, 2), "\1\0", 2);
529 memcpy(skb_push(skb, 4), "\1\0\1\0", 4);
531 skb_queue_tail(&info->xmit_queue, skb);
534 /************************************************************
538 * mostly "stolen" from original Linux-serial.c and friends.
540 ************************************************************/
542 /* The next routine is called once from within timer-interrupt
543 * triggered within isdn_tty_modem_ncarrier(). It calls
544 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
545 * into the tty's buffer.
548 isdn_tty_modem_do_ncarrier(unsigned long data)
550 modem_info *info = (modem_info *) data;
551 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
554 /* Next routine is called, whenever the DTR-signal is raised.
555 * It checks the ncarrier-flag, and triggers the above routine
556 * when necessary. The ncarrier-flag is set, whenever DTR goes
560 isdn_tty_modem_ncarrier(modem_info *info)
562 if (info->ncarrier) {
563 info->nc_timer.expires = jiffies + HZ;
564 add_timer(&info->nc_timer);
569 * return the usage calculated by si and layer 2 protocol
572 isdn_calc_usage(int si, int l2)
574 int usg = ISDN_USAGE_MODEM;
576 #ifdef CONFIG_ISDN_AUDIO
579 case ISDN_PROTO_L2_MODEM:
580 usg = ISDN_USAGE_MODEM;
582 #ifdef CONFIG_ISDN_TTY_FAX
583 case ISDN_PROTO_L2_FAX:
584 usg = ISDN_USAGE_FAX;
587 case ISDN_PROTO_L2_TRANS:
589 usg = ISDN_USAGE_VOICE;
597 /* isdn_tty_dial() performs dialing of a tty an the necessary
598 * setup of the lower levels before that.
601 isdn_tty_dial(char *n, modem_info *info, atemu *m)
603 int usg = ISDN_USAGE_MODEM;
605 int l2 = m->mdmreg[REG_L2PROT];
611 for (j = 7; j >= 0; j--)
612 if (m->mdmreg[REG_SI1] & (1 << j)) {
616 usg = isdn_calc_usage(si, l2);
617 #ifdef CONFIG_ISDN_AUDIO
619 (l2 != ISDN_PROTO_L2_MODEM)
620 #ifdef CONFIG_ISDN_TTY_FAX
621 && (l2 != ISDN_PROTO_L2_FAX)
624 l2 = ISDN_PROTO_L2_TRANS;
625 usg = ISDN_USAGE_VOICE;
628 m->mdmreg[REG_SI1I] = si2bit[si];
629 spin_lock_irqsave(&dev->lock, flags);
630 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
632 spin_unlock_irqrestore(&dev->lock, flags);
633 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
635 info->isdn_driver = dev->drvmap[i];
636 info->isdn_channel = dev->chanmap[i];
638 dev->m_idx[i] = info->line;
639 dev->usage[i] |= ISDN_USAGE_OUTGOING;
641 strcpy(info->last_num, n);
643 spin_unlock_irqrestore(&dev->lock, flags);
644 cmd.driver = info->isdn_driver;
645 cmd.arg = info->isdn_channel;
646 cmd.command = ISDN_CMD_CLREAZ;
648 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
649 cmd.driver = info->isdn_driver;
650 cmd.command = ISDN_CMD_SETEAZ;
652 cmd.driver = info->isdn_driver;
653 cmd.command = ISDN_CMD_SETL2;
655 cmd.arg = info->isdn_channel + (l2 << 8);
657 cmd.driver = info->isdn_driver;
658 cmd.command = ISDN_CMD_SETL3;
659 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
660 #ifdef CONFIG_ISDN_TTY_FAX
661 if (l2 == ISDN_PROTO_L2_FAX) {
662 cmd.parm.fax = info->fax;
663 info->fax->direction = ISDN_TTY_FAX_CONN_OUT;
667 cmd.driver = info->isdn_driver;
668 cmd.arg = info->isdn_channel;
669 sprintf(cmd.parm.setup.phone, "%s", n);
670 sprintf(cmd.parm.setup.eazmsn, "%s",
671 isdn_map_eaz2msn(m->msn, info->isdn_driver));
672 cmd.parm.setup.si1 = si;
673 cmd.parm.setup.si2 = m->mdmreg[REG_SI2];
674 cmd.command = ISDN_CMD_DIAL;
676 info->emu.carrierwait = 0;
677 strcpy(dev->num[i], n);
680 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
684 /* isdn_tty_hangup() disassociates a tty from the real
685 * ISDN-line (hangup). The usage-status is cleared
686 * and some cleanup is done also.
689 isdn_tty_modem_hup(modem_info *info, int local)
697 di = info->isdn_driver;
698 ch = info->isdn_channel;
699 if (di < 0 || ch < 0)
702 info->isdn_driver = -1;
703 info->isdn_channel = -1;
705 #ifdef ISDN_DEBUG_MODEM_HUP
706 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
709 isdn_tty_flush_buffer(info->port.tty);
711 info->last_lhup = local;
713 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
715 #ifdef CONFIG_ISDN_AUDIO
717 #ifdef CONFIG_ISDN_TTY_FAX
719 info->fax->phase = ISDN_FAX_PHASE_IDLE;
721 info->emu.vpar[4] = 0;
722 info->emu.vpar[5] = 8;
723 kfree(info->dtmf_state);
724 info->dtmf_state = NULL;
725 kfree(info->silence_state);
726 info->silence_state = NULL;
732 if ((info->msr & UART_MSR_RI) &&
733 (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
734 isdn_tty_modem_result(RESULT_RUNG, info);
735 info->msr &= ~(UART_MSR_DCD | UART_MSR_RI);
736 info->lsr |= UART_LSR_TEMT;
740 cmd.command = ISDN_CMD_HANGUP;
745 isdn_all_eaz(di, ch);
746 info->emu.mdmreg[REG_RINGCNT] = 0;
747 isdn_free_channel(di, ch, 0);
749 if (info->drv_index >= 0) {
750 dev->m_idx[info->drv_index] = -1;
751 info->drv_index = -1;
756 * Begin of a CAPI like interface, currently used only for
757 * supplementary service (CAPI 2.0 part III)
759 #include <linux/isdn/capicmd.h>
760 #include <linux/module.h>
763 isdn_tty_capi_facility(capi_msg *cm) {
764 return (-1); /* dummy */
767 /* isdn_tty_suspend() tries to suspend the current tty connection
770 isdn_tty_suspend(char *id, modem_info *info, atemu *m)
779 #ifdef ISDN_DEBUG_MODEM_SERVICES
780 printk(KERN_DEBUG "Msusp ttyI%d\n", info->line);
783 if ((info->isdn_driver >= 0)) {
784 cmd.parm.cmsg.Length = l + 18;
785 cmd.parm.cmsg.Command = CAPI_FACILITY;
786 cmd.parm.cmsg.Subcommand = CAPI_REQ;
787 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
788 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
789 cmd.parm.cmsg.para[1] = 0;
790 cmd.parm.cmsg.para[2] = l + 3;
791 cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
792 cmd.parm.cmsg.para[4] = 0;
793 cmd.parm.cmsg.para[5] = l;
794 strncpy(&cmd.parm.cmsg.para[6], id, l);
795 cmd.command = CAPI_PUT_MESSAGE;
796 cmd.driver = info->isdn_driver;
797 cmd.arg = info->isdn_channel;
802 /* isdn_tty_resume() tries to resume a suspended call
803 * setup of the lower levels before that. unfortunately here is no
804 * checking for compatibility of used protocols implemented by Q931
805 * It does the same things like isdn_tty_dial, the last command
806 * is different, may be we can merge it.
810 isdn_tty_resume(char *id, modem_info *info, atemu *m)
812 int usg = ISDN_USAGE_MODEM;
814 int l2 = m->mdmreg[REG_L2PROT];
822 for (j = 7; j >= 0; j--)
823 if (m->mdmreg[REG_SI1] & (1 << j)) {
827 usg = isdn_calc_usage(si, l2);
828 #ifdef CONFIG_ISDN_AUDIO
830 (l2 != ISDN_PROTO_L2_MODEM)
831 #ifdef CONFIG_ISDN_TTY_FAX
832 && (l2 != ISDN_PROTO_L2_FAX)
835 l2 = ISDN_PROTO_L2_TRANS;
836 usg = ISDN_USAGE_VOICE;
839 m->mdmreg[REG_SI1I] = si2bit[si];
840 spin_lock_irqsave(&dev->lock, flags);
841 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
843 spin_unlock_irqrestore(&dev->lock, flags);
844 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
846 info->isdn_driver = dev->drvmap[i];
847 info->isdn_channel = dev->chanmap[i];
849 dev->m_idx[i] = info->line;
850 dev->usage[i] |= ISDN_USAGE_OUTGOING;
852 // strcpy(info->last_num, n);
854 spin_unlock_irqrestore(&dev->lock, flags);
855 cmd.driver = info->isdn_driver;
856 cmd.arg = info->isdn_channel;
857 cmd.command = ISDN_CMD_CLREAZ;
859 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
860 cmd.driver = info->isdn_driver;
861 cmd.command = ISDN_CMD_SETEAZ;
863 cmd.driver = info->isdn_driver;
864 cmd.command = ISDN_CMD_SETL2;
866 cmd.arg = info->isdn_channel + (l2 << 8);
868 cmd.driver = info->isdn_driver;
869 cmd.command = ISDN_CMD_SETL3;
870 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
872 cmd.driver = info->isdn_driver;
873 cmd.arg = info->isdn_channel;
874 cmd.parm.cmsg.Length = l + 18;
875 cmd.parm.cmsg.Command = CAPI_FACILITY;
876 cmd.parm.cmsg.Subcommand = CAPI_REQ;
877 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
878 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
879 cmd.parm.cmsg.para[1] = 0;
880 cmd.parm.cmsg.para[2] = l + 3;
881 cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
882 cmd.parm.cmsg.para[4] = 0;
883 cmd.parm.cmsg.para[5] = l;
884 strncpy(&cmd.parm.cmsg.para[6], id, l);
885 cmd.command = CAPI_PUT_MESSAGE;
887 // strcpy(dev->num[i], n);
890 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
894 /* isdn_tty_send_msg() sends a message to a HL driver
895 * This is used for hybrid modem cards to send AT commands to it
899 isdn_tty_send_msg(modem_info *info, atemu *m, char *msg)
901 int usg = ISDN_USAGE_MODEM;
903 int l2 = m->mdmreg[REG_L2PROT];
912 isdn_tty_modem_result(RESULT_ERROR, info);
915 for (j = 7; j >= 0; j--)
916 if (m->mdmreg[REG_SI1] & (1 << j)) {
920 usg = isdn_calc_usage(si, l2);
921 #ifdef CONFIG_ISDN_AUDIO
923 (l2 != ISDN_PROTO_L2_MODEM)
924 #ifdef CONFIG_ISDN_TTY_FAX
925 && (l2 != ISDN_PROTO_L2_FAX)
928 l2 = ISDN_PROTO_L2_TRANS;
929 usg = ISDN_USAGE_VOICE;
932 m->mdmreg[REG_SI1I] = si2bit[si];
933 spin_lock_irqsave(&dev->lock, flags);
934 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
936 spin_unlock_irqrestore(&dev->lock, flags);
937 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
939 info->isdn_driver = dev->drvmap[i];
940 info->isdn_channel = dev->chanmap[i];
942 dev->m_idx[i] = info->line;
943 dev->usage[i] |= ISDN_USAGE_OUTGOING;
946 spin_unlock_irqrestore(&dev->lock, flags);
947 cmd.driver = info->isdn_driver;
948 cmd.arg = info->isdn_channel;
949 cmd.command = ISDN_CMD_CLREAZ;
951 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
952 cmd.driver = info->isdn_driver;
953 cmd.command = ISDN_CMD_SETEAZ;
955 cmd.driver = info->isdn_driver;
956 cmd.command = ISDN_CMD_SETL2;
958 cmd.arg = info->isdn_channel + (l2 << 8);
960 cmd.driver = info->isdn_driver;
961 cmd.command = ISDN_CMD_SETL3;
962 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
964 cmd.driver = info->isdn_driver;
965 cmd.arg = info->isdn_channel;
966 cmd.parm.cmsg.Length = l + 14;
967 cmd.parm.cmsg.Command = CAPI_MANUFACTURER;
968 cmd.parm.cmsg.Subcommand = CAPI_REQ;
969 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
970 cmd.parm.cmsg.para[0] = l + 1;
971 strncpy(&cmd.parm.cmsg.para[1], msg, l);
972 cmd.parm.cmsg.para[l + 1] = 0xd;
973 cmd.command = CAPI_PUT_MESSAGE;
974 /* info->dialing = 1;
975 strcpy(dev->num[i], n);
983 isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine)
985 #ifdef MODEM_PARANOIA_CHECK
987 printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n",
991 if (info->magic != ISDN_ASYNC_MAGIC) {
992 printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n",
1001 * This routine is called to set the UART divisor registers to match
1002 * the specified baud rate for a serial port.
1005 isdn_tty_change_speed(modem_info *info)
1007 struct tty_port *port = &info->port;
1015 cflag = port->tty->termios.c_cflag;
1017 quot = i = cflag & CBAUD;
1021 port->tty->termios.c_cflag &= ~CBAUDEX;
1026 info->mcr |= UART_MCR_DTR;
1027 isdn_tty_modem_ncarrier(info);
1029 info->mcr &= ~UART_MCR_DTR;
1030 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1031 #ifdef ISDN_DEBUG_MODEM_HUP
1032 printk(KERN_DEBUG "Mhup in changespeed\n");
1036 isdn_tty_modem_reset_regs(info, 0);
1037 isdn_tty_modem_hup(info, 1);
1041 /* byte size and parity */
1042 cval = cflag & (CSIZE | CSTOPB);
1045 cval |= UART_LCR_PARITY;
1046 if (!(cflag & PARODD))
1047 cval |= UART_LCR_EPAR;
1049 /* CTS flow control flag and modem status interrupts */
1050 if (cflag & CRTSCTS) {
1051 port->flags |= ASYNC_CTS_FLOW;
1053 port->flags &= ~ASYNC_CTS_FLOW;
1055 port->flags &= ~ASYNC_CHECK_CD;
1057 port->flags |= ASYNC_CHECK_CD;
1062 isdn_tty_startup(modem_info *info)
1064 if (info->port.flags & ASYNC_INITIALIZED)
1066 isdn_lock_drivers();
1067 #ifdef ISDN_DEBUG_MODEM_OPEN
1068 printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line);
1071 * Now, initialize the UART
1073 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
1075 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
1077 * and set the speed of the serial port
1079 isdn_tty_change_speed(info);
1081 info->port.flags |= ASYNC_INITIALIZED;
1082 info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
1083 info->send_outstanding = 0;
1088 * This routine will shutdown a serial port; interrupts are disabled, and
1089 * DTR is dropped if the hangup on close termio flag is on.
1092 isdn_tty_shutdown(modem_info *info)
1094 if (!(info->port.flags & ASYNC_INITIALIZED))
1096 #ifdef ISDN_DEBUG_MODEM_OPEN
1097 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
1099 isdn_unlock_drivers();
1100 info->msr &= ~UART_MSR_RI;
1101 if (!info->port.tty || (info->port.tty->termios.c_cflag & HUPCL)) {
1102 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
1103 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1104 isdn_tty_modem_reset_regs(info, 0);
1105 #ifdef ISDN_DEBUG_MODEM_HUP
1106 printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n");
1108 isdn_tty_modem_hup(info, 1);
1112 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
1114 info->port.flags &= ~ASYNC_INITIALIZED;
1117 /* isdn_tty_write() is the main send-routine. It is called from the upper
1118 * levels within the kernel to perform sending data. Depending on the
1119 * online-flag it either directs output to the at-command-interpreter or
1120 * to the lower level. Additional tasks done here:
1121 * - If online, check for escape-sequence (+++)
1122 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1123 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1124 * - If dialing, abort dial.
1127 isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count)
1131 modem_info *info = (modem_info *) tty->driver_data;
1132 atemu *m = &info->emu;
1134 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write"))
1136 /* See isdn_tty_senddown() */
1137 atomic_inc(&info->xmit_lock);
1140 if (c > info->xmit_size - info->xmit_count)
1141 c = info->xmit_size - info->xmit_count;
1142 if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize)
1143 c = dev->drv[info->isdn_driver]->maxbufsize;
1146 if ((info->online > 1)
1147 #ifdef CONFIG_ISDN_AUDIO
1148 || (info->vonline & 3)
1151 #ifdef CONFIG_ISDN_AUDIO
1154 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
1157 memcpy(&info->port.xmit_buf[info->xmit_count], buf, c);
1158 #ifdef CONFIG_ISDN_AUDIO
1159 if (info->vonline) {
1160 int cc = isdn_tty_handleDLEdown(info, m, c);
1161 if (info->vonline & 2) {
1163 /* If DLE decoding results in zero-transmit, but
1164 * c originally was non-zero, do a wakeup.
1167 info->msr |= UART_MSR_CTS;
1168 info->lsr |= UART_LSR_TEMT;
1170 info->xmit_count += cc;
1172 if ((info->vonline & 3) == 1) {
1173 /* Do NOT handle Ctrl-Q or Ctrl-S
1174 * when in full-duplex audio mode.
1176 if (isdn_tty_end_vrx(buf, c)) {
1177 info->vonline &= ~1;
1178 #ifdef ISDN_DEBUG_MODEM_VOICE
1180 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1183 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
1187 if (TTY_IS_FCLASS1(info)) {
1188 int cc = isdn_tty_handleDLEdown(info, m, c);
1190 if (info->vonline & 4) { /* ETX seen */
1193 c.command = ISDN_CMD_FAXCMD;
1194 c.driver = info->isdn_driver;
1195 c.arg = info->isdn_channel;
1196 c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
1197 c.parm.aux.subcmd = ETX;
1201 #ifdef ISDN_DEBUG_MODEM_VOICE
1202 printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c);
1204 info->xmit_count += cc;
1207 info->xmit_count += c;
1209 info->msr |= UART_MSR_CTS;
1210 info->lsr |= UART_LSR_TEMT;
1211 if (info->dialing) {
1213 #ifdef ISDN_DEBUG_MODEM_HUP
1214 printk(KERN_DEBUG "Mhup in isdn_tty_write\n");
1216 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
1217 isdn_tty_modem_hup(info, 1);
1219 c = isdn_tty_edit_at(buf, c, info);
1225 atomic_dec(&info->xmit_lock);
1226 if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) {
1227 if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
1228 isdn_tty_senddown(info);
1229 isdn_tty_tint(info);
1231 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1237 isdn_tty_write_room(struct tty_struct *tty)
1239 modem_info *info = (modem_info *) tty->driver_data;
1242 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room"))
1245 return info->xmit_size;
1246 ret = info->xmit_size - info->xmit_count;
1247 return (ret < 0) ? 0 : ret;
1251 isdn_tty_chars_in_buffer(struct tty_struct *tty)
1253 modem_info *info = (modem_info *) tty->driver_data;
1255 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer"))
1259 return (info->xmit_count);
1263 isdn_tty_flush_buffer(struct tty_struct *tty)
1270 info = (modem_info *) tty->driver_data;
1271 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) {
1274 isdn_tty_cleanup_xmit(info);
1275 info->xmit_count = 0;
1280 isdn_tty_flush_chars(struct tty_struct *tty)
1282 modem_info *info = (modem_info *) tty->driver_data;
1284 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars"))
1286 if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue))
1287 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1291 * ------------------------------------------------------------
1292 * isdn_tty_throttle()
1294 * This routine is called by the upper-layer tty layer to signal that
1295 * incoming characters should be throttled.
1296 * ------------------------------------------------------------
1299 isdn_tty_throttle(struct tty_struct *tty)
1301 modem_info *info = (modem_info *) tty->driver_data;
1303 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle"))
1306 info->x_char = STOP_CHAR(tty);
1307 info->mcr &= ~UART_MCR_RTS;
1311 isdn_tty_unthrottle(struct tty_struct *tty)
1313 modem_info *info = (modem_info *) tty->driver_data;
1315 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle"))
1321 info->x_char = START_CHAR(tty);
1323 info->mcr |= UART_MCR_RTS;
1327 * ------------------------------------------------------------
1328 * isdn_tty_ioctl() and friends
1329 * ------------------------------------------------------------
1333 * isdn_tty_get_lsr_info - get line status register info
1335 * Purpose: Let user call ioctl() to get info when the UART physically
1336 * is emptied. On bus types like RS485, the transmitter must
1337 * release the bus after transmitting. This must be done when
1338 * the transmit shift register is empty, not be done when the
1339 * transmit holding register is empty. This functionality
1340 * allows RS485 driver to be written in user space.
1343 isdn_tty_get_lsr_info(modem_info *info, uint __user *value)
1349 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1350 return put_user(result, value);
1355 isdn_tty_tiocmget(struct tty_struct *tty)
1357 modem_info *info = (modem_info *) tty->driver_data;
1358 u_char control, status;
1360 if (isdn_tty_paranoia_check(info, tty->name, __func__))
1362 if (tty->flags & (1 << TTY_IO_ERROR))
1365 mutex_lock(&modem_info_mutex);
1366 #ifdef ISDN_DEBUG_MODEM_IOCTL
1367 printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
1370 control = info->mcr;
1372 mutex_unlock(&modem_info_mutex);
1373 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1374 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1375 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1376 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1377 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1378 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1382 isdn_tty_tiocmset(struct tty_struct *tty,
1383 unsigned int set, unsigned int clear)
1385 modem_info *info = (modem_info *) tty->driver_data;
1387 if (isdn_tty_paranoia_check(info, tty->name, __func__))
1389 if (tty->flags & (1 << TTY_IO_ERROR))
1392 #ifdef ISDN_DEBUG_MODEM_IOCTL
1393 printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear);
1396 mutex_lock(&modem_info_mutex);
1397 if (set & TIOCM_RTS)
1398 info->mcr |= UART_MCR_RTS;
1399 if (set & TIOCM_DTR) {
1400 info->mcr |= UART_MCR_DTR;
1401 isdn_tty_modem_ncarrier(info);
1404 if (clear & TIOCM_RTS)
1405 info->mcr &= ~UART_MCR_RTS;
1406 if (clear & TIOCM_DTR) {
1407 info->mcr &= ~UART_MCR_DTR;
1408 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1409 isdn_tty_modem_reset_regs(info, 0);
1410 #ifdef ISDN_DEBUG_MODEM_HUP
1411 printk(KERN_DEBUG "Mhup in TIOCMSET\n");
1415 isdn_tty_modem_hup(info, 1);
1418 mutex_unlock(&modem_info_mutex);
1423 isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong arg)
1425 modem_info *info = (modem_info *) tty->driver_data;
1428 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl"))
1430 if (tty->flags & (1 << TTY_IO_ERROR))
1433 case TCSBRK: /* SVID version: non-zero arg --> no break */
1434 #ifdef ISDN_DEBUG_MODEM_IOCTL
1435 printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line);
1437 retval = tty_check_change(tty);
1440 tty_wait_until_sent(tty, 0);
1442 case TCSBRKP: /* support for POSIX tcsendbreak() */
1443 #ifdef ISDN_DEBUG_MODEM_IOCTL
1444 printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line);
1446 retval = tty_check_change(tty);
1449 tty_wait_until_sent(tty, 0);
1451 case TIOCSERGETLSR: /* Get line status register */
1452 #ifdef ISDN_DEBUG_MODEM_IOCTL
1453 printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);
1455 return isdn_tty_get_lsr_info(info, (uint __user *) arg);
1457 #ifdef ISDN_DEBUG_MODEM_IOCTL
1458 printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line);
1460 return -ENOIOCTLCMD;
1466 isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1468 modem_info *info = (modem_info *) tty->driver_data;
1471 isdn_tty_change_speed(info);
1473 if (tty->termios.c_cflag == old_termios->c_cflag &&
1474 tty->termios.c_ispeed == old_termios->c_ispeed &&
1475 tty->termios.c_ospeed == old_termios->c_ospeed)
1477 isdn_tty_change_speed(info);
1478 if ((old_termios->c_cflag & CRTSCTS) &&
1479 !(tty->termios.c_cflag & CRTSCTS))
1480 tty->hw_stopped = 0;
1485 * ------------------------------------------------------------
1486 * isdn_tty_open() and friends
1487 * ------------------------------------------------------------
1490 static int isdn_tty_install(struct tty_driver *driver, struct tty_struct *tty)
1492 modem_info *info = &dev->mdm.info[tty->index];
1494 if (isdn_tty_paranoia_check(info, tty->name, __func__))
1497 tty->driver_data = info;
1499 return tty_port_install(&info->port, driver, tty);
1503 * This routine is called whenever a serial port is opened. It
1504 * enables interrupts for a serial port, linking in its async structure into
1505 * the IRQ chain. It also performs the serial-specific
1506 * initialization for the tty structure.
1509 isdn_tty_open(struct tty_struct *tty, struct file *filp)
1511 modem_info *info = tty->driver_data;
1512 struct tty_port *port = &info->port;
1515 #ifdef ISDN_DEBUG_MODEM_OPEN
1516 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
1522 * Start up serial port
1524 retval = isdn_tty_startup(info);
1526 #ifdef ISDN_DEBUG_MODEM_OPEN
1527 printk(KERN_DEBUG "isdn_tty_open return after startup\n");
1531 retval = tty_port_block_til_ready(port, tty, filp);
1533 #ifdef ISDN_DEBUG_MODEM_OPEN
1534 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");
1538 #ifdef ISDN_DEBUG_MODEM_OPEN
1539 printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line);
1542 #ifdef ISDN_DEBUG_MODEM_OPEN
1543 printk(KERN_DEBUG "isdn_tty_open normal exit\n");
1549 isdn_tty_close(struct tty_struct *tty, struct file *filp)
1551 modem_info *info = (modem_info *) tty->driver_data;
1552 struct tty_port *port = &info->port;
1555 if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close"))
1557 if (tty_hung_up_p(filp)) {
1558 #ifdef ISDN_DEBUG_MODEM_OPEN
1559 printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n");
1563 if ((tty->count == 1) && (port->count != 1)) {
1565 * Uh, oh. tty->count is 1, which means that the tty
1566 * structure will be freed. Info->count should always
1567 * be one in these conditions. If it's greater than
1568 * one, we've got real problems, since it means the
1569 * serial port won't be shutdown.
1571 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
1572 "info->count is %d\n", port->count);
1575 if (--port->count < 0) {
1576 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
1577 info->line, port->count);
1581 #ifdef ISDN_DEBUG_MODEM_OPEN
1582 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
1586 port->flags |= ASYNC_CLOSING;
1590 * At this point we stop accepting input. To do this, we
1591 * disable the receive line status interrupts, and tell the
1592 * interrupt driver to stop checking the data ready bit in the
1593 * line status register.
1595 if (port->flags & ASYNC_INITIALIZED) {
1596 tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */
1598 * Before we drop DTR, make sure the UART transmitter
1599 * has completely drained; this is especially
1600 * important if there is a transmit FIFO!
1602 timeout = jiffies + HZ;
1603 while (!(info->lsr & UART_LSR_TEMT)) {
1604 schedule_timeout_interruptible(20);
1605 if (time_after(jiffies, timeout))
1610 isdn_tty_shutdown(info);
1611 isdn_tty_flush_buffer(tty);
1612 tty_ldisc_flush(tty);
1616 tty_port_close_end(port, tty);
1617 #ifdef ISDN_DEBUG_MODEM_OPEN
1618 printk(KERN_DEBUG "isdn_tty_close normal exit\n");
1623 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1626 isdn_tty_hangup(struct tty_struct *tty)
1628 modem_info *info = (modem_info *) tty->driver_data;
1629 struct tty_port *port = &info->port;
1631 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
1633 isdn_tty_shutdown(info);
1635 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1637 wake_up_interruptible(&port->open_wait);
1640 /* This routine initializes all emulator-data.
1643 isdn_tty_reset_profile(atemu *m)
1656 m->profile[11] = 70;
1657 m->profile[12] = 0x45;
1659 m->profile[14] = ISDN_PROTO_L2_X75I;
1660 m->profile[15] = ISDN_PROTO_L3_TRANS;
1661 m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16;
1662 m->profile[17] = ISDN_MODEM_WINSIZE;
1671 #ifdef CONFIG_ISDN_AUDIO
1673 isdn_tty_modem_reset_vpar(atemu *m)
1675 m->vpar[0] = 2; /* Voice-device (2 = phone line) */
1676 m->vpar[1] = 0; /* Silence detection level (0 = none ) */
1677 m->vpar[2] = 70; /* Silence interval (7 sec. ) */
1678 m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1679 m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */
1680 m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1684 #ifdef CONFIG_ISDN_TTY_FAX
1686 isdn_tty_modem_reset_faxpar(modem_info *info)
1688 T30_s *f = info->fax;
1691 f->phase = ISDN_FAX_PHASE_IDLE;
1693 f->resolution = 1; /* fine */
1694 f->rate = 5; /* 14400 bit/s */
1701 memset(&f->id[0], 32, FAXIDLEN - 1);
1702 f->id[FAXIDLEN - 1] = 0;
1713 memset(&f->pollid[0], 32, FAXIDLEN - 1);
1714 f->pollid[FAXIDLEN - 1] = 0;
1719 isdn_tty_modem_reset_regs(modem_info *info, int force)
1721 atemu *m = &info->emu;
1722 if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {
1723 memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);
1724 memcpy(m->msn, m->pmsn, ISDN_MSNLEN);
1725 memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);
1726 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
1728 #ifdef CONFIG_ISDN_AUDIO
1729 isdn_tty_modem_reset_vpar(m);
1731 #ifdef CONFIG_ISDN_TTY_FAX
1732 isdn_tty_modem_reset_faxpar(info);
1738 modem_write_profile(atemu *m)
1740 memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG);
1741 memcpy(m->pmsn, m->msn, ISDN_MSNLEN);
1742 memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN);
1744 send_sig(SIGIO, dev->profd, 1);
1747 static const struct tty_operations modem_ops = {
1748 .install = isdn_tty_install,
1749 .open = isdn_tty_open,
1750 .close = isdn_tty_close,
1751 .write = isdn_tty_write,
1752 .flush_chars = isdn_tty_flush_chars,
1753 .write_room = isdn_tty_write_room,
1754 .chars_in_buffer = isdn_tty_chars_in_buffer,
1755 .flush_buffer = isdn_tty_flush_buffer,
1756 .ioctl = isdn_tty_ioctl,
1757 .throttle = isdn_tty_throttle,
1758 .unthrottle = isdn_tty_unthrottle,
1759 .set_termios = isdn_tty_set_termios,
1760 .hangup = isdn_tty_hangup,
1761 .tiocmget = isdn_tty_tiocmget,
1762 .tiocmset = isdn_tty_tiocmset,
1765 static int isdn_tty_carrier_raised(struct tty_port *port)
1767 modem_info *info = container_of(port, modem_info, port);
1768 return info->msr & UART_MSR_DCD;
1771 static const struct tty_port_operations isdn_tty_port_ops = {
1772 .carrier_raised = isdn_tty_carrier_raised,
1776 isdn_tty_modem_init(void)
1783 m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS);
1786 m->tty_modem->name = "ttyI";
1787 m->tty_modem->major = ISDN_TTY_MAJOR;
1788 m->tty_modem->minor_start = 0;
1789 m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL;
1790 m->tty_modem->subtype = SERIAL_TYPE_NORMAL;
1791 m->tty_modem->init_termios = tty_std_termios;
1792 m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1793 m->tty_modem->flags = TTY_DRIVER_REAL_RAW;
1794 m->tty_modem->driver_name = "isdn_tty";
1795 tty_set_operations(m->tty_modem, &modem_ops);
1796 retval = tty_register_driver(m->tty_modem);
1798 printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n");
1801 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1803 #ifdef CONFIG_ISDN_TTY_FAX
1804 if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) {
1805 printk(KERN_ERR "Could not allocate fax t30-buffer\n");
1807 goto err_unregister;
1810 tty_port_init(&info->port);
1811 info->port.ops = &isdn_tty_port_ops;
1812 spin_lock_init(&info->readlock);
1813 sprintf(info->last_cause, "0000");
1814 sprintf(info->last_num, "none");
1816 info->last_lhup = 1;
1819 isdn_tty_reset_profile(&info->emu);
1820 isdn_tty_modem_reset_regs(info, 1);
1821 info->magic = ISDN_ASYNC_MAGIC;
1824 info->isdn_driver = -1;
1825 info->isdn_channel = -1;
1826 info->drv_index = -1;
1827 info->xmit_size = ISDN_SERIAL_XMIT_SIZE;
1828 init_timer(&info->nc_timer);
1829 info->nc_timer.function = isdn_tty_modem_do_ncarrier;
1830 info->nc_timer.data = (unsigned long) info;
1831 skb_queue_head_init(&info->xmit_queue);
1832 #ifdef CONFIG_ISDN_AUDIO
1833 skb_queue_head_init(&info->dtmf_queue);
1835 info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5,
1837 if (!info->port.xmit_buf) {
1838 printk(KERN_ERR "Could not allocate modem xmit-buffer\n");
1840 goto err_unregister;
1842 /* Make room for T.70 header */
1843 info->port.xmit_buf += 4;
1847 for (i--; i >= 0; i--) {
1849 #ifdef CONFIG_ISDN_TTY_FAX
1852 kfree(info->port.xmit_buf - 4);
1853 info->port.xmit_buf = NULL;
1854 tty_port_destroy(&info->port);
1856 tty_unregister_driver(m->tty_modem);
1858 put_tty_driver(m->tty_modem);
1859 m->tty_modem = NULL;
1869 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1870 info = &dev->mdm.info[i];
1871 isdn_tty_cleanup_xmit(info);
1872 #ifdef CONFIG_ISDN_TTY_FAX
1875 kfree(info->port.xmit_buf - 4);
1876 info->port.xmit_buf = NULL;
1877 tty_port_destroy(&info->port);
1879 tty_unregister_driver(dev->mdm.tty_modem);
1880 put_tty_driver(dev->mdm.tty_modem);
1881 dev->mdm.tty_modem = NULL;
1886 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
1887 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
1888 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
1892 isdn_tty_match_icall(char *cid, atemu *emu, int di)
1894 #ifdef ISDN_DEBUG_MODEM_ICALL
1895 printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
1896 emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di),
1897 emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]);
1899 if (strlen(emu->lmsn)) {
1900 char *p = emu->lmsn;
1906 if ((q = strchr(p, ';')))
1908 if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret)
1910 #ifdef ISDN_DEBUG_MODEM_ICALL
1911 printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
1912 p, isdn_map_eaz2msn(emu->msn, di), tmp);
1927 tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di));
1928 #ifdef ISDN_DEBUG_MODEM_ICALL
1929 printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n",
1930 isdn_map_eaz2msn(emu->msn, di), tmp);
1937 * An incoming call-request has arrived.
1938 * Search the tty-devices for an appropriate device and bind
1939 * it to the ISDN-Channel.
1942 * 0 = No matching device found.
1943 * 1 = A matching device found.
1944 * 3 = No match found, but eventually would match, if
1948 isdn_tty_find_icall(int di, int ch, setup_parm *setup)
1959 if (!setup->phone[0]) {
1961 printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n");
1964 si1 = (int) setup->si1;
1965 si2 = (int) setup->si2;
1966 if (!setup->eazmsn[0]) {
1967 printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n");
1970 eaz = setup->eazmsn;
1971 #ifdef ISDN_DEBUG_MODEM_ICALL
1972 printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2);
1975 spin_lock_irqsave(&dev->lock, flags);
1976 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
1977 modem_info *info = &dev->mdm.info[i];
1979 if (info->port.count == 0)
1981 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
1982 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
1983 idx = isdn_dc2minor(di, ch);
1984 #ifdef ISDN_DEBUG_MODEM_ICALL
1985 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret);
1986 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx,
1987 info->port.flags, info->isdn_driver,
1988 info->isdn_channel, dev->usage[idx]);
1991 #ifndef FIX_FILE_TRANSFER
1992 (info->port.flags & ASYNC_NORMAL_ACTIVE) &&
1994 (info->isdn_driver == -1) &&
1995 (info->isdn_channel == -1) &&
1996 (USG_NONE(dev->usage[idx]))) {
1999 if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret)
2001 if (!matchret) { /* EAZ is matching */
2002 info->isdn_driver = di;
2003 info->isdn_channel = ch;
2004 info->drv_index = idx;
2005 dev->m_idx[idx] = info->line;
2006 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2007 dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]);
2008 strcpy(dev->num[idx], nr);
2009 strcpy(info->emu.cpn, eaz);
2010 info->emu.mdmreg[REG_SI1I] = si2bit[si1];
2011 info->emu.mdmreg[REG_PLAN] = setup->plan;
2012 info->emu.mdmreg[REG_SCREEN] = setup->screen;
2014 spin_unlock_irqrestore(&dev->lock, flags);
2015 printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr,
2017 info->msr |= UART_MSR_RI;
2018 isdn_tty_modem_result(RESULT_RING, info);
2019 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1);
2025 spin_unlock_irqrestore(&dev->lock, flags);
2026 printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz,
2027 ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2)) ? "rejected" : "ignored");
2028 return (wret == 2) ? 3 : 0;
2031 #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE)
2034 isdn_tty_stat_callback(int i, isdn_ctrl *c)
2042 if ((mi = dev->m_idx[i]) >= 0) {
2043 info = &dev->mdm.info[mi];
2044 switch (c->command) {
2045 case ISDN_STAT_CINF:
2046 printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num);
2047 info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10);
2048 if (e == (char *)c->parm.num)
2049 info->emu.charge = 0;
2052 case ISDN_STAT_BSENT:
2053 #ifdef ISDN_TTY_STAT_DEBUG
2054 printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line);
2056 if ((info->isdn_driver == c->driver) &&
2057 (info->isdn_channel == c->arg)) {
2058 info->msr |= UART_MSR_CTS;
2059 if (info->send_outstanding)
2060 if (!(--info->send_outstanding))
2061 info->lsr |= UART_LSR_TEMT;
2062 isdn_tty_tint(info);
2066 case ISDN_STAT_CAUSE:
2067 #ifdef ISDN_TTY_STAT_DEBUG
2068 printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line);
2070 /* Signal cause to tty-device */
2071 strncpy(info->last_cause, c->parm.num, 5);
2073 case ISDN_STAT_DISPLAY:
2074 #ifdef ISDN_TTY_STAT_DEBUG
2075 printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line);
2077 /* Signal display to tty-device */
2078 if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) &&
2079 !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) {
2080 isdn_tty_at_cout("\r\n", info);
2081 isdn_tty_at_cout("DISPLAY: ", info);
2082 isdn_tty_at_cout(c->parm.display, info);
2083 isdn_tty_at_cout("\r\n", info);
2086 case ISDN_STAT_DCONN:
2087 #ifdef ISDN_TTY_STAT_DEBUG
2088 printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line);
2090 if (TTY_IS_ACTIVE(info)) {
2091 if (info->dialing == 1) {
2097 case ISDN_STAT_DHUP:
2098 #ifdef ISDN_TTY_STAT_DEBUG
2099 printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
2101 if (TTY_IS_ACTIVE(info)) {
2102 if (info->dialing == 1)
2103 isdn_tty_modem_result(RESULT_BUSY, info);
2104 if (info->dialing > 1)
2105 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
2107 #ifdef ISDN_DEBUG_MODEM_HUP
2108 printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n");
2110 isdn_tty_modem_hup(info, 0);
2114 case ISDN_STAT_BCONN:
2115 #ifdef ISDN_TTY_STAT_DEBUG
2116 printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line);
2118 /* Wake up any processes waiting
2119 * for incoming call of this device when
2120 * DCD follow the state of incoming carrier
2122 if (info->port.blocked_open &&
2123 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) {
2124 wake_up_interruptible(&info->port.open_wait);
2127 /* Schedule CONNECT-Message to any tty
2128 * waiting for it and
2129 * set DCD-bit of its modem-status.
2131 if (TTY_IS_ACTIVE(info) ||
2132 (info->port.blocked_open &&
2133 (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
2134 info->msr |= UART_MSR_DCD;
2135 info->emu.charge = 0;
2136 if (info->dialing & 0xf)
2142 if (USG_MODEM(dev->usage[i])) {
2143 if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) {
2144 strcpy(info->emu.connmsg, c->parm.num);
2145 isdn_tty_modem_result(RESULT_CONNECT, info);
2147 isdn_tty_modem_result(RESULT_CONNECT64000, info);
2149 if (USG_VOICE(dev->usage[i]))
2150 isdn_tty_modem_result(RESULT_VCON, info);
2154 case ISDN_STAT_BHUP:
2155 #ifdef ISDN_TTY_STAT_DEBUG
2156 printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
2158 if (TTY_IS_ACTIVE(info)) {
2159 #ifdef ISDN_DEBUG_MODEM_HUP
2160 printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
2162 isdn_tty_modem_hup(info, 0);
2166 case ISDN_STAT_NODCH:
2167 #ifdef ISDN_TTY_STAT_DEBUG
2168 printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line);
2170 if (TTY_IS_ACTIVE(info)) {
2171 if (info->dialing) {
2175 sprintf(info->last_cause, "0000");
2176 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
2178 isdn_tty_modem_hup(info, 0);
2182 case ISDN_STAT_UNLOAD:
2183 #ifdef ISDN_TTY_STAT_DEBUG
2184 printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line);
2186 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2187 info = &dev->mdm.info[i];
2188 if (info->isdn_driver == c->driver) {
2190 isdn_tty_modem_hup(info, 1);
2194 #ifdef CONFIG_ISDN_TTY_FAX
2195 case ISDN_STAT_FAXIND:
2196 if (TTY_IS_ACTIVE(info)) {
2197 isdn_tty_fax_command(info, c);
2201 #ifdef CONFIG_ISDN_AUDIO
2202 case ISDN_STAT_AUDIO:
2203 if (TTY_IS_ACTIVE(info)) {
2204 switch (c->parm.num[0]) {
2205 case ISDN_AUDIO_DTMF:
2206 if (info->vonline) {
2207 isdn_audio_put_dle_code(info,
2220 /*********************************************************************
2221 Modem-Emulator-Routines
2222 *********************************************************************/
2224 #define cmdchar(c) ((c >= ' ') && (c <= 0x7f))
2227 * Put a message from the AT-emulator into receive-buffer of tty,
2228 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2231 isdn_tty_at_cout(char *msg, modem_info *info)
2233 struct tty_struct *tty;
2234 struct tty_port *port = &info->port;
2235 atemu *m = &info->emu;
2239 struct sk_buff *skb = NULL;
2244 printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
2250 spin_lock_irqsave(&info->readlock, flags);
2252 if ((port->flags & ASYNC_CLOSING) || (!tty)) {
2253 spin_unlock_irqrestore(&info->readlock, flags);
2257 /* use queue instead of direct, if online and */
2258 /* data is in queue or buffer is full */
2259 if (info->online && ((tty_buffer_request_room(port, l) < l) ||
2260 !skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) {
2261 skb = alloc_skb(l, GFP_ATOMIC);
2263 spin_unlock_irqrestore(&info->readlock, flags);
2266 sp = skb_put(skb, l);
2267 #ifdef CONFIG_ISDN_AUDIO
2268 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
2269 ISDN_AUDIO_SKB_LOCK(skb) = 0;
2273 for (p = msg; *p; p++) {
2276 c = m->mdmreg[REG_CR];
2279 c = m->mdmreg[REG_LF];
2282 c = m->mdmreg[REG_BS];
2290 if (tty_insert_flip_char(port, c, TTY_NORMAL) == 0)
2295 __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb);
2296 dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len;
2297 spin_unlock_irqrestore(&info->readlock, flags);
2298 /* Schedule dequeuing */
2299 if (dev->modempoll && info->rcvsched)
2300 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
2303 spin_unlock_irqrestore(&info->readlock, flags);
2304 tty_flip_buffer_push(tty);
2309 * Perform ATH Hangup
2312 isdn_tty_on_hook(modem_info *info)
2314 if (info->isdn_channel >= 0) {
2315 #ifdef ISDN_DEBUG_MODEM_HUP
2316 printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n");
2318 isdn_tty_modem_hup(info, 1);
2323 isdn_tty_off_hook(void)
2325 printk(KERN_DEBUG "isdn_tty_off_hook\n");
2328 #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */
2329 #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */
2332 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2333 * isdn_tty_modem_escape() if sequence found.
2336 * p pointer to databuffer
2337 * plus escape-character
2338 * count length of buffer
2339 * pluscount count of valid escape-characters so far
2340 * lastplus timestamp of last character
2343 isdn_tty_check_esc(const u_char *p, u_char plus, int count, int *pluscount,
2354 if (*(p++) == plus) {
2355 if ((*pluscount)++) {
2356 /* Time since last '+' > 0.5 sec. ? */
2357 if (time_after(jiffies, *lastplus + PLUSWAIT1))
2360 /* Time since last non-'+' < 1.5 sec. ? */
2361 if (time_before(jiffies, *lastplus + PLUSWAIT2))
2364 if ((*pluscount == 3) && (count == 1))
2365 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1);
2370 *lastplus = jiffies;
2376 * Return result of AT-emulator to tty-receive-buffer, depending on
2377 * modem-register 12, bit 0 and 1.
2378 * For CONNECT-messages also switch to online-mode.
2379 * For RING-message handle auto-ATA if register 0 != 0
2383 isdn_tty_modem_result(int code, modem_info *info)
2385 atemu *m = &info->emu;
2386 static char *msg[] =
2387 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2388 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2389 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2390 char s[ISDN_MSNLEN + 10];
2394 m->mdmreg[REG_RINGCNT]++;
2395 if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA])
2396 /* Automatically accept incoming call */
2397 isdn_tty_cmd_ATA(info);
2399 case RESULT_NO_CARRIER:
2400 #ifdef ISDN_DEBUG_MODEM_HUP
2401 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n",
2402 (info->port.flags & ASYNC_CLOSING),
2405 m->mdmreg[REG_RINGCNT] = 0;
2406 del_timer(&info->nc_timer);
2408 if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty))
2411 #ifdef CONFIG_ISDN_AUDIO
2412 if (info->vonline & 1) {
2413 #ifdef ISDN_DEBUG_MODEM_VOICE
2414 printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n",
2417 /* voice-recording, add DLE-ETX */
2418 isdn_tty_at_cout("\020\003", info);
2420 if (info->vonline & 2) {
2421 #ifdef ISDN_DEBUG_MODEM_VOICE
2422 printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n",
2425 /* voice-playing, add DLE-DC4 */
2426 isdn_tty_at_cout("\020\024", info);
2430 case RESULT_CONNECT:
2431 case RESULT_CONNECT64000:
2432 sprintf(info->last_cause, "0000");
2437 #ifdef ISDN_DEBUG_MODEM_VOICE
2438 printk(KERN_DEBUG "res3: send VCON on ttyI%d\n",
2441 sprintf(info->last_cause, "0000");
2445 } /* switch (code) */
2447 if (m->mdmreg[REG_RESP] & BIT_RESP) {
2449 if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) {
2450 /* Show numeric results only */
2451 sprintf(s, "\r\n%d\r\n", code);
2452 isdn_tty_at_cout(s, info);
2454 if (code == RESULT_RING) {
2455 /* return if "show RUNG" and ringcounter>1 */
2456 if ((m->mdmreg[REG_RUNG] & BIT_RUNG) &&
2457 (m->mdmreg[REG_RINGCNT] > 1))
2459 /* print CID, _before_ _every_ ring */
2460 if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) {
2461 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info);
2462 isdn_tty_at_cout(dev->num[info->drv_index], info);
2463 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2464 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2465 isdn_tty_at_cout(info->emu.cpn, info);
2469 isdn_tty_at_cout("\r\n", info);
2470 isdn_tty_at_cout(msg[code], info);
2472 case RESULT_CONNECT:
2473 switch (m->mdmreg[REG_L2PROT]) {
2474 case ISDN_PROTO_L2_MODEM:
2475 isdn_tty_at_cout(" ", info);
2476 isdn_tty_at_cout(m->connmsg, info);
2481 /* Append CPN, if enabled */
2482 if ((m->mdmreg[REG_CPN] & BIT_CPN)) {
2483 sprintf(s, "/%s", m->cpn);
2484 isdn_tty_at_cout(s, info);
2486 /* Print CID only once, _after_ 1st RING */
2487 if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) &&
2488 (m->mdmreg[REG_RINGCNT] == 1)) {
2489 isdn_tty_at_cout("\r\n", info);
2490 isdn_tty_at_cout("CALLER NUMBER: ", info);
2491 isdn_tty_at_cout(dev->num[info->drv_index], info);
2492 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2493 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2494 isdn_tty_at_cout(info->emu.cpn, info);
2498 case RESULT_NO_CARRIER:
2499 case RESULT_NO_DIALTONE:
2501 case RESULT_NO_ANSWER:
2502 m->mdmreg[REG_RINGCNT] = 0;
2503 /* Append Cause-Message if enabled */
2504 if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) {
2505 sprintf(s, "/%s", info->last_cause);
2506 isdn_tty_at_cout(s, info);
2509 case RESULT_CONNECT64000:
2510 /* Append Protocol to CONNECT message */
2511 switch (m->mdmreg[REG_L2PROT]) {
2512 case ISDN_PROTO_L2_X75I:
2513 case ISDN_PROTO_L2_X75UI:
2514 case ISDN_PROTO_L2_X75BUI:
2515 isdn_tty_at_cout("/X.75", info);
2517 case ISDN_PROTO_L2_HDLC:
2518 isdn_tty_at_cout("/HDLC", info);
2520 case ISDN_PROTO_L2_V11096:
2521 isdn_tty_at_cout("/V110/9600", info);
2523 case ISDN_PROTO_L2_V11019:
2524 isdn_tty_at_cout("/V110/19200", info);
2526 case ISDN_PROTO_L2_V11038:
2527 isdn_tty_at_cout("/V110/38400", info);
2530 if (m->mdmreg[REG_T70] & BIT_T70) {
2531 isdn_tty_at_cout("/T.70", info);
2532 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2533 isdn_tty_at_cout("+", info);
2537 isdn_tty_at_cout("\r\n", info);
2540 if (code == RESULT_NO_CARRIER) {
2541 if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty))
2544 if (info->port.flags & ASYNC_CHECK_CD)
2545 tty_hangup(info->port.tty);
2551 * Display a modem-register-value.
2554 isdn_tty_show_profile(int ridx, modem_info *info)
2558 sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]);
2559 isdn_tty_at_cout(v, info);
2563 * Get MSN-string from char-pointer, set pointer to end of number
2566 isdn_tty_get_msnstr(char *n, char **p)
2568 int limit = ISDN_MSNLEN - 1;
2570 while (((*p[0] >= '0' && *p[0] <= '9') ||
2571 /* Why a comma ??? */
2572 (*p[0] == ',') || (*p[0] == ':')) &&
2579 * Get phone-number from modem-commandbuffer
2582 isdn_tty_getdial(char *p, char *q, int cnt)
2585 int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
2588 while (strchr(" 0123456789,#.*WPTSR-", *p) && *p && --cnt > 0) {
2589 if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
2590 ((*p == 'R') && first) ||
2591 (*p == '*') || (*p == '#')) {
2603 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2604 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2607 isdn_tty_report(modem_info *info)
2609 atemu *m = &info->emu;
2612 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info);
2613 sprintf(s, " Remote Number: %s\r\n", info->last_num);
2614 isdn_tty_at_cout(s, info);
2615 sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming");
2616 isdn_tty_at_cout(s, info);
2617 isdn_tty_at_cout(" Layer-2 Protocol: ", info);
2618 switch (info->last_l2) {
2619 case ISDN_PROTO_L2_X75I:
2620 isdn_tty_at_cout("X.75i", info);
2622 case ISDN_PROTO_L2_X75UI:
2623 isdn_tty_at_cout("X.75ui", info);
2625 case ISDN_PROTO_L2_X75BUI:
2626 isdn_tty_at_cout("X.75bui", info);
2628 case ISDN_PROTO_L2_HDLC:
2629 isdn_tty_at_cout("HDLC", info);
2631 case ISDN_PROTO_L2_V11096:
2632 isdn_tty_at_cout("V.110 9600 Baud", info);
2634 case ISDN_PROTO_L2_V11019:
2635 isdn_tty_at_cout("V.110 19200 Baud", info);
2637 case ISDN_PROTO_L2_V11038:
2638 isdn_tty_at_cout("V.110 38400 Baud", info);
2640 case ISDN_PROTO_L2_TRANS:
2641 isdn_tty_at_cout("transparent", info);
2643 case ISDN_PROTO_L2_MODEM:
2644 isdn_tty_at_cout("modem", info);
2646 case ISDN_PROTO_L2_FAX:
2647 isdn_tty_at_cout("fax", info);
2650 isdn_tty_at_cout("unknown", info);
2653 if (m->mdmreg[REG_T70] & BIT_T70) {
2654 isdn_tty_at_cout("/T.70", info);
2655 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2656 isdn_tty_at_cout("+", info);
2658 isdn_tty_at_cout("\r\n", info);
2659 isdn_tty_at_cout(" Service: ", info);
2660 switch (info->last_si) {
2662 isdn_tty_at_cout("audio\r\n", info);
2665 isdn_tty_at_cout("btx\r\n", info);
2668 isdn_tty_at_cout("data\r\n", info);
2671 sprintf(s, "%d\r\n", info->last_si);
2672 isdn_tty_at_cout(s, info);
2675 sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote");
2676 isdn_tty_at_cout(s, info);
2677 sprintf(s, " Last cause: %s\r\n", info->last_cause);
2678 isdn_tty_at_cout(s, info);
2682 * Parse AT&.. commands.
2685 isdn_tty_cmd_ATand(char **p, modem_info *info)
2687 atemu *m = &info->emu;
2691 #define MAXRB (sizeof(rb) - 1)
2695 /* &B - Set Buffersize */
2698 if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX))
2700 #ifdef CONFIG_ISDN_AUDIO
2701 if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF))
2704 m->mdmreg[REG_PSIZE] = i / 16;
2705 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2706 switch (m->mdmreg[REG_L2PROT]) {
2707 case ISDN_PROTO_L2_V11096:
2708 case ISDN_PROTO_L2_V11019:
2709 case ISDN_PROTO_L2_V11038:
2710 info->xmit_size /= 10;
2714 /* &C - DCD Status */
2716 switch (isdn_getnum(p)) {
2718 m->mdmreg[REG_DCD] &= ~BIT_DCD;
2721 m->mdmreg[REG_DCD] |= BIT_DCD;
2728 /* &D - Set DTR-Low-behavior */
2730 switch (isdn_getnum(p)) {
2732 m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP;
2733 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2736 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2737 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2740 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2741 m->mdmreg[REG_DTRR] |= BIT_DTRR;
2748 /* &E -Set EAZ/MSN */
2750 isdn_tty_get_msnstr(m->msn, p);
2753 /* &F -Set Factory-Defaults */
2755 if (info->msr & UART_MSR_DCD)
2757 isdn_tty_reset_profile(m);
2758 isdn_tty_modem_reset_regs(info, 1);
2760 #ifdef DUMMY_HAYES_AT
2762 /* only for be compilant with common scripts */
2763 /* &K Flowcontrol - no function */
2769 /* &L -Set Numbers to listen on */
2772 while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) &&
2773 (i < ISDN_LMSNLEN - 1))
2774 m->lmsn[i++] = *p[0]++;
2778 /* &R - Set V.110 bitrate adaption */
2783 /* Switch off V.110, back to X.75 */
2784 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2785 m->mdmreg[REG_SI2] = 0;
2786 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2789 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096;
2790 m->mdmreg[REG_SI2] = 197;
2791 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2794 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019;
2795 m->mdmreg[REG_SI2] = 199;
2796 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2799 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038;
2800 m->mdmreg[REG_SI2] = 198; /* no existing standard for this */
2801 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
2806 /* Switch off T.70 */
2807 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
2809 m->mdmreg[REG_SI1] |= 4;
2812 /* &S - Set Windowsize */
2815 if ((i > 0) && (i < 9))
2816 m->mdmreg[REG_WSIZE] = i;
2821 /* &V - Show registers */
2823 isdn_tty_at_cout("\r\n", info);
2824 for (i = 0; i < ISDN_MODEM_NUMREG; i++) {
2825 sprintf(rb, "S%02d=%03d%s", i,
2826 m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n");
2827 isdn_tty_at_cout(rb, info);
2829 sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n",
2830 strlen(m->msn) ? m->msn : "None");
2831 isdn_tty_at_cout(rb, info);
2832 if (strlen(m->lmsn)) {
2833 isdn_tty_at_cout("\r\nListen: ", info);
2834 isdn_tty_at_cout(m->lmsn, info);
2835 isdn_tty_at_cout("\r\n", info);
2839 /* &W - Write Profile */
2844 modem_write_profile(m);
2851 /* &X - Switch to BTX-Mode and T.70 */
2853 switch (isdn_getnum(p)) {
2855 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
2856 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2859 m->mdmreg[REG_T70] |= BIT_T70;
2860 m->mdmreg[REG_T70] &= ~BIT_T70_EXT;
2861 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2862 info->xmit_size = 112;
2863 m->mdmreg[REG_SI1] = 4;
2864 m->mdmreg[REG_SI2] = 0;
2867 m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT);
2868 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
2869 info->xmit_size = 112;
2870 m->mdmreg[REG_SI1] = 4;
2871 m->mdmreg[REG_SI2] = 0;
2884 isdn_tty_check_ats(int mreg, int mval, modem_info *info, atemu *m)
2886 /* Some plausibility checks */
2889 if (mval > ISDN_PROTO_L2_MAX)
2893 if ((mval * 16) > ISDN_SERIAL_XMIT_MAX)
2895 #ifdef CONFIG_ISDN_AUDIO
2896 if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX))
2899 info->xmit_size = mval * 16;
2900 switch (m->mdmreg[REG_L2PROT]) {
2901 case ISDN_PROTO_L2_V11096:
2902 case ISDN_PROTO_L2_V11019:
2903 case ISDN_PROTO_L2_V11038:
2904 info->xmit_size /= 10;
2910 /* readonly registers */
2917 * Perform ATS command
2920 isdn_tty_cmd_ATS(char **p, modem_info *info)
2922 atemu *m = &info->emu;
2928 mreg = isdn_getnum(p);
2929 if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG)
2934 mval = isdn_getnum(p);
2935 if (mval < 0 || mval > 255)
2937 if (isdn_tty_check_ats(mreg, mval, info, m))
2939 m->mdmreg[mreg] = mval;
2942 /* Set/Clear a single bit */
2944 bitpos = isdn_getnum(p);
2945 if ((bitpos < 0) || (bitpos > 7))
2950 bval = isdn_getnum(p);
2951 if (bval < 0 || bval > 1)
2954 mval = m->mdmreg[mreg] | (1 << bitpos);
2956 mval = m->mdmreg[mreg] & ~(1 << bitpos);
2957 if (isdn_tty_check_ats(mreg, mval, info, m))
2959 m->mdmreg[mreg] = mval;
2963 isdn_tty_at_cout("\r\n", info);
2964 isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0",
2973 isdn_tty_show_profile(mreg, info);
2983 * Perform ATA command
2986 isdn_tty_cmd_ATA(modem_info *info)
2988 atemu *m = &info->emu;
2992 if (info->msr & UART_MSR_RI) {
2993 /* Accept incoming call */
2995 strcpy(info->last_num, dev->num[info->drv_index]);
2996 m->mdmreg[REG_RINGCNT] = 0;
2997 info->msr &= ~UART_MSR_RI;
2998 l2 = m->mdmreg[REG_L2PROT];
2999 #ifdef CONFIG_ISDN_AUDIO
3000 /* If more than one bit set in reg18, autoselect Layer2 */
3001 if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) {
3002 if (m->mdmreg[REG_SI1I] == 1) {
3003 if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX))
3004 l2 = ISDN_PROTO_L2_TRANS;
3006 l2 = ISDN_PROTO_L2_X75I;
3009 cmd.driver = info->isdn_driver;
3010 cmd.command = ISDN_CMD_SETL2;
3011 cmd.arg = info->isdn_channel + (l2 << 8);
3014 cmd.driver = info->isdn_driver;
3015 cmd.command = ISDN_CMD_SETL3;
3016 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
3017 #ifdef CONFIG_ISDN_TTY_FAX
3018 if (l2 == ISDN_PROTO_L2_FAX) {
3019 cmd.parm.fax = info->fax;
3020 info->fax->direction = ISDN_TTY_FAX_CONN_IN;
3024 cmd.driver = info->isdn_driver;
3025 cmd.arg = info->isdn_channel;
3026 cmd.command = ISDN_CMD_ACCEPTD;
3028 info->emu.carrierwait = 0;
3030 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
3032 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3035 #ifdef CONFIG_ISDN_AUDIO
3037 * Parse AT+F.. commands
3040 isdn_tty_cmd_PLUSF(char **p, modem_info *info)
3042 atemu *m = &info->emu;
3045 if (!strncmp(p[0], "CLASS", 5)) {
3050 sprintf(rs, "\r\n%d",
3051 (m->mdmreg[REG_SI1] & 1) ? 8 : 0);
3052 #ifdef CONFIG_ISDN_TTY_FAX
3053 if (TTY_IS_FCLASS2(info))
3054 sprintf(rs, "\r\n2");
3055 else if (TTY_IS_FCLASS1(info))
3056 sprintf(rs, "\r\n1");
3058 isdn_tty_at_cout(rs, info);
3065 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3066 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3067 m->mdmreg[REG_SI1] = 4;
3069 m->mdmreg[REG_PSIZE] * 16;
3071 #ifdef CONFIG_ISDN_TTY_FAX
3074 if (!(dev->global_features &
3075 ISDN_FEATURE_L3_FCLASS1))
3077 m->mdmreg[REG_SI1] = 1;
3078 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3079 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1;
3081 m->mdmreg[REG_PSIZE] * 16;
3085 if (!(dev->global_features &
3086 ISDN_FEATURE_L3_FCLASS2))
3088 m->mdmreg[REG_SI1] = 1;
3089 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3090 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2;
3092 m->mdmreg[REG_PSIZE] * 16;
3097 /* L2 will change on dialout with si=1 */
3098 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3099 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3100 m->mdmreg[REG_SI1] = 5;
3101 info->xmit_size = VBUF;
3105 strcpy(rs, "\r\n0,");
3106 #ifdef CONFIG_ISDN_TTY_FAX
3107 if (dev->global_features &
3108 ISDN_FEATURE_L3_FCLASS1)
3110 if (dev->global_features &
3111 ISDN_FEATURE_L3_FCLASS2)
3115 isdn_tty_at_cout(rs, info);
3126 #ifdef CONFIG_ISDN_TTY_FAX
3127 return (isdn_tty_cmd_PLUSF_FAX(p, info));
3134 * Parse AT+V.. commands
3137 isdn_tty_cmd_PLUSV(char **p, modem_info *info)
3139 atemu *m = &info->emu;
3141 static char *vcmd[] =
3142 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL};
3150 if (!strncmp(vcmd[i], p[0], 2)) {
3158 /* AT+VNH - Auto hangup feature */
3162 isdn_tty_at_cout("\r\n1", info);
3172 isdn_tty_at_cout("\r\n1", info);
3183 /* AT+VIP - Reset all voice parameters */
3184 isdn_tty_modem_reset_vpar(m);
3187 /* AT+VLS - Select device, accept incoming call */
3191 sprintf(rs, "\r\n%d", m->vpar[0]);
3192 isdn_tty_at_cout(rs, info);
3207 isdn_tty_at_cout("\r\n0,2", info);
3218 /* AT+VRX - Start recording */
3221 if (info->online != 1) {
3222 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3225 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3226 if (!info->dtmf_state) {
3227 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3230 info->silence_state = isdn_audio_silence_init(info->silence_state);
3231 if (!info->silence_state) {
3232 printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n");
3235 if (m->vpar[3] < 5) {
3236 info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]);
3237 if (!info->adpcmr) {
3238 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3242 #ifdef ISDN_DEBUG_AT
3243 printk(KERN_DEBUG "AT: +VRX\n");
3246 isdn_tty_modem_result(RESULT_CONNECT, info);
3250 /* AT+VSD - Silence detection */
3254 sprintf(rs, "\r\n<%d>,<%d>",
3257 isdn_tty_at_cout(rs, info);
3261 if ((*p[0] >= '0') && (*p[0] <= '9')) {
3262 par1 = isdn_getnum(p);
3263 if ((par1 < 0) || (par1 > 31))
3268 par2 = isdn_getnum(p);
3269 if ((par2 < 0) || (par2 > 255))
3277 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3288 /* AT+VSM - Select compression */
3292 sprintf(rs, "\r\n<%d>,<%d><8000>",
3295 isdn_tty_at_cout(rs, info);
3305 par1 = isdn_getnum(p);
3306 if ((par1 < 2) || (par1 > 6))
3312 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3314 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3316 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3318 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3320 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3332 /* AT+VTX - Start sending */
3335 if (info->online != 1) {
3336 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3339 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3340 if (!info->dtmf_state) {
3341 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3344 if (m->vpar[3] < 5) {
3345 info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]);
3346 if (!info->adpcms) {
3347 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3351 #ifdef ISDN_DEBUG_AT
3352 printk(KERN_DEBUG "AT: +VTX\n");
3356 isdn_tty_modem_result(RESULT_CONNECT, info);
3360 /* AT+VDD - DTMF detection */
3364 sprintf(rs, "\r\n<%d>,<%d>",
3367 isdn_tty_at_cout(rs, info);
3371 if ((*p[0] >= '0') && (*p[0] <= '9')) {
3372 if (info->online != 1)
3374 par1 = isdn_getnum(p);
3375 if ((par1 < 0) || (par1 > 15))
3380 par2 = isdn_getnum(p);
3381 if ((par2 < 0) || (par2 > 255))
3385 cmd.driver = info->isdn_driver;
3386 cmd.command = ISDN_CMD_AUDIO;
3387 cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8);
3388 cmd.parm.num[0] = par1;
3389 cmd.parm.num[1] = par2;
3395 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3410 #endif /* CONFIG_ISDN_AUDIO */
3413 * Parse and perform an AT-command-line.
3416 isdn_tty_parse_at(modem_info *info)
3418 atemu *m = &info->emu;
3420 char ds[ISDN_MSNLEN];
3422 #ifdef ISDN_DEBUG_AT
3423 printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd);
3425 for (p = &m->mdmcmd[2]; *p;) {
3431 /* A - Accept incoming call */
3433 isdn_tty_cmd_ATA(info);
3438 if (info->msr & UART_MSR_DCD)
3440 if (info->msr & UART_MSR_RI) {
3441 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3444 isdn_tty_getdial(++p, ds, sizeof ds);
3446 if (!strlen(m->msn))
3447 isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info);
3448 else if (strlen(ds))
3449 isdn_tty_dial(ds, info, m);
3454 /* E - Turn Echo on/off */
3456 switch (isdn_getnum(&p)) {
3458 m->mdmreg[REG_ECHO] &= ~BIT_ECHO;
3461 m->mdmreg[REG_ECHO] |= BIT_ECHO;
3468 /* H - On/Off-hook */
3473 isdn_tty_on_hook(info);
3477 isdn_tty_off_hook();
3480 isdn_tty_on_hook(info);
3485 /* I - Information */
3487 isdn_tty_at_cout("\r\nLinux ISDN", info);
3495 isdn_tty_report(info);
3499 snprintf(ds, sizeof(ds), "\r\n%d", info->emu.charge);
3500 isdn_tty_at_cout(ds, info);
3505 #ifdef DUMMY_HAYES_AT
3508 /* only for be compilant with common scripts */
3517 if (info->msr & UART_MSR_DCD)
3518 /* if B-Channel is up */
3519 isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT : RESULT_CONNECT64000, info);
3521 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3524 /* Q - Turn Emulator messages on/off */
3526 switch (isdn_getnum(&p)) {
3528 m->mdmreg[REG_RESP] |= BIT_RESP;
3531 m->mdmreg[REG_RESP] &= ~BIT_RESP;
3538 /* S - Set/Get Register */
3540 if (isdn_tty_cmd_ATS(&p, info))
3544 /* V - Numeric or ASCII Emulator-messages */
3546 switch (isdn_getnum(&p)) {
3548 m->mdmreg[REG_RESP] |= BIT_RESPNUM;
3551 m->mdmreg[REG_RESP] &= ~BIT_RESPNUM;
3558 /* Z - Load Registers from Profile */
3560 if (info->msr & UART_MSR_DCD) {
3562 isdn_tty_on_hook(info);
3564 isdn_tty_modem_reset_regs(info, 1);
3569 #ifdef CONFIG_ISDN_AUDIO
3572 if (isdn_tty_cmd_PLUSF(&p, info))
3576 if ((!(m->mdmreg[REG_SI1] & 1)) ||
3577 (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM))
3580 if (isdn_tty_cmd_PLUSV(&p, info))
3583 #endif /* CONFIG_ISDN_AUDIO */
3584 case 'S': /* SUSPEND */
3586 isdn_tty_get_msnstr(ds, &p);
3587 isdn_tty_suspend(ds, info, m);
3589 case 'R': /* RESUME */
3591 isdn_tty_get_msnstr(ds, &p);
3592 isdn_tty_resume(ds, info, m);
3594 case 'M': /* MESSAGE */
3596 isdn_tty_send_msg(info, m, p);
3604 if (isdn_tty_cmd_ATand(&p, info))
3611 #ifdef CONFIG_ISDN_AUDIO
3614 isdn_tty_modem_result(RESULT_OK, info);
3617 /* Need own toupper() because standard-toupper is not available
3620 #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c)
3623 * Perform line-editing of AT-commands
3627 * count length of buffer
3628 * channel index to line (minor-device)
3631 isdn_tty_edit_at(const char *p, int count, modem_info *info)
3633 atemu *m = &info->emu;
3639 for (cnt = count; cnt > 0; p++, cnt--) {
3642 if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) {
3643 /* Separator (CR or LF) */
3644 m->mdmcmd[m->mdmcmdl] = 0;
3645 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3648 isdn_tty_at_cout(eb, info);
3650 if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2))))
3651 isdn_tty_parse_at(info);
3655 if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) {
3656 /* Backspace-Function */
3657 if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) {
3660 if (m->mdmreg[REG_ECHO] & BIT_ECHO)
3661 isdn_tty_at_cout("\b", info);
3666 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3669 isdn_tty_at_cout(eb, info);
3671 if (m->mdmcmdl < 255) {
3673 switch (m->mdmcmdl) {
3676 m->mdmcmd[m->mdmcmdl] = c;
3677 m->mdmcmd[++m->mdmcmdl] = 0;
3681 /* Fall through, check for 'A' */
3684 m->mdmcmd[m->mdmcmdl] = c;
3685 m->mdmcmd[++m->mdmcmdl] = 0;
3689 m->mdmcmd[m->mdmcmdl] = c;
3690 m->mdmcmd[++m->mdmcmdl] = 0;
3699 * Switch all modem-channels who are online and got a valid
3700 * escape-sequence 1.5 seconds ago, to command-mode.
3701 * This function is called every second via timer-interrupt from within
3702 * timer-dispatcher isdn_timer_function()
3705 isdn_tty_modem_escape(void)
3711 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
3712 if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) {
3713 modem_info *info = &dev->mdm.info[midx];
3716 if ((info->emu.pluscount == 3) &&
3718 info->emu.lastplus + PLUSWAIT2)) {
3719 info->emu.pluscount = 0;
3721 isdn_tty_modem_result(RESULT_OK, info);
3725 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
3729 * Put a RING-message to all modem-channels who have the RI-bit set.
3730 * This function is called every second via timer-interrupt from within
3731 * timer-dispatcher isdn_timer_function()
3734 isdn_tty_modem_ring(void)
3739 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3740 modem_info *info = &dev->mdm.info[i];
3741 if (info->msr & UART_MSR_RI) {
3743 isdn_tty_modem_result(RESULT_RING, info);
3746 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton);
3750 * For all online tty's, try sending data to
3754 isdn_tty_modem_xmit(void)
3759 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3760 modem_info *info = &dev->mdm.info[i];
3763 isdn_tty_senddown(info);
3764 isdn_tty_tint(info);
3767 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton);
3771 * Check all channels if we have a 'no carrier' timeout.
3772 * Timeout value is set by Register S7.
3775 isdn_tty_carrier_timeout(void)
3780 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3781 modem_info *info = &dev->mdm.info[i];
3784 if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
3786 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3787 isdn_tty_modem_hup(info, 1);
3791 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);