1 /* $Id: isdn_tty.c,v 1.84 2000/02/16 15:10:14 paul Exp $
3 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
6 * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * $Log: isdn_tty.c,v $
23 * Revision 1.84 2000/02/16 15:10:14 paul
24 * If a ttyI has no open FDs, don't connect incoming calls to it.
25 * (Hangup on close of last FD is still to be done.)
27 * Revision 1.83 2000/02/16 14:59:33 paul
28 * translated ISDN_MODEM_ANZREG to ISDN_MODEM_NUMREG for english speakers;
29 * used defines for result codes;
30 * fixed RING ... RUNG problem (no empty lines in between).
32 * Revision 1.82 2000/01/23 18:45:37 keil
33 * Change EAZ mapping to forbit the use of cards (insert a "-" for the MSN)
35 * Revision 1.81 2000/01/20 19:55:33 keil
36 * Add FAX Class 1 support
38 * Revision 1.80 1999/11/07 13:34:30 armin
39 * Fixed AT command line editor
41 * Revision 1.79 1999/10/29 18:35:08 armin
42 * Check number len in isdn_get_msnstr() to avoid buffer overflow.
44 * Revision 1.78 1999/10/28 23:03:51 armin
45 * Bugfix: now freeing channel on modem_hup() even when
46 * usage on ttyI has changed and error-report for
47 * AT-commands on wrong channel-state.
49 * Revision 1.77 1999/10/26 21:13:14 armin
50 * using define for checking phone number len in isdn_tty_getdial()
52 * Revision 1.76 1999/10/11 22:16:26 keil
53 * Suspend/Resume is possible without explicit ID too
55 * Revision 1.75 1999/10/08 18:59:32 armin
56 * Bugfix of too small MSN buffer and checking phone number
57 * in isdn_tty_getdial()
59 * Revision 1.74 1999/09/04 06:20:04 keil
60 * Changes from kernel set_current_state()
62 * Revision 1.73 1999/08/28 21:56:27 keil
63 * misplaced #endif caused ttyI crash in 2.3.X
65 * Revision 1.72 1999/07/31 12:59:45 armin
66 * Added tty fax capabilities.
68 * Revision 1.71 1999/07/27 10:34:34 armin
69 * Fixed last change. Did not compile with AUDIO support off.
71 * Revision 1.70 1999/07/25 16:17:58 keil
74 * Revision 1.69 1999/07/25 12:56:15 armin
75 * isdn_tty_at_cout() now queues the message if online and
76 * data is in queue or flip buffer is full.
77 * needed for fax connections.
79 * Revision 1.68 1999/07/11 17:51:51 armin
80 * Bugfix, "-" was missing for AT&L settings.
82 * Revision 1.67 1999/07/11 17:14:12 armin
83 * Added new layer 2 and 3 protocols for Fax and DSP functions.
84 * Moved "Add CPN to RING message" to new register S23,
85 * "Display message" is now correct on register S13 bit 7.
86 * New audio command AT+VDD implemented (deactivate DTMF decoder and
87 * activate possible existing hardware/DSP decoder).
88 * Moved some tty defines to .h file.
89 * Made whitespace possible in AT command line.
90 * Some AT-emulator output bugfixes.
91 * First Fax G3 implementations.
93 * Revision 1.66 1999/07/07 10:13:46 detabc
94 * remove unused messages
96 * Revision 1.65 1999/07/04 21:01:59 werner
97 * Added support for keypad and display (ported from 2.0)
99 * Revision 1.64 1999/07/01 08:30:00 keil
100 * compatibility to 2.3 kernel
102 * Revision 1.63 1999/04/12 12:33:39 fritz
103 * Changes from 2.0 tree.
105 * Revision 1.62 1999/03/02 12:04:48 armin
106 * -added ISDN_STAT_ADDCH to increase supported channels after
108 * -ttyI now goes on-hook on ATZ when B-Ch is connected.
109 * -added timer-function for register S7 (Wait for Carrier).
110 * -analog modem (ISDN_PROTO_L2_MODEM) implementations.
111 * -on L2_MODEM a string will be appended to the CONNECT-Message,
112 * which is provided by the HL-Driver in parm.num in ISDN_STAT_BCONN.
113 * -variable "dialing" used for ATA also, for interrupting call
114 * establishment and register S7.
116 * Revision 1.61 1999/01/27 22:53:11 he
117 * minor updates (spellings, jiffies wrap around in isdn_tty)
119 * Revision 1.60 1998/11/15 23:57:32 keil
120 * changes for 2.1.127
122 * Revision 1.59 1998/08/20 13:50:15 keil
123 * More support for hybrid modem (not working yet)
125 * Revision 1.58 1998/07/26 18:48:45 armin
126 * Added silence detection in voice receive mode.
128 * Revision 1.57 1998/06/26 15:12:36 fritz
129 * Added handling of STAT_ICALL with incomplete CPN.
130 * Added AT&L for ttyI emulator.
131 * Added more locking stuff in tty_write.
133 * Revision 1.56 1998/06/18 23:31:51 fritz
134 * Replaced cli()/restore_flags() in isdn_tty_write() by locking.
135 * Removed direct-senddown feature in isdn_tty_write because it will
136 * never succeed with locking and is useless anyway.
138 * Revision 1.55 1998/06/17 19:50:55 he
139 * merged with 2.1.10[34] (cosmetics and udelay() -> mdelay())
140 * brute force fix to avoid Ugh's in isdn_tty_write()
141 * cleaned up some dead code
145 * Revision 1.52 1998/03/19 13:18:21 keil
146 * Start of a CAPI like interface for supplementary Service
147 * first service: SUSPEND
150 * Revision 1.49 1998/03/08 00:01:59 fritz
151 * Bugfix: Lowlevel module usage and channel usage were not
152 * reset on NO DCHANNEL.
154 * Revision 1.48 1998/03/07 12:28:15 tsbogend
155 * fixed kernel unaligned traps on Linux/Alpha
157 * Revision 1.47 1998/02/22 19:44:14 fritz
158 * Bugfixes and improvements regarding V.110, V.110 now running.
160 * Revision 1.46 1998/02/20 17:23:08 fritz
161 * Changes for recent kernels.
162 * Merged in contributions by Thomas Pfeiffer (V.110 T.70+ Extended FAX stuff)
163 * Added symbolic constants for Modem-Registers.
165 * Revision 1.45 1998/01/31 22:07:49 keil
166 * changes for newer kernels
168 * Revision 1.44 1998/01/31 19:30:02 calle
169 * Merged changes from and for 2.1.82, not tested only compiled ...
171 * Revision 1.43 1997/10/09 21:29:04 fritz
172 * New HL<->LL interface:
173 * New BSENT callback with nr. of bytes included.
174 * Sending without ACK.
175 * New L1 error status (not yet in use).
176 * Cleaned up obsolete structures.
177 * Implemented Cisco-SLARP.
178 * Changed local net-interface data to be dynamically allocated.
179 * Removed old 2.0 compatibility stuff.
181 * Revision 1.42 1997/10/01 09:20:49 fritz
182 * Removed old compatibility stuff for 2.0.X kernels.
183 * From now on, this code is for 2.1.X ONLY!
184 * Old stuff is still in the separate branch.
186 * Revision 1.41 1997/05/27 15:17:31 fritz
187 * Added changes for recent 2.1.x kernels:
188 * changed return type of isdn_close
189 * queue_task_* -> queue_task
190 * clear/set_bit -> test_and_... where apropriate.
191 * changed type of hard_header_cache parameter.
193 * Revision 1.40 1997/03/24 22:55:27 fritz
194 * Added debug code for status callbacks.
196 * Revision 1.39 1997/03/21 18:25:56 fritz
197 * Corrected CTS handling.
199 * Revision 1.38 1997/03/07 12:13:35 fritz
200 * Bugfix: Send audio in adpcm format was broken.
201 * Bugfix: CTS handling was wrong.
203 * Revision 1.37 1997/03/07 01:37:34 fritz
204 * Bugfix: Did not compile with CONFIG_ISDN_AUDIO disabled.
205 * Bugfix: isdn_tty_tint() did not handle lowlevel errors correctly.
206 * Bugfix: conversion was wrong when sending ulaw audio.
207 * Added proper ifdef's for CONFIG_ISDN_AUDIO
209 * Revision 1.36 1997/03/04 21:41:55 fritz
210 * Fix: Excessive stack usage of isdn_tty_senddown()
211 * and isdn_tty_end_vrx() could lead to problems.
213 * Revision 1.35 1997/03/02 19:05:52 fritz
214 * Bugfix: Avoid recursion.
216 * Revision 1.34 1997/03/02 14:29:22 fritz
217 * More ttyI related cleanup.
219 * Revision 1.33 1997/02/28 02:32:45 fritz
220 * Cleanup: Moved some tty related stuff from isdn_common.c
222 * Bugfix: Bisync protocol did not behave like documented.
224 * Revision 1.32 1997/02/23 15:43:03 fritz
225 * Small change in handling of incoming calls
226 * documented in newest version of ttyI.4
228 * Revision 1.31 1997/02/21 13:05:57 fritz
229 * Bugfix: Remote hangup did not set location-info on ttyI's
231 * Revision 1.30 1997/02/18 09:41:05 fritz
232 * Added support for bitwise access to modem registers (ATSx.y=n, ATSx.y?).
233 * Beautified output of AT&V.
235 * Revision 1.29 1997/02/16 12:11:51 fritz
236 * Added S13,Bit4 option.
238 * Revision 1.28 1997/02/10 22:07:08 fritz
239 * Added 2 modem registers for numbering plan and screening info.
241 * Revision 1.27 1997/02/10 21:31:14 fritz
242 * Changed setup-interface (incoming and outgoing).
244 * Revision 1.26 1997/02/10 20:12:48 fritz
245 * Changed interface for reporting incoming calls.
247 * Revision 1.25 1997/02/03 23:04:30 fritz
248 * Reformatted according CodingStyle.
249 * skb->free stuff replaced by macro.
250 * Finished full-duplex audio.
252 * Revision 1.24 1997/01/14 01:32:42 fritz
253 * Changed audio receive not to rely on skb->users and skb->lock.
254 * Added ATI2 and related variables.
255 * Started adding full-duplex audio capability.
257 * Revision 1.23 1996/10/22 23:14:02 fritz
258 * Changes for compatibility to 2.0.X and 2.1.X kernels.
260 * Revision 1.22 1996/10/19 18:56:43 fritz
261 * ATZ did not change the xmitbuf size.
263 * Revision 1.21 1996/06/24 17:40:28 fritz
264 * Bugfix: Did not compile without CONFIG_ISDN_AUDIO
266 * Revision 1.20 1996/06/15 14:59:39 fritz
267 * Fixed isdn_tty_tint() to handle partially sent
270 * Revision 1.19 1996/06/12 15:53:56 fritz
271 * Bugfix: AT+VTX and AT+VRX could be executed without
272 * having a connection.
273 * Missing check for NULL tty in isdn_tty_flush_buffer().
275 * Revision 1.18 1996/06/07 11:17:33 tsbogend
276 * added missing #ifdef CONFIG_ISDN_AUDIO to make compiling without
277 * audio support possible
279 * Revision 1.17 1996/06/06 14:55:47 fritz
280 * Changed to support DTMF decoding on audio playback also.
281 * Bugfix: Added check for invalid info->isdn_driver in
282 * isdn_tty_senddown().
283 * Clear ncarrier flag on last close() of a tty.
285 * Revision 1.16 1996/06/05 02:24:12 fritz
286 * Added DTMF decoder for audio mode.
288 * Revision 1.15 1996/06/03 20:35:01 fritz
291 * Revision 1.14 1996/06/03 20:12:19 fritz
293 * Added call to write_wakeup via isdn_tty_flush_buffer()
294 * in isdn_tty_modem_hup().
296 * Revision 1.13 1996/05/31 01:33:29 fritz
297 * Changed buffering due to bad performance with mgetty.
298 * Now sk_buff is delayed allocated in isdn_tty_senddown
299 * using xmit_buff like in standard serial driver.
300 * Fixed module locking.
301 * Added DLE-DC4 handling in voice mode.
303 * Revision 1.12 1996/05/19 01:34:40 fritz
304 * Bugfix: ATS returned error.
305 * Register 20 made readonly.
307 * Revision 1.11 1996/05/18 01:37:03 fritz
308 * Added spelling corrections and some minor changes
309 * to stay in sync with kernel.
311 * Revision 1.10 1996/05/17 03:51:49 fritz
312 * Changed DLE handling for audio receive.
314 * Revision 1.9 1996/05/11 21:52:07 fritz
315 * Changed queue management to use sk_buffs.
317 * Revision 1.8 1996/05/10 08:49:43 fritz
318 * Checkin before major changes of tty-code.
320 * Revision 1.7 1996/05/07 09:15:09 fritz
321 * Reorganized and general cleanup.
323 * - Audio-transmit working now.
324 * - "NO CARRIER" now reported, when hanging up with DTR low.
325 * - Corrected CTS handling.
327 * Revision 1.6 1996/05/02 03:59:25 fritz
329 * - On dialout, layer-2 setup had been incomplete
330 * when using new auto-layer2 feature.
331 * - On hangup, "NO CARRIER" message sometimes missing.
333 * Revision 1.5 1996/04/30 21:05:25 fritz
336 * Revision 1.4 1996/04/20 16:39:54 fritz
337 * Changed all io to go through generic routines in isdn_common.c
338 * Fixed a real ugly bug in modem-emulator: 'ATA' had been accepted
339 * even when a call has been cancelled from the remote machine.
341 * Revision 1.3 1996/02/11 02:12:32 fritz
342 * Bugfixes according to similar fixes in standard serial.c of kernel.
344 * Revision 1.2 1996/01/22 05:12:25 fritz
345 * replaced my_atoi by simple_strtoul
347 * Revision 1.1 1996/01/09 04:13:18 fritz
351 #undef ISDN_TTY_STAT_DEBUG
353 #define __NO_VERSION__
354 #include <linux/config.h>
355 #include <linux/module.h>
356 #include <linux/isdn.h>
357 #include "isdn_common.h"
358 #include "isdn_tty.h"
359 #ifdef CONFIG_ISDN_AUDIO
360 #include "isdn_audio.h"
362 #define VBUFX (VBUF/16)
365 #define FIX_FILE_TRANSFER
366 #define DUMMY_HAYES_AT
370 static int isdn_tty_edit_at(const char *, int, modem_info
*, int);
371 static void isdn_tty_check_esc(const u_char
*, u_char
, int, int *, int *, int);
372 static void isdn_tty_modem_reset_regs(modem_info
*, int);
373 static void isdn_tty_cmd_ATA(modem_info
*);
374 static void isdn_tty_flush_buffer(struct tty_struct
*);
375 static void isdn_tty_modem_result(int, modem_info
*);
376 #ifdef CONFIG_ISDN_AUDIO
377 static int isdn_tty_countDLE(unsigned char *, int);
380 /* Leave this unchanged unless you know what you do! */
381 #define MODEM_PARANOIA_CHECK
382 #define MODEM_DO_RESTART
384 #ifdef CONFIG_DEVFS_FS
385 static char *isdn_ttyname_ttyI
= "isdn/ttyI%d";
386 static char *isdn_ttyname_cui
= "isdn/cui%d";
388 static char *isdn_ttyname_ttyI
= "ttyI";
389 static char *isdn_ttyname_cui
= "cui";
392 static int bit2si
[8] =
393 {1, 5, 7, 7, 7, 7, 7, 7};
394 static int si2bit
[8] =
395 {4, 1, 4, 4, 4, 4, 4, 4};
397 char *isdn_tty_revision
= "$Revision: 1.84 $";
400 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
401 * to stuff incoming data directly into a tty's flip-buffer. This
402 * is done to speed up tty-receiving if the receive-queue is empty.
403 * This routine MUST be called with interrupts off.
406 * 0 = Failure, data has to be buffered and later processed by
407 * isdn_tty_readmodem().
410 isdn_tty_try_read(modem_info
* info
, struct sk_buff
*skb
)
414 struct tty_struct
*tty
;
417 if ((tty
= info
->tty
)) {
418 if (info
->mcr
& UART_MCR_RTS
) {
419 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
421 #ifdef CONFIG_ISDN_AUDIO
422 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
426 #ifdef CONFIG_ISDN_AUDIO
427 if (ISDN_AUDIO_SKB_DLECOUNT(skb
))
429 if (*skb
->data
== DLE
)
430 tty_insert_flip_char(tty
, DLE
, 0);
431 tty_insert_flip_char(tty
, *skb
->data
++, 0);
434 memcpy(tty
->flip
.char_buf_ptr
,
436 tty
->flip
.count
+= len
;
437 tty
->flip
.char_buf_ptr
+= len
;
438 memset(tty
->flip
.flag_buf_ptr
, 0, len
);
439 tty
->flip
.flag_buf_ptr
+= len
;
440 #ifdef CONFIG_ISDN_AUDIO
443 if (info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
)
444 tty
->flip
.flag_buf_ptr
[len
- 1] = 0xff;
445 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
455 /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
456 * It tries getting received data from the receive queue an stuff it into
457 * the tty's flip-buffer.
460 isdn_tty_readmodem(void)
468 struct tty_struct
*tty
;
471 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
472 if ((midx
= dev
->m_idx
[i
]) >= 0) {
473 info
= &dev
->mdm
.info
[midx
];
476 #ifdef CONFIG_ISDN_AUDIO
477 isdn_audio_eval_dtmf(info
);
478 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
479 isdn_audio_eval_silence(info
);
481 if ((tty
= info
->tty
)) {
482 if (info
->mcr
& UART_MCR_RTS
) {
483 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
487 r
= isdn_readbchan(info
->isdn_driver
, info
->isdn_channel
,
488 tty
->flip
.char_buf_ptr
,
489 tty
->flip
.flag_buf_ptr
, c
, 0);
490 /* CISCO AsyncPPP Hack */
491 if (!(info
->emu
.mdmreg
[REG_CPPP
] & BIT_CPPP
))
492 memset(tty
->flip
.flag_buf_ptr
, 0, r
);
493 tty
->flip
.count
+= r
;
494 tty
->flip
.flag_buf_ptr
+= r
;
495 tty
->flip
.char_buf_ptr
+= r
;
497 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
498 restore_flags(flags
);
513 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 0);
517 isdn_tty_rcv_skb(int i
, int di
, int channel
, struct sk_buff
*skb
)
521 #ifdef CONFIG_ISDN_AUDIO
526 if ((midx
= dev
->m_idx
[i
]) < 0) {
527 /* if midx is invalid, packet is not for tty */
530 info
= &dev
->mdm
.info
[midx
];
531 #ifdef CONFIG_ISDN_AUDIO
534 if ((info
->vonline
) && (!info
->emu
.vpar
[4]))
535 isdn_audio_calc_dtmf(info
, skb
->data
, skb
->len
, ifmt
);
536 if ((info
->vonline
& 1) && (info
->emu
.vpar
[1]))
537 isdn_audio_calc_silence(info
, skb
->data
, skb
->len
, ifmt
);
539 if ((info
->online
< 2)
540 #ifdef CONFIG_ISDN_AUDIO
541 && (!(info
->vonline
& 1))
544 /* If Modem not listening, drop data */
548 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
549 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
) {
550 /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
551 if (skb
->data
[0] == 3) /* pure data packet -> 4 byte headers */
554 if (skb
->data
[0] == 1) /* keepalive packet -> 2 byte hdr */
557 /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
558 if ((skb
->data
[0] == 1) && ((skb
->data
[1] == 0) || (skb
->data
[1] == 1)))
561 #ifdef CONFIG_ISDN_AUDIO
562 if (skb_headroom(skb
) < sizeof(isdn_audio_skb
)) {
564 "isdn_audio: insufficient skb_headroom, dropping\n");
568 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
569 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
570 if (info
->vonline
& 1) {
571 /* voice conversion/compression */
572 switch (info
->emu
.vpar
[3]) {
577 * Since compressed data takes less
578 * space, we can overwrite the buffer.
580 skb_trim(skb
, isdn_audio_xlaw2adpcm(info
->adpcmr
,
589 isdn_audio_ulaw2alaw(skb
->data
, skb
->len
);
594 isdn_audio_alaw2ulaw(skb
->data
, skb
->len
);
597 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
598 isdn_tty_countDLE(skb
->data
, skb
->len
);
600 #ifdef CONFIG_ISDN_TTY_FAX
602 if (info
->faxonline
& 2) {
603 isdn_tty_fax_bitorder(info
, skb
);
604 ISDN_AUDIO_SKB_DLECOUNT(skb
) =
605 isdn_tty_countDLE(skb
->data
, skb
->len
);
610 /* Try to deliver directly via tty-flip-buf if queue is empty */
613 if (skb_queue_empty(&dev
->drv
[di
]->rpqueue
[channel
]))
614 if (isdn_tty_try_read(info
, skb
)) {
615 restore_flags(flags
);
618 /* Direct deliver failed or queue wasn't empty.
619 * Queue up for later dequeueing via timer-irq.
621 __skb_queue_tail(&dev
->drv
[di
]->rpqueue
[channel
], skb
);
622 dev
->drv
[di
]->rcvcount
[channel
] +=
624 #ifdef CONFIG_ISDN_AUDIO
625 + ISDN_AUDIO_SKB_DLECOUNT(skb
)
628 restore_flags(flags
);
629 /* Schedule dequeuing */
630 if ((dev
->modempoll
) && (info
->rcvsched
))
631 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
636 isdn_tty_cleanup_xmit(modem_info
* info
)
643 if (skb_queue_len(&info
->xmit_queue
))
644 while ((skb
= skb_dequeue(&info
->xmit_queue
)))
646 #ifdef CONFIG_ISDN_AUDIO
647 if (skb_queue_len(&info
->dtmf_queue
))
648 while ((skb
= skb_dequeue(&info
->dtmf_queue
)))
651 restore_flags(flags
);
655 isdn_tty_tint(modem_info
* info
)
657 struct sk_buff
*skb
= skb_dequeue(&info
->xmit_queue
);
664 if ((slen
= isdn_writebuf_skb_stub(info
->isdn_driver
,
665 info
->isdn_channel
, 1, skb
)) == len
) {
666 struct tty_struct
*tty
= info
->tty
;
667 info
->send_outstanding
++;
668 info
->msr
&= ~UART_MSR_CTS
;
669 info
->lsr
&= ~UART_LSR_TEMT
;
670 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
671 tty
->ldisc
.write_wakeup
)
672 (tty
->ldisc
.write_wakeup
) (tty
);
673 wake_up_interruptible(&tty
->write_wait
);
677 /* Error: no channel, already shutdown, or wrong parameter */
681 skb_queue_head(&info
->xmit_queue
, skb
);
684 #ifdef CONFIG_ISDN_AUDIO
686 isdn_tty_countDLE(unsigned char *buf
, int len
)
696 /* This routine is called from within isdn_tty_write() to perform
697 * DLE-decoding when sending audio-data.
700 isdn_tty_handleDLEdown(modem_info
* info
, atemu
* m
, int len
)
702 unsigned char *p
= &info
->xmit_buf
[info
->xmit_count
];
712 memmove(p
, p
+ 1, len
- 1);
723 #ifdef ISDN_DEBUG_MODEM_VOICE
725 "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
728 isdn_tty_at_cout("\020\003", info
);
729 if (!info
->vonline
) {
730 #ifdef ISDN_DEBUG_MODEM_VOICE
732 "DLEdown: send VCON on ttyI%d\n",
735 isdn_tty_at_cout("\r\nVCON\r\n", info
);
742 memmove(p
, p
+ 1, len
- 1);
756 printk(KERN_WARNING
"isdn_tty: len<0 in DLEdown\n");
762 /* This routine is called from within isdn_tty_write() when receiving
763 * audio-data. It interrupts receiving, if an character other than
767 isdn_tty_end_vrx(const char *buf
, int c
, int from_user
)
776 if ((ch
!= 0x11) && (ch
!= 0x13))
783 static int voice_cf
[7] =
784 {0, 0, 4, 3, 2, 0, 0};
786 #endif /* CONFIG_ISDN_AUDIO */
788 /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
789 * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
790 * outgoing data from the tty's xmit-buffer, handles voice-decompression or
791 * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
794 isdn_tty_senddown(modem_info
* info
)
798 #ifdef CONFIG_ISDN_AUDIO
803 #ifdef CONFIG_ISDN_AUDIO
804 if (info
->vonline
& 4) {
806 if (!info
->vonline
) {
807 #ifdef ISDN_DEBUG_MODEM_VOICE
809 "senddown: send VCON on ttyI%d\n",
812 isdn_tty_at_cout("\r\nVCON\r\n", info
);
816 if (!(buflen
= info
->xmit_count
))
818 if ((info
->emu
.mdmreg
[REG_CTS
] & BIT_CTS
) != 0)
819 info
->msr
&= ~UART_MSR_CTS
;
820 info
->lsr
&= ~UART_LSR_TEMT
;
821 /* info->xmit_count is modified here and in isdn_tty_write().
822 * So we return here if isdn_tty_write() is in the
825 atomic_inc(&info
->xmit_lock
);
826 if (!(atomic_dec_and_test(&info
->xmit_lock
)))
828 if (info
->isdn_driver
< 0) {
829 info
->xmit_count
= 0;
832 skb_res
= dev
->drv
[info
->isdn_driver
]->interface
->hl_hdrlen
+ 4;
833 #ifdef CONFIG_ISDN_AUDIO
834 if (info
->vonline
& 2)
835 audio_len
= buflen
* voice_cf
[info
->emu
.vpar
[3]];
838 skb
= dev_alloc_skb(skb_res
+ buflen
+ audio_len
);
840 skb
= dev_alloc_skb(skb_res
+ buflen
);
844 "isdn_tty: Out of memory in ttyI%d senddown\n",
848 skb_reserve(skb
, skb_res
);
849 memcpy(skb_put(skb
, buflen
), info
->xmit_buf
, buflen
);
850 info
->xmit_count
= 0;
851 #ifdef CONFIG_ISDN_AUDIO
852 if (info
->vonline
& 2) {
853 /* For now, ifmt is fixed to 1 (alaw), since this
854 * is used with ISDN everywhere in the world, except
855 * US, Canada and Japan.
856 * Later, when US-ISDN protocols are implemented,
857 * this setting will depend on the D-channel protocol.
861 /* voice conversion/decompression */
862 switch (info
->emu
.vpar
[3]) {
866 /* adpcm, compatible to ZyXel 1496 modem
867 * with ROM revision 6.01
869 audio_len
= isdn_audio_adpcm2xlaw(info
->adpcms
,
872 skb_put(skb
, audio_len
),
874 skb_pull(skb
, buflen
);
875 skb_trim(skb
, audio_len
);
880 isdn_audio_alaw2ulaw(skb
->data
,
886 isdn_audio_ulaw2alaw(skb
->data
,
891 #endif /* CONFIG_ISDN_AUDIO */
892 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70
) {
893 /* Add T.70 simplified header */
894 if (info
->emu
.mdmreg
[REG_T70
] & BIT_T70_EXT
)
895 memcpy(skb_push(skb
, 2), "\1\0", 2);
897 memcpy(skb_push(skb
, 4), "\1\0\1\0", 4);
899 skb_queue_tail(&info
->xmit_queue
, skb
);
902 /************************************************************
906 * mostly "stolen" from original Linux-serial.c and friends.
908 ************************************************************/
910 /* The next routine is called once from within timer-interrupt
911 * triggered within isdn_tty_modem_ncarrier(). It calls
912 * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
913 * into the tty's flip-buffer.
916 isdn_tty_modem_do_ncarrier(unsigned long data
)
918 modem_info
*info
= (modem_info
*) data
;
919 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
922 /* Next routine is called, whenever the DTR-signal is raised.
923 * It checks the ncarrier-flag, and triggers the above routine
924 * when necessary. The ncarrier-flag is set, whenever DTR goes
928 isdn_tty_modem_ncarrier(modem_info
* info
)
930 if (info
->ncarrier
) {
931 info
->nc_timer
.expires
= jiffies
+ HZ
;
932 info
->nc_timer
.function
= isdn_tty_modem_do_ncarrier
;
933 info
->nc_timer
.data
= (unsigned long) info
;
934 add_timer(&info
->nc_timer
);
939 * return the usage calculated by si and layer 2 protocol
942 isdn_calc_usage(int si
, int l2
)
944 int usg
= ISDN_USAGE_MODEM
;
946 #ifdef CONFIG_ISDN_AUDIO
949 case ISDN_PROTO_L2_MODEM
:
950 usg
= ISDN_USAGE_MODEM
;
952 #ifdef CONFIG_ISDN_TTY_FAX
953 case ISDN_PROTO_L2_FAX
:
954 usg
= ISDN_USAGE_FAX
;
957 case ISDN_PROTO_L2_TRANS
:
959 usg
= ISDN_USAGE_VOICE
;
967 /* isdn_tty_dial() performs dialing of a tty an the necessary
968 * setup of the lower levels before that.
971 isdn_tty_dial(char *n
, modem_info
* info
, atemu
* m
)
973 int usg
= ISDN_USAGE_MODEM
;
975 int l2
= m
->mdmreg
[REG_L2PROT
];
981 for (j
= 7; j
>= 0; j
--)
982 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
986 usg
= isdn_calc_usage(si
, l2
);
987 #ifdef CONFIG_ISDN_AUDIO
989 (l2
!= ISDN_PROTO_L2_MODEM
)
990 #ifdef CONFIG_ISDN_TTY_FAX
991 && (l2
!= ISDN_PROTO_L2_FAX
)
994 l2
= ISDN_PROTO_L2_TRANS
;
995 usg
= ISDN_USAGE_VOICE
;
998 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
1001 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
1003 restore_flags(flags
);
1004 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
1006 info
->isdn_driver
= dev
->drvmap
[i
];
1007 info
->isdn_channel
= dev
->chanmap
[i
];
1008 info
->drv_index
= i
;
1009 dev
->m_idx
[i
] = info
->line
;
1010 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
1012 strcpy(info
->last_num
, n
);
1014 restore_flags(flags
);
1015 cmd
.driver
= info
->isdn_driver
;
1016 cmd
.arg
= info
->isdn_channel
;
1017 cmd
.command
= ISDN_CMD_CLREAZ
;
1019 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
1020 cmd
.driver
= info
->isdn_driver
;
1021 cmd
.command
= ISDN_CMD_SETEAZ
;
1023 cmd
.driver
= info
->isdn_driver
;
1024 cmd
.command
= ISDN_CMD_SETL2
;
1026 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
1028 cmd
.driver
= info
->isdn_driver
;
1029 cmd
.command
= ISDN_CMD_SETL3
;
1030 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
1031 #ifdef CONFIG_ISDN_TTY_FAX
1032 if (l2
== ISDN_PROTO_L2_FAX
) {
1033 cmd
.parm
.fax
= info
->fax
;
1034 info
->fax
->direction
= ISDN_TTY_FAX_CONN_OUT
;
1038 cmd
.driver
= info
->isdn_driver
;
1039 cmd
.arg
= info
->isdn_channel
;
1040 sprintf(cmd
.parm
.setup
.phone
, "%s", n
);
1041 sprintf(cmd
.parm
.setup
.eazmsn
, "%s",
1042 isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
1043 cmd
.parm
.setup
.si1
= si
;
1044 cmd
.parm
.setup
.si2
= m
->mdmreg
[REG_SI2
];
1045 cmd
.command
= ISDN_CMD_DIAL
;
1047 info
->emu
.carrierwait
= 0;
1048 strcpy(dev
->num
[i
], n
);
1051 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
1055 /* isdn_tty_hangup() disassociates a tty from the real
1056 * ISDN-line (hangup). The usage-status is cleared
1057 * and some cleanup is done also.
1060 isdn_tty_modem_hup(modem_info
* info
, int local
)
1066 #ifdef ISDN_DEBUG_MODEM_HUP
1067 printk(KERN_DEBUG
"Mhup ttyI%d\n", info
->line
);
1070 isdn_tty_flush_buffer(info
->tty
);
1072 info
->last_lhup
= local
;
1074 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1076 #ifdef CONFIG_ISDN_AUDIO
1078 #ifdef CONFIG_ISDN_TTY_FAX
1079 info
->faxonline
= 0;
1080 info
->fax
->phase
= ISDN_FAX_PHASE_IDLE
;
1082 info
->emu
.vpar
[4] = 0;
1083 info
->emu
.vpar
[5] = 8;
1084 if (info
->dtmf_state
) {
1085 kfree(info
->dtmf_state
);
1086 info
->dtmf_state
= NULL
;
1088 if (info
->silence_state
) {
1089 kfree(info
->silence_state
);
1090 info
->silence_state
= NULL
;
1093 kfree(info
->adpcms
);
1094 info
->adpcms
= NULL
;
1097 kfree(info
->adpcmr
);
1098 info
->adpcmr
= NULL
;
1101 if ((info
->msr
& UART_MSR_RI
) &&
1102 (info
->emu
.mdmreg
[REG_RUNG
] & BIT_RUNG
))
1103 isdn_tty_modem_result(RESULT_RUNG
, info
);
1104 info
->msr
&= ~(UART_MSR_DCD
| UART_MSR_RI
);
1105 info
->lsr
|= UART_LSR_TEMT
;
1106 if (info
->isdn_driver
>= 0) {
1108 cmd
.driver
= info
->isdn_driver
;
1109 cmd
.command
= ISDN_CMD_HANGUP
;
1110 cmd
.arg
= info
->isdn_channel
;
1113 isdn_all_eaz(info
->isdn_driver
, info
->isdn_channel
);
1114 info
->emu
.mdmreg
[REG_RINGCNT
] = 0;
1115 isdn_free_channel(info
->isdn_driver
, info
->isdn_channel
, 0);
1117 info
->isdn_driver
= -1;
1118 info
->isdn_channel
= -1;
1119 if (info
->drv_index
>= 0) {
1120 dev
->m_idx
[info
->drv_index
] = -1;
1121 info
->drv_index
= -1;
1126 * Begin of a CAPI like interface, currently used only for
1127 * supplementary service (CAPI 2.0 part III)
1129 #include "avmb1/capicmd.h" /* this should be moved in a common place */
1132 isdn_tty_capi_facility(capi_msg
*cm
) {
1133 return(-1); /* dummy */
1136 /* isdn_tty_suspend() tries to suspend the current tty connection
1139 isdn_tty_suspend(char *id
, modem_info
* info
, atemu
* m
)
1148 #ifdef ISDN_DEBUG_MODEM_SERVICES
1149 printk(KERN_DEBUG
"Msusp ttyI%d\n", info
->line
);
1152 if ((info
->isdn_driver
>= 0)) {
1153 cmd
.parm
.cmsg
.Length
= l
+18;
1154 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
1155 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
1156 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
1157 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
1158 cmd
.parm
.cmsg
.para
[1] = 0;
1159 cmd
.parm
.cmsg
.para
[2] = l
+ 3;
1160 cmd
.parm
.cmsg
.para
[3] = 4; /* 16 bit 0x0004 Suspend */
1161 cmd
.parm
.cmsg
.para
[4] = 0;
1162 cmd
.parm
.cmsg
.para
[5] = l
;
1163 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
1164 cmd
.command
= CAPI_PUT_MESSAGE
;
1165 cmd
.driver
= info
->isdn_driver
;
1166 cmd
.arg
= info
->isdn_channel
;
1171 /* isdn_tty_resume() tries to resume a suspended call
1172 * setup of the lower levels before that. unfortunatly here is no
1173 * checking for compatibility of used protocols implemented by Q931
1174 * It does the same things like isdn_tty_dial, the last command
1175 * is different, may be we can merge it.
1179 isdn_tty_resume(char *id
, modem_info
* info
, atemu
* m
)
1181 int usg
= ISDN_USAGE_MODEM
;
1183 int l2
= m
->mdmreg
[REG_L2PROT
];
1191 for (j
= 7; j
>= 0; j
--)
1192 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
1196 usg
= isdn_calc_usage(si
, l2
);
1197 #ifdef CONFIG_ISDN_AUDIO
1199 (l2
!= ISDN_PROTO_L2_MODEM
)
1200 #ifdef CONFIG_ISDN_TTY_FAX
1201 && (l2
!= ISDN_PROTO_L2_FAX
)
1204 l2
= ISDN_PROTO_L2_TRANS
;
1205 usg
= ISDN_USAGE_VOICE
;
1208 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
1211 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
1213 restore_flags(flags
);
1214 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
1216 info
->isdn_driver
= dev
->drvmap
[i
];
1217 info
->isdn_channel
= dev
->chanmap
[i
];
1218 info
->drv_index
= i
;
1219 dev
->m_idx
[i
] = info
->line
;
1220 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
1222 // strcpy(info->last_num, n);
1224 restore_flags(flags
);
1225 cmd
.driver
= info
->isdn_driver
;
1226 cmd
.arg
= info
->isdn_channel
;
1227 cmd
.command
= ISDN_CMD_CLREAZ
;
1229 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
1230 cmd
.driver
= info
->isdn_driver
;
1231 cmd
.command
= ISDN_CMD_SETEAZ
;
1233 cmd
.driver
= info
->isdn_driver
;
1234 cmd
.command
= ISDN_CMD_SETL2
;
1236 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
1238 cmd
.driver
= info
->isdn_driver
;
1239 cmd
.command
= ISDN_CMD_SETL3
;
1240 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
1242 cmd
.driver
= info
->isdn_driver
;
1243 cmd
.arg
= info
->isdn_channel
;
1244 cmd
.parm
.cmsg
.Length
= l
+18;
1245 cmd
.parm
.cmsg
.Command
= CAPI_FACILITY
;
1246 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
1247 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
1248 cmd
.parm
.cmsg
.para
[0] = 3; /* 16 bit 0x0003 suplementary service */
1249 cmd
.parm
.cmsg
.para
[1] = 0;
1250 cmd
.parm
.cmsg
.para
[2] = l
+3;
1251 cmd
.parm
.cmsg
.para
[3] = 5; /* 16 bit 0x0005 Resume */
1252 cmd
.parm
.cmsg
.para
[4] = 0;
1253 cmd
.parm
.cmsg
.para
[5] = l
;
1254 strncpy(&cmd
.parm
.cmsg
.para
[6], id
, l
);
1255 cmd
.command
=CAPI_PUT_MESSAGE
;
1257 // strcpy(dev->num[i], n);
1260 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
1264 /* isdn_tty_send_msg() sends a message to a HL driver
1265 * This is used for hybrid modem cards to send AT commands to it
1269 isdn_tty_send_msg(modem_info
* info
, atemu
* m
, char *msg
)
1271 int usg
= ISDN_USAGE_MODEM
;
1273 int l2
= m
->mdmreg
[REG_L2PROT
];
1282 isdn_tty_modem_result(RESULT_ERROR
, info
);
1285 for (j
= 7; j
>= 0; j
--)
1286 if (m
->mdmreg
[REG_SI1
] & (1 << j
)) {
1290 usg
= isdn_calc_usage(si
, l2
);
1291 #ifdef CONFIG_ISDN_AUDIO
1293 (l2
!= ISDN_PROTO_L2_MODEM
)
1294 #ifdef CONFIG_ISDN_TTY_FAX
1295 && (l2
!= ISDN_PROTO_L2_FAX
)
1298 l2
= ISDN_PROTO_L2_TRANS
;
1299 usg
= ISDN_USAGE_VOICE
;
1302 m
->mdmreg
[REG_SI1I
] = si2bit
[si
];
1305 i
= isdn_get_free_channel(usg
, l2
, m
->mdmreg
[REG_L3PROT
], -1, -1, m
->msn
);
1307 restore_flags(flags
);
1308 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
1310 info
->isdn_driver
= dev
->drvmap
[i
];
1311 info
->isdn_channel
= dev
->chanmap
[i
];
1312 info
->drv_index
= i
;
1313 dev
->m_idx
[i
] = info
->line
;
1314 dev
->usage
[i
] |= ISDN_USAGE_OUTGOING
;
1317 restore_flags(flags
);
1318 cmd
.driver
= info
->isdn_driver
;
1319 cmd
.arg
= info
->isdn_channel
;
1320 cmd
.command
= ISDN_CMD_CLREAZ
;
1322 strcpy(cmd
.parm
.num
, isdn_map_eaz2msn(m
->msn
, info
->isdn_driver
));
1323 cmd
.driver
= info
->isdn_driver
;
1324 cmd
.command
= ISDN_CMD_SETEAZ
;
1326 cmd
.driver
= info
->isdn_driver
;
1327 cmd
.command
= ISDN_CMD_SETL2
;
1329 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
1331 cmd
.driver
= info
->isdn_driver
;
1332 cmd
.command
= ISDN_CMD_SETL3
;
1333 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
1335 cmd
.driver
= info
->isdn_driver
;
1336 cmd
.arg
= info
->isdn_channel
;
1337 cmd
.parm
.cmsg
.Length
= l
+14;
1338 cmd
.parm
.cmsg
.Command
= CAPI_MANUFACTURER
;
1339 cmd
.parm
.cmsg
.Subcommand
= CAPI_REQ
;
1340 cmd
.parm
.cmsg
.adr
.Controller
= info
->isdn_driver
+ 1;
1341 cmd
.parm
.cmsg
.para
[0] = l
+1;
1342 strncpy(&cmd
.parm
.cmsg
.para
[1], msg
, l
);
1343 cmd
.parm
.cmsg
.para
[l
+1] = 0xd;
1344 cmd
.command
=CAPI_PUT_MESSAGE
;
1345 /* info->dialing = 1;
1346 strcpy(dev->num[i], n);
1354 isdn_tty_paranoia_check(modem_info
* info
, kdev_t device
, const char *routine
)
1356 #ifdef MODEM_PARANOIA_CHECK
1358 printk(KERN_WARNING
"isdn_tty: null info_struct for (%d, %d) in %s\n",
1359 MAJOR(device
), MINOR(device
), routine
);
1362 if (info
->magic
!= ISDN_ASYNC_MAGIC
) {
1363 printk(KERN_WARNING
"isdn_tty: bad magic for modem struct (%d, %d) in %s\n",
1364 MAJOR(device
), MINOR(device
), routine
);
1372 * This routine is called to set the UART divisor registers to match
1373 * the specified baud rate for a serial port.
1376 isdn_tty_change_speed(modem_info
* info
)
1384 if (!info
->tty
|| !info
->tty
->termios
)
1386 cflag
= info
->tty
->termios
->c_cflag
;
1388 quot
= i
= cflag
& CBAUD
;
1392 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
1397 info
->mcr
|= UART_MCR_DTR
;
1398 isdn_tty_modem_ncarrier(info
);
1400 info
->mcr
&= ~UART_MCR_DTR
;
1401 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1402 #ifdef ISDN_DEBUG_MODEM_HUP
1403 printk(KERN_DEBUG
"Mhup in changespeed\n");
1407 isdn_tty_modem_reset_regs(info
, 0);
1408 isdn_tty_modem_hup(info
, 1);
1412 /* byte size and parity */
1413 cval
= cflag
& (CSIZE
| CSTOPB
);
1416 cval
|= UART_LCR_PARITY
;
1417 if (!(cflag
& PARODD
))
1418 cval
|= UART_LCR_EPAR
;
1421 /* CTS flow control flag and modem status interrupts */
1422 if (cflag
& CRTSCTS
) {
1423 info
->flags
|= ISDN_ASYNC_CTS_FLOW
;
1425 info
->flags
&= ~ISDN_ASYNC_CTS_FLOW
;
1427 info
->flags
&= ~ISDN_ASYNC_CHECK_CD
;
1429 info
->flags
|= ISDN_ASYNC_CHECK_CD
;
1434 isdn_tty_startup(modem_info
* info
)
1438 if (info
->flags
& ISDN_ASYNC_INITIALIZED
)
1442 isdn_MOD_INC_USE_COUNT();
1443 #ifdef ISDN_DEBUG_MODEM_OPEN
1444 printk(KERN_DEBUG
"starting up ttyi%d ...\n", info
->line
);
1447 * Now, initialize the UART
1449 info
->mcr
= UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
;
1451 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1453 * and set the speed of the serial port
1455 isdn_tty_change_speed(info
);
1457 info
->flags
|= ISDN_ASYNC_INITIALIZED
;
1458 info
->msr
|= (UART_MSR_DSR
| UART_MSR_CTS
);
1459 info
->send_outstanding
= 0;
1460 restore_flags(flags
);
1465 * This routine will shutdown a serial port; interrupts are disabled, and
1466 * DTR is dropped if the hangup on close termio flag is on.
1469 isdn_tty_shutdown(modem_info
* info
)
1473 if (!(info
->flags
& ISDN_ASYNC_INITIALIZED
))
1475 #ifdef ISDN_DEBUG_MODEM_OPEN
1476 printk(KERN_DEBUG
"Shutting down isdnmodem port %d ....\n", info
->line
);
1479 cli(); /* Disable interrupts */
1480 isdn_MOD_DEC_USE_COUNT();
1481 info
->msr
&= ~UART_MSR_RI
;
1482 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
1483 info
->mcr
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1484 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1485 isdn_tty_modem_reset_regs(info
, 0);
1486 #ifdef ISDN_DEBUG_MODEM_HUP
1487 printk(KERN_DEBUG
"Mhup in isdn_tty_shutdown\n");
1489 isdn_tty_modem_hup(info
, 1);
1493 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1495 info
->flags
&= ~ISDN_ASYNC_INITIALIZED
;
1496 restore_flags(flags
);
1499 /* isdn_tty_write() is the main send-routine. It is called from the upper
1500 * levels within the kernel to perform sending data. Depending on the
1501 * online-flag it either directs output to the at-command-interpreter or
1502 * to the lower level. Additional tasks done here:
1503 * - If online, check for escape-sequence (+++)
1504 * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
1505 * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
1506 * - If dialing, abort dial.
1509 isdn_tty_write(struct tty_struct
*tty
, int from_user
, const u_char
* buf
, int count
)
1513 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1515 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_write"))
1520 down(&info
->write_sem
);
1521 /* See isdn_tty_senddown() */
1522 atomic_inc(&info
->xmit_lock
);
1524 c
= MIN(count
, info
->xmit_size
- info
->xmit_count
);
1525 if (info
->isdn_driver
>= 0)
1526 c
= MIN(c
, dev
->drv
[info
->isdn_driver
]->maxbufsize
);
1529 if ((info
->online
> 1)
1530 #ifdef CONFIG_ISDN_AUDIO
1531 || (info
->vonline
& 3)
1534 atemu
*m
= &info
->emu
;
1536 #ifdef CONFIG_ISDN_AUDIO
1539 isdn_tty_check_esc(buf
, m
->mdmreg
[REG_ESC
], c
,
1544 copy_from_user(&(info
->xmit_buf
[info
->xmit_count
]), buf
, c
);
1546 memcpy(&(info
->xmit_buf
[info
->xmit_count
]), buf
, c
);
1547 #ifdef CONFIG_ISDN_AUDIO
1548 if (info
->vonline
) {
1549 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1550 if (info
->vonline
& 2) {
1552 /* If DLE decoding results in zero-transmit, but
1553 * c originally was non-zero, do a wakeup.
1555 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1556 tty
->ldisc
.write_wakeup
)
1557 (tty
->ldisc
.write_wakeup
) (tty
);
1558 wake_up_interruptible(&tty
->write_wait
);
1559 info
->msr
|= UART_MSR_CTS
;
1560 info
->lsr
|= UART_LSR_TEMT
;
1562 info
->xmit_count
+= cc
;
1564 if ((info
->vonline
& 3) == 1) {
1565 /* Do NOT handle Ctrl-Q or Ctrl-S
1566 * when in full-duplex audio mode.
1568 if (isdn_tty_end_vrx(buf
, c
, from_user
)) {
1569 info
->vonline
&= ~1;
1570 #ifdef ISDN_DEBUG_MODEM_VOICE
1572 "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
1575 isdn_tty_at_cout("\020\003\r\nVCON\r\n", info
);
1579 if (TTY_IS_FCLASS1(info
)) {
1580 int cc
= isdn_tty_handleDLEdown(info
, m
, c
);
1582 if (info
->vonline
& 4) { /* ETX seen */
1585 c
.command
= ISDN_CMD_FAXCMD
;
1586 c
.driver
= info
->isdn_driver
;
1587 c
.arg
= info
->isdn_channel
;
1588 c
.parm
.aux
.cmd
= ISDN_FAX_CLASS1_CTRL
;
1589 c
.parm
.aux
.subcmd
= ETX
;
1593 printk(KERN_DEBUG
"fax dle cc/c %d/%d\n", cc
,c
);
1594 info
->xmit_count
+= cc
;
1597 info
->xmit_count
+= c
;
1599 info
->msr
|= UART_MSR_CTS
;
1600 info
->lsr
|= UART_LSR_TEMT
;
1601 if (info
->dialing
) {
1603 #ifdef ISDN_DEBUG_MODEM_HUP
1604 printk(KERN_DEBUG
"Mhup in isdn_tty_write\n");
1606 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
1607 isdn_tty_modem_hup(info
, 1);
1609 c
= isdn_tty_edit_at(buf
, c
, info
, from_user
);
1615 if ((info
->xmit_count
) || (skb_queue_len(&info
->xmit_queue
)))
1616 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1617 atomic_dec(&info
->xmit_lock
);
1619 up(&info
->write_sem
);
1624 isdn_tty_write_room(struct tty_struct
*tty
)
1626 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1629 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_write_room"))
1632 return info
->xmit_size
;
1633 ret
= info
->xmit_size
- info
->xmit_count
;
1634 return (ret
< 0) ? 0 : ret
;
1638 isdn_tty_chars_in_buffer(struct tty_struct
*tty
)
1640 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1642 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_chars_in_buffer"))
1646 return (info
->xmit_count
);
1650 isdn_tty_flush_buffer(struct tty_struct
*tty
)
1653 unsigned long flags
;
1658 restore_flags(flags
);
1661 info
= (modem_info
*) tty
->driver_data
;
1662 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_flush_buffer")) {
1663 restore_flags(flags
);
1666 isdn_tty_cleanup_xmit(info
);
1667 info
->xmit_count
= 0;
1668 restore_flags(flags
);
1669 wake_up_interruptible(&tty
->write_wait
);
1670 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1671 tty
->ldisc
.write_wakeup
)
1672 (tty
->ldisc
.write_wakeup
) (tty
);
1676 isdn_tty_flush_chars(struct tty_struct
*tty
)
1678 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1680 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_flush_chars"))
1682 if ((info
->xmit_count
) || (skb_queue_len(&info
->xmit_queue
)))
1683 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, 1);
1687 * ------------------------------------------------------------
1688 * isdn_tty_throttle()
1690 * This routine is called by the upper-layer tty layer to signal that
1691 * incoming characters should be throttled.
1692 * ------------------------------------------------------------
1695 isdn_tty_throttle(struct tty_struct
*tty
)
1697 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1699 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_throttle"))
1702 info
->x_char
= STOP_CHAR(tty
);
1703 info
->mcr
&= ~UART_MCR_RTS
;
1707 isdn_tty_unthrottle(struct tty_struct
*tty
)
1709 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1711 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_unthrottle"))
1717 info
->x_char
= START_CHAR(tty
);
1719 info
->mcr
|= UART_MCR_RTS
;
1723 * ------------------------------------------------------------
1724 * isdn_tty_ioctl() and friends
1725 * ------------------------------------------------------------
1729 * isdn_tty_get_lsr_info - get line status register info
1731 * Purpose: Let user call ioctl() to get info when the UART physically
1732 * is emptied. On bus types like RS485, the transmitter must
1733 * release the bus after transmitting. This must be done when
1734 * the transmit shift register is empty, not be done when the
1735 * transmit holding register is empty. This functionality
1736 * allows RS485 driver to be written in user space.
1739 isdn_tty_get_lsr_info(modem_info
* info
, uint
* value
)
1748 restore_flags(flags
);
1749 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1750 put_user(result
, (uint
*) value
);
1756 isdn_tty_get_modem_info(modem_info
* info
, uint
* value
)
1763 control
= info
->mcr
;
1767 restore_flags(flags
);
1768 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1769 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1770 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1771 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1772 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1773 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1774 put_user(result
, (uint
*) value
);
1779 isdn_tty_set_modem_info(modem_info
* info
, uint cmd
, uint
* value
)
1784 get_user(arg
, (uint
*) value
);
1787 #ifdef ISDN_DEBUG_MODEM_IOCTL
1788 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMBIS\n", info
->line
);
1790 if (arg
& TIOCM_RTS
) {
1791 info
->mcr
|= UART_MCR_RTS
;
1793 if (arg
& TIOCM_DTR
) {
1794 info
->mcr
|= UART_MCR_DTR
;
1795 isdn_tty_modem_ncarrier(info
);
1799 #ifdef ISDN_DEBUG_MODEM_IOCTL
1800 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMBIC\n", info
->line
);
1802 if (arg
& TIOCM_RTS
) {
1803 info
->mcr
&= ~UART_MCR_RTS
;
1805 if (arg
& TIOCM_DTR
) {
1806 info
->mcr
&= ~UART_MCR_DTR
;
1807 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1808 isdn_tty_modem_reset_regs(info
, 0);
1809 #ifdef ISDN_DEBUG_MODEM_HUP
1810 printk(KERN_DEBUG
"Mhup in TIOCMBIC\n");
1814 isdn_tty_modem_hup(info
, 1);
1819 #ifdef ISDN_DEBUG_MODEM_IOCTL
1820 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMSET\n", info
->line
);
1822 pre_dtr
= (info
->mcr
& UART_MCR_DTR
);
1823 info
->mcr
= ((info
->mcr
& ~(UART_MCR_RTS
| UART_MCR_DTR
))
1824 | ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0)
1825 | ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
1826 if (pre_dtr
|= (info
->mcr
& UART_MCR_DTR
)) {
1827 if (!(info
->mcr
& UART_MCR_DTR
)) {
1828 if (info
->emu
.mdmreg
[REG_DTRHUP
] & BIT_DTRHUP
) {
1829 isdn_tty_modem_reset_regs(info
, 0);
1830 #ifdef ISDN_DEBUG_MODEM_HUP
1831 printk(KERN_DEBUG
"Mhup in TIOCMSET\n");
1835 isdn_tty_modem_hup(info
, 1);
1838 isdn_tty_modem_ncarrier(info
);
1848 isdn_tty_ioctl(struct tty_struct
*tty
, struct file
*file
,
1849 uint cmd
, ulong arg
)
1851 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1855 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_ioctl"))
1857 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1860 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1861 #ifdef ISDN_DEBUG_MODEM_IOCTL
1862 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRK\n", info
->line
);
1864 retval
= tty_check_change(tty
);
1867 tty_wait_until_sent(tty
, 0);
1869 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1870 #ifdef ISDN_DEBUG_MODEM_IOCTL
1871 printk(KERN_DEBUG
"ttyI%d ioctl TCSBRKP\n", info
->line
);
1873 retval
= tty_check_change(tty
);
1876 tty_wait_until_sent(tty
, 0);
1879 #ifdef ISDN_DEBUG_MODEM_IOCTL
1880 printk(KERN_DEBUG
"ttyI%d ioctl TIOCGSOFTCAR\n", info
->line
);
1882 error
= verify_area(VERIFY_WRITE
, (void *) arg
, sizeof(long));
1885 put_user(C_CLOCAL(tty
) ? 1 : 0, (ulong
*) arg
);
1888 #ifdef ISDN_DEBUG_MODEM_IOCTL
1889 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSSOFTCAR\n", info
->line
);
1891 error
= verify_area(VERIFY_READ
, (void *) arg
, sizeof(long));
1894 get_user(arg
, (ulong
*) arg
);
1895 tty
->termios
->c_cflag
=
1896 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1897 (arg
? CLOCAL
: 0));
1900 #ifdef ISDN_DEBUG_MODEM_IOCTL
1901 printk(KERN_DEBUG
"ttyI%d ioctl TIOCMGET\n", info
->line
);
1903 error
= verify_area(VERIFY_WRITE
, (void *) arg
, sizeof(uint
));
1906 return isdn_tty_get_modem_info(info
, (uint
*) arg
);
1910 error
= verify_area(VERIFY_READ
, (void *) arg
, sizeof(uint
));
1913 return isdn_tty_set_modem_info(info
, cmd
, (uint
*) arg
);
1914 case TIOCSERGETLSR
: /* Get line status register */
1915 #ifdef ISDN_DEBUG_MODEM_IOCTL
1916 printk(KERN_DEBUG
"ttyI%d ioctl TIOCSERGETLSR\n", info
->line
);
1918 error
= verify_area(VERIFY_WRITE
, (void *) arg
, sizeof(uint
));
1922 return isdn_tty_get_lsr_info(info
, (uint
*) arg
);
1924 #ifdef ISDN_DEBUG_MODEM_IOCTL
1925 printk(KERN_DEBUG
"UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd
, info
->line
);
1927 return -ENOIOCTLCMD
;
1933 isdn_tty_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1935 modem_info
*info
= (modem_info
*) tty
->driver_data
;
1938 isdn_tty_change_speed(info
);
1940 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1942 isdn_tty_change_speed(info
);
1943 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1944 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1945 tty
->hw_stopped
= 0;
1951 * ------------------------------------------------------------
1952 * isdn_tty_open() and friends
1953 * ------------------------------------------------------------
1956 isdn_tty_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, modem_info
* info
)
1958 DECLARE_WAITQUEUE(wait
, NULL
);
1960 unsigned long flags
;
1964 * If the device is in the middle of being closed, then block
1965 * until it's done, and then try again.
1967 if (tty_hung_up_p(filp
) ||
1968 (info
->flags
& ISDN_ASYNC_CLOSING
)) {
1969 if (info
->flags
& ISDN_ASYNC_CLOSING
)
1970 interruptible_sleep_on(&info
->close_wait
);
1971 #ifdef MODEM_DO_RESTART
1972 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
1975 return -ERESTARTSYS
;
1981 * If this is a callout device, then just make sure the normal
1982 * device isn't being used.
1984 if (tty
->driver
.subtype
== ISDN_SERIAL_TYPE_CALLOUT
) {
1985 if (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
)
1987 if ((info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
1988 (info
->flags
& ISDN_ASYNC_SESSION_LOCKOUT
) &&
1989 (info
->session
!= current
->session
))
1991 if ((info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
1992 (info
->flags
& ISDN_ASYNC_PGRP_LOCKOUT
) &&
1993 (info
->pgrp
!= current
->pgrp
))
1995 info
->flags
|= ISDN_ASYNC_CALLOUT_ACTIVE
;
1999 * If non-blocking mode is set, then make the check up front
2002 if ((filp
->f_flags
& O_NONBLOCK
) ||
2003 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2004 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
2006 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
2009 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) {
2010 if (info
->normal_termios
.c_cflag
& CLOCAL
)
2013 if (tty
->termios
->c_cflag
& CLOCAL
)
2017 * Block waiting for the carrier detect and the line to become
2018 * free (i.e., not in use by the callout). While we are in
2019 * this loop, info->count is dropped by one, so that
2020 * isdn_tty_close() knows when to free things. We restore it upon
2021 * exit, either normal or abnormal.
2024 add_wait_queue(&info
->open_wait
, &wait
);
2025 #ifdef ISDN_DEBUG_MODEM_OPEN
2026 printk(KERN_DEBUG
"isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
2027 info
->line
, info
->count
);
2031 if (!(tty_hung_up_p(filp
)))
2033 restore_flags(flags
);
2034 info
->blocked_open
++;
2036 set_current_state(TASK_INTERRUPTIBLE
);
2037 if (tty_hung_up_p(filp
) ||
2038 !(info
->flags
& ISDN_ASYNC_INITIALIZED
)) {
2039 #ifdef MODEM_DO_RESTART
2040 if (info
->flags
& ISDN_ASYNC_HUP_NOTIFY
)
2043 retval
= -ERESTARTSYS
;
2049 if (!(info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
2050 !(info
->flags
& ISDN_ASYNC_CLOSING
) &&
2051 (do_clocal
|| (info
->msr
& UART_MSR_DCD
))) {
2054 if (signal_pending(current
)) {
2055 retval
= -ERESTARTSYS
;
2058 #ifdef ISDN_DEBUG_MODEM_OPEN
2059 printk(KERN_DEBUG
"isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
2060 info
->line
, info
->count
);
2064 current
->state
= TASK_RUNNING
;
2065 remove_wait_queue(&info
->open_wait
, &wait
);
2066 if (!tty_hung_up_p(filp
))
2068 info
->blocked_open
--;
2069 #ifdef ISDN_DEBUG_MODEM_OPEN
2070 printk(KERN_DEBUG
"isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
2071 info
->line
, info
->count
);
2075 info
->flags
|= ISDN_ASYNC_NORMAL_ACTIVE
;
2080 * This routine is called whenever a serial port is opened. It
2081 * enables interrupts for a serial port, linking in its async structure into
2082 * the IRQ chain. It also performs the serial-specific
2083 * initialization for the tty structure.
2086 isdn_tty_open(struct tty_struct
*tty
, struct file
*filp
)
2092 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2093 if (line
< 0 || line
> ISDN_MAX_CHANNELS
)
2095 info
= &dev
->mdm
.info
[line
];
2096 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_open"))
2098 #ifdef ISDN_DEBUG_MODEM_OPEN
2099 printk(KERN_DEBUG
"isdn_tty_open %s%d, count = %d\n", tty
->driver
.name
,
2100 info
->line
, info
->count
);
2103 tty
->driver_data
= info
;
2106 * Start up serial port
2108 retval
= isdn_tty_startup(info
);
2110 #ifdef ISDN_DEBUG_MODEM_OPEN
2111 printk(KERN_DEBUG
"isdn_tty_open return after startup\n");
2115 retval
= isdn_tty_block_til_ready(tty
, filp
, info
);
2117 #ifdef ISDN_DEBUG_MODEM_OPEN
2118 printk(KERN_DEBUG
"isdn_tty_open return after isdn_tty_block_til_ready \n");
2122 if ((info
->count
== 1) && (info
->flags
& ISDN_ASYNC_SPLIT_TERMIOS
)) {
2123 if (tty
->driver
.subtype
== ISDN_SERIAL_TYPE_NORMAL
)
2124 *tty
->termios
= info
->normal_termios
;
2126 *tty
->termios
= info
->callout_termios
;
2127 isdn_tty_change_speed(info
);
2129 info
->session
= current
->session
;
2130 info
->pgrp
= current
->pgrp
;
2131 #ifdef ISDN_DEBUG_MODEM_OPEN
2132 printk(KERN_DEBUG
"isdn_tty_open ttyi%d successful...\n", info
->line
);
2135 #ifdef ISDN_DEBUG_MODEM_OPEN
2136 printk(KERN_DEBUG
"isdn_tty_open normal exit\n");
2142 isdn_tty_close(struct tty_struct
*tty
, struct file
*filp
)
2144 modem_info
*info
= (modem_info
*) tty
->driver_data
;
2148 if (!info
|| isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_close"))
2152 if (tty_hung_up_p(filp
)) {
2153 restore_flags(flags
);
2154 #ifdef ISDN_DEBUG_MODEM_OPEN
2155 printk(KERN_DEBUG
"isdn_tty_close return after tty_hung_up_p\n");
2159 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2161 * Uh, oh. tty->count is 1, which means that the tty
2162 * structure will be freed. Info->count should always
2163 * be one in these conditions. If it's greater than
2164 * one, we've got real problems, since it means the
2165 * serial port won't be shutdown.
2167 printk(KERN_ERR
"isdn_tty_close: bad port count; tty->count is 1, "
2168 "info->count is %d\n", info
->count
);
2171 if (--info
->count
< 0) {
2172 printk(KERN_ERR
"isdn_tty_close: bad port count for ttyi%d: %d\n",
2173 info
->line
, info
->count
);
2177 restore_flags(flags
);
2178 #ifdef ISDN_DEBUG_MODEM_OPEN
2179 printk(KERN_DEBUG
"isdn_tty_close after info->count != 0\n");
2183 info
->flags
|= ISDN_ASYNC_CLOSING
;
2185 * Save the termios structure, since this port may have
2186 * separate termios for callout and dialin.
2188 if (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
)
2189 info
->normal_termios
= *tty
->termios
;
2190 if (info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
)
2191 info
->callout_termios
= *tty
->termios
;
2195 * At this point we stop accepting input. To do this, we
2196 * disable the receive line status interrupts, and tell the
2197 * interrupt driver to stop checking the data ready bit in the
2198 * line status register.
2200 if (info
->flags
& ISDN_ASYNC_INITIALIZED
) {
2201 tty_wait_until_sent(tty
, 3000); /* 30 seconds timeout */
2203 * Before we drop DTR, make sure the UART transmitter
2204 * has completely drained; this is especially
2205 * important if there is a transmit FIFO!
2207 timeout
= jiffies
+ HZ
;
2208 while (!(info
->lsr
& UART_LSR_TEMT
)) {
2209 set_current_state(TASK_INTERRUPTIBLE
);
2210 schedule_timeout(20);
2211 if (time_after(jiffies
,timeout
))
2216 isdn_tty_shutdown(info
);
2217 if (tty
->driver
.flush_buffer
)
2218 tty
->driver
.flush_buffer(tty
);
2219 if (tty
->ldisc
.flush_buffer
)
2220 tty
->ldisc
.flush_buffer(tty
);
2224 if (info
->blocked_open
) {
2225 set_current_state(TASK_INTERRUPTIBLE
);
2226 schedule_timeout(50);
2227 wake_up_interruptible(&info
->open_wait
);
2229 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CALLOUT_ACTIVE
|
2230 ISDN_ASYNC_CLOSING
);
2231 wake_up_interruptible(&info
->close_wait
);
2232 restore_flags(flags
);
2233 #ifdef ISDN_DEBUG_MODEM_OPEN
2234 printk(KERN_DEBUG
"isdn_tty_close normal exit\n");
2239 * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
2242 isdn_tty_hangup(struct tty_struct
*tty
)
2244 modem_info
*info
= (modem_info
*) tty
->driver_data
;
2246 if (isdn_tty_paranoia_check(info
, tty
->device
, "isdn_tty_hangup"))
2248 isdn_tty_shutdown(info
);
2250 info
->flags
&= ~(ISDN_ASYNC_NORMAL_ACTIVE
| ISDN_ASYNC_CALLOUT_ACTIVE
);
2252 wake_up_interruptible(&info
->open_wait
);
2255 /* This routine initializes all emulator-data.
2258 isdn_tty_reset_profile(atemu
* m
)
2271 m
->profile
[11] = 70;
2272 m
->profile
[12] = 0x45;
2274 m
->profile
[14] = ISDN_PROTO_L2_X75I
;
2275 m
->profile
[15] = ISDN_PROTO_L3_TRANS
;
2276 m
->profile
[16] = ISDN_SERIAL_XMIT_SIZE
/ 16;
2277 m
->profile
[17] = ISDN_MODEM_WINSIZE
;
2286 #ifdef CONFIG_ISDN_AUDIO
2288 isdn_tty_modem_reset_vpar(atemu
* m
)
2290 m
->vpar
[0] = 2; /* Voice-device (2 = phone line) */
2291 m
->vpar
[1] = 0; /* Silence detection level (0 = none ) */
2292 m
->vpar
[2] = 70; /* Silence interval (7 sec. ) */
2293 m
->vpar
[3] = 2; /* Compression type (1 = ADPCM-2 ) */
2294 m
->vpar
[4] = 0; /* DTMF detection level (0 = softcode ) */
2295 m
->vpar
[5] = 8; /* DTMF interval (8 * 5 ms. ) */
2299 #ifdef CONFIG_ISDN_TTY_FAX
2301 isdn_tty_modem_reset_faxpar(modem_info
* info
)
2303 T30_s
*f
= info
->fax
;
2306 f
->phase
= ISDN_FAX_PHASE_IDLE
;
2308 f
->resolution
= 1; /* fine */
2309 f
->rate
= 5; /* 14400 bit/s */
2316 memset(&f
->id
[0], 32, FAXIDLEN
- 1);
2317 f
->id
[FAXIDLEN
- 1] = 0;
2328 memset(&f
->pollid
[0], 32, FAXIDLEN
- 1);
2329 f
->pollid
[FAXIDLEN
- 1] = 0;
2334 isdn_tty_modem_reset_regs(modem_info
* info
, int force
)
2336 atemu
*m
= &info
->emu
;
2337 if ((m
->mdmreg
[REG_DTRR
] & BIT_DTRR
) || force
) {
2338 memcpy(m
->mdmreg
, m
->profile
, ISDN_MODEM_NUMREG
);
2339 memcpy(m
->msn
, m
->pmsn
, ISDN_MSNLEN
);
2340 memcpy(m
->lmsn
, m
->plmsn
, ISDN_LMSNLEN
);
2341 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
2343 #ifdef CONFIG_ISDN_AUDIO
2344 isdn_tty_modem_reset_vpar(m
);
2346 #ifdef CONFIG_ISDN_TTY_FAX
2347 isdn_tty_modem_reset_faxpar(info
);
2353 modem_write_profile(atemu
* m
)
2355 memcpy(m
->profile
, m
->mdmreg
, ISDN_MODEM_NUMREG
);
2356 memcpy(m
->pmsn
, m
->msn
, ISDN_MSNLEN
);
2357 memcpy(m
->plmsn
, m
->lmsn
, ISDN_LMSNLEN
);
2359 send_sig(SIGIO
, dev
->profd
, 1);
2363 isdn_tty_modem_init(void)
2370 memset(&m
->tty_modem
, 0, sizeof(struct tty_driver
));
2371 m
->tty_modem
.magic
= TTY_DRIVER_MAGIC
;
2372 m
->tty_modem
.name
= isdn_ttyname_ttyI
;
2373 m
->tty_modem
.major
= ISDN_TTY_MAJOR
;
2374 m
->tty_modem
.minor_start
= 0;
2375 m
->tty_modem
.num
= ISDN_MAX_CHANNELS
;
2376 m
->tty_modem
.type
= TTY_DRIVER_TYPE_SERIAL
;
2377 m
->tty_modem
.subtype
= ISDN_SERIAL_TYPE_NORMAL
;
2378 m
->tty_modem
.init_termios
= tty_std_termios
;
2379 m
->tty_modem
.init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2380 m
->tty_modem
.flags
= TTY_DRIVER_REAL_RAW
;
2381 m
->tty_modem
.refcount
= &m
->refcount
;
2382 m
->tty_modem
.table
= m
->modem_table
;
2383 m
->tty_modem
.termios
= m
->modem_termios
;
2384 m
->tty_modem
.termios_locked
= m
->modem_termios_locked
;
2385 m
->tty_modem
.open
= isdn_tty_open
;
2386 m
->tty_modem
.close
= isdn_tty_close
;
2387 m
->tty_modem
.write
= isdn_tty_write
;
2388 m
->tty_modem
.put_char
= NULL
;
2389 m
->tty_modem
.flush_chars
= isdn_tty_flush_chars
;
2390 m
->tty_modem
.write_room
= isdn_tty_write_room
;
2391 m
->tty_modem
.chars_in_buffer
= isdn_tty_chars_in_buffer
;
2392 m
->tty_modem
.flush_buffer
= isdn_tty_flush_buffer
;
2393 m
->tty_modem
.ioctl
= isdn_tty_ioctl
;
2394 m
->tty_modem
.throttle
= isdn_tty_throttle
;
2395 m
->tty_modem
.unthrottle
= isdn_tty_unthrottle
;
2396 m
->tty_modem
.set_termios
= isdn_tty_set_termios
;
2397 m
->tty_modem
.stop
= NULL
;
2398 m
->tty_modem
.start
= NULL
;
2399 m
->tty_modem
.hangup
= isdn_tty_hangup
;
2400 m
->tty_modem
.driver_name
= "isdn_tty";
2402 * The callout device is just like normal device except for
2403 * major number and the subtype code.
2405 m
->cua_modem
= m
->tty_modem
;
2406 m
->cua_modem
.name
= isdn_ttyname_cui
;
2407 m
->cua_modem
.major
= ISDN_TTYAUX_MAJOR
;
2408 m
->tty_modem
.minor_start
= 0;
2409 m
->cua_modem
.subtype
= ISDN_SERIAL_TYPE_CALLOUT
;
2411 if (tty_register_driver(&m
->tty_modem
)) {
2412 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-device\n");
2415 if (tty_register_driver(&m
->cua_modem
)) {
2416 printk(KERN_WARNING
"isdn_tty: Couldn't register modem-callout-device\n");
2419 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2421 #ifdef CONFIG_ISDN_TTY_FAX
2422 if (!(info
->fax
= kmalloc(sizeof(T30_s
), GFP_KERNEL
))) {
2423 printk(KERN_ERR
"Could not allocate fax t30-buffer\n");
2427 init_MUTEX(&info
->write_sem
);
2428 sprintf(info
->last_cause
, "0000");
2429 sprintf(info
->last_num
, "none");
2431 info
->last_lhup
= 1;
2434 isdn_tty_reset_profile(&info
->emu
);
2435 isdn_tty_modem_reset_regs(info
, 1);
2436 info
->magic
= ISDN_ASYNC_MAGIC
;
2441 info
->blocked_open
= 0;
2442 info
->callout_termios
= m
->cua_modem
.init_termios
;
2443 info
->normal_termios
= m
->tty_modem
.init_termios
;
2444 init_waitqueue_head(&info
->open_wait
);
2445 init_waitqueue_head(&info
->close_wait
);
2446 info
->isdn_driver
= -1;
2447 info
->isdn_channel
= -1;
2448 info
->drv_index
= -1;
2449 info
->xmit_size
= ISDN_SERIAL_XMIT_SIZE
;
2450 skb_queue_head_init(&info
->xmit_queue
);
2451 #ifdef CONFIG_ISDN_AUDIO
2452 skb_queue_head_init(&info
->dtmf_queue
);
2454 if (!(info
->xmit_buf
= kmalloc(ISDN_SERIAL_XMIT_MAX
+ 5, GFP_KERNEL
))) {
2455 printk(KERN_ERR
"Could not allocate modem xmit-buffer\n");
2458 /* Make room for T.70 header */
2459 info
->xmit_buf
+= 4;
2466 * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
2467 * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
2468 * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
2472 isdn_tty_match_icall(char *cid
, atemu
*emu
, int di
)
2474 #ifdef ISDN_DEBUG_MODEM_ICALL
2475 printk(KERN_DEBUG
"m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
2476 emu
->msn
, emu
->lmsn
, isdn_map_eaz2msn(emu
->msn
, di
),
2477 emu
->mdmreg
[REG_SI1
], emu
->mdmreg
[REG_SI2
]);
2479 if (strlen(emu
->lmsn
)) {
2480 char *p
= emu
->lmsn
;
2486 if ((q
= strchr(p
, ';')))
2488 if ((tmp
= isdn_wildmat(cid
, isdn_map_eaz2msn(p
, di
))) > ret
)
2490 #ifdef ISDN_DEBUG_MODEM_ICALL
2491 printk(KERN_DEBUG
"m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
2492 p
, isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2507 tmp
= isdn_wildmat(cid
, isdn_map_eaz2msn(emu
->msn
, di
));
2508 #ifdef ISDN_DEBUG_MODEM_ICALL
2509 printk(KERN_DEBUG
"m_fi: mmsn=%s -> tmp=%d\n",
2510 isdn_map_eaz2msn(emu
->msn
, di
), tmp
);
2517 * An incoming call-request has arrived.
2518 * Search the tty-devices for an appropriate device and bind
2519 * it to the ISDN-Channel.
2522 * 0 = No matching device found.
2523 * 1 = A matching device found.
2524 * 3 = No match found, but eventually would match, if
2528 isdn_tty_find_icall(int di
, int ch
, setup_parm setup
)
2539 if (!setup
.phone
[0]) {
2541 printk(KERN_INFO
"isdn_tty: Incoming call without OAD, assuming '0'\n");
2544 si1
= (int) setup
.si1
;
2545 si2
= (int) setup
.si2
;
2546 if (!setup
.eazmsn
[0]) {
2547 printk(KERN_WARNING
"isdn_tty: Incoming call without CPN, assuming '0'\n");
2551 #ifdef ISDN_DEBUG_MODEM_ICALL
2552 printk(KERN_DEBUG
"m_fi: eaz=%s si1=%d si2=%d\n", eaz
, si1
, si2
);
2557 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2558 modem_info
*info
= &dev
->mdm
.info
[i
];
2560 if (info
->count
== 0)
2562 if ((info
->emu
.mdmreg
[REG_SI1
] & si2bit
[si1
]) && /* SI1 is matching */
2563 (info
->emu
.mdmreg
[REG_SI2
] == si2
)) { /* SI2 is matching */
2564 idx
= isdn_dc2minor(di
, ch
);
2565 #ifdef ISDN_DEBUG_MODEM_ICALL
2566 printk(KERN_DEBUG
"m_fi: match1 wret=%d\n", wret
);
2567 printk(KERN_DEBUG
"m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx
,
2568 info
->flags
, info
->isdn_driver
, info
->isdn_channel
,
2572 #ifndef FIX_FILE_TRANSFER
2573 (info
->flags
& ISDN_ASYNC_NORMAL_ACTIVE
) &&
2575 (info
->isdn_driver
== -1) &&
2576 (info
->isdn_channel
== -1) &&
2577 (USG_NONE(dev
->usage
[idx
]))) {
2580 if ((matchret
= isdn_tty_match_icall(eaz
, &info
->emu
, di
)) > wret
)
2582 if (!matchret
) { /* EAZ is matching */
2583 info
->isdn_driver
= di
;
2584 info
->isdn_channel
= ch
;
2585 info
->drv_index
= idx
;
2586 dev
->m_idx
[idx
] = info
->line
;
2587 dev
->usage
[idx
] &= ISDN_USAGE_EXCLUSIVE
;
2588 dev
->usage
[idx
] |= isdn_calc_usage(si1
, info
->emu
.mdmreg
[REG_L2PROT
]);
2589 strcpy(dev
->num
[idx
], nr
);
2590 strcpy(info
->emu
.cpn
, eaz
);
2591 info
->emu
.mdmreg
[REG_SI1I
] = si2bit
[si1
];
2592 info
->emu
.mdmreg
[REG_PLAN
] = setup
.plan
;
2593 info
->emu
.mdmreg
[REG_SCREEN
] = setup
.screen
;
2595 restore_flags(flags
);
2596 printk(KERN_INFO
"isdn_tty: call from %s, -> RING on ttyI%d\n", nr
,
2598 info
->msr
|= UART_MSR_RI
;
2599 isdn_tty_modem_result(RESULT_RING
, info
);
2600 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, 1);
2606 restore_flags(flags
);
2607 printk(KERN_INFO
"isdn_tty: call from %s -> %s %s\n", nr
, eaz
,
2608 ((dev
->drv
[di
]->flags
& DRV_FLAG_REJBUS
) && (wret
!= 2))? "rejected" : "ignored");
2609 return (wret
== 2)?3:0;
2612 #define TTY_IS_ACTIVE(info) \
2613 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2616 isdn_tty_stat_callback(int i
, isdn_ctrl
*c
)
2624 if ((mi
= dev
->m_idx
[i
]) >= 0) {
2625 info
= &dev
->mdm
.info
[mi
];
2626 switch (c
->command
) {
2627 case ISDN_STAT_CINF
:
2628 printk(KERN_DEBUG
"CHARGEINFO on ttyI%d: %ld %s\n", info
->line
, c
->arg
, c
->parm
.num
);
2629 info
->emu
.charge
= (unsigned) simple_strtoul(c
->parm
.num
, &e
, 10);
2630 if (e
== (char *)c
->parm
.num
)
2631 info
->emu
.charge
= 0;
2634 case ISDN_STAT_BSENT
:
2635 #ifdef ISDN_TTY_STAT_DEBUG
2636 printk(KERN_DEBUG
"tty_STAT_BSENT ttyI%d\n", info
->line
);
2638 if ((info
->isdn_driver
== c
->driver
) &&
2639 (info
->isdn_channel
== c
->arg
)) {
2640 info
->msr
|= UART_MSR_CTS
;
2641 if (info
->send_outstanding
)
2642 if (!(--info
->send_outstanding
))
2643 info
->lsr
|= UART_LSR_TEMT
;
2644 isdn_tty_tint(info
);
2648 case ISDN_STAT_CAUSE
:
2649 #ifdef ISDN_TTY_STAT_DEBUG
2650 printk(KERN_DEBUG
"tty_STAT_CAUSE ttyI%d\n", info
->line
);
2652 /* Signal cause to tty-device */
2653 strncpy(info
->last_cause
, c
->parm
.num
, 5);
2655 case ISDN_STAT_DISPLAY
:
2656 #ifdef ISDN_TTY_STAT_DEBUG
2657 printk(KERN_DEBUG
"tty_STAT_DISPLAY ttyI%d\n", info
->line
);
2659 /* Signal display to tty-device */
2660 if ((info
->emu
.mdmreg
[REG_DISPLAY
] & BIT_DISPLAY
) &&
2661 !(info
->emu
.mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
)) {
2662 isdn_tty_at_cout("\r\n", info
);
2663 isdn_tty_at_cout("DISPLAY: ", info
);
2664 isdn_tty_at_cout(c
->parm
.display
, info
);
2665 isdn_tty_at_cout("\r\n", info
);
2668 case ISDN_STAT_DCONN
:
2669 #ifdef ISDN_TTY_STAT_DEBUG
2670 printk(KERN_DEBUG
"tty_STAT_DCONN ttyI%d\n", info
->line
);
2672 if (TTY_IS_ACTIVE(info
)) {
2673 if (info
->dialing
== 1) {
2679 case ISDN_STAT_DHUP
:
2680 #ifdef ISDN_TTY_STAT_DEBUG
2681 printk(KERN_DEBUG
"tty_STAT_DHUP ttyI%d\n", info
->line
);
2683 if (TTY_IS_ACTIVE(info
)) {
2684 if (info
->dialing
== 1)
2685 isdn_tty_modem_result(RESULT_BUSY
, info
);
2686 if (info
->dialing
> 1)
2687 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
2689 #ifdef ISDN_DEBUG_MODEM_HUP
2690 printk(KERN_DEBUG
"Mhup in ISDN_STAT_DHUP\n");
2692 isdn_tty_modem_hup(info
, 0);
2696 case ISDN_STAT_BCONN
:
2697 #ifdef ISDN_TTY_STAT_DEBUG
2698 printk(KERN_DEBUG
"tty_STAT_BCONN ttyI%d\n", info
->line
);
2700 /* Schedule CONNECT-Message to any tty
2701 * waiting for it and
2702 * set DCD-bit of its modem-status.
2704 if (TTY_IS_ACTIVE(info
)) {
2705 info
->msr
|= UART_MSR_DCD
;
2706 info
->emu
.charge
= 0;
2707 if (info
->dialing
& 0xf)
2713 if (USG_MODEM(dev
->usage
[i
])) {
2714 if (info
->emu
.mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) {
2715 strcpy(info
->emu
.connmsg
, c
->parm
.num
);
2716 isdn_tty_modem_result(RESULT_CONNECT
, info
);
2718 isdn_tty_modem_result(RESULT_CONNECT64000
, info
);
2720 if (USG_VOICE(dev
->usage
[i
]))
2721 isdn_tty_modem_result(RESULT_VCON
, info
);
2725 case ISDN_STAT_BHUP
:
2726 #ifdef ISDN_TTY_STAT_DEBUG
2727 printk(KERN_DEBUG
"tty_STAT_BHUP ttyI%d\n", info
->line
);
2729 if (TTY_IS_ACTIVE(info
)) {
2730 #ifdef ISDN_DEBUG_MODEM_HUP
2731 printk(KERN_DEBUG
"Mhup in ISDN_STAT_BHUP\n");
2733 isdn_tty_modem_hup(info
, 0);
2737 case ISDN_STAT_NODCH
:
2738 #ifdef ISDN_TTY_STAT_DEBUG
2739 printk(KERN_DEBUG
"tty_STAT_NODCH ttyI%d\n", info
->line
);
2741 if (TTY_IS_ACTIVE(info
)) {
2742 if (info
->dialing
) {
2746 sprintf(info
->last_cause
, "0000");
2747 isdn_tty_modem_result(RESULT_NO_DIALTONE
, info
);
2749 isdn_tty_modem_hup(info
, 0);
2753 case ISDN_STAT_UNLOAD
:
2754 #ifdef ISDN_TTY_STAT_DEBUG
2755 printk(KERN_DEBUG
"tty_STAT_UNLOAD ttyI%d\n", info
->line
);
2757 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
2758 info
= &dev
->mdm
.info
[i
];
2759 if (info
->isdn_driver
== c
->driver
) {
2761 isdn_tty_modem_hup(info
, 1);
2765 #ifdef CONFIG_ISDN_TTY_FAX
2766 case ISDN_STAT_FAXIND
:
2767 if (TTY_IS_ACTIVE(info
)) {
2768 isdn_tty_fax_command(info
, c
);
2772 #ifdef CONFIG_ISDN_AUDIO
2773 case ISDN_STAT_AUDIO
:
2774 if (TTY_IS_ACTIVE(info
)) {
2775 switch(c
->parm
.num
[0]) {
2776 case ISDN_AUDIO_DTMF
:
2777 if (info
->vonline
) {
2778 isdn_audio_put_dle_code(info
,
2791 /*********************************************************************
2792 Modem-Emulator-Routines
2793 *********************************************************************/
2795 #define cmdchar(c) ((c>=' ')&&(c<=0x7f))
2798 * Put a message from the AT-emulator into receive-buffer of tty,
2799 * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
2802 isdn_tty_at_cout(char *msg
, modem_info
* info
)
2804 struct tty_struct
*tty
;
2805 atemu
*m
= &info
->emu
;
2809 struct sk_buff
*skb
= 0;
2813 printk(KERN_WARNING
"isdn_tty: Null-Message in isdn_tty_at_cout\n");
2819 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!tty
)) {
2820 restore_flags(flags
);
2824 /* use queue instead of direct flip, if online and */
2825 /* data is in queue or flip buffer is full */
2826 if ((info
->online
) && (((tty
->flip
.count
+ strlen(msg
)) >= TTY_FLIPBUF_SIZE
) ||
2827 (!skb_queue_empty(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
])))) {
2828 skb
= alloc_skb(strlen(msg
)
2829 #ifdef CONFIG_ISDN_AUDIO
2830 + sizeof(isdn_audio_skb
)
2834 restore_flags(flags
);
2837 #ifdef CONFIG_ISDN_AUDIO
2838 skb_reserve(skb
, sizeof(isdn_audio_skb
));
2840 sp
= skb_put(skb
, strlen(msg
));
2841 #ifdef CONFIG_ISDN_AUDIO
2842 ISDN_AUDIO_SKB_DLECOUNT(skb
) = 0;
2843 ISDN_AUDIO_SKB_LOCK(skb
) = 0;
2847 for (p
= msg
; *p
; p
++) {
2850 c
= m
->mdmreg
[REG_CR
];
2853 c
= m
->mdmreg
[REG_LF
];
2856 c
= m
->mdmreg
[REG_BS
];
2864 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
2866 tty_insert_flip_char(tty
, c
, 0);
2870 __skb_queue_tail(&dev
->drv
[info
->isdn_driver
]->rpqueue
[info
->isdn_channel
], skb
);
2871 dev
->drv
[info
->isdn_driver
]->rcvcount
[info
->isdn_channel
] += skb
->len
;
2872 restore_flags(flags
);
2873 /* Schedule dequeuing */
2874 if ((dev
->modempoll
) && (info
->rcvsched
))
2875 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD
, 1);
2878 restore_flags(flags
);
2879 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
2884 * Perform ATH Hangup
2887 isdn_tty_on_hook(modem_info
* info
)
2889 if (info
->isdn_channel
>= 0) {
2890 #ifdef ISDN_DEBUG_MODEM_HUP
2891 printk(KERN_DEBUG
"Mhup in isdn_tty_on_hook\n");
2893 isdn_tty_modem_hup(info
, 1);
2898 isdn_tty_off_hook(void)
2900 printk(KERN_DEBUG
"isdn_tty_off_hook\n");
2903 #define PLUSWAIT1 (HZ/2) /* 0.5 sec. */
2904 #define PLUSWAIT2 (HZ*3/2) /* 1.5 sec */
2907 * Check Buffer for Modem-escape-sequence, activate timer-callback to
2908 * isdn_tty_modem_escape() if sequence found.
2911 * p pointer to databuffer
2912 * plus escape-character
2913 * count length of buffer
2914 * pluscount count of valid escape-characters so far
2915 * lastplus timestamp of last character
2918 isdn_tty_check_esc(const u_char
* p
, u_char plus
, int count
, int *pluscount
,
2919 int *lastplus
, int from_user
)
2931 copy_from_user(cbuf
, p
, count
);
2935 if (*(p
++) == plus
) {
2936 if ((*pluscount
)++) {
2937 /* Time since last '+' > 0.5 sec. ? */
2938 if ((jiffies
- *lastplus
) > PLUSWAIT1
)
2941 /* Time since last non-'+' < 1.5 sec. ? */
2942 if ((jiffies
- *lastplus
) < PLUSWAIT2
)
2945 if ((*pluscount
== 3) && (count
= 1))
2946 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, 1);
2951 *lastplus
= jiffies
;
2957 * Return result of AT-emulator to tty-receive-buffer, depending on
2958 * modem-register 12, bit 0 and 1.
2959 * For CONNECT-messages also switch to online-mode.
2960 * For RING-message handle auto-ATA if register 0 != 0
2964 isdn_tty_modem_result(int code
, modem_info
* info
)
2966 atemu
*m
= &info
->emu
;
2967 static char *msg
[] =
2968 {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
2969 "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
2970 "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
2972 char s
[ISDN_MSNLEN
+10];
2976 m
->mdmreg
[REG_RINGCNT
]++;
2977 if (m
->mdmreg
[REG_RINGCNT
] == m
->mdmreg
[REG_RINGATA
])
2978 /* Automatically accept incoming call */
2979 isdn_tty_cmd_ATA(info
);
2981 case RESULT_NO_CARRIER
:
2982 #ifdef ISDN_DEBUG_MODEM_HUP
2983 printk(KERN_DEBUG
"modem_result: NO CARRIER %d %d\n",
2984 (info
->flags
& ISDN_ASYNC_CLOSING
),
2989 m
->mdmreg
[REG_RINGCNT
] = 0;
2990 del_timer(&info
->nc_timer
);
2992 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
2993 restore_flags(flags
);
2996 restore_flags(flags
);
2997 #ifdef CONFIG_ISDN_AUDIO
2998 if (info
->vonline
& 1) {
2999 #ifdef ISDN_DEBUG_MODEM_VOICE
3000 printk(KERN_DEBUG
"res3: send DLE-ETX on ttyI%d\n",
3003 /* voice-recording, add DLE-ETX */
3004 isdn_tty_at_cout("\020\003", info
);
3006 if (info
->vonline
& 2) {
3007 #ifdef ISDN_DEBUG_MODEM_VOICE
3008 printk(KERN_DEBUG
"res3: send DLE-DC4 on ttyI%d\n",
3011 /* voice-playing, add DLE-DC4 */
3012 isdn_tty_at_cout("\020\024", info
);
3016 case RESULT_CONNECT
:
3017 case RESULT_CONNECT64000
:
3018 sprintf(info
->last_cause
, "0000");
3023 #ifdef ISDN_DEBUG_MODEM_VOICE
3024 printk(KERN_DEBUG
"res3: send VCON on ttyI%d\n",
3027 sprintf(info
->last_cause
, "0000");
3031 } /* switch(code) */
3033 if (m
->mdmreg
[REG_RESP
] & BIT_RESP
) {
3035 if (m
->mdmreg
[REG_RESPNUM
] & BIT_RESPNUM
) {
3036 /* Show numeric results only */
3037 sprintf(s
, "\r\n%d\r\n", code
);
3038 isdn_tty_at_cout(s
, info
);
3040 if (code
== RESULT_RING
) {
3041 /* return if "show RUNG" and ringcounter>1 */
3042 if ((m
->mdmreg
[REG_RUNG
] & BIT_RUNG
) &&
3043 (m
->mdmreg
[REG_RINGCNT
] > 1))
3045 /* print CID, _before_ _every_ ring */
3046 if (!(m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
)) {
3047 isdn_tty_at_cout("\r\nCALLER NUMBER: ", info
);
3048 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
3051 isdn_tty_at_cout("\r\n", info
);
3052 isdn_tty_at_cout(msg
[code
], info
);
3054 case RESULT_CONNECT
:
3055 switch (m
->mdmreg
[REG_L2PROT
]) {
3056 case ISDN_PROTO_L2_MODEM
:
3057 isdn_tty_at_cout(" ", info
);
3058 isdn_tty_at_cout(m
->connmsg
, info
);
3063 /* Append CPN, if enabled */
3064 if ((m
->mdmreg
[REG_CPN
] & BIT_CPN
)) {
3065 sprintf(s
, "/%s", m
->cpn
);
3066 isdn_tty_at_cout(s
, info
);
3068 /* Print CID only once, _after_ 1st RING */
3069 if ((m
->mdmreg
[REG_CIDONCE
] & BIT_CIDONCE
) &&
3070 (m
->mdmreg
[REG_RINGCNT
] == 1)) {
3071 isdn_tty_at_cout("\r\n", info
);
3072 isdn_tty_at_cout("CALLER NUMBER: ", info
);
3073 isdn_tty_at_cout(dev
->num
[info
->drv_index
], info
);
3076 case RESULT_NO_CARRIER
:
3077 case RESULT_NO_DIALTONE
:
3079 case RESULT_NO_ANSWER
:
3080 m
->mdmreg
[REG_RINGCNT
] = 0;
3081 /* Append Cause-Message if enabled */
3082 if (m
->mdmreg
[REG_RESPXT
] & BIT_RESPXT
) {
3083 sprintf(s
, "/%s", info
->last_cause
);
3084 isdn_tty_at_cout(s
, info
);
3087 case RESULT_CONNECT64000
:
3088 /* Append Protocol to CONNECT message */
3089 switch (m
->mdmreg
[REG_L2PROT
]) {
3090 case ISDN_PROTO_L2_X75I
:
3091 case ISDN_PROTO_L2_X75UI
:
3092 case ISDN_PROTO_L2_X75BUI
:
3093 isdn_tty_at_cout("/X.75", info
);
3095 case ISDN_PROTO_L2_HDLC
:
3096 isdn_tty_at_cout("/HDLC", info
);
3098 case ISDN_PROTO_L2_V11096
:
3099 isdn_tty_at_cout("/V110/9600", info
);
3101 case ISDN_PROTO_L2_V11019
:
3102 isdn_tty_at_cout("/V110/19200", info
);
3104 case ISDN_PROTO_L2_V11038
:
3105 isdn_tty_at_cout("/V110/38400", info
);
3108 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
3109 isdn_tty_at_cout("/T.70", info
);
3110 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
3111 isdn_tty_at_cout("+", info
);
3115 isdn_tty_at_cout("\r\n", info
);
3118 if (code
== RESULT_NO_CARRIER
) {
3121 if ((info
->flags
& ISDN_ASYNC_CLOSING
) || (!info
->tty
)) {
3122 restore_flags(flags
);
3125 if (info
->tty
->ldisc
.flush_buffer
)
3126 info
->tty
->ldisc
.flush_buffer(info
->tty
);
3127 if ((info
->flags
& ISDN_ASYNC_CHECK_CD
) &&
3128 (!((info
->flags
& ISDN_ASYNC_CALLOUT_ACTIVE
) &&
3129 (info
->flags
& ISDN_ASYNC_CALLOUT_NOHUP
)))) {
3130 tty_hangup(info
->tty
);
3132 restore_flags(flags
);
3138 * Display a modem-register-value.
3141 isdn_tty_show_profile(int ridx
, modem_info
* info
)
3145 sprintf(v
, "\r\n%d", info
->emu
.mdmreg
[ridx
]);
3146 isdn_tty_at_cout(v
, info
);
3150 * Get MSN-string from char-pointer, set pointer to end of number
3153 isdn_tty_get_msnstr(char *n
, char **p
)
3155 int limit
= ISDN_MSNLEN
- 1;
3157 while (((*p
[0] >= '0' && *p
[0] <= '9') ||
3158 /* Why a comma ??? */
3166 * Get phone-number from modem-commandbuffer
3169 isdn_tty_getdial(char *p
, char *q
,int cnt
)
3172 int limit
= ISDN_MSNLEN
- 1; /* MUST match the size of interface var to avoid
3175 while (strchr(" 0123456789,#.*WPTS-", *p
) && *p
&& --cnt
>0) {
3176 if ((*p
>= '0' && *p
<= '9') || ((*p
== 'S') && first
) ||
3177 (*p
== '*') || (*p
== '#')) {
3189 #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
3190 #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
3193 isdn_tty_report(modem_info
* info
)
3195 atemu
*m
= &info
->emu
;
3198 isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info
);
3199 sprintf(s
, " Remote Number: %s\r\n", info
->last_num
);
3200 isdn_tty_at_cout(s
, info
);
3201 sprintf(s
, " Direction: %s\r\n", info
->last_dir
? "outgoing" : "incoming");
3202 isdn_tty_at_cout(s
, info
);
3203 isdn_tty_at_cout(" Layer-2 Protocol: ", info
);
3204 switch (info
->last_l2
) {
3205 case ISDN_PROTO_L2_X75I
:
3206 isdn_tty_at_cout("X.75i", info
);
3208 case ISDN_PROTO_L2_X75UI
:
3209 isdn_tty_at_cout("X.75ui", info
);
3211 case ISDN_PROTO_L2_X75BUI
:
3212 isdn_tty_at_cout("X.75bui", info
);
3214 case ISDN_PROTO_L2_HDLC
:
3215 isdn_tty_at_cout("HDLC", info
);
3217 case ISDN_PROTO_L2_V11096
:
3218 isdn_tty_at_cout("V.110 9600 Baud", info
);
3220 case ISDN_PROTO_L2_V11019
:
3221 isdn_tty_at_cout("V.110 19200 Baud", info
);
3223 case ISDN_PROTO_L2_V11038
:
3224 isdn_tty_at_cout("V.110 38400 Baud", info
);
3226 case ISDN_PROTO_L2_TRANS
:
3227 isdn_tty_at_cout("transparent", info
);
3229 case ISDN_PROTO_L2_MODEM
:
3230 isdn_tty_at_cout("modem", info
);
3232 case ISDN_PROTO_L2_FAX
:
3233 isdn_tty_at_cout("fax", info
);
3236 isdn_tty_at_cout("unknown", info
);
3239 if (m
->mdmreg
[REG_T70
] & BIT_T70
) {
3240 isdn_tty_at_cout("/T.70", info
);
3241 if (m
->mdmreg
[REG_T70
] & BIT_T70_EXT
)
3242 isdn_tty_at_cout("+", info
);
3244 isdn_tty_at_cout("\r\n", info
);
3245 isdn_tty_at_cout(" Service: ", info
);
3246 switch (info
->last_si
) {
3248 isdn_tty_at_cout("audio\r\n", info
);
3251 isdn_tty_at_cout("btx\r\n", info
);
3254 isdn_tty_at_cout("data\r\n", info
);
3257 sprintf(s
, "%d\r\n", info
->last_si
);
3258 isdn_tty_at_cout(s
, info
);
3261 sprintf(s
, " Hangup location: %s\r\n", info
->last_lhup
? "local" : "remote");
3262 isdn_tty_at_cout(s
, info
);
3263 sprintf(s
, " Last cause: %s\r\n", info
->last_cause
);
3264 isdn_tty_at_cout(s
, info
);
3268 * Parse AT&.. commands.
3271 isdn_tty_cmd_ATand(char **p
, modem_info
* info
)
3273 atemu
*m
= &info
->emu
;
3277 #define MAXRB (sizeof(rb) - 1)
3281 /* &B - Set Buffersize */
3284 if ((i
< 0) || (i
> ISDN_SERIAL_XMIT_MAX
))
3286 #ifdef CONFIG_ISDN_AUDIO
3287 if ((m
->mdmreg
[REG_SI1
] & 1) && (i
> VBUF
))
3290 m
->mdmreg
[REG_PSIZE
] = i
/ 16;
3291 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
3292 switch (m
->mdmreg
[REG_L2PROT
]) {
3293 case ISDN_PROTO_L2_V11096
:
3294 case ISDN_PROTO_L2_V11019
:
3295 case ISDN_PROTO_L2_V11038
:
3296 info
->xmit_size
/= 10;
3300 /* &C - DCD Status */
3302 switch (isdn_getnum(p
)) {
3304 m
->mdmreg
[REG_DCD
] &= ~BIT_DCD
;
3307 m
->mdmreg
[REG_DCD
] |= BIT_DCD
;
3314 /* &D - Set DTR-Low-behavior */
3316 switch (isdn_getnum(p
)) {
3318 m
->mdmreg
[REG_DTRHUP
] &= ~BIT_DTRHUP
;
3319 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
3322 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
3323 m
->mdmreg
[REG_DTRR
] &= ~BIT_DTRR
;
3326 m
->mdmreg
[REG_DTRHUP
] |= BIT_DTRHUP
;
3327 m
->mdmreg
[REG_DTRR
] |= BIT_DTRR
;
3334 /* &E -Set EAZ/MSN */
3336 isdn_tty_get_msnstr(m
->msn
, p
);
3339 /* &F -Set Factory-Defaults */
3341 if (info
->msr
& UART_MSR_DCD
)
3343 isdn_tty_reset_profile(m
);
3344 isdn_tty_modem_reset_regs(info
, 1);
3346 #ifdef DUMMY_HAYES_AT
3348 /* only for be compilant with common scripts */
3349 /* &K Flowcontrol - no function */
3355 /* &L -Set Numbers to listen on */
3358 while (*p
[0] && (strchr("0123456789,-*[]?;", *p
[0])) &&
3360 m
->lmsn
[i
++] = *p
[0]++;
3364 /* &R - Set V.110 bitrate adaption */
3369 /* Switch off V.110, back to X.75 */
3370 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3371 m
->mdmreg
[REG_SI2
] = 0;
3372 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
3375 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11096
;
3376 m
->mdmreg
[REG_SI2
] = 197;
3377 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
3380 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11019
;
3381 m
->mdmreg
[REG_SI2
] = 199;
3382 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
3385 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_V11038
;
3386 m
->mdmreg
[REG_SI2
] = 198; /* no existing standard for this */
3387 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16 / 10;
3392 /* Switch off T.70 */
3393 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
3395 m
->mdmreg
[REG_SI1
] |= 4;
3398 /* &S - Set Windowsize */
3401 if ((i
> 0) && (i
< 9))
3402 m
->mdmreg
[REG_WSIZE
] = i
;
3407 /* &V - Show registers */
3409 isdn_tty_at_cout("\r\n", info
);
3410 for (i
= 0; i
< ISDN_MODEM_NUMREG
; i
++) {
3411 sprintf(rb
, "S%02d=%03d%s", i
,
3412 m
->mdmreg
[i
], ((i
+ 1) % 10) ? " " : "\r\n");
3413 isdn_tty_at_cout(rb
, info
);
3415 sprintf(rb
, "\r\nEAZ/MSN: %.50s\r\n",
3416 strlen(m
->msn
) ? m
->msn
: "None");
3417 isdn_tty_at_cout(rb
, info
);
3418 if (strlen(m
->lmsn
)) {
3419 isdn_tty_at_cout("\r\nListen: ", info
);
3420 isdn_tty_at_cout(m
->lmsn
, info
);
3421 isdn_tty_at_cout("\r\n", info
);
3425 /* &W - Write Profile */
3430 modem_write_profile(m
);
3437 /* &X - Switch to BTX-Mode and T.70 */
3439 switch (isdn_getnum(p
)) {
3441 m
->mdmreg
[REG_T70
] &= ~(BIT_T70
| BIT_T70_EXT
);
3442 info
->xmit_size
= m
->mdmreg
[REG_PSIZE
] * 16;
3445 m
->mdmreg
[REG_T70
] |= BIT_T70
;
3446 m
->mdmreg
[REG_T70
] &= ~BIT_T70_EXT
;
3447 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3448 info
->xmit_size
= 112;
3449 m
->mdmreg
[REG_SI1
] = 4;
3450 m
->mdmreg
[REG_SI2
] = 0;
3453 m
->mdmreg
[REG_T70
] |= (BIT_T70
| BIT_T70_EXT
);
3454 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3455 info
->xmit_size
= 112;
3456 m
->mdmreg
[REG_SI1
] = 4;
3457 m
->mdmreg
[REG_SI2
] = 0;
3470 isdn_tty_check_ats(int mreg
, int mval
, modem_info
* info
, atemu
* m
)
3472 /* Some plausibility checks */
3475 if (mval
> ISDN_PROTO_L2_MAX
)
3479 if ((mval
* 16) > ISDN_SERIAL_XMIT_MAX
)
3481 #ifdef CONFIG_ISDN_AUDIO
3482 if ((m
->mdmreg
[REG_SI1
] & 1) && (mval
> VBUFX
))
3485 info
->xmit_size
= mval
* 16;
3486 switch (m
->mdmreg
[REG_L2PROT
]) {
3487 case ISDN_PROTO_L2_V11096
:
3488 case ISDN_PROTO_L2_V11019
:
3489 case ISDN_PROTO_L2_V11038
:
3490 info
->xmit_size
/= 10;
3496 /* readonly registers */
3503 * Perform ATS command
3506 isdn_tty_cmd_ATS(char **p
, modem_info
* info
)
3508 atemu
*m
= &info
->emu
;
3514 mreg
= isdn_getnum(p
);
3515 if (mreg
< 0 || mreg
>= ISDN_MODEM_NUMREG
)
3520 mval
= isdn_getnum(p
);
3521 if (mval
< 0 || mval
> 255)
3523 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3525 m
->mdmreg
[mreg
] = mval
;
3528 /* Set/Clear a single bit */
3530 bitpos
= isdn_getnum(p
);
3531 if ((bitpos
< 0) || (bitpos
> 7))
3536 bval
= isdn_getnum(p
);
3537 if (bval
< 0 || bval
> 1)
3540 mval
= m
->mdmreg
[mreg
] | (1 << bitpos
);
3542 mval
= m
->mdmreg
[mreg
] & ~(1 << bitpos
);
3543 if (isdn_tty_check_ats(mreg
, mval
, info
, m
))
3545 m
->mdmreg
[mreg
] = mval
;
3549 isdn_tty_at_cout("\r\n", info
);
3550 isdn_tty_at_cout((m
->mdmreg
[mreg
] & (1 << bitpos
)) ? "1" : "0",
3559 isdn_tty_show_profile(mreg
, info
);
3569 * Perform ATA command
3572 isdn_tty_cmd_ATA(modem_info
* info
)
3574 atemu
*m
= &info
->emu
;
3578 if (info
->msr
& UART_MSR_RI
) {
3579 /* Accept incoming call */
3581 strcpy(info
->last_num
, dev
->num
[info
->drv_index
]);
3582 m
->mdmreg
[REG_RINGCNT
] = 0;
3583 info
->msr
&= ~UART_MSR_RI
;
3584 l2
= m
->mdmreg
[REG_L2PROT
];
3585 #ifdef CONFIG_ISDN_AUDIO
3586 /* If more than one bit set in reg18, autoselect Layer2 */
3587 if ((m
->mdmreg
[REG_SI1
] & m
->mdmreg
[REG_SI1I
]) != m
->mdmreg
[REG_SI1
]) {
3588 if (m
->mdmreg
[REG_SI1I
] == 1) {
3589 if ((l2
!= ISDN_PROTO_L2_MODEM
) && (l2
!= ISDN_PROTO_L2_FAX
))
3590 l2
= ISDN_PROTO_L2_TRANS
;
3592 l2
= ISDN_PROTO_L2_X75I
;
3595 cmd
.driver
= info
->isdn_driver
;
3596 cmd
.command
= ISDN_CMD_SETL2
;
3597 cmd
.arg
= info
->isdn_channel
+ (l2
<< 8);
3600 cmd
.driver
= info
->isdn_driver
;
3601 cmd
.command
= ISDN_CMD_SETL3
;
3602 cmd
.arg
= info
->isdn_channel
+ (m
->mdmreg
[REG_L3PROT
] << 8);
3603 #ifdef CONFIG_ISDN_TTY_FAX
3604 if (l2
== ISDN_PROTO_L2_FAX
) {
3605 cmd
.parm
.fax
= info
->fax
;
3606 info
->fax
->direction
= ISDN_TTY_FAX_CONN_IN
;
3610 cmd
.driver
= info
->isdn_driver
;
3611 cmd
.arg
= info
->isdn_channel
;
3612 cmd
.command
= ISDN_CMD_ACCEPTD
;
3614 info
->emu
.carrierwait
= 0;
3616 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, 1);
3618 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3621 #ifdef CONFIG_ISDN_AUDIO
3623 * Parse AT+F.. commands
3626 isdn_tty_cmd_PLUSF(char **p
, modem_info
* info
)
3628 atemu
*m
= &info
->emu
;
3631 if (!strncmp(p
[0], "CLASS", 5)) {
3636 sprintf(rs
, "\r\n%d",
3637 (m
->mdmreg
[REG_SI1
] & 1) ? 8 : 0);
3638 #ifdef CONFIG_ISDN_TTY_FAX
3639 if (TTY_IS_FCLASS2(info
))
3640 sprintf(rs
, "\r\n2");
3641 else if (TTY_IS_FCLASS1(info
))
3642 sprintf(rs
, "\r\n1");
3644 isdn_tty_at_cout(rs
, info
);
3651 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3652 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3653 m
->mdmreg
[REG_SI1
] = 4;
3655 m
->mdmreg
[REG_PSIZE
] * 16;
3657 #ifdef CONFIG_ISDN_TTY_FAX
3660 if (!(dev
->global_features
&
3661 ISDN_FEATURE_L3_FCLASS1
))
3663 m
->mdmreg
[REG_SI1
] = 1;
3664 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3665 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS1
;
3667 m
->mdmreg
[REG_PSIZE
] * 16;
3671 if (!(dev
->global_features
&
3672 ISDN_FEATURE_L3_FCLASS2
))
3674 m
->mdmreg
[REG_SI1
] = 1;
3675 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_FAX
;
3676 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_FCLASS2
;
3678 m
->mdmreg
[REG_PSIZE
] * 16;
3683 /* L2 will change on dialout with si=1 */
3684 m
->mdmreg
[REG_L2PROT
] = ISDN_PROTO_L2_X75I
;
3685 m
->mdmreg
[REG_L3PROT
] = ISDN_PROTO_L3_TRANS
;
3686 m
->mdmreg
[REG_SI1
] = 5;
3687 info
->xmit_size
= VBUF
;
3691 strcpy(rs
, "\r\n0,");
3692 #ifdef CONFIG_ISDN_TTY_FAX
3693 if (dev
->global_features
&
3694 ISDN_FEATURE_L3_FCLASS1
)
3696 if (dev
->global_features
&
3697 ISDN_FEATURE_L3_FCLASS2
)
3701 isdn_tty_at_cout(rs
, info
);
3712 #ifdef CONFIG_ISDN_TTY_FAX
3713 return (isdn_tty_cmd_PLUSF_FAX(p
, info
));
3720 * Parse AT+V.. commands
3723 isdn_tty_cmd_PLUSV(char **p
, modem_info
* info
)
3725 atemu
*m
= &info
->emu
;
3727 static char *vcmd
[] =
3728 {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL
};
3736 if (!strncmp(vcmd
[i
], p
[0], 2)) {
3744 /* AT+VNH - Auto hangup feature */
3748 isdn_tty_at_cout("\r\n1", info
);
3758 isdn_tty_at_cout("\r\n1", info
);
3769 /* AT+VIP - Reset all voice parameters */
3770 isdn_tty_modem_reset_vpar(m
);
3773 /* AT+VLS - Select device, accept incoming call */
3777 sprintf(rs
, "\r\n%d", m
->vpar
[0]);
3778 isdn_tty_at_cout(rs
, info
);
3793 isdn_tty_at_cout("\r\n0,2", info
);
3804 /* AT+VRX - Start recording */
3807 if (info
->online
!= 1) {
3808 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3811 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3812 if (!info
->dtmf_state
) {
3813 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3816 info
->silence_state
= isdn_audio_silence_init(info
->silence_state
);
3817 if (!info
->silence_state
) {
3818 printk(KERN_WARNING
"isdn_tty: Couldn't malloc silence state\n");
3821 if (m
->vpar
[3] < 5) {
3822 info
->adpcmr
= isdn_audio_adpcm_init(info
->adpcmr
, m
->vpar
[3]);
3823 if (!info
->adpcmr
) {
3824 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3828 #ifdef ISDN_DEBUG_AT
3829 printk(KERN_DEBUG
"AT: +VRX\n");
3832 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3836 /* AT+VSD - Silence detection */
3840 sprintf(rs
, "\r\n<%d>,<%d>",
3843 isdn_tty_at_cout(rs
, info
);
3847 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3848 par1
= isdn_getnum(p
);
3849 if ((par1
< 0) || (par1
> 31))
3854 par2
= isdn_getnum(p
);
3855 if ((par2
< 0) || (par2
> 255))
3863 isdn_tty_at_cout("\r\n<0-31>,<0-255>",
3874 /* AT+VSM - Select compression */
3878 sprintf(rs
, "\r\n<%d>,<%d><8000>",
3881 isdn_tty_at_cout(rs
, info
);
3891 par1
= isdn_getnum(p
);
3892 if ((par1
< 2) || (par1
> 6))
3898 isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
3900 isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
3902 isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
3904 isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
3906 isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
3918 /* AT+VTX - Start sending */
3921 if (info
->online
!= 1) {
3922 isdn_tty_modem_result(RESULT_NO_ANSWER
, info
);
3925 info
->dtmf_state
= isdn_audio_dtmf_init(info
->dtmf_state
);
3926 if (!info
->dtmf_state
) {
3927 printk(KERN_WARNING
"isdn_tty: Couldn't malloc dtmf state\n");
3930 if (m
->vpar
[3] < 5) {
3931 info
->adpcms
= isdn_audio_adpcm_init(info
->adpcms
, m
->vpar
[3]);
3932 if (!info
->adpcms
) {
3933 printk(KERN_WARNING
"isdn_tty: Couldn't malloc adpcm state\n");
3937 #ifdef ISDN_DEBUG_AT
3938 printk(KERN_DEBUG
"AT: +VTX\n");
3942 isdn_tty_modem_result(RESULT_CONNECT
, info
);
3946 /* AT+VDD - DTMF detection */
3950 sprintf(rs
, "\r\n<%d>,<%d>",
3953 isdn_tty_at_cout(rs
, info
);
3957 if ((*p
[0]>='0') && (*p
[0]<='9')) {
3958 if (info
->online
!= 1)
3960 par1
= isdn_getnum(p
);
3961 if ((par1
< 0) || (par1
> 15))
3966 par2
= isdn_getnum(p
);
3967 if ((par2
< 0) || (par2
> 255))
3971 cmd
.driver
= info
->isdn_driver
;
3972 cmd
.command
= ISDN_CMD_AUDIO
;
3973 cmd
.arg
= info
->isdn_channel
+ (ISDN_AUDIO_SETDD
<< 8);
3974 cmd
.parm
.num
[0] = par1
;
3975 cmd
.parm
.num
[1] = par2
;
3981 isdn_tty_at_cout("\r\n<0-15>,<0-255>",
3996 #endif /* CONFIG_ISDN_AUDIO */
3999 * Parse and perform an AT-command-line.
4002 isdn_tty_parse_at(modem_info
* info
)
4004 atemu
*m
= &info
->emu
;
4008 #ifdef ISDN_DEBUG_AT
4009 printk(KERN_DEBUG
"AT: '%s'\n", m
->mdmcmd
);
4011 for (p
= &m
->mdmcmd
[2]; *p
;) {
4017 /* A - Accept incoming call */
4019 isdn_tty_cmd_ATA(info
);
4024 if (info
->msr
& UART_MSR_DCD
)
4026 if (info
->msr
& UART_MSR_RI
) {
4027 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
4030 isdn_tty_getdial(++p
, ds
, sizeof ds
);
4032 if (!strlen(m
->msn
))
4033 isdn_tty_modem_result(RESULT_NO_MSN_EAZ
, info
);
4034 else if (strlen(ds
))
4035 isdn_tty_dial(ds
, info
, m
);
4040 /* E - Turn Echo on/off */
4042 switch (isdn_getnum(&p
)) {
4044 m
->mdmreg
[REG_ECHO
] &= ~BIT_ECHO
;
4047 m
->mdmreg
[REG_ECHO
] |= BIT_ECHO
;
4054 /* H - On/Off-hook */
4059 isdn_tty_on_hook(info
);
4063 isdn_tty_off_hook();
4066 isdn_tty_on_hook(info
);
4071 /* I - Information */
4073 isdn_tty_at_cout("\r\nLinux ISDN", info
);
4081 isdn_tty_report(info
);
4085 sprintf(ds
, "\r\n%d", info
->emu
.charge
);
4086 isdn_tty_at_cout(ds
, info
);
4091 #ifdef DUMMY_HAYES_AT
4094 /* only for be compilant with common scripts */
4103 if (info
->msr
& UART_MSR_DCD
)
4104 /* if B-Channel is up */
4105 isdn_tty_modem_result((m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
) ? RESULT_CONNECT
:RESULT_CONNECT64000
, info
);
4107 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
4110 /* Q - Turn Emulator messages on/off */
4112 switch (isdn_getnum(&p
)) {
4114 m
->mdmreg
[REG_RESP
] |= BIT_RESP
;
4117 m
->mdmreg
[REG_RESP
] &= ~BIT_RESP
;
4124 /* S - Set/Get Register */
4126 if (isdn_tty_cmd_ATS(&p
, info
))
4130 /* V - Numeric or ASCII Emulator-messages */
4132 switch (isdn_getnum(&p
)) {
4134 m
->mdmreg
[REG_RESP
] |= BIT_RESPNUM
;
4137 m
->mdmreg
[REG_RESP
] &= ~BIT_RESPNUM
;
4144 /* Z - Load Registers from Profile */
4146 if (info
->msr
& UART_MSR_DCD
) {
4148 isdn_tty_on_hook(info
);
4150 isdn_tty_modem_reset_regs(info
, 1);
4155 #ifdef CONFIG_ISDN_AUDIO
4158 if (isdn_tty_cmd_PLUSF(&p
, info
))
4162 if ((!(m
->mdmreg
[REG_SI1
] & 1)) ||
4163 (m
->mdmreg
[REG_L2PROT
] == ISDN_PROTO_L2_MODEM
))
4166 if (isdn_tty_cmd_PLUSV(&p
, info
))
4169 #endif /* CONFIG_ISDN_AUDIO */
4170 case 'S': /* SUSPEND */
4172 isdn_tty_get_msnstr(ds
, &p
);
4173 isdn_tty_suspend(ds
, info
, m
);
4175 case 'R': /* RESUME */
4177 isdn_tty_get_msnstr(ds
, &p
);
4178 isdn_tty_resume(ds
, info
, m
);
4180 case 'M': /* MESSAGE */
4182 isdn_tty_send_msg(info
, m
, p
);
4190 if (isdn_tty_cmd_ATand(&p
, info
))
4197 #ifdef CONFIG_ISDN_AUDIO
4200 isdn_tty_modem_result(RESULT_OK
, info
);
4203 /* Need own toupper() because standard-toupper is not available
4206 #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
4209 * Perform line-editing of AT-commands
4213 * count length of buffer
4214 * channel index to line (minor-device)
4215 * user flag: buffer is in userspace
4218 isdn_tty_edit_at(const char *p
, int count
, modem_info
* info
, int user
)
4220 atemu
*m
= &info
->emu
;
4226 for (cnt
= count
; cnt
> 0; p
++, cnt
--) {
4232 if (c
== m
->mdmreg
[REG_CR
] || c
== m
->mdmreg
[REG_LF
]) {
4233 /* Separator (CR or LF) */
4234 m
->mdmcmd
[m
->mdmcmdl
] = 0;
4235 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
4238 isdn_tty_at_cout(eb
, info
);
4240 if ((m
->mdmcmdl
>= 2) && (!(strncmp(m
->mdmcmd
, "AT", 2))))
4241 isdn_tty_parse_at(info
);
4245 if (c
== m
->mdmreg
[REG_BS
] && m
->mdmreg
[REG_BS
] < 128) {
4246 /* Backspace-Function */
4247 if ((m
->mdmcmdl
> 2) || (!m
->mdmcmdl
)) {
4250 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
)
4251 isdn_tty_at_cout("\b", info
);
4256 if (m
->mdmreg
[REG_ECHO
] & BIT_ECHO
) {
4259 isdn_tty_at_cout(eb
, info
);
4261 if (m
->mdmcmdl
< 255) {
4263 switch (m
->mdmcmdl
) {
4266 m
->mdmcmd
[m
->mdmcmdl
] = c
;
4267 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
4271 /* Fall through, check for 'A' */
4274 m
->mdmcmd
[m
->mdmcmdl
] = c
;
4275 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
4279 m
->mdmcmd
[m
->mdmcmdl
] = c
;
4280 m
->mdmcmd
[++m
->mdmcmdl
] = 0;
4289 * Switch all modem-channels who are online and got a valid
4290 * escape-sequence 1.5 seconds ago, to command-mode.
4291 * This function is called every second via timer-interrupt from within
4292 * timer-dispatcher isdn_timer_function()
4295 isdn_tty_modem_escape(void)
4301 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++)
4302 if (USG_MODEM(dev
->usage
[i
]))
4303 if ((midx
= dev
->m_idx
[i
]) >= 0) {
4304 modem_info
*info
= &dev
->mdm
.info
[midx
];
4307 if ((info
->emu
.pluscount
== 3) &&
4308 ((jiffies
- info
->emu
.lastplus
) > PLUSWAIT2
)) {
4309 info
->emu
.pluscount
= 0;
4311 isdn_tty_modem_result(RESULT_OK
, info
);
4315 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS
, ton
);
4319 * Put a RING-message to all modem-channels who have the RI-bit set.
4320 * This function is called every second via timer-interrupt from within
4321 * timer-dispatcher isdn_timer_function()
4324 isdn_tty_modem_ring(void)
4329 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
4330 modem_info
*info
= &dev
->mdm
.info
[i
];
4331 if (info
->msr
& UART_MSR_RI
) {
4333 isdn_tty_modem_result(RESULT_RING
, info
);
4336 isdn_timer_ctrl(ISDN_TIMER_MODEMRING
, ton
);
4340 * For all online tty's, try sending data to
4344 isdn_tty_modem_xmit(void)
4349 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
4350 modem_info
*info
= &dev
->mdm
.info
[i
];
4353 isdn_tty_senddown(info
);
4354 isdn_tty_tint(info
);
4357 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT
, ton
);
4361 * Check all channels if we have a 'no carrier' timeout.
4362 * Timeout value is set by Register S7.
4365 isdn_tty_carrier_timeout(void)
4370 for (i
= 0; i
< ISDN_MAX_CHANNELS
; i
++) {
4371 modem_info
*info
= &dev
->mdm
.info
[i
];
4372 if (info
->dialing
) {
4373 if (info
->emu
.carrierwait
++ > info
->emu
.mdmreg
[REG_WAITC
]) {
4375 isdn_tty_modem_result(RESULT_NO_CARRIER
, info
);
4376 isdn_tty_modem_hup(info
, 1);
4382 isdn_timer_ctrl(ISDN_TIMER_CARRIER
, ton
);