Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Nov 2012 12:13:49 +0100
From:      Hans Petter Selasky <hselasky@c2i.net>
To:        freebsd-hackers@freebsd.org
Cc:        Niclas Zeising <zeising+freebsd@daemonic.se>
Subject:   Re: Questions about USB, uhid, ukbd and quirks
Message-ID:  <201211241213.49794.hselasky@c2i.net>
In-Reply-To: <50B0001C.6050202@daemonic.se>
References:  <50B0001C.6050202@daemonic.se>

next in thread | previous in thread | raw e-mail | index | archive | help
--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211241213.49794.hselasky>