【问题标题】:USB permission error using libusb使用 libusb 的 USB 权限错误
【发布时间】:2013-03-04 19:19:02
【问题描述】:

我正在尝试为 USB-to-DMX 转换器 (Velleman VM116) 创建驱动程序。

我遇到的问题是,当我尝试打开 USB 设备并对其进行配置时,它返回一个错误:Configurating USB failed: Operation not permitted,我找不到这个错误代表什么。如何配置 USB 设备的好方法?这是我的代码:

int dmxOpen(){
    int result;

    struct usb_bus *busses;
    struct usb_bus *bus;

    usb_init();
    usb_find_busses();
    result = usb_find_devices();
    if(result < 0){
        perror("Finding USB devices failed");
        return 0;
    }

    usb_set_debug(1);

    busses = usb_get_busses();
    for(bus = busses; bus; bus = bus->next){
        for(dev = bus->devices; dev; dev = dev->next){
             if ((dev->descriptor.idVendor == 0x10cf) && (dev->descriptor.idProduct == 0x8062)){
                udev = usb_open(dev);
#if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
                usb_detach_kernel_driver_np(udev, 0);
#endif
                result = usb_set_configuration(udev, dev->descriptor.bNumConfigurations);
                if(result < 0){
                    usb_close(udev);
                    perror("Configurating USB failed");
                    return 0;
                }
                result = usb_claim_interface(udev, 0);
                if(result < 0){
                    usb_release_interface(udev, 1);
                    usb_close(udev);
                    perror("Claiming USB failed");
                    return 0;
                }
                return 1;
            }
        }
    }
    return 0;
}

顺便说一下,我的电脑在 Linux Debian 64 位上运行,这是设备规格:

Bus 010 Device 002: ID 10cf:8062 Velleman Components, Inc. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x10cf Velleman Components, Inc.
  idProduct          0x8062 
  bcdDevice            0.00
  iManufacturer           1 
  iProduct                2 
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
    HID Device Descriptor:
      bLength                 9
      bDescriptorType        33
      bcdHID               1.00
      bCountryCode            0 Not supported
      bNumDescriptors         1
      bDescriptorType        34 Report
      wDescriptorLength      29
     Report Descriptors: 
       ** UNAVAILABLE **
      Endpoint Descriptor:
    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x81  EP 1 IN
    bmAttributes            3
      Transfer Type            Interrupt
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0008  1x 8 bytes
    bInterval              10
      Endpoint Descriptor:
    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x01  EP 1 OUT
    bmAttributes            3
      Transfer Type            Interrupt
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0008  1x 8 bytes
    bInterval              10

【问题讨论】:

  • 总是,使用 perror 代替 printf
  • 现在我把printf都改成了perror,报错是Configurating USB failed: Operation not permitted,怎么获得权限?
  • 不确定为什么不允许该操作可能是权限问题,请尝试以 root 身份运行它。这是驱动程序方法,还是驱动程序的测试应用程序?
  • 这确实是一个权限问题,当我sudo 时它起作用了。有没有办法可以绕过每次都必须使用管理员权限?
  • 不确定是否可以绕过它,因为您使用的是系统数据结构和方法,所以您必须是 root 才有意义

标签: c permissions usb driver libusb


【解决方案1】:

确实是权限问题,当我sudo时它可以工作

您可以使用UDEV 脚本在附加时更改您的 USB 设备的权限。这样,您无需成为 root 即可允许通过 libusb 进行访问。

【讨论】:

    猜你喜欢
    • 2014-05-07
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多