fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / serial / kobil_sct.c
index b479916..62bea0c 100644 (file)
@@ -35,7 +35,6 @@
  */
 
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -47,8 +46,8 @@
 #include <linux/spinlock.h>
 #include <asm/uaccess.h>
 #include <linux/usb.h>
+#include <linux/usb/serial.h>
 #include <linux/ioctl.h>
-#include "usb-serial.h"
 #include "kobil_sct.h"
 
 static int debug;
@@ -73,7 +72,7 @@ static int  kobil_startup (struct usb_serial *serial);
 static void kobil_shutdown (struct usb_serial *serial);
 static int  kobil_open (struct usb_serial_port *port, struct file *filp);
 static void kobil_close (struct usb_serial_port *port, struct file *filp);
-static int  kobil_write (struct usb_serial_port *port, int from_user, 
+static int  kobil_write (struct usb_serial_port *port, 
                         const unsigned char *buf, int count);
 static int  kobil_write_room(struct usb_serial_port *port);
 static int  kobil_ioctl(struct usb_serial_port *port, struct file *file,
@@ -81,8 +80,8 @@ static int  kobil_ioctl(struct usb_serial_port *port, struct file *file,
 static int  kobil_tiocmget(struct usb_serial_port *port, struct file *file);
 static int  kobil_tiocmset(struct usb_serial_port *port, struct file *file,
                           unsigned int set, unsigned int clear);
-static void kobil_read_int_callback( struct urb *urb, struct pt_regs *regs );
-static void kobil_write_callback( struct urb *purb, struct pt_regs *regs );
+static void kobil_read_int_callback( struct urb *urb );
+static void kobil_write_callback( struct urb *purb );
 
 
 static struct usb_device_id id_table [] = {
@@ -97,17 +96,20 @@ static struct usb_device_id id_table [] = {
 MODULE_DEVICE_TABLE (usb, id_table);
 
 static struct usb_driver kobil_driver = {
-       .owner =        THIS_MODULE,
        .name =         "kobil",
        .probe =        usb_serial_probe,
        .disconnect =   usb_serial_disconnect,
        .id_table =     id_table,
+       .no_dynamic_id =        1,
 };
 
 
-static struct usb_serial_device_type kobil_device = {
-       .owner =                THIS_MODULE,
-       .name =                 "KOBIL USB smart card terminal",
+static struct usb_serial_driver kobil_device = {
+       .driver = {
+               .owner =        THIS_MODULE,
+               .name =         "kobil",
+       },
+       .description =          "KOBIL USB smart card terminal",
        .id_table =             id_table,
        .num_interrupt_in =     NUM_DONT_CARE,
        .num_bulk_in =          0,
@@ -134,7 +136,7 @@ struct kobil_private {
        int cur_pos; // index of the next char to send in buf
        __u16 device_type;
        int line_state;
-       struct termios internal_termios;
+       struct ktermios internal_termios;
 };
 
 
@@ -155,7 +157,7 @@ static int kobil_startup (struct usb_serial *serial)
 
        priv->filled = 0;
        priv->cur_pos = 0;
-       priv->device_type = serial->product;
+       priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
        priv->line_state = 0;
 
        switch (priv->device_type){
@@ -183,13 +185,11 @@ static int kobil_startup (struct usb_serial *serial)
   
        for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
                endpoint = &altsetting->endpoint[i];
-               if (((endpoint->desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && 
-                   ((endpoint->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
+               if (usb_endpoint_is_int_out(&endpoint->desc)) {
                        dbg("%s Found interrupt out endpoint. Address: %d", __FUNCTION__, endpoint->desc.bEndpointAddress);
                        priv->write_int_endpoint_address = endpoint->desc.bEndpointAddress;
                }
-               if (((endpoint->desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && 
-                   ((endpoint->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
+               if (usb_endpoint_is_int_in(&endpoint->desc)) {
                        dbg("%s Found interrupt in  endpoint. Address: %d", __FUNCTION__, endpoint->desc.bEndpointAddress);
                        priv->read_int_endpoint_address = endpoint->desc.bEndpointAddress;
                }
@@ -252,11 +252,9 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
        }
        
        // allocate memory for transfer buffer
-       transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL);  
+       transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
        if (! transfer_buffer) {
                return -ENOMEM;
-       } else {
-               memset(transfer_buffer, 0, transfer_buffer_length);
        }
        
        // allocate write_urb
@@ -271,7 +269,7 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
        }
 
        // allocate memory for write_urb transfer buffer
-       port->write_urb->transfer_buffer = (unsigned char *) kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL);
+       port->write_urb->transfer_buffer = kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL);
        if (! port->write_urb->transfer_buffer) {
                kfree(transfer_buffer);
                usb_free_urb(port->write_urb);
@@ -350,20 +348,17 @@ static void kobil_close (struct usb_serial_port *port, struct file *filp)
 {
        dbg("%s - port %d", __FUNCTION__, port->number);
 
-       if (port->write_urb){
-               usb_unlink_urb( port->write_urb );
+       if (port->write_urb) {
+               usb_kill_urb(port->write_urb);
                usb_free_urb( port->write_urb );
                port->write_urb = NULL;
        }
-       if (port->interrupt_in_urb){
-               usb_unlink_urb (port->interrupt_in_urb);
-       }
+       usb_kill_urb(port->interrupt_in_urb);
 }
 
 
-static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs)
+static void kobil_read_int_callback( struct urb *purb)
 {
-       int i;
        int result;
        struct usb_serial_port *port = (struct usb_serial_port *) purb->context;
        struct tty_struct *tty;
@@ -382,11 +377,10 @@ static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs)
                
                // BEGIN DEBUG
                /*
-                 dbg_data = (unsigned char *) kmalloc((3 *  purb->actual_length + 10) * sizeof(char), GFP_KERNEL);
+                 dbg_data = kzalloc((3 *  purb->actual_length + 10) * sizeof(char), GFP_KERNEL);
                  if (! dbg_data) {
                  return;
                  }
-                 memset(dbg_data, 0, (3 *  purb->actual_length + 10));
                  for (i = 0; i < purb->actual_length; i++) { 
                  sprintf(dbg_data +3*i, "%02X ", data[i]); 
                  }
@@ -395,14 +389,8 @@ static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs)
                */
                // END DEBUG
 
-               for (i = 0; i < purb->actual_length; ++i) {
-                       // if we insert more than TTY_FLIPBUF_SIZE characters, we drop them.
-                       if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-                               tty_flip_buffer_push(tty);
-                       }
-                       // this doesn't actually push the data through unless tty->low_latency is set
-                       tty_insert_flip_char(tty, data[i], 0);
-               }
+               tty_buffer_request_room(tty, purb->actual_length);
+               tty_insert_flip_string(tty, data, purb->actual_length);
                tty_flip_buffer_push(tty);
        }
 
@@ -414,12 +402,12 @@ static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs)
 }
 
 
-static void kobil_write_callback( struct urb *purb, struct pt_regs *regs )
+static void kobil_write_callback( struct urb *purb )
 {
 }
 
 
-static int kobil_write (struct usb_serial_port *port, int from_user, 
+static int kobil_write (struct usb_serial_port *port, 
                        const unsigned char *buf, int count)
 {
        int length = 0;
@@ -440,13 +428,7 @@ static int kobil_write (struct usb_serial_port *port, int from_user,
        }
 
        // Copy data to buffer
-       if (from_user) {
-               if (copy_from_user(priv->buf + priv->filled, buf, count)) {
-                       return -EFAULT;
-               }
-       } else {
-               memcpy (priv->buf + priv->filled, buf, count);
-       }
+       memcpy (priv->buf + priv->filled, buf, count);
 
        usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, priv->buf + priv->filled);
 
@@ -458,9 +440,8 @@ static int kobil_write (struct usb_serial_port *port, int from_user,
             ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4))) ) {
                
                // stop reading (except TWIN and KAAN SIM)
-               if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) ) {
-                       usb_unlink_urb( port->interrupt_in_urb );
-               }
+               if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) )
+                       usb_kill_urb(port->interrupt_in_urb);
 
                todo = priv->filled - priv->cur_pos;
 
@@ -530,11 +511,10 @@ static int kobil_tiocmget(struct usb_serial_port *port, struct file *file)
        }
 
        // allocate memory for transfer buffer
-       transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL);  
+       transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
        if (!transfer_buffer) {
                return -ENOMEM;
        }
-       memset(transfer_buffer, 0, transfer_buffer_length);
 
        result = usb_control_msg( port->serial->dev, 
                                  usb_rcvctrlpipe(port->serial->dev, 0 ), 
@@ -576,11 +556,10 @@ static int  kobil_tiocmset(struct usb_serial_port *port, struct file *file,
        }
 
        // allocate memory for transfer buffer
-       transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL);
+       transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
        if (! transfer_buffer) {
                return -ENOMEM;
        }
-       memset(transfer_buffer, 0, transfer_buffer_length);
 
        if (set & TIOCM_RTS)
                rts = 1;
@@ -645,12 +624,11 @@ static int  kobil_ioctl(struct usb_serial_port *port, struct file *file,
 
        switch (cmd) {
        case TCGETS:   // 0x5401
-               result = verify_area(VERIFY_WRITE, user_arg, sizeof(struct termios));
-               if (result) {
-                       dbg("%s - port %d Error in verify_area", __FUNCTION__, port->number);
-                       return(result);
+               if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct ktermios))) {
+                       dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number);
+                       return -EFAULT;
                }
-               if (kernel_termios_to_user_termios((struct termios __user *)arg,
+               if (kernel_termios_to_user_termios((struct ktermios __user *)arg,
                                                   &priv->internal_termios))
                        return -EFAULT;
                return 0;
@@ -660,20 +638,18 @@ static int  kobil_ioctl(struct usb_serial_port *port, struct file *file,
                        dbg("%s - port %d Error: port->tty->termios is NULL", __FUNCTION__, port->number);
                        return -ENOTTY;
                }
-               result = verify_area(VERIFY_READ, user_arg, sizeof(struct termios));
-               if (result) {
-                       dbg("%s - port %d Error in verify_area", __FUNCTION__, port->number);
-                       return result;
+               if (!access_ok(VERIFY_READ, user_arg, sizeof(struct ktermios))) {
+                       dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number);
+                       return -EFAULT;
                }
                if (user_termios_to_kernel_termios(&priv->internal_termios,
-                                                  (struct termios __user *)arg))
+                                                  (struct ktermios __user *)arg))
                        return -EFAULT;
                
-               settings = (unsigned char *) kmalloc(50, GFP_KERNEL);  
+               settings = kzalloc(50, GFP_KERNEL);
                if (! settings) {
                        return -ENOBUFS;
                }
-               memset(settings, 0, 50);
 
                switch (priv->internal_termios.c_cflag & CBAUD) {
                case B1200:
@@ -720,7 +696,7 @@ static int  kobil_ioctl(struct usb_serial_port *port, struct file *file,
                return 0;
 
        case TCFLSH:   // 0x540B
-               transfer_buffer = (unsigned char *) kmalloc(transfer_buffer_length, GFP_KERNEL);
+               transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
                if (! transfer_buffer) {
                        return -ENOBUFS;
                }