v4l2-apps/util/parse-sniffusb2.pl: new version
authorDouglas Schilling Landgraf <dougsland@redhat.com>
Tue, 19 Jan 2010 18:04:51 +0000 (16:04 -0200)
committerDouglas Schilling Landgraf <dougsland@redhat.com>
Tue, 19 Jan 2010 18:04:51 +0000 (16:04 -0200)
From: Franklin Meng <fmeng2002@yahoo.com>

Priority: normal

Signed-off-by: Franklin Meng <fmeng2002@yahoo.com>
Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>
utils/parse-sniffusb2.pl

index 34406b0..9ba715f 100755 (executable)
@@ -8,6 +8,8 @@ use strict;
 use warnings;
 use Data::Dumper;
 
+my $urbhash;
+
 foreach my $curfile (@ARGV) {
        parsefile($curfile);
        #we can only process 1 file
@@ -16,69 +18,108 @@ foreach my $curfile (@ARGV) {
 
 sub parsefile {
        my $curfile = shift;
-       my $SetupPacket ='';
-       my $preS = '';
-       my $TransferBuffer ='';
-       my $preT = '';
-       my $Direction ='';
-       my $preD = '';
-       my @tmpsplit;
-       my $t=0;
-       my $s=0;
+
+       my $s1 = 0;
+       my $t1 = 0;
+       my $tmp1 = "";
+       my $printurb = 0;
+       my $cururb = 0;
 
        open(FD, $curfile) || die("Error: $!\n");
 
        while(<FD>) {
                chomp;
-               if($t==1 && /^\s+\d{8}/) {
-#                      print $_ . "\n";
-                       @tmpsplit = split(/\:\s/,$_);
-                       $TransferBuffer = $TransferBuffer . $tmpsplit[1] . " ";
-               } elsif($s==1 && /^\s+\d{8}/) {
-#                      print $_ . "\n";
-                       @tmpsplit = split(/\:\s/,$_);
-                       $SetupPacket = $SetupPacket . $tmpsplit[1] ;
-               } else {
-                       $t=0;
-                       $s=0;
-               }
-               if(/[<>]{3}/){
-                       #print out last packet if valid
-                       if($SetupPacket) {
-                               if($preT) {
-                                       print "$SetupPacket $preD $preT\n";
-
-                               } else {
-                                       print "$SetupPacket $Direction $TransferBuffer\n";
-                               }
+               if (/URB\s+(\d+)\s+going\s+down/) {
+                       # print previous urb if available
+                       if($printurb != 0 && exists($urbhash->{$printurb}->{'SetupPacket'})) {
+                               print "$urbhash->{$printurb}->{'SetupPacket'} $urbhash->{$printurb}->{'Direction'} $urbhash->{$printurb}->{'TransferBufferMDL'}\n";
+#                              # delete urb information
+#                              delete($urbhash->{$printurb});
+                       }
+                       # delete urb information
+                       delete($urbhash->{$printurb});
+                       $printurb = 0;  #reset here
+                       $tmp1 = "";
+                       $s1 = 0;
+                       $t1 = 0;
+                       # store next urb info here
+                       $cururb = $1;
+                       $urbhash->{$1} = undef;
+                       next;
+               } elsif (/URB\s+(\d+)\s+coming\s+back/) {
+                       # print previous urb if available
+                       if($printurb != 0 && exists($urbhash->{$printurb}->{'SetupPacket'})) {
+                               print "$urbhash->{$printurb}->{'SetupPacket'} $urbhash->{$printurb}->{'Direction'} $urbhash->{$printurb}->{'TransferBufferMDL'}\n";
+#                              # delete urb information
+#                              delete($urbhash->{$printurb});
+                       }
+                       # delete urb information
+                       delete($urbhash->{$printurb});
+                       $printurb = 0;  #reset here
+                       $tmp1 = "";
+                       $s1 = 0;
+                       $t1 = 0;
+                       # flag next urb for print out
+                       if(exists($urbhash->{$1})) {
+                               $printurb = $1;
+                       } else {
+                               warn "Error: cannot match urb!!\n";
+                       }
+                       $cururb = $1;
+                       next;
+               } elsif (/\-{2}\s+(URB_FUN.+)\:/) {  # store urb function (used for debugging)
+                       if(!exists($urbhash->{$cururb}->{'Function'})) {
+                               $urbhash->{$cururb}->{'Function'} = $1;
+                       }
+                       next;
+               } elsif (/USBD_TRANSFER_DIRECTION_IN/) {  #store in direction
+                       #check if we already stored a value
+                       if(!exists($urbhash->{$cururb}->{'Direction'})) {
+                               $urbhash->{$cururb}->{'Direction'} = "<<<";
                        }
-#                      print "$SetupPacket $Direction $TransferBuffer\n";
-                       #clear variables
-                       $preT = $TransferBuffer;
-                       $TransferBuffer = '';
-                       $preS = $SetupPacket;
-                       $SetupPacket = '';
-                       $preD = $Direction;
-                       $t = 0;
-                       $s = 0;
-                       # get direction
-                       @tmpsplit = split(/\s+/, $_);
-                       $Direction = $tmpsplit[2];
-#                      print $_ . "\n";
-               } elsif(/TransferBufferMDL/) {
-                       $t = 1
-               } elsif(/SetupPacket/) {
-                       $s = 1;
+                       next;
+               } elsif (/USBD_TRANSFER_DIRECTION_OUT/) { #store out direction
+                       #check if we already stored a value
+                       if(!exists($urbhash->{$cururb}->{'Direction'})) {
+                               $urbhash->{$cururb}->{'Direction'} = ">>>";
+                       }
+                       next;
+               } elsif (/TransferBufferMDL\s+=\s+/) {  #flag data packet
+                       $t1 = 1;
+                       next;
+               } elsif (/SetupPacket\s+=/) {  #flag setup packet
+                       $s1 = 1;
+                       next;
+               } elsif (/(.+\s+\=|ms\])/ && ($s1 || $t1)) { #save data packet and reset
+                       if($s1 && ($tmp1 ne "")) {
+                               $tmp1 =~ s/^\s+//;
+                               $urbhash->{$cururb}->{'SetupPacket'} = $tmp1;
+                       } elsif($t1 && ($tmp1 ne "")) {
+                               $tmp1 =~ s/^\s+//;
+                               $urbhash->{$cururb}->{'TransferBufferMDL'} = $tmp1
+                       }
+                       $tmp1 = "";
+                       $s1 = 0;
+                       $t1 = 0;
+                       next;
+               } elsif (/^\s+\d+\:(.+)/ && ($s1 || $t1)) { #capture packet
+                       $tmp1 = $tmp1 . $1;
                }
+
        }
-       #print last packet
-#      print "$SetupPacket $Direction $TransferBuffer\n";
-       if($SetupPacket) {
-               if($preT) {
-                       print "$SetupPacket $preD $preT\n";
-               } else {
-                       print "$SetupPacket $Direction $TransferBuffer\n";
-               }
+
+       # print remaining URB
+       if($printurb != 0 && exists($urbhash->{$printurb}->{'SetupPacket'})) {
+               print "$urbhash->{$printurb}->{'SetupPacket'} $urbhash->{$printurb}->{'Direction'} $urbhash->{$printurb}->{'TransferBufferMDL'}\n";
+#              # delete urb information
+#              delete($urbhash->{$printurb});
        }
+       # delete urb information
+       delete($urbhash->{$printurb});
+
+       # Maybe we should warn for the URB's that did not have matches?
+
+       # print out stuff remaining in the hash for debugging
+       #print Dumper($urbhash);
 }