From owner-freebsd-hackers@FreeBSD.ORG Sat Nov 24 11:12:21 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8F717AD8 for ; Sat, 24 Nov 2012 11:12:21 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe05.c2i.net [212.247.154.130]) by mx1.freebsd.org (Postfix) with ESMTP id EE0C98FC13 for ; Sat, 24 Nov 2012 11:12:20 +0000 (UTC) X-T2-Spam-Status: No, hits=-0.2 required=5.0 tests=ALL_TRUSTED, BAYES_50 Received: from [176.74.213.204] (account mc467741@c2i.net HELO laptop015.hselasky.homeunix.org) by mailfe05.swip.net (CommuniGate Pro SMTP 5.4.4) with ESMTPA id 344564638; Sat, 24 Nov 2012 12:12:12 +0100 From: Hans Petter Selasky To: freebsd-hackers@freebsd.org Subject: Re: Questions about USB, uhid, ukbd and quirks Date: Sat, 24 Nov 2012 12:13:49 +0100 User-Agent: KMail/1.13.7 (FreeBSD/9.1-PRERELEASE; KDE/4.8.4; amd64; ; ) References: <50B0001C.6050202@daemonic.se> In-Reply-To: <50B0001C.6050202@daemonic.se> X-Face: 'mmZ:T{)),Oru^0c+/}w'`gU1$ubmG?lp!=R4Wy\ELYo2)@'UZ24N@d2+AyewRX}mAm; Yp |U[@, _z/([?1bCfM{_"B<.J>mICJCHAzzGHI{y7{%JVz%R~yJHIji`y>Y}k1C4TfysrsUI -%GU9V5]iUZF&nRn9mJ'?&>O MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_tvKsQH4+EHyEBct" Message-Id: <201211241213.49794.hselasky@c2i.net> Cc: Niclas Zeising X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Nov 2012 11:12:21 -0000 --Boundary-00=_tvKsQH4+EHyEBct Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit On Saturday 24 November 2012 00:00:44 Niclas Zeising wrote: > Hi! > I have a couple of questions about USB. > I recently bought a new USB keyboard, a Logitech K120. When attaching > this to a FreeBSD system, however, it is detected as a hid device > (attaching to uhid) rather than a keyboard (attaching to ukbd). The > keyboard works fine, but I'm just curious as to why it doesn't use ukbd. > The output from usbconfig for this keyboard is: > Hi, It seems the UHID driver needs to be synced with UMS and UKBD regarding the detection logic. Can you try the attached patch and report back. --HPS --Boundary-00=_tvKsQH4+EHyEBct Content-Type: text/x-patch; charset="iso-8859-1"; name="input.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="input.diff" === sys/dev/usb/input/uhid.c ================================================================== --- sys/dev/usb/input/uhid.c (revision 243384) +++ sys/dev/usb/input/uhid.c (local) @@ -670,7 +670,11 @@ uhid_probe(device_t dev) { struct usb_attach_arg *uaa = device_get_ivars(dev); + void *d_ptr; int error; + uint16_t d_len; + int is_keyboard; + int is_mouse; DPRINTFN(11, "\n"); @@ -684,18 +688,44 @@ if (usb_test_quirk(uaa, UQ_HID_IGNORE)) return (ENXIO); + is_keyboard = (uaa->info.bInterfaceClass == UICLASS_HID) && + (uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) && + (uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD); + + is_mouse = (uaa->info.bInterfaceClass == UICLASS_HID) && + (uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) && + (uaa->info.bInterfaceProtocol == UIPROTO_MOUSE); + + if (is_keyboard == 0 && is_mouse == 0) { + /* search a bit more before we conclude */ + + error = usbd_req_get_hid_desc(uaa->device, NULL, + &d_ptr, &d_len, M_TEMP, uaa->info.bIfaceIndex); + + if (error == 0) { + if (hid_is_collection(d_ptr, d_len, + HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE))) { + /* most likely a mouse */ + is_mouse = 1; + } + if (hid_is_collection(d_ptr, d_len, + HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_KEYBOARD))) { + /* most likely a keyboard */ + is_keyboard = 1; + } + free(d_ptr, M_TEMP); + } + } + /* * Don't attach to mouse and keyboard devices, hence then no * "nomatch" event is generated and then ums and ukbd won't * attach properly when loaded. */ - if ((uaa->info.bInterfaceClass == UICLASS_HID) && - (uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) && - (((uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD) && - !usb_test_quirk(uaa, UQ_KBD_IGNORE)) || - ((uaa->info.bInterfaceProtocol == UIPROTO_MOUSE) && - !usb_test_quirk(uaa, UQ_UMS_IGNORE)))) + if (is_keyboard != 0 && usb_test_quirk(uaa, UQ_KBD_IGNORE) == 0) return (ENXIO); + if (is_mouse != 0 && usb_test_quirk(uaa, UQ_UMS_IGNORE) == 0) + return (ENXIO); return (BUS_PROBE_GENERIC); } --Boundary-00=_tvKsQH4+EHyEBct--