linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Accessing usb devices with USBDEVFS
@ 2006-04-28 17:44 Danny Budik
  2006-04-28 21:14 ` Greg KH
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Danny Budik @ 2006-04-28 17:44 UTC (permalink / raw)
  To: linux-hotplug

I have a question that may or may not be related to hotplugging. I have 
noticed that when I plug in a USB device, it takes about 5 seconds for 
it to show up in /proc/bus/usb/001/xxx. I am using HAL to recognize when 
a USB device is plugged in and USBDEVFS to communicate with my device.

When I plug it in, dbus/HAL instantly recognizes it and sends me a 
message.  But when I make the function call to open it (using fopen on 
the file above) I get an error that the device is not found. In fact, it 
takes about 5 seconds for the device to show up in the /proc/bus/usb/ 
directory so I have to place a sleep(5) line in my C code before I am 
able to open the device.

My test machine is a PIII 733 with FC4, latest kernel, so it is a 
relatively slow machine. Is there a way to predict the time that it 
takes for the device to be accessible with USBDEVFS so that I don't have 
to hardcode the sleep statement?

Thanks,
Danny Budik


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
@ 2006-04-28 21:14 ` Greg KH
  2006-04-29 13:06 ` Kay Sievers
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2006-04-28 21:14 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Apr 28, 2006 at 01:44:08PM -0400, Danny Budik wrote:
> I have a question that may or may not be related to hotplugging. I have 
> noticed that when I plug in a USB device, it takes about 5 seconds for 
> it to show up in /proc/bus/usb/001/xxx.

What kind of USB device is this?

> I am using HAL to recognize when 
> a USB device is plugged in and USBDEVFS to communicate with my device.

You mean "usbfs" right?  The old "usbdevfs" name went away about 3-4
years ago :)

> When I plug it in, dbus/HAL instantly recognizes it and sends me a 
> message.  But when I make the function call to open it (using fopen on 
> the file above) I get an error that the device is not found. In fact, it 
> takes about 5 seconds for the device to show up in the /proc/bus/usb/ 
> directory so I have to place a sleep(5) line in my C code before I am 
> able to open the device.

Can you enable CONFIG_USB_DEBUG, rebuild the kernel, and post the kernel
log messages for when you plug in the device?

Also, what kernel version is this?

thanks,

greg k-h


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
  2006-04-28 21:14 ` Greg KH
@ 2006-04-29 13:06 ` Kay Sievers
  2006-05-01 15:39 ` Danny Budik
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Kay Sievers @ 2006-04-29 13:06 UTC (permalink / raw)
  To: linux-hotplug

On Fri, Apr 28, 2006 at 01:44:08PM -0400, Danny Budik wrote:
> I have a question that may or may not be related to hotplugging. I have 
> noticed that when I plug in a USB device, it takes about 5 seconds for 
> it to show up in /proc/bus/usb/001/xxx. I am using HAL to recognize when 
> a USB device is plugged in and USBDEVFS to communicate with my device.
> 
> When I plug it in, dbus/HAL instantly recognizes it and sends me a 
> message.  But when I make the function call to open it (using fopen on 
> the file above) I get an error that the device is not found. In fact, it 
> takes about 5 seconds for the device to show up in the /proc/bus/usb/ 
> directory so I have to place a sleep(5) line in my C code before I am 
> able to open the device.
> 
> My test machine is a PIII 733 with FC4, latest kernel, so it is a 
> relatively slow machine. Is there a way to predict the time that it 
> takes for the device to be accessible with USBDEVFS so that I don't have 
> to hardcode the sleep statement?

Recent systems don't use /proc for usb access anymore and real device
nodes in /dev/bus/usb instead. HAL sends "usbraw" device anouncements with
"linux.device_file" as a property when the device is created.

Kay


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
  2006-04-28 21:14 ` Greg KH
  2006-04-29 13:06 ` Kay Sievers
@ 2006-05-01 15:39 ` Danny Budik
  2006-05-01 16:57 ` Greg KH
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Danny Budik @ 2006-05-01 15:39 UTC (permalink / raw)
  To: linux-hotplug

Kay Sievers wrote:
> On Fri, Apr 28, 2006 at 01:44:08PM -0400, Danny Budik wrote:
>   
>> I have a question that may or may not be related to hotplugging. I have 
>> noticed that when I plug in a USB device, it takes about 5 seconds for 
>> it to show up in /proc/bus/usb/001/xxx. I am using HAL to recognize when 
>> a USB device is plugged in and USBDEVFS to communicate with my device.
>>
>> When I plug it in, dbus/HAL instantly recognizes it and sends me a 
>> message.  But when I make the function call to open it (using fopen on 
>> the file above) I get an error that the device is not found. In fact, it 
>> takes about 5 seconds for the device to show up in the /proc/bus/usb/ 
>> directory so I have to place a sleep(5) line in my C code before I am 
>> able to open the device.
>>
>> My test machine is a PIII 733 with FC4, latest kernel, so it is a 
>> relatively slow machine. Is there a way to predict the time that it 
>> takes for the device to be accessible with USBDEVFS so that I don't have 
>> to hardcode the sleep statement?
>>     
>
> Recent systems don't use /proc for usb access anymore and real device
> nodes in /dev/bus/usb instead. HAL sends "usbraw" device anouncements with
> "linux.device_file" as a property when the device is created.
>
> Kay
So is there a way then to read from the /dev/bus/usb? Like I mentioned 
in the parent post, I am just using fopen, and the functions provided in 
usbdevice_fs.h and usb.h to read data from the usb device. The device is 
a proprietary sensor that my company makes. Is there a 
manual/documentation about how to do this the more "modern" way?

