31 #include <linux/kernel.h>
32 #include <linux/errno.h>
34 #include <linux/slab.h>
35 #include <linux/tty.h>
38 #include <linux/module.h>
44 #define CYBERJACK_LOCAL_BUF_SIZE 32
49 #define DRIVER_VERSION "v1.01"
50 #define DRIVER_AUTHOR "Matthias Bruestle"
51 #define DRIVER_DESC "REINER SCT cyberJack pinpad/e-com USB Chipcard Reader Driver"
54 #define CYBERJACK_VENDOR_ID 0x0C4B
55 #define CYBERJACK_PRODUCT_ID 0x0100
61 static int cyberjack_open(
struct tty_struct *tty,
64 static int cyberjack_write(
struct tty_struct *tty,
66 static int cyberjack_write_room(
struct tty_struct *tty);
67 static void cyberjack_read_int_callback(
struct urb *
urb);
68 static void cyberjack_read_bulk_callback(
struct urb *
urb);
69 static void cyberjack_write_bulk_callback(
struct urb *
urb);
83 .description =
"Reiner SCT Cyberjack USB card reader",
86 .disconnect = cyberjack_disconnect,
87 .port_probe = cyberjack_port_probe,
88 .port_remove = cyberjack_port_remove,
89 .open = cyberjack_open,
90 .close = cyberjack_close,
91 .write = cyberjack_write,
92 .write_room = cyberjack_write_room,
93 .read_int_callback = cyberjack_read_int_callback,
94 .read_bulk_callback = cyberjack_read_bulk_callback,
95 .write_bulk_callback = cyberjack_write_bulk_callback,
99 &cyberjack_device,
NULL
124 usb_set_serial_port_data(port, priv);
128 dev_err(&port->
dev,
"usb_submit_urb(read int) failed\n");
137 priv = usb_get_serial_port_data(port);
151 static int cyberjack_open(
struct tty_struct *tty,
158 dev_dbg(&port->
dev,
"%s - usb_clear_halt\n", __func__);
161 priv = usb_get_serial_port_data(port);
166 spin_unlock_irqrestore(&priv->
lock, flags);
180 static int cyberjack_write(
struct tty_struct *tty,
190 dev_dbg(dev,
"%s - write request of 0 bytes\n", __func__);
195 dev_dbg(dev,
"%s - already writing\n", __func__);
204 spin_unlock_irqrestore(&priv->
lock, flags);
212 usb_serial_debug_data(dev, __func__, count, priv->
wrbuf + priv->
wrfilled);
217 dev_dbg(dev,
"%s - expected data: %d\n", __func__, wrexpected);
219 wrexpected =
sizeof(priv->
wrbuf);
225 dev_dbg(dev,
"%s - transmitting data (frame 1)\n", __func__);
239 "%s - failed submitting write urb, error %d",
244 spin_unlock_irqrestore(&priv->
lock, flags);
249 dev_dbg(dev,
"%s - priv->wrsent=%d\n", __func__, priv->
wrsent);
253 dev_dbg(dev,
"%s - buffer cleaned\n", __func__);
260 spin_unlock_irqrestore(&priv->
lock, flags);
265 static int cyberjack_write_room(
struct tty_struct *tty)
271 static void cyberjack_read_int_callback(
struct urb *
urb)
276 unsigned char *
data = urb->transfer_buffer;
284 usb_serial_debug_data(dev, __func__, urb->actual_length, data);
287 if (urb->actual_length == 4 && data[0] == 0x01) {
291 unsigned short size = ((
unsigned short)data[3]<<8)+data[2]+3;
293 spin_lock(&priv->
lock);
295 old_rdtodo = priv->
rdtodo;
297 if (old_rdtodo + size < old_rdtodo) {
298 dev_dbg(dev,
"To many bulk_in urbs to do.\n");
299 spin_unlock(&priv->
lock);
308 spin_unlock(&priv->
lock);
313 dev_err(dev,
"%s - failed resubmitting read urb, error %d\n",
315 dev_dbg(dev,
"%s - usb_submit_urb(read urb)\n", __func__);
322 dev_err(&port->
dev,
"usb_submit_urb(read int) failed\n");
323 dev_dbg(dev,
"%s - usb_submit_urb(int urb)\n", __func__);
326 static void cyberjack_read_bulk_callback(
struct urb *urb)
332 unsigned char *data = urb->transfer_buffer;
335 int status = urb->status;
337 usb_serial_debug_data(dev, __func__, urb->actual_length, data);
339 dev_dbg(dev,
"%s - nonzero read bulk status received: %d\n",
346 dev_dbg(dev,
"%s - ignoring since device not open\n", __func__);
349 if (urb->actual_length) {
350 tty_insert_flip_string(tty, data, urb->actual_length);
355 spin_lock(&priv->
lock);
358 priv->
rdtodo -= urb->actual_length;
364 spin_unlock(&priv->
lock);
366 dev_dbg(dev,
"%s - rdtodo: %d\n", __func__, todo);
372 dev_err(dev,
"%s - failed resubmitting read urb, error %d\n",
374 dev_dbg(dev,
"%s - usb_submit_urb(read urb)\n", __func__);
378 static void cyberjack_write_bulk_callback(
struct urb *urb)
383 int status = urb->status;
387 dev_dbg(dev,
"%s - nonzero write bulk status received: %d\n",
392 spin_lock(&priv->
lock);
398 dev_dbg(dev,
"%s - transmitting data (frame n)\n", __func__);
413 dev_err(dev,
"%s - failed submitting write urb, error %d\n",
421 dev_dbg(dev,
"%s - priv->wrsent=%d\n", __func__, priv->
wrsent);
427 priv->
wrsent >= blksize) {
428 dev_dbg(dev,
"%s - buffer cleaned\n", __func__);
436 spin_unlock(&priv->
lock);