/* Perform I/O control on an active RIN channel. */ static int rin_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct rin_st *sl = tty->disc_data; unsigned int tmp; // int __user *p = (int __user *)arg; /* First make sure we're connected. */ if (!sl || sl->magic != RIN_MAGIC) return -EINVAL; switch (cmd) { case SIOCGIFNAME: tmp = strlen(sl->dev->name) + 1; if (copy_to_user((void __user *)arg, sl->dev->name, tmp)) return -EFAULT; return 0; case SIOCSIFHWADDR: return -EINVAL; default: return tty_mode_ioctl(tty, file, cmd, arg); } }
/* Perform I/O control on an active SLCAN channel. */ static int slcan_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct slcan *sl = (struct slcan *) tty->disc_data; unsigned int tmp; /* First make sure we're connected. */ if (!sl || sl->magic != SLCAN_MAGIC) return -EINVAL; switch (cmd) { case SIOCGIFNAME: tmp = strlen(sl->dev->name) + 1; if (copy_to_user((void __user *)arg, sl->dev->name, tmp)) return -EFAULT; return 0; case SIOCSIFHWADDR: return -EINVAL; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) /* Allow stty to read, but not set, the serial port */ case TCGETS: case TCGETA: return n_tty_ioctl(tty, file, cmd, arg); default: return -ENOIOCTLCMD; #else default: return tty_mode_ioctl(tty, file, cmd, arg); #endif } }
/* Perform I/O control on an active X.25 channel. */ static int x25_asy_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct x25_asy *sl = tty->disc_data; /* First make sure we're connected. */ if (!sl || sl->magic != X25_ASY_MAGIC) return -EINVAL; switch (cmd) { case SIOCGIFNAME: if (copy_to_user((void __user *)arg, sl->dev->name, strlen(sl->dev->name) + 1)) return -EFAULT; return 0; case SIOCSIFHWADDR: return -EINVAL; default: return tty_mode_ioctl(tty, file, cmd, arg); } }
static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file, unsigned int cmd, unsigned long arg) { struct ipw_tty *tty = linux_tty->driver_data; if (!tty) return -ENODEV; if (!atomic_read(&tty->open_count)) return -EINVAL; /* FIXME: Exactly how is the tty object locked here .. */ switch (cmd) { case TIOCGSERIAL: return ipwireless_get_serial_info(tty, (void __user *) arg); case TIOCSSERIAL: return 0; /* Keeps the PCMCIA scripts happy. */ } if (tty->tty_type == TTYTYPE_MODEM) { switch (cmd) { case PPPIOCGCHAN: { int chan = ipwireless_ppp_channel_index( tty->network); if (chan < 0) return -ENODEV; if (put_user(chan, (int __user *) arg)) return -EFAULT; } return 0; case PPPIOCGUNIT: { int unit = ipwireless_ppp_unit_number( tty->network); if (unit < 0) return -ENODEV; if (put_user(unit, (int __user *) arg)) return -EFAULT; } return 0; case FIONREAD: { int val = 0; if (put_user(val, (int __user *) arg)) return -EFAULT; } return 0; case TCFLSH: return tty_perform_flush(linux_tty, arg); } } return tty_mode_ioctl(linux_tty, file, cmd , arg); }
static int ev3_uart_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { return tty_mode_ioctl(tty, file, cmd, arg); }
static int send_prio_char(struct tty_struct *tty, char ch) { int was_stopped = tty->stopped; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) if (tty->ops->send_xchar) { tty->ops->send_xchar(tty, ch); #else if (tty->driver->send_xchar) { tty->driver->send_xchar(tty, ch); #endif return 0; } if (tty_write_lock(tty, 0) < 0) return -ERESTARTSYS; if (was_stopped) start_tty(tty); #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) tty->ops->write(tty, &ch, 1); #else tty->driver->write(tty, &ch, 1); #endif if (was_stopped) stop_tty(tty); tty_write_unlock(tty); return 0; } int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) unsigned long flags; #endif int retval; switch (cmd) { case TCXONC: retval = tty_check_change(tty); if (retval) return retval; switch (arg) { case TCOOFF: if (!tty->flow_stopped) { tty->flow_stopped = 1; stop_tty(tty); } break; case TCOON: if (tty->flow_stopped) { tty->flow_stopped = 0; start_tty(tty); } break; case TCIOFF: if (STOP_CHAR(tty) != __DISABLED_CHAR) return send_prio_char(tty, STOP_CHAR(tty)); break; case TCION: if (START_CHAR(tty) != __DISABLED_CHAR) return send_prio_char(tty, START_CHAR(tty)); break; default: return -EINVAL; } return 0; case TCFLSH: return tty_perform_flush(tty, arg); case TIOCPKT: { int pktmode; if (tty->driver->type != TTY_DRIVER_TYPE_PTY || tty->driver->subtype != PTY_TYPE_MASTER) return -ENOTTY; if (get_user(pktmode, (int __user *) arg)) return -EFAULT; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) spin_lock_irqsave(&tty->ctrl_lock, flags); #endif if (pktmode) { if (!tty->packet) { tty->packet = 1; tty->link->ctrl_status = 0; } } else tty->packet = 0; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) spin_unlock_irqrestore(&tty->ctrl_lock, flags); #endif return 0; } default: /* Try the mode commands */ return tty_mode_ioctl(tty, file, cmd, arg); } }