diff options
author | Dafydd Crosby <dtcrsby@gmail.com> | 2011-06-08 14:45:30 -0600 |
---|---|---|
committer | Dafydd Crosby <dtcrsby@gmail.com> | 2011-06-08 14:45:30 -0600 |
commit | 71413e7723e152371d18de3f090fb427706e49c6 (patch) | |
tree | 5e78a479f4b72ed0af5f84c41a28b4967286298f | |
parent | 7170260942c403a1c6e8359e085e48cf4a14668c (diff) | |
download | usbutils-71413e7723e152371d18de3f090fb427706e49c6.tar.gz |
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 <dtcrsby@gmail.com>
-rw-r--r-- | devtree.c | 24 | ||||
-rw-r--r-- | devtree.h | 2 | ||||
-rw-r--r-- | lsusb.c | 26 | ||||
-rw-r--r-- | names.c | 26 | ||||
-rw-r--r-- | names.h | 4 |
5 files changed, 49 insertions, 33 deletions
@@ -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); } } @@ -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))); @@ -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; } @@ -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; @@ -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); |