]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/hid/usbhid/hid-core.c
78553b457a2b6193a762b727612d685b0b1f4c77
[linux-2.6-omap-h63xx.git] / drivers / hid / usbhid / hid-core.c
1 /*
2  *  USB HID support for Linux
3  *
4  *  Copyright (c) 1999 Andreas Gal
5  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7  *  Copyright (c) 2006-2007 Jiri Kosina
8  */
9
10 /*
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the Free
13  * Software Foundation; either version 2 of the License, or (at your option)
14  * any later version.
15  */
16
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/list.h>
22 #include <linux/mm.h>
23 #include <linux/smp_lock.h>
24 #include <linux/spinlock.h>
25 #include <asm/unaligned.h>
26 #include <asm/byteorder.h>
27 #include <linux/input.h>
28 #include <linux/wait.h>
29
30 #include <linux/usb.h>
31
32 #include <linux/hid.h>
33 #include <linux/hiddev.h>
34 #include <linux/hid-debug.h>
35 #include <linux/hidraw.h>
36 #include "usbhid.h"
37
38 /*
39  * Version Information
40  */
41
42 #define DRIVER_VERSION "v2.6"
43 #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina"
44 #define DRIVER_DESC "USB HID core driver"
45 #define DRIVER_LICENSE "GPL"
46
47 static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
48                                 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
49 /*
50  * Module parameters.
51  */
52
53 static unsigned int hid_mousepoll_interval;
54 module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
55 MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
56
57 /* Quirks specified at module load time */
58 static char *quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL };
59 module_param_array_named(quirks, quirks_param, charp, NULL, 0444);
60 MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
61                 " quirks=vendorID:productID:quirks"
62                 " where vendorID, productID, and quirks are all in"
63                 " 0x-prefixed hex");
64 static char *rdesc_quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL };
65 module_param_array_named(rdesc_quirks, rdesc_quirks_param, charp, NULL, 0444);
66 MODULE_PARM_DESC(rdesc_quirks, "Add/modify report descriptor quirks by specifying "
67                 " rdesc_quirks=vendorID:productID:rdesc_quirks"
68                 " where vendorID, productID, and rdesc_quirks are all in"
69                 " 0x-prefixed hex");
70 /*
71  * Input submission and I/O error handler.
72  */
73
74 static void hid_io_error(struct hid_device *hid);
75
76 /* Start up the input URB */
77 static int hid_start_in(struct hid_device *hid)
78 {
79         unsigned long flags;
80         int rc = 0;
81         struct usbhid_device *usbhid = hid->driver_data;
82
83         spin_lock_irqsave(&usbhid->inlock, flags);
84         if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) &&
85                         !test_bit(HID_DISCONNECTED, &usbhid->iofl) &&
86                         !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
87                 rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC);
88                 if (rc != 0)
89                         clear_bit(HID_IN_RUNNING, &usbhid->iofl);
90         }
91         spin_unlock_irqrestore(&usbhid->inlock, flags);
92         return rc;
93 }
94
95 /* I/O retry timer routine */
96 static void hid_retry_timeout(unsigned long _hid)
97 {
98         struct hid_device *hid = (struct hid_device *) _hid;
99         struct usbhid_device *usbhid = hid->driver_data;
100
101         dev_dbg(&usbhid->intf->dev, "retrying intr urb\n");
102         if (hid_start_in(hid))
103                 hid_io_error(hid);
104 }
105
106 /* Workqueue routine to reset the device or clear a halt */
107 static void hid_reset(struct work_struct *work)
108 {
109         struct usbhid_device *usbhid =
110                 container_of(work, struct usbhid_device, reset_work);
111         struct hid_device *hid = usbhid->hid;
112         int rc_lock, rc = 0;
113
114         if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) {
115                 dev_dbg(&usbhid->intf->dev, "clear halt\n");
116                 rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe);
117                 clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
118                 hid_start_in(hid);
119         }
120
121         else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) {
122                 dev_dbg(&usbhid->intf->dev, "resetting device\n");
123                 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf);
124                 if (rc_lock >= 0) {
125                         rc = usb_reset_device(hid_to_usb_dev(hid));
126                         if (rc_lock)
127                                 usb_unlock_device(hid_to_usb_dev(hid));
128                 }
129                 clear_bit(HID_RESET_PENDING, &usbhid->iofl);
130         }
131
132         switch (rc) {
133         case 0:
134                 if (!test_bit(HID_IN_RUNNING, &usbhid->iofl))
135                         hid_io_error(hid);
136                 break;
137         default:
138                 err_hid("can't reset device, %s-%s/input%d, status %d",
139                                 hid_to_usb_dev(hid)->bus->bus_name,
140                                 hid_to_usb_dev(hid)->devpath,
141                                 usbhid->ifnum, rc);
142                 /* FALLTHROUGH */
143         case -EHOSTUNREACH:
144         case -ENODEV:
145         case -EINTR:
146                 break;
147         }
148 }
149
150 /* Main I/O error handler */
151 static void hid_io_error(struct hid_device *hid)
152 {
153         unsigned long flags;
154         struct usbhid_device *usbhid = hid->driver_data;
155
156         spin_lock_irqsave(&usbhid->inlock, flags);
157
158         /* Stop when disconnected */
159         if (test_bit(HID_DISCONNECTED, &usbhid->iofl))
160                 goto done;
161
162         /* If it has been a while since the last error, we'll assume
163          * this a brand new error and reset the retry timeout. */
164         if (time_after(jiffies, usbhid->stop_retry + HZ/2))
165                 usbhid->retry_delay = 0;
166
167         /* When an error occurs, retry at increasing intervals */
168         if (usbhid->retry_delay == 0) {
169                 usbhid->retry_delay = 13;       /* Then 26, 52, 104, 104, ... */
170                 usbhid->stop_retry = jiffies + msecs_to_jiffies(1000);
171         } else if (usbhid->retry_delay < 100)
172                 usbhid->retry_delay *= 2;
173
174         if (time_after(jiffies, usbhid->stop_retry)) {
175
176                 /* Retries failed, so do a port reset */
177                 if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) {
178                         schedule_work(&usbhid->reset_work);
179                         goto done;
180                 }
181         }
182
183         mod_timer(&usbhid->io_retry,
184                         jiffies + msecs_to_jiffies(usbhid->retry_delay));
185 done:
186         spin_unlock_irqrestore(&usbhid->inlock, flags);
187 }
188
189 /*
190  * Input interrupt completion handler.
191  */
192
193 static void hid_irq_in(struct urb *urb)
194 {
195         struct hid_device       *hid = urb->context;
196         struct usbhid_device    *usbhid = hid->driver_data;
197         int                     status;
198
199         switch (urb->status) {
200         case 0:                 /* success */
201                 usbhid->retry_delay = 0;
202                 hid_input_report(urb->context, HID_INPUT_REPORT,
203                                  urb->transfer_buffer,
204                                  urb->actual_length, 1);
205                 break;
206         case -EPIPE:            /* stall */
207                 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
208                 set_bit(HID_CLEAR_HALT, &usbhid->iofl);
209                 schedule_work(&usbhid->reset_work);
210                 return;
211         case -ECONNRESET:       /* unlink */
212         case -ENOENT:
213         case -ESHUTDOWN:        /* unplug */
214                 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
215                 return;
216         case -EILSEQ:           /* protocol error or unplug */
217         case -EPROTO:           /* protocol error or unplug */
218         case -ETIME:            /* protocol error or unplug */
219         case -ETIMEDOUT:        /* Should never happen, but... */
220                 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
221                 hid_io_error(hid);
222                 return;
223         default:                /* error */
224                 warn("input irq status %d received", urb->status);
225         }
226
227         status = usb_submit_urb(urb, GFP_ATOMIC);
228         if (status) {
229                 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
230                 if (status != -EPERM) {
231                         err_hid("can't resubmit intr, %s-%s/input%d, status %d",
232                                         hid_to_usb_dev(hid)->bus->bus_name,
233                                         hid_to_usb_dev(hid)->devpath,
234                                         usbhid->ifnum, status);
235                         hid_io_error(hid);
236                 }
237         }
238 }
239
240 static int hid_submit_out(struct hid_device *hid)
241 {
242         struct hid_report *report;
243         struct usbhid_device *usbhid = hid->driver_data;
244
245         report = usbhid->out[usbhid->outtail];
246
247         hid_output_report(report, usbhid->outbuf);
248         usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
249         usbhid->urbout->dev = hid_to_usb_dev(hid);
250
251         dbg_hid("submitting out urb\n");
252
253         if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) {
254                 err_hid("usb_submit_urb(out) failed");
255                 return -1;
256         }
257
258         return 0;
259 }
260
261 static int hid_submit_ctrl(struct hid_device *hid)
262 {
263         struct hid_report *report;
264         unsigned char dir;
265         int len;
266         struct usbhid_device *usbhid = hid->driver_data;
267
268         report = usbhid->ctrl[usbhid->ctrltail].report;
269         dir = usbhid->ctrl[usbhid->ctrltail].dir;
270
271         len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
272         if (dir == USB_DIR_OUT) {
273                 hid_output_report(report, usbhid->ctrlbuf);
274                 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
275                 usbhid->urbctrl->transfer_buffer_length = len;
276         } else {
277                 int maxpacket, padlen;
278
279                 usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
280                 maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0);
281                 if (maxpacket > 0) {
282                         padlen = DIV_ROUND_UP(len, maxpacket);
283                         padlen *= maxpacket;
284                         if (padlen > usbhid->bufsize)
285                                 padlen = usbhid->bufsize;
286                 } else
287                         padlen = 0;
288                 usbhid->urbctrl->transfer_buffer_length = padlen;
289         }
290         usbhid->urbctrl->dev = hid_to_usb_dev(hid);
291
292         usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
293         usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
294         usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
295         usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum);
296         usbhid->cr->wLength = cpu_to_le16(len);
297
298         dbg_hid("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u\n",
299                 usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report",
300                 usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength);
301
302         if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) {
303                 err_hid("usb_submit_urb(ctrl) failed");
304                 return -1;
305         }
306
307         return 0;
308 }
309
310 /*
311  * Output interrupt completion handler.
312  */
313
314 static void hid_irq_out(struct urb *urb)
315 {
316         struct hid_device *hid = urb->context;
317         struct usbhid_device *usbhid = hid->driver_data;
318         unsigned long flags;
319         int unplug = 0;
320
321         switch (urb->status) {
322         case 0:                 /* success */
323                 break;
324         case -ESHUTDOWN:        /* unplug */
325                 unplug = 1;
326         case -EILSEQ:           /* protocol error or unplug */
327         case -EPROTO:           /* protocol error or unplug */
328         case -ECONNRESET:       /* unlink */
329         case -ENOENT:
330                 break;
331         default:                /* error */
332                 warn("output irq status %d received", urb->status);
333         }
334
335         spin_lock_irqsave(&usbhid->outlock, flags);
336
337         if (unplug)
338                 usbhid->outtail = usbhid->outhead;
339         else
340                 usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
341
342         if (usbhid->outhead != usbhid->outtail) {
343                 if (hid_submit_out(hid)) {
344                         clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
345                         wake_up(&usbhid->wait);
346                 }
347                 spin_unlock_irqrestore(&usbhid->outlock, flags);
348                 return;
349         }
350
351         clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
352         spin_unlock_irqrestore(&usbhid->outlock, flags);
353         wake_up(&usbhid->wait);
354 }
355
356 /*
357  * Control pipe completion handler.
358  */
359
360 static void hid_ctrl(struct urb *urb)
361 {
362         struct hid_device *hid = urb->context;
363         struct usbhid_device *usbhid = hid->driver_data;
364         unsigned long flags;
365         int unplug = 0;
366
367         spin_lock_irqsave(&usbhid->ctrllock, flags);
368
369         switch (urb->status) {
370         case 0:                 /* success */
371                 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN)
372                         hid_input_report(urb->context,
373                                 usbhid->ctrl[usbhid->ctrltail].report->type,
374                                 urb->transfer_buffer, urb->actual_length, 0);
375                 break;
376         case -ESHUTDOWN:        /* unplug */
377                 unplug = 1;
378         case -EILSEQ:           /* protocol error or unplug */
379         case -EPROTO:           /* protocol error or unplug */
380         case -ECONNRESET:       /* unlink */
381         case -ENOENT:
382         case -EPIPE:            /* report not available */
383                 break;
384         default:                /* error */
385                 warn("ctrl urb status %d received", urb->status);
386         }
387
388         if (unplug)
389                 usbhid->ctrltail = usbhid->ctrlhead;
390         else
391                 usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
392
393         if (usbhid->ctrlhead != usbhid->ctrltail) {
394                 if (hid_submit_ctrl(hid)) {
395                         clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
396                         wake_up(&usbhid->wait);
397                 }
398                 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
399                 return;
400         }
401
402         clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
403         spin_unlock_irqrestore(&usbhid->ctrllock, flags);
404         wake_up(&usbhid->wait);
405 }
406
407 void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
408 {
409         int head;
410         unsigned long flags;
411         struct usbhid_device *usbhid = hid->driver_data;
412
413         if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
414                 return;
415
416         if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
417
418                 spin_lock_irqsave(&usbhid->outlock, flags);
419
420                 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) {
421                         spin_unlock_irqrestore(&usbhid->outlock, flags);
422                         warn("output queue full");
423                         return;
424                 }
425
426                 usbhid->out[usbhid->outhead] = report;
427                 usbhid->outhead = head;
428
429                 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl))
430                         if (hid_submit_out(hid))
431                                 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
432
433                 spin_unlock_irqrestore(&usbhid->outlock, flags);
434                 return;
435         }
436
437         spin_lock_irqsave(&usbhid->ctrllock, flags);
438
439         if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) {
440                 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
441                 warn("control queue full");
442                 return;
443         }
444
445         usbhid->ctrl[usbhid->ctrlhead].report = report;
446         usbhid->ctrl[usbhid->ctrlhead].dir = dir;
447         usbhid->ctrlhead = head;
448
449         if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl))
450                 if (hid_submit_ctrl(hid))
451                         clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
452
453         spin_unlock_irqrestore(&usbhid->ctrllock, flags);
454 }
455
456 static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
457 {
458         struct hid_device *hid = input_get_drvdata(dev);
459         struct hid_field *field;
460         int offset;
461
462         if (type == EV_FF)
463                 return input_ff_event(dev, type, code, value);
464
465         if (type != EV_LED)
466                 return -1;
467
468         if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
469                 warn("event field not found");
470                 return -1;
471         }
472
473         hid_set_field(field, offset, value);
474         usbhid_submit_report(hid, field->report, USB_DIR_OUT);
475
476         return 0;
477 }
478
479 int usbhid_wait_io(struct hid_device *hid)
480 {
481         struct usbhid_device *usbhid = hid->driver_data;
482
483         if (!wait_event_timeout(usbhid->wait,
484                                 (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) &&
485                                 !test_bit(HID_OUT_RUNNING, &usbhid->iofl)),
486                                         10*HZ)) {
487                 dbg_hid("timeout waiting for ctrl or out queue to clear\n");
488                 return -1;
489         }
490
491         return 0;
492 }
493
494 static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
495 {
496         return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
497                 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
498                 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
499 }
500
501 static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
502                 unsigned char type, void *buf, int size)
503 {
504         int result, retries = 4;
505
506         memset(buf, 0, size);
507
508         do {
509                 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
510                                 USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN,
511                                 (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT);
512                 retries--;
513         } while (result < size && retries);
514         return result;
515 }
516
517 int usbhid_open(struct hid_device *hid)
518 {
519         struct usbhid_device *usbhid = hid->driver_data;
520         int res;
521
522         if (!hid->open++) {
523                 res = usb_autopm_get_interface(usbhid->intf);
524                 if (res < 0) {
525                         hid->open--;
526                         return -EIO;
527                 }
528         }
529         if (hid_start_in(hid))
530                 hid_io_error(hid);
531         return 0;
532 }
533
534 void usbhid_close(struct hid_device *hid)
535 {
536         struct usbhid_device *usbhid = hid->driver_data;
537
538         if (!--hid->open) {
539                 usb_kill_urb(usbhid->urbin);
540                 usb_autopm_put_interface(usbhid->intf);
541         }
542 }
543
544 /*
545  * Initialize all reports
546  */
547
548 void usbhid_init_reports(struct hid_device *hid)
549 {
550         struct hid_report *report;
551         struct usbhid_device *usbhid = hid->driver_data;
552         int err, ret;
553
554         list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
555                 usbhid_submit_report(hid, report, USB_DIR_IN);
556
557         list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
558                 usbhid_submit_report(hid, report, USB_DIR_IN);
559
560         err = 0;
561         ret = usbhid_wait_io(hid);
562         while (ret) {
563                 err |= ret;
564                 if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl))
565                         usb_kill_urb(usbhid->urbctrl);
566                 if (test_bit(HID_OUT_RUNNING, &usbhid->iofl))
567                         usb_kill_urb(usbhid->urbout);
568                 ret = usbhid_wait_io(hid);
569         }
570
571         if (err)
572                 warn("timeout initializing reports");
573 }
574
575 /*
576  * Reset LEDs which BIOS might have left on. For now, just NumLock (0x01).
577  */
578 static int hid_find_field_early(struct hid_device *hid, unsigned int page,
579     unsigned int hid_code, struct hid_field **pfield)
580 {
581         struct hid_report *report;
582         struct hid_field *field;
583         struct hid_usage *usage;
584         int i, j;
585
586         list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) {
587                 for (i = 0; i < report->maxfield; i++) {
588                         field = report->field[i];
589                         for (j = 0; j < field->maxusage; j++) {
590                                 usage = &field->usage[j];
591                                 if ((usage->hid & HID_USAGE_PAGE) == page &&
592                                     (usage->hid & 0xFFFF) == hid_code) {
593                                         *pfield = field;
594                                         return j;
595                                 }
596                         }
597                 }
598         }
599         return -1;
600 }
601
602 static void usbhid_set_leds(struct hid_device *hid)
603 {
604         struct hid_field *field;
605         int offset;
606
607         if ((offset = hid_find_field_early(hid, HID_UP_LED, 0x01, &field)) != -1) {
608                 hid_set_field(field, offset, 0);
609                 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
610         }
611 }
612
613 /*
614  * Traverse the supplied list of reports and find the longest
615  */
616 static void hid_find_max_report(struct hid_device *hid, unsigned int type,
617                 unsigned int *max)
618 {
619         struct hid_report *report;
620         unsigned int size;
621
622         list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
623                 size = ((report->size - 1) >> 3) + 1;
624                 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
625                         size++;
626                 if (*max < size)
627                         *max = size;
628         }
629 }
630
631 static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
632 {
633         struct usbhid_device *usbhid = hid->driver_data;
634
635         if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma)))
636                 return -1;
637         if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma)))
638                 return -1;
639         if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma)))
640                 return -1;
641         if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma)))
642                 return -1;
643
644         return 0;
645 }
646
647 static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count)
648 {
649         struct usbhid_device *usbhid = hid->driver_data;
650         struct usb_device *dev = hid_to_usb_dev(hid);
651         struct usb_interface *intf = usbhid->intf;
652         struct usb_host_interface *interface = intf->cur_altsetting;
653         int ret;
654
655         ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
656                 HID_REQ_SET_REPORT,
657                 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
658                 ((HID_OUTPUT_REPORT + 1) << 8) | *buf,
659                 interface->desc.bInterfaceNumber, buf + 1, count - 1,
660                 USB_CTRL_SET_TIMEOUT);
661
662         /* count also the report id */
663         if (ret > 0)
664                 ret++;
665
666         return ret;
667 }
668
669 static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
670 {
671         struct usbhid_device *usbhid = hid->driver_data;
672
673         usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
674         usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
675         usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
676         usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
677 }
678
679 /*
680  * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
681  * to "operational".  Without this, the ps3 controller will not report any
682  * events.
683  */
684 static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum)
685 {
686         int result;
687         char *buf = kmalloc(18, GFP_KERNEL);
688
689         if (!buf)
690                 return;
691
692         result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
693                                  HID_REQ_GET_REPORT,
694                                  USB_DIR_IN | USB_TYPE_CLASS |
695                                  USB_RECIP_INTERFACE,
696                                  (3 << 8) | 0xf2, ifnum, buf, 17,
697                                  USB_CTRL_GET_TIMEOUT);
698
699         if (result < 0)
700                 err_hid("%s failed: %d\n", __func__, result);
701
702         kfree(buf);
703 }
704
705 static int usbhid_start_finish(struct hid_device *hid)
706 {
707         struct usb_interface *intf = to_usb_interface(hid->dev.parent);
708         char path[64], *type;
709         unsigned int i;
710
711         usbhid_init_reports(hid);
712         hid_dump_device(hid);
713         if (hid->quirks & HID_QUIRK_RESET_LEDS)
714                 usbhid_set_leds(hid);
715
716         if (!hidinput_connect(hid))
717                 hid->claimed |= HID_CLAIMED_INPUT;
718         if (!hiddev_connect(hid))
719                 hid->claimed |= HID_CLAIMED_HIDDEV;
720         if (!hidraw_connect(hid))
721                 hid->claimed |= HID_CLAIMED_HIDRAW;
722
723         if (!hid->claimed) {
724                 printk(KERN_ERR "HID device claimed by neither input, hiddev "
725                                 "nor hidraw\n");
726                 return -ENODEV;
727         }
728
729         if ((hid->claimed & HID_CLAIMED_INPUT))
730                 hid_ff_init(hid);
731
732         if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER)
733                 hid_fixup_sony_ps3_controller(interface_to_usbdev(intf),
734                         intf->cur_altsetting->desc.bInterfaceNumber);
735
736         printk(KERN_INFO);
737
738         if (hid->claimed & HID_CLAIMED_INPUT)
739                 printk("input");
740         if ((hid->claimed & HID_CLAIMED_INPUT) &&
741                         ((hid->claimed & HID_CLAIMED_HIDDEV) ||
742                                 hid->claimed & HID_CLAIMED_HIDRAW))
743                 printk(",");
744         if (hid->claimed & HID_CLAIMED_HIDDEV)
745                 printk("hiddev%d", hid->minor);
746         if ((hid->claimed & HID_CLAIMED_INPUT) &&
747                         (hid->claimed & HID_CLAIMED_HIDDEV) &&
748                         (hid->claimed & HID_CLAIMED_HIDRAW))
749                 printk(",");
750         if (hid->claimed & HID_CLAIMED_HIDRAW)
751                 printk("hidraw%d", ((struct hidraw *)hid->hidraw)->minor);
752
753         type = "Device";
754         for (i = 0; i < hid->maxcollection; i++) {
755                 if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
756                     (hid->collection[i].usage & HID_USAGE_PAGE) ==
757                                                 HID_UP_GENDESK &&
758                     (hid->collection[i].usage & 0xffff) <
759                                                 ARRAY_SIZE(hid_types)) {
760                         type = hid_types[hid->collection[i].usage & 0xffff];
761                         break;
762                 }
763         }
764
765         usb_make_path(interface_to_usbdev(intf), path, 63);
766
767         printk(": USB HID v%x.%02x %s [%s] on %s\n",
768                 hid->version >> 8, hid->version & 0xff, type, hid->name, path);
769
770         return 0;
771 }
772
773 static int usbhid_parse(struct hid_device *hid)
774 {
775         struct usb_interface *intf = to_usb_interface(hid->dev.parent);
776         struct usb_host_interface *interface = intf->cur_altsetting;
777         struct usb_device *dev = interface_to_usbdev (intf);
778         struct hid_descriptor *hdesc;
779         u32 quirks = 0;
780         unsigned int rsize = 0;
781         char *rdesc;
782         int ret, n;
783
784         quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
785                         le16_to_cpu(dev->descriptor.idProduct));
786
787         /* Many keyboards and mice don't like to be polled for reports,
788          * so we will always set the HID_QUIRK_NOGET flag for them. */
789         if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
790                 if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
791                         interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
792                                 quirks |= HID_QUIRK_NOGET;
793         }
794
795         if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
796             (!interface->desc.bNumEndpoints ||
797              usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
798                 dbg_hid("class descriptor not present\n");
799                 return -ENODEV;
800         }
801
802         hid->version = le16_to_cpu(hdesc->bcdHID);
803         hid->country = hdesc->bCountryCode;
804
805         for (n = 0; n < hdesc->bNumDescriptors; n++)
806                 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
807                         rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
808
809         if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
810                 dbg_hid("weird size of report descriptor (%u)\n", rsize);
811                 return -EINVAL;
812         }
813
814         if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
815                 dbg_hid("couldn't allocate rdesc memory\n");
816                 return -ENOMEM;
817         }
818
819         hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
820
821         ret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber,
822                         HID_DT_REPORT, rdesc, rsize);
823         if (ret < 0) {
824                 dbg_hid("reading report descriptor failed\n");
825                 kfree(rdesc);
826                 goto err;
827         }
828
829         usbhid_fixup_report_descriptor(le16_to_cpu(dev->descriptor.idVendor),
830                         le16_to_cpu(dev->descriptor.idProduct), rdesc,
831                         rsize, rdesc_quirks_param);
832
833         dbg_hid("report descriptor (size %u, read %d) = ", rsize, n);
834         for (n = 0; n < rsize; n++)
835                 dbg_hid_line(" %02x", (unsigned char) rdesc[n]);
836         dbg_hid_line("\n");
837
838         ret = hid_parse_report(hid, rdesc, rsize);
839         kfree(rdesc);
840         if (ret) {
841                 dbg_hid("parsing report descriptor failed\n");
842                 goto err;
843         }
844
845         hid->quirks = quirks;
846
847         return 0;
848 err:
849         return ret;
850 }
851
852 static int usbhid_start(struct hid_device *hid)
853 {
854         struct usb_interface *intf = to_usb_interface(hid->dev.parent);
855         struct usb_host_interface *interface = intf->cur_altsetting;
856         struct usb_device *dev = interface_to_usbdev(intf);
857         struct usbhid_device *usbhid;
858         unsigned int n, insize = 0;
859         int ret;
860
861         WARN_ON(hid->driver_data);
862
863         usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL);
864         if (usbhid == NULL) {
865                 ret = -ENOMEM;
866                 goto err;
867         }
868
869         hid->driver_data = usbhid;
870         usbhid->hid = hid;
871
872         usbhid->bufsize = HID_MIN_BUFFER_SIZE;
873         hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize);
874         hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize);
875         hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize);
876
877         if (usbhid->bufsize > HID_MAX_BUFFER_SIZE)
878                 usbhid->bufsize = HID_MAX_BUFFER_SIZE;
879
880         hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
881
882         if (insize > HID_MAX_BUFFER_SIZE)
883                 insize = HID_MAX_BUFFER_SIZE;
884
885         if (hid_alloc_buffers(dev, hid)) {
886                 ret = -ENOMEM;
887                 goto fail;
888         }
889
890         for (n = 0; n < interface->desc.bNumEndpoints; n++) {
891                 struct usb_endpoint_descriptor *endpoint;
892                 int pipe;
893                 int interval;
894
895                 endpoint = &interface->endpoint[n].desc;
896                 if ((endpoint->bmAttributes & 3) != 3)          /* Not an interrupt endpoint */
897                         continue;
898
899                 interval = endpoint->bInterval;
900
901                 /* Some vendors give fullspeed interval on highspeed devides */
902                 if (hid->quirks & HID_QUIRK_FULLSPEED_INTERVAL &&
903                     dev->speed == USB_SPEED_HIGH) {
904                         interval = fls(endpoint->bInterval*8);
905                         printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n",
906                                hid->name, endpoint->bInterval, interval);
907                 }
908
909                 /* Change the polling interval of mice. */
910                 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
911                         interval = hid_mousepoll_interval;
912
913                 ret = -ENOMEM;
914                 if (usb_endpoint_dir_in(endpoint)) {
915                         if (usbhid->urbin)
916                                 continue;
917                         if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
918                                 goto fail;
919                         pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
920                         usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize,
921                                          hid_irq_in, hid, interval);
922                         usbhid->urbin->transfer_dma = usbhid->inbuf_dma;
923                         usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
924                 } else {
925                         if (usbhid->urbout)
926                                 continue;
927                         if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
928                                 goto fail;
929                         pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
930                         usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0,
931                                          hid_irq_out, hid, interval);
932                         usbhid->urbout->transfer_dma = usbhid->outbuf_dma;
933                         usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
934                 }
935         }
936
937         if (!usbhid->urbin) {
938                 err_hid("couldn't find an input interrupt endpoint");
939                 ret = -ENODEV;
940                 goto fail;
941         }
942
943         init_waitqueue_head(&usbhid->wait);
944         INIT_WORK(&usbhid->reset_work, hid_reset);
945         setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
946
947         spin_lock_init(&usbhid->inlock);
948         spin_lock_init(&usbhid->outlock);
949         spin_lock_init(&usbhid->ctrllock);
950
951         usbhid->intf = intf;
952         usbhid->ifnum = interface->desc.bInterfaceNumber;
953
954         usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
955         if (!usbhid->urbctrl) {
956                 ret = -ENOMEM;
957                 goto fail;
958         }
959
960         usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
961                              usbhid->ctrlbuf, 1, hid_ctrl, hid);
962         usbhid->urbctrl->setup_dma = usbhid->cr_dma;
963         usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
964         usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
965
966         ret = usbhid_start_finish(hid);
967         if (ret)
968                 goto fail;
969
970         return 0;
971
972 fail:
973         usb_free_urb(usbhid->urbin);
974         usb_free_urb(usbhid->urbout);
975         usb_free_urb(usbhid->urbctrl);
976         hid_free_buffers(dev, hid);
977         kfree(usbhid);
978 err:
979         return ret;
980 }
981
982 static void usbhid_stop(struct hid_device *hid)
983 {
984         struct usbhid_device *usbhid = hid->driver_data;
985
986         if (WARN_ON(!usbhid))
987                 return;
988
989         spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
990         set_bit(HID_DISCONNECTED, &usbhid->iofl);
991         spin_unlock_irq(&usbhid->inlock);
992         usb_kill_urb(usbhid->urbin);
993         usb_kill_urb(usbhid->urbout);
994         usb_kill_urb(usbhid->urbctrl);
995
996         del_timer_sync(&usbhid->io_retry);
997         cancel_work_sync(&usbhid->reset_work);
998
999         if (hid->claimed & HID_CLAIMED_INPUT)
1000                 hidinput_disconnect(hid);
1001         if (hid->claimed & HID_CLAIMED_HIDDEV)
1002                 hiddev_disconnect(hid);
1003         if (hid->claimed & HID_CLAIMED_HIDRAW)
1004                 hidraw_disconnect(hid);
1005
1006         hid->claimed = 0;
1007
1008         usb_free_urb(usbhid->urbin);
1009         usb_free_urb(usbhid->urbctrl);
1010         usb_free_urb(usbhid->urbout);
1011
1012         hid_free_buffers(hid_to_usb_dev(hid), hid);
1013         kfree(usbhid);
1014         hid->driver_data = NULL;
1015 }
1016
1017 static struct hid_ll_driver usb_hid_driver = {
1018         .parse = usbhid_parse,
1019         .start = usbhid_start,
1020         .stop = usbhid_stop,
1021         .open = usbhid_open,
1022         .close = usbhid_close,
1023         .hidinput_input_event = usb_hidinput_input_event,
1024 };
1025
1026 static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
1027 {
1028         struct usb_device *dev = interface_to_usbdev(intf);
1029         struct hid_device *hid;
1030         size_t len;
1031         int ret;
1032
1033         dbg_hid("HID probe called for ifnum %d\n",
1034                         intf->altsetting->desc.bInterfaceNumber);
1035
1036         hid = hid_allocate_device();
1037         if (IS_ERR(hid))
1038                 return PTR_ERR(hid);
1039
1040         usb_set_intfdata(intf, hid);
1041         hid->ll_driver = &usb_hid_driver;
1042         hid->hid_output_raw_report = usbhid_output_raw_report;
1043 #ifdef CONFIG_USB_HIDDEV
1044         hid->hiddev_hid_event = hiddev_hid_event;
1045         hid->hiddev_report_event = hiddev_report_event;
1046 #endif
1047         hid->dev.parent = &intf->dev;
1048         hid->bus = BUS_USB;
1049         hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
1050         hid->product = le16_to_cpu(dev->descriptor.idProduct);
1051         hid->name[0] = 0;
1052
1053         if (dev->manufacturer)
1054                 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
1055
1056         if (dev->product) {
1057                 if (dev->manufacturer)
1058                         strlcat(hid->name, " ", sizeof(hid->name));
1059                 strlcat(hid->name, dev->product, sizeof(hid->name));
1060         }
1061
1062         if (!strlen(hid->name))
1063                 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
1064                          le16_to_cpu(dev->descriptor.idVendor),
1065                          le16_to_cpu(dev->descriptor.idProduct));
1066
1067         usb_make_path(dev, hid->phys, sizeof(hid->phys));
1068         strlcat(hid->phys, "/input", sizeof(hid->phys));
1069         len = strlen(hid->phys);
1070         if (len < sizeof(hid->phys) - 1)
1071                 snprintf(hid->phys + len, sizeof(hid->phys) - len,
1072                          "%d", intf->altsetting[0].desc.bInterfaceNumber);
1073
1074         if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
1075                 hid->uniq[0] = 0;
1076
1077         ret = hid_add_device(hid);
1078         if (ret) {
1079                 if (ret != -ENODEV)
1080                         dev_err(&intf->dev, "can't add hid device: %d\n", ret);
1081                 goto err;
1082         }
1083
1084         return 0;
1085 err:
1086         hid_destroy_device(hid);
1087         return ret;
1088 }
1089
1090 static void hid_disconnect(struct usb_interface *intf)
1091 {
1092         struct hid_device *hid = usb_get_intfdata(intf);
1093
1094         if (WARN_ON(!hid))
1095                 return;
1096
1097         hid_destroy_device(hid);
1098 }
1099
1100 static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1101 {
1102         struct hid_device *hid = usb_get_intfdata (intf);
1103         struct usbhid_device *usbhid = hid->driver_data;
1104
1105         spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
1106         set_bit(HID_SUSPENDED, &usbhid->iofl);
1107         spin_unlock_irq(&usbhid->inlock);
1108         del_timer(&usbhid->io_retry);
1109         usb_kill_urb(usbhid->urbin);
1110         dev_dbg(&intf->dev, "suspend\n");
1111         return 0;
1112 }
1113
1114 static int hid_resume(struct usb_interface *intf)
1115 {
1116         struct hid_device *hid = usb_get_intfdata (intf);
1117         struct usbhid_device *usbhid = hid->driver_data;
1118         int status;
1119
1120         clear_bit(HID_SUSPENDED, &usbhid->iofl);
1121         usbhid->retry_delay = 0;
1122         status = hid_start_in(hid);
1123         dev_dbg(&intf->dev, "resume status %d\n", status);
1124         return status;
1125 }
1126
1127 /* Treat USB reset pretty much the same as suspend/resume */
1128 static int hid_pre_reset(struct usb_interface *intf)
1129 {
1130         /* FIXME: What if the interface is already suspended? */
1131         hid_suspend(intf, PMSG_ON);
1132         return 0;
1133 }
1134
1135 /* Same routine used for post_reset and reset_resume */
1136 static int hid_post_reset(struct usb_interface *intf)
1137 {
1138         struct usb_device *dev = interface_to_usbdev (intf);
1139
1140         hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
1141         /* FIXME: Any more reinitialization needed? */
1142
1143         return hid_resume(intf);
1144 }
1145
1146 static struct usb_device_id hid_usb_ids [] = {
1147         { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
1148                 .bInterfaceClass = USB_INTERFACE_CLASS_HID },
1149         { }                                             /* Terminating entry */
1150 };
1151
1152 MODULE_DEVICE_TABLE (usb, hid_usb_ids);
1153
1154 static struct usb_driver hid_driver = {
1155         .name =         "usbhid",
1156         .probe =        hid_probe,
1157         .disconnect =   hid_disconnect,
1158         .suspend =      hid_suspend,
1159         .resume =       hid_resume,
1160         .reset_resume = hid_post_reset,
1161         .pre_reset =    hid_pre_reset,
1162         .post_reset =   hid_post_reset,
1163         .id_table =     hid_usb_ids,
1164         .supports_autosuspend = 1,
1165 };
1166
1167 static const struct hid_device_id hid_usb_table[] = {
1168         { HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) },
1169         { }
1170 };
1171
1172 static struct hid_driver hid_usb_driver = {
1173         .name = "generic-usb",
1174         .id_table = hid_usb_table,
1175 };
1176
1177 static int __init hid_init(void)
1178 {
1179         int retval;
1180         retval = hid_register_driver(&hid_usb_driver);
1181         if (retval)
1182                 goto hid_register_fail;
1183         retval = usbhid_quirks_init(quirks_param);
1184         if (retval)
1185                 goto usbhid_quirks_init_fail;
1186         retval = hiddev_init();
1187         if (retval)
1188                 goto hiddev_init_fail;
1189         retval = usb_register(&hid_driver);
1190         if (retval)
1191                 goto usb_register_fail;
1192         info(DRIVER_VERSION ":" DRIVER_DESC);
1193
1194         return 0;
1195 usb_register_fail:
1196         hiddev_exit();
1197 hiddev_init_fail:
1198         usbhid_quirks_exit();
1199 usbhid_quirks_init_fail:
1200         hid_unregister_driver(&hid_usb_driver);
1201 hid_register_fail:
1202         return retval;
1203 }
1204
1205 static void __exit hid_exit(void)
1206 {
1207         usb_deregister(&hid_driver);
1208         hiddev_exit();
1209         usbhid_quirks_exit();
1210         hid_unregister_driver(&hid_usb_driver);
1211 }
1212
1213 module_init(hid_init);
1214 module_exit(hid_exit);
1215
1216 MODULE_AUTHOR(DRIVER_AUTHOR);
1217 MODULE_DESCRIPTION(DRIVER_DESC);
1218 MODULE_LICENSE(DRIVER_LICENSE);