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