2 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
4 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
5 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
11 #undef ISDN_TTY_STAT_DEBUG
13 #include <linux/isdn.h>
14 #include <linux/serial.h> /* ASYNC_* flags */
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/mutex.h>
18 #include "isdn_common.h"
20 #ifdef CONFIG_ISDN_AUDIO
21 #include "isdn_audio.h"
23 #define VBUFX (VBUF/16)
26 #define FIX_FILE_TRANSFER
27 #define DUMMY_HAYES_AT
31 static DEFINE_MUTEX(modem_info_mutex
);
32 static int isdn_tty_edit_at(const char *, int, modem_info
*);
33 static void isdn_tty_check_esc(const u_char
*, u_char
, int, int *, u_long
*);
34 static void isdn_tty_modem_reset_regs(modem_info
*, int);
35 static void isdn_tty_cmd_ATA(modem_info
*);
36 static void isdn_tty_flush_buffer(struct tty_struct
*);
37 static void isdn_tty_modem_result(int, modem_info
*);
38 #ifdef CONFIG_ISDN_AUDIO
39 static int isdn_tty_countDLE(unsigned char *, int);
42 /* Leave this unchanged unless you know what you do! */
43 #define MODEM_PARANOIA_CHECK
44 #define MODEM_DO_RESTART
46 static int bit2si
[8] =
47 {1, 5, 7, 7, 7, 7, 7, 7};
48 static int si2bit
[8] =
49 {4, 1, 4, 4, 4, 4, 4, 4};
51 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
52 * to stuff incoming data directly into a tty's flip-buffer. This
53 * is done to speed up tty-receiving if the receive-queue is empty.
54 * This routine MUST be called with interrupts off.
57 * 0 = Failure, data has to be buffered and later processed by
58 * isdn_tty_readmodem().
61 isdn_tty_try_read(modem_info
*info
, struct sk_buff
*skb
)
65 struct tty_struct
*tty
;
75 if (!(info
->mcr
& UART_MCR_RTS
))
79 #ifdef CONFIG_ISDN_AUDIO
80 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
84 c
= tty_buffer_request_room(tty
, len
);
88 #ifdef CONFIG_ISDN_AUDIO
89 if (ISDN_AUDIO_SKB_DLECOUNT(skb
)) {
91 unsigned char *dp
= skb
->data
;
94 tty_insert_flip_char(tty
, DLE
, 0);
95 tty_insert_flip_char(tty
, *dp
++, 0);
98 tty_insert_flip_char(tty
, DLE
, 0);
103 tty_insert_flip_string(tty
, skb
->data
, len
- 1);
104 last
= skb
->data
[len
- 1];
105 #ifdef CONFIG_ISDN_AUDIO
108 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
109 tty_insert_flip_char(tty
, last
, 0xFF);
111 tty_insert_flip_char(tty
, last
, TTY_NORMAL
);
112 tty_flip_buffer_push(tty
);
118 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
119 * It tries getting received data from the receive queue an stuff it into
120 * the tty's flip-buffer.
123 isdn_tty_readmodem(void)
129 struct tty_struct
*tty
;
132 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
133 midx
= dev
->m_idx
[i
];
137 info
= &dev
->mdm
.info
[midx
];
142 #ifdef CONFIG_ISDN_AUDIO
143 isdn_audio_eval_dtmf(info
);
144 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
145 isdn_audio_eval_silence(info
);
147 tty
= info
->port
.tty
;
149 if (info
->mcr
& UART_MCR_RTS
) {
150 /* CISCO AsyncPPP Hack */
151 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
152 r
= isdn_readbchan_tty(info
->isdn_driver
, info
->isdn_channel
, tty
, 0);
154 r
= isdn_readbchan_tty(info
->isdn_driver
, info
->isdn_channel
, tty
, 1);
156 tty_flip_buffer_push(tty
);
168 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
172 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
176 #ifdef CONFIG_ISDN_AUDIO
181 if ((midx
= dev
->m_idx
[i
]) < 0) {
182 /* if midx is invalid, packet is not for tty */
185 info
= &dev
->mdm
.info
[midx
];
186 #ifdef CONFIG_ISDN_AUDIO
189 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
190 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
191 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
192 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
194 if ((info
->online
< 2)
195 #ifdef CONFIG_ISDN_AUDIO
196 && (!(info
->vonline
& 1))
199 /* If Modem not listening, drop data */
203 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
204 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
205 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
206 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
209 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
212 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
213 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
216 #ifdef CONFIG_ISDN_AUDIO
217 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
218 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
219 if (info
->vonline
& 1) {
220 /* voice conversion/compression */
221 switch (info
->emu
.vpar
[3]) {
226 * Since compressed data takes less
227 * space, we can overwrite the buffer.
229 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
238 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
243 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
246 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
247 isdn_tty_countDLE(skb
->data
, skb
->len
);
249 #ifdef CONFIG_ISDN_TTY_FAX
251 if (info
->faxonline
& 2) {
252 isdn_tty_fax_bitorder(info
, skb
);
253 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
254 isdn_tty_countDLE(skb
->data
, skb
->len
);
259 /* Try to deliver directly via tty-buf if queue is empty */
260 spin_lock_irqsave(&info
->readlock
, flags
);
261 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
262 if (isdn_tty_try_read(info
, skb
)) {
263 spin_unlock_irqrestore(&info
->readlock
, flags
);
266 /* Direct deliver failed or queue wasn't empty.
267 * Queue up for later dequeueing via timer-irq.
269 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
270 dev
->drv
[di
]->rcvcount
[channel
] +=
272 #ifdef CONFIG_ISDN_AUDIO
273 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
276 spin_unlock_irqrestore(&info
->readlock
, flags
);
277 /* Schedule dequeuing */
278 if ((dev
->modempoll
) && (info
->rcvsched
))
279 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
284 isdn_tty_cleanup_xmit(modem_info
*info
)
286 skb_queue_purge(&info
->xmit_queue
);
287 #ifdef CONFIG_ISDN_AUDIO
288 skb_queue_purge(&info
->dtmf_queue
);
293 isdn_tty_tint(modem_info
*info
)
295 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
301 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
302 info
->isdn_channel
, 1, skb
)) == len
) {
303 struct tty_struct
*tty
= info
->port
.tty
;
304 info
->send_outstanding
++;
305 info
->msr
&= ~UART_MSR_CTS
;
306 info
->lsr
&= ~UART_LSR_TEMT
;
311 /* Error: no channel, already shutdown, or wrong parameter */
315 skb_queue_head(&info
->xmit_queue
, skb
);
318 #ifdef CONFIG_ISDN_AUDIO
320 isdn_tty_countDLE(unsigned char *buf
, int len
)
330 /* This routine is called from within isdn_tty_write() to perform
331 * DLE-decoding when sending audio-data.
334 isdn_tty_handleDLEdown(modem_info
*info
, atemu
*m
, int len
)
336 unsigned char *p
= &info
->port
.xmit_buf
[info
->xmit_count
];
346 memmove(p
, p
+ 1, len
- 1);
357 #ifdef ISDN_DEBUG_MODEM_VOICE
359 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
362 isdn_tty_at_cout("\020\003", info
);
363 if (!info
->vonline
) {
364 #ifdef ISDN_DEBUG_MODEM_VOICE
366 "DLEdown: send VCON on ttyI%d\n",
369 isdn_tty_at_cout("\r\nVCON\r\n", info
);
376 memmove(p
, p
+ 1, len
- 1);
390 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
396 /* This routine is called from within isdn_tty_write() when receiving
397 * audio-data. It interrupts receiving, if an character other than
401 isdn_tty_end_vrx(const char *buf
, int c
)
407 if ((ch
!= 0x11) && (ch
!= 0x13))
414 static int voice_cf
[7] =
415 {0, 0, 4, 3, 2, 0, 0};
417 #endif /* CONFIG_ISDN_AUDIO */
419 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
420 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
421 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
422 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
425 isdn_tty_senddown(modem_info
*info
)
429 #ifdef CONFIG_ISDN_AUDIO
434 #ifdef CONFIG_ISDN_AUDIO
435 if (info
->vonline
& 4) {
437 if (!info
->vonline
) {
438 #ifdef ISDN_DEBUG_MODEM_VOICE
440 "senddown: send VCON on ttyI%d\n",
443 isdn_tty_at_cout("\r\nVCON\r\n", info
);
447 if (!(buflen
= info
->xmit_count
))
449 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
450 info
->msr
&= ~UART_MSR_CTS
;
451 info
->lsr
&= ~UART_LSR_TEMT
;
452 /* info->xmit_count is modified here and in isdn_tty_write().
453 * So we return here if isdn_tty_write() is in the
456 atomic_inc(&info
->xmit_lock
);
457 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
459 if (info
->isdn_driver
< 0) {
460 info
->xmit_count
= 0;
463 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
464 #ifdef CONFIG_ISDN_AUDIO
465 if (info
->vonline
& 2)
466 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
469 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
471 skb
= dev_alloc_skb(skb_res
+ buflen
);
475 "isdn_tty: Out of memory in ttyI%d senddown\n",
479 skb_reserve(skb
, skb_res
);
480 memcpy(skb_put(skb
, buflen
), info
->port
.xmit_buf
, buflen
);
481 info
->xmit_count
= 0;
482 #ifdef CONFIG_ISDN_AUDIO
483 if (info
->vonline
& 2) {
484 /* For now, ifmt is fixed to 1 (alaw), since this
485 * is used with ISDN everywhere in the world, except
486 * US, Canada and Japan.
487 * Later, when US-ISDN protocols are implemented,
488 * this setting will depend on the D-channel protocol.
492 /* voice conversion/decompression */
493 switch (info
->emu
.vpar
[3]) {
497 /* adpcm, compatible to ZyXel 1496 modem
498 * with ROM revision 6.01
500 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
503 skb_put(skb
, audio_len
),
505 skb_pull(skb
, buflen
);
506 skb_trim(skb
, audio_len
);
511 isdn_audio_alaw2ulaw(skb
->data
,
517 isdn_audio_ulaw2alaw(skb
->data
,
522 #endif /* CONFIG_ISDN_AUDIO */
523 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
524 /* Add T.70 simplified header */
525 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
526 memcpy(skb_push(skb
, 2), "\1\0", 2);
528 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
530 skb_queue_tail(&info
->xmit_queue
, skb
);
533 /************************************************************
537 * mostly "stolen" from original Linux-serial.c and friends.
539 ************************************************************/
541 /* The next routine is called once from within timer-interrupt
542 * triggered within isdn_tty_modem_ncarrier(). It calls
543 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
544 * into the tty's buffer.
547 isdn_tty_modem_do_ncarrier(unsigned long data
)
549 modem_info
*info
= (modem_info
*) data
;
550 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
553 /* Next routine is called, whenever the DTR-signal is raised.
554 * It checks the ncarrier-flag, and triggers the above routine
555 * when necessary. The ncarrier-flag is set, whenever DTR goes
559 isdn_tty_modem_ncarrier(modem_info
*info
)
561 if (info
->ncarrier
) {
562 info
->nc_timer
.expires
= jiffies
+ HZ
;
563 add_timer(&info
->nc_timer
);
568 * return the usage calculated by si and layer 2 protocol
571 isdn_calc_usage(int si
, int l2
)
573 int usg
= ISDN_USAGE_MODEM
;
575 #ifdef CONFIG_ISDN_AUDIO
578 case ISDN_PROTO_L2_MODEM
:
579 usg
= ISDN_USAGE_MODEM
;
581 #ifdef CONFIG_ISDN_TTY_FAX
582 case ISDN_PROTO_L2_FAX
:
583 usg
= ISDN_USAGE_FAX
;
586 case ISDN_PROTO_L2_TRANS
:
588 usg
= ISDN_USAGE_VOICE
;
596 /* isdn_tty_dial() performs dialing of a tty an the necessary
597 * setup of the lower levels before that.
600 isdn_tty_dial(char *n
, modem_info
*info
, atemu
*m
)
602 int usg
= ISDN_USAGE_MODEM
;
604 int l2
= m
->mdmreg
[REG_L2PROT
];
610 for (j
= 7; j
>= 0; j
--)
611 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
615 usg
= isdn_calc_usage(si
, l2
);
616 #ifdef CONFIG_ISDN_AUDIO
618 (l2
!= ISDN_PROTO_L2_MODEM
)
619 #ifdef CONFIG_ISDN_TTY_FAX
620 && (l2
!= ISDN_PROTO_L2_FAX
)
623 l2
= ISDN_PROTO_L2_TRANS
;
624 usg
= ISDN_USAGE_VOICE
;
627 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
628 spin_lock_irqsave(&dev
->lock
, flags
);
629 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
631 spin_unlock_irqrestore(&dev
->lock
, flags
);
632 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
634 info
->isdn_driver
= dev
->drvmap
[i
];
635 info
->isdn_channel
= dev
->chanmap
[i
];
637 dev
->m_idx
[i
] = info
->line
;
638 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
640 strcpy(info
->last_num
, n
);
642 spin_unlock_irqrestore(&dev
->lock
, flags
);
643 cmd
.driver
= info
->isdn_driver
;
644 cmd
.arg
= info
->isdn_channel
;
645 cmd
.command
= ISDN_CMD_CLREAZ
;
647 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
648 cmd
.driver
= info
->isdn_driver
;
649 cmd
.command
= ISDN_CMD_SETEAZ
;
651 cmd
.driver
= info
->isdn_driver
;
652 cmd
.command
= ISDN_CMD_SETL2
;
654 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
656 cmd
.driver
= info
->isdn_driver
;
657 cmd
.command
= ISDN_CMD_SETL3
;
658 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
659 #ifdef CONFIG_ISDN_TTY_FAX
660 if (l2
== ISDN_PROTO_L2_FAX
) {
661 cmd
.parm
.fax
= info
->fax
;
662 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
666 cmd
.driver
= info
->isdn_driver
;
667 cmd
.arg
= info
->isdn_channel
;
668 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
669 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
670 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
671 cmd
.parm
.setup
.si1
= si
;
672 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
673 cmd
.command
= ISDN_CMD_DIAL
;
675 info
->emu
.carrierwait
= 0;
676 strcpy(dev
->num
[i
], n
);
679 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
683 /* isdn_tty_hangup() disassociates a tty from the real
684 * ISDN-line (hangup). The usage-status is cleared
685 * and some cleanup is done also.
688 isdn_tty_modem_hup(modem_info
*info
, int local
)
696 di
= info
->isdn_driver
;
697 ch
= info
->isdn_channel
;
698 if (di
< 0 || ch
< 0)
701 info
->isdn_driver
= -1;
702 info
->isdn_channel
= -1;
704 #ifdef ISDN_DEBUG_MODEM_HUP
705 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
708 isdn_tty_flush_buffer(info
->port
.tty
);
710 info
->last_lhup
= local
;
712 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
714 #ifdef CONFIG_ISDN_AUDIO
716 #ifdef CONFIG_ISDN_TTY_FAX
718 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
720 info
->emu
.vpar
[4] = 0;
721 info
->emu
.vpar
[5] = 8;
722 kfree(info
->dtmf_state
);
723 info
->dtmf_state
= NULL
;
724 kfree(info
->silence_state
);
725 info
->silence_state
= NULL
;
731 if ((info
->msr
& UART_MSR_RI
) &&
732 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
733 isdn_tty_modem_result(RESULT_RUNG
, info
);
734 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
735 info
->lsr
|= UART_LSR_TEMT
;
739 cmd
.command
= ISDN_CMD_HANGUP
;
744 isdn_all_eaz(di
, ch
);
745 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
746 isdn_free_channel(di
, ch
, 0);
748 if (info
->drv_index
>= 0) {
749 dev
->m_idx
[info
->drv_index
] = -1;
750 info
->drv_index
= -1;
755 * Begin of a CAPI like interface, currently used only for
756 * supplementary service (CAPI 2.0 part III)
758 #include <linux/isdn/capicmd.h>
759 #include <linux/module.h>
762 isdn_tty_capi_facility(capi_msg
*cm
) {
763 return (-1); /* dummy */
766 /* isdn_tty_suspend() tries to suspend the current tty connection
769 isdn_tty_suspend(char *id
, modem_info
*info
, atemu
*m
)
778 #ifdef ISDN_DEBUG_MODEM_SERVICES
779 printk(KERN_DEBUG
"Msusp ttyI%d\n", info
->line
);
782 if ((info
->isdn_driver
>= 0)) {
783 cmd
.parm
.cmsg
.Length
= l
+ 18;
784 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
785 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
786 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
787 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
788 cmd
.parm
.cmsg
.para
[1] = 0;
789 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
790 cmd
.parm
.cmsg
.para
[3] = 4; /* 16 bit 0x0004 Suspend */
791 cmd
.parm
.cmsg
.para
[4] = 0;
792 cmd
.parm
.cmsg
.para
[5] = l
;
793 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
794 cmd
.command
= CAPI_PUT_MESSAGE
;
795 cmd
.driver
= info
->isdn_driver
;
796 cmd
.arg
= info
->isdn_channel
;
801 /* isdn_tty_resume() tries to resume a suspended call
802 * setup of the lower levels before that. unfortunately here is no
803 * checking for compatibility of used protocols implemented by Q931
804 * It does the same things like isdn_tty_dial, the last command
805 * is different, may be we can merge it.
809 isdn_tty_resume(char *id
, modem_info
*info
, atemu
*m
)
811 int usg
= ISDN_USAGE_MODEM
;
813 int l2
= m
->mdmreg
[REG_L2PROT
];
821 for (j
= 7; j
>= 0; j
--)
822 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
826 usg
= isdn_calc_usage(si
, l2
);
827 #ifdef CONFIG_ISDN_AUDIO
829 (l2
!= ISDN_PROTO_L2_MODEM
)
830 #ifdef CONFIG_ISDN_TTY_FAX
831 && (l2
!= ISDN_PROTO_L2_FAX
)
834 l2
= ISDN_PROTO_L2_TRANS
;
835 usg
= ISDN_USAGE_VOICE
;
838 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
839 spin_lock_irqsave(&dev
->lock
, flags
);
840 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
842 spin_unlock_irqrestore(&dev
->lock
, flags
);
843 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
845 info
->isdn_driver
= dev
->drvmap
[i
];
846 info
->isdn_channel
= dev
->chanmap
[i
];
848 dev
->m_idx
[i
] = info
->line
;
849 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
851 // strcpy(info->last_num, n);
853 spin_unlock_irqrestore(&dev
->lock
, flags
);
854 cmd
.driver
= info
->isdn_driver
;
855 cmd
.arg
= info
->isdn_channel
;
856 cmd
.command
= ISDN_CMD_CLREAZ
;
858 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
859 cmd
.driver
= info
->isdn_driver
;
860 cmd
.command
= ISDN_CMD_SETEAZ
;
862 cmd
.driver
= info
->isdn_driver
;
863 cmd
.command
= ISDN_CMD_SETL2
;
865 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
867 cmd
.driver
= info
->isdn_driver
;
868 cmd
.command
= ISDN_CMD_SETL3
;
869 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
871 cmd
.driver
= info
->isdn_driver
;
872 cmd
.arg
= info
->isdn_channel
;
873 cmd
.parm
.cmsg
.Length
= l
+ 18;
874 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
875 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
876 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
877 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
878 cmd
.parm
.cmsg
.para
[1] = 0;
879 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
880 cmd
.parm
.cmsg
.para
[3] = 5; /* 16 bit 0x0005 Resume */
881 cmd
.parm
.cmsg
.para
[4] = 0;
882 cmd
.parm
.cmsg
.para
[5] = l
;
883 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
884 cmd
.command
= CAPI_PUT_MESSAGE
;
886 // strcpy(dev->num[i], n);
889 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
893 /* isdn_tty_send_msg() sends a message to a HL driver
894 * This is used for hybrid modem cards to send AT commands to it
898 isdn_tty_send_msg(modem_info
*info
, atemu
*m
, char *msg
)
900 int usg
= ISDN_USAGE_MODEM
;
902 int l2
= m
->mdmreg
[REG_L2PROT
];
911 isdn_tty_modem_result(RESULT_ERROR
, info
);
914 for (j
= 7; j
>= 0; j
--)
915 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
919 usg
= isdn_calc_usage(si
, l2
);
920 #ifdef CONFIG_ISDN_AUDIO
922 (l2
!= ISDN_PROTO_L2_MODEM
)
923 #ifdef CONFIG_ISDN_TTY_FAX
924 && (l2
!= ISDN_PROTO_L2_FAX
)
927 l2
= ISDN_PROTO_L2_TRANS
;
928 usg
= ISDN_USAGE_VOICE
;
931 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
932 spin_lock_irqsave(&dev
->lock
, flags
);
933 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
935 spin_unlock_irqrestore(&dev
->lock
, flags
);
936 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
938 info
->isdn_driver
= dev
->drvmap
[i
];
939 info
->isdn_channel
= dev
->chanmap
[i
];
941 dev
->m_idx
[i
] = info
->line
;
942 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
945 spin_unlock_irqrestore(&dev
->lock
, flags
);
946 cmd
.driver
= info
->isdn_driver
;
947 cmd
.arg
= info
->isdn_channel
;
948 cmd
.command
= ISDN_CMD_CLREAZ
;
950 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
951 cmd
.driver
= info
->isdn_driver
;
952 cmd
.command
= ISDN_CMD_SETEAZ
;
954 cmd
.driver
= info
->isdn_driver
;
955 cmd
.command
= ISDN_CMD_SETL2
;
957 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
959 cmd
.driver
= info
->isdn_driver
;
960 cmd
.command
= ISDN_CMD_SETL3
;
961 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
963 cmd
.driver
= info
->isdn_driver
;
964 cmd
.arg
= info
->isdn_channel
;
965 cmd
.parm
.cmsg
.Length
= l
+ 14;
966 cmd
.parm
.cmsg
.Command
= CAPI_MANUFACTURER
;
967 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
968 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
969 cmd
.parm
.cmsg
.para
[0] = l
+ 1;
970 strncpy(&cmd
.parm
.cmsg
.para
[1], msg
, l
);
971 cmd
.parm
.cmsg
.para
[l
+ 1] = 0xd;
972 cmd
.command
= CAPI_PUT_MESSAGE
;
973 /* info->dialing = 1;
974 strcpy(dev->num[i], n);
982 isdn_tty_paranoia_check(modem_info
*info
, char *name
, const char *routine
)
984 #ifdef MODEM_PARANOIA_CHECK
986 printk(KERN_WARNING
"isdn_tty: null info_struct for %s in %s\n",
990 if (info
->magic
!= ISDN_ASYNC_MAGIC
) {
991 printk(KERN_WARNING
"isdn_tty: bad magic for modem struct %s in %s\n",
1000 * This routine is called to set the UART divisor registers to match
1001 * the specified baud rate for a serial port.
1004 isdn_tty_change_speed(modem_info
*info
)
1006 struct tty_port
*port
= &info
->port
;
1014 cflag
= port
->tty
->termios
.c_cflag
;
1016 quot
= i
= cflag
& CBAUD
;
1020 port
->tty
->termios
.c_cflag
&= ~CBAUDEX
;
1025 info
->mcr
|= UART_MCR_DTR
;
1026 isdn_tty_modem_ncarrier(info
);
1028 info
->mcr
&= ~UART_MCR_DTR
;
1029 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1030 #ifdef ISDN_DEBUG_MODEM_HUP
1031 printk(KERN_DEBUG
"Mhup in changespeed\n");
1035 isdn_tty_modem_reset_regs(info
, 0);
1036 isdn_tty_modem_hup(info
, 1);
1040 /* byte size and parity */
1041 cval
= cflag
& (CSIZE
| CSTOPB
);
1044 cval
|= UART_LCR_PARITY
;
1045 if (!(cflag
& PARODD
))
1046 cval
|= UART_LCR_EPAR
;
1048 /* CTS flow control flag and modem status interrupts */
1049 if (cflag
& CRTSCTS
) {
1050 port
->flags
|= ASYNC_CTS_FLOW
;
1052 port
->flags
&= ~ASYNC_CTS_FLOW
;
1054 port
->flags
&= ~ASYNC_CHECK_CD
;
1056 port
->flags
|= ASYNC_CHECK_CD
;
1061 isdn_tty_startup(modem_info
*info
)
1063 if (info
->port
.flags
& ASYNC_INITIALIZED
)
1065 isdn_lock_drivers();
1066 #ifdef ISDN_DEBUG_MODEM_OPEN
1067 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1070 * Now, initialize the UART
1072 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1074 clear_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1076 * and set the speed of the serial port
1078 isdn_tty_change_speed(info
);
1080 info
->port
.flags
|= ASYNC_INITIALIZED
;
1081 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1082 info
->send_outstanding
= 0;
1087 * This routine will shutdown a serial port; interrupts are disabled, and
1088 * DTR is dropped if the hangup on close termio flag is on.
1091 isdn_tty_shutdown(modem_info
*info
)
1093 if (!(info
->port
.flags
& ASYNC_INITIALIZED
))
1095 #ifdef ISDN_DEBUG_MODEM_OPEN
1096 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1098 isdn_unlock_drivers();
1099 info
->msr
&= ~UART_MSR_RI
;
1100 if (!info
->port
.tty
|| (info
->port
.tty
->termios
.c_cflag
& HUPCL
)) {
1101 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1102 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1103 isdn_tty_modem_reset_regs(info
, 0);
1104 #ifdef ISDN_DEBUG_MODEM_HUP
1105 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1107 isdn_tty_modem_hup(info
, 1);
1111 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1113 info
->port
.flags
&= ~ASYNC_INITIALIZED
;
1116 /* isdn_tty_write() is the main send-routine. It is called from the upper
1117 * levels within the kernel to perform sending data. Depending on the
1118 * online-flag it either directs output to the at-command-interpreter or
1119 * to the lower level. Additional tasks done here:
1120 * - If online, check for escape-sequence (+++)
1121 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1122 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1123 * - If dialing, abort dial.
1126 isdn_tty_write(struct tty_struct
*tty
, const u_char
*buf
, int count
)
1130 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1131 atemu
*m
= &info
->emu
;
1133 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write"))
1135 /* See isdn_tty_senddown() */
1136 atomic_inc(&info
->xmit_lock
);
1139 if (c
> info
->xmit_size
- info
->xmit_count
)
1140 c
= info
->xmit_size
- info
->xmit_count
;
1141 if (info
->isdn_driver
>= 0 && c
> dev
->drv
[info
->isdn_driver
]->maxbufsize
)
1142 c
= dev
->drv
[info
->isdn_driver
]->maxbufsize
;
1145 if ((info
->online
> 1)
1146 #ifdef CONFIG_ISDN_AUDIO
1147 || (info
->vonline
& 3)
1150 #ifdef CONFIG_ISDN_AUDIO
1153 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1156 memcpy(&info
->port
.xmit_buf
[info
->xmit_count
], buf
, c
);
1157 #ifdef CONFIG_ISDN_AUDIO
1158 if (info
->vonline
) {
1159 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1160 if (info
->vonline
& 2) {
1162 /* If DLE decoding results in zero-transmit, but
1163 * c originally was non-zero, do a wakeup.
1166 info
->msr
|= UART_MSR_CTS
;
1167 info
->lsr
|= UART_LSR_TEMT
;
1169 info
->xmit_count
+= cc
;
1171 if ((info
->vonline
& 3) == 1) {
1172 /* Do NOT handle Ctrl-Q or Ctrl-S
1173 * when in full-duplex audio mode.
1175 if (isdn_tty_end_vrx(buf
, c
)) {
1176 info
->vonline
&= ~1;
1177 #ifdef ISDN_DEBUG_MODEM_VOICE
1179 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1182 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1186 if (TTY_IS_FCLASS1(info
)) {
1187 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1189 if (info
->vonline
& 4) { /* ETX seen */
1192 c
.command
= ISDN_CMD_FAXCMD
;
1193 c
.driver
= info
->isdn_driver
;
1194 c
.arg
= info
->isdn_channel
;
1195 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1196 c
.parm
.aux
.subcmd
= ETX
;
1200 #ifdef ISDN_DEBUG_MODEM_VOICE
1201 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
, c
);
1203 info
->xmit_count
+= cc
;
1206 info
->xmit_count
+= c
;
1208 info
->msr
|= UART_MSR_CTS
;
1209 info
->lsr
|= UART_LSR_TEMT
;
1210 if (info
->dialing
) {
1212 #ifdef ISDN_DEBUG_MODEM_HUP
1213 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1215 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1216 isdn_tty_modem_hup(info
, 1);
1218 c
= isdn_tty_edit_at(buf
, c
, info
);
1224 atomic_dec(&info
->xmit_lock
);
1225 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
)) {
1226 if (m
->mdmreg
[REG_DXMT
] & BIT_DXMT
) {
1227 isdn_tty_senddown(info
);
1228 isdn_tty_tint(info
);
1230 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1236 isdn_tty_write_room(struct tty_struct
*tty
)
1238 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1241 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write_room"))
1244 return info
->xmit_size
;
1245 ret
= info
->xmit_size
- info
->xmit_count
;
1246 return (ret
< 0) ? 0 : ret
;
1250 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1252 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1254 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_chars_in_buffer"))
1258 return (info
->xmit_count
);
1262 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1269 info
= (modem_info
*) tty
->driver_data
;
1270 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_buffer")) {
1273 isdn_tty_cleanup_xmit(info
);
1274 info
->xmit_count
= 0;
1279 isdn_tty_flush_chars(struct tty_struct
*tty
)
1281 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1283 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_chars"))
1285 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
))
1286 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1290 * ------------------------------------------------------------
1291 * isdn_tty_throttle()
1293 * This routine is called by the upper-layer tty layer to signal that
1294 * incoming characters should be throttled.
1295 * ------------------------------------------------------------
1298 isdn_tty_throttle(struct tty_struct
*tty
)
1300 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1302 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_throttle"))
1305 info
->x_char
= STOP_CHAR(tty
);
1306 info
->mcr
&= ~UART_MCR_RTS
;
1310 isdn_tty_unthrottle(struct tty_struct
*tty
)
1312 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1314 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_unthrottle"))
1320 info
->x_char
= START_CHAR(tty
);
1322 info
->mcr
|= UART_MCR_RTS
;
1326 * ------------------------------------------------------------
1327 * isdn_tty_ioctl() and friends
1328 * ------------------------------------------------------------
1332 * isdn_tty_get_lsr_info - get line status register info
1334 * Purpose: Let user call ioctl() to get info when the UART physically
1335 * is emptied. On bus types like RS485, the transmitter must
1336 * release the bus after transmitting. This must be done when
1337 * the transmit shift register is empty, not be done when the
1338 * transmit holding register is empty. This functionality
1339 * allows RS485 driver to be written in user space.
1342 isdn_tty_get_lsr_info(modem_info
*info
, uint __user
*value
)
1348 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1349 return put_user(result
, value
);
1354 isdn_tty_tiocmget(struct tty_struct
*tty
)
1356 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1357 u_char control
, status
;
1359 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1361 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1364 mutex_lock(&modem_info_mutex
);
1365 #ifdef ISDN_DEBUG_MODEM_IOCTL
1366 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1369 control
= info
->mcr
;
1371 mutex_unlock(&modem_info_mutex
);
1372 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1373 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1374 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1375 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1376 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1377 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1381 isdn_tty_tiocmset(struct tty_struct
*tty
,
1382 unsigned int set
, unsigned int clear
)
1384 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1386 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1388 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1391 #ifdef ISDN_DEBUG_MODEM_IOCTL
1392 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMxxx: %x %x\n", info
->line
, set
, clear
);
1395 mutex_lock(&modem_info_mutex
);
1396 if (set
& TIOCM_RTS
)
1397 info
->mcr
|= UART_MCR_RTS
;
1398 if (set
& TIOCM_DTR
) {
1399 info
->mcr
|= UART_MCR_DTR
;
1400 isdn_tty_modem_ncarrier(info
);
1403 if (clear
& TIOCM_RTS
)
1404 info
->mcr
&= ~UART_MCR_RTS
;
1405 if (clear
& TIOCM_DTR
) {
1406 info
->mcr
&= ~UART_MCR_DTR
;
1407 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1408 isdn_tty_modem_reset_regs(info
, 0);
1409 #ifdef ISDN_DEBUG_MODEM_HUP
1410 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1414 isdn_tty_modem_hup(info
, 1);
1417 mutex_unlock(&modem_info_mutex
);
1422 isdn_tty_ioctl(struct tty_struct
*tty
, uint cmd
, ulong arg
)
1424 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1427 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_ioctl"))
1429 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1432 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1433 #ifdef ISDN_DEBUG_MODEM_IOCTL
1434 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1436 retval
= tty_check_change(tty
);
1439 tty_wait_until_sent(tty
, 0);
1441 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1442 #ifdef ISDN_DEBUG_MODEM_IOCTL
1443 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1445 retval
= tty_check_change(tty
);
1448 tty_wait_until_sent(tty
, 0);
1450 case TIOCSERGETLSR
: /* Get line status register */
1451 #ifdef ISDN_DEBUG_MODEM_IOCTL
1452 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1454 return isdn_tty_get_lsr_info(info
, (uint __user
*) arg
);
1456 #ifdef ISDN_DEBUG_MODEM_IOCTL
1457 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1459 return -ENOIOCTLCMD
;
1465 isdn_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
1467 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1470 isdn_tty_change_speed(info
);
1472 if (tty
->termios
.c_cflag
== old_termios
->c_cflag
&&
1473 tty
->termios
.c_ispeed
== old_termios
->c_ispeed
&&
1474 tty
->termios
.c_ospeed
== old_termios
->c_ospeed
)
1476 isdn_tty_change_speed(info
);
1477 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1478 !(tty
->termios
.c_cflag
& CRTSCTS
))
1479 tty
->hw_stopped
= 0;
1484 * ------------------------------------------------------------
1485 * isdn_tty_open() and friends
1486 * ------------------------------------------------------------
1489 static int isdn_tty_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
1491 modem_info
*info
= &dev
->mdm
.info
[tty
->index
];
1493 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1496 tty
->driver_data
= info
;
1498 return tty_port_install(&info
->port
, driver
, tty
);
1502 * This routine is called whenever a serial port is opened. It
1503 * enables interrupts for a serial port, linking in its async structure into
1504 * the IRQ chain. It also performs the serial-specific
1505 * initialization for the tty structure.
1508 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
1510 modem_info
*info
= tty
->driver_data
;
1511 struct tty_port
*port
= &info
->port
;
1514 #ifdef ISDN_DEBUG_MODEM_OPEN
1515 printk(KERN_DEBUG
"isdn_tty_open %s, count = %d\n", tty
->name
,
1521 * Start up serial port
1523 retval
= isdn_tty_startup(info
);
1525 #ifdef ISDN_DEBUG_MODEM_OPEN
1526 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
1530 retval
= tty_port_block_til_ready(port
, tty
, filp
);
1532 #ifdef ISDN_DEBUG_MODEM_OPEN
1533 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
1537 #ifdef ISDN_DEBUG_MODEM_OPEN
1538 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
1541 #ifdef ISDN_DEBUG_MODEM_OPEN
1542 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
1548 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
1550 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1551 struct tty_port
*port
= &info
->port
;
1554 if (!info
|| isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_close"))
1556 if (tty_hung_up_p(filp
)) {
1557 #ifdef ISDN_DEBUG_MODEM_OPEN
1558 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
1562 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1564 * Uh, oh. tty->count is 1, which means that the tty
1565 * structure will be freed. Info->count should always
1566 * be one in these conditions. If it's greater than
1567 * one, we've got real problems, since it means the
1568 * serial port won't be shutdown.
1570 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
1571 "info->count is %d\n", port
->count
);
1574 if (--port
->count
< 0) {
1575 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
1576 info
->line
, port
->count
);
1580 #ifdef ISDN_DEBUG_MODEM_OPEN
1581 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
1585 port
->flags
|= ASYNC_CLOSING
;
1589 * At this point we stop accepting input. To do this, we
1590 * disable the receive line status interrupts, and tell the
1591 * interrupt driver to stop checking the data ready bit in the
1592 * line status register.
1594 if (port
->flags
& ASYNC_INITIALIZED
) {
1595 tty_wait_until_sent_from_close(tty
, 3000); /* 30 seconds timeout */
1597 * Before we drop DTR, make sure the UART transmitter
1598 * has completely drained; this is especially
1599 * important if there is a transmit FIFO!
1601 timeout
= jiffies
+ HZ
;
1602 while (!(info
->lsr
& UART_LSR_TEMT
)) {
1603 schedule_timeout_interruptible(20);
1604 if (time_after(jiffies
, timeout
))
1609 isdn_tty_shutdown(info
);
1610 isdn_tty_flush_buffer(tty
);
1611 tty_ldisc_flush(tty
);
1615 tty_port_close_end(port
, tty
);
1616 #ifdef ISDN_DEBUG_MODEM_OPEN
1617 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
1622 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1625 isdn_tty_hangup(struct tty_struct
*tty
)
1627 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1628 struct tty_port
*port
= &info
->port
;
1630 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_hangup"))
1632 isdn_tty_shutdown(info
);
1634 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1636 wake_up_interruptible(&port
->open_wait
);
1639 /* This routine initializes all emulator-data.
1642 isdn_tty_reset_profile(atemu
*m
)
1655 m
->profile
[11] = 70;
1656 m
->profile
[12] = 0x45;
1658 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
1659 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
1660 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
1661 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
1670 #ifdef CONFIG_ISDN_AUDIO
1672 isdn_tty_modem_reset_vpar(atemu
*m
)
1674 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
1675 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
1676 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
1677 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1678 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
1679 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1683 #ifdef CONFIG_ISDN_TTY_FAX
1685 isdn_tty_modem_reset_faxpar(modem_info
*info
)
1687 T30_s
*f
= info
->fax
;
1690 f
->phase
= ISDN_FAX_PHASE_IDLE
;
1692 f
->resolution
= 1; /* fine */
1693 f
->rate
= 5; /* 14400 bit/s */
1700 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
1701 f
->id
[FAXIDLEN
- 1] = 0;
1712 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
1713 f
->pollid
[FAXIDLEN
- 1] = 0;
1718 isdn_tty_modem_reset_regs(modem_info
*info
, int force
)
1720 atemu
*m
= &info
->emu
;
1721 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
1722 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
1723 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
1724 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
1725 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
1727 #ifdef CONFIG_ISDN_AUDIO
1728 isdn_tty_modem_reset_vpar(m
);
1730 #ifdef CONFIG_ISDN_TTY_FAX
1731 isdn_tty_modem_reset_faxpar(info
);
1737 modem_write_profile(atemu
*m
)
1739 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
1740 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
1741 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
1743 send_sig(SIGIO
, dev
->profd
, 1);
1746 static const struct tty_operations modem_ops
= {
1747 .install
= isdn_tty_install
,
1748 .open
= isdn_tty_open
,
1749 .close
= isdn_tty_close
,
1750 .write
= isdn_tty_write
,
1751 .flush_chars
= isdn_tty_flush_chars
,
1752 .write_room
= isdn_tty_write_room
,
1753 .chars_in_buffer
= isdn_tty_chars_in_buffer
,
1754 .flush_buffer
= isdn_tty_flush_buffer
,
1755 .ioctl
= isdn_tty_ioctl
,
1756 .throttle
= isdn_tty_throttle
,
1757 .unthrottle
= isdn_tty_unthrottle
,
1758 .set_termios
= isdn_tty_set_termios
,
1759 .hangup
= isdn_tty_hangup
,
1760 .tiocmget
= isdn_tty_tiocmget
,
1761 .tiocmset
= isdn_tty_tiocmset
,
1764 static int isdn_tty_carrier_raised(struct tty_port
*port
)
1766 modem_info
*info
= container_of(port
, modem_info
, port
);
1767 return info
->msr
& UART_MSR_DCD
;
1770 static const struct tty_port_operations isdn_tty_port_ops
= {
1771 .carrier_raised
= isdn_tty_carrier_raised
,
1775 isdn_tty_modem_init(void)
1782 m
->tty_modem
= alloc_tty_driver(ISDN_MAX_CHANNELS
);
1785 m
->tty_modem
->name
= "ttyI";
1786 m
->tty_modem
->major
= ISDN_TTY_MAJOR
;
1787 m
->tty_modem
->minor_start
= 0;
1788 m
->tty_modem
->type
= TTY_DRIVER_TYPE_SERIAL
;
1789 m
->tty_modem
->subtype
= SERIAL_TYPE_NORMAL
;
1790 m
->tty_modem
->init_termios
= tty_std_termios
;
1791 m
->tty_modem
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1792 m
->tty_modem
->flags
= TTY_DRIVER_REAL_RAW
;
1793 m
->tty_modem
->driver_name
= "isdn_tty";
1794 tty_set_operations(m
->tty_modem
, &modem_ops
);
1795 retval
= tty_register_driver(m
->tty_modem
);
1797 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
1800 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1802 #ifdef CONFIG_ISDN_TTY_FAX
1803 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
1804 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
1806 goto err_unregister
;
1809 tty_port_init(&info
->port
);
1810 info
->port
.ops
= &isdn_tty_port_ops
;
1811 spin_lock_init(&info
->readlock
);
1812 sprintf(info
->last_cause
, "0000");
1813 sprintf(info
->last_num
, "none");
1815 info
->last_lhup
= 1;
1818 isdn_tty_reset_profile(&info
->emu
);
1819 isdn_tty_modem_reset_regs(info
, 1);
1820 info
->magic
= ISDN_ASYNC_MAGIC
;
1823 info
->isdn_driver
= -1;
1824 info
->isdn_channel
= -1;
1825 info
->drv_index
= -1;
1826 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
1827 init_timer(&info
->nc_timer
);
1828 info
->nc_timer
.function
= isdn_tty_modem_do_ncarrier
;
1829 info
->nc_timer
.data
= (unsigned long) info
;
1830 skb_queue_head_init(&info
->xmit_queue
);
1831 #ifdef CONFIG_ISDN_AUDIO
1832 skb_queue_head_init(&info
->dtmf_queue
);
1834 info
->port
.xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5,
1836 if (!info
->port
.xmit_buf
) {
1837 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
1839 goto err_unregister
;
1841 /* Make room for T.70 header */
1842 info
->port
.xmit_buf
+= 4;
1846 for (i
--; i
>= 0; i
--) {
1848 #ifdef CONFIG_ISDN_TTY_FAX
1851 kfree(info
->port
.xmit_buf
- 4);
1853 tty_unregister_driver(m
->tty_modem
);
1855 put_tty_driver(m
->tty_modem
);
1856 m
->tty_modem
= NULL
;
1866 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1867 info
= &dev
->mdm
.info
[i
];
1868 isdn_tty_cleanup_xmit(info
);
1869 #ifdef CONFIG_ISDN_TTY_FAX
1872 kfree(info
->port
.xmit_buf
- 4);
1874 tty_unregister_driver(dev
->mdm
.tty_modem
);
1875 put_tty_driver(dev
->mdm
.tty_modem
);
1876 dev
->mdm
.tty_modem
= NULL
;
1881 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
1882 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
1883 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
1887 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
1889 #ifdef ISDN_DEBUG_MODEM_ICALL
1890 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
1891 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
1892 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
1894 if (strlen(emu
->lmsn
)) {
1895 char *p
= emu
->lmsn
;
1901 if ((q
= strchr(p
, ';')))
1903 if ((tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
1905 #ifdef ISDN_DEBUG_MODEM_ICALL
1906 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
1907 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
1922 tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
1923 #ifdef ISDN_DEBUG_MODEM_ICALL
1924 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
1925 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
1932 * An incoming call-request has arrived.
1933 * Search the tty-devices for an appropriate device and bind
1934 * it to the ISDN-Channel.
1937 * 0 = No matching device found.
1938 * 1 = A matching device found.
1939 * 3 = No match found, but eventually would match, if
1943 isdn_tty_find_icall(int di
, int ch
, setup_parm
*setup
)
1954 if (!setup
->phone
[0]) {
1956 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
1959 si1
= (int) setup
->si1
;
1960 si2
= (int) setup
->si2
;
1961 if (!setup
->eazmsn
[0]) {
1962 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
1965 eaz
= setup
->eazmsn
;
1966 #ifdef ISDN_DEBUG_MODEM_ICALL
1967 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
1970 spin_lock_irqsave(&dev
->lock
, flags
);
1971 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1972 modem_info
*info
= &dev
->mdm
.info
[i
];
1974 if (info
->port
.count
== 0)
1976 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
1977 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
1978 idx
= isdn_dc2minor(di
, ch
);
1979 #ifdef ISDN_DEBUG_MODEM_ICALL
1980 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
1981 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
1982 info
->port
.flags
, info
->isdn_driver
,
1983 info
->isdn_channel
, dev
->usage
[idx
]);
1986 #ifndef FIX_FILE_TRANSFER
1987 (info
->port
.flags
& ASYNC_NORMAL_ACTIVE
) &&
1989 (info
->isdn_driver
== -1) &&
1990 (info
->isdn_channel
== -1) &&
1991 (USG_NONE(dev
->usage
[idx
]))) {
1994 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
1996 if (!matchret
) { /* EAZ is matching */
1997 info
->isdn_driver
= di
;
1998 info
->isdn_channel
= ch
;
1999 info
->drv_index
= idx
;
2000 dev
->m_idx
[idx
] = info
->line
;
2001 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2002 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
2003 strcpy(dev
->num
[idx
], nr
);
2004 strcpy(info
->emu
.cpn
, eaz
);
2005 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
2006 info
->emu
.mdmreg
[REG_PLAN
] = setup
->plan
;
2007 info
->emu
.mdmreg
[REG_SCREEN
] = setup
->screen
;
2009 spin_unlock_irqrestore(&dev
->lock
, flags
);
2010 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2012 info
->msr
|= UART_MSR_RI
;
2013 isdn_tty_modem_result(RESULT_RING
, info
);
2014 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2020 spin_unlock_irqrestore(&dev
->lock
, flags
);
2021 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2022 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2)) ? "rejected" : "ignored");
2023 return (wret
== 2) ? 3 : 0;
2026 #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE)
2029 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2037 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2038 info
= &dev
->mdm
.info
[mi
];
2039 switch (c
->command
) {
2040 case ISDN_STAT_CINF
:
2041 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2042 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2043 if (e
== (char *)c
->parm
.num
)
2044 info
->emu
.charge
= 0;
2047 case ISDN_STAT_BSENT
:
2048 #ifdef ISDN_TTY_STAT_DEBUG
2049 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2051 if ((info
->isdn_driver
== c
->driver
) &&
2052 (info
->isdn_channel
== c
->arg
)) {
2053 info
->msr
|= UART_MSR_CTS
;
2054 if (info
->send_outstanding
)
2055 if (!(--info
->send_outstanding
))
2056 info
->lsr
|= UART_LSR_TEMT
;
2057 isdn_tty_tint(info
);
2061 case ISDN_STAT_CAUSE
:
2062 #ifdef ISDN_TTY_STAT_DEBUG
2063 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2065 /* Signal cause to tty-device */
2066 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2068 case ISDN_STAT_DISPLAY
:
2069 #ifdef ISDN_TTY_STAT_DEBUG
2070 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2072 /* Signal display to tty-device */
2073 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2074 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2075 isdn_tty_at_cout("\r\n", info
);
2076 isdn_tty_at_cout("DISPLAY: ", info
);
2077 isdn_tty_at_cout(c
->parm
.display
, info
);
2078 isdn_tty_at_cout("\r\n", info
);
2081 case ISDN_STAT_DCONN
:
2082 #ifdef ISDN_TTY_STAT_DEBUG
2083 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2085 if (TTY_IS_ACTIVE(info
)) {
2086 if (info
->dialing
== 1) {
2092 case ISDN_STAT_DHUP
:
2093 #ifdef ISDN_TTY_STAT_DEBUG
2094 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2096 if (TTY_IS_ACTIVE(info
)) {
2097 if (info
->dialing
== 1)
2098 isdn_tty_modem_result(RESULT_BUSY
, info
);
2099 if (info
->dialing
> 1)
2100 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2102 #ifdef ISDN_DEBUG_MODEM_HUP
2103 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2105 isdn_tty_modem_hup(info
, 0);
2109 case ISDN_STAT_BCONN
:
2110 #ifdef ISDN_TTY_STAT_DEBUG
2111 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2113 /* Wake up any processes waiting
2114 * for incoming call of this device when
2115 * DCD follow the state of incoming carrier
2117 if (info
->port
.blocked_open
&&
2118 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
)) {
2119 wake_up_interruptible(&info
->port
.open_wait
);
2122 /* Schedule CONNECT-Message to any tty
2123 * waiting for it and
2124 * set DCD-bit of its modem-status.
2126 if (TTY_IS_ACTIVE(info
) ||
2127 (info
->port
.blocked_open
&&
2128 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
))) {
2129 info
->msr
|= UART_MSR_DCD
;
2130 info
->emu
.charge
= 0;
2131 if (info
->dialing
& 0xf)
2137 if (USG_MODEM(dev
->usage
[i
])) {
2138 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2139 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2140 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2142 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2144 if (USG_VOICE(dev
->usage
[i
]))
2145 isdn_tty_modem_result(RESULT_VCON
, info
);
2149 case ISDN_STAT_BHUP
:
2150 #ifdef ISDN_TTY_STAT_DEBUG
2151 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2153 if (TTY_IS_ACTIVE(info
)) {
2154 #ifdef ISDN_DEBUG_MODEM_HUP
2155 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2157 isdn_tty_modem_hup(info
, 0);
2161 case ISDN_STAT_NODCH
:
2162 #ifdef ISDN_TTY_STAT_DEBUG
2163 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2165 if (TTY_IS_ACTIVE(info
)) {
2166 if (info
->dialing
) {
2170 sprintf(info
->last_cause
, "0000");
2171 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2173 isdn_tty_modem_hup(info
, 0);
2177 case ISDN_STAT_UNLOAD
:
2178 #ifdef ISDN_TTY_STAT_DEBUG
2179 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2181 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2182 info
= &dev
->mdm
.info
[i
];
2183 if (info
->isdn_driver
== c
->driver
) {
2185 isdn_tty_modem_hup(info
, 1);
2189 #ifdef CONFIG_ISDN_TTY_FAX
2190 case ISDN_STAT_FAXIND
:
2191 if (TTY_IS_ACTIVE(info
)) {
2192 isdn_tty_fax_command(info
, c
);
2196 #ifdef CONFIG_ISDN_AUDIO
2197 case ISDN_STAT_AUDIO
:
2198 if (TTY_IS_ACTIVE(info
)) {
2199 switch (c
->parm
.num
[0]) {
2200 case ISDN_AUDIO_DTMF
:
2201 if (info
->vonline
) {
2202 isdn_audio_put_dle_code(info
,
2215 /*********************************************************************
2216 Modem-Emulator-Routines
2217 *********************************************************************/
2219 #define cmdchar(c) ((c >= ' ') && (c <= 0x7f))
2222 * Put a message from the AT-emulator into receive-buffer of tty,
2223 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2226 isdn_tty_at_cout(char *msg
, modem_info
*info
)
2228 struct tty_struct
*tty
;
2229 atemu
*m
= &info
->emu
;
2233 struct sk_buff
*skb
= NULL
;
2238 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2244 spin_lock_irqsave(&info
->readlock
, flags
);
2245 tty
= info
->port
.tty
;
2246 if ((info
->port
.flags
& ASYNC_CLOSING
) || (!tty
)) {
2247 spin_unlock_irqrestore(&info
->readlock
, flags
);
2251 /* use queue instead of direct, if online and */
2252 /* data is in queue or buffer is full */
2253 if (info
->online
&& ((tty_buffer_request_room(tty
, l
) < l
) ||
2254 !skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
]))) {
2255 skb
= alloc_skb(l
, GFP_ATOMIC
);
2257 spin_unlock_irqrestore(&info
->readlock
, flags
);
2260 sp
= skb_put(skb
, l
);
2261 #ifdef CONFIG_ISDN_AUDIO
2262 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2263 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2267 for (p
= msg
; *p
; p
++) {
2270 c
= m
->mdmreg
[REG_CR
];
2273 c
= m
->mdmreg
[REG_LF
];
2276 c
= m
->mdmreg
[REG_BS
];
2284 if (tty_insert_flip_char(tty
, c
, TTY_NORMAL
) == 0)
2289 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2290 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2291 spin_unlock_irqrestore(&info
->readlock
, flags
);
2292 /* Schedule dequeuing */
2293 if (dev
->modempoll
&& info
->rcvsched
)
2294 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2297 spin_unlock_irqrestore(&info
->readlock
, flags
);
2298 tty_flip_buffer_push(tty
);
2303 * Perform ATH Hangup
2306 isdn_tty_on_hook(modem_info
*info
)
2308 if (info
->isdn_channel
>= 0) {
2309 #ifdef ISDN_DEBUG_MODEM_HUP
2310 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2312 isdn_tty_modem_hup(info
, 1);
2317 isdn_tty_off_hook(void)
2319 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2322 #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */
2323 #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */
2326 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2327 * isdn_tty_modem_escape() if sequence found.
2330 * p pointer to databuffer
2331 * plus escape-character
2332 * count length of buffer
2333 * pluscount count of valid escape-characters so far
2334 * lastplus timestamp of last character
2337 isdn_tty_check_esc(const u_char
*p
, u_char plus
, int count
, int *pluscount
,
2348 if (*(p
++) == plus
) {
2349 if ((*pluscount
)++) {
2350 /* Time since last '+' > 0.5 sec. ? */
2351 if (time_after(jiffies
, *lastplus
+ PLUSWAIT1
))
2354 /* Time since last non-'+' < 1.5 sec. ? */
2355 if (time_before(jiffies
, *lastplus
+ PLUSWAIT2
))
2358 if ((*pluscount
== 3) && (count
== 1))
2359 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2364 *lastplus
= jiffies
;
2370 * Return result of AT-emulator to tty-receive-buffer, depending on
2371 * modem-register 12, bit 0 and 1.
2372 * For CONNECT-messages also switch to online-mode.
2373 * For RING-message handle auto-ATA if register 0 != 0
2377 isdn_tty_modem_result(int code
, modem_info
*info
)
2379 atemu
*m
= &info
->emu
;
2380 static char *msg
[] =
2381 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2382 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2383 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2384 char s
[ISDN_MSNLEN
+ 10];
2388 m
->mdmreg
[REG_RINGCNT
]++;
2389 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2390 /* Automatically accept incoming call */
2391 isdn_tty_cmd_ATA(info
);
2393 case RESULT_NO_CARRIER
:
2394 #ifdef ISDN_DEBUG_MODEM_HUP
2395 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2396 (info
->port
.flags
& ASYNC_CLOSING
),
2399 m
->mdmreg
[REG_RINGCNT
] = 0;
2400 del_timer(&info
->nc_timer
);
2402 if ((info
->port
.flags
& ASYNC_CLOSING
) || (!info
->port
.tty
))
2405 #ifdef CONFIG_ISDN_AUDIO
2406 if (info
->vonline
& 1) {
2407 #ifdef ISDN_DEBUG_MODEM_VOICE
2408 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
2411 /* voice-recording, add DLE-ETX */
2412 isdn_tty_at_cout("\020\003", info
);
2414 if (info
->vonline
& 2) {
2415 #ifdef ISDN_DEBUG_MODEM_VOICE
2416 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
2419 /* voice-playing, add DLE-DC4 */
2420 isdn_tty_at_cout("\020\024", info
);
2424 case RESULT_CONNECT
:
2425 case RESULT_CONNECT64000
:
2426 sprintf(info
->last_cause
, "0000");
2431 #ifdef ISDN_DEBUG_MODEM_VOICE
2432 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
2435 sprintf(info
->last_cause
, "0000");
2439 } /* switch (code) */
2441 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
2443 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
2444 /* Show numeric results only */
2445 sprintf(s
, "\r\n%d\r\n", code
);
2446 isdn_tty_at_cout(s
, info
);
2448 if (code
== RESULT_RING
) {
2449 /* return if "show RUNG" and ringcounter>1 */
2450 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
2451 (m
->mdmreg
[REG_RINGCNT
] > 1))
2453 /* print CID, _before_ _every_ ring */
2454 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
2455 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
2456 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2457 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2458 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2459 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2463 isdn_tty_at_cout("\r\n", info
);
2464 isdn_tty_at_cout(msg
[code
], info
);
2466 case RESULT_CONNECT
:
2467 switch (m
->mdmreg
[REG_L2PROT
]) {
2468 case ISDN_PROTO_L2_MODEM
:
2469 isdn_tty_at_cout(" ", info
);
2470 isdn_tty_at_cout(m
->connmsg
, info
);
2475 /* Append CPN, if enabled */
2476 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
2477 sprintf(s
, "/%s", m
->cpn
);
2478 isdn_tty_at_cout(s
, info
);
2480 /* Print CID only once, _after_ 1st RING */
2481 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
2482 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
2483 isdn_tty_at_cout("\r\n", info
);
2484 isdn_tty_at_cout("CALLER NUMBER: ", info
);
2485 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2486 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2487 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2488 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2492 case RESULT_NO_CARRIER
:
2493 case RESULT_NO_DIALTONE
:
2495 case RESULT_NO_ANSWER
:
2496 m
->mdmreg
[REG_RINGCNT
] = 0;
2497 /* Append Cause-Message if enabled */
2498 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
2499 sprintf(s
, "/%s", info
->last_cause
);
2500 isdn_tty_at_cout(s
, info
);
2503 case RESULT_CONNECT64000
:
2504 /* Append Protocol to CONNECT message */
2505 switch (m
->mdmreg
[REG_L2PROT
]) {
2506 case ISDN_PROTO_L2_X75I
:
2507 case ISDN_PROTO_L2_X75UI
:
2508 case ISDN_PROTO_L2_X75BUI
:
2509 isdn_tty_at_cout("/X.75", info
);
2511 case ISDN_PROTO_L2_HDLC
:
2512 isdn_tty_at_cout("/HDLC", info
);
2514 case ISDN_PROTO_L2_V11096
:
2515 isdn_tty_at_cout("/V110/9600", info
);
2517 case ISDN_PROTO_L2_V11019
:
2518 isdn_tty_at_cout("/V110/19200", info
);
2520 case ISDN_PROTO_L2_V11038
:
2521 isdn_tty_at_cout("/V110/38400", info
);
2524 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2525 isdn_tty_at_cout("/T.70", info
);
2526 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2527 isdn_tty_at_cout("+", info
);
2531 isdn_tty_at_cout("\r\n", info
);
2534 if (code
== RESULT_NO_CARRIER
) {
2535 if ((info
->port
.flags
& ASYNC_CLOSING
) || (!info
->port
.tty
))
2538 if (info
->port
.flags
& ASYNC_CHECK_CD
)
2539 tty_hangup(info
->port
.tty
);
2545 * Display a modem-register-value.
2548 isdn_tty_show_profile(int ridx
, modem_info
*info
)
2552 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
2553 isdn_tty_at_cout(v
, info
);
2557 * Get MSN-string from char-pointer, set pointer to end of number
2560 isdn_tty_get_msnstr(char *n
, char **p
)
2562 int limit
= ISDN_MSNLEN
- 1;
2564 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
2565 /* Why a comma ??? */
2566 (*p
[0] == ',') || (*p
[0] == ':')) &&
2573 * Get phone-number from modem-commandbuffer
2576 isdn_tty_getdial(char *p
, char *q
, int cnt
)
2579 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
2582 while (strchr(" 0123456789,#.*WPTSR-", *p
) && *p
&& --cnt
> 0) {
2583 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
2584 ((*p
== 'R') && first
) ||
2585 (*p
== '*') || (*p
== '#')) {
2597 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2598 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2601 isdn_tty_report(modem_info
*info
)
2603 atemu
*m
= &info
->emu
;
2606 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
2607 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
2608 isdn_tty_at_cout(s
, info
);
2609 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
2610 isdn_tty_at_cout(s
, info
);
2611 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
2612 switch (info
->last_l2
) {
2613 case ISDN_PROTO_L2_X75I
:
2614 isdn_tty_at_cout("X.75i", info
);
2616 case ISDN_PROTO_L2_X75UI
:
2617 isdn_tty_at_cout("X.75ui", info
);
2619 case ISDN_PROTO_L2_X75BUI
:
2620 isdn_tty_at_cout("X.75bui", info
);
2622 case ISDN_PROTO_L2_HDLC
:
2623 isdn_tty_at_cout("HDLC", info
);
2625 case ISDN_PROTO_L2_V11096
:
2626 isdn_tty_at_cout("V.110 9600 Baud", info
);
2628 case ISDN_PROTO_L2_V11019
:
2629 isdn_tty_at_cout("V.110 19200 Baud", info
);
2631 case ISDN_PROTO_L2_V11038
:
2632 isdn_tty_at_cout("V.110 38400 Baud", info
);
2634 case ISDN_PROTO_L2_TRANS
:
2635 isdn_tty_at_cout("transparent", info
);
2637 case ISDN_PROTO_L2_MODEM
:
2638 isdn_tty_at_cout("modem", info
);
2640 case ISDN_PROTO_L2_FAX
:
2641 isdn_tty_at_cout("fax", info
);
2644 isdn_tty_at_cout("unknown", info
);
2647 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2648 isdn_tty_at_cout("/T.70", info
);
2649 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2650 isdn_tty_at_cout("+", info
);
2652 isdn_tty_at_cout("\r\n", info
);
2653 isdn_tty_at_cout(" Service: ", info
);
2654 switch (info
->last_si
) {
2656 isdn_tty_at_cout("audio\r\n", info
);
2659 isdn_tty_at_cout("btx\r\n", info
);
2662 isdn_tty_at_cout("data\r\n", info
);
2665 sprintf(s
, "%d\r\n", info
->last_si
);
2666 isdn_tty_at_cout(s
, info
);
2669 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
2670 isdn_tty_at_cout(s
, info
);
2671 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
2672 isdn_tty_at_cout(s
, info
);
2676 * Parse AT&.. commands.
2679 isdn_tty_cmd_ATand(char **p
, modem_info
*info
)
2681 atemu
*m
= &info
->emu
;
2685 #define MAXRB (sizeof(rb) - 1)
2689 /* &B - Set Buffersize */
2692 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
2694 #ifdef CONFIG_ISDN_AUDIO
2695 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
2698 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
2699 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2700 switch (m
->mdmreg
[REG_L2PROT
]) {
2701 case ISDN_PROTO_L2_V11096
:
2702 case ISDN_PROTO_L2_V11019
:
2703 case ISDN_PROTO_L2_V11038
:
2704 info
->xmit_size
/= 10;
2708 /* &C - DCD Status */
2710 switch (isdn_getnum(p
)) {
2712 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
2715 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
2722 /* &D - Set DTR-Low-behavior */
2724 switch (isdn_getnum(p
)) {
2726 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
2727 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2730 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2731 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2734 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2735 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
2742 /* &E -Set EAZ/MSN */
2744 isdn_tty_get_msnstr(m
->msn
, p
);
2747 /* &F -Set Factory-Defaults */
2749 if (info
->msr
& UART_MSR_DCD
)
2751 isdn_tty_reset_profile(m
);
2752 isdn_tty_modem_reset_regs(info
, 1);
2754 #ifdef DUMMY_HAYES_AT
2756 /* only for be compilant with common scripts */
2757 /* &K Flowcontrol - no function */
2763 /* &L -Set Numbers to listen on */
2766 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
2767 (i
< ISDN_LMSNLEN
- 1))
2768 m
->lmsn
[i
++] = *p
[0]++;
2772 /* &R - Set V.110 bitrate adaption */
2777 /* Switch off V.110, back to X.75 */
2778 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2779 m
->mdmreg
[REG_SI2
] = 0;
2780 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2783 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
2784 m
->mdmreg
[REG_SI2
] = 197;
2785 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2788 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
2789 m
->mdmreg
[REG_SI2
] = 199;
2790 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2793 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
2794 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
2795 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2800 /* Switch off T.70 */
2801 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2803 m
->mdmreg
[REG_SI1
] |= 4;
2806 /* &S - Set Windowsize */
2809 if ((i
> 0) && (i
< 9))
2810 m
->mdmreg
[REG_WSIZE
] = i
;
2815 /* &V - Show registers */
2817 isdn_tty_at_cout("\r\n", info
);
2818 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
2819 sprintf(rb
, "S%02d=%03d%s", i
,
2820 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
2821 isdn_tty_at_cout(rb
, info
);
2823 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
2824 strlen(m
->msn
) ? m
->msn
: "None");
2825 isdn_tty_at_cout(rb
, info
);
2826 if (strlen(m
->lmsn
)) {
2827 isdn_tty_at_cout("\r\nListen: ", info
);
2828 isdn_tty_at_cout(m
->lmsn
, info
);
2829 isdn_tty_at_cout("\r\n", info
);
2833 /* &W - Write Profile */
2838 modem_write_profile(m
);
2845 /* &X - Switch to BTX-Mode and T.70 */
2847 switch (isdn_getnum(p
)) {
2849 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2850 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2853 m
->mdmreg
[REG_T70
] |= BIT_T70
;
2854 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
2855 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2856 info
->xmit_size
= 112;
2857 m
->mdmreg
[REG_SI1
] = 4;
2858 m
->mdmreg
[REG_SI2
] = 0;
2861 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
2862 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2863 info
->xmit_size
= 112;
2864 m
->mdmreg
[REG_SI1
] = 4;
2865 m
->mdmreg
[REG_SI2
] = 0;
2878 isdn_tty_check_ats(int mreg
, int mval
, modem_info
*info
, atemu
*m
)
2880 /* Some plausibility checks */
2883 if (mval
> ISDN_PROTO_L2_MAX
)
2887 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
2889 #ifdef CONFIG_ISDN_AUDIO
2890 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
2893 info
->xmit_size
= mval
* 16;
2894 switch (m
->mdmreg
[REG_L2PROT
]) {
2895 case ISDN_PROTO_L2_V11096
:
2896 case ISDN_PROTO_L2_V11019
:
2897 case ISDN_PROTO_L2_V11038
:
2898 info
->xmit_size
/= 10;
2904 /* readonly registers */
2911 * Perform ATS command
2914 isdn_tty_cmd_ATS(char **p
, modem_info
*info
)
2916 atemu
*m
= &info
->emu
;
2922 mreg
= isdn_getnum(p
);
2923 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
2928 mval
= isdn_getnum(p
);
2929 if (mval
< 0 || mval
> 255)
2931 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
2933 m
->mdmreg
[mreg
] = mval
;
2936 /* Set/Clear a single bit */
2938 bitpos
= isdn_getnum(p
);
2939 if ((bitpos
< 0) || (bitpos
> 7))
2944 bval
= isdn_getnum(p
);
2945 if (bval
< 0 || bval
> 1)
2948 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
2950 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
2951 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
2953 m
->mdmreg
[mreg
] = mval
;
2957 isdn_tty_at_cout("\r\n", info
);
2958 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
2967 isdn_tty_show_profile(mreg
, info
);
2977 * Perform ATA command
2980 isdn_tty_cmd_ATA(modem_info
*info
)
2982 atemu
*m
= &info
->emu
;
2986 if (info
->msr
& UART_MSR_RI
) {
2987 /* Accept incoming call */
2989 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
2990 m
->mdmreg
[REG_RINGCNT
] = 0;
2991 info
->msr
&= ~UART_MSR_RI
;
2992 l2
= m
->mdmreg
[REG_L2PROT
];
2993 #ifdef CONFIG_ISDN_AUDIO
2994 /* If more than one bit set in reg18, autoselect Layer2 */
2995 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
2996 if (m
->mdmreg
[REG_SI1I
] == 1) {
2997 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
2998 l2
= ISDN_PROTO_L2_TRANS
;
3000 l2
= ISDN_PROTO_L2_X75I
;
3003 cmd
.driver
= info
->isdn_driver
;
3004 cmd
.command
= ISDN_CMD_SETL2
;
3005 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
3008 cmd
.driver
= info
->isdn_driver
;
3009 cmd
.command
= ISDN_CMD_SETL3
;
3010 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
3011 #ifdef CONFIG_ISDN_TTY_FAX
3012 if (l2
== ISDN_PROTO_L2_FAX
) {
3013 cmd
.parm
.fax
= info
->fax
;
3014 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3018 cmd
.driver
= info
->isdn_driver
;
3019 cmd
.arg
= info
->isdn_channel
;
3020 cmd
.command
= ISDN_CMD_ACCEPTD
;
3022 info
->emu
.carrierwait
= 0;
3024 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3026 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3029 #ifdef CONFIG_ISDN_AUDIO
3031 * Parse AT+F.. commands
3034 isdn_tty_cmd_PLUSF(char **p
, modem_info
*info
)
3036 atemu
*m
= &info
->emu
;
3039 if (!strncmp(p
[0], "CLASS", 5)) {
3044 sprintf(rs
, "\r\n%d",
3045 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3046 #ifdef CONFIG_ISDN_TTY_FAX
3047 if (TTY_IS_FCLASS2(info
))
3048 sprintf(rs
, "\r\n2");
3049 else if (TTY_IS_FCLASS1(info
))
3050 sprintf(rs
, "\r\n1");
3052 isdn_tty_at_cout(rs
, info
);
3059 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3060 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3061 m
->mdmreg
[REG_SI1
] = 4;
3063 m
->mdmreg
[REG_PSIZE
] * 16;
3065 #ifdef CONFIG_ISDN_TTY_FAX
3068 if (!(dev
->global_features
&
3069 ISDN_FEATURE_L3_FCLASS1
))
3071 m
->mdmreg
[REG_SI1
] = 1;
3072 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3073 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3075 m
->mdmreg
[REG_PSIZE
] * 16;
3079 if (!(dev
->global_features
&
3080 ISDN_FEATURE_L3_FCLASS2
))
3082 m
->mdmreg
[REG_SI1
] = 1;
3083 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3084 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3086 m
->mdmreg
[REG_PSIZE
] * 16;
3091 /* L2 will change on dialout with si=1 */
3092 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3093 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3094 m
->mdmreg
[REG_SI1
] = 5;
3095 info
->xmit_size
= VBUF
;
3099 strcpy(rs
, "\r\n0,");
3100 #ifdef CONFIG_ISDN_TTY_FAX
3101 if (dev
->global_features
&
3102 ISDN_FEATURE_L3_FCLASS1
)
3104 if (dev
->global_features
&
3105 ISDN_FEATURE_L3_FCLASS2
)
3109 isdn_tty_at_cout(rs
, info
);
3120 #ifdef CONFIG_ISDN_TTY_FAX
3121 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3128 * Parse AT+V.. commands
3131 isdn_tty_cmd_PLUSV(char **p
, modem_info
*info
)
3133 atemu
*m
= &info
->emu
;
3135 static char *vcmd
[] =
3136 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3144 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3152 /* AT+VNH - Auto hangup feature */
3156 isdn_tty_at_cout("\r\n1", info
);
3166 isdn_tty_at_cout("\r\n1", info
);
3177 /* AT+VIP - Reset all voice parameters */
3178 isdn_tty_modem_reset_vpar(m
);
3181 /* AT+VLS - Select device, accept incoming call */
3185 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3186 isdn_tty_at_cout(rs
, info
);
3201 isdn_tty_at_cout("\r\n0,2", info
);
3212 /* AT+VRX - Start recording */
3215 if (info
->online
!= 1) {
3216 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3219 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3220 if (!info
->dtmf_state
) {
3221 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3224 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3225 if (!info
->silence_state
) {
3226 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3229 if (m
->vpar
[3] < 5) {
3230 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3231 if (!info
->adpcmr
) {
3232 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3236 #ifdef ISDN_DEBUG_AT
3237 printk(KERN_DEBUG
"AT: +VRX\n");
3240 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3244 /* AT+VSD - Silence detection */
3248 sprintf(rs
, "\r\n<%d>,<%d>",
3251 isdn_tty_at_cout(rs
, info
);
3255 if ((*p
[0] >= '0') && (*p
[0] <= '9')) {
3256 par1
= isdn_getnum(p
);
3257 if ((par1
< 0) || (par1
> 31))
3262 par2
= isdn_getnum(p
);
3263 if ((par2
< 0) || (par2
> 255))
3271 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3282 /* AT+VSM - Select compression */
3286 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3289 isdn_tty_at_cout(rs
, info
);
3299 par1
= isdn_getnum(p
);
3300 if ((par1
< 2) || (par1
> 6))
3306 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3308 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3310 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3312 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3314 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3326 /* AT+VTX - Start sending */
3329 if (info
->online
!= 1) {
3330 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3333 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3334 if (!info
->dtmf_state
) {
3335 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3338 if (m
->vpar
[3] < 5) {
3339 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3340 if (!info
->adpcms
) {
3341 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3345 #ifdef ISDN_DEBUG_AT
3346 printk(KERN_DEBUG
"AT: +VTX\n");
3350 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3354 /* AT+VDD - DTMF detection */
3358 sprintf(rs
, "\r\n<%d>,<%d>",
3361 isdn_tty_at_cout(rs
, info
);
3365 if ((*p
[0] >= '0') && (*p
[0] <= '9')) {
3366 if (info
->online
!= 1)
3368 par1
= isdn_getnum(p
);
3369 if ((par1
< 0) || (par1
> 15))
3374 par2
= isdn_getnum(p
);
3375 if ((par2
< 0) || (par2
> 255))
3379 cmd
.driver
= info
->isdn_driver
;
3380 cmd
.command
= ISDN_CMD_AUDIO
;
3381 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3382 cmd
.parm
.num
[0] = par1
;
3383 cmd
.parm
.num
[1] = par2
;
3389 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3404 #endif /* CONFIG_ISDN_AUDIO */
3407 * Parse and perform an AT-command-line.
3410 isdn_tty_parse_at(modem_info
*info
)
3412 atemu
*m
= &info
->emu
;
3414 char ds
[ISDN_MSNLEN
];
3416 #ifdef ISDN_DEBUG_AT
3417 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
3419 for (p
= &m
->mdmcmd
[2]; *p
;) {
3425 /* A - Accept incoming call */
3427 isdn_tty_cmd_ATA(info
);
3432 if (info
->msr
& UART_MSR_DCD
)
3434 if (info
->msr
& UART_MSR_RI
) {
3435 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3438 isdn_tty_getdial(++p
, ds
, sizeof ds
);
3440 if (!strlen(m
->msn
))
3441 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
3442 else if (strlen(ds
))
3443 isdn_tty_dial(ds
, info
, m
);
3448 /* E - Turn Echo on/off */
3450 switch (isdn_getnum(&p
)) {
3452 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
3455 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
3462 /* H - On/Off-hook */
3467 isdn_tty_on_hook(info
);
3471 isdn_tty_off_hook();
3474 isdn_tty_on_hook(info
);
3479 /* I - Information */
3481 isdn_tty_at_cout("\r\nLinux ISDN", info
);
3489 isdn_tty_report(info
);
3493 snprintf(ds
, sizeof(ds
), "\r\n%d", info
->emu
.charge
);
3494 isdn_tty_at_cout(ds
, info
);
3499 #ifdef DUMMY_HAYES_AT
3502 /* only for be compilant with common scripts */
3511 if (info
->msr
& UART_MSR_DCD
)
3512 /* if B-Channel is up */
3513 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
: RESULT_CONNECT64000
, info
);
3515 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3518 /* Q - Turn Emulator messages on/off */
3520 switch (isdn_getnum(&p
)) {
3522 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
3525 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
3532 /* S - Set/Get Register */
3534 if (isdn_tty_cmd_ATS(&p
, info
))
3538 /* V - Numeric or ASCII Emulator-messages */
3540 switch (isdn_getnum(&p
)) {
3542 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
3545 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
3552 /* Z - Load Registers from Profile */
3554 if (info
->msr
& UART_MSR_DCD
) {
3556 isdn_tty_on_hook(info
);
3558 isdn_tty_modem_reset_regs(info
, 1);
3563 #ifdef CONFIG_ISDN_AUDIO
3566 if (isdn_tty_cmd_PLUSF(&p
, info
))
3570 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
3571 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
3574 if (isdn_tty_cmd_PLUSV(&p
, info
))
3577 #endif /* CONFIG_ISDN_AUDIO */
3578 case 'S': /* SUSPEND */
3580 isdn_tty_get_msnstr(ds
, &p
);
3581 isdn_tty_suspend(ds
, info
, m
);
3583 case 'R': /* RESUME */
3585 isdn_tty_get_msnstr(ds
, &p
);
3586 isdn_tty_resume(ds
, info
, m
);
3588 case 'M': /* MESSAGE */
3590 isdn_tty_send_msg(info
, m
, p
);
3598 if (isdn_tty_cmd_ATand(&p
, info
))
3605 #ifdef CONFIG_ISDN_AUDIO
3608 isdn_tty_modem_result(RESULT_OK
, info
);
3611 /* Need own toupper() because standard-toupper is not available
3614 #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c)
3617 * Perform line-editing of AT-commands
3621 * count length of buffer
3622 * channel index to line (minor-device)
3625 isdn_tty_edit_at(const char *p
, int count
, modem_info
*info
)
3627 atemu
*m
= &info
->emu
;
3633 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
3636 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
3637 /* Separator (CR or LF) */
3638 m
->mdmcmd
[m
->mdmcmdl
] = 0;
3639 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3642 isdn_tty_at_cout(eb
, info
);
3644 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
3645 isdn_tty_parse_at(info
);
3649 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
3650 /* Backspace-Function */
3651 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
3654 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
3655 isdn_tty_at_cout("\b", info
);
3660 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3663 isdn_tty_at_cout(eb
, info
);
3665 if (m
->mdmcmdl
< 255) {
3667 switch (m
->mdmcmdl
) {
3670 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3671 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3675 /* Fall through, check for 'A' */
3678 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3679 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3683 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3684 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3693 * Switch all modem-channels who are online and got a valid
3694 * escape-sequence 1.5 seconds ago, to command-mode.
3695 * This function is called every second via timer-interrupt from within
3696 * timer-dispatcher isdn_timer_function()
3699 isdn_tty_modem_escape(void)
3705 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
3706 if (USG_MODEM(dev
->usage
[i
]) && (midx
= dev
->m_idx
[i
]) >= 0) {
3707 modem_info
*info
= &dev
->mdm
.info
[midx
];
3710 if ((info
->emu
.pluscount
== 3) &&
3712 info
->emu
.lastplus
+ PLUSWAIT2
)) {
3713 info
->emu
.pluscount
= 0;
3715 isdn_tty_modem_result(RESULT_OK
, info
);
3719 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
3723 * Put a RING-message to all modem-channels who have the RI-bit set.
3724 * This function is called every second via timer-interrupt from within
3725 * timer-dispatcher isdn_timer_function()
3728 isdn_tty_modem_ring(void)
3733 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3734 modem_info
*info
= &dev
->mdm
.info
[i
];
3735 if (info
->msr
& UART_MSR_RI
) {
3737 isdn_tty_modem_result(RESULT_RING
, info
);
3740 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
3744 * For all online tty's, try sending data to
3748 isdn_tty_modem_xmit(void)
3753 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3754 modem_info
*info
= &dev
->mdm
.info
[i
];
3757 isdn_tty_senddown(info
);
3758 isdn_tty_tint(info
);
3761 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
3765 * Check all channels if we have a 'no carrier' timeout.
3766 * Timeout value is set by Register S7.
3769 isdn_tty_carrier_timeout(void)
3774 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3775 modem_info
*info
= &dev
->mdm
.info
[i
];
3778 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
3780 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3781 isdn_tty_modem_hup(info
, 1);
3785 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);