static int usb_host_update_interfaces(USBHostDevice *dev, int configuration)

{

    int dev_descr_len, config_descr_len;

    int interface, nb_interfaces, nb_configurations;

    int ret, i;



    if (configuration == 0) /* address state - ignore */

        return 1;



    i = 0;

    dev_descr_len = dev->descr[0];

    if (dev_descr_len > dev->descr_len)

        goto fail;

    nb_configurations = dev->descr[17];



    i += dev_descr_len;

    while (i < dev->descr_len) {

#ifdef DEBUG

        printf("i is %d, descr_len is %d, dl %d, dt %d\n", i, dev->descr_len,

               dev->descr[i], dev->descr[i+1]);

#endif

        if (dev->descr[i+1] != USB_DT_CONFIG) {

            i += dev->descr[i];

            continue;

        }

        config_descr_len = dev->descr[i];



        if (configuration == dev->descr[i + 5])

            break;



        i += config_descr_len;

    }



    if (i >= dev->descr_len) {

        printf("usb_host: error - device has no matching configuration\n");

        goto fail;

    }

    nb_interfaces = dev->descr[i + 4];



#ifdef USBDEVFS_DISCONNECT

    /* earlier Linux 2.4 do not support that */

    {

        struct usbdevfs_ioctl ctrl;

        for (interface = 0; interface < nb_interfaces; interface++) {

            ctrl.ioctl_code = USBDEVFS_DISCONNECT;

            ctrl.ifno = interface;

            ret = ioctl(dev->fd, USBDEVFS_IOCTL, &ctrl);

            if (ret < 0 && errno != ENODATA) {

                perror("USBDEVFS_DISCONNECT");

                goto fail;

            }

        }

    }

#endif



    /* XXX: only grab if all interfaces are free */

    for (interface = 0; interface < nb_interfaces; interface++) {

        ret = ioctl(dev->fd, USBDEVFS_CLAIMINTERFACE, &interface);

        if (ret < 0) {

            if (errno == EBUSY) {

                fprintf(stderr,

                        "usb_host: warning - device already grabbed\n");

            } else {

                perror("USBDEVFS_CLAIMINTERFACE");

            }

        fail:

            return 0;

        }

    }



#ifdef DEBUG

    printf("usb_host: %d interfaces claimed for configuration %d\n",

           nb_interfaces, configuration);

#endif



    return 1;

}

static int usb_host_update_interfaces(USBHostDevice *dev, int configuration)

{

    int dev_descr_len, config_descr_len;

    int interface, nb_interfaces, nb_configurations;

    int ret, i;



    if (configuration == 0) 

        return 1;



    i = 0;

    dev_descr_len = dev->descr[0];

    if (dev_descr_len > dev->descr_len)

        goto fail;

    nb_configurations = dev->descr[17];



    i += dev_descr_len;

    while (i < dev->descr_len) {

#ifdef DEBUG

        printf("i is %d, descr_len is %d, dl %d, dt %d\n", i, dev->descr_len,

               dev->descr[i], dev->descr[i+1]);

#endif

        if (dev->descr[i+1] != USB_DT_CONFIG) {

            i += dev->descr[i];

            continue;

        }

        config_descr_len = dev->descr[i];



        if (configuration == dev->descr[i + 5])

            break;



        i += config_descr_len;

    }



    if (i >= dev->descr_len) {

        printf("usb_host: error - device has no matching configuration\n");

        goto fail;

    }

    nb_interfaces = dev->descr[i + 4];



#ifdef USBDEVFS_DISCONNECT

    

    {

        struct usbdevfs_ioctl ctrl;

        for (interface = 0; interface < nb_interfaces; interface++) {

            ctrl.ioctl_code = USBDEVFS_DISCONNECT;

            ctrl.ifno = interface;

            ret = ioctl(dev->fd, USBDEVFS_IOCTL, &ctrl);

            if (ret < 0 && errno != ENODATA) {

                perror("USBDEVFS_DISCONNECT");

                goto fail;

            }

        }

    }

#endif



    

    for (interface = 0; interface < nb_interfaces; interface++) {

        ret = ioctl(dev->fd, USBDEVFS_CLAIMINTERFACE, &interface);

        if (ret < 0) {

            if (errno == EBUSY) {

                fprintf(stderr,

                        "usb_host: warning - device already grabbed\n");

            } else {

                perror("USBDEVFS_CLAIMINTERFACE");

            }

        fail:

            return 0;

        }

    }



#ifdef DEBUG

    printf("usb_host: %d interfaces claimed for configuration %d\n",

           nb_interfaces, configuration);

#endif



    return 1;

}

static int FUNC_0(USBHostDevice *VAR_0, int VAR_1)

