Bugfixes
[wifihood] / wifisniffer / wifilogger.py
index 6163e9d..8b44527 100755 (executable)
@@ -3,7 +3,11 @@
 import pcapy
 import struct
 
+import pyiw
+import threading
+
 iface = 'wlan0'
+wlan = pyiw.WirelessInterface(iface)
 
 import time
 
@@ -20,6 +24,19 @@ read_timeout = 100 # in milliseconds
 pc = pcapy.open_live(iface, max_bytes, promiscuous, read_timeout)
 
 
+channel_hop = [ 30.0 , False ]
+
+def channel_change ( ) :
+    try :
+        wlan["channel"] = ( wlan["channel"] ) % 12 + 1
+    except pyiw.error, error:
+        print "PYIW error : %s" % error
+    else :
+        if channel_hop[0] :
+            channel_hop[1] = threading.Timer( channel_hop[0] , channel_change ) 
+            channel_hop[1].start()
+
+
 def parse_radiotap( radiotap , it_present ) :
 
     fields = []
@@ -124,8 +141,13 @@ def dealWithPacket ( hdr , data ) :
                 frame_subtype = name
                 break
         else :
-            print "ERROR : unknown CTL subtype %s" % ( frame_ctl & 0xf0 , )
-            return
+            if frame_ctl & 0xf0 == 144 :
+                frame_subtype = "CF_END_ACK"
+            elif frame_ctl & 0xf0 == 128 :
+                frame_subtype = "UNKNOWN_1"
+            else :
+                print "ERROR : unknown CTL subtype %s" % ( frame_ctl & 0xf0 , )
+                return
 
     elif frame_type == "DATA" :
         _subtype = []
@@ -168,7 +190,7 @@ def dealWithPacket ( hdr , data ) :
         sequence = ( -1 , -1 )
 
 
-    if frame_type == "DATA" :
+    if frame_type == "DATA" and pcktlen > 6 :
         maclist.append( mac_fmt % struct.unpack( mac_str , payload[pointer:pointer+6] ) )
         pointer += 6
         pcktlen -= 6
@@ -183,15 +205,22 @@ def dealWithPacket ( hdr , data ) :
 
     curtime = time.time()
     if curtime - tstamp > max_time :
+        channel_hop[0] = 0
         raise CaptureEnd( "Neighborhoud scan completed" )
 
 
+if channel_hop[0]  :
+    channel_hop[1] = threading.Timer( channel_hop[0] , channel_change ) 
+    channel_hop[1].start()
+
+
 packet_limit = -1 # infinite
 try :
     pc.loop( packet_limit , dealWithPacket )
 except CaptureEnd , ex :
     print "FINISED : %s" % ex
 except Exception , ex :
+    channel_hop[0] = 0
     print "ERROR : %s" % ex
 
 logfile.close()