Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001 Paul Stewart |
| 3 | * Copyright (c) 2001 Vojtech Pavlik |
| 4 | * |
| 5 | * HID char devices, giving access to raw HID device events. |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * Should you need to contact me, the author, you can do so either by |
| 25 | * e-mail - mail your message to Paul Stewart <stewart@wetlogic.net> |
| 26 | */ |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/poll.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/smp_lock.h> |
| 33 | #include <linux/input.h> |
| 34 | #include <linux/usb.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 35 | #include <linux/hid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/hiddev.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 37 | #include "usbhid.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #ifdef CONFIG_USB_DYNAMIC_MINORS |
| 40 | #define HIDDEV_MINOR_BASE 0 |
| 41 | #define HIDDEV_MINORS 256 |
| 42 | #else |
| 43 | #define HIDDEV_MINOR_BASE 96 |
| 44 | #define HIDDEV_MINORS 16 |
| 45 | #endif |
| 46 | #define HIDDEV_BUFFER_SIZE 64 |
| 47 | |
| 48 | struct hiddev { |
| 49 | int exist; |
| 50 | int open; |
| 51 | wait_queue_head_t wait; |
| 52 | struct hid_device *hid; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 53 | struct list_head list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | struct hiddev_list { |
| 57 | struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE]; |
| 58 | int head; |
| 59 | int tail; |
| 60 | unsigned flags; |
| 61 | struct fasync_struct *fasync; |
| 62 | struct hiddev *hiddev; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 63 | struct list_head node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static struct hiddev *hiddev_table[HIDDEV_MINORS]; |
| 67 | |
| 68 | /* |
| 69 | * Find a report, given the report's type and ID. The ID can be specified |
| 70 | * indirectly by REPORT_ID_FIRST (which returns the first report of the given |
| 71 | * type) or by (REPORT_ID_NEXT | old_id), which returns the next report of the |
| 72 | * given type which follows old_id. |
| 73 | */ |
| 74 | static struct hid_report * |
| 75 | hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo) |
| 76 | { |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 77 | unsigned int flags = rinfo->report_id & ~HID_REPORT_ID_MASK; |
| 78 | unsigned int rid = rinfo->report_id & HID_REPORT_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | struct hid_report_enum *report_enum; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 80 | struct hid_report *report; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct list_head *list; |
| 82 | |
| 83 | if (rinfo->report_type < HID_REPORT_TYPE_MIN || |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 84 | rinfo->report_type > HID_REPORT_TYPE_MAX) |
| 85 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | report_enum = hid->report_enum + |
| 88 | (rinfo->report_type - HID_REPORT_TYPE_MIN); |
| 89 | |
| 90 | switch (flags) { |
| 91 | case 0: /* Nothing to do -- report_id is already set correctly */ |
| 92 | break; |
| 93 | |
| 94 | case HID_REPORT_ID_FIRST: |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 95 | if (list_empty(&report_enum->report_list)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return NULL; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 97 | |
| 98 | list = report_enum->report_list.next; |
| 99 | report = list_entry(list, struct hid_report, list); |
| 100 | rinfo->report_id = report->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | break; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | case HID_REPORT_ID_NEXT: |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 104 | report = report_enum->report_id_hash[rid]; |
| 105 | if (!report) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return NULL; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 107 | |
| 108 | list = report->list.next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (list == &report_enum->report_list) |
| 110 | return NULL; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 111 | |
| 112 | report = list_entry(list, struct hid_report, list); |
| 113 | rinfo->report_id = report->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | break; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | default: |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | return report_enum->report_id_hash[rinfo->report_id]; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * Perform an exhaustive search of the report table for a usage, given its |
| 125 | * type and usage id. |
| 126 | */ |
| 127 | static struct hid_field * |
| 128 | hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref) |
| 129 | { |
| 130 | int i, j; |
| 131 | struct hid_report *report; |
| 132 | struct hid_report_enum *report_enum; |
| 133 | struct hid_field *field; |
| 134 | |
| 135 | if (uref->report_type < HID_REPORT_TYPE_MIN || |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 136 | uref->report_type > HID_REPORT_TYPE_MAX) |
| 137 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | report_enum = hid->report_enum + |
| 140 | (uref->report_type - HID_REPORT_TYPE_MIN); |
| 141 | |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 142 | list_for_each_entry(report, &report_enum->report_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | for (i = 0; i < report->maxfield; i++) { |
| 144 | field = report->field[i]; |
| 145 | for (j = 0; j < field->maxusage; j++) { |
| 146 | if (field->usage[j].hid == uref->usage_code) { |
| 147 | uref->report_id = report->id; |
| 148 | uref->field_index = i; |
| 149 | uref->usage_index = j; |
| 150 | return field; |
| 151 | } |
| 152 | } |
| 153 | } |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | return NULL; |
| 157 | } |
| 158 | |
| 159 | static void hiddev_send_event(struct hid_device *hid, |
| 160 | struct hiddev_usage_ref *uref) |
| 161 | { |
| 162 | struct hiddev *hiddev = hid->hiddev; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 163 | struct hiddev_list *list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 165 | list_for_each_entry(list, &hiddev->list, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | if (uref->field_index != HID_FIELD_INDEX_NONE || |
| 167 | (list->flags & HIDDEV_FLAG_REPORT) != 0) { |
| 168 | list->buffer[list->head] = *uref; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 169 | list->head = (list->head + 1) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | (HIDDEV_BUFFER_SIZE - 1); |
| 171 | kill_fasync(&list->fasync, SIGIO, POLL_IN); |
| 172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | wake_up_interruptible(&hiddev->wait); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * This is where hid.c calls into hiddev to pass an event that occurred over |
| 180 | * the interrupt pipe |
| 181 | */ |
| 182 | void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 183 | struct hid_usage *usage, __s32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | unsigned type = field->report_type; |
| 186 | struct hiddev_usage_ref uref; |
| 187 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 188 | uref.report_type = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 190 | ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 191 | ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | uref.report_id = field->report->id; |
| 193 | uref.field_index = field->index; |
| 194 | uref.usage_index = (usage - field->usage); |
| 195 | uref.usage_code = usage->hid; |
| 196 | uref.value = value; |
| 197 | |
| 198 | hiddev_send_event(hid, &uref); |
| 199 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame^] | 200 | EXPORT_SYMBOL_GPL(hiddev_hid_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | void hiddev_report_event(struct hid_device *hid, struct hid_report *report) |
| 203 | { |
| 204 | unsigned type = report->type; |
| 205 | struct hiddev_usage_ref uref; |
| 206 | |
| 207 | memset(&uref, 0, sizeof(uref)); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 208 | uref.report_type = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 210 | ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 211 | ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | uref.report_id = report->id; |
| 213 | uref.field_index = HID_FIELD_INDEX_NONE; |
| 214 | |
| 215 | hiddev_send_event(hid, &uref); |
| 216 | } |
| 217 | /* |
| 218 | * fasync file op |
| 219 | */ |
| 220 | static int hiddev_fasync(int fd, struct file *file, int on) |
| 221 | { |
| 222 | int retval; |
| 223 | struct hiddev_list *list = file->private_data; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | retval = fasync_helper(fd, file, on, &list->fasync); |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return retval < 0 ? retval : 0; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /* |
| 232 | * release file op |
| 233 | */ |
| 234 | static int hiddev_release(struct inode * inode, struct file * file) |
| 235 | { |
| 236 | struct hiddev_list *list = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | hiddev_fasync(-1, file, 0); |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 239 | list_del(&list->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | if (!--list->hiddev->open) { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 242 | if (list->hiddev->exist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | hid_close(list->hiddev->hid); |
| 244 | else |
| 245 | kfree(list->hiddev); |
| 246 | } |
| 247 | |
| 248 | kfree(list); |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * open file op |
| 255 | */ |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 256 | static int hiddev_open(struct inode *inode, struct file *file) |
| 257 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct hiddev_list *list; |
| 259 | |
| 260 | int i = iminor(inode) - HIDDEV_MINOR_BASE; |
| 261 | |
| 262 | if (i >= HIDDEV_MINORS || !hiddev_table[i]) |
| 263 | return -ENODEV; |
| 264 | |
Oliver Neukum | bbdb7da | 2006-01-06 20:54:29 +0100 | [diff] [blame] | 265 | if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | list->hiddev = hiddev_table[i]; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 269 | list_add_tail(&list->node, &hiddev_table[i]->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | file->private_data = list; |
| 271 | |
| 272 | if (!list->hiddev->open++) |
| 273 | if (list->hiddev->exist) |
| 274 | hid_open(hiddev_table[i]->hid); |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * "write" file op |
| 281 | */ |
| 282 | static ssize_t hiddev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) |
| 283 | { |
| 284 | return -EINVAL; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * "read" file op |
| 289 | */ |
| 290 | static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) |
| 291 | { |
| 292 | DECLARE_WAITQUEUE(wait, current); |
| 293 | struct hiddev_list *list = file->private_data; |
| 294 | int event_size; |
| 295 | int retval = 0; |
| 296 | |
| 297 | event_size = ((list->flags & HIDDEV_FLAG_UREF) != 0) ? |
| 298 | sizeof(struct hiddev_usage_ref) : sizeof(struct hiddev_event); |
| 299 | |
| 300 | if (count < event_size) |
| 301 | return 0; |
| 302 | |
| 303 | while (retval == 0) { |
| 304 | if (list->head == list->tail) { |
| 305 | add_wait_queue(&list->hiddev->wait, &wait); |
| 306 | set_current_state(TASK_INTERRUPTIBLE); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | while (list->head == list->tail) { |
| 309 | if (file->f_flags & O_NONBLOCK) { |
| 310 | retval = -EAGAIN; |
| 311 | break; |
| 312 | } |
| 313 | if (signal_pending(current)) { |
| 314 | retval = -ERESTARTSYS; |
| 315 | break; |
| 316 | } |
| 317 | if (!list->hiddev->exist) { |
| 318 | retval = -EIO; |
| 319 | break; |
| 320 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | schedule(); |
Micon, David | 48d7055 | 2006-05-20 14:59:59 -0700 | [diff] [blame] | 323 | set_current_state(TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | set_current_state(TASK_RUNNING); |
| 327 | remove_wait_queue(&list->hiddev->wait, &wait); |
| 328 | } |
| 329 | |
| 330 | if (retval) |
| 331 | return retval; |
| 332 | |
| 333 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 334 | while (list->head != list->tail && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | retval + event_size <= count) { |
| 336 | if ((list->flags & HIDDEV_FLAG_UREF) == 0) { |
| 337 | if (list->buffer[list->tail].field_index != |
| 338 | HID_FIELD_INDEX_NONE) { |
| 339 | struct hiddev_event event; |
| 340 | event.hid = list->buffer[list->tail].usage_code; |
| 341 | event.value = list->buffer[list->tail].value; |
| 342 | if (copy_to_user(buffer + retval, &event, sizeof(struct hiddev_event))) |
| 343 | return -EFAULT; |
| 344 | retval += sizeof(struct hiddev_event); |
| 345 | } |
| 346 | } else { |
| 347 | if (list->buffer[list->tail].field_index != HID_FIELD_INDEX_NONE || |
| 348 | (list->flags & HIDDEV_FLAG_REPORT) != 0) { |
| 349 | if (copy_to_user(buffer + retval, list->buffer + list->tail, sizeof(struct hiddev_usage_ref))) |
| 350 | return -EFAULT; |
| 351 | retval += sizeof(struct hiddev_usage_ref); |
| 352 | } |
| 353 | } |
| 354 | list->tail = (list->tail + 1) & (HIDDEV_BUFFER_SIZE - 1); |
| 355 | } |
| 356 | |
| 357 | } |
| 358 | |
| 359 | return retval; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * "poll" file op |
| 364 | * No kernel lock - fine |
| 365 | */ |
| 366 | static unsigned int hiddev_poll(struct file *file, poll_table *wait) |
| 367 | { |
| 368 | struct hiddev_list *list = file->private_data; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | poll_wait(file, &list->hiddev->wait, wait); |
| 371 | if (list->head != list->tail) |
| 372 | return POLLIN | POLLRDNORM; |
| 373 | if (!list->hiddev->exist) |
| 374 | return POLLERR | POLLHUP; |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * "ioctl" file op |
| 380 | */ |
| 381 | static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) |
| 382 | { |
| 383 | struct hiddev_list *list = file->private_data; |
| 384 | struct hiddev *hiddev = list->hiddev; |
| 385 | struct hid_device *hid = hiddev->hid; |
| 386 | struct usb_device *dev = hid->dev; |
| 387 | struct hiddev_collection_info cinfo; |
| 388 | struct hiddev_report_info rinfo; |
| 389 | struct hiddev_field_info finfo; |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 390 | struct hiddev_usage_ref_multi *uref_multi = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | struct hiddev_usage_ref *uref; |
| 392 | struct hiddev_devinfo dinfo; |
| 393 | struct hid_report *report; |
| 394 | struct hid_field *field; |
| 395 | void __user *user_arg = (void __user *)arg; |
| 396 | int i; |
| 397 | |
| 398 | if (!hiddev->exist) |
| 399 | return -EIO; |
| 400 | |
| 401 | switch (cmd) { |
| 402 | |
| 403 | case HIDIOCGVERSION: |
| 404 | return put_user(HID_VERSION, (int __user *)arg); |
| 405 | |
| 406 | case HIDIOCAPPLICATION: |
| 407 | if (arg < 0 || arg >= hid->maxapplication) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | for (i = 0; i < hid->maxcollection; i++) |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 411 | if (hid->collection[i].type == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | HID_COLLECTION_APPLICATION && arg-- == 0) |
| 413 | break; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (i == hid->maxcollection) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | return hid->collection[i].usage; |
| 419 | |
| 420 | case HIDIOCGDEVINFO: |
| 421 | dinfo.bustype = BUS_USB; |
| 422 | dinfo.busnum = dev->bus->busnum; |
| 423 | dinfo.devnum = dev->devnum; |
| 424 | dinfo.ifnum = hid->ifnum; |
| 425 | dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor); |
| 426 | dinfo.product = le16_to_cpu(dev->descriptor.idProduct); |
| 427 | dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice); |
| 428 | dinfo.num_applications = hid->maxapplication; |
| 429 | if (copy_to_user(user_arg, &dinfo, sizeof(dinfo))) |
| 430 | return -EFAULT; |
| 431 | |
| 432 | return 0; |
| 433 | |
| 434 | case HIDIOCGFLAG: |
| 435 | if (put_user(list->flags, (int __user *)arg)) |
| 436 | return -EFAULT; |
| 437 | |
| 438 | return 0; |
| 439 | |
| 440 | case HIDIOCSFLAG: |
| 441 | { |
| 442 | int newflags; |
| 443 | if (get_user(newflags, (int __user *)arg)) |
| 444 | return -EFAULT; |
| 445 | |
| 446 | if ((newflags & ~HIDDEV_FLAGS) != 0 || |
| 447 | ((newflags & HIDDEV_FLAG_REPORT) != 0 && |
| 448 | (newflags & HIDDEV_FLAG_UREF) == 0)) |
| 449 | return -EINVAL; |
| 450 | |
| 451 | list->flags = newflags; |
| 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | case HIDIOCGSTRING: |
| 457 | { |
| 458 | int idx, len; |
| 459 | char *buf; |
| 460 | |
| 461 | if (get_user(idx, (int __user *)arg)) |
| 462 | return -EFAULT; |
| 463 | |
| 464 | if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL) |
| 465 | return -ENOMEM; |
| 466 | |
| 467 | if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) { |
| 468 | kfree(buf); |
| 469 | return -EINVAL; |
| 470 | } |
| 471 | |
| 472 | if (copy_to_user(user_arg+sizeof(int), buf, len+1)) { |
| 473 | kfree(buf); |
| 474 | return -EFAULT; |
| 475 | } |
| 476 | |
| 477 | kfree(buf); |
| 478 | |
| 479 | return len; |
| 480 | } |
| 481 | |
| 482 | case HIDIOCINITREPORT: |
| 483 | hid_init_reports(hid); |
| 484 | |
| 485 | return 0; |
| 486 | |
| 487 | case HIDIOCGREPORT: |
| 488 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) |
| 489 | return -EFAULT; |
| 490 | |
| 491 | if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT) |
| 492 | return -EINVAL; |
| 493 | |
| 494 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 495 | return -EINVAL; |
| 496 | |
| 497 | hid_submit_report(hid, report, USB_DIR_IN); |
| 498 | hid_wait_io(hid); |
| 499 | |
| 500 | return 0; |
| 501 | |
| 502 | case HIDIOCSREPORT: |
| 503 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) |
| 504 | return -EFAULT; |
| 505 | |
| 506 | if (rinfo.report_type == HID_REPORT_TYPE_INPUT) |
| 507 | return -EINVAL; |
| 508 | |
| 509 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 510 | return -EINVAL; |
| 511 | |
| 512 | hid_submit_report(hid, report, USB_DIR_OUT); |
Stefan Nickl | 010988e | 2005-09-05 01:57:46 -0500 | [diff] [blame] | 513 | hid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | return 0; |
| 516 | |
| 517 | case HIDIOCGREPORTINFO: |
| 518 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) |
| 519 | return -EFAULT; |
| 520 | |
| 521 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 522 | return -EINVAL; |
| 523 | |
| 524 | rinfo.num_fields = report->maxfield; |
| 525 | |
| 526 | if (copy_to_user(user_arg, &rinfo, sizeof(rinfo))) |
| 527 | return -EFAULT; |
| 528 | |
| 529 | return 0; |
| 530 | |
| 531 | case HIDIOCGFIELDINFO: |
| 532 | if (copy_from_user(&finfo, user_arg, sizeof(finfo))) |
| 533 | return -EFAULT; |
| 534 | rinfo.report_type = finfo.report_type; |
| 535 | rinfo.report_id = finfo.report_id; |
| 536 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 537 | return -EINVAL; |
| 538 | |
| 539 | if (finfo.field_index >= report->maxfield) |
| 540 | return -EINVAL; |
| 541 | |
| 542 | field = report->field[finfo.field_index]; |
| 543 | memset(&finfo, 0, sizeof(finfo)); |
| 544 | finfo.report_type = rinfo.report_type; |
| 545 | finfo.report_id = rinfo.report_id; |
| 546 | finfo.field_index = field->report_count - 1; |
| 547 | finfo.maxusage = field->maxusage; |
| 548 | finfo.flags = field->flags; |
| 549 | finfo.physical = field->physical; |
| 550 | finfo.logical = field->logical; |
| 551 | finfo.application = field->application; |
| 552 | finfo.logical_minimum = field->logical_minimum; |
| 553 | finfo.logical_maximum = field->logical_maximum; |
| 554 | finfo.physical_minimum = field->physical_minimum; |
| 555 | finfo.physical_maximum = field->physical_maximum; |
| 556 | finfo.unit_exponent = field->unit_exponent; |
| 557 | finfo.unit = field->unit; |
| 558 | |
| 559 | if (copy_to_user(user_arg, &finfo, sizeof(finfo))) |
| 560 | return -EFAULT; |
| 561 | |
| 562 | return 0; |
| 563 | |
| 564 | case HIDIOCGUCODE: |
| 565 | uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); |
| 566 | if (!uref_multi) |
| 567 | return -ENOMEM; |
| 568 | uref = &uref_multi->uref; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 569 | if (copy_from_user(uref, user_arg, sizeof(*uref))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | goto fault; |
| 571 | |
| 572 | rinfo.report_type = uref->report_type; |
| 573 | rinfo.report_id = uref->report_id; |
| 574 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 575 | goto inval; |
| 576 | |
| 577 | if (uref->field_index >= report->maxfield) |
| 578 | goto inval; |
| 579 | |
| 580 | field = report->field[uref->field_index]; |
| 581 | if (uref->usage_index >= field->maxusage) |
| 582 | goto inval; |
| 583 | |
| 584 | uref->usage_code = field->usage[uref->usage_index].hid; |
| 585 | |
| 586 | if (copy_to_user(user_arg, uref, sizeof(*uref))) |
| 587 | goto fault; |
| 588 | |
| 589 | kfree(uref_multi); |
| 590 | return 0; |
| 591 | |
| 592 | case HIDIOCGUSAGE: |
| 593 | case HIDIOCSUSAGE: |
| 594 | case HIDIOCGUSAGES: |
| 595 | case HIDIOCSUSAGES: |
| 596 | case HIDIOCGCOLLECTIONINDEX: |
| 597 | uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); |
| 598 | if (!uref_multi) |
| 599 | return -ENOMEM; |
| 600 | uref = &uref_multi->uref; |
| 601 | if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 602 | if (copy_from_user(uref_multi, user_arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | sizeof(*uref_multi))) |
| 604 | goto fault; |
| 605 | } else { |
| 606 | if (copy_from_user(uref, user_arg, sizeof(*uref))) |
| 607 | goto fault; |
| 608 | } |
| 609 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 610 | if (cmd != HIDIOCGUSAGE && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | cmd != HIDIOCGUSAGES && |
| 612 | uref->report_type == HID_REPORT_TYPE_INPUT) |
| 613 | goto inval; |
| 614 | |
| 615 | if (uref->report_id == HID_REPORT_ID_UNKNOWN) { |
| 616 | field = hiddev_lookup_usage(hid, uref); |
| 617 | if (field == NULL) |
| 618 | goto inval; |
| 619 | } else { |
| 620 | rinfo.report_type = uref->report_type; |
| 621 | rinfo.report_id = uref->report_id; |
| 622 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) |
| 623 | goto inval; |
| 624 | |
| 625 | if (uref->field_index >= report->maxfield) |
| 626 | goto inval; |
| 627 | |
| 628 | field = report->field[uref->field_index]; |
| 629 | |
| 630 | if (cmd == HIDIOCGCOLLECTIONINDEX) { |
| 631 | if (uref->usage_index >= field->maxusage) |
| 632 | goto inval; |
| 633 | } else if (uref->usage_index >= field->report_count) |
| 634 | goto inval; |
| 635 | |
| 636 | else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) && |
| 637 | (uref_multi->num_values > HID_MAX_MULTI_USAGES || |
Ben Collins | 6dea934 | 2006-01-31 01:31:13 -0500 | [diff] [blame] | 638 | uref->usage_index + uref_multi->num_values > field->report_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | goto inval; |
| 640 | } |
| 641 | |
| 642 | switch (cmd) { |
| 643 | case HIDIOCGUSAGE: |
| 644 | uref->value = field->value[uref->usage_index]; |
| 645 | if (copy_to_user(user_arg, uref, sizeof(*uref))) |
| 646 | goto fault; |
| 647 | goto goodreturn; |
| 648 | |
| 649 | case HIDIOCSUSAGE: |
| 650 | field->value[uref->usage_index] = uref->value; |
| 651 | goto goodreturn; |
| 652 | |
| 653 | case HIDIOCGCOLLECTIONINDEX: |
| 654 | kfree(uref_multi); |
| 655 | return field->usage[uref->usage_index].collection_index; |
| 656 | case HIDIOCGUSAGES: |
| 657 | for (i = 0; i < uref_multi->num_values; i++) |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 658 | uref_multi->values[i] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | field->value[uref->usage_index + i]; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 660 | if (copy_to_user(user_arg, uref_multi, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | sizeof(*uref_multi))) |
| 662 | goto fault; |
| 663 | goto goodreturn; |
| 664 | case HIDIOCSUSAGES: |
| 665 | for (i = 0; i < uref_multi->num_values; i++) |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 666 | field->value[uref->usage_index + i] = |
| 667 | uref_multi->values[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | goto goodreturn; |
| 669 | } |
| 670 | |
| 671 | goodreturn: |
| 672 | kfree(uref_multi); |
| 673 | return 0; |
| 674 | fault: |
| 675 | kfree(uref_multi); |
| 676 | return -EFAULT; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 677 | inval: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | kfree(uref_multi); |
| 679 | return -EINVAL; |
| 680 | |
| 681 | case HIDIOCGCOLLECTIONINFO: |
| 682 | if (copy_from_user(&cinfo, user_arg, sizeof(cinfo))) |
| 683 | return -EFAULT; |
| 684 | |
| 685 | if (cinfo.index >= hid->maxcollection) |
| 686 | return -EINVAL; |
| 687 | |
| 688 | cinfo.type = hid->collection[cinfo.index].type; |
| 689 | cinfo.usage = hid->collection[cinfo.index].usage; |
| 690 | cinfo.level = hid->collection[cinfo.index].level; |
| 691 | |
| 692 | if (copy_to_user(user_arg, &cinfo, sizeof(cinfo))) |
| 693 | return -EFAULT; |
| 694 | return 0; |
| 695 | |
| 696 | default: |
| 697 | |
| 698 | if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ) |
| 699 | return -EINVAL; |
| 700 | |
| 701 | if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) { |
| 702 | int len; |
| 703 | if (!hid->name) |
| 704 | return 0; |
| 705 | len = strlen(hid->name) + 1; |
| 706 | if (len > _IOC_SIZE(cmd)) |
| 707 | len = _IOC_SIZE(cmd); |
| 708 | return copy_to_user(user_arg, hid->name, len) ? |
| 709 | -EFAULT : len; |
| 710 | } |
| 711 | |
| 712 | if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) { |
| 713 | int len; |
| 714 | if (!hid->phys) |
| 715 | return 0; |
| 716 | len = strlen(hid->phys) + 1; |
| 717 | if (len > _IOC_SIZE(cmd)) |
| 718 | len = _IOC_SIZE(cmd); |
| 719 | return copy_to_user(user_arg, hid->phys, len) ? |
| 720 | -EFAULT : len; |
| 721 | } |
| 722 | } |
| 723 | return -EINVAL; |
| 724 | } |
| 725 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 726 | static const struct file_operations hiddev_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | .owner = THIS_MODULE, |
| 728 | .read = hiddev_read, |
| 729 | .write = hiddev_write, |
| 730 | .poll = hiddev_poll, |
| 731 | .open = hiddev_open, |
| 732 | .release = hiddev_release, |
| 733 | .ioctl = hiddev_ioctl, |
| 734 | .fasync = hiddev_fasync, |
| 735 | }; |
| 736 | |
| 737 | static struct usb_class_driver hiddev_class = { |
Greg Kroah-Hartman | d6e5bcf | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 738 | .name = "hiddev%d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | .fops = &hiddev_fops, |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 740 | .minor_base = HIDDEV_MINOR_BASE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | }; |
| 742 | |
| 743 | /* |
| 744 | * This is where hid.c calls us to connect a hid device to the hiddev driver |
| 745 | */ |
| 746 | int hiddev_connect(struct hid_device *hid) |
| 747 | { |
| 748 | struct hiddev *hiddev; |
| 749 | int i; |
| 750 | int retval; |
| 751 | |
| 752 | for (i = 0; i < hid->maxcollection; i++) |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 753 | if (hid->collection[i].type == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | HID_COLLECTION_APPLICATION && |
| 755 | !IS_INPUT_APPLICATION(hid->collection[i].usage)) |
| 756 | break; |
| 757 | |
| 758 | if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) |
| 759 | return -1; |
| 760 | |
Oliver Neukum | bbdb7da | 2006-01-06 20:54:29 +0100 | [diff] [blame] | 761 | if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 764 | retval = usb_register_dev(hid->intf, &hiddev_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | if (retval) { |
| 766 | err("Not able to get a minor for this device."); |
| 767 | kfree(hiddev); |
| 768 | return -1; |
| 769 | } |
| 770 | |
| 771 | init_waitqueue_head(&hiddev->wait); |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 772 | INIT_LIST_HEAD(&hiddev->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | hiddev->hid = hid; |
| 774 | hiddev->exist = 1; |
| 775 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 776 | hid->minor = hid->intf->minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | hid->hiddev = hiddev; |
| 778 | |
Dmitry Torokhov | 826d598 | 2006-07-19 01:09:10 -0400 | [diff] [blame] | 779 | hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev; |
| 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | /* |
| 785 | * This is where hid.c calls us to disconnect a hiddev device from the |
| 786 | * corresponding hid device (usually because the usb device has disconnected) |
| 787 | */ |
| 788 | static struct usb_class_driver hiddev_class; |
| 789 | void hiddev_disconnect(struct hid_device *hid) |
| 790 | { |
| 791 | struct hiddev *hiddev = hid->hiddev; |
| 792 | |
| 793 | hiddev->exist = 0; |
| 794 | |
| 795 | hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL; |
| 796 | usb_deregister_dev(hiddev->hid->intf, &hiddev_class); |
| 797 | |
| 798 | if (hiddev->open) { |
| 799 | hid_close(hiddev->hid); |
| 800 | wake_up_interruptible(&hiddev->wait); |
| 801 | } else { |
| 802 | kfree(hiddev); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | /* Currently this driver is a USB driver. It's not a conventional one in |
| 807 | * the sense that it doesn't probe at the USB level. Instead it waits to |
| 808 | * be connected by HID through the hiddev_connect / hiddev_disconnect |
| 809 | * routines. The reason to register as a USB device is to gain part of the |
| 810 | * minor number space from the USB major. |
| 811 | * |
| 812 | * In theory, should the HID code be generalized to more than one physical |
| 813 | * medium (say, IEEE 1384), this driver will probably need to register its |
| 814 | * own major number, and in doing so, no longer need to register with USB. |
| 815 | * At that point the probe routine and hiddev_driver struct below will no |
| 816 | * longer be useful. |
| 817 | */ |
| 818 | |
| 819 | |
| 820 | /* We never attach in this manner, and rely on HID to connect us. This |
| 821 | * is why there is no disconnect routine defined in the usb_driver either. |
| 822 | */ |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 823 | static int hiddev_usbd_probe(struct usb_interface *intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | const struct usb_device_id *hiddev_info) |
| 825 | { |
| 826 | return -ENODEV; |
| 827 | } |
| 828 | |
| 829 | |
| 830 | static /* const */ struct usb_driver hiddev_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | .name = "hiddev", |
| 832 | .probe = hiddev_usbd_probe, |
| 833 | }; |
| 834 | |
| 835 | int __init hiddev_init(void) |
| 836 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | return usb_register(&hiddev_driver); |
| 838 | } |
| 839 | |
| 840 | void hiddev_exit(void) |
| 841 | { |
| 842 | usb_deregister(&hiddev_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |