On Wed, Jan 12, 2005 at 09:08:19PM +0100, Florian Echtler wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> This patch adds a new usb-misc driver for the fingerprint sensor that
> can be found in the Siemens ID Mouse USB. "cat /dev/usb/idmouseX"
> yields a 225x288 greyscale PNM with the fingerprint information.
Can't this driver be done successfully in userspace using usbfs/libusb?
Or is there some requirement for it to be in the kernel that I missed?
> --- linux-2.6.10-orig/drivers/usb/misc/idmouse.c 1970-01-01
> 01:00:00.000000000 +0100
> +++ linux-2.6.10/drivers/usb/misc/idmouse.c 2005-01-12 17:44:07.514419240
> +0100
> @@ -0,0 +1,441 @@
> +/* Siemens ID Mouse driver v0.5
> +
> + This file is licensed under the GNU Public License.
Which version?
> + Authors: Florian 'Floe' Echtler <[EMAIL PROTECTED]>
> + Andreas 'ad' Deresch <[EMAIL PROTECTED]>
No copyright notice? No "based on file foo..." comment?
> +/* structure to hold all of our device specific stuff */
> +struct usb_idmouse {
> +
> + struct usb_device *udev; /* save off the usb device pointer */
> + struct usb_interface *interface; /* the interface for this
> device */
> +
> + unsigned char minor; /* starting minor number for this device */
You don't need to save this, as it's always available in your interface,
and you never use it in your code :)
> +static int idmouse_open(struct inode *inode, struct file *file)
> +{
> + struct usb_idmouse *dev = NULL;
> + struct usb_interface *interface;
> + int result = 0;
> +
> + /* prevent disconnects */
> + down(&disconnect_sem);
> +
> + /* get the interface from minor number and driver information */
> + interface = usb_find_interface (&idmouse_driver, iminor (inode));
> + if (!interface) {
> + up(&disconnect_sem);
> + return -ENODEV;
> + }
> + /* get the device information block from the interface */
> + dev = usb_get_intfdata(interface);
> + if (!dev) {
> + up(&disconnect_sem);
> + return -ENODEV;
> + }
> +
> + /* lock this device */
> + down(&dev->sem);
> +
> + /* check if already open */
> + if (dev->open) {
> +
> + /* already open, so fail */
> + result = -EBUSY;
> +
> + } else {
> +
> + /* create a new image and check for success */
> + result = idmouse_create_image (dev);
> + if (result)
> + goto error;
> +
> + /* increment our usage count for the driver */
> + ++dev->open;
> +
> + /* save our object in the file's private structure */
> + file->private_data = dev;
> +
> + }
Wrong indentation here.
> +
> +error:
> +
> + /* unlock this device */
> + up(&dev->sem);
> +
> + /* unlock the disconnect semaphore */
> + up(&disconnect_sem);
> + return result;
> +}
> +
> +static int idmouse_release(struct inode *inode, struct file *file)
> +{
> + struct usb_idmouse *dev;
> +
> + /* prevent a race condition with open() */
> + down(&disconnect_sem);
> +
> + dev = (struct usb_idmouse *) file->private_data;
> +
> + if (dev == NULL) {
> + up(&disconnect_sem);
> + return -ENODEV;
> + }
> +
> + /* lock our device */
> + down(&dev->sem);
> +
> + /* are we really open? */
> + if (dev->open <= 0) {
> + up(&dev->sem);
> + up(&disconnect_sem);
> + return -ENODEV;
> + }
> +
> + --dev->open;
> +
> + if (!dev->present) {
> + /* the device was unplugged before the file was released */
> + up(&dev->sem);
> + idmouse_delete(dev);
> + up(&disconnect_sem);
> + return 0;
> + }
> +
> + up(&dev->sem);
> + up(&disconnect_sem);
> + return 0;
Mix up of tabs and spaces.
> +static int idmouse_probe(struct usb_interface *interface,
> + const struct usb_device_id *id)
> +{
> + struct usb_device *udev = interface_to_usbdev(interface);
> + struct usb_idmouse *dev = NULL;
> + struct usb_host_interface *iface_desc;
> + struct usb_endpoint_descriptor *endpoint;
> + size_t buffer_size;
> + int result;
> +
> + /* check if we have gotten the data or the hid interface */
> + iface_desc = &interface->altsetting[0];
> + if (iface_desc->desc.bInterfaceClass != 0x0A)
> + return -ENODEV;
> +
> + /* allocate memory for our device state and initialize it */
> + dev = kmalloc(sizeof(*dev), GFP_KERNEL);
> + if (dev == NULL)
> + return -ENOMEM;
> + memset(dev, 0x00, sizeof(*dev));
> +
> + init_MUTEX(&dev->sem);
> + dev->udev = udev;
> + dev->interface = interface;
> +
> + /* set up the endpoint information - use only the first bulk-in
> endpoint */
> + endpoint = &iface_desc->endpoint[0].desc;
> + if (!dev->bulk_in_endpointAddr
> + && (endpoint->bEndpointAddress & USB_DIR_IN)
> + && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> + USB_ENDPOINT_XFER_BULK)) {
> +
> + /* we found a bulk in endpoint */
> + buffer_size = endpoint->wMaxPacketSize;
> + dev->bulk_in_size = buffer_size;
> + dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
> + dev->bulk_in_buffer =
> + kmalloc(IMGSIZE + buffer_size, GFP_KERNEL);
> +
> + if (!dev->bulk_in_buffer) {
> + err("Unable to allocate input buffer.");
> + idmouse_delete(dev);
> + return -ENOMEM;
> + }
> + }
> +
> + if (!(dev->bulk_in_endpointAddr)) {
> + err("Unable to find bulk-in endpoint.");
> + idmouse_delete(dev);
> + return -ENODEV;
> + }
> + /* allow device read, write and ioctl */
> + dev->present = 1;
> +
> + /* we can register the device now, as it is ready */
> + usb_set_intfdata(interface, dev);
> + result = usb_register_dev(interface, &idmouse_class);
> + if (result) {
> + /* something prevented us from registering this device */
> + err("Unble to allocate minor number.");
> + usb_set_intfdata(interface, NULL);
> + idmouse_delete(dev);
> + return result;
> + }
> + /* save the minor number */
> + dev->minor = interface->minor;
> +
> + /* be noisy */
> + info("%s attached to /dev/idmouse%d",
> + DRIVER_DESC,(dev->minor)-USB_IDMOUSE_MINOR_BASE);
Can you use dev_info() here? It's more descriptive. Also, if
CONFIG_USB_DYNAMIC_MINORS is set, this number will print out negative,
which I don't think you want.
And wrong tab usage.
thanks,
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel