diff --git a/dongle.c b/dongle.c index ee571563479852309e0b3ae23d5ff24007c89b8b..3cca1c730725b4dc1b6aab73c0c806b0eca5e062 100644 --- a/dongle.c +++ b/dongle.c @@ -466,15 +466,13 @@ fail_dr: int get_devices(void) { - char usb_path[PATH_MAX], product_path[PATH_MAX], path[PATH_MAX], *name; + char devices_path[PATH_MAX], mount_path[PATH_MAX]; struct dirent *de; DIR *dir; - struct stat st; - struct device *dev; int rv; - strncpy(usb_path, "/sys/bus/usb/devices/", PATH_MAX); - dir = opendir(usb_path); + strncpy(devices_path, "/sys/bus/usb/devices/", PATH_MAX); + dir = opendir(devices_path); if (!dir) { perror("opendir"); goto fail_dr; @@ -485,38 +483,14 @@ int get_devices(void) continue; if (strstr(de->d_name, ":") || strstr(de->d_name, "usb")) continue; - snprintf(product_path, PATH_MAX, "%s%s/product", usb_path, de->d_name); - - memset(&st, 0, sizeof(st)); - rv = stat(product_path, &st); - if (rv < 0) { - //perror("stat"); - continue; - } - - snprintf(path, PATH_MAX, "%s%s/", usb_path, de->d_name); - name = get_device_name(path); - if (!name) - continue; - - dev = (struct device *)calloc(1, sizeof(*dev)); - if (!dev) { - perror("calloc"); - goto fail_dev; - } - dev->usb.product = get_usb_stat(path, "product"); - dev->usb.product_id = get_usb_stat(path, "idProduct"); - dev->usb.vendor_id = get_usb_stat(path, "idVendor"); - dev->usb.if_name = name; - dev->ip = get_device_ip(dev->usb.if_name); - - add_device(dev); + snprintf(mount_path, PATH_MAX, "%s%s/", devices_path, de->d_name); + rv = get_devices_from_path(mount_path); + if (rv < 0) + break; } closedir(dir); return 0; -fail_dev: - closedir(dir); fail_dr: return -1; }