From 71413e7723e152371d18de3f090fb427706e49c6 Mon Sep 17 00:00:00 2001 From: Dafydd Crosby Date: Wed, 8 Jun 2011 14:45:30 -0600 Subject: Verbose flag in tree mode shows vendor and product name. When running `lsusb -tv`, devices should have the vendor and product name appended to the row. Signed-off-by: Dafydd Crosby --- devtree.c | 24 +++++++++++++++++------- devtree.h | 2 +- lsusb.c | 26 +------------------------- names.c | 26 ++++++++++++++++++++++++++ names.h | 4 ++++ 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/devtree.c b/devtree.c index 69c93ac..25a5fc2 100644 --- a/devtree.c +++ b/devtree.c @@ -294,10 +294,12 @@ void devtree_processchanges(void) /* ---------------------------------------------------------------------- */ static void dumpdevlist(struct list_head *list, unsigned int level, - unsigned int mask) + unsigned int mask, unsigned int verblevel) { struct usbdevnode *dev; struct list_head *list2; + char vendor[128]; + char product[128]; char buf[512]; char *cp; unsigned int i; @@ -317,15 +319,23 @@ static void dumpdevlist(struct list_head *list, unsigned int level, *cp++ = '`'; } *cp++ = '-'; - snprintf(cp, buf + sizeof(buf) - cp, - "Dev# %3d Vendor 0x%04x Product 0x%04x", - dev->devnum, dev->vendorid, dev->productid); + if (verblevel > 1) { + get_vendor_string(vendor, sizeof(vendor), dev->vendorid); + get_product_string(product, sizeof(product), dev->vendorid, dev->productid); + snprintf(cp, buf + sizeof(buf) - cp, + "Dev# %3d Vendor 0x%04x Product 0x%04x %s %s", + dev->devnum, dev->vendorid, dev->productid, vendor, product); + } else { + snprintf(cp, buf + sizeof(buf) - cp, + "Dev# %3d Vendor 0x%04x Product 0x%04x", + dev->devnum, dev->vendorid, dev->productid); + } lprintf(1, "%s\n", buf); - dumpdevlist(&dev->childlist, level+1, mask); + dumpdevlist(&dev->childlist, level+1, mask, verblevel); } } -void devtree_dump(void) +void devtree_dump(unsigned int verblevel) { struct list_head *list; struct usbbusnode *bus; @@ -333,6 +343,6 @@ void devtree_dump(void) for (list = usbbuslist.next; list != &usbbuslist; list = list->next) { bus = list_entry(list, struct usbbusnode, list); lprintf(1, "Bus# %2d\n", bus->busnum); - dumpdevlist(&bus->childlist, 0, 0); + dumpdevlist(&bus->childlist, 0, 0, verblevel); } } diff --git a/devtree.h b/devtree.h index 8971d06..4348bf3 100644 --- a/devtree.h +++ b/devtree.h @@ -80,7 +80,7 @@ extern void devtree_busdisconnect(struct usbbusnode *bus); extern void devtree_devconnect(struct usbdevnode *dev); extern void devtree_devdisconnect(struct usbdevnode *dev); extern void devtree_processchanges(void); -extern void devtree_dump(void); +extern void devtree_dump(unsigned int verblevel); extern int lprintf(unsigned int vl, const char *format, ...) __attribute__ ((format (printf, 2, 3))); diff --git a/lsusb.c b/lsusb.c index 6ba2288..17e9dce 100644 --- a/lsusb.c +++ b/lsusb.c @@ -207,30 +207,6 @@ static int get_string(libusb_device_handle *dev, char *buf, size_t size, u_int8_ } } -static int get_vendor_string(char *buf, size_t size, u_int16_t vid) -{ - const char *cp; - - if (size < 1) - return 0; - *buf = 0; - if (!(cp = names_vendor(vid))) - return 0; - return snprintf(buf, size, "%s", cp); -} - -static int get_product_string(char *buf, size_t size, u_int16_t vid, u_int16_t pid) -{ - const char *cp; - - if (size < 1) - return 0; - *buf = 0; - if (!(cp = names_product(vid, pid))) - return 0; - return snprintf(buf, size, "%s", cp); -} - static int get_class_string(char *buf, size_t size, u_int8_t cls) { const char *cp; @@ -3929,7 +3905,7 @@ static int treedump(void) } devtree_parsedevfile(fd); close(fd); - devtree_dump(); + devtree_dump(verblevel); return 0; } diff --git a/names.c b/names.c index 3e2ac58..1cb4743 100644 --- a/names.c +++ b/names.c @@ -270,6 +270,32 @@ const char *names_videoterminal(u_int16_t termt) /* ---------------------------------------------------------------------- */ +int get_vendor_string(char *buf, size_t size, u_int16_t vid) +{ + const char *cp; + + if (size < 1) + return 0; + *buf = 0; + if (!(cp = names_vendor(vid))) + return 0; + return snprintf(buf, size, "%s", cp); +} + +int get_product_string(char *buf, size_t size, u_int16_t vid, u_int16_t pid) +{ + const char *cp; + + if (size < 1) + return 0; + *buf = 0; + if (!(cp = names_product(vid, pid))) + return 0; + return snprintf(buf, size, "%s", cp); +} + +/* ---------------------------------------------------------------------- */ + static int new_vendor(const char *name, u_int16_t vendorid) { struct vendor *v; diff --git a/names.h b/names.h index 2235aec..0c491c7 100644 --- a/names.h +++ b/names.h @@ -47,6 +47,10 @@ extern const char *names_langid(u_int16_t langid); extern const char *names_physdes(u_int8_t ph); extern const char *names_bias(u_int8_t b); extern const char *names_countrycode(unsigned int countrycode); + +extern int get_vendor_string(char *buf, size_t size, u_int16_t vid); +extern int get_product_string(char *buf, size_t size, u_int16_t vid, u_int16_t pid); + extern int names_init(char *n); extern void names_exit(void); -- cgit v1.2.1