28 #include <linux/poll.h>
29 #include <linux/slab.h>
30 #include <linux/module.h>
32 #include <linux/input.h>
34 #include <linux/hid.h>
35 #include <linux/hiddev.h>
40 #ifdef CONFIG_USB_DYNAMIC_MINORS
41 #define HIDDEV_MINOR_BASE 0
42 #define HIDDEV_MINORS 256
44 #define HIDDEV_MINOR_BASE 96
45 #define HIDDEV_MINORS 16
47 #define HIDDEV_BUFFER_SIZE 2048
110 list = report->
list.next;
145 for (i = 0; i < report->
maxfield; i++) {
147 for (j = 0; j < field->
maxusage; j++) {
161 static void hiddev_send_event(
struct hid_device *hid,
178 spin_unlock_irqrestore(&hiddev->
list_lock, flags);
203 hiddev_send_event(hid, &uref);
212 memset(&uref, 0,
sizeof(uref));
220 hiddev_send_event(hid, &uref);
226 static int hiddev_fasync(
int fd,
struct file *
file,
int on)
244 spin_unlock_irqrestore(&list->
hiddev->list_lock, flags);
247 if (!--list->
hiddev->open) {
248 if (list->
hiddev->exist) {
268 static int hiddev_open(
struct inode *inode,
struct file *file)
273 struct hiddev *hiddev;
279 hid = usb_get_intfdata(intf);
292 if (list->
hiddev->exist) {
293 if (!list->
hiddev->open++) {
305 spin_lock_irq(&list->
hiddev->list_lock);
307 spin_unlock_irq(&list->
hiddev->list_lock);
310 if (!list->
hiddev->open++)
311 if (list->
hiddev->exist) {
333 static ssize_t hiddev_write(
struct file * file,
const char __user *
buffer,
size_t count, loff_t *ppos)
341 static ssize_t hiddev_read(
struct file * file,
char __user *
buffer,
size_t count, loff_t *ppos)
351 if (count < event_size)
355 retval = mutex_lock_interruptible(&list->thread_lock);
359 while (retval == 0) {
372 if (!list->
hiddev->exist) {
397 retval + event_size <= count) {
402 event.hid = list->
buffer[list->
tail].usage_code;
434 static unsigned int hiddev_poll(
struct file *file,
poll_table *
wait)
438 poll_wait(file, &list->
hiddev->wait, wait);
449 static noinline int hiddev_ioctl_usage(
struct hiddev *hiddev,
unsigned int cmd,
void __user *user_arg)
462 uref = &uref_multi->
uref;
465 sizeof(*uref_multi)))
476 if ((report = hiddev_lookup_report(hid, &rinfo)) ==
NULL)
500 field = hiddev_lookup_usage(hid, uref);
506 if ((report = hiddev_lookup_report(hid, &rinfo)) ==
NULL)
546 sizeof(*uref_multi)))
568 static noinline int hiddev_ioctl_string(
struct hiddev *hiddev,
unsigned int cmd,
void __user *user_arg)
575 if (
get_user(idx, (
int __user *)user_arg))
596 static long hiddev_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
599 struct hiddev *hiddev = list->
hiddev;
613 if (!hiddev->
exist) {
636 if (i < hid->maxcollection)
645 memset(&dinfo, 0,
sizeof(dinfo));
648 dinfo.busnum = dev->bus->busnum;
649 dinfo.devnum = dev->devnum;
650 dinfo.ifnum = usbhid->
ifnum;
651 dinfo.vendor =
le16_to_cpu(dev->descriptor.idVendor);
652 dinfo.product =
le16_to_cpu(dev->descriptor.idProduct);
653 dinfo.version =
le16_to_cpu(dev->descriptor.bcdDevice);
670 if (
get_user(newflags, (
int __user *)arg)) {
680 list->
flags = newflags;
687 r = hiddev_ioctl_string(hiddev, cmd, user_arg);
704 report = hiddev_lookup_report(hid, &rinfo);
723 report = hiddev_lookup_report(hid, &rinfo);
739 report = hiddev_lookup_report(hid, &rinfo);
758 report = hiddev_lookup_report(hid, &rinfo);
762 if (finfo.field_index >= report->
maxfield)
765 field = report->
field[finfo.field_index];
766 memset(&finfo, 0,
sizeof(finfo));
771 finfo.flags = field->
flags;
773 finfo.logical = field->
logical;
780 finfo.unit = field->
unit;
793 r = hiddev_ioctl_usage(hiddev, cmd, user_arg);
805 cinfo.type = hid->
collection[cinfo.index].type;
806 cinfo.usage = hid->
collection[cinfo.index].usage;
807 cinfo.level = hid->
collection[cinfo.index].level;
842 static long hiddev_compat_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
844 return hiddev_ioctl(file, cmd, (
unsigned long)compat_ptr(arg));
851 .write = hiddev_write,
854 .release = hiddev_release,
855 .unlocked_ioctl = hiddev_ioctl,
856 .fasync = hiddev_fasync,
858 .compat_ioctl = hiddev_compat_ioctl,
868 static struct usb_class_driver hiddev_class = {
870 .devnode = hiddev_devnode,
871 .fops = &hiddev_fops,
880 struct hiddev *hiddev;
896 if (!(hiddev = kzalloc(
sizeof(
struct hiddev),
GFP_KERNEL)))
900 INIT_LIST_HEAD(&hiddev->
list);
908 hid_err(hid,
"Not able to get a minor for this device\n");
920 static struct usb_class_driver hiddev_class;
923 struct hiddev *hiddev = hid->
hiddev;