Péter Szabó | 5 Oct 2009 22:09
Picon

how do I read events from a Hama MCE remote (keyboard+mouse)

Hi,

I have a Hama MCE remote control, whose USB dongle registers itself as
two HID devices on my machine running stock Ubuntu Jaunty 64-bit
desktop:

[210440.980030] usb 2-6: new low speed USB device using ohci_hcd and address 5
[210441.192962] usb 2-6: configuration #1 chosen from 1 choice
[210441.216468] input: HID 05a4:9881 as
/devices/pci0000:00/0000:00:04.0/usb2/2-6/2-6:1.0/input/input9
[210441.245334] generic-usb 0003:05A4:9881.0006: input,hidraw3: USB
HID v1.10 Keyboard [HID 05a4:9881] on usb-0000:00:04.0-6/input0
[210441.274963] input: HID 05a4:9881 as
/devices/pci0000:00/0000:00:04.0/usb2/2-6/2-6:1.1/input/input10
[210441.324278] generic-usb 0003:05A4:9881.0007: input,hidraw4: USB
HID v1.10 Mouse [HID 05a4:9881] on usb-0000:00:04.0-6/input1

Whenever I press a key on the remote, a few bytes become available for
reading on /dev/input/event7 or /dev/input/event8 (depending on the
key pressed; some of the keys emulate a mouse key, others emulate a
keyboard key).

