static int usb_host_scan_dev(void *opaque, USBScanFunc *func)

{

    FILE *f = NULL;

    char line[1024];

    char buf[1024];

    int bus_num, addr, speed, device_count, class_id, product_id, vendor_id;

    char product_name[512];

    int ret = 0;



    if (!usb_host_device_path) {

        perror("husb: USB Host Device Path not set");

        goto the_end;

    }

    snprintf(line, sizeof(line), "%s/devices", usb_host_device_path);

    f = fopen(line, "r");

    if (!f) {

        perror("husb: cannot open devices file");

        goto the_end;

    }



    device_count = 0;

    bus_num = addr = class_id = product_id = vendor_id = 0;

    speed = -1; /* Can't get the speed from /[proc|dev]/bus/usb/devices */

    for(;;) {

        if (fgets(line, sizeof(line), f) == NULL) {

            break;

        }

        if (strlen(line) > 0) {

            line[strlen(line) - 1] = '\0';

        }

        if (line[0] == 'T' && line[1] == ':') {

            if (device_count && (vendor_id || product_id)) {

                /* New device.  Add the previously discovered device.  */

                ret = func(opaque, bus_num, addr, 0, class_id, vendor_id,

                           product_id, product_name, speed);

                if (ret) {

                    goto the_end;

                }

            }

            if (get_tag_value(buf, sizeof(buf), line, "Bus=", " ") < 0) {

                goto fail;

            }

            bus_num = atoi(buf);

            if (get_tag_value(buf, sizeof(buf), line, "Dev#=", " ") < 0) {

                goto fail;

            }

            addr = atoi(buf);

            if (get_tag_value(buf, sizeof(buf), line, "Spd=", " ") < 0) {

                goto fail;

            }

            if (!strcmp(buf, "5000")) {

                speed = USB_SPEED_SUPER;

            } else if (!strcmp(buf, "480")) {

                speed = USB_SPEED_HIGH;

            } else if (!strcmp(buf, "1.5")) {

                speed = USB_SPEED_LOW;

            } else {

                speed = USB_SPEED_FULL;

            }

            product_name[0] = '\0';

            class_id = 0xff;

            device_count++;

            product_id = 0;

            vendor_id = 0;

        } else if (line[0] == 'P' && line[1] == ':') {

            if (get_tag_value(buf, sizeof(buf), line, "Vendor=", " ") < 0) {

                goto fail;

            }

            vendor_id = strtoul(buf, NULL, 16);

            if (get_tag_value(buf, sizeof(buf), line, "ProdID=", " ") < 0) {

                goto fail;

            }

            product_id = strtoul(buf, NULL, 16);

        } else if (line[0] == 'S' && line[1] == ':') {

            if (get_tag_value(buf, sizeof(buf), line, "Product=", "") < 0) {

                goto fail;

            }

            pstrcpy(product_name, sizeof(product_name), buf);

        } else if (line[0] == 'D' && line[1] == ':') {

            if (get_tag_value(buf, sizeof(buf), line, "Cls=", " (") < 0) {

                goto fail;

            }

            class_id = strtoul(buf, NULL, 16);

        }

    fail: ;

    }

    if (device_count && (vendor_id || product_id)) {

        /* Add the last device.  */

        ret = func(opaque, bus_num, addr, 0, class_id, vendor_id,

                   product_id, product_name, speed);

    }

 the_end:

    if (f) {

        fclose(f);

    }

    return ret;

}

static int usb_host_scan_dev(void *opaque, USBScanFunc *func)

