⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isdn_tty.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	/*	 * If non-blocking mode is set, then make the check up front	 * and then exit.	 */	if ((filp->f_flags & O_NONBLOCK) ||	    (tty->flags & (1 << TTY_IO_ERROR))) {		if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)			return -EBUSY;		info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;		return 0;	}	if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) {		if (info->normal_termios.c_cflag & CLOCAL)			do_clocal = 1;	} else {		if (tty->termios->c_cflag & CLOCAL)			do_clocal = 1;	}	/*	 * Block waiting for the carrier detect and the line to become	 * free (i.e., not in use by the callout).  While we are in	 * this loop, info->count is dropped by one, so that	 * isdn_tty_close() knows when to free things.  We restore it upon	 * exit, either normal or abnormal.	 */	retval = 0;	add_wait_queue(&info->open_wait, &wait);#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",	       info->line, info->count);#endif	if (!(tty_hung_up_p(filp)))		info->count--;	info->blocked_open++;	while (1) {		set_current_state(TASK_INTERRUPTIBLE);		if (tty_hung_up_p(filp) ||		    !(info->flags & ISDN_ASYNC_INITIALIZED)) {#ifdef MODEM_DO_RESTART			if (info->flags & ISDN_ASYNC_HUP_NOTIFY)				retval = -EAGAIN;			else				retval = -ERESTARTSYS;#else			retval = -EAGAIN;#endif			break;		}		if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&		    !(info->flags & ISDN_ASYNC_CLOSING) &&		    (do_clocal || (info->msr & UART_MSR_DCD))) {			break;		}		if (signal_pending(current)) {			retval = -ERESTARTSYS;			break;		}#ifdef ISDN_DEBUG_MODEM_OPEN		printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",		       info->line, info->count);#endif		schedule();	}	current->state = TASK_RUNNING;	remove_wait_queue(&info->open_wait, &wait);	if (!tty_hung_up_p(filp))		info->count++;	info->blocked_open--;#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",	       info->line, info->count);#endif	if (retval)		return retval;	info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;	return 0;}/* * This routine is called whenever a serial port is opened.  It * enables interrupts for a serial port, linking in its async structure into * the IRQ chain.   It also performs the serial-specific * initialization for the tty structure. */static intisdn_tty_open(struct tty_struct *tty, struct file *filp){	modem_info *info;	int retval, line;	line = tty->index;	if (line < 0 || line > ISDN_MAX_CHANNELS)		return -ENODEV;	info = &dev->mdm.info[line];	if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))		return -ENODEV;	if (!try_module_get(info->owner)) {		printk(KERN_WARNING "%s: cannot reserve module\n", __FUNCTION__);		return -ENODEV;	}#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, 	       info->count);#endif	info->count++;	tty->driver_data = info;	info->tty = tty;	/*	 * Start up serial port	 */	retval = isdn_tty_startup(info);	if (retval) {#ifdef ISDN_DEBUG_MODEM_OPEN		printk(KERN_DEBUG "isdn_tty_open return after startup\n");#endif		module_put(info->owner);		return retval;	}	retval = isdn_tty_block_til_ready(tty, filp, info);	if (retval) {#ifdef ISDN_DEBUG_MODEM_OPEN		printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");#endif		module_put(info->owner);		return retval;	}#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line);#endif	dev->modempoll++;#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_open normal exit\n");#endif	return 0;}static voidisdn_tty_close(struct tty_struct *tty, struct file *filp){	modem_info *info = (modem_info *) tty->driver_data;	ulong timeout;	if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close"))		return;	if (tty_hung_up_p(filp)) {#ifdef ISDN_DEBUG_MODEM_OPEN		printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n");#endif		return;	}	if ((tty->count == 1) && (info->count != 1)) {		/*		 * Uh, oh.  tty->count is 1, which means that the tty		 * structure will be freed.  Info->count should always		 * be one in these conditions.  If it's greater than		 * one, we've got real problems, since it means the		 * serial port won't be shutdown.		 */		printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "		       "info->count is %d\n", info->count);		info->count = 1;	}	if (--info->count < 0) {		printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",		       info->line, info->count);		info->count = 0;	}	if (info->count) {#ifdef ISDN_DEBUG_MODEM_OPEN		printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");#endif		return;	}	info->flags |= ISDN_ASYNC_CLOSING;	/*	 * Save the termios structure, since this port may have	 * separate termios for callout and dialin.	 */	if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)		info->normal_termios = *tty->termios;	if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)		info->callout_termios = *tty->termios;	tty->closing = 1;	/*	 * At this point we stop accepting input.  To do this, we	 * disable the receive line status interrupts, and tell the	 * interrupt driver to stop checking the data ready bit in the	 * line status register.	 */	if (info->flags & ISDN_ASYNC_INITIALIZED) {		tty_wait_until_sent(tty, 3000);	/* 30 seconds timeout */		/*		 * Before we drop DTR, make sure the UART transmitter		 * has completely drained; this is especially		 * important if there is a transmit FIFO!		 */		timeout = jiffies + HZ;		while (!(info->lsr & UART_LSR_TEMT)) {			schedule_timeout_interruptible(20);			if (time_after(jiffies,timeout))				break;		}	}	dev->modempoll--;	isdn_tty_shutdown(info);		if (tty->driver->flush_buffer)		tty->driver->flush_buffer(tty);	tty_ldisc_flush(tty);	info->tty = NULL;	info->ncarrier = 0;	tty->closing = 0;	module_put(info->owner);	if (info->blocked_open) {		msleep_interruptible(500);		wake_up_interruptible(&info->open_wait);	}	info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CLOSING);	wake_up_interruptible(&info->close_wait);#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_close normal exit\n");#endif}/* * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled. */static voidisdn_tty_hangup(struct tty_struct *tty){	modem_info *info = (modem_info *) tty->driver_data;	if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))		return;	isdn_tty_shutdown(info);	info->count = 0;	info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE);	info->tty = NULL;	wake_up_interruptible(&info->open_wait);}/* This routine initializes all emulator-data. */static voidisdn_tty_reset_profile(atemu * m){	m->profile[0] = 0;	m->profile[1] = 0;	m->profile[2] = 43;	m->profile[3] = 13;	m->profile[4] = 10;	m->profile[5] = 8;	m->profile[6] = 3;	m->profile[7] = 60;	m->profile[8] = 2;	m->profile[9] = 6;	m->profile[10] = 7;	m->profile[11] = 70;	m->profile[12] = 0x45;	m->profile[13] = 4;	m->profile[14] = ISDN_PROTO_L2_X75I;	m->profile[15] = ISDN_PROTO_L3_TRANS;	m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16;	m->profile[17] = ISDN_MODEM_WINSIZE;	m->profile[18] = 4;	m->profile[19] = 0;	m->profile[20] = 0;	m->profile[23] = 0;	m->pmsn[0] = '\0';	m->plmsn[0] = '\0';}#ifdef CONFIG_ISDN_AUDIOstatic voidisdn_tty_modem_reset_vpar(atemu * m){	m->vpar[0] = 2;         /* Voice-device            (2 = phone line) */	m->vpar[1] = 0;         /* Silence detection level (0 = none      ) */	m->vpar[2] = 70;        /* Silence interval        (7 sec.        ) */	m->vpar[3] = 2;         /* Compression type        (1 = ADPCM-2   ) */	m->vpar[4] = 0;         /* DTMF detection level    (0 = softcode  ) */	m->vpar[5] = 8;         /* DTMF interval           (8 * 5 ms.     ) */}#endif#ifdef CONFIG_ISDN_TTY_FAXstatic voidisdn_tty_modem_reset_faxpar(modem_info * info){	T30_s *f = info->fax;	f->code = 0;	f->phase = ISDN_FAX_PHASE_IDLE;	f->direction = 0;	f->resolution = 1;	/* fine */	f->rate = 5;		/* 14400 bit/s */	f->width = 0;	f->length = 0;	f->compression = 0;	f->ecm = 0;	f->binary = 0;	f->scantime = 0;	memset(&f->id[0], 32, FAXIDLEN - 1);	f->id[FAXIDLEN - 1] = 0;	f->badlin = 0;	f->badmul = 0;	f->bor = 0;	f->nbc = 0;	f->cq = 0;	f->cr = 0;	f->ctcrty = 0;	f->minsp = 0;	f->phcto = 30;	f->rel = 0;	memset(&f->pollid[0], 32, FAXIDLEN - 1);	f->pollid[FAXIDLEN - 1] = 0;}#endifstatic voidisdn_tty_modem_reset_regs(modem_info * info, int force){	atemu *m = &info->emu;	if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {		memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);		memcpy(m->msn, m->pmsn, ISDN_MSNLEN);		memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);		info->xmit_size = m->mdmreg[REG_PSIZE] * 16;	}#ifdef CONFIG_ISDN_AUDIO	isdn_tty_modem_reset_vpar(m);#endif#ifdef CONFIG_ISDN_TTY_FAX	isdn_tty_modem_reset_faxpar(info);#endif	m->mdmcmdl = 0;}static voidmodem_write_profile(atemu * m){	memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG);	memcpy(m->pmsn, m->msn, ISDN_MSNLEN);	memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN);	if (dev->profd)		send_sig(SIGIO, dev->profd, 1);}static struct tty_operations modem_ops = {        .open = isdn_tty_open,	.close = isdn_tty_close,	.write = isdn_tty_write,	.flush_chars = isdn_tty_flush_chars,	.write_room = isdn_tty_write_room,	.chars_in_buffer = isdn_tty_chars_in_buffer,	.flush_buffer = isdn_tty_flush_buffer,	.ioctl = isdn_tty_ioctl,	.throttle = isdn_tty_throttle,	.unthrottle = isdn_tty_unthrottle,	.set_termios = isdn_tty_set_termios,	.hangup = isdn_tty_hangup,	.tiocmget = isdn_tty_tiocmget,	.tiocmset = isdn_tty_tiocmset,};intisdn_tty_modem_init(void){	isdn_modem_t	*m;	int		i, retval;	modem_info	*info;	m = &dev->mdm;	m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS);	if (!m->tty_modem)		return -ENOMEM;	m->tty_modem->name = "ttyI";	m->tty_modem->devfs_name = "isdn/ttyI";	m->tty_modem->major = ISDN_TTY_MAJOR;	m->tty_modem->minor_start = 0;	m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL;	m->tty_modem->subtype = SERIAL_TYPE_NORMAL;	m->tty_modem->init_termios = tty_std_termios;	m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;	m->tty_modem->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;	m->tty_modem->driver_name = "isdn_tty";	tty_set_operations(m->tty_modem, &modem_ops);	retval = tty_register_driver(m->tty_modem);	if (retval) {		printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n");		goto err;	}	for (i = 0; i < ISDN_MAX_CHANNELS; i++) {		info = &m->info[i];#ifdef CONFIG_ISDN_TTY_FAX		if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) {			printk(KERN_ERR "Could not allocate fax t30-buffer\n");			retval = -ENOMEM;			goto err_unregister;		}#endif#ifdef MODULE		info->owner = THIS_MODULE;#endif		spin_lock_init(&info->readlock);		init_MUTEX(&info->write_sem);		sprintf(info->last_cause, "0000");		sprintf(info->last_num, "none");		info->last_dir = 0;		info->last_lhup = 1;		info->last_l2 = -1;		info->last_si = 0;		isdn_tty_reset_profile(&info->emu);		isdn_tty_modem_reset_regs(info, 1);		info->magic = ISDN_ASYNC_MAGIC;		info->line = i;		info->tty = NULL;		info->x_char = 0;		info->count = 0;		info->blocked_open = 0;		init_waitqueue_head(&info->open_wait);		init_waitqueue_head(&info->close_wait);		info->isdn_driver = -1;		info->isdn_channel = -1;		info->drv_index = -1;		info->xmit_size = ISDN_SERIAL_XMIT_SIZE;		init_timer(&info->nc_timer);		info->nc_timer.function = isdn_tty_modem_do_ncarrier;		info->nc_timer.data = (unsigned long) info;		skb_queue_head_init(&info->xmit_queue);#ifdef CONFIG_ISDN_AUDIO		skb_queue_head_init(&info->dtmf_queue);#endif		if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) {			printk(KERN_ERR "Could not allocate modem xmit-buffer\n");			retval = -ENOMEM;			goto err_unregister;		}		/* Make room for T.70 header */		info->xmit_buf += 4;	}	return 0;err_unregister:	for (i--; i >= 0; i--) {		info = &m->info[i];#ifdef CONFIG_ISDN_TTY_FAX		kfree(info->fax);#endif		kfree(info->xmit_buf - 4);	}	tty_unregister_driver(m->tty_modem); err:	put_tty_driver(m->tty_modem);	m->tty_modem = NULL;	return retval;}voidisdn_tty_exit(void){	modem_info *info;	int i;	for (i = 0; i < ISDN_MAX_CHANNELS; i++) {		info = &dev->mdm.info[i];		isdn_tty_cleanup_xmit(info);#ifdef CONFIG_ISDN_TTY_FAX		kfree(info->fax);#endif		kfree(info->xmit_buf - 4);	}	tty_unregister_driver(dev->mdm.tty_modem);	put_tty_driver(dev->mdm.tty_modem);	dev->mdm.tty_modem = NULL;}/* * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx) *      match the MSN against the MSNs (glob patterns) defined for tty_emulator, *      and return 0 for match, 1 for no match, 2 if MSN could match if longer. */static intisdn_tty_match_icall(char *cid, atemu *emu, int di){#ifdef ISDN_DEBUG_MODEM_ICALL	printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",	       emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di),	       emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]);#endif	if (strlen(emu->lmsn)) {		char *p = emu->lmsn;		char *q;		int  tmp;		int  ret = 0;		while (1) {			if ((q = strchr(p, ';')))				*q = '\0';			if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret)				ret = tmp;#ifdef ISDN_DEBUG_MODEM_ICALL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -