2 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
4 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
5 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
11 #undef ISDN_TTY_STAT_DEBUG
13 #include <linux/isdn.h>
14 #include <linux/serial.h> /* ASYNC_* flags */
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/mutex.h>
18 #include <linux/sched/signal.h>
19 #include "isdn_common.h"
21 #ifdef CONFIG_ISDN_AUDIO
22 #include "isdn_audio.h"
24 #define VBUFX (VBUF/16)
27 #define FIX_FILE_TRANSFER
28 #define DUMMY_HAYES_AT
32 static DEFINE_MUTEX(modem_info_mutex
);
33 static int isdn_tty_edit_at(const char *, int, modem_info
*);
34 static void isdn_tty_check_esc(const u_char
*, u_char
, int, int *, u_long
*);
35 static void isdn_tty_modem_reset_regs(modem_info
*, int);
36 static void isdn_tty_cmd_ATA(modem_info
*);
37 static void isdn_tty_flush_buffer(struct tty_struct
*);
38 static void isdn_tty_modem_result(int, modem_info
*);
39 #ifdef CONFIG_ISDN_AUDIO
40 static int isdn_tty_countDLE(unsigned char *, int);
43 /* Leave this unchanged unless you know what you do! */
44 #define MODEM_PARANOIA_CHECK
45 #define MODEM_DO_RESTART
47 static int bit2si
[8] =
48 {1, 5, 7, 7, 7, 7, 7, 7};
49 static int si2bit
[8] =
50 {4, 1, 4, 4, 4, 4, 4, 4};
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
)
64 struct tty_port
*port
= &info
->port
;
72 if (!(info
->mcr
& UART_MCR_RTS
))
76 #ifdef CONFIG_ISDN_AUDIO
77 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
81 c
= tty_buffer_request_room(port
, len
);
85 #ifdef CONFIG_ISDN_AUDIO
86 if (ISDN_AUDIO_SKB_DLECOUNT(skb
)) {
88 unsigned char *dp
= skb
->data
;
91 tty_insert_flip_char(port
, DLE
, 0);
92 tty_insert_flip_char(port
, *dp
++, 0);
95 tty_insert_flip_char(port
, DLE
, 0);
100 tty_insert_flip_string(port
, skb
->data
, len
- 1);
101 last
= skb
->data
[len
- 1];
102 #ifdef CONFIG_ISDN_AUDIO
105 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
106 tty_insert_flip_char(port
, last
, 0xFF);
108 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
109 tty_flip_buffer_push(port
);
115 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
116 * It tries getting received data from the receive queue an stuff it into
117 * the tty's flip-buffer.
120 isdn_tty_readmodem(void)
128 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
129 midx
= dev
->m_idx
[i
];
133 info
= &dev
->mdm
.info
[midx
];
138 #ifdef CONFIG_ISDN_AUDIO
139 isdn_audio_eval_dtmf(info
);
140 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
141 isdn_audio_eval_silence(info
);
143 if (info
->mcr
& UART_MCR_RTS
) {
144 /* CISCO AsyncPPP Hack */
145 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
146 r
= isdn_readbchan_tty(info
->isdn_driver
,
150 r
= isdn_readbchan_tty(info
->isdn_driver
,
154 tty_flip_buffer_push(&info
->port
);
165 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
169 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
173 #ifdef CONFIG_ISDN_AUDIO
178 if ((midx
= dev
->m_idx
[i
]) < 0) {
179 /* if midx is invalid, packet is not for tty */
182 info
= &dev
->mdm
.info
[midx
];
183 #ifdef CONFIG_ISDN_AUDIO
186 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
187 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
188 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
189 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
191 if ((info
->online
< 2)
192 #ifdef CONFIG_ISDN_AUDIO
193 && (!(info
->vonline
& 1))
196 /* If Modem not listening, drop data */
200 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
201 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
202 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
203 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
206 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
209 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
210 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
213 #ifdef CONFIG_ISDN_AUDIO
214 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
215 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
216 if (info
->vonline
& 1) {
217 /* voice conversion/compression */
218 switch (info
->emu
.vpar
[3]) {
223 * Since compressed data takes less
224 * space, we can overwrite the buffer.
226 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
235 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
240 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
243 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
244 isdn_tty_countDLE(skb
->data
, skb
->len
);
246 #ifdef CONFIG_ISDN_TTY_FAX
248 if (info
->faxonline
& 2) {
249 isdn_tty_fax_bitorder(info
, skb
);
250 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
251 isdn_tty_countDLE(skb
->data
, skb
->len
);
256 /* Try to deliver directly via tty-buf if queue is empty */
257 spin_lock_irqsave(&info
->readlock
, flags
);
258 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
259 if (isdn_tty_try_read(info
, skb
)) {
260 spin_unlock_irqrestore(&info
->readlock
, flags
);
263 /* Direct deliver failed or queue wasn't empty.
264 * Queue up for later dequeueing via timer-irq.
266 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
267 dev
->drv
[di
]->rcvcount
[channel
] +=
269 #ifdef CONFIG_ISDN_AUDIO
270 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
273 spin_unlock_irqrestore(&info
->readlock
, flags
);
274 /* Schedule dequeuing */
275 if ((dev
->modempoll
) && (info
->rcvsched
))
276 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
281 isdn_tty_cleanup_xmit(modem_info
*info
)
283 skb_queue_purge(&info
->xmit_queue
);
284 #ifdef CONFIG_ISDN_AUDIO
285 skb_queue_purge(&info
->dtmf_queue
);
290 isdn_tty_tint(modem_info
*info
)
292 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
298 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
299 info
->isdn_channel
, 1, skb
)) == len
) {
300 struct tty_struct
*tty
= info
->port
.tty
;
301 info
->send_outstanding
++;
302 info
->msr
&= ~UART_MSR_CTS
;
303 info
->lsr
&= ~UART_LSR_TEMT
;
308 /* Error: no channel, already shutdown, or wrong parameter */
312 skb_queue_head(&info
->xmit_queue
, skb
);
315 #ifdef CONFIG_ISDN_AUDIO
317 isdn_tty_countDLE(unsigned char *buf
, int len
)
327 /* This routine is called from within isdn_tty_write() to perform
328 * DLE-decoding when sending audio-data.
331 isdn_tty_handleDLEdown(modem_info
*info
, atemu
*m
, int len
)
333 unsigned char *p
= &info
->port
.xmit_buf
[info
->xmit_count
];
343 memmove(p
, p
+ 1, len
- 1);
354 #ifdef ISDN_DEBUG_MODEM_VOICE
356 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
359 isdn_tty_at_cout("\020\003", info
);
360 if (!info
->vonline
) {
361 #ifdef ISDN_DEBUG_MODEM_VOICE
363 "DLEdown: send VCON on ttyI%d\n",
366 isdn_tty_at_cout("\r\nVCON\r\n", info
);
373 memmove(p
, p
+ 1, len
- 1);
387 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
393 /* This routine is called from within isdn_tty_write() when receiving
394 * audio-data. It interrupts receiving, if an character other than
398 isdn_tty_end_vrx(const char *buf
, int c
)
404 if ((ch
!= 0x11) && (ch
!= 0x13))
411 static int voice_cf
[7] =
412 {0, 0, 4, 3, 2, 0, 0};
414 #endif /* CONFIG_ISDN_AUDIO */
416 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
417 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
418 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
419 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
422 isdn_tty_senddown(modem_info
*info
)
426 #ifdef CONFIG_ISDN_AUDIO
431 #ifdef CONFIG_ISDN_AUDIO
432 if (info
->vonline
& 4) {
434 if (!info
->vonline
) {
435 #ifdef ISDN_DEBUG_MODEM_VOICE
437 "senddown: send VCON on ttyI%d\n",
440 isdn_tty_at_cout("\r\nVCON\r\n", info
);
444 if (!(buflen
= info
->xmit_count
))
446 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
447 info
->msr
&= ~UART_MSR_CTS
;
448 info
->lsr
&= ~UART_LSR_TEMT
;
449 /* info->xmit_count is modified here and in isdn_tty_write().
450 * So we return here if isdn_tty_write() is in the
453 atomic_inc(&info
->xmit_lock
);
454 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
456 if (info
->isdn_driver
< 0) {
457 info
->xmit_count
= 0;
460 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
461 #ifdef CONFIG_ISDN_AUDIO
462 if (info
->vonline
& 2)
463 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
466 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
468 skb
= dev_alloc_skb(skb_res
+ buflen
);
472 "isdn_tty: Out of memory in ttyI%d senddown\n",
476 skb_reserve(skb
, skb_res
);
477 skb_put_data(skb
, info
->port
.xmit_buf
, buflen
);
478 info
->xmit_count
= 0;
479 #ifdef CONFIG_ISDN_AUDIO
480 if (info
->vonline
& 2) {
481 /* For now, ifmt is fixed to 1 (alaw), since this
482 * is used with ISDN everywhere in the world, except
483 * US, Canada and Japan.
484 * Later, when US-ISDN protocols are implemented,
485 * this setting will depend on the D-channel protocol.
489 /* voice conversion/decompression */
490 switch (info
->emu
.vpar
[3]) {
494 /* adpcm, compatible to ZyXel 1496 modem
495 * with ROM revision 6.01
497 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
500 skb_put(skb
, audio_len
),
502 skb_pull(skb
, buflen
);
503 skb_trim(skb
, audio_len
);
508 isdn_audio_alaw2ulaw(skb
->data
,
514 isdn_audio_ulaw2alaw(skb
->data
,
519 #endif /* CONFIG_ISDN_AUDIO */
520 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
521 /* Add T.70 simplified header */
522 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
523 memcpy(skb_push(skb
, 2), "\1\0", 2);
525 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
527 skb_queue_tail(&info
->xmit_queue
, skb
);
530 /************************************************************
534 * mostly "stolen" from original Linux-serial.c and friends.
536 ************************************************************/
538 /* The next routine is called once from within timer-interrupt
539 * triggered within isdn_tty_modem_ncarrier(). It calls
540 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
541 * into the tty's buffer.
544 isdn_tty_modem_do_ncarrier(struct timer_list
*t
)
546 modem_info
*info
= from_timer(info
, t
, nc_timer
);
547 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
550 /* Next routine is called, whenever the DTR-signal is raised.
551 * It checks the ncarrier-flag, and triggers the above routine
552 * when necessary. The ncarrier-flag is set, whenever DTR goes
556 isdn_tty_modem_ncarrier(modem_info
*info
)
558 if (info
->ncarrier
) {
559 info
->nc_timer
.expires
= jiffies
+ HZ
;
560 add_timer(&info
->nc_timer
);
565 * return the usage calculated by si and layer 2 protocol
568 isdn_calc_usage(int si
, int l2
)
570 int usg
= ISDN_USAGE_MODEM
;
572 #ifdef CONFIG_ISDN_AUDIO
575 case ISDN_PROTO_L2_MODEM
:
576 usg
= ISDN_USAGE_MODEM
;
578 #ifdef CONFIG_ISDN_TTY_FAX
579 case ISDN_PROTO_L2_FAX
:
580 usg
= ISDN_USAGE_FAX
;
583 case ISDN_PROTO_L2_TRANS
:
585 usg
= ISDN_USAGE_VOICE
;
593 /* isdn_tty_dial() performs dialing of a tty an the necessary
594 * setup of the lower levels before that.
597 isdn_tty_dial(char *n
, modem_info
*info
, atemu
*m
)
599 int usg
= ISDN_USAGE_MODEM
;
601 int l2
= m
->mdmreg
[REG_L2PROT
];
607 for (j
= 7; j
>= 0; j
--)
608 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
612 usg
= isdn_calc_usage(si
, l2
);
613 #ifdef CONFIG_ISDN_AUDIO
615 (l2
!= ISDN_PROTO_L2_MODEM
)
616 #ifdef CONFIG_ISDN_TTY_FAX
617 && (l2
!= ISDN_PROTO_L2_FAX
)
620 l2
= ISDN_PROTO_L2_TRANS
;
621 usg
= ISDN_USAGE_VOICE
;
624 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
625 spin_lock_irqsave(&dev
->lock
, flags
);
626 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
628 spin_unlock_irqrestore(&dev
->lock
, flags
);
629 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
631 info
->isdn_driver
= dev
->drvmap
[i
];
632 info
->isdn_channel
= dev
->chanmap
[i
];
634 dev
->m_idx
[i
] = info
->line
;
635 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
637 strcpy(info
->last_num
, n
);
639 spin_unlock_irqrestore(&dev
->lock
, flags
);
640 cmd
.driver
= info
->isdn_driver
;
641 cmd
.arg
= info
->isdn_channel
;
642 cmd
.command
= ISDN_CMD_CLREAZ
;
644 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
645 cmd
.driver
= info
->isdn_driver
;
646 cmd
.command
= ISDN_CMD_SETEAZ
;
648 cmd
.driver
= info
->isdn_driver
;
649 cmd
.command
= ISDN_CMD_SETL2
;
651 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
653 cmd
.driver
= info
->isdn_driver
;
654 cmd
.command
= ISDN_CMD_SETL3
;
655 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
656 #ifdef CONFIG_ISDN_TTY_FAX
657 if (l2
== ISDN_PROTO_L2_FAX
) {
658 cmd
.parm
.fax
= info
->fax
;
659 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
663 cmd
.driver
= info
->isdn_driver
;
664 cmd
.arg
= info
->isdn_channel
;
665 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
666 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
667 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
668 cmd
.parm
.setup
.si1
= si
;
669 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
670 cmd
.command
= ISDN_CMD_DIAL
;
672 info
->emu
.carrierwait
= 0;
673 strcpy(dev
->num
[i
], n
);
676 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
680 /* isdn_tty_hangup() disassociates a tty from the real
681 * ISDN-line (hangup). The usage-status is cleared
682 * and some cleanup is done also.
685 isdn_tty_modem_hup(modem_info
*info
, int local
)
693 di
= info
->isdn_driver
;
694 ch
= info
->isdn_channel
;
695 if (di
< 0 || ch
< 0)
698 info
->isdn_driver
= -1;
699 info
->isdn_channel
= -1;
701 #ifdef ISDN_DEBUG_MODEM_HUP
702 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
705 isdn_tty_flush_buffer(info
->port
.tty
);
707 info
->last_lhup
= local
;
709 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
711 #ifdef CONFIG_ISDN_AUDIO
713 #ifdef CONFIG_ISDN_TTY_FAX
715 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
717 info
->emu
.vpar
[4] = 0;
718 info
->emu
.vpar
[5] = 8;
719 kfree(info
->dtmf_state
);
720 info
->dtmf_state
= NULL
;
721 kfree(info
->silence_state
);
722 info
->silence_state
= NULL
;
728 if ((info
->msr
& UART_MSR_RI
) &&
729 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
730 isdn_tty_modem_result(RESULT_RUNG
, info
);
731 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
732 info
->lsr
|= UART_LSR_TEMT
;
736 cmd
.command
= ISDN_CMD_HANGUP
;
741 isdn_all_eaz(di
, ch
);
742 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
743 isdn_free_channel(di
, ch
, 0);
745 if (info
->drv_index
>= 0) {
746 dev
->m_idx
[info
->drv_index
] = -1;
747 info
->drv_index
= -1;
752 * Begin of a CAPI like interface, currently used only for
753 * supplementary service (CAPI 2.0 part III)
755 #include <linux/isdn/capicmd.h>
756 #include <linux/module.h>
759 isdn_tty_capi_facility(capi_msg
*cm
) {
760 return (-1); /* dummy */
763 /* isdn_tty_suspend() tries to suspend the current tty connection
766 isdn_tty_suspend(char *id
, modem_info
*info
, atemu
*m
)
775 #ifdef ISDN_DEBUG_MODEM_SERVICES
776 printk(KERN_DEBUG
"Msusp ttyI%d\n", info
->line
);
779 if ((info
->isdn_driver
>= 0)) {
780 cmd
.parm
.cmsg
.Length
= l
+ 18;
781 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
782 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
783 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
784 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
785 cmd
.parm
.cmsg
.para
[1] = 0;
786 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
787 cmd
.parm
.cmsg
.para
[3] = 4; /* 16 bit 0x0004 Suspend */
788 cmd
.parm
.cmsg
.para
[4] = 0;
789 cmd
.parm
.cmsg
.para
[5] = l
;
790 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
791 cmd
.command
= CAPI_PUT_MESSAGE
;
792 cmd
.driver
= info
->isdn_driver
;
793 cmd
.arg
= info
->isdn_channel
;
798 /* isdn_tty_resume() tries to resume a suspended call
799 * setup of the lower levels before that. unfortunately here is no
800 * checking for compatibility of used protocols implemented by Q931
801 * It does the same things like isdn_tty_dial, the last command
802 * is different, may be we can merge it.
806 isdn_tty_resume(char *id
, modem_info
*info
, atemu
*m
)
808 int usg
= ISDN_USAGE_MODEM
;
810 int l2
= m
->mdmreg
[REG_L2PROT
];
818 for (j
= 7; j
>= 0; j
--)
819 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
823 usg
= isdn_calc_usage(si
, l2
);
824 #ifdef CONFIG_ISDN_AUDIO
826 (l2
!= ISDN_PROTO_L2_MODEM
)
827 #ifdef CONFIG_ISDN_TTY_FAX
828 && (l2
!= ISDN_PROTO_L2_FAX
)
831 l2
= ISDN_PROTO_L2_TRANS
;
832 usg
= ISDN_USAGE_VOICE
;
835 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
836 spin_lock_irqsave(&dev
->lock
, flags
);
837 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
839 spin_unlock_irqrestore(&dev
->lock
, flags
);
840 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
842 info
->isdn_driver
= dev
->drvmap
[i
];
843 info
->isdn_channel
= dev
->chanmap
[i
];
845 dev
->m_idx
[i
] = info
->line
;
846 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
848 // strcpy(info->last_num, n);
850 spin_unlock_irqrestore(&dev
->lock
, flags
);
851 cmd
.driver
= info
->isdn_driver
;
852 cmd
.arg
= info
->isdn_channel
;
853 cmd
.command
= ISDN_CMD_CLREAZ
;
855 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
856 cmd
.driver
= info
->isdn_driver
;
857 cmd
.command
= ISDN_CMD_SETEAZ
;
859 cmd
.driver
= info
->isdn_driver
;
860 cmd
.command
= ISDN_CMD_SETL2
;
862 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
864 cmd
.driver
= info
->isdn_driver
;
865 cmd
.command
= ISDN_CMD_SETL3
;
866 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
868 cmd
.driver
= info
->isdn_driver
;
869 cmd
.arg
= info
->isdn_channel
;
870 cmd
.parm
.cmsg
.Length
= l
+ 18;
871 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
872 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
873 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
874 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
875 cmd
.parm
.cmsg
.para
[1] = 0;
876 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
877 cmd
.parm
.cmsg
.para
[3] = 5; /* 16 bit 0x0005 Resume */
878 cmd
.parm
.cmsg
.para
[4] = 0;
879 cmd
.parm
.cmsg
.para
[5] = l
;
880 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
881 cmd
.command
= CAPI_PUT_MESSAGE
;
883 // strcpy(dev->num[i], n);
886 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
890 /* isdn_tty_send_msg() sends a message to a HL driver
891 * This is used for hybrid modem cards to send AT commands to it
895 isdn_tty_send_msg(modem_info
*info
, atemu
*m
, char *msg
)
897 int usg
= ISDN_USAGE_MODEM
;
899 int l2
= m
->mdmreg
[REG_L2PROT
];
906 l
= min(strlen(msg
), sizeof(cmd
.parm
) - sizeof(cmd
.parm
.cmsg
)
907 + sizeof(cmd
.parm
.cmsg
.para
) - 2);
910 isdn_tty_modem_result(RESULT_ERROR
, info
);
913 for (j
= 7; j
>= 0; j
--)
914 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
918 usg
= isdn_calc_usage(si
, l2
);
919 #ifdef CONFIG_ISDN_AUDIO
921 (l2
!= ISDN_PROTO_L2_MODEM
)
922 #ifdef CONFIG_ISDN_TTY_FAX
923 && (l2
!= ISDN_PROTO_L2_FAX
)
926 l2
= ISDN_PROTO_L2_TRANS
;
927 usg
= ISDN_USAGE_VOICE
;
930 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
931 spin_lock_irqsave(&dev
->lock
, flags
);
932 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
934 spin_unlock_irqrestore(&dev
->lock
, flags
);
935 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
937 info
->isdn_driver
= dev
->drvmap
[i
];
938 info
->isdn_channel
= dev
->chanmap
[i
];
940 dev
->m_idx
[i
] = info
->line
;
941 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
944 spin_unlock_irqrestore(&dev
->lock
, flags
);
945 cmd
.driver
= info
->isdn_driver
;
946 cmd
.arg
= info
->isdn_channel
;
947 cmd
.command
= ISDN_CMD_CLREAZ
;
949 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
950 cmd
.driver
= info
->isdn_driver
;
951 cmd
.command
= ISDN_CMD_SETEAZ
;
953 cmd
.driver
= info
->isdn_driver
;
954 cmd
.command
= ISDN_CMD_SETL2
;
956 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
958 cmd
.driver
= info
->isdn_driver
;
959 cmd
.command
= ISDN_CMD_SETL3
;
960 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
962 cmd
.driver
= info
->isdn_driver
;
963 cmd
.arg
= info
->isdn_channel
;
964 cmd
.parm
.cmsg
.Length
= l
+ 14;
965 cmd
.parm
.cmsg
.Command
= CAPI_MANUFACTURER
;
966 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
967 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
968 cmd
.parm
.cmsg
.para
[0] = l
+ 1;
969 strncpy(&cmd
.parm
.cmsg
.para
[1], msg
, l
);
970 cmd
.parm
.cmsg
.para
[l
+ 1] = 0xd;
971 cmd
.command
= CAPI_PUT_MESSAGE
;
972 /* info->dialing = 1;
973 strcpy(dev->num[i], n);
981 isdn_tty_paranoia_check(modem_info
*info
, char *name
, const char *routine
)
983 #ifdef MODEM_PARANOIA_CHECK
985 printk(KERN_WARNING
"isdn_tty: null info_struct for %s in %s\n",
989 if (info
->magic
!= ISDN_ASYNC_MAGIC
) {
990 printk(KERN_WARNING
"isdn_tty: bad magic for modem struct %s in %s\n",
999 * This routine is called to set the UART divisor registers to match
1000 * the specified baud rate for a serial port.
1003 isdn_tty_change_speed(modem_info
*info
)
1005 struct tty_port
*port
= &info
->port
;
1013 cflag
= port
->tty
->termios
.c_cflag
;
1015 quot
= i
= cflag
& CBAUD
;
1019 port
->tty
->termios
.c_cflag
&= ~CBAUDEX
;
1024 info
->mcr
|= UART_MCR_DTR
;
1025 isdn_tty_modem_ncarrier(info
);
1027 info
->mcr
&= ~UART_MCR_DTR
;
1028 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1029 #ifdef ISDN_DEBUG_MODEM_HUP
1030 printk(KERN_DEBUG
"Mhup in changespeed\n");
1034 isdn_tty_modem_reset_regs(info
, 0);
1035 isdn_tty_modem_hup(info
, 1);
1039 /* byte size and parity */
1040 cval
= cflag
& (CSIZE
| CSTOPB
);
1043 cval
|= UART_LCR_PARITY
;
1044 if (!(cflag
& PARODD
))
1045 cval
|= UART_LCR_EPAR
;
1047 tty_port_set_check_carrier(port
, ~cflag
& CLOCAL
);
1051 isdn_tty_startup(modem_info
*info
)
1053 if (tty_port_initialized(&info
->port
))
1055 isdn_lock_drivers();
1056 #ifdef ISDN_DEBUG_MODEM_OPEN
1057 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1060 * Now, initialize the UART
1062 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1064 clear_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1066 * and set the speed of the serial port
1068 isdn_tty_change_speed(info
);
1070 tty_port_set_initialized(&info
->port
, 1);
1071 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1072 info
->send_outstanding
= 0;
1077 * This routine will shutdown a serial port; interrupts are disabled, and
1078 * DTR is dropped if the hangup on close termio flag is on.
1081 isdn_tty_shutdown(modem_info
*info
)
1083 if (!tty_port_initialized(&info
->port
))
1085 #ifdef ISDN_DEBUG_MODEM_OPEN
1086 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1088 isdn_unlock_drivers();
1089 info
->msr
&= ~UART_MSR_RI
;
1090 if (!info
->port
.tty
|| (info
->port
.tty
->termios
.c_cflag
& HUPCL
)) {
1091 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1092 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1093 isdn_tty_modem_reset_regs(info
, 0);
1094 #ifdef ISDN_DEBUG_MODEM_HUP
1095 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1097 isdn_tty_modem_hup(info
, 1);
1101 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1103 tty_port_set_initialized(&info
->port
, 0);
1106 /* isdn_tty_write() is the main send-routine. It is called from the upper
1107 * levels within the kernel to perform sending data. Depending on the
1108 * online-flag it either directs output to the at-command-interpreter or
1109 * to the lower level. Additional tasks done here:
1110 * - If online, check for escape-sequence (+++)
1111 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1112 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1113 * - If dialing, abort dial.
1116 isdn_tty_write(struct tty_struct
*tty
, const u_char
*buf
, int count
)
1120 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1121 atemu
*m
= &info
->emu
;
1123 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write"))
1125 /* See isdn_tty_senddown() */
1126 atomic_inc(&info
->xmit_lock
);
1129 if (c
> info
->xmit_size
- info
->xmit_count
)
1130 c
= info
->xmit_size
- info
->xmit_count
;
1131 if (info
->isdn_driver
>= 0 && c
> dev
->drv
[info
->isdn_driver
]->maxbufsize
)
1132 c
= dev
->drv
[info
->isdn_driver
]->maxbufsize
;
1135 if ((info
->online
> 1)
1136 #ifdef CONFIG_ISDN_AUDIO
1137 || (info
->vonline
& 3)
1140 #ifdef CONFIG_ISDN_AUDIO
1143 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1146 memcpy(&info
->port
.xmit_buf
[info
->xmit_count
], buf
, c
);
1147 #ifdef CONFIG_ISDN_AUDIO
1148 if (info
->vonline
) {
1149 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1150 if (info
->vonline
& 2) {
1152 /* If DLE decoding results in zero-transmit, but
1153 * c originally was non-zero, do a wakeup.
1156 info
->msr
|= UART_MSR_CTS
;
1157 info
->lsr
|= UART_LSR_TEMT
;
1159 info
->xmit_count
+= cc
;
1161 if ((info
->vonline
& 3) == 1) {
1162 /* Do NOT handle Ctrl-Q or Ctrl-S
1163 * when in full-duplex audio mode.
1165 if (isdn_tty_end_vrx(buf
, c
)) {
1166 info
->vonline
&= ~1;
1167 #ifdef ISDN_DEBUG_MODEM_VOICE
1169 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1172 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1176 if (TTY_IS_FCLASS1(info
)) {
1177 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1179 if (info
->vonline
& 4) { /* ETX seen */
1182 c
.command
= ISDN_CMD_FAXCMD
;
1183 c
.driver
= info
->isdn_driver
;
1184 c
.arg
= info
->isdn_channel
;
1185 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1186 c
.parm
.aux
.subcmd
= ETX
;
1190 #ifdef ISDN_DEBUG_MODEM_VOICE
1191 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
, c
);
1193 info
->xmit_count
+= cc
;
1196 info
->xmit_count
+= c
;
1198 info
->msr
|= UART_MSR_CTS
;
1199 info
->lsr
|= UART_LSR_TEMT
;
1200 if (info
->dialing
) {
1202 #ifdef ISDN_DEBUG_MODEM_HUP
1203 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1205 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1206 isdn_tty_modem_hup(info
, 1);
1208 c
= isdn_tty_edit_at(buf
, c
, info
);
1214 atomic_dec(&info
->xmit_lock
);
1215 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
)) {
1216 if (m
->mdmreg
[REG_DXMT
] & BIT_DXMT
) {
1217 isdn_tty_senddown(info
);
1218 isdn_tty_tint(info
);
1220 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1226 isdn_tty_write_room(struct tty_struct
*tty
)
1228 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1231 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write_room"))
1234 return info
->xmit_size
;
1235 ret
= info
->xmit_size
- info
->xmit_count
;
1236 return (ret
< 0) ? 0 : ret
;
1240 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1242 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1244 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_chars_in_buffer"))
1248 return (info
->xmit_count
);
1252 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1259 info
= (modem_info
*) tty
->driver_data
;
1260 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_buffer")) {
1263 isdn_tty_cleanup_xmit(info
);
1264 info
->xmit_count
= 0;
1269 isdn_tty_flush_chars(struct tty_struct
*tty
)
1271 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1273 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_chars"))
1275 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
))
1276 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1280 * ------------------------------------------------------------
1281 * isdn_tty_throttle()
1283 * This routine is called by the upper-layer tty layer to signal that
1284 * incoming characters should be throttled.
1285 * ------------------------------------------------------------
1288 isdn_tty_throttle(struct tty_struct
*tty
)
1290 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1292 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_throttle"))
1295 info
->x_char
= STOP_CHAR(tty
);
1296 info
->mcr
&= ~UART_MCR_RTS
;
1300 isdn_tty_unthrottle(struct tty_struct
*tty
)
1302 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1304 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_unthrottle"))
1310 info
->x_char
= START_CHAR(tty
);
1312 info
->mcr
|= UART_MCR_RTS
;
1316 * ------------------------------------------------------------
1317 * isdn_tty_ioctl() and friends
1318 * ------------------------------------------------------------
1322 * isdn_tty_get_lsr_info - get line status register info
1324 * Purpose: Let user call ioctl() to get info when the UART physically
1325 * is emptied. On bus types like RS485, the transmitter must
1326 * release the bus after transmitting. This must be done when
1327 * the transmit shift register is empty, not be done when the
1328 * transmit holding register is empty. This functionality
1329 * allows RS485 driver to be written in user space.
1332 isdn_tty_get_lsr_info(modem_info
*info
, uint __user
*value
)
1338 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1339 return put_user(result
, value
);
1344 isdn_tty_tiocmget(struct tty_struct
*tty
)
1346 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1347 u_char control
, status
;
1349 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1351 if (tty_io_error(tty
))
1354 mutex_lock(&modem_info_mutex
);
1355 #ifdef ISDN_DEBUG_MODEM_IOCTL
1356 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1359 control
= info
->mcr
;
1361 mutex_unlock(&modem_info_mutex
);
1362 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1363 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1364 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1365 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1366 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1367 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1371 isdn_tty_tiocmset(struct tty_struct
*tty
,
1372 unsigned int set
, unsigned int clear
)
1374 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1376 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1378 if (tty_io_error(tty
))
1381 #ifdef ISDN_DEBUG_MODEM_IOCTL
1382 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMxxx: %x %x\n", info
->line
, set
, clear
);
1385 mutex_lock(&modem_info_mutex
);
1386 if (set
& TIOCM_RTS
)
1387 info
->mcr
|= UART_MCR_RTS
;
1388 if (set
& TIOCM_DTR
) {
1389 info
->mcr
|= UART_MCR_DTR
;
1390 isdn_tty_modem_ncarrier(info
);
1393 if (clear
& TIOCM_RTS
)
1394 info
->mcr
&= ~UART_MCR_RTS
;
1395 if (clear
& TIOCM_DTR
) {
1396 info
->mcr
&= ~UART_MCR_DTR
;
1397 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1398 isdn_tty_modem_reset_regs(info
, 0);
1399 #ifdef ISDN_DEBUG_MODEM_HUP
1400 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1404 isdn_tty_modem_hup(info
, 1);
1407 mutex_unlock(&modem_info_mutex
);
1412 isdn_tty_ioctl(struct tty_struct
*tty
, uint cmd
, ulong arg
)
1414 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1417 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_ioctl"))
1419 if (tty_io_error(tty
))
1422 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1423 #ifdef ISDN_DEBUG_MODEM_IOCTL
1424 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1426 retval
= tty_check_change(tty
);
1429 tty_wait_until_sent(tty
, 0);
1431 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1432 #ifdef ISDN_DEBUG_MODEM_IOCTL
1433 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1435 retval
= tty_check_change(tty
);
1438 tty_wait_until_sent(tty
, 0);
1440 case TIOCSERGETLSR
: /* Get line status register */
1441 #ifdef ISDN_DEBUG_MODEM_IOCTL
1442 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1444 return isdn_tty_get_lsr_info(info
, (uint __user
*) arg
);
1446 #ifdef ISDN_DEBUG_MODEM_IOCTL
1447 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1449 return -ENOIOCTLCMD
;
1455 isdn_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
1457 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1460 isdn_tty_change_speed(info
);
1462 if (tty
->termios
.c_cflag
== old_termios
->c_cflag
&&
1463 tty
->termios
.c_ispeed
== old_termios
->c_ispeed
&&
1464 tty
->termios
.c_ospeed
== old_termios
->c_ospeed
)
1466 isdn_tty_change_speed(info
);
1471 * ------------------------------------------------------------
1472 * isdn_tty_open() and friends
1473 * ------------------------------------------------------------
1476 static int isdn_tty_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
1478 modem_info
*info
= &dev
->mdm
.info
[tty
->index
];
1480 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1483 tty
->driver_data
= info
;
1485 return tty_port_install(&info
->port
, driver
, tty
);
1489 * This routine is called whenever a serial port is opened. It
1490 * enables interrupts for a serial port, linking in its async structure into
1491 * the IRQ chain. It also performs the serial-specific
1492 * initialization for the tty structure.
1495 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
1497 modem_info
*info
= tty
->driver_data
;
1498 struct tty_port
*port
= &info
->port
;
1501 #ifdef ISDN_DEBUG_MODEM_OPEN
1502 printk(KERN_DEBUG
"isdn_tty_open %s, count = %d\n", tty
->name
,
1508 * Start up serial port
1510 retval
= isdn_tty_startup(info
);
1512 #ifdef ISDN_DEBUG_MODEM_OPEN
1513 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
1517 retval
= tty_port_block_til_ready(port
, tty
, filp
);
1519 #ifdef ISDN_DEBUG_MODEM_OPEN
1520 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
1524 #ifdef ISDN_DEBUG_MODEM_OPEN
1525 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
1528 #ifdef ISDN_DEBUG_MODEM_OPEN
1529 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
1535 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
1537 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1538 struct tty_port
*port
= &info
->port
;
1541 if (!info
|| isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_close"))
1543 if (tty_hung_up_p(filp
)) {
1544 #ifdef ISDN_DEBUG_MODEM_OPEN
1545 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
1549 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1551 * Uh, oh. tty->count is 1, which means that the tty
1552 * structure will be freed. Info->count should always
1553 * be one in these conditions. If it's greater than
1554 * one, we've got real problems, since it means the
1555 * serial port won't be shutdown.
1557 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
1558 "info->count is %d\n", port
->count
);
1561 if (--port
->count
< 0) {
1562 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
1563 info
->line
, port
->count
);
1567 #ifdef ISDN_DEBUG_MODEM_OPEN
1568 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
1576 * At this point we stop accepting input. To do this, we
1577 * disable the receive line status interrupts, and tell the
1578 * interrupt driver to stop checking the data ready bit in the
1579 * line status register.
1581 if (tty_port_initialized(port
)) {
1582 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
1584 * Before we drop DTR, make sure the UART transmitter
1585 * has completely drained; this is especially
1586 * important if there is a transmit FIFO!
1588 timeout
= jiffies
+ HZ
;
1589 while (!(info
->lsr
& UART_LSR_TEMT
)) {
1590 schedule_timeout_interruptible(20);
1591 if (time_after(jiffies
, timeout
))
1596 isdn_tty_shutdown(info
);
1597 isdn_tty_flush_buffer(tty
);
1598 tty_ldisc_flush(tty
);
1602 tty_port_close_end(port
, tty
);
1604 #ifdef ISDN_DEBUG_MODEM_OPEN
1605 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
1610 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1613 isdn_tty_hangup(struct tty_struct
*tty
)
1615 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1616 struct tty_port
*port
= &info
->port
;
1618 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_hangup"))
1620 isdn_tty_shutdown(info
);
1622 tty_port_set_active(port
, 0);
1624 wake_up_interruptible(&port
->open_wait
);
1627 /* This routine initializes all emulator-data.
1630 isdn_tty_reset_profile(atemu
*m
)
1643 m
->profile
[11] = 70;
1644 m
->profile
[12] = 0x45;
1646 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
1647 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
1648 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
1649 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
1658 #ifdef CONFIG_ISDN_AUDIO
1660 isdn_tty_modem_reset_vpar(atemu
*m
)
1662 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
1663 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
1664 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
1665 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1666 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
1667 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1671 #ifdef CONFIG_ISDN_TTY_FAX
1673 isdn_tty_modem_reset_faxpar(modem_info
*info
)
1675 T30_s
*f
= info
->fax
;
1678 f
->phase
= ISDN_FAX_PHASE_IDLE
;
1680 f
->resolution
= 1; /* fine */
1681 f
->rate
= 5; /* 14400 bit/s */
1688 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
1689 f
->id
[FAXIDLEN
- 1] = 0;
1700 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
1701 f
->pollid
[FAXIDLEN
- 1] = 0;
1706 isdn_tty_modem_reset_regs(modem_info
*info
, int force
)
1708 atemu
*m
= &info
->emu
;
1709 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
1710 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
1711 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
1712 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
1713 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
1715 #ifdef CONFIG_ISDN_AUDIO
1716 isdn_tty_modem_reset_vpar(m
);
1718 #ifdef CONFIG_ISDN_TTY_FAX
1719 isdn_tty_modem_reset_faxpar(info
);
1725 modem_write_profile(atemu
*m
)
1727 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
1728 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
1729 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
1731 send_sig(SIGIO
, dev
->profd
, 1);
1734 static const struct tty_operations modem_ops
= {
1735 .install
= isdn_tty_install
,
1736 .open
= isdn_tty_open
,
1737 .close
= isdn_tty_close
,
1738 .write
= isdn_tty_write
,
1739 .flush_chars
= isdn_tty_flush_chars
,
1740 .write_room
= isdn_tty_write_room
,
1741 .chars_in_buffer
= isdn_tty_chars_in_buffer
,
1742 .flush_buffer
= isdn_tty_flush_buffer
,
1743 .ioctl
= isdn_tty_ioctl
,
1744 .throttle
= isdn_tty_throttle
,
1745 .unthrottle
= isdn_tty_unthrottle
,
1746 .set_termios
= isdn_tty_set_termios
,
1747 .hangup
= isdn_tty_hangup
,
1748 .tiocmget
= isdn_tty_tiocmget
,
1749 .tiocmset
= isdn_tty_tiocmset
,
1752 static int isdn_tty_carrier_raised(struct tty_port
*port
)
1754 modem_info
*info
= container_of(port
, modem_info
, port
);
1755 return info
->msr
& UART_MSR_DCD
;
1758 static const struct tty_port_operations isdn_tty_port_ops
= {
1759 .carrier_raised
= isdn_tty_carrier_raised
,
1763 isdn_tty_modem_init(void)
1770 m
->tty_modem
= alloc_tty_driver(ISDN_MAX_CHANNELS
);
1773 m
->tty_modem
->name
= "ttyI";
1774 m
->tty_modem
->major
= ISDN_TTY_MAJOR
;
1775 m
->tty_modem
->minor_start
= 0;
1776 m
->tty_modem
->type
= TTY_DRIVER_TYPE_SERIAL
;
1777 m
->tty_modem
->subtype
= SERIAL_TYPE_NORMAL
;
1778 m
->tty_modem
->init_termios
= tty_std_termios
;
1779 m
->tty_modem
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1780 m
->tty_modem
->flags
= TTY_DRIVER_REAL_RAW
;
1781 m
->tty_modem
->driver_name
= "isdn_tty";
1782 tty_set_operations(m
->tty_modem
, &modem_ops
);
1783 retval
= tty_register_driver(m
->tty_modem
);
1785 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
1788 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1790 #ifdef CONFIG_ISDN_TTY_FAX
1791 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
1792 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
1794 goto err_unregister
;
1797 tty_port_init(&info
->port
);
1798 info
->port
.ops
= &isdn_tty_port_ops
;
1799 spin_lock_init(&info
->readlock
);
1800 sprintf(info
->last_cause
, "0000");
1801 sprintf(info
->last_num
, "none");
1803 info
->last_lhup
= 1;
1806 isdn_tty_reset_profile(&info
->emu
);
1807 isdn_tty_modem_reset_regs(info
, 1);
1808 info
->magic
= ISDN_ASYNC_MAGIC
;
1811 info
->isdn_driver
= -1;
1812 info
->isdn_channel
= -1;
1813 info
->drv_index
= -1;
1814 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
1815 timer_setup(&info
->nc_timer
, isdn_tty_modem_do_ncarrier
, 0);
1816 skb_queue_head_init(&info
->xmit_queue
);
1817 #ifdef CONFIG_ISDN_AUDIO
1818 skb_queue_head_init(&info
->dtmf_queue
);
1820 info
->port
.xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5,
1822 if (!info
->port
.xmit_buf
) {
1823 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
1825 goto err_unregister
;
1827 /* Make room for T.70 header */
1828 info
->port
.xmit_buf
+= 4;
1832 for (i
--; i
>= 0; i
--) {
1834 #ifdef CONFIG_ISDN_TTY_FAX
1837 kfree(info
->port
.xmit_buf
- 4);
1838 info
->port
.xmit_buf
= NULL
;
1839 tty_port_destroy(&info
->port
);
1841 tty_unregister_driver(m
->tty_modem
);
1843 put_tty_driver(m
->tty_modem
);
1844 m
->tty_modem
= NULL
;
1854 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1855 info
= &dev
->mdm
.info
[i
];
1856 isdn_tty_cleanup_xmit(info
);
1857 #ifdef CONFIG_ISDN_TTY_FAX
1860 kfree(info
->port
.xmit_buf
- 4);
1861 info
->port
.xmit_buf
= NULL
;
1862 tty_port_destroy(&info
->port
);
1864 tty_unregister_driver(dev
->mdm
.tty_modem
);
1865 put_tty_driver(dev
->mdm
.tty_modem
);
1866 dev
->mdm
.tty_modem
= NULL
;
1871 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
1872 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
1873 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
1877 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
1879 #ifdef ISDN_DEBUG_MODEM_ICALL
1880 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
1881 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
1882 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
1884 if (strlen(emu
->lmsn
)) {
1885 char *p
= emu
->lmsn
;
1891 if ((q
= strchr(p
, ';')))
1893 if ((tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
1895 #ifdef ISDN_DEBUG_MODEM_ICALL
1896 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
1897 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
1912 tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
1913 #ifdef ISDN_DEBUG_MODEM_ICALL
1914 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
1915 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
1922 * An incoming call-request has arrived.
1923 * Search the tty-devices for an appropriate device and bind
1924 * it to the ISDN-Channel.
1927 * 0 = No matching device found.
1928 * 1 = A matching device found.
1929 * 3 = No match found, but eventually would match, if
1933 isdn_tty_find_icall(int di
, int ch
, setup_parm
*setup
)
1944 if (!setup
->phone
[0]) {
1946 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
1949 si1
= (int) setup
->si1
;
1950 si2
= (int) setup
->si2
;
1951 if (!setup
->eazmsn
[0]) {
1952 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
1955 eaz
= setup
->eazmsn
;
1956 #ifdef ISDN_DEBUG_MODEM_ICALL
1957 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
1960 spin_lock_irqsave(&dev
->lock
, flags
);
1961 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1962 modem_info
*info
= &dev
->mdm
.info
[i
];
1964 if (info
->port
.count
== 0)
1966 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
1967 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
1968 idx
= isdn_dc2minor(di
, ch
);
1969 #ifdef ISDN_DEBUG_MODEM_ICALL
1970 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
1971 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
1972 info
->port
.flags
, info
->isdn_driver
,
1973 info
->isdn_channel
, dev
->usage
[idx
]);
1976 #ifndef FIX_FILE_TRANSFER
1977 tty_port_active(&info
->port
) &&
1979 (info
->isdn_driver
== -1) &&
1980 (info
->isdn_channel
== -1) &&
1981 (USG_NONE(dev
->usage
[idx
]))) {
1984 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
1986 if (!matchret
) { /* EAZ is matching */
1987 info
->isdn_driver
= di
;
1988 info
->isdn_channel
= ch
;
1989 info
->drv_index
= idx
;
1990 dev
->m_idx
[idx
] = info
->line
;
1991 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
1992 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
1993 strcpy(dev
->num
[idx
], nr
);
1994 strcpy(info
->emu
.cpn
, eaz
);
1995 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
1996 info
->emu
.mdmreg
[REG_PLAN
] = setup
->plan
;
1997 info
->emu
.mdmreg
[REG_SCREEN
] = setup
->screen
;
1999 spin_unlock_irqrestore(&dev
->lock
, flags
);
2000 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2002 info
->msr
|= UART_MSR_RI
;
2003 isdn_tty_modem_result(RESULT_RING
, info
);
2004 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2010 spin_unlock_irqrestore(&dev
->lock
, flags
);
2011 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2012 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2)) ? "rejected" : "ignored");
2013 return (wret
== 2) ? 3 : 0;
2017 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2025 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2026 info
= &dev
->mdm
.info
[mi
];
2027 switch (c
->command
) {
2028 case ISDN_STAT_CINF
:
2029 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2030 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2031 if (e
== (char *)c
->parm
.num
)
2032 info
->emu
.charge
= 0;
2035 case ISDN_STAT_BSENT
:
2036 #ifdef ISDN_TTY_STAT_DEBUG
2037 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2039 if ((info
->isdn_driver
== c
->driver
) &&
2040 (info
->isdn_channel
== c
->arg
)) {
2041 info
->msr
|= UART_MSR_CTS
;
2042 if (info
->send_outstanding
)
2043 if (!(--info
->send_outstanding
))
2044 info
->lsr
|= UART_LSR_TEMT
;
2045 isdn_tty_tint(info
);
2049 case ISDN_STAT_CAUSE
:
2050 #ifdef ISDN_TTY_STAT_DEBUG
2051 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2053 /* Signal cause to tty-device */
2054 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2056 case ISDN_STAT_DISPLAY
:
2057 #ifdef ISDN_TTY_STAT_DEBUG
2058 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2060 /* Signal display to tty-device */
2061 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2062 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2063 isdn_tty_at_cout("\r\n", info
);
2064 isdn_tty_at_cout("DISPLAY: ", info
);
2065 isdn_tty_at_cout(c
->parm
.display
, info
);
2066 isdn_tty_at_cout("\r\n", info
);
2069 case ISDN_STAT_DCONN
:
2070 #ifdef ISDN_TTY_STAT_DEBUG
2071 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2073 if (tty_port_active(&info
->port
)) {
2074 if (info
->dialing
== 1) {
2080 case ISDN_STAT_DHUP
:
2081 #ifdef ISDN_TTY_STAT_DEBUG
2082 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2084 if (tty_port_active(&info
->port
)) {
2085 if (info
->dialing
== 1)
2086 isdn_tty_modem_result(RESULT_BUSY
, info
);
2087 if (info
->dialing
> 1)
2088 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2090 #ifdef ISDN_DEBUG_MODEM_HUP
2091 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2093 isdn_tty_modem_hup(info
, 0);
2097 case ISDN_STAT_BCONN
:
2098 #ifdef ISDN_TTY_STAT_DEBUG
2099 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2101 /* Wake up any processes waiting
2102 * for incoming call of this device when
2103 * DCD follow the state of incoming carrier
2105 if (info
->port
.blocked_open
&&
2106 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
)) {
2107 wake_up_interruptible(&info
->port
.open_wait
);
2110 /* Schedule CONNECT-Message to any tty
2111 * waiting for it and
2112 * set DCD-bit of its modem-status.
2114 if (tty_port_active(&info
->port
) ||
2115 (info
->port
.blocked_open
&&
2116 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
))) {
2117 info
->msr
|= UART_MSR_DCD
;
2118 info
->emu
.charge
= 0;
2119 if (info
->dialing
& 0xf)
2125 if (USG_MODEM(dev
->usage
[i
])) {
2126 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2127 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2128 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2130 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2132 if (USG_VOICE(dev
->usage
[i
]))
2133 isdn_tty_modem_result(RESULT_VCON
, info
);
2137 case ISDN_STAT_BHUP
:
2138 #ifdef ISDN_TTY_STAT_DEBUG
2139 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2141 if (tty_port_active(&info
->port
)) {
2142 #ifdef ISDN_DEBUG_MODEM_HUP
2143 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2145 isdn_tty_modem_hup(info
, 0);
2149 case ISDN_STAT_NODCH
:
2150 #ifdef ISDN_TTY_STAT_DEBUG
2151 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2153 if (tty_port_active(&info
->port
)) {
2154 if (info
->dialing
) {
2158 sprintf(info
->last_cause
, "0000");
2159 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2161 isdn_tty_modem_hup(info
, 0);
2165 case ISDN_STAT_UNLOAD
:
2166 #ifdef ISDN_TTY_STAT_DEBUG
2167 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2169 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2170 info
= &dev
->mdm
.info
[i
];
2171 if (info
->isdn_driver
== c
->driver
) {
2173 isdn_tty_modem_hup(info
, 1);
2177 #ifdef CONFIG_ISDN_TTY_FAX
2178 case ISDN_STAT_FAXIND
:
2179 if (tty_port_active(&info
->port
)) {
2180 isdn_tty_fax_command(info
, c
);
2184 #ifdef CONFIG_ISDN_AUDIO
2185 case ISDN_STAT_AUDIO
:
2186 if (tty_port_active(&info
->port
)) {
2187 switch (c
->parm
.num
[0]) {
2188 case ISDN_AUDIO_DTMF
:
2189 if (info
->vonline
) {
2190 isdn_audio_put_dle_code(info
,
2203 /*********************************************************************
2204 Modem-Emulator-Routines
2205 *********************************************************************/
2207 #define cmdchar(c) ((c >= ' ') && (c <= 0x7f))
2210 * Put a message from the AT-emulator into receive-buffer of tty,
2211 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2214 isdn_tty_at_cout(char *msg
, modem_info
*info
)
2216 struct tty_port
*port
= &info
->port
;
2217 atemu
*m
= &info
->emu
;
2221 struct sk_buff
*skb
= NULL
;
2226 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2232 spin_lock_irqsave(&info
->readlock
, flags
);
2233 if (info
->closing
) {
2234 spin_unlock_irqrestore(&info
->readlock
, flags
);
2238 /* use queue instead of direct, if online and */
2239 /* data is in queue or buffer is full */
2240 if (info
->online
&& ((tty_buffer_request_room(port
, l
) < l
) ||
2241 !skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
]))) {
2242 skb
= alloc_skb(l
, GFP_ATOMIC
);
2244 spin_unlock_irqrestore(&info
->readlock
, flags
);
2247 sp
= skb_put(skb
, l
);
2248 #ifdef CONFIG_ISDN_AUDIO
2249 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2250 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2254 for (p
= msg
; *p
; p
++) {
2257 c
= m
->mdmreg
[REG_CR
];
2260 c
= m
->mdmreg
[REG_LF
];
2263 c
= m
->mdmreg
[REG_BS
];
2271 if (tty_insert_flip_char(port
, c
, TTY_NORMAL
) == 0)
2276 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2277 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2278 spin_unlock_irqrestore(&info
->readlock
, flags
);
2279 /* Schedule dequeuing */
2280 if (dev
->modempoll
&& info
->rcvsched
)
2281 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2284 spin_unlock_irqrestore(&info
->readlock
, flags
);
2285 tty_flip_buffer_push(port
);
2290 * Perform ATH Hangup
2293 isdn_tty_on_hook(modem_info
*info
)
2295 if (info
->isdn_channel
>= 0) {
2296 #ifdef ISDN_DEBUG_MODEM_HUP
2297 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2299 isdn_tty_modem_hup(info
, 1);
2304 isdn_tty_off_hook(void)
2306 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2309 #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */
2310 #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */
2313 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2314 * isdn_tty_modem_escape() if sequence found.
2317 * p pointer to databuffer
2318 * plus escape-character
2319 * count length of buffer
2320 * pluscount count of valid escape-characters so far
2321 * lastplus timestamp of last character
2324 isdn_tty_check_esc(const u_char
*p
, u_char plus
, int count
, int *pluscount
,
2335 if (*(p
++) == plus
) {
2336 if ((*pluscount
)++) {
2337 /* Time since last '+' > 0.5 sec. ? */
2338 if (time_after(jiffies
, *lastplus
+ PLUSWAIT1
))
2341 /* Time since last non-'+' < 1.5 sec. ? */
2342 if (time_before(jiffies
, *lastplus
+ PLUSWAIT2
))
2345 if ((*pluscount
== 3) && (count
== 1))
2346 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2351 *lastplus
= jiffies
;
2357 * Return result of AT-emulator to tty-receive-buffer, depending on
2358 * modem-register 12, bit 0 and 1.
2359 * For CONNECT-messages also switch to online-mode.
2360 * For RING-message handle auto-ATA if register 0 != 0
2364 isdn_tty_modem_result(int code
, modem_info
*info
)
2366 atemu
*m
= &info
->emu
;
2367 static char *msg
[] =
2368 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2369 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2370 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2371 char s
[ISDN_MSNLEN
+ 10];
2375 m
->mdmreg
[REG_RINGCNT
]++;
2376 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2377 /* Automatically accept incoming call */
2378 isdn_tty_cmd_ATA(info
);
2380 case RESULT_NO_CARRIER
:
2381 #ifdef ISDN_DEBUG_MODEM_HUP
2382 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2383 info
->closing
, !info
->port
.tty
);
2385 m
->mdmreg
[REG_RINGCNT
] = 0;
2386 del_timer(&info
->nc_timer
);
2388 if (info
->closing
|| !info
->port
.tty
)
2391 #ifdef CONFIG_ISDN_AUDIO
2392 if (info
->vonline
& 1) {
2393 #ifdef ISDN_DEBUG_MODEM_VOICE
2394 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
2397 /* voice-recording, add DLE-ETX */
2398 isdn_tty_at_cout("\020\003", info
);
2400 if (info
->vonline
& 2) {
2401 #ifdef ISDN_DEBUG_MODEM_VOICE
2402 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
2405 /* voice-playing, add DLE-DC4 */
2406 isdn_tty_at_cout("\020\024", info
);
2410 case RESULT_CONNECT
:
2411 case RESULT_CONNECT64000
:
2412 sprintf(info
->last_cause
, "0000");
2417 #ifdef ISDN_DEBUG_MODEM_VOICE
2418 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
2421 sprintf(info
->last_cause
, "0000");
2425 } /* switch (code) */
2427 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
2429 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
2430 /* Show numeric results only */
2431 sprintf(s
, "\r\n%d\r\n", code
);
2432 isdn_tty_at_cout(s
, info
);
2434 if (code
== RESULT_RING
) {
2435 /* return if "show RUNG" and ringcounter>1 */
2436 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
2437 (m
->mdmreg
[REG_RINGCNT
] > 1))
2439 /* print CID, _before_ _every_ ring */
2440 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
2441 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
2442 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2443 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2444 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2445 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2449 isdn_tty_at_cout("\r\n", info
);
2450 isdn_tty_at_cout(msg
[code
], info
);
2452 case RESULT_CONNECT
:
2453 switch (m
->mdmreg
[REG_L2PROT
]) {
2454 case ISDN_PROTO_L2_MODEM
:
2455 isdn_tty_at_cout(" ", info
);
2456 isdn_tty_at_cout(m
->connmsg
, info
);
2461 /* Append CPN, if enabled */
2462 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
2463 sprintf(s
, "/%s", m
->cpn
);
2464 isdn_tty_at_cout(s
, info
);
2466 /* Print CID only once, _after_ 1st RING */
2467 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
2468 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
2469 isdn_tty_at_cout("\r\n", info
);
2470 isdn_tty_at_cout("CALLER NUMBER: ", info
);
2471 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2472 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2473 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2474 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2478 case RESULT_NO_CARRIER
:
2479 case RESULT_NO_DIALTONE
:
2481 case RESULT_NO_ANSWER
:
2482 m
->mdmreg
[REG_RINGCNT
] = 0;
2483 /* Append Cause-Message if enabled */
2484 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
2485 sprintf(s
, "/%s", info
->last_cause
);
2486 isdn_tty_at_cout(s
, info
);
2489 case RESULT_CONNECT64000
:
2490 /* Append Protocol to CONNECT message */
2491 switch (m
->mdmreg
[REG_L2PROT
]) {
2492 case ISDN_PROTO_L2_X75I
:
2493 case ISDN_PROTO_L2_X75UI
:
2494 case ISDN_PROTO_L2_X75BUI
:
2495 isdn_tty_at_cout("/X.75", info
);
2497 case ISDN_PROTO_L2_HDLC
:
2498 isdn_tty_at_cout("/HDLC", info
);
2500 case ISDN_PROTO_L2_V11096
:
2501 isdn_tty_at_cout("/V110/9600", info
);
2503 case ISDN_PROTO_L2_V11019
:
2504 isdn_tty_at_cout("/V110/19200", info
);
2506 case ISDN_PROTO_L2_V11038
:
2507 isdn_tty_at_cout("/V110/38400", info
);
2510 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2511 isdn_tty_at_cout("/T.70", info
);
2512 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2513 isdn_tty_at_cout("+", info
);
2517 isdn_tty_at_cout("\r\n", info
);
2520 if (code
== RESULT_NO_CARRIER
) {
2521 if (info
->closing
|| (!info
->port
.tty
))
2524 if (tty_port_check_carrier(&info
->port
))
2525 tty_hangup(info
->port
.tty
);
2531 * Display a modem-register-value.
2534 isdn_tty_show_profile(int ridx
, modem_info
*info
)
2538 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
2539 isdn_tty_at_cout(v
, info
);
2543 * Get MSN-string from char-pointer, set pointer to end of number
2546 isdn_tty_get_msnstr(char *n
, char **p
)
2548 int limit
= ISDN_MSNLEN
- 1;
2550 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
2551 /* Why a comma ??? */
2552 (*p
[0] == ',') || (*p
[0] == ':')) &&
2559 * Get phone-number from modem-commandbuffer
2562 isdn_tty_getdial(char *p
, char *q
, int cnt
)
2565 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
2568 while (strchr(" 0123456789,#.*WPTSR-", *p
) && *p
&& --cnt
> 0) {
2569 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
2570 ((*p
== 'R') && first
) ||
2571 (*p
== '*') || (*p
== '#')) {
2583 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2584 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2587 isdn_tty_report(modem_info
*info
)
2589 atemu
*m
= &info
->emu
;
2592 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
2593 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
2594 isdn_tty_at_cout(s
, info
);
2595 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
2596 isdn_tty_at_cout(s
, info
);
2597 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
2598 switch (info
->last_l2
) {
2599 case ISDN_PROTO_L2_X75I
:
2600 isdn_tty_at_cout("X.75i", info
);
2602 case ISDN_PROTO_L2_X75UI
:
2603 isdn_tty_at_cout("X.75ui", info
);
2605 case ISDN_PROTO_L2_X75BUI
:
2606 isdn_tty_at_cout("X.75bui", info
);
2608 case ISDN_PROTO_L2_HDLC
:
2609 isdn_tty_at_cout("HDLC", info
);
2611 case ISDN_PROTO_L2_V11096
:
2612 isdn_tty_at_cout("V.110 9600 Baud", info
);
2614 case ISDN_PROTO_L2_V11019
:
2615 isdn_tty_at_cout("V.110 19200 Baud", info
);
2617 case ISDN_PROTO_L2_V11038
:
2618 isdn_tty_at_cout("V.110 38400 Baud", info
);
2620 case ISDN_PROTO_L2_TRANS
:
2621 isdn_tty_at_cout("transparent", info
);
2623 case ISDN_PROTO_L2_MODEM
:
2624 isdn_tty_at_cout("modem", info
);
2626 case ISDN_PROTO_L2_FAX
:
2627 isdn_tty_at_cout("fax", info
);
2630 isdn_tty_at_cout("unknown", info
);
2633 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2634 isdn_tty_at_cout("/T.70", info
);
2635 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2636 isdn_tty_at_cout("+", info
);
2638 isdn_tty_at_cout("\r\n", info
);
2639 isdn_tty_at_cout(" Service: ", info
);
2640 switch (info
->last_si
) {
2642 isdn_tty_at_cout("audio\r\n", info
);
2645 isdn_tty_at_cout("btx\r\n", info
);
2648 isdn_tty_at_cout("data\r\n", info
);
2651 sprintf(s
, "%d\r\n", info
->last_si
);
2652 isdn_tty_at_cout(s
, info
);
2655 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
2656 isdn_tty_at_cout(s
, info
);
2657 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
2658 isdn_tty_at_cout(s
, info
);
2662 * Parse AT&.. commands.
2665 isdn_tty_cmd_ATand(char **p
, modem_info
*info
)
2667 atemu
*m
= &info
->emu
;
2671 #define MAXRB (sizeof(rb) - 1)
2675 /* &B - Set Buffersize */
2678 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
2680 #ifdef CONFIG_ISDN_AUDIO
2681 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
2684 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
2685 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2686 switch (m
->mdmreg
[REG_L2PROT
]) {
2687 case ISDN_PROTO_L2_V11096
:
2688 case ISDN_PROTO_L2_V11019
:
2689 case ISDN_PROTO_L2_V11038
:
2690 info
->xmit_size
/= 10;
2694 /* &C - DCD Status */
2696 switch (isdn_getnum(p
)) {
2698 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
2701 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
2708 /* &D - Set DTR-Low-behavior */
2710 switch (isdn_getnum(p
)) {
2712 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
2713 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2716 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2717 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2720 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2721 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
2728 /* &E -Set EAZ/MSN */
2730 isdn_tty_get_msnstr(m
->msn
, p
);
2733 /* &F -Set Factory-Defaults */
2735 if (info
->msr
& UART_MSR_DCD
)
2737 isdn_tty_reset_profile(m
);
2738 isdn_tty_modem_reset_regs(info
, 1);
2740 #ifdef DUMMY_HAYES_AT
2742 /* only for be compilant with common scripts */
2743 /* &K Flowcontrol - no function */
2749 /* &L -Set Numbers to listen on */
2752 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
2753 (i
< ISDN_LMSNLEN
- 1))
2754 m
->lmsn
[i
++] = *p
[0]++;
2758 /* &R - Set V.110 bitrate adaption */
2763 /* Switch off V.110, back to X.75 */
2764 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2765 m
->mdmreg
[REG_SI2
] = 0;
2766 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2769 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
2770 m
->mdmreg
[REG_SI2
] = 197;
2771 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2774 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
2775 m
->mdmreg
[REG_SI2
] = 199;
2776 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2779 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
2780 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
2781 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2786 /* Switch off T.70 */
2787 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2789 m
->mdmreg
[REG_SI1
] |= 4;
2792 /* &S - Set Windowsize */
2795 if ((i
> 0) && (i
< 9))
2796 m
->mdmreg
[REG_WSIZE
] = i
;
2801 /* &V - Show registers */
2803 isdn_tty_at_cout("\r\n", info
);
2804 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
2805 sprintf(rb
, "S%02d=%03d%s", i
,
2806 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
2807 isdn_tty_at_cout(rb
, info
);
2809 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
2810 strlen(m
->msn
) ? m
->msn
: "None");
2811 isdn_tty_at_cout(rb
, info
);
2812 if (strlen(m
->lmsn
)) {
2813 isdn_tty_at_cout("\r\nListen: ", info
);
2814 isdn_tty_at_cout(m
->lmsn
, info
);
2815 isdn_tty_at_cout("\r\n", info
);
2819 /* &W - Write Profile */
2824 modem_write_profile(m
);
2831 /* &X - Switch to BTX-Mode and T.70 */
2833 switch (isdn_getnum(p
)) {
2835 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2836 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2839 m
->mdmreg
[REG_T70
] |= BIT_T70
;
2840 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
2841 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2842 info
->xmit_size
= 112;
2843 m
->mdmreg
[REG_SI1
] = 4;
2844 m
->mdmreg
[REG_SI2
] = 0;
2847 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
2848 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2849 info
->xmit_size
= 112;
2850 m
->mdmreg
[REG_SI1
] = 4;
2851 m
->mdmreg
[REG_SI2
] = 0;
2864 isdn_tty_check_ats(int mreg
, int mval
, modem_info
*info
, atemu
*m
)
2866 /* Some plausibility checks */
2869 if (mval
> ISDN_PROTO_L2_MAX
)
2873 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
2875 #ifdef CONFIG_ISDN_AUDIO
2876 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
2879 info
->xmit_size
= mval
* 16;
2880 switch (m
->mdmreg
[REG_L2PROT
]) {
2881 case ISDN_PROTO_L2_V11096
:
2882 case ISDN_PROTO_L2_V11019
:
2883 case ISDN_PROTO_L2_V11038
:
2884 info
->xmit_size
/= 10;
2890 /* readonly registers */
2897 * Perform ATS command
2900 isdn_tty_cmd_ATS(char **p
, modem_info
*info
)
2902 atemu
*m
= &info
->emu
;
2908 mreg
= isdn_getnum(p
);
2909 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
2914 mval
= isdn_getnum(p
);
2915 if (mval
< 0 || mval
> 255)
2917 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
2919 m
->mdmreg
[mreg
] = mval
;
2922 /* Set/Clear a single bit */
2924 bitpos
= isdn_getnum(p
);
2925 if ((bitpos
< 0) || (bitpos
> 7))
2930 bval
= isdn_getnum(p
);
2931 if (bval
< 0 || bval
> 1)
2934 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
2936 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
2937 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
2939 m
->mdmreg
[mreg
] = mval
;
2943 isdn_tty_at_cout("\r\n", info
);
2944 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
2953 isdn_tty_show_profile(mreg
, info
);
2963 * Perform ATA command
2966 isdn_tty_cmd_ATA(modem_info
*info
)
2968 atemu
*m
= &info
->emu
;
2972 if (info
->msr
& UART_MSR_RI
) {
2973 /* Accept incoming call */
2975 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
2976 m
->mdmreg
[REG_RINGCNT
] = 0;
2977 info
->msr
&= ~UART_MSR_RI
;
2978 l2
= m
->mdmreg
[REG_L2PROT
];
2979 #ifdef CONFIG_ISDN_AUDIO
2980 /* If more than one bit set in reg18, autoselect Layer2 */
2981 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
2982 if (m
->mdmreg
[REG_SI1I
] == 1) {
2983 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
2984 l2
= ISDN_PROTO_L2_TRANS
;
2986 l2
= ISDN_PROTO_L2_X75I
;
2989 cmd
.driver
= info
->isdn_driver
;
2990 cmd
.command
= ISDN_CMD_SETL2
;
2991 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
2994 cmd
.driver
= info
->isdn_driver
;
2995 cmd
.command
= ISDN_CMD_SETL3
;
2996 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
2997 #ifdef CONFIG_ISDN_TTY_FAX
2998 if (l2
== ISDN_PROTO_L2_FAX
) {
2999 cmd
.parm
.fax
= info
->fax
;
3000 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3004 cmd
.driver
= info
->isdn_driver
;
3005 cmd
.arg
= info
->isdn_channel
;
3006 cmd
.command
= ISDN_CMD_ACCEPTD
;
3008 info
->emu
.carrierwait
= 0;
3010 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3012 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3015 #ifdef CONFIG_ISDN_AUDIO
3017 * Parse AT+F.. commands
3020 isdn_tty_cmd_PLUSF(char **p
, modem_info
*info
)
3022 atemu
*m
= &info
->emu
;
3025 if (!strncmp(p
[0], "CLASS", 5)) {
3030 sprintf(rs
, "\r\n%d",
3031 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3032 #ifdef CONFIG_ISDN_TTY_FAX
3033 if (TTY_IS_FCLASS2(info
))
3034 sprintf(rs
, "\r\n2");
3035 else if (TTY_IS_FCLASS1(info
))
3036 sprintf(rs
, "\r\n1");
3038 isdn_tty_at_cout(rs
, info
);
3045 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3046 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3047 m
->mdmreg
[REG_SI1
] = 4;
3049 m
->mdmreg
[REG_PSIZE
] * 16;
3051 #ifdef CONFIG_ISDN_TTY_FAX
3054 if (!(dev
->global_features
&
3055 ISDN_FEATURE_L3_FCLASS1
))
3057 m
->mdmreg
[REG_SI1
] = 1;
3058 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3059 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3061 m
->mdmreg
[REG_PSIZE
] * 16;
3065 if (!(dev
->global_features
&
3066 ISDN_FEATURE_L3_FCLASS2
))
3068 m
->mdmreg
[REG_SI1
] = 1;
3069 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3070 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3072 m
->mdmreg
[REG_PSIZE
] * 16;
3077 /* L2 will change on dialout with si=1 */
3078 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3079 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3080 m
->mdmreg
[REG_SI1
] = 5;
3081 info
->xmit_size
= VBUF
;
3085 strcpy(rs
, "\r\n0,");
3086 #ifdef CONFIG_ISDN_TTY_FAX
3087 if (dev
->global_features
&
3088 ISDN_FEATURE_L3_FCLASS1
)
3090 if (dev
->global_features
&
3091 ISDN_FEATURE_L3_FCLASS2
)
3095 isdn_tty_at_cout(rs
, info
);
3106 #ifdef CONFIG_ISDN_TTY_FAX
3107 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3114 * Parse AT+V.. commands
3117 isdn_tty_cmd_PLUSV(char **p
, modem_info
*info
)
3119 atemu
*m
= &info
->emu
;
3121 static char *vcmd
[] =
3122 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3130 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3138 /* AT+VNH - Auto hangup feature */
3142 isdn_tty_at_cout("\r\n1", info
);
3152 isdn_tty_at_cout("\r\n1", info
);
3163 /* AT+VIP - Reset all voice parameters */
3164 isdn_tty_modem_reset_vpar(m
);
3167 /* AT+VLS - Select device, accept incoming call */
3171 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3172 isdn_tty_at_cout(rs
, info
);
3187 isdn_tty_at_cout("\r\n0,2", info
);
3198 /* AT+VRX - Start recording */
3201 if (info
->online
!= 1) {
3202 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3205 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3206 if (!info
->dtmf_state
) {
3207 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3210 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3211 if (!info
->silence_state
) {
3212 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3215 if (m
->vpar
[3] < 5) {
3216 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3217 if (!info
->adpcmr
) {
3218 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3222 #ifdef ISDN_DEBUG_AT
3223 printk(KERN_DEBUG
"AT: +VRX\n");
3226 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3230 /* AT+VSD - Silence detection */
3234 sprintf(rs
, "\r\n<%d>,<%d>",
3237 isdn_tty_at_cout(rs
, info
);
3241 if ((*p
[0] >= '0') && (*p
[0] <= '9')) {
3242 par1
= isdn_getnum(p
);
3243 if ((par1
< 0) || (par1
> 31))
3248 par2
= isdn_getnum(p
);
3249 if ((par2
< 0) || (par2
> 255))
3257 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3268 /* AT+VSM - Select compression */
3272 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3275 isdn_tty_at_cout(rs
, info
);
3285 par1
= isdn_getnum(p
);
3286 if ((par1
< 2) || (par1
> 6))
3292 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3294 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3296 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3298 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3300 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3312 /* AT+VTX - Start sending */
3315 if (info
->online
!= 1) {
3316 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3319 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3320 if (!info
->dtmf_state
) {
3321 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3324 if (m
->vpar
[3] < 5) {
3325 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3326 if (!info
->adpcms
) {
3327 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3331 #ifdef ISDN_DEBUG_AT
3332 printk(KERN_DEBUG
"AT: +VTX\n");
3336 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3340 /* AT+VDD - DTMF detection */
3344 sprintf(rs
, "\r\n<%d>,<%d>",
3347 isdn_tty_at_cout(rs
, info
);
3351 if ((*p
[0] >= '0') && (*p
[0] <= '9')) {
3352 if (info
->online
!= 1)
3354 par1
= isdn_getnum(p
);
3355 if ((par1
< 0) || (par1
> 15))
3360 par2
= isdn_getnum(p
);
3361 if ((par2
< 0) || (par2
> 255))
3365 cmd
.driver
= info
->isdn_driver
;
3366 cmd
.command
= ISDN_CMD_AUDIO
;
3367 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3368 cmd
.parm
.num
[0] = par1
;
3369 cmd
.parm
.num
[1] = par2
;
3375 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3390 #endif /* CONFIG_ISDN_AUDIO */
3393 * Parse and perform an AT-command-line.
3396 isdn_tty_parse_at(modem_info
*info
)
3398 atemu
*m
= &info
->emu
;
3400 char ds
[ISDN_MSNLEN
];
3402 #ifdef ISDN_DEBUG_AT
3403 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
3405 for (p
= &m
->mdmcmd
[2]; *p
;) {
3411 /* A - Accept incoming call */
3413 isdn_tty_cmd_ATA(info
);
3417 if (info
->msr
& UART_MSR_DCD
)
3419 if (info
->msr
& UART_MSR_RI
) {
3420 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3423 isdn_tty_getdial(++p
, ds
, sizeof ds
);
3425 if (!strlen(m
->msn
))
3426 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
3427 else if (strlen(ds
))
3428 isdn_tty_dial(ds
, info
, m
);
3433 /* E - Turn Echo on/off */
3435 switch (isdn_getnum(&p
)) {
3437 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
3440 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
3447 /* H - On/Off-hook */
3452 isdn_tty_on_hook(info
);
3456 isdn_tty_off_hook();
3459 isdn_tty_on_hook(info
);
3464 /* I - Information */
3466 isdn_tty_at_cout("\r\nLinux ISDN", info
);
3474 isdn_tty_report(info
);
3478 snprintf(ds
, sizeof(ds
), "\r\n%d", info
->emu
.charge
);
3479 isdn_tty_at_cout(ds
, info
);
3484 #ifdef DUMMY_HAYES_AT
3487 /* only for be compilant with common scripts */
3496 if (info
->msr
& UART_MSR_DCD
)
3497 /* if B-Channel is up */
3498 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
: RESULT_CONNECT64000
, info
);
3500 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3503 /* Q - Turn Emulator messages on/off */
3505 switch (isdn_getnum(&p
)) {
3507 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
3510 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
3517 /* S - Set/Get Register */
3519 if (isdn_tty_cmd_ATS(&p
, info
))
3523 /* V - Numeric or ASCII Emulator-messages */
3525 switch (isdn_getnum(&p
)) {
3527 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
3530 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
3537 /* Z - Load Registers from Profile */
3539 if (info
->msr
& UART_MSR_DCD
) {
3541 isdn_tty_on_hook(info
);
3543 isdn_tty_modem_reset_regs(info
, 1);
3548 #ifdef CONFIG_ISDN_AUDIO
3551 if (isdn_tty_cmd_PLUSF(&p
, info
))
3555 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
3556 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
3559 if (isdn_tty_cmd_PLUSV(&p
, info
))
3562 #endif /* CONFIG_ISDN_AUDIO */
3563 case 'S': /* SUSPEND */
3565 isdn_tty_get_msnstr(ds
, &p
);
3566 isdn_tty_suspend(ds
, info
, m
);
3568 case 'R': /* RESUME */
3570 isdn_tty_get_msnstr(ds
, &p
);
3571 isdn_tty_resume(ds
, info
, m
);
3573 case 'M': /* MESSAGE */
3575 isdn_tty_send_msg(info
, m
, p
);
3583 if (isdn_tty_cmd_ATand(&p
, info
))
3590 #ifdef CONFIG_ISDN_AUDIO
3593 isdn_tty_modem_result(RESULT_OK
, info
);
3596 /* Need own toupper() because standard-toupper is not available
3599 #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c)
3602 * Perform line-editing of AT-commands
3606 * count length of buffer
3607 * channel index to line (minor-device)
3610 isdn_tty_edit_at(const char *p
, int count
, modem_info
*info
)
3612 atemu
*m
= &info
->emu
;
3618 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
3621 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
3622 /* Separator (CR or LF) */
3623 m
->mdmcmd
[m
->mdmcmdl
] = 0;
3624 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3627 isdn_tty_at_cout(eb
, info
);
3629 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
3630 isdn_tty_parse_at(info
);
3634 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
3635 /* Backspace-Function */
3636 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
3639 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
3640 isdn_tty_at_cout("\b", info
);
3645 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3648 isdn_tty_at_cout(eb
, info
);
3650 if (m
->mdmcmdl
< 255) {
3652 switch (m
->mdmcmdl
) {
3655 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3656 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3660 /* Fall through, check for 'A' */
3663 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3664 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3668 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3669 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3678 * Switch all modem-channels who are online and got a valid
3679 * escape-sequence 1.5 seconds ago, to command-mode.
3680 * This function is called every second via timer-interrupt from within
3681 * timer-dispatcher isdn_timer_function()
3684 isdn_tty_modem_escape(void)
3690 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
3691 if (USG_MODEM(dev
->usage
[i
]) && (midx
= dev
->m_idx
[i
]) >= 0) {
3692 modem_info
*info
= &dev
->mdm
.info
[midx
];
3695 if ((info
->emu
.pluscount
== 3) &&
3697 info
->emu
.lastplus
+ PLUSWAIT2
)) {
3698 info
->emu
.pluscount
= 0;
3700 isdn_tty_modem_result(RESULT_OK
, info
);
3704 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
3708 * Put a RING-message to all modem-channels who have the RI-bit set.
3709 * This function is called every second via timer-interrupt from within
3710 * timer-dispatcher isdn_timer_function()
3713 isdn_tty_modem_ring(void)
3718 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3719 modem_info
*info
= &dev
->mdm
.info
[i
];
3720 if (info
->msr
& UART_MSR_RI
) {
3722 isdn_tty_modem_result(RESULT_RING
, info
);
3725 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
3729 * For all online tty's, try sending data to
3733 isdn_tty_modem_xmit(void)
3738 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3739 modem_info
*info
= &dev
->mdm
.info
[i
];
3742 isdn_tty_senddown(info
);
3743 isdn_tty_tint(info
);
3746 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
3750 * Check all channels if we have a 'no carrier' timeout.
3751 * Timeout value is set by Register S7.
3754 isdn_tty_carrier_timeout(void)
3759 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3760 modem_info
*info
= &dev
->mdm
.info
[i
];
3763 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
3765 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3766 isdn_tty_modem_hup(info
, 1);
3770 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);