2

I have a Netware uniFlow device. When I plug it in it shows up in dmesg:

[ 2962.369905] usb 2-1.4: new full-speed USB device number 11 using ehci-pci
[ 2962.463867] usb 2-1.4: New USB device found, idVendor=171b, idProduct=2001
[ 2962.463871] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2962.463874] usb 2-1.4: Product: USB Keyboard
[ 2962.463876] usb 2-1.4: Manufacturer: RFIDeas
[ 2962.465361] input: RFIDeas USB Keyboard as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/0003:171B:2001.0008/input/input17
[ 2962.465481] hid-generic 0003:171B:2001.0008: input,hidraw3: USB HID v1.10 Keyboard [RFIDeas USB Keyboard] on usb-0000:00:1d.0-1.4/input0

It also appears in the listed USB devices, with the lsusb command:

Bus 002 Device 011: ID 171b:2001

Correct me if I am wrong here, but I think I need to unbind the device, so that I may use pyusb to to communicate with the device. When I try to run my code, I get resource busy errors.

So then I cd'd down to /sys/bus/usb/devices/usb2/2-1/2-1.4 (taken form dmesg) and then tried to unbind the device using

sudo sh -c echo "2-1.4:1.0 > unbind"

But I got permission denied. So I logged in as root, but I still got permission denied.

Here is my source code that I am trying to use to communicate with the device:

#!/usr/bin/env python
import usb.core
import usb.util
import sys

# Find our device from lsusb
# Vendor : Product     171b:2001
dev = usb.core.find(idVendor=0x171b, idProduct=0x2001)

# Was it found?
if dev is None:
    raise ValueError('Device not found')

    # Set the active configuration. With no arguments, the first
    # configuration will be the active one
dev.set_configuration()

    # Let's fuzz around!

    # Let's start by reading one byte from the device using different requests
    # bRequest is a byte so there are 255 different values
for bRequest in range(255):
    try:
        ret = dev.ctrl_transfer(0xC0, bRequest, 0, 0, 1)
        print "bRequest ",bRequest
        print ret
    except:
       # Failed to get data for this request
         pass

And here are the errors, I get when I try to run the program:

$ sudo python usbhax.py
Traceback (most recent call last):
  File "usbhax.py", line 16, in <module>
    dev.set_configuration()
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 799, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 128, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 730, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy

What am I doing wrong? What can I do to communicate with this device?

Yes, I have libusb installed, and pyusb. I am working from a Ubuntu environment.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
j0h
  • 1,675
  • 6
  • 27
  • 50

1 Answers1

3

In my experience, you have to have set up a rules file for the device for the udev system

  1. Something along the lines of:

    ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="171b", ATTRS{idProduct}=="2001", MODE="660", GROUP="plugdev"
    

    in a file called /lib/udev/rules.d/50-YourSoftwareName.rules (for example, dig around in man udev for file naming rules but 50-usbhax.rules should do)

  2. Add your username to the plugdev group

    adduser username plugdev
    
  3. Reload rules

    sudo udevadm control --reload (that is minus minus reload)
    sudo udevadm trigger

  4. Unplug and replug the device or reboot your machine and see if it works.

NOTE: Some systems use the group input rather than plugdev, so edit the above accordingly.
To check what your system uses have a look at the group name for the relevant entries in /dev/usb or /dev/input

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
  • I had to add the `SUBSYSTEM=="usb", ` (singular) in addition to the `SUBSYSTEMS=="usb"` (plural), set `MODE="0666"`, and reboot in order to be able to access the Keysight TMC device without root/sudo. – skitheo Nov 10 '16 at 21:25
  • Also, reading `man udev` says that local changes should be made to `/etc/udev/rules.d` **not** `/lib/udev/rules.d/`. – skitheo Nov 10 '16 at 21:28
  • @skitheo As I said, check the `group` name in `/dev/usb` or `/dev/input` for the group relevant to your machine. `/lib/udev/rules.d/` holds the default entries, whilst `/etc/udev/rules.d/` contains the customised rules. the `/etc` rules can be used to override the default entries but if you don't have any default rules for your device, it's a toss up as to whether you use /etc/udev or /lib/udev, both are valid. – Rolf of Saxony Nov 11 '16 at 09:59
  • I think it's considered best practice to only make changes in `/etc/udev/rules.d`. As it turns out, Ubuntu-based distributions (may be other Debian derivatives) do not have `/dev/usb`, but `/dev/bus/usb/nnn/mmm` where `nnn` = bus number `mmm` = device number, both from `lsusb`. In addition `SUBSYSTEMS` (plural) does not seem to be defined for udev, according to the man page, etc. – skitheo Nov 16 '16 at 23:19
  • @skitheo I am not sure where your information is coming from but my `udev` man page details both `SUBSYSTEM` (Match the subsystem of the event device) and `SUBSYSTEMS` (Search the devpath upwards for a matching device subsystem name). Similarly my `Ubuntu` based OS (3.19.0-32-generic #37~14.04.1-Ubuntu) has both `/dev/usb` and `/dev/bus/usb/nnn/mmm`. So either your last comment is incorrect and therefore misleading or my box is some sort of Frankenstein machine. – Rolf of Saxony Nov 17 '16 at 09:50
  • 1
    I was mistaken. You do not have a Frankenstein machine. Initial read did not show the plural. I think it's a bit confusing to have both. – skitheo Nov 22 '16 at 20:00