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

📄 isdn_tty.c

📁 是关于linux2.5.1的完全源码
💻 C
📖 第 1 页 / 共 5 页
字号:
			return -EINVAL;	}	return 0;}static intisdn_tty_ioctl(struct tty_struct *tty, struct file *file,	       uint cmd, ulong arg){	modem_info *info = (modem_info *) tty->driver_data;	int retval;	if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_ioctl"))		return -ENODEV;	if (tty->flags & (1 << TTY_IO_ERROR))		return -EIO;	switch (cmd) {		case TCSBRK:   /* SVID version: non-zero arg --> no break */#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line);#endif			retval = tty_check_change(tty);			if (retval)				return retval;			tty_wait_until_sent(tty, 0);			return 0;		case TCSBRKP:  /* support for POSIX tcsendbreak() */#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line);#endif			retval = tty_check_change(tty);			if (retval)				return retval;			tty_wait_until_sent(tty, 0);			return 0;		case TIOCGSOFTCAR:#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "ttyI%d ioctl TIOCGSOFTCAR\n", info->line);#endif			return put_user(C_CLOCAL(tty) ? 1 : 0, (ulong *) arg);		case TIOCSSOFTCAR:#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "ttyI%d ioctl TIOCSSOFTCAR\n", info->line);#endif			if (get_user(arg, (ulong *) arg))				return -EFAULT;			tty->termios->c_cflag =			    ((tty->termios->c_cflag & ~CLOCAL) |			     (arg ? CLOCAL : 0));			return 0;		case TIOCMGET:#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);#endif			return isdn_tty_get_modem_info(info, (uint *) arg);		case TIOCMBIS:		case TIOCMBIC:		case TIOCMSET:			return isdn_tty_set_modem_info(info, cmd, (uint *) arg);		case TIOCSERGETLSR:	/* Get line status register */#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);#endif			return isdn_tty_get_lsr_info(info, (uint *) arg);		default:#ifdef ISDN_DEBUG_MODEM_IOCTL			printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line);#endif			return -ENOIOCTLCMD;	}	return 0;}static voidisdn_tty_set_termios(struct tty_struct *tty, struct termios *old_termios){	modem_info *info = (modem_info *) tty->driver_data;	if (!old_termios)		isdn_tty_change_speed(info);	else {		if (tty->termios->c_cflag == old_termios->c_cflag)			return;		isdn_tty_change_speed(info);		if ((old_termios->c_cflag & CRTSCTS) &&		    !(tty->termios->c_cflag & CRTSCTS)) {			tty->hw_stopped = 0;		}	}}/* * ------------------------------------------------------------ * isdn_tty_open() and friends * ------------------------------------------------------------ */static intisdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info * info){	DECLARE_WAITQUEUE(wait, NULL);	int do_clocal = 0;	unsigned long flags;	int retval;	/*	 * If the device is in the middle of being closed, then block	 * until it's done, and then try again.	 */	if (tty_hung_up_p(filp) ||	    (info->flags & ISDN_ASYNC_CLOSING)) {		if (info->flags & ISDN_ASYNC_CLOSING)			interruptible_sleep_on(&info->close_wait);#ifdef MODEM_DO_RESTART		if (info->flags & ISDN_ASYNC_HUP_NOTIFY)			return -EAGAIN;		else			return -ERESTARTSYS;#else		return -EAGAIN;#endif	}	/*	 * If this is a callout device, then just make sure the normal	 * device isn't being used.	 */	if (tty->driver.subtype == ISDN_SERIAL_TYPE_CALLOUT) {		if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)			return -EBUSY;		if ((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&		    (info->flags & ISDN_ASYNC_SESSION_LOCKOUT) &&		    (info->session != current->session))			return -EBUSY;		if ((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&		    (info->flags & ISDN_ASYNC_PGRP_LOCKOUT) &&		    (info->pgrp != current->pgrp))			return -EBUSY;		info->flags |= ISDN_ASYNC_CALLOUT_ACTIVE;		return 0;	}	/*	 * 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	save_flags(flags);	cli();	if (!(tty_hung_up_p(filp)))		info->count--;	restore_flags(flags);	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 = minor(tty->device) - tty->driver.minor_start;	if (line < 0 || line > ISDN_MAX_CHANNELS)		return -ENODEV;	info = &dev->mdm.info[line];	if (isdn_tty_paranoia_check(info, tty->device, "isdn_tty_open"))		return -ENODEV;#ifdef ISDN_DEBUG_MODEM_OPEN	printk(KERN_DEBUG "isdn_tty_open %s%d, count = %d\n", tty->driver.name,	       info->line, 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		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		return retval;	}	if ((info->count == 1) && (info->flags & ISDN_ASYNC_SPLIT_TERMIOS)) {		if (tty->driver.subtype == ISDN_SERIAL_TYPE_NORMAL)			*tty->termios = info->normal_termios;		else			*tty->termios = info->callout_termios;		isdn_tty_change_speed(info);	}	info->session = current->session;	info->pgrp = current->pgrp;#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 flags;	ulong timeout;	if (!info || isdn_tty_paranoia_check(info, tty->device, "isdn_tty_close"))		return;	save_flags(flags);	cli();	if (tty_hung_up_p(filp)) {		restore_flags(flags);#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) {		restore_flags(flags);#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)) {			set_current_state(TASK_INTERRUPTIBLE);			schedule_timeout(20);			if (time_after(jiffies,timeout))				break;		}	}	dev->modempoll--;	isdn_tty_shutdown(info);	if (tty->driver.flush_buffer)		tty->driver.flush_buffer(tty);	if (tty->ldisc.flush_buffer)		tty->ldisc.flush_buffer(tty);	info->tty = 0;	info->ncarrier = 0;	tty->closing = 0;	if (info->blocked_open) {		set_current_state(TASK_INTERRUPTIBLE);		schedule_timeout(50);		wake_up_interruptible(&info->open_wait);	}	info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE |			 ISDN_ASYNC_CLOSING);	wake_up_interruptible(&info->close_wait);	restore_flags(flags);#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->device, "isdn_tty_hangup"))		return;	isdn_tty_shutdown(info);	info->count = 0;	info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE);	info->tty = 0;	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);}

⌨️ 快捷键说明

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