2 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
4 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
5 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
11 #undef ISDN_TTY_STAT_DEBUG
13 #include <linux/isdn.h>
14 #include <linux/serial.h> /* ASYNC_* flags */
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/mutex.h>
18 #include "isdn_common.h"
20 #ifdef CONFIG_ISDN_AUDIO
21 #include "isdn_audio.h"
23 #define VBUFX (VBUF/16)
26 #define FIX_FILE_TRANSFER
27 #define DUMMY_HAYES_AT
31 static DEFINE_MUTEX(modem_info_mutex
);
32 static int isdn_tty_edit_at(const char *, int, modem_info
*);
33 static void isdn_tty_check_esc(const u_char
*, u_char
, int, int *, u_long
*);
34 static void isdn_tty_modem_reset_regs(modem_info
*, int);
35 static void isdn_tty_cmd_ATA(modem_info
*);
36 static void isdn_tty_flush_buffer(struct tty_struct
*);
37 static void isdn_tty_modem_result(int, modem_info
*);
38 #ifdef CONFIG_ISDN_AUDIO
39 static int isdn_tty_countDLE(unsigned char *, int);
42 /* Leave this unchanged unless you know what you do! */
43 #define MODEM_PARANOIA_CHECK
44 #define MODEM_DO_RESTART
46 static int bit2si
[8] =
47 {1, 5, 7, 7, 7, 7, 7, 7};
48 static int si2bit
[8] =
49 {4, 1, 4, 4, 4, 4, 4, 4};
51 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
52 * to stuff incoming data directly into a tty's flip-buffer. This
53 * is done to speed up tty-receiving if the receive-queue is empty.
54 * This routine MUST be called with interrupts off.
57 * 0 = Failure, data has to be buffered and later processed by
58 * isdn_tty_readmodem().
61 isdn_tty_try_read(modem_info
*info
, struct sk_buff
*skb
)
63 struct tty_port
*port
= &info
->port
;
71 if (!(info
->mcr
& UART_MCR_RTS
))
75 #ifdef CONFIG_ISDN_AUDIO
76 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
80 c
= tty_buffer_request_room(port
, len
);
84 #ifdef CONFIG_ISDN_AUDIO
85 if (ISDN_AUDIO_SKB_DLECOUNT(skb
)) {
87 unsigned char *dp
= skb
->data
;
90 tty_insert_flip_char(port
, DLE
, 0);
91 tty_insert_flip_char(port
, *dp
++, 0);
94 tty_insert_flip_char(port
, DLE
, 0);
99 tty_insert_flip_string(port
, skb
->data
, len
- 1);
100 last
= skb
->data
[len
- 1];
101 #ifdef CONFIG_ISDN_AUDIO
104 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
105 tty_insert_flip_char(port
, last
, 0xFF);
107 tty_insert_flip_char(port
, last
, TTY_NORMAL
);
108 tty_flip_buffer_push(port
);
114 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
115 * It tries getting received data from the receive queue an stuff it into
116 * the tty's flip-buffer.
119 isdn_tty_readmodem(void)
127 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
128 midx
= dev
->m_idx
[i
];
132 info
= &dev
->mdm
.info
[midx
];
137 #ifdef CONFIG_ISDN_AUDIO
138 isdn_audio_eval_dtmf(info
);
139 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
140 isdn_audio_eval_silence(info
);
142 if (info
->mcr
& UART_MCR_RTS
) {
143 /* CISCO AsyncPPP Hack */
144 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
145 r
= isdn_readbchan_tty(info
->isdn_driver
,
149 r
= isdn_readbchan_tty(info
->isdn_driver
,
153 tty_flip_buffer_push(&info
->port
);
164 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
168 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
172 #ifdef CONFIG_ISDN_AUDIO
177 if ((midx
= dev
->m_idx
[i
]) < 0) {
178 /* if midx is invalid, packet is not for tty */
181 info
= &dev
->mdm
.info
[midx
];
182 #ifdef CONFIG_ISDN_AUDIO
185 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
186 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
187 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
188 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
190 if ((info
->online
< 2)
191 #ifdef CONFIG_ISDN_AUDIO
192 && (!(info
->vonline
& 1))
195 /* If Modem not listening, drop data */
199 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
200 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
201 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
202 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
205 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
208 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
209 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
212 #ifdef CONFIG_ISDN_AUDIO
213 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
214 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
215 if (info
->vonline
& 1) {
216 /* voice conversion/compression */
217 switch (info
->emu
.vpar
[3]) {
222 * Since compressed data takes less
223 * space, we can overwrite the buffer.
225 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
234 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
239 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
242 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
243 isdn_tty_countDLE(skb
->data
, skb
->len
);
245 #ifdef CONFIG_ISDN_TTY_FAX
247 if (info
->faxonline
& 2) {
248 isdn_tty_fax_bitorder(info
, skb
);
249 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
250 isdn_tty_countDLE(skb
->data
, skb
->len
);
255 /* Try to deliver directly via tty-buf if queue is empty */
256 spin_lock_irqsave(&info
->readlock
, flags
);
257 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
258 if (isdn_tty_try_read(info
, skb
)) {
259 spin_unlock_irqrestore(&info
->readlock
, flags
);
262 /* Direct deliver failed or queue wasn't empty.
263 * Queue up for later dequeueing via timer-irq.
265 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
266 dev
->drv
[di
]->rcvcount
[channel
] +=
268 #ifdef CONFIG_ISDN_AUDIO
269 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
272 spin_unlock_irqrestore(&info
->readlock
, flags
);
273 /* Schedule dequeuing */
274 if ((dev
->modempoll
) && (info
->rcvsched
))
275 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
280 isdn_tty_cleanup_xmit(modem_info
*info
)
282 skb_queue_purge(&info
->xmit_queue
);
283 #ifdef CONFIG_ISDN_AUDIO
284 skb_queue_purge(&info
->dtmf_queue
);
289 isdn_tty_tint(modem_info
*info
)
291 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
297 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
298 info
->isdn_channel
, 1, skb
)) == len
) {
299 struct tty_struct
*tty
= info
->port
.tty
;
300 info
->send_outstanding
++;
301 info
->msr
&= ~UART_MSR_CTS
;
302 info
->lsr
&= ~UART_LSR_TEMT
;
307 /* Error: no channel, already shutdown, or wrong parameter */
311 skb_queue_head(&info
->xmit_queue
, skb
);
314 #ifdef CONFIG_ISDN_AUDIO
316 isdn_tty_countDLE(unsigned char *buf
, int len
)
326 /* This routine is called from within isdn_tty_write() to perform
327 * DLE-decoding when sending audio-data.
330 isdn_tty_handleDLEdown(modem_info
*info
, atemu
*m
, int len
)
332 unsigned char *p
= &info
->port
.xmit_buf
[info
->xmit_count
];
342 memmove(p
, p
+ 1, len
- 1);
353 #ifdef ISDN_DEBUG_MODEM_VOICE
355 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
358 isdn_tty_at_cout("\020\003", info
);
359 if (!info
->vonline
) {
360 #ifdef ISDN_DEBUG_MODEM_VOICE
362 "DLEdown: send VCON on ttyI%d\n",
365 isdn_tty_at_cout("\r\nVCON\r\n", info
);
372 memmove(p
, p
+ 1, len
- 1);
386 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
392 /* This routine is called from within isdn_tty_write() when receiving
393 * audio-data. It interrupts receiving, if an character other than
397 isdn_tty_end_vrx(const char *buf
, int c
)
403 if ((ch
!= 0x11) && (ch
!= 0x13))
410 static int voice_cf
[7] =
411 {0, 0, 4, 3, 2, 0, 0};
413 #endif /* CONFIG_ISDN_AUDIO */
415 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
416 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
417 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
418 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
421 isdn_tty_senddown(modem_info
*info
)
425 #ifdef CONFIG_ISDN_AUDIO
430 #ifdef CONFIG_ISDN_AUDIO
431 if (info
->vonline
& 4) {
433 if (!info
->vonline
) {
434 #ifdef ISDN_DEBUG_MODEM_VOICE
436 "senddown: send VCON on ttyI%d\n",
439 isdn_tty_at_cout("\r\nVCON\r\n", info
);
443 if (!(buflen
= info
->xmit_count
))
445 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
446 info
->msr
&= ~UART_MSR_CTS
;
447 info
->lsr
&= ~UART_LSR_TEMT
;
448 /* info->xmit_count is modified here and in isdn_tty_write().
449 * So we return here if isdn_tty_write() is in the
452 atomic_inc(&info
->xmit_lock
);
453 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
455 if (info
->isdn_driver
< 0) {
456 info
->xmit_count
= 0;
459 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
460 #ifdef CONFIG_ISDN_AUDIO
461 if (info
->vonline
& 2)
462 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
465 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
467 skb
= dev_alloc_skb(skb_res
+ buflen
);
471 "isdn_tty: Out of memory in ttyI%d senddown\n",
475 skb_reserve(skb
, skb_res
);
476 memcpy(skb_put(skb
, buflen
), info
->port
.xmit_buf
, buflen
);
477 info
->xmit_count
= 0;
478 #ifdef CONFIG_ISDN_AUDIO
479 if (info
->vonline
& 2) {
480 /* For now, ifmt is fixed to 1 (alaw), since this
481 * is used with ISDN everywhere in the world, except
482 * US, Canada and Japan.
483 * Later, when US-ISDN protocols are implemented,
484 * this setting will depend on the D-channel protocol.
488 /* voice conversion/decompression */
489 switch (info
->emu
.vpar
[3]) {
493 /* adpcm, compatible to ZyXel 1496 modem
494 * with ROM revision 6.01
496 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
499 skb_put(skb
, audio_len
),
501 skb_pull(skb
, buflen
);
502 skb_trim(skb
, audio_len
);
507 isdn_audio_alaw2ulaw(skb
->data
,
513 isdn_audio_ulaw2alaw(skb
->data
,
518 #endif /* CONFIG_ISDN_AUDIO */
519 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
520 /* Add T.70 simplified header */
521 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
522 memcpy(skb_push(skb
, 2), "\1\0", 2);
524 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
526 skb_queue_tail(&info
->xmit_queue
, skb
);
529 /************************************************************
533 * mostly "stolen" from original Linux-serial.c and friends.
535 ************************************************************/
537 /* The next routine is called once from within timer-interrupt
538 * triggered within isdn_tty_modem_ncarrier(). It calls
539 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
540 * into the tty's buffer.
543 isdn_tty_modem_do_ncarrier(unsigned long data
)
545 modem_info
*info
= (modem_info
*) data
;
546 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
549 /* Next routine is called, whenever the DTR-signal is raised.
550 * It checks the ncarrier-flag, and triggers the above routine
551 * when necessary. The ncarrier-flag is set, whenever DTR goes
555 isdn_tty_modem_ncarrier(modem_info
*info
)
557 if (info
->ncarrier
) {
558 info
->nc_timer
.expires
= jiffies
+ HZ
;
559 add_timer(&info
->nc_timer
);
564 * return the usage calculated by si and layer 2 protocol
567 isdn_calc_usage(int si
, int l2
)
569 int usg
= ISDN_USAGE_MODEM
;
571 #ifdef CONFIG_ISDN_AUDIO
574 case ISDN_PROTO_L2_MODEM
:
575 usg
= ISDN_USAGE_MODEM
;
577 #ifdef CONFIG_ISDN_TTY_FAX
578 case ISDN_PROTO_L2_FAX
:
579 usg
= ISDN_USAGE_FAX
;
582 case ISDN_PROTO_L2_TRANS
:
584 usg
= ISDN_USAGE_VOICE
;
592 /* isdn_tty_dial() performs dialing of a tty an the necessary
593 * setup of the lower levels before that.
596 isdn_tty_dial(char *n
, modem_info
*info
, atemu
*m
)
598 int usg
= ISDN_USAGE_MODEM
;
600 int l2
= m
->mdmreg
[REG_L2PROT
];
606 for (j
= 7; j
>= 0; j
--)
607 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
611 usg
= isdn_calc_usage(si
, l2
);
612 #ifdef CONFIG_ISDN_AUDIO
614 (l2
!= ISDN_PROTO_L2_MODEM
)
615 #ifdef CONFIG_ISDN_TTY_FAX
616 && (l2
!= ISDN_PROTO_L2_FAX
)
619 l2
= ISDN_PROTO_L2_TRANS
;
620 usg
= ISDN_USAGE_VOICE
;
623 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
624 spin_lock_irqsave(&dev
->lock
, flags
);
625 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
627 spin_unlock_irqrestore(&dev
->lock
, flags
);
628 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
630 info
->isdn_driver
= dev
->drvmap
[i
];
631 info
->isdn_channel
= dev
->chanmap
[i
];
633 dev
->m_idx
[i
] = info
->line
;
634 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
636 strcpy(info
->last_num
, n
);
638 spin_unlock_irqrestore(&dev
->lock
, flags
);
639 cmd
.driver
= info
->isdn_driver
;
640 cmd
.arg
= info
->isdn_channel
;
641 cmd
.command
= ISDN_CMD_CLREAZ
;
643 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
644 cmd
.driver
= info
->isdn_driver
;
645 cmd
.command
= ISDN_CMD_SETEAZ
;
647 cmd
.driver
= info
->isdn_driver
;
648 cmd
.command
= ISDN_CMD_SETL2
;
650 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
652 cmd
.driver
= info
->isdn_driver
;
653 cmd
.command
= ISDN_CMD_SETL3
;
654 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
655 #ifdef CONFIG_ISDN_TTY_FAX
656 if (l2
== ISDN_PROTO_L2_FAX
) {
657 cmd
.parm
.fax
= info
->fax
;
658 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
662 cmd
.driver
= info
->isdn_driver
;
663 cmd
.arg
= info
->isdn_channel
;
664 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
665 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
666 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
667 cmd
.parm
.setup
.si1
= si
;
668 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
669 cmd
.command
= ISDN_CMD_DIAL
;
671 info
->emu
.carrierwait
= 0;
672 strcpy(dev
->num
[i
], n
);
675 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
679 /* isdn_tty_hangup() disassociates a tty from the real
680 * ISDN-line (hangup). The usage-status is cleared
681 * and some cleanup is done also.
684 isdn_tty_modem_hup(modem_info
*info
, int local
)
692 di
= info
->isdn_driver
;
693 ch
= info
->isdn_channel
;
694 if (di
< 0 || ch
< 0)
697 info
->isdn_driver
= -1;
698 info
->isdn_channel
= -1;
700 #ifdef ISDN_DEBUG_MODEM_HUP
701 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
704 isdn_tty_flush_buffer(info
->port
.tty
);
706 info
->last_lhup
= local
;
708 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
710 #ifdef CONFIG_ISDN_AUDIO
712 #ifdef CONFIG_ISDN_TTY_FAX
714 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
716 info
->emu
.vpar
[4] = 0;
717 info
->emu
.vpar
[5] = 8;
718 kfree(info
->dtmf_state
);
719 info
->dtmf_state
= NULL
;
720 kfree(info
->silence_state
);
721 info
->silence_state
= NULL
;
727 if ((info
->msr
& UART_MSR_RI
) &&
728 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
729 isdn_tty_modem_result(RESULT_RUNG
, info
);
730 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
731 info
->lsr
|= UART_LSR_TEMT
;
735 cmd
.command
= ISDN_CMD_HANGUP
;
740 isdn_all_eaz(di
, ch
);
741 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
742 isdn_free_channel(di
, ch
, 0);
744 if (info
->drv_index
>= 0) {
745 dev
->m_idx
[info
->drv_index
] = -1;
746 info
->drv_index
= -1;
751 * Begin of a CAPI like interface, currently used only for
752 * supplementary service (CAPI 2.0 part III)
754 #include <linux/isdn/capicmd.h>
755 #include <linux/module.h>
758 isdn_tty_capi_facility(capi_msg
*cm
) {
759 return (-1); /* dummy */
762 /* isdn_tty_suspend() tries to suspend the current tty connection
765 isdn_tty_suspend(char *id
, modem_info
*info
, atemu
*m
)
774 #ifdef ISDN_DEBUG_MODEM_SERVICES
775 printk(KERN_DEBUG
"Msusp ttyI%d\n", info
->line
);
778 if ((info
->isdn_driver
>= 0)) {
779 cmd
.parm
.cmsg
.Length
= l
+ 18;
780 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
781 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
782 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
783 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
784 cmd
.parm
.cmsg
.para
[1] = 0;
785 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
786 cmd
.parm
.cmsg
.para
[3] = 4; /* 16 bit 0x0004 Suspend */
787 cmd
.parm
.cmsg
.para
[4] = 0;
788 cmd
.parm
.cmsg
.para
[5] = l
;
789 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
790 cmd
.command
= CAPI_PUT_MESSAGE
;
791 cmd
.driver
= info
->isdn_driver
;
792 cmd
.arg
= info
->isdn_channel
;
797 /* isdn_tty_resume() tries to resume a suspended call
798 * setup of the lower levels before that. unfortunately here is no
799 * checking for compatibility of used protocols implemented by Q931
800 * It does the same things like isdn_tty_dial, the last command
801 * is different, may be we can merge it.
805 isdn_tty_resume(char *id
, modem_info
*info
, atemu
*m
)
807 int usg
= ISDN_USAGE_MODEM
;
809 int l2
= m
->mdmreg
[REG_L2PROT
];
817 for (j
= 7; j
>= 0; j
--)
818 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
822 usg
= isdn_calc_usage(si
, l2
);
823 #ifdef CONFIG_ISDN_AUDIO
825 (l2
!= ISDN_PROTO_L2_MODEM
)
826 #ifdef CONFIG_ISDN_TTY_FAX
827 && (l2
!= ISDN_PROTO_L2_FAX
)
830 l2
= ISDN_PROTO_L2_TRANS
;
831 usg
= ISDN_USAGE_VOICE
;
834 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
835 spin_lock_irqsave(&dev
->lock
, flags
);
836 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
838 spin_unlock_irqrestore(&dev
->lock
, flags
);
839 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
841 info
->isdn_driver
= dev
->drvmap
[i
];
842 info
->isdn_channel
= dev
->chanmap
[i
];
844 dev
->m_idx
[i
] = info
->line
;
845 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
847 // strcpy(info->last_num, n);
849 spin_unlock_irqrestore(&dev
->lock
, flags
);
850 cmd
.driver
= info
->isdn_driver
;
851 cmd
.arg
= info
->isdn_channel
;
852 cmd
.command
= ISDN_CMD_CLREAZ
;
854 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
855 cmd
.driver
= info
->isdn_driver
;
856 cmd
.command
= ISDN_CMD_SETEAZ
;
858 cmd
.driver
= info
->isdn_driver
;
859 cmd
.command
= ISDN_CMD_SETL2
;
861 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
863 cmd
.driver
= info
->isdn_driver
;
864 cmd
.command
= ISDN_CMD_SETL3
;
865 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
867 cmd
.driver
= info
->isdn_driver
;
868 cmd
.arg
= info
->isdn_channel
;
869 cmd
.parm
.cmsg
.Length
= l
+ 18;
870 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
871 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
872 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
873 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
874 cmd
.parm
.cmsg
.para
[1] = 0;
875 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
876 cmd
.parm
.cmsg
.para
[3] = 5; /* 16 bit 0x0005 Resume */
877 cmd
.parm
.cmsg
.para
[4] = 0;
878 cmd
.parm
.cmsg
.para
[5] = l
;
879 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
880 cmd
.command
= CAPI_PUT_MESSAGE
;
882 // strcpy(dev->num[i], n);
885 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
889 /* isdn_tty_send_msg() sends a message to a HL driver
890 * This is used for hybrid modem cards to send AT commands to it
894 isdn_tty_send_msg(modem_info
*info
, atemu
*m
, char *msg
)
896 int usg
= ISDN_USAGE_MODEM
;
898 int l2
= m
->mdmreg
[REG_L2PROT
];
905 l
= min(strlen(msg
), sizeof(cmd
.parm
) - sizeof(cmd
.parm
.cmsg
)
906 + sizeof(cmd
.parm
.cmsg
.para
) - 2);
909 isdn_tty_modem_result(RESULT_ERROR
, info
);
912 for (j
= 7; j
>= 0; j
--)
913 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
917 usg
= isdn_calc_usage(si
, l2
);
918 #ifdef CONFIG_ISDN_AUDIO
920 (l2
!= ISDN_PROTO_L2_MODEM
)
921 #ifdef CONFIG_ISDN_TTY_FAX
922 && (l2
!= ISDN_PROTO_L2_FAX
)
925 l2
= ISDN_PROTO_L2_TRANS
;
926 usg
= ISDN_USAGE_VOICE
;
929 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
930 spin_lock_irqsave(&dev
->lock
, flags
);
931 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
933 spin_unlock_irqrestore(&dev
->lock
, flags
);
934 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
936 info
->isdn_driver
= dev
->drvmap
[i
];
937 info
->isdn_channel
= dev
->chanmap
[i
];
939 dev
->m_idx
[i
] = info
->line
;
940 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
943 spin_unlock_irqrestore(&dev
->lock
, flags
);
944 cmd
.driver
= info
->isdn_driver
;
945 cmd
.arg
= info
->isdn_channel
;
946 cmd
.command
= ISDN_CMD_CLREAZ
;
948 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
949 cmd
.driver
= info
->isdn_driver
;
950 cmd
.command
= ISDN_CMD_SETEAZ
;
952 cmd
.driver
= info
->isdn_driver
;
953 cmd
.command
= ISDN_CMD_SETL2
;
955 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
957 cmd
.driver
= info
->isdn_driver
;
958 cmd
.command
= ISDN_CMD_SETL3
;
959 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
961 cmd
.driver
= info
->isdn_driver
;
962 cmd
.arg
= info
->isdn_channel
;
963 cmd
.parm
.cmsg
.Length
= l
+ 14;
964 cmd
.parm
.cmsg
.Command
= CAPI_MANUFACTURER
;
965 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
966 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
967 cmd
.parm
.cmsg
.para
[0] = l
+ 1;
968 strncpy(&cmd
.parm
.cmsg
.para
[1], msg
, l
);
969 cmd
.parm
.cmsg
.para
[l
+ 1] = 0xd;
970 cmd
.command
= CAPI_PUT_MESSAGE
;
971 /* info->dialing = 1;
972 strcpy(dev->num[i], n);
980 isdn_tty_paranoia_check(modem_info
*info
, char *name
, const char *routine
)
982 #ifdef MODEM_PARANOIA_CHECK
984 printk(KERN_WARNING
"isdn_tty: null info_struct for %s in %s\n",
988 if (info
->magic
!= ISDN_ASYNC_MAGIC
) {
989 printk(KERN_WARNING
"isdn_tty: bad magic for modem struct %s in %s\n",
998 * This routine is called to set the UART divisor registers to match
999 * the specified baud rate for a serial port.
1002 isdn_tty_change_speed(modem_info
*info
)
1004 struct tty_port
*port
= &info
->port
;
1012 cflag
= port
->tty
->termios
.c_cflag
;
1014 quot
= i
= cflag
& CBAUD
;
1018 port
->tty
->termios
.c_cflag
&= ~CBAUDEX
;
1023 info
->mcr
|= UART_MCR_DTR
;
1024 isdn_tty_modem_ncarrier(info
);
1026 info
->mcr
&= ~UART_MCR_DTR
;
1027 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1028 #ifdef ISDN_DEBUG_MODEM_HUP
1029 printk(KERN_DEBUG
"Mhup in changespeed\n");
1033 isdn_tty_modem_reset_regs(info
, 0);
1034 isdn_tty_modem_hup(info
, 1);
1038 /* byte size and parity */
1039 cval
= cflag
& (CSIZE
| CSTOPB
);
1042 cval
|= UART_LCR_PARITY
;
1043 if (!(cflag
& PARODD
))
1044 cval
|= UART_LCR_EPAR
;
1046 /* CTS flow control flag and modem status interrupts */
1047 if (cflag
& CRTSCTS
) {
1048 port
->flags
|= ASYNC_CTS_FLOW
;
1050 port
->flags
&= ~ASYNC_CTS_FLOW
;
1052 port
->flags
&= ~ASYNC_CHECK_CD
;
1054 port
->flags
|= ASYNC_CHECK_CD
;
1059 isdn_tty_startup(modem_info
*info
)
1061 if (info
->port
.flags
& ASYNC_INITIALIZED
)
1063 isdn_lock_drivers();
1064 #ifdef ISDN_DEBUG_MODEM_OPEN
1065 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1068 * Now, initialize the UART
1070 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1072 clear_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1074 * and set the speed of the serial port
1076 isdn_tty_change_speed(info
);
1078 info
->port
.flags
|= ASYNC_INITIALIZED
;
1079 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1080 info
->send_outstanding
= 0;
1085 * This routine will shutdown a serial port; interrupts are disabled, and
1086 * DTR is dropped if the hangup on close termio flag is on.
1089 isdn_tty_shutdown(modem_info
*info
)
1091 if (!(info
->port
.flags
& ASYNC_INITIALIZED
))
1093 #ifdef ISDN_DEBUG_MODEM_OPEN
1094 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1096 isdn_unlock_drivers();
1097 info
->msr
&= ~UART_MSR_RI
;
1098 if (!info
->port
.tty
|| (info
->port
.tty
->termios
.c_cflag
& HUPCL
)) {
1099 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1100 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1101 isdn_tty_modem_reset_regs(info
, 0);
1102 #ifdef ISDN_DEBUG_MODEM_HUP
1103 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1105 isdn_tty_modem_hup(info
, 1);
1109 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1111 info
->port
.flags
&= ~ASYNC_INITIALIZED
;
1114 /* isdn_tty_write() is the main send-routine. It is called from the upper
1115 * levels within the kernel to perform sending data. Depending on the
1116 * online-flag it either directs output to the at-command-interpreter or
1117 * to the lower level. Additional tasks done here:
1118 * - If online, check for escape-sequence (+++)
1119 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1120 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1121 * - If dialing, abort dial.
1124 isdn_tty_write(struct tty_struct
*tty
, const u_char
*buf
, int count
)
1128 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1129 atemu
*m
= &info
->emu
;
1131 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write"))
1133 /* See isdn_tty_senddown() */
1134 atomic_inc(&info
->xmit_lock
);
1137 if (c
> info
->xmit_size
- info
->xmit_count
)
1138 c
= info
->xmit_size
- info
->xmit_count
;
1139 if (info
->isdn_driver
>= 0 && c
> dev
->drv
[info
->isdn_driver
]->maxbufsize
)
1140 c
= dev
->drv
[info
->isdn_driver
]->maxbufsize
;
1143 if ((info
->online
> 1)
1144 #ifdef CONFIG_ISDN_AUDIO
1145 || (info
->vonline
& 3)
1148 #ifdef CONFIG_ISDN_AUDIO
1151 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1154 memcpy(&info
->port
.xmit_buf
[info
->xmit_count
], buf
, c
);
1155 #ifdef CONFIG_ISDN_AUDIO
1156 if (info
->vonline
) {
1157 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1158 if (info
->vonline
& 2) {
1160 /* If DLE decoding results in zero-transmit, but
1161 * c originally was non-zero, do a wakeup.
1164 info
->msr
|= UART_MSR_CTS
;
1165 info
->lsr
|= UART_LSR_TEMT
;
1167 info
->xmit_count
+= cc
;
1169 if ((info
->vonline
& 3) == 1) {
1170 /* Do NOT handle Ctrl-Q or Ctrl-S
1171 * when in full-duplex audio mode.
1173 if (isdn_tty_end_vrx(buf
, c
)) {
1174 info
->vonline
&= ~1;
1175 #ifdef ISDN_DEBUG_MODEM_VOICE
1177 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1180 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1184 if (TTY_IS_FCLASS1(info
)) {
1185 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1187 if (info
->vonline
& 4) { /* ETX seen */
1190 c
.command
= ISDN_CMD_FAXCMD
;
1191 c
.driver
= info
->isdn_driver
;
1192 c
.arg
= info
->isdn_channel
;
1193 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1194 c
.parm
.aux
.subcmd
= ETX
;
1198 #ifdef ISDN_DEBUG_MODEM_VOICE
1199 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
, c
);
1201 info
->xmit_count
+= cc
;
1204 info
->xmit_count
+= c
;
1206 info
->msr
|= UART_MSR_CTS
;
1207 info
->lsr
|= UART_LSR_TEMT
;
1208 if (info
->dialing
) {
1210 #ifdef ISDN_DEBUG_MODEM_HUP
1211 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1213 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1214 isdn_tty_modem_hup(info
, 1);
1216 c
= isdn_tty_edit_at(buf
, c
, info
);
1222 atomic_dec(&info
->xmit_lock
);
1223 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
)) {
1224 if (m
->mdmreg
[REG_DXMT
] & BIT_DXMT
) {
1225 isdn_tty_senddown(info
);
1226 isdn_tty_tint(info
);
1228 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1234 isdn_tty_write_room(struct tty_struct
*tty
)
1236 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1239 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_write_room"))
1242 return info
->xmit_size
;
1243 ret
= info
->xmit_size
- info
->xmit_count
;
1244 return (ret
< 0) ? 0 : ret
;
1248 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1250 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1252 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_chars_in_buffer"))
1256 return (info
->xmit_count
);
1260 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1267 info
= (modem_info
*) tty
->driver_data
;
1268 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_buffer")) {
1271 isdn_tty_cleanup_xmit(info
);
1272 info
->xmit_count
= 0;
1277 isdn_tty_flush_chars(struct tty_struct
*tty
)
1279 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1281 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_flush_chars"))
1283 if ((info
->xmit_count
) || !skb_queue_empty(&info
->xmit_queue
))
1284 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1288 * ------------------------------------------------------------
1289 * isdn_tty_throttle()
1291 * This routine is called by the upper-layer tty layer to signal that
1292 * incoming characters should be throttled.
1293 * ------------------------------------------------------------
1296 isdn_tty_throttle(struct tty_struct
*tty
)
1298 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1300 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_throttle"))
1303 info
->x_char
= STOP_CHAR(tty
);
1304 info
->mcr
&= ~UART_MCR_RTS
;
1308 isdn_tty_unthrottle(struct tty_struct
*tty
)
1310 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1312 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_unthrottle"))
1318 info
->x_char
= START_CHAR(tty
);
1320 info
->mcr
|= UART_MCR_RTS
;
1324 * ------------------------------------------------------------
1325 * isdn_tty_ioctl() and friends
1326 * ------------------------------------------------------------
1330 * isdn_tty_get_lsr_info - get line status register info
1332 * Purpose: Let user call ioctl() to get info when the UART physically
1333 * is emptied. On bus types like RS485, the transmitter must
1334 * release the bus after transmitting. This must be done when
1335 * the transmit shift register is empty, not be done when the
1336 * transmit holding register is empty. This functionality
1337 * allows RS485 driver to be written in user space.
1340 isdn_tty_get_lsr_info(modem_info
*info
, uint __user
*value
)
1346 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1347 return put_user(result
, value
);
1352 isdn_tty_tiocmget(struct tty_struct
*tty
)
1354 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1355 u_char control
, status
;
1357 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1359 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1362 mutex_lock(&modem_info_mutex
);
1363 #ifdef ISDN_DEBUG_MODEM_IOCTL
1364 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1367 control
= info
->mcr
;
1369 mutex_unlock(&modem_info_mutex
);
1370 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1371 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1372 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1373 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1374 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1375 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1379 isdn_tty_tiocmset(struct tty_struct
*tty
,
1380 unsigned int set
, unsigned int clear
)
1382 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1384 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1386 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1389 #ifdef ISDN_DEBUG_MODEM_IOCTL
1390 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMxxx: %x %x\n", info
->line
, set
, clear
);
1393 mutex_lock(&modem_info_mutex
);
1394 if (set
& TIOCM_RTS
)
1395 info
->mcr
|= UART_MCR_RTS
;
1396 if (set
& TIOCM_DTR
) {
1397 info
->mcr
|= UART_MCR_DTR
;
1398 isdn_tty_modem_ncarrier(info
);
1401 if (clear
& TIOCM_RTS
)
1402 info
->mcr
&= ~UART_MCR_RTS
;
1403 if (clear
& TIOCM_DTR
) {
1404 info
->mcr
&= ~UART_MCR_DTR
;
1405 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1406 isdn_tty_modem_reset_regs(info
, 0);
1407 #ifdef ISDN_DEBUG_MODEM_HUP
1408 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1412 isdn_tty_modem_hup(info
, 1);
1415 mutex_unlock(&modem_info_mutex
);
1420 isdn_tty_ioctl(struct tty_struct
*tty
, uint cmd
, ulong arg
)
1422 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1425 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_ioctl"))
1427 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1430 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1431 #ifdef ISDN_DEBUG_MODEM_IOCTL
1432 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1434 retval
= tty_check_change(tty
);
1437 tty_wait_until_sent(tty
, 0);
1439 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1440 #ifdef ISDN_DEBUG_MODEM_IOCTL
1441 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1443 retval
= tty_check_change(tty
);
1446 tty_wait_until_sent(tty
, 0);
1448 case TIOCSERGETLSR
: /* Get line status register */
1449 #ifdef ISDN_DEBUG_MODEM_IOCTL
1450 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1452 return isdn_tty_get_lsr_info(info
, (uint __user
*) arg
);
1454 #ifdef ISDN_DEBUG_MODEM_IOCTL
1455 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1457 return -ENOIOCTLCMD
;
1463 isdn_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
1465 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1468 isdn_tty_change_speed(info
);
1470 if (tty
->termios
.c_cflag
== old_termios
->c_cflag
&&
1471 tty
->termios
.c_ispeed
== old_termios
->c_ispeed
&&
1472 tty
->termios
.c_ospeed
== old_termios
->c_ospeed
)
1474 isdn_tty_change_speed(info
);
1479 * ------------------------------------------------------------
1480 * isdn_tty_open() and friends
1481 * ------------------------------------------------------------
1484 static int isdn_tty_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
1486 modem_info
*info
= &dev
->mdm
.info
[tty
->index
];
1488 if (isdn_tty_paranoia_check(info
, tty
->name
, __func__
))
1491 tty
->driver_data
= info
;
1493 return tty_port_install(&info
->port
, driver
, tty
);
1497 * This routine is called whenever a serial port is opened. It
1498 * enables interrupts for a serial port, linking in its async structure into
1499 * the IRQ chain. It also performs the serial-specific
1500 * initialization for the tty structure.
1503 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
1505 modem_info
*info
= tty
->driver_data
;
1506 struct tty_port
*port
= &info
->port
;
1509 #ifdef ISDN_DEBUG_MODEM_OPEN
1510 printk(KERN_DEBUG
"isdn_tty_open %s, count = %d\n", tty
->name
,
1516 * Start up serial port
1518 retval
= isdn_tty_startup(info
);
1520 #ifdef ISDN_DEBUG_MODEM_OPEN
1521 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
1525 retval
= tty_port_block_til_ready(port
, tty
, filp
);
1527 #ifdef ISDN_DEBUG_MODEM_OPEN
1528 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
1532 #ifdef ISDN_DEBUG_MODEM_OPEN
1533 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
1536 #ifdef ISDN_DEBUG_MODEM_OPEN
1537 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
1543 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
1545 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1546 struct tty_port
*port
= &info
->port
;
1549 if (!info
|| isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_close"))
1551 if (tty_hung_up_p(filp
)) {
1552 #ifdef ISDN_DEBUG_MODEM_OPEN
1553 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
1557 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1559 * Uh, oh. tty->count is 1, which means that the tty
1560 * structure will be freed. Info->count should always
1561 * be one in these conditions. If it's greater than
1562 * one, we've got real problems, since it means the
1563 * serial port won't be shutdown.
1565 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
1566 "info->count is %d\n", port
->count
);
1569 if (--port
->count
< 0) {
1570 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
1571 info
->line
, port
->count
);
1575 #ifdef ISDN_DEBUG_MODEM_OPEN
1576 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
1580 port
->flags
|= ASYNC_CLOSING
;
1584 * At this point we stop accepting input. To do this, we
1585 * disable the receive line status interrupts, and tell the
1586 * interrupt driver to stop checking the data ready bit in the
1587 * line status register.
1589 if (port
->flags
& ASYNC_INITIALIZED
) {
1590 tty_wait_until_sent_from_close(tty
, 3000); /* 30 seconds timeout */
1592 * Before we drop DTR, make sure the UART transmitter
1593 * has completely drained; this is especially
1594 * important if there is a transmit FIFO!
1596 timeout
= jiffies
+ HZ
;
1597 while (!(info
->lsr
& UART_LSR_TEMT
)) {
1598 schedule_timeout_interruptible(20);
1599 if (time_after(jiffies
, timeout
))
1604 isdn_tty_shutdown(info
);
1605 isdn_tty_flush_buffer(tty
);
1606 tty_ldisc_flush(tty
);
1610 tty_port_close_end(port
, tty
);
1611 #ifdef ISDN_DEBUG_MODEM_OPEN
1612 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
1617 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
1620 isdn_tty_hangup(struct tty_struct
*tty
)
1622 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1623 struct tty_port
*port
= &info
->port
;
1625 if (isdn_tty_paranoia_check(info
, tty
->name
, "isdn_tty_hangup"))
1627 isdn_tty_shutdown(info
);
1629 port
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1631 wake_up_interruptible(&port
->open_wait
);
1634 /* This routine initializes all emulator-data.
1637 isdn_tty_reset_profile(atemu
*m
)
1650 m
->profile
[11] = 70;
1651 m
->profile
[12] = 0x45;
1653 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
1654 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
1655 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
1656 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
1665 #ifdef CONFIG_ISDN_AUDIO
1667 isdn_tty_modem_reset_vpar(atemu
*m
)
1669 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
1670 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
1671 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
1672 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
1673 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
1674 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
1678 #ifdef CONFIG_ISDN_TTY_FAX
1680 isdn_tty_modem_reset_faxpar(modem_info
*info
)
1682 T30_s
*f
= info
->fax
;
1685 f
->phase
= ISDN_FAX_PHASE_IDLE
;
1687 f
->resolution
= 1; /* fine */
1688 f
->rate
= 5; /* 14400 bit/s */
1695 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
1696 f
->id
[FAXIDLEN
- 1] = 0;
1707 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
1708 f
->pollid
[FAXIDLEN
- 1] = 0;
1713 isdn_tty_modem_reset_regs(modem_info
*info
, int force
)
1715 atemu
*m
= &info
->emu
;
1716 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
1717 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
1718 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
1719 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
1720 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
1722 #ifdef CONFIG_ISDN_AUDIO
1723 isdn_tty_modem_reset_vpar(m
);
1725 #ifdef CONFIG_ISDN_TTY_FAX
1726 isdn_tty_modem_reset_faxpar(info
);
1732 modem_write_profile(atemu
*m
)
1734 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
1735 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
1736 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
1738 send_sig(SIGIO
, dev
->profd
, 1);
1741 static const struct tty_operations modem_ops
= {
1742 .install
= isdn_tty_install
,
1743 .open
= isdn_tty_open
,
1744 .close
= isdn_tty_close
,
1745 .write
= isdn_tty_write
,
1746 .flush_chars
= isdn_tty_flush_chars
,
1747 .write_room
= isdn_tty_write_room
,
1748 .chars_in_buffer
= isdn_tty_chars_in_buffer
,
1749 .flush_buffer
= isdn_tty_flush_buffer
,
1750 .ioctl
= isdn_tty_ioctl
,
1751 .throttle
= isdn_tty_throttle
,
1752 .unthrottle
= isdn_tty_unthrottle
,
1753 .set_termios
= isdn_tty_set_termios
,
1754 .hangup
= isdn_tty_hangup
,
1755 .tiocmget
= isdn_tty_tiocmget
,
1756 .tiocmset
= isdn_tty_tiocmset
,
1759 static int isdn_tty_carrier_raised(struct tty_port
*port
)
1761 modem_info
*info
= container_of(port
, modem_info
, port
);
1762 return info
->msr
& UART_MSR_DCD
;
1765 static const struct tty_port_operations isdn_tty_port_ops
= {
1766 .carrier_raised
= isdn_tty_carrier_raised
,
1770 isdn_tty_modem_init(void)
1777 m
->tty_modem
= alloc_tty_driver(ISDN_MAX_CHANNELS
);
1780 m
->tty_modem
->name
= "ttyI";
1781 m
->tty_modem
->major
= ISDN_TTY_MAJOR
;
1782 m
->tty_modem
->minor_start
= 0;
1783 m
->tty_modem
->type
= TTY_DRIVER_TYPE_SERIAL
;
1784 m
->tty_modem
->subtype
= SERIAL_TYPE_NORMAL
;
1785 m
->tty_modem
->init_termios
= tty_std_termios
;
1786 m
->tty_modem
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1787 m
->tty_modem
->flags
= TTY_DRIVER_REAL_RAW
;
1788 m
->tty_modem
->driver_name
= "isdn_tty";
1789 tty_set_operations(m
->tty_modem
, &modem_ops
);
1790 retval
= tty_register_driver(m
->tty_modem
);
1792 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
1795 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1797 #ifdef CONFIG_ISDN_TTY_FAX
1798 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
1799 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
1801 goto err_unregister
;
1804 tty_port_init(&info
->port
);
1805 info
->port
.ops
= &isdn_tty_port_ops
;
1806 spin_lock_init(&info
->readlock
);
1807 sprintf(info
->last_cause
, "0000");
1808 sprintf(info
->last_num
, "none");
1810 info
->last_lhup
= 1;
1813 isdn_tty_reset_profile(&info
->emu
);
1814 isdn_tty_modem_reset_regs(info
, 1);
1815 info
->magic
= ISDN_ASYNC_MAGIC
;
1818 info
->isdn_driver
= -1;
1819 info
->isdn_channel
= -1;
1820 info
->drv_index
= -1;
1821 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
1822 init_timer(&info
->nc_timer
);
1823 info
->nc_timer
.function
= isdn_tty_modem_do_ncarrier
;
1824 info
->nc_timer
.data
= (unsigned long) info
;
1825 skb_queue_head_init(&info
->xmit_queue
);
1826 #ifdef CONFIG_ISDN_AUDIO
1827 skb_queue_head_init(&info
->dtmf_queue
);
1829 info
->port
.xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5,
1831 if (!info
->port
.xmit_buf
) {
1832 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
1834 goto err_unregister
;
1836 /* Make room for T.70 header */
1837 info
->port
.xmit_buf
+= 4;
1841 for (i
--; i
>= 0; i
--) {
1843 #ifdef CONFIG_ISDN_TTY_FAX
1846 kfree(info
->port
.xmit_buf
- 4);
1847 info
->port
.xmit_buf
= NULL
;
1848 tty_port_destroy(&info
->port
);
1850 tty_unregister_driver(m
->tty_modem
);
1852 put_tty_driver(m
->tty_modem
);
1853 m
->tty_modem
= NULL
;
1863 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1864 info
= &dev
->mdm
.info
[i
];
1865 isdn_tty_cleanup_xmit(info
);
1866 #ifdef CONFIG_ISDN_TTY_FAX
1869 kfree(info
->port
.xmit_buf
- 4);
1870 info
->port
.xmit_buf
= NULL
;
1871 tty_port_destroy(&info
->port
);
1873 tty_unregister_driver(dev
->mdm
.tty_modem
);
1874 put_tty_driver(dev
->mdm
.tty_modem
);
1875 dev
->mdm
.tty_modem
= NULL
;
1880 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
1881 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
1882 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
1886 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
1888 #ifdef ISDN_DEBUG_MODEM_ICALL
1889 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
1890 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
1891 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
1893 if (strlen(emu
->lmsn
)) {
1894 char *p
= emu
->lmsn
;
1900 if ((q
= strchr(p
, ';')))
1902 if ((tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
1904 #ifdef ISDN_DEBUG_MODEM_ICALL
1905 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
1906 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
1921 tmp
= isdn_msncmp(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
1922 #ifdef ISDN_DEBUG_MODEM_ICALL
1923 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
1924 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
1931 * An incoming call-request has arrived.
1932 * Search the tty-devices for an appropriate device and bind
1933 * it to the ISDN-Channel.
1936 * 0 = No matching device found.
1937 * 1 = A matching device found.
1938 * 3 = No match found, but eventually would match, if
1942 isdn_tty_find_icall(int di
, int ch
, setup_parm
*setup
)
1953 if (!setup
->phone
[0]) {
1955 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
1958 si1
= (int) setup
->si1
;
1959 si2
= (int) setup
->si2
;
1960 if (!setup
->eazmsn
[0]) {
1961 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
1964 eaz
= setup
->eazmsn
;
1965 #ifdef ISDN_DEBUG_MODEM_ICALL
1966 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
1969 spin_lock_irqsave(&dev
->lock
, flags
);
1970 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
1971 modem_info
*info
= &dev
->mdm
.info
[i
];
1973 if (info
->port
.count
== 0)
1975 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
1976 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
1977 idx
= isdn_dc2minor(di
, ch
);
1978 #ifdef ISDN_DEBUG_MODEM_ICALL
1979 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
1980 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
1981 info
->port
.flags
, info
->isdn_driver
,
1982 info
->isdn_channel
, dev
->usage
[idx
]);
1985 #ifndef FIX_FILE_TRANSFER
1986 (info
->port
.flags
& ASYNC_NORMAL_ACTIVE
) &&
1988 (info
->isdn_driver
== -1) &&
1989 (info
->isdn_channel
== -1) &&
1990 (USG_NONE(dev
->usage
[idx
]))) {
1993 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
1995 if (!matchret
) { /* EAZ is matching */
1996 info
->isdn_driver
= di
;
1997 info
->isdn_channel
= ch
;
1998 info
->drv_index
= idx
;
1999 dev
->m_idx
[idx
] = info
->line
;
2000 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2001 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
2002 strcpy(dev
->num
[idx
], nr
);
2003 strcpy(info
->emu
.cpn
, eaz
);
2004 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
2005 info
->emu
.mdmreg
[REG_PLAN
] = setup
->plan
;
2006 info
->emu
.mdmreg
[REG_SCREEN
] = setup
->screen
;
2008 spin_unlock_irqrestore(&dev
->lock
, flags
);
2009 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2011 info
->msr
|= UART_MSR_RI
;
2012 isdn_tty_modem_result(RESULT_RING
, info
);
2013 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2019 spin_unlock_irqrestore(&dev
->lock
, flags
);
2020 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2021 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2)) ? "rejected" : "ignored");
2022 return (wret
== 2) ? 3 : 0;
2025 #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE)
2028 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2036 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2037 info
= &dev
->mdm
.info
[mi
];
2038 switch (c
->command
) {
2039 case ISDN_STAT_CINF
:
2040 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2041 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2042 if (e
== (char *)c
->parm
.num
)
2043 info
->emu
.charge
= 0;
2046 case ISDN_STAT_BSENT
:
2047 #ifdef ISDN_TTY_STAT_DEBUG
2048 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2050 if ((info
->isdn_driver
== c
->driver
) &&
2051 (info
->isdn_channel
== c
->arg
)) {
2052 info
->msr
|= UART_MSR_CTS
;
2053 if (info
->send_outstanding
)
2054 if (!(--info
->send_outstanding
))
2055 info
->lsr
|= UART_LSR_TEMT
;
2056 isdn_tty_tint(info
);
2060 case ISDN_STAT_CAUSE
:
2061 #ifdef ISDN_TTY_STAT_DEBUG
2062 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2064 /* Signal cause to tty-device */
2065 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2067 case ISDN_STAT_DISPLAY
:
2068 #ifdef ISDN_TTY_STAT_DEBUG
2069 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2071 /* Signal display to tty-device */
2072 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2073 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2074 isdn_tty_at_cout("\r\n", info
);
2075 isdn_tty_at_cout("DISPLAY: ", info
);
2076 isdn_tty_at_cout(c
->parm
.display
, info
);
2077 isdn_tty_at_cout("\r\n", info
);
2080 case ISDN_STAT_DCONN
:
2081 #ifdef ISDN_TTY_STAT_DEBUG
2082 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2084 if (TTY_IS_ACTIVE(info
)) {
2085 if (info
->dialing
== 1) {
2091 case ISDN_STAT_DHUP
:
2092 #ifdef ISDN_TTY_STAT_DEBUG
2093 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2095 if (TTY_IS_ACTIVE(info
)) {
2096 if (info
->dialing
== 1)
2097 isdn_tty_modem_result(RESULT_BUSY
, info
);
2098 if (info
->dialing
> 1)
2099 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2101 #ifdef ISDN_DEBUG_MODEM_HUP
2102 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2104 isdn_tty_modem_hup(info
, 0);
2108 case ISDN_STAT_BCONN
:
2109 #ifdef ISDN_TTY_STAT_DEBUG
2110 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2112 /* Wake up any processes waiting
2113 * for incoming call of this device when
2114 * DCD follow the state of incoming carrier
2116 if (info
->port
.blocked_open
&&
2117 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
)) {
2118 wake_up_interruptible(&info
->port
.open_wait
);
2121 /* Schedule CONNECT-Message to any tty
2122 * waiting for it and
2123 * set DCD-bit of its modem-status.
2125 if (TTY_IS_ACTIVE(info
) ||
2126 (info
->port
.blocked_open
&&
2127 (info
->emu
.mdmreg
[REG_DCD
] & BIT_DCD
))) {
2128 info
->msr
|= UART_MSR_DCD
;
2129 info
->emu
.charge
= 0;
2130 if (info
->dialing
& 0xf)
2136 if (USG_MODEM(dev
->usage
[i
])) {
2137 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2138 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2139 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2141 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2143 if (USG_VOICE(dev
->usage
[i
]))
2144 isdn_tty_modem_result(RESULT_VCON
, info
);
2148 case ISDN_STAT_BHUP
:
2149 #ifdef ISDN_TTY_STAT_DEBUG
2150 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2152 if (TTY_IS_ACTIVE(info
)) {
2153 #ifdef ISDN_DEBUG_MODEM_HUP
2154 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2156 isdn_tty_modem_hup(info
, 0);
2160 case ISDN_STAT_NODCH
:
2161 #ifdef ISDN_TTY_STAT_DEBUG
2162 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2164 if (TTY_IS_ACTIVE(info
)) {
2165 if (info
->dialing
) {
2169 sprintf(info
->last_cause
, "0000");
2170 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2172 isdn_tty_modem_hup(info
, 0);
2176 case ISDN_STAT_UNLOAD
:
2177 #ifdef ISDN_TTY_STAT_DEBUG
2178 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2180 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2181 info
= &dev
->mdm
.info
[i
];
2182 if (info
->isdn_driver
== c
->driver
) {
2184 isdn_tty_modem_hup(info
, 1);
2188 #ifdef CONFIG_ISDN_TTY_FAX
2189 case ISDN_STAT_FAXIND
:
2190 if (TTY_IS_ACTIVE(info
)) {
2191 isdn_tty_fax_command(info
, c
);
2195 #ifdef CONFIG_ISDN_AUDIO
2196 case ISDN_STAT_AUDIO
:
2197 if (TTY_IS_ACTIVE(info
)) {
2198 switch (c
->parm
.num
[0]) {
2199 case ISDN_AUDIO_DTMF
:
2200 if (info
->vonline
) {
2201 isdn_audio_put_dle_code(info
,
2214 /*********************************************************************
2215 Modem-Emulator-Routines
2216 *********************************************************************/
2218 #define cmdchar(c) ((c >= ' ') && (c <= 0x7f))
2221 * Put a message from the AT-emulator into receive-buffer of tty,
2222 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2225 isdn_tty_at_cout(char *msg
, modem_info
*info
)
2227 struct tty_port
*port
= &info
->port
;
2228 atemu
*m
= &info
->emu
;
2232 struct sk_buff
*skb
= NULL
;
2237 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2243 spin_lock_irqsave(&info
->readlock
, flags
);
2244 if (port
->flags
& ASYNC_CLOSING
) {
2245 spin_unlock_irqrestore(&info
->readlock
, flags
);
2249 /* use queue instead of direct, if online and */
2250 /* data is in queue or buffer is full */
2251 if (info
->online
&& ((tty_buffer_request_room(port
, l
) < l
) ||
2252 !skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
]))) {
2253 skb
= alloc_skb(l
, GFP_ATOMIC
);
2255 spin_unlock_irqrestore(&info
->readlock
, flags
);
2258 sp
= skb_put(skb
, l
);
2259 #ifdef CONFIG_ISDN_AUDIO
2260 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2261 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2265 for (p
= msg
; *p
; p
++) {
2268 c
= m
->mdmreg
[REG_CR
];
2271 c
= m
->mdmreg
[REG_LF
];
2274 c
= m
->mdmreg
[REG_BS
];
2282 if (tty_insert_flip_char(port
, c
, TTY_NORMAL
) == 0)
2287 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2288 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2289 spin_unlock_irqrestore(&info
->readlock
, flags
);
2290 /* Schedule dequeuing */
2291 if (dev
->modempoll
&& info
->rcvsched
)
2292 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2295 spin_unlock_irqrestore(&info
->readlock
, flags
);
2296 tty_flip_buffer_push(port
);
2301 * Perform ATH Hangup
2304 isdn_tty_on_hook(modem_info
*info
)
2306 if (info
->isdn_channel
>= 0) {
2307 #ifdef ISDN_DEBUG_MODEM_HUP
2308 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2310 isdn_tty_modem_hup(info
, 1);
2315 isdn_tty_off_hook(void)
2317 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2320 #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */
2321 #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */
2324 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2325 * isdn_tty_modem_escape() if sequence found.
2328 * p pointer to databuffer
2329 * plus escape-character
2330 * count length of buffer
2331 * pluscount count of valid escape-characters so far
2332 * lastplus timestamp of last character
2335 isdn_tty_check_esc(const u_char
*p
, u_char plus
, int count
, int *pluscount
,
2346 if (*(p
++) == plus
) {
2347 if ((*pluscount
)++) {
2348 /* Time since last '+' > 0.5 sec. ? */
2349 if (time_after(jiffies
, *lastplus
+ PLUSWAIT1
))
2352 /* Time since last non-'+' < 1.5 sec. ? */
2353 if (time_before(jiffies
, *lastplus
+ PLUSWAIT2
))
2356 if ((*pluscount
== 3) && (count
== 1))
2357 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2362 *lastplus
= jiffies
;
2368 * Return result of AT-emulator to tty-receive-buffer, depending on
2369 * modem-register 12, bit 0 and 1.
2370 * For CONNECT-messages also switch to online-mode.
2371 * For RING-message handle auto-ATA if register 0 != 0
2375 isdn_tty_modem_result(int code
, modem_info
*info
)
2377 atemu
*m
= &info
->emu
;
2378 static char *msg
[] =
2379 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2380 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2381 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2382 char s
[ISDN_MSNLEN
+ 10];
2386 m
->mdmreg
[REG_RINGCNT
]++;
2387 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2388 /* Automatically accept incoming call */
2389 isdn_tty_cmd_ATA(info
);
2391 case RESULT_NO_CARRIER
:
2392 #ifdef ISDN_DEBUG_MODEM_HUP
2393 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2394 (info
->port
.flags
& ASYNC_CLOSING
),
2397 m
->mdmreg
[REG_RINGCNT
] = 0;
2398 del_timer(&info
->nc_timer
);
2400 if ((info
->port
.flags
& ASYNC_CLOSING
) || (!info
->port
.tty
))
2403 #ifdef CONFIG_ISDN_AUDIO
2404 if (info
->vonline
& 1) {
2405 #ifdef ISDN_DEBUG_MODEM_VOICE
2406 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
2409 /* voice-recording, add DLE-ETX */
2410 isdn_tty_at_cout("\020\003", info
);
2412 if (info
->vonline
& 2) {
2413 #ifdef ISDN_DEBUG_MODEM_VOICE
2414 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
2417 /* voice-playing, add DLE-DC4 */
2418 isdn_tty_at_cout("\020\024", info
);
2422 case RESULT_CONNECT
:
2423 case RESULT_CONNECT64000
:
2424 sprintf(info
->last_cause
, "0000");
2429 #ifdef ISDN_DEBUG_MODEM_VOICE
2430 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
2433 sprintf(info
->last_cause
, "0000");
2437 } /* switch (code) */
2439 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
2441 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
2442 /* Show numeric results only */
2443 sprintf(s
, "\r\n%d\r\n", code
);
2444 isdn_tty_at_cout(s
, info
);
2446 if (code
== RESULT_RING
) {
2447 /* return if "show RUNG" and ringcounter>1 */
2448 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
2449 (m
->mdmreg
[REG_RINGCNT
] > 1))
2451 /* print CID, _before_ _every_ ring */
2452 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
2453 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
2454 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2455 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2456 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2457 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2461 isdn_tty_at_cout("\r\n", info
);
2462 isdn_tty_at_cout(msg
[code
], info
);
2464 case RESULT_CONNECT
:
2465 switch (m
->mdmreg
[REG_L2PROT
]) {
2466 case ISDN_PROTO_L2_MODEM
:
2467 isdn_tty_at_cout(" ", info
);
2468 isdn_tty_at_cout(m
->connmsg
, info
);
2473 /* Append CPN, if enabled */
2474 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
2475 sprintf(s
, "/%s", m
->cpn
);
2476 isdn_tty_at_cout(s
, info
);
2478 /* Print CID only once, _after_ 1st RING */
2479 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
2480 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
2481 isdn_tty_at_cout("\r\n", info
);
2482 isdn_tty_at_cout("CALLER NUMBER: ", info
);
2483 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
2484 if (m
->mdmreg
[REG_CDN
] & BIT_CDN
) {
2485 isdn_tty_at_cout("\r\nCALLED NUMBER: ", info
);
2486 isdn_tty_at_cout(info
->emu
.cpn
, info
);
2490 case RESULT_NO_CARRIER
:
2491 case RESULT_NO_DIALTONE
:
2493 case RESULT_NO_ANSWER
:
2494 m
->mdmreg
[REG_RINGCNT
] = 0;
2495 /* Append Cause-Message if enabled */
2496 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
2497 sprintf(s
, "/%s", info
->last_cause
);
2498 isdn_tty_at_cout(s
, info
);
2501 case RESULT_CONNECT64000
:
2502 /* Append Protocol to CONNECT message */
2503 switch (m
->mdmreg
[REG_L2PROT
]) {
2504 case ISDN_PROTO_L2_X75I
:
2505 case ISDN_PROTO_L2_X75UI
:
2506 case ISDN_PROTO_L2_X75BUI
:
2507 isdn_tty_at_cout("/X.75", info
);
2509 case ISDN_PROTO_L2_HDLC
:
2510 isdn_tty_at_cout("/HDLC", info
);
2512 case ISDN_PROTO_L2_V11096
:
2513 isdn_tty_at_cout("/V110/9600", info
);
2515 case ISDN_PROTO_L2_V11019
:
2516 isdn_tty_at_cout("/V110/19200", info
);
2518 case ISDN_PROTO_L2_V11038
:
2519 isdn_tty_at_cout("/V110/38400", info
);
2522 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2523 isdn_tty_at_cout("/T.70", info
);
2524 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2525 isdn_tty_at_cout("+", info
);
2529 isdn_tty_at_cout("\r\n", info
);
2532 if (code
== RESULT_NO_CARRIER
) {
2533 if ((info
->port
.flags
& ASYNC_CLOSING
) || (!info
->port
.tty
))
2536 if (info
->port
.flags
& ASYNC_CHECK_CD
)
2537 tty_hangup(info
->port
.tty
);
2543 * Display a modem-register-value.
2546 isdn_tty_show_profile(int ridx
, modem_info
*info
)
2550 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
2551 isdn_tty_at_cout(v
, info
);
2555 * Get MSN-string from char-pointer, set pointer to end of number
2558 isdn_tty_get_msnstr(char *n
, char **p
)
2560 int limit
= ISDN_MSNLEN
- 1;
2562 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
2563 /* Why a comma ??? */
2564 (*p
[0] == ',') || (*p
[0] == ':')) &&
2571 * Get phone-number from modem-commandbuffer
2574 isdn_tty_getdial(char *p
, char *q
, int cnt
)
2577 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
2580 while (strchr(" 0123456789,#.*WPTSR-", *p
) && *p
&& --cnt
> 0) {
2581 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
2582 ((*p
== 'R') && first
) ||
2583 (*p
== '*') || (*p
== '#')) {
2595 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
2596 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
2599 isdn_tty_report(modem_info
*info
)
2601 atemu
*m
= &info
->emu
;
2604 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
2605 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
2606 isdn_tty_at_cout(s
, info
);
2607 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
2608 isdn_tty_at_cout(s
, info
);
2609 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
2610 switch (info
->last_l2
) {
2611 case ISDN_PROTO_L2_X75I
:
2612 isdn_tty_at_cout("X.75i", info
);
2614 case ISDN_PROTO_L2_X75UI
:
2615 isdn_tty_at_cout("X.75ui", info
);
2617 case ISDN_PROTO_L2_X75BUI
:
2618 isdn_tty_at_cout("X.75bui", info
);
2620 case ISDN_PROTO_L2_HDLC
:
2621 isdn_tty_at_cout("HDLC", info
);
2623 case ISDN_PROTO_L2_V11096
:
2624 isdn_tty_at_cout("V.110 9600 Baud", info
);
2626 case ISDN_PROTO_L2_V11019
:
2627 isdn_tty_at_cout("V.110 19200 Baud", info
);
2629 case ISDN_PROTO_L2_V11038
:
2630 isdn_tty_at_cout("V.110 38400 Baud", info
);
2632 case ISDN_PROTO_L2_TRANS
:
2633 isdn_tty_at_cout("transparent", info
);
2635 case ISDN_PROTO_L2_MODEM
:
2636 isdn_tty_at_cout("modem", info
);
2638 case ISDN_PROTO_L2_FAX
:
2639 isdn_tty_at_cout("fax", info
);
2642 isdn_tty_at_cout("unknown", info
);
2645 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
2646 isdn_tty_at_cout("/T.70", info
);
2647 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
2648 isdn_tty_at_cout("+", info
);
2650 isdn_tty_at_cout("\r\n", info
);
2651 isdn_tty_at_cout(" Service: ", info
);
2652 switch (info
->last_si
) {
2654 isdn_tty_at_cout("audio\r\n", info
);
2657 isdn_tty_at_cout("btx\r\n", info
);
2660 isdn_tty_at_cout("data\r\n", info
);
2663 sprintf(s
, "%d\r\n", info
->last_si
);
2664 isdn_tty_at_cout(s
, info
);
2667 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
2668 isdn_tty_at_cout(s
, info
);
2669 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
2670 isdn_tty_at_cout(s
, info
);
2674 * Parse AT&.. commands.
2677 isdn_tty_cmd_ATand(char **p
, modem_info
*info
)
2679 atemu
*m
= &info
->emu
;
2683 #define MAXRB (sizeof(rb) - 1)
2687 /* &B - Set Buffersize */
2690 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
2692 #ifdef CONFIG_ISDN_AUDIO
2693 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
2696 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
2697 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2698 switch (m
->mdmreg
[REG_L2PROT
]) {
2699 case ISDN_PROTO_L2_V11096
:
2700 case ISDN_PROTO_L2_V11019
:
2701 case ISDN_PROTO_L2_V11038
:
2702 info
->xmit_size
/= 10;
2706 /* &C - DCD Status */
2708 switch (isdn_getnum(p
)) {
2710 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
2713 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
2720 /* &D - Set DTR-Low-behavior */
2722 switch (isdn_getnum(p
)) {
2724 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
2725 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2728 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2729 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
2732 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
2733 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
2740 /* &E -Set EAZ/MSN */
2742 isdn_tty_get_msnstr(m
->msn
, p
);
2745 /* &F -Set Factory-Defaults */
2747 if (info
->msr
& UART_MSR_DCD
)
2749 isdn_tty_reset_profile(m
);
2750 isdn_tty_modem_reset_regs(info
, 1);
2752 #ifdef DUMMY_HAYES_AT
2754 /* only for be compilant with common scripts */
2755 /* &K Flowcontrol - no function */
2761 /* &L -Set Numbers to listen on */
2764 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
2765 (i
< ISDN_LMSNLEN
- 1))
2766 m
->lmsn
[i
++] = *p
[0]++;
2770 /* &R - Set V.110 bitrate adaption */
2775 /* Switch off V.110, back to X.75 */
2776 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2777 m
->mdmreg
[REG_SI2
] = 0;
2778 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2781 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
2782 m
->mdmreg
[REG_SI2
] = 197;
2783 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2786 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
2787 m
->mdmreg
[REG_SI2
] = 199;
2788 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2791 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
2792 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
2793 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
2798 /* Switch off T.70 */
2799 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2801 m
->mdmreg
[REG_SI1
] |= 4;
2804 /* &S - Set Windowsize */
2807 if ((i
> 0) && (i
< 9))
2808 m
->mdmreg
[REG_WSIZE
] = i
;
2813 /* &V - Show registers */
2815 isdn_tty_at_cout("\r\n", info
);
2816 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
2817 sprintf(rb
, "S%02d=%03d%s", i
,
2818 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
2819 isdn_tty_at_cout(rb
, info
);
2821 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
2822 strlen(m
->msn
) ? m
->msn
: "None");
2823 isdn_tty_at_cout(rb
, info
);
2824 if (strlen(m
->lmsn
)) {
2825 isdn_tty_at_cout("\r\nListen: ", info
);
2826 isdn_tty_at_cout(m
->lmsn
, info
);
2827 isdn_tty_at_cout("\r\n", info
);
2831 /* &W - Write Profile */
2836 modem_write_profile(m
);
2843 /* &X - Switch to BTX-Mode and T.70 */
2845 switch (isdn_getnum(p
)) {
2847 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
2848 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2851 m
->mdmreg
[REG_T70
] |= BIT_T70
;
2852 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
2853 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2854 info
->xmit_size
= 112;
2855 m
->mdmreg
[REG_SI1
] = 4;
2856 m
->mdmreg
[REG_SI2
] = 0;
2859 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
2860 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
2861 info
->xmit_size
= 112;
2862 m
->mdmreg
[REG_SI1
] = 4;
2863 m
->mdmreg
[REG_SI2
] = 0;
2876 isdn_tty_check_ats(int mreg
, int mval
, modem_info
*info
, atemu
*m
)
2878 /* Some plausibility checks */
2881 if (mval
> ISDN_PROTO_L2_MAX
)
2885 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
2887 #ifdef CONFIG_ISDN_AUDIO
2888 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
2891 info
->xmit_size
= mval
* 16;
2892 switch (m
->mdmreg
[REG_L2PROT
]) {
2893 case ISDN_PROTO_L2_V11096
:
2894 case ISDN_PROTO_L2_V11019
:
2895 case ISDN_PROTO_L2_V11038
:
2896 info
->xmit_size
/= 10;
2902 /* readonly registers */
2909 * Perform ATS command
2912 isdn_tty_cmd_ATS(char **p
, modem_info
*info
)
2914 atemu
*m
= &info
->emu
;
2920 mreg
= isdn_getnum(p
);
2921 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
2926 mval
= isdn_getnum(p
);
2927 if (mval
< 0 || mval
> 255)
2929 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
2931 m
->mdmreg
[mreg
] = mval
;
2934 /* Set/Clear a single bit */
2936 bitpos
= isdn_getnum(p
);
2937 if ((bitpos
< 0) || (bitpos
> 7))
2942 bval
= isdn_getnum(p
);
2943 if (bval
< 0 || bval
> 1)
2946 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
2948 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
2949 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
2951 m
->mdmreg
[mreg
] = mval
;
2955 isdn_tty_at_cout("\r\n", info
);
2956 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
2965 isdn_tty_show_profile(mreg
, info
);
2975 * Perform ATA command
2978 isdn_tty_cmd_ATA(modem_info
*info
)
2980 atemu
*m
= &info
->emu
;
2984 if (info
->msr
& UART_MSR_RI
) {
2985 /* Accept incoming call */
2987 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
2988 m
->mdmreg
[REG_RINGCNT
] = 0;
2989 info
->msr
&= ~UART_MSR_RI
;
2990 l2
= m
->mdmreg
[REG_L2PROT
];
2991 #ifdef CONFIG_ISDN_AUDIO
2992 /* If more than one bit set in reg18, autoselect Layer2 */
2993 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
2994 if (m
->mdmreg
[REG_SI1I
] == 1) {
2995 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
2996 l2
= ISDN_PROTO_L2_TRANS
;
2998 l2
= ISDN_PROTO_L2_X75I
;
3001 cmd
.driver
= info
->isdn_driver
;
3002 cmd
.command
= ISDN_CMD_SETL2
;
3003 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
3006 cmd
.driver
= info
->isdn_driver
;
3007 cmd
.command
= ISDN_CMD_SETL3
;
3008 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
3009 #ifdef CONFIG_ISDN_TTY_FAX
3010 if (l2
== ISDN_PROTO_L2_FAX
) {
3011 cmd
.parm
.fax
= info
->fax
;
3012 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3016 cmd
.driver
= info
->isdn_driver
;
3017 cmd
.arg
= info
->isdn_channel
;
3018 cmd
.command
= ISDN_CMD_ACCEPTD
;
3020 info
->emu
.carrierwait
= 0;
3022 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3024 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3027 #ifdef CONFIG_ISDN_AUDIO
3029 * Parse AT+F.. commands
3032 isdn_tty_cmd_PLUSF(char **p
, modem_info
*info
)
3034 atemu
*m
= &info
->emu
;
3037 if (!strncmp(p
[0], "CLASS", 5)) {
3042 sprintf(rs
, "\r\n%d",
3043 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3044 #ifdef CONFIG_ISDN_TTY_FAX
3045 if (TTY_IS_FCLASS2(info
))
3046 sprintf(rs
, "\r\n2");
3047 else if (TTY_IS_FCLASS1(info
))
3048 sprintf(rs
, "\r\n1");
3050 isdn_tty_at_cout(rs
, info
);
3057 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3058 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3059 m
->mdmreg
[REG_SI1
] = 4;
3061 m
->mdmreg
[REG_PSIZE
] * 16;
3063 #ifdef CONFIG_ISDN_TTY_FAX
3066 if (!(dev
->global_features
&
3067 ISDN_FEATURE_L3_FCLASS1
))
3069 m
->mdmreg
[REG_SI1
] = 1;
3070 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3071 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3073 m
->mdmreg
[REG_PSIZE
] * 16;
3077 if (!(dev
->global_features
&
3078 ISDN_FEATURE_L3_FCLASS2
))
3080 m
->mdmreg
[REG_SI1
] = 1;
3081 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3082 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3084 m
->mdmreg
[REG_PSIZE
] * 16;
3089 /* L2 will change on dialout with si=1 */
3090 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3091 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3092 m
->mdmreg
[REG_SI1
] = 5;
3093 info
->xmit_size
= VBUF
;
3097 strcpy(rs
, "\r\n0,");
3098 #ifdef CONFIG_ISDN_TTY_FAX
3099 if (dev
->global_features
&
3100 ISDN_FEATURE_L3_FCLASS1
)
3102 if (dev
->global_features
&
3103 ISDN_FEATURE_L3_FCLASS2
)
3107 isdn_tty_at_cout(rs
, info
);
3118 #ifdef CONFIG_ISDN_TTY_FAX
3119 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3126 * Parse AT+V.. commands
3129 isdn_tty_cmd_PLUSV(char **p
, modem_info
*info
)
3131 atemu
*m
= &info
->emu
;
3133 static char *vcmd
[] =
3134 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3142 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3150 /* AT+VNH - Auto hangup feature */
3154 isdn_tty_at_cout("\r\n1", info
);
3164 isdn_tty_at_cout("\r\n1", info
);
3175 /* AT+VIP - Reset all voice parameters */
3176 isdn_tty_modem_reset_vpar(m
);
3179 /* AT+VLS - Select device, accept incoming call */
3183 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3184 isdn_tty_at_cout(rs
, info
);
3199 isdn_tty_at_cout("\r\n0,2", info
);
3210 /* AT+VRX - Start recording */
3213 if (info
->online
!= 1) {
3214 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3217 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3218 if (!info
->dtmf_state
) {
3219 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3222 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3223 if (!info
->silence_state
) {
3224 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3227 if (m
->vpar
[3] < 5) {
3228 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3229 if (!info
->adpcmr
) {
3230 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3234 #ifdef ISDN_DEBUG_AT
3235 printk(KERN_DEBUG
"AT: +VRX\n");
3238 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3242 /* AT+VSD - Silence detection */
3246 sprintf(rs
, "\r\n<%d>,<%d>",
3249 isdn_tty_at_cout(rs
, info
);
3253 if ((*p
[0] >= '0') && (*p
[0] <= '9')) {
3254 par1
= isdn_getnum(p
);
3255 if ((par1
< 0) || (par1
> 31))
3260 par2
= isdn_getnum(p
);
3261 if ((par2
< 0) || (par2
> 255))
3269 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3280 /* AT+VSM - Select compression */
3284 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3287 isdn_tty_at_cout(rs
, info
);
3297 par1
= isdn_getnum(p
);
3298 if ((par1
< 2) || (par1
> 6))
3304 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3306 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3308 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3310 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3312 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3324 /* AT+VTX - Start sending */
3327 if (info
->online
!= 1) {
3328 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3331 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3332 if (!info
->dtmf_state
) {
3333 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3336 if (m
->vpar
[3] < 5) {
3337 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3338 if (!info
->adpcms
) {
3339 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3343 #ifdef ISDN_DEBUG_AT
3344 printk(KERN_DEBUG
"AT: +VTX\n");
3348 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3352 /* AT+VDD - DTMF detection */
3356 sprintf(rs
, "\r\n<%d>,<%d>",
3359 isdn_tty_at_cout(rs
, info
);
3363 if ((*p
[0] >= '0') && (*p
[0] <= '9')) {
3364 if (info
->online
!= 1)
3366 par1
= isdn_getnum(p
);
3367 if ((par1
< 0) || (par1
> 15))
3372 par2
= isdn_getnum(p
);
3373 if ((par2
< 0) || (par2
> 255))
3377 cmd
.driver
= info
->isdn_driver
;
3378 cmd
.command
= ISDN_CMD_AUDIO
;
3379 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3380 cmd
.parm
.num
[0] = par1
;
3381 cmd
.parm
.num
[1] = par2
;
3387 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3402 #endif /* CONFIG_ISDN_AUDIO */
3405 * Parse and perform an AT-command-line.
3408 isdn_tty_parse_at(modem_info
*info
)
3410 atemu
*m
= &info
->emu
;
3412 char ds
[ISDN_MSNLEN
];
3414 #ifdef ISDN_DEBUG_AT
3415 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
3417 for (p
= &m
->mdmcmd
[2]; *p
;) {
3423 /* A - Accept incoming call */
3425 isdn_tty_cmd_ATA(info
);
3429 if (info
->msr
& UART_MSR_DCD
)
3431 if (info
->msr
& UART_MSR_RI
) {
3432 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3435 isdn_tty_getdial(++p
, ds
, sizeof ds
);
3437 if (!strlen(m
->msn
))
3438 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
3439 else if (strlen(ds
))
3440 isdn_tty_dial(ds
, info
, m
);
3445 /* E - Turn Echo on/off */
3447 switch (isdn_getnum(&p
)) {
3449 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
3452 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
3459 /* H - On/Off-hook */
3464 isdn_tty_on_hook(info
);
3468 isdn_tty_off_hook();
3471 isdn_tty_on_hook(info
);
3476 /* I - Information */
3478 isdn_tty_at_cout("\r\nLinux ISDN", info
);
3486 isdn_tty_report(info
);
3490 snprintf(ds
, sizeof(ds
), "\r\n%d", info
->emu
.charge
);
3491 isdn_tty_at_cout(ds
, info
);
3496 #ifdef DUMMY_HAYES_AT
3499 /* only for be compilant with common scripts */
3508 if (info
->msr
& UART_MSR_DCD
)
3509 /* if B-Channel is up */
3510 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
: RESULT_CONNECT64000
, info
);
3512 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3515 /* Q - Turn Emulator messages on/off */
3517 switch (isdn_getnum(&p
)) {
3519 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
3522 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
3529 /* S - Set/Get Register */
3531 if (isdn_tty_cmd_ATS(&p
, info
))
3535 /* V - Numeric or ASCII Emulator-messages */
3537 switch (isdn_getnum(&p
)) {
3539 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
3542 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
3549 /* Z - Load Registers from Profile */
3551 if (info
->msr
& UART_MSR_DCD
) {
3553 isdn_tty_on_hook(info
);
3555 isdn_tty_modem_reset_regs(info
, 1);
3560 #ifdef CONFIG_ISDN_AUDIO
3563 if (isdn_tty_cmd_PLUSF(&p
, info
))
3567 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
3568 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
3571 if (isdn_tty_cmd_PLUSV(&p
, info
))
3574 #endif /* CONFIG_ISDN_AUDIO */
3575 case 'S': /* SUSPEND */
3577 isdn_tty_get_msnstr(ds
, &p
);
3578 isdn_tty_suspend(ds
, info
, m
);
3580 case 'R': /* RESUME */
3582 isdn_tty_get_msnstr(ds
, &p
);
3583 isdn_tty_resume(ds
, info
, m
);
3585 case 'M': /* MESSAGE */
3587 isdn_tty_send_msg(info
, m
, p
);
3595 if (isdn_tty_cmd_ATand(&p
, info
))
3602 #ifdef CONFIG_ISDN_AUDIO
3605 isdn_tty_modem_result(RESULT_OK
, info
);
3608 /* Need own toupper() because standard-toupper is not available
3611 #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c)
3614 * Perform line-editing of AT-commands
3618 * count length of buffer
3619 * channel index to line (minor-device)
3622 isdn_tty_edit_at(const char *p
, int count
, modem_info
*info
)
3624 atemu
*m
= &info
->emu
;
3630 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
3633 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
3634 /* Separator (CR or LF) */
3635 m
->mdmcmd
[m
->mdmcmdl
] = 0;
3636 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3639 isdn_tty_at_cout(eb
, info
);
3641 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
3642 isdn_tty_parse_at(info
);
3646 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
3647 /* Backspace-Function */
3648 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
3651 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
3652 isdn_tty_at_cout("\b", info
);
3657 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
3660 isdn_tty_at_cout(eb
, info
);
3662 if (m
->mdmcmdl
< 255) {
3664 switch (m
->mdmcmdl
) {
3667 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3668 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3672 /* Fall through, check for 'A' */
3675 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3676 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3680 m
->mdmcmd
[m
->mdmcmdl
] = c
;
3681 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
3690 * Switch all modem-channels who are online and got a valid
3691 * escape-sequence 1.5 seconds ago, to command-mode.
3692 * This function is called every second via timer-interrupt from within
3693 * timer-dispatcher isdn_timer_function()
3696 isdn_tty_modem_escape(void)
3702 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
3703 if (USG_MODEM(dev
->usage
[i
]) && (midx
= dev
->m_idx
[i
]) >= 0) {
3704 modem_info
*info
= &dev
->mdm
.info
[midx
];
3707 if ((info
->emu
.pluscount
== 3) &&
3709 info
->emu
.lastplus
+ PLUSWAIT2
)) {
3710 info
->emu
.pluscount
= 0;
3712 isdn_tty_modem_result(RESULT_OK
, info
);
3716 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
3720 * Put a RING-message to all modem-channels who have the RI-bit set.
3721 * This function is called every second via timer-interrupt from within
3722 * timer-dispatcher isdn_timer_function()
3725 isdn_tty_modem_ring(void)
3730 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3731 modem_info
*info
= &dev
->mdm
.info
[i
];
3732 if (info
->msr
& UART_MSR_RI
) {
3734 isdn_tty_modem_result(RESULT_RING
, info
);
3737 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
3741 * For all online tty's, try sending data to
3745 isdn_tty_modem_xmit(void)
3750 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3751 modem_info
*info
= &dev
->mdm
.info
[i
];
3754 isdn_tty_senddown(info
);
3755 isdn_tty_tint(info
);
3758 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
3762 * Check all channels if we have a 'no carrier' timeout.
3763 * Timeout value is set by Register S7.
3766 isdn_tty_carrier_timeout(void)
3771 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
3772 modem_info
*info
= &dev
->mdm
.info
[i
];
3775 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
3777 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
3778 isdn_tty_modem_hup(info
, 1);
3782 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);