【问题标题】:How to set interface alternate setting如何设置界面交替设置
【发布时间】:2018-05-20 04:59:33
【问题描述】:

我正在尝试使用 USBFS IOCTL 调用设置接口的备用设置。

以下是我的代码 sn-p。

    int interface = 3;
    struct usbdevfs_ioctl command;
    struct usbdevfs_getdriver getdrv;

    getdrv.interface = interface;
    ret = ioctl(fd, USBDEVFS_GETDRIVER, &getdrv);
    if (ret < 0)
    {
            print((" get driver failed %d %d", ret, errno));
    }

    command.ifno = interface;
    command.ioctl_code = USBDEVFS_DISCONNECT;
    command.data = NULL;
    ret = ioctl(fd, USBDEVFS_IOCTL, &command);
    if (ret < 0)
    {
            print((" detach driver failed %d %d", ret, errno));
    }

   ret = ioctl(fd, USBDEVFS_CLAIMINTERFACE, &interface);
    if (ret < 0)
   {
            print(("claim interface failed %d %d", ret, errno));
   }

    si.interface = 3;
    si.altsetting = setZerobandwidth;
    ret = ioctl(fd, USBDEVFS_SETINTERFACE, &si);
    if (ret < 0)
    {
            print(("set interface ioctl failed %d %d", ret, errno));

    }

    ret = ioctl(fd, USBDEVFS_RELEASEINTERFACE, &interface);
    if (ret < 0)
   {
            print(("release interface ioctl failed %d %d", ret, errno));
   }

    command.ifno = interface;
    command.ioctl_code = USBDEVFS_CONNECT;
    command.data = NULL;

    ret = ioctl(fd, USBDEVFS_IOCTL, &command);

    if (ret < 0)
    {
            print(("attach driver ioctl failed %d %d", ret, errno));
    }

但是ret = ioctl(fd, USBDEVFS_SETINTERFACE, &amp;si) 工作正常,但是一旦我释放接口ret = ioctl(fd, USBDEVFS_RELEASEINTERFACE, &amp;interface); 备用设置正在重置为第一个替代设置。

根据 libusb API 文档,libusb_release_interface 会将备用设置重置为第一个备用设置。 请帮助我了解我需要遵循的 IOCTL 调用。

【问题讨论】:

    标签: linux-kernel usb driver libusb ioctl


    【解决方案1】:

    您无法从user space 永久更改alt setting。 这可以从kernal space 永久更改。

    我建议你关闭端点的使用,一旦你关闭内核会将其设置为零带宽接口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多