NetBSD Problem Report #46391

From www@NetBSD.org  Mon Apr 30 14:02:18 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 7413D63C785
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 30 Apr 2012 14:02:18 +0000 (UTC)
Message-Id: <20120430140217.8E16863BA4F@www.NetBSD.org>
Date: Mon, 30 Apr 2012 14:02:17 +0000 (UTC)
From: nathanialsloss@yahoo.com.au
Reply-To: nathanialsloss@yahoo.com.au
To: gnats-bugs@NetBSD.org
Subject: ums.c doesn't support digitizers or touchscreens
X-Send-Pr-Version: www-1.0

>Number:         46391
>Category:       kern
>Synopsis:       ums.c doesn't support digitizers or touchscreens
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 30 14:05:00 +0000 2012
>Last-Modified:  Wed Aug 29 16:30:03 +0000 2012
>Originator:     Nat Sloss
>Release:        NetBSD Current 6.99.5
>Organization:
>Environment:
NetBSD beast 6.99.5 NetBSD 6.99.5 (LOCKDEBUG) #41: Mon Apr 30 14:13:38 EST 2012  build@beast:/usr/src/sys/arch/i386/compile/obj/LOCKDEBUG i386

>Description:
Hi.

I have a laptop with a touchscreen that was supported by ums.c as a usb mouse.  After upgrading my bios it now reports as a digitizer and was no longer supported by ums.c.  And instead of reporting buttons it now reports as tip, barrel and eraser switches.
>How-To-Repeat:
Attach a usb digitizer or touch screen and possibly only uhidev attaches.
>Fix:
To fix the problem I modified the match and attach routines of ums.c.

Note: The digitizer type is 0002 which was undefined but I think it means digitizer.  This patch is my own work and I submit it under the NetBSD license.

 --- ums.c.orig  2012-01-01 15:46:53.000000000 +1100
+++ ums.c       2012-04-30 22:10:39.000000000 +1000
@@ -118,6 +118,7 @@
        ums_ioctl,
        ums_disable,
 };
+static int is_digitizer = 0;

 int ums_match(device_t, cfdata_t, void *);
 void ums_attach(device_t, device_t, void *);
@@ -147,9 +148,15 @@
        if (!hid_is_collection(desc, size, uha->reportid,
                               HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)) &&
            !hid_is_collection(desc, size, uha->reportid,
-                              HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)))
+                              HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER))
+           && !hid_is_collection(desc, size, uha->reportid,
+                                  HID_USAGE2(HUP_DIGITIZERS, 0x0002)))
                return (UMATCH_NONE);

+       if (hid_is_collection(desc, size, uha->reportid,
+                              HID_USAGE2(HUP_DIGITIZERS, 0x0002)))
+               is_digitizer = 1;
+
        return (UMATCH_IFACECLASS);
 }

@@ -165,6 +172,7 @@
        int i, hl;
        struct hid_location *zloc;
        struct hid_location loc_btn;
+       int tip_sw, tip_sw_sec, barrel_sw, eraser;

        aprint_naive("\n");

@@ -173,6 +181,11 @@
        sc->sc_hdev.sc_parent = uha->parent;
        sc->sc_hdev.sc_report_id = uha->reportid;

+       tip_sw = 0;
+       tip_sw_sec = 0;
+       barrel_sw = 0;
+       eraser = 0;
+
        quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
        if (quirks & UQ_MS_REVZ)
                sc->flags |= UMS_REVZ;
@@ -302,17 +315,67 @@
                        break;
        sc->nbuttons = i - 1;

+       for (i = 1; i <= sc->nbuttons; i++)
+               hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
+                          uha->reportid, hid_input,
+                          &sc->sc_loc_btn[i-1], 0);
+
+       if (is_digitizer && sc->nbuttons < (MAX_BUTTONS - 4)) {
+               if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                   HUD_TIP_SWITCH),
+                       uha->reportid, hid_input, &loc_btn, 0))
+                       tip_sw = 1;
+
+               if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                   HUD_SEC_TIP_SWITCH),
+                       uha->reportid, hid_input, &loc_btn, 0))
+                       tip_sw_sec = 1;
+
+               if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                   HUD_BARREL_SWITCH),
+                       uha->reportid, hid_input, &loc_btn, 0))
+                       barrel_sw = 1;
+
+               if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                   HUD_ERASER),
+                       uha->reportid, hid_input, &loc_btn, 0))
+                       eraser = 1;
+
+               if (tip_sw) {
+                       sc->nbuttons++;
+                       hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                           HUD_TIP_SWITCH), uha->reportid, hid_input, 
+                           &sc->sc_loc_btn[sc->nbuttons-1], 0);
+               }
+
+               if (tip_sw_sec) {
+                       sc->nbuttons++;
+                       hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                           HUD_SEC_TIP_SWITCH), uha->reportid, hid_input, 
+                           &sc->sc_loc_btn[sc->nbuttons-1], 0);
+               }
+
+               if (barrel_sw) {
+                       sc->nbuttons++;
+                       hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                       HUD_BARREL_SWITCH), uha->reportid, hid_input, 
+                       &sc->sc_loc_btn[sc->nbuttons-1], 0);
+               }
+
+               if (eraser) {
+                       sc->nbuttons++;
+                       hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
+                       HUD_ERASER), uha->reportid, hid_input, 
+                       &sc->sc_loc_btn[sc->nbuttons-1], 0);
+               }
+       }
+
        aprint_normal(": %d button%s%s%s%s\n",
            sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
            sc->flags & UMS_W ? ", W" : "",
            sc->flags & UMS_Z ? " and Z dir" : "",
            sc->flags & UMS_W ? "s" : "");

