NetBSD Problem Report #46868

From www@NetBSD.org  Tue Aug 28 14:42:11 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 7D1B963B8E6
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 28 Aug 2012 14:42:11 +0000 (UTC)
Message-Id: <20120828144209.B33E963B86D@www.NetBSD.org>
Date: Tue, 28 Aug 2012 14:42:09 +0000 (UTC)
From: nathanialsloss@yahoo.com.au
Reply-To: nathanialsloss@yahoo.com.au
To: gnats-bugs@NetBSD.org
Subject: usb - hid_is_collection matching problems.
X-Send-Pr-Version: www-1.0

>Number:         46868
>Category:       kern
>Synopsis:       usb - hid_is_collection matching problems.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    nat
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 28 14:45:00 +0000 2012
>Last-Modified:  Mon Nov 21 05:41:49 +0000 2016
>Originator:     Nat Sloss
>Release:        NetBSD Current 6.99.7
>Organization:
>Environment:
NetBSD beast 6.99.7 NetBSD 6.99.7 (LOCKDEBUG) #186: Wed Jul  4 05:47:37 EST 2012  build@beast:/usr/src/sys/arch/i386/compile/obj/LOCKDEBUG i386

>Description:
There is a problem matching hid collections under certain conditions.

Consider the following usbhidctl output:

report ID=0
Report descriptor:
item: kind=3 repid=0 usage=0xd0002
Collection page=Digitizer usage=Pen (13:0x2)
item: kind=3 repid=0 usage=0xd0020
Collection page=Digitizer usage=Stylus (13:0x20)
item: kind=0 repid=0 usage=0xd0042
Input   size=1 count=1 page=Digitizer usage=Tip_Switch (13:0x42), logical range 0..1
item: kind=0 repid=0 usage=0xd0044
Input   size=1 count=1 page=Digitizer usage=Barrel_Switch (13:0x44), logical range 0..1
item: kind=0 repid=0 usage=0xd003c
Input   size=1 count=1 page=Digitizer usage=Invert (13:0x3c), logical range 0..1
item: kind=0 repid=0 usage=0xd0045
Input   size=1 count=1 page=Digitizer usage=Eraser (13:0x45), logical range 0..1
item: kind=0 repid=0 usage=0x0
Input   size=1 count=1 Const page=0x0000 usage=0x0000 (0:0x0), logical range 0..1
item: kind=0 repid=0 usage=0xd0032
Input   size=1 count=1 page=Digitizer usage=In_Range (13:0x32), logical range 0..1
item: kind=0 repid=0 usage=0x0
Input   size=1 count=1 Const page=0x0000 usage=0x0000 (0:0x0), logical range 0..1
item: kind=0 repid=0 usage=0x0
Input   size=1 count=1 Const page=0x0000 usage=0x0000 (0:0x0), logical range 0..1
item: kind=0 repid=0 usage=0x10030
Input   size=16 count=1 page=Generic_Desktop usage=X (1:0x30), logical range 0..4095, physical range 0..4095
item: kind=0 repid=0 usage=0x10031
Input   size=16 count=1 page=Generic_Desktop usage=Y (1:0x31), logical range 0..4095, physical range 0..4095
item: kind=4 repid=0 usage=0x0
End collection
item: kind=4 repid=0 usage=0x0
End collection
Total   input size 5 bytes
Total  output size 0 bytes
Total feature size 0 bytes


There are two usages: Pen and stylus.
The Pen usage has collection type application and stylus physical.

Whilst experimenting with ums.c trying to match on the stylus usage it would always fail.  This was experienced by another user I believe this could be the reason for their problem.  Refer to kern/46391.

What ever the last usage of kind collection of collection application is considered and then it checks for input reports.

hid_is_collection should not check for any reports (input, output or feature) but just match on the collection usage and then it should be up to the corresponding driver to check for input reports or output reports.

It should check all collection types application, physical and logical and not check any input reports.  Just match if it is a valid collection.
>How-To-Repeat:
Attempt to use with certain types of touchscreen/digitizer.
>Fix:
To fix the problem I patched hid.c as follows:

Index: src/sys/dev/usb/hid.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/hid.c,v
retrieving revision 1.35
diff -u -r1.35 hid.c
--- src/sys/dev/usb/hid.c	24 Feb 2012 06:48:23 -0000	1.35
+++ src/sys/dev/usb/hid.c	28 Aug 2012 14:15:10 -0000
@@ -501,13 +501,15 @@
 			    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 ||
+		    hi.collection == HCOLL_LOGICAL))
 			coll_usage = hi.usage;

 		if (hi.kind == hid_endcollection)
 			coll_usage = ~0;

-		if (hi.kind == hid_input &&
+		if (hi.kind == hid_collection &&
 		    coll_usage == usage &&
 		    hi.report_ID == id) {
 			DPRINTFN(2,("hid_is_collection: found\n"));


Note:  This patch is my own work which I submit under the NetBSD licence.

After applying this patch, I was able to match on pen and stylus usages.

Regards,

Nat.

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->nat
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Mon, 21 Nov 2016 05:41:49 +0000
Responsible-Changed-Why:
nat can commit his own patches now :-)


>Unformatted:

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.