1 /* $Id: isdn_tty.c,v 1.1.4.1 2001/11/20 14:19:34 kai Exp $
3 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
12 #undef ISDN_TTY_STAT_DEBUG
14 #include <linux/config.h>
15 #include <linux/isdn.h>
16 #include "isdn_common.h"
18 #ifdef CONFIG_ISDN_AUDIO
19 #include "isdn_audio.h"
21 #define VBUFX (VBUF/16)
24 #define FIX_FILE_TRANSFER
25 #define DUMMY_HAYES_AT
29 static int isdn_tty_edit_at(const char *, int, modem_info *, int);
30 static void isdn_tty_check_esc(const u_char *, u_char, int, int *, int *, int);
31 static void isdn_tty_modem_reset_regs(modem_info *, int);
32 static void isdn_tty_cmd_ATA(modem_info *);
33 static void isdn_tty_flush_buffer(struct tty_struct *);
34 static void isdn_tty_modem_result(int, modem_info *);
35 #ifdef CONFIG_ISDN_AUDIO
36 static int isdn_tty_countDLE(unsigned char *, int);
39 /* Leave this unchanged unless you know what you do! */
40 #define MODEM_PARANOIA_CHECK
41 #define MODEM_DO_RESTART
43 #ifdef CONFIG_DEVFS_FS
44 static char *isdn_ttyname_ttyI = "isdn/ttyI%d";
45 static char *isdn_ttyname_cui = "isdn/cui%d";
47 static char *isdn_ttyname_ttyI = "ttyI";
48 static char *isdn_ttyname_cui = "cui";
51 static int bit2si[8] =
52 {1, 5, 7, 7, 7, 7, 7, 7};
53 static int si2bit[8] =
54 {4, 1, 4, 4, 4, 4, 4, 4};
56 char *isdn_tty_revision = "$Revision: 1.1.4.1 $";
59 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
60 * to stuff incoming data directly into a tty's flip-buffer. This
61 * is done to speed up tty-receiving if the receive-queue is empty.
62 * This routine MUST be called with interrupts off.
65 * 0 = Failure, data has to be buffered and later processed by
66 * isdn_tty_readmodem().
69 isdn_tty_try_read(modem_info * info, struct sk_buff *skb)
73 struct tty_struct *tty;
76 if ((tty = info->tty)) {
77 if (info->mcr & UART_MCR_RTS) {
78 c = TTY_FLIPBUF_SIZE - tty->flip.count;
80 #ifdef CONFIG_ISDN_AUDIO
81 + ISDN_AUDIO_SKB_DLECOUNT(skb)
85 #ifdef CONFIG_ISDN_AUDIO
86 if (ISDN_AUDIO_SKB_DLECOUNT(skb))
88 if (*skb->data == DLE)
89 tty_insert_flip_char(tty, DLE, 0);
90 tty_insert_flip_char(tty, *skb->data++, 0);
93 memcpy(tty->flip.char_buf_ptr,
95 tty->flip.count += len;
96 tty->flip.char_buf_ptr += len;
97 memset(tty->flip.flag_buf_ptr, 0, len);
98 tty->flip.flag_buf_ptr += len;
99 #ifdef CONFIG_ISDN_AUDIO
102 if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
103 tty->flip.flag_buf_ptr[len - 1] = 0xff;
104 queue_task(&tty->flip.tqueue, &tq_timer);
114 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
115 * It tries getting received data from the receive queue an stuff it into
116 * the tty's flip-buffer.
119 isdn_tty_readmodem(void)
127 struct tty_struct *tty;
130 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
131 if ((midx = dev->m_idx[i]) >= 0) {
132 info = &dev->mdm.info[midx];
135 #ifdef CONFIG_ISDN_AUDIO
136 isdn_audio_eval_dtmf(info);
137 if ((info->vonline & 1) && (info->emu.vpar[1]))
138 isdn_audio_eval_silence(info);
140 if ((tty = info->tty)) {
141 if (info->mcr & UART_MCR_RTS) {
142 c = TTY_FLIPBUF_SIZE - tty->flip.count;
146 r = isdn_readbchan(info->isdn_driver, info->isdn_channel,
147 tty->flip.char_buf_ptr,
148 tty->flip.flag_buf_ptr, c, 0);
149 /* CISCO AsyncPPP Hack */
150 if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
151 memset(tty->flip.flag_buf_ptr, 0, r);
152 tty->flip.count += r;
153 tty->flip.flag_buf_ptr += r;
154 tty->flip.char_buf_ptr += r;
156 queue_task(&tty->flip.tqueue, &tq_timer);
157 restore_flags(flags);
172 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
176 isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb)
180 #ifdef CONFIG_ISDN_AUDIO
185 if ((midx = dev->m_idx[i]) < 0) {
186 /* if midx is invalid, packet is not for tty */
189 info = &dev->mdm.info[midx];
190 #ifdef CONFIG_ISDN_AUDIO
193 if ((info->vonline) && (!info->emu.vpar[4]))
194 isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt);
195 if ((info->vonline & 1) && (info->emu.vpar[1]))
196 isdn_audio_calc_silence(info, skb->data, skb->len, ifmt);
198 if ((info->online < 2)
199 #ifdef CONFIG_ISDN_AUDIO
200 && (!(info->vonline & 1))
203 /* If Modem not listening, drop data */
207 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
208 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) {
209 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
210 if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */
213 if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */
216 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
217 if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1)))
220 #ifdef CONFIG_ISDN_AUDIO
221 if (skb_headroom(skb) < sizeof(isdn_audio_skb)) {
223 "isdn_audio: insufficient skb_headroom, dropping\n");
227 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
228 ISDN_AUDIO_SKB_LOCK(skb) = 0;
229 if (info->vonline & 1) {
230 /* voice conversion/compression */
231 switch (info->emu.vpar[3]) {
236 * Since compressed data takes less
237 * space, we can overwrite the buffer.
239 skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr,
248 isdn_audio_ulaw2alaw(skb->data, skb->len);
253 isdn_audio_alaw2ulaw(skb->data, skb->len);
256 ISDN_AUDIO_SKB_DLECOUNT(skb) =
257 isdn_tty_countDLE(skb->data, skb->len);
259 #ifdef CONFIG_ISDN_TTY_FAX
261 if (info->faxonline & 2) {
262 isdn_tty_fax_bitorder(info, skb);
263 ISDN_AUDIO_SKB_DLECOUNT(skb) =
264 isdn_tty_countDLE(skb->data, skb->len);
269 /* Try to deliver directly via tty-flip-buf if queue is empty */
272 if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
273 if (isdn_tty_try_read(info, skb)) {
274 restore_flags(flags);
277 /* Direct deliver failed or queue wasn't empty.
278 * Queue up for later dequeueing via timer-irq.
280 __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb);
281 dev->drv[di]->rcvcount[channel] +=
283 #ifdef CONFIG_ISDN_AUDIO
284 + ISDN_AUDIO_SKB_DLECOUNT(skb)
287 restore_flags(flags);
288 /* Schedule dequeuing */
289 if ((dev->modempoll) && (info->rcvsched))
290 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
295 isdn_tty_cleanup_xmit(modem_info * info)
301 skb_queue_purge(&info->xmit_queue);
302 #ifdef CONFIG_ISDN_AUDIO
303 skb_queue_purge(&info->dtmf_queue);
305 restore_flags(flags);
309 isdn_tty_tint(modem_info * info)
311 struct sk_buff *skb = skb_dequeue(&info->xmit_queue);
318 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
319 info->isdn_channel, 1, skb)) == len) {
320 struct tty_struct *tty = info->tty;
321 info->send_outstanding++;
322 info->msr &= ~UART_MSR_CTS;
323 info->lsr &= ~UART_LSR_TEMT;
328 /* Error: no channel, already shutdown, or wrong parameter */
332 skb_queue_head(&info->xmit_queue, skb);
335 #ifdef CONFIG_ISDN_AUDIO
337 isdn_tty_countDLE(unsigned char *buf, int len)
347 /* This routine is called from within isdn_tty_write() to perform
348 * DLE-decoding when sending audio-data.
351 isdn_tty_handleDLEdown(modem_info * info, atemu * m, int len)
353 unsigned char *p = &info->xmit_buf[info->xmit_count];
363 memmove(p, p + 1, len - 1);
374 #ifdef ISDN_DEBUG_MODEM_VOICE
376 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
379 isdn_tty_at_cout("\020\003", info);
380 if (!info->vonline) {
381 #ifdef ISDN_DEBUG_MODEM_VOICE
383 "DLEdown: send VCON on ttyI%d\n",
386 isdn_tty_at_cout("\r\nVCON\r\n", info);
393 memmove(p, p + 1, len - 1);
407 printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n");
413 /* This routine is called from within isdn_tty_write() when receiving
414 * audio-data. It interrupts receiving, if an character other than
418 isdn_tty_end_vrx(const char *buf, int c, int from_user)
427 if ((ch != 0x11) && (ch != 0x13))
434 static int voice_cf[7] =
435 {0, 0, 4, 3, 2, 0, 0};
437 #endif /* CONFIG_ISDN_AUDIO */
439 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
440 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
441 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
442 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
445 isdn_tty_senddown(modem_info * info)
449 #ifdef CONFIG_ISDN_AUDIO
454 #ifdef CONFIG_ISDN_AUDIO
455 if (info->vonline & 4) {
457 if (!info->vonline) {
458 #ifdef ISDN_DEBUG_MODEM_VOICE
460 "senddown: send VCON on ttyI%d\n",
463 isdn_tty_at_cout("\r\nVCON\r\n", info);
467 if (!(buflen = info->xmit_count))
469 if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0)
470 info->msr &= ~UART_MSR_CTS;
471 info->lsr &= ~UART_LSR_TEMT;
472 /* info->xmit_count is modified here and in isdn_tty_write().
473 * So we return here if isdn_tty_write() is in the
476 atomic_inc(&info->xmit_lock);
477 if (!(atomic_dec_and_test(&info->xmit_lock)))
479 if (info->isdn_driver < 0) {
480 info->xmit_count = 0;
483 skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4;
484 #ifdef CONFIG_ISDN_AUDIO
485 if (info->vonline & 2)
486 audio_len = buflen * voice_cf[info->emu.vpar[3]];
489 skb = dev_alloc_skb(skb_res + buflen + audio_len);
491 skb = dev_alloc_skb(skb_res + buflen);
495 "isdn_tty: Out of memory in ttyI%d senddown\n",
499 skb_reserve(skb, skb_res);
500 memcpy(skb_put(skb, buflen), info->xmit_buf, buflen);
501 info->xmit_count = 0;
502 #ifdef CONFIG_ISDN_AUDIO
503 if (info->vonline & 2) {
504 /* For now, ifmt is fixed to 1 (alaw), since this
505 * is used with ISDN everywhere in the world, except
506 * US, Canada and Japan.
507 * Later, when US-ISDN protocols are implemented,
508 * this setting will depend on the D-channel protocol.
512 /* voice conversion/decompression */
513 switch (info->emu.vpar[3]) {
517 /* adpcm, compatible to ZyXel 1496 modem
518 * with ROM revision 6.01
520 audio_len = isdn_audio_adpcm2xlaw(info->adpcms,
523 skb_put(skb, audio_len),
525 skb_pull(skb, buflen);
526 skb_trim(skb, audio_len);
531 isdn_audio_alaw2ulaw(skb->data,
537 isdn_audio_ulaw2alaw(skb->data,
542 #endif /* CONFIG_ISDN_AUDIO */
543 if (info->emu.mdmreg[REG_T70] & BIT_T70) {
544 /* Add T.70 simplified header */
545 if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT)
546 memcpy(skb_push(skb, 2), "\1\0", 2);
548 memcpy(skb_push(skb, 4), "\1\0\1\0", 4);
550 skb_queue_tail(&info->xmit_queue, skb);
553 /************************************************************
557 * mostly "stolen" from original Linux-serial.c and friends.
559 ************************************************************/
561 /* The next routine is called once from within timer-interrupt
562 * triggered within isdn_tty_modem_ncarrier(). It calls
563 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
564 * into the tty's flip-buffer.
567 isdn_tty_modem_do_ncarrier(unsigned long data)
569 modem_info *info = (modem_info *) data;
570 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
573 /* Next routine is called, whenever the DTR-signal is raised.
574 * It checks the ncarrier-flag, and triggers the above routine
575 * when necessary. The ncarrier-flag is set, whenever DTR goes
579 isdn_tty_modem_ncarrier(modem_info * info)
581 if (info->ncarrier) {
582 info->nc_timer.expires = jiffies + HZ;
583 info->nc_timer.function = isdn_tty_modem_do_ncarrier;
584 info->nc_timer.data = (unsigned long) info;
585 add_timer(&info->nc_timer);
590 * return the usage calculated by si and layer 2 protocol
593 isdn_calc_usage(int si, int l2)
595 int usg = ISDN_USAGE_MODEM;
597 #ifdef CONFIG_ISDN_AUDIO
600 case ISDN_PROTO_L2_MODEM:
601 usg = ISDN_USAGE_MODEM;
603 #ifdef CONFIG_ISDN_TTY_FAX
604 case ISDN_PROTO_L2_FAX:
605 usg = ISDN_USAGE_FAX;
608 case ISDN_PROTO_L2_TRANS:
610 usg = ISDN_USAGE_VOICE;
618 /* isdn_tty_dial() performs dialing of a tty an the necessary
619 * setup of the lower levels before that.
622 isdn_tty_dial(char *n, modem_info * info, atemu * m)
624 int usg = ISDN_USAGE_MODEM;
626 int l2 = m->mdmreg[REG_L2PROT];
632 for (j = 7; j >= 0; j--)
633 if (m->mdmreg[REG_SI1] & (1 << j)) {
637 usg = isdn_calc_usage(si, l2);
638 #ifdef CONFIG_ISDN_AUDIO
640 (l2 != ISDN_PROTO_L2_MODEM)
641 #ifdef CONFIG_ISDN_TTY_FAX
642 && (l2 != ISDN_PROTO_L2_FAX)
645 l2 = ISDN_PROTO_L2_TRANS;
646 usg = ISDN_USAGE_VOICE;
649 m->mdmreg[REG_SI1I] = si2bit[si];
652 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
654 restore_flags(flags);
655 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
657 info->isdn_driver = dev->drvmap[i];
658 info->isdn_channel = dev->chanmap[i];
660 dev->m_idx[i] = info->line;
661 dev->usage[i] |= ISDN_USAGE_OUTGOING;
663 strcpy(info->last_num, n);
665 restore_flags(flags);
666 cmd.driver = info->isdn_driver;
667 cmd.arg = info->isdn_channel;
668 cmd.command = ISDN_CMD_CLREAZ;
670 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
671 cmd.driver = info->isdn_driver;
672 cmd.command = ISDN_CMD_SETEAZ;
674 cmd.driver = info->isdn_driver;
675 cmd.command = ISDN_CMD_SETL2;
677 cmd.arg = info->isdn_channel + (l2 << 8);
679 cmd.driver = info->isdn_driver;
680 cmd.command = ISDN_CMD_SETL3;
681 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
682 #ifdef CONFIG_ISDN_TTY_FAX
683 if (l2 == ISDN_PROTO_L2_FAX) {
684 cmd.parm.fax = info->fax;
685 info->fax->direction = ISDN_TTY_FAX_CONN_OUT;
689 cmd.driver = info->isdn_driver;
690 cmd.arg = info->isdn_channel;
691 sprintf(cmd.parm.setup.phone, "%s", n);
692 sprintf(cmd.parm.setup.eazmsn, "%s",
693 isdn_map_eaz2msn(m->msn, info->isdn_driver));
694 cmd.parm.setup.si1 = si;
695 cmd.parm.setup.si2 = m->mdmreg[REG_SI2];
696 cmd.command = ISDN_CMD_DIAL;
698 info->emu.carrierwait = 0;
699 strcpy(dev->num[i], n);
702 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
706 /* isdn_tty_hangup() disassociates a tty from the real
707 * ISDN-line (hangup). The usage-status is cleared
708 * and some cleanup is done also.
711 isdn_tty_modem_hup(modem_info * info, int local)
719 di = info->isdn_driver;
720 ch = info->isdn_channel;
721 if (di < 0 || ch < 0)
724 info->isdn_driver = -1;
725 info->isdn_channel = -1;
727 #ifdef ISDN_DEBUG_MODEM_HUP
728 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
731 isdn_tty_flush_buffer(info->tty);
733 info->last_lhup = local;
735 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
737 #ifdef CONFIG_ISDN_AUDIO
739 #ifdef CONFIG_ISDN_TTY_FAX
741 info->fax->phase = ISDN_FAX_PHASE_IDLE;
743 info->emu.vpar[4] = 0;
744 info->emu.vpar[5] = 8;
745 if (info->dtmf_state) {
746 kfree(info->dtmf_state);
747 info->dtmf_state = NULL;
749 if (info->silence_state) {
750 kfree(info->silence_state);
751 info->silence_state = NULL;
762 if ((info->msr & UART_MSR_RI) &&
763 (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
764 isdn_tty_modem_result(RESULT_RUNG, info);
765 info->msr &= ~(UART_MSR_DCD | UART_MSR_RI);
766 info->lsr |= UART_LSR_TEMT;
770 cmd.command = ISDN_CMD_HANGUP;
775 isdn_all_eaz(di, ch);
776 info->emu.mdmreg[REG_RINGCNT] = 0;
777 isdn_free_channel(di, ch, 0);
779 if (info->drv_index >= 0) {
780 dev->m_idx[info->drv_index] = -1;
781 info->drv_index = -1;
786 * Begin of a CAPI like interface, currently used only for
787 * supplementary service (CAPI 2.0 part III)
789 #include "avmb1/capicmd.h" /* this should be moved in a common place */
792 isdn_tty_capi_facility(capi_msg *cm) {
793 return(-1); /* dummy */
796 /* isdn_tty_suspend() tries to suspend the current tty connection
799 isdn_tty_suspend(char *id, modem_info * info, atemu * m)
808 #ifdef ISDN_DEBUG_MODEM_SERVICES
809 printk(KERN_DEBUG "Msusp ttyI%d\n", info->line);
812 if ((info->isdn_driver >= 0)) {
813 cmd.parm.cmsg.Length = l+18;
814 cmd.parm.cmsg.Command = CAPI_FACILITY;
815 cmd.parm.cmsg.Subcommand = CAPI_REQ;
816 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
817 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
818 cmd.parm.cmsg.para[1] = 0;
819 cmd.parm.cmsg.para[2] = l + 3;
820 cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
821 cmd.parm.cmsg.para[4] = 0;
822 cmd.parm.cmsg.para[5] = l;
823 strncpy(&cmd.parm.cmsg.para[6], id, l);
824 cmd.command = CAPI_PUT_MESSAGE;
825 cmd.driver = info->isdn_driver;
826 cmd.arg = info->isdn_channel;
831 /* isdn_tty_resume() tries to resume a suspended call
832 * setup of the lower levels before that. unfortunatly here is no
833 * checking for compatibility of used protocols implemented by Q931
834 * It does the same things like isdn_tty_dial, the last command
835 * is different, may be we can merge it.
839 isdn_tty_resume(char *id, modem_info * info, atemu * m)
841 int usg = ISDN_USAGE_MODEM;
843 int l2 = m->mdmreg[REG_L2PROT];
851 for (j = 7; j >= 0; j--)
852 if (m->mdmreg[REG_SI1] & (1 << j)) {
856 usg = isdn_calc_usage(si, l2);
857 #ifdef CONFIG_ISDN_AUDIO
859 (l2 != ISDN_PROTO_L2_MODEM)
860 #ifdef CONFIG_ISDN_TTY_FAX
861 && (l2 != ISDN_PROTO_L2_FAX)
864 l2 = ISDN_PROTO_L2_TRANS;
865 usg = ISDN_USAGE_VOICE;
868 m->mdmreg[REG_SI1I] = si2bit[si];
871 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
873 restore_flags(flags);
874 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
876 info->isdn_driver = dev->drvmap[i];
877 info->isdn_channel = dev->chanmap[i];
879 dev->m_idx[i] = info->line;
880 dev->usage[i] |= ISDN_USAGE_OUTGOING;
882 // strcpy(info->last_num, n);
884 restore_flags(flags);
885 cmd.driver = info->isdn_driver;
886 cmd.arg = info->isdn_channel;
887 cmd.command = ISDN_CMD_CLREAZ;
889 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
890 cmd.driver = info->isdn_driver;
891 cmd.command = ISDN_CMD_SETEAZ;
893 cmd.driver = info->isdn_driver;
894 cmd.command = ISDN_CMD_SETL2;
896 cmd.arg = info->isdn_channel + (l2 << 8);
898 cmd.driver = info->isdn_driver;
899 cmd.command = ISDN_CMD_SETL3;
900 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
902 cmd.driver = info->isdn_driver;
903 cmd.arg = info->isdn_channel;
904 cmd.parm.cmsg.Length = l+18;
905 cmd.parm.cmsg.Command = CAPI_FACILITY;
906 cmd.parm.cmsg.Subcommand = CAPI_REQ;
907 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
908 cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
909 cmd.parm.cmsg.para[1] = 0;
910 cmd.parm.cmsg.para[2] = l+3;
911 cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
912 cmd.parm.cmsg.para[4] = 0;
913 cmd.parm.cmsg.para[5] = l;
914 strncpy(&cmd.parm.cmsg.para[6], id, l);
915 cmd.command =CAPI_PUT_MESSAGE;
917 // strcpy(dev->num[i], n);
920 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
924 /* isdn_tty_send_msg() sends a message to a HL driver
925 * This is used for hybrid modem cards to send AT commands to it
929 isdn_tty_send_msg(modem_info * info, atemu * m, char *msg)
931 int usg = ISDN_USAGE_MODEM;
933 int l2 = m->mdmreg[REG_L2PROT];
942 isdn_tty_modem_result(RESULT_ERROR, info);
945 for (j = 7; j >= 0; j--)
946 if (m->mdmreg[REG_SI1] & (1 << j)) {
950 usg = isdn_calc_usage(si, l2);
951 #ifdef CONFIG_ISDN_AUDIO
953 (l2 != ISDN_PROTO_L2_MODEM)
954 #ifdef CONFIG_ISDN_TTY_FAX
955 && (l2 != ISDN_PROTO_L2_FAX)
958 l2 = ISDN_PROTO_L2_TRANS;
959 usg = ISDN_USAGE_VOICE;
962 m->mdmreg[REG_SI1I] = si2bit[si];
965 i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
967 restore_flags(flags);
968 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
970 info->isdn_driver = dev->drvmap[i];
971 info->isdn_channel = dev->chanmap[i];
973 dev->m_idx[i] = info->line;
974 dev->usage[i] |= ISDN_USAGE_OUTGOING;
977 restore_flags(flags);
978 cmd.driver = info->isdn_driver;
979 cmd.arg = info->isdn_channel;
980 cmd.command = ISDN_CMD_CLREAZ;
982 strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
983 cmd.driver = info->isdn_driver;
984 cmd.command = ISDN_CMD_SETEAZ;
986 cmd.driver = info->isdn_driver;
987 cmd.command = ISDN_CMD_SETL2;
989 cmd.arg = info->isdn_channel + (l2 << 8);
991 cmd.driver = info->isdn_driver;
992 cmd.command = ISDN_CMD_SETL3;
993 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
995 cmd.driver = info->isdn_driver;
996 cmd.arg = info->isdn_channel;
997 cmd.parm.cmsg.Length = l+14;
998 cmd.parm.cmsg.Command = CAPI_MANUFACTURER;
999 cmd.parm.cmsg.Subcommand = CAPI_REQ;
1000 cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
1001 cmd.parm.cmsg.para[0] = l+1;
1002 strncpy(&cmd.parm.cmsg.para[1], msg, l);
1003 cmd.parm.cmsg.para[l+1] = 0xd;
1004 cmd.command =CAPI_PUT_MESSAGE;
1005 /* info->dialing = 1;
1006 strcpy(dev->num[i], n);
1014 isdn_tty_paranoia_check(modem_info * info, kdev_t device, const char *routine)
1016 #ifdef MODEM_PARANOIA_CHECK
1018 printk(KERN_WARNING "isdn_tty: null info_struct for (%d, %d) in %s\n",
1019 MAJOR(device), MINOR(device), routine);
1022 if (info->magic != ISDN_ASYNC_MAGIC) {
1023 printk(KERN_WARNING "isdn_tty: bad magic for modem struct (%d, %d) in %s\n",
1024 MAJOR(device), MINOR(device), routine);
1032 * This routine is called to set the UART divisor registers to match
1033 * the specified baud rate for a serial port.
1036 isdn_tty_change_speed(modem_info * info)
1044 if (!info->tty || !info->tty->termios)
1046 cflag = info->tty->termios->c_cflag;
1048 quot = i = cflag & CBAUD;
1052 info->tty->termios->c_cflag &= ~CBAUDEX;
1057 info->mcr |= UART_MCR_DTR;
1058 isdn_tty_modem_ncarrier(info);
1060 info->mcr &= ~UART_MCR_DTR;
1061 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1062 #ifdef ISDN_DEBUG_MODEM_HUP
1063 printk(KERN_DEBUG "Mhup in changespeed\n");
1067 isdn_tty_modem_reset_regs(info, 0);
1068 isdn_tty_modem_hup(info, 1);
1072 /* byte size and parity */
1073 cval = cflag & (CSIZE | CSTOPB);
1076 cval |= UART_LCR_PARITY;
1077 if (!(cflag & PARODD))
1078 cval |= UART_LCR_EPAR;
1081 /* CTS flow control flag and modem status interrupts */
1082 if (cflag & CRTSCTS) {
1083 info->flags |= ISDN_ASYNC_CTS_FLOW;
1085 info->flags &= ~ISDN_ASYNC_CTS_FLOW;
1087 info->flags &= ~ISDN_ASYNC_CHECK_CD;
1089 info->flags |= ISDN_ASYNC_CHECK_CD;
1094 isdn_tty_startup(modem_info * info)
1098 if (info->flags & ISDN_ASYNC_INITIALIZED)
1102 isdn_MOD_INC_USE_COUNT();
1103 #ifdef ISDN_DEBUG_MODEM_OPEN
1104 printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line);
1107 * Now, initialize the UART
1109 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
1111 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1113 * and set the speed of the serial port
1115 isdn_tty_change_speed(info);
1117 info->flags |= ISDN_ASYNC_INITIALIZED;
1118 info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
1119 info->send_outstanding = 0;
1120 restore_flags(flags);
1125 * This routine will shutdown a serial port; interrupts are disabled, and
1126 * DTR is dropped if the hangup on close termio flag is on.
1129 isdn_tty_shutdown(modem_info * info)
1133 if (!(info->flags & ISDN_ASYNC_INITIALIZED))
1135 #ifdef ISDN_DEBUG_MODEM_OPEN
1136 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
1139 cli(); /* Disable interrupts */
1140 isdn_MOD_DEC_USE_COUNT();
1141 info->msr &= ~UART_MSR_RI;
1142 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1143 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
1144 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1145 isdn_tty_modem_reset_regs(info, 0);
1146 #ifdef ISDN_DEBUG_MODEM_HUP
1147 printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n");
1149 isdn_tty_modem_hup(info, 1);
1153 set_bit(TTY_IO_ERROR, &info->tty->flags);
1155 info->flags &= ~ISDN_ASYNC_INITIALIZED;
1156 restore_flags(flags);
1159 /* isdn_tty_write() is the main send-routine. It is called from the upper
1160 * levels within the kernel to perform sending data. Depending on the
1161 * online-flag it either directs output to the at-command-interpreter or
1162 * to the lower level. Additional tasks done here:
1163 * - If online, check for escape-sequence (+++)
1164 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1165 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1166 * - If dialing, abort dial.
1169 isdn_tty_write(struct tty_struct *tty, int from_user, const u_char * buf, int count)
1173 modem_info *info = (modem_info *) tty->driver_data;
1174 atemu *m = &info->emu;
1176 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_write"))
1179 down(&info->write_sem);
1180 /* See isdn_tty_senddown() */
1181 atomic_inc(&info->xmit_lock);
1184 if (c > info->xmit_size - info->xmit_count)
1185 c = info->xmit_size - info->xmit_count;
1186 if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize)
1187 c = dev->drv[info->isdn_driver]->maxbufsize;
1190 if ((info->online > 1)
1191 #ifdef CONFIG_ISDN_AUDIO
1192 || (info->vonline & 3)
1195 #ifdef CONFIG_ISDN_AUDIO
1198 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
1203 copy_from_user(&(info->xmit_buf[info->xmit_count]), buf, c);
1205 memcpy(&(info->xmit_buf[info->xmit_count]), buf, c);
1206 #ifdef CONFIG_ISDN_AUDIO
1207 if (info->vonline) {
1208 int cc = isdn_tty_handleDLEdown(info, m, c);
1209 if (info->vonline & 2) {
1211 /* If DLE decoding results in zero-transmit, but
1212 * c originally was non-zero, do a wakeup.
1215 info->msr |= UART_MSR_CTS;
1216 info->lsr |= UART_LSR_TEMT;
1218 info->xmit_count += cc;
1220 if ((info->vonline & 3) == 1) {
1221 /* Do NOT handle Ctrl-Q or Ctrl-S
1222 * when in full-duplex audio mode.
1224 if (isdn_tty_end_vrx(buf, c, from_user)) {
1225 info->vonline &= ~1;
1226 #ifdef ISDN_DEBUG_MODEM_VOICE
1228 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1231 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
1235 if (TTY_IS_FCLASS1(info)) {
1236 int cc = isdn_tty_handleDLEdown(info, m, c);
1238 if (info->vonline & 4) { /* ETX seen */
1241 c.command = ISDN_CMD_FAXCMD;
1242 c.driver = info->isdn_driver;
1243 c.arg = info->isdn_channel;
1244 c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
1245 c.parm.aux.subcmd = ETX;
1249 #ifdef ISDN_DEBUG_MODEM_VOICE
1250 printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c);
1252 info->xmit_count += cc;
1255 info->xmit_count += c;
1257 info->msr |= UART_MSR_CTS;
1258 info->lsr |= UART_LSR_TEMT;
1259 if (info->dialing) {
1261 #ifdef ISDN_DEBUG_MODEM_HUP
1262 printk(KERN_DEBUG "Mhup in isdn_tty_write\n");
1264 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
1265 isdn_tty_modem_hup(info, 1);
1267 c = isdn_tty_edit_at(buf, c, info, from_user);
1273 atomic_dec(&info->xmit_lock);
1274 if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue))) {
1275 if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
1276 isdn_tty_senddown(info);
1277 isdn_tty_tint(info);
1279 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1282 up(&info->write_sem);
1287 isdn_tty_write_room(struct tty_struct *tty)
1289 modem_info *info = (modem_info *) tty->driver_data;
1292 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_write_room"))
1295 return info->xmit_size;
1296 ret = info->xmit_size - info->xmit_count;
1297 return (ret < 0) ? 0 : ret;
1301 isdn_tty_chars_in_buffer(struct tty_struct *tty)
1303 modem_info *info = (modem_info *) tty->driver_data;
1305 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_chars_in_buffer"))
1309 return (info->xmit_count);
1313 isdn_tty_flush_buffer(struct tty_struct *tty)
1316 unsigned long flags;
1321 restore_flags(flags);
1324 info = (modem_info *) tty->driver_data;
1325 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_flush_buffer")) {
1326 restore_flags(flags);
1329 isdn_tty_cleanup_xmit(info);
1330 info->xmit_count = 0;
1331 restore_flags(flags);
1336 isdn_tty_flush_chars(struct tty_struct *tty)
1338 modem_info *info = (modem_info *) tty->driver_data;
1340 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_flush_chars"))
1342 if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue)))
1343 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1347 * ------------------------------------------------------------
1348 * isdn_tty_throttle()
1350 * This routine is called by the upper-layer tty layer to signal that
1351 * incoming characters should be throttled.
1352 * ------------------------------------------------------------
1355 isdn_tty_throttle(struct tty_struct *tty)
1357 modem_info *info = (modem_info *) tty->driver_data;
1359 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_throttle"))
1362 info->x_char = STOP_CHAR(tty);
1363 info->mcr &= ~UART_MCR_RTS;
1367 isdn_tty_unthrottle(struct tty_struct *tty)
1369 modem_info *info = (modem_info *) tty->driver_data;
1371 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_unthrottle"))
1377 info->x_char = START_CHAR(tty);
1379 info->mcr |= UART_MCR_RTS;
1383 * ------------------------------------------------------------
1384 * isdn_tty_ioctl() and friends
1385 * ------------------------------------------------------------
1389 * isdn_tty_get_lsr_info - get line status register info
1391 * Purpose: Let user call ioctl() to get info when the UART physically
1392 * is emptied. On bus types like RS485, the transmitter must
1393 * release the bus after transmitting. This must be done when
1394 * the transmit shift register is empty, not be done when the
1395 * transmit holding register is empty. This functionality
1396 * allows RS485 driver to be written in user space.
1399 isdn_tty_get_lsr_info(modem_info * info, uint * value)
1408 restore_flags(flags);
1409 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1410 return put_user(result, (uint *) value);
1415 isdn_tty_get_modem_info(modem_info * info, uint * value)
1422 control = info->mcr;
1426 restore_flags(flags);
1427 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1428 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1429 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1430 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1431 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1432 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1433 return put_user(result, (uint *) value);
1437 isdn_tty_set_modem_info(modem_info * info, uint cmd, uint * value)
1442 if (get_user(arg, (uint *) value))
1446 #ifdef ISDN_DEBUG_MODEM_IOCTL
1447 printk(KERN_DEBUG "ttyI%d ioctl TIOCMBIS\n", info->line);
1449 if (arg & TIOCM_RTS) {
1450 info->mcr |= UART_MCR_RTS;
1452 if (arg & TIOCM_DTR) {
1453 info->mcr |= UART_MCR_DTR;
1454 isdn_tty_modem_ncarrier(info);
1458 #ifdef ISDN_DEBUG_MODEM_IOCTL
1459 printk(KERN_DEBUG "ttyI%d ioctl TIOCMBIC\n", info->line);
1461 if (arg & TIOCM_RTS) {
1462 info->mcr &= ~UART_MCR_RTS;
1464 if (arg & TIOCM_DTR) {
1465 info->mcr &= ~UART_MCR_DTR;
1466 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1467 isdn_tty_modem_reset_regs(info, 0);
1468 #ifdef ISDN_DEBUG_MODEM_HUP
1469 printk(KERN_DEBUG "Mhup in TIOCMBIC\n");
1473 isdn_tty_modem_hup(info, 1);
1478 #ifdef ISDN_DEBUG_MODEM_IOCTL
1479 printk(KERN_DEBUG "ttyI%d ioctl TIOCMSET\n", info->line);
1481 pre_dtr = (info->mcr & UART_MCR_DTR);
1482 info->mcr = ((info->mcr & ~(UART_MCR_RTS | UART_MCR_DTR))
1483 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1484 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1485 if (pre_dtr |= (info->mcr & UART_MCR_DTR)) {
1486 if (!(info->mcr & UART_MCR_DTR)) {
1487 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1488 isdn_tty_modem_reset_regs(info, 0);
1489 #ifdef ISDN_DEBUG_MODEM_HUP
1490 printk(KERN_DEBUG "Mhup in TIOCMSET\n");
1494 isdn_tty_modem_hup(info, 1);
1497 isdn_tty_modem_ncarrier(info);
1507 isdn_tty_ioctl(struct tty_struct *tty, struct file *file,
1508 uint cmd, ulong arg)
1510 modem_info *info = (modem_info *) tty->driver_data;
1513 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_ioctl"))
1515 if (tty->flags & (1 << TTY_IO_ERROR))
1518 case TCSBRK: /* SVID version: non-zero arg --> no break */
1519 #ifdef ISDN_DEBUG_MODEM_IOCTL
1520 printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line);
1522 retval = tty_check_change(tty);
1525 tty_wait_until_sent(tty, 0);
1527 case TCSBRKP: /* support for POSIX tcsendbreak() */
1528 #ifdef ISDN_DEBUG_MODEM_IOCTL
1529 printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line);
1531 retval = tty_check_change(tty);
1534 tty_wait_until_sent(tty, 0);
1537 #ifdef ISDN_DEBUG_MODEM_IOCTL
1538 printk(KERN_DEBUG "ttyI%d ioctl TIOCGSOFTCAR\n", info->line);
1540 return put_user(C_CLOCAL(tty) ? 1 : 0, (ulong *) arg);
1542 #ifdef ISDN_DEBUG_MODEM_IOCTL
1543 printk(KERN_DEBUG "ttyI%d ioctl TIOCSSOFTCAR\n", info->line);
1545 if (get_user(arg, (ulong *) arg))
1547 tty->termios->c_cflag =
1548 ((tty->termios->c_cflag & ~CLOCAL) |
1549 (arg ? CLOCAL : 0));
1552 #ifdef ISDN_DEBUG_MODEM_IOCTL
1553 printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
1555 return isdn_tty_get_modem_info(info, (uint *) arg);
1559 return isdn_tty_set_modem_info(info, cmd, (uint *) arg);
1560 case TIOCSERGETLSR: /* Get line status register */
1561 #ifdef ISDN_DEBUG_MODEM_IOCTL
1562 printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);
1564 return isdn_tty_get_lsr_info(info, (uint *) arg);
1566 #ifdef ISDN_DEBUG_MODEM_IOCTL
1567 printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line);
1569 return -ENOIOCTLCMD;
1575 isdn_tty_set_termios(struct tty_struct *tty, struct termios *old_termios)
1577 modem_info *info = (modem_info *) tty->driver_data;
1580 isdn_tty_change_speed(info);
1582 if (tty->termios->c_cflag == old_termios->c_cflag)
1584 isdn_tty_change_speed(info);
1585 if ((old_termios->c_cflag & CRTSCTS) &&
1586 !(tty->termios->c_cflag & CRTSCTS)) {
1587 tty->hw_stopped = 0;
1593 * ------------------------------------------------------------
1594 * isdn_tty_open() and friends
1595 * ------------------------------------------------------------
1598 isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info * info)
1600 DECLARE_WAITQUEUE(wait, NULL);
1602 unsigned long flags;
1606 * If the device is in the middle of being closed, then block
1607 * until it's done, and then try again.
1609 if (tty_hung_up_p(filp) ||
1610 (info->flags & ISDN_ASYNC_CLOSING)) {
1611 if (info->flags & ISDN_ASYNC_CLOSING)
1612 interruptible_sleep_on(&info->close_wait);
1613 #ifdef MODEM_DO_RESTART
1614 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1617 return -ERESTARTSYS;
1623 * If this is a callout device, then just make sure the normal
1624 * device isn't being used.
1626 if (tty->driver.subtype == ISDN_SERIAL_TYPE_CALLOUT) {
1627 if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)
1629 if ((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
1630 (info->flags & ISDN_ASYNC_SESSION_LOCKOUT) &&
1631 (info->session != current->session))
1633 if ((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
1634 (info->flags & ISDN_ASYNC_PGRP_LOCKOUT) &&
1635 (info->pgrp != current->pgrp))
1637 info->flags |= ISDN_ASYNC_CALLOUT_ACTIVE;
1641 * If non-blocking mode is set, then make the check up front
1644 if ((filp->f_flags & O_NONBLOCK) ||
1645 (tty->flags & (1 << TTY_IO_ERROR))) {
1646 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1648 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1651 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) {
1652 if (info->normal_termios.c_cflag & CLOCAL)
1655 if (tty->termios->c_cflag & CLOCAL)
1659 * Block waiting for the carrier detect and the line to become
1660 * free (i.e., not in use by the callout). While we are in
1661 * this loop, info->count is dropped by one, so that
1662 * isdn_tty_close() knows when to free things. We restore it upon
1663 * exit, either normal or abnormal.
1666 add_wait_queue(&info->open_wait, &wait);
1667 #ifdef ISDN_DEBUG_MODEM_OPEN
1668 printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1669 info->line, info->count);
1673 if (!(tty_hung_up_p(filp)))
1675 restore_flags(flags);
1676 info->blocked_open++;
1678 set_current_state(TASK_INTERRUPTIBLE);
1679 if (tty_hung_up_p(filp) ||
1680 !(info->flags & ISDN_ASYNC_INITIALIZED)) {
1681 #ifdef MODEM_DO_RESTART
1682 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1685 retval = -ERESTARTSYS;
1691 if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
1692 !(info->flags & ISDN_ASYNC_CLOSING) &&
1693 (do_clocal || (info->msr & UART_MSR_DCD))) {
1696 if (signal_pending(current)) {
1697 retval = -ERESTARTSYS;
1700 #ifdef ISDN_DEBUG_MODEM_OPEN
1701 printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1702 info->line, info->count);
1706 current->state = TASK_RUNNING;
1707 remove_wait_queue(&info->open_wait, &wait);
1708 if (!tty_hung_up_p(filp))
1710 info->blocked_open--;
1711 #ifdef ISDN_DEBUG_MODEM_OPEN
1712 printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1713 info->line, info->count);
1717 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1722 * This routine is called whenever a serial port is opened. It
1723 * enables interrupts for a serial port, linking in its async structure into
1724 * the IRQ chain. It also performs the serial-specific
1725 * initialization for the tty structure.
1728 isdn_tty_open(struct tty_struct *tty, struct file *filp)
1734 line = MINOR(tty->device) - tty->driver.minor_start;
1735 if (line < 0 || line > ISDN_MAX_CHANNELS)
1737 info = &dev->mdm.info[line];
1738 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_open"))
1740 #ifdef ISDN_DEBUG_MODEM_OPEN
1741 printk(KERN_DEBUG "isdn_tty_open %s%d, count = %d\n", tty->driver.name,
1742 info->line, info->count);
1745 tty->driver_data = info;
1748 * Start up serial port
1750 retval = isdn_tty_startup(info);
1752 #ifdef ISDN_DEBUG_MODEM_OPEN
1753 printk(KERN_DEBUG "isdn_tty_open return after startup\n");
1757 retval = isdn_tty_block_til_ready(tty, filp, info);
1759 #ifdef ISDN_DEBUG_MODEM_OPEN
1760 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");
1764 if ((info->count == 1) && (info->flags & ISDN_ASYNC_SPLIT_TERMIOS)) {
1765 if (tty->driver.subtype == ISDN_SERIAL_TYPE_NORMAL)
1766 *tty->termios = info->normal_termios;
1768 *tty->termios = info->callout_termios;
1769 isdn_tty_change_speed(info);
1771 info->session = current->session;
1772 info->pgrp = current->pgrp;
1773 #ifdef ISDN_DEBUG_MODEM_OPEN
1774 printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line);
1777 #ifdef ISDN_DEBUG_MODEM_OPEN
1778 printk(KERN_DEBUG "isdn_tty_open normal exit\n");
1784 isdn_tty_close(struct tty_struct *tty, struct file *filp)
1786 modem_info *info = (modem_info *) tty->driver_data;
1790 if (!info || isdn_tty_paranoia_check(info, tty->device, "isdn_tty_close"))
1794 if (tty_hung_up_p(filp)) {
1795 restore_flags(flags);
1796 #ifdef ISDN_DEBUG_MODEM_OPEN
1797 printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n");
1801 if ((tty->count == 1) && (info->count != 1)) {
1803 * Uh, oh. tty->count is 1, which means that the tty
1804 * structure will be freed. Info->count should always
1805 * be one in these conditions. If it's greater than
1806 * one, we've got real problems, since it means the
1807 * serial port won't be shutdown.
1809 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
1810 "info->count is %d\n", info->count);
1813 if (--info->count < 0) {
1814 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
1815 info->line, info->count);
1819 restore_flags(flags);
1820 #ifdef ISDN_DEBUG_MODEM_OPEN
1821 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
1825 info->flags |= ISDN_ASYNC_CLOSING;
1827 * Save the termios structure, since this port may have
1828 * separate termios for callout and dialin.
1830 if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)
1831 info->normal_termios = *tty->termios;
1832 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1833 info->callout_termios = *tty->termios;
1837 * At this point we stop accepting input. To do this, we
1838 * disable the receive line status interrupts, and tell the
1839 * interrupt driver to stop checking the data ready bit in the
1840 * line status register.
1842 if (info->flags & ISDN_ASYNC_INITIALIZED) {
1843 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1845 * Before we drop DTR, make sure the UART transmitter
1846 * has completely drained; this is especially
1847 * important if there is a transmit FIFO!
1849 timeout = jiffies + HZ;
1850 while (!(info->lsr & UART_LSR_TEMT)) {
1851 set_current_state(TASK_INTERRUPTIBLE);
1852 schedule_timeout(20);
1853 if (time_after(jiffies,timeout))
1858 isdn_tty_shutdown(info);
1859 if (tty->driver.flush_buffer)
1860 tty->driver.flush_buffer(tty);
1861 tty_ldisc_flush(tty);
1865 if (info->blocked_open) {
1866 set_current_state(TASK_INTERRUPTIBLE);
1867 schedule_timeout(50);
1868 wake_up_interruptible(&info->open_wait);
1870 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE |
1871 ISDN_ASYNC_CLOSING);
1872 wake_up_interruptible(&info->close_wait);
1873 restore_flags(flags);
1874 #ifdef ISDN_DEBUG_MODEM_OPEN
1875 printk(KERN_DEBUG "isdn_tty_close normal exit\n");
1880 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1883 isdn_tty_hangup(struct tty_struct *tty)
1885 modem_info *info = (modem_info *) tty->driver_data;
1887 if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_hangup"))
1889 isdn_tty_shutdown(info);
1891 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE);
1893 wake_up_interruptible(&info->open_wait);
1896 /* This routine initializes all emulator-data.
1899 isdn_tty_reset_profile(atemu * m)
1912 m->profile[11] = 70;
1913 m->profile[12] = 0x45;
1915 m->profile[14] = ISDN_PROTO_L2_X75I;
1916 m->profile[15] = ISDN_PROTO_L3_TRANS;
1917 m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16;
1918 m->profile[17] = ISDN_MODEM_WINSIZE;
1927 #ifdef CONFIG_ISDN_AUDIO
1929 isdn_tty_modem_reset_vpar(atemu * m)
1931 m->vpar[0] = 2; /* Voice-device (2 = phone line) */
1932 m->vpar[1] = 0; /* Silence detection level (0 = none ) */
1933 m->vpar[2] = 70; /* Silence interval (7 sec. ) */
1934 m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1935 m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */
1936 m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1940 #ifdef CONFIG_ISDN_TTY_FAX
1942 isdn_tty_modem_reset_faxpar(modem_info * info)
1944 T30_s *f = info->fax;
1947 f->phase = ISDN_FAX_PHASE_IDLE;
1949 f->resolution = 1; /* fine */
1950 f->rate = 5; /* 14400 bit/s */
1957 memset(&f->id[0], 32, FAXIDLEN - 1);
1958 f->id[FAXIDLEN - 1] = 0;
1969 memset(&f->pollid[0], 32, FAXIDLEN - 1);
1970 f->pollid[FAXIDLEN - 1] = 0;
1975 isdn_tty_modem_reset_regs(modem_info * info, int force)
1977 atemu *m = &info->emu;
1978 if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {
1979 memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);
1980 memcpy(m->msn, m->pmsn, ISDN_MSNLEN);
1981 memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);
1982 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
1984 #ifdef CONFIG_ISDN_AUDIO
1985 isdn_tty_modem_reset_vpar(m);
1987 #ifdef CONFIG_ISDN_TTY_FAX
1988 isdn_tty_modem_reset_faxpar(info);
1994 modem_write_profile(atemu * m)
1996 memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG);
1997 memcpy(m->pmsn, m->msn, ISDN_MSNLEN);
1998 memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN);
2000 send_sig(SIGIO, dev->profd, 1);
2004 isdn_tty_modem_init(void)
2011 memset(&m->tty_modem, 0, sizeof(struct tty_driver));
2012 m->tty_modem.magic = TTY_DRIVER_MAGIC;
2013 m->tty_modem.name = isdn_ttyname_ttyI;
2014 m->tty_modem.major = ISDN_TTY_MAJOR;
2015 m->tty_modem.minor_start = 0;
2016 m->tty_modem.num = ISDN_MAX_CHANNELS;
2017 m->tty_modem.type = TTY_DRIVER_TYPE_SERIAL;
2018 m->tty_modem.subtype = ISDN_SERIAL_TYPE_NORMAL;
2019 m->tty_modem.init_termios = tty_std_termios;
2020 m->tty_modem.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2021 m->tty_modem.flags = TTY_DRIVER_REAL_RAW;
2022 m->tty_modem.refcount = &m->refcount;
2023 m->tty_modem.table = m->modem_table;
2024 m->tty_modem.termios = m->modem_termios;
2025 m->tty_modem.termios_locked = m->modem_termios_locked;
2026 m->tty_modem.open = isdn_tty_open;
2027 m->tty_modem.close = isdn_tty_close;
2028 m->tty_modem.write = isdn_tty_write;
2029 m->tty_modem.put_char = NULL;
2030 m->tty_modem.flush_chars = isdn_tty_flush_chars;
2031 m->tty_modem.write_room = isdn_tty_write_room;
2032 m->tty_modem.chars_in_buffer = isdn_tty_chars_in_buffer;
2033 m->tty_modem.flush_buffer = isdn_tty_flush_buffer;
2034 m->tty_modem.ioctl = isdn_tty_ioctl;
2035 m->tty_modem.throttle = isdn_tty_throttle;
2036 m->tty_modem.unthrottle = isdn_tty_unthrottle;
2037 m->tty_modem.set_termios = isdn_tty_set_termios;
2038 m->tty_modem.stop = NULL;
2039 m->tty_modem.start = NULL;
2040 m->tty_modem.hangup = isdn_tty_hangup;
2041 m->tty_modem.driver_name = "isdn_tty";
2043 * The callout device is just like normal device except for
2044 * major number and the subtype code.
2046 m->cua_modem = m->tty_modem;
2047 m->cua_modem.name = isdn_ttyname_cui;
2048 m->cua_modem.major = ISDN_TTYAUX_MAJOR;
2049 m->tty_modem.minor_start = 0;
2050 m->cua_modem.subtype = ISDN_SERIAL_TYPE_CALLOUT;
2052 if (tty_register_driver(&m->tty_modem)) {
2053 printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n");
2056 if (tty_register_driver(&m->cua_modem)) {
2057 printk(KERN_WARNING "isdn_tty: Couldn't register modem-callout-device\n");
2060 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2062 #ifdef CONFIG_ISDN_TTY_FAX
2063 if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) {
2064 printk(KERN_ERR "Could not allocate fax t30-buffer\n");
2068 init_MUTEX(&info->write_sem);
2069 sprintf(info->last_cause, "0000");
2070 sprintf(info->last_num, "none");
2072 info->last_lhup = 1;
2075 isdn_tty_reset_profile(&info->emu);
2076 isdn_tty_modem_reset_regs(info, 1);
2077 info->magic = ISDN_ASYNC_MAGIC;
2082 info->blocked_open = 0;
2083 info->callout_termios = m->cua_modem.init_termios;
2084 info->normal_termios = m->tty_modem.init_termios;
2085 init_waitqueue_head(&info->open_wait);
2086 init_waitqueue_head(&info->close_wait);
2087 info->isdn_driver = -1;
2088 info->isdn_channel = -1;
2089 info->drv_index = -1;
2090 info->xmit_size = ISDN_SERIAL_XMIT_SIZE;
2091 skb_queue_head_init(&info->xmit_queue);
2092 #ifdef CONFIG_ISDN_AUDIO
2093 skb_queue_head_init(&info->dtmf_queue);
2095 if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) {
2096 printk(KERN_ERR "Could not allocate modem xmit-buffer\n");
2099 /* Make room for T.70 header */
2100 info->xmit_buf += 4;
2107 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
2108 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
2109 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
2113 isdn_tty_match_icall(char *cid, atemu *emu, int di)
2115 #ifdef ISDN_DEBUG_MODEM_ICALL
2116 printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
2117 emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di),
2118 emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]);
2120 if (strlen(emu->lmsn)) {
2121 char *p = emu->lmsn;
2127 if ((q = strchr(p, ';')))
2129 if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret)
2131 #ifdef ISDN_DEBUG_MODEM_ICALL
2132 printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2133 p, isdn_map_eaz2msn(emu->msn, di), tmp);
2148 tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di));
2149 #ifdef ISDN_DEBUG_MODEM_ICALL
2150 printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n",
2151 isdn_map_eaz2msn(emu->msn, di), tmp);
2158 * An incoming call-request has arrived.
2159 * Search the tty-devices for an appropriate device and bind
2160 * it to the ISDN-Channel.
2163 * 0 = No matching device found.
2164 * 1 = A matching device found.
2165 * 3 = No match found, but eventually would match, if
2169 isdn_tty_find_icall(int di, int ch, setup_parm *setup)
2180 if (!setup->phone[0]) {
2182 printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n");
2185 si1 = (int) setup->si1;
2186 si2 = (int) setup->si2;
2187 if (!setup->eazmsn[0]) {
2188 printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n");
2191 eaz = setup->eazmsn;
2192 #ifdef ISDN_DEBUG_MODEM_ICALL
2193 printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2);
2198 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2199 modem_info *info = &dev->mdm.info[i];
2201 if (info->count == 0)
2203 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
2204 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
2205 idx = isdn_dc2minor(di, ch);
2206 #ifdef ISDN_DEBUG_MODEM_ICALL
2207 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret);
2208 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx,
2209 info->flags, info->isdn_driver, info->isdn_channel,
2213 #ifndef FIX_FILE_TRANSFER
2214 (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) &&
2216 (info->isdn_driver == -1) &&
2217 (info->isdn_channel == -1) &&
2218 (USG_NONE(dev->usage[idx]))) {
2221 if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret)
2223 if (!matchret) { /* EAZ is matching */
2224 info->isdn_driver = di;
2225 info->isdn_channel = ch;
2226 info->drv_index = idx;
2227 dev->m_idx[idx] = info->line;
2228 dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
2229 dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]);
2230 strcpy(dev->num[idx], nr);
2231 strcpy(info->emu.cpn, eaz);
2232 info->emu.mdmreg[REG_SI1I] = si2bit[si1];
2233 info->emu.mdmreg[REG_PLAN] = setup->plan;
2234 info->emu.mdmreg[REG_SCREEN] = setup->screen;
2236 restore_flags(flags);
2237 printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr,
2239 info->msr |= UART_MSR_RI;
2240 isdn_tty_modem_result(RESULT_RING, info);
2241 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1);
2247 restore_flags(flags);
2248 printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz,
2249 ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2))? "rejected" : "ignored");
2250 return (wret == 2)?3:0;
2253 #define TTY_IS_ACTIVE(info) \
2254 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2257 isdn_tty_stat_callback(int i, isdn_ctrl *c)
2265 if ((mi = dev->m_idx[i]) >= 0) {
2266 info = &dev->mdm.info[mi];
2267 switch (c->command) {
2268 case ISDN_STAT_CINF:
2269 printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num);
2270 info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10);
2271 if (e == (char *)c->parm.num)
2272 info->emu.charge = 0;
2275 case ISDN_STAT_BSENT:
2276 #ifdef ISDN_TTY_STAT_DEBUG
2277 printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line);
2279 if ((info->isdn_driver == c->driver) &&
2280 (info->isdn_channel == c->arg)) {
2281 info->msr |= UART_MSR_CTS;
2282 if (info->send_outstanding)
2283 if (!(--info->send_outstanding))
2284 info->lsr |= UART_LSR_TEMT;
2285 isdn_tty_tint(info);
2289 case ISDN_STAT_CAUSE:
2290 #ifdef ISDN_TTY_STAT_DEBUG
2291 printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line);
2293 /* Signal cause to tty-device */
2294 strncpy(info->last_cause, c->parm.num, 5);
2296 case ISDN_STAT_DISPLAY:
2297 #ifdef ISDN_TTY_STAT_DEBUG
2298 printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line);
2300 /* Signal display to tty-device */
2301 if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) &&
2302 !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) {
2303 isdn_tty_at_cout("\r\n", info);
2304 isdn_tty_at_cout("DISPLAY: ", info);
2305 isdn_tty_at_cout(c->parm.display, info);
2306 isdn_tty_at_cout("\r\n", info);
2309 case ISDN_STAT_DCONN:
2310 #ifdef ISDN_TTY_STAT_DEBUG
2311 printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line);
2313 if (TTY_IS_ACTIVE(info)) {
2314 if (info->dialing == 1) {
2320 case ISDN_STAT_DHUP:
2321 #ifdef ISDN_TTY_STAT_DEBUG
2322 printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
2324 if (TTY_IS_ACTIVE(info)) {
2325 if (info->dialing == 1)
2326 isdn_tty_modem_result(RESULT_BUSY, info);
2327 if (info->dialing > 1)
2328 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
2330 #ifdef ISDN_DEBUG_MODEM_HUP
2331 printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n");
2333 isdn_tty_modem_hup(info, 0);
2337 case ISDN_STAT_BCONN:
2338 #ifdef ISDN_TTY_STAT_DEBUG
2339 printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line);
2341 /* Wake up any processes waiting
2342 * for incoming call of this device when
2343 * DCD follow the state of incoming carrier
2345 if (info->blocked_open &&
2346 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) {
2347 wake_up_interruptible(&info->open_wait);
2350 /* Schedule CONNECT-Message to any tty
2351 * waiting for it and
2352 * set DCD-bit of its modem-status.
2354 if (TTY_IS_ACTIVE(info) ||
2355 (info->blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
2356 info->msr |= UART_MSR_DCD;
2357 info->emu.charge = 0;
2358 if (info->dialing & 0xf)
2364 if (USG_MODEM(dev->usage[i])) {
2365 if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) {
2366 strcpy(info->emu.connmsg, c->parm.num);
2367 isdn_tty_modem_result(RESULT_CONNECT, info);
2369 isdn_tty_modem_result(RESULT_CONNECT64000, info);
2371 if (USG_VOICE(dev->usage[i]))
2372 isdn_tty_modem_result(RESULT_VCON, info);
2376 case ISDN_STAT_BHUP:
2377 #ifdef ISDN_TTY_STAT_DEBUG
2378 printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
2380 if (TTY_IS_ACTIVE(info)) {
2381 #ifdef ISDN_DEBUG_MODEM_HUP
2382 printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
2384 isdn_tty_modem_hup(info, 0);
2388 case ISDN_STAT_NODCH:
2389 #ifdef ISDN_TTY_STAT_DEBUG
2390 printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line);
2392 if (TTY_IS_ACTIVE(info)) {
2393 if (info->dialing) {
2397 sprintf(info->last_cause, "0000");
2398 isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
2400 isdn_tty_modem_hup(info, 0);
2404 case ISDN_STAT_UNLOAD:
2405 #ifdef ISDN_TTY_STAT_DEBUG
2406 printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line);
2408 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2409 info = &dev->mdm.info[i];
2410 if (info->isdn_driver == c->driver) {
2412 isdn_tty_modem_hup(info, 1);
2416 #ifdef CONFIG_ISDN_TTY_FAX
2417 case ISDN_STAT_FAXIND:
2418 if (TTY_IS_ACTIVE(info)) {
2419 isdn_tty_fax_command(info, c);
2423 #ifdef CONFIG_ISDN_AUDIO
2424 case ISDN_STAT_AUDIO:
2425 if (TTY_IS_ACTIVE(info)) {
2426 switch(c->parm.num[0]) {
2427 case ISDN_AUDIO_DTMF:
2428 if (info->vonline) {
2429 isdn_audio_put_dle_code(info,
2442 /*********************************************************************
2443 Modem-Emulator-Routines
2444 *********************************************************************/
2446 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2449 * Put a message from the AT-emulator into receive-buffer of tty,
2450 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2453 isdn_tty_at_cout(char *msg, modem_info * info)
2455 struct tty_struct *tty;
2456 atemu *m = &info->emu;
2460 struct sk_buff *skb = 0;
2464 printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
2470 if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) {
2471 restore_flags(flags);
2475 /* use queue instead of direct flip, if online and */
2476 /* data is in queue or flip buffer is full */
2477 if ((info->online) && (((tty->flip.count + strlen(msg)) >= TTY_FLIPBUF_SIZE) ||
2478 (!skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel])))) {
2479 skb = alloc_skb(strlen(msg)
2480 #ifdef CONFIG_ISDN_AUDIO
2481 + sizeof(isdn_audio_skb)
2485 restore_flags(flags);
2488 #ifdef CONFIG_ISDN_AUDIO
2489 skb_reserve(skb, sizeof(isdn_audio_skb));
2491 sp = skb_put(skb, strlen(msg));
2492 #ifdef CONFIG_ISDN_AUDIO
2493 ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
2494 ISDN_AUDIO_SKB_LOCK(skb) = 0;
2498 for (p = msg; *p; p++) {
2501 c = m->mdmreg[REG_CR];
2504 c = m->mdmreg[REG_LF];
2507 c = m->mdmreg[REG_BS];
2515 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
2517 tty_insert_flip_char(tty, c, 0);
2521 __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb);
2522 dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len;
2523 restore_flags(flags);
2524 /* Schedule dequeuing */
2525 if ((dev->modempoll) && (info->rcvsched))
2526 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
2529 restore_flags(flags);
2530 queue_task(&tty->flip.tqueue, &tq_timer);
2535 * Perform ATH Hangup
2538 isdn_tty_on_hook(modem_info * info)
2540 if (info->isdn_channel >= 0) {
2541 #ifdef ISDN_DEBUG_MODEM_HUP
2542 printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n");
2544 isdn_tty_modem_hup(info, 1);
2549 isdn_tty_off_hook(void)
2551 printk(KERN_DEBUG "isdn_tty_off_hook\n");
2554 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2555 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2558 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2559 * isdn_tty_modem_escape() if sequence found.
2562 * p pointer to databuffer
2563 * plus escape-character
2564 * count length of buffer
2565 * pluscount count of valid escape-characters so far
2566 * lastplus timestamp of last character
2569 isdn_tty_check_esc(const u_char * p, u_char plus, int count, int *pluscount,
2570 int *lastplus, int from_user)
2582 copy_from_user(cbuf, p, count);
2586 if (*(p++) == plus) {
2587 if ((*pluscount)++) {
2588 /* Time since last '+' > 0.5 sec. ? */
2589 if (time_after(jiffies, *lastplus + PLUSWAIT1))
2592 /* Time since last non-'+' < 1.5 sec. ? */
2593 if (time_before(jiffies, *lastplus + PLUSWAIT2))
2596 if ((*pluscount == 3) && (count == 1))
2597 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1);
2602 *lastplus = jiffies;
2608 * Return result of AT-emulator to tty-receive-buffer, depending on
2609 * modem-register 12, bit 0 and 1.
2610 * For CONNECT-messages also switch to online-mode.
2611 * For RING-message handle auto-ATA if register 0 != 0
2615 isdn_tty_modem_result(int code, modem_info * info)
2617 atemu *m = &info->emu;
2618 static char *msg[] =
2619 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2620 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2621 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2623 char s[ISDN_MSNLEN+10];
2627 m->mdmreg[REG_RINGCNT]++;
2628 if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA])
2629 /* Automatically accept incoming call */
2630 isdn_tty_cmd_ATA(info);
2632 case RESULT_NO_CARRIER:
2633 #ifdef ISDN_DEBUG_MODEM_HUP
2634 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n",
2635 (info->flags & ISDN_ASYNC_CLOSING),
2640 m->mdmreg[REG_RINGCNT] = 0;
2641 del_timer(&info->nc_timer);
2643 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) {
2644 restore_flags(flags);
2647 restore_flags(flags);
2648 #ifdef CONFIG_ISDN_AUDIO
2649 if (info->vonline & 1) {
2650 #ifdef ISDN_DEBUG_MODEM_VOICE
2651 printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n",
2654 /* voice-recording, add DLE-ETX */
2655 isdn_tty_at_cout("\020\003", info);
2657 if (info->vonline & 2) {
2658 #ifdef ISDN_DEBUG_MODEM_VOICE
2659 printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n",
2662 /* voice-playing, add DLE-DC4 */
2663 isdn_tty_at_cout("\020\024", info);
2667 case RESULT_CONNECT:
2668 case RESULT_CONNECT64000:
2669 sprintf(info->last_cause, "0000");
2674 #ifdef ISDN_DEBUG_MODEM_VOICE
2675 printk(KERN_DEBUG "res3: send VCON on ttyI%d\n",
2678 sprintf(info->last_cause, "0000");
2682 } /* switch(code) */
2684 if (m->mdmreg[REG_RESP] & BIT_RESP) {
2686 if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) {
2687 /* Show numeric results only */
2688 sprintf(s, "\r\n%d\r\n", code);
2689 isdn_tty_at_cout(s, info);
2691 if (code == RESULT_RING) {
2692 /* return if "show RUNG" and ringcounter>1 */
2693 if ((m->mdmreg[REG_RUNG] & BIT_RUNG) &&
2694 (m->mdmreg[REG_RINGCNT] > 1))
2696 /* print CID, _before_ _every_ ring */
2697 if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) {
2698 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info);
2699 isdn_tty_at_cout(dev->num[info->drv_index], info);
2700 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2701 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2702 isdn_tty_at_cout(info->emu.cpn, info);
2706 isdn_tty_at_cout("\r\n", info);
2707 isdn_tty_at_cout(msg[code], info);
2709 case RESULT_CONNECT:
2710 switch (m->mdmreg[REG_L2PROT]) {
2711 case ISDN_PROTO_L2_MODEM:
2712 isdn_tty_at_cout(" ", info);
2713 isdn_tty_at_cout(m->connmsg, info);
2718 /* Append CPN, if enabled */
2719 if ((m->mdmreg[REG_CPN] & BIT_CPN)) {
2720 sprintf(s, "/%s", m->cpn);
2721 isdn_tty_at_cout(s, info);
2723 /* Print CID only once, _after_ 1st RING */
2724 if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) &&
2725 (m->mdmreg[REG_RINGCNT] == 1)) {
2726 isdn_tty_at_cout("\r\n", info);
2727 isdn_tty_at_cout("CALLER NUMBER: ", info);
2728 isdn_tty_at_cout(dev->num[info->drv_index], info);
2729 if (m->mdmreg[REG_CDN] & BIT_CDN) {
2730 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
2731 isdn_tty_at_cout(info->emu.cpn, info);
2735 case RESULT_NO_CARRIER:
2736 case RESULT_NO_DIALTONE:
2738 case RESULT_NO_ANSWER:
2739 m->mdmreg[REG_RINGCNT] = 0;
2740 /* Append Cause-Message if enabled */
2741 if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) {
2742 sprintf(s, "/%s", info->last_cause);
2743 isdn_tty_at_cout(s, info);
2746 case RESULT_CONNECT64000:
2747 /* Append Protocol to CONNECT message */
2748 switch (m->mdmreg[REG_L2PROT]) {
2749 case ISDN_PROTO_L2_X75I:
2750 case ISDN_PROTO_L2_X75UI:
2751 case ISDN_PROTO_L2_X75BUI:
2752 isdn_tty_at_cout("/X.75", info);
2754 case ISDN_PROTO_L2_HDLC:
2755 isdn_tty_at_cout("/HDLC", info);
2757 case ISDN_PROTO_L2_V11096:
2758 isdn_tty_at_cout("/V110/9600", info);
2760 case ISDN_PROTO_L2_V11019:
2761 isdn_tty_at_cout("/V110/19200", info);
2763 case ISDN_PROTO_L2_V11038:
2764 isdn_tty_at_cout("/V110/38400", info);
2767 if (m->mdmreg[REG_T70] & BIT_T70) {
2768 isdn_tty_at_cout("/T.70", info);
2769 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2770 isdn_tty_at_cout("+", info);
2774 isdn_tty_at_cout("\r\n", info);
2777 if (code == RESULT_NO_CARRIER) {
2780 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) {
2781 restore_flags(flags);
2784 tty_ldisc_flush(info->tty);
2785 if ((info->flags & ISDN_ASYNC_CHECK_CD) &&
2786 (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
2787 (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) {
2788 tty_hangup(info->tty);
2790 restore_flags(flags);
2796 * Display a modem-register-value.
2799 isdn_tty_show_profile(int ridx, modem_info * info)
2803 sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]);
2804 isdn_tty_at_cout(v, info);
2808 * Get MSN-string from char-pointer, set pointer to end of number
2811 isdn_tty_get_msnstr(char *n, char **p)
2813 int limit = ISDN_MSNLEN - 1;
2815 while (((*p[0] >= '0' && *p[0] <= '9') ||
2816 /* Why a comma ??? */
2817 (*p[0] == ',') || (*p[0] == ':')) &&
2824 * Get phone-number from modem-commandbuffer
2827 isdn_tty_getdial(char *p, char *q,int cnt)
2830 int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
2833 while (strchr(" 0123456789,#.*WPTS-", *p) && *p && --cnt>0) {
2834 if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
2835 (*p == '*') || (*p == '#')) {
2847 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2848 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2851 isdn_tty_report(modem_info * info)
2853 atemu *m = &info->emu;
2856 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info);
2857 sprintf(s, " Remote Number: %s\r\n", info->last_num);
2858 isdn_tty_at_cout(s, info);
2859 sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming");
2860 isdn_tty_at_cout(s, info);
2861 isdn_tty_at_cout(" Layer-2 Protocol: ", info);
2862 switch (info->last_l2) {
2863 case ISDN_PROTO_L2_X75I:
2864 isdn_tty_at_cout("X.75i", info);
2866 case ISDN_PROTO_L2_X75UI:
2867 isdn_tty_at_cout("X.75ui", info);
2869 case ISDN_PROTO_L2_X75BUI:
2870 isdn_tty_at_cout("X.75bui", info);
2872 case ISDN_PROTO_L2_HDLC:
2873 isdn_tty_at_cout("HDLC", info);
2875 case ISDN_PROTO_L2_V11096:
2876 isdn_tty_at_cout("V.110 9600 Baud", info);
2878 case ISDN_PROTO_L2_V11019:
2879 isdn_tty_at_cout("V.110 19200 Baud", info);
2881 case ISDN_PROTO_L2_V11038:
2882 isdn_tty_at_cout("V.110 38400 Baud", info);
2884 case ISDN_PROTO_L2_TRANS:
2885 isdn_tty_at_cout("transparent", info);
2887 case ISDN_PROTO_L2_MODEM:
2888 isdn_tty_at_cout("modem", info);
2890 case ISDN_PROTO_L2_FAX:
2891 isdn_tty_at_cout("fax", info);
2894 isdn_tty_at_cout("unknown", info);
2897 if (m->mdmreg[REG_T70] & BIT_T70) {
2898 isdn_tty_at_cout("/T.70", info);
2899 if (m->mdmreg[REG_T70] & BIT_T70_EXT)
2900 isdn_tty_at_cout("+", info);
2902 isdn_tty_at_cout("\r\n", info);
2903 isdn_tty_at_cout(" Service: ", info);
2904 switch (info->last_si) {
2906 isdn_tty_at_cout("audio\r\n", info);
2909 isdn_tty_at_cout("btx\r\n", info);
2912 isdn_tty_at_cout("data\r\n", info);
2915 sprintf(s, "%d\r\n", info->last_si);
2916 isdn_tty_at_cout(s, info);
2919 sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote");
2920 isdn_tty_at_cout(s, info);
2921 sprintf(s, " Last cause: %s\r\n", info->last_cause);
2922 isdn_tty_at_cout(s, info);
2926 * Parse AT&.. commands.
2929 isdn_tty_cmd_ATand(char **p, modem_info * info)
2931 atemu *m = &info->emu;
2935 #define MAXRB (sizeof(rb) - 1)
2939 /* &B - Set Buffersize */
2942 if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX))
2944 #ifdef CONFIG_ISDN_AUDIO
2945 if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF))
2948 m->mdmreg[REG_PSIZE] = i / 16;
2949 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
2950 switch (m->mdmreg[REG_L2PROT]) {
2951 case ISDN_PROTO_L2_V11096:
2952 case ISDN_PROTO_L2_V11019:
2953 case ISDN_PROTO_L2_V11038:
2954 info->xmit_size /= 10;
2958 /* &C - DCD Status */
2960 switch (isdn_getnum(p)) {
2962 m->mdmreg[REG_DCD] &= ~BIT_DCD;
2965 m->mdmreg[REG_DCD] |= BIT_DCD;
2972 /* &D - Set DTR-Low-behavior */
2974 switch (isdn_getnum(p)) {
2976 m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP;
2977 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2980 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2981 m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
2984 m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
2985 m->mdmreg[REG_DTRR] |= BIT_DTRR;
2992 /* &E -Set EAZ/MSN */
2994 isdn_tty_get_msnstr(m->msn, p);
2997 /* &F -Set Factory-Defaults */
2999 if (info->msr & UART_MSR_DCD)
3001 isdn_tty_reset_profile(m);
3002 isdn_tty_modem_reset_regs(info, 1);
3004 #ifdef DUMMY_HAYES_AT
3006 /* only for be compilant with common scripts */
3007 /* &K Flowcontrol - no function */
3013 /* &L -Set Numbers to listen on */
3016 while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) &&
3018 m->lmsn[i++] = *p[0]++;
3022 /* &R - Set V.110 bitrate adaption */
3027 /* Switch off V.110, back to X.75 */
3028 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3029 m->mdmreg[REG_SI2] = 0;
3030 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
3033 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096;
3034 m->mdmreg[REG_SI2] = 197;
3035 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
3038 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019;
3039 m->mdmreg[REG_SI2] = 199;
3040 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
3043 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038;
3044 m->mdmreg[REG_SI2] = 198; /* no existing standard for this */
3045 info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
3050 /* Switch off T.70 */
3051 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
3053 m->mdmreg[REG_SI1] |= 4;
3056 /* &S - Set Windowsize */
3059 if ((i > 0) && (i < 9))
3060 m->mdmreg[REG_WSIZE] = i;
3065 /* &V - Show registers */
3067 isdn_tty_at_cout("\r\n", info);
3068 for (i = 0; i < ISDN_MODEM_NUMREG; i++) {
3069 sprintf(rb, "S%02d=%03d%s", i,
3070 m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n");
3071 isdn_tty_at_cout(rb, info);
3073 sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n",
3074 strlen(m->msn) ? m->msn : "None");
3075 isdn_tty_at_cout(rb, info);
3076 if (strlen(m->lmsn)) {
3077 isdn_tty_at_cout("\r\nListen: ", info);
3078 isdn_tty_at_cout(m->lmsn, info);
3079 isdn_tty_at_cout("\r\n", info);
3083 /* &W - Write Profile */
3088 modem_write_profile(m);
3095 /* &X - Switch to BTX-Mode and T.70 */
3097 switch (isdn_getnum(p)) {
3099 m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
3100 info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
3103 m->mdmreg[REG_T70] |= BIT_T70;
3104 m->mdmreg[REG_T70] &= ~BIT_T70_EXT;
3105 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3106 info->xmit_size = 112;
3107 m->mdmreg[REG_SI1] = 4;
3108 m->mdmreg[REG_SI2] = 0;
3111 m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT);
3112 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3113 info->xmit_size = 112;
3114 m->mdmreg[REG_SI1] = 4;
3115 m->mdmreg[REG_SI2] = 0;
3128 isdn_tty_check_ats(int mreg, int mval, modem_info * info, atemu * m)
3130 /* Some plausibility checks */
3133 if (mval > ISDN_PROTO_L2_MAX)
3137 if ((mval * 16) > ISDN_SERIAL_XMIT_MAX)
3139 #ifdef CONFIG_ISDN_AUDIO
3140 if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX))
3143 info->xmit_size = mval * 16;
3144 switch (m->mdmreg[REG_L2PROT]) {
3145 case ISDN_PROTO_L2_V11096:
3146 case ISDN_PROTO_L2_V11019:
3147 case ISDN_PROTO_L2_V11038:
3148 info->xmit_size /= 10;
3154 /* readonly registers */
3161 * Perform ATS command
3164 isdn_tty_cmd_ATS(char **p, modem_info * info)
3166 atemu *m = &info->emu;
3172 mreg = isdn_getnum(p);
3173 if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG)
3178 mval = isdn_getnum(p);
3179 if (mval < 0 || mval > 255)
3181 if (isdn_tty_check_ats(mreg, mval, info, m))
3183 m->mdmreg[mreg] = mval;
3186 /* Set/Clear a single bit */
3188 bitpos = isdn_getnum(p);
3189 if ((bitpos < 0) || (bitpos > 7))
3194 bval = isdn_getnum(p);
3195 if (bval < 0 || bval > 1)
3198 mval = m->mdmreg[mreg] | (1 << bitpos);
3200 mval = m->mdmreg[mreg] & ~(1 << bitpos);
3201 if (isdn_tty_check_ats(mreg, mval, info, m))
3203 m->mdmreg[mreg] = mval;
3207 isdn_tty_at_cout("\r\n", info);
3208 isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0",
3217 isdn_tty_show_profile(mreg, info);
3227 * Perform ATA command
3230 isdn_tty_cmd_ATA(modem_info * info)
3232 atemu *m = &info->emu;
3236 if (info->msr & UART_MSR_RI) {
3237 /* Accept incoming call */
3239 strcpy(info->last_num, dev->num[info->drv_index]);
3240 m->mdmreg[REG_RINGCNT] = 0;
3241 info->msr &= ~UART_MSR_RI;
3242 l2 = m->mdmreg[REG_L2PROT];
3243 #ifdef CONFIG_ISDN_AUDIO
3244 /* If more than one bit set in reg18, autoselect Layer2 */
3245 if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) {
3246 if (m->mdmreg[REG_SI1I] == 1) {
3247 if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX))
3248 l2 = ISDN_PROTO_L2_TRANS;
3250 l2 = ISDN_PROTO_L2_X75I;
3253 cmd.driver = info->isdn_driver;
3254 cmd.command = ISDN_CMD_SETL2;
3255 cmd.arg = info->isdn_channel + (l2 << 8);
3258 cmd.driver = info->isdn_driver;
3259 cmd.command = ISDN_CMD_SETL3;
3260 cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
3261 #ifdef CONFIG_ISDN_TTY_FAX
3262 if (l2 == ISDN_PROTO_L2_FAX) {
3263 cmd.parm.fax = info->fax;
3264 info->fax->direction = ISDN_TTY_FAX_CONN_IN;
3268 cmd.driver = info->isdn_driver;
3269 cmd.arg = info->isdn_channel;
3270 cmd.command = ISDN_CMD_ACCEPTD;
3272 info->emu.carrierwait = 0;
3274 isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
3276 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3279 #ifdef CONFIG_ISDN_AUDIO
3281 * Parse AT+F.. commands
3284 isdn_tty_cmd_PLUSF(char **p, modem_info * info)
3286 atemu *m = &info->emu;
3289 if (!strncmp(p[0], "CLASS", 5)) {
3294 sprintf(rs, "\r\n%d",
3295 (m->mdmreg[REG_SI1] & 1) ? 8 : 0);
3296 #ifdef CONFIG_ISDN_TTY_FAX
3297 if (TTY_IS_FCLASS2(info))
3298 sprintf(rs, "\r\n2");
3299 else if (TTY_IS_FCLASS1(info))
3300 sprintf(rs, "\r\n1");
3302 isdn_tty_at_cout(rs, info);
3309 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3310 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3311 m->mdmreg[REG_SI1] = 4;
3313 m->mdmreg[REG_PSIZE] * 16;
3315 #ifdef CONFIG_ISDN_TTY_FAX
3318 if (!(dev->global_features &
3319 ISDN_FEATURE_L3_FCLASS1))
3321 m->mdmreg[REG_SI1] = 1;
3322 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3323 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1;
3325 m->mdmreg[REG_PSIZE] * 16;
3329 if (!(dev->global_features &
3330 ISDN_FEATURE_L3_FCLASS2))
3332 m->mdmreg[REG_SI1] = 1;
3333 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
3334 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2;
3336 m->mdmreg[REG_PSIZE] * 16;
3341 /* L2 will change on dialout with si=1 */
3342 m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
3343 m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
3344 m->mdmreg[REG_SI1] = 5;
3345 info->xmit_size = VBUF;
3349 strcpy(rs, "\r\n0,");
3350 #ifdef CONFIG_ISDN_TTY_FAX
3351 if (dev->global_features &
3352 ISDN_FEATURE_L3_FCLASS1)
3354 if (dev->global_features &
3355 ISDN_FEATURE_L3_FCLASS2)
3359 isdn_tty_at_cout(rs, info);
3370 #ifdef CONFIG_ISDN_TTY_FAX
3371 return (isdn_tty_cmd_PLUSF_FAX(p, info));
3378 * Parse AT+V.. commands
3381 isdn_tty_cmd_PLUSV(char **p, modem_info * info)
3383 atemu *m = &info->emu;
3385 static char *vcmd[] =
3386 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL};
3394 if (!strncmp(vcmd[i], p[0], 2)) {
3402 /* AT+VNH - Auto hangup feature */
3406 isdn_tty_at_cout("\r\n1", info);
3416 isdn_tty_at_cout("\r\n1", info);
3427 /* AT+VIP - Reset all voice parameters */
3428 isdn_tty_modem_reset_vpar(m);
3431 /* AT+VLS - Select device, accept incoming call */
3435 sprintf(rs, "\r\n%d", m->vpar[0]);
3436 isdn_tty_at_cout(rs, info);
3451 isdn_tty_at_cout("\r\n0,2", info);
3462 /* AT+VRX - Start recording */
3465 if (info->online != 1) {
3466 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3469 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3470 if (!info->dtmf_state) {
3471 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3474 info->silence_state = isdn_audio_silence_init(info->silence_state);
3475 if (!info->silence_state) {
3476 printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n");
3479 if (m->vpar[3] < 5) {
3480 info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]);
3481 if (!info->adpcmr) {
3482 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3486 #ifdef ISDN_DEBUG_AT
3487 printk(KERN_DEBUG "AT: +VRX\n");
3490 isdn_tty_modem_result(RESULT_CONNECT, info);
3494 /* AT+VSD - Silence detection */
3498 sprintf(rs, "\r\n<%d>,<%d>",
3501 isdn_tty_at_cout(rs, info);
3505 if ((*p[0]>='0') && (*p[0]<='9')) {
3506 par1 = isdn_getnum(p);
3507 if ((par1 < 0) || (par1 > 31))
3512 par2 = isdn_getnum(p);
3513 if ((par2 < 0) || (par2 > 255))
3521 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3532 /* AT+VSM - Select compression */
3536 sprintf(rs, "\r\n<%d>,<%d><8000>",
3539 isdn_tty_at_cout(rs, info);
3549 par1 = isdn_getnum(p);
3550 if ((par1 < 2) || (par1 > 6))
3556 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3558 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3560 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3562 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3564 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3576 /* AT+VTX - Start sending */
3579 if (info->online != 1) {
3580 isdn_tty_modem_result(RESULT_NO_ANSWER, info);
3583 info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
3584 if (!info->dtmf_state) {
3585 printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
3588 if (m->vpar[3] < 5) {
3589 info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]);
3590 if (!info->adpcms) {
3591 printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
3595 #ifdef ISDN_DEBUG_AT
3596 printk(KERN_DEBUG "AT: +VTX\n");
3600 isdn_tty_modem_result(RESULT_CONNECT, info);
3604 /* AT+VDD - DTMF detection */
3608 sprintf(rs, "\r\n<%d>,<%d>",
3611 isdn_tty_at_cout(rs, info);
3615 if ((*p[0]>='0') && (*p[0]<='9')) {
3616 if (info->online != 1)
3618 par1 = isdn_getnum(p);
3619 if ((par1 < 0) || (par1 > 15))
3624 par2 = isdn_getnum(p);
3625 if ((par2 < 0) || (par2 > 255))
3629 cmd.driver = info->isdn_driver;
3630 cmd.command = ISDN_CMD_AUDIO;
3631 cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8);
3632 cmd.parm.num[0] = par1;
3633 cmd.parm.num[1] = par2;
3639 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3654 #endif /* CONFIG_ISDN_AUDIO */
3657 * Parse and perform an AT-command-line.
3660 isdn_tty_parse_at(modem_info * info)
3662 atemu *m = &info->emu;
3666 #ifdef ISDN_DEBUG_AT
3667 printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd);
3669 for (p = &m->mdmcmd[2]; *p;) {
3675 /* A - Accept incoming call */
3677 isdn_tty_cmd_ATA(info);
3682 if (info->msr & UART_MSR_DCD)
3684 if (info->msr & UART_MSR_RI) {
3685 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3688 isdn_tty_getdial(++p, ds, sizeof ds);
3690 if (!strlen(m->msn))
3691 isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info);
3692 else if (strlen(ds))
3693 isdn_tty_dial(ds, info, m);
3698 /* E - Turn Echo on/off */
3700 switch (isdn_getnum(&p)) {
3702 m->mdmreg[REG_ECHO] &= ~BIT_ECHO;
3705 m->mdmreg[REG_ECHO] |= BIT_ECHO;
3712 /* H - On/Off-hook */
3717 isdn_tty_on_hook(info);
3721 isdn_tty_off_hook();
3724 isdn_tty_on_hook(info);
3729 /* I - Information */
3731 isdn_tty_at_cout("\r\nLinux ISDN", info);
3739 isdn_tty_report(info);
3743 sprintf(ds, "\r\n%d", info->emu.charge);
3744 isdn_tty_at_cout(ds, info);
3749 #ifdef DUMMY_HAYES_AT
3752 /* only for be compilant with common scripts */
3761 if (info->msr & UART_MSR_DCD)
3762 /* if B-Channel is up */
3763 isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT:RESULT_CONNECT64000, info);
3765 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3768 /* Q - Turn Emulator messages on/off */
3770 switch (isdn_getnum(&p)) {
3772 m->mdmreg[REG_RESP] |= BIT_RESP;
3775 m->mdmreg[REG_RESP] &= ~BIT_RESP;
3782 /* S - Set/Get Register */
3784 if (isdn_tty_cmd_ATS(&p, info))
3788 /* V - Numeric or ASCII Emulator-messages */
3790 switch (isdn_getnum(&p)) {
3792 m->mdmreg[REG_RESP] |= BIT_RESPNUM;
3795 m->mdmreg[REG_RESP] &= ~BIT_RESPNUM;
3802 /* Z - Load Registers from Profile */
3804 if (info->msr & UART_MSR_DCD) {
3806 isdn_tty_on_hook(info);
3808 isdn_tty_modem_reset_regs(info, 1);
3813 #ifdef CONFIG_ISDN_AUDIO
3816 if (isdn_tty_cmd_PLUSF(&p, info))
3820 if ((!(m->mdmreg[REG_SI1] & 1)) ||
3821 (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM))
3824 if (isdn_tty_cmd_PLUSV(&p, info))
3827 #endif /* CONFIG_ISDN_AUDIO */
3828 case 'S': /* SUSPEND */
3830 isdn_tty_get_msnstr(ds, &p);
3831 isdn_tty_suspend(ds, info, m);
3833 case 'R': /* RESUME */
3835 isdn_tty_get_msnstr(ds, &p);
3836 isdn_tty_resume(ds, info, m);
3838 case 'M': /* MESSAGE */
3840 isdn_tty_send_msg(info, m, p);
3848 if (isdn_tty_cmd_ATand(&p, info))
3855 #ifdef CONFIG_ISDN_AUDIO
3858 isdn_tty_modem_result(RESULT_OK, info);
3861 /* Need own toupper() because standard-toupper is not available
3864 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
3867 * Perform line-editing of AT-commands
3871 * count length of buffer
3872 * channel index to line (minor-device)
3873 * user flag: buffer is in userspace
3876 isdn_tty_edit_at(const char *p, int count, modem_info * info, int user)
3878 atemu *m = &info->emu;
3884 for (cnt = count; cnt > 0; p++, cnt--) {
3890 if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) {
3891 /* Separator (CR or LF) */
3892 m->mdmcmd[m->mdmcmdl] = 0;
3893 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3896 isdn_tty_at_cout(eb, info);
3898 if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2))))
3899 isdn_tty_parse_at(info);
3903 if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) {
3904 /* Backspace-Function */
3905 if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) {
3908 if (m->mdmreg[REG_ECHO] & BIT_ECHO)
3909 isdn_tty_at_cout("\b", info);
3914 if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
3917 isdn_tty_at_cout(eb, info);
3919 if (m->mdmcmdl < 255) {
3921 switch (m->mdmcmdl) {
3924 m->mdmcmd[m->mdmcmdl] = c;
3925 m->mdmcmd[++m->mdmcmdl] = 0;
3929 /* Fall through, check for 'A' */
3932 m->mdmcmd[m->mdmcmdl] = c;
3933 m->mdmcmd[++m->mdmcmdl] = 0;
3937 m->mdmcmd[m->mdmcmdl] = c;
3938 m->mdmcmd[++m->mdmcmdl] = 0;
3947 * Switch all modem-channels who are online and got a valid
3948 * escape-sequence 1.5 seconds ago, to command-mode.
3949 * This function is called every second via timer-interrupt from within
3950 * timer-dispatcher isdn_timer_function()
3953 isdn_tty_modem_escape(void)
3959 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
3960 if (USG_MODEM(dev->usage[i]))
3961 if ((midx = dev->m_idx[i]) >= 0) {
3962 modem_info *info = &dev->mdm.info[midx];
3965 if ((info->emu.pluscount == 3) &&
3966 time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) {
3967 info->emu.pluscount = 0;
3969 isdn_tty_modem_result(RESULT_OK, info);
3973 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
3977 * Put a RING-message to all modem-channels who have the RI-bit set.
3978 * This function is called every second via timer-interrupt from within
3979 * timer-dispatcher isdn_timer_function()
3982 isdn_tty_modem_ring(void)
3987 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3988 modem_info *info = &dev->mdm.info[i];
3989 if (info->msr & UART_MSR_RI) {
3991 isdn_tty_modem_result(RESULT_RING, info);
3994 isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton);
3998 * For all online tty's, try sending data to
4002 isdn_tty_modem_xmit(void)
4007 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
4008 modem_info *info = &dev->mdm.info[i];
4011 isdn_tty_senddown(info);
4012 isdn_tty_tint(info);
4015 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton);
4019 * Check all channels if we have a 'no carrier' timeout.
4020 * Timeout value is set by Register S7.
4023 isdn_tty_carrier_timeout(void)
4028 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
4029 modem_info *info = &dev->mdm.info[i];
4030 if (info->dialing) {
4031 if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
4033 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
4034 isdn_tty_modem_hup(info, 1);
4040 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);