Example #1
0
class SingleSnifferInterface(AbstractInterface):
    """
    Single sniffer interface class.

    This class communicates with a single sniffer plugged into the computer.
    """

    def __init__(self, device=None, baudrate=115200):
        """
        Constructor.
        """
        self.link = Link(interface=device, baudrate=115200)
        super().__init__(self.link)

        # reset and request version.
        self.link.reset()
        self.version = self.link.get_version()

    def get_version(self):
        """
        Returns cached version.
        """
        return self.version

    def send_packet(self, packet):
        """
        Send packet if not idling. (synchronous)
        """
        if not self.is_idling():
            self.link.write(
                SendPacketCommand(
                    packet
                )
            )
            return True
        return False

    def set_timeout(self, timeout):
        """
        Set underlying interface timeout (Link).

        @param  float   timeout Timeout to set
        """
        self.link.set_timeout(timeout)

    def scan_access_addresses(self):
        """
        Scan access addresses (synchronous).

        Sends a command switching link into AA scanning mode.
        """
        self.link.write(ScanConnectionsCommand())
        self.link.wait_packet(ScanConnectionsResponse)
        super().scan_access_addresses()

    def recover_crcinit(self, access_address):
        """
        Recover crcinit value based on the provided parameters.

        @param access_address   int     target access address
        """
        self.link.write(RecoverCrcInitCommand(access_address))
        self.link.wait_packet(RecoverResponse)
        super().recover_crcinit()

    def recover_chm(self, access_address, crcinit, start, stop, timeout):
        """
        Recover channel map (distributed over sniffers)

        @param access_address   int     target access address
        @param crcinit          int     CRCInit value
        """
        self.link.write(RecoverChmCommand(access_address, crcinit, start, stop, timeout))
        self.link.wait_packet(RecoverResponse)
        super().recover_chm()

    def recover_hop(self, access_address, crcinit, chm):
        """
        Recover hop interval and increment.

        @param access_address   int     target access address
        @param crcinit          int     CRCInit value
        @param chm              int     Channel map
        """
        self.link.write(RecoverHopCommand(access_address, crcinit, chm))
        self.link.wait_packet(RecoverResponse)
        super().recover_hop()

    def sniff_connection(self, bd_address, channel=37):
        """
        Sniff a specific bd address on a specific channel.
        """
        self.link.write(SniffConnReqCommand(bd_address, channel))
        self.link.wait_packet(SniffConnReqResponse)
        super().sniff_connection()

    def read_packet(self):
        """
        Read packet if one is ready (asynchroous)
        """
        packets = []
        packet = self.link.async_read()
        if packet is not None:
            packets.append(packet)
        return packets
Example #2
0
class SingleSnifferInterface(AbstractInterface):
    """
    Single sniffer interface class.

    This class communicates with a single sniffer plugged into the computer.
    """
    def __init__(self, device=None, baudrate=115200):
        """
        Constructor.
        """
        self.link = Link(interface=device, baudrate=115200)
        super().__init__(self.link)

        # reset and request version.
        self.link.reset()
        self.version = self.link.get_version()

    def get_version(self):
        """
        Returns cached version.
        """
        return self.version

    def send_packet(self, packet):
        """
        Send packet if not idling. (synchronous)
        """
        if not self.is_idling():
            self.link.write(SendPacketCommand(packet))
            return True
        return False

    def set_timeout(self, timeout):
        """
        Set underlying interface timeout (Link).

        @param  float   timeout Timeout to set
        """
        self.link.set_timeout(timeout)

    def scan_access_addresses(self):
        """
        Scan access addresses (synchronous).

        Sends a command switching link into AA scanning mode.
        """
        self.link.write(ScanConnectionsCommand())
        self.link.wait_packet(ScanConnectionsResponse)
        super().scan_access_addresses()

    def recover_crcinit(self, access_address):
        """
        Recover crcinit value based on the provided parameters.

        @param access_address   int     target access address
        """
        self.link.write(RecoverCrcInitCommand(access_address))
        self.link.wait_packet(RecoverResponse)
        super().recover_crcinit()

    def recover_chm(self, access_address, crcinit, start, stop, timeout):
        """
        Recover channel map (distributed over sniffers)

        @param access_address   int     target access address
        @param crcinit          int     CRCInit value
        """
        self.link.write(
            RecoverChmCommand(access_address, crcinit, start, stop, timeout))
        self.link.wait_packet(RecoverResponse)
        super().recover_chm()

    def recover_hop(self, access_address, crcinit, chm):
        """
        Recover hop interval and increment.

        @param access_address   int     target access address
        @param crcinit          int     CRCInit value
        @param chm              int     Channel map
        """
        self.link.write(RecoverHopCommand(access_address, crcinit, chm))
        self.link.wait_packet(RecoverResponse)
        super().recover_hop()

    def sniff_connection(self, bd_address, channel=37):
        """
        Sniff a specific bd address on a specific channel.
        """
        self.link.write(SniffConnReqCommand(bd_address, channel))
        self.link.wait_packet(SniffConnReqResponse)
        super().sniff_connection()

    def read_packet(self):
        """
        Read packet if one is ready (asynchroous)
        """
        packets = []
        packet = self.link.async_read()
        if packet is not None:
            packets.append(packet)
        return packets

    def enable_advertisements_reactive_jamming(self, channel, pattern,
                                               position):
        """
        Enable Advertisements jamming (synchronous).

        Sends a command switching link into Advertisements reactive Jamming mode.
        """
        self.link.write(
            EnableReactiveJammingCommand(channel=channel,
                                         pattern=pattern,
                                         position=position))
        self.link.wait_packet(AdvertisementsResponse)
        super().jam_advertisements()
        return True

    def disable_advertisements_reactive_jamming(self):
        """
        Disable Advertisements jamming.

        Sends a command disabling Advertisements reactive jamming mode.
        """
        self.link.write(DisableReactiveJammingCommand())

    def enable_advertisements_sniffing(self, channel):
        """
        Enable Advertisements sniffing (synchronous).

        Sends a command switching link into Advertisements sniffing mode.
        """
        self.link.write(EnableAdvertisementsSniffingCommand(channel))
        pkt = self.link.wait_packet(AdvertisementsResponse)
        super().sniff_advertisements()
        return (pkt.response_type == 0x03 and pkt.status == 0)

    def reset_filtering_policy(self, policy_type="blacklist"):
        """
        Reset filtering policy.

        Sends a command reseting the filtering policy to the provided filtering mode ("whitelist" or "blacklist").
        """
        self.link.write(ResetFilteringPolicyCommand(policy_type))

    def add_rule(self, pattern, mask, position=None):
        """
        Add filtering Rule.

        Sends a command adding a new rule to the filtering policy.
        """
        self.link.write(AddRuleCommand(pattern, mask, position))

    def disable_advertisements_sniffing(self):
        """
        Disable Advertisements sniffing (synchronous).

        Sends a command disabling Advertisements sniffing mode.
        """
        self.link.write(DisableAdvertisementsSniffingCommand())