1

I am working with an embedded platform. Typical software in this devices are Linux 2.6 + Busybox, so resources are limited.

I need to run an user space application every time a USB device is connected. I need to pass as parameter to this user space app the DeviceID and ProductID.

I don't really know which strategy should I follow to achieve this:

  • Writing a linux kernel module.
  • Doing it from inside the kernel (usb drivers) i'm currently doing this, but i dont think its the best way to do it
  • A user space app that 'polls' for usb connected devices.?

Which one should be the best way?

Thanks for your answer!

fazineroso
  • 7,196
  • 7
  • 31
  • 42
  • there is very similar question to yours http://stackoverflow.com/questions/7115731/linux-usb-connect-disconnect-event hope it helps – aisbaa Jul 17 '12 at 07:13
  • RegisterDeviceNotification kinda API helps you? – 2vision2 Jul 17 '12 at 09:13
  • 1
    [udev can do this](http://superuser.com/questions/305723/using-udev-rules-to-run-a-script-on-usb-insertion) and is the way to go. No need to faff with kernel level stuff at all. – Flexo Jul 17 '12 at 17:42
  • unfortunately sysfs is not available in the system. – fazineroso Jul 18 '12 at 06:49

3 Answers3

2

If you want to remain in user space, then you can use libudev.

You have an example here. You can extract product id and device id from this.

Community
  • 1
  • 1
Alexandru C.
  • 3,337
  • 1
  • 25
  • 27
0

Even though other options like @aisbaa mentioned, modifying kernel is interesting and challenging one. I suggest you to modify the USB driver. Reason is, you need to send the arguments to the user space application(Product ID, Device ID).

These Ids will be obtained in driver. so calling user space app with these Ids are my choice.

For calling user space app nice explanation available here.

Jeyaram
  • 9,158
  • 7
  • 41
  • 63
  • There's already a mechanism for running user programs when devices are connected. Reinventing the wheel might be interesting, but it's not the way to solve this for real. – Flexo Jul 17 '12 at 17:44
0

To the best of my knowledge, there is a mechanism for USB hot plugging in the kernel. When a hot plug event happens, the user can be notified. Unfortunately, I am not very familiar with the details.

Maybe linux-3.3.5/samples/kobject/kset-example.c will give you some ideas.

User
  • 566
  • 5
  • 9
shawn xy bai
  • 158
  • 6