usbhid.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /* USB HID devices: mice, keyboards and the Logitech Unifying receiver.
  2. *
  3. * The probe claims every HID interface it understands: boot mouse/keyboard
  4. * (class 3 / subclass 1 / protocol 2 or 1), report-protocol HID interfaces
  5. * whose report descriptor says "mouse"/"pointer" or "keyboard" (class 3,
  6. * other subclasses — many modern and composite devices), and the vendor
  7. * DJ interface of a Logitech Unifying receiver. Each claimed interface
  8. * gets its own interrupt slot, so a composite device (keyboard + mouse in
  9. * one) and several devices can coexist.
  10. *
  11. * Mouse reports are handed back to mouse.c; keyboard reports are decoded
  12. * into PS/2 set-1 scancodes and injected into the regular input queue
  13. * (io_inject_scancode), so the terminal/WM see them exactly like a PS/2
  14. * keyboard. Root ports are watched so devices can be plugged in later. */
  15. #include "usbhid.h"
  16. #include "io.h"
  17. #include "usb.h"
  18. #include "serial.h"
  19. #include "timer.h"
  20. /* Request types/requests used here. */
  21. #define RT_HOST2DEV_STD 0x00u
  22. #define RT_HOST2DEV_CLS 0x21u
  23. #define RT_DEV2HOST_CLS_IF 0x81u /* class request to an interface, IN */
  24. #define REQ_GET_DESCRIPTOR 0x06u
  25. #define REQ_SET_CONFIGURATION 0x09u
  26. #define REQ_SET_PROTOCOL 0x0Bu
  27. /* Hotplug watcher period (must match usb.c's internal throttle). */
  28. #define WATCH_MS 250
  29. /* Extended (0xE0-prefixed) PS/2 make codes in the mapping table. */
  30. #define K_EXT 0xE000u
  31. /* How much of a report descriptor to read for classification. */
  32. #define REPORT_MAX 64
  33. enum { KIND_FREE = 0, KIND_MOUSE, KIND_KBD, KIND_DJ };
  34. struct hid_dev {
  35. unsigned int kind; /* KIND_*, KIND_FREE = slot unused */
  36. int present; /* endpoint armed */
  37. int claimed; /* claimed by the scan in progress */
  38. unsigned int ctrl, addr, ep, mps, port;
  39. unsigned int xfer; /* report buffer size for int_in_start */
  40. int low;
  41. unsigned int err; /* consecutive transfer errors */
  42. unsigned int disc; /* consecutive "port disconnected" reads */
  43. /* keyboard report-diff state */
  44. unsigned char prev[6];
  45. unsigned char prev_mod;
  46. };
  47. static struct hid_dev devs[USB_HCD_INT_SLOTS];
  48. static int hcd_ok;
  49. static int need_rescan;
  50. static unsigned int gen;
  51. static unsigned int last_watch;
  52. /* --- keyboard report decoding ------------------------------------------ */
  53. /* HID keyboard usage -> PS/2 set-1 make code (0 = unmapped). */
  54. static const unsigned short hid_to_sc[256] = {
  55. [0x04] = 0x1E, [0x05] = 0x30, [0x06] = 0x2E, [0x07] = 0x20,
  56. [0x08] = 0x12, [0x09] = 0x21, [0x0A] = 0x22, [0x0B] = 0x23,
  57. [0x0C] = 0x17, [0x0D] = 0x24, [0x0E] = 0x25, [0x0F] = 0x26,
  58. [0x10] = 0x32, [0x11] = 0x31, [0x12] = 0x18, [0x13] = 0x19,
  59. [0x14] = 0x10, [0x15] = 0x13, [0x16] = 0x1F, [0x17] = 0x14,
  60. [0x18] = 0x16, [0x19] = 0x2F, [0x1A] = 0x11, [0x1B] = 0x2D,
  61. [0x1C] = 0x15, [0x1D] = 0x2C,
  62. [0x1E] = 0x02, [0x1F] = 0x03, [0x20] = 0x04, [0x21] = 0x05,
  63. [0x22] = 0x06, [0x23] = 0x07, [0x24] = 0x08, [0x25] = 0x09,
  64. [0x26] = 0x0A, [0x27] = 0x0B,
  65. [0x28] = 0x1C, [0x29] = 0x01, [0x2A] = 0x0E, [0x2B] = 0x0F,
  66. [0x2C] = 0x39, [0x2D] = 0x0C, [0x2E] = 0x0D, [0x2F] = 0x1A,
  67. [0x30] = 0x1B, [0x31] = 0x2B, [0x33] = 0x27, [0x34] = 0x28,
  68. [0x35] = 0x29, [0x36] = 0x33, [0x37] = 0x34, [0x38] = 0x35,
  69. [0x39] = 0x3A,
  70. [0x3A] = 0x3B, [0x3B] = 0x3C, [0x3C] = 0x3D, [0x3D] = 0x3E,
  71. [0x3E] = 0x3F, [0x3F] = 0x40, [0x40] = 0x41, [0x41] = 0x42,
  72. [0x42] = 0x43, [0x43] = 0x44, [0x44] = 0x57, [0x45] = 0x58,
  73. [0x49] = K_EXT | 0x52, [0x4A] = K_EXT | 0x47, [0x4B] = K_EXT | 0x49,
  74. [0x4C] = K_EXT | 0x53, [0x4D] = K_EXT | 0x4F, [0x4E] = K_EXT | 0x51,
  75. [0x4F] = K_EXT | 0x4D, [0x50] = K_EXT | 0x4B, [0x51] = K_EXT | 0x50,
  76. [0x52] = K_EXT | 0x48,
  77. };
  78. /* Modifier bit -> PS/2 make code: L/R ctrl, shift, alt, GUI. */
  79. static const unsigned short hid_mod_sc[8] = {
  80. 0x1D, K_EXT | 0x1D, /* L Ctrl, R Ctrl */
  81. 0x2A, 0x36, /* L Shift, R Shift */
  82. 0x38, K_EXT | 0x38, /* L Alt, R Alt */
  83. K_EXT | 0x5B, K_EXT | 0x5C, /* L GUI, R GUI */
  84. };
  85. static const unsigned char hid_mod_bit[8] = {
  86. 0x01, 0x10, 0x02, 0x20, 0x04, 0x40, 0x08, 0x80,
  87. };
  88. static void kbd_inject(unsigned int code, int down)
  89. {
  90. if (!code)
  91. return;
  92. if (code & K_EXT) {
  93. io_inject_scancode(0xE0);
  94. io_inject_scancode((unsigned char)((code & 0xFFu) |
  95. (down ? 0 : 0x80)));
  96. } else {
  97. io_inject_scancode((unsigned char)(code | (down ? 0 : 0x80)));
  98. }
  99. }
  100. /* Boot keyboard report: [modifiers][reserved][key0..key5]. Diff against
  101. the previous report to derive make/break scancodes. */
  102. static void kbd_decode(struct hid_dev *d, const unsigned char *r)
  103. {
  104. unsigned int i, j;
  105. for (i = 0; i < 8; i++) {
  106. int was = (d->prev_mod & hid_mod_bit[i]) != 0;
  107. int now = (r[0] & hid_mod_bit[i]) != 0;
  108. if (was != now)
  109. kbd_inject(hid_mod_sc[i], now);
  110. }
  111. d->prev_mod = r[0];
  112. /* Releases: in the previous report, gone from this one. */
  113. for (i = 0; i < 6; i++) {
  114. if (!d->prev[i])
  115. continue;
  116. for (j = 0; j < 6; j++) {
  117. if (r[2 + j] == d->prev[i])
  118. break;
  119. }
  120. if (j == 6)
  121. kbd_inject(hid_to_sc[d->prev[i]], 0);
  122. }
  123. /* Presses: new in this report. */
  124. for (i = 0; i < 6; i++) {
  125. if (!r[2 + i])
  126. continue;
  127. for (j = 0; j < 6; j++) {
  128. if (d->prev[j] == r[2 + i])
  129. break;
  130. }
  131. if (j == 6)
  132. kbd_inject(hid_to_sc[r[2 + i]], 1);
  133. }
  134. for (i = 0; i < 6; i++)
  135. d->prev[i] = r[2 + i];
  136. }
  137. /* --- report-descriptor classification ----------------------------------- */
  138. /* Minimal HID item walk: find a Generic Desktop (usage page 1) mouse or
  139. keyboard collection. Mouse detection accepts a Mouse/Pointer collection
  140. or a relative X/Y input item (so absolute tablets are not claimed). */
  141. static unsigned int hid_classify(const struct usb_iface_info *in)
  142. {
  143. static unsigned char rep[REPORT_MAX];
  144. int n, mouse = 0, kbd = 0;
  145. unsigned int i = 0, page = 0;
  146. int loc_mouse = 0, loc_kbd = 0, loc_xy = 0;
  147. n = usb_control_in(in->ctrl, in->addr, in->mps, in->low_speed,
  148. RT_DEV2HOST_CLS_IF, REQ_GET_DESCRIPTOR,
  149. (unsigned short)(0x22u << 8),
  150. (unsigned short)in->iface_num, rep, sizeof(rep));
  151. if (n <= 0)
  152. return KIND_FREE;
  153. while (i < (unsigned int)n) {
  154. unsigned int item = rep[i++];
  155. unsigned int size = item & 3u;
  156. unsigned int type = (item >> 2) & 3u;
  157. unsigned int tag = (item >> 4) & 0xFu;
  158. unsigned int data = 0, k;
  159. if (size == 3u)
  160. size = 4u;
  161. for (k = 0; k < size; k++) {
  162. if (i + k < (unsigned int)n)
  163. data |= (unsigned int)rep[i + k] << (8u * k);
  164. }
  165. i += size;
  166. if (type == 1u && tag == 0u) { /* Global Usage Page */
  167. page = data;
  168. } else if (type == 2u && tag == 0u && page == 0x01u) {
  169. if (data == 0x01u || data == 0x02u) /* Pointer/Mouse */
  170. loc_mouse = 1;
  171. else if (data == 0x06u) /* Keyboard */
  172. loc_kbd = 1;
  173. else if (data == 0x30u || data == 0x31u) /* X/Y */
  174. loc_xy = 1;
  175. } else if (type == 0u) { /* Main item */
  176. if (tag == 0xAu) { /* Collection */
  177. if (loc_mouse)
  178. mouse = 1;
  179. if (loc_kbd)
  180. kbd = 1;
  181. } else if (tag == 0x8u && loc_xy &&
  182. (data & 0x04u)) { /* Input, relative */
  183. mouse = 1;
  184. }
  185. loc_mouse = loc_kbd = loc_xy = 0;
  186. }
  187. }
  188. if (mouse)
  189. return KIND_MOUSE;
  190. if (kbd)
  191. return KIND_KBD;
  192. return KIND_FREE;
  193. }
  194. /* --- manager ------------------------------------------------------------ */
  195. static int hid_probe(const struct usb_iface_info *in)
  196. {
  197. struct hid_dev *d = 0;
  198. unsigned int kind, i;
  199. if (in->cls != 0x03u || !in->ep_addr || !(in->ep_addr & 0x80u))
  200. return 0;
  201. /* Logitech Unifying receiver: interface 2 is the HID++/DJ channel
  202. * that carries the paired device's reports. Its vendor report
  203. * descriptor is not a mouse collection, so claim it explicitly. */
  204. if (in->vendor == 0x046du && in->product == 0xc52bu &&
  205. in->iface_num == 2 && in->subcls == 0x00u && in->proto == 0x00u)
  206. kind = KIND_DJ;
  207. else if (in->subcls == 0x01u && in->proto == 0x02u)
  208. kind = KIND_MOUSE;
  209. else if (in->subcls == 0x01u && in->proto == 0x01u)
  210. kind = KIND_KBD;
  211. else
  212. kind = hid_classify(in);
  213. if (kind == KIND_FREE)
  214. return 0;
  215. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  216. if (!devs[i].present && !devs[i].claimed) {
  217. d = &devs[i];
  218. break;
  219. }
  220. }
  221. if (!d)
  222. return 0; /* every slot is busy */
  223. /* The endpoint is unusable until the device is configured. */
  224. usb_control_out(in->ctrl, in->addr, in->mps, in->low_speed,
  225. RT_HOST2DEV_STD, REQ_SET_CONFIGURATION,
  226. (unsigned short)(in->config_value & 0xFFu), 0);
  227. /* Boot protocol for boot-class devices; a stall is tolerated. */
  228. if (in->subcls == 0x01u)
  229. usb_control_out(in->ctrl, in->addr, in->mps, in->low_speed,
  230. RT_HOST2DEV_CLS, REQ_SET_PROTOCOL, 0,
  231. in->iface_num);
  232. d->kind = kind;
  233. d->ctrl = in->ctrl;
  234. d->addr = in->addr;
  235. d->ep = in->ep_addr & 0x0Fu;
  236. d->mps = in->ep_mps ? in->ep_mps : 8;
  237. d->xfer = kind == KIND_DJ ? USB_INT_MAX :
  238. (in->ep_mps ? in->ep_mps : 8);
  239. d->port = in->port;
  240. d->low = in->low_speed;
  241. d->claimed = 1;
  242. return 1;
  243. }
  244. static void dev_attach(struct hid_dev *d, unsigned int slot)
  245. {
  246. unsigned int i;
  247. if (usb_int_in_start(d->ctrl, slot, d->addr, d->ep, d->mps,
  248. d->xfer, d->low) != 0)
  249. return;
  250. d->err = 0;
  251. d->disc = 0;
  252. d->present = 1;
  253. d->prev_mod = 0;
  254. for (i = 0; i < 6; i++)
  255. d->prev[i] = 0;
  256. if (d->kind == KIND_DJ)
  257. serial_puts(SERIAL_COM1, "usbhid: Logitech DJ receiver attached (");
  258. else if (d->kind == KIND_MOUSE)
  259. serial_puts(SERIAL_COM1, "usbhid: mouse attached (");
  260. else
  261. serial_puts(SERIAL_COM1, "usbhid: keyboard attached (");
  262. serial_puts(SERIAL_COM1, usb_hcd_name_ctrl(d->ctrl));
  263. serial_puts(SERIAL_COM1, " ctrl ");
  264. serial_putdec(SERIAL_COM1, d->ctrl);
  265. serial_puts(SERIAL_COM1, ", addr ");
  266. serial_putdec(SERIAL_COM1, d->addr);
  267. serial_puts(SERIAL_COM1, " ep ");
  268. serial_putdec(SERIAL_COM1, 0x80u | d->ep);
  269. serial_puts(SERIAL_COM1, ")\n");
  270. }
  271. static void dev_detach(struct hid_dev *d, unsigned int slot)
  272. {
  273. usb_int_in_stop(slot);
  274. d->present = 0;
  275. d->claimed = 0;
  276. /* A false port-loss leaves the device attached but unreachable (no
  277. * CSC to wake the hotplug watcher). A clean full rescan re-arms
  278. * everything, and is the only reliable recovery on this SB950. */
  279. need_rescan = 1;
  280. last_watch = get_ticks_ms() - WATCH_MS; /* watch again soon */
  281. serial_puts(SERIAL_COM1, d->kind == KIND_DJ
  282. ? "usbhid: Logitech DJ receiver detached (addr "
  283. : d->kind == KIND_MOUSE
  284. ? "usbhid: mouse detached (addr "
  285. : "usbhid: keyboard detached (addr ");
  286. serial_putdec(SERIAL_COM1, d->addr);
  287. serial_puts(SERIAL_COM1, ")\n");
  288. d->kind = KIND_FREE;
  289. }
  290. static void arm_claimed(void)
  291. {
  292. unsigned int i;
  293. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  294. if (devs[i].claimed) {
  295. dev_attach(&devs[i], i);
  296. devs[i].claimed = 0;
  297. }
  298. }
  299. }
  300. static void hid_scan(void)
  301. {
  302. unsigned int i;
  303. /* A full scan resets every root port: existing handles are stale. */
  304. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  305. if (devs[i].kind != KIND_FREE) {
  306. usb_int_in_stop(i);
  307. devs[i].kind = KIND_FREE;
  308. devs[i].present = 0;
  309. devs[i].claimed = 0;
  310. }
  311. }
  312. if (usb_scan(hid_probe) != 0)
  313. return; /* busy: retried from the watcher */
  314. need_rescan = 0;
  315. gen = usb_generation();
  316. arm_claimed();
  317. }
  318. void usbhid_init(void)
  319. {
  320. /* usb_scan() brings the controllers up itself, under the scan claim;
  321. * hcd_ok stays 0 until it returns, so usbhid_poll() keeps out. */
  322. int r = usb_scan(hid_probe);
  323. if (r == -1) {
  324. serial_puts(SERIAL_COM1, "usbhid: no USB host controller\n");
  325. hcd_ok = 0;
  326. return;
  327. }
  328. hcd_ok = 1;
  329. if (r != 0) {
  330. /* A scan is already running (unlikely at boot): finish from
  331. the watcher. */
  332. need_rescan = 1;
  333. gen = usb_generation();
  334. return;
  335. }
  336. gen = usb_generation();
  337. arm_claimed();
  338. if (!usbhid_mouse_attached() && !usbhid_keyboard_attached())
  339. serial_puts(SERIAL_COM1,
  340. "usbhid: no HID boot mouse/keyboard found\n");
  341. }
  342. /* Service one slot: detach on disconnect/errors, return report length. */
  343. static int dev_poll(struct hid_dev *d, unsigned int slot, unsigned char *buf,
  344. unsigned int len)
  345. {
  346. int n;
  347. if (!d->present)
  348. return 0;
  349. /* CCS can glitch for a frame on the SB950; a single read must not
  350. * detach a working device. Require three consecutive misses. */
  351. if (d->port != 0xFFu && !usb_port_connected(d->ctrl, d->port)) {
  352. if (++d->disc >= 3)
  353. dev_detach(d, slot);
  354. return 0;
  355. }
  356. d->disc = 0;
  357. n = usb_int_in_poll(slot, buf, len);
  358. if (n < 0) {
  359. /* The HCD re-arms on every error; a short burst is normal on
  360. * a marginal low-speed link and must not kill the device. */
  361. if (++d->err >= 50)
  362. dev_detach(d, slot);
  363. return 0;
  364. }
  365. d->err = 0;
  366. return n;
  367. }
  368. static int dj_seen;
  369. static int mouse_seen;
  370. static void dj_decode(const unsigned char *r, unsigned int n,
  371. unsigned int *buttons, int *dx, int *dy,
  372. int *scroll, int *got)
  373. {
  374. const unsigned char *p;
  375. unsigned int btn;
  376. int x, y;
  377. if (n < 10 || (r[0] != 0x20u && r[0] != 0x21u))
  378. return;
  379. /* Device index 1..7, standard mouse report type. The receiver's
  380. * connection/notification reports (0x40/0x41/0x42) and other device
  381. * types are ignored. */
  382. if (r[1] < 1 || r[1] > 7 || r[2] != 0x02u)
  383. return;
  384. p = r + 3;
  385. btn = p[0] | ((unsigned int)p[1] << 8);
  386. x = p[2] | ((p[3] & 0x0Fu) << 8);
  387. y = (p[3] >> 4) | (p[4] << 4);
  388. if (x & 0x800)
  389. x -= 0x1000; /* 12-bit signed relative X */
  390. if (y & 0x800)
  391. y -= 0x1000;
  392. *buttons |= btn & 0x07u;
  393. *dx += x;
  394. *dy -= y; /* HID +y down; mouse.c expects +y up */
  395. if (scroll)
  396. *scroll -= (int)(signed char)p[5] * 48;
  397. *got = 1;
  398. if (!dj_seen) {
  399. dj_seen = 1;
  400. serial_puts(SERIAL_COM1, "usbhid: first DJ mouse report\n");
  401. }
  402. }
  403. int usbhid_poll(unsigned int *buttons, int *dx, int *dy, int *scroll)
  404. {
  405. unsigned char buf[USB_INT_MAX];
  406. unsigned int now, i, all_busy = 1;
  407. unsigned int b = 0;
  408. int n, x = 0, y = 0, got = 0;
  409. if (scroll)
  410. *scroll = 0;
  411. if (!hcd_ok)
  412. return 0;
  413. /* Another context's scan is sleeping between port resets: the
  414. * controllers are its until it finishes. */
  415. if (usb_scan_foreign())
  416. return 0;
  417. /* A full bus re-scan (`lsusb`) invalidates every handle. */
  418. if (usb_generation() != gen) {
  419. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  420. if (devs[i].present)
  421. dev_detach(&devs[i], i);
  422. }
  423. need_rescan = 1;
  424. }
  425. /* Throttled: finish a pending rescan, or watch for hotplug. */
  426. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  427. if (devs[i].kind == KIND_FREE)
  428. all_busy = 0;
  429. }
  430. now = get_ticks_ms();
  431. if (now - last_watch >= WATCH_MS) {
  432. last_watch = now;
  433. if (need_rescan) {
  434. hid_scan();
  435. } else if (!all_busy) {
  436. for (i = 0; i < USB_HCD_INT_SLOTS; i++)
  437. devs[i].claimed = 0;
  438. if (usb_hotplug_poll(hid_probe) > 0)
  439. arm_claimed();
  440. }
  441. }
  442. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  443. struct hid_dev *d = &devs[i];
  444. if (d->kind == KIND_FREE)
  445. continue;
  446. n = dev_poll(d, i, buf, sizeof(buf));
  447. if (n >= 3 && d->kind == KIND_MOUSE) {
  448. b |= buf[0] & 0x07u;
  449. x += (int)(signed char)buf[1];
  450. /* HID: +y is down; mouse.c expects +y = up. */
  451. y -= (int)(signed char)buf[2];
  452. got = 1;
  453. if (!mouse_seen) {
  454. mouse_seen = 1;
  455. serial_puts(SERIAL_COM1,
  456. "usbhid: first boot mouse report\n");
  457. }
  458. } else if (d->kind == KIND_DJ && n >= 10) {
  459. dj_decode(buf, (unsigned int)n, &b, &x, &y,
  460. scroll, &got);
  461. } else if (n >= 8 && d->kind == KIND_KBD) {
  462. kbd_decode(d, buf);
  463. }
  464. }
  465. if (got) {
  466. *buttons = b;
  467. *dx = x;
  468. *dy = y;
  469. }
  470. return got;
  471. }
  472. int usbhid_mouse_attached(void)
  473. {
  474. unsigned int i;
  475. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  476. if ((devs[i].kind == KIND_MOUSE || devs[i].kind == KIND_DJ) &&
  477. devs[i].present)
  478. return 1;
  479. }
  480. return 0;
  481. }
  482. int usbhid_keyboard_attached(void)
  483. {
  484. unsigned int i;
  485. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  486. if (devs[i].kind == KIND_KBD && devs[i].present)
  487. return 1;
  488. }
  489. return 0;
  490. }
  491. void usbhid_get_info(unsigned int *ctrl, unsigned int *addr,
  492. unsigned int *ep, unsigned int *mps, int *low)
  493. {
  494. unsigned int i;
  495. for (i = 0; i < USB_HCD_INT_SLOTS; i++) {
  496. struct hid_dev *d = &devs[i];
  497. if (d->kind == KIND_MOUSE || d->kind == KIND_DJ) {
  498. if (!d->present)
  499. continue;
  500. *ctrl = d->ctrl;
  501. *addr = d->addr;
  502. *ep = d->ep;
  503. *mps = d->mps;
  504. *low = d->low;
  505. return;
  506. }
  507. }
  508. *ctrl = 0;
  509. *addr = 0;
  510. *ep = 0;
  511. *mps = 0;
  512. *low = 0;
  513. }