Package killerbee :: Package zbwardrive :: Module db
[hide private]
[frames] | no frames]

Source Code for Module killerbee.zbwardrive.db

 1  import string 
 2   
 3  # Manages Local "database" for ZBWarDrive: 
 4  # This keeps track of current ZBWarDrive and Sniffing Device State. 
 5  # It is different from the online logging database. 
 6   
7 -class ZBScanDB:
8 """ 9 API to interact with the "database" storing information 10 for the zbscanning program. 11 """ 12
13 - def __init__(self):
14 self.channels = {11:None, 12:None, 13:None, 14:None, 15:None, 16:None, 17:None, 18:None, 19:None, 20:None, 21:None, 22:None, 23:None, 24:None, 25:None, 26:None} 15 # Devices is indexed by deviceId and stores a 4-tuple of device string, device serial, current status, and current channel 16 self.devices = {}
17
18 - def close(self):
19 pass
20 21 # Add a new devices to the DB
22 - def store_devices(self, devid, devstr, devserial):
23 self.devices[devid] = (devstr, devserial, 'Free', None)
24 25 # Returns the devid of a device marked 'Free', 26 # or None if there are no Free devices in the DB.
27 - def get_devices_nextFree(self):
28 for devid, dev in self.devices.items(): 29 if dev[2] == 'Free': 30 return devid
31
32 - def update_devices_status(self, devid, newstatus):
33 if devid not in self.devices: 34 return None 35 (devstr, devserial, _, chan) = self.devices[devid] 36 self.devices[devid] = (devstr, devserial, newstatus, chan)
37
38 - def update_devices_start_capture(self, devid, channel):
39 if devid not in self.devices: 40 return None 41 (devstr, devserial, _, _) = self.devices[devid] 42 self.devices[devid] = (devstr, devserial, "Capture", channel)
43 44 # Add a new network to the DB
45 - def store_networks(self, key, spanid, source, channel, packet):
46 if channel not in self.channels: 47 return None 48 # TODO note this only stores the most recent in the channel 49 self.channels[channel] = (key, spanid, source, packet)
50 51 # Return the channel of the network identified by key, 52 # or None if it doesn't exist in the DB.
53 - def get_networks_channel(self, key):
54 #print "Looking up channel for network with key of %s" % (key) 55 for chan, data in self.channels: 56 if data[0] == key: return chan 57 return None
58
59 - def channel_status_logging(self, chan):
60 ''' 61 Returns False if we have not seen the network or are not currently 62 logging it's channel, and returns True if we are currently logging it. 63 @return boolean 64 ''' 65 if chan == None: raise Exception("None given for channel number") 66 elif chan not in self.channels: raise Exception("Invalid channel") 67 for dev in self.devices.values(): 68 if dev[3] == chan and dev[2] == 'Capture': 69 return True 70 return False
71 # end of ZBScanDB class 72
73 -def toHex(bin):
74 return ''.join(["%02x" % ord(x) for x in bin])
75