commit 1b5db92dbd54dc1e4ccdfde3848e31457196a6c8
parent 57a1b3850e65f37c2282177f6201439eefcb49a2
Author: Brian Swetland <swetland@frotz.net>
Date: Sun, 20 Apr 2014 12:03:08 -0700
add README and -b and -b options
Diffstat:
A | README | | | 20 | ++++++++++++++++++++ |
M | usbmon.c | | | 24 | +++++++++++++++++++++--- |
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/README b/README
@@ -0,0 +1,20 @@
+
+USBMON
+------
+
+A simple tool to trace linux USB activity, using /dev/usbmon0.
+
+By default it dumps all USB traffic. Use options:
+
+ -b### dump only bus ###
+ -d### dump only device ###
+ -x### exclude device ### from dump
+
+If you don't have /dev/usbmon0 you probably need to load the driver:
+% sudo modprobe usbmon
+
+And you will likely have to adjust permissions too (unless you want to
+run this program as root):
+% sudo chown $USER /dev/usbmon0
+
+
diff --git a/usbmon.c b/usbmon.c
@@ -41,6 +41,7 @@ int main(int argc, char **argv)
struct usbmon_get arg;
unsigned char filter_dev[128];
int fd, r, n;
+ unsigned busmask = 0;
memset(filter_dev, 0, sizeof(filter_dev));
@@ -53,12 +54,23 @@ int main(int argc, char **argv)
while (argc--) {
if (argv[0][0] == '-') {
switch(argv[0][1]) {
- case 'x':
+ case 'x': /* eXclude device */
r = atoi(argv[0] + 2);
if ((r < 0) || (r > 127))
continue;
filter_dev[r] = 1;
break;
+ case 'b': /* limit to Bus */
+ r = atoi(argv[0] + 2);
+ busmask = ~(1 << r);
+ break;
+ case 'd': /* limit to Device */
+ memset(filter_dev, 0x01, sizeof(filter_dev));
+ r = atoi(argv[0] + 2);
+ if ((r < 0) || (r > 127))
+ continue;
+ filter_dev[r] = 0;
+ break;
}
}
argv++;
@@ -73,6 +85,8 @@ int main(int argc, char **argv)
break;
if (filter_dev[hdr.devnum])
continue;
+ if (busmask & (1 << hdr.busnum))
+ continue;
printf("%d.%03d.%03d %c %c%c %04x",
hdr.busnum, hdr.devnum, hdr.epnum & 0x7F,
hdr.type,
@@ -107,8 +121,11 @@ int main(int argc, char **argv)
case -ETIMEDOUT:
printf(" TIMEDOUT\n");
break;
+ case -EREMOTEIO:
+ printf(" OK (SHORT)\n");
+ break;
default:
- printf(" %s\n", strerror(-hdr.status));
+ printf(" %s (%d)\n", strerror(-hdr.status),-hdr.status);
}
}
if (!hdr.len_cap)
@@ -118,8 +135,9 @@ dumpdata:
if (hdr.len_cap > sizeof(data))
hdr.len_cap = sizeof(data);
for (n = 0; n < hdr.len_cap; n++)
- printf((n & 3) ? "%02x" : " %02x",data[n]);
+ printf((n & 3) ? " %02x" : " %02x",data[n]);
printf("\n");
+ fflush(stdout);
}
return 0;
}