#! /usr/bin/python
import binascii
import struct
import sys, os, time
import bluepy.btle as btle
chall_uuid = 0x30
board_uuid = 0x2e
score_uuid = 0x00ff
if len(sys.argv) != 2:
print "Requires level no.:", sys.argv[0], "<0-9 or \"s\" for scoreboard>"
quit()
deviceMAC = open('ctf_mac.txt').read()
p = btle.Peripheral(deviceMAC)
#p.connect(deviceMAC, "public")
if( sys.argv[1] == "s"):
# load scroebaord... hopefully
print("Loading scoreboard")
#deviceMAC = open('ctf_mac.txt').read()
#p = btle.Peripheral(deviceMAC)
response = p.writeCharacteristic(board_uuid, "fuck you")
else:
level = int(sys.argv[1])
level_hex = str('%0*x' % (4,level))
print level_hex
#print ("Attached to peripheral")
#services = p.getServiceByUUID(score_uuid)
#char = services.getCharacteristics(chall_uuid)[0]
print("Loading level")
#char.write(level_hex)
hex1 = binascii.unhexlify(level_hex)
response = p.writeCharacteristic(chall_uuid, hex1)
print("If error try again...it takes a few attempts, BLE is a bit crap")
p.disconnect()
time.sleep(1)
p = btle.Peripheral(deviceMAC)
scoreboard = p.getServiceByUUID(score_uuid)
q = scoreboard.getCharacteristics()
scoreboard = p.getServiceByUUID(score_uuid)
q = scoreboard.getCharacteristics()
for characteristic in q:
hex1 = int(format(characteristic.getHandle(),'02X'), 16)
if (characteristic.supportsRead()):
#hex2 = binascii.b2a_hex(p.readCharacteristic(hex1))
#hexlif2 = binascii.unhexlify(hex2)
hexlif2 = characteristic.read()
print (str(hex1)+" 0x"+ format(characteristic.getHandle(),'02X') +" "+ characteristic.propertiesToString() + " " + hexlif2)
else:
print (str(hex1)+" 0x"+ format(characteristic.getHandle(),'02X') +" "+ characteristic.propertiesToString() )
p.disconnect()