Jiri Slaby | 1ca6711 | 2012-04-02 13:53:48 +0200 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). |
| 3 | * |
| 4 | * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) |
| 5 | * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg |
| 6 | * |
| 7 | * This software may be used and distributed according to the terms |
| 8 | * of the GNU General Public License, incorporated herein by reference. |
| 9 | * |
| 10 | */ |
| 11 | #undef ISDN_TTY_STAT_DEBUG |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/isdn.h> |
Jiri Slaby | 6776a2f | 2012-04-02 13:53:50 +0200 | [diff] [blame] | 14 | #include <linux/serial.h> /* ASYNC_* flags */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> |
Arnd Bergmann | 72250d4 | 2010-09-14 09:35:04 +0000 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "isdn_common.h" |
| 19 | #include "isdn_tty.h" |
| 20 | #ifdef CONFIG_ISDN_AUDIO |
| 21 | #include "isdn_audio.h" |
| 22 | #define VBUF 0x3e0 |
| 23 | #define VBUFX (VBUF/16) |
| 24 | #endif |
| 25 | |
| 26 | #define FIX_FILE_TRANSFER |
| 27 | #define DUMMY_HAYES_AT |
| 28 | |
| 29 | /* Prototypes */ |
| 30 | |
Arnd Bergmann | 72250d4 | 2010-09-14 09:35:04 +0000 | [diff] [blame] | 31 | static DEFINE_MUTEX(modem_info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int isdn_tty_edit_at(const char *, int, modem_info *); |
| 33 | static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *); |
| 34 | static void isdn_tty_modem_reset_regs(modem_info *, int); |
| 35 | static void isdn_tty_cmd_ATA(modem_info *); |
| 36 | static void isdn_tty_flush_buffer(struct tty_struct *); |
| 37 | static void isdn_tty_modem_result(int, modem_info *); |
| 38 | #ifdef CONFIG_ISDN_AUDIO |
| 39 | static int isdn_tty_countDLE(unsigned char *, int); |
| 40 | #endif |
| 41 | |
| 42 | /* Leave this unchanged unless you know what you do! */ |
| 43 | #define MODEM_PARANOIA_CHECK |
| 44 | #define MODEM_DO_RESTART |
| 45 | |
| 46 | static int bit2si[8] = |
| 47 | {1, 5, 7, 7, 7, 7, 7, 7}; |
| 48 | static int si2bit[8] = |
| 49 | {4, 1, 4, 4, 4, 4, 4, 4}; |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() |
| 52 | * to stuff incoming data directly into a tty's flip-buffer. This |
| 53 | * is done to speed up tty-receiving if the receive-queue is empty. |
| 54 | * This routine MUST be called with interrupts off. |
| 55 | * Return: |
| 56 | * 1 = Success |
| 57 | * 0 = Failure, data has to be buffered and later processed by |
| 58 | * isdn_tty_readmodem(). |
| 59 | */ |
| 60 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 61 | isdn_tty_try_read(modem_info *info, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | int c; |
| 64 | int len; |
| 65 | struct tty_struct *tty; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 66 | char last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 68 | if (!info->online) |
| 69 | return 0; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 70 | |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 71 | tty = info->port.tty; |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 72 | if (!tty) |
| 73 | return 0; |
| 74 | |
| 75 | if (!(info->mcr & UART_MCR_RTS)) |
| 76 | return 0; |
| 77 | |
| 78 | len = skb->len |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #ifdef CONFIG_ISDN_AUDIO |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 80 | + ISDN_AUDIO_SKB_DLECOUNT(skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #endif |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 82 | ; |
| 83 | |
| 84 | c = tty_buffer_request_room(tty, len); |
| 85 | if (c < len) |
| 86 | return 0; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #ifdef CONFIG_ISDN_AUDIO |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 89 | if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { |
| 90 | int l = skb->len; |
| 91 | unsigned char *dp = skb->data; |
| 92 | while (--l) { |
| 93 | if (*dp == DLE) |
| 94 | tty_insert_flip_char(tty, DLE, 0); |
| 95 | tty_insert_flip_char(tty, *dp++, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 97 | if (*dp == DLE) |
| 98 | tty_insert_flip_char(tty, DLE, 0); |
| 99 | last = *dp; |
| 100 | } else { |
| 101 | #endif |
| 102 | if (len > 1) |
| 103 | tty_insert_flip_string(tty, skb->data, len - 1); |
| 104 | last = skb->data[len - 1]; |
| 105 | #ifdef CONFIG_ISDN_AUDIO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 107 | #endif |
| 108 | if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) |
| 109 | tty_insert_flip_char(tty, last, 0xFF); |
| 110 | else |
| 111 | tty_insert_flip_char(tty, last, TTY_NORMAL); |
| 112 | tty_flip_buffer_push(tty); |
| 113 | kfree_skb(skb); |
| 114 | |
| 115 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* isdn_tty_readmodem() is called periodically from within timer-interrupt. |
| 119 | * It tries getting received data from the receive queue an stuff it into |
| 120 | * the tty's flip-buffer. |
| 121 | */ |
| 122 | void |
| 123 | isdn_tty_readmodem(void) |
| 124 | { |
| 125 | int resched = 0; |
| 126 | int midx; |
| 127 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | int r; |
| 129 | struct tty_struct *tty; |
| 130 | modem_info *info; |
| 131 | |
| 132 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 133 | midx = dev->m_idx[i]; |
| 134 | if (midx < 0) |
| 135 | continue; |
| 136 | |
| 137 | info = &dev->mdm.info[midx]; |
| 138 | if (!info->online) |
| 139 | continue; |
| 140 | |
| 141 | r = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #ifdef CONFIG_ISDN_AUDIO |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 143 | isdn_audio_eval_dtmf(info); |
| 144 | if ((info->vonline & 1) && (info->emu.vpar[1])) |
| 145 | isdn_audio_eval_silence(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | #endif |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 147 | tty = info->port.tty; |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 148 | if (tty) { |
| 149 | if (info->mcr & UART_MCR_RTS) { |
| 150 | /* CISCO AsyncPPP Hack */ |
| 151 | if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) |
| 152 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); |
| 153 | else |
| 154 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); |
| 155 | if (r) |
| 156 | tty_flip_buffer_push(tty); |
| 157 | } else |
| 158 | r = 1; |
| 159 | } else |
| 160 | r = 1; |
| 161 | if (r) { |
| 162 | info->rcvsched = 0; |
| 163 | resched = 1; |
| 164 | } else |
| 165 | info->rcvsched = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | if (!resched) |
| 168 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); |
| 169 | } |
| 170 | |
| 171 | int |
| 172 | isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb) |
| 173 | { |
| 174 | ulong flags; |
| 175 | int midx; |
| 176 | #ifdef CONFIG_ISDN_AUDIO |
| 177 | int ifmt; |
| 178 | #endif |
| 179 | modem_info *info; |
| 180 | |
| 181 | if ((midx = dev->m_idx[i]) < 0) { |
| 182 | /* if midx is invalid, packet is not for tty */ |
| 183 | return 0; |
| 184 | } |
| 185 | info = &dev->mdm.info[midx]; |
| 186 | #ifdef CONFIG_ISDN_AUDIO |
| 187 | ifmt = 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | if ((info->vonline) && (!info->emu.vpar[4])) |
| 190 | isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt); |
| 191 | if ((info->vonline & 1) && (info->emu.vpar[1])) |
| 192 | isdn_audio_calc_silence(info, skb->data, skb->len, ifmt); |
| 193 | #endif |
| 194 | if ((info->online < 2) |
| 195 | #ifdef CONFIG_ISDN_AUDIO |
| 196 | && (!(info->vonline & 1)) |
| 197 | #endif |
| 198 | ) { |
| 199 | /* If Modem not listening, drop data */ |
| 200 | kfree_skb(skb); |
| 201 | return 1; |
| 202 | } |
| 203 | if (info->emu.mdmreg[REG_T70] & BIT_T70) { |
| 204 | if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) { |
| 205 | /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */ |
| 206 | if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */ |
| 207 | skb_pull(skb, 4); |
| 208 | else |
| 209 | if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */ |
| 210 | skb_pull(skb, 2); |
| 211 | } else |
| 212 | /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */ |
| 213 | if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1))) |
| 214 | skb_pull(skb, 4); |
| 215 | } |
| 216 | #ifdef CONFIG_ISDN_AUDIO |
| 217 | ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; |
| 218 | ISDN_AUDIO_SKB_LOCK(skb) = 0; |
| 219 | if (info->vonline & 1) { |
| 220 | /* voice conversion/compression */ |
| 221 | switch (info->emu.vpar[3]) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 222 | case 2: |
| 223 | case 3: |
| 224 | case 4: |
| 225 | /* adpcm |
| 226 | * Since compressed data takes less |
| 227 | * space, we can overwrite the buffer. |
| 228 | */ |
| 229 | skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr, |
| 230 | ifmt, |
| 231 | skb->data, |
| 232 | skb->data, |
| 233 | skb->len)); |
| 234 | break; |
| 235 | case 5: |
| 236 | /* a-law */ |
| 237 | if (!ifmt) |
| 238 | isdn_audio_ulaw2alaw(skb->data, skb->len); |
| 239 | break; |
| 240 | case 6: |
| 241 | /* u-law */ |
| 242 | if (ifmt) |
| 243 | isdn_audio_alaw2ulaw(skb->data, skb->len); |
| 244 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | ISDN_AUDIO_SKB_DLECOUNT(skb) = |
| 247 | isdn_tty_countDLE(skb->data, skb->len); |
| 248 | } |
| 249 | #ifdef CONFIG_ISDN_TTY_FAX |
| 250 | else { |
| 251 | if (info->faxonline & 2) { |
| 252 | isdn_tty_fax_bitorder(info, skb); |
| 253 | ISDN_AUDIO_SKB_DLECOUNT(skb) = |
| 254 | isdn_tty_countDLE(skb->data, skb->len); |
| 255 | } |
| 256 | } |
| 257 | #endif |
| 258 | #endif |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 259 | /* Try to deliver directly via tty-buf if queue is empty */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | spin_lock_irqsave(&info->readlock, flags); |
| 261 | if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) |
| 262 | if (isdn_tty_try_read(info, skb)) { |
| 263 | spin_unlock_irqrestore(&info->readlock, flags); |
| 264 | return 1; |
| 265 | } |
| 266 | /* Direct deliver failed or queue wasn't empty. |
| 267 | * Queue up for later dequeueing via timer-irq. |
| 268 | */ |
| 269 | __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb); |
| 270 | dev->drv[di]->rcvcount[channel] += |
| 271 | (skb->len |
| 272 | #ifdef CONFIG_ISDN_AUDIO |
| 273 | + ISDN_AUDIO_SKB_DLECOUNT(skb) |
| 274 | #endif |
| 275 | ); |
| 276 | spin_unlock_irqrestore(&info->readlock, flags); |
| 277 | /* Schedule dequeuing */ |
| 278 | if ((dev->modempoll) && (info->rcvsched)) |
| 279 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); |
| 280 | return 1; |
| 281 | } |
| 282 | |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 283 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 284 | isdn_tty_cleanup_xmit(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
| 286 | skb_queue_purge(&info->xmit_queue); |
| 287 | #ifdef CONFIG_ISDN_AUDIO |
| 288 | skb_queue_purge(&info->dtmf_queue); |
| 289 | #endif |
| 290 | } |
| 291 | |
| 292 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 293 | isdn_tty_tint(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
| 295 | struct sk_buff *skb = skb_dequeue(&info->xmit_queue); |
| 296 | int len, slen; |
| 297 | |
| 298 | if (!skb) |
| 299 | return; |
| 300 | len = skb->len; |
| 301 | if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, |
| 302 | info->isdn_channel, 1, skb)) == len) { |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 303 | struct tty_struct *tty = info->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | info->send_outstanding++; |
| 305 | info->msr &= ~UART_MSR_CTS; |
| 306 | info->lsr &= ~UART_LSR_TEMT; |
| 307 | tty_wakeup(tty); |
| 308 | return; |
| 309 | } |
| 310 | if (slen < 0) { |
| 311 | /* Error: no channel, already shutdown, or wrong parameter */ |
| 312 | dev_kfree_skb(skb); |
| 313 | return; |
| 314 | } |
| 315 | skb_queue_head(&info->xmit_queue, skb); |
| 316 | } |
| 317 | |
| 318 | #ifdef CONFIG_ISDN_AUDIO |
| 319 | static int |
| 320 | isdn_tty_countDLE(unsigned char *buf, int len) |
| 321 | { |
| 322 | int count = 0; |
| 323 | |
| 324 | while (len--) |
| 325 | if (*buf++ == DLE) |
| 326 | count++; |
| 327 | return count; |
| 328 | } |
| 329 | |
| 330 | /* This routine is called from within isdn_tty_write() to perform |
| 331 | * DLE-decoding when sending audio-data. |
| 332 | */ |
| 333 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 334 | isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 336 | unsigned char *p = &info->port.xmit_buf[info->xmit_count]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int count = 0; |
| 338 | |
| 339 | while (len > 0) { |
| 340 | if (m->lastDLE) { |
| 341 | m->lastDLE = 0; |
| 342 | switch (*p) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 343 | case DLE: |
| 344 | /* Escape code */ |
| 345 | if (len > 1) |
| 346 | memmove(p, p + 1, len - 1); |
| 347 | p--; |
| 348 | count++; |
| 349 | break; |
| 350 | case ETX: |
| 351 | /* End of data */ |
| 352 | info->vonline |= 4; |
| 353 | return count; |
| 354 | case DC4: |
| 355 | /* Abort RX */ |
| 356 | info->vonline &= ~1; |
| 357 | #ifdef ISDN_DEBUG_MODEM_VOICE |
| 358 | printk(KERN_DEBUG |
| 359 | "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n", |
| 360 | info->line); |
| 361 | #endif |
| 362 | isdn_tty_at_cout("\020\003", info); |
| 363 | if (!info->vonline) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | #ifdef ISDN_DEBUG_MODEM_VOICE |
| 365 | printk(KERN_DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 366 | "DLEdown: send VCON on ttyI%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | info->line); |
| 368 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 369 | isdn_tty_at_cout("\r\nVCON\r\n", info); |
| 370 | } |
| 371 | /* Fall through */ |
| 372 | case 'q': |
| 373 | case 's': |
| 374 | /* Silence */ |
| 375 | if (len > 1) |
| 376 | memmove(p, p + 1, len - 1); |
| 377 | p--; |
| 378 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | } else { |
| 381 | if (*p == DLE) |
| 382 | m->lastDLE = 1; |
| 383 | else |
| 384 | count++; |
| 385 | } |
| 386 | p++; |
| 387 | len--; |
| 388 | } |
| 389 | if (len < 0) { |
| 390 | printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n"); |
| 391 | return 0; |
| 392 | } |
| 393 | return count; |
| 394 | } |
| 395 | |
| 396 | /* This routine is called from within isdn_tty_write() when receiving |
| 397 | * audio-data. It interrupts receiving, if an character other than |
| 398 | * ^S or ^Q is sent. |
| 399 | */ |
| 400 | static int |
| 401 | isdn_tty_end_vrx(const char *buf, int c) |
| 402 | { |
| 403 | char ch; |
| 404 | |
| 405 | while (c--) { |
| 406 | ch = *buf; |
| 407 | if ((ch != 0x11) && (ch != 0x13)) |
| 408 | return 1; |
| 409 | buf++; |
| 410 | } |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static int voice_cf[7] = |
| 415 | {0, 0, 4, 3, 2, 0, 0}; |
| 416 | |
| 417 | #endif /* CONFIG_ISDN_AUDIO */ |
| 418 | |
| 419 | /* isdn_tty_senddown() is called either directly from within isdn_tty_write() |
| 420 | * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls |
| 421 | * outgoing data from the tty's xmit-buffer, handles voice-decompression or |
| 422 | * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint. |
| 423 | */ |
| 424 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 425 | isdn_tty_senddown(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
| 427 | int buflen; |
| 428 | int skb_res; |
| 429 | #ifdef CONFIG_ISDN_AUDIO |
| 430 | int audio_len; |
| 431 | #endif |
| 432 | struct sk_buff *skb; |
| 433 | |
| 434 | #ifdef CONFIG_ISDN_AUDIO |
| 435 | if (info->vonline & 4) { |
| 436 | info->vonline &= ~6; |
| 437 | if (!info->vonline) { |
| 438 | #ifdef ISDN_DEBUG_MODEM_VOICE |
| 439 | printk(KERN_DEBUG |
| 440 | "senddown: send VCON on ttyI%d\n", |
| 441 | info->line); |
| 442 | #endif |
| 443 | isdn_tty_at_cout("\r\nVCON\r\n", info); |
| 444 | } |
| 445 | } |
| 446 | #endif |
| 447 | if (!(buflen = info->xmit_count)) |
| 448 | return; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 449 | if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | info->msr &= ~UART_MSR_CTS; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 451 | info->lsr &= ~UART_LSR_TEMT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* info->xmit_count is modified here and in isdn_tty_write(). |
| 453 | * So we return here if isdn_tty_write() is in the |
| 454 | * critical section. |
| 455 | */ |
| 456 | atomic_inc(&info->xmit_lock); |
| 457 | if (!(atomic_dec_and_test(&info->xmit_lock))) |
| 458 | return; |
| 459 | if (info->isdn_driver < 0) { |
| 460 | info->xmit_count = 0; |
| 461 | return; |
| 462 | } |
| 463 | skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4; |
| 464 | #ifdef CONFIG_ISDN_AUDIO |
| 465 | if (info->vonline & 2) |
| 466 | audio_len = buflen * voice_cf[info->emu.vpar[3]]; |
| 467 | else |
| 468 | audio_len = 0; |
| 469 | skb = dev_alloc_skb(skb_res + buflen + audio_len); |
| 470 | #else |
| 471 | skb = dev_alloc_skb(skb_res + buflen); |
| 472 | #endif |
| 473 | if (!skb) { |
| 474 | printk(KERN_WARNING |
| 475 | "isdn_tty: Out of memory in ttyI%d senddown\n", |
| 476 | info->line); |
| 477 | return; |
| 478 | } |
| 479 | skb_reserve(skb, skb_res); |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 480 | memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | info->xmit_count = 0; |
| 482 | #ifdef CONFIG_ISDN_AUDIO |
| 483 | if (info->vonline & 2) { |
| 484 | /* For now, ifmt is fixed to 1 (alaw), since this |
| 485 | * is used with ISDN everywhere in the world, except |
| 486 | * US, Canada and Japan. |
| 487 | * Later, when US-ISDN protocols are implemented, |
| 488 | * this setting will depend on the D-channel protocol. |
| 489 | */ |
| 490 | int ifmt = 1; |
| 491 | |
| 492 | /* voice conversion/decompression */ |
| 493 | switch (info->emu.vpar[3]) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 494 | case 2: |
| 495 | case 3: |
| 496 | case 4: |
| 497 | /* adpcm, compatible to ZyXel 1496 modem |
| 498 | * with ROM revision 6.01 |
| 499 | */ |
| 500 | audio_len = isdn_audio_adpcm2xlaw(info->adpcms, |
| 501 | ifmt, |
| 502 | skb->data, |
| 503 | skb_put(skb, audio_len), |
| 504 | buflen); |
| 505 | skb_pull(skb, buflen); |
| 506 | skb_trim(skb, audio_len); |
| 507 | break; |
| 508 | case 5: |
| 509 | /* a-law */ |
| 510 | if (!ifmt) |
| 511 | isdn_audio_alaw2ulaw(skb->data, |
| 512 | buflen); |
| 513 | break; |
| 514 | case 6: |
| 515 | /* u-law */ |
| 516 | if (ifmt) |
| 517 | isdn_audio_ulaw2alaw(skb->data, |
| 518 | buflen); |
| 519 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | #endif /* CONFIG_ISDN_AUDIO */ |
| 523 | if (info->emu.mdmreg[REG_T70] & BIT_T70) { |
| 524 | /* Add T.70 simplified header */ |
| 525 | if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) |
| 526 | memcpy(skb_push(skb, 2), "\1\0", 2); |
| 527 | else |
| 528 | memcpy(skb_push(skb, 4), "\1\0\1\0", 4); |
| 529 | } |
| 530 | skb_queue_tail(&info->xmit_queue, skb); |
| 531 | } |
| 532 | |
| 533 | /************************************************************ |
| 534 | * |
| 535 | * Modem-functions |
| 536 | * |
| 537 | * mostly "stolen" from original Linux-serial.c and friends. |
| 538 | * |
| 539 | ************************************************************/ |
| 540 | |
| 541 | /* The next routine is called once from within timer-interrupt |
| 542 | * triggered within isdn_tty_modem_ncarrier(). It calls |
| 543 | * isdn_tty_modem_result() to stuff a "NO CARRIER" Message |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 544 | * into the tty's buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | */ |
| 546 | static void |
| 547 | isdn_tty_modem_do_ncarrier(unsigned long data) |
| 548 | { |
| 549 | modem_info *info = (modem_info *) data; |
| 550 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
| 551 | } |
| 552 | |
| 553 | /* Next routine is called, whenever the DTR-signal is raised. |
| 554 | * It checks the ncarrier-flag, and triggers the above routine |
| 555 | * when necessary. The ncarrier-flag is set, whenever DTR goes |
| 556 | * low. |
| 557 | */ |
| 558 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 559 | isdn_tty_modem_ncarrier(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
| 561 | if (info->ncarrier) { |
| 562 | info->nc_timer.expires = jiffies + HZ; |
| 563 | add_timer(&info->nc_timer); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | * return the usage calculated by si and layer 2 protocol |
| 569 | */ |
Adrian Bunk | 3e206b0 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 570 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | isdn_calc_usage(int si, int l2) |
| 572 | { |
| 573 | int usg = ISDN_USAGE_MODEM; |
| 574 | |
| 575 | #ifdef CONFIG_ISDN_AUDIO |
| 576 | if (si == 1) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 577 | switch (l2) { |
| 578 | case ISDN_PROTO_L2_MODEM: |
| 579 | usg = ISDN_USAGE_MODEM; |
| 580 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | #ifdef CONFIG_ISDN_TTY_FAX |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 582 | case ISDN_PROTO_L2_FAX: |
| 583 | usg = ISDN_USAGE_FAX; |
| 584 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 586 | case ISDN_PROTO_L2_TRANS: |
| 587 | default: |
| 588 | usg = ISDN_USAGE_VOICE; |
| 589 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 593 | return (usg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /* isdn_tty_dial() performs dialing of a tty an the necessary |
| 597 | * setup of the lower levels before that. |
| 598 | */ |
| 599 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 600 | isdn_tty_dial(char *n, modem_info *info, atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
| 602 | int usg = ISDN_USAGE_MODEM; |
| 603 | int si = 7; |
| 604 | int l2 = m->mdmreg[REG_L2PROT]; |
| 605 | u_long flags; |
| 606 | isdn_ctrl cmd; |
| 607 | int i; |
| 608 | int j; |
| 609 | |
| 610 | for (j = 7; j >= 0; j--) |
| 611 | if (m->mdmreg[REG_SI1] & (1 << j)) { |
| 612 | si = bit2si[j]; |
| 613 | break; |
| 614 | } |
| 615 | usg = isdn_calc_usage(si, l2); |
| 616 | #ifdef CONFIG_ISDN_AUDIO |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 617 | if ((si == 1) && |
| 618 | (l2 != ISDN_PROTO_L2_MODEM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #ifdef CONFIG_ISDN_TTY_FAX |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 620 | && (l2 != ISDN_PROTO_L2_FAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | #endif |
| 622 | ) { |
| 623 | l2 = ISDN_PROTO_L2_TRANS; |
| 624 | usg = ISDN_USAGE_VOICE; |
| 625 | } |
| 626 | #endif |
| 627 | m->mdmreg[REG_SI1I] = si2bit[si]; |
| 628 | spin_lock_irqsave(&dev->lock, flags); |
| 629 | i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); |
| 630 | if (i < 0) { |
| 631 | spin_unlock_irqrestore(&dev->lock, flags); |
| 632 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); |
| 633 | } else { |
| 634 | info->isdn_driver = dev->drvmap[i]; |
| 635 | info->isdn_channel = dev->chanmap[i]; |
| 636 | info->drv_index = i; |
| 637 | dev->m_idx[i] = info->line; |
| 638 | dev->usage[i] |= ISDN_USAGE_OUTGOING; |
| 639 | info->last_dir = 1; |
| 640 | strcpy(info->last_num, n); |
| 641 | isdn_info_update(); |
| 642 | spin_unlock_irqrestore(&dev->lock, flags); |
| 643 | cmd.driver = info->isdn_driver; |
| 644 | cmd.arg = info->isdn_channel; |
| 645 | cmd.command = ISDN_CMD_CLREAZ; |
| 646 | isdn_command(&cmd); |
| 647 | strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); |
| 648 | cmd.driver = info->isdn_driver; |
| 649 | cmd.command = ISDN_CMD_SETEAZ; |
| 650 | isdn_command(&cmd); |
| 651 | cmd.driver = info->isdn_driver; |
| 652 | cmd.command = ISDN_CMD_SETL2; |
| 653 | info->last_l2 = l2; |
| 654 | cmd.arg = info->isdn_channel + (l2 << 8); |
| 655 | isdn_command(&cmd); |
| 656 | cmd.driver = info->isdn_driver; |
| 657 | cmd.command = ISDN_CMD_SETL3; |
| 658 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); |
| 659 | #ifdef CONFIG_ISDN_TTY_FAX |
| 660 | if (l2 == ISDN_PROTO_L2_FAX) { |
| 661 | cmd.parm.fax = info->fax; |
| 662 | info->fax->direction = ISDN_TTY_FAX_CONN_OUT; |
| 663 | } |
| 664 | #endif |
| 665 | isdn_command(&cmd); |
| 666 | cmd.driver = info->isdn_driver; |
| 667 | cmd.arg = info->isdn_channel; |
| 668 | sprintf(cmd.parm.setup.phone, "%s", n); |
| 669 | sprintf(cmd.parm.setup.eazmsn, "%s", |
| 670 | isdn_map_eaz2msn(m->msn, info->isdn_driver)); |
| 671 | cmd.parm.setup.si1 = si; |
| 672 | cmd.parm.setup.si2 = m->mdmreg[REG_SI2]; |
| 673 | cmd.command = ISDN_CMD_DIAL; |
| 674 | info->dialing = 1; |
| 675 | info->emu.carrierwait = 0; |
| 676 | strcpy(dev->num[i], n); |
| 677 | isdn_info_update(); |
| 678 | isdn_command(&cmd); |
| 679 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /* isdn_tty_hangup() disassociates a tty from the real |
| 684 | * ISDN-line (hangup). The usage-status is cleared |
| 685 | * and some cleanup is done also. |
| 686 | */ |
| 687 | void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 688 | isdn_tty_modem_hup(modem_info *info, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
| 690 | isdn_ctrl cmd; |
| 691 | int di, ch; |
| 692 | |
| 693 | if (!info) |
| 694 | return; |
| 695 | |
| 696 | di = info->isdn_driver; |
| 697 | ch = info->isdn_channel; |
| 698 | if (di < 0 || ch < 0) |
| 699 | return; |
| 700 | |
| 701 | info->isdn_driver = -1; |
| 702 | info->isdn_channel = -1; |
| 703 | |
| 704 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 705 | printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); |
| 706 | #endif |
| 707 | info->rcvsched = 0; |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 708 | isdn_tty_flush_buffer(info->port.tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | if (info->online) { |
| 710 | info->last_lhup = local; |
| 711 | info->online = 0; |
| 712 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
| 713 | } |
| 714 | #ifdef CONFIG_ISDN_AUDIO |
| 715 | info->vonline = 0; |
| 716 | #ifdef CONFIG_ISDN_TTY_FAX |
| 717 | info->faxonline = 0; |
| 718 | info->fax->phase = ISDN_FAX_PHASE_IDLE; |
| 719 | #endif |
| 720 | info->emu.vpar[4] = 0; |
| 721 | info->emu.vpar[5] = 8; |
Jesper Juhl | 3c7208f | 2005-11-07 01:01:29 -0800 | [diff] [blame] | 722 | kfree(info->dtmf_state); |
| 723 | info->dtmf_state = NULL; |
| 724 | kfree(info->silence_state); |
| 725 | info->silence_state = NULL; |
| 726 | kfree(info->adpcms); |
| 727 | info->adpcms = NULL; |
| 728 | kfree(info->adpcmr); |
| 729 | info->adpcmr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | #endif |
| 731 | if ((info->msr & UART_MSR_RI) && |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 732 | (info->emu.mdmreg[REG_RUNG] & BIT_RUNG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | isdn_tty_modem_result(RESULT_RUNG, info); |
| 734 | info->msr &= ~(UART_MSR_DCD | UART_MSR_RI); |
| 735 | info->lsr |= UART_LSR_TEMT; |
| 736 | |
| 737 | if (local) { |
| 738 | cmd.driver = di; |
| 739 | cmd.command = ISDN_CMD_HANGUP; |
| 740 | cmd.arg = ch; |
| 741 | isdn_command(&cmd); |
| 742 | } |
| 743 | |
| 744 | isdn_all_eaz(di, ch); |
| 745 | info->emu.mdmreg[REG_RINGCNT] = 0; |
| 746 | isdn_free_channel(di, ch, 0); |
| 747 | |
| 748 | if (info->drv_index >= 0) { |
| 749 | dev->m_idx[info->drv_index] = -1; |
| 750 | info->drv_index = -1; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | /* |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 755 | * Begin of a CAPI like interface, currently used only for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | * supplementary service (CAPI 2.0 part III) |
| 757 | */ |
| 758 | #include <linux/isdn/capicmd.h> |
Paul Gortmaker | 07a97fe | 2011-08-30 12:08:51 -0400 | [diff] [blame] | 759 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | int |
| 762 | isdn_tty_capi_facility(capi_msg *cm) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 763 | return (-1); /* dummy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /* isdn_tty_suspend() tries to suspend the current tty connection |
| 767 | */ |
| 768 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 769 | isdn_tty_suspend(char *id, modem_info *info, atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
| 771 | isdn_ctrl cmd; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | int l; |
| 774 | |
| 775 | if (!info) |
| 776 | return; |
| 777 | |
| 778 | #ifdef ISDN_DEBUG_MODEM_SERVICES |
| 779 | printk(KERN_DEBUG "Msusp ttyI%d\n", info->line); |
| 780 | #endif |
| 781 | l = strlen(id); |
| 782 | if ((info->isdn_driver >= 0)) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 783 | cmd.parm.cmsg.Length = l + 18; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | cmd.parm.cmsg.Command = CAPI_FACILITY; |
| 785 | cmd.parm.cmsg.Subcommand = CAPI_REQ; |
| 786 | cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; |
| 787 | cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */ |
| 788 | cmd.parm.cmsg.para[1] = 0; |
| 789 | cmd.parm.cmsg.para[2] = l + 3; |
| 790 | cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */ |
| 791 | cmd.parm.cmsg.para[4] = 0; |
| 792 | cmd.parm.cmsg.para[5] = l; |
| 793 | strncpy(&cmd.parm.cmsg.para[6], id, l); |
| 794 | cmd.command = CAPI_PUT_MESSAGE; |
| 795 | cmd.driver = info->isdn_driver; |
| 796 | cmd.arg = info->isdn_channel; |
| 797 | isdn_command(&cmd); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /* isdn_tty_resume() tries to resume a suspended call |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 802 | * setup of the lower levels before that. unfortunately here is no |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | * checking for compatibility of used protocols implemented by Q931 |
| 804 | * It does the same things like isdn_tty_dial, the last command |
| 805 | * is different, may be we can merge it. |
| 806 | */ |
| 807 | |
| 808 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 809 | isdn_tty_resume(char *id, modem_info *info, atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { |
| 811 | int usg = ISDN_USAGE_MODEM; |
| 812 | int si = 7; |
| 813 | int l2 = m->mdmreg[REG_L2PROT]; |
| 814 | isdn_ctrl cmd; |
| 815 | ulong flags; |
| 816 | int i; |
| 817 | int j; |
| 818 | int l; |
| 819 | |
| 820 | l = strlen(id); |
| 821 | for (j = 7; j >= 0; j--) |
| 822 | if (m->mdmreg[REG_SI1] & (1 << j)) { |
| 823 | si = bit2si[j]; |
| 824 | break; |
| 825 | } |
| 826 | usg = isdn_calc_usage(si, l2); |
| 827 | #ifdef CONFIG_ISDN_AUDIO |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 828 | if ((si == 1) && |
| 829 | (l2 != ISDN_PROTO_L2_MODEM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | #ifdef CONFIG_ISDN_TTY_FAX |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 831 | && (l2 != ISDN_PROTO_L2_FAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | #endif |
| 833 | ) { |
| 834 | l2 = ISDN_PROTO_L2_TRANS; |
| 835 | usg = ISDN_USAGE_VOICE; |
| 836 | } |
| 837 | #endif |
| 838 | m->mdmreg[REG_SI1I] = si2bit[si]; |
| 839 | spin_lock_irqsave(&dev->lock, flags); |
| 840 | i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); |
| 841 | if (i < 0) { |
| 842 | spin_unlock_irqrestore(&dev->lock, flags); |
| 843 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); |
| 844 | } else { |
| 845 | info->isdn_driver = dev->drvmap[i]; |
| 846 | info->isdn_channel = dev->chanmap[i]; |
| 847 | info->drv_index = i; |
| 848 | dev->m_idx[i] = info->line; |
| 849 | dev->usage[i] |= ISDN_USAGE_OUTGOING; |
| 850 | info->last_dir = 1; |
| 851 | // strcpy(info->last_num, n); |
| 852 | isdn_info_update(); |
| 853 | spin_unlock_irqrestore(&dev->lock, flags); |
| 854 | cmd.driver = info->isdn_driver; |
| 855 | cmd.arg = info->isdn_channel; |
| 856 | cmd.command = ISDN_CMD_CLREAZ; |
| 857 | isdn_command(&cmd); |
| 858 | strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); |
| 859 | cmd.driver = info->isdn_driver; |
| 860 | cmd.command = ISDN_CMD_SETEAZ; |
| 861 | isdn_command(&cmd); |
| 862 | cmd.driver = info->isdn_driver; |
| 863 | cmd.command = ISDN_CMD_SETL2; |
| 864 | info->last_l2 = l2; |
| 865 | cmd.arg = info->isdn_channel + (l2 << 8); |
| 866 | isdn_command(&cmd); |
| 867 | cmd.driver = info->isdn_driver; |
| 868 | cmd.command = ISDN_CMD_SETL3; |
| 869 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); |
| 870 | isdn_command(&cmd); |
| 871 | cmd.driver = info->isdn_driver; |
| 872 | cmd.arg = info->isdn_channel; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 873 | cmd.parm.cmsg.Length = l + 18; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | cmd.parm.cmsg.Command = CAPI_FACILITY; |
| 875 | cmd.parm.cmsg.Subcommand = CAPI_REQ; |
| 876 | cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; |
| 877 | cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */ |
| 878 | cmd.parm.cmsg.para[1] = 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 879 | cmd.parm.cmsg.para[2] = l + 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */ |
| 881 | cmd.parm.cmsg.para[4] = 0; |
| 882 | cmd.parm.cmsg.para[5] = l; |
| 883 | strncpy(&cmd.parm.cmsg.para[6], id, l); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 884 | cmd.command = CAPI_PUT_MESSAGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | info->dialing = 1; |
| 886 | // strcpy(dev->num[i], n); |
| 887 | isdn_info_update(); |
| 888 | isdn_command(&cmd); |
| 889 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | /* isdn_tty_send_msg() sends a message to a HL driver |
| 894 | * This is used for hybrid modem cards to send AT commands to it |
| 895 | */ |
| 896 | |
| 897 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 898 | isdn_tty_send_msg(modem_info *info, atemu *m, char *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
| 900 | int usg = ISDN_USAGE_MODEM; |
| 901 | int si = 7; |
| 902 | int l2 = m->mdmreg[REG_L2PROT]; |
| 903 | isdn_ctrl cmd; |
| 904 | ulong flags; |
| 905 | int i; |
| 906 | int j; |
| 907 | int l; |
| 908 | |
| 909 | l = strlen(msg); |
| 910 | if (!l) { |
| 911 | isdn_tty_modem_result(RESULT_ERROR, info); |
| 912 | return; |
| 913 | } |
| 914 | for (j = 7; j >= 0; j--) |
| 915 | if (m->mdmreg[REG_SI1] & (1 << j)) { |
| 916 | si = bit2si[j]; |
| 917 | break; |
| 918 | } |
| 919 | usg = isdn_calc_usage(si, l2); |
| 920 | #ifdef CONFIG_ISDN_AUDIO |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 921 | if ((si == 1) && |
| 922 | (l2 != ISDN_PROTO_L2_MODEM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | #ifdef CONFIG_ISDN_TTY_FAX |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 924 | && (l2 != ISDN_PROTO_L2_FAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | #endif |
| 926 | ) { |
| 927 | l2 = ISDN_PROTO_L2_TRANS; |
| 928 | usg = ISDN_USAGE_VOICE; |
| 929 | } |
| 930 | #endif |
| 931 | m->mdmreg[REG_SI1I] = si2bit[si]; |
| 932 | spin_lock_irqsave(&dev->lock, flags); |
| 933 | i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); |
| 934 | if (i < 0) { |
| 935 | spin_unlock_irqrestore(&dev->lock, flags); |
| 936 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); |
| 937 | } else { |
| 938 | info->isdn_driver = dev->drvmap[i]; |
| 939 | info->isdn_channel = dev->chanmap[i]; |
| 940 | info->drv_index = i; |
| 941 | dev->m_idx[i] = info->line; |
| 942 | dev->usage[i] |= ISDN_USAGE_OUTGOING; |
| 943 | info->last_dir = 1; |
| 944 | isdn_info_update(); |
| 945 | spin_unlock_irqrestore(&dev->lock, flags); |
| 946 | cmd.driver = info->isdn_driver; |
| 947 | cmd.arg = info->isdn_channel; |
| 948 | cmd.command = ISDN_CMD_CLREAZ; |
| 949 | isdn_command(&cmd); |
| 950 | strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); |
| 951 | cmd.driver = info->isdn_driver; |
| 952 | cmd.command = ISDN_CMD_SETEAZ; |
| 953 | isdn_command(&cmd); |
| 954 | cmd.driver = info->isdn_driver; |
| 955 | cmd.command = ISDN_CMD_SETL2; |
| 956 | info->last_l2 = l2; |
| 957 | cmd.arg = info->isdn_channel + (l2 << 8); |
| 958 | isdn_command(&cmd); |
| 959 | cmd.driver = info->isdn_driver; |
| 960 | cmd.command = ISDN_CMD_SETL3; |
| 961 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); |
| 962 | isdn_command(&cmd); |
| 963 | cmd.driver = info->isdn_driver; |
| 964 | cmd.arg = info->isdn_channel; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 965 | cmd.parm.cmsg.Length = l + 14; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | cmd.parm.cmsg.Command = CAPI_MANUFACTURER; |
| 967 | cmd.parm.cmsg.Subcommand = CAPI_REQ; |
| 968 | cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 969 | cmd.parm.cmsg.para[0] = l + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | strncpy(&cmd.parm.cmsg.para[1], msg, l); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 971 | cmd.parm.cmsg.para[l + 1] = 0xd; |
| 972 | cmd.command = CAPI_PUT_MESSAGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | /* info->dialing = 1; |
| 974 | strcpy(dev->num[i], n); |
| 975 | isdn_info_update(); |
| 976 | */ |
| 977 | isdn_command(&cmd); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | static inline int |
| 982 | isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine) |
| 983 | { |
| 984 | #ifdef MODEM_PARANOIA_CHECK |
| 985 | if (!info) { |
| 986 | printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 987 | name, routine); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | return 1; |
| 989 | } |
| 990 | if (info->magic != ISDN_ASYNC_MAGIC) { |
| 991 | printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n", |
| 992 | name, routine); |
| 993 | return 1; |
| 994 | } |
| 995 | #endif |
| 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | /* |
| 1000 | * This routine is called to set the UART divisor registers to match |
| 1001 | * the specified baud rate for a serial port. |
| 1002 | */ |
| 1003 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1004 | isdn_tty_change_speed(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | { |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1006 | struct tty_port *port = &info->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | uint cflag, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1008 | cval, |
| 1009 | quot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | int i; |
| 1011 | |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1012 | if (!port->tty || !port->tty->termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | return; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1014 | cflag = port->tty->termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | |
| 1016 | quot = i = cflag & CBAUD; |
| 1017 | if (i & CBAUDEX) { |
| 1018 | i &= ~CBAUDEX; |
| 1019 | if (i < 1 || i > 2) |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1020 | port->tty->termios->c_cflag &= ~CBAUDEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | else |
| 1022 | i += 15; |
| 1023 | } |
| 1024 | if (quot) { |
| 1025 | info->mcr |= UART_MCR_DTR; |
| 1026 | isdn_tty_modem_ncarrier(info); |
| 1027 | } else { |
| 1028 | info->mcr &= ~UART_MCR_DTR; |
| 1029 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { |
| 1030 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 1031 | printk(KERN_DEBUG "Mhup in changespeed\n"); |
| 1032 | #endif |
| 1033 | if (info->online) |
| 1034 | info->ncarrier = 1; |
| 1035 | isdn_tty_modem_reset_regs(info, 0); |
| 1036 | isdn_tty_modem_hup(info, 1); |
| 1037 | } |
| 1038 | return; |
| 1039 | } |
| 1040 | /* byte size and parity */ |
| 1041 | cval = cflag & (CSIZE | CSTOPB); |
| 1042 | cval >>= 4; |
| 1043 | if (cflag & PARENB) |
| 1044 | cval |= UART_LCR_PARITY; |
| 1045 | if (!(cflag & PARODD)) |
| 1046 | cval |= UART_LCR_EPAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | /* CTS flow control flag and modem status interrupts */ |
| 1049 | if (cflag & CRTSCTS) { |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1050 | port->flags |= ASYNC_CTS_FLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } else |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1052 | port->flags &= ~ASYNC_CTS_FLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | if (cflag & CLOCAL) |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1054 | port->flags &= ~ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | else { |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1056 | port->flags |= ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1061 | isdn_tty_startup(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 1063 | if (info->port.flags & ASYNC_INITIALIZED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | return 0; |
| 1065 | isdn_lock_drivers(); |
| 1066 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1067 | printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line); |
| 1068 | #endif |
| 1069 | /* |
| 1070 | * Now, initialize the UART |
| 1071 | */ |
| 1072 | info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 1073 | if (info->port.tty) |
| 1074 | clear_bit(TTY_IO_ERROR, &info->port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | /* |
| 1076 | * and set the speed of the serial port |
| 1077 | */ |
| 1078 | isdn_tty_change_speed(info); |
| 1079 | |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 1080 | info->port.flags |= ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | info->msr |= (UART_MSR_DSR | UART_MSR_CTS); |
| 1082 | info->send_outstanding = 0; |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | /* |
| 1087 | * This routine will shutdown a serial port; interrupts are disabled, and |
| 1088 | * DTR is dropped if the hangup on close termio flag is on. |
| 1089 | */ |
| 1090 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1091 | isdn_tty_shutdown(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 1093 | if (!(info->port.flags & ASYNC_INITIALIZED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | return; |
| 1095 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1096 | printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); |
| 1097 | #endif |
| 1098 | isdn_unlock_drivers(); |
| 1099 | info->msr &= ~UART_MSR_RI; |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 1100 | if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); |
| 1102 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { |
| 1103 | isdn_tty_modem_reset_regs(info, 0); |
| 1104 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 1105 | printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n"); |
| 1106 | #endif |
| 1107 | isdn_tty_modem_hup(info, 1); |
| 1108 | } |
| 1109 | } |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 1110 | if (info->port.tty) |
| 1111 | set_bit(TTY_IO_ERROR, &info->port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 1113 | info->port.flags &= ~ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /* isdn_tty_write() is the main send-routine. It is called from the upper |
| 1117 | * levels within the kernel to perform sending data. Depending on the |
| 1118 | * online-flag it either directs output to the at-command-interpreter or |
| 1119 | * to the lower level. Additional tasks done here: |
| 1120 | * - If online, check for escape-sequence (+++) |
| 1121 | * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes. |
| 1122 | * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed. |
| 1123 | * - If dialing, abort dial. |
| 1124 | */ |
| 1125 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1126 | isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | { |
| 1128 | int c; |
| 1129 | int total = 0; |
| 1130 | modem_info *info = (modem_info *) tty->driver_data; |
| 1131 | atemu *m = &info->emu; |
| 1132 | |
| 1133 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write")) |
| 1134 | return 0; |
| 1135 | /* See isdn_tty_senddown() */ |
| 1136 | atomic_inc(&info->xmit_lock); |
| 1137 | while (1) { |
| 1138 | c = count; |
| 1139 | if (c > info->xmit_size - info->xmit_count) |
| 1140 | c = info->xmit_size - info->xmit_count; |
| 1141 | if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize) |
| 1142 | c = dev->drv[info->isdn_driver]->maxbufsize; |
| 1143 | if (c <= 0) |
| 1144 | break; |
| 1145 | if ((info->online > 1) |
| 1146 | #ifdef CONFIG_ISDN_AUDIO |
| 1147 | || (info->vonline & 3) |
| 1148 | #endif |
| 1149 | ) { |
| 1150 | #ifdef CONFIG_ISDN_AUDIO |
| 1151 | if (!info->vonline) |
| 1152 | #endif |
| 1153 | isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, |
| 1154 | &(m->pluscount), |
| 1155 | &(m->lastplus)); |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 1156 | memcpy(&info->port.xmit_buf[info->xmit_count], buf, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | #ifdef CONFIG_ISDN_AUDIO |
| 1158 | if (info->vonline) { |
| 1159 | int cc = isdn_tty_handleDLEdown(info, m, c); |
| 1160 | if (info->vonline & 2) { |
| 1161 | if (!cc) { |
| 1162 | /* If DLE decoding results in zero-transmit, but |
| 1163 | * c originally was non-zero, do a wakeup. |
| 1164 | */ |
| 1165 | tty_wakeup(tty); |
| 1166 | info->msr |= UART_MSR_CTS; |
| 1167 | info->lsr |= UART_LSR_TEMT; |
| 1168 | } |
| 1169 | info->xmit_count += cc; |
| 1170 | } |
| 1171 | if ((info->vonline & 3) == 1) { |
| 1172 | /* Do NOT handle Ctrl-Q or Ctrl-S |
| 1173 | * when in full-duplex audio mode. |
| 1174 | */ |
| 1175 | if (isdn_tty_end_vrx(buf, c)) { |
| 1176 | info->vonline &= ~1; |
| 1177 | #ifdef ISDN_DEBUG_MODEM_VOICE |
| 1178 | printk(KERN_DEBUG |
| 1179 | "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n", |
| 1180 | info->line); |
| 1181 | #endif |
| 1182 | isdn_tty_at_cout("\020\003\r\nVCON\r\n", info); |
| 1183 | } |
| 1184 | } |
| 1185 | } else |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1186 | if (TTY_IS_FCLASS1(info)) { |
| 1187 | int cc = isdn_tty_handleDLEdown(info, m, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1189 | if (info->vonline & 4) { /* ETX seen */ |
| 1190 | isdn_ctrl c; |
| 1191 | |
| 1192 | c.command = ISDN_CMD_FAXCMD; |
| 1193 | c.driver = info->isdn_driver; |
| 1194 | c.arg = info->isdn_channel; |
| 1195 | c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL; |
| 1196 | c.parm.aux.subcmd = ETX; |
| 1197 | isdn_command(&c); |
| 1198 | } |
| 1199 | info->vonline = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | #ifdef ISDN_DEBUG_MODEM_VOICE |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1201 | printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1203 | info->xmit_count += cc; |
| 1204 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1206 | info->xmit_count += c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | } else { |
| 1208 | info->msr |= UART_MSR_CTS; |
| 1209 | info->lsr |= UART_LSR_TEMT; |
| 1210 | if (info->dialing) { |
| 1211 | info->dialing = 0; |
| 1212 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 1213 | printk(KERN_DEBUG "Mhup in isdn_tty_write\n"); |
| 1214 | #endif |
| 1215 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
| 1216 | isdn_tty_modem_hup(info, 1); |
| 1217 | } else |
| 1218 | c = isdn_tty_edit_at(buf, c, info); |
| 1219 | } |
| 1220 | buf += c; |
| 1221 | count -= c; |
| 1222 | total += c; |
| 1223 | } |
| 1224 | atomic_dec(&info->xmit_lock); |
David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 1225 | if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | if (m->mdmreg[REG_DXMT] & BIT_DXMT) { |
| 1227 | isdn_tty_senddown(info); |
| 1228 | isdn_tty_tint(info); |
| 1229 | } |
| 1230 | isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); |
| 1231 | } |
| 1232 | return total; |
| 1233 | } |
| 1234 | |
| 1235 | static int |
| 1236 | isdn_tty_write_room(struct tty_struct *tty) |
| 1237 | { |
| 1238 | modem_info *info = (modem_info *) tty->driver_data; |
| 1239 | int ret; |
| 1240 | |
| 1241 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room")) |
| 1242 | return 0; |
| 1243 | if (!info->online) |
| 1244 | return info->xmit_size; |
| 1245 | ret = info->xmit_size - info->xmit_count; |
| 1246 | return (ret < 0) ? 0 : ret; |
| 1247 | } |
| 1248 | |
| 1249 | static int |
| 1250 | isdn_tty_chars_in_buffer(struct tty_struct *tty) |
| 1251 | { |
| 1252 | modem_info *info = (modem_info *) tty->driver_data; |
| 1253 | |
| 1254 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer")) |
| 1255 | return 0; |
| 1256 | if (!info->online) |
| 1257 | return 0; |
| 1258 | return (info->xmit_count); |
| 1259 | } |
| 1260 | |
| 1261 | static void |
| 1262 | isdn_tty_flush_buffer(struct tty_struct *tty) |
| 1263 | { |
| 1264 | modem_info *info; |
| 1265 | |
| 1266 | if (!tty) { |
| 1267 | return; |
| 1268 | } |
| 1269 | info = (modem_info *) tty->driver_data; |
| 1270 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) { |
| 1271 | return; |
| 1272 | } |
| 1273 | isdn_tty_cleanup_xmit(info); |
| 1274 | info->xmit_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | tty_wakeup(tty); |
| 1276 | } |
| 1277 | |
| 1278 | static void |
| 1279 | isdn_tty_flush_chars(struct tty_struct *tty) |
| 1280 | { |
| 1281 | modem_info *info = (modem_info *) tty->driver_data; |
| 1282 | |
| 1283 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars")) |
| 1284 | return; |
David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 1285 | if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); |
| 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * ------------------------------------------------------------ |
| 1291 | * isdn_tty_throttle() |
| 1292 | * |
| 1293 | * This routine is called by the upper-layer tty layer to signal that |
| 1294 | * incoming characters should be throttled. |
| 1295 | * ------------------------------------------------------------ |
| 1296 | */ |
| 1297 | static void |
| 1298 | isdn_tty_throttle(struct tty_struct *tty) |
| 1299 | { |
| 1300 | modem_info *info = (modem_info *) tty->driver_data; |
| 1301 | |
| 1302 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle")) |
| 1303 | return; |
| 1304 | if (I_IXOFF(tty)) |
| 1305 | info->x_char = STOP_CHAR(tty); |
| 1306 | info->mcr &= ~UART_MCR_RTS; |
| 1307 | } |
| 1308 | |
| 1309 | static void |
| 1310 | isdn_tty_unthrottle(struct tty_struct *tty) |
| 1311 | { |
| 1312 | modem_info *info = (modem_info *) tty->driver_data; |
| 1313 | |
| 1314 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle")) |
| 1315 | return; |
| 1316 | if (I_IXOFF(tty)) { |
| 1317 | if (info->x_char) |
| 1318 | info->x_char = 0; |
| 1319 | else |
| 1320 | info->x_char = START_CHAR(tty); |
| 1321 | } |
| 1322 | info->mcr |= UART_MCR_RTS; |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * ------------------------------------------------------------ |
| 1327 | * isdn_tty_ioctl() and friends |
| 1328 | * ------------------------------------------------------------ |
| 1329 | */ |
| 1330 | |
| 1331 | /* |
| 1332 | * isdn_tty_get_lsr_info - get line status register info |
| 1333 | * |
| 1334 | * Purpose: Let user call ioctl() to get info when the UART physically |
| 1335 | * is emptied. On bus types like RS485, the transmitter must |
| 1336 | * release the bus after transmitting. This must be done when |
| 1337 | * the transmit shift register is empty, not be done when the |
| 1338 | * transmit holding register is empty. This functionality |
| 1339 | * allows RS485 driver to be written in user space. |
| 1340 | */ |
| 1341 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1342 | isdn_tty_get_lsr_info(modem_info *info, uint __user *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | { |
| 1344 | u_char status; |
| 1345 | uint result; |
| 1346 | |
| 1347 | status = info->lsr; |
| 1348 | result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); |
| 1349 | return put_user(result, value); |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | static int |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 1354 | isdn_tty_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | { |
| 1356 | modem_info *info = (modem_info *) tty->driver_data; |
| 1357 | u_char control, status; |
| 1358 | |
Harvey Harrison | 156f1ed | 2008-04-28 02:14:40 -0700 | [diff] [blame] | 1359 | if (isdn_tty_paranoia_check(info, tty->name, __func__)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | return -ENODEV; |
| 1361 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 1362 | return -EIO; |
| 1363 | |
Arnd Bergmann | 72250d4 | 2010-09-14 09:35:04 +0000 | [diff] [blame] | 1364 | mutex_lock(&modem_info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
| 1366 | printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line); |
| 1367 | #endif |
| 1368 | |
| 1369 | control = info->mcr; |
| 1370 | status = info->msr; |
Arnd Bergmann | 72250d4 | 2010-09-14 09:35:04 +0000 | [diff] [blame] | 1371 | mutex_unlock(&modem_info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1373 | | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
| 1374 | | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
| 1375 | | ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
| 1376 | | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
| 1377 | | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | static int |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 1381 | isdn_tty_tiocmset(struct tty_struct *tty, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1382 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | { |
| 1384 | modem_info *info = (modem_info *) tty->driver_data; |
| 1385 | |
Harvey Harrison | 156f1ed | 2008-04-28 02:14:40 -0700 | [diff] [blame] | 1386 | if (isdn_tty_paranoia_check(info, tty->name, __func__)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | return -ENODEV; |
| 1388 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 1389 | return -EIO; |
| 1390 | |
| 1391 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
| 1392 | printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear); |
| 1393 | #endif |
| 1394 | |
Arnd Bergmann | 72250d4 | 2010-09-14 09:35:04 +0000 | [diff] [blame] | 1395 | mutex_lock(&modem_info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | if (set & TIOCM_RTS) |
| 1397 | info->mcr |= UART_MCR_RTS; |
| 1398 | if (set & TIOCM_DTR) { |
| 1399 | info->mcr |= UART_MCR_DTR; |
| 1400 | isdn_tty_modem_ncarrier(info); |
| 1401 | } |
| 1402 | |
| 1403 | if (clear & TIOCM_RTS) |
| 1404 | info->mcr &= ~UART_MCR_RTS; |
| 1405 | if (clear & TIOCM_DTR) { |
| 1406 | info->mcr &= ~UART_MCR_DTR; |
| 1407 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { |
| 1408 | isdn_tty_modem_reset_regs(info, 0); |
| 1409 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 1410 | printk(KERN_DEBUG "Mhup in TIOCMSET\n"); |
| 1411 | #endif |
| 1412 | if (info->online) |
| 1413 | info->ncarrier = 1; |
| 1414 | isdn_tty_modem_hup(info, 1); |
| 1415 | } |
| 1416 | } |
Arnd Bergmann | 72250d4 | 2010-09-14 09:35:04 +0000 | [diff] [blame] | 1417 | mutex_unlock(&modem_info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | static int |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 1422 | isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | { |
| 1424 | modem_info *info = (modem_info *) tty->driver_data; |
| 1425 | int retval; |
| 1426 | |
| 1427 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl")) |
| 1428 | return -ENODEV; |
| 1429 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 1430 | return -EIO; |
| 1431 | switch (cmd) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1432 | case TCSBRK: /* SVID version: non-zero arg --> no break */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1434 | printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1436 | retval = tty_check_change(tty); |
| 1437 | if (retval) |
| 1438 | return retval; |
| 1439 | tty_wait_until_sent(tty, 0); |
| 1440 | return 0; |
| 1441 | case TCSBRKP: /* support for POSIX tcsendbreak() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1443 | printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1445 | retval = tty_check_change(tty); |
| 1446 | if (retval) |
| 1447 | return retval; |
| 1448 | tty_wait_until_sent(tty, 0); |
| 1449 | return 0; |
| 1450 | case TIOCSERGETLSR: /* Get line status register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1452 | printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1454 | return isdn_tty_get_lsr_info(info, (uint __user *) arg); |
| 1455 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | #ifdef ISDN_DEBUG_MODEM_IOCTL |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1457 | printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1459 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | } |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | static void |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1465 | isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | { |
| 1467 | modem_info *info = (modem_info *) tty->driver_data; |
| 1468 | |
| 1469 | if (!old_termios) |
| 1470 | isdn_tty_change_speed(info); |
| 1471 | else { |
Alan Cox | 6e4d376 | 2008-04-30 00:53:27 -0700 | [diff] [blame] | 1472 | if (tty->termios->c_cflag == old_termios->c_cflag && |
| 1473 | tty->termios->c_ispeed == old_termios->c_ispeed && |
| 1474 | tty->termios->c_ospeed == old_termios->c_ospeed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | return; |
| 1476 | isdn_tty_change_speed(info); |
| 1477 | if ((old_termios->c_cflag & CRTSCTS) && |
Alan Cox | 6e4d376 | 2008-04-30 00:53:27 -0700 | [diff] [blame] | 1478 | !(tty->termios->c_cflag & CRTSCTS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | tty->hw_stopped = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | /* |
| 1484 | * ------------------------------------------------------------ |
| 1485 | * isdn_tty_open() and friends |
| 1486 | * ------------------------------------------------------------ |
| 1487 | */ |
| 1488 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1489 | isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | { |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1491 | struct tty_port *port = &info->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | DECLARE_WAITQUEUE(wait, NULL); |
| 1493 | int do_clocal = 0; |
| 1494 | int retval; |
| 1495 | |
| 1496 | /* |
| 1497 | * If the device is in the middle of being closed, then block |
| 1498 | * until it's done, and then try again. |
| 1499 | */ |
| 1500 | if (tty_hung_up_p(filp) || |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1501 | (port->flags & ASYNC_CLOSING)) { |
| 1502 | if (port->flags & ASYNC_CLOSING) |
| 1503 | interruptible_sleep_on(&port->close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | #ifdef MODEM_DO_RESTART |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1505 | if (port->flags & ASYNC_HUP_NOTIFY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | return -EAGAIN; |
| 1507 | else |
| 1508 | return -ERESTARTSYS; |
| 1509 | #else |
| 1510 | return -EAGAIN; |
| 1511 | #endif |
| 1512 | } |
| 1513 | /* |
| 1514 | * If non-blocking mode is set, then make the check up front |
| 1515 | * and then exit. |
| 1516 | */ |
| 1517 | if ((filp->f_flags & O_NONBLOCK) || |
| 1518 | (tty->flags & (1 << TTY_IO_ERROR))) { |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1519 | port->flags |= ASYNC_NORMAL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | return 0; |
| 1521 | } |
Jiri Slaby | 05eb48b | 2012-04-02 13:53:49 +0200 | [diff] [blame] | 1522 | if (tty->termios->c_cflag & CLOCAL) |
| 1523 | do_clocal = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | /* |
| 1525 | * Block waiting for the carrier detect and the line to become |
| 1526 | * free (i.e., not in use by the callout). While we are in |
| 1527 | * this loop, info->count is dropped by one, so that |
| 1528 | * isdn_tty_close() knows when to free things. We restore it upon |
| 1529 | * exit, either normal or abnormal. |
| 1530 | */ |
| 1531 | retval = 0; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1532 | add_wait_queue(&port->open_wait, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1534 | printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n", |
| 1535 | info->line, info->count); |
| 1536 | #endif |
| 1537 | if (!(tty_hung_up_p(filp))) |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1538 | port->count--; |
| 1539 | port->blocked_open++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | while (1) { |
| 1541 | set_current_state(TASK_INTERRUPTIBLE); |
| 1542 | if (tty_hung_up_p(filp) || |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1543 | !(port->flags & ASYNC_INITIALIZED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | #ifdef MODEM_DO_RESTART |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1545 | if (port->flags & ASYNC_HUP_NOTIFY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | retval = -EAGAIN; |
| 1547 | else |
| 1548 | retval = -ERESTARTSYS; |
| 1549 | #else |
| 1550 | retval = -EAGAIN; |
| 1551 | #endif |
| 1552 | break; |
| 1553 | } |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1554 | if (!(port->flags & ASYNC_CLOSING) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | (do_clocal || (info->msr & UART_MSR_DCD))) { |
| 1556 | break; |
| 1557 | } |
| 1558 | if (signal_pending(current)) { |
| 1559 | retval = -ERESTARTSYS; |
| 1560 | break; |
| 1561 | } |
| 1562 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1563 | printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n", |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1564 | info->line, port->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | #endif |
| 1566 | schedule(); |
| 1567 | } |
| 1568 | current->state = TASK_RUNNING; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1569 | remove_wait_queue(&port->open_wait, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | if (!tty_hung_up_p(filp)) |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1571 | port->count++; |
| 1572 | port->blocked_open--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1574 | printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n", |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1575 | info->line, port->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | #endif |
| 1577 | if (retval) |
| 1578 | return retval; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1579 | port->flags |= ASYNC_NORMAL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | /* |
| 1584 | * This routine is called whenever a serial port is opened. It |
| 1585 | * enables interrupts for a serial port, linking in its async structure into |
| 1586 | * the IRQ chain. It also performs the serial-specific |
| 1587 | * initialization for the tty structure. |
| 1588 | */ |
| 1589 | static int |
| 1590 | isdn_tty_open(struct tty_struct *tty, struct file *filp) |
| 1591 | { |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1592 | struct tty_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | modem_info *info; |
Jiri Slaby | 410235f | 2012-03-05 14:52:01 +0100 | [diff] [blame] | 1594 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Jiri Slaby | 410235f | 2012-03-05 14:52:01 +0100 | [diff] [blame] | 1596 | info = &dev->mdm.info[tty->index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) |
| 1598 | return -ENODEV; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1599 | port = &info->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | #ifdef ISDN_DEBUG_MODEM_OPEN |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1601 | printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1602 | port->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | #endif |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1604 | port->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | tty->driver_data = info; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1606 | port->tty = tty; |
| 1607 | tty->port = port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | /* |
| 1609 | * Start up serial port |
| 1610 | */ |
| 1611 | retval = isdn_tty_startup(info); |
| 1612 | if (retval) { |
| 1613 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1614 | printk(KERN_DEBUG "isdn_tty_open return after startup\n"); |
| 1615 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | return retval; |
| 1617 | } |
| 1618 | retval = isdn_tty_block_til_ready(tty, filp, info); |
| 1619 | if (retval) { |
| 1620 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1621 | printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); |
| 1622 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | return retval; |
| 1624 | } |
| 1625 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1626 | printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line); |
| 1627 | #endif |
| 1628 | dev->modempoll++; |
| 1629 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1630 | printk(KERN_DEBUG "isdn_tty_open normal exit\n"); |
| 1631 | #endif |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
| 1635 | static void |
| 1636 | isdn_tty_close(struct tty_struct *tty, struct file *filp) |
| 1637 | { |
| 1638 | modem_info *info = (modem_info *) tty->driver_data; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1639 | struct tty_port *port = &info->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | ulong timeout; |
| 1641 | |
| 1642 | if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) |
| 1643 | return; |
| 1644 | if (tty_hung_up_p(filp)) { |
| 1645 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1646 | printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n"); |
| 1647 | #endif |
| 1648 | return; |
| 1649 | } |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1650 | if ((tty->count == 1) && (port->count != 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | /* |
| 1652 | * Uh, oh. tty->count is 1, which means that the tty |
| 1653 | * structure will be freed. Info->count should always |
| 1654 | * be one in these conditions. If it's greater than |
| 1655 | * one, we've got real problems, since it means the |
| 1656 | * serial port won't be shutdown. |
| 1657 | */ |
| 1658 | printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1659 | "info->count is %d\n", port->count); |
| 1660 | port->count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | } |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1662 | if (--port->count < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1664 | info->line, port->count); |
| 1665 | port->count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | } |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1667 | if (port->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1669 | printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); |
| 1670 | #endif |
| 1671 | return; |
| 1672 | } |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1673 | port->flags |= ASYNC_CLOSING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
| 1675 | tty->closing = 1; |
| 1676 | /* |
| 1677 | * At this point we stop accepting input. To do this, we |
| 1678 | * disable the receive line status interrupts, and tell the |
| 1679 | * interrupt driver to stop checking the data ready bit in the |
| 1680 | * line status register. |
| 1681 | */ |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1682 | if (port->flags & ASYNC_INITIALIZED) { |
Jiri Slaby | 0b05835 | 2011-08-25 15:12:08 +0200 | [diff] [blame] | 1683 | tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | /* |
| 1685 | * Before we drop DTR, make sure the UART transmitter |
| 1686 | * has completely drained; this is especially |
| 1687 | * important if there is a transmit FIFO! |
| 1688 | */ |
| 1689 | timeout = jiffies + HZ; |
| 1690 | while (!(info->lsr & UART_LSR_TEMT)) { |
Nishanth Aravamudan | 24763c4 | 2005-11-07 01:01:16 -0800 | [diff] [blame] | 1691 | schedule_timeout_interruptible(20); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1692 | if (time_after(jiffies, timeout)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | break; |
| 1694 | } |
| 1695 | } |
| 1696 | dev->modempoll--; |
| 1697 | isdn_tty_shutdown(info); |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 1698 | isdn_tty_flush_buffer(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | tty_ldisc_flush(tty); |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1700 | port->tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | info->ncarrier = 0; |
Jiri Slaby | 4330d66 | 2012-04-02 13:54:00 +0200 | [diff] [blame^] | 1702 | |
| 1703 | tty_port_close_end(port, tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | #ifdef ISDN_DEBUG_MODEM_OPEN |
| 1705 | printk(KERN_DEBUG "isdn_tty_close normal exit\n"); |
| 1706 | #endif |
| 1707 | } |
| 1708 | |
| 1709 | /* |
| 1710 | * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled. |
| 1711 | */ |
| 1712 | static void |
| 1713 | isdn_tty_hangup(struct tty_struct *tty) |
| 1714 | { |
| 1715 | modem_info *info = (modem_info *) tty->driver_data; |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1716 | struct tty_port *port = &info->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | |
| 1718 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) |
| 1719 | return; |
| 1720 | isdn_tty_shutdown(info); |
Jiri Slaby | 265d6f0 | 2012-04-02 13:53:59 +0200 | [diff] [blame] | 1721 | port->count = 0; |
| 1722 | port->flags &= ~ASYNC_NORMAL_ACTIVE; |
| 1723 | port->tty = NULL; |
| 1724 | wake_up_interruptible(&port->open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | /* This routine initializes all emulator-data. |
| 1728 | */ |
| 1729 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1730 | isdn_tty_reset_profile(atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | { |
| 1732 | m->profile[0] = 0; |
| 1733 | m->profile[1] = 0; |
| 1734 | m->profile[2] = 43; |
| 1735 | m->profile[3] = 13; |
| 1736 | m->profile[4] = 10; |
| 1737 | m->profile[5] = 8; |
| 1738 | m->profile[6] = 3; |
| 1739 | m->profile[7] = 60; |
| 1740 | m->profile[8] = 2; |
| 1741 | m->profile[9] = 6; |
| 1742 | m->profile[10] = 7; |
| 1743 | m->profile[11] = 70; |
| 1744 | m->profile[12] = 0x45; |
| 1745 | m->profile[13] = 4; |
| 1746 | m->profile[14] = ISDN_PROTO_L2_X75I; |
| 1747 | m->profile[15] = ISDN_PROTO_L3_TRANS; |
| 1748 | m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16; |
| 1749 | m->profile[17] = ISDN_MODEM_WINSIZE; |
| 1750 | m->profile[18] = 4; |
| 1751 | m->profile[19] = 0; |
| 1752 | m->profile[20] = 0; |
| 1753 | m->profile[23] = 0; |
| 1754 | m->pmsn[0] = '\0'; |
| 1755 | m->plmsn[0] = '\0'; |
| 1756 | } |
| 1757 | |
| 1758 | #ifdef CONFIG_ISDN_AUDIO |
| 1759 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1760 | isdn_tty_modem_reset_vpar(atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | { |
| 1762 | m->vpar[0] = 2; /* Voice-device (2 = phone line) */ |
| 1763 | m->vpar[1] = 0; /* Silence detection level (0 = none ) */ |
| 1764 | m->vpar[2] = 70; /* Silence interval (7 sec. ) */ |
| 1765 | m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */ |
| 1766 | m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */ |
| 1767 | m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */ |
| 1768 | } |
| 1769 | #endif |
| 1770 | |
| 1771 | #ifdef CONFIG_ISDN_TTY_FAX |
| 1772 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1773 | isdn_tty_modem_reset_faxpar(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | { |
| 1775 | T30_s *f = info->fax; |
| 1776 | |
| 1777 | f->code = 0; |
| 1778 | f->phase = ISDN_FAX_PHASE_IDLE; |
| 1779 | f->direction = 0; |
| 1780 | f->resolution = 1; /* fine */ |
| 1781 | f->rate = 5; /* 14400 bit/s */ |
| 1782 | f->width = 0; |
| 1783 | f->length = 0; |
| 1784 | f->compression = 0; |
| 1785 | f->ecm = 0; |
| 1786 | f->binary = 0; |
| 1787 | f->scantime = 0; |
| 1788 | memset(&f->id[0], 32, FAXIDLEN - 1); |
| 1789 | f->id[FAXIDLEN - 1] = 0; |
| 1790 | f->badlin = 0; |
| 1791 | f->badmul = 0; |
| 1792 | f->bor = 0; |
| 1793 | f->nbc = 0; |
| 1794 | f->cq = 0; |
| 1795 | f->cr = 0; |
| 1796 | f->ctcrty = 0; |
| 1797 | f->minsp = 0; |
| 1798 | f->phcto = 30; |
| 1799 | f->rel = 0; |
| 1800 | memset(&f->pollid[0], 32, FAXIDLEN - 1); |
| 1801 | f->pollid[FAXIDLEN - 1] = 0; |
| 1802 | } |
| 1803 | #endif |
| 1804 | |
| 1805 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1806 | isdn_tty_modem_reset_regs(modem_info *info, int force) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
| 1808 | atemu *m = &info->emu; |
| 1809 | if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) { |
| 1810 | memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG); |
| 1811 | memcpy(m->msn, m->pmsn, ISDN_MSNLEN); |
| 1812 | memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN); |
| 1813 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; |
| 1814 | } |
| 1815 | #ifdef CONFIG_ISDN_AUDIO |
| 1816 | isdn_tty_modem_reset_vpar(m); |
| 1817 | #endif |
| 1818 | #ifdef CONFIG_ISDN_TTY_FAX |
| 1819 | isdn_tty_modem_reset_faxpar(info); |
| 1820 | #endif |
| 1821 | m->mdmcmdl = 0; |
| 1822 | } |
| 1823 | |
| 1824 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1825 | modem_write_profile(atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | { |
| 1827 | memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG); |
| 1828 | memcpy(m->pmsn, m->msn, ISDN_MSNLEN); |
| 1829 | memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN); |
| 1830 | if (dev->profd) |
| 1831 | send_sig(SIGIO, dev->profd, 1); |
| 1832 | } |
| 1833 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1834 | static const struct tty_operations modem_ops = { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1835 | .open = isdn_tty_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | .close = isdn_tty_close, |
| 1837 | .write = isdn_tty_write, |
| 1838 | .flush_chars = isdn_tty_flush_chars, |
| 1839 | .write_room = isdn_tty_write_room, |
| 1840 | .chars_in_buffer = isdn_tty_chars_in_buffer, |
| 1841 | .flush_buffer = isdn_tty_flush_buffer, |
| 1842 | .ioctl = isdn_tty_ioctl, |
| 1843 | .throttle = isdn_tty_throttle, |
| 1844 | .unthrottle = isdn_tty_unthrottle, |
| 1845 | .set_termios = isdn_tty_set_termios, |
| 1846 | .hangup = isdn_tty_hangup, |
| 1847 | .tiocmget = isdn_tty_tiocmget, |
| 1848 | .tiocmset = isdn_tty_tiocmset, |
| 1849 | }; |
| 1850 | |
| 1851 | int |
| 1852 | isdn_tty_modem_init(void) |
| 1853 | { |
| 1854 | isdn_modem_t *m; |
| 1855 | int i, retval; |
| 1856 | modem_info *info; |
| 1857 | |
| 1858 | m = &dev->mdm; |
| 1859 | m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS); |
| 1860 | if (!m->tty_modem) |
| 1861 | return -ENOMEM; |
| 1862 | m->tty_modem->name = "ttyI"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | m->tty_modem->major = ISDN_TTY_MAJOR; |
| 1864 | m->tty_modem->minor_start = 0; |
| 1865 | m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL; |
| 1866 | m->tty_modem->subtype = SERIAL_TYPE_NORMAL; |
| 1867 | m->tty_modem->init_termios = tty_std_termios; |
| 1868 | m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
Greg Kroah-Hartman | 331b831 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 1869 | m->tty_modem->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | m->tty_modem->driver_name = "isdn_tty"; |
| 1871 | tty_set_operations(m->tty_modem, &modem_ops); |
| 1872 | retval = tty_register_driver(m->tty_modem); |
| 1873 | if (retval) { |
| 1874 | printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n"); |
| 1875 | goto err; |
| 1876 | } |
| 1877 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 1878 | info = &m->info[i]; |
| 1879 | #ifdef CONFIG_ISDN_TTY_FAX |
| 1880 | if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) { |
| 1881 | printk(KERN_ERR "Could not allocate fax t30-buffer\n"); |
| 1882 | retval = -ENOMEM; |
| 1883 | goto err_unregister; |
| 1884 | } |
| 1885 | #endif |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 1886 | tty_port_init(&info->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | spin_lock_init(&info->readlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | sprintf(info->last_cause, "0000"); |
| 1889 | sprintf(info->last_num, "none"); |
| 1890 | info->last_dir = 0; |
| 1891 | info->last_lhup = 1; |
| 1892 | info->last_l2 = -1; |
| 1893 | info->last_si = 0; |
| 1894 | isdn_tty_reset_profile(&info->emu); |
| 1895 | isdn_tty_modem_reset_regs(info, 1); |
| 1896 | info->magic = ISDN_ASYNC_MAGIC; |
| 1897 | info->line = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | info->x_char = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | info->isdn_driver = -1; |
| 1900 | info->isdn_channel = -1; |
| 1901 | info->drv_index = -1; |
| 1902 | info->xmit_size = ISDN_SERIAL_XMIT_SIZE; |
| 1903 | init_timer(&info->nc_timer); |
| 1904 | info->nc_timer.function = isdn_tty_modem_do_ncarrier; |
| 1905 | info->nc_timer.data = (unsigned long) info; |
| 1906 | skb_queue_head_init(&info->xmit_queue); |
| 1907 | #ifdef CONFIG_ISDN_AUDIO |
| 1908 | skb_queue_head_init(&info->dtmf_queue); |
| 1909 | #endif |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 1910 | info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, |
| 1911 | GFP_KERNEL); |
| 1912 | if (!info->port.xmit_buf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); |
| 1914 | retval = -ENOMEM; |
| 1915 | goto err_unregister; |
| 1916 | } |
| 1917 | /* Make room for T.70 header */ |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 1918 | info->port.xmit_buf += 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } |
| 1920 | return 0; |
| 1921 | err_unregister: |
| 1922 | for (i--; i >= 0; i--) { |
| 1923 | info = &m->info[i]; |
| 1924 | #ifdef CONFIG_ISDN_TTY_FAX |
| 1925 | kfree(info->fax); |
| 1926 | #endif |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 1927 | kfree(info->port.xmit_buf - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | tty_unregister_driver(m->tty_modem); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1930 | err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | put_tty_driver(m->tty_modem); |
| 1932 | m->tty_modem = NULL; |
| 1933 | return retval; |
| 1934 | } |
| 1935 | |
| 1936 | void |
| 1937 | isdn_tty_exit(void) |
| 1938 | { |
| 1939 | modem_info *info; |
| 1940 | int i; |
| 1941 | |
| 1942 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 1943 | info = &dev->mdm.info[i]; |
| 1944 | isdn_tty_cleanup_xmit(info); |
| 1945 | #ifdef CONFIG_ISDN_TTY_FAX |
| 1946 | kfree(info->fax); |
| 1947 | #endif |
Jiri Slaby | 82e46b3 | 2012-04-02 13:53:58 +0200 | [diff] [blame] | 1948 | kfree(info->port.xmit_buf - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | } |
| 1950 | tty_unregister_driver(dev->mdm.tty_modem); |
| 1951 | put_tty_driver(dev->mdm.tty_modem); |
| 1952 | dev->mdm.tty_modem = NULL; |
| 1953 | } |
| 1954 | |
| 1955 | |
| 1956 | /* |
| 1957 | * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx) |
| 1958 | * match the MSN against the MSNs (glob patterns) defined for tty_emulator, |
| 1959 | * and return 0 for match, 1 for no match, 2 if MSN could match if longer. |
| 1960 | */ |
| 1961 | |
| 1962 | static int |
| 1963 | isdn_tty_match_icall(char *cid, atemu *emu, int di) |
| 1964 | { |
| 1965 | #ifdef ISDN_DEBUG_MODEM_ICALL |
| 1966 | printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n", |
| 1967 | emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di), |
| 1968 | emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]); |
| 1969 | #endif |
| 1970 | if (strlen(emu->lmsn)) { |
| 1971 | char *p = emu->lmsn; |
| 1972 | char *q; |
| 1973 | int tmp; |
| 1974 | int ret = 0; |
| 1975 | |
| 1976 | while (1) { |
| 1977 | if ((q = strchr(p, ';'))) |
| 1978 | *q = '\0'; |
| 1979 | if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret) |
| 1980 | ret = tmp; |
| 1981 | #ifdef ISDN_DEBUG_MODEM_ICALL |
| 1982 | printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n", |
| 1983 | p, isdn_map_eaz2msn(emu->msn, di), tmp); |
| 1984 | #endif |
| 1985 | if (q) { |
| 1986 | *q = ';'; |
| 1987 | p = q; |
| 1988 | p++; |
| 1989 | } |
| 1990 | if (!tmp) |
| 1991 | return 0; |
| 1992 | if (!q) |
| 1993 | break; |
| 1994 | } |
| 1995 | return ret; |
| 1996 | } else { |
| 1997 | int tmp; |
| 1998 | tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di)); |
| 1999 | #ifdef ISDN_DEBUG_MODEM_ICALL |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2000 | printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n", |
| 2001 | isdn_map_eaz2msn(emu->msn, di), tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | #endif |
| 2003 | return tmp; |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | /* |
| 2008 | * An incoming call-request has arrived. |
| 2009 | * Search the tty-devices for an appropriate device and bind |
| 2010 | * it to the ISDN-Channel. |
| 2011 | * Return: |
| 2012 | * |
| 2013 | * 0 = No matching device found. |
| 2014 | * 1 = A matching device found. |
| 2015 | * 3 = No match found, but eventually would match, if |
| 2016 | * CID is longer. |
| 2017 | */ |
| 2018 | int |
| 2019 | isdn_tty_find_icall(int di, int ch, setup_parm *setup) |
| 2020 | { |
| 2021 | char *eaz; |
| 2022 | int i; |
| 2023 | int wret; |
| 2024 | int idx; |
| 2025 | int si1; |
| 2026 | int si2; |
| 2027 | char *nr; |
| 2028 | ulong flags; |
| 2029 | |
| 2030 | if (!setup->phone[0]) { |
| 2031 | nr = "0"; |
| 2032 | printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n"); |
| 2033 | } else |
| 2034 | nr = setup->phone; |
| 2035 | si1 = (int) setup->si1; |
| 2036 | si2 = (int) setup->si2; |
| 2037 | if (!setup->eazmsn[0]) { |
| 2038 | printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n"); |
| 2039 | eaz = "0"; |
| 2040 | } else |
| 2041 | eaz = setup->eazmsn; |
| 2042 | #ifdef ISDN_DEBUG_MODEM_ICALL |
| 2043 | printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2); |
| 2044 | #endif |
| 2045 | wret = 0; |
| 2046 | spin_lock_irqsave(&dev->lock, flags); |
| 2047 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 2048 | modem_info *info = &dev->mdm.info[i]; |
| 2049 | |
Jiri Slaby | 1b05f030 | 2012-04-02 13:53:56 +0200 | [diff] [blame] | 2050 | if (info->port.count == 0) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2051 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ |
| 2053 | (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ |
| 2054 | idx = isdn_dc2minor(di, ch); |
| 2055 | #ifdef ISDN_DEBUG_MODEM_ICALL |
| 2056 | printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); |
| 2057 | printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 2058 | info->port.flags, info->isdn_driver, |
| 2059 | info->isdn_channel, dev->usage[idx]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | #endif |
| 2061 | if ( |
| 2062 | #ifndef FIX_FILE_TRANSFER |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 2063 | (info->port.flags & ASYNC_NORMAL_ACTIVE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | #endif |
| 2065 | (info->isdn_driver == -1) && |
| 2066 | (info->isdn_channel == -1) && |
| 2067 | (USG_NONE(dev->usage[idx]))) { |
| 2068 | int matchret; |
| 2069 | |
| 2070 | if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret) |
| 2071 | wret = matchret; |
| 2072 | if (!matchret) { /* EAZ is matching */ |
| 2073 | info->isdn_driver = di; |
| 2074 | info->isdn_channel = ch; |
| 2075 | info->drv_index = idx; |
| 2076 | dev->m_idx[idx] = info->line; |
| 2077 | dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2078 | dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | strcpy(dev->num[idx], nr); |
| 2080 | strcpy(info->emu.cpn, eaz); |
| 2081 | info->emu.mdmreg[REG_SI1I] = si2bit[si1]; |
| 2082 | info->emu.mdmreg[REG_PLAN] = setup->plan; |
| 2083 | info->emu.mdmreg[REG_SCREEN] = setup->screen; |
| 2084 | isdn_info_update(); |
| 2085 | spin_unlock_irqrestore(&dev->lock, flags); |
| 2086 | printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr, |
| 2087 | info->line); |
| 2088 | info->msr |= UART_MSR_RI; |
| 2089 | isdn_tty_modem_result(RESULT_RING, info); |
| 2090 | isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1); |
| 2091 | return 1; |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | } |
| 2096 | spin_unlock_irqrestore(&dev->lock, flags); |
| 2097 | printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2098 | ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2)) ? "rejected" : "ignored"); |
| 2099 | return (wret == 2) ? 3 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 2102 | #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
| 2104 | int |
| 2105 | isdn_tty_stat_callback(int i, isdn_ctrl *c) |
| 2106 | { |
| 2107 | int mi; |
| 2108 | modem_info *info; |
| 2109 | char *e; |
| 2110 | |
| 2111 | if (i < 0) |
| 2112 | return 0; |
| 2113 | if ((mi = dev->m_idx[i]) >= 0) { |
| 2114 | info = &dev->mdm.info[mi]; |
| 2115 | switch (c->command) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2116 | case ISDN_STAT_CINF: |
| 2117 | printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num); |
| 2118 | info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10); |
| 2119 | if (e == (char *)c->parm.num) |
| 2120 | info->emu.charge = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2122 | break; |
| 2123 | case ISDN_STAT_BSENT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | #ifdef ISDN_TTY_STAT_DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2125 | printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2127 | if ((info->isdn_driver == c->driver) && |
| 2128 | (info->isdn_channel == c->arg)) { |
| 2129 | info->msr |= UART_MSR_CTS; |
| 2130 | if (info->send_outstanding) |
| 2131 | if (!(--info->send_outstanding)) |
| 2132 | info->lsr |= UART_LSR_TEMT; |
| 2133 | isdn_tty_tint(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | return 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2135 | } |
| 2136 | break; |
| 2137 | case ISDN_STAT_CAUSE: |
| 2138 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2139 | printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line); |
| 2140 | #endif |
| 2141 | /* Signal cause to tty-device */ |
| 2142 | strncpy(info->last_cause, c->parm.num, 5); |
| 2143 | return 1; |
| 2144 | case ISDN_STAT_DISPLAY: |
| 2145 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2146 | printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line); |
| 2147 | #endif |
| 2148 | /* Signal display to tty-device */ |
| 2149 | if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) && |
| 2150 | !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) { |
| 2151 | isdn_tty_at_cout("\r\n", info); |
| 2152 | isdn_tty_at_cout("DISPLAY: ", info); |
| 2153 | isdn_tty_at_cout(c->parm.display, info); |
| 2154 | isdn_tty_at_cout("\r\n", info); |
| 2155 | } |
| 2156 | return 1; |
| 2157 | case ISDN_STAT_DCONN: |
| 2158 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2159 | printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line); |
| 2160 | #endif |
| 2161 | if (TTY_IS_ACTIVE(info)) { |
| 2162 | if (info->dialing == 1) { |
| 2163 | info->dialing = 2; |
| 2164 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2166 | } |
| 2167 | break; |
| 2168 | case ISDN_STAT_DHUP: |
| 2169 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2170 | printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line); |
| 2171 | #endif |
| 2172 | if (TTY_IS_ACTIVE(info)) { |
| 2173 | if (info->dialing == 1) |
| 2174 | isdn_tty_modem_result(RESULT_BUSY, info); |
| 2175 | if (info->dialing > 1) |
| 2176 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
| 2177 | info->dialing = 0; |
| 2178 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 2179 | printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n"); |
| 2180 | #endif |
| 2181 | isdn_tty_modem_hup(info, 0); |
| 2182 | return 1; |
| 2183 | } |
| 2184 | break; |
| 2185 | case ISDN_STAT_BCONN: |
| 2186 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2187 | printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line); |
| 2188 | #endif |
| 2189 | /* Wake up any processes waiting |
| 2190 | * for incoming call of this device when |
| 2191 | * DCD follow the state of incoming carrier |
| 2192 | */ |
Jiri Slaby | 1b05f030 | 2012-04-02 13:53:56 +0200 | [diff] [blame] | 2193 | if (info->port.blocked_open && |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2194 | (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { |
Jiri Slaby | c6e92b6 | 2012-04-02 13:53:55 +0200 | [diff] [blame] | 2195 | wake_up_interruptible(&info->port.open_wait); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | /* Schedule CONNECT-Message to any tty |
| 2199 | * waiting for it and |
| 2200 | * set DCD-bit of its modem-status. |
| 2201 | */ |
| 2202 | if (TTY_IS_ACTIVE(info) || |
Jiri Slaby | 1b05f030 | 2012-04-02 13:53:56 +0200 | [diff] [blame] | 2203 | (info->port.blocked_open && |
| 2204 | (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2205 | info->msr |= UART_MSR_DCD; |
| 2206 | info->emu.charge = 0; |
| 2207 | if (info->dialing & 0xf) |
| 2208 | info->last_dir = 1; |
| 2209 | else |
| 2210 | info->last_dir = 0; |
| 2211 | info->dialing = 0; |
| 2212 | info->rcvsched = 1; |
| 2213 | if (USG_MODEM(dev->usage[i])) { |
| 2214 | if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) { |
| 2215 | strcpy(info->emu.connmsg, c->parm.num); |
| 2216 | isdn_tty_modem_result(RESULT_CONNECT, info); |
| 2217 | } else |
| 2218 | isdn_tty_modem_result(RESULT_CONNECT64000, info); |
| 2219 | } |
| 2220 | if (USG_VOICE(dev->usage[i])) |
| 2221 | isdn_tty_modem_result(RESULT_VCON, info); |
| 2222 | return 1; |
| 2223 | } |
| 2224 | break; |
| 2225 | case ISDN_STAT_BHUP: |
| 2226 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2227 | printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line); |
| 2228 | #endif |
| 2229 | if (TTY_IS_ACTIVE(info)) { |
| 2230 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 2231 | printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n"); |
| 2232 | #endif |
| 2233 | isdn_tty_modem_hup(info, 0); |
| 2234 | return 1; |
| 2235 | } |
| 2236 | break; |
| 2237 | case ISDN_STAT_NODCH: |
| 2238 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2239 | printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line); |
| 2240 | #endif |
| 2241 | if (TTY_IS_ACTIVE(info)) { |
| 2242 | if (info->dialing) { |
| 2243 | info->dialing = 0; |
| 2244 | info->last_l2 = -1; |
| 2245 | info->last_si = 0; |
| 2246 | sprintf(info->last_cause, "0000"); |
| 2247 | isdn_tty_modem_result(RESULT_NO_DIALTONE, info); |
| 2248 | } |
| 2249 | isdn_tty_modem_hup(info, 0); |
| 2250 | return 1; |
| 2251 | } |
| 2252 | break; |
| 2253 | case ISDN_STAT_UNLOAD: |
| 2254 | #ifdef ISDN_TTY_STAT_DEBUG |
| 2255 | printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line); |
| 2256 | #endif |
| 2257 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 2258 | info = &dev->mdm.info[i]; |
| 2259 | if (info->isdn_driver == c->driver) { |
| 2260 | if (info->online) |
| 2261 | isdn_tty_modem_hup(info, 1); |
| 2262 | } |
| 2263 | } |
| 2264 | return 1; |
| 2265 | #ifdef CONFIG_ISDN_TTY_FAX |
| 2266 | case ISDN_STAT_FAXIND: |
| 2267 | if (TTY_IS_ACTIVE(info)) { |
| 2268 | isdn_tty_fax_command(info, c); |
| 2269 | } |
| 2270 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | #endif |
| 2272 | #ifdef CONFIG_ISDN_AUDIO |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2273 | case ISDN_STAT_AUDIO: |
| 2274 | if (TTY_IS_ACTIVE(info)) { |
| 2275 | switch (c->parm.num[0]) { |
| 2276 | case ISDN_AUDIO_DTMF: |
| 2277 | if (info->vonline) { |
| 2278 | isdn_audio_put_dle_code(info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | c->parm.num[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2281 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2283 | } |
| 2284 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | #endif |
| 2286 | } |
| 2287 | } |
| 2288 | return 0; |
| 2289 | } |
| 2290 | |
| 2291 | /********************************************************************* |
| 2292 | Modem-Emulator-Routines |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2293 | *********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2295 | #define cmdchar(c) ((c >= ' ') && (c <= 0x7f)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | |
| 2297 | /* |
| 2298 | * Put a message from the AT-emulator into receive-buffer of tty, |
| 2299 | * convert CR, LF, and BS to values in modem-registers 3, 4 and 5. |
| 2300 | */ |
| 2301 | void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2302 | isdn_tty_at_cout(char *msg, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | { |
| 2304 | struct tty_struct *tty; |
| 2305 | atemu *m = &info->emu; |
| 2306 | char *p; |
| 2307 | char c; |
| 2308 | u_long flags; |
| 2309 | struct sk_buff *skb = NULL; |
| 2310 | char *sp = NULL; |
Adrian Bunk | 1f4d4a8 | 2006-03-25 03:08:06 -0800 | [diff] [blame] | 2311 | int l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
| 2313 | if (!msg) { |
| 2314 | printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n"); |
| 2315 | return; |
| 2316 | } |
Adrian Bunk | 1f4d4a8 | 2006-03-25 03:08:06 -0800 | [diff] [blame] | 2317 | |
| 2318 | l = strlen(msg); |
| 2319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | spin_lock_irqsave(&info->readlock, flags); |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 2321 | tty = info->port.tty; |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 2322 | if ((info->port.flags & ASYNC_CLOSING) || (!tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | spin_unlock_irqrestore(&info->readlock, flags); |
| 2324 | return; |
| 2325 | } |
| 2326 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2327 | /* use queue instead of direct, if online and */ |
| 2328 | /* data is in queue or buffer is full */ |
Karsten Keil | 61b9a26 | 2006-02-14 13:53:06 -0800 | [diff] [blame] | 2329 | if (info->online && ((tty_buffer_request_room(tty, l) < l) || |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2330 | !skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2331 | skb = alloc_skb(l, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | if (!skb) { |
| 2333 | spin_unlock_irqrestore(&info->readlock, flags); |
| 2334 | return; |
| 2335 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2336 | sp = skb_put(skb, l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | #ifdef CONFIG_ISDN_AUDIO |
| 2338 | ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; |
| 2339 | ISDN_AUDIO_SKB_LOCK(skb) = 0; |
| 2340 | #endif |
| 2341 | } |
| 2342 | |
| 2343 | for (p = msg; *p; p++) { |
| 2344 | switch (*p) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2345 | case '\r': |
| 2346 | c = m->mdmreg[REG_CR]; |
| 2347 | break; |
| 2348 | case '\n': |
| 2349 | c = m->mdmreg[REG_LF]; |
| 2350 | break; |
| 2351 | case '\b': |
| 2352 | c = m->mdmreg[REG_BS]; |
| 2353 | break; |
| 2354 | default: |
| 2355 | c = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | } |
| 2357 | if (skb) { |
| 2358 | *sp++ = c; |
| 2359 | } else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2360 | if (tty_insert_flip_char(tty, c, TTY_NORMAL) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | } |
| 2363 | } |
| 2364 | if (skb) { |
| 2365 | __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb); |
| 2366 | dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len; |
| 2367 | spin_unlock_irqrestore(&info->readlock, flags); |
| 2368 | /* Schedule dequeuing */ |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2369 | if (dev->modempoll && info->rcvsched) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); |
| 2371 | |
| 2372 | } else { |
| 2373 | spin_unlock_irqrestore(&info->readlock, flags); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2374 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | /* |
| 2379 | * Perform ATH Hangup |
| 2380 | */ |
| 2381 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2382 | isdn_tty_on_hook(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | { |
| 2384 | if (info->isdn_channel >= 0) { |
| 2385 | #ifdef ISDN_DEBUG_MODEM_HUP |
| 2386 | printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n"); |
| 2387 | #endif |
| 2388 | isdn_tty_modem_hup(info, 1); |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | static void |
| 2393 | isdn_tty_off_hook(void) |
| 2394 | { |
| 2395 | printk(KERN_DEBUG "isdn_tty_off_hook\n"); |
| 2396 | } |
| 2397 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2398 | #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */ |
| 2399 | #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | |
| 2401 | /* |
| 2402 | * Check Buffer for Modem-escape-sequence, activate timer-callback to |
| 2403 | * isdn_tty_modem_escape() if sequence found. |
| 2404 | * |
| 2405 | * Parameters: |
| 2406 | * p pointer to databuffer |
| 2407 | * plus escape-character |
| 2408 | * count length of buffer |
| 2409 | * pluscount count of valid escape-characters so far |
| 2410 | * lastplus timestamp of last character |
| 2411 | */ |
| 2412 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2413 | isdn_tty_check_esc(const u_char *p, u_char plus, int count, int *pluscount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | u_long *lastplus) |
| 2415 | { |
| 2416 | if (plus > 127) |
| 2417 | return; |
| 2418 | if (count > 3) { |
| 2419 | p += count - 3; |
| 2420 | count = 3; |
| 2421 | *pluscount = 0; |
| 2422 | } |
| 2423 | while (count > 0) { |
| 2424 | if (*(p++) == plus) { |
| 2425 | if ((*pluscount)++) { |
| 2426 | /* Time since last '+' > 0.5 sec. ? */ |
| 2427 | if (time_after(jiffies, *lastplus + PLUSWAIT1)) |
| 2428 | *pluscount = 1; |
| 2429 | } else { |
| 2430 | /* Time since last non-'+' < 1.5 sec. ? */ |
| 2431 | if (time_before(jiffies, *lastplus + PLUSWAIT2)) |
| 2432 | *pluscount = 0; |
| 2433 | } |
| 2434 | if ((*pluscount == 3) && (count == 1)) |
| 2435 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1); |
| 2436 | if (*pluscount > 3) |
| 2437 | *pluscount = 1; |
| 2438 | } else |
| 2439 | *pluscount = 0; |
| 2440 | *lastplus = jiffies; |
| 2441 | count--; |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | /* |
| 2446 | * Return result of AT-emulator to tty-receive-buffer, depending on |
| 2447 | * modem-register 12, bit 0 and 1. |
| 2448 | * For CONNECT-messages also switch to online-mode. |
| 2449 | * For RING-message handle auto-ATA if register 0 != 0 |
| 2450 | */ |
| 2451 | |
| 2452 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2453 | isdn_tty_modem_result(int code, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | { |
| 2455 | atemu *m = &info->emu; |
| 2456 | static char *msg[] = |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2457 | {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR", |
| 2458 | "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER", |
| 2459 | "RINGING", "NO MSN/EAZ", "VCON", "RUNG"}; |
| 2460 | char s[ISDN_MSNLEN + 10]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | |
| 2462 | switch (code) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2463 | case RESULT_RING: |
| 2464 | m->mdmreg[REG_RINGCNT]++; |
| 2465 | if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA]) |
| 2466 | /* Automatically accept incoming call */ |
| 2467 | isdn_tty_cmd_ATA(info); |
| 2468 | break; |
| 2469 | case RESULT_NO_CARRIER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | #ifdef ISDN_DEBUG_MODEM_HUP |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2471 | printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 2472 | (info->port.flags & ASYNC_CLOSING), |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 2473 | (!info->port.tty)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2475 | m->mdmreg[REG_RINGCNT] = 0; |
| 2476 | del_timer(&info->nc_timer); |
| 2477 | info->ncarrier = 0; |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 2478 | if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2479 | return; |
Jiri Slaby | 6776a2f | 2012-04-02 13:53:50 +0200 | [diff] [blame] | 2480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | #ifdef CONFIG_ISDN_AUDIO |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2482 | if (info->vonline & 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | #ifdef ISDN_DEBUG_MODEM_VOICE |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2484 | printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | info->line); |
| 2486 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2487 | /* voice-recording, add DLE-ETX */ |
| 2488 | isdn_tty_at_cout("\020\003", info); |
| 2489 | } |
| 2490 | if (info->vonline & 2) { |
| 2491 | #ifdef ISDN_DEBUG_MODEM_VOICE |
| 2492 | printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n", |
| 2493 | info->line); |
| 2494 | #endif |
| 2495 | /* voice-playing, add DLE-DC4 */ |
| 2496 | isdn_tty_at_cout("\020\024", info); |
| 2497 | } |
| 2498 | #endif |
| 2499 | break; |
| 2500 | case RESULT_CONNECT: |
| 2501 | case RESULT_CONNECT64000: |
| 2502 | sprintf(info->last_cause, "0000"); |
| 2503 | if (!info->online) |
| 2504 | info->online = 2; |
| 2505 | break; |
| 2506 | case RESULT_VCON: |
| 2507 | #ifdef ISDN_DEBUG_MODEM_VOICE |
| 2508 | printk(KERN_DEBUG "res3: send VCON on ttyI%d\n", |
| 2509 | info->line); |
| 2510 | #endif |
| 2511 | sprintf(info->last_cause, "0000"); |
| 2512 | if (!info->online) |
| 2513 | info->online = 1; |
| 2514 | break; |
| 2515 | } /* switch (code) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | |
| 2517 | if (m->mdmreg[REG_RESP] & BIT_RESP) { |
| 2518 | /* Show results */ |
| 2519 | if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) { |
| 2520 | /* Show numeric results only */ |
| 2521 | sprintf(s, "\r\n%d\r\n", code); |
| 2522 | isdn_tty_at_cout(s, info); |
| 2523 | } else { |
| 2524 | if (code == RESULT_RING) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2525 | /* return if "show RUNG" and ringcounter>1 */ |
| 2526 | if ((m->mdmreg[REG_RUNG] & BIT_RUNG) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | (m->mdmreg[REG_RINGCNT] > 1)) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2528 | return; |
| 2529 | /* print CID, _before_ _every_ ring */ |
| 2530 | if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) { |
| 2531 | isdn_tty_at_cout("\r\nCALLER NUMBER: ", info); |
| 2532 | isdn_tty_at_cout(dev->num[info->drv_index], info); |
| 2533 | if (m->mdmreg[REG_CDN] & BIT_CDN) { |
| 2534 | isdn_tty_at_cout("\r\nCALLED NUMBER: ", info); |
| 2535 | isdn_tty_at_cout(info->emu.cpn, info); |
| 2536 | } |
| 2537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | } |
| 2539 | isdn_tty_at_cout("\r\n", info); |
| 2540 | isdn_tty_at_cout(msg[code], info); |
| 2541 | switch (code) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2542 | case RESULT_CONNECT: |
| 2543 | switch (m->mdmreg[REG_L2PROT]) { |
| 2544 | case ISDN_PROTO_L2_MODEM: |
| 2545 | isdn_tty_at_cout(" ", info); |
| 2546 | isdn_tty_at_cout(m->connmsg, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2548 | } |
| 2549 | break; |
| 2550 | case RESULT_RING: |
| 2551 | /* Append CPN, if enabled */ |
| 2552 | if ((m->mdmreg[REG_CPN] & BIT_CPN)) { |
| 2553 | sprintf(s, "/%s", m->cpn); |
| 2554 | isdn_tty_at_cout(s, info); |
| 2555 | } |
| 2556 | /* Print CID only once, _after_ 1st RING */ |
| 2557 | if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) && |
| 2558 | (m->mdmreg[REG_RINGCNT] == 1)) { |
| 2559 | isdn_tty_at_cout("\r\n", info); |
| 2560 | isdn_tty_at_cout("CALLER NUMBER: ", info); |
| 2561 | isdn_tty_at_cout(dev->num[info->drv_index], info); |
| 2562 | if (m->mdmreg[REG_CDN] & BIT_CDN) { |
| 2563 | isdn_tty_at_cout("\r\nCALLED NUMBER: ", info); |
| 2564 | isdn_tty_at_cout(info->emu.cpn, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2566 | } |
| 2567 | break; |
| 2568 | case RESULT_NO_CARRIER: |
| 2569 | case RESULT_NO_DIALTONE: |
| 2570 | case RESULT_BUSY: |
| 2571 | case RESULT_NO_ANSWER: |
| 2572 | m->mdmreg[REG_RINGCNT] = 0; |
| 2573 | /* Append Cause-Message if enabled */ |
| 2574 | if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) { |
| 2575 | sprintf(s, "/%s", info->last_cause); |
| 2576 | isdn_tty_at_cout(s, info); |
| 2577 | } |
| 2578 | break; |
| 2579 | case RESULT_CONNECT64000: |
| 2580 | /* Append Protocol to CONNECT message */ |
| 2581 | switch (m->mdmreg[REG_L2PROT]) { |
| 2582 | case ISDN_PROTO_L2_X75I: |
| 2583 | case ISDN_PROTO_L2_X75UI: |
| 2584 | case ISDN_PROTO_L2_X75BUI: |
| 2585 | isdn_tty_at_cout("/X.75", info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2587 | case ISDN_PROTO_L2_HDLC: |
| 2588 | isdn_tty_at_cout("/HDLC", info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2590 | case ISDN_PROTO_L2_V11096: |
| 2591 | isdn_tty_at_cout("/V110/9600", info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2593 | case ISDN_PROTO_L2_V11019: |
| 2594 | isdn_tty_at_cout("/V110/19200", info); |
| 2595 | break; |
| 2596 | case ISDN_PROTO_L2_V11038: |
| 2597 | isdn_tty_at_cout("/V110/38400", info); |
| 2598 | break; |
| 2599 | } |
| 2600 | if (m->mdmreg[REG_T70] & BIT_T70) { |
| 2601 | isdn_tty_at_cout("/T.70", info); |
| 2602 | if (m->mdmreg[REG_T70] & BIT_T70_EXT) |
| 2603 | isdn_tty_at_cout("+", info); |
| 2604 | } |
| 2605 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
| 2607 | isdn_tty_at_cout("\r\n", info); |
| 2608 | } |
| 2609 | } |
| 2610 | if (code == RESULT_NO_CARRIER) { |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 2611 | if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | return; |
Jiri Slaby | 6776a2f | 2012-04-02 13:53:50 +0200 | [diff] [blame] | 2613 | |
Jiri Slaby | 48decc1 | 2012-04-02 13:53:54 +0200 | [diff] [blame] | 2614 | if (info->port.flags & ASYNC_CHECK_CD) |
Jiri Slaby | ba43294 | 2012-04-02 13:53:57 +0200 | [diff] [blame] | 2615 | tty_hangup(info->port.tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | |
| 2620 | /* |
| 2621 | * Display a modem-register-value. |
| 2622 | */ |
| 2623 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2624 | isdn_tty_show_profile(int ridx, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | { |
| 2626 | char v[6]; |
| 2627 | |
| 2628 | sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]); |
| 2629 | isdn_tty_at_cout(v, info); |
| 2630 | } |
| 2631 | |
| 2632 | /* |
| 2633 | * Get MSN-string from char-pointer, set pointer to end of number |
| 2634 | */ |
| 2635 | static void |
| 2636 | isdn_tty_get_msnstr(char *n, char **p) |
| 2637 | { |
| 2638 | int limit = ISDN_MSNLEN - 1; |
| 2639 | |
| 2640 | while (((*p[0] >= '0' && *p[0] <= '9') || |
| 2641 | /* Why a comma ??? */ |
| 2642 | (*p[0] == ',') || (*p[0] == ':')) && |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2643 | (limit--)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | *n++ = *p[0]++; |
| 2645 | *n = '\0'; |
| 2646 | } |
| 2647 | |
| 2648 | /* |
| 2649 | * Get phone-number from modem-commandbuffer |
| 2650 | */ |
| 2651 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2652 | isdn_tty_getdial(char *p, char *q, int cnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | { |
| 2654 | int first = 1; |
| 2655 | int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2656 | buffer overflow */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2658 | while (strchr(" 0123456789,#.*WPTSR-", *p) && *p && --cnt > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) || |
Karsten Keil | 924ad15 | 2007-06-01 00:46:55 -0700 | [diff] [blame] | 2660 | ((*p == 'R') && first) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | (*p == '*') || (*p == '#')) { |
| 2662 | *q++ = *p; |
| 2663 | limit--; |
| 2664 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2665 | if (!limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | break; |
| 2667 | p++; |
| 2668 | first = 0; |
| 2669 | } |
| 2670 | *q = 0; |
| 2671 | } |
| 2672 | |
| 2673 | #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; } |
| 2674 | #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; } |
| 2675 | |
| 2676 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2677 | isdn_tty_report(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | { |
| 2679 | atemu *m = &info->emu; |
| 2680 | char s[80]; |
| 2681 | |
| 2682 | isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info); |
| 2683 | sprintf(s, " Remote Number: %s\r\n", info->last_num); |
| 2684 | isdn_tty_at_cout(s, info); |
| 2685 | sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming"); |
| 2686 | isdn_tty_at_cout(s, info); |
| 2687 | isdn_tty_at_cout(" Layer-2 Protocol: ", info); |
| 2688 | switch (info->last_l2) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2689 | case ISDN_PROTO_L2_X75I: |
| 2690 | isdn_tty_at_cout("X.75i", info); |
| 2691 | break; |
| 2692 | case ISDN_PROTO_L2_X75UI: |
| 2693 | isdn_tty_at_cout("X.75ui", info); |
| 2694 | break; |
| 2695 | case ISDN_PROTO_L2_X75BUI: |
| 2696 | isdn_tty_at_cout("X.75bui", info); |
| 2697 | break; |
| 2698 | case ISDN_PROTO_L2_HDLC: |
| 2699 | isdn_tty_at_cout("HDLC", info); |
| 2700 | break; |
| 2701 | case ISDN_PROTO_L2_V11096: |
| 2702 | isdn_tty_at_cout("V.110 9600 Baud", info); |
| 2703 | break; |
| 2704 | case ISDN_PROTO_L2_V11019: |
| 2705 | isdn_tty_at_cout("V.110 19200 Baud", info); |
| 2706 | break; |
| 2707 | case ISDN_PROTO_L2_V11038: |
| 2708 | isdn_tty_at_cout("V.110 38400 Baud", info); |
| 2709 | break; |
| 2710 | case ISDN_PROTO_L2_TRANS: |
| 2711 | isdn_tty_at_cout("transparent", info); |
| 2712 | break; |
| 2713 | case ISDN_PROTO_L2_MODEM: |
| 2714 | isdn_tty_at_cout("modem", info); |
| 2715 | break; |
| 2716 | case ISDN_PROTO_L2_FAX: |
| 2717 | isdn_tty_at_cout("fax", info); |
| 2718 | break; |
| 2719 | default: |
| 2720 | isdn_tty_at_cout("unknown", info); |
| 2721 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } |
| 2723 | if (m->mdmreg[REG_T70] & BIT_T70) { |
| 2724 | isdn_tty_at_cout("/T.70", info); |
| 2725 | if (m->mdmreg[REG_T70] & BIT_T70_EXT) |
| 2726 | isdn_tty_at_cout("+", info); |
| 2727 | } |
| 2728 | isdn_tty_at_cout("\r\n", info); |
| 2729 | isdn_tty_at_cout(" Service: ", info); |
| 2730 | switch (info->last_si) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2731 | case 1: |
| 2732 | isdn_tty_at_cout("audio\r\n", info); |
| 2733 | break; |
| 2734 | case 5: |
| 2735 | isdn_tty_at_cout("btx\r\n", info); |
| 2736 | break; |
| 2737 | case 7: |
| 2738 | isdn_tty_at_cout("data\r\n", info); |
| 2739 | break; |
| 2740 | default: |
| 2741 | sprintf(s, "%d\r\n", info->last_si); |
| 2742 | isdn_tty_at_cout(s, info); |
| 2743 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | } |
| 2745 | sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote"); |
| 2746 | isdn_tty_at_cout(s, info); |
| 2747 | sprintf(s, " Last cause: %s\r\n", info->last_cause); |
| 2748 | isdn_tty_at_cout(s, info); |
| 2749 | } |
| 2750 | |
| 2751 | /* |
| 2752 | * Parse AT&.. commands. |
| 2753 | */ |
| 2754 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2755 | isdn_tty_cmd_ATand(char **p, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | { |
| 2757 | atemu *m = &info->emu; |
| 2758 | int i; |
| 2759 | char rb[100]; |
| 2760 | |
| 2761 | #define MAXRB (sizeof(rb) - 1) |
| 2762 | |
| 2763 | switch (*p[0]) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2764 | case 'B': |
| 2765 | /* &B - Set Buffersize */ |
| 2766 | p[0]++; |
| 2767 | i = isdn_getnum(p); |
| 2768 | if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX)) |
| 2769 | PARSE_ERROR1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | #ifdef CONFIG_ISDN_AUDIO |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2771 | if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF)) |
| 2772 | PARSE_ERROR1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2774 | m->mdmreg[REG_PSIZE] = i / 16; |
| 2775 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; |
| 2776 | switch (m->mdmreg[REG_L2PROT]) { |
| 2777 | case ISDN_PROTO_L2_V11096: |
| 2778 | case ISDN_PROTO_L2_V11019: |
| 2779 | case ISDN_PROTO_L2_V11038: |
| 2780 | info->xmit_size /= 10; |
| 2781 | } |
| 2782 | break; |
| 2783 | case 'C': |
| 2784 | /* &C - DCD Status */ |
| 2785 | p[0]++; |
| 2786 | switch (isdn_getnum(p)) { |
| 2787 | case 0: |
| 2788 | m->mdmreg[REG_DCD] &= ~BIT_DCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2790 | case 1: |
| 2791 | m->mdmreg[REG_DCD] |= BIT_DCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2793 | default: |
| 2794 | PARSE_ERROR1 |
| 2795 | } |
| 2796 | break; |
| 2797 | case 'D': |
| 2798 | /* &D - Set DTR-Low-behavior */ |
| 2799 | p[0]++; |
| 2800 | switch (isdn_getnum(p)) { |
| 2801 | case 0: |
| 2802 | m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP; |
| 2803 | m->mdmreg[REG_DTRR] &= ~BIT_DTRR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2805 | case 2: |
| 2806 | m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP; |
| 2807 | m->mdmreg[REG_DTRR] &= ~BIT_DTRR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2809 | case 3: |
| 2810 | m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP; |
| 2811 | m->mdmreg[REG_DTRR] |= BIT_DTRR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2813 | default: |
| 2814 | PARSE_ERROR1 |
| 2815 | } |
| 2816 | break; |
| 2817 | case 'E': |
| 2818 | /* &E -Set EAZ/MSN */ |
| 2819 | p[0]++; |
| 2820 | isdn_tty_get_msnstr(m->msn, p); |
| 2821 | break; |
| 2822 | case 'F': |
| 2823 | /* &F -Set Factory-Defaults */ |
| 2824 | p[0]++; |
| 2825 | if (info->msr & UART_MSR_DCD) |
| 2826 | PARSE_ERROR1; |
| 2827 | isdn_tty_reset_profile(m); |
| 2828 | isdn_tty_modem_reset_regs(info, 1); |
| 2829 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | #ifdef DUMMY_HAYES_AT |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2831 | case 'K': |
| 2832 | /* only for be compilant with common scripts */ |
| 2833 | /* &K Flowcontrol - no function */ |
| 2834 | p[0]++; |
| 2835 | isdn_getnum(p); |
| 2836 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2838 | case 'L': |
| 2839 | /* &L -Set Numbers to listen on */ |
| 2840 | p[0]++; |
| 2841 | i = 0; |
| 2842 | while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) && |
| 2843 | (i < ISDN_LMSNLEN - 1)) |
| 2844 | m->lmsn[i++] = *p[0]++; |
| 2845 | m->lmsn[i] = '\0'; |
| 2846 | break; |
| 2847 | case 'R': |
| 2848 | /* &R - Set V.110 bitrate adaption */ |
| 2849 | p[0]++; |
| 2850 | i = isdn_getnum(p); |
| 2851 | switch (i) { |
| 2852 | case 0: |
| 2853 | /* Switch off V.110, back to X.75 */ |
| 2854 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; |
| 2855 | m->mdmreg[REG_SI2] = 0; |
| 2856 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2858 | case 9600: |
| 2859 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096; |
| 2860 | m->mdmreg[REG_SI2] = 197; |
| 2861 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2863 | case 19200: |
| 2864 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019; |
| 2865 | m->mdmreg[REG_SI2] = 199; |
| 2866 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2868 | case 38400: |
| 2869 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038; |
| 2870 | m->mdmreg[REG_SI2] = 198; /* no existing standard for this */ |
| 2871 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | break; |
| 2873 | default: |
| 2874 | PARSE_ERROR1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2875 | } |
| 2876 | /* Switch off T.70 */ |
| 2877 | m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT); |
| 2878 | /* Set Service 7 */ |
| 2879 | m->mdmreg[REG_SI1] |= 4; |
| 2880 | break; |
| 2881 | case 'S': |
| 2882 | /* &S - Set Windowsize */ |
| 2883 | p[0]++; |
| 2884 | i = isdn_getnum(p); |
| 2885 | if ((i > 0) && (i < 9)) |
| 2886 | m->mdmreg[REG_WSIZE] = i; |
| 2887 | else |
| 2888 | PARSE_ERROR1; |
| 2889 | break; |
| 2890 | case 'V': |
| 2891 | /* &V - Show registers */ |
| 2892 | p[0]++; |
| 2893 | isdn_tty_at_cout("\r\n", info); |
| 2894 | for (i = 0; i < ISDN_MODEM_NUMREG; i++) { |
| 2895 | sprintf(rb, "S%02d=%03d%s", i, |
| 2896 | m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n"); |
| 2897 | isdn_tty_at_cout(rb, info); |
| 2898 | } |
| 2899 | sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n", |
| 2900 | strlen(m->msn) ? m->msn : "None"); |
| 2901 | isdn_tty_at_cout(rb, info); |
| 2902 | if (strlen(m->lmsn)) { |
| 2903 | isdn_tty_at_cout("\r\nListen: ", info); |
| 2904 | isdn_tty_at_cout(m->lmsn, info); |
| 2905 | isdn_tty_at_cout("\r\n", info); |
| 2906 | } |
| 2907 | break; |
| 2908 | case 'W': |
| 2909 | /* &W - Write Profile */ |
| 2910 | p[0]++; |
| 2911 | switch (*p[0]) { |
| 2912 | case '0': |
| 2913 | p[0]++; |
| 2914 | modem_write_profile(m); |
| 2915 | break; |
| 2916 | default: |
| 2917 | PARSE_ERROR1; |
| 2918 | } |
| 2919 | break; |
| 2920 | case 'X': |
| 2921 | /* &X - Switch to BTX-Mode and T.70 */ |
| 2922 | p[0]++; |
| 2923 | switch (isdn_getnum(p)) { |
| 2924 | case 0: |
| 2925 | m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT); |
| 2926 | info->xmit_size = m->mdmreg[REG_PSIZE] * 16; |
| 2927 | break; |
| 2928 | case 1: |
| 2929 | m->mdmreg[REG_T70] |= BIT_T70; |
| 2930 | m->mdmreg[REG_T70] &= ~BIT_T70_EXT; |
| 2931 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; |
| 2932 | info->xmit_size = 112; |
| 2933 | m->mdmreg[REG_SI1] = 4; |
| 2934 | m->mdmreg[REG_SI2] = 0; |
| 2935 | break; |
| 2936 | case 2: |
| 2937 | m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT); |
| 2938 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; |
| 2939 | info->xmit_size = 112; |
| 2940 | m->mdmreg[REG_SI1] = 4; |
| 2941 | m->mdmreg[REG_SI2] = 0; |
| 2942 | break; |
| 2943 | default: |
| 2944 | PARSE_ERROR1; |
| 2945 | } |
| 2946 | break; |
| 2947 | default: |
| 2948 | PARSE_ERROR1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | } |
| 2950 | return 0; |
| 2951 | } |
| 2952 | |
| 2953 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2954 | isdn_tty_check_ats(int mreg, int mval, modem_info *info, atemu *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | { |
| 2956 | /* Some plausibility checks */ |
| 2957 | switch (mreg) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2958 | case REG_L2PROT: |
| 2959 | if (mval > ISDN_PROTO_L2_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | return 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2961 | break; |
| 2962 | case REG_PSIZE: |
| 2963 | if ((mval * 16) > ISDN_SERIAL_XMIT_MAX) |
| 2964 | return 1; |
| 2965 | #ifdef CONFIG_ISDN_AUDIO |
| 2966 | if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX)) |
| 2967 | return 1; |
| 2968 | #endif |
| 2969 | info->xmit_size = mval * 16; |
| 2970 | switch (m->mdmreg[REG_L2PROT]) { |
| 2971 | case ISDN_PROTO_L2_V11096: |
| 2972 | case ISDN_PROTO_L2_V11019: |
| 2973 | case ISDN_PROTO_L2_V11038: |
| 2974 | info->xmit_size /= 10; |
| 2975 | } |
| 2976 | break; |
| 2977 | case REG_SI1I: |
| 2978 | case REG_PLAN: |
| 2979 | case REG_SCREEN: |
| 2980 | /* readonly registers */ |
| 2981 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
| 2983 | return 0; |
| 2984 | } |
| 2985 | |
| 2986 | /* |
| 2987 | * Perform ATS command |
| 2988 | */ |
| 2989 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2990 | isdn_tty_cmd_ATS(char **p, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | { |
| 2992 | atemu *m = &info->emu; |
| 2993 | int bitpos; |
| 2994 | int mreg; |
| 2995 | int mval; |
| 2996 | int bval; |
| 2997 | |
| 2998 | mreg = isdn_getnum(p); |
| 2999 | if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG) |
| 3000 | PARSE_ERROR1; |
| 3001 | switch (*p[0]) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3002 | case '=': |
| 3003 | p[0]++; |
| 3004 | mval = isdn_getnum(p); |
| 3005 | if (mval < 0 || mval > 255) |
| 3006 | PARSE_ERROR1; |
| 3007 | if (isdn_tty_check_ats(mreg, mval, info, m)) |
| 3008 | PARSE_ERROR1; |
| 3009 | m->mdmreg[mreg] = mval; |
| 3010 | break; |
| 3011 | case '.': |
| 3012 | /* Set/Clear a single bit */ |
| 3013 | p[0]++; |
| 3014 | bitpos = isdn_getnum(p); |
| 3015 | if ((bitpos < 0) || (bitpos > 7)) |
| 3016 | PARSE_ERROR1; |
| 3017 | switch (*p[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | case '=': |
| 3019 | p[0]++; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3020 | bval = isdn_getnum(p); |
| 3021 | if (bval < 0 || bval > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | PARSE_ERROR1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3023 | if (bval) |
| 3024 | mval = m->mdmreg[mreg] | (1 << bitpos); |
| 3025 | else |
| 3026 | mval = m->mdmreg[mreg] & ~(1 << bitpos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | if (isdn_tty_check_ats(mreg, mval, info, m)) |
| 3028 | PARSE_ERROR1; |
| 3029 | m->mdmreg[mreg] = mval; |
| 3030 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | case '?': |
| 3032 | p[0]++; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3033 | isdn_tty_at_cout("\r\n", info); |
| 3034 | isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0", |
| 3035 | info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | break; |
| 3037 | default: |
| 3038 | PARSE_ERROR1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3039 | } |
| 3040 | break; |
| 3041 | case '?': |
| 3042 | p[0]++; |
| 3043 | isdn_tty_show_profile(mreg, info); |
| 3044 | break; |
| 3045 | default: |
| 3046 | PARSE_ERROR1; |
| 3047 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | } |
| 3049 | return 0; |
| 3050 | } |
| 3051 | |
| 3052 | /* |
| 3053 | * Perform ATA command |
| 3054 | */ |
| 3055 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3056 | isdn_tty_cmd_ATA(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | { |
| 3058 | atemu *m = &info->emu; |
| 3059 | isdn_ctrl cmd; |
| 3060 | int l2; |
| 3061 | |
| 3062 | if (info->msr & UART_MSR_RI) { |
| 3063 | /* Accept incoming call */ |
| 3064 | info->last_dir = 0; |
| 3065 | strcpy(info->last_num, dev->num[info->drv_index]); |
| 3066 | m->mdmreg[REG_RINGCNT] = 0; |
| 3067 | info->msr &= ~UART_MSR_RI; |
| 3068 | l2 = m->mdmreg[REG_L2PROT]; |
| 3069 | #ifdef CONFIG_ISDN_AUDIO |
| 3070 | /* If more than one bit set in reg18, autoselect Layer2 */ |
| 3071 | if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) { |
| 3072 | if (m->mdmreg[REG_SI1I] == 1) { |
| 3073 | if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX)) |
| 3074 | l2 = ISDN_PROTO_L2_TRANS; |
| 3075 | } else |
| 3076 | l2 = ISDN_PROTO_L2_X75I; |
| 3077 | } |
| 3078 | #endif |
| 3079 | cmd.driver = info->isdn_driver; |
| 3080 | cmd.command = ISDN_CMD_SETL2; |
| 3081 | cmd.arg = info->isdn_channel + (l2 << 8); |
| 3082 | info->last_l2 = l2; |
| 3083 | isdn_command(&cmd); |
| 3084 | cmd.driver = info->isdn_driver; |
| 3085 | cmd.command = ISDN_CMD_SETL3; |
| 3086 | cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); |
| 3087 | #ifdef CONFIG_ISDN_TTY_FAX |
| 3088 | if (l2 == ISDN_PROTO_L2_FAX) { |
| 3089 | cmd.parm.fax = info->fax; |
| 3090 | info->fax->direction = ISDN_TTY_FAX_CONN_IN; |
| 3091 | } |
| 3092 | #endif |
| 3093 | isdn_command(&cmd); |
| 3094 | cmd.driver = info->isdn_driver; |
| 3095 | cmd.arg = info->isdn_channel; |
| 3096 | cmd.command = ISDN_CMD_ACCEPTD; |
| 3097 | info->dialing = 16; |
| 3098 | info->emu.carrierwait = 0; |
| 3099 | isdn_command(&cmd); |
| 3100 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); |
| 3101 | } else |
| 3102 | isdn_tty_modem_result(RESULT_NO_ANSWER, info); |
| 3103 | } |
| 3104 | |
| 3105 | #ifdef CONFIG_ISDN_AUDIO |
| 3106 | /* |
| 3107 | * Parse AT+F.. commands |
| 3108 | */ |
| 3109 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3110 | isdn_tty_cmd_PLUSF(char **p, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | { |
| 3112 | atemu *m = &info->emu; |
| 3113 | char rs[20]; |
| 3114 | |
| 3115 | if (!strncmp(p[0], "CLASS", 5)) { |
| 3116 | p[0] += 5; |
| 3117 | switch (*p[0]) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3118 | case '?': |
| 3119 | p[0]++; |
| 3120 | sprintf(rs, "\r\n%d", |
| 3121 | (m->mdmreg[REG_SI1] & 1) ? 8 : 0); |
| 3122 | #ifdef CONFIG_ISDN_TTY_FAX |
| 3123 | if (TTY_IS_FCLASS2(info)) |
| 3124 | sprintf(rs, "\r\n2"); |
| 3125 | else if (TTY_IS_FCLASS1(info)) |
| 3126 | sprintf(rs, "\r\n1"); |
| 3127 | #endif |
| 3128 | isdn_tty_at_cout(rs, info); |
| 3129 | break; |
| 3130 | case '=': |
| 3131 | p[0]++; |
| 3132 | switch (*p[0]) { |
| 3133 | case '0': |
| 3134 | p[0]++; |
| 3135 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; |
| 3136 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS; |
| 3137 | m->mdmreg[REG_SI1] = 4; |
| 3138 | info->xmit_size = |
| 3139 | m->mdmreg[REG_PSIZE] * 16; |
| 3140 | break; |
| 3141 | #ifdef CONFIG_ISDN_TTY_FAX |
| 3142 | case '1': |
| 3143 | p[0]++; |
| 3144 | if (!(dev->global_features & |
| 3145 | ISDN_FEATURE_L3_FCLASS1)) |
| 3146 | PARSE_ERROR1; |
| 3147 | m->mdmreg[REG_SI1] = 1; |
| 3148 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX; |
| 3149 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1; |
| 3150 | info->xmit_size = |
| 3151 | m->mdmreg[REG_PSIZE] * 16; |
| 3152 | break; |
| 3153 | case '2': |
| 3154 | p[0]++; |
| 3155 | if (!(dev->global_features & |
| 3156 | ISDN_FEATURE_L3_FCLASS2)) |
| 3157 | PARSE_ERROR1; |
| 3158 | m->mdmreg[REG_SI1] = 1; |
| 3159 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX; |
| 3160 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2; |
| 3161 | info->xmit_size = |
| 3162 | m->mdmreg[REG_PSIZE] * 16; |
| 3163 | break; |
| 3164 | #endif |
| 3165 | case '8': |
| 3166 | p[0]++; |
| 3167 | /* L2 will change on dialout with si=1 */ |
| 3168 | m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; |
| 3169 | m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS; |
| 3170 | m->mdmreg[REG_SI1] = 5; |
| 3171 | info->xmit_size = VBUF; |
| 3172 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | case '?': |
| 3174 | p[0]++; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3175 | strcpy(rs, "\r\n0,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | #ifdef CONFIG_ISDN_TTY_FAX |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3177 | if (dev->global_features & |
| 3178 | ISDN_FEATURE_L3_FCLASS1) |
| 3179 | strcat(rs, "1,"); |
| 3180 | if (dev->global_features & |
| 3181 | ISDN_FEATURE_L3_FCLASS2) |
| 3182 | strcat(rs, "2,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3184 | strcat(rs, "8"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | isdn_tty_at_cout(rs, info); |
| 3186 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | default: |
| 3188 | PARSE_ERROR1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3189 | } |
| 3190 | break; |
| 3191 | default: |
| 3192 | PARSE_ERROR1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | } |
| 3194 | return 0; |
| 3195 | } |
| 3196 | #ifdef CONFIG_ISDN_TTY_FAX |
| 3197 | return (isdn_tty_cmd_PLUSF_FAX(p, info)); |
| 3198 | #else |
| 3199 | PARSE_ERROR1; |
| 3200 | #endif |
| 3201 | } |
| 3202 | |
| 3203 | /* |
| 3204 | * Parse AT+V.. commands |
| 3205 | */ |
| 3206 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3207 | isdn_tty_cmd_PLUSV(char **p, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | { |
| 3209 | atemu *m = &info->emu; |
| 3210 | isdn_ctrl cmd; |
| 3211 | static char *vcmd[] = |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3212 | {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | int i; |
| 3214 | int par1; |
| 3215 | int par2; |
| 3216 | char rs[20]; |
| 3217 | |
| 3218 | i = 0; |
| 3219 | while (vcmd[i]) { |
| 3220 | if (!strncmp(vcmd[i], p[0], 2)) { |
| 3221 | p[0] += 2; |
| 3222 | break; |
| 3223 | } |
| 3224 | i++; |
| 3225 | } |
| 3226 | switch (i) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3227 | case 0: |
| 3228 | /* AT+VNH - Auto hangup feature */ |
| 3229 | switch (*p[0]) { |
| 3230 | case '?': |
| 3231 | p[0]++; |
| 3232 | isdn_tty_at_cout("\r\n1", info); |
| 3233 | break; |
| 3234 | case '=': |
| 3235 | p[0]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | switch (*p[0]) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3237 | case '1': |
| 3238 | p[0]++; |
| 3239 | break; |
| 3240 | case '?': |
| 3241 | p[0]++; |
| 3242 | isdn_tty_at_cout("\r\n1", info); |
| 3243 | break; |
| 3244 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | PARSE_ERROR1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | } |
| 3247 | break; |
| 3248 | default: |
| 3249 | PARSE_ERROR1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3250 | } |
| 3251 | break; |
| 3252 | case 1: |
| 3253 | /* AT+VIP - Reset all voice parameters */ |
| 3254 | isdn_tty_modem_reset_vpar(m); |
| 3255 | break; |
| 3256 | case 2: |
| 3257 | /* AT+VLS - Select device, accept incoming call */ |
| 3258 | switch (*p[0]) { |
| 3259 | case '?': |
| 3260 | p[0]++; |
| 3261 | sprintf(rs, "\r\n%d", m->vpar[0]); |
| 3262 | isdn_tty_at_cout(rs, info); |
| 3263 | break; |
| 3264 | case '=': |
| 3265 | p[0]++; |
| 3266 | switch (*p[0]) { |
| 3267 | case '0': |
| 3268 | p[0]++; |
| 3269 | m->vpar[0] = 0; |
| 3270 | break; |
| 3271 | case '2': |
| 3272 | p[0]++; |
| 3273 | m->vpar[0] = 2; |
| 3274 | break; |
| 3275 | case '?': |
| 3276 | p[0]++; |
| 3277 | isdn_tty_at_cout("\r\n0,2", info); |
| 3278 | break; |
| 3279 | default: |
| 3280 | PARSE_ERROR1; |
| 3281 | } |
| 3282 | break; |
| 3283 | default: |
| 3284 | PARSE_ERROR1; |
| 3285 | } |
| 3286 | break; |
| 3287 | case 3: |
| 3288 | /* AT+VRX - Start recording */ |
| 3289 | if (!m->vpar[0]) |
| 3290 | PARSE_ERROR1; |
| 3291 | if (info->online != 1) { |
| 3292 | isdn_tty_modem_result(RESULT_NO_ANSWER, info); |
| 3293 | return 1; |
| 3294 | } |
| 3295 | info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state); |
| 3296 | if (!info->dtmf_state) { |
| 3297 | printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n"); |
| 3298 | PARSE_ERROR1; |
| 3299 | } |
| 3300 | info->silence_state = isdn_audio_silence_init(info->silence_state); |
| 3301 | if (!info->silence_state) { |
| 3302 | printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n"); |
| 3303 | PARSE_ERROR1; |
| 3304 | } |
| 3305 | if (m->vpar[3] < 5) { |
| 3306 | info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]); |
| 3307 | if (!info->adpcmr) { |
| 3308 | printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n"); |
| 3309 | PARSE_ERROR1; |
| 3310 | } |
| 3311 | } |
| 3312 | #ifdef ISDN_DEBUG_AT |
| 3313 | printk(KERN_DEBUG "AT: +VRX\n"); |
| 3314 | #endif |
| 3315 | info->vonline |= 1; |
| 3316 | isdn_tty_modem_result(RESULT_CONNECT, info); |
| 3317 | return 0; |
| 3318 | break; |
| 3319 | case 4: |
| 3320 | /* AT+VSD - Silence detection */ |
| 3321 | switch (*p[0]) { |
| 3322 | case '?': |
| 3323 | p[0]++; |
| 3324 | sprintf(rs, "\r\n<%d>,<%d>", |
| 3325 | m->vpar[1], |
| 3326 | m->vpar[2]); |
| 3327 | isdn_tty_at_cout(rs, info); |
| 3328 | break; |
| 3329 | case '=': |
| 3330 | p[0]++; |
| 3331 | if ((*p[0] >= '0') && (*p[0] <= '9')) { |
| 3332 | par1 = isdn_getnum(p); |
| 3333 | if ((par1 < 0) || (par1 > 31)) |
| 3334 | PARSE_ERROR1; |
| 3335 | if (*p[0] != ',') |
| 3336 | PARSE_ERROR1; |
| 3337 | p[0]++; |
| 3338 | par2 = isdn_getnum(p); |
| 3339 | if ((par2 < 0) || (par2 > 255)) |
| 3340 | PARSE_ERROR1; |
| 3341 | m->vpar[1] = par1; |
| 3342 | m->vpar[2] = par2; |
| 3343 | break; |
| 3344 | } else |
| 3345 | if (*p[0] == '?') { |
| 3346 | p[0]++; |
| 3347 | isdn_tty_at_cout("\r\n<0-31>,<0-255>", |
| 3348 | info); |
| 3349 | break; |
| 3350 | } else |
| 3351 | PARSE_ERROR1; |
| 3352 | break; |
| 3353 | default: |
| 3354 | PARSE_ERROR1; |
| 3355 | } |
| 3356 | break; |
| 3357 | case 5: |
| 3358 | /* AT+VSM - Select compression */ |
| 3359 | switch (*p[0]) { |
| 3360 | case '?': |
| 3361 | p[0]++; |
| 3362 | sprintf(rs, "\r\n<%d>,<%d><8000>", |
| 3363 | m->vpar[3], |
| 3364 | m->vpar[1]); |
| 3365 | isdn_tty_at_cout(rs, info); |
| 3366 | break; |
| 3367 | case '=': |
| 3368 | p[0]++; |
| 3369 | switch (*p[0]) { |
| 3370 | case '2': |
| 3371 | case '3': |
| 3372 | case '4': |
| 3373 | case '5': |
| 3374 | case '6': |
| 3375 | par1 = isdn_getnum(p); |
| 3376 | if ((par1 < 2) || (par1 > 6)) |
| 3377 | PARSE_ERROR1; |
| 3378 | m->vpar[3] = par1; |
| 3379 | break; |
| 3380 | case '?': |
| 3381 | p[0]++; |
| 3382 | isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n", |
| 3383 | info); |
| 3384 | isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n", |
| 3385 | info); |
| 3386 | isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n", |
| 3387 | info); |
| 3388 | isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n", |
| 3389 | info); |
| 3390 | isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n", |
| 3391 | info); |
| 3392 | break; |
| 3393 | default: |
| 3394 | PARSE_ERROR1; |
| 3395 | } |
| 3396 | break; |
| 3397 | default: |
| 3398 | PARSE_ERROR1; |
| 3399 | } |
| 3400 | break; |
| 3401 | case 6: |
| 3402 | /* AT+VTX - Start sending */ |
| 3403 | if (!m->vpar[0]) |
| 3404 | PARSE_ERROR1; |
| 3405 | if (info->online != 1) { |
| 3406 | isdn_tty_modem_result(RESULT_NO_ANSWER, info); |
| 3407 | return 1; |
| 3408 | } |
| 3409 | info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state); |
| 3410 | if (!info->dtmf_state) { |
| 3411 | printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n"); |
| 3412 | PARSE_ERROR1; |
| 3413 | } |
| 3414 | if (m->vpar[3] < 5) { |
| 3415 | info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]); |
| 3416 | if (!info->adpcms) { |
| 3417 | printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n"); |
| 3418 | PARSE_ERROR1; |
| 3419 | } |
| 3420 | } |
| 3421 | #ifdef ISDN_DEBUG_AT |
| 3422 | printk(KERN_DEBUG "AT: +VTX\n"); |
| 3423 | #endif |
| 3424 | m->lastDLE = 0; |
| 3425 | info->vonline |= 2; |
| 3426 | isdn_tty_modem_result(RESULT_CONNECT, info); |
| 3427 | return 0; |
| 3428 | break; |
| 3429 | case 7: |
| 3430 | /* AT+VDD - DTMF detection */ |
| 3431 | switch (*p[0]) { |
| 3432 | case '?': |
| 3433 | p[0]++; |
| 3434 | sprintf(rs, "\r\n<%d>,<%d>", |
| 3435 | m->vpar[4], |
| 3436 | m->vpar[5]); |
| 3437 | isdn_tty_at_cout(rs, info); |
| 3438 | break; |
| 3439 | case '=': |
| 3440 | p[0]++; |
| 3441 | if ((*p[0] >= '0') && (*p[0] <= '9')) { |
| 3442 | if (info->online != 1) |
| 3443 | PARSE_ERROR1; |
| 3444 | par1 = isdn_getnum(p); |
| 3445 | if ((par1 < 0) || (par1 > 15)) |
| 3446 | PARSE_ERROR1; |
| 3447 | if (*p[0] != ',') |
| 3448 | PARSE_ERROR1; |
| 3449 | p[0]++; |
| 3450 | par2 = isdn_getnum(p); |
| 3451 | if ((par2 < 0) || (par2 > 255)) |
| 3452 | PARSE_ERROR1; |
| 3453 | m->vpar[4] = par1; |
| 3454 | m->vpar[5] = par2; |
| 3455 | cmd.driver = info->isdn_driver; |
| 3456 | cmd.command = ISDN_CMD_AUDIO; |
| 3457 | cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8); |
| 3458 | cmd.parm.num[0] = par1; |
| 3459 | cmd.parm.num[1] = par2; |
| 3460 | isdn_command(&cmd); |
| 3461 | break; |
| 3462 | } else |
| 3463 | if (*p[0] == '?') { |
| 3464 | p[0]++; |
| 3465 | isdn_tty_at_cout("\r\n<0-15>,<0-255>", |
| 3466 | info); |
| 3467 | break; |
| 3468 | } else |
| 3469 | PARSE_ERROR1; |
| 3470 | break; |
| 3471 | default: |
| 3472 | PARSE_ERROR1; |
| 3473 | } |
| 3474 | break; |
| 3475 | default: |
| 3476 | PARSE_ERROR1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | } |
| 3478 | return 0; |
| 3479 | } |
| 3480 | #endif /* CONFIG_ISDN_AUDIO */ |
| 3481 | |
| 3482 | /* |
| 3483 | * Parse and perform an AT-command-line. |
| 3484 | */ |
| 3485 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3486 | isdn_tty_parse_at(modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | { |
| 3488 | atemu *m = &info->emu; |
| 3489 | char *p; |
Dan Carpenter | f417f5e | 2010-09-04 08:33:03 +0000 | [diff] [blame] | 3490 | char ds[ISDN_MSNLEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | |
| 3492 | #ifdef ISDN_DEBUG_AT |
| 3493 | printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd); |
| 3494 | #endif |
| 3495 | for (p = &m->mdmcmd[2]; *p;) { |
| 3496 | switch (*p) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3497 | case ' ': |
| 3498 | p++; |
| 3499 | break; |
| 3500 | case 'A': |
| 3501 | /* A - Accept incoming call */ |
| 3502 | p++; |
| 3503 | isdn_tty_cmd_ATA(info); |
| 3504 | return; |
| 3505 | break; |
| 3506 | case 'D': |
| 3507 | /* D - Dial */ |
| 3508 | if (info->msr & UART_MSR_DCD) |
| 3509 | PARSE_ERROR; |
| 3510 | if (info->msr & UART_MSR_RI) { |
| 3511 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | return; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3513 | } |
| 3514 | isdn_tty_getdial(++p, ds, sizeof ds); |
| 3515 | p += strlen(p); |
| 3516 | if (!strlen(m->msn)) |
| 3517 | isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info); |
| 3518 | else if (strlen(ds)) |
| 3519 | isdn_tty_dial(ds, info, m); |
| 3520 | else |
| 3521 | PARSE_ERROR; |
| 3522 | return; |
| 3523 | case 'E': |
| 3524 | /* E - Turn Echo on/off */ |
| 3525 | p++; |
| 3526 | switch (isdn_getnum(&p)) { |
| 3527 | case 0: |
| 3528 | m->mdmreg[REG_ECHO] &= ~BIT_ECHO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3530 | case 1: |
| 3531 | m->mdmreg[REG_ECHO] |= BIT_ECHO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | break; |
| 3533 | default: |
| 3534 | PARSE_ERROR; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3535 | } |
| 3536 | break; |
| 3537 | case 'H': |
| 3538 | /* H - On/Off-hook */ |
| 3539 | p++; |
| 3540 | switch (*p) { |
| 3541 | case '0': |
| 3542 | p++; |
| 3543 | isdn_tty_on_hook(info); |
| 3544 | break; |
| 3545 | case '1': |
| 3546 | p++; |
| 3547 | isdn_tty_off_hook(); |
| 3548 | break; |
| 3549 | default: |
| 3550 | isdn_tty_on_hook(info); |
| 3551 | break; |
| 3552 | } |
| 3553 | break; |
| 3554 | case 'I': |
| 3555 | /* I - Information */ |
| 3556 | p++; |
| 3557 | isdn_tty_at_cout("\r\nLinux ISDN", info); |
| 3558 | switch (*p) { |
| 3559 | case '0': |
| 3560 | case '1': |
| 3561 | p++; |
| 3562 | break; |
| 3563 | case '2': |
| 3564 | p++; |
| 3565 | isdn_tty_report(info); |
| 3566 | break; |
| 3567 | case '3': |
| 3568 | p++; |
| 3569 | snprintf(ds, sizeof(ds), "\r\n%d", info->emu.charge); |
| 3570 | isdn_tty_at_cout(ds, info); |
| 3571 | break; |
| 3572 | default:; |
| 3573 | } |
| 3574 | break; |
| 3575 | #ifdef DUMMY_HAYES_AT |
| 3576 | case 'L': |
| 3577 | case 'M': |
| 3578 | /* only for be compilant with common scripts */ |
| 3579 | /* no function */ |
| 3580 | p++; |
| 3581 | isdn_getnum(&p); |
| 3582 | break; |
| 3583 | #endif |
| 3584 | case 'O': |
| 3585 | /* O - Go online */ |
| 3586 | p++; |
| 3587 | if (info->msr & UART_MSR_DCD) |
| 3588 | /* if B-Channel is up */ |
| 3589 | isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT : RESULT_CONNECT64000, info); |
| 3590 | else |
| 3591 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
| 3592 | return; |
| 3593 | case 'Q': |
| 3594 | /* Q - Turn Emulator messages on/off */ |
| 3595 | p++; |
| 3596 | switch (isdn_getnum(&p)) { |
| 3597 | case 0: |
| 3598 | m->mdmreg[REG_RESP] |= BIT_RESP; |
| 3599 | break; |
| 3600 | case 1: |
| 3601 | m->mdmreg[REG_RESP] &= ~BIT_RESP; |
| 3602 | break; |
| 3603 | default: |
| 3604 | PARSE_ERROR; |
| 3605 | } |
| 3606 | break; |
| 3607 | case 'S': |
| 3608 | /* S - Set/Get Register */ |
| 3609 | p++; |
| 3610 | if (isdn_tty_cmd_ATS(&p, info)) |
| 3611 | return; |
| 3612 | break; |
| 3613 | case 'V': |
| 3614 | /* V - Numeric or ASCII Emulator-messages */ |
| 3615 | p++; |
| 3616 | switch (isdn_getnum(&p)) { |
| 3617 | case 0: |
| 3618 | m->mdmreg[REG_RESP] |= BIT_RESPNUM; |
| 3619 | break; |
| 3620 | case 1: |
| 3621 | m->mdmreg[REG_RESP] &= ~BIT_RESPNUM; |
| 3622 | break; |
| 3623 | default: |
| 3624 | PARSE_ERROR; |
| 3625 | } |
| 3626 | break; |
| 3627 | case 'Z': |
| 3628 | /* Z - Load Registers from Profile */ |
| 3629 | p++; |
| 3630 | if (info->msr & UART_MSR_DCD) { |
| 3631 | info->online = 0; |
| 3632 | isdn_tty_on_hook(info); |
| 3633 | } |
| 3634 | isdn_tty_modem_reset_regs(info, 1); |
| 3635 | break; |
| 3636 | case '+': |
| 3637 | p++; |
| 3638 | switch (*p) { |
| 3639 | #ifdef CONFIG_ISDN_AUDIO |
| 3640 | case 'F': |
| 3641 | p++; |
| 3642 | if (isdn_tty_cmd_PLUSF(&p, info)) |
| 3643 | return; |
| 3644 | break; |
| 3645 | case 'V': |
| 3646 | if ((!(m->mdmreg[REG_SI1] & 1)) || |
| 3647 | (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM)) |
| 3648 | PARSE_ERROR; |
| 3649 | p++; |
| 3650 | if (isdn_tty_cmd_PLUSV(&p, info)) |
| 3651 | return; |
| 3652 | break; |
| 3653 | #endif /* CONFIG_ISDN_AUDIO */ |
| 3654 | case 'S': /* SUSPEND */ |
| 3655 | p++; |
| 3656 | isdn_tty_get_msnstr(ds, &p); |
| 3657 | isdn_tty_suspend(ds, info, m); |
| 3658 | break; |
| 3659 | case 'R': /* RESUME */ |
| 3660 | p++; |
| 3661 | isdn_tty_get_msnstr(ds, &p); |
| 3662 | isdn_tty_resume(ds, info, m); |
| 3663 | break; |
| 3664 | case 'M': /* MESSAGE */ |
| 3665 | p++; |
| 3666 | isdn_tty_send_msg(info, m, p); |
| 3667 | break; |
| 3668 | default: |
| 3669 | PARSE_ERROR; |
| 3670 | } |
| 3671 | break; |
| 3672 | case '&': |
| 3673 | p++; |
| 3674 | if (isdn_tty_cmd_ATand(&p, info)) |
| 3675 | return; |
| 3676 | break; |
| 3677 | default: |
| 3678 | PARSE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | } |
| 3680 | } |
| 3681 | #ifdef CONFIG_ISDN_AUDIO |
| 3682 | if (!info->vonline) |
| 3683 | #endif |
| 3684 | isdn_tty_modem_result(RESULT_OK, info); |
| 3685 | } |
| 3686 | |
| 3687 | /* Need own toupper() because standard-toupper is not available |
| 3688 | * within modules. |
| 3689 | */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3690 | #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | |
| 3692 | /* |
| 3693 | * Perform line-editing of AT-commands |
| 3694 | * |
| 3695 | * Parameters: |
| 3696 | * p inputbuffer |
| 3697 | * count length of buffer |
| 3698 | * channel index to line (minor-device) |
| 3699 | */ |
| 3700 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3701 | isdn_tty_edit_at(const char *p, int count, modem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | { |
| 3703 | atemu *m = &info->emu; |
| 3704 | int total = 0; |
| 3705 | u_char c; |
| 3706 | char eb[2]; |
| 3707 | int cnt; |
| 3708 | |
| 3709 | for (cnt = count; cnt > 0; p++, cnt--) { |
| 3710 | c = *p; |
| 3711 | total++; |
| 3712 | if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) { |
| 3713 | /* Separator (CR or LF) */ |
| 3714 | m->mdmcmd[m->mdmcmdl] = 0; |
| 3715 | if (m->mdmreg[REG_ECHO] & BIT_ECHO) { |
| 3716 | eb[0] = c; |
| 3717 | eb[1] = 0; |
| 3718 | isdn_tty_at_cout(eb, info); |
| 3719 | } |
| 3720 | if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2)))) |
| 3721 | isdn_tty_parse_at(info); |
| 3722 | m->mdmcmdl = 0; |
| 3723 | continue; |
| 3724 | } |
| 3725 | if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) { |
| 3726 | /* Backspace-Function */ |
| 3727 | if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) { |
| 3728 | if (m->mdmcmdl) |
| 3729 | m->mdmcmdl--; |
| 3730 | if (m->mdmreg[REG_ECHO] & BIT_ECHO) |
| 3731 | isdn_tty_at_cout("\b", info); |
| 3732 | } |
| 3733 | continue; |
| 3734 | } |
| 3735 | if (cmdchar(c)) { |
| 3736 | if (m->mdmreg[REG_ECHO] & BIT_ECHO) { |
| 3737 | eb[0] = c; |
| 3738 | eb[1] = 0; |
| 3739 | isdn_tty_at_cout(eb, info); |
| 3740 | } |
| 3741 | if (m->mdmcmdl < 255) { |
| 3742 | c = my_toupper(c); |
| 3743 | switch (m->mdmcmdl) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3744 | case 1: |
| 3745 | if (c == 'T') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | m->mdmcmd[m->mdmcmdl] = c; |
| 3747 | m->mdmcmd[++m->mdmcmdl] = 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 3748 | break; |
| 3749 | } else |
| 3750 | m->mdmcmdl = 0; |
| 3751 | /* Fall through, check for 'A' */ |
| 3752 | case 0: |
| 3753 | if (c == 'A') { |
| 3754 | m->mdmcmd[m->mdmcmdl] = c; |
| 3755 | m->mdmcmd[++m->mdmcmdl] = 0; |
| 3756 | } |
| 3757 | break; |
| 3758 | default: |
| 3759 | m->mdmcmd[m->mdmcmdl] = c; |
| 3760 | m->mdmcmd[++m->mdmcmdl] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | } |
| 3762 | } |
| 3763 | } |
| 3764 | } |
| 3765 | return total; |
| 3766 | } |
| 3767 | |
| 3768 | /* |
| 3769 | * Switch all modem-channels who are online and got a valid |
| 3770 | * escape-sequence 1.5 seconds ago, to command-mode. |
| 3771 | * This function is called every second via timer-interrupt from within |
| 3772 | * timer-dispatcher isdn_timer_function() |
| 3773 | */ |
| 3774 | void |
| 3775 | isdn_tty_modem_escape(void) |
| 3776 | { |
| 3777 | int ton = 0; |
| 3778 | int i; |
| 3779 | int midx; |
| 3780 | |
| 3781 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 3782 | if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) { |
| 3783 | modem_info *info = &dev->mdm.info[midx]; |
| 3784 | if (info->online) { |
| 3785 | ton = 1; |
| 3786 | if ((info->emu.pluscount == 3) && |
| 3787 | time_after(jiffies, |
| 3788 | info->emu.lastplus + PLUSWAIT2)) { |
| 3789 | info->emu.pluscount = 0; |
| 3790 | info->online = 0; |
| 3791 | isdn_tty_modem_result(RESULT_OK, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | } |
| 3793 | } |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 3794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); |
| 3796 | } |
| 3797 | |
| 3798 | /* |
| 3799 | * Put a RING-message to all modem-channels who have the RI-bit set. |
| 3800 | * This function is called every second via timer-interrupt from within |
| 3801 | * timer-dispatcher isdn_timer_function() |
| 3802 | */ |
| 3803 | void |
| 3804 | isdn_tty_modem_ring(void) |
| 3805 | { |
| 3806 | int ton = 0; |
| 3807 | int i; |
| 3808 | |
| 3809 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 3810 | modem_info *info = &dev->mdm.info[i]; |
| 3811 | if (info->msr & UART_MSR_RI) { |
| 3812 | ton = 1; |
| 3813 | isdn_tty_modem_result(RESULT_RING, info); |
| 3814 | } |
| 3815 | } |
| 3816 | isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton); |
| 3817 | } |
| 3818 | |
| 3819 | /* |
| 3820 | * For all online tty's, try sending data to |
| 3821 | * the lower levels. |
| 3822 | */ |
| 3823 | void |
| 3824 | isdn_tty_modem_xmit(void) |
| 3825 | { |
| 3826 | int ton = 1; |
| 3827 | int i; |
| 3828 | |
| 3829 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 3830 | modem_info *info = &dev->mdm.info[i]; |
| 3831 | if (info->online) { |
| 3832 | ton = 1; |
| 3833 | isdn_tty_senddown(info); |
| 3834 | isdn_tty_tint(info); |
| 3835 | } |
| 3836 | } |
| 3837 | isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton); |
| 3838 | } |
| 3839 | |
| 3840 | /* |
| 3841 | * Check all channels if we have a 'no carrier' timeout. |
| 3842 | * Timeout value is set by Register S7. |
| 3843 | */ |
| 3844 | void |
| 3845 | isdn_tty_carrier_timeout(void) |
| 3846 | { |
| 3847 | int ton = 0; |
| 3848 | int i; |
| 3849 | |
| 3850 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
| 3851 | modem_info *info = &dev->mdm.info[i]; |
Jiri Slaby | 37630f4 | 2012-04-02 13:53:52 +0200 | [diff] [blame] | 3852 | if (!info->dialing) |
| 3853 | continue; |
| 3854 | if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { |
| 3855 | info->dialing = 0; |
| 3856 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
| 3857 | isdn_tty_modem_hup(info, 1); |
| 3858 | } else |
| 3859 | ton = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | } |
| 3861 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); |
| 3862 | } |