So the hardware seems to work, keypresses can be propagated to
userspace (e.g. with `cat /dev/input/event7'). My questions are the
following:

1. How do I prevent the remote from sending keyboard events (such as
Enter, BackSpace, PageUp and numpad number keys) to the text-mode
virtual terminal and to X11? I don't want my remote to be recognized
as a regular keyboard or mouse -- but I have several USB keyboards and
(Continue reading)

Charles Lepple | 6 Oct 2009 00:50

Re: how do I read events from a Hama MCE remote (keyboard+mouse)


On Oct 5, 2009, at 4:09 PM, Péter Szabó wrote:

> Hi,
>
> I have a Hama MCE remote control, whose USB dongle registers itself as
> two HID devices on my machine running stock Ubuntu Jaunty 64-bit
> desktop:
>
> [210440.980030] usb 2-6: new low speed USB device using ohci_hcd and  
> address 5
> [210441.192962] usb 2-6: configuration #1 chosen from 1 choice
> [210441.216468] input: HID 05a4:9881 as
> /devices/pci0000:00/0000:00:04.0/usb2/2-6/2-6:1.0/input/input9
> [210441.245334] generic-usb 0003:05A4:9881.0006: input,hidraw3: USB
> HID v1.10 Keyboard [HID 05a4:9881] on usb-0000:00:04.0-6/input0
> [210441.274963] input: HID 05a4:9881 as
> /devices/pci0000:00/0000:00:04.0/usb2/2-6/2-6:1.1/input/input10
> [210441.324278] generic-usb 0003:05A4:9881.0007: input,hidraw4: USB
> HID v1.10 Mouse [HID 05a4:9881] on usb-0000:00:04.0-6/input1
>
> Whenever I press a key on the remote, a few bytes become available for
> reading on /dev/input/event7 or /dev/input/event8 (depending on the
> key pressed; some of the keys emulate a mouse key, others emulate a
> keyboard key).
>
> So the hardware seems to work, keypresses can be propagated to
> userspace (e.g. with `cat /dev/input/event7'). My questions are the
> following:
>
(Continue reading)

Peter Stuge | 6 Oct 2009 02:54
Picon

Re: how do I read events from a Hama MCE remote (keyboard+mouse)

Péter Szabó wrote:
> Hama MCE remote control
..

Linux knows this only as a USB keyboard and a USB mouse, since that
is how the dongle identifies itself. Like any other keyboard and
mouse, these are handled by the (kernel) input layer, which is what
provides you (processed) data in /dev/input/.

> 1. How do I prevent the remote from sending keyboard events
..
> I don't want my remote to be recognized as a regular keyboard or
> mouse

Too bad. That is how the device was built. The device type in USB is
stored in descriptors inside the device. Unless you want to hack the
dongle (extensively) you can not change this.

> Should I blacklist the USB device ID somewhere, possibly in udev's
> configs? Exactly where and how?

udev does you no good. The kernel USB stack identifies the devices,
and hooks them up to the kernel input layer, which then informs udev
that a new keyboard and mouse was attached.

If you're going to blacklist, it has to happen in the kernel HID
driver. Another option could be to detach the kernel drivers from
the devices in your application.

> 2. Which is the easiest way to write a program which can dump the
(Continue reading)

Péter Szabó | 6 Oct 2009 10:06
Picon

Re: how do I read events from a Hama MCE remote (keyboard+mouse)

Thanks for the helpful and insightful answer.

> Another option could be to detach the kernel drivers from
> the devices in your application.

This does work. With a little modification of Bob Pwwer's detach
program (original: http://www.linuxha.com/common/iplcd/detach.tgz ;
modified: http://code.google.com/p/pts-mini-gpl/source/browse/#svn/trunk/pts-usb-detach
) I could detach the usbhid driver from the device. Unfortunately,
/dev/input/event7 and event8 also disappeared. Do I understand
correctly that I can use libhid or libusb (which one? I think libusb
would be more appropriate) at this point to talk to the remote? Is
there some library which makes parsing easy?

> Ideally you will find a way to not just use the kernel drivers.
> /dev/input/event data is very easy to consume, you only really have
> to block the keyboard and mouse within the HID layer. Maybe you can
> get that done easily in the kernel.

Yeah, reading /dev/input/event* should be the easiest for me. Any idea
how to block the kernel from using the remote in the keyboard and
mouse subsystem? Any idea who knows how to to do this.

Thanks again,

Péter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
(Continue reading)

Peter Stuge | 6 Oct 2009 18:10
Picon

Re: how do I read events from a Hama MCE remote (keyboard+mouse)

Péter Szabó wrote:
> Thanks for the helpful and insightful answer.

You're welcome.

> > Another option could be to detach the kernel drivers from
> > the devices in your application.
> 
> This does work. With a little modification of Bob Pwwer's detach
> program (original: http://www.linuxha.com/common/iplcd/detach.tgz ;
> modified: http://code.google.com/p/pts-mini-gpl/source/browse/#svn/trunk/pts-usb-detach
> ) I could detach the usbhid driver from the device.

You would do this in your own program, which will then drive the
device.

> Unfortunately, /dev/input/event7 and event8 also disappeared.

Yes, that is to be expected. As I explained they are provided by the
kernel input layer, which is fed data by the kernel USB HID driver,
which you just disabled.

> Do I understand correctly that I can use libhid or libusb (which
> one? I think libusb would be more appropriate) at this point to
> talk to the remote?

Yes. libusb also has a function for detaching kernel drivers,
although it only works on Linux. libhid and libusb will both work.
Which you use is really up to you.

(Continue reading)

Péter Szabó | 6 Oct 2009 18:29
Picon

Re: how do I read events from a Hama MCE remote (keyboard+mouse)

Hi,

This USB HID business now makes sense now to me. Thank you for the
clarifications.

> Look for the Linux input layer developers. Ask them how you can make
> a device accessible via the event interface but just not pool into
> the "console" keyboard and mouse inputs. I'd be happy to learn what
> they reply too.

I'll do so.

Best regards,

Péter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Péter Szabó | 6 Oct 2009 22:06
Picon

Re: how do I read events from a Hama MCE remote (keyboard+mouse)

Hi,

> Look for the Linux input layer developers. Ask them how you can make
> a device accessible via the event interface but just not pool into
> the "console" keyboard and mouse inputs. I'd be happy to learn what
> they reply too.

I've got a quick answer from the Linux HID developers:

  ioctl(open("/dev/input/event7"), EVIOCGRAB, 1);

as long as this filehandle is open, the events generated would go only
to this filehandle (not to other open()s of the same device or to the
system keyboard or mouse event pool). At most one process can hold a
successful EVIOCGRAB at a HID device at a time. Lirc can be configured
to do an EVIOCGRAB.

Best regards,

Péter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Peter Stuge | 7 Oct 2009 00:56
Picon

Re: how do I read events from a Hama MCE remote (keyboard+mouse)

Péter Szabó wrote:
> > a device accessible via the event interface but just not pool into
> > the "console" keyboard and mouse inputs.
> 
> I've got a quick answer from the Linux HID developers:
> 
>   ioctl(open("/dev/input/event7"), EVIOCGRAB, 1);

Lovely! Thanks for passing the information on.

//Peter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Kustaa Nyholm | 10 Oct 2009 11:41

Problems with libhid and weather station WMR100

Hi,

I'm new to this list and noticed that this very same
topic was discussed very recently (August 9) but
having read the whole thread and having followed
all the clues and after spending hours and hours
with google I still cannot get this to work.

My problem is as follows:

I'm writing a weather station software that should
interface with WMR100 from Oregon Scientific.

I need this to be cross platform, hence I'm using
libusb 0.1 which works for Linux,Mac OS X and Windows.

My code works nicely on Mac (which I presumed would
be the hardest of the platforms!).

It probably works in Linux too but I can't claim
the interface.

I'm doing this on Ubuntu 9.04

First when I tried the code libusb complained
about access rights, so I modified the (I'm writing
this here for posterity) udev rules as per this
post:

http://www.nabble.com/Upgrade-to-Ubuntu-9.04-lost-all-permission-for-normal-users--td23462238.html
(Continue reading)

Kacper Wysocki | 14 Oct 2009 18:14

[PATCH] bugfix: hid_compare_usb_device() will match incorrect device

Hello dear libhid list,

we use libhid to modeswitch a MagTek magnetic swipe card reader into a
different ascii to keypress conversion type.

We do something like:

   HIDInterfaceMatcher matcher = { 0x0801, product_id, NULL, NULL, 0 };
   ret = hid_init();
   hid = hid_new_HIDInterface();
   ret = hid_force_open(hid, 0, &matcher, 3);
   /* snip modeswitching set_property() code */

hid_force_open() will fail with return code 13 (HID_RET_NOT_HID_DEVICE)
because the matcher matches on my root hub and not the
Vendor:ProductId passed in the matcher.

This is because in
hid_opening.c:hid_compare_usb_device(),
one uses a binary AND to match vendor and product ID. In a theoretical
example, if
I am trying to open a device with vendor_id 0x0001 and product_id 0x0001,
and I have another USB device with vendor_id 0x0005 and product_id 0x0005,
the matching function might match the wrong device, because the code

(dev->descriptor.idVendor & match->vendor_id) == match->vendor_id) {
 =>     0x0003 & 0x0001 == 0x0001 is true!
   and
     (dev->descriptor.idProduct & match->product_id) == match->product_id) {
 =>     0x0005 & 0x0001 == 0x0001 is true!
(Continue reading)


Gmane