2 * KOBIL USB Smart Card Terminal Driver
4 * Copyright (C) 2002 KOBIL Systems GmbH
5 * Author: Thomas Wahrenbruch
7 * Contact: linuxusb@kobil.de
9 * This program is largely derived from work by the linux-usb group
10 * and associated source files. Please see the usb/serial files for
11 * individual credits and copyrights.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * Thanks to Greg Kroah-Hartman (greg@kroah.com) for his help and
21 * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus
22 * (Adapter K), B1 Professional and KAAN Professional (Adapter B)
25 * Fix bug with P'n'P readers
28 * Add support for KAAN SIM
38 #include <linux/config.h>
39 #include <linux/kernel.h>
40 #include <linux/errno.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/tty.h>
44 #include <linux/tty_driver.h>
45 #include <linux/tty_flip.h>
46 #include <linux/module.h>
47 #include <linux/spinlock.h>
48 #include <asm/uaccess.h>
49 #include <linux/usb.h>
50 #include <linux/ioctl.h>
51 #include "usb-serial.h"
52 #include "kobil_sct.h"
56 /* Version Information */
57 #define DRIVER_VERSION "21/05/2004"
58 #define DRIVER_AUTHOR "KOBIL Systems GmbH - http://www.kobil.com"
59 #define DRIVER_DESC "KOBIL USB Smart Card Terminal Driver (experimental)"
61 #define KOBIL_VENDOR_ID 0x0D46
62 #define KOBIL_ADAPTER_B_PRODUCT_ID 0x2011
63 #define KOBIL_ADAPTER_K_PRODUCT_ID 0x2012
64 #define KOBIL_USBTWIN_PRODUCT_ID 0x0078
65 #define KOBIL_KAAN_SIM_PRODUCT_ID 0x0081
67 #define KOBIL_TIMEOUT 500
68 #define KOBIL_BUF_LENGTH 300
71 /* Function prototypes */
72 static int kobil_startup (struct usb_serial
*serial
);
73 static void kobil_shutdown (struct usb_serial
*serial
);
74 static int kobil_open (struct usb_serial_port
*port
, struct file
*filp
);
75 static void kobil_close (struct usb_serial_port
*port
, struct file
*filp
);
76 static int kobil_write (struct usb_serial_port
*port
,
77 const unsigned char *buf
, int count
);
78 static int kobil_write_room(struct usb_serial_port
*port
);
79 static int kobil_ioctl(struct usb_serial_port
*port
, struct file
*file
,
80 unsigned int cmd
, unsigned long arg
);
81 static int kobil_tiocmget(struct usb_serial_port
*port
, struct file
*file
);
82 static int kobil_tiocmset(struct usb_serial_port
*port
, struct file
*file
,
83 unsigned int set
, unsigned int clear
);
84 static void kobil_read_int_callback( struct urb
*urb
, struct pt_regs
*regs
);
85 static void kobil_write_callback( struct urb
*purb
, struct pt_regs
*regs
);
88 static struct usb_device_id id_table
[] = {
89 { USB_DEVICE(KOBIL_VENDOR_ID
, KOBIL_ADAPTER_B_PRODUCT_ID
) },
90 { USB_DEVICE(KOBIL_VENDOR_ID
, KOBIL_ADAPTER_K_PRODUCT_ID
) },
91 { USB_DEVICE(KOBIL_VENDOR_ID
, KOBIL_USBTWIN_PRODUCT_ID
) },
92 { USB_DEVICE(KOBIL_VENDOR_ID
, KOBIL_KAAN_SIM_PRODUCT_ID
) },
93 { } /* Terminating entry */
97 MODULE_DEVICE_TABLE (usb
, id_table
);
99 static struct usb_driver kobil_driver
= {
100 .owner
= THIS_MODULE
,
102 .probe
= usb_serial_probe
,
103 .disconnect
= usb_serial_disconnect
,
104 .id_table
= id_table
,
108 static struct usb_serial_device_type kobil_device
= {
109 .owner
= THIS_MODULE
,
110 .name
= "KOBIL USB smart card terminal",
111 .id_table
= id_table
,
112 .num_interrupt_in
= NUM_DONT_CARE
,
116 .attach
= kobil_startup
,
117 .shutdown
= kobil_shutdown
,
118 .ioctl
= kobil_ioctl
,
119 .tiocmget
= kobil_tiocmget
,
120 .tiocmset
= kobil_tiocmset
,
122 .close
= kobil_close
,
123 .write
= kobil_write
,
124 .write_room
= kobil_write_room
,
125 .read_int_callback
= kobil_read_int_callback
,
129 struct kobil_private
{
130 int write_int_endpoint_address
;
131 int read_int_endpoint_address
;
132 unsigned char buf
[KOBIL_BUF_LENGTH
]; // buffer for the APDU to send
133 int filled
; // index of the last char in buf
134 int cur_pos
; // index of the next char to send in buf
137 struct termios internal_termios
;
141 static int kobil_startup (struct usb_serial
*serial
)
144 struct kobil_private
*priv
;
145 struct usb_device
*pdev
;
146 struct usb_host_config
*actconfig
;
147 struct usb_interface
*interface
;
148 struct usb_host_interface
*altsetting
;
149 struct usb_host_endpoint
*endpoint
;
151 priv
= kmalloc(sizeof(struct kobil_private
), GFP_KERNEL
);
158 priv
->device_type
= le16_to_cpu(serial
->dev
->descriptor
.idProduct
);
159 priv
->line_state
= 0;
161 switch (priv
->device_type
){
162 case KOBIL_ADAPTER_B_PRODUCT_ID
:
163 printk(KERN_DEBUG
"KOBIL B1 PRO / KAAN PRO detected\n");
165 case KOBIL_ADAPTER_K_PRODUCT_ID
:
166 printk(KERN_DEBUG
"KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n");
168 case KOBIL_USBTWIN_PRODUCT_ID
:
169 printk(KERN_DEBUG
"KOBIL USBTWIN detected\n");
171 case KOBIL_KAAN_SIM_PRODUCT_ID
:
172 printk(KERN_DEBUG
"KOBIL KAAN SIM detected\n");
175 usb_set_serial_port_data(serial
->port
[0], priv
);
177 // search for the necessary endpoints
179 actconfig
= pdev
->actconfig
;
180 interface
= actconfig
->interface
[0];
181 altsetting
= interface
->cur_altsetting
;
182 endpoint
= altsetting
->endpoint
;
184 for (i
= 0; i
< altsetting
->desc
.bNumEndpoints
; i
++) {
185 endpoint
= &altsetting
->endpoint
[i
];
186 if (((endpoint
->desc
.bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_OUT
) &&
187 ((endpoint
->desc
.bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_INT
)) {
188 dbg("%s Found interrupt out endpoint. Address: %d", __FUNCTION__
, endpoint
->desc
.bEndpointAddress
);
189 priv
->write_int_endpoint_address
= endpoint
->desc
.bEndpointAddress
;
191 if (((endpoint
->desc
.bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_IN
) &&
192 ((endpoint
->desc
.bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) == USB_ENDPOINT_XFER_INT
)) {
193 dbg("%s Found interrupt in endpoint. Address: %d", __FUNCTION__
, endpoint
->desc
.bEndpointAddress
);
194 priv
->read_int_endpoint_address
= endpoint
->desc
.bEndpointAddress
;
201 static void kobil_shutdown (struct usb_serial
*serial
)
204 dbg("%s - port %d", __FUNCTION__
, serial
->port
[0]->number
);
206 for (i
=0; i
< serial
->num_ports
; ++i
) {
207 while (serial
->port
[i
]->open_count
> 0) {
208 kobil_close (serial
->port
[i
], NULL
);
210 kfree(usb_get_serial_port_data(serial
->port
[i
]));
211 usb_set_serial_port_data(serial
->port
[i
], NULL
);
216 static int kobil_open (struct usb_serial_port
*port
, struct file
*filp
)
219 struct kobil_private
*priv
;
220 unsigned char *transfer_buffer
;
221 int transfer_buffer_length
= 8;
222 int write_urb_transfer_buffer_length
= 8;
224 dbg("%s - port %d", __FUNCTION__
, port
->number
);
225 priv
= usb_get_serial_port_data(port
);
226 priv
->line_state
= 0;
228 // someone sets the dev to 0 if the close method has been called
229 port
->interrupt_in_urb
->dev
= port
->serial
->dev
;
232 /* force low_latency on so that our tty_push actually forces
233 * the data through, otherwise it is scheduled, and with high
234 * data rates (like with OHCI) data can get lost.
236 port
->tty
->low_latency
= 1;
238 // without this, every push_tty_char is echoed :-(
239 port
->tty
->termios
->c_lflag
= 0;
240 port
->tty
->termios
->c_lflag
&= ~(ISIG
| ICANON
| ECHO
| IEXTEN
| XCASE
);
241 port
->tty
->termios
->c_iflag
= IGNBRK
| IGNPAR
| IXOFF
;
242 port
->tty
->termios
->c_oflag
&= ~ONLCR
; // do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D)
244 // set up internal termios structure
245 priv
->internal_termios
.c_iflag
= port
->tty
->termios
->c_iflag
;
246 priv
->internal_termios
.c_oflag
= port
->tty
->termios
->c_oflag
;
247 priv
->internal_termios
.c_cflag
= port
->tty
->termios
->c_cflag
;
248 priv
->internal_termios
.c_lflag
= port
->tty
->termios
->c_lflag
;
250 for (i
=0; i
<NCCS
; i
++) {
251 priv
->internal_termios
.c_cc
[i
] = port
->tty
->termios
->c_cc
[i
];
254 // allocate memory for transfer buffer
255 transfer_buffer
= (unsigned char *) kmalloc(transfer_buffer_length
, GFP_KERNEL
);
256 if (! transfer_buffer
) {
259 memset(transfer_buffer
, 0, transfer_buffer_length
);
262 // allocate write_urb
263 if (!port
->write_urb
) {
264 dbg("%s - port %d Allocating port->write_urb", __FUNCTION__
, port
->number
);
265 port
->write_urb
= usb_alloc_urb(0, GFP_KERNEL
);
266 if (!port
->write_urb
) {
267 dbg("%s - port %d usb_alloc_urb failed", __FUNCTION__
, port
->number
);
268 kfree(transfer_buffer
);
273 // allocate memory for write_urb transfer buffer
274 port
->write_urb
->transfer_buffer
= (unsigned char *) kmalloc(write_urb_transfer_buffer_length
, GFP_KERNEL
);
275 if (! port
->write_urb
->transfer_buffer
) {
276 kfree(transfer_buffer
);
277 usb_free_urb(port
->write_urb
);
278 port
->write_urb
= NULL
;
282 // get hardware version
283 result
= usb_control_msg( port
->serial
->dev
,
284 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
285 SUSBCRequest_GetMisc
,
286 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
287 SUSBCR_MSC_GetHWVersion
,
290 transfer_buffer_length
,
293 dbg("%s - port %d Send get_HW_version URB returns: %i", __FUNCTION__
, port
->number
, result
);
294 dbg("Harware version: %i.%i.%i", transfer_buffer
[0], transfer_buffer
[1], transfer_buffer
[2] );
296 // get firmware version
297 result
= usb_control_msg( port
->serial
->dev
,
298 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
299 SUSBCRequest_GetMisc
,
300 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
301 SUSBCR_MSC_GetFWVersion
,
304 transfer_buffer_length
,
307 dbg("%s - port %d Send get_FW_version URB returns: %i", __FUNCTION__
, port
->number
, result
);
308 dbg("Firmware version: %i.%i.%i", transfer_buffer
[0], transfer_buffer
[1], transfer_buffer
[2] );
310 if (priv
->device_type
== KOBIL_ADAPTER_B_PRODUCT_ID
|| priv
->device_type
== KOBIL_ADAPTER_K_PRODUCT_ID
) {
311 // Setting Baudrate, Parity and Stopbits
312 result
= usb_control_msg( port
->serial
->dev
,
313 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
314 SUSBCRequest_SetBaudRateParityAndStopBits
,
315 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_OUT
,
316 SUSBCR_SBR_9600
| SUSBCR_SPASB_EvenParity
| SUSBCR_SPASB_1StopBit
,
322 dbg("%s - port %d Send set_baudrate URB returns: %i", __FUNCTION__
, port
->number
, result
);
325 result
= usb_control_msg( port
->serial
->dev
,
326 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
328 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_OUT
,
329 SUSBCR_MSC_ResetAllQueues
,
335 dbg("%s - port %d Send reset_all_queues URB returns: %i", __FUNCTION__
, port
->number
, result
);
337 if (priv
->device_type
== KOBIL_USBTWIN_PRODUCT_ID
|| priv
->device_type
== KOBIL_ADAPTER_B_PRODUCT_ID
||
338 priv
->device_type
== KOBIL_KAAN_SIM_PRODUCT_ID
) {
339 // start reading (Adapter B 'cause PNP string)
340 result
= usb_submit_urb( port
->interrupt_in_urb
, GFP_ATOMIC
);
341 dbg("%s - port %d Send read URB returns: %i", __FUNCTION__
, port
->number
, result
);
344 kfree(transfer_buffer
);
349 static void kobil_close (struct usb_serial_port
*port
, struct file
*filp
)
351 dbg("%s - port %d", __FUNCTION__
, port
->number
);
353 if (port
->write_urb
) {
354 usb_kill_urb(port
->write_urb
);
355 usb_free_urb( port
->write_urb
);
356 port
->write_urb
= NULL
;
358 if (port
->interrupt_in_urb
)
359 usb_kill_urb(port
->interrupt_in_urb
);
363 static void kobil_read_int_callback( struct urb
*purb
, struct pt_regs
*regs
)
367 struct usb_serial_port
*port
= (struct usb_serial_port
*) purb
->context
;
368 struct tty_struct
*tty
;
369 unsigned char *data
= purb
->transfer_buffer
;
372 dbg("%s - port %d", __FUNCTION__
, port
->number
);
375 dbg("%s - port %d Read int status not zero: %d", __FUNCTION__
, port
->number
, purb
->status
);
380 if (purb
->actual_length
) {
384 dbg_data = (unsigned char *) kmalloc((3 * purb->actual_length + 10) * sizeof(char), GFP_KERNEL);
388 memset(dbg_data, 0, (3 * purb->actual_length + 10));
389 for (i = 0; i < purb->actual_length; i++) {
390 sprintf(dbg_data +3*i, "%02X ", data[i]);
392 dbg(" <-- %s", dbg_data );
397 for (i
= 0; i
< purb
->actual_length
; ++i
) {
398 // if we insert more than TTY_FLIPBUF_SIZE characters, we drop them.
399 if(tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
400 tty_flip_buffer_push(tty
);
402 // this doesn't actually push the data through unless tty->low_latency is set
403 tty_insert_flip_char(tty
, data
[i
], 0);
405 tty_flip_buffer_push(tty
);
408 // someone sets the dev to 0 if the close method has been called
409 port
->interrupt_in_urb
->dev
= port
->serial
->dev
;
411 result
= usb_submit_urb( port
->interrupt_in_urb
, GFP_ATOMIC
);
412 dbg("%s - port %d Send read URB returns: %i", __FUNCTION__
, port
->number
, result
);
416 static void kobil_write_callback( struct urb
*purb
, struct pt_regs
*regs
)
421 static int kobil_write (struct usb_serial_port
*port
,
422 const unsigned char *buf
, int count
)
427 struct kobil_private
* priv
;
430 dbg("%s - port %d write request of 0 bytes", __FUNCTION__
, port
->number
);
434 priv
= usb_get_serial_port_data(port
);
436 if (count
> (KOBIL_BUF_LENGTH
- priv
->filled
)) {
437 dbg("%s - port %d Error: write request bigger than buffer size", __FUNCTION__
, port
->number
);
441 // Copy data to buffer
442 memcpy (priv
->buf
+ priv
->filled
, buf
, count
);
444 usb_serial_debug_data(debug
, &port
->dev
, __FUNCTION__
, count
, priv
->buf
+ priv
->filled
);
446 priv
->filled
= priv
->filled
+ count
;
449 // only send complete block. TWIN, KAAN SIM and adapter K use the same protocol.
450 if ( ((priv
->device_type
!= KOBIL_ADAPTER_B_PRODUCT_ID
) && (priv
->filled
> 2) && (priv
->filled
>= (priv
->buf
[1] + 3))) ||
451 ((priv
->device_type
== KOBIL_ADAPTER_B_PRODUCT_ID
) && (priv
->filled
> 3) && (priv
->filled
>= (priv
->buf
[2] + 4))) ) {
453 // stop reading (except TWIN and KAAN SIM)
454 if ( (priv
->device_type
== KOBIL_ADAPTER_B_PRODUCT_ID
) || (priv
->device_type
== KOBIL_ADAPTER_K_PRODUCT_ID
) )
455 usb_kill_urb(port
->interrupt_in_urb
);
457 todo
= priv
->filled
- priv
->cur_pos
;
460 // max 8 byte in one urb (endpoint size)
461 length
= (todo
< 8) ? todo
: 8;
462 // copy data to transfer buffer
463 memcpy(port
->write_urb
->transfer_buffer
, priv
->buf
+ priv
->cur_pos
, length
);
464 usb_fill_int_urb( port
->write_urb
,
466 usb_sndintpipe(port
->serial
->dev
, priv
->write_int_endpoint_address
),
467 port
->write_urb
->transfer_buffer
,
469 kobil_write_callback
,
474 priv
->cur_pos
= priv
->cur_pos
+ length
;
475 result
= usb_submit_urb( port
->write_urb
, GFP_NOIO
);
476 dbg("%s - port %d Send write URB returns: %i", __FUNCTION__
, port
->number
, result
);
477 todo
= priv
->filled
- priv
->cur_pos
;
488 // someone sets the dev to 0 if the close method has been called
489 port
->interrupt_in_urb
->dev
= port
->serial
->dev
;
491 // start reading (except TWIN and KAAN SIM)
492 if ( (priv
->device_type
== KOBIL_ADAPTER_B_PRODUCT_ID
) || (priv
->device_type
== KOBIL_ADAPTER_K_PRODUCT_ID
) ) {
493 // someone sets the dev to 0 if the close method has been called
494 port
->interrupt_in_urb
->dev
= port
->serial
->dev
;
496 result
= usb_submit_urb( port
->interrupt_in_urb
, GFP_NOIO
);
497 dbg("%s - port %d Send read URB returns: %i", __FUNCTION__
, port
->number
, result
);
504 static int kobil_write_room (struct usb_serial_port
*port
)
506 //dbg("%s - port %d", __FUNCTION__, port->number);
511 static int kobil_tiocmget(struct usb_serial_port
*port
, struct file
*file
)
513 struct kobil_private
* priv
;
515 unsigned char *transfer_buffer
;
516 int transfer_buffer_length
= 8;
518 priv
= usb_get_serial_port_data(port
);
519 if ((priv
->device_type
== KOBIL_USBTWIN_PRODUCT_ID
) || (priv
->device_type
== KOBIL_KAAN_SIM_PRODUCT_ID
)) {
520 // This device doesn't support ioctl calls
524 // allocate memory for transfer buffer
525 transfer_buffer
= (unsigned char *) kmalloc(transfer_buffer_length
, GFP_KERNEL
);
526 if (!transfer_buffer
) {
529 memset(transfer_buffer
, 0, transfer_buffer_length
);
531 result
= usb_control_msg( port
->serial
->dev
,
532 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
533 SUSBCRequest_GetStatusLineState
,
534 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_IN
,
538 transfer_buffer_length
,
541 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x",
542 __FUNCTION__
, port
->number
, result
, transfer_buffer
[0]);
544 if ((transfer_buffer
[0] & SUSBCR_GSL_DSR
) != 0) {
545 priv
->line_state
|= TIOCM_DSR
;
547 priv
->line_state
&= ~TIOCM_DSR
;
550 kfree(transfer_buffer
);
551 return priv
->line_state
;
554 static int kobil_tiocmset(struct usb_serial_port
*port
, struct file
*file
,
555 unsigned int set
, unsigned int clear
)
557 struct kobil_private
* priv
;
561 unsigned char *transfer_buffer
;
562 int transfer_buffer_length
= 8;
564 priv
= usb_get_serial_port_data(port
);
565 if ((priv
->device_type
== KOBIL_USBTWIN_PRODUCT_ID
) || (priv
->device_type
== KOBIL_KAAN_SIM_PRODUCT_ID
)) {
566 // This device doesn't support ioctl calls
570 // allocate memory for transfer buffer
571 transfer_buffer
= (unsigned char *) kmalloc(transfer_buffer_length
, GFP_KERNEL
);
572 if (! transfer_buffer
) {
575 memset(transfer_buffer
, 0, transfer_buffer_length
);
581 if (clear
& TIOCM_RTS
)
583 if (clear
& TIOCM_DTR
)
586 if (priv
->device_type
== KOBIL_ADAPTER_B_PRODUCT_ID
) {
588 dbg("%s - port %d Setting DTR", __FUNCTION__
, port
->number
);
590 dbg("%s - port %d Clearing DTR", __FUNCTION__
, port
->number
);
591 result
= usb_control_msg( port
->serial
->dev
,
592 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
593 SUSBCRequest_SetStatusLinesOrQueues
,
594 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_OUT
,
595 ((dtr
!= 0) ? SUSBCR_SSL_SETDTR
: SUSBCR_SSL_CLRDTR
),
602 dbg("%s - port %d Setting RTS", __FUNCTION__
, port
->number
);
604 dbg("%s - port %d Clearing RTS", __FUNCTION__
, port
->number
);
605 result
= usb_control_msg( port
->serial
->dev
,
606 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
607 SUSBCRequest_SetStatusLinesOrQueues
,
608 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_OUT
,
609 ((rts
!= 0) ? SUSBCR_SSL_SETRTS
: SUSBCR_SSL_CLRRTS
),
615 dbg("%s - port %d Send set_status_line URB returns: %i", __FUNCTION__
, port
->number
, result
);
616 kfree(transfer_buffer
);
617 return (result
< 0) ? result
: 0;
621 static int kobil_ioctl(struct usb_serial_port
*port
, struct file
*file
,
622 unsigned int cmd
, unsigned long arg
)
624 struct kobil_private
* priv
;
626 unsigned short urb_val
= 0;
627 unsigned char *transfer_buffer
;
628 int transfer_buffer_length
= 8;
630 void __user
*user_arg
= (void __user
*)arg
;
632 priv
= usb_get_serial_port_data(port
);
633 if ((priv
->device_type
== KOBIL_USBTWIN_PRODUCT_ID
) || (priv
->device_type
== KOBIL_KAAN_SIM_PRODUCT_ID
)) {
634 // This device doesn't support ioctl calls
639 case TCGETS
: // 0x5401
640 if (!access_ok(VERIFY_WRITE
, user_arg
, sizeof(struct termios
))) {
641 dbg("%s - port %d Error in access_ok", __FUNCTION__
, port
->number
);
644 if (kernel_termios_to_user_termios((struct termios __user
*)arg
,
645 &priv
->internal_termios
))
649 case TCSETS
: // 0x5402
650 if (!(port
->tty
->termios
)) {
651 dbg("%s - port %d Error: port->tty->termios is NULL", __FUNCTION__
, port
->number
);
654 if (!access_ok(VERIFY_READ
, user_arg
, sizeof(struct termios
))) {
655 dbg("%s - port %d Error in access_ok", __FUNCTION__
, port
->number
);
658 if (user_termios_to_kernel_termios(&priv
->internal_termios
,
659 (struct termios __user
*)arg
))
662 settings
= (unsigned char *) kmalloc(50, GFP_KERNEL
);
666 memset(settings
, 0, 50);
668 switch (priv
->internal_termios
.c_cflag
& CBAUD
) {
670 urb_val
= SUSBCR_SBR_1200
;
671 strcat(settings
, "1200 ");
675 urb_val
= SUSBCR_SBR_9600
;
676 strcat(settings
, "9600 ");
680 urb_val
|= (priv
->internal_termios
.c_cflag
& CSTOPB
) ? SUSBCR_SPASB_2StopBits
: SUSBCR_SPASB_1StopBit
;
681 strcat(settings
, (priv
->internal_termios
.c_cflag
& CSTOPB
) ? "2 StopBits " : "1 StopBit ");
683 if (priv
->internal_termios
.c_cflag
& PARENB
) {
684 if (priv
->internal_termios
.c_cflag
& PARODD
) {
685 urb_val
|= SUSBCR_SPASB_OddParity
;
686 strcat(settings
, "Odd Parity");
688 urb_val
|= SUSBCR_SPASB_EvenParity
;
689 strcat(settings
, "Even Parity");
692 urb_val
|= SUSBCR_SPASB_NoParity
;
693 strcat(settings
, "No Parity");
695 dbg("%s - port %d setting port to: %s", __FUNCTION__
, port
->number
, settings
);
697 result
= usb_control_msg( port
->serial
->dev
,
698 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
699 SUSBCRequest_SetBaudRateParityAndStopBits
,
700 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_OUT
,
708 dbg("%s - port %d Send set_baudrate URB returns: %i", __FUNCTION__
, port
->number
, result
);
712 case TCFLSH
: // 0x540B
713 transfer_buffer
= (unsigned char *) kmalloc(transfer_buffer_length
, GFP_KERNEL
);
714 if (! transfer_buffer
) {
718 result
= usb_control_msg( port
->serial
->dev
,
719 usb_rcvctrlpipe(port
->serial
->dev
, 0 ),
721 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
| USB_DIR_OUT
,
722 SUSBCR_MSC_ResetAllQueues
,
724 NULL
,//transfer_buffer,
729 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __FUNCTION__
, port
->number
, result
);
731 kfree(transfer_buffer
);
732 return ((result
< 0) ? -EFAULT
: 0);
739 static int __init
kobil_init (void)
742 retval
= usb_serial_register(&kobil_device
);
744 goto failed_usb_serial_register
;
745 retval
= usb_register(&kobil_driver
);
747 goto failed_usb_register
;
749 info(DRIVER_VERSION
" " DRIVER_AUTHOR
);
754 usb_serial_deregister(&kobil_device
);
755 failed_usb_serial_register
:
760 static void __exit
kobil_exit (void)
762 usb_deregister (&kobil_driver
);
763 usb_serial_deregister (&kobil_device
);
766 module_init(kobil_init
);
767 module_exit(kobil_exit
);
769 MODULE_AUTHOR( DRIVER_AUTHOR
);
770 MODULE_DESCRIPTION( DRIVER_DESC
);
771 MODULE_LICENSE( "GPL" );
773 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
774 MODULE_PARM_DESC(debug
, "Debug enabled or not");