15
15
static int FAST_FUNC fileAction (
16
16
const char * fileName ,
17
17
struct stat * statbuf UNUSED_PARAM ,
18
- void * userData UNUSED_PARAM ,
18
+ void * userData ,
19
19
int depth UNUSED_PARAM )
20
20
{
21
21
parser_t * parser ;
22
22
char * tokens [4 ];
23
- char * busnum = NULL , * devnum = NULL ;
23
+ char * busnum = NULL , * devnum = NULL , * devname = NULL ;
24
24
int product_vid = 0 , product_did = 0 ;
25
25
char * uevent_filename = concat_path_file (fileName , "/uevent" );
26
26
27
27
parser = config_open2 (uevent_filename , fopen_for_read );
28
28
free (uevent_filename );
29
29
30
- while (config_read (parser , tokens , 4 , 2 , "\\/ =" , PARSE_NORMAL )) {
30
+ while (config_read (parser , tokens , 4 , 2 , "\\=" , PARSE_NORMAL )) {
31
31
if ((parser -> lineno == 1 ) && strcmp (tokens [0 ], "DEVTYPE" ) == 0 ) {
32
32
break ;
33
33
}
34
34
35
35
if (strcmp (tokens [0 ], "PRODUCT" ) == 0 ) {
36
- product_vid = xstrtou (tokens [1 ], 16 );
37
- product_did = xstrtou (tokens [2 ], 16 );
36
+ sscanf (tokens [1 ], "%x/%x/" , & product_vid , & product_did );
38
37
continue ;
39
38
}
40
39
@@ -47,13 +46,29 @@ static int FAST_FUNC fileAction(
47
46
devnum = xstrdup (tokens [1 ]);
48
47
continue ;
49
48
}
49
+
50
+ if (strcmp (tokens [0 ], "DEVNAME" ) == 0 ) {
51
+ devname = xstrdup (tokens [1 ]);
52
+ continue ;
53
+ }
50
54
}
51
55
config_close (parser );
52
56
53
57
if (busnum ) {
54
- printf ("Bus %s Device %s: ID %04x:%04x\n" , busnum , devnum , product_vid , product_did );
58
+ char extra [127 ] = "" ;
59
+ if (userData ) {
60
+ int class ;
61
+ uevent_filename = concat_path_file (fileName , "/bDeviceClass" );
62
+ FILE * tfp = fopen_for_read (uevent_filename );
63
+ free (uevent_filename );
64
+ fscanf (tfp , "%x" , & class );
65
+ fclose (tfp );
66
+ snprintf (extra , sizeof (extra ), " Class: %02X\t/dev/%s" , class , devname );
67
+ }
68
+ printf ("Bus %s Device %s: ID %04x:%04x%s\n" , busnum , devnum , product_vid , product_did , extra );
55
69
free (busnum );
56
70
free (devnum );
71
+ free (devname );
57
72
}
58
73
59
74
return TRUE;
@@ -68,7 +83,7 @@ int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
68
83
ACTION_RECURSE ,
69
84
fileAction ,
70
85
NULL , /* dirAction */
71
- NULL , /* userData */
86
+ argc > 1 ? argv [ 1 ] : NULL , /* userData */
72
87
0 /* depth */ );
73
88
74
89
return EXIT_SUCCESS ;
0 commit comments