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 "isdn_common.h"
18 #ifdef CONFIG_ISDN_AUDIO
19 #include "isdn_audio.h"
21 #define VBUFX (VBUF/16)
24 #define FIX_FILE_TRANSFER
25 #define DUMMY_HAYES_AT
29 static int isdn_tty_edit_at(const char *, int, modem_info
*, int);
30 static void isdn_tty_check_esc(const u_char
*, u_char
, int, int *, u_long
*, int);
31 static void isdn_tty_modem_reset_regs(modem_info
*, int);
32 static void isdn_tty_cmd_ATA(modem_info
*);
33 static void isdn_tty_flush_buffer(struct tty_struct
*);
34 static void isdn_tty_modem_result(int, modem_info
*);
35 #ifdef CONFIG_ISDN_AUDIO
36 static int isdn_tty_countDLE(unsigned char *, int);
39 /* Leave this unchanged unless you know what you do! */
40 #define MODEM_PARANOIA_CHECK
41 #define MODEM_DO_RESTART
43 static int bit2si
[8] =
44 {1, 5, 7, 7, 7, 7, 7, 7};
45 static int si2bit
[8] =
46 {4, 1, 4, 4, 4, 4, 4, 4};
48 char *isdn_tty_revision
= "$Revision: 1.1.2.3 $";
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
;
68 if ((tty
= info
->tty
)) {
69 if (info
->mcr
& UART_MCR_RTS
) {
70 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
72 #ifdef CONFIG_ISDN_AUDIO
73 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
77 #ifdef CONFIG_ISDN_AUDIO
78 if (ISDN_AUDIO_SKB_DLECOUNT(skb
))
80 if (*skb
->data
== DLE
)
81 tty_insert_flip_char(tty
, DLE
, 0);
82 tty_insert_flip_char(tty
, *skb
->data
++, 0);
85 memcpy(tty
->flip
.char_buf_ptr
,
87 tty
->flip
.count
+= len
;
88 tty
->flip
.char_buf_ptr
+= len
;
89 memset(tty
->flip
.flag_buf_ptr
, 0, len
);
90 tty
->flip
.flag_buf_ptr
+= len
;
91 #ifdef CONFIG_ISDN_AUDIO
94 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
95 tty
->flip
.flag_buf_ptr
[len
- 1] = 0xff;
96 schedule_delayed_work(&tty
->flip
.work
, 1);
106 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
107 * It tries getting received data from the receive queue an stuff it into
108 * the tty's flip-buffer.
111 isdn_tty_readmodem(void)
118 struct tty_struct
*tty
;
121 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
122 if ((midx
= dev
->m_idx
[i
]) >= 0) {
123 info
= &dev
->mdm
.info
[midx
];
126 #ifdef CONFIG_ISDN_AUDIO
127 isdn_audio_eval_dtmf(info
);
128 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
129 isdn_audio_eval_silence(info
);
131 if ((tty
= info
->tty
)) {
132 if (info
->mcr
& UART_MCR_RTS
) {
133 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
135 r
= isdn_readbchan(info
->isdn_driver
, info
->isdn_channel
,
136 tty
->flip
.char_buf_ptr
,
137 tty
->flip
.flag_buf_ptr
, c
, NULL
);
138 /* CISCO AsyncPPP Hack */
139 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
140 memset(tty
->flip
.flag_buf_ptr
, 0, r
);
141 tty
->flip
.count
+= r
;
142 tty
->flip
.flag_buf_ptr
+= r
;
143 tty
->flip
.char_buf_ptr
+= r
;
145 schedule_delayed_work(&tty
->flip
.work
, 1);
160 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
164 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
168 #ifdef CONFIG_ISDN_AUDIO
173 if ((midx
= dev
->m_idx
[i
]) < 0) {
174 /* if midx is invalid, packet is not for tty */
177 info
= &dev
->mdm
.info
[midx
];
178 #ifdef CONFIG_ISDN_AUDIO
181 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
182 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
183 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
184 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
186 if ((info
->online
< 2)
187 #ifdef CONFIG_ISDN_AUDIO
188 && (!(info
->vonline
& 1))
191 /* If Modem not listening, drop data */
195 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
196 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
197 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
198 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
201 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
204 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
205 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
208 #ifdef CONFIG_ISDN_AUDIO
209 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
210 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
211 if (info
->vonline
& 1) {
212 /* voice conversion/compression */
213 switch (info
->emu
.vpar
[3]) {
218 * Since compressed data takes less
219 * space, we can overwrite the buffer.
221 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
230 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
235 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
238 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
239 isdn_tty_countDLE(skb
->data
, skb
->len
);
241 #ifdef CONFIG_ISDN_TTY_FAX
243 if (info
->faxonline
& 2) {
244 isdn_tty_fax_bitorder(info
, skb
);
245 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
246 isdn_tty_countDLE(skb
->data
, skb
->len
);
251 /* Try to deliver directly via tty-flip-buf if queue is empty */
252 spin_lock_irqsave(&info
->readlock
, flags
);
253 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
254 if (isdn_tty_try_read(info
, skb
)) {
255 spin_unlock_irqrestore(&info
->readlock
, flags
);
258 /* Direct deliver failed or queue wasn't empty.
259 * Queue up for later dequeueing via timer-irq.
261 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
262 dev
->drv
[di
]->rcvcount
[channel
] +=
264 #ifdef CONFIG_ISDN_AUDIO
265 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
268 spin_unlock_irqrestore(&info
->readlock
, flags
);
269 /* Schedule dequeuing */
270 if ((dev
->modempoll
) && (info
->rcvsched
))
271 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
276 isdn_tty_cleanup_xmit(modem_info
* info
)
278 skb_queue_purge(&info
->xmit_queue
);
279 #ifdef CONFIG_ISDN_AUDIO
280 skb_queue_purge(&info
->dtmf_queue
);
285 isdn_tty_tint(modem_info
* info
)
287 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
293 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
294 info
->isdn_channel
, 1, skb
)) == len
) {
295 struct tty_struct
*tty
= info
->tty
;
296 info
->send_outstanding
++;
297 info
->msr
&= ~UART_MSR_CTS
;
298 info
->lsr
&= ~UART_LSR_TEMT
;
303 /* Error: no channel, already shutdown, or wrong parameter */
307 skb_queue_head(&info
->xmit_queue
, skb
);
310 #ifdef CONFIG_ISDN_AUDIO
312 isdn_tty_countDLE(unsigned char *buf
, int len
)
322 /* This routine is called from within isdn_tty_write() to perform
323 * DLE-decoding when sending audio-data.
326 isdn_tty_handleDLEdown(modem_info
* info
, atemu
* m
, int len
)
328 unsigned char *p
= &info
->xmit_buf
[info
->xmit_count
];
338 memmove(p
, p
+ 1, len
- 1);
349 #ifdef ISDN_DEBUG_MODEM_VOICE
351 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
354 isdn_tty_at_cout("\020\003", info
);
355 if (!info
->vonline
) {
356 #ifdef ISDN_DEBUG_MODEM_VOICE
358 "DLEdown: send VCON on ttyI%d\n",
361 isdn_tty_at_cout("\r\nVCON\r\n", info
);
368 memmove(p
, p
+ 1, len
- 1);
382 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
388 /* This routine is called from within isdn_tty_write() when receiving
389 * audio-data. It interrupts receiving, if an character other than
393 isdn_tty_end_vrx(const char *buf
, int c
, int from_user
)
402 if ((ch
!= 0x11) && (ch
!= 0x13))
409 static int voice_cf
[7] =
410 {0, 0, 4, 3, 2, 0, 0};
412 #endif /* CONFIG_ISDN_AUDIO */
414 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
415 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
416 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
417 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
420 isdn_tty_senddown(modem_info
* info
)
424 #ifdef CONFIG_ISDN_AUDIO
429 #ifdef CONFIG_ISDN_AUDIO
430 if (info
->vonline
& 4) {
432 if (!info
->vonline
) {
433 #ifdef ISDN_DEBUG_MODEM_VOICE
435 "senddown: send VCON on ttyI%d\n",
438 isdn_tty_at_cout("\r\nVCON\r\n", info
);
442 if (!(buflen
= info
->xmit_count
))
444 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
445 info
->msr
&= ~UART_MSR_CTS
;
446 info
->lsr
&= ~UART_LSR_TEMT
;
447 /* info->xmit_count is modified here and in isdn_tty_write().
448 * So we return here if isdn_tty_write() is in the
451 atomic_inc(&info
->xmit_lock
);
452 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
454 if (info
->isdn_driver
< 0) {
455 info
->xmit_count
= 0;
458 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
459 #ifdef CONFIG_ISDN_AUDIO
460 if (info
->vonline
& 2)
461 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
464 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
466 skb
= dev_alloc_skb(skb_res
+ buflen
);
470 "isdn_tty: Out of memory in ttyI%d senddown\n",
474 skb_reserve(skb
, skb_res
);
475 memcpy(skb_put(skb
, buflen
), info
->xmit_buf
, buflen
);
476 info
->xmit_count
= 0;
477 #ifdef CONFIG_ISDN_AUDIO
478 if (info
->vonline
& 2) {
479 /* For now, ifmt is fixed to 1 (alaw), since this
480 * is used with ISDN everywhere in the world, except
481 * US, Canada and Japan.
482 * Later, when US-ISDN protocols are implemented,
483 * this setting will depend on the D-channel protocol.
487 /* voice conversion/decompression */
488 switch (info
->emu
.vpar
[3]) {
492 /* adpcm, compatible to ZyXel 1496 modem
493 * with ROM revision 6.01
495 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
498 skb_put(skb
, audio_len
),
500 skb_pull(skb
, buflen
);
501 skb_trim(skb
, audio_len
);
506 isdn_audio_alaw2ulaw(skb
->data
,
512 isdn_audio_ulaw2alaw(skb
->data
,
517 #endif /* CONFIG_ISDN_AUDIO */
518 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
519 /* Add T.70 simplified header */
520 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
521 memcpy(skb_push(skb
, 2), "\1\0", 2);
523 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
525 skb_queue_tail(&info
->xmit_queue
, skb
);
528 /************************************************************
532 * mostly "stolen" from original Linux-serial.c and friends.
534 ************************************************************/
536 /* The next routine is called once from within timer-interrupt
537 * triggered within isdn_tty_modem_ncarrier(). It calls
538 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
539 * into the tty's flip-buffer.
542 isdn_tty_modem_do_ncarrier(unsigned long data
)
544 modem_info
*info
= (modem_info
*) data
;
545 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
548 /* Next routine is called, whenever the DTR-signal is raised.
549 * It checks the ncarrier-flag, and triggers the above routine
550 * when necessary. The ncarrier-flag is set, whenever DTR goes
554 isdn_tty_modem_ncarrier(modem_info
* info
)
556 if (info
->ncarrier
) {
557 info
->nc_timer
.expires
= jiffies
+ HZ
;
558 add_timer(&info
->nc_timer
);
563 * return the usage calculated by si and layer 2 protocol
566 isdn_calc_usage(int si
, int l2
)
568 int usg
= ISDN_USAGE_MODEM
;
570 #ifdef CONFIG_ISDN_AUDIO
573 case ISDN_PROTO_L2_MODEM
:
574 usg
= ISDN_USAGE_MODEM
;
576 #ifdef CONFIG_ISDN_TTY_FAX
577 case ISDN_PROTO_L2_FAX
:
578 usg
= ISDN_USAGE_FAX
;
581 case ISDN_PROTO_L2_TRANS
:
583 usg
= ISDN_USAGE_VOICE
;
591 /* isdn_tty_dial() performs dialing of a tty an the necessary
592 * setup of the lower levels before that.
595 isdn_tty_dial(char *n
, modem_info
* info
, atemu
* m
)
597 int usg
= ISDN_USAGE_MODEM
;
599 int l2
= m
->mdmreg
[REG_L2PROT
];
605 for (j
= 7; j
>= 0; j
--)
606 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
610 usg
= isdn_calc_usage(si
, l2
);
611 #ifdef CONFIG_ISDN_AUDIO
613 (l2
!= ISDN_PROTO_L2_MODEM
)
614 #ifdef CONFIG_ISDN_TTY_FAX
615 && (l2
!= ISDN_PROTO_L2_FAX
)
618 l2
= ISDN_PROTO_L2_TRANS
;
619 usg
= ISDN_USAGE_VOICE
;
622 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
623 spin_lock_irqsave(&dev
->lock
, flags
);
624 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
626 spin_unlock_irqrestore(&dev
->lock
, flags
);
627 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
629 info
->isdn_driver
= dev
->drvmap
[i
];
630 info
->isdn_channel
= dev
->chanmap
[i
];
632 dev
->m_idx
[i
] = info
->line
;
633 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
635 strcpy(info
->last_num
, n
);
637 spin_unlock_irqrestore(&dev
->lock
, flags
);
638 cmd
.driver
= info
->isdn_driver
;
639 cmd
.arg
= info
->isdn_channel
;
640 cmd
.command
= ISDN_CMD_CLREAZ
;
642 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
643 cmd
.driver
= info
->isdn_driver
;
644 cmd
.command
= ISDN_CMD_SETEAZ
;
646 cmd
.driver
= info
->isdn_driver
;
647 cmd
.command
= ISDN_CMD_SETL2
;
649 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
651 cmd
.driver
= info
->isdn_driver
;
652 cmd
.command
= ISDN_CMD_SETL3
;
653 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
654 #ifdef CONFIG_ISDN_TTY_FAX
655 if (l2
== ISDN_PROTO_L2_FAX
) {
656 cmd
.parm
.fax
= info
->fax
;
657 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
661 cmd
.driver
= info
->isdn_driver
;
662 cmd
.arg
= info
->isdn_channel
;
663 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
664 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
665 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
666 cmd
.parm
.setup
.si1
= si
;
667 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
668 cmd
.command
= ISDN_CMD_DIAL
;
670 info
->emu
.carrierwait
= 0;
671 strcpy(dev
->num
[i
], n
);
674 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
678 /* isdn_tty_hangup() disassociates a tty from the real
679 * ISDN-line (hangup). The usage-status is cleared
680 * and some cleanup is done also.
683 isdn_tty_modem_hup(modem_info
* info
, int local
)
691 di
= info
->isdn_driver
;
692 ch
= info
->isdn_channel
;
693 if (di
< 0 || ch
< 0)
696 info
->isdn_driver
= -1;
697 info
->isdn_channel
= -1;
699 #ifdef ISDN_DEBUG_MODEM_HUP
700 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
703 isdn_tty_flush_buffer(info
->tty
);
705 info
->last_lhup
= local
;
707 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
709 #ifdef CONFIG_ISDN_AUDIO
711 #ifdef CONFIG_ISDN_TTY_FAX
713 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
715 info
->emu
.vpar
[4] = 0;
716 info
->emu
.vpar
[5] = 8;
717 if (info
->dtmf_state
) {
718 kfree(info
->dtmf_state
);
719 info
->dtmf_state
= NULL
;
721 if (info
->silence_state
) {
722 kfree(info
->silence_state
);
723 info
->silence_state
= NULL
;
734 if ((info
->msr
& UART_MSR_RI
) &&
735 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
736 isdn_tty_modem_result(RESULT_RUNG
, info
);
737 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
738 info
->lsr
|= UART_LSR_TEMT
;
742 cmd
.command
= ISDN_CMD_HANGUP
;
747 isdn_all_eaz(di
, ch
);
748 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
749 isdn_free_channel(di
, ch
, 0);
751 if (info
->drv_index
>= 0) {
752 dev
->m_idx
[info
->drv_index
] = -1;
753 info
->drv_index
= -1;
758 * Begin of a CAPI like interface, currently used only for
759 * supplementary service (CAPI 2.0 part III)
761 #include <linux/isdn/capicmd.h>
764 isdn_tty_capi_facility(capi_msg
*cm
) {
765 return(-1); /* dummy */
768 /* isdn_tty_suspend() tries to suspend the current tty connection
771 isdn_tty_suspend(char *id
, modem_info
* info
, atemu
* m
)
780 #ifdef ISDN_DEBUG_MODEM_SERVICES
781 printk(KERN_DEBUG
"Msusp ttyI%d\n", info
->line
);
784 if ((info
->isdn_driver
>= 0)) {
785 cmd
.parm
.cmsg
.Length
= l
+18;
786 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
787 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
788 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
789 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
790 cmd
.parm
.cmsg
.para
[1] = 0;
791 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
792 cmd
.parm
.cmsg
.para
[3] = 4; /* 16 bit 0x0004 Suspend */
793 cmd
.parm
.cmsg
.para
[4] = 0;
794 cmd
.parm
.cmsg
.para
[5] = l
;
795 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
796 cmd
.command
= CAPI_PUT_MESSAGE
;
797 cmd
.driver
= info
->isdn_driver
;
798 cmd
.arg
= info
->isdn_channel
;
803 /* isdn_tty_resume() tries to resume a suspended call
804 * setup of the lower levels before that. unfortunatly here is no
805 * checking for compatibility of used protocols implemented by Q931
806 * It does the same things like isdn_tty_dial, the last command
807 * is different, may be we can merge it.
811 isdn_tty_resume(char *id
, modem_info
* info
, atemu
* m
)
813 int usg
= ISDN_USAGE_MODEM
;
815 int l2
= m
->mdmreg
[REG_L2PROT
];
823 for (j
= 7; j
>= 0; j
--)
824 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
828 usg
= isdn_calc_usage(si
, l2
);
829 #ifdef CONFIG_ISDN_AUDIO
831 (l2
!= ISDN_PROTO_L2_MODEM
)
832 #ifdef CONFIG_ISDN_TTY_FAX
833 && (l2
!= ISDN_PROTO_L2_FAX
)
836 l2
= ISDN_PROTO_L2_TRANS
;
837 usg
= ISDN_USAGE_VOICE
;
840 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
841 spin_lock_irqsave(&dev
->lock
, flags
);
842 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
844 spin_unlock_irqrestore(&dev
->lock
, flags
);
845 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
847 info
->isdn_driver
= dev
->drvmap
[i
];
848 info
->isdn_channel
= dev
->chanmap
[i
];
850 dev
->m_idx
[i
] = info
->line
;
851 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
853 // strcpy(info->last_num, n);
855 spin_unlock_irqrestore(&dev
->lock
, flags
);
856 cmd
.driver
= info
->isdn_driver
;
857 cmd
.arg
= info
->isdn_channel
;
858 cmd
.command
= ISDN_CMD_CLREAZ
;
860 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
861 cmd
.driver
= info
->isdn_driver
;
862 cmd
.command
= ISDN_CMD_SETEAZ
;
864 cmd
.driver
= info
->isdn_driver
;
865 cmd
.command
= ISDN_CMD_SETL2
;
867 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
869 cmd
.driver
= info
->isdn_driver
;
870 cmd
.command
= ISDN_CMD_SETL3
;
871 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
873 cmd
.driver
= info
->isdn_driver
;
874 cmd
.arg
= info
->isdn_channel
;
875 cmd
.parm
.cmsg
.Length
= l
+18;
876 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
877 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
878 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
879 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
880 cmd
.parm
.cmsg
.para
[1] = 0;
881 cmd
.parm
.cmsg
.para
[2] = l
+3;
882 cmd
.parm
.cmsg
.para
[3] = 5; /* 16 bit 0x0005 Resume */
883 cmd
.parm
.cmsg
.para
[4] = 0;
884 cmd
.parm
.cmsg
.para
[5] = l
;
885 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
886 cmd
.command
=CAPI_PUT_MESSAGE
;
888 // strcpy(dev->num[i], n);
891 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
895 /* isdn_tty_send_msg() sends a message to a HL driver
896 * This is used for hybrid modem cards to send AT commands to it
900 isdn_tty_send_msg(modem_info
* info
, atemu
* m
, char *msg
)
902 int usg
= ISDN_USAGE_MODEM
;
904 int l2
= m
->mdmreg
[REG_L2PROT
];
913 isdn_tty_modem_result(RESULT_ERROR
, info
);
916 for (j
= 7; j
>= 0; j
--)
917 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
921 usg
= isdn_calc_usage(si
, l2
);
922 #ifdef CONFIG_ISDN_AUDIO
924 (l2
!= ISDN_PROTO_L2_MODEM
)
925 #ifdef CONFIG_ISDN_TTY_FAX
926 && (l2
!= ISDN_PROTO_L2_FAX
)
929 l2
= ISDN_PROTO_L2_TRANS
;
930 usg
= ISDN_USAGE_VOICE
;
933 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
934 spin_lock_irqsave(&dev
->lock
, flags
);
935 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
937 spin_unlock_irqrestore(&dev
->lock
, flags
);
938 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
940 info
->isdn_driver
= dev
->drvmap
[i
];
941 info
->isdn_channel
= dev
->chanmap
[i
];
943 dev
->m_idx
[i
] = info
->line
;
944 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
947 spin_unlock_irqrestore(&dev
->lock
, flags
);
948 cmd
.driver
= info
->isdn_driver
;
949 cmd
.arg
= info
->isdn_channel
;
950 cmd
.command
= ISDN_CMD_CLREAZ
;
952 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
953 cmd
.driver
= info
->isdn_driver
;
954 cmd
.command
= ISDN_CMD_SETEAZ
;
956 cmd
.driver
= info
->isdn_driver
;
957 cmd
.command
= ISDN_CMD_SETL2
;
959 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
961 cmd
.driver
= info
->isdn_driver
;
962 cmd
.command
= ISDN_CMD_SETL3
;
963 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
965 cmd
.driver
= info
->isdn_driver
;
966 cmd
.arg
= info
->isdn_channel
;
967 cmd
.parm
.cmsg
.Length
= l
+14;
968 cmd
.parm
.cmsg
.Command
= CAPI_MANUFACTURER
;
969 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
970 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
971 cmd
.parm
.cmsg
.para
[0] = l
+1;
972 strncpy(&cmd
.parm
.cmsg
.para
[1], msg
, l
);
973 cmd
.parm
.cmsg
.para
[l
+1] = 0xd;
974 cmd
.command
=CAPI_PUT_MESSAGE
;
975 /* info->dialing = 1;
976 strcpy(dev->num[i], n);
984 isdn_tty_paranoia_check(modem_info
*info
, char *name
, const char *routine
)
986 #ifdef MODEM_PARANOIA_CHECK
988 printk(KERN_WARNING
"isdn_tty: null info_struct for %s in %s\n",
992 if (info
->magic
!= ISDN_ASYNC_MAGIC
) {
993 printk(KERN_WARNING
"isdn_tty: bad magic for modem struct %s in %s\n",
1002 * This routine is called to set the UART divisor registers to match
1003 * the specified baud rate for a serial port.
1006 isdn_tty_change_speed(modem_info
* info
)
1014 if (!info
->tty
|| !info
->tty
->termios
)
1016 cflag
= info
->tty
->termios
->c_cflag
;
1018 quot
= i
= cflag
& CBAUD
;
1022 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
1027 info
->mcr
|= UART_MCR_DTR
;
1028 isdn_tty_modem_ncarrier(info
);
1030 info
->mcr
&= ~UART_MCR_DTR
;
1031 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1032 #ifdef ISDN_DEBUG_MODEM_HUP
1033 printk(KERN_DEBUG
"Mhup in changespeed\n");
1037 isdn_tty_modem_reset_regs(info
, 0);
1038 isdn_tty_modem_hup(info
, 1);
1042 /* byte size and parity */
1043 cval
= cflag
& (CSIZE
| CSTOPB
);
1046 cval
|= UART_LCR_PARITY
;
1047 if (!(cflag
& PARODD
))
1048 cval
|= UART_LCR_EPAR
;
1051 /* CTS flow control flag and modem status interrupts */
1052 if (cflag
& CRTSCTS
) {
1053 info
->flags
|= ISDN_ASYNC_CTS_FLOW
;
1055 info
->flags
&= ~ISDN_ASYNC_CTS_FLOW
;
1057 info
->flags
&= ~ISDN_ASYNC_CHECK_CD
;
1059 info
->flags
|= ISDN_ASYNC_CHECK_CD
;
1064 isdn_tty_startup(modem_info
* info
)
1066 if (info
->flags
& ISDN_ASYNC_INITIALIZED
)
1068 isdn_lock_drivers();
1069 #ifdef ISDN_DEBUG_MODEM_OPEN
1070 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1073 * Now, initialize the UART
1075 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1077 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1079 * and set the speed of the serial port
1081 isdn_tty_change_speed(info
);
1083 info
->flags
|= ISDN_ASYNC_INITIALIZED
;
1084 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1085 info
->send_outstanding
= 0;
1090 * This routine will shutdown a serial port; interrupts are disabled, and
1091 * DTR is dropped if the hangup on close termio flag is on.
1094 isdn_tty_shutdown(modem_info
* info
)
1096 if (!(info
->flags
& ISDN_ASYNC_INITIALIZED
))
1098 #ifdef ISDN_DEBUG_MODEM_OPEN
1099 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1101 isdn_unlock_drivers();
1102 info
->msr
&= ~UART_MSR_RI
;
1103 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
1104 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1105 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1106 isdn_tty_modem_reset_regs(info
, 0);
1107 #ifdef ISDN_DEBUG_MODEM_HUP
1108 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1110 isdn_tty_modem_hup(info
, 1);
1114 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1116 info
->flags
&= ~ISDN_ASYNC_INITIALIZED
;
1119 /* isdn_tty_write() is the main send-routine. It is called from the upper
1120 * levels within the kernel to perform sending data. Depending on the
1121 * online-flag it either directs output to the at-command-interpreter or
1122 * to the lower level. Additional tasks done here:
1123 * - If online, check for escape-sequence (+++)
1124 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1125 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1126 * - If dialing, abort dial.
1129 isdn_tty_write(struct tty_struct
*tty
, int from_user
, const u_char
* buf
, int count
)
1133 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1134 atemu
*m
= &info
->emu
;
1136 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write"))
1139 down(&info
->write_sem
);
1140 /* See isdn_tty_senddown() */
1141 atomic_inc(&info
->xmit_lock
);
1144 if (c
> info
->xmit_size
- info
->xmit_count
)
1145 c
= info
->xmit_size
- info
->xmit_count
;
1146 if (info
->isdn_driver
>= 0 && c
> dev
->drv
[info
->isdn_driver
]->maxbufsize
)
1147 c
= dev
->drv
[info
->isdn_driver
]->maxbufsize
;
1150 if ((info
->online
> 1)
1151 #ifdef CONFIG_ISDN_AUDIO
1152 || (info
->vonline
& 3)
1155 #ifdef CONFIG_ISDN_AUDIO
1158 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1163 copy_from_user(&(info
->xmit_buf
[info
->xmit_count
]), buf
, c
);
1165 memcpy(&(info
->xmit_buf
[info
->xmit_count
]), buf
, c
);
1166 #ifdef CONFIG_ISDN_AUDIO
1167 if (info
->vonline
) {
1168 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1169 if (info
->vonline
& 2) {
1171 /* If DLE decoding results in zero-transmit, but
1172 * c originally was non-zero, do a wakeup.
1175 info
->msr
|= UART_MSR_CTS
;
1176 info
->lsr
|= UART_LSR_TEMT
;
1178 info
->xmit_count
+= cc
;
1180 if ((info
->vonline
& 3) == 1) {
1181 /* Do NOT handle Ctrl-Q or Ctrl-S
1182 * when in full-duplex audio mode.
1184 if (isdn_tty_end_vrx(buf
, c
, from_user
)) {
1185 info
->vonline
&= ~1;
1186 #ifdef ISDN_DEBUG_MODEM_VOICE
1188 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1191 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1195 if (TTY_IS_FCLASS1(info
)) {
1196 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1198 if (info
->vonline
& 4) { /* ETX seen */
1201 c
.command
= ISDN_CMD_FAXCMD
;
1202 c
.driver
= info
->isdn_driver
;
1203 c
.arg
= info
->isdn_channel
;
1204 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1205 c
.parm
.aux
.subcmd
= ETX
;
1209 #ifdef ISDN_DEBUG_MODEM_VOICE
1210 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
, c
);
1212 info
->xmit_count
+= cc
;
1215 info
->xmit_count
+= c
;
1217 info
->msr
|= UART_MSR_CTS
;
1218 info
->lsr
|= UART_LSR_TEMT
;
1219 if (info
->dialing
) {
1221 #ifdef ISDN_DEBUG_MODEM_HUP
1222 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1224 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1225 isdn_tty_modem_hup(info
, 1);
1227 c
= isdn_tty_edit_at(buf
, c
, info
, from_user
);
1233 atomic_dec(&info
->xmit_lock
);
1234 if ((info
->xmit_count
) || (skb_queue_len(&info
->xmit_queue
))) {
1235 if (m
->mdmreg
[REG_DXMT
] & BIT_DXMT
) {
1236 isdn_tty_senddown(info
);
1237 isdn_tty_tint(info
);
1239 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1242 up(&info
->write_sem
);
1247 isdn_tty_write_room(struct tty_struct
*tty
)
1249 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1252 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write_room"))
1255 return info
->xmit_size
;
1256 ret
= info
->xmit_size
- info
->xmit_count
;
1257 return (ret
< 0) ? 0 : ret
;
1261 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1263 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1265 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_chars_in_buffer"))
1269 return (info
->xmit_count
);
1273 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1280 info
= (modem_info
*) tty
->driver_data
;
1281 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_buffer")) {
1284 isdn_tty_cleanup_xmit(info
);
1285 info
->xmit_count
= 0;
1286 wake_up_interruptible(&tty
->write_wait
);
1291 isdn_tty_flush_chars(struct tty_struct
*tty
)
1293 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1295 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_chars"))
1297 if ((info
->xmit_count
) || (skb_queue_len(&info
->xmit_queue
)))
1298 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1302 * ------------------------------------------------------------
1303 * isdn_tty_throttle()
1305 * This routine is called by the upper-layer tty layer to signal that
1306 * incoming characters should be throttled.
1307 * ------------------------------------------------------------
1310 isdn_tty_throttle(struct tty_struct
*tty
)
1312 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1314 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_throttle"))
1317 info
->x_char
= STOP_CHAR(tty
);
1318 info
->mcr
&= ~UART_MCR_RTS
;
1322 isdn_tty_unthrottle(struct tty_struct
*tty
)
1324 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1326 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_unthrottle"))
1332 info
->x_char
= START_CHAR(tty
);
1334 info
->mcr
|= UART_MCR_RTS
;
1338 * ------------------------------------------------------------
1339 * isdn_tty_ioctl() and friends
1340 * ------------------------------------------------------------
1344 * isdn_tty_get_lsr_info - get line status register info
1346 * Purpose: Let user call ioctl() to get info when the UART physically
1347 * is emptied. On bus types like RS485, the transmitter must
1348 * release the bus after transmitting. This must be done when
1349 * the transmit shift register is empty, not be done when the
1350 * transmit holding register is empty. This functionality
1351 * allows RS485 driver to be written in user space.
1354 isdn_tty_get_lsr_info(modem_info
* info
, uint __user
* value
)
1360 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1361 return put_user(result
, value
);
1366 isdn_tty_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1368 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1369 u_char control
, status
;
1371 if (isdn_tty_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1373 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1376 #ifdef ISDN_DEBUG_MODEM_IOCTL
1377 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1380 control
= info
->mcr
;
1382 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1383 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1384 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1385 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1386 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1387 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1391 isdn_tty_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1392 unsigned int set
, unsigned int clear
)
1394 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1396 if (isdn_tty_paranoia_check(info
, tty
->name
, __FUNCTION__
))
1398 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1401 #ifdef ISDN_DEBUG_MODEM_IOCTL
1402 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMxxx: %x %x\n", info
->line
, set
, clear
);
1405 if (set
& TIOCM_RTS
)
1406 info
->mcr
|= UART_MCR_RTS
;
1407 if (set
& TIOCM_DTR
) {
1408 info
->mcr
|= UART_MCR_DTR
;
1409 isdn_tty_modem_ncarrier(info
);
1412 if (clear
& TIOCM_RTS
)
1413 info
->mcr
&= ~UART_MCR_RTS
;
1414 if (clear
& TIOCM_DTR
) {
1415 info
->mcr
&= ~UART_MCR_DTR
;
1416 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1417 isdn_tty_modem_reset_regs(info
, 0);
1418 #ifdef ISDN_DEBUG_MODEM_HUP
1419 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1423 isdn_tty_modem_hup(info
, 1);
1430 isdn_tty_ioctl(struct tty_struct
*tty
, struct file
*file
,
1431 uint cmd
, ulong arg
)
1433 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1436 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_ioctl"))
1438 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1441 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1442 #ifdef ISDN_DEBUG_MODEM_IOCTL
1443 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1445 retval
= tty_check_change(tty
);
1448 tty_wait_until_sent(tty
, 0);
1450 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1451 #ifdef ISDN_DEBUG_MODEM_IOCTL
1452 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1454 retval
= tty_check_change(tty
);
1457 tty_wait_until_sent(tty
, 0);
1460 #ifdef ISDN_DEBUG_MODEM_IOCTL
1461 printk(KERN_DEBUG
"ttyI%d ioctl TIOCGSOFTCAR\n", info
->line
);
1463 return put_user(C_CLOCAL(tty
) ? 1 : 0, (ulong __user
*) arg
);
1465 #ifdef ISDN_DEBUG_MODEM_IOCTL
1466 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSSOFTCAR\n", info
->line
);
1468 if (get_user(arg
, (ulong __user
*) arg
))
1470 tty
->termios
->c_cflag
=
1471 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1472 (arg
? CLOCAL
: 0));
1474 case TIOCSERGETLSR
: /* Get line status register */
1475 #ifdef ISDN_DEBUG_MODEM_IOCTL
1476 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1478 return isdn_tty_get_lsr_info(info
, (uint __user
*) arg
);
1480 #ifdef ISDN_DEBUG_MODEM_IOCTL
1481 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1483 return -ENOIOCTLCMD
;
1489 isdn_tty_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1491 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1494 isdn_tty_change_speed(info
);
1496 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1498 isdn_tty_change_speed(info
);
1499 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1500 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1501 tty
->hw_stopped
= 0;
1507 * ------------------------------------------------------------
1508 * isdn_tty_open() and friends
1509 * ------------------------------------------------------------
1512 isdn_tty_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, modem_info
* info
)
1514 DECLARE_WAITQUEUE(wait
, NULL
);
1519 * If the device is in the middle of being closed, then block
1520 * until it's done, and then try again.
1522 if (tty_hung_up_p(filp
) ||
1523 (info
->flags
& ISDN_ASYNC_CLOSING
)) {
1524 if (info
->flags
& ISDN_ASYNC_CLOSING
)
1525 interruptible_sleep_on(&info
->close_wait
);
1526 #ifdef MODEM_DO_RESTART
1527 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1530 return -ERESTARTSYS
;
1536 * If non-blocking mode is set, then make the check up front
1539 if ((filp
->f_flags
& O_NONBLOCK
) ||
1540 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1541 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
1543 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
1546 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) {
1547 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1550 if (tty
->termios
->c_cflag
& CLOCAL
)
1554 * Block waiting for the carrier detect and the line to become
1555 * free (i.e., not in use by the callout). While we are in
1556 * this loop, info->count is dropped by one, so that
1557 * isdn_tty_close() knows when to free things. We restore it upon
1558 * exit, either normal or abnormal.
1561 add_wait_queue(&info
->open_wait
, &wait
);
1562 #ifdef ISDN_DEBUG_MODEM_OPEN
1563 printk(KERN_DEBUG
"isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1564 info
->line
, info
->count
);
1566 if (!(tty_hung_up_p(filp
)))
1568 info
->blocked_open
++;
1570 set_current_state(TASK_INTERRUPTIBLE
);
1571 if (tty_hung_up_p(filp
) ||
1572 !(info
->flags
& ISDN_ASYNC_INITIALIZED
)) {
1573 #ifdef MODEM_DO_RESTART
1574 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1577 retval
= -ERESTARTSYS
;
1583 if (!(info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
1584 !(info
->flags
& ISDN_ASYNC_CLOSING
) &&
1585 (do_clocal
|| (info
->msr
& UART_MSR_DCD
))) {
1588 if (signal_pending(current
)) {
1589 retval
= -ERESTARTSYS
;
1592 #ifdef ISDN_DEBUG_MODEM_OPEN
1593 printk(KERN_DEBUG
"isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1594 info
->line
, info
->count
);
1598 current
->state
= TASK_RUNNING
;
1599 remove_wait_queue(&info
->open_wait
, &wait
);
1600 if (!tty_hung_up_p(filp
))
1602 info
->blocked_open
--;
1603 #ifdef ISDN_DEBUG_MODEM_OPEN
1604 printk(KERN_DEBUG
"isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1605 info
->line
, info
->count
);
1609 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
1614 * This routine is called whenever a serial port is opened. It
1615 * enables interrupts for a serial port, linking in its async structure into
1616 * the IRQ chain. It also performs the serial-specific
1617 * initialization for the tty structure.
1620 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
1626 if (line
< 0 || line
> ISDN_MAX_CHANNELS
)
1628 info
= &dev
->mdm
.info
[line
];
1629 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_open"))
1631 if (!try_module_get(info
->owner
)) {
1632 printk(KERN_WARNING
"%s: cannot reserve module\n", __FUNCTION__
);
1635 #ifdef ISDN_DEBUG_MODEM_OPEN
1636 printk(KERN_DEBUG
"isdn_tty_open %s, count = %d\n", tty
->name
,
1640 tty
->driver_data
= info
;
1643 * Start up serial port
1645 retval
= isdn_tty_startup(info
);
1647 #ifdef ISDN_DEBUG_MODEM_OPEN
1648 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
1650 module_put(info
->owner
);
1653 retval
= isdn_tty_block_til_ready(tty
, filp
, info
);
1655 #ifdef ISDN_DEBUG_MODEM_OPEN
1656 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
1658 module_put(info
->owner
);
1661 #ifdef ISDN_DEBUG_MODEM_OPEN
1662 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
1665 #ifdef ISDN_DEBUG_MODEM_OPEN
1666 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
1672 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
1674 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1677 if (!info
|| isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_close"))
1679 if (tty_hung_up_p(filp
)) {
1680 #ifdef ISDN_DEBUG_MODEM_OPEN
1681 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
1685 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1687 * Uh, oh. tty->count is 1, which means that the tty
1688 * structure will be freed. Info->count should always
1689 * be one in these conditions. If it's greater than
1690 * one, we've got real problems, since it means the
1691 * serial port won't be shutdown.
1693 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
1694 "info->count is %d\n", info
->count
);
1697 if (--info
->count
< 0) {
1698 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
1699 info
->line
, info
->count
);
1703 #ifdef ISDN_DEBUG_MODEM_OPEN
1704 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
1708 info
->flags
|= ISDN_ASYNC_CLOSING
;
1710 * Save the termios structure, since this port may have
1711 * separate termios for callout and dialin.
1713 if (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
)
1714 info
->normal_termios
= *tty
->termios
;
1715 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
1716 info
->callout_termios
= *tty
->termios
;
1720 * At this point we stop accepting input. To do this, we
1721 * disable the receive line status interrupts, and tell the
1722 * interrupt driver to stop checking the data ready bit in the
1723 * line status register.
1725 if (info
->flags
& ISDN_ASYNC_INITIALIZED
) {
1726 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
1728 * Before we drop DTR, make sure the UART transmitter
1729 * has completely drained; this is especially
1730 * important if there is a transmit FIFO!
1732 timeout
= jiffies
+ HZ
;
1733 while (!(info
->lsr
& UART_LSR_TEMT
)) {
1734 set_current_state(TASK_INTERRUPTIBLE
);
1735 schedule_timeout(20);
1736 if (time_after(jiffies
,timeout
))
1741 isdn_tty_shutdown(info
);
1743 if (tty
->driver
->flush_buffer
)
1744 tty
->driver
->flush_buffer(tty
);
1745 tty_ldisc_flush(tty
);
1749 module_put(info
->owner
);
1750 if (info
->blocked_open
) {
1751 set_current_state(TASK_INTERRUPTIBLE
);
1752 schedule_timeout(HZ
/2);
1753 wake_up_interruptible(&info
->open_wait
);
1755 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CLOSING
);
1756 wake_up_interruptible(&info
->close_wait
);
1757 #ifdef ISDN_DEBUG_MODEM_OPEN
1758 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
1763 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1766 isdn_tty_hangup(struct tty_struct
*tty
)
1768 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1770 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_hangup"))
1772 isdn_tty_shutdown(info
);
1774 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CALLOUT_ACTIVE
);
1776 wake_up_interruptible(&info
->open_wait
);
1779 /* This routine initializes all emulator-data.
1782 isdn_tty_reset_profile(atemu
* m
)
1795 m
->profile
[11] = 70;
1796 m
->profile
[12] = 0x45;
1798 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
1799 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
1800 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
1801 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
1810 #ifdef CONFIG_ISDN_AUDIO
1812 isdn_tty_modem_reset_vpar(atemu
* m
)
1814 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
1815 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
1816 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
1817 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1818 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
1819 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1823 #ifdef CONFIG_ISDN_TTY_FAX
1825 isdn_tty_modem_reset_faxpar(modem_info
* info
)
1827 T30_s
*f
= info
->fax
;
1830 f
->phase
= ISDN_FAX_PHASE_IDLE
;
1832 f
->resolution
= 1; /* fine */
1833 f
->rate
= 5; /* 14400 bit/s */
1840 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
1841 f
->id
[FAXIDLEN
- 1] = 0;
1852 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
1853 f
->pollid
[FAXIDLEN
- 1] = 0;
1858 isdn_tty_modem_reset_regs(modem_info
* info
, int force
)
1860 atemu
*m
= &info
->emu
;
1861 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
1862 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
1863 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
1864 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
1865 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
1867 #ifdef CONFIG_ISDN_AUDIO
1868 isdn_tty_modem_reset_vpar(m
);
1870 #ifdef CONFIG_ISDN_TTY_FAX
1871 isdn_tty_modem_reset_faxpar(info
);
1877 modem_write_profile(atemu
* m
)
1879 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
1880 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
1881 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
1883 send_sig(SIGIO
, dev
->profd
, 1);
1886 static struct tty_operations modem_ops
= {
1887 .open
= isdn_tty_open
,
1888 .close
= isdn_tty_close
,
1889 .write
= isdn_tty_write
,
1890 .flush_chars
= isdn_tty_flush_chars
,
1891 .write_room
= isdn_tty_write_room
,
1892 .chars_in_buffer
= isdn_tty_chars_in_buffer
,
1893 .flush_buffer
= isdn_tty_flush_buffer
,
1894 .ioctl
= isdn_tty_ioctl
,
1895 .throttle
= isdn_tty_throttle
,
1896 .unthrottle
= isdn_tty_unthrottle
,
1897 .set_termios
= isdn_tty_set_termios
,
1898 .hangup
= isdn_tty_hangup
,
1899 .tiocmget
= isdn_tty_tiocmget
,
1900 .tiocmset
= isdn_tty_tiocmset
,
1904 isdn_tty_modem_init(void)
1911 m
->tty_modem
= alloc_tty_driver(ISDN_MAX_CHANNELS
);
1914 m
->tty_modem
->name
= "ttyI";
1915 m
->tty_modem
->devfs_name
= "isdn/ttyI";
1916 m
->tty_modem
->major
= ISDN_TTY_MAJOR
;
1917 m
->tty_modem
->minor_start
= 0;
1918 m
->tty_modem
->type
= TTY_DRIVER_TYPE_SERIAL
;
1919 m
->tty_modem
->subtype
= SERIAL_TYPE_NORMAL
;
1920 m
->tty_modem
->init_termios
= tty_std_termios
;
1921 m
->tty_modem
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1922 m
->tty_modem
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
;
1923 m
->tty_modem
->driver_name
= "isdn_tty";
1924 tty_set_operations(m
->tty_modem
, &modem_ops
);
1925 retval
= tty_register_driver(m
->tty_modem
);
1927 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
1930 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1932 #ifdef CONFIG_ISDN_TTY_FAX
1933 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
1934 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
1936 goto err_unregister
;
1940 info
->owner
= THIS_MODULE
;
1942 spin_lock_init(&info
->readlock
);
1943 init_MUTEX(&info
->write_sem
);
1944 sprintf(info
->last_cause
, "0000");
1945 sprintf(info
->last_num
, "none");
1947 info
->last_lhup
= 1;
1950 isdn_tty_reset_profile(&info
->emu
);
1951 isdn_tty_modem_reset_regs(info
, 1);
1952 info
->magic
= ISDN_ASYNC_MAGIC
;
1957 info
->blocked_open
= 0;
1958 init_waitqueue_head(&info
->open_wait
);
1959 init_waitqueue_head(&info
->close_wait
);
1960 info
->isdn_driver
= -1;
1961 info
->isdn_channel
= -1;
1962 info
->drv_index
= -1;
1963 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
1964 init_timer(&info
->nc_timer
);
1965 info
->nc_timer
.function
= isdn_tty_modem_do_ncarrier
;
1966 info
->nc_timer
.data
= (unsigned long) info
;
1967 skb_queue_head_init(&info
->xmit_queue
);
1968 #ifdef CONFIG_ISDN_AUDIO
1969 skb_queue_head_init(&info
->dtmf_queue
);
1971 if (!(info
->xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5, GFP_KERNEL
))) {
1972 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
1974 goto err_unregister
;
1976 /* Make room for T.70 header */
1977 info
->xmit_buf
+= 4;
1981 for (i
--; i
>= 0; i
--) {
1983 #ifdef CONFIG_ISDN_TTY_FAX
1986 kfree(info
->xmit_buf
- 4);
1988 tty_unregister_driver(m
->tty_modem
);
1990 put_tty_driver(m
->tty_modem
);
1991 m
->tty_modem
= NULL
;
2001 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2002 info
= &dev
->mdm
.info
[i
];
2003 isdn_tty_cleanup_xmit(info
);
2004 #ifdef CONFIG_ISDN_TTY_FAX
2007 kfree(info
->xmit_buf
- 4);
2009 tty_unregister_driver(dev
->mdm
.tty_modem
);
2010 put_tty_driver(dev
->mdm
.tty_modem
);
2011 dev
->mdm
.tty_modem
= NULL
;
2016 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
2017 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
2018 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
2022 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
2024 #ifdef ISDN_DEBUG_MODEM_ICALL
2025 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
2026 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
2027 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
2029 if (strlen(emu
->lmsn
)) {
2030 char *p
= emu
->lmsn
;
2036 if ((q
= strchr(p
, ';')))
2038 if ((tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
2040 #ifdef ISDN_DEBUG_MODEM_ICALL
2041 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2042 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2057 tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
2058 #ifdef ISDN_DEBUG_MODEM_ICALL
2059 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
2060 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2067 * An incoming call-request has arrived.
2068 * Search the tty-devices for an appropriate device and bind
2069 * it to the ISDN-Channel.
2072 * 0 = No matching device found.
2073 * 1 = A matching device found.
2074 * 3 = No match found, but eventually would match, if
2078 isdn_tty_find_icall(int di
, int ch
, setup_parm
*setup
)
2089 if (!setup
->phone
[0]) {
2091 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
2094 si1
= (int) setup
->si1
;
2095 si2
= (int) setup
->si2
;
2096 if (!setup
->eazmsn
[0]) {
2097 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
2100 eaz
= setup
->eazmsn
;
2101 #ifdef ISDN_DEBUG_MODEM_ICALL
2102 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
2105 spin_lock_irqsave(&dev
->lock
, flags
);
2106 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2107 modem_info
*info
= &dev
->mdm
.info
[i
];
2109 if (info
->count
== 0)
2111 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
2112 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
2113 idx
= isdn_dc2minor(di
, ch
);
2114 #ifdef ISDN_DEBUG_MODEM_ICALL
2115 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
2116 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
2117 info
->flags
, info
->isdn_driver
, info
->isdn_channel
,
2121 #ifndef FIX_FILE_TRANSFER
2122 (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
) &&
2124 (info
->isdn_driver
== -1) &&
2125 (info
->isdn_channel
== -1) &&
2126 (USG_NONE(dev
->usage
[idx
]))) {
2129 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
2131 if (!matchret
) { /* EAZ is matching */
2132 info
->isdn_driver
= di
;
2133 info
->isdn_channel
= ch
;
2134 info
->drv_index
= idx
;
2135 dev
->m_idx
[idx
] = info
->line
;
2136 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2137 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
2138 strcpy(dev
->num
[idx
], nr
);
2139 strcpy(info
->emu
.cpn
, eaz
);
2140 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
2141 info
->emu
.mdmreg
[REG_PLAN
] = setup
->plan
;
2142 info
->emu
.mdmreg
[REG_SCREEN
] = setup
->screen
;
2144 spin_unlock_irqrestore(&dev
->lock
, flags
);
2145 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2147 info
->msr
|= UART_MSR_RI
;
2148 isdn_tty_modem_result(RESULT_RING
, info
);
2149 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2155 spin_unlock_irqrestore(&dev
->lock
, flags
);
2156 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2157 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2))? "rejected" : "ignored");
2158 return (wret
== 2)?3:0;
2161 #define TTY_IS_ACTIVE(info) \
2162 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2165 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2173 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2174 info
= &dev
->mdm
.info
[mi
];
2175 switch (c
->command
) {
2176 case ISDN_STAT_CINF
:
2177 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2178 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2179 if (e
== (char *)c
->parm
.num
)
2180 info
->emu
.charge
= 0;
2183 case ISDN_STAT_BSENT
:
2184 #ifdef ISDN_TTY_STAT_DEBUG
2185 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2187 if ((info
->isdn_driver
== c
->driver
) &&
2188 (info
->isdn_channel
== c
->arg
)) {
2189 info
->msr
|= UART_MSR_CTS
;
2190 if (info
->send_outstanding
)
2191 if (!(--info
->send_outstanding
))
2192 info
->lsr
|= UART_LSR_TEMT
;
2193 isdn_tty_tint(info
);
2197 case ISDN_STAT_CAUSE
:
2198 #ifdef ISDN_TTY_STAT_DEBUG
2199 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2201 /* Signal cause to tty-device */
2202 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2204 case ISDN_STAT_DISPLAY
:
2205 #ifdef ISDN_TTY_STAT_DEBUG
2206 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2208 /* Signal display to tty-device */
2209 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2210 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2211 isdn_tty_at_cout("\r\n", info
);
2212 isdn_tty_at_cout("DISPLAY: ", info
);
2213 isdn_tty_at_cout(c
->parm
.display
, info
);
2214 isdn_tty_at_cout("\r\n", info
);
2217 case ISDN_STAT_DCONN
:
2218 #ifdef ISDN_TTY_STAT_DEBUG
2219 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2221 if (TTY_IS_ACTIVE(info
)) {
2222 if (info
->dialing
== 1) {
2228 case ISDN_STAT_DHUP
:
2229 #ifdef ISDN_TTY_STAT_DEBUG
2230 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2232 if (TTY_IS_ACTIVE(info
)) {
2233 if (info
->dialing
== 1)
2234 isdn_tty_modem_result(RESULT_BUSY
, info
);
2235 if (info
->dialing
> 1)
2236 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2238 #ifdef ISDN_DEBUG_MODEM_HUP
2239 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2241 isdn_tty_modem_hup(info
, 0);
2245 case ISDN_STAT_BCONN
:
2246 #ifdef ISDN_TTY_STAT_DEBUG
2247 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2249 /* Wake up any processes waiting
2250 * for incoming call of this device when
2251 * DCD follow the state of incoming carrier
2253 if (info
->blocked_open
&&
2254 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
)) {
2255 wake_up_interruptible(&info
->open_wait
);
2258 /* Schedule CONNECT-Message to any tty
2259 * waiting for it and
2260 * set DCD-bit of its modem-status.
2262 if (TTY_IS_ACTIVE(info
) ||
2263 (info
->blocked_open
&& (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
))) {
2264 info
->msr
|= UART_MSR_DCD
;
2265 info
->emu
.charge
= 0;
2266 if (info
->dialing
& 0xf)
2272 if (USG_MODEM(dev
->usage
[i
])) {
2273 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2274 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2275 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2277 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2279 if (USG_VOICE(dev
->usage
[i
]))
2280 isdn_tty_modem_result(RESULT_VCON
, info
);
2284 case ISDN_STAT_BHUP
:
2285 #ifdef ISDN_TTY_STAT_DEBUG
2286 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2288 if (TTY_IS_ACTIVE(info
)) {
2289 #ifdef ISDN_DEBUG_MODEM_HUP
2290 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2292 isdn_tty_modem_hup(info
, 0);
2296 case ISDN_STAT_NODCH
:
2297 #ifdef ISDN_TTY_STAT_DEBUG
2298 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2300 if (TTY_IS_ACTIVE(info
)) {
2301 if (info
->dialing
) {
2305 sprintf(info
->last_cause
, "0000");
2306 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2308 isdn_tty_modem_hup(info
, 0);
2312 case ISDN_STAT_UNLOAD
:
2313 #ifdef ISDN_TTY_STAT_DEBUG
2314 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2316 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2317 info
= &dev
->mdm
.info
[i
];
2318 if (info
->isdn_driver
== c
->driver
) {
2320 isdn_tty_modem_hup(info
, 1);
2324 #ifdef CONFIG_ISDN_TTY_FAX
2325 case ISDN_STAT_FAXIND
:
2326 if (TTY_IS_ACTIVE(info
)) {
2327 isdn_tty_fax_command(info
, c
);
2331 #ifdef CONFIG_ISDN_AUDIO
2332 case ISDN_STAT_AUDIO
:
2333 if (TTY_IS_ACTIVE(info
)) {
2334 switch(c
->parm
.num
[0]) {
2335 case ISDN_AUDIO_DTMF
:
2336 if (info
->vonline
) {
2337 isdn_audio_put_dle_code(info
,
2350 /*********************************************************************
2351 Modem-Emulator-Routines
2352 *********************************************************************/
2354 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2357 * Put a message from the AT-emulator into receive-buffer of tty,
2358 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2361 isdn_tty_at_cout(char *msg
, modem_info
* info
)
2363 struct tty_struct
*tty
;
2364 atemu
*m
= &info
->emu
;
2368 struct sk_buff
*skb
= NULL
;
2372 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2375 spin_lock_irqsave(&info
->readlock
, flags
);
2377 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!tty
)) {
2378 spin_unlock_irqrestore(&info
->readlock
, flags
);
2382 /* use queue instead of direct flip, if online and */
2383 /* data is in queue or flip buffer is full */
2384 if ((info
->online
) && (((tty
->flip
.count
+ strlen(msg
)) >= TTY_FLIPBUF_SIZE
) ||
2385 (!skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
])))) {
2386 skb
= alloc_skb(strlen(msg
), GFP_ATOMIC
);
2388 spin_unlock_irqrestore(&info
->readlock
, flags
);
2391 sp
= skb_put(skb
, strlen(msg
));
2392 #ifdef CONFIG_ISDN_AUDIO
2393 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2394 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2398 for (p
= msg
; *p
; p
++) {
2401 c
= m
->mdmreg
[REG_CR
];
2404 c
= m
->mdmreg
[REG_LF
];
2407 c
= m
->mdmreg
[REG_BS
];
2415 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
2417 tty_insert_flip_char(tty
, c
, 0);
2421 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2422 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2423 spin_unlock_irqrestore(&info
->readlock
, flags
);
2424 /* Schedule dequeuing */
2425 if ((dev
->modempoll
) && (info
->rcvsched
))
2426 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2429 spin_unlock_irqrestore(&info
->readlock
, flags
);
2430 schedule_delayed_work(&tty
->flip
.work
, 1);
2435 * Perform ATH Hangup
2438 isdn_tty_on_hook(modem_info
* info
)
2440 if (info
->isdn_channel
>= 0) {
2441 #ifdef ISDN_DEBUG_MODEM_HUP
2442 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2444 isdn_tty_modem_hup(info
, 1);
2449 isdn_tty_off_hook(void)
2451 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2454 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2455 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2458 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2459 * isdn_tty_modem_escape() if sequence found.
2462 * p pointer to databuffer
2463 * plus escape-character
2464 * count length of buffer
2465 * pluscount count of valid escape-characters so far
2466 * lastplus timestamp of last character
2469 isdn_tty_check_esc(const u_char
* p
, u_char plus
, int count
, int *pluscount
,
2470 u_long
*lastplus
, int from_user
)
2482 copy_from_user(cbuf
, p
, count
);
2486 if (*(p
++) == plus
) {
2487 if ((*pluscount
)++) {
2488 /* Time since last '+' > 0.5 sec. ? */
2489 if (time_after(jiffies
, *lastplus
+ PLUSWAIT1
))
2492 /* Time since last non-'+' < 1.5 sec. ? */
2493 if (time_before(jiffies
, *lastplus
+ PLUSWAIT2
))
2496 if ((*pluscount
== 3) && (count
== 1))
2497 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2502 *lastplus
= jiffies
;
2508 * Return result of AT-emulator to tty-receive-buffer, depending on
2509 * modem-register 12, bit 0 and 1.
2510 * For CONNECT-messages also switch to online-mode.
2511 * For RING-message handle auto-ATA if register 0 != 0
2515 isdn_tty_modem_result(int code
, modem_info
* info
)
2517 atemu
*m
= &info
->emu
;
2518 static char *msg
[] =
2519 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2520 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2521 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2522 char s
[ISDN_MSNLEN
+10];
2526 m
->mdmreg
[REG_RINGCNT
]++;
2527 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2528 /* Automatically accept incoming call */
2529 isdn_tty_cmd_ATA(info
);
2531 case RESULT_NO_CARRIER
:
2532 #ifdef ISDN_DEBUG_MODEM_HUP
2533 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2534 (info
->flags
& ISDN_ASYNC_CLOSING
),
2537 m
->mdmreg
[REG_RINGCNT
] = 0;
2538 del_timer(&info
->nc_timer
);
2540 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2543 #ifdef CONFIG_ISDN_AUDIO
2544 if (info
->vonline
& 1) {
2545 #ifdef ISDN_DEBUG_MODEM_VOICE
2546 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
2549 /* voice-recording, add DLE-ETX */
2550 isdn_tty_at_cout("\020\003", info
);
2552 if (info
->vonline
& 2) {
2553 #ifdef ISDN_DEBUG_MODEM_VOICE
2554 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
2557 /* voice-playing, add DLE-DC4 */
2558 isdn_tty_at_cout("\020\024", info
);
2562 case RESULT_CONNECT
:
2563 case RESULT_CONNECT64000
:
2564 sprintf(info
->last_cause
, "0000");
2569 #ifdef ISDN_DEBUG_MODEM_VOICE
2570 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
2573 sprintf(info
->last_cause
, "0000");
2577 } /* switch(code) */
2579 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
2581 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
2582 /* Show numeric results only */
2583 sprintf(s
, "\r\n%d\r\n", code
);
2584 isdn_tty_at_cout(s
, info
);
2586 if (code
== RESULT_RING
) {
2587 /* return if "show RUNG" and ringcounter>1 */
2588 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
2589 (m
->mdmreg
[REG_RINGCNT
] > 1))
2591 /* print CID, _before_ _every_ ring */
2592 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
2593 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
2594 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2595 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2596 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2597 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2601 isdn_tty_at_cout("\r\n", info
);
2602 isdn_tty_at_cout(msg
[code
], info
);
2604 case RESULT_CONNECT
:
2605 switch (m
->mdmreg
[REG_L2PROT
]) {
2606 case ISDN_PROTO_L2_MODEM
:
2607 isdn_tty_at_cout(" ", info
);
2608 isdn_tty_at_cout(m
->connmsg
, info
);
2613 /* Append CPN, if enabled */
2614 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
2615 sprintf(s
, "/%s", m
->cpn
);
2616 isdn_tty_at_cout(s
, info
);
2618 /* Print CID only once, _after_ 1st RING */
2619 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
2620 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
2621 isdn_tty_at_cout("\r\n", info
);
2622 isdn_tty_at_cout("CALLER NUMBER: ", info
);
2623 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2624 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2625 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2626 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2630 case RESULT_NO_CARRIER
:
2631 case RESULT_NO_DIALTONE
:
2633 case RESULT_NO_ANSWER
:
2634 m
->mdmreg
[REG_RINGCNT
] = 0;
2635 /* Append Cause-Message if enabled */
2636 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
2637 sprintf(s
, "/%s", info
->last_cause
);
2638 isdn_tty_at_cout(s
, info
);
2641 case RESULT_CONNECT64000
:
2642 /* Append Protocol to CONNECT message */
2643 switch (m
->mdmreg
[REG_L2PROT
]) {
2644 case ISDN_PROTO_L2_X75I
:
2645 case ISDN_PROTO_L2_X75UI
:
2646 case ISDN_PROTO_L2_X75BUI
:
2647 isdn_tty_at_cout("/X.75", info
);
2649 case ISDN_PROTO_L2_HDLC
:
2650 isdn_tty_at_cout("/HDLC", info
);
2652 case ISDN_PROTO_L2_V11096
:
2653 isdn_tty_at_cout("/V110/9600", info
);
2655 case ISDN_PROTO_L2_V11019
:
2656 isdn_tty_at_cout("/V110/19200", info
);
2658 case ISDN_PROTO_L2_V11038
:
2659 isdn_tty_at_cout("/V110/38400", info
);
2662 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2663 isdn_tty_at_cout("/T.70", info
);
2664 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2665 isdn_tty_at_cout("+", info
);
2669 isdn_tty_at_cout("\r\n", info
);
2672 if (code
== RESULT_NO_CARRIER
) {
2673 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2676 tty_ldisc_flush(info
->tty
);
2677 if ((info
->flags
& ISDN_ASYNC_CHECK_CD
) &&
2678 (!((info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
2679 (info
->flags
& ISDN_ASYNC_CALLOUT_NOHUP
)))) {
2680 tty_hangup(info
->tty
);
2687 * Display a modem-register-value.
2690 isdn_tty_show_profile(int ridx
, modem_info
* info
)
2694 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
2695 isdn_tty_at_cout(v
, info
);
2699 * Get MSN-string from char-pointer, set pointer to end of number
2702 isdn_tty_get_msnstr(char *n
, char **p
)
2704 int limit
= ISDN_MSNLEN
- 1;
2706 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
2707 /* Why a comma ??? */
2708 (*p
[0] == ',') || (*p
[0] == ':')) &&
2715 * Get phone-number from modem-commandbuffer
2718 isdn_tty_getdial(char *p
, char *q
,int cnt
)
2721 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
2724 while (strchr(" 0123456789,#.*WPTS-", *p
) && *p
&& --cnt
>0) {
2725 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
2726 (*p
== '*') || (*p
== '#')) {
2738 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2739 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2742 isdn_tty_report(modem_info
* info
)
2744 atemu
*m
= &info
->emu
;
2747 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
2748 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
2749 isdn_tty_at_cout(s
, info
);
2750 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
2751 isdn_tty_at_cout(s
, info
);
2752 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
2753 switch (info
->last_l2
) {
2754 case ISDN_PROTO_L2_X75I
:
2755 isdn_tty_at_cout("X.75i", info
);
2757 case ISDN_PROTO_L2_X75UI
:
2758 isdn_tty_at_cout("X.75ui", info
);
2760 case ISDN_PROTO_L2_X75BUI
:
2761 isdn_tty_at_cout("X.75bui", info
);
2763 case ISDN_PROTO_L2_HDLC
:
2764 isdn_tty_at_cout("HDLC", info
);
2766 case ISDN_PROTO_L2_V11096
:
2767 isdn_tty_at_cout("V.110 9600 Baud", info
);
2769 case ISDN_PROTO_L2_V11019
:
2770 isdn_tty_at_cout("V.110 19200 Baud", info
);
2772 case ISDN_PROTO_L2_V11038
:
2773 isdn_tty_at_cout("V.110 38400 Baud", info
);
2775 case ISDN_PROTO_L2_TRANS
:
2776 isdn_tty_at_cout("transparent", info
);
2778 case ISDN_PROTO_L2_MODEM
:
2779 isdn_tty_at_cout("modem", info
);
2781 case ISDN_PROTO_L2_FAX
:
2782 isdn_tty_at_cout("fax", info
);
2785 isdn_tty_at_cout("unknown", info
);
2788 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2789 isdn_tty_at_cout("/T.70", info
);
2790 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2791 isdn_tty_at_cout("+", info
);
2793 isdn_tty_at_cout("\r\n", info
);
2794 isdn_tty_at_cout(" Service: ", info
);
2795 switch (info
->last_si
) {
2797 isdn_tty_at_cout("audio\r\n", info
);
2800 isdn_tty_at_cout("btx\r\n", info
);
2803 isdn_tty_at_cout("data\r\n", info
);
2806 sprintf(s
, "%d\r\n", info
->last_si
);
2807 isdn_tty_at_cout(s
, info
);
2810 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
2811 isdn_tty_at_cout(s
, info
);
2812 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
2813 isdn_tty_at_cout(s
, info
);
2817 * Parse AT&.. commands.
2820 isdn_tty_cmd_ATand(char **p
, modem_info
* info
)
2822 atemu
*m
= &info
->emu
;
2826 #define MAXRB (sizeof(rb) - 1)
2830 /* &B - Set Buffersize */
2833 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
2835 #ifdef CONFIG_ISDN_AUDIO
2836 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
2839 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
2840 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2841 switch (m
->mdmreg
[REG_L2PROT
]) {
2842 case ISDN_PROTO_L2_V11096
:
2843 case ISDN_PROTO_L2_V11019
:
2844 case ISDN_PROTO_L2_V11038
:
2845 info
->xmit_size
/= 10;
2849 /* &C - DCD Status */
2851 switch (isdn_getnum(p
)) {
2853 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
2856 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
2863 /* &D - Set DTR-Low-behavior */
2865 switch (isdn_getnum(p
)) {
2867 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
2868 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2871 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2872 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2875 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2876 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
2883 /* &E -Set EAZ/MSN */
2885 isdn_tty_get_msnstr(m
->msn
, p
);
2888 /* &F -Set Factory-Defaults */
2890 if (info
->msr
& UART_MSR_DCD
)
2892 isdn_tty_reset_profile(m
);
2893 isdn_tty_modem_reset_regs(info
, 1);
2895 #ifdef DUMMY_HAYES_AT
2897 /* only for be compilant with common scripts */
2898 /* &K Flowcontrol - no function */
2904 /* &L -Set Numbers to listen on */
2907 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
2909 m
->lmsn
[i
++] = *p
[0]++;
2913 /* &R - Set V.110 bitrate adaption */
2918 /* Switch off V.110, back to X.75 */
2919 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2920 m
->mdmreg
[REG_SI2
] = 0;
2921 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2924 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
2925 m
->mdmreg
[REG_SI2
] = 197;
2926 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2929 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
2930 m
->mdmreg
[REG_SI2
] = 199;
2931 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2934 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
2935 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
2936 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2941 /* Switch off T.70 */
2942 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2944 m
->mdmreg
[REG_SI1
] |= 4;
2947 /* &S - Set Windowsize */
2950 if ((i
> 0) && (i
< 9))
2951 m
->mdmreg
[REG_WSIZE
] = i
;
2956 /* &V - Show registers */
2958 isdn_tty_at_cout("\r\n", info
);
2959 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
2960 sprintf(rb
, "S%02d=%03d%s", i
,
2961 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
2962 isdn_tty_at_cout(rb
, info
);
2964 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
2965 strlen(m
->msn
) ? m
->msn
: "None");
2966 isdn_tty_at_cout(rb
, info
);
2967 if (strlen(m
->lmsn
)) {
2968 isdn_tty_at_cout("\r\nListen: ", info
);
2969 isdn_tty_at_cout(m
->lmsn
, info
);
2970 isdn_tty_at_cout("\r\n", info
);
2974 /* &W - Write Profile */
2979 modem_write_profile(m
);
2986 /* &X - Switch to BTX-Mode and T.70 */
2988 switch (isdn_getnum(p
)) {
2990 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2991 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2994 m
->mdmreg
[REG_T70
] |= BIT_T70
;
2995 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
2996 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2997 info
->xmit_size
= 112;
2998 m
->mdmreg
[REG_SI1
] = 4;
2999 m
->mdmreg
[REG_SI2
] = 0;
3002 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
3003 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3004 info
->xmit_size
= 112;
3005 m
->mdmreg
[REG_SI1
] = 4;
3006 m
->mdmreg
[REG_SI2
] = 0;
3019 isdn_tty_check_ats(int mreg
, int mval
, modem_info
* info
, atemu
* m
)
3021 /* Some plausibility checks */
3024 if (mval
> ISDN_PROTO_L2_MAX
)
3028 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
3030 #ifdef CONFIG_ISDN_AUDIO
3031 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
3034 info
->xmit_size
= mval
* 16;
3035 switch (m
->mdmreg
[REG_L2PROT
]) {
3036 case ISDN_PROTO_L2_V11096
:
3037 case ISDN_PROTO_L2_V11019
:
3038 case ISDN_PROTO_L2_V11038
:
3039 info
->xmit_size
/= 10;
3045 /* readonly registers */
3052 * Perform ATS command
3055 isdn_tty_cmd_ATS(char **p
, modem_info
* info
)
3057 atemu
*m
= &info
->emu
;
3063 mreg
= isdn_getnum(p
);
3064 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
3069 mval
= isdn_getnum(p
);
3070 if (mval
< 0 || mval
> 255)
3072 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3074 m
->mdmreg
[mreg
] = mval
;
3077 /* Set/Clear a single bit */
3079 bitpos
= isdn_getnum(p
);
3080 if ((bitpos
< 0) || (bitpos
> 7))
3085 bval
= isdn_getnum(p
);
3086 if (bval
< 0 || bval
> 1)
3089 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
3091 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
3092 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3094 m
->mdmreg
[mreg
] = mval
;
3098 isdn_tty_at_cout("\r\n", info
);
3099 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
3108 isdn_tty_show_profile(mreg
, info
);
3118 * Perform ATA command
3121 isdn_tty_cmd_ATA(modem_info
* info
)
3123 atemu
*m
= &info
->emu
;
3127 if (info
->msr
& UART_MSR_RI
) {
3128 /* Accept incoming call */
3130 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
3131 m
->mdmreg
[REG_RINGCNT
] = 0;
3132 info
->msr
&= ~UART_MSR_RI
;
3133 l2
= m
->mdmreg
[REG_L2PROT
];
3134 #ifdef CONFIG_ISDN_AUDIO
3135 /* If more than one bit set in reg18, autoselect Layer2 */
3136 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
3137 if (m
->mdmreg
[REG_SI1I
] == 1) {
3138 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
3139 l2
= ISDN_PROTO_L2_TRANS
;
3141 l2
= ISDN_PROTO_L2_X75I
;
3144 cmd
.driver
= info
->isdn_driver
;
3145 cmd
.command
= ISDN_CMD_SETL2
;
3146 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
3149 cmd
.driver
= info
->isdn_driver
;
3150 cmd
.command
= ISDN_CMD_SETL3
;
3151 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
3152 #ifdef CONFIG_ISDN_TTY_FAX
3153 if (l2
== ISDN_PROTO_L2_FAX
) {
3154 cmd
.parm
.fax
= info
->fax
;
3155 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3159 cmd
.driver
= info
->isdn_driver
;
3160 cmd
.arg
= info
->isdn_channel
;
3161 cmd
.command
= ISDN_CMD_ACCEPTD
;
3163 info
->emu
.carrierwait
= 0;
3165 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3167 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3170 #ifdef CONFIG_ISDN_AUDIO
3172 * Parse AT+F.. commands
3175 isdn_tty_cmd_PLUSF(char **p
, modem_info
* info
)
3177 atemu
*m
= &info
->emu
;
3180 if (!strncmp(p
[0], "CLASS", 5)) {
3185 sprintf(rs
, "\r\n%d",
3186 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3187 #ifdef CONFIG_ISDN_TTY_FAX
3188 if (TTY_IS_FCLASS2(info
))
3189 sprintf(rs
, "\r\n2");
3190 else if (TTY_IS_FCLASS1(info
))
3191 sprintf(rs
, "\r\n1");
3193 isdn_tty_at_cout(rs
, info
);
3200 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3201 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3202 m
->mdmreg
[REG_SI1
] = 4;
3204 m
->mdmreg
[REG_PSIZE
] * 16;
3206 #ifdef CONFIG_ISDN_TTY_FAX
3209 if (!(dev
->global_features
&
3210 ISDN_FEATURE_L3_FCLASS1
))
3212 m
->mdmreg
[REG_SI1
] = 1;
3213 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3214 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3216 m
->mdmreg
[REG_PSIZE
] * 16;
3220 if (!(dev
->global_features
&
3221 ISDN_FEATURE_L3_FCLASS2
))
3223 m
->mdmreg
[REG_SI1
] = 1;
3224 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3225 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3227 m
->mdmreg
[REG_PSIZE
] * 16;
3232 /* L2 will change on dialout with si=1 */
3233 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3234 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3235 m
->mdmreg
[REG_SI1
] = 5;
3236 info
->xmit_size
= VBUF
;
3240 strcpy(rs
, "\r\n0,");
3241 #ifdef CONFIG_ISDN_TTY_FAX
3242 if (dev
->global_features
&
3243 ISDN_FEATURE_L3_FCLASS1
)
3245 if (dev
->global_features
&
3246 ISDN_FEATURE_L3_FCLASS2
)
3250 isdn_tty_at_cout(rs
, info
);
3261 #ifdef CONFIG_ISDN_TTY_FAX
3262 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3269 * Parse AT+V.. commands
3272 isdn_tty_cmd_PLUSV(char **p
, modem_info
* info
)
3274 atemu
*m
= &info
->emu
;
3276 static char *vcmd
[] =
3277 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3285 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3293 /* AT+VNH - Auto hangup feature */
3297 isdn_tty_at_cout("\r\n1", info
);
3307 isdn_tty_at_cout("\r\n1", info
);
3318 /* AT+VIP - Reset all voice parameters */
3319 isdn_tty_modem_reset_vpar(m
);
3322 /* AT+VLS - Select device, accept incoming call */
3326 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3327 isdn_tty_at_cout(rs
, info
);
3342 isdn_tty_at_cout("\r\n0,2", info
);
3353 /* AT+VRX - Start recording */
3356 if (info
->online
!= 1) {
3357 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3360 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3361 if (!info
->dtmf_state
) {
3362 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3365 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3366 if (!info
->silence_state
) {
3367 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3370 if (m
->vpar
[3] < 5) {
3371 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3372 if (!info
->adpcmr
) {
3373 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3377 #ifdef ISDN_DEBUG_AT
3378 printk(KERN_DEBUG
"AT: +VRX\n");
3381 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3385 /* AT+VSD - Silence detection */
3389 sprintf(rs
, "\r\n<%d>,<%d>",
3392 isdn_tty_at_cout(rs
, info
);
3396 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3397 par1
= isdn_getnum(p
);
3398 if ((par1
< 0) || (par1
> 31))
3403 par2
= isdn_getnum(p
);
3404 if ((par2
< 0) || (par2
> 255))
3412 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3423 /* AT+VSM - Select compression */
3427 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3430 isdn_tty_at_cout(rs
, info
);
3440 par1
= isdn_getnum(p
);
3441 if ((par1
< 2) || (par1
> 6))
3447 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3449 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3451 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3453 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3455 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3467 /* AT+VTX - Start sending */
3470 if (info
->online
!= 1) {
3471 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3474 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3475 if (!info
->dtmf_state
) {
3476 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3479 if (m
->vpar
[3] < 5) {
3480 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3481 if (!info
->adpcms
) {
3482 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3486 #ifdef ISDN_DEBUG_AT
3487 printk(KERN_DEBUG
"AT: +VTX\n");
3491 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3495 /* AT+VDD - DTMF detection */
3499 sprintf(rs
, "\r\n<%d>,<%d>",
3502 isdn_tty_at_cout(rs
, info
);
3506 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3507 if (info
->online
!= 1)
3509 par1
= isdn_getnum(p
);
3510 if ((par1
< 0) || (par1
> 15))
3515 par2
= isdn_getnum(p
);
3516 if ((par2
< 0) || (par2
> 255))
3520 cmd
.driver
= info
->isdn_driver
;
3521 cmd
.command
= ISDN_CMD_AUDIO
;
3522 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3523 cmd
.parm
.num
[0] = par1
;
3524 cmd
.parm
.num
[1] = par2
;
3530 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3545 #endif /* CONFIG_ISDN_AUDIO */
3548 * Parse and perform an AT-command-line.
3551 isdn_tty_parse_at(modem_info
* info
)
3553 atemu
*m
= &info
->emu
;
3557 #ifdef ISDN_DEBUG_AT
3558 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
3560 for (p
= &m
->mdmcmd
[2]; *p
;) {
3566 /* A - Accept incoming call */
3568 isdn_tty_cmd_ATA(info
);
3573 if (info
->msr
& UART_MSR_DCD
)
3575 if (info
->msr
& UART_MSR_RI
) {
3576 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3579 isdn_tty_getdial(++p
, ds
, sizeof ds
);
3581 if (!strlen(m
->msn
))
3582 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
3583 else if (strlen(ds
))
3584 isdn_tty_dial(ds
, info
, m
);
3589 /* E - Turn Echo on/off */
3591 switch (isdn_getnum(&p
)) {
3593 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
3596 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
3603 /* H - On/Off-hook */
3608 isdn_tty_on_hook(info
);
3612 isdn_tty_off_hook();
3615 isdn_tty_on_hook(info
);
3620 /* I - Information */
3622 isdn_tty_at_cout("\r\nLinux ISDN", info
);
3630 isdn_tty_report(info
);
3634 sprintf(ds
, "\r\n%d", info
->emu
.charge
);
3635 isdn_tty_at_cout(ds
, info
);
3640 #ifdef DUMMY_HAYES_AT
3643 /* only for be compilant with common scripts */
3652 if (info
->msr
& UART_MSR_DCD
)
3653 /* if B-Channel is up */
3654 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
:RESULT_CONNECT64000
, info
);
3656 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3659 /* Q - Turn Emulator messages on/off */
3661 switch (isdn_getnum(&p
)) {
3663 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
3666 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
3673 /* S - Set/Get Register */
3675 if (isdn_tty_cmd_ATS(&p
, info
))
3679 /* V - Numeric or ASCII Emulator-messages */
3681 switch (isdn_getnum(&p
)) {
3683 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
3686 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
3693 /* Z - Load Registers from Profile */
3695 if (info
->msr
& UART_MSR_DCD
) {
3697 isdn_tty_on_hook(info
);
3699 isdn_tty_modem_reset_regs(info
, 1);
3704 #ifdef CONFIG_ISDN_AUDIO
3707 if (isdn_tty_cmd_PLUSF(&p
, info
))
3711 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
3712 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
3715 if (isdn_tty_cmd_PLUSV(&p
, info
))
3718 #endif /* CONFIG_ISDN_AUDIO */
3719 case 'S': /* SUSPEND */
3721 isdn_tty_get_msnstr(ds
, &p
);
3722 isdn_tty_suspend(ds
, info
, m
);
3724 case 'R': /* RESUME */
3726 isdn_tty_get_msnstr(ds
, &p
);
3727 isdn_tty_resume(ds
, info
, m
);
3729 case 'M': /* MESSAGE */
3731 isdn_tty_send_msg(info
, m
, p
);
3739 if (isdn_tty_cmd_ATand(&p
, info
))
3746 #ifdef CONFIG_ISDN_AUDIO
3749 isdn_tty_modem_result(RESULT_OK
, info
);
3752 /* Need own toupper() because standard-toupper is not available
3755 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
3758 * Perform line-editing of AT-commands
3762 * count length of buffer
3763 * channel index to line (minor-device)
3764 * user flag: buffer is in userspace
3767 isdn_tty_edit_at(const char *p
, int count
, modem_info
* info
, int user
)
3769 atemu
*m
= &info
->emu
;
3775 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
3781 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
3782 /* Separator (CR or LF) */
3783 m
->mdmcmd
[m
->mdmcmdl
] = 0;
3784 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3787 isdn_tty_at_cout(eb
, info
);
3789 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
3790 isdn_tty_parse_at(info
);
3794 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
3795 /* Backspace-Function */
3796 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
3799 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
3800 isdn_tty_at_cout("\b", info
);
3805 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3808 isdn_tty_at_cout(eb
, info
);
3810 if (m
->mdmcmdl
< 255) {
3812 switch (m
->mdmcmdl
) {
3815 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3816 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3820 /* Fall through, check for 'A' */
3823 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3824 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3828 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3829 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3838 * Switch all modem-channels who are online and got a valid
3839 * escape-sequence 1.5 seconds ago, to command-mode.
3840 * This function is called every second via timer-interrupt from within
3841 * timer-dispatcher isdn_timer_function()
3844 isdn_tty_modem_escape(void)
3850 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
3851 if (USG_MODEM(dev
->usage
[i
]))
3852 if ((midx
= dev
->m_idx
[i
]) >= 0) {
3853 modem_info
*info
= &dev
->mdm
.info
[midx
];
3856 if ((info
->emu
.pluscount
== 3) &&
3857 time_after(jiffies
, info
->emu
.lastplus
+ PLUSWAIT2
)) {
3858 info
->emu
.pluscount
= 0;
3860 isdn_tty_modem_result(RESULT_OK
, info
);
3864 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
3868 * Put a RING-message to all modem-channels who have the RI-bit set.
3869 * This function is called every second via timer-interrupt from within
3870 * timer-dispatcher isdn_timer_function()
3873 isdn_tty_modem_ring(void)
3878 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3879 modem_info
*info
= &dev
->mdm
.info
[i
];
3880 if (info
->msr
& UART_MSR_RI
) {
3882 isdn_tty_modem_result(RESULT_RING
, info
);
3885 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
3889 * For all online tty's, try sending data to
3893 isdn_tty_modem_xmit(void)
3898 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3899 modem_info
*info
= &dev
->mdm
.info
[i
];
3902 isdn_tty_senddown(info
);
3903 isdn_tty_tint(info
);
3906 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
3910 * Check all channels if we have a 'no carrier' timeout.
3911 * Timeout value is set by Register S7.
3914 isdn_tty_carrier_timeout(void)
3919 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3920 modem_info
*info
= &dev
->mdm
.info
[i
];
3921 if (info
->dialing
) {
3922 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
3924 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3925 isdn_tty_modem_hup(info
, 1);
3931 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);