From patchwork Wed Oct 10 13:39:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 1573851 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 6430CDFB34 for ; Wed, 10 Oct 2012 13:45:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756325Ab2JJNpH (ORCPT ); Wed, 10 Oct 2012 09:45:07 -0400 Received: from smtp209.alice.it ([82.57.200.105]:37349 "EHLO smtp209.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754675Ab2JJNpG (ORCPT ); Wed, 10 Oct 2012 09:45:06 -0400 X-Greylist: delayed 337 seconds by postgrey-1.27 at vger.kernel.org; Wed, 10 Oct 2012 09:45:06 EDT Received: from jcn (87.1.92.64) by smtp209.alice.it (8.6.023.02) id 506F18A000A9A3D1; Wed, 10 Oct 2012 15:39:27 +0200 Received: from ao2 by jcn with local (Exim 4.80) (envelope-from ) id 1TLwVR-00039r-1v; Wed, 10 Oct 2012 15:39:25 +0200 From: Antonio Ospite To: linux-media@vger.kernel.org Cc: Aapo Tahkola , CityK Subject: [PATCH 2/5] contrib: add a script to convert usbmon captures to usbsnoop Date: Wed, 10 Oct 2012 15:39:19 +0200 Message-Id: <1349876363-12098-3-git-send-email-ospite@studenti.unina.it> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1349876363-12098-1-git-send-email-ospite@studenti.unina.it> References: <1349876363-12098-1-git-send-email-ospite@studenti.unina.it> X-Face: z*RaLf`X<@C75u6Ig9}{oW$H; 1_\2t5)({*|jhM/Vb; ]yA5\I~93>J<_`<4)A{':UrE Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Aapo Tahkola This makes it possible to reuse tools written for usbsnoop with captures done using a virtual machine and usbmon. Signed-off-by: Aapo Tahkola --- contrib/usbmon2usbsnoop.pl | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 contrib/usbmon2usbsnoop.pl diff --git a/contrib/usbmon2usbsnoop.pl b/contrib/usbmon2usbsnoop.pl new file mode 100755 index 0000000..c656687 --- /dev/null +++ b/contrib/usbmon2usbsnoop.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl +# +# This perl script converts output from usbmon to a format (usbsnoop's log format) that is compatible with usbreplay. +# Taken from http://www.linuxtv.org/wiki/index.php/Usbmon2usbsnoop + +sub print_bytes{ + my($str) = @_; + + @str_1 = split(/ /, $str); + + foreach(@str_1){ + if (length($_) == 8) { + print substr($_, 0, 2) . " " . substr($_, 2, 2) . " " . substr($_, 4, 2) . " " . substr($_, 6, 2); + }elsif(length($_) == 4) { + print substr($_, 2, 2) . " " . substr($_, 0, 2); + }elsif(length($_) == 2) { + print $_; + }elsif(length($_) == 1) { + next; + } + print " "; + } +} + + +$i = 0; +while($line = ) { + $i++; + + if($line =~ m/\S+ \S+ \S+ \S+ \S+ (.+) \S+ ; + $i++; + if($line =~ m/\S+ \S+ \S+ \S+ [a-fA-F0-9 ]+ = ([a-fA-F0-9 ]+)/) { + print_bytes($1); + #print "\n"; + #print " $1\n"; + } + print "\n"; + }elsif($line =~ m/\S+ \S+ \S+ \S+ ([a-fA-F0-9 ]+) [a-fA-F0-9]+ = ([a-fA-F0-9 ]+)/) { + printf "%06d: OUT: %06d ms %06d ms ", $i, 1, $i; + print_bytes($1); + print ">>> "; + print_bytes($2); + print "\n"; + }elsif($line =~ m/\S+ \S+ \S+ \S+ s (.+)/) { + printf "%06d: OUT: %06d ms %06d ms ", $i, 1, $i; + print_bytes($1); + print ">>>\n"; + } +}