Skip to content
Snippets Groups Projects
Commit 056b25e1 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

slight input changes to get_usb_stat

parent 9a5858db
No related branches found
No related tags found
No related merge requests found
...@@ -285,12 +285,12 @@ void remove_newline(char *input) ...@@ -285,12 +285,12 @@ void remove_newline(char *input)
*pos = '\0'; *pos = '\0';
} }
char *get_usb_stat(char *path, char *dir, char *stat) char *get_usb_stat(char *path, char *file)
{ {
char stat_path[PATH_MAX], contents[1024]; char stat_path[PATH_MAX], contents[1024];
FILE *f; FILE *f;
snprintf(stat_path, PATH_MAX, "%s/%s/%s", path, dir, stat); snprintf(stat_path, PATH_MAX, "%s%s", path, file);
f = fopen(stat_path, "r"); f = fopen(stat_path, "r");
if (!f) { if (!f) {
perror("fopen"); perror("fopen");
...@@ -417,18 +417,20 @@ int get_devices_from_path(char *input_path) ...@@ -417,18 +417,20 @@ int get_devices_from_path(char *input_path)
continue; continue;
} }
snprintf(path, PATH_MAX, "%s/", input_path); snprintf(path, PATH_MAX, "%s/", input_path);
name = get_device_name(path); name = get_device_name(path);
if (!name) if (!name)
continue; continue;
printf("found device inside _from_path %s\n", name);
dev = (struct device *)calloc(1, sizeof(*dev)); dev = (struct device *)calloc(1, sizeof(*dev));
if (!dev) { if (!dev) {
perror("calloc"); perror("calloc");
goto fail_dev; goto fail_dev;
} }
dev->usb.product = get_usb_stat(input_path, "", "product");
dev->usb.product_id = get_usb_stat(input_path, "", "idProduct"); dev->usb.product = get_usb_stat(path, "product");
dev->usb.vendor_id = get_usb_stat(input_path, "", "idVendor"); dev->usb.product_id = get_usb_stat(path, "idProduct");
dev->usb.vendor_id = get_usb_stat(path, "idVendor");
dev->usb.if_name = name; dev->usb.if_name = name;
dev->ip = get_device_ip(dev->usb.if_name); dev->ip = get_device_ip(dev->usb.if_name);
...@@ -466,12 +468,14 @@ int get_devices(void) ...@@ -466,12 +468,14 @@ int get_devices(void)
if (strstr(de->d_name, ":") || strstr(de->d_name, "usb")) if (strstr(de->d_name, ":") || strstr(de->d_name, "usb"))
continue; continue;
snprintf(product_path, PATH_MAX, "%s%s/product", usb_path, de->d_name); snprintf(product_path, PATH_MAX, "%s%s/product", usb_path, de->d_name);
memset(&st, 0, sizeof(st)); memset(&st, 0, sizeof(st));
rv = stat(product_path, &st); rv = stat(product_path, &st);
if (rv < 0) { if (rv < 0) {
//perror("stat"); //perror("stat");
continue; continue;
} }
snprintf(path, PATH_MAX, "%s%s/", usb_path, de->d_name); snprintf(path, PATH_MAX, "%s%s/", usb_path, de->d_name);
name = get_device_name(path); name = get_device_name(path);
if (!name) if (!name)
...@@ -481,9 +485,10 @@ int get_devices(void) ...@@ -481,9 +485,10 @@ int get_devices(void)
perror("calloc"); perror("calloc");
goto fail_dev; goto fail_dev;
} }
dev->usb.product = get_usb_stat(usb_path, de->d_name, "product");
dev->usb.product_id = get_usb_stat(usb_path, de->d_name, "idProduct"); dev->usb.product = get_usb_stat(path, "product");
dev->usb.vendor_id = get_usb_stat(usb_path, de->d_name, "idVendor"); dev->usb.product_id = get_usb_stat(path, "idProduct");
dev->usb.vendor_id = get_usb_stat(path, "idVendor");
dev->usb.if_name = name; dev->usb.if_name = name;
dev->ip = get_device_ip(dev->usb.if_name); dev->ip = get_device_ip(dev->usb.if_name);
......
...@@ -35,7 +35,7 @@ void free_usb(struct USB *usb); ...@@ -35,7 +35,7 @@ void free_usb(struct USB *usb);
struct device *search_list(char *name); struct device *search_list(char *name);
char *lexer(char **input, char *delimiter); char *lexer(char **input, char *delimiter);
void remove_newline(char *input); void remove_newline(char *input);
char *get_usb_stat(char *path, char *dir, char *stat); char *get_usb_stat(char *path, char *file);
char *get_device_name(char *dir_name); char *get_device_name(char *dir_name);
char *get_device_ip(char *device_name); char *get_device_ip(char *device_name);
int list_to_blob(struct blob_buf *bb); int list_to_blob(struct blob_buf *bb);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment