26 #include <linux/kernel.h>
27 #include <linux/errno.h>
29 #include <linux/slab.h>
30 #include <linux/tty.h>
33 #include <linux/module.h>
42 #define DRIVER_VERSION "21/05/2004"
43 #define DRIVER_AUTHOR "KOBIL Systems GmbH - http://www.kobil.com"
44 #define DRIVER_DESC "KOBIL USB Smart Card Terminal Driver (experimental)"
46 #define KOBIL_VENDOR_ID 0x0D46
47 #define KOBIL_ADAPTER_B_PRODUCT_ID 0x2011
48 #define KOBIL_ADAPTER_K_PRODUCT_ID 0x2012
49 #define KOBIL_USBTWIN_PRODUCT_ID 0x0078
50 #define KOBIL_KAAN_SIM_PRODUCT_ID 0x0081
52 #define KOBIL_TIMEOUT 500
53 #define KOBIL_BUF_LENGTH 300
62 const unsigned char *
buf,
int count);
63 static int kobil_write_room(
struct tty_struct *tty);
65 unsigned int cmd,
unsigned long arg);
66 static int kobil_tiocmget(
struct tty_struct *tty);
67 static int kobil_tiocmset(
struct tty_struct *tty,
68 unsigned int set,
unsigned int clear);
69 static void kobil_read_int_callback(
struct urb *
urb);
70 static void kobil_write_callback(
struct urb *purb);
71 static void kobil_set_termios(
struct tty_struct *tty,
73 static void kobil_init_termios(
struct tty_struct *tty);
89 .description =
"KOBIL USB smart card terminal",
92 .port_probe = kobil_port_probe,
93 .port_remove = kobil_port_remove,
95 .set_termios = kobil_set_termios,
96 .init_termios = kobil_init_termios,
97 .tiocmget = kobil_tiocmget,
98 .tiocmset = kobil_tiocmset,
100 .close = kobil_close,
101 .write = kobil_write,
102 .write_room = kobil_write_room,
103 .read_int_callback = kobil_read_int_callback,
125 struct usb_device *
pdev;
126 struct usb_host_config *actconfig;
128 struct usb_host_interface *altsetting;
141 dev_dbg(&serial->
dev->dev,
"KOBIL B1 PRO / KAAN PRO detected\n");
144 dev_dbg(&serial->
dev->dev,
"KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n");
147 dev_dbg(&serial->
dev->dev,
"KOBIL USBTWIN detected\n");
150 dev_dbg(&serial->
dev->dev,
"KOBIL KAAN SIM detected\n");
153 usb_set_serial_port_data(port, priv);
157 actconfig = pdev->actconfig;
158 interface = actconfig->interface[0];
159 altsetting = interface->cur_altsetting;
160 endpoint = altsetting->endpoint;
162 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
163 endpoint = &altsetting->endpoint[
i];
164 if (usb_endpoint_is_int_out(&endpoint->desc)) {
166 "%s Found interrupt out endpoint. Address: %d\n",
167 __func__, endpoint->desc.bEndpointAddress);
169 endpoint->desc.bEndpointAddress;
171 if (usb_endpoint_is_int_in(&endpoint->desc)) {
173 "%s Found interrupt in endpoint. Address: %d\n",
174 __func__, endpoint->desc.bEndpointAddress);
176 endpoint->desc.bEndpointAddress;
187 priv = usb_get_serial_port_data(port);
193 static void kobil_init_termios(
struct tty_struct *tty)
196 tty->termios.c_lflag = 0;
200 tty->termios.c_oflag &= ~
ONLCR;
209 int transfer_buffer_length = 8;
210 int write_urb_transfer_buffer_length = 8;
212 priv = usb_get_serial_port_data(port);
215 transfer_buffer = kzalloc(transfer_buffer_length,
GFP_KERNEL);
216 if (!transfer_buffer)
221 dev_dbg(dev,
"%s - Allocating port->write_urb\n", __func__);
224 dev_dbg(dev,
"%s - usb_alloc_urb failed\n", __func__);
225 kfree(transfer_buffer);
234 kfree(transfer_buffer);
242 usb_rcvctrlpipe(port->
serial->dev, 0),
248 transfer_buffer_length,
251 dev_dbg(dev,
"%s - Send get_HW_version URB returns: %i\n", __func__, result);
252 dev_dbg(dev,
"Harware version: %i.%i.%i\n", transfer_buffer[0],
253 transfer_buffer[1], transfer_buffer[2]);
257 usb_rcvctrlpipe(port->
serial->dev, 0),
263 transfer_buffer_length,
266 dev_dbg(dev,
"%s - Send get_FW_version URB returns: %i\n", __func__, result);
267 dev_dbg(dev,
"Firmware version: %i.%i.%i\n", transfer_buffer[0],
268 transfer_buffer[1], transfer_buffer[2]);
274 usb_rcvctrlpipe(port->
serial->dev, 0),
284 dev_dbg(dev,
"%s - Send set_baudrate URB returns: %i\n", __func__, result);
288 usb_rcvctrlpipe(port->
serial->dev, 0),
297 dev_dbg(dev,
"%s - Send reset_all_queues URB returns: %i\n", __func__, result);
304 dev_dbg(dev,
"%s - Send read URB returns: %i\n", __func__, result);
307 kfree(transfer_buffer);
325 static void kobil_read_int_callback(
struct urb *
urb)
330 unsigned char *
data = urb->transfer_buffer;
334 dev_dbg(&port->
dev,
"%s - Read int status not zero: %d\n", __func__, status);
339 if (tty && urb->actual_length) {
358 tty_insert_flip_string(tty, data, urb->actual_length);
364 dev_dbg(&port->
dev,
"%s - Send read URB returns: %i\n", __func__, result);
368 static void kobil_write_callback(
struct urb *purb)
374 const unsigned char *
buf,
int count)
382 dev_dbg(&port->
dev,
"%s - write request of 0 bytes\n", __func__);
386 priv = usb_get_serial_port_data(port);
389 dev_dbg(&port->
dev,
"%s - Error: write request bigger than buffer size\n", __func__);
395 usb_serial_debug_data(&port->
dev, __func__, count, priv->
buf + priv->
filled);
411 length = (todo < 8) ? todo : 8;
417 usb_sndintpipe(port->
serial->dev,
421 kobil_write_callback,
428 dev_dbg(&port->
dev,
"%s - Send write URB returns: %i\n", __func__, result);
443 dev_dbg(&port->
dev,
"%s - Send read URB returns: %i\n", __func__, result);
450 static int kobil_write_room(
struct tty_struct *tty)
457 static int kobil_tiocmget(
struct tty_struct *tty)
463 int transfer_buffer_length = 8;
465 priv = usb_get_serial_port_data(port);
473 transfer_buffer = kzalloc(transfer_buffer_length,
GFP_KERNEL);
474 if (!transfer_buffer)
478 usb_rcvctrlpipe(port->
serial->dev, 0),
484 transfer_buffer_length,
487 dev_dbg(&port->
dev,
"%s - Send get_status_line_state URB returns: %i. Statusline: %02x\n",
488 __func__, result, transfer_buffer[0]);
493 kfree(transfer_buffer);
497 static int kobil_tiocmset(
struct tty_struct *tty,
498 unsigned int set,
unsigned int clear)
507 int transfer_buffer_length = 8;
510 priv = usb_get_serial_port_data(port);
518 transfer_buffer = kzalloc(transfer_buffer_length,
GFP_KERNEL);
519 if (!transfer_buffer)
533 dev_dbg(dev,
"%s - Setting DTR\n", __func__);
535 dev_dbg(dev,
"%s - Clearing DTR\n", __func__);
537 usb_rcvctrlpipe(port->
serial->dev, 0),
547 dev_dbg(dev,
"%s - Setting RTS\n", __func__);
549 dev_dbg(dev,
"%s - Clearing RTS\n", __func__);
551 usb_rcvctrlpipe(port->
serial->dev, 0),
560 dev_dbg(dev,
"%s - Send set_status_line URB returns: %i\n", __func__, result);
561 kfree(transfer_buffer);
562 return (result < 0) ? result : 0;
565 static void kobil_set_termios(
struct tty_struct *tty,
570 unsigned short urb_val = 0;
571 int c_cflag = tty->termios.c_cflag;
574 priv = usb_get_serial_port_data(port);
602 tty->termios.c_cflag &= ~
CMSPAR;
606 usb_rcvctrlpipe(port->
serial->dev, 0),
617 static int kobil_ioctl(
struct tty_struct *tty,
618 unsigned int cmd,
unsigned long arg)
623 int transfer_buffer_length = 8;
634 if (!transfer_buffer)
638 usb_rcvctrlpipe(port->
serial->dev, 0),
649 "%s - Send reset_all_queues (FLUSH) URB returns: %i", __func__, result);
650 kfree(transfer_buffer);
651 return (result < 0) ? -
EIO: 0;