#!/usr/bin/awk -f # # This script generates a more readable log from a sniffusb log. # # Usage: parseusbsnoop.awk < usbsnoop.log > log1.txt # # It works with sniffusb 1.8 ("UsbSnoop compiled on Jan 18 2003 22:41:32") # # This script is based on a idea by Thomas SOUMARMON (soumarmt hotmail com). # # Author: Frank Zago (base work) # Gerhard Jaeger (some formatting stuff) # # License: GPL v2 # # Note: this script does its best to ignore returning URB from interrupts. BEGIN { # number of data until the output will be skipped skiplen = 256; # 0 means don't format the output, > 0 the number of output values per line nl = 8; # if you don't want the timestamps, set "want_time" to 0 want_time = 1; # the "run-time" vars action = ""; buffer[0] = 0; rtype = 0; request = 0; value = 0; rindex = 0; ignore_urb = 0; last_int_urb = -1; } { if ($4 == "URB" ) { if( $1 == "*******" ) { # comment line printf("warning: line %d ignored:\n%s\n",NR,$0); ignore_urb = 1; next; } # get the time field tt = strtonum(substr($1,2)); time = ""; fill = "\n "; if( want_time ) { time = sprintf( "%9dms ", tt ); fill = fill " "; } # New URB this_urb = strtonum($5); if (this_urb == last_int_urb) { # this interrupt URB is coming back ignore_urb = 1; next; } # this happens, when we try to analyze only a portion of log if( last_int_urb == -1 ) { last_int_urb = this_urb - 1; urb = this_urb - 1; } if (way == "down" && $7 == "down") { # This URB is also an interrupt URB printf "%sURB %5d skip\n", time, this_urb; ignore_urb = 1; last_int_urb = this_urb; next; } old_way = way; way = $7; if (way == "back") { if (urb != this_urb) { printf "got URB back %d instead of %d at line %d\n", this_urb, urb, NR; exit; } } else if (way == "down") { ignore_urb = 0; if (this_urb != urb+1 && this_urb != urb+2) { printf "expected URB down %d instead of %d at line %d\n", urb+1, this_urb, NR; exit; } if (last_int_urb != urb) { if (endpoint == "CONTROL") { printf "%sURB %5d %c%c control 0x%02x 0x%02x 0x%02x 0x%02x len %5d", time, urb, last_action, action, rtype, request, value, rindex, buflen; if (direction == "OUT") { printf(" wrote "); } else { printf(" read "); } j = 0; for (i=0; i skiplen) { printf("SKIPPED\n"); } else { j = 0; for (i=0; i skiplen) { printf("SKIPPED\n"); } else { j = 0; for (i=0; i 16) data_len = 16; else data_len = data_left; if (NF == (data_len+1)) { data_left = data_left - data_len; for (i=0; i