Ejemplo n.º 1
0
static int
ucomioctl(dev_t dev, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
{
	struct ucom_softc *sc;
	struct tty *tp;
	int error;
	int s;
	int d;
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
	u_long oldcmd;
	struct termios term;
#endif

	USB_GET_SC(ucom, UCOMUNIT(dev), sc);
	tp = sc->sc_tty;

	if (sc->sc_dying)
		return (EIO);

	DPRINTF(("ucomioctl: cmd = 0x%08lx\n", cmd));

#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
	term = tp->t_termios;
	oldcmd = cmd;
	error = ttsetcompat(tp, &cmd, data, &term);
	if (error != 0)
		return (error);
	if (cmd != oldcmd)
		data = (caddr_t)&term;
#endif

	error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
	if (error != ENOIOCTL) {
		DPRINTF(("ucomioctl: l_ioctl: error = %d\n", error));
		return (error);
	}

	s = spltty();

	error = ttioctl(tp, cmd, data, flag);
	disc_optim(tp, &tp->t_termios, sc);
	if (error != ENOIOCTL) {
		splx(s);
		DPRINTF(("ucomioctl: ttioctl: error = %d\n", error));
		return (error);
	}

	if (sc->sc_callback->ucom_ioctl != NULL) {
		error = sc->sc_callback->ucom_ioctl(sc->sc_parent,
						    sc->sc_portno,
						    cmd, data, flag, p);
		if (error >= 0)
			return (error);
	}

	error = 0;

	DPRINTF(("ucomioctl: our cmd = 0x%08lx\n", cmd));

	switch (cmd) {
	case TIOCSBRK:
		DPRINTF(("ucomioctl: TIOCSBRK\n"));
		ucom_break(sc, 1);
		break;
	case TIOCCBRK:
		DPRINTF(("ucomioctl: TIOCCBRK\n"));
		ucom_break(sc, 0);
		break;

	case TIOCSDTR:
		DPRINTF(("ucomioctl: TIOCSDTR\n"));
		(void)ucomctl(sc, TIOCM_DTR, DMBIS);
		break;
	case TIOCCDTR:
		DPRINTF(("ucomioctl: TIOCCDTR\n"));
		(void)ucomctl(sc, TIOCM_DTR, DMBIC);
		break;

	case TIOCMSET:
		d = *(int *)data;
		DPRINTF(("ucomioctl: TIOCMSET, 0x%x\n", d));
		(void)ucomctl(sc, d, DMSET);
		break;
	case TIOCMBIS:
		d = *(int *)data;
		DPRINTF(("ucomioctl: TIOCMBIS, 0x%x\n", d));
		(void)ucomctl(sc, d, DMBIS);
		break;
	case TIOCMBIC:
		d = *(int *)data;
		DPRINTF(("ucomioctl: TIOCMBIC, 0x%x\n", d));
		(void)ucomctl(sc, d, DMBIC);
		break;
	case TIOCMGET:
		d = ucomctl(sc, 0, DMGET);
		DPRINTF(("ucomioctl: TIOCMGET, 0x%x\n", d));
		*(int *)data = d;
		break;

	default:
		DPRINTF(("ucomioctl: error: our cmd = 0x%08lx\n", cmd));
		error = ENOTTY;
		break;
	}

	splx(s);

	return (error);
}
Ejemplo n.º 2
0
/*ARGSUSED*/
__private_extern__ int
ttcompat(struct tty *tp, u_long com, caddr_t data, int flag, struct proc *p)
{
	switch (com) {
	case TIOCSETP:
	case TIOCSETN:
	case TIOCSETC:
	case TIOCSLTC:
	case TIOCLBIS:
	case TIOCLBIC:
	case TIOCLSET:
		/*
		 * See ttsetcompat() for a full description of these command
		 * values and their meanings.
		 */
	{
		struct termios term;
		int error;

		term = tp->t_termios;
		if ((error = ttsetcompat(tp, &com, data, &term)) != 0)
			return error;
		return ttioctl_locked(tp, com, (caddr_t) &term, flag, p);
	}
	case TIOCGETP:
		/*
		 * Get the current input and output speeds, and device
		 * flags, into the structure pointed to by 'data'.
		 */
	    {
		register struct sgttyb *sg = (struct sgttyb *)data;
		register cc_t *cc = tp->t_cc;

		sg->sg_ospeed = ttcompatspeedtab(tp->t_ospeed, compatspeeds);
		if (tp->t_ispeed == 0)
			sg->sg_ispeed = sg->sg_ospeed;
		else
			sg->sg_ispeed = ttcompatspeedtab(tp->t_ispeed, compatspeeds);
		sg->sg_erase = cc[VERASE];
		sg->sg_kill = cc[VKILL];
		sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);
		break;
	}
	case TIOCGETC:
		/*
		 * Get the terminal control characters into the struct
		 * tchars that 'data' points to.
		 */
	    {
		struct tchars *tc = (struct tchars *)data;
		register cc_t *cc = tp->t_cc;

		tc->t_intrc = cc[VINTR];
		tc->t_quitc = cc[VQUIT];
		tc->t_startc = cc[VSTART];
		tc->t_stopc = cc[VSTOP];
		tc->t_eofc = cc[VEOF];
		tc->t_brkc = cc[VEOL];
		break;
	}
	case TIOCGLTC:
		/*
		 * Get the terminal control characters into the struct
		 * ltchars that 'data' points to.
		 */
	{
		struct ltchars *ltc = (struct ltchars *)data;
		register cc_t *cc = tp->t_cc;

		ltc->t_suspc = cc[VSUSP];
		ltc->t_dsuspc = cc[VDSUSP];
		ltc->t_rprntc = cc[VREPRINT];
		ltc->t_flushc = cc[VDISCARD];
		ltc->t_werasc = cc[VWERASE];
		ltc->t_lnextc = cc[VLNEXT];
		break;
	}
	case TIOCLGET:
		/*
		 * Get the terminal state local flags word into the 16 bit
		 * value pointed to by 'data'.
		 */
		tp->t_flags =
		 (ttcompatgetflags(tp) & 0xffff0000UL)
		   | (tp->t_flags & 0xffff);
		*(int *)data = tp->t_flags>>16;
		break;

	case OTIOCGETD:
		/*
		 * Get the current line discipline into the int pointed to
		 * by 'data'.
		 */
		*(int *)data = tp->t_line ? tp->t_line : 2;
		break;

	case OTIOCSETD:
		/*
		 * Set the current line discipline based on the value of the
		 * int pointed to by 'data'.
		 */
	    {
		int ldisczero = 0;

		return (ttioctl_locked(tp, TIOCSETD, 
		    *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag, p));
	    }

	case OTIOCCONS:
		/*
		 * Become the console device.
		 */
		*(int *)data = 1;
		return (ttioctl_locked(tp, TIOCCONS, data, flag, p));

	case TIOCGSID:
		/*
		 * Get the current session ID (controlling process' PID).
		 */
		if (tp->t_session == NULL)
			return ENOTTY;

		if (tp->t_session->s_leader == NULL)
			return ENOTTY;

		*(int *) data =  tp->t_session->s_leader->p_pid;
		break;

	default:
		/*
		 * This ioctl is not handled at this layer.
		 */
		return (ENOTTY);
	}

	/*
	 * Successful 'get' operation.
	 */
	return (0);
}
Ejemplo n.º 3
0
/*ARGSUSED*/
int
ttcompat(struct tty *tp, u_long com, caddr_t data, int flag)
{
	switch (com) {
	case TIOCSETP:
	case TIOCSETN:
	case TIOCSETC:
	case TIOCSLTC:
	case TIOCLBIS:
	case TIOCLBIC:
	case TIOCLSET: {
		struct termios term;
		int error;

		term = tp->t_termios;
		if ((error = ttsetcompat(tp, &com, data, &term)) != 0)
			return error;
		return ttioctl(tp, com, &term, flag);
	}
	case TIOCGETP: {
		struct sgttyb *sg = (struct sgttyb *)data;
		cc_t *cc = tp->t_cc;

		sg->sg_ospeed = ttcompatspeedtab(tp->t_ospeed, compatspeeds);
		if (tp->t_ispeed == 0)
			sg->sg_ispeed = sg->sg_ospeed;
		else
			sg->sg_ispeed = ttcompatspeedtab(tp->t_ispeed, compatspeeds);
		sg->sg_erase = cc[VERASE];
		sg->sg_kill = cc[VKILL];
		sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);
		break;
	}
	case TIOCGETC: {
		struct tchars *tc = (struct tchars *)data;
		cc_t *cc = tp->t_cc;

		tc->t_intrc = cc[VINTR];
		tc->t_quitc = cc[VQUIT];
		tc->t_startc = cc[VSTART];
		tc->t_stopc = cc[VSTOP];
		tc->t_eofc = cc[VEOF];
		tc->t_brkc = cc[VEOL];
		break;
	}
	case TIOCGLTC: {
		struct ltchars *ltc = (struct ltchars *)data;
		cc_t *cc = tp->t_cc;

		ltc->t_suspc = cc[VSUSP];
		ltc->t_dsuspc = cc[VDSUSP];
		ltc->t_rprntc = cc[VREPRINT];
		ltc->t_flushc = cc[VDISCARD];
		ltc->t_werasc = cc[VWERASE];
		ltc->t_lnextc = cc[VLNEXT];
		break;
	}
	case TIOCLGET:
		tp->t_flags =
		 (ttcompatgetflags(tp) & 0xffff0000UL)
		   | (tp->t_flags & 0xffff);
		*(int *)data = tp->t_flags>>16;
		if (ttydebug)
			kprintf("CLGET: returning %x\n", *(int *)data);
		break;

	case OTIOCGETD:
		*(int *)data = tp->t_line ? tp->t_line : 2;
		break;

	case OTIOCSETD: {
		int ldisczero = 0;

		return (ttioctl(tp, TIOCSETD,
			*(int *)data == 2 ? (caddr_t)&ldisczero : data, flag));
	    }

	case OTIOCCONS:
		*(int *)data = 1;
		return (ttioctl(tp, TIOCCONS, data, flag));

	default:
		return (ENOIOCTL);
	}
	return (0);
}