-       for (i = 1; i <= sc->nbuttons; i++)
-               hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
-                          uha->reportid, hid_input,
-                          &sc->sc_loc_btn[i-1], 0);
-
 #ifdef USB_DEBUG
        DPRINTF(("ums_attach: sc=%p\n", sc));
        DPRINTF(("ums_attach: X\t%d/%d\n",

I think it would also be possible to mach against digitizer touchscreens type 0004.  But I didn't add it as I don't have the hardware to test.

I hope this helps.

Regards,

Nat.

>Audit-Trail:
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: kern/46391: ums.c doesn't support digitizers or touchscreens
Date: Mon, 30 Apr 2012 10:39:30 -0400

 On Apr 30,  2:05pm, nathanialsloss@yahoo.com.au (nathanialsloss@yahoo.com.au) wrote:
 -- Subject: kern/46391: ums.c doesn't support digitizers or touchscreens


 How about this instead?

 Index: ums.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/ums.c,v
 retrieving revision 1.83
 diff -u -u -r1.83 ums.c
 --- ums.c	23 Dec 2011 00:51:48 -0000	1.83
 +++ ums.c	30 Apr 2012 14:38:49 -0000
 @@ -90,12 +90,16 @@

  	int sc_enabled;

 -	int flags;		/* device configuration */
 -#define UMS_Z		0x01	/* z direction available */
 -#define UMS_SPUR_BUT_UP	0x02	/* spurious button up events */
 -#define UMS_REVZ	0x04	/* Z-axis is reversed */
 -#define UMS_W		0x08	/* w direction/tilt available */
 -#define UMS_ABS		0x10	/* absolute position, touchpanel */
 +	u_int flags;		/* device configuration */
 +#define UMS_Z			0x001	/* z direction available */
 +#define UMS_SPUR_BUT_UP		0x002	/* spurious button up events */
 +#define UMS_REVZ		0x004	/* Z-axis is reversed */
 +#define UMS_W			0x008	/* w direction/tilt available */
 +#define UMS_ABS			0x010	/* absolute position, touchpanel */
 +#define UMS_TIP_SWITCH  	0x020	/* digitizer tip switch */
 +#define UMS_SEC_TIP_SWITCH 	0x040	/* digitizer secondary tip switch */
 +#define UMS_BARREL_SWITCH 	0x080	/* digitizer barrel switch */
 +#define UMS_ERASER 		0x100	/* digitizer eraser */

  	int nbuttons;

 @@ -105,6 +109,16 @@
  	char			sc_dying;
  };

 +static const struct {
 +	u_int feature;
 +	u_int flag;
 +} digbut[] = {
 +	{ HUD_TIP_SWITCH, UMS_TIP_SWITCH },
 +	{ HUD_SEC_TIP_SWITCH, UMS_SEC_TIP_SWITCH },
 +	{ HUD_BARREL_SWITCH, UMS_BARREL_SWITCH },
 +	{ HUD_ERASER, UMS_ERASER },
 +};
 +
  #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)

  Static void ums_intr(struct uhidev *addr, void *ibuf, u_int len);
 @@ -147,7 +161,9 @@
  	if (!hid_is_collection(desc, size, uha->reportid,
  			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)) &&
  	    !hid_is_collection(desc, size, uha->reportid,
 -			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)))
 +			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)) &&
 +	    !hid_is_collection(desc, size, uha->reportid,
 +                               HID_USAGE2(HUP_DIGITIZERS, 0x0002)))
  		return (UMATCH_NONE);

  	return (UMATCH_IFACECLASS);
 @@ -164,7 +180,7 @@
  	u_int32_t flags, quirks;
  	int i, hl;
  	struct hid_location *zloc;
 -	struct hid_location loc_btn;
 +	bool isdigitizer;

  	aprint_naive("\n");

 @@ -181,6 +197,9 @@

  	uhidev_get_report_desc(uha->parent, &desc, &size);

 +	isdigitizer = hid_is_collection(desc, size, uha->reportid,
 +	    HID_USAGE2(HUP_DIGITIZERS, 0x0002));
 +
  	if (!pmf_device_register(self, NULL, NULL))
  		aprint_error_dev(self, "couldn't establish power handler\n");

 @@ -298,20 +317,35 @@
  	/* figure out the number of buttons */
  	for (i = 1; i <= MAX_BUTTONS; i++)
  		if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
 -			uha->reportid, hid_input, &loc_btn, 0))
 +		    uha->reportid, hid_input, &sc->sc_loc_btn[i - 1], 0))
  			break;
 +
 +	if (isdigitizer) {
 +		for (size_t j = 0; j < __arraycount(digbut); j++) {
 +			if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, 
 +			    digbut[i].feature), uha->reportid, hid_input,
 +			    &sc->sc_loc_btn[i - 1], 0)) {
 +				if (i <= MAX_BUTTONS) {
 +					i++;
 +					sc->flags |= digbut[i].flag;
 +				} else
 +					aprint_error_dev(self,
 +					    "ran out of buttons\n");
 +			}
 +		}
 +	}
  	sc->nbuttons = i - 1;

 -	aprint_normal(": %d button%s%s%s%s\n",
 +	aprint_normal(": %d button%s%s%s%s%s%s%s%s%s\n",
  	    sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
  	    sc->flags & UMS_W ? ", W" : "",
  	    sc->flags & UMS_Z ? " and Z dir" : "",
 -	    sc->flags & UMS_W ? "s" : "");
 -
 -	for (i = 1; i <= sc->nbuttons; i++)
 -		hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
 -			   uha->reportid, hid_input,
 -			   &sc->sc_loc_btn[i-1], 0);
 +	    sc->flags & UMS_W ? "s" : "",
 +	    isdigitizer ? " digitizer"  : "",
 +	    sc->flags & UMS_TIP_SWITCH ? ", tip" : "",
 +	    sc->flags & UMS_SEC_TIP_SWITCH ? ", sec tip" : "",
 +	    sc->flags & UMS_BARREL_SWITCH ? ", barrel" : "",
 +	    sc->flags & UMS_ERASER ? ", eraser" : "");

  #ifdef USB_DEBUG
  	DPRINTF(("ums_attach: sc=%p\n", sc));

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/46391: ums.c doesn't support digitizers or touchscreens
Date: Tue, 1 May 2012 03:13:52 +1000

 Hi.


 Thanks Christos for the fast response.  I tested your patch and initially it 
 reported no buttons and it took me a while to find the problem but I found 
 it.

 --- ums.c.orig  2012-05-01 00:58:44.000000000 +1000
 +++ ums.c       2012-05-01 02:55:28.000000000 +1000
 @@ -323,11 +323,11 @@
         if (isdigitizer) {
                 for (size_t j = 0; j < __arraycount(digbut); j++) {
                         if (hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS,
 -                           digbut[i].feature), uha->reportid, hid_input,
 +                           digbut[j].feature), uha->reportid, hid_input,
                             &sc->sc_loc_btn[i - 1], 0)) {
                                 if (i <= MAX_BUTTONS) {
                                         i++;
 -                                       sc->flags |= digbut[i].flag;
 +                                       sc->flags |= digbut[j].flag;
                                 } else
                                         aprint_error_dev(self,
                                             "ran out of buttons\n");

 Now all buttons are reported and it works perfectly.

 So thanks again.

 Regards,

 Nat.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, 
	nathanialsloss@yahoo.com.au
Cc: 
Subject: Re: kern/46391: ums.c doesn't support digitizers or touchscreens
Date: Mon, 30 Apr 2012 13:28:01 -0400

 On Apr 30,  5:20pm, nathanialsloss@yahoo.com.au (Nat Sloss) wrote:
 -- Subject: Re: kern/46391: ums.c doesn't support digitizers or touchscreens

 |  Thanks Christos for the fast response.  I tested your patch and initially it 
 |  reported no buttons and it took me a while to find the problem but I found 
 |  it.

 Oops, sorry about that. Thanks for the patch and the debugging. All committed
 now.

 christos

From: Kooda <kooda@upyum.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/46391
Date: Sun, 26 Aug 2012 14:50:28 +0200

 --h31gzZEtNLTqOjlF
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 Hello,
 Sorry for waking up this report but I recently acquired a graphics tablet
 and I am unable to make it work with ums though I can get relevant data
 from uhid.

 My system is:
 NetBSD black-star.upyum.com 6.0_RC1 NetBSD 6.0_RC1 (GENERIC) #7: Sun Aug 26
 13:35:58 CEST 2012
 adrien@black-star.upyum.com:/mnt/src/netbsd-6/usr/src/sys/arch/i386/compile/GENERIC
 i386

 I attach to this mail the related dmesg part (USB_DEBUG enabled and usmdebug
 set to 6) and the output of usbhidctl.

 Thank you in advance,
 Kooda.


 --h31gzZEtNLTqOjlF
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=dmesg

 usb_needs_explore
 usb_needs_explore
 usb_event_thread: woke up
 usb_discover
 usb_needs_explore
 usb_needs_explore
 usb_event_thread: woke up
 usb_discover
 usbd_ar_pipe: pipe=0xc2f1bf24
 uhidev2 at uhub1 port 2 configuration 1 interface 0
 uhidev2: WALTOP International Corp. Media Tablet, rev 1.10/1.07, addr 2, iclass 3/0
 usbd_do_request: status = 0x0000
 usbd_do_request_flags_pipe: returning err=STALLED
 usb_allocmem: large alloc 300
 usb_freemem: large free
 uhidev2: 16 report ids
 uhidev2: ums matchedums0 at uhidev2 reportid 1: 5 buttons and Z dir
 ums_attach: sc=0xc24a23c0
 ums_attach: X   8/8
 ums_attach: Y   16/8
 ums_attach: Z   24/8
 ums_attach: B1  0/1
 ums_attach: B2  1/1
 ums_attach: B3  2/1
 ums_attach: B4  3/1
 ums_attach: B5  4/1
 wsmouse1 at ums0ums_enable: sc=0xc24a23c0
 usbd_open_pipe_intr: address=0x81 flags=0x4 len=8
 usbd_open_pipe: iface=0xc286a644 address=0x81 flags=0x1
  mux 0
 uhidev2: ums matchedums1 at uhidev2 reportid 2
 ums1: mouse has no X report
 uhid3 at uhidev2 reportid 5: input=7, output=0, feature=0
 uhid4 at uhidev2 reportid 10: input=7, output=0, feature=0
 uhid5 at uhidev2 reportid 12: input=1, output=0, feature=0
 ukbd1 at uhidev2 reportid 13
 wskbd2 at ukbd1 mux 1
 wskbd2: connecting to wsdisplay0
 uhid6 at uhidev2 reportid 16: input=7, output=0, feature=0

 --h31gzZEtNLTqOjlF
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=usbhidctl

 % usbhidctl -f uhid6 -r
 Report descriptor:
 Collection page=Digitizer usage=Stylus
 Input   size=1 count=1 page=Digitizer usage=Tip_Switch, logical range 0..1
 Input   size=1 count=1 page=Digitizer usage=Barrel_Switch, logical range 0..1
 Input   size=1 count=1 page=Digitizer usage=Invert, logical range 0..1
 Input   size=1 count=1 page=Digitizer usage=Eraser, logical range 0..1
 Input   size=1 count=1 page=Digitizer usage=In_Range, logical range 0..1
 Input   size=16 count=1 page=Generic_Desktop usage=X, logical range 0..18000, physical range 0..18000, unit=0x33 exp=-3
 Input   size=16 count=1 page=Generic_Desktop usage=Y, logical range 0..11000, physical range 0..11000, unit=0x33 exp=-3
 Input   size=16 count=1 page=Digitizer usage=Tip_Pressure, logical range 0..1023, physical range 0..1023, unit=0x33 exp=-3
 End collection
 usbhidctl: Excessive collection ends

 --h31gzZEtNLTqOjlF--

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: kooda@upyum.com
Subject: Re: kern/46391
Date: Mon, 27 Aug 2012 00:49:57 +1000

 Hi.

 It seems like it would work

 It must have a different report id.  When I submitted the report I used my 
 report id 0x0002 which I was sure meant touch screen as in my case.

 Usbhidctl is reporting that you have the right x-y axis and only three buttons 
 would be supported in it current state tip,barrel and eraser.

 I believe I found my report Id by adding a printf to the match routine on an 
 unsuccessful match.

 Regards,

 Nat.

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: kooda@upyum.com
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Mon, 27 Aug 2012 01:47:42 +1000

 Hi.

 I've found the problem and it's an easy fix the match routine for ums must be 
 broadened to cater for stylus':

 If you use usbhidctl -rvv you will see that the usage will be 0x13:0x20 for 
 stylus I now know that my touch screen was 0x13:0x2 for pen.

 Using usbhidctl is faster and easier than using printf.


 So the test for matching must be broadened by adding:

 	!hid_is_collection(desc, size, uha->reportid,
                                HID_USAGE2(HUP_DIGITIZERS, 0x0020)))

 Please check that your usage id is in fact 0x20.

 Regards,

 Nat.

