Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Filename: ircomm_tty_ioctl.c |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 4 | * Version: |
| 5 | * Description: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Status: Experimental. |
| 7 | * Author: Dag Brattli <dagb@cs.uit.no> |
| 8 | * Created at: Thu Jun 10 14:39:09 1999 |
| 9 | * Modified at: Wed Jan 5 14:45:43 2000 |
| 10 | * Modified by: Dag Brattli <dagb@cs.uit.no> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * the License, or (at your option) any later version. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
Jeff Kirsher | d377050 | 2013-12-06 09:13:43 -0800 | [diff] [blame] | 25 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 26 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | ********************************************************************/ |
| 28 | |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/termios.h> |
| 32 | #include <linux/tty.h> |
| 33 | #include <linux/serial.h> |
| 34 | |
| 35 | #include <asm/uaccess.h> |
| 36 | |
| 37 | #include <net/irda/irda.h> |
| 38 | #include <net/irda/irmod.h> |
| 39 | |
| 40 | #include <net/irda/ircomm_core.h> |
| 41 | #include <net/irda/ircomm_param.h> |
| 42 | #include <net/irda/ircomm_tty_attach.h> |
| 43 | #include <net/irda/ircomm_tty.h> |
| 44 | |
| 45 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
| 46 | |
| 47 | /* |
| 48 | * Function ircomm_tty_change_speed (driver) |
| 49 | * |
| 50 | * Change speed of the driver. If the remote device is a DCE, then this |
| 51 | * should make it change the speed of its serial port |
| 52 | */ |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 53 | static void ircomm_tty_change_speed(struct ircomm_tty_cb *self, |
| 54 | struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 56 | unsigned int cflag, cval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | int baud; |
| 58 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 59 | if (!self->ircomm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | return; |
| 61 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 62 | cflag = tty->termios.c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | /* byte size and parity */ |
| 65 | switch (cflag & CSIZE) { |
| 66 | case CS5: cval = IRCOMM_WSIZE_5; break; |
| 67 | case CS6: cval = IRCOMM_WSIZE_6; break; |
| 68 | case CS7: cval = IRCOMM_WSIZE_7; break; |
| 69 | case CS8: cval = IRCOMM_WSIZE_8; break; |
| 70 | default: cval = IRCOMM_WSIZE_5; break; |
| 71 | } |
| 72 | if (cflag & CSTOPB) |
| 73 | cval |= IRCOMM_2_STOP_BIT; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (cflag & PARENB) |
| 76 | cval |= IRCOMM_PARITY_ENABLE; |
| 77 | if (!(cflag & PARODD)) |
| 78 | cval |= IRCOMM_PARITY_EVEN; |
| 79 | |
| 80 | /* Determine divisor based on baud rate */ |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 81 | baud = tty_get_baud_rate(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (!baud) |
| 83 | baud = 9600; /* B0 transition handled in rs_set_termios */ |
| 84 | |
| 85 | self->settings.data_rate = baud; |
| 86 | ircomm_param_request(self, IRCOMM_DATA_RATE, FALSE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* CTS flow control flag and modem status interrupts */ |
| 89 | if (cflag & CRTSCTS) { |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 90 | self->port.flags |= ASYNC_CTS_FLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | self->settings.flow_control |= IRCOMM_RTS_CTS_IN; |
| 92 | /* This got me. Bummer. Jean II */ |
| 93 | if (self->service_type == IRCOMM_3_WIRE_RAW) |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 94 | net_warn_ratelimited("%s(), enabling RTS/CTS on link that doesn't support it (3-wire-raw)\n", |
| 95 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } else { |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 97 | self->port.flags &= ~ASYNC_CTS_FLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | self->settings.flow_control &= ~IRCOMM_RTS_CTS_IN; |
| 99 | } |
| 100 | if (cflag & CLOCAL) |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 101 | self->port.flags &= ~ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | else |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 103 | self->port.flags |= ASYNC_CHECK_CD; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 104 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /* |
| 106 | * Set up parity check flag |
| 107 | */ |
| 108 | |
| 109 | if (I_INPCK(self->tty)) |
| 110 | driver->read_status_mask |= LSR_FE | LSR_PE; |
| 111 | if (I_BRKINT(driver->tty) || I_PARMRK(driver->tty)) |
| 112 | driver->read_status_mask |= LSR_BI; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* |
| 115 | * Characters to ignore |
| 116 | */ |
| 117 | driver->ignore_status_mask = 0; |
| 118 | if (I_IGNPAR(driver->tty)) |
| 119 | driver->ignore_status_mask |= LSR_PE | LSR_FE; |
| 120 | |
| 121 | if (I_IGNBRK(self->tty)) { |
| 122 | self->ignore_status_mask |= LSR_BI; |
| 123 | /* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 124 | * If we're ignore parity and break indicators, ignore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | * overruns too. (For real raw support). |
| 126 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 127 | if (I_IGNPAR(self->tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | self->ignore_status_mask |= LSR_OE; |
| 129 | } |
| 130 | #endif |
| 131 | self->settings.data_format = cval; |
| 132 | |
| 133 | ircomm_param_request(self, IRCOMM_DATA_FORMAT, FALSE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 134 | ircomm_param_request(self, IRCOMM_FLOW_CONTROL, TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Function ircomm_tty_set_termios (tty, old_termios) |
| 139 | * |
| 140 | * This routine allows the tty driver to be notified when device's |
| 141 | * termios settings have changed. Note that a well-designed tty driver |
| 142 | * should be prepared to accept the case where old == NULL, and try to |
| 143 | * do something rational. |
| 144 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 145 | void ircomm_tty_set_termios(struct tty_struct *tty, |
Alan Cox | edc6afc | 2006-12-08 02:38:44 -0800 | [diff] [blame] | 146 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 149 | unsigned int cflag = tty->termios.c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 151 | if ((cflag == old_termios->c_cflag) && |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 152 | (RELEVANT_IFLAG(tty->termios.c_iflag) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | RELEVANT_IFLAG(old_termios->c_iflag))) |
| 154 | { |
| 155 | return; |
| 156 | } |
| 157 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 158 | ircomm_tty_change_speed(self, tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /* Handle transition to B0 status */ |
| 161 | if ((old_termios->c_cflag & CBAUD) && |
| 162 | !(cflag & CBAUD)) { |
| 163 | self->settings.dte &= ~(IRCOMM_DTR|IRCOMM_RTS); |
| 164 | ircomm_param_request(self, IRCOMM_DTE, TRUE); |
| 165 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Handle transition away from B0 status */ |
| 168 | if (!(old_termios->c_cflag & CBAUD) && |
| 169 | (cflag & CBAUD)) { |
| 170 | self->settings.dte |= IRCOMM_DTR; |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 171 | if (!(tty->termios.c_cflag & CRTSCTS) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | !test_bit(TTY_THROTTLED, &tty->flags)) { |
| 173 | self->settings.dte |= IRCOMM_RTS; |
| 174 | } |
| 175 | ircomm_param_request(self, IRCOMM_DTE, TRUE); |
| 176 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* Handle turning off CRTSCTS */ |
| 179 | if ((old_termios->c_cflag & CRTSCTS) && |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 180 | !(tty->termios.c_cflag & CRTSCTS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
| 182 | tty->hw_stopped = 0; |
| 183 | ircomm_tty_start(tty); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 188 | * Function ircomm_tty_tiocmget (tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 190 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | * |
| 192 | */ |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 193 | int ircomm_tty_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; |
| 196 | unsigned int result; |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 199 | return -EIO; |
| 200 | |
| 201 | result = ((self->settings.dte & IRCOMM_RTS) ? TIOCM_RTS : 0) |
| 202 | | ((self->settings.dte & IRCOMM_DTR) ? TIOCM_DTR : 0) |
| 203 | | ((self->settings.dce & IRCOMM_CD) ? TIOCM_CAR : 0) |
| 204 | | ((self->settings.dce & IRCOMM_RI) ? TIOCM_RNG : 0) |
| 205 | | ((self->settings.dce & IRCOMM_DSR) ? TIOCM_DSR : 0) |
| 206 | | ((self->settings.dce & IRCOMM_CTS) ? TIOCM_CTS : 0); |
| 207 | return result; |
| 208 | } |
| 209 | |
| 210 | /* |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 211 | * Function ircomm_tty_tiocmset (tty, set, clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 213 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * |
| 215 | */ |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 216 | int ircomm_tty_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | unsigned int set, unsigned int clear) |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 218 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 222 | return -EIO; |
| 223 | |
| 224 | IRDA_ASSERT(self != NULL, return -1;); |
| 225 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 226 | |
| 227 | if (set & TIOCM_RTS) |
| 228 | self->settings.dte |= IRCOMM_RTS; |
| 229 | if (set & TIOCM_DTR) |
| 230 | self->settings.dte |= IRCOMM_DTR; |
| 231 | |
| 232 | if (clear & TIOCM_RTS) |
| 233 | self->settings.dte &= ~IRCOMM_RTS; |
| 234 | if (clear & TIOCM_DTR) |
| 235 | self->settings.dte &= ~IRCOMM_DTR; |
| 236 | |
| 237 | if ((set|clear) & TIOCM_RTS) |
| 238 | self->settings.dte |= IRCOMM_DELTA_RTS; |
| 239 | if ((set|clear) & TIOCM_DTR) |
| 240 | self->settings.dte |= IRCOMM_DELTA_DTR; |
| 241 | |
| 242 | ircomm_param_request(self, IRCOMM_DTE, TRUE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Function get_serial_info (driver, retinfo) |
| 249 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 250 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | * |
| 252 | */ |
| 253 | static int ircomm_tty_get_serial_info(struct ircomm_tty_cb *self, |
| 254 | struct serial_struct __user *retinfo) |
| 255 | { |
| 256 | struct serial_struct info; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (!retinfo) |
| 259 | return -EFAULT; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | memset(&info, 0, sizeof(info)); |
| 262 | info.line = self->line; |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 263 | info.flags = self->port.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | info.baud_base = self->settings.data_rate; |
Jiri Slaby | 2a0213c | 2012-06-04 13:35:17 +0200 | [diff] [blame] | 265 | info.close_delay = self->port.close_delay; |
| 266 | info.closing_wait = self->port.closing_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | /* For compatibility */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 269 | info.type = PORT_16550A; |
| 270 | info.port = 0; |
| 271 | info.irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | info.xmit_fifo_size = 0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 273 | info.hub6 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | info.custom_divisor = 0; |
| 275 | |
| 276 | if (copy_to_user(retinfo, &info, sizeof(*retinfo))) |
| 277 | return -EFAULT; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * Function set_serial_info (driver, new_info) |
| 284 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 285 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | * |
| 287 | */ |
| 288 | static int ircomm_tty_set_serial_info(struct ircomm_tty_cb *self, |
| 289 | struct serial_struct __user *new_info) |
| 290 | { |
| 291 | #if 0 |
| 292 | struct serial_struct new_serial; |
| 293 | struct ircomm_tty_cb old_state, *state; |
| 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) |
| 296 | return -EFAULT; |
| 297 | |
| 298 | |
| 299 | state = self |
| 300 | old_state = *self; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (!capable(CAP_SYS_ADMIN)) { |
| 303 | if ((new_serial.baud_base != state->settings.data_rate) || |
| 304 | (new_serial.close_delay != state->close_delay) || |
| 305 | ((new_serial.flags & ~ASYNC_USR_MASK) != |
| 306 | (self->flags & ~ASYNC_USR_MASK))) |
| 307 | return -EPERM; |
| 308 | state->flags = ((state->flags & ~ASYNC_USR_MASK) | |
| 309 | (new_serial.flags & ASYNC_USR_MASK)); |
| 310 | self->flags = ((self->flags & ~ASYNC_USR_MASK) | |
| 311 | (new_serial.flags & ASYNC_USR_MASK)); |
| 312 | /* self->custom_divisor = new_serial.custom_divisor; */ |
| 313 | goto check_and_exit; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * OK, past this point, all the error checking has been done. |
| 318 | * At this point, we start making changes..... |
| 319 | */ |
| 320 | |
| 321 | if (self->settings.data_rate != new_serial.baud_base) { |
| 322 | self->settings.data_rate = new_serial.baud_base; |
| 323 | ircomm_param_request(self, IRCOMM_DATA_RATE, TRUE); |
| 324 | } |
| 325 | |
| 326 | self->close_delay = new_serial.close_delay * HZ/100; |
| 327 | self->closing_wait = new_serial.closing_wait * HZ/100; |
| 328 | /* self->custom_divisor = new_serial.custom_divisor; */ |
| 329 | |
| 330 | self->flags = ((self->flags & ~ASYNC_FLAGS) | |
| 331 | (new_serial.flags & ASYNC_FLAGS)); |
| 332 | self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
| 333 | |
| 334 | check_and_exit: |
| 335 | |
| 336 | if (self->flags & ASYNC_INITIALIZED) { |
| 337 | if (((old_state.flags & ASYNC_SPD_MASK) != |
| 338 | (self->flags & ASYNC_SPD_MASK)) || |
| 339 | (old_driver.custom_divisor != driver->custom_divisor)) { |
| 340 | if ((driver->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
| 341 | driver->tty->alt_speed = 57600; |
| 342 | if ((driver->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
| 343 | driver->tty->alt_speed = 115200; |
| 344 | if ((driver->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) |
| 345 | driver->tty->alt_speed = 230400; |
| 346 | if ((driver->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) |
| 347 | driver->tty->alt_speed = 460800; |
| 348 | ircomm_tty_change_speed(driver); |
| 349 | } |
| 350 | } |
| 351 | #endif |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | /* |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 356 | * Function ircomm_tty_ioctl (tty, cmd, arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 358 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | * |
| 360 | */ |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 361 | int ircomm_tty_ioctl(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | unsigned int cmd, unsigned long arg) |
| 363 | { |
| 364 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; |
| 365 | int ret = 0; |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && |
| 368 | (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) && |
| 369 | (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { |
| 370 | if (tty->flags & (1 << TTY_IO_ERROR)) |
| 371 | return -EIO; |
| 372 | } |
| 373 | |
| 374 | switch (cmd) { |
| 375 | case TIOCGSERIAL: |
| 376 | ret = ircomm_tty_get_serial_info(self, (struct serial_struct __user *) arg); |
| 377 | break; |
| 378 | case TIOCSSERIAL: |
| 379 | ret = ircomm_tty_set_serial_info(self, (struct serial_struct __user *) arg); |
| 380 | break; |
| 381 | case TIOCMIWAIT: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 382 | pr_debug("(), TIOCMIWAIT, not impl!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
| 384 | |
| 385 | case TIOCGICOUNT: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 386 | pr_debug("%s(), TIOCGICOUNT not impl!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | #if 0 |
| 388 | save_flags(flags); cli(); |
| 389 | cnow = driver->icount; |
| 390 | restore_flags(flags); |
| 391 | p_cuser = (struct serial_icounter_struct __user *) arg; |
| 392 | if (put_user(cnow.cts, &p_cuser->cts) || |
| 393 | put_user(cnow.dsr, &p_cuser->dsr) || |
| 394 | put_user(cnow.rng, &p_cuser->rng) || |
| 395 | put_user(cnow.dcd, &p_cuser->dcd) || |
| 396 | put_user(cnow.rx, &p_cuser->rx) || |
| 397 | put_user(cnow.tx, &p_cuser->tx) || |
| 398 | put_user(cnow.frame, &p_cuser->frame) || |
| 399 | put_user(cnow.overrun, &p_cuser->overrun) || |
| 400 | put_user(cnow.parity, &p_cuser->parity) || |
| 401 | put_user(cnow.brk, &p_cuser->brk) || |
| 402 | put_user(cnow.buf_overrun, &p_cuser->buf_overrun)) |
| 403 | return -EFAULT; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 404 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | return 0; |
| 406 | default: |
| 407 | ret = -ENOIOCTLCMD; /* ioctls which we must ignore */ |
| 408 | } |
| 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | |