1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/perl
use strict;
# Copyright (C) 2010 Mauro Carvalho Chehab
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# This small script parses USB dumps generated by several drivers,
# decoding USB bits.
#
# To use it, do:
# dmesg | ./parse_usb.pl
#
# Also, there are other utilities that produce similar outputs, and it
# is not hard to parse some USB analyzers log into the expected format.
#
sub type_req($)
{
my $reqtype = shift;
my $s;
if ($reqtype & 0x80) {
$s = "RD ";
} else {
$s = "WR ";
}
if (($reqtype & 0x60) == 0x20) {
$s .= "CLAS ";
} elsif (($reqtype & 0x60) == 0x40) {
$s .= "VEND ";
} elsif (($reqtype & 0x60) == 0x60) {
$s .= "RSVD ";
}
if (($reqtype & 0x1f) == 0x00) {
$s .= "DEV ";
} elsif (($reqtype & 0x1f) == 0x01) {
$s .= "INT ";
} elsif (($reqtype & 0x1f) == 0x02) {
$s .= "EP ";
} elsif (($reqtype & 0x1f) == 0x03) {
$s .= "OTHER ";
} elsif (($reqtype & 0x1f) == 0x04) {
$s .= "PORT ";
} elsif (($reqtype & 0x1f) == 0x05) {
$s .= "RPIPE ";
} else {
$s .= sprintf "RECIP 0x%02x ", $reqtype & 0x1f;
}
$s =~ s/\s+$//;
return $s;
}
while (<>) {
if (m/(.*)([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].)[\<\>\s]+(.*)/) {
my $timestamp = $1;
my $reqtype = hex($2);
my $req = hex($3);
my $wvalue = hex("$5$4");
my $windex = hex("$7$6");
my $wlen = hex("$9$8");
my $payload = $10;
$timestamp =~ s/^\s+//;
$timestamp =~ s/\s+$//;
printf("%s %s(0x%02x), Req 0x%02x, wValue: 0x%04x, wIndex 0x%04x, wlen %d: %s\n",
$timestamp, type_req($reqtype), $reqtype, $req, $wvalue, $windex, $wlen, $payload);
}
}
|