1 /* $Id: isdn_tty.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $
3 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
12 #undef ISDN_TTY_STAT_DEBUG
14 #include <linux/config.h>
15 #include <linux/isdn.h>
16 #include <linux/delay.h>
17 #include "isdn_common.h"
19 #ifdef CONFIG_ISDN_AUDIO
20 #include "isdn_audio.h"
22 #define VBUFX (VBUF/16)
25 #define FIX_FILE_TRANSFER
26 #define DUMMY_HAYES_AT
30 static int isdn_tty_edit_at(const char *, int, modem_info
*);
31 static void isdn_tty_check_esc(const u_char
*, u_char
, int, int *, u_long
*);
32 static void isdn_tty_modem_reset_regs(modem_info
*, int);
33 static void isdn_tty_cmd_ATA(modem_info
*);
34 static void isdn_tty_flush_buffer(struct tty_struct
*);
35 static void isdn_tty_modem_result(int, modem_info
*);
36 #ifdef CONFIG_ISDN_AUDIO
37 static int isdn_tty_countDLE(unsigned char *, int);
40 /* Leave this unchanged unless you know what you do! */
41 #define MODEM_PARANOIA_CHECK
42 #define MODEM_DO_RESTART
44 static int bit2si
[8] =
45 {1, 5, 7, 7, 7, 7, 7, 7};
46 static int si2bit
[8] =
47 {4, 1, 4, 4, 4, 4, 4, 4};
49 char *isdn_tty_revision
= "$Revision: 1.1.2.3 $";
52 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
53 * to stuff incoming data directly into a tty's flip-buffer. This
54 * is done to speed up tty-receiving if the receive-queue is empty.
55 * This routine MUST be called with interrupts off.
58 * 0 = Failure, data has to be buffered and later processed by
59 * isdn_tty_readmodem().
62 isdn_tty_try_read(modem_info
* info
, struct sk_buff
*skb
)
66 struct tty_struct
*tty
;
69 if ((tty
= info
->tty
)) {
70 if (info
->mcr
& UART_MCR_RTS
) {
71 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
73 #ifdef CONFIG_ISDN_AUDIO
74 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
78 #ifdef CONFIG_ISDN_AUDIO
79 if (ISDN_AUDIO_SKB_DLECOUNT(skb
))
81 if (*skb
->data
== DLE
)
82 tty_insert_flip_char(tty
, DLE
, 0);
83 tty_insert_flip_char(tty
, *skb
->data
++, 0);
86 memcpy(tty
->flip
.char_buf_ptr
,
88 tty
->flip
.count
+= len
;
89 tty
->flip
.char_buf_ptr
+= len
;
90 memset(tty
->flip
.flag_buf_ptr
, 0, len
);
91 tty
->flip
.flag_buf_ptr
+= len
;
92 #ifdef CONFIG_ISDN_AUDIO
95 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
96 tty
->flip
.flag_buf_ptr
[len
- 1] = 0xff;
97 schedule_delayed_work(&tty
->flip
.work
, 1);
107 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
108 * It tries getting received data from the receive queue an stuff it into
109 * the tty's flip-buffer.
112 isdn_tty_readmodem(void)
119 struct tty_struct
*tty
;
122 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
123 if ((midx
= dev
->m_idx
[i
]) >= 0) {
124 info
= &dev
->mdm
.info
[midx
];
127 #ifdef CONFIG_ISDN_AUDIO
128 isdn_audio_eval_dtmf(info
);
129 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
130 isdn_audio_eval_silence(info
);
132 if ((tty
= info
->tty
)) {
133 if (info
->mcr
& UART_MCR_RTS
) {
134 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
136 r
= isdn_readbchan(info
->isdn_driver
, info
->isdn_channel
,
137 tty
->flip
.char_buf_ptr
,
138 tty
->flip
.flag_buf_ptr
, c
, NULL
);
139 /* CISCO AsyncPPP Hack */
140 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
141 memset(tty
->flip
.flag_buf_ptr
, 0, r
);
142 tty
->flip
.count
+= r
;
143 tty
->flip
.flag_buf_ptr
+= r
;
144 tty
->flip
.char_buf_ptr
+= r
;
146 schedule_delayed_work(&tty
->flip
.work
, 1);
161 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
165 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
169 #ifdef CONFIG_ISDN_AUDIO
174 if ((midx
= dev
->m_idx
[i
]) < 0) {
175 /* if midx is invalid, packet is not for tty */
178 info
= &dev
->mdm
.info
[midx
];
179 #ifdef CONFIG_ISDN_AUDIO
182 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
183 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
184 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
185 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
187 if ((info
->online
< 2)
188 #ifdef CONFIG_ISDN_AUDIO
189 && (!(info
->vonline
& 1))
192 /* If Modem not listening, drop data */
196 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
197 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
198 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
199 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
202 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
205 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
206 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
209 #ifdef CONFIG_ISDN_AUDIO
210 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
211 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
212 if (info
->vonline
& 1) {
213 /* voice conversion/compression */
214 switch (info
->emu
.vpar
[3]) {
219 * Since compressed data takes less
220 * space, we can overwrite the buffer.
222 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
231 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
236 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
239 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
240 isdn_tty_countDLE(skb
->data
, skb
->len
);
242 #ifdef CONFIG_ISDN_TTY_FAX
244 if (info
->faxonline
& 2) {
245 isdn_tty_fax_bitorder(info
, skb
);
246 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
247 isdn_tty_countDLE(skb
->data
, skb
->len
);
252 /* Try to deliver directly via tty-flip-buf if queue is empty */
253 spin_lock_irqsave(&info
->readlock
, flags
);
254 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
255 if (isdn_tty_try_read(info
, skb
)) {
256 spin_unlock_irqrestore(&info
->readlock
, flags
);
259 /* Direct deliver failed or queue wasn't empty.
260 * Queue up for later dequeueing via timer-irq.
262 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
263 dev
->drv
[di
]->rcvcount
[channel
] +=
265 #ifdef CONFIG_ISDN_AUDIO
266 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
269 spin_unlock_irqrestore(&info
->readlock
, flags
);
270 /* Schedule dequeuing */
271 if ((dev
->modempoll
) && (info
->rcvsched
))
272 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
277 isdn_tty_cleanup_xmit(modem_info
* info
)
279 skb_queue_purge(&info
->xmit_queue
);
280 #ifdef CONFIG_ISDN_AUDIO
281 skb_queue_purge(&info
->dtmf_queue
);
286 isdn_tty_tint(modem_info
* info
)
288 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
294 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
295 info
->isdn_channel
, 1, skb
)) == len
) {
296 struct tty_struct
*tty
= info
->tty
;
297 info
->send_outstanding
++;
298 info
->msr
&= ~UART_MSR_CTS
;
299 info
->lsr
&= ~UART_LSR_TEMT
;
304 /* Error: no channel, already shutdown, or wrong parameter */
308 skb_queue_head(&info
->xmit_queue
, skb
);
311 #ifdef CONFIG_ISDN_AUDIO
313 isdn_tty_countDLE(unsigned char *buf
, int len
)
323 /* This routine is called from within isdn_tty_write() to perform
324 * DLE-decoding when sending audio-data.
327 isdn_tty_handleDLEdown(modem_info
* info
, atemu
* m
, int len
)
329 unsigned char *p
= &info
->xmit_buf
[info
->xmit_count
];
339 memmove(p
, p
+ 1, len
- 1);
350 #ifdef ISDN_DEBUG_MODEM_VOICE
352 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
355 isdn_tty_at_cout("\020\003", info
);
356 if (!info
->vonline
) {
357 #ifdef ISDN_DEBUG_MODEM_VOICE
359 "DLEdown: send VCON on ttyI%d\n",
362 isdn_tty_at_cout("\r\nVCON\r\n", info
);
369 memmove(p
, p
+ 1, len
- 1);
383 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
389 /* This routine is called from within isdn_tty_write() when receiving
390 * audio-data. It interrupts receiving, if an character other than
394 isdn_tty_end_vrx(const char *buf
, int c
)
400 if ((ch
!= 0x11) && (ch
!= 0x13))
407 static int voice_cf
[7] =
408 {0, 0, 4, 3, 2, 0, 0};
410 #endif /* CONFIG_ISDN_AUDIO */
412 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
413 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
414 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
415 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
418 isdn_tty_senddown(modem_info
* info
)
422 #ifdef CONFIG_ISDN_AUDIO
427 #ifdef CONFIG_ISDN_AUDIO
428 if (info
->vonline
& 4) {
430 if (!info
->vonline
) {
431 #ifdef ISDN_DEBUG_MODEM_VOICE
433 "senddown: send VCON on ttyI%d\n",
436 isdn_tty_at_cout("\r\nVCON\r\n", info
);
440 if (!(buflen
= info
->xmit_count
))
442 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
443 info
->msr
&= ~UART_MSR_CTS
;
444 info
->lsr
&= ~UART_LSR_TEMT
;
445 /* info->xmit_count is modified here and in isdn_tty_write().
446 * So we return here if isdn_tty_write() is in the
449 atomic_inc(&info
->xmit_lock
);
450 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
452 if (info
->isdn_driver
< 0) {
453 info
->xmit_count
= 0;
456 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
457 #ifdef CONFIG_ISDN_AUDIO
458 if (info
->vonline
& 2)
459 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
462 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
464 skb
= dev_alloc_skb(skb_res
+ buflen
);
468 "isdn_tty: Out of memory in ttyI%d senddown\n",
472 skb_reserve(skb
, skb_res
);
473 memcpy(skb_put(skb
, buflen
), info
->xmit_buf
, buflen
);
474 info
->xmit_count
= 0;
475 #ifdef CONFIG_ISDN_AUDIO
476 if (info
->vonline
& 2) {
477 /* For now, ifmt is fixed to 1 (alaw), since this
478 * is used with ISDN everywhere in the world, except
479 * US, Canada and Japan.
480 * Later, when US-ISDN protocols are implemented,
481 * this setting will depend on the D-channel protocol.
485 /* voice conversion/decompression */
486 switch (info
->emu
.vpar
[3]) {
490 /* adpcm, compatible to ZyXel 1496 modem
491 * with ROM revision 6.01
493 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
496 skb_put(skb
, audio_len
),
498 skb_pull(skb
, buflen
);
499 skb_trim(skb
, audio_len
);
504 isdn_audio_alaw2ulaw(skb
->data
,
510 isdn_audio_ulaw2alaw(skb
->data
,
515 #endif /* CONFIG_ISDN_AUDIO */
516 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
517 /* Add T.70 simplified header */
518 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
519 memcpy(skb_push(skb
, 2), "\1\0", 2);
521 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
523 skb_queue_tail(&info
->xmit_queue
, skb
);
526 /************************************************************
530 * mostly "stolen" from original Linux-serial.c and friends.
532 ************************************************************/
534 /* The next routine is called once from within timer-interrupt
535 * triggered within isdn_tty_modem_ncarrier(). It calls
536 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
537 * into the tty's flip-buffer.
540 isdn_tty_modem_do_ncarrier(unsigned long data
)
542 modem_info
*info
= (modem_info
*) data
;
543 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
546 /* Next routine is called, whenever the DTR-signal is raised.
547 * It checks the ncarrier-flag, and triggers the above routine
548 * when necessary. The ncarrier-flag is set, whenever DTR goes
552 isdn_tty_modem_ncarrier(modem_info
* info
)
554 if (info
->ncarrier
) {
555 info
->nc_timer
.expires
= jiffies
+ HZ
;
556 add_timer(&info
->nc_timer
);
561 * return the usage calculated by si and layer 2 protocol
564 isdn_calc_usage(int si
, int l2
)
566 int usg
= ISDN_USAGE_MODEM
;
568 #ifdef CONFIG_ISDN_AUDIO
571 case ISDN_PROTO_L2_MODEM
:
572 usg
= ISDN_USAGE_MODEM
;
574 #ifdef CONFIG_ISDN_TTY_FAX
575 case ISDN_PROTO_L2_FAX
:
576 usg
= ISDN_USAGE_FAX
;
579 case ISDN_PROTO_L2_TRANS
:
581 usg
= ISDN_USAGE_VOICE
;
589 /* isdn_tty_dial() performs dialing of a tty an the necessary
590 * setup of the lower levels before that.
593 isdn_tty_dial(char *n
, modem_info
* info
, atemu
* m
)
595 int usg
= ISDN_USAGE_MODEM
;
597 int l2
= m
->mdmreg
[REG_L2PROT
];
603 for (j
= 7; j
>= 0; j
--)
604 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
608 usg
= isdn_calc_usage(si
, l2
);
609 #ifdef CONFIG_ISDN_AUDIO
611 (l2
!= ISDN_PROTO_L2_MODEM
)
612 #ifdef CONFIG_ISDN_TTY_FAX
613 && (l2
!= ISDN_PROTO_L2_FAX
)
616 l2
= ISDN_PROTO_L2_TRANS
;
617 usg
= ISDN_USAGE_VOICE
;
620 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
621 spin_lock_irqsave(&dev
->lock
, flags
);
622 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
624 spin_unlock_irqrestore(&dev
->lock
, flags
);
625 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
627 info
->isdn_driver
= dev
->drvmap
[i
];
628 info
->isdn_channel
= dev
->chanmap
[i
];
630 dev
->m_idx
[i
] = info
->line
;
631 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
633 strcpy(info
->last_num
, n
);
635 spin_unlock_irqrestore(&dev
->lock
, flags
);
636 cmd
.driver
= info
->isdn_driver
;
637 cmd
.arg
= info
->isdn_channel
;
638 cmd
.command
= ISDN_CMD_CLREAZ
;
640 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
641 cmd
.driver
= info
->isdn_driver
;
642 cmd
.command
= ISDN_CMD_SETEAZ
;
644 cmd
.driver
= info
->isdn_driver
;
645 cmd
.command
= ISDN_CMD_SETL2
;
647 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
649 cmd
.driver
= info
->isdn_driver
;
650 cmd
.command
= ISDN_CMD_SETL3
;
651 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
652 #ifdef CONFIG_ISDN_TTY_FAX
653 if (l2
== ISDN_PROTO_L2_FAX
) {
654 cmd
.parm
.fax
= info
->fax
;
655 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
659 cmd
.driver
= info
->isdn_driver
;
660 cmd
.arg
= info
->isdn_channel
;
661 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
662 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
663 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
664 cmd
.parm
.setup
.si1
= si
;
665 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
666 cmd
.command
= ISDN_CMD_DIAL
;
668 info
->emu
.carrierwait
= 0;
669 strcpy(dev
->num
[i
], n
);
672 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
676 /* isdn_tty_hangup() disassociates a tty from the real
677 * ISDN-line (hangup). The usage-status is cleared
678 * and some cleanup is done also.
681 isdn_tty_modem_hup(modem_info
* info
, int local
)
689 di
= info
->isdn_driver
;
690 ch
= info
->isdn_channel
;
691 if (di
< 0 || ch
< 0)
694 info
->isdn_driver
= -1;
695 info
->isdn_channel
= -1;
697 #ifdef ISDN_DEBUG_MODEM_HUP
698 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
701 isdn_tty_flush_buffer(info
->tty
);
703 info
->last_lhup
= local
;
705 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
707 #ifdef CONFIG_ISDN_AUDIO
709 #ifdef CONFIG_ISDN_TTY_FAX
711 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
713 info
->emu
.vpar
[4] = 0;
714 info
->emu
.vpar
[5] = 8;
715 if (info
->dtmf_state
) {
716 kfree(info
->dtmf_state
);
717 info
->dtmf_state
= NULL
;
719 if (info
->silence_state
) {
720 kfree(info
->silence_state
);
721 info
->silence_state
= NULL
;
732 if ((info
->msr
& UART_MSR_RI
) &&
733 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
734 isdn_tty_modem_result(RESULT_RUNG
, info
);
735 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
736 info
->lsr
|= UART_LSR_TEMT
;
740 cmd
.command
= ISDN_CMD_HANGUP
;
745 isdn_all_eaz(di
, ch
);
746 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
747 isdn_free_channel(di
, ch
, 0);
749 if (info
->drv_index
>= 0) {
750 dev
->m_idx
[info
->drv_index
] = -1;
751 info
->drv_index
= -1;
756 * Begin of a CAPI like interface, currently used only for
757 * supplementary service (CAPI 2.0 part III)
759 #include <linux/isdn/capicmd.h>
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. unfortunatly 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
)
1012 if (!info
->tty
|| !info
->tty
->termios
)
1014 cflag
= info
->tty
->termios
->c_cflag
;
1016 quot
= i
= cflag
& CBAUD
;
1020 info
->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
;
1049 /* CTS flow control flag and modem status interrupts */
1050 if (cflag
& CRTSCTS
) {
1051 info
->flags
|= ISDN_ASYNC_CTS_FLOW
;
1053 info
->flags
&= ~ISDN_ASYNC_CTS_FLOW
;
1055 info
->flags
&= ~ISDN_ASYNC_CHECK_CD
;
1057 info
->flags
|= ISDN_ASYNC_CHECK_CD
;
1062 isdn_tty_startup(modem_info
* info
)
1064 if (info
->flags
& ISDN_ASYNC_INITIALIZED
)
1066 isdn_lock_drivers();
1067 #ifdef ISDN_DEBUG_MODEM_OPEN
1068 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1071 * Now, initialize the UART
1073 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1075 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1077 * and set the speed of the serial port
1079 isdn_tty_change_speed(info
);
1081 info
->flags
|= ISDN_ASYNC_INITIALIZED
;
1082 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1083 info
->send_outstanding
= 0;
1088 * This routine will shutdown a serial port; interrupts are disabled, and
1089 * DTR is dropped if the hangup on close termio flag is on.
1092 isdn_tty_shutdown(modem_info
* info
)
1094 if (!(info
->flags
& ISDN_ASYNC_INITIALIZED
))
1096 #ifdef ISDN_DEBUG_MODEM_OPEN
1097 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1099 isdn_unlock_drivers();
1100 info
->msr
&= ~UART_MSR_RI
;
1101 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
1102 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1103 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1104 isdn_tty_modem_reset_regs(info
, 0);
1105 #ifdef ISDN_DEBUG_MODEM_HUP
1106 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1108 isdn_tty_modem_hup(info
, 1);
1112 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1114 info
->flags
&= ~ISDN_ASYNC_INITIALIZED
;
1117 /* isdn_tty_write() is the main send-routine. It is called from the upper
1118 * levels within the kernel to perform sending data. Depending on the
1119 * online-flag it either directs output to the at-command-interpreter or
1120 * to the lower level. Additional tasks done here:
1121 * - If online, check for escape-sequence (+++)
1122 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1123 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1124 * - If dialing, abort dial.
1127 isdn_tty_write(struct tty_struct
*tty
, const u_char
* buf
, int count
)
1131 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1132 atemu
*m
= &info
->emu
;
1134 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write"))
1136 /* See isdn_tty_senddown() */
1137 atomic_inc(&info
->xmit_lock
);
1140 if (c
> info
->xmit_size
- info
->xmit_count
)
1141 c
= info
->xmit_size
- info
->xmit_count
;
1142 if (info
->isdn_driver
>= 0 && c
> dev
->drv
[info
->isdn_driver
]->maxbufsize
)
1143 c
= dev
->drv
[info
->isdn_driver
]->maxbufsize
;
1146 if ((info
->online
> 1)
1147 #ifdef CONFIG_ISDN_AUDIO
1148 || (info
->vonline
& 3)
1151 #ifdef CONFIG_ISDN_AUDIO
1154 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1157 memcpy(&(info
->xmit_buf
[info
->xmit_count
]), buf
, c
);
1158 #ifdef CONFIG_ISDN_AUDIO
1159 if (info
->vonline
) {
1160 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1161 if (info
->vonline
& 2) {
1163 /* If DLE decoding results in zero-transmit, but
1164 * c originally was non-zero, do a wakeup.
1167 info
->msr
|= UART_MSR_CTS
;
1168 info
->lsr
|= UART_LSR_TEMT
;
1170 info
->xmit_count
+= cc
;
1172 if ((info
->vonline
& 3) == 1) {
1173 /* Do NOT handle Ctrl-Q or Ctrl-S
1174 * when in full-duplex audio mode.
1176 if (isdn_tty_end_vrx(buf
, c
)) {
1177 info
->vonline
&= ~1;
1178 #ifdef ISDN_DEBUG_MODEM_VOICE
1180 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1183 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1187 if (TTY_IS_FCLASS1(info
)) {
1188 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1190 if (info
->vonline
& 4) { /* ETX seen */
1193 c
.command
= ISDN_CMD_FAXCMD
;
1194 c
.driver
= info
->isdn_driver
;
1195 c
.arg
= info
->isdn_channel
;
1196 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1197 c
.parm
.aux
.subcmd
= ETX
;
1201 #ifdef ISDN_DEBUG_MODEM_VOICE
1202 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
, c
);
1204 info
->xmit_count
+= cc
;
1207 info
->xmit_count
+= c
;
1209 info
->msr
|= UART_MSR_CTS
;
1210 info
->lsr
|= UART_LSR_TEMT
;
1211 if (info
->dialing
) {
1213 #ifdef ISDN_DEBUG_MODEM_HUP
1214 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1216 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1217 isdn_tty_modem_hup(info
, 1);
1219 c
= isdn_tty_edit_at(buf
, c
, info
);
1225 atomic_dec(&info
->xmit_lock
);
1226 if ((info
->xmit_count
) || (skb_queue_len(&info
->xmit_queue
))) {
1227 if (m
->mdmreg
[REG_DXMT
] & BIT_DXMT
) {
1228 isdn_tty_senddown(info
);
1229 isdn_tty_tint(info
);
1231 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1237 isdn_tty_write_room(struct tty_struct
*tty
)
1239 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1242 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write_room"))
1245 return info
->xmit_size
;
1246 ret
= info
->xmit_size
- info
->xmit_count
;
1247 return (ret
< 0) ? 0 : ret
;
1251 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1253 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1255 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_chars_in_buffer"))
1259 return (info
->xmit_count
);
1263 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1270 info
= (modem_info
*) tty
->driver_data
;
1271 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_buffer")) {
1274 isdn_tty_cleanup_xmit(info
);
1275 info
->xmit_count
= 0;
1276 wake_up_interruptible(&tty
->write_wait
);
1281 isdn_tty_flush_chars(struct tty_struct
*tty
)
1283 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1285 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_chars"))
1287 if ((info
->xmit_count
) || (skb_queue_len(&info
->xmit_queue
)))
1288 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1292 * ------------------------------------------------------------
1293 * isdn_tty_throttle()
1295 * This routine is called by the upper-layer tty layer to signal that
1296 * incoming characters should be throttled.
1297 * ------------------------------------------------------------
1300 isdn_tty_throttle(struct tty_struct
*tty
)
1302 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1304 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_throttle"))
1307 info
->x_char
= STOP_CHAR(tty
);
1308 info
->mcr
&= ~UART_MCR_RTS
;
1312 isdn_tty_unthrottle(struct tty_struct
*tty
)
1314 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1316 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_unthrottle"))
1322 info
->x_char
= START_CHAR(tty
);
1324 info
->mcr
|= UART_MCR_RTS
;
1328 * ------------------------------------------------------------
1329 * isdn_tty_ioctl() and friends
1330 * ------------------------------------------------------------
1334 * isdn_tty_get_lsr_info - get line status register info
1336 * Purpose: Let user call ioctl() to get info when the UART physically
1337 * is emptied. On bus types like RS485, the transmitter must
1338 * release the bus after transmitting. This must be done when
1339 * the transmit shift register is empty, not be done when the
1340 * transmit holding register is empty. This functionality
1341 * allows RS485 driver to be written in user space.
1344 isdn_tty_get_lsr_info(modem_info
* info
, uint __user
* value
)
1350 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1351 return put_user(result
, value
);
1356 isdn_tty_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1358 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1359 u_char control
, status
;
1361 if (isdn_tty_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1363 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1366 #ifdef ISDN_DEBUG_MODEM_IOCTL
1367 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1370 control
= info
->mcr
;
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
, struct file
*file
,
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
, __FUNCTION__
))
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 if (set
& TIOCM_RTS
)
1396 info
->mcr
|= UART_MCR_RTS
;
1397 if (set
& TIOCM_DTR
) {
1398 info
->mcr
|= UART_MCR_DTR
;
1399 isdn_tty_modem_ncarrier(info
);
1402 if (clear
& TIOCM_RTS
)
1403 info
->mcr
&= ~UART_MCR_RTS
;
1404 if (clear
& TIOCM_DTR
) {
1405 info
->mcr
&= ~UART_MCR_DTR
;
1406 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1407 isdn_tty_modem_reset_regs(info
, 0);
1408 #ifdef ISDN_DEBUG_MODEM_HUP
1409 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1413 isdn_tty_modem_hup(info
, 1);
1420 isdn_tty_ioctl(struct tty_struct
*tty
, struct file
*file
,
1421 uint cmd
, ulong arg
)
1423 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1426 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_ioctl"))
1428 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1431 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1432 #ifdef ISDN_DEBUG_MODEM_IOCTL
1433 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1435 retval
= tty_check_change(tty
);
1438 tty_wait_until_sent(tty
, 0);
1440 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1441 #ifdef ISDN_DEBUG_MODEM_IOCTL
1442 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1444 retval
= tty_check_change(tty
);
1447 tty_wait_until_sent(tty
, 0);
1450 #ifdef ISDN_DEBUG_MODEM_IOCTL
1451 printk(KERN_DEBUG
"ttyI%d ioctl TIOCGSOFTCAR\n", info
->line
);
1453 return put_user(C_CLOCAL(tty
) ? 1 : 0, (ulong __user
*) arg
);
1455 #ifdef ISDN_DEBUG_MODEM_IOCTL
1456 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSSOFTCAR\n", info
->line
);
1458 if (get_user(arg
, (ulong __user
*) arg
))
1460 tty
->termios
->c_cflag
=
1461 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1462 (arg
? CLOCAL
: 0));
1464 case TIOCSERGETLSR
: /* Get line status register */
1465 #ifdef ISDN_DEBUG_MODEM_IOCTL
1466 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1468 return isdn_tty_get_lsr_info(info
, (uint __user
*) arg
);
1470 #ifdef ISDN_DEBUG_MODEM_IOCTL
1471 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1473 return -ENOIOCTLCMD
;
1479 isdn_tty_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1481 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1484 isdn_tty_change_speed(info
);
1486 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1488 isdn_tty_change_speed(info
);
1489 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1490 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1491 tty
->hw_stopped
= 0;
1497 * ------------------------------------------------------------
1498 * isdn_tty_open() and friends
1499 * ------------------------------------------------------------
1502 isdn_tty_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, modem_info
* info
)
1504 DECLARE_WAITQUEUE(wait
, NULL
);
1509 * If the device is in the middle of being closed, then block
1510 * until it's done, and then try again.
1512 if (tty_hung_up_p(filp
) ||
1513 (info
->flags
& ISDN_ASYNC_CLOSING
)) {
1514 if (info
->flags
& ISDN_ASYNC_CLOSING
)
1515 interruptible_sleep_on(&info
->close_wait
);
1516 #ifdef MODEM_DO_RESTART
1517 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1520 return -ERESTARTSYS
;
1526 * If non-blocking mode is set, then make the check up front
1529 if ((filp
->f_flags
& O_NONBLOCK
) ||
1530 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1531 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
1533 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
1536 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) {
1537 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1540 if (tty
->termios
->c_cflag
& CLOCAL
)
1544 * Block waiting for the carrier detect and the line to become
1545 * free (i.e., not in use by the callout). While we are in
1546 * this loop, info->count is dropped by one, so that
1547 * isdn_tty_close() knows when to free things. We restore it upon
1548 * exit, either normal or abnormal.
1551 add_wait_queue(&info
->open_wait
, &wait
);
1552 #ifdef ISDN_DEBUG_MODEM_OPEN
1553 printk(KERN_DEBUG
"isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1554 info
->line
, info
->count
);
1556 if (!(tty_hung_up_p(filp
)))
1558 info
->blocked_open
++;
1560 set_current_state(TASK_INTERRUPTIBLE
);
1561 if (tty_hung_up_p(filp
) ||
1562 !(info
->flags
& ISDN_ASYNC_INITIALIZED
)) {
1563 #ifdef MODEM_DO_RESTART
1564 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1567 retval
= -ERESTARTSYS
;
1573 if (!(info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
1574 !(info
->flags
& ISDN_ASYNC_CLOSING
) &&
1575 (do_clocal
|| (info
->msr
& UART_MSR_DCD
))) {
1578 if (signal_pending(current
)) {
1579 retval
= -ERESTARTSYS
;
1582 #ifdef ISDN_DEBUG_MODEM_OPEN
1583 printk(KERN_DEBUG
"isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1584 info
->line
, info
->count
);
1588 current
->state
= TASK_RUNNING
;
1589 remove_wait_queue(&info
->open_wait
, &wait
);
1590 if (!tty_hung_up_p(filp
))
1592 info
->blocked_open
--;
1593 #ifdef ISDN_DEBUG_MODEM_OPEN
1594 printk(KERN_DEBUG
"isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1595 info
->line
, info
->count
);
1599 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
1604 * This routine is called whenever a serial port is opened. It
1605 * enables interrupts for a serial port, linking in its async structure into
1606 * the IRQ chain. It also performs the serial-specific
1607 * initialization for the tty structure.
1610 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
1616 if (line
< 0 || line
> ISDN_MAX_CHANNELS
)
1618 info
= &dev
->mdm
.info
[line
];
1619 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_open"))
1621 if (!try_module_get(info
->owner
)) {
1622 printk(KERN_WARNING
"%s: cannot reserve module\n", __FUNCTION__
);
1625 #ifdef ISDN_DEBUG_MODEM_OPEN
1626 printk(KERN_DEBUG
"isdn_tty_open %s, count = %d\n", tty
->name
,
1630 tty
->driver_data
= info
;
1633 * Start up serial port
1635 retval
= isdn_tty_startup(info
);
1637 #ifdef ISDN_DEBUG_MODEM_OPEN
1638 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
1640 module_put(info
->owner
);
1643 retval
= isdn_tty_block_til_ready(tty
, filp
, info
);
1645 #ifdef ISDN_DEBUG_MODEM_OPEN
1646 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
1648 module_put(info
->owner
);
1651 #ifdef ISDN_DEBUG_MODEM_OPEN
1652 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
1655 #ifdef ISDN_DEBUG_MODEM_OPEN
1656 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
1662 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
1664 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1667 if (!info
|| isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_close"))
1669 if (tty_hung_up_p(filp
)) {
1670 #ifdef ISDN_DEBUG_MODEM_OPEN
1671 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
1675 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1677 * Uh, oh. tty->count is 1, which means that the tty
1678 * structure will be freed. Info->count should always
1679 * be one in these conditions. If it's greater than
1680 * one, we've got real problems, since it means the
1681 * serial port won't be shutdown.
1683 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
1684 "info->count is %d\n", info
->count
);
1687 if (--info
->count
< 0) {
1688 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
1689 info
->line
, info
->count
);
1693 #ifdef ISDN_DEBUG_MODEM_OPEN
1694 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
1698 info
->flags
|= ISDN_ASYNC_CLOSING
;
1700 * Save the termios structure, since this port may have
1701 * separate termios for callout and dialin.
1703 if (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
)
1704 info
->normal_termios
= *tty
->termios
;
1705 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
1706 info
->callout_termios
= *tty
->termios
;
1710 * At this point we stop accepting input. To do this, we
1711 * disable the receive line status interrupts, and tell the
1712 * interrupt driver to stop checking the data ready bit in the
1713 * line status register.
1715 if (info
->flags
& ISDN_ASYNC_INITIALIZED
) {
1716 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
1718 * Before we drop DTR, make sure the UART transmitter
1719 * has completely drained; this is especially
1720 * important if there is a transmit FIFO!
1722 timeout
= jiffies
+ HZ
;
1723 while (!(info
->lsr
& UART_LSR_TEMT
)) {
1724 set_current_state(TASK_INTERRUPTIBLE
);
1725 schedule_timeout(20);
1726 if (time_after(jiffies
,timeout
))
1731 isdn_tty_shutdown(info
);
1733 if (tty
->driver
->flush_buffer
)
1734 tty
->driver
->flush_buffer(tty
);
1735 tty_ldisc_flush(tty
);
1739 module_put(info
->owner
);
1740 if (info
->blocked_open
) {
1741 msleep_interruptible(500);
1742 wake_up_interruptible(&info
->open_wait
);
1744 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CLOSING
);
1745 wake_up_interruptible(&info
->close_wait
);
1746 #ifdef ISDN_DEBUG_MODEM_OPEN
1747 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
1752 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1755 isdn_tty_hangup(struct tty_struct
*tty
)
1757 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1759 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_hangup"))
1761 isdn_tty_shutdown(info
);
1763 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CALLOUT_ACTIVE
);
1765 wake_up_interruptible(&info
->open_wait
);
1768 /* This routine initializes all emulator-data.
1771 isdn_tty_reset_profile(atemu
* m
)
1784 m
->profile
[11] = 70;
1785 m
->profile
[12] = 0x45;
1787 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
1788 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
1789 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
1790 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
1799 #ifdef CONFIG_ISDN_AUDIO
1801 isdn_tty_modem_reset_vpar(atemu
* m
)
1803 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
1804 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
1805 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
1806 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1807 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
1808 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1812 #ifdef CONFIG_ISDN_TTY_FAX
1814 isdn_tty_modem_reset_faxpar(modem_info
* info
)
1816 T30_s
*f
= info
->fax
;
1819 f
->phase
= ISDN_FAX_PHASE_IDLE
;
1821 f
->resolution
= 1; /* fine */
1822 f
->rate
= 5; /* 14400 bit/s */
1829 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
1830 f
->id
[FAXIDLEN
- 1] = 0;
1841 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
1842 f
->pollid
[FAXIDLEN
- 1] = 0;
1847 isdn_tty_modem_reset_regs(modem_info
* info
, int force
)
1849 atemu
*m
= &info
->emu
;
1850 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
1851 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
1852 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
1853 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
1854 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
1856 #ifdef CONFIG_ISDN_AUDIO
1857 isdn_tty_modem_reset_vpar(m
);
1859 #ifdef CONFIG_ISDN_TTY_FAX
1860 isdn_tty_modem_reset_faxpar(info
);
1866 modem_write_profile(atemu
* m
)
1868 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
1869 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
1870 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
1872 send_sig(SIGIO
, dev
->profd
, 1);
1875 static struct tty_operations modem_ops
= {
1876 .open
= isdn_tty_open
,
1877 .close
= isdn_tty_close
,
1878 .write
= isdn_tty_write
,
1879 .flush_chars
= isdn_tty_flush_chars
,
1880 .write_room
= isdn_tty_write_room
,
1881 .chars_in_buffer
= isdn_tty_chars_in_buffer
,
1882 .flush_buffer
= isdn_tty_flush_buffer
,
1883 .ioctl
= isdn_tty_ioctl
,
1884 .throttle
= isdn_tty_throttle
,
1885 .unthrottle
= isdn_tty_unthrottle
,
1886 .set_termios
= isdn_tty_set_termios
,
1887 .hangup
= isdn_tty_hangup
,
1888 .tiocmget
= isdn_tty_tiocmget
,
1889 .tiocmset
= isdn_tty_tiocmset
,
1893 isdn_tty_modem_init(void)
1900 m
->tty_modem
= alloc_tty_driver(ISDN_MAX_CHANNELS
);
1903 m
->tty_modem
->name
= "ttyI";
1904 m
->tty_modem
->devfs_name
= "isdn/ttyI";
1905 m
->tty_modem
->major
= ISDN_TTY_MAJOR
;
1906 m
->tty_modem
->minor_start
= 0;
1907 m
->tty_modem
->type
= TTY_DRIVER_TYPE_SERIAL
;
1908 m
->tty_modem
->subtype
= SERIAL_TYPE_NORMAL
;
1909 m
->tty_modem
->init_termios
= tty_std_termios
;
1910 m
->tty_modem
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1911 m
->tty_modem
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
;
1912 m
->tty_modem
->driver_name
= "isdn_tty";
1913 tty_set_operations(m
->tty_modem
, &modem_ops
);
1914 retval
= tty_register_driver(m
->tty_modem
);
1916 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
1919 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1921 #ifdef CONFIG_ISDN_TTY_FAX
1922 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
1923 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
1925 goto err_unregister
;
1929 info
->owner
= THIS_MODULE
;
1931 spin_lock_init(&info
->readlock
);
1932 init_MUTEX(&info
->write_sem
);
1933 sprintf(info
->last_cause
, "0000");
1934 sprintf(info
->last_num
, "none");
1936 info
->last_lhup
= 1;
1939 isdn_tty_reset_profile(&info
->emu
);
1940 isdn_tty_modem_reset_regs(info
, 1);
1941 info
->magic
= ISDN_ASYNC_MAGIC
;
1946 info
->blocked_open
= 0;
1947 init_waitqueue_head(&info
->open_wait
);
1948 init_waitqueue_head(&info
->close_wait
);
1949 info
->isdn_driver
= -1;
1950 info
->isdn_channel
= -1;
1951 info
->drv_index
= -1;
1952 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
1953 init_timer(&info
->nc_timer
);
1954 info
->nc_timer
.function
= isdn_tty_modem_do_ncarrier
;
1955 info
->nc_timer
.data
= (unsigned long) info
;
1956 skb_queue_head_init(&info
->xmit_queue
);
1957 #ifdef CONFIG_ISDN_AUDIO
1958 skb_queue_head_init(&info
->dtmf_queue
);
1960 if (!(info
->xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5, GFP_KERNEL
))) {
1961 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
1963 goto err_unregister
;
1965 /* Make room for T.70 header */
1966 info
->xmit_buf
+= 4;
1970 for (i
--; i
>= 0; i
--) {
1972 #ifdef CONFIG_ISDN_TTY_FAX
1975 kfree(info
->xmit_buf
- 4);
1977 tty_unregister_driver(m
->tty_modem
);
1979 put_tty_driver(m
->tty_modem
);
1980 m
->tty_modem
= NULL
;
1990 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1991 info
= &dev
->mdm
.info
[i
];
1992 isdn_tty_cleanup_xmit(info
);
1993 #ifdef CONFIG_ISDN_TTY_FAX
1996 kfree(info
->xmit_buf
- 4);
1998 tty_unregister_driver(dev
->mdm
.tty_modem
);
1999 put_tty_driver(dev
->mdm
.tty_modem
);
2000 dev
->mdm
.tty_modem
= NULL
;
2005 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
2006 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
2007 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
2011 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
2013 #ifdef ISDN_DEBUG_MODEM_ICALL
2014 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
2015 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
2016 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
2018 if (strlen(emu
->lmsn
)) {
2019 char *p
= emu
->lmsn
;
2025 if ((q
= strchr(p
, ';')))
2027 if ((tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
2029 #ifdef ISDN_DEBUG_MODEM_ICALL
2030 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2031 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2046 tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
2047 #ifdef ISDN_DEBUG_MODEM_ICALL
2048 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
2049 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2056 * An incoming call-request has arrived.
2057 * Search the tty-devices for an appropriate device and bind
2058 * it to the ISDN-Channel.
2061 * 0 = No matching device found.
2062 * 1 = A matching device found.
2063 * 3 = No match found, but eventually would match, if
2067 isdn_tty_find_icall(int di
, int ch
, setup_parm
*setup
)
2078 if (!setup
->phone
[0]) {
2080 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
2083 si1
= (int) setup
->si1
;
2084 si2
= (int) setup
->si2
;
2085 if (!setup
->eazmsn
[0]) {
2086 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
2089 eaz
= setup
->eazmsn
;
2090 #ifdef ISDN_DEBUG_MODEM_ICALL
2091 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
2094 spin_lock_irqsave(&dev
->lock
, flags
);
2095 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2096 modem_info
*info
= &dev
->mdm
.info
[i
];
2098 if (info
->count
== 0)
2100 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
2101 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
2102 idx
= isdn_dc2minor(di
, ch
);
2103 #ifdef ISDN_DEBUG_MODEM_ICALL
2104 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
2105 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
2106 info
->flags
, info
->isdn_driver
, info
->isdn_channel
,
2110 #ifndef FIX_FILE_TRANSFER
2111 (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
) &&
2113 (info
->isdn_driver
== -1) &&
2114 (info
->isdn_channel
== -1) &&
2115 (USG_NONE(dev
->usage
[idx
]))) {
2118 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
2120 if (!matchret
) { /* EAZ is matching */
2121 info
->isdn_driver
= di
;
2122 info
->isdn_channel
= ch
;
2123 info
->drv_index
= idx
;
2124 dev
->m_idx
[idx
] = info
->line
;
2125 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2126 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
2127 strcpy(dev
->num
[idx
], nr
);
2128 strcpy(info
->emu
.cpn
, eaz
);
2129 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
2130 info
->emu
.mdmreg
[REG_PLAN
] = setup
->plan
;
2131 info
->emu
.mdmreg
[REG_SCREEN
] = setup
->screen
;
2133 spin_unlock_irqrestore(&dev
->lock
, flags
);
2134 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2136 info
->msr
|= UART_MSR_RI
;
2137 isdn_tty_modem_result(RESULT_RING
, info
);
2138 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2144 spin_unlock_irqrestore(&dev
->lock
, flags
);
2145 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2146 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2))? "rejected" : "ignored");
2147 return (wret
== 2)?3:0;
2150 #define TTY_IS_ACTIVE(info) \
2151 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2154 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2162 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2163 info
= &dev
->mdm
.info
[mi
];
2164 switch (c
->command
) {
2165 case ISDN_STAT_CINF
:
2166 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2167 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2168 if (e
== (char *)c
->parm
.num
)
2169 info
->emu
.charge
= 0;
2172 case ISDN_STAT_BSENT
:
2173 #ifdef ISDN_TTY_STAT_DEBUG
2174 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2176 if ((info
->isdn_driver
== c
->driver
) &&
2177 (info
->isdn_channel
== c
->arg
)) {
2178 info
->msr
|= UART_MSR_CTS
;
2179 if (info
->send_outstanding
)
2180 if (!(--info
->send_outstanding
))
2181 info
->lsr
|= UART_LSR_TEMT
;
2182 isdn_tty_tint(info
);
2186 case ISDN_STAT_CAUSE
:
2187 #ifdef ISDN_TTY_STAT_DEBUG
2188 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2190 /* Signal cause to tty-device */
2191 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2193 case ISDN_STAT_DISPLAY
:
2194 #ifdef ISDN_TTY_STAT_DEBUG
2195 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2197 /* Signal display to tty-device */
2198 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2199 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2200 isdn_tty_at_cout("\r\n", info
);
2201 isdn_tty_at_cout("DISPLAY: ", info
);
2202 isdn_tty_at_cout(c
->parm
.display
, info
);
2203 isdn_tty_at_cout("\r\n", info
);
2206 case ISDN_STAT_DCONN
:
2207 #ifdef ISDN_TTY_STAT_DEBUG
2208 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2210 if (TTY_IS_ACTIVE(info
)) {
2211 if (info
->dialing
== 1) {
2217 case ISDN_STAT_DHUP
:
2218 #ifdef ISDN_TTY_STAT_DEBUG
2219 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2221 if (TTY_IS_ACTIVE(info
)) {
2222 if (info
->dialing
== 1)
2223 isdn_tty_modem_result(RESULT_BUSY
, info
);
2224 if (info
->dialing
> 1)
2225 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2227 #ifdef ISDN_DEBUG_MODEM_HUP
2228 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2230 isdn_tty_modem_hup(info
, 0);
2234 case ISDN_STAT_BCONN
:
2235 #ifdef ISDN_TTY_STAT_DEBUG
2236 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2238 /* Wake up any processes waiting
2239 * for incoming call of this device when
2240 * DCD follow the state of incoming carrier
2242 if (info
->blocked_open
&&
2243 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
)) {
2244 wake_up_interruptible(&info
->open_wait
);
2247 /* Schedule CONNECT-Message to any tty
2248 * waiting for it and
2249 * set DCD-bit of its modem-status.
2251 if (TTY_IS_ACTIVE(info
) ||
2252 (info
->blocked_open
&& (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
))) {
2253 info
->msr
|= UART_MSR_DCD
;
2254 info
->emu
.charge
= 0;
2255 if (info
->dialing
& 0xf)
2261 if (USG_MODEM(dev
->usage
[i
])) {
2262 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2263 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2264 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2266 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2268 if (USG_VOICE(dev
->usage
[i
]))
2269 isdn_tty_modem_result(RESULT_VCON
, info
);
2273 case ISDN_STAT_BHUP
:
2274 #ifdef ISDN_TTY_STAT_DEBUG
2275 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2277 if (TTY_IS_ACTIVE(info
)) {
2278 #ifdef ISDN_DEBUG_MODEM_HUP
2279 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2281 isdn_tty_modem_hup(info
, 0);
2285 case ISDN_STAT_NODCH
:
2286 #ifdef ISDN_TTY_STAT_DEBUG
2287 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2289 if (TTY_IS_ACTIVE(info
)) {
2290 if (info
->dialing
) {
2294 sprintf(info
->last_cause
, "0000");
2295 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2297 isdn_tty_modem_hup(info
, 0);
2301 case ISDN_STAT_UNLOAD
:
2302 #ifdef ISDN_TTY_STAT_DEBUG
2303 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2305 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2306 info
= &dev
->mdm
.info
[i
];
2307 if (info
->isdn_driver
== c
->driver
) {
2309 isdn_tty_modem_hup(info
, 1);
2313 #ifdef CONFIG_ISDN_TTY_FAX
2314 case ISDN_STAT_FAXIND
:
2315 if (TTY_IS_ACTIVE(info
)) {
2316 isdn_tty_fax_command(info
, c
);
2320 #ifdef CONFIG_ISDN_AUDIO
2321 case ISDN_STAT_AUDIO
:
2322 if (TTY_IS_ACTIVE(info
)) {
2323 switch(c
->parm
.num
[0]) {
2324 case ISDN_AUDIO_DTMF
:
2325 if (info
->vonline
) {
2326 isdn_audio_put_dle_code(info
,
2339 /*********************************************************************
2340 Modem-Emulator-Routines
2341 *********************************************************************/
2343 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2346 * Put a message from the AT-emulator into receive-buffer of tty,
2347 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2350 isdn_tty_at_cout(char *msg
, modem_info
* info
)
2352 struct tty_struct
*tty
;
2353 atemu
*m
= &info
->emu
;
2357 struct sk_buff
*skb
= NULL
;
2361 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2364 spin_lock_irqsave(&info
->readlock
, flags
);
2366 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!tty
)) {
2367 spin_unlock_irqrestore(&info
->readlock
, flags
);
2371 /* use queue instead of direct flip, if online and */
2372 /* data is in queue or flip buffer is full */
2373 if ((info
->online
) && (((tty
->flip
.count
+ strlen(msg
)) >= TTY_FLIPBUF_SIZE
) ||
2374 (!skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
])))) {
2375 skb
= alloc_skb(strlen(msg
), GFP_ATOMIC
);
2377 spin_unlock_irqrestore(&info
->readlock
, flags
);
2380 sp
= skb_put(skb
, strlen(msg
));
2381 #ifdef CONFIG_ISDN_AUDIO
2382 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2383 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2387 for (p
= msg
; *p
; p
++) {
2390 c
= m
->mdmreg
[REG_CR
];
2393 c
= m
->mdmreg
[REG_LF
];
2396 c
= m
->mdmreg
[REG_BS
];
2404 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
2406 tty_insert_flip_char(tty
, c
, 0);
2410 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2411 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2412 spin_unlock_irqrestore(&info
->readlock
, flags
);
2413 /* Schedule dequeuing */
2414 if ((dev
->modempoll
) && (info
->rcvsched
))
2415 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2418 spin_unlock_irqrestore(&info
->readlock
, flags
);
2419 schedule_delayed_work(&tty
->flip
.work
, 1);
2424 * Perform ATH Hangup
2427 isdn_tty_on_hook(modem_info
* info
)
2429 if (info
->isdn_channel
>= 0) {
2430 #ifdef ISDN_DEBUG_MODEM_HUP
2431 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2433 isdn_tty_modem_hup(info
, 1);
2438 isdn_tty_off_hook(void)
2440 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2443 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2444 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2447 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2448 * isdn_tty_modem_escape() if sequence found.
2451 * p pointer to databuffer
2452 * plus escape-character
2453 * count length of buffer
2454 * pluscount count of valid escape-characters so far
2455 * lastplus timestamp of last character
2458 isdn_tty_check_esc(const u_char
* p
, u_char plus
, int count
, int *pluscount
,
2469 if (*(p
++) == plus
) {
2470 if ((*pluscount
)++) {
2471 /* Time since last '+' > 0.5 sec. ? */
2472 if (time_after(jiffies
, *lastplus
+ PLUSWAIT1
))
2475 /* Time since last non-'+' < 1.5 sec. ? */
2476 if (time_before(jiffies
, *lastplus
+ PLUSWAIT2
))
2479 if ((*pluscount
== 3) && (count
== 1))
2480 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2485 *lastplus
= jiffies
;
2491 * Return result of AT-emulator to tty-receive-buffer, depending on
2492 * modem-register 12, bit 0 and 1.
2493 * For CONNECT-messages also switch to online-mode.
2494 * For RING-message handle auto-ATA if register 0 != 0
2498 isdn_tty_modem_result(int code
, modem_info
* info
)
2500 atemu
*m
= &info
->emu
;
2501 static char *msg
[] =
2502 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2503 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2504 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2505 char s
[ISDN_MSNLEN
+10];
2509 m
->mdmreg
[REG_RINGCNT
]++;
2510 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2511 /* Automatically accept incoming call */
2512 isdn_tty_cmd_ATA(info
);
2514 case RESULT_NO_CARRIER
:
2515 #ifdef ISDN_DEBUG_MODEM_HUP
2516 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2517 (info
->flags
& ISDN_ASYNC_CLOSING
),
2520 m
->mdmreg
[REG_RINGCNT
] = 0;
2521 del_timer(&info
->nc_timer
);
2523 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2526 #ifdef CONFIG_ISDN_AUDIO
2527 if (info
->vonline
& 1) {
2528 #ifdef ISDN_DEBUG_MODEM_VOICE
2529 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
2532 /* voice-recording, add DLE-ETX */
2533 isdn_tty_at_cout("\020\003", info
);
2535 if (info
->vonline
& 2) {
2536 #ifdef ISDN_DEBUG_MODEM_VOICE
2537 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
2540 /* voice-playing, add DLE-DC4 */
2541 isdn_tty_at_cout("\020\024", info
);
2545 case RESULT_CONNECT
:
2546 case RESULT_CONNECT64000
:
2547 sprintf(info
->last_cause
, "0000");
2552 #ifdef ISDN_DEBUG_MODEM_VOICE
2553 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
2556 sprintf(info
->last_cause
, "0000");
2560 } /* switch(code) */
2562 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
2564 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
2565 /* Show numeric results only */
2566 sprintf(s
, "\r\n%d\r\n", code
);
2567 isdn_tty_at_cout(s
, info
);
2569 if (code
== RESULT_RING
) {
2570 /* return if "show RUNG" and ringcounter>1 */
2571 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
2572 (m
->mdmreg
[REG_RINGCNT
] > 1))
2574 /* print CID, _before_ _every_ ring */
2575 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
2576 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
2577 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2578 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2579 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2580 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2584 isdn_tty_at_cout("\r\n", info
);
2585 isdn_tty_at_cout(msg
[code
], info
);
2587 case RESULT_CONNECT
:
2588 switch (m
->mdmreg
[REG_L2PROT
]) {
2589 case ISDN_PROTO_L2_MODEM
:
2590 isdn_tty_at_cout(" ", info
);
2591 isdn_tty_at_cout(m
->connmsg
, info
);
2596 /* Append CPN, if enabled */
2597 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
2598 sprintf(s
, "/%s", m
->cpn
);
2599 isdn_tty_at_cout(s
, info
);
2601 /* Print CID only once, _after_ 1st RING */
2602 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
2603 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
2604 isdn_tty_at_cout("\r\n", info
);
2605 isdn_tty_at_cout("CALLER NUMBER: ", info
);
2606 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2607 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2608 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2609 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2613 case RESULT_NO_CARRIER
:
2614 case RESULT_NO_DIALTONE
:
2616 case RESULT_NO_ANSWER
:
2617 m
->mdmreg
[REG_RINGCNT
] = 0;
2618 /* Append Cause-Message if enabled */
2619 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
2620 sprintf(s
, "/%s", info
->last_cause
);
2621 isdn_tty_at_cout(s
, info
);
2624 case RESULT_CONNECT64000
:
2625 /* Append Protocol to CONNECT message */
2626 switch (m
->mdmreg
[REG_L2PROT
]) {
2627 case ISDN_PROTO_L2_X75I
:
2628 case ISDN_PROTO_L2_X75UI
:
2629 case ISDN_PROTO_L2_X75BUI
:
2630 isdn_tty_at_cout("/X.75", info
);
2632 case ISDN_PROTO_L2_HDLC
:
2633 isdn_tty_at_cout("/HDLC", info
);
2635 case ISDN_PROTO_L2_V11096
:
2636 isdn_tty_at_cout("/V110/9600", info
);
2638 case ISDN_PROTO_L2_V11019
:
2639 isdn_tty_at_cout("/V110/19200", info
);
2641 case ISDN_PROTO_L2_V11038
:
2642 isdn_tty_at_cout("/V110/38400", info
);
2645 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2646 isdn_tty_at_cout("/T.70", info
);
2647 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2648 isdn_tty_at_cout("+", info
);
2652 isdn_tty_at_cout("\r\n", info
);
2655 if (code
== RESULT_NO_CARRIER
) {
2656 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2659 tty_ldisc_flush(info
->tty
);
2660 if ((info
->flags
& ISDN_ASYNC_CHECK_CD
) &&
2661 (!((info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
2662 (info
->flags
& ISDN_ASYNC_CALLOUT_NOHUP
)))) {
2663 tty_hangup(info
->tty
);
2670 * Display a modem-register-value.
2673 isdn_tty_show_profile(int ridx
, modem_info
* info
)
2677 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
2678 isdn_tty_at_cout(v
, info
);
2682 * Get MSN-string from char-pointer, set pointer to end of number
2685 isdn_tty_get_msnstr(char *n
, char **p
)
2687 int limit
= ISDN_MSNLEN
- 1;
2689 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
2690 /* Why a comma ??? */
2691 (*p
[0] == ',') || (*p
[0] == ':')) &&
2698 * Get phone-number from modem-commandbuffer
2701 isdn_tty_getdial(char *p
, char *q
,int cnt
)
2704 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
2707 while (strchr(" 0123456789,#.*WPTS-", *p
) && *p
&& --cnt
>0) {
2708 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
2709 (*p
== '*') || (*p
== '#')) {
2721 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2722 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2725 isdn_tty_report(modem_info
* info
)
2727 atemu
*m
= &info
->emu
;
2730 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
2731 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
2732 isdn_tty_at_cout(s
, info
);
2733 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
2734 isdn_tty_at_cout(s
, info
);
2735 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
2736 switch (info
->last_l2
) {
2737 case ISDN_PROTO_L2_X75I
:
2738 isdn_tty_at_cout("X.75i", info
);
2740 case ISDN_PROTO_L2_X75UI
:
2741 isdn_tty_at_cout("X.75ui", info
);
2743 case ISDN_PROTO_L2_X75BUI
:
2744 isdn_tty_at_cout("X.75bui", info
);
2746 case ISDN_PROTO_L2_HDLC
:
2747 isdn_tty_at_cout("HDLC", info
);
2749 case ISDN_PROTO_L2_V11096
:
2750 isdn_tty_at_cout("V.110 9600 Baud", info
);
2752 case ISDN_PROTO_L2_V11019
:
2753 isdn_tty_at_cout("V.110 19200 Baud", info
);
2755 case ISDN_PROTO_L2_V11038
:
2756 isdn_tty_at_cout("V.110 38400 Baud", info
);
2758 case ISDN_PROTO_L2_TRANS
:
2759 isdn_tty_at_cout("transparent", info
);
2761 case ISDN_PROTO_L2_MODEM
:
2762 isdn_tty_at_cout("modem", info
);
2764 case ISDN_PROTO_L2_FAX
:
2765 isdn_tty_at_cout("fax", info
);
2768 isdn_tty_at_cout("unknown", info
);
2771 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2772 isdn_tty_at_cout("/T.70", info
);
2773 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2774 isdn_tty_at_cout("+", info
);
2776 isdn_tty_at_cout("\r\n", info
);
2777 isdn_tty_at_cout(" Service: ", info
);
2778 switch (info
->last_si
) {
2780 isdn_tty_at_cout("audio\r\n", info
);
2783 isdn_tty_at_cout("btx\r\n", info
);
2786 isdn_tty_at_cout("data\r\n", info
);
2789 sprintf(s
, "%d\r\n", info
->last_si
);
2790 isdn_tty_at_cout(s
, info
);
2793 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
2794 isdn_tty_at_cout(s
, info
);
2795 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
2796 isdn_tty_at_cout(s
, info
);
2800 * Parse AT&.. commands.
2803 isdn_tty_cmd_ATand(char **p
, modem_info
* info
)
2805 atemu
*m
= &info
->emu
;
2809 #define MAXRB (sizeof(rb) - 1)
2813 /* &B - Set Buffersize */
2816 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
2818 #ifdef CONFIG_ISDN_AUDIO
2819 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
2822 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
2823 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2824 switch (m
->mdmreg
[REG_L2PROT
]) {
2825 case ISDN_PROTO_L2_V11096
:
2826 case ISDN_PROTO_L2_V11019
:
2827 case ISDN_PROTO_L2_V11038
:
2828 info
->xmit_size
/= 10;
2832 /* &C - DCD Status */
2834 switch (isdn_getnum(p
)) {
2836 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
2839 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
2846 /* &D - Set DTR-Low-behavior */
2848 switch (isdn_getnum(p
)) {
2850 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
2851 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2854 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2855 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2858 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2859 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
2866 /* &E -Set EAZ/MSN */
2868 isdn_tty_get_msnstr(m
->msn
, p
);
2871 /* &F -Set Factory-Defaults */
2873 if (info
->msr
& UART_MSR_DCD
)
2875 isdn_tty_reset_profile(m
);
2876 isdn_tty_modem_reset_regs(info
, 1);
2878 #ifdef DUMMY_HAYES_AT
2880 /* only for be compilant with common scripts */
2881 /* &K Flowcontrol - no function */
2887 /* &L -Set Numbers to listen on */
2890 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
2892 m
->lmsn
[i
++] = *p
[0]++;
2896 /* &R - Set V.110 bitrate adaption */
2901 /* Switch off V.110, back to X.75 */
2902 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2903 m
->mdmreg
[REG_SI2
] = 0;
2904 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2907 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
2908 m
->mdmreg
[REG_SI2
] = 197;
2909 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2912 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
2913 m
->mdmreg
[REG_SI2
] = 199;
2914 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2917 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
2918 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
2919 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2924 /* Switch off T.70 */
2925 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2927 m
->mdmreg
[REG_SI1
] |= 4;
2930 /* &S - Set Windowsize */
2933 if ((i
> 0) && (i
< 9))
2934 m
->mdmreg
[REG_WSIZE
] = i
;
2939 /* &V - Show registers */
2941 isdn_tty_at_cout("\r\n", info
);
2942 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
2943 sprintf(rb
, "S%02d=%03d%s", i
,
2944 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
2945 isdn_tty_at_cout(rb
, info
);
2947 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
2948 strlen(m
->msn
) ? m
->msn
: "None");
2949 isdn_tty_at_cout(rb
, info
);
2950 if (strlen(m
->lmsn
)) {
2951 isdn_tty_at_cout("\r\nListen: ", info
);
2952 isdn_tty_at_cout(m
->lmsn
, info
);
2953 isdn_tty_at_cout("\r\n", info
);
2957 /* &W - Write Profile */
2962 modem_write_profile(m
);
2969 /* &X - Switch to BTX-Mode and T.70 */
2971 switch (isdn_getnum(p
)) {
2973 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2974 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2977 m
->mdmreg
[REG_T70
] |= BIT_T70
;
2978 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
2979 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2980 info
->xmit_size
= 112;
2981 m
->mdmreg
[REG_SI1
] = 4;
2982 m
->mdmreg
[REG_SI2
] = 0;
2985 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
2986 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2987 info
->xmit_size
= 112;
2988 m
->mdmreg
[REG_SI1
] = 4;
2989 m
->mdmreg
[REG_SI2
] = 0;
3002 isdn_tty_check_ats(int mreg
, int mval
, modem_info
* info
, atemu
* m
)
3004 /* Some plausibility checks */
3007 if (mval
> ISDN_PROTO_L2_MAX
)
3011 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
3013 #ifdef CONFIG_ISDN_AUDIO
3014 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
3017 info
->xmit_size
= mval
* 16;
3018 switch (m
->mdmreg
[REG_L2PROT
]) {
3019 case ISDN_PROTO_L2_V11096
:
3020 case ISDN_PROTO_L2_V11019
:
3021 case ISDN_PROTO_L2_V11038
:
3022 info
->xmit_size
/= 10;
3028 /* readonly registers */
3035 * Perform ATS command
3038 isdn_tty_cmd_ATS(char **p
, modem_info
* info
)
3040 atemu
*m
= &info
->emu
;
3046 mreg
= isdn_getnum(p
);
3047 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
3052 mval
= isdn_getnum(p
);
3053 if (mval
< 0 || mval
> 255)
3055 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3057 m
->mdmreg
[mreg
] = mval
;
3060 /* Set/Clear a single bit */
3062 bitpos
= isdn_getnum(p
);
3063 if ((bitpos
< 0) || (bitpos
> 7))
3068 bval
= isdn_getnum(p
);
3069 if (bval
< 0 || bval
> 1)
3072 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
3074 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
3075 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3077 m
->mdmreg
[mreg
] = mval
;
3081 isdn_tty_at_cout("\r\n", info
);
3082 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
3091 isdn_tty_show_profile(mreg
, info
);
3101 * Perform ATA command
3104 isdn_tty_cmd_ATA(modem_info
* info
)
3106 atemu
*m
= &info
->emu
;
3110 if (info
->msr
& UART_MSR_RI
) {
3111 /* Accept incoming call */
3113 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
3114 m
->mdmreg
[REG_RINGCNT
] = 0;
3115 info
->msr
&= ~UART_MSR_RI
;
3116 l2
= m
->mdmreg
[REG_L2PROT
];
3117 #ifdef CONFIG_ISDN_AUDIO
3118 /* If more than one bit set in reg18, autoselect Layer2 */
3119 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
3120 if (m
->mdmreg
[REG_SI1I
] == 1) {
3121 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
3122 l2
= ISDN_PROTO_L2_TRANS
;
3124 l2
= ISDN_PROTO_L2_X75I
;
3127 cmd
.driver
= info
->isdn_driver
;
3128 cmd
.command
= ISDN_CMD_SETL2
;
3129 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
3132 cmd
.driver
= info
->isdn_driver
;
3133 cmd
.command
= ISDN_CMD_SETL3
;
3134 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
3135 #ifdef CONFIG_ISDN_TTY_FAX
3136 if (l2
== ISDN_PROTO_L2_FAX
) {
3137 cmd
.parm
.fax
= info
->fax
;
3138 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3142 cmd
.driver
= info
->isdn_driver
;
3143 cmd
.arg
= info
->isdn_channel
;
3144 cmd
.command
= ISDN_CMD_ACCEPTD
;
3146 info
->emu
.carrierwait
= 0;
3148 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3150 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3153 #ifdef CONFIG_ISDN_AUDIO
3155 * Parse AT+F.. commands
3158 isdn_tty_cmd_PLUSF(char **p
, modem_info
* info
)
3160 atemu
*m
= &info
->emu
;
3163 if (!strncmp(p
[0], "CLASS", 5)) {
3168 sprintf(rs
, "\r\n%d",
3169 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3170 #ifdef CONFIG_ISDN_TTY_FAX
3171 if (TTY_IS_FCLASS2(info
))
3172 sprintf(rs
, "\r\n2");
3173 else if (TTY_IS_FCLASS1(info
))
3174 sprintf(rs
, "\r\n1");
3176 isdn_tty_at_cout(rs
, info
);
3183 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3184 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3185 m
->mdmreg
[REG_SI1
] = 4;
3187 m
->mdmreg
[REG_PSIZE
] * 16;
3189 #ifdef CONFIG_ISDN_TTY_FAX
3192 if (!(dev
->global_features
&
3193 ISDN_FEATURE_L3_FCLASS1
))
3195 m
->mdmreg
[REG_SI1
] = 1;
3196 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3197 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3199 m
->mdmreg
[REG_PSIZE
] * 16;
3203 if (!(dev
->global_features
&
3204 ISDN_FEATURE_L3_FCLASS2
))
3206 m
->mdmreg
[REG_SI1
] = 1;
3207 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3208 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3210 m
->mdmreg
[REG_PSIZE
] * 16;
3215 /* L2 will change on dialout with si=1 */
3216 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3217 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3218 m
->mdmreg
[REG_SI1
] = 5;
3219 info
->xmit_size
= VBUF
;
3223 strcpy(rs
, "\r\n0,");
3224 #ifdef CONFIG_ISDN_TTY_FAX
3225 if (dev
->global_features
&
3226 ISDN_FEATURE_L3_FCLASS1
)
3228 if (dev
->global_features
&
3229 ISDN_FEATURE_L3_FCLASS2
)
3233 isdn_tty_at_cout(rs
, info
);
3244 #ifdef CONFIG_ISDN_TTY_FAX
3245 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3252 * Parse AT+V.. commands
3255 isdn_tty_cmd_PLUSV(char **p
, modem_info
* info
)
3257 atemu
*m
= &info
->emu
;
3259 static char *vcmd
[] =
3260 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3268 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3276 /* AT+VNH - Auto hangup feature */
3280 isdn_tty_at_cout("\r\n1", info
);
3290 isdn_tty_at_cout("\r\n1", info
);
3301 /* AT+VIP - Reset all voice parameters */
3302 isdn_tty_modem_reset_vpar(m
);
3305 /* AT+VLS - Select device, accept incoming call */
3309 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3310 isdn_tty_at_cout(rs
, info
);
3325 isdn_tty_at_cout("\r\n0,2", info
);
3336 /* AT+VRX - Start recording */
3339 if (info
->online
!= 1) {
3340 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3343 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3344 if (!info
->dtmf_state
) {
3345 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3348 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3349 if (!info
->silence_state
) {
3350 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3353 if (m
->vpar
[3] < 5) {
3354 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3355 if (!info
->adpcmr
) {
3356 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3360 #ifdef ISDN_DEBUG_AT
3361 printk(KERN_DEBUG
"AT: +VRX\n");
3364 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3368 /* AT+VSD - Silence detection */
3372 sprintf(rs
, "\r\n<%d>,<%d>",
3375 isdn_tty_at_cout(rs
, info
);
3379 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3380 par1
= isdn_getnum(p
);
3381 if ((par1
< 0) || (par1
> 31))
3386 par2
= isdn_getnum(p
);
3387 if ((par2
< 0) || (par2
> 255))
3395 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3406 /* AT+VSM - Select compression */
3410 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3413 isdn_tty_at_cout(rs
, info
);
3423 par1
= isdn_getnum(p
);
3424 if ((par1
< 2) || (par1
> 6))
3430 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3432 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3434 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3436 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3438 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3450 /* AT+VTX - Start sending */
3453 if (info
->online
!= 1) {
3454 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3457 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3458 if (!info
->dtmf_state
) {
3459 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3462 if (m
->vpar
[3] < 5) {
3463 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3464 if (!info
->adpcms
) {
3465 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3469 #ifdef ISDN_DEBUG_AT
3470 printk(KERN_DEBUG
"AT: +VTX\n");
3474 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3478 /* AT+VDD - DTMF detection */
3482 sprintf(rs
, "\r\n<%d>,<%d>",
3485 isdn_tty_at_cout(rs
, info
);
3489 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3490 if (info
->online
!= 1)
3492 par1
= isdn_getnum(p
);
3493 if ((par1
< 0) || (par1
> 15))
3498 par2
= isdn_getnum(p
);
3499 if ((par2
< 0) || (par2
> 255))
3503 cmd
.driver
= info
->isdn_driver
;
3504 cmd
.command
= ISDN_CMD_AUDIO
;
3505 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3506 cmd
.parm
.num
[0] = par1
;
3507 cmd
.parm
.num
[1] = par2
;
3513 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3528 #endif /* CONFIG_ISDN_AUDIO */
3531 * Parse and perform an AT-command-line.
3534 isdn_tty_parse_at(modem_info
* info
)
3536 atemu
*m
= &info
->emu
;
3540 #ifdef ISDN_DEBUG_AT
3541 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
3543 for (p
= &m
->mdmcmd
[2]; *p
;) {
3549 /* A - Accept incoming call */
3551 isdn_tty_cmd_ATA(info
);
3556 if (info
->msr
& UART_MSR_DCD
)
3558 if (info
->msr
& UART_MSR_RI
) {
3559 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3562 isdn_tty_getdial(++p
, ds
, sizeof ds
);
3564 if (!strlen(m
->msn
))
3565 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
3566 else if (strlen(ds
))
3567 isdn_tty_dial(ds
, info
, m
);
3572 /* E - Turn Echo on/off */
3574 switch (isdn_getnum(&p
)) {
3576 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
3579 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
3586 /* H - On/Off-hook */
3591 isdn_tty_on_hook(info
);
3595 isdn_tty_off_hook();
3598 isdn_tty_on_hook(info
);
3603 /* I - Information */
3605 isdn_tty_at_cout("\r\nLinux ISDN", info
);
3613 isdn_tty_report(info
);
3617 sprintf(ds
, "\r\n%d", info
->emu
.charge
);
3618 isdn_tty_at_cout(ds
, info
);
3623 #ifdef DUMMY_HAYES_AT
3626 /* only for be compilant with common scripts */
3635 if (info
->msr
& UART_MSR_DCD
)
3636 /* if B-Channel is up */
3637 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
:RESULT_CONNECT64000
, info
);
3639 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3642 /* Q - Turn Emulator messages on/off */
3644 switch (isdn_getnum(&p
)) {
3646 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
3649 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
3656 /* S - Set/Get Register */
3658 if (isdn_tty_cmd_ATS(&p
, info
))
3662 /* V - Numeric or ASCII Emulator-messages */
3664 switch (isdn_getnum(&p
)) {
3666 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
3669 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
3676 /* Z - Load Registers from Profile */
3678 if (info
->msr
& UART_MSR_DCD
) {
3680 isdn_tty_on_hook(info
);
3682 isdn_tty_modem_reset_regs(info
, 1);
3687 #ifdef CONFIG_ISDN_AUDIO
3690 if (isdn_tty_cmd_PLUSF(&p
, info
))
3694 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
3695 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
3698 if (isdn_tty_cmd_PLUSV(&p
, info
))
3701 #endif /* CONFIG_ISDN_AUDIO */
3702 case 'S': /* SUSPEND */
3704 isdn_tty_get_msnstr(ds
, &p
);
3705 isdn_tty_suspend(ds
, info
, m
);
3707 case 'R': /* RESUME */
3709 isdn_tty_get_msnstr(ds
, &p
);
3710 isdn_tty_resume(ds
, info
, m
);
3712 case 'M': /* MESSAGE */
3714 isdn_tty_send_msg(info
, m
, p
);
3722 if (isdn_tty_cmd_ATand(&p
, info
))
3729 #ifdef CONFIG_ISDN_AUDIO
3732 isdn_tty_modem_result(RESULT_OK
, info
);
3735 /* Need own toupper() because standard-toupper is not available
3738 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
3741 * Perform line-editing of AT-commands
3745 * count length of buffer
3746 * channel index to line (minor-device)
3749 isdn_tty_edit_at(const char *p
, int count
, modem_info
* info
)
3751 atemu
*m
= &info
->emu
;
3757 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
3760 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
3761 /* Separator (CR or LF) */
3762 m
->mdmcmd
[m
->mdmcmdl
] = 0;
3763 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3766 isdn_tty_at_cout(eb
, info
);
3768 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
3769 isdn_tty_parse_at(info
);
3773 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
3774 /* Backspace-Function */
3775 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
3778 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
3779 isdn_tty_at_cout("\b", info
);
3784 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3787 isdn_tty_at_cout(eb
, info
);
3789 if (m
->mdmcmdl
< 255) {
3791 switch (m
->mdmcmdl
) {
3794 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3795 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3799 /* Fall through, check for 'A' */
3802 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3803 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3807 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3808 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3817 * Switch all modem-channels who are online and got a valid
3818 * escape-sequence 1.5 seconds ago, to command-mode.
3819 * This function is called every second via timer-interrupt from within
3820 * timer-dispatcher isdn_timer_function()
3823 isdn_tty_modem_escape(void)
3829 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
3830 if (USG_MODEM(dev
->usage
[i
]))
3831 if ((midx
= dev
->m_idx
[i
]) >= 0) {
3832 modem_info
*info
= &dev
->mdm
.info
[midx
];
3835 if ((info
->emu
.pluscount
== 3) &&
3836 time_after(jiffies
, info
->emu
.lastplus
+ PLUSWAIT2
)) {
3837 info
->emu
.pluscount
= 0;
3839 isdn_tty_modem_result(RESULT_OK
, info
);
3843 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
3847 * Put a RING-message to all modem-channels who have the RI-bit set.
3848 * This function is called every second via timer-interrupt from within
3849 * timer-dispatcher isdn_timer_function()
3852 isdn_tty_modem_ring(void)
3857 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3858 modem_info
*info
= &dev
->mdm
.info
[i
];
3859 if (info
->msr
& UART_MSR_RI
) {
3861 isdn_tty_modem_result(RESULT_RING
, info
);
3864 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
3868 * For all online tty's, try sending data to
3872 isdn_tty_modem_xmit(void)
3877 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3878 modem_info
*info
= &dev
->mdm
.info
[i
];
3881 isdn_tty_senddown(info
);
3882 isdn_tty_tint(info
);
3885 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
3889 * Check all channels if we have a 'no carrier' timeout.
3890 * Timeout value is set by Register S7.
3893 isdn_tty_carrier_timeout(void)
3898 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3899 modem_info
*info
= &dev
->mdm
.info
[i
];
3900 if (info
->dialing
) {
3901 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
3903 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3904 isdn_tty_modem_hup(info
, 1);
3910 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);