如何设置界面交替设置

How to set interface alternate setting

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

以下是我的代码片段。

    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, &si) 工作正常但是一旦我释放界面 ret = ioctl(fd, USBDEVFS_RELEASEINTERFACE, &interface); 替代设置正在重置为第一个替代设置。

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

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

永久更改

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