0

I'm trying to get OWPDK (a 1-wire library) to access an USB to 1-wire adapter (DS9490R, based on the DS2490 USB-to-1-wire bridge chip).

This library uses libusb to enumerate devices (using usb_get_busses, then exploring bus->devices for each bus). It will then get the first device that matches vendor and product ID (I only have one plugged in), and call usb_open on it, and then usb_set_configuration on the returned handle.

On my Debian 10 system, when I run this program as root, it works fine.

However, I'd like to run the program as user onewire from group onewire which would get access only to this USB device.

So, I created this file: /etc/udev/rules.d/90-onewire.rules which contains this single line :

SUBSYSTEMS=="usb", ATTRS{vendor}=="04fa", GROUP="onewire", MODE="0660"

I then reload rules with sudo udevadm control --reload

While usb_open works for that user, usb_set_configuration doesn't (returns a non-zero result).

I've tried various combinations in the rule, such as SUBSYSTEM (without S), removing the ATTRS condition, etc, with no luck. What am I missing?

1 Answer 1

0

The usb_set_configuration(3) man page says:

int libusb_set_configuration(libusb_device_handle *devh, int config)

Set the active configuration to config for the device contained by devh. This function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested configuration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently claimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a LIBUSB_ERROR code on failure.

So, which non-zero result are you getting?

If there is a kernel driver for the adapter, you'll get LIBUSB_ERROR_BUSY.

In that case, you (or the library) will need to detach it first. The library can do it automatically if libusb_set_auto_detach_kernel_driver(handle, 1) is set (it might be the default), but probably requires being root to do it successfully.

You might need to blacklist the ds2490 kernel module to prevent it from claiming the 1-wire adapter, if you want the onewire user to have libusb access to it. Create a file named /etc/modprobe.d/blacklist-1wire.conf with the following contents:

blacklist ds2490

Then run modprobe -r ds2490 as root, or reboot.

3
  • usb_set_configuration returns -1. However I don't know if that's LIBUSB_ERROR_BUSY or something else, because that symbol is undeclared. I also tried USB_ERROR_BUSY, undeclared as well. I also didn't find either in any *.h file on my whole system. usb_set_configuration is declared in /usr/include/usb.h but I don't see any error code defined there.
    – youen
    Jan 3, 2021 at 17:06
  • I also get the same error code (-1) after blacklisting ds2490 and rebooting.
    – youen
    Jan 3, 2021 at 17:15
  • In Debian 10, there are 2 versions of libusb available, and each has its corresponding development package: libusb-1.0-0-dev for libusb-1.0-0 and libusb-dev for libusb-0.1-4. The respective .h files are at /usr/include/libusb-1.0/libusb.h and /usr/include/usb.h, but only if the development packages are installed.
    – telcoM
    Jan 3, 2021 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .