Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac build and python3 fixes #281

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions killerbee/dev_sl_beehive.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,25 @@ def __send_cmd(self, cmdstr, arg=None, confirm= True, send_return= True, extra_d
self.handle.readline()

# some commands require us to be in idle, so do it always
self.handle.write("rx 0\r")
self.handle.write(b"rx 0\r")
time.sleep(0.02)
for x in range(3):
self.handle.readline()

if arg != None:
cmdstr += ' ' + arg
if not isinstance(cmdstr, bytes):
cmdstr= cmdstr.encode()
self.handle.write(cmdstr)
if send_return:
self.handle.write('\r')
self.handle.write(b'\r')
#time.sleep(0.1)
time.sleep(extra_delay)
if confirm:
ret= False
for x in range(100):
d= self.handle.readline().strip()
if d[-1:] == '>':
if d[-1:] == b'>':
ret= True
break
else:
Expand All @@ -114,7 +116,7 @@ def __dissect_pkt(self, packet):
packet will be in the format: "{{(rxPacket)}{len:11}{timeUs:994524212}{crc:Pass}{rssi:-44}{lqi:210}{phy:0}{isAck:False}{syncWordId:0}{antenna:0}{payload: 0x0a 0x03 0x08 0xba 0xff 0xff }"
'''
try:
data = packet.replace('}','').split(':')[10].split()
data = packet.replace(b'}',b'').split(b':')[10].split()
except:
return None, None, None
if not data:
Expand All @@ -130,8 +132,8 @@ def __dissect_pkt(self, packet):
except:
return None, None, None
try:
crc = packet.replace('}','').split(':')[4].split('{')[0] == 'Pass'
rssi = packet.replace('}','').split(':')[4].split('{')[0]
crc = packet.replace(b'}',b'').split(b':')[4].split(b'{')[0] == 'Pass'
rssi = packet.replace(b'}',b'').split(b':')[4].split(b'{')[0]
except:
return None, None, None
return rssi, out, crc
Expand All @@ -158,7 +160,7 @@ def sniffer_on(self, channel=None, page=0):
self.__send_cmd("rx", "1", confirm= False)
for x in range(5):
d = self.handle.readline()
if 'Rx:Enabled' in d:
if b'Rx:Enabled' in d:
self.mode = MODE_SNIFF
self.__stream_open = True

Expand All @@ -178,7 +180,7 @@ def sniffer_off(self):
self.__send_cmd("rx", "0", confirm= False, initial_read= 0)
for x in range(3):
d= self.handle.readline().strip()
if "Rx:Disabled" in d:
if b'Rx:Disabled' in d:
self.mode = MODE_NONE
self.__stream_open = False
self.handle.readline()
Expand Down Expand Up @@ -252,9 +254,9 @@ def inject(self, packet, channel=None, count=1, delay=0, page=0):
tosend = maxp
else:
tosend = len(packet)
self.__send_cmd("setTxPayload", "00 %02x%s" % ((len(packet)), packet[:tosend].encode('hex')))
self.__send_cmd("setTxPayload", "00 %02x%s" % ((len(packet)), packet[:tosend].hex()))
if len(packet) > maxp:
self.__send_cmd("setTxPayload", "%d %s" % (tosend + 1, packet[tosend:].encode('hex')))
self.__send_cmd("setTxPayload", "%d %s" % (tosend + 1, packet[tosend:].hex()))
for pnum in range(0, count):
self.__send_cmd("tx", "1", confirm= False)
time.sleep(delay)
Expand Down Expand Up @@ -290,7 +292,7 @@ def pnext(self, timeout=1):
return None
#Return in a nicer dictionary format, so we don't have to reference by number indicies.
#Note that 0,1,2 indicies inserted twice for backwards compatibility.
result = {0:frame, 1:validcrc, 2:rssi, 'bytes':frame, 'validcrc':validcrc, 'rssi':rssi}
result = {0:frame.encode(), 1:validcrc, 2:rssi, 'bytes':frame.encode(), 'validcrc':validcrc, 'rssi':rssi}
result['dbm'] = None #TODO calculate dBm antenna signal based on RSSI formula
result['datetime'] = datetime.utcnow() # TODO - see what time field in sniff is actually telling us
result['location'] = (self.lon, self.lat, self.alt)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
zigbee_crypt = Extension('zigbee_crypt',
sources = ['zigbee_crypt/zigbee_crypt.c'],
libraries = ['gcrypt'],
include_dirs = ['/usr/local/include', '/usr/include', '/sw/include/', 'zigbee_crypt'],
library_dirs = ['/usr/local/lib', '/usr/lib','/sw/var/lib/']
include_dirs = ['/usr/local/include', '/usr/include', '/sw/include/', 'zigbee_crypt', '/opt/homebrew/include/'],
library_dirs = ['/usr/local/lib', '/usr/lib','/sw/var/lib/', '/opt/homebrew/lib']
)

setup(name = 'killerbee',
Expand Down
4 changes: 2 additions & 2 deletions tools/zbdump
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def dump_packets(args):
print('ERROR: Could not open stdout for verbose mode.', file=sys.stderr)
sys.exit(0)
else:
unbuffered.write('.')
unbuffered.write(b'.')

if pcap_dumper is not None:
pcap_dumper.pcap_dump(packet['bytes'], ant_dbm=packet['dbm'], freq_mhz=rf_freq_mhz)
Expand Down Expand Up @@ -112,7 +112,7 @@ def main():

#Handle required args
if args.verbose:
unbuffered = os.fdopen(sys.stdout.fileno(), 'w', 0)
unbuffered = os.fdopen(sys.stdout.fileno(), 'wb', 0)

if args.channel == None:
print("ERROR: Must specify a channel.", file=sys.stderr)
Expand Down