Thanks,
Danny


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
                   ` (2 preceding siblings ...)
  2006-05-01 15:39 ` Danny Budik
@ 2006-05-01 16:57 ` Greg KH
  2006-05-01 19:00 ` Danny Budik
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2006-05-01 16:57 UTC (permalink / raw)
  To: linux-hotplug

On Mon, May 01, 2006 at 11:39:11AM -0400, Danny Budik wrote:
> Kay Sievers wrote:
> >On Fri, Apr 28, 2006 at 01:44:08PM -0400, Danny Budik wrote:
> >  
> >>I have a question that may or may not be related to hotplugging. I have 
> >>noticed that when I plug in a USB device, it takes about 5 seconds for 
> >>it to show up in /proc/bus/usb/001/xxx. I am using HAL to recognize when 
> >>a USB device is plugged in and USBDEVFS to communicate with my device.
> >>
> >>When I plug it in, dbus/HAL instantly recognizes it and sends me a 
> >>message.  But when I make the function call to open it (using fopen on 
> >>the file above) I get an error that the device is not found. In fact, it 
> >>takes about 5 seconds for the device to show up in the /proc/bus/usb/ 
> >>directory so I have to place a sleep(5) line in my C code before I am 
> >>able to open the device.
> >>
> >>My test machine is a PIII 733 with FC4, latest kernel, so it is a 
> >>relatively slow machine. Is there a way to predict the time that it 
> >>takes for the device to be accessible with USBDEVFS so that I don't have 
> >>to hardcode the sleep statement?
> >>    
> >
> >Recent systems don't use /proc for usb access anymore and real device
> >nodes in /dev/bus/usb instead. HAL sends "usbraw" device anouncements with
> >"linux.device_file" as a property when the device is created.
> >
> >Kay
> So is there a way then to read from the /dev/bus/usb? Like I mentioned 
> in the parent post, I am just using fopen, and the functions provided in 
> usbdevice_fs.h and usb.h to read data from the usb device. The device is 
> a proprietary sensor that my company makes. Is there a 
> manual/documentation about how to do this the more "modern" way?

No, that's still the correct way.  If you use libusb, none of your code
changes at all.   If you are using "raw" usbfs, then just open a
different file.

Hope this helps,

greg k-h


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
                   ` (3 preceding siblings ...)
  2006-05-01 16:57 ` Greg KH
@ 2006-05-01 19:00 ` Danny Budik
  2006-05-01 19:06 ` Greg KH
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Danny Budik @ 2006-05-01 19:00 UTC (permalink / raw)
  To: linux-hotplug


>> So is there a way then to read from the /dev/bus/usb? Like I  
>> mentioned
>> in the parent post, I am just using fopen, and the functions  
>> provided in
>> usbdevice_fs.h and usb.h to read data from the usb device. The  
>> device is
>> a proprietary sensor that my company makes. Is there a
>> manual/documentation about how to do this the more "modern" way?
>
> No, that's still the correct way.  If you use libusb, none of your  
> code
> changes at all.   If you are using "raw" usbfs, then just open a
> different file.
>
> Hope this helps,
>
> greg k-h
>
So that brings me to my next question. I guess I didn't know that  
libusb existed and wrote my own interface functions. Is it because of  
this that whenever I access the USB device, I must be root? Obviously  
that's a security issue. In other words, can I read/write to my USB  
device as a user using libusb?

Danny Budik
Inductive Signature Technologies
Systems Engineer




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
                   ` (4 preceding siblings ...)
  2006-05-01 19:00 ` Danny Budik
@ 2006-05-01 19:06 ` Greg KH
  2006-05-01 19:09 ` Kay Sievers
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2006-05-01 19:06 UTC (permalink / raw)
  To: linux-hotplug

On Mon, May 01, 2006 at 03:00:17PM -0400, Danny Budik wrote:
> 
> >>So is there a way then to read from the /dev/bus/usb? Like I  
> >>mentioned
> >>in the parent post, I am just using fopen, and the functions  
> >>provided in
> >>usbdevice_fs.h and usb.h to read data from the usb device. The  
> >>device is
> >>a proprietary sensor that my company makes. Is there a
> >>manual/documentation about how to do this the more "modern" way?
> >
> >No, that's still the correct way.  If you use libusb, none of your  
> >code
> >changes at all.   If you are using "raw" usbfs, then just open a
> >different file.
> >
> >Hope this helps,
> >
> >greg k-h
> >
> So that brings me to my next question. I guess I didn't know that  
> libusb existed and wrote my own interface functions. Is it because of  
> this that whenever I access the USB device, I must be root? Obviously  
> that's a security issue. In other words, can I read/write to my USB  
> device as a user using libusb?

