Exemple #1
0
    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
Exemple #2
0
 def writeRequest(self, packet):
     if self.getStage() == BLEMitmStage.ACTIVE_MITM:
         io.info("Write Request (from master) : handle = " +
                 hex(packet.handle) + " / value = " + packet.value.hex())
         io.info("Redirecting to slave ...")
         self.a2sEmitter.sendp(
             ble.BLEWriteRequest(handle=packet.handle, value=packet.value))
Exemple #3
0
    def write_req(self, handle, value):
        if self.receiver.isConnected():
            if utils.isHexadecimal(handle) and utils.isHexadecimal(value):
                self.emitter.sendp(
                    ble.BLEWriteRequest(handle=int(handle, 16),
                                        value=bytes.fromhex(value)))
                io.info("Write Request : handle = " + handle + " / value = " +
                        value)

                response = self.receiver.next(timeout=3)
                retry = 3
                while not (isinstance(response, ble.BLEWriteResponse)
                           or isinstance(response, ble.BLEErrorResponse)
                           or retry == 0):
                    response = self.receiver.next(timeout=1)
                    retry -= 1
                if isinstance(response, ble.BLEWriteResponse):
                    io.success("Response : success")
                elif isinstance(response, ble.BLEErrorResponse):
                    io.fail("Error response !")
                elif retry == 0:
                    io.fail("Timeout error !")
            else:
                io.fail(
                    "Handle or value is not correctly formatted (hexadecimal) !"
                )
        else:
            io.fail("No active connections !")