{

    FILE *f = NULL;

    char line[1024];

    char buf[1024];

    int bus_num, addr, speed, device_count, class_id, product_id, vendor_id;

    char product_name[512];

    int ret = 0;



    if (!usb_host_device_path) {

        perror("husb: USB Host Device Path not set");

        goto the_end;

    }

    snprintf(line, sizeof(line), "%s/devices", usb_host_device_path);

    f = fopen(line, "r");

    if (!f) {

        perror("husb: cannot open devices file");

        goto the_end;

    }



    device_count = 0;

    bus_num = addr = class_id = product_id = vendor_id = 0;

    speed = -1; 

    for(;;) {

        if (fgets(line, sizeof(line), f) == NULL) {

            break;

        }

        if (strlen(line) > 0) {

            line[strlen(line) - 1] = '\0';

        }

        if (line[0] == 'T' && line[1] == ':') {

            if (device_count && (vendor_id || product_id)) {

                

                ret = func(opaque, bus_num, addr, 0, class_id, vendor_id,

                           product_id, product_name, speed);

                if (ret) {

                    goto the_end;

                }

            }

            if (get_tag_value(buf, sizeof(buf), line, "Bus=", " ") < 0) {

                goto fail;

            }

            bus_num = atoi(buf);

            if (get_tag_value(buf, sizeof(buf), line, "Dev#=", " ") < 0) {

                goto fail;

            }

            addr = atoi(buf);

            if (get_tag_value(buf, sizeof(buf), line, "Spd=", " ") < 0) {

                goto fail;

            }

            if (!strcmp(buf, "5000")) {

                speed = USB_SPEED_SUPER;

            } else if (!strcmp(buf, "480")) {

                speed = USB_SPEED_HIGH;

            } else if (!strcmp(buf, "1.5")) {

                speed = USB_SPEED_LOW;

            } else {

                speed = USB_SPEED_FULL;

            }

            product_name[0] = '\0';

            class_id = 0xff;

            device_count++;

            product_id = 0;

            vendor_id = 0;

        } else if (line[0] == 'P' && line[1] == ':') {

            if (get_tag_value(buf, sizeof(buf), line, "Vendor=", " ") < 0) {

                goto fail;

            }

            vendor_id = strtoul(buf, NULL, 16);

            if (get_tag_value(buf, sizeof(buf), line, "ProdID=", " ") < 0) {

                goto fail;

            }

            product_id = strtoul(buf, NULL, 16);

        } else if (line[0] == 'S' && line[1] == ':') {

            if (get_tag_value(buf, sizeof(buf), line, "Product=", "") < 0) {

                goto fail;

            }

            pstrcpy(product_name, sizeof(product_name), buf);

        } else if (line[0] == 'D' && line[1] == ':') {

            if (get_tag_value(buf, sizeof(buf), line, "Cls=", " (") < 0) {

                goto fail;

            }

            class_id = strtoul(buf, NULL, 16);

        }

    fail: ;

    }

    if (device_count && (vendor_id || product_id)) {

        

        ret = func(opaque, bus_num, addr, 0, class_id, vendor_id,

                   product_id, product_name, speed);

    }

 the_end:

    if (f) {

        fclose(f);

    }

    return ret;

}

static int FUNC_0(void *VAR_0, USBScanFunc *VAR_1)

{

    FILE *f = NULL;

    char VAR_2[1024];

    char VAR_3[1024];

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    char VAR_11[512];

    int VAR_12 = 0;



    if (!usb_host_device_path) {

        perror("husb: USB Host Device Path not set");

        goto the_end;

    }

    snprintf(VAR_2, sizeof(VAR_2), "%s/devices", usb_host_device_path);

    f = fopen(VAR_2, "r");

    if (!f) {

        perror("husb: cannot open devices file");

        goto the_end;

    }



    VAR_7 = 0;

    VAR_4 = VAR_5 = VAR_8 = VAR_9 = VAR_10 = 0;

    VAR_6 = -1; 

    for(;;) {

        if (fgets(VAR_2, sizeof(VAR_2), f) == NULL) {

            break;

        }

        if (strlen(VAR_2) > 0) {

            VAR_2[strlen(VAR_2) - 1] = '\0';

        }

        if (VAR_2[0] == 'T' && VAR_2[1] == ':') {

            if (VAR_7 && (VAR_10 || VAR_9)) {

                

                VAR_12 = VAR_1(VAR_0, VAR_4, VAR_5, 0, VAR_8, VAR_10,

                           VAR_9, VAR_11, VAR_6);

                if (VAR_12) {

                    goto the_end;

                }

            }

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Bus=", " ") < 0) {

                goto fail;

            }

            VAR_4 = atoi(VAR_3);

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Dev#=", " ") < 0) {

                goto fail;

            }

            VAR_5 = atoi(VAR_3);

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Spd=", " ") < 0) {

                goto fail;

            }

            if (!strcmp(VAR_3, "5000")) {

                VAR_6 = USB_SPEED_SUPER;

            } else if (!strcmp(VAR_3, "480")) {

                VAR_6 = USB_SPEED_HIGH;

            } else if (!strcmp(VAR_3, "1.5")) {

                VAR_6 = USB_SPEED_LOW;

            } else {

                VAR_6 = USB_SPEED_FULL;

            }

            VAR_11[0] = '\0';

            VAR_8 = 0xff;

            VAR_7++;

            VAR_9 = 0;

            VAR_10 = 0;

        } else if (VAR_2[0] == 'P' && VAR_2[1] == ':') {

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Vendor=", " ") < 0) {

                goto fail;

            }

            VAR_10 = strtoul(VAR_3, NULL, 16);

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "ProdID=", " ") < 0) {

                goto fail;

            }

            VAR_9 = strtoul(VAR_3, NULL, 16);

        } else if (VAR_2[0] == 'S' && VAR_2[1] == ':') {

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Product=", "") < 0) {

                goto fail;

            }

            pstrcpy(VAR_11, sizeof(VAR_11), VAR_3);

        } else if (VAR_2[0] == 'D' && VAR_2[1] == ':') {

            if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Cls=", " (") < 0) {

                goto fail;

            }

            VAR_8 = strtoul(VAR_3, NULL, 16);

        }

    fail: ;

    }

    if (VAR_7 && (VAR_10 || VAR_9)) {

        

        VAR_12 = VAR_1(VAR_0, VAR_4, VAR_5, 0, VAR_8, VAR_10,

                   VAR_9, VAR_11, VAR_6);

    }

 the_end:

    if (f) {

        fclose(f);

    }

    return VAR_12;

}