No, that is what this change in moving the usbfs files from
/proc/bus/usb/ to /dev/bus/usb enables now.  You can create a simple
udev rule to give your device the proper owner:group permissions and
then you will not have to be root to use your program.

Or you could have mounted usbfs with the proper options, but that would
make all usbfs files with that owner:group permissions.

libusb just tries to make writing to usbfs devices easier than handling
the "raw" usb commands.

Hope this helps,

greg k-h


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
                   ` (5 preceding siblings ...)
  2006-05-01 19:06 ` Greg KH
@ 2006-05-01 19:09 ` Kay Sievers
  2006-05-05 20:45 ` Danny Budik
  2006-05-05 21:02 ` Greg KH
  8 siblings, 0 replies; 10+ messages in thread
From: Kay Sievers @ 2006-05-01 19:09 UTC (permalink / raw)
  To: linux-hotplug

On Mon, May 01, 2006 at 03:00:17PM -0400, Danny Budik wrote:
> 
> >>So is there a way then to read from the /dev/bus/usb? Like I  
> >>mentioned
> >>in the parent post, I am just using fopen, and the functions  
> >>provided in
> >>usbdevice_fs.h and usb.h to read data from the usb device. The  
> >>device is
> >>a proprietary sensor that my company makes. Is there a
> >>manual/documentation about how to do this the more "modern" way?
> >
> >No, that's still the correct way.  If you use libusb, none of your  
> >code
> >changes at all.   If you are using "raw" usbfs, then just open a
> >different file.
> >
> >Hope this helps,
> >
> >greg k-h
> >
> So that brings me to my next question. I guess I didn't know that  
> libusb existed and wrote my own interface functions. Is it because of  
> this that whenever I access the USB device, I must be root? Obviously  
> that's a security issue. In other words, can I read/write to my USB  
> device as a user using libusb?

That has nothing to do with the way you access the device it's not
different for libusb or a simple open(). The usual way is to change
the owner/group of the device node or add an user ACL to the
node when it appears and grant access that way to normal users.
There are several solutions out there like pam_console, resmgr, or just
putting the users in a special group.

Kay


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
                   ` (6 preceding siblings ...)
  2006-05-01 19:09 ` Kay Sievers
@ 2006-05-05 20:45 ` Danny Budik
  2006-05-05 21:02 ` Greg KH
  8 siblings, 0 replies; 10+ messages in thread
From: Danny Budik @ 2006-05-05 20:45 UTC (permalink / raw)
  To: linux-hotplug

>>>Recent systems don't use /proc for usb access anymore and real device
>>>nodes in /dev/bus/usb instead. HAL sends "usbraw" device anouncements with
>>>"linux.device_file" as a property when the device is created.
>>>
>>>Kay

I looked at the hal properties of my device and there is no 
linux.device_file property. Does this mean that my device is not 
"usbraw" enabled?

>>So is there a way then to read from the /dev/bus/usb? Like I mentioned 
>>in the parent post, I am just using fopen, and the functions provided in 
>>usbdevice_fs.h and usb.h to read data from the usb device. The device is 
>>a proprietary sensor that my company makes. Is there a 
>>manual/documentation about how to do this the more "modern" way?
> 
> 
> No, that's still the correct way.  If you use libusb, none of your code
> changes at all.   If you are using "raw" usbfs, then just open a
> different file.
> 
> Hope this helps,
> 
> greg k-h
> 
> 

How do I use the "raw" usbfs? I tried reading from the /dev/bus/usb file 
and got a bind - address already in use error.

Danny


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: Accessing usb devices with USBDEVFS
  2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
                   ` (7 preceding siblings ...)
  2006-05-05 20:45 ` Danny Budik
@ 2006-05-05 21:02 ` Greg KH
  8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2006-05-05 21:02 UTC (permalink / raw)
  To: linux-hotplug

On Fri, May 05, 2006 at 04:45:30PM -0400, Danny Budik wrote:
> How do I use the "raw" usbfs? I tried reading from the /dev/bus/usb file 
> and got a bind - address already in use error.

Look at how libusb is implemented for a good example of how to do this.
The source code to 'lsusb' will also help you out here.

good luck,

greg k-h


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid\x120709&bid&3057&dat\x121642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

end of thread, other threads:[~2006-05-05 21:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-28 17:44 Accessing usb devices with USBDEVFS Danny Budik
2006-04-28 21:14 ` Greg KH
2006-04-29 13:06 ` Kay Sievers
2006-05-01 15:39 ` Danny Budik
2006-05-01 16:57 ` Greg KH
2006-05-01 19:00 ` Danny Budik
2006-05-01 19:06 ` Greg KH
2006-05-01 19:09 ` Kay Sievers
2006-05-05 20:45 ` Danny Budik
2006-05-05 21:02 ` Greg KH

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).