Subject: kern/31884: [PATCH] Add quirk for uhid to ignore certain usb devices (blacklist)
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <akropel1@rochester.rr.com>
List: netbsd-bugs
Date: 10/21/2005 22:33:00
>Number:         31884
>Category:       kern
>Synopsis:       [PATCH] Add quirk for uhid to ignore certain usb devices (blacklist)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 21 22:33:00 +0000 2005
>Originator:     Adam Kropelin
>Release:        2.0
>Organization:
apcupsd maintainer
>Environment:
NetBSD p3.kroptech.com 2.0 NetBSD 2.0 (GENERIC.adk) #3: Sun Mar 27 15:43:05 EST 2005  adk0212@p3.kroptech.com:/usr/src/sys/arch/i386/compile/GENERIC.adk i386
>Description:
The uhid driver claims HID devices including power devices such as
UPSes. The apcupsd and NUT tools both control USB UPSes via ugen. As a
workaround, users are required to recompile their kernel, disabling
uhid support along with usb kbd and mouse support.

>How-To-Repeat:

>Fix:
The FreeBSD PR database has patches implementing a UQ_HID_IGNORE quirk
which allows UPSes and other devices to avoid being claimed by uhid.
FreeBSD has not merged the patch in over a year,  but I'm hoping OpenBSD
is more receptive. (Or at least more responsive...if the patch is the
wrong way to solve the problem, I can accept that.)

The FreeBSD patch is below. It includes quirks for several devices as
submitted by individuals who need them. (If the form whitespace mangles this, feel free to email me for a clean copy.)

The original patch was by Lonnie Mendez <lmendez19@austin.rr.com>. Thierry Thomas <thierry@FreeBSD.org> added MGE UPS quirks, and I added
APC UPS quirks.


diff -urN src/sys/dev/usb.orig/uhid.c src/sys/dev/usb/uhid.c
--- src/sys/dev/usb.orig/uhid.c	Sun Jan 30 02:00:10 2005
+++ src/sys/dev/usb/uhid.c	Sun May 22 10:35:28 2005
@@ -91,6 +91,9 @@
 /* Report descriptor for broken Wacom Graphire */
 #include <dev/usb/ugraphire_rdesc.h>
 
+/* For hid blacklist quirk */
+#include <dev/usb/usb_quirks.h>
+
 #ifdef USB_DEBUG
 #define DPRINTF(x)	if (uhiddebug) logprintf x
 #define DPRINTFN(n,x)	if (uhiddebug>(n)) logprintf x
@@ -190,6 +193,8 @@
 		return (UMATCH_NONE);
 	id = usbd_get_interface_descriptor(uaa->iface);
 	if (id == NULL || id->bInterfaceClass != UICLASS_HID)
+		return (UMATCH_NONE);
+	if (usbd_get_quirks(uaa->device)->uq_flags & UQ_HID_IGNORE)
 		return (UMATCH_NONE);
 #if 0
 	if (uaa->matchlvl)
diff -urN src/sys/dev/usb.orig/usb_quirks.c src/sys/dev/usb/usb_quirks.c
--- src/sys/dev/usb.orig/usb_quirks.c	Sun Jan 30 02:00:10 2005
+++ src/sys/dev/usb/usb_quirks.c	Sun May 22 10:31:55 2005
@@ -101,6 +101,15 @@
 	ANY, { UQ_ASSUME_CM_OVER_DATA }},
  { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_AS64LX,
 	0x100, { UQ_ASSUME_CM_OVER_DATA }},
+ /* Devices which should be ignored by uhid */
+ { USB_VENDOR_APC, USB_PRODUCT_APC_UPS,
+	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_DELORME, USB_PRODUCT_DELORME_EARTHMATE,
+	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_MGE, USB_PRODUCT_MGE_UPS1,
+	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_MGE, USB_PRODUCT_MGE_UPS2,
+	ANY, { UQ_HID_IGNORE }},
  { 0, 0, 0, { 0 } }
 };
 
diff -urN src/sys/dev/usb.orig/usb_quirks.h src/sys/dev/usb/usb_quirks.h
--- src/sys/dev/usb.orig/usb_quirks.h	Sun Jan 30 02:00:10 2005
+++ src/sys/dev/usb/usb_quirks.h	Sun May 22 10:37:18 2005
@@ -54,6 +54,7 @@
 #define UQ_AU_INP_ASYNC	0x0800	/* input is async despite claim of adaptive */
 #define UQ_ASSUME_CM_OVER_DATA 0x1000 /* modem device breaks on cm over data */
 #define UQ_BROKEN_BIDIR	0x2000	/* printer has broken bidir mode */
+#define UQ_HID_IGNORE	0x4000	/* device should be ignored by hid class */
 };
 
 extern const struct usbd_quirks usbd_no_quirk;
diff -urN src/sys/dev/usb.orig/usbdevs src/sys/dev/usb/usbdevs
--- src/sys/dev/usb.orig/usbdevs	Wed May 18 21:45:23 2005
+++ src/sys/dev/usb/usbdevs	Sun May 22 10:42:35 2005
@@ -90,6 +90,7 @@
 vendor DIAMOND2		0x045a	Diamond (Supra)
 vendor MICROSOFT	0x045e	Microsoft
 vendor PRIMAX		0x0461	Primax Electronics
+vendor MGE		0x0463	MGE UPS Systems
 vendor AMP		0x0464	AMP
 vendor CHERRY		0x046a	Cherry Mikroschalter
 vendor MEGATRENDS	0x046b	American Megatrends
@@ -470,7 +471,7 @@
 product ALTEC ASC495		0xff05	ASC495 Speakers
 
 /* American Power Conversion products */
-product APC UPSPRO500		0x0002	Back-UPS Pro 500
+product APC UPS			0x0002	Uninterruptible Power Supply
 
 /* Anchor products */
 product ANCHOR EZUSB		0x2131	EZUSB
@@ -962,6 +963,10 @@
 
 /* Metricom products */
 product METRICOM RICOCHET_GS	0x0001	Ricochet GS
+
+/* MGE UPS Systems */
+product MGE UPS1		0x0001	MGE UPS SYSTEMS PROTECTIONCENTER 1
+product MGE UPS2		0xffff	MGE UPS SYSTEMS PROTECTIONCENTER 2
 
 /* Microsoft products */
 product MICROSOFT SIDEPREC	0x0008	SideWinder Precision Pro