[PATCH] 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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Dafydd Crosby <dtcrsby@xxxxxxxxx>
---
 devtree.c |   48 +++++++++++++++++++++++++++++++++++++++++-------
 devtree.h |    2 +-
 lsusb.c   |    2 +-
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/devtree.c b/devtree.c
index 69c93ac..8ce0611 100644
--- a/devtree.c
+++ b/devtree.c
@@ -39,6 +39,7 @@
 #include <unistd.h>
 
 #include "devtree.h"
+#include "names.h"
 
 /* ---------------------------------------------------------------------- */
 
@@ -58,6 +59,30 @@ static void freebus(struct usbbusnode *bus)
 
 /* ---------------------------------------------------------------------- */
 
+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 void markdel(struct list_head *list)
 {
 	struct usbdevnode *dev;
@@ -294,11 +319,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 buf[512];
+	char vendor[128], product[128];
 	char *cp;
 	unsigned int i;
 
@@ -317,15 +343,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 +367,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..e2c451d 100644
--- a/lsusb.c
+++ b/lsusb.c
@@ -3929,7 +3929,7 @@ static int treedump(void)
 	}
 	devtree_parsedevfile(fd);
 	close(fd);
-	devtree_dump();
+	devtree_dump(verblevel);
 	return 0;
 }
 
-- 
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux