Skip to content

Commit

Permalink
Make 'lsusb -t' use the correct device class string names
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gregkh committed Jul 6, 2012
1 parent 7974906 commit bfb14c8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 83 deletions.
61 changes: 7 additions & 54 deletions lsusb-t.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "list.h"
#include "lsusb.h"
#include "names.h"

#define MY_SYSFS_FILENAME_LEN 255
#define MY_PATH_MAX 4096
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
37 changes: 8 additions & 29 deletions lsusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions names.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bfb14c8

Please sign in to comment.