From: Kooda <kooda@upyum.com>
To: Nat Sloss <nathanialsloss@yahoo.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Sun, 26 Aug 2012 22:05:05 +0200

 --cWoXeonUoKmBZSoM
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 Content-Transfer-Encoding: 8bit

 Hello,

 usbhidctl does report 13:0x20, but changing the matching test doesn’t fix
 the problem. Perhaps I’m missing something, here is what I did:


 --cWoXeonUoKmBZSoM
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=patch

 --- ums.c.orig  2012-08-26 12:32:23.000000000 +0200
 +++ ums.c       2012-08-26 21:55:41.000000000 +0200
 @@ -163,7 +163,9 @@
             !hid_is_collection(desc, size, uha->reportid,
                                HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)) &&
             !hid_is_collection(desc, size, uha->reportid,
 -                               HID_USAGE2(HUP_DIGITIZERS, 0x0002)))
 +                               HID_USAGE2(HUP_DIGITIZERS, 0x0002)) &&
 +           !hid_is_collection(desc, size, uha->reportid,
 +                               HID_USAGE2(HUP_DIGITIZERS, 0x0020)))
                 return (UMATCH_NONE);

         return (UMATCH_IFACECLASS);
 @@ -198,7 +200,9 @@
         uhidev_get_report_desc(uha->parent, &desc, &size);

         isdigitizer = hid_is_collection(desc, size, uha->reportid,
 -           HID_USAGE2(HUP_DIGITIZERS, 0x0002));
 +           HID_USAGE2(HUP_DIGITIZERS, 0x0002)) ||
 +           hid_is_collection(desc, size, uha->reportid,
 +           HID_USAGE2(HUP_DIGITIZERS, 0x0020));

         if (!pmf_device_register(self, NULL, NULL))
                 aprint_error_dev(self, "couldn't establish power handler\n");

 --cWoXeonUoKmBZSoM--

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: kooda@upyum.com
Subject: Re: kern/46391
Date: Mon, 27 Aug 2012 12:26:16 +1000

 Hi. What you hid was right.

 But the ids reported by usbhidctl are decimal so the matching number would be 
 0x0014 and not 0x0020 so you can change it to 0x0020 or just remove the 0x 
 and leave it as 20 and it should work.

 Sorry I didn't notice that earlier.

 Regards,

 Nat.

