Commit 5f8d18dd4b555d34ce86936240c94d4c19b2e71a
Committed by
GitHub
Merge pull request #18 from ReallyNiceGuy/master
Format code according to Linux rules
Showing
1 changed file
with
257 additions
and
277 deletions
module/tty0tty.c
| ... | ... | @@ -25,8 +25,6 @@ |
| 25 | 25 | For e-mail suggestions : lcgamboa@yahoo.com |
| 26 | 26 | ######################################################################## */ |
| 27 | 27 | |
| 28 | - | |
| 29 | - | |
| 30 | 28 | #include <linux/kernel.h> |
| 31 | 29 | #include <linux/errno.h> |
| 32 | 30 | #include <linux/init.h> |
| ... | ... | @@ -44,19 +42,19 @@ |
| 44 | 42 | #endif |
| 45 | 43 | #include <asm/uaccess.h> |
| 46 | 44 | |
| 47 | - | |
| 48 | 45 | #define DRIVER_VERSION "v1.2" |
| 49 | 46 | #define DRIVER_AUTHOR "Luis Claudio Gamboa Lopes <lcgamboa@yahoo.com>" |
| 50 | 47 | #define DRIVER_DESC "tty0tty null modem driver" |
| 51 | 48 | |
| 52 | 49 | /* Module information */ |
| 53 | -MODULE_AUTHOR( DRIVER_AUTHOR ); | |
| 54 | -MODULE_DESCRIPTION( DRIVER_DESC ); | |
| 50 | +MODULE_AUTHOR(DRIVER_AUTHOR); | |
| 51 | +MODULE_DESCRIPTION(DRIVER_DESC); | |
| 55 | 52 | MODULE_LICENSE("GPL"); |
| 56 | 53 | |
| 57 | -short pairs = 4; //Default number of pairs of devices | |
| 54 | +short pairs = 4; //Default number of pairs of devices | |
| 58 | 55 | module_param(pairs, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); |
| 59 | -MODULE_PARM_DESC(pairs, "Number of pairs of devices to be created, maximum of 128"); | |
| 56 | +MODULE_PARM_DESC(pairs, | |
| 57 | + "Number of pairs of devices to be created, maximum of 128"); | |
| 60 | 58 | |
| 61 | 59 | #if 0 |
| 62 | 60 | #define TTY0TTY_MAJOR 240 /* experimental range */ |
| ... | ... | @@ -76,40 +74,38 @@ MODULE_PARM_DESC(pairs, "Number of pairs of devices to be created, maximum of 12 |
| 76 | 74 | #define MSR_CD 0x20 |
| 77 | 75 | #define MSR_DSR 0x40 |
| 78 | 76 | #define MSR_RI 0x80 |
| 79 | - | |
| 80 | 77 | |
| 81 | 78 | static struct tty_port *tport; |
| 82 | 79 | |
| 83 | 80 | struct tty0tty_serial { |
| 84 | - struct tty_struct *tty; /* pointer to the tty for this device */ | |
| 85 | - int open_count; /* number of times this port has been opened */ | |
| 86 | - struct semaphore sem; /* locks this structure */ | |
| 81 | + struct tty_struct *tty; /* pointer to the tty for this device */ | |
| 82 | + int open_count; /* number of times this port has been opened */ | |
| 83 | + struct semaphore sem; /* locks this structure */ | |
| 87 | 84 | |
| 88 | 85 | /* for tiocmget and tiocmset functions */ |
| 89 | - int msr; /* MSR shadow */ | |
| 90 | - int mcr; /* MCR shadow */ | |
| 86 | + int msr; /* MSR shadow */ | |
| 87 | + int mcr; /* MCR shadow */ | |
| 91 | 88 | |
| 92 | 89 | /* for ioctl fun */ |
| 93 | - struct serial_struct serial; | |
| 94 | - wait_queue_head_t wait; | |
| 95 | - struct async_icount icount; | |
| 96 | - | |
| 90 | + struct serial_struct serial; | |
| 91 | + wait_queue_head_t wait; | |
| 92 | + struct async_icount icount; | |
| 93 | + | |
| 97 | 94 | }; |
| 98 | 95 | |
| 99 | 96 | static struct tty0tty_serial **tty0tty_table; /* initially all NULL */ |
| 100 | 97 | |
| 101 | - | |
| 102 | 98 | static int tty0tty_open(struct tty_struct *tty, struct file *file) |
| 103 | 99 | { |
| 104 | 100 | struct tty0tty_serial *tty0tty; |
| 105 | - int index; | |
| 106 | - int msr=0; | |
| 107 | - int mcr=0; | |
| 101 | + int index; | |
| 102 | + int msr = 0; | |
| 103 | + int mcr = 0; | |
| 108 | 104 | |
| 109 | 105 | #ifdef SCULL_DEBUG |
| 110 | 106 | printk(KERN_DEBUG "%s - \n", __FUNCTION__); |
| 111 | -#endif | |
| 112 | - /* initialize the pointer in case something fails */ | |
| 107 | +#endif | |
| 108 | + /* initialize the pointer in case something fails */ | |
| 113 | 109 | tty->driver_data = NULL; |
| 114 | 110 | |
| 115 | 111 | /* get the serial object associated with this tty pointer */ |
| ... | ... | @@ -121,48 +117,42 @@ static int tty0tty_open(struct tty_struct *tty, struct file *file) |
| 121 | 117 | if (!tty0tty) |
| 122 | 118 | return -ENOMEM; |
| 123 | 119 | |
| 124 | - sema_init(&tty0tty->sem,1); | |
| 120 | + sema_init(&tty0tty->sem, 1); | |
| 125 | 121 | tty0tty->open_count = 0; |
| 126 | 122 | |
| 127 | 123 | tty0tty_table[index] = tty0tty; |
| 128 | - | |
| 129 | - } | |
| 130 | - | |
| 131 | - tport[index].tty=tty; | |
| 132 | - tty->port = &tport[index]; | |
| 133 | - | |
| 134 | - if( (index % 2) == 0) | |
| 135 | - { | |
| 136 | - if(tty0tty_table[index+1] != NULL) | |
| 137 | - if (tty0tty_table[index+1]->open_count > 0) | |
| 138 | - mcr=tty0tty_table[index+1]->mcr; | |
| 139 | - } | |
| 140 | - else | |
| 141 | - { | |
| 142 | - if(tty0tty_table[index-1] != NULL) | |
| 143 | - if (tty0tty_table[index-1]->open_count > 0) | |
| 144 | - mcr=tty0tty_table[index-1]->mcr; | |
| 145 | - } | |
| 146 | - | |
| 124 | + | |
| 125 | + } | |
| 126 | + | |
| 127 | + tport[index].tty = tty; | |
| 128 | + tty->port = &tport[index]; | |
| 129 | + | |
| 130 | + if ((index % 2) == 0) { | |
| 131 | + if (tty0tty_table[index + 1] != NULL) | |
| 132 | + if (tty0tty_table[index + 1]->open_count > 0) | |
| 133 | + mcr = tty0tty_table[index + 1]->mcr; | |
| 134 | + } else { | |
| 135 | + if (tty0tty_table[index - 1] != NULL) | |
| 136 | + if (tty0tty_table[index - 1]->open_count > 0) | |
| 137 | + mcr = tty0tty_table[index - 1]->mcr; | |
| 138 | + } | |
| 139 | + | |
| 147 | 140 | //null modem connection |
| 148 | 141 | |
| 149 | - if( (mcr & MCR_RTS) == MCR_RTS ) | |
| 150 | - { | |
| 151 | - msr |= MSR_CTS; | |
| 152 | - } | |
| 153 | - | |
| 154 | - if( (mcr & MCR_DTR) == MCR_DTR ) | |
| 155 | - { | |
| 156 | - msr |= MSR_DSR; | |
| 157 | - msr |= MSR_CD; | |
| 158 | - } | |
| 159 | - | |
| 142 | + if ((mcr & MCR_RTS) == MCR_RTS) { | |
| 143 | + msr |= MSR_CTS; | |
| 144 | + } | |
| 145 | + | |
| 146 | + if ((mcr & MCR_DTR) == MCR_DTR) { | |
| 147 | + msr |= MSR_DSR; | |
| 148 | + msr |= MSR_CD; | |
| 149 | + } | |
| 150 | + | |
| 160 | 151 | tty0tty->msr = msr; |
| 161 | 152 | tty0tty->mcr = 0; |
| 162 | - | |
| 163 | 153 | |
| 164 | 154 | /* register the tty driver */ |
| 165 | - | |
| 155 | + | |
| 166 | 156 | down(&tty0tty->sem); |
| 167 | 157 | |
| 168 | 158 | /* save our structure within the tty structure */ |
| ... | ... | @@ -176,25 +166,26 @@ static int tty0tty_open(struct tty_struct *tty, struct file *file) |
| 176 | 166 | } |
| 177 | 167 | |
| 178 | 168 | static void do_close(struct tty0tty_serial *tty0tty) |
| 179 | -{ | |
| 180 | - unsigned int msr=0; | |
| 181 | - | |
| 169 | +{ | |
| 170 | + unsigned int msr = 0; | |
| 171 | + | |
| 182 | 172 | #ifdef SCULL_DEBUG |
| 183 | 173 | printk(KERN_DEBUG "%s - \n", __FUNCTION__); |
| 184 | 174 | #endif |
| 185 | - if( (tty0tty->tty->index % 2) == 0) | |
| 186 | - { | |
| 187 | - if(tty0tty_table[tty0tty->tty->index+1] != NULL) | |
| 188 | - if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | |
| 189 | - tty0tty_table[tty0tty->tty->index+1]->msr=msr; | |
| 190 | - } | |
| 191 | - else | |
| 192 | - { | |
| 193 | - if(tty0tty_table[tty0tty->tty->index-1] != NULL) | |
| 194 | - if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | |
| 195 | - tty0tty_table[tty0tty->tty->index-1]->msr=msr; | |
| 196 | - } | |
| 197 | - | |
| 175 | + if ((tty0tty->tty->index % 2) == 0) { | |
| 176 | + if (tty0tty_table[tty0tty->tty->index + 1] != NULL) | |
| 177 | + if (tty0tty_table[tty0tty->tty->index + 1]->open_count > | |
| 178 | + 0) | |
| 179 | + tty0tty_table[tty0tty->tty->index + 1]->msr = | |
| 180 | + msr; | |
| 181 | + } else { | |
| 182 | + if (tty0tty_table[tty0tty->tty->index - 1] != NULL) | |
| 183 | + if (tty0tty_table[tty0tty->tty->index - 1]->open_count > | |
| 184 | + 0) | |
| 185 | + tty0tty_table[tty0tty->tty->index - 1]->msr = | |
| 186 | + msr; | |
| 187 | + } | |
| 188 | + | |
| 198 | 189 | down(&tty0tty->sem); |
| 199 | 190 | if (!tty0tty->open_count) { |
| 200 | 191 | /* port was never opened */ |
| ... | ... | @@ -204,29 +195,29 @@ static void do_close(struct tty0tty_serial *tty0tty) |
| 204 | 195 | --tty0tty->open_count; |
| 205 | 196 | exit: |
| 206 | 197 | up(&tty0tty->sem); |
| 207 | - | |
| 208 | - | |
| 209 | - return; | |
| 198 | + | |
| 199 | + return; | |
| 210 | 200 | } |
| 211 | 201 | |
| 212 | 202 | static void tty0tty_close(struct tty_struct *tty, struct file *file) |
| 213 | 203 | { |
| 214 | 204 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 215 | - | |
| 205 | + | |
| 216 | 206 | #ifdef SCULL_DEBUG |
| 217 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 207 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 218 | 208 | #endif |
| 219 | 209 | if (tty0tty) |
| 220 | 210 | do_close(tty0tty); |
| 221 | -} | |
| 211 | +} | |
| 222 | 212 | |
| 223 | -static int tty0tty_write(struct tty_struct *tty, const unsigned char *buffer, int count) | |
| 213 | +static int tty0tty_write(struct tty_struct *tty, const unsigned char *buffer, | |
| 214 | + int count) | |
| 224 | 215 | { |
| 225 | 216 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 226 | 217 | int retval = -EINVAL; |
| 227 | - struct tty_struct *ttyx = NULL; | |
| 218 | + struct tty_struct *ttyx = NULL; | |
| 228 | 219 | |
| 229 | - if (!tty0tty) | |
| 220 | + if (!tty0tty) | |
| 230 | 221 | return -ENODEV; |
| 231 | 222 | |
| 232 | 223 | down(&tty0tty->sem); |
| ... | ... | @@ -235,48 +226,48 @@ static int tty0tty_write(struct tty_struct *tty, const unsigned char *buffer, in |
| 235 | 226 | /* port was not opened */ |
| 236 | 227 | goto exit; |
| 237 | 228 | |
| 238 | - if( (tty0tty->tty->index % 2) == 0) | |
| 239 | - { | |
| 240 | - if(tty0tty_table[tty0tty->tty->index+1] != NULL) | |
| 241 | - if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | |
| 242 | - ttyx=tty0tty_table[tty0tty->tty->index+1]->tty; | |
| 243 | - } | |
| 244 | - else | |
| 245 | - { | |
| 246 | - if(tty0tty_table[tty0tty->tty->index-1] != NULL) | |
| 247 | - if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | |
| 248 | - ttyx=tty0tty_table[tty0tty->tty->index-1]->tty; | |
| 249 | - } | |
| 229 | + if ((tty0tty->tty->index % 2) == 0) { | |
| 230 | + if (tty0tty_table[tty0tty->tty->index + 1] != NULL) | |
| 231 | + if (tty0tty_table[tty0tty->tty->index + 1]->open_count > | |
| 232 | + 0) | |
| 233 | + ttyx = | |
| 234 | + tty0tty_table[tty0tty->tty->index + 1]->tty; | |
| 235 | + } else { | |
| 236 | + if (tty0tty_table[tty0tty->tty->index - 1] != NULL) | |
| 237 | + if (tty0tty_table[tty0tty->tty->index - 1]->open_count > | |
| 238 | + 0) | |
| 239 | + ttyx = | |
| 240 | + tty0tty_table[tty0tty->tty->index - 1]->tty; | |
| 241 | + } | |
| 250 | 242 | |
| 251 | 243 | // tty->low_latency=1; |
| 252 | 244 | |
| 253 | - if(ttyx != NULL) | |
| 254 | - { | |
| 245 | + if (ttyx != NULL) { | |
| 255 | 246 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0) |
| 256 | - tty_insert_flip_string(ttyx->port, buffer, count); | |
| 257 | - tty_flip_buffer_push(ttyx->port); | |
| 247 | + tty_insert_flip_string(ttyx->port, buffer, count); | |
| 248 | + tty_flip_buffer_push(ttyx->port); | |
| 258 | 249 | #else |
| 259 | - tty_insert_flip_string(ttyx, buffer, count); | |
| 260 | - tty_flip_buffer_push(ttyx); | |
| 250 | + tty_insert_flip_string(ttyx, buffer, count); | |
| 251 | + tty_flip_buffer_push(ttyx); | |
| 261 | 252 | #endif |
| 262 | - retval=count; | |
| 263 | - } | |
| 264 | - | |
| 253 | + retval = count; | |
| 254 | + } | |
| 255 | + | |
| 265 | 256 | exit: |
| 266 | 257 | up(&tty0tty->sem); |
| 267 | 258 | return retval; |
| 268 | 259 | } |
| 269 | 260 | |
| 270 | -static int tty0tty_write_room(struct tty_struct *tty) | |
| 261 | +static int tty0tty_write_room(struct tty_struct *tty) | |
| 271 | 262 | { |
| 272 | 263 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 273 | 264 | int room = -EINVAL; |
| 274 | - | |
| 265 | + | |
| 275 | 266 | if (!tty0tty) |
| 276 | 267 | return -ENODEV; |
| 277 | 268 | |
| 278 | 269 | down(&tty0tty->sem); |
| 279 | - | |
| 270 | + | |
| 280 | 271 | if (!tty0tty->open_count) { |
| 281 | 272 | /* port was not opened */ |
| 282 | 273 | goto exit; |
| ... | ... | @@ -290,17 +281,16 @@ exit: |
| 290 | 281 | return room; |
| 291 | 282 | } |
| 292 | 283 | |
| 293 | - | |
| 294 | - | |
| 295 | 284 | #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
| 296 | 285 | |
| 297 | -static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) | |
| 286 | +static void tty0tty_set_termios(struct tty_struct *tty, | |
| 287 | + struct ktermios *old_termios) | |
| 298 | 288 | { |
| 299 | 289 | unsigned int cflag; |
| 300 | 290 | unsigned int iflag; |
| 301 | - | |
| 291 | + | |
| 302 | 292 | #ifdef SCULL_DEBUG |
| 303 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 293 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 304 | 294 | #endif |
| 305 | 295 | |
| 306 | 296 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) |
| ... | ... | @@ -314,7 +304,7 @@ static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_ter |
| 314 | 304 | /* check that they really want us to change something */ |
| 315 | 305 | if (old_termios) { |
| 316 | 306 | if ((cflag == old_termios->c_cflag) && |
| 317 | - (RELEVANT_IFLAG(iflag) == | |
| 307 | + (RELEVANT_IFLAG(iflag) == | |
| 318 | 308 | RELEVANT_IFLAG(old_termios->c_iflag))) { |
| 319 | 309 | #ifdef SCULL_DEBUG |
| 320 | 310 | printk(KERN_DEBUG " - nothing to change...\n"); |
| ... | ... | @@ -322,25 +312,24 @@ static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_ter |
| 322 | 312 | return; |
| 323 | 313 | } |
| 324 | 314 | } |
| 325 | - | |
| 326 | 315 | #ifdef SCULL_DEBUG |
| 327 | 316 | /* get the byte size */ |
| 328 | 317 | switch (cflag & CSIZE) { |
| 329 | - case CS5: | |
| 330 | - printk(KERN_DEBUG " - data bits = 5\n"); | |
| 331 | - break; | |
| 332 | - case CS6: | |
| 333 | - printk(KERN_DEBUG " - data bits = 6\n"); | |
| 334 | - break; | |
| 335 | - case CS7: | |
| 336 | - printk(KERN_DEBUG " - data bits = 7\n"); | |
| 337 | - break; | |
| 338 | - default: | |
| 339 | - case CS8: | |
| 340 | - printk(KERN_DEBUG " - data bits = 8\n"); | |
| 341 | - break; | |
| 318 | + case CS5: | |
| 319 | + printk(KERN_DEBUG " - data bits = 5\n"); | |
| 320 | + break; | |
| 321 | + case CS6: | |
| 322 | + printk(KERN_DEBUG " - data bits = 6\n"); | |
| 323 | + break; | |
| 324 | + case CS7: | |
| 325 | + printk(KERN_DEBUG " - data bits = 7\n"); | |
| 326 | + break; | |
| 327 | + default: | |
| 328 | + case CS8: | |
| 329 | + printk(KERN_DEBUG " - data bits = 8\n"); | |
| 330 | + break; | |
| 342 | 331 | } |
| 343 | - | |
| 332 | + | |
| 344 | 333 | /* determine the parity */ |
| 345 | 334 | if (cflag & PARENB) |
| 346 | 335 | if (cflag & PARODD) |
| ... | ... | @@ -361,27 +350,29 @@ static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_ter |
| 361 | 350 | printk(KERN_DEBUG " - RTS/CTS is enabled\n"); |
| 362 | 351 | else |
| 363 | 352 | printk(KERN_DEBUG " - RTS/CTS is disabled\n"); |
| 364 | - | |
| 353 | + | |
| 365 | 354 | /* determine software flow control */ |
| 366 | 355 | /* if we are implementing XON/XOFF, set the start and |
| 367 | 356 | * stop character in the device */ |
| 368 | 357 | if (I_IXOFF(tty) || I_IXON(tty)) { |
| 369 | - unsigned char stop_char = STOP_CHAR(tty); | |
| 358 | + unsigned char stop_char = STOP_CHAR(tty); | |
| 370 | 359 | unsigned char start_char = START_CHAR(tty); |
| 371 | 360 | |
| 372 | 361 | /* if we are implementing INBOUND XON/XOFF */ |
| 373 | 362 | if (I_IXOFF(tty)) |
| 374 | 363 | printk(KERN_DEBUG " - INBOUND XON/XOFF is enabled, " |
| 375 | - "XON = %2x, XOFF = %2x\n", start_char, stop_char); | |
| 364 | + "XON = %2x, XOFF = %2x\n", start_char, | |
| 365 | + stop_char); | |
| 376 | 366 | else |
| 377 | - printk(KERN_DEBUG" - INBOUND XON/XOFF is disabled\n"); | |
| 367 | + printk(KERN_DEBUG " - INBOUND XON/XOFF is disabled\n"); | |
| 378 | 368 | |
| 379 | 369 | /* if we are implementing OUTBOUND XON/XOFF */ |
| 380 | 370 | if (I_IXON(tty)) |
| 381 | - printk(KERN_DEBUG" - OUTBOUND XON/XOFF is enabled, " | |
| 382 | - "XON = %2x, XOFF = %2x\n", start_char, stop_char); | |
| 371 | + printk(KERN_DEBUG " - OUTBOUND XON/XOFF is enabled, " | |
| 372 | + "XON = %2x, XOFF = %2x\n", start_char, | |
| 373 | + stop_char); | |
| 383 | 374 | else |
| 384 | - printk(KERN_DEBUG" - OUTBOUND XON/XOFF is disabled\n"); | |
| 375 | + printk(KERN_DEBUG " - OUTBOUND XON/XOFF is disabled\n"); | |
| 385 | 376 | } |
| 386 | 377 | |
| 387 | 378 | /* get the baud rate wanted */ |
| ... | ... | @@ -389,7 +380,6 @@ static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_ter |
| 389 | 380 | #endif |
| 390 | 381 | } |
| 391 | 382 | |
| 392 | - | |
| 393 | 383 | //static int tty0tty_tiocmget(struct tty_struct *tty, struct file *file) |
| 394 | 384 | static int tty0tty_tiocmget(struct tty_struct *tty) |
| 395 | 385 | { |
| ... | ... | @@ -398,103 +388,94 @@ static int tty0tty_tiocmget(struct tty_struct *tty) |
| 398 | 388 | unsigned int result = 0; |
| 399 | 389 | unsigned int msr = tty0tty->msr; |
| 400 | 390 | unsigned int mcr = tty0tty->mcr; |
| 401 | - | |
| 402 | 391 | |
| 403 | - result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | /* DTR is set */ | |
| 404 | - ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | /* RTS is set */ | |
| 405 | - ((mcr & MCR_LOOP) ? TIOCM_LOOP : 0) | /* LOOP is set */ | |
| 406 | - ((msr & MSR_CTS) ? TIOCM_CTS : 0) | /* CTS is set */ | |
| 407 | - ((msr & MSR_CD) ? TIOCM_CAR : 0) | /* Carrier detect is set*/ | |
| 408 | - ((msr & MSR_RI) ? TIOCM_RI : 0) | /* Ring Indicator is set */ | |
| 409 | - ((msr & MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */ | |
| 392 | + result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | /* DTR is set */ | |
| 393 | + ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | /* RTS is set */ | |
| 394 | + ((mcr & MCR_LOOP) ? TIOCM_LOOP : 0) | /* LOOP is set */ | |
| 395 | + ((msr & MSR_CTS) ? TIOCM_CTS : 0) | /* CTS is set */ | |
| 396 | + ((msr & MSR_CD) ? TIOCM_CAR : 0) | /* Carrier detect is set */ | |
| 397 | + ((msr & MSR_RI) ? TIOCM_RI : 0) | /* Ring Indicator is set */ | |
| 398 | + ((msr & MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */ | |
| 410 | 399 | |
| 411 | 400 | return result; |
| 412 | 401 | } |
| 413 | 402 | |
| 414 | - | |
| 415 | - | |
| 416 | - | |
| 417 | - | |
| 418 | 403 | //static int tty0tty_tiocmset(struct tty_struct *tty, struct file *file, |
| 419 | -static int tty0tty_tiocmset(struct tty_struct *tty, | |
| 420 | - unsigned int set, unsigned int clear) | |
| 404 | +static int tty0tty_tiocmset(struct tty_struct *tty, | |
| 405 | + unsigned int set, unsigned int clear) | |
| 421 | 406 | { |
| 422 | 407 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 423 | 408 | unsigned int mcr = tty0tty->mcr; |
| 424 | - unsigned int msr=0; | |
| 425 | - | |
| 409 | + unsigned int msr = 0; | |
| 410 | + | |
| 426 | 411 | #ifdef SCULL_DEBUG |
| 427 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 412 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 428 | 413 | #endif |
| 429 | 414 | |
| 430 | - if( (tty0tty->tty->index % 2) == 0) | |
| 431 | - { | |
| 432 | - if(tty0tty_table[tty0tty->tty->index+1] != NULL) | |
| 433 | - if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | |
| 434 | - msr=tty0tty_table[tty0tty->tty->index+1]->msr; | |
| 435 | - } | |
| 436 | - else | |
| 437 | - { | |
| 438 | - if(tty0tty_table[tty0tty->tty->index-1] != NULL) | |
| 439 | - if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | |
| 440 | - msr=tty0tty_table[tty0tty->tty->index-1]->msr; | |
| 441 | - } | |
| 442 | - | |
| 415 | + if ((tty0tty->tty->index % 2) == 0) { | |
| 416 | + if (tty0tty_table[tty0tty->tty->index + 1] != NULL) | |
| 417 | + if (tty0tty_table[tty0tty->tty->index + 1]->open_count > | |
| 418 | + 0) | |
| 419 | + msr = | |
| 420 | + tty0tty_table[tty0tty->tty->index + 1]->msr; | |
| 421 | + } else { | |
| 422 | + if (tty0tty_table[tty0tty->tty->index - 1] != NULL) | |
| 423 | + if (tty0tty_table[tty0tty->tty->index - 1]->open_count > | |
| 424 | + 0) | |
| 425 | + msr = | |
| 426 | + tty0tty_table[tty0tty->tty->index - 1]->msr; | |
| 427 | + } | |
| 428 | + | |
| 443 | 429 | //null modem connection |
| 444 | 430 | |
| 445 | - if (set & TIOCM_RTS) | |
| 446 | - { | |
| 447 | - mcr |= MCR_RTS; | |
| 448 | - msr |= MSR_CTS; | |
| 449 | - } | |
| 450 | - | |
| 451 | - if (set & TIOCM_DTR) | |
| 452 | - { | |
| 453 | - mcr |= MCR_DTR; | |
| 454 | - msr |= MSR_DSR; | |
| 455 | - msr |= MSR_CD; | |
| 456 | - } | |
| 457 | - | |
| 458 | - if (clear & TIOCM_RTS) | |
| 459 | - { | |
| 460 | - mcr &= ~MCR_RTS; | |
| 461 | - msr &= ~MSR_CTS; | |
| 462 | - } | |
| 463 | - | |
| 464 | - if (clear & TIOCM_DTR) | |
| 465 | - { | |
| 466 | - mcr &= ~MCR_DTR; | |
| 467 | - msr &= ~MSR_DSR; | |
| 468 | - msr &= ~MSR_CD; | |
| 469 | - } | |
| 470 | - | |
| 431 | + if (set & TIOCM_RTS) { | |
| 432 | + mcr |= MCR_RTS; | |
| 433 | + msr |= MSR_CTS; | |
| 434 | + } | |
| 435 | + | |
| 436 | + if (set & TIOCM_DTR) { | |
| 437 | + mcr |= MCR_DTR; | |
| 438 | + msr |= MSR_DSR; | |
| 439 | + msr |= MSR_CD; | |
| 440 | + } | |
| 441 | + | |
| 442 | + if (clear & TIOCM_RTS) { | |
| 443 | + mcr &= ~MCR_RTS; | |
| 444 | + msr &= ~MSR_CTS; | |
| 445 | + } | |
| 446 | + | |
| 447 | + if (clear & TIOCM_DTR) { | |
| 448 | + mcr &= ~MCR_DTR; | |
| 449 | + msr &= ~MSR_DSR; | |
| 450 | + msr &= ~MSR_CD; | |
| 451 | + } | |
| 471 | 452 | |
| 472 | 453 | /* set the new MCR value in the device */ |
| 473 | 454 | tty0tty->mcr = mcr; |
| 474 | - | |
| 475 | - if( (tty0tty->tty->index % 2) == 0) | |
| 476 | - { | |
| 477 | - if(tty0tty_table[tty0tty->tty->index+1] != NULL) | |
| 478 | - if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | |
| 479 | - tty0tty_table[tty0tty->tty->index+1]->msr=msr; | |
| 480 | - } | |
| 481 | - else | |
| 482 | - { | |
| 483 | - if(tty0tty_table[tty0tty->tty->index-1] != NULL) | |
| 484 | - if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | |
| 485 | - tty0tty_table[tty0tty->tty->index-1]->msr=msr; | |
| 486 | - } | |
| 455 | + | |
| 456 | + if ((tty0tty->tty->index % 2) == 0) { | |
| 457 | + if (tty0tty_table[tty0tty->tty->index + 1] != NULL) | |
| 458 | + if (tty0tty_table[tty0tty->tty->index + 1]->open_count > | |
| 459 | + 0) | |
| 460 | + tty0tty_table[tty0tty->tty->index + 1]->msr = | |
| 461 | + msr; | |
| 462 | + } else { | |
| 463 | + if (tty0tty_table[tty0tty->tty->index - 1] != NULL) | |
| 464 | + if (tty0tty_table[tty0tty->tty->index - 1]->open_count > | |
| 465 | + 0) | |
| 466 | + tty0tty_table[tty0tty->tty->index - 1]->msr = | |
| 467 | + msr; | |
| 468 | + } | |
| 487 | 469 | return 0; |
| 488 | 470 | } |
| 489 | 471 | |
| 490 | - | |
| 491 | -static int tty0tty_ioctl_tiocgserial(struct tty_struct *tty, | |
| 492 | - unsigned int cmd, unsigned long arg) | |
| 472 | +static int tty0tty_ioctl_tiocgserial(struct tty_struct *tty, | |
| 473 | + unsigned int cmd, unsigned long arg) | |
| 493 | 474 | { |
| 494 | 475 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 495 | - | |
| 476 | + | |
| 496 | 477 | #ifdef SCULL_DEBUG |
| 497 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 478 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 498 | 479 | #endif |
| 499 | 480 | if (cmd == TIOCGSERIAL) { |
| 500 | 481 | struct serial_struct tmp; |
| ... | ... | @@ -504,20 +485,21 @@ static int tty0tty_ioctl_tiocgserial(struct tty_struct *tty, |
| 504 | 485 | |
| 505 | 486 | memset(&tmp, 0, sizeof(tmp)); |
| 506 | 487 | |
| 507 | - tmp.type = tty0tty->serial.type; | |
| 508 | - tmp.line = tty0tty->serial.line; | |
| 509 | - tmp.port = tty0tty->serial.port; | |
| 510 | - tmp.irq = tty0tty->serial.irq; | |
| 511 | - tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | |
| 512 | - tmp.xmit_fifo_size = tty0tty->serial.xmit_fifo_size; | |
| 513 | - tmp.baud_base = tty0tty->serial.baud_base; | |
| 514 | - tmp.close_delay = 5*HZ; | |
| 515 | - tmp.closing_wait = 30*HZ; | |
| 516 | - tmp.custom_divisor = tty0tty->serial.custom_divisor; | |
| 517 | - tmp.hub6 = tty0tty->serial.hub6; | |
| 518 | - tmp.io_type = tty0tty->serial.io_type; | |
| 519 | - | |
| 520 | - if (copy_to_user((void __user *)arg, &tmp, sizeof(struct serial_struct))) | |
| 488 | + tmp.type = tty0tty->serial.type; | |
| 489 | + tmp.line = tty0tty->serial.line; | |
| 490 | + tmp.port = tty0tty->serial.port; | |
| 491 | + tmp.irq = tty0tty->serial.irq; | |
| 492 | + tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | |
| 493 | + tmp.xmit_fifo_size = tty0tty->serial.xmit_fifo_size; | |
| 494 | + tmp.baud_base = tty0tty->serial.baud_base; | |
| 495 | + tmp.close_delay = 5 * HZ; | |
| 496 | + tmp.closing_wait = 30 * HZ; | |
| 497 | + tmp.custom_divisor = tty0tty->serial.custom_divisor; | |
| 498 | + tmp.hub6 = tty0tty->serial.hub6; | |
| 499 | + tmp.io_type = tty0tty->serial.io_type; | |
| 500 | + | |
| 501 | + if (copy_to_user | |
| 502 | + ((void __user *)arg, &tmp, sizeof(struct serial_struct))) | |
| 521 | 503 | return -EFAULT; |
| 522 | 504 | return 0; |
| 523 | 505 | } |
| ... | ... | @@ -525,12 +507,12 @@ static int tty0tty_ioctl_tiocgserial(struct tty_struct *tty, |
| 525 | 507 | } |
| 526 | 508 | |
| 527 | 509 | static int tty0tty_ioctl_tiocmiwait(struct tty_struct *tty, |
| 528 | - unsigned int cmd, unsigned long arg) | |
| 510 | + unsigned int cmd, unsigned long arg) | |
| 529 | 511 | { |
| 530 | 512 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 531 | - | |
| 513 | + | |
| 532 | 514 | #ifdef SCULL_DEBUG |
| 533 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 515 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 534 | 516 | #endif |
| 535 | 517 | if (cmd == TIOCMIWAIT) { |
| 536 | 518 | DECLARE_WAITQUEUE(wait, current); |
| ... | ... | @@ -551,11 +533,11 @@ static int tty0tty_ioctl_tiocmiwait(struct tty_struct *tty, |
| 551 | 533 | cnow = tty0tty->icount; |
| 552 | 534 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
| 553 | 535 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
| 554 | - return -EIO; /* no change => error */ | |
| 536 | + return -EIO; /* no change => error */ | |
| 555 | 537 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
| 556 | 538 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
| 557 | - ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | |
| 558 | - ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { | |
| 539 | + ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | |
| 540 | + ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { | |
| 559 | 541 | return 0; |
| 560 | 542 | } |
| 561 | 543 | cprev = cnow; |
| ... | ... | @@ -566,27 +548,27 @@ static int tty0tty_ioctl_tiocmiwait(struct tty_struct *tty, |
| 566 | 548 | } |
| 567 | 549 | |
| 568 | 550 | static int tty0tty_ioctl_tiocgicount(struct tty_struct *tty, |
| 569 | - unsigned int cmd, unsigned long arg) | |
| 551 | + unsigned int cmd, unsigned long arg) | |
| 570 | 552 | { |
| 571 | 553 | struct tty0tty_serial *tty0tty = tty->driver_data; |
| 572 | - | |
| 554 | + | |
| 573 | 555 | #ifdef SCULL_DEBUG |
| 574 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 556 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 575 | 557 | #endif |
| 576 | 558 | if (cmd == TIOCGICOUNT) { |
| 577 | 559 | struct async_icount cnow = tty0tty->icount; |
| 578 | 560 | struct serial_icounter_struct icount; |
| 579 | 561 | |
| 580 | - icount.cts = cnow.cts; | |
| 581 | - icount.dsr = cnow.dsr; | |
| 582 | - icount.rng = cnow.rng; | |
| 583 | - icount.dcd = cnow.dcd; | |
| 584 | - icount.rx = cnow.rx; | |
| 585 | - icount.tx = cnow.tx; | |
| 586 | - icount.frame = cnow.frame; | |
| 587 | - icount.overrun = cnow.overrun; | |
| 588 | - icount.parity = cnow.parity; | |
| 589 | - icount.brk = cnow.brk; | |
| 562 | + icount.cts = cnow.cts; | |
| 563 | + icount.dsr = cnow.dsr; | |
| 564 | + icount.rng = cnow.rng; | |
| 565 | + icount.dcd = cnow.dcd; | |
| 566 | + icount.rx = cnow.rx; | |
| 567 | + icount.tx = cnow.tx; | |
| 568 | + icount.frame = cnow.frame; | |
| 569 | + icount.overrun = cnow.overrun; | |
| 570 | + icount.parity = cnow.parity; | |
| 571 | + icount.brk = cnow.brk; | |
| 590 | 572 | icount.buf_overrun = cnow.buf_overrun; |
| 591 | 573 | |
| 592 | 574 | if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) |
| ... | ... | @@ -597,10 +579,10 @@ static int tty0tty_ioctl_tiocgicount(struct tty_struct *tty, |
| 597 | 579 | } |
| 598 | 580 | |
| 599 | 581 | static int tty0tty_ioctl(struct tty_struct *tty, |
| 600 | - unsigned int cmd, unsigned long arg) | |
| 582 | + unsigned int cmd, unsigned long arg) | |
| 601 | 583 | { |
| 602 | 584 | #ifdef SCULL_DEBUG |
| 603 | - printk(KERN_DEBUG "%s - %04X \n", __FUNCTION__,cmd); | |
| 585 | + printk(KERN_DEBUG "%s - %04X \n", __FUNCTION__, cmd); | |
| 604 | 586 | #endif |
| 605 | 587 | switch (cmd) { |
| 606 | 588 | case TIOCGSERIAL: |
| ... | ... | @@ -625,29 +607,28 @@ static struct tty_operations serial_ops = { |
| 625 | 607 | .ioctl = tty0tty_ioctl, |
| 626 | 608 | }; |
| 627 | 609 | |
| 628 | - | |
| 629 | - | |
| 630 | - | |
| 631 | 610 | static struct tty_driver *tty0tty_tty_driver; |
| 632 | 611 | |
| 633 | 612 | static int __init tty0tty_init(void) |
| 634 | 613 | { |
| 635 | 614 | int retval; |
| 636 | - int i; | |
| 637 | - if (pairs > 128) pairs = 128; | |
| 638 | - if (pairs < 1) pairs = 1; | |
| 639 | - tport = kmalloc(2*pairs*sizeof(struct tty_port),GFP_KERNEL); | |
| 640 | - tty0tty_table = kmalloc(2*pairs*sizeof(struct tty0tty_serial*),GFP_KERNEL); | |
| 641 | - | |
| 642 | - for(i=0;i<2*pairs;i++) | |
| 643 | - { | |
| 615 | + int i; | |
| 616 | + if (pairs > 128) | |
| 617 | + pairs = 128; | |
| 618 | + if (pairs < 1) | |
| 619 | + pairs = 1; | |
| 620 | + tport = kmalloc(2 * pairs * sizeof(struct tty_port), GFP_KERNEL); | |
| 621 | + tty0tty_table = | |
| 622 | + kmalloc(2 * pairs * sizeof(struct tty0tty_serial *), GFP_KERNEL); | |
| 623 | + | |
| 624 | + for (i = 0; i < 2 * pairs; i++) { | |
| 644 | 625 | tty0tty_table[i] = NULL; |
| 645 | 626 | } |
| 646 | 627 | #ifdef SCULL_DEBUG |
| 647 | 628 | printk(KERN_DEBUG "%s - \n", __FUNCTION__); |
| 648 | 629 | #endif |
| 649 | 630 | /* allocate the tty driver */ |
| 650 | - tty0tty_tty_driver = alloc_tty_driver(2*pairs); | |
| 631 | + tty0tty_tty_driver = alloc_tty_driver(2 * pairs); | |
| 651 | 632 | if (!tty0tty_tty_driver) |
| 652 | 633 | return -ENOMEM; |
| 653 | 634 | |
| ... | ... | @@ -655,32 +636,32 @@ static int __init tty0tty_init(void) |
| 655 | 636 | tty0tty_tty_driver->owner = THIS_MODULE; |
| 656 | 637 | tty0tty_tty_driver->driver_name = "tty0tty"; |
| 657 | 638 | tty0tty_tty_driver->name = "tnt"; |
| 658 | - /* no more devfs subsystem */ | |
| 639 | + /* no more devfs subsystem */ | |
| 659 | 640 | tty0tty_tty_driver->major = TTY0TTY_MAJOR; |
| 660 | 641 | tty0tty_tty_driver->minor_start = TTY0TTY_MINOR; |
| 661 | 642 | tty0tty_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 662 | 643 | tty0tty_tty_driver->subtype = SERIAL_TYPE_NORMAL; |
| 663 | - tty0tty_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW ; | |
| 664 | - /* no more devfs subsystem */ | |
| 644 | + tty0tty_tty_driver->flags = | |
| 645 | + TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW; | |
| 646 | + /* no more devfs subsystem */ | |
| 665 | 647 | tty0tty_tty_driver->init_termios = tty_std_termios; |
| 666 | - tty0tty_tty_driver->init_termios.c_iflag = 0; | |
| 667 | - tty0tty_tty_driver->init_termios.c_oflag = 0; | |
| 668 | - tty0tty_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; | |
| 669 | - tty0tty_tty_driver->init_termios.c_lflag = 0; | |
| 670 | - tty0tty_tty_driver->init_termios.c_ispeed = 38400; | |
| 671 | - tty0tty_tty_driver->init_termios.c_ospeed = 38400; | |
| 648 | + tty0tty_tty_driver->init_termios.c_iflag = 0; | |
| 649 | + tty0tty_tty_driver->init_termios.c_oflag = 0; | |
| 650 | + tty0tty_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; | |
| 651 | + tty0tty_tty_driver->init_termios.c_lflag = 0; | |
| 652 | + tty0tty_tty_driver->init_termios.c_ispeed = 38400; | |
| 653 | + tty0tty_tty_driver->init_termios.c_ospeed = 38400; | |
| 672 | 654 | |
| 673 | 655 | tty_set_operations(tty0tty_tty_driver, &serial_ops); |
| 674 | - | |
| 675 | - for(i=0;i<2*pairs;i++) | |
| 676 | - { | |
| 677 | - tty_port_init(&tport[i]); | |
| 656 | + | |
| 657 | + for (i = 0; i < 2 * pairs; i++) { | |
| 658 | + tty_port_init(&tport[i]); | |
| 678 | 659 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) |
| 679 | - tty_port_link_device(&tport[i],tty0tty_tty_driver, i); | |
| 660 | + tty_port_link_device(&tport[i], tty0tty_tty_driver, i); | |
| 680 | 661 | #endif |
| 681 | 662 | } |
| 682 | 663 | |
| 683 | - retval = tty_register_driver(tty0tty_tty_driver); | |
| 664 | + retval = tty_register_driver(tty0tty_tty_driver); | |
| 684 | 665 | if (retval) { |
| 685 | 666 | printk(KERN_ERR "failed to register tty0tty tty driver"); |
| 686 | 667 | put_tty_driver(tty0tty_tty_driver); |
| ... | ... | @@ -695,21 +676,20 @@ static void __exit tty0tty_exit(void) |
| 695 | 676 | { |
| 696 | 677 | struct tty0tty_serial *tty0tty; |
| 697 | 678 | int i; |
| 698 | - | |
| 679 | + | |
| 699 | 680 | #ifdef SCULL_DEBUG |
| 700 | - printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 681 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | |
| 701 | 682 | #endif |
| 702 | - for (i = 0; i < 2*pairs; ++i) | |
| 703 | - { | |
| 683 | + for (i = 0; i < 2 * pairs; ++i) { | |
| 704 | 684 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) |
| 705 | - tty_port_destroy(&tport[i]); | |
| 685 | + tty_port_destroy(&tport[i]); | |
| 706 | 686 | #endif |
| 707 | 687 | tty_unregister_device(tty0tty_tty_driver, i); |
| 708 | - } | |
| 688 | + } | |
| 709 | 689 | tty_unregister_driver(tty0tty_tty_driver); |
| 710 | 690 | |
| 711 | 691 | /* shut down all of the timers and free the memory */ |
| 712 | - for (i = 0; i < 2*pairs; ++i) { | |
| 692 | + for (i = 0; i < 2 * pairs; ++i) { | |
| 713 | 693 | tty0tty = tty0tty_table[i]; |
| 714 | 694 | if (tty0tty) { |
| 715 | 695 | /* close the port */ | ... | ... |