Discussion:
[libhid-discuss] Talking to an HID device from user account in Linux
Ali Asad
2009-03-30 17:26:06 UTC
Permalink
Hi,

This is a follow-up to my earlier postings.

I am using a device that enumerates as both mass storage device and HID device. I have used libhid as well as libusb to communicate with this composite USB device and the communication works as expected. So far so good.

Here is my dilemma:

The application that is used for communicating with the device over HID is not installed on the Linux machine, but is carried on the token itself. This application uses libhid or libusb and can be run from one of the mass storage partitions after the user connects the device to a Linux box.

As I understand it, the use of libhid requires root access in order to read-write from the device, right? This is how I have tested my application. Is there another way to talk to the HID device so that root access is not required? If so what would I need to do from my application, and more importantly, what would the end-user have to do on their Linux machines in order to run this application? I am targeting the Ubuntu distribution.

best regards, and many thanks for your feedback.
--- asad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20090330/3e918daa/attachment.htm
Xiaofan Chen
2009-03-30 23:40:43 UTC
Permalink
Post by Ali Asad
As I understand it, the use of libhid requires root access in order to
read-write from the device, right? This is how I have tested my application.
Is there another way to talk to the HID device so that root access is not
required? If so what would I need to do from my application, and more
importantly, what would the end-user have to do on their Linux machines in
order to run this application? I am targeting the Ubuntu distribution.
You need to use udev rules.
Ubuntu is quite consistent in terms of udev rules.
http://piklab.wiki.sourceforge.net/USB+Port+Problems

Regards,
Xiaofan
Ali Asad
2009-03-31 04:24:48 UTC
Permalink
Post by Xiaofan Chen
You need to use udev rules.
Ubuntu is quite consistent in terms of udev rules.
http://piklab.wiki.sourceforge.net/USB+Port+Problems
Thanks for the pointer. The first paragraph at this link states ...

"You need to have read and write access to the port (serial, parallel or USB).
Some distributions do not grant read/write access to regular users by default ..."

I understand that the end user would have to use udev rules before they can use the HID device. However, these distributions do allow HID devices to be connected and used without the user doing anything. For example, you can connect a USB mouse (a HID device) without requiring root access or forcing the user to use udev rules.

How are user mode applications able to talk to such HID devices? Is that through some generic/universal HID device driver supported by the Linux kernal (say uhid)? If so how do user applications use this universal HID driver? This technique would be orthogonal to the approach of using libhid to create our own device driver, but I want to explore all options.

regards,
--- asad



-----Original Message-----
From: Xiaofan Chen [mailto:xiaofanc at gmail.com]
Sent: Monday, March 30, 2009 6:41 PM
To: Ali Asad
Cc: libhid-discuss at lists.alioth.debian.org
Subject: Re: [libhid-discuss] Talking to an HID device from user account in Linux
Post by Xiaofan Chen
As I understand it, the use of libhid requires root access in order to
read-write from the device, right? This is how I have tested my application.
Is there another way to talk to the HID device so that root access is
not required? If so what would I need to do from my application, and
more importantly, what would the end-user have to do on their Linux
machines in order to run this application? I am targeting the Ubuntu distribution.
You need to use udev rules.
Ubuntu is quite consistent in terms of udev rules.
http://piklab.wiki.sourceforge.net/USB+Port+Problems

Regards,
Xiaofan
Peter Stuge
2009-03-31 04:47:44 UTC
Permalink
Post by Ali Asad
For example, you can connect a USB mouse (a HID device) without
requiring root access or forcing the user to use udev rules.
How are user mode applications able to talk to such HID devices?
Is that through some generic/universal HID device driver supported
by the Linux kernal (say uhid)?
Correct. (Though I think uhid is BSD only.)
Post by Ali Asad
If so how do user applications use this universal HID driver?
Via the Linux input layer. For keyboards that maps to stdin.
Post by Ali Asad
This technique would be orthogonal to the approach of using libhid
to create our own device driver, but I want to explore all options.
Then you could also look into hiddev and/or hidraw. They can be used
to communicate with HID devices at a higher level than USB.

CONFIG_HID_DEV /usr/src/linux/Documentation/usb/hiddev.txt
CONFIG_HIDRAW http://cateee.net/lkddb/web-lkddb/HIDRAW.html (brief)

hiddev may come with restrictions on which non-HID-class things your
device can do however - but still worth looking into.


//Peter
Xiaofan Chen
2009-03-31 05:14:44 UTC
Permalink
Post by Peter Stuge
Post by Ali Asad
This technique would be orthogonal to the approach of using libhid
to create our own device driver, but I want to explore all options.
Then you could also look into hiddev and/or hidraw. They can be used
to communicate with HID devices at a higher level than USB.
CONFIG_HID_DEV /usr/src/linux/Documentation/usb/hiddev.txt
CONFIG_HIDRAW http://cateee.net/lkddb/web-lkddb/HIDRAW.html (brief)
hiddev may come with restrictions on which non-HID-class things your
device can do however - but still worth looking into.
You may still need to write a udev rule even if you use the hiddev
or hidraw interface unless the system has already udev rules
in place.

I am not familiar with hiddev but there is an example here.
http://openprog.altervista.org/OP_eng.html

Last time it is said that hiddev is not a good option for generic
HID device but hidraw might be an option.
http://osdir.com/ml/lib.libusb.devel.general/2007-04/msg00233.html