static int FUNC_0(void *VAR_0, USBScanFunc *VAR_1)
{ FILE *f = NULL; char VAR_2[1024]; char VAR_3[1024]; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; char VAR_11[512]; int VAR_12 = 0; if (!usb_host_device_path) { perror("husb: USB Host Device Path not set"); goto the_end; } snprintf(VAR_2, sizeof(VAR_2), "%s/devices", usb_host_device_path); f = fopen(VAR_2, "r"); if (!f) { perror("husb: cannot open devices file"); goto the_end; } VAR_7 = 0; VAR_4 = VAR_5 = VAR_8 = VAR_9 = VAR_10 = 0; VAR_6 = -1; for(;;) { if (fgets(VAR_2, sizeof(VAR_2), f) == NULL) { break; } if (strlen(VAR_2) > 0) { VAR_2[strlen(VAR_2) - 1] = '\0'; } if (VAR_2[0] == 'T' && VAR_2[1] == ':') { if (VAR_7 && (VAR_10 || VAR_9)) { VAR_12 = VAR_1(VAR_0, VAR_4, VAR_5, 0, VAR_8, VAR_10,
VAR_9, VAR_11, VAR_6); if (VAR_12) { goto the_end; } } if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Bus=", " ") < 0) { goto fail; } VAR_4 = atoi(VAR_3); if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Dev#=", " ") < 0) { goto fail; } VAR_5 = atoi(VAR_3); if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Spd=", " ") < 0) { goto fail; } if (!strcmp(VAR_3, "5000")) { VAR_6 = USB_SPEED_SUPER; } else if (!strcmp(VAR_3, "480")) { VAR_6 = USB_SPEED_HIGH; } else if (!strcmp(VAR_3, "1.5")) { VAR_6 = USB_SPEED_LOW; } else { VAR_6 = USB_SPEED_FULL; } VAR_11[0] = '\0'; VAR_8 = 0xff; VAR_7++; VAR_9 = 0; VAR_10 = 0; } else if (VAR_2[0] == 'P' && VAR_2[1] == ':') { if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Vendor=", " ") < 0) { goto fail; } VAR_10 = strtoul(VAR_3, NULL, 16); if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "ProdID=", " ") < 0) { goto fail; } VAR_9 = strtoul(VAR_3, NULL, 16); } else if (VAR_2[0] == 'S' && VAR_2[1] == ':') { if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Product=", "") < 0) { goto fail; } pstrcpy(VAR_11, sizeof(VAR_11), VAR_3); } else if (VAR_2[0] == 'D' && VAR_2[1] == ':') { if (get_tag_value(VAR_3, sizeof(VAR_3), VAR_2, "Cls=", " (") < 0) { goto fail; } VAR_8 = strtoul(VAR_3, NULL, 16); } fail: ; } if (VAR_7 && (VAR_10 || VAR_9)) { VAR_12 = VAR_1(VAR_0, VAR_4, VAR_5, 0, VAR_8, VAR_10,
VAR_9, VAR_11, VAR_6); } the_end:
if (f) { fclose(f); } return VAR_12; }