summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-06 13:03:58 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-06 13:03:58 -0700
commitbfb14c83406e797763a38e9477d84fd8b5013211 (patch)
tree32dd29d65867863f7f6fa064ed86440baab2a519
parent797490624ac2118bd6ddcc10b112335cf52c45de (diff)
downloadusbutils-bfb14c83406e797763a38e9477d84fd8b5013211.tar.gz
Make 'lsusb -t' use the correct device class string names
This fixes the annoying "bInterfaceClass 0x0e not yet handled" messages in 'lsusb -t' for video devices, and will handle any future class types as well. Just one step in merging 'lsusb -t' into the main portion of the program instead of really just being a stand-alone program. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--lsusb-t.c61
-rw-r--r--lsusb.c37
-rw-r--r--names.c24
-rw-r--r--names.h2
4 files changed, 41 insertions, 83 deletions
diff --git a/lsusb-t.c b/lsusb-t.c
index 92a9830..074dafb 100644
--- a/lsusb-t.c
+++ b/lsusb-t.c
@@ -11,6 +11,7 @@
#include "list.h"
#include "lsusb.h"
+#include "names.h"
#define MY_SYSFS_FILENAME_LEN 255
#define MY_PATH_MAX 4096
@@ -117,58 +118,6 @@ static void dump_usbinterface(struct usbinterface *i)
#endif
static char tmp_str[128];
-static const char *bInterfaceClass_to_str(unsigned int dc)
-{
- const char *s;
- switch (dc) {
- case 0:
- s = ">ifc";
- break;
- case 1:
- s = "audio";
- break;
- case 2:
- s = "comm.";
- break;
- case 3:
- s = "HID";
- break;
- case 5:
- s = "PID";
- break;
- case 6:
- s = "still";
- break;
- case 7:
- s = "print";
- break;
- case 8:
- s = "stor.";
- break;
- case 9:
- s = "hub";
- break;
- case 10:
- s = "data";
- break;
- case 11:
- s = "scard";
- break;
- case 13:
- s = "c-sec";
- break;
- case 254:
- s = "app.";
- break;
- case 255:
- s = "vend.";
- break;
- default:
- snprintf(tmp_str, 128, "'bInterfaceClass 0x%02x not yet handled'", dc);;
- s = tmp_str;
- }
- return s;
-}
static const char *bDeviceClass_to_str(unsigned int dc)
{
const char *s;
@@ -190,11 +139,15 @@ static void print_usbbusnode(struct usbbusnode *b)
static void print_usbdevice(struct usbdevice *d, struct usbinterface *i)
{
+ char subcls[128];
+
+ get_class_string(subcls, sizeof(subcls), i->bInterfaceClass);
+
if (i->bInterfaceClass == 9)
- printf("Port %u: Dev %u, If %u, Class=%s, Driver=%s/%up, %sM\n", d->portnum, d->devnum, i->ifnum, bInterfaceClass_to_str(i->bInterfaceClass),
+ printf("Port %u: Dev %u, If %u, Class=%s, Driver=%s/%up, %sM\n", d->portnum, d->devnum, i->ifnum, subcls,
i->driver, d->maxchild, d->speed);
else
- printf("Port %u: Dev %u, If %u, Class=%s, Driver=%s, %sM\n", d->portnum, d->devnum, i->ifnum, bInterfaceClass_to_str(i->bInterfaceClass), i->driver,
+ printf("Port %u: Dev %u, If %u, Class=%s, Driver=%s, %sM\n", d->portnum, d->devnum, i->ifnum, subcls, i->driver,
d->speed);
}
diff --git a/lsusb.c b/lsusb.c
index 783180b..2a709f6 100644
--- a/lsusb.c
+++ b/lsusb.c
@@ -194,30 +194,6 @@ static int get_string(libusb_device_handle *dev, char *buf, size_t size, u_int8_
return 0;
}
-static int get_class_string(char *buf, size_t size, u_int8_t cls)
-{
- const char *cp;
-
- if (size < 1)
- return 0;
- *buf = 0;
- if (!(cp = names_class(cls)))
- return 0;
- return snprintf(buf, size, "%s", cp);
-}
-
-static int get_subclass_string(char *buf, size_t size, u_int8_t cls, u_int8_t subcls)
-{
- const char *cp;
-
- if (size < 1)
- return 0;
- *buf = 0;
- if (!(cp = names_subclass(cls, subcls)))
- return 0;
- return snprintf(buf, size, "%s", cp);
-}
-
static int get_protocol_string(char *buf, size_t size, u_int8_t cls, u_int8_t subcls, u_int8_t proto)
{
const char *cp;
@@ -4015,11 +3991,6 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (treemode) {
- /* treemode requires at least verblevel 1 */
- verblevel += 1 - VERBLEVEL_DEFAULT;
- return treedump();
- }
/* by default, print names as well as numbers */
err = names_init(DATADIR "/usb.ids");
@@ -4034,6 +4005,14 @@ int main(int argc, char *argv[])
strerror(err));
status = 0;
+ if (treemode) {
+ /* treemode requires at least verblevel 1 */
+ verblevel += 1 - VERBLEVEL_DEFAULT;
+ status = treedump();
+ names_exit();
+ return status;
+ }
+
err = libusb_init(&ctx);
if (err) {
fprintf(stderr, "unable to initialize libusb: %i\n", err);
diff --git a/names.c b/names.c
index 25763d5..12cbd60 100644
--- a/names.c
+++ b/names.c
@@ -290,6 +290,30 @@ int get_product_string(char *buf, size_t size, u_int16_t vid, u_int16_t pid)
return snprintf(buf, size, "%s", cp);
}
+int get_class_string(char *buf, size_t size, u_int8_t cls)
+{
+ const char *cp;
+
+ if (size < 1)
+ return 0;
+ *buf = 0;
+ if (!(cp = names_class(cls)))
+ return 0;
+ return snprintf(buf, size, "%s", cp);
+}
+
+int get_subclass_string(char *buf, size_t size, u_int8_t cls, u_int8_t subcls)
+{
+ const char *cp;
+
+ if (size < 1)
+ return 0;
+ *buf = 0;
+ if (!(cp = names_subclass(cls, subcls)))
+ return 0;
+ return snprintf(buf, size, "%s", cp);
+}
+
/* ---------------------------------------------------------------------- */
static int new_vendor(const char *name, u_int16_t vendorid)
diff --git a/names.h b/names.h
index 8227a45..0eba890 100644
--- a/names.h
+++ b/names.h
@@ -46,6 +46,8 @@ 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 get_class_string(char *buf, size_t size, u_int8_t cls);
+extern int get_subclass_string(char *buf, size_t size, u_int8_t cls, u_int8_t subcls);
extern int names_init(char *n);
extern void names_exit(void);