Xiaofan
Ali Asad
2009-04-01 23:28:36 UTC
Permalink
Post by Xiaofan Chen
You may still need to write a udev rule even if you use the hiddev
or hidraw interface unless the system has already udev rules
in place.
I created the udev rule for my device and copied it to the /etc/udev/rules.d directory. Had to do it using root access (no surprises there), but I can now talk to my Hid device from user mode; which is good news.

I am now looking for a 'seamless' way for the end-users of this device to apply this udev rule on their Linux systems. They do this once and on each subsequent use the application works from use account. I can have my application write the rules file to /etc/udev/rules.d directory but for this I would need root access. What is the best way for a C application to ask user to type the root password and then use it to gain root access. Once this is done, the application can then write the rules file.

Best regards, and many thanks for your continued help.

--- asad



-----Original Message-----
From: libhid-discuss-bounces+asad.ali=gemalto.com at lists.alioth.debian.org [mailto:libhid-discuss-bounces+asad.ali=gemalto.com at lists.alioth.debian.org] On Behalf Of Xiaofan Chen
Sent: Tuesday, March 31, 2009 12:15 AM
To: libhid-discuss at lists.alioth.debian.org
Subject: Re: [libhid-discuss] Talking to an HID device from user account in Linux
Post by Xiaofan Chen
Post by Ali Asad
This technique would be orthogonal to the approach of using libhid
to create our own device driver, but I want to explore all options.
Then you could also look into hiddev and/or hidraw. They can be used
to communicate with HID devices at a higher level than USB.
CONFIG_HID_DEV /usr/src/linux/Documentation/usb/hiddev.txt
CONFIG_HIDRAW http://cateee.net/lkddb/web-lkddb/HIDRAW.html (brief)
hiddev may come with restrictions on which non-HID-class things your
device can do however - but still worth looking into.
You may still need to write a udev rule even if you use the hiddev
or hidraw interface unless the system has already udev rules
in place.

I am not familiar with hiddev but there is an example here.
http://openprog.altervista.org/OP_eng.html

Last time it is said that hiddev is not a good option for generic
HID device but hidraw might be an option.
http://osdir.com/ml/lib.libusb.devel.general/2007-04/msg00233.html

Xiaofan
Sarah Mount
2009-05-06 14:30:17 UTC
Permalink
2009/4/2 Ali Asad <Asad.Ali at gemalto.com>:
<snip>
Post by Ali Asad
I am now looking for a 'seamless' way for the end-users of this device to apply this udev rule on their Linux systems. They do this once and on each subsequent use the application works from use account. I can have my application write the rules file to /etc/udev/rules.d directory but for this I would need root access. What is the best way for a C application to ask user to type the root password and then use it to gain root access. Once this is done, the application can then write the rules file.
If you are using Makefiles, then store the udev rule in the source
distribution of your program and copy it to /etc/wherever as part of
the "INSTALL" target in the makefile. Usually 'make install' is run as
root or with sudo.

Sarah
Post by Ali Asad
-----Original Message-----
From: libhid-discuss-bounces+asad.ali=gemalto.com at lists.alioth.debian.org [mailto:libhid-discuss-bounces+asad.ali=gemalto.com at lists.alioth.debian.org] On Behalf Of Xiaofan Chen
Sent: Tuesday, March 31, 2009 12:15 AM
To: libhid-discuss at lists.alioth.debian.org
Subject: Re: [libhid-discuss] Talking to an HID device from user account in Linux
Post by Peter Stuge
Post by Ali Asad
This technique would be orthogonal to the approach of using libhid
to create our own device driver, but I want to explore all options.
Then you could also look into hiddev and/or hidraw. They can be used
to communicate with HID devices at a higher level than USB.
CONFIG_HID_DEV /usr/src/linux/Documentation/usb/hiddev.txt
CONFIG_HIDRAW http://cateee.net/lkddb/web-lkddb/HIDRAW.html (brief)
hiddev may come with restrictions on which non-HID-class things your
device can do however - but still worth looking into.
You may still need to write a udev rule even if you use the hiddev
or hidraw interface unless the system has already udev rules
in place.
I am not familiar with hiddev but there is an example here.
http://openprog.altervista.org/OP_eng.html
Last time it is said that hiddev is not a good option for generic
HID device but hidraw might be an option.
http://osdir.com/ml/lib.libusb.devel.general/2007-04/msg00233.html
Xiaofan
_______________________________________________
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/
_______________________________________________
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/
--
Sarah Mount, Senior Lecturer, University of Wolverhampton
Web: http://www.wlv.ac.uk/~in0316/
Book: http://www.pythonforrookies.org/
WSN: http://www.fieldsensing.org.uk/
Photos: http://flickr.com/photos/sarahmount/

This email, together with any attachment, is for the exclusive and
confidential use of the addressee(s) and may contain legally
privileged information. Any use, disclosure or reproduction without
the sender's explicit consent is unauthorised and may be unlawful.

Any e-mail including its content and any attachments may be monitored
and used by The University of Wolverhampton for reasons of security
and for monitoring internal compliance with the University's policy on
internet use. E-mail blocking software may also be used. The
University cannot guarantee that this message or any attachment is
virus free or has not been intercepted and amended.

If you believe you have received this message in error please notify
the sender by email, telephone or fax and destroy the message and any
copies.
Sent from Wolverhampton, United Kingdom
Loading...