From: Kooda <kooda@upyum.com>
To: Nat Sloss <nathanialsloss@yahoo.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Mon, 27 Aug 2012 20:39:05 +0200

 --KsGdsel6WgEHnImy
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 Content-Transfer-Encoding: 8bit

 Hello,

 Are you sure about that? It seems that only the "page" part is reported in
 decimal form. The usage is still in hex (as it is in
 /usr/share/misc/usb_hid_usages).
 Anyways, I tried what you suggested and it still does'n work.

 I attatch the output of `usbhidctl -f uhid6 -rvvvv̉' so that you can see in
 details the device I have here. As you can see, the usage is 0xd0020 so I
 really do not understand where the matching fails...

 Thank you a lot for helping me out,

 Kooda.


 --KsGdsel6WgEHnImy
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=usbhidctl

 % usbhidctl -f uhid6 -rvvvv
 report ID=16
 Report descriptor:
 item: kind=3 repid=16 usage=0xd0020
 Collection page=Digitizer usage=Stylus (13:0x20)
 item: kind=0 repid=16 usage=0xd0042
 Input   size=1 count=1 page=Digitizer usage=Tip_Switch (13:0x42), logical range 0..1
 item: kind=0 repid=16 usage=0xd0044
 Input   size=1 count=1 page=Digitizer usage=Barrel_Switch (13:0x44), logical range 0..1
 item: kind=0 repid=16 usage=0xd003c
 Input   size=1 count=1 page=Digitizer usage=Invert (13:0x3c), logical range 0..1
 item: kind=0 repid=16 usage=0xd0045
 Input   size=1 count=1 page=Digitizer usage=Eraser (13:0x45), logical range 0..1
 item: kind=0 repid=16 usage=0xd0032
 Input   size=1 count=1 page=Digitizer usage=In_Range (13:0x32), logical range 0..1
 item: kind=0 repid=16 usage=0x0
 Input   size=1 count=1 Const page=0x0000 usage=0x0000 (0:0x0), logical range 0..1
 item: kind=0 repid=16 usage=0x0
 Input   size=1 count=1 Const page=0x0000 usage=0x0000 (0:0x0), logical range 0..1
 item: kind=0 repid=16 usage=0x0
 Input   size=1 count=1 Const page=0x0000 usage=0x0000 (0:0x0), logical range 0..1
 item: kind=0 repid=16 usage=0x10030
 Input   size=16 count=1 page=Generic_Desktop usage=X (1:0x30), logical range 0..18000, physical range 0..18000, unit=0x33 exp=-3
 item: kind=0 repid=16 usage=0x10031
 Input   size=16 count=1 page=Generic_Desktop usage=Y (1:0x31), logical range 0..11000, physical range 0..11000, unit=0x33 exp=-3
 item: kind=0 repid=16 usage=0xd0030
 Input   size=16 count=1 page=Digitizer usage=Tip_Pressure (13:0x30), logical range 0..1023, physical range 0..1023, unit=0x33 exp=-3
 item: kind=4 repid=16 usage=0x0
 End collection
 item: kind=4 repid=16 usage=0x0
 usbhidctl: Excessive collection ends

 --KsGdsel6WgEHnImy--

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: kooda@upyum.com
Subject: Re: kern/46391
Date: Tue, 28 Aug 2012 12:45:37 +1000

 Hi.

 Sorry I missed the problem

 Going back to your original post.  It seems the mouse is attached: wsmouse1 at 
 uhidev2.  The device has multiple report ids.  I also agree that the usage id 
 for stylus' is 0x20.

 Try this:

 mousepacketsniffer.c

 #include <sys/ioctl.h>

 #include <err.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>

 #include <dev/wscons/wsconsio.h>

 int main() {
 	int fd, errno, bytesRead;
 	struct wscons_event event;
 	char *fileName = "/dev/wsmouse1";
 	fd = open(fileName, O_RDONLY);
 	if (fd < 0) {
 		err(errno, "Error opening %s", fileName);
 		return -1;
 	}
 	for (;;) {
 		bytesRead = read(fd, &event, sizeof(event));

 		if (bytesRead = sizeof(event)) {
 			/* Absolute events. */
 			if (event.type == WSCONS_EVENT_MOUSE_ABSOLUTE_X)
 				printf("ABSOLUTE_X: %d\n", event.value);

 			if (event.type == WSCONS_EVENT_MOUSE_ABSOLUTE_Y)
 				printf("ABSOLUTE_Y: %d\n", event.value);

 			/* Relative events. */
 			if (event.type == WSCONS_EVENT_MOUSE_DELTA_X)
 				printf("DELTA_X: %d\n", event.value);

 			if (event.type == WSCONS_EVENT_MOUSE_DELTA_Y)
 				printf("DELTA_Y: %d\n", event.value);

 			/* Button events. */
 			if (event.type == WSCONS_EVENT_MOUSE_UP)
 				printf("BUTTON_UP: %d\n", event.value);

 			if (event.type == WSCONS_EVENT_MOUSE_DOWN)
 				printf("BUTTON_DOWN: %d\n", event.value);
 		}
 	}

 	close(fd);
 	return 0;
 }


 Note: Have to run using sudo or root unless you have permission to the device.
 Press control c to exit the programme.


 If it reports absolute packets you'll have to use the ws(4) driver for X 
 windows.

 You can use this programme tee it to a file and grep and sort the absolute x 
 and y values to find the limits for ws(4) refer to the manual page for more 
 info.

 Regards,

 Nat.

From: Kooda <kooda@upyum.com>
To: Nat Sloss <nathanialsloss@yahoo.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Tue, 28 Aug 2012 09:20:06 +0200

 --SUOF0GtieIMvvwua
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 Hello,

 Using your test program on wsmouse1 didn't show any position or button
 events at all. I modidied it to see if other events were sended and only the
 wheel events were reported.

 I then forced the ums match on reportid 16, I did get a new wsmouse
 interface. I tested it with your sniffer and I got (absolute) position and
 buttons events with it (it also works in X with ws).

 Here is what I did. I find really odd that the matching doesn't work in the
 standard way. Perhaps adding a match based on vendor-product-reportid would
 do the job...


 --SUOF0GtieIMvvwua
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=patch

 --- ums.c.orig	2012-08-26 12:32:23.000000000 +0200
 +++ ums.c	2012-08-28 09:10:46.000000000 +0200
 @@ -158,6 +158,13 @@
  		return (UMATCH_NONE);

  	uhidev_get_report_desc(uha->parent, &desc, &size);
 +
 +	if (uha->reportid == 16) {
 +		printf("Waltop tablet: vendor=0x%x product=0x%x\n",
 +		    uha->uaa->vendor, uha->uaa->product);
 +		return UMATCH_IFACECLASS;
 +	}
 +
  	if (!hid_is_collection(desc, size, uha->reportid,
  			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)) &&
  	    !hid_is_collection(desc, size, uha->reportid,
 @@ -198,7 +205,8 @@
  	uhidev_get_report_desc(uha->parent, &desc, &size);

  	isdigitizer = hid_is_collection(desc, size, uha->reportid,
 -	    HID_USAGE2(HUP_DIGITIZERS, 0x0002));
 +	    HID_USAGE2(HUP_DIGITIZERS, 0x0002)) ||
 +	    (uha->reportid == 16);

  	if (!pmf_device_register(self, NULL, NULL))
  		aprint_error_dev(self, "couldn't establish power handler\n");

 --SUOF0GtieIMvvwua
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=dmesg

 uhidev2 at uhub1 port 2 configuration 1 interface 0
 uhidev2: WALTOP International Corp. Media Tablet, rev 1.10/1.07, addr 2, iclass 3/0
 uhidev2: 16 report ids
 ums0 at uhidev2 reportid 1: 5 buttons and Z dir
 wsmouse1 at ums0 mux 0
 ums1 at uhidev2 reportid 2
 ums1: mouse has no X report
 uhid3 at uhidev2 reportid 5: input=7, output=0, feature=0
 uhid4 at uhidev2 reportid 10: input=7, output=0, feature=0
 uhid5 at uhidev2 reportid 12: input=1, output=0, feature=0
 ukbd1 at uhidev2 reportid 13
 wskbd2 at ukbd1 mux 1
 wskbd2: connecting to wsdisplay0
 Waltop tablet: vendor=0x172f product=0x501
 ums2 at uhidev2 reportid 16: 3 buttons digitizer, tip, barrel, eraser
 wsmouse2 at ums2 mux 0

 --SUOF0GtieIMvvwua--

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: Kooda <kooda@upyum.com>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Tue, 28 Aug 2012 17:26:18 +1000

 Hi.

 Glad to see it worked.

 I was thinking of changing the match routine to scan all report ids but I 
 wasn't sure as to how to go about it.  But I'm happy it's sorted hopefully 
 your patch will make it upstrem.  That or we solve as to why it wont match 
 without it.

 Are the buttons in the right order otherwise you can use xinput or I have 
 another PR with a fix just search for wsmouse.*remap.

 Regards,

 Nat.

From: Kooda <kooda@upyum.com>
To: Nat Sloss <nathanialsloss@yahoo.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Tue, 28 Aug 2012 09:47:38 +0200

 Hello,

 I don't know if matching the device that way is a good idea. Any other usb
 device could use a reportid of 16 without being a digitizer, right?

 Oh, I didn't notice but you're right, the buttons 2 and 3 are reversed.
 Thanks for pointing that out, I'll take a look at your other PR.

 Thanks a lot,

 Kooda.

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: Kooda <kooda@upyum.com>
Subject: Re: kern/46391
Date: Tue, 28 Aug 2012 17:55:57 +1000

 Hi.

 Maybe you could change it to:

         isdigitizer = hid_is_collection(desc, size, uha->reportid,
  -          HID_USAGE2(HUP_DIGITIZERS, 0x0002));
  +          HID_USAGE2(HUP_DIGITIZERS, 0x0002)) ||
  +          hid_is_collection(desc,size, uha->reportid,
  +	    HID_USAGE2(HUP_DIGITIZERS, 0X0020);


 As it has matched because of product/vendor ids.

 Regards,

 Nat.

From: Kooda <kooda@upyum.com>
To: Nat Sloss <nathanialsloss@yahoo.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Tue, 28 Aug 2012 10:28:35 +0200

 Hello,

 If I do this, then here is what I get:
 ums2 at uhidev2 reportid 16: 0 buttons

 Perhaps the little note on top of hid_is_collection() in hid.c is the key of
 the problem, but I don't quiet understand it as I'm not used to hardware and
 kernel code.

 Regards,

 Kooda.

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: Kooda <kooda@upyum.com>
Subject: Re: kern/46391
Date: Wed, 29 Aug 2012 00:56:18 +1000

 Hi.

 There was a problem with hid_is_collection for which I have submitted a patch.  
 Refer to kern/46868.  This was a problem for me too when trying to match on 
 stylus usage.

 So if you apply that patch along with the following patches to ums etc. the 
 problem should be solved.  Hopefully :)

 The following patches are just revisions of what has already been done:

 Index: usbhid.h
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usbhid.h,v
 retrieving revision 1.14
 diff -u -r1.14 usbhid.h
 --- usbhid.h	17 Jan 2012 03:49:20 -0000	1.14
 +++ usbhid.h	28 Aug 2012 14:53:33 -0000
 @@ -133,7 +133,9 @@

  /* Usages Digitizers */
  #define HUD_UNDEFINED		0x0000
 +#define HUD_PEN			0x0002
  #define HUD_TOUCH_SCREEN	0x0004
 +#define HUD_STYLUS		0x0020
  #define HUD_FINGER		0x0022
  #define HUD_TIP_PRESSURE	0x0030
  #define HUD_BARREL_PRESSURE	0x0031
 Index: ums.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/ums.c,v
 retrieving revision 1.84
 diff -u -r1.84 ums.c
 --- ums.c	30 Apr 2012 17:27:50 -0000	1.84
 +++ ums.c	28 Aug 2012 14:55:02 -0000
 @@ -163,7 +163,9 @@
  	    !hid_is_collection(desc, size, uha->reportid,
  			       HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_POINTER)) &&
  	    !hid_is_collection(desc, size, uha->reportid,
 -                               HID_USAGE2(HUP_DIGITIZERS, 0x0002)))
 +                               HID_USAGE2(HUP_DIGITIZERS, HUD_PEN)) &&
 +	    !hid_is_collection(desc, size, uha->reportid,
 +                               HID_USAGE2(HUP_DIGITIZERS, HUD_STYLUS)))
  		return (UMATCH_NONE);

  	return (UMATCH_IFACECLASS);
 @@ -198,7 +200,9 @@
  	uhidev_get_report_desc(uha->parent, &desc, &size);

  	isdigitizer = hid_is_collection(desc, size, uha->reportid,
 -	    HID_USAGE2(HUP_DIGITIZERS, 0x0002));
 +	    HID_USAGE2(HUP_DIGITIZERS, HUD_PEN)) ||
 +	    hid_is_collection(desc, size, uha->reportid,
 +	    HID_USAGE2(HUP_DIGITIZERS, HUD_STYLUS));

  	if (!pmf_device_register(self, NULL, NULL))
  		aprint_error_dev(self, "couldn't establish power handler\n");


 I hope this works, that is with the modified hid_is_collection.

 Please post back with results.

 Regards,

 Nat.


From: Kooda <kooda@upyum.com>
To: Nat Sloss <nathanialsloss@yahoo.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Wed, 29 Aug 2012 17:31:34 +0200

 Hello,

 I applied your patches and now it's even more strange:

 uhidev2 at uhub1 port 2 configuration 1 interface 0
 uhidev2: WALTOP International Corp. Media Tablet, rev 1.10/1.07, addr 2, iclass 3/0
 uhidev2: 16 report ids
 ums0 at uhidev2 reportid 1: 5 buttons and Z dir digitizer
 wsmouse1 at ums0 mux 0
 ums1 at uhidev2 reportid 2
 ums1: mouse has no X report
 ums2 at uhidev2 reportid 5
 ums2: mouse has no X report
 ums3 at uhidev2 reportid 10
 ums3: mouse has no X report
 uhid3 at uhidev2 reportid 12: input=1, output=0, feature=0
 uhid4 at uhidev2 reportid 13: input=7, output=0, feature=0
 ukbd1 at uhidev2 reportid 16
 wskbd2 at ukbd1 mux 1
 wskbd2: connecting to wsdisplay0

 I tried the packetsniffer on wsmouse1 and it reported no position or buttons
 events. And now, the part at id 16 (which works well with ums) is now
 matched as a keyboard.


 Regards,
 Kooda.

From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: Kooda <kooda@upyum.com>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/46391
Date: Thu, 30 Aug 2012 02:22:56 +1000

 Hi Kooda.

 I'm just experimenting to try and solve your problem as I don't have the 
 hardware.

 Could you change hid.c and re-test.

 --- hid.c.orig  2012-03-03 08:28:40.000000000 +0000
 +++ hid.c
 @@ -501,13 +501,14 @@ hid_is_collection(const void *desc, int
                             hi.kind, hi.report_ID, hi.usage, coll_usage));

                 if (hi.kind == hid_collection &&
 -                   hi.collection == HCOLL_APPLICATION)
 +                   (hi.collection == HCOLL_APPLICATION ||
 +                   hi.collection == HCOLL_PHYSICAL))
                         coll_usage = hi.usage;


 Hopefully we'll get it solved.  The problem is that the device as did mine 
 when matching on stylus is not of kind application.  Mine was of type 
 physical.  I put logical in there for good measure but it was a bad idea.

 Regards,

 Nat.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.