linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG?] hid-core.c: hid->name = dev->manufacturer + dev->product   ... why not + dev->serial?
@ 2010-03-07 15:55 Melchior FRANZ
  2010-03-09  8:22 ` Dmitry Torokhov
  0 siblings, 1 reply; 10+ messages in thread
From: Melchior FRANZ @ 2010-03-07 15:55 UTC (permalink / raw)
  To: linux-input

Hi,

just recently I purchased two data acquisition HID devices that pretend to be
joysticks[1], because that way no special kernel drivers are required, and
because they are usually used for joystick-like purposes. The devices identify
themselves as

  idVendor           0x16c0
  idProduct          0x05ba 
  iManufacturer      1 Leo Bodnar
  iProduct           2 BU0836A Interface
  iSerial            3 A10123

The Linux kernel creates the HID/"joystick name" from only iManufacturer and
iProduct, ignoring iSerial. That way, JSIOCGNAME returns the same string
for all such devices, making an actual identification impossible.
joystick-api.txt says about JSIOCGNAME:

  #define JSIOCGNAME(len) /* get identifier string        char    */
  ...
  JSIOCGNAME(len) allows you to get the name string of the joystick

But this isn't actually true. "Leo Bodnar BU0836A Interface" is only
the name of the product, but not of the actual (joystick or whatever)
device. If you have more of these devices on the bus, then software has
no way to know which is which -- which is the one with the temperature
sensor on axis 0 etc. (Apart from doing all the USB querying itself,
of course.)

The patch below fixed the problem for me. But, certainly, the current
(mis)behaviour wasn't an accident, but intentional. But what was the
intention? What happens if I attach two actual identical joysticks?
What's the purpose of them having the same name on the system under
/dev/input/{js,event}? Not even two (human) identical twins have the
same first name, and for a reason!

I'm aware that at the moment, some software could rely on the fact
that a joystick name is just a generic product name, but that would
be easy to fix. I'm only aware of one such application, but exactly
in this case the serial number in the joystick name would actually
be an improvement!

m.




[1] http://www.leobodnar.com/products/BU0836A/





--- a/drivers/hid/usbhid/hid-core.c     2010-03-04 02:49:38.676850618 +0100
+++ b/drivers/hid/usbhid/hid-core.c     2010-03-04 03:03:43.269006052 +0100
@@ -1131,6 +1131,12 @@
                strlcat(hid->name, dev->product, sizeof(hid->name));
        }
 
+       if (dev->serial) {
+               if (hid->name[0])
+                       strlcat(hid->name, " ", sizeof(hid->name));
+               strlcat(hid->name, dev->serial, sizeof(hid->name));
+       }
+
        if (!strlen(hid->name))
                snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
                         le16_to_cpu(dev->descriptor.idVendor),

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [BUG?] hid-core.c: hid->name = dev->manufacturer + dev->product ... why not + dev->serial?
@ 2010-06-14 21:12 Melchior FRANZ
  0 siblings, 0 replies; 10+ messages in thread
From: Melchior FRANZ @ 2010-06-14 21:12 UTC (permalink / raw)
  To: linux-input; +Cc: linux-iio

* Melchior FRANZ -- Tuesday 09 March 2010:
> Anyway, my kernel is "fixed", so it's not about me at all. I just feel a
> bit uncomfortably if I have to hack my kernel. Before the fix I got this
> information from js_demo/JSIOCGNAME:
> 
>   Joystick 0: "Leo Bodnar BU0836A Interface"
>   Joystick 1: "Leo Bodnar BU0836A Interface"
>   Joystick 2: "SAITEK CYBORG 3D USB"
> 
> and now I get:
> 
>   Joystick 0: "Leo Bodnar BU0836A Interface A12107"
>   Joystick 1: "Leo Bodnar BU0836A Interface A12100"
>   Joystick 2: "SAITEK CYBORG 3D USB"

As my fix[1] for this kernel flaw was brushed away without arguments (other than
a disingenious "the joystick interface sucks, anyway, just use something else"),
but people come across this thread and then ask me privatly about solutions,
(which doesn't bother me at all, btw), here again, strictly for the archive:

There's now a preload library[1] available, which overrides ioctl(), watches
for JSIOCGNAME and replaces the retarded generic product name by the actual
device identifier, which is taken from the /dev/input/by-id/ name. For some
reason the latter interface actually thinks the serial number belongs to the
joystick name. I totally agree with it!  :-}

Howto build:

  $ git clone git://gitorious.org/bu0836/bu0836.git
  $ cd bu0836/js_serial_preload/
  $ make
  $ sudo make install

Howto use:

  $ LD_PRELOAD=/usr/local/lib/js_serial_preload.so fgfs --aircraft=bo105

Viola. Everything works as intended without having to patch the broken kernel.

m.


[1] http://members.aon.at/mfranz/bu0836a.html
[2] http://gitorious.org/bu0836/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-06-14 21:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-07 15:55 [BUG?] hid-core.c: hid->name = dev->manufacturer + dev->product ... why not + dev->serial? Melchior FRANZ
2010-03-09  8:22 ` Dmitry Torokhov
2010-03-09 12:42   ` Melchior FRANZ
2010-03-09 18:41     ` Dmitry Torokhov
2010-03-09 18:52       ` Melchior FRANZ
2010-03-09 18:57         ` Dmitry Torokhov
2010-03-09 18:58         ` Melchior FRANZ
2010-03-13 23:50         ` Melchior FRANZ
2010-06-14 21:11     ` Melchior FRANZ
2010-06-14 21:12 Melchior FRANZ

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).