static int usb_host_claim_interfaces(USBHostDevice *s, int configuration)

{

    USBDevice *udev = USB_DEVICE(s);

    struct libusb_config_descriptor *conf;

    int rc, i;



    for (i = 0; i < USB_MAX_INTERFACES; i++) {

        udev->altsetting[i] = 0;

    }

    udev->ninterfaces   = 0;

    udev->configuration = 0;



    if (configuration == 0) {

        /* address state - ignore */

        return USB_RET_SUCCESS;

    }



    usb_host_detach_kernel(s);



    rc = libusb_get_active_config_descriptor(s->dev, &conf);

    if (rc != 0) {

        return USB_RET_STALL;

    }



    for (i = 0; i < conf->bNumInterfaces; i++) {

        trace_usb_host_claim_interface(s->bus_num, s->addr, configuration, i);

        rc = libusb_claim_interface(s->dh, i);

        usb_host_libusb_error("libusb_claim_interface", rc);

        if (rc != 0) {

            return USB_RET_STALL;

        }

        s->ifs[i].claimed = true;

    }



    udev->ninterfaces   = conf->bNumInterfaces;

    udev->configuration = configuration;



    libusb_free_config_descriptor(conf);

    return USB_RET_SUCCESS;

}

static int usb_host_claim_interfaces(USBHostDevice *s, int configuration)

{

    USBDevice *udev = USB_DEVICE(s);

    struct libusb_config_descriptor *conf;

    int rc, i;



    for (i = 0; i < USB_MAX_INTERFACES; i++) {

        udev->altsetting[i] = 0;

    }

    udev->ninterfaces   = 0;

    udev->configuration = 0;



    if (configuration == 0) {

        

        return USB_RET_SUCCESS;

    }



    usb_host_detach_kernel(s);



    rc = libusb_get_active_config_descriptor(s->dev, &conf);

    if (rc != 0) {

        return USB_RET_STALL;

    }



    for (i = 0; i < conf->bNumInterfaces; i++) {

        trace_usb_host_claim_interface(s->bus_num, s->addr, configuration, i);

        rc = libusb_claim_interface(s->dh, i);

        usb_host_libusb_error("libusb_claim_interface", rc);

        if (rc != 0) {

            return USB_RET_STALL;

        }

        s->ifs[i].claimed = true;

    }



    udev->ninterfaces   = conf->bNumInterfaces;

    udev->configuration = configuration;



    libusb_free_config_descriptor(conf);

    return USB_RET_SUCCESS;

}

static int FUNC_0(USBHostDevice *VAR_0, int VAR_1)

{

    USBDevice *udev = USB_DEVICE(VAR_0);

    struct libusb_config_descriptor *VAR_2;

    int VAR_3, VAR_4;



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

        udev->altsetting[VAR_4] = 0;

    }

    udev->ninterfaces   = 0;

    udev->VAR_1 = 0;



    if (VAR_1 == 0) {

        

        return USB_RET_SUCCESS;

    }



    usb_host_detach_kernel(VAR_0);



    VAR_3 = libusb_get_active_config_descriptor(VAR_0->dev, &VAR_2);

    if (VAR_3 != 0) {

        return USB_RET_STALL;

    }



    for (VAR_4 = 0; VAR_4 < VAR_2->bNumInterfaces; VAR_4++) {

        trace_usb_host_claim_interface(VAR_0->bus_num, VAR_0->addr, VAR_1, VAR_4);

        VAR_3 = libusb_claim_interface(VAR_0->dh, VAR_4);

        usb_host_libusb_error("libusb_claim_interface", VAR_3);

        if (VAR_3 != 0) {

            return USB_RET_STALL;

        }

        VAR_0->ifs[VAR_4].claimed = true;

    }



    udev->ninterfaces   = VAR_2->bNumInterfaces;

    udev->VAR_1 = VAR_1;



    libusb_free_config_descriptor(VAR_2);

    return USB_RET_SUCCESS;

}

static int FUNC_0(USBHostDevice *VAR_0, int VAR_1)
{ USBDevice *udev = USB_DEVICE(VAR_0); struct libusb_config_descriptor *VAR_2; int VAR_3, VAR_4; for (VAR_4 = 0; VAR_4 < USB_MAX_INTERFACES; VAR_4++) { udev->altsetting[VAR_4] = 0; } udev->ninterfaces   = 0; udev->VAR_1 = 0; if (VAR_1 == 0) { return USB_RET_SUCCESS; } usb_host_detach_kernel(VAR_0); VAR_3 = libusb_get_active_config_descriptor(VAR_0->dev, &VAR_2); if (VAR_3 != 0) { return USB_RET_STALL; } for (VAR_4 = 0; VAR_4 < VAR_2->bNumInterfaces; VAR_4++) { trace_usb_host_claim_interface(VAR_0->bus_num, VAR_0->addr, VAR_1, VAR_4); VAR_3 = libusb_claim_interface(VAR_0->dh, VAR_4); usb_host_libusb_error("libusb_claim_interface", VAR_3); if (VAR_3 != 0) { return USB_RET_STALL; } VAR_0->ifs[VAR_4].claimed = true; } udev->ninterfaces   = VAR_2->bNumInterfaces; udev->VAR_1 = VAR_1; libusb_free_config_descriptor(VAR_2); return USB_RET_SUCCESS; }