1 /* $Id: isdn_tty.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
3 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
12 #undef ISDN_TTY_STAT_DEBUG
14 #include <linux/isdn.h>
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 char *isdn_tty_revision
= "$Revision: 1.1.2.3 $";
54 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
55 * to stuff incoming data directly into a tty's flip-buffer. This
56 * is done to speed up tty-receiving if the receive-queue is empty.
57 * This routine MUST be called with interrupts off.
60 * 0 = Failure, data has to be buffered and later processed by
61 * isdn_tty_readmodem().
64 isdn_tty_try_read(modem_info
* info
, struct sk_buff
*skb
)
68 struct tty_struct
*tty
;
72 if ((tty
= info
->tty
)) {
73 if (info
->mcr
& UART_MCR_RTS
) {
75 #ifdef CONFIG_ISDN_AUDIO
76 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
80 c
= tty_buffer_request_room(tty
, len
);
82 #ifdef CONFIG_ISDN_AUDIO
83 if (ISDN_AUDIO_SKB_DLECOUNT(skb
)) {
85 unsigned char *dp
= skb
->data
;
88 tty_insert_flip_char(tty
, DLE
, 0);
89 tty_insert_flip_char(tty
, *dp
++, 0);
92 tty_insert_flip_char(tty
, DLE
, 0);
97 tty_insert_flip_string(tty
, skb
->data
, len
- 1);
98 last
= skb
->data
[len
- 1];
99 #ifdef CONFIG_ISDN_AUDIO
102 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
103 tty_insert_flip_char(tty
, last
, 0xFF);
105 tty_insert_flip_char(tty
, last
, TTY_NORMAL
);
106 tty_flip_buffer_push(tty
);
116 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
117 * It tries getting received data from the receive queue an stuff it into
118 * the tty's flip-buffer.
121 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 /* CISCO AsyncPPP Hack */
143 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
144 r
= isdn_readbchan_tty(info
->isdn_driver
, info
->isdn_channel
, tty
, 0);
146 r
= isdn_readbchan_tty(info
->isdn_driver
, info
->isdn_channel
, tty
, 1);
148 tty_flip_buffer_push(tty
);
162 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
166 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
170 #ifdef CONFIG_ISDN_AUDIO
175 if ((midx
= dev
->m_idx
[i
]) < 0) {
176 /* if midx is invalid, packet is not for tty */
179 info
= &dev
->mdm
.info
[midx
];
180 #ifdef CONFIG_ISDN_AUDIO
183 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
184 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
185 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
186 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
188 if ((info
->online
< 2)
189 #ifdef CONFIG_ISDN_AUDIO
190 && (!(info
->vonline
& 1))
193 /* If Modem not listening, drop data */
197 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
198 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
199 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
200 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
203 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
206 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
207 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
210 #ifdef CONFIG_ISDN_AUDIO
211 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
212 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
213 if (info
->vonline
& 1) {
214 /* voice conversion/compression */
215 switch (info
->emu
.vpar
[3]) {
220 * Since compressed data takes less
221 * space, we can overwrite the buffer.
223 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
232 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
237 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
240 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
241 isdn_tty_countDLE(skb
->data
, skb
->len
);
243 #ifdef CONFIG_ISDN_TTY_FAX
245 if (info
->faxonline
& 2) {
246 isdn_tty_fax_bitorder(info
, skb
);
247 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
248 isdn_tty_countDLE(skb
->data
, skb
->len
);
253 /* Try to deliver directly via tty-buf if queue is empty */
254 spin_lock_irqsave(&info
->readlock
, flags
);
255 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
256 if (isdn_tty_try_read(info
, skb
)) {
257 spin_unlock_irqrestore(&info
->readlock
, flags
);
260 /* Direct deliver failed or queue wasn't empty.
261 * Queue up for later dequeueing via timer-irq.
263 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
264 dev
->drv
[di
]->rcvcount
[channel
] +=
266 #ifdef CONFIG_ISDN_AUDIO
267 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
270 spin_unlock_irqrestore(&info
->readlock
, flags
);
271 /* Schedule dequeuing */
272 if ((dev
->modempoll
) && (info
->rcvsched
))
273 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
278 isdn_tty_cleanup_xmit(modem_info
* info
)
280 skb_queue_purge(&info
->xmit_queue
);
281 #ifdef CONFIG_ISDN_AUDIO
282 skb_queue_purge(&info
->dtmf_queue
);
287 isdn_tty_tint(modem_info
* info
)
289 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
295 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
296 info
->isdn_channel
, 1, skb
)) == len
) {
297 struct tty_struct
*tty
= info
->tty
;
298 info
->send_outstanding
++;
299 info
->msr
&= ~UART_MSR_CTS
;
300 info
->lsr
&= ~UART_LSR_TEMT
;
305 /* Error: no channel, already shutdown, or wrong parameter */
309 skb_queue_head(&info
->xmit_queue
, skb
);
312 #ifdef CONFIG_ISDN_AUDIO
314 isdn_tty_countDLE(unsigned char *buf
, int len
)
324 /* This routine is called from within isdn_tty_write() to perform
325 * DLE-decoding when sending audio-data.
328 isdn_tty_handleDLEdown(modem_info
* info
, atemu
* m
, int len
)
330 unsigned char *p
= &info
->xmit_buf
[info
->xmit_count
];
340 memmove(p
, p
+ 1, len
- 1);
351 #ifdef ISDN_DEBUG_MODEM_VOICE
353 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
356 isdn_tty_at_cout("\020\003", info
);
357 if (!info
->vonline
) {
358 #ifdef ISDN_DEBUG_MODEM_VOICE
360 "DLEdown: send VCON on ttyI%d\n",
363 isdn_tty_at_cout("\r\nVCON\r\n", info
);
370 memmove(p
, p
+ 1, len
- 1);
384 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
390 /* This routine is called from within isdn_tty_write() when receiving
391 * audio-data. It interrupts receiving, if an character other than
395 isdn_tty_end_vrx(const char *buf
, int c
)
401 if ((ch
!= 0x11) && (ch
!= 0x13))
408 static int voice_cf
[7] =
409 {0, 0, 4, 3, 2, 0, 0};
411 #endif /* CONFIG_ISDN_AUDIO */
413 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
414 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
415 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
416 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
419 isdn_tty_senddown(modem_info
* info
)
423 #ifdef CONFIG_ISDN_AUDIO
428 #ifdef CONFIG_ISDN_AUDIO
429 if (info
->vonline
& 4) {
431 if (!info
->vonline
) {
432 #ifdef ISDN_DEBUG_MODEM_VOICE
434 "senddown: send VCON on ttyI%d\n",
437 isdn_tty_at_cout("\r\nVCON\r\n", info
);
441 if (!(buflen
= info
->xmit_count
))
443 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
444 info
->msr
&= ~UART_MSR_CTS
;
445 info
->lsr
&= ~UART_LSR_TEMT
;
446 /* info->xmit_count is modified here and in isdn_tty_write().
447 * So we return here if isdn_tty_write() is in the
450 atomic_inc(&info
->xmit_lock
);
451 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
453 if (info
->isdn_driver
< 0) {
454 info
->xmit_count
= 0;
457 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
458 #ifdef CONFIG_ISDN_AUDIO
459 if (info
->vonline
& 2)
460 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
463 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
465 skb
= dev_alloc_skb(skb_res
+ buflen
);
469 "isdn_tty: Out of memory in ttyI%d senddown\n",
473 skb_reserve(skb
, skb_res
);
474 memcpy(skb_put(skb
, buflen
), info
->xmit_buf
, buflen
);
475 info
->xmit_count
= 0;
476 #ifdef CONFIG_ISDN_AUDIO
477 if (info
->vonline
& 2) {
478 /* For now, ifmt is fixed to 1 (alaw), since this
479 * is used with ISDN everywhere in the world, except
480 * US, Canada and Japan.
481 * Later, when US-ISDN protocols are implemented,
482 * this setting will depend on the D-channel protocol.
486 /* voice conversion/decompression */
487 switch (info
->emu
.vpar
[3]) {
491 /* adpcm, compatible to ZyXel 1496 modem
492 * with ROM revision 6.01
494 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
497 skb_put(skb
, audio_len
),
499 skb_pull(skb
, buflen
);
500 skb_trim(skb
, audio_len
);
505 isdn_audio_alaw2ulaw(skb
->data
,
511 isdn_audio_ulaw2alaw(skb
->data
,
516 #endif /* CONFIG_ISDN_AUDIO */
517 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
518 /* Add T.70 simplified header */
519 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
520 memcpy(skb_push(skb
, 2), "\1\0", 2);
522 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
524 skb_queue_tail(&info
->xmit_queue
, skb
);
527 /************************************************************
531 * mostly "stolen" from original Linux-serial.c and friends.
533 ************************************************************/
535 /* The next routine is called once from within timer-interrupt
536 * triggered within isdn_tty_modem_ncarrier(). It calls
537 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
538 * into the tty's buffer.
541 isdn_tty_modem_do_ncarrier(unsigned long data
)
543 modem_info
*info
= (modem_info
*) data
;
544 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
547 /* Next routine is called, whenever the DTR-signal is raised.
548 * It checks the ncarrier-flag, and triggers the above routine
549 * when necessary. The ncarrier-flag is set, whenever DTR goes
553 isdn_tty_modem_ncarrier(modem_info
* info
)
555 if (info
->ncarrier
) {
556 info
->nc_timer
.expires
= jiffies
+ HZ
;
557 add_timer(&info
->nc_timer
);
562 * return the usage calculated by si and layer 2 protocol
565 isdn_calc_usage(int si
, int l2
)
567 int usg
= ISDN_USAGE_MODEM
;
569 #ifdef CONFIG_ISDN_AUDIO
572 case ISDN_PROTO_L2_MODEM
:
573 usg
= ISDN_USAGE_MODEM
;
575 #ifdef CONFIG_ISDN_TTY_FAX
576 case ISDN_PROTO_L2_FAX
:
577 usg
= ISDN_USAGE_FAX
;
580 case ISDN_PROTO_L2_TRANS
:
582 usg
= ISDN_USAGE_VOICE
;
590 /* isdn_tty_dial() performs dialing of a tty an the necessary
591 * setup of the lower levels before that.
594 isdn_tty_dial(char *n
, modem_info
* info
, atemu
* m
)
596 int usg
= ISDN_USAGE_MODEM
;
598 int l2
= m
->mdmreg
[REG_L2PROT
];
604 for (j
= 7; j
>= 0; j
--)
605 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
609 usg
= isdn_calc_usage(si
, l2
);
610 #ifdef CONFIG_ISDN_AUDIO
612 (l2
!= ISDN_PROTO_L2_MODEM
)
613 #ifdef CONFIG_ISDN_TTY_FAX
614 && (l2
!= ISDN_PROTO_L2_FAX
)
617 l2
= ISDN_PROTO_L2_TRANS
;
618 usg
= ISDN_USAGE_VOICE
;
621 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
622 spin_lock_irqsave(&dev
->lock
, flags
);
623 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
625 spin_unlock_irqrestore(&dev
->lock
, flags
);
626 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
628 info
->isdn_driver
= dev
->drvmap
[i
];
629 info
->isdn_channel
= dev
->chanmap
[i
];
631 dev
->m_idx
[i
] = info
->line
;
632 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
634 strcpy(info
->last_num
, n
);
636 spin_unlock_irqrestore(&dev
->lock
, flags
);
637 cmd
.driver
= info
->isdn_driver
;
638 cmd
.arg
= info
->isdn_channel
;
639 cmd
.command
= ISDN_CMD_CLREAZ
;
641 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
642 cmd
.driver
= info
->isdn_driver
;
643 cmd
.command
= ISDN_CMD_SETEAZ
;
645 cmd
.driver
= info
->isdn_driver
;
646 cmd
.command
= ISDN_CMD_SETL2
;
648 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
650 cmd
.driver
= info
->isdn_driver
;
651 cmd
.command
= ISDN_CMD_SETL3
;
652 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
653 #ifdef CONFIG_ISDN_TTY_FAX
654 if (l2
== ISDN_PROTO_L2_FAX
) {
655 cmd
.parm
.fax
= info
->fax
;
656 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
660 cmd
.driver
= info
->isdn_driver
;
661 cmd
.arg
= info
->isdn_channel
;
662 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
663 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
664 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
665 cmd
.parm
.setup
.si1
= si
;
666 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
667 cmd
.command
= ISDN_CMD_DIAL
;
669 info
->emu
.carrierwait
= 0;
670 strcpy(dev
->num
[i
], n
);
673 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
677 /* isdn_tty_hangup() disassociates a tty from the real
678 * ISDN-line (hangup). The usage-status is cleared
679 * and some cleanup is done also.
682 isdn_tty_modem_hup(modem_info
* info
, int local
)
690 di
= info
->isdn_driver
;
691 ch
= info
->isdn_channel
;
692 if (di
< 0 || ch
< 0)
695 info
->isdn_driver
= -1;
696 info
->isdn_channel
= -1;
698 #ifdef ISDN_DEBUG_MODEM_HUP
699 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
702 isdn_tty_flush_buffer(info
->tty
);
704 info
->last_lhup
= local
;
706 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
708 #ifdef CONFIG_ISDN_AUDIO
710 #ifdef CONFIG_ISDN_TTY_FAX
712 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
714 info
->emu
.vpar
[4] = 0;
715 info
->emu
.vpar
[5] = 8;
716 kfree(info
->dtmf_state
);
717 info
->dtmf_state
= NULL
;
718 kfree(info
->silence_state
);
719 info
->silence_state
= NULL
;
725 if ((info
->msr
& UART_MSR_RI
) &&
726 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
727 isdn_tty_modem_result(RESULT_RUNG
, info
);
728 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
729 info
->lsr
|= UART_LSR_TEMT
;
733 cmd
.command
= ISDN_CMD_HANGUP
;
738 isdn_all_eaz(di
, ch
);
739 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
740 isdn_free_channel(di
, ch
, 0);
742 if (info
->drv_index
>= 0) {
743 dev
->m_idx
[info
->drv_index
] = -1;
744 info
->drv_index
= -1;
749 * Begin of a CAPI like interface, currently used only for
750 * supplementary service (CAPI 2.0 part III)
752 #include <linux/isdn/capicmd.h>
755 isdn_tty_capi_facility(capi_msg
*cm
) {
756 return(-1); /* dummy */
759 /* isdn_tty_suspend() tries to suspend the current tty connection
762 isdn_tty_suspend(char *id
, modem_info
* info
, atemu
* m
)
771 #ifdef ISDN_DEBUG_MODEM_SERVICES
772 printk(KERN_DEBUG
"Msusp ttyI%d\n", info
->line
);
775 if ((info
->isdn_driver
>= 0)) {
776 cmd
.parm
.cmsg
.Length
= l
+18;
777 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
778 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
779 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
780 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
781 cmd
.parm
.cmsg
.para
[1] = 0;
782 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
783 cmd
.parm
.cmsg
.para
[3] = 4; /* 16 bit 0x0004 Suspend */
784 cmd
.parm
.cmsg
.para
[4] = 0;
785 cmd
.parm
.cmsg
.para
[5] = l
;
786 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
787 cmd
.command
= CAPI_PUT_MESSAGE
;
788 cmd
.driver
= info
->isdn_driver
;
789 cmd
.arg
= info
->isdn_channel
;
794 /* isdn_tty_resume() tries to resume a suspended call
795 * setup of the lower levels before that. unfortunatly here is no
796 * checking for compatibility of used protocols implemented by Q931
797 * It does the same things like isdn_tty_dial, the last command
798 * is different, may be we can merge it.
802 isdn_tty_resume(char *id
, modem_info
* info
, atemu
* m
)
804 int usg
= ISDN_USAGE_MODEM
;
806 int l2
= m
->mdmreg
[REG_L2PROT
];
814 for (j
= 7; j
>= 0; j
--)
815 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
819 usg
= isdn_calc_usage(si
, l2
);
820 #ifdef CONFIG_ISDN_AUDIO
822 (l2
!= ISDN_PROTO_L2_MODEM
)
823 #ifdef CONFIG_ISDN_TTY_FAX
824 && (l2
!= ISDN_PROTO_L2_FAX
)
827 l2
= ISDN_PROTO_L2_TRANS
;
828 usg
= ISDN_USAGE_VOICE
;
831 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
832 spin_lock_irqsave(&dev
->lock
, flags
);
833 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
835 spin_unlock_irqrestore(&dev
->lock
, flags
);
836 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
838 info
->isdn_driver
= dev
->drvmap
[i
];
839 info
->isdn_channel
= dev
->chanmap
[i
];
841 dev
->m_idx
[i
] = info
->line
;
842 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
844 // strcpy(info->last_num, n);
846 spin_unlock_irqrestore(&dev
->lock
, flags
);
847 cmd
.driver
= info
->isdn_driver
;
848 cmd
.arg
= info
->isdn_channel
;
849 cmd
.command
= ISDN_CMD_CLREAZ
;
851 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
852 cmd
.driver
= info
->isdn_driver
;
853 cmd
.command
= ISDN_CMD_SETEAZ
;
855 cmd
.driver
= info
->isdn_driver
;
856 cmd
.command
= ISDN_CMD_SETL2
;
858 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
860 cmd
.driver
= info
->isdn_driver
;
861 cmd
.command
= ISDN_CMD_SETL3
;
862 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
864 cmd
.driver
= info
->isdn_driver
;
865 cmd
.arg
= info
->isdn_channel
;
866 cmd
.parm
.cmsg
.Length
= l
+18;
867 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
868 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
869 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
870 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
871 cmd
.parm
.cmsg
.para
[1] = 0;
872 cmd
.parm
.cmsg
.para
[2] = l
+3;
873 cmd
.parm
.cmsg
.para
[3] = 5; /* 16 bit 0x0005 Resume */
874 cmd
.parm
.cmsg
.para
[4] = 0;
875 cmd
.parm
.cmsg
.para
[5] = l
;
876 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
877 cmd
.command
=CAPI_PUT_MESSAGE
;
879 // strcpy(dev->num[i], n);
882 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
886 /* isdn_tty_send_msg() sends a message to a HL driver
887 * This is used for hybrid modem cards to send AT commands to it
891 isdn_tty_send_msg(modem_info
* info
, atemu
* m
, char *msg
)
893 int usg
= ISDN_USAGE_MODEM
;
895 int l2
= m
->mdmreg
[REG_L2PROT
];
904 isdn_tty_modem_result(RESULT_ERROR
, info
);
907 for (j
= 7; j
>= 0; j
--)
908 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
912 usg
= isdn_calc_usage(si
, l2
);
913 #ifdef CONFIG_ISDN_AUDIO
915 (l2
!= ISDN_PROTO_L2_MODEM
)
916 #ifdef CONFIG_ISDN_TTY_FAX
917 && (l2
!= ISDN_PROTO_L2_FAX
)
920 l2
= ISDN_PROTO_L2_TRANS
;
921 usg
= ISDN_USAGE_VOICE
;
924 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
925 spin_lock_irqsave(&dev
->lock
, flags
);
926 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
928 spin_unlock_irqrestore(&dev
->lock
, flags
);
929 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
931 info
->isdn_driver
= dev
->drvmap
[i
];
932 info
->isdn_channel
= dev
->chanmap
[i
];
934 dev
->m_idx
[i
] = info
->line
;
935 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
938 spin_unlock_irqrestore(&dev
->lock
, flags
);
939 cmd
.driver
= info
->isdn_driver
;
940 cmd
.arg
= info
->isdn_channel
;
941 cmd
.command
= ISDN_CMD_CLREAZ
;
943 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
944 cmd
.driver
= info
->isdn_driver
;
945 cmd
.command
= ISDN_CMD_SETEAZ
;
947 cmd
.driver
= info
->isdn_driver
;
948 cmd
.command
= ISDN_CMD_SETL2
;
950 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
952 cmd
.driver
= info
->isdn_driver
;
953 cmd
.command
= ISDN_CMD_SETL3
;
954 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
956 cmd
.driver
= info
->isdn_driver
;
957 cmd
.arg
= info
->isdn_channel
;
958 cmd
.parm
.cmsg
.Length
= l
+14;
959 cmd
.parm
.cmsg
.Command
= CAPI_MANUFACTURER
;
960 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
961 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
962 cmd
.parm
.cmsg
.para
[0] = l
+1;
963 strncpy(&cmd
.parm
.cmsg
.para
[1], msg
, l
);
964 cmd
.parm
.cmsg
.para
[l
+1] = 0xd;
965 cmd
.command
=CAPI_PUT_MESSAGE
;
966 /* info->dialing = 1;
967 strcpy(dev->num[i], n);
975 isdn_tty_paranoia_check(modem_info
*info
, char *name
, const char *routine
)
977 #ifdef MODEM_PARANOIA_CHECK
979 printk(KERN_WARNING
"isdn_tty: null info_struct for %s in %s\n",
983 if (info
->magic
!= ISDN_ASYNC_MAGIC
) {
984 printk(KERN_WARNING
"isdn_tty: bad magic for modem struct %s in %s\n",
993 * This routine is called to set the UART divisor registers to match
994 * the specified baud rate for a serial port.
997 isdn_tty_change_speed(modem_info
* info
)
1005 if (!info
->tty
|| !info
->tty
->termios
)
1007 cflag
= info
->tty
->termios
->c_cflag
;
1009 quot
= i
= cflag
& CBAUD
;
1013 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
1018 info
->mcr
|= UART_MCR_DTR
;
1019 isdn_tty_modem_ncarrier(info
);
1021 info
->mcr
&= ~UART_MCR_DTR
;
1022 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1023 #ifdef ISDN_DEBUG_MODEM_HUP
1024 printk(KERN_DEBUG
"Mhup in changespeed\n");
1028 isdn_tty_modem_reset_regs(info
, 0);
1029 isdn_tty_modem_hup(info
, 1);
1033 /* byte size and parity */
1034 cval
= cflag
& (CSIZE
| CSTOPB
);
1037 cval
|= UART_LCR_PARITY
;
1038 if (!(cflag
& PARODD
))
1039 cval
|= UART_LCR_EPAR
;
1042 /* CTS flow control flag and modem status interrupts */
1043 if (cflag
& CRTSCTS
) {
1044 info
->flags
|= ISDN_ASYNC_CTS_FLOW
;
1046 info
->flags
&= ~ISDN_ASYNC_CTS_FLOW
;
1048 info
->flags
&= ~ISDN_ASYNC_CHECK_CD
;
1050 info
->flags
|= ISDN_ASYNC_CHECK_CD
;
1055 isdn_tty_startup(modem_info
* info
)
1057 if (info
->flags
& ISDN_ASYNC_INITIALIZED
)
1059 isdn_lock_drivers();
1060 #ifdef ISDN_DEBUG_MODEM_OPEN
1061 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1064 * Now, initialize the UART
1066 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1068 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1070 * and set the speed of the serial port
1072 isdn_tty_change_speed(info
);
1074 info
->flags
|= ISDN_ASYNC_INITIALIZED
;
1075 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1076 info
->send_outstanding
= 0;
1081 * This routine will shutdown a serial port; interrupts are disabled, and
1082 * DTR is dropped if the hangup on close termio flag is on.
1085 isdn_tty_shutdown(modem_info
* info
)
1087 if (!(info
->flags
& ISDN_ASYNC_INITIALIZED
))
1089 #ifdef ISDN_DEBUG_MODEM_OPEN
1090 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1092 isdn_unlock_drivers();
1093 info
->msr
&= ~UART_MSR_RI
;
1094 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
1095 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1096 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1097 isdn_tty_modem_reset_regs(info
, 0);
1098 #ifdef ISDN_DEBUG_MODEM_HUP
1099 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1101 isdn_tty_modem_hup(info
, 1);
1105 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1107 info
->flags
&= ~ISDN_ASYNC_INITIALIZED
;
1110 /* isdn_tty_write() is the main send-routine. It is called from the upper
1111 * levels within the kernel to perform sending data. Depending on the
1112 * online-flag it either directs output to the at-command-interpreter or
1113 * to the lower level. Additional tasks done here:
1114 * - If online, check for escape-sequence (+++)
1115 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1116 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1117 * - If dialing, abort dial.
1120 isdn_tty_write(struct tty_struct
*tty
, const u_char
* buf
, int count
)
1124 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1125 atemu
*m
= &info
->emu
;
1127 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write"))
1129 /* See isdn_tty_senddown() */
1130 atomic_inc(&info
->xmit_lock
);
1133 if (c
> info
->xmit_size
- info
->xmit_count
)
1134 c
= info
->xmit_size
- info
->xmit_count
;
1135 if (info
->isdn_driver
>= 0 && c
> dev
->drv
[info
->isdn_driver
]->maxbufsize
)
1136 c
= dev
->drv
[info
->isdn_driver
]->maxbufsize
;
1139 if ((info
->online
> 1)
1140 #ifdef CONFIG_ISDN_AUDIO
1141 || (info
->vonline
& 3)
1144 #ifdef CONFIG_ISDN_AUDIO
1147 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1150 memcpy(&(info
->xmit_buf
[info
->xmit_count
]), buf
, c
);
1151 #ifdef CONFIG_ISDN_AUDIO
1152 if (info
->vonline
) {
1153 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1154 if (info
->vonline
& 2) {
1156 /* If DLE decoding results in zero-transmit, but
1157 * c originally was non-zero, do a wakeup.
1160 info
->msr
|= UART_MSR_CTS
;
1161 info
->lsr
|= UART_LSR_TEMT
;
1163 info
->xmit_count
+= cc
;
1165 if ((info
->vonline
& 3) == 1) {
1166 /* Do NOT handle Ctrl-Q or Ctrl-S
1167 * when in full-duplex audio mode.
1169 if (isdn_tty_end_vrx(buf
, c
)) {
1170 info
->vonline
&= ~1;
1171 #ifdef ISDN_DEBUG_MODEM_VOICE
1173 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1176 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1180 if (TTY_IS_FCLASS1(info
)) {
1181 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1183 if (info
->vonline
& 4) { /* ETX seen */
1186 c
.command
= ISDN_CMD_FAXCMD
;
1187 c
.driver
= info
->isdn_driver
;
1188 c
.arg
= info
->isdn_channel
;
1189 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1190 c
.parm
.aux
.subcmd
= ETX
;
1194 #ifdef ISDN_DEBUG_MODEM_VOICE
1195 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
, c
);
1197 info
->xmit_count
+= cc
;
1200 info
->xmit_count
+= c
;
1202 info
->msr
|= UART_MSR_CTS
;
1203 info
->lsr
|= UART_LSR_TEMT
;
1204 if (info
->dialing
) {
1206 #ifdef ISDN_DEBUG_MODEM_HUP
1207 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1209 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1210 isdn_tty_modem_hup(info
, 1);
1212 c
= isdn_tty_edit_at(buf
, c
, info
);
1218 atomic_dec(&info
->xmit_lock
);
1219 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
)) {
1220 if (m
->mdmreg
[REG_DXMT
] & BIT_DXMT
) {
1221 isdn_tty_senddown(info
);
1222 isdn_tty_tint(info
);
1224 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1230 isdn_tty_write_room(struct tty_struct
*tty
)
1232 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1235 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write_room"))
1238 return info
->xmit_size
;
1239 ret
= info
->xmit_size
- info
->xmit_count
;
1240 return (ret
< 0) ? 0 : ret
;
1244 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1246 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1248 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_chars_in_buffer"))
1252 return (info
->xmit_count
);
1256 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1263 info
= (modem_info
*) tty
->driver_data
;
1264 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_buffer")) {
1267 isdn_tty_cleanup_xmit(info
);
1268 info
->xmit_count
= 0;
1273 isdn_tty_flush_chars(struct tty_struct
*tty
)
1275 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1277 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_chars"))
1279 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
))
1280 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1284 * ------------------------------------------------------------
1285 * isdn_tty_throttle()
1287 * This routine is called by the upper-layer tty layer to signal that
1288 * incoming characters should be throttled.
1289 * ------------------------------------------------------------
1292 isdn_tty_throttle(struct tty_struct
*tty
)
1294 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1296 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_throttle"))
1299 info
->x_char
= STOP_CHAR(tty
);
1300 info
->mcr
&= ~UART_MCR_RTS
;
1304 isdn_tty_unthrottle(struct tty_struct
*tty
)
1306 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1308 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_unthrottle"))
1314 info
->x_char
= START_CHAR(tty
);
1316 info
->mcr
|= UART_MCR_RTS
;
1320 * ------------------------------------------------------------
1321 * isdn_tty_ioctl() and friends
1322 * ------------------------------------------------------------
1326 * isdn_tty_get_lsr_info - get line status register info
1328 * Purpose: Let user call ioctl() to get info when the UART physically
1329 * is emptied. On bus types like RS485, the transmitter must
1330 * release the bus after transmitting. This must be done when
1331 * the transmit shift register is empty, not be done when the
1332 * transmit holding register is empty. This functionality
1333 * allows RS485 driver to be written in user space.
1336 isdn_tty_get_lsr_info(modem_info
* info
, uint __user
* value
)
1342 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1343 return put_user(result
, value
);
1348 isdn_tty_tiocmget(struct tty_struct
*tty
)
1350 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1351 u_char control
, status
;
1353 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1355 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1358 mutex_lock(&modem_info_mutex
);
1359 #ifdef ISDN_DEBUG_MODEM_IOCTL
1360 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1363 control
= info
->mcr
;
1365 mutex_unlock(&modem_info_mutex
);
1366 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1367 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1368 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1369 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1370 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1371 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1375 isdn_tty_tiocmset(struct tty_struct
*tty
,
1376 unsigned int set
, unsigned int clear
)
1378 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1380 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1382 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1385 #ifdef ISDN_DEBUG_MODEM_IOCTL
1386 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMxxx: %x %x\n", info
->line
, set
, clear
);
1389 mutex_lock(&modem_info_mutex
);
1390 if (set
& TIOCM_RTS
)
1391 info
->mcr
|= UART_MCR_RTS
;
1392 if (set
& TIOCM_DTR
) {
1393 info
->mcr
|= UART_MCR_DTR
;
1394 isdn_tty_modem_ncarrier(info
);
1397 if (clear
& TIOCM_RTS
)
1398 info
->mcr
&= ~UART_MCR_RTS
;
1399 if (clear
& TIOCM_DTR
) {
1400 info
->mcr
&= ~UART_MCR_DTR
;
1401 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1402 isdn_tty_modem_reset_regs(info
, 0);
1403 #ifdef ISDN_DEBUG_MODEM_HUP
1404 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1408 isdn_tty_modem_hup(info
, 1);
1411 mutex_unlock(&modem_info_mutex
);
1416 isdn_tty_ioctl(struct tty_struct
*tty
, uint cmd
, ulong arg
)
1418 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1421 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_ioctl"))
1423 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1426 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1427 #ifdef ISDN_DEBUG_MODEM_IOCTL
1428 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1430 retval
= tty_check_change(tty
);
1433 tty_wait_until_sent(tty
, 0);
1435 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1436 #ifdef ISDN_DEBUG_MODEM_IOCTL
1437 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1439 retval
= tty_check_change(tty
);
1442 tty_wait_until_sent(tty
, 0);
1444 case TIOCSERGETLSR
: /* Get line status register */
1445 #ifdef ISDN_DEBUG_MODEM_IOCTL
1446 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1448 return isdn_tty_get_lsr_info(info
, (uint __user
*) arg
);
1450 #ifdef ISDN_DEBUG_MODEM_IOCTL
1451 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1453 return -ENOIOCTLCMD
;
1459 isdn_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
1461 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1464 isdn_tty_change_speed(info
);
1466 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
&&
1467 tty
->termios
->c_ispeed
== old_termios
->c_ispeed
&&
1468 tty
->termios
->c_ospeed
== old_termios
->c_ospeed
)
1470 isdn_tty_change_speed(info
);
1471 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1472 !(tty
->termios
->c_cflag
& CRTSCTS
))
1473 tty
->hw_stopped
= 0;
1478 * ------------------------------------------------------------
1479 * isdn_tty_open() and friends
1480 * ------------------------------------------------------------
1483 isdn_tty_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, modem_info
* info
)
1485 DECLARE_WAITQUEUE(wait
, NULL
);
1490 * If the device is in the middle of being closed, then block
1491 * until it's done, and then try again.
1493 if (tty_hung_up_p(filp
) ||
1494 (info
->flags
& ISDN_ASYNC_CLOSING
)) {
1495 if (info
->flags
& ISDN_ASYNC_CLOSING
)
1496 interruptible_sleep_on(&info
->close_wait
);
1497 #ifdef MODEM_DO_RESTART
1498 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1501 return -ERESTARTSYS
;
1507 * If non-blocking mode is set, then make the check up front
1510 if ((filp
->f_flags
& O_NONBLOCK
) ||
1511 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1512 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
1514 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
1517 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) {
1518 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1521 if (tty
->termios
->c_cflag
& CLOCAL
)
1525 * Block waiting for the carrier detect and the line to become
1526 * free (i.e., not in use by the callout). While we are in
1527 * this loop, info->count is dropped by one, so that
1528 * isdn_tty_close() knows when to free things. We restore it upon
1529 * exit, either normal or abnormal.
1532 add_wait_queue(&info
->open_wait
, &wait
);
1533 #ifdef ISDN_DEBUG_MODEM_OPEN
1534 printk(KERN_DEBUG
"isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1535 info
->line
, info
->count
);
1537 if (!(tty_hung_up_p(filp
)))
1539 info
->blocked_open
++;
1541 set_current_state(TASK_INTERRUPTIBLE
);
1542 if (tty_hung_up_p(filp
) ||
1543 !(info
->flags
& ISDN_ASYNC_INITIALIZED
)) {
1544 #ifdef MODEM_DO_RESTART
1545 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1548 retval
= -ERESTARTSYS
;
1554 if (!(info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
1555 !(info
->flags
& ISDN_ASYNC_CLOSING
) &&
1556 (do_clocal
|| (info
->msr
& UART_MSR_DCD
))) {
1559 if (signal_pending(current
)) {
1560 retval
= -ERESTARTSYS
;
1563 #ifdef ISDN_DEBUG_MODEM_OPEN
1564 printk(KERN_DEBUG
"isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1565 info
->line
, info
->count
);
1569 current
->state
= TASK_RUNNING
;
1570 remove_wait_queue(&info
->open_wait
, &wait
);
1571 if (!tty_hung_up_p(filp
))
1573 info
->blocked_open
--;
1574 #ifdef ISDN_DEBUG_MODEM_OPEN
1575 printk(KERN_DEBUG
"isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1576 info
->line
, info
->count
);
1580 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
1585 * This routine is called whenever a serial port is opened. It
1586 * enables interrupts for a serial port, linking in its async structure into
1587 * the IRQ chain. It also performs the serial-specific
1588 * initialization for the tty structure.
1591 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
1597 if (line
< 0 || line
>= ISDN_MAX_CHANNELS
)
1599 info
= &dev
->mdm
.info
[line
];
1600 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_open"))
1602 if (!try_module_get(info
->owner
)) {
1603 printk(KERN_WARNING
"%s: cannot reserve module\n", __func__
);
1606 #ifdef ISDN_DEBUG_MODEM_OPEN
1607 printk(KERN_DEBUG
"isdn_tty_open %s, count = %d\n", tty
->name
,
1611 tty
->driver_data
= info
;
1614 * Start up serial port
1616 retval
= isdn_tty_startup(info
);
1618 #ifdef ISDN_DEBUG_MODEM_OPEN
1619 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
1621 module_put(info
->owner
);
1624 retval
= isdn_tty_block_til_ready(tty
, filp
, info
);
1626 #ifdef ISDN_DEBUG_MODEM_OPEN
1627 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
1629 module_put(info
->owner
);
1632 #ifdef ISDN_DEBUG_MODEM_OPEN
1633 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
1636 #ifdef ISDN_DEBUG_MODEM_OPEN
1637 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
1643 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
1645 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1648 if (!info
|| isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_close"))
1650 if (tty_hung_up_p(filp
)) {
1651 #ifdef ISDN_DEBUG_MODEM_OPEN
1652 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
1656 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1658 * Uh, oh. tty->count is 1, which means that the tty
1659 * structure will be freed. Info->count should always
1660 * be one in these conditions. If it's greater than
1661 * one, we've got real problems, since it means the
1662 * serial port won't be shutdown.
1664 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
1665 "info->count is %d\n", info
->count
);
1668 if (--info
->count
< 0) {
1669 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
1670 info
->line
, info
->count
);
1674 #ifdef ISDN_DEBUG_MODEM_OPEN
1675 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
1677 module_put(info
->owner
);
1680 info
->flags
|= ISDN_ASYNC_CLOSING
;
1682 * Save the termios structure, since this port may have
1683 * separate termios for callout and dialin.
1685 if (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
)
1686 info
->normal_termios
= *tty
->termios
;
1687 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
1688 info
->callout_termios
= *tty
->termios
;
1692 * At this point we stop accepting input. To do this, we
1693 * disable the receive line status interrupts, and tell the
1694 * interrupt driver to stop checking the data ready bit in the
1695 * line status register.
1697 if (info
->flags
& ISDN_ASYNC_INITIALIZED
) {
1698 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
1700 * Before we drop DTR, make sure the UART transmitter
1701 * has completely drained; this is especially
1702 * important if there is a transmit FIFO!
1704 timeout
= jiffies
+ HZ
;
1705 while (!(info
->lsr
& UART_LSR_TEMT
)) {
1706 schedule_timeout_interruptible(20);
1707 if (time_after(jiffies
,timeout
))
1712 isdn_tty_shutdown(info
);
1713 isdn_tty_flush_buffer(tty
);
1714 tty_ldisc_flush(tty
);
1718 module_put(info
->owner
);
1719 if (info
->blocked_open
) {
1720 msleep_interruptible(500);
1721 wake_up_interruptible(&info
->open_wait
);
1723 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CLOSING
);
1724 wake_up_interruptible(&info
->close_wait
);
1725 #ifdef ISDN_DEBUG_MODEM_OPEN
1726 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
1731 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1734 isdn_tty_hangup(struct tty_struct
*tty
)
1736 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1738 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_hangup"))
1740 isdn_tty_shutdown(info
);
1742 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CALLOUT_ACTIVE
);
1744 wake_up_interruptible(&info
->open_wait
);
1747 /* This routine initializes all emulator-data.
1750 isdn_tty_reset_profile(atemu
* m
)
1763 m
->profile
[11] = 70;
1764 m
->profile
[12] = 0x45;
1766 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
1767 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
1768 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
1769 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
1778 #ifdef CONFIG_ISDN_AUDIO
1780 isdn_tty_modem_reset_vpar(atemu
* m
)
1782 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
1783 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
1784 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
1785 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1786 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
1787 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1791 #ifdef CONFIG_ISDN_TTY_FAX
1793 isdn_tty_modem_reset_faxpar(modem_info
* info
)
1795 T30_s
*f
= info
->fax
;
1798 f
->phase
= ISDN_FAX_PHASE_IDLE
;
1800 f
->resolution
= 1; /* fine */
1801 f
->rate
= 5; /* 14400 bit/s */
1808 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
1809 f
->id
[FAXIDLEN
- 1] = 0;
1820 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
1821 f
->pollid
[FAXIDLEN
- 1] = 0;
1826 isdn_tty_modem_reset_regs(modem_info
* info
, int force
)
1828 atemu
*m
= &info
->emu
;
1829 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
1830 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
1831 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
1832 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
1833 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
1835 #ifdef CONFIG_ISDN_AUDIO
1836 isdn_tty_modem_reset_vpar(m
);
1838 #ifdef CONFIG_ISDN_TTY_FAX
1839 isdn_tty_modem_reset_faxpar(info
);
1845 modem_write_profile(atemu
* m
)
1847 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
1848 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
1849 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
1851 send_sig(SIGIO
, dev
->profd
, 1);
1854 static const struct tty_operations modem_ops
= {
1855 .open
= isdn_tty_open
,
1856 .close
= isdn_tty_close
,
1857 .write
= isdn_tty_write
,
1858 .flush_chars
= isdn_tty_flush_chars
,
1859 .write_room
= isdn_tty_write_room
,
1860 .chars_in_buffer
= isdn_tty_chars_in_buffer
,
1861 .flush_buffer
= isdn_tty_flush_buffer
,
1862 .ioctl
= isdn_tty_ioctl
,
1863 .throttle
= isdn_tty_throttle
,
1864 .unthrottle
= isdn_tty_unthrottle
,
1865 .set_termios
= isdn_tty_set_termios
,
1866 .hangup
= isdn_tty_hangup
,
1867 .tiocmget
= isdn_tty_tiocmget
,
1868 .tiocmset
= isdn_tty_tiocmset
,
1872 isdn_tty_modem_init(void)
1879 m
->tty_modem
= alloc_tty_driver(ISDN_MAX_CHANNELS
);
1882 m
->tty_modem
->name
= "ttyI";
1883 m
->tty_modem
->major
= ISDN_TTY_MAJOR
;
1884 m
->tty_modem
->minor_start
= 0;
1885 m
->tty_modem
->type
= TTY_DRIVER_TYPE_SERIAL
;
1886 m
->tty_modem
->subtype
= SERIAL_TYPE_NORMAL
;
1887 m
->tty_modem
->init_termios
= tty_std_termios
;
1888 m
->tty_modem
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1889 m
->tty_modem
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
1890 m
->tty_modem
->driver_name
= "isdn_tty";
1891 tty_set_operations(m
->tty_modem
, &modem_ops
);
1892 retval
= tty_register_driver(m
->tty_modem
);
1894 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
1897 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1899 #ifdef CONFIG_ISDN_TTY_FAX
1900 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
1901 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
1903 goto err_unregister
;
1907 info
->owner
= THIS_MODULE
;
1909 spin_lock_init(&info
->readlock
);
1910 sprintf(info
->last_cause
, "0000");
1911 sprintf(info
->last_num
, "none");
1913 info
->last_lhup
= 1;
1916 isdn_tty_reset_profile(&info
->emu
);
1917 isdn_tty_modem_reset_regs(info
, 1);
1918 info
->magic
= ISDN_ASYNC_MAGIC
;
1923 info
->blocked_open
= 0;
1924 init_waitqueue_head(&info
->open_wait
);
1925 init_waitqueue_head(&info
->close_wait
);
1926 info
->isdn_driver
= -1;
1927 info
->isdn_channel
= -1;
1928 info
->drv_index
= -1;
1929 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
1930 init_timer(&info
->nc_timer
);
1931 info
->nc_timer
.function
= isdn_tty_modem_do_ncarrier
;
1932 info
->nc_timer
.data
= (unsigned long) info
;
1933 skb_queue_head_init(&info
->xmit_queue
);
1934 #ifdef CONFIG_ISDN_AUDIO
1935 skb_queue_head_init(&info
->dtmf_queue
);
1937 if (!(info
->xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5, GFP_KERNEL
))) {
1938 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
1940 goto err_unregister
;
1942 /* Make room for T.70 header */
1943 info
->xmit_buf
+= 4;
1947 for (i
--; i
>= 0; i
--) {
1949 #ifdef CONFIG_ISDN_TTY_FAX
1952 kfree(info
->xmit_buf
- 4);
1954 tty_unregister_driver(m
->tty_modem
);
1956 put_tty_driver(m
->tty_modem
);
1957 m
->tty_modem
= NULL
;
1967 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1968 info
= &dev
->mdm
.info
[i
];
1969 isdn_tty_cleanup_xmit(info
);
1970 #ifdef CONFIG_ISDN_TTY_FAX
1973 kfree(info
->xmit_buf
- 4);
1975 tty_unregister_driver(dev
->mdm
.tty_modem
);
1976 put_tty_driver(dev
->mdm
.tty_modem
);
1977 dev
->mdm
.tty_modem
= NULL
;
1982 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
1983 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
1984 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
1988 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
1990 #ifdef ISDN_DEBUG_MODEM_ICALL
1991 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
1992 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
1993 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
1995 if (strlen(emu
->lmsn
)) {
1996 char *p
= emu
->lmsn
;
2002 if ((q
= strchr(p
, ';')))
2004 if ((tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
2006 #ifdef ISDN_DEBUG_MODEM_ICALL
2007 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2008 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2023 tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
2024 #ifdef ISDN_DEBUG_MODEM_ICALL
2025 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
2026 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2033 * An incoming call-request has arrived.
2034 * Search the tty-devices for an appropriate device and bind
2035 * it to the ISDN-Channel.
2038 * 0 = No matching device found.
2039 * 1 = A matching device found.
2040 * 3 = No match found, but eventually would match, if
2044 isdn_tty_find_icall(int di
, int ch
, setup_parm
*setup
)
2055 if (!setup
->phone
[0]) {
2057 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
2060 si1
= (int) setup
->si1
;
2061 si2
= (int) setup
->si2
;
2062 if (!setup
->eazmsn
[0]) {
2063 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
2066 eaz
= setup
->eazmsn
;
2067 #ifdef ISDN_DEBUG_MODEM_ICALL
2068 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
2071 spin_lock_irqsave(&dev
->lock
, flags
);
2072 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2073 modem_info
*info
= &dev
->mdm
.info
[i
];
2075 if (info
->count
== 0)
2077 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
2078 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
2079 idx
= isdn_dc2minor(di
, ch
);
2080 #ifdef ISDN_DEBUG_MODEM_ICALL
2081 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
2082 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
2083 info
->flags
, info
->isdn_driver
, info
->isdn_channel
,
2087 #ifndef FIX_FILE_TRANSFER
2088 (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
) &&
2090 (info
->isdn_driver
== -1) &&
2091 (info
->isdn_channel
== -1) &&
2092 (USG_NONE(dev
->usage
[idx
]))) {
2095 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
2097 if (!matchret
) { /* EAZ is matching */
2098 info
->isdn_driver
= di
;
2099 info
->isdn_channel
= ch
;
2100 info
->drv_index
= idx
;
2101 dev
->m_idx
[idx
] = info
->line
;
2102 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2103 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
2104 strcpy(dev
->num
[idx
], nr
);
2105 strcpy(info
->emu
.cpn
, eaz
);
2106 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
2107 info
->emu
.mdmreg
[REG_PLAN
] = setup
->plan
;
2108 info
->emu
.mdmreg
[REG_SCREEN
] = setup
->screen
;
2110 spin_unlock_irqrestore(&dev
->lock
, flags
);
2111 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2113 info
->msr
|= UART_MSR_RI
;
2114 isdn_tty_modem_result(RESULT_RING
, info
);
2115 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2121 spin_unlock_irqrestore(&dev
->lock
, flags
);
2122 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2123 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2))? "rejected" : "ignored");
2124 return (wret
== 2)?3:0;
2127 #define TTY_IS_ACTIVE(info) \
2128 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2131 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2139 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2140 info
= &dev
->mdm
.info
[mi
];
2141 switch (c
->command
) {
2142 case ISDN_STAT_CINF
:
2143 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2144 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2145 if (e
== (char *)c
->parm
.num
)
2146 info
->emu
.charge
= 0;
2149 case ISDN_STAT_BSENT
:
2150 #ifdef ISDN_TTY_STAT_DEBUG
2151 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2153 if ((info
->isdn_driver
== c
->driver
) &&
2154 (info
->isdn_channel
== c
->arg
)) {
2155 info
->msr
|= UART_MSR_CTS
;
2156 if (info
->send_outstanding
)
2157 if (!(--info
->send_outstanding
))
2158 info
->lsr
|= UART_LSR_TEMT
;
2159 isdn_tty_tint(info
);
2163 case ISDN_STAT_CAUSE
:
2164 #ifdef ISDN_TTY_STAT_DEBUG
2165 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2167 /* Signal cause to tty-device */
2168 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2170 case ISDN_STAT_DISPLAY
:
2171 #ifdef ISDN_TTY_STAT_DEBUG
2172 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2174 /* Signal display to tty-device */
2175 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2176 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2177 isdn_tty_at_cout("\r\n", info
);
2178 isdn_tty_at_cout("DISPLAY: ", info
);
2179 isdn_tty_at_cout(c
->parm
.display
, info
);
2180 isdn_tty_at_cout("\r\n", info
);
2183 case ISDN_STAT_DCONN
:
2184 #ifdef ISDN_TTY_STAT_DEBUG
2185 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2187 if (TTY_IS_ACTIVE(info
)) {
2188 if (info
->dialing
== 1) {
2194 case ISDN_STAT_DHUP
:
2195 #ifdef ISDN_TTY_STAT_DEBUG
2196 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2198 if (TTY_IS_ACTIVE(info
)) {
2199 if (info
->dialing
== 1)
2200 isdn_tty_modem_result(RESULT_BUSY
, info
);
2201 if (info
->dialing
> 1)
2202 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2204 #ifdef ISDN_DEBUG_MODEM_HUP
2205 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2207 isdn_tty_modem_hup(info
, 0);
2211 case ISDN_STAT_BCONN
:
2212 #ifdef ISDN_TTY_STAT_DEBUG
2213 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2215 /* Wake up any processes waiting
2216 * for incoming call of this device when
2217 * DCD follow the state of incoming carrier
2219 if (info
->blocked_open
&&
2220 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
)) {
2221 wake_up_interruptible(&info
->open_wait
);
2224 /* Schedule CONNECT-Message to any tty
2225 * waiting for it and
2226 * set DCD-bit of its modem-status.
2228 if (TTY_IS_ACTIVE(info
) ||
2229 (info
->blocked_open
&& (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
))) {
2230 info
->msr
|= UART_MSR_DCD
;
2231 info
->emu
.charge
= 0;
2232 if (info
->dialing
& 0xf)
2238 if (USG_MODEM(dev
->usage
[i
])) {
2239 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2240 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2241 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2243 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2245 if (USG_VOICE(dev
->usage
[i
]))
2246 isdn_tty_modem_result(RESULT_VCON
, info
);
2250 case ISDN_STAT_BHUP
:
2251 #ifdef ISDN_TTY_STAT_DEBUG
2252 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2254 if (TTY_IS_ACTIVE(info
)) {
2255 #ifdef ISDN_DEBUG_MODEM_HUP
2256 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2258 isdn_tty_modem_hup(info
, 0);
2262 case ISDN_STAT_NODCH
:
2263 #ifdef ISDN_TTY_STAT_DEBUG
2264 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2266 if (TTY_IS_ACTIVE(info
)) {
2267 if (info
->dialing
) {
2271 sprintf(info
->last_cause
, "0000");
2272 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2274 isdn_tty_modem_hup(info
, 0);
2278 case ISDN_STAT_UNLOAD
:
2279 #ifdef ISDN_TTY_STAT_DEBUG
2280 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2282 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2283 info
= &dev
->mdm
.info
[i
];
2284 if (info
->isdn_driver
== c
->driver
) {
2286 isdn_tty_modem_hup(info
, 1);
2290 #ifdef CONFIG_ISDN_TTY_FAX
2291 case ISDN_STAT_FAXIND
:
2292 if (TTY_IS_ACTIVE(info
)) {
2293 isdn_tty_fax_command(info
, c
);
2297 #ifdef CONFIG_ISDN_AUDIO
2298 case ISDN_STAT_AUDIO
:
2299 if (TTY_IS_ACTIVE(info
)) {
2300 switch(c
->parm
.num
[0]) {
2301 case ISDN_AUDIO_DTMF
:
2302 if (info
->vonline
) {
2303 isdn_audio_put_dle_code(info
,
2316 /*********************************************************************
2317 Modem-Emulator-Routines
2318 *********************************************************************/
2320 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2323 * Put a message from the AT-emulator into receive-buffer of tty,
2324 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2327 isdn_tty_at_cout(char *msg
, modem_info
* info
)
2329 struct tty_struct
*tty
;
2330 atemu
*m
= &info
->emu
;
2334 struct sk_buff
*skb
= NULL
;
2339 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2345 spin_lock_irqsave(&info
->readlock
, flags
);
2347 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!tty
)) {
2348 spin_unlock_irqrestore(&info
->readlock
, flags
);
2352 /* use queue instead of direct, if online and */
2353 /* data is in queue or buffer is full */
2354 if (info
->online
&& ((tty_buffer_request_room(tty
, l
) < l
) ||
2355 !skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
]))) {
2356 skb
= alloc_skb(l
, GFP_ATOMIC
);
2358 spin_unlock_irqrestore(&info
->readlock
, flags
);
2361 sp
= skb_put(skb
, l
);
2362 #ifdef CONFIG_ISDN_AUDIO
2363 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2364 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2368 for (p
= msg
; *p
; p
++) {
2371 c
= m
->mdmreg
[REG_CR
];
2374 c
= m
->mdmreg
[REG_LF
];
2377 c
= m
->mdmreg
[REG_BS
];
2385 if(tty_insert_flip_char(tty
, c
, TTY_NORMAL
) == 0)
2390 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2391 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2392 spin_unlock_irqrestore(&info
->readlock
, flags
);
2393 /* Schedule dequeuing */
2394 if (dev
->modempoll
&& info
->rcvsched
)
2395 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2398 spin_unlock_irqrestore(&info
->readlock
, flags
);
2399 tty_flip_buffer_push(tty
);
2404 * Perform ATH Hangup
2407 isdn_tty_on_hook(modem_info
* info
)
2409 if (info
->isdn_channel
>= 0) {
2410 #ifdef ISDN_DEBUG_MODEM_HUP
2411 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2413 isdn_tty_modem_hup(info
, 1);
2418 isdn_tty_off_hook(void)
2420 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2423 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2424 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2427 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2428 * isdn_tty_modem_escape() if sequence found.
2431 * p pointer to databuffer
2432 * plus escape-character
2433 * count length of buffer
2434 * pluscount count of valid escape-characters so far
2435 * lastplus timestamp of last character
2438 isdn_tty_check_esc(const u_char
* p
, u_char plus
, int count
, int *pluscount
,
2449 if (*(p
++) == plus
) {
2450 if ((*pluscount
)++) {
2451 /* Time since last '+' > 0.5 sec. ? */
2452 if (time_after(jiffies
, *lastplus
+ PLUSWAIT1
))
2455 /* Time since last non-'+' < 1.5 sec. ? */
2456 if (time_before(jiffies
, *lastplus
+ PLUSWAIT2
))
2459 if ((*pluscount
== 3) && (count
== 1))
2460 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2465 *lastplus
= jiffies
;
2471 * Return result of AT-emulator to tty-receive-buffer, depending on
2472 * modem-register 12, bit 0 and 1.
2473 * For CONNECT-messages also switch to online-mode.
2474 * For RING-message handle auto-ATA if register 0 != 0
2478 isdn_tty_modem_result(int code
, modem_info
* info
)
2480 atemu
*m
= &info
->emu
;
2481 static char *msg
[] =
2482 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2483 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2484 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2485 char s
[ISDN_MSNLEN
+10];
2489 m
->mdmreg
[REG_RINGCNT
]++;
2490 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2491 /* Automatically accept incoming call */
2492 isdn_tty_cmd_ATA(info
);
2494 case RESULT_NO_CARRIER
:
2495 #ifdef ISDN_DEBUG_MODEM_HUP
2496 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2497 (info
->flags
& ISDN_ASYNC_CLOSING
),
2500 m
->mdmreg
[REG_RINGCNT
] = 0;
2501 del_timer(&info
->nc_timer
);
2503 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2506 #ifdef CONFIG_ISDN_AUDIO
2507 if (info
->vonline
& 1) {
2508 #ifdef ISDN_DEBUG_MODEM_VOICE
2509 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
2512 /* voice-recording, add DLE-ETX */
2513 isdn_tty_at_cout("\020\003", info
);
2515 if (info
->vonline
& 2) {
2516 #ifdef ISDN_DEBUG_MODEM_VOICE
2517 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
2520 /* voice-playing, add DLE-DC4 */
2521 isdn_tty_at_cout("\020\024", info
);
2525 case RESULT_CONNECT
:
2526 case RESULT_CONNECT64000
:
2527 sprintf(info
->last_cause
, "0000");
2532 #ifdef ISDN_DEBUG_MODEM_VOICE
2533 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
2536 sprintf(info
->last_cause
, "0000");
2540 } /* switch(code) */
2542 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
2544 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
2545 /* Show numeric results only */
2546 sprintf(s
, "\r\n%d\r\n", code
);
2547 isdn_tty_at_cout(s
, info
);
2549 if (code
== RESULT_RING
) {
2550 /* return if "show RUNG" and ringcounter>1 */
2551 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
2552 (m
->mdmreg
[REG_RINGCNT
] > 1))
2554 /* print CID, _before_ _every_ ring */
2555 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
2556 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
2557 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2558 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2559 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2560 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2564 isdn_tty_at_cout("\r\n", info
);
2565 isdn_tty_at_cout(msg
[code
], info
);
2567 case RESULT_CONNECT
:
2568 switch (m
->mdmreg
[REG_L2PROT
]) {
2569 case ISDN_PROTO_L2_MODEM
:
2570 isdn_tty_at_cout(" ", info
);
2571 isdn_tty_at_cout(m
->connmsg
, info
);
2576 /* Append CPN, if enabled */
2577 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
2578 sprintf(s
, "/%s", m
->cpn
);
2579 isdn_tty_at_cout(s
, info
);
2581 /* Print CID only once, _after_ 1st RING */
2582 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
2583 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
2584 isdn_tty_at_cout("\r\n", info
);
2585 isdn_tty_at_cout("CALLER NUMBER: ", info
);
2586 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2587 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2588 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2589 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2593 case RESULT_NO_CARRIER
:
2594 case RESULT_NO_DIALTONE
:
2596 case RESULT_NO_ANSWER
:
2597 m
->mdmreg
[REG_RINGCNT
] = 0;
2598 /* Append Cause-Message if enabled */
2599 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
2600 sprintf(s
, "/%s", info
->last_cause
);
2601 isdn_tty_at_cout(s
, info
);
2604 case RESULT_CONNECT64000
:
2605 /* Append Protocol to CONNECT message */
2606 switch (m
->mdmreg
[REG_L2PROT
]) {
2607 case ISDN_PROTO_L2_X75I
:
2608 case ISDN_PROTO_L2_X75UI
:
2609 case ISDN_PROTO_L2_X75BUI
:
2610 isdn_tty_at_cout("/X.75", info
);
2612 case ISDN_PROTO_L2_HDLC
:
2613 isdn_tty_at_cout("/HDLC", info
);
2615 case ISDN_PROTO_L2_V11096
:
2616 isdn_tty_at_cout("/V110/9600", info
);
2618 case ISDN_PROTO_L2_V11019
:
2619 isdn_tty_at_cout("/V110/19200", info
);
2621 case ISDN_PROTO_L2_V11038
:
2622 isdn_tty_at_cout("/V110/38400", info
);
2625 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2626 isdn_tty_at_cout("/T.70", info
);
2627 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2628 isdn_tty_at_cout("+", info
);
2632 isdn_tty_at_cout("\r\n", info
);
2635 if (code
== RESULT_NO_CARRIER
) {
2636 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2639 if ((info
->flags
& ISDN_ASYNC_CHECK_CD
) &&
2640 (!((info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
2641 (info
->flags
& ISDN_ASYNC_CALLOUT_NOHUP
)))) {
2642 tty_hangup(info
->tty
);
2649 * Display a modem-register-value.
2652 isdn_tty_show_profile(int ridx
, modem_info
* info
)
2656 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
2657 isdn_tty_at_cout(v
, info
);
2661 * Get MSN-string from char-pointer, set pointer to end of number
2664 isdn_tty_get_msnstr(char *n
, char **p
)
2666 int limit
= ISDN_MSNLEN
- 1;
2668 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
2669 /* Why a comma ??? */
2670 (*p
[0] == ',') || (*p
[0] == ':')) &&
2677 * Get phone-number from modem-commandbuffer
2680 isdn_tty_getdial(char *p
, char *q
,int cnt
)
2683 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
2686 while (strchr(" 0123456789,#.*WPTSR-", *p
) && *p
&& --cnt
>0) {
2687 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
2688 ((*p
== 'R') && first
) ||
2689 (*p
== '*') || (*p
== '#')) {
2701 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2702 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2705 isdn_tty_report(modem_info
* info
)
2707 atemu
*m
= &info
->emu
;
2710 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
2711 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
2712 isdn_tty_at_cout(s
, info
);
2713 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
2714 isdn_tty_at_cout(s
, info
);
2715 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
2716 switch (info
->last_l2
) {
2717 case ISDN_PROTO_L2_X75I
:
2718 isdn_tty_at_cout("X.75i", info
);
2720 case ISDN_PROTO_L2_X75UI
:
2721 isdn_tty_at_cout("X.75ui", info
);
2723 case ISDN_PROTO_L2_X75BUI
:
2724 isdn_tty_at_cout("X.75bui", info
);
2726 case ISDN_PROTO_L2_HDLC
:
2727 isdn_tty_at_cout("HDLC", info
);
2729 case ISDN_PROTO_L2_V11096
:
2730 isdn_tty_at_cout("V.110 9600 Baud", info
);
2732 case ISDN_PROTO_L2_V11019
:
2733 isdn_tty_at_cout("V.110 19200 Baud", info
);
2735 case ISDN_PROTO_L2_V11038
:
2736 isdn_tty_at_cout("V.110 38400 Baud", info
);
2738 case ISDN_PROTO_L2_TRANS
:
2739 isdn_tty_at_cout("transparent", info
);
2741 case ISDN_PROTO_L2_MODEM
:
2742 isdn_tty_at_cout("modem", info
);
2744 case ISDN_PROTO_L2_FAX
:
2745 isdn_tty_at_cout("fax", info
);
2748 isdn_tty_at_cout("unknown", info
);
2751 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2752 isdn_tty_at_cout("/T.70", info
);
2753 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2754 isdn_tty_at_cout("+", info
);
2756 isdn_tty_at_cout("\r\n", info
);
2757 isdn_tty_at_cout(" Service: ", info
);
2758 switch (info
->last_si
) {
2760 isdn_tty_at_cout("audio\r\n", info
);
2763 isdn_tty_at_cout("btx\r\n", info
);
2766 isdn_tty_at_cout("data\r\n", info
);
2769 sprintf(s
, "%d\r\n", info
->last_si
);
2770 isdn_tty_at_cout(s
, info
);
2773 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
2774 isdn_tty_at_cout(s
, info
);
2775 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
2776 isdn_tty_at_cout(s
, info
);
2780 * Parse AT&.. commands.
2783 isdn_tty_cmd_ATand(char **p
, modem_info
* info
)
2785 atemu
*m
= &info
->emu
;
2789 #define MAXRB (sizeof(rb) - 1)
2793 /* &B - Set Buffersize */
2796 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
2798 #ifdef CONFIG_ISDN_AUDIO
2799 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
2802 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
2803 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2804 switch (m
->mdmreg
[REG_L2PROT
]) {
2805 case ISDN_PROTO_L2_V11096
:
2806 case ISDN_PROTO_L2_V11019
:
2807 case ISDN_PROTO_L2_V11038
:
2808 info
->xmit_size
/= 10;
2812 /* &C - DCD Status */
2814 switch (isdn_getnum(p
)) {
2816 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
2819 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
2826 /* &D - Set DTR-Low-behavior */
2828 switch (isdn_getnum(p
)) {
2830 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
2831 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2834 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2835 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2838 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2839 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
2846 /* &E -Set EAZ/MSN */
2848 isdn_tty_get_msnstr(m
->msn
, p
);
2851 /* &F -Set Factory-Defaults */
2853 if (info
->msr
& UART_MSR_DCD
)
2855 isdn_tty_reset_profile(m
);
2856 isdn_tty_modem_reset_regs(info
, 1);
2858 #ifdef DUMMY_HAYES_AT
2860 /* only for be compilant with common scripts */
2861 /* &K Flowcontrol - no function */
2867 /* &L -Set Numbers to listen on */
2870 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
2871 (i
< ISDN_LMSNLEN
- 1))
2872 m
->lmsn
[i
++] = *p
[0]++;
2876 /* &R - Set V.110 bitrate adaption */
2881 /* Switch off V.110, back to X.75 */
2882 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2883 m
->mdmreg
[REG_SI2
] = 0;
2884 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2887 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
2888 m
->mdmreg
[REG_SI2
] = 197;
2889 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2892 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
2893 m
->mdmreg
[REG_SI2
] = 199;
2894 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2897 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
2898 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
2899 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2904 /* Switch off T.70 */
2905 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2907 m
->mdmreg
[REG_SI1
] |= 4;
2910 /* &S - Set Windowsize */
2913 if ((i
> 0) && (i
< 9))
2914 m
->mdmreg
[REG_WSIZE
] = i
;
2919 /* &V - Show registers */
2921 isdn_tty_at_cout("\r\n", info
);
2922 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
2923 sprintf(rb
, "S%02d=%03d%s", i
,
2924 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
2925 isdn_tty_at_cout(rb
, info
);
2927 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
2928 strlen(m
->msn
) ? m
->msn
: "None");
2929 isdn_tty_at_cout(rb
, info
);
2930 if (strlen(m
->lmsn
)) {
2931 isdn_tty_at_cout("\r\nListen: ", info
);
2932 isdn_tty_at_cout(m
->lmsn
, info
);
2933 isdn_tty_at_cout("\r\n", info
);
2937 /* &W - Write Profile */
2942 modem_write_profile(m
);
2949 /* &X - Switch to BTX-Mode and T.70 */
2951 switch (isdn_getnum(p
)) {
2953 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2954 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2957 m
->mdmreg
[REG_T70
] |= BIT_T70
;
2958 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
2959 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2960 info
->xmit_size
= 112;
2961 m
->mdmreg
[REG_SI1
] = 4;
2962 m
->mdmreg
[REG_SI2
] = 0;
2965 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
2966 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2967 info
->xmit_size
= 112;
2968 m
->mdmreg
[REG_SI1
] = 4;
2969 m
->mdmreg
[REG_SI2
] = 0;
2982 isdn_tty_check_ats(int mreg
, int mval
, modem_info
* info
, atemu
* m
)
2984 /* Some plausibility checks */
2987 if (mval
> ISDN_PROTO_L2_MAX
)
2991 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
2993 #ifdef CONFIG_ISDN_AUDIO
2994 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
2997 info
->xmit_size
= mval
* 16;
2998 switch (m
->mdmreg
[REG_L2PROT
]) {
2999 case ISDN_PROTO_L2_V11096
:
3000 case ISDN_PROTO_L2_V11019
:
3001 case ISDN_PROTO_L2_V11038
:
3002 info
->xmit_size
/= 10;
3008 /* readonly registers */
3015 * Perform ATS command
3018 isdn_tty_cmd_ATS(char **p
, modem_info
* info
)
3020 atemu
*m
= &info
->emu
;
3026 mreg
= isdn_getnum(p
);
3027 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
3032 mval
= isdn_getnum(p
);
3033 if (mval
< 0 || mval
> 255)
3035 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3037 m
->mdmreg
[mreg
] = mval
;
3040 /* Set/Clear a single bit */
3042 bitpos
= isdn_getnum(p
);
3043 if ((bitpos
< 0) || (bitpos
> 7))
3048 bval
= isdn_getnum(p
);
3049 if (bval
< 0 || bval
> 1)
3052 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
3054 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
3055 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3057 m
->mdmreg
[mreg
] = mval
;
3061 isdn_tty_at_cout("\r\n", info
);
3062 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
3071 isdn_tty_show_profile(mreg
, info
);
3081 * Perform ATA command
3084 isdn_tty_cmd_ATA(modem_info
* info
)
3086 atemu
*m
= &info
->emu
;
3090 if (info
->msr
& UART_MSR_RI
) {
3091 /* Accept incoming call */
3093 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
3094 m
->mdmreg
[REG_RINGCNT
] = 0;
3095 info
->msr
&= ~UART_MSR_RI
;
3096 l2
= m
->mdmreg
[REG_L2PROT
];
3097 #ifdef CONFIG_ISDN_AUDIO
3098 /* If more than one bit set in reg18, autoselect Layer2 */
3099 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
3100 if (m
->mdmreg
[REG_SI1I
] == 1) {
3101 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
3102 l2
= ISDN_PROTO_L2_TRANS
;
3104 l2
= ISDN_PROTO_L2_X75I
;
3107 cmd
.driver
= info
->isdn_driver
;
3108 cmd
.command
= ISDN_CMD_SETL2
;
3109 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
3112 cmd
.driver
= info
->isdn_driver
;
3113 cmd
.command
= ISDN_CMD_SETL3
;
3114 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
3115 #ifdef CONFIG_ISDN_TTY_FAX
3116 if (l2
== ISDN_PROTO_L2_FAX
) {
3117 cmd
.parm
.fax
= info
->fax
;
3118 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3122 cmd
.driver
= info
->isdn_driver
;
3123 cmd
.arg
= info
->isdn_channel
;
3124 cmd
.command
= ISDN_CMD_ACCEPTD
;
3126 info
->emu
.carrierwait
= 0;
3128 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3130 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3133 #ifdef CONFIG_ISDN_AUDIO
3135 * Parse AT+F.. commands
3138 isdn_tty_cmd_PLUSF(char **p
, modem_info
* info
)
3140 atemu
*m
= &info
->emu
;
3143 if (!strncmp(p
[0], "CLASS", 5)) {
3148 sprintf(rs
, "\r\n%d",
3149 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3150 #ifdef CONFIG_ISDN_TTY_FAX
3151 if (TTY_IS_FCLASS2(info
))
3152 sprintf(rs
, "\r\n2");
3153 else if (TTY_IS_FCLASS1(info
))
3154 sprintf(rs
, "\r\n1");
3156 isdn_tty_at_cout(rs
, info
);
3163 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3164 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3165 m
->mdmreg
[REG_SI1
] = 4;
3167 m
->mdmreg
[REG_PSIZE
] * 16;
3169 #ifdef CONFIG_ISDN_TTY_FAX
3172 if (!(dev
->global_features
&
3173 ISDN_FEATURE_L3_FCLASS1
))
3175 m
->mdmreg
[REG_SI1
] = 1;
3176 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3177 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3179 m
->mdmreg
[REG_PSIZE
] * 16;
3183 if (!(dev
->global_features
&
3184 ISDN_FEATURE_L3_FCLASS2
))
3186 m
->mdmreg
[REG_SI1
] = 1;
3187 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3188 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3190 m
->mdmreg
[REG_PSIZE
] * 16;
3195 /* L2 will change on dialout with si=1 */
3196 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3197 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3198 m
->mdmreg
[REG_SI1
] = 5;
3199 info
->xmit_size
= VBUF
;
3203 strcpy(rs
, "\r\n0,");
3204 #ifdef CONFIG_ISDN_TTY_FAX
3205 if (dev
->global_features
&
3206 ISDN_FEATURE_L3_FCLASS1
)
3208 if (dev
->global_features
&
3209 ISDN_FEATURE_L3_FCLASS2
)
3213 isdn_tty_at_cout(rs
, info
);
3224 #ifdef CONFIG_ISDN_TTY_FAX
3225 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3232 * Parse AT+V.. commands
3235 isdn_tty_cmd_PLUSV(char **p
, modem_info
* info
)
3237 atemu
*m
= &info
->emu
;
3239 static char *vcmd
[] =
3240 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3248 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3256 /* AT+VNH - Auto hangup feature */
3260 isdn_tty_at_cout("\r\n1", info
);
3270 isdn_tty_at_cout("\r\n1", info
);
3281 /* AT+VIP - Reset all voice parameters */
3282 isdn_tty_modem_reset_vpar(m
);
3285 /* AT+VLS - Select device, accept incoming call */
3289 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3290 isdn_tty_at_cout(rs
, info
);
3305 isdn_tty_at_cout("\r\n0,2", info
);
3316 /* AT+VRX - Start recording */
3319 if (info
->online
!= 1) {
3320 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3323 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3324 if (!info
->dtmf_state
) {
3325 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3328 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3329 if (!info
->silence_state
) {
3330 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3333 if (m
->vpar
[3] < 5) {
3334 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3335 if (!info
->adpcmr
) {
3336 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3340 #ifdef ISDN_DEBUG_AT
3341 printk(KERN_DEBUG
"AT: +VRX\n");
3344 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3348 /* AT+VSD - Silence detection */
3352 sprintf(rs
, "\r\n<%d>,<%d>",
3355 isdn_tty_at_cout(rs
, info
);
3359 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3360 par1
= isdn_getnum(p
);
3361 if ((par1
< 0) || (par1
> 31))
3366 par2
= isdn_getnum(p
);
3367 if ((par2
< 0) || (par2
> 255))
3375 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3386 /* AT+VSM - Select compression */
3390 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3393 isdn_tty_at_cout(rs
, info
);
3403 par1
= isdn_getnum(p
);
3404 if ((par1
< 2) || (par1
> 6))
3410 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3412 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3414 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3416 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3418 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3430 /* AT+VTX - Start sending */
3433 if (info
->online
!= 1) {
3434 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3437 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3438 if (!info
->dtmf_state
) {
3439 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3442 if (m
->vpar
[3] < 5) {
3443 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3444 if (!info
->adpcms
) {
3445 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3449 #ifdef ISDN_DEBUG_AT
3450 printk(KERN_DEBUG
"AT: +VTX\n");
3454 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3458 /* AT+VDD - DTMF detection */
3462 sprintf(rs
, "\r\n<%d>,<%d>",
3465 isdn_tty_at_cout(rs
, info
);
3469 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3470 if (info
->online
!= 1)
3472 par1
= isdn_getnum(p
);
3473 if ((par1
< 0) || (par1
> 15))
3478 par2
= isdn_getnum(p
);
3479 if ((par2
< 0) || (par2
> 255))
3483 cmd
.driver
= info
->isdn_driver
;
3484 cmd
.command
= ISDN_CMD_AUDIO
;
3485 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3486 cmd
.parm
.num
[0] = par1
;
3487 cmd
.parm
.num
[1] = par2
;
3493 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3508 #endif /* CONFIG_ISDN_AUDIO */
3511 * Parse and perform an AT-command-line.
3514 isdn_tty_parse_at(modem_info
* info
)
3516 atemu
*m
= &info
->emu
;
3518 char ds
[ISDN_MSNLEN
];
3520 #ifdef ISDN_DEBUG_AT
3521 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
3523 for (p
= &m
->mdmcmd
[2]; *p
;) {
3529 /* A - Accept incoming call */
3531 isdn_tty_cmd_ATA(info
);
3536 if (info
->msr
& UART_MSR_DCD
)
3538 if (info
->msr
& UART_MSR_RI
) {
3539 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3542 isdn_tty_getdial(++p
, ds
, sizeof ds
);
3544 if (!strlen(m
->msn
))
3545 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
3546 else if (strlen(ds
))
3547 isdn_tty_dial(ds
, info
, m
);
3552 /* E - Turn Echo on/off */
3554 switch (isdn_getnum(&p
)) {
3556 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
3559 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
3566 /* H - On/Off-hook */
3571 isdn_tty_on_hook(info
);
3575 isdn_tty_off_hook();
3578 isdn_tty_on_hook(info
);
3583 /* I - Information */
3585 isdn_tty_at_cout("\r\nLinux ISDN", info
);
3593 isdn_tty_report(info
);
3597 snprintf(ds
, sizeof(ds
), "\r\n%d", info
->emu
.charge
);
3598 isdn_tty_at_cout(ds
, info
);
3603 #ifdef DUMMY_HAYES_AT
3606 /* only for be compilant with common scripts */
3615 if (info
->msr
& UART_MSR_DCD
)
3616 /* if B-Channel is up */
3617 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
:RESULT_CONNECT64000
, info
);
3619 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3622 /* Q - Turn Emulator messages on/off */
3624 switch (isdn_getnum(&p
)) {
3626 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
3629 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
3636 /* S - Set/Get Register */
3638 if (isdn_tty_cmd_ATS(&p
, info
))
3642 /* V - Numeric or ASCII Emulator-messages */
3644 switch (isdn_getnum(&p
)) {
3646 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
3649 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
3656 /* Z - Load Registers from Profile */
3658 if (info
->msr
& UART_MSR_DCD
) {
3660 isdn_tty_on_hook(info
);
3662 isdn_tty_modem_reset_regs(info
, 1);
3667 #ifdef CONFIG_ISDN_AUDIO
3670 if (isdn_tty_cmd_PLUSF(&p
, info
))
3674 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
3675 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
3678 if (isdn_tty_cmd_PLUSV(&p
, info
))
3681 #endif /* CONFIG_ISDN_AUDIO */
3682 case 'S': /* SUSPEND */
3684 isdn_tty_get_msnstr(ds
, &p
);
3685 isdn_tty_suspend(ds
, info
, m
);
3687 case 'R': /* RESUME */
3689 isdn_tty_get_msnstr(ds
, &p
);
3690 isdn_tty_resume(ds
, info
, m
);
3692 case 'M': /* MESSAGE */
3694 isdn_tty_send_msg(info
, m
, p
);
3702 if (isdn_tty_cmd_ATand(&p
, info
))
3709 #ifdef CONFIG_ISDN_AUDIO
3712 isdn_tty_modem_result(RESULT_OK
, info
);
3715 /* Need own toupper() because standard-toupper is not available
3718 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
3721 * Perform line-editing of AT-commands
3725 * count length of buffer
3726 * channel index to line (minor-device)
3729 isdn_tty_edit_at(const char *p
, int count
, modem_info
* info
)
3731 atemu
*m
= &info
->emu
;
3737 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
3740 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
3741 /* Separator (CR or LF) */
3742 m
->mdmcmd
[m
->mdmcmdl
] = 0;
3743 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3746 isdn_tty_at_cout(eb
, info
);
3748 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
3749 isdn_tty_parse_at(info
);
3753 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
3754 /* Backspace-Function */
3755 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
3758 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
3759 isdn_tty_at_cout("\b", info
);
3764 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3767 isdn_tty_at_cout(eb
, info
);
3769 if (m
->mdmcmdl
< 255) {
3771 switch (m
->mdmcmdl
) {
3774 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3775 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3779 /* Fall through, check for 'A' */
3782 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3783 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3787 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3788 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3797 * Switch all modem-channels who are online and got a valid
3798 * escape-sequence 1.5 seconds ago, to command-mode.
3799 * This function is called every second via timer-interrupt from within
3800 * timer-dispatcher isdn_timer_function()
3803 isdn_tty_modem_escape(void)
3809 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
3810 if (USG_MODEM(dev
->usage
[i
]))
3811 if ((midx
= dev
->m_idx
[i
]) >= 0) {
3812 modem_info
*info
= &dev
->mdm
.info
[midx
];
3815 if ((info
->emu
.pluscount
== 3) &&
3816 time_after(jiffies
, info
->emu
.lastplus
+ PLUSWAIT2
)) {
3817 info
->emu
.pluscount
= 0;
3819 isdn_tty_modem_result(RESULT_OK
, info
);
3823 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
3827 * Put a RING-message to all modem-channels who have the RI-bit set.
3828 * This function is called every second via timer-interrupt from within
3829 * timer-dispatcher isdn_timer_function()
3832 isdn_tty_modem_ring(void)
3837 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3838 modem_info
*info
= &dev
->mdm
.info
[i
];
3839 if (info
->msr
& UART_MSR_RI
) {
3841 isdn_tty_modem_result(RESULT_RING
, info
);
3844 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
3848 * For all online tty's, try sending data to
3852 isdn_tty_modem_xmit(void)
3857 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3858 modem_info
*info
= &dev
->mdm
.info
[i
];
3861 isdn_tty_senddown(info
);
3862 isdn_tty_tint(info
);
3865 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
3869 * Check all channels if we have a 'no carrier' timeout.
3870 * Timeout value is set by Register S7.
3873 isdn_tty_carrier_timeout(void)
3878 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3879 modem_info
*info
= &dev
->mdm
.info
[i
];
3880 if (info
->dialing
) {
3881 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
3883 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3884 isdn_tty_modem_hup(info
, 1);
3890 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);