{

    int VAR_2, VAR_3;

    int VAR_4, VAR_5, VAR_6;

    int VAR_7, VAR_8;



    if (VAR_1 == 0) 

        return 1;



    VAR_8 = 0;

    VAR_2 = VAR_0->descr[0];

    if (VAR_2 > VAR_0->descr_len)

        goto fail;

    VAR_6 = VAR_0->descr[17];



    VAR_8 += VAR_2;

    while (VAR_8 < VAR_0->descr_len) {

#ifdef DEBUG

        printf("VAR_8 is %d, descr_len is %d, dl %d, dt %d\n", VAR_8, VAR_0->descr_len,

               VAR_0->descr[VAR_8], VAR_0->descr[VAR_8+1]);

#endif

        if (VAR_0->descr[VAR_8+1] != USB_DT_CONFIG) {

            VAR_8 += VAR_0->descr[VAR_8];

            continue;

        }

        VAR_3 = VAR_0->descr[VAR_8];



        if (VAR_1 == VAR_0->descr[VAR_8 + 5])

            break;



        VAR_8 += VAR_3;

    }



    if (VAR_8 >= VAR_0->descr_len) {

        printf("usb_host: error - device has no matching VAR_1\n");

        goto fail;

    }

    VAR_5 = VAR_0->descr[VAR_8 + 4];



#ifdef USBDEVFS_DISCONNECT

    

    {

        struct usbdevfs_ioctl ctrl;

        for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) {

            ctrl.ioctl_code = USBDEVFS_DISCONNECT;

            ctrl.ifno = VAR_4;

            VAR_7 = ioctl(VAR_0->fd, USBDEVFS_IOCTL, &ctrl);

            if (VAR_7 < 0 && errno != ENODATA) {

                perror("USBDEVFS_DISCONNECT");

                goto fail;

            }

        }

    }

#endif



    

    for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) {

        VAR_7 = ioctl(VAR_0->fd, USBDEVFS_CLAIMINTERFACE, &VAR_4);

        if (VAR_7 < 0) {

            if (errno == EBUSY) {

                fprintf(stderr,

                        "usb_host: warning - device already grabbed\n");

            } else {

                perror("USBDEVFS_CLAIMINTERFACE");

            }

        fail:

            return 0;

        }

    }



#ifdef DEBUG

    printf("usb_host: %d interfaces claimed for VAR_1 %d\n",

           VAR_5, VAR_1);

#endif



    return 1;

}

static int FUNC_0(USBHostDevice *VAR_0, int VAR_1)
{ int VAR_2, VAR_3; int VAR_4, VAR_5, VAR_6; int VAR_7, VAR_8; if (VAR_1 == 0)
return 1; VAR_8 = 0; VAR_2 = VAR_0->descr[0]; if (VAR_2 > VAR_0->descr_len)
goto fail; VAR_6 = VAR_0->descr[17]; VAR_8 += VAR_2; while (VAR_8 < VAR_0->descr_len) { #ifdef DEBUG
printf("VAR_8 is %d, descr_len is %d, dl %d, dt %d\n", VAR_8, VAR_0->descr_len,
VAR_0->descr[VAR_8], VAR_0->descr[VAR_8+1]); #endif
if (VAR_0->descr[VAR_8+1] != USB_DT_CONFIG) { VAR_8 += VAR_0->descr[VAR_8]; continue; } VAR_3 = VAR_0->descr[VAR_8]; if (VAR_1 == VAR_0->descr[VAR_8 + 5])
break; VAR_8 += VAR_3; } if (VAR_8 >= VAR_0->descr_len) { printf("usb_host: error - device has no matching VAR_1\n"); goto fail; } VAR_5 = VAR_0->descr[VAR_8 + 4]; #ifdef USBDEVFS_DISCONNECT
{ struct usbdevfs_ioctl ctrl; for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) { ctrl.ioctl_code = USBDEVFS_DISCONNECT; ctrl.ifno = VAR_4; VAR_7 = ioctl(VAR_0->fd, USBDEVFS_IOCTL, &ctrl); if (VAR_7 < 0 && errno != ENODATA) { perror("USBDEVFS_DISCONNECT"); goto fail; } } } #endif
for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) { VAR_7 = ioctl(VAR_0->fd, USBDEVFS_CLAIMINTERFACE, &VAR_4); if (VAR_7 < 0) { if (errno == EBUSY) { fprintf(stderr,
"usb_host: warning - device already grabbed\n"); } else { perror("USBDEVFS_CLAIMINTERFACE"); } fail:
return 0; } } #ifdef DEBUG
printf("usb_host: %d interfaces claimed for VAR_1 %d\n",
VAR_5, VAR_1); #endif
return 1; }