| @@ -1,690 +1,699 @@ | | | @@ -1,690 +1,699 @@ |
1 | /* $NetBSD: uhidev.c,v 1.50 2011/07/20 19:27:53 ryoon Exp $ */ | | 1 | /* $NetBSD: uhidev.c,v 1.51 2011/07/30 12:15:44 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2001 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2001 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Lennart Augustsson (lennart@augustsson.net) at | | 8 | * by Lennart Augustsson (lennart@augustsson.net) at |
9 | * Carlstedt Research & Technology. | | 9 | * Carlstedt Research & Technology. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. | | 15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright | | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the | | 17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. | | 18 | * documentation and/or other materials provided with the distribution. |
19 | * | | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf | | 34 | * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.50 2011/07/20 19:27:53 ryoon Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.51 2011/07/30 12:15:44 jmcneill Exp $"); |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/systm.h> | | 41 | #include <sys/systm.h> |
42 | #include <sys/kernel.h> | | 42 | #include <sys/kernel.h> |
43 | #include <sys/malloc.h> | | 43 | #include <sys/malloc.h> |
44 | #include <sys/signalvar.h> | | 44 | #include <sys/signalvar.h> |
45 | #include <sys/device.h> | | 45 | #include <sys/device.h> |
46 | #include <sys/ioctl.h> | | 46 | #include <sys/ioctl.h> |
47 | #include <sys/conf.h> | | 47 | #include <sys/conf.h> |
48 | | | 48 | |
49 | #include <dev/usb/usb.h> | | 49 | #include <dev/usb/usb.h> |
50 | #include <dev/usb/usbhid.h> | | 50 | #include <dev/usb/usbhid.h> |
51 | | | 51 | |
52 | #include <dev/usb/usbdevs.h> | | 52 | #include <dev/usb/usbdevs.h> |
53 | #include <dev/usb/usbdi.h> | | 53 | #include <dev/usb/usbdi.h> |
54 | #include <dev/usb/usbdi_util.h> | | 54 | #include <dev/usb/usbdi_util.h> |
55 | #include <dev/usb/hid.h> | | 55 | #include <dev/usb/hid.h> |
56 | #include <dev/usb/usb_quirks.h> | | 56 | #include <dev/usb/usb_quirks.h> |
57 | | | 57 | |
58 | #include <dev/usb/uhidev.h> | | 58 | #include <dev/usb/uhidev.h> |
59 | | | 59 | |
60 | /* Report descriptor for broken Wacom Graphire */ | | 60 | /* Report descriptor for broken Wacom Graphire */ |
61 | #include <dev/usb/ugraphire_rdesc.h> | | 61 | #include <dev/usb/ugraphire_rdesc.h> |
| | | 62 | /* Report descriptor for game controllers in "XInput" mode */ |
| | | 63 | #include <dev/usb/xinput_rdesc.h> |
62 | | | 64 | |
63 | #include "locators.h" | | 65 | #include "locators.h" |
64 | | | 66 | |
65 | #ifdef UHIDEV_DEBUG | | 67 | #ifdef UHIDEV_DEBUG |
66 | #define DPRINTF(x) if (uhidevdebug) printf x | | 68 | #define DPRINTF(x) if (uhidevdebug) printf x |
67 | #define DPRINTFN(n,x) if (uhidevdebug>(n)) printf x | | 69 | #define DPRINTFN(n,x) if (uhidevdebug>(n)) printf x |
68 | int uhidevdebug = 0; | | 70 | int uhidevdebug = 0; |
69 | #else | | 71 | #else |
70 | #define DPRINTF(x) | | 72 | #define DPRINTF(x) |
71 | #define DPRINTFN(n,x) | | 73 | #define DPRINTFN(n,x) |
72 | #endif | | 74 | #endif |
73 | | | 75 | |
74 | Static void uhidev_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); | | 76 | Static void uhidev_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); |
75 | | | 77 | |
76 | Static int uhidev_maxrepid(void *, int); | | 78 | Static int uhidev_maxrepid(void *, int); |
77 | Static int uhidevprint(void *, const char *); | | 79 | Static int uhidevprint(void *, const char *); |
78 | | | 80 | |
79 | int uhidev_match(device_t, cfdata_t, void *); | | 81 | int uhidev_match(device_t, cfdata_t, void *); |
80 | void uhidev_attach(device_t, device_t, void *); | | 82 | void uhidev_attach(device_t, device_t, void *); |
81 | void uhidev_childdet(device_t, device_t); | | 83 | void uhidev_childdet(device_t, device_t); |
82 | int uhidev_detach(device_t, int); | | 84 | int uhidev_detach(device_t, int); |
83 | int uhidev_activate(device_t, enum devact); | | 85 | int uhidev_activate(device_t, enum devact); |
84 | extern struct cfdriver uhidev_cd; | | 86 | extern struct cfdriver uhidev_cd; |
85 | CFATTACH_DECL2_NEW(uhidev, sizeof(struct uhidev_softc), uhidev_match, | | 87 | CFATTACH_DECL2_NEW(uhidev, sizeof(struct uhidev_softc), uhidev_match, |
86 | uhidev_attach, uhidev_detach, uhidev_activate, NULL, uhidev_childdet); | | 88 | uhidev_attach, uhidev_detach, uhidev_activate, NULL, uhidev_childdet); |
87 | | | 89 | |
88 | int | | 90 | int |
89 | uhidev_match(device_t parent, cfdata_t match, void *aux) | | 91 | uhidev_match(device_t parent, cfdata_t match, void *aux) |
90 | { | | 92 | { |
91 | struct usbif_attach_arg *uaa = aux; | | 93 | struct usbif_attach_arg *uaa = aux; |
92 | | | 94 | |
| | | 95 | /* Game controllers in "XInput" mode */ |
| | | 96 | if (USBIF_IS_XINPUT(uaa)) |
| | | 97 | return UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO; |
93 | if (uaa->class != UICLASS_HID) | | 98 | if (uaa->class != UICLASS_HID) |
94 | return (UMATCH_NONE); | | 99 | return (UMATCH_NONE); |
95 | if (usbd_get_quirks(uaa->device)->uq_flags & UQ_HID_IGNORE) | | 100 | if (usbd_get_quirks(uaa->device)->uq_flags & UQ_HID_IGNORE) |
96 | return (UMATCH_NONE); | | 101 | return (UMATCH_NONE); |
97 | return (UMATCH_IFACECLASS_GENERIC); | | 102 | return (UMATCH_IFACECLASS_GENERIC); |
98 | } | | 103 | } |
99 | | | 104 | |
100 | void | | 105 | void |
101 | uhidev_attach(device_t parent, device_t self, void *aux) | | 106 | uhidev_attach(device_t parent, device_t self, void *aux) |
102 | { | | 107 | { |
103 | struct uhidev_softc *sc = device_private(self); | | 108 | struct uhidev_softc *sc = device_private(self); |
104 | struct usbif_attach_arg *uaa = aux; | | 109 | struct usbif_attach_arg *uaa = aux; |
105 | usbd_interface_handle iface = uaa->iface; | | 110 | usbd_interface_handle iface = uaa->iface; |
106 | usb_interface_descriptor_t *id; | | 111 | usb_interface_descriptor_t *id; |
107 | usb_endpoint_descriptor_t *ed; | | 112 | usb_endpoint_descriptor_t *ed; |
108 | struct uhidev_attach_arg uha; | | 113 | struct uhidev_attach_arg uha; |
109 | device_t dev; | | 114 | device_t dev; |
110 | struct uhidev *csc; | | 115 | struct uhidev *csc; |
111 | int maxinpktsize, size, nrepid, repid, repsz; | | 116 | int maxinpktsize, size, nrepid, repid, repsz; |
112 | int *repsizes; | | 117 | int *repsizes; |
113 | int i; | | 118 | int i; |
114 | void *desc; | | 119 | void *desc; |
115 | const void *descptr; | | 120 | const void *descptr; |
116 | usbd_status err; | | 121 | usbd_status err; |
117 | char *devinfop; | | 122 | char *devinfop; |
118 | int locs[UHIDBUSCF_NLOCS]; | | 123 | int locs[UHIDBUSCF_NLOCS]; |
119 | | | 124 | |
120 | sc->sc_dev = self; | | 125 | sc->sc_dev = self; |
121 | sc->sc_udev = uaa->device; | | 126 | sc->sc_udev = uaa->device; |
122 | sc->sc_iface = iface; | | 127 | sc->sc_iface = iface; |
123 | | | 128 | |
124 | aprint_naive("\n"); | | 129 | aprint_naive("\n"); |
125 | aprint_normal("\n"); | | 130 | aprint_normal("\n"); |
126 | | | 131 | |
127 | id = usbd_get_interface_descriptor(iface); | | 132 | id = usbd_get_interface_descriptor(iface); |
128 | | | 133 | |
129 | devinfop = usbd_devinfo_alloc(uaa->device, 0); | | 134 | devinfop = usbd_devinfo_alloc(uaa->device, 0); |
130 | aprint_normal_dev(self, "%s, iclass %d/%d\n", | | 135 | aprint_normal_dev(self, "%s, iclass %d/%d\n", |
131 | devinfop, id->bInterfaceClass, id->bInterfaceSubClass); | | 136 | devinfop, id->bInterfaceClass, id->bInterfaceSubClass); |
132 | usbd_devinfo_free(devinfop); | | 137 | usbd_devinfo_free(devinfop); |
133 | | | 138 | |
134 | if (!pmf_device_register(self, NULL, NULL)) | | 139 | if (!pmf_device_register(self, NULL, NULL)) |
135 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 140 | aprint_error_dev(self, "couldn't establish power handler\n"); |
136 | | | 141 | |
137 | (void)usbd_set_idle(iface, 0, 0); | | 142 | (void)usbd_set_idle(iface, 0, 0); |
138 | #if 0 | | 143 | #if 0 |
139 | | | 144 | |
140 | qflags = usbd_get_quirks(sc->sc_udev)->uq_flags; | | 145 | qflags = usbd_get_quirks(sc->sc_udev)->uq_flags; |
141 | if ((qflags & UQ_NO_SET_PROTO) == 0 && | | 146 | if ((qflags & UQ_NO_SET_PROTO) == 0 && |
142 | id->bInterfaceSubClass != UISUBCLASS_BOOT) | | 147 | id->bInterfaceSubClass != UISUBCLASS_BOOT) |
143 | (void)usbd_set_protocol(iface, 1); | | 148 | (void)usbd_set_protocol(iface, 1); |
144 | #endif | | 149 | #endif |
145 | | | 150 | |
146 | maxinpktsize = 0; | | 151 | maxinpktsize = 0; |
147 | sc->sc_iep_addr = sc->sc_oep_addr = -1; | | 152 | sc->sc_iep_addr = sc->sc_oep_addr = -1; |
148 | for (i = 0; i < id->bNumEndpoints; i++) { | | 153 | for (i = 0; i < id->bNumEndpoints; i++) { |
149 | ed = usbd_interface2endpoint_descriptor(iface, i); | | 154 | ed = usbd_interface2endpoint_descriptor(iface, i); |
150 | if (ed == NULL) { | | 155 | if (ed == NULL) { |
151 | aprint_error_dev(self, | | 156 | aprint_error_dev(self, |
152 | "could not read endpoint descriptor\n"); | | 157 | "could not read endpoint descriptor\n"); |
153 | sc->sc_dying = 1; | | 158 | sc->sc_dying = 1; |
154 | return; | | 159 | return; |
155 | } | | 160 | } |
156 | | | 161 | |
157 | DPRINTFN(10,("uhidev_attach: bLength=%d bDescriptorType=%d " | | 162 | DPRINTFN(10,("uhidev_attach: bLength=%d bDescriptorType=%d " |
158 | "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d" | | 163 | "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d" |
159 | " bInterval=%d\n", | | 164 | " bInterval=%d\n", |
160 | ed->bLength, ed->bDescriptorType, | | 165 | ed->bLength, ed->bDescriptorType, |
161 | ed->bEndpointAddress & UE_ADDR, | | 166 | ed->bEndpointAddress & UE_ADDR, |
162 | UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out", | | 167 | UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out", |
163 | ed->bmAttributes & UE_XFERTYPE, | | 168 | ed->bmAttributes & UE_XFERTYPE, |
164 | UGETW(ed->wMaxPacketSize), ed->bInterval)); | | 169 | UGETW(ed->wMaxPacketSize), ed->bInterval)); |
165 | | | 170 | |
166 | if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && | | 171 | if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && |
167 | (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { | | 172 | (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { |
168 | maxinpktsize = UGETW(ed->wMaxPacketSize); | | 173 | maxinpktsize = UGETW(ed->wMaxPacketSize); |
169 | sc->sc_iep_addr = ed->bEndpointAddress; | | 174 | sc->sc_iep_addr = ed->bEndpointAddress; |
170 | } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && | | 175 | } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && |
171 | (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { | | 176 | (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { |
172 | sc->sc_oep_addr = ed->bEndpointAddress; | | 177 | sc->sc_oep_addr = ed->bEndpointAddress; |
173 | } else { | | 178 | } else { |
174 | aprint_verbose_dev(self, "endpoint %d: ignored\n", i); | | 179 | aprint_verbose_dev(self, "endpoint %d: ignored\n", i); |
175 | } | | 180 | } |
176 | } | | 181 | } |
177 | | | 182 | |
178 | /* | | 183 | /* |
179 | * Check that we found an input interrupt endpoint. The output interrupt | | 184 | * Check that we found an input interrupt endpoint. The output interrupt |
180 | * endpoint is optional | | 185 | * endpoint is optional |
181 | */ | | 186 | */ |
182 | if (sc->sc_iep_addr == -1) { | | 187 | if (sc->sc_iep_addr == -1) { |
183 | aprint_error_dev(self, "no input interrupt endpoint\n"); | | 188 | aprint_error_dev(self, "no input interrupt endpoint\n"); |
184 | sc->sc_dying = 1; | | 189 | sc->sc_dying = 1; |
185 | return; | | 190 | return; |
186 | } | | 191 | } |
187 | | | 192 | |
188 | /* XXX need to extend this */ | | 193 | /* XXX need to extend this */ |
189 | descptr = NULL; | | 194 | descptr = NULL; |
190 | if (uaa->vendor == USB_VENDOR_WACOM) { | | 195 | if (uaa->vendor == USB_VENDOR_WACOM) { |
191 | static uByte reportbuf[] = {2, 2, 2}; | | 196 | static uByte reportbuf[] = {2, 2, 2}; |
192 | | | 197 | |
193 | /* The report descriptor for the Wacom Graphire is broken. */ | | 198 | /* The report descriptor for the Wacom Graphire is broken. */ |
194 | switch (uaa->product) { | | 199 | switch (uaa->product) { |
195 | case USB_PRODUCT_WACOM_GRAPHIRE: | | 200 | case USB_PRODUCT_WACOM_GRAPHIRE: |
196 | case USB_PRODUCT_WACOM_GRAPHIRE2: | | 201 | case USB_PRODUCT_WACOM_GRAPHIRE2: |
197 | case USB_PRODUCT_WACOM_GRAPHIRE3_4X5: | | 202 | case USB_PRODUCT_WACOM_GRAPHIRE3_4X5: |
198 | case USB_PRODUCT_WACOM_GRAPHIRE3_6X8: | | 203 | case USB_PRODUCT_WACOM_GRAPHIRE3_6X8: |
199 | case USB_PRODUCT_WACOM_GRAPHIRE4_4X5: /* The 6x8 too? */ | | 204 | case USB_PRODUCT_WACOM_GRAPHIRE4_4X5: /* The 6x8 too? */ |
200 | /* | | 205 | /* |
201 | * The Graphire3 needs 0x0202 to be written to | | 206 | * The Graphire3 needs 0x0202 to be written to |
202 | * feature report ID 2 before it'll start | | 207 | * feature report ID 2 before it'll start |
203 | * returning digitizer data. | | 208 | * returning digitizer data. |
204 | */ | | 209 | */ |
205 | usbd_set_report(uaa->iface, UHID_FEATURE_REPORT, 2, | | 210 | usbd_set_report(uaa->iface, UHID_FEATURE_REPORT, 2, |
206 | &reportbuf, sizeof reportbuf); | | 211 | &reportbuf, sizeof reportbuf); |
207 | | | 212 | |
208 | size = sizeof uhid_graphire3_4x5_report_descr; | | 213 | size = sizeof uhid_graphire3_4x5_report_descr; |
209 | descptr = uhid_graphire3_4x5_report_descr; | | 214 | descptr = uhid_graphire3_4x5_report_descr; |
210 | break; | | 215 | break; |
211 | default: | | 216 | default: |
212 | /* Keep descriptor */ | | 217 | /* Keep descriptor */ |
213 | break; | | 218 | break; |
214 | } | | 219 | } |
215 | } | | 220 | } |
| | | 221 | if (USBIF_IS_XINPUT(uaa)) { |
| | | 222 | size = sizeof uhid_xinput_report_descr; |
| | | 223 | descptr = uhid_xinput_report_descr; |
| | | 224 | } |
216 | | | 225 | |
217 | if (descptr) { | | 226 | if (descptr) { |
218 | desc = malloc(size, M_USBDEV, M_NOWAIT); | | 227 | desc = malloc(size, M_USBDEV, M_NOWAIT); |
219 | if (desc == NULL) | | 228 | if (desc == NULL) |
220 | err = USBD_NOMEM; | | 229 | err = USBD_NOMEM; |
221 | else { | | 230 | else { |
222 | err = USBD_NORMAL_COMPLETION; | | 231 | err = USBD_NORMAL_COMPLETION; |
223 | memcpy(desc, descptr, size); | | 232 | memcpy(desc, descptr, size); |
224 | } | | 233 | } |
225 | } else { | | 234 | } else { |
226 | desc = NULL; | | 235 | desc = NULL; |
227 | err = usbd_read_report_desc(uaa->iface, &desc, &size, | | 236 | err = usbd_read_report_desc(uaa->iface, &desc, &size, |
228 | M_USBDEV); | | 237 | M_USBDEV); |
229 | } | | 238 | } |
230 | if (err) { | | 239 | if (err) { |
231 | aprint_error_dev(self, "no report descriptor\n"); | | 240 | aprint_error_dev(self, "no report descriptor\n"); |
232 | sc->sc_dying = 1; | | 241 | sc->sc_dying = 1; |
233 | return; | | 242 | return; |
234 | } | | 243 | } |
235 | | | 244 | |
236 | if (uaa->vendor == USB_VENDOR_HOSIDEN && | | 245 | if (uaa->vendor == USB_VENDOR_HOSIDEN && |
237 | uaa->product == USB_PRODUCT_HOSIDEN_PPP) { | | 246 | uaa->product == USB_PRODUCT_HOSIDEN_PPP) { |
238 | static uByte reportbuf[] = { 1 }; | | 247 | static uByte reportbuf[] = { 1 }; |
239 | /* | | 248 | /* |
240 | * This device was sold by Konami with its ParaParaParadise | | 249 | * This device was sold by Konami with its ParaParaParadise |
241 | * game for PlayStation2. It needs to be "turned on" | | 250 | * game for PlayStation2. It needs to be "turned on" |
242 | * before it will send any reports. | | 251 | * before it will send any reports. |
243 | */ | | 252 | */ |
244 | | | 253 | |
245 | usbd_set_report(uaa->iface, UHID_FEATURE_REPORT, 0, | | 254 | usbd_set_report(uaa->iface, UHID_FEATURE_REPORT, 0, |
246 | &reportbuf, sizeof reportbuf); | | 255 | &reportbuf, sizeof reportbuf); |
247 | } | | 256 | } |
248 | | | 257 | |
249 | if (uaa->vendor == USB_VENDOR_LOGITECH && | | 258 | if (uaa->vendor == USB_VENDOR_LOGITECH && |
250 | uaa->product == USB_PRODUCT_LOGITECH_CBT44 && size == 0xb1) { | | 259 | uaa->product == USB_PRODUCT_LOGITECH_CBT44 && size == 0xb1) { |
251 | uint8_t *data = desc; | | 260 | uint8_t *data = desc; |
252 | /* | | 261 | /* |
253 | * This device has a odd USAGE_MINIMUM value that would | | 262 | * This device has a odd USAGE_MINIMUM value that would |
254 | * cause the multimedia keys to have their usage number | | 263 | * cause the multimedia keys to have their usage number |
255 | * shifted up one usage. Adjust so the usages are sane. | | 264 | * shifted up one usage. Adjust so the usages are sane. |
256 | */ | | 265 | */ |
257 | | | 266 | |
258 | if (data[0x56] == 0x19 && data[0x57] == 0x01 && | | 267 | if (data[0x56] == 0x19 && data[0x57] == 0x01 && |
259 | data[0x58] == 0x2a && data[0x59] == 0x8c) | | 268 | data[0x58] == 0x2a && data[0x59] == 0x8c) |
260 | data[0x57] = 0x00; | | 269 | data[0x57] = 0x00; |
261 | } | | 270 | } |
262 | | | 271 | |
263 | sc->sc_repdesc = desc; | | 272 | sc->sc_repdesc = desc; |
264 | sc->sc_repdesc_size = size; | | 273 | sc->sc_repdesc_size = size; |
265 | | | 274 | |
266 | uha.uaa = uaa; | | 275 | uha.uaa = uaa; |
267 | nrepid = uhidev_maxrepid(desc, size); | | 276 | nrepid = uhidev_maxrepid(desc, size); |
268 | if (nrepid < 0) | | 277 | if (nrepid < 0) |
269 | return; | | 278 | return; |
270 | if (nrepid > 0) | | 279 | if (nrepid > 0) |
271 | aprint_normal_dev(self, "%d report ids\n", nrepid); | | 280 | aprint_normal_dev(self, "%d report ids\n", nrepid); |
272 | nrepid++; | | 281 | nrepid++; |
273 | repsizes = malloc(nrepid * sizeof(*repsizes), M_TEMP, M_NOWAIT); | | 282 | repsizes = malloc(nrepid * sizeof(*repsizes), M_TEMP, M_NOWAIT); |
274 | if (repsizes == NULL) | | 283 | if (repsizes == NULL) |
275 | goto nomem; | | 284 | goto nomem; |
276 | sc->sc_subdevs = malloc(nrepid * sizeof(device_t), | | 285 | sc->sc_subdevs = malloc(nrepid * sizeof(device_t), |
277 | M_USBDEV, M_NOWAIT | M_ZERO); | | 286 | M_USBDEV, M_NOWAIT | M_ZERO); |
278 | if (sc->sc_subdevs == NULL) { | | 287 | if (sc->sc_subdevs == NULL) { |
279 | free(repsizes, M_TEMP); | | 288 | free(repsizes, M_TEMP); |
280 | nomem: | | 289 | nomem: |
281 | aprint_error_dev(self, "no memory\n"); | | 290 | aprint_error_dev(self, "no memory\n"); |
282 | return; | | 291 | return; |
283 | } | | 292 | } |
284 | | | 293 | |
285 | /* Just request max packet size for the interrupt pipe */ | | 294 | /* Just request max packet size for the interrupt pipe */ |
286 | sc->sc_isize = maxinpktsize; | | 295 | sc->sc_isize = maxinpktsize; |
287 | sc->sc_nrepid = nrepid; | | 296 | sc->sc_nrepid = nrepid; |
288 | | | 297 | |
289 | usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, | | 298 | usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, |
290 | sc->sc_dev); | | 299 | sc->sc_dev); |
291 | | | 300 | |
292 | for (repid = 0; repid < nrepid; repid++) { | | 301 | for (repid = 0; repid < nrepid; repid++) { |
293 | repsz = hid_report_size(desc, size, hid_input, repid); | | 302 | repsz = hid_report_size(desc, size, hid_input, repid); |
294 | DPRINTF(("uhidev_match: repid=%d, repsz=%d\n", repid, repsz)); | | 303 | DPRINTF(("uhidev_match: repid=%d, repsz=%d\n", repid, repsz)); |
295 | repsizes[repid] = repsz; | | 304 | repsizes[repid] = repsz; |
296 | } | | 305 | } |
297 | | | 306 | |
298 | DPRINTF(("uhidev_attach: isize=%d\n", sc->sc_isize)); | | 307 | DPRINTF(("uhidev_attach: isize=%d\n", sc->sc_isize)); |
299 | | | 308 | |
300 | uha.parent = sc; | | 309 | uha.parent = sc; |
301 | for (repid = 0; repid < nrepid; repid++) { | | 310 | for (repid = 0; repid < nrepid; repid++) { |
302 | DPRINTF(("uhidev_match: try repid=%d\n", repid)); | | 311 | DPRINTF(("uhidev_match: try repid=%d\n", repid)); |
303 | if (hid_report_size(desc, size, hid_input, repid) == 0 && | | 312 | if (hid_report_size(desc, size, hid_input, repid) == 0 && |
304 | hid_report_size(desc, size, hid_output, repid) == 0 && | | 313 | hid_report_size(desc, size, hid_output, repid) == 0 && |
305 | hid_report_size(desc, size, hid_feature, repid) == 0) { | | 314 | hid_report_size(desc, size, hid_feature, repid) == 0) { |
306 | ; /* already NULL in sc->sc_subdevs[repid] */ | | 315 | ; /* already NULL in sc->sc_subdevs[repid] */ |
307 | } else { | | 316 | } else { |
308 | uha.reportid = repid; | | 317 | uha.reportid = repid; |
309 | locs[UHIDBUSCF_REPORTID] = repid; | | 318 | locs[UHIDBUSCF_REPORTID] = repid; |
310 | | | 319 | |
311 | dev = config_found_sm_loc(self, | | 320 | dev = config_found_sm_loc(self, |
312 | "uhidbus", locs, &uha, | | 321 | "uhidbus", locs, &uha, |
313 | uhidevprint, config_stdsubmatch); | | 322 | uhidevprint, config_stdsubmatch); |
314 | sc->sc_subdevs[repid] = dev; | | 323 | sc->sc_subdevs[repid] = dev; |
315 | if (dev != NULL) { | | 324 | if (dev != NULL) { |
316 | csc = device_private(dev); | | 325 | csc = device_private(dev); |
317 | csc->sc_in_rep_size = repsizes[repid]; | | 326 | csc->sc_in_rep_size = repsizes[repid]; |
318 | #ifdef DIAGNOSTIC | | 327 | #ifdef DIAGNOSTIC |
319 | DPRINTF(("uhidev_match: repid=%d dev=%p\n", | | 328 | DPRINTF(("uhidev_match: repid=%d dev=%p\n", |
320 | repid, dev)); | | 329 | repid, dev)); |
321 | if (csc->sc_intr == NULL) { | | 330 | if (csc->sc_intr == NULL) { |
322 | free(repsizes, M_TEMP); | | 331 | free(repsizes, M_TEMP); |
323 | aprint_error_dev(self, | | 332 | aprint_error_dev(self, |
324 | "sc_intr == NULL\n"); | | 333 | "sc_intr == NULL\n"); |
325 | return; | | 334 | return; |
326 | } | | 335 | } |
327 | #endif | | 336 | #endif |
328 | #if NRND > 0 | | 337 | #if NRND > 0 |
329 | rnd_attach_source(&csc->rnd_source, | | 338 | rnd_attach_source(&csc->rnd_source, |
330 | device_xname(dev), | | 339 | device_xname(dev), |
331 | RND_TYPE_TTY, 0); | | 340 | RND_TYPE_TTY, 0); |
332 | #endif | | 341 | #endif |
333 | } | | 342 | } |
334 | } | | 343 | } |
335 | } | | 344 | } |
336 | free(repsizes, M_TEMP); | | 345 | free(repsizes, M_TEMP); |
337 | | | 346 | |
338 | return; | | 347 | return; |
339 | } | | 348 | } |
340 | | | 349 | |
341 | int | | 350 | int |
342 | uhidev_maxrepid(void *buf, int len) | | 351 | uhidev_maxrepid(void *buf, int len) |
343 | { | | 352 | { |
344 | struct hid_data *d; | | 353 | struct hid_data *d; |
345 | struct hid_item h; | | 354 | struct hid_item h; |
346 | int maxid; | | 355 | int maxid; |
347 | | | 356 | |
348 | maxid = -1; | | 357 | maxid = -1; |
349 | h.report_ID = 0; | | 358 | h.report_ID = 0; |
350 | for (d = hid_start_parse(buf, len, hid_none); hid_get_item(d, &h); ) | | 359 | for (d = hid_start_parse(buf, len, hid_none); hid_get_item(d, &h); ) |
351 | if (h.report_ID > maxid) | | 360 | if (h.report_ID > maxid) |
352 | maxid = h.report_ID; | | 361 | maxid = h.report_ID; |
353 | hid_end_parse(d); | | 362 | hid_end_parse(d); |
354 | return (maxid); | | 363 | return (maxid); |
355 | } | | 364 | } |
356 | | | 365 | |
357 | int | | 366 | int |
358 | uhidevprint(void *aux, const char *pnp) | | 367 | uhidevprint(void *aux, const char *pnp) |
359 | { | | 368 | { |
360 | struct uhidev_attach_arg *uha = aux; | | 369 | struct uhidev_attach_arg *uha = aux; |
361 | | | 370 | |
362 | if (pnp) | | 371 | if (pnp) |
363 | aprint_normal("uhid at %s", pnp); | | 372 | aprint_normal("uhid at %s", pnp); |
364 | if (uha->reportid != 0) | | 373 | if (uha->reportid != 0) |
365 | aprint_normal(" reportid %d", uha->reportid); | | 374 | aprint_normal(" reportid %d", uha->reportid); |
366 | return (UNCONF); | | 375 | return (UNCONF); |
367 | } | | 376 | } |
368 | | | 377 | |
369 | int | | 378 | int |
370 | uhidev_activate(device_t self, enum devact act) | | 379 | uhidev_activate(device_t self, enum devact act) |
371 | { | | 380 | { |
372 | struct uhidev_softc *sc = device_private(self); | | 381 | struct uhidev_softc *sc = device_private(self); |
373 | | | 382 | |
374 | switch (act) { | | 383 | switch (act) { |
375 | case DVACT_DEACTIVATE: | | 384 | case DVACT_DEACTIVATE: |
376 | sc->sc_dying = 1; | | 385 | sc->sc_dying = 1; |
377 | return 0; | | 386 | return 0; |
378 | default: | | 387 | default: |
379 | return EOPNOTSUPP; | | 388 | return EOPNOTSUPP; |
380 | } | | 389 | } |
381 | } | | 390 | } |
382 | | | 391 | |
383 | void | | 392 | void |
384 | uhidev_childdet(device_t self, device_t child) | | 393 | uhidev_childdet(device_t self, device_t child) |
385 | { | | 394 | { |
386 | int i; | | 395 | int i; |
387 | struct uhidev_softc *sc = device_private(self); | | 396 | struct uhidev_softc *sc = device_private(self); |
388 | | | 397 | |
389 | for (i = 0; i < sc->sc_nrepid; i++) { | | 398 | for (i = 0; i < sc->sc_nrepid; i++) { |
390 | if (sc->sc_subdevs[i] == child) | | 399 | if (sc->sc_subdevs[i] == child) |
391 | break; | | 400 | break; |
392 | } | | 401 | } |
393 | KASSERT(i < sc->sc_nrepid); | | 402 | KASSERT(i < sc->sc_nrepid); |
394 | sc->sc_subdevs[i] = NULL; | | 403 | sc->sc_subdevs[i] = NULL; |
395 | } | | 404 | } |
396 | | | 405 | |
397 | int | | 406 | int |
398 | uhidev_detach(device_t self, int flags) | | 407 | uhidev_detach(device_t self, int flags) |
399 | { | | 408 | { |
400 | struct uhidev_softc *sc = device_private(self); | | 409 | struct uhidev_softc *sc = device_private(self); |
401 | int i, rv; | | 410 | int i, rv; |
402 | #if NRND > 0 | | 411 | #if NRND > 0 |
403 | struct uhidev *csc; | | 412 | struct uhidev *csc; |
404 | #endif | | 413 | #endif |
405 | | | 414 | |
406 | DPRINTF(("uhidev_detach: sc=%p flags=%d\n", sc, flags)); | | 415 | DPRINTF(("uhidev_detach: sc=%p flags=%d\n", sc, flags)); |
407 | | | 416 | |
408 | sc->sc_dying = 1; | | 417 | sc->sc_dying = 1; |
409 | if (sc->sc_ipipe != NULL) | | 418 | if (sc->sc_ipipe != NULL) |
410 | usbd_abort_pipe(sc->sc_ipipe); | | 419 | usbd_abort_pipe(sc->sc_ipipe); |
411 | | | 420 | |
412 | if (sc->sc_repdesc != NULL) | | 421 | if (sc->sc_repdesc != NULL) |
413 | free(sc->sc_repdesc, M_USBDEV); | | 422 | free(sc->sc_repdesc, M_USBDEV); |
414 | | | 423 | |
415 | rv = 0; | | 424 | rv = 0; |
416 | for (i = 0; i < sc->sc_nrepid; i++) { | | 425 | for (i = 0; i < sc->sc_nrepid; i++) { |
417 | if (sc->sc_subdevs[i] != NULL) { | | 426 | if (sc->sc_subdevs[i] != NULL) { |
418 | #if NRND > 0 | | 427 | #if NRND > 0 |
419 | csc = device_private(sc->sc_subdevs[i]); | | 428 | csc = device_private(sc->sc_subdevs[i]); |
420 | rnd_detach_source(&csc->rnd_source); | | 429 | rnd_detach_source(&csc->rnd_source); |
421 | #endif | | 430 | #endif |
422 | rv |= config_detach(sc->sc_subdevs[i], flags); | | 431 | rv |= config_detach(sc->sc_subdevs[i], flags); |
423 | } | | 432 | } |
424 | } | | 433 | } |
425 | | | 434 | |
426 | usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, | | 435 | usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, |
427 | sc->sc_dev); | | 436 | sc->sc_dev); |
428 | | | 437 | |
429 | pmf_device_deregister(self); | | 438 | pmf_device_deregister(self); |
430 | | | 439 | |
431 | return (rv); | | 440 | return (rv); |
432 | } | | 441 | } |
433 | | | 442 | |
434 | void | | 443 | void |
435 | uhidev_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status) | | 444 | uhidev_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status) |
436 | { | | 445 | { |
437 | struct uhidev_softc *sc = addr; | | 446 | struct uhidev_softc *sc = addr; |
438 | device_t cdev; | | 447 | device_t cdev; |
439 | struct uhidev *scd; | | 448 | struct uhidev *scd; |
440 | u_char *p; | | 449 | u_char *p; |
441 | u_int rep; | | 450 | u_int rep; |
442 | u_int32_t cc; | | 451 | u_int32_t cc; |
443 | | | 452 | |
444 | usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL); | | 453 | usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL); |
445 | | | 454 | |
446 | #ifdef UHIDEV_DEBUG | | 455 | #ifdef UHIDEV_DEBUG |
447 | if (uhidevdebug > 5) { | | 456 | if (uhidevdebug > 5) { |
448 | u_int32_t i; | | 457 | u_int32_t i; |
449 | | | 458 | |
450 | DPRINTF(("uhidev_intr: status=%d cc=%d\n", status, cc)); | | 459 | DPRINTF(("uhidev_intr: status=%d cc=%d\n", status, cc)); |
451 | DPRINTF(("uhidev_intr: data =")); | | 460 | DPRINTF(("uhidev_intr: data =")); |
452 | for (i = 0; i < cc; i++) | | 461 | for (i = 0; i < cc; i++) |
453 | DPRINTF((" %02x", sc->sc_ibuf[i])); | | 462 | DPRINTF((" %02x", sc->sc_ibuf[i])); |
454 | DPRINTF(("\n")); | | 463 | DPRINTF(("\n")); |
455 | } | | 464 | } |
456 | #endif | | 465 | #endif |
457 | | | 466 | |
458 | if (status == USBD_CANCELLED) | | 467 | if (status == USBD_CANCELLED) |
459 | return; | | 468 | return; |
460 | | | 469 | |
461 | if (status != USBD_NORMAL_COMPLETION) { | | 470 | if (status != USBD_NORMAL_COMPLETION) { |
462 | DPRINTF(("%s: interrupt status=%d\n", device_xname(sc->sc_dev), | | 471 | DPRINTF(("%s: interrupt status=%d\n", device_xname(sc->sc_dev), |
463 | status)); | | 472 | status)); |
464 | usbd_clear_endpoint_stall_async(sc->sc_ipipe); | | 473 | usbd_clear_endpoint_stall_async(sc->sc_ipipe); |
465 | return; | | 474 | return; |
466 | } | | 475 | } |
467 | | | 476 | |
468 | p = sc->sc_ibuf; | | 477 | p = sc->sc_ibuf; |
469 | if (sc->sc_nrepid != 1) | | 478 | if (sc->sc_nrepid != 1) |
470 | rep = *p++, cc--; | | 479 | rep = *p++, cc--; |
471 | else | | 480 | else |
472 | rep = 0; | | 481 | rep = 0; |
473 | if (rep >= sc->sc_nrepid) { | | 482 | if (rep >= sc->sc_nrepid) { |
474 | printf("uhidev_intr: bad repid %d\n", rep); | | 483 | printf("uhidev_intr: bad repid %d\n", rep); |
475 | return; | | 484 | return; |
476 | } | | 485 | } |
477 | cdev = sc->sc_subdevs[rep]; | | 486 | cdev = sc->sc_subdevs[rep]; |
478 | if (!cdev) | | 487 | if (!cdev) |
479 | return; | | 488 | return; |
480 | scd = device_private(cdev); | | 489 | scd = device_private(cdev); |
481 | DPRINTFN(5,("uhidev_intr: rep=%d, scd=%p state=0x%x\n", | | 490 | DPRINTFN(5,("uhidev_intr: rep=%d, scd=%p state=0x%x\n", |
482 | rep, scd, scd ? scd->sc_state : 0)); | | 491 | rep, scd, scd ? scd->sc_state : 0)); |
483 | if (!(scd->sc_state & UHIDEV_OPEN)) | | 492 | if (!(scd->sc_state & UHIDEV_OPEN)) |
484 | return; | | 493 | return; |
485 | #ifdef UHIDEV_DEBUG | | 494 | #ifdef UHIDEV_DEBUG |
486 | if (scd->sc_in_rep_size != cc) { | | 495 | if (scd->sc_in_rep_size != cc) { |
487 | DPRINTF(("%s: expected %d bytes, got %d\n", | | 496 | DPRINTF(("%s: expected %d bytes, got %d\n", |
488 | device_xname(sc->sc_dev), scd->sc_in_rep_size, cc)); | | 497 | device_xname(sc->sc_dev), scd->sc_in_rep_size, cc)); |
489 | } | | 498 | } |
490 | #endif | | 499 | #endif |
491 | if (cc == 0) { | | 500 | if (cc == 0) { |
492 | DPRINTF(("%s: 0-length input ignored\n", | | 501 | DPRINTF(("%s: 0-length input ignored\n", |
493 | device_xname(sc->sc_dev))); | | 502 | device_xname(sc->sc_dev))); |
494 | return; | | 503 | return; |
495 | } | | 504 | } |
496 | #if NRND > 0 | | 505 | #if NRND > 0 |
497 | rnd_add_uint32(&scd->rnd_source, (uintptr_t)(sc->sc_ibuf)); | | 506 | rnd_add_uint32(&scd->rnd_source, (uintptr_t)(sc->sc_ibuf)); |
498 | #endif | | 507 | #endif |
499 | scd->sc_intr(scd, p, cc); | | 508 | scd->sc_intr(scd, p, cc); |
500 | } | | 509 | } |
501 | | | 510 | |
502 | void | | 511 | void |
503 | uhidev_get_report_desc(struct uhidev_softc *sc, void **desc, int *size) | | 512 | uhidev_get_report_desc(struct uhidev_softc *sc, void **desc, int *size) |
504 | { | | 513 | { |
505 | *desc = sc->sc_repdesc; | | 514 | *desc = sc->sc_repdesc; |
506 | *size = sc->sc_repdesc_size; | | 515 | *size = sc->sc_repdesc_size; |
507 | } | | 516 | } |
508 | | | 517 | |
509 | int | | 518 | int |
510 | uhidev_open(struct uhidev *scd) | | 519 | uhidev_open(struct uhidev *scd) |
511 | { | | 520 | { |
512 | struct uhidev_softc *sc = scd->sc_parent; | | 521 | struct uhidev_softc *sc = scd->sc_parent; |
513 | usbd_status err; | | 522 | usbd_status err; |
514 | int error; | | 523 | int error; |
515 | | | 524 | |
516 | DPRINTF(("uhidev_open: open pipe, state=%d refcnt=%d\n", | | 525 | DPRINTF(("uhidev_open: open pipe, state=%d refcnt=%d\n", |
517 | scd->sc_state, sc->sc_refcnt)); | | 526 | scd->sc_state, sc->sc_refcnt)); |
518 | | | 527 | |
519 | if (scd->sc_state & UHIDEV_OPEN) | | 528 | if (scd->sc_state & UHIDEV_OPEN) |
520 | return (EBUSY); | | 529 | return (EBUSY); |
521 | scd->sc_state |= UHIDEV_OPEN; | | 530 | scd->sc_state |= UHIDEV_OPEN; |
522 | if (sc->sc_refcnt++) | | 531 | if (sc->sc_refcnt++) |
523 | return (0); | | 532 | return (0); |
524 | | | 533 | |
525 | if (sc->sc_isize == 0) | | 534 | if (sc->sc_isize == 0) |
526 | return (0); | | 535 | return (0); |
527 | | | 536 | |
528 | sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK); | | 537 | sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK); |
529 | | | 538 | |
530 | /* Set up input interrupt pipe. */ | | 539 | /* Set up input interrupt pipe. */ |
531 | DPRINTF(("uhidev_open: isize=%d, ep=0x%02x\n", sc->sc_isize, | | 540 | DPRINTF(("uhidev_open: isize=%d, ep=0x%02x\n", sc->sc_isize, |
532 | sc->sc_iep_addr)); | | 541 | sc->sc_iep_addr)); |
533 | | | 542 | |
534 | err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_iep_addr, | | 543 | err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_iep_addr, |
535 | USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_ibuf, | | 544 | USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_ibuf, |
536 | sc->sc_isize, uhidev_intr, USBD_DEFAULT_INTERVAL); | | 545 | sc->sc_isize, uhidev_intr, USBD_DEFAULT_INTERVAL); |
537 | if (err != USBD_NORMAL_COMPLETION) { | | 546 | if (err != USBD_NORMAL_COMPLETION) { |
538 | DPRINTF(("uhidopen: usbd_open_pipe_intr failed, " | | 547 | DPRINTF(("uhidopen: usbd_open_pipe_intr failed, " |
539 | "error=%d\n", err)); | | 548 | "error=%d\n", err)); |
540 | error = EIO; | | 549 | error = EIO; |
541 | goto out1; | | 550 | goto out1; |
542 | } | | 551 | } |
543 | | | 552 | |
544 | /* | | 553 | /* |
545 | * Set up output interrupt pipe if an output interrupt endpoint | | 554 | * Set up output interrupt pipe if an output interrupt endpoint |
546 | * exists. | | 555 | * exists. |
547 | */ | | 556 | */ |
548 | if (sc->sc_oep_addr != -1) { | | 557 | if (sc->sc_oep_addr != -1) { |
549 | DPRINTF(("uhidev_open: oep=0x%02x\n", sc->sc_oep_addr)); | | 558 | DPRINTF(("uhidev_open: oep=0x%02x\n", sc->sc_oep_addr)); |
550 | | | 559 | |
551 | err = usbd_open_pipe(sc->sc_iface, sc->sc_oep_addr, | | 560 | err = usbd_open_pipe(sc->sc_iface, sc->sc_oep_addr, |
552 | 0, &sc->sc_opipe); | | 561 | 0, &sc->sc_opipe); |
553 | | | 562 | |
554 | if (err != USBD_NORMAL_COMPLETION) { | | 563 | if (err != USBD_NORMAL_COMPLETION) { |
555 | DPRINTF(("uhidev_open: usbd_open_pipe failed, " | | 564 | DPRINTF(("uhidev_open: usbd_open_pipe failed, " |
556 | "error=%d\n", err)); | | 565 | "error=%d\n", err)); |
557 | error = EIO; | | 566 | error = EIO; |
558 | goto out2; | | 567 | goto out2; |
559 | } | | 568 | } |
560 | DPRINTF(("uhidev_open: sc->sc_opipe=%p\n", sc->sc_opipe)); | | 569 | DPRINTF(("uhidev_open: sc->sc_opipe=%p\n", sc->sc_opipe)); |
561 | | | 570 | |
562 | sc->sc_oxfer = usbd_alloc_xfer(sc->sc_udev); | | 571 | sc->sc_oxfer = usbd_alloc_xfer(sc->sc_udev); |
563 | if (sc->sc_oxfer == NULL) { | | 572 | if (sc->sc_oxfer == NULL) { |
564 | DPRINTF(("uhidev_open: couldn't allocate an xfer\n")); | | 573 | DPRINTF(("uhidev_open: couldn't allocate an xfer\n")); |
565 | error = ENOMEM; | | 574 | error = ENOMEM; |
566 | goto out3; | | 575 | goto out3; |
567 | } | | 576 | } |
568 | } | | 577 | } |
569 | | | 578 | |
570 | return (0); | | 579 | return (0); |
571 | out3: | | 580 | out3: |
572 | /* Abort output pipe */ | | 581 | /* Abort output pipe */ |
573 | usbd_close_pipe(sc->sc_opipe); | | 582 | usbd_close_pipe(sc->sc_opipe); |
574 | out2: | | 583 | out2: |
575 | /* Abort input pipe */ | | 584 | /* Abort input pipe */ |
576 | usbd_close_pipe(sc->sc_ipipe); | | 585 | usbd_close_pipe(sc->sc_ipipe); |
577 | out1: | | 586 | out1: |
578 | DPRINTF(("uhidev_open: failed in someway")); | | 587 | DPRINTF(("uhidev_open: failed in someway")); |
579 | free(sc->sc_ibuf, M_USBDEV); | | 588 | free(sc->sc_ibuf, M_USBDEV); |
580 | scd->sc_state &= ~UHIDEV_OPEN; | | 589 | scd->sc_state &= ~UHIDEV_OPEN; |
581 | sc->sc_refcnt = 0; | | 590 | sc->sc_refcnt = 0; |
582 | sc->sc_ipipe = NULL; | | 591 | sc->sc_ipipe = NULL; |
583 | sc->sc_opipe = NULL; | | 592 | sc->sc_opipe = NULL; |
584 | sc->sc_oxfer = NULL; | | 593 | sc->sc_oxfer = NULL; |
585 | return error; | | 594 | return error; |
586 | } | | 595 | } |
587 | | | 596 | |
588 | void | | 597 | void |
589 | uhidev_close(struct uhidev *scd) | | 598 | uhidev_close(struct uhidev *scd) |
590 | { | | 599 | { |
591 | struct uhidev_softc *sc = scd->sc_parent; | | 600 | struct uhidev_softc *sc = scd->sc_parent; |
592 | | | 601 | |
593 | if (!(scd->sc_state & UHIDEV_OPEN)) | | 602 | if (!(scd->sc_state & UHIDEV_OPEN)) |
594 | return; | | 603 | return; |
595 | scd->sc_state &= ~UHIDEV_OPEN; | | 604 | scd->sc_state &= ~UHIDEV_OPEN; |
596 | if (--sc->sc_refcnt) | | 605 | if (--sc->sc_refcnt) |
597 | return; | | 606 | return; |
598 | DPRINTF(("uhidev_close: close pipe\n")); | | 607 | DPRINTF(("uhidev_close: close pipe\n")); |
599 | | | 608 | |
600 | if (sc->sc_oxfer != NULL) | | 609 | if (sc->sc_oxfer != NULL) |
601 | usbd_free_xfer(sc->sc_oxfer); | | 610 | usbd_free_xfer(sc->sc_oxfer); |
602 | | | 611 | |
603 | /* Disable interrupts. */ | | 612 | /* Disable interrupts. */ |
604 | if (sc->sc_opipe != NULL) { | | 613 | if (sc->sc_opipe != NULL) { |
605 | usbd_abort_pipe(sc->sc_opipe); | | 614 | usbd_abort_pipe(sc->sc_opipe); |
606 | usbd_close_pipe(sc->sc_opipe); | | 615 | usbd_close_pipe(sc->sc_opipe); |
607 | sc->sc_opipe = NULL; | | 616 | sc->sc_opipe = NULL; |
608 | } | | 617 | } |
609 | | | 618 | |
610 | if (sc->sc_ipipe != NULL) { | | 619 | if (sc->sc_ipipe != NULL) { |
611 | usbd_abort_pipe(sc->sc_ipipe); | | 620 | usbd_abort_pipe(sc->sc_ipipe); |
612 | usbd_close_pipe(sc->sc_ipipe); | | 621 | usbd_close_pipe(sc->sc_ipipe); |
613 | sc->sc_ipipe = NULL; | | 622 | sc->sc_ipipe = NULL; |
614 | } | | 623 | } |
615 | | | 624 | |
616 | if (sc->sc_ibuf != NULL) { | | 625 | if (sc->sc_ibuf != NULL) { |
617 | free(sc->sc_ibuf, M_USBDEV); | | 626 | free(sc->sc_ibuf, M_USBDEV); |
618 | sc->sc_ibuf = NULL; | | 627 | sc->sc_ibuf = NULL; |
619 | } | | 628 | } |
620 | } | | 629 | } |
621 | | | 630 | |
622 | usbd_status | | 631 | usbd_status |
623 | uhidev_set_report(struct uhidev *scd, int type, void *data, int len) | | 632 | uhidev_set_report(struct uhidev *scd, int type, void *data, int len) |
624 | { | | 633 | { |
625 | char *buf; | | 634 | char *buf; |
626 | usbd_status retstat; | | 635 | usbd_status retstat; |
627 | | | 636 | |
628 | if (scd->sc_report_id == 0) | | 637 | if (scd->sc_report_id == 0) |
629 | return usbd_set_report(scd->sc_parent->sc_iface, type, | | 638 | return usbd_set_report(scd->sc_parent->sc_iface, type, |
630 | scd->sc_report_id, data, len); | | 639 | scd->sc_report_id, data, len); |
631 | | | 640 | |
632 | buf = malloc(len + 1, M_TEMP, M_WAITOK); | | 641 | buf = malloc(len + 1, M_TEMP, M_WAITOK); |
633 | buf[0] = scd->sc_report_id; | | 642 | buf[0] = scd->sc_report_id; |
634 | memcpy(buf+1, data, len); | | 643 | memcpy(buf+1, data, len); |
635 | | | 644 | |
636 | retstat = usbd_set_report(scd->sc_parent->sc_iface, type, | | 645 | retstat = usbd_set_report(scd->sc_parent->sc_iface, type, |
637 | scd->sc_report_id, buf, len + 1); | | 646 | scd->sc_report_id, buf, len + 1); |
638 | | | 647 | |
639 | free(buf, M_TEMP); | | 648 | free(buf, M_TEMP); |
640 | | | 649 | |
641 | return retstat; | | 650 | return retstat; |
642 | } | | 651 | } |
643 | | | 652 | |
644 | void | | 653 | void |
645 | uhidev_set_report_async(struct uhidev *scd, int type, void *data, int len) | | 654 | uhidev_set_report_async(struct uhidev *scd, int type, void *data, int len) |
646 | { | | 655 | { |
647 | /* XXX */ | | 656 | /* XXX */ |
648 | char buf[100]; | | 657 | char buf[100]; |
649 | if (scd->sc_report_id) { | | 658 | if (scd->sc_report_id) { |
650 | buf[0] = scd->sc_report_id; | | 659 | buf[0] = scd->sc_report_id; |
651 | memcpy(buf+1, data, len); | | 660 | memcpy(buf+1, data, len); |
652 | len++; | | 661 | len++; |
653 | data = buf; | | 662 | data = buf; |
654 | } | | 663 | } |
655 | | | 664 | |
656 | usbd_set_report_async(scd->sc_parent->sc_iface, type, | | 665 | usbd_set_report_async(scd->sc_parent->sc_iface, type, |
657 | scd->sc_report_id, data, len); | | 666 | scd->sc_report_id, data, len); |
658 | } | | 667 | } |
659 | | | 668 | |
660 | usbd_status | | 669 | usbd_status |
661 | uhidev_get_report(struct uhidev *scd, int type, void *data, int len) | | 670 | uhidev_get_report(struct uhidev *scd, int type, void *data, int len) |
662 | { | | 671 | { |
663 | return usbd_get_report(scd->sc_parent->sc_iface, type, | | 672 | return usbd_get_report(scd->sc_parent->sc_iface, type, |
664 | scd->sc_report_id, data, len); | | 673 | scd->sc_report_id, data, len); |
665 | } | | 674 | } |
666 | | | 675 | |
667 | usbd_status | | 676 | usbd_status |
668 | uhidev_write(struct uhidev_softc *sc, void *data, int len) | | 677 | uhidev_write(struct uhidev_softc *sc, void *data, int len) |
669 | { | | 678 | { |
670 | | | 679 | |
671 | DPRINTF(("uhidev_write: data=%p, len=%d\n", data, len)); | | 680 | DPRINTF(("uhidev_write: data=%p, len=%d\n", data, len)); |
672 | | | 681 | |
673 | if (sc->sc_opipe == NULL) | | 682 | if (sc->sc_opipe == NULL) |
674 | return USBD_INVAL; | | 683 | return USBD_INVAL; |
675 | | | 684 | |
676 | #ifdef UHIDEV_DEBUG | | 685 | #ifdef UHIDEV_DEBUG |
677 | if (uhidevdebug > 50) { | | 686 | if (uhidevdebug > 50) { |
678 | | | 687 | |
679 | u_int32_t i; | | 688 | u_int32_t i; |
680 | u_int8_t *d = data; | | 689 | u_int8_t *d = data; |
681 | | | 690 | |
682 | DPRINTF(("uhidev_write: data =")); | | 691 | DPRINTF(("uhidev_write: data =")); |
683 | for (i = 0; i < len; i++) | | 692 | for (i = 0; i < len; i++) |
684 | DPRINTF((" %02x", d[i])); | | 693 | DPRINTF((" %02x", d[i])); |
685 | DPRINTF(("\n")); | | 694 | DPRINTF(("\n")); |
686 | } | | 695 | } |
687 | #endif | | 696 | #endif |
688 | return usbd_intr_transfer(sc->sc_oxfer, sc->sc_opipe, 0, | | 697 | return usbd_intr_transfer(sc->sc_oxfer, sc->sc_opipe, 0, |
689 | USBD_NO_TIMEOUT, data, &len, "uhidevwi"); | | 698 | USBD_NO_TIMEOUT, data, &len, "uhidevwi"); |
690 | } | | 699 | } |